OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / templates / car_city_v1 / functions.php
1 <?php
2 defined('_JEXEC') or die('Restricted access'); // no direct access
3
4 if (!defined('_ARTX_FUNCTIONS')) {
5
6         define('_ARTX_FUNCTIONS', 1);
7
8         function artxHasMessages()
9         {
10                 global $mainframe;
11                 $messages = $mainframe->getMessageQueue();
12                 if (is_array($messages) && count($messages))
13                         foreach ($messages as $msg)
14                                 if (isset($msg['type']) && isset($msg['message']))
15                                         return true;
16                 return false;
17         }
18
19         function artxUrlToHref($url)
20         {
21                 $result = '';
22                 $p = parse_url($url);
23                 if (isset($p['scheme']) && isset($p['host'])) {
24                         $result = $p['scheme'] . '://';
25                         if (isset($p['user'])) {
26                                 $result .= $p['user'];
27                                 if (isset($p['pass']))
28                                         $result .= ':' . $p['pass'];
29                                 $result .= '@';
30                         }
31                         $result .= $p['host'];
32                         if (isset($p['port']))
33                                 $result .= ':' . $p['port'];
34                         if (!isset($p['path']))
35                                 $result .= '/';
36                 }
37                 if (isset($p['path']))
38                         $result .= $p['path'];
39                 if (isset($p['query'])) {
40                         $result .= '?' . str_replace('&', '&amp;', $p['query']);
41                 }
42                 if (isset($p['fragment']))
43                         $result .= '#' . $p['fragment'];
44                 return $result;
45         }
46
47         function artxReplaceButtonsRegex() {
48                 return '' .
49                         '~<input\b[^>]*'
50                                 . '(?:'
51                                         . '[^>]*\bclass=(?:"(?:[^"]*\s)?button(?:\s[^"]*)?"|\'(?:[^\']*\s)?button(?:\s[^\']*)?\'|button\b)[^>]*'
52                                         . '(?:\bvalue=(?:"[^"]*"|\'[^\']*\'|[^>\s]*))'
53                                 . '|'
54                                         . '(?:\bvalue=(?:"[^"]*"|\'[^\']*\'|[^>\s]*))'
55                                         . '[^>]*\bclass=(?:"(?:[^"]*\s)?button(?:\s[^"]*)?"|\'(?:[^\']*\s)?button(?:\s[^\']*)?\'|button\b)[^>]*'
56                                 . '|'
57                                         . '[^>]*\bclass=(?:"(?:[^"]*\s)?button(?:\s[^"]*)?"|\'(?:[^\']*\s)?button(?:\s[^\']*)?\'|button\b)[^>]*'
58                                 . ')'
59                         . '[^>]*/?\s*>~i';
60         }
61
62         function artxReplaceButtons($content)
63         {
64                 $re = artxReplaceButtonsRegex();
65                 if (!preg_match_all($re, $content, $matches, PREG_OFFSET_CAPTURE))
66                         return $content;
67
68                 $result = '';
69                 $position = 0;
70                 foreach ($matches[0] as $match) {
71                         $result .= substr($content, $position, $match[1] - $position);
72                         $position = $match[1] + strlen($match[0]);
73                         $result .= '<span class="art-button-wrapper"><span class="l"> </span><span class="r"> </span>'
74                                 . preg_replace('~\bclass=(?:"([^"]*\s)?button(\s[^"]*)?"|\'([^\']*\s)?button(\s[^\']*)?\'|button\b)~i',
75                                         'class="\1\3button art-button\2\4"', $match[0]) . '</span>';
76                 }
77                 $result .= substr($content, $position);
78                 return $result;
79         }
80
81         function artxPost($caption, $content)
82         {
83                 $hasCaption = (null !== $caption && strlen(trim($caption)) > 0);
84                 $hasContent = (null !== $content && strlen(trim($content)) > 0);
85
86                 if (!$hasCaption && !$hasContent)
87                         return '';
88
89                 ob_start();
90 ?>
91 <div class="art-Post">
92                     <div class="art-Post-body">
93                 <div class="art-Post-inner">
94                 
95                 <?php if ($hasCaption): ?>
96 <div class="art-PostMetadataHeader">
97                 <h2 class="art-PostHeader"> 
98                 <?php echo $caption; ?>
99
100                 </h2>
101                 
102                 </div>
103                 
104                 <?php endif; ?>
105                 <?php if ($hasContent): ?>
106 <div class="art-PostContent">
107                 
108                 <?php echo artxReplaceButtons($content); ?>
109
110                 </div>
111                 <div class="cleared"></div>
112                 
113                 <?php endif; ?>
114
115                 </div>
116                 
117                                 <div class="cleared"></div>
118                     </div>
119                 </div>
120                 
121 <?php
122                 return ob_get_clean();
123         }
124
125         function artxBlock($caption, $content)
126         {
127                 $hasCaption = (null !== $caption && strlen(trim($caption)) > 0);
128                 $hasContent = (null !== $content && strlen(trim($content)) > 0);
129
130                 if (!$hasCaption && !$hasContent)
131                         return '';
132
133                 ob_start();
134 ?>
135 <div class="art-Block">
136                     <div class="art-Block-tl"></div>
137                     <div class="art-Block-tr"></div>
138                     <div class="art-Block-bl"></div>
139                     <div class="art-Block-br"></div>
140                     <div class="art-Block-tc"></div>
141                     <div class="art-Block-bc"></div>
142                     <div class="art-Block-cl"></div>
143                     <div class="art-Block-cr"></div>
144                     <div class="art-Block-cc"></div>
145                     <div class="art-Block-body">
146                 
147                 <?php if ($hasCaption): ?>
148 <div class="art-BlockHeader">
149                     <div class="l"></div>
150                     <div class="r"></div>
151                     <div class="art-header-tag-icon">
152                         <div class="t">
153                 <?php echo $caption; ?>
154 </div>
155                     </div>
156                 </div>
157                 <?php endif; ?>
158                 <?php if ($hasContent): ?>
159 <div class="art-BlockContent">
160                     <div class="art-BlockContent-tl"></div>
161                     <div class="art-BlockContent-tr"></div>
162                     <div class="art-BlockContent-bl"></div>
163                     <div class="art-BlockContent-br"></div>
164                     <div class="art-BlockContent-tc"></div>
165                     <div class="art-BlockContent-bc"></div>
166                     <div class="art-BlockContent-cl"></div>
167                     <div class="art-BlockContent-cr"></div>
168                     <div class="art-BlockContent-cc"></div>
169                     <div class="art-BlockContent-body">
170                 
171                 <?php echo artxReplaceButtons($content); ?>
172
173                                 <div class="cleared"></div>
174                     </div>
175                 </div>
176                 
177                 <?php endif; ?>
178
179                                 <div class="cleared"></div>
180                     </div>
181                 </div>
182                 
183 <?php
184                 return ob_get_clean();
185         }
186
187         function artxPageTitle($page, $criteria = null, $key = null)
188         {
189                 if ($criteria === null)
190                         $criteria = $page->params->def('show_page_title', 1);
191                 return $criteria
192                         ? ('<span class="componentheading' . $page->params->get('pageclass_sfx') . '">'
193                                 . $page->escape($page->params->get($key === null ? 'page_title' : $key)) . '</span>')
194                         : '';
195         }
196         
197         function artxCountModules(&$document, $position)
198         {
199                 if (null === $document)
200                         // for Joomla 1.0
201                         return mosCountModules($position);
202                 // for Joomla 1.5
203                 return $document->countModules($position);
204         }
205         
206         function artxPositions(&$document, $positions, $style)
207         {
208                 ob_start();
209                 if (count($positions) == 3) {
210                         if (artxCountModules($document, $positions[0])
211                                 && artxCountModules($document, $positions[1])
212                                 && artxCountModules($document, $positions[2]))
213                         {
214                                 ?>
215 <table class="position" cellpadding="0" cellspacing="0" border="0">
216 <tr valign="top">
217   <td width="33%"><?php echo artxModules($document, $positions[0], $style); ?></td>
218   <td width="33%"><?php echo artxModules($document, $positions[1], $style); ?></td>
219   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
220 </tr>
221 </table>
222 <?php
223                         } elseif (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[1])) {
224 ?>
225 <table class="position" cellpadding="0" cellspacing="0" border="0">
226 <tr valign="top">
227   <td width="33%"><?php echo artxModules($document, $positions[0], $style); ?></td>
228   <td><?php echo artxModules($document, $positions[1], $style); ?></td>
229 </tr>
230 </table>
231 <?php
232                         } elseif (artxCountModules($document, $positions[1]) && artxCountModules($document, $positions[2])) {
233 ?>
234 <table class="position" cellpadding="0" cellspacing="0" border="0">
235 <tr valign="top">
236   <td width="67%"><?php echo artxModules($document, $positions[1], $style); ?></td>
237   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
238 </tr>
239 </table>
240 <?php
241                         } elseif (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[2])) {
242 ?>
243 <table class="position" cellpadding="0" cellspacing="0" border="0">
244 <tr valign="top">
245   <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
246   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
247 </tr>
248 </table>
249 <?php
250                         } else {
251                                 echo artxModules($document, $positions[0], $style);
252                                 echo artxModules($document, $positions[1], $style);
253                                 echo artxModules($document, $positions[2], $style);
254                         }
255                 } elseif (count($positions) == 2) {
256                         if (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[1])) {
257 ?>
258 <table class="position" cellpadding="0" cellspacing="0" border="0">
259 <tr valign="top">
260 <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
261 <td><?php echo artxModules($document, $positions[1], $style); ?></td>
262 </tr>
263 </table>
264 <?php
265                         } else {
266                                 echo artxModules($document, $positions[0], $style);
267                                 echo artxModules($document, $positions[1], $style);
268                         }
269                 } // count($positions)
270                 return ob_get_clean();
271         }
272         
273         function artxGetContentCellStyle(&$document)
274         {
275                 $leftCnt = artxCountModules($document, 'left');
276                 $rightCnt = artxCountModules($document, 'right');
277                 if ($leftCnt > 0 && $rightCnt > 0)
278                         return 'content';
279                 if ($rightCnt > 0)
280                         return 'content-sidebar1';
281                 if ($leftCnt > 0)
282                         return 'content-sidebar2';
283                 return 'content-wide';
284         }
285         
286         function artxHtmlFixMoveScriptToHead($re, $content)
287         {
288                 if (preg_match($re, $content, $matches, PREG_OFFSET_CAPTURE)) {
289                         $content = substr($content, 0, $matches[0][1])
290                                 . substr($content, $matches[0][1] + strlen($matches[0][0]));
291                         $document =& JFactory::getDocument();
292                         $document->addScriptDeclaration($matches[1][0]); 
293                 }
294                 return $content;
295         }
296
297         function artxHtmlFixFormAction($content)
298         {
299                 if (preg_match('~ action="([^"]+)" ~', $content, $matches, PREG_OFFSET_CAPTURE)) {
300                         $content = substr($content, 0, $matches[0][1])
301                                 . ' action="' . artxUrlToHref($matches[1][0]) . '" '
302                                 . substr($content, $matches[0][1] + strlen($matches[0][0]));
303                 }
304                 return $content;
305         }
306
307         function artxHtmlFixRemove($re, $content)
308         {
309                 if (preg_match($re, $content, $matches, PREG_OFFSET_CAPTURE)) {
310                         $content = substr($content, 0, $matches[0][1])
311                                 . substr($content, $matches[0][1] + strlen($matches[0][0]));
312                 }
313                 return $content;
314         }
315
316         function artxComponentWrapper(&$document)
317         {
318                 if (null === $document) {
319                         // for Joomla 1.0
320                         return;
321                 }
322                 // for Joomla 1.5
323                 if ($document->getType() != 'html') return;
324                 $option = JRequest::getCmd('option');
325                 $view = JRequest::getCmd('view');
326                 $layout = JRequest::getCmd('layout');
327                 $content = $document->getBuffer('component');
328                 // fixes for w3.org validation
329                 if ('com_contact' == $option) {
330                         if ('category' == $view) {
331                                 $content = artxHtmlFixFormAction($content);
332                         } elseif ('contact' == $view) {
333                                 $content = artxHtmlFixMoveScriptToHead('~<script [^>]+>\s*(<!--[^>]*-->)\s*</script>~', $content);
334                         }
335                 } elseif ('com_content' == $option) {
336                         if ('category' == $view) {
337                                 if ('' == $layout) {
338                                         $content = artxHtmlFixMoveScriptToHead('~<script [^>]+>([^<]*)</script>~', $content);
339                                         $content = artxHtmlFixFormAction($content);
340                                 }
341                         } elseif ('archive' == $view) {
342                                 $content = artxHtmlFixRemove('~<ul id="archive-list" style="list-style: none;">\s*</ul>~', $content);
343                         }
344                 } elseif ('com_user' == $option) {
345                         if ('user' == $view) {
346                                 if ('form' == $layout) {
347                                         $content = artxHtmlFixRemove('~autocomplete="off"~', $content);
348                                 }
349                         }
350                 }
351                 if (false === strpos($content, '<div class="art-Post">')) {
352                         $title = null;
353                         if (preg_match('~<div\s+class="(componentheading[^"]*)"([^>]*)>([^<]+)</div>~', $content, $matches, PREG_OFFSET_CAPTURE)) {
354                                 $content = substr($content, 0, $matches[0][1]) . substr($content, $matches[0][1] + strlen($matches[0][0]));
355                                 $title = '<span class="' . $matches[1][0] . '"' . $matches[2][0] . '>' . $matches[3][0] . '</span>';
356                         }
357                         $document->setBuffer(artxPost($title, $content), 'component');
358                 }
359         }
360         
361         function artxComponent()
362         {
363                 // for Joomla 1.0
364                 ob_start();
365                 mosMainBody();
366                 $content = ob_get_clean();
367                 if (false === strpos($content, '<div class="art-Post">')) {
368                         $title = null;
369                         if (preg_match('~<div\s+class="(componentheading[^"]*)"([^>]*)>([^<]+)</div>~', $content, $matches, PREG_OFFSET_CAPTURE)) {
370                                 $content = substr($content, 0, $matches[0][1]) . substr($content, $matches[0][1] + strlen($matches[0][0]));
371                                 $title = '<span class="' . $matches[1][0] . '"' . $matches[2][0] . '>' . $matches[3][0] . '</span>';
372                         }
373                         return artxPost($title, $content);
374                 }
375                 return $content;
376         }
377         
378         function artxModules(&$document, $position, $style = null)
379         {
380                 if (null === $document) {
381                         // for Joomla 1.0
382                         ob_start();
383                         mosLoadModules($position, -2);
384                         $content = ob_get_clean();
385                         if (null == $style || 'xhtml' == $style)
386                                 return $content;
387                         $decorator = 'artblock' == $style ? 'artxBlock' : ('artpost' == $style ? 'artxPost' : null);
388                         $result = '';
389                         $modules = preg_split('~</div>\s*<div class="moduletable">~', $content);
390                         $lastModule = count($modules) - 1;
391                         if ($lastModule > -1) {
392                                 $modules[0] = preg_replace('~^\s*<div class="moduletable">~', '', $modules[0]);
393                                 $modules[$lastModule] = preg_replace('~</div>\s*$~', '', $modules[$lastModule]);
394                                 foreach ($modules as $module) {
395                                         if (preg_match('~^\s*<h3>([^<]*)</h3>~', $module, $matches, PREG_OFFSET_CAPTURE)) {
396                                                 $result .= $decorator($matches[1][0], substr($module, 0, $matches[0][1])
397                                                         . substr($module, $matches[0][1] + strlen($matches[0][0])));
398                                         } else {
399                                                 $result .= $decorator(null, $module);
400                                         }
401                                 }
402                         }
403                         return $result;
404                 }
405                 // for Joomla 1.5
406                 return '<jdoc:include type="modules" name="' . $position . '"' . (null != $style ? ' style="artstyle" artstyle="' . $style . '"' : '') . ' />';
407         }
408         
409         $artxFragments = array();
410
411         function artxFragmentBegin($head = '')
412         {
413                 global $artxFragments;
414                 $artxFragments[] = array('head' => $head, 'content' => '', 'tail' => '');
415         }
416
417         function artxFragmentContent($content = '')
418         {
419                 global $artxFragments;
420                 $artxFragments[count($artxFragments) - 1]['content'] = $content;
421         }
422
423         function artxFragmentEnd($tail = '', $separator = '')
424         {
425                 global $artxFragments;
426                 $fragment = array_pop($artxFragments);
427                 $fragment['tail'] = $tail;
428                 $content = trim($fragment['content']);
429                 if (count($artxFragments) == 0) {
430                         echo (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
431                 } else {
432                         $result = (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
433                         $fragment =& $artxFragments[count($artxFragments) - 1];
434                         $fragment['content'] .= (trim($fragment['content']) == '' ? '' : $separator) . $result;
435                 }
436         }
437
438         function artxFragment($head = '', $content = '', $tail = '', $separator = '')
439         {
440                 global $artxFragments;
441                 if ($head != '' && $content == '' && $tail == '' && $separator == '') {
442                         $content = $head;
443                         $head = '';
444                 } elseif ($head != '' && $content != '' && $tail == '' && $separator == '') {
445                         $separator = $content;
446                         $content = $head;
447                         $head = '';
448                 }
449                 artxFragmentBegin($head);
450                 artxFragmentContent($content);
451                 artxFragmentEnd($tail, $separator);
452         }
453
454 }