aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/HttpUtils.php2
-rw-r--r--application/NetscapeBookmarkUtils.php15
-rw-r--r--application/Router.php26
-rw-r--r--application/Utils.php16
4 files changed, 39 insertions, 20 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/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php
index 8a296705..fdbb0ad7 100644
--- a/application/NetscapeBookmarkUtils.php
+++ b/application/NetscapeBookmarkUtils.php
@@ -13,17 +13,19 @@ class NetscapeBookmarkUtils
13 * - timestamp link addition date, using the Unix epoch format 13 * - timestamp link addition date, using the Unix epoch format
14 * - taglist comma-separated tag list 14 * - taglist comma-separated tag list
15 * 15 *
16 * @param LinkDB $linkDb The link datastore 16 * @param LinkDB $linkDb Link datastore
17 * @param string $selection Which links to export: (all|private|public) 17 * @param string $selection Which links to export: (all|private|public)
18 * @param bool $prependNoteUrl Prepend note permalinks with the server's URL
19 * @param string $indexUrl Absolute URL of the Shaarli index page
18 * 20 *
19 * @throws Exception Invalid export selection 21 * @throws Exception Invalid export selection
20 * 22 *
21 * @return array The links to be exported, with additional fields 23 * @return array The links to be exported, with additional fields
22 */ 24 */
23 public static function filterAndFormat($linkDb, $selection) 25 public static function filterAndFormat($linkDb, $selection, $prependNoteUrl, $indexUrl)
24 { 26 {
25 // see tpl/export.html for possible values 27 // see tpl/export.html for possible values
26 if (! in_array($selection, array('all','public','private'))) { 28 if (! in_array($selection, array('all', 'public', 'private'))) {
27 throw new Exception('Invalid export selection: "'.$selection.'"'); 29 throw new Exception('Invalid export selection: "'.$selection.'"');
28 } 30 }
29 31
@@ -39,6 +41,11 @@ class NetscapeBookmarkUtils
39 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); 41 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
40 $link['timestamp'] = $date->getTimestamp(); 42 $link['timestamp'] = $date->getTimestamp();
41 $link['taglist'] = str_replace(' ', ',', $link['tags']); 43 $link['taglist'] = str_replace(' ', ',', $link['tags']);
44
45 if (startsWith($link['url'], '?') && $prependNoteUrl) {
46 $link['url'] = $indexUrl . $link['url'];
47 }
48
42 $bookmarkLinks[] = $link; 49 $bookmarkLinks[] = $link;
43 } 50 }
44 51
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);