OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / templates / FishNew / 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 artxPost($caption, $content)
48         {
49                 $hasCaption = (null !== $caption && strlen(trim($caption)) > 0);
50                 $hasContent = (null !== $content && strlen(trim($content)) > 0);
51
52                 if (!$hasCaption && !$hasContent)
53                         return '';
54
55                 ob_start();
56 ?>
57 <div class="Post">
58                     <div class="Post-body">
59                 <div class="Post-inner">
60                 
61                 <?php if ($hasCaption): ?>
62 <h2 class="PostHeaderIcon-wrapper"> <span class="PostHeader">
63                 <?php echo $caption; ?>
64 </span>
65                 </h2>
66                 
67                 <?php endif; ?>
68                 <?php if ($hasContent): ?>
69 <div class="PostContent">
70                 
71                 <?php echo $content; ?>
72
73                 </div>
74                 <div class="cleared"></div>
75                 
76                 <?php endif; ?>
77
78                 </div>
79                 
80                     </div>
81                 </div>
82                 
83 <?php
84                 return ob_get_clean();
85         }
86
87         function artxBlock($caption, $content)
88         {
89                 $hasCaption = (null !== $caption && strlen(trim($caption)) > 0);
90                 $hasContent = (null !== $content && strlen(trim($content)) > 0);
91
92                 if (!$hasCaption && !$hasContent)
93                         return '';
94
95                 ob_start();
96 ?>
97 <div class="Block">
98                     <div class="Block-tl"></div>
99                     <div class="Block-tr"></div>
100                     <div class="Block-bl"></div>
101                     <div class="Block-br"></div>
102                     <div class="Block-tc"></div>
103                     <div class="Block-bc"></div>
104                     <div class="Block-cl"></div>
105                     <div class="Block-cr"></div>
106                     <div class="Block-cc"></div>
107                     <div class="Block-body">
108                 
109                 <?php if ($hasCaption): ?>
110 <div class="BlockHeader">
111                     <div class="l"></div>
112                     <div class="r"></div>
113                     <div class="header-tag-icon">
114                         <div class="t">
115                 <?php echo $caption; ?>
116 </div>
117                     </div>
118                 </div>
119                 <?php endif; ?>
120                 <?php if ($hasContent): ?>
121 <div class="BlockContent">
122                     <div class="BlockContent-body">
123                 
124                 <?php echo $content; ?>
125
126                     </div>
127                 </div>
128                 
129                 <?php endif; ?>
130
131                     </div>
132                 </div>
133                 
134 <?php
135                 return ob_get_clean();
136         }
137
138         function artxPageTitle($page, $criteria = null, $key = null)
139         {
140                 if ($criteria === null)
141                         $criteria = $page->params->def('show_page_title', 1);
142                 return $criteria
143                         ? ('<span class="componentheading' . $page->params->get('pageclass_sfx') . '">'
144                                 . $page->escape($page->params->get($key === null ? 'page_title' : $key)) . '</span>')
145                         : '';
146         }
147         
148         function artxCountModules($document, $position)
149         {
150                 if (null == $document)
151                         // for Joomla 1.0
152                         return mosCountModules($position);
153                 // for Joomla 1.5
154                 return $document->countModules($position);
155         }
156         
157         function artxPositions($document, $positions, $style)
158         {
159                 ob_start();
160                 if (count($positions) == 3) {
161                         if (artxCountModules($document, $positions[0])
162                                 && artxCountModules($document, $positions[1])
163                                 && artxCountModules($document, $positions[2]))
164                         {
165                                 ?>
166 <table class="position" cellpadding="0" cellspacing="0" border="0">
167 <tr valign="top">
168   <td width="33%"><?php echo artxModules($document, $positions[0], $style); ?></td>
169   <td width="33%"><?php echo artxModules($document, $positions[1], $style); ?></td>
170   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
171 </tr>
172 </table>
173 <?php
174                         } elseif (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[1])) {
175 ?>
176 <table class="position" cellpadding="0" cellspacing="0" border="0">
177 <tr valign="top">
178   <td width="33%"><?php echo artxModules($document, $positions[0], $style); ?></td>
179   <td><?php echo artxModules($document, $positions[1], $style); ?></td>
180 </tr>
181 </table>
182 <?php
183                         } elseif (artxCountModules($document, $positions[1]) && artxCountModules($document, $positions[2])) {
184 ?>
185 <table class="position" cellpadding="0" cellspacing="0" border="0">
186 <tr valign="top">
187   <td width="67%"><?php echo artxModules($document, $positions[1], $style); ?></td>
188   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
189 </tr>
190 </table>
191 <?php
192                         } elseif (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[2])) {
193 ?>
194 <table class="position" cellpadding="0" cellspacing="0" border="0">
195 <tr valign="top">
196   <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
197   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
198 </tr>
199 </table>
200 <?php
201                         } else {
202                                 echo artxModules($document, $positions[0], $style);
203                                 echo artxModules($document, $positions[1], $style);
204                                 echo artxModules($document, $positions[2], $style);
205                         }
206                 } elseif (count($positions) == 2) {
207                         if (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[1])) {
208 ?>
209 <table class="position" cellpadding="0" cellspacing="0" border="0">
210 <tr valign="top">
211 <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
212 <td><?php echo artxModules($document, $positions[1], $style); ?></td>
213 </tr>
214 </table>
215 <?php
216                         } else {
217                                 echo artxModules($document, $positions[0], $style);
218                                 echo artxModules($document, $positions[1], $style);
219                         }
220                 } // count($positions)
221                 return ob_get_clean();
222         }
223         
224         function artxGetContentCellStyle($document)
225         {
226                 $leftCnt = artxCountModules($document, 'left');
227                 $rightCnt = artxCountModules($document, 'right');
228                 if ($leftCnt > 0 && $rightCnt > 0)
229                         return 'content';
230                 if ($rightCnt > 0)
231                         return 'content-sidebar1';
232                 if ($leftCnt > 0)
233                         return 'content-sidebar2';
234                 return 'content-wide';
235         }
236         
237         function artxHtmlFixMoveScriptToHead($re, $content)
238         {
239                 if (preg_match($re, $content, $matches, PREG_OFFSET_CAPTURE)) {
240                         $content = substr($content, 0, $matches[0][1])
241                                 . substr($content, $matches[0][1] + strlen($matches[0][0]));
242                         $document =& JFactory::getDocument();
243                         $document->addScriptDeclaration($matches[1][0]); 
244                 }
245                 return $content;
246         }
247
248         function artxHtmlFixFormAction($content)
249         {
250                 if (preg_match('~ action="([^"]+)" ~', $content, $matches, PREG_OFFSET_CAPTURE)) {
251                         $content = substr($content, 0, $matches[0][1])
252                                 . ' action="' . artxUrlToHref($matches[1][0]) . '" '
253                                 . substr($content, $matches[0][1] + strlen($matches[0][0]));
254                 }
255                 return $content;
256         }
257
258         function artxHtmlFixRemove($re, $content)
259         {
260                 if (preg_match($re, $content, $matches, PREG_OFFSET_CAPTURE)) {
261                         $content = substr($content, 0, $matches[0][1])
262                                 . substr($content, $matches[0][1] + strlen($matches[0][0]));
263                 }
264                 return $content;
265         }
266
267         function artxComponentWrapper($document)
268         {
269                 if (null == $document) {
270                         // for Joomla 1.0
271                         return;
272                 }
273                 // for Joomla 1.5
274                 if ($document->getType() != 'html') return;
275                 $option = JRequest::getCmd('option');
276                 $view = JRequest::getCmd('view');
277                 $layout = JRequest::getCmd('layout');
278                 $content = $document->getBuffer('component');
279                 // fixes for w3.org validation
280                 if ('com_contact' == $option) {
281                         if ('category' == $view) {
282                                 $content = artxHtmlFixFormAction($content);
283                         } elseif ('contact' == $view) {
284                                 $content = artxHtmlFixMoveScriptToHead('~<script [^>]+>\s*(<!--[^>]*-->)\s*</script>~', $content);
285                         }
286                 } elseif ('com_content' == $option) {
287                         if ('category' == $view) {
288                                 if ('' == $layout) {
289                                         $content = artxHtmlFixMoveScriptToHead('~<script [^>]+>([^<]*)</script>~', $content);
290                                         $content = artxHtmlFixFormAction($content);
291                                 }
292                         } elseif ('archive' == $view) {
293                                 $content = artxHtmlFixRemove('~<ul id="archive-list" style="list-style: none;">\s*</ul>~', $content);
294                         }
295                 } elseif ('com_user' == $option) {
296                         if ('user' == $view) {
297                                 if ('form' == $layout) {
298                                         $content = artxHtmlFixRemove('~autocomplete="off"~', $content);
299                                 }
300                         }
301                 }
302                 if (false === strpos($content, '<div class="Post">')) {
303                         $title = null;
304                         if (preg_match('~<div\s+class="(componentheading[^"]*)"([^>]*)>([^<]+)</div>~', $content, $matches, PREG_OFFSET_CAPTURE)) {
305                                 $content = substr($content, 0, $matches[0][1]) . substr($content, $matches[0][1] + strlen($matches[0][0]));
306                                 $title = '<span class="' . $matches[1][0] . '"' . $matches[2][0] . '>' . $matches[3][0] . '</span>';
307                         }
308                         $document->setBuffer(artxPost($title, $content), 'component');
309                 }
310         }
311         
312         function artxComponent()
313         {
314                 // for Joomla 1.0
315                 ob_start();
316                 mosMainBody();
317                 $content = ob_get_clean();
318                 if (false === strpos($content, '<div class="Post">')) {
319                         $title = null;
320                         if (preg_match('~<div\s+class="(componentheading[^"]*)"([^>]*)>([^<]+)</div>~', $content, $matches, PREG_OFFSET_CAPTURE)) {
321                                 $content = substr($content, 0, $matches[0][1]) . substr($content, $matches[0][1] + strlen($matches[0][0]));
322                                 $title = '<span class="' . $matches[1][0] . '"' . $matches[2][0] . '>' . $matches[3][0] . '</span>';
323                         }
324                         return artxPost($title, $content);
325                 }
326                 return $content;
327         }
328         
329         function artxModules($document, $position, $style = null)
330         {
331                 if ($document == null) {
332                         // for Joomla 1.0
333                         ob_start();
334                         mosLoadModules($position, -2);
335                         $content = ob_get_clean();
336                         if (null == $style || 'xhtml' == $style)
337                                 return $content;
338                         $decorator = 'artblock' == $style ? 'artxBlock' : ('artpost' == $style ? 'artxPost' : null);
339                         $result = '';
340                         $modules = preg_split('~</div>\s*<div class="moduletable">~', $content);
341                         $lastModule = count($modules) - 1;
342                         if ($lastModule > -1) {
343                                 $modules[0] = preg_replace('~^\s*<div class="moduletable">~', '', $modules[0]);
344                                 $modules[$lastModule] = preg_replace('~</div>\s*$~', '', $modules[$lastModule]);
345                                 foreach ($modules as $module) {
346                                         if (preg_match('~^\s*<h3>([^<]*)</h3>~', $module, $matches, PREG_OFFSET_CAPTURE)) {
347                                                 $result .= $decorator($matches[1][0], substr($module, 0, $matches[0][1])
348                                                         . substr($module, $matches[0][1] + strlen($matches[0][0])));
349                                         } else {
350                                                 $result .= $decorator(null, $module);
351                                         }
352                                 }
353                         }
354                         return $result;
355                 }
356                 // for Joomla 1.5
357                 return '<jdoc:include type="modules" name="' . $position . '"' . (null != $style ? ' style="' . $style . '"' : '') . ' />';
358         }
359 }