Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 01 Apr 2015, 00:53
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Firefox/Seamonkey/Palemoon Bookmark Navigator Script
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 3 [33 Posts]   Goto page: 1, 2, 3 Next
Author Message
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Fri 23 Jan 2015, 10:15    Post subject:  Firefox/Seamonkey/Palemoon Bookmark Navigator Script
Subject description: PHP script to navigate standard firefox bookmarks.html files
 

firefox/seamonkey/palemoon bookmarks organizer

Introduction:
This PHP script reads a standard firefox bookmarks.html file and displays it via an easy to navigate user interface.
It is quick and easy to use and I am now using it to navigate and categorize my haystack of surfing history, that is 1200+ bookmarks most of which I had forgotton existed.

The bookmarks.html file is a third party (mozilla) code, so parsing it is an inherently fragile method, due to the possibility of future changes to its code, beyond our control.
However, it is quite easy to analyse and fix a broken parser script, provided one has copies of the old and new files and from that you can work out the changes necessary.
Sometimes though, the parsed file is no longer available or has changed so much, that a complete rewrite or abandonment is the only option.
I wrote this script based upon a bookmarks.html file I exported from Seamonkey 2,24 (Bookmarks, Manage Bookmarks, Tools, Export HTML).
The script only reads and does not alter the firefox/seamonkey/palemoon bookmarks.html file.

Requirements:
1. Firefox or Seamonkey or Palemoon browser, you need one of these to export your bookmarks to a bookmarks.html file.
After that, the script will display the firefox bookmarks on other browsers too, like Opera.
2. The ability to run PHP pages locally on your computer and display the resulting HTML pages in your web browser.
To do this I suggest installing Hiawatha Server and then test a simple PHP page at for example http://localhost/index.php (browser address).
This page will probably be located at /root/httpd/hiawatha/index.php (file manager location).
Some server installations install to a folder called 'webserver'.
Installation and configuration of a local server is beyond the scope of this post.
Make sure that the server is working and runs every time you start Puppy.
To view the example PHP page (spoken about above) type the address http://localhost/index.php into your browser address bar.

File Permissions note:
Set the file permissions as indicated below or alter them according to your security/functionality requirements.
The permissions are important as the bookmark script needs to read the bookmarks.html file and also read and write the list-1.txt, list-2.txt list-3.txt files.

Files required:
1. /root/httpd/hiawatha/bookmarks.html (rw-r--r--)
(standard bookmarks.html exported from browser dialog)

2. /root/httpd/hiawatha/bookmarks.php (rwxr--r--)

Code:

<?php  // **** PREVENT BROWSER CACHE ****
//header('Cache-Control: no-cache, must-revalidate');
//header('Pragma: no-cache');
//header('Expires: Sat,1 Jan 2000 00:00:01 GMT');
error_reporting (E_ALL ^ E_NOTICE);
$search=$_POST['word'];
$list=$_POST['list'];
$hide_domain=$_POST['dn'];
if(strlen($hide_domain)<1) {$hide_domain=1;};

$t1=$_POST['t1'];
$t2=$_POST['t2'];
$t3=$_POST['t3'];

$list1=@file_get_contents("list-1.txt");
$list2=@file_get_contents("list-2.txt");
$list3=@file_get_contents("list-3.txt");

$title1=get_string_between($list1,'<t>','</t>');
$title2=get_string_between($list2,'<t>','</t>');
$title3=get_string_between($list3,'<t>','</t>');

if($_POST['button1']){//change button1 name by pressing for 2 seconds
$list1=str_replace('<t>'.$title1.'</t>','<t>'.$t1.'</t>',$list1);
$title1=$t1;
$list1=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list1);//strip some whitespace
$fh=fopen("list-1.txt","w+");
fwrite($fh, $list1);
fclose($fh);
}

if($_POST['button2']){//change button2 name by pressing for 2 seconds
$list2=str_replace('<t>'.$title2.'</t>','<t>'.$t2.'</t>',$list2);
$title2=$t2;
$list2=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list2);//strip some whitespace
$fh=fopen("list-2.txt","w+");
fwrite($fh, $list2);
fclose($fh);
}

if($_POST['button3']){//change button3 name by pressing for 2 seconds
$list3=str_replace('<t>'.$title3.'</t>','<t>'.$t3.'</t>',$list3);
$title3=$t3;
$list3=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list3);//strip some whitespace
$fh=fopen("list-3.txt","w+");
fwrite($fh, $list3);
fclose($fh);
}

if(strlen($list)<1) {$list=1;};

$fg=0;//flag you are trying to add a name already in one of the lists

$ss1=explode('<s>', $list1);$ss1[0]=$ss1[1];
for($n=0;$n<=(count($ss1)-1);$n++){
$ss1[$n]=get_string_between($ss1[$n],'<w>','</w>');
if($ss1[$n]==$search){$fg=1;};}

$ss2=explode('<s>', $list2);$ss2[0]=$ss2[1];
for($n=0;$n<=(count($ss2)-1);$n++){
$ss2[$n]=get_string_between($ss2[$n],'<w>','</w>');
if($ss2[$n]==$search){$fg=1;};}

$ss3=explode('<s>', $list3);$ss3[0]=$ss3[1];
for($n=0;$n<=(count($ss3)-1);$n++){
$ss3[$n]=get_string_between($ss3[$n],'<w>','</w>');
if($ss3[$n]==$search){$fg=1;};}

if(($fg!=1)&&($search!='')&&($_POST['add'])){
$fh=fopen("list-".$list.".txt","a+");
fwrite($fh,PHP_EOL."<s><w>".$search."</w>"); //write to txtfile
fclose($fh);}

if($_POST['remove']){
$dat=@file_get_contents("list-".$list.".txt")   ;
$dat=str_replace('<s><w>'.$search.'</w>','', $dat);
$dat=preg_replace('/^\n+|^[\t\s]*\n+/m','',$dat);//strip some whitespace
$fh=fopen("list-".$list.".txt","w+");
fwrite($fh, $dat);
fclose($fh);}

function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$links='bookmarks.html';
$pg1=@file_get_contents($links) or die ('<html><body><p>Sorry for any inconvenience, error 1, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
$file='list-'.$list.'.txt';
$pg2=@file_get_contents($file) or die ('<html><body><p>Sorry for any inconvenience, error 2, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Bookmarks</title>
<link rel="shortcut icon" href="bookmark.ico">
<style type="text/css">
body{font:normal 24px 'Arial';color:#000;background-color:#ddd;background-image:url(ptv2.jpg);}
a:link,a:visited,a:active{text-decoration:none;color:#036}
.m1,.r1{display:inline;float:left;border-radius:0.2em;cursor:pointer;font:bold 24px "Arial";padding:4px 4px 4px 4px;background-color:#bbb;color:#036;margin:4px 4px 4px 4px;border:solid 2px #040}
.r1{display:block;}
.m1:hover{background-color:#0ee;}
.r1:hover{background-color:#fdd;}
#form{display:block;margin-right:100%;margin-top:10px}
#links{display:block;float:left;width:100%;margin-top:10px;margin-bottom:10px}
#word{display:inline;width:200px;height:30px;margin:10px 10px 0px 6px;font:normal 24px 'Arial'}
#buttons{margin-top:-20px;width:670px}
.num{background-color:#eca;}
.b1{border-radius:0.2em;margin:auto;text-align:left;text-decoration:none;display:block;font:bold 24px "Arial";border:solid 1px #060;overflow:hidden;margin:4px 4px 4px 4px;color:#036;background-color:#bbb;min-height:30px;padding:4px 4px 4px 4px;width:638px}
.b1{color:#036;background-color:#ddd;}
.b1:hover{text-decoration:none;color:#036;background-color:#ff0}
.b1:visited{text-decoration:none;color:#000;background-color:#eca}
.s1{background-color:#e00;color:#fff;border-radius:0.2em}
.s2{background-color:#cec;color:#000;border-radius:0.2em}
</style>
<script type="text/javascript">
<!--
if (top.location != self.location) {top.location = self.location}
function init()
{
document.form.reset();   
}
// -->
</script>
</head>
<body onload="document.form.add.value='0';document.form.button1.value='0';document.form.button2.value='0';document.form.button3.value='0';window.focus()" onunload="window.blur()">
<div class='r1' onfocus='this.blur()' <?php if($list=='1'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='1';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t1.value=document.form.word.value;document.form.button1.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title1; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='2'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='2';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t2.value=document.form.word.value;document.form.button2.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title2; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='3'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='3';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t3.value=document.form.word.value;document.form.button3.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title3; ?></div>
<div class='r1' onfocus='this.blur()' onclick="document.form.dn.value='<?php if($hide_domain=='1'){echo '0';}else {echo '1';}?>';document.form.submit();">DOMAIN</div>
<form name="form" id="form" method="post" action="bookmarks.php">
<div>
<input type='text' style="" name='word' id='word' value='<?php echo $search; ?>' title='Search - (2 or more characters) - Then Hit Enter'>
<input type="hidden" name="add" value="0">
<input type="hidden" name="remove" value="0">
<input type="hidden" name="button1" value="0">
<input type="hidden" name="button2" value="0">
<input type="hidden" name="button3" value="0">
<input type="hidden" name="list" value="<?php echo $list; ?>">
<input type="hidden" name="t1" value="<?php echo $t1; ?>">
<input type="hidden" name="t2" value="<?php echo $t2; ?>">
<input type="hidden" name="t3" value="<?php echo $t3; ?>">
<input type="hidden" name="dn" value="<?php echo $hide_domain; ?>">
<input style="visibility:hidden" type="submit" onclick="document.form.add.value='1';">
</div>
</form>
<div id='buttons'>
<div class='r1' onfocus='this.blur()' <?php if($search==''){echo ('style="background-color:#ff0" ');}?>onclick="this.style.backgroundColor='#ff0';document.form.word.value='';document.form.submit();">ALL</div>
<?php
$ss=explode('<s>', $pg2);
$ss[0]=$ss[1];
natcasesort($ss);//puts buttons in natural case sorted order
for($n=-1;$n<=(count($ss)-1);$n++){$sp[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
$ss[$n]=get_string_between($ss[$n],'<w>','</w>');
$ss=array_values(array_unique($ss));
$ss = array_values($ss);
if($search==$ss[$n]){$style='style="background-color:#ff0" ';}else{$style='';};$sp[$n]=$ss[$n];$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces but not in posted word
if($ss[$n]!=''){echo '<div class="m1" onfocus="this.blur()" '.$style.'onclick="this.style.backgroundColor=\'#ff0\';document.form.word.value=\''.$sp[$n].'\';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.remove.value=\'1\';document.form.submit();},2000)" onmouseup="clearTimeout(timer)">'.$ss[$n].'</div>'."\n";};$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
};
?>
</div>
<div id='links'>
<?php
if (strlen($search)<2){//NO SEARCH
if($hide_domain=='1'){//domain hidden
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
}else{//domain visible
$pg1 = str_replace('<DT><H3','', $pg1);//replace
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace
$pg1 = preg_replace('/^\n+|^[\t\s]*\n+/m','',$pg1);//strip some whitespace
$tt=explode('<DT>', $pg1);
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
natcasesort($tt);//puts urls of links in natural case sorted order
}
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
if($title[$n]==''){$title[$n]=$url[$n];}
if($hide_domain=='0'){$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';}else{$dn='';};
if($n>1){echo '<a class="b1" target="new" href="'.$url[$n].'">'.$dn.''.$title[$n].'</a>'."\n";};}
}
else{//SEARCH
if($hide_domain=='1'){//domain hidden
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
}else{//domain visible   
$pg1 = str_replace('<DT><H3','', $pg1);//replace
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace
$pg1 = preg_replace('/^\n+|^[\t\s]*\n+/m','',$pg1);//strip some whitespace
$tt=explode('<DT>', $pg1);
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
//$tt=array_unique($tt);//removes array duplicates
natcasesort($tt);//puts urls of links in natural case sorted order
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
}
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
//$domain[$n]= str_replace('www.','',$domain[$n]);//replace
if($hide_domain=='0'){$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';}else{$dn='';};
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};echo '<a class="b1" target="new" href="'.$url[$n].'">'.$dn.''.$title[$n].'</a>'."\n";
};};};
?>
</div>
</body>
</html>



3. /root/httpd/hiawatha/list-1.txt (rw-rw-rw-)

Code:

<t>portugal</t>
<s><w>flashcard</w>
<s><w>rafa</w>
<s><w>grammar</w>
<s><w>conj</w>
<s><w>transl</w>
<s><w>portug</w>
<s><w>phrase</w>
<s><w>lingu</w>
<s><w>teletext</w>
<s><w>verb</w>


4. /root/httpd/hiawatha/list-2.txt (rw-rw-rw-)

Code:

<t>technical</t>
<s><w>javascript</w>
<s><w>tiny</w>
<s><w>lxde</w>
<s><w>puppy</w>
<s><w>ubuntu</w>
<s><w>sourcef</w>
<s><w>bacon</w>
<s><w>firefox</w>
<s><w>css</w>
<s><w>pup</w>
<s><w>css3</w>
<s><w>linux</w>
<s><w>python</w>
<s><w>openbox</w>
<s><w>debian</w>
<s><w>css2</w>
<s><w>mouse</w>
<s><w>gtk</w>
<s><w>script</w>
<s><w> php</w>
<s><w>tint</w>
<s><w>village</w>
<s><w>php.net</w>
<s><w>hiaw</w>


5. /root/httpd/hiawatha/list-3.txt (rw-rw-rw-)

Code:

<t>other</t>


6. /root/httpd/hiawatha/ptv2.jpg (rw-r--r--)

Use your own tile.

7. /root/httpd/hiawatha/bookmark.ico (rw-r--r--)

Use your own icon.

Summary:
(remember to alter file permissions if necessary - see above):
File 1 is the mozilla bookmarks.html file
File 2 is the PHP script.
Files 3,4 and 5 are text files that hold the shortcut button configurations.
File 6 is the background wallpaper image for the PHP page.
File 7 is the shortcut (fav) icon for the PHP page.

Setting up:
1. Copy the above files to the specified locations.
2. Ensure file permissions are set correctly (otherwise you will get PHP error messages).
3. Place a shortcut icon on your browser toolbar to the PHP script (/root/httpd/hiawatha/bookmarks.php).

Description and how to use:
1. This PHP script only displays an existing bookmarks.html file.
2. Any recent bookmarks added to your browser toolbar will not appear until you export them to a new bookmarks.html file.
3. Domains starting 'https' are highlighted in light green all other domains are highlighted red.
4. The domain names can be distracting, so there is a DOMAIN button at the top ... click it to turn the highlighted domains on or off.
5. There are 3 Master Category buttons at the top, it is possible to alter a button's name by way of mousedown (left click and hold down) on the button for 2 seconds, then the text box contents will load onto the button.
6. Obviously you could alter the code and text files for more or less Master Category buttons or automate adding and removing them.
7. Below the text box are the Search buttons, when you search your links a Search button will be added in alphabetical order.
8. Mousedown (left click and hold down) on a Search button for 2 seconds whilst it is highlighted yellow and that will remove the button.
9. The browser 'mozilla, seamonkey default links' are not included in the results but you can easily add them manually.
10. The searches are case insensitive and search both the complete url string and the bookmark title, so nothing is missed.
11. When domain names are visible hyperlinks are listed in 'alphabetical order by url and then bookmark'. When domain names are hidden hyperlinks are listed in 'alphabetical order by bookmark and then url'.
12. Note that some links look identical, hover on them and the browser status bar reveals the complete url strings to be different pages.
Duplicate links are sometimes shown. Delete them if you want. It can be informative to compare the results obtained here, with searches obtained using the firefox bookmarks manager.

EDIT Script updated 23:50 UTC 2015-01-25 to alphabetically sort bookmarks when domains hidden. Please note: bookmarks.php code changed.
EDIT Script updated 00:30 UTC 2015-01-26 to set default state when page is first opened to domains hidden. if(strlen($hide_domain)<1) {$hide_domain=1;};
EDIT The script can read and display correctly with all browsers I have tried ... Firefox, Opera, Seamonkey, Pale Moon.

To create a correctly formatted bookmarks.html file (export HTML), I found that browsers Pale Moon 25.2.0 (x86) and Sea Monkey 2.24 (User agent: Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24) worked identically and perfectly.
However a newer version of Firefox (Firefox 35.0) did not export 'correctly' and produced a jumbled and incomplete list of links when viewed with my script.
So I recommend trying an earlier version of Firefox (Firefox 27.0) on which Seamonkey 2.24 is based, when exporting the bookmarks.html file.
Once you have a good exported bookmarks.html file it doesn't matter which version of Firefox you use.

This reinforces the statement at the beginning of this post.
The bookmarks.html file is a third party (mozilla) code, so parsing it is an inherently fragile method, due to the possibility of future changes to its code, beyond our control.
bookmark-script-with-domain-button.jpg
 Description   
 Filesize   86.75 KB
 Viewed   61 Time(s)

bookmark-script-with-domain-button.jpg

bookmark-script-3-with-domain-button.jpg
 Description   
 Filesize   72.26 KB
 Viewed   60 Time(s)

bookmark-script-3-with-domain-button.jpg

bookmark.ico.tar.gz
Description  fav icon
gz

 Download 
Filename  bookmark.ico.tar.gz 
Filesize  1.11 KB 
Downloaded  67 Time(s) 
ptv2.jpg
 Description   Wallpaper tile
 Filesize   1.64 KB
 Viewed   637 Time(s)

ptv2.jpg


Last edited by kjdixo on Mon 16 Feb 2015, 07:37; edited 2 times in total
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Tue 27 Jan 2015, 20:09    Post subject: Updated bookmark script for a slightly different output
Subject description: This version has screenshots and selectable bookmark.html files
 

Post 2: Version 2 with screenshots and selectable bookmark.html files.

1. This version only sorts in 'alphabetical order by bookmark and then by url'.
2. The domains are not shown, only the titles.
3. Searches title then complete url string so that nothing is missed.
4. Top left button added, defaults to 1 when page is first opened.
5. The number or name on this button is user configurable, by mousedown (left click and hold down) on the button for 2 seconds, then the text box contents will load onto the button.
6. Look at the PHP code to understand that the value entered refers to the unique folder and file name where the bookmarks.html file and the .png screenshots are stored.
7. The default firefox bookmarks file in my case is at /root/httpd/hiawatha/1/bookmarks-1.html. and has been manually renamed.
8. The default location for my 1200+ screenshots is /root/httpd/hiawatha/1/screenshots-1/
9. The images in that folder are mtPaint screenshots taken from the relevant website pages. I leave them as .png files but scale down to 600px square. My PHP script then displays them as 300px square.
10. To find out 'what to name each screenshot?' simply hover over the PHP script page empty image link and a number 2 to 1200 (in my example) will appear, so name the screenshot 'that number' .png.
eg 398.png or 757.png. It will take a while to do them all and then your bookmarks file will be 'set in stone' and altering it will also entail renaming lots of .png files.
11. Another file and folder structure could use the number 2 or even a date code, but you must follow the naming convention so that the script can access the images in /whatever/screenshots-whatever/ and the /whatever/bookmarks-whatever.html file.
12. If you rename the top left button incorrectly and then cannot access the files, don't worry simply close the browser, delete cache if necessary and reopen the page, the button will default to '1', so obviously it is important to not delete the '1' folder or its contents.

Edit 10:45 UTC 2015-02-13 add this:
if(!is_dir($folder)){$folder=1;}
in the place shown below, to prevent an error occurring when a folder is entered that does not exist, using the top left button (now defaults to folder '1').

Code:

$folder=$_POST['folder'];
if(strlen($folder)<1){$folder=1;};
if(!is_dir($folder)){$folder=1;}


Code:

<?php  // **** PREVENT BROWSER CACHE ****
//header('Cache-Control: no-cache, must-revalidate');
//header('Pragma: no-cache');
//header('Expires: Sat,1 Jan 2000 00:00:01 GMT');
error_reporting (E_ALL ^ E_NOTICE);
$search=$_POST['word'];
$list=$_POST['list'];
$folder=$_POST['folder'];
if(strlen($folder)<1) {$folder=1;};

$t1=$_POST['t1'];
$t2=$_POST['t2'];
$t3=$_POST['t3'];

$list1=@file_get_contents($folder.'/list-1.txt');
$list2=@file_get_contents($folder.'/list-2.txt');
$list3=@file_get_contents($folder.'/list-3.txt');

$title1=get_string_between($list1,'<t>','</t>');
$title2=get_string_between($list2,'<t>','</t>');
$title3=get_string_between($list3,'<t>','</t>');

if($_POST['button1']){//change button1 name by pressing for 2 seconds
$list1=str_replace('<t>'.$title1.'</t>','<t>'.$t1.'</t>',$list1);
$title1=$t1;
$list1=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list1);//strip some whitespace
$fh=fopen($folder.'/list-1.txt','w+');
fwrite($fh, $list1);
fclose($fh);
}

if($_POST['button2']){//change button2 name by pressing for 2 seconds
$list2=str_replace('<t>'.$title2.'</t>','<t>'.$t2.'</t>',$list2);
$title2=$t2;
$list2=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list2);//strip some whitespace
$fh=fopen($folder.'/list-2.txt','w+');
fwrite($fh, $list2);
fclose($fh);
}

if($_POST['button3']){//change button3 name by pressing for 2 seconds
$list3=str_replace('<t>'.$title3.'</t>','<t>'.$t3.'</t>',$list3);
$title3=$t3;
$list3=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list3);//strip some whitespace
$fh=fopen($folder.'/list-3.txt','w+');
fwrite($fh, $list3);
fclose($fh);
}

if(strlen($list)<1) {$list=1;};

$fg=0;//flag you are trying to add a name already in one of the lists

$ss1=explode('<s>', $list1);$ss1[0]=$ss1[1];
for($n=0;$n<=(count($ss1)-1);$n++){
$ss1[$n]=get_string_between($ss1[$n],'<w>','</w>');
if($ss1[$n]==$search){$fg=1;};}

$ss2=explode('<s>', $list2);$ss2[0]=$ss2[1];
for($n=0;$n<=(count($ss2)-1);$n++){
$ss2[$n]=get_string_between($ss2[$n],'<w>','</w>');
if($ss2[$n]==$search){$fg=1;};}

$ss3=explode('<s>', $list3);$ss3[0]=$ss3[1];
for($n=0;$n<=(count($ss3)-1);$n++){
$ss3[$n]=get_string_between($ss3[$n],'<w>','</w>');
if($ss3[$n]==$search){$fg=1;};}

if(($fg!=1)&&($search!='')&&($_POST['add'])){
$fh=fopen($folder.'/list-'.$list.'.txt','a+');
fwrite($fh,PHP_EOL.'<s><w>'.$search.'</w>'); //write to txtfile
fclose($fh);}

if($_POST['remove']){
$dat=@file_get_contents($folder.'/list-'.$list.'.txt')   ;
$dat=str_replace('<s><w>'.$search.'</w>','', $dat);
$dat=preg_replace('/^\n+|^[\t\s]*\n+/m','',$dat);//strip some whitespace
$fh=fopen($folder.'/list-'.$list.'.txt','w+');
fwrite($fh, $dat);
fclose($fh);}

function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$links=$folder.'/bookmarks-'.$folder.'.html';
$pg1=@file_get_contents($links) or die ('<html><body><p>Sorry for any inconvenience, error 1, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
$file=$folder.'/list-'.$list.'.txt';
$pg2=@file_get_contents($file) or die ('<html><body><p>Sorry for any inconvenience, error 2, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Bookmarks</title>
<link rel="shortcut icon" href="bookmark.ico">
<style type="text/css">
body{font:normal 24px 'Arial';color:#000;background-color:#ddd;background-image:url(ptv2.jpg);}
a:link,a:visited,a:active{text-decoration:none;color:#036}
.m1,.r1{display:inline;float:left;border-radius:0.2em;cursor:pointer;font:bold 24px "Arial";padding:4px 4px 4px 4px;background-color:#bbb;color:#036;margin:4px 4px 4px 4px;border:solid 2px #040}
.r1{display:block;}
.m1:hover{background-color:#0ee;}
.r1:hover{background-color:#fdd;}
#form{display:block;margin-right:100%;margin-top:10px}
#links{display:block;float:left;width:100%;margin-top:10px;margin-bottom:10px}
#word{display:inline;width:200px;height:30px;margin:10px 10px 0px 6px;font:normal 24px 'Arial'}
#buttons{margin-top:-20px;width:670px}
.num{background-color:#eca;}
.b1{border-radius:0.2em;margin:auto;text-align:left;text-decoration:none;display:block;font:bold 24px "Arial";border:solid 1px #060;overflow:hidden;margin:4px 4px 4px 4px;color:#036;background-color:#bbb;min-height:30px;padding:4px 4px 4px 4px;width:638px}
.b1{color:#036;background-color:#ddd;}
.b1:visited{text-decoration:none;color:#000;background-color:#eca}
.b1{margin:auto;text-align:left;text-decoration:none;;display:inline;float:left;font:bold 36px "Arial";border:solid 1px #060;margin:8px 0px 8px 10px;width:400px;min-height:310px;padding:8px 8px 8px 340px;overflow:hidden}
.b1 {color:#036;background-color:#c2cccc;background-repeat:no-repeat;background-position:13px 13px;background-size:300px 300px;}
.b1:hover{text-decoration:none;color:#036;background-color:#ff0}
</style>
<script type="text/javascript">
<!--
if (top.location != self.location) {top.location = self.location}
function init()
{
document.form.reset();   
}
// -->
</script>
</head>
<body onload="document.form.add.value='0';document.form.button1.value='0';document.form.button2.value='0';document.form.button3.value='0';window.focus()" onunload="window.blur()">
<div class='m1' onfocus='this.blur()' onmousedown="timer=window.setTimeout(function(){document.form.folder.value=document.form.word.value;document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $folder; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='1'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='1';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t1.value=document.form.word.value;document.form.button1.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title1; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='2'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='2';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t2.value=document.form.word.value;document.form.button2.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title2; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='3'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='3';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t3.value=document.form.word.value;document.form.button3.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title3; ?></div>
<form name="form" id="form" method="post" action="bookmarks.php">
<div>
<input type='text' style="" name='word' id='word' value='<?php echo $search; ?>' title='Search - (2 or more characters) - Then Hit Enter'>
<input type="hidden" name="add" value="0">
<input type="hidden" name="remove" value="0">
<input type="hidden" name="button1" value="0">
<input type="hidden" name="button2" value="0">
<input type="hidden" name="button3" value="0">
<input type="hidden" name="list" value="<?php echo $list; ?>">
<input type="hidden" name="t1" value="<?php echo $t1; ?>">
<input type="hidden" name="t2" value="<?php echo $t2; ?>">
<input type="hidden" name="t3" value="<?php echo $t3; ?>">
<input type="hidden" name="folder" value="<?php echo $folder; ?>">
<input style="visibility:hidden" type="submit" onclick="document.form.add.value='1';">
</div>
</form>
<div id='buttons'>
<div class='r1' onfocus='this.blur()' <?php if($search==''){echo ('style="background-color:#ff0" ');}?>onclick="this.style.backgroundColor='#ff0';document.form.word.value='';document.form.submit();">ALL</div>
<?php
$ss=explode('<s>', $pg2);
$ss[0]=$ss[1];
natcasesort($ss);//puts buttons in natural case sorted order
for($n=-1;$n<=(count($ss)-1);$n++){$sp[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
$ss[$n]=get_string_between($ss[$n],'<w>','</w>');
$ss=array_values(array_unique($ss));
$ss = array_values($ss);
if($search==$ss[$n]){$style='style="background-color:#ff0" ';}else{$style='';};$sp[$n]=$ss[$n];$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces but not in posted word
if($ss[$n]!=''){echo '<div class="m1" onfocus="this.blur()" '.$style.'onclick="this.style.backgroundColor=\'#ff0\';document.form.word.value=\''.$sp[$n].'\';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.remove.value=\'1\';document.form.submit();},2000)" onmouseup="clearTimeout(timer)">'.$ss[$n].'</div>'."\n";};$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
};
?>
</div>
<div id='links'>
<?php
if (strlen($search)<2){//NO SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
if($title[$n]==''){$title[$n]=$url[$n];}
$im=' style="background-image:url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)" title="'.$n.'"';
if($n>1){echo '<a class="b1" target="new" href="'.$url[$n].'"'.$im.'>'.$title[$n].'</a>'."\n";};}
}
else{//SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$https=' (HTTPS)';}else{$https='';};
$im=' style="background-image:url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)" title="'.$n.'"';
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};echo '<a class="b1" target="new" href="'.$url[$n].'"'.$im.'>'.$title[$n].$https.'</a>'."\n";
};};};
?>
</div>
</body>
</html>


For a basic description of the script also refer to the description in my first post.

Edit Script 2 updated 01:20 UTC 2015-01-28 to place the list-1.txt, list-2.txt and list-3.txt button configuration files into the user configurable folders.
The 3 Master category buttons above the text box and the search category buttons under the text box can now be completely independent, specific and unique to the folder specified by the top left button.
This is an obvious and necessary refinement. Make sure you put the list-1.txt, list-2.txt and list-3.txt files (rw-rw-rw-) in the same folder as the bookmarks-whatever.html (rw-r--r--) file.

Please note: bookmarks.php code changed.
version-2-screenshots.jpg
 Description   
 Filesize   33.99 KB
 Viewed   234 Time(s)

version-2-screenshots.jpg


Last edited by kjdixo on Fri 13 Feb 2015, 06:45; edited 3 times in total
Back to top
View user's profile Send private message 
puppy_apprentice


Joined: 07 Feb 2012
Posts: 143

PostPosted: Sat 31 Jan 2015, 19:51    Post subject:  

Firefox-like browsers use SQLite database to store bookmarks. You can try to query Firefox bookmarks database directly without parsing html file.
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Sun 01 Feb 2015, 05:10    Post subject:  

Yes thanks for the tip, I did already know that.
My method as I described is fragile due to possible future changes in the bookmarks.html format.
Similar with parsing the bookmarks .json file.
Another purpose of my post was to showcase some working PHP and HTML forms to get people interested.
Incidentally, I created a bash script to gather the screenshots in post 2.
1. First modify the bookmarks.php code from post 2
Code:

if (strlen($search)<2){//NO SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
$fh=fopen('13e.txt','w');
fwrite($fh,''); //clear txtfile
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
if($title[$n]==''){$title[$n]=$url[$n];}
$im=' style="background-image:url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)" title="'.$n.'"';
if($n>1){echo '<a class="b1" target="new" href="'.$url[$n].'"'.$im.'>'.$title[$n].'</a>'."\n";
};

$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
}
else{//SEARCH


2. Then create 2 blank text files ABC.txt and 13e.txt (with read/write permissions), see them referenced in the code above and below.
Also create a folder build-1 in which to store the .png files.
Install cutycapt (screenshooter) and imagemagick. Use imagemagick (my version im6) identify and convert commands, see below.
This works to get 600px square screenshots (I managed to collect 500 using this recently) although my youtube page screenshots are blank for some reason.

Code:

#!/bin/sh
cd /root/httpd/hiawatha

# Load text file lines into a bash array.
OLD_IFS=$IFS
IFS=$'\n'
let line_counter=0
for line in $(cat "./13e.txt"); do
let line_counter=$(($line_counter+1))
printf "${line_counter}: ${line}\n"
cutycapt --url=${line} --max-wait=5000 --out="1/build-1/"${line_counter}.png
identify.im6 -format %w "1/build-1/"${line_counter}.png > ABC.txt
width=$(head -c 4 ABC.txt)
convert.im6 "1/build-1/"${line_counter}.png -crop $width'x'$width+0+0 -resize 600'x'600 "1/build-1/"${line_counter}.png
done
IFS=$OLD_IFS


Hope this helps.
If anyone wants to showcase an sqlite database method then that would be great, I would be interested, though I usually try to avoid databases.
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Sun 01 Feb 2015, 19:52    Post subject: FASTER ... Images only on mouseover
Subject description: Best of both worlds script 3. (script 1 with added image popups)
 

Loading 1200 images 600px square, slowed down my script 2 page.
Also script 2 did not show domains like script 1 did.
So script 3, here, combines all the features of script 1 (domain hide / unhide button) and script 2 (top left button for user definable bookmark folders).
The difference with this new script is each link has a span element whose background image only shows when the link is moused over.
The image is only loaded when needed. So it is a lot faster.
The span element displays within the link . . . however this might be slightly too dynamic for some people as the individual link heights keep changing when you hover over them.
It might be better to provide a relatively positioned popup next to the link list, so the link list remains static and readable, whilst popups occur to the right hand side of them.
I will post the code for the external popups next time.

Code:

<?php  // **** PREVENT BROWSER CACHE ****
//header('Cache-Control: no-cache, must-revalidate');
//header('Pragma: no-cache');
//header('Expires: Sat,1 Jan 2000 00:00:01 GMT');
error_reporting (E_ALL ^ E_NOTICE);
$search=$_POST['word'];
$list=$_POST['list'];
$hide_domain=$_POST['dn'];
if(strlen($hide_domain)<1) {$hide_domain=1;};
$folder=$_POST['folder'];
if(strlen($folder)<1) {$folder=1;};

$t1=$_POST['t1'];
$t2=$_POST['t2'];
$t3=$_POST['t3'];

$list1=@file_get_contents($folder.'/list-1.txt');
$list2=@file_get_contents($folder.'/list-2.txt');
$list3=@file_get_contents($folder.'/list-3.txt');

$title1=get_string_between($list1,'<t>','</t>');
$title2=get_string_between($list2,'<t>','</t>');
$title3=get_string_between($list3,'<t>','</t>');

if($_POST['button1']){//change button1 name by pressing for 2 seconds
$list1=str_replace('<t>'.$title1.'</t>','<t>'.$t1.'</t>',$list1);
$title1=$t1;
$list1=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list1);//strip some whitespace
$fh=fopen($folder.'/list-1.txt','w+');
fwrite($fh, $list1);
fclose($fh);
}

if($_POST['button2']){//change button2 name by pressing for 2 seconds
$list2=str_replace('<t>'.$title2.'</t>','<t>'.$t2.'</t>',$list2);
$title2=$t2;
$list2=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list2);//strip some whitespace
$fh=fopen($folder.'/list-2.txt','w+');
fwrite($fh, $list2);
fclose($fh);
}

if($_POST['button3']){//change button3 name by pressing for 2 seconds
$list3=str_replace('<t>'.$title3.'</t>','<t>'.$t3.'</t>',$list3);
$title3=$t3;
$list3=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list3);//strip some whitespace
$fh=fopen($folder.'/list-3.txt','w+');
fwrite($fh, $list3);
fclose($fh);
}

if(strlen($list)<1) {$list=1;};

$fg=0;//flag you are trying to add a name already in one of the lists

$ss1=explode('<s>', $list1);$ss1[0]=$ss1[1];
for($n=0;$n<=(count($ss1)-1);$n++){
$ss1[$n]=get_string_between($ss1[$n],'<w>','</w>');
if($ss1[$n]==$search){$fg=1;};}

$ss2=explode('<s>', $list2);$ss2[0]=$ss2[1];
for($n=0;$n<=(count($ss2)-1);$n++){
$ss2[$n]=get_string_between($ss2[$n],'<w>','</w>');
if($ss2[$n]==$search){$fg=1;};}

$ss3=explode('<s>', $list3);$ss3[0]=$ss3[1];
for($n=0;$n<=(count($ss3)-1);$n++){
$ss3[$n]=get_string_between($ss3[$n],'<w>','</w>');
if($ss3[$n]==$search){$fg=1;};}

if(($fg!=1)&&($search!='')&&($_POST['add'])){
$fh=fopen($folder.'/list-'.$list.'.txt','a+');
fwrite($fh,PHP_EOL.'<s><w>'.$search.'</w>'); //write to txtfile
fclose($fh);}

if($_POST['remove']){
$dat=@file_get_contents($folder.'/list-'.$list.'.txt');
$dat=str_replace('<s><w>'.$search.'</w>','', $dat);
$dat=preg_replace('/^\n+|^[\t\s]*\n+/m','',$dat);//strip some whitespace
$fh=fopen($folder.'/list-'.$list.'.txt','w+');
fwrite($fh, $dat);
fclose($fh);}

function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$links=$folder.'/bookmarks-'.$folder.'.html';
$pg1=@file_get_contents($links) or die ('<html><body><p>Sorry for any inconvenience, error 1, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
$file=$folder.'/list-'.$list.'.txt';
$pg2=@file_get_contents($file) or die ('<html><body><p>Sorry for any inconvenience, error 2, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Bookmarks</title>
<link rel="shortcut icon" href="bookmark.ico">
<style type="text/css">
body{font:normal 24px 'Arial';color:#000;background-color:#ddd;background-image:url(ptv2.jpg);}
a:link,a:visited,a:active{text-decoration:none;color:#036}
.m1,.r1{display:inline;float:left;border-radius:0.2em;cursor:pointer;font:bold 24px "Arial";padding:4px 4px 4px 4px;background-color:#bbb;color:#036;margin:4px 4px 4px 4px;border:solid 2px #040}
.r1{display:block;}
.m1:hover{background-color:#0ee;}
.r1:hover{background-color:#fdd;}
#form{display:block;margin-right:100%;margin-top:10px}
#links{display:block;float:left;width:100%;margin-top:10px;margin-bottom:10px}
#word{display:inline;width:200px;height:30px;margin:10px 10px 0px 6px;font:normal 24px 'Arial'}
#buttons{margin-top:-20px;width:670px}
.num{background-color:#eca;}
.b1{border-radius:0.2em;margin:auto;text-align:left;text-decoration:none;display:block;font:bold 24px "Arial";border:solid 1px #060;overflow:hidden;margin:4px 4px 4px 4px;color:#036;background-color:#bbb;min-height:30px;padding:4px 4px 4px 4px;width:638px}
.b1{color:#036;background-color:#ddd;}
.b1:hover{text-decoration:none;color:#036;background-color:#ff0}
.b1:visited{text-decoration:none;color:#000;background-color:#eca}
.s1{background-color:#e00;color:#fff;border-radius:0.2em}
.s2{background-color:#cec;color:#000;border-radius:0.2em}
.im{position:relative;display: block}
</style>
<script type="text/javascript">
<!--
if (top.location != self.location) {top.location = self.location}
function init()
{
document.form.reset();   
}
// -->
</script>
</head>
<body onload="document.form.add.value='0';document.form.button1.value='0';document.form.button2.value='0';document.form.button3.value='0';window.focus()" onunload="window.blur()">
<div class='m1' onfocus='this.blur()' onmousedown="timer=window.setTimeout(function(){document.form.folder.value=document.form.word.value;document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $folder; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='1'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='1';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t1.value=document.form.word.value;document.form.button1.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title1; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='2'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='2';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t2.value=document.form.word.value;document.form.button2.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title2; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='3'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='3';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t3.value=document.form.word.value;document.form.button3.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title3; ?></div>
<div class='r1' onfocus='this.blur()' onclick="document.form.dn.value='<?php if($hide_domain=='1'){echo '0';}else {echo '1';}?>';document.form.submit();">DOMAIN</div>
<form name="form" id="form" method="post" action="bookmarks.php">
<div>
<input type='text' style="" name='word' id='word' value='<?php echo $search; ?>' title='Search - (2 or more characters) - Then Hit Enter'>
<input type="hidden" name="add" value="0">
<input type="hidden" name="remove" value="0">
<input type="hidden" name="button1" value="0">
<input type="hidden" name="button2" value="0">
<input type="hidden" name="button3" value="0">
<input type="hidden" name="list" value="<?php echo $list; ?>">
<input type="hidden" name="t1" value="<?php echo $t1; ?>">
<input type="hidden" name="t2" value="<?php echo $t2; ?>">
<input type="hidden" name="t3" value="<?php echo $t3; ?>">
<input type="hidden" name="folder" value="<?php echo $folder; ?>">
<input type="hidden" name="dn" value="<?php echo $hide_domain; ?>">
<input style="visibility:hidden" type="submit" onclick="document.form.add.value='1';">
</div>
</form>
<div id='buttons'>
<div class='r1' onfocus='this.blur()' <?php if($search==''){echo ('style="background-color:#ff0" ');}?>onclick="this.style.backgroundColor='#ff0';document.form.word.value='';document.form.submit();">ALL</div>
<?php
$ss=explode('<s>', $pg2);
$ss[0]=$ss[1];
natcasesort($ss);//puts buttons in natural case sorted order
for($n=-1;$n<=(count($ss)-1);$n++){$sp[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
$ss[$n]=get_string_between($ss[$n],'<w>','</w>');
$ss=array_values(array_unique($ss));
$ss = array_values($ss);
if($search==$ss[$n]){$style='style="background-color:#ff0" ';}else{$style='';};$sp[$n]=$ss[$n];$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces but not in posted word
if($ss[$n]!=''){echo '<div class="m1" onfocus="this.blur()" '.$style.'onclick="this.style.backgroundColor=\'#ff0\';document.form.word.value=\''.$sp[$n].'\';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.remove.value=\'1\';document.form.submit();},2000)" onmouseup="clearTimeout(timer)">'.$ss[$n].'</div>'."\n";};$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
};
?>
</div>
<div id='links'>
<?php
if (strlen($search)<2){//NO SEARCH
if($hide_domain=='1'){//domain hidden
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
}else{//domain visible
$pg1 = str_replace('<DT><H3','', $pg1);//replace
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace
$pg1 = preg_replace('/^\n+|^[\t\s]*\n+/m','',$pg1);//strip some whitespace
$tt=explode('<DT>', $pg1);
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
natcasesort($tt);//puts urls of links in natural case sorted order
}
$fh=fopen('13e.txt','w');
fwrite($fh,''); //clear txtfile
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
if($title[$n]==''){$title[$n]=$url[$n];}
if($hide_domain=='0'){$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';}else{$dn='';};
if($n>1){echo '<a class="b1" target="new" href="'.$url[$n].'" onmouseover="img'.$n.'=getElementById(\'im'.$n.'\');img'.$n.'.style.width=\'600px\';img'.$n.'.style.height=\'600px\';img'.$n.'.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'" onmouseout="img'.$n.'.style.width=\'0px\';img'.$n.'.style.height=\'0px\';">'.$dn.''.$title[$n].'<span class="im" id=im'.$n.' title="'.$n.'"></span></a>'."\n";
};
$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
}
else{//SEARCH
if($hide_domain=='1'){//domain hidden
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
}else{//domain visible   
$pg1 = str_replace('<DT><H3','', $pg1);//replace
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace
$pg1 = preg_replace('/^\n+|^[\t\s]*\n+/m','',$pg1);//strip some whitespace
$tt=explode('<DT>', $pg1);
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
//$tt=array_unique($tt);//removes array duplicates
natcasesort($tt);//puts urls of links in natural case sorted order
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
}
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
//$domain[$n]= str_replace('www.','',$domain[$n]);//replace
if($hide_domain=='0'){$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';}else{$dn='';};
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};echo '<a class="b1" target="new" href="'.$url[$n].'" onmouseover="img'.$n.'=getElementById(\'im'.$n.'\');img'.$n.'.style.width=\'600px\';img'.$n.'.style.height=\'600px\';img'.$n.'.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'" onmouseout="img'.$n.'.style.width=\'0px\';img'.$n.'.style.height=\'0px\';">'.$dn.''.$title[$n].'<span class="im" id=im'.$n.' title="'.$n.'"></span></a>'."\n";
};};};
?>
</div>
</body>
</html>

Last edited by kjdixo on Mon 09 Feb 2015, 16:07; edited 1 time in total
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Sun 01 Feb 2015, 22:08    Post subject: POPUPS to one side instead of within Links
Subject description: Change CSS code to display screenshots in centre of window.
 

The screenshot will now be in a fixed position 'popup' to the right of the links instead of within the links themselves.

Change this: .im{position:relative;display: block}
To this: .im{position:fixed;top:100px;left:700px;}

I also noticed the array indexing is different between domain visible and domain hidden, so I need to fix that, so the correct screenshots are shown when the domain names are visible. They are correct when the domain names are hidden.
Nearly there . . .
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Mon 02 Feb 2015, 11:53    Post subject: Domains display correctly and POPUPS to one side.
Subject description: Fixed this: array indexing was different between domain visible and domain hidden
 

This works quite well.
Points to note:
1. It will alphabetically list by title, but not by domain, however you can search for a domain, and all the urls in that domain will be listed.
2. Domains can be shown or hidden.
3. Search and add/remove buttons work as in script 1.
4. There is a screenshot popup to the right hand side.
5. I used the Bash Script from an earlier post to collect 1242 screenshots from 1242 web sites in about 2 hours.
6. If the bash script halts or the internet connection is interrupted, simply restart from where you left off (in the bash script change the code: 'let line_counter=0' to: 'let line_counter=800' for example, and make sure you manually delete the urls 1 to 799 from the file 13e.txt before proceeding with the thumbs.sh bash script).
7. If the bash script stops because of one particular website then skip that one and do a manual screenshot later.
8. I definitely, definitely want to make this easier to set up.
9. Also automate adding new bookmarks without the need to recapture all the screenshots.
10. You have been watching a 'work in progress', I hope to improve this sometime in the future.

Code:

<?php  // **** PREVENT BROWSER CACHE ****
//header('Cache-Control: no-cache, must-revalidate');
//header('Pragma: no-cache');
//header('Expires: Sat,1 Jan 2000 00:00:01 GMT');
error_reporting (E_ALL ^ E_NOTICE);
$search=$_POST['word'];
$list=$_POST['list'];
$hide_domain=$_POST['dn'];
if(strlen($hide_domain)<1) {$hide_domain=1;};
$folder=$_POST['folder'];
if(strlen($folder)<1) {$folder=1;};

$t1=$_POST['t1'];
$t2=$_POST['t2'];
$t3=$_POST['t3'];

$list1=@file_get_contents($folder.'/list-1.txt');
$list2=@file_get_contents($folder.'/list-2.txt');
$list3=@file_get_contents($folder.'/list-3.txt');

$title1=get_string_between($list1,'<t>','</t>');
$title2=get_string_between($list2,'<t>','</t>');
$title3=get_string_between($list3,'<t>','</t>');

if($_POST['button1']){//change button1 name by pressing for 2 seconds
$list1=str_replace('<t>'.$title1.'</t>','<t>'.$t1.'</t>',$list1);
$title1=$t1;
$list1=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list1);//strip some whitespace
$fh=fopen($folder.'/list-1.txt','w+');
fwrite($fh, $list1);
fclose($fh);
}

if($_POST['button2']){//change button2 name by pressing for 2 seconds
$list2=str_replace('<t>'.$title2.'</t>','<t>'.$t2.'</t>',$list2);
$title2=$t2;
$list2=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list2);//strip some whitespace
$fh=fopen($folder.'/list-2.txt','w+');
fwrite($fh, $list2);
fclose($fh);
}

if($_POST['button3']){//change button3 name by pressing for 2 seconds
$list3=str_replace('<t>'.$title3.'</t>','<t>'.$t3.'</t>',$list3);
$title3=$t3;
$list3=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list3);//strip some whitespace
$fh=fopen($folder.'/list-3.txt','w+');
fwrite($fh, $list3);
fclose($fh);
}

if(strlen($list)<1) {$list=1;};

$fg=0;//flag you are trying to add a name already in one of the lists

$ss1=explode('<s>', $list1);$ss1[0]=$ss1[1];
for($n=0;$n<=(count($ss1)-1);$n++){
$ss1[$n]=get_string_between($ss1[$n],'<w>','</w>');
if($ss1[$n]==$search){$fg=1;};}

$ss2=explode('<s>', $list2);$ss2[0]=$ss2[1];
for($n=0;$n<=(count($ss2)-1);$n++){
$ss2[$n]=get_string_between($ss2[$n],'<w>','</w>');
if($ss2[$n]==$search){$fg=1;};}

$ss3=explode('<s>', $list3);$ss3[0]=$ss3[1];
for($n=0;$n<=(count($ss3)-1);$n++){
$ss3[$n]=get_string_between($ss3[$n],'<w>','</w>');
if($ss3[$n]==$search){$fg=1;};}

if(($fg!=1)&&($search!='')&&($_POST['add'])){
$fh=fopen($folder.'/list-'.$list.'.txt','a+');
fwrite($fh,PHP_EOL.'<s><w>'.$search.'</w>'); //write to txtfile
fclose($fh);}

if($_POST['remove']){
$dat=@file_get_contents($folder.'/list-'.$list.'.txt');
$dat=str_replace('<s><w>'.$search.'</w>','', $dat);
$dat=preg_replace('/^\n+|^[\t\s]*\n+/m','',$dat);//strip some whitespace
$fh=fopen($folder.'/list-'.$list.'.txt','w+');
fwrite($fh, $dat);
fclose($fh);}

function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$links=$folder.'/bookmarks-'.$folder.'.html';
$pg1=@file_get_contents($links) or die ('<html><body><p>Sorry for any inconvenience, error 1, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
$file=$folder.'/list-'.$list.'.txt';
$pg2=@file_get_contents($file) or die ('<html><body><p>Sorry for any inconvenience, error 2, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Bookmarks</title>
<link rel="shortcut icon" href="bookmark.ico">
<style type="text/css">
body{font:normal 24px 'Arial';color:#000;background-color:#ddd;background-image:url(ptv2.jpg);}
a:link,a:visited,a:active{text-decoration:none;color:#036}
.m1,.r1{display:inline;float:left;border-radius:0.2em;cursor:pointer;font:bold 24px "Arial";padding:4px 4px 4px 4px;background-color:#bbb;color:#036;margin:4px 4px 4px 4px;border:solid 2px #040}
.r1{display:block;}
.m1:hover{background-color:#0ee;}
.r1:hover{background-color:#fdd;}
#form{display:block;margin-right:100%;margin-top:10px}
#links{display:block;float:left;width:100%;margin-top:10px;margin-bottom:10px}
#word{display:inline;width:200px;height:30px;margin:10px 10px 0px 6px;font:normal 24px 'Arial'}
#buttons{margin-top:-20px;width:670px}
.num{background-color:#eca;}
.b1{border-radius:0.2em;margin:auto;text-align:left;text-decoration:none;display:block;font:bold 24px "Arial";border:solid 1px #060;overflow:hidden;margin:4px 4px 4px 4px;color:#036;background-color:#bbb;min-height:30px;padding:4px 4px 4px 4px;width:638px}
.b1{color:#036;background-color:#ddd;}
.b1:hover{text-decoration:none;color:#036;background-color:#ff0}
.b1:visited{text-decoration:none;color:#000;background-color:#eca}
.s1{background-color:#e00;color:#fff;border-radius:0.2em}
.s2{background-color:#cec;color:#000;border-radius:0.2em}
.im{position:fixed;top:100px;left:700px;border-radius:0.2em;}
</style>
<script type="text/javascript">
<!--
if (top.location != self.location) {top.location = self.location}
function init()
{
document.form.reset();   
}
// -->
</script>
</head>
<body onload="document.form.add.value='0';document.form.button1.value='0';document.form.button2.value='0';document.form.button3.value='0';window.focus()" onunload="window.blur()">
<div class='m1' onfocus='this.blur()' onmousedown="timer=window.setTimeout(function(){document.form.folder.value=document.form.word.value;document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $folder; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='1'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='1';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t1.value=document.form.word.value;document.form.button1.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title1; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='2'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='2';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t2.value=document.form.word.value;document.form.button2.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title2; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='3'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='3';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t3.value=document.form.word.value;document.form.button3.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title3; ?></div>
<div class='r1' onfocus='this.blur()' onclick="document.form.dn.value='<?php if($hide_domain=='1'){echo '0';}else {echo '1';}?>';document.form.submit();">DOMAIN</div>
<form name="form" id="form" method="post" action="bookmarks.php">
<div>
<input type='text' style="" name='word' id='word' value='<?php echo $search; ?>' title='Search - (2 or more characters) - Then Hit Enter'>
<input type="hidden" name="add" value="0">
<input type="hidden" name="remove" value="0">
<input type="hidden" name="button1" value="0">
<input type="hidden" name="button2" value="0">
<input type="hidden" name="button3" value="0">
<input type="hidden" name="list" value="<?php echo $list; ?>">
<input type="hidden" name="t1" value="<?php echo $t1; ?>">
<input type="hidden" name="t2" value="<?php echo $t2; ?>">
<input type="hidden" name="t3" value="<?php echo $t3; ?>">
<input type="hidden" name="folder" value="<?php echo $folder; ?>">
<input type="hidden" name="dn" value="<?php echo $hide_domain; ?>">
<input style="visibility:hidden" type="submit" onclick="document.form.add.value='1';">
</div>
</form>
<div id='buttons'>
<div class='r1' onfocus='this.blur()' <?php if($search==''){echo ('style="background-color:#ff0" ');}?>onclick="this.style.backgroundColor='#ff0';document.form.word.value='';document.form.submit();">ALL</div>
<?php
$ss=explode('<s>', $pg2);
$ss[0]=$ss[1];
natcasesort($ss);//puts buttons in natural case sorted order
for($n=-1;$n<=(count($ss)-1);$n++){$sp[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
$ss[$n]=get_string_between($ss[$n],'<w>','</w>');
$ss=array_values(array_unique($ss));
$ss = array_values($ss);
if($search==$ss[$n]){$style='style="background-color:#ff0" ';}else{$style='';};$sp[$n]=$ss[$n];$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces but not in posted word
if($ss[$n]!=''){echo '<div class="m1" onfocus="this.blur()" '.$style.'onclick="this.style.backgroundColor=\'#ff0\';document.form.word.value=\''.$sp[$n].'\';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.remove.value=\'1\';document.form.submit();},2000)" onmouseup="clearTimeout(timer)">'.$ss[$n].'</div>'."\n";};$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
};
?>
</div>
<div id='links'>
<?php
if (strlen($search)<2){//NO SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){
$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';//combine arrays for sorting if domain hidden
}
natcasesort($tt);//puts titles in natural case sorted order
$fh=fopen('13e.txt','w');
fwrite($fh,''); //clear txtfile
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
if($title[$n]==''){$title[$n]=$url[$n];}
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};   
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img'.$n.'=getElementById(\'im'.$n.'\');img'.$n.'.style.width=\'600px\';img'.$n.'.style.height=\'600px\';img'.$n.'.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'" onmouseout="img'.$n.'.style.width=\'0px\';img'.$n.'.style.height=\'0px\';">'.$dn.''.$title[$n].'<span class="im" id="im'.$n.'"></span></a>'."\n";};
}
else{
if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img'.$n.'=getElementById(\'im'.$n.'\');img'.$n.'.style.width=\'600px\';img'.$n.'.style.height=\'600px\';img'.$n.'.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'" onmouseout="img'.$n.'.style.width=\'0px\';img'.$n.'.style.height=\'0px\';">'.$title[$n].'<span class="im" id="im'.$n.'"></span></a>'."\n";};   
}
$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
}
else{//SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img'.$n.'=getElementById(\'im'.$n.'\');img'.$n.'.style.width=\'600px\';img'.$n.'.style.height=\'600px\';img'.$n.'.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'" onmouseout="img'.$n.'.style.width=\'0px\';img'.$n.'.style.height=\'0px\';">'.$dn.''.$title[$n].'<span class="im" id="im'.$n.'"></span></a>'."\n";};
};}
else{
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);   
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img'.$n.'=getElementById(\'im'.$n.'\');img'.$n.'.style.width=\'600px\';img'.$n.'.style.height=\'600px\';img'.$n.'.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'" onmouseout="img'.$n.'.style.width=\'0px\';img'.$n.'.style.height=\'0px\';">'.$title[$n].'<span class="im" id="im'.$n.'"></span></a>'."\n";};   
}
};}
$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
?>
</div>
</body>
</html>

Last edited by kjdixo on Mon 09 Feb 2015, 16:05; edited 1 time in total
Back to top
View user's profile Send private message 
puppy_apprentice


Joined: 07 Feb 2012
Posts: 143

PostPosted: Thu 05 Feb 2015, 19:56    Post subject:  

Windows batch script (index.cmd) that collects data (tags names, folders names and links) directly from Firefox database (places.sqlite).



Code:

:: by puppy_apprentice, GPL
:: turn off commands echoing
@echo off

:: send proper header
echo Content-type: text/html
echo.

:: send html stuff
echo ^<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"^>^<html^>
echo ^<head^>
echo ^<META http-equiv="Content-Type" content="text/html; charset=UTF-8"^>
echo ^<link rel="stylesheet" type="text/css" href="style.css"^>
echo ^<title^>Firefox Bookmarks^</title^>
echo ^</head^>
echo ^<body^>
echo ^<div id="header"^>Firefox Bookmarks^</div^>
if not exist "places.sqlite" (
   echo ^<div id="content"^>
   echo Cannot continue database not found...
   echo ^</div^>
   goto :finish
)
echo ^<div id="tags"^>

:: query database for tags
for /F "tokens=1,2 delims=   " %%i in ('sqlite3.exe -separator "   " -nullvalue "NO VALUE" places.sqlite "select id, title from moz_bookmarks where parent = '4' order by title;"') do echo ^<a href="index.cmd?tag=%%i"^>%%j^</a^>

:: send html stuff
echo ^<form action="index.cmd" method="get"^>
echo ^<input type="text" name="phrase"^>
echo ^<input type="submit" value="Search"^>
echo ^</form^>
echo ^</div^>
echo ^<div id="folders"^>

:: query database for folders
for /F "tokens=1,2 delims=   " %%i in ('sqlite3.exe -separator "   " -nullvalue "NO VALUE" places.sqlite "select id, title from moz_bookmarks where type = '2' and parent != '4' and title != '' and title != 'All Bookmarks' and title != 'Mozilla Firefox' and title != 'Tags' order by title;"') do echo ^<p^>^<a href="index.cmd?folder=%%i"^>%%j^</a^>^</p^>

:: send html stuff
echo ^</div^>
echo ^<div id="content"^>
:: check if variable query string exist and initialize variables folder or phrase and initialize variable counter
if defined QUERY_STRING (
   set %QUERY_STRING%
   set count=0
) else (
   goto :finish
)

:: send html stuff
echo ^<table border="0" cellspacing="1" cellpadding="4"^>

:: check if variable tag exist and query database for data
if defined tag (
   for /F "tokens=1,2 delims=   " %%i in ('sqlite3.exe -separator "   " -nullvalue "NO VALUE" places.sqlite "select moz_places.url, moz_places.title from moz_bookmarks, moz_places where moz_bookmarks.fk = moz_places.id and moz_bookmarks.parent = '%tag%' and moz_places.url glob '*:*' order by moz_bookmarks.title;"') do (
      echo ^<tr^>^<td class="title"^>%%j^</td^>^</tr^>^<tr^>^<td^>^<a href="%%i"^>%%i^</a^>^</td^>^</tr^>
      set /a count+=1
   )
)

:: check if variable folder exist and query database for data
if defined folder (
   for /F "tokens=1,2 delims=   " %%i in ('sqlite3.exe -separator "   " -nullvalue "NO VALUE" places.sqlite "select moz_places.url, moz_bookmarks.title from moz_bookmarks, moz_places where moz_bookmarks.fk = moz_places.id and moz_bookmarks.parent = '%folder%' and moz_places.url glob '*:*' order by moz_bookmarks.title;"') do (
      echo ^<tr^>^<td class="title"^>%%j^</td^>^</tr^>^<tr^>^<td^>^<a href="%%i"^>%%i^</a^>^</td^>^</tr^>
      set /a count+=1
   )
)

:: check if variable phrase exist and query database for data
if defined phrase (
   for /F "tokens=1,2 delims=   " %%i in ('sqlite3.exe -separator "   " -nullvalue "NO VALUE" places.sqlite "select moz_places.url, moz_bookmarks.title from moz_bookmarks, moz_places where moz_bookmarks.fk = moz_places.id and (moz_places.url like '%%%phrase%%%' or moz_bookmarks.title like '%%%phrase%%%') order by moz_bookmarks.title;"') do (
      echo ^<tr^>^<td class="title"^>%%j^</td^>^</tr^>^<tr^>^<td^>^<a href="%%i"^>%%i^</a^>^</td^>^</tr^>
      set /a count+=1
   )
)

:: send value of count variable
echo ^<caption^>Number of items: %count%^</caption^>
echo ^</table^>

:finish
:: send html stuff
echo ^</div^>
echo ^<div id="footer"^>by puppy_apprentice, GPL^</div^>
echo ^</body^>
echo ^</html^>


You have to copy places.sqlite file to folder with my script. Run mongoose server and in the internet browser use address: localhost:8080.

Later i will write versions for PHP and Linux Bash.

Download:
http://przeklej.org/file/hwHglP/package.zip

Last edited by puppy_apprentice on Thu 12 Feb 2015, 16:58; edited 1 time in total
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Fri 06 Feb 2015, 04:53    Post subject: Windows batch script / Firefox database (places.sqlite)
Subject description: Windows batch script (index.cmd) that collects data (tags names, folders names and links)
 

Quote:
Later i will write versions for PHP and Linux Bash

Excellent
Thank you very much, I will wait for your Linux version as I have only one Windows XP computer and it does not have a browser and is always offline, I use it to install and run old Windows program discs that I sometimes buy from charity shops or flea markets.
A Linux version would be better for me.
no hurry ...
I realise what I have done so far is not the finished item.
I am thinking of creating a similar interface to a 'Speed Dial' with 10 screenshots loading at a time, and tiny thumbnails on every link.
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Fri 06 Feb 2015, 06:38    Post subject: Permanently visible div background for the screenshots
Subject description: Placeholder for screenshots so they don't flash on/off annoyingly
 

Optional addition to Mon 02 Feb 2015, 11:53 Post subject: Domains display correctly and POPUPS to one side.

Provides a permanently visible div background for the screenshots, rather than them appearing and disappearing on a blank background. It is better . . . a more 'user friendly' transition between screenshots.

Edited Feb 7th 2015, I have also made the link code less bloated
Edited Feb 7th 2015 14:24 UTC to combine css hover code and mouseover code for .b1 links
Edited Feb 7th 2015 20:15 UTC to make the popup image clickable so it has the correct href and title
Note that the <div> (sd) is now an <a> tag and the default link is:
Code:
<a href="http://localhost/bookmarks.php" title="Bookmarks" id="sd">Bookmarks</a>

The b1 link list when moused over, rewrites the (sd) <a> tag with the appropriate url and title.
The following tips and tricks helped me with this:
1. http://codingforums.com/javascript-programming/25333-can-javascript-change-links-href.html
2. http://ran.ge/2012/04/03/css-trick-turning-a-background-image-into-a-clickable-link-take-2/
3. When the image is clicked the url will open in the same browser window/tab.
If you want it to open in another tab/window then add the following target="new" to the default (sd) <a> tag.
Code:
<a href="http://localhost/bookmarks.php" target="new" title="Bookmarks" id="sd">Bookmarks</a>

The modified bookmarks.php
Code:

<?php  // **** PREVENT BROWSER CACHE ****
//header('Cache-Control: no-cache, must-revalidate');
//header('Pragma: no-cache');
//header('Expires: Sat,1 Jan 2000 00:00:01 GMT');
error_reporting (E_ALL ^ E_NOTICE);
$search=$_POST['word'];
$list=$_POST['list'];
$hide_domain=$_POST['dn'];
if(strlen($hide_domain)<1) {$hide_domain=1;};
$folder=$_POST['folder'];
if(strlen($folder)<1) {$folder=1;};

$t1=$_POST['t1'];
$t2=$_POST['t2'];
$t3=$_POST['t3'];

$list1=@file_get_contents($folder.'/list-1.txt');
$list2=@file_get_contents($folder.'/list-2.txt');
$list3=@file_get_contents($folder.'/list-3.txt');

$title1=get_string_between($list1,'<t>','</t>');
$title2=get_string_between($list2,'<t>','</t>');
$title3=get_string_between($list3,'<t>','</t>');

if($_POST['button1']){//change button1 name by pressing for 2 seconds
$list1=str_replace('<t>'.$title1.'</t>','<t>'.$t1.'</t>',$list1);
$title1=$t1;
$list1=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list1);//strip some whitespace
$fh=fopen($folder.'/list-1.txt','w+');
fwrite($fh, $list1);
fclose($fh);
}

if($_POST['button2']){//change button2 name by pressing for 2 seconds
$list2=str_replace('<t>'.$title2.'</t>','<t>'.$t2.'</t>',$list2);
$title2=$t2;
$list2=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list2);//strip some whitespace
$fh=fopen($folder.'/list-2.txt','w+');
fwrite($fh, $list2);
fclose($fh);
}

if($_POST['button3']){//change button3 name by pressing for 2 seconds
$list3=str_replace('<t>'.$title3.'</t>','<t>'.$t3.'</t>',$list3);
$title3=$t3;
$list3=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list3);//strip some whitespace
$fh=fopen($folder.'/list-3.txt','w+');
fwrite($fh, $list3);
fclose($fh);
}

if(strlen($list)<1) {$list=1;};

$fg=0;//flag you are trying to add a name already in one of the lists

$ss1=explode('<s>', $list1);$ss1[0]=$ss1[1];
for($n=0;$n<=(count($ss1)-1);$n++){
$ss1[$n]=get_string_between($ss1[$n],'<w>','</w>');
if($ss1[$n]==$search){$fg=1;};}

$ss2=explode('<s>', $list2);$ss2[0]=$ss2[1];
for($n=0;$n<=(count($ss2)-1);$n++){
$ss2[$n]=get_string_between($ss2[$n],'<w>','</w>');
if($ss2[$n]==$search){$fg=1;};}

$ss3=explode('<s>', $list3);$ss3[0]=$ss3[1];
for($n=0;$n<=(count($ss3)-1);$n++){
$ss3[$n]=get_string_between($ss3[$n],'<w>','</w>');
if($ss3[$n]==$search){$fg=1;};}

if(($fg!=1)&&($search!='')&&($_POST['add'])){
$fh=fopen($folder.'/list-'.$list.'.txt','a+');
fwrite($fh,PHP_EOL.'<s><w>'.$search.'</w>'); //write to txtfile
fclose($fh);}

if($_POST['remove']){
$dat=@file_get_contents($folder.'/list-'.$list.'.txt');
$dat=str_replace('<s><w>'.$search.'</w>','', $dat);
$dat=preg_replace('/^\n+|^[\t\s]*\n+/m','',$dat);//strip some whitespace
$fh=fopen($folder.'/list-'.$list.'.txt','w+');
fwrite($fh, $dat);
fclose($fh);}

function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$links=$folder.'/bookmarks-'.$folder.'.html';
$pg1=@file_get_contents($links) or die ('<html><body><p>Sorry for any inconvenience, error 1, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
$file=$folder.'/list-'.$list.'.txt';
$pg2=@file_get_contents($file) or die ('<html><body><p>Sorry for any inconvenience, error 2, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Bookmarks</title>
<link rel="shortcut icon" href="bookmark.ico">
<style type="text/css">
body{font:normal 24px 'Arial';color:#000;background-color:#ddd;background-image:url(ptv2.jpg);}
a:link,a:visited,a:active{text-decoration:none;color:#036}
.m1,.r1{display:inline;float:left;border-radius:0.2em;cursor:pointer;font:bold 24px "Arial";padding:4px 4px 4px 4px;background-color:#bbb;color:#036;margin:4px 4px 4px 4px;border:solid 2px #040}
.r1{display:block;}
.m1:hover{background-color:#0ee;}
.r1:hover{background-color:#fdd;}
#form{display:block;margin-right:100%;margin-top:10px}
#links{display:block;float:left;width:100%;margin-top:10px;margin-bottom:10px}
#word{display:inline;width:200px;height:30px;margin:10px 10px 0px 6px;font:normal 24px 'Arial'}
#buttons{margin-top:-20px;width:670px}
.num{background-color:#eca;}
.b1{border-radius:0.2em;margin:auto;text-align:left;text-decoration:none;display:block;font:bold 24px "Arial";border:solid 1px #060;overflow:hidden;margin:4px 4px 4px 4px;color:#036;background-color:#bbb;min-height:30px;padding:4px 4px 4px 4px;width:638px}
.b1{color:#036;background-color:#ddd;}
.b1:hover{text-decoration:none;color:#036;background-color:#eee}
.b1:visited{text-decoration:none;color:#000;background-color:#eca}
.s1{background-color:#e00;color:#fff;border-radius:0.2em}
.s2{background-color:#cec;color:#000;border-radius:0.2em}
#sd{position:fixed;top:100px;left:700px;border-radius:0.2em;background-color:#eee;height:600px;width:600px;border:1px solid #ccc;display:block;overflow:hidden;text-indent:100%;white-space:nowrap}
</style>
<script type="text/javascript">
<!--
if (top.location != self.location) {top.location = self.location}
function init()
{
document.form.reset();   
}
// -->
</script>
</head>
<body onload="document.form.add.value='0';document.form.button1.value='0';document.form.button2.value='0';document.form.button3.value='0';window.focus()" onunload="window.blur()">
<div class='m1' onfocus='this.blur()' onmousedown="timer=window.setTimeout(function(){document.form.folder.value=document.form.word.value;document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $folder; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='1'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='1';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t1.value=document.form.word.value;document.form.button1.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title1; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='2'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='2';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t2.value=document.form.word.value;document.form.button2.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title2; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='3'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='3';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t3.value=document.form.word.value;document.form.button3.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title3; ?></div>
<div class='r1' onfocus='this.blur()' onclick="document.form.dn.value='<?php if($hide_domain=='1'){echo '0';}else {echo '1';}?>';document.form.submit();">DOMAIN</div>
<form name="form" id="form" method="post" action="bookmarks.php">
<div>
<input type='text' style="" name='word' id='word' value='<?php echo $search; ?>' title='Search - (2 or more characters) - Then Hit Enter'>
<input type="hidden" name="add" value="0">
<input type="hidden" name="remove" value="0">
<input type="hidden" name="button1" value="0">
<input type="hidden" name="button2" value="0">
<input type="hidden" name="button3" value="0">
<input type="hidden" name="list" value="<?php echo $list; ?>">
<input type="hidden" name="t1" value="<?php echo $t1; ?>">
<input type="hidden" name="t2" value="<?php echo $t2; ?>">
<input type="hidden" name="t3" value="<?php echo $t3; ?>">
<input type="hidden" name="folder" value="<?php echo $folder; ?>">
<input type="hidden" name="dn" value="<?php echo $hide_domain; ?>">
<input style="visibility:hidden" type="submit" onclick="document.form.add.value='1';">
</div>
</form>
<div id='buttons'>
<div class='r1' onfocus='this.blur()' <?php if($search==''){echo ('style="background-color:#ff0" ');}?>onclick="this.style.backgroundColor='#ff0';document.form.word.value='';document.form.submit();">ALL</div>
<?php
$ss=explode('<s>', $pg2);
$ss[0]=$ss[1];
natcasesort($ss);//puts buttons in natural case sorted order
for($n=-1;$n<=(count($ss)-1);$n++){$sp[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
$ss[$n]=get_string_between($ss[$n],'<w>','</w>');
$ss=array_values(array_unique($ss));
$ss = array_values($ss);
if($search==$ss[$n]){$style='style="background-color:#ff0" ';}else{$style='';};$sp[$n]=$ss[$n];$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces but not in posted word
if($ss[$n]!=''){echo '<div class="m1" onfocus="this.blur()" '.$style.'onclick="this.style.backgroundColor=\'#ff0\';document.form.word.value=\''.$sp[$n].'\';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.remove.value=\'1\';document.form.submit();},2000)" onmouseup="clearTimeout(timer)">'.$ss[$n].'</div>'."\n";};$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
};
?>
</div>
<div id='links'>
<a href="http://localhost/bookmarks.php" title="Bookmarks" id="sd">Bookmarks</a>
<?php
if (strlen($search)<2){//NO SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){
$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';//combine arrays for sorting if domain hidden
}
natcasesort($tt);//puts titles in natural case sorted order
$fh=fopen('13e.txt','w');
fwrite($fh,''); //clear txtfile
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
if($title[$n]==''){$title[$n]=$url[$n];}
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};   
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'">'.$dn.''.$title[$n].'</a>'."\n";};
}
else{
if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'">'.$title[$n].'</a>'."\n";};   
}
$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
}
else{//SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
$i=0;
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'">'.$dn.''.$title[$n].'</a>'."\n";};
};}
else{
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'">'.$title[$n].'</a>'."\n";};   
}
};};

$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
?>
</div>
</body>
</html>

Last edited by kjdixo on Mon 09 Feb 2015, 16:03; edited 1 time in total
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Sun 08 Feb 2015, 14:32    Post subject: Scrolling Link List and Layout rearranged
Subject description: Scrolling Link List and Layout rearranged - see the image attached
 

Shifted the layout around a bit and made a scrolling link list.
I think this makes it much easier to navigate the links.

Edit Feb 8th 2015 21:10 UTC: Noticed that a single quote in a link title, stopped its screenshot from being displayed.
A quick solution was to change all single quotes (and-hash-39-semicolon) to single right quotes (and-hash-146-semicolon) whilst parsing the firefox bookmarks.html file. . . There might be a more elegant solution than that, but it works.
I have not copied and pasted this modification into the code below as the forum will change the (and-hash-39-semicolon) and display a single quote, which will break the code if it is copied and pasted.
Instead I have included the two lines of code as .jpg files see lines 180 and 223 in the .jpg attachments below.

Code:

<?php  // **** PREVENT BROWSER CACHE ****
//header('Cache-Control: no-cache, must-revalidate');
//header('Pragma: no-cache');
//header('Expires: Sat,1 Jan 2000 00:00:01 GMT');
error_reporting (E_ALL ^ E_NOTICE);
$search=$_POST['word'];
$list=$_POST['list'];
$hide_domain=$_POST['dn'];
if(strlen($hide_domain)<1) {$hide_domain=1;};
$folder=$_POST['folder'];
if(strlen($folder)<1) {$folder=1;};

$t1=$_POST['t1'];
$t2=$_POST['t2'];
$t3=$_POST['t3'];

$list1=@file_get_contents($folder.'/list-1.txt');
$list2=@file_get_contents($folder.'/list-2.txt');
$list3=@file_get_contents($folder.'/list-3.txt');

$title1=get_string_between($list1,'<t>','</t>');
$title2=get_string_between($list2,'<t>','</t>');
$title3=get_string_between($list3,'<t>','</t>');

if($_POST['button1']){//change button1 name by pressing for 2 seconds
$list1=str_replace('<t>'.$title1.'</t>','<t>'.$t1.'</t>',$list1);
$title1=$t1;
$list1=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list1);//strip some whitespace
$fh=fopen($folder.'/list-1.txt','w+');
fwrite($fh, $list1);
fclose($fh);
}

if($_POST['button2']){//change button2 name by pressing for 2 seconds
$list2=str_replace('<t>'.$title2.'</t>','<t>'.$t2.'</t>',$list2);
$title2=$t2;
$list2=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list2);//strip some whitespace
$fh=fopen($folder.'/list-2.txt','w+');
fwrite($fh, $list2);
fclose($fh);
}

if($_POST['button3']){//change button3 name by pressing for 2 seconds
$list3=str_replace('<t>'.$title3.'</t>','<t>'.$t3.'</t>',$list3);
$title3=$t3;
$list3=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list3);//strip some whitespace
$fh=fopen($folder.'/list-3.txt','w+');
fwrite($fh, $list3);
fclose($fh);
}

if(strlen($list)<1) {$list=1;};

$fg=0;//flag you are trying to add a name already in one of the lists

$ss1=explode('<s>', $list1);$ss1[0]=$ss1[1];
for($n=0;$n<=(count($ss1)-1);$n++){
$ss1[$n]=get_string_between($ss1[$n],'<w>','</w>');
if($ss1[$n]==$search){$fg=1;};}

$ss2=explode('<s>', $list2);$ss2[0]=$ss2[1];
for($n=0;$n<=(count($ss2)-1);$n++){
$ss2[$n]=get_string_between($ss2[$n],'<w>','</w>');
if($ss2[$n]==$search){$fg=1;};}

$ss3=explode('<s>', $list3);$ss3[0]=$ss3[1];
for($n=0;$n<=(count($ss3)-1);$n++){
$ss3[$n]=get_string_between($ss3[$n],'<w>','</w>');
if($ss3[$n]==$search){$fg=1;};}

if(($fg!=1)&&($search!='')&&($_POST['add'])){
$fh=fopen($folder.'/list-'.$list.'.txt','a+');
fwrite($fh,PHP_EOL.'<s><w>'.$search.'</w>'); //write to txtfile
fclose($fh);}

if($_POST['remove']){
$dat=@file_get_contents($folder.'/list-'.$list.'.txt');
$dat=str_replace('<s><w>'.$search.'</w>','', $dat);
$dat=preg_replace('/^\n+|^[\t\s]*\n+/m','',$dat);//strip some whitespace
$fh=fopen($folder.'/list-'.$list.'.txt','w+');
fwrite($fh, $dat);
fclose($fh);}

function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$links=$folder.'/bookmarks-'.$folder.'.html';
$pg1=@file_get_contents($links) or die ('<html><body><p>Sorry for any inconvenience, error 1, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
$file=$folder.'/list-'.$list.'.txt';
$pg2=@file_get_contents($file) or die ('<html><body><p>Sorry for any inconvenience, error 2, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Bookmarks</title>
<link rel="shortcut icon" href="bookmark.ico">
<style type="text/css">
body{font:normal 24px 'Arial';color:#000;background-color:#ddd;background-image:url(ptv2.jpg);}
a:link,a:visited,a:active{text-decoration:none;color:#036}
.m1,.r1{display:inline;float:left;border-radius:0.2em;cursor:pointer;font:bold 24px "Arial";padding:4px 4px 4px 4px;background-color:#bbb;color:#036;margin:4px 4px 4px 4px;border:solid 2px #040}
.r1{display:block;}
.m1:hover{background-color:#0ee;}
.r1:hover{background-color:#fdd;}
#form{display:block;margin-right:100%;margin-top:10px}
#links{display:block;float:left;width:100%;margin-top:10px;margin-bottom:10px}
#word{display:inline;width:200px;height:30px;margin:10px 10px 0px 6px;font:normal 24px 'Arial'}
#buttons{margin-top:-20px;width:1400px}
.num{background-color:#eca;}
.b1{border-radius:0.2em;margin:auto;text-align:left;text-decoration:none;display:block;font:bold 24px "Arial";border:solid 1px #060;overflow:hidden;margin:4px 4px 4px 4px;color:#036;background-color:#bbb;min-height:30px;padding:4px 4px 4px 4px;width:638px}
.b1{color:#036;background-color:#ddd;}
.b1:hover{text-decoration:none;color:#036;background-color:#eee}
.b1:visited{text-decoration:none;color:#000;background-color:#eca}
.s1{background-color:#e00;color:#fff;border-radius:0.2em}
.s2{background-color:#cec;color:#000;border-radius:0.2em}
#sd{border-radius:0.2em;background-color:#eee;height:600px;width:600px;border:1px solid #ccc;display:block;overflow:hidden;text-indent:100%;white-space:nowrap}
#list{border-radius:0.2em;border:solid 2px black;margin:-604px 4px 4px 624px;max-height:604px;width:700px;background-color:#99d;overflow: auto;}
</style>
<script type="text/javascript">
<!--
if (top.location != self.location) {top.location = self.location}
// -->
</script>
</head>
<body onload="document.form.add.value='0';document.form.button1.value='0';document.form.button2.value='0';document.form.button3.value='0';window.focus()" onunload="window.blur()">
<div class='m1' onfocus='this.blur()' onmousedown="timer=window.setTimeout(function(){document.form.folder.value=document.form.word.value;document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $folder; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='1'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='1';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t1.value=document.form.word.value;document.form.button1.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title1; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='2'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='2';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t2.value=document.form.word.value;document.form.button2.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title2; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='3'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='3';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t3.value=document.form.word.value;document.form.button3.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title3; ?></div>
<div class='r1' onfocus='this.blur()' onclick="document.form.dn.value='<?php if($hide_domain=='1'){echo '0';}else {echo '1';}?>';document.form.submit();">DOMAIN</div>
<form name="form" id="form" method="post" action="bookmarks.php">
<div>
<input type='text' style="" name='word' id='word' value='<?php echo $search; ?>' title='Search - (2 or more characters) - Then Hit Enter'>
<input type="hidden" name="add" value="0">
<input type="hidden" name="remove" value="0">
<input type="hidden" name="button1" value="0">
<input type="hidden" name="button2" value="0">
<input type="hidden" name="button3" value="0">
<input type="hidden" name="list" value="<?php echo $list; ?>">
<input type="hidden" name="t1" value="<?php echo $t1; ?>">
<input type="hidden" name="t2" value="<?php echo $t2; ?>">
<input type="hidden" name="t3" value="<?php echo $t3; ?>">
<input type="hidden" name="folder" value="<?php echo $folder; ?>">
<input type="hidden" name="dn" value="<?php echo $hide_domain; ?>">
<input style="visibility:hidden" type="submit" onclick="document.form.add.value='1';">
</div>
</form>
<div id='buttons'>
<div class='r1' onfocus='this.blur()' <?php if($search==''){echo ('style="background-color:#ff0" ');}?>onclick="this.style.backgroundColor='#ff0';document.form.word.value='';document.form.submit();">ALL</div>
<?php
$ss=explode('<s>', $pg2);
$ss[0]=$ss[1];
natcasesort($ss);//puts buttons in natural case sorted order
for($n=-1;$n<=(count($ss)-1);$n++){$sp[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
$ss[$n]=get_string_between($ss[$n],'<w>','</w>');
$ss=array_values(array_unique($ss));
$ss = array_values($ss);
if($search==$ss[$n]){$style='style="background-color:#ff0" ';}else{$style='';};$sp[$n]=$ss[$n];$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces but not in posted word
if($ss[$n]!=''){echo '<div class="m1" onfocus="this.blur()" '.$style.'onclick="this.style.backgroundColor=\'#ff0\';document.form.word.value=\''.$sp[$n].'\';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.remove.value=\'1\';document.form.submit();},2000)" onmouseup="clearTimeout(timer)">'.$ss[$n].'</div>'."\n";};$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
};
?>
</div>
<div id='links'>
<a href="http://localhost/bookmarks.php" title="Bookmarks" id="sd">Bookmarks</a>
<div id='list'>
<?php
if (strlen($search)<2){//NO SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){
$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';//combine arrays for sorting if domain hidden
}
natcasesort($tt);//puts titles in natural case sorted order
$fh=fopen('13e.txt','w');
fwrite($fh,''); //clear txtfile
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
if($title[$n]==''){$title[$n]=$url[$n];}
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};   
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'">'.$dn.''.$title[$n].'</a>'."\n";};
}
else{
if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'">'.$title[$n].'</a>'."\n";};   
}
$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
}
else{//SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'">'.$dn.''.$title[$n].'</a>'."\n";};
};}
else{
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'">'.$title[$n].'</a>'."\n";};   
}
};};

$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
?>
</div></div>
</body>
</html>
code2.jpg
 Description   
 Filesize   16.71 KB
 Viewed   215 Time(s)

code2.jpg

code1.jpg
 Description   
 Filesize   16.64 KB
 Viewed   219 Time(s)

code1.jpg

scroll-links.jpg
 Description   
 Filesize   78.63 KB
 Viewed   233 Time(s)

scroll-links.jpg


Last edited by kjdixo on Mon 09 Feb 2015, 16:01; edited 1 time in total
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Mon 09 Feb 2015, 06:59    Post subject: 600px square screenshots displayed in links as 120px square
Subject description: Note: for faster loading, create a folder with compressed filesize thumbnails
 

This version displays the 600px square screenshots as 120px square thumbnails in the link list.

1. added css class .txt span tags to the .b1 link text.
2. added css class .tn image tags to the .b1 links.

Note: for faster loading, create a folder with compressed filesize thumbnails.
It would not be difficult to re-code the bookmarks.php to include a folder with compressed thumbnails.
However, if the 600px originals load fast enough, then the code is simpler.
Remember to add the 2 lines of code that correct the 'single quote (and-hash-39-semicolon) problem' described in the last post and its .jpg attachments.

Code:

<?php  // **** PREVENT BROWSER CACHE ****
//header('Cache-Control: no-cache, must-revalidate');
//header('Pragma: no-cache');
//header('Expires: Sat,1 Jan 2000 00:00:01 GMT');
error_reporting (E_ALL ^ E_NOTICE);
$search=$_POST['word'];
$list=$_POST['list'];
$hide_domain=$_POST['dn'];
if(strlen($hide_domain)<1) {$hide_domain=1;};
$folder=$_POST['folder'];
if(strlen($folder)<1) {$folder=1;};

$t1=$_POST['t1'];
$t2=$_POST['t2'];
$t3=$_POST['t3'];

$list1=@file_get_contents($folder.'/list-1.txt');
$list2=@file_get_contents($folder.'/list-2.txt');
$list3=@file_get_contents($folder.'/list-3.txt');

$title1=get_string_between($list1,'<t>','</t>');
$title2=get_string_between($list2,'<t>','</t>');
$title3=get_string_between($list3,'<t>','</t>');

if($_POST['button1']){//change button1 name by pressing for 2 seconds
$list1=str_replace('<t>'.$title1.'</t>','<t>'.$t1.'</t>',$list1);
$title1=$t1;
$list1=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list1);//strip some whitespace
$fh=fopen($folder.'/list-1.txt','w+');
fwrite($fh, $list1);
fclose($fh);
}

if($_POST['button2']){//change button2 name by pressing for 2 seconds
$list2=str_replace('<t>'.$title2.'</t>','<t>'.$t2.'</t>',$list2);
$title2=$t2;
$list2=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list2);//strip some whitespace
$fh=fopen($folder.'/list-2.txt','w+');
fwrite($fh, $list2);
fclose($fh);
}

if($_POST['button3']){//change button3 name by pressing for 2 seconds
$list3=str_replace('<t>'.$title3.'</t>','<t>'.$t3.'</t>',$list3);
$title3=$t3;
$list3=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list3);//strip some whitespace
$fh=fopen($folder.'/list-3.txt','w+');
fwrite($fh, $list3);
fclose($fh);
}

if(strlen($list)<1) {$list=1;};

$fg=0;//flag you are trying to add a name already in one of the lists

$ss1=explode('<s>', $list1);$ss1[0]=$ss1[1];
for($n=0;$n<=(count($ss1)-1);$n++){
$ss1[$n]=get_string_between($ss1[$n],'<w>','</w>');
if($ss1[$n]==$search){$fg=1;};}

$ss2=explode('<s>', $list2);$ss2[0]=$ss2[1];
for($n=0;$n<=(count($ss2)-1);$n++){
$ss2[$n]=get_string_between($ss2[$n],'<w>','</w>');
if($ss2[$n]==$search){$fg=1;};}

$ss3=explode('<s>', $list3);$ss3[0]=$ss3[1];
for($n=0;$n<=(count($ss3)-1);$n++){
$ss3[$n]=get_string_between($ss3[$n],'<w>','</w>');
if($ss3[$n]==$search){$fg=1;};}

if(($fg!=1)&&($search!='')&&($_POST['add'])){
$fh=fopen($folder.'/list-'.$list.'.txt','a+');
fwrite($fh,PHP_EOL.'<s><w>'.$search.'</w>'); //write to txtfile
fclose($fh);}

if($_POST['remove']){
$dat=@file_get_contents($folder.'/list-'.$list.'.txt');
$dat=str_replace('<s><w>'.$search.'</w>','', $dat);
$dat=preg_replace('/^\n+|^[\t\s]*\n+/m','',$dat);//strip some whitespace
$fh=fopen($folder.'/list-'.$list.'.txt','w+');
fwrite($fh, $dat);
fclose($fh);}

function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$links=$folder.'/bookmarks-'.$folder.'.html';
$pg1=@file_get_contents($links) or die ('<html><body><p>Sorry for any inconvenience, error 1, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
$file=$folder.'/list-'.$list.'.txt';
$pg2=@file_get_contents($file) or die ('<html><body><p>Sorry for any inconvenience, error 2, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Bookmarks</title>
<link rel="shortcut icon" href="bookmark.ico">
<style type="text/css">
body{font:normal 24px 'Arial';color:#000;background-color:#ddd;background-image:url(ptv2.jpg);}
a:link,a:visited,a:active{text-decoration:none;color:#036}
.m1,.r1{display:inline;float:left;border-radius:0.2em;cursor:pointer;font:bold 24px "Arial";padding:4px 4px 4px 4px;background-color:#bbb;color:#036;margin:4px 4px 4px 4px;border:solid 2px #040}
.r1{display:block;}
.m1:hover{background-color:#0ee;}
.r1:hover{background-color:#fdd;}
#form{display:block;margin-right:100%;margin-top:10px}
#links{display:block;float:left;width:100%;margin-top:10px;margin-bottom:10px}
#word{display:inline;width:200px;height:30px;margin:10px 10px 0px 6px;font:normal 24px 'Arial'}
#buttons{margin-top:-20px;width:1400px}
.num{background-color:#eca;}
.b1{border-radius:0.2em;margin:auto;text-align:left;text-decoration:none;display:block;font:bold 24px "Arial";border:solid 1px #060;overflow:hidden;margin:4px 4px 4px 4px;color:#036;background-color:#bbb;min-height:30px;padding:4px 4px 4px 4px;width:638px}
.b1{color:#036;background-color:#ddd;}
.b1:hover{text-decoration:none;color:#036;background-color:#eee}
.b1:visited{text-decoration:none;color:#000;background-color:#eca}
.s1{background-color:#e00;color:#fff;border-radius:0.2em}
.s2{background-color:#cec;color:#000;border-radius:0.2em}
#sd{border-radius:0.2em;background-color:#eee;height:600px;width:600px;border:1px solid #ccc;display:block;overflow:hidden;text-indent:100%;white-space:nowrap}
#list{border-radius:0.2em;border:solid 2px black;margin:-604px 4px 4px 624px;max-height:604px;width:700px;background-color:#99d;overflow: auto;}
.txt{display:inline;float:left;width:500px;overflow:hidden}
.tn{width:120px;float:right;padding:4px 4px 4px 4px}
</style>
<script type="text/javascript">
<!--
if (top.location != self.location) {top.location = self.location}
// -->
</script>
</head>
<body onload="document.form.add.value='0';document.form.button1.value='0';document.form.button2.value='0';document.form.button3.value='0';window.focus()" onunload="window.blur()">
<div class='m1' onfocus='this.blur()' onmousedown="timer=window.setTimeout(function(){document.form.folder.value=document.form.word.value;document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $folder; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='1'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='1';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t1.value=document.form.word.value;document.form.button1.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title1; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='2'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='2';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t2.value=document.form.word.value;document.form.button2.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title2; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='3'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='3';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t3.value=document.form.word.value;document.form.button3.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title3; ?></div>
<div class='r1' onfocus='this.blur()' onclick="document.form.dn.value='<?php if($hide_domain=='1'){echo '0';}else {echo '1';}?>';document.form.submit();">DOMAIN</div>
<form name="form" id="form" method="post" action="bookmarks.php">
<div>
<input type='text' style="" name='word' id='word' value='<?php echo $search; ?>' title='Search - (2 or more characters) - Then Hit Enter'>
<input type="hidden" name="add" value="0">
<input type="hidden" name="remove" value="0">
<input type="hidden" name="button1" value="0">
<input type="hidden" name="button2" value="0">
<input type="hidden" name="button3" value="0">
<input type="hidden" name="list" value="<?php echo $list; ?>">
<input type="hidden" name="t1" value="<?php echo $t1; ?>">
<input type="hidden" name="t2" value="<?php echo $t2; ?>">
<input type="hidden" name="t3" value="<?php echo $t3; ?>">
<input type="hidden" name="folder" value="<?php echo $folder; ?>">
<input type="hidden" name="dn" value="<?php echo $hide_domain; ?>">
<input style="visibility:hidden" type="submit" onclick="document.form.add.value='1';">
</div>
</form>
<div id='buttons'>
<div class='r1' onfocus='this.blur()' <?php if($search==''){echo ('style="background-color:#ff0" ');}?>onclick="this.style.backgroundColor='#ff0';document.form.word.value='';document.form.submit();">ALL</div>
<?php
$ss=explode('<s>', $pg2);
$ss[0]=$ss[1];
natcasesort($ss);//puts buttons in natural case sorted order
for($n=-1;$n<=(count($ss)-1);$n++){$sp[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
$ss[$n]=get_string_between($ss[$n],'<w>','</w>');
$ss=array_values(array_unique($ss));
$ss = array_values($ss);
if($search==$ss[$n]){$style='style="background-color:#ff0" ';}else{$style='';};$sp[$n]=$ss[$n];$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces but not in posted word
if($ss[$n]!=''){echo '<div class="m1" onfocus="this.blur()" '.$style.'onclick="this.style.backgroundColor=\'#ff0\';document.form.word.value=\''.$sp[$n].'\';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.remove.value=\'1\';document.form.submit();},2000)" onmouseup="clearTimeout(timer)">'.$ss[$n].'</div>'."\n";};$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
};
?>
</div>
<div id='links'>
<a href="http://localhost/bookmarks.php" title="Bookmarks" id="sd">Bookmarks</a>
<div id='list'>
<?php
if (strlen($search)<2){//NO SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){
$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';//combine arrays for sorting if domain hidden
}
natcasesort($tt);//puts titles in natural case sorted order
$fh=fopen('13e.txt','w');
fwrite($fh,''); //clear txtfile
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
if($title[$n]==''){$title[$n]=$url[$n];}
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};   
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'"><span class="txt">'.$dn.''.$title[$n].'</span><img src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};
}
else{
if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'"><span class="txt">'.$title[$n].'</span><img class="tn" src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};   
}
$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
}
else{//SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'"><span class="txt">'.$dn.''.$title[$n].'</span><img class="tn" src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};
};}
else{
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\'"><span class="txt">'.$title[$n].'</span><img class="tn" src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};   
}
};};

$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
?>
</div></div>
</body>
</html>
thumbnails_tn.jpg
 Description   Thumbnails on the links, these are 600px square displayed as 120px square, if speedier loading is required it would be quite easy to re-code and reference to a thumbnail folder with smaller compressed filesize screenshot thumbnails
 Filesize   79.48 KB
 Viewed   187 Time(s)

thumbnails_tn.jpg


Last edited by kjdixo on Mon 09 Feb 2015, 15:58; edited 1 time in total
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Mon 09 Feb 2015, 11:01    Post subject: Faster loading thumbnails  

An alternative approach for faster loading of the thumbnails in the link list, is to only load those thumbnails that are immediately visible in the link list div area.
Using this method we can forget about creating compressed thumbnails and a folder for them and just use the original 600px square screenshots.
I have modified the code to initially not display all the thumbnails when the page loads.
Only the first 10 thumbnails are loaded at page load time.
Then as the link list is scrolled through and the links are moused-over, then more thumbnails are loaded.
The code loads 3 at a time but that could be increased to say 10 if required.
In that case a javascript loop might be considered, so as to keep the mouse-over code to a minimum.
Anyway as a little demonstration . . . the new code below works fine with no long delays whilst images load, (as was the case before).

1. The css class .tn is set to 'display:none' in the styles at the top of the page.
2. The css id #im1 to #im10 'display:inline' loads the first 10 thumbnails.
3. #im 'display:inline' triggers for 1 or more thumbnails depending on the mouseover code.

Also: Remember to add the 2 lines of code that correct the 'single quote (and-hash-39-semicolon) problem' described in the post before last and its .jpg attachments.
Code:

<?php  // **** PREVENT BROWSER CACHE ****
//header('Cache-Control: no-cache, must-revalidate');
//header('Pragma: no-cache');
//header('Expires: Sat,1 Jan 2000 00:00:01 GMT');
error_reporting (E_ALL ^ E_NOTICE);
$search=$_POST['word'];
$list=$_POST['list'];
$hide_domain=$_POST['dn'];
if(strlen($hide_domain)<1) {$hide_domain=1;};
$folder=$_POST['folder'];
if(strlen($folder)<1) {$folder=1;};

$t1=$_POST['t1'];
$t2=$_POST['t2'];
$t3=$_POST['t3'];

$list1=@file_get_contents($folder.'/list-1.txt');
$list2=@file_get_contents($folder.'/list-2.txt');
$list3=@file_get_contents($folder.'/list-3.txt');

$title1=get_string_between($list1,'<t>','</t>');
$title2=get_string_between($list2,'<t>','</t>');
$title3=get_string_between($list3,'<t>','</t>');

if($_POST['button1']){//change button1 name by pressing for 2 seconds
$list1=str_replace('<t>'.$title1.'</t>','<t>'.$t1.'</t>',$list1);
$title1=$t1;
$list1=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list1);//strip some whitespace
$fh=fopen($folder.'/list-1.txt','w+');
fwrite($fh, $list1);
fclose($fh);
}

if($_POST['button2']){//change button2 name by pressing for 2 seconds
$list2=str_replace('<t>'.$title2.'</t>','<t>'.$t2.'</t>',$list2);
$title2=$t2;
$list2=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list2);//strip some whitespace
$fh=fopen($folder.'/list-2.txt','w+');
fwrite($fh, $list2);
fclose($fh);
}

if($_POST['button3']){//change button3 name by pressing for 2 seconds
$list3=str_replace('<t>'.$title3.'</t>','<t>'.$t3.'</t>',$list3);
$title3=$t3;
$list3=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list3);//strip some whitespace
$fh=fopen($folder.'/list-3.txt','w+');
fwrite($fh, $list3);
fclose($fh);
}

if(strlen($list)<1) {$list=1;};

$fg=0;//flag you are trying to add a name already in one of the lists

$ss1=explode('<s>', $list1);$ss1[0]=$ss1[1];
for($n=0;$n<=(count($ss1)-1);$n++){
$ss1[$n]=get_string_between($ss1[$n],'<w>','</w>');
if($ss1[$n]==$search){$fg=1;};}

$ss2=explode('<s>', $list2);$ss2[0]=$ss2[1];
for($n=0;$n<=(count($ss2)-1);$n++){
$ss2[$n]=get_string_between($ss2[$n],'<w>','</w>');
if($ss2[$n]==$search){$fg=1;};}

$ss3=explode('<s>', $list3);$ss3[0]=$ss3[1];
for($n=0;$n<=(count($ss3)-1);$n++){
$ss3[$n]=get_string_between($ss3[$n],'<w>','</w>');
if($ss3[$n]==$search){$fg=1;};}

if(($fg!=1)&&($search!='')&&($_POST['add'])){
$fh=fopen($folder.'/list-'.$list.'.txt','a+');
fwrite($fh,PHP_EOL.'<s><w>'.$search.'</w>'); //write to txtfile
fclose($fh);}

if($_POST['remove']){
$dat=@file_get_contents($folder.'/list-'.$list.'.txt');
$dat=str_replace('<s><w>'.$search.'</w>','', $dat);
$dat=preg_replace('/^\n+|^[\t\s]*\n+/m','',$dat);//strip some whitespace
$fh=fopen($folder.'/list-'.$list.'.txt','w+');
fwrite($fh, $dat);
fclose($fh);}

function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$links=$folder.'/bookmarks-'.$folder.'.html';
$pg1=@file_get_contents($links) or die ('<html><body><p>Sorry for any inconvenience, error 1, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
$file=$folder.'/list-'.$list.'.txt';
$pg2=@file_get_contents($file) or die ('<html><body><p>Sorry for any inconvenience, error 2, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Bookmarks</title>
<link rel="shortcut icon" href="bookmark.ico">
<style type="text/css">
body{font:normal 24px 'Arial';color:#000;background-color:#ddd;background-image:url(ptv2.jpg);}
a:link,a:visited,a:active{text-decoration:none;color:#036}
.m1,.r1{display:inline;float:left;border-radius:0.2em;cursor:pointer;font:bold 24px "Arial";padding:4px 4px 4px 4px;background-color:#bbb;color:#036;margin:4px 4px 4px 4px;border:solid 2px #040}
.r1{display:block;}
.m1:hover{background-color:#0ee;}
.r1:hover{background-color:#fdd;}
#form{display:block;margin-right:100%;margin-top:10px}
#links{display:block;float:left;width:100%;margin-top:10px;margin-bottom:10px}
#word{display:inline;width:200px;height:30px;margin:10px 10px 0px 6px;font:normal 24px 'Arial'}
#buttons{margin-top:-20px;width:1400px}
.num{background-color:#eca;}
.b1{border-radius:0.2em;margin:auto;text-align:left;text-decoration:none;display:block;font:bold 24px "Arial";border:solid 1px #060;overflow:hidden;margin:4px 4px 4px 4px;color:#036;background-color:#bbb;min-height:30px;padding:4px 4px 4px 4px;width:638px}
.b1{color:#036;background-color:#ddd;}
.b1:hover{text-decoration:none;color:#036;background-color:#eee}
.b1:visited{text-decoration:none;color:#000;background-color:#eca}
.s1{background-color:#e00;color:#fff;border-radius:0.2em}
.s2{background-color:#cec;color:#000;border-radius:0.2em}
#sd{border-radius:0.2em;background-color:#eee;height:600px;width:600px;border:1px solid #ccc;display:block;overflow:hidden;text-indent:100%;white-space:nowrap}
#list{border-radius:0.2em;border:solid 2px black;margin:-604px 4px 4px 624px;max-height:604px;width:700px;background-color:#99d;overflow: auto;}
.txt{display:inline;float:left;width:500px;overflow:hidden}
.tn{width:120px;float:right;padding:4px 4px 4px 4px;display:none}
#im1,#im2,#im3,#im4,#im5,#im6,#im7,#im8,#im9,#im10{display:inline}
</style>
<script type="text/javascript">
<!--
if (top.location != self.location) {top.location = self.location}
// -->
</script>
</head>
<body onload="loadthumbnails();document.form.add.value='0';document.form.button1.value='0';document.form.button2.value='0';document.form.button3.value='0';window.focus()" onunload="window.blur()">
<div class='m1' onfocus='this.blur()' onmousedown="timer=window.setTimeout(function(){document.form.folder.value=document.form.word.value;document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $folder; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='1'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='1';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t1.value=document.form.word.value;document.form.button1.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title1; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='2'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='2';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t2.value=document.form.word.value;document.form.button2.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title2; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='3'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='3';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t3.value=document.form.word.value;document.form.button3.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title3; ?></div>
<div class='r1' onfocus='this.blur()' onclick="document.form.dn.value='<?php if($hide_domain=='1'){echo '0';}else {echo '1';}?>';document.form.submit();">DOMAIN</div>
<form name="form" id="form" method="post" action="bookmarks.php">
<div>
<input type='text' style="" name='word' id='word' value='<?php echo $search; ?>' title='Search - (2 or more characters) - Then Hit Enter'>
<input type="hidden" name="add" value="0">
<input type="hidden" name="remove" value="0">
<input type="hidden" name="button1" value="0">
<input type="hidden" name="button2" value="0">
<input type="hidden" name="button3" value="0">
<input type="hidden" name="list" value="<?php echo $list; ?>">
<input type="hidden" name="t1" value="<?php echo $t1; ?>">
<input type="hidden" name="t2" value="<?php echo $t2; ?>">
<input type="hidden" name="t3" value="<?php echo $t3; ?>">
<input type="hidden" name="folder" value="<?php echo $folder; ?>">
<input type="hidden" name="dn" value="<?php echo $hide_domain; ?>">
<input style="visibility:hidden" type="submit" onclick="document.form.add.value='1';">
</div>
</form>
<div id='buttons'>
<div class='r1' onfocus='this.blur()' <?php if($search==''){echo ('style="background-color:#ff0" ');}?>onclick="this.style.backgroundColor='#ff0';document.form.word.value='';document.form.submit();">ALL</div>
<?php
$ss=explode('<s>', $pg2);
$ss[0]=$ss[1];
natcasesort($ss);//puts buttons in natural case sorted order
for($n=-1;$n<=(count($ss)-1);$n++){$sp[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
$ss[$n]=get_string_between($ss[$n],'<w>','</w>');
$ss=array_values(array_unique($ss));
$ss = array_values($ss);
if($search==$ss[$n]){$style='style="background-color:#ff0" ';}else{$style='';};$sp[$n]=$ss[$n];$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces but not in posted word
if($ss[$n]!=''){echo '<div class="m1" onfocus="this.blur()" '.$style.'onclick="this.style.backgroundColor=\'#ff0\';document.form.word.value=\''.$sp[$n].'\';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.remove.value=\'1\';document.form.submit();},2000)" onmouseup="clearTimeout(timer)">'.$ss[$n].'</div>'."\n";};$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
};
?>
</div>
<div id='links'>
<a href="http://localhost/bookmarks.php" title="Bookmarks" id="sd">Bookmarks</a>
<div id='list'>
<?php
if (strlen($search)<2){//NO SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){
$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';//combine arrays for sorting if domain hidden
}
natcasesort($tt);//puts titles in natural case sorted order
$fh=fopen('13e.txt','w');
fwrite($fh,''); //clear txtfile
$i=0;
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
if($title[$n]==''){$title[$n]=$url[$n];}
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};   
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
if($n>1){$i=$i+1;echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\';document.getElementById(\'im'.($i).'\').style.display=\'inline\';document.getElementById(\'im'.($i+1).'\').style.display=\'inline\';document.getElementById(\'im'.($i+2).'\').style.display=\'inline\';"><span class="txt">'.$dn.''.$title[$n].'</span><img class="tn" id="im'.$i.'" src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};
}
else{
if($n>1){$i=$i+1;echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\';document.getElementById(\'im'.($i).'\').style.display=\'inline\';document.getElementById(\'im'.($i+1).'\').style.display=\'inline\';document.getElementById(\'im'.($i+2).'\').style.display=\'inline\';"><span class="txt">'.$title[$n].'</span><img class="tn" id="im'.$i.'" src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};   
}
$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
}
else{//SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
$i=0;
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){$i=$i+1;echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\';document.getElementById(\'im'.($i).'\').style.display=\'inline\';document.getElementById(\'im'.($i+1).'\').style.display=\'inline\';document.getElementById(\'im'.($i+2).'\').style.display=\'inline\';"><span class="txt">'.$dn.''.$title[$n].'</span><img class="tn" id="im'.$i.'" src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};
};}
else{
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){$i=$i+1;echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\';document.getElementById(\'im'.($i).'\').style.display=\'inline\';document.getElementById(\'im'.($i+1).'\').style.display=\'inline\';document.getElementById(\'im'.($i+2).'\').style.display=\'inline\';"><span class="txt">'.$title[$n].'</span><img class="tn" id="im'.$i.'" src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};   
}
};};

$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
?>
</div></div>
</body>
</html>

Last edited by kjdixo on Mon 09 Feb 2015, 15:50; edited 1 time in total
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Mon 09 Feb 2015, 15:48    Post subject: Using the jSeamonkey Error Console I found two errors
Subject description: css .r1 and #form 'inline' written as 'inlne', but should actually be' block'
 

Using the Seamonkey Error Console I found two errors that have been reproduced throughout all my posts on this topic.

error 1 =
.r1{display:inlne;} inline mis-spelled and code should be
.r1{display:block;}

error 2 =
#form{display:inlne;margin-right:100%;margin-top:10px} inline mis-spelled and code should be
#form{display:block;margin-right:100%;margin-top:10px}

Sorry for the 2 slight errors, luckily they didn't stop the pages from displaying correctly.
I have corrected the 2 errors by editing the code in all of my posts.
Back to top
View user's profile Send private message 
kjdixo

Joined: 13 Sep 2009
Posts: 39

PostPosted: Tue 10 Feb 2015, 14:51    Post subject: Specifying the default yellow highlighted buttons
Subject description: Mousedown (left click and hold down) on the DOMAIN button for 2 seconds
 

Whilst selecting one of the 3 Master Category buttons above the text box, it would be nice to have your favorite yellow highlighted button selected automatically.
Also, there should be an easy way to specify which yellow highlighted button is your favorite (the default).

The following code does all of the above.

1. Modify list-1.txt, list-2.txt and list-3.txt to include some <d></d> tags, these tags will hold the default yellow highlighted button name.
Example new format for list-1.txt, list-2.txt and list-3.txt, note the addition of d tags.
Code:

<t>technical</t>
<d>forum</d>
<s><w>javascript</w>
<s><w>tiny</w>
<s><w>lxde</w>

2. Modify bookmarks.php see code below.
Operation:
Mousedown (left click and hold down) on the DOMAIN button for 2 seconds . . . and the current yellow highlighted button will become the default.

Also: Remember to add the 2 lines of code that correct the 'single quote (and-hash-39-semicolon) problem' described in a previous post and its .jpg attachments.
Code:

<?php  // **** PREVENT BROWSER CACHE ****
//header('Cache-Control: no-cache, must-revalidate');
//header('Pragma: no-cache');
//header('Expires: Sat,1 Jan 2000 00:00:01 GMT');
error_reporting (E_ALL ^ E_NOTICE);
$search=$_POST['word'];
$list=$_POST['list'];
$hide_domain=$_POST['dn'];
if(strlen($hide_domain)<1) {$hide_domain=1;};
$folder=$_POST['folder'];
if(strlen($folder)<1) {$folder=1;};

$t1=$_POST['t1'];
$t2=$_POST['t2'];
$t3=$_POST['t3'];

$list1=@file_get_contents($folder.'/list-1.txt');
$list2=@file_get_contents($folder.'/list-2.txt');
$list3=@file_get_contents($folder.'/list-3.txt');

$title1=get_string_between($list1,'<t>','</t>');
$title2=get_string_between($list2,'<t>','</t>');
$title3=get_string_between($list3,'<t>','</t>');

$def1=get_string_between($list1,'<d>','</d>');
$def2=get_string_between($list2,'<d>','</d>');
$def3=get_string_between($list3,'<d>','</d>');

if($_POST['default']){//change yellow highlighted search button to be default by pressing domain button for 2 seconds
$def=@file_get_contents($folder.'/list-'.$list.'.txt');
$dd=get_string_between($def,'<d>','</d>');
$def=str_replace('<d>'.$dd.'</d>','<d>'.$search.'</d>', $def);
$def=preg_replace('/^\n+|^[\t\s]*\n+/m','',$def);//strip some whitespace
$fh=fopen($folder.'/list-'.$list.'.txt','w+');
fwrite($fh, $def);
fclose($fh);}

if($_POST['button1']){//change button1 name by pressing for 2 seconds
$list1=str_replace('<t>'.$title1.'</t>','<t>'.$t1.'</t>',$list1);
$title1=$t1;
$list1=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list1);//strip some whitespace
$fh=fopen($folder.'/list-1.txt','w+');
fwrite($fh, $list1);
fclose($fh);
}

if($_POST['button2']){//change button2 name by pressing for 2 seconds
$list2=str_replace('<t>'.$title2.'</t>','<t>'.$t2.'</t>',$list2);
$title2=$t2;
$list2=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list2);//strip some whitespace
$fh=fopen($folder.'/list-2.txt','w+');
fwrite($fh, $list2);
fclose($fh);
}

if($_POST['button3']){//change button3 name by pressing for 2 seconds
$list3=str_replace('<t>'.$title3.'</t>','<t>'.$t3.'</t>',$list3);
$title3=$t3;
$list3=preg_replace('/^\n+|^[\t\s]*\n+/m','',$list3);//strip some whitespace
$fh=fopen($folder.'/list-3.txt','w+');
fwrite($fh, $list3);
fclose($fh);
}

if(strlen($list)<1) {$list=1;};

$fg=0;//flag you are trying to add a name already in one of the lists

$ss1=explode('<s>', $list1);$ss1[0]=$ss1[1];
for($n=0;$n<=(count($ss1)-1);$n++){
$ss1[$n]=get_string_between($ss1[$n],'<w>','</w>');
if($ss1[$n]==$search){$fg=1;};}

$ss2=explode('<s>', $list2);$ss2[0]=$ss2[1];
for($n=0;$n<=(count($ss2)-1);$n++){
$ss2[$n]=get_string_between($ss2[$n],'<w>','</w>');
if($ss2[$n]==$search){$fg=1;};}

$ss3=explode('<s>', $list3);$ss3[0]=$ss3[1];
for($n=0;$n<=(count($ss3)-1);$n++){
$ss3[$n]=get_string_between($ss3[$n],'<w>','</w>');
if($ss3[$n]==$search){$fg=1;};}

if(($fg!=1)&&($search!='')&&($_POST['add'])){
$fh=fopen($folder.'/list-'.$list.'.txt','a+');
fwrite($fh,PHP_EOL.'<s><w>'.$search.'</w>'); //write to txtfile
fclose($fh);}

if($_POST['remove']){
$dat=@file_get_contents($folder.'/list-'.$list.'.txt');
$dat=str_replace('<s><w>'.$search.'</w>','', $dat);
$dat=preg_replace('/^\n+|^[\t\s]*\n+/m','',$dat);//strip some whitespace
$fh=fopen($folder.'/list-'.$list.'.txt','w+');
fwrite($fh, $dat);
fclose($fh);}

function get_string_between($string, $start, $end)
{
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$links=$folder.'/bookmarks-'.$folder.'.html';
$pg1=@file_get_contents($links) or die ('<html><body><p>Sorry for any inconvenience, error 1, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
$file=$folder.'/list-'.$list.'.txt';
$pg2=@file_get_contents($file) or die ('<html><body><p>Sorry for any inconvenience, error 2, fault will be fixed soon. Try reloading the page using your browser refresh button</p></body></html>');
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Bookmarks</title>
<link rel="shortcut icon" href="bookmark.ico">
<style type="text/css">
body{font:normal 24px 'Arial';color:#000;background-color:#ddd;background-image:url(ptv2.jpg);}
a:link,a:visited,a:active{text-decoration:none;color:#036}
.m1,.r1{display:inline;float:left;border-radius:0.2em;cursor:pointer;font:bold 24px "Arial";padding:4px 4px 4px 4px;background-color:#bbb;color:#036;margin:4px 4px 4px 4px;border:solid 2px #040}
.r1{display:block;}
.m1:hover{background-color:#0ee;}
.r1:hover{background-color:#fdd;}
#form{display:block;margin-right:100%;margin-top:10px}
#links{display:block;float:left;width:100%;margin-top:10px;margin-bottom:10px}
#word{display:inline;width:200px;height:30px;margin:10px 10px 0px 6px;font:normal 24px 'Arial'}
#buttons{margin-top:-20px;width:1400px}
.num{background-color:#eca;}
.b1{border-radius:0.2em;margin:auto;text-align:left;text-decoration:none;display:block;font:bold 24px "Arial";border:solid 1px #060;overflow:hidden;margin:4px 4px 4px 4px;color:#036;background-color:#bbb;min-height:30px;padding:4px 4px 4px 4px;width:638px}
.b1{color:#036;background-color:#ddd;}
.b1:hover{text-decoration:none;color:#036;background-color:#eee}
.b1:visited{text-decoration:none;color:#000;background-color:#eca}
.s1{background-color:#e00;color:#fff;border-radius:0.2em}
.s2{background-color:#cec;color:#000;border-radius:0.2em}
#sd{border-radius:0.2em;background-color:#eee;height:600px;width:600px;border:1px solid #ccc;display:block;overflow:hidden;text-indent:100%;white-space:nowrap}
#list{border-radius:0.2em;border:solid 2px black;margin:-604px 4px 4px 624px;max-height:604px;width:700px;background-color:#99d;overflow: auto;}
.txt{display:inline;float:left;width:500px;overflow:hidden}
.tn{width:120px;float:right;padding:4px 4px 4px 4px;display:none}
#im1,#im2,#im3,#im4,#im5,#im6,#im7,#im8,#im9,#im10{display:inline}
</style>
<script type="text/javascript">
<!--
if (top.location != self.location) {top.location = self.location}
// -->
</script>
</head>
<body onload="window.focus()" onunload="window.blur()">
<div class='m1' onfocus='this.blur()' onmousedown="timer=window.setTimeout(function(){document.form.folder.value=document.form.word.value;document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $folder; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='1'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='1';document.form.word.value='<?php echo $def1; ?>';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t1.value=document.form.word.value;document.form.button1.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title1; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='2'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='2';document.form.word.value='<?php echo $def2; ?>';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t2.value=document.form.word.value;document.form.button2.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title2; ?></div>
<div class='r1' onfocus='this.blur()' <?php if($list=='3'){echo ('style="background-color:lime" ');}?>onclick="document.form.list.value='3';document.form.word.value='<?php echo $def3; ?>';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.t3.value=document.form.word.value;document.form.button3.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)"><?php echo $title3; ?></div>
<div class='r1' onfocus='this.blur()' onclick="document.form.dn.value='<?php if($hide_domain=='1'){echo '0';}else {echo '1';}?>';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.default.value='1';document.form.submit();},2000)" onmouseup="clearTimeout(timer)">DOMAIN</div>
<form name="form" id="form" method="post" action="bookmarks.php">
<div>
<input type='text' style="" name='word' id='word' value='<?php echo $search; ?>' title='Search - (2 or more characters) - Then Hit Enter'>
<input type="hidden" name="add" value="0">
<input type="hidden" name="remove" value="0">
<input type="hidden" name="button1" value="0">
<input type="hidden" name="button2" value="0">
<input type="hidden" name="button3" value="0">
<input type="hidden" name="default" value="0">
<input type="hidden" name="list" value="<?php echo $list; ?>">
<input type="hidden" name="t1" value="<?php echo $t1; ?>">
<input type="hidden" name="t2" value="<?php echo $t2; ?>">
<input type="hidden" name="t3" value="<?php echo $t3; ?>">
<input type="hidden" name="folder" value="<?php echo $folder; ?>">
<input type="hidden" name="dn" value="<?php echo $hide_domain; ?>">
<input style="visibility:hidden" type="submit" onclick="document.form.add.value='1';">
</div>
</form>
<div id='buttons'>
<div class='r1' onfocus='this.blur()' <?php if($search==''){echo ('style="background-color:#ff0" ');}?>onclick="this.style.backgroundColor='#ff0';document.form.word.value='';document.form.submit();">ALL</div>
<?php
$ss=explode('<s>', $pg2);
$ss[0]=$ss[1];
natcasesort($ss);//puts buttons in natural case sorted order
for($n=-1;$n<=(count($ss)-1);$n++){$sp[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
$ss[$n]=get_string_between($ss[$n],'<w>','</w>');
$ss=array_values(array_unique($ss));
$ss = array_values($ss);
if($search==$ss[$n]){$style='style="background-color:#ff0" ';}else{$style='';};$sp[$n]=$ss[$n];$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces but not in posted word
if($ss[$n]!=''){echo '<div class="m1" onfocus="this.blur()" '.$style.'onclick="this.style.backgroundColor=\'#ff0\';document.form.word.value=\''.$sp[$n].'\';document.form.submit();" onmousedown="timer=window.setTimeout(function(){document.form.remove.value=\'1\';document.form.submit();},2000)" onmouseup="clearTimeout(timer)">'.$ss[$n].'</div>'."\n";};$ss[$n]=str_replace(' ','&nbsp;', $ss[$n]);//replace spaces
};
?>
</div>
<div id='links'>
<a href="http://localhost/bookmarks.php" title="Bookmarks" id="sd">Bookmarks</a>
<div id='list'>
<?php
if (strlen($search)<2){//NO SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){
$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';//combine arrays for sorting if domain hidden
}
natcasesort($tt);//puts titles in natural case sorted order
$fh=fopen('13e.txt','w');
fwrite($fh,''); //clear txtfile
$i=0;
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
if($title[$n]==''){$title[$n]=$url[$n];}
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};   
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
if($n>1){$i=$i+1;echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\';document.getElementById(\'im'.($i).'\').style.display=\'inline\';document.getElementById(\'im'.($i+1).'\').style.display=\'inline\';document.getElementById(\'im'.($i+2).'\').style.display=\'inline\';"><span class="txt">'.$dn.''.$title[$n].'</span><img class="tn" id="im'.$i.'" src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};
}
else{
if($n>1){$i=$i+1;echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\';document.getElementById(\'im'.($i).'\').style.display=\'inline\';document.getElementById(\'im'.($i+1).'\').style.display=\'inline\';document.getElementById(\'im'.($i+2).'\').style.display=\'inline\';"><span class="txt">'.$title[$n].'</span><img class="tn" id="im'.$i.'" src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};   
}
$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
}
else{//SEARCH
$dd=explode('<HR>    <DT><A', $pg1);
$pg1=$dd[1];
$pg1='<DT><A'.$pg1;
$pg1 = str_replace('<DD>','', $pg1);//remove
$pg1 = str_replace('<DL>','', $pg1);//remove
$pg1 = str_replace('</DL>','', $pg1);//remove
$pg1 = str_replace('<p>','', $pg1);//remove
$pg1 = str_replace('FEEDURL','HREF', $pg1);//replace   
$pg1 = preg_replace('/\<DT><H3[^\>]+\>/', '', $pg1);//remove
$pg1 = str_replace('</H3>','', $pg1);//remove
$pg2 = preg_replace('/\<A HREF=[^\>]+\>/','',$pg1);//remove everything before title to allow title to be sorted first
$tt=explode('<DT>', $pg1);//array 1
$rr=explode('<DT>', $pg2);//array 2
$tt[0]=$tt[1];//$tt[0] will be empty, so make it equal to $tt[1].
$rr[0]=$rr[1];//$rr[0] will be empty, so make it equal to $rr[1].
for($n=1;$n<=(count($tt)-1);$n++){$tt[$n]='<sort_title_first>'.$rr[$n].'<then_sort_url>'.$tt[$n].'<if_domain_hidden>';}//combine arrays for sorting if domain hidden
natcasesort($tt);//puts titles of links in natural case sorted order
$tt=array_values(array_unique($tt));//removes array duplicates and re-indexes array
$i=0;
for($n=1;$n<=(count($tt)-1);$n++){
$url[$n]=get_string_between($tt[$n], '<A HREF="', '" ');
$title[$n]=get_string_between($tt[$n], '">', '</A>');
if($hide_domain=='0'){//domains visible
$domain[$n]=get_string_between($url[$n], '://', '/');
$spn=strpos($url[$n],'https');
if($spn!==false){$span='s2';}else{$span='s1';};
$dn='<span class="'.$span.'">&nbsp;'.$domain[$n].'&nbsp;</span><br>';
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){$i=$i+1;echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\';document.getElementById(\'im'.($i).'\').style.display=\'inline\';document.getElementById(\'im'.($i+1).'\').style.display=\'inline\';document.getElementById(\'im'.($i+2).'\').style.display=\'inline\';"><span class="txt">'.$dn.''.$title[$n].'</span><img class="tn" id="im'.$i.'" src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};
};}
else{
$surl=stripos($url[$n], $search);
$stit=stripos($title[$n], $search);
if(($surl!==false)||($stit!==false)){if($title[$n]==''){$title[$n]=$url[$n];};if($n>1){$i=$i+1;echo '<a class="b1" title="'.$n.'" target="new" href="'.$url[$n].'" onmouseover="img=getElementById(\'sd\');img.href=\''.$url[$n].'\';img.title=\''.$title[$n].'\';img.style.backgroundImage=\'url(/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png)\';document.getElementById(\'im'.($i).'\').style.display=\'inline\';document.getElementById(\'im'.($i+1).'\').style.display=\'inline\';document.getElementById(\'im'.($i+2).'\').style.display=\'inline\';"><span class="txt">'.$title[$n].'</span><img class="tn" id="im'.$i.'" src="/'.$folder.'/screenshots-'.$folder.'/'.$n.'.png"></a>'."\n";};   
}
};};

$fh=fopen('13e.txt','a+');
fwrite($fh,$url[$n]."\n"); //write to txtfile
fclose($fh);
}
?>
</div></div>
</body>
</html>
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 3 [33 Posts]   Goto page: 1, 2, 3 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.7285s ][ Queries: 12 (0.0070s) ][ GZIP on ]