Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » 2 different modules same trigger word
2 different modules same trigger word
2 different modules same trigger word
Hi,
Firstly thanks for this great module!
I am trying to get 2 modules to display with the same word trigger. I have it set to $max_num_modules = 3; and it is not case sensitive.
It displays more than one module when a differnt word trigger is used but not if the same word is used.
Is there a way around this?
(example of what I have calling 2 different modules with the same word)
"SABADELL" => 116,
"TERRASSA" => 117,
"GIRONA" => 118,
"GIRONA" => 122,
Thank you
Re: 2 different modules same trigger word
Sorry for the delay in replying. Here's a modified example for you. See how you can return multiple modules by putting them in quotes and separating them with commas.
Code:
// To set it up, just edit the "$source", "$case_sensitive",
// "$allow_as_substrings", "$names" and "$max_num_modules"
// variables below. The "$names" array contains the
// words/phrases that you want to search for, and the module
// ID or module position to use when any one of them is found.
$source = "content"; /* either "keywords", "description" or "content" */
$case_sensitive = false; /* set to true or false */
/* if you set $allow_as_substrings to true, then the search
* will pick up "billybob thornton" even if you are trying
* to search for "bob thornton". Set it to false to make
* sure that there's an least 1 non-alphabet character on
* each end of the string you are searching for.
*/
$allow_as_substrings = false; /* set to true or false */
$max_num_modules = 3; /* it will just give you the first 3 it finds */
/* In this array, the first part is the text to search for, and
* the last part is the module id to include if that text is
* found. Add as many as you like.
* Remember every line has to end in a comma EXCEPT the last one!
*/
$names = array(
"SABADELL" => 116,
"TERRASSA" => 117,
"GIRONA" => "118,122"
);
/*****************************************/
/* you shouldn't need to edit below here */
/*****************************************/
$document =& JFactory::getDocument();
switch ($source) {
case "keywords":
$content = $document->getMetaData('keywords');
break;
case "description":
$content = $document->getMetaData('description');
break;
default:
$buffer = $document->getBuffer();
$content = $buffer['component'][''];
}
$names_escaped = array();
foreach ($names as $key=>$module) {
if (!$case_sensitive) {
$key = strtolower($key);
}
$names_escaped[preg_quote($key)] = $module;
}
$names = $names_escaped;
$names_only = str_replace('/','\/',implode("|", array_keys($names)));
$word_boundary = $allow_as_substrings ? '' : '\b';
$result = preg_match_all("/" . $word_boundary
. "(" . $names_only . ")"
. $word_boundary . "/"
. ($case_sensitive ? '' : 'i'), $content, $all);
if ($result > 0) {
$modules = array();
$final = array();
foreach ($all[0] as $matched_name) {
$module = $names[$case_sensitive ?
$matched_name : strtolower($matched_name)];
$modules[] = $module;
}
// explode comma-separated module lists
foreach ($modules as $m) {
$exp = explode(",",$m);
foreach ($exp as $el) {
if (!in_array((int)$el, $final)) $final[] = (int)$el;
}
}
if ( count($final) > $max_num_modules ) {
return array_slice( $final, 0, $max_num_modules );
}
return $final;
}
- Index
- » MetaMod
- » MetaMod General Support
- » 2 different modules same trigger word
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Total Posts Today:
- 1
- User Info:
- Total Users:
- 7624
- Newest User:
- borger3298
- Members Online:
- 0
- Guests Online:
- 163
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked