Your IP : 216.73.216.240
<?php
/**
* @package VM OG Meta Tag - System Plugin
* @copyright Copyright (C) 2012-2024 VirtuePlanet Services LLP. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @author Abhishek Das <info@virtueplanet.com>
* @link https://www.virtueplanet.com
*
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* VM OG Meta Tag Helper class
*
* Compatible with Joomla! 3, Joomla! 4 and Joomla! 5
*
* @since 4.0
*/
class PlgSystemVmogmetatagHelper
{
protected $app;
protected $params;
protected $excluded;
protected $fallbackTitle = '';
protected $fallbackDescription = '';
protected $product;
protected $productCategory;
protected $content = array();
protected $contentParams = array();
protected $tags = array();
protected static $instance = null;
/**
* Constructor method.
*
* @param \Joomla\CMS\Application\CMSApplication $app
* @param \Joomla\Registry\Registry $params
*
* @return void
*/
public function __construct($app, &$params)
{
$this->app = $app;
$this->params = $params;
}
public function __get($property)
{
if (!property_exists($this, $property)) {
$method = 'get' . ucfirst(strtolower($property));
if (method_exists($this, $method)) {
return call_user_func(array($this, $method));
}
$trace = debug_backtrace();
trigger_error('Undefined property via __get(): ' . $property . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
return null;
}
return $this->{$property};
}
public static function getInstance($app, &$params)
{
if (self::$instance === null) {
self::$instance = new self($app, $params);
}
return self::$instance;
}
public function getOption()
{
return strtolower($this->app->input->getCmd('option', ''));
}
public function getView()
{
return strtolower($this->app->input->getCmd('view', ''));
}
public function getTask()
{
$input = $this->app->input;
$task = $input->post->getCmd('task', '') ? strtolower($input->post->getCmd('task', '')) : $input->getCmd('task', '');
return strtolower($task);
}
public function getTmpl()
{
return strtolower($this->app->input->getCmd('tmpl', ''));
}
public function getLayout()
{
return strtolower($this->app->input->getCmd('layout', ''));
}
/**
* Method to check if application is administration
*
* @return void
*/
public function isAdmin()
{
return version_compare(JVERSION, '3.7.0', 'ge') ? $this->app->isClient('administrator') : $this->app->isAdmin();
}
/**
* Method to check if we are in a HTML page
*
* @return boolean
*/
public function isHTML()
{
$input = $this->app->input;
$document = JFactory::getDocument();
$isFeed = ($document->getType() == 'feed' || $input->getWord('format') == 'feed' || $input->getWord('type') == 'rss' || $input->getWord('type') == 'atom');
$isHTML = ($document->getType() == 'html' && !$isFeed);
return $isHTML;
}
/**
* Method to know if the current view needs to be excluded
*
* @return boolean True if the view needs to be excluded
*/
public function isExcluded()
{
if ($this->excluded !== null) {
return $this->excluded;
}
$this->excluded = false;
$items = (array) $this->params->get('excludes', array());
if (!empty($items)) {
if (is_string($items)) {
if (strpos($items, ',')) {
$items = explode(',', $items);
$items = array_map('trim', $items);
} else {
$items = array($items);
}
}
foreach ($items as $item) {
$item = json_decode(base64_decode($item), true);
$option = $item['option'];
$view = $item['view'];
$layout = $item['layout'];
if ($option === $this->getOption() && $view === $this->getView() && (empty($layout) || $layout === $this->getLayout())) {
$this->excluded = true;
break;
}
}
}
return $this->excluded;
}
public function setFallbackTitle($title)
{
if (!empty($title)) {
$this->fallbackTitle = $this->escape(strip_tags($title));
}
}
public function getTitle()
{
$document = JFactory::getDocument();
if ($document->getTitle()) {
return $document->getTitle();
}
return $this->fallbackTitle;
}
public function setFallbackDescription($description)
{
if (!empty($description)) {
$description = strip_tags($description);
$description = str_replace(array(PHP_EOL, "\t"), array(' ', ' '), $description);
$description = preg_replace('/\s+/', ' ', $description);
$this->fallbackDescription = $this->escape($description);
}
}
public function getDescription()
{
$document = JFactory::getDocument();
if ($document->getDescription()) {
return $document->getDescription();
}
return $this->fallbackDescription;
}
public function setContent($content, $type)
{
$this->content[$type] = $content;
$cache = JFactory::getCache('plg_system_vmogmetatag', '');
$cacheKey = 'content.url:' . JUri::getInstance()->toString();
$cache->store($this->content, $cacheKey);
}
public function getContent($type)
{
if (array_key_exists($type, $this->content)) {
return $this->content[$type];
}
$cache = JFactory::getCache('plg_system_vmogmetatag', '');
$cacheKey = 'content.url:' . JUri::getInstance()->toString();
$content = $cache->get($cacheKey);
if (is_array($content) && array_key_exists($type, $content)) {
$this->content[$type] = $content[$type];
return $this->content[$type];
}
return null;
}
public function setContentParams($params, $type)
{
$this->contentParams[$type] = $params;
$cache = JFactory::getCache('plg_system_vmogmetatag', '');
$cacheKey = 'params.url:' . JUri::getInstance()->toString();
$cache->store($this->contentParams, $cacheKey);
}
public function getContentParams($type)
{
if (array_key_exists($type, $this->contentParams)) {
return $this->contentParams[$type];
}
$cache = JFactory::getCache('plg_system_vmogmetatag', '');
$cacheKey = 'params.url:' . JUri::getInstance()->toString();
$params = $cache->get($cacheKey);
if (is_array($params) && array_key_exists($type, $params)) {
$this->contentParams[$type] = $params[$type];
return $this->contentParams[$type];
}
return null;
}
public function setProduct($product)
{
$this->product = $product;
}
public function getProduct()
{
return $this->product;
}
public function setProductCategory($productCategory)
{
$this->productCategory = $productCategory;
}
public function getProductCategory()
{
return $this->productCategory;
}
public function getVirtueMartImageList($item)
{
$imageList = array();
if (!empty($item->images)) {
foreach ($item->images as $image) {
$imageData = new stdClass();
$imageData->url = '';
$imageData->width = '';
$imageData->height = '';
$imageData->type = '';
if (!$image->file_is_forSale) {
if (substr($image->file_url, 0, 4) == 'http') {
$imageData->url = $image->file_url;
} else {
$mediaPath = JPath::clean(JPATH_SITE . '/' . $image->file_url);
if (!file_exists($mediaPath)) {
$imageData = $this->getImageData($image->theme_url . 'assets/images/vmgeneral/' . VmConfig::get('no_image_set'));
} else {
$imageData = $this->getImageData($image->file_url);
}
}
} else {
if (empty($image->file_name)) {
if ($image->file_is_downloadable) {
$imageData = $this->getImageData($image->theme_url . 'assets/images/vmgeneral/' . VmConfig::get('downloadable', 'zip.png'));
} else {
$imageData = $this->getImageData($image->theme_url . 'assets/images/vmgeneral/' . VmConfig::get('no_image_set'));
}
} elseif (!empty($image->file_url_thumb)) {
if (substr($image->file_url_thumb, 0, 4) == 'http') {
$imageData->url = $image->file_url_thumb;
} else {
$mediaPath = JPath::clean(JPATH_SITE . '/' . $image->file_url_thumb);
if (!file_exists($mediaPath)) {
$imageData = $this->getImageData($image->theme_url . 'assets/images/vmgeneral/' . VmConfig::get('no_image_set'));
} else {
$imageData = $this->getImageData($image->file_url);
}
}
}
}
$imageList[] = $imageData;
}
}
return $imageList;
}
/**
* Method to set meta tag
*
* @param string $name Name of the tag
* @param string $value Tag value
*
* @return void
*/
public function setTag(string $name, string $value)
{
if (!empty($value)) {
$this->tags[$name] = $value;
}
}
/**
* Method to get the array of tags
*
* @return JRegistry object
*/
public function getTags()
{
$tags = new JRegistry();
$tags->loadArray($this->tags);
return $tags;
}
/**
* Method to check if current page is home page.
*
* @return boolean
*/
public function isHomePage()
{
$menus = $this->app->getMenu();
$activeMenu = $menus->getActive();
if (is_object($activeMenu) && property_exists($activeMenu, 'home') && $activeMenu->home) {
return true;
}
return false;
}
/**
* Method to get image data.
*
* @param string $url URL of the image.
*
* @return object Image data object.
*/
public function getImageData($url)
{
$image = new stdClass();
$image->url = '';
$image->width = '';
$image->height = '';
$image->type = '';
if (version_compare(JVERSION, '4.0.0', 'ge') && $url) {
$url = Joomla\CMS\Helper\MediaHelper::getCleanMediaFieldValue($url);
}
$path = JPath::clean(JPATH_ROOT . '/' . $url);
if (file_exists($path)) {
$url = substr($path, strlen(JPATH_ROOT . DIRECTORY_SEPARATOR));
$url = implode('/', explode(DIRECTORY_SEPARATOR, $url));
$root = rtrim(JUri::root(), '/');
$image->url = $root . '/' . str_replace(' ', '%20', $url);
if (function_exists('getimagesize')) {
$imageInfo = @getimagesize($path);
if (!empty($imageInfo) && isset($imageInfo[0]) && isset($imageInfo[1])) {
$image->width = $imageInfo[0];
$image->height = $imageInfo[1];
}
if (!empty($imageInfo) && !empty($imageInfo['mime'])) {
$image->type = $imageInfo['mime'];
}
}
}
return $image;
}
/**
* Escapes a value for output in a view script.
*
* If escaping mechanism is htmlspecialchars, use
* {@link $_charset} setting.
*
* @param mixed $var The output to escape.
*
* @return mixed The escaped value.
*
* @note the ENT_COMPAT flag was replaced by ENT_QUOTES in Joomla 4.0 to also escape single quotes
*/
public function escape($var)
{
if ($var === null) {
return '';
}
return htmlspecialchars($var, ENT_QUOTES, 'UTF-8');
}
}