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