-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspcomments.php
97 lines (65 loc) · 2.54 KB
/
spcomments.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
<?php
/**
* @package SP Comments - Three in One comments plugin for Joomla by JoomShaper.com
* @author JoomShaper http://www.joomshaper.com
* @copyright Copyright (C) 2010 - 2015 JoomShaper
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2
*/
//no direct access
defined('_JEXEC') or die('Restricted Access');
jimport('joomla.plugin.plugin');
class plgContentSPComments extends JPlugin {
protected $autoloadLanguage = true;
/* function to work when preparing the content on frontpage or listing pages */
function onContentAfterDisplay($context, &$article, &$params, $limitstart=0) {
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$option = $app->input->getCmd('option', '');
if ($app->isAdmin()) {
return;
}
$language = $doc->language;
if( $option == 'com_content' || $option = 'com_k2' ) {
$view = JFactory::getApplication()->input->getString('view', '');
} else {
$view = 'unknown';
}
ob_start();
if( $view == 'article' || $view == 'item' ) {
if( !$this->inCategory($article, $this->params) ) return; /*Return if not in this category*/
$url = $this->getUrl( $article );
require_once __DIR__ . '/layout/' . $this->params->get('commenting_engine') . '.php';
} else if ( $view == 'category' || $view == 'featured' || $view == 'itemlist' ) { /* Comments Count */
if( !$this->inCategory($article, $this->params) ) return; /*Return if not in this category*/
$url = $this->getUrl( $article );
include __DIR__ . '/layout/' . $this->params->get('commenting_engine') . '-count.php';
}
return ob_get_clean();
}
function inCategory($article, $params) {
$app = JFactory::getApplication();
$option = $app->input->getCmd('option', '');
$cats = $params->get('catids');
if($option == "com_k2") {
$cats = $params->get('k2catids');
}
if(in_array($article->catid, $cats)) {
return true;
}
return false;
}
/* Get Article URL */
function getUrl( $article ) {
$app = JFactory::getApplication();
$option = $app->input->getCmd('option', '');
if ($option == 'com_content') {
$url = JRoute::_(ContentHelperRoute::getArticleRoute($article->id . ':' . $article->alias, $article->catid, $article->language));
} elseif($option == "com_k2") {
$url = urldecode(JRoute::_(K2HelperRoute::getItemRoute($article->id.':'.urlencode($article->alias), $article->catid.':'.urlencode($article->category->alias))));
}
$root = JURI::base();
$root = new JURI($root);
$url = $root->getScheme() . '://' . $root->getHost() . $url;
return $url;
}
}