From 80d5b5e1d834c2180a02a76f1d166128a2fa3e10 Mon Sep 17 00:00:00 2001 From: Frank Mayer Date: Tue, 18 Oct 2016 20:39:27 +0300 Subject: [PATCH] Cleanups, fixes and a bit of optimizations for site/components batch #2 (#12291) * Cleanups, fixes and a bit of optimizations for site/components batch #2 - com_contact Note: This is a single commit bundling all types of changes, since PR #12261 which had detailed commits, was rejected as a whole * oops ;) --- .../com_contact/controllers/contact.php | 2 +- .../com_contact/helpers/association.php | 6 +- components/com_contact/helpers/route.php | 12 ++-- components/com_contact/models/category.php | 6 +- components/com_contact/models/contact.php | 2 +- components/com_contact/router.php | 31 +++++----- .../views/categories/tmpl/default_items.php | 6 +- .../views/category/tmpl/default_children.php | 2 +- .../com_contact/views/category/view.html.php | 4 +- .../views/contact/tmpl/default.php | 58 +++++++++---------- .../views/contact/tmpl/default_form.php | 2 +- .../views/contact/tmpl/default_links.php | 12 ++-- .../views/contact/tmpl/default_profile.php | 6 +- .../com_contact/views/contact/view.html.php | 40 ++++++------- .../views/featured/tmpl/default_items.php | 2 +- 15 files changed, 94 insertions(+), 97 deletions(-) diff --git a/components/com_contact/controllers/contact.php b/components/com_contact/controllers/contact.php index 4b6e4b6f77da0..8993230bc55dd 100644 --- a/components/com_contact/controllers/contact.php +++ b/components/com_contact/controllers/contact.php @@ -59,7 +59,7 @@ public function submit() // Check for a valid session cookie if ($params->get('validate_session', 0)) { - if (JFactory::getSession()->getState() != 'active') + if (JFactory::getSession()->getState() !== 'active') { JError::raiseWarning(403, JText::_('JLIB_ENVIRONMENT_SESSION_INVALID')); diff --git a/components/com_contact/helpers/association.php b/components/com_contact/helpers/association.php index 2f2be6c3956ae..a3b8ad9338a39 100644 --- a/components/com_contact/helpers/association.php +++ b/components/com_contact/helpers/association.php @@ -33,10 +33,10 @@ abstract class ContactHelperAssociation 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 == 'contact') + if ($view === 'contact') { 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_contact'); } diff --git a/components/com_contact/helpers/route.php b/components/com_contact/helpers/route.php index 6b3f210238c14..2b3394e498f6e 100644 --- a/components/com_contact/helpers/route.php +++ b/components/com_contact/helpers/route.php @@ -54,7 +54,7 @@ public static function getContactRoute($id, $catid, $language = 0) } } - if ($language && $language != "*" && JLanguageMultilang::isEnabled()) + if ($language && $language !== '*' && JLanguageMultilang::isEnabled()) { $link .= '&lang=' . $language; $needles['language'] = $language; @@ -106,7 +106,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; @@ -145,7 +145,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'], '*'); @@ -155,7 +155,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']; @@ -171,7 +171,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; } @@ -199,7 +199,7 @@ protected static function _findItem($needles = null) // Check if the active menuitem matches the requested language $active = $menus->getActive(); - if ($active && ($language == '*' || in_array($active->language, array('*', $language)) || !JLanguageMultilang::isEnabled())) + if ($active && ($language === '*' || in_array($active->language, array('*', $language)) || !JLanguageMultilang::isEnabled())) { return $active->id; } diff --git a/components/com_contact/models/category.php b/components/com_contact/models/category.php index 044d42b783d74..57976cd3e6de3 100644 --- a/components/com_contact/models/category.php +++ b/components/com_contact/models/category.php @@ -159,7 +159,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'); @@ -201,7 +201,7 @@ protected function getListQuery() } // Set sortname ordering if selected - if ($this->getState('list.ordering') == 'sortname') + if ($this->getState('list.ordering') === 'sortname') { $query->order($db->escape('a.sortname1') . ' ' . $db->escape($this->getState('list.direction', 'ASC'))) ->order($db->escape('a.sortname2') . ' ' . $db->escape($this->getState('list.direction', 'ASC'))) @@ -235,7 +235,7 @@ protected function populateState($ordering = null, $direction = null) // List state information $format = $app->input->getWord('format'); - if ($format == 'feed') + if ($format === 'feed') { $limit = $app->get('feed_limit'); } diff --git a/components/com_contact/models/contact.php b/components/com_contact/models/contact.php index 32f5e535183ed..f19e65b89179b 100644 --- a/components/com_contact/models/contact.php +++ b/components/com_contact/models/contact.php @@ -199,7 +199,7 @@ public function &getItem($pk = null) } // Check for published state if filter set. - if (((is_numeric($published)) || (is_numeric($archived))) && (($data->published != $published) && ($data->published != $archived))) + if ((is_numeric($published) || is_numeric($archived)) && (($data->published != $published) && ($data->published != $archived))) { JError::raiseError(404, JText::_('COM_CONTACT_ERROR_CONTACT_NOT_FOUND')); } diff --git a/components/com_contact/router.php b/components/com_contact/router.php index 3de9dc7910d1c..fa36616019695 100644 --- a/components/com_contact/router.php +++ b/components/com_contact/router.php @@ -42,14 +42,14 @@ public function build(&$query) $menuItem = $this->menu->getItem($query['Itemid']); } - $mView = (empty($menuItem->query['view'])) ? null : $menuItem->query['view']; - $mId = (empty($menuItem->query['id'])) ? null : $menuItem->query['id']; + $mView = empty($menuItem->query['view']) ? null : $menuItem->query['view']; + $mId = empty($menuItem->query['id']) ? null : $menuItem->query['id']; if (isset($query['view'])) { $view = $query['view']; - if (empty($query['Itemid']) || empty($menuItem) || $menuItem->component != 'com_contact') + if (empty($query['Itemid']) || empty($menuItem) || $menuItem->component !== 'com_contact') { $segments[] = $query['view']; } @@ -58,19 +58,17 @@ public function build(&$query) } // Are we dealing with a contact that is attached to a menu item? - if (isset($view) && ($mView == $view) and (isset($query['id'])) and ($mId == (int) $query['id'])) + if (isset($view, $query['id']) && ($mView == $view) && ($mId == (int) $query['id'])) { - unset($query['view']); - unset($query['catid']); - unset($query['id']); + unset($query['view'], $query['catid'], $query['id']); return $segments; } - if (isset($view) and ($view == 'category' or $view == 'contact')) + if (isset($view) && ($view === 'category' || $view === 'contact')) { - if ($mId != (int) $query['id'] || $mView != $view) + if ($mView != $view || $mId != (int) $query['id']) { - if ($view == 'contact' && isset($query['catid'])) + if ($view === 'contact' && isset($query['catid'])) { $catid = $query['catid']; } @@ -92,7 +90,7 @@ public function build(&$query) foreach ($path as $id) { - if ((int) $id == (int) $menuCatid) + if ((int) $id === (int) $menuCatid) { break; } @@ -108,7 +106,7 @@ public function build(&$query) $segments = array_merge($segments, array_reverse($array)); } - if ($view == 'contact') + if ($view === 'contact') { if ($advanced) { @@ -123,8 +121,7 @@ public function build(&$query) } } - unset($query['id']); - unset($query['catid']); + unset($query['id'], $query['catid']); } if (isset($query['layout'])) @@ -139,7 +136,7 @@ public function build(&$query) } else { - if ($query['layout'] == 'default') + if ($query['layout'] === 'default') { unset($query['layout']); } @@ -196,7 +193,7 @@ public function parse(&$segments) $contactCategory = JCategories::getInstance('Contact')->get($id); - $categories = ($contactCategory) ? $contactCategory->getChildren() : array(); + $categories = $contactCategory ? $contactCategory->getChildren() : array(); $vars['catid'] = $id; $vars['id'] = $id; $found = 0; @@ -218,7 +215,7 @@ public function parse(&$segments) } } - if ($found == 0) + if ($found === 0) { if ($advanced) { diff --git a/components/com_contact/views/categories/tmpl/default_items.php b/components/com_contact/views/categories/tmpl/default_items.php index 2d718bf1f5c83..041ea24a2f232 100644 --- a/components/com_contact/views/categories/tmpl/default_items.php +++ b/components/com_contact/views/categories/tmpl/default_items.php @@ -12,7 +12,7 @@ JHtml::_('bootstrap.tooltip'); $class = ' class="first"'; -if (count($this->items[$this->parent->id]) > 0 && $this->maxLevelcat != 0) : +if ($this->maxLevelcat != 0 && count($this->items[$this->parent->id]) > 0) : ?> items[$this->parent->id] as $id => $item) : ?> numitems; ?> - getChildren()) > 0 && $this->maxLevelcat > 1) : ?> + maxLevelcat > 1 && count($item->getChildren()) > 0) : ?> @@ -46,7 +46,7 @@ - getChildren()) > 0 && $this->maxLevelcat > 1) :?> + maxLevelcat > 1 && count($item->getChildren()) > 0) :?>
items[$item->id] = $item->getChildren(); diff --git a/components/com_contact/views/category/tmpl/default_children.php b/components/com_contact/views/category/tmpl/default_children.php index 11e0fed99afaf..b7bba546b9222 100644 --- a/components/com_contact/views/category/tmpl/default_children.php +++ b/components/com_contact/views/category/tmpl/default_children.php @@ -9,7 +9,7 @@ defined('_JEXEC') or die; $class = ' class="first"'; -if (count($this->children[$this->category->id]) > 0 && $this->maxLevel != 0) : +if ($this->maxLevel != 0 && count($this->children[$this->category->id]) > 0) : ?>
- + - + - + - + diff --git a/components/com_contact/views/contact/tmpl/default_form.php b/components/com_contact/views/contact/tmpl/default_form.php index 31b0e2b282b99..ef21ae02405cd 100644 --- a/components/com_contact/views/contact/tmpl/default_form.php +++ b/components/com_contact/views/contact/tmpl/default_form.php @@ -22,7 +22,7 @@ form->getFieldset($fieldset->name); ?>
- label) && strlen($legend = trim(JText::_($fieldset->label)))) : ?> + label) && ($legend = trim(JText::_($fieldset->label))) !== '') : ?> diff --git a/components/com_contact/views/contact/tmpl/default_links.php b/components/com_contact/views/contact/tmpl/default_links.php index 4a38c96c5f9d1..8f7ecddb9171b 100644 --- a/components/com_contact/views/contact/tmpl/default_links.php +++ b/components/com_contact/views/contact/tmpl/default_links.php @@ -10,13 +10,13 @@ defined('_JEXEC') or die; ?> -params->get('presentation_style') == 'sliders') : ?> +params->get('presentation_style') === 'sliders') : ?> -params->get('presentation_style') == 'tabs') : ?> +params->get('presentation_style') === 'tabs') : ?> -params->get('presentation_style') == 'plain'):?> +params->get('presentation_style') === 'plain'):?> ' . JText::_('COM_CONTACT_LINKS') . ''; ?> @@ -36,7 +36,7 @@ $link = (0 === strpos($link, 'http')) ? $link : 'http://' . $link; // If no label is present, take the link - $label = ($label) ? $label : $link; + $label = $label ?: $link; ?>
  • ' . JStringPunycode::urlToUTF8($profile->text) . '
    '; else : echo '
    ' . JStringPunycode::urlToUTF8($profile->text) . '
    '; endif; break; - case "profile_dob": + case 'profile_dob': echo '
    ' . JHtml::_('date', $profile->text, JText::_('DATE_FORMAT_LC4'), false) . '
    '; break; diff --git a/components/com_contact/views/contact/view.html.php b/components/com_contact/views/contact/view.html.php index 6c645bba4aea4..80e347ef52edd 100644 --- a/components/com_contact/views/contact/view.html.php +++ b/components/com_contact/views/contact/view.html.php @@ -138,12 +138,12 @@ public function display($tpl = null) { case 1 : // Text - $params->set('marker_address', JText::_('COM_CONTACT_ADDRESS') . ": "); - $params->set('marker_email', JText::_('JGLOBAL_EMAIL') . ": "); - $params->set('marker_telephone', JText::_('COM_CONTACT_TELEPHONE') . ": "); - $params->set('marker_fax', JText::_('COM_CONTACT_FAX') . ": "); - $params->set('marker_mobile', JText::_('COM_CONTACT_MOBILE') . ": "); - $params->set('marker_misc', JText::_('COM_CONTACT_OTHER_INFORMATION') . ": "); + $params->set('marker_address', JText::_('COM_CONTACT_ADDRESS') . ': '); + $params->set('marker_email', JText::_('JGLOBAL_EMAIL') . ': '); + $params->set('marker_telephone', JText::_('COM_CONTACT_TELEPHONE') . ': '); + $params->set('marker_fax', JText::_('COM_CONTACT_FAX') . ': '); + $params->set('marker_mobile', JText::_('COM_CONTACT_MOBILE') . ': '); + $params->set('marker_misc', JText::_('COM_CONTACT_OTHER_INFORMATION') . ': '); $params->set('marker_class', 'jicons-text'); break; @@ -161,60 +161,60 @@ public function display($tpl = null) default : if ($params->get('icon_address')) { - $image1 = JHtml::_('image', $params->get('icon_address', 'con_address.png'), JText::_('COM_CONTACT_ADDRESS') . ": ", null, false); + $image1 = JHtml::_('image', $params->get('icon_address', 'con_address.png'), JText::_('COM_CONTACT_ADDRESS') . ': ', null, false); } else { - $image1 = JHtml::_('image', 'contacts/' . $params->get('icon_address', 'con_address.png'), JText::_('COM_CONTACT_ADDRESS') . ": ", null, true); + $image1 = JHtml::_('image', 'contacts/' . $params->get('icon_address', 'con_address.png'), JText::_('COM_CONTACT_ADDRESS') . ': ', null, true); } if ($params->get('icon_email')) { - $image2 = JHtml::_('image', $params->get('icon_email', 'emailButton.png'), JText::_('JGLOBAL_EMAIL') . ": ", null, false); + $image2 = JHtml::_('image', $params->get('icon_email', 'emailButton.png'), JText::_('JGLOBAL_EMAIL') . ': ', null, false); } else { - $image2 = JHtml::_('image', 'contacts/' . $params->get('icon_email', 'emailButton.png'), JText::_('JGLOBAL_EMAIL') . ": ", null, true); + $image2 = JHtml::_('image', 'contacts/' . $params->get('icon_email', 'emailButton.png'), JText::_('JGLOBAL_EMAIL') . ': ', null, true); } if ($params->get('icon_telephone')) { - $image3 = JHtml::_('image', $params->get('icon_telephone', 'con_tel.png'), JText::_('COM_CONTACT_TELEPHONE') . ": ", null, false); + $image3 = JHtml::_('image', $params->get('icon_telephone', 'con_tel.png'), JText::_('COM_CONTACT_TELEPHONE') . ': ', null, false); } else { - $image3 = JHtml::_('image', 'contacts/' . $params->get('icon_telephone', 'con_tel.png'), JText::_('COM_CONTACT_TELEPHONE') . ": ", null, true); + $image3 = JHtml::_('image', 'contacts/' . $params->get('icon_telephone', 'con_tel.png'), JText::_('COM_CONTACT_TELEPHONE') . ': ', null, true); } if ($params->get('icon_fax')) { - $image4 = JHtml::_('image', $params->get('icon_fax', 'con_fax.png'), JText::_('COM_CONTACT_FAX') . ": ", null, false); + $image4 = JHtml::_('image', $params->get('icon_fax', 'con_fax.png'), JText::_('COM_CONTACT_FAX') . ': ', null, false); } else { - $image4 = JHtml::_('image', 'contacts/' . $params->get('icon_fax', 'con_fax.png'), JText::_('COM_CONTACT_FAX') . ": ", null, true); + $image4 = JHtml::_('image', 'contacts/' . $params->get('icon_fax', 'con_fax.png'), JText::_('COM_CONTACT_FAX') . ': ', null, true); } if ($params->get('icon_misc')) { - $image5 = JHtml::_('image', $params->get('icon_misc', 'con_info.png'), JText::_('COM_CONTACT_OTHER_INFORMATION') . ": ", null, false); + $image5 = JHtml::_('image', $params->get('icon_misc', 'con_info.png'), JText::_('COM_CONTACT_OTHER_INFORMATION') . ': ', null, false); } else { $image5 = JHtml::_( 'image', 'contacts/' . $params->get('icon_misc', 'con_info.png'), - JText::_('COM_CONTACT_OTHER_INFORMATION') . ": ", null, true + JText::_('COM_CONTACT_OTHER_INFORMATION') . ': ', null, true ); } if ($params->get('icon_mobile')) { - $image6 = JHtml::_('image', $params->get('icon_mobile', 'con_mobile.png'), JText::_('COM_CONTACT_MOBILE') . ": ", null, false); + $image6 = JHtml::_('image', $params->get('icon_mobile', 'con_mobile.png'), JText::_('COM_CONTACT_MOBILE') . ': ', null, false); } else { - $image6 = JHtml::_('image', 'contacts/' . $params->get('icon_mobile', 'con_mobile.png'), JText::_('COM_CONTACT_MOBILE') . ": ", null, true); + $image6 = JHtml::_('image', 'contacts/' . $params->get('icon_mobile', 'con_mobile.png'), JText::_('COM_CONTACT_MOBILE') . ': ', null, true); } $params->set('marker_address', $image1); @@ -344,7 +344,7 @@ protected function _prepareDocument() $id = (int) @$menu->query['id']; // If the menu item does not concern this contact - if ($menu && ($menu->query['option'] != 'com_contact' || $menu->query['view'] != 'contact' || $id != $this->item->id)) + if ($menu && ($menu->query['option'] !== 'com_contact' || $menu->query['view'] !== 'contact' || $id != $this->item->id)) { // If this is not a single contact menu item, set the page title to the contact title if ($this->item->name) @@ -355,7 +355,7 @@ protected function _prepareDocument() $path = array(array('title' => $this->contact->name, 'link' => '')); $category = JCategories::getInstance('Contact')->get($this->contact->catid); - while ($category && ($menu->query['option'] != 'com_contact' || $menu->query['view'] == 'contact' || $id != $category->id) && $category->id > 1) + while ($category && ($menu->query['option'] !== 'com_contact' || $menu->query['view'] === 'contact' || $id != $category->id) && $category->id > 1) { $path[] = array('title' => $category->title, 'link' => ContactHelperRoute::getCategoryRoute($this->contact->catid)); $category = $category->getParent(); diff --git a/components/com_contact/views/featured/tmpl/default_items.php b/components/com_contact/views/featured/tmpl/default_items.php index 0e5d96a2a2086..04654ae96441b 100644 --- a/components/com_contact/views/featured/tmpl/default_items.php +++ b/components/com_contact/views/featured/tmpl/default_items.php @@ -95,7 +95,7 @@ items as $i => $item) : ?> - " itemscope itemtype="https://schema.org/Person"> +