2 defined('_JEXEC') or die;
5 * Contains page rendering helpers.
11 public static $inlineScripts = array();
13 public function __construct($page)
19 * Checks whether Joomla! has system messages to display.
21 public function hasMessages()
23 $app = JFactory::getApplication();
24 $messages = $app->getMessageQueue();
25 if (is_array($messages) && count($messages))
26 foreach ($messages as $msg)
27 if (isset($msg['type']) && isset($msg['message']))
33 * Returns true when any of the positions contains at least one module.
35 * if ($obj->containsModules('top1', 'top2', 'top3')) {
36 * // the following code will be executed when one of the positions contains modules:
40 public function containsModules()
42 foreach (func_get_args() as $position)
43 if (0 != $this->page->countModules($position))
49 * Builds the list of positions, collapsing the empty ones.
53 * No empty positions: 25%:25%:25%:25%
54 * With one empty position: -:50%:25%:25%, 50%:-:25%:25%, 25%:50%:-:25%, 25%:25%:50%:-
55 * With two empty positions: -:-:75%:25%, -:50%:-:50%, -:50%:50%:-, -:50%:50%:-, 75%:-:-:25%, 50%:-:50%:-, 25%:75%:-:-
56 * One non-empty position: 100%
58 * No empty positions: 33%:33%:34%
59 * With one empty position: -:66%:34%, 50%:-:50%, 33%:67%:-
60 * One non-empty position: 100%
62 public function positions($positions, $style)
64 // Build $cells by collapsing empty positions:
68 foreach ($positions as $name => $width) {
69 if ($this->containsModules($name)) {
70 $cells[$name] = $buffer + $width;
73 } else if (null == $cell)
76 $cells[$cell] += $width;
79 // Backward compatibility: for three equal width columns with empty center position the result should be 50%/50%:
80 if (3 == count($positions) && 2 == count($cells)) {
81 $columns1 = array_keys($positions);
82 $columns2 = array_keys($cells);
83 if (33 == $positions[$columns1[0]] && 33 == $positions[$columns1[1]] && 34 == $positions[$columns1[2]]
84 && $columns2[0] == $columns1[0] && $columns2[1] == $columns1[2])
86 $cells[$columns2[0]] = 50;
87 $cells[$columns2[1]] = 50;
92 if (count($cells) == 0)
94 $result = '<div class="art-content-layout">';
95 $result .= '<div class="art-content-layout-row">';
96 foreach ($cells as $name => $width)
97 $result .='<div class="art-layout-cell' . ('art-block' == $style ? ' art-layout-sidebar-bg' : '')
98 . '" style="width: ' . $width. '%;">' . $this->position($name, $style) . '</div>';
104 public function position($position, $style = null)
106 return '<jdoc:include type="modules" name="' . $position . '"' . (null != $style ? ' style="artstyle" artstyle="' . $style . '"' : '') . ' />';
109 private function parseInlineScripts($matches) {
111 if (strpos($matches[1], '/*Artisteer scripts*/')) {
112 ArtxPage::$inlineScripts[] = $matches[0];
120 public function includeInlineScripts() {
121 foreach(ArtxPage::$inlineScripts as $script)
126 * Wraps component content into article style unless it is not already wrapped.
128 * The componentWrapper method gets the content of the 'component' buffer and searches for the '<div class="art-post">' string in it.
129 * Then it wraps the content of the buffer with the art-post.
131 public function componentWrapper()
133 if ($this->page->getType() != 'html')
135 $option = JRequest::getCmd('option');
136 $view = JRequest::getCmd('view');
137 $layout = JRequest::getCmd('layout');
138 $content = $this->page->getBuffer('component');
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);
148 $content = preg_replace_callback('/<script[^>]*>([\s\S]+?)<\/script>/', array( &$this, 'parseInlineScripts'), $content);
156 $content = str_replace('<button type="submit">', '<button type="submit" class="button">', $content);
157 $content = str_replace('<button type="submit" class="validate">', '<button type="submit" class="button">', $content);
162 $content = str_replace('<button type="submit">', '<button type="submit" class="button">', $content);
163 $content = str_replace('<button type="submit" class="validate">', '<button type="submit" class="button">', $content);
168 $content = str_replace('<button type="submit" class="validate">', '<button type="submit" class="button validate">', $content);
178 if ("edit" == $layout)
179 $this->page->addScriptDeclaration($this->getWysiwygBackgroundImprovement());
185 if ('com_content' == $option && ('featured' == $view || 'article' == $view || ('category' == $view && 'blog' == $layout))){
186 $this->page->setBuffer($content, 'component');
189 if (false === strpos($content, '<div class="art-post'))
190 $this->page->setBuffer(artxPost(array('header-text' => null, 'content' => $content)), 'component');
193 public function getWysiwygBackgroundImprovement()
197 window.addEvent('domready', function() {
198 var waitFor = function (interval, criteria, callback) {
199 var interval = setInterval(function () {
202 clearInterval(interval);
206 var editor = ('undefined' != typeof tinyMCE)
208 : (('undefined' != typeof JContentEditor)
209 ? JContentEditor : null);
210 if (null != editor) {
211 // fix for TinyMCE editor
215 for (var key in editor.editors)
216 if (editor.editors.hasOwnProperty(key))
217 return editor.editors[key].initialized;
221 jQuery('#jform_articletext_ifr').load( function () {
223 document = context.contentDocument;
224 if (jQuery('link[href*="/css/editor.css"]', document).length) {
225 jQuery('link[href$="content.css"]', document).remove();
226 context.css('background', 'transparent').attr('allowtransparency', 'true');
227 var ifrBodyNode = jQuery('body', document),
228 layout = jQuery('table.mceLayout'),
229 toolbar = layout.find('.mceToolbar'),
230 toolbarBg = toolbar.css('background-color'),
231 statusbar = layout.find('.mceStatusbar'),
232 statusbarBg = statusbar.css('background-color');
233 layout.css('background', 'transparent');
234 toolbar.css('background', toolbarBg);
235 toolbar.css('direction', 'ltr');
236 statusbar.css('background', statusbarBg);
237 ifrBodyNode.css('background', 'transparent');
238 ifrBodyNode.attr('dir', 'ltr');
242 } else if ('undefined' != typeof CKEDITOR) {
243 CKEDITOR.on('instanceReady', function (evt) {
244 var includesTemplateStyle = 0 != jQuery('link[href*="/css/template.css"]', evt.editor.document.$).length;
245 var includesEditorStyle = 0 != jQuery('link[href*="/css/editor.css"]', evt.editor.document.$).length;
246 if (includesTemplateStyle || includesEditorStyle) {
247 jQuery('#cke_ui_color').remove();
248 var ifr = jQuery('.cke_editor iframe');
249 ifr.parent().css('background', 'transparent')
250 .parent().parent().parent().parent()
251 .css('background', 'transparent');
252 console.log(jQuery('.cke_wrapper'));
253 ifr.attr('allowtransparency', 'true');
254 ifr.css('background', 'transparent');
255 var ifrdoc = ifr.get(0).contentDocument;
256 jQuery('body', ifrdoc).css({'background' : 'transparent', 'overflow' : 'scroll'});
257 if (includesTemplateStyle)
258 jQuery('body', ifrdoc).attr('id', 'art-main').addClass('art-postcontent');
264 return ob_get_clean();