1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 JFormHelper::loadFieldClass('groupedlist');
13
14 15 16 17 18
19 class JFormFieldChromeStyle extends JFormFieldGroupedList
20 {
21 22 23 24 25 26
27 public $type = 'ChromeStyle';
28
29 30 31 32 33 34 35 36
37 protected function getGroups()
38 {
39 $groups = array();
40
41
42 $tmp = '---' . JText::_('JLIB_FORM_VALUE_FROM_TEMPLATE') . '---';
43 $groups[$tmp][] = JHtml::_('select.option', '0', JText::_('JLIB_FORM_VALUE_INHERITED'));
44
45 $templateStyles = $this->getTemplateModuleStyles();
46
47
48 foreach ($templateStyles as $template => $styles)
49 {
50 $template = ucfirst($template);
51 $groups[$template] = array();
52
53 foreach ($styles as $style)
54 {
55 $tmp = JHtml::_('select.option', $template . '-' . $style, $style);
56 $groups[$template][] = $tmp;
57 }
58 }
59
60 reset($groups);
61
62 return $groups;
63 }
64
65 66 67 68 69 70 71
72 protected function getTemplateModuleStyles()
73 {
74 $moduleStyles = array();
75
76 $templates = array($this->getSystemTemplate());
77 $templates = array_merge($templates, $this->getTemplates());
78
79 foreach ($templates as $template)
80 {
81 $modulesFilePath = JPATH_SITE . '/templates/' . $template->element . '/html/modules.php';
82
83
84 if (file_exists($modulesFilePath))
85 {
86 $modulesFileData = file_get_contents($modulesFilePath);
87
88 preg_match_all('/function[\s\t]*modChrome\_([a-z0-9\-\_]*)[\s\t]*\(/i', $modulesFileData, $styles);
89
90 if (!array_key_exists($template->element, $moduleStyles))
91 {
92 $moduleStyles[$template->element] = array();
93 }
94
95 $moduleStyles[$template->element] = $styles[1];
96 }
97 }
98
99 return $moduleStyles;
100 }
101
102 103 104 105 106 107 108
109 protected function getSystemTemplate()
110 {
111 $template = new stdClass;
112 $template->element = 'system';
113 $template->name = 'system';
114 $template->enabled = 1;
115
116 return $template;
117 }
118
119 120 121 122 123 124 125
126 protected function getTemplates()
127 {
128 $db = JFactory::getDbo();
129
130
131 $query = $db->getQuery(true);
132
133
134 $query->select('element, name, enabled')
135 ->from('#__extensions')
136 ->where('client_id = 0')
137 ->where('type = ' . $db->quote('template'));
138
139
140 $db->setQuery($query);
141
142 return $db->loadObjectList('element');
143 }
144 }
145