Skip to content

Commit

Permalink
Changed code style to match Joomla! + Added option to exclude menu it…
Browse files Browse the repository at this point in the history
…ems + Moved regular expression into the Advanced tab
  • Loading branch information
OctavianC committed Aug 25, 2015
1 parent 399c559 commit 24b8f33
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
4 changes: 3 additions & 1 deletion administrator/language/en-GB/en-GB.plg_system_cache.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

PLG_CACHE_FIELD_BROWSERCACHE_DESC="If yes, use mechanism for storing page cache in the browser."
PLG_CACHE_FIELD_BROWSERCACHE_LABEL="Use Browser Caching"
PLG_CACHE_FIELD_EXCLUDE_DESC="Specify which pages you wish to exclude from caching, each on a separate line. Regular expressions are supported."
PLG_CACHE_FIELD_EXCLUDE_DESC="Specify which pages you want to exclude from caching, each on a separate line. Regular expressions are supported."
PLG_CACHE_FIELD_EXCLUDE_LABEL="Exclude Pages"
PLG_CACHE_FIELD_EXCLUDE_MENU_ITEMS_DESC="Select which menu items you want to exclude from caching."
PLG_CACHE_FIELD_EXCLUDE_MENU_ITEMS_LABEL="Exclude Menu Items"
PLG_CACHE_FIELD_LIFETIME_DESC="Page cache lifetime in minutes."
PLG_CACHE_FIELD_LIFETIME_LABEL="Cache Lifetime"
PLG_CACHE_XML_DESCRIPTION="Provides page caching."
Expand Down
28 changes: 23 additions & 5 deletions plugins/system/cache/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,21 @@ public function onAfterRender()
}

protected function isExcluded() {
if ($exclusions = $this->params->get('exclude', '')) {
// Check if menu items have been excluded
if ($exclusions = $this->params->get('exclude_menu_items', array()))
{
// Get the current menu item
$active = JFactory::getApplication()->getMenu()->getActive();

if ($active && $active->id && in_array($active->id, (array) $exclusions))
{
return true;
}
}

// Check if regular expressions are being used
if ($exclusions = $this->params->get('exclude', ''))
{
// Normalize line endings
$exclusions = str_replace(array("\r\n", "\r"), "\n", $exclusions);

Expand All @@ -132,11 +146,15 @@ protected function isExcluded() {
$path = JUri::getInstance()->toString(array('path', 'query', 'fragment'));

// Loop through each pattern
if ($exclusions) {
foreach ($exclusions as $exclusion) {
if ($exclusions)
{
foreach ($exclusions as $exclusion)
{
// Make sure the exclusion has some content
if (strlen($exclusion)) {
if (preg_match('/'.$exclusion.'/is', $path, $match)) {
if (strlen($exclusion))
{
if (preg_match('/'.$exclusion.'/is', $path, $match))
{
return true;
}
}
Expand Down
8 changes: 8 additions & 0 deletions plugins/system/cache/cache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="exclude_menu_items" type="menuitem"
default=""
multiple="multiple"
description="PLG_CACHE_FIELD_EXCLUDE_MENU_ITEMS_DESC"
label="PLG_CACHE_FIELD_EXCLUDE_MENU_ITEMS_LABEL"
/>
</fieldset>
<fieldset name="advanced">
<field name="exclude" type="textarea"
filter="raw"
default=""
Expand Down

0 comments on commit 24b8f33

Please sign in to comment.