Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Recipe Help: specific parameter to a module based on article metadata

Recipe Help: specific parameter to a module based on article metadata

Hello,
I need a recipe which passes a specific parameter to a module depending on what metadata description is present. However, I’m a PHP neophyte so I’m in need some assistance

Since I have a few hundred description and parameter pairs, I’m looking for an array which has the metadata description as the array key and the corresponding module parameter as the array value.

I think what I’m trying to do can be accomplished by making a minor modification to the “Control modules based on page content/keywords/description” (http://www.metamodpro.com/metamod/recip … escription) recipe. However, instead of returning a module id, it would return a string which can then be passed as a parameter to the target module using:

   $changes->mod(19)
      ->setParam(string,string);
   return 19;

Hopefully this is a simple modification to the above recipe, but let me know if you need additional information. I really appreciate your assistance and have found metamod to be a fantastic program which has already proved invaluable in my current project.

Thank you,

bbjurstrom
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

Re: Recipe Help: specific parameter to a module based on article metadata

Sure, try this:

Code:

$case_sensitive = false; /* set to true or false */

$mod_to_change = XXX; /* replace with id of module you want to change params for */
$param_name = 'name_of_param'; /* replace with name of param you want to alter */

/* 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(
  "bob jones" => 'param value 1',
  "jim baker" => 'param value 2',
  "john major" => 'param value 3',
  "tony blair" => 'param value 4',
  "CREATIVE" => 'param value 5',
  "global action" => 'param value 6',
  "joomla" => 'param value 7',
  "CMS" => 'param value 8',
  "graphical user interface" => 'param value 9'
);

/*****************************************/
/* you shouldn't need to edit below here */
/*****************************************/
$document =& JFactory::getDocument();

$content = $document->getMetaData('description');

$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) {
  $param = '';

  foreach ($all[0] as $matched_name) {
    $param = $names[$case_sensitive ?
      $matched_name : strtolower($matched_name)];
  }
  $changes->mod($mod_to_change)->setParam($param_name, $param);
}

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Recipe Help: specific parameter to a module based on article metadata

It works great, thank you so much!

bbjurstrom
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5913
Dormant:
User Info:
 
Total Users:
10789
Newest User:
parus6
Members Online:
1
Guests Online:
183

Online: 
parus6

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked