1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-06 03:50:04 +02:00

Add option to select what type of caninical URL you want

This commit is contained in:
Daniel Neto 2023-12-13 22:02:47 -03:00
parent d16b5fa119
commit 63875fa56f
6 changed files with 77 additions and 42 deletions

View file

@ -4139,7 +4139,7 @@ function siteMap()
TimeLogEnd("siteMap Video::getLink $videos_id", __LINE__, 0.5);
$title = strip_tags($video['title']);
TimeLogStart("siteMap Video::getLinkToVideo $videos_id");
$player_loc = Video::getLinkToVideo($video['id'], $video['clean_title'], true, Video::$urlTypeCanonical);
$player_loc = Video::getLinkToVideo($video['id'], $video['clean_title'], true, Video::$urlTypeShort);
//$player_loc = $loc;
TimeLogEnd("siteMap Video::getLinkToVideo $videos_id", __LINE__, 0.5);
TimeLogStart("siteMap Video::isPublic $videos_id");

View file

@ -42,7 +42,7 @@ function getMetaTagsContentVideoType($sourceFileURL)
return "video/mp4";
}
function generateMetaTags($videoType, $modifiedDate, $createdDate, $title, $description, $pageURL, $pageURLEmbed, $duration_in_seconds, $sourceFileURL, $imgPath, $imgURL, $extraMetatags = array())
function generateMetaTags($videoType, $modifiedDate, $createdDate, $title, $description, $pageURL, $pageURLEmbed, $duration_in_seconds, $sourceFileURL, $imgPath, $imgURL, $extraMetatags = array(), $canonicalURL='')
{
global $global, $config, $advancedCustom;
$ogType = determineOgType($videoType);
@ -119,8 +119,13 @@ function generateMetaTags($videoType, $modifiedDate, $createdDate, $title, $desc
}
if ($pageURL) {
$metaTags[] = "<meta property='og:url' content='{$pageURL}' />";
$metaTags[] = "<link rel=\"canonical\" href=\"{$pageURL}\" />";
$metaTags[] = "<meta name=\"twitter:url\" content=\"{$pageURL}\"/>";
if(empty($canonicalURL)){
$canonicalURL = $pageURL;
}
}
if(!empty($canonicalURL)){
$metaTags[] = "<link rel=\"canonical\" href=\"{$canonicalURL}\" />";
}
if (!empty($advancedCustom->fb_app_id)) {
$metaTags[] = "<meta property='fb:app_id' content='{$advancedCustom->fb_app_id}' />";
@ -262,7 +267,7 @@ function getOpenGraphVideo($videos_id)
{
global $global, $config, $advancedCustom;
$video = Video::getVideoLight($videos_id);
$canonicalURL = '';
if (!empty($_REQUEST['playlists_id'])) {
echo PHP_EOL . "<!-- OpenGraph Playlist -->" . PHP_EOL;
$pageURL = PlayLists::getLink($_REQUEST['playlists_id'], false, @$_REQUEST['playlist_index']);
@ -273,8 +278,9 @@ function getOpenGraphVideo($videos_id)
$pageURLEmbed = PlayLists::getTagLink($_REQUEST['tags_id'], true, @$_REQUEST['playlist_index']);
} else {
echo PHP_EOL . "<!-- OpenGraph Video -->" . PHP_EOL;
$pageURL = Video::getLinkToVideo($videos_id, '', false, Video::$urlTypeCanonical, [], true);
$pageURLEmbed = Video::getLinkToVideo($videos_id, '', true, Video::$urlTypeCanonical, [], true);
$pageURL = Video::getLinkToVideo($videos_id, '', false, Video::$urlTypeShort, [], true);
$pageURLEmbed = Video::getLinkToVideo($videos_id, '', true, Video::$urlTypeShort, [], true);
$canonicalURL = Video::getCanonicalLink($videos_id);
}
$sourceFileURL = '';
@ -319,7 +325,7 @@ function getOpenGraphVideo($videos_id)
$imgPath = $images->posterPortraitPath;
}
//var_dump(debug_backtrace());
return generateMetaTags($videoType, $modifiedDate, $createdDate, $title, $description, $pageURL, $pageURLEmbed, $duration_in_seconds, $sourceFileURL, $imgPath, $imgURL);
return generateMetaTags($videoType, $modifiedDate, $createdDate, $title, $description, $pageURL, $pageURLEmbed, $duration_in_seconds, $sourceFileURL, $imgPath, array(), $canonicalURL);
}
function getOpenGraphLiveLink($liveLink_id)

View file

@ -139,7 +139,7 @@ if (!class_exists('Video')) {
public static $videoTypeBlockedUser = 'blockedUser';
public static $typeOptions = ['audio', 'video', 'short', 'embed', 'linkVideo', 'linkAudio', 'torrent', 'pdf', 'image', 'gallery', 'article', 'serie', 'image', 'zip', 'notfound', 'blockedUser'];
public static $urlTypeFriendly = 'URLFriendly';
public static $urlTypeCanonical = 'URLCanonical';
public static $urlTypeShort = 'URLShort';
private $categoryWasChanged = false;
public function __construct($title = "", $filename = "", $id = 0, $refreshCache = false)
@ -1634,8 +1634,8 @@ if (!class_exists('Video')) {
} elseif (in_array($videoType, self::$typeOptions)) {
$sql .= " AND v.type = '{$videoType}' ";
}
}
}
if (!empty($videosArrayId) && is_array($videosArrayId) && (is_numeric($videosArrayId[0]))) {
$sql .= " ORDER BY FIELD(v.id, '" . implode("', '", $videosArrayId) . "') ";
} else {
@ -1697,7 +1697,7 @@ if (!class_exists('Video')) {
$max_duration_in_seconds = intval($max_duration_in_seconds);
$sql .= " AND duration_in_seconds IS NOT NULL AND duration_in_seconds <= {$max_duration_in_seconds} AND duration_in_seconds > 0 ";
}
if (!empty($passwordProtectedOnly)) {
$sql .= " AND (v.video_password IS NOT NULL AND v.video_password != '') ";
}
@ -1835,14 +1835,14 @@ if (!class_exists('Video')) {
}
$tlogName = TimeLogStart("video::getInfo index={$index} id={$row['id']} {$row['type']}");
$row = self::getInfo($row, $getStatistcs);
if ($getStatistcs) {
$row = self::getInfoPersonal($row);
}
if(!empty($users_id)){
}
if (!empty($users_id)) {
TimeLogEnd($tlogName, __LINE__, $tolerance / 2);
$row['progress'] = self::getVideoPogressPercent($row['id'], $users_id);
}else {
} else {
$row['progress'] = ['percent' => 0, 'lastVideoTime' => 0, 'duration' => $row['duration_in_seconds']];
}
TimeLogEnd($tlogName, __LINE__, $tolerance / 2);
@ -2197,31 +2197,31 @@ if (!class_exists('Video')) {
}
public static function getDistinctVideoTypes()
{
global $global;
{
global $global;
// SQL query to select distinct types from the videos table
$sql = "SELECT DISTINCT v.`type` FROM videos as v";
// SQL query to select distinct types from the videos table
$sql = "SELECT DISTINCT v.`type` FROM videos as v";
// Execute the SQL query
$res = sqlDAL::readSql($sql);
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
// Execute the SQL query
$res = sqlDAL::readSql($sql);
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
// Initialize an array to store the distinct video types
$videoTypes = [];
// Initialize an array to store the distinct video types
$videoTypes = [];
// Check if the query execution was successful
if ($res !== false) {
foreach ($fullData as $row) {
// Add the video type to the array
$videoTypes[] = $row['type'];
// Check if the query execution was successful
if ($res !== false) {
foreach ($fullData as $row) {
// Add the video type to the array
$videoTypes[] = $row['type'];
}
}
// Return the array containing distinct video types
return $videoTypes;
}
}
// Return the array containing distinct video types
return $videoTypes;
}
/**
@ -2377,7 +2377,7 @@ if (!class_exists('Video')) {
if ($status === 'suggested') {
$suggestedOnly = true;
$status = '';
}else if ($status === 'passwordProtected') {
} else if ($status === 'passwordProtected') {
$passwordProtectedOnly = true;
$status = '';
}
@ -3195,7 +3195,7 @@ if (!class_exists('Video')) {
if (empty($this->users_id)) {
return false;
}
if ((!User::isLogged()) ) {
if ((!User::isLogged())) {
return false;
}
@ -4238,7 +4238,7 @@ if (!class_exists('Video')) {
if (!empty($global['langs_codes_values_withdot']) && is_array($global['langs_codes_values_withdot'])) {
$search = array_merge($search, $global['langs_codes_values_withdot']);
}
$path_parts = pathinfo($filename);
if (!empty($path_parts['extension']) && $path_parts['extension'] == 'vtt') {
$p = explode('.', $path_parts['filename']);
@ -5110,9 +5110,32 @@ if (!class_exists('Video')) {
return $url;
}
public static function getCanonicalLink($videos_id)
{
global $advancedCustom;
$type = Video::$urlTypeShort;
$ignoreChannelname = true;
$embed = isEmbed();
//array(0 => 'Short URL', 1 => 'URL+Channel Name', 2 => 'URL+Channel+Title');
switch ($advancedCustom->canonicalURLType) {
case 0:
$type = Video::$urlTypeShort;
$ignoreChannelname = true;
break;
case 1:
$type = Video::$urlTypeShort;
$ignoreChannelname = false;
break;
case 2:
$type = Video::$urlTypeFriendly;
$ignoreChannelname = false;
break;
}
return Video::getLinkToVideo($videos_id, '', $embed, $type, [], $ignoreChannelname);
}
public static function getPermaLink($videos_id, $embed = false, $get = [])
{
return self::getLinkToVideo($videos_id, "", $embed, Video::$urlTypeCanonical, $get);
return self::getLinkToVideo($videos_id, "", $embed, Video::$urlTypeShort, $get);
}
public static function getURLFriendly($videos_id, $embed = false, $get = [])
@ -5122,7 +5145,7 @@ if (!class_exists('Video')) {
public static function getPermaLinkFromCleanTitle($clean_title, $embed = false, $get = [])
{
return self::getLinkToVideo("", $clean_title, $embed, Video::$urlTypeCanonical, $get);
return self::getLinkToVideo("", $clean_title, $embed, Video::$urlTypeShort, $get);
}
public static function getURLFriendlyFromCleanTitle($clean_title, $embed = false, $get = [])

View file

@ -102,7 +102,7 @@ class AutoPostOnSocialMedia extends PluginAbstract {
if(AVideoPlugin::isEnabledByName('BitLy')){
$url = BitLy::getLink($videos_id);
}else{
$url = Video::getLinkToVideo($videos_id, "", false, Video::$urlTypeCanonical);
$url = Video::getLinkToVideo($videos_id, "", false, Video::$urlTypeShort);
}
_error_log("AutoPostOnSocialMedia::postVideo($videos_id) $url");
return self::post($url);

View file

@ -167,6 +167,7 @@ class CustomizeAdvanced extends PluginAbstract {
'showCreationTimeOnVideoItem',
'showChannelPhotoOnVideoItem',
'showChannelNameOnVideoItem',
'canonicalURLType',
);
}
@ -257,6 +258,11 @@ class CustomizeAdvanced extends PluginAbstract {
$obj->usePermalinks = false;
self::addDataObjectHelper('usePermalinks', 'Do not show video title on URL', 'This option is not good for SEO, but makes the URL clear');
$o->type = array(0 => 'Short URL', 1 => 'URL+Channel Name', 2 => 'URL+Channel+Title');
$o->value = 1;
$obj->canonicalURLType = $o;
$obj->disableAnimatedGif = false;
$obj->removeBrowserChannelLinkFromMenu = false;
$obj->EnableMinifyJS = false;

View file

@ -7,7 +7,7 @@ if (empty($video['id']) && !empty(getVideos_id())) {
}
if (!empty($video['id'])) {
$url = Video::getLinkToVideo($video['id']);
$urlShort = Video::getLinkToVideo($video['id'], '', false, Video::$urlTypeCanonical, [], true);
$urlShort = Video::getLinkToVideo($video['id'], '', false, Video::$urlTypeShort, [], true);
if (!empty($video['title'])) {
$titleSocial = $video['title'];
} else {