diff options
author | Seb Sauvage <sebsauvage@sebsauvage.net> | 2011-09-21 10:50:54 +0200 |
---|---|---|
committer | Emilien Klein <emilien@klein.st> | 2011-09-21 10:50:54 +0200 |
commit | eae4f48bf0b4137ee4764d06678ba6e6a9c74978 (patch) | |
tree | 8eb93925a155c3c854a26126b9bf420fe62a8f68 /index.php | |
parent | ef4275c50edad6de268d53214db37f071e227b34 (diff) | |
download | Shaarli-eae4f48bf0b4137ee4764d06678ba6e6a9c74978.tar.gz Shaarli-eae4f48bf0b4137ee4764d06678ba6e6a9c74978.tar.zst Shaarli-eae4f48bf0b4137ee4764d06678ba6e6a9c74978.zip |
Version 0.0.15 beta:
- Bug corrected in import: HTML entities were not properly decoded. If you imported your Delicious/Diigo bookmarks, your should import them again an use the 'overwrite' option of the import feature.
- Removed some parameters in URL added by some feed proxies (#xtor=RSS-…)
- On free.fr, automatic creation of the /sessions directory.
- CSS Stylesheet is now an external file (shaarli.css). This reduces page size and eases customization.
- New in import: Option to overwrite existing links when importing.
- Bug corrected: Prevented loop on login screen upon successful login after a failed login.
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 106 |
1 files changed, 27 insertions, 79 deletions
@@ -1,5 +1,5 @@ | |||
1 | <?php | 1 | <?php |
2 | // Shaarli 0.0.14 beta - Shaare your links... | 2 | // Shaarli 0.0.15 beta - Shaare your links... |
3 | // The personal, minimalist, super-fast, no-database delicious clone. By sebsauvage.net | 3 | // The personal, minimalist, super-fast, no-database delicious clone. By sebsauvage.net |
4 | // http://sebsauvage.net/wiki/doku.php?id=php:shaarli | 4 | // http://sebsauvage.net/wiki/doku.php?id=php:shaarli |
5 | // Licence: http://www.opensource.org/licenses/zlib-license.php | 5 | // Licence: http://www.opensource.org/licenses/zlib-license.php |
@@ -43,7 +43,7 @@ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); | |||
43 | header("Cache-Control: no-store, no-cache, must-revalidate"); | 43 | header("Cache-Control: no-store, no-cache, must-revalidate"); |
44 | header("Cache-Control: post-check=0, pre-check=0", false); | 44 | header("Cache-Control: post-check=0, pre-check=0", false); |
45 | header("Pragma: no-cache"); | 45 | header("Pragma: no-cache"); |
46 | define('shaarli_version','0.0.14 beta'); | 46 | define('shaarli_version','0.0.15 beta'); |
47 | if (!is_dir(DATADIR)) { mkdir(DATADIR,0705); chmod(DATADIR,0705); } | 47 | if (!is_dir(DATADIR)) { mkdir(DATADIR,0705); chmod(DATADIR,0705); } |
48 | if (!is_file(DATADIR.'/.htaccess')) { file_put_contents(DATADIR.'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. | 48 | if (!is_file(DATADIR.'/.htaccess')) { file_put_contents(DATADIR.'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. |
49 | if (!is_file(CONFIG_FILE)) install(); | 49 | if (!is_file(CONFIG_FILE)) install(); |
@@ -203,7 +203,11 @@ if (isset($_POST['login'])) | |||
203 | ban_loginOk(); | 203 | ban_loginOk(); |
204 | // Optional redirect after login: | 204 | // Optional redirect after login: |
205 | if (isset($_GET['post'])) { header('Location: ?post='.urlencode($_GET['post']).(!empty($_GET['source'])?'&source='.urlencode($_GET['source']):'')); exit; } | 205 | if (isset($_GET['post'])) { header('Location: ?post='.urlencode($_GET['post']).(!empty($_GET['source'])?'&source='.urlencode($_GET['source']):'')); exit; } |
206 | if (isset($_POST['returnurl'])) { header('Location: '.$_POST['returnurl']); exit; } | 206 | if (isset($_POST['returnurl'])) |
207 | { | ||
208 | if (endsWith($_POST['returnurl'],'?do=login')) { header('Location: ?'); exit; } // Prevent loops over login screen. | ||
209 | header('Location: '.$_POST['returnurl']); exit; | ||
210 | } | ||
207 | header('Location: ?'); exit; | 211 | header('Location: ?'); exit; |
208 | } | 212 | } |
209 | else | 213 | else |
@@ -753,6 +757,7 @@ HTML; | |||
753 | // We remove the annoying parameters added by FeedBurner and GoogleFeedProxy (?utm_source=...) | 757 | // We remove the annoying parameters added by FeedBurner and GoogleFeedProxy (?utm_source=...) |
754 | $i=strpos($url,'&utm_source='); if ($i) $url=substr($url,0,$i); | 758 | $i=strpos($url,'&utm_source='); if ($i) $url=substr($url,0,$i); |
755 | $i=strpos($url,'?utm_source='); if ($i) $url=substr($url,0,$i); | 759 | $i=strpos($url,'?utm_source='); if ($i) $url=substr($url,0,$i); |
760 | $i=strpos($url,'#xtor=RSS-'); if ($i) $url=substr($url,0,$i); | ||
756 | 761 | ||
757 | $link_is_new = false; | 762 | $link_is_new = false; |
758 | $link = $LINKSDB->getLinkFromUrl($url); // Check if URL is not already in database (in this case, we will edit the existing link) | 763 | $link = $LINKSDB->getLinkFromUrl($url); // Check if URL is not already in database (in this case, we will edit the existing link) |
@@ -853,7 +858,8 @@ Import Netscape html bookmarks (as exported from Firefox/Chrome/Opera/delicious/ | |||
853 | <input type="file" name="filetoupload" size="80"> | 858 | <input type="file" name="filetoupload" size="80"> |
854 | <input type="hidden" name="MAX_FILE_SIZE" value="{$maxfilesize}"> | 859 | <input type="hidden" name="MAX_FILE_SIZE" value="{$maxfilesize}"> |
855 | <input type="submit" name="import_file" value="Import" class="bigbutton"><br> | 860 | <input type="submit" name="import_file" value="Import" class="bigbutton"><br> |
856 | <input type="checkbox" name="private"> Import all links as private | 861 | <input type="checkbox" name="private"> Import all links as private<br> |
862 | <input type="checkbox" name="overwrite"> Overwrite existing links | ||
857 | </form> | 863 | </form> |
858 | </div> | 864 | </div> |
859 | HTML; | 865 | HTML; |
@@ -884,6 +890,8 @@ function importFile() | |||
884 | $filesize=$_FILES['filetoupload']['size']; | 890 | $filesize=$_FILES['filetoupload']['size']; |
885 | $data=file_get_contents($_FILES['filetoupload']['tmp_name']); | 891 | $data=file_get_contents($_FILES['filetoupload']['tmp_name']); |
886 | $private = (empty($_POST['private']) ? 0 : 1); // Should the links be imported as private ? | 892 | $private = (empty($_POST['private']) ? 0 : 1); // Should the links be imported as private ? |
893 | $overwrite = !empty($_POST['overwrite']) ; // Should the imported links overwrite existing ones ? | ||
894 | $import_count=0; | ||
887 | 895 | ||
888 | // Sniff file type: | 896 | // Sniff file type: |
889 | $type='unknown'; | 897 | $type='unknown'; |
@@ -895,35 +903,35 @@ function importFile() | |||
895 | // This is a standard Netscape-style bookmark file. | 903 | // This is a standard Netscape-style bookmark file. |
896 | // This format is supported by all browsers (except IE, of course), also delicious, diigo and others. | 904 | // This format is supported by all browsers (except IE, of course), also delicious, diigo and others. |
897 | // I didn't want to use DOM... anyway, this is FAST (less than 1 second to import 7200 links (2.1 Mb html file)). | 905 | // I didn't want to use DOM... anyway, this is FAST (less than 1 second to import 7200 links (2.1 Mb html file)). |
898 | $before=count($LINKSDB); | ||
899 | foreach(explode('<DT>',$data) as $html) // explode is very fast | 906 | foreach(explode('<DT>',$data) as $html) // explode is very fast |
900 | { | 907 | { |
901 | $link = array('linkdate'=>'','title'=>'','url'=>'','description'=>'','tags'=>'','private'=>0); | 908 | $link = array('linkdate'=>'','title'=>'','url'=>'','description'=>'','tags'=>'','private'=>0); |
902 | $d = explode('<DD>',$html); | 909 | $d = explode('<DD>',$html); |
903 | if (startswith($d[0],'<A ')) | 910 | if (startswith($d[0],'<A ')) |
904 | { | 911 | { |
905 | $link['description'] = (isset($d[1]) ? trim($d[1]) : ''); // Get description (optional) | 912 | $link['description'] = (isset($d[1]) ? html_entity_decode(trim($d[1]),ENT_QUOTES,'UTF-8') : ''); // Get description (optional) |
906 | preg_match('!<A .*?>(.*?)</A>!i',$d[0],$matches); $link['title'] = (isset($matches[1]) ? trim($matches[1]) : ''); // Get title | 913 | preg_match('!<A .*?>(.*?)</A>!i',$d[0],$matches); $link['title'] = (isset($matches[1]) ? trim($matches[1]) : ''); // Get title |
914 | $link['title'] = html_entity_decode($link['title'],ENT_QUOTES,'UTF-8'); | ||
907 | preg_match_all('! ([A-Z_]+)=\"(.*?)"!i',$html,$matches,PREG_SET_ORDER); // Get all other attributes | 915 | preg_match_all('! ([A-Z_]+)=\"(.*?)"!i',$html,$matches,PREG_SET_ORDER); // Get all other attributes |
908 | foreach($matches as $m) | 916 | foreach($matches as $m) |
909 | { | 917 | { |
910 | $attr=$m[1]; $value=$m[2]; | 918 | $attr=$m[1]; $value=$m[2]; |
911 | if ($attr=='HREF') $link['url']=$value; | 919 | if ($attr=='HREF') $link['url']=html_entity_decode($value,ENT_QUOTES,'UTF-8'); |
912 | elseif ($attr=='ADD_DATE') $link['linkdate']=date('Ymd_His',intval($value)); | 920 | elseif ($attr=='ADD_DATE') $link['linkdate']=date('Ymd_His',intval($value)); |
913 | elseif ($attr=='PRIVATE') $link['private']=($value=='0'?0:1); | 921 | elseif ($attr=='PRIVATE') $link['private']=($value=='0'?0:1); |
914 | elseif ($attr=='TAGS') $link['tags']=str_replace(',',' ',$value); | 922 | elseif ($attr=='TAGS') $link['tags']=html_entity_decode(str_replace(',',' ',$value),ENT_QUOTES,'UTF-8'); |
915 | } | 923 | } |
916 | if ($link['linkdate']!='' && $link['url']!='' && empty($LINKSDB[$link['linkdate']])) | 924 | if ($link['linkdate']!='' && $link['url']!='' && ($overwrite || empty($LINKSDB[$link['linkdate']]))) |
917 | { | 925 | { |
918 | if ($private==1) $link['private']=1; | 926 | if ($private==1) $link['private']=1; |
919 | $LINKSDB[$link['linkdate']] = $link; | 927 | $LINKSDB[$link['linkdate']] = $link; |
928 | $import_count++; | ||
920 | } | 929 | } |
921 | } | 930 | } |
922 | } | 931 | } |
923 | $import_count = count($LINKSDB)-$before; | ||
924 | $LINKSDB->savedb(); | 932 | $LINKSDB->savedb(); |
925 | invalidateCaches(); | 933 | invalidateCaches(); |
926 | echo '<script language="JavaScript">alert("File '.$filename.' ('.$filesize.' bytes) was successfully imported: '.$import_count.' new links.");document.location=\'?\';</script>'; | 934 | echo '<script language="JavaScript">alert("File '.$filename.' ('.$filesize.' bytes) was successfully processed: '.$import_count.' links imported.");document.location=\'?\';</script>'; |
927 | } | 935 | } |
928 | else | 936 | else |
929 | { | 937 | { |
@@ -1095,70 +1103,9 @@ JS; | |||
1095 | <html> | 1103 | <html> |
1096 | <head> | 1104 | <head> |
1097 | <title>{$open}Shaarli - Let's shaare your links...</title> | 1105 | <title>{$open}Shaarli - Let's shaare your links...</title> |
1098 | <link rel="alternate" type="application/rss+xml" href="{$feedurl}"> | 1106 | <link rel="alternate" type="application/rss+xml" href="{$feedurl}" /> |
1107 | <link type="text/css" rel="stylesheet" href="shaarli.css" /> | ||
1099 | {$jsincludes} | 1108 | {$jsincludes} |
1100 | <style type="text/css"> | ||
1101 | <!-- | ||
1102 | /* CSS Reset from Yahoo to cope with browsers CSS inconsistencies. */ | ||
1103 | /* | ||
1104 | Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html | ||
1105 | version: 2.8.2r1 | ||
1106 | */ | ||
1107 | html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var,optgroup{font-style:inherit;font-weight:inherit;}del,ins{text-decoration:none;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:baseline;}sub{vertical-align:baseline;}legend{color:#000;}input,button,textarea,select,optgroup,option{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;}input,button,textarea,select{*font-size:100%;} | ||
1108 | |||
1109 | body { font-family: "Trebuchet MS",Verdana,Arial,Helvetica,sans-serif; font-size:10pt; background-color: #ffffff; } | ||
1110 | input { border: 1px solid #aaa; background-color:#F0F0FF; padding: 2 5 2 5; -moz-box-shadow: inset 2px 2px 3px #aaaaaa; -webkit-box-shadow: inset 2px 2px 3px #aaaaaa; box-shadow: inset 2px 2px 3px #aaaaaa; } | ||
1111 | textarea { border: 1px solid #aaa; background-color:#F0F0FF; padding: 2 5 2 5; -moz-box-shadow: inset 2px 2px 3px #B2B2C4; -webkit-box-shadow: inset 2px 2px 3px #B2B2C4; box-shadow: inset 2px 2px 3px #B2B2C4; } | ||
1112 | /* I don't give a shit about IE. He can't understand selectors such as input[type='submit']. */ | ||
1113 | |||
1114 | .bigbutton {border-style:outset;border-width:2px;padding:3px 6px;background-color:rgb(212,212,212);font-family:Tahoma,Verdana,Arial,Helvetica,sans-serif;font-size:8pt;-moz-border-radius:0.5em;border-radius:0.5em;} | ||
1115 | .smallbutton {border-style:outset;border-width:2px;padding:0px 4px;background-color:rgb(212,212,212);font-family:Tahoma,Verdana,Arial,Helvetica,sans-serif;font-size:8pt;-moz-border-radius:0.5em;border-radius:0.5em;} | ||
1116 | #pageheader | ||
1117 | { | ||
1118 | color:#eee; | ||
1119 | border-bottom: 1px solid #aaa; | ||
1120 | background-color: #6A6A6A; | ||
1121 | background-image: -webkit-gradient(linear, left top, left bottom, from(#6A6A6A), to(#303030)); /* Saf4+, Chrome */ | ||
1122 | background-image: -webkit-linear-gradient(top, #6A6A6A, #303030); /* Chrome 10+, Saf5.1+ */ | ||
1123 | background-image: -moz-linear-gradient(top, #6A6A6A, #303030); /* FF3.6 */ | ||
1124 | background-image: -ms-linear-gradient(top, #6A6A6A, #303030); /* IE10 */ | ||
1125 | background-image: -o-linear-gradient(top, #6A6A6A, #303030); /* Opera 11.10+ */ | ||
1126 | background-image: linear-gradient(top, #6A6A6A, #303030); | ||
1127 | filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#6A6A6A', EndColorStr='#303030'); /* IE6-IE9 */ | ||
1128 | padding-bottom: 5px; | ||
1129 | } | ||
1130 | #pageheader a:link { color:#bbb; text-decoration:none;} | ||
1131 | #pageheader a:visited { color:#bbb; text-decoration:none;} | ||
1132 | #pageheader a:hover { color:#FFFFC9; text-decoration:none;} | ||
1133 | #pageheader a:active { color:#bbb; text-decoration:none;} | ||
1134 | .paging { background-color:#777; color:#ccc; text-align:center; padding:0 0 3 0;} | ||
1135 | .paging a:link { color:#ccc; text-decoration:none;} | ||
1136 | .paging a:visited { color:#ccc; } | ||
1137 | .paging a:hover { color:#FFFFC9; } | ||
1138 | .paging a:active { color:#fff; } | ||
1139 | #headerform { padding:5 5 5 15; } | ||
1140 | #editlinkform { padding:5 5 5 15px; width:80%; } | ||
1141 | #linklist li { padding:4 10 8 20; border-bottom: 1px solid #bbb;} | ||
1142 | #linklist li.private { background-color: #ccc; border-left:8px solid #888; } | ||
1143 | .linktitle { font-size:14pt; font-weight:bold; } | ||
1144 | .linktitle a { text-decoration: none; color:#0000EE; } | ||
1145 | .linktitle a:hover { text-decoration: underline; } | ||
1146 | .linktitle a:visited { color:#0000BB; } | ||
1147 | .linkdate { font-size:8pt; color:#888; } | ||
1148 | .linkurl { font-size:8pt; color:#4BAA74; } | ||
1149 | .linkdescription { color:#000; margin-top:0px; margin-bottom:0px; font-weight:normal; } | ||
1150 | .linktag { font-size:9pt; color:#777; background-color:#ddd; padding:0 6 0 6; -moz-box-shadow: inset 2px 2px 3px #ffffff; -webkit-box-shadow: inset 2px 2px 3px #ffffff; box-shadow: inset 2px 2px 3px ffffff; | ||
1151 | border-bottom:1px solid #aaa; border-right:1px solid #aaa; } | ||
1152 | .linktag a { color:#777; text-decoration:none; } | ||
1153 | .buttoneditform { display:inline; } | ||
1154 | #footer { font-size:8pt; text-align:center; border-top:1px solid #ddd; color: #888; } | ||
1155 | |||
1156 | /* Minimal customisation for jQuery widgets */ | ||
1157 | .ui-autocomplete { background-color:#fff; padding-left:5px;} | ||
1158 | .ui-state-hover { background-color: #604dff; color:#fff; } | ||
1159 | |||
1160 | --> | ||
1161 | </style> | ||
1162 | </head> | 1109 | </head> |
1163 | <body {$data['onload']}> | 1110 | <body {$data['onload']}> |
1164 | <div id="pageheader"><div style="float:right; font-style:italic; color:#bbb; text-align:right; padding:0 5 0 0;">Shaare your links...<br>{$linkcount} links</div> | 1111 | <div id="pageheader"><div style="float:right; font-style:italic; color:#bbb; text-align:right; padding:0 5 0 0;">Shaare your links...<br>{$linkcount} links</div> |
@@ -1179,6 +1126,9 @@ HTML; | |||
1179 | // This function should NEVER be called if the file data/config.php exists. | 1126 | // This function should NEVER be called if the file data/config.php exists. |
1180 | function install() | 1127 | function install() |
1181 | { | 1128 | { |
1129 | // On free.fr host, make sure the /sessions directory exists, otherwise login will not work. | ||
1130 | if (endsWith($_SERVER['SERVER_NAME'],'.free.fr') && !is_dir($_SERVER['DOCUMENT_ROOT'].'/sessions')) mkdir($_SERVER['DOCUMENT_ROOT'].'/sessions',0705); | ||
1131 | |||
1182 | if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) | 1132 | if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) |
1183 | { | 1133 | { |
1184 | $tz=(empty($_POST['settimezone']) ? 'UTC':$_POST['settimezone']); | 1134 | $tz=(empty($_POST['settimezone']) ? 'UTC':$_POST['settimezone']); |
@@ -1203,11 +1153,9 @@ function install() | |||
1203 | $timezoneselect='Timezone: <select name="settimezone"><option value="" selected>(please select:)</option>'.$timezones.'</select><br><br>'; | 1153 | $timezoneselect='Timezone: <select name="settimezone"><option value="" selected>(please select:)</option>'.$timezones.'</select><br><br>'; |
1204 | } | 1154 | } |
1205 | echo <<<HTML | 1155 | echo <<<HTML |
1206 | <html><title>Shaarli - Configuration</title><style type="text/css"> | 1156 | <html><head><title>Shaarli - Configuration</title><link type="text/css" rel="stylesheet" href="shaarli.css" /></head> |
1207 | body { font-family: "Trebuchet MS",Verdana,Arial,Helvetica,sans-serif; font-size:10pt; background-color: #ffffff; } | 1157 | <body onload="document.configform.setlogin.focus();" style="padding:20px;"><h1>Shaarli - Shaare your links...</h1> |
1208 | input { border: 1px solid #aaa; background-color:#F0F0FF; padding: 2 5 2 5; -moz-box-shadow: inset 2px 2px 3px #aaaaaa; -webkit-box-shadow: inset 2px 2px 3px #aaaaaa; box-shadow: inset 2px 2px 3px #aaaaaa; } | 1158 | It looks like it's the first time you run Shaarli. Please chose a login/password and a timezone:<br> |
1209 | .bigbutton {border-style:outset;border-width:2px;padding:3px 6px;background-color:rgb(212,212,212);font-family:Tahoma,Verdana,Arial,Helvetica,sans-serif;font-size:8pt;-moz-border-radius:0.5em;border-radius:0.5em;} | ||
1210 | </style></head><body onload="document.configform.setlogin.focus();"><h1>Shaarli - Shaare your links...</h1>It looks like it's the first time you run Shaarli. Please chose a login/password and a timezone:<br> | ||
1211 | <form method="POST" action="" name="configform" style="border:1px solid black; padding:10 10 10 10;"> | 1159 | <form method="POST" action="" name="configform" style="border:1px solid black; padding:10 10 10 10;"> |
1212 | Login: <input type="text" name="setlogin"><br><br>Password: <input type="password" name="setpassword"><br><br> | 1160 | Login: <input type="text" name="setlogin"><br><br>Password: <input type="password" name="setpassword"><br><br> |
1213 | {$timezoneselect} | 1161 | {$timezoneselect} |