-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht4.php
214 lines (175 loc) · 5.26 KB
/
t4.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/**
* @package Joomla.Plugin
* @subpackage Editors.none
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\Event\Event;
/**
* Plain Textarea Editor Plugin
*
* @since 1.5
*/
class PlgSystemT4 extends JPlugin
{
var $editorHelper;
var $updatedRef = false;
var $menuChanged = false;
var $t4 = null;
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
JLoader::registerNamespace('T4', __DIR__ . '/src/t4', false, false, 'psr4');
JLoader::registerNamespace('T4Admin', __DIR__ . '/admin/src', false, false, 'psr4');
$this->t4 = \T4\T4::getInstance();
// add field
//\Joomla\CMS\Form\FormHelper::addFieldPrefix('T4\\Field');
define('T4_PLUGIN', $config['name']);
define('T4PATH', __DIR__);
define('T4PATH_URI', JUri::root(true) . '/plugins/system/' . T4_PLUGIN);
define('T4PATH_THEMES', T4PATH . '/themes');
define('T4PATH_THEMES_URI', T4PATH_URI . '/themes');
define('T4PATH_MEDIA', JPATH_ROOT . '/media/'. T4_PLUGIN);
define('T4PATH_MEDIA_URI', JUri::root(true) . '/media/'. T4_PLUGIN);
define('T4PATH_ADMIN', T4PATH . '/admin');
define('T4PATH_ADMIN_URI', T4PATH_URI . '/admin');
}
protected function isSite() {
return JFactory::getApplication()->isClient('site');
}
/**
* Handle data process
*/
//public function onAfterInitialise() {
public function onAfterRoute() {
if (!$this->isSite()) return;
$this->t4->init();
}
/**
* Init T4Admin if T4 template style is editting
*/
public function onContentPrepareForm($form, $data) {
// Override J3 for admin
\T4Admin\Admin::initj3();
$form_name = $form->getName();
if (!$this->isSite() && $form_name == 'com_templates.style') {
// load the language
$this->loadLanguage();
\T4Admin\Admin::init($form, $data);
}
$this->t4->contentPrepareForm($form, $data);
}
public function onBeforeCompileHead() {
if (!$this->isSite() || !\T4\T4::isT4()) return;
$this->t4->compileHead();
}
/**
* Clean output html, remove empty column
*/
public function onBeforeRender() {
if (!$this->isSite() || !\T4\T4::isT4()) return;
$this->t4->beforeRender();
}
/**
* Clean output html, remove empty column
*/
public function onAfterRender() {
if (!$this->isSite() || !\T4\T4::isT4()) return;
$this->t4->afterRender();
}
/**
* Prepare save, make some data modification
*/
public function onExtensionBeforeSave($context, $table, $isNew = false) {
if ($context == 'com_templates.style') {
\T4Admin\Params::beforeSave($table);
}
}
/* Clean T4 cache */
public function onExtensionAfterSave($context, $table, $isNew) {
if ($context == 'com_templates.style') {
\T4\Helper\Cache::clean();
\T4Admin\Draft::clean();
}
}
/**
* Implement event onRenderModule to include the module chrome provide by T4
* This event is fired by overriding ModuleHelper class
* Return false for continueing render module
*
* @param object &$module A module object.
* @param array $attribs An array of attributes for the module (probably from the XML).
*
* @return bool
*/
function onRenderModule(&$module, $attribs)
{
// only for Joomla 3 frontend
if (!$this->isSite() || \T4\Helper\J3J4::major() >= 4) return false;
static $chromed = false;
// Chrome for module
if (\T4\T4::isT4() && !$chromed) {
$chromed = true;
// We don't need chrome multi times
$chromePath = T4PATH_BASE . '/html/modules.php';
if (file_exists($chromePath)) {
include_once $chromePath;
}
}
return false;
}
/**
* Implement event to allow select layout from base theme inside plugin.
* These events are fireed by overriding Core Joomla lib: FileLayout, HtmlView, ModuleHelper
*/
public function onLayoutIncludePaths (&$path) {
\T4\Helper\Path::addIncludePath($path);
}
public function onHtmlViewAddPath ($type, &$path) {
\T4\Helper\Path::addIncludePath($path);
}
public function onGetLayoutPath($path, $layout)
{
if (!defined('T4PATH_BASE')) return false;
$template = \JFactory::getApplication()->getTemplate();
if (strpos($layout, ':') !== false)
{
$temp = explode(':', $layout);
$template = $temp[0] === '_' ? $template : $temp[0];
$layout = $temp[1];
}
$files = [];
if (\T4\Helper\J3J4::isJ3()) {
// specific for Joomla 3 layout
$files[] = T4PATH_LOCAL . '/html/' . $path . '/' . $layout . '.j3.php';
$files[] = T4PATH_TPL . '/html/' . $path . '/' . $layout . '.j3.php';
$files[] = T4PATH_BASE . '/html/' . $path . '/' . $layout . '.j3.php';
}
// Detect layout path in T4 base
$files[] = T4PATH_LOCAL . '/html/' . $path . '/' . $layout . '.php';
$files[] = T4PATH_TPL . '/html/' . $path . '/' . $layout . '.php';
$files[] = T4PATH_BASE . '/html/' . $path . '/' . $layout . '.php';
foreach ($files as $file) {
if (is_file($file)) return $file;
}
return false;
}
/* Process Ajax for T4 Admin */
public function onAjaxT4(){
// load the language
$this->loadLanguage();
// Clean T4 cache
\T4\Helper\Cache::clean();
// Saving
\T4Admin\Action::run();
}
/* Clean media cache */
public function onAfterPurge($group = null) {
if ($group == 't4') {
\JFolder::delete(T4PATH_MEDIA);
}
}
}