Created
October 29, 2010 04:23
-
-
Save eqdw/652906 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @version $Id: helper.php 14401 2010-01-26 14:10:00Z louis $ | |
* @package Joomla | |
* @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. | |
* @license GNU/GPL, see LICENSE.php | |
* Joomla! is free software. This version may have been modified pursuant | |
* to the GNU General Public License, and as distributed it includes or | |
* is derivative of works licensed under the GNU General Public License or | |
* other free or open source software licenses. | |
* See COPYRIGHT.php for copyright notices and details. | |
*/ | |
// no direct access | |
defined('_JEXEC') or die('Restricted access'); | |
require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php'); | |
class modRelatedHelper | |
{ | |
function getTheShitYouNeed(&$params) | |
{ | |
global $mainframe; | |
$db =& JFactory::getDBO(); | |
$user =& JFactory::getUser(); | |
$userId = (int) $user->get('id'); | |
$count = (int) $params->get('count', 5); | |
$catid = trim( $params->get('catid') ); | |
$secid = trim( $params->get('secid') ); | |
$show_front = $params->get('show_front', 1); | |
$aid = $user->get('aid', 0); | |
$contentConfig = &JComponentHelper::getParams( 'com_content' ); | |
$access = !$contentConfig->get('show_noauth'); | |
//MY EDITS | |
$relatedArticles = $contentConfig->get('related_articles'); | |
$arrRelatedArticles = explode(",", $relatedArticles); | |
$tmp__curID = explode(":", $_GET[id]); | |
$curID = $tmp__curID[0]; | |
$show_clients = $contentConfig->get("link_to_client"); | |
////////// | |
$nullDate = $db->getNullDate(); | |
$date =& JFactory::getDate(); | |
$now = $date->toMySQL(); | |
$where = 'a.state = 1' | |
. ' AND ( a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).' )' | |
. ' AND ( a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).' )' | |
; | |
// User Filter | |
switch ($params->get( 'user_id' )) | |
{ | |
case 'by_me': | |
$where .= ' AND (created_by = ' . (int) $userId . ' OR modified_by = ' . (int) $userId . ')'; | |
break; | |
case 'not_me': | |
$where .= ' AND (created_by <> ' . (int) $userId . ' AND modified_by <> ' . (int) $userId . ')'; | |
break; | |
} | |
// Ordering | |
switch ($params->get( 'ordering' )) | |
{ | |
case 'a_asc': | |
$ordering = 'a.title ASC'; | |
break; | |
case 'm_dsc': | |
$ordering = 'a.modified DESC, a.created DESC'; | |
break; | |
case 'c_dsc': | |
default: | |
$ordering = 'a.created DESC'; | |
break; | |
} | |
if ($catid) | |
{ | |
$ids = explode( ',', $catid ); | |
JArrayHelper::toInteger( $ids ); | |
$catCondition = ' AND (cc.id=' . implode( ' OR cc.id=', $ids ) . ')'; | |
} | |
if ($secid) | |
{ | |
$ids = explode( ',', $secid ); | |
JArrayHelper::toInteger( $ids ); | |
$secCondition = ' AND (s.id=' . implode( ' OR s.id=', $ids ) . ')'; | |
} | |
// Content Items only | |
$query = 'SELECT a.*, ' . | |
' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'. | |
' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug'. | |
' FROM #__content AS a' . | |
($show_front == '0' ? ' LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id' : '') . | |
' INNER JOIN #__categories AS cc ON cc.id = a.catid' . | |
' INNER JOIN #__sections AS s ON s.id = a.sectionid' . | |
' WHERE '. $where .' AND s.id > 0' . | |
($access ? ' AND a.access <= ' .(int) $aid. ' AND cc.access <= ' .(int) $aid. ' AND s.access <= ' .(int) $aid : ''). | |
($catid ? $catCondition : ''). | |
($secid ? $secCondition : ''). | |
($show_front == '0' ? ' AND f.content_id IS NULL ' : ''). | |
' AND s.published = 1' . | |
' AND cc.published = 1' . | |
' ORDER BY a.title ASC'; | |
$db->setQuery($query, 0, 0); | |
$rows = $db->loadObjectList(); | |
$i = 0; | |
$related_by_tags = array(); | |
$related_client = array(); | |
$related_client_second = array(); | |
$isAClient = false; | |
foreach ( $rows as $row ) | |
{ | |
$tmp_param = new JParameter($row->attribs); | |
//enumerate context's primary client | |
if( $params->get('show_related_by_client') && | |
//$row->id != $curID && | |
$show_clients && | |
$row->sectionid != 2 /*so it doesn't display client articles */ && | |
(($tmp_param->get('link_to_client') && | |
($tmp_param->get('client_article_id') == $contentConfig->get('client_article_id') || | |
$tmp_param->get('client_article_id') == $curID)) || | |
($tmp_param->get('multiclass') && | |
($tmp_param->get('second_client_article_id') == $contentConfig->get('client_article_id') || | |
$tmp_param->get('second_client_article_id') == $curID))) ){ | |
$tmp = new stdClass(); | |
if($row->access <= $aid) | |
{ | |
$tmp->link = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid)); | |
} else { | |
$tmp->link = JRoute::_('index.php?option=com_user&view=login'); | |
} | |
if($tmp_param->get("short_title")): | |
$tmp->text = htmlspecialchars( $tmp_param->get("short_title") ); | |
else: | |
$tmp->text = htmlspecialchars( $row->title); | |
endif; | |
$related_client[$i] = $tmp; | |
$i++; | |
} | |
} | |
if($contentConfig->get('multiclass')){ | |
$i = 0; | |
foreach ( $rows as $row ) { | |
$tmp_param = new JParameter($row->attribs); | |
if($row->id != $curID){ | |
} | |
if($row->id == $curID){ | |
} | |
//enumerate context's primary client | |
if( | |
$params->get('show_related_by_client') && | |
// $row->id != $curID && | |
$show_clients && | |
$row->sectionid != 2 /*so it doesn't display client articles */ && | |
(($tmp_param->get('link_to_client') && | |
($tmp_param->get('client_article_id') == $contentConfig->get('second_client_article_id') || | |
$tmp_param->get('client_article_id') == $curID)) || | |
($tmp_param->get('multiclass') && | |
($tmp_param->get('second_client_article_id') == $contentConfig->get('second_client_article_id') || | |
$tmp_param->get('second_client_article_id') == $curID))) ){ | |
$tmp = new stdClass(); | |
if($row->access <= $aid) | |
{ | |
$tmp->link = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid)); | |
} else { | |
$tmp->link = JRoute::_('index.php?option=com_user&view=login'); | |
} | |
if($tmp_param->get("short_title")): | |
$tmp->text = htmlspecialchars( $tmp_param->get("short_title") ); | |
else: | |
$tmp->text = htmlspecialchars( $row->title); | |
endif; | |
$related_client_second[$i] = $tmp; | |
$i++; | |
} | |
} | |
} | |
//shortcut and save | |
$tags = explode(",", $contentConfig->get('tags')); | |
for($i=0;$i<count($tags);$i++){ | |
$related_by_tags[$i] = array(); | |
} | |
foreach($rows as $row){ | |
$tmp = new stdClass(); | |
$tmp_param = new JParameter($row->attribs); | |
$tmp_tags = explode(",", $tmp_param->get('tags')); | |
if($row->access <= $aid){ | |
$tmp->link = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid)); | |
} else { | |
$tmp->link = JRoute::_('index.php?option=com_user&view=login'); | |
} | |
if($tmp_param->get("short_title")): | |
$tmp->text = htmlspecialchars( $tmp_param->get("short_title") ); | |
else: | |
$tmp->text = htmlspecialchars( $row->title); | |
endif; | |
for($i=0;$i<sizeof($tags);$i++){ | |
if($tags[$i] && in_array($tags[$i], $tmp_tags)){ | |
$related_by_tags[$i][] = $tmp; | |
} | |
} | |
// $related_by_tags[$i] = $tmp; | |
$i++; | |
} | |
$rtn = new stdClass(); | |
$rtn->tags = $tags; | |
$rtn->related_by_tags = $related_by_tags; | |
$rtn->client = $related_client; | |
$rtn->second_client = $related_client_second; | |
if( count($rtn->client)){ | |
$query = ""; | |
$query = "SELECT title FROM #__content WHERE id = " . $contentConfig->get('client_article_id'); | |
$db->setQuery($query, 0, 0); | |
$rtn->title = $db->loadResult(); | |
}else{ | |
$rtn->title = "Client"; | |
} | |
if( count($rtn->second_client)){ | |
$query = ""; | |
$query = "SELECT title FROM #__content WHERE id = " . $contentConfig->get('second_client_article_id'); | |
$db->setQuery($query,0,0); | |
$rtn->second_title = $db->loadResult(); | |
}else{ | |
$rtn->second_title = "Second Client"; | |
} | |
return $rtn; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment