Skip to content

Commit 5e4b71d

Browse files
committed
Release v 1.0 (Road map #6)
1 parent 20990e7 commit 5e4b71d

4 files changed

Lines changed: 47 additions & 11 deletions

File tree

assets/css/movies.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ article.movies .kinds {font-size: 12px;}
5656
.stars.stars-3 {color: #9272C2;}
5757
.stars.stars-4 {color: #428bca;}
5858
.stars.stars-5 {color: #468847;}
59+
article ul.text-muted a {color: rgb(153,153,153);}
5960

6061
article.movie .page-header {margin-top: 0; margin-bottom: 15px;}
6162
article.movie h2 {margin-bottom: 0; position: relative; color: #444;}

index.php

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
date_default_timezone_set('Europe/Paris');
4-
//error_reporting(0);
4+
error_reporting(0);
55

66
global $_CONFIG;
77
$_CONFIG['data'] = 'data';
@@ -110,6 +110,7 @@ class Movies implements Iterator, Countable, ArrayAccess {
110110
public $total_not_seen = 0;
111111
public $total_seen = 0;
112112
public $total_search = 0;
113+
public $total_genre = 0;
113114

114115
function __construct($logged = FALSE) {
115116
$this->logged = $logged;
@@ -207,12 +208,24 @@ public function byNote($begin = 0, $end = PAGINATION) {
207208
return array_slice($sorted, $begin, $end, TRUE);
208209
}
209210

211+
// function to get only movies with a genre given
212+
public function byGenre($genre, $begin = 0, $end = PAGINATION) {
213+
$result = array();
214+
$genre = mb_convert_case(htmlspecialchars($genre), MB_CASE_LOWER, "UTF-8");
215+
foreach($this->data as $m) {
216+
if (strpos(mb_convert_case($m['genre'], MB_CASE_LOWER, "UTF-8"), $genre)!==false)
217+
{ $result[$m['id']] = $m; }
218+
}
219+
krsort($result);
220+
$this->total_genre = sizeof($result);
221+
return array_slice($result, $begin, $end, TRUE);
222+
}
223+
210224
// search function (case no sensitive). Currently: search exact whole expression
211-
public function search($term, $begin = 0) {
212-
$result=array();
225+
public function search($term, $begin = 0, $end = PAGINATION) {
226+
$result = array();
213227
$s = mb_convert_case(htmlspecialchars($term), MB_CASE_LOWER, "UTF-8");
214-
foreach($this->data as $m)
215-
{
228+
foreach($this->data as $m) {
216229
$found = (strpos(mb_convert_case($m['title'], MB_CASE_LOWER, "UTF-8"),$s)!==false)
217230
|| (strpos(mb_convert_case($m['original_title'], MB_CASE_LOWER, "UTF-8"),$s)!==false)
218231
|| (strpos(mb_convert_case($m['synopsis'], MB_CASE_LOWER, "UTF-8"),$s)!==false)
@@ -221,7 +234,7 @@ public function search($term, $begin = 0) {
221234
}
222235
krsort($result);
223236
$this->total_search = sizeof($result);
224-
return array_slice($result, $begin, PAGINATION, TRUE);
237+
return array_slice($result, $begin, $end, TRUE);
225238
}
226239

227240
/*
@@ -720,7 +733,7 @@ function displayGenres($genres) {
720733
ksort($genre);
721734
$result = '';
722735
foreach ($genre as $value)
723-
$result .= '<li><i class="icon-tag"></i> '.trim(mb_convert_case($value, MB_CASE_TITLE, "UTF-8")).'</li>';
736+
$result .= '<li><i class="icon-tag"></i> <a href="?genre='.trim(mb_convert_case($value, MB_CASE_LOWER, "UTF-8")).'">'.trim(mb_convert_case($value, MB_CASE_TITLE, "UTF-8")).'</a></li>';
724737
return $result.PHP_EOL;
725738
}
726739
// shortcut the synopsis (= summary) of the movie with [...]
@@ -1355,7 +1368,7 @@ function signin() {
13551368
$tpl->assign('movie', $movies->search(htmlspecialchars($_GET['search']), $page*PAGINATION));
13561369
} else { $tpl->assign('movie', $movies->search(htmlspecialchars($_GET['search']))); }
13571370
$tpl->assign('pagination', displayPagination($page, $movies->total_search, '?search='.htmlspecialchars($_GET['search']).'&amp;'));
1358-
$tpl->assign('page_title', !empty($page) ? 'Box office &middot; Page '.($page+1) : 'Box office');
1371+
$tpl->assign('page_title', !empty($page) ? 'Search &middot; Page '.($page+1) : 'Search');
13591372
$tpl->assign('menu_links', Path::menu('search'));
13601373
$tpl->assign('menu_links_admin', Path::menuAdmin('search'));
13611374
$tpl->assign('search', htmlspecialchars($_GET['search']));
@@ -1364,6 +1377,28 @@ function signin() {
13641377
$tpl->draw('list');
13651378
exit();
13661379
}
1380+
// movies sorted with a given genre asked
1381+
if (isset($_GET['genre'])) {
1382+
if (empty($_GET['genre'])) { notFound(); }
1383+
$movies = new Movies();
1384+
$movies->byGenre(htmlspecialchars($_GET['genre'])); // used to update $movies->total_genre
1385+
// if no result found, genre does not exist
1386+
if ($movies->total_genre == 0) { notFound(); }
1387+
1388+
$page = isset($_GET['page']) ? (int) $_GET['page'] : 0;
1389+
// check if pagination is asked
1390+
if (!empty($_GET['page'])) {
1391+
checkPagination($page, $movies->total_genre);
1392+
$tpl->assign('movie', $movies->byGenre(htmlspecialchars($_GET['genre']), $page*PAGINATION));
1393+
} else { $tpl->assign('movie', $movies->byGenre(htmlspecialchars($_GET['genre']))); }
1394+
$tpl->assign('pagination', displayPagination($page, $movies->total_genre, '?genre='.htmlspecialchars($_GET['genre']).'&amp;'));
1395+
$tpl->assign('page_title', !empty($page) ? ucfirst(htmlspecialchars($_GET['genre'])).' &middot; Page '.($page+1) : ucfirst(htmlspecialchars($_GET['genre'])));
1396+
$tpl->assign('menu_links', Path::menu('genre'));
1397+
$tpl->assign('menu_links_admin', Path::menuAdmin('genre'));
1398+
$tpl->assign('token', getToken());
1399+
$tpl->draw('list');
1400+
exit();
1401+
}
13671402
// all movies asked [need to be after other page they need pagination!]
13681403
// HOME PAGE
13691404
if (empty($_GET) || isset($_GET['page'])) {
@@ -1376,7 +1411,7 @@ function signin() {
13761411
$tpl->assign('movie', $movies->lastMovies($page*PAGINATION));
13771412
} else { $tpl->assign('movie', $movies->lastMovies()); }
13781413
$tpl->assign('pagination', displayPagination($page, $movies->count()));
1379-
$tpl->assign('page_title', !empty($page) ? 'Home &middot; Page '.($page+1) : 'Home');
1414+
$tpl->assign('page_title', !empty($page) ? 'Page '.($page+1) : '');
13801415
$tpl->assign('menu_links', Path::menu('home'));
13811416
$tpl->assign('menu_links_admin', Path::menuAdmin('home'));
13821417
$tpl->assign('token', getToken());

templates/movie.rain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
{if="!empty($movie['duration'])"}<p>{$movie['duration']} min</p>{/if}
3535
{if="!empty($movie['release_date'])"}<p><span class="tip" data-title="Release&nbsp;date"><i class="icon-calendar"></i></span> {$movie['release_date']}</p>{/if}
3636
{if="!empty($country)"}<p>{$country|displayFlagWithName}</p>{/if}
37-
<ul class="list-unstyled espace-top">
37+
<ul class="list-unstyled espace-top text-muted">
3838
{$displayGenres}
3939
</ul>
4040
{if="!empty($movie['link_website'])"}<p class="espace-top"><a href="{$movie['link_website']}" rel="external" class="normal tip" title="External information"><i class="icon-globe"></i> more online</a></p>{/if}

templates/page.head.rain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<meta charset="utf-8" />
2-
<title>{$page_title} &middot; {#TITLE#}</title>
2+
<title>{#TITLE#}{if="!empty($page_title)"} &middot; {$page_title}{/if}</title>
33

44
<meta name="author" content="Nicolas Devenet" />
55
<meta name="robots" content="noindex, noarchive, nofollow" />

0 commit comments

Comments
 (0)