Your IP : 216.73.216.11


Current Path : /home/digilove/public_html/41423/
Upload File :
Current File : //home/digilove/public_html/41423/content.php.tar

home/digilove/public_html/components/com_content/content.php000064400000003140152326033610020457 0ustar00<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_content
 *
 * @copyright   (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php');
JLoader::register('ContentHelperQuery', JPATH_SITE . '/components/com_content/helpers/query.php');
JLoader::register('ContentHelperAssociation', JPATH_SITE . '/components/com_content/helpers/association.php');

$input = JFactory::getApplication()->input;
$user  = JFactory::getUser();

$checkCreateEdit = ($input->get('view') === 'articles' && $input->get('layout') === 'modal')
	|| ($input->get('view') === 'article' && $input->get('layout') === 'pagebreak');

if ($checkCreateEdit)
{
	// Can create in any category (component permission) or at least in one category
	$canCreateRecords = $user->authorise('core.create', 'com_content')
		|| count($user->getAuthorisedCategories('com_content', 'core.create')) > 0;

	// Instead of checking edit on all records, we can use **same** check as the form editing view
	$values = (array) JFactory::getApplication()->getUserState('com_content.edit.article.id');
	$isEditingRecords = count($values);

	$hasAccess = $canCreateRecords || $isEditingRecords;

	if (!$hasAccess)
	{
		JFactory::getApplication()->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'warning');

		return;
	}
}

$controller = JControllerLegacy::getInstance('Content');
$controller->execute(JFactory::getApplication()->input->get('task'));
$controller->redirect();
home/digilove/public_html/110/plugins/finder/content/content.php000064400000025400152352515740020700 0ustar00<?php
/**
 * @package     Joomla.Plugin
 * @subpackage  Finder.Content
 *
 * @copyright   (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\Registry\Registry;

JLoader::register('FinderIndexerAdapter', JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/adapter.php');

/**
 * Smart Search adapter for com_content.
 *
 * @since  2.5
 */
class PlgFinderContent extends FinderIndexerAdapter
{
	/**
	 * The plugin identifier.
	 *
	 * @var    string
	 * @since  2.5
	 */
	protected $context = 'Content';

	/**
	 * The extension name.
	 *
	 * @var    string
	 * @since  2.5
	 */
	protected $extension = 'com_content';

	/**
	 * The sublayout to use when rendering the results.
	 *
	 * @var    string
	 * @since  2.5
	 */
	protected $layout = 'article';

	/**
	 * The type of content that the adapter indexes.
	 *
	 * @var    string
	 * @since  2.5
	 */
	protected $type_title = 'Article';

	/**
	 * The table name.
	 *
	 * @var    string
	 * @since  2.5
	 */
	protected $table = '#__content';

	/**
	 * Load the language file on instantiation.
	 *
	 * @var    boolean
	 * @since  3.1
	 */
	protected $autoloadLanguage = true;

	/**
	 * Method to update the item link information when the item category is
	 * changed. This is fired when the item category is published or unpublished
	 * from the list view.
	 *
	 * @param   string   $extension  The extension whose category has been updated.
	 * @param   array    $pks        A list of primary key ids of the content that has changed state.
	 * @param   integer  $value      The value of the state that the content has been changed to.
	 *
	 * @return  void
	 *
	 * @since   2.5
	 */
	public function onFinderCategoryChangeState($extension, $pks, $value)
	{
		// Make sure we're handling com_content categories.
		if ($extension === 'com_content')
		{
			$this->categoryStateChange($pks, $value);
		}
	}

	/**
	 * Method to remove the link information for items that have been deleted.
	 *
	 * @param   string  $context  The context of the action being performed.
	 * @param   JTable  $table    A JTable object containing the record to be deleted
	 *
	 * @return  boolean  True on success.
	 *
	 * @since   2.5
	 * @throws  Exception on database error.
	 */
	public function onFinderAfterDelete($context, $table)
	{
		if ($context === 'com_content.article')
		{
			$id = $table->id;
		}
		elseif ($context === 'com_finder.index')
		{
			$id = $table->link_id;
		}
		else
		{
			return true;
		}

		// Remove item from the index.
		return $this->remove($id);
	}

	/**
	 * Smart Search after save content method.
	 * Reindexes the link information for an article that has been saved.
	 * It also makes adjustments if the access level of an item or the
	 * category to which it belongs has changed.
	 *
	 * @param   string   $context  The context of the content passed to the plugin.
	 * @param   JTable   $row      A JTable object.
	 * @param   boolean  $isNew    True if the content has just been created.
	 *
	 * @return  boolean  True on success.
	 *
	 * @since   2.5
	 * @throws  Exception on database error.
	 */
	public function onFinderAfterSave($context, $row, $isNew)
	{
		// We only want to handle articles here.
		if ($context === 'com_content.article' || $context === 'com_content.form')
		{
			// Check if the access levels are different.
			if (!$isNew && $this->old_access != $row->access)
			{
				// Process the change.
				$this->itemAccessChange($row);
			}

			// Reindex the item.
			$this->reindex($row->id);
		}

		// Check for access changes in the category.
		if ($context === 'com_categories.category')
		{
			// Check if the access levels are different.
			if (!$isNew && $this->old_cataccess != $row->access)
			{
				$this->categoryAccessChange($row);
			}
		}

		return true;
	}

	/**
	 * Smart Search before content save method.
	 * This event is fired before the data is actually saved.
	 *
	 * @param   string   $context  The context of the content passed to the plugin.
	 * @param   JTable   $row      A JTable object.
	 * @param   boolean  $isNew    If the content is just about to be created.
	 *
	 * @return  boolean  True on success.
	 *
	 * @since   2.5
	 * @throws  Exception on database error.
	 */
	public function onFinderBeforeSave($context, $row, $isNew)
	{
		// We only want to handle articles here.
		if ($context === 'com_content.article' || $context === 'com_content.form')
		{
			// Query the database for the old access level if the item isn't new.
			if (!$isNew)
			{
				$this->checkItemAccess($row);
			}
		}

		// Check for access levels from the category.
		if ($context === 'com_categories.category')
		{
			// Query the database for the old access level if the item isn't new.
			if (!$isNew)
			{
				$this->checkCategoryAccess($row);
			}
		}

		return true;
	}

	/**
	 * Method to update the link information for items that have been changed
	 * from outside the edit screen. This is fired when the item is published,
	 * unpublished, archived, or unarchived from the list view.
	 *
	 * @param   string   $context  The context for the content passed to the plugin.
	 * @param   array    $pks      An array of primary key ids of the content that has changed state.
	 * @param   integer  $value    The value of the state that the content has been changed to.
	 *
	 * @return  void
	 *
	 * @since   2.5
	 */
	public function onFinderChangeState($context, $pks, $value)
	{
		// We only want to handle articles here.
		if ($context === 'com_content.article' || $context === 'com_content.form')
		{
			$this->itemStateChange($pks, $value);
		}

		// Handle when the plugin is disabled.
		if ($context === 'com_plugins.plugin' && $value === 0)
		{
			$this->pluginDisable($pks);
		}
	}

	/**
	 * Method to index an item. The item must be a FinderIndexerResult object.
	 *
	 * @param   FinderIndexerResult  $item    The item to index as a FinderIndexerResult object.
	 * @param   string               $format  The item format.  Not used.
	 *
	 * @return  void
	 *
	 * @since   2.5
	 * @throws  Exception on database error.
	 */
	protected function index(FinderIndexerResult $item, $format = 'html')
	{
		$item->setLanguage();

		// Check if the extension is enabled.
		if (JComponentHelper::isEnabled($this->extension) === false)
		{
			return;
		}

		$item->context = 'com_content.article';

		// Initialise the item parameters.
		$registry = new Registry($item->params);
		$item->params = clone JComponentHelper::getParams('com_content', true);
		$item->params->merge($registry);

		$item->metadata = new Registry($item->metadata);

		// Trigger the onContentPrepare event.
		$item->summary = FinderIndexerHelper::prepareContent($item->summary, $item->params, $item);
		$item->body    = FinderIndexerHelper::prepareContent($item->body, $item->params, $item);

		// Build the necessary route and path information.
		$item->url = $this->getUrl($item->id, $this->extension, $this->layout);
		$item->route = ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language);
		$item->path = FinderIndexerHelper::getContentPath($item->route);

		// Get the menu title if it exists.
		$title = $this->getItemMenuTitle($item->url);

		// Adjust the title if necessary.
		if (!empty($title) && $this->params->get('use_menu_title', true))
		{
			$item->title = $title;
		}

		// Add the meta author.
		$item->metaauthor = $item->metadata->get('author');

		// Add the metadata processing instructions.
		$item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey');
		$item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc');
		$item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor');
		$item->addInstruction(FinderIndexer::META_CONTEXT, 'author');
		$item->addInstruction(FinderIndexer::META_CONTEXT, 'created_by_alias');

		// Translate the state. Articles should only be published if the category is published.
		$item->state = $this->translateState($item->state, $item->cat_state);

		// Add the type taxonomy data.
		$item->addTaxonomy('Type', 'Article');

		// Add the author taxonomy data.
		if (!empty($item->author) || !empty($item->created_by_alias))
		{
			$item->addTaxonomy('Author', !empty($item->created_by_alias) ? $item->created_by_alias : $item->author);
		}

		// Add the category taxonomy data.
		$item->addTaxonomy('Category', $item->category, $item->cat_state, $item->cat_access);

		// Add the language taxonomy data.
		$item->addTaxonomy('Language', $item->language);

		// Get content extras.
		FinderIndexerHelper::getContentExtras($item);

		// Index the item.
		$this->indexer->index($item);
	}

	/**
	 * Method to setup the indexer to be run.
	 *
	 * @return  boolean  True on success.
	 *
	 * @since   2.5
	 */
	protected function setup()
	{
		// Load dependent classes.
		JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php');

		return true;
	}

	/**
	 * Method to get the SQL query used to retrieve the list of content items.
	 *
	 * @param   mixed  $query  A JDatabaseQuery object or null.
	 *
	 * @return  JDatabaseQuery  A database object.
	 *
	 * @since   2.5
	 */
	protected function getListQuery($query = null)
	{
		$db = JFactory::getDbo();

		// Check if we can use the supplied SQL query.
		$query = $query instanceof JDatabaseQuery ? $query : $db->getQuery(true)
			->select('a.id, a.title, a.alias, a.introtext AS summary, a.fulltext AS body')
			->select('a.images')
			->select('a.state, a.catid, a.created AS start_date, a.created_by')
			->select('a.created_by_alias, a.modified, a.modified_by, a.attribs AS params')
			->select('a.metakey, a.metadesc, a.metadata, a.language, a.access, a.version, a.ordering')
			->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date')
			->select('c.title AS category, c.published AS cat_state, c.access AS cat_access');

		// Handle the alias CASE WHEN portion of the query
		$case_when_item_alias = ' CASE WHEN ';
		$case_when_item_alias .= $query->charLength('a.alias', '!=', '0');
		$case_when_item_alias .= ' THEN ';
		$a_id = $query->castAsChar('a.id');
		$case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':');
		$case_when_item_alias .= ' ELSE ';
		$case_when_item_alias .= $a_id . ' END as slug';
		$query->select($case_when_item_alias);

		$case_when_category_alias = ' CASE WHEN ';
		$case_when_category_alias .= $query->charLength('c.alias', '!=', '0');
		$case_when_category_alias .= ' THEN ';
		$c_id = $query->castAsChar('c.id');
		$case_when_category_alias .= $query->concatenate(array($c_id, 'c.alias'), ':');
		$case_when_category_alias .= ' ELSE ';
		$case_when_category_alias .= $c_id . ' END as catslug';
		$query->select($case_when_category_alias)

			->select('u.name AS author')
			->from('#__content AS a')
			->join('LEFT', '#__categories AS c ON c.id = a.catid')
			->join('LEFT', '#__users AS u ON u.id = a.created_by');

		return $query;
	}
}
home/digilove/public_html/plugins/gsd/content/content.php000064400000021416152353265750017714 0ustar00<?php

/**
 * @package         Google Structured Data
 * @version         5.6.5 Pro
 *
 * @author          Tassos Marinos <info@tassos.gr>
 * @link            http://www.tassos.gr
 * @copyright       Copyright © 2021 Tassos Marinos All Rights Reserved
 * @license         GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
 */

defined('_JEXEC') or die('Restricted access');

use NRFramework\Cache;
use NRFramework\Functions;
use GSD\MappingOptions;
use GSD\Helper\JReviews;
use Joomla\Registry\Registry;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\PluginHelper;

/**
 *  Joomla! Content Google Structured Data Plugin
 */
class plgGSDContent extends GSD\PluginBaseArticle
{
    /**
     *  Validate context to decide whether the plugin should run or not.
     *
     *  @return   bool
     */
    protected function passContext()
    {
        if (!$id = $this->app->input->get('id'))
        {
            return;
        }
		
		// YooTheme Builder is previewing an article
        return parent::passContext() && !$this->app->input->get('customizer');
    }

	/**
	 *  Get article's data
	 *
	 *  @return  array
	 */
	public function viewArticle()
	{
		// Load current item via model
		if (defined('nrJ4'))
		{	
			$model = new Joomla\Component\Content\Site\Model\ArticleModel(['ignore_request' => true]);
			$model->setState('article.id', $this->getThingID());
			$model->setState('params', $this->app->getParams());
		} else 
		{
			$model = BaseDatabaseModel::getInstance('Article', 'ContentModel');
		}

		// Make sure we have a valid item data
		if (!is_object($model) || !$item = $model->getItem())
		{
			return;
		}

		// Image
		$image = new Registry($item->images);

		// Set text property required by the Content Prepare Event
		$item->text = isset($item->introtext) && !empty($item->introtext) ? $item->introtext : $item->fulltext;

		// Prepare Article with Content Plugins
		if ($this->params->get('preparecontent', false))
		{
			$this->prepareItem($item);
		}

		// Array data
		$payload = [
			'id'           => $item->id,
			'alias'        => $item->alias,
			'headline'     => $item->title,
			'description'  => $item->text,
			'introtext'    => $item->introtext,
			'fulltext'     => $item->fulltext,
			'image_intro'  => $image->get('image_intro'),
			'image_full'   => $image->get('image_fulltext'),
			'image'        => $image->get('image_intro') ?: $image->get('image_fulltext'),
			'imagetext'	   => \GSD\Helper::getFirstImageFromString($item->introtext . $item->fulltext),
			'created_by'   => $item->created_by,
			'created_by_alias' => $item->created_by_alias,
			'created'      => $item->created,
			'modified'     => $item->modified,
			'publish_up'   => $item->publish_up,
			'publish_down' => $item->publish_down,
			'ratingValue'  => $item->rating,
        	'reviewCount'  => $item->rating_count,
        	'metakey'	   => $item->metakey,
            'metadesc'	   => $item->metadesc,
            
            // Category Info
            'category.id'     => $item->catid,
            'category.title'  => $item->category_title,
            'category.alias'  => $item->category_alias
		];

		// key_ref and ext_ref are no longer available in J4 - https://github.com/joomla/joomla-cms/pull/25549
		if (!defined('nrJ4'))
		{
            $payload['key_ref'] = $item->xreference; 
            $payload['ext_ref'] = $item->metadata->get('xreference');
		}

		if ((bool) $this->params->get('load_custom_fields', true))
		{
			$this->attachCustomFields($item, $payload);
		}

		return $payload;
	}
	
	/**
	 * Append Custom Fields to payload
	 *
	 * @param	object	$article
	 * @param	array	$payload
	 * @param   string 	$prefix
	 *
	 * @return	void
	 */
	private function attachCustomFields($article, &$payload, $prefix = 'cf.')
	{
		$fields = $this->getCustomFields($article);
		
		if (!is_array($fields) || count($fields) == 0)
		{
			return;
		}

		foreach ($fields as $key => $field)
		{
			$field_path = $prefix . strtolower($field->name);
			$value = $field->value;

			if ($field->rawvalue && $field->value != $field->rawvalue)
			{
				$value = $field->rawvalue;
			}

			if ($field->type === 'media' && defined('nrJ4'))
			{
				$value_decoded = json_decode($value, true);
				$value = $value_decoded && isset($value_decoded['imagefile']) ? $value_decoded['imagefile'] : $value;
			}

			if ($field->type === 'acfupload')
			{
				$value = is_string($value) && json_decode($value, true) ? json_decode($value, true) : $value;
				if (is_array($value))
				{
					$value = array_values($value);
				}
				$value = isset($value[0]['value']) ? $value[0]['value'] : $value;
			}
			else if ($field->type === 'acfgallery')
			{
				$value = is_string($value) && json_decode($value, true) ? json_decode($value, true) : $value;
				$value = isset($value['items'][0]['image']) ? $value['items'][0]['image'] : $value;
			}

			$payload[$field_path] = is_array($value) ? @implode(', ', $value) : $value;
		}
	}
	
	/**
	 *  Add a new tab called Google Structured Data in the article editing page
	 *
	 *  @param   Form  $form  The form to be altered.
	 *  @param   mixed  $data  The associated data for the form.
	 *
	 *  @return  boolean
	 */
	public function onGSDPluginForm($form, $data)
	{
		// Only if fast edit is enabled
		if (!(bool) $this->params->get('fastedit', true))
		{
			return;
		}
		
		// Make sure the user can access com_gsd
		if (!Factory::getUser()->authorise('core.manage', 'com_gsd'))
		{
			return;
		}
		
		// Make sure we are manipulating a Form
		if (!($form instanceof Form))
		{
			return;
		}
		
		if ($form->getName() != 'com_content.article')
		{
			return;
		}

		if (empty($data))
		{
			return;
		}
		
		// Ohh boy.. another B/C break introduced in Joomla! 3.8.10
		// Issue:   https://github.com/joomla/joomla-cms/issues/20879
		// Culprit: https://github.com/joomla/joomla-cms/pull/20313
		if (is_object($data))
		{
			$data = (array) $data;
		}

		$form->loadFile(__DIR__ . '/form/form.xml', false);
		
		$form->setFieldAttribute('snippet', 'thing', $data['id'], 'attribs.gsd');
		$form->setFieldAttribute('snippet', 'thing_title', $data['title'], 'attribs.gsd');
		$form->setFieldAttribute('snippet', 'plugin_assignment_name', 'article',  'attribs.gsd');
		$form->setFieldAttribute('snippet', 'plugin', $this->_name, 'attribs.gsd');
	}

	/**
	 * The MapOptions Backend Event. Triggered by the mappingoptions fields to help each integration add its own map options.
	 *  
	 * @param	string	$plugin
	 * @param	array	$options
	 *
	 * @return	void
	 */
    public function onMapOptions($plugin, &$options)
    {
		if ($plugin != $this->_name)
        {
			return;
		}

		// Custom mapping options
		$options_ = [
			'image_intro' => 'NR_INTRO_IMAGE',
			'image_full'  => 'NR_FULL_IMAGE',
		];

		// Only on J3
		if (!defined('nrJ4'))
		{
			$options_['key_ref'] = 'COM_GSD_KEY_REF';
			$options_['ext_ref'] = 'COM_GSD_EXT_REF';
		}

		MappingOptions::add($options, $options_, 'GSD_INTEGRATION', 'gsd.item.');

		if ((bool) !$this->params->get('load_custom_fields', true))
		{
			return;
		}
		
		// Add Author Alias option
		$offset = array_search('user.name', array_keys($options['GSD_INTEGRATION']));
		$options['GSD_INTEGRATION'] = Functions::array_splice_assoc($options['GSD_INTEGRATION'], ['gsd.item.created_by_alias' => 'Author Alias'], $offset);
		
		// Add Custom Fields
		if (!$custom_fields = $this->getCustomFields())
		{
			return;
		}

		$custom_fields_options = [];
	
		foreach ($custom_fields as $key => $field)
		{
			$custom_fields_options[$field->name] = $field->title;
		}

		MappingOptions::add($options, $custom_fields_options);

        // Add Category Options
        $cat_options = [
            'category.id'     => 'GSD_MAPPING_OPTION_CAT_ID',
            'category.alias'  => 'GSD_MAPPING_OPTION_CAT_ALIAS',
            'category.title'  => 'GSD_MAPPING_OPTION_CAT_TITLE'
        ];

		MappingOptions::add($options, $cat_options, 'GSD_INTEGRATION', 'gsd.item.');
    }
	
	/**
	 * Load Joomla Articles Custom Fields
	 *
	 * @param  mixed $article
	 *
	 * @return void
	 */
	private function getCustomFields($article = null)
	{
		$hash = md5($this->_name . 'cf');

		if (Cache::has($hash))
		{
			return Cache::get($hash);
		}

		JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');

		if (!class_exists('FieldsHelper'))
		{
			return;
		}

		$fields = FieldsHelper::getFields('com_content.article', $article, true);

		return Cache::set($hash, $fields);
	}

	/**
	 * Prepare Article with Content Plugins.
	 *
	 * @param	object	$item 	The article object
	 *
	 * @return	void
	 */
	private function prepareItem($item)
	{
		// add more to parameters if needed
		$params = new CMSObject();
		PluginHelper::importPlugin('content');
		$this->app->triggerEvent('onContentPrepare', ['com_content.article', &$item, &$params, 0]);
	}
}
home/digilove/public_html/plugins/system/forseo/platform/components/content.php000064400000056172152355105760024322 0ustar00<?php
/**
 * Project: 4SEO
 *
 * @package          4SEO
 * @copyright        Copyright Weeblr llc - 2020-2024
 * @author           Yannick Gaultier - Weeblr llc
 * @license          GNU General Public License version 3; see LICENSE.md
 * @version          6.2.0.2478
 * @date        2024-10-03
 */

namespace Weeblr\Forseo\Platform\Components;

use Weeblr\Forseo\Data;
use Weeblr\Forseo\Helper;

use Weeblr\Wblib\Forseo\Wb;
use Weeblr\Wblib\Forseo\System;
use Weeblr\Wblib\Forseo\Html;
use Weeblr\Wblib\Forseo\Joomla\Registry;

use Joomla\CMS\Factory as JoomlaFactory;
use Joomla\CMS\Router\Route;

// no direct access
defined('_JEXEC') || defined('WBLIB_EXEC') || die;

/**
 */
class Content extends Base
{
	/**
	 * @var string Component name - with leading com_ removed, eg content for com_content
	 */
	protected $component = 'content';

	/**
	 * @var \stdClass Cache for com_content being rendered.
	 */
	protected $contentData = null;

	/**
	 * @var string[] com_content views we can store.
	 */
	protected $includedViews = [
		'archive',
		'article',
		'categories',
		'category',
		'featured'
	];

	/**
	 * @var null|array List of layouts names that should be stored. None if null. All if empty.
	 */
	protected $includedLayouts = [];

	/**
	 * @var null|array List of layouts names that should NOT be stored. No effect if null or empty.
	 */
	protected $excludedLayouts = [
		'edit'
	];

	/**
	 * @var array List of schema types supported by this plugin.
	 */
	protected $supportedSdTypes = [
		Data\Sd::ARTICLE,
		Data\Sd::NEWS_ARTICLE,
		Data\Sd::BLOG_POSTING,
		Data\Sd::VIDEO_OBJECT,
		Data\Sd::COURSE,
		Data\Sd::EVENT,
		Data\Sd::PRODUCT,
		Data\Sd::RECIPE,
		Data\Sd::FAQ_PAGE,
		Data\SD::MOVIE
	];

	/**
	 * @var bool Whether the plugin wants to filter raw, SEF URL. Time consuming, avoid if not needed.
	 */
	protected $filterShouldCollectUrlsFoundOnPage = false;

	/**
	 * Add handlers for desired com_content hooks.
	 */
	public function addHooks()
	{
		parent::addHooks();

		$this->hook->add(
			'forseo_page_canonical_or_duplicate',
			[
				$this,
				'filterPageCanonicalOrDuplicate'
			]
		);

		$this->hook->add(
			'forseo_expandable_variables',
			[
				$this,
				'filterExpandableVariables'
			]
		);

		$this->hook->add(
			'forseo_extract_images',
			[
				$this,
				'filterExtractImages'
			]
		);
	}

	/**
	 * Tries to build automatically a canonical link for the current page described
	 * by the Page object passed in.
	 *
	 * Canonical returned will be made absolute downstream if not already fully qualified.
	 *
	 * Return null if no canonical can be determined based solely on the current request data.
	 *
	 * @param bool      $dynamicCanonical
	 * @param Data\Page $pageData Collected request information.
	 *
	 * @return null | string
	 *
	 * @throws \Exception
	 */
	protected function filterDynamicCanonical($dynamicCanonical, $pageData)
	{
		$dynamicCanonical = parent::filterDynamicCanonical($dynamicCanonical, $pageData);
		if (!is_null($dynamicCanonical))
		{
			return $dynamicCanonical;
		}

		$inputVars = $pageData->get('input_vars', []);
		$format    = Wb\arrayGet($inputVars, 'format', 'html');
		if ('html' !== $format)
		{
			return $dynamicCanonical;
		}

		$view = Wb\arrayGet($inputVars, 'view');
		if (!in_array($view, ['article', 'category']))
		{
			return $dynamicCanonical;
		}

		if (
			Wb\arrayIsTruthy($inputVars, 'task')
			||
			Wb\arrayIsTruthy($inputVars, 'a_id')
		)
		{
			return $dynamicCanonical;
		}

		$id = Wb\arrayGet($inputVars, 'id');
		if (empty($id))
		{
			return $dynamicCanonical;
		}

		// hack for Joomla 4 bug
		if ('article' === $view)
		{
			$layout = Wb\arrayGet($inputVars, 'layout');
			if ('blog' === $layout)
			{
				unset($inputVars['layout']);
			}
		}

		// keep going now
		$nonSefVars = array_intersect_key(
			$inputVars,
			array_flip(
				[
					'option',
					'view',
					'layout',
					'id',
					'catid',
					'limitstart',
					'limit',
					'Itemid'
				]
			)
		);

		$nonSefUrl = implode(
			'?',
			[
				'index.php',
				http_build_query(
					$nonSefVars,
					'',
					'&',
					PHP_QUERY_RFC3986
				)
			]
		);

		return Route::link(
			'site',
			$nonSefUrl,
			false // $xhtml
		);
	}

	/**
	 * Actually add SD rules to the current request.
	 *
	 * @param array            $rules
	 * @param Data\Requestinfo $requestInfo
	 * @param Data\Page        $pageData
	 * @param string           $baseId
	 * @return array
	 * @throws \Exception
	 */
	protected function filterSdRules($rules, $requestInfo, $pageData, $baseId)
	{
		if ('article' !== $pageData->get('view'))
		{
			return $rules;
		}

		if ($this->factory->getThis('forseo.config', 'sd')->isFalsy('enabledBuiltInRules'))
		{
			return $rules;
		}

		$rule = $this->factory->getA(Data\Rule::class);

		// Article
		$ruleData = [
			'actionSdType' => [Data\Sd::ARTICLE],
		];

		$rule->set(
			[
				'rule'   => $ruleData,
				'source' => Data\Rule::SOURCE_BUILT_IN
			]
		);

		$rules[] = $rule;

		return $rules;
	}

	/**
	 * Decides whether a given SD rule can apply to the current page.
	 * By default is null.
	 * If a plugin can support, it sets it to true.
	 * If a plugin says this SD type cannot exist on this page, it sets it to false.
	 * Else leave as is.
	 *
	 * In the end, returned value must be true (ie at least one plugin can support and no other
	 * contradict) for the rule to run.
	 *
	 * NB: At this stage, it has already been checked that:
	 *
	 * - the current request is for this plugin extension
	 * - the current plugin lists the SD rule type in its $supportedSdTypes property.
	 *
	 * @param bool             $canRunRule
	 * @param array            $spec
	 * @param Data\Requestinfo $requestInfo
	 * @param Data\Page        $pageData
	 * @return bool
	 * @throws \Exception
	 */
	public function filterSdCanRunRule($canRunRule, $spec, $requestInfo, $pageData)
	{
		if ('article' !== strtolower($pageData->get('view')))
		{
			return false;
		}

		return $canRunRule;
	}

	/**
	 * Build automatically computed structured data for a com_content article.
	 *
	 * @param array            $autoFieldsData
	 * @param array            $autoFields
	 * @param array            $spec
	 * @param Data\Requestinfo $requestInfo
	 * @param Data\Page        $pageData
	 * @param string           $baseId
	 * @return array
	 * @throws \Exception
	 */
	protected function filterSdData($autoFieldsData, $autoFields, $spec, $requestInfo, $pageData, $baseId)
	{
		if (!$this->shouldRunFilter($pageData))
		{
			return $autoFieldsData;
		}

		if (array_key_exists('url', $autoFields))
		{
			$autoFieldsData['sdData']['url'] = $requestInfo->get('page_url');
		}

		if (
			!empty($this->contentData)
			&&
			!empty($this->contentData['content'])
		)
		{
			if (
				array_key_exists('headline', $autoFields)
				&&
				isset($this->contentData['content']->title))
			{
				$autoFieldsData['sdData']['headline'] = $this->contentData['content']->title;
			}
			if (
				array_key_exists('name', $autoFields)
				&&
				isset($this->contentData['content']->title))
			{
				$autoFieldsData['sdData']['name'] = $this->contentData['content']->title;
			}

			if (
				array_key_exists('datePublished', $autoFields)
				&&
				isset($this->contentData['content']->publish_up)
			)
			{
				$autoFieldsData['sdData']['datePublished'] = $this->contentData['content']->publish_up;
			}

			if (
				array_key_exists('dateCreated', $autoFields)
				&&
				isset($this->contentData['content']->publish_up)
			)
			{
				$autoFieldsData['sdData']['dateCreated'] = $this->contentData['content']->publish_up;
			}

			if (
				array_key_exists('dateModified', $autoFields)
				&&
				isset($this->contentData['content']->modified))
			{
				$dateModified                             =
					empty($this->contentData['content']->modified)
					||
					'0000-00-00 00:00:00' == $this->contentData['content']->modified
						? $this->contentData['content']->publish_up
						: $this->contentData['content']->modified;
				$autoFieldsData['sdData']['dateModified'] = $dateModified;
			}

			if (
				array_key_exists('author', $autoFields)
				&&
				isset($this->contentData['content']->author)
				&&
				isset($this->contentData['content']->created_by)
				&&
				!Wb\arrayIsEmpty($spec, 'useItemAuthor')
			)
			{
				$authorUserName = $this->contentData['content']->author;
				$authorId       = $this->factory
					->getA(Helper\Sd::class)
					->toId(
						$authorUserName
						. '_'
						. System\Auth::shortHash(
							$authorUserName . $this->contentData['content']->created_by
						)
					);

				$autoFieldsData['identitiesUsed']    = [
					'author' => $authorId
				];
				$autoFieldsData['identitiesCreated'] = [
					$authorId => [
						'@type' => Data\Sd::PERSON, // Person | Organization
						'name'  => $authorUserName
					]
				];

				$authorField = [
					'@id' => $baseId . '#' . $authorId
				];

				$autoFieldsData['sdData']['author'] = $authorField;
			}

			if (array_key_exists('aggregateRating', $autoFields))
			{
				$reviews = $this->buildAggregateRating($spec);
				if (!empty($reviews))
				{
					$autoFieldsData['sdData']['aggregateRating'] = $reviews;
				}
			}

			// VideoObject
			if (
				array_key_exists('contentUrl', $autoFields)
				&&
				isset($this->contentData['content']->publish_up))
			{
				// search for 1st mp4 file in src attr in content
				$url = Html\Extract::extractVideo(
					$this->contentData['content']->text,
					'mp4'
				);
				if (!empty($url))
				{
					$autoFieldsData['sdData']['contentUrl'] = $url;
				}
			}
			if (
				array_key_exists('uploadDate', $autoFields)
				&&
				isset($this->contentData['content']->publish_up))
			{
				$autoFieldsData['sdData']['uploadDate'] = $this->contentData['content']->publish_up;
			}

			// Event
			if (
				array_key_exists('startDate', $autoFields)
				&&
				isset($this->contentData['content']->publish_up))
			{
				$autoFieldsData['sdData']['startDate'] = $this->contentData['content']->publish_up;
			}

		}

		return $autoFieldsData;
	}

	/**
	 * Build an aggregateRating record if applicable to current content type.
	 *
	 * @param array $spec
	 * @return array|null
	 */
	private function buildAggregateRating($spec)
	{
		$reviews  = null;
		$itemType = Wb\arrayGet($spec, 'actualType', '');
		if (in_array($itemType, Data\Sd::REVIEWABLE_TYPES))
		{
			$rating      = $this->contentData['content']->rating;
			$ratingCount = $this->contentData['content']->rating_count;
			if (null !== $rating && !empty($ratingCount))
			{
				$reviews = [
					'@type'       => Data\Sd::AGGREGATE_RATING,
					'ratingValue' => $rating,
					'reviewCount' => $ratingCount,
					'worstRating' => 0,
					'bestRating'  => 5
				];
			}
		}

		return $reviews;
	}

	/**
	 * Filters page data collected at the onAfterRoute event.
	 *
	 * @param Data\Page $pageData
	 *
	 * @return Data\Page
	 * @throws \Exception
	 */
	protected function filterAfterRoutePageData($pageData)
	{
		$pageData = parent::filterAfterRoutePageData($pageData);

		$view = $pageData->get('view');
		if (!in_array($view, ['featured']))
		{
			return $pageData;
		}

		// this is a featured view
		// this a category view, are we on a second or more pages?
		// if so, include page number in id to distinguish them.
		$inputVars = $pageData->get('input_vars', []);
		$Itemid    = Wb\arrayGet(
			$inputVars,
			'Itemid',
			null
		);

		if (is_null($Itemid))
		{
			return $pageData;
		}

		// search menu item for a category specification
		$menuItem = JoomlaFactory::getApplication()
								 ->getMenu('site')
								 ->getItem($Itemid);
		if (empty($menuItem))
		{
			return $pageData;
		}

		$featuredCategories = $menuItem
			->getParams()
			->get('featured_categories');
		if (empty($featuredCategories))
		{
			return $pageData;
		}

		// update the item_id based on non-sef variables
		$pageData->set(
			'item_id',
			$this->helper->compactValuesList($featuredCategories)
		);

		return $pageData;
	}

	/**
	 * Whether passed page should be considered canonical or duplicate (automatically). Presence of a duplicate
	 * (ie with same content_id) has already been checked.
	 *
	 * @param int       $urlType  Data\Page::CANONICAL | Data\Page::DUPLICATE
	 * @param Data\Page $pageData The page object.
	 *
	 * @return int
	 *
	 * @throws \Exception
	 */
	public function filterPageCanonicalOrDuplicate(int $urlType, Data\Page $pageData)
	{
		if (!$this->shouldRunFilter($pageData))
		{
			return $urlType;
		}

		// Multipage articles: if current page has ?showall, it should be canonical
		$inputVars          = $pageData->get('input_vars', []);
		$hasShowallVar      = Wb\arrayGetInt($inputVars, 'showall') === 1;
		$isShowAllMultipage = $hasShowallVar
							  ||
							  Wb\contains($pageData->get('full_url'), 'showall=1');

		if (
			!$isShowAllMultipage
			&&
			$pageData->isFalsy('isMultiPage')
		)
		{
			return $urlType;
		}

		$hasShowAll = $this->platform->isShowAllEnabled();

		// Site is configured to display a showAll page.
		if ($hasShowAll)
		{
			$urlType = $isShowAllMultipage
				? Data\Page::CANONICAL
				: Data\Page::DUPLICATE;
		}

		// Site is not configured to display show all
		// all pages are canonical
		if (!$hasShowAll)
		{
			$urlType = Data\Page::CANONICAL;
		}

		return $urlType;
	}

