OSDN Git Service

携帯関係のウィジェット、テンプレートを削除。
[magic3/magic3.git] / templates / themler_old / editor / library / Designer / Page.php
1 <?php
2 defined('_JEXEC') or die;
3
4 Designer::load("Designer_Shortcodes");
5 /**
6  * Contains page rendering helpers.
7  */
8 class DesignerPage
9 {
10
11     public $page;
12     public $positions = array();
13
14     private $_componentProxy = null;
15     private $_counter = 0;
16
17     public function __construct($page)
18     {
19         $this->page = $page;
20     }
21
22     /*
23      * Checks whether Joomla! has system messages to display and renders theirs.
24      */
25     public function renderSystemMessages()
26     {
27         $app = JFactory::getApplication();
28         $messages = $app->getMessageQueue();
29         ob_start();
30         if (is_array($messages) && count($messages))
31             foreach ($messages as $msg) {
32                 if (isset($msg['type']) && isset($msg['message'])) {
33                     switch ($msg['type']) {
34                         case "info":
35                             echo renderTemplateFromIncludes('funcInfoMessage', array($msg['message']), 'prototypes');
36                             break;
37                         case "error":
38                             echo renderTemplateFromIncludes('funcErrorMessage', array($msg['message']), 'prototypes');
39                             break;
40                         case "":
41                         case "warning":
42                         case "message":
43                             echo renderTemplateFromIncludes('funcWarningMessage', array($msg['message']), 'prototypes');
44                             break;
45                         case "notice":
46                             echo renderTemplateFromIncludes('funcSuccessMessage', array($msg['message']), 'prototypes');
47                             break;
48                         default:
49                             echo $msg['message'];
50                     }
51                 }
52             }
53         return ob_get_clean();
54     }
55
56     /**
57      * Returns true when any of the positions contains at least one module.
58      * Example:
59      *  if ($obj->containsModules('top1', 'top2', 'top3')) {
60      *   // the following code will be executed when one of the positions contains modules:
61      *   ...
62      *  }
63      */
64     public function containsModules()
65     {
66         foreach (func_get_args() as $position)
67             if (0 != $this->page->countModules($position))
68                 return true;
69         return false;
70     }
71
72     public function renderTemplate($themeDir)
73     {
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];
78         }
79         $templates = $themeDir . '/templates/';
80         $templatePath = $templates . $GLOBALS['theme_settings']['currentTemplate'] . '.php';
81
82         if (file_exists($templatePath)) {
83             ob_start();
84             $document = JFactory::getDocument();
85             include_once $templatePath;
86             $template = ob_get_contents();
87             ob_end_clean();
88         } else {
89             $template = 'Template ' . $templatePath . ' not found';
90         }
91
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);
96         }
97         $template = funcContentRoutesCorrector($template);
98         return $template;
99     }
100
101     private function _positionDuplicator($matches)
102     {
103        if ($this->_counter != 1){
104             $content =  str_replace($matches[3], $matches[2], $matches[0]);
105        } else
106             $content =  $matches[0];
107        $this->_counter--;
108        return $content;
109     }
110
111     public function position($position, $style = null, $id = '', $type= '')
112     {
113         array_push($this->positions, $position);
114
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]);
120         }
121         return '<jdoc:include type="modules" title="name-' . $id . '" id="' . $id . '" type="' . $type . '" name="' . $position . '" style="drstyle"' . ' drstyle="' . (null != $style ?  $style : '') . '" />';
122     }
123
124     /**
125      * Process and including needed template
126      */
127     public function componentWrapper($template)
128     {
129         $content = getCustomComponentContent($this->page->getBuffer('component'), $template);
130
131         if ($this->page->getType() != 'html')
132             return;
133         $option = JRequest::getCmd('option');
134         $view = JRequest::getCmd('view');
135         $layout = JRequest::getCmd('layout');
136
137         // Processing of all links
138         $content = funcContentRoutesCorrector($content);
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                         break;
149                     case "category":
150                     case "featured":
151                     case "archive":
152                         break;
153                     case "archive":
154                         break;
155                 }
156                 break;
157             case "com_virtuemart":
158                 switch ($view) {
159                     case "category":
160                         break;
161                     case "productdetails":
162                         break;
163                      case "cart":
164                         break;
165                 }
166                 break;
167             case "com_users":
168                 switch ($view) {
169                     case "remind":
170                         if ("" == $layout) {
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);
173                         }
174                         break;
175                     case "reset":
176                         if ("" == $layout) {
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);
179                         }
180                         break;
181                     case "registration":
182                         if ("" == $layout)
183                             $content = str_replace('<button type="submit" class="validate">', '<button type="submit" class="button validate">', $content);
184                         break;
185                 }
186                 break;
187             default:
188                 break;
189         }
190                 // Code injections:
191         switch ($option) {
192             case "com_content":
193                 switch ($view) {
194                     case "form":
195                         if ("edit" == $layout)
196                             $this->page->addScriptDeclaration($this->getWysiwygBackgroundImprovement());
197                         break;
198                 }
199                 break;
200         }
201
202         $this->page->setBuffer($content, 'component');
203     }
204
205     public function getComponentProxy()
206     {
207         return $this->_componentProxy;
208     }
209
210     public function getWysiwygBackgroundImprovement()
211     {
212         ob_start();
213 ?>
214 window.addEvent('domready', function() {
215     var waitFor = function (interval, criteria, callback) {
216         var interval = setInterval(function () {
217             if (!criteria())
218                 return;
219             clearInterval(interval);
220             callback();
221         }, interval);
222     };
223     var editor = ('undefined' != typeof tinyMCE)
224         ? tinyMCE
225         : (('undefined' != typeof JContentEditor)
226             ? JContentEditor : null);
227     if (null != editor) {
228         // fix for TinyMCE editor
229         waitFor(75,
230             function () {
231                 if (editor.editors)
232                     for (var key in editor.editors)
233                         if (editor.editors.hasOwnProperty(key))
234                             return editor.editors[key].initialized;
235                 return false;
236             },
237             function () {
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/>', {
242                         rel: 'stylesheet',
243                         type: 'text/css',
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');
260                 });
261             });
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');*/
279             }
280         });
281     }
282 });
283 <?php
284         return ob_get_clean();
285     }
286 }