|
29 | 29 | define('PHPPREFIX','<?php /* '); |
30 | 30 | define('PHPSUFFIX',' */ ?>'); |
31 | 31 | define('MYMOVIES', 'MyMovies'); |
32 | | -define('MYMOVIES_VERSION', '1.2.1'); |
| 32 | +define('MYMOVIES_VERSION', '1.3.0'); |
33 | 33 | define('INACTIVITY_TIMEOUT', 3600); |
34 | 34 | define('RSS', 'movies.rss'); |
35 | 35 | define('RSS_BOXOFFICE', 'box-office.rss'); |
|
69 | 69 | define('AUTHOR', empty($_CONFIG['author']) ? $_CONFIG['login'] : $_CONFIG['author'] ); |
70 | 70 | define('BASE_LANG', $_CONFIG['language']); |
71 | 71 | define('BASE_URL', (empty($_SERVER['REQUEST_SCHEME']) ? 'http' : $_SERVER['REQUEST_SCHEME']).'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']).'/'); |
| 72 | +define('CURRENT_URL_QUERY', htmlspecialchars(parse_url($_SERVER[REQUEST_URI], PHP_URL_QUERY))); |
| 73 | + |
72 | 74 |
|
73 | 75 | $tpl->assign('MyMoviesVersion', preg_replace('#(\d+\.\d+)(\.\d+)#', '$1', MYMOVIES_VERSION)); |
74 | 76 |
|
@@ -193,6 +195,11 @@ public function all() { |
193 | 195 | return $this->data; |
194 | 196 | } |
195 | 197 |
|
| 198 | + // random movie |
| 199 | + public function random() { |
| 200 | + return $this->data[array_rand($this->data)]; |
| 201 | + } |
| 202 | + |
196 | 203 | // last movies inserted |
197 | 204 | public function lastMovies($begin = 0, $end = PAGINATION) { |
198 | 205 | krsort($this->data); |
@@ -461,10 +468,16 @@ private static function url_admin($url, $name, $tpl = FALSE) { |
461 | 468 | return $result.($tpl ? '</li>' : NULL); |
462 | 469 | } |
463 | 470 | static function menu($active) { |
464 | | - return self::url('home', 'All', $active).self::url('box-office', 'Box office', $active).self::url('soon', 'Watchlist', $active).'<li class="rss"><a href="./?rss-feeds" class="tip" title="RSS feeds"><i class="icon-rss"></i></a></li>'.PHP_EOL; |
| 471 | + return self::url('home', 'All', $active) |
| 472 | + .self::url('box-office', 'Box office', $active) |
| 473 | + .self::url('soon', 'Watchlist', $active) |
| 474 | + .'<li class="rss'.($active=='rss'?' active':'').'"><a href="./?rss-feeds" class="tip" title="RSS feeds"><i class="icon-rss"></i></a></li>' |
| 475 | + .PHP_EOL; |
465 | 476 | } |
466 | 477 | static function menuAdmin($active) { |
467 | | - return self::url_admin('add', 'Movie', $active).self::url_admin('admin', 'Admin', $active).PHP_EOL; |
| 478 | + return self::url_admin('add', 'Movie', $active) |
| 479 | + .self::url_admin('admin', 'Admin', $active) |
| 480 | + .PHP_EOL; |
468 | 481 | } |
469 | 482 | static function movie($id) { |
470 | 483 | $movies = new Movies(isLogged()); |
@@ -980,6 +993,14 @@ function moviePage() { |
980 | 993 | exit(); |
981 | 994 | } |
982 | 995 |
|
| 996 | +// redirection to a random movie |
| 997 | +function randomMovie() { |
| 998 | + $movies = new Movies(); |
| 999 | + $movie = $movies->random(); |
| 1000 | + header('Location: '.str_replace('./', BASE_URL, Path::movie($movie['id']))); |
| 1001 | + exit(); |
| 1002 | +} |
| 1003 | + |
983 | 1004 | // rss feeds page |
984 | 1005 | function rssPage() { |
985 | 1006 | global $tpl; |
@@ -1543,6 +1564,8 @@ function signin() { |
1543 | 1564 | if (!empty($_GET['movie'])) {moviePage();} |
1544 | 1565 | // rss feeds asked |
1545 | 1566 | if (isset($_GET['rss-feeds'])) {rssPage();} |
| 1567 | +// random movie |
| 1568 | +if (isset($_GET['random'])) {randomMovie();} |
1546 | 1569 | // admin asked |
1547 | 1570 | if (isset($_GET['admin'])) {administration();} |
1548 | 1571 | // login asked |
|
0 commit comments