| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: helper.php 15200 2010-03-05 09:12:56Z ian $ 4 * @package Joomla 5 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 6 * @license GNU/GPL, see LICENSE.php 7 * Joomla! is free software. This version may have been modified pursuant 8 * to the GNU General Public License, and as distributed it includes or 9 * is derivative of works licensed under the GNU General Public License or 10 * other free or open source software licenses. 11 * See COPYRIGHT.php for copyright notices and details. 12 */ 13 14 // no direct access 15 defined('_JEXEC') or die('Restricted access'); 16 17 require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php'); 18 19 class modRelatedItemsHelper 20 { 21 function getList($params) 22 { 23 global $mainframe; 24 25 $db =& JFactory::getDBO(); 26 $user =& JFactory::getUser(); 27 28 $option = JRequest::getCmd('option'); 29 $view = JRequest::getCmd('view'); 30 31 $temp = JRequest::getString('id'); 32 $temp = explode(':', $temp); 33 $id = $temp[0]; 34 35 $aid = $user->get('aid', 0); 36 37 $showDate = $params->get('showDate', 0); 38 $conf =& JFactory::getConfig(); 39 40 if ($option == 'com_content' && $view == 'article' && $id) 41 { 42 if ($params->get('cache_items', 0)==1 && $conf->getValue( 'config.caching' )) { 43 $cache =& JFactory::getCache('mod_related_items', 'callback'); 44 $cache->setLifeTime( $params->get( 'cache_time', $conf->getValue( 'config.cachetime' ) * 60 ) ); 45 $cache->setCacheValidation(true); 46 $related = $cache->get(array('modRelatedItemsHelper', 'getRelatedItemsById'), array($id, $aid, $showDate)); 47 } else { 48 $related = modRelatedItemsHelper::getRelatedItemsById($id, $aid, $showDate); 49 } 50 } else { 51 $related = array(); 52 } 53 54 return $related; 55 } 56 57 function getRelatedItemsById($id, $aid, $showDate) { 58 $db =& JFactory::getDBO(); 59 $user =& JFactory::getUser(); 60 $date =& JFactory::getDate(); 61 62 $related = array(); 63 64 $nullDate = $db->getNullDate(); 65 $now = $date->toMySQL(); 66 67 // select the meta keywords from the item 68 $query = 'SELECT metakey' . 69 ' FROM #__content' . 70 ' WHERE id = '.(int) $id; 71 $db->setQuery($query); 72 73 if ($metakey = trim($db->loadResult())) 74 { 75 // explode the meta keys on a comma 76 $keys = explode(',', $metakey); 77 $likes = array (); 78 79 // assemble any non-blank word(s) 80 foreach ($keys as $key) 81 { 82 $key = trim($key); 83 if ($key) { 84 $likes[] = ',' . $db->getEscaped($key) . ','; // surround with commas so first and last items have surrounding commas 85 } 86 } 87 88 if (count($likes)) 89 { 90 // select other items based on the metakey field 'like' the keys found 91 $query = 'SELECT a.id, a.title, DATE_FORMAT(a.created, "%Y-%m-%d") AS created, a.sectionid, a.catid, cc.access AS cat_access, s.access AS sec_access, cc.published AS cat_state, s.published AS sec_state,' . 92 ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'. 93 ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug'. 94 ' FROM #__content AS a' . 95 ' LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id' . 96 ' LEFT JOIN #__categories AS cc ON cc.id = a.catid' . 97 ' LEFT JOIN #__sections AS s ON s.id = a.sectionid' . 98 ' WHERE a.id != '.(int) $id . 99 ' AND a.state = 1' . 100 ' AND a.access <= ' .(int) $user->get('aid', 0) . 101 ' AND ( CONCAT(",", REPLACE(a.metakey,", ",","),",") LIKE "%'.implode('%" OR CONCAT(",", REPLACE(a.metakey,", ",","),",") LIKE "%', $likes).'%" )' . //remove single space after commas in keywords 102 ' AND ( a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).' )' . 103 ' AND ( a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).' )'; 104 $db->setQuery($query); 105 $temp = $db->loadObjectList(); 106 107 if (count($temp)) 108 { 109 foreach ($temp as $row) 110 { 111 if (($row->cat_state == 1 || $row->cat_state == '') && ($row->sec_state == 1 || $row->sec_state == '') && ($row->cat_access <= $user->get('aid', 0) || $row->cat_access == '') && ($row->sec_access <= $user->get('aid', 0) || $row->sec_access == '')) 112 { 113 $row->route = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid)); 114 $related[] = $row; 115 } 116 } 117 } 118 unset ($temp); 119 } 120 } 121 122 return $related; 123 } 124 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |