Ticket #1574: handler.php

File handler.php, 6.9 KB (added by ATSantema@…, 20 years ago)

mythweb/modules/video/handler.php

Line 
1<?php
2/**
3 * View MythVideo files
4 *
5 * @url $URL$
6 * @date $Date: 2006-01-25 21:45:37 -0500 (Wed, 25 Jan 2006) $
7 * @version $Revision: 8727 $
8 * @author $Author: xris $
9 *
10 * @package MythWeb
11 * @subpackage Video
12 *
13/**/
14
15/**
16 * This points to the local filesystem path where MythVideo has been told to
17 * look for videos.
18 *
19 * @global string $GLOBALS['mythvideo_dir']
20 * @name $mythvideo_dir
21/**/
22 global $mythvideo_dir;
23 $mythvideo_dir = $db->query_col('SELECT data
24 FROM settings
25 WHERE value="VideoStartupDir" AND hostname=?',
26 hostname
27 );
28
29// Make sure the video directory exists
30 if (file_exists('data/video')) {
31 // File is not a directory or a symlink
32 if (!is_dir('data/video') && !is_link('data/video')) {
33 $Error = 'An invalid file exists at data/video. Please remove it in'
34 .' order to use the video portions of MythWeb.';
35 require_once 'templates/_error.php';
36 }
37 }
38// Create the symlink, if possible.
39//
40// NOTE: Errors have been disabled because if I turn them on, people hosting
41// MythWeb on Windows machines will have issues. I will turn the errors
42// back on when I find a clean way to do so.
43//
44 else {
45 if ($mythvideo_dir) {
46 $ret = @symlink($mythvideo_dir, 'data/video');
47 if (!$ret) {
48 #$Error = "Could not create a symlink to $mythvideo_dir, the local MythVideo"
49 # .' directory for this hostname ('.hostname.'). Please create a
50 # .' symlink to your MythVideo directory at data/video in order to
51 # .' use the video portions of MythWeb.';
52 #require_once 'templates/_error.php';
53 }
54 }
55 else {
56 #$Error = 'Could not find a value in the database for the MythVideo directory'
57 # .' for this hostname ('.hostname.'). Please create a symlink to your'
58 # .' MythVideo directory at data/video in order to use the video'
59 # .' portions of MythWeb.';
60 #require_once 'templates/_error.php';
61 }
62 }
63
64// Editing?
65 if ($Path[1] == 'edit') {
66 require_once 'modules/video/edit.php';
67 exit;
68 }
69
70// Load the sorting routines
71 require_once "includes/sorting.php";
72
73// Queries for a specific program title
74 isset($_GET['title']) or $_GET['title'] = $_POST['title'];
75
76// Get the video categories on the system
77 $Category_String = array();
78 $Total_Categories = 0;
79 $sh = $db->query('SELECT * FROM videocategory');
80 while ($row = $sh->fetch_assoc()) {
81 $Category_String[$row['intid']] = $row['category'];
82 $Total_Categories++;
83 }
84 $sh->finish();
85 $Category_String[0] = 'Uncategorized';
86
87// ADDED
88// Get the video genres on the system
89 $Genre_String = array();
90 $Total_Genres = 0;
91 $sh = $db->query('SELECT * FROM videogenre');
92 while ($row = $sh->fetch_assoc()) {
93 $Genre_String[$row['intid']] = $row['genre'];
94 $Total_Genres++;
95 }
96 $sh->finish();
97 $Genre_String[0] = 'No Genre';
98
99// Parse the list
100// Filter_Category of -1 means All, 0 mean uncategorized
101 $Total_Programs = 0;
102 $All_Shows = array();
103 if( isset($_GET['category']) ) {
104 $Filter_Category = $_GET['category'];
105 if( $Filter_Category != -1)
106 $where = ' AND category='.$db->escape($Filter_Category);
107 } else {
108 $Filter_Category = -1;
109 }
110
111 if( isset($_GET['genre']) ) {
112 $Filter_Genre = $_GET['genre'];
113 if( $Filter_Genre != -1)
114 $where .= ' AND idgenre='.$db->escape($Filter_Genre);
115 }
116 else {
117 $Filter_Genre = -1;
118 }
119
120 if( isset($_GET['browse']) ) {
121 $Filter_Browse = $_GET['browse'];
122 if( $Filter_Browse != -1)
123 $where .= ' AND browse='.$db->escape($Filter_Browse);
124 }
125 else {
126 $Filter_Browse = -1;
127 }
128
129 if( isset($_GET['search']) ) {
130 $Filter_Search = $_GET['search'];
131 if( strlen($Filter_Search) != 0)
132 $where .= ' AND title LIKE '.$db->escape("%".$Filter_Search."%");
133 }
134 else {
135 $Filter_Search = "";
136 }
137
138 if ($where) { $where = 'WHERE '.substr($where, 4); }
139
140 #$sh = $db->query('SELECT * FROM videometadata ' . $where . ' ORDER BY title');
141 $sql = 'SELECT * FROM videometadata LEFT JOIN videometadatagenre ON videometadata.intid=videometadatagenre.idvideo ' . $where . ' GROUP BY intid ORDER BY title';
142 $sh = $db->query($sql);
143
144 while ($row = $sh->fetch_assoc()) {
145 // Create a new show object
146 $All_Shows[] = new Video($row);
147 }
148 $sh->finish();
149
150// Set sorting
151 if (!is_array($_SESSION['video_sortby']))
152 $_SESSION['video_sortby'] = array(array('field' => 'title',
153 'reverse' => false));
154
155// Sort the programs
156 if (count($All_Shows))
157 sort_programs($All_Shows, 'video_sortby');
158
159// Load the class for this page
160 require_once theme_dir.'video/video.php';
161
162// Exit
163 exit;
164
165
166
167class Video {
168
169 var $intid;
170 var $plot;
171 var $category;
172 var $rating; // this should be a reference to the $Channel array value
173
174 var $title;
175 var $director;
176 var $inetref;
177 var $year;
178 var $userrating;
179 var $length; // css class, based on category and/or category_type
180 var $showlevel;
181 var $filename;
182 var $coverfile;
183 var $childid;
184 var $url;
185
186 function Video($program_data) {
187 global $mythvideo_dir;
188 $this->intid = $program_data['intid'];
189 $this->plot = $program_data['plot'];
190 $this->category = $program_data['category'];
191 $this->rating = $program_data['rating'];
192 $this->title = $program_data['title'];
193 $this->director = $program_data['director'];
194 $this->inetref = $program_data['inetref'];
195 $this->year = $program_data['year'] ? $program_data['year'] : 'Unknown';
196 $this->userrating = $program_data['userrating'] ? $program_data['userrating'] : 'Unknown';
197 $this->length = $program_data['length'];
198 $this->showlevel = $program_data['showlevel'];
199 $this->filename = $program_data['filename'];
200 $this->coverfile = $program_data['coverfile'];
201 $this->childid = $program_data['childid'];
202 // Figure out the URL
203 $this->url = '#';
204 if (file_exists('data/video/')) {
205 $this->url = root . implode('/', array_map('rawurlencode',
206 array_map('utf8tolocal',
207 explode('/',
208 'data/video/' . preg_replace('#^'.$mythvideo_dir.'/?#', '', $this->filename)
209 ))));
210 }
211 }
212}
213