├── views ├── Movie │ ├── publish.php │ ├── addqueue.php │ ├── makeedit.php │ ├── viewed.php │ ├── removecomment.php │ ├── towatch.php │ ├── vote.php │ ├── addcomment.php │ ├── index.php │ ├── wall.php │ ├── queue.php │ ├── stat.php │ ├── addman.php │ ├── add.php │ ├── display.php │ ├── addimdb.php │ └── edit.php ├── Error │ ├── badurl.php │ ├── badview.php │ └── badtemplate.php ├── Series │ ├── makeedit.php │ ├── index.php │ ├── display.php │ ├── create.php │ └── edit.php ├── User │ ├── towatch.php │ └── recomended.php ├── Login │ ├── login.php │ └── index.php ├── Home │ └── index.php └── maintemplate.php ├── public ├── img │ └── posters │ │ └── index.php ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.ttf │ └── glyphicons-halflings-regular.woff └── js │ └── bootstrap.min.js ├── .htaccess ├── classes ├── auth.php ├── arraytools.php ├── viewmodel.php ├── basecontroller.php ├── functions.php ├── basemodel.php ├── view.php ├── session.php ├── database.php ├── loader.php └── imdb.php ├── models ├── error.php ├── home.php ├── login.php ├── user.php ├── series.php └── movie.php ├── config └── config_sample.php ├── .gitattributes ├── controllers ├── error.php ├── home.php ├── login.php ├── user.php ├── series.php └── movie.php ├── index.php ├── README.md ├── .gitignore └── db.sql /views/Movie/publish.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/img/posters/index.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /views/Movie/addqueue.php: -------------------------------------------------------------------------------- 1 | Fel! -------------------------------------------------------------------------------- /views/Movie/makeedit.php: -------------------------------------------------------------------------------- 1 | Fel! -------------------------------------------------------------------------------- /views/Movie/viewed.php: -------------------------------------------------------------------------------- 1 | Fel! -------------------------------------------------------------------------------- /views/Movie/removecomment.php: -------------------------------------------------------------------------------- 1 | Fel! -------------------------------------------------------------------------------- /views/Movie/towatch.php: -------------------------------------------------------------------------------- 1 | Något gick fel! 2 | -------------------------------------------------------------------------------- /views/Movie/vote.php: -------------------------------------------------------------------------------- 1 | Något gick fel! 2 | -------------------------------------------------------------------------------- /views/Error/badurl.php: -------------------------------------------------------------------------------- 1 |

Error

2 |

The URL you have requested does not exist.

-------------------------------------------------------------------------------- /views/Movie/addcomment.php: -------------------------------------------------------------------------------- 1 | Du försöker posta en tom kommentar! Skriv något så blir det bra :) -------------------------------------------------------------------------------- /views/Series/makeedit.php: -------------------------------------------------------------------------------- 1 | '; 3 | var_dump($_POST); 4 | echo ''; -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Groggy1/PHP-movie-database/HEAD/public/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Groggy1/PHP-movie-database/HEAD/public/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Groggy1/PHP-movie-database/HEAD/public/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /views/Series/index.php: -------------------------------------------------------------------------------- 1 | printTable($viewModel -> get("tableBody"), $viewModel -> get("tableHead")); -------------------------------------------------------------------------------- /views/User/towatch.php: -------------------------------------------------------------------------------- 1 | printTable($viewModel -> get("tableBody"), $viewModel -> get("tableHead")); 4 | -------------------------------------------------------------------------------- /views/Login/login.php: -------------------------------------------------------------------------------- 1 |

Fel!

2 | -------------------------------------------------------------------------------- /views/Error/badview.php: -------------------------------------------------------------------------------- 1 |

Fatal MVC Error

2 |

The controller action you requested does not have a view. This should exist as viewFile; ?>. Please create this file. -------------------------------------------------------------------------------- /views/Movie/index.php: -------------------------------------------------------------------------------- 1 | get("actors"); 4 | echo $viewModel -> get("directors"); 5 | $functions -> printTable($viewModel -> get("tableBody"), $viewModel -> get("tableHead")); 6 | ?> 7 | -------------------------------------------------------------------------------- /views/User/recomended.php: -------------------------------------------------------------------------------- 1 |

Poäng är beräknade på filmens genres och de filmer du betygsatt sedan tidigare.

2 | printTable($viewModel -> get("tableBody"), $viewModel -> get("tableHead")); -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | Options +FollowSymLinks 2 | RewriteEngine on 3 | RewriteRule ^(cron|install|old)($|/) - [L] 4 | RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&id=$3&id2=$4&id3=$5&id4=$6 [NC,L] -------------------------------------------------------------------------------- /views/Home/index.php: -------------------------------------------------------------------------------- 1 |
2 | get("posters") as $key => $value) { 4 | echo '
'; 5 | } 6 | ?> 7 |
8 | -------------------------------------------------------------------------------- /views/Error/badtemplate.php: -------------------------------------------------------------------------------- 1 |

Fatal MVC Error

2 |

The controller action you requested is configured to access /views/.php as a view template, but this does not exist. Please make sure this file exists in /views or change the template name argument in your controller action's $this->returnView() method call to an existing template.

-------------------------------------------------------------------------------- /classes/auth.php: -------------------------------------------------------------------------------- 1 | 'login','action' => 'index','path' => $urlValues)); 8 | $controller = $loader -> createController(); 9 | $controller -> executeAction(); 10 | die(); 11 | } 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /views/Series/display.php: -------------------------------------------------------------------------------- 1 |

2 | [Ändra] 3 |

4 | ' . $viewModel -> get("seriesname") . ''; 6 | echo $viewModel -> get("seriesdesc"); 7 | $functions = new Functions(); 8 | $functions -> printTable($viewModel -> get("tableBody"), $viewModel -> get("tableHead")); 9 | -------------------------------------------------------------------------------- /models/error.php: -------------------------------------------------------------------------------- 1 | viewModel->set("pageTitle","Error - Bad URL"); 15 | return $this->viewModel; 16 | } 17 | } 18 | 19 | ?> 20 | -------------------------------------------------------------------------------- /config/config_sample.php: -------------------------------------------------------------------------------- 1 | get('posters'); 3 | $first = $posters[0]; 4 | $second = $posters[1]; 5 | $third = $posters[2]; 6 | ?> 7 |
8 | get('posters') as $value) { 10 | echo $value; 11 | } 12 | ?> 13 |
14 |
15 | get("getPrew") ?>> 16 | get("getNext") ?>> 17 |
18 |
-------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /views/Movie/queue.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | printTable($viewModel -> get('tableBody'), $viewModel -> get('tableHead')); 6 | ?> 7 |
8 | 9 |
10 |
11 | 12 | 15 |
16 |
17 |
-------------------------------------------------------------------------------- /models/home.php: -------------------------------------------------------------------------------- 1 | db -> select_query("SELECT `id`, `poster` FROM `movies` ORDER BY id DESC LIMIT 3"); 13 | 14 | $this -> viewModel -> set("posters", $posters); 15 | $this -> viewModel -> set('urlValues', $this -> urlValues); 16 | $this -> viewModel -> set("pageTitle", TITLE . "Index"); 17 | return $this -> viewModel; 18 | } 19 | } 20 | ?> 21 | -------------------------------------------------------------------------------- /classes/arraytools.php: -------------------------------------------------------------------------------- 1 | $value) { 7 | if (is_array($array[$key])) { 8 | $out = array_merge($out, $this -> flatten_array($array[$key])); 9 | } else { 10 | $out[] = $value; 11 | } 12 | } 13 | return $out; 14 | } 15 | 16 | public function unique_flat_array($array) { 17 | $out = $this -> flatten_array($array); 18 | return array_unique($out); 19 | } 20 | 21 | public function pickvalues_to_array($post, $start, $stop){ 22 | $result = array(); 23 | for($i = $start; $i <= $stop;$i++){ 24 | $result[] = $post[$i]; 25 | } 26 | return $result; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /classes/viewmodel.php: -------------------------------------------------------------------------------- 1 | $name = $val; 14 | } 15 | 16 | //returns the requested property value 17 | public function get($name) { 18 | if (isset($this->{$name})) { 19 | return $this->{$name}; 20 | } else { 21 | return null; 22 | } 23 | } 24 | } 25 | 26 | ?> -------------------------------------------------------------------------------- /classes/basecontroller.php: -------------------------------------------------------------------------------- 1 | action = $action; 18 | $this -> urlValues = $urlValues; 19 | 20 | //establish the view object 21 | $this -> view = new View(get_class($this), $action); 22 | } 23 | 24 | //executes the requested method 25 | public function executeAction() { 26 | return $this -> {$this->action}(); 27 | } 28 | 29 | } 30 | ?> 31 | -------------------------------------------------------------------------------- /controllers/error.php: -------------------------------------------------------------------------------- 1 | model = new ErrorModel(); 18 | } 19 | 20 | //bad URL request error 21 | protected function badURL() 22 | { 23 | $this->view->output($this->model->badURL()); 24 | } 25 | } 26 | 27 | ?> 28 | -------------------------------------------------------------------------------- /views/Login/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 | 6 |
7 |
8 | 9 | 10 |
11 | 12 | 15 |
16 |
-------------------------------------------------------------------------------- /controllers/home.php: -------------------------------------------------------------------------------- 1 | model = new HomeModel(); 20 | $this -> model -> set('urlValues', $urlValues); 21 | } 22 | 23 | //default method 24 | protected function index() { 25 | $this -> view -> output($this -> model -> index()); 26 | } 27 | } 28 | ?> 29 | -------------------------------------------------------------------------------- /controllers/login.php: -------------------------------------------------------------------------------- 1 | model = new LoginModel(); 17 | $this -> model -> set('urlValues', $urlValues); 18 | } 19 | 20 | //default method 21 | protected function index() { 22 | $this -> view -> output($this -> model -> index()); 23 | } 24 | 25 | protected function login() { 26 | $this -> view -> output($this -> model -> login()); 27 | } 28 | 29 | protected function logout() { 30 | $this -> view -> output($this -> model -> logout()); 31 | } 32 | 33 | } 34 | ?> 35 | -------------------------------------------------------------------------------- /classes/functions.php: -------------------------------------------------------------------------------- 1 | '; 6 | if ($header) { 7 | echo ' 8 | '; 9 | foreach ($header as $value) { 10 | echo '' . $value . ''; 11 | } 12 | echo ' 13 | '; 14 | } 15 | echo ''; 16 | foreach ($body as $key => $value) { 17 | $trclass = (!empty($class[$key])) ? $class[$key] : ''; 18 | echo ''; 19 | foreach ($value as $value2) { 20 | echo '' . $value2 . ''; 21 | } 22 | echo ''; 23 | } 24 | echo ''; 25 | if ($footer) { 26 | echo ' 27 | '; 28 | foreach ($footer as $value) { 29 | echo '' . $value . ''; 30 | } 31 | echo ' 32 | '; 33 | } 34 | echo ''; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /classes/basemodel.php: -------------------------------------------------------------------------------- 1 | db = new Database(); 17 | $this -> viewModel = new ViewModel(); 18 | $this -> commonViewData(); 19 | } 20 | 21 | //establish viewModel data that is required for all views in this method (i.e. the main template) 22 | protected function commonViewData() { 23 | //e.g. $this->viewModel->set("mainMenu",array("Home" => "/home", "Help" => "/help")); 24 | } 25 | 26 | public function set($name, $value) { 27 | $this -> $name = $value; 28 | } 29 | 30 | public function get($name) { 31 | return $this -> $name; 32 | } 33 | 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /controllers/user.php: -------------------------------------------------------------------------------- 1 | model = new UserModel(); 20 | $this -> model -> set('urlValues', $urlValues); 21 | } 22 | 23 | //default method 24 | protected function towatch() { 25 | $this -> view -> output($this -> model -> towatch()); 26 | } 27 | 28 | protected function recomended() { 29 | $this -> view -> output($this -> model -> recomended()); 30 | } 31 | 32 | } 33 | ?> 34 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | createController(); //creates the requested controller object based on the 'controller' URL value 26 | $controller->executeAction(); //execute the requested controller's requested method based on the 'action' URL value. Controller methods output a View. 27 | 28 | ?> 29 | -------------------------------------------------------------------------------- /views/Series/create.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 | 6 |
7 | 8 |
9 |
10 |
11 | 12 |
13 | 14 |
15 |
16 |
17 |
18 |
19 | 20 |
21 | 22 |
23 |
24 |
25 |
26 | 29 |
30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PHP-movie-database 2 | ======================= 3 | PHP-movie-database is a movie database script written in PHP. 4 | 5 | Major overhaul of the script. If installed before, database structure is changed. 6 | 7 | Tested on 8 | ------------------------- 9 | The script is tested on both a local Rasbian server with: 10 | * PHP 5.4.36 11 | * MySQL 5.5.41 12 | * Apache 2.2.22 13 | 14 | and on a Ubuntu VPS with: 15 | * PHP 7.0.8 16 | * MySQL 5.7.13 17 | * Apache 2.4.18 18 | 19 | You have to do the following for the script to work: 20 | ------------------------- 21 | * Download [Twitter Bootstrap](http://twitter.github.com/bootstrap/), created with 3.1 22 | * Just copy it straight to the script folder 23 | * Download [PHP IMDb Scraper](http://web3o.blogspot.se/2010/10/php-imdb-scraper-for-new-imdb-template.html), tested with update May 6, 2014 24 | * Copy it to the class/ directory 25 | * Change MySQL account information and script path in file config/config.php 26 | * When uploaded to your webpage will you need to make the director public/img/posters/ writable as it is the folder where the posters will be saved by the script 27 | 28 | Licence 29 | ------------------------- 30 | [![Creative Commons License](http://i.creativecommons.org/l/by-sa/3.0/88x31.png)](http://creativecommons.org/licenses/by-sa/3.0/deed.en_US) 31 | 32 | -------------------------------------------------------------------------------- /classes/view.php: -------------------------------------------------------------------------------- 1 | viewFile = "views/" . $controllerName . "/" . $action . ".php"; 17 | } 18 | 19 | //output the view 20 | public function output($viewModel, $template = "maintemplate") { 21 | 22 | $templateFile = "views/".$template.".php"; 23 | 24 | if (file_exists($this->viewFile)) { 25 | if ($template) { 26 | //include the full template 27 | if (file_exists($templateFile)) { 28 | require($templateFile); 29 | } else { 30 | require("views/error/badtemplate.php"); 31 | } 32 | } else { 33 | //we're not using a template view so just output the method's view directly 34 | require($this->viewFile); 35 | } 36 | } else { 37 | require("views/error/badview.php"); 38 | } 39 | 40 | } 41 | } 42 | 43 | ?> -------------------------------------------------------------------------------- /controllers/series.php: -------------------------------------------------------------------------------- 1 | model = new SeriesModel(); 20 | $this -> model -> set('urlValues', $urlValues); 21 | } 22 | 23 | //default method 24 | protected function index() { 25 | $this -> view -> output($this -> model -> index()); 26 | } 27 | protected function display() { 28 | $this -> view -> output($this -> model -> display()); 29 | } 30 | protected function create() { 31 | $this -> model -> set('submit', $_POST['submit']); 32 | $this -> view -> output($this -> model -> create()); 33 | } 34 | protected function edit() { 35 | $this -> view -> output($this -> model -> edit()); 36 | } 37 | protected function makeedit() { 38 | $this -> model -> set('submit', $_POST['submit']); 39 | $this -> view -> output($this -> model -> makeedit()); 40 | } 41 | protected function remove() { 42 | $this -> view -> output($this -> model -> remove()); 43 | } 44 | } 45 | ?> 46 | -------------------------------------------------------------------------------- /classes/session.php: -------------------------------------------------------------------------------- 1 | 2 | [Ta bort] 3 |

4 | Tillbaka 5 |
6 |
7 |
8 |
9 | 10 |
11 | 12 |
13 |
14 |
15 | 16 |
17 | 18 |
19 |
20 |
21 |
22 |
23 |
24 | printTable($viewModel -> get("tableBody"), $viewModel -> get("tableHead")); 27 | ?> 28 |
29 |
30 |
31 |
32 |
33 | 34 |
35 | 36 |
37 |
38 |
39 |
40 | 43 |
44 | -------------------------------------------------------------------------------- /models/login.php: -------------------------------------------------------------------------------- 1 | viewModel -> set('urlValues', $this -> get('urlValues')); 13 | $this -> viewModel -> set('pageTitle', TITLE . 'Logga in'); 14 | return $this -> viewModel; 15 | } 16 | 17 | public function login() { 18 | if (!empty($_POST['username']) && !empty($_POST['password'])) { 19 | //Om användarnamn/lösenord matats in måste de kontroleras 20 | $sql = "SELECT id, name, password FROM " . DB_FLAG . "users 21 | WHERE BINARY name = :name"; 22 | $param = array(':name' => $_POST['username']); 23 | 24 | $checklogin = $this -> db -> select_query($sql, $param); 25 | if (count($checklogin) == 1) { 26 | if (crypt($_POST['password'], $checklogin[0]['password']) == $checklogin[0]['password']) { 27 | $_SESSION["user_id"] = $checklogin[0]['id']; 28 | $_SESSION["user_name"] = $checklogin[0]['name']; 29 | $_SESSION["user_logged_in"] = 1; 30 | $_SESSION["site"] = SITE; 31 | header('location: ' . $_POST['path']); 32 | } else { 33 | $this -> viewModel -> set('error[]', 'Fel användare/lösenord'); 34 | } 35 | } else { 36 | $this -> viewModel -> set('error[]', 'Användarnamnet finns inte'); 37 | } 38 | } else { 39 | $this -> viewModel -> set('error[]', 'Användarnamn eller lösenord saknas'); 40 | } 41 | return $this -> viewModel; 42 | } 43 | 44 | public Function logout() { 45 | session_destroy(); 46 | header('location: ' . URL); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /views/Movie/stat.php: -------------------------------------------------------------------------------- 1 |

Statistik

2 |
3 |
4 |

Filmer

5 | Det finns ' . $viewModel -> get(antalfilmer) . ' filmer i databasen

'; 7 | echo '

Av dessa har ' . $viewModel -> get(watched) . ' filmer setts'; 8 | echo '

' . $viewModel -> get(towatch) . ' filmer är markerade för att ses

'; 9 | echo '

' . $viewModel -> get(watchedtowatch) . ' filmer har varit markerade för att ses och setts

'; 10 | echo '

Det finns ' . $viewModel -> get(numberinqueue) . ' filmer i kö

'; 11 | echo '

' . $viewModel -> get(movieswithoutruntime) . ' filmer saknar speltid

'; 12 | ?> 13 |
14 |
15 |

Filminnehåll

16 | Filmerna har regiserats av ' . $viewModel -> get(numberofdirectors) . ' olika regisörer

'; 18 | echo '

I filmerna finns det totalt ' . $viewModel -> get(numberofactors) . ' skådespelare

'; 19 | echo '

Filmerna spänner över ' . $viewModel -> get(numberofgenres) . ' olika genres

'; 20 | $subtitle = $viewModel -> get(subtitle); 21 | for ($i = 0; $i <= sizeof($subtitle) - 1; $i++) : 22 | echo '

Det finns ' . $subtitle[$i][1] . ' filmer med ' . $subtitle[$i][0] . '

'; 23 | endfor; 24 | ?> 25 |
26 |
27 |

Användardata

28 | get(votes); 30 | echo '

Det har postats totalt ' . $viewModel -> get(comments) . ' kommentar på filmerna

'; 31 | echo '

Det har postats ' . $viewModel -> get(numberofnews) . ' nyheter

'; 32 | echo '

Det har lagts ' . $votes[0][1] . ' röster på filmerna

'; 33 | echo '

Rösterna har ett genomsnitt på ' . number_format($votes[0][0], 1) . ' poäng

'; 34 | ?> 35 |
36 |
-------------------------------------------------------------------------------- /classes/database.php: -------------------------------------------------------------------------------- 1 | exec("SET CHARACTER SET utf8"); 8 | } 9 | 10 | public function alteration_query($query) 11 | /* It returns an one row array containing 12 | how many rows where affected and the 13 | errors (if any) */ 14 | { 15 | $count = parent::exec($query); 16 | $error = parent::errorInfo(); 17 | if ($error[0] == 00000) 18 | $error[2] = ''; 19 | $resultarray = array('rows_affected' => $count, 'error' => $error[2]); 20 | return $resultarray; 21 | } 22 | 23 | public function select_query($query, $param = array(), $items_per_page = NULL, $page = NULL) 24 | /* It returns an array containing all the items we asked for. 25 | In case of an error it returns this array: 26 | ('1'=>'false','2'=>'There was an error in sql syntax.') 27 | $param is an array on form of: array(':placeholder' => $value)*/ 28 | { 29 | if ($items_per_page != null) { 30 | if ($page == null) { 31 | $page = 1; 32 | } 33 | $limit = ' LIMIT ' . ($page - 1) * $items_per_page . ' , ' . $items_per_page; 34 | } else { 35 | $limit = ''; 36 | } 37 | 38 | $stmnt = parent::prepare($query . $limit); 39 | if (!$stmnt -> execute($param)) { 40 | $result = array(1 => 'false', 2 => "There was an error in sql syntax."); 41 | return $result; 42 | } 43 | $result = $stmnt -> fetchAll(); 44 | return $result; 45 | } 46 | 47 | public function multi_query($query, $param = array(array())) 48 | /* It returns true/false depending on success of query. 49 | $param is an array on form of: array(array(':placeholder' => 'value'))*/ 50 | { 51 | $result = array(); 52 | $stmnt = parent::prepare($query); 53 | foreach ($param as $value) { 54 | if (!$stmnt -> execute($value)) { 55 | return array("Fel!"); 56 | } 57 | $value1 = $stmnt -> fetchAll(); 58 | $result[] = $value1; 59 | } 60 | return $result; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /classes/loader.php: -------------------------------------------------------------------------------- 1 | urlValues = $_GET; 20 | } else { 21 | $this -> urlValues = $urlValues; 22 | } 23 | 24 | if ($this -> urlValues['controller'] == "") { 25 | $this -> controllerName = "home"; 26 | $this -> controllerClass = "HomeController"; 27 | $this -> urlValues['controller'] = "home"; 28 | } else { 29 | $this -> controllerName = strtolower($this -> urlValues['controller']); 30 | $this -> controllerClass = ucfirst(strtolower($this -> urlValues['controller'])) . "Controller"; 31 | } 32 | 33 | if ($this -> urlValues['action'] == "") { 34 | $this -> action = "index"; 35 | $this -> urlValues['action'] = "index"; 36 | } else { 37 | $this -> action = $this -> urlValues['action']; 38 | } 39 | } 40 | 41 | //factory method which establishes the requested controller as an object 42 | public function createController() { 43 | //check our requested controller's class file exists and require it if so 44 | if (file_exists("controllers/" . $this -> controllerName . ".php")) { 45 | require ("controllers/" . $this -> controllerName . ".php"); 46 | } else { 47 | require ("controllers/error.php"); 48 | return new ErrorController("badurl", $this -> urlValues); 49 | } 50 | 51 | //does the class exist? 52 | if (class_exists($this -> controllerClass)) { 53 | $parents = class_parents($this -> controllerClass); 54 | 55 | //does the class inherit from the BaseController class? 56 | if (in_array("BaseController", $parents)) { 57 | //does the requested class contain the requested action as a method? 58 | if (method_exists($this -> controllerClass, $this -> action)) { 59 | return new $this->controllerClass($this -> action, $this -> urlValues); 60 | } else { 61 | //bad action/method error 62 | require ("controllers/error.php"); 63 | return new ErrorController("badurl", $this -> urlValues); 64 | } 65 | } else { 66 | //bad controller error 67 | require ("controllers/error.php"); 68 | return new ErrorController("badurl", $this -> urlValues); 69 | } 70 | } else { 71 | //bad controller error 72 | require ("controllers/error.php"); 73 | return new ErrorController("badurl", $this -> urlValues); 74 | } 75 | } 76 | 77 | } 78 | ?> 79 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *_i.c 48 | *_p.c 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.vspscc 63 | .builds 64 | *.dotCover 65 | 66 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 67 | #packages/ 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | 76 | # Visual Studio profiler 77 | *.psess 78 | *.vsp 79 | 80 | # ReSharper is a .NET coding add-in 81 | _ReSharper* 82 | 83 | # Installshield output folder 84 | [Ee]xpress 85 | 86 | # DocProject is a documentation generator add-in 87 | DocProject/buildhelp/ 88 | DocProject/Help/*.HxT 89 | DocProject/Help/*.HxC 90 | DocProject/Help/*.hhc 91 | DocProject/Help/*.hhk 92 | DocProject/Help/*.hhp 93 | DocProject/Help/Html2 94 | DocProject/Help/html 95 | 96 | # Click-Once directory 97 | publish 98 | 99 | # Others 100 | [Bb]in 101 | [Oo]bj 102 | sql 103 | TestResults 104 | *.Cache 105 | ClientBin 106 | stylecop.* 107 | ~$* 108 | *.dbmdl 109 | Generated_Code #added for RIA/Silverlight projects 110 | 111 | # Backup & report files from converting an old project file to a newer 112 | # Visual Studio version. Backup files are not needed, because we have git ;-) 113 | _UpgradeReport_Files/ 114 | Backup*/ 115 | UpgradeLog*.XML 116 | 117 | 118 | 119 | ############ 120 | ## Windows 121 | ############ 122 | 123 | # Windows image file caches 124 | Thumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | 130 | ############# 131 | ## Python 132 | ############# 133 | 134 | *.py[co] 135 | 136 | # Packages 137 | *.egg 138 | *.egg-info 139 | dist 140 | build 141 | eggs 142 | parts 143 | bin 144 | var 145 | sdist 146 | develop-eggs 147 | .installed.cfg 148 | 149 | # Installer logs 150 | pip-log.txt 151 | 152 | # Unit test / coverage reports 153 | .coverage 154 | .tox 155 | 156 | #Translations 157 | *.mo 158 | 159 | #Mr Developer 160 | .mr.developer.cfg 161 | 162 | # Mac crap 163 | .DS_Store 164 | 165 | ############################### 166 | # Different files not included# 167 | ############################### 168 | public/img/posters/* 169 | !public/img/posters/index.php 170 | class/imdb.php 171 | config/config.php 172 | /public/img/header.jpg 173 | -------------------------------------------------------------------------------- /controllers/movie.php: -------------------------------------------------------------------------------- 1 | model = new MovieModel(); 20 | $this -> model -> set('urlValues', $urlValues); 21 | } 22 | 23 | //default method 24 | protected function index() { 25 | $this -> view -> output($this -> model -> index()); 26 | } 27 | 28 | protected function display() { 29 | $this -> view -> output($this -> model -> display()); 30 | } 31 | 32 | protected function edit() { 33 | $this -> view -> output($this -> model -> edit()); 34 | } 35 | 36 | protected function vote() { 37 | $this -> view -> output($this -> model -> vote()); 38 | } 39 | 40 | protected function towatch() { 41 | $this -> view -> output($this -> model -> towatch()); 42 | } 43 | 44 | protected function towatchagain() { 45 | $this -> view -> output($this -> model -> towatchagain()); 46 | } 47 | 48 | protected function viewed() { 49 | $this -> view -> output($this -> model -> viewed()); 50 | } 51 | 52 | protected function wall() { 53 | $this -> view -> output($this -> model -> wall()); 54 | } 55 | 56 | protected function add() { 57 | $this -> view -> output($this -> model -> add()); 58 | } 59 | 60 | protected function addcomment() { 61 | $param = array(':uid' => $_SESSION['user_id'], ':mid' => $_POST['mid'], ':comment' => strip_tags($_POST['comment'])); 62 | $this -> model -> set('param', $param); 63 | $this -> view -> output($this -> model -> addcomment()); 64 | } 65 | 66 | protected function removecomment() { 67 | $this -> view -> output($this -> model -> removecomment()); 68 | } 69 | 70 | protected function makeedit() { 71 | $this -> model -> set('submit', $_POST['submit']); 72 | $this -> view -> output($this -> model -> makeedit()); 73 | } 74 | 75 | protected function addimdb() { 76 | $this -> model -> set('imdbID', $_POST['imdbid']); 77 | $this -> model -> set('sub', $_POST['sub']); 78 | $this -> model -> set('type', $_POST['type']); 79 | $this -> view -> output($this -> model -> addimdb()); 80 | } 81 | 82 | protected function publish() { 83 | $this -> view -> output($this -> model -> publish(), 0); 84 | } 85 | 86 | protected function addman() { 87 | $this -> model -> set('Nodir', trim($_POST['Nodir'])); 88 | $this -> model -> set('Noact', trim($_POST['Noact'])); 89 | $this -> model -> set('Nogen', trim($_POST['Nogen'])); 90 | $this -> model -> set('sub', trim($_POST['sub'])); 91 | $this -> model -> set('type', trim($_POST['type'])); 92 | $this -> view -> output($this -> model -> addman()); 93 | } 94 | 95 | protected function queue() { 96 | $this -> view -> output($this -> model -> queue()); 97 | } 98 | 99 | protected function addqueue() { 100 | $this -> model -> set('imdbid', trim($_POST['imdbid'])); 101 | $this -> model -> set('chars', strlen(trim($_POST['imdbid']))); 102 | $this -> view -> output($this -> model -> addqueue()); 103 | } 104 | 105 | protected function stat() { 106 | $this -> view -> output($this -> model -> stat()); 107 | } 108 | } 109 | ?> 110 | -------------------------------------------------------------------------------- /views/Movie/addman.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 | 6 |
7 | 8 |
9 |
10 |
11 | 12 |
13 | 14 |
15 |
16 |
17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 | 26 |
27 |
28 |
29 | 30 |
31 | 32 |
33 |
34 |
35 | 36 |
37 | 38 |
39 |
40 |
41 |
42 |
43 | 44 |
45 | get('Nodir') ; $i++) { 48 | $director = $director + 1; 49 | echo ''; 50 | } 51 | ?> 52 |
53 |
54 |
55 | 56 |
57 | get('Noact') ; $i++) { 60 | $actor = $actor + 1; 61 | echo ''; 62 | } 63 | ?> 64 |
65 |
66 |
67 | 68 |
69 | get('Nogen') ; $i++) { 72 | $genre = $genre + 1; 73 | echo ''; 74 | } 75 | ?> 76 |
77 |
78 |
79 | 80 | 81 | 82 | 83 | 84 | 85 |
86 |
87 |
88 |
-------------------------------------------------------------------------------- /views/Movie/add.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

