本文整理汇总了PHP中Tags::AddToFrequency方法的典型用法代码示例。如果您正苦于以下问题:PHP Tags::AddToFrequency方法的具体用法?PHP Tags::AddToFrequency怎么用?PHP Tags::AddToFrequency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tags
的用法示例。
在下文中一共展示了Tags::AddToFrequency方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Import
public function Import()
{
$imported = 0;
$DB = GetDB();
$yt = new Zend_Gdata_YouTube();
$video_feed = $yt->getVideoFeed($this->feed['feed_url']);
$entry;
foreach ($video_feed as $entry) {
// Check for duplicates, and skip
if ($DB->QueryCount('SELECT COUNT(*) FROM `tbx_video_feed_history` WHERE `feed_id`=? AND `unique_id`=?', array($this->feed['feed_id'], $entry->getVideoId()))) {
continue;
}
// Video is not embeddable, skip
if (!$entry->isVideoEmbeddable()) {
continue;
}
// Setup defaults
$video = $this->defaults;
$video['title'] = $entry->getVideoTitle();
$video['description'] = $entry->getVideoDescription();
$video['tags'] = Tags::Format(implode(' ', $entry->getVideoTags()));
$video['duration'] = $entry->getVideoDuration();
// Get preview images
$times = array();
$thumbs = array();
foreach ($entry->getVideoThumbnails() as $thumb) {
if (!isset($times[$thumb['time']])) {
$times[$thumb['time']] = true;
$thumbs[] = array('thumbnail' => $thumb['url']);
}
}
$clip = array('type' => 'Embed', 'clip' => '<object width="640" height="385">' . '<param name="movie" value="http://www.youtube.com/v/' . $entry->getVideoId() . '&fs=1"></param>' . '<param name="allowFullScreen" value="true"></param>' . '<param name="allowscriptaccess" value="always"></param>' . '<embed src="http://www.youtube.com/v/' . $entry->getVideoId() . '&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="640" height="385"></embed>' . '</object>');
$best_category = GetBestCategory(join(' ', array($video['title'], $video['description'], $video['tags'])));
if (!empty($best_category)) {
$video['category_id'] = $best_category;
}
$video['video_id'] = DatabaseAdd('tbx_video', $video);
DatabaseAdd('tbx_video_custom', $video);
DatabaseAdd('tbx_video_stat', $video);
if (!$video['is_private']) {
Tags::AddToFrequency($video['tags']);
}
UpdateCategoryStats($video['category_id']);
$video_dir = new Video_Dir(Video_Dir::DirNameFromId($video['video_id']));
$clip['video_id'] = $video['video_id'];
DatabaseAdd('tbx_video_clip', $clip);
$display_thumbnail = null;
foreach ($thumbs as $thumb) {
$thttp = new HTTP();
if ($thttp->Get($thumb['thumbnail'], $thumb['thumbnail'])) {
$temp_file = $video_dir->AddTempFromVar($thttp->body, JPG_EXTENSION);
$imgsize = @getimagesize($temp_file);
if ($imgsize !== false) {
if (Video_Thumbnail::CanResize()) {
$local_filename = Video_Thumbnail::Resize($temp_file, Config::Get('thumb_size'), Config::Get('thumb_quality'), $video_dir->GetThumbsDir());
} else {
$local_filename = $video_dir->AddThumbFromFile($temp_file, JPG_EXTENSION);
}
$local_filename = str_replace(Config::Get('document_root'), '', $local_filename);
$thumb_id = DatabaseAdd('tbx_video_thumbnail', array('video_id' => $video['video_id'], 'thumbnail' => $local_filename));
if (empty($display_thumbnail)) {
$display_thumbnail = $thumb_id;
}
} else {
unlink($temp_file);
}
}
}
if (!empty($display_thumbnail)) {
$DB->Update('UPDATE `tbx_video` SET `display_thumbnail`=? WHERE `video_id`=?', array($display_thumbnail, $video['video_id']));
}
$DB->Update('INSERT INTO `tbx_video_feed_history` VALUES (?,?)', array($this->feed['feed_id'], $entry->getVideoId()));
$imported++;
}
$DB->Update('UPDATE `tbx_video_feed` SET `date_last_read`=? WHERE `feed_id`=?', array(Database_MySQL::Now(), $this->feed['feed_id']));
UpdateSponsorStats($this->feed['sponsor_id']);
return $imported;
}
示例2: tbxUploadStepTwo
function tbxUploadStepTwo()
{
global $t;
$upload = $_FILES['video_file'];
$v = Validator::Create();
$DB = GetDB();
$v->Register(sha1($_REQUEST['step_one_data'] . Config::Get('random_value')) == $_REQUEST['step_one_sig'], Validator_Type::IS_TRUE, _T('Validation:Video Data Altered'));
$v->Register($upload['error'] == UPLOAD_ERR_OK, Validator_Type::IS_TRUE, Uploads::CodeToMessage($upload['error']));
if (is_uploaded_file($upload['tmp_name'])) {
$max_filesize = Format::StringToBytes(Config::Get('max_upload_size'));
$max_duration = Format::DurationToSeconds(Config::Get('max_upload_duration'));
$extensions = str_replace(',', '|', Config::Get('upload_extensions'));
$v->Register($upload['size'], Validator_Type::IS_BETWEEN, _T('Validation:Video size too large'), '1,' . $max_filesize);
$v->Register(File::Extension($upload['name']), Validator_Type::REGEX_MATCH, _T('Validation:Video file extension not allowed'), '~^(' . $extensions . ')$~');
try {
$vi = new Video_Info($upload['tmp_name']);
$vi->Extract();
$v->Register($vi->length, Validator_Type::LESS_EQ, _T('Validation:Video duration too long'), $max_duration);
} catch (Exception $e) {
$v->Register(false, Validator_Type::IS_TRUE, $e->getMessage());
}
$md5 = md5_file($upload['tmp_name']);
if (Config::Get('flag_upload_reject_duplicates')) {
$v->Register($DB->QueryCount('SELECT COUNT(*) FROM `tbx_video_md5sum` WHERE `md5`=?', array($md5)), Validator_Type::IS_ZERO, _T('Validation:Duplicate video'));
}
}
// Validate input
if (!$v->Validate()) {
$t->Assign('g_errors', $v->GetErrors());
$t->AssignByRef('g_form', $_REQUEST);
if (isset($_REQUEST['flash'])) {
$t->Display('upload-flash-errors.tpl');
} else {
$t->Assign('g_file_types', '*.' . str_replace(',', ';*.', Config::Get('upload_extensions')));
$t->Assign('g_cookie', $_COOKIE[LOGIN_COOKIE]);
$t->Display('upload-step-two.tpl');
}
return;
}
$_REQUEST = array_merge($_REQUEST, unserialize(base64_decode($_REQUEST['step_one_data'])));
Form_Prepare::Standard('tbx_video');
Form_Prepare::Standard('tbx_video_stat');
Form_Prepare::Custom('tbx_video_custom_schema', 'on_submit');
$_REQUEST['duration'] = $vi->length;
$_REQUEST['date_added'] = Database_MySQL::Now();
$_REQUEST['username'] = AuthenticateUser::GetUsername();
$_REQUEST['is_private'] = Config::Get('flag_upload_allow_private') ? intval($_REQUEST['is_private']) : 0;
$_REQUEST['allow_ratings'] = intval($_REQUEST['allow_ratings']);
$_REQUEST['allow_embedding'] = intval($_REQUEST['allow_embedding']);
$_REQUEST['allow_comments'] = intval($_REQUEST['allow_comments']) ? 'Yes - Add Immediately' : 'No';
$_REQUEST['is_user_submitted'] = 1;
if ($_REQUEST['recorded_day'] && $_REQUEST['recorded_month'] && $_REQUEST['recorded_year']) {
$_REQUEST['date_recorded'] = $_REQUEST['recorded_year'] . '-' . $_REQUEST['recorded_month'] . '-' . $_REQUEST['recorded_day'];
}
// Strip HTML tags
if (Config::Get('flag_video_strip_tags')) {
$_REQUEST = String::StripTags($_REQUEST);
}
// Configure status
$_REQUEST['status'] = STATUS_ACTIVE;
if (Config::Get('flag_upload_convert')) {
$_REQUEST['status'] = STATUS_QUEUED;
$_REQUEST['next_status'] = Config::Get('flag_upload_review') ? STATUS_PENDING : STATUS_ACTIVE;
} else {
if (Config::Get('flag_upload_review')) {
$_REQUEST['status'] = STATUS_PENDING;
}
}
// Add to database
$_REQUEST['video_id'] = DatabaseAdd('tbx_video', $_REQUEST);
DatabaseAdd('tbx_video_custom', $_REQUEST);
DatabaseAdd('tbx_video_stat', $_REQUEST);
if ($_REQUEST['status'] == STATUS_ACTIVE && !$_REQUEST['is_private']) {
Tags::AddToFrequency($_REQUEST['tags']);
} else {
if ($_REQUEST['status'] == STATUS_QUEUED) {
DatabaseAdd('tbx_conversion_queue', array('video_id' => $_REQUEST['video_id'], 'queued' => time()));
}
}
// Mark as private
if ($_REQUEST['is_private']) {
$_REQUEST['private_id'] = sha1(uniqid(rand(), true));
DatabaseAdd('tbx_video_private', $_REQUEST);
}
// Setup video files and generate thumbnails
$directory = Video_Dir::DirNameFromId($_REQUEST['video_id']);
$vd = new Video_Dir($directory);
$clip = $vd->AddClipFromFile($upload['tmp_name'], File::Extension($upload['name']));
if (Video_FrameGrabber::CanGrab()) {
Video_FrameGrabber::Grab($clip, $vd->GetThumbsDir(), Config::Get('thumb_amount'), Config::Get('thumb_quality'), Config::Get('thumb_size'), $vi);
}
foreach ($vd->GetClipURIs() as $clip) {
$_REQUEST['clip'] = $clip;
$_REQUEST['filesize'] = filesize(Config::Get('document_root') . $clip);
DatabaseAdd('tbx_video_clip', $_REQUEST);
}
$thumb_ids = array();
foreach ($vd->GetThumbURIs() as $thumb) {
$_REQUEST['thumbnail'] = $thumb;
$thumb_ids[] = DatabaseAdd('tbx_video_thumbnail', $_REQUEST);
//.........这里部分代码省略.........
示例3: Run
public static function Run()
{
chdir(realpath(dirname(__FILE__) . '/../'));
require_once 'includes/global.php';
$doc_root = Config::Get('document_root');
$DB = GetDB();
self::Log('Starting...');
self::MarkRunning();
while (true) {
// See if we were requested to stop
if (self::ShouldStop()) {
self::Log('User requested stop...');
break;
}
self::Ping();
$DB->Connect();
$queue_item = $DB->Row('SELECT *,`tbx_conversion_queue`.`video_id` AS `video_id`,`tbx_conversion_queue`.`queued` AS `queued` FROM `tbx_conversion_queue` LEFT JOIN ' . '`tbx_thumb_queue` USING (`video_id`) WHERE `tbx_thumb_queue`.`video_id` IS NULL ORDER BY `tbx_conversion_queue`.`queued` LIMIT 1');
if (!empty($queue_item)) {
$video = $DB->Row('SELECT * FROM `tbx_video` WHERE `video_id`=?', array($queue_item['video_id']));
if (!empty($video)) {
$DB->Update('UPDATE `tbx_video` SET `conversion_failed`=0 WHERE `video_id`=?', array($video['video_id']));
$DB->Update('UPDATE `tbx_conversion_queue` SET `date_started`=? WHERE `video_id`=?', array(Database_MySQL::Now(), $video['video_id']));
$clips = $DB->FetchAll('SELECT * FROM `tbx_video_clip` WHERE `video_id`=? ORDER BY `clip_id`', array($queue_item['video_id']));
$dir = new Video_Dir(Video_Dir::DirNameFromId($video['video_id']));
Video_Converter::SetLogFile($dir->GetBaseDir() . '/convert.log');
$convert_start = time();
$conversion_failed = false;
foreach ($clips as $clip) {
$clip_path = null;
$old_path = null;
try {
// Stored locally, move to originals directory
if ($clip['clip'][0] == '/') {
$old_path = $doc_root . $clip['clip'];
$clip_path = $dir->AddOriginalFromFile($old_path);
} else {
$http = new HTTP();
if ($http->Get($clip['clip'], $clip['clip'])) {
$clip_path = $dir->AddOriginalFromVar($http->body, File::Extension($clip['clip']));
} else {
throw new BaseException('Could not download clip for conversion: ' . $http->error);
}
}
$output_file = Video_Converter::Convert($clip_path, $dir->GetProcessingDir(), Config::Get('video_format'), Config::Get('video_bitrate'), Config::Get('audio_bitrate'), Config::Get('video_size'), array('ConversionQueue', 'Ping'));
$converted_video = $dir->AddClipFromFile($output_file);
$DB->Disconnect();
$DB->Connect();
$DB->Update('UPDATE `tbx_video_clip` SET `clip`=?,`filesize`=? WHERE `clip_id`=?', array(str_replace($doc_root, '', $converted_video), filesize($converted_video), $clip['clip_id']));
} catch (Exception $e) {
if (!empty($old_path) && !empty($clip_path)) {
rename($clip_path, $old_path);
}
Video_Converter::Log($e->getMessage() . (strtolower(get_class($e)) == 'baseexception' ? $e->getExtras() : '') . "\n" . $e->getTraceAsString());
$conversion_failed = true;
}
}
$convert_end = time();
$dir->ClearProcessing();
$dir->ClearTemp();
$DB->Connect();
$DB->Update('DELETE FROM `tbx_conversion_queue` WHERE `video_id`=?', array($queue_item['video_id']));
if ($conversion_failed) {
self::UpdateStatsProcessed($convert_start, $convert_end, $queue_item['queued'], true);
$DB->Update('UPDATE `tbx_video` SET `conversion_failed`=1 WHERE `video_id`=?', array($video['video_id']));
} else {
// Update stats
self::UpdateStatsProcessed($convert_start, $convert_end, $queue_item['queued']);
$status = empty($video['next_status']) ? STATUS_ACTIVE : $video['next_status'];
// Set video status
$DB->Update('UPDATE `tbx_video` SET `status`=? WHERE `video_id`=?', array($status, $video['video_id']));
if ($video['status'] != $status && $status == STATUS_ACTIVE && !$video['is_private']) {
Tags::AddToFrequency($video['tags']);
}
UpdateCategoryStats($video['category_id']);
}
}
} else {
break;
}
}
self::MarkStopped();
self::Log('Exiting...');
}
示例4: tbxVideoEdit
function tbxVideoEdit()
{
Privileges::Check(Privileges::VIDEOS);
$DB = GetDB();
$schema = GetDBSchema();
$v = Validator::Create();
$v->RegisterFromXml($schema->el('//table[name="tbx_video"]'));
$v->RegisterFromXml($schema->el('//table[name="tbx_video_custom"]'));
if (!String::IsEmpty($_REQUEST['username'])) {
$v->Register($DB->QueryCount('SELECT COUNT(*) FROM `tbx_user` WHERE `username`=?', array($_REQUEST['username'])) > 0, Validator_Type::IS_TRUE, 'The Username entered does not exist');
}
if (!$v->Validate()) {
return JSON::Failure(array('message' => 'Video could not be updated; please fix the following items', 'errors' => $v->GetErrors()));
}
$_REQUEST['display_thumbnail'] = empty($_REQUEST['display_thumbnail']) ? null : $_REQUEST['display_thumbnail'];
$_REQUEST['date_recorded'] = String::Nullify($_REQUEST['date_recorded']);
$_REQUEST['tags'] = Tags::Format($_REQUEST['tags']);
$_REQUEST['username'] = String::Nullify(Request::Get('username'));
$_REQUEST['duration'] = Format::DurationToSeconds($_REQUEST['duration']);
$original = $DB->Row('SELECT * FROM `tbx_video` WHERE `video_id`=?', array($_REQUEST['video_id']));
// Handle uploaded thumbs, if any
$dir = new Video_Dir(Video_Dir::DirNameFromId($original['video_id']));
$thumbs_added = 0;
$thumb_ids = array();
Request::FixFiles();
if (isset($_FILES['thumb_uploads'])) {
foreach ($_FILES['thumb_uploads'] as $upload) {
if (File::Extension($upload['name']) == JPG_EXTENSION && ($imgsize = getimagesize($upload['tmp_name'])) !== false) {
$temp_file = $dir->AddTempFromFile($upload['tmp_name'], JPG_EXTENSION);
if (Video_Thumbnail::CanResize()) {
$temp_file = Video_Thumbnail::Resize($temp_file, Config::Get('thumb_size'), Config::Get('thumb_quality'), $dir->GetTempDir());
}
$thumb = $dir->AddThumbFromFile($temp_file);
$thumbs_added++;
$thumb = str_replace(Config::Get('document_root'), '', $thumb);
$thumb_ids[] = array('uri' => $thumb, 'id' => DatabaseAdd('tbx_video_thumbnail', array('video_id' => $original['video_id'], 'thumbnail' => $thumb)));
}
}
if ($thumbs_added > 0) {
$dir->ClearTemp();
$_REQUEST['num_thumbnails'] = $original['num_thumbnails'] + $thumbs_added;
}
}
// Update base database tables
$video = DatabaseUpdate('tbx_video', $_REQUEST);
DatabaseUpdate('tbx_video_custom', $_REQUEST);
// Handle changes to video clips
foreach ($_REQUEST['clips'] as $clip_id => $clip) {
DatabaseUpdate('tbx_video_clip', array('video_id' => $video['video_id'], 'clip_id' => $clip_id, 'clip' => $clip['clip']));
}
if ($_REQUEST['is_private'] && !$original['is_private']) {
$_REQUEST['private_id'] = sha1(uniqid(mt_rand(), true));
DatabaseAdd('tbx_video_private', $_REQUEST);
if ($original['status'] == STATUS_ACTIVE) {
Tags::RemoveFromFrequency($original['tags']);
}
} else {
if (!$_REQUEST['is_private']) {
if ($original['status'] == STATUS_ACTIVE) {
if ($original['is_private']) {
Tags::AddToFrequency($_REQUEST['tags']);
} else {
Tags::UpdateFrequency($original['tags'], $_REQUEST['tags']);
}
}
$DB->Update('DELETE FROM `tbx_video_private` WHERE `video_id`=?', array($_REQUEST['video_id']));
}
}
if ($original['status'] == STATUS_ACTIVE) {
$t = new Template();
$t->ClearCache('categories.tpl');
}
UpdateCategoryStats($original['category_id'], $video['category_id']);
UpdateSponsorStats($original['sponsor_id'], $_REQUEST['sponsor_id']);
$output = array('id' => $video['video_id'], 'message' => 'Video has been successfully updated', 'html' => SearchItemHtml('video', $video), 'thumbs' => $thumb_ids);
JSON::Success($output);
}
示例5: Import
//.........这里部分代码省略.........
} else {
if (isset($video['duration_formatted'])) {
$video['duration'] = Format::DurationToSeconds($video['duration_formatted']);
}
}
// Use description for title
if (empty($video['title'])) {
$video['title'] = isset($video['description']) ? $video['description'] : '';
}
// Use title for description
if (empty($video['description'])) {
$video['description'] = isset($video['title']) ? $video['title'] : '';
}
// Use title for tags
if (empty($video['tags'])) {
$video['tags'] = isset($video['title']) ? $video['title'] : '';
}
// Setup category
if (isset($video['category']) && ($category_id = $DB->QuerySingleColumn('SELECT `category_id` FROM `tbx_category` WHERE `name` LIKE ?', array($video['category']))) !== false) {
$video['category_id'] = $category_id;
} else {
if (($category_id = GetBestCategory($video['title'] . ' ' . $video['description'])) !== null) {
$video['category_id'] = $category_id;
}
}
// Merge in the defaults
$video = array_merge($defaults, $video);
// Format tags and convert to UTF-8
$video['tags'] = Tags::Format($video['tags']);
$video = String::ToUTF8($video);
if (Request::Get('flag_convert')) {
$video['status'] = STATUS_QUEUED;
}
// Add to database
$video['video_id'] = DatabaseAdd('tbx_video', $video);
DatabaseAdd('tbx_video_custom', $video);
DatabaseAdd('tbx_video_stat', $video);
if ($video['is_private']) {
$video['private_id'] = sha1(uniqid(mt_rand(), true));
DatabaseAdd('tbx_video_private', $video);
}
if ($video['status'] == STATUS_QUEUED) {
$video['queued'] = time();
DatabaseAdd('tbx_conversion_queue', $video);
}
if (Request::Get('flag_thumb')) {
$video['queued'] = time();
DatabaseAdd('tbx_thumb_queue', $video);
}
if ($video['status'] == STATUS_ACTIVE && !$video['is_private']) {
Tags::AddToFrequency($video['tags']);
}
// Add clips
foreach ($clips as $clip) {
DatabaseAdd('tbx_video_clip', array('video_id' => $video['video_id'], 'type' => $clip_type, 'clip' => $clip));
}
$dir = new Video_Dir(Video_Dir::DirNameFromId($video['video_id']));
// Process thumbs
$thumb_ids = array();
foreach ($thumbs as $thumb) {
$http = new HTTP();
if ($http->Get($thumb, $thumb)) {
if (Video_Thumbnail::CanResize()) {
$thumb_temp = $dir->AddTempFromVar($http->body, 'jpg');
$thumb_file = Video_Thumbnail::Resize($thumb_temp, Config::Get('thumb_size'), Config::Get('thumb_quality'), $dir->GetThumbsDir());
} else {
$thumb_file = $dir->AddThumbFromVar($http->body);
}
if (!empty($thumb_file)) {
$thumb_ids[] = DatabaseAdd('tbx_video_thumbnail', array('video_id' => $video['video_id'], 'thumbnail' => str_replace(Config::Get('document_root'), '', $thumb_file)));
}
}
}
// Determine number of thumbnails and select random display thumbnail
$num_thumbnails = count($thumb_ids);
$display_thumbnail = null;
if ($num_thumbnails > 0) {
// Select display thumbnail randomly from the first 40%
$display_thumbnail = $thumb_ids[rand(0, floor(0.4 * $num_thumbnails))];
}
DatabaseUpdate('tbx_video', array('video_id' => $video['video_id'], 'num_thumbnails' => $num_thumbnails, 'display_thumbnail' => $display_thumbnail));
$imported++;
}
fclose($fp);
UpdateCategoryStats();
UpdateSponsorStats($settings['sponsor_id']);
$t = new Template();
$t->ClearCache('categories.tpl');
ProgressBarHide('pb-import', NumberFormatInteger($imported) . ' videos have been imported!');
// Start up the thumbnail and converson queues if needed
if (!Config::Get('flag_using_cron')) {
if (Request::Get('flag_convert')) {
ConversionQueue::Start();
}
if (Request::Get('flag_thumb')) {
ThumbQueue::Start();
}
}
File::Delete($file);
}
示例6: ActivateScheduledVideos
function ActivateScheduledVideos()
{
$DB = GetDB();
$args = ParseCommandLine();
$queries = array();
if (!isset($args['sort']) || empty($args['sort'])) {
$args['sort'] = 'RAND()';
}
if (!isset($args['sort-direction']) || empty($args['sort-direction'])) {
$args['sort-direction'] = SQL::SORT_ASC;
}
if (isset($args['amount'])) {
$sb = new SQL_SelectBuilder('tbx_video');
$sb->AddSelectField('`video_id`');
$sb->AddSelectField('`tags`');
$sb->AddWhere('tbx_video.status', SQL::EQUALS, STATUS_SCHEDULED);
$sb->AddOrder($args['sort'], $args['sort-direction']);
$sb->SetLimit($args['amount']);
$queries[] = $DB->Prepare($sb->Generate(), $sb->Binds());
} else {
if (isset($args['amount-per-sponsor'])) {
$result = $DB->Query('SELECT `sponsor_id` FROM `tbx_sponsor`');
while ($sponsor = $DB->NextRow($result)) {
$sb = new SQL_SelectBuilder('tbx_video');
$sb->AddSelectField('`video_id`');
$sb->AddSelectField('`tags`');
$sb->AddWhere('tbx_sponsor.sponsor_id', SQL::EQUALS, $sponsor['sponsor_id']);
$sb->AddWhere('tbx_video.status', SQL::EQUALS, STATUS_SCHEDULED);
$sb->AddOrder($args['sort'], $args['sort-direction']);
$sb->SetLimit($args['amount-per-sponsor']);
$queries[] = $DB->Prepare($sb->Generate(), $sb->Binds());
}
$DB->Free($result);
} else {
if (isset($args['amount-per-category'])) {
$result = $DB->Query('SELECT `category_id` FROM `tbx_category`');
while ($category = $DB->NextRow($result)) {
$sb = new SQL_SelectBuilder('tbx_video');
$sb->AddSelectField('`video_id`');
$sb->AddSelectField('`tags`');
$sb->AddWhere('tbx_video.category_id', SQL::EQUALS, $category['category_id']);
$sb->AddWhere('tbx_video.status', SQL::EQUALS, STATUS_SCHEDULED);
$sb->AddOrder($args['sort'], $args['sort-direction']);
$sb->SetLimit($args['amount-per-category']);
$queries[] = $DB->Prepare($sb->Generate(), $sb->Binds());
}
$DB->Free($result);
} else {
throw new BaseException('One of --amount, --amount-per-sponsor or --amount-per-category must be specified');
}
}
}
foreach ($queries as $query) {
$result = $DB->Query($query);
while ($video = $DB->NextRow($result)) {
$DB->Update('UPDATE `tbx_video` SET `status`=?,`date_added`=? WHERE `video_id`=?', array(STATUS_ACTIVE, Database_MySQL::Now(), $video['video_id']));
Tags::AddToFrequency($video['tags']);
}
$DB->Free($result);
}
UpdateCategoryStats();
}
示例7: define
<?php
// Copyright 2011 JMB Software, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
if (!preg_match('~/admin$~', realpath(dirname(__FILE__)))) {
echo "This file must be located in the admin directory of your TubeX installation";
exit;
}
define('TUBEX_CONTROL_PANEL', true);
require_once 'includes/cp-global.php';
$DB = GetDB();
$DB->Update('DELETE FROM `tbx_video_tag`');
$result = $DB->Query('SELECT * FROM `tbx_video` WHERE `status`=? AND `is_private`=?', array(STATUS_ACTIVE, 0));
while ($video = $DB->NextRow($result)) {
$video['tags'] = Tags::Format($video['tags']);
Tags::AddToFrequency($video['tags']);
$DB->Update('UPDATE `tbx_video` SET `tags`=? WHERE `video_id`=?', array($video['tags'], $video['video_id']));
}
$DB->Free($result);
echo "VIDEO TAGS HAVE BEEN SUCCESSFULLY UPDATED!\n";
示例8: Import
public function Import()
{
$imported = 0;
$http = new HTTP();
if ($http->Get($this->feed['feed_url'])) {
$xml = simplexml_load_string($this->ToUTF8($http->body), 'XML_Element', LIBXML_NOERROR, LIBXML_NOWARNING, LIBXML_NOCDATA);
if ($xml !== false) {
$DB = GetDB();
foreach ($xml->xpath('//videos/video') as $xvideo) {
// Check for duplicates, and skip
if ($DB->QueryCount('SELECT COUNT(*) FROM `tbx_video_feed_history` WHERE `feed_id`=? AND `unique_id`=?', array($this->feed['feed_id'], $xvideo->id->val()))) {
continue;
}
// Setup defaults
$video = $this->defaults;
$video['title'] = $xvideo->title->val();
$video['description'] = $xvideo->description->val();
$video['tags'] = Tags::Format($xvideo->tags->val());
if (empty($video['description'])) {
$video['description'] = $video['title'];
}
// Process <clips>
$clips = array();
$screens = array();
foreach ($xvideo->xpath('./clips/clip') as $xclip) {
$video['duration'] += $xclip->duration;
$clip_url = $xvideo->clip_url->val();
$flv = $xclip->flv->val();
// Account for malformed feeds where the clip_url contains the URL to the video
// file rather than the required root URL
if (strstr($clip_url, $flv) === false) {
$clip_url = $clip_url . $flv;
}
$clips[] = array('type' => 'URL', 'clip' => $clip_url);
foreach ($xclip->xpath('./screens/screen') as $xscreen) {
$screen_url = $xvideo->screen_url->val();
$screen = $xscreen->val();
// Account for malformed feeds where the screen_url contains the URL to the image
// file rather than the required root URL
if (strstr($screen_url, $screen) === false) {
$screen_url = $screen_url . $screen;
}
$screens[] = array('thumbnail' => $screen_url);
}
}
if (count($clips) > 0) {
$best_category = GetBestCategory(join(' ', array($video['title'], $video['description'], $video['tags'])));
if (!empty($best_category)) {
$video['category_id'] = $best_category;
}
if ($this->feed['flag_convert']) {
$video['status'] = STATUS_QUEUED;
$video['next_status'] = $this->feed['status'];
}
$video['video_id'] = DatabaseAdd('tbx_video', $video);
DatabaseAdd('tbx_video_custom', $video);
DatabaseAdd('tbx_video_stat', $video);
if (!$video['is_private']) {
Tags::AddToFrequency($video['tags']);
}
$video['queued'] = time();
if ($this->feed['flag_convert']) {
DatabaseAdd('tbx_conversion_queue', $video);
}
if ($this->feed['flag_thumb']) {
DatabaseAdd('tbx_thumb_queue', $video);
}
UpdateCategoryStats($video['category_id']);
$video_dir = new Video_Dir(Video_Dir::DirNameFromId($video['video_id']));
foreach ($clips as $clip) {
$clip['video_id'] = $video['video_id'];
DatabaseAdd('tbx_video_clip', $clip);
}
$display_thumbnail = null;
foreach ($screens as $screen) {
$thttp = new HTTP();
if ($thttp->Get($screen['thumbnail'], $screen['thumbnail'])) {
$temp_file = $video_dir->AddTempFromVar($thttp->body, JPG_EXTENSION);
$imgsize = @getimagesize($temp_file);
if ($imgsize !== false) {
if (Video_Thumbnail::CanResize()) {
$local_filename = Video_Thumbnail::Resize($temp_file, Config::Get('thumb_size'), Config::Get('thumb_quality'), $video_dir->GetThumbsDir());
} else {
$local_filename = $video_dir->AddThumbFromFile($temp_file, JPG_EXTENSION);
}
$local_filename = str_replace(Config::Get('document_root'), '', $local_filename);
$thumb_id = DatabaseAdd('tbx_video_thumbnail', array('video_id' => $video['video_id'], 'thumbnail' => $local_filename));
if (empty($display_thumbnail)) {
$display_thumbnail = $thumb_id;
}
}
}
}
$video_dir->ClearTemp();
if (!empty($display_thumbnail)) {
$DB->Update('UPDATE `tbx_video` SET `display_thumbnail`=? WHERE `video_id`=?', array($display_thumbnail, $video['video_id']));
}
$DB->Update('INSERT INTO `tbx_video_feed_history` VALUES (?,?)', array($this->feed['feed_id'], $xvideo->id->val()));
$imported++;
}
//.........这里部分代码省略.........