mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Updates for new tags support
This commit is contained in:
parent
e948abe78f
commit
f9b92661e6
10 changed files with 260 additions and 67 deletions
|
@ -41,9 +41,9 @@ if (!function_exists('xss_esc')) {
|
|||
}
|
||||
$result = @htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
|
||||
if (empty($result)) {
|
||||
$result = str_replace(['"', "'", "\\"], ["", "", ""], strip_tags($text));
|
||||
$result = str_replace(['"', "'", "\\", "document.", "cookie"], ["", "", "", '', ''], strip_tags($text));
|
||||
}
|
||||
$result = str_replace(['&'], ['&'], $result);
|
||||
$result = str_ireplace(['&'], ['&'], $result);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ foreach ($scanVars as $value) {
|
|||
|
||||
foreach ($securityFilter as $value) {
|
||||
if (!empty($scanThis[$value])) {
|
||||
$scanThis[$value] = str_replace(['\\', "--", "'", '"', """, "'", "%23", "%5c", "#"], ['', '', '', '', '', '', '', '', ''], xss_esc($scanThis[$value]));
|
||||
$scanThis[$value] = str_ireplace(['\\', "--", "'", '"', """, "'", "%23", "%5c", "#"], ['', '', '', '', '', '', '', '', ''], xss_esc($scanThis[$value]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2768,14 +2768,6 @@ if (!class_exists('Video')) {
|
|||
}
|
||||
TimeLogEnd("video::getTags_ new Video $video_id, $type", __LINE__, $tolerance);
|
||||
|
||||
/**
|
||||
a = active
|
||||
i = inactive
|
||||
e = encoding
|
||||
x = encoding error
|
||||
d = downloading
|
||||
u = unlisted
|
||||
*/
|
||||
TimeLogStart("video::getTags_ status $video_id, $type");
|
||||
if (empty($type) || $type === "status") {
|
||||
$objTag = new stdClass();
|
||||
|
|
|
@ -277,22 +277,6 @@ class API extends PluginAbstract {
|
|||
return new ApiObject("There are no videos for this playlist", true, $parameters);
|
||||
}
|
||||
|
||||
if (empty($parameters['index'])) {
|
||||
$parameters['index'] = 0;
|
||||
}
|
||||
|
||||
if (empty($videos[$parameters['index']])) {
|
||||
$video = $videos[0];
|
||||
} else {
|
||||
$video = $videos[$parameters['index']];
|
||||
}
|
||||
|
||||
$parameters['nextIndex'] = $parameters['index'] + 1;
|
||||
|
||||
if (empty($videos[$parameters['nextIndex']])) {
|
||||
$parameters['nextIndex'] = 0;
|
||||
}
|
||||
|
||||
if (empty($parameters['playlists_id'])) {
|
||||
//return new ApiObject("Playlist ID is empty", true, $parameters);
|
||||
$_POST['sort']['created'] = 'DESC';
|
||||
|
@ -318,37 +302,8 @@ class API extends PluginAbstract {
|
|||
$parameters['channel_bg'] = $user->getBackground();
|
||||
$parameters['channel_link'] = $user->getChannelLink();
|
||||
}
|
||||
$videoPath = Video::getHigherVideoPathFromID($video['id']);
|
||||
$parameters['videos'] = $videos;
|
||||
$parameters['modified_timestamp'] = strtotime($parameters['modified']);
|
||||
$parameters['totalPlaylistDuration'] = 0;
|
||||
$parameters['currentPlaylistTime'] = 0;
|
||||
foreach ($parameters['videos'] as $key => $value) {
|
||||
$parameters['videos'][$key]['path'] = Video::getHigherVideoPathFromID($value['id']);
|
||||
if ($key && $key <= $parameters['index']) {
|
||||
$parameters['currentPlaylistTime'] += durationToSeconds($parameters['videos'][$key - 1]['duration']);
|
||||
}
|
||||
$parameters['totalPlaylistDuration'] += durationToSeconds($parameters['videos'][$key]['duration']);
|
||||
|
||||
$parameters['videos'][$key]['info'] = Video::getTags($value['id']);
|
||||
$parameters['videos'][$key]['category'] = Category::getCategory($value['categories_id']);
|
||||
$parameters['videos'][$key]['media_session'] = Video::getMediaSession($value['id']);
|
||||
$parameters['videos'][$key]['images'] = Video::getImageFromFilename_($value['filename'], $value['type']);
|
||||
|
||||
if (!empty($parameters['audioOnly'])) {
|
||||
$parameters['videos'][$key]['mp3'] = convertVideoToMP3FileIfNotExists($value['id']);
|
||||
}
|
||||
}
|
||||
if (empty($parameters['totalPlaylistDuration'])) {
|
||||
$parameters['percentage_progress'] = 0;
|
||||
} else {
|
||||
$parameters['percentage_progress'] = ($parameters['currentPlaylistTime'] / $parameters['totalPlaylistDuration']) * 100;
|
||||
}
|
||||
$parameters['title'] = $video['title'];
|
||||
$parameters['videos_id'] = $video['id'];
|
||||
$parameters['path'] = $videoPath;
|
||||
$parameters['duration'] = $video['duration'];
|
||||
$parameters['duration_seconds'] = durationToSeconds($parameters['duration']);
|
||||
|
||||
$parameters = array_merge($parameters, PlayLists::videosToPlaylist($videos, @$parameters['index'], !empty($parameters['audioOnly'])));
|
||||
|
||||
return new ApiObject("", false, $parameters);
|
||||
}
|
||||
|
@ -405,6 +360,41 @@ class API extends PluginAbstract {
|
|||
}
|
||||
return new ApiObject("", false, $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* This API will return all the tags from VideoTags plugin, also will list the latest 100 videos from the tags your user is subscribed to
|
||||
* @param string $parameters
|
||||
* 'audioOnly' 1 or 0, this option will extract the MP3 from the video file
|
||||
* @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}
|
||||
* @return \ApiObject
|
||||
*/
|
||||
public function get_api_tags($parameters) {
|
||||
global $global;
|
||||
$vtags = AVideoPlugin::loadPluginIfEnabled("VideoTags");
|
||||
|
||||
if (empty($vtags)) {
|
||||
return new ApiObject("VideoTags is disabled");
|
||||
}
|
||||
|
||||
$tags = VideoTags::getAll(User::getId());
|
||||
if (is_array($tags)) {
|
||||
foreach ($tags as $key => $row) {
|
||||
$tags[$key]['videos'] = array();
|
||||
$tags[$key]['photo'] = $global['webSiteRootURL'].'view/img/notfound.jpg';
|
||||
if(!empty($row['subscription'])){
|
||||
$videos = TagsHasVideos::getAllVideosFromTagsId($row['id']);
|
||||
$tags[$key]['videos'] = PlayLists::videosToPlaylist($videos, @$parameters['index'], !empty($parameters['audioOnly']));
|
||||
if(!empty($tags[$key]['videos'][0])){
|
||||
$tags[$key]['photo'] = $tags[$key]['videos'][0]['images']['poster'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$tags = array();
|
||||
}
|
||||
|
||||
return new ApiObject("", false, $tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $parameters
|
||||
|
@ -453,10 +443,17 @@ class API extends PluginAbstract {
|
|||
*/
|
||||
public function get_api_video($parameters) {
|
||||
$start = microtime(true);
|
||||
$rowCount = getRowCount();
|
||||
if ($rowCount > 100) {
|
||||
// use 1 hour cache
|
||||
$cacheName = 'get_api_video' . md5(json_encode($parameters) . json_encode($_GET));
|
||||
|
||||
$cacheParameters = array('APIName', 'catName', 'rowCount', 'APISecret', 'sort', 'searchPhrase', 'current', 'tags_id', 'channelName', 'videoType', 'is_serie', 'user', 'videos_id');
|
||||
|
||||
$cacheVars = array();
|
||||
foreach ($cacheParameters as $value) {
|
||||
$cacheVars[$value] = @$_REQUEST[$value];
|
||||
}
|
||||
|
||||
// use 1 hour cache
|
||||
$cacheName = 'get_api_video' . md5(json_encode($cacheVars));
|
||||
if(empty($parameters['videos_id'])){
|
||||
$obj = ObjectYPT::getCache($cacheName, 3600);
|
||||
if (!empty($obj)) {
|
||||
$end = microtime(true) - $start;
|
||||
|
|
|
@ -2399,6 +2399,14 @@ Click <a href=\"{link}\">here</a> to join our live.";
|
|||
}
|
||||
return $latest['key'];
|
||||
}
|
||||
|
||||
public static function getLatest() {
|
||||
$latest = LiveTransmitionHistory::getLatest();
|
||||
if (empty($latest)) {
|
||||
return false;
|
||||
}
|
||||
return $latest;
|
||||
}
|
||||
|
||||
public static function isLive($users_id, $live_servers_id = 0, $live_index = '', $force_recreate = false) {
|
||||
global $_live_is_live;
|
||||
|
|
|
@ -388,14 +388,13 @@ class LiveTransmitionHistory extends ObjectYPT {
|
|||
return self::getApplicationObject($row['id']);
|
||||
}
|
||||
|
||||
public static function getLatest($key, $live_servers_id = null, $active=false) {
|
||||
public static function getLatest($key='', $live_servers_id = null, $active=false) {
|
||||
global $global;
|
||||
|
||||
if (empty($key)) {
|
||||
return false;
|
||||
$sql = "SELECT * FROM " . static::getTableName() . " WHERE 1=1 ";
|
||||
if (!empty($key)) {
|
||||
$sql .= " AND `key` LIKE '{$key}%' ";
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM " . static::getTableName() . " WHERE `key` LIKE '{$key}%' ";
|
||||
if (isset($live_servers_id)) {
|
||||
$sql .= " AND (live_servers_id = " . intval($live_servers_id);
|
||||
|
||||
|
|
114
plugin/Live/latestOrLive.php
Normal file
114
plugin/Live/latestOrLive.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
global $isLive;
|
||||
$isLive = 1;
|
||||
$isEmbed = 1;
|
||||
require_once '../../videos/configuration.php';
|
||||
$p = AVideoPlugin::loadPlugin("Live");
|
||||
$objSecure = AVideoPlugin::loadPluginIfEnabled('SecureVideosDirectory');
|
||||
if (!empty($objSecure)) {
|
||||
$objSecure->verifyEmbedSecurity();
|
||||
}
|
||||
|
||||
$liveVideo = Live::getLatest();
|
||||
if (!empty($liveVideo)) {
|
||||
setLiveKey($liveVideo['key'], $liveVideo['live_servers_id'], $liveVideo['live_index']);
|
||||
$poster = getURL(Live::getPosterImage($liveVideo['users_id'], $liveVideo['live_servers_id']));
|
||||
$sources = "<source src=\"" . Live::getM3U8File($liveVideo['key']) . "\" type=\"application/x-mpegURL\">";
|
||||
} else {
|
||||
$_POST['rowCount'] = 1;
|
||||
$videos = Video::getAllVideos();
|
||||
if (empty($videos)) {
|
||||
videoNotFound('');
|
||||
}
|
||||
$video = $videos[0];
|
||||
$poster = Video::getPoster($video['id']);
|
||||
$sources = getSources($video['filename']);
|
||||
}
|
||||
//var_dump($liveVideo, $video['id'], $poster, $sources);exit;
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?php echo getLanguage(); ?>">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" href="<?php echo getCDN(); ?>view/img/favicon.ico">
|
||||
<title><?php echo $liveTitle; ?></title>
|
||||
<link href="<?php echo getURL('view/bootstrap/css/bootstrap.css'); ?>" rel="stylesheet" type="text/css"/>
|
||||
<link href="<?php echo getURL('node_modules/fontawesome-free/css/all.min.css'); ?>" rel="stylesheet" type="text/css"/>
|
||||
<script src="<?php echo getURL('node_modules/jquery/dist/jquery.min.js'); ?>" type="text/javascript"></script>
|
||||
<link href="<?php echo getURL('node_modules/video.js/dist/video-js.min.css'); ?>" rel="stylesheet" type="text/css"/>
|
||||
<?php
|
||||
echo AVideoPlugin::afterVideoJS();
|
||||
?>
|
||||
<style>
|
||||
body {
|
||||
padding: 0 !important;
|
||||
margin: 0 !important;
|
||||
<?php
|
||||
if (!empty($customizedAdvanced->embedBackgroundColor)) {
|
||||
echo "background-color: $customizedAdvanced->embedBackgroundColor;";
|
||||
}
|
||||
?>
|
||||
overflow:hidden;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
var webSiteRootURL = '<?php echo $global['webSiteRootURL']; ?>';
|
||||
var player;
|
||||
</script>
|
||||
<?php
|
||||
echo AVideoPlugin::getHeadCode();
|
||||
?>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="">
|
||||
<video poster="<?php echo $poster; ?>" controls <?php echo PlayerSkins::getPlaysinline(); ?>
|
||||
class="video-js vjs-default-skin vjs-big-play-centered"
|
||||
id="mainVideo" style="width: 100%; height: 100%; position: absolute;">
|
||||
<?php echo $sources; ?>
|
||||
</video>
|
||||
</div>
|
||||
|
||||
<div style="z-index: 999; position: absolute; top:5px; left: 5px; opacity: 0.8; filter: alpha(opacity=80);" class="liveEmbed">
|
||||
<?php
|
||||
$streamName = $uuid;
|
||||
include $global['systemRootPath'] . 'plugin/Live/view/onlineLabel.php';
|
||||
echo getLiveUsersLabel();
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
include $global['systemRootPath'] . 'view/include/video.min.js.php';
|
||||
?>
|
||||
<?php
|
||||
echo AVideoPlugin::afterVideoJS();
|
||||
?>
|
||||
<?php
|
||||
include $global['systemRootPath'] . 'view/include/bootstrap.js.php';
|
||||
?>
|
||||
<script src="<?php echo getURL('view/js/script.js'); ?>" type="text/javascript"></script>
|
||||
<script src="<?php echo getURL('node_modules/js-cookie/dist/js.cookie.js'); ?>" type="text/javascript"></script>
|
||||
<script src="<?php echo getURL('node_modules/jquery-toast-plugin/dist/jquery.toast.min.js'); ?>" type="text/javascript"></script>
|
||||
<script src="<?php echo getURL('node_modules/sweetalert/dist/sweetalert.min.js'); ?>" type="text/javascript"></script>
|
||||
<script>
|
||||
<?php
|
||||
echo PlayerSkins::getStartPlayerJS();
|
||||
?>
|
||||
</script>
|
||||
<?php
|
||||
require_once $global['systemRootPath'] . 'plugin/AVideoPlugin.php';
|
||||
?>
|
||||
<!-- getFooterCode start -->
|
||||
<?php
|
||||
echo AVideoPlugin::getFooterCode();
|
||||
showCloseButton();
|
||||
?>
|
||||
<!-- getFooterCode end -->
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
include $global['systemRootPath'] . 'objects/include_end.php';
|
||||
?>
|
|
@ -421,6 +421,64 @@ class PlayLists extends PluginAbstract {
|
|||
return $link;
|
||||
}
|
||||
|
||||
static function videosToPlaylist($videos, $index=0, $audioOnly=false) {
|
||||
$parameters = array();
|
||||
$parameters['index'] = intval($index);
|
||||
|
||||
while(empty($videoPath) && !empty($videos)){
|
||||
|
||||
if (empty($videos[$parameters['index']])) {
|
||||
$video = $videos[0];
|
||||
} else {
|
||||
$video = $videos[$parameters['index']];
|
||||
}
|
||||
|
||||
$videoPath = Video::getHigherVideoPathFromID($video['id']);
|
||||
|
||||
if(!empty($videoPath)){
|
||||
$parameters['nextIndex'] = $parameters['index'] + 1;
|
||||
if (empty($videos[$parameters['nextIndex']])) {
|
||||
$parameters['nextIndex'] = 0;
|
||||
}
|
||||
break;
|
||||
}else{
|
||||
unset($videos[$parameters['index']]);
|
||||
$parameters['index']++;
|
||||
}
|
||||
}
|
||||
$parameters['videos'] = array_values($videos);
|
||||
$parameters['totalPlaylistDuration'] = 0;
|
||||
$parameters['currentPlaylistTime'] = 0;
|
||||
foreach ($parameters['videos'] as $key => $value) {
|
||||
$parameters['videos'][$key]['path'] = Video::getHigherVideoPathFromID($value['id']);
|
||||
if ($key && $key <= $parameters['index']) {
|
||||
$parameters['currentPlaylistTime'] += durationToSeconds($parameters['videos'][$key - 1]['duration']);
|
||||
}
|
||||
$parameters['totalPlaylistDuration'] += durationToSeconds($parameters['videos'][$key]['duration']);
|
||||
|
||||
$parameters['videos'][$key]['info'] = Video::getTags($value['id']);
|
||||
$parameters['videos'][$key]['category'] = Category::getCategory($value['categories_id']);
|
||||
$parameters['videos'][$key]['media_session'] = Video::getMediaSession($value['id']);
|
||||
$parameters['videos'][$key]['images'] = Video::getImageFromFilename_($value['filename'], $value['type']);
|
||||
|
||||
if (!empty($audioOnly)) {
|
||||
$parameters['videos'][$key]['mp3'] = convertVideoToMP3FileIfNotExists($value['id']);
|
||||
}
|
||||
}
|
||||
if (empty($parameters['totalPlaylistDuration'])) {
|
||||
$parameters['percentage_progress'] = 0;
|
||||
} else {
|
||||
$parameters['percentage_progress'] = ($parameters['currentPlaylistTime'] / $parameters['totalPlaylistDuration']) * 100;
|
||||
}
|
||||
$parameters['title'] = $video['title'];
|
||||
$parameters['videos_id'] = $video['id'];
|
||||
$parameters['path'] = $videoPath;
|
||||
$parameters['duration'] = $video['duration'];
|
||||
$parameters['duration_seconds'] = durationToSeconds($parameters['duration']);
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
static function getLinkToLive($playlists_id) {
|
||||
global $global;
|
||||
$pl = new PlayList($playlists_id);
|
||||
|
|
|
@ -154,5 +154,26 @@ class Tags extends ObjectYPT {
|
|||
return $rows;
|
||||
}
|
||||
|
||||
public static function getAllWithSubscriptionRow($users_id)
|
||||
{
|
||||
global $global;
|
||||
if (!static::isTableInstalled()) {
|
||||
return false;
|
||||
}
|
||||
$subSelect = " 0 as subscription ";
|
||||
if(!empty($users_id)){
|
||||
$subSelect = " (select id from tags_subscriptions thv WHERE thv.tags_id = t.id AND thv.users_id = {$users_id}) as subscription ";
|
||||
}
|
||||
$sql = "SELECT *, {$subSelect} FROM " . static::getTableName() . " t WHERE 1=1 ";
|
||||
|
||||
$sql .= self::getSqlFromPost();
|
||||
//echo $sql;exit;
|
||||
$res = sqlDAL::readSql($sql);
|
||||
$fullData = sqlDAL::fetchAllAssoc($res);
|
||||
sqlDAL::close($res);
|
||||
return $fullData;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -96,6 +96,10 @@ class VideoTags extends PluginAbstract {
|
|||
return $tag;
|
||||
}
|
||||
|
||||
static function getAll($users_id = 0) {
|
||||
return Tags::getAllWithSubscriptionRow($users_id);
|
||||
}
|
||||
|
||||
static function getAllFromVideosId($videos_id) {
|
||||
return TagsHasVideos::getAllFromVideosId($videos_id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue