How to make plugins process Section/Category descriptions (for Joomla 1.5.x)?
Written by kksou   
Monday, 28 April 2008

In standard Joomla 1.5.x installation, only the content items get processed by the mambots/plugins.

This article shows you how to make the mambots/plugins process the Section/Category descriptions too.

Note: the steps below are for Joomla 1.5.x. If you're using Joomla 1.0.x, please refer to How to make plugins process Section/Category descriptions (for Joomla 1.0.x)?.

Solutions

  1. Add Trigger for Category Description. In the original Joomla installation, there is no trigger during the display of Section/Category description. When there is no trigger, none of the plugin gets called. In order for the Section/Category description to be processed by the content plugins, we need to add a trigger.
    1. Go to the folder <Joomla root folder>/components/com_content/views/category, you will see a file called view.html.php.
    2. Open this file view.html.php in your favorite editor.
    3. Go to around Line 39. In the function display(), add the six lines highlighted in yellow near the beginning of the function as follows:
    4. class ContentViewCategory extends ContentView
      {
          function display($tpl = null)
          {
              global $mainframe, $option;
      
              // Initialize some variables
              $user		=& JFactory::getUser();
              $uri 		=& JFactory::getURI();
              $document	=& JFactory::getDocument();
              $pathway	=& $mainframe->getPathway();
      
              $category	=& $this->get('Category');
              $dispatcher	=& JDispatcher::getInstance();
              JPluginHelper::importPlugin('content');
              $category->text = $category->description;
              $results = $dispatcher->trigger('onPrepareContent',
                      array (&$category, $category->params, 0));
              $category->description = $category->text;
      
              // Get the menu item object
              $menus = &JSite::getMenu();
              $menu  = $menus->getActive();
      
    5. Save and close this file.
    6. If you're only want the Category description to be processed by the content plugins, the six lines listed above is all that you need.

  2. Add Trigger for Section Description. If you also want the Section Description to be processed by content plugins, you also add the following six lines.
    1. Go to the folder <Joomla root folder>/components/com_content/views/section, you will see a file called view.html.php.
    2. Open this file view.html.php in your favorite editor.
    3. Go to around Line 36. In the function display(), add the six lines highlighted in yellow near the beginning of the function as follows:
    4. class ContentViewSection extends ContentView
      {
          function display($tpl = null)
          {
              global $mainframe, $option;
      
              // Initialize some variables
              $user		=& JFactory::getUser();
              $document	=& JFactory::getDocument();
      
              $section	=& $this->get('Section');
              $dispatcher	=& JDispatcher::getInstance();
              JPluginHelper::importPlugin('content');
              $section->text = $section->description;
              $results = $dispatcher->trigger('onPrepareContent',
                      array (&$section, $section->params, 0));
              $section->description = $section->text ;
      
              // Get the page/component configuration
              $params = &$mainframe->getParams();
      
              // Request variables
              $limit = JRequest::getVar('limit', $params->get('display_num'), '', 'int');
              $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
      
    5. Then go to around Line 87, also in the function display(), add the five lines highlighted in yellow as follows. (Note: this one takes care of the case in which you have modules embedded in each of the category description):
    6. class ContentViewSection extends ContentView
      {
          function display($tpl = null)
          {
                  .
                  .
                  .
      
              //add alternate feed link
              if($params->get('show_feed_link', 1) == 1)
              {
                  $link	= '&format=feed&limitstart=';
                  $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
                  $document->addHeadLink(JRoute::_($link.'&type=rss'), 
                      'alternate', 'rel', $attribs);
                  $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
                  $document->addHeadLink(JRoute::_($link.'&type=atom'), 
                      'alternate', 'rel', $attribs);
              }
      
              $dispatcher	=& JDispatcher::getInstance();
              JPluginHelper::importPlugin('content');
      
              for($i = 0; $i < count($categories); $i++)
              {
                  $category =& $categories[$i];
                  $category->link = JRoute::_('index.php?view=category&id='.
                      $category->slug);
      
                  $category->text = $category->description;
                  $results=$dispatcher->trigger('onPrepareContent', 
                          array(&$category, $category->params, 0));
                  $category->description = $category->text ;
              }
      
              if ($total == 0) {
                  $params->set('show_categories', false);
              }
      
    7. Save and close this file.

That's it. You can try {loadposition}. It should now work even in Section/Category descriptions.

You can also try DirectPHP plugin. You will now be able to include PHP commands in both the content items as well as Section/Category descriptions.

Note

  • Bear in mind that this solution will mean that ALL plugins that work on your content items will also work on section/category descriptions. So make sure you double check that the section/category descriptions look ok.
  • In the event that you do not want a plugin to work on a section/category description, you might need to modify the plugin to bypass the processing.

Last Updated ( Tuesday, 29 April 2008 )
 

Add comment


Security code
Refresh

< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2012. kksou.com. All Rights Reserved