aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-05-10 23:31:41 +0200
committerArthurHoaro <arthur@hoa.ro>2016-05-10 23:31:41 +0200
commit5046bcb6ab324a6b52669b2b76a41665022f653a (patch)
tree84a2c144ef7d9eb0a585d2c8e1bfe63311f979a3
parentd95533778d86bb6c6de3b14a9da35e6d6e6428bd (diff)
downloadShaarli-5046bcb6ab324a6b52669b2b76a41665022f653a.tar.gz
Shaarli-5046bcb6ab324a6b52669b2b76a41665022f653a.tar.zst
Shaarli-5046bcb6ab324a6b52669b2b76a41665022f653a.zip
Fix startsWith and endsWith case
-rw-r--r--application/HttpUtils.php2
-rw-r--r--application/Router.php26
-rw-r--r--application/Utils.php16
-rw-r--r--index.php14
4 files changed, 35 insertions, 23 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 408aeae9..85064e2e 100644
--- a/index.php
+++ b/index.php
@@ -690,7 +690,7 @@ class pageBuilder
690// This RSS feed cannot be filtered. 690// This RSS feed cannot be filtered.
691function showDailyRSS() { 691function showDailyRSS() {
692 // Cache system 692 // Cache system
693 $query = $_SERVER["QUERY_STRING"]; 693 $query = $_SERVER['QUERY_STRING'];
694 $cache = new CachedPage( 694 $cache = new CachedPage(
695 $GLOBALS['config']['PAGECACHE'], 695 $GLOBALS['config']['PAGECACHE'],
696 page_url($_SERVER), 696 page_url($_SERVER),
@@ -948,7 +948,7 @@ function renderPage()
948 exit; 948 exit;
949 } 949 }
950 // -------- User wants to logout. 950 // -------- User wants to logout.
951 if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=logout')) 951 if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=logout'))
952 { 952 {
953 invalidateCaches($GLOBALS['config']['PAGECACHE']); 953 invalidateCaches($GLOBALS['config']['PAGECACHE']);
954 logout(); 954 logout();
@@ -1636,7 +1636,7 @@ function renderPage()
1636 } 1636 }
1637 1637
1638 // -------- User is uploading a file for import 1638 // -------- User is uploading a file for import
1639 if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=upload')) 1639 if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=upload'))
1640 { 1640 {
1641 // If file is too big, some form field may be missing. 1641 // If file is too big, some form field may be missing.
1642 if (!isset($_POST['token']) || (!isset($_FILES)) || (isset($_FILES['filetoupload']['size']) && $_FILES['filetoupload']['size']==0)) 1642 if (!isset($_POST['token']) || (!isset($_FILES)) || (isset($_FILES['filetoupload']['size']) && $_FILES['filetoupload']['size']==0))
@@ -1739,7 +1739,7 @@ function importFile($LINKSDB)
1739 { 1739 {
1740 $link = array('linkdate'=>'','title'=>'','url'=>'','description'=>'','tags'=>'','private'=>0); 1740 $link = array('linkdate'=>'','title'=>'','url'=>'','description'=>'','tags'=>'','private'=>0);
1741 $d = explode('<DD>',$html); 1741 $d = explode('<DD>',$html);
1742 if (startswith($d[0],'<A ')) 1742 if (startsWith($d[0], '<A '))
1743 { 1743 {
1744 $link['description'] = (isset($d[1]) ? html_entity_decode(trim($d[1]),ENT_QUOTES,'UTF-8') : ''); // Get description (optional) 1744 $link['description'] = (isset($d[1]) ? html_entity_decode(trim($d[1]),ENT_QUOTES,'UTF-8') : ''); // Get description (optional)
1745 preg_match('!<A .*?>(.*?)</A>!i',$d[0],$matches); $link['title'] = (isset($matches[1]) ? trim($matches[1]) : ''); // Get title 1745 preg_match('!<A .*?>(.*?)</A>!i',$d[0],$matches); $link['title'] = (isset($matches[1]) ? trim($matches[1]) : ''); // Get title
@@ -2210,7 +2210,7 @@ function genThumbnail()
2210 2210
2211 // Is this a link to an image, or to a flickr page ? 2211 // Is this a link to an image, or to a flickr page ?
2212 $imageurl=''; 2212 $imageurl='';
2213 if (endswith(parse_url($url,PHP_URL_PATH),'.jpg')) 2213 if (endsWith(parse_url($url, PHP_URL_PATH), '.jpg'))
2214 { // This is a direct link to an image. e.g. http://farm1.staticflickr.com/5/5921913_ac83ed27bd_o.jpg 2214 { // This is a direct link to an image. e.g. http://farm1.staticflickr.com/5/5921913_ac83ed27bd_o.jpg
2215 preg_match('!(http://farm\d+\.staticflickr\.com/\d+/\d+_\w+_)\w.jpg!',$url,$matches); 2215 preg_match('!(http://farm\d+\.staticflickr\.com/\d+/\d+_\w+_)\w.jpg!',$url,$matches);
2216 if (!empty($matches[1])) $imageurl=$matches[1].'m.jpg'; 2216 if (!empty($matches[1])) $imageurl=$matches[1].'m.jpg';
@@ -2387,8 +2387,8 @@ function resizeImage($filepath)
2387 return true; 2387 return true;
2388} 2388}
2389 2389
2390if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. 2390if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database.
2391if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=dailyrss')) { showDailyRSS(); exit; } 2391if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=dailyrss')) { showDailyRSS(); exit; }
2392if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE']; 2392if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE'];
2393renderPage(); 2393renderPage();
2394?> 2394?>