Skip to content

Commit

Permalink
Removing IDs from SEF URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackwar committed May 1, 2016
1 parent 80a8939 commit 4931350
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 17 deletions.
11 changes: 11 additions & 0 deletions administrator/components/com_contact/config.xml
Expand Up @@ -827,6 +827,17 @@
<option value="0">JNO</option>
</field>

<field
name="sef_ids"
type="radio"
class="btn-group btn-group-yesno"
default="0"
label="JGLOBAL_SEF_NOIDS_LABEL"
description="JGLOBAL_SEF_NOIDS_DESC"
filter="integer">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
</fieldset>

<fieldset name="permissions"
Expand Down
12 changes: 12 additions & 0 deletions administrator/components/com_content/config.xml
Expand Up @@ -896,6 +896,18 @@
<option value="0">JNO</option>
</field>

<field
name="sef_ids"
type="radio"
class="btn-group btn-group-yesno"
default="0"
label="JGLOBAL_SEF_NOIDS_LABEL"
description="JGLOBAL_SEF_NOIDS_DESC"
filter="integer">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>

</fieldset>

<fieldset
Expand Down
11 changes: 11 additions & 0 deletions administrator/components/com_newsfeeds/config.xml
Expand Up @@ -401,6 +401,17 @@
<option value="0">JNO</option>
</field>

<field
name="sef_ids"
type="radio"
class="btn-group btn-group-yesno"
default="0"
label="JGLOBAL_SEF_NOIDS_LABEL"
description="JGLOBAL_SEF_NOIDS_DESC"
filter="integer">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
</fieldset>

<fieldset
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.ini
Expand Up @@ -471,6 +471,8 @@ JGLOBAL_SECRETKEY="Secret Key"
JGLOBAL_SECRETKEY_HELP="If you have enabled two factor authentication in your user account please enter your secret key. If you do not know what this means, you can leave this field blank."
JGLOBAL_SEF_ADVANCED_DESC="This uses the new URL routing. This may change your URLs!"
JGLOBAL_SEF_ADVANCED_LABEL="Use new URL routing"
JGLOBAL_SEF_NOIDS_DESC="Remove the IDs from the URLs of this component"
JGLOBAL_SEF_NOIDS_LABEL="Remove IDs from URLs"
JGLOBAL_SELECT_ALLOW_DENY_GROUP="Change %s permission for %s group."
JGLOBAL_SELECT_AN_OPTION="Select an option"
JGLOBAL_SELECT_NO_RESULTS_MATCH="No results match"
Expand Down
70 changes: 66 additions & 4 deletions components/com_contact/router.php
Expand Up @@ -16,6 +16,8 @@
*/
class ContactRouter extends JComponentRouterView
{
protected $noIDs = false;

/**
* Search Component router constructor
*
Expand All @@ -24,6 +26,8 @@ class ContactRouter extends JComponentRouterView
*/
public function __construct($app = null, $menu = null)
{
$params = JComponentHelper::getParams('com_contact');
$this->noIDs = (bool) $params->get('sef_ids');
$categories = new JComponentRouterViewconfiguration('categories');
$categories->setKey('id');
$this->registerView($categories);
Expand All @@ -44,6 +48,7 @@ public function __construct($app = null, $menu = null)
if ($params->get('sef_advanced', 0))
{
$this->attachRule(new JComponentRouterRulesStandard($this));
$this->attachRule(new JComponentRouterRulesNomenu($this));
}
else
{
Expand All @@ -66,7 +71,20 @@ public function getCategorySegment($id, $query)

if ($category)
{
return array_reverse($category->getPath());
if ($this->noIDs)
{
$path = array_reverse($category->getPath(), true);
foreach ($path as &$segment)
{
list($id, $segment) = explode(':', $segment, 2);
}

return $path;
}
else
{
return array_reverse($category->getPath(), true);
}
}

return array();
Expand Down Expand Up @@ -95,7 +113,28 @@ public function getCategoriesSegment($id, $query)
*/
public function getContactSegment($id, $query)
{
return array($id);
if ($this->noIDs)
{
if (strpos($id, ':'))
{
list($void, $segment) = explode(':', $id, 2);

return array($void => $segment);
}
else
{
$db = JFactory::getDbo();
$dbquery = $db->getQuery(true);
$dbquery->select($dbquery->qn('alias'))
->from($dbquery->qn('#__contact_details'))
->where('id = ' . $dbquery->q((int) $id));
$db->setQuery($dbquery);

return array($id => $id . ':' . $db->loadResult());
}
}

return array((int) $id => $id);
}

/**
Expand All @@ -114,9 +153,19 @@ public function getCategoryId($segment, $query)

foreach ($category->getChildren() as $child)
{
if ($child->id == (int) $segment)
if ($this->noIDs)
{
return $child->id;
if ($child->alias == $segment)
{
return $child->id;
}
}
else
{
if ($child->id == (int) $segment)
{
return $child->id;
}
}
}
}
Expand Down Expand Up @@ -147,6 +196,19 @@ public function getCategoriesId($segment, $query)
*/
public function getContactId($segment, $query)
{
if ($this->noIDs)
{
$db = JFactory::getDbo();
$dbquery = $db->getQuery(true);
$dbquery->select($dbquery->qn('id'))
->from($dbquery->qn('#__contact_details'))
->where('alias = ' . $dbquery->q($segment))
->where('catid = ' . $dbquery->q($query['id']));
$db->setQuery($dbquery);

return (int) $db->loadResult();
}

return (int) $segment;
}
}
Expand Down
70 changes: 66 additions & 4 deletions components/com_content/router.php
Expand Up @@ -16,6 +16,8 @@
*/
class ContentRouter extends JComponentRouterView
{
protected $noIDs = false;

/**
* Content Component router constructor
*
Expand All @@ -24,6 +26,8 @@ class ContentRouter extends JComponentRouterView
*/
public function __construct($app = null, $menu = null)
{
$params = JComponentHelper::getParams('com_content');
$this->noIDs = (bool) $params->get('sef_ids');
$categories = new JComponentRouterViewconfiguration('categories');
$categories->setKey('id');
$this->registerView($categories);
Expand All @@ -46,6 +50,7 @@ public function __construct($app = null, $menu = null)
if ($params->get('sef_advanced', 0))
{
$this->attachRule(new JComponentRouterRulesStandard($this));
$this->attachRule(new JComponentRouterRulesNomenu($this));
}
else
{
Expand All @@ -68,7 +73,20 @@ public function getCategorySegment($id, $query)

if ($category)
{
return array_reverse($category->getPath());
if ($this->noIDs)
{
$path = array_reverse($category->getPath(), true);
foreach ($path as &$segment)
{
list($id, $segment) = explode(':', $segment, 2);
}

return $path;
}
else
{
return array_reverse($category->getPath(), true);
}
}

return array();
Expand Down Expand Up @@ -97,7 +115,28 @@ public function getCategoriesSegment($id, $query)
*/
public function getArticleSegment($id, $query)
{
return array($id);
if ($this->noIDs)
{
if (strpos($id, ':'))
{
list($void, $segment) = explode(':', $id, 2);

return array($void => $segment);
}
else
{
$db = JFactory::getDbo();
$dbquery = $db->getQuery(true);
$dbquery->select($dbquery->qn('alias'))
->from($dbquery->qn('#__content'))
->where('id = ' . $dbquery->q($id));
$db->setQuery($dbquery);

return array($id => $id . ':' . $db->loadResult());
}
}

return array((int) $id => $id);
}

/**
Expand All @@ -116,9 +155,19 @@ public function getCategoryId($segment, $query)

foreach ($category->getChildren() as $child)
{
if ($child->id == (int) $segment)
if ($this->noIDs)
{
return $child->id;
if ($child->alias == $segment)
{
return $child->id;
}
}
else
{
if ($child->id == (int) $segment)
{
return $child->id;
}
}
}
}
Expand Down Expand Up @@ -149,6 +198,19 @@ public function getCategoriesId($segment, $query)
*/
public function getArticleId($segment, $query)
{
if ($this->noIDs)
{
$db = JFactory::getDbo();
$dbquery = $db->getQuery(true);
$dbquery->select($dbquery->qn('id'))
->from($dbquery->qn('#__content'))
->where('alias = ' . $dbquery->q($segment))
->where('catid = ' . $dbquery->q($query['id']));
$db->setQuery($dbquery);

return (int) $db->loadResult();
}

return (int) $segment;
}
}
Expand Down

0 comments on commit 4931350

Please sign in to comment.