Hämta data från imdB

5 |
6 | 7 |
8 | 9 |
10 |
11 |
12 | 13 |
14 | 20 |
21 |
22 |
23 | 24 |
25 | 32 |
33 |
34 |
35 |
36 | 39 |
40 |
41 |
42 |
43 |
44 |
45 |

Mata in data själv

46 |
47 | 48 |
49 | 50 |
51 |
52 |
53 | 54 |
55 | 56 |
57 |
58 |
59 | 60 |
61 | 62 |
63 |
64 |
65 | 66 |
67 | 73 |
74 |
75 |
76 | 77 |
78 | 85 |
86 |
87 |
88 |
89 | 92 |
93 |
94 |
95 |
96 |
97 |
98 | -------------------------------------------------------------------------------- /views/Movie/display.php: -------------------------------------------------------------------------------- 1 |
2 | 37 |
38 |
39 | 40 |
41 |
42 |
43 |
44 |

Handlning

45 | get('plot')) ?> 46 |
47 |
48 |
49 |
50 |

Trailer

51 | get('youtube')) > 0) { 53 | echo ''; 54 | } 55 | ?> 56 |
57 |
58 |
59 |

Betyg

60 | printTable($viewModel -> get('betygBody'), $viewModel -> get('betygHead')); 63 | ?> 64 |
65 |
66 |
67 |
68 |
69 |
70 |

Skådespelare

