forked from JoomShaper/mod_news_show_sp2_j3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.php
executable file
·179 lines (152 loc) · 5.84 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/*
# News Show SP2 - News display/Slider module by JoomShaper.com
# Author JoomShaper http://www.joomshaper.com
# Copyright (C) 2010 - 2014 JoomShaper.com. All Rights Reserved.
# @license - GNU/GPL V2 or later
# Websites: http://www.joomshaper.com
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
require_once JPATH_SITE.'/components/com_content/helpers/route.php';
jimport( 'joomla.plugin.helper');
JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel');
abstract class modNSSP2JHelper
{
public static function getList($params,$count){
$app = JFactory::getApplication();
$db = JFactory::getDbo();
//Parameters
$catids = $params->get('catids', array());
// Get an instance of the generic articles model
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
// Set application parameters in model
$appParams = $app->getParams();
$model->setState('params', $appParams);
// Set the filters based on the module params
$model->setState('list.start', 0);
$model->setState('list.limit', (int) $count);
$model->setState('filter.published', 1);
// Access filter
$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
$model->setState('filter.access', $access);
//sp comments
if (JPluginHelper::isEnabled('content', 'spcomments')) {
$plgname = JPluginHelper::getPlugin('content', 'spcomments');
$plgParams = json_decode($plgname->params);
}
//sp comments
// Category filter
$model->setState('filter.category_id', $catids);
// User filter
$userId = JFactory::getUser()->get('id');
switch ($params->get('user_id'))
{
case 'by_me':
$model->setState('filter.author_id', (int) $userId);
break;
case 'not_me':
$model->setState('filter.author_id', $userId);
$model->setState('filter.author_id.include', false);
break;
case '0':
break;
default:
$model->setState('filter.author_id', (int) $params->get('user_id'));
break;
}
// Filter by language
$model->setState('filter.language', $app->getLanguageFilter());
// Featured switch
switch ($params->get('show_featured'))
{
case '1':
$model->setState('filter.featured', 'only');
break;
case '0':
$model->setState('filter.featured', 'hide');
break;
default:
$model->setState('filter.featured', 'show');
break;
}
$ordering = $params->get('ordering', 'a.ordering');
$ordering_direction = $params->get('ordering_direction', 'ASC');
$model->setState('list.ordering', $ordering);
$model->setState('list.direction', $ordering_direction);
$items = $model->getItems();
foreach ($items as &$item) {
$item->slug = $item->id.':'.$item->alias;
$item->catslug = $item->catid.':'.$item->category_alias;
$author = JFactory::getUser($item->created_by);
$item->author = ($item->created_by_alias) ? $item->created_by_alias : $author->name;
$item->created = $item->created;
$item->hits = $item->hits;
$item->category = $item->category_title;
$item->cat_link = JRoute::_(ContentHelperRoute::getCategoryRoute($item->catid));
$item->image = self::getImage($item->introtext,$item->images);
$item->title = htmlspecialchars($item->title);
$item->introtext = JHtml::_('content.prepare', $item->introtext);
$item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
if (JPluginHelper::isEnabled('content', 'spcomments'))
{
$item->comment = self::getComment($item->link, $item->catid, $plgParams);
}
else
{
$item->comment = '<a class="ns2-comments" href="#">0 Comment</a>';
}
$item->rating = ($item->rating) ? number_format(intval($item->rating)/intval($item->rating_count), 2)*20 : 0;
}
return $items;
}
private static function getImage($text, $image_src="") {
$image_src = json_decode($image_src);
if (JVERSION>=2.5 && @$image_src->image_intro) {
return $image_src->image_intro;
} elseif (JVERSION>=2.5 && @$image_src->image_fulltext) {
return $image_src->image_fulltext;
} else {
preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $text, $matches);
if (isset($matches[1])) {
return $matches[1];
}
}
}
//function to retrive comment from sp comments plugin
private static function getComment($url, $catid, $params) {
if (JPluginHelper::isEnabled('content', 'spcomments')) {
if (in_array($catid, $params->catids)) {
//identifier
$post_id =substr(JURI::base(), 0, -1)."/".strstr($url, 'index.php');
$identifier = md5($post_id);
//params
$commenting_engine = $params->commenting_engine;
$disqus_subdomain = $params->disqus_subdomain;
$disqus_devmode = $params->disqus_devmode;
$disqus_lang = $params->disqus_lang;
$intensedebate_acc = $params->intensedebate_acc;
$fb_appID = $params->fb_appID;
$fb_lang = $params->fb_lang;
if ($commenting_engine=="disqus") {//if disquss
$link = '<a class="ns2-comments" href="' . $url . '#disqus_thread" data-disqus-identifier="' . $identifier . '"></a>';
} else if ($commenting_engine=="intensedebate") {//intenseDebate
$link = '<span class="containerCountComment">
<script type="text/javascript">
//<![CDATA[
var idcomments_acct = "' . $intensedebate_acc . '";
var idcomments_post_id = "' . $identifier . '";
var idcomments_post_url = encodeURIComponent("' . $post_id . '");
//]]>
</script>
<script type="text/javascript" src="http://www.intensedebate.com/js/genericLinkWrapperV2.js"></script>
</span>';
} else {//facebook
$link = "<a class=\"ns2-comments\" href='$url'>Comments (<fb:comments-count href='$url'></fb:comments-count>)</a>";
}
return $link;
}
}
}
}