-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadd_xml_fields.php
More file actions
161 lines (148 loc) · 5.31 KB
/
add_xml_fields.php
File metadata and controls
161 lines (148 loc) · 5.31 KB
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
<?php
// No direct access
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Form\Form;
use Joomla\Database\DatabaseDriver;
class plgSystemAdd_xml_fields extends CMSPlugin
{
/**
* Load the language file on instantiation.
* Note this is only available in Joomla 3.1 and higher.
* If you want to support 3.0 series you must override the constructor
*
* @var boolean
* @since <your version>
*/
protected $autoloadLanguage = true;
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
}
/**
* Prepare form and add my field.
*
* @param Form $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since <your version>
*/
function onContentPrepareForm($form, $data)
{
$app = Factory::getApplication();
$option = $app->input->get('option');
$theadmincomponentsfiles = preg_split('/\s*,\s*/', (string) $this->params->get('theadmincomponentsfiles', ''), -1, PREG_SPLIT_NO_EMPTY);
$theadmincomponents = preg_split('/\s*,\s*/', (string) $this->params->get('theadmincomponents'), -1, PREG_SPLIT_NO_EMPTY);
$thesitecomponentsfiles = preg_split('/\s*,\s*/', (string) $this->params->get('thesitecomponentsfiles'), -1, PREG_SPLIT_NO_EMPTY);
$thesitecomponents = preg_split('/\s*,\s*/', (string) $this->params->get('thesitecomponents'), -1, PREG_SPLIT_NO_EMPTY);
$pieces = preg_split('/\s*,\s*/', (string) $this->params->get('filenames'), -1, PREG_SPLIT_NO_EMPTY);
$themodules = preg_split('/\s*,\s*/', (string) $this->params->get('themodules'), -1, PREG_SPLIT_NO_EMPTY);
if (version_compare(JVERSION, '3.0', 'ge'))
{
$db = Factory::getDBO();
}
else
{
$db = Factory::getContainer()->get(DatabaseDriver::class);
}
$query = 'SELECT module' . ' FROM #__modules' . ' WHERE id = ' . $db->Quote($app->input->get("id"));
$db->setQuery($query);
$module = $db->loadResult();
//Load the Site Default Template
// if Joomla 3.0
if (version_compare(JVERSION, '3.0', 'ge'))
{
$dbtemplate = Factory::getDBO();
}
else
{
$dbtemplate = Factory::getContainer()->get(DatabaseDriver::class);
}
$querytemplate = "SELECT template FROM #__template_styles WHERE client_id = 0 AND home = 1";
$dbtemplate->setQuery($querytemplate);
$defaultsitetemplate = $dbtemplate->loadResult();
if (version_compare(JVERSION, '3.0', 'ge'))
{
$dbadmintemplate = Factory::getDBO();
}
else
{
$dbadmintemplate = Factory::getContainer()->get(DatabaseDriver::class);
}
$queryadmintemplate = "SELECT template FROM #__template_styles WHERE client_id = 1 AND home = 1";
$dbadmintemplate->setQuery($queryadmintemplate);
$defaultadmintemplate = $dbadmintemplate->loadResult();
//For ADMIN COMPONENTS
foreach ($theadmincomponents as $adminkey => $theadmincomponent)
{
$theadmincomponent = trim($theadmincomponent);
if (in_array($option, $theadmincomponents))
{
switch ($this->params->get('theadmincomponentsfilespaths'))
{
case 'system' :
Form::addFormPath(JPATH_ADMINISTRATOR . '/templates/system/forms/' . $theadmincomponent . '/');
break;
case 'template_override' :
Form::addFormPath(JPATH_ADMINISTRATOR . '/templates/' . $defaultadmintemplate . '/html/' . $theadmincomponent . '/forms/');
break;
case 'plugins' :
Form::addFormPath(JPATH_PLUGINS . '/system/add_xml_fields/');
break;
}
if ($option == $theadmincomponent)
{
$form->loadFile($theadmincomponentsfiles[$adminkey], false);
}
}
}
//For SITE COMPONENTS
foreach ($thesitecomponents as $sitekey => $thesitecomponent)
{
$thesitecomponent = trim($thesitecomponent);
if (in_array($option, $thesitecomponents))
{
switch ($this->params->get('thesitecomponentsfilespaths'))
{
case 'system' :
Form::addFormPath(JPATH_SITE . '/templates/system/forms/' . $thesitecomponent . '/');
break;
case 'template_override' :
Form::addFormPath(JPATH_SITE . '/templates/' . $defaultsitetemplate . '/html/' . $thesitecomponent . '/forms/');
break;
case 'plugins' :
Form::addFormPath(JPATH_PLUGINS . '/system/add_xml_fields/');
break;
}
if ($option == $thesitecomponent)
{
$form->loadFile($thesitecomponentsfiles[$sitekey], false);
}
}
}
// For Site Modules
foreach ($themodules as $key => $themodule)
{
$themodule = trim($themodule);
if (in_array($module, $themodules))
{
switch ($this->params->get('thepath'))
{
case 'template_override' :
Form::addFormPath(JPATH_SITE . '/templates/' . $defaultsitetemplate . '/html/' . $themodule . '/');
break;
case 'plugins' :
Form::addFormPath(JPATH_PLUGINS . '/system/add_xml_fields/');
break;
}
if ($module == $themodule)
{
$form->loadFile($pieces[$key], false);
}
}
}
}
}