Skip to content

Commit

Permalink
Use setDocumentHeadDatas to set document head data for some views
Browse files Browse the repository at this point in the history
  • Loading branch information
joomdonation committed Dec 30, 2017
1 parent d7c0df7 commit 3210416
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 118 deletions.
33 changes: 7 additions & 26 deletions components/com_content/views/category/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,51 +212,32 @@ public function display($tpl = null)
$title = $this->category->title;
}

$this->document->setTitle($title);
$this->params->set('page_title', $title);

if ($this->category->metadesc)
{
$this->document->setDescription($this->category->metadesc);
}
elseif ($this->params->get('menu-meta_description'))
{
$this->document->setDescription($this->params->get('menu-meta_description'));
$this->params->set('menu-meta_description', $this->category->metadesc);
}

if ($this->category->metakey)
{
$this->document->setMetadata('keywords', $this->category->metakey);
}
elseif ($this->params->get('menu-meta_keywords'))
{
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
}

if ($this->params->get('robots'))
{
$this->document->setMetadata('robots', $this->params->get('robots'));
$this->params->set('keywords', $this->category->metakey);
}

if (!is_object($this->category->metadata))
{
$this->category->metadata = new Registry($this->category->metadata);
}

if (($app->get('MetaAuthor') == '1') && $this->category->get('author', ''))
{
$this->document->setMetaData('author', $this->category->get('author', ''));
}

$mdata = $this->category->metadata->toArray();

foreach ($mdata as $k => $v)
if ($app->get('MetaAuthor') == '1' && $this->category->get('author', ''))
{
if ($v)
{
$this->document->setMetadata($k, $v);
}
$mdata['author'] = $this->category->get('author', '');
}

$this->params->set('metadata', $mdata);

return parent::display($tpl);
}

Expand Down
50 changes: 6 additions & 44 deletions libraries/src/MVC/View/CategoriesView.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Joomla\CMS\MVC\View;

use Joomla\CMS\Factory;

defined('JPATH_PLATFORM') or die;

/**
Expand Down Expand Up @@ -56,7 +58,7 @@ public function display($tpl = null)
$items = $this->get('Items');
$parent = $this->get('Parent');

$app = \JFactory::getApplication();
$app = Factory::getApplication();

// Check for errors.
if (count($errors = $this->get('Errors')))
Expand All @@ -66,14 +68,7 @@ public function display($tpl = null)
return false;
}

if ($items === false)
{
$app->enqueueMessage(\JText::_('JGLOBAL_CATEGORY_NOT_FOUND'), 'error');

return false;
}

if ($parent == false)
if ($items === false || $parent === false)
{
$app->enqueueMessage(\JText::_('JGLOBAL_CATEGORY_NOT_FOUND'), 'error');

Expand Down Expand Up @@ -106,11 +101,8 @@ public function display($tpl = null)
*/
protected function prepareDocument()
{
$app = \JFactory::getApplication();
$menus = $app->getMenu();

// Because the application sets a default page title, we need to get it from the menu item itself
$menu = $menus->getActive();
$menu = Factory::getApplication()->getMenu()->getActive();

if ($menu)
{
Expand All @@ -121,36 +113,6 @@ protected function prepareDocument()
$this->params->def('page_heading', \JText::_($this->pageHeading));
}

$title = $this->params->get('page_title', '');

if (empty($title))
{
$title = $app->get('sitename');
}
elseif ($app->get('sitename_pagetitles', 0) == 1)
{
$title = \JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
}
elseif ($app->get('sitename_pagetitles', 0) == 2)
{
$title = \JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
}

$this->document->setTitle($title);

if ($this->params->get('menu-meta_description'))
{
$this->document->setDescription($this->params->get('menu-meta_description'));
}

if ($this->params->get('menu-meta_keywords'))
{
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
}

if ($this->params->get('robots'))
{
$this->document->setMetadata('robots', $this->params->get('robots'));
}
$this->setDocumentHeadDatas();
}
}
58 changes: 10 additions & 48 deletions libraries/src/MVC/View/CategoryView.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Joomla\CMS\MVC\View;

use Joomla\CMS\Factory;

defined('JPATH_PLATFORM') or die;

/**
Expand Down Expand Up @@ -107,8 +109,8 @@ class CategoryView extends HtmlView
*/
public function commonCategoryDisplay()
{
$app = \JFactory::getApplication();
$user = \JFactory::getUser();
$app = Factory::getApplication();
$user = Factory::getUser();
$params = $app->getParams();

// Get some data from the models
Expand All @@ -123,20 +125,13 @@ public function commonCategoryDisplay()
$children = $this->get('Children');
$parent = $this->get('Parent');

if ($category == false)
{
return \JError::raiseError(404, \JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
}

if ($parent == false)
if ($category == false || $parent == false)
{
return \JError::raiseError(404, \JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
}

// Check whether category access level allows access.
$groups = $user->getAuthorisedViewLevels();

if (!in_array($category->access, $groups))
if (!in_array($category->access, $user->getAuthorisedViewLevels()))
{
return \JError::raiseError(403, \JText::_('JERROR_ALERTNOAUTHOR'));
}
Expand Down Expand Up @@ -165,6 +160,7 @@ public function commonCategoryDisplay()
if ($this->runPlugins)
{
\JPluginHelper::importPlugin('content');
$dispatcher = \JEventDispatcher::getInstance();

foreach ($items as $itemElement)
{
Expand All @@ -174,8 +170,6 @@ public function commonCategoryDisplay()
// For some plugins.
!empty($itemElement->description)? $itemElement->text = $itemElement->description : $itemElement->text = null;

$dispatcher = \JEventDispatcher::getInstance();

$dispatcher->trigger('onContentPrepare', array($this->extension . '.category', &$itemElement, &$itemElement->params, 0));

$results = $dispatcher->trigger('onContentAfterTitle', array($this->extension . '.category', &$itemElement, &$itemElement->core_params, 0));
Expand Down Expand Up @@ -251,13 +245,11 @@ public function display($tpl = null)
*/
protected function prepareDocument()
{
$app = \JFactory::getApplication();
$menus = $app->getMenu();
$app = Factory::getApplication();
$this->pathway = $app->getPathway();
$title = null;

// Because the application sets a default page title, we need to get it from the menu item itself
$this->menu = $menus->getActive();
$this->menu = $app->getMenu()->getActive();

if ($this->menu)
{
Expand All @@ -268,37 +260,7 @@ protected function prepareDocument()
$this->params->def('page_heading', \JText::_($this->defaultPageTitle));
}

$title = $this->params->get('page_title', '');

if (empty($title))
{
$title = $app->get('sitename');
}
elseif ($app->get('sitename_pagetitles', 0) == 1)
{
$title = \JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
}
elseif ($app->get('sitename_pagetitles', 0) == 2)
{
$title = \JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
}

$this->document->setTitle($title);

if ($this->params->get('menu-meta_description'))
{
$this->document->setDescription($this->params->get('menu-meta_description'));
}

if ($this->params->get('menu-meta_keywords'))
{
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
}

if ($this->params->get('robots'))
{
$this->document->setMetadata('robots', $this->params->get('robots'));
}
$this->setDocumentHeadDatas();
}

/**
Expand Down

0 comments on commit 3210416

Please sign in to comment.