execute(sprintf("SELECT `usr_perm` FROM `db_accountuser` WHERE `usr_id`='%s' LIMIT 1;", $uid)); $perm = unserialize($p->fields['usr_perm']); } /* layout start */ $html = $side == 'frontend' ? '
' . ($err ? '
' . VGenerate::noticeTpl('', $err, '') : null) . '
' : ''; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
    '; /* embed single file */ if ($side == 'backend' or ($side == 'frontend' and intval($perm['perm_embed_single']) == 1 and !$err)) { if ($all == 1) { $html .= '
  • '; $html .= '
    '; $html .= VGenerate::simpleDivWrap('top-padding5 wd90p all-paddings5 bold pointer', '', ' ' . $language['backend.import.embed.h1'], '', 'span'); $html .= ''; $html .= ''; $html .= '
    '; $html .= '
    '; $html .= '
    '; $html .= VGenerate::sigleInputEntry('text', 'left-float lh20 wd140', '', 'left-float', 'be_video_url', 'text-input wd190', ''); $html .= VGenerate::simpleDivWrap('row', '', '
    ' . $category_file . '
    '); $html .= $side == 'backend' ? VGenerate::simpleDivWrap('row top-padding15', '', '
    ' . self::username_selectList('import_single') . '
    ') : null; $html .= VGenerate::simpleDivWrap('row', '', '

    ' . VGenerate::basicInput('button', 'find_video_file', 'button-grey search-button form-button save-entry-button find-video-file', '', 'embed', '' . $language['backend.embed.video.find'] . '')); $html .= '
    '; $html .= '
    '; $html .= '
  • '; } else { $html .= VGenerate::simpleDivWrap('row', '', $language['backend.import.menu.disabled.functions']); } } if ($cfg['import_yt'] == 1) { if ($side == 'backend' or ($side == 'frontend' and intval($perm['perm_embed_yt_video']) == 1 and !$err)) { $resnr = ((int) $_POST['yt_video_results'] > 0) ? (int) $_POST['yt_video_results'] : 10; /* import youtube video feeds */ $html .= '
  • '; $html .= '
    '; $html .= VGenerate::simpleDivWrap('top-padding5 wd90p all-paddings5 bold pointer', '', ' ' . $language['backend.import.feed.h1'], '', 'span'); $html .= ''; $html .= ''; $html .= '
    '; $html .= ''; $html .= '
  • '; } if ($side == 'backend' or ($side == 'frontend' and intval($perm['perm_embed_yt_channel']) == 1 and !$err)) { $resnr = ((int) $_POST['yt_channel_results'] > 0) ? (int) $_POST['yt_channel_results'] : 10; /* import youtube channel feeds */ $html .= '
  • '; $html .= '
    '; $html .= VGenerate::simpleDivWrap('top-padding5 wd90p all-paddings5 bold pointer', '', ' ' . $language['backend.import.channel.h1'], '', 'span'); $html .= ''; $html .= ''; $html .= '
    '; $html .= ''; $html .= '
  • '; } } if ($cfg['import_vi'] == 1) { if ($side == 'backend' or ($side == 'frontend' and intval($perm['perm_embed_vi_user']) == 1 and !$err)) { /* import vimeo user feeds */ $html .= '
  • '; $html .= '
    '; $html .= VGenerate::simpleDivWrap('top-padding5 wd90p all-paddings5 bold pointer', '', ' ' . $language['backend.import.vimeo.h1'], '', 'span'); $html .= ''; $html .= ''; $html .= '
    '; $html .= ''; $html .= '
  • '; } } if ($cfg['import_dm'] == 1) { if ($side == 'backend' or ($side == 'frontend' and intval($perm['perm_embed_dm_video']) == 1 and !$err)) { /* import dailymotion video feeds */ $html .= '
  • '; $html .= '
    '; $html .= VGenerate::simpleDivWrap('top-padding5 wd90p all-paddings5 bold pointer', '', ' ' . $language['backend.import.dm.video.h1'], '', 'span'); $html .= ''; $html .= ''; $html .= '
    '; $html .= ''; $html .= '
  • '; } if ($side == 'backend' or ($side == 'frontend' and intval($perm['perm_embed_dm_user']) == 1 and !$err)) { /* import dailymotion user feeds */ $html .= '
  • '; $html .= '
    '; $html .= VGenerate::simpleDivWrap('top-padding5 wd90p all-paddings5 bold pointer', '', ' ' . $language['backend.import.dm.h1'], '', 'span'); $html .= ''; $html .= ''; $html .= '
    '; $html .= ''; $html .= '
  • '; } } $html .= '
'; $html .= '
'; //end left-side $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; //end right-side $html .= '
'; $html .= '
'; $html .= '
'; //end import-wrap $html .= '
'; $html .= ' '; return $html; } /* check for existing accounts */ public function chkAccount() { global $db, $language; $chk = $db->execute("SELECT `usr_key`, `usr_user` FROM `db_accountuser` WHERE `usr_status`='1' ORDER BY `usr_user` LIMIT 1;"); $err = $chk->fields['usr_key'] == '' ? $language['upload.err.msg.13'] : null; return $err; } /* get "other" category id */ public function getOther() { global $db; $c = $db->execute("SELECT `ct_id` FROM `db_categories` WHERE (`ct_name`='Other' OR `ct_descr` LIKE '%other%') AND `ct_type`='video' LIMIT 1;"); $ct_id = $c->fields['ct_id']; return ($ct_id > 0 ? $ct_id : 1); } /* select all/none entries */ public function selectEntries($btn1, $btn2, $list_button = false) { global $language, $cfg; $sel = '
'; $sel = null; if ($cfg['import_mode'] == 'ask') { $save_action = '
'; } else { $save_action = '
'; } $button = VGenerate::simpleDivWrap('row', '', '

' . VGenerate::basicInput('button', $btn1, 'button-grey save-entry-button search-list-entry search-button form-button ' . str_replace('_', '-', $btn1), '', 'import', '' . $language['backend.import.feed.list'] . '') . '
'); $html = $list_button ? $button : $save_action; return $html; } /* submit YOUTUBE video feeds */ public function processVideoFeed() { global $cfg; if (isset($_POST['feed_categ'])) { //standard feeds $out = self::getAndPrintStandardFeeds('m1'); } else { //channel feeds $out = self::getAndPrintStandardFeeds('m2'); } echo $out; } /* submit VIMEO user video feeds */ public function processVimeoFeed() { global $class_filter, $language, $cfg, $smarty, $side; $user = $class_filter->clr_str(trim($_POST['feed_channel_vimeo'])); $type = $class_filter->clr_str($_POST['feed_type_vimeo']); $results = $class_filter->clr_str($_POST['feed_results_vimeo']); $smarty->assign('page_display', 'tpl_import'); switch ($results) { case '1_-_20':$page = 1; break; case '21_-_40':$page = 2; break; case '41_-_60':$page = 3; break; default:$page = 1; break; } $vimeo_api = 'http://vimeo.com/api/v2/' . $user . '/' . $type . '.php?page=' . $page; $r = VServer::curl_tt($vimeo_api); $res = unserialize($r); $count = 1; $checked = count($_POST['import_id']); $error = false; $btn1 = 'list_vimeo_feed'; $btn2 = 'import_vimeo_feed'; $usr = 'assign_username_import_vimeo_channel'; $btn = VGenerate::basicInput('button', $btn2, 'no-display save-videos-button search-button form-button ' . str_replace('_', '-', $btn2), '', 'import', $language['backend.import.feed.import']); if ($_GET['do'] == 'import-vimeo-feed' and $checked == 0) { $error = VGenerate::noticeTpl('', $language['backend.embed.nosel'], ''); } elseif ($_POST[$usr] == '' and $side == 'backend' and $_GET['do'] == 'import-vimeo-feed') { $error = VGenerate::noticeTpl('', $language['backend.embed.username'], ''); } if (is_array($res)) { $html = '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= self::selectEntries($btn1, $btn2); $html .= $btn; $html .= '
'; $html .= '
' . $smarty->fetch("tpl_backend/tpl_settings/ct-save-open-close.tpl") . '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
' . $error . '
'; $html .= ''; $html .= '
'; $html .= VGenerate::declareJS(self::grabberjs()); $html .= ''; } else { $html = $r; } $ht = '
' . $html . '
'; echo $ht; } /* submit DAILYMOTION user and video feeds */ public function processDailymotionFeed() { global $class_filter, $db, $language, $smarty, $cfg, $side; $_do = $class_filter->clr_str($_GET['do']); $user = $class_filter->clr_str(trim($_POST['feed_channel_dm'])); $type = $class_filter->clr_str($_POST['feed_type_dm']); $type_video = $class_filter->clr_str($_POST['feed_type_dm_video']); $categ_video = $class_filter->clr_str($_POST['assign_category_dm_video']); $sort_video = $class_filter->clr_str($_POST['feed_sort_dm_video']); $region_video = $class_filter->clr_str($_POST['feed_region_dm']); $search_video = $class_filter->clr_str($_POST['be_search_term']); $results = ($_do == 'dm-feed' or $_do == 'import-dm-user') ? $class_filter->clr_str($_POST['feed_results_dm']) : $class_filter->clr_str($_POST['feed_results_dm_type']); $fr = explode("-", $results); $feed_start = substr($fr[0], 0, -1); $feed_max = substr($fr[1], 1); $feed_stop = 50; $feed_page = $feed_max / $feed_stop; $dm_api = 'https://api.dailymotion.com'; $dm_get = ($_do == 'dm-feed' or $_do == 'import-dm-user') ? '/user/' . $user . '/' . $type : '/videos'; $dm_param = '?page=' . $feed_page . '&limit=' . $feed_stop . '&fields=description,duration,tags,title,channel,thumbnail_url,thumbnail_small_url,thumbnail_medium_url,thumbnail_large_url,url,id'; if ($_do == 'dm-video' or $_do == 'import-dm-video') { $dm_param .= ($type_video != '' ? '&filters=' . $type_video : null); $dm_param .= ($categ_video != '' ? '&channel=' . $categ_video : null); $dm_param .= ($sort_video != '' ? '&sort=' . $sort_video : null); $dm_param .= ($region_video != '' ? '&language=' . $region_video : null); $dm_param .= ($search_video != '' ? '&search=' . urlencode($search_video) : null); } $dm_api = $dm_api . $dm_get . $dm_param; $rs = VServer::curl_tt($dm_api); $res = json_decode($rs, true); $err = $res['error']['message'] != '' ? $res['error']['message'] : false; $error = false; $total = count($res['list']); $checked = is_array($_POST['import_id']) ? count($_POST['import_id']) : 0; if ($_do == 'dm-feed' or $_do == 'import-dm-user') { $btn1 = 'list_dailymotion_feed'; $btn2 = 'import_dailymotion_feed'; $usr = 'assign_username_import_dm_channel'; } else { $btn1 = 'list_dailymotion_feed_video'; $btn2 = 'import_dailymotion_feed_video'; $usr = 'assign_username_import_dm_video'; } $smarty->assign('page_display', 'tpl_import'); $btn = VGenerate::basicInput('button', $btn2, 'no-display save-videos-button search-button form-button ' . str_replace('_', '-', $btn2), '', 'import', $language['backend.import.feed.import']); if (($_GET['do'] == 'import-dm-user' or $_GET['do'] == 'import-dm-video') and $checked == 0) { $error = VGenerate::noticeTpl('', $language['backend.embed.nosel'], ''); } elseif ($_POST[$usr] == '' and $side == 'backend' and ($_GET['do'] == 'import-dm-user' or $_GET['do'] == 'import-dm-video')) { $error = VGenerate::noticeTpl('', $language['backend.embed.username'], ''); } $i = 0; $count = 1; $html = '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= self::selectEntries($btn1, $btn2); $html .= $btn; $html .= '
'; $html .= '
' . $smarty->fetch("tpl_backend/tpl_settings/ct-save-open-close.tpl") . '
'; $html .= '
'; $html .= '
'; //end left-float $html .= '
'; //end section-top-bar $html .= '
'; $html .= '
' . ($err != '' ? $err : $error) . '
'; $html .= ''; $html .= '
'; $html .= VGenerate::declareJS(self::grabberjs()); $html .= ''; $ht = '
' . $html . '
'; echo $ht; } private static function durationFromString($string) { if (is_array($string) and isset($string[0])) { $string = $string[0]; } if (substr($string, 0, 2) === "PT") { $period = new DateInterval($string); $totalSeconds = $period->s + $period->i * 60; } else { if (strpos($string, ":") !== false) { $exp = explode(":", $string); $ext = count($exp); if ($ext == 2) { $hours = 0; list($minutes, $seconds) = $exp; } elseif ($ext == 3) { list($hours, $minutes, $seconds) = $exp; } $totalSeconds = $hours * 3600 + $minutes * 60 + $seconds; } else { $totalSeconds = $string; } } return (float) $totalSeconds; } private static function extractUniqueWords($inputArray, $limit = 10) { $uniqueWords = array(); $count = 0; foreach ($inputArray as $text) { $words = explode(" ", $text); foreach ($words as $word) { // Remove non-alphanumeric characters and convert to lowercase $word = strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $word)); // Check if the word is longer than 4 characters and not in the $uniqueWords array if (strlen($word) > 4 && !in_array($word, $uniqueWords)) { $uniqueWords[] = $word; $count++; } // Stop after reaching the specified limit if ($count >= $limit) { break 2; // Break both the inner and outer loops } } } return $uniqueWords; } /* submit single video embed */ public function processVideoEmbed() { global $class_filter, $language, $cfg; require_once 'f_core/f_classes/class_oembed/vendor/autoload.php'; // $video_url = $class_filter->clr_str($_POST['be_video_url']); $video_url = htmlspecialchars($_POST['be_video_url']); $video_categ = $class_filter->clr_str($_POST['assign_category_file']); $u = parse_url($video_url); $h = explode('.', $u['host']); $src = $h[(count($h) - 2)]; $src = ($src == 'youtu' ? 'youtube' : $src); $data = array(); $duration = null; $short = 0; try { $embed = new Embed(); $info = $embed->get($video_url); $title = $info->title; $thumb = $info->image; $code = $info->code->html; $description = $info->description ?: $title; $tags = $info->keywords ?: $title; if ($src == 'facebook') { $metas = $info->getMetas()->all(); $title = $metas['og:title'][0]; $description = $metas['og:description'][0]; $thumb = $metas['og:image'][0]; $tags = implode(' ', self::extractUniqueWords(array_slice($metas['og:title'], 0, 10))); $code = '
'; } if (is_array($tags)) { $tags = implode(' ', self::extractUniqueWords(array_slice($tags, 0, 10))); } if (strpos($u['path'], "/shorts/") !== false) { $short = 1; } if ($title and $thumb and $code) { $metas = $info->getMetas()->all(); if (isset($metas['og:video:duration'])) { $duration = $metas['og:video:duration']; } elseif (isset($metas['video:duration'])) { $duration = $metas['video:duration']; } elseif (isset($metas['duration'][0])) { $duration = $metas['duration'][0]; } elseif (isset($metas['duration'])) { $duration = $metas['duration']; } if ($duration) { $duration = self::durationFromString($duration); } if (!$duration) { $ld = $info->getLinkedData()->all(); if (isset($ld[0]['duration'])) { $duration = $ld[0]['duration']; } elseif (isset($ld['duration'])) { $duration = $ld['duration']; } if ($duration) { $duration = self::durationFromString($duration); } } if (!$duration) { $duration = 1; } $key = md5($video_url); if ($src == 'youtube') { $u = parse_url($video_url); $v = explode('&', $u['query']); $id = $class_filter->clr_str(substr($v[0], 2)); if ($id == '') { $id = str_replace("/", "", $u['path']); } $key = str_replace('shorts', '', $id); if ($short) { $thumb = 'https://i.ytimg.com/vi/' . $key . '/hq720.jpg'; } } $data['src'] = $src; $data['title'] = $title; $data['description'] = $description; $data['duration'] = $duration; $data['tags'] = $tags; $data['url'] = $info->url; $data['code'] = $code; $data['key'] = $key; $data['category'] = null; $data['short'] = $short; $data['tmb'] = array( 0 => $thumb, 1 => $thumb, ); $html = self::embedFile_details($src, $data); echo $html; } else { echo VGenerate::noticeTpl('', 'Unable to extract video data.', ''); return false; } } catch (Exception $e) { echo VGenerate::noticeTpl('', $e->getMessage(), ''); return false; } } /* print details about embedded video */ public function embedFile_details($src, $info) { global $cfg, $db, $class_filter, $language, $smarty, $side; $ec = preg_replace('/(width|height)="[^"]*"/', '$1="100%"', $info['code']); $video_categ = $class_filter->clr_str($_POST['assign_category_file']); $username = $class_filter->clr_str($_POST['assign_username_import_single']); $db_uid = $class_filter->clr_str($_POST['assign_username']); if ($cfg['import_mode'] == 'ask') { $save_action = '
'; } else { $save_action = '
'; } $error = false; if ($video_categ == '' and $_GET['do'] == 'video-embed') { $error = VGenerate::noticeTpl('', $language['backend.embed.category'], ''); } elseif ($username == '' and $_GET['do'] == 'video-embed' and $side == 'backend') { $error = VGenerate::noticeTpl('', $language['backend.embed.username'], ''); } $smarty->assign('page_display', 'tpl_import'); $html = '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= VGenerate::simpleDivWrap('row', '', $save_action); $html .= VGenerate::basicInput('button', 'embed_video_file', 'no-display save-videos-button search-button form-button embed-video-file', '', 'embed', $language['backend.embed.video.save']); $html .= '
'; $html .= '
' . $smarty->fetch("tpl_backend/tpl_settings/ct-save-open-close.tpl") . '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
' . $error . '
'; $html .= ''; $html .= '
'; $html .= VGenerate::declareJS(self::grabberjs()); $html .= ''; return $html; } /* check and save selected files, save single embedded file */ public function saveCheck($db_rkey, $info) { global $language, $class_filter, $db; $ok = null; $_do = $class_filter->clr_str($_GET['do']); $checked = $_do == 'video-embed' ? 1 : (is_array($_POST['import_id']) ? count($_POST['import_id']) : 0); $save_action = $class_filter->clr_str($_POST['save_action']); if ($_do == 'video-embed' or (substr($_GET['do'], 0, 6) == 'import' and $checked > 0)) { if ($_do == 'video-embed' or (in_array($db_rkey, $_POST['import_id']))) { $act = self::embedFile_save(array( "title" => $info['title'], "description" => $info['description'], "tags" => $info['tags'], "category" => $info['category'], "duration" => $info['duration'], "key" => $info['key'], "src" => $info['src'], "url" => $info['url'], "tmb" => $info['tmb'], "short" => (int) $info['short'], )); if ($db->Affected_Rows() > 0) { $ok = '' . ($save_action == 'download' ? $language['backend.embed.confirmed.dl'] : $language['backend.embed.confirmed']) . ''; } else { $ok = '' . $language['backend.embed.failed'] . ''; } } } return $ok; } /* save file to database */ public function embedFile_save($info) { global $class_database, $cfg, $db, $class_filter, $side, $smarty; $err = false; $short = (isset($info['short']) and $info['short'] == 1); $type = $short ? 'short' : 'video'; $filekey = VUserinfo::generateRandomString(10); $chk = $class_database->singleFieldValue('db_' . $type . 'files', 'db_id', 'file_key', $filekey); for ($i = 1; $i <= 10; $i++) { $chk = $class_database->singleFieldValue('db_' . $type . 'files', 'db_id', 'file_key', $filekey); if ($chk) { $filekey = VUserinfo::generateRandomString(10); } else { break; } } $ukey = $side == 'backend' ? $class_filter->clr_str($_POST['assign_username']) : $_SESSION['USER_KEY']; if ($ukey == '' and $side != 'backend') { header("Location:" . $cfg['main_url'] . '/' . VHref::getKey('signout')); exit; } $info['title'] = $class_filter->clr_str($info['title']); $info['description'] = $class_filter->clr_str(str_replace(array('
', '
'), array("\n", "\n"), $info['description'])); $info['tags'] = str_replace('quot', '', $info['tags']); $info['tags'] = str_replace('amp', '', $info['tags']); $categ = isset($_POST['assign_category_file']) ? $class_filter->clr_str($_POST['assign_category_file']) : (isset($_POST['assign_category_feed']) ? $class_filter->clr_str($_POST['assign_category_feed']) : (isset($_POST['assign_category_channel']) ? $class_filter->clr_str($_POST['assign_category_channel']) : (isset($_POST['assign_category_dm_type']) ? $class_filter->clr_str($_POST['assign_category_dm_type']) : (isset($_POST['assign_category_dm']) ? $class_filter->clr_str($_POST['assign_category_dm']) : (isset($_POST['assign_category_vimeo']) ? $class_filter->clr_str($_POST['assign_category_vimeo']) : self::getOther()))))); if ($side == 'backend') { $ukey = isset($_POST['assign_category_file']) ? $class_filter->clr_str($_POST['assign_username_import_single']) : (isset($_POST['assign_category_feed']) ? $class_filter->clr_str($_POST['assign_username_import_yt_video']) : (isset($_POST['assign_category_channel']) ? $class_filter->clr_str($_POST['assign_username_import_yt_channel']) : (isset($_POST['assign_category_dm_type']) ? $class_filter->clr_str($_POST['assign_username_import_dm_video']) : (isset($_POST['assign_category_dm']) ? $class_filter->clr_str($_POST['assign_username_import_dm_channel']) : (isset($_POST['assign_category_vimeo']) ? $class_filter->clr_str($_POST['assign_username_import_vimeo_channel']) : self::getOther()))))); } $usr_id = $side == 'backend' ? $class_database->singleFieldValue('db_accountuser', 'usr_id', 'usr_key', $ukey) : intval($_SESSION['USER_ID']); $save_action = $class_filter->clr_str($_POST['save_action']); $db_approved = (($cfg['file_approval'] == 1 or $save_action == 'download') ? 0 : 1); $v_info = array( "usr_id" => $usr_id, "file_key" => $filekey, "old_file_key" => 0, "file_type" => 'embed', "file_name" => 'none', "file_size" => 0, "file_duration" => $class_filter->clr_str(($info['duration'] == '' or (int) $info['duration'] == 0) ? 1 : $info['duration']), "upload_date" => date("Y-m-d H:i:s"), "is_subscription" => ($side == 'frontend' ? intval($cfg['paid_memberships']) : 0), "file_views" => 0, "file_comments" => 0, "file_responses" => 0, "file_like" => 0, "file_dislike" => 0, "file_mobile" => 1, "embed_key" => $class_filter->clr_str(str_replace('shorts', '', $info['key'])), "embed_src" => $class_filter->clr_str($info['src']), "embed_url" => $class_filter->clr_str($info['url']), "file_title" => $info['title'], "file_description" => $info['description'], "file_tags" => VForm::clearTag($info['tags']), "file_category" => intval($categ != '' ? $categ : $info['category']), "approved" => $db_approved, "privacy" => "public", "comments" => "all", "comment_votes" => 1, "rating" => 1, "responding" => "all", "embedding" => 1, "social" => 1, ); if ($cfg['paid_memberships'] == 1 and $side == 'frontend' and $save_action == 'embed') { $err = VUpload::subscriptionCheck($type); $db_id = 0; } if (!$err) { $do_db = $class_database->doInsert('db_' . $type . 'files', $v_info); $db_id = $db->Insert_ID(); } if ($db_id > 0) { if ($save_action == 'download') { $v_que = array( "file_key" => $filekey, "usr_key" => $ukey, ); $do_db = $class_database->doInsert('db_videodl', $v_que); } $activity = ($cfg['activity_logging'] == 1 and $action = new VActivity($usr_id, 0)) ? $action->addTo('log_upload', $type . ':' . $filekey) : null; $src_folder = $cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/'; foreach ($info['tmb'] as $k => $tmb) { //download thumbnails $tmb = $info['tmb'][$k]; $file_loc = $cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/' . $k . '.tmp.jpg'; $file_src = $cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/0.tmp.jpg'; $d1 = $cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey; if (!is_dir($d1)) { mkdir($d1); } if ($info['src'] == 'youtube' and $k == 0) { $cmd = 'curl -r 0-25 --silent ' . $tmb . ' | identify -format "%wx%h" -'; // error_log($cmd); exec($cmd . ' 2>&1', $output); $dim = $output[0]; if ($dim == '120x90') { $tmb = str_replace('maxresdefault.jpg', 'mqdefault.jpg', $tmb); } } $ch = curl_init($tmb); $fp = fopen($file_loc, 'wb'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); curl_close($ch); fclose($fp); if (file_exists($file_loc) and $k > 0) { $conv = new VDocument(); $conv->log_setup($filekey, true); $dst_folder_tmb = $cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/'; if ($conv->createThumbs_ffmpeg($src_folder, $k, 640, 360, $filekey, $ukey, $file_src, $short)) { $final = $cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/' . $k . '.jpg'; if (file_exists($final)) { unlink($file_loc); } } } } if (file_exists($file_src)) { $conv = new VDocument(); $conv->log_setup($filekey, true); $dst_folder_tmb = $cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/'; if ($conv->createThumbs_ffmpeg($src_folder, 0, 640, 360, $filekey, $ukey, $file_src, $short)) { $final = $cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/0.jpg'; if (file_exists($final)) { unlink($file_src); } } } if (!VGenerate::isImage($cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/0.jpg')) { if (file_exists($cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/0.jpg')) { unlink($cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/0.jpg'); } if (file_exists($cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/1.jpg')) { unlink($cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/1.jpg'); } $tmp_file = str_replace($cfg['main_url'], $cfg['main_dir'], VUseraccount::getProfileImage($usr_id, false)); if ($tmp_file && is_file($tmp_file)) { $src_folder = $cfg['media_files_dir'] . '/' . $ukey . '/t/' . $filekey . '/'; $conv = new VDocument(); $conv->log_setup($filekey, false); if ($conv->createThumbs_ffmpeg($src_folder, '1', 320, 180, $filekey, $ukey, $tmp_file, $short)) {} if ($conv->createThumbs_ffmpeg($src_folder, '0', 640, 360, $filekey, $ukey, $tmp_file, $short)) {} } } $ct_update = $db->execute(sprintf("UPDATE `db_accountuser` SET `usr_%s_count`=`usr_%s_count`+1 WHERE `usr_id`='%s' LIMIT 1;", $type[0], $type[0], $usr_id)); if ($cfg['paid_memberships'] == 1 and $side == 'frontend' and $save_action == 'embed') { $ct_update = $db->execute(sprintf("UPDATE `db_packusers` SET `pk_total_%s`=`pk_total_%s`+1 WHERE `usr_id`='%s' LIMIT 1;", $type, $type, $usr_id)); } } } /* get youtube tags from title */ public function yt_tags($string) { $tags = array(); $arr = explode(' ', $string); foreach ($arr as $word) { if (strlen($word) > 4) { $tags[] = VUserinfo::clearString($word); } } if ($tags[0][0]) { return str_replace(array('amp', 'quot'), array('', ''), implode(" ", $tags)); } } /* single file embed, get YOUTUBE details */ public function embedFile_youtube($url) { return; global $class_filter, $language, $cfg; $DEVELOPER_KEY = $cfg['youtube_api_key']; $client = new Google_Client(); $client->setDeveloperKey($DEVELOPER_KEY); // Define an object that will be used to make all API requests. $youtube = new Google_Service_YouTube($client); $info = array(); $v = explode('&', $url['query']); $id = $url['path'] == "/watch" ? $class_filter->clr_str(substr($v[0], 2)) : null; if ($id == '') { $id = str_replace(array("/live", "/"), array("", ""), $url['path']); } try { $videosResponse = $youtube->videos->listVideos('snippet,contentDetails,statistics,status', array( 'id' => $id, )); foreach ($videosResponse['items'] as $videoResult) { $info['src'] = 'youtube'; $info['key'] = $id; $info['title'] = $videoResult['snippet']['title']; $info['description'] = $videoResult['snippet']['description']; $info['tags'] = self::yt_tags($class_filter->clr_str($info['title'])); $info['category'] = $language['backend.import.feed.categ.list'][$videoResult['snippet']['categoryId']]; $date = new DateTime('1970-01-01'); $date->add(new DateInterval($videoResult['contentDetails']['duration'])); $duration = $date->format('H:i:s'); $d = explode(':', $duration); $info['duration'] = ($d[0] * 60 * 60) + ($d[1] * 60) + ($d[2]); $tmb = array( 0 => "http://i.ytimg.com/vi/" . $id . "/maxresdefault.jpg", 1 => "http://i.ytimg.com/vi/" . $id . "/mqdefault.jpg", 2 => "http://i.ytimg.com/vi/" . $id . "/mqdefault.jpg", 3 => "http://i.ytimg.com/vi/" . $id . "/mqdefault.jpg", ); $info['tmb'] = $tmb; } } catch (Google_Service_Exception $e) { $htmlBody .= sprintf('

A service error occurred: %s

', htmlspecialchars($e->getMessage())); } catch (Google_Exception $e) { $htmlBody .= sprintf('

An client error occurred: %s

', htmlspecialchars($e->getMessage())); } $html = self::embedFile_details('youtube', $info); echo $html; } /* single file embed, get VIMEO details */ public function embedFile_vimeo($url) { global $class_filter; $info = array(); $id = $class_filter->clr_str(substr($url['path'], 1)); $vimeo_api = 'http://vimeo.com/api/v2/video/' . $id . '.php'; $r = unserialize(VServer::curl_tt($vimeo_api)); $info['src'] = 'vimeo'; $info['key'] = $id; $info['title'] = $r[0]['title']; $info['description'] = $r[0]['description']; $info['tags'] = str_replace(',', ' ', $r[0]['tags']); $info['category'] = ''; $info['duration'] = $r[0]['duration']; $tmb = array( 0 => $r[0]['thumbnail_large'], 1 => $r[0]['thumbnail_medium'], 2 => $r[0]['thumbnail_medium'], 3 => $r[0]['thumbnail_medium'], ); $info['tmb'] = $tmb; $html = self::embedFile_details('vimeo', $info); echo $html; } /* single file embed, get DAILYMOTION details */ public function embedFile_dailymotion($url) { $info = array(); $p = explode('_', $url['path']); $id = str_replace('/video/', '', $p[0]); $dm_api = 'https://api.dailymotion.com/video/' . $id . '?fields=description,duration,tags,title,channel,thumbnail_url,thumbnail_small_url,thumbnail_medium_url,thumbnail_large_url'; $rs = VServer::curl_tt($dm_api); $r = json_decode($rs); $info['src'] = 'dailymotion'; $info['key'] = $id; $info['title'] = $r->{'title'}; $info['description'] = $r->{'description'}; $info['tags'] = implode(" ", $r->{'tags'}); $info['category'] = $r->{'channel'}; $info['duration'] = $r->{'duration'}; $tmb = array( 0 => $r->{'thumbnail_url'}, 1 => $r->{'thumbnail_medium_url'}, 2 => $r->{'thumbnail_medium_url'}, 3 => $r->{'thumbnail_medium_url'}, ); $info['tmb'] = $tmb; $html = self::embedFile_details('dailymotion', $info); echo $html; } /* youtube video feeds functions */ public function getAndPrintVideoFeed($api_url, $feed_type) { global $language, $class_filter; $response = VServer::curl_tt($api_url); $results = json_decode($response); $res = self::printVideoFeed($results, $feed_type); $html = $res == '' ? $language['backend.import.feed.stop'] : $res; return '
' . $html . '
'; } public function printVideoFeed($videoFeed, $feed_type) { global $class_filter, $language, $cfg, $smarty, $side; $error = false; $count = 1; if (is_array($videoFeed) and count($videoFeed) == 0) { return false; } $smarty->assign('page_display', 'tpl_import'); $checked = is_array($_POST['import_id']) ? count($_POST['import_id']) : 0; switch ($feed_type) { case "m1": $form = 'video-feed-form'; $btn1 = 'list_video_feed'; $btn2 = 'import_video_feed'; $usr = 'assign_username_import_yt_video'; break; case "m2": $form = 'channel-feed-form'; $btn1 = 'list_channel_feed'; $btn2 = 'import_channel_feed'; $usr = 'assign_username_import_yt_channel'; break; } $btn = VGenerate::basicInput('button', $btn2, 'no-display save-videos-button search-button form-button ' . str_replace('_', '-', $btn2), '', 'import', $language['backend.import.feed.import']); if (($_GET['do'] == 'import-yt-channel' or $_GET['do'] == 'import-yt-video') and $checked == 0) { $error = VGenerate::noticeTpl('', $language['backend.embed.nosel'], ''); } elseif ($_POST[$usr] == '' and $side == 'backend' and ($_GET['do'] == 'import-yt-channel' or $_GET['do'] == 'import-yt-video')) { $error = VGenerate::noticeTpl('', $language['backend.embed.username'], ''); } $html = null; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= self::selectEntries($btn1, $btn2); $html .= $btn; $html .= '
'; $html .= '
' . $smarty->fetch("tpl_backend/tpl_settings/ct-save-open-close.tpl") . '
'; $html .= '
'; $html .= '
'; //end left-float $html .= '
'; //end section-top-bar $html .= '
'; $html .= '
' . $error . '
'; $html .= ''; $html .= '
'; $nextPageToken = $videoFeed->nextPageToken; $prevPageToken = $videoFeed->prevPageToken; $currentPageToken = isset($_GET['token']) ? $class_filter->clr_str($_GET['token']) : null; $pjsct = $prevPageToken != '' ? '' . $prevPageToken . '' : '##prevPageToken##'; $njsct = '' . $nextPageToken . ''; $cjsct = $currentPageToken != '' ? '' . $currentPageToken . '' : '##currentPageToken##'; $js = '$(document).ready(function(){$("#' . $form . ' .next-page").html(\'' . $njsct . '\');$("#' . $form . ' .prev-page").html(\'' . $pjsct . '\');$("#' . $form . ' .current-page").html(\'' . $cjsct . '\');});'; $js .= self::grabberjs(); $html .= VGenerate::declareJS($js); $html .= ''; return $html; } public function grabberjs() { $js .= '$(".icheck-box.fetched input").each(function () { var self = $(this); self.iCheck({ checkboxClass: "icheckbox_square-blue", radioClass: "iradio_square-blue", increaseArea: "20%" }); }); $(".embed-title").each(function () { var self = $(this).text(); $(this).parent().parent().parent().find(".entry-title-off").first().append(self); $(this).detach(); }); $(document).on({click: function () { $("#right-side .responsive-accordion div.responsive-accordion-head").addClass("active"); $("#right-side .responsive-accordion div.responsive-accordion-panel").addClass("active").show(); $("#right-side .responsive-accordion i.responsive-accordion-plus").hide(); $("#right-side .responsive-accordion i.responsive-accordion-minus").show(); resizeDelimiter(); }}, "#all-open"); $(document).on({click: function () { $("#right-side .responsive-accordion div.responsive-accordion-head").removeClass("active"); $("#right-side .responsive-accordion div.responsive-accordion-panel").removeClass("active").hide(); $("#right-side .responsive-accordion i.responsive-accordion-plus").show(); $("#right-side .responsive-accordion i.responsive-accordion-minus").hide(); $("#ct_entry").val(""); resizeDelimiter(); }}, "#all-close"); $("#checkselect-all-entries input").on("ifChecked", function () { $("#import-wrap .responsive-accordion input").iCheck("check"); }); $("#checkselect-all-entries input").on("ifUnchecked", function () { $("#import-wrap .responsive-accordion input").iCheck("uncheck"); }); $(".icheck-box.ask input").each(function () { var self = $(this); label = self.parent().parent().find("label").first(); label_text = label.text(); label.detach(); self.iCheck({ checkboxClass: "icheckbox_line-blue place-left", radioClass: "iradio_line-blue place-left", insert: "
" + label_text }); }); '; return $js; } public function printVideoEntry($videoFeed, $_id, $error = false) { global $class_filter, $db, $cfg, $language; $DEVELOPER_KEY = $cfg['youtube_api_key']; $client = new Google_Client(); $client->setDeveloperKey($DEVELOPER_KEY); $youtube = new Google_Service_YouTube($client); $videosResponse = $youtube->videos->listVideos('snippet,contentDetails,statistics,status', array('id' => $_id)); foreach ($videosResponse['items'] as $videoResult) { $category = str_replace(' ', '%', VForm::clearTag($language['backend.import.feed.categ.list'][$videoResult['snippet']['categoryId']])); $dbc = $db->execute(sprintf("SELECT `ct_id`, `ct_name` FROM `db_categories` WHERE `ct_type`='video' AND `ct_active`='1' AND `ct_name` LIKE '%s' OR `ct_descr` LIKE '%s';", '%' . $category . '%', '%' . $category . '%')); $db_uid = $class_filter->clr_str($_POST['assign_username']); $date = new DateTime('1970-01-01'); $date->add(new DateInterval($videoResult['contentDetails']['duration'])); $duration = $date->format('H:i:s'); $d = explode(':', $duration); $db_duration = ($d[0] * 60 * 60) + ($d[1] * 60) + ($d[2]); $db_categ_id = intval($dbc->fields['ct_id']); $db_categ_name = $dbc->fields['ct_name']; $db_title = $videoResult['snippet']['title']; $db_tags = self::yt_tags($class_filter->clr_str($db_title)); $db_desc = $videoResult['snippet']['description']; $db_rkey = $_id; $tmb = array( 0 => "http://i.ytimg.com/vi/" . $db_rkey . "/maxresdefault.jpg", 1 => "http://i.ytimg.com/vi/" . $db_rkey . "/mqdefault.jpg", 2 => "http://i.ytimg.com/vi/" . $db_rkey . "/mqdefault.jpg", 3 => "http://i.ytimg.com/vi/" . $db_rkey . "/mqdefault.jpg", ); $html = !$error ? self::saveCheck($db_rkey, array( "title" => $db_title, "description" => $db_desc, "tags" => $db_tags, "category" => ((isset($_POST['assign_category_feed']) and $_POST['assign_category_feed'] != '') ? intval($_POST['assign_category_feed']) : ((isset($_POST['assign_category_channel']) and $_POST['assign_category_channel'] != '') ? intval($_POST['assign_category_channel']) : ($db_categ_id > 0 ? $db_categ_id : self::getOther()))), "duration" => $db_duration, "key" => $db_rkey, "src" => 'youtube', "url" => 'http://www.youtube.com/watch?v=' . $db_rkey, "tmb" => $tmb)) : null; $html .= VGenerate::simpleDivWrap('row embed-title', '', $db_title); $html .= VGenerate::simpleDivWrap('row embed-description', '', VUserinfo::truncateString($db_desc, 200)); $html .= VGenerate::simpleDivWrap('row embed-category greyed-out', '', $language['backend.import.category'] . $db_categ_name); } return $html; } public function getAndPrintStandardFeeds($m) { global $class_filter, $cfg; $DEVELOPER_KEY = $cfg['youtube_api_key']; $token = (isset($_GET['token']) and $_GET['token'] != "undefined") ? $class_filter->clr_str($_GET['token']) : false; switch ($m) { case "m1": //video feeds $feed_region = $class_filter->clr_str($_POST['feed_region']); $feed_category = $class_filter->clr_str($_POST['feed_categ']); $feed_def = $class_filter->clr_str($_POST['feed_def']); $feed_dim = $class_filter->clr_str($_POST['feed_dim']); $feed_dur = $class_filter->clr_str($_POST['feed_dur']); $feed_emb = $class_filter->clr_str($_POST['feed_emb']); $feed_lic = $class_filter->clr_str($_POST['feed_lic']); $feed_syn = $class_filter->clr_str($_POST['feed_syn']); $feed_type = $class_filter->clr_str($_POST['feed_type']); $feed_search = str_replace(' ', '+', $class_filter->clr_str($_POST['be_search_term'])); $region = $feed_region != '' ? '&regionCode=' . $feed_region : null; $category = $feed_category != '' ? '&videoCategoryId=' . $feed_category : null; $def = $feed_def != '' ? '&videoDefinition=' . $feed_def : null; $dim = $feed_dim != '' ? '&videoDimension=' . $feed_dim : null; $dur = $feed_dur != '' ? '&videoDuration=' . $feed_dur : null; $emb = $feed_emb != '' ? '&videoEmbeddable=' . $feed_emb : null; $lic = $feed_lic != '' ? '&videoLicense=' . $feed_lic : null; $syn = $feed_syn != '' ? '&videoSyndicated=' . $feed_syn : null; $type = $feed_type != '' ? '&videoType=' . $feed_type : null; $search = $feed_search != '' ? '&q=' . $feed_search : null; $page = $token ? '&pageToken=' . $token : null; $max = (int) $_POST['yt_video_results']; $YOUTUBE_FEED = 'https://www.googleapis.com/youtube/v3/search?part=snippet' . $search . '&maxResults=' . $max . $region . $def . $dim . $dur . $emb . $lic . $syn . $type . '&type=video' . $category . '&key=' . $DEVELOPER_KEY . $page; break; case "m2": //channel feeds $username_get = $class_filter->clr_str(trim($_POST['feed_channel_yt'])); $ch_id = self::getYTchannelID($username_get); $search = '&channelId=' . ($ch_id != '' ? $ch_id : $username_get); $page = $token ? '&pageToken=' . $token : null; $max = (int) $_POST['yt_channel_results']; $YOUTUBE_FEED = 'https://www.googleapis.com/youtube/v3/search?part=snippet' . $search . '&maxResults=' . $max . '&type=video&order=date&key=' . $DEVELOPER_KEY . $page; break; } return self::getAndPrintVideoFeed($YOUTUBE_FEED, $m); } /* end youtube video feeds functions */ public function getYTchannelID($username) { global $cfg; $api_url = 'https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername=' . $username . '&key=' . $cfg['youtube_api_key']; $result = json_decode(VServer::curl_tt($api_url)); return $result->items[0]->id; } /* generate various select lists */ public function selectList($name, $for, $show_blank) { global $db, $language; $_ht = ''; return $_ht; } /* get category list */ public function getCategoryList() { require_once 'f_core/config.backend.php'; global $db, $cfg; $c = array(); $_section = (strstr($_SERVER['REQUEST_URI'], $backend_access_url) == true) ? 'backend' : 'frontend'; $res = $db->execute("SELECT `ct_name`, `ct_lang` FROM `db_categories` WHERE `ct_type`='video' AND `ct_active`='1';"); if ($res->fields['ct_name']) { while (!$res->EOF) { if ($res->fields['ct_lang'] != '') { $cl = unserialize($res->fields['ct_lang']); $ln = ((isset($_SESSION['be_lang']) and $_section == 'backend') ? $_SESSION['be_lang'] : ((isset($_SESSION['fe_lang']) and $_section == 'frontend') ? $_SESSION['fe_lang'] : 'en_US')); $c[] = $ln != 'en_US' ? $cl[$ln] : $res->fields['ct_name']; } else { $c[] = $res->fields['ct_name']; } $res->MoveNext(); } } return $c; } /* get username list */ public function getUsernameList() { global $db; $u = array(); $res = $db->execute("SELECT `usr_key`, `usr_user` FROM `db_accountuser` WHERE `usr_status`='1' ORDER BY `usr_user`;"); if ($res->fields['usr_key']) { return $res; } } /* generate html username select list */ public function username_selectList($name) { $input_name = $name ? 'assign_username_' . $name : 'assign_username'; $input_id = str_replace('_', '-', $input_name); $html = ''; $html .= ''; return $html; } }