mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
This commit is contained in:
parent
9776de2680
commit
aa48a4bd12
2 changed files with 57 additions and 29 deletions
|
@ -2627,8 +2627,7 @@ function getAdsDebugTag($adCode)
|
|||
if(!empty($_REQUEST['AdsDebug']) && User::isAdmin()){
|
||||
$function = debug_backtrace()[1]["function"];
|
||||
$function = str_replace('get', '', $function);
|
||||
$reason = ADs::getAdsCodeReason($global['lastAdsCodeType']);
|
||||
$adCode = "<div class=\"AdsDebug\">{$function}<br>".implode('<br>', $reason)."<br>$adCode</div>";
|
||||
$adCode = "<div class=\"AdsDebug\">{$function}<br>{$global['lastAdsCodeReason']}<br>$adCode</div>";
|
||||
}
|
||||
return $adCode;
|
||||
}
|
||||
|
|
|
@ -379,48 +379,77 @@ class ADs extends PluginAbstract
|
|||
{
|
||||
global $global;
|
||||
$global['lastAdsCodeType'] = $type;
|
||||
$global['lastAdsCodeReason'] = ''; // Initialize last reason as an empty string
|
||||
|
||||
// Check for infinite scroll
|
||||
if (isInfiniteScroll()) {
|
||||
$global['lastAdsCodeReason'] = 'Infinite scroll is enabled, ads are disabled in this mode.';
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if viewer is a bot
|
||||
if (isBot()) {
|
||||
$global['lastAdsCodeReason'] = 'Viewer is a bot, ads are not shown to bots.';
|
||||
self::debug(__LINE__);
|
||||
return false;
|
||||
}
|
||||
$videos_id = 0;
|
||||
if (empty($videos_id)) {
|
||||
|
||||
$videos_id = getVideos_id();
|
||||
if (empty($videos_id)) {
|
||||
$global['lastAdsCodeReason'] = 'No video ID found, unable to retrieve ads for specific content.';
|
||||
}
|
||||
|
||||
// Check if ADs plugin is enabled
|
||||
$ad = AVideoPlugin::getObjectDataIfEnabled('ADs');
|
||||
$adCode = '';
|
||||
if (!empty($ad)) {
|
||||
if (empty($ad)) {
|
||||
$global['lastAdsCodeReason'] = 'ADs plugin is disabled, ads cannot be displayed without this plugin.';
|
||||
return false;
|
||||
}
|
||||
|
||||
// Determine if ads should be shown on video player page
|
||||
$showOnVideoPlayerPage = true;
|
||||
eval("\$showOnVideoPlayerPage = \$obj->{$type}ShowOnVideoPlayerPage;");
|
||||
// Check if ads are configured to show on the video player page for the specified ad type
|
||||
eval("\$showOnVideoPlayerPage = \$ad->{$type}ShowOnVideoPlayerPage;");
|
||||
if (!$showOnVideoPlayerPage && isVideo()) {
|
||||
$global['lastAdsCodeReason'] = 'Ads are configured not to show on the video player page for this ad type. '
|
||||
. '<br>To enable ads here, go to the Ads plugin settings and set the parameter '
|
||||
. "{$type}ShowOnVideoPlayerPage to true if you want to display ads on the video page.";
|
||||
return false;
|
||||
}
|
||||
self::debug(__LINE__);
|
||||
|
||||
// Adjust ad type for mobile if applicable
|
||||
if (isMobile()) {
|
||||
$type = $type . 'Mobile';
|
||||
$type .= 'Mobile';
|
||||
}
|
||||
|
||||
// Retrieve ads based on user ID or video ID
|
||||
$users_id = getUsers_idOwnerFromRequest();
|
||||
//var_dump($users_id);exit;
|
||||
$adC = self::getAdsFromUsersId($type, $users_id);
|
||||
if (_empty($adC['adCode'])) {
|
||||
self::debug(__LINE__);
|
||||
$adC = self::getAdsHTML($type);
|
||||
if (!_empty($adC['html'])) {
|
||||
return $adC['html'];
|
||||
} else {
|
||||
$global['lastAdsCodeReason'] = 'No ad code found for this content type and user ID.';
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
self::debug(__LINE__);
|
||||
}
|
||||
|
||||
// Finalize ad code if found, adding label and Google timeout if applicable
|
||||
$adCode = ADs::giveGoogleATimeout($adC['adCode']);
|
||||
$adCode = ADs::addLabel($adCode, $adC['label']);
|
||||
}
|
||||
$global['lastAdsCodeReason'] = 'Ad code successfully generated.';
|
||||
self::debug(__LINE__);
|
||||
|
||||
return $adCode;
|
||||
}
|
||||
|
||||
|
||||
public static function getAdsCodeReason($type)
|
||||
{
|
||||
$reasons = array();
|
||||
|
@ -433,7 +462,7 @@ class ADs extends PluginAbstract
|
|||
// Get the video ID, if available
|
||||
$videos_id = getVideos_id();
|
||||
if (empty($videos_id)) {
|
||||
$reasons[] = 'No video ID found, this might prevent ads from displaying.';
|
||||
$reasons[] = 'No video ID found';
|
||||
} else {
|
||||
$reasons[] = 'Video ID detected: ' . $videos_id;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue