aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/Languages.php3
-rw-r--r--application/bookmark/BookmarkArray.php9
-rw-r--r--application/bookmark/BookmarkFileService.php13
-rw-r--r--application/bookmark/BookmarkServiceInterface.php9
-rw-r--r--application/feed/FeedBuilder.php2
-rw-r--r--application/front/ShaarliMiddleware.php2
-rw-r--r--application/front/controller/visitor/FeedController.php4
-rw-r--r--application/legacy/LegacyController.php44
-rw-r--r--application/legacy/LegacyRouter.php134
-rw-r--r--assets/default/js/base.js19
-rw-r--r--inc/languages/jp/LC_MESSAGES/shaarli.po (renamed from inc/languages/ja/LC_MESSAGES/shaarli.po)0
-rw-r--r--plugins/default_colors/default_colors.php56
-rw-r--r--tests/feed/FeedBuilderTest.php12
-rw-r--r--tests/front/controller/admin/ConfigureControllerTest.php2
-rw-r--r--tests/front/controller/visitor/FeedControllerTest.php6
-rw-r--r--tests/legacy/LegacyControllerTest.php8
-rw-r--r--tests/legacy/LegacyRouterTest.php512
-rw-r--r--tests/plugins/PluginDefaultColorsTest.php19
-rw-r--r--tpl/default/linklist.html12
19 files changed, 156 insertions, 710 deletions
diff --git a/application/Languages.php b/application/Languages.php
index 5cda802e..d83e0765 100644
--- a/application/Languages.php
+++ b/application/Languages.php
@@ -179,9 +179,10 @@ class Languages
179 { 179 {
180 return [ 180 return [
181 'auto' => t('Automatic'), 181 'auto' => t('Automatic'),
182 'de' => t('German'),
182 'en' => t('English'), 183 'en' => t('English'),
183 'fr' => t('French'), 184 'fr' => t('French'),
184 'de' => t('German'), 185 'jp' => t('Japanese'),
185 ]; 186 ];
186 } 187 }
187} 188}
diff --git a/application/bookmark/BookmarkArray.php b/application/bookmark/BookmarkArray.php
index d87d43b4..3bd5eb20 100644
--- a/application/bookmark/BookmarkArray.php
+++ b/application/bookmark/BookmarkArray.php
@@ -234,16 +234,17 @@ class BookmarkArray implements \Iterator, \Countable, \ArrayAccess
234 * 234 *
235 * Also update the urls and ids mapping arrays. 235 * Also update the urls and ids mapping arrays.
236 * 236 *
237 * @param string $order ASC|DESC 237 * @param string $order ASC|DESC
238 * @param bool $ignoreSticky If set to true, sticky bookmarks won't be first
238 */ 239 */
239 public function reorder($order = 'DESC') 240 public function reorder(string $order = 'DESC', bool $ignoreSticky = false): void
240 { 241 {
241 $order = $order === 'ASC' ? -1 : 1; 242 $order = $order === 'ASC' ? -1 : 1;
242 // Reorder array by dates. 243 // Reorder array by dates.
243 usort($this->bookmarks, function ($a, $b) use ($order) { 244 usort($this->bookmarks, function ($a, $b) use ($order, $ignoreSticky) {
244 /** @var $a Bookmark */ 245 /** @var $a Bookmark */
245 /** @var $b Bookmark */ 246 /** @var $b Bookmark */
246 if ($a->isSticky() !== $b->isSticky()) { 247 if (false === $ignoreSticky && $a->isSticky() !== $b->isSticky()) {
247 return $a->isSticky() ? -1 : 1; 248 return $a->isSticky() ? -1 : 1;
248 } 249 }
249 return $a->getCreated() < $b->getCreated() ? 1 * $order : -1 * $order; 250 return $a->getCreated() < $b->getCreated() ? 1 * $order : -1 * $order;
diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php
index b3a90ed4..e3a61146 100644
--- a/application/bookmark/BookmarkFileService.php
+++ b/application/bookmark/BookmarkFileService.php
@@ -114,8 +114,13 @@ class BookmarkFileService implements BookmarkServiceInterface
114 /** 114 /**
115 * @inheritDoc 115 * @inheritDoc
116 */ 116 */
117 public function search($request = [], $visibility = null, $caseSensitive = false, $untaggedOnly = false) 117 public function search(
118 { 118 $request = [],
119 $visibility = null,
120 $caseSensitive = false,
121 $untaggedOnly = false,
122 bool $ignoreSticky = false
123 ) {
119 if ($visibility === null) { 124 if ($visibility === null) {
120 $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC; 125 $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC;
121 } 126 }
@@ -124,6 +129,10 @@ class BookmarkFileService implements BookmarkServiceInterface
124 $searchtags = isset($request['searchtags']) ? $request['searchtags'] : ''; 129 $searchtags = isset($request['searchtags']) ? $request['searchtags'] : '';
125 $searchterm = isset($request['searchterm']) ? $request['searchterm'] : ''; 130 $searchterm = isset($request['searchterm']) ? $request['searchterm'] : '';
126 131
132 if ($ignoreSticky) {
133 $this->bookmarks->reorder('DESC', true);
134 }
135
127 return $this->bookmarkFilter->filter( 136 return $this->bookmarkFilter->filter(
128 BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT, 137 BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
129 [$searchtags, $searchterm], 138 [$searchtags, $searchterm],
diff --git a/application/bookmark/BookmarkServiceInterface.php b/application/bookmark/BookmarkServiceInterface.php
index ce8bd912..b9b483eb 100644
--- a/application/bookmark/BookmarkServiceInterface.php
+++ b/application/bookmark/BookmarkServiceInterface.php
@@ -49,10 +49,17 @@ interface BookmarkServiceInterface
49 * @param string $visibility 49 * @param string $visibility
50 * @param bool $caseSensitive 50 * @param bool $caseSensitive
51 * @param bool $untaggedOnly 51 * @param bool $untaggedOnly
52 * @param bool $ignoreSticky
52 * 53 *
53 * @return Bookmark[] 54 * @return Bookmark[]
54 */ 55 */
55 public function search($request = [], $visibility = null, $caseSensitive = false, $untaggedOnly = false); 56 public function search(
57 $request = [],
58 $visibility = null,
59 $caseSensitive = false,
60 $untaggedOnly = false,
61 bool $ignoreSticky = false
62 );
56 63
57 /** 64 /**
58 * Get a single bookmark by its ID. 65 * Get a single bookmark by its ID.
diff --git a/application/feed/FeedBuilder.php b/application/feed/FeedBuilder.php
index 269ad877..3653c32f 100644
--- a/application/feed/FeedBuilder.php
+++ b/application/feed/FeedBuilder.php
@@ -102,7 +102,7 @@ class FeedBuilder
102 } 102 }
103 103
104 // Optionally filter the results: 104 // Optionally filter the results:
105 $linksToDisplay = $this->linkDB->search($userInput); 105 $linksToDisplay = $this->linkDB->search($userInput, null, false, false, true);
106 106
107 $nblinksToDisplay = $this->getNbLinks(count($linksToDisplay), $userInput); 107 $nblinksToDisplay = $this->getNbLinks(count($linksToDisplay), $userInput);
108 108
diff --git a/application/front/ShaarliMiddleware.php b/application/front/ShaarliMiddleware.php
index c015c0c6..d1aa1399 100644
--- a/application/front/ShaarliMiddleware.php
+++ b/application/front/ShaarliMiddleware.php
@@ -94,7 +94,7 @@ class ShaarliMiddleware
94 && $this->container->conf->get('privacy.force_login') 94 && $this->container->conf->get('privacy.force_login')
95 // and the current page isn't already the login page 95 // and the current page isn't already the login page
96 // and the user is not requesting a feed (which would lead to a different content-type as expected) 96 // and the user is not requesting a feed (which would lead to a different content-type as expected)
97 && !in_array($next->getName(), ['login', 'atom', 'rss'], true) 97 && !in_array($next->getName(), ['login', 'processLogin', 'atom', 'rss'], true)
98 ) { 98 ) {
99 throw new UnauthorizedException(); 99 throw new UnauthorizedException();
100 } 100 }
diff --git a/application/front/controller/visitor/FeedController.php b/application/front/controller/visitor/FeedController.php
index da2848c2..8d8b546a 100644
--- a/application/front/controller/visitor/FeedController.php
+++ b/application/front/controller/visitor/FeedController.php
@@ -46,10 +46,10 @@ class FeedController extends ShaarliVisitorController
46 46
47 $data = $this->container->feedBuilder->buildData($feedType, $request->getParams()); 47 $data = $this->container->feedBuilder->buildData($feedType, $request->getParams());
48 48
49 $this->executePageHooks('render_feed', $data, $feedType); 49 $this->executePageHooks('render_feed', $data, 'feed.' . $feedType);
50 $this->assignAllView($data); 50 $this->assignAllView($data);
51 51
52 $content = $this->render('feed.'. $feedType); 52 $content = $this->render('feed.' . $feedType);
53 53
54 $cache->cache($content); 54 $cache->cache($content);
55 55
diff --git a/application/legacy/LegacyController.php b/application/legacy/LegacyController.php
index 26465d2c..826604e7 100644
--- a/application/legacy/LegacyController.php
+++ b/application/legacy/LegacyController.php
@@ -39,29 +39,44 @@ class LegacyController extends ShaarliVisitorController
39 /** Legacy route: ?post= */ 39 /** Legacy route: ?post= */
40 public function post(Request $request, Response $response): Response 40 public function post(Request $request, Response $response): Response
41 { 41 {
42 $parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : ''; 42 $route = '/admin/shaare';
43 $buildParameters = function (?array $parameters, bool $encode) {
44 if ($encode) {
45 $parameters = array_map('urlencode', $parameters);
46 }
47
48 return count($parameters) > 0 ? '?' . http_build_query($parameters) : '';
49 };
50
43 51
44 if (!$this->container->loginManager->isLoggedIn()) { 52 if (!$this->container->loginManager->isLoggedIn()) {
45 return $this->redirect($response, '/login' . $parameters); 53 $parameters = $buildParameters($request->getQueryParams(), true);
54 return $this->redirect($response, '/login?returnurl='. $this->getBasePath() . $route . $parameters);
46 } 55 }
47 56
48 return $this->redirect($response, '/admin/shaare' . $parameters); 57 $parameters = $buildParameters($request->getQueryParams(), false);
58
59 return $this->redirect($response, $route . $parameters);
49 } 60 }
50 61
51 /** Legacy route: ?addlink= */ 62 /** Legacy route: ?addlink= */
52 protected function addlink(Request $request, Response $response): Response 63 protected function addlink(Request $request, Response $response): Response
53 { 64 {
65 $route = '/admin/add-shaare';
66
54 if (!$this->container->loginManager->isLoggedIn()) { 67 if (!$this->container->loginManager->isLoggedIn()) {
55 return $this->redirect($response, '/login'); 68 return $this->redirect($response, '/login?returnurl=' . $this->getBasePath() . $route);
56 } 69 }
57 70
58 return $this->redirect($response, '/admin/add-shaare'); 71 return $this->redirect($response, $route);
59 } 72 }
60 73
61 /** Legacy route: ?do=login */ 74 /** Legacy route: ?do=login */
62 protected function login(Request $request, Response $response): Response 75 protected function login(Request $request, Response $response): Response
63 { 76 {
64 return $this->redirect($response, '/login'); 77 $returnUrl = $request->getQueryParam('returnurl');
78
79 return $this->redirect($response, '/login' . ($returnUrl ? '?returnurl=' . $returnUrl : ''));
65 } 80 }
66 81
67 /** Legacy route: ?do=logout */ 82 /** Legacy route: ?do=logout */
@@ -127,4 +142,21 @@ class LegacyController extends ShaarliVisitorController
127 142
128 return $this->redirect($response, '/feed/' . $feedType . $parameters); 143 return $this->redirect($response, '/feed/' . $feedType . $parameters);
129 } 144 }
145
146 /** Legacy route: ?do=configure */
147 protected function configure(Request $request, Response $response): Response
148 {
149 $route = '/admin/configure';
150
151 if (!$this->container->loginManager->isLoggedIn()) {
152 return $this->redirect($response, '/login?returnurl=' . $this->getBasePath() . $route);
153 }
154
155 return $this->redirect($response, $route);
156 }
157
158 protected function getBasePath(): string
159 {
160 return $this->container->basePath ?: '';
161 }
130} 162}
diff --git a/application/legacy/LegacyRouter.php b/application/legacy/LegacyRouter.php
index cea99154..0449c7e1 100644
--- a/application/legacy/LegacyRouter.php
+++ b/application/legacy/LegacyRouter.php
@@ -17,15 +17,15 @@ class LegacyRouter
17 17
18 public static $PAGE_PICWALL = 'picwall'; 18 public static $PAGE_PICWALL = 'picwall';
19 19
20 public static $PAGE_TAGCLOUD = 'tagcloud'; 20 public static $PAGE_TAGCLOUD = 'tag.cloud';
21 21
22 public static $PAGE_TAGLIST = 'taglist'; 22 public static $PAGE_TAGLIST = 'tag.list';
23 23
24 public static $PAGE_DAILY = 'daily'; 24 public static $PAGE_DAILY = 'daily';
25 25
26 public static $PAGE_FEED_ATOM = 'atom'; 26 public static $PAGE_FEED_ATOM = 'feed.atom';
27 27
28 public static $PAGE_FEED_RSS = 'rss'; 28 public static $PAGE_FEED_RSS = 'feed.rss';
29 29
30 public static $PAGE_TOOLS = 'tools'; 30 public static $PAGE_TOOLS = 'tools';
31 31
@@ -37,7 +37,7 @@ class LegacyRouter
37 37
38 public static $PAGE_ADDLINK = 'addlink'; 38 public static $PAGE_ADDLINK = 'addlink';
39 39
40 public static $PAGE_EDITLINK = 'edit_link'; 40 public static $PAGE_EDITLINK = 'editlink';
41 41
42 public static $PAGE_DELETELINK = 'delete_link'; 42 public static $PAGE_DELETELINK = 'delete_link';
43 43
@@ -60,128 +60,4 @@ class LegacyRouter
60 public static $PAGE_THUMBS_UPDATE = 'thumbs_update'; 60 public static $PAGE_THUMBS_UPDATE = 'thumbs_update';
61 61
62 public static $GET_TOKEN = 'token'; 62 public static $GET_TOKEN = 'token';
63
64 /**
65 * Reproducing renderPage() if hell, to avoid regression.
66 *
67 * This highlights how bad this needs to be rewrite,
68 * but let's focus on plugins for now.
69 *
70 * @param string $query $_SERVER['QUERY_STRING'].
71 * @param array $get $_SERVER['GET'].
72 * @param bool $loggedIn true if authenticated user.
73 *
74 * @return string page found.
75 */
76 public static function findPage($query, $get, $loggedIn)
77 {
78 $loggedIn = ($loggedIn === true) ? true : false;
79
80 if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) {
81 return self::$PAGE_LINKLIST;
82 }
83
84 if (startsWith($query, 'do=' . self::$PAGE_LOGIN) && $loggedIn === false) {
85 return self::$PAGE_LOGIN;
86 }
87
88 if (startsWith($query, 'do=' . self::$PAGE_PICWALL)) {
89 return self::$PAGE_PICWALL;
90 }
91
92 if (startsWith($query, 'do=' . self::$PAGE_TAGCLOUD)) {
93 return self::$PAGE_TAGCLOUD;
94 }
95
96 if (startsWith($query, 'do=' . self::$PAGE_TAGLIST)) {
97 return self::$PAGE_TAGLIST;
98 }
99
100 if (startsWith($query, 'do=' . self::$PAGE_OPENSEARCH)) {
101 return self::$PAGE_OPENSEARCH;
102 }
103
104 if (startsWith($query, 'do=' . self::$PAGE_DAILY)) {
105 return self::$PAGE_DAILY;
106 }
107
108 if (startsWith($query, 'do=' . self::$PAGE_FEED_ATOM)) {
109 return self::$PAGE_FEED_ATOM;
110 }
111
112 if (startsWith($query, 'do=' . self::$PAGE_FEED_RSS)) {
113 return self::$PAGE_FEED_RSS;
114 }
115
116 if (startsWith($query, 'do=' . self::$PAGE_THUMBS_UPDATE)) {
117 return self::$PAGE_THUMBS_UPDATE;
118 }
119
120 if (startsWith($query, 'do=' . self::$AJAX_THUMB_UPDATE)) {
121 return self::$AJAX_THUMB_UPDATE;
122 }
123
124 // At this point, only loggedin pages.
125 if (!$loggedIn) {
126 return self::$PAGE_LINKLIST;
127 }
128
129 if (startsWith($query, 'do=' . self::$PAGE_TOOLS)) {
130 return self::$PAGE_TOOLS;
131 }
132
133 if (startsWith($query, 'do=' . self::$PAGE_CHANGEPASSWORD)) {
134 return self::$PAGE_CHANGEPASSWORD;
135 }
136
137 if (startsWith($query, 'do=' . self::$PAGE_CONFIGURE)) {
138 return self::$PAGE_CONFIGURE;
139 }
140
141 if (startsWith($query, 'do=' . self::$PAGE_CHANGETAG)) {
142 return self::$PAGE_CHANGETAG;
143 }
144
145 if (startsWith($query, 'do=' . self::$PAGE_ADDLINK)) {
146 return self::$PAGE_ADDLINK;
147 }
148
149 if (isset($get['edit_link']) || isset($get['post'])) {
150 return self::$PAGE_EDITLINK;
151 }
152
153 if (isset($get['delete_link'])) {
154 return self::$PAGE_DELETELINK;
155 }
156
157 if (isset($get[self::$PAGE_CHANGE_VISIBILITY])) {
158 return self::$PAGE_CHANGE_VISIBILITY;
159 }
160
161 if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) {
162 return self::$PAGE_PINLINK;
163 }
164
165 if (startsWith($query, 'do=' . self::$PAGE_EXPORT)) {
166 return self::$PAGE_EXPORT;
167 }
168
169 if (startsWith($query, 'do=' . self::$PAGE_IMPORT)) {
170 return self::$PAGE_IMPORT;
171 }
172
173 if (startsWith($query, 'do=' . self::$PAGE_PLUGINSADMIN)) {
174 return self::$PAGE_PLUGINSADMIN;
175 }
176
177 if (startsWith($query, 'do=' . self::$PAGE_SAVE_PLUGINSADMIN)) {
178 return self::$PAGE_SAVE_PLUGINSADMIN;
179 }
180
181 if (startsWith($query, 'do=' . self::$GET_TOKEN)) {
182 return self::$GET_TOKEN;
183 }
184
185 return self::$PAGE_LINKLIST;
186 }
187} 63}
diff --git a/assets/default/js/base.js b/assets/default/js/base.js
index 0f29799d..27938823 100644
--- a/assets/default/js/base.js
+++ b/assets/default/js/base.js
@@ -25,16 +25,18 @@ function findParent(element, tagName, attributes) {
25/** 25/**
26 * Ajax request to refresh the CSRF token. 26 * Ajax request to refresh the CSRF token.
27 */ 27 */
28function refreshToken(basePath) { 28function refreshToken(basePath, callback) {
29 console.log('refresh');
30 const xhr = new XMLHttpRequest(); 29 const xhr = new XMLHttpRequest();
31 xhr.open('GET', `${basePath}/admin/token`); 30 xhr.open('GET', `${basePath}/admin/token`);
32 xhr.onload = () => { 31 xhr.onload = () => {
33 const elements = document.querySelectorAll('input[name="token"]'); 32 const elements = document.querySelectorAll('input[name="token"]');
34 [...elements].forEach((element) => { 33 [...elements].forEach((element) => {
35 console.log(element);
36 element.setAttribute('value', xhr.responseText); 34 element.setAttribute('value', xhr.responseText);
37 }); 35 });
36
37 if (callback) {
38 callback(xhr.response);
39 }
38 }; 40 };
39 xhr.send(); 41 xhr.send();
40} 42}
@@ -622,4 +624,15 @@ function init(description) {
622 [...autocompleteFields].forEach((autocompleteField) => { 624 [...autocompleteFields].forEach((autocompleteField) => {
623 awesomepletes.push(createAwesompleteInstance(autocompleteField)); 625 awesomepletes.push(createAwesompleteInstance(autocompleteField));
624 }); 626 });
627
628 const exportForm = document.querySelector('#exportform');
629 if (exportForm != null) {
630 exportForm.addEventListener('submit', (event) => {
631 event.preventDefault();
632
633 refreshToken(basePath, () => {
634 event.target.submit();
635 });
636 });
637 }
625})(); 638})();
diff --git a/inc/languages/ja/LC_MESSAGES/shaarli.po b/inc/languages/jp/LC_MESSAGES/shaarli.po
index b420bb51..b420bb51 100644
--- a/inc/languages/ja/LC_MESSAGES/shaarli.po
+++ b/inc/languages/jp/LC_MESSAGES/shaarli.po
diff --git a/plugins/default_colors/default_colors.php b/plugins/default_colors/default_colors.php
index 1928cc9f..e1fd5cfb 100644
--- a/plugins/default_colors/default_colors.php
+++ b/plugins/default_colors/default_colors.php
@@ -15,6 +15,8 @@ const DEFAULT_COLORS_PLACEHOLDERS = [
15 'DEFAULT_COLORS_DARK_MAIN', 15 'DEFAULT_COLORS_DARK_MAIN',
16]; 16];
17 17
18const DEFAULT_COLORS_CSS_FILE = '/default_colors/default_colors.css';
19
18/** 20/**
19 * Display an error if the plugin is active a no color is configured. 21 * Display an error if the plugin is active a no color is configured.
20 * 22 *
@@ -24,58 +26,62 @@ const DEFAULT_COLORS_PLACEHOLDERS = [
24 */ 26 */
25function default_colors_init($conf) 27function default_colors_init($conf)
26{ 28{
27 $params = ''; 29 $params = [];
28 foreach (DEFAULT_COLORS_PLACEHOLDERS as $placeholder) { 30 foreach (DEFAULT_COLORS_PLACEHOLDERS as $placeholder) {
29 $params .= trim($conf->get('plugins.'. $placeholder, '')); 31 $value = trim($conf->get('plugins.'. $placeholder, ''));
32 if (strlen($value) > 0) {
33 $params[$placeholder] = $value;
34 }
30 } 35 }
31 36
32 if (empty($params)) { 37 if (empty($params)) {
33 $error = t('Default colors plugin error: '. 38 $error = t('Default colors plugin error: '.
34 'This plugin is active and no custom color is configured.'); 39 'This plugin is active and no custom color is configured.');
35 return array($error); 40 return [$error];
41 }
42
43 // Colors are defined but the custom CSS file does not exist -> generate it
44 if (!file_exists(PluginManager::$PLUGINS_PATH . DEFAULT_COLORS_CSS_FILE)) {
45 default_colors_generate_css_file($params);
36 } 46 }
37} 47}
38 48
39/** 49/**
40 * When plugin parameters are saved, we regenerate the custom CSS file with provided settings. 50 * When linklist is displayed, include default_colors CSS file.
41 * 51 *
42 * @param array $data $_POST array 52 * @param array $data - header data.
43 * 53 *
44 * @return array Updated $_POST array 54 * @return mixed - header data with default_colors CSS file added.
45 */ 55 */
46function hook_default_colors_save_plugin_parameters($data) 56function hook_default_colors_render_includes($data)
47{ 57{
48 $file = PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css'; 58 $file = PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css';
49 $template = file_get_contents(PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css.template'); 59 if (file_exists($file )) {
50 $content = ''; 60 $data['css_files'][] = $file ;
51 foreach (DEFAULT_COLORS_PLACEHOLDERS as $rule) {
52 $content .= ! empty($data[$rule])
53 ? default_colors_format_css_rule($data, $rule) .';'. PHP_EOL
54 : '';
55 }
56
57 if (! empty($content)) {
58 file_put_contents($file, sprintf($template, $content));
59 } 61 }
60 62
61 return $data; 63 return $data;
62} 64}
63 65
64/** 66/**
65 * When linklist is displayed, include default_colors CSS file. 67 * Regenerate the custom CSS file with provided settings.
66 *
67 * @param array $data - header data.
68 * 68 *
69 * @return mixed - header data with default_colors CSS file added. 69 * @param array $params Plugin configuration (CSS rules)
70 */ 70 */
71function hook_default_colors_render_includes($data) 71function default_colors_generate_css_file($params): void
72{ 72{
73 $file = PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css'; 73 $file = PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css';
74 if (file_exists($file )) { 74 $template = file_get_contents(PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css.template');
75 $data['css_files'][] = $file ; 75 $content = '';
76 foreach (DEFAULT_COLORS_PLACEHOLDERS as $rule) {
77 $content .= !empty($params[$rule])
78 ? default_colors_format_css_rule($params, $rule) .';'. PHP_EOL
79 : '';
76 } 80 }
77 81
78 return $data; 82 if (! empty($content)) {
83 file_put_contents($file, sprintf($template, $content));
84 }
79} 85}
80 86
81/** 87/**
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php
index 5c2aaedb..fe37d5f2 100644
--- a/tests/feed/FeedBuilderTest.php
+++ b/tests/feed/FeedBuilderTest.php
@@ -87,7 +87,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
87 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 87 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
88 88
89 // Test first not pinned link (note link) 89 // Test first not pinned link (note link)
90 $link = $data['links'][array_keys($data['links'])[2]]; 90 $link = $data['links'][array_keys($data['links'])[0]];
91 $this->assertEquals(41, $link['id']); 91 $this->assertEquals(41, $link['id']);
92 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 92 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
93 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); 93 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']);
@@ -128,7 +128,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
128 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); 128 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
129 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 129 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
130 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']); 130 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']);
131 $link = $data['links'][array_keys($data['links'])[2]]; 131 $link = $data['links'][array_keys($data['links'])[0]];
132 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']); 132 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']);
133 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']); 133 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']);
134 } 134 }
@@ -173,7 +173,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
173 $feedBuilder->setLocale(self::$LOCALE); 173 $feedBuilder->setLocale(self::$LOCALE);
174 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria); 174 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria);
175 $this->assertEquals(3, count($data['links'])); 175 $this->assertEquals(3, count($data['links']));
176 $link = $data['links'][array_keys($data['links'])[2]]; 176 $link = $data['links'][array_keys($data['links'])[0]];
177 $this->assertEquals(41, $link['id']); 177 $this->assertEquals(41, $link['id']);
178 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 178 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
179 } 179 }
@@ -195,7 +195,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
195 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 195 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
196 $this->assertTrue($data['usepermalinks']); 196 $this->assertTrue($data['usepermalinks']);
197 // First link is a permalink 197 // First link is a permalink
198 $link = $data['links'][array_keys($data['links'])[2]]; 198 $link = $data['links'][array_keys($data['links'])[0]];
199 $this->assertEquals(41, $link['id']); 199 $this->assertEquals(41, $link['id']);
200 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 200 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
201 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); 201 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']);
@@ -203,7 +203,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
203 $this->assertContains('Direct link', $link['description']); 203 $this->assertContains('Direct link', $link['description']);
204 $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); 204 $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']);
205 // Second link is a direct link 205 // Second link is a direct link
206 $link = $data['links'][array_keys($data['links'])[3]]; 206 $link = $data['links'][array_keys($data['links'])[1]];
207 $this->assertEquals(8, $link['id']); 207 $this->assertEquals(8, $link['id']);
208 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); 208 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
209 $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']); 209 $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']);
@@ -270,7 +270,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
270 ); 270 );
271 271
272 // Test first link (note link) 272 // Test first link (note link)
273 $link = $data['links'][array_keys($data['links'])[2]]; 273 $link = $data['links'][array_keys($data['links'])[0]];
274 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']); 274 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']);
275 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']); 275 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']);
276 $this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']); 276 $this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']);
diff --git a/tests/front/controller/admin/ConfigureControllerTest.php b/tests/front/controller/admin/ConfigureControllerTest.php
index f2f84bac..612f20f1 100644
--- a/tests/front/controller/admin/ConfigureControllerTest.php
+++ b/tests/front/controller/admin/ConfigureControllerTest.php
@@ -62,7 +62,7 @@ class ConfigureControllerTest extends TestCase
62 static::assertSame('privacy.hide_public_links', $assignedVariables['hide_public_links']); 62 static::assertSame('privacy.hide_public_links', $assignedVariables['hide_public_links']);
63 static::assertSame('api.enabled', $assignedVariables['api_enabled']); 63 static::assertSame('api.enabled', $assignedVariables['api_enabled']);
64 static::assertSame('api.secret', $assignedVariables['api_secret']); 64 static::assertSame('api.secret', $assignedVariables['api_secret']);
65 static::assertCount(4, $assignedVariables['languages']); 65 static::assertCount(5, $assignedVariables['languages']);
66 static::assertArrayHasKey('gd_enabled', $assignedVariables); 66 static::assertArrayHasKey('gd_enabled', $assignedVariables);
67 static::assertSame('thumbnails.mode', $assignedVariables['thumbnails_mode']); 67 static::assertSame('thumbnails.mode', $assignedVariables['thumbnails_mode']);
68 } 68 }
diff --git a/tests/front/controller/visitor/FeedControllerTest.php b/tests/front/controller/visitor/FeedControllerTest.php
index fb417e2a..0a6b577f 100644
--- a/tests/front/controller/visitor/FeedControllerTest.php
+++ b/tests/front/controller/visitor/FeedControllerTest.php
@@ -52,7 +52,7 @@ class FeedControllerTest extends TestCase
52 static::assertSame('data', $data['content']); 52 static::assertSame('data', $data['content']);
53 53
54 static::assertArrayHasKey('loggedin', $param); 54 static::assertArrayHasKey('loggedin', $param);
55 static::assertSame('rss', $param['target']); 55 static::assertSame('feed.rss', $param['target']);
56 }) 56 })
57 ; 57 ;
58 58
@@ -91,7 +91,7 @@ class FeedControllerTest extends TestCase
91 static::assertSame('data', $data['content']); 91 static::assertSame('data', $data['content']);
92 92
93 static::assertArrayHasKey('loggedin', $param); 93 static::assertArrayHasKey('loggedin', $param);
94 static::assertSame('atom', $param['target']); 94 static::assertSame('feed.atom', $param['target']);
95 }) 95 })
96 ; 96 ;
97 97
@@ -131,7 +131,7 @@ class FeedControllerTest extends TestCase
131 static::assertSame('data', $data['content']); 131 static::assertSame('data', $data['content']);
132 132
133 static::assertArrayHasKey('loggedin', $param); 133 static::assertArrayHasKey('loggedin', $param);
134 static::assertSame('atom', $param['target']); 134 static::assertSame('feed.atom', $param['target']);
135 }) 135 })
136 ; 136 ;
137 137
diff --git a/tests/legacy/LegacyControllerTest.php b/tests/legacy/LegacyControllerTest.php
index 759a5b2a..4e52f3e1 100644
--- a/tests/legacy/LegacyControllerTest.php
+++ b/tests/legacy/LegacyControllerTest.php
@@ -66,11 +66,11 @@ class LegacyControllerTest extends TestCase
66 { 66 {
67 return [ 67 return [
68 ['post', [], '/admin/shaare', true], 68 ['post', [], '/admin/shaare', true],
69 ['post', [], '/login', false], 69 ['post', [], '/login?returnurl=/subfolder/admin/shaare', false],
70 ['post', ['title' => 'test'], '/admin/shaare?title=test', true], 70 ['post', ['title' => 'test'], '/admin/shaare?title=test', true],
71 ['post', ['title' => 'test'], '/login?title=test', false], 71 ['post', ['title' => 'test'], '/login?returnurl=/subfolder/admin/shaare?title=test', false],
72 ['addlink', [], '/admin/add-shaare', true], 72 ['addlink', [], '/admin/add-shaare', true],
73 ['addlink', [], '/login', false], 73 ['addlink', [], '/login?returnurl=/subfolder/admin/add-shaare', false],
74 ['login', [], '/login', true], 74 ['login', [], '/login', true],
75 ['login', [], '/login', false], 75 ['login', [], '/login', false],
76 ['logout', [], '/admin/logout', true], 76 ['logout', [], '/admin/logout', true],
@@ -94,6 +94,8 @@ class LegacyControllerTest extends TestCase
94 ['opensearch', [], '/open-search', true], 94 ['opensearch', [], '/open-search', true],
95 ['dailyrss', [], '/daily-rss', false], 95 ['dailyrss', [], '/daily-rss', false],
96 ['dailyrss', [], '/daily-rss', true], 96 ['dailyrss', [], '/daily-rss', true],
97 ['configure', [], '/login?returnurl=/subfolder/admin/configure', false],
98 ['configure', [], '/admin/configure', true],
97 ]; 99 ];
98 } 100 }
99} 101}
diff --git a/tests/legacy/LegacyRouterTest.php b/tests/legacy/LegacyRouterTest.php
deleted file mode 100644
index c2019ca7..00000000
--- a/tests/legacy/LegacyRouterTest.php
+++ /dev/null
@@ -1,512 +0,0 @@
1<?php
2
3namespace Shaarli\Legacy;
4
5use PHPUnit\Framework\TestCase;
6
7/**
8 * Unit tests for Router
9 */
10class LegacyRouterTest extends TestCase
11{
12 /**
13 * Test findPage: login page output.
14 * Valid: page should be return.
15 *
16 * @return void
17 */
18 public function testFindPageLoginValid()
19 {
20 $this->assertEquals(
21 LegacyRouter::$PAGE_LOGIN,
22 LegacyRouter::findPage('do=login', array(), false)
23 );
24
25 $this->assertEquals(
26 LegacyRouter::$PAGE_LOGIN,
27 LegacyRouter::findPage('do=login', array(), 1)
28 );
29
30 $this->assertEquals(
31 LegacyRouter::$PAGE_LOGIN,
32 LegacyRouter::findPage('do=login&stuff', array(), false)
33 );
34 }
35
36 /**
37 * Test findPage: login page output.
38 * Invalid: page shouldn't be return.
39 *
40 * @return void
41 */
42 public function testFindPageLoginInvalid()
43 {
44 $this->assertNotEquals(
45 LegacyRouter::$PAGE_LOGIN,
46 LegacyRouter::findPage('do=login', array(), true)
47 );
48
49 $this->assertNotEquals(
50 LegacyRouter::$PAGE_LOGIN,
51 LegacyRouter::findPage('do=other', array(), false)
52 );
53 }
54
55 /**
56 * Test findPage: picwall page output.
57 * Valid: page should be return.
58 *
59 * @return void
60 */
61 public function testFindPagePicwallValid()
62 {
63 $this->assertEquals(
64 LegacyRouter::$PAGE_PICWALL,
65 LegacyRouter::findPage('do=picwall', array(), false)
66 );
67
68 $this->assertEquals(
69 LegacyRouter::$PAGE_PICWALL,
70 LegacyRouter::findPage('do=picwall', array(), true)
71 );
72 }
73
74 /**
75 * Test findPage: picwall page output.
76 * Invalid: page shouldn't be return.
77 *
78 * @return void
79 */
80 public function testFindPagePicwallInvalid()
81 {
82 $this->assertEquals(
83 LegacyRouter::$PAGE_PICWALL,
84 LegacyRouter::findPage('do=picwall&stuff', array(), false)
85 );
86
87 $this->assertNotEquals(
88 LegacyRouter::$PAGE_PICWALL,
89 LegacyRouter::findPage('do=other', array(), false)
90 );
91 }
92
93 /**
94 * Test findPage: tagcloud page output.
95 * Valid: page should be return.
96 *
97 * @return void
98 */
99 public function testFindPageTagcloudValid()
100 {
101 $this->assertEquals(
102 LegacyRouter::$PAGE_TAGCLOUD,
103 LegacyRouter::findPage('do=tagcloud', array(), false)
104 );
105
106 $this->assertEquals(
107 LegacyRouter::$PAGE_TAGCLOUD,
108 LegacyRouter::findPage('do=tagcloud', array(), true)
109 );
110
111 $this->assertEquals(
112 LegacyRouter::$PAGE_TAGCLOUD,
113 LegacyRouter::findPage('do=tagcloud&stuff', array(), false)
114 );
115 }
116
117 /**
118 * Test findPage: tagcloud page output.
119 * Invalid: page shouldn't be return.
120 *
121 * @return void
122 */
123 public function testFindPageTagcloudInvalid()
124 {
125 $this->assertNotEquals(
126 LegacyRouter::$PAGE_TAGCLOUD,
127 LegacyRouter::findPage('do=other', array(), false)
128 );
129 }
130
131 /**
132 * Test findPage: linklist page output.
133 * Valid: page should be return.
134 *
135 * @return void
136 */
137 public function testFindPageLinklistValid()
138 {
139 $this->assertEquals(
140 LegacyRouter::$PAGE_LINKLIST,
141 LegacyRouter::findPage('', array(), true)
142 );
143
144 $this->assertEquals(
145 LegacyRouter::$PAGE_LINKLIST,
146 LegacyRouter::findPage('whatever', array(), true)
147 );
148
149 $this->assertEquals(
150 LegacyRouter::$PAGE_LINKLIST,
151 LegacyRouter::findPage('whatever', array(), false)
152 );
153
154 $this->assertEquals(
155 LegacyRouter::$PAGE_LINKLIST,
156 LegacyRouter::findPage('do=tools', array(), false)
157 );
158 }
159
160 /**
161 * Test findPage: tools page output.
162 * Valid: page should be return.
163 *
164 * @return void
165 */
166 public function testFindPageToolsValid()
167 {
168 $this->assertEquals(
169 LegacyRouter::$PAGE_TOOLS,
170 LegacyRouter::findPage('do=tools', array(), true)
171 );
172
173 $this->assertEquals(
174 LegacyRouter::$PAGE_TOOLS,
175 LegacyRouter::findPage('do=tools&stuff', array(), true)
176 );
177 }
178
179 /**
180 * Test findPage: tools page output.
181 * Invalid: page shouldn't be return.
182 *
183 * @return void
184 */
185 public function testFindPageToolsInvalid()
186 {
187 $this->assertNotEquals(
188 LegacyRouter::$PAGE_TOOLS,
189 LegacyRouter::findPage('do=tools', array(), 1)
190 );
191
192 $this->assertNotEquals(
193 LegacyRouter::$PAGE_TOOLS,
194 LegacyRouter::findPage('do=tools', array(), false)
195 );
196
197 $this->assertNotEquals(
198 LegacyRouter::$PAGE_TOOLS,
199 LegacyRouter::findPage('do=other', array(), true)
200 );
201 }
202
203 /**
204 * Test findPage: changepasswd page output.
205 * Valid: page should be return.
206 *
207 * @return void
208 */
209 public function testFindPageChangepasswdValid()
210 {
211 $this->assertEquals(
212 LegacyRouter::$PAGE_CHANGEPASSWORD,
213 LegacyRouter::findPage('do=changepasswd', array(), true)
214 );
215 $this->assertEquals(
216 LegacyRouter::$PAGE_CHANGEPASSWORD,
217 LegacyRouter::findPage('do=changepasswd&stuff', array(), true)
218 );
219 }
220
221 /**
222 * Test findPage: changepasswd page output.
223 * Invalid: page shouldn't be return.
224 *
225 * @return void
226 */
227 public function testFindPageChangepasswdInvalid()
228 {
229 $this->assertNotEquals(
230 LegacyRouter::$PAGE_CHANGEPASSWORD,
231 LegacyRouter::findPage('do=changepasswd', array(), 1)
232 );
233
234 $this->assertNotEquals(
235 LegacyRouter::$PAGE_CHANGEPASSWORD,
236 LegacyRouter::findPage('do=changepasswd', array(), false)
237 );
238
239 $this->assertNotEquals(
240 LegacyRouter::$PAGE_CHANGEPASSWORD,
241 LegacyRouter::findPage('do=other', array(), true)
242 );
243 }
244 /**
245 * Test findPage: configure page output.
246 * Valid: page should be return.
247 *
248 * @return void
249 */
250 public function testFindPageConfigureValid()
251 {
252 $this->assertEquals(
253 LegacyRouter::$PAGE_CONFIGURE,
254 LegacyRouter::findPage('do=configure', array(), true)
255 );
256
257 $this->assertEquals(
258 LegacyRouter::$PAGE_CONFIGURE,
259 LegacyRouter::findPage('do=configure&stuff', array(), true)
260 );
261 }
262
263 /**
264 * Test findPage: configure page output.
265 * Invalid: page shouldn't be return.
266 *
267 * @return void
268 */
269 public function testFindPageConfigureInvalid()
270 {
271 $this->assertNotEquals(
272 LegacyRouter::$PAGE_CONFIGURE,
273 LegacyRouter::findPage('do=configure', array(), 1)
274 );
275
276 $this->assertNotEquals(
277 LegacyRouter::$PAGE_CONFIGURE,
278 LegacyRouter::findPage('do=configure', array(), false)
279 );
280
281 $this->assertNotEquals(
282 LegacyRouter::$PAGE_CONFIGURE,
283 LegacyRouter::findPage('do=other', array(), true)
284 );
285 }
286
287 /**
288 * Test findPage: changetag page output.
289 * Valid: page should be return.
290 *
291 * @return void
292 */
293 public function testFindPageChangetagValid()
294 {
295 $this->assertEquals(
296 LegacyRouter::$PAGE_CHANGETAG,
297 LegacyRouter::findPage('do=changetag', array(), true)
298 );
299
300 $this->assertEquals(
301 LegacyRouter::$PAGE_CHANGETAG,
302 LegacyRouter::findPage('do=changetag&stuff', array(), true)
303 );
304 }
305
306 /**
307 * Test findPage: changetag page output.
308 * Invalid: page shouldn't be return.
309 *
310 * @return void
311 */
312 public function testFindPageChangetagInvalid()
313 {
314 $this->assertNotEquals(
315 LegacyRouter::$PAGE_CHANGETAG,
316 LegacyRouter::findPage('do=changetag', array(), 1)
317 );
318
319 $this->assertNotEquals(
320 LegacyRouter::$PAGE_CHANGETAG,
321 LegacyRouter::findPage('do=changetag', array(), false)
322 );
323
324 $this->assertNotEquals(
325 LegacyRouter::$PAGE_CHANGETAG,
326 LegacyRouter::findPage('do=other', array(), true)
327 );
328 }
329
330 /**
331 * Test findPage: addlink page output.
332 * Valid: page should be return.
333 *
334 * @return void
335 */
336 public function testFindPageAddlinkValid()
337 {
338 $this->assertEquals(
339 LegacyRouter::$PAGE_ADDLINK,
340 LegacyRouter::findPage('do=addlink', array(), true)
341 );
342
343 $this->assertEquals(
344 LegacyRouter::$PAGE_ADDLINK,
345 LegacyRouter::findPage('do=addlink&stuff', array(), true)
346 );
347 }
348
349 /**
350 * Test findPage: addlink page output.
351 * Invalid: page shouldn't be return.
352 *
353 * @return void
354 */
355 public function testFindPageAddlinkInvalid()
356 {
357 $this->assertNotEquals(
358 LegacyRouter::$PAGE_ADDLINK,
359 LegacyRouter::findPage('do=addlink', array(), 1)
360 );
361
362 $this->assertNotEquals(
363 LegacyRouter::$PAGE_ADDLINK,
364 LegacyRouter::findPage('do=addlink', array(), false)
365 );
366
367 $this->assertNotEquals(
368 LegacyRouter::$PAGE_ADDLINK,
369 LegacyRouter::findPage('do=other', array(), true)
370 );
371 }
372
373 /**
374 * Test findPage: export page output.
375 * Valid: page should be return.
376 *
377 * @return void
378 */
379 public function testFindPageExportValid()
380 {
381 $this->assertEquals(
382 LegacyRouter::$PAGE_EXPORT,
383 LegacyRouter::findPage('do=export', array(), true)
384 );
385
386 $this->assertEquals(
387 LegacyRouter::$PAGE_EXPORT,
388 LegacyRouter::findPage('do=export&stuff', array(), true)
389 );
390 }
391
392 /**
393 * Test findPage: export page output.
394 * Invalid: page shouldn't be return.
395 *
396 * @return void
397 */
398 public function testFindPageExportInvalid()
399 {
400 $this->assertNotEquals(
401 LegacyRouter::$PAGE_EXPORT,
402 LegacyRouter::findPage('do=export', array(), 1)
403 );
404
405 $this->assertNotEquals(
406 LegacyRouter::$PAGE_EXPORT,
407 LegacyRouter::findPage('do=export', array(), false)
408 );
409
410 $this->assertNotEquals(
411 LegacyRouter::$PAGE_EXPORT,
412 LegacyRouter::findPage('do=other', array(), true)
413 );
414 }
415
416 /**
417 * Test findPage: import page output.
418 * Valid: page should be return.
419 *
420 * @return void
421 */
422 public function testFindPageImportValid()
423 {
424 $this->assertEquals(
425 LegacyRouter::$PAGE_IMPORT,
426 LegacyRouter::findPage('do=import', array(), true)
427 );
428
429 $this->assertEquals(
430 LegacyRouter::$PAGE_IMPORT,
431 LegacyRouter::findPage('do=import&stuff', array(), true)
432 );
433 }
434
435 /**
436 * Test findPage: import page output.
437 * Invalid: page shouldn't be return.
438 *
439 * @return void
440 */
441 public function testFindPageImportInvalid()
442 {
443 $this->assertNotEquals(
444 LegacyRouter::$PAGE_IMPORT,
445 LegacyRouter::findPage('do=import', array(), 1)
446 );
447
448 $this->assertNotEquals(
449 LegacyRouter::$PAGE_IMPORT,
450 LegacyRouter::findPage('do=import', array(), false)
451 );
452
453 $this->assertNotEquals(
454 LegacyRouter::$PAGE_IMPORT,
455 LegacyRouter::findPage('do=other', array(), true)
456 );
457 }
458
459 /**
460 * Test findPage: editlink page output.
461 * Valid: page should be return.
462 *
463 * @return void
464 */
465 public function testFindPageEditlinkValid()
466 {
467 $this->assertEquals(
468 LegacyRouter::$PAGE_EDITLINK,
469 LegacyRouter::findPage('whatever', array('edit_link' => 1), true)
470 );
471
472 $this->assertEquals(
473 LegacyRouter::$PAGE_EDITLINK,
474 LegacyRouter::findPage('', array('edit_link' => 1), true)
475 );
476
477
478 $this->assertEquals(
479 LegacyRouter::$PAGE_EDITLINK,
480 LegacyRouter::findPage('whatever', array('post' => 1), true)
481 );
482
483 $this->assertEquals(
484 LegacyRouter::$PAGE_EDITLINK,
485 LegacyRouter::findPage('whatever', array('post' => 1, 'edit_link' => 1), true)
486 );
487 }
488
489 /**
490 * Test findPage: editlink page output.
491 * Invalid: page shouldn't be return.
492 *
493 * @return void
494 */
495 public function testFindPageEditlinkInvalid()
496 {
497 $this->assertNotEquals(
498 LegacyRouter::$PAGE_EDITLINK,
499 LegacyRouter::findPage('whatever', array('edit_link' => 1), false)
500 );
501
502 $this->assertNotEquals(
503 LegacyRouter::$PAGE_EDITLINK,
504 LegacyRouter::findPage('whatever', array('edit_link' => 1), 1)
505 );
506
507 $this->assertNotEquals(
508 LegacyRouter::$PAGE_EDITLINK,
509 LegacyRouter::findPage('whatever', array(), true)
510 );
511 }
512}
diff --git a/tests/plugins/PluginDefaultColorsTest.php b/tests/plugins/PluginDefaultColorsTest.php
index b9951cca..9835dfa3 100644
--- a/tests/plugins/PluginDefaultColorsTest.php
+++ b/tests/plugins/PluginDefaultColorsTest.php
@@ -2,7 +2,6 @@
2 2
3namespace Shaarli\Plugin\DefaultColors; 3namespace Shaarli\Plugin\DefaultColors;
4 4
5use DateTime;
6use PHPUnit\Framework\TestCase; 5use PHPUnit\Framework\TestCase;
7use Shaarli\Bookmark\LinkDB; 6use Shaarli\Bookmark\LinkDB;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
@@ -57,6 +56,8 @@ class PluginDefaultColorsTest extends TestCase
57 $conf->set('plugins.DEFAULT_COLORS_BACKGROUND', 'value'); 56 $conf->set('plugins.DEFAULT_COLORS_BACKGROUND', 'value');
58 $errors = default_colors_init($conf); 57 $errors = default_colors_init($conf);
59 $this->assertEmpty($errors); 58 $this->assertEmpty($errors);
59
60 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css');
60 } 61 }
61 62
62 /** 63 /**
@@ -72,9 +73,9 @@ class PluginDefaultColorsTest extends TestCase
72 /** 73 /**
73 * Test the save plugin parameters hook with all colors specified. 74 * Test the save plugin parameters hook with all colors specified.
74 */ 75 */
75 public function testSavePluginParametersAll() 76 public function testGenerateCssFile()
76 { 77 {
77 $post = [ 78 $params = [
78 'other1' => true, 79 'other1' => true,
79 'DEFAULT_COLORS_MAIN' => 'blue', 80 'DEFAULT_COLORS_MAIN' => 'blue',
80 'DEFAULT_COLORS_BACKGROUND' => 'pink', 81 'DEFAULT_COLORS_BACKGROUND' => 'pink',
@@ -82,7 +83,7 @@ class PluginDefaultColorsTest extends TestCase
82 'DEFAULT_COLORS_DARK_MAIN' => 'green', 83 'DEFAULT_COLORS_DARK_MAIN' => 'green',
83 ]; 84 ];
84 85
85 hook_default_colors_save_plugin_parameters($post); 86 default_colors_generate_css_file($params);
86 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css'); 87 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css');
87 $content = file_get_contents($file); 88 $content = file_get_contents($file);
88 $expected = ':root { 89 $expected = ':root {
@@ -98,16 +99,16 @@ class PluginDefaultColorsTest extends TestCase
98 /** 99 /**
99 * Test the save plugin parameters hook with only one color specified. 100 * Test the save plugin parameters hook with only one color specified.
100 */ 101 */
101 public function testSavePluginParametersSingle() 102 public function testGenerateCssFileSingle()
102 { 103 {
103 $post = [ 104 $params = [
104 'other1' => true, 105 'other1' => true,
105 'DEFAULT_COLORS_BACKGROUND' => 'pink', 106 'DEFAULT_COLORS_BACKGROUND' => 'pink',
106 'other2' => ['yep'], 107 'other2' => ['yep'],
107 'DEFAULT_COLORS_DARK_MAIN' => '', 108 'DEFAULT_COLORS_DARK_MAIN' => '',
108 ]; 109 ];
109 110
110 hook_default_colors_save_plugin_parameters($post); 111 default_colors_generate_css_file($params);
111 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css'); 112 $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css');
112 $content = file_get_contents($file); 113 $content = file_get_contents($file);
113 $expected = ':root { 114 $expected = ':root {
@@ -121,9 +122,9 @@ class PluginDefaultColorsTest extends TestCase
121 /** 122 /**
122 * Test the save plugin parameters hook with no color specified. 123 * Test the save plugin parameters hook with no color specified.
123 */ 124 */
124 public function testSavePluginParametersNone() 125 public function testGenerateCssFileNone()
125 { 126 {
126 hook_default_colors_save_plugin_parameters([]); 127 default_colors_generate_css_file([]);
127 $this->assertFileNotExists($file = 'sandbox/default_colors/default_colors.css'); 128 $this->assertFileNotExists($file = 'sandbox/default_colors/default_colors.css');
128 } 129 }
129 130
diff --git a/tpl/default/linklist.html b/tpl/default/linklist.html
index c7617b22..2475f5fd 100644
--- a/tpl/default/linklist.html
+++ b/tpl/default/linklist.html
@@ -272,7 +272,17 @@
272 <i class="fa fa-trash" aria-hidden="true"></i> 272 <i class="fa fa-trash" aria-hidden="true"></i>
273 </a> 273 </a>
274 &middot; 274 &middot;
275 <a href="{$base_path}/admin/shaare/{$value.id}" aria-label="{$strEdit}" title="{$strEdit}"><i class="fa fa-pencil-square-o edit-link" aria-hidden="true"></i></a> 275 <a href="{$base_path}/admin/shaare/{$value.id}" aria-label="{$strEdit}" title="{$strEdit}">
276 <i class="fa fa-pencil-square-o edit-link" aria-hidden="true"></i>
277 </a>
278 &middot;
279 <a href="{$base_path}/admin/shaare/{$value.id}/pin?token={$token}"
280 aria-label="{$strToggleSticky}"
281 title="{$strToggleSticky}"
282 class="pin-link {if="$value.sticky"}pinned-link{/if}"
283 >
284 <i class="fa fa-thumb-tack" aria-hidden="true"></i>
285 </a>
276 {/if} 286 {/if}
277 </div> 287 </div>
278 </div> 288 </div>