private function set_video_data_from_get() { if (isset($_GET['video_id'])) { $this->set_video_data(VideoLibrary_DatabaseHelper::get_external_video_data($_GET['video_id'])); } else { throw new VideoGallery_VideoNotSetException(); } }
public static function get_video_name_for_external_video_id($id) { try { $video_data = VideoLibrary_DatabaseHelper::get_external_video_data($id); return $video_data['name']; } catch (VideoLibrary_Exception $e) { return $e->getMessage(); } }
public function do_actions() { try { /* * Get videos which haven't been processed */ $queued_videos = VideoLibrary_DatabaseHelper::get_external_videos_frame_grabbing_queue('last_processed IS NULL'); // print_r($queued_videos);exit; foreach ($queued_videos as $queued_video) { /** * get the thumbnail urls */ $video = VideoLibrary_DatabaseHelper::get_external_video_data($queued_video['external_video_id']); $thumbnail_urls = VideoLibrary_CLIScriptsHelper::get_thumbnail_urls_for_external_video($video); // print_r($thumbnail_urls);exit; $i = 1; foreach ($thumbnail_urls as $thumbnail_url) { try { /* *Download the thumbnail */ $thumbnail_filename = $video['id'] . '_' . $i . '.jpg'; $thumbnails_original_dir = VideoLibrary_CLIScriptsHelper::get_thumbnails_original_directory(); $original_filename = VideoLibrary_CLIScriptsHelper::download_file($thumbnail_url, $thumbnails_original_dir, $thumbnail_filename); /* *Resize the thumbnail and copy the resized versions *to the other directories */ $thumbnails_medium_dir = VideoLibrary_CLIScriptsHelper::get_thumbnails_medium_directory(); $medium_width = VideoLibrary_CLIScriptsHelper::get_thumbnails_medium_width(); $medium_height = VideoLibrary_CLIScriptsHelper::get_thumbnails_medium_height(); $medium_filename = VideoLibrary_CLIScriptsHelper::resize_image($original_filename, $medium_width, $medium_height, $thumbnails_medium_dir, $thumbnail_filename); /** * Update the video's status and thumbnail details * but only for the first thumb */ if ($i == 1) { $thumbnails_medium_web_dir = VideoLibrary_CLIScriptsHelper::get_thumbnails_medium_web_directory(); $thumbnails_medium_web_dir .= substr($thumbnails_medium_web_dir, -1) != DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : ""; VideoLibrary_DatabaseHelper::set_external_video_thumbnail_url($video['id'], $thumbnails_medium_web_dir . $thumbnail_filename); VideoLibrary_DatabaseHelper::update_external_video_frame_grabbing_queue_for_video($queued_video['id']); } $output = '#' . $video['id'] . ' Set thumbnail ' . $i . ' for video "' . $video['name'] . '"' . PHP_EOL; print_r($this->colour_output($output, 'green')); $i++; } catch (Exception $e) { $output = "#" . $video['id'] . ' Failed to set thumbnail ' . $i . ' for video "' . $video['name'] . '" (' . $e->getMessage() . ")" . PHP_EOL; print_r($this->colour_output($output, 'red')); } } } print_r('Queue processed. Exiting...' . PHP_EOL); } catch (VideoLibrary_Exception $e) { print_r($this->colour_output($e->getMessage() . PHP_EOL, 'red')); exit; } }
public function do_actions() { try { VideoLibrary_DatabaseHelper::add_all_videos_to_external_videos_frame_grabbing_queue(); $output = 'Succeeded' . PHP_EOL; print_r($this->colour_output($output, 'green')); } catch (Exception $e) { $output = 'Failed' . ' (' . $e->getMessage() . ")" . PHP_EOL; print_r($this->colour_output($output, 'red')); } print_r('Exiting...' . PHP_EOL); }
public static function get_external_videos_for_search_string($external_video_library_id, $search_string, $start, $duration, $options = array('count' => FALSE, 'admin' => FALSE)) { /* *Prepare the string */ $search_string = strtolower($search_string); /* * Search Names of the videos */ $named_videos_sql = VideoLibrary_DatabaseHelper::get_sql_parts_for_external_videos_by_searching_in_video_names($external_video_library_id, $search_string, $start, $duration, array('count' => $options['count'], 'admin' => $options['admin'], 'union_query' => TRUE)); if ($options['count'] == FALSE) { /* * Because the tagged sql has an extra column (for its * quirky merging behaviour) I have to insert a dummy one * here to union them */ $named_videos_sql['select'] .= ',' . "\n" . 'external_video_id'; } /* * Search Tags of the videos, */ $tag_names = array(VideoLibrary_TagsHelper::filter_tag($search_string)); $search_string_exploded = explode(' ', trim($search_string)); foreach ($search_string_exploded as $tag_name) { $tag_names[] = VideoLibrary_TagsHelper::filter_tag($tag_name); } // print_r($tag_names);exit; /* * Old style, uses tag1 AND tag2, so less results */ // $tagged_videos_sql = VideoLibrary_DatabaseHelper:: // get_sql_parts_for_external_videos_for_tag_names( // $external_video_library_id, // $tag_names, // NULL, // $start, // $duration, // array( // 'count' => $options['count'], // 'admin' => $options['admin'], // 'union_query' => TRUE // ) // ); /* * This related vids function uses tag1 OR tag2 */ $tag_names = VideoLibrary_DatabaseHelper::limit_tags($tag_names); $tagged_videos_sql = VideoLibrary_RelatedVideosDatabaseHelper::get_sql_parts_for_external_videos_matching_any_of_these_tags($external_video_library_id, $tag_names, NULL, NULL, $start, $duration, array('count' => $options['count'], 'use_ids_for_tags' => FALSE, 'union_query' => TRUE)); $videos = self::get_external_videos_through_union_query(array($tagged_videos_sql, $named_videos_sql), array('count' => $options['count'])); // print_r($videos);exit; return $videos; }
public function render_json() { if (isset($_GET['ajax']) && isset($_GET['check_providers_internal_id']) && isset($_GET['providers_internal_id']) && isset($_GET['external_video_provider_id'])) { $result = VideoLibrary_DatabaseHelper::video_exists_in_external_videos_by_external_video_provider_id_and_providers_internal_id($_GET['external_video_provider_id'], $_GET['providers_internal_id']); echo '{ "result" : '; if ($result) { echo 'true'; } else { echo 'false'; } echo ' }'; } }
public static function get_related_videos_for_external_video_data($external_video_library_id, $video_data, $external_video_provider_id = NULL, $start = NULL, $duration = NULL) { // print_r($start . ' - ' . $duration);exit; /* * TODO: * Surely a better way of extracting this data? */ $tag_ids = array(); foreach ($video_data['tags'] as $tag) { $tag_ids[] = $tag['id']; } if (isset($external_video_provider_id)) { return VideoLibrary_DatabaseHelper::get_related_external_videos_for_tag_ids($external_video_library_id, $tag_ids, $external_video_provider_id, $video_data['id'], $start, $duration); } else { return VideoLibrary_DatabaseHelper::get_related_external_videos_for_tag_ids($external_video_library_id, $tag_ids, NULL, $video_data['id'], $start, $duration); } }
protected function render_edit_something_form_ol() { $acm = $this->get_admin_crud_manager(); echo "<ol>\n"; $this->render_edit_something_form_li_text_input('name'); $this->render_edit_something_form_li_text_input('url'); $status_values = VideoLibrary_DatabaseHelper::get_enum_values('hpi_video_library_external_video_providers', 'status'); $status_li = '<li><label for="status">Status</label><select name="status">'; foreach ($status_values as $status_value) { $status_li .= '<option value="' . $status_value . '"'; $cur_status_value = $acm->has_current_var('status') ? $acm->get_current_var('status') : NULL; if ($cur_status_value == $status_value) { $status_li .= ' selected="selected"'; } $status_li .= '>' . $status_value . '</option>'; } $status_li .= '</select></li>'; echo $status_li; $this->render_edit_something_form_li_text_input('haddock_class_name'); echo "</ol>\n"; }
public function is_video_unique($external_video_provider_id, $providers_internal_id) { if (VideoLibrary_DatabaseHelper::video_exists_in_external_videos_by_external_video_provider_id_and_providers_internal_id($external_video_provider_id, $providers_internal_id)) { throw new VideoLibrary_VideoAlreadyExistsInDatabaseException(); } return TRUE; }
private function get_related_videos_div() { /** * TODO: * Get these providers from the SQL * As a possible optimisation */ $related_video_providers = VideoLibrary_DatabaseHelper::get_external_video_providers_for_videos(VideoLibrary_RelatedVideosHelper::get_related_videos_for_external_video_data($this->get_external_video_library_id(), $this->get_video_data())); //print_r($video_data);exit; $div = new HTMLTags_Div(); $div->set_attribute_str('id', 'related-videos'); $div->append('<h2 class="related-videos">Related Videos</h2>'); $video_data = $this->get_video_data(); $video_page_url = VideoLibrary_URLHelper::get_video_page_url($video_data['id']); $providers_wrapper_div = new HTMLTags_Div(); $providers_wrapper_div->set_attribute_str('id', 'providers-wrapper'); $providers_wrapper_div->append('<h3 id="channels">Channels</h3>'); $providers_wrapper_div->append(VideoLibrary_DisplayHelper::get_external_video_provider_navigation_div($related_video_providers, $video_page_url)); $div->append($providers_wrapper_div); $video_control_wrapper_div = new HTMLTags_Div(); $video_control_wrapper_div->set_attribute_str('id', 'video-control-wrapper'); $thumbnails_wrapper_div = new HTMLTags_Div(); $thumbnails_wrapper_div->set_attribute_str('id', 'thumbnails-wrapper'); $thumbnails_wrapper_div->append(VideoLibrary_DisplayHelper::get_thumbnails_div($this->get_related_videos())); $video_control_wrapper_div->append($thumbnails_wrapper_div); $video_control_wrapper_div->append(VideoLibrary_DisplayHelper::get_pager_div($this->get_start(), $this->get_duration(), $this->get_total_related_videos_count(), $this->get_page_url())); $div->append($video_control_wrapper_div); $div->append('<div class="clear"> </div>'); return $div; }
public static function get_sql_parts_for_external_videos_matching_any_of_these_tags($external_video_library_id, $tag_ids, $external_video_provider_id = NULL, $ignore_video_id = NULL, $start = NULL, $duration = NULL, $options = array('count' => FALSE, 'principal_tags' => FALSE, 'use_ids_for_tags' => TRUE, 'union_query' => FALSE)) { $sql = array(); if ($options['count']) { $sql['select'] = VideoLibrary_DatabaseHelper::get_select_sql_for_external_videos_count(array('union_query' => $options['union_query'])); } else { $sql['select'] = VideoLibrary_DatabaseHelper::get_select_sql_for_external_videos(); $sql['select'] .= ' ,' . "\n" . 'COUNT( * ) AS tag_count' . "\n"; } $sql['from'] = VideoLibrary_DatabaseHelper::get_from_sql_for_external_videos(); $sql['from'] .= <<<SQL , hpi_video_library_tags, hpi_video_library_tags_to_ext_vid_links SQL; $external_video_library_id = mysql_real_escape_string($external_video_library_id); $sql['where'] = <<<SQL WHERE hpi_video_library_external_video_libraries.id = hpi_video_library_ext_vid_to_ext_vid_lib_links.external_video_library_id AND hpi_video_library_external_videos.id = hpi_video_library_ext_vid_to_ext_vid_lib_links.external_video_id SQL; if (isset($external_video_provider_id)) { $sql['where'] .= <<<SQL AND hpi_video_library_external_video_providers.id = '{$external_video_provider_id}' SQL; } $sql['where'] .= <<<SQL AND hpi_video_library_external_video_libraries.id = '{$external_video_library_id}' AND hpi_video_library_external_videos.external_video_provider_id = hpi_video_library_external_video_providers.id AND hpi_video_library_external_videos.id = hpi_video_library_tags_to_ext_vid_links.external_video_id AND hpi_video_library_tags.id = hpi_video_library_tags_to_ext_vid_links.tag_id AND hpi_video_library_external_videos.status = 'display' AND hpi_video_library_external_video_providers.status = 'display' SQL; if (count($tag_ids) > 0) { $sql['where'] .= <<<SQL AND ( SQL; $i = 0; foreach ($tag_ids as $tag_id) { $tag_id = mysql_real_escape_string($tag_id); if ($i != 0) { $sql['where'] .= <<<SQL OR SQL; } $i++; if ($options['principal_tags']) { if ($options['use_ids_for_tags']) { $sql['where'] .= <<<SQL ( hpi_video_library_tags.id = '{$tag_id}' AND hpi_video_library_tags.principal = 'yes' ) SQL; } else { $sql['where'] .= <<<SQL ( hpi_video_library_tags.tag = '{$tag_id}' AND hpi_video_library_tags.principal = 'yes' ) SQL; } } else { if ($options['use_ids_for_tags']) { $sql['where'] .= <<<SQL ( hpi_video_library_tags.id = '{$tag_id}' ) SQL; } else { $sql['where'] .= <<<SQL ( hpi_video_library_tags.tag = '{$tag_id}' ) SQL; } } } $sql['where'] .= <<<SQL ) SQL; } if ($ignore_video_id > 0) { $ignore_video_id = mysql_real_escape_string($ignore_video_id); $sql['where'] .= <<<SQL AND hpi_video_library_external_videos.id <> {$ignore_video_id} SQL; } if (!$options['count']) { $sql['group_by'] = <<<SQL GROUP BY hpi_video_library_external_videos.id SQL; $sql['limit'] = VideoLibrary_DatabaseHelper::get_limit_sql_for_external_videos($start, $duration); } return $sql; }
protected function set_total_videos_count() { $count = VideoLibrary_DatabaseHelper::get_external_videos_count($this->get_external_video_library_id()); $this->total_videos_count = $count; }
public function render_content_to_delete_everything() { VideoLibrary_DatabaseHelper::delete_all_external_videos_in_frame_grabbing_queue(); $back_a = new HTMLTags_A('Back to the Queue'); $back_href = $this->get_current_base_url(); $back_a->set_href($back_href); $back_a_str = $back_a->get_as_string(); echo <<<HTML <h2>Remove all External Videos from the Frame Grabbing Queue</h2> <p> All videos have been removed and the queue has been emptied. </p> <ul> <li> {$back_a_str} </li> </ul> HTML; }
public function get_tags_list_for_form($library_values) { $div = '<div id="tags-list">'; // $div .= '<h3>Principal Tags</h3>'; // $div .= VideoLibrary_DisplayHelper::get_tags_empty_links_list( // VideoLibrary_DatabaseHelper::get_tags(TRUE) // )->get_as_string(); foreach ($library_values as $library_value) { $principal_lib_tags = VideoLibrary_DatabaseHelper::get_tags_for_external_library_id($library_value['id'], TRUE); $lib_tags = VideoLibrary_DatabaseHelper::get_tags_for_external_library_id($library_value['id']); if (count($lib_tags) > 0) { $div .= '<div class="library ' . $library_value['id'] . '">'; $div .= '<div class="principal-tags ' . $library_value['name'] . '">'; $div .= '<h3>Principal ' . $library_value['name'] . ' Tags</h3>'; $div .= VideoLibrary_DisplayHelper::get_tags_empty_links_list($principal_lib_tags)->get_as_string(); $div .= '</div>'; $div .= '<h3>All ' . $library_value['name'] . ' Tags</h3>'; $div .= VideoLibrary_DisplayHelper::get_tags_empty_links_list($lib_tags)->get_as_string(); $div .= '</div>'; } } // $div .= '<h3>All Tags</h3>'; // $div .= VideoLibrary_DisplayHelper::get_tags_empty_links_list( // VideoLibrary_DatabaseHelper::get_tags() // )->get_as_string(); $div .= '</div>'; return $div; }
public function delete_something() { $dbh = DB::m(); $id = mysql_real_escape_string($_GET['id'], $dbh); $stmt = <<<SQL DELETE FROM \thpi_video_library_external_videos WHERE \tid = {$id} SQL; #echo $stmt; exit; mysql_query($stmt, $dbh); $stmt_2 = <<<SQL DELETE FROM \thpi_video_library_ext_vid_to_ext_vid_lib_links WHERE \texternal_video_id = {$id} SQL; #echo $stmt; exit; mysql_query($stmt_2, $dbh); $stmt_3 = <<<SQL DELETE FROM \thpi_video_library_tags_to_ext_vid_links WHERE \texternal_video_id = {$id} SQL; #echo $stmt; exit; mysql_query($stmt_3, $dbh); VideoLibrary_DatabaseHelper::delete_orphaned_tags(); }
public function render_content_to_view_a_library() { echo $this->get_back_link_p(); if (isset($_GET['id'])) { $tag_array = array(); $tag_array[] = $_GET['id']; echo VideoLibrary_DisplayHelper::get_admin_view_library_div(VideoLibrary_DatabaseHelper::get_all_external_videos_for_tag_ids_on_admin_page($tag_array))->get_as_string(); } else { echo '<p>Form ID not set!</p>'; } echo $this->get_back_link_p(); }
protected function set_provider_navigation_div() { $providers = VideoLibrary_DatabaseHelper::get_external_video_providers_for_external_video_library_id($this->get_external_video_library_id()); $this->provider_navigation_div = VideoLibrary_DisplayHelper::get_external_video_provider_navigation_div($providers, VideoLibrary_URLHelper::get_search_page_url()); }
protected function get_videos_description_div() { if (isset($_GET['external_video_provider_id'])) { $external_video_provider = VideoLibrary_DatabaseHelper::get_external_video_provider_for_id($this->get_external_video_provider_id()); } else { $external_video_provider = NULL; } if (isset($_GET['q'])) { $search_query = $_GET['q']; } else { $search_query = NULL; } // if (isset($_GET['external_video_library_id'])) { // $external_video_library_id = $_GET['external_video_library_id']; // } else { // $external_video_library_id = $this->get_external_video_library_id(); // } return VideoLibrary_DisplayHelper::get_search_page_videos_description_div($this->get_tags(), $external_video_provider, $this->get_external_video_library_id(), $search_query); }
public function render_content_to_view_a_video() { echo $this->get_back_link_p(); echo $this->get_actions_div()->get_as_string(); if (isset($_GET['id'])) { echo VideoLibrary_DisplayHelper::get_admin_view_video_div(VideoLibrary_DatabaseHelper::get_external_video_data($_GET['id'])); } else { echo '<p>Form ID not set!</p>'; } echo $this->get_back_link_p(); }