	/**
	 * Implement construction of com_content item unique id.
	 *
	 * @param null|array     $id
	 * @param null|Data\Page $pageData
	 *
	 * @return       array
	 * @throws \Exception
	 */
	protected function filterPageBuildContentId($id, $pageData)
	{
		$id = $this->defaultPageBuildContentId($id, $pageData);

		// clean up id of item title
		$itemId = Wb\arrayGet($id, 'id');
		if (!empty($itemId))
		{
			$id['id'] = $this->helper->cleanIdsWithColons($itemId);
		}

		// multipage article
		unset($id['showall']);

		if ('article' === Wb\arrayGet($id, 'view'))
		{
			// for an article, only keep option, view and id
			$contentIdvars = [
				'option',
				'view',
				'id'
			];

			if (!$this->platform->isShowAllEnabled())
			{
				$contentIdvars[] = 'limitstart';
			}

			// and limitstart if showall is not enabled (ie all subpages re canonical)
			$id = array_intersect_key(
				$id,
				array_flip(
					$contentIdvars
				)
			);
		}

		return $id;
	}

	/**
	 * Implement default construction of a content hash that may be computed
	 * from a raw content array as provided by the platform.
	 *
	 * @param string         $hash
	 * @param array          $contentData
	 * @param null|Data\Page $pageData
	 *
	 * @return string
	 * @throws \Exception
	 */
	protected function filterPageBuildContentHash($hash, $contentData, $pageData)
	{
		$context = Wb\arrayGet($contentData, 'context', '');

		if ('com_content.article' != $context)
		{
			return $hash;
		}

		$content = Wb\arrayGet($contentData, 'content');
		if (
			empty($content)
			||
			// Some extensions (GSD) create invalid records, missing some parts.
			!isset($content->catid)
			||
			!isset($content->author)
			||
			!isset($content->title)
		)
		{
			return $hash;
		}

		$id = $content->catid
			  . $content->author
			  . strip_tags($content->text)
			  . $content->images
			  . $content->language
			  . $content->title
			  . $content->urls;

		return md5(json_encode($id));
	}

	/**
	 * Hook to store the finalized content data of current page.
	 *
	 * @param array $contentData
	 * @return void
	 */
	public function actionStorePreparedContent($contentData)
	{
		$context = Wb\arrayGet($contentData, 'context', '');

		if ('com_content.article' !== $context)
		{
			return;
		}

		$this->contentData = $contentData;
	}

	/**
	 * Filter automatically detected images from content data object.
	 *
	 * @param array     $extractedImages
	 * @param string    $context       An option string representing the context, the content type.
	 * @param string    $content       Rendered content.
	 * @param Object    $contentObject Data object holding the content data.
	 * @param Data\Page $pageData      Collected request information.
	 * @param Data\Meta $pageMeta      Collected meta data about the request.
	 *
	 * @return array
	 *
	 */
	protected function filterExtractPageImagesFromContentData($extractedImages, $context, $content, $contentObject, $pageData, $pageMeta)
	{
		if ('com_content.article' == $context)
		{
			$appConfig    = $this->factory->getThis('forseo.config', 'app');
			$imageSpec    = $appConfig->get('imageDetectionRequireSizeSd');
			$ogpImageSpec = $appConfig->get('imageDetectionRequireSizeOgp');

			$extractedImages['page_image']         = $this->detectComContentImages($contentObject, $imageSpec);
			$extractedImages['page_sharing_image'] = $this->detectComContentImages($contentObject, $ogpImageSpec);
		}

		return $extractedImages;
	}

	/**
	 * Detect whether an article Full or intro image are suitable as a page image.
	 *
	 * @param Object $contentObject
	 * @param array  $imageSpec
	 *
	 * @return array|string
	 */
	private function detectComContentImages($contentObject, $imageSpec)
	{
		if (!empty($contentObject) && !empty($contentObject->images))
		{
			$imageDef       = new Registry\Registry($contentObject->images);
			$possibleImages = [
				'image_fulltext',
				'image_intro'
			];
			$imageHelper    = $this->factory->getA(Helper\Meta::class);
			foreach ($possibleImages as $possibleImage)
			{
				$imageUrl = $imageDef->get(
					$possibleImage,
					''
				);

				// special J4 cleanup
				if (Wb\contains($imageUrl, '#joomlaImage'))
				{
					$imageUrlBits = explode('#joomlaImage', $imageUrl, 2);
					$imageUrl     = array_shift($imageUrlBits);
				}

				$image = $imageHelper->validateImageFromContent(
					$imageUrl,
					$imageSpec
				);
				// return right away if a valid image is found
				// User has set those images, they should be representative
				if (!empty($image))
				{
					// possibly extract alt
					$image['alt'] = $imageDef->get($possibleImage . '_alt', '');
					// possibly extract caption
					$image['caption'] = $imageDef->get($possibleImage . '_caption', '');

					return $image;
				}
			}
		}

		return '';
	}

	/**
	 * Implement default construction of finding out modified_at date time.
	 *
	 * Use MYSQL format (Y-m-d H:i:s), assumes UTC.
	 *
	 * Null if unable to determine.
	 *
	 * @param null|string $lastMod
	 * @param Data\Page   $pageData
	 *
	 * @return null | string
	 * @throws \Exception
	 */
	protected function filterPageModifiedAt($lastMod, $pageData)
	{
		$inputVars = $pageData->get('input_vars', []);
		$view      = Wb\arrayGet($inputVars, 'view', '');
		if (!in_array($view, ['article', 'category']))
		{
			return $lastMod;
		}

		$itemId = (int)Wb\arrayGet($inputVars, 'id');
		if (empty($itemId))
		{
			return $lastMod;
		}

		if ('article' == $view)
		{
			$dbTable                  = '#__content';
			$modificationColumn       = 'modified';
			$modificationBackupColumn = 'created';
		}
		else
		{
			$dbTable                  = '#__categories';
			$modificationColumn       = 'modified_time';
			$modificationBackupColumn = 'created_time';
		}

		$modData = $this->factory
			->getThe('db')
			->selectAssoc(
				$dbTable,
				[$modificationColumn, $modificationBackupColumn],
				[
					'id' => $itemId
				]
			);

		if (empty($modData))
		{
			return null;
		}

		$lastMod = Wb\arrayGet($modData, $modificationColumn, null);
		$lastMod = empty($lastMod) || '0000-00-00 00:00:00' == $lastMod
			? Wb\arrayGet($modData, $modificationBackupColumn, null)
			: $lastMod;

		return $lastMod;
	}

	/**
	 * Filters whether the content described by in $pageData is considered archived. Will have an impact on
	 * sitemap inclusion.
	 *
	 * @param bool      $isArchived True if content hyas support for archiving and is archived, false otherwise.
	 * @param Data\Page $pageData
	 *
	 * @return bool
	 * @throws \Exception
	 */
	protected function filterPageIsArchived($isArchived, $pageData)
	{
		$inputVars = $pageData->get('input_vars', []);
		$view      = Wb\arrayGet($inputVars, 'view', '');
		if (!in_array($view, ['article', 'category']))
		{
			return $isArchived;
		}

		$itemId = (int)Wb\arrayGet($inputVars, 'id');
		if (empty($itemId))
		{
			return $isArchived;
		}

		if ('article' == $view)
		{
			$dbTable = '#__content';
			$column  = 'state';
		}
		else
		{
			$dbTable = '#__categories';
			$column  = 'published';
		}

		$stateData = $this->factory
			->getThe('db')
			->selectAssoc(
				$dbTable,
				[$column],
				[
					'id' => $itemId
				]
			);

		$state = Wb\arrayGet($stateData, $column, null);

		return !empty($state) && 2 == $state;
	}

	/**
	 * Filter auto-generated dynamic variables that will be substituted by 4SEO based on rules.
	 *
	 * @param array     $variables
	 * @param Data\Page $pageData
	 * @return array
	 * @throws \Exception
	 */
	public function filterExpandableVariables($variables, $pageData)
	{
		if (!$this->shouldRunFilter($pageData))
		{
			return $variables;
		}

		if (
			empty($this->contentData)
			||
			empty($this->contentData['content'])
		)
		{
			return $variables;
		}

		$contentVariables = [];
		if (
			'article' === $pageData->get('view')
			&&
			'com_content.article' === $this->contentData['context']
		)
		{
			$contentVariables['article_id'] = $this->contentData['content']->id;
			if (!empty($this->contentData['content']->title))
			{
				$contentVariables['article_title'] = $this->contentData['content']->title;
			}
			if (!empty($this->contentData['content']->metadesc))
			{
				$contentVariables['article_description'] = $this->contentData['content']->metadesc;
			}
			$contentVariables['article_date_modified']  = $this->contentData['content']->modified;
			$contentVariables['article_date_published'] = $this->contentData['content']->publish_up;
			$contentVariables['article_category_id']    = $this->contentData['content']->catid;
			$contentVariables['article_category']       = $this->contentData['content']->category_title;
			$contentVariables['article_author']         = $this->contentData['content']->author;
			$contentVariables['article_rating']         = empty($this->contentData['content']->rating) ? 0 : $this->contentData['content']->rating;
			$contentVariables['article_rating_count']   = empty($this->contentData['content']->rating_count) ? 0 : $this->contentData['content']->rating_count;
			$contentVariables['article_hits']           = $this->contentData['content']->hits;
		}

		return array_merge(
			$variables,
			$contentVariables
		);
	}

	/**
	 * Extract best images from gallery found in a page.
	 *
	 * $images[$href] = [
	 * 'url'       => $href,
	 * 'title'     => $imgTag->getAttribute('title'),
	 * 'alt'       => $imgTag->getAttribute('alt'),
	 * 'el_width'  => $imgTag->getAttribute('width'),
	 * 'el_height' => $imgTag->getAttribute('height'),
	 * 'data'      => $dataAttributes
	 * ];
	 *
	 * @param null|array   $extractedImages
	 * @param string       $buffer
	 * @param \DOMDocument $dom
	 * @param \DocNodeList $imgTags
	 * @param array        $options
	 * @param Data\Page    $pageData
	 * @return null|array
	 * @throws \Exception
	 */
	public function filterExtractImages($extractedImages, $buffer, $dom, $imgTags, $options, $pageData)
	{
		if (!$this->shouldRunFilter($pageData))
		{
			return $extractedImages;
		}

		$view = strtolower($pageData->get('view'));
		if ('article' !== $view)
		{
			return [];
		}

		return $extractedImages;
	}

	/**
	 * Check whether the current plugin can retrieve a custom field value
	 * associated with the provided context string.
	 *
	 * @param string $context
	 * @return bool
	 */
	protected function isValidCustomFieldContext($context)
	{
		return Wb\startsWith(
			$context,
			'com_content.article'
		);
	}
}
home/digilove/public_html/plugins/system/nnframework/fields/content.php000064400000010040152355574200022572 0ustar00<?php
/**
 * Element: Content
 * Displays a multiselectbox of available categories / items
 *
 * @package         NoNumber Framework
 * @version         14.11.6
 *
 * @author          Peter van Westen <peter@nonumber.nl>
 * @link            http://www.nonumber.nl
 * @copyright       Copyright © 2014 NoNumber All Rights Reserved
 * @license         http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

defined('_JEXEC') or die;

require_once JPATH_PLUGINS . '/system/nnframework/helpers/parameters.php';
require_once JPATH_PLUGINS . '/system/nnframework/helpers/text.php';

class JFormFieldNN_Content extends JFormField
{
	public $type = 'Content';
	private $params = null;
	private $db = null;
	private $max_list_count = 0;

	protected function getInput()
	{
		$this->params = $this->element->attributes();
		$this->db = JFactory::getDbo();

		$parameters = nnParameters::getInstance();
		$params = $parameters->getPluginParams('nnframework');
		$this->max_list_count = $params->max_list_count;

		if (!is_array($this->value))
		{
			$this->value = explode(',', $this->value);
		}

		$group = $this->get('group', 'categories');
		$options = $this->{'get' . $group}();

		$size = (int) $this->get('size');
		$multiple = $this->get('multiple');

		require_once JPATH_PLUGINS . '/system/nnframework/helpers/html.php';

		switch ($group)
		{
			case 'categories':
				return nnHtml::selectlist($options, $this->name, $this->value, $this->id, $size, $multiple);

			default:
				return nnHtml::selectlistsimple($options, $this->name, $this->value, $this->id, $size, $multiple);
		}
	}

	function getCategories()
	{
		$query = $this->db->getQuery(true)
			->select('COUNT(*)')
			->from('#__categories AS c')
			->where('c.extension = ' . $this->db->quote('com_content'))
			->where('c.parent_id > 0')
			->where('c.published > -1');
		$this->db->setQuery($query);
		$total = $this->db->loadResult();

		if ($total > $this->max_list_count)
		{
			return -1;
		}

		$show_ignore = $this->get('show_ignore');

		// assemble items to the array
		$options = array();
		if ($show_ignore)
		{
			if (in_array('-1', $this->value))
			{
				$this->value = array('-1');
			}
			$options[] = JHtml::_('select.option', '-1', '- ' . JText::_('NN_IGNORE') . ' -', 'value', 'text', 0);
			$options[] = JHtml::_('select.option', '-', '&nbsp;', 'value', 'text', 1);
		}

		$query->clear('select')
			->select('c.id, c.title, c.level, c.published, c.language')
			->order('c.lft');

		$this->db->setQuery($query);
		$items = $this->db->loadObjectList();

		foreach ($items as &$item)
		{
			if ($item->language && $item->language != '*')
			{
				$item->title .= ' (' . $item->language . ')';
			}
			$item->title = nnText::prepareSelectItem($item->title, $item->published);
			$option = JHtml::_('select.option', $item->id, $item->title);
			$option->level = $item->level - 1;
			$options[] = $option;
		}

		return $options;
	}

	function getItems()
	{
		$query = $this->db->getQuery(true)
			->select('COUNT(*)')
			->from('#__content AS i')
			->join('LEFT', '#__categories AS c ON c.id = i.catid')
			->where('i.access > -1');
		$this->db->setQuery($query);
		$total = $this->db->loadResult();

		if ($total > $this->max_list_count)
		{
			return -1;
		}

		$query->clear('select')
			->select('i.id, i.title as name, i.language, c.title as cat, i.access as published')
			->order('i.title, i.ordering, i.id');
		$this->db->setQuery($query);
		$list = $this->db->loadObjectList();

		// assemble items to the array
		$options = array();
		foreach ($list as $item)
		{
			$item->name .= ' [' . $item->id . ']';
			if ($item->language && $item->language != '*')
			{
				$item->name .= ' (' . $item->language . ')';
			}
			$item->name .= ($item->cat ? ' [' . $item->cat . ']' : '');
			$item->name = nnText::prepareSelectItem($item->name, $item->published);
			$options[] = JHtml::_('select.option', $item->id, $item->name, 'value', 'text', 0);
		}

		return $options;
	}

	private function get($val, $default = '')
	{
		return (isset($this->params[$val]) && (string) $this->params[$val] != '') ? (string) $this->params[$val] : $default;
	}
}
home/digilove/public_html/libraries/cms/html/content.php000064400000003660152355644750017512 0ustar00<?php
/**
 * @package     Joomla.Libraries
 * @subpackage  HTML
 *
 * @copyright   (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('JPATH_PLATFORM') or die;

/**
 * Utility class to fire onContentPrepare for non-article based content.
 *
 * @since  1.5
 */
