2 defined('_JEXEC') or die('Restricted access'); // no direct access
4 if (!defined('_ARTX_FUNCTIONS')) {
6 define('_ARTX_FUNCTIONS', 1);
8 function artxHasMessages()
11 $messages = $mainframe->getMessageQueue();
12 if (is_array($messages) && count($messages))
13 foreach ($messages as $msg)
14 if (isset($msg['type']) && isset($msg['message']))
19 function artxUrlToHref($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'];
31 $result .= $p['host'];
32 if (isset($p['port']))
33 $result .= ':' . $p['port'];
34 if (!isset($p['path']))
37 if (isset($p['path']))
38 $result .= $p['path'];
39 if (isset($p['query'])) {
40 $result .= '?' . str_replace('&', '&', $p['query']);
42 if (isset($p['fragment']))
43 $result .= '#' . $p['fragment'];
47 function artxReplaceButtonsRegex() {
51 . '[^>]*\bclass=(?:"(?:[^"]*\s)?button(?:\s[^"]*)?"|\'(?:[^\']*\s)?button(?:\s[^\']*)?\'|button\b)[^>]*'
52 . '(?:\bvalue=(?:"[^"]*"|\'[^\']*\'|[^>\s]*))'
54 . '(?:\bvalue=(?:"[^"]*"|\'[^\']*\'|[^>\s]*))'
55 . '[^>]*\bclass=(?:"(?:[^"]*\s)?button(?:\s[^"]*)?"|\'(?:[^\']*\s)?button(?:\s[^\']*)?\'|button\b)[^>]*'
57 . '[^>]*\bclass=(?:"(?:[^"]*\s)?button(?:\s[^"]*)?"|\'(?:[^\']*\s)?button(?:\s[^\']*)?\'|button\b)[^>]*'
62 function artxReplaceButtons($content)
64 $re = artxReplaceButtonsRegex();
65 if (!preg_match_all($re, $content, $matches, PREG_OFFSET_CAPTURE))
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>';
77 $result .= substr($content, $position);
81 function artxPost($caption, $content)
83 $hasCaption = (null !== $caption && strlen(trim($caption)) > 0);
84 $hasContent = (null !== $content && strlen(trim($content)) > 0);
86 if (!$hasCaption && !$hasContent)
91 <div class="art-Post">
92 <div class="art-Post-body">
93 <div class="art-Post-inner">
95 <?php if ($hasCaption): ?>
96 <div class="art-PostMetadataHeader">
97 <h2 class="art-PostHeader">
98 <?php echo $caption; ?>
105 <?php if ($hasContent): ?>
106 <div class="art-PostContent">
108 <?php echo artxReplaceButtons($content); ?>
111 <div class="cleared"></div>
117 <div class="cleared"></div>
122 return ob_get_clean();
125 function artxBlock($caption, $content)
127 $hasCaption = (null !== $caption && strlen(trim($caption)) > 0);
128 $hasContent = (null !== $content && strlen(trim($content)) > 0);
130 if (!$hasCaption && !$hasContent)
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">
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">
153 <?php echo $caption; ?>
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">
171 <?php echo artxReplaceButtons($content); ?>
173 <div class="cleared"></div>
179 <div class="cleared"></div>
184 return ob_get_clean();
187 function artxPageTitle($page, $criteria = null, $key = null)
189 if ($criteria === null)
190 $criteria = $page->params->def('show_page_title', 1);
192 ? ('<span class="componentheading' . $page->params->get('pageclass_sfx') . '">'
193 . $page->escape($page->params->get($key === null ? 'page_title' : $key)) . '</span>')
197 function artxCountModules(&$document, $position)
199 if (null === $document)
201 return mosCountModules($position);
203 return $document->countModules($position);
206 function artxPositions(&$document, $positions, $style)
209 if (count($positions) == 3) {
210 if (artxCountModules($document, $positions[0])
211 && artxCountModules($document, $positions[1])
212 && artxCountModules($document, $positions[2]))
215 <table class="position" cellpadding="0" cellspacing="0" border="0">
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>
223 } elseif (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[1])) {
225 <table class="position" cellpadding="0" cellspacing="0" border="0">
227 <td width="33%"><?php echo artxModules($document, $positions[0], $style); ?></td>
228 <td><?php echo artxModules($document, $positions[1], $style); ?></td>
232 } elseif (artxCountModules($document, $positions[1]) && artxCountModules($document, $positions[2])) {
234 <table class="position" cellpadding="0" cellspacing="0" border="0">
236 <td width="67%"><?php echo artxModules($document, $positions[1], $style); ?></td>
237 <td><?php echo artxModules($document, $positions[2], $style); ?></td>
241 } elseif (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[2])) {
243 <table class="position" cellpadding="0" cellspacing="0" border="0">
245 <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
246 <td><?php echo artxModules($document, $positions[2], $style); ?></td>
251 echo artxModules($document, $positions[0], $style);
252 echo artxModules($document, $positions[1], $style);
253 echo artxModules($document, $positions[2], $style);
255 } elseif (count($positions) == 2) {
256 if (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[1])) {
258 <table class="position" cellpadding="0" cellspacing="0" border="0">
260 <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
261 <td><?php echo artxModules($document, $positions[1], $style); ?></td>
266 echo artxModules($document, $positions[0], $style);
267 echo artxModules($document, $positions[1], $style);
269 } // count($positions)
270 return ob_get_clean();
273 function artxGetContentCellStyle(&$document)
275 $leftCnt = artxCountModules($document, 'left');
276 $rightCnt = artxCountModules($document, 'right');
277 if ($leftCnt > 0 && $rightCnt > 0)
280 return 'content-sidebar1';
282 return 'content-sidebar2';
283 return 'content-wide';
286 function artxHtmlFixMoveScriptToHead($re, $content)
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]);
297 function artxHtmlFixFormAction($content)
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]));
307 function artxHtmlFixRemove($re, $content)
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]));
316 function artxComponentWrapper(&$document)
318 if (null === $document) {
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);
335 } elseif ('com_content' == $option) {
336 if ('category' == $view) {
338 $content = artxHtmlFixMoveScriptToHead('~<script [^>]+>([^<]*)</script>~', $content);
339 $content = artxHtmlFixFormAction($content);
341 } elseif ('archive' == $view) {
342 $content = artxHtmlFixRemove('~<ul id="archive-list" style="list-style: none;">\s*</ul>~', $content);
344 } elseif ('com_user' == $option) {
345 if ('user' == $view) {
346 if ('form' == $layout) {
347 $content = artxHtmlFixRemove('~autocomplete="off"~', $content);
351 if (false === strpos($content, '<div class="art-Post">')) {
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>';
357 $document->setBuffer(artxPost($title, $content), 'component');
361 function artxComponent()
366 $content = ob_get_clean();
367 if (false === strpos($content, '<div class="art-Post">')) {
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>';
373 return artxPost($title, $content);
378 function artxModules(&$document, $position, $style = null)
380 if (null === $document) {
383 mosLoadModules($position, -2);
384 $content = ob_get_clean();
385 if (null == $style || 'xhtml' == $style)
387 $decorator = 'artblock' == $style ? 'artxBlock' : ('artpost' == $style ? 'artxPost' : null);
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])));
399 $result .= $decorator(null, $module);
406 return '<jdoc:include type="modules" name="' . $position . '"' . (null != $style ? ' style="artstyle" artstyle="' . $style . '"' : '') . ' />';
409 $artxFragments = array();
411 function artxFragmentBegin($head = '')
413 global $artxFragments;
414 $artxFragments[] = array('head' => $head, 'content' => '', 'tail' => '');
417 function artxFragmentContent($content = '')
419 global $artxFragments;
420 $artxFragments[count($artxFragments) - 1]['content'] = $content;
423 function artxFragmentEnd($tail = '', $separator = '')
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']);
432 $result = (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
433 $fragment =& $artxFragments[count($artxFragments) - 1];
434 $fragment['content'] .= (trim($fragment['content']) == '' ? '' : $separator) . $result;
438 function artxFragment($head = '', $content = '', $tail = '', $separator = '')
440 global $artxFragments;
441 if ($head != '' && $content == '' && $tail == '' && $separator == '') {
444 } elseif ($head != '' && $content != '' && $tail == '' && $separator == '') {
445 $separator = $content;
449 artxFragmentBegin($head);
450 artxFragmentContent($content);
451 artxFragmentEnd($tail, $separator);