71 | get('actor')); 72 | foreach ($actor AS $value) { 73 | $value2 = explode(',', $value); 74 | echo '' . $value2[1] . '
'; 75 | } 76 | ?> 77 |
78 |
79 |

Regisörer

80 | get('director')); 81 | foreach ($director AS $value) { 82 | $value2 = explode(',', $value); 83 | echo '' . $value2[1] . '
'; 84 | } 85 | ?> 86 |
87 |
88 |

Kommentarer

89 | get('comments') AS $value) { 91 | echo '

' . $value['name'] . ' ' . $value['date'] . '

'; 92 | echo '

' . nl2br($value['comment']) . '

'; 93 | } 94 | ?> 95 |
96 |
97 |

Kommentera

98 |
99 | 100 | 101 | 104 |
105 |
106 |
107 |
108 | -------------------------------------------------------------------------------- /views/maintemplate.php: -------------------------------------------------------------------------------- 1 | get('urlValues'); 3 | /* 4 | echo '
';
  5 |  var_dump($url);
  6 |  echo '
'; 7 | */ 8 | ?> 9 | 10 | 11 | 12 | <?php echo $viewModel -> get('pageTitle'); ?> 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 94 | viewFile); 96 | ?> 97 |
98 | 101 |
102 |
103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /views/Movie/addimdb.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 | 6 |
7 | 8 |
9 |
10 |
11 | 12 |
13 | 14 |
15 |
16 |
17 | 18 |
19 | 20 | 21 | 22 |
23 |
24 |
25 | 26 |
27 | 28 |
29 |
30 |
31 | 32 |
33 | 34 |
35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 |
43 |
44 |
45 | 46 |
47 | get('directors') as $value) { 50 | $director = $director + 1; 51 | echo ''; 52 | } 53 | ?> 54 |
55 |
56 |
57 | 58 |
59 | get('cast') as $value) { 62 | $actor = $actor + 1; 63 | echo ''; 64 | } 65 | ?> 66 |
67 |
68 |
69 | 70 |
71 | get('genres') as $value) { 74 | $genre = $genre + 1; 75 | echo ''; 76 | } 77 | ?> 78 |
79 |
80 |
81 | 82 | 83 | 84 | 85 | 86 | 87 |
88 |
89 |
90 |
91 | -------------------------------------------------------------------------------- /views/Movie/edit.php: -------------------------------------------------------------------------------- 1 | Tillbaka 2 |
3 |
4 |
5 |
6 | 7 |
8 | 9 |
10 |
11 |
12 | 13 |
14 | 15 |
16 |
17 |
18 | 19 |
20 | 21 |
22 |
23 |
24 | 25 |
26 | 27 |
28 |
29 |
30 |
31 |
32 | 33 |
34 | 35 |
36 |
37 |
38 | 39 |
40 | 41 |
42 |
43 |
44 | 45 |
46 | 58 |
59 |
60 |
61 |
62 | 63 |
64 | 76 |
77 |
78 |
79 | 80 |
81 | 82 |
83 |
84 |
85 |
86 |
87 |
88 | 89 |
90 | 96 |
97 |
98 |
99 | 100 |
101 | 102 | get('comments') as $key => $value) { 104 | echo ''; 105 | } 106 | ?> 107 |
' . $value['comment'] . '
108 |
109 |
110 |
111 |
112 |
113 | 114 |
115 | 116 |
117 |
118 |
119 |
120 | 123 |
124 | 125 | 131 | -------------------------------------------------------------------------------- /models/user.php: -------------------------------------------------------------------------------- 1 | db -> select_query($sql, array(':uid' => $_SESSION['user_id'])); 29 | 30 | $i = 0; 31 | foreach ($result AS $value) { 32 | $tableBody[$i][0] = '' . $value['title'] . ''; 33 | $tableBody[$i][1] = $value['year']; 34 | $genres = explode('|', $value['genre']); 35 | foreach ($genres AS $value2) { 36 | $localgenre = explode(':', $value2); 37 | $tableBody[$i][2] .= $localgenre[1]; 38 | if (end($genres) !== $value2) { 39 | $tableBody[$i][2] .= ', '; 40 | } 41 | } 42 | $tableBody[$i][3] = $value['date']; 43 | $i++; 44 | } 45 | 46 | $sql = "SELECT allMovies.id, allMovies.title, allMovies.year, allMovies.genre, towatchagain.added as date 47 | FROM allMovies 48 | JOIN towatchagain ON towatchagain.movieid = allMovies.id 49 | LEFT JOIN (SELECT userid, movieid, date FROM userviewed) AS UV ON UV.movieid = allMovies.id AND UV.userid = towatchagain.userid 50 | WHERE towatchagain.userid = :uid 51 | ORDER BY towatchagain.added, allMovies.title"; 52 | 53 | $result = $this -> db -> select_query($sql, array(':uid' => $_SESSION['user_id'])); 54 | 55 | foreach ($result AS $value) { 56 | $tableBody[$i][0] = '' . $value['title'] . ''; 57 | $tableBody[$i][1] = $value['year']; 58 | $genres = explode('|', $value['genre']); 59 | foreach ($genres AS $value2) { 60 | $localgenre = explode(':', $value2); 61 | $tableBody[$i][2] .= $localgenre[1]; 62 | if (end($genres) !== $value2) { 63 | $tableBody[$i][2] .= ', '; 64 | } 65 | } 66 | $tableBody[$i][3] = $value['date']; 67 | $i++; 68 | } 69 | 70 | $this -> viewModel -> set('tableHead', array('Film', 'År', 'Genre','Tillagd')); 71 | $this -> viewModel -> set('tableBody', $tableBody); 72 | $this -> viewModel -> set('tableBody2', $tableBody2); 73 | $this -> viewModel -> set('urlValues', $this -> urlValues); 74 | $this -> viewModel -> set('pageTitle', TITLE . 'Filmer att se'); 75 | return $this -> viewModel; 76 | } 77 | 78 | public function recomended() { 79 | $sql = "SELECT movies.id,movies.title, movies.year, avg(avg) AS totalavg 80 | FROM movies JOIN genresinmovies AS gim ON movies.id = gim.movie_id 81 | JOIN 82 | (SELECT gim.genre_id, avg(uv.value) AS avg FROM uservote AS uv 83 | JOIN genresinmovies AS gim ON uv.movie_id = gim.movie_id 84 | JOIN genres AS gen ON gim.genre_id = gen.id 85 | WHERE uv.user_id = :uid 86 | GROUP BY gim.genre_id 87 | ORDER BY avg DESC) AS avg 88 | ON avg.genre_id = gim.genre_id 89 | LEFT JOIN userviewed AS uw ON uw.movieid = movies.id 90 | GROUP BY movies.id 91 | ORDER BY totalavg DESC"; 92 | 93 | $result = $this -> db -> select_query($sql, array(':uid' => $_SESSION['user_id'])); 94 | 95 | $i = 0; 96 | foreach ($result as $value) { 97 | $tableBody[$i][0] = '' . $value['title'] . ''; 98 | $tableBody[$i][1] = $value['year']; 99 | $tableBody[$i][2] = round($value['totalavg'], 1);; 100 | $i++; 101 | } 102 | 103 | /* 104 | $i = 0; 105 | foreach ($result AS $value) { 106 | $actors[] = explode('|', $value['actors']); 107 | $directors[] = explode('|', $value['directors']); 108 | $tableBody[$i][0] = '' . $value['title'] . ''; 109 | $tableBody[$i][1] = $value['year']; 110 | $genres = explode('|', $value['genre']); 111 | foreach ($genres AS $value2) { 112 | $localgenre = explode(':', $value2); 113 | $tableBody[$i][2] .= $localgenre[1]; 114 | if (end($genres) !== $value2) { 115 | $tableBody[$i][2] .= ', '; 116 | } 117 | } 118 | $tableBody[$i][3] = $value['date']; 119 | $i++; 120 | } 121 | */ 122 | 123 | $this -> viewModel -> set('tableHead', array('Film', 'År', 'Poäng')); 124 | $this -> viewModel -> set('tableBody', $tableBody); 125 | $this -> viewModel -> set('urlValues', $this -> urlValues); 126 | $this -> viewModel -> set('pageTitle', TITLE . 'Rekomenderade filmer'); 127 | return $this -> viewModel; 128 | } 129 | 130 | } 131 | ?> 132 | -------------------------------------------------------------------------------- /models/series.php: -------------------------------------------------------------------------------- 1 | db -> select_query($sql); 23 | 24 | $i = 0; 25 | foreach ($series as $value) { 26 | $tableBody[$i][0] = '' . $value['name'] . ''; 27 | $tableBody[$i][1] = $value['count']; 28 | $tableBody[$i][2] = $value['genres']; 29 | $i++; 30 | } 31 | 32 | $this -> viewModel -> set('tableHead', array("Namn", "Antal filmer", "Genres i serien")); 33 | $this -> viewModel -> set('tableBody', $tableBody); 34 | $this -> viewModel -> set('urlValues', $this -> urlValues); 35 | $this -> viewModel -> set("pageTitle", TITLE . "Alla filmserier"); 36 | return $this -> viewModel; 37 | } 38 | 39 | public function display() { 40 | $id = $this -> urlValues['id']; 41 | $sql = "SELECT series.name, movies.title, movies.id, moviesinseries.number, group_concat(DISTINCT `genres`.`genre` ORDER BY genres.genre separator ', ') AS genres FROM 42 | series JOIN moviesinseries ON series.id = moviesinseries.seriesID 43 | JOIN movies ON moviesinseries.movieID = movies.id 44 | JOIN genresinmovies ON genresinmovies.movie_id = movies.id 45 | JOIN genres ON genresinmovies.genre_id = genres.id 46 | WHERE series.id = :id 47 | GROUP BY movies.id 48 | ORDER BY moviesinseries.number"; 49 | 50 | $result = $this -> db -> select_query($sql, array(':id' => $id)); 51 | 52 | $i = 0; 53 | foreach ($result as $value) { 54 | $tableBody[$i][0] = '' . $value['title'] . ''; 55 | $tableBody[$i][1] = $value['number']; 56 | $tableBody[$i][2] = $value['genres']; 57 | $i++; 58 | } 59 | 60 | $sql = "SELECT series.infopage, series.description, series.name FROM series WHERE series.id = :id"; 61 | $result = $this -> db -> select_query($sql, array(':id' => $id)); 62 | 63 | $infopage = $result[0]['infopage']; 64 | $seriesname = $result[0]['name']; 65 | $seriesdesc = $result[0]['description']; 66 | 67 | $this -> viewModel -> set('infopage', $infopage); 68 | $this -> viewModel -> set('seriesname', $seriesname); 69 | $this -> viewModel -> set('seriesdesc', $seriesdesc); 70 | $this -> viewModel -> set('tableHead', array("Film", "Nummer", "Genres")); 71 | $this -> viewModel -> set('tableBody', $tableBody); 72 | $this -> viewModel -> set('urlValues', $this -> urlValues); 73 | $this -> viewModel -> set("pageTitle", TITLE . $result[0]['name'] . "-serien"); 74 | return $this -> viewModel; 75 | } 76 | 77 | public function create() { 78 | $post = $this -> submit; 79 | if (isset($post)) { 80 | $sql = "INSERT INTO `series`(`name`, `infopage`, `adDate`, `description`) 81 | VALUES (:name,:infopage,now(),:desc)"; 82 | $this -> db -> select_query($sql, array(":name" => $_POST["name"], ":infopage" => $_POST["infopage"], ":desc" => $_POST["desc"])); 83 | header('Location: ' . URL . 'series/display/' . $this -> db -> lastInsertId()); 84 | } 85 | $this -> viewModel -> set('urlValues', $this -> urlValues); 86 | $this -> viewModel -> set("pageTitle", TITLE . "Skapa en serie"); 87 | return $this -> viewModel; 88 | } 89 | 90 | public function edit() { 91 | $id = $this -> urlValues['id']; 92 | 93 | $result = $this -> db -> select_query("SELECT `name`, `infopage`, `description` FROM `series` WHERE id = :id", array(":id" => $id)); 94 | $name = $result[0]["name"]; 95 | $infopage = $result[0]["infopage"]; 96 | $description = $result[0]["description"]; 97 | 98 | $sql = "SELECT movies.title, movies.id, moviesinseries.seriesID, moviesinseries.number FROM moviesinseries 99 | JOIN movies ON moviesinseries.movieID = movies.id 100 | WHERE moviesinseries.seriesID = :id 101 | ORDER BY moviesinseries.number"; 102 | $result = $this -> db -> select_query($sql, array(":id" => $id)); 103 | 104 | $i = 0; 105 | foreach ($result as $value) { 106 | $tableBody[$i][0] = $value['title']; 107 | $tableBody[$i][1] = $value['number']; 108 | $tableBody[$i][2] = ''; 109 | $i++; 110 | } 111 | 112 | $this -> viewModel -> set('tableHead', array("Film", "Nummer", "Ta bort")); 113 | $this -> viewModel -> set('tableBody', $tableBody); 114 | $this -> viewModel -> set('name', $name); 115 | $this -> viewModel -> set('infopage', $infopage); 116 | $this -> viewModel -> set('desc', $description); 117 | $this -> viewModel -> set('movies', $movies); 118 | $this -> viewModel -> set('urlValues', $this -> urlValues); 119 | $this -> viewModel -> set("pageTitle", TITLE . "Ändra \"" . $name . "\""); 120 | return $this -> viewModel; 121 | } 122 | 123 | public function makeedit() { 124 | $post = $this -> submit; 125 | if (isset($post)) { 126 | $this -> db -> select_query("UPDATE `series` SET `name`=:name,`infopage`=:infopage,`description`=:desc WHERE id = :id", array(":id" => $this -> urlValues["id"], ":name" => $_POST["name"], ":infopage" => $_POST["infopage"], ":desc" => $_POST["desc"])); 127 | header('Location: ' . URL . 'series/display/' . $this -> urlValues["id"]); 128 | } elseif ($this -> urlValues["id"] == "rem") { 129 | $movieid = $this -> urlValues["id2"]; 130 | $seriesid = $this -> urlValues["id3"]; 131 | $this -> db -> select_query("DELETE FROM `moviesinseries` WHERE `movieID` = :movieid AND `seriesID` = :seriesid", array(":movieid" => $movieid, ":seriesid" => $seriesid)); 132 | header('Location: ' . URL . 'series/display/' . $seriesid); 133 | } 134 | $this -> viewModel -> set('urlValues', $this -> urlValues); 135 | $this -> viewModel -> set("pageTitle", TITLE . "Fel!"); 136 | return $this -> viewModel; 137 | } 138 | 139 | public function remove() { 140 | $id = $this -> urlValues['id']; 141 | echo $id; 142 | $this -> db -> select_query("DELETE FROM `series` WHERE `id` = :id;", array(":id" => $id)); 143 | $this -> db -> select_query("DELETE FROM `moviesinseries` WHERE `seriesID` = :id", array(":id" => $id)); 144 | header('Location: ' . URL . 'series'); 145 | } 146 | 147 | } 148 | ?> 149 | -------------------------------------------------------------------------------- /db.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.5.4.1deb2ubuntu2 3 | -- http://www.phpmyadmin.net 4 | -- 5 | -- Host: localhost 6 | -- Generation Time: Aug 30, 2016 at 07:35 PM 7 | -- Server version: 5.7.13-0ubuntu0.16.04.2 8 | -- PHP Version: 7.0.8-0ubuntu0.16.04.2 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | -- 14 | -- Database: `filmdb` 15 | -- 16 | 17 | -- -------------------------------------------------------- 18 | 19 | -- 20 | -- Table structure for table `actors` 21 | -- 22 | 23 | CREATE TABLE `actors` ( 24 | `id` int(11) NOT NULL, 25 | `actor` varchar(50) CHARACTER SET utf8 COLLATE utf8_swedish_ci NOT NULL 26 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 27 | 28 | -- -------------------------------------------------------- 29 | 30 | -- 31 | -- Table structure for table `actorsinmovies` 32 | -- 33 | 34 | CREATE TABLE `actorsinmovies` ( 35 | `movie_id` int(11) NOT NULL, 36 | `actor_id` int(11) NOT NULL 37 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 38 | 39 | -- -------------------------------------------------------- 40 | 41 | -- 42 | -- Stand-in structure for view `allMovies` 43 | -- 44 | CREATE TABLE `allMovies` ( 45 | `id` int(11) 46 | ,`title` varchar(100) 47 | ,`year` int(10) 48 | ,`genreid` text 49 | ,`genre` text 50 | ); 51 | 52 | -- -------------------------------------------------------- 53 | 54 | -- 55 | -- Table structure for table `directors` 56 | -- 57 | 58 | CREATE TABLE `directors` ( 59 | `id` int(11) NOT NULL, 60 | `director` varchar(50) CHARACTER SET utf8 COLLATE utf8_swedish_ci NOT NULL 61 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 62 | 63 | -- -------------------------------------------------------- 64 | 65 | -- 66 | -- Table structure for table `directorsinmovies` 67 | -- 68 | 69 | CREATE TABLE `directorsinmovies` ( 70 | `director_id` int(11) NOT NULL, 71 | `movie_id` int(11) NOT NULL 72 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 73 | 74 | -- -------------------------------------------------------- 75 | 76 | -- 77 | -- Table structure for table `genres` 78 | -- 79 | 80 | CREATE TABLE `genres` ( 81 | `id` int(11) NOT NULL, 82 | `genre` varchar(50) NOT NULL 83 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 84 | 85 | -- -------------------------------------------------------- 86 | 87 | -- 88 | -- Table structure for table `genresinmovies` 89 | -- 90 | 91 | CREATE TABLE `genresinmovies` ( 92 | `movie_id` int(11) NOT NULL, 93 | `genre_id` int(11) NOT NULL 94 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 95 | 96 | -- -------------------------------------------------------- 97 | 98 | -- 99 | -- Table structure for table `genresinqueue` 100 | -- 101 | 102 | CREATE TABLE `genresinqueue` ( 103 | `movie_id` int(11) NOT NULL, 104 | `genre_id` int(11) NOT NULL 105 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 106 | 107 | -- -------------------------------------------------------- 108 | 109 | -- 110 | -- Table structure for table `movies` 111 | -- 112 | 113 | CREATE TABLE `movies` ( 114 | `id` int(11) NOT NULL, 115 | `imdbid` varchar(20) NOT NULL, 116 | `title` varchar(100) NOT NULL, 117 | `plot` text NOT NULL, 118 | `year` int(10) NOT NULL, 119 | `poster` varchar(100) NOT NULL, 120 | `type` varchar(11) NOT NULL, 121 | `sub` varchar(30) NOT NULL, 122 | `runtime` int(11) NOT NULL, 123 | `youtube` char(100) NOT NULL, 124 | `date` datetime NOT NULL 125 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 126 | 127 | -- -------------------------------------------------------- 128 | 129 | -- 130 | -- Table structure for table `moviesinseries` 131 | -- 132 | 133 | CREATE TABLE `moviesinseries` ( 134 | `movieID` int(11) NOT NULL, 135 | `seriesID` int(11) NOT NULL, 136 | `number` int(11) NOT NULL 137 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 138 | 139 | -- -------------------------------------------------------- 140 | 141 | -- 142 | -- Table structure for table `movietype` 143 | -- 144 | 145 | CREATE TABLE `movietype` ( 146 | `short` varchar(5) NOT NULL, 147 | `type` varchar(30) NOT NULL 148 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 149 | 150 | -- -------------------------------------------------------- 151 | 152 | -- 153 | -- Table structure for table `news` 154 | -- 155 | 156 | CREATE TABLE `news` ( 157 | `id` int(11) NOT NULL, 158 | `userid` int(11) NOT NULL, 159 | `description` mediumtext NOT NULL, 160 | `date` date NOT NULL 161 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 162 | 163 | -- -------------------------------------------------------- 164 | 165 | -- 166 | -- Table structure for table `queue` 167 | -- 168 | 169 | CREATE TABLE `queue` ( 170 | `id` int(11) NOT NULL, 171 | `imdb` varchar(20) NOT NULL, 172 | `title` varchar(60) NOT NULL, 173 | `year` int(10) NOT NULL, 174 | `added` date NOT NULL 175 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 176 | 177 | -- -------------------------------------------------------- 178 | 179 | -- 180 | -- Table structure for table `series` 181 | -- 182 | 183 | CREATE TABLE `series` ( 184 | `id` int(11) NOT NULL, 185 | `name` varchar(60) NOT NULL, 186 | `infopage` varchar(200) NOT NULL, 187 | `adDate` datetime NOT NULL, 188 | `description` text NOT NULL 189 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 190 | 191 | -- -------------------------------------------------------- 192 | 193 | -- 194 | -- Table structure for table `towatch` 195 | -- 196 | 197 | CREATE TABLE `towatch` ( 198 | `movieid` int(11) NOT NULL, 199 | `userid` int(11) NOT NULL, 200 | `date` date NOT NULL 201 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 202 | 203 | -- -------------------------------------------------------- 204 | 205 | -- 206 | -- Table structure for table `towatchagain` 207 | -- 208 | 209 | CREATE TABLE `towatchagain` ( 210 | `movieid` int(11) NOT NULL, 211 | `userid` int(11) NOT NULL, 212 | `added` date NOT NULL 213 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 214 | 215 | -- -------------------------------------------------------- 216 | 217 | -- 218 | -- Table structure for table `usercomment` 219 | -- 220 | 221 | CREATE TABLE `usercomment` ( 222 | `id` int(11) NOT NULL, 223 | `userid` int(11) NOT NULL, 224 | `movieid` int(11) NOT NULL, 225 | `comment` text NOT NULL, 226 | `date` date NOT NULL 227 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 228 | 229 | -- -------------------------------------------------------- 230 | 231 | -- 232 | -- Table structure for table `users` 233 | -- 234 | 235 | CREATE TABLE `users` ( 236 | `id` int(11) NOT NULL, 237 | `name` varchar(40) NOT NULL, 238 | `password` char(130) NOT NULL 239 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 240 | 241 | -- -------------------------------------------------------- 242 | 243 | -- 244 | -- Table structure for table `userviewed` 245 | -- 246 | 247 | CREATE TABLE `userviewed` ( 248 | `userid` int(11) NOT NULL, 249 | `movieid` int(11) NOT NULL, 250 | `date` date NOT NULL 251 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 252 | 253 | -- -------------------------------------------------------- 254 | 255 | -- 256 | -- Table structure for table `uservote` 257 | -- 258 | 259 | CREATE TABLE `uservote` ( 260 | `user_id` int(11) NOT NULL, 261 | `movie_id` int(11) NOT NULL, 262 | `value` int(1) NOT NULL, 263 | `date` date NOT NULL 264 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 265 | 266 | -- -------------------------------------------------------- 267 | 268 | -- 269 | -- Structure for view `allMovies` 270 | -- 271 | DROP TABLE IF EXISTS `allMovies`; 272 | 273 | CREATE ALGORITHM=UNDEFINED DEFINER=`groggy`@`localhost` SQL SECURITY DEFINER VIEW `allMovies` AS select `movies`.`id` AS `id`,`movies`.`title` AS `title`,`movies`.`year` AS `year`,group_concat(`genres`.`id` separator ',') AS `genreid`,group_concat(concat(`genres`.`id`,':',`genres`.`genre`) order by `genres`.`genre` ASC separator '|') AS `genre` from ((`movies` join `genresinmovies` on((`movies`.`id` = `genresinmovies`.`movie_id`))) join `genres` on((`genresinmovies`.`genre_id` = `genres`.`id`))) group by `movies`.`id` order by `movies`.`title`,`genres`.`genre` ; 274 | 275 | -- 276 | -- Indexes for dumped tables 277 | -- 278 | 279 | -- 280 | -- Indexes for table `actors` 281 | -- 282 | ALTER TABLE `actors` 283 | ADD PRIMARY KEY (`id`); 284 | 285 | -- 286 | -- Indexes for table `directors` 287 | -- 288 | ALTER TABLE `directors` 289 | ADD PRIMARY KEY (`id`); 290 | 291 | -- 292 | -- Indexes for table `genres` 293 | -- 294 | ALTER TABLE `genres` 295 | ADD PRIMARY KEY (`id`); 296 | 297 | -- 298 | -- Indexes for table `movies` 299 | -- 300 | ALTER TABLE `movies` 301 | ADD PRIMARY KEY (`id`); 302 | 303 | -- 304 | -- Indexes for table `news` 305 | -- 306 | ALTER TABLE `news` 307 | ADD PRIMARY KEY (`id`); 308 | 309 | -- 310 | -- Indexes for table `queue` 311 | -- 312 | ALTER TABLE `queue` 313 | ADD PRIMARY KEY (`id`); 314 | 315 | -- 316 | -- Indexes for table `series` 317 | -- 318 | ALTER TABLE `series` 319 | ADD PRIMARY KEY (`id`); 320 | 321 | -- 322 | -- Indexes for table `usercomment` 323 | -- 324 | ALTER TABLE `usercomment` 325 | ADD PRIMARY KEY (`id`); 326 | 327 | -- 328 | -- Indexes for table `users` 329 | -- 330 | ALTER TABLE `users` 331 | ADD PRIMARY KEY (`id`); 332 | 333 | -- 334 | -- AUTO_INCREMENT for dumped tables 335 | -- 336 | 337 | -- 338 | -- AUTO_INCREMENT for table `actors` 339 | -- 340 | ALTER TABLE `actors` 341 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0; 342 | -- 343 | -- AUTO_INCREMENT for table `directors` 344 | -- 345 | ALTER TABLE `directors` 346 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0; 347 | -- 348 | -- AUTO_INCREMENT for table `genres` 349 | -- 350 | ALTER TABLE `genres` 351 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0; 352 | -- 353 | -- AUTO_INCREMENT for table `movies` 354 | -- 355 | ALTER TABLE `movies` 356 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0; 357 | -- 358 | -- AUTO_INCREMENT for table `news` 359 | -- 360 | ALTER TABLE `news` 361 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0; 362 | -- 363 | -- AUTO_INCREMENT for table `queue` 364 | -- 365 | ALTER TABLE `queue` 366 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0; 367 | -- 368 | -- AUTO_INCREMENT for table `series` 369 | -- 370 | ALTER TABLE `series` 371 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0; 372 | -- 373 | -- AUTO_INCREMENT for table `usercomment` 374 | -- 375 | ALTER TABLE `usercomment` 376 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0; 377 | -- 378 | -- AUTO_INCREMENT for table `users` 379 | -- 380 | ALTER TABLE `users` 381 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0; 382 | -------------------------------------------------------------------------------- /classes/imdb.php: -------------------------------------------------------------------------------- 1 | getIMDbIdFromSearch(trim($title)); 20 | if($imdbId === NULL){ 21 | $arr = array(); 22 | $arr['error'] = "No Title found in Search Results!"; 23 | return $arr; 24 | } 25 | return $this->getMovieInfoById($imdbId, $getExtraInfo); 26 | } 27 | 28 | // Get movie information by IMDb Id. 29 | public function getMovieInfoById($imdbId, $getExtraInfo = true) 30 | { 31 | $arr = array(); 32 | $imdbUrl = "http://www.imdb.com/title/" . trim($imdbId) . "/"; 33 | return $this->scrapeMovieInfo($imdbUrl, $getExtraInfo); 34 | } 35 | 36 | // Scrape movie information from IMDb page and return results in an array. 37 | private function scrapeMovieInfo($imdbUrl, $getExtraInfo = true) 38 | { 39 | $arr = array(); 40 | $html = $this->geturl("${imdbUrl}combined"); 41 | $title_id = $this->match('//ms', $html, 1); 42 | if(empty($title_id) || !preg_match("/tt\d+/i", $title_id)) { 43 | $arr['error'] = "No Title found on IMDb!"; 44 | return $arr; 45 | } 46 | $arr['title_id'] = $title_id; 47 | $arr['imdb_url'] = $imdbUrl; 48 | $arr['title'] = str_replace('"', '', trim($this->match('/(IMDb \- )*(.*?) \(.*?<\/title>/ms', $html, 2))); 49 | $arr['original_title'] = trim($this->match('/class="title-extra">(.*?)</ms', $html, 1)); 50 | $arr['year'] = trim($this->match('/<title>.*?\(.*?(\d{4}).*?\).*?<\/title>/ms', $html, 1)); 51 | $arr['rating'] = $this->match('/<b>(\d.\d)\/10<\/b>/ms', $html, 1); 52 | $arr['genres'] = $this->match_all('/<a.*?>(.*?)<\/a>/ms', $this->match('/Genre.?:(.*?)(<\/div>|See more)/ms', $html, 1), 1); 53 | $arr['directors'] = $this->match_all_key_value('/<td valign="top"><a.*?href="\/name\/(.*?)\/">(.*?)<\/a>/ms', $this->match('/Directed by<\/a><\/h5>(.*?)<\/table>/ms', $html, 1)); 54 | $arr['writers'] = $this->match_all_key_value('/<td valign="top"><a.*?href="\/name\/(.*?)\/">(.*?)<\/a>/ms', $this->match('/Writing credits<\/a><\/h5>(.*?)<\/table>/ms', $html, 1)); 55 | $arr['cast'] = $this->match_all_key_value('/<td class="nm"><a.*?href="\/name\/(.*?)\/".*?>(.*?)<\/a>/ms', $this->match('/<h3>Cast<\/h3>(.*?)<\/table>/ms', $html, 1)); 56 | $arr['cast'] = array_slice($arr['cast'], 0, 30); 57 | $arr['stars'] = array_slice($arr['cast'], 0, 5); 58 | $arr['producers'] = $this->match_all_key_value('/<td valign="top"><a.*?href="\/name\/(.*?)\/">(.*?)<\/a>/ms', $this->match('/Produced by<\/a><\/h5>(.*?)<\/table>/ms', $html, 1)); 59 | $arr['musicians'] = $this->match_all_key_value('/<td valign="top"><a.*?href="\/name\/(.*?)\/">(.*?)<\/a>/ms', $this->match('/Original Music by<\/a><\/h5>(.*?)<\/table>/ms', $html, 1)); 60 | $arr['cinematographers'] = $this->match_all_key_value('/<td valign="top"><a.*?href="\/name\/(.*?)\/">(.*?)<\/a>/ms', $this->match('/Cinematography by<\/a><\/h5>(.*?)<\/table>/ms', $html, 1)); 61 | $arr['editors'] = $this->match_all_key_value('/<td valign="top"><a.*?href="\/name\/(.*?)\/">(.*?)<\/a>/ms', $this->match('/Film Editing by<\/a><\/h5>(.*?)<\/table>/ms', $html, 1)); 62 | $arr['mpaa_rating'] = $this->match('/MPAA<\/a>:<\/h5><div class="info-content">Rated (G|PG|PG-13|PG-14|R|NC-17|X) /ms', $html, 1); 63 | $arr['release_date'] = $this->match('/Release Date:<\/h5>.*?<div class="info-content">.*?([0-9][0-9]? (January|February|March|April|May|June|July|August|September|October|November|December) (19|20)[0-9][0-9])/ms', $html, 1); 64 | $arr['tagline'] = trim(strip_tags($this->match('/Tagline:<\/h5>.*?<div class="info-content">(.*?)(<a|<\/div)/ms', $html, 1))); 65 | $arr['plot'] = trim(strip_tags($this->match('/Plot:<\/h5>.*?<div class="info-content">(.*?)(<a|<\/div|\|)/ms', $html, 1))); 66 | $arr['plot_keywords'] = $this->match_all('/<a.*?>(.*?)<\/a>/ms', $this->match('/Plot Keywords:<\/h5>.*?<div class="info-content">(.*?)<\/div/ms', $html, 1), 1); 67 | $arr['poster'] = $this->match('/<div class="photo">.*?<a name="poster".*?><img.*?src="(.*?)".*?<\/div>/ms', $html, 1); 68 | $arr['poster_large'] = ""; 69 | $arr['poster_full'] = ""; 70 | if ($arr['poster'] != '' && strpos($arr['poster'], "media-imdb.com") > 0) { //Get large and small posters 71 | $arr['poster'] = preg_replace('/_V1.*?.jpg/ms', "_V1._SY200.jpg", $arr['poster']); 72 | $arr['poster_large'] = preg_replace('/_V1.*?.jpg/ms', "_V1._SY500.jpg", $arr['poster']); 73 | $arr['poster_full'] = preg_replace('/_V1.*?.jpg/ms', "_V1._SY0.jpg", $arr['poster']); 74 | } else { 75 | $arr['poster'] = ""; 76 | } 77 | $arr['runtime'] = trim($this->match('/Runtime:<\/h5><div class="info-content">.*?(\d+) min.*?<\/div>/ms', $html, 1)); 78 | $arr['top_250'] = trim($this->match('/Top 250: #(\d+)</ms', $html, 1)); 79 | $arr['oscars'] = trim($this->match('/Won (\d+) Oscars?\./ms', $html, 1)); 80 | if(empty($arr['oscars']) && preg_match("/Won Oscar\./i", $html)) $arr['oscars'] = "1"; 81 | $arr['awards'] = trim($this->match('/(\d+) wins/ms',$html, 1)); 82 | $arr['nominations'] = trim($this->match('/(\d+) nominations/ms',$html, 1)); 83 | $arr['votes'] = $this->match('/>([0-9,]*) votes</ms', $html, 1); 84 | $arr['language'] = $this->match_all('/<a.*?>(.*?)<\/a>/ms', $this->match('/Language.?:(.*?)(<\/div>|>.?and )/ms', $html, 1), 1); 85 | $arr['country'] = $this->match_all('/<a.*?>(.*?)<\/a>/ms', $this->match('/Country:(.*?)(<\/div>|>.?and )/ms', $html, 1), 1); 86 | 87 | if($getExtraInfo == true) { 88 | $plotPageHtml = $this->geturl("${imdbUrl}plotsummary"); 89 | $arr['storyline'] = trim(strip_tags($this->match('/<li class="odd">.*?<p>(.*?)(<|<\/p>)/ms', $plotPageHtml, 1))); 90 | $releaseinfoHtml = $this->geturl("http://www.imdb.com/title/" . $arr['title_id'] . "/releaseinfo"); 91 | $arr['also_known_as'] = $this->getAkaTitles($releaseinfoHtml); 92 | $arr['release_dates'] = $this->getReleaseDates($releaseinfoHtml); 93 | $arr['recommended_titles'] = $this->getRecommendedTitles($arr['title_id']); 94 | $arr['media_images'] = $this->getMediaImages($arr['title_id']); 95 | $arr['videos'] = $this->getVideos($arr['title_id']); 96 | } 97 | 98 | return $arr; 99 | } 100 | 101 | // Scan all Release Dates. 102 | private function getReleaseDates($html){ 103 | $releaseDates = array(); 104 | foreach($this->match_all('/<tr.*?>(.*?)<\/tr>/ms', $this->match('/<table id="release_dates".*?>(.*?)<\/table>/ms', $html, 1), 1) as $r) { 105 | $country = trim(strip_tags($this->match('/<td>(.*?)<\/td>/ms', $r, 1))); 106 | $date = trim(strip_tags($this->match('/<td class="release_date">(.*?)<\/td>/ms', $r, 1))); 107 | array_push($releaseDates, $country . " = " . $date); 108 | } 109 | return array_filter($releaseDates); 110 | } 111 | 112 | // Scan all AKA Titles. 113 | private function getAkaTitles($html){ 114 | $akaTitles = array(); 115 | foreach($this->match_all('/<tr.*?>(.*?)<\/tr>/msi', $this->match('/<table id="akas".*?>(.*?)<\/table>/ms', $html, 1), 1) as $m) { 116 | $akaTitleMatch = $this->match_all('/<td>(.*?)<\/td>/ms', $m, 1); 117 | $akaCountry = trim($akaTitleMatch[0]); 118 | $akaTitle = trim($akaTitleMatch[1]); 119 | array_push($akaTitles, $akaTitle . " = " . $akaCountry); 120 | } 121 | return array_filter($akaTitles); 122 | } 123 | 124 | // Collect all Media Images. 125 | private function getMediaImages($titleId){ 126 | $url = "http://www.imdb.com/title/" . $titleId . "/mediaindex"; 127 | $html = $this->geturl($url); 128 | $media = array(); 129 | $media = array_merge($media, $this->scanMediaImages($html)); 130 | foreach($this->match_all('/<a.*?>(\d*)<\/a>/ms', $this->match('/<span class="page_list">(.*?)<\/span>/ms', $html, 1), 1) as $p) { 131 | $html = $this->geturl($url . "?page=" . $p); 132 | $media = array_merge($media, $this->scanMediaImages($html)); 133 | } 134 | return $media; 135 | } 136 | 137 | // Scan all media images. 138 | private function scanMediaImages($html){ 139 | $pics = array(); 140 | foreach($this->match_all('/src="(.*?)"/msi', $this->match('/<div class="media_index_thumb_list".*?>(.*?)<\/div>/msi', $html, 1), 1) as $i) { 141 | array_push($pics, preg_replace('/_V1\..*?.jpg/ms', "_V1._SY0.jpg", $i)); 142 | } 143 | return array_filter($pics); 144 | } 145 | 146 | // Get recommended titles by IMDb title id. 147 | public function getRecommendedTitles($titleId){ 148 | $json = $this->geturl("http://www.imdb.com/widget/recommendations/_ajax/get_more_recs?specs=p13nsims%3A${titleId}"); 149 | $resp = json_decode($json, true); 150 | $arr = array(); 151 | if(isset($resp["recommendations"])) { 152 | foreach($resp["recommendations"] as $val) { 153 | $name = $this->match('/title="(.*?)"/msi', $val['content'], 1); 154 | $arr[$val['tconst']] = $name; 155 | } 156 | } 157 | return array_filter($arr); 158 | } 159 | 160 | // Get all Videos and Trailers 161 | public function getVideos($titleId){ 162 | $html = $this->geturl("http://www.imdb.com/title/${titleId}/videogallery"); 163 | $videos = array(); 164 | foreach ($this->match_all('/<a.*?href="(\/video\/imdb\/.*?)".*?>.*?<\/a>/ms', $html, 1) as $v) { 165 | $videos[] = "http://www.imdb.com${v}"; 166 | } 167 | return array_filter($videos); 168 | } 169 | 170 | // Get Top 250 Movie List 171 | public function getTop250(){ 172 | $html = $this->geturl("http://www.imdb.com/chart/top"); 173 | $top250 = array(); 174 | $rank = 1; 175 | foreach ($this->match_all('/<tr class="(even|odd)">(.*?)<\/tr>/ms', $html, 2) as $m) { 176 | $id = $this->match('/<td class="titleColumn">.*?<a href="\/title\/(tt\d+)\/.*?"/msi', $m, 1); 177 | $title = $this->match('/<td class="titleColumn">.*?<a.*?>(.*?)<\/a>/msi', $m, 1); 178 | $year = $this->match('/<td class="titleColumn">.*?<span class="secondaryInfo">\((.*?)\)<\/span>/msi', $m, 1); 179 | $rating = $this->match('/<td class="ratingColumn"><strong.*?>(.*?)<\/strong>/msi', $m, 1); 180 | $poster = $this->match('/<td class="posterColumn">.*?<img src="(.*?)"/msi', $m, 1); 181 | $poster = preg_replace('/_V1.*?.jpg/ms', "_V1._SY200.jpg", $poster); 182 | $url = "http://www.imdb.com/title/${id}/"; 183 | $top250[] = array("id"=>$id, "rank"=>$rank, "title"=>$title, "year"=>$year, "rating"=>$rating, "poster"=>$poster, "url"=>$url); 184 | $rank++; 185 | } 186 | return $top250; 187 | } 188 | 189 | //************************[ Extra Functions ]****************************** 190 | 191 | // Movie title search on Google, Bing or Ask. If search fails, return FALSE. 192 | private function getIMDbIdFromSearch($title, $engine = "google"){ 193 | switch ($engine) { 194 | case "google": $nextEngine = "bing"; break; 195 | case "bing": $nextEngine = "ask"; break; 196 | case "ask": $nextEngine = FALSE; break; 197 | case FALSE: return NULL; 198 | default: return NULL; 199 | } 200 | $url = "http://www.${engine}.com/search?q=imdb+" . rawurlencode($title); 201 | $ids = $this->match_all('/<a.*?href="http:\/\/www.imdb.com\/title\/(tt\d+).*?".*?>.*?<\/a>/ms', $this->geturl($url), 1); 202 | if (!isset($ids[0]) || empty($ids[0])) //if search failed 203 | return $this->getIMDbIdFromSearch($title, $nextEngine); //move to next search engine 204 | else 205 | return $ids[0]; //return first IMDb result 206 | } 207 | 208 | private function geturl($url){ 209 | $ch = curl_init(); 210 | curl_setopt($ch, CURLOPT_URL, $url); 211 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 212 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 213 | $ip=rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255); 214 | curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip")); 215 | curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/".rand(3,5).".".rand(0,3)." (Windows NT ".rand(3,5).".".rand(0,2)."; rv:2.0.1) Gecko/20100101 Firefox/".rand(3,5).".0.1"); 216 | $html = curl_exec($ch); 217 | curl_close($ch); 218 | return $html; 219 | } 220 | 221 | private function match_all_key_value($regex, $str, $keyIndex = 1, $valueIndex = 2){ 222 | $arr = array(); 223 | preg_match_all($regex, $str, $matches, PREG_SET_ORDER); 224 | foreach($matches as $m){ 225 | $arr[$m[$keyIndex]] = $m[$valueIndex]; 226 | } 227 | return $arr; 228 | } 229 | 230 | private function match_all($regex, $str, $i = 0){ 231 | if(preg_match_all($regex, $str, $matches) === false) 232 | return false; 233 | else 234 | return $matches[$i]; 235 | } 236 | 237 | private function match($regex, $str, $i = 0){ 238 | if(preg_match($regex, $str, $match) == 1) 239 | return $match[$i]; 240 | else 241 | return false; 242 | } 243 | } 244 | ?> 245 | -------------------------------------------------------------------------------- /public/js/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.1.1 (http://getbootstrap.com) 3 | * Copyright 2011-2014 Twitter, Inc. 4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 5 | */ 6 | if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one(a.support.transition.end,function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b()})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.1.1",d.prototype.close=function(b){function c(){f.detach().trigger("closed.bs.alert").remove()}var d=a(this),e=d.attr("data-target");e||(e=d.attr("href"),e=e&&e.replace(/.*(?=#[^\s]*$)/,""));var f=a(e);b&&b.preventDefault(),f.length||(f=d.hasClass("alert")?d:d.parent()),f.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(f.removeClass("in"),a.support.transition&&f.hasClass("fade")?f.one(a.support.transition.end,c).emulateTransitionEnd(150):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.1.1",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),d[e](null==f[b]?this.options[b]:f[b]),setTimeout(a.proxy(function(){"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")&&(c.prop("checked")&&this.$element.hasClass("active")?a=!1:b.find(".active").removeClass("active")),a&&c.prop("checked",!this.$element.hasClass("active")).trigger("change")}a&&this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target);d.hasClass("btn")||(d=d.closest(".btn")),b.call(d,"toggle"),c.preventDefault()})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==typeof b?e.to(b):g?e[g]():f.interval&&e.pause().cycle()})}var c=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=this.sliding=this.interval=this.$active=this.$items=null,"hover"==this.options.pause&&this.$element.on("mouseenter",a.proxy(this.pause,this)).on("mouseleave",a.proxy(this.cycle,this))};c.VERSION="3.1.1",c.DEFAULTS={interval:5e3,pause:"hover",wrap:!0},c.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},c.prototype.getItemIndex=function(a){return this.$items=a.parent().children(".item"),this.$items.index(a||this.$active)},c.prototype.to=function(b){var c=this,d=this.getItemIndex(this.$active=this.$element.find(".item.active"));return b>this.$items.length-1||0>b?void 0:this.sliding?this.$element.one("slid.bs.carousel",function(){c.to(b)}):d==b?this.pause().cycle():this.slide(b>d?"next":"prev",a(this.$items[b]))},c.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},c.prototype.next=function(){return this.sliding?void 0:this.slide("next")},c.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},c.prototype.slide=function(b,c){var d=this.$element.find(".item.active"),e=c||d[b](),f=this.interval,g="next"==b?"left":"right",h="next"==b?"first":"last",i=this;if(!e.length){if(!this.options.wrap)return;e=this.$element.find(".item")[h]()}if(e.hasClass("active"))return this.sliding=!1;var j=e[0],k=a.Event("slide.bs.carousel",{relatedTarget:j,direction:g});if(this.$element.trigger(k),!k.isDefaultPrevented()){if(this.sliding=!0,f&&this.pause(),this.$indicators.length){this.$indicators.find(".active").removeClass("active");var l=a(this.$indicators.children()[this.getItemIndex(e)]);l&&l.addClass("active")}var m=a.Event("slid.bs.carousel",{relatedTarget:j,direction:g});return a.support.transition&&this.$element.hasClass("slide")?(e.addClass(b),e[0].offsetWidth,d.addClass(g),e.addClass(g),d.one(a.support.transition.end,function(){e.removeClass([b,g].join(" ")).addClass("active"),d.removeClass(["active",g].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger(m)},0)}).emulateTransitionEnd(1e3*d.css("transition-duration").slice(0,-1))):(d.removeClass("active"),e.addClass("active"),this.sliding=!1,this.$element.trigger(m)),f&&this.cycle(),this}};var d=a.fn.carousel;a.fn.carousel=b,a.fn.carousel.Constructor=c,a.fn.carousel.noConflict=function(){return a.fn.carousel=d,this},a(document).on("click.bs.carousel.data-api","[data-slide], [data-slide-to]",function(c){var d,e=a(this),f=a(e.attr("data-target")||(d=e.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,"")),g=a.extend({},f.data(),e.data()),h=e.attr("data-slide-to");h&&(g.interval=!1),b.call(f,g),h&&f.data("bs.carousel").to(h),c.preventDefault()}),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var c=a(this);b.call(c,c.data())})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.collapse"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b);!e&&f.toggle&&"show"==b&&(b=!b),e||d.data("bs.collapse",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.transitioning=null,this.options.parent&&(this.$parent=a(this.options.parent)),this.options.toggle&&this.toggle()};c.VERSION="3.1.1",c.DEFAULTS={toggle:!0},c.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},c.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var c=a.Event("show.bs.collapse");if(this.$element.trigger(c),!c.isDefaultPrevented()){var d=this.$parent&&this.$parent.find("> .panel > .in");if(d&&d.length){var e=d.data("bs.collapse");if(e&&e.transitioning)return;b.call(d,"hide"),e||d.data("bs.collapse",null)}var f=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[f](0),this.transitioning=1;var g=function(b){return b&&b.target!=this.$element[0]?void this.$element.one(a.support.transition.end,a.proxy(g,this)):(this.$element.removeClass("collapsing").addClass("collapse in")[f](""),this.transitioning=0,void this.$element.off(a.support.transition.end+".bs.collapse").trigger("shown.bs.collapse"))};if(!a.support.transition)return g.call(this);var h=a.camelCase(["scroll",f].join("-"));this.$element.on(a.support.transition.end+".bs.collapse",a.proxy(g,this)).emulateTransitionEnd(350)[f](this.$element[0][h])}}},c.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse").removeClass("in"),this.transitioning=1;var d=function(b){return b&&b.target!=this.$element[0]?void this.$element.one(a.support.transition.end,a.proxy(d,this)):(this.transitioning=0,void this.$element.trigger("hidden.bs.collapse").removeClass("collapsing").addClass("collapse"))};return a.support.transition?void this.$element[c](0).one(a.support.transition.end,a.proxy(d,this)).emulateTransitionEnd(350):d.call(this)}}},c.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()};var d=a.fn.collapse;a.fn.collapse=b,a.fn.collapse.Constructor=c,a.fn.collapse.noConflict=function(){return a.fn.collapse=d,this},a(document).on("click.bs.collapse.data-api",'[data-toggle="collapse"]',function(c){var d,e=a(this),f=e.attr("data-target")||c.preventDefault()||(d=e.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""),g=a(f),h=g.data("bs.collapse"),i=h?"toggle":e.data(),j=e.attr("data-parent"),k=j&&a(j);h&&h.transitioning||(k&&k.find('[data-toggle="collapse"][data-parent="'+j+'"]').not(e).addClass("collapsed"),e[g.hasClass("in")?"addClass":"removeClass"]("collapsed")),b.call(g,i)})}(jQuery),+function(a){"use strict";function b(b){b&&3===b.which||(a(e).remove(),a(f).each(function(){var d=c(a(this)),e={relatedTarget:this};d.hasClass("open")&&(d.trigger(b=a.Event("hide.bs.dropdown",e)),b.isDefaultPrevented()||d.removeClass("open").trigger("hidden.bs.dropdown",e))}))}function c(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}function d(b){return this.each(function(){var c=a(this),d=c.data("bs.dropdown");d||c.data("bs.dropdown",d=new g(this)),"string"==typeof b&&d[b].call(c)})}var e=".dropdown-backdrop",f='[data-toggle="dropdown"]',g=function(b){a(b).on("click.bs.dropdown",this.toggle)};g.VERSION="3.1.1",g.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=c(e),g=f.hasClass("open");if(b(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a('<div class="dropdown-backdrop"/>').insertAfter(a(this)).on("click",b);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;e.trigger("focus"),f.toggleClass("open").trigger("shown.bs.dropdown",h)}return!1}},g.prototype.keydown=function(b){if(/(38|40|27)/.test(b.keyCode)){var d=a(this);if(b.preventDefault(),b.stopPropagation(),!d.is(".disabled, :disabled")){var e=c(d),g=e.hasClass("open");if(!g||g&&27==b.keyCode)return 27==b.which&&e.find(f).trigger("focus"),d.trigger("click");var h=" li:not(.divider):visible a",i=e.find('[role="menu"]'+h+', [role="listbox"]'+h);if(i.length){var j=i.index(i.filter(":focus"));38==b.keyCode&&j>0&&j--,40==b.keyCode&&j<i.length-1&&j++,~j||(j=0),i.eq(j).trigger("focus")}}}};var h=a.fn.dropdown;a.fn.dropdown=d,a.fn.dropdown.Constructor=g,a.fn.dropdown.noConflict=function(){return a.fn.dropdown=h,this},a(document).on("click.bs.dropdown.data-api",b).on("click.bs.dropdown.data-api",".dropdown form",function(a){a.stopPropagation()}).on("click.bs.dropdown.data-api",f,g.prototype.toggle).on("keydown.bs.dropdown.data-api",f+', [role="menu"], [role="listbox"]',g.prototype.keydown)}(jQuery),+function(a){"use strict";function b(b,d){return this.each(function(){var e=a(this),f=e.data("bs.modal"),g=a.extend({},c.DEFAULTS,e.data(),"object"==typeof b&&b);f||e.data("bs.modal",f=new c(this,g)),"string"==typeof b?f[b](d):g.show&&f.show(d)})}var c=function(b,c){this.options=c,this.$body=a(document.body),this.$element=a(b),this.$backdrop=this.isShown=null,this.scrollbarWidth=0,this.options.remote&&this.$element.find(".modal-content").load(this.options.remote,a.proxy(function(){this.$element.trigger("loaded.bs.modal")},this))};c.VERSION="3.1.1",c.DEFAULTS={backdrop:!0,keyboard:!0,show:!0},c.prototype.toggle=function(a){return this.isShown?this.hide():this.show(a)},c.prototype.show=function(b){var c=this,d=a.Event("show.bs.modal",{relatedTarget:b});this.$element.trigger(d),this.isShown||d.isDefaultPrevented()||(this.isShown=!0,this.checkScrollbar(),this.$body.addClass("modal-open"),this.setScrollbar(),this.escape(),this.$element.on("click.dismiss.bs.modal",'[data-dismiss="modal"]',a.proxy(this.hide,this)),this.backdrop(function(){var d=a.support.transition&&c.$element.hasClass("fade");c.$element.parent().length||c.$element.appendTo(c.$body),c.$element.show().scrollTop(0),d&&c.$element[0].offsetWidth,c.$element.addClass("in").attr("aria-hidden",!1),c.enforceFocus();var e=a.Event("shown.bs.modal",{relatedTarget:b});d?c.$element.find(".modal-dialog").one(a.support.transition.end,function(){c.$element.trigger("focus").trigger(e)}).emulateTransitionEnd(300):c.$element.trigger("focus").trigger(e)}))},c.prototype.hide=function(b){b&&b.preventDefault(),b=a.Event("hide.bs.modal"),this.$element.trigger(b),this.isShown&&!b.isDefaultPrevented()&&(this.isShown=!1,this.$body.removeClass("modal-open"),this.resetScrollbar(),this.escape(),a(document).off("focusin.bs.modal"),this.$element.removeClass("in").attr("aria-hidden",!0).off("click.dismiss.bs.modal"),a.support.transition&&this.$element.hasClass("fade")?this.$element.one(a.support.transition.end,a.proxy(this.hideModal,this)).emulateTransitionEnd(300):this.hideModal())},c.prototype.enforceFocus=function(){a(document).off("focusin.bs.modal").on("focusin.bs.modal",a.proxy(function(a){this.$element[0]===a.target||this.$element.has(a.target).length||this.$element.trigger("focus")},this))},c.prototype.escape=function(){this.isShown&&this.options.keyboard?this.$element.on("keyup.dismiss.bs.modal",a.proxy(function(a){27==a.which&&this.hide()},this)):this.isShown||this.$element.off("keyup.dismiss.bs.modal")},c.prototype.hideModal=function(){var a=this;this.$element.hide(),this.backdrop(function(){a.$element.trigger("hidden.bs.modal")})},c.prototype.removeBackdrop=function(){this.$backdrop&&this.$backdrop.remove(),this.$backdrop=null},c.prototype.backdrop=function(b){var c=this,d=this.$element.hasClass("fade")?"fade":"";if(this.isShown&&this.options.backdrop){var e=a.support.transition&&d;if(this.$backdrop=a('<div class="modal-backdrop '+d+'" />').appendTo(this.$body),this.$element.on("click.dismiss.bs.modal",a.proxy(function(a){a.target===a.currentTarget&&("static"==this.options.backdrop?this.$element[0].focus.call(this.$element[0]):this.hide.call(this))},this)),e&&this.$backdrop[0].offsetWidth,this.$backdrop.addClass("in"),!b)return;e?this.$backdrop.one(a.support.transition.end,b).emulateTransitionEnd(150):b()}else if(!this.isShown&&this.$backdrop){this.$backdrop.removeClass("in");var f=function(){c.removeBackdrop(),b&&b()};a.support.transition&&this.$element.hasClass("fade")?this.$backdrop.one(a.support.transition.end,f).emulateTransitionEnd(150):f()}else b&&b()},c.prototype.checkScrollbar=function(){document.body.clientWidth>=window.innerWidth||(this.scrollbarWidth=this.scrollbarWidth||this.measureScrollbar())},c.prototype.setScrollbar=function(){var a=parseInt(this.$body.css("padding-right")||0,10);this.scrollbarWidth&&this.$body.css("padding-right",a+this.scrollbarWidth)},c.prototype.resetScrollbar=function(){this.$body.css("padding-right","")},c.prototype.measureScrollbar=function(){var a=document.createElement("div");a.className="modal-scrollbar-measure",this.$body.append(a);var b=a.offsetWidth-a.clientWidth;return this.$body[0].removeChild(a),b};var d=a.fn.modal;a.fn.modal=b,a.fn.modal.Constructor=c,a.fn.modal.noConflict=function(){return a.fn.modal=d,this},a(document).on("click.bs.modal.data-api",'[data-toggle="modal"]',function(c){var d=a(this),e=d.attr("href"),f=a(d.attr("data-target")||e&&e.replace(/.*(?=#[^\s]+$)/,"")),g=f.data("bs.modal")?"toggle":a.extend({remote:!/#/.test(e)&&e},f.data(),d.data());d.is("a")&&c.preventDefault(),f.one("show.bs.modal",function(a){a.isDefaultPrevented()||f.one("hidden.bs.modal",function(){d.is(":visible")&&d.trigger("focus")})}),b.call(f,g,this)})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.tooltip"),f="object"==typeof b&&b;(e||"destroy"!=b)&&(e||d.data("bs.tooltip",e=new c(this,f)),"string"==typeof b&&e[b]())})}var c=function(a,b){this.type=this.options=this.enabled=this.timeout=this.hoverState=this.$element=null,this.init("tooltip",a,b)};c.VERSION="3.1.1",c.DEFAULTS={animation:!0,placement:"top",selector:!1,template:'<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',trigger:"hover focus",title:"",delay:0,html:!1,container:!1,viewport:{selector:"body",padding:0}},c.prototype.init=function(b,c,d){this.enabled=!0,this.type=b,this.$element=a(c),this.options=this.getOptions(d),this.$viewport=this.options.viewport&&a(this.options.viewport.selector||this.options.viewport);for(var e=this.options.trigger.split(" "),f=e.length;f--;){var g=e[f];if("click"==g)this.$element.on("click."+this.type,this.options.selector,a.proxy(this.toggle,this));else if("manual"!=g){var h="hover"==g?"mouseenter":"focusin",i="hover"==g?"mouseleave":"focusout";this.$element.on(h+"."+this.type,this.options.selector,a.proxy(this.enter,this)),this.$element.on(i+"."+this.type,this.options.selector,a.proxy(this.leave,this))}}this.options.selector?this._options=a.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.getOptions=function(b){return b=a.extend({},this.getDefaults(),this.$element.data(),b),b.delay&&"number"==typeof b.delay&&(b.delay={show:b.delay,hide:b.delay}),b},c.prototype.getDelegateOptions=function(){var b={},c=this.getDefaults();return this._options&&a.each(this._options,function(a,d){c[a]!=d&&(b[a]=d)}),b},c.prototype.enter=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),clearTimeout(c.timeout),c.hoverState="in",c.options.delay&&c.options.delay.show?void(c.timeout=setTimeout(function(){"in"==c.hoverState&&c.show()},c.options.delay.show)):c.show()},c.prototype.leave=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),clearTimeout(c.timeout),c.hoverState="out",c.options.delay&&c.options.delay.hide?void(c.timeout=setTimeout(function(){"out"==c.hoverState&&c.hide()},c.options.delay.hide)):c.hide()},c.prototype.show=function(){var b=a.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){this.$element.trigger(b);var c=a.contains(document.documentElement,this.$element[0]);if(b.isDefaultPrevented()||!c)return;var d=this,e=this.tip(),f=this.getUID(this.type);this.setContent(),e.attr("id",f),this.$element.attr("aria-describedby",f),this.options.animation&&e.addClass("fade");var g="function"==typeof this.options.placement?this.options.placement.call(this,e[0],this.$element[0]):this.options.placement,h=/\s?auto?\s?/i,i=h.test(g);i&&(g=g.replace(h,"")||"top"),e.detach().css({top:0,left:0,display:"block"}).addClass(g).data("bs."+this.type,this),this.options.container?e.appendTo(this.options.container):e.insertAfter(this.$element);var j=this.getPosition(),k=e[0].offsetWidth,l=e[0].offsetHeight;if(i){var m=g,n=this.$element.parent(),o=this.getPosition(n);g="bottom"==g&&j.top+j.height+l-o.scroll>o.height?"top":"top"==g&&j.top-o.scroll-l<0?"bottom":"right"==g&&j.right+k>o.width?"left":"left"==g&&j.left-k<o.left?"right":g,e.removeClass(m).addClass(g)}var p=this.getCalculatedOffset(g,j,k,l);this.applyPlacement(p,g),this.hoverState=null;var q=function(){d.$element.trigger("shown.bs."+d.type)};a.support.transition&&this.$tip.hasClass("fade")?e.one(a.support.transition.end,q).emulateTransitionEnd(150):q()}},c.prototype.applyPlacement=function(b,c){var d=this.tip(),e=d[0].offsetWidth,f=d[0].offsetHeight,g=parseInt(d.css("margin-top"),10),h=parseInt(d.css("margin-left"),10);isNaN(g)&&(g=0),isNaN(h)&&(h=0),b.top=b.top+g,b.left=b.left+h,a.offset.setOffset(d[0],a.extend({using:function(a){d.css({top:Math.round(a.top),left:Math.round(a.left)})}},b),0),d.addClass("in");var i=d[0].offsetWidth,j=d[0].offsetHeight;"top"==c&&j!=f&&(b.top=b.top+f-j);var k=this.getViewportAdjustedDelta(c,b,i,j);k.left?b.left+=k.left:b.top+=k.top;var l=k.left?2*k.left-e+i:2*k.top-f+j,m=k.left?"left":"top",n=k.left?"offsetWidth":"offsetHeight";d.offset(b),this.replaceArrow(l,d[0][n],m)},c.prototype.replaceArrow=function(a,b,c){this.arrow().css(c,a?50*(1-a/b)+"%":"")},c.prototype.setContent=function(){var a=this.tip(),b=this.getTitle();a.find(".tooltip-inner")[this.options.html?"html":"text"](b),a.removeClass("fade in top bottom left right")},c.prototype.hide=function(){function b(){"in"!=c.hoverState&&d.detach(),c.$element.trigger("hidden.bs."+c.type)}var c=this,d=this.tip(),e=a.Event("hide.bs."+this.type);return this.$element.removeAttr("aria-describedby"),this.$element.trigger(e),e.isDefaultPrevented()?void 0:(d.removeClass("in"),a.support.transition&&this.$tip.hasClass("fade")?d.one(a.support.transition.end,b).emulateTransitionEnd(150):b(),this.hoverState=null,this)},c.prototype.fixTitle=function(){var a=this.$element;(a.attr("title")||"string"!=typeof a.attr("data-original-title"))&&a.attr("data-original-title",a.attr("title")||"").attr("title","")},c.prototype.hasContent=function(){return this.getTitle()},c.prototype.getPosition=function(b){b=b||this.$element;var c=b[0],d="BODY"==c.tagName;return a.extend({},"function"==typeof c.getBoundingClientRect?c.getBoundingClientRect():null,{scroll:d?document.documentElement.scrollTop||document.body.scrollTop:b.scrollTop(),width:d?a(window).width():b.outerWidth(),height:d?a(window).height():b.outerHeight()},d?{top:0,left:0}:b.offset())},c.prototype.getCalculatedOffset=function(a,b,c,d){return"bottom"==a?{top:b.top+b.height,left:b.left+b.width/2-c/2}:"top"==a?{top:b.top-d,left:b.left+b.width/2-c/2}:"left"==a?{top:b.top+b.height/2-d/2,left:b.left-c}:{top:b.top+b.height/2-d/2,left:b.left+b.width}},c.prototype.getViewportAdjustedDelta=function(a,b,c,d){var e={top:0,left:0};if(!this.$viewport)return e;var f=this.options.viewport&&this.options.viewport.padding||0,g=this.getPosition(this.$viewport);if(/right|left/.test(a)){var h=b.top-f-g.scroll,i=b.top+f-g.scroll+d;h<g.top?e.top=g.top-h:i>g.top+g.height&&(e.top=g.top+g.height-i)}else{var j=b.left-f,k=b.left+f+c;j<g.left?e.left=g.left-j:k>g.width&&(e.left=g.left+g.width-k)}return e},c.prototype.getTitle=function(){var a,b=this.$element,c=this.options;return a=b.attr("data-original-title")||("function"==typeof c.title?c.title.call(b[0]):c.title)},c.prototype.getUID=function(a){do a+=~~(1e6*Math.random());while(document.getElementById(a));return a},c.prototype.tip=function(){return this.$tip=this.$tip||a(this.options.template)},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")},c.prototype.validate=function(){this.$element[0].parentNode||(this.hide(),this.$element=null,this.options=null)},c.prototype.enable=function(){this.enabled=!0},c.prototype.disable=function(){this.enabled=!1},c.prototype.toggleEnabled=function(){this.enabled=!this.enabled},c.prototype.toggle=function(b){var c=this;b&&(c=a(b.currentTarget).data("bs."+this.type),c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c))),c.tip().hasClass("in")?c.leave(c):c.enter(c)},c.prototype.destroy=function(){clearTimeout(this.timeout),this.hide().$element.off("."+this.type).removeData("bs."+this.type)};var d=a.fn.tooltip;a.fn.tooltip=b,a.fn.tooltip.Constructor=c,a.fn.tooltip.noConflict=function(){return a.fn.tooltip=d,this}}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof b&&b;(e||"destroy"!=b)&&(e||d.data("bs.popover",e=new c(this,f)),"string"==typeof b&&e[b]())})}var c=function(a,b){this.init("popover",a,b)};if(!a.fn.tooltip)throw new Error("Popover requires tooltip.js");c.VERSION="3.1.1",c.DEFAULTS=a.extend({},a.fn.tooltip.Constructor.DEFAULTS,{placement:"right",trigger:"click",content:"",template:'<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'}),c.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),c.prototype.constructor=c,c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content").empty()[this.options.html?"string"==typeof c?"html":"append":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},c.prototype.hasContent=function(){return this.getTitle()||this.getContent()},c.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")},c.prototype.tip=function(){return this.$tip||(this.$tip=a(this.options.template)),this.$tip};var d=a.fn.popover;a.fn.popover=b,a.fn.popover.Constructor=c,a.fn.popover.noConflict=function(){return a.fn.popover=d,this}}(jQuery),+function(a){"use strict";function b(c,d){var e=a.proxy(this.process,this);this.$body=a("body"),this.$scrollElement=a(a(c).is("body")?window:c),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||"")+" .nav li > a",this.offsets=[],this.targets=[],this.activeTarget=null,this.$scrollElement.on("scroll.bs.scrollspy",e),this.refresh(),this.process()}function c(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})}b.VERSION="3.1.1",b.DEFAULTS={offset:10},b.prototype.refresh=function(){var b="offset",c=0;a.isWindow(this.$scrollElement[0])||(b="position",c=this.$scrollElement.scrollTop()),this.offsets=[],this.targets=[];var d=this;this.$body.find(this.selector).map(function(){var d=a(this),e=d.data("target")||d.attr("href"),f=/^#./.test(e)&&a(e);return f&&f.length&&f.is(":visible")&&[[f[b]().top+c,e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){d.offsets.push(this[0]),d.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.$scrollElement[0].scrollHeight||Math.max(this.$body[0].scrollHeight,document.documentElement.scrollHeight),d=this.options.offset+c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(b>=d)return g!=(a=f[f.length-1])&&this.activate(a);if(g&&b<=e[0])return g!=(a=f[0])&&this.activate(a);for(a=e.length;a--;)g!=f[a]&&b>=e[a]&&(!e[a+1]||b<=e[a+1])&&this.activate(f[a])},b.prototype.activate=function(b){this.activeTarget=b,a(this.selector).parentsUntil(this.options.target,".active").removeClass("active");var c=this.selector+'[data-target="'+b+'"],'+this.selector+'[href="'+b+'"]',d=a(c).parents("li").addClass("active");d.parent(".dropdown-menu").length&&(d=d.closest("li.dropdown").addClass("active")),d.trigger("activate.bs.scrollspy")};var d=a.fn.scrollspy;a.fn.scrollspy=c,a.fn.scrollspy.Constructor=b,a.fn.scrollspy.noConflict=function(){return a.fn.scrollspy=d,this},a(window).on("load.bs.scrollspy.data-api",function(){a('[data-spy="scroll"]').each(function(){var b=a(this);c.call(b,b.data())})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.tab");e||d.data("bs.tab",e=new c(this)),"string"==typeof b&&e[b]()})}var c=function(b){this.element=a(b)};c.VERSION="3.1.1",c.prototype.show=function(){var b=this.element,c=b.closest("ul:not(.dropdown-menu)"),d=b.data("target");if(d||(d=b.attr("href"),d=d&&d.replace(/.*(?=#[^\s]*$)/,"")),!b.parent("li").hasClass("active")){var e=c.find(".active:last a")[0],f=a.Event("show.bs.tab",{relatedTarget:e});if(b.trigger(f),!f.isDefaultPrevented()){var g=a(d);this.activate(b.closest("li"),c),this.activate(g,g.parent(),function(){b.trigger({type:"shown.bs.tab",relatedTarget:e})})}}},c.prototype.activate=function(b,c,d){function e(){f.removeClass("active").find("> .dropdown-menu > .active").removeClass("active"),b.addClass("active"),g?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu")&&b.closest("li.dropdown").addClass("active"),d&&d()}var f=c.find("> .active"),g=d&&a.support.transition&&f.hasClass("fade");g?f.one(a.support.transition.end,e).emulateTransitionEnd(150):e(),f.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this},a(document).on("click.bs.tab.data-api",'[data-toggle="tab"], [data-toggle="pill"]',function(c){c.preventDefault(),b.call(a(this),"show")})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=this.unpin=this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.1.1",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=a(document).height(),d=this.$target.scrollTop(),e=this.$element.offset(),f=this.options.offset,g=f.top,h=f.bottom;"object"!=typeof f&&(h=g=f),"function"==typeof g&&(g=f.top(this.$element)),"function"==typeof h&&(h=f.bottom(this.$element));var i=null!=this.unpin&&d+this.unpin<=e.top?!1:null!=h&&e.top+this.$element.height()>=b-h?"bottom":null!=g&&g>=d?"top":!1;if(this.affixed!==i){null!=this.unpin&&this.$element.css("top","");var j="affix"+(i?"-"+i:""),k=a.Event(j+".bs.affix");this.$element.trigger(k),k.isDefaultPrevented()||(this.affixed=i,this.unpin="bottom"==i?this.getPinnedOffset():null,this.$element.removeClass(c.RESET).addClass(j).trigger(a.Event(j.replace("affix","affixed"))),"bottom"==i&&this.$element.offset({top:b-this.$element.height()-h}))}}};var d=a.fn.affix;a.fn.affix=b,a.fn.affix.Constructor=c,a.fn.affix.noConflict=function(){return a.fn.affix=d,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var c=a(this),d=c.data();d.offset=d.offset||{},d.offsetBottom&&(d.offset.bottom=d.offsetBottom),d.offsetTop&&(d.offset.top=d.offsetTop),b.call(c,d)})})}(jQuery); -------------------------------------------------------------------------------- /models/movie.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /* 3 | * Project: Nathan MVC 4 | * File: /models/home.php 5 | * Purpose: model for the home controller. 6 | * Author: Nathan Davison 7 | */ 8 | 9 | class MovieModel extends BaseModel { 10 | //data passed to the home index view 11 | public function index() { 12 | $ar = new ArrayTools(); 13 | 14 | foreach ($this -> urlValues AS $key => $value) { 15 | if (substr($key, 0, 2) == 'id') { 16 | $glink .= $value . '/'; 17 | $ylink .= $value . '/'; 18 | $alink .= $value . '/'; 19 | $dlink .= $value . '/'; 20 | if (substr($value, 0, 1) == 'g') { 21 | $genre = substr($value, 1); 22 | $glink = substr($glink, 0, strlen($glink) - (strlen($value) + 1)); 23 | } elseif (substr($value, 0, 1) == 'y') { 24 | $year = substr($value, 1); 25 | $ylink = substr($ylink, 0, strlen($ylink) - (strlen($value) + 1)); 26 | } elseif (substr($value, 0, 1) == 'a') { 27 | $actor = substr($value, 1); 28 | $alink = substr($alink, 0, strlen($alink) - (strlen($value) + 1)); 29 | } elseif (substr($value, 0, 1) == 'd') { 30 | $director = substr($value, 1); 31 | $dlink = substr($dlink, 0, strlen($dlink) - (strlen($value) + 1)); 32 | } 33 | } 34 | } 35 | 36 | $glink = rtrim($glink, '/'); 37 | $ylink = rtrim($ylink, '/'); 38 | $alink = rtrim($alink, '/'); 39 | $dlink = rtrim($dlink, '/'); 40 | 41 | $param = array(); 42 | $SQL = "SELECT allMovies.id, allMovies.title, allMovies.year, allMovies.genre"; 43 | if (strlen($actor) > 0 && strlen($director) == 0) { 44 | $SQL .= ", group_concat(DISTINCT concat(directors.id,':',directors.director) separator '|') AS directors"; 45 | } elseif (strlen($actor) == 0 && strlen($director) > 0) { 46 | $SQL .= ", group_concat(DISTINCT concat(actors.id,':',actors.actor) separator '|') AS actors"; 47 | } 48 | $SQL .= " FROM allMovies"; 49 | 50 | if (strlen($actor) > 0 || strlen($director) > 0) { 51 | $SQL .= " JOIN actorsinmovies ON allMovies.id = actorsinmovies.movie_id 52 | JOIN directorsinmovies ON directorsinmovies.movie_id = allMovies.id"; 53 | if (strlen($actor) > 0 && strlen($director) == 0) { 54 | $SQL .= " JOIN directors ON directors.id = directorsinmovies.director_id"; 55 | } elseif (strlen($actor) == 0 && strlen($director) > 0) { 56 | $SQL .= " JOIN actors ON actors.id = actorsinmovies.actor_id"; 57 | } 58 | } 59 | $SQL .= " WHERE"; 60 | if (strlen($actor) > 0) { 61 | $SQL .= " actorsinmovies.actor_id = :aid AND"; 62 | $param = array_merge($param, array(':aid' => $actor)); 63 | } 64 | if (strlen($director) > 0) { 65 | $SQL .= " directorsinmovies.director_id = :did AND"; 66 | $param = array_merge($param, array(':did' => $director)); 67 | } 68 | if (strlen($genre) > 0) { 69 | $SQL .= " (genre LIKE :genre1 OR genre LIKE :genre2 OR genre LIKE :genre3) AND"; 70 | $param = array_merge($param, array(':genre1' => '%|' . $genre . ':%', ':genre2' => $genre . ':%', ':genre3' => '%|' . $genre)); 71 | } 72 | if (strlen($year) > 0) { 73 | $SQL .= " year = :year AND"; 74 | $param = array_merge($param, array(':year' => $year)); 75 | } 76 | $SQL .= " 1=1 GROUP BY allMovies.id ORDER BY allMovies.title "; 77 | 78 | $result = $this -> db -> select_query($SQL, $param); 79 | 80 | $i = 0; 81 | foreach ($result AS $value) { 82 | $actors[] = explode('|', $value['actors']); 83 | $directors[] = explode('|', $value['directors']); 84 | $tableBody[$i][0] = '<a href="' . URL . 'movie/display/' . $value['id'] . '">' . $value['title'] . '</a>'; 85 | $tableBody[$i][1] = '<a href="' . rtrim(URL . 'movie/index/' . $ylink, '/') . '/y' . $value['year'] . '">' . $value['year'] . '</a>'; 86 | $genres = explode('|', $value['genre']); 87 | foreach ($genres AS $value2) { 88 | $localgenre = explode(':', $value2); 89 | $tableBody[$i][2] .= '<a href="' . rtrim(URL . 'movie/index/' . $glink, '/') . '/g' . $localgenre[0] . '">' . $localgenre[1] . '</a>'; 90 | if (end($genres) !== $value2) { 91 | $tableBody[$i][2] .= ', '; 92 | } 93 | } 94 | $i++; 95 | } 96 | 97 | foreach ($ar -> unique_flat_array($actors) as $value) { 98 | if (strlen($value) != 0) { 99 | $local = explode(':', $value); 100 | $actorsout .= '<a href="' . rtrim(URL . 'movie/index/' . $alink, '/') . '/a' . $local[0] . '">' . $local[1] . '</a>'; 101 | if ($value !== end($ar -> unique_flat_array($actors))) 102 | $actorsout .= ', '; 103 | } 104 | } 105 | foreach ($ar -> unique_flat_array($directors) as $value) { 106 | if (strlen($value) != 0) { 107 | $local = explode(':', $value); 108 | $directorsout .= '<a href="' . rtrim(URL . 'movie/index/' . $dlink, '/') . '/d' . $local[0] . '">' . $local[1] . '</a>'; 109 | if ($value !== end($ar -> unique_flat_array($directors))) 110 | $directorsout .= ', '; 111 | } 112 | } 113 | 114 | $this -> viewModel -> set('actors', trim($actorsout, ',')); 115 | $this -> viewModel -> set('directors', trim($directorsout, ',')); 116 | $this -> viewModel -> set('tableHead', array('Film', 'År', 'Genre')); 117 | $this -> viewModel -> set('tableBody', $tableBody); 118 | $this -> viewModel -> set('urlValues', $this -> urlValues); 119 | $this -> viewModel -> set('pageTitle', TITLE . 'Alla filmer'); 120 | return $this -> viewModel; 121 | } 122 | 123 | public function display() { 124 | $id = $this -> urlValues['id']; 125 | $ar = new ArrayTools(); 126 | 127 | $sql = "SELECT movies.youtube, movies.imdbid, movies.runtime, movies.title, movies.year, movies.poster, movies.plot, movies.sub, group_concat(DISTINCT concat(actors.id,',',actors.actor) separator '|') AS actor, group_concat(DISTINCT concat(directors.id,',',directors.director) separator '|') AS director, movietype.type, group_concat(DISTINCT concat(genres.id,',',genres.genre) separator '|') AS genre, series.name AS seriesname, series.id AS seriesid 128 | FROM movies 129 | LEFT JOIN actorsinmovies ON movies.id = actorsinmovies.movie_id 130 | LEFT JOIN actors ON actors.id = actorsinmovies.actor_id 131 | LEFT JOIN directorsinmovies ON movies.id = directorsinmovies.movie_id 132 | LEFT JOIN directors ON directorsinmovies.director_id = directors.id 133 | LEFT JOIN movietype ON movies.type = movietype.short 134 | LEFT JOIN genresinmovies ON movies.id = genresinmovies.movie_id 135 | LEFT JOIN genres ON genresinmovies.genre_id = genres.id 136 | LEFT JOIN moviesinseries ON movies.id = moviesinseries.movieID 137 | LEFT JOIN series ON moviesinseries.seriesID = series.id 138 | WHERE movies.id = :id 139 | GROUP BY movies.id"; 140 | 141 | $result = $this -> db -> select_query($sql, array(':id' => $id)); 142 | $result = $result[0]; 143 | 144 | $sql = "SELECT user_id, value FROM uservote 145 | WHERE movie_id = :movieid"; 146 | 147 | $votes = $this -> db -> select_query($sql, array(':movieid' => $id)); 148 | 149 | $averagepoint = 0; 150 | $numberofvoters = 0; 151 | 152 | $sql = "SELECT id, name FROM users"; 153 | 154 | $users = $this -> db -> select_query($sql); 155 | 156 | foreach ($votes as $value) { 157 | foreach ($users as $key => $value2) { 158 | if ($value2['id'] == $value['user_id']) { 159 | $users[$key]['value'] = $value['value']; 160 | } 161 | } 162 | $averagepoint += $value['value']; 163 | if (isset($value['value'])) { 164 | $numberofvoters++; 165 | } 166 | } 167 | 168 | $sql = "SELECT userid FROM userviewed 169 | WHERE movieid = :id"; 170 | 171 | $viewed = $ar -> unique_flat_array($this -> db -> select_query($sql, array(':id' => $id))); 172 | 173 | $sql = "SELECT userid FROM towatch 174 | WHERE movieid = :id"; 175 | 176 | $towatch = $ar -> unique_flat_array($this -> db -> select_query($sql, array(':id' => $id))); 177 | 178 | $sql = "SELECT usercomment.comment, users.name, usercomment.date FROM usercomment 179 | JOIN users ON usercomment.userid = users.id 180 | WHERE usercomment.movieid = :id 181 | ORDER BY usercomment.date, usercomment.id DESC"; 182 | 183 | $comments = $this -> db -> select_query($sql, array(':id' => $id)); 184 | 185 | $sql = "SELECT userid FROM towatchagain WHERE movieid = :id"; 186 | $watchagain = $ar -> unique_flat_array($this -> db -> select_query($sql, array(':id' => $id))); 187 | 188 | foreach ($users as $key => $value) { 189 | $usertable[$key][0] = $value['name']; 190 | 191 | if (in_array($key + 1, $viewed)) { 192 | $usertable[$key][1] .= '<span class="glyphicon glyphicon-ok"></span>'; 193 | } else { 194 | if ($_SESSION['user_id'] == $key + 1) { 195 | $usertable[$key][1] .= '<a href="' . URL . 'movie/viewed/' . $id . '" class="glyphicon glyphicon-remove"></a>'; 196 | } else { 197 | $usertable[$key][1] .= '<a class="glyphicon glyphicon-remove novote"></a>'; 198 | } 199 | } 200 | 201 | for ($i = 1; $i <= 5; $i++) { 202 | if ($value['value'] == $i) { 203 | $usertable[$key][2] .= '<a class="vote">' . $i . '</a> '; 204 | } else { 205 | if ($_SESSION['user_id'] == $key + 1) { 206 | $usertable[$key][2] .= '<a href="' . URL . 'movie/vote/' . $id . '/' . $i . '">' . $i . '</a> '; 207 | } else { 208 | $usertable[$key][2] .= '<a class="novote">' . $i . '</a> '; 209 | } 210 | } 211 | } 212 | 213 | if (in_array($key + 1, $towatch)) { 214 | $usertable[$key][3] .= '<span class="glyphicon glyphicon-ok"></span>'; 215 | } else { 216 | if ($_SESSION['user_id'] == $key + 1) { 217 | if (!in_array($_SESSION['user_id'], $viewed)) { 218 | $usertable[$key][3] .= '<a href="' . URL . 'movie/towatch/' . $id . '" class="glyphicon glyphicon-remove"></a>'; 219 | } else { 220 | $usertable[$key][3] .= '<a class="glyphicon glyphicon-remove novote"></a>'; 221 | } 222 | } else { 223 | $usertable[$key][3] .= '<a class="glyphicon glyphicon-remove novote"></a>'; 224 | } 225 | } 226 | 227 | if (in_array($key + 1, $viewed)) { 228 | if(in_array($key + 1, $watchagain) && $_SESSION['user_id'] == $key + 1) { 229 | $usertable[$key][4] .= '<a href="' . URL . 'movie/towatchagain/watched/' . $id . '" class="glyphicon glyphicon-ok"></a>'; 230 | } elseif ($_SESSION['user_id'] == $key + 1) { 231 | $usertable[$key][4] .= '<a href="' . URL . 'movie/towatchagain/again/' . $id . '" class="glyphicon glyphicon-remove"></a>'; 232 | } elseif (in_array($key + 1, $watchagain)) { 233 | $usertable[$key][4] .= '<span class="glyphicon glyphicon-ok"></span>'; 234 | } else { 235 | $usertable[$key][4] .= '<span class="glyphicon glyphicon-remove"></span>'; 236 | } 237 | } else { 238 | $usertable[$key][4] .= '<span class="glyphicon glyphicon-remove"></span>'; 239 | } 240 | } 241 | 242 | $this -> viewModel -> set('comments', $comments); 243 | $this -> viewModel -> set('betygHead', array('Namn', 'Sedd', 'Betyg', 'Att se', 'Se igen')); 244 | $this -> viewModel -> set('betygBody', $usertable); 245 | $this -> viewModel -> set('avgPoints', number_format($averagepoint / $numberofvoters, 1)); 246 | $this -> viewModel -> set('seriesid', $result['seriesid']); 247 | $this -> viewModel -> set('seriesname', $result['seriesname']); 248 | $this -> viewModel -> set('imdbid', $result['imdbid']); 249 | $this -> viewModel -> set('runtime', $result['runtime']); 250 | $this -> viewModel -> set('title', $result['title']); 251 | $this -> viewModel -> set('year', $result['year']); 252 | $this -> viewModel -> set('poster', $result['poster']); 253 | $this -> viewModel -> set('plot', $result['plot']); 254 | $this -> viewModel -> set('sub', $result['sub']); 255 | $this -> viewModel -> set('actor', $result['actor']); 256 | $this -> viewModel -> set('director', $result['director']); 257 | $this -> viewModel -> set('type', $result['type']); 258 | $this -> viewModel -> set('genre', $result['genre']); 259 | $this -> viewModel -> set('youtube', $result['youtube']); 260 | $this -> viewModel -> set('id', $result['id']); 261 | $this -> viewModel -> set('urlValues', $this -> urlValues); 262 | $this -> viewModel -> set('pageTitle', TITLE . $result['title']); 263 | return $this -> viewModel; 264 | } 265 | 266 | public function vote() { 267 | $url = filter_var_array($this -> urlValues, FILTER_VALIDATE_INT); 268 | if ($url['id'] && $url['id2']) { 269 | $param = array(':mid' => $url['id'], ':uid' => $_SESSION['user_id']); 270 | $ar = new ArrayTools(); 271 | 272 | $sql = "SELECT count(*) FROM `userviewed` WHERE 273 | `movieid` = :mid AND `userid` = :uid"; 274 | 275 | $result = $ar -> unique_flat_array($this -> db -> select_query($sql, $param)); 276 | 277 | if ($result[0] == 0) { 278 | $sql = "INSERT INTO userviewed (userid, movieid, date) 279 | VALUE (:uid,:mid,NOW())"; 280 | 281 | $this -> db -> select_query($sql, $param); 282 | } 283 | $sql = "SELECT user_id FROM `uservote` 284 | WHERE `user_id` = :uid AND `movie_id` = :mid"; 285 | 286 | $result = $ar -> unique_flat_array($this -> db -> select_query($sql, $param)); 287 | var_dump($result); 288 | if (empty($result)) { 289 | $sql = "INSERT INTO `uservote`(`user_id`, `movie_id`, `value`, date) 290 | VALUES (:uid,:mid,:vote, NOW())"; 291 | $param = array(':mid' => $url['id'], ':uid' => $_SESSION['user_id'], ':vote' => $url['id2']); 292 | 293 | $this -> db -> select_query($sql, $param); 294 | } else { 295 | $sql = "UPDATE `uservote` SET `value`=:vote , `date` = NOW() 296 | WHERE `movie_id` = :mid AND `user_id` = :uid"; 297 | $param = array(':mid' => $url['id'], ':uid' => $_SESSION['user_id'], ':vote' => $url['id2']); 298 | 299 | $this -> db -> select_query($sql, $param); 300 | } 301 | 302 | $sql = "DELETE FROM `towatchagain` WHERE `movieid`=:mid AND `userid`=:uid"; 303 | $param = array(':mid' => $url['id'], ':uid' => $_SESSION['user_id']); 304 | $this -> db -> select_query($sql, $param); 305 | 306 | header('location:' . URL . 'movie/display/' . $url['id']); 307 | } 308 | $this -> viewModel -> set('urlValues', $this -> urlValues); 309 | $this -> viewModel -> set('pageTitle', TITLE . 'Fel!'); 310 | return $this -> viewModel; 311 | } 312 | 313 | public function towatch() { 314 | $url = filter_var_array($this -> urlValues, FILTER_VALIDATE_INT); 315 | if ($url['id']) { 316 | $sql = "INSERT INTO towatch(movieid, userid, date) 317 | VALUES (:mid,:uid,now())"; 318 | $param = array(':mid' => $url['id'], ':uid' => $_SESSION['user_id']); 319 | $this -> db -> select_query($sql, $param); 320 | header('location:' . URL . 'movie/display/' . $url['id']); 321 | } 322 | $this -> viewModel -> set('urlValues', $this -> urlValues); 323 | $this -> viewModel -> set('pageTitle', TITLE . 'Fel!'); 324 | return $this -> viewModel; 325 | } 326 | 327 | public function towatchagain() { 328 | $url = $this -> urlValues; 329 | if ($url['id'] && $url['id'] == "again") { 330 | $sql = "INSERT INTO towatchagain(movieid, userid, added) 331 | VALUES (:mid,:uid,now())"; 332 | $param = array(':mid' => $url['id2'], ':uid' => $_SESSION['user_id']); 333 | $this -> db -> select_query($sql, $param); 334 | header('location:' . URL . 'movie/display/' . $url['id2']); 335 | } elseif ($url['id']) { 336 | $sql = "DELETE FROM `towatchagain` WHERE `movieid`=:mid AND `userid`=:uid"; 337 | $param = array(':mid' => $url['id2'], ':uid' => $_SESSION['user_id']); 338 | $this -> db -> select_query($sql, $param); 339 | header('location:' . URL . 'movie/display/' . $url['id2']); 340 | } 341 | $this -> viewModel -> set('urlValues', $this -> urlValues); 342 | $this -> viewModel -> set('pageTitle', TITLE . 'Fel!'); 343 | return $this -> viewModel; 344 | } 345 | 346 | public function viewed() { 347 | $url = filter_var_array($this -> urlValues, FILTER_VALIDATE_INT); 348 | if ($url['id']) { 349 | $sql = "INSERT INTO userviewed (userid, movieid, date) 350 | VALUE (:uid,:mid,NOW())"; 351 | $param = array(':mid' => $url['id'], ':uid' => $_SESSION['user_id']); 352 | $this -> db -> select_query($sql, $param); 353 | header('location:' . URL . 'movie/display/' . $url['id']); 354 | } 355 | $this -> viewModel -> set('urlValues', $this -> urlValues); 356 | $this -> viewModel -> set('pageTitle', TITLE . 'Fel!'); 357 | return $this -> viewModel; 358 | } 359 | 360 | public function edit() { 361 | $id = $this -> urlValues['id']; 362 | $ar = new ArrayTools(); 363 | 364 | $sql = "SELECT movies.youtube, movies.imdbid, movies.runtime, movies.title, movies.year, movies.poster, movies.plot, movies.sub, group_concat(DISTINCT concat(actors.id,',',actors.actor) separator '|') AS actor, group_concat(DISTINCT concat(directors.id,',',directors.director) separator '|') AS director, movietype.type, group_concat(DISTINCT concat(genres.id,',',genres.genre) separator '|') AS genre 365 | FROM movies 366 | LEFT JOIN actorsinmovies ON movies.id = actorsinmovies.movie_id 367 | LEFT JOIN actors ON actors.id = actorsinmovies.actor_id 368 | LEFT JOIN directorsinmovies ON movies.id = directorsinmovies.movie_id 369 | LEFT JOIN directors ON directorsinmovies.director_id = directors.id 370 | LEFT JOIN movietype ON movies.type = movietype.short 371 | LEFT JOIN genresinmovies ON movies.id = genresinmovies.movie_id 372 | LEFT JOIN genres ON genresinmovies.genre_id = genres.id 373 | WHERE movies.id = :id 374 | GROUP BY movies.id"; 375 | 376 | $result = $this -> db -> select_query($sql, array(':id' => $id)); 377 | $result = $result[0]; 378 | 379 | $types = $this -> db -> select_query("SELECT short, type FROM movietype"); 380 | foreach ($types as $value) { 381 | $types2[$value['short']] = $value['type']; 382 | } 383 | $actors = $this -> db -> select_query("SELECT id,actor FROM actors"); 384 | foreach ($actors as $value) { 385 | $actors2[$value['id']] = $value['actor']; 386 | } 387 | 388 | $comments = $this -> db -> select_query("SELECT `comment`,`id` FROM `usercomment` WHERE `userid` = :uid AND `movieid` = :mid ORDER BY `id` DESC", array(':uid' => $_SESSION['user_id'], ':mid' => $id)); 389 | 390 | $sql = "SELECT series.name, moviesinseries.number FROM moviesinseries 391 | JOIN series ON moviesinseries.seriesID = series.id 392 | WHERE moviesinseries.movieID = :id"; 393 | $serie = $this -> db -> select_query($sql, array(":id" => $id)); 394 | 395 | $series = $this -> db -> select_query("SELECT series.id, series.name FROM series"); 396 | 397 | $this -> viewModel -> set('series', $series); 398 | $this -> viewModel -> set('number', $serie[0]["number"]); 399 | $this -> viewModel -> set('theSerie', $serie[0]["name"]); 400 | $this -> viewModel -> set('comments', $comments); 401 | $this -> viewModel -> set('actors', $actors2); 402 | $this -> viewModel -> set('types', $types2); 403 | $this -> viewModel -> set('imdbid', $result['imdbid']); 404 | $this -> viewModel -> set('runtime', $result['runtime']); 405 | $this -> viewModel -> set('title', $result['title']); 406 | $this -> viewModel -> set('year', $result['year']); 407 | $this -> viewModel -> set('poster', $result['poster']); 408 | $this -> viewModel -> set('plot', $result['plot']); 409 | $this -> viewModel -> set('sub', $result['sub']); 410 | $this -> viewModel -> set('actor', $result['actor']); 411 | $this -> viewModel -> set('director', $result['director']); 412 | $this -> viewModel -> set('type', $result['type']); 413 | $this -> viewModel -> set('genre', $result['genre']); 414 | $this -> viewModel -> set('youtube', $result['youtube']); 415 | $this -> viewModel -> set('urlValues', $this -> urlValues); 416 | $this -> viewModel -> set('pageTitle', TITLE . 'Ändra "' . $result['title'] . '"'); 417 | return $this -> viewModel; 418 | } 419 | 420 | public function wall() { 421 | $numberofimgperside = 9; 422 | $ar = new ArrayTools(); 423 | $url = filter_var_array($this -> urlValues, FILTER_VALIDATE_INT); 424 | $sql = "SELECT `id`,`poster` FROM `movies` 425 | ORDER BY id DESC "; 426 | if ($url['id']) { 427 | $sql .= "LIMIT " . $numberofimgperside * ((int)$url['id'] - 1) . ", " . $numberofimgperside; 428 | } else { 429 | $url['id'] = 1; 430 | $sql .= "LIMIT " . $numberofimgperside; 431 | } 432 | 433 | $result = $this -> db -> select_query($sql); 434 | 435 | $sql = "SELECT count(id) 436 | FROM movies 437 | ORDER BY id DESC"; 438 | 439 | $numberofmovies = $ar -> unique_flat_array($this -> db -> select_query($sql)); 440 | $numberofmovies = $numberofmovies[0]; 441 | 442 | $antalSidor = ceil($numberofmovies / 9); 443 | 444 | if ($this -> urlValues['id'] == 0) { 445 | $id = 1; 446 | $classone = 'class="notclickable"'; 447 | } elseif ($this -> urlValues['id'] == $antalSidor) { 448 | $id = $antalSidor; 449 | $classtwo = 'class="notclickable"'; 450 | } else { 451 | $id = $this -> urlValues['id']; 452 | } 453 | 454 | $getPrew = 'href="' . URL . $this -> urlValues['controller'] . '/' . $this -> urlValues['action'] . '/' . ($id - 1) . '" ' . $classone; 455 | $getNext = 'href="' . URL . $this -> urlValues['controller'] . '/' . $this -> urlValues['action'] . '/' . ($id + 1) . '"' . $classtwo; 456 | 457 | $row = 1; 458 | foreach ($result as $key => $value) { 459 | if ($key == 3 || $key == 6) 460 | $row++; 461 | $posters[$row] .= '<a href="' . URL . 'movie/display/' . $value['id'] . '"><img src="' . URL . 'public/img/posters/' . $value['poster'] . '" class="poster"></a>'; 462 | } 463 | 464 | $this -> viewModel -> set("getPrew", $getPrew); 465 | $this -> viewModel -> set("getNext", $getNext); 466 | $this -> viewModel -> set('posters', $posters); 467 | $this -> viewModel -> set('urlValues', $this -> urlValues); 468 | $this -> viewModel -> set('pageTitle', TITLE . 'Filmvägg'); 469 | return $this -> viewModel; 470 | } 471 | 472 | public function addcomment() { 473 | $param = $this -> param; 474 | if (!empty($param[':uid']) && !empty($param[':mid']) && !empty($param[':comment'])) { 475 | $sql = "INSERT INTO `usercomment`(`userid`, `movieid`, `comment`, date) 476 | VALUES (:uid,:mid,:comment,now())"; 477 | 478 | $this -> db -> select_query($sql, $param); 479 | header('location:' . URL . 'movie/display/' . $param[':mid']); 480 | } 481 | $this -> viewModel -> set('urlValues', $this -> urlValues); 482 | $this -> viewModel -> set('pageTitle', TITLE . 'Fel!'); 483 | return $this -> viewModel; 484 | } 485 | 486 | public function add() { 487 | $sql = "SELECT * FROM movietype"; 488 | $movieype = $this -> db -> select_query($sql); 489 | 490 | $this -> viewModel -> set('movietype', $movieype); 491 | $this -> viewModel -> set('imdbID', ''); 492 | $this -> viewModel -> set('urlValues', $this -> urlValues); 493 | $this -> viewModel -> set('pageTitle', TITLE . 'Lägg till film'); 494 | return $this -> viewModel; 495 | } 496 | 497 | public function addimdb() { 498 | $imdb = new Imdb(); 499 | $imdbid = $this -> imdbID; 500 | $movieData = $imdb -> getMovieInfoById($imdbid); 501 | 502 | if (!empty($movieData['original_title'])) { 503 | $title = trim($movieData['original_title']); 504 | } else { 505 | $title = trim($movieData['title']); 506 | } 507 | 508 | $url = $movieData['poster_large']; 509 | $path = time() . "." . pathinfo($url, PATHINFO_EXTENSION); 510 | 511 | $this -> viewModel -> set('imdbid', $movieData['title_id']); 512 | $this -> viewModel -> set('title', $title); 513 | $this -> viewModel -> set('year', $movieData['year']); 514 | $this -> viewModel -> set('genres', $movieData['genres']); 515 | $this -> viewModel -> set('directors', $movieData['directors']); 516 | $this -> viewModel -> set('cast', $movieData['cast']); 517 | $this -> viewModel -> set('plot', $movieData['plot']); 518 | $this -> viewModel -> set('poster', $path); 519 | $this -> viewModel -> set('posterURL', $url); 520 | $this -> viewModel -> set('runtime', $movieData['runtime']); 521 | $this -> viewModel -> set('type', $this -> type); 522 | $this -> viewModel -> set('sub', $this -> sub); 523 | $this -> viewModel -> set('urlValues', $this -> urlValues); 524 | $this -> viewModel -> set('pageTitle', TITLE . 'Lägg till film'); 525 | return $this -> viewModel; 526 | } 527 | 528 | public function publish() { 529 | $title = trim($_POST['title']); 530 | $imdb = trim($_POST['imdbid']); 531 | 532 | $sql = "DELETE FROM queue WHERE imdb = :imdb"; 533 | $param = array(':imdb' => $imdb); 534 | 535 | $this -> db -> select_query($sql, $param); 536 | 537 | $sql = "SELECT * FROM movies WHERE title = :title"; 538 | $param = array(':title' => $title); 539 | 540 | $count = $this -> db -> select_query($sql, $param); 541 | 542 | if (sizeof($count) == 0) { 543 | $ar = new ArrayTools(); 544 | 545 | $directors = $ar -> pickvalues_to_array($_POST, 1, $_POST['NoDirectors']); 546 | $actors = $ar -> pickvalues_to_array($_POST, 100, $_POST['NoActors']); 547 | $genres = $ar -> pickvalues_to_array($_POST, 1000, $_POST['NoGenres']); 548 | 549 | //Hämta hem postern -- http://www.phpriot.com/articles/download-with-curl-and-php 550 | 551 | $path = $_POST['poster']; 552 | $url = $_POST['posterurl']; 553 | $img = 'public/img/posters/' . $path; 554 | file_put_contents($img, file_get_contents($url)); 555 | 556 | $sql = "INSERT INTO movies (imdbid, title, plot, year, poster, type, sub, runtime, date, youtube) 557 | VALUES(:imdbid, :title, :plot, :year, :path, :type, :sub, :runtime, now(), :youtube)"; 558 | 559 | $param = array(':imdbid' => $_POST['imdbid'], ':title' => strip_tags($_POST['title']), ':plot' => strip_tags($_POST['plot']), ':year' => strip_tags($_POST['year']), ':path' => $path, ':type' => strip_tags($_POST['type']), ':sub' => strip_tags($_POST['sub']), ':runtime' => strip_tags($_POST['runtime']), ':youtube' => strip_tags($_POST['youtube'])); 560 | 561 | $this -> db -> select_query($sql, $param); 562 | $mid = $this -> db -> lastInsertId('id'); 563 | 564 | $genreparam = array(); 565 | foreach ($genres as $value) { 566 | $genreparam[] = array(':genre' => strip_tags($value)); 567 | } 568 | $actorparam = array(); 569 | foreach ($actors as $value) { 570 | $actorparam[] = array(':actor' => strip_tags($value)); 571 | } 572 | $directorparam = array(); 573 | foreach ($directors as $value) { 574 | $directorparam[] = array(':director' => strip_tags($value)); 575 | } 576 | 577 | ######################################################## 578 | # Genres hanteras här # 579 | # Ser till att mata in all data i databasen # 580 | ######################################################## 581 | 582 | $sql = "SELECT * FROM genres 583 | WHERE genre = :genre"; 584 | $genreids = $this -> db -> multi_query($sql, $genreparam); 585 | 586 | $genrenotindb = array_diff($ar -> flatten_array($genreparam), $ar -> flatten_array($genreids)); 587 | 588 | $paraminsert = array(); 589 | foreach ($genrenotindb as $value) { 590 | $paraminsert[] = array(':genre' => strip_tags($value)); 591 | } 592 | 593 | $sql = "INSERT INTO genres (genre) 594 | VALUES(:genre)"; 595 | 596 | $result = $this -> db -> multi_query($sql, $paraminsert); 597 | $genrefromdbid = $this -> db -> lastInsertId(); 598 | 599 | $genreidstomovie = array(); 600 | for ($i = $genrefromdbid - sizeof($result) + 1; $i <= $genrefromdbid; $i++) { 601 | $genresinmovies[] = array(':genreid' => (int)$i, ':movieid' => $mid); 602 | } 603 | 604 | $genreindb = $ar -> unique_flat_array(array_diff($ar -> flatten_array($genreids), $ar -> flatten_array($genreparam))); 605 | 606 | foreach ($genreindb as $value) { 607 | $genresinmovies[] = array(':genreid' => (int)$value, ':movieid' => $mid); 608 | } 609 | 610 | $sql = "INSERT INTO genresinmovies (movie_id, genre_id) 611 | VALUES (:movieid,:genreid)"; 612 | 613 | $this -> db -> multi_query($sql, $genresinmovies); 614 | 615 | ######################################################## 616 | # Actors hanteras här # 617 | # Ser till att mata in all data i databasen # 618 | ######################################################## 619 | 620 | $sql = "SELECT * FROM actors 621 | WHERE actor = :actor"; 622 | 623 | $actorsinmovie = $this -> db -> multi_query($sql, $actorparam); 624 | 625 | $actorsinmovienotdb = array_diff($ar -> flatten_array($actorparam), $ar -> flatten_array($actorsinmovie)); 626 | 627 | $actorinsertparam = array(); 628 | foreach ($actorsinmovienotdb as $value) { 629 | $actorinsertparam[] = array(':actor' => strip_tags($value)); 630 | } 631 | 632 | $sql = "INSERT INTO actors (actor) 633 | VALUES (:actor)"; 634 | 635 | $this -> db -> multi_query($sql, $actorinsertparam); 636 | $actorid = $this -> db -> lastInsertId(); 637 | 638 | $actorsparam = array(); 639 | for ($i = $actorid - sizeof($actorinsertparam) + 1; $i <= $actorid; $i++) { 640 | $actorsparam[] = array(':actor' => (int)$i, ':movieid' => $mid); 641 | } 642 | 643 | $actorsinmoviedb = $ar -> unique_flat_array(array_diff($ar -> flatten_array($actorsinmovie), $ar -> flatten_array($actorparam))); 644 | foreach ($actorsinmoviedb as $value) { 645 | $actorsparam[] = array(':actor' => (int)$value, ':movieid' => $mid); 646 | } 647 | 648 | $sql = "INSERT INTO actorsinmovies (movie_id,actor_id) 649 | VALUES (:movieid,:actor)"; 650 | $this -> db -> multi_query($sql, $actorsparam); 651 | 652 | ######################################################## 653 | # Directors hanteras här # 654 | # Ser till att mata in all data i databasen # 655 | ######################################################## 656 | 657 | $sql = "SELECT * FROM directors 658 | WHERE director = :director"; 659 | 660 | $directorsindb = $this -> db -> multi_query($sql, $directorparam); 661 | 662 | $directorsnotindb = array_diff($ar -> flatten_array($directorparam), $ar -> flatten_array($directorsindb)); 663 | 664 | $directorsinsertdb = array(); 665 | foreach ($directorsnotindb as $value) { 666 | $directorsinsertdb[] = array(':director' => strip_tags($value)); 667 | } 668 | 669 | $sql = "INSERT INTO directors (director) 670 | VALUES (:director)"; 671 | 672 | $this -> db -> multi_query($sql, $directorsinsertdb); 673 | $dib = $this -> db -> lastInsertId(); 674 | 675 | $directorsparam = array(); 676 | for ($i = $dib - sizeof($directorsinsertdb) + 1; $i <= $dib; $i++) { 677 | $directorsparam[] = array(':directorid' => (int)$i, ':movieid' => $mid); 678 | } 679 | 680 | $directorsindb = $ar -> unique_flat_array(array_diff($ar -> flatten_array($directorsindb), $ar -> flatten_array($directorparam))); 681 | foreach ($directorsindb as $value) { 682 | $directorsparam[] = array(':directorid' => (int)$value, ':movieid' => $mid); 683 | } 684 | 685 | $sql = "INSERT INTO directorsinmovies (movie_id,director_id) 686 | VALUES (:movieid,:directorid)"; 687 | 688 | $res = $this -> db -> multi_query($sql, $directorsparam); 689 | 690 | header('Location:' . URL . 'movie/display/' . $mid); 691 | } else { 692 | header('Location:' . URL . 'movie/display/' . $count[0][id]); 693 | die(); 694 | } 695 | 696 | $this -> viewModel -> set('pageTitle', TITLE . ''); 697 | return $this -> viewModel; 698 | } 699 | 700 | public function removecomment() { 701 | $result = $this -> db -> select_query("SELECT `movieid` FROM `usercomment` WHERE `id` = :id AND `userid` = :uid", array(':id' => $this -> urlValues['id'], ':uid' => $_SESSION['user_id'])); 702 | $this -> db -> select_query("DELETE FROM `usercomment` WHERE `id` = :id AND `userid` = :uid", array(':id' => $this -> urlValues['id'], ':uid' => $_SESSION['user_id'])); 703 | header('location:' . URL . 'movie/edit/' . $result[0][0]); 704 | $this -> viewModel -> set('pageTitle', TITLE . 'removecomment!'); 705 | return $this -> viewModel; 706 | } 707 | 708 | public function makeedit() { 709 | $id = $this -> urlValues['id']; 710 | $post = $this -> submit; 711 | if (isset($post)) { 712 | if (is_numeric($_POST['series'])) { 713 | $movieinserie = $this -> db -> select_query("SELECT seriesID FROM `moviesinseries` WHERE movieID = :id", array(":id" => $id)); 714 | if ($movieinserie[0]["seriesID"] == NULL) { 715 | $this -> db -> select_query("INSERT INTO `moviesinseries`(`movieID`, `seriesID`, `number`) VALUES (:mid,:sid,:number)", array(":mid" => $id, ":sid" => $_POST["series"], ":number" => $_POST["number"])); 716 | } elseif ($movieinserie[0]["seriesID"] != $_POST["series"]) { 717 | $this -> db -> select_query("UPDATE `moviesinseries` SET `seriesID`=:sid,`number`=:number WHERE movieID = :mid", array(":mid" => $id, ":sid" => $_POST["series"], ":number" => $_POST["number"])); 718 | } 719 | } else { 720 | $this -> db -> select_query("DELETE FROM `moviesinseries` WHERE movieID = :id", array(":id" => $id)); 721 | } 722 | $url = $_POST['poster']; 723 | if (substr($url, 0, 4) == "http") { 724 | $imgtitle = basename($url); 725 | $path = time() . '-' . $imgtitle; 726 | $fp = fopen('public/img/posters/' . $path, 'w'); 727 | $ch = curl_init($url); 728 | curl_setopt($ch, CURLOPT_FILE, $fp); 729 | curl_exec($ch); 730 | curl_close($ch); 731 | fclose($fp); 732 | echo "hej!"; 733 | $url = $path; 734 | } 735 | $sql = "UPDATE `movies` SET `poster` = :poster, `imdbid`=:imdb,`title`=:title,`plot`=:plot,`year`=:year,`type`=:type,`sub`=:sub,`runtime`=:runtime,`youtube`=:youtube WHERE id = :id"; 736 | $param = array(':poster' => $url, ':imdb' => $_REQUEST['imdbid'], ':title' => $_REQUEST['title'], ':plot' => strip_tags($_REQUEST['plot']), ':year' => $_REQUEST['year'], ':type' => $_REQUEST['type'], ':sub' => $_REQUEST['sub'], ':runtime' => $_REQUEST['runtime'], ':youtube' => $_REQUEST['youtube'], ':id' => $id); 737 | $this -> db -> select_query($sql, $param); 738 | header('location:' . URL . $_REQUEST['controller'] . '/display/' . $_REQUEST['id']); 739 | } 740 | $this -> viewModel -> set('pageTitle', TITLE . 'makeedit!'); 741 | return $this -> viewModel; 742 | } 743 | 744 | public function addman() { 745 | $this -> viewModel -> set('Nodir', $this -> Nodir); 746 | $this -> viewModel -> set('Noact', $this -> Noact); 747 | $this -> viewModel -> set('Nogen', $this -> Nogen); 748 | $this -> viewModel -> set('sub', $this -> sub); 749 | $this -> viewModel -> set('type', $this -> type); 750 | $this -> viewModel -> set('urlValues', $this -> urlValues); 751 | $this -> viewModel -> set('pageTitle', TITLE . 'Lägg till film'); 752 | return $this -> viewModel; 753 | } 754 | 755 | public function queue() { 756 | $sql = "SELECT queue.imdb, queue.title, queue.year, queue.added, group_concat(genres.genre ORDER BY genres.genre ASC SEPARATOR ', ') AS genre 757 | FROM queue JOIN genresinqueue ON queue.id = genresinqueue.movie_id 758 | JOIN genres ON genres.id = genresinqueue.genre_id 759 | GROUP BY queue.imdb 760 | ORDER BY queue.id DESC, genres.genre ASC"; 761 | 762 | $result = $this -> db -> select_query($sql); 763 | 764 | foreach ($result as $key => $value) { 765 | $tableBody[$key]['0'] = '<a href="http://www.imdb.com/title/' . $value['imdb'] . '" target="_blank">' . $value['title'] . '</a> (' . $value['year'] . ')'; 766 | $tableBody[$key]['1'] = $value['genre']; 767 | $tableBody[$key]['2'] = $value['added']; 768 | $tableBody[$key]['3'] = '<a href="' . URL . 'movie/add/' . $value['imdb'] . '"><i class="glyphicon glyphicon-remove"></i></a>'; 769 | } 770 | 771 | $this -> viewModel -> set('tableBody', $tableBody); 772 | $this -> viewModel -> set('tableHead', array('Titel', 'Genres', 'Tillagd')); 773 | $this -> viewModel -> set('urlValues', $this -> urlValues); 774 | $this -> viewModel -> set('pageTitle', TITLE . 'Köa en film'); 775 | return $this -> viewModel; 776 | } 777 | 778 | public function addqueue() { 779 | if ($this -> chars == 9) { 780 | $sql = "SELECT id FROM movies 781 | WHERE imdbid = :imdbid"; 782 | 783 | $resultfrommovies = $this -> db -> select_query($sql, array(':imdbid' => $_POST['imdbid'])); 784 | 785 | if (sizeof($resultfrommovies)) { 786 | header("Location:" . URL . "movie/display/" . $resultfrommovies[0]['id']); 787 | die(); 788 | } 789 | 790 | $sql = "SELECT id FROM queue 791 | WHERE imdb = :imdbid"; 792 | 793 | $resultfromqueue = $this -> db -> select_query($sql, array(':imdbid' => $_POST['imdbid'])); 794 | 795 | if (sizeof($resultfromqueue)) { 796 | header("Location:" . URL . "movie/queue"); 797 | die(); 798 | } 799 | 800 | $imdb = new Imdb(); 801 | $imdbid = $this -> imdbid; 802 | $movieData = $imdb -> getMovieInfoById($imdbid); 803 | 804 | $title = trim($movieData['title']); 805 | $year = $movieData['year']; 806 | 807 | $sql = "SELECT title FROM movies 808 | WHERE movies.title = :title 809 | UNION 810 | SELECT title FROM queue 811 | WHERE queue.title = :title"; 812 | 813 | $result = $this -> db -> select_query($sql, array(':title' => $title)); 814 | 815 | if (sizeof($result) == 0) { 816 | $sql = "INSERT INTO queue (imdb , title, year, added) 817 | VALUES (:imdbid, :title, :year, CURDATE())"; 818 | $imdbidt = $this -> imdbid; 819 | $result = $this -> db -> select_query($sql, array(':imdbid' => $imdbidt, ':title' => $title, ':year' => $year)); 820 | $mid = $this -> db -> lastInsertId('id'); 821 | 822 | foreach ($movieData['genres'] as $genre) { 823 | $param[] = array(':genre' => $genre); 824 | } 825 | 826 | $sql = "SELECT id FROM genres 827 | WHERE genre = :genre"; 828 | 829 | $result = $this -> db -> multi_query($sql, $param); 830 | 831 | foreach ($result as $key => $value) { 832 | echo sizeof($value); 833 | if (sizeof($value) == 0) { 834 | $insertparam[] = $param[$key]; 835 | } else { 836 | $genreparam[] = $value[0]; 837 | } 838 | } 839 | 840 | $sql = "INSERT INTO genres (genre) 841 | VALUES(:genre)"; 842 | 843 | $this -> db -> multi_query($sql, $insertparam); 844 | 845 | $gid = $this -> db -> lastInsertId('id'); 846 | 847 | for ($i = $gid - sizeof($insertparam) + 1; $i <= $gid; $i++) { 848 | $genreparam[] = $i; 849 | } 850 | 851 | $ar = new ArrayTools(); 852 | 853 | $genres = $ar -> unique_flat_array($genreparam); 854 | 855 | foreach ($genres as $value) { 856 | $genresin[] = array(':gid' => $value, ':mid' => $mid); 857 | } 858 | 859 | $sql = "INSERT INTO genresinqueue (movie_id,genre_id) 860 | VALUES (:mid,:gid)"; 861 | 862 | $this -> db -> multi_query($sql, $genresin); 863 | header("Location:" . URL . "movie/queue"); 864 | 865 | } else { 866 | $sql = "SELECT id FROM movies 867 | WHERE title = :title"; 868 | 869 | $resultfrommovies = $this -> db -> select_query($sql, array(':title' => $title)); 870 | if (sizeof($resultfrommovies) > 0) { 871 | header("Location:" . URL . "movie/display/" . $resultfrommovies[0]['id']); 872 | die(); 873 | } else { 874 | header("Location:" . URL . "movie/queue"); 875 | } 876 | } 877 | 878 | die(); 879 | } 880 | $this -> viewModel -> set('urlValues', $this -> urlValues); 881 | $this -> viewModel -> set('pageTitle', TITLE . 'Köa en film'); 882 | return $this -> viewModel; 883 | } 884 | 885 | public function stat() { 886 | $ar = new Arraytools(); 887 | 888 | $antalfilmer = array_sum($ar -> unique_flat_array($this -> db -> select_query("SELECT COUNT(movies.id) FROM movies"))); 889 | 890 | $sql = "SELECT count(*) 891 | FROM users 892 | JOIN towatch ON users.id = towatch.userid 893 | JOIN movies ON towatch.movieid = movies.id 894 | LEFT JOIN (SELECT userid, movieid, date FROM userviewed) AS UV ON UV.movieid = movies.id AND UV.userid = towatch.userid 895 | WHERE UV.date IS NULL 896 | ORDER BY users.name, towatch.date, movies.title"; 897 | 898 | $towatch = array_sum($ar -> unique_flat_array($this -> db -> select_query($sql))); 899 | 900 | $sql = "SELECT count(*) 901 | FROM users 902 | JOIN towatch ON users.id = towatch.userid 903 | JOIN movies ON towatch.movieid = movies.id 904 | LEFT JOIN (SELECT userid, movieid, date FROM userviewed) AS UV ON UV.movieid = movies.id AND UV.userid = towatch.userid 905 | WHERE UV.date IS NOT NULL 906 | ORDER BY users.name, towatch.date, movies.title"; 907 | 908 | $watchedtowatch = array_sum($ar -> unique_flat_array($this -> db -> select_query($sql))); 909 | $comments = array_sum($ar -> unique_flat_array($this -> db -> select_query("SELECT COUNT(id) FROM usercomment"))); 910 | $watched = sizeof($this -> db -> select_query("SELECT count(*) FROM userviewed GROUP BY movieid")); 911 | $numberofnews = array_sum($ar -> unique_flat_array($this -> db -> select_query("SELECT count(*) FROM news"))); 912 | $numberinqueue = array_sum($ar -> unique_flat_array($this -> db -> select_query("SELECT count(*) FROM queue"))); 913 | $numberofactors = array_sum($ar -> unique_flat_array($this -> db -> select_query("SELECT count(*) FROM actors"))); 914 | $numberofdirectors = array_sum($ar -> unique_flat_array($this -> db -> select_query("SELECT count(*) FROM directors"))); 915 | $numberofgenres = array_sum($ar -> unique_flat_array($this -> db -> select_query("SELECT count(*) FROM genres"))); 916 | $votes = $this -> db -> select_query("SELECT avg(value), count(*) FROM uservote"); 917 | $movieswithoutruntime = array_sum($ar -> unique_flat_array($this -> db -> select_query("SELECT count(id) FROM `movies` WHERE `runtime` = 0"))); 918 | $subtitle = $this -> db -> select_query("SELECT sub,count(*) FROM movies GROUP BY sub"); 919 | 920 | $this -> viewModel -> set('antalfilmer', $antalfilmer); 921 | $this -> viewModel -> set('towatch', $towatch); 922 | $this -> viewModel -> set('watchedtowatch', $watchedtowatch); 923 | $this -> viewModel -> set('comments', $comments); 924 | $this -> viewModel -> set('watched', $watched); 925 | $this -> viewModel -> set('numberofnews', $numberofnews); 926 | $this -> viewModel -> set('numberinqueue', $numberinqueue); 927 | $this -> viewModel -> set('numberofactors', $numberofactors); 928 | $this -> viewModel -> set('numberofdirectors', $numberofdirectors); 929 | $this -> viewModel -> set('numberofgenres', $numberofgenres); 930 | $this -> viewModel -> set('votes', $votes); 931 | $this -> viewModel -> set('movieswithoutruntime', $movieswithoutruntime); 932 | $this -> viewModel -> set('subtitle', $subtitle); 933 | $this -> viewModel -> set('urlValues', $this -> urlValues); 934 | $this -> viewModel -> set('pageTitle', TITLE . 'Köa en film'); 935 | return $this -> viewModel; 936 | } 937 | } 938 | ?> 939 | --------------------------------------------------------------------------------