aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/HttpUtils.php2
-rw-r--r--application/Router.php26
-rw-r--r--application/Utils.php16
-rw-r--r--index.php27
-rw-r--r--plugins/markdown/markdown.css7
-rw-r--r--tpl/loginform.html46
6 files changed, 75 insertions, 49 deletions
diff --git a/application/HttpUtils.php b/application/HttpUtils.php
index c84ba6f0..2e0792f9 100644
--- a/application/HttpUtils.php
+++ b/application/HttpUtils.php
@@ -193,7 +193,7 @@ function server_url($server)
193function index_url($server) 193function index_url($server)
194{ 194{
195 $scriptname = $server['SCRIPT_NAME']; 195 $scriptname = $server['SCRIPT_NAME'];
196 if (endswith($scriptname, 'index.php')) { 196 if (endsWith($scriptname, 'index.php')) {
197 $scriptname = substr($scriptname, 0, -9); 197 $scriptname = substr($scriptname, 0, -9);
198 } 198 }
199 return server_url($server) . $scriptname; 199 return server_url($server) . $scriptname;
diff --git a/application/Router.php b/application/Router.php
index a1e594a0..2c3934b0 100644
--- a/application/Router.php
+++ b/application/Router.php
@@ -63,19 +63,19 @@ class Router
63 return self::$PAGE_LINKLIST; 63 return self::$PAGE_LINKLIST;
64 } 64 }
65 65
66 if (startswith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) { 66 if (startsWith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) {
67 return self::$PAGE_LOGIN; 67 return self::$PAGE_LOGIN;
68 } 68 }
69 69
70 if (startswith($query, 'do='. self::$PAGE_PICWALL)) { 70 if (startsWith($query, 'do='. self::$PAGE_PICWALL)) {
71 return self::$PAGE_PICWALL; 71 return self::$PAGE_PICWALL;
72 } 72 }
73 73
74 if (startswith($query, 'do='. self::$PAGE_TAGCLOUD)) { 74 if (startsWith($query, 'do='. self::$PAGE_TAGCLOUD)) {
75 return self::$PAGE_TAGCLOUD; 75 return self::$PAGE_TAGCLOUD;
76 } 76 }
77 77
78 if (startswith($query, 'do='. self::$PAGE_OPENSEARCH)) { 78 if (startsWith($query, 'do='. self::$PAGE_OPENSEARCH)) {
79 return self::$PAGE_OPENSEARCH; 79 return self::$PAGE_OPENSEARCH;
80 } 80 }
81 81
@@ -96,23 +96,23 @@ class Router
96 return self::$PAGE_LINKLIST; 96 return self::$PAGE_LINKLIST;
97 } 97 }
98 98
99 if (startswith($query, 'do='. self::$PAGE_TOOLS)) { 99 if (startsWith($query, 'do='. self::$PAGE_TOOLS)) {
100 return self::$PAGE_TOOLS; 100 return self::$PAGE_TOOLS;
101 } 101 }
102 102
103 if (startswith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) { 103 if (startsWith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) {
104 return self::$PAGE_CHANGEPASSWORD; 104 return self::$PAGE_CHANGEPASSWORD;
105 } 105 }
106 106
107 if (startswith($query, 'do='. self::$PAGE_CONFIGURE)) { 107 if (startsWith($query, 'do='. self::$PAGE_CONFIGURE)) {
108 return self::$PAGE_CONFIGURE; 108 return self::$PAGE_CONFIGURE;
109 } 109 }
110 110
111 if (startswith($query, 'do='. self::$PAGE_CHANGETAG)) { 111 if (startsWith($query, 'do='. self::$PAGE_CHANGETAG)) {
112 return self::$PAGE_CHANGETAG; 112 return self::$PAGE_CHANGETAG;
113 } 113 }
114 114
115 if (startswith($query, 'do='. self::$PAGE_ADDLINK)) { 115 if (startsWith($query, 'do='. self::$PAGE_ADDLINK)) {
116 return self::$PAGE_ADDLINK; 116 return self::$PAGE_ADDLINK;
117 } 117 }
118 118
@@ -120,19 +120,19 @@ class Router
120 return self::$PAGE_EDITLINK; 120 return self::$PAGE_EDITLINK;
121 } 121 }
122 122
123 if (startswith($query, 'do='. self::$PAGE_EXPORT)) { 123 if (startsWith($query, 'do='. self::$PAGE_EXPORT)) {
124 return self::$PAGE_EXPORT; 124 return self::$PAGE_EXPORT;
125 } 125 }
126 126
127 if (startswith($query, 'do='. self::$PAGE_IMPORT)) { 127 if (startsWith($query, 'do='. self::$PAGE_IMPORT)) {
128 return self::$PAGE_IMPORT; 128 return self::$PAGE_IMPORT;
129 } 129 }
130 130
131 if (startswith($query, 'do='. self::$PAGE_PLUGINSADMIN)) { 131 if (startsWith($query, 'do='. self::$PAGE_PLUGINSADMIN)) {
132 return self::$PAGE_PLUGINSADMIN; 132 return self::$PAGE_PLUGINSADMIN;
133 } 133 }
134 134
135 if (startswith($query, 'do='. self::$PAGE_SAVE_PLUGINSADMIN)) { 135 if (startsWith($query, 'do='. self::$PAGE_SAVE_PLUGINSADMIN)) {
136 return self::$PAGE_SAVE_PLUGINSADMIN; 136 return self::$PAGE_SAVE_PLUGINSADMIN;
137 } 137 }
138 138
diff --git a/application/Utils.php b/application/Utils.php
index 5b8ca508..da521cce 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -41,8 +41,14 @@ function smallHash($text)
41 41
42/** 42/**
43 * Tells if a string start with a substring 43 * Tells if a string start with a substring
44 *
45 * @param string $haystack Given string.
46 * @param string $needle String to search at the beginning of $haystack.
47 * @param bool $case Case sensitive.
48 *
49 * @return bool True if $haystack starts with $needle.
44 */ 50 */
45function startsWith($haystack, $needle, $case=true) 51function startsWith($haystack, $needle, $case = true)
46{ 52{
47 if ($case) { 53 if ($case) {
48 return (strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0); 54 return (strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0);
@@ -52,8 +58,14 @@ function startsWith($haystack, $needle, $case=true)
52 58
53/** 59/**
54 * Tells if a string ends with a substring 60 * Tells if a string ends with a substring
61 *
62 * @param string $haystack Given string.
63 * @param string $needle String to search at the end of $haystack.
64 * @param bool $case Case sensitive.
65 *
66 * @return bool True if $haystack ends with $needle.
55 */ 67 */
56function endsWith($haystack, $needle, $case=true) 68function endsWith($haystack, $needle, $case = true)
57{ 69{
58 if ($case) { 70 if ($case) {
59 return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0); 71 return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0);
diff --git a/index.php b/index.php
index 90fdac81..5b8384ba 100644
--- a/index.php
+++ b/index.php
@@ -496,9 +496,9 @@ if (isset($_POST['login']))
496 else 496 else
497 { 497 {
498 ban_loginFailed(); 498 ban_loginFailed();
499 $redir = ''; 499 $redir = '&username='. $_POST['login'];
500 if (isset($_GET['post'])) { 500 if (isset($_GET['post'])) {
501 $redir = '?post=' . urlencode($_GET['post']); 501 $redir .= '&post=' . urlencode($_GET['post']);
502 foreach (array('description', 'source', 'title') as $param) { 502 foreach (array('description', 'source', 'title') as $param) {
503 if (!empty($_GET[$param])) { 503 if (!empty($_GET[$param])) {
504 $redir .= '&' . $param . '=' . urlencode($_GET[$param]); 504 $redir .= '&' . $param . '=' . urlencode($_GET[$param]);
@@ -569,7 +569,7 @@ function tokenOk($token)
569// This RSS feed cannot be filtered. 569// This RSS feed cannot be filtered.
570function showDailyRSS() { 570function showDailyRSS() {
571 // Cache system 571 // Cache system
572 $query = $_SERVER["QUERY_STRING"]; 572 $query = $_SERVER['QUERY_STRING'];
573 $cache = new CachedPage( 573 $cache = new CachedPage(
574 $GLOBALS['config']['PAGECACHE'], 574 $GLOBALS['config']['PAGECACHE'],
575 page_url($_SERVER), 575 page_url($_SERVER),
@@ -823,12 +823,15 @@ function renderPage()
823 if ($GLOBALS['config']['OPEN_SHAARLI']) { header('Location: ?'); exit; } // No need to login for open Shaarli 823 if ($GLOBALS['config']['OPEN_SHAARLI']) { header('Location: ?'); exit; } // No need to login for open Shaarli
824 $token=''; if (ban_canLogin()) $token=getToken(); // Do not waste token generation if not useful. 824 $token=''; if (ban_canLogin()) $token=getToken(); // Do not waste token generation if not useful.
825 $PAGE->assign('token',$token); 825 $PAGE->assign('token',$token);
826 if (isset($_GET['username'])) {
827 $PAGE->assign('username', escape($_GET['username']));
828 }
826 $PAGE->assign('returnurl',(isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):'')); 829 $PAGE->assign('returnurl',(isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):''));
827 $PAGE->renderPage('loginform'); 830 $PAGE->renderPage('loginform');
828 exit; 831 exit;
829 } 832 }
830 // -------- User wants to logout. 833 // -------- User wants to logout.
831 if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=logout')) 834 if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=logout'))
832 { 835 {
833 invalidateCaches($GLOBALS['config']['PAGECACHE']); 836 invalidateCaches($GLOBALS['config']['PAGECACHE']);
834 logout(); 837 logout();
@@ -1077,12 +1080,6 @@ function renderPage()
1077 exit; 1080 exit;
1078 } 1081 }
1079 1082
1080 // Same case as above except that user tried to access ?do=addlink without being logged in
1081 // Note: passing empty parameters makes Shaarli generate default URLs and descriptions.
1082 if (isset($_GET['do']) && $_GET['do'] === 'addlink') {
1083 header('Location: ?do=login&post=');
1084 exit;
1085 }
1086 showLinkList($PAGE, $LINKSDB); 1083 showLinkList($PAGE, $LINKSDB);
1087 if (isset($_GET['edit_link'])) { 1084 if (isset($_GET['edit_link'])) {
1088 header('Location: ?do=login&edit_link='. escape($_GET['edit_link'])); 1085 header('Location: ?do=login&edit_link='. escape($_GET['edit_link']));
@@ -1506,7 +1503,7 @@ function renderPage()
1506 } 1503 }
1507 1504
1508 // -------- User is uploading a file for import 1505 // -------- User is uploading a file for import
1509 if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=upload')) 1506 if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=upload'))
1510 { 1507 {
1511 // If file is too big, some form field may be missing. 1508 // If file is too big, some form field may be missing.
1512 if (!isset($_POST['token']) || (!isset($_FILES)) || (isset($_FILES['filetoupload']['size']) && $_FILES['filetoupload']['size']==0)) 1509 if (!isset($_POST['token']) || (!isset($_FILES)) || (isset($_FILES['filetoupload']['size']) && $_FILES['filetoupload']['size']==0))
@@ -1608,7 +1605,7 @@ function importFile($LINKSDB)
1608 { 1605 {
1609 $link = array('linkdate'=>'','title'=>'','url'=>'','description'=>'','tags'=>'','private'=>0); 1606 $link = array('linkdate'=>'','title'=>'','url'=>'','description'=>'','tags'=>'','private'=>0);
1610 $d = explode('<DD>',$html); 1607 $d = explode('<DD>',$html);
1611 if (startswith($d[0],'<A ')) 1608 if (startsWith($d[0], '<A '))
1612 { 1609 {
1613 $link['description'] = (isset($d[1]) ? html_entity_decode(trim($d[1]),ENT_QUOTES,'UTF-8') : ''); // Get description (optional) 1610 $link['description'] = (isset($d[1]) ? html_entity_decode(trim($d[1]),ENT_QUOTES,'UTF-8') : ''); // Get description (optional)
1614 preg_match('!<A .*?>(.*?)</A>!i',$d[0],$matches); $link['title'] = (isset($matches[1]) ? trim($matches[1]) : ''); // Get title 1611 preg_match('!<A .*?>(.*?)</A>!i',$d[0],$matches); $link['title'] = (isset($matches[1]) ? trim($matches[1]) : ''); // Get title
@@ -2078,7 +2075,7 @@ function genThumbnail()
2078 2075
2079 // Is this a link to an image, or to a flickr page ? 2076 // Is this a link to an image, or to a flickr page ?
2080 $imageurl=''; 2077 $imageurl='';
2081 if (endswith(parse_url($url,PHP_URL_PATH),'.jpg')) 2078 if (endsWith(parse_url($url, PHP_URL_PATH), '.jpg'))
2082 { // This is a direct link to an image. e.g. http://farm1.staticflickr.com/5/5921913_ac83ed27bd_o.jpg 2079 { // This is a direct link to an image. e.g. http://farm1.staticflickr.com/5/5921913_ac83ed27bd_o.jpg
2083 preg_match('!(http://farm\d+\.staticflickr\.com/\d+/\d+_\w+_)\w.jpg!',$url,$matches); 2080 preg_match('!(http://farm\d+\.staticflickr\.com/\d+/\d+_\w+_)\w.jpg!',$url,$matches);
2084 if (!empty($matches[1])) $imageurl=$matches[1].'m.jpg'; 2081 if (!empty($matches[1])) $imageurl=$matches[1].'m.jpg';
@@ -2255,8 +2252,8 @@ function resizeImage($filepath)
2255 return true; 2252 return true;
2256} 2253}
2257 2254
2258if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. 2255if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database.
2259if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=dailyrss')) { showDailyRSS(); exit; } 2256if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=dailyrss')) { showDailyRSS(); exit; }
2260if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE']; 2257if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE'];
2261renderPage(); 2258renderPage();
2262?> 2259?>
diff --git a/plugins/markdown/markdown.css b/plugins/markdown/markdown.css
index 3c1b2aeb..6789ce84 100644
--- a/plugins/markdown/markdown.css
+++ b/plugins/markdown/markdown.css
@@ -143,6 +143,13 @@
143 hyphens: none; 143 hyphens: none;
144} 144}
145 145
146.markdown :not(pre) code {
147 background-color: #eee;
148 padding: 1px 3px;
149 border-radius: 1px;
150 box-shadow: 0 -1px 0 #e5e5e5,0 0 1px rgba(0,0,0,0.12),0 1px 1px rgba(0,0,0,0.24);
151}
152
146.md_help { 153.md_help {
147 color: white; 154 color: white;
148} 155}
diff --git a/tpl/loginform.html b/tpl/loginform.html
index 678375fd..a49b42d3 100644
--- a/tpl/loginform.html
+++ b/tpl/loginform.html
@@ -1,26 +1,36 @@
1<!DOCTYPE html> 1<!DOCTYPE html>
2<html> 2<html>
3<head>{include="includes"}</head> 3<head>{include="includes"}</head>
4<body{if="ban_canLogin()"} onload="document.loginform.login.focus();"{/if}> 4<body
5{if="ban_canLogin()"}
6 {if="empty($username)"}
7 onload="document.loginform.login.focus();"
8 {else}
9 onload="document.loginform.password.focus();"
10 {/if}
11{/if}>
5<div id="pageheader"> 12<div id="pageheader">
6 {include="page.header"} 13 {include="page.header"}
7 14
8 <div id="headerform"> 15 <div id="headerform">
9{if="!ban_canLogin()"} 16 {if="!ban_canLogin()"}
10 You have been banned from login after too many failed attempts. Try later. 17 You have been banned from login after too many failed attempts. Try later.
11{else} 18 {else}
12 <form method="post" name="loginform"> 19 <form method="post" name="loginform">
13 <label for="login">Login: <input type="text" id="login" name="login" tabindex="1"></label> 20 <label for="login">Login: <input type="text" id="login" name="login" tabindex="1"
14 <label for="password">Password: <input type="password" id="password" name="password" tabindex="2"></label> 21 {if="!empty($username)"}value="{$username}"{/if}>
15 <input type="submit" value="Login" class="bigbutton" tabindex="4"> 22 </label>
16 <label for="longlastingsession"> 23 <label for="password">Password: <input type="password" id="password" name="password" tabindex="2">
17 <input type="checkbox" name="longlastingsession" id="longlastingsession" tabindex="3"> 24 </label>
18 Stay signed in (Do not check on public computers)</label> 25 <input type="submit" value="Login" class="bigbutton" tabindex="4">
19 <input type="hidden" name="token" value="{$token}"> 26 <label for="longlastingsession">
20 {if="$returnurl"}<input type="hidden" name="returnurl" value="{$returnurl}">{/if} 27 <input type="checkbox" name="longlastingsession" id="longlastingsession" tabindex="3">
21 </form> 28 Stay signed in (Do not check on public computers)</label>
22{/if} 29 <input type="hidden" name="token" value="{$token}">
23 </div> 30 {if="$returnurl"}<input type="hidden" name="returnurl" value="{$returnurl}">{/if}
31 </form>
32 {/if}
33 </div>
24</div> 34</div>
25 35
26{include="page.footer"} 36{include="page.footer"}