From fe3b1cb4798ff197cadfa5c00dae359bd097e0bf Mon Sep 17 00:00:00 2001 From: Frank Mayer Date: Mon, 3 Oct 2016 17:58:51 +0300 Subject: [PATCH 1/7] 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 #12261 which had detailed commits, was rejected as a whole --- components/com_content/controller.php | 8 ++--- .../com_content/controllers/article.php | 1 - .../com_content/helpers/association.php | 6 ++-- components/com_content/helpers/icon.php | 8 ++--- components/com_content/helpers/query.php | 4 +-- components/com_content/helpers/route.php | 14 ++++----- components/com_content/models/article.php | 4 +-- components/com_content/models/articles.php | 12 ++++---- components/com_content/models/category.php | 7 +++-- components/com_content/models/form.php | 6 ++-- components/com_content/router.php | 29 +++++++++---------- .../views/archive/tmpl/default.php | 2 +- .../views/archive/tmpl/default_items.php | 2 +- .../com_content/views/archive/view.html.php | 12 ++++---- .../views/article/tmpl/default.php | 6 ++-- .../views/article/tmpl/default_links.php | 4 +-- .../com_content/views/article/view.html.php | 10 +++---- .../views/categories/tmpl/default_items.php | 6 ++-- .../com_content/views/category/tmpl/blog.php | 8 ++--- .../views/category/tmpl/blog_children.php | 8 ++--- .../views/category/tmpl/default_articles.php | 14 ++++----- .../views/category/tmpl/default_children.php | 6 ++-- .../com_content/views/category/view.feed.php | 2 +- .../com_content/views/category/view.html.php | 10 +++---- .../views/featured/tmpl/default.php | 6 ++-- .../com_content/views/featured/view.feed.php | 4 +-- .../com_content/views/featured/view.html.php | 6 ++-- .../com_content/views/form/tmpl/edit.php | 4 +-- .../com_content/views/form/view.html.php | 4 +-- 29 files changed, 103 insertions(+), 110 deletions(-) diff --git a/components/com_content/controller.php b/components/com_content/controller.php index ae86b40a271b4..efaf6c087d4ca 100644 --- a/components/com_content/controller.php +++ b/components/com_content/controller.php @@ -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; } @@ -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)) diff --git a/components/com_content/controllers/article.php b/components/com_content/controllers/article.php index be4ebf16b112d..a86c062355348 100644 --- a/components/com_content/controllers/article.php +++ b/components/com_content/controllers/article.php @@ -286,7 +286,6 @@ protected function getReturnPage() */ protected function postSaveHook(JModelLegacy $model, $validData = array()) { - return; } /** diff --git a/components/com_content/helpers/association.php b/components/com_content/helpers/association.php index 278cdbeb5e8b5..bea3aca6295b8 100644 --- a/components/com_content/helpers/association.php +++ b/components/com_content/helpers/association.php @@ -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) { @@ -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'); } diff --git a/components/com_content/helpers/icon.php b/components/com_content/helpers/icon.php index a0a034fca05f6..84eb0d5332ed0 100644 --- a/components/com_content/helpers/icon.php +++ b/components/com_content/helpers/icon.php @@ -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 { @@ -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); } /** @@ -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; diff --git a/components/com_content/helpers/query.php b/components/com_content/helpers/query.php index bcb789bc03142..4b4d25247eaeb 100644 --- a/components/com_content/helpers/query.php +++ b/components/com_content/helpers/query.php @@ -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); } /** diff --git a/components/com_content/helpers/route.php b/components/com_content/helpers/route.php index 5dece4143a292..be3434a5f7681 100644 --- a/components/com_content/helpers/route.php +++ b/components/com_content/helpers/route.php @@ -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; @@ -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; @@ -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'], '*'); @@ -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']; @@ -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; } @@ -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; } diff --git a/components/com_content/models/article.php b/components/com_content/models/article.php index b72a4de0a3b40..29addb74d8781 100644 --- a/components/com_content/models/article.php +++ b/components/com_content/models/article.php @@ -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')); } @@ -333,7 +333,7 @@ public function storeVote($pk = 0, $rate = 0) } else { - if ($userIP != ($rating->lastip)) + if ($userIP != $rating->lastip) { $query = $db->getQuery(true); diff --git a/components/com_content/models/articles.php b/components/com_content/models/articles.php index 15d0fa8f61967..813e81a0541e0 100644 --- a/components/com_content/models/articles.php +++ b/components/com_content/models/articles.php @@ -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'); } @@ -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'); } @@ -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'); @@ -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); @@ -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(); diff --git a/components/com_content/models/category.php b/components/com_content/models/category.php index 5906a59c090e1..a2035f7d10160 100644 --- a/components/com_content/models/category.php +++ b/components/com_content/models/category.php @@ -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')); @@ -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') { - $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)); } } diff --git a/components/com_content/models/form.php b/components/com_content/models/form.php index c39be47a16b08..3833b225e8a34 100644 --- a/components/com_content/models/form.php +++ b/components/com_content/models/form.php @@ -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; - } } return parent::save($data); diff --git a/components/com_content/router.php b/components/com_content/router.php index 9a7ef6e7583fa..c803e122081a8 100644 --- a/components/com_content/router.php +++ b/components/com_content/router.php @@ -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']); @@ -91,7 +91,7 @@ public function build(&$query) return $segments; } - if ($view == 'category' || $view == 'article') + if ($view === 'category' || $view === 'article') { if (!$menuItemGiven) { @@ -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']; @@ -162,7 +162,7 @@ public function build(&$query) foreach ($path as $id) { - if ((int) $id == (int) $mCatid) + if ((int) $id === (int) $mCatid) { break; } @@ -181,7 +181,7 @@ public function build(&$query) $segments = array_merge($segments, $array); - if ($view == 'article') + if ($view === 'article') { if ($advanced) { @@ -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)) @@ -227,7 +226,7 @@ public function build(&$query) } } - if ($view == 'featured') + if ($view === 'featured') { if (!$menuItemGiven) { @@ -252,7 +251,7 @@ public function build(&$query) } else { - if ($query['layout'] == 'default') + if ($query['layout'] === 'default') { unset($query['layout']); } @@ -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]; @@ -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) @@ -429,7 +428,7 @@ public function parse(&$segments) } } - if ($found == 0) + if ($found === 0) { if ($advanced) { diff --git a/components/com_content/views/archive/tmpl/default.php b/components/com_content/views/archive/tmpl/default.php index f14093209c2e8..252e8710cbc78 100644 --- a/components/com_content/views/archive/tmpl/default.php +++ b/components/com_content/views/archive/tmpl/default.php @@ -24,7 +24,7 @@