OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / templates / art41_sample2 / library / Artx / Page.php
1 <?php
2 defined('_JEXEC') or die;
3
4 /**
5  * Contains page rendering helpers.
6  */
7 class ArtxPage
8 {
9
10     public $page;
11     public static $inlineScripts = array();
12
13     public function __construct($page)
14     {
15         $this->page = $page;
16     }
17
18     /**
19      * Checks whether Joomla! has system messages to display.
20      */
21     public function hasMessages()
22     {
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']))
28                     return true;
29         return false;
30     }
31
32     /**
33      * Returns true when any of the positions contains at least one module.
34      * Example:
35      *  if ($obj->containsModules('top1', 'top2', 'top3')) {
36      *   // the following code will be executed when one of the positions contains modules:
37      *   ...
38      *  }
39      */
40     public function containsModules()
41     {
42         foreach (func_get_args() as $position)
43             if (0 != $this->page->countModules($position))
44                 return true;
45         return false;
46     }
47
48     /**
49      * Builds the list of positions, collapsing the empty ones.
50      *
51      * Samples:
52      *  Four positions:
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%
57      *  Three positions:
58      *   No empty positions: 33%:33%:34%
59      *   With one empty position: -:66%:34%, 50%:-:50%, 33%:67%:-
60      *   One non-empty position: 100%
61      */
62     public function positions($positions, $style)
63     {
64         // Build $cells by collapsing empty positions:
65         $cells = array();
66         $buffer = 0;
67         $cell = null;
68         foreach ($positions as $name => $width) {
69             if ($this->containsModules($name)) {
70                 $cells[$name] = $buffer + $width;
71                 $buffer = 0;
72                 $cell = $name;
73             } else if (null == $cell)
74                 $buffer += $width;
75             else
76                 $cells[$cell] += $width;
77         }
78
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])
85             {
86                 $cells[$columns2[0]] = 50;
87                 $cells[$columns2[1]] = 50;
88             }
89         }
90
91         // Render $cells:
92         if (count($cells) == 0)
93             return '';
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>';
99         $result .= '</div>';
100         $result .= '</div>';
101         return $result;
102     }
103
104     public function position($position, $style = null)
105     {
106         return '<jdoc:include type="modules" name="' . $position . '"' . (null != $style ? ' style="artstyle" artstyle="' . $style . '"' : '') . ' />';
107     }
108     
109     private function parseInlineScripts($matches) {
110         
111         if (strpos($matches[1], '/*Artisteer scripts*/')) {
112             ArtxPage::$inlineScripts[] = $matches[0];
113             return "";
114         } else {
115             return $matches[0];
116         }
117         
118     }
119     
120     public function includeInlineScripts() {
121         foreach(ArtxPage::$inlineScripts as $script)
122             echo $script;
123     }
124
125     /**
126      * Wraps component content into article style unless it is not already wrapped.
127      *
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.
130      */
131     public function componentWrapper()
132     {
133         if ($this->page->getType() != 'html')
134             return;
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:
140         switch ($option) {
141             case "com_content":
142                 switch ($view) {
143                     case "form":
144                         if ("edit" == $layout)
145                             $content = str_replace('<button type="button" onclick="', '<button type="button" class="button" onclick="', $content);
146                         break;
147                     case "article":
148                         $content = preg_replace_callback('/<script[^>]*>([\s\S]+?)<\/script>/', array( &$this, 'parseInlineScripts'), $content);
149                         break;
150                 }
151                 break;
152             case "com_users":
153                 switch ($view) {
154                     case "remind":
155                         if ("" == $layout) {
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);
158                         }
159                         break;
160                     case "reset":
161                         if ("" == $layout) {
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);
164                         }
165                         break;
166                     case "registration":
167                         if ("" == $layout)
168                             $content = str_replace('<button type="submit" class="validate">', '<button type="submit" class="button validate">', $content);
169                         break;
170                 }
171                 break;
172         }
173         // Code injections:
174         switch ($option) {
175             case "com_content":
176                 switch ($view) {
177                     case "form":
178                         if ("edit" == $layout)
179                             $this->page->addScriptDeclaration($this->getWysiwygBackgroundImprovement());
180                         break;
181                 }
182                 break;
183         }
184         
185         if ('com_content' == $option && ('featured' == $view || 'article' == $view || ('category' == $view && 'blog' == $layout))){
186             $this->page->setBuffer($content, 'component');
187         }
188
189         if (false === strpos($content, '<div class="art-post'))
190             $this->page->setBuffer(artxPost(array('header-text' => null, 'content' => $content)), 'component');
191     }
192
193     public function getWysiwygBackgroundImprovement()
194     {
195         ob_start();
196 ?>
197 window.addEvent('domready', function() {
198     var waitFor = function (interval, criteria, callback) {
199         var interval = setInterval(function () {
200             if (!criteria())
201                 return;
202             clearInterval(interval);
203             callback();
204         }, interval);
205     };
206     var editor = ('undefined' != typeof tinyMCE)
207         ? tinyMCE
208         : (('undefined' != typeof JContentEditor)
209             ? JContentEditor : null);
210     if (null != editor) {
211         // fix for TinyMCE editor
212         waitFor(75,
213             function () {
214                 if (editor.editors)
215                     for (var key in editor.editors)
216                         if (editor.editors.hasOwnProperty(key))
217                             return editor.editors[key].initialized;
218                 return false;
219             },
220             function () {
221                 jQuery('#jform_articletext_ifr').load( function () {
222                     var context = this,
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');
239                     }
240                 });
241             });
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');
259             }
260         });
261     }
262 });
263 <?php
264         return ob_get_clean();
265     }
266 }