abstract class JHtmlContent
{
	/**
	 * Fire onContentPrepare for content that isn't part of an article.
	 *
	 * @param   string  $text     The content to be transformed.
	 * @param   array   $params   The content params.
	 * @param   string  $context  The context of the content to be transformed.
	 *
	 * @return  string   The content after transformation.
	 *
	 * @since   1.5
	 */
	public static function prepare($text, $params = null, $context = 'text')
	{
		if ($params === null)
		{
			$params = new JObject;
		}

		$article = new stdClass;
		$article->text = $text;
		JPluginHelper::importPlugin('content');
		$dispatcher = JEventDispatcher::getInstance();
		$dispatcher->trigger('onContentPrepare', array($context, &$article, &$params, 0));

		return $article->text;
	}

	/**
	 * Returns an array of months.
	 *
	 * @param   Registry  $state  The state object.
	 *
	 * @return  array
	 *
	 * @since   3.9.0
	 */
	public static function months($state)
	{
		$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));

		foreach ($state as $key => $value) 
		{
			$model->setState($key, $value);
		}

		$model->setState('filter.category_id', $state->get('category.id'));
		$model->setState('list.start', 0);
		$model->setState('list.limit', -1);
		$model->setState('list.direction', 'asc');
		$model->setState('list.filter', '');

		$items = array();

		foreach ($model->countItemsByMonth() as $item)
		{
			$date    = new JDate($item->d);
			$items[] = JHtml::_('select.option', $item->d, $date->format('F Y') . ' [' . $item->c . ']');
		}

		return $items;
	}
}
home/digilove/public_html/110/plugins/system/nnframework/fields/content.php000064400000010040152356626650023103 0ustar00<?php
/**
 * Element: Content
 * Displays a multiselectbox of available categories / items
 *
 * @package         NoNumber Framework
 * @version         14.11.6
 *
 * @author          Peter van Westen <peter@nonumber.nl>
 * @link            http://www.nonumber.nl
 * @copyright       Copyright © 2014 NoNumber All Rights Reserved
 * @license         http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

defined('_JEXEC') or die;

require_once JPATH_PLUGINS . '/system/nnframework/helpers/parameters.php';
require_once JPATH_PLUGINS . '/system/nnframework/helpers/text.php';

class JFormFieldNN_Content extends JFormField
{
	public $type = 'Content';
	private $params = null;
	private $db = null;
	private $max_list_count = 0;

	protected function getInput()
	{
		$this->params = $this->element->attributes();
		$this->db = JFactory::getDbo();

		$parameters = nnParameters::getInstance();
		$params = $parameters->getPluginParams('nnframework');
		$this->max_list_count = $params->max_list_count;

		if (!is_array($this->value))
		{
			$this->value = explode(',', $this->value);
		}

		$group = $this->get('group', 'categories');
		$options = $this->{'get' . $group}();

		$size = (int) $this->get('size');
		$multiple = $this->get('multiple');

		require_once JPATH_PLUGINS . '/system/nnframework/helpers/html.php';

		switch ($group)
		{
			case 'categories':
				return nnHtml::selectlist($options, $this->name, $this->value, $this->id, $size, $multiple);

			default:
				return nnHtml::selectlistsimple($options, $this->name, $this->value, $this->id, $size, $multiple);
		}
	}

	function getCategories()
	{
		$query = $this->db->getQuery(true)
			->select('COUNT(*)')
			->from('#__categories AS c')
			->where('c.extension = ' . $this->db->quote('com_content'))
			->where('c.parent_id > 0')
			->where('c.published > -1');
		$this->db->setQuery($query);
		$total = $this->db->loadResult();

		if ($total > $this->max_list_count)
		{
			return -1;
		}

		$show_ignore = $this->get('show_ignore');

		// assemble items to the array
		$options = array();
		if ($show_ignore)
		{
			if (in_array('-1', $this->value))
			{
				$this->value = array('-1');
			}
			$options[] = JHtml::_('select.option', '-1', '- ' . JText::_('NN_IGNORE') . ' -', 'value', 'text', 0);
			$options[] = JHtml::_('select.option', '-', '&nbsp;', 'value', 'text', 1);
		}

		$query->clear('select')
			->select('c.id, c.title, c.level, c.published, c.language')
			->order('c.lft');

		$this->db->setQuery($query);
		$items = $this->db->loadObjectList();

		foreach ($items as &$item)
		{
			if ($item->language && $item->language != '*')
			{
				$item->title .= ' (' . $item->language . ')';
			}
			$item->title = nnText::prepareSelectItem($item->title, $item->published);
			$option = JHtml::_('select.option', $item->id, $item->title);
			$option->level = $item->level - 1;
			$options[] = $option;
		}

		return $options;
	}

	function getItems()
	{
		$query = $this->db->getQuery(true)
			->select('COUNT(*)')
			->from('#__content AS i')
			->join('LEFT', '#__categories AS c ON c.id = i.catid')
			->where('i.access > -1');
		$this->db->setQuery($query);
		$total = $this->db->loadResult();

		if ($total > $this->max_list_count)
		{
			return -1;
		}

		$query->clear('select')
			->select('i.id, i.title as name, i.language, c.title as cat, i.access as published')
			->order('i.title, i.ordering, i.id');
		$this->db->setQuery($query);
		$list = $this->db->loadObjectList();

		// assemble items to the array
		$options = array();
		foreach ($list as $item)
		{
			$item->name .= ' [' . $item->id . ']';
			if ($item->language && $item->language != '*')
			{
				$item->name .= ' (' . $item->language . ')';
			}
			$item->name .= ($item->cat ? ' [' . $item->cat . ']' : '');
			$item->name = nnText::prepareSelectItem($item->name, $item->published);
			$options[] = JHtml::_('select.option', $item->id, $item->name, 'value', 'text', 0);
		}

		return $options;
	}

	private function get($val, $default = '')
	{
		return (isset($this->params[$val]) && (string) $this->params[$val] != '') ? (string) $this->params[$val] : $default;
	}
}