PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/video/tmpl/default/video.php

https://github.com/MythTV/mythweb
PHP | 341 lines | 294 code | 30 blank | 17 comment | 47 complexity | 81a38c3c39b79b1c3a3f1dd3fbf59907 MD5 | raw file
  1. <?php
  2. /**
  3. * Rudimentary interface to MythVideo data
  4. *
  5. * @license GPL
  6. *
  7. * @package MythWeb
  8. * @subpackage Video
  9. *
  10. **/
  11. // Set the desired page title
  12. $page_title = 'MythWeb - '.t('Videos');
  13. // Custom headers
  14. $headers[] = '<link rel="stylesheet" type="text/css" href="'.root_url.'dcss/video.css">';
  15. $headers[] = '<link rel="stylesheet" type="text/css" href="'.root_url.'skins/'.skin.'/video.css">';
  16. // Print the page header
  17. require 'modules/_shared/tmpl/'.tmpl.'/header.php';
  18. ?>
  19. <script type="text/javascript">
  20. function newWindow(id) {
  21. $('window_title').innerHTML = '<?php echo addslashes(t('Editing ')); ?> ' + $(id+'-title').childNodes[1].innerHTML;
  22. $('window_content').innerHTML = '<iframe src="<?php echo root_url; ?>video/edit?intid='+id+'">';
  23. $('window').show();
  24. Tips.hideAll();
  25. }
  26. function imdb_lookup(id, title) {
  27. if (pending_ajax_requests > 0) {
  28. alert('<?php echo addslashes(t('Please wait for the pending AJAX request')); ?>');
  29. return;
  30. }
  31. ajax_add_request();
  32. // Clean up the title string
  33. title = title.replace('&', '%26');
  34. new Ajax.Request('<?php echo root_url ?>video/imdb',
  35. {
  36. method: 'get',
  37. parameters: {
  38. action: 'lookup',
  39. id: id,
  40. title: title
  41. },
  42. onSuccess: imdb_handler
  43. });
  44. }
  45. function imdb_handler(response) {
  46. ajax_remove_request();
  47. var result = response.responseJSON;
  48. if (result['error']) {
  49. for (var key in result['error']) {
  50. console.error(result['error'][key]);
  51. }
  52. return;
  53. }
  54. if (result['warning']) {
  55. for (var key in result['warning']) {
  56. console.warn(result['warning'][key]);
  57. }
  58. return
  59. }
  60. for (var key in result['update']) {
  61. update_video(result['update'][key]);
  62. }
  63. if (result['action'] == 'lookup') {
  64. if (result['matches']) {
  65. $('window_title').innerHTML = '<?php echo addslashes(t('Video: IMDB: Window Title')); ?> (<a href="javascript: imdb_prompt(\''+result['id']+'\');"><?php echo addslashes(t('Custom Search')); ?><\/a>)';
  66. $('window_content').innerHTML = '';
  67. for (var key in result['matches'])
  68. if (result['matches'][key]['title'])
  69. $('window_content').innerHTML += '<br>'
  70. + '<a href="'+makeImdbWebUrl(result['matches'][key]['imdbid'])+'" style="float: right; margin-left: 1em;" target="_blank">(IMDB)</a>'
  71. + '<a href="javascript:imdb_select(\''+result['id']+'\',\''+result['matches'][key]['imdbid']+'\')">'+result['matches'][key]['title']+'</a>';
  72. }
  73. else {
  74. $('window_title').innerHTML = '<?php echo addslashes(t('Video: IMDB: Window Title')); ?> (<a href="javascript: imdb_prompt(\''+result['id']+'\');"><?php echo addslashes(t('Custom Search')); ?><\/a>)';
  75. $('window_content').innerHTML = '<?php echo addslashes(t('Video: IMDB: No Matches')); ?>';
  76. }
  77. $('window').show();
  78. Tips.hideAll();
  79. }
  80. }
  81. function makeImdbWebUrl(num) {
  82. var imdb = "<?php echo setting('web_video_imdb_type', hostname); ?>";
  83. if (imdb == 'ALLOCINE')
  84. return "http://www.allocine.fr/film/fichefilm_gen_cfilm="+num+".html";
  85. return "http://www.imdb.com/Title?"+num;
  86. }
  87. function imdb_select(id, number) {
  88. ajax_add_request();
  89. $('window').hide();
  90. new Ajax.Request('<?php echo root_url; ?>video/imdb',
  91. {
  92. method: 'get',
  93. parameters: {
  94. action: 'grab',
  95. id: id,
  96. number: number
  97. },
  98. onSuccess: imdb_handler
  99. });
  100. }
  101. function imdb_prompt(id) {
  102. var title = $(id+'-title').childNodes[1].innerHTML;
  103. var number = prompt('<?php echo addslashes(t('Please enter an IMDB number or a title to do another search')); ?>', title);
  104. if (typeof(number) != 'string' || number.length == 0)
  105. return;
  106. $('window').hide();
  107. if (number.match(/^(\d*)$/))
  108. imdb_select(id, number);
  109. else
  110. imdb_lookup(id, number);
  111. }
  112. function update_video(id) {
  113. if (!id.match(/^(\d*)$/))
  114. return;
  115. ajax_add_request();
  116. new Ajax.Request('<?php echo root_url; ?>video/imdb',
  117. {
  118. method: 'get',
  119. parameters: {
  120. action: 'metadata',
  121. id: id
  122. },
  123. onSuccess: update_video_result
  124. });
  125. }
  126. function update_video_result(result) {
  127. var video = result.responseJSON.metadata;
  128. // Update the video
  129. for (var key in video) {
  130. if (key == 'title')
  131. $(video['intid']+'-'+key).childNodes[0].innerHTML = video[key];
  132. var element = $(video['intid']+'_'+key);
  133. if (element != null & typeof(element) != 'undefined')
  134. element.innerHTML = video[key];
  135. }
  136. Tips.remove(video['intid']);
  137. ajax_remove_request();
  138. }
  139. // The filter timeout is done because it can take awhile to filter the page
  140. // The timeout prevents the script from fireing while the user is setting options
  141. var filter_timeout = null;
  142. function filter() {
  143. if (filter_timeout != null)
  144. window.clearTimeout(filter_timeout);
  145. filter_timeout = window.setTimeout('filter_action()', 1050);
  146. }
  147. function filter_action() {
  148. ajax_add_request();
  149. var title = $('filter_box').value.toLowerCase();
  150. var category = $('category').value;
  151. var genre = $('genre').value;
  152. var browse = $('browse').value;
  153. for (key in $$('#videos div.video') ) {
  154. var video = $$('#videos div.video')[key];
  155. if (!video.id)
  156. continue;
  157. var hide = false;
  158. if (category != -1 & $(video.id+'_categoryid').innerHTML != category)
  159. hide = true;
  160. if (genre != -1 & !$(video.id+'_genre').innerHTML.match(' '+video.id+' '))
  161. hide = true;
  162. if (browse != -1 & $(video.id+'_browse').innerHTML != browse)
  163. hide = true;
  164. if (title.length > 0 & $(video.id+'-title').childNodes[0].innerHTML.toLowerCase().match(title) == null )
  165. hide = true;
  166. if (hide)
  167. $(video.id).hide();
  168. else
  169. $(video.id).show();
  170. }
  171. ajax_remove_request();
  172. }
  173. var hovering_video_id = null;
  174. var loading_popups = new Array();
  175. function video_popup(id) {
  176. hovering_video_id = id;
  177. if (!Tips.hasTip(id) && loading_popups[id] != true ) {
  178. loading_popups[id] = true;
  179. new Ajax.Request('<?php echo root_url; ?>video/imdb',
  180. {
  181. method: 'get',
  182. parameters: {
  183. action: 'metadata',
  184. id: id
  185. },
  186. onSuccess: video_create_popup
  187. });
  188. }
  189. }
  190. function video_create_popup(result) {
  191. var video = result.responseJSON['metadata'];
  192. var content = '<dl class="details_list">'
  193. + '<dt><?php echo addslashes(t('Plot:')); ?></dt> <dd>' + (video['plot'] ? video['plot'] : '&nbsp;')+'</dd>'
  194. + '<dt><?php echo addslashes(t('Rating:')); ?></dt> <dd>' + (video['rating'] ? video['rating'] : '&nbsp;')+'</dd>'
  195. + '<dt><?php echo addslashes(t('Director:')); ?></dt> <dd>' + (video['director'] ? video['director'] : '&nbsp;')+'</dd>'
  196. + '<dt><?php echo addslashes(t('Year:')); ?></dt> <dd>' + (video['year'] ? video['year'] : '&nbsp;')+'</dd>';
  197. + '</dl>';
  198. new Tip(video['intid'], content, { className: 'popup' });
  199. loading_popups[video['intid']] = false;
  200. if (video['intid'] == hovering_video_id)
  201. Tips.showTip(video['intid']);
  202. }
  203. // We currently do require a reload after a scan event
  204. function scan() {
  205. ajax_add_request();
  206. new Ajax.Request('<?php echo root_url; ?>video/scan',
  207. {
  208. method: 'get',
  209. onSuccess: reload
  210. });
  211. }
  212. function reload() {
  213. location.reload(true);
  214. }
  215. </script>
  216. <div id="window" style="display: none">
  217. <a style="position: absolute; right: 1px; top: 1px;" onclick="$('window').hide()">[X]</a>
  218. <span id="window_video_title" class="hidden"></span>
  219. <span id="window_title"></span><br>
  220. <div id="window_content"></div>
  221. </div>
  222. <table width="100%" border="0" cellpadding="4" cellspacing="2" class="list small">
  223. <tr class="menu">
  224. <td>
  225. <!-- Bad! Don't do this! <span style="float: right"><input type="button" value="<?php echo t('Scan Collection'); ?>" class="submit" onclick="scan()"></span> -->
  226. <form action="<?php echo root_url; ?>video" method="GET">
  227. <?php echo t('Display'); ?>:
  228. <select name="category" id="category" onchange="filter();">
  229. <option value="-1" <?php if($Filter_Category == -1) echo 'SELECTED'; ?>><?php echo t('All Categories'); ?></option>
  230. <?php
  231. foreach (array_keys($Category_String) as $i) {
  232. echo "<option value=\"$i\"";
  233. if( $i == $Filter_Category )
  234. echo ' SELECTED';
  235. echo '>'.html_entities($Category_String[$i])."</option>\n";
  236. }
  237. ?>
  238. </select>&nbsp;&nbsp;
  239. <select name="genre" id="genre" onchange="filter();">
  240. <option value="-1" <?php if ($Filter_Genre == -1) echo 'SELECTED'; ?>><?php echo t('All Genres'); ?></option>
  241. <?php
  242. foreach (array_keys($Genre_String) as $i) {
  243. echo "<option value=\"$i\"";
  244. if( $i == $Filter_Genre )
  245. echo ' SELECTED';
  246. echo '>'.html_entities($Genre_String[$i])."</option>\n";
  247. }
  248. ?>
  249. </select>&nbsp;&nbsp;
  250. <select name="browse" id="browse" onchange="filter();">
  251. <option value="-1" <?php if ($Filter_Browse == -1) echo 'SELECTED'; ?>><?php echo t('Browse all'); ?></option>
  252. <option value="1" <?php if ($Filter_Browse == 1) echo 'SELECTED'; ?>><?php echo t('Browse = yes'); ?></option>
  253. <option value="0" <?php if ($Filter_Browse == 0) echo 'SELECTED'; ?>><?php echo t('Browse = no'); ?></option>
  254. </select>&nbsp;&nbsp;
  255. <?php echo t('Title search'); ?>: <input id="filter_box" name="search" value="<?php echo $Filter_Search; ?>" onchange="filter();" onkeyup="filter();">
  256. <?php echo t('Admin Key'); ?>: <input type="password" name="VideoAdminPassword" value="<?php echo $_SESSION['video']['VideoAdminPassword']; ?>" size="5">
  257. <input type="submit" class="submit" value="<?php echo t('Update') ?>">
  258. </form>
  259. </td>
  260. <td style="text-align: right;">
  261. <?php
  262. $video_count = count($All_Videos);
  263. if( $video_count ) {
  264. echo tn('$1 video', '$1 videos', $video_count);
  265. } else {
  266. echo t('No videos');
  267. }
  268. ?>
  269. </td>
  270. </tr>
  271. </table>
  272. <div id="videos">
  273. <div id="path">
  274. <b><?php echo t('Directory Structure'); ?></b><hr>
  275. <a class="<?php if (!isset($_SESSION['video']['path']) || $_SESSION['video']['path'] == '/') echo 'active'; ?>" href="<?php echo root_url; ?>video?path=/"><?php echo t('Root Directory'); ?></a><br><br>
  276. <?php foreach ($PATH_TREE as $path) { output_path_picker($path); } ?>
  277. </div>
  278. <?php
  279. foreach ($All_Videos as $video) {
  280. ?>
  281. <div id="<?php echo $video->intid; ?>" class="video" onmouseover="video_popup(this.id)" onmouseout="hovering_video_id = null;">
  282. <div id="<?php echo $video->intid; ?>_categoryid" class="hidden"><?php echo $video->category; ?></div>
  283. <div id="<?php echo $video->intid; ?>_genre" class="hidden"><?php if ($video->genres != null && count($video->genres)) foreach ($video->genres as $genre) echo ' '.$genre.' ';?></div>
  284. <div id="<?php echo $video->intid; ?>_browse" class="hidden"><?php echo $video->browse; ?></div>
  285. <div id="<?php echo $video->intid; ?>-title" class="title">
  286. <a href="<?php echo $video->url; ?>"><?php echo html_entities($video->title); ?></a><?php
  287. if (($video->season > 0) && ($video->episode >= 0))
  288. printf('(S%02d E%02d)', $video->season, $video->episode);
  289. if (strlen($video->subtitle) > 0)
  290. echo '<br>' . html_entities($video->subtitle);
  291. ?></div>
  292. <div id="<?php echo $video->intid; ?>_img"> <img <?php if ($_SESSION["show_video_covers"] && (strcmp($video->cover_url, '') != 0)) echo 'src="'.$video->cover_url.'"'; echo ' width="'.$video->cover_scaled_width.'" height="'.$video->cover_scaled_height.'"'; ?> alt="<?php echo t('Missing Cover'); ?>"></div>
  293. <div id="<?php echo $video->intid; ?>-category"> <?php echo $Category_String[$video->category]; ?></div>
  294. <div id="<?php echo $video->intid; ?>_playtime"> <?php echo nice_length($video->length * 60); ?></div>
  295. <div id="<?php echo $video->intid; ?>_imdb"> <?php if ($video->inetref != '00000000') { ?><a href="<?php echo makeImdbWebUrl($video->inetref); ?>"><?php echo $video->inetref ?></a><?php } ?></div>
  296. <div class="command">
  297. <span class="commands"><a href="javascript:newWindow('<?php echo $video->intid ?>')" ><?php echo t('Edit') ?></a></span>
  298. <span class="commands"><a href="javascript:imdb_lookup('<?php echo $video->intid ?>','<?php echo addslashes($video->title); ?>')"><?php echo t('IMDB') ?></a></span>
  299. </div>
  300. </div>
  301. <?php
  302. }
  303. ?>
  304. </div>
  305. <?php
  306. // Print the page footer
  307. require 'modules/_shared/tmpl/'.tmpl.'/footer.php';