Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from
Dec 18, 2016
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
1 change: 0 additions & 1 deletion components/com_content/controllers/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ protected function getReturnPage()
*/
protected function postSaveHook(JModelLegacy $model, $validData = array())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. I didn't follow the trail, there. Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean revert the removal?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
return;
}

/**
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')
if ($view === 'article')
{
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
8 changes: 3 additions & 5 deletions components/com_content/helpers/icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function create($category, $params, $attribs = array(), $legacy =
// Add the button classes to the attribs array
if (isset($attribs['class']))
{
$attribs['class'] = $attribs['class'] . ' btn btn-primary';
$attribs['class'] .= ' btn btn-primary';
}
else
{
Expand Down Expand Up @@ -111,9 +111,7 @@ public static function email($article, $params, $attribs = array(), $legacy = fa
$attribs['onclick'] = "window.open(this.href,'win2','" . $status . "'); return false;";
$attribs['rel'] = 'nofollow';

$output = JHtml::_('link', JRoute::_($url), $text, $attribs);

return $output;
return JHtml::_('link', JRoute::_($url), $text, $attribs);
}

/**
Expand Down Expand Up @@ -190,7 +188,7 @@ public static function edit($article, $params, $attribs = array(), $legacy = fal
}

$date = JHtml::_('date', $article->created);
$author = $article->created_by_alias ? $article->created_by_alias : $article->author;
$author = $article->created_by_alias ?: $article->author;

$overlib .= '<br />';
$overlib .= $date;
Expand Down
4 changes: 1 addition & 3 deletions components/com_content/helpers/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ public static function buildVotingQuery($params = null)
$join = '';
}

$results = array ('select' => $select, 'join' => $join);

return $results;
return array ('select' => $select, 'join' => $join);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove the space here?

}

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

if ($language && $language != "*" && JLanguageMultilang::isEnabled())
if ($language && $language !== '*' && JLanguageMultilang::isEnabled())
{
$link .= '&lang=' . $language;
$needles['language'] = $language;
Expand Down Expand Up @@ -100,7 +100,7 @@ public static function getCategoryRoute($catid, $language = 0)
$needles['category'] = $catids;
$needles['categories'] = $catids;

if ($language && $language != "*" && JLanguageMultilang::isEnabled())
if ($language && $language !== '*' && JLanguageMultilang::isEnabled())
{
$link .= '&lang=' . $language;
$needles['language'] = $language;
Expand Down Expand Up @@ -164,7 +164,7 @@ protected static function _findItem($needles = null)
$attributes = array('component_id');
$values = array($component->id);

if ($language != '*')
if ($language !== '*')
{
$attributes[] = 'language';
$values[] = array($needles['language'], '*');
Expand All @@ -174,7 +174,7 @@ protected static function _findItem($needles = null)

foreach ($items as $item)
{
if (isset($item->query) && isset($item->query['view']))
if (isset($item->query, $item->query['view']))
{
$view = $item->query['view'];

Expand All @@ -190,7 +190,7 @@ protected static function _findItem($needles = null)
* language != * can override existing entries
* language == * cannot override existing entries
*/
if (!isset(self::$lookup[$language][$view][$item->query['id']]) || $item->language != '*')
if ($item->language !== '*' || !isset(self::$lookup[$language][$view][$item->query['id']]))
{
self::$lookup[$language][$view][$item->query['id']] = $item->id;
}
Expand Down Expand Up @@ -220,8 +220,8 @@ protected static function _findItem($needles = null)
$active = $menus->getActive();

if ($active
&& $active->component == 'com_content'
&& ($language == '*' || in_array($active->language, array('*', $language)) || !JLanguageMultilang::isEnabled()))
&& $active->component === 'com_content'
&& ($language === '*' || in_array($active->language, array('*', $language)) || !JLanguageMultilang::isEnabled()))
{
return $active->id;
}
Expand Down
4 changes: 2 additions & 2 deletions components/com_content/models/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function getItem($pk = null)
}

// Check for published state if filter set.
if (((is_numeric($published)) || (is_numeric($archived))) && (($data->state != $published) && ($data->state != $archived)))
if ((is_numeric($published) || is_numeric($archived)) && (($data->state != $published) && ($data->state != $archived)))
{
return JError::raiseError(404, JText::_('COM_CONTENT_ERROR_ARTICLE_NOT_FOUND'));
}
Expand Down Expand Up @@ -333,7 +333,7 @@ public function storeVote($pk = 0, $rate = 0)
}
else
{
if ($userIP != ($rating->lastip))
if ($userIP != $rating->lastip)
{
$query = $db->getQuery(true);

Expand Down
12 changes: 6 additions & 6 deletions components/com_content/models/articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,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 @@ -233,7 +233,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 All @@ -244,7 +244,7 @@ protected function getListQuery()

// Join over the users for the author and modified_by names.
$query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author")
->select("ua.email AS author_email")
->select('ua.email AS author_email')

->join('LEFT', '#__users AS ua ON ua.id = a.created_by')
->join('LEFT', '#__users AS uam ON uam.id = a.modified_by');
Expand Down Expand Up @@ -498,7 +498,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 = JString::strtolower($filter);
Expand Down Expand Up @@ -587,8 +587,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
7 changes: 4 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 @@ -457,9 +457,10 @@ 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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cs: can we have an aempty line before the if statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course :)

{
$this->_children = ArrayHelper::sortObjects($this->_children, 'title', ($params->get('orderby_pri') == 'alpha') ? 1 : (-1));
$this->_children = ArrayHelper::sortObjects($this->_children, 'title', ($params->get('orderby_pri') === 'alpha') ? 1 : (-1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we getting orderby_pri param again here?

}
}

Expand Down
6 changes: 2 additions & 4 deletions components/com_content/models/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,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)
{
$associations[$tag] = (int) $associated->id;
}

$data['associations'] = $associations;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you remove one if block you should remove one tab inside the if.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted as in other PR

}
}

return parent::save($data);
Expand Down
29 changes: 14 additions & 15 deletions components/com_content/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function build(&$query)
}

// Check again
if ($menuItemGiven && isset($menuItem) && $menuItem->component != 'com_content')
if ($menuItemGiven && isset($menuItem) && $menuItem->component !== 'com_content')
{
$menuItemGiven = false;
unset($query['Itemid']);
Expand Down Expand Up @@ -91,7 +91,7 @@ public function build(&$query)
return $segments;
}

if ($view == 'category' || $view == 'article')
if ($view === 'category' || $view === 'article')
{
if (!$menuItemGiven)
{
Expand All @@ -100,9 +100,9 @@ public function build(&$query)

unset($query['view']);

if ($view == 'article')
if ($view === 'article')
{
if (isset($query['id']) && isset($query['catid']) && $query['catid'])
if (isset($query['id'], $query['catid']) && $query['catid'])
{
$catid = $query['catid'];

Expand Down Expand Up @@ -162,7 +162,7 @@ public function build(&$query)

foreach ($path as $id)
{
if ((int) $id == (int) $mCatid)
if ((int) $id === (int) $mCatid)
{
break;
}
Expand All @@ -181,7 +181,7 @@ public function build(&$query)

$segments = array_merge($segments, $array);

if ($view == 'article')
if ($view === 'article')
{
if ($advanced)
{
Expand All @@ -195,13 +195,12 @@ public function build(&$query)
$segments[] = $id;
}

unset($query['id']);
unset($query['catid']);
unset($query['id'], $query['catid']);
}

if ($view == 'archive')
if ($view === 'archive')
{
if (!$menuItemGiven || $menuItem->query['view'] != 'archive')
if (!$menuItemGiven || $menuItem->query['view'] !== 'archive')
{
// Did not work without removing Itemid
if (isset($menuItem))
Expand All @@ -227,7 +226,7 @@ public function build(&$query)
}
}

if ($view == 'featured')
if ($view === 'featured')
{
if (!$menuItemGiven)
{
Expand All @@ -252,7 +251,7 @@ public function build(&$query)
}
else
{
if ($query['layout'] == 'default')
if ($query['layout'] === 'default')
{
unset($query['layout']);
}
Expand Down Expand Up @@ -306,7 +305,7 @@ public function parse(&$segments)
$vars['view'] = $segments[0];

// Called if no menu item created
if ($vars['view'] == 'archive')
if ($vars['view'] === 'archive')
{
$vars['year'] = $count >= 2 ? $segments[$count - 2] : null;
$vars['month'] = $segments[$count - 1];
Expand All @@ -324,7 +323,7 @@ public function parse(&$segments)
* We test it first to see if it is a category. If the id and alias match a category,
* then we assume it is a category. If they don't we assume it is an article
*/
if ($count == 1)
if ($count === 1)
{
// We check to see if an alias is given. If not, we assume it is an article
if (strpos($segments[0], ':') === false)
Expand Down Expand Up @@ -429,7 +428,7 @@ public function parse(&$segments)
}
}

if ($found == 0)
if ($found === 0)
{
if ($advanced)
{
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</h2>
<?php if ($params->get('show_author') && !empty($item->author )) : ?>
<div class="createdby" itemprop="author" itemscope itemtype="https://schema.org/Person">
<?php $author = ($item->created_by_alias) ? $item->created_by_alias : $item->author; ?>
<?php $author = $item->created_by_alias ?: $item->author; ?>
<?php $author = '<span itemprop="name">' . $author . '</span>'; ?>
<?php if (!empty($item->contact_link) && $params->get('link_author') == true) : ?>
<?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', JHtml::_('link', $this->item->contact_link, $author, array('itemprop' => 'url'))); ?>
Expand Down
Loading