Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yiannistaos/5c255bd3c058c219d13dbd98a7614a7a to your computer and use it in GitHub Desktop.
Save Yiannistaos/5c255bd3c058c219d13dbd98a7614a7a to your computer and use it in GitHub Desktop.
How to block youtube, vimeo, and other cookies from video providers by using the Cookies Policy Notification Bar Joomla! plugin, and the AllVideos Joomla! plugin.
<?php
/**
* @version 6.1.0
* @package AllVideos (plugin)
* @author JoomlaWorks - https://www.joomlaworks.net
* @copyright Copyright (c) 2006 - 2020 JoomlaWorks Ltd. All rights reserved.
* @license GNU/GPL license: https://www.gnu.org/copyleft/gpl.html
* This AllVideos template is compatible with the Cookies Policy Notification Bar - Joomla! plugin by Web357.com
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
// BEGIN: Check if Cookies are accepted from the User (Compatible with Cookies Policy Notification Bar - Joomla! plugin by Web357.com)
// get cookies from browser
$jcookies = JFactory::getApplication()->input->cookie->getArray(); // $_COOKIE
// get plugin's parameters
jimport('joomla.plugin.helper');
$cookiespolicynotificationbar = JPluginHelper::getPlugin('system', 'cookiespolicynotificationbar');
$cpnb_params = new JRegistry($cookiespolicynotificationbar->params);
$cpnb_cookie_name = $cpnb_params->get('cookie_name', 'cookiesDirective');
// Block video cookies from specific categories
# $cpnb_specific_cookie_category_name_to_be_blocked = 'video-cookies';
# $cpnb_cookiesSettings = $jcookies['cpnb_cookiesSettings'];
# $cpnb_cookiesSettings_arr = json_decode($cpnb_cookiesSettings, true);
# $cpnb_specific_cookies_category_accepted = $cpnb_cookiesSettings_arr[$cpnb_specific_cookie_category_name_to_be_blocked];
if (isset($jcookies[$cpnb_cookie_name]))
# if (isset($jcookies[$cpnb_cookie_name]) && $cpnb_specific_cookies_category_accepted)
{
$cookies_accepted = true;
}
else
{
$cookies_accepted = false;
}
// END: Check if Cookies are accepted from the User
?>
<?php if ($cookies_accepted === FALSE): ?>
<div class="cpnb-accept-first-message">
<p><?php echo JText::_('The video cannot be displayed because you have to accept the cookies first.'); ?></p>
</div>
<?php endif; ?>
<?php if ($cookies_accepted === TRUE): ?>
<div class="avPlayerWrapper<?php echo $output->mediaTypeClass; ?>">
<div class="avPlayerContainer"<?php echo $maxwidth; ?>>
<div id="<?php echo $output->playerID; ?>" class="avPlayerBlock">
<?php echo $output->player; ?>
</div>
<?php if (($allowVideoDownloading && $output->mediaType == 'video') || ($allowAudioDownloading && $output->mediaType == 'audio')): ?>
<div class="avDownloadLink">
<a target="_blank" href="<?php echo $output->source; ?>" download><?php echo JText::_('JW_PLG_AV_DOWNLOAD'); ?></a>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
@raramuridesign
Copy link

@Yiannistaos
I just wanted to point out that JoomlaWorks has enabled a privacy mode switch in the latest version.
Its using the co-cookie domain from Youtube.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment