| Current Path : /home/digilove/public_html/plugins/content/aimyindexnow/helpers/ |
| Current File : /home/digilove/public_html/plugins/content/aimyindexnow/helpers/ComponentInfoHelper.php |
<?php
/* Copyright (c) 2022-2024 Aimy Extensions, Netzum Sorglos Software GmbH
*
* https://www.aimy-extensions.com/
*
* License: GNU GPLv2, see LICENSE.txt within distribution and/or
* http://www.aimy-extensions.com/software-license.html
*/
namespace Aimy\IndexNow\Helpers; defined( '_JEXEC' ) or die(); require_once( __DIR__ . '/PluginHelper.php' ); use Aimy\IndexNow\Helpers\PluginHelper; use Joomla\CMS\Factory; use Joomla\CMS\Router\Route; use Joomla\CMS\Uri\Uri; abstract class ComponentInfoHelper { static public function get( $context, &$data ) { $handler = sprintf( '%s::getInfo__%s', __CLASS__, PluginHelper::getCtxComponent( $context ) ); if ( ! is_callable( $handler ) ) { return false; } $ci = $handler( PluginHelper::getCtxView( $context ), $data ); if ( ! $ci or ( ! $ci->route && ! isset( $ci->path ) ) ) { if ( ! ( $ci && isset( $ci->ignore ) && $ci->ignore ) ) { Factory::getApplication()->enqueueMessage( $handler . ': No info retrieved' ); } return false; } if ( $ci->route ) { $ci->path = Route::link( 'site', 'index.php?' . $ci->route ); unset( $ci->route ); } $ci->url = PluginHelper::getAbsoluteUrl( $ci->path ); return $ci; } static private function getInfo__com_content( $view, &$data ) { if ( $view == 'article' or $view == 'form' ) { $ci = new \StdClass(); $ci->isPublished = ( $data->state == 1 ); $ci->isPublic = ( $data->access == 1 ); $ci->route = 'option=com_content&view=article&id=' . $data->id; $ci->robots = (new \JConfig())->robots; if ( isset( $data->alias ) && $data->alias ) { $ci->route .= ':' . $data->alias; } if ( isset( $data->catid ) && $data->catid ) { $ci->route .= '&catid=' . $data->catid; } if ( isset( $data->language ) ) { $ci->lang = $data->language; if ( $data->language != '*' ) { $ci->route .= '&lang=' . $data->language; } } if ( isset( $data->title ) && ! empty( $data->title ) ) { $ci->title = $data->title; } if ( isset( $data->metadata ) && ! empty( $data->metadata ) ) { $md = PluginHelper::jsonToObject( $data->metadata ); if ( $md && isset( $md->robots ) && ! empty( $md->robots ) ) { $ci->robots = $md->robots; } } $now = Factory::getDate()->format( 'Y-m-d H:i:s' ); if ( $data->publish_up > $now ) { $ci->isPublished = false; } if ( $now > $data->publish_down && ( $data->publish_down != '0000-00-00 00:00:00' && ! is_null( $data->publish_down ) ) ) { $ci->isPublished = false; } return $ci; } return false; } static private function getInfo__com_media( $view, &$data ) { if ( $view == 'file' ) { $ci = new \StdClass(); $path = false; if ( isset( $data->filepath ) ) { $path = $data->filepath; } elseif ( isset( $data->path ) && isset( $data->name ) ) { $path = JPATH_ROOT . '/' . PluginHelper::getComMediaImagePath() . $data->path . '/' . $data->name; $path = preg_replace( '#/{2,}#', '/', $path ); } if ( ! $path ) { return false; } $path = preg_replace( '#^\Q' . JPATH_ROOT . '\E/?#i', '', $path ); if ( ! $path ) { return false; } $ci->isPublished = true; $ci->isPublic = true; $ci->route = false; $ci->path = Uri::root( true ) . '/' . $path; $ci->title = basename( $path ); $ci->robots = false; return $ci; } elseif ( $view == 'folder' ) { $ci = new \StdClass(); $ci->ignore = true; return $ci; } return false; } static private function getInfo__com_tags( $view, &$data ) { if ( $view == 'tag' ) { $ci = new \StdClass(); $ci->isPublished = ( $data->published == 1 ); $ci->isPublic = ( $data->access == 1 ); $ci->route = sprintf( 'option=com_tags&view=tag&id=%d:%s', $data->id, $data->alias ); $ci->robots = (new \JConfig())->robots; if ( isset( $data->language ) ) { $ci->lang = $data->language; if ( $data->language != '*' ) { $ci->route .= '&lang=' . $data->language; } } if ( isset( $data->title ) && ! empty( $data->title ) ) { $ci->title = $data->title; } if ( isset( $data->metadata ) && ! empty( $data->metadata ) ) { $md = PluginHelper::jsonToObject( $data->metadata ); if ( $md && isset( $md->robots ) && ! empty( $md->robots ) ) { $ci->robots = $md->robots; } } return $ci; } return false; } static private function getInfo__com_categories( $view, &$data ) { if ( $view == 'category' ) { $ci = new \StdClass(); $ci->isPublished = ( $data->published == 1 ); $ci->isPublic = ( $data->access == 1 ); $ci->route = 'option=com_content&view=category&id=' . $data->id; $ci->robots = (new \JConfig())->robots; if ( isset( $data->alias ) && $data->alias ) { $ci->route .= ':' . $data->alias; } if ( isset( $data->language ) ) { $ci->lang = $data->language; if ( $data->language != '*' ) { $ci->route .= '&lang=' . $data->language; } } if ( isset( $data->title ) && ! empty( $data->title ) ) { $ci->title = $data->title; } if ( isset( $data->metadata ) && ! empty( $data->metadata ) ) { $md = PluginHelper::jsonToObject( $data->metadata ); if ( $md && isset( $md->robots ) && ! empty( $md->robots ) ) { $ci->robots = $md->robots; } } return $ci; } return false; } }