2 defined('_JEXEC') or die;
4 Designer::load("Designer_Shortcodes");
6 * Contains page rendering helpers.
12 public $positions = array();
14 private $_componentProxy = null;
15 private $_counter = 0;
17 public function __construct($page)
23 * Checks whether Joomla! has system messages to display and renders theirs.
25 public function renderSystemMessages()
27 $app = JFactory::getApplication();
28 $messages = $app->getMessageQueue();
30 if (is_array($messages) && count($messages))
31 foreach ($messages as $msg) {
32 if (isset($msg['type']) && isset($msg['message'])) {
33 switch ($msg['type']) {
35 echo renderTemplateFromIncludes('funcInfoMessage', array($msg['message']), 'prototypes');
38 echo renderTemplateFromIncludes('funcErrorMessage', array($msg['message']), 'prototypes');
43 echo renderTemplateFromIncludes('funcWarningMessage', array($msg['message']), 'prototypes');
46 echo renderTemplateFromIncludes('funcSuccessMessage', array($msg['message']), 'prototypes');
53 return ob_get_clean();
57 * Returns true when any of the positions contains at least one module.
59 * if ($obj->containsModules('top1', 'top2', 'top3')) {
60 * // the following code will be executed when one of the positions contains modules:
64 public function containsModules()
66 foreach (func_get_args() as $position)
67 if (0 != $this->page->countModules($position))
72 public function renderTemplate($themeDir)
74 $content = $this->page->getBuffer('component');
75 if (preg_match('/<!--TEMPLATE ([\s\S]*?) \/-->/', $content, $matches)) {
76 $this->page->setBuffer(str_replace('<!--TEMPLATE ' . $matches[1] . ' /-->', '', $content), 'component');
77 $GLOBALS['theme_settings']['currentTemplate'] = $matches[1];
79 $templates = $themeDir . '/templates/';
80 $templatePath = $templates . $GLOBALS['theme_settings']['currentTemplate'] . '.php';
82 if (file_exists($templatePath)) {
84 $document = JFactory::getDocument();
85 include_once $templatePath;
86 $template = ob_get_contents();
89 $template = 'Template ' . $templatePath . ' not found';
92 foreach($this->positions as $position) {
93 preg_match_all('/<jdoc:include\ type="([^"]+)" id="([^"]*)" name="' . $position . '" (.*)\/>/iU', $template, $matches);
94 $this->_counter = count($matches[0]);
95 $template = preg_replace_callback('#<jdoc:include\ type="([^"]+)" id="([^"]*)" name="(' . $position . ')" (.*)\/>#iU', array( &$this, '_positionDuplicator'), $template);
97 $template = funcContentRoutesCorrector($template);
101 private function _positionDuplicator($matches)
103 if ($this->_counter != 1){
104 $content = str_replace($matches[3], $matches[2], $matches[0]);
106 $content = $matches[0];
111 public function position($position, $style = null, $id = '', $type= '')
113 array_push($this->positions, $position);
115 $g = array_count_values($this->positions);
116 $count = $g[$position];
117 if ($count > 1 && !empty($id)) {
118 $key = array_search($position, $this->positions);
119 unset($this->positions[$key]);
121 return '<jdoc:include type="modules" title="name-' . $id . '" id="' . $id . '" type="' . $type . '" name="' . $position . '" style="drstyle"' . ' drstyle="' . (null != $style ? $style : '') . '" />';
125 * Process and including needed template
127 public function componentWrapper($template)
129 $content = getCustomComponentContent($this->page->getBuffer('component'), $template);
131 if ($this->page->getType() != 'html')
133 $option = JRequest::getCmd('option');
134 $view = JRequest::getCmd('view');
135 $layout = JRequest::getCmd('layout');
137 // Processing of all links
138 $content = funcContentRoutesCorrector($content);
139 // Workarounds for Joomla bugs and inconsistencies:
144 if ("edit" == $layout)
145 $content = str_replace('<button type="button" onclick="', '<button type="button" class="button" onclick="', $content);
157 case "com_virtuemart":
161 case "productdetails":
171 $content = str_replace('<button type="submit">', '<button type="submit" class="button">', $content);
172 $content = str_replace('<button type="submit" class="validate">', '<button type="submit" class="button">', $content);
177 $content = str_replace('<button type="submit">', '<button type="submit" class="button">', $content);
178 $content = str_replace('<button type="submit" class="validate">', '<button type="submit" class="button">', $content);
183 $content = str_replace('<button type="submit" class="validate">', '<button type="submit" class="button validate">', $content);
195 if ("edit" == $layout)
196 $this->page->addScriptDeclaration($this->getWysiwygBackgroundImprovement());
202 $this->page->setBuffer($content, 'component');
205 public function getComponentProxy()
207 return $this->_componentProxy;
210 public function getWysiwygBackgroundImprovement()
214 window.addEvent('domready', function() {
215 var waitFor = function (interval, criteria, callback) {
216 var interval = setInterval(function () {
219 clearInterval(interval);
223 var editor = ('undefined' != typeof tinyMCE)
225 : (('undefined' != typeof JContentEditor)
226 ? JContentEditor : null);
227 if (null != editor) {
228 // fix for TinyMCE editor
232 for (var key in editor.editors)
233 if (editor.editors.hasOwnProperty(key))
234 return editor.editors[key].initialized;
238 var ifr = jQuery('#jform_articletext_ifr');
239 var ifrdoc = ifr[0] && ifr[0].contentDocument;
240 ifrdoc && jQuery('link[href*="/css/editor.css"]', ifrdoc).ready(function () {
241 var link = jQuery('<link/>', {
244 href: '<?php echo JURI::root() . 'templates/' . $this->page->template . '/css/bootstrap.css'; ?>' });
245 jQuery('head', ifrdoc).append(link);
246 jQuery('link[href$="content.css"]', ifrdoc).remove();
247 ifr.css('background', 'transparent').attr('allowtransparency', 'true');
248 var ifrBodyNode = jQuery('body', ifrdoc);
249 var layout = jQuery('table.mceLayout');
250 var toolbar = layout.find('.mceToolbar');
251 var toolbarBg = toolbar.css('background-color');
252 var statusbar = layout.find('.mceStatusbar');
253 var statusbarBg = statusbar.css('background-color');
254 layout.css('background', 'transparent');
255 toolbar.css('background', toolbarBg);
256 toolbar.css('direction', '');
257 statusbar.css('background', statusbarBg);
258 ifrBodyNode.css('background', 'transparent');
259 ifrBodyNode.attr('dir', 'ltr');
262 } else if ('undefined' != typeof CKEDITOR) {
263 CKEDITOR.on('instanceReady', function (evt) {
264 var includesTemplateStyle = 0 != jQuery('link[href*="/css/template.css"]', evt.editor.document.$).length;
265 var includesEditorStyle = 0 != jQuery('link[href*="/css/editor.css"]', evt.editor.document.$).length;
266 if (includesTemplateStyle || includesEditorStyle) {
267 jQuery('#cke_ui_color').remove();
268 var ifr = jQuery('#cke_contents_text>iframe');
269 ifr.parent().css('background', 'transparent')
270 .parent().parent().parent().parent()
271 .css('background', 'transparent');
272 console.log(jQuery('.cke_wrapper'));
273 ifr.attr('allowtransparency', 'true');
274 ifr.css('background', 'transparent');
275 var ifrdoc = ifr.attr('contentDocument');
276 jQuery('body', ifrdoc).css('background', 'transparent');
277 /*if (includesTemplateStyle)
278 jQuery('body', ifrdoc).attr('id', 'bd-main').addClass('bd-postcontent');*/
284 return ob_get_clean();