Exemple #1
0
 /**
  * The UI to show a video.
  *
  * @param  ?string		Alternate category name to use (NULL: use standard one). This is useful if you are overriding this code to show images in virtual galleries.
  * @param  ?tempcode		Breadcrumbs (NULL: derive in this function).
  * @return tempcode		The UI
  */
 function show_video($category_name = NULL, $tree = NULL)
 {
     $id = get_param_integer('id');
     if (get_param_integer('ajax', 0) == 1) {
         header('Content-type: text/xml');
     }
     list($sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos) = $this->get_sort_order();
     if (addon_installed('awards')) {
         require_code('awards');
         $awards = find_awards_for('video', strval($id));
     } else {
         $awards = array();
     }
     // Pic up some info
     $rows = $GLOBALS['SITE_DB']->query_select('videos', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $rows)) {
         return warn_screen(get_page_title('ERROR_OCCURRED'), do_lang_tempcode('MISSING_RESOURCE'));
     }
     $myrow = $rows[0];
     $url = $myrow['url'];
     if (url_is_local($url)) {
         $url = get_custom_base_url() . '/' . $url;
     }
     $cat = $myrow['cat'];
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=galleries&filter=' . urlencode($cat);
     if (get_value('no_individual_gallery_view') === '1' && $GLOBALS['SITE_DB']->query_value('galleries', 'flow_mode_interface', array('name' => $cat)) == '1') {
         require_code('site2');
         assign_refresh(build_url(array('page' => '_SELF', 'type' => 'misc', 'id' => $cat, 'probe_id' => $id, 'probe_type' => 'video'), '_SELF'), 0.0);
     }
     $true_category_name = get_translated_text($GLOBALS['SITE_DB']->query_value('galleries', 'fullname', array('name' => $cat)));
     if (is_null($category_name)) {
         $category_name = $true_category_name;
     }
     if (get_param_integer('slideshow', 0) == 1) {
         $title = get_page_title('VIEW_SLIDESHOW', true, array(escape_html($category_name)));
         global $EXTRA_HEAD;
         $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />');
         // XHTMLXHTML
     } else {
         $title = get_page_title(get_translated_text($myrow['title']) == '' ? 'VIEW_VIDEO' : '_VIEW_VIDEO', true, array(escape_html(get_translated_text($myrow['title']))), NULL, $awards);
     }
     $root = get_param('root', 'root');
     seo_meta_load_for('video', strval($id));
     $thumb_url = $myrow['thumb_url'];
     if (url_is_local($thumb_url)) {
         $thumb_url = get_custom_base_url() . '/' . $thumb_url;
     }
     if (!has_category_access(get_member(), 'galleries', $cat)) {
         access_denied('CATEGORY_ACCESS');
     }
     // Views
     if (get_db_type() != 'xml') {
         $myrow['video_views']++;
         $GLOBALS['SITE_DB']->query_update('videos', array('video_views' => $myrow['video_views']), array('id' => $id), '', 1, NULL, false, true);
     }
     list($rating_details, $comment_details, $trackback_details) = embed_feedback_systems('videos', strval($id), $myrow['allow_rating'], $myrow['allow_comments'], $myrow['allow_trackbacks'], $myrow['validated'], $myrow['submitter'], build_url(array('page' => '_SELF', 'type' => 'video', 'id' => $id), '_SELF', NULL, false, false, true), get_translated_text($myrow['title']) == '' ? do_lang('VIEW_VIDEO_IN', $true_category_name) : get_translated_text($myrow['title']), get_value('comment_forum__videos'));
     // Validation
     if ($myrow['validated'] == 0) {
         if (!has_specific_permission(get_member(), 'jump_to_unvalidated')) {
             access_denied('SPECIFIC_PERMISSION', 'jump_to_unvalidated');
         }
         $warning_details = do_template('WARNING_TABLE', array('_GUID' => 'b32faacba974e648a67e5e91ffd3d8e5', 'WARNING' => do_lang_tempcode(get_param_integer('redirected', 0) == 1 ? 'UNVALIDATED_TEXT_NON_DIRECT' : 'UNVALIDATED_TEXT')));
     } else {
         $warning_details = new ocp_tempcode();
     }
     // Comments
     $comments = get_translated_tempcode($myrow['comments']);
     if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_edit_permission('mid', get_member(), $myrow['submitter'], 'cms_galleries', array('galleries', $cat))) {
         $edit_url = build_url(array('page' => 'cms_galleries', 'type' => '_ev', 'id' => $id), get_module_zone('cms_galleries'));
     } else {
         $edit_url = new ocp_tempcode();
     }
     $add_date = get_timezoned_date($myrow['add_date']);
     $edit_date = is_null($myrow['edit_date']) ? '' : get_timezoned_date($myrow['edit_date']);
     // Video HTML
     $video = show_gallery_media($url, $thumb_url, $myrow['video_width'], $myrow['video_height'], $myrow['video_length']);
     $extension = get_file_extension($url);
     require_code('mime_types');
     $mime_type = get_mime_type($extension);
     list($n, $x, $nav) = $this->build_set_navigation(db_string_equal_to('cat', $cat), '', $category_name, $id, $root, 'video', get_param_integer('slideshow', 0), get_param_integer('wide_high', 0), get_param_integer('start', 0), get_param_integer('max', get_default_gallery_max()), $cat, $sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos, get_param('select', '*'), get_param('video_select', '*'));
     $member_id = get_member_id_from_gallery_name($cat, NULL, true);
     if (get_forum_type() == 'ocf') {
         require_code('ocf_members');
         require_code('ocf_members2');
     }
     $member_details = is_null($member_id) || get_forum_type() != 'ocf' ? new ocp_tempcode() : ocf_show_member_box($member_id);
     $video_details = show_video_details($myrow);
     if (is_null($tree)) {
         $tree = gallery_breadcrumbs($cat, $root, false, get_module_zone('galleries'));
     }
     breadcrumb_add_segment($tree, do_lang_tempcode('VIEW_VIDEO'));
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $myrow['add_date']), 'creator' => $GLOBALS['FORUM_DRIVER']->get_username($myrow['submitter']), 'publisher' => '', 'modified' => is_null($myrow['edit_date']) ? '' : date('Y-m-d', $myrow['edit_date']), 'type' => 'Video', 'title' => get_translated_text($myrow['title']), 'identifier' => '_SEARCH:galleries:video:' . strval($id), 'description' => get_translated_text($myrow['comments']), 'image' => $thumb_url, 'video' => $url, 'video:height' => strval($myrow['video_height']), 'video:width' => strval($myrow['video_width']), 'video:type' => $mime_type);
     return do_template('GALLERY_ENTRY_SCREEN', array('_GUID' => '91e231906ed899513ec2db8a2974dddf', 'MEDIA_TYPE' => 'video', 'E_TITLE' => get_translated_text($myrow['title']), 'CAT' => $cat, 'SLIDESHOW' => get_param_integer('slideshow', 0) == 1, 'TRUE_GALLERY_TITLE' => $true_category_name, 'GALLERY_TITLE' => $category_name, 'MEMBER_ID' => is_null($member_id) ? '' : strval($member_id), 'ID' => strval($id), 'TAGS' => get_loaded_tags('videos'), 'TITLE' => $title, 'SUBMITTER' => strval($myrow['submitter']), 'URL' => $url, 'VIDEO_DETAILS' => $video_details, 'MEMBER_DETAILS' => $member_details, 'X' => integer_format($x), 'N' => integer_format($n), 'VIEWS' => integer_format($myrow['video_views']), 'ADD_DATE_RAW' => strval($myrow['add_date']), 'EDIT_DATE_RAW' => is_null($myrow['edit_date']) ? '' : strval($myrow['edit_date']), 'ADD_DATE' => $add_date, 'EDIT_DATE' => $edit_date, 'RATING_DETAILS' => $rating_details, 'TRACKBACK_DETAILS' => $trackback_details, 'COMMENT_DETAILS' => $comment_details, 'EDIT_URL' => $edit_url, 'NAV' => $nav, 'COMMENTS' => $comments, 'VIDEO' => $video, 'WARNING_DETAILS' => $warning_details));
 }
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_css('galleries');
     require_lang('galleries');
     require_code('galleries');
     require_code('images');
     require_code('feedback');
     require_code('ocfiltering');
     $cat = array_key_exists('param', $map) ? $map['param'] : 'root';
     $cat_select = ocfilter_to_sqlfragment($cat, 'cat', 'galleries', 'parent_id', 'cat', 'name', false, false);
     $title = array_key_exists('title', $map) ? $map['title'] : '';
     /*if ((file_exists(get_custom_file_base().'/themes/default/templates_custom/JAVASCRIPT_GALLERIES.tpl')) || (file_exists(get_file_base().'/themes/default/templates/JAVASCRIPT_GALLERIES.tpl')))
     		require_javascript('javascript_galleries');*/
     $max = get_param_integer('mge_max', array_key_exists('max', $map) ? intval($map['max']) : 30);
     $start = get_param_integer('mge_start', 0);
     if (!array_key_exists('select', $map)) {
         $map['select'] = '*';
     }
     $image_select = ocfilter_to_sqlfragment($map['select'], 'id');
     if (!array_key_exists('video_select', $map)) {
         $map['video_select'] = '*';
     }
     $video_select = ocfilter_to_sqlfragment($map['video_select'], 'id');
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('galleries');
     $_days = array_key_exists('days', $map) ? $map['days'] : '';
     $days = mixed();
     $days = $_days == '' ? NULL : intval($_days);
     $where_sup = '';
     if (!is_null($days)) {
         $where_sup .= ' AND add_date>=' . strval(time() - $days * 60 * 60 * 24);
     }
     $sort = array_key_exists('sort', $map) ? $map['sort'] : 'add_date DESC';
     if ($sort != 'random ASC' && $sort != 'fixed_random ASC' && $sort != 'compound_rating DESC' && $sort != 'compound_rating ASC' && $sort != 'add_date DESC' && $sort != 'add_date ASC' && $sort != 'url DESC' && $sort != 'url ASC') {
         $sort = 'add_date DESC';
     }
     list($_sort, $_dir) = explode(' ', $sort, 2);
     $total_images = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'images WHERE ' . $cat_select . ' AND ' . $image_select . $where_sup);
     $total_videos = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'videos WHERE ' . $cat_select . ' AND ' . $video_select . $where_sup);
     if ($_sort == 'random') {
         $start = 0;
         $max = min($total_images + $total_videos, $max);
         $done_images = '1=1';
         $done_videos = '1=1';
         $rows_images = array();
         $rows_videos = array();
         for ($i = 0; $i < $max; $i++) {
             if (mt_rand(0, 1) == 0 || $total_videos - count($rows_videos) == 0) {
                 $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'images e WHERE ' . $cat_select . ' AND ' . $image_select . $where_sup . ' AND ' . $done_images, 1, mt_rand(0, $total_images - count($rows_images) - 1));
                 $rows_images[] = $rows[0];
                 $done_images .= ' AND ';
                 $done_images .= 'id<>' . strval($rows[0]['id']);
             } else {
                 $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'videos e WHERE ' . $cat_select . ' AND ' . $video_select . $where_sup . ' AND ' . $done_videos, 1, mt_rand(0, $total_videos - count($rows_videos) - 1));
                 $rows_videos[] = $rows[0];
                 $done_videos .= ' AND ';
                 $done_videos .= 'id<>' . strval($rows[0]['id']);
             }
         }
     } else {
         if ($_sort == 'compound_rating') {
             $rating_sort = ',(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', 'images') . ' AND rating_for_id=e.id) AS compound_rating';
         } elseif ($_sort == 'fixed_random') {
             $rating_sort = ',(MOD(id,3.142)) AS fixed_random';
         } else {
             $rating_sort = '';
         }
         $rows_images = $GLOBALS['SITE_DB']->query('SELECT *' . $rating_sort . ' FROM ' . get_table_prefix() . 'images e WHERE ' . $cat_select . ' AND ' . $image_select . $where_sup . ' ORDER BY ' . $sort, $max + $start);
         if ($_sort == 'compound_rating') {
             $rating_sort = ',(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', 'videos') . ' AND rating_for_id=e.id) AS compound_rating';
         } elseif ($_sort == 'fixed_random') {
             $rating_sort = ',(MOD(id,3.142)) AS fixed_random';
         } else {
             $rating_sort = '';
         }
         $rows_videos = $GLOBALS['SITE_DB']->query('SELECT *' . $rating_sort . ' FROM ' . get_table_prefix() . 'videos e WHERE ' . $cat_select . ' AND ' . $video_select . $where_sup . ' ORDER BY ' . $sort, $max + $start);
     }
     // Sort
     $combined = array();
     foreach ($rows_images as $row_image) {
         $combined[] = array($row_image, 'image', $_sort == 'random' ? NULL : $row_image[$_sort]);
     }
     foreach ($rows_videos as $row_video) {
         $combined[] = array($row_video, 'video', $_sort == 'random' ? NULL : $row_video[$_sort]);
     }
     if ($_sort == 'random') {
         shuffle($combined);
     } else {
         global $M_SORT_KEY;
         $M_SORT_KEY = 2;
         usort($combined, 'multi_sort');
         if ($_dir == 'DESC') {
             $combined = array_reverse($combined);
         }
     }
     // Display
     $entries = new ocp_tempcode();
     foreach ($combined as $i => $c) {
         if ($i >= $start) {
             switch ($c[1]) {
                 case 'image':
                     // Display image
                     $row_image = $c[0];
                     $view_url = build_url(array('page' => 'galleries', 'type' => 'image', 'wide' => 1, 'id' => $row_image['id']), $zone);
                     $thumb_url = ensure_thumbnail($row_image['url'], $row_image['thumb_url'], 'galleries', 'images', $row_image['id']);
                     $thumb = do_image_thumb($thumb_url, '', true);
                     $full_url = $row_image['url'];
                     $file_size = url_is_local($full_url) ? file_exists(get_custom_file_base() . '/' . rawurldecode($full_url)) ? strval(filesize(get_custom_file_base() . '/' . rawurldecode($full_url))) : '' : '';
                     if (url_is_local($full_url)) {
                         $full_url = get_custom_base_url() . '/' . $full_url;
                     }
                     $thumb_url = $row_image['thumb_url'];
                     if (url_is_local($thumb_url)) {
                         $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                     }
                     $entry_rating_details = $row_image['allow_rating'] == 1 ? display_rating($view_url, get_translated_text($row_image['title']), 'images', strval($row_image['id']), 'RATING_INLINE_STATIC', $row_image['submitter']) : NULL;
                     $entry_map = array('_GUID' => '043ac7d15ce02715ac02309f6e8340ff', 'RATING_DETAILS' => $entry_rating_details, 'TITLE' => get_translated_text($row_image['title']), 'DESCRIPTION' => get_translated_tempcode($row_image['comments']), 'ID' => strval($row_image['id']), 'FILE_SIZE' => $file_size, 'SUBMITTER' => strval($row_image['submitter']), 'FULL_URL' => $full_url, 'THUMB_URL' => $thumb_url, 'CAT' => $cat, 'THUMB' => $thumb, 'VIEW_URL' => $view_url, 'VIEWS' => strval($row_image['image_views']), 'ADD_DATE_RAW' => strval($row_image['add_date']), 'EDIT_DATE_RAW' => is_null($row_image['edit_date']) ? '' : strval($row_image['edit_date']));
                     $entry = do_template('GALLERY_IMAGE', $entry_map);
                     $entries->attach(do_template('GALLERY_ENTRY_WRAP', array('_GUID' => '13134830e1ebea158ab44885eeec0953', 'ENTRY' => $entry) + $entry_map));
                     break;
                 case 'video':
                     // Display video
                     $row_video = $c[0];
                     $view_url = build_url(array('page' => 'galleries', 'type' => 'video', 'wide' => 1, 'id' => $row_video['id']), $zone);
                     $thumb_url = $row_video['thumb_url'];
                     if ($thumb_url != '' && url_is_local($thumb_url)) {
                         $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                     }
                     if ($thumb_url == '') {
                         $thumb_url = find_theme_image('na');
                     }
                     $thumb = do_image_thumb($thumb_url, '', true);
                     $full_url = $row_video['url'];
                     if (url_is_local($full_url)) {
                         $full_url = get_custom_base_url() . '/' . $full_url;
                     }
                     $thumb_url = $row_video['thumb_url'];
                     if ($thumb_url != '' && url_is_local($thumb_url)) {
                         $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                     }
                     $entry_rating_details = $row_video['allow_rating'] == 1 ? display_rating($view_url, get_translated_text($row_video['title']), 'videos', strval($row_video['id']), 'RATING_INLINE_STATIC', $row_video['submitter']) : NULL;
                     $entry_map = array('_GUID' => '66b7fb4d3b61ef79d6803c170d102cbf', 'RATING_DETAILS' => $entry_rating_details, 'TITLE' => get_translated_text($row_video['title']), 'DESCRIPTION' => get_translated_tempcode($row_video['comments']), 'ID' => strval($row_video['id']), 'CAT' => $cat, 'THUMB' => $thumb, 'VIEW_URL' => $view_url, 'SUBMITTER' => strval($row_video['submitter']), 'FULL_URL' => $full_url, 'THUMB_URL' => $thumb_url, 'VIDEO_DETAILS' => show_video_details($row_video), 'VIEWS' => strval($row_video['video_views']), 'ADD_DATE_RAW' => strval($row_video['add_date']), 'EDIT_DATE_RAW' => is_null($row_video['edit_date']) ? '' : strval($row_video['edit_date']));
                     $entry = do_template('GALLERY_VIDEO', $entry_map);
                     $entries->attach(do_template('GALLERY_ENTRY_WRAP', array('_GUID' => 'a0ff010ae7fd1f7b3341993072ed23cf', 'ENTRY' => $entry) + $entry_map));
                     break;
             }
         }
         $i++;
         if ($i == $start + $max) {
             break;
         }
     }
     if (!isset($map['render_if_empty']) || $map['render_if_empty'] != '1') {
         if ($entries->is_empty()) {
             if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_galleries', array('galleries', $cat))) {
                 $submit_url = build_url(array('page' => 'cms_galleries', 'type' => 'ad', 'cat' => $cat, 'redirect' => SELF_REDIRECT), get_module_zone('cms_galleries'));
             } else {
                 $submit_url = new ocp_tempcode();
             }
             return do_template('BLOCK_NO_ENTRIES', array('_GUID' => 'bf84d65b8dd134ba6cd7b1b7bde99de2', 'HIGH' => false, 'TITLE' => do_lang_tempcode('GALLERY'), 'MESSAGE' => do_lang_tempcode('NO_ENTRIES'), 'ADD_NAME' => do_lang_tempcode('ADD_IMAGE'), 'SUBMIT_URL' => $submit_url));
         }
     }
     // Results browser
     require_code('templates_results_browser');
     $_selectors = array_map('intval', explode(',', get_option('gallery_selectors')));
     $root = get_param('root', 'root');
     $results_browser = results_browser(do_lang('ENTRY'), $cat, $start, 'mge_start', $max, 'mge_max', $total_videos + $total_images, $root, 'misc', true, false, 10, $_selectors);
     $tpl = do_template('BLOCK_MAIN_GALLERY_EMBED', array('_GUID' => 'b7b969c8fe8c398dd6e3af7ee06717ea', 'IMAGE_SELECT' => $map['select'], 'VIDEO_SELECT' => $map['video_select'], 'DAYS' => $_days, 'SORT' => $sort, 'BLOCK_PARAMS' => block_params_arr_to_str($map), 'RESULTS_BROWSER' => $results_browser, 'TITLE' => $title, 'CAT' => $cat, 'IMAGES' => $entries, 'MAX' => strval($max), 'ZONE' => $zone, 'TOTAL_VIDEOS' => strval($total_videos), 'TOTAL_IMAGES' => strval($total_images), 'TOTAL' => strval($total_videos + $total_images)));
     return $tpl;
 }