diff options
author | Seb Sauvage <seb@sebsauvage.net> | 2011-12-16 21:27:16 +0100 |
---|---|---|
committer | Emilien Klein <emilien+ubuntu@klein.st> | 2011-12-16 21:27:16 +0100 |
commit | 24e267ca714f591921eb659457332c3f7fea1930 (patch) | |
tree | 98fc646456708df7d3b133ed7f33835c1f1b059f | |
parent | 5112a433897d4d6507982b64bb07333b774ddb3a (diff) | |
download | Shaarli-24e267ca714f591921eb659457332c3f7fea1930.tar.gz Shaarli-24e267ca714f591921eb659457332c3f7fea1930.tar.zst Shaarli-24e267ca714f591921eb659457332c3f7fea1930.zip |
Version 0.0.32 beta:
- Changed: HTML generation moved to RainTPL templates (in the tpl/ directory).
- Added: Better check on URL parameters (patch by gege2061).
- Changed: Better detection of HTTPS (patch by gege2061).
- Changed: In RSS/ATOM feeds, the GUID is now the permalink instead of the final URL (patch by gege2061).
- Changed: Jerrywham CSS patch included.
- Changed: Multiple spaces are now respected in description. Thus you can use Shaarli as a personal pastebin (for posting source code, for example). I also ad$
- Corrected: Tab order changed in login screen.
- Corrected: Permalinks now work even if additional parameters have been added (eg. /?E8Yj2Q&utm_source=blablabla…)
- Corrected: user.css is included only if the file is present (This prevent a useless CSS include which makes a harmless but useless 404 error.).
- Removed: Page time generation was removed.
-rw-r--r-- | inc/jquery-ui.custom.min.js (renamed from jquery-ui.custom.min.js) | 0 | ||||
-rw-r--r-- | inc/jquery.min.js (renamed from jquery.min.js) | 0 | ||||
-rw-r--r-- | inc/rain.tpl.class.php | 1011 | ||||
-rw-r--r-- | inc/shaarli.css (renamed from shaarli.css) | 61 | ||||
-rw-r--r-- | index.php | 983 | ||||
-rw-r--r-- | tpl/addlink.html | 15 | ||||
-rw-r--r-- | tpl/changepassword.html | 14 | ||||
-rw-r--r-- | tpl/changetag.html | 15 | ||||
-rw-r--r-- | tpl/configure.html | 19 | ||||
-rw-r--r-- | tpl/editlink.html | 27 | ||||
-rw-r--r-- | tpl/export.html | 14 | ||||
-rw-r--r-- | tpl/import.html | 20 | ||||
-rw-r--r-- | tpl/includes.html | 7 | ||||
-rw-r--r-- | tpl/install.html | 20 | ||||
-rw-r--r-- | tpl/linklist.html | 61 | ||||
-rw-r--r-- | tpl/linklist.paging.html | 9 | ||||
-rw-r--r-- | tpl/loginform.html | 25 | ||||
-rw-r--r-- | tpl/page.footer.html | 20 | ||||
-rw-r--r-- | tpl/page.header.html | 24 | ||||
-rw-r--r-- | tpl/page.html | 8 | ||||
-rw-r--r-- | tpl/picwall.html | 16 | ||||
-rw-r--r-- | tpl/picwall2.html | 18 | ||||
-rw-r--r-- | tpl/readme.txt | 42 | ||||
-rw-r--r-- | tpl/tagcloud.html | 14 | ||||
-rw-r--r-- | tpl/tools.html | 18 |
25 files changed, 1860 insertions, 601 deletions
diff --git a/jquery-ui.custom.min.js b/inc/jquery-ui.custom.min.js index 42d75d2c..42d75d2c 100644 --- a/jquery-ui.custom.min.js +++ b/inc/jquery-ui.custom.min.js | |||
diff --git a/jquery.min.js b/inc/jquery.min.js index 48590ecb..48590ecb 100644 --- a/jquery.min.js +++ b/inc/jquery.min.js | |||
diff --git a/inc/rain.tpl.class.php b/inc/rain.tpl.class.php new file mode 100644 index 00000000..30b6deb8 --- /dev/null +++ b/inc/rain.tpl.class.php | |||
@@ -0,0 +1,1011 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * RainTPL | ||
5 | * ------- | ||
6 | * Realized by Federico Ulfo & maintained by the Rain Team | ||
7 | * Distributed under GNU/LGPL 3 License | ||
8 | * | ||
9 | * @version 2.6.4 | ||
10 | */ | ||
11 | |||
12 | |||
13 | class RainTPL{ | ||
14 | |||
15 | // ------------------------- | ||
16 | // CONFIGURATION | ||
17 | // ------------------------- | ||
18 | |||
19 | /** | ||
20 | * Template directory | ||
21 | * | ||
22 | * @var string | ||
23 | */ | ||
24 | static $tpl_dir = "tpl/"; | ||
25 | |||
26 | |||
27 | /** | ||
28 | * Cache directory. Is the directory where RainTPL will compile the template and save the cache | ||
29 | * | ||
30 | * @var string | ||
31 | */ | ||
32 | static $cache_dir = "tmp/"; | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Template base URL. RainTPL will add this URL to the relative paths of element selected in $path_replace_list. | ||
37 | * | ||
38 | * @var string | ||
39 | */ | ||
40 | static $base_url = null; | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Template extension. | ||
45 | * | ||
46 | * @var string | ||
47 | */ | ||
48 | static $tpl_ext = "html"; | ||
49 | |||
50 | |||
51 | /** | ||
52 | * Path replace is a cool features that replace all relative paths of images (<img src="...">), stylesheet (<link href="...">), script (<script src="...">) and link (<a href="...">) | ||
53 | * Set true to enable the path replace. | ||
54 | * | ||
55 | * @var unknown_type | ||
56 | */ | ||
57 | static $path_replace = true; | ||
58 | |||
59 | |||
60 | /** | ||
61 | * You can set what the path_replace method will replace. | ||
62 | * Avaible options: a, img, link, script, input | ||
63 | * | ||
64 | * @var array | ||
65 | */ | ||
66 | static $path_replace_list = array( 'a', 'img', 'link', 'script', 'input' ); | ||
67 | |||
68 | |||
69 | /** | ||
70 | * You can define in the black list what string are disabled into the template tags | ||
71 | * | ||
72 | * @var unknown_type | ||
73 | */ | ||
74 | static $black_list = array( '\$this', 'raintpl::', 'self::', '_SESSION', '_SERVER', '_ENV', 'eval', 'exec', 'unlink', 'rmdir' ); | ||
75 | |||
76 | |||
77 | /** | ||
78 | * Check template. | ||
79 | * true: checks template update time, if changed it compile them | ||
80 | * false: loads the compiled template. Set false if server doesn't have write permission for cache_directory. | ||
81 | * | ||
82 | */ | ||
83 | static $check_template_update = true; | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Debug mode flag. | ||
88 | * True: debug mode is used, syntax errors are displayed directly in template. Execution of script is not terminated. | ||
89 | * False: exception is thrown on found error. | ||
90 | * | ||
91 | * @var bool | ||
92 | */ | ||
93 | static $debug = false; | ||
94 | |||
95 | // ------------------------- | ||
96 | |||
97 | |||
98 | // ------------------------- | ||
99 | // RAINTPL VARIABLES | ||
100 | // ------------------------- | ||
101 | |||
102 | /** | ||
103 | * Is the array where RainTPL keep the variables assigned | ||
104 | * | ||
105 | * @var array | ||
106 | */ | ||
107 | public $var = array(); | ||
108 | |||
109 | private $tpl = array(), // variables to keep the template directories and info | ||
110 | $cache = false, // static cache enabled / disabled | ||
111 | $cache_id = null; // identify only one cache | ||
112 | |||
113 | private static $config_name_sum = null; // takes all the config to create the md5 of the file | ||
114 | |||
115 | // ------------------------- | ||
116 | |||
117 | |||
118 | |||
119 | const CACHE_EXPIRE_TIME = 3600; // default cache expire time = hour | ||
120 | |||
121 | |||
122 | |||
123 | /** | ||
124 | * Assign variable | ||
125 | * eg. $t->assign('name','mickey'); | ||
126 | * | ||
127 | * @param mixed $variable_name Name of template variable or associative array name/value | ||
128 | * @param mixed $value value assigned to this variable. Not set if variable_name is an associative array | ||
129 | */ | ||
130 | |||
131 | function assign( $variable, $value = null ){ | ||
132 | if( is_array( $variable ) ) | ||
133 | $this->var += $variable; | ||
134 | else | ||
135 | $this->var[ $variable ] = $value; | ||
136 | } | ||
137 | |||
138 | |||
139 | |||
140 | /** | ||
141 | * Draw the template | ||
142 | * eg. $html = $tpl->draw( 'demo', TRUE ); // return template in string | ||
143 | * or $tpl->draw( $tpl_name ); // echo the template | ||
144 | * | ||
145 | * @param string $tpl_name template to load | ||
146 | * @param boolean $return_string true=return a string, false=echo the template | ||
147 | * @return string | ||
148 | */ | ||
149 | |||
150 | function draw( $tpl_name, $return_string = false ){ | ||
151 | |||
152 | try { | ||
153 | // compile the template if necessary and set the template filepath | ||
154 | $this->check_template( $tpl_name ); | ||
155 | } catch (RainTpl_Exception $e) { | ||
156 | $output = $this->printDebug($e); | ||
157 | die($output); | ||
158 | } | ||
159 | |||
160 | // Cache is off and, return_string is false | ||
161 | // Rain just echo the template | ||
162 | |||
163 | if( !$this->cache && !$return_string ){ | ||
164 | extract( $this->var ); | ||
165 | include $this->tpl['compiled_filename']; | ||
166 | unset( $this->tpl ); | ||
167 | } | ||
168 | |||
169 | |||
170 | // cache or return_string are enabled | ||
171 | // rain get the output buffer to save the output in the cache or to return it as string | ||
172 | |||
173 | else{ | ||
174 | |||
175 | //---------------------- | ||
176 | // get the output buffer | ||
177 | //---------------------- | ||
178 | ob_start(); | ||
179 | extract( $this->var ); | ||
180 | include $this->tpl['compiled_filename']; | ||
181 | $raintpl_contents = ob_get_contents(); | ||
182 | ob_end_clean(); | ||
183 | //---------------------- | ||
184 | |||
185 | |||
186 | // save the output in the cache | ||
187 | if( $this->cache ) | ||
188 | file_put_contents( $this->tpl['cache_filename'], "<?php if(!class_exists('raintpl')){exit;}?>" . $raintpl_contents ); | ||
189 | |||
190 | // free memory | ||
191 | unset( $this->tpl ); | ||
192 | |||
193 | // return or print the template | ||
194 | if( $return_string ) return $raintpl_contents; else echo $raintpl_contents; | ||
195 | |||
196 | } | ||
197 | |||
198 | } | ||
199 | |||
200 | |||
201 | |||
202 | |||
203 | /** | ||
204 | * If exists a valid cache for this template it returns the cache | ||
205 | * | ||
206 | * @param string $tpl_name Name of template (set the same of draw) | ||
207 | * @param int $expiration_time Set after how many seconds the cache expire and must be regenerated | ||
208 | * @return string it return the HTML or null if the cache must be recreated | ||
209 | */ | ||
210 | |||
211 | function cache( $tpl_name, $expire_time = self::CACHE_EXPIRE_TIME, $cache_id = null ){ | ||
212 | |||
213 | // set the cache_id | ||
214 | $this->cache_id = $cache_id; | ||
215 | |||
216 | if( !$this->check_template( $tpl_name ) && file_exists( $this->tpl['cache_filename'] ) && ( time() - filemtime( $this->tpl['cache_filename'] ) < $expire_time ) ) | ||
217 | return substr( file_get_contents( $this->tpl['cache_filename'] ), 43 ); | ||
218 | else{ | ||
219 | //delete the cache of the selected template | ||
220 | if (file_exists($this->tpl['cache_filename'])) | ||
221 | unlink($this->tpl['cache_filename'] ); | ||
222 | $this->cache = true; | ||
223 | } | ||
224 | } | ||
225 | |||
226 | |||
227 | |||
228 | /** | ||
229 | * Configure the settings of RainTPL | ||
230 | * | ||
231 | */ | ||
232 | static function configure( $setting, $value = null ){ | ||
233 | if( is_array( $setting ) ) | ||
234 | foreach( $setting as $key => $value ) | ||
235 | self::configure( $key, $value ); | ||
236 | else if( property_exists( __CLASS__, $setting ) ){ | ||
237 | self::$$setting = $value; | ||
238 | self::$config_name_sum .= $value; // take trace of all config | ||
239 | } | ||
240 | } | ||
241 | |||
242 | |||
243 | |||
244 | // check if has to compile the template | ||
245 | // return true if the template has changed | ||
246 | private function check_template( $tpl_name ){ | ||
247 | |||
248 | if( !isset($this->tpl['checked']) ){ | ||
249 | |||
250 | $tpl_basename = basename( $tpl_name ); // template basename | ||
251 | $tpl_basedir = strpos($tpl_name,"/") ? dirname($tpl_name) . '/' : null; // template basedirectory | ||
252 | $tpl_dir = self::$tpl_dir . $tpl_basedir; // template directory | ||
253 | $this->tpl['tpl_filename'] = $tpl_dir . $tpl_basename . '.' . self::$tpl_ext; // template filename | ||
254 | $temp_compiled_filename = self::$cache_dir . $tpl_basename . "." . md5( $tpl_dir . self::$config_name_sum ); | ||
255 | $this->tpl['compiled_filename'] = $temp_compiled_filename . '.php'; // cache filename | ||
256 | $this->tpl['cache_filename'] = $temp_compiled_filename . '.s_' . $this->cache_id . '.php'; // static cache filename | ||
257 | |||
258 | // if the template doesn't exsist throw an error | ||
259 | if( self::$check_template_update && !file_exists( $this->tpl['tpl_filename'] ) ){ | ||
260 | $e = new RainTpl_NotFoundException( 'Template '. $tpl_basename .' not found!' ); | ||
261 | throw $e->setTemplateFile($this->tpl['tpl_filename']); | ||
262 | } | ||
263 | |||
264 | // file doesn't exsist, or the template was updated, Rain will compile the template | ||
265 | if( !file_exists( $this->tpl['compiled_filename'] ) || ( self::$check_template_update && filemtime($this->tpl['compiled_filename']) < filemtime( $this->tpl['tpl_filename'] ) ) ){ | ||
266 | $this->compileFile( $tpl_basename, $tpl_basedir, $this->tpl['tpl_filename'], self::$cache_dir, $this->tpl['compiled_filename'] ); | ||
267 | return true; | ||
268 | } | ||
269 | $this->tpl['checked'] = true; | ||
270 | } | ||
271 | } | ||
272 | |||
273 | |||
274 | /** | ||
275 | * execute stripslaches() on the xml block. Invoqued by preg_replace_callback function below | ||
276 | * @access private | ||
277 | */ | ||
278 | private function xml_reSubstitution($capture) { | ||
279 | return "<?php echo '<?xml ".stripslashes($capture[1])." ?>'; ?>"; | ||
280 | } | ||
281 | |||
282 | /** | ||
283 | * Compile and write the compiled template file | ||
284 | * @access private | ||
285 | */ | ||
286 | private function compileFile( $tpl_basename, $tpl_basedir, $tpl_filename, $cache_dir, $compiled_filename ){ | ||
287 | |||
288 | //read template file | ||
289 | $this->tpl['source'] = $template_code = file_get_contents( $tpl_filename ); | ||
290 | |||
291 | //xml substitution | ||
292 | $template_code = preg_replace( "/<\?xml(.*?)\?>/s", "##XML\\1XML##", $template_code ); | ||
293 | |||
294 | //disable php tag | ||
295 | $template_code = str_replace( array("<?","?>"), array("<?","?>"), $template_code ); | ||
296 | |||
297 | //xml re-substitution | ||
298 | $template_code = preg_replace_callback ( "/##XML(.*?)XML##/s", array($this, 'xml_reSubstitution'), $template_code ); | ||
299 | |||
300 | //compile template | ||
301 | $template_compiled = "<?php if(!class_exists('raintpl')){exit;}?>" . $this->compileTemplate( $template_code, $tpl_basedir ); | ||
302 | |||
303 | |||
304 | // fix the php-eating-newline-after-closing-tag-problem | ||
305 | $template_compiled = str_replace( "?>\n", "?>\n\n", $template_compiled ); | ||
306 | |||
307 | // create directories | ||
308 | if( !is_dir( $cache_dir ) ) | ||
309 | mkdir( $cache_dir, 0755, true ); | ||
310 | |||
311 | if( !is_writable( $cache_dir ) ) | ||
312 | throw new RainTpl_Exception ('Cache directory ' . $cache_dir . 'doesn\'t have write permission. Set write permission or set RAINTPL_CHECK_TEMPLATE_UPDATE to false. More details on http://www.raintpl.com/Documentation/Documentation-for-PHP-developers/Configuration/'); | ||
313 | |||
314 | //write compiled file | ||
315 | file_put_contents( $compiled_filename, $template_compiled ); | ||
316 | } | ||
317 | |||
318 | |||
319 | |||
320 | /** | ||
321 | * Compile template | ||
322 | * @access private | ||
323 | */ | ||
324 | private function compileTemplate( $template_code, $tpl_basedir ){ | ||
325 | |||
326 | //tag list | ||
327 | $tag_regexp = array( 'loop' => '(\{loop(?: name){0,1}="\${0,1}[^"]*"\})', | ||
328 | 'loop_close' => '(\{\/loop\})', | ||
329 | 'if' => '(\{if(?: condition){0,1}="[^"]*"\})', | ||
330 | 'elseif' => '(\{elseif(?: condition){0,1}="[^"]*"\})', | ||
331 | 'else' => '(\{else\})', | ||
332 | 'if_close' => '(\{\/if\})', | ||
333 | 'function' => '(\{function="[^"]*"\})', | ||
334 | 'noparse' => '(\{noparse\})', | ||
335 | 'noparse_close' => '(\{\/noparse\})', | ||
336 | 'ignore' => '(\{ignore\})', | ||
337 | 'ignore_close' => '(\{\/ignore\})', | ||
338 | 'include' => '(\{include="[^"]*"(?: cache="[^"]*")?\})', | ||
339 | 'template_info' => '(\{\$template_info\})', | ||
340 | ); | ||
341 | |||
342 | $tag_regexp = "/" . join( "|", $tag_regexp ) . "/"; | ||
343 | |||
344 | //split the code with the tags regexp | ||
345 | $template_code = preg_split ( $tag_regexp, $template_code, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); | ||
346 | |||
347 | //path replace (src of img, background and href of link) | ||
348 | $template_code = $this->path_replace( $template_code, $tpl_basedir ); | ||
349 | |||
350 | //compile the code | ||
351 | $compiled_code = $this->compileCode( $template_code ); | ||
352 | |||
353 | //return the compiled code | ||
354 | return $compiled_code; | ||
355 | |||
356 | } | ||
357 | |||
358 | |||
359 | |||
360 | /** | ||
361 | * Compile the code | ||
362 | * @access private | ||
363 | */ | ||
364 | private function compileCode( $parsed_code ){ | ||
365 | |||
366 | //variables initialization | ||
367 | $compiled_code = $open_if = $comment_is_open = $ignore_is_open = null; | ||
368 | $loop_level = 0; | ||
369 | |||
370 | |||
371 | //read all parsed code | ||
372 | while( $html = array_shift( $parsed_code ) ){ | ||
373 | |||
374 | //close ignore tag | ||
375 | if( !$comment_is_open && strpos( $html, '{/ignore}' ) !== FALSE ) | ||
376 | $ignore_is_open = false; | ||
377 | |||
378 | //code between tag ignore id deleted | ||
379 | elseif( $ignore_is_open ){ | ||
380 | //ignore the code | ||
381 | } | ||
382 | |||
383 | //close no parse tag | ||
384 | elseif( strpos( $html, '{/noparse}' ) !== FALSE ) | ||
385 | $comment_is_open = false; | ||
386 | |||
387 | //code between tag noparse is not compiled | ||
388 | elseif( $comment_is_open ) | ||
389 | $compiled_code .= $html; | ||
390 | |||
391 | //ignore | ||
392 | elseif( strpos( $html, '{ignore}' ) !== FALSE ) | ||
393 | $ignore_is_open = true; | ||
394 | |||
395 | //noparse | ||
396 | elseif( strpos( $html, '{noparse}' ) !== FALSE ) | ||
397 | $comment_is_open = true; | ||
398 | |||
399 | //include tag | ||
400 | elseif( preg_match( '/(?:\{include="([^"]*)"(?: cache="([^"]*)"){0,1}\})/', $html, $code ) ){ | ||
401 | |||
402 | //variables substitution | ||
403 | $include_var = $this->var_replace( $code[ 1 ], $left_delimiter = null, $right_delimiter = null, $php_left_delimiter = '".' , $php_right_delimiter = '."', $loop_level ); | ||
404 | |||
405 | // if the cache is active | ||
406 | if( isset($code[ 2 ]) ) | ||
407 | //dynamic include | ||
408 | $compiled_code .= '<?php $tpl = new RainTPL;' . | ||
409 | 'if( $cache = $tpl->cache( $template = basename("'.$include_var.'") ) )' . | ||
410 | ' echo $cache;' . | ||
411 | 'else{ ' . | ||
412 | '$tpl_dir_temp = self::$tpl_dir;' . | ||
413 | '$tpl->assign( $this->var );' . | ||
414 | ( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ). | ||
415 | '$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . $template );'. | ||
416 | '}' . | ||
417 | '?>'; | ||
418 | else | ||
419 | //dynamic include | ||
420 | $compiled_code .= '<?php $tpl = new RainTPL;' . | ||
421 | '$tpl_dir_temp = self::$tpl_dir;' . | ||
422 | '$tpl->assign( $this->var );' . | ||
423 | ( !$loop_level ? null : '$tpl->assign( "key", $key'.$loop_level.' ); $tpl->assign( "value", $value'.$loop_level.' );' ). | ||
424 | '$tpl->draw( dirname("'.$include_var.'") . ( substr("'.$include_var.'",-1,1) != "/" ? "/" : "" ) . basename("'.$include_var.'") );'. | ||
425 | '?>'; | ||
426 | |||
427 | } | ||
428 | |||
429 | //loop | ||
430 | elseif( preg_match( '/\{loop(?: name){0,1}="\${0,1}([^"]*)"\}/', $html, $code ) ){ | ||
431 | |||
432 | //increase the loop counter | ||
433 | $loop_level++; | ||
434 | |||
435 | //replace the variable in the loop | ||
436 | $var = $this->var_replace( '$' . $code[ 1 ], $tag_left_delimiter=null, $tag_right_delimiter=null, $php_left_delimiter=null, $php_right_delimiter=null, $loop_level-1 ); | ||
437 | |||
438 | //loop variables | ||
439 | $counter = "\$counter$loop_level"; // count iteration | ||
440 | $key = "\$key$loop_level"; // key | ||
441 | $value = "\$value$loop_level"; // value | ||
442 | |||
443 | //loop code | ||
444 | $compiled_code .= "<?php $counter=-1; if( isset($var) && is_array($var) && sizeof($var) ) foreach( $var as $key => $value ){ $counter++; ?>"; | ||
445 | |||
446 | } | ||
447 | |||
448 | //close loop tag | ||
449 | elseif( strpos( $html, '{/loop}' ) !== FALSE ) { | ||
450 | |||
451 | //iterator | ||
452 | $counter = "\$counter$loop_level"; | ||
453 | |||
454 | //decrease the loop counter | ||
455 | $loop_level--; | ||
456 | |||
457 | //close loop code | ||
458 | $compiled_code .= "<?php } ?>"; | ||
459 | |||
460 | } | ||
461 | |||
462 | //if | ||
463 | elseif( preg_match( '/\{if(?: condition){0,1}="([^"]*)"\}/', $html, $code ) ){ | ||
464 | |||
465 | //increase open if counter (for intendation) | ||
466 | $open_if++; | ||
467 | |||
468 | //tag | ||
469 | $tag = $code[ 0 ]; | ||
470 | |||
471 | //condition attribute | ||
472 | $condition = $code[ 1 ]; | ||
473 | |||
474 | // check if there's any function disabled by black_list | ||
475 | $this->function_check( $tag ); | ||
476 | |||
477 | //variable substitution into condition (no delimiter into the condition) | ||
478 | $parsed_condition = $this->var_replace( $condition, $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level ); | ||
479 | |||
480 | //if code | ||
481 | $compiled_code .= "<?php if( $parsed_condition ){ ?>"; | ||
482 | |||
483 | } | ||
484 | |||
485 | //elseif | ||
486 | elseif( preg_match( '/\{elseif(?: condition){0,1}="([^"]*)"\}/', $html, $code ) ){ | ||
487 | |||
488 | //tag | ||
489 | $tag = $code[ 0 ]; | ||
490 | |||
491 | //condition attribute | ||
492 | $condition = $code[ 1 ]; | ||
493 | |||
494 | //variable substitution into condition (no delimiter into the condition) | ||
495 | $parsed_condition = $this->var_replace( $condition, $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level ); | ||
496 | |||
497 | //elseif code | ||
498 | $compiled_code .= "<?php }elseif( $parsed_condition ){ ?>"; | ||
499 | } | ||
500 | |||
501 | //else | ||
502 | elseif( strpos( $html, '{else}' ) !== FALSE ) { | ||
503 | |||
504 | //else code | ||
505 | $compiled_code .= '<?php }else{ ?>'; | ||
506 | |||
507 | } | ||
508 | |||
509 | //close if tag | ||
510 | elseif( strpos( $html, '{/if}' ) !== FALSE ) { | ||
511 | |||
512 | //decrease if counter | ||
513 | $open_if--; | ||
514 | |||
515 | // close if code | ||
516 | $compiled_code .= '<?php } ?>'; | ||
517 | |||
518 | } | ||
519 | |||
520 | //function | ||
521 | elseif( preg_match( '/\{function="([^(]*)(\([^)]*\)){0,1}"\}/', $html, $code ) ){ | ||
522 | |||
523 | //tag | ||
524 | $tag = $code[ 0 ]; | ||
525 | |||
526 | //function | ||
527 | $function = $code[ 1 ]; | ||
528 | |||
529 | // check if there's any function disabled by black_list | ||
530 | $this->function_check( $tag ); | ||
531 | |||
532 | //parse the parameters | ||
533 | $parsed_param = isset( $code[2] ) ? $this->var_replace( $code[2], $tag_left_delimiter = null, $tag_right_delimiter = null, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level ) : '()'; | ||
534 | |||
535 | //if code | ||
536 | $compiled_code .= "<?php echo {$function}{$parsed_param}; ?>"; | ||
537 | } | ||
538 | |||
539 | // show all vars | ||
540 | elseif ( strpos( $html, '{$template_info}' ) !== FALSE ) { | ||
541 | |||
542 | //tag | ||
543 | $tag = '{$template_info}'; | ||
544 | |||
545 | //if code | ||
546 | $compiled_code .= '<?php echo "<pre>"; print_r( $this->var ); echo "</pre>"; ?>'; | ||
547 | } | ||
548 | |||
549 | |||
550 | //all html code | ||
551 | else{ | ||
552 | |||
553 | //variables substitution (es. {$title}) | ||
554 | $html = $this->var_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true ); | ||
555 | //const substitution (es. {#CONST#}) | ||
556 | $html = $this->const_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true ); | ||
557 | //functions substitution (es. {"string"|functions}) | ||
558 | $compiled_code .= $this->func_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php ', $php_right_delimiter = ';?>', $loop_level, $echo = true ); | ||
559 | } | ||
560 | } | ||
561 | |||
562 | if( $open_if > 0 ) { | ||
563 | $e = new RainTpl_SyntaxException('Error! You need to close an {if} tag in ' . $this->tpl['tpl_filename'] . ' template'); | ||
564 | throw $e->setTemplateFile($this->tpl['tpl_filename']); | ||
565 | } | ||
566 | return $compiled_code; | ||
567 | } | ||
568 | |||
569 | |||
570 | |||
571 | /** | ||
572 | * replace the path of image src, link href and a href. | ||
573 | * url => template_dir/url | ||
574 | * url# => url | ||
575 | * http://url => http://url | ||
576 | * | ||
577 | * @param string $html | ||
578 | * @return string html sostituito | ||
579 | */ | ||
580 | private function path_replace( $html, $tpl_basedir ){ | ||
581 | |||
582 | if( self::$path_replace ){ | ||
583 | |||
584 | // reduce the path | ||
585 | $path = preg_replace('/\w+\/\.\.\//', '', self::$base_url . self::$tpl_dir . $tpl_basedir ); | ||
586 | |||
587 | $exp = $sub = array(); | ||
588 | |||
589 | if( in_array( "img", self::$path_replace_list ) ){ | ||
590 | $exp = array( '/<img(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<img(.*?)src=(?:")([^"]+?)#(?:")/i', '/<img(.*?)src="(.*?)"/', '/<img(.*?)src=(?:\@)([^"]+?)(?:\@)/i' ); | ||
591 | $sub = array( '<img$1src=@$2://$3@', '<img$1src=@$2@', '<img$1src="' . self::$base_url . self::$tpl_dir . $tpl_basedir . '$2"', '<img$1src="$2"' ); | ||
592 | } | ||
593 | |||
594 | if( in_array( "script", self::$path_replace_list ) ){ | ||
595 | $exp = array_merge( $exp , array( '/<script(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<script(.*?)src=(?:")([^"]+?)#(?:")/i', '/<script(.*?)src="(.*?)"/', '/<script(.*?)src=(?:\@)([^"]+?)(?:\@)/i' ) ); | ||
596 | $sub = array_merge( $sub , array( '<script$1src=@$2://$3@', '<script$1src=@$2@', '<script$1src="' . self::$base_url . self::$tpl_dir . $tpl_basedir . '$2"', '<script$1src="$2"' ) ); | ||
597 | } | ||
598 | |||
599 | if( in_array( "link", self::$path_replace_list ) ){ | ||
600 | $exp = array_merge( $exp , array( '/<link(.*?)href=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<link(.*?)href=(?:")([^"]+?)#(?:")/i', '/<link(.*?)href="(.*?)"/', '/<link(.*?)href=(?:\@)([^"]+?)(?:\@)/i' ) ); | ||
601 | $sub = array_merge( $sub , array( '<link$1href=@$2://$3@', '<link$1href=@$2@' , '<link$1href="' . self::$base_url . self::$tpl_dir . $tpl_basedir . '$2"', '<link$1href="$2"' ) ); | ||
602 | } | ||
603 | |||
604 | if( in_array( "a", self::$path_replace_list ) ){ | ||
605 | $exp = array_merge( $exp , array( '/<a(.*?)href=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<a(.*?)href="(.*?)"/', '/<a(.*?)href=(?:\@)([^"]+?)(?:\@)/i' ) ); | ||
606 | $sub = array_merge( $sub , array( '<a$1href=@$2://$3@', '<a$1href="' . self::$base_url . '$2"', '<a$1href="$2"' ) ); | ||
607 | } | ||
608 | |||
609 | if( in_array( "input", self::$path_replace_list ) ){ | ||
610 | $exp = array_merge( $exp , array( '/<input(.*?)src=(?:")(http|https)\:\/\/([^"]+?)(?:")/i', '/<input(.*?)src=(?:")([^"]+?)#(?:")/i', '/<input(.*?)src="(.*?)"/', '/<input(.*?)src=(?:\@)([^"]+?)(?:\@)/i' ) ); | ||
611 | $sub = array_merge( $sub , array( '<input$1src=@$2://$3@', '<input$1src=@$2@', '<input$1src="' . self::$base_url . self::$tpl_dir . $tpl_basedir . '$2"', '<input$1src="$2"' ) ); | ||
612 | } | ||
613 | |||
614 | return preg_replace( $exp, $sub, $html ); | ||
615 | |||
616 | } | ||
617 | else | ||
618 | return $html; | ||
619 | |||
620 | } | ||
621 | |||
622 | |||
623 | |||
624 | |||
625 | |||
626 | // replace const | ||
627 | function const_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){ | ||
628 | // const | ||
629 | return preg_replace( '/\{\#(\w+)\#{0,1}\}/', $php_left_delimiter . ( $echo ? " echo " : null ) . '\\1' . $php_right_delimiter, $html ); | ||
630 | } | ||
631 | |||
632 | |||
633 | |||
634 | // replace functions/modifiers on constants and strings | ||
635 | function func_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){ | ||
636 | |||
637 | preg_match_all( '/' . '\{\#{0,1}(\"{0,1}.*?\"{0,1})(\|\w.*?)\#{0,1}\}' . '/', $html, $matches ); | ||
638 | |||
639 | for( $i=0, $n=count($matches[0]); $i<$n; $i++ ){ | ||
640 | |||
641 | //complete tag ex: {$news.title|substr:0,100} | ||
642 | $tag = $matches[ 0 ][ $i ]; | ||
643 | |||
644 | //variable name ex: news.title | ||
645 | $var = $matches[ 1 ][ $i ]; | ||
646 | |||
647 | //function and parameters associate to the variable ex: substr:0,100 | ||
648 | $extra_var = $matches[ 2 ][ $i ]; | ||
649 | |||
650 | // check if there's any function disabled by black_list | ||
651 | $this->function_check( $tag ); | ||
652 | |||
653 | $extra_var = $this->var_replace( $extra_var, null, null, null, null, $loop_level ); | ||
654 | |||
655 | |||
656 | // check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value | ||
657 | $is_init_variable = preg_match( "/^(\s*?)\=[^=](.*?)$/", $extra_var ); | ||
658 | |||
659 | //function associate to variable | ||
660 | $function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null; | ||
661 | |||
662 | //variable path split array (ex. $news.title o $news[title]) or object (ex. $news->title) | ||
663 | $temp = preg_split( "/\.|\[|\-\>/", $var ); | ||
664 | |||
665 | //variable name | ||
666 | $var_name = $temp[ 0 ]; | ||
667 | |||
668 | //variable path | ||
669 | $variable_path = substr( $var, strlen( $var_name ) ); | ||
670 | |||
671 | //parentesis transform [ e ] in [" e in "] | ||
672 | $variable_path = str_replace( '[', '["', $variable_path ); | ||
673 | $variable_path = str_replace( ']', '"]', $variable_path ); | ||
674 | |||
675 | //transform .$variable in ["$variable"] | ||
676 | $variable_path = preg_replace('/\.\$(\w+)/', '["$\\1"]', $variable_path ); | ||
677 | |||
678 | //transform [variable] in ["variable"] | ||
679 | $variable_path = preg_replace('/\.(\w+)/', '["\\1"]', $variable_path ); | ||
680 | |||
681 | //if there's a function | ||
682 | if( $function_var ){ | ||
683 | |||
684 | // check if there's a function or a static method and separate, function by parameters | ||
685 | $function_var = str_replace("::", "@double_dot@", $function_var ); | ||
686 | |||
687 | // get the position of the first : | ||
688 | if( $dot_position = strpos( $function_var, ":" ) ){ | ||
689 | |||
690 | // get the function and the parameters | ||
691 | $function = substr( $function_var, 0, $dot_position ); | ||
692 | $params = substr( $function_var, $dot_position+1 ); | ||
693 | |||
694 | } | ||
695 | else{ | ||
696 | |||
697 | //get the function | ||
698 | $function = str_replace( "@double_dot@", "::", $function_var ); | ||
699 | $params = null; | ||
700 | |||
701 | } | ||
702 | |||
703 | // replace back the @double_dot@ with :: | ||
704 | $function = str_replace( "@double_dot@", "::", $function ); | ||
705 | $params = str_replace( "@double_dot@", "::", $params ); | ||
706 | |||
707 | |||
708 | } | ||
709 | else | ||
710 | $function = $params = null; | ||
711 | |||
712 | $php_var = $var_name . $variable_path; | ||
713 | |||
714 | // compile the variable for php | ||
715 | if( isset( $function ) ){ | ||
716 | if( $php_var ) | ||
717 | $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter; | ||
718 | else | ||
719 | $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $params ) )" : "$function()" ) . $php_right_delimiter; | ||
720 | } | ||
721 | else | ||
722 | $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter; | ||
723 | |||
724 | $html = str_replace( $tag, $php_var, $html ); | ||
725 | |||
726 | } | ||
727 | |||
728 | return $html; | ||
729 | |||
730 | } | ||
731 | |||
732 | |||
733 | |||
734 | function var_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_level = null, $echo = null ){ | ||
735 | |||
736 | //all variables | ||
737 | if( preg_match_all( '/' . $tag_left_delimiter . '\$(\w+(?:\.\${0,1}[A-Za-z0-9_]+)*(?:(?:\[\${0,1}[A-Za-z0-9_]+\])|(?:\-\>\${0,1}[A-Za-z0-9_]+))*)(.*?)' . $tag_right_delimiter . '/', $html, $matches ) ){ | ||
738 | |||
739 | for( $parsed=array(), $i=0, $n=count($matches[0]); $i<$n; $i++ ) | ||
740 | $parsed[$matches[0][$i]] = array('var'=>$matches[1][$i],'extra_var'=>$matches[2][$i]); | ||
741 | |||
742 | foreach( $parsed as $tag => $array ){ | ||
743 | |||
744 | //variable name ex: news.title | ||
745 | $var = $array['var']; | ||
746 | |||
747 | //function and parameters associate to the variable ex: substr:0,100 | ||
748 | $extra_var = $array['extra_var']; | ||
749 | |||
750 | // check if there's any function disabled by black_list | ||
751 | $this->function_check( $tag ); | ||
752 | |||
753 | $extra_var = $this->var_replace( $extra_var, null, null, null, null, $loop_level ); | ||
754 | |||
755 | // check if there's an operator = in the variable tags, if there's this is an initialization so it will not output any value | ||
756 | $is_init_variable = preg_match( "/^(\s*?)\=[^=](.*?)$/", $extra_var ); | ||
757 | |||
758 | //function associate to variable | ||
759 | $function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null; | ||
760 | |||
761 | //variable path split array (ex. $news.title o $news[title]) or object (ex. $news->title) | ||
762 | $temp = preg_split( "/\.|\[|\-\>/", $var ); | ||
763 | |||
764 | //variable name | ||
765 | $var_name = $temp[ 0 ]; | ||
766 | |||
767 | //variable path | ||
768 | $variable_path = substr( $var, strlen( $var_name ) ); | ||
769 | |||
770 | //parentesis transform [ e ] in [" e in "] | ||
771 | $variable_path = str_replace( '[', '["', $variable_path ); | ||
772 | $variable_path = str_replace( ']', '"]', $variable_path ); | ||
773 | |||
774 | //transform .$variable in ["$variable"] and .variable in ["variable"] | ||
775 | $variable_path = preg_replace('/\.(\${0,1}\w+)/', '["\\1"]', $variable_path ); | ||
776 | |||
777 | // if is an assignment also assign the variable to $this->var['value'] | ||
778 | if( $is_init_variable ) | ||
779 | $extra_var = "=\$this->var['{$var_name}']{$variable_path}" . $extra_var; | ||
780 | |||
781 | |||
782 | |||
783 | //if there's a function | ||
784 | if( $function_var ){ | ||
785 | |||
786 | // check if there's a function or a static method and separate, function by parameters | ||
787 | $function_var = str_replace("::", "@double_dot@", $function_var ); | ||
788 | |||
789 | |||
790 | // get the position of the first : | ||
791 | if( $dot_position = strpos( $function_var, ":" ) ){ | ||
792 | |||
793 | // get the function and the parameters | ||
794 | $function = substr( $function_var, 0, $dot_position ); | ||
795 | $params = substr( $function_var, $dot_position+1 ); | ||
796 | |||
797 | } | ||
798 | else{ | ||
799 | |||
800 | //get the function | ||
801 | $function = str_replace( "@double_dot@", "::", $function_var ); | ||
802 | $params = null; | ||
803 | |||
804 | } | ||
805 | |||
806 | // replace back the @double_dot@ with :: | ||
807 | $function = str_replace( "@double_dot@", "::", $function ); | ||
808 | $params = str_replace( "@double_dot@", "::", $params ); | ||
809 | } | ||
810 | else | ||
811 | $function = $params = null; | ||
812 | |||
813 | //if it is inside a loop | ||
814 | if( $loop_level ){ | ||
815 | //verify the variable name | ||
816 | if( $var_name == 'key' ) | ||
817 | $php_var = '$key' . $loop_level; | ||
818 | elseif( $var_name == 'value' ) | ||
819 | $php_var = '$value' . $loop_level . $variable_path; | ||
820 | elseif( $var_name == 'counter' ) | ||
821 | $php_var = '$counter' . $loop_level; | ||
822 | else | ||
823 | $php_var = '$' . $var_name . $variable_path; | ||
824 | }else | ||
825 | $php_var = '$' . $var_name . $variable_path; | ||
826 | |||
827 | // compile the variable for php | ||
828 | if( isset( $function ) ) | ||
829 | $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . ( $params ? "( $function( $php_var, $params ) )" : "$function( $php_var )" ) . $php_right_delimiter; | ||
830 | else | ||
831 | $php_var = $php_left_delimiter . ( !$is_init_variable && $echo ? 'echo ' : null ) . $php_var . $extra_var . $php_right_delimiter; | ||
832 | |||
833 | $html = str_replace( $tag, $php_var, $html ); | ||
834 | |||
835 | |||
836 | } | ||
837 | } | ||
838 | |||
839 | return $html; | ||
840 | } | ||
841 | |||
842 | |||
843 | |||
844 | /** | ||
845 | * Check if function is in black list (sandbox) | ||
846 | * | ||
847 | * @param string $code | ||
848 | * @param string $tag | ||
849 | */ | ||
850 | private function function_check( $code ){ | ||
851 | |||
852 | $preg = '#(\W|\s)' . implode( '(\W|\s)|(\W|\s)', self::$black_list ) . '(\W|\s)#'; | ||
853 | |||
854 | // check if the function is in the black list (or not in white list) | ||
855 | if( count(self::$black_list) && preg_match( $preg, $code, $match ) ){ | ||
856 | |||
857 | // find the line of the error | ||
858 | $line = 0; | ||
859 | $rows=explode("\n",$this->tpl['source']); | ||
860 | while( !strpos($rows[$line],$code) ) | ||
861 | $line++; | ||
862 | |||
863 | // stop the execution of the script | ||
864 | $e = new RainTpl_SyntaxException('Unallowed syntax in ' . $this->tpl['tpl_filename'] . ' template'); | ||
865 | throw $e->setTemplateFile($this->tpl['tpl_filename']) | ||
866 | ->setTag($code) | ||
867 | ->setTemplateLine($line); | ||
868 | } | ||
869 | |||
870 | } | ||
871 | |||
872 | /** | ||
873 | * Prints debug info about exception or passes it further if debug is disabled. | ||
874 | * | ||
875 | * @param RainTpl_Exception $e | ||
876 | * @return string | ||
877 | */ | ||
878 | private function printDebug(RainTpl_Exception $e){ | ||
879 | if (!self::$debug) { | ||
880 | throw $e; | ||
881 | } | ||
882 | $output = sprintf('<h2>Exception: %s</h2><h3>%s</h3><p>template: %s</p>', | ||
883 | get_class($e), | ||
884 | $e->getMessage(), | ||
885 | $e->getTemplateFile() | ||
886 | ); | ||
887 | if ($e instanceof RainTpl_SyntaxException) { | ||
888 | if (null != $e->getTemplateLine()) { | ||
889 | $output .= '<p>line: ' . $e->getTemplateLine() . '</p>'; | ||
890 | } | ||
891 | if (null != $e->getTag()) { | ||
892 | $output .= '<p>in tag: ' . htmlspecialchars($e->getTag()) . '</p>'; | ||
893 | } | ||
894 | if (null != $e->getTemplateLine() && null != $e->getTag()) { | ||
895 | $rows=explode("\n", htmlspecialchars($this->tpl['source'])); | ||
896 | $rows[$e->getTemplateLine()] = '<font color=red>' . $rows[$e->getTemplateLine()] . '</font>'; | ||
897 | $output .= '<h3>template code</h3>' . implode('<br />', $rows) . '</pre>'; | ||
898 | } | ||
899 | } | ||
900 | $output .= sprintf('<h3>trace</h3><p>In %s on line %d</p><pre>%s</pre>', | ||
901 | $e->getFile(), $e->getLine(), | ||
902 | nl2br(htmlspecialchars($e->getTraceAsString())) | ||
903 | ); | ||
904 | return $output; | ||
905 | } | ||
906 | } | ||
907 | |||
908 | |||
909 | /** | ||
910 | * Basic Rain tpl exception. | ||
911 | */ | ||
912 | class RainTpl_Exception extends Exception{ | ||
913 | /** | ||
914 | * Path of template file with error. | ||
915 | */ | ||
916 | private $templateFile = ''; | ||
917 | |||
918 | /** | ||
919 | * Returns path of template file with error. | ||
920 | * | ||
921 | * @return string | ||
922 | */ | ||
923 | public function getTemplateFile() | ||
924 | { | ||
925 | return $this->templateFile; | ||
926 | } | ||
927 | |||
928 | /** | ||
929 | * Sets path of template file with error. | ||
930 | * | ||
931 | * @param string $templateFile | ||
932 | * @return RainTpl_Exception | ||
933 | */ | ||
934 | public function setTemplateFile($templateFile) | ||
935 | { | ||
936 | $this->templateFile = (string) $templateFile; | ||
937 | return $this; | ||
938 | } | ||
939 | } | ||
940 | |||
941 | /** | ||
942 | * Exception thrown when template file does not exists. | ||
943 | */ | ||
944 | class RainTpl_NotFoundException extends RainTpl_Exception{ | ||
945 | } | ||
946 | |||
947 | /** | ||
948 | * Exception thrown when syntax error occurs. | ||
949 | */ | ||
950 | class RainTpl_SyntaxException extends RainTpl_Exception{ | ||
951 | /** | ||
952 | * Line in template file where error has occured. | ||
953 | * | ||
954 | * @var int | null | ||
955 | */ | ||
956 | private $templateLine = null; | ||
957 | |||
958 | /** | ||
959 | * Tag which caused an error. | ||
960 | * | ||
961 | * @var string | null | ||
962 | */ | ||
963 | private $tag = null; | ||
964 | |||
965 | /** | ||
966 | * Returns line in template file where error has occured | ||
967 | * or null if line is not defined. | ||
968 | * | ||
969 | * @return int | null | ||
970 | */ | ||
971 | public function getTemplateLine() | ||
972 | { | ||
973 | return $this->templateLine; | ||
974 | } | ||
975 | |||
976 | /** | ||
977 | * Sets line in template file where error has occured. | ||
978 | * | ||
979 | * @param int $templateLine | ||
980 | * @return RainTpl_SyntaxException | ||
981 | */ | ||
982 | public function setTemplateLine($templateLine) | ||
983 | { | ||
984 | $this->templateLine = (int) $templateLine; | ||
985 | return $this; | ||
986 | } | ||
987 | |||
988 | /** | ||
989 | * Returns tag which caused an error. | ||
990 | * | ||
991 | * @return string | ||
992 | */ | ||
993 | public function getTag() | ||
994 | { | ||
995 | return $this->tag; | ||
996 | } | ||
997 | |||
998 | /** | ||
999 | * Sets tag which caused an error. | ||
1000 | * | ||
1001 | * @param string $tag | ||
1002 | * @return RainTpl_SyntaxException | ||
1003 | */ | ||
1004 | public function setTag($tag) | ||
1005 | { | ||
1006 | $this->tag = (string) $tag; | ||
1007 | return $this; | ||
1008 | } | ||
1009 | } | ||
1010 | |||
1011 | ?> \ No newline at end of file | ||
diff --git a/shaarli.css b/inc/shaarli.css index aba488a7..d0614e34 100644 --- a/shaarli.css +++ b/inc/shaarli.css | |||
@@ -7,9 +7,9 @@ version: 2.8.2r1 | |||
7 | */ | 7 | */ |
8 | 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%;} | 8 | 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%;} |
9 | 9 | ||
10 | body { font-family: "Trebuchet MS",Verdana,Arial,Helvetica,sans-serif; font-size:10pt; background-color: #ffffff; } | 10 | body { font-family: "Trebuchet MS",Verdana,Arial,Helvetica,sans-serif; font-size:10pt; background-color: #ffffff; } |
11 | input, textarea { | 11 | input, textarea { |
12 | 12 | ||
13 | background-color: #dedede; | 13 | background-color: #dedede; |
14 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#dedede), to(#ffffff)); | 14 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#dedede), to(#ffffff)); |
15 | background: -webkit-linear-gradient(#dedede, #ffffff); | 15 | background: -webkit-linear-gradient(#dedede, #ffffff); |
@@ -22,8 +22,8 @@ input, textarea { | |||
22 | border-radius: 5px 5px 5px 5px; | 22 | border-radius: 5px 5px 5px 5px; |
23 | border: none; | 23 | border: none; |
24 | color:#000; | 24 | color:#000; |
25 | 25 | ||
26 | } | 26 | } |
27 | 27 | ||
28 | h1 { font-size:20pt; font-weight:bold; font-style:italic; margin-bottom:20px; } | 28 | h1 { font-size:20pt; font-weight:bold; font-style:italic; margin-bottom:20px; } |
29 | /* I don't give a shit about IE. He can't understand selectors such as input[type='submit']. */ | 29 | /* I don't give a shit about IE. He can't understand selectors such as input[type='submit']. */ |
@@ -46,7 +46,7 @@ h1 { font-size:20pt; font-weight:bold; font-style:italic; margin-bottom:20px; } | |||
46 | border-style:outset; | 46 | border-style:outset; |
47 | border-width:1px; | 47 | border-width:1px; |
48 | 48 | ||
49 | } | 49 | } |
50 | .smallbutton { | 50 | .smallbutton { |
51 | background: -moz-linear-gradient(#c0c0c0, #ffffff) repeat scroll 0 0 transparent; | 51 | background: -moz-linear-gradient(#c0c0c0, #ffffff) repeat scroll 0 0 transparent; |
52 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#c0c0c0), to(#ffffff)); | 52 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#c0c0c0), to(#ffffff)); |
@@ -67,18 +67,19 @@ h1 { font-size:20pt; font-weight:bold; font-style:italic; margin-bottom:20px; } | |||
67 | } | 67 | } |
68 | 68 | ||
69 | /* Edit/Delete buttons on links */ | 69 | /* Edit/Delete buttons on links */ |
70 | .button_edit, .button_delete { border-radius:0; box-shadow:none; border-style:none; border-width:0; padding:0; background:none; } | 70 | .button_edit, .button_delete { border-radius:0; box-shadow:none; border-style:none; border-width:0; padding:0; background:none; } |
71 | .button_edit { margin-left:10px; } | 71 | .button_edit { margin-left:10px; } |
72 | 72 | ||
73 | 73 | ||
74 | #pageheader #logo{ | 74 | #pageheader #logo{ |
75 | background-image: url('./images/logo.png'); | 75 | background-image: url('../images/logo.png'); |
76 | background-repeat: no-repeat; | 76 | background-repeat: no-repeat; |
77 | float:left; | 77 | float:left; |
78 | margin:0 10px 0 10px; | 78 | margin:0 10px 0 10px; |
79 | width:105px; | 79 | width:105px; |
80 | height:55px; | 80 | height:55px; |
81 | cursor:pointer; | 81 | cursor:pointer; |
82 | |||
82 | } | 83 | } |
83 | 84 | ||
84 | #pageheader | 85 | #pageheader |
@@ -90,11 +91,11 @@ cursor:pointer; | |||
90 | background: -ms-linear-gradient(#333333, #111111); | 91 | background: -ms-linear-gradient(#333333, #111111); |
91 | background: -o-linear-gradient(#333333, #111111); | 92 | background: -o-linear-gradient(#333333, #111111); |
92 | background: linear-gradient(#333333, #111111); | 93 | background: linear-gradient(#333333, #111111); |
93 | 94 | ||
94 | box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); | 95 | box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); |
95 | padding:5px 0 5px 0; | 96 | width:auto; |
96 | width: 100%; | 97 | padding:0 10px 5px 10px; |
97 | margin: auto; | 98 | margin: auto; |
98 | } | 99 | } |
99 | 100 | ||
100 | #pageheader a | 101 | #pageheader a |
@@ -118,7 +119,7 @@ cursor:pointer; | |||
118 | clear:both; | 119 | clear:both; |
119 | } | 120 | } |
120 | #toolsdiv a span{ | 121 | #toolsdiv a span{ |
121 | color:#ffffff; | 122 | color:#ffffff; |
122 | } | 123 | } |
123 | .linksperpage,.tagfilter,.searchform,.addform { | 124 | .linksperpage,.tagfilter,.searchform,.addform { |
124 | background-color: #dedede; | 125 | background-color: #dedede; |
@@ -129,12 +130,12 @@ cursor:pointer; | |||
129 | background: -o-linear-gradient(#dedede, #ffffff); | 130 | background: -o-linear-gradient(#dedede, #ffffff); |
130 | background: linear-gradient(#dedede, #ffffff); | 131 | background: linear-gradient(#dedede, #ffffff); |
131 | display:inline; | 132 | display:inline; |
132 | 133 | ||
133 | box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); | 134 | box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); |
134 | padding:5px; | 135 | padding:5px; |
135 | border: none; | 136 | border: none; |
136 | border-radius: 5px 5px 5px 5px; | 137 | border-radius: 5px 5px 5px 5px; |
137 | margin:10px 3px 3px 3px; | 138 | margin:10px 3px 3px 3px; |
138 | color:#cecece; | 139 | color:#cecece; |
139 | } | 140 | } |
140 | 141 | ||
@@ -175,7 +176,7 @@ cursor:pointer; | |||
175 | 176 | ||
176 | #pageheader a:visited { color:#98C943; text-decoration:none;} | 177 | #pageheader a:visited { color:#98C943; text-decoration:none;} |
177 | #pageheader a:hover { color:#FFFFC9; text-decoration:none;} | 178 | #pageheader a:hover { color:#FFFFC9; text-decoration:none;} |
178 | #pageheader a:active { color:#bbb; text-decoration:none;} | 179 | #pageheader a:active { color:#bbb; text-decoration:none;} |
179 | #searchcriteria { padding: 4 0 5 5; font-weight:bold;} | 180 | #searchcriteria { padding: 4 0 5 5; font-weight:bold;} |
180 | .paging { padding:5px;background-color:#777; color:#ccc; text-align:center; clear:both;} | 181 | .paging { padding:5px;background-color:#777; color:#ccc; text-align:center; clear:both;} |
181 | .paging a:link { color:#ccc; text-decoration:none;} | 182 | .paging a:link { color:#ccc; text-decoration:none;} |
@@ -186,8 +187,8 @@ cursor:pointer; | |||
186 | #toolsdiv { color:#ffffff; padding:5 5 5 5; clear:left; } | 187 | #toolsdiv { color:#ffffff; padding:5 5 5 5; clear:left; } |
187 | #uploaddiv { color:#ffffff; padding:5 5 5 5; clear:left; } | 188 | #uploaddiv { color:#ffffff; padding:5 5 5 5; clear:left; } |
188 | #editlinkform { height:100%;color:#ffffff; padding:5 5 5 15px; width:80%; clear:left; } | 189 | #editlinkform { height:100%;color:#ffffff; padding:5 5 5 15px; width:80%; clear:left; } |
189 | #linklist li { | 190 | #linklist li { |
190 | padding:4 10 15 20; border-top: 1px solid #bbb; clear:both; | 191 | padding:4 10 15 20; border-top: 1px solid #bbb; clear:both; |
191 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#F2F2F2), to(#ffffff)); | 192 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#F2F2F2), to(#ffffff)); |
192 | background: -webkit-linear-gradient(#F2F2F2, #ffffff); | 193 | background: -webkit-linear-gradient(#F2F2F2, #ffffff); |
193 | background: -moz-linear-gradient(#F2F2F2, #ffffff); | 194 | background: -moz-linear-gradient(#F2F2F2, #ffffff); |
@@ -197,39 +198,39 @@ cursor:pointer; | |||
197 | } | 198 | } |
198 | 199 | ||
199 | 200 | ||
200 | #linklist li.publicLinkHightLight:hover,#linklist li:hover{ | 201 | #linklist li.publicLinkHightLight:hover,#linklist li:hover{ |
201 | background: #E9FFCE; | 202 | background: #E9FFCE; |
202 | } | 203 | } |
203 | #linklist li.private { background: url('./images/private.png') no-repeat 10px center; padding-left:60px; } | 204 | #linklist li.private { background: url('../images/private.png') no-repeat 10px center; padding-left:60px; } |
204 | .private .linktitle a {color:#969696;} | 205 | .private .linktitle a {color:#969696;} |
205 | .linktitle { font-size:14pt; font-weight:bold; } | 206 | .linktitle { font-size:14pt; font-weight:bold; } |
206 | .linktitle a { text-decoration: none; color:#80AD48; } | 207 | .linktitle a { text-decoration: none; color:#80AD48; } |
207 | .linktitle a:hover { color:#F57900; } | 208 | .linktitle a:hover { color:#F57900; } |
208 | .linkdate { font-size:8pt; color:#888; } | 209 | .linkdate { font-size:8pt; color:#888; } |
209 | .linkdate a { background-image:url('./images/calendar.png');padding:2px 0 3px 20px;background-repeat:no-repeat;text-decoration: none; color:#E28E3F; } | 210 | .linkdate a { background-image:url('../images/calendar.png');padding:2px 0 3px 20px;background-repeat:no-repeat;text-decoration: none; color:#E28E3F; } |
210 | .linkdate a:hover { color: #F57900 } | 211 | .linkdate a:hover { color: #F57900 } |
211 | .linkurl { font-size:8pt; color:#4BAA74; } | 212 | .linkurl { font-size:8pt; color:#4BAA74; } |
212 | .linkdescription { color:#000; margin-top:0; margin-bottom:0; font-weight:normal; } | 213 | .linkdescription { color:#000; margin-top:0; margin-bottom:12px; font-weight:normal; max-height:400px; overflow:auto; } |
213 | .linkdescription a { text-decoration: none; color:#3465A4; } | 214 | .linkdescription a { text-decoration: none; color:#3465A4; } |
214 | .linkdescription a:hover { color:#F57900; } | 215 | .linkdescription a:hover { color:#F57900; } |
215 | .linktaglist { padding-top:10px;} | 216 | .linktaglist { padding-top:10px;} |
216 | .linktag { | 217 | .linktag { |
217 | 218 | ||
218 | font-size:9pt; | 219 | font-size:9pt; |
219 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#F2F2F2), to(#ffffff)); | 220 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#F2F2F2), to(#ffffff)); |
220 | background: -webkit-linear-gradient(#F2F2F2, #ffffff); | 221 | background: -webkit-linear-gradient(#F2F2F2, #ffffff); |
221 | background: -moz-linear-gradient(#F2F2F2, #ffffff); | 222 | background: -moz-linear-gradient(#F2F2F2, #ffffff); |
222 | background: -ms-linear-gradient(#F2F2F2, #ffffff); | 223 | background: -ms-linear-gradient(#F2F2F2, #ffffff); |
223 | background: -o-linear-gradient(#F2F2F2, #ffffff); | 224 | background: -o-linear-gradient(#F2F2F2, #ffffff); |
224 | background: linear-gradient(#F2F2F2, #ffffff); | 225 | background: linear-gradient(#F2F2F2, #ffffff); |
225 | 226 | ||
226 | 227 | ||
227 | box-shadow: 0 0 2px rgba(0, 0, 0, 0.5); | 228 | box-shadow: 0 0 2px rgba(0, 0, 0, 0.5); |
228 | padding:3px 3px 3px 20px; | 229 | padding:3px 3px 3px 20px; |
229 | height:20px; | 230 | height:20px; |
230 | border-radius: 3px 3px 3px 3px; | 231 | border-radius: 3px 3px 3px 3px; |
231 | cursor:pointer; | 232 | cursor:pointer; |
232 | background-image:url('./images/tag_blue.png'); | 233 | background-image:url('../images/tag_blue.png'); |
233 | background-repeat:no-repeat; | 234 | background-repeat:no-repeat; |
234 | background-position:3px center; | 235 | background-position:3px center; |
235 | background-color:#ffffff; | 236 | background-color:#ffffff; |
@@ -243,7 +244,7 @@ font-size:9pt; | |||
243 | #footer { font-size:8pt; text-align:center; border-top:1px solid #ddd; color: #888; clear:both; } | 244 | #footer { font-size:8pt; text-align:center; border-top:1px solid #ddd; color: #888; clear:both; } |
244 | #footer a{ color:#486D08;} | 245 | #footer a{ color:#486D08;} |
245 | #footer a:hover{ color:#000000;} | 246 | #footer a:hover{ color:#000000;} |
246 | #newversion { background-color: #FFFFA0; color:#000; position:absolute; top:0;right:0; padding:2 7 2 7; font-size:9pt;} | 247 | #newversion { background-color: #FFFFA0; color:#000; position:absolute; top:0;right:0; padding:2 7 2 7; font-size:9pt;} |
247 | #cloudtag { padding-left:10%; padding-right:10%; } | 248 | #cloudtag { padding-left:10%; padding-right:10%; } |
248 | #cloudtag a { color:black; text-decoration:none; } | 249 | #cloudtag a { color:black; text-decoration:none; } |
249 | #installform td { font-size: 10pt; padding:10 5 10 5; clear:left; } | 250 | #installform td { font-size: 10pt; padding:10 5 10 5; clear:left; } |
@@ -261,8 +262,8 @@ font-size:9pt; | |||
261 | 262 | ||
262 | 263 | ||
263 | /* --- Picture wall CSS --- */ | 264 | /* --- Picture wall CSS --- */ |
264 | #picwall_container { color:#fff; background-color:#000; } | 265 | #picwall_container { color:#fff; background-color:#000; clear:both; } |
265 | .picwall_pictureframe { z-index:5; position:relative; display:table-cell; vertical-align:middle;width:90px; height:90px; overflow:hidden; text-align:center; float:left; } | 266 | .picwall_pictureframe { background-color:#000; z-index:5; position:relative; display:table-cell; vertical-align:middle;width:90px; height:90px; overflow:hidden; text-align:center; float:left; } |
266 | .picwall_pictureframe img { max-width: 100%;height: auto; } /* Adapt the width of the image */ | 267 | .picwall_pictureframe img { max-width: 100%;height: auto; } /* Adapt the width of the image */ |
267 | .picwall_pictureframe a {text-decoration:none;} | 268 | .picwall_pictureframe a {text-decoration:none;} |
268 | 269 | ||
@@ -311,4 +312,4 @@ a {color:#000!important;text-decoration:none!important;} | |||
311 | 312 | ||
312 | 313 | ||
313 | 314 | ||
314 | } \ No newline at end of file | 315 | } |
@@ -1,5 +1,5 @@ | |||
1 | <?php | 1 | <?php |
2 | // Shaarli 0.0.31 beta - Shaare your links... | 2 | // Shaarli 0.0.32 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 |
@@ -21,7 +21,7 @@ $GLOBALS['config']['ENABLE_THUMBNAILS'] = true; // Enable thumbnails in links. | |||
21 | $GLOBALS['config']['CACHEDIR'] = 'cache'; // Cache directory for thumbnails for SLOW services (like flickr) | 21 | $GLOBALS['config']['CACHEDIR'] = 'cache'; // Cache directory for thumbnails for SLOW services (like flickr) |
22 | $GLOBALS['config']['ENABLE_LOCALCACHE'] = true; // Enable Shaarli to store thumbnail in a local cache. Disable to reduce webspace usage. | 22 | $GLOBALS['config']['ENABLE_LOCALCACHE'] = true; // Enable Shaarli to store thumbnail in a local cache. Disable to reduce webspace usage. |
23 | $GLOBALS['config']['PUBSUBHUB_URL'] = ''; // PubSubHubbub support. Put an empty string to disable, or put your hub url here to enable. | 23 | $GLOBALS['config']['PUBSUBHUB_URL'] = ''; // PubSubHubbub support. Put an empty string to disable, or put your hub url here to enable. |
24 | // Note: You must have publisher.php in the same directory as Shaarli index.php | 24 | // Note: You must have publisher.php in the same directory as Shaarli index.php |
25 | // ----------------------------------------------------------------------------------------------- | 25 | // ----------------------------------------------------------------------------------------------- |
26 | // Program config (touch at your own risks !) | 26 | // Program config (touch at your own risks !) |
27 | $GLOBALS['config']['UPDATECHECK_FILENAME'] = $GLOBALS['config']['DATADIR'].'/lastupdatecheck.txt'; // For updates check of Shaarli. | 27 | $GLOBALS['config']['UPDATECHECK_FILENAME'] = $GLOBALS['config']['DATADIR'].'/lastupdatecheck.txt'; // For updates check of Shaarli. |
@@ -32,17 +32,21 @@ ini_set('post_max_size', '16M'); | |||
32 | ini_set('upload_max_filesize', '16M'); | 32 | ini_set('upload_max_filesize', '16M'); |
33 | define('PHPPREFIX','<?php /* '); // Prefix to encapsulate data in php code. | 33 | define('PHPPREFIX','<?php /* '); // Prefix to encapsulate data in php code. |
34 | define('PHPSUFFIX',' */ ?>'); // Suffix to encapsulate data in php code. | 34 | define('PHPSUFFIX',' */ ?>'); // Suffix to encapsulate data in php code. |
35 | $STARTTIME = microtime(true); // Measure page execution time. | ||
36 | checkphpversion(); | 35 | checkphpversion(); |
37 | error_reporting(E_ALL^E_WARNING); // See all error except warnings. | 36 | error_reporting(E_ALL^E_WARNING); // See all error except warnings. |
38 | //error_reporting(-1); // See all errors (for debugging only) | 37 | //error_reporting(-1); // See all errors (for debugging only) |
38 | |||
39 | include "inc/rain.tpl.class.php"; //include Rain TPL | ||
40 | raintpl::$tpl_dir = "tpl/"; // template directory | ||
41 | raintpl::$cache_dir = "tmp/"; // cache directory | ||
42 | |||
39 | ob_start(); | 43 | ob_start(); |
40 | 44 | ||
41 | // Optionnal config file. | 45 | // Optionnal config file. |
42 | if (is_file($GLOBALS['config']['DATADIR'].'/options.php')) require($GLOBALS['config']['DATADIR'].'/options.php'); | 46 | if (is_file($GLOBALS['config']['DATADIR'].'/options.php')) require($GLOBALS['config']['DATADIR'].'/options.php'); |
43 | 47 | ||
44 | // In case stupid admin has left magic_quotes enabled in php.ini: | 48 | // In case stupid admin has left magic_quotes enabled in php.ini: |
45 | if (get_magic_quotes_gpc()) | 49 | if (get_magic_quotes_gpc()) |
46 | { | 50 | { |
47 | function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } | 51 | function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } |
48 | $_POST = array_map('stripslashes_deep', $_POST); | 52 | $_POST = array_map('stripslashes_deep', $_POST); |
@@ -54,24 +58,24 @@ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); | |||
54 | header("Cache-Control: no-store, no-cache, must-revalidate"); | 58 | header("Cache-Control: no-store, no-cache, must-revalidate"); |
55 | header("Cache-Control: post-check=0, pre-check=0", false); | 59 | header("Cache-Control: post-check=0, pre-check=0", false); |
56 | header("Pragma: no-cache"); | 60 | header("Pragma: no-cache"); |
57 | define('shaarli_version','0.0.31 beta'); | 61 | define('shaarli_version','0.0.32 beta'); |
58 | if (!is_dir($GLOBALS['config']['DATADIR'])) { mkdir($GLOBALS['config']['DATADIR'],0705); chmod($GLOBALS['config']['DATADIR'],0705); } | 62 | if (!is_dir($GLOBALS['config']['DATADIR'])) { mkdir($GLOBALS['config']['DATADIR'],0705); chmod($GLOBALS['config']['DATADIR'],0705); } |
59 | if (!is_file($GLOBALS['config']['DATADIR'].'/.htaccess')) { file_put_contents($GLOBALS['config']['DATADIR'].'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. | 63 | if (!is_file($GLOBALS['config']['DATADIR'].'/.htaccess')) { file_put_contents($GLOBALS['config']['DATADIR'].'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. |
60 | if ($GLOBALS['config']['ENABLE_LOCALCACHE']) | 64 | if ($GLOBALS['config']['ENABLE_LOCALCACHE']) |
61 | { | 65 | { |
62 | if (!is_dir($GLOBALS['config']['CACHEDIR'])) { mkdir($GLOBALS['config']['CACHEDIR'],0705); chmod($GLOBALS['config']['CACHEDIR'],0705); } | 66 | if (!is_dir($GLOBALS['config']['CACHEDIR'])) { mkdir($GLOBALS['config']['CACHEDIR'],0705); chmod($GLOBALS['config']['CACHEDIR'],0705); } |
63 | if (!is_file($GLOBALS['config']['CACHEDIR'].'/.htaccess')) { file_put_contents($GLOBALS['config']['CACHEDIR'].'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. | 67 | if (!is_file($GLOBALS['config']['CACHEDIR'].'/.htaccess')) { file_put_contents($GLOBALS['config']['CACHEDIR'].'/.htaccess',"Allow from none\nDeny from all\n"); } // Protect data files. |
64 | } | 68 | } |
65 | if (!is_file($GLOBALS['config']['CONFIG_FILE'])) install(); | 69 | if (!is_file($GLOBALS['config']['CONFIG_FILE'])) install(); |
66 | require $GLOBALS['config']['CONFIG_FILE']; // Read login/password hash into $GLOBALS. | 70 | require $GLOBALS['config']['CONFIG_FILE']; // Read login/password hash into $GLOBALS. |
67 | // Small protection against dodgy config files: | 71 | // Small protection against dodgy config files: |
68 | if (empty($GLOBALS['title'])) $GLOBALS['title']='Shared links on '.htmlspecialchars(serverUrl().$_SERVER['SCRIPT_NAME']); | 72 | if (empty($GLOBALS['title'])) $GLOBALS['title']='Shared links on '.htmlspecialchars(indexUrl()); |
69 | if (empty($GLOBALS['timezone'])) $GLOBALS['timezone']=date_default_timezone_get(); | 73 | if (empty($GLOBALS['timezone'])) $GLOBALS['timezone']=date_default_timezone_get(); |
70 | autoLocale(); // Sniff browser language and set date format accordingly. | 74 | autoLocale(); // Sniff browser language and set date format accordingly. |
71 | header('Content-Type: text/html; charset=utf-8'); // We use UTF-8 for proper international characters handling. | 75 | header('Content-Type: text/html; charset=utf-8'); // We use UTF-8 for proper international characters handling. |
72 | $LINKSDB=false; | 76 | $LINKSDB=false; |
73 | 77 | ||
74 | // Check php version | 78 | // Check php version |
75 | function checkphpversion() | 79 | function checkphpversion() |
76 | { | 80 | { |
77 | if (version_compare(PHP_VERSION, '5.1.0') < 0) | 81 | if (version_compare(PHP_VERSION, '5.1.0') < 0) |
@@ -79,7 +83,7 @@ function checkphpversion() | |||
79 | header('Content-Type: text/plain; charset=utf-8'); | 83 | header('Content-Type: text/plain; charset=utf-8'); |
80 | echo 'Your server supports php '.PHP_VERSION.'. Shaarli requires at last php 5.1.0, and thus cannot run. Sorry.'; | 84 | echo 'Your server supports php '.PHP_VERSION.'. Shaarli requires at last php 5.1.0, and thus cannot run. Sorry.'; |
81 | exit; | 85 | exit; |
82 | } | 86 | } |
83 | } | 87 | } |
84 | 88 | ||
85 | // Checks if an update is available for Shaarli. | 89 | // Checks if an update is available for Shaarli. |
@@ -89,14 +93,14 @@ function checkphpversion() | |||
89 | function checkUpdate() | 93 | function checkUpdate() |
90 | { | 94 | { |
91 | if (!isLoggedIn()) return ''; // Do not check versions for visitors. | 95 | if (!isLoggedIn()) return ''; // Do not check versions for visitors. |
92 | 96 | ||
93 | // Get latest version number at most once a day. | 97 | // Get latest version number at most once a day. |
94 | if (!is_file($GLOBALS['config']['UPDATECHECK_FILENAME']) || (filemtime($GLOBALS['config']['UPDATECHECK_FILENAME'])<time()-($GLOBALS['config']['UPDATECHECK_INTERVAL']))) | 98 | if (!is_file($GLOBALS['config']['UPDATECHECK_FILENAME']) || (filemtime($GLOBALS['config']['UPDATECHECK_FILENAME'])<time()-($GLOBALS['config']['UPDATECHECK_INTERVAL']))) |
95 | { | 99 | { |
96 | $version=shaarli_version; | 100 | $version=shaarli_version; |
97 | list($httpstatus,$headers,$data) = getHTTP('http://sebsauvage.net/files/shaarli_version.txt',2); | 101 | list($httpstatus,$headers,$data) = getHTTP('http://sebsauvage.net/files/shaarli_version.txt',2); |
98 | if (strpos($httpstatus,'200 OK')!==false) $version=$data; | 102 | if (strpos($httpstatus,'200 OK')!==false) $version=$data; |
99 | // If failed, nevermind. We don't want to bother the user with that. | 103 | // If failed, nevermind. We don't want to bother the user with that. |
100 | file_put_contents($GLOBALS['config']['UPDATECHECK_FILENAME'],$version); // touch file date | 104 | file_put_contents($GLOBALS['config']['UPDATECHECK_FILENAME'],$version); // touch file date |
101 | } | 105 | } |
102 | // Compare versions: | 106 | // Compare versions: |
@@ -121,7 +125,7 @@ function logm($message) | |||
121 | - only use the following characters: a-z A-Z 0-9 - _ @ | 125 | - only use the following characters: a-z A-Z 0-9 - _ @ |
122 | - are NOT cryptographically secure (they CAN be forged) | 126 | - are NOT cryptographically secure (they CAN be forged) |
123 | In Shaarli, they are used as a tinyurl-like link to individual entries. | 127 | In Shaarli, they are used as a tinyurl-like link to individual entries. |
124 | */ | 128 | */ |
125 | function smallHash($text) | 129 | function smallHash($text) |
126 | { | 130 | { |
127 | $t = rtrim(base64_encode(hash('crc32',$text,true)),'='); | 131 | $t = rtrim(base64_encode(hash('crc32',$text,true)),'='); |
@@ -137,11 +141,19 @@ function text2clickable($url) | |||
137 | $redir = empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector']; | 141 | $redir = empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector']; |
138 | return preg_replace('!((?:https?|ftp)://\S+[[:alnum:]]/?)!si','<a href="'.$redir.'$1" rel="nofollow">$1</a>',$url); | 142 | return preg_replace('!((?:https?|ftp)://\S+[[:alnum:]]/?)!si','<a href="'.$redir.'$1" rel="nofollow">$1</a>',$url); |
139 | } | 143 | } |
144 | |||
145 | // This function inserts where relevant so that multiple spaces are properly displayed in HTML | ||
146 | // even in the absence of <pre> (This is used in description to keep text formatting) | ||
147 | function keepMultipleSpaces($text) | ||
148 | { | ||
149 | return str_replace(' ',' ',$text); | ||
150 | |||
151 | } | ||
140 | // ------------------------------------------------------------------------------------------ | 152 | // ------------------------------------------------------------------------------------------ |
141 | // Sniff browser language to display dates in the right format automatically. | 153 | // Sniff browser language to display dates in the right format automatically. |
142 | // (Note that is may not work on your server if the corresponding local is not installed.) | 154 | // (Note that is may not work on your server if the corresponding local is not installed.) |
143 | function autoLocale() | 155 | function autoLocale() |
144 | { | 156 | { |
145 | $loc='en_US'; // Default if browser does not send HTTP_ACCEPT_LANGUAGE | 157 | $loc='en_US'; // Default if browser does not send HTTP_ACCEPT_LANGUAGE |
146 | if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // eg. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3" | 158 | if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // eg. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3" |
147 | { // (It's a bit crude, but it works very well. Prefered language is always presented first.) | 159 | { // (It's a bit crude, but it works very well. Prefered language is always presented first.) |
@@ -160,8 +172,8 @@ function pubsubhub() | |||
160 | { | 172 | { |
161 | $p = new Publisher($GLOBALS['config']['PUBSUBHUB_URL']); | 173 | $p = new Publisher($GLOBALS['config']['PUBSUBHUB_URL']); |
162 | $topic_url = array ( | 174 | $topic_url = array ( |
163 | serverUrl().$_SERVER['SCRIPT_NAME'].'?do=atom', | 175 | indexUrl().'?do=atom', |
164 | serverUrl().$_SERVER['SCRIPT_NAME'].'?do=rss' | 176 | indexUrl().'?do=rss' |
165 | ); | 177 | ); |
166 | $p->publish_update($topic_url); | 178 | $p->publish_update($topic_url); |
167 | } | 179 | } |
@@ -187,7 +199,7 @@ function allIPs() | |||
187 | } | 199 | } |
188 | 200 | ||
189 | // Check that user/password is correct. | 201 | // Check that user/password is correct. |
190 | function check_auth($login,$password) | 202 | function check_auth($login,$password) |
191 | { | 203 | { |
192 | $hash = sha1($password.$login.$GLOBALS['salt']); | 204 | $hash = sha1($password.$login.$GLOBALS['salt']); |
193 | if ($login==$GLOBALS['login'] && $hash==$GLOBALS['hash']) | 205 | if ($login==$GLOBALS['login'] && $hash==$GLOBALS['hash']) |
@@ -205,9 +217,9 @@ function check_auth($login,$password) | |||
205 | 217 | ||
206 | // Returns true if the user is logged in. | 218 | // Returns true if the user is logged in. |
207 | function isLoggedIn() | 219 | function isLoggedIn() |
208 | { | 220 | { |
209 | if ($GLOBALS['config']['OPEN_SHAARLI']) return true; | 221 | if ($GLOBALS['config']['OPEN_SHAARLI']) return true; |
210 | 222 | ||
211 | // If session does not exist on server side, or IP address has changed, or session has expired, logout. | 223 | // If session does not exist on server side, or IP address has changed, or session has expired, logout. |
212 | if (empty($_SESSION['uid']) || $_SESSION['ip']!=allIPs() || time()>=$_SESSION['expires_on']) | 224 | if (empty($_SESSION['uid']) || $_SESSION['ip']!=allIPs() || time()>=$_SESSION['expires_on']) |
213 | { | 225 | { |
@@ -216,7 +228,7 @@ function isLoggedIn() | |||
216 | } | 228 | } |
217 | if (!empty($_SESSION['longlastingsession'])) $_SESSION['expires_on']=time()+$_SESSION['longlastingsession']; // In case of "Stay signed in" checked. | 229 | if (!empty($_SESSION['longlastingsession'])) $_SESSION['expires_on']=time()+$_SESSION['longlastingsession']; // In case of "Stay signed in" checked. |
218 | else $_SESSION['expires_on']=time()+INACTIVITY_TIMEOUT; // Standard session expiration date. | 230 | else $_SESSION['expires_on']=time()+INACTIVITY_TIMEOUT; // Standard session expiration date. |
219 | 231 | ||
220 | return true; | 232 | return true; |
221 | } | 233 | } |
222 | 234 | ||
@@ -260,7 +272,7 @@ function ban_canLogin() | |||
260 | if (isset($gb['BANS'][$ip])) | 272 | if (isset($gb['BANS'][$ip])) |
261 | { | 273 | { |
262 | // User is banned. Check if the ban has expired: | 274 | // User is banned. Check if the ban has expired: |
263 | if ($gb['BANS'][$ip]<=time()) | 275 | if ($gb['BANS'][$ip]<=time()) |
264 | { // Ban expired, user can try to login again. | 276 | { // Ban expired, user can try to login again. |
265 | logm('Ban lifted.'); | 277 | logm('Ban lifted.'); |
266 | unset($gb['FAILURES'][$ip]); unset($gb['BANS'][$ip]); | 278 | unset($gb['FAILURES'][$ip]); unset($gb['BANS'][$ip]); |
@@ -279,36 +291,36 @@ if (isset($_POST['login'])) | |||
279 | if (!ban_canLogin()) die('I said: NO. You are banned for the moment. Go away.'); | 291 | if (!ban_canLogin()) die('I said: NO. You are banned for the moment. Go away.'); |
280 | if (isset($_POST['password']) && tokenOk($_POST['token']) && (check_auth($_POST['login'], $_POST['password']))) | 292 | if (isset($_POST['password']) && tokenOk($_POST['token']) && (check_auth($_POST['login'], $_POST['password']))) |
281 | { // Login/password is ok. | 293 | { // Login/password is ok. |
282 | ban_loginOk(); | 294 | ban_loginOk(); |
283 | // If user wants to keep the session cookie even after the browser closes: | 295 | // If user wants to keep the session cookie even after the browser closes: |
284 | if (!empty($_POST['longlastingsession'])) | 296 | if (!empty($_POST['longlastingsession'])) |
285 | { | 297 | { |
286 | $_SESSION['longlastingsession']=31536000; // (31536000 seconds = 1 year) | 298 | $_SESSION['longlastingsession']=31536000; // (31536000 seconds = 1 year) |
287 | $_SESSION['expires_on']=time()+$_SESSION['longlastingsession']; // Set session expiration on server-side. | 299 | $_SESSION['expires_on']=time()+$_SESSION['longlastingsession']; // Set session expiration on server-side. |
288 | session_set_cookie_params($_SESSION['longlastingsession']); // Set session cookie expiration on client side | 300 | session_set_cookie_params($_SESSION['longlastingsession']); // Set session cookie expiration on client side |
289 | session_regenerate_id(true); // Send cookie with new expiration date to browser. | 301 | session_regenerate_id(true); // Send cookie with new expiration date to browser. |
290 | } | 302 | } |
291 | else // Standard session expiration (=when browser closes) | 303 | else // Standard session expiration (=when browser closes) |
292 | { | 304 | { |
293 | session_set_cookie_params(0); // 0 means "When browser closes" | 305 | session_set_cookie_params(0); // 0 means "When browser closes" |
294 | session_regenerate_id(true); | 306 | session_regenerate_id(true); |
295 | } | 307 | } |
296 | // Optional redirect after login: | 308 | // Optional redirect after login: |
297 | if (isset($_GET['post'])) { header('Location: ?post='.urlencode($_GET['post']).(!empty($_GET['title'])?'&title='.urlencode($_GET['title']):'').(!empty($_GET['source'])?'&source='.urlencode($_GET['source']):'')); exit; } | 309 | if (isset($_GET['post'])) { header('Location: ?post='.urlencode($_GET['post']).(!empty($_GET['title'])?'&title='.urlencode($_GET['title']):'').(!empty($_GET['source'])?'&source='.urlencode($_GET['source']):'')); exit; } |
298 | if (isset($_POST['returnurl'])) | 310 | if (isset($_POST['returnurl'])) |
299 | { | 311 | { |
300 | if (endsWith($_POST['returnurl'],'?do=login')) { header('Location: ?'); exit; } // Prevent loops over login screen. | 312 | if (endsWith($_POST['returnurl'],'?do=login')) { header('Location: ?'); exit; } // Prevent loops over login screen. |
301 | header('Location: '.$_POST['returnurl']); exit; | 313 | header('Location: '.$_POST['returnurl']); exit; |
302 | } | 314 | } |
303 | header('Location: ?'); exit; | 315 | header('Location: ?'); exit; |
304 | } | 316 | } |
305 | else | 317 | else |
306 | { | 318 | { |
307 | ban_loginFailed(); | 319 | ban_loginFailed(); |
308 | echo '<script language="JavaScript">alert("Wrong login/password.");document.location=\'?do=login\';</script>'; // Redirect to login screen. | 320 | echo '<script language="JavaScript">alert("Wrong login/password.");document.location=\'?do=login\';</script>'; // Redirect to login screen. |
309 | exit; | 321 | exit; |
310 | } | 322 | } |
311 | } | 323 | } |
312 | 324 | ||
313 | // ------------------------------------------------------------------------------------------ | 325 | // ------------------------------------------------------------------------------------------ |
314 | // Misc utility functions: | 326 | // Misc utility functions: |
@@ -318,15 +330,20 @@ if (isset($_POST['login'])) | |||
318 | // You can append $_SERVER['SCRIPT_NAME'] to get the current script URL. | 330 | // You can append $_SERVER['SCRIPT_NAME'] to get the current script URL. |
319 | function serverUrl() | 331 | function serverUrl() |
320 | { | 332 | { |
321 | $serverport = ($_SERVER["SERVER_PORT"]!='80' ? ':'.$_SERVER["SERVER_PORT"] : ''); | 333 | $serverport = ($_SERVER["SERVER_PORT"]=='80' || (!empty($_SERVER['HTTPS']) && $_SERVER["SERVER_PORT"]=='443') ? '' : ':'.$_SERVER["SERVER_PORT"]); |
322 | return 'http'.(!empty($_SERVER['HTTPS'])?'s':'').'://'.$_SERVER["SERVER_NAME"].$serverport; | 334 | return 'http'.(!empty($_SERVER['HTTPS'])?'s':'').'://'.$_SERVER["SERVER_NAME"].$serverport; |
323 | } | 335 | } |
324 | 336 | ||
337 | function indexUrl() | ||
338 | { | ||
339 | return serverUrl() . ($_SERVER["SCRIPT_NAME"] == '/index.php' ? '' : $_SERVER["SCRIPT_NAME"]); | ||
340 | } | ||
341 | |||
325 | // Convert post_max_size/upload_max_filesize (eg.'16M') parameters to bytes. | 342 | // Convert post_max_size/upload_max_filesize (eg.'16M') parameters to bytes. |
326 | function return_bytes($val) | 343 | function return_bytes($val) |
327 | { | 344 | { |
328 | $val = trim($val); $last=strtolower($val[strlen($val)-1]); | 345 | $val = trim($val); $last=strtolower($val[strlen($val)-1]); |
329 | switch($last) | 346 | switch($last) |
330 | { | 347 | { |
331 | case 'g': $val *= 1024; | 348 | case 'g': $val *= 1024; |
332 | case 'm': $val *= 1024; | 349 | case 'm': $val *= 1024; |
@@ -396,7 +413,7 @@ function linkdate2locale($linkdate) | |||
396 | } | 413 | } |
397 | 414 | ||
398 | // Parse HTTP response headers and return an associative array. | 415 | // Parse HTTP response headers and return an associative array. |
399 | function http_parse_headers_shaarli( $headers ) | 416 | function http_parse_headers_shaarli( $headers ) |
400 | { | 417 | { |
401 | $res=array(); | 418 | $res=array(); |
402 | foreach($headers as $header) | 419 | foreach($headers as $header) |
@@ -444,9 +461,9 @@ function getHTTP($url,$timeout=30) | |||
444 | 461 | ||
445 | // Extract title from an HTML document. | 462 | // Extract title from an HTML document. |
446 | // (Returns an empty string if not found.) | 463 | // (Returns an empty string if not found.) |
447 | function html_extract_title($html) | 464 | function html_extract_title($html) |
448 | { | 465 | { |
449 | return preg_match('!<title>(.*?)</title>!is', $html, $matches) ? trim(str_replace("\n",' ', $matches[1])) : '' ; | 466 | return preg_match('!<title>(.*?)</title>!is', $html, $matches) ? trim(str_replace("\n",' ', $matches[1])) : '' ; |
450 | } | 467 | } |
451 | 468 | ||
452 | // ------------------------------------------------------------------------------------------ | 469 | // ------------------------------------------------------------------------------------------ |
@@ -459,11 +476,11 @@ function getToken() | |||
459 | { | 476 | { |
460 | $rnd = sha1(uniqid('',true).'_'.mt_rand()); // We generate a random string. | 477 | $rnd = sha1(uniqid('',true).'_'.mt_rand()); // We generate a random string. |
461 | $_SESSION['tokens'][$rnd]=1; // Store it on the server side. | 478 | $_SESSION['tokens'][$rnd]=1; // Store it on the server side. |
462 | return $rnd; | 479 | return $rnd; |
463 | } | 480 | } |
464 | 481 | ||
465 | // Tells if a token is ok. Using this function will destroy the token. | 482 | // Tells if a token is ok. Using this function will destroy the token. |
466 | // true=token is ok. | 483 | // true=token is ok. |
467 | function tokenOk($token) | 484 | function tokenOk($token) |
468 | { | 485 | { |
469 | if (isset($_SESSION['tokens'][$token])) | 486 | if (isset($_SESSION['tokens'][$token])) |
@@ -475,6 +492,58 @@ function tokenOk($token) | |||
475 | } | 492 | } |
476 | 493 | ||
477 | // ------------------------------------------------------------------------------------------ | 494 | // ------------------------------------------------------------------------------------------ |
495 | /* This class is in charge of building the final page. | ||
496 | (This is basically a wrapper around RainTPL which pre-fills some fields.) | ||
497 | p = new pageBuilder; | ||
498 | p.assign('myfield','myvalue'); | ||
499 | p.renderPage('mytemplate'); | ||
500 | |||
501 | */ | ||
502 | class pageBuilder | ||
503 | { | ||
504 | private $tpl; // RainTPL template | ||
505 | function __construct() | ||
506 | { | ||
507 | $this->tpl=false; | ||
508 | } | ||
509 | |||
510 | private function initialize() | ||
511 | { | ||
512 | global $LINKSDB; | ||
513 | $this->tpl = new RainTPL; | ||
514 | $this->tpl->assign('newversion',checkUpdate()); | ||
515 | $this->tpl->assign('linkcount',count($LINKSDB)); | ||
516 | $this->tpl->assign('feedurl',htmlspecialchars(indexUrl())); | ||
517 | $searchcrits=''; // Search criteria | ||
518 | if (!empty($_GET['searchtags'])) $searchcrits.='&searchtags='.$_GET['searchtags']; | ||
519 | elseif (!empty($_GET['searchterm'])) $searchcrits.='&searchterm='.$_GET['searchterm']; | ||
520 | $this->tpl->assign('searchcrits',$searchcrits); | ||
521 | $this->tpl->assign('source',indexUrl()); | ||
522 | $this->tpl->assign('version',shaarli_version); | ||
523 | $this->tpl->assign('pagetitle','Shaarli'); | ||
524 | if (!empty($GLOBALS['title'])) $this->tpl->assign('pagetitle',$GLOBALS['title']); | ||
525 | if (!empty($GLOBALS['pagetitle'])) $this->tpl->assign('pagetitle',$GLOBALS['pagetitle']); | ||
526 | $this->tpl->assign('shaarlititle',empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title'] ); | ||
527 | return; | ||
528 | } | ||
529 | |||
530 | // The following assign() method is basically the same as RainTPL (except that it's lazy) | ||
531 | public function assign($what,$where) | ||
532 | { | ||
533 | if ($this->tpl===false) $this->initialize(); // Lazy initialization | ||
534 | $this->tpl->assign($what,$where); | ||
535 | } | ||
536 | |||
537 | // Render a specific page (using a template). | ||
538 | // eg. pb.renderPage('picwall') | ||
539 | public function renderPage($page) | ||
540 | { | ||
541 | if ($this->tpl===false) $this->initialize(); // Lazy initialization | ||
542 | $this->tpl->draw($page); | ||
543 | } | ||
544 | } | ||
545 | |||
546 | // ------------------------------------------------------------------------------------------ | ||
478 | /* Data storage for links. | 547 | /* Data storage for links. |
479 | This object behaves like an associative array. | 548 | This object behaves like an associative array. |
480 | Example: | 549 | Example: |
@@ -482,14 +551,13 @@ function tokenOk($token) | |||
482 | echo $mylinks['20110826_161819']['title']; | 551 | echo $mylinks['20110826_161819']['title']; |
483 | foreach($mylinks as $link) | 552 | foreach($mylinks as $link) |
484 | echo $link['title'].' at url '.$link['url'].' ; description:'.$link['description']; | 553 | echo $link['title'].' at url '.$link['url'].' ; description:'.$link['description']; |
485 | 554 | ||
486 | We implement 3 interfaces: | 555 | We implement 3 interfaces: |
487 | - ArrayAccess so that this object behaves like an associative array. | 556 | - ArrayAccess so that this object behaves like an associative array. |
488 | - Iterator so that this object can be used in foreach() loops. | 557 | - Iterator so that this object can be used in foreach() loops. |
489 | - Countable interface so that we can do a count() on this object. | 558 | - Countable interface so that we can do a count() on this object. |
490 | */ | 559 | */ |
491 | class linkdb implements Iterator, Countable, ArrayAccess | 560 | class linkdb implements Iterator, Countable, ArrayAccess |
492 | |||
493 | { | 561 | { |
494 | private $links; // List of links (associative array. Key=linkdate (eg. "20110823_124546"), value= associative array (keys:title,description...) | 562 | private $links; // List of links (associative array. Key=linkdate (eg. "20110823_124546"), value= associative array (keys:title,description...) |
495 | private $urls; // List of all recorded URLs (key=url, value=linkdate) for fast reserve search (url-->linkdate) | 563 | private $urls; // List of all recorded URLs (key=url, value=linkdate) for fast reserve search (url-->linkdate) |
@@ -504,8 +572,8 @@ class linkdb implements Iterator, Countable, ArrayAccess | |||
504 | $this->loggedin = $isLoggedIn; | 572 | $this->loggedin = $isLoggedIn; |
505 | $this->checkdb(); // Make sure data file exists. | 573 | $this->checkdb(); // Make sure data file exists. |
506 | $this->readdb(); // Then read it. | 574 | $this->readdb(); // Then read it. |
507 | } | 575 | } |
508 | 576 | ||
509 | // ---- Countable interface implementation | 577 | // ---- Countable interface implementation |
510 | public function count() { return count($this->links); } | 578 | public function count() { return count($this->links); } |
511 | 579 | ||
@@ -516,17 +584,17 @@ class linkdb implements Iterator, Countable, ArrayAccess | |||
516 | if (empty($value['linkdate']) || empty($value['url'])) die('Internal Error: A link should always have a linkdate and url.'); | 584 | if (empty($value['linkdate']) || empty($value['url'])) die('Internal Error: A link should always have a linkdate and url.'); |
517 | if (empty($offset)) die('You must specify a key.'); | 585 | if (empty($offset)) die('You must specify a key.'); |
518 | $this->links[$offset] = $value; | 586 | $this->links[$offset] = $value; |
519 | $this->urls[$value['url']]=$offset; | 587 | $this->urls[$value['url']]=$offset; |
520 | } | 588 | } |
521 | public function offsetExists($offset) { return array_key_exists($offset,$this->links); } | 589 | public function offsetExists($offset) { return array_key_exists($offset,$this->links); } |
522 | public function offsetUnset($offset) | 590 | public function offsetUnset($offset) |
523 | { | 591 | { |
524 | if (!$this->loggedin) die('You are not authorized to delete a link.'); | 592 | if (!$this->loggedin) die('You are not authorized to delete a link.'); |
525 | $url = $this->links[$offset]['url']; unset($this->urls[$url]); | 593 | $url = $this->links[$offset]['url']; unset($this->urls[$url]); |
526 | unset($this->links[$offset]); | 594 | unset($this->links[$offset]); |
527 | } | 595 | } |
528 | public function offsetGet($offset) { return isset($this->links[$offset]) ? $this->links[$offset] : null; } | 596 | public function offsetGet($offset) { return isset($this->links[$offset]) ? $this->links[$offset] : null; } |
529 | 597 | ||
530 | // ---- Iterator interface implementation | 598 | // ---- Iterator interface implementation |
531 | function rewind() { $this->keys=array_keys($this->links); rsort($this->keys); $this->position=0; } // Start over for iteration, ordered by date (latest first). | 599 | function rewind() { $this->keys=array_keys($this->links); rsort($this->keys); $this->position=0; } // Start over for iteration, ordered by date (latest first). |
532 | function key() { return $this->keys[$this->position]; } // current key | 600 | function key() { return $this->keys[$this->position]; } // current key |
@@ -543,18 +611,18 @@ class linkdb implements Iterator, Countable, ArrayAccess | |||
543 | $link = array('title'=>'Shaarli - sebsauvage.net','url'=>'http://sebsauvage.net/wiki/doku.php?id=php:shaarli','description'=>'Welcome to Shaarli ! This is a bookmark. To edit or delete me, you must first login.','private'=>0,'linkdate'=>'20110914_190000','tags'=>'opensource software'); | 611 | $link = array('title'=>'Shaarli - sebsauvage.net','url'=>'http://sebsauvage.net/wiki/doku.php?id=php:shaarli','description'=>'Welcome to Shaarli ! This is a bookmark. To edit or delete me, you must first login.','private'=>0,'linkdate'=>'20110914_190000','tags'=>'opensource software'); |
544 | $this->links[$link['linkdate']] = $link; | 612 | $this->links[$link['linkdate']] = $link; |
545 | $link = array('title'=>'My secret stuff... - Pastebin.com','url'=>'http://pastebin.com/smCEEeSn','description'=>'SShhhh!! I\'m a private link only YOU can see. You can delete me too.','private'=>1,'linkdate'=>'20110914_074522','tags'=>'secretstuff'); | 613 | $link = array('title'=>'My secret stuff... - Pastebin.com','url'=>'http://pastebin.com/smCEEeSn','description'=>'SShhhh!! I\'m a private link only YOU can see. You can delete me too.','private'=>1,'linkdate'=>'20110914_074522','tags'=>'secretstuff'); |
546 | $this->links[$link['linkdate']] = $link; | 614 | $this->links[$link['linkdate']] = $link; |
547 | file_put_contents($GLOBALS['config']['DATASTORE'], PHPPREFIX.base64_encode(gzdeflate(serialize($this->links))).PHPSUFFIX); // Write database to disk | 615 | file_put_contents($GLOBALS['config']['DATASTORE'], PHPPREFIX.base64_encode(gzdeflate(serialize($this->links))).PHPSUFFIX); // Write database to disk |
548 | } | 616 | } |
549 | } | 617 | } |
550 | 618 | ||
551 | // Read database from disk to memory | 619 | // Read database from disk to memory |
552 | private function readdb() | 620 | private function readdb() |
553 | { | 621 | { |
554 | // Read data | 622 | // Read data |
555 | $this->links=(file_exists($GLOBALS['config']['DATASTORE']) ? unserialize(gzinflate(base64_decode(substr(file_get_contents($GLOBALS['config']['DATASTORE']),strlen(PHPPREFIX),-strlen(PHPSUFFIX))))) : array() ); | 623 | $this->links=(file_exists($GLOBALS['config']['DATASTORE']) ? unserialize(gzinflate(base64_decode(substr(file_get_contents($GLOBALS['config']['DATASTORE']),strlen(PHPPREFIX),-strlen(PHPSUFFIX))))) : array() ); |
556 | // Note that gzinflate is faster than gzuncompress. See: http://www.php.net/manual/en/function.gzdeflate.php#96439 | 624 | // Note that gzinflate is faster than gzuncompress. See: http://www.php.net/manual/en/function.gzdeflate.php#96439 |
557 | 625 | ||
558 | // If user is not logged in, filter private links. | 626 | // If user is not logged in, filter private links. |
559 | if (!$this->loggedin) | 627 | if (!$this->loggedin) |
560 | { | 628 | { |
@@ -562,21 +630,21 @@ class linkdb implements Iterator, Countable, ArrayAccess | |||
562 | foreach($this->links as $link) { if ($link['private']!=0) $toremove[]=$link['linkdate']; } | 630 | foreach($this->links as $link) { if ($link['private']!=0) $toremove[]=$link['linkdate']; } |
563 | foreach($toremove as $linkdate) { unset($this->links[$linkdate]); } | 631 | foreach($toremove as $linkdate) { unset($this->links[$linkdate]); } |
564 | } | 632 | } |
565 | 633 | ||
566 | // Keep the list of the mapping URLs-->linkdate up-to-date. | 634 | // Keep the list of the mapping URLs-->linkdate up-to-date. |
567 | $this->urls=array(); | 635 | $this->urls=array(); |
568 | foreach($this->links as $link) { $this->urls[$link['url']]=$link['linkdate']; } | 636 | foreach($this->links as $link) { $this->urls[$link['url']]=$link['linkdate']; } |
569 | } | 637 | } |
570 | 638 | ||
571 | // Save database from memory to disk. | 639 | // Save database from memory to disk. |
572 | public function savedb() | 640 | public function savedb() |
573 | { | 641 | { |
574 | if (!$this->loggedin) die('You are not authorized to change the database.'); | 642 | if (!$this->loggedin) die('You are not authorized to change the database.'); |
575 | file_put_contents($GLOBALS['config']['DATASTORE'], PHPPREFIX.base64_encode(gzdeflate(serialize($this->links))).PHPSUFFIX); | 643 | file_put_contents($GLOBALS['config']['DATASTORE'], PHPPREFIX.base64_encode(gzdeflate(serialize($this->links))).PHPSUFFIX); |
576 | } | 644 | } |
577 | 645 | ||
578 | // Returns the link for a given URL (if it exists). false it does not exist. | 646 | // Returns the link for a given URL (if it exists). false it does not exist. |
579 | public function getLinkFromUrl($url) | 647 | public function getLinkFromUrl($url) |
580 | { | 648 | { |
581 | if (isset($this->urls[$url])) return $this->links[$this->urls[$url]]; | 649 | if (isset($this->urls[$url])) return $this->links[$this->urls[$url]]; |
582 | return false; | 650 | return false; |
@@ -584,14 +652,14 @@ class linkdb implements Iterator, Countable, ArrayAccess | |||
584 | 652 | ||
585 | // Case insentitive search among links (in url, title and description). Returns filtered list of links. | 653 | // Case insentitive search among links (in url, title and description). Returns filtered list of links. |
586 | // eg. print_r($mydb->filterFulltext('hollandais')); | 654 | // eg. print_r($mydb->filterFulltext('hollandais')); |
587 | public function filterFulltext($searchterms) | 655 | public function filterFulltext($searchterms) |
588 | { | 656 | { |
589 | // FIXME: explode(' ',$searchterms) and perform a AND search. | 657 | // FIXME: explode(' ',$searchterms) and perform a AND search. |
590 | // FIXME: accept double-quotes to search for a string "as is" ? | 658 | // FIXME: accept double-quotes to search for a string "as is" ? |
591 | $filtered=array(); | 659 | $filtered=array(); |
592 | $s = strtolower($searchterms); | 660 | $s = strtolower($searchterms); |
593 | foreach($this->links as $l) | 661 | foreach($this->links as $l) |
594 | { | 662 | { |
595 | $found= (strpos(strtolower($l['title']),$s)!==false) | 663 | $found= (strpos(strtolower($l['title']),$s)!==false) |
596 | || (strpos(strtolower($l['description']),$s)!==false) | 664 | || (strpos(strtolower($l['description']),$s)!==false) |
597 | || (strpos(strtolower($l['url']),$s)!==false) | 665 | || (strpos(strtolower($l['url']),$s)!==false) |
@@ -601,7 +669,7 @@ class linkdb implements Iterator, Countable, ArrayAccess | |||
601 | krsort($filtered); | 669 | krsort($filtered); |
602 | return $filtered; | 670 | return $filtered; |
603 | } | 671 | } |
604 | 672 | ||
605 | // Filter by tag. | 673 | // Filter by tag. |
606 | // You can specify one or more tags (tags can be separated by space or comma). | 674 | // You can specify one or more tags (tags can be separated by space or comma). |
607 | // eg. print_r($mydb->filterTags('linux programming')); | 675 | // eg. print_r($mydb->filterTags('linux programming')); |
@@ -611,22 +679,22 @@ class linkdb implements Iterator, Countable, ArrayAccess | |||
611 | $searchtags=explode(' ',$t); | 679 | $searchtags=explode(' ',$t); |
612 | $filtered=array(); | 680 | $filtered=array(); |
613 | foreach($this->links as $l) | 681 | foreach($this->links as $l) |
614 | { | 682 | { |
615 | $linktags = explode(' ',($casesensitive?$l['tags']:strtolower($l['tags']))); | 683 | $linktags = explode(' ',($casesensitive?$l['tags']:strtolower($l['tags']))); |
616 | if (count(array_intersect($linktags,$searchtags)) == count($searchtags)) | 684 | if (count(array_intersect($linktags,$searchtags)) == count($searchtags)) |
617 | $filtered[$l['linkdate']] = $l; | 685 | $filtered[$l['linkdate']] = $l; |
618 | } | 686 | } |
619 | krsort($filtered); | 687 | krsort($filtered); |
620 | return $filtered; | 688 | return $filtered; |
621 | } | 689 | } |
622 | 690 | ||
623 | // Filter by smallHash. | 691 | // Filter by smallHash. |
624 | // Only 1 article is returned. | 692 | // Only 1 article is returned. |
625 | public function filterSmallHash($smallHash) | 693 | public function filterSmallHash($smallHash) |
626 | { | 694 | { |
627 | $filtered=array(); | 695 | $filtered=array(); |
628 | foreach($this->links as $l) | 696 | foreach($this->links as $l) |
629 | { | 697 | { |
630 | if ($smallHash==smallHash($l['linkdate'])) // Yes, this is ugly and slow | 698 | if ($smallHash==smallHash($l['linkdate'])) // Yes, this is ugly and slow |
631 | { | 699 | { |
632 | $filtered[$l['linkdate']] = $l; | 700 | $filtered[$l['linkdate']] = $l; |
@@ -634,7 +702,7 @@ class linkdb implements Iterator, Countable, ArrayAccess | |||
634 | } | 702 | } |
635 | } | 703 | } |
636 | return $filtered; | 704 | return $filtered; |
637 | } | 705 | } |
638 | 706 | ||
639 | // Returns the list of all tags | 707 | // Returns the list of all tags |
640 | // Output: associative array key=tags, value=0 | 708 | // Output: associative array key=tags, value=0 |
@@ -646,7 +714,7 @@ class linkdb implements Iterator, Countable, ArrayAccess | |||
646 | if (!empty($tag)) $tags[$tag]=(empty($tags[$tag]) ? 1 : $tags[$tag]+1); | 714 | if (!empty($tag)) $tags[$tag]=(empty($tags[$tag]) ? 1 : $tags[$tag]+1); |
647 | arsort($tags); // Sort tags by usage (most used tag first) | 715 | arsort($tags); // Sort tags by usage (most used tag first) |
648 | return $tags; | 716 | return $tags; |
649 | } | 717 | } |
650 | } | 718 | } |
651 | 719 | ||
652 | // ------------------------------------------------------------------------------------------ | 720 | // ------------------------------------------------------------------------------------------ |
@@ -654,15 +722,15 @@ class linkdb implements Iterator, Countable, ArrayAccess | |||
654 | function showRSS() | 722 | function showRSS() |
655 | { | 723 | { |
656 | global $LINKSDB; | 724 | global $LINKSDB; |
657 | 725 | ||
658 | // Optionnaly filter the results: | 726 | // Optionnaly filter the results: |
659 | $linksToDisplay=array(); | 727 | $linksToDisplay=array(); |
660 | if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']); | 728 | if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']); |
661 | elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); | 729 | elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); |
662 | else $linksToDisplay = $LINKSDB; | 730 | else $linksToDisplay = $LINKSDB; |
663 | 731 | ||
664 | header('Content-Type: application/rss+xml; charset=utf-8'); | 732 | header('Content-Type: application/rss+xml; charset=utf-8'); |
665 | $pageaddr=htmlspecialchars(serverUrl().$_SERVER["SCRIPT_NAME"]); | 733 | $pageaddr=htmlspecialchars(indexUrl()); |
666 | echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">'; | 734 | echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">'; |
667 | echo '<channel><title>'.htmlspecialchars($GLOBALS['title']).'</title><link>'.$pageaddr.'</link>'; | 735 | echo '<channel><title>'.htmlspecialchars($GLOBALS['title']).'</title><link>'.$pageaddr.'</link>'; |
668 | echo '<description>Shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n\n"; | 736 | echo '<description>Shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n\n"; |
@@ -678,16 +746,17 @@ function showRSS() | |||
678 | while ($i<50 && $i<count($keys)) | 746 | while ($i<50 && $i<count($keys)) |
679 | { | 747 | { |
680 | $link = $linksToDisplay[$keys[$i]]; | 748 | $link = $linksToDisplay[$keys[$i]]; |
749 | $guid = $pageaddr.'?'.smallHash($link['linkdate']); | ||
681 | $rfc822date = linkdate2rfc822($link['linkdate']); | 750 | $rfc822date = linkdate2rfc822($link['linkdate']); |
682 | $absurl = htmlspecialchars($link['url']); | 751 | $absurl = htmlspecialchars($link['url']); |
683 | if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute | 752 | if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute |
684 | echo '<item><title>'.htmlspecialchars($link['title']).'</title><guid>'.$absurl.'</guid><link>'.$absurl.'</link>'; | 753 | echo '<item><title>'.htmlspecialchars($link['title']).'</title><guid>'.$guid.'</guid><link>'.$absurl.'</link>'; |
685 | if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) echo '<pubDate>'.htmlspecialchars($rfc822date)."</pubDate>\n"; | 754 | if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) echo '<pubDate>'.htmlspecialchars($rfc822date)."</pubDate>\n"; |
686 | if ($link['tags']!='') // Adding tags to each RSS entry (as mentioned in RSS specification) | 755 | if ($link['tags']!='') // Adding tags to each RSS entry (as mentioned in RSS specification) |
687 | { | 756 | { |
688 | foreach(explode(' ',$link['tags']) as $tag) { echo '<category domain="'.htmlspecialchars($pageaddr).'">'.htmlspecialchars($tag).'</category>'."\n"; } | 757 | foreach(explode(' ',$link['tags']) as $tag) { echo '<category domain="'.htmlspecialchars($pageaddr).'">'.htmlspecialchars($tag).'</category>'."\n"; } |
689 | } | 758 | } |
690 | echo '<description><![CDATA['.nl2br(text2clickable(htmlspecialchars($link['description']))).']]></description>'."\n</item>\n"; | 759 | echo '<description><![CDATA['.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))).']]></description>'."\n</item>\n"; |
691 | $i++; | 760 | $i++; |
692 | } | 761 | } |
693 | echo '</channel></rss>'; | 762 | echo '</channel></rss>'; |
@@ -699,15 +768,15 @@ function showRSS() | |||
699 | function showATOM() | 768 | function showATOM() |
700 | { | 769 | { |
701 | global $LINKSDB; | 770 | global $LINKSDB; |
702 | 771 | ||
703 | // Optionnaly filter the results: | 772 | // Optionnaly filter the results: |
704 | $linksToDisplay=array(); | 773 | $linksToDisplay=array(); |
705 | if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']); | 774 | if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']); |
706 | elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); | 775 | elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); |
707 | else $linksToDisplay = $LINKSDB; | 776 | else $linksToDisplay = $LINKSDB; |
708 | 777 | ||
709 | header('Content-Type: application/atom+xml; charset=utf-8'); | 778 | header('Content-Type: application/atom+xml; charset=utf-8'); |
710 | $pageaddr=htmlspecialchars(serverUrl().$_SERVER["SCRIPT_NAME"]); | 779 | $pageaddr=htmlspecialchars(indexUrl()); |
711 | $latestDate = ''; | 780 | $latestDate = ''; |
712 | $entries=''; | 781 | $entries=''; |
713 | $i=0; | 782 | $i=0; |
@@ -715,19 +784,20 @@ function showATOM() | |||
715 | while ($i<50 && $i<count($keys)) | 784 | while ($i<50 && $i<count($keys)) |
716 | { | 785 | { |
717 | $link = $linksToDisplay[$keys[$i]]; | 786 | $link = $linksToDisplay[$keys[$i]]; |
787 | $guid = $pageaddr.'?'.smallHash($link['linkdate']); | ||
718 | $iso8601date = linkdate2iso8601($link['linkdate']); | 788 | $iso8601date = linkdate2iso8601($link['linkdate']); |
719 | $latestDate = max($latestDate,$iso8601date); | 789 | $latestDate = max($latestDate,$iso8601date); |
720 | $absurl = htmlspecialchars($link['url']); | 790 | $absurl = htmlspecialchars($link['url']); |
721 | if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute | 791 | if (startsWith($absurl,'?')) $absurl=$pageaddr.$absurl; // make permalink URL absolute |
722 | $entries.='<entry><title>'.htmlspecialchars($link['title']).'</title><link href="'.$absurl.'" /><id>'.$absurl.'</id>'; | 792 | $entries.='<entry><title>'.htmlspecialchars($link['title']).'</title><link href="'.$absurl.'" /><id>'.$guid.'</id>'; |
723 | if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) $entries.='<updated>'.htmlspecialchars($iso8601date).'</updated>'; | 793 | if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) $entries.='<updated>'.htmlspecialchars($iso8601date).'</updated>'; |
724 | $entries.='<summary>'.nl2br(text2clickable(htmlspecialchars($link['description'])))."</summary>\n"; | 794 | $entries.='<summary>'.nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))."</summary>\n"; |
725 | if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification) | 795 | if ($link['tags']!='') // Adding tags to each ATOM entry (as mentioned in ATOM specification) |
726 | { | 796 | { |
727 | foreach(explode(' ',$link['tags']) as $tag) | 797 | foreach(explode(' ',$link['tags']) as $tag) |
728 | { $entries.='<category scheme="'.htmlspecialchars($pageaddr,ENT_QUOTES).'" term="'.htmlspecialchars($tag,ENT_QUOTES).'" />'."\n"; } | 798 | { $entries.='<category scheme="'.htmlspecialchars($pageaddr,ENT_QUOTES).'" term="'.htmlspecialchars($tag,ENT_QUOTES).'" />'."\n"; } |
729 | } | 799 | } |
730 | $entries.="</entry>\n"; | 800 | $entries.="</entry>\n"; |
731 | $i++; | 801 | $i++; |
732 | } | 802 | } |
733 | $feed='<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">'; | 803 | $feed='<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">'; |
@@ -749,92 +819,79 @@ function showATOM() | |||
749 | } | 819 | } |
750 | 820 | ||
751 | // ------------------------------------------------------------------------------------------ | 821 | // ------------------------------------------------------------------------------------------ |
752 | // Render HTML page: | 822 | // Render HTML page (according to URL parameters and user rights) |
753 | function renderPage() | 823 | function renderPage() |
754 | { | 824 | { |
755 | global $STARTTIME; | ||
756 | global $LINKSDB; | 825 | global $LINKSDB; |
757 | 826 | ||
758 | // Well... rendering the page would be 100x better with the excellent Smarty, but I don't want to tie this minimalist project to 100+ files. | ||
759 | // So I use a custom templating system. | ||
760 | |||
761 | // -------- Display login form. | 827 | // -------- Display login form. |
762 | if (startswith($_SERVER["QUERY_STRING"],'do=login')) | 828 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=login')) |
763 | { | 829 | { |
764 | if ($GLOBALS['config']['OPEN_SHAARLI']) { header('Location: ?'); exit; } // No need to login for open Shaarli | 830 | if ($GLOBALS['config']['OPEN_SHAARLI']) { header('Location: ?'); exit; } // No need to login for open Shaarli |
765 | if (!ban_canLogin()) | 831 | $token=''; if (ban_canLogin()) $token=getToken(); // Do not waste token generation if not useful. |
766 | { | 832 | $PAGE = new pageBuilder; |
767 | $loginform='<div id="headerform">You have been banned from login after too many failed attempts. Try later.</div>'; | 833 | $PAGE->assign('token',$token); |
768 | $data = array('pageheader'=>$loginform,'body'=>'','onload'=>''); | 834 | $PAGE->assign('returnurl',(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER']:'')); |
769 | templatePage($data); | 835 | $PAGE->renderPage('loginform'); |
770 | exit; | ||
771 | } | ||
772 | $returnurl_html = (isset($_SERVER['HTTP_REFERER']) ? '<input type="hidden" name="returnurl" value="'.htmlspecialchars($_SERVER['HTTP_REFERER']).'">' : ''); | ||
773 | $loginform='<div id="headerform"><form method="post" name="loginform">Login: <input type="text" name="login"> Password : <input type="password" name="password"> <input type="submit" value="Login" class="bigbutton"><br>'; | ||
774 | $loginform.='<input style="margin:10 0 0 40;" type="checkbox" name="longlastingsession" id="longlastingsession"><label for="longlastingsession"> Stay signed in (Do not check on public computers)</label><input type="hidden" name="token" value="'.getToken().'">'.$returnurl_html.'</form></div>'; | ||
775 | $onload = 'onload="document.loginform.login.focus();"'; | ||
776 | $data = array('pageheader'=>$loginform,'body'=>'','onload'=>$onload); | ||
777 | templatePage($data); | ||
778 | exit; | 836 | exit; |
779 | } | 837 | } |
780 | // -------- User wants to logout. | 838 | // -------- User wants to logout. |
781 | if (startswith($_SERVER["QUERY_STRING"],'do=logout')) | 839 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=logout')) |
782 | { | 840 | { |
783 | invalidateCaches(); | 841 | invalidateCaches(); |
784 | logout(); | 842 | logout(); |
785 | header('Location: ?'); | 843 | header('Location: ?'); |
786 | exit; | 844 | exit; |
787 | } | 845 | } |
788 | 846 | ||
789 | // -------- Picture wall | 847 | // -------- Picture wall |
790 | if (startswith($_SERVER["QUERY_STRING"],'do=picwall')) | 848 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=picwall')) |
791 | { | 849 | { |
792 | // Optionnaly filter the results: | 850 | // Optionnaly filter the results: |
793 | $linksToDisplay=array(); | 851 | $links=array(); |
794 | if (!empty($_GET['searchterm'])) $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']); | 852 | if (!empty($_GET['searchterm'])) $links = $LINKSDB->filterFulltext($_GET['searchterm']); |
795 | elseif (!empty($_GET['searchtags'])) $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); | 853 | elseif (!empty($_GET['searchtags'])) $links = $LINKSDB->filterTags(trim($_GET['searchtags'])); |
796 | else $linksToDisplay = $LINKSDB; | 854 | else $links = $LINKSDB; |
797 | $body=''; | 855 | $body=''; |
798 | 856 | $linksToDisplay=array(); | |
799 | foreach($linksToDisplay as $link) | 857 | |
858 | // Get only links which have a thumbnail. | ||
859 | foreach($links as $link) | ||
800 | { | 860 | { |
801 | $href='?'.htmlspecialchars(smallhash($link['linkdate']),ENT_QUOTES); | 861 | $permalink='?'.htmlspecialchars(smallhash($link['linkdate']),ENT_QUOTES); |
802 | $thumb=thumbnail($link['url'],$href); | 862 | $thumb=thumbnail($link['url'],$permalink); |
803 | if ($thumb!='') | 863 | if ($thumb!='') // Only output links which have a thumbnail. |
804 | { | 864 | { |
805 | $body.='<div class="picwall_pictureframe">'.$thumb.'<a href="'.$href.'"><span class="info">'.htmlspecialchars($link['title']).'</span></a></div>'; | 865 | $link['thumbnail']=$thumb; // Thumbnail HTML code. |
806 | 866 | $link['permalink']=$permalink; | |
867 | $linksToDisplay[]=$link; // Add to array. | ||
807 | } | 868 | } |
808 | } | 869 | } |
809 | $body = '<center><div id="picwall_container">'.$body.'<hr style="width:0;height:0;clear:both;"></div></center>'; | 870 | $PAGE = new pageBuilder; |
810 | $data = array('pageheader'=>'<br> ','body'=>$body,'onload'=>''); | 871 | $PAGE->assign('linksToDisplay',$linksToDisplay); |
811 | templatePage($data); | 872 | $PAGE->renderPage('picwall'); |
812 | exit; | 873 | exit; |
813 | 874 | } | |
814 | } | ||
815 | 875 | ||
816 | // -------- Tag cloud | 876 | // -------- Tag cloud |
817 | if (startswith($_SERVER["QUERY_STRING"],'do=tagcloud')) | 877 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=tagcloud')) |
818 | { | 878 | { |
819 | $tags= $LINKSDB->allTags(); | 879 | $tags= $LINKSDB->allTags(); |
820 | // We sort tags alphabetically, then choose a font size according to count. | 880 | // We sort tags alphabetically, then choose a font size according to count. |
821 | // First, find max value. | 881 | // First, find max value. |
822 | $maxcount=0; foreach($tags as $key=>$value) $maxcount=max($maxcount,$value); | 882 | $maxcount=0; foreach($tags as $key=>$value) $maxcount=max($maxcount,$value); |
823 | ksort($tags); | 883 | ksort($tags); |
824 | $cloud=''; | 884 | $tagList=array(); |
825 | foreach($tags as $key=>$value) | 885 | foreach($tags as $key=>$value) |
826 | { | 886 | { |
827 | $size = max(40*$value/$maxcount,8); // Minimum size 8. | 887 | $tagList[$key] = array('count'=>$value,'size'=>max(40*$value/$maxcount,8)); |
828 | $colorvalue = 128-ceil(127*$value/$maxcount); | ||
829 | $color='rgb('.$colorvalue.','.$colorvalue.','.$colorvalue.')'; | ||
830 | $cloud.= '<span style="color:#99f; font-size:9pt; padding-left:5px; padding-right:2px;">'.$value.'</span><a href="?searchtags='.htmlspecialchars($key).'" style="font-size:'.$size.'pt; font-weight:bold; color:'.$color.';">'.htmlspecialchars($key).'</a> '; | ||
831 | } | 888 | } |
832 | $cloud='<div id="cloudtag">'.$cloud.'</div>'; | 889 | $PAGE = new pageBuilder; |
833 | $data = array('pageheader'=>'','body'=>$cloud,'onload'=>''); | 890 | $PAGE->assign('tags',$tagList); |
834 | templatePage($data); | 891 | $PAGE->renderPage('tagcloud'); |
835 | exit; | 892 | exit; |
836 | } | 893 | } |
837 | 894 | ||
838 | // -------- User clicks on a tag in a link: The tag is added to the list of searched tags (searchtags=...) | 895 | // -------- User clicks on a tag in a link: The tag is added to the list of searched tags (searchtags=...) |
839 | if (isset($_GET['addtag'])) | 896 | if (isset($_GET['addtag'])) |
840 | { | 897 | { |
@@ -862,8 +919,8 @@ function renderPage() | |||
862 | } | 919 | } |
863 | header('Location: ?'.http_build_query($params)); | 920 | header('Location: ?'.http_build_query($params)); |
864 | exit; | 921 | exit; |
865 | } | 922 | } |
866 | 923 | ||
867 | // -------- User wants to change the number of links per page (linksperpage=...) | 924 | // -------- User wants to change the number of links per page (linksperpage=...) |
868 | if (isset($_GET['linksperpage'])) | 925 | if (isset($_GET['linksperpage'])) |
869 | { | 926 | { |
@@ -871,57 +928,37 @@ function renderPage() | |||
871 | header('Location: '.(empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER'])); | 928 | header('Location: '.(empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER'])); |
872 | exit; | 929 | exit; |
873 | } | 930 | } |
874 | 931 | ||
875 | 932 | ||
876 | // -------- Handle other actions allowed for non-logged in users: | 933 | // -------- Handle other actions allowed for non-logged in users: |
877 | if (!isLoggedIn()) | 934 | if (!isLoggedIn()) |
878 | { | 935 | { |
879 | // User tries to post new link but is not loggedin: | 936 | // User tries to post new link but is not loggedin: |
880 | // Show login screen, then redirect to ?post=... | 937 | // Show login screen, then redirect to ?post=... |
881 | if (isset($_GET['post'])) | 938 | if (isset($_GET['post'])) |
882 | { | 939 | { |
883 | header('Location: ?do=login&post='.urlencode($_GET['post']).(!empty($_GET['title'])?'&title='.urlencode($_GET['title']):'').(!empty($_GET['source'])?'&source='.urlencode($_GET['source']):'')); // Redirect to login page, then back to post link. | 940 | header('Location: ?do=login&post='.urlencode($_GET['post']).(!empty($_GET['title'])?'&title='.urlencode($_GET['title']):'').(!empty($_GET['source'])?'&source='.urlencode($_GET['source']):'')); // Redirect to login page, then back to post link. |
884 | exit; | 941 | exit; |
885 | } | 942 | } |
886 | 943 | $PAGE = new pageBuilder; | |
887 | // Show search form and display list of links. | 944 | buildLinkList($PAGE); // Compute list of links to display |
888 | $searchform=<<<HTML | 945 | $PAGE->renderPage('linklist'); |
889 | <div id="headerform" style="width:100%; white-space:nowrap;";> | 946 | exit; // Never remove this one ! All operations below are reserved for logged in user. |
890 | <form method="GET" class="searchform" name="searchform" style="display:inline;"><input type="text" name="searchterm" style="width:30%" value=""> <input type="submit" value="Search" class="bigbutton"></form> | ||
891 | <form method="GET" class="tagfilter" name="tagfilter" style="display:inline;margin-left:24px;"><input type="text" name="searchtags" id="searchtags" style="width:10%" value=""> <input type="submit" value="Filter by tag" class="bigbutton"></form> | ||
892 | </div> | ||
893 | HTML; | ||
894 | $data = array('pageheader'=>$searchform,'body'=>templateLinkList(),'onload'=>''); | ||
895 | templatePage($data); | ||
896 | exit; // Never remove this one ! All operations below are reserved for logged in user. | ||
897 | } | 947 | } |
898 | 948 | ||
899 | // -------- All other functions are reserved for the registered user: | 949 | // -------- All other functions are reserved for the registered user: |
900 | 950 | ||
901 | // -------- Display the Tools menu if requested (import/export/bookmarklet...) | 951 | // -------- Display the Tools menu if requested (import/export/bookmarklet...) |
902 | if (startswith($_SERVER["QUERY_STRING"],'do=tools')) | 952 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=tools')) |
903 | { | 953 | { |
904 | $pageabsaddr=serverUrl().$_SERVER["SCRIPT_NAME"]; // Why doesn't php have a built-in function for that ? | 954 | $PAGE = new pageBuilder; |
905 | // The javascript code for the bookmarklet: | 955 | $PAGE->assign('pageabsaddr',indexUrl()); |
906 | $changepwd = ($GLOBALS['config']['OPEN_SHAARLI'] ? '' : '<a href="?do=changepasswd"><b>Change password</b> <span>: Change your password.</span></a><br><br>' ); | 956 | $PAGE->renderPage('tools'); |
907 | $toolbar= <<<HTML | ||
908 | <div id="toolsdiv"> | ||
909 | {$changepwd} | ||
910 | <a href="?do=configure"><b>Configure your Shaarli</b> <span>: Change Title, timezone...</span></a><br><br> | ||
911 | <a href="?do=changetag"><b>Rename/delete tags</b> <span>: Rename or delete a tag in all links</span></a><br><br> | ||
912 | <a href="?do=import"><b>Import</b> <span>: Import Netscape html bookmarks (as exported from Firefox, Chrome, Opera, delicious...)</span></a> <br><br> | ||
913 | <a href="?do=export"><b>Export</b> <span>: Export Netscape html bookmarks (which can be imported in Firefox, Chrome, Opera, delicious...)</span></a><br><br> | ||
914 | <a class="smallbutton" onclick="alert('Drag this link to your bookmarks toolbar, or right-click it and choose Bookmark This Link...');return false;" href="javascript:javascript:(function(){var%20url%20=%20location.href;var%20title%20=%20document.title%20||%20url;window.open('{$pageabsaddr}?post='%20+%20encodeURIComponent(url)+'&title='%20+%20encodeURIComponent(title)+'&source=bookmarklet','_blank','menubar=no,height=390,width=600,toolbar=no,scrollbars=no,status=no');})();"><b>Shaare link</b></a> <a href="#" style="clear:none;"><span>⇐ Drag this link to your bookmarks toolbar (or right-click it and choose Bookmark This Link....). Then click "Shaare link" button in any page you want to share.</span></a><br><br> | ||
915 | <div class="clear"></div> | ||
916 | </div> | ||
917 | HTML; | ||
918 | $data = array('pageheader'=>$toolbar,'body'=>'','onload'=>''); | ||
919 | templatePage($data); | ||
920 | exit; | 957 | exit; |
921 | } | 958 | } |
922 | 959 | ||
923 | // -------- User wants to change his/her password. | 960 | // -------- User wants to change his/her password. |
924 | if (startswith($_SERVER["QUERY_STRING"],'do=changepasswd')) | 961 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=changepasswd')) |
925 | { | 962 | { |
926 | if ($GLOBALS['config']['OPEN_SHAARLI']) die('You are not supposed to change a password on an Open Shaarli.'); | 963 | if ($GLOBALS['config']['OPEN_SHAARLI']) die('You are not supposed to change a password on an Open Shaarli.'); |
927 | if (!empty($_POST['setpassword']) && !empty($_POST['oldpassword'])) | 964 | if (!empty($_POST['setpassword']) && !empty($_POST['oldpassword'])) |
@@ -938,32 +975,25 @@ HTML; | |||
938 | echo '<script language="JavaScript">alert("Your password has been changed.");document.location=\'?do=tools\';</script>'; | 975 | echo '<script language="JavaScript">alert("Your password has been changed.");document.location=\'?do=tools\';</script>'; |
939 | exit; | 976 | exit; |
940 | } | 977 | } |
941 | else | 978 | else // show the change password form. |
942 | { | 979 | { |
943 | $token = getToken(); | 980 | $PAGE = new pageBuilder; |
944 | $changepwdform= <<<HTML | 981 | $PAGE->assign('token',getToken()); |
945 | <form method="POST" action="" name="changepasswordform" id="changepasswordform"> | 982 | $PAGE->renderPage('changepassword'); |
946 | Old password: <input type="password" name="oldpassword"> | 983 | exit; |
947 | New password: <input type="password" name="setpassword"> | ||
948 | <input type="hidden" name="token" value="{$token}"> | ||
949 | <input type="submit" name="Save" value="Save password" class="bigbutton"></form> | ||
950 | HTML; | ||
951 | $data = array('pageheader'=>$changepwdform,'body'=>'','onload'=>'onload="document.changepasswordform.oldpassword.focus();"'); | ||
952 | templatePage($data); | ||
953 | exit; | ||
954 | } | 984 | } |
955 | } | 985 | } |
956 | 986 | ||
957 | // -------- User wants to change configuration | 987 | // -------- User wants to change configuration |
958 | if (startswith($_SERVER["QUERY_STRING"],'do=configure')) | 988 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=configure')) |
959 | { | 989 | { |
960 | if (!empty($_POST['title']) ) | 990 | if (!empty($_POST['title']) ) |
961 | { | 991 | { |
962 | if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away ! | 992 | if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away ! |
963 | $tz = 'UTC'; | 993 | $tz = 'UTC'; |
964 | if (!empty($_POST['continent']) && !empty($_POST['city'])) | 994 | if (!empty($_POST['continent']) && !empty($_POST['city'])) |
965 | if (isTZvalid($_POST['continent'],$_POST['city'])) | 995 | if (isTZvalid($_POST['continent'],$_POST['city'])) |
966 | $tz = $_POST['continent'].'/'.$_POST['city']; | 996 | $tz = $_POST['continent'].'/'.$_POST['city']; |
967 | $GLOBALS['timezone'] = $tz; | 997 | $GLOBALS['timezone'] = $tz; |
968 | $GLOBALS['title']=$_POST['title']; | 998 | $GLOBALS['title']=$_POST['title']; |
969 | $GLOBALS['redirector']=$_POST['redirector']; | 999 | $GLOBALS['redirector']=$_POST['redirector']; |
@@ -971,49 +1001,33 @@ HTML; | |||
971 | echo '<script language="JavaScript">alert("Configuration was saved.");document.location=\'?do=tools\';</script>'; | 1001 | echo '<script language="JavaScript">alert("Configuration was saved.");document.location=\'?do=tools\';</script>'; |
972 | exit; | 1002 | exit; |
973 | } | 1003 | } |
974 | else | 1004 | else // Show the configuration form. |
975 | { | 1005 | { |
976 | $token = getToken(); | 1006 | $PAGE = new pageBuilder; |
977 | $title = htmlspecialchars( empty($GLOBALS['title']) ? '' : $GLOBALS['title'] , ENT_QUOTES); | 1007 | $PAGE->assign('token',getToken()); |
978 | $redirector = htmlspecialchars( empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'] , ENT_QUOTES); | 1008 | $PAGE->assign('title',htmlspecialchars( empty($GLOBALS['title']) ? '' : $GLOBALS['title'] , ENT_QUOTES)); |
1009 | $PAGE->assign('redirector',htmlspecialchars( empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'] , ENT_QUOTES)); | ||
979 | list($timezone_form,$timezone_js) = templateTZform($GLOBALS['timezone']); | 1010 | list($timezone_form,$timezone_js) = templateTZform($GLOBALS['timezone']); |
980 | $timezone_html=''; if ($timezone_form!='') $timezone_html='<tr><td valign="top"><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>'; | 1011 | $PAGE->assign('timezone_form',$timezone_form); // FIXME: put entire tz form generation in template ? |
981 | $changepwdform= <<<HTML | 1012 | $PAGE->assign('timezone_js',$timezone_js); |
982 | ${timezone_js}<form method="POST" action="" name="configform" id="configform"><input type="hidden" name="token" value="{$token}"> | 1013 | $PAGE->renderPage('configure'); |
983 | <table border="0" cellpadding="20"> | 1014 | exit; |
984 | <tr><td><b>Page title:</b></td><td><input type="text" name="title" id="title" size="50" value="{$title}"></td></tr> | ||
985 | {$timezone_html} | ||
986 | <tr><td valign="top"><b>Redirector</b></td><td><input type="text" name="redirector" id="redirector" size="50" value="{$redirector}"><br>(e.g. <i>http://anonym.to/?</i> will mask the HTTP_REFERER)</td></tr> | ||
987 | <tr><td></td><td align="right"><input type="submit" name="Save" value="Save config" class="bigbutton"></td></tr> | ||
988 | </table> | ||
989 | </form> | ||
990 | HTML; | ||
991 | $data = array('pageheader'=>$changepwdform,'body'=>'','onload'=>'onload="document.configform.title.focus();"'); | ||
992 | templatePage($data); | ||
993 | exit; | ||
994 | } | 1015 | } |
995 | } | 1016 | } |
996 | 1017 | ||
997 | // -------- User wants to rename a tag or delete it | 1018 | // -------- User wants to rename a tag or delete it |
998 | if (startswith($_SERVER["QUERY_STRING"],'do=changetag')) | 1019 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=changetag')) |
999 | { | 1020 | { |
1000 | if (empty($_POST['fromtag'])) | 1021 | if (empty($_POST['fromtag'])) |
1001 | { | 1022 | { |
1002 | $token = getToken(); | 1023 | $PAGE = new pageBuilder; |
1003 | $changetagform = <<<HTML | 1024 | $PAGE->assign('token',getToken()); |
1004 | <form method="POST" action="" name="changetag" id="changetag"> | 1025 | $PAGE->renderPage('changetag'); |
1005 | <input type="hidden" name="token" value="{$token}"> | 1026 | exit; |
1006 | Tag: <input type="text" name="fromtag" id="fromtag"> | ||
1007 | <input type="text" name="totag" style="margin-left:40px;"><input type="submit" name="renametag" value="Rename tag" class="bigbutton"> | ||
1008 | or <input type="submit" name="deletetag" value="Delete tag" class="bigbutton" onClick="return confirmDeleteTag();"><br>(Case sensitive)</form> | ||
1009 | <script language="JavaScript">function confirmDeleteTag() { var agree=confirm("Are you sure you want to delete this tag from all links ?"); if (agree) return true ; else return false ; }</script> | ||
1010 | HTML; | ||
1011 | $data = array('pageheader'=>$changetagform,'body'=>'','onload'=>'onload="document.changetag.fromtag.focus();"'); | ||
1012 | templatePage($data); | ||
1013 | exit; | ||
1014 | } | 1027 | } |
1015 | if (!tokenOk($_POST['token'])) die('Wrong token.'); | 1028 | if (!tokenOk($_POST['token'])) die('Wrong token.'); |
1016 | 1029 | ||
1030 | // Delete a tag: | ||
1017 | if (!empty($_POST['deletetag']) && !empty($_POST['fromtag'])) | 1031 | if (!empty($_POST['deletetag']) && !empty($_POST['fromtag'])) |
1018 | { | 1032 | { |
1019 | $needle=trim($_POST['fromtag']); | 1033 | $needle=trim($_POST['fromtag']); |
@@ -1047,19 +1061,17 @@ HTML; | |||
1047 | invalidateCaches(); | 1061 | invalidateCaches(); |
1048 | echo '<script language="JavaScript">alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode($_POST['totag']).'\';</script>'; | 1062 | echo '<script language="JavaScript">alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode($_POST['totag']).'\';</script>'; |
1049 | exit; | 1063 | exit; |
1050 | } | 1064 | } |
1051 | } | 1065 | } |
1052 | 1066 | ||
1053 | // -------- User wants to add a link without using the bookmarklet: show form. | 1067 | // -------- User wants to add a link without using the bookmarklet: show form. |
1054 | if (startswith($_SERVER["QUERY_STRING"],'do=addlink')) | 1068 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=addlink')) |
1055 | { | 1069 | { |
1056 | $onload = 'onload="document.addform.post.focus();"'; | 1070 | $PAGE = new pageBuilder; |
1057 | $addform= '<div id="headerform"><form method="GET" action="" name="addform" class="addform"><input type="text" name="post" style="width:50%;"> <input type="submit" value="Add link" class="bigbutton"></div>'; | 1071 | $PAGE->renderPage('addlink'); |
1058 | $data = array('pageheader'=>$addform,'body'=>'','onload'=>$onload); | ||
1059 | templatePage($data); | ||
1060 | exit; | 1072 | exit; |
1061 | } | 1073 | } |
1062 | 1074 | ||
1063 | // -------- User clicked the "Save" button when editing a link: Save link to database. | 1075 | // -------- User clicked the "Save" button when editing a link: Save link to database. |
1064 | if (isset($_POST['save_edit'])) | 1076 | if (isset($_POST['save_edit'])) |
1065 | { | 1077 | { |
@@ -1067,20 +1079,20 @@ HTML; | |||
1067 | $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces. | 1079 | $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces. |
1068 | $linkdate=$_POST['lf_linkdate']; | 1080 | $linkdate=$_POST['lf_linkdate']; |
1069 | $link = array('title'=>trim($_POST['lf_title']),'url'=>trim($_POST['lf_url']),'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0), | 1081 | $link = array('title'=>trim($_POST['lf_title']),'url'=>trim($_POST['lf_url']),'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0), |
1070 | 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags)); | 1082 | 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags)); |
1071 | if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title. | 1083 | if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title. |
1072 | $LINKSDB[$linkdate] = $link; | 1084 | $LINKSDB[$linkdate] = $link; |
1073 | $LINKSDB->savedb(); // save to disk | 1085 | $LINKSDB->savedb(); // save to disk |
1074 | pubsubhub(); | 1086 | pubsubhub(); |
1075 | invalidateCaches(); | 1087 | invalidateCaches(); |
1076 | 1088 | ||
1077 | // If we are called from the bookmarklet, we must close the popup: | 1089 | // If we are called from the bookmarklet, we must close the popup: |
1078 | if (isset($_GET['source']) && $_GET['source']=='bookmarklet') { echo '<script language="JavaScript">self.close();</script>'; exit; } | 1090 | if (isset($_GET['source']) && $_GET['source']=='bookmarklet') { echo '<script language="JavaScript">self.close();</script>'; exit; } |
1079 | $returnurl = ( isset($_POST['returnurl']) ? $_POST['returnurl'] : '?' ); | 1091 | $returnurl = ( isset($_POST['returnurl']) ? $_POST['returnurl'] : '?' ); |
1080 | header('Location: '.$returnurl); // After saving the link, redirect to the page the user was on. | 1092 | header('Location: '.$returnurl); // After saving the link, redirect to the page the user was on. |
1081 | exit; | 1093 | exit; |
1082 | } | 1094 | } |
1083 | 1095 | ||
1084 | // -------- User clicked the "Cancel" button when editing a link. | 1096 | // -------- User clicked the "Cancel" button when editing a link. |
1085 | if (isset($_POST['cancel_edit'])) | 1097 | if (isset($_POST['cancel_edit'])) |
1086 | { | 1098 | { |
@@ -1088,7 +1100,7 @@ HTML; | |||
1088 | if (isset($_GET['source']) && $_GET['source']=='bookmarklet') { echo '<script language="JavaScript">self.close();</script>'; exit; } | 1100 | if (isset($_GET['source']) && $_GET['source']=='bookmarklet') { echo '<script language="JavaScript">self.close();</script>'; exit; } |
1089 | $returnurl = ( isset($_POST['returnurl']) ? $_POST['returnurl'] : '?' ); | 1101 | $returnurl = ( isset($_POST['returnurl']) ? $_POST['returnurl'] : '?' ); |
1090 | header('Location: '.$returnurl); // After canceling, redirect to the page the user was on. | 1102 | header('Location: '.$returnurl); // After canceling, redirect to the page the user was on. |
1091 | exit; | 1103 | exit; |
1092 | } | 1104 | } |
1093 | 1105 | ||
1094 | // -------- User clicked the "Delete" button when editing a link : Delete link from database. | 1106 | // -------- User clicked the "Delete" button when editing a link : Delete link from database. |
@@ -1107,19 +1119,22 @@ HTML; | |||
1107 | $returnurl = ( isset($_POST['returnurl']) ? $_POST['returnurl'] : '?' ); | 1119 | $returnurl = ( isset($_POST['returnurl']) ? $_POST['returnurl'] : '?' ); |
1108 | header('Location: '.$returnurl); // After deleting the link, redirect to the page the user was on. | 1120 | header('Location: '.$returnurl); // After deleting the link, redirect to the page the user was on. |
1109 | exit; | 1121 | exit; |
1110 | } | 1122 | } |
1111 | 1123 | ||
1112 | // -------- User clicked the "EDIT" button on a link: Display link edit form. | 1124 | // -------- User clicked the "EDIT" button on a link: Display link edit form. |
1113 | if (isset($_GET['edit_link'])) | 1125 | if (isset($_GET['edit_link'])) |
1114 | { | 1126 | { |
1115 | $link = $LINKSDB[$_GET['edit_link']]; // Read database | 1127 | $link = $LINKSDB[$_GET['edit_link']]; // Read database |
1116 | if (!$link) { header('Location: ?'); exit; } // Link not found in database. | 1128 | if (!$link) { header('Location: ?'); exit; } // Link not found in database. |
1117 | list($editform,$onload)=templateEditForm($link); | 1129 | $PAGE = new pageBuilder; |
1118 | $data = array('pageheader'=>$editform,'body'=>'','onload'=>$onload); | 1130 | $PAGE->assign('link',$link); |
1119 | templatePage($data); | 1131 | $PAGE->assign('link_is_new',false); |
1120 | exit; | 1132 | $PAGE->assign('token',getToken()); // XSRF protection. |
1133 | $PAGE->assign('http_referer',(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '')); | ||
1134 | $PAGE->renderPage('editlink'); | ||
1135 | exit; | ||
1121 | } | 1136 | } |
1122 | 1137 | ||
1123 | // -------- User want to post a new link: Display link edit form. | 1138 | // -------- User want to post a new link: Display link edit form. |
1124 | if (isset($_GET['post'])) | 1139 | if (isset($_GET['post'])) |
1125 | { | 1140 | { |
@@ -1129,51 +1144,48 @@ HTML; | |||
1129 | $i=strpos($url,'&utm_source='); if ($i!==false) $url=substr($url,0,$i); | 1144 | $i=strpos($url,'&utm_source='); if ($i!==false) $url=substr($url,0,$i); |
1130 | $i=strpos($url,'?utm_source='); if ($i!==false) $url=substr($url,0,$i); | 1145 | $i=strpos($url,'?utm_source='); if ($i!==false) $url=substr($url,0,$i); |
1131 | $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i); | 1146 | $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i); |
1132 | 1147 | ||
1133 | $link_is_new = false; | 1148 | $link_is_new = false; |
1134 | $link = $LINKSDB->getLinkFromUrl($url); // Check if URL is not already in database (in this case, we will edit the existing link) | 1149 | $link = $LINKSDB->getLinkFromUrl($url); // Check if URL is not already in database (in this case, we will edit the existing link) |
1135 | if (!$link) | 1150 | if (!$link) |
1136 | { | 1151 | { |
1137 | $link_is_new = true; // This is a new link | 1152 | $link_is_new = true; // This is a new link |
1138 | $linkdate = strval(date('Ymd_His')); | 1153 | $linkdate = strval(date('Ymd_His')); |
1139 | $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet). | 1154 | $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet). |
1140 | $description=''; $tags=''; $private=0; | 1155 | $description=''; $tags=''; $private=0; |
1141 | if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url; | 1156 | if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url; |
1142 | // If this is an HTTP link, we try go get the page to extact the title (otherwise we will to straight to the edit form.) | 1157 | // If this is an HTTP link, we try go get the page to extact the title (otherwise we will to straight to the edit form.) |
1143 | if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http') | 1158 | if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http') |
1144 | { | 1159 | { |
1145 | list($status,$headers,$data) = getHTTP($url,4); // Short timeout to keep the application responsive. | 1160 | list($status,$headers,$data) = getHTTP($url,4); // Short timeout to keep the application responsive. |
1146 | // FIXME: Decode charset according to specified in either 1) HTTP response headers or 2) <head> in html | 1161 | // FIXME: Decode charset according to specified in either 1) HTTP response headers or 2) <head> in html |
1147 | if (strpos($status,'200 OK')!==false) $title=html_entity_decode(html_extract_title($data),ENT_QUOTES,'UTF-8'); | 1162 | if (strpos($status,'200 OK')!==false) $title=html_entity_decode(html_extract_title($data),ENT_QUOTES,'UTF-8'); |
1148 | } | 1163 | } |
1149 | if ($url=='') $url='?'.smallHash($linkdate); // In case of empty URL, this is just a text (with a link that point to itself) | 1164 | if ($url=='') $url='?'.smallHash($linkdate); // In case of empty URL, this is just a text (with a link that point to itself) |
1150 | $link = array('linkdate'=>$linkdate,'title'=>$title,'url'=>$url,'description'=>$description,'tags'=>$tags,'private'=>0); | 1165 | $link = array('linkdate'=>$linkdate,'title'=>$title,'url'=>$url,'description'=>$description,'tags'=>$tags,'private'=>0); |
1151 | } | 1166 | } |
1152 | list($editform,$onload)=templateEditForm($link,$link_is_new); | 1167 | |
1153 | $data = array('pageheader'=>$editform,'body'=>'','onload'=>$onload); | 1168 | $PAGE = new pageBuilder; |
1154 | templatePage($data); | 1169 | $PAGE->assign('link',$link); |
1170 | $PAGE->assign('link_is_new',$link_is_new); | ||
1171 | $PAGE->assign('token',getToken()); // XSRF protection. | ||
1172 | $PAGE->assign('http_referer',(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '')); | ||
1173 | $PAGE->renderPage('editlink'); | ||
1155 | exit; | 1174 | exit; |
1156 | } | 1175 | } |
1157 | 1176 | ||
1158 | // -------- Export as Netscape Bookmarks HTML file. | 1177 | // -------- Export as Netscape Bookmarks HTML file. |
1159 | if (startswith($_SERVER["QUERY_STRING"],'do=export')) | 1178 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=export')) |
1160 | { | 1179 | { |
1161 | if (empty($_GET['what'])) | 1180 | if (empty($_GET['what'])) |
1162 | { | 1181 | { |
1163 | $toolbar= <<<HTML | 1182 | $PAGE = new pageBuilder; |
1164 | <div id="toolsdiv"> | 1183 | $PAGE->renderPage('export'); |
1165 | <a href="?do=export&what=all"><b>Export all</b> <span>: Export all links</span></a><br><br> | 1184 | exit; |
1166 | <a href="?do=export&what=public"><b>Export public</b> <span>: Export public links only</a><br><br> | ||
1167 | <a href="?do=export&what=private"><b>Export private</b> <span>: Export private links only</a><br><br style="clear:both;"> | ||
1168 | </div> | ||
1169 | HTML; | ||
1170 | $data = array('pageheader'=>$toolbar,'body'=>'','onload'=>''); | ||
1171 | templatePage($data); | ||
1172 | exit; | ||
1173 | } | 1185 | } |
1174 | $exportWhat=$_GET['what']; | 1186 | $exportWhat=$_GET['what']; |
1175 | if (!array_intersect(array('all','public','private'),array($exportWhat))) die('What are you trying to export ???'); | 1187 | if (!array_intersect(array('all','public','private'),array($exportWhat))) die('What are you trying to export ???'); |
1176 | 1188 | ||
1177 | header('Content-Type: text/html; charset=utf-8'); | 1189 | header('Content-Type: text/html; charset=utf-8'); |
1178 | header('Content-disposition: attachment; filename=bookmarks_'.$exportWhat.'_'.strval(date('Ymd_His')).'.html'); | 1190 | header('Content-disposition: attachment; filename=bookmarks_'.$exportWhat.'_'.strval(date('Ymd_His')).'.html'); |
1179 | $currentdate=date('Y/m/d H:i:s'); | 1191 | $currentdate=date('Y/m/d H:i:s'); |
@@ -1182,7 +1194,7 @@ HTML; | |||
1182 | <!-- This is an automatically generated file. | 1194 | <!-- This is an automatically generated file. |
1183 | It will be read and overwritten. | 1195 | It will be read and overwritten. |
1184 | DO NOT EDIT! --> | 1196 | DO NOT EDIT! --> |
1185 | <!-- Shaarli {$exportWhat} bookmarks export on {$currentdate} --> | 1197 | <!-- Shaarli {$exportWhat} bookmarks export on {$currentdate} --> |
1186 | <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> | 1198 | <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> |
1187 | <TITLE>Bookmarks</TITLE> | 1199 | <TITLE>Bookmarks</TITLE> |
1188 | <H1>Bookmarks</H1> | 1200 | <H1>Bookmarks</H1> |
@@ -1200,10 +1212,10 @@ HTML; | |||
1200 | } | 1212 | } |
1201 | } | 1213 | } |
1202 | exit; | 1214 | exit; |
1203 | } | 1215 | } |
1204 | 1216 | ||
1205 | // -------- User is uploading a file for import | 1217 | // -------- User is uploading a file for import |
1206 | if (startswith($_SERVER["QUERY_STRING"],'do=upload')) | 1218 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=upload')) |
1207 | { | 1219 | { |
1208 | // If file is too big, some form field may be missing. | 1220 | // If file is too big, some form field may be missing. |
1209 | if (!isset($_POST['token']) || (!isset($_FILES)) || (isset($_FILES['filetoupload']['size']) && $_FILES['filetoupload']['size']==0)) | 1221 | if (!isset($_POST['token']) || (!isset($_FILES)) || (isset($_FILES['filetoupload']['size']) && $_FILES['filetoupload']['size']==0)) |
@@ -1211,47 +1223,28 @@ HTML; | |||
1211 | $returnurl = ( empty($_SERVER['HTTP_REFERER']) ? '?' : $_SERVER['HTTP_REFERER'] ); | 1223 | $returnurl = ( empty($_SERVER['HTTP_REFERER']) ? '?' : $_SERVER['HTTP_REFERER'] ); |
1212 | echo '<script language="JavaScript">alert("The file you are trying to upload is probably bigger than what this webserver can accept ('.getMaxFileSize().' bytes). Please upload in smaller chunks.");document.location=\''.htmlspecialchars($returnurl).'\';</script>'; | 1224 | echo '<script language="JavaScript">alert("The file you are trying to upload is probably bigger than what this webserver can accept ('.getMaxFileSize().' bytes). Please upload in smaller chunks.");document.location=\''.htmlspecialchars($returnurl).'\';</script>'; |
1213 | exit; | 1225 | exit; |
1214 | } | 1226 | } |
1215 | if (!tokenOk($_POST['token'])) die('Wrong token.'); | 1227 | if (!tokenOk($_POST['token'])) die('Wrong token.'); |
1216 | importFile(); | 1228 | importFile(); |
1217 | exit; | 1229 | exit; |
1218 | } | 1230 | } |
1219 | 1231 | ||
1220 | // -------- Show upload/import dialog: | 1232 | // -------- Show upload/import dialog: |
1221 | if (startswith($_SERVER["QUERY_STRING"],'do=import')) | 1233 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=import')) |
1222 | { | 1234 | { |
1223 | $token = getToken(); | 1235 | $PAGE = new pageBuilder; |
1224 | $maxfilesize=getMaxFileSize(); | 1236 | $PAGE->assign('token',getToken()); |
1225 | $onload = 'onload="document.uploadform.filetoupload.focus();"'; | 1237 | $PAGE->assign('maxfilesize',getMaxFileSize()); |
1226 | $uploadform=<<<HTML | 1238 | $PAGE->renderPage('import'); |
1227 | <div id="uploaddiv"> | ||
1228 | Import Netscape html bookmarks (as exported from Firefox/Chrome/Opera/delicious/diigo...) (Max: {$maxfilesize} bytes). | ||
1229 | <form method="POST" action="?do=upload" enctype="multipart/form-data" name="uploadform" id="uploadform"> | ||
1230 | <input type="hidden" name="token" value="{$token}"> | ||
1231 | <input type="file" name="filetoupload" size="80"> | ||
1232 | <input type="hidden" name="MAX_FILE_SIZE" value="{$maxfilesize}"> | ||
1233 | <input type="submit" name="import_file" value="Import" class="bigbutton"><br> | ||
1234 | <input type="checkbox" name="private"> Import all links as private<br> | ||
1235 | <input type="checkbox" name="overwrite"> Overwrite existing links | ||
1236 | </form> | ||
1237 | </div> | ||
1238 | HTML; | ||
1239 | $data = array('pageheader'=>$uploadform,'body'=>'','onload'=>$onload ); | ||
1240 | templatePage($data); | ||
1241 | exit; | 1239 | exit; |
1242 | } | 1240 | } |
1243 | 1241 | ||
1244 | // -------- Otherwise, simply display search form and links: | 1242 | // -------- Otherwise, simply display search form and links: |
1245 | $searchform=<<<HTML | 1243 | $PAGE = new pageBuilder; |
1246 | <div id="headerform" style="width:100%; white-space:nowrap;";> | 1244 | buildLinkList($PAGE); // Compute list of links to display |
1247 | <form method="GET" class="searchform" name="searchform"><input type="text" name="searchterm" style="width:30%" value=""> <input type="submit" value="Search" class="bigbutton"></form> | 1245 | $PAGE->renderPage('linklist'); |
1248 | <form method="GET" class="tagfilter" name="tagfilter" style="margin-left:24px;"><input type="text" name="searchtags" id="searchtags" style="width:10%" value=""> <input type="submit" value="Filter by tag" class="bigbutton"></form> | ||
1249 | </div> | ||
1250 | HTML; | ||
1251 | $data = array('pageheader'=>$searchform,'body'=>templateLinkList(),'onload'=>''); | ||
1252 | templatePage($data); | ||
1253 | exit; | 1246 | exit; |
1254 | } | 1247 | } |
1255 | 1248 | ||
1256 | // ----------------------------------------------------------------------------------------------- | 1249 | // ----------------------------------------------------------------------------------------------- |
1257 | // Process the import file form. | 1250 | // Process the import file form. |
@@ -1259,7 +1252,7 @@ function importFile() | |||
1259 | { | 1252 | { |
1260 | global $LINKSDB; | 1253 | global $LINKSDB; |
1261 | $filename=$_FILES['filetoupload']['name']; | 1254 | $filename=$_FILES['filetoupload']['name']; |
1262 | $filesize=$_FILES['filetoupload']['size']; | 1255 | $filesize=$_FILES['filetoupload']['size']; |
1263 | $data=file_get_contents($_FILES['filetoupload']['tmp_name']); | 1256 | $data=file_get_contents($_FILES['filetoupload']['tmp_name']); |
1264 | $private = (empty($_POST['private']) ? 0 : 1); // Should the links be imported as private ? | 1257 | $private = (empty($_POST['private']) ? 0 : 1); // Should the links be imported as private ? |
1265 | $overwrite = !empty($_POST['overwrite']) ; // Should the imported links overwrite existing ones ? | 1258 | $overwrite = !empty($_POST['overwrite']) ; // Should the imported links overwrite existing ones ? |
@@ -1268,15 +1261,15 @@ function importFile() | |||
1268 | // Sniff file type: | 1261 | // Sniff file type: |
1269 | $type='unknown'; | 1262 | $type='unknown'; |
1270 | if (startsWith($data,'<!DOCTYPE NETSCAPE-Bookmark-file-1>')) $type='netscape'; // Netscape bookmark file (aka Firefox). | 1263 | if (startsWith($data,'<!DOCTYPE NETSCAPE-Bookmark-file-1>')) $type='netscape'; // Netscape bookmark file (aka Firefox). |
1271 | 1264 | ||
1272 | // Then import the bookmarks. | 1265 | // Then import the bookmarks. |
1273 | if ($type=='netscape') | 1266 | if ($type=='netscape') |
1274 | { | 1267 | { |
1275 | // This is a standard Netscape-style bookmark file. | 1268 | // This is a standard Netscape-style bookmark file. |
1276 | // This format is supported by all browsers (except IE, of course), also delicious, diigo and others. | 1269 | // This format is supported by all browsers (except IE, of course), also delicious, diigo and others. |
1277 | foreach(explode('<DT>',$data) as $html) // explode is very fast | 1270 | foreach(explode('<DT>',$data) as $html) // explode is very fast |
1278 | { | 1271 | { |
1279 | $link = array('linkdate'=>'','title'=>'','url'=>'','description'=>'','tags'=>'','private'=>0); | 1272 | $link = array('linkdate'=>'','title'=>'','url'=>'','description'=>'','tags'=>'','private'=>0); |
1280 | $d = explode('<DD>',$html); | 1273 | $d = explode('<DD>',$html); |
1281 | if (startswith($d[0],'<A ')) | 1274 | if (startswith($d[0],'<A ')) |
1282 | { | 1275 | { |
@@ -1292,7 +1285,7 @@ function importFile() | |||
1292 | elseif ($attr=='ADD_DATE') $raw_add_date=intval($value); | 1285 | elseif ($attr=='ADD_DATE') $raw_add_date=intval($value); |
1293 | elseif ($attr=='PRIVATE') $link['private']=($value=='0'?0:1); | 1286 | elseif ($attr=='PRIVATE') $link['private']=($value=='0'?0:1); |
1294 | elseif ($attr=='TAGS') $link['tags']=html_entity_decode(str_replace(',',' ',$value),ENT_QUOTES,'UTF-8'); | 1287 | elseif ($attr=='TAGS') $link['tags']=html_entity_decode(str_replace(',',' ',$value),ENT_QUOTES,'UTF-8'); |
1295 | } | 1288 | } |
1296 | if ($link['url']!='') | 1289 | if ($link['url']!='') |
1297 | { | 1290 | { |
1298 | if ($private==1) $link['private']=1; | 1291 | if ($private==1) $link['private']=1; |
@@ -1300,7 +1293,7 @@ function importFile() | |||
1300 | if ($dblink==false) | 1293 | if ($dblink==false) |
1301 | { // Link not in database, let's import it... | 1294 | { // Link not in database, let's import it... |
1302 | if (empty($raw_add_date)) $raw_add_date=time(); // In case of shitty bookmark file with no ADD_DATE | 1295 | if (empty($raw_add_date)) $raw_add_date=time(); // In case of shitty bookmark file with no ADD_DATE |
1303 | 1296 | ||
1304 | // Make sure date/time is not already used by another link. | 1297 | // Make sure date/time is not already used by another link. |
1305 | // (Some bookmark files have several different links with the same ADD_DATE) | 1298 | // (Some bookmark files have several different links with the same ADD_DATE) |
1306 | // We increment date by 1 second until we find a date which is not used in db. | 1299 | // We increment date by 1 second until we find a date which is not used in db. |
@@ -1321,98 +1314,51 @@ function importFile() | |||
1321 | } | 1314 | } |
1322 | 1315 | ||
1323 | } | 1316 | } |
1324 | } | 1317 | } |
1325 | } | 1318 | } |
1326 | $LINKSDB->savedb(); | 1319 | $LINKSDB->savedb(); |
1327 | invalidateCaches(); | 1320 | invalidateCaches(); |
1328 | echo '<script language="JavaScript">alert("File '.$filename.' ('.$filesize.' bytes) was successfully processed: '.$import_count.' links imported.");document.location=\'?\';</script>'; | 1321 | echo '<script language="JavaScript">alert("File '.$filename.' ('.$filesize.' bytes) was successfully processed: '.$import_count.' links imported.");document.location=\'?\';</script>'; |
1329 | } | 1322 | } |
1330 | else | 1323 | else |
1331 | { | 1324 | { |
1332 | echo '<script language="JavaScript">alert("File '.$filename.' ('.$filesize.' bytes) has an unknown file format. Nothing was imported.");document.location=\'?\';</script>'; | 1325 | echo '<script language="JavaScript">alert("File '.$filename.' ('.$filesize.' bytes) has an unknown file format. Nothing was imported.");document.location=\'?\';</script>'; |
1333 | } | 1326 | } |
1334 | } | 1327 | } |
1335 | 1328 | ||
1336 | // ----------------------------------------------------------------------------------------------- | 1329 | // ----------------------------------------------------------------------------------------------- |
1337 | /* Template for the edit link form | 1330 | // Template for the list of links (<div id="linklist">) |
1338 | Input: $link : link to edit (assocative array item as returned by the LINKDB class) | 1331 | // This function fills all the necessary fields in the $PAGE for the template 'linklist.html' |
1339 | Output: An array : (string) : The html code of the edit link form. | 1332 | function buildLinkList($PAGE) |
1340 | (string) : The proper onload to use in body. | ||
1341 | Example: list($html,$onload)=templateEditForm($mylinkdb['20110805_124532']); | ||
1342 | echo $html; | ||
1343 | */ | ||
1344 | function templateEditForm($link,$link_is_new=false) | ||
1345 | { | 1333 | { |
1346 | $url=htmlspecialchars($link['url']); | 1334 | global $LINKSDB; // Get the links database. |
1347 | $title=htmlspecialchars($link['title']); | ||
1348 | $tags=htmlspecialchars($link['tags']); | ||
1349 | $description=htmlspecialchars($link['description']); | ||
1350 | $private = ($link['private']==0 ? '' : 'checked="yes"'); | ||
1351 | |||
1352 | // Automatically focus on empty fields: | ||
1353 | $onload='onload="document.linkform.lf_tags.focus();"'; | ||
1354 | if ($description=='') $onload='onload="document.linkform.lf_description.focus();"'; | ||
1355 | if ($title=='') $onload='onload="document.linkform.lf_title.focus();"'; | ||
1356 | |||
1357 | // Do not show "Delete" button if this is a new link. | ||
1358 | $delete_button = '<input type="submit" value="Delete" name="delete_link" class="bigbutton" style="margin-left:180px;" onClick="return confirmDeleteLink();">'; | ||
1359 | if ($link_is_new) $delete_button=''; | ||
1360 | |||
1361 | $token=getToken(); // XSRF protection. | ||
1362 | $returnurl_html = (isset($_SERVER['HTTP_REFERER']) ? '<input type="hidden" name="returnurl" value="'.htmlspecialchars($_SERVER['HTTP_REFERER']).'">' : ''); | ||
1363 | $editlinkform=<<<HTML | ||
1364 | <div id="editlinkform"> | ||
1365 | <form method="post" name="linkform"> | ||
1366 | <input type="hidden" name="lf_linkdate" value="{$link['linkdate']}"> | ||
1367 | <i>URL</i><br><input type="text" name="lf_url" value="{$url}" style="width:100%"><br> | ||
1368 | <i>Title</i><br><input type="text" name="lf_title" value="{$title}" style="width:100%"><br> | ||
1369 | <i>Description</i><br><textarea name="lf_description" rows="4" cols="25" style="width:100%">{$description}</textarea><br> | ||
1370 | <i>Tags</i><br><input type="text" id="lf_tags" name="lf_tags" value="{$tags}" style="width:100%"><br> | ||
1371 | <input type="checkbox" {$private} style="margin:7 0 10 0;" name="lf_private"> <i>Private</i><br> | ||
1372 | <input type="submit" value="Save" name="save_edit" class="bigbutton" style="margin-left:40px;"> | ||
1373 | <input type="submit" value="Cancel" name="cancel_edit" class="bigbutton" style="margin-left:40px;"> | ||
1374 | {$delete_button} | ||
1375 | <input type="hidden" name="token" value="{$token}"> | ||
1376 | {$returnurl_html} | ||
1377 | </form> | ||
1378 | </div> | ||
1379 | HTML; | ||
1380 | return array($editlinkform,$onload); | ||
1381 | } | ||
1382 | |||
1383 | |||
1384 | // ----------------------------------------------------------------------------------------------- | ||
1385 | // Template for the list of links. | ||
1386 | // Returns html code to show the list of link according to parameters passed in URL (search terms, page...) | ||
1387 | function templateLinkList() | ||
1388 | { | ||
1389 | global $LINKSDB; | ||
1390 | 1335 | ||
1391 | // Search according to entered search terms: | 1336 | // ---- Filter link database according to parameters |
1392 | $linksToDisplay=array(); | 1337 | $linksToDisplay=array(); |
1393 | $searched=''; | 1338 | $search_type=''; |
1339 | $search_crits=''; | ||
1394 | if (!empty($_GET['searchterm'])) // Fulltext search | 1340 | if (!empty($_GET['searchterm'])) // Fulltext search |
1395 | { | 1341 | { |
1396 | $linksToDisplay = $LINKSDB->filterFulltext(trim($_GET['searchterm'])); | 1342 | $linksToDisplay = $LINKSDB->filterFulltext(trim($_GET['searchterm'])); |
1397 | $searched=count($linksToDisplay).' results for <i>'.htmlspecialchars(trim($_GET['searchterm'])).'</i>:'; | 1343 | $search_crits=htmlspecialchars(trim($_GET['searchterm'])); |
1344 | $search_type='fulltext'; | ||
1398 | } | 1345 | } |
1399 | elseif (!empty($_GET['searchtags'])) // Search by tag | 1346 | elseif (!empty($_GET['searchtags'])) // Search by tag |
1400 | { | 1347 | { |
1401 | $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); | 1348 | $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); |
1402 | $tagshtml=''; foreach(explode(' ',trim($_GET['searchtags'])) as $tag) $tagshtml.='<span class="linktag" title="Remove tag"><a href="?removetag='.htmlspecialchars($tag).'">'.htmlspecialchars($tag).' <span style="border-left:1px solid #aaa; padding-left:5px; color:#6767A7;">x</span></a></span> '; | 1349 | $search_crits=explode(' ',trim($_GET['searchtags'])); |
1403 | $searched=''.count($linksToDisplay).' results for tags '.$tagshtml.':'; | 1350 | $search_type='tags'; |
1404 | } | 1351 | } |
1405 | elseif (preg_match('/[a-zA-Z0-9-_@]{6}/',$_SERVER["QUERY_STRING"])) // Detect smallHashes in URL | 1352 | elseif (isset($_SERVER["QUERY_STRING"]) && preg_match('/[a-zA-Z0-9-_@]{6}(&.+?)?/',$_SERVER["QUERY_STRING"])) // Detect smallHashes in URL |
1406 | { | 1353 | { |
1407 | $linksToDisplay = $LINKSDB->filterSmallHash($_SERVER["QUERY_STRING"]); | 1354 | $linksToDisplay = $LINKSDB->filterSmallHash(substr(trim($_SERVER["QUERY_STRING"], '/'),0,6)); |
1355 | $search_type='permalink'; | ||
1408 | } | 1356 | } |
1409 | else | 1357 | else |
1410 | $linksToDisplay = $LINKSDB; // otherwise, display without filtering. | 1358 | $linksToDisplay = $LINKSDB; // otherwise, display without filtering. |
1411 | if ($searched!='') $searched='<div id="searchcriteria">'.$searched.'</div>'; | 1359 | |
1412 | $linklist=''; | 1360 | |
1413 | $actions=''; | 1361 | // ---- Handle paging. |
1414 | |||
1415 | // Handle paging. | ||
1416 | /* Can someone explain to me why you get the following error when using array_keys() on an object which implements the interface ArrayAccess ??? | 1362 | /* Can someone explain to me why you get the following error when using array_keys() on an object which implements the interface ArrayAccess ??? |
1417 | "Warning: array_keys() expects parameter 1 to be array, object given in ... " | 1363 | "Warning: array_keys() expects parameter 1 to be array, object given in ... " |
1418 | If my class implements ArrayAccess, why won't array_keys() accept it ? ( $keys=array_keys($linksToDisplay); ) | 1364 | If my class implements ArrayAccess, why won't array_keys() accept it ? ( $keys=array_keys($linksToDisplay); ) |
@@ -1422,72 +1368,62 @@ function templateLinkList() | |||
1422 | // If there is only a single link, we change on-the-fly the title of the page. | 1368 | // If there is only a single link, we change on-the-fly the title of the page. |
1423 | if (count($linksToDisplay)==1) $GLOBALS['pagetitle'] = $linksToDisplay[$keys[0]]['title'].' - '.$GLOBALS['title']; | 1369 | if (count($linksToDisplay)==1) $GLOBALS['pagetitle'] = $linksToDisplay[$keys[0]]['title'].' - '.$GLOBALS['title']; |
1424 | 1370 | ||
1371 | // Select articles according to paging. | ||
1425 | $pagecount = ceil(count($keys)/$_SESSION['LINKS_PER_PAGE']); | 1372 | $pagecount = ceil(count($keys)/$_SESSION['LINKS_PER_PAGE']); |
1426 | $pagecount = ($pagecount==0 ? 1 : $pagecount); | 1373 | $pagecount = ($pagecount==0 ? 1 : $pagecount); |
1427 | $page=( empty($_GET['page']) ? 1 : intval($_GET['page'])); | 1374 | $page=( empty($_GET['page']) ? 1 : intval($_GET['page'])); |
1428 | $page = ( $page<1 ? 1 : $page ); | 1375 | $page = ( $page<1 ? 1 : $page ); |
1429 | $page = ( $page>$pagecount ? $pagecount : $page ); | 1376 | $page = ( $page>$pagecount ? $pagecount : $page ); |
1430 | $i = ($page-1)*$_SESSION['LINKS_PER_PAGE']; // Start index. | 1377 | $i = ($page-1)*$_SESSION['LINKS_PER_PAGE']; // Start index. |
1431 | $end = $i+$_SESSION['LINKS_PER_PAGE']; | 1378 | $end = $i+$_SESSION['LINKS_PER_PAGE']; |
1432 | $redir = empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector']; // optional redirector URL | 1379 | $linkDisp=array(); // Links to display |
1433 | $token = ''; if (isLoggedIn()) $token=getToken(); | ||
1434 | |||
1435 | while ($i<$end && $i<count($keys)) | 1380 | while ($i<$end && $i<count($keys)) |
1436 | { | 1381 | { |
1437 | $link = $linksToDisplay[$keys[$i]]; | 1382 | $link = $linksToDisplay[$keys[$i]]; |
1438 | $description=text2clickable(htmlspecialchars($link['description'])); | 1383 | $link['description']=nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description'])))); |
1439 | $title=$link['title']; | 1384 | $title=$link['title']; |
1440 | $classLi = $i%2!=0 ? '' : 'class="publicLinkHightLight"'; | 1385 | $classLi = $i%2!=0 ? '' : 'publicLinkHightLight'; |
1441 | $classprivate = ($link['private']==0 ? $classLi : 'class="private"'); | 1386 | $link['class'] = ($link['private']==0 ? $classLi : 'private'); |
1442 | if (isLoggedIn()) | 1387 | $link['localdate']=linkdate2locale($link['linkdate']); |
1443 | { | 1388 | $link['taglist']=explode(' ',$link['tags']); |
1444 | $actions=' <form method="GET" class="buttoneditform"><input type="hidden" name="edit_link" value="'.$link['linkdate'].'"><input type="image" alt="Edit" src="images/edit_icon.png" title="Edit" class="button_edit"></form>'; | 1389 | $linkDisp[$keys[$i]] = $link; |
1445 | $actions.=' <form method="POST" class="buttoneditform"><input type="hidden" name="lf_linkdate" value="'.$link['linkdate'].'">'; | ||
1446 | $actions.='<input type="hidden" name="token" value="'.$token.'"><input type="hidden" name="delete_link"><input type="image" alt="Delete" src="images/delete_icon.png" title="Delete" class="button_delete" onClick="return confirmDeleteLink();"></form>'; | ||
1447 | } | ||
1448 | $tags=''; | ||
1449 | if ($link['tags']!='') | ||
1450 | { | ||
1451 | foreach(explode(' ',$link['tags']) as $tag) { $tags.='<span class="linktag" title="Add tag"><a href="?addtag='.htmlspecialchars($tag).'">'.htmlspecialchars($tag).'</a></span> '; } | ||
1452 | $tags='<div class="linktaglist">'.$tags.'</div>'; | ||
1453 | } | ||
1454 | $linklist.='<li '.$classprivate.'><div class="thumbnail">'.thumbnail($link['url']).'</div>'; | ||
1455 | $linklist.='<div class="linkcontainer"><span class="linktitle"><a href="'.$redir.htmlspecialchars($link['url']).'">'.htmlspecialchars($title).'</a></span>'.$actions.'<br>'; | ||
1456 | if ($description!='') $linklist.='<div class="linkdescription">'.nl2br($description).'</div><br>'; | ||
1457 | if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) $linklist.='<span class="linkdate" title="Permalink"><a href="?'.smallHash($link['linkdate']).'">'.htmlspecialchars(linkdate2locale($link['linkdate'])).' - permalink</a> - </span>'; | ||
1458 | else $linklist.='<span class="linkdate" title="Short link here"><a href="?'.smallHash($link['linkdate']).'">permalink</a> - </span>'; | ||
1459 | $linklist.='<span class="linkurl" title="Short link">'.htmlspecialchars($link['url']).'</span><br>'.$tags."</div></li>\n"; | ||
1460 | $i++; | 1390 | $i++; |
1461 | } | 1391 | } |
1462 | 1392 | ||
1463 | // Show paging. | 1393 | // Compute paging navigation |
1464 | $searchterm= ( empty($_GET['searchterm']) ? '' : '&searchterm='.$_GET['searchterm'] ); | 1394 | $searchterm= ( empty($_GET['searchterm']) ? '' : '&searchterm='.$_GET['searchterm'] ); |
1465 | $searchtags= ( empty($_GET['searchtags']) ? '' : '&searchtags='.$_GET['searchtags'] ); | 1395 | $searchtags= ( empty($_GET['searchtags']) ? '' : '&searchtags='.$_GET['searchtags'] ); |
1466 | $paging=''; | 1396 | $paging=''; |
1467 | if ($i!=count($keys)) $paging.='<a href="?page='.($page+1).$searchterm.$searchtags.'">◄Older</a>'; | 1397 | $previous_page_url=''; if ($i!=count($keys)) $previous_page_url='?page='.($page+1).$searchterm.$searchtags; |
1468 | $paging.= '<span style="color:#fff; padding:0 20 0 20;">page '.$page.' / '.$pagecount.'</span>'; | 1398 | $next_page_url='';if ($page>1) $next_page_url='?page='.($page-1).$searchterm.$searchtags; |
1469 | if ($page>1) $paging.='<a href="?page='.($page-1).$searchterm.$searchtags.'">Newer►</a>'; | 1399 | |
1470 | $linksperpage = <<<HTML | 1400 | $token = ''; if (isLoggedIn()) $token=getToken(); |
1471 | <div style="float:right; padding-right:5px;"> | 1401 | |
1472 | Links per page: <a href="?linksperpage=20">20</a> <a href="?linksperpage=50">50</a> <a href="?linksperpage=100">100</a> | 1402 | // Fill all template fields. |
1473 | <form method="GET" style="display:inline;" class="linksperpage"><input type="text" name="linksperpage" size="2" style="height:15px;"></form></div> | 1403 | $PAGE->assign('previous_page_url',$previous_page_url); |
1474 | HTML; | 1404 | $PAGE->assign('next_page_url',$next_page_url); |
1475 | $paging = '<div class="paging">'.$linksperpage.$paging.'</div>'; | 1405 | $PAGE->assign('page_current',$page); |
1476 | $linklist='<div id="linklist">'.$paging.$searched.'<ul>'.$linklist.'</ul>'.$paging.'</div>'; | 1406 | $PAGE->assign('page_max',$pagecount); |
1477 | return $linklist; | 1407 | $PAGE->assign('result_count',count($linksToDisplay)); |
1408 | $PAGE->assign('search_type',$search_type); | ||
1409 | $PAGE->assign('search_crits',$search_crits); | ||
1410 | $PAGE->assign('redirector',empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector']); // optional redirector URL | ||
1411 | $PAGE->assign('token',$token); | ||
1412 | $PAGE->assign('links',$linkDisp); | ||
1413 | return; | ||
1478 | } | 1414 | } |
1479 | 1415 | ||
1480 | // Returns the HTML code to display a thumbnail for a link | 1416 | // Returns the HTML code to display a thumbnail for a link |
1481 | // with a link to the original URL. | 1417 | // with a link to the original URL. |
1482 | // Understands various services (youtube.com...) | 1418 | // Understands various services (youtube.com...) |
1483 | // Input: $url = url for which the thumbnail must be found. | 1419 | // Input: $url = url for which the thumbnail must be found. |
1484 | // $href = if provided, this URL will be followed instead of $url | 1420 | // $href = if provided, this URL will be followed instead of $url |
1485 | function thumbnail($url,$href=false) | 1421 | function thumbnail($url,$href=false) |
1486 | { | 1422 | { |
1487 | if (!$GLOBALS['config']['ENABLE_THUMBNAILS']) return ''; | 1423 | if (!$GLOBALS['config']['ENABLE_THUMBNAILS']) return ''; |
1488 | 1424 | ||
1489 | if ($href==false) $href=$url; | 1425 | if ($href==false) $href=$url; |
1490 | 1426 | ||
1491 | // For most hosts, the URL of the thumbnail can be easily deduced from the URL of the link. | 1427 | // For most hosts, the URL of the thumbnail can be easily deduced from the URL of the link. |
1492 | // (eg. http://www.youtube.com/watch?v=spVypYk4kto ---> http://img.youtube.com/vi/spVypYk4kto/default.jpg ) | 1428 | // (eg. http://www.youtube.com/watch?v=spVypYk4kto ---> http://img.youtube.com/vi/spVypYk4kto/default.jpg ) |
1493 | // ^^^^^^^^^^^ ^^^^^^^^^^^ | 1429 | // ^^^^^^^^^^^ ^^^^^^^^^^^ |
@@ -1501,7 +1437,7 @@ function thumbnail($url,$href=false) | |||
1501 | { | 1437 | { |
1502 | $path = parse_url($url,PHP_URL_PATH); | 1438 | $path = parse_url($url,PHP_URL_PATH); |
1503 | return '<a href="'.htmlspecialchars($href).'"><img src="http://img.youtube.com/vi'.htmlspecialchars($path).'/default.jpg" width="120" height="90"></a>'; | 1439 | return '<a href="'.htmlspecialchars($href).'"><img src="http://img.youtube.com/vi'.htmlspecialchars($path).'/default.jpg" width="120" height="90"></a>'; |
1504 | } | 1440 | } |
1505 | if ($domain=='imgur.com') | 1441 | if ($domain=='imgur.com') |
1506 | { | 1442 | { |
1507 | $path = parse_url($url,PHP_URL_PATH); | 1443 | $path = parse_url($url,PHP_URL_PATH); |
@@ -1514,7 +1450,7 @@ function thumbnail($url,$href=false) | |||
1514 | { | 1450 | { |
1515 | $pi = pathinfo(parse_url($url,PHP_URL_PATH)); | 1451 | $pi = pathinfo(parse_url($url,PHP_URL_PATH)); |
1516 | if (!empty($pi['filename'])) return '<a href="'.htmlspecialchars($href).'"><img src="http://i.imgur.com/'.htmlspecialchars($pi['filename']).'s.jpg" width="90" height="90"></a>'; | 1452 | if (!empty($pi['filename'])) return '<a href="'.htmlspecialchars($href).'"><img src="http://i.imgur.com/'.htmlspecialchars($pi['filename']).'s.jpg" width="90" height="90"></a>'; |
1517 | } | 1453 | } |
1518 | if ($domain=='dailymotion.com' || $domain=='www.dailymotion.com') | 1454 | if ($domain=='dailymotion.com' || $domain=='www.dailymotion.com') |
1519 | { | 1455 | { |
1520 | if (strpos($url,'dailymotion.com/video/')!==false) | 1456 | if (strpos($url,'dailymotion.com/video/')!==false) |
@@ -1522,7 +1458,7 @@ function thumbnail($url,$href=false) | |||
1522 | $thumburl=str_replace('dailymotion.com/video/','dailymotion.com/thumbnail/video/',$url); | 1458 | $thumburl=str_replace('dailymotion.com/video/','dailymotion.com/thumbnail/video/',$url); |
1523 | return '<a href="'.htmlspecialchars($href).'"><img src="'.htmlspecialchars($thumburl).'" width="120" style="height:auto;"></a>'; | 1459 | return '<a href="'.htmlspecialchars($href).'"><img src="'.htmlspecialchars($thumburl).'" width="120" style="height:auto;"></a>'; |
1524 | } | 1460 | } |
1525 | } | 1461 | } |
1526 | if (endsWith($domain,'.imageshack.us')) | 1462 | if (endsWith($domain,'.imageshack.us')) |
1527 | { | 1463 | { |
1528 | $ext=strtolower(pathinfo($url,PATHINFO_EXTENSION)); | 1464 | $ext=strtolower(pathinfo($url,PATHINFO_EXTENSION)); |
@@ -1536,9 +1472,9 @@ function thumbnail($url,$href=false) | |||
1536 | // Some other hosts are SLOW AS HELL and usually require an extra HTTP request to get the thumbnail URL. | 1472 | // Some other hosts are SLOW AS HELL and usually require an extra HTTP request to get the thumbnail URL. |
1537 | // So we deport the thumbnail generation in order not to slow down page generation | 1473 | // So we deport the thumbnail generation in order not to slow down page generation |
1538 | // (and we also cache the thumbnail) | 1474 | // (and we also cache the thumbnail) |
1539 | 1475 | ||
1540 | if (!$GLOBALS['config']['ENABLE_LOCALCACHE']) return ''; // If local cache is disabled, no thumbnails for services which require the use a local cache. | 1476 | if (!$GLOBALS['config']['ENABLE_LOCALCACHE']) return ''; // If local cache is disabled, no thumbnails for services which require the use a local cache. |
1541 | 1477 | ||
1542 | if ($domain=='flickr.com' || endsWith($domain,'.flickr.com') | 1478 | if ($domain=='flickr.com' || endsWith($domain,'.flickr.com') |
1543 | || $domain=='vimeo.com' | 1479 | || $domain=='vimeo.com' |
1544 | || $domain=='ted.com' || endsWith($domain,'.ted.com') | 1480 | || $domain=='ted.com' || endsWith($domain,'.ted.com') |
@@ -1546,7 +1482,7 @@ function thumbnail($url,$href=false) | |||
1546 | { | 1482 | { |
1547 | if ($domain=='vimeo.com') | 1483 | if ($domain=='vimeo.com') |
1548 | { // Make sure this vimeo url points to a video (/xxx... where xxx is numeric) | 1484 | { // Make sure this vimeo url points to a video (/xxx... where xxx is numeric) |
1549 | $path = parse_url($url,PHP_URL_PATH); | 1485 | $path = parse_url($url,PHP_URL_PATH); |
1550 | if (!preg_match('!/\d+.+?!',$path)) return ''; // This is not a single video URL. | 1486 | if (!preg_match('!/\d+.+?!',$path)) return ''; // This is not a single video URL. |
1551 | } | 1487 | } |
1552 | if ($domain=='ted.com' || endsWith($domain,'.ted.com')) | 1488 | if ($domain=='ted.com' || endsWith($domain,'.ted.com')) |
@@ -1565,140 +1501,45 @@ function thumbnail($url,$href=false) | |||
1565 | if ($ext=='jpg' || $ext=='jpeg' || $ext=='png' || $ext=='gif') | 1501 | if ($ext=='jpg' || $ext=='jpeg' || $ext=='png' || $ext=='gif') |
1566 | { | 1502 | { |
1567 | $sign = hash_hmac('sha256', $url, $GLOBALS['salt']); // We use the salt to sign data (it's random, secret, and specific to each installation) | 1503 | $sign = hash_hmac('sha256', $url, $GLOBALS['salt']); // We use the salt to sign data (it's random, secret, and specific to each installation) |
1568 | return '<a href="'.htmlspecialchars($href).'"><img src="?do=genthumbnail&hmac='.htmlspecialchars($sign).'&url='.urlencode($url).'" width="120" style="height:auto;"></a>'; | 1504 | return '<a href="'.htmlspecialchars($href).'"><img src="?do=genthumbnail&hmac='.htmlspecialchars($sign).'&url='.urlencode($url).'" width="120" style="height:auto;"></a>'; |
1569 | } | 1505 | } |
1570 | return ''; // No thumbnail. | 1506 | return ''; // No thumbnail. |
1571 | 1507 | ||
1572 | } | 1508 | } |
1573 | 1509 | ||
1574 | // ----------------------------------------------------------------------------------------------- | 1510 | // ----------------------------------------------------------------------------------------------- |
1575 | // Template for the whole page. | ||
1576 | /* Input: $data (associative array). | ||
1577 | Keys: 'body' : body of HTML document | ||
1578 | 'pageheader' : html code to show in page header (top of page) | ||
1579 | 'onload' : optional onload javascript for the <body> | ||
1580 | */ | ||
1581 | function templatePage($data) | ||
1582 | { | ||
1583 | global $STARTTIME; | ||
1584 | global $LINKSDB; | ||
1585 | $shaarli_version = shaarli_version; | ||
1586 | |||
1587 | $newversion=checkUpdate(); | ||
1588 | if ($newversion!='') $newversion='<div id="newversion"><span style="text-decoration:blink;">●</span> Shaarli '.htmlspecialchars($newversion).' is <a href="http://sebsauvage.net/wiki/doku.php?id=php:shaarli#download">available</a>.</div>'; | ||
1589 | $linkcount = count($LINKSDB); | ||
1590 | |||
1591 | $feedurl=htmlspecialchars(serverUrl().$_SERVER['SCRIPT_NAME']); | ||
1592 | $searchcrits=''; // Search criteria | ||
1593 | if (!empty($_GET['searchtags'])) $searchcrits.='&searchtags='.$_GET['searchtags']; | ||
1594 | elseif (!empty($_GET['searchterm'])) $searchcrits.='&searchterm='.$_GET['searchterm']; | ||
1595 | $filtered_feed= ($searchcrits=='' ? '' : 'Filtered '); | ||
1596 | |||
1597 | $open=''; | ||
1598 | if ($GLOBALS['config']['OPEN_SHAARLI']) | ||
1599 | { | ||
1600 | $menu='<a href="?do=tools">Tools</a><a href="?do=addlink"><b>Add link</b></a>'; | ||
1601 | $open='Open '; | ||
1602 | } | ||
1603 | else | ||
1604 | $menu=(isLoggedIn() ? '<a href="?do=logout">Logout</a><a href="?do=tools">Tools</a><a href="?do=addlink"><b>Add link</b></a>' : ' <a href="?do=login">Login</a>'); | ||
1605 | $menu='<a href="?">Home</a>'.$menu.'<a href="'.$feedurl.'?do=rss'.$searchcrits.'">RSS Feed</a><a href="'.$feedurl.'?do=atom'.$searchcrits.'" style="padding-left:10px;">ATOM Feed</a><a href="?do=tagcloud">Tag cloud</a><a href="?do=picwall'.$searchcrits.'">Picture wall</a>'; | ||
1606 | # If we are in the bookmarklet popup, do not display menu. | ||
1607 | if (!empty($_GET['source']) && $_GET['source']=='bookmarklet') $menu=''; | ||
1608 | |||
1609 | foreach(array('pageheader','body','onload') as $k) // make sure all required fields exist (put an empty string if not). | ||
1610 | { | ||
1611 | if (!array_key_exists($k,$data)) $data[$k]=''; | ||
1612 | } | ||
1613 | $jsincludes=''; $jsincludes_bottom = ''; | ||
1614 | if ($GLOBALS['config']['OPEN_SHAARLI'] || isLoggedIn()) | ||
1615 | { | ||
1616 | $source = serverUrl().$_SERVER['SCRIPT_NAME']; | ||
1617 | $jsincludes='<script language="JavaScript" src="jquery.min.js"></script><script language="JavaScript" src="jquery-ui.custom.min.js"></script>'; | ||
1618 | $jsincludes_bottom = <<<JS | ||
1619 | <script language="JavaScript"> | ||
1620 | $(document).ready(function() | ||
1621 | { | ||
1622 | $('#lf_tags').autocomplete({source:'{$source}?ws=tags',minLength:1}); | ||
1623 | $('#searchtags').autocomplete({source:'{$source}?ws=tags',minLength:1}); | ||
1624 | $('#fromtag').autocomplete({source:'{$source}?ws=singletag',minLength:1}); | ||
1625 | }); | ||
1626 | </script> | ||
1627 | JS; | ||
1628 | } | ||
1629 | |||
1630 | $version=shaarli_version; | ||
1631 | |||
1632 | $title = htmlspecialchars( $GLOBALS['title'] ); | ||
1633 | $pagetitle = htmlspecialchars( empty($GLOBALS['pagetitle']) ? $title : $GLOBALS['pagetitle'] ); | ||
1634 | |||
1635 | echo <<<HTML | ||
1636 | <html> | ||
1637 | <head> | ||
1638 | <title>{$pagetitle}</title> | ||
1639 | <link rel="alternate" type="application/rss+xml" href="{$feedurl}?do=rss{$searchcrits}" title="{$filtered_feed}RSS Feed" /> | ||
1640 | <link rel="alternate" type="application/atom+xml" href="{$feedurl}?do=atom{$searchcrits}" title="{$filtered_feed}ATOM Feed" /> | ||
1641 | <link href="./images/favicon.ico" rel="shortcut icon" type="image/x-icon" /> | ||
1642 | <link type="text/css" rel="stylesheet" href="shaarli.css?version={$version}" /> | ||
1643 | <link type="text/css" rel="stylesheet" href="user.css?version={$version}" /> | ||
1644 | {$jsincludes} | ||
1645 | </head> | ||
1646 | <body {$data['onload']}>{$newversion} | ||
1647 | <div id="pageheader"><div id="logo" title="Share your links !" onclick="document.location='?';"></div><div style="float:right; font-style:italic; color:#bbb; text-align:right; padding:0 5 0 0;">Shaare your links...<br>{$linkcount} links</div> | ||
1648 | <span id="shaarli_title"><a href="?">{$title}</a></span>{$menu}<div class="clear"></div> | ||
1649 | {$data['pageheader']} | ||
1650 | </div> | ||
1651 | {$data['body']} | ||
1652 | |||
1653 | HTML; | ||
1654 | $exectime = round(microtime(true)-$STARTTIME,4); | ||
1655 | echo '<div id="footer"><b><a href="http://sebsauvage.net/wiki/doku.php?id=php:shaarli">Shaarli '.shaarli_version.'</a></b> - The personal, minimalist, super-fast, no-database delicious clone. By <a href="http://sebsauvage.net" target="_blank">sebsauvage.net</a>. Theme by <a href="http://blog.idleman.fr" target="_blank">idleman.fr</a>.<br>Who gives a shit that this page was generated in '.$exectime.' seconds ?</div>'; | ||
1656 | if (isLoggedIn()) echo '<script language="JavaScript">function confirmDeleteLink() { var agree=confirm("Are you sure you want to delete this link ?"); if (agree) return true ; else return false ; }</script>'; | ||
1657 | echo $jsincludes_bottom.'</body></html>'; | ||
1658 | } | ||
1659 | |||
1660 | // ----------------------------------------------------------------------------------------------- | ||
1661 | // Installation | 1511 | // Installation |
1662 | // This function should NEVER be called if the file data/config.php exists. | 1512 | // This function should NEVER be called if the file data/config.php exists. |
1663 | function install() | 1513 | function install() |
1664 | { | 1514 | { |
1665 | // On free.fr host, make sure the /sessions directory exists, otherwise login will not work. | 1515 | // On free.fr host, make sure the /sessions directory exists, otherwise login will not work. |
1666 | if (endsWith($_SERVER['SERVER_NAME'],'.free.fr') && !is_dir($_SERVER['DOCUMENT_ROOT'].'/sessions')) mkdir($_SERVER['DOCUMENT_ROOT'].'/sessions',0705); | 1516 | if (endsWith($_SERVER['SERVER_NAME'],'.free.fr') && !is_dir($_SERVER['DOCUMENT_ROOT'].'/sessions')) mkdir($_SERVER['DOCUMENT_ROOT'].'/sessions',0705); |
1667 | 1517 | ||
1668 | if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) | 1518 | if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) |
1669 | { | 1519 | { |
1670 | $tz = 'UTC'; | 1520 | $tz = 'UTC'; |
1671 | if (!empty($_POST['continent']) && !empty($_POST['city'])) | 1521 | if (!empty($_POST['continent']) && !empty($_POST['city'])) |
1672 | if (isTZvalid($_POST['continent'],$_POST['city'])) | 1522 | if (isTZvalid($_POST['continent'],$_POST['city'])) |
1673 | $tz = $_POST['continent'].'/'.$_POST['city']; | 1523 | $tz = $_POST['continent'].'/'.$_POST['city']; |
1674 | $GLOBALS['timezone'] = $tz; | 1524 | $GLOBALS['timezone'] = $tz; |
1675 | // Everything is ok, let's create config file. | 1525 | // Everything is ok, let's create config file. |
1676 | $GLOBALS['login'] = $_POST['setlogin']; | 1526 | $GLOBALS['login'] = $_POST['setlogin']; |
1677 | $GLOBALS['salt'] = sha1(uniqid('',true).'_'.mt_rand()); // Salt renders rainbow-tables attacks useless. | 1527 | $GLOBALS['salt'] = sha1(uniqid('',true).'_'.mt_rand()); // Salt renders rainbow-tables attacks useless. |
1678 | $GLOBALS['hash'] = sha1($_POST['setpassword'].$GLOBALS['login'].$GLOBALS['salt']); | 1528 | $GLOBALS['hash'] = sha1($_POST['setpassword'].$GLOBALS['login'].$GLOBALS['salt']); |
1679 | $GLOBALS['title'] = (empty($_POST['title']) ? 'Shared links on '.htmlspecialchars(serverUrl().$_SERVER['SCRIPT_NAME']) : $_POST['title'] ); | 1529 | $GLOBALS['title'] = (empty($_POST['title']) ? 'Shared links on '.htmlspecialchars(indexUrl()) : $_POST['title'] ); |
1680 | writeConfig(); | 1530 | writeConfig(); |
1681 | echo '<script language="JavaScript">alert("Shaarli is now configured. Please enter your login/password and start shaaring your links !");document.location=\'?do=login\';</script>'; | 1531 | echo '<script language="JavaScript">alert("Shaarli is now configured. Please enter your login/password and start shaaring your links !");document.location=\'?do=login\';</script>'; |
1682 | exit; | 1532 | exit; |
1683 | } | 1533 | } |
1684 | 1534 | ||
1685 | // Display config form: | 1535 | // Display config form: |
1686 | list($timezone_form,$timezone_js) = templateTZform(); | 1536 | list($timezone_form,$timezone_js) = templateTZform(); |
1687 | $timezone_html=''; if ($timezone_form!='') $timezone_html='<tr><td valign="top"><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>'; | 1537 | $timezone_html=''; if ($timezone_form!='') $timezone_html='<tr><td valign="top"><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>'; |
1688 | echo <<<HTML | 1538 | |
1689 | <html><head><title>Shaarli - Configuration</title><link type="text/css" rel="stylesheet" href="shaarli.css" />${timezone_js}</head> | 1539 | $PAGE = new pageBuilder; |
1690 | <body onload="document.installform.setlogin.focus();" style="padding:20px;"><h1>Shaarli - Shaare your links...</h1> | 1540 | $PAGE->assign('timezone_html',$timezone_html); |
1691 | It looks like it's the first time you run Shaarli. Please configure it:<br> | 1541 | $PAGE->assign('timezone_js',$timezone_js); |
1692 | <form method="POST" action="" name="installform" id="installform" style="border:1px solid black; padding:10 10 10 10;"> | 1542 | $PAGE->renderPage('install'); |
1693 | <table border="0" cellpadding="20"> | ||
1694 | <tr><td><b>Login:</b></td><td><input type="text" name="setlogin" size="30"></td></tr> | ||
1695 | <tr><td><b>Password:</b></td><td><input type="password" name="setpassword" size="30"></td></tr> | ||
1696 | {$timezone_html} | ||
1697 | <tr><td><b>Page title:</b></td><td><input type="text" name="title" size="30"></td></tr> | ||
1698 | <tr><td></td><td align="right"><input type="submit" name="Save" value="Save config" class="bigbutton"></td></tr> | ||
1699 | </table> | ||
1700 | </form></body></html> | ||
1701 | HTML; | ||
1702 | exit; | 1543 | exit; |
1703 | } | 1544 | } |
1704 | 1545 | ||
@@ -1714,7 +1555,7 @@ function templateTZform($ptz=false) | |||
1714 | // Try to split the provided timezone. | 1555 | // Try to split the provided timezone. |
1715 | if ($ptz==false) { $l=timezone_identifiers_list(); $ptz=$l[0]; } | 1556 | if ($ptz==false) { $l=timezone_identifiers_list(); $ptz=$l[0]; } |
1716 | $spos=strpos($ptz,'/'); $pcontinent=substr($ptz,0,$spos); $pcity=substr($ptz,$spos+1); | 1557 | $spos=strpos($ptz,'/'); $pcontinent=substr($ptz,0,$spos); $pcity=substr($ptz,$spos+1); |
1717 | 1558 | ||
1718 | // Display config form: | 1559 | // Display config form: |
1719 | $timezone_form = ''; | 1560 | $timezone_form = ''; |
1720 | $timezone_js = ''; | 1561 | $timezone_js = ''; |
@@ -1722,7 +1563,7 @@ function templateTZform($ptz=false) | |||
1722 | // We split the list in continents/cities. | 1563 | // We split the list in continents/cities. |
1723 | $continents = array(); | 1564 | $continents = array(); |
1724 | $cities = array(); | 1565 | $cities = array(); |
1725 | foreach(timezone_identifiers_list() as $tz) | 1566 | foreach(timezone_identifiers_list() as $tz) |
1726 | { | 1567 | { |
1727 | if ($tz=='UTC') $tz='UTC/UTC'; | 1568 | if ($tz=='UTC') $tz='UTC/UTC'; |
1728 | $spos = strpos($tz,'/'); | 1569 | $spos = strpos($tz,'/'); |
@@ -1737,12 +1578,12 @@ function templateTZform($ptz=false) | |||
1737 | $continents_html = ''; | 1578 | $continents_html = ''; |
1738 | $continents = array_keys($continents); | 1579 | $continents = array_keys($continents); |
1739 | foreach($continents as $continent) | 1580 | foreach($continents as $continent) |
1740 | $continents_html.='<option value="'.$continent.'"'.($pcontinent==$continent?'selected':'').'>'.$continent.'</option>'; | 1581 | $continents_html.='<option value="'.$continent.'"'.($pcontinent==$continent?'selected':'').'>'.$continent.'</option>'; |
1741 | $cities_html = $cities[$pcontinent]; | 1582 | $cities_html = $cities[$pcontinent]; |
1742 | $timezone_form = "Continent: <select name=\"continent\" id=\"continent\" onChange=\"onChangecontinent();\">${continents_html}</select><br /><br />"; | 1583 | $timezone_form = "Continent: <select name=\"continent\" id=\"continent\" onChange=\"onChangecontinent();\">${continents_html}</select><br /><br />"; |
1743 | $timezone_form .= "City: <select name=\"city\" id=\"city\">${cities[$pcontinent]}</select><br /><br />"; | 1584 | $timezone_form .= "City: <select name=\"city\" id=\"city\">${cities[$pcontinent]}</select><br /><br />"; |
1744 | $timezone_js = "<script language=\"JavaScript\">"; | 1585 | $timezone_js = "<script language=\"JavaScript\">"; |
1745 | $timezone_js .= "function onChangecontinent(){document.getElementById(\"city\").innerHTML = citiescontinent[document.getElementById(\"continent\").value];}"; | 1586 | $timezone_js .= "function onChangecontinent(){document.getElementById(\"city\").innerHTML = citiescontinent[document.getElementById(\"continent\").value];}"; |
1746 | $timezone_js .= "var citiescontinent = ".json_encode($cities).";" ; | 1587 | $timezone_js .= "var citiescontinent = ".json_encode($cities).";" ; |
1747 | $timezone_js .= "</script>" ; | 1588 | $timezone_js .= "</script>" ; |
1748 | return array($timezone_form,$timezone_js); | 1589 | return array($timezone_form,$timezone_js); |
@@ -1776,32 +1617,32 @@ function processWS() | |||
1776 | 1617 | ||
1777 | // Search in tags (case insentitive, cumulative search) | 1618 | // Search in tags (case insentitive, cumulative search) |
1778 | if ($_GET['ws']=='tags') | 1619 | if ($_GET['ws']=='tags') |
1779 | { | 1620 | { |
1780 | $tags=explode(' ',str_replace(',',' ',$term)); $last = array_pop($tags); // Get the last term ("a b c d" ==> "a b c", "d") | 1621 | $tags=explode(' ',str_replace(',',' ',$term)); $last = array_pop($tags); // Get the last term ("a b c d" ==> "a b c", "d") |
1781 | $addtags=''; if ($tags) $addtags=implode(' ',$tags).' '; // We will pre-pend previous tags | 1622 | $addtags=''; if ($tags) $addtags=implode(' ',$tags).' '; // We will pre-pend previous tags |
1782 | $suggested=array(); | 1623 | $suggested=array(); |
1783 | /* To speed up things, we store list of tags in session */ | 1624 | /* To speed up things, we store list of tags in session */ |
1784 | if (empty($_SESSION['tags'])) $_SESSION['tags'] = $LINKSDB->allTags(); | 1625 | if (empty($_SESSION['tags'])) $_SESSION['tags'] = $LINKSDB->allTags(); |
1785 | foreach($_SESSION['tags'] as $key=>$value) | 1626 | foreach($_SESSION['tags'] as $key=>$value) |
1786 | { | 1627 | { |
1787 | if (startsWith($key,$last,$case=false) && !in_array($key,$tags)) $suggested[$addtags.$key.' ']=0; | 1628 | if (startsWith($key,$last,$case=false) && !in_array($key,$tags)) $suggested[$addtags.$key.' ']=0; |
1788 | } | 1629 | } |
1789 | echo json_encode(array_keys($suggested)); | 1630 | echo json_encode(array_keys($suggested)); |
1790 | exit; | 1631 | exit; |
1791 | } | 1632 | } |
1792 | 1633 | ||
1793 | // Search a single tag (case sentitive, single tag search) | 1634 | // Search a single tag (case sentitive, single tag search) |
1794 | if ($_GET['ws']=='singletag') | 1635 | if ($_GET['ws']=='singletag') |
1795 | { | 1636 | { |
1796 | /* To speed up things, we store list of tags in session */ | 1637 | /* To speed up things, we store list of tags in session */ |
1797 | if (empty($_SESSION['tags'])) $_SESSION['tags'] = $LINKSDB->allTags(); | 1638 | if (empty($_SESSION['tags'])) $_SESSION['tags'] = $LINKSDB->allTags(); |
1798 | foreach($_SESSION['tags'] as $key=>$value) | 1639 | foreach($_SESSION['tags'] as $key=>$value) |
1799 | { | 1640 | { |
1800 | if (startsWith($key,$term,$case=true)) $suggested[$key]=0; | 1641 | if (startsWith($key,$term,$case=true)) $suggested[$key]=0; |
1801 | } | 1642 | } |
1802 | echo json_encode(array_keys($suggested)); | 1643 | echo json_encode(array_keys($suggested)); |
1803 | exit; | 1644 | exit; |
1804 | } | 1645 | } |
1805 | } | 1646 | } |
1806 | 1647 | ||
1807 | // Re-write configuration file according to globals. | 1648 | // Re-write configuration file according to globals. |
@@ -1815,7 +1656,7 @@ function writeConfig() | |||
1815 | $config='<?php $GLOBALS[\'login\']='.var_export($GLOBALS['login'],true).'; $GLOBALS[\'hash\']='.var_export($GLOBALS['hash'],true).'; $GLOBALS[\'salt\']='.var_export($GLOBALS['salt'],true).'; '; | 1656 | $config='<?php $GLOBALS[\'login\']='.var_export($GLOBALS['login'],true).'; $GLOBALS[\'hash\']='.var_export($GLOBALS['hash'],true).'; $GLOBALS[\'salt\']='.var_export($GLOBALS['salt'],true).'; '; |
1816 | $config .='$GLOBALS[\'timezone\']='.var_export($GLOBALS['timezone'],true).'; date_default_timezone_set('.var_export($GLOBALS['timezone'],true).'); $GLOBALS[\'title\']='.var_export($GLOBALS['title'],true).';'; | 1657 | $config .='$GLOBALS[\'timezone\']='.var_export($GLOBALS['timezone'],true).'; date_default_timezone_set('.var_export($GLOBALS['timezone'],true).'); $GLOBALS[\'title\']='.var_export($GLOBALS['title'],true).';'; |
1817 | $config .= '$GLOBALS[\'redirector\']='.var_export($GLOBALS['redirector'],true).'; '; | 1658 | $config .= '$GLOBALS[\'redirector\']='.var_export($GLOBALS['redirector'],true).'; '; |
1818 | $config .= ' ?>'; | 1659 | $config .= ' ?>'; |
1819 | if (!file_put_contents($GLOBALS['config']['CONFIG_FILE'],$config) || strcmp(file_get_contents($GLOBALS['config']['CONFIG_FILE']),$config)!=0) | 1660 | if (!file_put_contents($GLOBALS['config']['CONFIG_FILE'],$config) || strcmp(file_get_contents($GLOBALS['config']['CONFIG_FILE']),$config)!=0) |
1820 | { | 1661 | { |
1821 | echo '<script language="JavaScript">alert("Shaarli could not create the config file. Please make sure Shaarli has the right to write in the folder is it installed in.");document.location=\'?\';</script>'; | 1662 | echo '<script language="JavaScript">alert("Shaarli could not create the config file. Please make sure Shaarli has the right to write in the folder is it installed in.");document.location=\'?\';</script>'; |
@@ -1836,14 +1677,14 @@ function genThumbnail() | |||
1836 | { | 1677 | { |
1837 | // Make sure the parameters in the URL were generated by us. | 1678 | // Make sure the parameters in the URL were generated by us. |
1838 | $sign = hash_hmac('sha256', $_GET['url'], $GLOBALS['salt']); | 1679 | $sign = hash_hmac('sha256', $_GET['url'], $GLOBALS['salt']); |
1839 | if ($sign!=$_GET['hmac']) die('Naughty boy !'); | 1680 | if ($sign!=$_GET['hmac']) die('Naughty boy !'); |
1840 | 1681 | ||
1841 | // Let's see if we don't already have the image for this URL in the cache. | 1682 | // Let's see if we don't already have the image for this URL in the cache. |
1842 | $thumbname=hash('sha1',$_GET['url']).'.jpg'; | 1683 | $thumbname=hash('sha1',$_GET['url']).'.jpg'; |
1843 | if (is_file($GLOBALS['config']['CACHEDIR'].'/'.$thumbname)) | 1684 | if (is_file($GLOBALS['config']['CACHEDIR'].'/'.$thumbname)) |
1844 | { // We have the thumbnail, just serve it: | 1685 | { // We have the thumbnail, just serve it: |
1845 | header('Content-Type: image/jpeg'); | 1686 | header('Content-Type: image/jpeg'); |
1846 | echo file_get_contents($GLOBALS['config']['CACHEDIR'].'/'.$thumbname); | 1687 | echo file_get_contents($GLOBALS['config']['CACHEDIR'].'/'.$thumbname); |
1847 | return; | 1688 | return; |
1848 | } | 1689 | } |
1849 | // We may also serve a blank image (if service did not respond) | 1690 | // We may also serve a blank image (if service did not respond) |
@@ -1851,16 +1692,16 @@ function genThumbnail() | |||
1851 | if (is_file($GLOBALS['config']['CACHEDIR'].'/'.$blankname)) | 1692 | if (is_file($GLOBALS['config']['CACHEDIR'].'/'.$blankname)) |
1852 | { | 1693 | { |
1853 | header('Content-Type: image/gif'); | 1694 | header('Content-Type: image/gif'); |
1854 | echo file_get_contents($GLOBALS['config']['CACHEDIR'].'/'.$blankname); | 1695 | echo file_get_contents($GLOBALS['config']['CACHEDIR'].'/'.$blankname); |
1855 | return; | 1696 | return; |
1856 | } | 1697 | } |
1857 | 1698 | ||
1858 | // Otherwise, generate the thumbnail. | 1699 | // Otherwise, generate the thumbnail. |
1859 | $url = $_GET['url']; | 1700 | $url = $_GET['url']; |
1860 | $domain = parse_url($url,PHP_URL_HOST); | 1701 | $domain = parse_url($url,PHP_URL_HOST); |
1861 | 1702 | ||
1862 | if ($domain=='flickr.com' || endsWith($domain,'.flickr.com')) | 1703 | if ($domain=='flickr.com' || endsWith($domain,'.flickr.com')) |
1863 | { | 1704 | { |
1864 | // WTF ? I need a flickr API key to get a fucking thumbnail ? No way. | 1705 | // WTF ? I need a flickr API key to get a fucking thumbnail ? No way. |
1865 | // I'll extract the thumbnail URL myself. First, we have to get the flickr HTML page. | 1706 | // I'll extract the thumbnail URL myself. First, we have to get the flickr HTML page. |
1866 | // All images in Flickr are in the form: | 1707 | // All images in Flickr are in the form: |
@@ -1875,7 +1716,7 @@ function genThumbnail() | |||
1875 | if (endswith(parse_url($url,PHP_URL_PATH),'.jpg')) | 1716 | if (endswith(parse_url($url,PHP_URL_PATH),'.jpg')) |
1876 | { // This is a direct link to an image. eg. http://farm1.static.flickr.com/5/5921913_ac83ed27bd_o.jpg | 1717 | { // This is a direct link to an image. eg. http://farm1.static.flickr.com/5/5921913_ac83ed27bd_o.jpg |
1877 | preg_match('!(http://farm\d+.static.flickr.com/\d+/\d+_\w+_)\w.jpg!',$url,$matches); | 1718 | preg_match('!(http://farm\d+.static.flickr.com/\d+/\d+_\w+_)\w.jpg!',$url,$matches); |
1878 | if (!empty($matches[1])) $imageurl=$matches[1].'m.jpg'; | 1719 | if (!empty($matches[1])) $imageurl=$matches[1].'m.jpg'; |
1879 | } | 1720 | } |
1880 | else // this is a flickr page (html) | 1721 | else // this is a flickr page (html) |
1881 | { | 1722 | { |
@@ -1883,7 +1724,7 @@ function genThumbnail() | |||
1883 | if (strpos($httpstatus,'200 OK')!==false) | 1724 | if (strpos($httpstatus,'200 OK')!==false) |
1884 | { | 1725 | { |
1885 | preg_match('!(http://farm\d+.static.flickr.com/\d+/\d+_\w+_)[^s].jpg!',$data,$matches); | 1726 | preg_match('!(http://farm\d+.static.flickr.com/\d+/\d+_\w+_)[^s].jpg!',$data,$matches); |
1886 | if (!empty($matches[1])) $imageurl=$matches[1].'m.jpg'; | 1727 | if (!empty($matches[1])) $imageurl=$matches[1].'m.jpg'; |
1887 | } | 1728 | } |
1888 | } | 1729 | } |
1889 | if ($imageurl!='') | 1730 | if ($imageurl!='') |
@@ -1896,7 +1737,7 @@ function genThumbnail() | |||
1896 | echo $data; | 1737 | echo $data; |
1897 | return; | 1738 | return; |
1898 | } | 1739 | } |
1899 | } | 1740 | } |
1900 | } | 1741 | } |
1901 | 1742 | ||
1902 | elseif ($domain=='vimeo.com' ) | 1743 | elseif ($domain=='vimeo.com' ) |
@@ -1917,8 +1758,8 @@ function genThumbnail() | |||
1917 | header('Content-Type: image/jpeg'); | 1758 | header('Content-Type: image/jpeg'); |
1918 | echo $data; | 1759 | echo $data; |
1919 | return; | 1760 | return; |
1920 | } | 1761 | } |
1921 | } | 1762 | } |
1922 | } | 1763 | } |
1923 | 1764 | ||
1924 | elseif ($domain=='ted.com' || endsWith($domain,'.ted.com')) | 1765 | elseif ($domain=='ted.com' || endsWith($domain,'.ted.com')) |
@@ -1942,14 +1783,14 @@ function genThumbnail() | |||
1942 | if (resizeImage($filepath)) | 1783 | if (resizeImage($filepath)) |
1943 | { | 1784 | { |
1944 | header('Content-Type: image/jpeg'); | 1785 | header('Content-Type: image/jpeg'); |
1945 | echo file_get_contents($filepath); | 1786 | echo file_get_contents($filepath); |
1946 | return; | 1787 | return; |
1947 | } | 1788 | } |
1948 | } | 1789 | } |
1949 | } | 1790 | } |
1950 | } | 1791 | } |
1951 | } | 1792 | } |
1952 | 1793 | ||
1953 | else | 1794 | else |
1954 | { | 1795 | { |
1955 | // For all other domains, we try to download the image and make a thumbnail. | 1796 | // For all other domains, we try to download the image and make a thumbnail. |
@@ -1961,7 +1802,7 @@ function genThumbnail() | |||
1961 | if (resizeImage($filepath)) | 1802 | if (resizeImage($filepath)) |
1962 | { | 1803 | { |
1963 | header('Content-Type: image/jpeg'); | 1804 | header('Content-Type: image/jpeg'); |
1964 | echo file_get_contents($filepath); | 1805 | echo file_get_contents($filepath); |
1965 | return; | 1806 | return; |
1966 | } | 1807 | } |
1967 | } | 1808 | } |
@@ -2014,11 +1855,11 @@ function invalidateCaches() | |||
2014 | unset($_SESSION['tags']); | 1855 | unset($_SESSION['tags']); |
2015 | } | 1856 | } |
2016 | 1857 | ||
2017 | if (startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. | 1858 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. |
2018 | $LINKSDB=new linkdb(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in). | 1859 | $LINKSDB=new linkdb(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']); // Read links from database (and filter private links if used it not logged in). |
2019 | if (startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI) | 1860 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'ws=')) { processWS(); exit; } // Webservices (for jQuery/jQueryUI) |
2020 | if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE']; | 1861 | if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE']; |
2021 | if (startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; } | 1862 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; } |
2022 | if (startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; } | 1863 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; } |
2023 | renderPage(); | 1864 | renderPage(); |
2024 | ?> \ No newline at end of file | 1865 | ?> |
diff --git a/tpl/addlink.html b/tpl/addlink.html new file mode 100644 index 00000000..7dd767cc --- /dev/null +++ b/tpl/addlink.html | |||
@@ -0,0 +1,15 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body onload="document.addform.post.focus();"> | ||
4 | <div id="pageheader"> | ||
5 | {include="page.header"} | ||
6 | <div id="headerform"> | ||
7 | <form method="GET" action="" name="addform" class="addform"> | ||
8 | <input type="text" name="post" style="width:50%;"> | ||
9 | <input type="submit" value="Add link" class="bigbutton"> | ||
10 | </form> | ||
11 | </div> | ||
12 | </div> | ||
13 | {include="page.footer"} | ||
14 | </body> | ||
15 | </html> \ No newline at end of file | ||
diff --git a/tpl/changepassword.html b/tpl/changepassword.html new file mode 100644 index 00000000..acd61f55 --- /dev/null +++ b/tpl/changepassword.html | |||
@@ -0,0 +1,14 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body onload="document.changepasswordform.oldpassword.focus();"> | ||
4 | <div id="pageheader"> | ||
5 | {include="page.header"} | ||
6 | <form method="POST" action="" name="changepasswordform" id="changepasswordform"> | ||
7 | Old password: <input type="password" name="oldpassword"> | ||
8 | New password: <input type="password" name="setpassword"> | ||
9 | <input type="hidden" name="token" value="{$token}"> | ||
10 | <input type="submit" name="Save" value="Save password" class="bigbutton"></form> | ||
11 | </div> | ||
12 | {include="page.footer"} | ||
13 | </body> | ||
14 | </html> \ No newline at end of file | ||
diff --git a/tpl/changetag.html b/tpl/changetag.html new file mode 100644 index 00000000..a8ecfb4f --- /dev/null +++ b/tpl/changetag.html | |||
@@ -0,0 +1,15 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body onload="document.changetag.fromtag.focus();"> | ||
4 | <div id="pageheader"> | ||
5 | {include="page.header"} | ||
6 | <form method="POST" action="" name="changetag" id="changetag"> | ||
7 | <input type="hidden" name="token" value="{$token}"> | ||
8 | Tag: <input type="text" name="fromtag" id="fromtag"> | ||
9 | <input type="text" name="totag" style="margin-left:40px;"><input type="submit" name="renametag" value="Rename tag" class="bigbutton"> | ||
10 | or <input type="submit" name="deletetag" value="Delete tag" class="bigbutton" onClick="return confirmDeleteTag();"><br>(Case sensitive)</form> | ||
11 | <script language="JavaScript">function confirmDeleteTag() { var agree=confirm("Are you sure you want to delete this tag from all links ?"); if (agree) return true ; else return false ; }</script> | ||
12 | </div> | ||
13 | {include="page.footer"} | ||
14 | </body> | ||
15 | </html> \ No newline at end of file | ||
diff --git a/tpl/configure.html b/tpl/configure.html new file mode 100644 index 00000000..f13ecb9a --- /dev/null +++ b/tpl/configure.html | |||
@@ -0,0 +1,19 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body onload="document.configform.title.focus();"> | ||
4 | <div id="pageheader"> | ||
5 | {include="page.header"} | ||
6 | {$timezone_js} | ||
7 | <form method="POST" action="" name="configform" id="configform"> | ||
8 | <input type="hidden" name="token" value="{$token}"> | ||
9 | <table border="0" cellpadding="20"> | ||
10 | <tr><td><b>Page title:</b></td><td><input type="text" name="title" id="title" size="50" value="{$title}"></td></tr> | ||
11 | <tr><td valign="top"><b>Timezone:</b></td><td>{$timezone_form}</td></tr> | ||
12 | <tr><td valign="top"><b>Redirector</b></td><td><input type="text" name="redirector" id="redirector" size="50" value="{$redirector}"><br>(e.g. <i>http://anonym.to/?</i> will mask the HTTP_REFERER)</td></tr> | ||
13 | <tr><td></td><td align="right"><input type="submit" name="Save" value="Save config" class="bigbutton"></td></tr> | ||
14 | </table> | ||
15 | </form> | ||
16 | </div> | ||
17 | {include="page.footer"} | ||
18 | </body> | ||
19 | </html> \ No newline at end of file | ||
diff --git a/tpl/editlink.html b/tpl/editlink.html new file mode 100644 index 00000000..2225fbab --- /dev/null +++ b/tpl/editlink.html | |||
@@ -0,0 +1,27 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body | ||
4 | {if condition="$link.title==''"}onload="document.linkform.lf_title.focus();" | ||
5 | {elseif condition="$link.description==''"}onload="document.linkform.lf_description.focus();" | ||
6 | {else}onload="document.linkform.lf_tags.focus();"{/if} > | ||
7 | <div id="pageheader"> | ||
8 | {include="page.header"} | ||
9 | <div id="editlinkform"> | ||
10 | <form method="post" name="linkform"> | ||
11 | <input type="hidden" name="lf_linkdate" value="{$link.linkdate}"> | ||
12 | <i>URL</i><br><input type="text" name="lf_url" value="{$link.url|htmlspecialchars}" style="width:100%"><br> | ||
13 | <i>Title</i><br><input type="text" name="lf_title" value="{$link.title|htmlspecialchars}" style="width:100%"><br> | ||
14 | <i>Description</i><br><textarea name="lf_description" rows="4" cols="25" style="width:100%">{$link.description|htmlspecialchars}</textarea><br> | ||
15 | <i>Tags</i><br><input type="text" id="lf_tags" name="lf_tags" value="{$link.tags|htmlspecialchars}" style="width:100%"><br> | ||
16 | <input type="checkbox" {if condition="$link.private!=0"}checked="yes"{/if} style="margin:7 0 10 0;" name="lf_private"> <i>Private</i><br> | ||
17 | <input type="submit" value="Save" name="save_edit" class="bigbutton" style="margin-left:40px;"> | ||
18 | <input type="submit" value="Cancel" name="cancel_edit" class="bigbutton" style="margin-left:40px;"> | ||
19 | {if condition="!$link_is_new"}<input type="submit" value="Delete" name="delete_link" class="bigbutton" style="margin-left:180px;" onClick="return confirmDeleteLink();">{/if} | ||
20 | <input type="hidden" name="token" value="{$token}"> | ||
21 | {if condition="$http_referer"}<input type="hidden" name="returnurl" value="{$http_referer|htmlspecialchars}">{/if} | ||
22 | </form> | ||
23 | </div> | ||
24 | </div> | ||
25 | {include="page.footer"} | ||
26 | </body> | ||
27 | </html> \ No newline at end of file | ||
diff --git a/tpl/export.html b/tpl/export.html new file mode 100644 index 00000000..ccfcfcf1 --- /dev/null +++ b/tpl/export.html | |||
@@ -0,0 +1,14 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body> | ||
4 | <div id="pageheader"> | ||
5 | {include="page.header"} | ||
6 | <div id="toolsdiv"> | ||
7 | <a href="?do=export&what=all"><b>Export all</b> <span>: Export all links</span></a><br><br> | ||
8 | <a href="?do=export&what=public"><b>Export public</b> <span>: Export public links only</a><br><br> | ||
9 | <a href="?do=export&what=private"><b>Export private</b> <span>: Export private links only</a><br><br style="clear:both;"> | ||
10 | </div> | ||
11 | </div> | ||
12 | {include="page.footer"} | ||
13 | </body> | ||
14 | </html> \ No newline at end of file | ||
diff --git a/tpl/import.html b/tpl/import.html new file mode 100644 index 00000000..95df723e --- /dev/null +++ b/tpl/import.html | |||
@@ -0,0 +1,20 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body onload="document.uploadform.filetoupload.focus();"> | ||
4 | <div id="pageheader"> | ||
5 | {include="page.header"} | ||
6 | <div id="uploaddiv"> | ||
7 | Import Netscape html bookmarks (as exported from Firefox/Chrome/Opera/delicious/diigo...) (Max: {$maxfilesize|htmlspecialchars} bytes). | ||
8 | <form method="POST" action="?do=upload" enctype="multipart/form-data" name="uploadform" id="uploadform"> | ||
9 | <input type="hidden" name="token" value="{$token}"> | ||
10 | <input type="file" name="filetoupload" size="80"> | ||
11 | <input type="hidden" name="MAX_FILE_SIZE" value="{$maxfilesize|htmlspecialchars}"> | ||
12 | <input type="submit" name="import_file" value="Import" class="bigbutton"><br> | ||
13 | <input type="checkbox" name="private" id="private"><label for="private"> Import all links as private</label><br> | ||
14 | <input type="checkbox" name="overwrite" id="overwrite"><label for="overwrite"> Overwrite existing links</label> | ||
15 | </form> | ||
16 | </div> | ||
17 | </div> | ||
18 | {include="page.footer"} | ||
19 | </body> | ||
20 | </html> \ No newline at end of file | ||
diff --git a/tpl/includes.html b/tpl/includes.html new file mode 100644 index 00000000..c70b44e3 --- /dev/null +++ b/tpl/includes.html | |||
@@ -0,0 +1,7 @@ | |||
1 | <title>{$pagetitle}</title> | ||
2 | <link rel="alternate" type="application/rss+xml" href="{$feedurl}?do=rss{$searchcrits}#" title="RSS Feed" /> | ||
3 | <link rel="alternate" type="application/atom+xml" href="{$feedurl}?do=atom{$searchcrits}#" title="ATOM Feed" /> | ||
4 | <link href="images/favicon.ico#" rel="shortcut icon" type="image/x-icon" /> | ||
5 | <link type="text/css" rel="stylesheet" href="inc/shaarli.css?version={$version}#" /> | ||
6 | {if condition="is_file('inc/user.css')"}<link type="text/css" rel="stylesheet" href="inc/user.css?version={$version}#" />{/if} | ||
7 | <script language="JavaScript" src="inc/jquery.min.js#"></script><script language="JavaScript" src="inc/jquery-ui.custom.min.js#"></script> | ||
diff --git a/tpl/install.html b/tpl/install.html new file mode 100644 index 00000000..1e48a185 --- /dev/null +++ b/tpl/install.html | |||
@@ -0,0 +1,20 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}{$timezone_js}</head> | ||
3 | <body onload="document.installform.setlogin.focus();"> | ||
4 | <div style="margin-left:20px;"> | ||
5 | <h1>Shaarli</h1> | ||
6 | It looks like it's the first time you run Shaarli. Please configure it:<br> | ||
7 | <div style="color:white !important;"> | ||
8 | <form method="POST" action="" name="installform" id="installform" style="border:1px solid black; padding:10 10 10 10;"> | ||
9 | <table border="0" cellpadding="20"> | ||
10 | <tr><td><b>Login:</b></td><td><input type="text" name="setlogin" size="30"></td></tr> | ||
11 | <tr><td><b>Password:</b></td><td><input type="password" name="setpassword" size="30"></td></tr> | ||
12 | {$timezone_html} | ||
13 | <tr><td><b>Page title:</b></td><td><input type="text" name="title" size="30"></td></tr> | ||
14 | <tr><td></td><td align="right"><input type="submit" name="Save" value="Save config" class="bigbutton"></td></tr> | ||
15 | </table> | ||
16 | </form> | ||
17 | </div> | ||
18 | {include="page.footer"} | ||
19 | </body> | ||
20 | </html> \ No newline at end of file | ||
diff --git a/tpl/linklist.html b/tpl/linklist.html new file mode 100644 index 00000000..c7de5b87 --- /dev/null +++ b/tpl/linklist.html | |||
@@ -0,0 +1,61 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body> | ||
4 | <div id="pageheader"> | ||
5 | {include="page.header"} | ||
6 | <div id="headerform" style="width:100%; white-space:nowrap;";> | ||
7 | <form method="GET" class="searchform" name="searchform" style="display:inline;"><input type="text" name="searchterm" style="width:30%" value=""> <input type="submit" value="Search" class="bigbutton"></form> | ||
8 | <form method="GET" class="tagfilter" name="tagfilter" style="display:inline;margin-left:24px;"><input type="text" name="searchtags" id="searchtags" style="width:10%" value=""> <input type="submit" value="Filter by tag" class="bigbutton"></form> | ||
9 | </div> | ||
10 | </div> | ||
11 | |||
12 | <div id="linklist"> | ||
13 | |||
14 | {include="linklist.paging"} | ||
15 | |||
16 | {if="$search_type=='fulltext'"} | ||
17 | <div id="searchcriteria">{$result_count} results for <i>{$search_crits}</i></div> | ||
18 | {/if} | ||
19 | {if="$search_type=='tags'"} | ||
20 | <div id="searchcriteria">{$result_count} results for tags <i> | ||
21 | {loop="search_crits"} | ||
22 | <span class="linktag" title="Remove tag"><a href="?removetag={$value|htmlspecialchars}">{$value|htmlspecialchars} <span style="border-left:1px solid #aaa; padding-left:5px; color:#6767A7;">x</span></a></span> | ||
23 | {/loop}</i></div> | ||
24 | {/if} | ||
25 | |||
26 | <ul> | ||
27 | {loop="links"} | ||
28 | <li{if="$value.class"} class="{$value.class}"{/if}> | ||
29 | <div class="thumbnail">{$value.url|thumbnail}</div> | ||
30 | <div class="linkcontainer"> | ||
31 | <span class="linktitle"><a href="{$redirector}{$value.url|htmlspecialchars}">{$value.title|htmlspecialchars}</a></span> | ||
32 | {if="isLoggedIn()"} | ||
33 | <form method="GET" class="buttoneditform"><input type="hidden" name="edit_link" value="{$value.linkdate}"><input type="image" alt="Edit" src="images/edit_icon.png#" title="Edit" class="button_edit"></form> | ||
34 | <form method="POST" class="buttoneditform"><input type="hidden" name="lf_linkdate" value="{$value.linkdate}"> | ||
35 | <input type="hidden" name="token" value="{$token}"><input type="hidden" name="delete_link"><input type="image" alt="Delete" src="images/delete_icon.png#" title="Delete" class="button_delete" onClick="return confirmDeleteLink();"></form> | ||
36 | {/if} | ||
37 | <br> | ||
38 | {if="$value.description"}<div class="linkdescription"{if condition="$search_type=='permalink'"} style="max-height:none !important;"{/if}>{$value.description}</div>{/if} | ||
39 | {if="!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()"} | ||
40 | <span class="linkdate" title="Permalink"><a href="?{$value.linkdate|smallHash}">{$value.localdate|htmlspecialchars} - permalink</a> - </span> | ||
41 | {else} | ||
42 | <span class="linkdate" title="Short link here"><a href="?{$value.linkdate|smallHash}">permalink</a> - </span> | ||
43 | {/if} | ||
44 | <span class="linkurl" title="Short link">{$value.url|htmlspecialchars}</span><br> | ||
45 | {if="$value.tags"} | ||
46 | <div class="linktaglist"> | ||
47 | {loop="value.taglist"}<span class="linktag" title="Add tag"><a href="?addtag={$value|htmlspecialchars}">{$value|htmlspecialchars}</a></span> {/loop} | ||
48 | </div> | ||
49 | {/if} | ||
50 | </div> | ||
51 | </li> | ||
52 | {/loop} | ||
53 | </ul> | ||
54 | |||
55 | {include="linklist.paging"} | ||
56 | |||
57 | </div> | ||
58 | |||
59 | {include="page.footer"} | ||
60 | </body> | ||
61 | </html> \ No newline at end of file | ||
diff --git a/tpl/linklist.paging.html b/tpl/linklist.paging.html new file mode 100644 index 00000000..27e7440d --- /dev/null +++ b/tpl/linklist.paging.html | |||
@@ -0,0 +1,9 @@ | |||
1 | <div class="paging"> | ||
2 | <div style="float:right; padding-right:5px;"> | ||
3 | Links per page: <a href="?linksperpage=20">20</a> <a href="?linksperpage=50">50</a> <a href="?linksperpage=100">100</a> | ||
4 | <form method="GET" style="display:inline;" class="linksperpage"><input type="text" name="linksperpage" size="2" style="height:15px;"></form> | ||
5 | </div> | ||
6 | {if="$previous_page_url"} <a href="{$previous_page_url}">◄Older</a> {/if} | ||
7 | <span style="color:#fff; padding:0 20 0 20;">page {$page_current} / {$page_max} </span> | ||
8 | {if="$next_page_url"} <a href="{$next_page_url}">Newer►</a> {/if} | ||
9 | </div> \ No newline at end of file | ||
diff --git a/tpl/loginform.html b/tpl/loginform.html new file mode 100644 index 00000000..5a81fde1 --- /dev/null +++ b/tpl/loginform.html | |||
@@ -0,0 +1,25 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body{if="ban_canLogin()"} onload="document.loginform.login.focus();"{/if}> | ||
4 | <div id="pageheader"> | ||
5 | {include="page.header"} | ||
6 | |||
7 | <div id="headerform"> | ||
8 | {if="!ban_canLogin()"} | ||
9 | You have been banned from login after too many failed attempts. Try later. | ||
10 | {else} | ||
11 | <form method="post" name="loginform"> | ||
12 | Login: <input type="text" name="login" tabindex="1"> | ||
13 | Password : <input type="password" name="password" tabindex="2"> | ||
14 | <input type="submit" value="Login" class="bigbutton" tabindex="4"><br> | ||
15 | <input style="margin:10 0 0 40;" type="checkbox" name="longlastingsession" id="longlastingsession" tabindex="3"><label for="longlastingsession"> Stay signed in (Do not check on public computers)</label> | ||
16 | <input type="hidden" name="token" value="{$token}"> | ||
17 | {if="$returnurl"}<input type="hidden" name="returnurl" value="{$returnurl|htmlspecialchars}">{/if} | ||
18 | </form> | ||
19 | {/if} | ||
20 | </div> | ||
21 | </div> | ||
22 | |||
23 | {include="page.footer"} | ||
24 | </body> | ||
25 | </html> \ No newline at end of file | ||
diff --git a/tpl/page.footer.html b/tpl/page.footer.html new file mode 100644 index 00000000..80a000bb --- /dev/null +++ b/tpl/page.footer.html | |||
@@ -0,0 +1,20 @@ | |||
1 | <div id="footer"> | ||
2 | <b><a href="http://sebsauvage.net/wiki/doku.php?id=php:shaarli">Shaarli {$version}</a></b> - The personal, minimalist, super-fast, no-database delicious clone. By <a href="http://sebsauvage.net" target="_blank">sebsauvage.net</a>. Theme by <a href="http://blog.idleman.fr" target="_blank">idleman.fr</a>. | ||
3 | </div> | ||
4 | {if="$newversion"} | ||
5 | <div id="newversion"><span style="text-decoration:blink;">●</span> Shaarli {$newversion|htmlspecialchars} is <a href="http://sebsauvage.net/wiki/doku.php?id=php:shaarli#download">available</a>.</div> | ||
6 | {/if} | ||
7 | {if="isLoggedIn()"} | ||
8 | <script language="JavaScript">function confirmDeleteLink() { var agree=confirm("Are you sure you want to delete this link ?"); if (agree) return true ; else return false ; }</script> | ||
9 | {/if} | ||
10 | |||
11 | {if="$GLOBALS['config']['OPEN_SHAARLI'] || isLoggedIn()"} | ||
12 | <script language="JavaScript"> | ||
13 | $(document).ready(function() | ||
14 | { | ||
15 | $('#lf_tags').autocomplete({source:'{$source}?ws=tags',minLength:1}); | ||
16 | $('#searchtags').autocomplete({source:'{$source}?ws=tags',minLength:1}); | ||
17 | $('#fromtag').autocomplete({source:'{$source}?ws=singletag',minLength:1}); | ||
18 | }); | ||
19 | </script> | ||
20 | {/if} | ||
diff --git a/tpl/page.header.html b/tpl/page.header.html new file mode 100644 index 00000000..72965a87 --- /dev/null +++ b/tpl/page.header.html | |||
@@ -0,0 +1,24 @@ | |||
1 | |||
2 | <div id="logo" title="Share your links !" onclick="document.location='?';"></div> | ||
3 | <div style="float:right; font-style:italic; color:#bbb; text-align:right; padding:0 5 0 0;">Shaare your links...<br>{$linkcount} links</div> | ||
4 | <span id="shaarli_title"><a href="?">{$shaarlititle}</a></span> | ||
5 | |||
6 | {if="!empty($_GET['source']) && $_GET['source']=='bookmarklet'"} | ||
7 | {ignore} When called as a popup from bookmarklet, do not display menu. {/ignore} | ||
8 | {else} | ||
9 | <a href="?">Home</a> | ||
10 | {if="isLoggedIn()"} | ||
11 | <a href="?do=logout">Logout</a><a href="?do=tools">Tools</a><a href="?do=addlink"><b>Add link</b></a> | ||
12 | {elseif="$GLOBALS['config']['OPEN_SHAARLI']"} | ||
13 | <a href="?do=tools">Tools</a><a href="?do=addlink"><b>Add link</b></a> | ||
14 | {else} | ||
15 | <a href="?do=login">Login</a> | ||
16 | {/if} | ||
17 | <a href="{$feedurl}?do=rss{$searchcrits}">RSS Feed</a> | ||
18 | <a href="{$feedurl}?do=atom{$searchcrits}" style="padding-left:10px;">ATOM Feed</a> | ||
19 | <a href="?do=tagcloud">Tag cloud</a> | ||
20 | <a href="?do=picwall{$searchcrits}">Picture wall</a> | ||
21 | {/if} | ||
22 | <div class="clear"></div> | ||
23 | |||
24 | |||
diff --git a/tpl/page.html b/tpl/page.html new file mode 100644 index 00000000..2601169e --- /dev/null +++ b/tpl/page.html | |||
@@ -0,0 +1,8 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body> | ||
4 | <div id="pageheader">{include="page.header"}</div> | ||
5 | You body goes here... | ||
6 | {include="page.footer"} | ||
7 | </body> | ||
8 | </html> \ No newline at end of file | ||
diff --git a/tpl/picwall.html b/tpl/picwall.html new file mode 100644 index 00000000..48a1acf1 --- /dev/null +++ b/tpl/picwall.html | |||
@@ -0,0 +1,16 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body> | ||
4 | <div id="pageheader">{include="page.header"}</div> | ||
5 | <center> | ||
6 | <div class="picwall_container"> | ||
7 | {loop="linksToDisplay"} | ||
8 | <div class="picwall_pictureframe"> | ||
9 | {$value.thumbnail}<a href="{$value.permalink}"><span class="info">{$value.title|htmlspecialchars}</span></a> | ||
10 | </div> | ||
11 | {/loop} | ||
12 | </div> | ||
13 | </center> | ||
14 | {include="page.footer"} | ||
15 | </body> | ||
16 | </html> \ No newline at end of file | ||
diff --git a/tpl/picwall2.html b/tpl/picwall2.html new file mode 100644 index 00000000..765cf439 --- /dev/null +++ b/tpl/picwall2.html | |||
@@ -0,0 +1,18 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body> | ||
4 | <div id="pageheader">{include="page.header"}</div> | ||
5 | <div style="background-color:#003;"> | ||
6 | {loop="linksToDisplay"} | ||
7 | <div style="float:left;width:48%;border-right:2px solid white;height:120px;overflow:hide;"> | ||
8 | <div style="float:left;width:120px;text-align:center">{$value.thumbnail}</div> | ||
9 | <a href="{$value.permalink}" style="color:yellow;font-weight:bold;text-decoration:none;">{$value.title|htmlspecialchars}</a><br> | ||
10 | <span style="font-size:8pt;color:#eee;">{$value.description|htmlspecialchars}</span> | ||
11 | <div style="clear:both;"></div> | ||
12 | </div><br> | ||
13 | {/loop} | ||
14 | </div> | ||
15 | |||
16 | {include="page.footer"} | ||
17 | </body> | ||
18 | </html> \ No newline at end of file | ||
diff --git a/tpl/readme.txt b/tpl/readme.txt new file mode 100644 index 00000000..d57080ea --- /dev/null +++ b/tpl/readme.txt | |||
@@ -0,0 +1,42 @@ | |||
1 | ===== Shaarli template organisation ===== | ||
2 | |||
3 | Any Shaarli page should conform to this RainTPL template: | ||
4 | |||
5 | ----------------------------------------------------- | ||
6 | <html> | ||
7 | <head>{include="includes"}</head> | ||
8 | <body> | ||
9 | <div id="pageheader">{include="page.header"}</div> | ||
10 | You body goes here... | ||
11 | {include="page.footer"} | ||
12 | </body> | ||
13 | </html> | ||
14 | ----------------------------------------------------- | ||
15 | |||
16 | If you want to also add something in the page header (in the dark area), do it here: | ||
17 | |||
18 | <div id="pageheader">{include="page.header"}My menu goes here...</div> | ||
19 | |||
20 | |||
21 | Example: "Add new link" form: | ||
22 | ----------------------------------------------------- | ||
23 | <html> | ||
24 | <head>{include="includes"}</head> | ||
25 | <body onload="document.addform.post.focus();"> | ||
26 | <div id="pageheader"> | ||
27 | {include="page.header"} | ||
28 | <div id="headerform"> | ||
29 | <form method="GET" action="" name="addform" class="addform"> | ||
30 | <input type="text" name="post" style="width:50%;"> | ||
31 | <input type="submit" value="Add link" class="bigbutton"> | ||
32 | </form> | ||
33 | </div> | ||
34 | </div> | ||
35 | {include="page.footer"} | ||
36 | </body> | ||
37 | </html> | ||
38 | ----------------------------------------------------- | ||
39 | |||
40 | |||
41 | |||
42 | |||
diff --git a/tpl/tagcloud.html b/tpl/tagcloud.html new file mode 100644 index 00000000..4bd78115 --- /dev/null +++ b/tpl/tagcloud.html | |||
@@ -0,0 +1,14 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body> | ||
4 | <div id="pageheader">{include="page.header"}</div> | ||
5 | <center> | ||
6 | <div id="cloudtag"> | ||
7 | {loop="tags"} | ||
8 | <span style="color:#99f; font-size:9pt; padding-left:5px; padding-right:2px;">{$value.count}</span><a href="?searchtags={$key|htmlspecialchars}" style="font-size:{$value.size}pt; font-weight:bold; color:black; text-decoration:none">{$key|htmlspecialchars}</a> | ||
9 | {/loop} | ||
10 | </div> | ||
11 | </center> | ||
12 | {include="page.footer"} | ||
13 | </body> | ||
14 | </html> \ No newline at end of file | ||
diff --git a/tpl/tools.html b/tpl/tools.html new file mode 100644 index 00000000..bf70021c --- /dev/null +++ b/tpl/tools.html | |||
@@ -0,0 +1,18 @@ | |||
1 | <html> | ||
2 | <head>{include="includes"}</head> | ||
3 | <body> | ||
4 | <div id="pageheader"> | ||
5 | {include="page.header"} | ||
6 | <div id="toolsdiv"> | ||
7 | {if="!$GLOBALS['config']['OPEN_SHAARLI']"}<a href="?do=changepasswd"><b>Change password</b> <span>: Change your password.</span></a><br><br>{/if} | ||
8 | <a href="?do=configure"><b>Configure your Shaarli</b> <span>: Change Title, timezone...</span></a><br><br> | ||
9 | <a href="?do=changetag"><b>Rename/delete tags</b> <span>: Rename or delete a tag in all links</span></a><br><br> | ||
10 | <a href="?do=import"><b>Import</b> <span>: Import Netscape html bookmarks (as exported from Firefox, Chrome, Opera, delicious...)</span></a> <br><br> | ||
11 | <a href="?do=export"><b>Export</b> <span>: Export Netscape html bookmarks (which can be imported in Firefox, Chrome, Opera, delicious...)</span></a><br><br> | ||
12 | <a class="smallbutton" onclick="alert('Drag this link to your bookmarks toolbar, or right-click it and choose Bookmark This Link...');return false;" href="javascript:javascript:(function(){var%20url%20=%20location.href;var%20title%20=%20document.title%20||%20url;window.open('{$pageabsaddr}?post='%20+%20encodeURIComponent(url)+'&title='%20+%20encodeURIComponent(title)+'&source=bookmarklet','_blank','menubar=no,height=390,width=600,toolbar=no,scrollbars=no,status=no');})();"><b>Shaare link</b></a> <a href="#" style="clear:none;"><span>⇐ Drag this link to your bookmarks toolbar (or right-click it and choose Bookmark This Link....).<br> Then click "Shaare link" button in any page you want to share.</span></a><br><br> | ||
13 | <div class="clear"></div> | ||
14 | </div> | ||
15 | </div> | ||
16 | {include="page.footer"} | ||
17 | </body> | ||
18 | </html> \ No newline at end of file | ||