Skip to content

Commit

Permalink
Cleanups, fixes and a bit of optimizations for site/components batch #3
Browse files Browse the repository at this point in the history
… (joomla#12292)

* Cleanups, fixes and a bit of optimizations for site/components batch #3

- com_content

Note: This is a single commit bundling all types of changes, since PR joomla#12261 which had detailed commits, was rejected as a whole

* Ch-Ch-Ch-Changes!

Made some changes as pointed out by @andrepereiradasilva

* A bit more...

* Revert

* Removed empty function, as there is a fallback. Change made according to comment from @wilsonge

* Included @andrepereiradasilva's suggestions

* Inserting whitespace before php closing tag
  • Loading branch information
frankmayer authored and wilsonge committed Dec 18, 2016
1 parent 239b6ac commit 22ea525
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 70 deletions.
8 changes: 4 additions & 4 deletions components/com_content/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function display($cachable = false, $urlparams = false)
$user = JFactory::getUser();

if ($user->get('id')
|| ($this->input->getMethod() == 'POST'
&& (($vName == 'category' && $this->input->get('layout') != 'blog') || $vName == 'archive' )))
|| ($this->input->getMethod() === 'POST'
&& (($vName === 'category' && $this->input->get('layout') !== 'blog') || $vName === 'archive' )))
{
$cachable = false;
}
Expand All @@ -95,13 +95,13 @@ public function display($cachable = false, $urlparams = false)
'Itemid' => 'INT');

// Check for edit form.
if ($vName == 'form' && !$this->checkEditId('com_content.edit.article', $id))
if ($vName === 'form' && !$this->checkEditId('com_content.edit.article', $id))
{
// Somehow the person just went to the form - we don't allow that.
return JError::raiseError(403, JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
}

if ($vName == 'article')
if ($vName === 'article')
{
// Get/Create the model
if ($model = $this->getModel($vName))
Expand Down
15 changes: 0 additions & 15 deletions components/com_content/controllers/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,6 @@ protected function getReturnPage()
}
}

/**
* Function that allows child controller access to model data after the data has been saved.
*
* @param JModelLegacy $model The data model object.
* @param array $validData The validated data.
*
* @return void
*
* @since 1.6
*/
protected function postSaveHook(JModelLegacy $model, $validData = array())
{
return;
}

/**
* Method to save a record.
*
Expand Down
6 changes: 3 additions & 3 deletions components/com_content/helpers/association.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ abstract class ContentHelperAssociation extends CategoryHelperAssociation
public static function getAssociations($id = 0, $view = null)
{
$jinput = JFactory::getApplication()->input;
$view = is_null($view) ? $jinput->get('view') : $view;
$view = $view === null ? $jinput->get('view') : $view;
$id = empty($id) ? $jinput->getInt('id') : $id;

if ($view == 'article' || $view == 'category' || $view == 'featured')
if ($view === 'article' || $view === 'category' || $view === 'featured')
{
if ($id)
{
Expand All @@ -53,7 +53,7 @@ public static function getAssociations($id = 0, $view = null)
}
}

if ($view == 'category' || $view == 'categories')
if ($view === 'category' || $view === 'categories')
{
return self::getCategoryAssociations($id, 'com_content');
}
Expand Down
2 changes: 1 addition & 1 deletion components/com_content/helpers/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static function buildVotingQuery($params = null)
$join = '';
}

return array ('select' => $select, 'join' => $join);
return array('select' => $select, 'join' => $join);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions components/com_content/helpers/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function getArticleRoute($id, $catid = 0, $language = 0)
$link .= '&catid=' . $catid;
}

if ($language && $language != '*' && JLanguageMultilang::isEnabled())
if ($language && $language !== '*' && JLanguageMultilang::isEnabled())
{
$link .= '&lang=' . $language;
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public static function getCategoryRoute($catid, $language = 0)
{
$link = 'index.php?option=com_content&view=category&id=' . $id;

if ($language && $language != '*' && JLanguageMultilang::isEnabled())
if ($language && $language !== '*' && JLanguageMultilang::isEnabled())
{
$link .= '&lang=' . $language;
}
Expand Down
10 changes: 5 additions & 5 deletions components/com_content/models/articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ protected function getListQuery()
// Join over the frontpage articles if required.
if ($this->getState('filter.frontpage'))
{
if ($orderby_sec == 'front')
if ($orderby_sec === 'front')
{
$query->join('INNER', '#__content_frontpage AS fp ON fp.content_id = a.id');
}
Expand All @@ -234,7 +234,7 @@ protected function getListQuery()
$query->where('a.featured = 1');
}
}
elseif ($orderby_sec == 'front' || $this->getState('list.ordering') == 'fp.ordering')
elseif ($orderby_sec === 'front' || $this->getState('list.ordering') === 'fp.ordering')
{
$query->join('LEFT', '#__content_frontpage AS fp ON fp.content_id = a.id');
}
Expand Down Expand Up @@ -503,7 +503,7 @@ protected function getListQuery()
}

// Process the filter for list views with user-entered filters
if (is_object($params) && ($params->get('filter_field') != 'hide') && ($filter = $this->getState('list.filter')))
if (is_object($params) && ($params->get('filter_field') !== 'hide') && ($filter = $this->getState('list.filter')))
{
// Clean filter variable
$filter = StringHelper::strtolower($filter);
Expand Down Expand Up @@ -591,8 +591,8 @@ public function getItems()
/*For blogs, article params override menu item params only if menu param = 'use_article'
Otherwise, menu item params control the layout
If menu item is 'use_article' and there is no article param, use global*/
if (($input->getString('layout') == 'blog') || ($input->getString('view') == 'featured')
|| ($this->getState('params')->get('layout_type') == 'blog'))
if (($input->getString('layout') === 'blog') || ($input->getString('view') === 'featured')
|| ($this->getState('params')->get('layout_type') === 'blog'))
{
// Create an array of just the params set to 'use_article'
$menuParamsArray = $this->getState('params')->toArray();
Expand Down
8 changes: 5 additions & 3 deletions components/com_content/models/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected function populateState($ordering = null, $direction = null)
$this->setState('list.start', $app->input->get('limitstart', 0, 'uint'));

// Set limit for query. If list, use parameter. If blog, add blog parameters for limit.
if (($app->input->get('layout') == 'blog') || $params->get('layout_type') == 'blog')
if (($app->input->get('layout') === 'blog') || $params->get('layout_type') === 'blog')
{
$limit = $params->get('num_leading_articles') + $params->get('num_intro_articles') + $params->get('num_links');
$this->setState('list.links', $params->get('num_links'));
Expand Down Expand Up @@ -458,9 +458,11 @@ public function &getChildren()
{
$params = $this->getState()->get('params');

if ($params->get('orderby_pri') == 'alpha' || $params->get('orderby_pri') == 'ralpha')
$orderByPri = $params->get('orderby_pri');

if ($orderByPri === 'alpha' || $orderByPri === 'ralpha')
{
$this->_children = ArrayHelper::sortObjects($this->_children, 'title', ($params->get('orderby_pri') == 'alpha') ? 1 : (-1));
$this->_children = ArrayHelper::sortObjects($this->_children, 'title', ($orderByPri === 'alpha') ? 1 : (-1));
}
}

Expand Down
14 changes: 6 additions & 8 deletions components/com_content/models/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,15 @@ public function getReturnPage()
public function save($data)
{
// Associations are not edited in frontend ATM so we have to inherit them
if (JLanguageAssociations::isEnabled() && !empty($data['id']))
if (JLanguageAssociations::isEnabled() && !empty($data['id'])
&& $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $data['id']))
{
if ($associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $data['id']))
foreach ($associations as $tag => $associated)
{
foreach ($associations as $tag => $associated)
{
$associations[$tag] = (int) $associated->id;
}

$data['associations'] = $associations;
$associations[$tag] = (int) $associated->id;
}

$data['associations'] = $associations;
}

return parent::save($data);
Expand Down
2 changes: 1 addition & 1 deletion components/com_content/views/archive/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<form id="adminForm" action="<?php echo JRoute::_('index.php'); ?>" method="post" class="form-inline">
<fieldset class="filters">
<div class="filter-search">
<?php if ($this->params->get('filter_field') != 'hide') : ?>
<?php if ($this->params->get('filter_field') !== 'hide') : ?>
<label class="filter-search-lbl element-invisible" for="filter-search"><?php echo JText::_('COM_CONTENT_TITLE_FILTER_LABEL') . '&#160;'; ?></label>
<input type="text" name="filter-search" id="filter-search" value="<?php echo $this->escape($this->filter); ?>" class="inputbox span2" onchange="document.getElementById('adminForm').submit();" placeholder="<?php echo JText::_('COM_CONTENT_TITLE_FILTER_LABEL'); ?>" />
<?php endif; ?>
Expand Down
4 changes: 2 additions & 2 deletions components/com_content/views/archive/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function display($tpl = null)
$item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id;

// No link for ROOT category
if ($item->parent_alias == 'root')
if ($item->parent_alias === 'root')
{
$item->parent_slug = null;
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public function display($tpl = null)
$years = array();
$years[] = JHtml::_('select.option', null, JText::_('JYEAR'));

for ($i = 0; $i < count($this->years); $i++)
for ($i = 0, $iMax = count($this->years); $i < $iMax; $i++)
{
$years[] = JHtml::_('select.option', $this->years[$i], $this->years[$i]);
}
Expand Down
6 changes: 3 additions & 3 deletions components/com_content/views/article/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function display($tpl = null)
$item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id;

// No link for ROOT category
if ($item->parent_alias == 'root')
if ($item->parent_alias === 'root')
{
$item->parent_slug = null;
}
Expand Down Expand Up @@ -213,15 +213,15 @@ protected function _prepareDocument()
$id = (int) @$menu->query['id'];

// If the menu item does not concern this article
if ($menu && ($menu->query['option'] != 'com_content' || $menu->query['view'] != 'article' || $id != $this->item->id))
if ($menu && ($menu->query['option'] !== 'com_content' || $menu->query['view'] !== 'article' || $id != $this->item->id))
{
// If a browser page title is defined, use that, then fall back to the article title if set, then fall back to the page_title option
$title = $this->item->params->get('article_page_title', $this->item->title ?: $title);

$path = array(array('title' => $this->item->title, 'link' => ''));
$category = JCategories::getInstance('Content')->get($this->item->catid);

while ($category && ($menu->query['option'] != 'com_content' || $menu->query['view'] == 'article' || $id != $category->id) && $category->id > 1)
while ($category && ($menu->query['option'] !== 'com_content' || $menu->query['view'] === 'article' || $id != $category->id) && $category->id > 1)
{
$path[] = array('title' => $category->title, 'link' => ContentHelperRoute::getCategoryRoute($category->id));
$category = $category->getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$class = ' class="first"';
$lang = JFactory::getLanguage();

if (count($this->items[$this->parent->id]) > 0 && $this->maxLevelcat != 0) :
if ($this->maxLevelcat != 0 && count($this->items[$this->parent->id]) > 0) :
?>
<?php foreach ($this->items[$this->parent->id] as $id => $item) : ?>
<?php
Expand Down
4 changes: 2 additions & 2 deletions components/com_content/views/category/tmpl/blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<?php if (!empty($this->intro_items)) : ?>
<?php foreach ($this->intro_items as $key => &$item) : ?>
<?php $rowcount = ((int) $key % (int) $this->columns) + 1; ?>
<?php if ($rowcount == 1) : ?>
<?php if ($rowcount === 1) : ?>
<?php $row = $counter / $this->columns; ?>
<div class="items-row cols-<?php echo (int) $this->columns; ?> <?php echo 'row-' . $row; ?> row-fluid clearfix">
<?php endif; ?>
Expand All @@ -101,7 +101,7 @@
</div>
<?php endif; ?>

<?php if (!empty($this->children[$this->category->id]) && $this->maxLevel != 0) : ?>
<?php if ($this->maxLevel != 0 && !empty($this->children[$this->category->id])) : ?>
<div class="cat-children">
<?php if ($this->params->get('show_category_heading_title_text', 1) == 1) : ?>
<h3> <?php echo JText::_('JGLOBAL_SUBCATEGORIES'); ?> </h3>
Expand Down
8 changes: 4 additions & 4 deletions components/com_content/views/category/tmpl/blog_children.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$class = ' class="first"';
$lang = JFactory::getLanguage();

if (count($this->children[$this->category->id]) > 0 && $this->maxLevel != 0) : ?>
if ($this->maxLevel != 0 && count($this->children[$this->category->id]) > 0) : ?>

<?php foreach ($this->children[$this->category->id] as $id => $child) : ?>
<?php
Expand All @@ -35,7 +35,7 @@
<a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($child->id)); ?>">
<?php echo $this->escape($child->title); ?></a>

<?php if (count($child->getChildren()) > 0 && $this->maxLevel > 1) : ?>
<?php if ($this->maxLevel > 1 && count($child->getChildren()) > 0) : ?>
<a href="#category-<?php echo $child->id; ?>" data-toggle="collapse" data-toggle="button" class="btn btn-mini pull-right"><span class="icon-plus"></span></a>
<?php endif; ?>
</h3>
Expand All @@ -49,7 +49,7 @@
</span>
<?php endif; ?>

<?php if (count($child->getChildren()) > 0 && $this->maxLevel > 1) : ?>
<?php if ($this->maxLevel > 1 && count($child->getChildren()) > 0) : ?>
<a href="#category-<?php echo $child->id; ?>" data-toggle="collapse" data-toggle="button" class="btn btn-mini pull-right"><span class="icon-plus"></span></a>
<?php endif; ?>
</h3>
Expand All @@ -63,7 +63,7 @@
<?php endif; ?>
<?php endif; ?>

<?php if (count($child->getChildren()) > 0 && $this->maxLevel > 1) : ?>
<?php if ($this->maxLevel > 1 && count($child->getChildren()) > 0) : ?>
<div class="collapse fade" id="category-<?php echo $child->id; ?>">
<?php
$this->children[$child->id] = $child->getChildren();
Expand Down
14 changes: 7 additions & 7 deletions components/com_content/views/category/tmpl/default_articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
$tableClass = $this->params->get('show_headings') != 1 ? ' table-noheader' : '';
?>
<form action="<?php echo htmlspecialchars(JUri::getInstance()->toString()); ?>" method="post" name="adminForm" id="adminForm" class="form-inline">
<?php if ($this->params->get('filter_field') != 'hide' || $this->params->get('show_pagination_limit')) : ?>
<?php if ($this->params->get('filter_field') !== 'hide' || $this->params->get('show_pagination_limit')) : ?>
<fieldset class="filters btn-toolbar clearfix">
<legend class="hide"><?php echo JText::_('COM_CONTENT_FORM_FILTER_LEGEND'); ?></legend>
<?php if ($this->params->get('filter_field') != 'hide') : ?>
<?php if ($this->params->get('filter_field') !== 'hide') : ?>
<div class="btn-group">
<?php if ($this->params->get('filter_field') != 'tag') : ?>
<?php if ($this->params->get('filter_field') !== 'tag') : ?>
<label class="filter-search-lbl element-invisible" for="filter-search">
<?php echo JText::_('COM_CONTENT_' . $this->params->get('filter_field') . '_FILTER_LABEL') . '&#160;'; ?>
</label>
Expand Down Expand Up @@ -97,11 +97,11 @@
</th>
<?php if ($date = $this->params->get('list_show_date')) : ?>
<th scope="col" id="categorylist_header_date">
<?php if ($date == 'created') : ?>
<?php if ($date === 'created') : ?>
<?php echo JHtml::_('grid.sort', 'COM_CONTENT_' . $date . '_DATE', 'a.created', $listDirn, $listOrder); ?>
<?php elseif ($date == 'modified') : ?>
<?php elseif ($date === 'modified') : ?>
<?php echo JHtml::_('grid.sort', 'COM_CONTENT_' . $date . '_DATE', 'a.modified', $listDirn, $listOrder); ?>
<?php elseif ($date == 'published') : ?>
<?php elseif ($date === 'published') : ?>
<?php echo JHtml::_('grid.sort', 'COM_CONTENT_' . $date . '_DATE', 'a.publish_up', $listDirn, $listOrder); ?>
<?php endif; ?>
</th>
Expand Down Expand Up @@ -209,7 +209,7 @@
<td headers="categorylist_header_author" class="list-author">
<?php if (!empty($article->author) || !empty($article->created_by_alias)) : ?>
<?php $author = $article->author ?>
<?php $author = ($article->created_by_alias ?: $author); ?>
<?php $author = $article->created_by_alias ?: $author; ?>
<?php if (!empty($article->contact_link) && $this->params->get('link_author') == true) : ?>
<?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', JHtml::_('link', $article->contact_link, $author)); ?>
<?php else : ?>
Expand Down
8 changes: 4 additions & 4 deletions components/com_content/views/category/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function display($tpl = null)
$item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id;

// No link for ROOT category
if ($item->parent_alias == 'root')
if ($item->parent_alias === 'root')
{
$item->parent_slug = null;
}
Expand Down Expand Up @@ -144,7 +144,7 @@ public function display($tpl = null)

// For blog layouts, preprocess the breakdown of leading, intro and linked articles.
// This makes it much easier for the designer to just interrogate the arrays.
if (($params->get('layout_type') == 'blog') || ($this->getLayout() == 'blog'))
if ($params->get('layout_type') === 'blog' || $this->getLayout() === 'blog')
{
foreach ($this->items as $i => $item)
{
Expand Down Expand Up @@ -270,12 +270,12 @@ protected function prepareDocument()
$menu = $this->menu;
$id = (int) @$menu->query['id'];

if ($menu && ($menu->query['option'] != 'com_content' || $menu->query['view'] == 'article' || $id != $this->category->id))
if ($menu && ($menu->query['option'] !== 'com_content' || $menu->query['view'] === 'article' || $id != $this->category->id))
{
$path = array(array('title' => $this->category->title, 'link' => ''));
$category = $this->category->getParent();

while (($menu->query['option'] != 'com_content' || $menu->query['view'] == 'article' || $id != $category->id) && $category->id > 1)
while (($menu->query['option'] !== 'com_content' || $menu->query['view'] === 'article' || $id != $category->id) && $category->id > 1)
{
$path[] = array('title' => $category->title, 'link' => ContentHelperRoute::getCategoryRoute($category->id));
$category = $category->getParent();
Expand Down
2 changes: 1 addition & 1 deletion components/com_content/views/featured/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
$rowcount = (((int) $key - 1) % (int) $this->columns) + 1;
$row = $counter / $this->columns;

if ($rowcount == 1) : ?>
if ($rowcount === 1) : ?>

<div class="items-row cols-<?php echo (int) $this->columns; ?> <?php echo 'row-' . $row; ?> row-fluid">
<?php endif; ?>
Expand Down
4 changes: 2 additions & 2 deletions components/com_content/views/featured/view.feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function display($tpl = null)
$description = '<p><img src="' . $image . '" /></p>';
}

$description .= ($params->get('feed_summary', 0) ? $row->introtext . $row->fulltext : $row->introtext);
$description .= ($params->get('feed_summary', 0) ? $row->introtext . $row->fulltext : $row->introtext);
$author = $row->created_by_alias ?: $row->author;

// Load individual item creator class
Expand All @@ -93,7 +93,7 @@ public function display($tpl = null)

$item->author = $author;

if ($feedEmail == 'site')
if ($feedEmail === 'site')
{
$item->authorEmail = $siteEmail;
}
Expand Down
Loading

0 comments on commit 22ea525

Please sign in to comment.