1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00

Now the shorts AI can create portrait and square shorts

This commit is contained in:
Daniel Neto 2024-03-13 10:52:15 -03:00
parent df4b4436c1
commit 24539738ed
15 changed files with 333 additions and 185 deletions

View file

@ -128,16 +128,12 @@ class Page {
$rtl = 'rtl'; $rtl = 'rtl';
} }
echo "<body class=\"{$global['bodyClass']} {$rtl} {$this->bodyClass}\">"; echo "<body class=\"{$global['bodyClass']} {$rtl} {$this->bodyClass}\">";
//echo '<div id="_avideoPageLoader">';
//$loaderParts = Layout::getLoaderDefault();
//echo $loaderParts['css'];
//echo $loaderParts['html'];
//echo '</div>';
//echo '<div style="display: none;" id="_avideoPageContent">';
$this->getNavBar(); $this->getNavBar();
echo $this->bodyContent; //echo '<div id="_avideoPageContentLoading" class="progress"><div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%"><span class="sr-only">Loading...</span></div></div>';
$this->getFooter(); //echo '<div id="_avideoPageContent">';
echo $this->bodyContent;
//echo '</div>'; //echo '</div>';
$this->getFooter();
echo "</body>"; echo "</body>";
} }

View file

@ -1,36 +1,69 @@
<?php <?php
function cutVideoWithFFmpeg($inputFile, $startTimeInSeconds, $endTimeInSeconds, $outputFile)
function cutVideoWithFFmpeg($inputFile, $startTimeInSeconds, $endTimeInSeconds, $outputFile, $aspectRatio)
{ {
// Ensure start and end times are numeric // Ensure start and end times are numeric
$startTimeInSeconds = (int)$startTimeInSeconds; $startTimeInSeconds = (int)$startTimeInSeconds;
$endTimeInSeconds = (int)$endTimeInSeconds; $endTimeInSeconds = (int)$endTimeInSeconds;
// Define aspect ratio dimensions
$aspectRatioDimensions = [
Video::ASPECT_RATIO_ORIGINAL,
Video::ASPECT_RATIO_SQUARE,
Video::ASPECT_RATIO_VERTICAL,
Video::ASPECT_RATIO_HORIZONTAL,
];
// Validate aspect ratio parameter
if (!in_array($aspectRatio, $aspectRatioDimensions)) {
_error_log('cutVideoWithFFmpeg: Invalid aspect ratio parameter');
return false;
}
make_path($outputFile); make_path($outputFile);
// Use ffprobe to get video dimensions
$ffprobeCommand = get_ffprobe()." -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 {$inputFile}";
$ffprobeCommand = removeUserAgentIfNotURL($ffprobeCommand);
_error_log("cutAndAdaptVideoWithFFmpeg start shell_exec($ffprobeCommand)");
$videoDimensions = shell_exec($ffprobeCommand);
_error_log("cutAndAdaptVideoWithFFmpeg response ($videoDimensions)");
list($width, $height) = explode('x', trim($videoDimensions));
$cropParams = calculateCenterCrop($width, $height, $aspectRatio);
// Calculate crop dimensions
$cropDimension = "{$cropParams['newWidth']}:{$cropParams['newHeight']}:{$cropParams['x']}:{$cropParams['y']}";
// Escape arguments to ensure command is safe to execute // Escape arguments to ensure command is safe to execute
$escapedInputFile = escapeshellarg($inputFile); $escapedInputFile = escapeshellarg($inputFile);
$escapedOutputFile = escapeshellarg($outputFile); $escapedOutputFile = escapeshellarg($outputFile);
$escapedStartTime = escapeshellarg($startTimeInSeconds); $escapedStartTime = escapeshellarg($startTimeInSeconds);
$escapedEndTime = escapeshellarg($endTimeInSeconds); $escapedEndTime = escapeshellarg($endTimeInSeconds);
$escapedCropDimension = escapeshellarg($cropDimension);
// Construct the FFmpeg command // Construct the FFmpeg command
$cmd = get_ffmpeg() . " -ss {$escapedStartTime} -to {$escapedEndTime} -i {$escapedInputFile} -c copy {$escapedOutputFile}"; $cmd = get_ffmpeg() . " -ss {$escapedStartTime} -to {$escapedEndTime} -i {$escapedInputFile} -vf \"crop={$escapedCropDimension}\" -c:a copy {$escapedOutputFile}";
$cmd = removeUserAgentIfNotURL($cmd); $cmd = removeUserAgentIfNotURL($cmd);
// Execute the command // Execute the command
_error_log('cutVideoWithFFmpeg start ' . $cmd); _error_log('cutAndAdaptVideoWithFFmpeg start ' . $cmd);
exec($cmd, $output, $returnVar); exec($cmd, $output, $returnVar);
// Check if the command was executed successfully // Check if the command was executed successfully
if ($returnVar === 0) { if ($returnVar === 0) {
_error_log('cutVideoWithFFmpeg success ' . $outputFile); _error_log('cutAndAdaptVideoWithFFmpeg success ' . $outputFile);
return true; // Command executed successfully return true; // Command executed successfully
} else { } else {
_error_log('cutVideoWithFFmpeg error '); _error_log('cutAndAdaptVideoWithFFmpeg error ');
return false; // Command failed return false; // Command failed
} }
} }
function getDurationFromFile($file) function getDurationFromFile($file)
{ {
global $config, $getDurationFromFile; global $config, $getDurationFromFile;

View file

@ -7107,7 +7107,7 @@ function get_ffprobe() {
function removeUserAgentIfNotURL($cmd) function removeUserAgentIfNotURL($cmd)
{ {
if (!preg_match('/ -i [\'"]?https?:/', $cmd)) { if (!preg_match('/ -i [\'"]?https?:/i', $cmd) && !preg_match('/ffprobe.*[\'"]?https?:/i', $cmd)) {
$cmd = preg_replace('/-user_agent "[^"]+"/', '', $cmd); $cmd = preg_replace('/-user_agent "[^"]+"/', '', $cmd);
} }
return $cmd; return $cmd;
@ -10212,6 +10212,46 @@ function checkFileModified($filePath) {
} }
} }
function calculateCenterCrop($originalWidth, $originalHeight, $aspectRatio) {
// Define aspect ratio dimensions
$aspectRatioDimensions = [
Video::ASPECT_RATIO_SQUARE => ['width' => 1, 'height' => 1],
Video::ASPECT_RATIO_VERTICAL => ['width' => 9, 'height' => 16],
Video::ASPECT_RATIO_HORIZONTAL => ['width' => 16, 'height' => 9],
];
// Validate aspect ratio parameter
if (!array_key_exists($aspectRatio, $aspectRatioDimensions)) {
return false; // Invalid aspect ratio
}
// Get aspect ratio dimensions
$targetWidth = $aspectRatioDimensions[$aspectRatio]['width'];
$targetHeight = $aspectRatioDimensions[$aspectRatio]['height'];
// Calculate scaling factors for width and height
$scaleWidth = $originalHeight * $targetWidth / $targetHeight;
$scaleHeight = $originalWidth * $targetHeight / $targetWidth;
// Determine new width, height, x, and y for center cropping
if ($scaleWidth > $originalWidth) {
// Use scaled height
$newWidth = $originalWidth;
$newHeight = $scaleHeight;
$x = 0;
$y = ($originalHeight - $scaleHeight) / 2;
} else {
// Use scaled width
$newWidth = $scaleWidth;
$newHeight = $originalHeight;
$x = ($originalWidth - $scaleWidth) / 2;
$y = 0;
}
return ['newWidth' => $newWidth, 'newHeight' => $newHeight, 'x' => $x, 'y' => $y];
}
require_once __DIR__.'/functionSecurity.php'; require_once __DIR__.'/functionSecurity.php';
require_once __DIR__.'/functionMySQL.php'; require_once __DIR__.'/functionMySQL.php';
require_once __DIR__.'/functionDocker.php'; require_once __DIR__.'/functionDocker.php';

View file

@ -143,6 +143,11 @@ if (!class_exists('Video')) {
public static $urlTypeShort = 'URLShort'; public static $urlTypeShort = 'URLShort';
private $categoryWasChanged = false; private $categoryWasChanged = false;
const ASPECT_RATIO_ORIGINAL = '';
const ASPECT_RATIO_SQUARE = '1:1';
const ASPECT_RATIO_VERTICAL = '9:16';
const ASPECT_RATIO_HORIZONTAL = '16:9';
public function __construct($title = "", $filename = "", $id = 0, $refreshCache = false) public function __construct($title = "", $filename = "", $id = 0, $refreshCache = false)
{ {
global $global; global $global;
@ -6479,7 +6484,7 @@ if (!class_exists('Video')) {
$a = '<a videos_id="' . $videos_id . '" $a = '<a videos_id="' . $videos_id . '"
href="' . $href . '" href="' . $href . '"
embed="' . $embed . '" embed="' . $embed . '"
title="' . $title . '" alternativeLink="' . $alternativeLink . '">'; title="' . $title . '" alternativeLink="' . $alternativeLink . '" class="ajaxLoad">';
if ($addLink) { if ($addLink) {
$img = $a . $img . '</a>'; $img = $a . $img . '</a>';
} }

View file

@ -573,6 +573,11 @@ class AI extends PluginAbstract
if (preg_match('/[0-9]{2}:[0-9]{2}:[0-9]{2}/i', $obj->startTimeInSeconds)) { if (preg_match('/[0-9]{2}:[0-9]{2}:[0-9]{2}/i', $obj->startTimeInSeconds)) {
$obj->startTimeInSeconds = durationToSeconds($obj->startTimeInSeconds); $obj->startTimeInSeconds = durationToSeconds($obj->startTimeInSeconds);
} }
$aspectRatio = Video::ASPECT_RATIO_HORIZONTAL;
if(!empty($obj->aspectRatio)){
$aspectRatio = $obj->aspectRatio;
}
_error_log('AI:videoCut start ' . $ai->getJson() . "{$obj->startTimeInSeconds} => {$obj->endTimeInSeconds}"); _error_log('AI:videoCut start ' . $ai->getJson() . "{$obj->startTimeInSeconds} => {$obj->endTimeInSeconds}");
$vid = Video::getVideoLight($obj->videos_id); $vid = Video::getVideoLight($obj->videos_id);
$sources = getVideosURLOnly($vid['filename'], false); $sources = getVideosURLOnly($vid['filename'], false);
@ -591,7 +596,7 @@ class AI extends PluginAbstract
if (!empty($newVideos_id)) { if (!empty($newVideos_id)) {
_error_log('AI:videoCut new video saved videos_id=' . $newVideos_id); _error_log('AI:videoCut new video saved videos_id=' . $newVideos_id);
$outputFile = Video::getPathToFile("{$videoFileName}.mp4"); $outputFile = Video::getPathToFile("{$videoFileName}.mp4");
cutVideoWithFFmpeg($source['url'], $obj->startTimeInSeconds, $obj->endTimeInSeconds, $outputFile); cutVideoWithFFmpeg($source['url'], $obj->startTimeInSeconds, $obj->endTimeInSeconds, $outputFile, $aspectRatio);
$video = new Video('', '', $newVideos_id); $video = new Video('', '', $newVideos_id);
if (file_exists($outputFile)) { if (file_exists($outputFile)) {

View file

@ -35,8 +35,10 @@ $obj->videos_id = $videos_id;
$obj->startTimeInSeconds = $_REQUEST['startTimeInSeconds']; $obj->startTimeInSeconds = $_REQUEST['startTimeInSeconds'];
$obj->endTimeInSeconds = $_REQUEST['endTimeInSeconds']; $obj->endTimeInSeconds = $_REQUEST['endTimeInSeconds'];
$obj->users_id = User::getId(); $obj->users_id = User::getId();
$obj->title = $_REQUEST['title'];
$obj->description = $_REQUEST['description']; $obj->description = $_REQUEST['description'];
$obj->aspectRatio = empty($_REQUEST['aspectRatio'])? Video::ASPECT_RATIO_HORIZONTAL:$_REQUEST['aspectRatio'];
$obj->title = $obj->aspectRatio.' '.$_REQUEST['title'];
//$obj->title = $_REQUEST['title'];
$ai = new Ai_scheduler(0); $ai = new Ai_scheduler(0);
$ai->setAi_scheduler_type(Ai_scheduler::$typeCutVideo); $ai->setAi_scheduler_type(Ai_scheduler::$typeCutVideo);

View file

@ -28,6 +28,6 @@
if (typeof loadAIUsage == 'function') { if (typeof loadAIUsage == 'function') {
loadAIUsage(); loadAIUsage();
} }
avideoToastSuccess('AI '+json.type+" received"); avideoToastSuccess('AI ' + json.type + ' received');
} }
</script> </script>

View file

@ -59,7 +59,10 @@ function getShortsButtons($key)
global $bookmark; global $bookmark;
$buttons = array(); $buttons = array();
$buttons[] = '<button class="btn btn-primary" onclick="playVideoSegmentFromIndex(' . $key . ');" data-toggle="tooltip" title="' . __('Play') . '" type="button"><i class="fa-solid fa-play"></i></button>'; $buttons[] = '<button class="btn btn-primary" onclick="playVideoSegmentFromIndex(' . $key . ');" data-toggle="tooltip" title="' . __('Play') . '" type="button"><i class="fa-solid fa-play"></i></button>';
$buttons[] = '<button class="btn btn-success" onclick="submitVideoForm(' . $key . ');" data-toggle="tooltip" title="' . __('Save Cut') . '" type="button"><i class="fa-solid fa-scissors"></i></button>'; $buttons[] = '<button class="btn btn-success" onclick="submitVideoForm(' . $key . ', \''.Video::ASPECT_RATIO_ORIGINAL.'\');" data-toggle="tooltip" title="' . __('Save Cut Original') . '" type="button"><i class="fa-solid fa-scissors"></i></button>';
$buttons[] = '<button class="btn btn-success" onclick="submitVideoForm(' . $key . ', \''.Video::ASPECT_RATIO_HORIZONTAL.'\');" data-toggle="tooltip" title="' . __('Save Cut Horizontal') . '" type="button"><i class="fa-solid fa-desktop"></i></button>';
$buttons[] = '<button class="btn btn-success" onclick="submitVideoForm(' . $key . ', \''.Video::ASPECT_RATIO_VERTICAL.'\');" data-toggle="tooltip" title="' . __('Save Cut Vertical') . '" type="button"><i class="fa-solid fa-mobile-screen-button"></i></button>';
$buttons[] = '<button class="btn btn-success" onclick="submitVideoForm(' . $key . ', \''.Video::ASPECT_RATIO_SQUARE.'\');" data-toggle="tooltip" title="' . __('Save Cut Square') . '" type="button"><i class="fa-regular fa-square-full"></i></button>';
if ($bookmark) { if ($bookmark) {
$buttons[] = '<button class="btn btn-warning" onclick="bookmarkFromIndex(' . $key . ');" data-toggle="tooltip" title="' . __('Bookmark') . '" type="button"><i class="fa-solid fa-bookmark"></i></button>'; $buttons[] = '<button class="btn btn-warning" onclick="bookmarkFromIndex(' . $key . ');" data-toggle="tooltip" title="' . __('Bookmark') . '" type="button"><i class="fa-solid fa-bookmark"></i></button>';
} }

View file

@ -71,7 +71,7 @@ echo AVideoPlugin::afterVideoJS();
}); });
} }
function submitVideoForm(index) { function submitVideoForm(index, aspectRatio) {
modal.showPleaseWait(); modal.showPleaseWait();
var startTimeInSeconds = durationToSeconds($('#startTimeInSeconds' + index).val()); var startTimeInSeconds = durationToSeconds($('#startTimeInSeconds' + index).val());
var endTimeInSeconds = durationToSeconds($('#endTimeInSeconds' + index).val()); var endTimeInSeconds = durationToSeconds($('#endTimeInSeconds' + index).val());
@ -88,7 +88,7 @@ echo AVideoPlugin::afterVideoJS();
// Perform the AJAX request // Perform the AJAX request
$.ajax({ $.ajax({
url: webSiteRootURL + 'plugin/AI/cutVideo.json.php', // Replace with your server endpoint url: webSiteRootURL + 'plugin/AI/cutVideo.json.php?aspectRatio='+aspectRatio, // Replace with your server endpoint
type: 'POST', type: 'POST',
data: formData, data: formData,
success: function(response) { success: function(response) {

View file

@ -100,7 +100,7 @@ if (empty($MediaMetadata)) {
} else if (mediaId) { } else if (mediaId) {
videos_id = mediaId; videos_id = mediaId;
console.log('updateMediaSessionMetadata mediaId', mediaId); console.log('updateMediaSessionMetadata mediaId', mediaId);
} else if (isLive) { } else if (typeof isLive !== 'undefined' && isLive) {
key = isLive.key; key = isLive.key;
live_servers_id = isLive.live_servers_id; live_servers_id = isLive.live_servers_id;
live_schedule_id = isLive.live_schedule_id; live_schedule_id = isLive.live_schedule_id;

View file

@ -31,15 +31,23 @@ function expand() {
}); });
isCompressed = false; isCompressed = false;
} }
function isCompressedVar(){
if(typeof isCompressed === 'undefined'){
return false;
}
return !empty(isCompressed);
}
function toogleEC() { function toogleEC() {
if (!empty(isCompressed)) { if (isCompressedVar()) {
expand(); expand();
} else { } else {
compress(); compress();
} }
} }
$(document).ready(function () { $(function () {
if (!empty(isCompressed)) { if (isCompressedVar()) {
compress(); compress();
} else { } else {
expand(); expand();

View file

@ -18,6 +18,21 @@ body.fullscreen {
overflow: hidden; overflow: hidden;
} }
#_avideoPageContentLoading{
display: none;
}
body._avideoPageContentLoading #_avideoPageContentLoading{
display: unset;
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 99999;
width: 100vw;
height: 5px;
}
.nopadding { .nopadding {
padding: 0 !important; padding: 0 !important;
margin: 0 !important; margin: 0 !important;
@ -2036,13 +2051,3 @@ body.ypt-is-compressed #videoCol {
.loadInfiniteScrollButton:disabled .fas.fa-angle-double-down { .loadInfiniteScrollButton:disabled .fas.fa-angle-double-down {
display: none; display: none;
} }
/*
#_avideoPageLoader{
display: none !important;
}
#_avideoPageContent{
display: unset !important;
}
*/

View file

@ -3,115 +3,120 @@ global $global, $config;
if (!isset($global['systemRootPath'])) { if (!isset($global['systemRootPath'])) {
require_once '../videos/configuration.php'; require_once '../videos/configuration.php';
} }
require_once $global['systemRootPath'] . 'plugin/AVideoPlugin.php';
$_page = new Page(array('Help'));
?> ?>
<!DOCTYPE html> <div class="container">
<html lang="<?php echo getLanguage(); ?>"> <div class="panel panel-default">
<head> <div class="panel-body">
<title><?php echo __("Help") . $config->getPageTitleSeparator() . $config->getWebSiteTitle(); ?></title> <h1><?php echo __("User-manual of");
<?php echo " ";
include $global['systemRootPath'] . 'view/include/head.php'; echo $config->getWebSiteTitle(); ?></h1>
?> <p><?php echo AVideoPlugin::getHelpToc(); ?>
</head> <ul>
<li><a href="#Videoshelp"><?php echo __('Videos'); ?></a></li>
<body class="<?php echo $global['bodyClass']; ?>"> </ul>
<?php </p>
include $global['systemRootPath'] . 'view/include/navbar.php'; <p><?php echo __('Here you can find help, how this platform works.'); ?></p>
?> <?php if (User::isAdmin()) { ?>
<h2><?php echo __('Admin\'s manual'); ?></h2>
<div class="container"> <p><?php echo __('Only you can see this, because you are a admin.'); ?></p>
<div class="panel panel-default"> <h3><?php echo __('Settings and plugins'); ?></h3>
<div class="panel-body"> <p><?php echo __('The default'); ?> <a href='<?php echo $global['webSiteRootURL']; ?>siteConfigurations'><?php echo __('site config'); ?></a>, <?php echo __('you can find on the menu-point. But there are more settings avaible; go to the'); ?> <a href='<?php echo $global['webSiteRootURL']; ?>plugins'><?php echo __('plugins'); ?></a> <?php echo __('and check the'); ?> "CustomiseAdvanced"<?php echo __('-Plugin'); ?>.</p>
<h1><?php echo __("User-manual of"); <p><?php echo __('Like on a lot of plugins, on the right site, you will find a button'); ?> "<i class="fa-solid fa-pen-to-square"></i><?php echo __('Edit parameters'); ?>". <?php echo __('This button is always a click worth'); ?>.</p>
echo " "; <p><?php echo __('Also, when you activate a plugin and you see a button "Install Tables", press it at least once, if you never press it, this can cause bugs!'); ?></p>
echo $config->getWebSiteTitle(); ?></h1> <hr />
<p><?php echo AVideoPlugin::getHelpToc(); ?> <h3><?php echo __('Update via git'); ?></h3>
<ul> <p><?php echo __('This project is in a fast development. If you have done your setup via git (like in the howto\'s), you can update very easy!'); ?></p>
<li><a href="#Videos help"><?php echo __('Videos'); ?></a></li> <p><?php echo __('In the shell, go to the avideo-folder and type "git pull" there. Or, for copy-paste'); ?>: <code>cd <?php echo $global['systemRootPath']; ?>; git pull</code> . </p>
</ul> <p><?php echo __('It can be, that you will need a database-update after. For this, go as admin to the menu-point'); ?> "<a href='<?php echo $global['webSiteRootURL']; ?>update'><?php echo __('Update version'); ?></a>".</p>
</p> <p><?php echo __('Done'); ?>!</p>
<p><?php echo __('Here you can find help, how this platform works.'); ?></p> <hr />
<?php if (User::isAdmin()) { ?> <h3><?php echo __('Update via ftp/files'); ?></h3>
<h2><?php echo __('Admin\'s manual'); ?></h2> <p><?php echo __('Download this file'); ?>: <a href="https://github.com/WWBN/AVideo/archive/master.zip">github.com/DanielnetoDotCom/AVideo/archive/master.zip</a> (<?php echo __('always the newest'); ?>).</p>
<p><?php echo __('Only you can see this, because you are a admin.'); ?></p> <p><?php echo __('Unzip and upload/replace the'); ?> <b><?php echo __('all'); ?></b> <?php echo __('the files. Only the videos-folder should stay untouched.'); ?></p>
<h3><?php echo __('Settings and plugins'); ?></h3> <p><?php echo __('It can be, that you will need a database-update after. For this, go as admin to the menu-point'); ?> "<a href='<?php echo $global['webSiteRootURL']; ?>update'><?php echo __('Update version'); ?></a>".</p>
<p><?php echo __('The default'); ?> <a href='<?php echo $global['webSiteRootURL']; ?>siteConfigurations'><?php echo __('site config'); ?></a>, <?php echo __('you can find on the menu-point. But there are more settings avaible; go to the'); ?> <a href='<?php echo $global['webSiteRootURL']; ?>plugins'><?php echo __('plugins'); ?></a> <?php echo __('and check the'); ?> "CustomiseAdvanced"<?php echo __('-Plugin'); ?>.</p> <p><?php echo __('Done'); ?>!</p>
<p><?php echo __('Like on a lot of plugins, on the right site, you will find a button'); ?> "<i class="fa-solid fa-pen-to-square"></i><?php echo __('Edit parameters'); ?>". <?php echo __('This button is always a click worth'); ?>.</p> <hr />
<p><?php echo __('Also, when you activate a plugin and you see a button "Install Tables", press it at least once, if you never press it, this can cause bugs!'); ?></p> <h3><?php echo __('Issues on github'); ?></h3>
<hr /> <p><?php echo __('If you want to tell us, what is not working for you, this is great and helps us, to make the software more stable.'); ?></p>
<h3><?php echo __('Update via git'); ?></h3> <p><?php echo __('Some information can help us, to find your problem faster'); ?>:</p>
<p><?php echo __('This project is in a fast development. If you have done your setup via git (like in the howto\'s), you can update very easy!'); ?></p> <ul>
<p><?php echo __('In the shell, go to the avideo-folder and type "git pull" there. Or, for copy-paste'); ?>: <code>cd <?php echo $global['systemRootPath']; ?>; git pull</code> . </p> <li><?php echo __('Content of'); ?> <a href='<?php echo $global['webSiteRootURL']; ?>videos/avideo.log'>videos/avideo.log</a></li>
<p><?php echo __('It can be, that you will need a database-update after. For this, go as admin to the menu-point'); ?> "<a href='<?php echo $global['webSiteRootURL']; ?>update'><?php echo __('Update version'); ?></a>".</p> <li><?php echo __('Content of'); ?> <a href='<?php echo $global['webSiteRootURL']; ?>videos/avideo.js.log'>videos/avideo.js.log</a></li>
<p><?php echo __('Done'); ?>!</p> <li><?php echo __('If public: your domain, so we can see the error directly'); ?></li>
<hr /> </ul>
<h3><?php echo __('Update via ftp/files'); ?></h3> <p><?php echo __('If you can, clear the log-files, reproduce the error and send them. This helps to reduce old or repeating information.'); ?></p>
<p><?php echo __('Download this file'); ?>: <a href="https://github.com/WWBN/AVideo/archive/master.zip">github.com/DanielnetoDotCom/AVideo/archive/master.zip</a> (<?php echo __('always the newest'); ?>).</p> <hr />
<p><?php echo __('Unzip and upload/replace the'); ?> <b><?php echo __('all'); ?></b> <?php echo __('the files. Only the videos-folder should stay untouched.'); ?></p> <?php } ?>
<p><?php echo __('It can be, that you will need a database-update after. For this, go as admin to the menu-point'); ?> "<a href='<?php echo $global['webSiteRootURL']; ?>update'><?php echo __('Update version'); ?></a>".</p> <h2 id='Videoshelp'><?php echo __('Videos'); ?></h2>
<p><?php echo __('Done'); ?>!</p> <p><?php echo __('Here you find information about how to handle videos.'); ?></p>
<hr /> <h3><?php echo __('Add videos'); ?></h3>
<h3><?php echo __('Issues on github'); ?></h3> <p><?php echo __('There are various kinds of media you can integrate here. They are working different'); ?>:</p>
<p><?php echo __('If you want to tell us, what is not working for you, this is great and helps us, to make the software more stable.'); ?></p> <table class='table'>
<p><?php echo __('Some information can help us, to find your problem faster'); ?>:</p> <ul><li><?php echo __('Content of'); ?> <a href='<?php echo $global['webSiteRootURL']; ?>videos/avideo.log'>videos/avideo.log</a></li><li><?php echo __('Content of'); ?> <a href='<?php echo $global['webSiteRootURL']; ?>videos/avideo.js.log'>videos/avideo.js.log</a></li><li><?php echo __('If public: your domain, so we can see the error directly'); ?></li></ul> <thead>
<p><?php echo __('If you can, clear the log-files, reproduce the error and send them. This helps to reduce old or repeating information.'); ?></p> <tr>
<hr /> <th><?php echo __('Mediatype'); ?></th>
<?php } ?> <th><?php echo __('How to set'); ?></th>
<h2 id='Videos help'><?php echo __('Videos'); ?></h2> <th><?php echo __('Notes'); ?></th>
<p><?php echo __('Here you find information about how to handle videos.'); ?></p> </tr>
<h3><?php echo __('Add videos'); ?></h3> </thead>
<p><?php echo __('There are various kinds of media you can integrate here. They are working different'); ?>:</p> <tbody>
<table class='table'><thead><tr> <tr>
<th><?php echo __('Mediatype'); ?></th><th><?php echo __('How to set'); ?></th><th><?php echo __('Notes'); ?></th> <td><?php echo __('Audio'); ?></td>
</tr> <td><?php echo __('Via encoder or direct upload'); ?></td>
</thead><tbody> <td><?php echo __('Via encoder, most formats are possible, but you need to enable the Extract audio-option. With direct upload, only MP3 and OGG is allowed'); ?></td>
<tr><td><?php echo __('Audio'); ?></td><td><?php echo __('Via encoder or direct upload'); ?></td><td><?php echo __('Via encoder, most formats are possible, but you need to enable the Extract audio-option. With direct upload, only MP3 and OGG is allowed'); ?></td></tr> </tr>
<tr><td><?php echo __('Video'); ?></td><td><?php echo __('Via encoder or direct upload'); ?></td><td><?php echo __('Via encoder, most formats are possible. With direct upload, only MP4 is allowed'); ?></td></tr> <tr>
<tr><td><?php echo __('Embedded'); ?></td><td><?php echo __('My videos->Embed a video link->Embedded'); ?></td><td><?php echo __('Only direct mp3- or ogg-files - if you download it with the link, it should be a movie-file. No google-drive or stream-hoster. Also, do not mix https and http.'); ?></td></tr> <td><?php echo __('Video'); ?></td>
<tr><td><?php echo __('Direct audio-link (mp3 or ogg)'); ?></td><td><?php echo __('My videos->Embed a video link->Choose Direct audio-link (mp3 or ogg)'); ?></td><td><?php echo __('Only direct mp3- or ogg-files - if you download it with the link, it should be a movie-file. No google-drive or stream-hoster. Also, do not mix https and http.'); ?></td></tr> <td><?php echo __('Via encoder or direct upload'); ?></td>
<tr><td><?php echo __('Direct video-link (mp4)'); ?></td><td><?php echo __('My videos->Embed a video->Choose Direct video-link (mp4)'); ?></td><td><?php echo __('Only direct mp4-files - if you download it with the link, it should be a movie-file. No google-drive or stream-hoster. Also, do not mix https and http.'); ?></td></tr> <td><?php echo __('Via encoder, most formats are possible. With direct upload, only MP4 is allowed'); ?></td>
</tbody></table> </tr>
<hr /> <tr>
<h3><?php echo __('Edit videos'); ?></h3> <td><?php echo __('Embedded'); ?></td>
<p><?php echo __('After you add any kind of video, you can find it in'); ?> <?php echo __('My videos'); ?></p> <td><?php echo __('My videos->Embed a video link->Embedded'); ?></td>
<p><?php echo __('On the right site, you find various symbols'); ?>, <i class="fa-solid fa-pen-to-square"></i> <?php echo __('means edit'); ?>.</p> <td><?php echo __('Only direct mp3- or ogg-files - if you download it with the link, it should be a movie-file. No google-drive or stream-hoster. Also, do not mix https and http.'); ?></td>
<p><?php echo __('There, you can set'); ?></p> </tr>
<ul> <tr>
<li><?php echo __('Preview-picture and gif'); ?></li> <td><?php echo __('Direct audio-link (mp3 or ogg)'); ?></td>
<li><?php echo __('Title and description'); ?></li> <td><?php echo __('My videos->Embed a video link->Choose Direct audio-link (mp3 or ogg)'); ?></td>
<li><?php echo __('Category'); ?></li> <td><?php echo __('Only direct mp3- or ogg-files - if you download it with the link, it should be a movie-file. No google-drive or stream-hoster. Also, do not mix https and http.'); ?></td>
<li><?php echo __('Next video'); ?></li> </tr>
</ul> <tr>
<p><?php echo __('With the other options, you can delete, rotate and promote a video'); ?></p> <td><?php echo __('Direct video-link (mp4)'); ?></td>
<hr /> <td><?php echo __('My videos->Embed a video->Choose Direct video-link (mp4)'); ?></td>
<h3><?php echo __('Use a video as a ad'); ?></h3> <td><?php echo __('Only direct mp4-files - if you download it with the link, it should be a movie-file. No google-drive or stream-hoster. Also, do not mix https and http.'); ?></td>
<p><?php echo __('To use a video as a ad, go to'); ?> <?php echo __('My videos'); ?> -> <i class="fa-solid fa-pen-to-square"></i><?php echo __('Edit-symbol and enable Create an Advertising'); ?>.</p> </tr>
<p><?php echo __('After enabling this, you can directly set some options, like the name, link and active categorie for example.'); ?></p> </tbody>
<p><?php echo __('When the video is saved like this, it will show up under the menu-point'); ?> <?php echo __('Video Advertising'); ?><?php echo __(', where you can edit the ad-options'); ?>.</p> </table>
<hr />
<h3><?php echo __('Edit videos'); ?></h3>
<p><?php echo __('After you add any kind of video, you can find it in'); ?> <?php echo __('My videos'); ?></p>
<p><?php echo __('On the right site, you find various symbols'); ?>, <i class="fa-solid fa-pen-to-square"></i> <?php echo __('means edit'); ?>.</p>
<p><?php echo __('There, you can set'); ?></p>
<ul>
<li><?php echo __('Preview-picture and gif'); ?></li>
<li><?php echo __('Title and description'); ?></li>
<li><?php echo __('Category'); ?></li>
<li><?php echo __('Next video'); ?></li>
</ul>
<p><?php echo __('With the other options, you can delete, rotate and promote a video'); ?></p>
<hr />
<h3><?php echo __('Use a video as a ad'); ?></h3>
<p><?php echo __('To use a video as a ad, go to'); ?> <?php echo __('My videos'); ?> -> <i class="fa-solid fa-pen-to-square"></i><?php echo __('Edit-symbol and enable Create an Advertising'); ?>.</p>
<p><?php echo __('After enabling this, you can directly set some options, like the name, link and active categorie for example.'); ?></p>
<p><?php echo __('When the video is saved like this, it will show up under the menu-point'); ?> <?php echo __('Video Advertising'); ?><?php echo __(', where you can edit the ad-options'); ?>.</p>
<?php <?php
echo AVideoPlugin::getHelp(); echo AVideoPlugin::getHelp();
?> ?>
</div> </div>
</div> </div>
</div><!--/.container--> </div><!--/.container-->
<?php
include $global['systemRootPath'] . 'view/include/footer.php';
?>
<script>
$(document).ready(function () {
});
</script>
</body>
</html>
<?php <?php
include $global['systemRootPath'].'objects/include_end.php'; $_page->print();
?> ?>

View file

@ -23,7 +23,7 @@
</div> </div>
</li> </li>
<li style="width: 100%; text-align: center;"> <li style="width: 100%; text-align: center;">
<a class="navbar-brand" id="mainNavbarLogo" href="<?php echo empty($advancedCustom->logoMenuBarURL) ? getHomePageURL() : $advancedCustom->logoMenuBarURL; ?>"> <a class="navbar-brand ajaxLoad" id="mainNavbarLogo" href="<?php echo empty($advancedCustom->logoMenuBarURL) ? getHomePageURL() : $advancedCustom->logoMenuBarURL; ?>">
<img src="<?php echo getURL($config->getLogo()); ?>" alt="<?php echo str_replace('"', '', $config->getWebSiteTitle()); ?>" class="img-responsive " width="250" height="70"> <img src="<?php echo getURL($config->getLogo()); ?>" alt="<?php echo str_replace('"', '', $config->getWebSiteTitle()); ?>" class="img-responsive " width="250" height="70">
<?php <?php
if (isFirstPage()) { if (isFirstPage()) {

View file

@ -1,30 +1,59 @@
/*experimental load page*/ /*experimental load page*/
// 1. Query a URL and process its contents // 1. Query a URL and process its contents
// Modified queryAndProcessURL function to execute replaceInlineJS after all scripts are loaded
function queryAndProcessURL(url) { function queryAndProcessURL(url) {
var urlA = addQueryStringParameter(url, 'avideoIframe', 1); if ($('#_avideoPageContent').length) {
$.ajax({ $('body').addClass('_avideoPageContentLoading');
url: urlA, console.log('a.ajaxLoad _avideoPageContent is present locally');
type: 'GET', var urlA = addQueryStringParameter(url, 'avideoIframe', 1);
success: function (response) { $.ajax({
// Assuming response is the full HTML of the page url: urlA,
const tempDiv = $('<div></div>').html(response); type: 'GET',
success: function (response) {
// Assuming response is the full HTML of the page
const tempDiv = $('<div></div>').html(response);
// 2. Add new CSS files if (!tempDiv.find('#_avideoPageContent').length) {
addNewCSSFiles(tempDiv); console.log('a.ajaxLoad _avideoPageContent NOT is present remotely');
document.location = url;
} else {
console.log('a.ajaxLoad _avideoPageContent is present remotely');
// 3. Replace .principalContainer HTML // When all scripts are loaded, execute replaceInlineJS
replacePrincipalContainer(tempDiv); addNewScriptFiles(tempDiv).done(function () {
// Only execute replaceInlineJS if replacePrincipalContainer was successful
const replaceResult = replacePrincipalContainer(tempDiv);
if(replaceResult){
// Add new CSS files
addNewCSSFiles(tempDiv);
// Change the page title
changePageTitle(tempDiv);
// Replace all <meta> tags
replaceMetaTags(tempDiv);
// 7. Change the page title replaceInlineJS(tempDiv);
changePageTitle(tempDiv);
makeAjaxLoad();
// Change the current URL (using the History API for SPA behavior)
history.pushState({}, '', url);
}else{
console.log('a.ajaxLoad replacePrincipalContainer fail');
document.location = url;
}
$('body').removeClass('_avideoPageContentLoading');
});
// 8. Replace all <meta> tags }
replaceMetaTags(tempDiv);
}
// 9. Change the current URL (using the History API for SPA behavior) });
history.pushState({}, '', url); } else {
} console.log('a.ajaxLoad _avideoPageContent is NOT present locally');
}); document.location = url;
}
} }
// Add new CSS files that are not already present // Add new CSS files that are not already present
@ -41,46 +70,47 @@ function addNewCSSFiles(tempDiv) {
// Replace the .principalContainer HTML or the entire body's content // Replace the .principalContainer HTML or the entire body's content
function replacePrincipalContainer(tempDiv) { function replacePrincipalContainer(tempDiv) {
// Clone the #mainNavBar to re-insert it later // Check if #_avideoPageContent exists in the tempDiv
var mainNavBarClone = $('#mainNavBar').clone(); const newPrincipalContainer = tempDiv.find('#_avideoPageContent').html();
// Check for .principalContainer in the response
const newPrincipalContainer = tempDiv.find('.principalContainer').html();
if (newPrincipalContainer) { if (newPrincipalContainer) {
console.log('replacePrincipalContainer principalContainer'); // Replace the content of #_avideoPageContent with newPrincipalContainer
$('.principalContainer').html(newPrincipalContainer); $('#_avideoPageContent').html(newPrincipalContainer);
} else {
// If no .principalContainer, replace the body's content directly // Clone body classes from tempDiv and replace existing body classes
console.log('replacePrincipalContainer with direct response'); // const tempBodyClasses = tempDiv.find('body').attr('class');
document.body.innerHTML = tempDiv.find('body').html(); // Use .html() on tempDiv directly //$('body').attr('class', tempBodyClasses);
// Prepend the cloned #mainNavBar to the body or to a specific container within the body // Continue with additional operations
//$('body').prepend(mainNavBarClone); // 4. Add new script files
addNewScriptFiles(tempDiv);
// 5. Replace inline CSS
replaceInlineCSS(tempDiv);
// 6. Replace inline JS
replaceInlineJS(tempDiv);
return true;
} }
return false;
// Continue with additional operations
// 4. Add new script files
//addNewScriptFiles(tempDiv);
// 5. Replace inline CSS
//replaceInlineCSS(tempDiv);
// 6. Replace inline JS
//replaceInlineJS(tempDiv);
} }
// Add new script files that are not already present
function addNewScriptFiles(tempDiv) { function addNewScriptFiles(tempDiv) {
const promises = [];
$('script[src]').each(function () { $('script[src]').each(function () {
const currentSrc = $(this).attr('src'); const currentSrc = $(this).attr('src');
tempDiv.find('script[src]').each(function () { tempDiv.find('script[src]').each(function () {
if (currentSrc !== $(this).attr('src') && !$('body').find(`script[src="${$(this).attr('src')}"]`).length) { if (currentSrc !== $(this).attr('src') && !$('body').find(`script[src="${$(this).attr('src')}"]`).length) {
// Load script asynchronously and push the promise to the promises array
const promise = $.getScript($(this).attr('src'));
promises.push(promise);
$('body').append($(this).clone()); $('body').append($(this).clone());
} }
}); });
}); });
// Return a promise that resolves when all scripts are loaded
return $.when.apply($, promises);
} }
// Replace inline CSS // Replace inline CSS
@ -108,3 +138,19 @@ function replaceMetaTags(tempDiv) {
$('head').append($(this).clone()); $('head').append($(this).clone());
}); });
} }
function makeAjaxLoad(){
// Bind function to all <a> tags with class .ajaxLoad
$('a.ajaxLoad').each(function () {
$(this).on('click', function (event) {
event.preventDefault(); // Prevent default click action
console.log('a.ajaxLoad clicked');
var url = $(this).attr('href');
queryAndProcessURL(url);
});
});
}
$(function () {
makeAjaxLoad();
});