diff --git a/objects/Object.php b/objects/Object.php
index 6c9956805..feb17f054 100644
--- a/objects/Object.php
+++ b/objects/Object.php
@@ -1,678 +1,679 @@
load($id);
}
}
protected function load($id) {
$row = self::getFromDb($id);
if (empty($row)) {
return false;
}
foreach ($row as $key => $value) {
$this->$key = $value;
}
return true;
}
public static function getNowFromDB() {
global $global;
$sql = "SELECT NOW() as my_date_field";
$res = sqlDAL::readSql($sql);
$data = sqlDAL::fetchAssoc($res);
sqlDAL::close($res);
if ($res) {
$row = $data;
} else {
$row = false;
}
return $row;
}
public static function setTimeZone() {
global $advancedCustom, $timezoneOriginal;
if(!isset($timezoneOriginal)){
$timezoneOriginal = date_default_timezone_get();
}
$row = self::getNowFromDB();
$dt = new DateTime($row['my_date_field']);
if(!empty($_COOKIE['timezone']) && $_COOKIE['timezone'] !== 'undefined'){
$timezone = $_COOKIE['timezone'];
}else{
$timeZOnesOptions = object_to_array($advancedCustom->timeZone->type);
$timezone = $timeZOnesOptions[$advancedCustom->timeZone->value];
}
if (empty($timezone) || $timezone == 'undefined') {
return false;
}
try {
$objDate = new DateTimeZone($timezone);
if (is_object($objDate)) {
$dt->setTimezone($objDate);
date_default_timezone_set($timezone);
return $dt;
}
return false;
} catch (Exception $exc) {
_error_log("setTimeZone: " . $exc->getMessage(), AVideoLog::$ERROR);
return false;
}
}
protected static function getFromDb($id) {
global $global;
$id = intval($id);
$sql = "SELECT * FROM " . static::getTableName() . " WHERE id = ? LIMIT 1";
// I had to add this because the about from customize plugin was not loading on the about page http://127.0.0.1/AVideo/about
$res = sqlDAL::readSql($sql, "i", array($id), true);
$data = sqlDAL::fetchAssoc($res);
sqlDAL::close($res);
if ($res) {
$row = $data;
} else {
$row = false;
}
return $row;
}
public static function getAll() {
global $global;
if (!static::isTableInstalled()) {
return false;
}
$sql = "SELECT * FROM " . static::getTableName() . " WHERE 1=1 ";
$sql .= self::getSqlFromPost();
$res = sqlDAL::readSql($sql);
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$rows = array();
if ($res != false) {
foreach ($fullData as $row) {
$rows[] = $row;
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return $rows;
}
public static function getAllActive() {
global $global;
if (!static::isTableInstalled()) {
return false;
}
$sql = "SELECT * FROM " . static::getTableName() . " WHERE status='a' ";
$sql .= self::getSqlFromPost();
$res = sqlDAL::readSql($sql);
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$rows = array();
if ($res != false) {
foreach ($fullData as $row) {
$rows[] = $row;
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return $rows;
}
public static function getTotal() {
//will receive
//current=1&rowCount=10&sort[sender]=asc&searchPhrase=
global $global;
if (!static::isTableInstalled()) {
return 0;
}
$sql = "SELECT id FROM " . static::getTableName() . " WHERE 1=1 ";
$sql .= self::getSqlSearchFromPost();
$res = sqlDAL::readSql($sql);
$countRow = sqlDAL::num_rows($res);
sqlDAL::close($res);
return $countRow;
}
public static function getSqlFromPost($keyPrefix = "") {
global $global;
$sql = self::getSqlSearchFromPost();
if (empty($_POST['sort']) && !empty($_GET['order'][0]['dir'])) {
$index = intval($_GET['order'][0]['column']);
$_GET['columns'][$index]['data'];
$_POST['sort'][$_GET['columns'][$index]['data']] = $_GET['order'][0]['dir'];
}
// add a security here
if (!empty($_POST['sort'])) {
foreach ($_POST['sort'] as $key => $value) {
$_POST['sort'][xss_esc($key)] = xss_esc($value);
}
}
if (!empty($_POST['sort'])) {
$orderBy = array();
foreach ($_POST['sort'] as $key => $value) {
$key = $global['mysqli']->real_escape_string($key);
//$value = $global['mysqli']->real_escape_string($value);
$direction = "ASC";
if (strtoupper($value) === "DESC") {
$direction = "DESC";
}
$key = preg_replace("/[^A-Za-z0-9._ ]/", '', $key);
$orderBy[] = " {$keyPrefix}{$key} {$value} ";
}
$sql .= " ORDER BY " . implode(",", $orderBy);
}
$sql .= self::getSqlLimit();
return $sql;
}
public static function getSqlLimit() {
global $global;
$sql = "";
if (empty($_POST['rowCount']) && !empty($_GET['length'])) {
$_POST['rowCount'] = intval($_GET['length']);
}
if (empty($_POST['current']) && !empty($_GET['start'])) {
$_POST['current'] = ($_GET['start'] / $_GET['length']) + 1;
} elseif (empty($_POST['current']) && isset($_GET['start'])) {
$_POST['current'] = 1;
}
$_POST['current'] = getCurrentPage();
$_POST['rowCount'] = getRowCount();
if (!empty($_POST['rowCount']) && !empty($_POST['current']) && $_POST['rowCount'] > 0) {
$_POST['rowCount'] = intval($_POST['rowCount']);
$_POST['current'] = intval($_POST['current']);
$current = ($_POST['current'] - 1) * $_POST['rowCount'];
$current = $current < 0 ? 0 : $current;
$sql .= " LIMIT $current, {$_POST['rowCount']} ";
} else {
$_POST['current'] = 0;
$_POST['rowCount'] = 0;
$sql .= " LIMIT 1000 ";
}
return $sql;
}
public static function getSqlSearchFromPost() {
$sql = "";
if (!empty($_POST['searchPhrase'])) {
$_GET['q'] = $_POST['searchPhrase'];
} elseif (!empty($_GET['search']['value'])) {
$_GET['q'] = $_GET['search']['value'];
}
if (!empty($_GET['q'])) {
global $global;
$search = $global['mysqli']->real_escape_string(xss_esc($_GET['q']));
$like = array();
$searchFields = static::getSearchFieldsNames();
foreach ($searchFields as $value) {
$like[] = " {$value} LIKE '%{$search}%' ";
// for accent insensitive
$like[] = " CONVERT(CAST({$value} as BINARY) USING utf8) LIKE '%{$search}%' ";
}
if (!empty($like)) {
$sql .= " AND (" . implode(" OR ", $like) . ")";
} else {
$sql .= " AND 1=1 ";
}
}
return $sql;
}
public function save() {
if (!$this->tableExists()) {
_error_log("Save error, table " . static::getTableName() . " does not exists", AVideoLog::$ERROR);
return false;
}
global $global;
$fieldsName = $this->getAllFields();
if (!empty($this->id)) {
$sql = "UPDATE " . static::getTableName() . " SET ";
$fields = array();
foreach ($fieldsName as $value) {
if (strtolower($value) == 'created') {
// do nothing
} elseif (strtolower($value) == 'modified') {
$fields[] = " {$value} = now() ";
} elseif (is_numeric($this->$value)) {
$fields[] = " `{$value}` = {$this->$value} ";
} elseif (strtolower($this->$value) == 'null') {
$fields[] = " `{$value}` = NULL ";
} else {
$fields[] = " `{$value}` = '{$this->$value}' ";
}
}
$sql .= implode(", ", $fields);
$sql .= " WHERE id = {$this->id}";
} else {
$sql = "INSERT INTO " . static::getTableName() . " ( ";
$sql .= "`" . implode("`,`", $fieldsName) . "` )";
$fields = array();
foreach ($fieldsName as $value) {
if (strtolower($value) == 'created' || strtolower($value) == 'modified') {
$fields[] = " now() ";
} elseif (!isset($this->$value) || strtolower($this->$value) == 'null') {
$fields[] = " NULL ";
} else {
$fields[] = " '{$this->$value}' ";
}
}
$sql .= " VALUES (" . implode(", ", $fields) . ")";
}
//if(static::getTableName() == 'subscriptions') echo $sql;
$insert_row = sqlDAL::writeSql($sql);
if ($insert_row) {
if (empty($this->id)) {
$id = $global['mysqli']->insert_id;
} else {
$id = $this->id;
}
return $id;
} else {
_error_log("ObjectYPT::save Error on save: " . $sql . ' Error : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error, AVideoLog::$ERROR);
return false;
}
}
private function getAllFields() {
global $global, $mysqlDatabase;
$sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = '" . static::getTableName() . "'";
$res = sqlDAL::readSql($sql, "s", array($mysqlDatabase));
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$rows = array();
if ($res != false) {
foreach ($fullData as $row) {
$rows[] = $row["COLUMN_NAME"];
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return $rows;
}
public function delete() {
global $global;
if (!empty($this->id)) {
$sql = "DELETE FROM " . static::getTableName() . " ";
$sql .= " WHERE id = ?";
$global['lastQuery'] = $sql;
//_error_log("Delete Query: ".$sql);
return sqlDAL::writeSql($sql, "i", array($this->id));
}
_error_log("Id for table " . static::getTableName() . " not defined for deletion", AVideoLog::$ERROR);
return false;
}
public static function setCache($name, $value) {
$cachefile = self::getCacheFileName($name);
make_path($cachefile);
$content = _json_encode($value);
if(empty($content)){
$content = $value;
}
$bytes = @file_put_contents($cachefile, $content);
self::setSessionCache($name, $value);
return array('bytes' => $bytes, 'cachefile' => $cachefile);
}
public static function cleanCacheName($name) {
$name = str_replace(array('/', '\\'), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $name);
$name = preg_replace('/[!#$&\'()*+,:;=?@[\\]% -]+/', '_', trim(strtolower(cleanString($name))));
$name = preg_replace('/\/{2,}/', '/', trim(strtolower(cleanString($name))));
if (function_exists('mb_ereg_replace')) {
$name = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).\\/\\\])", '', $name);
// Remove any runs of periods (thanks falstro!)
$name = mb_ereg_replace("([\.]{2,})", '', $name);
}
return preg_replace('/[\x00-\x1F\x7F]/u', '', $name);
}
/**
*
* @param type $name
* @param type $lifetime, if is = 0 it is unlimited
* @return type
*/
public static function getCache($name, $lifetime = 60, $ignoreSessionCache = false) {
if (isCommandLineInterface()) {
return false;
}
if(isBot()){
$lifetime = 0;
}
global $getCachesProcessed, $_getCache;
if (empty($_getCache)) {
$_getCache = array();
}
if (empty($getCachesProcessed)) {
$getCachesProcessed = array();
}
$cachefile = self::getCacheFileName($name);
if (!empty($_getCache[$name])) {
return $_getCache[$name];
}
if (empty($getCachesProcessed[$name])) {
$getCachesProcessed[$name] = 0;
}
$getCachesProcessed[$name]++;
if (!empty($_GET['lifetime'])) {
$lifetime = intval($_GET['lifetime']);
}
if (empty($ignoreSessionCache)) {
$session = self::getSessionCache($name, $lifetime);
if (!empty($session)) {
$_getCache[$name] = $session;
return $session;
}
}
/*
if (preg_match('/firstpage/i', $cachefile)) {
echo var_dump($cachefile) . PHP_EOL;
$trace = debug_backtrace();
$backtrace_lite = array();
foreach ($trace as $call) {
echo $call['function'] . " " . $call['file'] . " line " . $call['line'] . PHP_EOL;
}exit;
}
/**
*/
if (file_exists($cachefile) && (empty($lifetime) || time() - $lifetime <= filemtime($cachefile))) {
//if(preg_match('/getStats/', $cachefile)){echo $cachefile,'
';}
$c = @url_get_contents($cachefile);
$json = _json_decode($c);
if(empty($json) && !is_object($json) && !is_array($json)){
$json = $c;
}
self::setSessionCache($name, $json);
$_getCache[$name] = $json;
return $json;
} elseif (file_exists($cachefile)) {
self::deleteCache($name);
}
//_error_log("YPTObject::getCache log error [{$name}] $cachefile filemtime = ".filemtime($cachefile));
return null;
}
public static function deleteCache($name) {
+ if(empty($name)){return false;}
global $__getAVideoCache;
unset($__getAVideoCache);
$cachefile = self::getCacheFileName($name);
@unlink($cachefile);
self::deleteSessionCache($name);
ObjectYPT::deleteCacheFromPattern($name);
}
static function deleteCachePattern($pattern) {
global $__getAVideoCache;
unset($__getAVideoCache);
$tmpDir = self::getCacheDir();
$array = _glob($tmpDir, $pattern);
foreach ($array as $value) {
_error_log("Object::deleteCachePattern file [{$value}]");
@unlink($value);
}
_session_start();
foreach ($_SESSION['user']['sessionCache'] as $key => $value) {
if (preg_match($pattern, $key)) {
_error_log("Object::deleteCachePattern session [{$key}]");
$_SESSION['user']['sessionCache'][$key] = null;
unset($_SESSION['user']['sessionCache'][$key]);
}
}
}
public static function deleteALLCache() {
global $__getAVideoCache;
unset($__getAVideoCache);
$tmpDir = self::getCacheDir();
rrmdir($tmpDir);
self::deleteAllSessionCache();
self::setLastDeleteALLCacheTime();
}
public static function getCacheDir($filename = '') {
global $_getCacheDir, $global;
if (!isset($_getCacheDir)) {
$_getCacheDir = array();
}
if (!empty($_getCacheDir[$filename])) {
return $_getCacheDir[$filename];
}
$tmpDir = getTmpDir();
$tmpDir = rtrim($tmpDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$tmpDir .= "YPTObjectCache" . DIRECTORY_SEPARATOR;
$filename = self::cleanCacheName($filename);
if (!empty($filename)) {
$tmpDir .= $filename . DIRECTORY_SEPARATOR;
$domain = getDomain();
$tmpDir .= $domain . DIRECTORY_SEPARATOR;
// make sure you separete http and https cache
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
$tmpDir .= $protocol . DIRECTORY_SEPARATOR;
if (class_exists("User_Location")) {
$loc = User_Location::getThisUserLocation();
if (!empty($loc) && !empty($loc['country_code'])) {
$tmpDir .= $loc['country_code'] . DIRECTORY_SEPARATOR;
}
}
if (User::isLogged()) {
if(User::isAdmin()){
$tmpDir .= 'admin_'.md5("admin".$global['salt']).DIRECTORY_SEPARATOR;
}else{
$tmpDir .= 'user_'.md5("user".$global['salt']).DIRECTORY_SEPARATOR;
}
}else{
$tmpDir .= 'notlogged_'.md5("notlogged".$global['salt']).DIRECTORY_SEPARATOR;
}
}
$tmpDir = fixPath($tmpDir);
make_path($tmpDir);
if (!file_exists($tmpDir . "index.html") && is_writable($tmpDir)) {// to avoid search into the directory
file_put_contents($tmpDir . "index.html", time());
}
$_getCacheDir[$filename] = $tmpDir;
return $tmpDir;
}
public static function getCacheFileName($name) {
global $global;
$tmpDir = self::getCacheDir($name);
$uniqueHash = md5($name . $global['salt']); // add salt for security reasons
return $tmpDir . $uniqueHash . '.cache';
}
public static function deleteCacheFromPattern($name) {
$tmpDir = getTmpDir();
$name = self::cleanCacheName($name);
$ignoreLocationDirectoryName = (strpos($name, DIRECTORY_SEPARATOR) !== false);
$filePattern = $tmpDir . DIRECTORY_SEPARATOR . $name;
foreach (glob("{$filePattern}*") as $filename) {
unlink($filename);
}
self::deleteSessionCache($name);
}
/**
* Make sure you start the session before any output
* @param type $name
* @param type $value
*/
public static function setSessionCache($name, $value) {
$name = self::cleanCacheName($name);
_session_start();
$_SESSION['user']['sessionCache'][$name]['value'] = json_encode($value);
$_SESSION['user']['sessionCache'][$name]['time'] = time();
if (empty($_SESSION['user']['sessionCache']['time'])) {
$_SESSION['user']['sessionCache']['time'] = time();
}
}
/**
*
* @param type $name
* @param type $lifetime, if is = 0 it is unlimited
* @return type
*/
public static function getSessionCache($name, $lifetime = 60) {
$name = self::cleanCacheName($name);
if (!empty($_GET['lifetime'])) {
$lifetime = intval($_GET['lifetime']);
}
if (!empty($_SESSION['user']['sessionCache'][$name])) {
if ((empty($lifetime) || time() - $lifetime <= $_SESSION['user']['sessionCache'][$name]['time'])) {
$c = $_SESSION['user']['sessionCache'][$name]['value'];
$json = _json_decode($c);
if(is_string($json) && strtolower($json) === 'false'){
$json = false;
}
return $json;
}
_session_start();
unset($_SESSION['user']['sessionCache'][$name]);
}
return null;
}
public static function clearSessionCache() {
unset($_SESSION['user']['sessionCache']);
}
private static function getLastDeleteALLCacheTimeFile() {
$tmpDir = getTmpDir();
$tmpDir = rtrim($tmpDir, DIRECTORY_SEPARATOR) . "/";
$tmpDir .= "lastDeleteALLCacheTime.cache";
return $tmpDir;
}
public static function setLastDeleteALLCacheTime() {
$file = self::getLastDeleteALLCacheTimeFile();
//_error_log("ObjectYPT::setLastDeleteALLCacheTime {$file}");
return file_put_contents($file, time());
}
public static function getLastDeleteALLCacheTime() {
global $getLastDeleteALLCacheTime;
if (empty($getLastDeleteALLCacheTime)) {
$getLastDeleteALLCacheTime = (int) @file_get_contents(self::getLastDeleteALLCacheTimeFile(), time());
}
return $getLastDeleteALLCacheTime;
}
public static function checkSessionCacheBasedOnLastDeleteALLCacheTime() {
/*
var_dump(
$session_var['time'],
self::getLastDeleteALLCacheTime(),
humanTiming($session_var['time']),
humanTiming(self::getLastDeleteALLCacheTime()),
$session_var['time'] <= self::getLastDeleteALLCacheTime());
*
*/
if (empty($_SESSION['user']['sessionCache']['time']) || $_SESSION['user']['sessionCache']['time'] <= self::getLastDeleteALLCacheTime()) {
self::deleteAllSessionCache();
return false;
}
return true;
}
public static function deleteSessionCache($name) {
$name = self::cleanCacheName($name);
_session_start();
$_SESSION['user']['sessionCache'][$name] = null;
unset($_SESSION['user']['sessionCache'][$name]);
}
public static function deleteAllSessionCache() {
_session_start();
unset($_SESSION['user']['sessionCache']);
}
public function tableExists() {
return self::isTableInstalled();
}
public static function isTableInstalled($tableName = "") {
global $global, $tableExists;
if (empty($tableName)) {
$tableName = static::getTableName();
}
if (empty($tableName)) {
return false;
}
if (!isset($tableExists[$tableName])) {
$sql = "SHOW TABLES LIKE '" . $tableName . "'";
//_error_log("isTableInstalled: ({$sql})");
$res = sqlDAL::readSql($sql);
$result = sqlDal::num_rows($res);
sqlDAL::close($res);
$tableExists[$tableName] = !empty($result);
}
return $tableExists[$tableName];
}
static function clientTimezoneToDatabaseTimezone($clientDate){
if(!preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $clientDate)){
return $clientDate;
}
global $timezoneOriginal;
$currentTimezone = date_default_timezone_get();
$time = strtotime($clientDate);
date_default_timezone_set($timezoneOriginal);
$dbDate = date('Y-m-d H:i:s', $time);
date_default_timezone_set($currentTimezone);
return $dbDate;
}
}
//abstract class Object extends ObjectYPT{};
diff --git a/plugin/AVideoPlugin.php b/plugin/AVideoPlugin.php
index 24394e64a..48eafb281 100644
--- a/plugin/AVideoPlugin.php
+++ b/plugin/AVideoPlugin.php
@@ -1,2067 +1,2080 @@
$timeLimit) {
_error_log("The plugin [{$pluginName}] takes {$total_time} seconds to complete. URL: " . getSelfURI() . " IP: " . getRealIpAddr(), AVideoLog::$WARNING);
}
}
public static function addRoutes() {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->addRoutes();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return false;
}
public static function addView($videos_id, $total) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->addView($videos_id, $total);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return false;
}
public static function getHeadCode() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getHeadCode();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function getChartTabs() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
if (method_exists($p, 'getChartTabs')) {
$str .= $p->getChartTabs();
} else {
$checkStr = $p->getChartContent();
if (!empty($checkStr)) {
$str .= '
';
}
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function getChartContent() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$checkStr = $p->getChartContent();
if (!empty($checkStr)) {
$str .= '';
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function getGallerySection() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getGallerySection();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function getHelpToc() {
$plugins = Plugin::getAllEnabled();
$str = "" . __("Table of content") . "
";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$t = $p->getHelp();
if (!empty($t)) {
$str .= "- " . __($value['name']) . "
";
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str . "
";
}
public static function getHelp() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$t = $p->getHelp();
$str .= $t;
if (!empty($t)) {
$str .= "
";
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function getFooterCode() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= PHP_EOL . "" . PHP_EOL;
$str .= $p->getFooterCode();
$str .= PHP_EOL . "" . PHP_EOL;
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function getJSFiles() {
$plugins = Plugin::getAllEnabled();
$allFiles = array();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$js = $p->getJSFiles();
if (is_array($js)) {
$allFiles = array_merge($allFiles, $js);
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $allFiles;
}
public static function getCSSFiles() {
$plugins = Plugin::getAllEnabled();
$allFiles = array();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$allFiles = array_merge($allFiles, $p->getCSSFiles());
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $allFiles;
}
public static function getHTMLBody() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getHTMLBody();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function getHTMLMenuLeft() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getHTMLMenuLeft();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function getHTMLMenuRight() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getHTMLMenuRight();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function getFirstPage() {
return static::getEnabledFirstPage();
}
public static function getEnabledFirstPage() {
$plugins = Plugin::getAllEnabled();
$firstPage = false;
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (!is_object($p)) {
continue;
}
$fp = $p->getFirstPage();
if (!empty($fp)) {
$firstPage = $fp;
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $firstPage;
}
static function loadPlugin($name, $forceReload = false) {
global $global, $pluginIsLoaded;
if (empty($pluginIsLoaded)) {
$pluginIsLoaded = array();
}
$loadPluginFile = "{$global['systemRootPath']}plugin/{$name}/{$name}.php";
// need to add dechex because some times it return an negative value and make it fails on javascript playlists
if (!isset($pluginIsLoaded[$name]) && empty($forceReload)) {
$pluginIsLoaded[$name] = false;
if (file_exists($loadPluginFile)) {
require_once $loadPluginFile;
if (class_exists($name)) {
$code = "\$p = new {$name}();";
eval($code);
if (is_object($p)) {
$pluginIsLoaded[$name] = $p;
} else {
_error_log("[loadPlugin] eval failed for plugin ($name) code ($code) code result ($codeResult) included file $loadPluginFile", AVideoLog::$ERROR);
}
}
}
}
return $pluginIsLoaded[$name];
}
static function loadPluginIfEnabled($name) {
$p = static::loadPlugin($name);
if ($p) {
$uuid = $p->getUUID();
if (static::isEnabled($uuid)) {
return $p;
}
}
return false;
}
static function isPluginTablesInstalled($name, $installIt = false) {
global $global, $isPluginTablesInstalled;
$name = self::fixName($name);
$installSQLFile = "{$global['systemRootPath']}plugin/{$name}/install/install.sql";
if (isset($isPluginTablesInstalled[$installSQLFile])) {
return $isPluginTablesInstalled[$installSQLFile];
}
//_error_log("isPluginTablesInstalled: Check for {$installSQLFile}");
if (!file_exists($installSQLFile)) {
$isPluginTablesInstalled[$installSQLFile] = true;
return $isPluginTablesInstalled[$installSQLFile];
}
$lines = file($installSQLFile);
foreach ($lines as $line) {
$pattern1 = "/CREATE TABLE IF NOT EXISTS `?([a-z0-9_]+)[` (]?/i";
$pattern2 = "/CREATE TABLE[^`]+`?([a-z0-9_]+)[` (]?/i";
if (preg_match($pattern1, $line, $matches)) {
if (!empty($matches[1])) {
//_error_log("isPluginTablesInstalled: Found ({$matches[1]})");
if (!ObjectYPT::isTableInstalled($matches[1])) {
//_error_log("isPluginTablesInstalled: ({$matches[1]}) is NOT installed");
if ($installIt) {
sqlDAL::executeFile($installSQLFile);
return self::isPluginTablesInstalled($name);
} else {
//_error_log("isPluginTablesInstalled: You need to install table {$matches[1]} for the plugin ({$name})", AVideoLog::$ERROR);
$isPluginTablesInstalled[$installSQLFile] = false;
return $isPluginTablesInstalled[$installSQLFile];
}
} else {
//_error_log("isPluginTablesInstalled: ({$matches[1]}) is installed");
}
}
} else if (preg_match($pattern2, $line, $matches)) {
if (!empty($matches[1])) {
if (!ObjectYPT::isTableInstalled($matches[1])) {
_error_log("You need to install table {$matches[1]} for the plugin ({$name})", AVideoLog::$ERROR);
$isPluginTablesInstalled[$installSQLFile] = false;
return $isPluginTablesInstalled[$installSQLFile];
}
}
}
}
$isPluginTablesInstalled[$installSQLFile] = true;
return $isPluginTablesInstalled[$installSQLFile];
}
static function getObjectData($name) {
return self::getDataObject($name);
}
static function getDataObject($name) {
global $pluginGetDataObject;
if (!isset($pluginGetDataObject)) {
$pluginGetDataObject = array();
}
if (!empty($pluginGetDataObject[$name])) {
return $pluginGetDataObject[$name];
}
$p = static::loadPlugin($name);
if ($p) {
$pluginGetDataObject[$name] = $p->getDataObject();
return $pluginGetDataObject[$name];
}
return false;
}
static function getObjectDataIfEnabled($name) {
return self::getDataObjectIfEnabled($name);
}
static function getDataObjectIfEnabled($name) {
global $_getDataObjectIfEnabled;
if (!isset($_getDataObjectIfEnabled)) {
$_getDataObjectIfEnabled = array();
}
if (isset($_getDataObjectIfEnabled[$name])) {
return $_getDataObjectIfEnabled[$name];
}
$p = static::loadPlugin($name);
if ($p) {
$uuid = $p->getUUID();
if (static::isEnabled($uuid)) {
$_getDataObjectIfEnabled[$name] = static::getObjectData($name);
return $_getDataObjectIfEnabled[$name];
}
}
$_getDataObjectIfEnabled[$name] = false;
return $_getDataObjectIfEnabled[$name];
}
static function xsendfilePreVideoPlay() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->xsendfilePreVideoPlay();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
static function getVideosManagerListButton() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getVideosManagerListButton();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
static function getVideosManagerListButtonTitle() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getVideosManagerListButtonTitle();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
static function getUsersManagerListButton() {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getUsersManagerListButton();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
static function getWatchActionButton($videos_id) {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getWatchActionButton($videos_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
static function getNetflixActionButton($videos_id) {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getNetflixActionButton($videos_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
static function getGalleryActionButton($videos_id) {
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getGalleryActionButton($videos_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function isEnabled($uuid) {
return !empty(Plugin::getEnabled($uuid));
}
public static function exists($name) {
global $global;
$name = self::fixName($name);
$filename = "{$global['systemRootPath']}plugin/{$name}/{$name}.php";
return file_exists($filename);
}
static function isEnabledByName($name, $minVersion = '') {
global $isPluginEnabledByName;
if (empty($isPluginEnabledByName)) {
$isPluginEnabledByName = array();
}
$index = "{$name}_{$minVersion}";
if (!isset($isPluginEnabledByName[$index])) {
$p = static::loadPluginIfEnabled($name);
$isPluginEnabledByName[$index] = false;
if ($minVersion) {
if(!empty($p)){
if(version_compare($p->getPluginVersion(), $minVersion, '>=')){
$isPluginEnabledByName[$index] = true;
}else{
_error_log("You need to update your plugin {$name} to version {$minVersion} or greater", AVideoLog::$WARNING);
}
}
} else {
$isPluginEnabledByName[$index] = !empty($p);
}
}
return $isPluginEnabledByName[$index];
}
static function getLogin() {
$plugins = Plugin::getAllEnabled();
$logins = array();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$l = $p->getLogin();
if (is_string($l) && file_exists($l)) { // it is a login form
$logins[] = $l;
} else if (!empty($l->type)) { // it is a hybridauth
$logins[] = array('parameters' => $l, 'loginObject' => $p);
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $logins;
}
public static function getStart() {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
//self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->getStart();
}
//self::YPTend("{$value['dirName']}::".__FUNCTION__);
}
}
public static function getEnd() {
$plugins = Plugin::getAllEnabled();
usort($plugins, function($a, $b) {
if ($a['name'] == 'Cache') {
return 1;
} else if ($b['name'] == 'Cache') {
return -1;
}
return 0;
});
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
//_error_log("{$value['dirName']}::" . __FUNCTION__);
$p->getEnd();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function afterVideoJS() {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->afterVideoJS();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function afterNewVideo($videos_id) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->afterNewVideo($videos_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function afterDonation($from_users_id, $how_much, $videos_id, $users_id) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->afterDonation($from_users_id, $how_much, $videos_id, $users_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function afterNewComment($comments_id) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->afterNewComment($comments_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function afterNewResponse($comments_id) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->afterNewResponse($comments_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function getChannelButton() {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->getChannelButton();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function getVideoManagerButton() {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->getVideoManagerButton();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function getLivePanel() {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->getLivePanel();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function getModeYouTube($videos_id) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->getModeYouTube($videos_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public function getModeLive($key) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->getModeLive($key);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public function getModeLiveLink($liveLink_id) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->getModeLiveLink($liveLink_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function getModeYouTubeLive($users_id) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->getModeYouTubeLive($users_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function getEmbed($videos_id) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->getEmbed($videos_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function getChannel($user_id, $user) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->getChannel($user_id, $user);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function getLiveApplicationArray() {
$plugins = Plugin::getAllEnabled();
$array = array();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$appArray = $p->getLiveApplicationArray();
$array = array_merge($array, $appArray);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $array;
}
public static function getPlayListButtons($playlist_id = "") {
if (empty($playlist_id))
return "";
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getPlayListButtons($playlist_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function getMyAccount($users_id = "") {
if (empty($users_id))
return "";
$plugins = Plugin::getAllEnabled();
$str = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$str .= $p->getMyAccount($users_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $str;
}
public static function getPluginUserOptions() {
$plugins = Plugin::getAllEnabled();
$userOptions = array();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$userOptions = array_merge($userOptions, $p->getUserOptions());
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $userOptions;
}
/**
*
* @return type return a list of IDs of the user groups
*/
public static function getDynamicUserGroupsId($users_id) {
$plugins = Plugin::getAllEnabled();
$array = array();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$appArray = $p->getDynamicUserGroupsId($users_id);
$array = array_merge($array, $appArray);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $array;
}
public static function getDynamicUsersId($users_groups_id) {
$plugins = Plugin::getAllEnabled();
$array = array();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$appArray = $p->getDynamicUsersId($users_groups_id);
$array = array_merge($array, $appArray);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $array;
}
public static function getUserOptions() {
$userOptions = static::getPluginUserOptions();
$str = "";
foreach ($userOptions as $userOption => $id) {
$str .= "
" . __($userOption) .
"
";
}
return $str;
}
public static function addUserBtnJS() {
$userOptions = static::getPluginUserOptions();
$userOptions = array();
$js = "";
foreach ($userOptions as $userOption => $id) {
$js .= " $('#$id').prop('checked', false);\n";
}
return $js;
}
public static function updateUserFormJS() {
$userOptions = static::getPluginUserOptions();
$js = "";
foreach ($userOptions as $userOption => $id) {
$js .= " \"$id\": $('#$id').is(':checked'),\n";
}
return $js;
}
public static function loadUsersFormJS() {
$userOptions = static::getPluginUserOptions();
$js = "";
foreach ($userOptions as $userOption => $id) {
$js .= " $('#$id').prop('checked', (row.$id == \"1\" ? true : false));
\n";
}
return $js;
}
public static function navBarButtons() {
$plugins = Plugin::getAllEnabled();
$userOptions = array();
$navBarButtons = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$navBarButtons .= $p->navBarButtons();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $navBarButtons;
}
public static function navBarProfileButtons() {
$plugins = Plugin::getAllEnabled();
$userOptions = array();
$navBarButtons = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$navBarButtons .= $p->navBarProfileButtons();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $navBarButtons;
}
public static function navBar() {
$plugins = Plugin::getAllEnabled();
$userOptions = array();
$navBarButtons = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$navBarButtons .= $p->navBar();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $navBarButtons;
}
public static function navBarAfter() {
$plugins = Plugin::getAllEnabled();
$userOptions = array();
$navBarButtons = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$navBarButtons .= $p->navBarAfter();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $navBarButtons;
}
/**
* excecute update function at plugin and
* update plugin version at database
*/
public static function updatePlugin($name) {
$p = static::loadPlugin($name);
if (empty($p)) {
return false;
}
$currentVersion = $p->getPluginVersion();
$uuid = $p->getUUID();
_error_log("AVideoPlugin::updatePlugin name=($name) uuid=($uuid) ");
if (method_exists($p, 'updateScript')) {
_error_log("AVideoPlugin::updatePlugin method_exists ", AVideoLog::$WARNING);
if ($p->updateScript())
Plugin::setCurrentVersionByUuid($uuid, $currentVersion);
else
return false;
} else {
_error_log("AVideoPlugin::updatePlugin method NOT exists ", AVideoLog::$WARNING);
Plugin::setCurrentVersionByUuid($uuid, $currentVersion);
}
return true;
}
public static function getCurrentVersion($name) {
$p = static::loadPlugin($name);
$uuid = $p->getUUID();
return Plugin::getCurrentVersionByUuid($uuid);
}
/**
*
* @param type $name
* @param type $version
* @return type
* -1 if your plugin is lower,
* 0 if they are equal, and
* 1 if your plugin is greater.
*/
public static function compareVersion($name, $version) {
$currentVersion = self::getCurrentVersion($name);
return version_compare($currentVersion, $version);
}
public static function getSwitchButton($name) {
global $global;
$p = static::loadPlugin($name);
$btn = "";
if (!empty($p)) {
$uid = uniqid();
$btn = '
';
}
return $btn;
}
public static function getAllVideosExcludeVideosIDArray() {
$plugins = Plugin::getAllEnabled();
$array = array();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$array = array_merge($array, $p->getAllVideosExcludeVideosIDArray());
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $array;
}
public static function userCanUpload($users_id) {
if (empty($users_id)) {
return false;
}
$resp = true;
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$can = $p->userCanUpload($users_id);
if (!empty($can)) {
if ($can < 0) {
_error_log("userCanUpload: DENIED The plugin {$value['dirName']} said the user ({$users_id}) can NOT upload a video ");
$resp = false;
}
if ($can > 0) {
_error_log("userCanUpload: SUCCESS The plugin {$value['dirName']} said the user ({$users_id}) can upload a video ");
return true;
}
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $resp;
}
public static function userCanWatchVideo($users_id, $videos_id) {
global $userCanWatchVideoFunction;
if (!isset($userCanWatchVideoFunction)) {
$userCanWatchVideoFunction = array();
}
if (!isset($userCanWatchVideoFunction[$users_id])) {
$userCanWatchVideoFunction[$users_id] = array();
}
if (isset($userCanWatchVideoFunction[$users_id][$videos_id])) {
return $userCanWatchVideoFunction[$users_id][$videos_id];
}
$cacheName = "userCanWatchVideo($users_id, $videos_id)";
$cache = ObjectYPT::getSessionCache($cacheName, 600);
if (isset($cache)) {
return $cache;
}
$plugins = Plugin::getAllEnabled();
$resp = Video::userGroupAndVideoGroupMatch($users_id, $videos_id);
$video = new Video("", "", $videos_id);
if (empty($video)) {
_error_log("userCanWatchVideo: the usergroup and the video group does not match, User = $users_id, video = $videos_id)");
$userCanWatchVideoFunction[$users_id][$videos_id] = false;
ObjectYPT::setSessionCache($cacheName, false);
return false;
}
// check if the video is for paid plans only
if ($video->getOnly_for_paid()) {
_error_log("userCanWatchVideo: the video ({$videos_id}) is set Only_for_paid = true)");
$resp = false;
}
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$can = $p->userCanWatchVideo($users_id, $videos_id);
if (!empty($can)) {
if ($can < 0) {
_error_log("userCanWatchVideo: DENIED The plugin {$value['dirName']} said the user ({$users_id}) can NOT watch the video ({$videos_id})");
$resp = false;
}
if ($can > 0) {
_error_log("userCanWatchVideo: SUCCESS The plugin {$value['dirName']} said the user ({$users_id}) can watch the video ({$videos_id})");
$userCanWatchVideoFunction[$users_id][$videos_id] = true;
ObjectYPT::setSessionCache($cacheName, true);
return true;
}
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
if (!empty($users_id)) {
_error_log("userCanWatchVideo: No plugins approve user ({$users_id}) watch the video ({$videos_id}) ");
}
$userCanWatchVideoFunction[$users_id][$videos_id] = $resp;
ObjectYPT::setSessionCache($cacheName, $resp);
return $resp;
}
public static function userCanWatchVideoWithAds($users_id, $videos_id) {
global $userCanWatchVideoWithAdsFunction;
$users_id = intval($users_id);
if (!isset($userCanWatchVideoWithAdsFunction)) {
$userCanWatchVideoWithAdsFunction = array();
}
if (!isset($userCanWatchVideoWithAdsFunction[$users_id])) {
$userCanWatchVideoWithAdsFunction[$users_id] = array();
}
if (isset($userCanWatchVideoWithAdsFunction[$users_id][$videos_id])) {
return $userCanWatchVideoWithAdsFunction[$users_id][$videos_id];
}
$plugins = Plugin::getAllEnabled();
$resp = Video::userGroupAndVideoGroupMatch($users_id, $videos_id);
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$can = $p->userCanWatchVideoWithAds($users_id, $videos_id);
if (!empty($can)) {
$resp = $can > 0 ? true : false;
if ($resp) {
_error_log("userCanWatchVideoWithAds the plugin ({$value['dirName']}) said user ({$users_id}) can watch");
$userCanWatchVideoWithAdsFunction[$users_id][$videos_id] = true;
return true;
} else {
//_error_log("userCanWatchVideoWithAds: users_id = $users_id, videos_id = $videos_id {$value['dirName']} said no");
}
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
$userCanWatchVideoWithAdsFunction[$users_id][$videos_id] = $resp;
return $resp;
}
public static function showAds($videos_id) {
global $_showAds;
if (!isset($_showAds)) {
$_showAds = array();
}
if (isset($_showAds[$videos_id])) {
return $_showAds[$videos_id];
}
$plugins = Plugin::getAllEnabled();
$resp = true;
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$showAds = $p->showAds($videos_id);
if (!$showAds) {
_error_log("showAds: {$value['dirName']} said NOT to show ads on {$videos_id}");
$_showAds[$videos_id] = false;
return false;
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
$_showAds[$videos_id] = $resp;
return $resp;
}
public static function isPaidUser($users_id) {
global $_isPaidUser;
if (!isset($_isPaidUser)) {
$_isPaidUser = array();
}
if (isset($_isPaidUser[$users_id])) {
return $_isPaidUser[$users_id];
}
$plugins = Plugin::getAllEnabled();
$resp = false;
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$isPaidUser = $p->isPaidUser($users_id);
if ($isPaidUser) {
_error_log("isPaidUser: {$value['dirName']} said {$users_id} is a paid user");
$_isPaidUser[$users_id] = true;
return true;
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
$_isPaidUser[$users_id] = $resp;
return $resp;
}
/**
* In case some plugin needs to play a video that is not allowed for some reason.
* A plugin can replace the getVideo method from the youtubeMode page
* @return type
*/
public static function getVideo() {
$plugins = Plugin::getAllEnabled();
$resp = null;
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$video = $p->getVideo();
if (!empty($video)) {
return $video;
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $resp;
}
public static function onUserSignIn($users_id) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onUserSignIn($users_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function onUserSignup($users_id) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onUserSignup($users_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function onLiveStream($users_id, $live_servers_id) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onLiveStream($users_id, $live_servers_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
}
public static function onUserSocketConnect() {
_mysql_connect();
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onUserSocketConnect();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
_mysql_close();
}
public static function onUserSocketDisconnect() {
_mysql_connect();
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onUserSocketDisconnect();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
_mysql_close();
}
public static function thumbsOverlay($videos_id) {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->thumbsOverlay($videos_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function profileTabName($users_id) {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->profileTabName($users_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function profileTabContent($users_id) {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->profileTabContent($users_id);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function getVideoTags($videos_id) {
global $global, $advancedCustom;
if (empty($videos_id) || !empty($global['disableVideoTags']) || !empty($advancedCustom->disableVideoTags)) {
return array();
}
global $_getVideoTags;
if (empty($_getVideoTags)) {
$_getVideoTags = array();
}
if (isset($_getVideoTags[$videos_id])) {
$array = $_getVideoTags[$videos_id];
} else {
$name = "getVideoTags{$videos_id}";
$array = ObjectYPT::getCache($name, 86400);
//_error_log("getVideoTags $name ".(empty($array)?"new":"old"));
if (empty($array)) {
TimeLogStart("AVideoPlugin::getVideoTags($videos_id)");
$plugins = Plugin::getAllEnabled();
$array = array();
foreach ($plugins as $value) {
$TimeLog = "AVideoPlugin::getVideoTags($videos_id) {$value['dirName']} ";
TimeLogStart($TimeLog);
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$array = array_merge($array, $p->getVideoTags($videos_id));
}
TimeLogEnd($TimeLog, __LINE__);
}
TimeLogEnd("AVideoPlugin::getVideoTags($videos_id)", __LINE__);
ObjectYPT::setCache($name, $array);
$_getVideoTags[$videos_id] = $array;
} else {
//$array = object_to_array($array);
}
}
return $array;
}
public static function deleteVideoTags($videos_id) {
if (empty($videos_id)) {
return false;
}
$name = "getVideoTags{$videos_id}";
_error_log("deleteVideoTags {$name}");
ObjectYPT::deleteSessionCache($name);
return ObjectYPT::deleteCache($name);
}
public static function getVideoWhereClause() {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->getVideoWhereClause();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function getManagerVideosAddNew() {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->getManagerVideosAddNew();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function saveVideosAddNew($post, $videos_id) {
$plugins = Plugin::getAllEnabled();
$r = true;
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r = $p->saveVideosAddNew($post, $videos_id) && $r;
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function getManagerVideosReset() {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->getManagerVideosReset();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function getManagerVideosEdit() {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->getManagerVideosEdit();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function getManagerVideosEditField() {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->getManagerVideosEditField();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function getManagerVideosJavaScripts() {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->getManagerVideosJavaScripts();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function getManagerVideosTab() {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->getManagerVideosTab();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function getManagerVideosBody() {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->getManagerVideosBody();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function getAllVideosArray($videos_id) {
$plugins = Plugin::getAllEnabled();
$r = array();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r = array_merge($r, $p->getAllVideosArray($videos_id));
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function getUploadMenuButton() {
$plugins = Plugin::getAllEnabled();
$r = "";
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$r .= $p->getUploadMenuButton();
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return $r;
}
public static function dataSetup() {
$plugins = Plugin::getAllEnabled();
$r = array();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$data = $p->dataSetup();
if (!empty($data)) {
$r[] = $data;
}
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return implode(",", $r);
}
/* Video properties hooks */
public static function onVideoSetLive_transmitions_history_id($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetLive_transmitions_history_id($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetEncoderURL($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetEncoderURL($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetFilepath($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetFilepath($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetFilesize($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetFilesize($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetUsers_id($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetUsers_id($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetSites_id($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetSites_id($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetVideo_password($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetVideo_password($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetClean_title($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetClean_title($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetDuration($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetDuration($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetIsSuggested($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetIsSuggested($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetStatus($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetStatus($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetType($video_id, $oldValue, $newValue, $force) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetType($video_id, $oldValue, $newValue, $force);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetRotation($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetRotation($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetZoom($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetZoom($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetDescription($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetDescription($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetCategories_id($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetCategories_id($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetVideoDownloadedLink($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetVideoDownloadedLink($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetVideoGroups($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetVideoGroups($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetTrailer1($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetTrailer1($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetTrailer2($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetTrailer2($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetTrailer3($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetTrailer3($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetRate($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetRate($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetYoutubeId($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetYoutubeId($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetTitle($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetTitle($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetFilename($video_id, $oldValue, $newValue, $force) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetFilename($video_id, $oldValue, $newValue, $force);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetNext_videos_id($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetNext_videos_id($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetVideoLink($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetVideoLink($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetCan_download($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetCan_download($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetCan_share($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetCan_share($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
+ public static function getWalletConfigurationHTML($users_id, $wallet, $walletDataObject) {
+ $plugins = Plugin::getAllEnabled();
+ foreach ($plugins as $value) {
+ self::YPTstart();
+ $p = static::loadPlugin($value['dirName']);
+ if (is_object($p)) {
+ $p->getWalletConfigurationHTML($users_id, $wallet, $walletDataObject);
+ }
+ self::YPTend("{$value['dirName']}::" . __FUNCTION__);
+ }
+ return;
+ }
+
public static function onVideoSetOnly_for_paid($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetOnly_for_paid($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetRrating($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetRrating($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetExternalOptions($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetExternalOptions($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetVideoStartSeconds($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetVideoStartSeconds($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function onVideoSetSerie_playlists_id($video_id, $oldValue, $newValue) {
$plugins = Plugin::getAllEnabled();
foreach ($plugins as $value) {
self::YPTstart();
$p = static::loadPlugin($value['dirName']);
if (is_object($p)) {
$p->onVideoSetSerie_playlists_id($video_id, $oldValue, $newValue);
}
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
}
return;
}
public static function getPluginsOnByDefault($getUUID = true) {
if (empty($getUUID)) {
return array(
'CustomizeUser', // CustomizeUser
'CustomizeAdvanced', // CustomizeAdvanced
'Layout', // Layout
'PlayerSkins', // PlayerSkins
'Permissions', // Permissions
'Scheduler', // Permissions
);
} else {
return array(
'55a4fa56-8a30-48d4-a0fb-8aa6b3fuser3', // CustomizeUser
'55a4fa56-8a30-48d4-a0fb-8aa6b3f69033', // CustomizeAdvanced
'layout84-8f5a-4d1b-b912-172c608bf9e3', // Layout
'e9a568e6-ef61-4dcc-aad0-0109e9be8e36', // PlayerSkins
'Permissions-5ee8405eaaa16', // Permissions
'Scheduler-5ee8405eaaa16', // Permissions
);
}
}
public static function getPluginsNameOnByDefaultFromUUID($UUID) {
$UUIDs = self::getPluginsOnByDefault();
$key = array_search($UUID, $UUIDs);
if ($key === false) {
return false;
}
$names = self::getPluginsOnByDefault(false);
if (empty($names[$key])) {
return false;
}
return $names[$key];
}
public static function isPluginOnByDefault($UUID) {
$UUIDs = self::getPluginsOnByDefault();
return in_array($UUID, $UUIDs);
}
static function fixName($name) {
if ($name === 'Programs') {
return 'PlayLists';
}
return $name;
}
}
class YouPHPTubePlugin extends AVideoPlugin {
}
diff --git a/plugin/Plugin.abstract.php b/plugin/Plugin.abstract.php
index 4d89e7b40..12439c25d 100644
--- a/plugin/Plugin.abstract.php
+++ b/plugin/Plugin.abstract.php
@@ -1,722 +1,726 @@
getUUID();
if (empty(PluginAbstract::$dataObject[$uuid])) {
$obj = Plugin::getPluginByUUID($uuid);
//echo $obj['object_data'];
$o = array();
if (!empty($obj['object_data'])) {
$o = _json_decode(stripslashes($obj['object_data']));
$json_last_error = json_last_error();
if ($json_last_error !== JSON_ERROR_NONE) {
//var_dump($this->getName(), $json_last_error, $o, $obj['object_data']);
//_error_log('getDataObject - JSON error (' . $json_last_error . ') ' . $this->getName()." ".$this->getUUID());
$o = _json_decode($obj['object_data']);
$json_last_error = json_last_error();
}
switch ($json_last_error) {
case JSON_ERROR_NONE:
//echo ' - No errors';
break;
default:
_error_log('getDataObject - JSON error ' . $this->getName());
_error_log($obj['object_data']);
_error_log('striped slashes');
_error_log(stripslashes($obj['object_data']));
case JSON_ERROR_DEPTH:
_error_log(' - Maximum stack depth exceeded');
break;
case JSON_ERROR_STATE_MISMATCH:
_error_log(' - Underflow or the modes mismatch');
break;
case JSON_ERROR_CTRL_CHAR:
_error_log(' - Unexpected control character found');
break;
case JSON_ERROR_SYNTAX:
_error_log(' - Syntax error, malformed JSON');
_error_log($obj['object_data']);
_error_log('striped slashes');
_error_log(stripslashes($obj['object_data']));
break;
case JSON_ERROR_UTF8:
_error_log(' - Malformed UTF-8 characters, possibly incorrectly encoded');
break;
}
}
$eo = $this->getEmptyDataObject();
// check if the plugin define any array for the select option, if does, overwrite it
foreach ($eo as $key => $value) {
if(isset($value->type) && is_array($value->type) && isset($o->$key) && isset($o->$key->type)){
$o->$key->type = $value->type;
}
}
$wholeObjects = array_merge((array) $eo, (array) $o);
$disabledPlugins = plugin::getAllDisabled();
foreach ($disabledPlugins as $value) {
$p = AVideoPlugin::loadPlugin($value['dirName']);
if (is_object($p)) {
$foreginObjects = $p->getCustomizeAdvancedOptions();
if ($foreginObjects) {
foreach ($foreginObjects as $optionName => $defaultValue)
if (isset($wholeObjects[$optionName]))
unset($wholeObjects[$optionName]);
}
}
}
PluginAbstract::$dataObject[$this->getUUID()] = $wholeObjects;
}else {
$wholeObjects = PluginAbstract::$dataObject[$this->getUUID()];
}
//var_dump($obj['object_data']);
//var_dump($eo, $o, (object) array_merge((array) $eo, (array) $o));exit;
return (object) $wholeObjects;
}
public function setDataObject($object) {
$pluginRow = Plugin::getPluginByUUID($this->getUUID());
if(empty($pluginRow)){
return false;
}
$obj = new Plugin($pluginRow['id']);
$obj->setObject_data(addcslashes(json_encode($object), '\\'));
return $obj->save();
}
public function setDataObjectParameter($parameterName, $value) {
$object = $this->getDataObject();
eval("\$object->$parameterName = \$value;");
return $this->setDataObject($object);
}
public function getEmptyDataObject() {
$obj = new stdClass();
return $obj;
}
public function getFirstPage() {
return false;
}
public function afterNewVideo($videos_id) {
return false;
}
public function afterDonation($from_users_id, $how_much, $videos_id, $users_id) {
return false;
}
public function afterNewComment($comments_id) {
return false;
}
public function afterNewResponse($comments_id) {
return false;
}
public function xsendfilePreVideoPlay() {
return false;
}
public function getLogin() {
$obj = new stdClass();
$obj->class = ""; // btn btn-primary btn-block
$obj->icon = ""; // fab fa-facebook-square
$obj->type = ""; // Facebook, Google, etc
$obj->linkToDevelopersPage = ""; //https://console.developers.google.com/apis/credentials , https://developers.facebook.com/apps
return $obj;
}
public function getWatchActionButton($videos_id) {
return "";
}
public function getNetflixActionButton($videos_id) {
return "";
}
public function getGalleryActionButton($videos_id) {
return "";
}
public function getStart() {
return false;
}
public function getEnd() {
return false;
}
public function afterVideoJS() {
return false;
}
public function canEditPlugin() {
global $global;
return empty($global['disableAdvancedConfigurations']);
}
public function hidePlugin() {
return false;
}
public function getChannelButton() {
return "";
}
public function getVideoManagerButton() {
return "";
}
public function getLivePanel() {
return "";
}
public function getPlayListButtons($playlist_id) {
return "";
}
public function getMyAccount($users_id) {
return "";
}
/**
*
* @return type array(array("key"=>'live key', "users"=>false, "name"=>$userName, "user"=>$user, "photo"=>$photo, "UserPhoto"=>$UserPhoto, "title"=>''));
*/
public function getLiveApplicationArray() {
return array();
}
public function addRoutes() {
return false;
}
public function addView($videos_id, $total) {
return false;
}
public function getCustomizeAdvancedOptions() {
return false;
}
public function getUserOptions() {
return array();
}
public function getModeYouTube($videos_id) {
return false;
}
public function getModeLive($key) {
return false;
}
public function getModeLiveLink($liveLink_id) {
return false;
}
public function getModeYouTubeLive($users_id) {
return false;
}
public function getEmbed($videos_id) {
return false;
}
/**
* Loads a channel before display the channel page, usefull to create customized channel pages
* @param type $user is an database array from channels owner
* @return boolean
*/
public function getChannel($user_id, $user) {
return false;
}
/**
*
* @return type return a list of IDs of the user groups
*/
public function getDynamicUserGroupsId($users_id) {
return array();
}
public function getDynamicUsersId($users_groups_id) {
return array();
}
public function navBarButtons() {
return "";
}
public function navBarProfileButtons() {
return "";
}
public function navBar() {
return "";
}
public function navBarAfter() {
return "";
}
public function isReady($pluginsList) {
$return = array('ready' => array(), 'missing' => array());
foreach ($pluginsList as $name) {
$plugin = AVideoPlugin::loadPlugin($name);
$uuid = $plugin->getUUID();
if (!AVideoPlugin::isEnabled($uuid)) {
$return['missing'][] = array('name' => $name, 'uuid' => $uuid);
} else {
$return['ready'][] = array('name' => $name, 'uuid' => $uuid);
}
}
return $return;
}
public function isReadyLabel($pluginsList) {
$desc = "
";
$ready = $this->isReady($pluginsList);
foreach ($ready['ready'] as $value) {
$desc .= "{$value['name']} ";
}
foreach ($ready['missing'] as $value) {
$desc .= "{$value['name']} ";
}
return $desc;
}
public function getAllVideosExcludeVideosIDArray() {
return array();
}
/**
*
* @param type $users_id
* @return 0 = I dont know, -1 = can not upload, 1 = can upload
*/
public function userCanUpload($users_id) {
return 0;
}
/**
*
* @param type $users_id
* @param type $videos_id
* @return 0 = I dont know, -1 = can not watch, 1 = can watch
*/
public function userCanWatchVideo($users_id, $videos_id) {
return 0;
}
/**
*
* @param type $users_id
* @param type $videos_id
* @return 0 = I dont know, -1 = can not watch, 1 = can watch
*/
public function userCanWatchVideoWithAds($users_id, $videos_id) {
return 0;
}
/**
* temporary, to avoid error on old secureVideosDirectory plugins
* @return boolean
*/
function verifyEmbedSecurity() {
return true;
}
function showAds($videos_id) {
return true;
}
function isPaidUser($users_id) {
return false;
}
function getVideo() {
return null;
}
public function onUserSignIn($users_id) {
return null;
}
public function onUserSignup($users_id) {
return null;
}
public function onLiveStream($users_id, $live_servers_id) {
return null;
}
public function thumbsOverlay($videos_id) {
return "";
}
public static function profileTabName($users_id) {
return "";
}
public static function profileTabContent($users_id) {
return "";
}
public static function getVideoWhereClause() {
return "";
}
public static function getManagerVideosAddNew() {
return "";
}
public static function saveVideosAddNew($post, $videos_id) {
return true;
}
public static function getManagerVideosReset() {
return "";
}
public static function getManagerVideosEdit() {
return "";
}
public static function getManagerVideosEditField() {
return "";
}
public static function getManagerVideosJavaScripts() {
return "";
}
public static function getManagerVideosTab() {
return "";
}
public static function getManagerVideosBody() {
return "";
}
public static function getAllVideosArray($videos_id) {
return array();
}
public static function getVideoTags($videos_id) {
return array();
}
public function getMobileInfo() {
return null;
}
public function getUploadMenuButton() {
return "";
}
public function dataSetup() {
return "";
}
function getPermissionsOptions(){
return array();
}
protected function addDataObjectHelper($property, $name, $description=""){
$this->dataObjectHelper[$property] = array("name"=>$name, "description"=>$description);
}
function getDataObjectHelper(){
return $this->dataObjectHelper;
}
function onUserSocketConnect(){
}
function onUserSocketDisconnect(){
}
function onVideoSetLive_transmitions_history_id($video_id, $oldValue, $newValue) {
}
function onVideoSetEncoderURL($video_id, $oldValue, $newValue) {
}
function onVideoSetFilepath($video_id, $oldValue, $newValue) {
}
function onVideoSetFilesize($video_id, $oldValue, $newValue) {
}
function onVideoSetUsers_id($video_id, $oldValue, $newValue) {
}
function onVideoSetSites_id($video_id, $oldValue, $newValue) {
}
function onVideoSetVideo_password($video_id, $oldValue, $newValue) {
}
function onVideoSetClean_title($video_id, $oldValue, $newValue) {
}
function onVideoSetDuration($video_id, $oldValue, $newValue) {
}
function onVideoSetIsSuggested($video_id, $oldValue, $newValue) {
}
function onVideoSetStatus($video_id, $oldValue, $newValue) {
}
function onVideoSetType($video_id, $oldValue, $newValue, $force) {
}
function onVideoSetRotation($video_id, $oldValue, $newValue) {
}
function onVideoSetZoom($video_id, $oldValue, $newValue) {
}
function onVideoSetDescription($video_id, $oldValue, $newValue) {
}
function onVideoSetCategories_id($video_id, $oldValue, $newValue) {
}
function onVideoSetVideoDownloadedLink($video_id, $oldValue, $newValue) {
}
function onVideoSetVideoGroups($video_id, $oldValue, $newValue) {
}
function onVideoSetTrailer1($video_id, $oldValue, $newValue) {
}
function onVideoSetTrailer2($video_id, $oldValue, $newValue) {
}
function onVideoSetTrailer3($video_id, $oldValue, $newValue) {
}
function onVideoSetRate($video_id, $oldValue, $newValue) {
}
function onVideoSetYoutubeId($video_id, $oldValue, $newValue) {
}
function onVideoSetTitle($video_id, $oldValue, $newValue) {
}
function onVideoSetFilename($video_id, $oldValue, $newValue, $force) {
}
function onVideoSetNext_videos_id($video_id, $oldValue, $newValue) {
}
function onVideoSetVideoLink($video_id, $oldValue, $newValue) {
}
function onVideoSetCan_download($video_id, $oldValue, $newValue) {
}
function onVideoSetCan_share($video_id, $oldValue, $newValue) {
}
function onVideoSetOnly_for_paid($video_id, $oldValue, $newValue) {
}
function onVideoSetRrating($video_id, $oldValue, $newValue) {
}
function onVideoSetExternalOptions($video_id, $oldValue, $newValue) {
}
function onVideoSetVideoStartSeconds($video_id, $oldValue, $newValue) {
}
function onVideoSetSerie_playlists_id($video_id, $oldValue, $newValue) {
}
function updateParameter($parameterName, $newValue) {
$pluginDO = $this->getDataObject();
$pluginDB = Plugin::getPluginByName($this->getName());
foreach ($pluginDO as $key => $value) {
if ($key == $parameterName) {
$pluginDO->$key = $newValue;
}
}
$p = new Plugin($pluginDB['id']);
$p->setObject_data(json_encode($pluginDO));
return $p->save();
}
+
+ public function getWalletConfigurationHTML($users_id, $wallet, $walletDataObject) {
+ return "";
+ }
}
class PluginPermissionOption{
private $type, $name, $description, $className;
function __construct($type, $name, $description, $className) {
$this->type = $type;
$this->name = $name;
$this->description = $description;
$this->className = $className;
}
function getType() {
return $this->type;
}
function getName() {
return $this->name;
}
function getDescription() {
return $this->description;
}
function getClassName() {
return $this->className;
}
}