Source for file helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  mod_related_items
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. require_once JPATH_SITE '/components/com_content/helpers/route.php';
  13.  
  14. /**
  15.  * Helper for mod_related_items
  16.  *
  17.  * @package     Joomla.Site
  18.  * @subpackage  mod_related_items
  19.  * @since       1.5
  20.  */
  21. abstract class ModRelatedItemsHelper
  22. {
  23.     public static function getList(&$params)
  24.     {
  25.         $db JFactory::getDbo();
  26.         $app JFactory::getApplication();
  27.         $user JFactory::getUser();
  28.         $groups implode(','$user->getAuthorisedViewLevels());
  29.         $date JFactory::getDate();
  30.         $maximum = (int) $params->get('maximum'5);
  31.  
  32.         $option $app->input->get('option');
  33.         $view $app->input->get('view');
  34.  
  35.         $temp $app->input->getString('id');
  36.         $temp explode(':'$temp);
  37.         $id $temp[0];
  38.  
  39.         $nullDate $db->getNullDate();
  40.         $now $date->toSql();
  41.         $related array();
  42.         $query $db->getQuery(true);
  43.  
  44.         if ($option == 'com_content' && $view == 'article' && $id)
  45.         {
  46.             // select the meta keywords from the item
  47.  
  48.             $query->select('metakey')
  49.                 ->from('#__content')
  50.                 ->where('id = ' . (int) $id);
  51.             $db->setQuery($query);
  52.  
  53.             if ($metakey trim($db->loadResult()))
  54.             {
  55.                 // explode the meta keys on a comma
  56.                 $keys explode(','$metakey);
  57.                 $likes array();
  58.  
  59.                 // assemble any non-blank word(s)
  60.                 foreach ($keys as $key)
  61.                 {
  62.                     $key trim($key);
  63.                     if ($key)
  64.                     {
  65.                         $likes[$db->escape($key);
  66.                     }
  67.                 }
  68.  
  69.                 if (count($likes))
  70.                 {
  71.                     // select other items based on the metakey field 'like' the keys found
  72.                     $query->clear()
  73.                         ->select('a.id')
  74.                         ->select('a.title')
  75.                         ->select('DATE_FORMAT(a.created, "%Y-%m-%d") as created')
  76.                         ->select('a.catid')
  77.                         ->select('cc.access AS cat_access')
  78.                         ->select('cc.published AS cat_state');
  79.  
  80.                     // Sqlsrv changes
  81.                     $case_when ' CASE WHEN ';
  82.                     $case_when .= $query->charLength('a.alias''!=''0');
  83.                     $case_when .= ' THEN ';
  84.                     $a_id $query->castAsChar('a.id');
  85.                     $case_when .= $query->concatenate(array($a_id'a.alias')':');
  86.                     $case_when .= ' ELSE ';
  87.                     $case_when .= $a_id ' END as slug';
  88.                     $query->select($case_when);
  89.  
  90.                     $case_when ' CASE WHEN ';
  91.                     $case_when .= $query->charLength('cc.alias''!=''0');
  92.                     $case_when .= ' THEN ';
  93.                     $c_id $query->castAsChar('cc.id');
  94.                     $case_when .= $query->concatenate(array($c_id'cc.alias')':');
  95.                     $case_when .= ' ELSE ';
  96.                     $case_when .= $c_id ' END as catslug';
  97.                     $query->select($case_when)
  98.                         ->from('#__content AS a')
  99.                         ->join('LEFT''#__content_frontpage AS f ON f.content_id = a.id')
  100.                         ->join('LEFT''#__categories AS cc ON cc.id = a.catid')
  101.                         ->where('a.id != ' . (int) $id)
  102.                         ->where('a.state = 1')
  103.                         ->where('a.access IN (' $groups ')');
  104.                     $concat_string $query->concatenate(array('","'' REPLACE(a.metakey, ", ", ",")'' ","'));
  105.                     $query->where('(' $concat_string ' LIKE "%' implode('%" OR ' $concat_string ' LIKE "%'$likes'%")'//remove single space after commas in keywords)
  106.                         ->where('(a.publish_up = ' $db->quote($nullDate' OR a.publish_up <= ' $db->quote($now')')
  107.                         ->where('(a.publish_down = ' $db->quote($nullDate' OR a.publish_down >= ' $db->quote($now')');
  108.  
  109.                     // Filter by language
  110.                     if (JLanguageMultilang::isEnabled())
  111.                     {
  112.                         $query->where('a.language in (' $db->quote(JFactory::getLanguage()->getTag()) ',' $db->quote('*'')');
  113.                     }
  114.  
  115.                     $db->setQuery($query0$maximum);
  116.                     $temp $db->loadObjectList();
  117.  
  118.                     if (count($temp))
  119.                     {
  120.                         foreach ($temp as $row)
  121.                         {
  122.                             if ($row->cat_state == 1)
  123.                             {
  124.                                 $row->route JRoute::_(ContentHelperRoute::getArticleRoute($row->slug$row->catslug));
  125.                                 $related[$row;
  126.                             }
  127.                         }
  128.                     }
  129.                     unset ($temp);
  130.                 }
  131.             }
  132.         }
  133.  
  134.         return $related;
  135.     }
  136. }

Documentation generated on Tue, 19 Nov 2013 15:04:18 +0100 by phpDocumentor 1.4.3