Skip to content

Commit

Permalink
Cleanups, fixes and a bit of optimizations for site/components batch #2
Browse files Browse the repository at this point in the history
… (joomla#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 joomla#12261 which had detailed commits, was rejected as a whole

* oops ;)
  • Loading branch information
frankmayer authored and rdeutz committed Oct 18, 2016
1 parent 7f8c329 commit 80d5b5e
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 97 deletions.
2 changes: 1 addition & 1 deletion components/com_contact/controllers/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
6 changes: 3 additions & 3 deletions components/com_contact/helpers/association.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
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_contact');
}
Expand Down
12 changes: 6 additions & 6 deletions components/com_contact/helpers/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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'], '*');
Expand All @@ -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'];

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions components/com_contact/models/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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')))
Expand Down Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion components/com_contact/models/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down
31 changes: 14 additions & 17 deletions components/com_contact/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand All @@ -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'];
}
Expand All @@ -92,7 +90,7 @@ public function build(&$query)

foreach ($path as $id)
{
if ((int) $id == (int) $menuCatid)
if ((int) $id === (int) $menuCatid)
{
break;
}
Expand All @@ -108,7 +106,7 @@ public function build(&$query)
$segments = array_merge($segments, array_reverse($array));
}

if ($view == 'contact')
if ($view === 'contact')
{
if ($advanced)
{
Expand All @@ -123,8 +121,7 @@ public function build(&$query)
}
}

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

if (isset($query['layout']))
Expand All @@ -139,7 +136,7 @@ public function build(&$query)
}
else
{
if ($query['layout'] == 'default')
if ($query['layout'] === 'default')
{
unset($query['layout']);
}
Expand Down Expand Up @@ -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;
Expand All @@ -218,7 +215,7 @@ public function parse(&$segments)
}
}

if ($found == 0)
if ($found === 0)
{
if ($advanced)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
?>
<?php foreach($this->items[$this->parent->id] as $id => $item) : ?>
<?php
Expand All @@ -33,7 +33,7 @@
<?php echo $item->numitems; ?>
</span>
<?php endif; ?>
<?php if (count($item->getChildren()) > 0 && $this->maxLevelcat > 1) : ?>
<?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) : ?>
<a id="category-btn-<?php echo $item->id;?>" href="#category-<?php echo $item->id;?>"
data-toggle="collapse" data-toggle="button" class="btn btn-mini pull-right"><span class="icon-plus"></span></a>
<?php endif;?>
Expand All @@ -46,7 +46,7 @@
<?php endif; ?>
<?php endif; ?>

<?php if (count($item->getChildren()) > 0 && $this->maxLevelcat > 1) :?>
<?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) :?>
<div class="collapse fade" id="category-<?php echo $item->id;?>">
<?php
$this->items[$item->id] = $item->getChildren();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
?>
<ul class="list-striped list-condensed">
<?php foreach ($this->children[$this->category->id] as $id => $child) : ?>
Expand Down
4 changes: 2 additions & 2 deletions components/com_contact/views/category/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->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
$temp = new Registry;
$temp->loadString($item->params);
$item->params = clone($this->params);
$item->params = clone $this->params;
$item->params->merge($temp);

if ($item->params->get('show_email_headings', 0) == 1)
Expand Down Expand Up @@ -100,7 +100,7 @@ protected function prepareDocument()
$path = array(array('title' => $this->category->title, 'link' => ''));
$category = $this->category->getParent();

while (($menu->query['option'] != 'com_contact' || $menu->query['view'] == 'contact' || $id != $category->id) && $category->id > 1)
while (($menu->query['option'] !== 'com_contact' || $menu->query['view'] === 'contact' || $id != $category->id) && $category->id > 1)
{
$path[] = array('title' => $category->title, 'link' => ContactHelperRoute::getCategoryRoute($category->id));
$category = $category->getParent();
Expand Down
Loading

0 comments on commit 80d5b5e

Please sign in to comment.