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