Skip to content

Commit

Permalink
Feature - Add always count option to 404 redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
tonypartridge committed Jun 28, 2021
1 parent 45692b8 commit 8355e23
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.plg_system_redirect.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ PLG_SYSTEM_REDIRECT_FIELD_EXCLUDE_URLS_TERM_LABEL="Term"
PLG_SYSTEM_REDIRECT_FIELD_STORE_FULL_URL_DESC="Save the expired URL as absolute (include domain) or relative (exclude domain)."
PLG_SYSTEM_REDIRECT_FIELD_STORE_FULL_URL_LABEL="Include Domain Name in Expired URL"
PLG_SYSTEM_REDIRECT_XML_DESCRIPTION="The system redirect plugin enables the Joomla Redirect system to catch missing pages and redirect users."
PLG_SYSTEM_REDIRECT_FIELD_ALWAYS_COUNT_LABEL="Always count hits?"
PLG_SYSTEM_REDIRECT_ALWAYS_COUNT_DESC="By default we only count 404 hits, enabling this will count hits on the 404 regardless of the url state."
15 changes: 15 additions & 0 deletions plugins/system/redirect/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,21 @@ private static function doErrorHandling($error)
// In case the url contains double // lets remove it
$destination = str_replace(JUri::root() . '/', JUri::root(), $dest);

// Should we always count the redirect hits?

if($params->get('alwaysCount', 0)) {
$redirect->hits++;

try
{
$db->updateObject('#__redirect_links', $redirect, 'id');
}
catch (Exception $e)
{
JErrorPage::render(new Exception(JText::_('PLG_SYSTEM_REDIRECT_ERROR_UPDATING_DATABASE'), 500, $e));
}
}

$app->redirect($destination, (int) $redirect->header);
}

Expand Down
12 changes: 12 additions & 0 deletions plugins/system/redirect/redirect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="alwaysCount"
type="radio"
label="PLG_SYSTEM_REDIRECT_FIELD_ALWAYS_COUNT_LABEL"
description="PLG_SYSTEM_REDIRECT_ALWAYS_COUNT_DESC"
default="0"
filter="integer"
class="btn-group btn-group-yesno"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="exclude_urls"
type="subform"
Expand Down

0 comments on commit 8355e23

Please sign in to comment.