-
Notifications
You must be signed in to change notification settings - Fork 2
/
injector_related.php
101 lines (93 loc) · 2.49 KB
/
injector_related.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
<?php
/**
* @Project Content - Injector Related 1.3
* @author Magnus Arebalus
* @email arebalus.NO.SPAM@gmail.com
* @website github.com/arebalus
* @licence GNU / GPL
* @copyright Copyright (C) 2018 Magnus Arebalus Marcus. All rights reserved.
*/
// No direct access
defined( '_JEXEC' ) or die();
require_once dirname(__FILE__) . '/helpers/helper.php';
class plgContentInjector_related extends JPlugin
{
protected $autoloadLanguage = true;
protected $db;
protected $app;
public function __construct(&$subject,$config)
{
parent::__construct($subject, $config);
}
public function onContentPrepare($context,&$article,&$params,$page)
{
if (plgContentInjector_relatedHelper::shouldRun($context))
{
$config = plgContentInjector_relatedHelper::getConfig($this->params,$article);
$input = JFactory::getApplication()->input;
if ( $input->getCmd('option')=='com_content'
&& $input->getCmd('view')=='article'
)
{
$inject = true;
if ($config['enable'])
{
if ($config['filter'] == 'inc')
{
if (!in_array($article->catid,$config['categories']))
{
$inject = false;
}
}
else
{
if (in_array($article->catid,$config['categories']))
{
$inject = false;
}
}
}
else
{
$inject = false;
}
if ($inject)
{
plgContentInjector_relatedHelper::injectText($article,$config);
}
}
}
return true;
}
public function onBeforeRender()
{
if (
$this->app->isAdmin()
&& $this->app->input->getCmd('option')=='com_plugins'
&& $this->app->input->getCmd('view')=='plugin'
&& $this->app->input->getCmd('layout')=='edit'
)
{
$id = $this->app->input->getCmd('extension_id');
if (!empty($id))
{
$query = $this->db->getQuery(true);
$query ->select('*')
->select($this->db->quoteName('folder'))
->from($this->db->quoteName('#__extensions'))
->where($this->db->quoteName('extension_id').'='.$id)
->where($this->db->quoteName('folder').'='.$this->db->quote($this->_type))
->where($this->db->quoteName('element').'='.$this->db->quote($this->_name))
;
$this ->db->setQuery($query);
$rows = $this->db->loadObjectList();
if (count($rows))
{
$doc = JFactory::getDocument();
$doc ->addScript(rtrim(JUri::root(true),'/').'/media/plg_content_injector_related/js/backend.js');
$doc ->addStyleSheet(rtrim(JUri::root(true),'/').'/media/plg_content_injector_related/css/backend.css');
}
}
}
}
}