Skip to content

Commit 8185aa8

Browse files
committed
Fix #21: Add link to a random movie page
1 parent 412940b commit 8185aa8

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ __Light web application to manage movies and track their state__
44

55

66

7-
Version 1.1 is now available!
7+
Version 1.3 is now available!
88
[Download the last version](https://github.com/Devenet/MyMovies/releases)
99

1010

index.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
define('PHPPREFIX','<?php /* ');
3030
define('PHPSUFFIX',' */ ?>');
3131
define('MYMOVIES', 'MyMovies');
32-
define('MYMOVIES_VERSION', '1.2.1');
32+
define('MYMOVIES_VERSION', '1.3.0');
3333
define('INACTIVITY_TIMEOUT', 3600);
3434
define('RSS', 'movies.rss');
3535
define('RSS_BOXOFFICE', 'box-office.rss');
@@ -69,6 +69,8 @@
6969
define('AUTHOR', empty($_CONFIG['author']) ? $_CONFIG['login'] : $_CONFIG['author'] );
7070
define('BASE_LANG', $_CONFIG['language']);
7171
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+
7274

7375
$tpl->assign('MyMoviesVersion', preg_replace('#(\d+\.\d+)(\.\d+)#', '$1', MYMOVIES_VERSION));
7476

@@ -193,6 +195,11 @@ public function all() {
193195
return $this->data;
194196
}
195197

198+
// random movie
199+
public function random() {
200+
return $this->data[array_rand($this->data)];
201+
}
202+
196203
// last movies inserted
197204
public function lastMovies($begin = 0, $end = PAGINATION) {
198205
krsort($this->data);
@@ -461,10 +468,16 @@ private static function url_admin($url, $name, $tpl = FALSE) {
461468
return $result.($tpl ? '</li>' : NULL);
462469
}
463470
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&nbsp;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&nbsp;feeds"><i class="icon-rss"></i></a></li>'
475+
.PHP_EOL;
465476
}
466477
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;
468481
}
469482
static function movie($id) {
470483
$movies = new Movies(isLogged());
@@ -980,6 +993,14 @@ function moviePage() {
980993
exit();
981994
}
982995

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+
9831004
// rss feeds page
9841005
function rssPage() {
9851006
global $tpl;
@@ -1543,6 +1564,8 @@ function signin() {
15431564
if (!empty($_GET['movie'])) {moviePage();}
15441565
// rss feeds asked
15451566
if (isset($_GET['rss-feeds'])) {rssPage();}
1567+
// random movie
1568+
if (isset($_GET['random'])) {randomMovie();}
15461569
// admin asked
15471570
if (isset($_GET['admin'])) {administration();}
15481571
// login asked

templates/page.menu.rain

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
</div>
2323
</form>
2424
<ul class="nav navbar-nav">
25+
<li class="random"><a href="./?random" class="tip" title="Random&nbsp;movie"><i class="icon-random"></i></a></li>
2526
{if="isLogged()"}
2627
{$menu_links_admin}
2728
<li><a href="{""|Path::signout}" title="Sign&nbsp;out" class="tip"><i class="icon-signout"></i></a></li>

0 commit comments

Comments
 (0)