OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / templates / art30_041_sample2 / functions.php
1 <?php
2 defined('_JEXEC') or die;
3
4 if (!defined('_ARTX_FUNCTIONS')) {
5
6     define('_ARTX_FUNCTIONS', 1);
7
8     $GLOBALS['artx_settings'] = array(
9         'block' => array('has_header' => true),
10         'menu' => array('show_submenus' => true),
11         'vmenu' => array('show_submenus' => false, 'simple' => false)
12     );
13
14     /**
15      * Base class with index.php view routines. Contains method for placing positions,
16      * calculating classes, decorating components. Version-specific routines are defined
17      * in subclasses: ArtxPage15 and ArtxPage16.
18      *
19      * @abstract
20      */
21     class ArtxPageView
22     {
23
24         /**
25          * @access public
26          */
27         var $page;
28
29         /**
30          * @access protected
31          */
32         function ArtxPageView(&$page) {
33             $this->page = & $page;
34         }
35
36         /**
37          * Returns version-specific body class: art-j15 for joomla15 or art-j16 for joomla16.
38          *
39          * Example:
40          *  <body class="art-j15">
41          *
42          * @access public
43          * @abstract
44          */
45         function bodyClass() { }
46
47         /**
48          * Checks whether Joomla! has system messages to display.
49          *
50          * @access public
51          * @abstract
52          */
53         function hasMessages() { }
54
55         /**
56          * Returns true when one of the given positions contains at least one module.
57          * Example:
58          *  if ($obj->containsModules('top1', 'top2', 'top3')) {
59          *   // the following code will be executed when one of the positions contains modules:
60          *   ...
61          *  }
62          *
63          * @access public
64          */
65         function containsModules()
66         {
67             foreach (func_get_args() as $position)
68                 if (0 != $this->page->countModules($position))
69                     return true;
70             return false;
71         }
72
73         /**
74          * Builds list of positions, collapsing the empty ones.
75          *
76          * Samples:
77          *  Four positions:
78          *   No empty positions: 25%:25%:25%:25%
79          *   With one empty position: -:50%:25%:25%, 50%:-:25%:25%, 25%:50%:-:25%, 25%:25%:50%:-
80          *   With two empty positions: -:-:75%:25%, -:50%:-:50%, -:50%:50%:-, -:50%:50%:-, 75%:-:-:25%, 50%:-:50%:-, 25%:75%:-:-
81          *   One non-empty position: 100%
82          *  Three positions:
83          *   No empty positions: 33%:33%:34%
84          *   With one empty position: -:66%:34%, 50%:-:50%, 33%:67%:-
85          *   One non-empty position: 100%
86          *
87          * @access public
88          */
89         function positions($positions, $style) {
90             // Build $cells by collapsing empty positions:
91             $cells = array();
92             $buffer = 0;
93             $cell = null;
94             foreach ($positions as $name => $width) {
95                 if ($this->containsModules($name)) {
96                     $cells[$name] = $buffer + $width;
97                     $buffer = 0;
98                     $cell = $name;
99                 } else if (null == $cell)
100                     $buffer += $width;
101                 else
102                     $cells[$cell] += $width;
103             }
104
105             // Backward compatibility:
106             //  For three equal width columns with empty center position width should be 50/50:
107             if (3 == count($positions) && 2 == count($cells)) {
108                 $columns1 = array_keys($positions);
109                 $columns2 = array_keys($cells);
110                 if (33 == $positions[$columns1[0]] && 33 == $positions[$columns1[1]] && 34 == $positions[$columns1[2]]
111                     && $columns2[0] == $columns1[0] && $columns2[1] == $columns1[2])
112                     $cells[$columns2[0]] = 50;
113                     $cells[$columns2[1]] = 50;
114             }
115
116             // Render $cells:
117             if (count($cells) == 0)
118                 return '';
119             if (count($cells) == 1)
120                 foreach ($cells as $name => $width)
121                     return $this->position($name, $style);
122             $result = '<table class="position" cellpadding="0" cellspacing="0" border="0">';
123             $result .= '<tr valign="top">';
124             foreach ($cells as $name => $width)
125                 $result .='<td width="' . $width. '%">' . $this->position($name, $style) . '</td>';
126             $result .= '</tr>';
127             $result .= '</table>';
128             return $result;
129         }
130
131         /**
132          * @access public
133          */
134         function position($position, $style = null)
135         {
136             return '<jdoc:include type="modules" name="' . $position . '"' . (null != $style ? ' style="artstyle" artstyle="' . $style . '"' : '') . ' />';
137         }
138
139         /**
140          * Preprocess component content before printing it.
141          * 
142          * @access public
143          * @abstract
144          */
145         function componentWrapper()
146         {
147         }
148
149         /**
150          * @access public
151          */
152         function getWysiwygBackgroundImprovement($id)
153         {
154             ob_start();
155             ?>
156
157 (function () {
158     var waitFor = function (interval, criteria, callback) {
159         var interval = setInterval(function () {
160             if (!criteria())
161                 return;
162             clearInterval(interval);
163             callback();
164         }, interval);
165     };
166     waitFor(20, function () { return 'undefined' != typeof jQuery; },
167         function () {
168             var editor = ('undefined' != typeof tinyMCE)
169                 ? tinyMCE
170                 : (('undefined' != typeof JContentEditor)
171                     ? JContentEditor : null);
172             if (null == editor)
173                 return;
174             waitFor(20,
175                 function () {
176                     if (editor.editors)
177                         for (var key in editor.editors)
178                             if (editor.editors.hasOwnProperty(key))
179                                 return editor.editors[key].initialized;
180                     return false;
181                 },
182                 function () {
183                     var ifr = jQuery('#<?php echo $id; ?>');
184                     var ifrdoc = ifr.attr('contentDocument');
185                     setTimeout(function () {
186                         // check whether editor.css is included or not:
187                         if (0 == jQuery('link[href*="/css/editor.css"]', ifrdoc).length)
188                             return;
189                         var background = ifr.css('background-color');
190                         ifr.css('background', 'transparent');
191                         ifr.attr('allowtransparency', 'true');
192                         var layout = jQuery('table.mceLayout');
193                         var background = layout.css('background-color');
194                         layout.css('background', 'transparent');
195                         layout.find('.mceToolbar').css('background', background);
196                         layout.find('.mceStatusbar').css('background', background);
197                         jQuery('body', ifrdoc).css('background', 'transparent');
198                     }, 1);
199                 });
200         });
201 })();
202
203 <?php
204             return ob_get_clean();
205         }
206     }
207
208     class ArtxPage15 extends ArtxPageView
209     {
210         /**
211          * @access public
212          */
213         function ArtxPage15(&$page) {
214             parent::ArtxPageView($page);
215         }
216
217         /**
218          * @access public
219          */
220         function bodyClass() {
221             return 'art-j15';
222         }
223
224         /**
225          * @access public
226          */
227         function hasMessages()
228         {
229             global $mainframe;
230             $messages = $mainframe->getMessageQueue();
231             if (is_array($messages) && count($messages))
232                 foreach ($messages as $msg)
233                     if (isset($msg['type']) && isset($msg['message']))
234                         return true;
235             return false;
236         }
237
238         /**
239          * Wraps component content into article style unless it is not wrapped already.
240          *
241          * The componentWrapper method gets the content of the 'component' buffer and searches for the '<div class="art-post">' string in it.
242          * Then it replaces the componentheading DIV tag with span (to fix the w3.org validation) and replaces content of the buffer with
243          * wrapped content.
244          *
245          * @access public
246          */
247         function componentWrapper()
248         {
249             if ($this->page->getType() != 'html')
250                 return;
251             $option = JRequest::getCmd('option');
252             $view = JRequest::getCmd('view');
253             $layout = JRequest::getCmd('layout');
254             $task = JRequest::getCmd('task');
255             $content = $this->page->getBuffer('component');
256             // Workarounds for Joomla bugs and inconsistencies:
257             switch ($option) {
258                 case "com_user":
259                     switch ($view) {
260                         case "remind":
261                             if ("" == $layout)
262                                 $content = str_replace('<button type="submit" class="validate">', '<button type="submit" class="button validate">', $content);
263                             break;
264                         case "reset":
265                             if ("" == $layout)
266                                 $content = str_replace('<button type="submit" class="validate">', '<button type="submit" class="button validate">', $content);
267                             break;
268                     }
269                     break;
270             }
271             // Code injections:
272             switch ($option) {
273                 case "com_content":
274                     switch ($view) {
275                         case "article":
276                             if ("edit" == $task)
277                                 $this->page->addScriptDeclaration($this->getWysiwygBackgroundImprovement('text_ifr'));
278                             break;
279                     }
280                     break;
281             }
282             if ('com_content' == $option && ('frontpage' == $view || 'article' == $view || ('category' == $view && 'blog' == $layout)))
283                 return;
284             if (false === strpos($content, '<div class="art-post')) {
285                 $title = null;
286                 if (preg_match('~<div\s+class="(componentheading[^"]*)"([^>]*)>([^<]+)</div>~', $content, $matches, PREG_OFFSET_CAPTURE)) {
287                     $content = substr($content, 0, $matches[0][1]) . substr($content, $matches[0][1] + strlen($matches[0][0]));
288                     $title = '<span class="' . $matches[1][0] . '"' . $matches[2][0] . '>' . $matches[3][0] . '</span>';
289                 }
290                 $this->page->setBuffer(artxPost(array('header-text' => $title, 'content' => $content)), 'component');
291             }
292         }
293     }
294
295     class ArtxPage16 extends ArtxPageView
296     {
297         /**
298          * @access public
299          */
300         function ArtxPage16($page) {
301             parent::ArtxPageView($page);
302         }
303
304         /**
305          * @access public
306          */
307         function bodyClass() {
308             return 'art-j16';
309         }
310
311         /**
312          * @access public
313          */
314         function hasMessages()
315         {
316             $app = JFactory::getApplication();
317             $messages = $app->getMessageQueue();
318             if (is_array($messages) && count($messages))
319                 foreach ($messages as $msg)
320                     if (isset($msg['type']) && isset($msg['message']))
321                         return true;
322             return false;
323         }
324
325         /**
326          * Wraps component content into article style unless it is not wrapped already.
327          *
328          * The componentWrapper method gets the content of the 'component' buffer and searches for the '<div class="art-post">' string in it.
329          * Then it wraps content of the buffer with art-post.
330          *
331          * @access public
332          */
333         function componentWrapper()
334         {
335             if ($this->page->getType() != 'html')
336                 return;
337             $option = JRequest::getCmd('option');
338             $view = JRequest::getCmd('view');
339             $layout = JRequest::getCmd('layout');
340             $content = $this->page->getBuffer('component');
341             // Workarounds for Joomla bugs and inconsistencies:
342             switch ($option) {
343                 case "com_content":
344                     switch ($view) {
345                         case "form":
346                             if ("edit" == $layout)
347                                 $content = str_replace('<button type="button" onclick="', '<button type="button" class="button" onclick="', $content);
348                             break;
349                     }
350                     break;
351                 case "com_users":
352                     switch ($view) {
353                         case "remind":
354                             if ("" == $layout)
355                                 $content = str_replace('<button type="submit">', '<button type="submit" class="button">', $content);
356                             break;
357                         case "reset":
358                             if ("" == $layout)
359                                 $content = str_replace('<button type="submit">', '<button type="submit" class="button">', $content);
360                             break;
361                         case "registration":
362                             if ("" == $layout)
363                                 $content = str_replace('<button type="submit" class="validate">', '<button type="submit" class="button validate">', $content);
364                             break;
365                     }
366                     break;
367             }
368             // Code injections:
369             switch ($option) {
370                 case "com_content":
371                     switch ($view) {
372                         case "form":
373                             if ("edit" == $layout)
374                                 $this->page->addScriptDeclaration($this->getWysiwygBackgroundImprovement('jform_articletext_ifr'));
375                             break;
376                     }
377                     break;
378             }
379             if ('com_content' == $option && ('featured' == $view || 'article' == $view || ('category' == $view && 'blog' == $layout)))
380                 return;
381             if (false === strpos($content, '<div class="art-post'))
382                 $this->page->setBuffer(artxPost(array('header-text' => null, 'content' => $content)), 'component');
383         }
384     }
385
386     /**
387      * Base class with content page routines for rendering page header and article factory.
388      *
389      * @abstract
390      */
391     class ArtxContentView
392     {
393         /**
394          * @access protected
395          */
396         var $_component;
397
398         /**
399          * @access protected
400          */
401         var $_componentParams;
402
403         /**
404          * Component page class suffix.
405          * @var string
406          * @access public
407          */
408         var $pageClassSfx;
409
410         /**
411          * @var boolean
412          * @access public
413          */
414         var $showPageHeading;
415
416         /**
417          * Page heading (or page title).
418          * @var string
419          * @access public
420          */
421         var $pageHeading;
422
423         /**
424          * @access protected
425          */
426         function ArtxContentView(&$component, &$params)
427         {
428             $this->_component = $component;
429             $this->_componentParams = $params;
430         }
431
432         /**
433          * @access public
434          * @abstract
435          */
436         function pageHeading($heading = null) { }
437
438         /**
439          * @access public
440          * @abstract
441          */
442         function article($article, $print) { }
443
444         /**
445          * @access public
446          * @abstract
447          */
448         function articleListItem($item) { }
449
450         /**
451          * @access public
452          */
453         function beginPageContainer($class)
454         {
455             return '<div class="' . $class . $this->pageClassSfx .'">';
456         }
457
458         /**
459          * @access public
460          */
461         function endPageContainer()
462         {
463             return '</div>';
464         }
465     }
466
467     class ArtxContent15 extends ArtxContentView
468     {
469
470         /**
471          * @access public
472          */
473         function ArtxContent15(&$component, &$params)
474         {
475             parent::ArtxContentView($component, $params);
476             $this->pageClassSfx = $this->_componentParams->get('pageclass_sfx');
477             $this->showPageHeading = $this->_componentParams->def('show_page_title', 1);
478             $this->pageHeading = $this->showPageHeading ? $this->_componentParams->get('page_title') : '';
479         }
480
481         /**
482          * @access public
483          */
484         function pageHeading($heading = null)
485         {
486             return artxPost(array('header-text' => null == $heading ? $this->pageHeading : $heading));
487         }
488
489         /**
490          * @access public
491          */
492         function article($article, $print)
493         {
494             return new ArtxContentArticleView15($this->_component, $this->_componentParams, $article, $print);
495         }
496
497         /**
498          * @access public
499          */
500         function articleListItem($item)
501         {
502             return new ArtxContentFrontpageItemView15($this->_component, $this->_componentParams, $item);
503         }
504     }
505
506     class ArtxContent16 extends ArtxContentView
507     {
508         /**
509          * @access public
510          */
511         function ArtxContent16($component, $params)
512         {
513             parent::ArtxContentView($component, $params);
514             $this->pageClassSfx = $this->_component->pageclass_sfx;
515             $this->showPageHeading = $this->_componentParams->def('show_page_heading', 1);
516             $this->pageHeading = $this->showPageHeading ? $this->_componentParams->get('page_heading') : '';
517         }
518
519         /**
520          * @access public
521          */
522         function pageHeading($heading = null)
523         {
524             return artxPost(array('header-text' => null == $heading ? $this->pageHeading : $heading));
525         }
526
527         /**
528          * @access public
529          */
530         function article($article, $print)
531         {
532             return new ArtxContentArticleView16($this->_component, $this->_componentParams, $article, $print);
533         }
534
535         /**
536          * @access public
537          */
538         function articleListItem($item)
539         {
540             return new ArtxContentFeaturedItemView16($this->_component, $this->_componentParams, $item);
541         }
542     }
543
544     /**
545      * @abstract
546      */
547     class ArtxContentGeneralArticleView
548     {
549         /**
550          * @access protected
551          */
552         var $_component;
553
554         /**
555          * @access protected
556          */
557         var $_componentParams;
558
559         /**
560          * @access protected
561          */
562         var $_article;
563
564         /**
565          * @access public
566          */
567         var $params;
568
569         /**
570          * @access public
571          */
572         var $isPublished;
573
574         /**
575          * @access public
576          */
577         var $canEdit;
578
579         /**
580          * @access public
581          */
582         var $title;
583
584         /**
585          * @access public
586          */
587         var $titleVisible;
588
589         /**
590          * @access public
591          */
592         var $titleLink;
593
594         /**
595          * @access public
596          */
597         var $hits;
598
599         /**
600          * @access public
601          */
602         var $print;
603
604         /**
605          * @access public
606          */
607         var $showCreateDate;
608
609         /**
610          * @access public
611          */
612         var $showModifyDate;
613
614         /**
615          * @access public
616          */
617         var $showPublishDate;
618
619         /**
620          * @access public
621          */
622         var $showAuthor;
623
624         /**
625          * @access public
626          */
627         var $showPdfIcon;
628
629         /**
630          * @access public
631          */
632         var $showPrintIcon;
633
634         /**
635          * @access public
636          */
637         var $showEmailIcon;
638
639         /**
640          * @access public
641          */
642         var $showHits;
643
644         /**
645          * @access public
646          */
647         var $showUrl;
648
649         /**
650          * @access public
651          */
652         var $showIntro;
653
654         /**
655          * @access public
656          */
657         var $showTeaser;
658
659         /**
660          * @access public
661          */
662         var $showText;
663
664         /**
665          * @access public
666          */
667         var $showReadmore;
668
669         /**
670          * @access public
671          */
672         var $showParentCategory;
673
674         /**
675          * @access public
676          */
677         var $parentCategoryLink;
678
679         /**
680          * @access public
681          */
682         var $parentCategory;
683
684         /**
685          * @access public
686          */
687         var $showCategory;
688
689         /**
690          * @access public
691          */
692         var $categoryLink;
693
694         /**
695          * @access public
696          */
697         var $category;
698
699         /**
700          * @access protected
701          */
702         function ArtxContentGeneralArticleView(&$component, &$componentParams, &$article)
703         {
704             // Initialization:
705             $this->_component = &$component;
706             $this->_componentParams = &$componentParams; 
707             $this->_article = &$article;
708             // Calculate properties:
709             $this->isPublished = 0 != $this->_article->state;
710         }
711
712         /**
713          * @access public
714          */
715         function introText() { return ''; }
716
717         /**
718          * @access public
719          */
720         function createDateInfo() { return ''; }
721
722         /**
723          * @access public
724          */
725         function modifyDateInfo() { return ''; }
726
727         /**
728          * @access public
729          */
730         function publishDateInfo() { return ''; }
731
732         /**
733          * @access public
734          */
735         function authorInfo() { return ''; }
736
737         /**
738          * @access public
739          */
740         function hitsInfo() { return ''; }
741
742         /**
743          * @access public
744          */
745         function pdfIcon() { return ''; }
746
747         /**
748          * @access public
749          */
750         function emailIcon() { return ''; }
751
752         /**
753          * @access public
754          */
755         function editIcon() { return ''; }
756
757         /**
758          * @access public
759          */
760         function printPopupIcon() { return ''; }
761
762         /**
763          * @access public
764          */
765         function printScreenIcon() { return ''; }
766
767         /**
768          * @access public
769          */
770         function readmore() { return ''; }
771
772         /**
773          * @access public
774          */
775         function beginUnpublishedArticle() { return '<div class="system-unpublished">'; }
776
777         /**
778          * @access public
779          */
780         function endUnpublishedArticle() { return '</div>'; }
781
782         /**
783          * @access public
784          */
785         function articleSeparator() { return '<div class="item-separator"></div>'; }
786
787         /**
788          * @access public
789          */
790         function categories()
791         {
792             $showParentCategory = $this->showParentCategory && !empty($this->parentCategory);
793             $showCategory = $this->showCategory && !empty($this->category);
794             $result = JText::_('Category') . ': ';
795             if ($showParentCategory) {
796                 $result .= '<span class="art-post-metadata-category-parent">';
797                 $title = $this->_component->escape($this->parentCategory);
798                 if (!empty($this->parentCategoryLink))
799                     $result .= '<a href="' . $this->parentCategoryLink . '">' . $title . '</a>';
800                 else
801                     $result .= $title;
802                 $result .= '</span>';
803             }
804             if ($showParentCategory && $showCategory)
805                 $result .= ' / ';
806             if ($showCategory) {
807                 $result .= '<span class="art-post-metadata-category-name">';
808                 $title = $this->_component->escape($this->category);
809                 if (!empty($this->categoryLink))
810                     $result .= '<a href="' . $this->categoryLink . '">' . $title . '</a>';
811                 else
812                     $result .= $title;
813                 $result .= '</span>';
814             }
815             return $result;
816         }
817
818         /**
819          * @access public
820          */
821         function urlInfo()
822         {
823             return '<a href="http://' . $this->_component->escape($this->_article->urls) . '" target="_blank">'
824                 . $this->_component->escape($this->_article->urls) . '</a>';
825         }
826
827         /**
828          * @access public
829          */
830         function getArticleViewParameters()
831         {
832             return array('metadata-header-icons' => array(), 'metadata-footer-icons' => array());
833         }
834
835         /**
836          * @access public
837          */
838         function event($name)
839         {
840             return $this->_article->event->{$name};
841         }
842
843         /**
844          * @access public
845          */
846         function article($article)
847         {
848             return artxPost($article);
849         }
850
851         /**
852          * @access public
853          */
854         function toc()
855         {
856             return isset($this->_article->toc) ? $this->_article->toc : '';
857         }
858
859         /**
860          * @access public
861          */
862         function content()
863         {
864             return "<div class=\"art-article\">" . $this->_article->text . "</div>";
865         }
866     }
867
868     class ArtxContentArticleView15 extends ArtxContentGeneralArticleView
869     {
870         /**
871          * @access public
872          */
873         function ArtxContentArticleView15(&$component, &$componentParams, &$article, $print)
874         {
875             parent::ArtxContentGeneralArticleView($component, $componentParams, $article);
876
877             $this->print = $print;
878             $this->canEdit = $this->_component->user->authorize('com_content', 'edit', 'content', 'all')
879                 || $this->_component->user->authorize('com_content', 'edit', 'content', 'own');
880             $this->title = $this->_article->title;
881             $this->titleVisible = $this->_componentParams->get('show_title') && strlen($this->title);
882             $this->titleLink = $this->_componentParams->get('link_titles') && '' != $this->_article->readmore_link
883                 ? $this->_article->readmore_link : '';
884             $this->showCreateDate = $this->_componentParams->get('show_create_date');
885             $this->showModifyDate = 0 != intval($this->_article->modified) && $this->_componentParams->get('show_modify_date');
886             $this->showPublishDate = false; // - not available in J! 1.5
887             $this->showAuthor = $this->_componentParams->get('show_author') && '' != $this->_article->author;
888             $this->showPdfIcon = $this->_componentParams->get('show_pdf_icon');
889             $this->showPrintIcon = $this->_componentParams->get('show_print_icon');
890             $this->showEmailIcon = $this->_componentParams->get('show_email_icon');
891             $this->showHits = false; // - not available in J! 1.5
892             $this->showUrl = $this->_componentParams->get('show_url') && $this->_article->urls;
893             $this->showIntro = $this->_componentParams->get('show_intro');
894             $this->showReadmore = false; // - no readmore in article
895             $this->showTeaser = false; // - not available in J! 1.5
896             $this->showText = true; // - not available in J! 1.5
897
898             $this->showParentCategory = $this->_componentParams->get('show_section') && $this->_article->sectionid && isset($this->_article->section);
899             $this->parentCategory = $this->showParentCategory ? $this->_article->section : '';
900             $this->parentCategoryLink = ($this->showParentCategory && $this->_componentParams->get('link_section'))
901                 ? JRoute::_(ContentHelperRoute::getSectionRoute($this->_article->sectionid)) : '';
902             $this->showCategory = $this->_componentParams->get('show_category') && $this->_article->catid;
903             $this->category = $this->showCategory ? $this->_article->category : '';
904             $this->categoryLink = ($this->showCategory && $this->_componentParams->get('link_category'))
905                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->catslug, $this->_article->sectionid)) : '';
906         }
907
908         /**
909          * @access public
910          */
911         function createDateInfo()
912         {
913             return JHTML::_('date', $this->_article->created, JText::_('DATE_FORMAT_LC2'));
914         }
915
916         /**
917          * @access public
918          */
919         function modifyDateInfo()
920         {
921             return JText::sprintf('LAST_UPDATED2', JHTML::_('date', $this->_article->modified, JText::_('DATE_FORMAT_LC2')));
922         }
923
924         /**
925          * @access public
926          */
927         function authorInfo()
928         {
929             return JText::sprintf('Written by', $this->_component->escape($this->_article->created_by_alias
930                 ? $this->_article->created_by_alias : $this->_article->author));
931         }
932
933         /**
934          * @access public
935          */
936         function pdfIcon()
937         {
938             return JHTML::_('icon.pdf', $this->_article, $this->_componentParams, $this->_component->access);
939         }
940
941         /**
942          * @access public
943          */
944         function emailIcon()
945         {
946             return JHTML::_('icon.email', $this->_article, $this->_componentParams, $this->_component->access);
947         }
948
949         /**
950          * @access public
951          */
952         function editIcon()
953         {
954             return JHTML::_('icon.edit', $this->_article, $this->_componentParams, $this->_component->access);
955         }
956
957         /**
958          * @access public
959          */
960         function printPopupIcon()
961         {
962             return JHTML::_('icon.print_popup', $this->_article, $this->_componentParams, $this->_component->access);
963         }
964
965         /**
966          * @access public
967          */
968         function printScreenIcon()
969         {
970             return JHtml::_('icon.print_screen', $this->_article, $this->_componentParams, $this->_component->access);
971         }
972     }
973
974     class ArtxContentArticleView16 extends ArtxContentGeneralArticleView
975     {
976         /**
977          * @access public
978          */
979         function ArtxContentArticleView16($component, $componentParams, $article, $print)
980         {
981             parent::ArtxContentGeneralArticleView($component, $componentParams, $article);
982
983             $user = JFactory::getUser();
984
985             $this->print = $print;
986             $this->canEdit = $this->_article->params->get('access-edit');
987             $this->title = $this->_article->title;
988             $this->titleVisible = $this->_article->params->get('show_title');
989             $this->titleLink = $this->_article->params->get('link_titles') && !empty($this->_article->readmore_link)
990                 ? $this->_article->readmore_link : '';
991             $this->hits = $this->_article->hits;
992             $this->showCreateDate = $this->_article->params->get('show_create_date');
993             $this->showModifyDate = $this->_article->params->get('show_modify_date');
994             $this->showPublishDate = $this->_article->params->get('show_publish_date');
995             $this->showAuthor = $this->_article->params->get('show_author') && !empty($this->_article->author);
996             $this->showPdfIcon = false; // - not available in J! 1.6
997             $this->showPrintIcon = $this->_article->params->get('show_print_icon');
998             $this->showEmailIcon = $this->_article->params->get('show_email_icon');
999             $this->showHits = $this->_article->params->get('show_hits');
1000             $this->showUrl = false; // - not available in J! 1.6
1001             $this->showIntro = $this->_article->params->get('show_intro');
1002             $this->showReadmore = $this->_article->params->get('show_readmore') && $this->_article->fulltext != null;
1003             $this->showTeaser = $this->_article->params->get('show_noauth') == true && $user->get('guest');
1004             $this->showText = $this->_article->params->get('access-view');
1005
1006             $this->showParentCategory = $this->_article->params->get('show_parent_category') && $this->_article->parent_slug != '1:root';
1007             $this->parentCategory = $this->showParentCategory ? $this->_article->parent_title : '';
1008             $this->parentCategoryLink = ($this->showParentCategory && $this->_article->params->get('link_parent_category') && $this->_article->parent_slug)
1009                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->parent_slug)) : '';
1010             $this->showCategory = $this->_article->params->get('show_category');
1011             $this->category = $this->showCategory ? $this->_article->category_title : '';
1012             $this->categoryLink = ($this->showCategory && $this->_article->params->get('link_category') && $this->_article->catslug)
1013                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->catslug)) : '';
1014         }
1015
1016         /**
1017          * @access public
1018          */
1019         function createDateInfo()
1020         {
1021             return JHtml::_('date', $this->_article->created, JText::_('DATE_FORMAT_LC2'));
1022         }
1023
1024         /**
1025          * @access public
1026          */
1027         function modifyDateInfo()
1028         {
1029             return JText::sprintf('COM_CONTENT_LAST_UPDATED', JHtml::_('date', $this->_article->modified, JText::_('DATE_FORMAT_LC2')));
1030         }
1031
1032         /**
1033          * @access public
1034          */
1035         function publishDateInfo()
1036         {
1037             return JText::sprintf('COM_CONTENT_PUBLISHED_DATE', JHtml::_('date', $this->_article->publish_up, JText::_('DATE_FORMAT_LC2')));
1038         }
1039
1040         /**
1041          * @access public
1042          */
1043         function authorInfo()
1044         {
1045             $author = $this->_article->created_by_alias ? $this->_article->created_by_alias : $this->_article->author;
1046             if (!empty($this->_article->contactid) && $this->_article->params->get('link_author'))
1047                 return JText::sprintf('COM_CONTENT_WRITTEN_BY', JHtml::_('link',
1048                     JRoute::_('index.php?option=com_contact&view=contact&id=' . $this->_article->contactid), $author));
1049             return JText::sprintf('COM_CONTENT_WRITTEN_BY', $author);
1050         }
1051
1052         /**
1053          * @access public
1054          */
1055         function emailIcon()
1056         {
1057             return JHtml::_('icon.email', $this->_article, $this->_article->params);
1058         }
1059
1060         /**
1061          * @access public
1062          */
1063         function editIcon()
1064         {
1065             return JHtml::_('icon.edit', $this->_article, $this->_article->params);
1066         }
1067
1068         /**
1069          * @access public
1070          */
1071         function printPopupIcon()
1072         {
1073             return JHtml::_('icon.print_popup', $this->_article, $this->_article->params);
1074         }
1075
1076         /**
1077          * @access public
1078          */
1079         function printScreenIcon()
1080         {
1081             return JHtml::_('icon.print_screen', $this->_article, $this->_article->params);
1082         }
1083
1084         /**
1085          * @access public
1086          */
1087         function hitsInfo()
1088         {
1089             return JText::sprintf('COM_CONTENT_ARTICLE_HITS', $this->_article->hits);
1090         }
1091
1092         /**
1093          * @access public
1094          */
1095         function introText()
1096         {
1097             return "<div class=\"art-article\">" . $this->_article->introtext . "</div>";
1098         }
1099
1100         /**
1101          * @access public
1102          */
1103         function readmore()
1104         {
1105             $content = '';
1106             $link1 = JRoute::_('index.php?option=com_users&view=login');
1107             $link = new JURI($link1);
1108             $content .= '<p class="readmore"><a href="' . $link . '">';
1109             $attribs = json_decode($this->_article->attribs);
1110             if ($attribs->alternative_readmore == null) {
1111                 $content .= JText::_('COM_CONTENT_REGISTER_TO_READ_MORE');
1112             } elseif ($readmore = $this->_article->alternative_readmore) {
1113                 $content .= $readmore;
1114                 if ($this->_article->params->get('show_readmore_title', 0) != 0) {
1115                     $content .= JHTML::_('string.truncate', ($this->_article->title), $this->_article->params->get('readmore_limit'));
1116                 }
1117             } elseif ($this->_article->get('show_readmore_title', 0) == 0) {
1118                 $content .= JText::sprintf('COM_CONTENT_READ_MORE_TITLE');
1119             } else {
1120                 $content .= JText::_('COM_CONTENT_READ_MORE');
1121                 $content .= JHTML::_('string.truncate', ($this->_article->title), $this->_article->params->get('readmore_limit'));
1122             }
1123             $content .= '</a></p>';
1124             return $content;
1125         }
1126     }
1127
1128     /**
1129      * Based on Joomla 1.5.23.
1130      */
1131     class ArtxContentFrontpageItemView15 extends ArtxContentGeneralArticleView
1132     {
1133         /**
1134          * @access public
1135          */
1136         function ArtxContentFrontpageItemView15(&$component, &$componentParams, &$article)
1137         {
1138             parent::ArtxContentGeneralArticleView($component, $componentParams, $article);
1139
1140             $this->canEdit = $this->_component->user->authorize('com_content', 'edit', 'content', 'all')
1141                 || $this->_component->user->authorize('com_content', 'edit', 'content', 'own');
1142             $this->title = $this->_article->title;
1143             $this->titleVisible = $this->_article->params->get('show_title') && strlen($this->title);
1144             $this->titleLink = $this->_article->params->get('link_titles') && '' != $this->_article->readmore_link
1145                 ? $this->_article->readmore_link : '';
1146             $this->showCreateDate = $this->_article->params->get('show_create_date');
1147             $this->showModifyDate = 0 != intval($this->_article->modified) && $this->_article->params->get('show_modify_date');
1148             $this->showPublishDate = false; // - not available in J! 1.5
1149             $this->showAuthor = $this->_article->params->get('show_author') && '' != $this->_article->author;
1150             $this->showPdfIcon = $this->_article->params->get('show_pdf_icon');
1151             $this->showPrintIcon = $this->_article->params->get('show_print_icon');
1152             $this->showEmailIcon = $this->_article->params->get('show_email_icon');
1153             $this->showHits = false; // - not available in J! 1.5
1154             $this->showUrl = $this->_componentParams->get('show_url') && $this->_article->urls;
1155             $this->showIntro = $this->_article->params->get('show_intro');
1156             $this->showReadmore = $this->_article->params->get('show_readmore') && $this->_article->readmore;
1157             $this->showTeaser = true; // - not available in J! 1.5
1158             $this->showText = false; // - not available in J! 1.5
1159
1160
1161             $this->showParentCategory = $this->_article->params->get('show_section') && $this->_article->sectionid && isset($this->_article->section);
1162             $this->parentCategory = $this->showParentCategory ? $this->_article->section : '';
1163             $this->parentCategoryLink = ($this->showParentCategory && $this->_article->params->get('link_section'))
1164                 ? JRoute::_(ContentHelperRoute::getSectionRoute($this->_article->sectionid)) : '';
1165             $this->showCategory = $this->_article->params->get('show_category') && $this->_article->catid;
1166             $this->category = $this->showCategory ? $this->_article->category : '';
1167             $this->categoryLink = ($this->showCategory && $this->_article->params->get('link_category'))
1168                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->catslug, $this->_article->sectionid)) : '';
1169         }
1170
1171         /**
1172          * @access public
1173          */
1174         function createDateInfo()
1175         {
1176             return JHTML::_('date', $this->_article->created, JText::_('DATE_FORMAT_LC2'));
1177         }
1178
1179         /**
1180          * @access public
1181          */
1182         function modifyDateInfo()
1183         {
1184             return JText::sprintf('LAST_UPDATED2', JHTML::_('date', $this->_article->modified, JText::_('DATE_FORMAT_LC2')));
1185         }
1186
1187         /**
1188          * @access public
1189          */
1190         function authorInfo()
1191         {
1192             return JText::sprintf('Written by', $this->_component->escape($this->_article->created_by_alias
1193                 ? $this->_article->created_by_alias : $this->_article->author));
1194         }
1195
1196         /**
1197          * @access public
1198          */
1199         function pdfIcon()
1200         {
1201             return JHTML::_('icon.pdf', $this->_article, $this->_article->params, $this->_component->access);
1202         }
1203
1204         /**
1205          * @access public
1206          */
1207         function emailIcon()
1208         {
1209             return JHTML::_('icon.email', $this->_article, $this->_article->params, $this->_component->access);
1210         }
1211
1212         /**
1213          * @access public
1214          */
1215         function editIcon()
1216         {
1217             return JHTML::_('icon.edit', $this->_article, $this->_article->params, $this->_component->access);
1218         }
1219
1220         /**
1221          * @access public
1222          */
1223         function printPopupIcon()
1224         {
1225             return JHTML::_('icon.print_popup', $this->_article, $this->_article->params, $this->_component->access);
1226         }
1227
1228         /**
1229          * @access public
1230          */
1231         function introText()
1232         {
1233             return "<div class=\"art-article\">" . $this->_article->text . "</div>";
1234         }
1235
1236         /**
1237          * @access public
1238          */
1239         function readmore()
1240         {
1241             if ($this->_article->readmore_register)
1242                 $text = JText::_('Register to read more...');
1243             elseif ($readmore = $this->_article->params->get('readmore'))
1244                 $text = $readmore;
1245             else
1246                 $text = JText::sprintf('Read more...');
1247             return '<p class="readmore">' . artxLinkButton(array(
1248                 'classes' => array('a' => 'readon'),
1249                 'link' => $this->_article->readmore_link,
1250                 'content' => str_replace(' ', '&#160;', $text))) . '</p>';
1251         }
1252     }
1253
1254     /**
1255      * Based on Joomla 1.6.1
1256      */
1257     class ArtxContentFeaturedItemView16 extends ArtxContentGeneralArticleView
1258     {
1259         /**
1260          * @access public
1261          */
1262         function ArtxContentFeaturedItemView16($component, $componentParams, $article)
1263         {
1264             parent::ArtxContentGeneralArticleView($component, $componentParams, $article);
1265
1266             $this->canEdit = $this->_article->params->get('access-edit');
1267             $this->title = $this->_article->title;
1268             $this->titleVisible = $this->_article->params->get('show_title') && strlen($this->title);
1269             $this->titleLink = $this->_article->params->get('link_titles') && $this->_article->params->get('access-view')
1270                 ? JRoute::_(ContentHelperRoute::getArticleRoute($this->_article->slug, $this->_article->catid)) : '';
1271             $this->hits = $this->_article->hits;
1272             $this->showCreateDate = $this->_article->params->get('show_create_date');
1273             $this->showModifyDate = $this->_article->params->get('show_modify_date');
1274             $this->showPublishDate = $this->_article->params->get('show_publish_date');
1275             $this->showAuthor = $this->_article->params->get('show_author') && !empty($this->_article->author);
1276             $this->showPdfIcon = false; // - not available in J! 1.6
1277             $this->showPrintIcon = $this->_article->params->get('show_print_icon');
1278             $this->showEmailIcon = $this->_article->params->get('show_email_icon');
1279             $this->showHits = $this->_article->params->get('show_hits');
1280             $this->showUrl = false; // - not available in J! 1.6
1281             $this->showIntro = $this->_article->params->get('show_intro');
1282             $this->showReadmore = $this->_article->params->get('show_readmore') && $this->_article->readmore;
1283             $this->showTeaser = true;
1284             $this->showText = false;
1285
1286             // Because category blog layout view does not support catslug:
1287             if (!isset($this->_article->catslug))
1288                 $this->_article->catslug = $this->_article->category_alias ? ($this->_article->catid . ':' . $this->_article->category_alias) : $this->_article->catid;
1289             if (!isset($this->_article->parent_slug))
1290                 $this->_article->parent_slug = $this->_article->parent_alias ? ($this->_article->parent_id . ':' . $this->_article->parent_alias) : $this->_article->parent_id;
1291
1292             $this->showParentCategory = $this->_article->params->get('show_parent_category') && $this->_article->parent_id != 1;
1293             $this->parentCategory = $this->showParentCategory ? $this->_article->parent_title : '';
1294             $this->parentCategoryLink = ($this->showParentCategory && $this->_article->params->get('link_parent_category') && $this->_article->parent_slug)
1295                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->parent_slug)) : '';
1296             $this->showCategory = $this->_article->params->get('show_category');
1297             $this->category = $this->showCategory ? $this->_article->category_title : '';
1298             $this->categoryLink = ($this->showCategory && $this->_article->params->get('link_category') && $this->_article->catslug)
1299                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->catslug)) : '';
1300         }
1301
1302         /**
1303          * @access public
1304          */
1305         function createDateInfo()
1306         {
1307             return JHtml::_('date', $this->_article->created, JText::_('DATE_FORMAT_LC2'));
1308         }
1309
1310         /**
1311          * @access public
1312          */
1313         function modifyDateInfo()
1314         {
1315             return JText::sprintf('COM_CONTENT_LAST_UPDATED', JHtml::_('date', $this->_article->modified, JText::_('DATE_FORMAT_LC2')));
1316         }
1317
1318         /**
1319          * @access public
1320          */
1321         function publishDateInfo()
1322         {
1323             return JText::sprintf('COM_CONTENT_PUBLISHED_DATE', JHtml::_('date', $this->_article->publish_up, JText::_('DATE_FORMAT_LC2')));
1324         }
1325
1326         /**
1327          * @access public
1328          */
1329         function authorInfo()
1330         {
1331             $author = $this->_article->created_by_alias ? $this->_article->created_by_alias : $this->_article->author;
1332             if (!empty($this->_article->contactid) && $this->_article->params->get('link_author'))
1333                 return JText::sprintf('COM_CONTENT_WRITTEN_BY', JHtml::_('link',
1334                     JRoute::_('index.php?option=com_contact&view=contact&id=' . $this->_article->contactid), $author));
1335             return JText::sprintf('COM_CONTENT_WRITTEN_BY', $author);
1336         }
1337
1338         /**
1339          * @access public
1340          */
1341         function emailIcon()
1342         {
1343             return JHtml::_('icon.email', $this->_article, $this->_article->params);
1344         }
1345
1346         /**
1347          * @access public
1348          */
1349         function editIcon()
1350         {
1351             return JHtml::_('icon.edit', $this->_article, $this->_article->params);
1352         }
1353
1354         /**
1355          * @access public
1356          */
1357         function printPopupIcon()
1358         {
1359             return JHtml::_('icon.print_popup', $this->_article, $this->_article->params);
1360         }
1361
1362         /**
1363          * @access public
1364          */
1365         function hitsInfo()
1366         {
1367             return JText::sprintf('COM_CONTENT_ARTICLE_HITS', $this->_article->hits);
1368         }
1369
1370         /**
1371          * @access public
1372          */
1373         function introText()
1374         {
1375             return "<div class=\"art-article\">" . $this->_article->introtext . "</div>";
1376         }
1377
1378         /**
1379          * @access public
1380          */
1381         function readmore()
1382         {
1383             if ($this->_article->params->get('access-view')) {
1384                 $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->_article->slug, $this->_article->catid));
1385             } else {
1386                 $app = JFactory::getApplication();
1387                 $menu = $app->getMenu();
1388                 $active = $menu->getActive();
1389                 $itemId = $active->id;
1390                 $link1 = JRoute::_('index.php?option=com_users&view=login&&Itemid=' . $itemId);
1391                 $returnURL = JRoute::_(ContentHelperRoute::getArticleRoute($this->_article->slug, $this->_article->catid));
1392                 $link = new JURI($link1);
1393                 $link->setVar('return', base64_encode($returnURL));
1394             }
1395             if (!$this->_article->params->get('access-view'))
1396                 $text = JText::_('COM_CONTENT_REGISTER_TO_READ_MORE');
1397             elseif ($readmore = $this->_article->alternative_readmore) {
1398                 $text = $readmore;
1399                 if ($this->_article->params->get('show_readmore_title', 0) != 0)
1400                     $text .= JHtml::_('string.truncate', ($this->_article->title), $this->_article->params->get('readmore_limit'));
1401             } elseif ($this->_article->params->get('show_readmore_title', 0) == 0)
1402                 $text = JText::sprintf('COM_CONTENT_READ_MORE_TITLE');
1403             else
1404                 $text = JText::_('COM_CONTENT_READ_MORE') . JHtml::_('string.truncate', $this->_article->title, $this->_article->params->get('readmore_limit'));
1405             return '<p class="readmore">' . artxLinkButton(array(
1406                 'classes' => array('a' => 'readon'),
1407                 'link' => $link,
1408                 'content' => str_replace(' ', '&#160;', $text))) . '</p>';
1409         }
1410     }
1411
1412
1413     /**
1414      * Renders article or block in the Post style.
1415      *
1416      * Elements of the $data array:
1417      *  'classes'
1418      *  'header-text'
1419      *  'header-icon'
1420      *  'header-link'
1421      *  'metadata-header-icons'
1422      *  'metadata-footer-icons'
1423      *  'content'
1424      */
1425     function artxPost($data)
1426     {
1427         if (is_string($data))
1428                 $data = array('content' => $data);
1429         $classes = isset($data['classes']) && strlen($data['classes']) ? $data['classes'] : '';
1430         artxFragmentBegin(str_replace('class="art-post">', 'class="art-post' . $classes . '">', "<div class=\"art-post\">\r\n    <div class=\"art-post-body\">\r\n<div class=\"art-post-inner\">\r\n"));
1431         artxFragmentBegin("<h2 class=\"art-postheader\">" . JHTML::_('image.site', 'postheadericon.png', null, null, null, '', array('width' => '25', 'height' => '22')) . " ");
1432         artxFragmentBegin("");
1433         if (isset($data['header-text']) && strlen($data['header-text'])) {
1434                 if (isset($data['header-link']) && strlen($data['header-link']))
1435                         artxFragmentContent('<a href="' . $data['header-link'] . '" class="PostHeader">' . $data['header-text'] . '</a>');
1436                 else
1437                         artxFragmentContent($data['header-text']);
1438         }
1439         artxFragmentEnd("\r\n");
1440         artxFragmentEnd("</h2>\r\n");
1441         artxFragmentBegin("<div class=\"art-postheadericons art-metadata-icons\">\r\n");
1442         if (isset($data['metadata-header-icons']) && count($data['metadata-header-icons']))
1443                 foreach ($data['metadata-header-icons'] as $icon)
1444                         artxFragment('', $icon, '', ' | ');
1445         artxFragmentEnd("\r\n</div>\r\n");
1446         artxFragmentBegin("<div class=\"art-postcontent\">\r\n");
1447         if (isset($data['content']) && strlen($data['content']))
1448                 artxFragmentContent(artxPostprocessPostContent($data['content']));
1449         artxFragmentEnd("\r\n</div>\r\n<div class=\"cleared\"></div>\r\n");
1450         artxFragmentBegin("<div class=\"art-postmetadatafooter\">\r\n");
1451         artxFragmentBegin("<div class=\"art-postfootericons art-metadata-icons\">\r\n");
1452         if (isset($data['metadata-footer-icons']) && count($data['metadata-footer-icons']))
1453                 foreach ($data['metadata-footer-icons'] as $icon)
1454                         artxFragment('', $icon, '', ' | ');
1455         artxFragmentEnd("\r\n</div>\r\n");
1456         artxFragmentEnd("\r\n</div>\r\n");
1457         return artxFragmentEnd("\r\n</div>\r\n\r\n              <div class=\"cleared\"></div>\r\n    </div>\r\n</div>\r\n", '', true);
1458     }
1459
1460     function artxBlock($caption, $content, $classes = '')
1461     {
1462         $hasCaption = ($GLOBALS['artx_settings']['block']['has_header']
1463             && null !== $caption && strlen(trim($caption)) > 0);
1464         $hasContent = (null !== $content && strlen(trim($content)) > 0);
1465
1466         if (!$hasCaption && !$hasContent)
1467             return '';
1468
1469         ob_start();
1470 ?>
1471         <?php ob_start(); ?>
1472 <div class="art-block">
1473             <div class="art-block-body">
1474         
1475         <?php echo str_replace('class="art-block">', 'class="art-block' . $classes . '">', ob_get_clean()); ?>
1476         <?php if ($hasCaption): ?>
1477 <div class="art-blockheader">
1478             <div class="l"></div>
1479             <div class="r"></div>
1480             <h3 class="t">
1481         <?php echo $caption; ?>
1482 </h3>
1483         </div>
1484         <?php endif; ?>
1485         <?php if ($hasContent): ?>
1486 <div class="art-blockcontent">
1487             <div class="art-blockcontent-body">
1488         
1489         <?php echo artxPostprocessBlockContent($content); ?>
1490
1491         
1492                         <div class="cleared"></div>
1493             </div>
1494         </div>
1495         
1496         <?php endif; ?>
1497
1498                         <div class="cleared"></div>
1499             </div>
1500         </div>
1501         
1502 <?php
1503         return ob_get_clean();
1504     }
1505
1506
1507     function artxVMenuBlock($caption, $content, $classes = '')
1508     {
1509         $hasCaption = (null !== $caption && strlen(trim($caption)) > 0);
1510         $hasContent = (null !== $content && strlen(trim($content)) > 0);
1511
1512         if (!$hasCaption && !$hasContent)
1513             return '';
1514
1515         ob_start();
1516 ?>
1517     <?php ob_start(); ?><div class="art-vmenublock">
1518     <div class="art-vmenublock-body">
1519
1520         <?php echo str_replace('class="art-vmenublock">', 'class="art-vmenublock' . $classes . '">', ob_get_clean()); ?>
1521         <?php if ($hasCaption): ?><div class="art-vmenublockheader">
1522     <h3 class="t">
1523         <?php echo $caption; ?></h3>
1524 </div>
1525         <?php endif; ?>
1526         <?php if ($hasContent): ?><div class="art-vmenublockcontent">
1527     <div class="art-vmenublockcontent-body">
1528
1529         <?php echo $content; ?>
1530
1531                 <div class="cleared"></div>
1532     </div>
1533 </div>
1534
1535         <?php endif; ?>
1536                 <div class="cleared"></div>
1537     </div>
1538 </div>
1539
1540 <?php
1541         return ob_get_clean();
1542     }
1543
1544     /**
1545      * Deprecated since Artisteer 3.0.
1546      */
1547     function artxCountModules(&$document, $position)
1548     {
1549         return $document->artx->countModules($position);
1550     }
1551
1552     /**
1553      * Deprecated since Artisteer 3.0.
1554      */
1555     function artxPositions(&$document, $positions, $style)
1556     {
1557         ob_start();
1558         if (count($positions) == 3) {
1559             if (artxCountModules($document, $positions[0])
1560                 && artxCountModules($document, $positions[1])
1561                 && artxCountModules($document, $positions[2]))
1562             {
1563                 ?>
1564 <table class="position" cellpadding="0" cellspacing="0" border="0">
1565 <tr valign="top">
1566   <td width="33%"><?php echo artxModules($document, $positions[0], $style); ?></td>
1567   <td width="33%"><?php echo artxModules($document, $positions[1], $style); ?></td>
1568   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
1569 </tr>
1570 </table>
1571 <?php
1572             } elseif (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[1])) {
1573 ?>
1574 <table class="position" cellpadding="0" cellspacing="0" border="0">
1575 <tr valign="top">
1576   <td width="33%"><?php echo artxModules($document, $positions[0], $style); ?></td>
1577   <td><?php echo artxModules($document, $positions[1], $style); ?></td>
1578 </tr>
1579 </table>
1580 <?php
1581             } elseif (artxCountModules($document, $positions[1]) && artxCountModules($document, $positions[2])) {
1582 ?>
1583 <table class="position" cellpadding="0" cellspacing="0" border="0">
1584 <tr valign="top">
1585   <td width="67%"><?php echo artxModules($document, $positions[1], $style); ?></td>
1586   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
1587 </tr>
1588 </table>
1589 <?php
1590             } elseif (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[2])) {
1591 ?>
1592 <table class="position" cellpadding="0" cellspacing="0" border="0">
1593 <tr valign="top">
1594   <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
1595   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
1596 </tr>
1597 </table>
1598 <?php
1599             } else {
1600                 echo artxModules($document, $positions[0], $style);
1601                 echo artxModules($document, $positions[1], $style);
1602                 echo artxModules($document, $positions[2], $style);
1603             }
1604         } elseif (count($positions) == 2) {
1605             if (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[1])) {
1606 ?>
1607 <table class="position" cellpadding="0" cellspacing="0" border="0">
1608 <tr valign="top">
1609 <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
1610 <td><?php echo artxModules($document, $positions[1], $style); ?></td>
1611 </tr>
1612 </table>
1613 <?php
1614             } else {
1615                 echo artxModules($document, $positions[0], $style);
1616                 echo artxModules($document, $positions[1], $style);
1617             }
1618         } // count($positions)
1619         return ob_get_clean();
1620     }
1621
1622     /**
1623      * Deprecated since Artisteer 3.0.
1624      */
1625     function artxComponentWrapper(&$document)
1626     {
1627         $this->artx->componentWrapper();
1628     }
1629
1630     /**
1631      * Deprecated since Artisteer 3.0.
1632      */
1633     function artxModules(&$document, $position, $style = null)
1634     {
1635         $this->artx->position($position, $style);
1636     }
1637
1638
1639         function artxUrlToHref($url)
1640         {
1641             $result = '';
1642             $p = parse_url($url);
1643             if (isset($p['scheme']) && isset($p['host'])) {
1644                 $result = $p['scheme'] . '://';
1645                 if (isset($p['user'])) {
1646                     $result .= $p['user'];
1647                     if (isset($p['pass']))
1648                         $result .= ':' . $p['pass'];
1649                     $result .= '@';
1650                 }
1651                 $result .= $p['host'];
1652                 if (isset($p['port']))
1653                     $result .= ':' . $p['port'];
1654                 if (!isset($p['path']))
1655                     $result .= '/';
1656             }
1657             if (isset($p['path']))
1658                 $result .= $p['path'];
1659             if (isset($p['query'])) {
1660                 $result .= '?' . str_replace('&', '&amp;', $p['query']);
1661             }
1662             if (isset($p['fragment']))
1663                 $result .= '#' . $p['fragment'];
1664             return $result;
1665         }
1666     
1667         /**
1668          * Searches $content for tags and returns information about each found tag.
1669          *
1670          * Created to support button replacing process, e.g. wrapping submit/reset 
1671          * inputs and buttons with artisteer style.
1672          *
1673          * When all the $name tags are found, they are processed by the $filter specified.
1674          * Filter is applied to the attributes. When an attribute contains several values
1675          * (e.g. class attribute), only tags that contain all the values from filter
1676          * will be selected. E.g. filtering by the button class will select elements
1677          * with class="button" and class="button validate".
1678          *
1679          * Parsing does not support nested tags. Looking for span tags in
1680          * <span>1<span>2</span>3</span> will return <span>1<span>2</span> and
1681          * <span>2</span>.
1682          *
1683          * Examples:
1684          *  Select all tags with class='readon':
1685          *   artxFindTags($html, array('*' => array('class' => 'readon')))
1686          *  Select inputs with type='submit' and class='button':
1687          *   artxFindTags($html, array('input' => array('type' => 'submit', 'class' => 'button')))
1688          *  Select inputs with type='submit' and class='button validate':
1689          *   artxFindTags($html, array('input' => array('type' => 'submit', 'class' => array('button', 'validate'))))
1690          *  Select inputs with class != 'art-button'
1691          *   artxFindTags($html, array('input' => array('class' => '!art-button')))
1692          *  Select inputs with non-empty class
1693          *   artxFindTags($html, array('input' => array('class' => '!')))
1694          *  Select inputs with class != 'art-button' and non-empty class:
1695          *   artxFindTags($html, array('input' => array('class' => array('!art-button', '!'))))
1696          *  Select inputs with class = button but != 'art-button'
1697          *   artxFindTags($html, array('input' => array('class' => array('button', '!art-button'))))
1698          *
1699          * @return array of text fragments and tag information: position, length,
1700          *         name, attributes, raw_open_tag, body.
1701          */
1702         function artxFindTags($content, $filters)
1703         {
1704             $result = array('');
1705             $index = 0;
1706             $position = 0;
1707             $name = implode('|', array_keys($filters));
1708             $name = str_replace('*', '\w+', $name);
1709             // search for open tag
1710             if (preg_match_all(
1711                 '~<(' . $name . ')\b(?:\s+[^\s]+\s*=\s*(?:"[^"]+"|\'[^\']+\'|[^\s>]+))*\s*/?>~i', $content,
1712                 $tagMatches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER))
1713             {
1714                 foreach ($tagMatches as $tagMatch) {
1715                     $rawMatch = $tagMatch[0][0];
1716                     $name = $tagMatch[1][0];
1717                     $tag = array('name' => $name, 'position' => $tagMatch[0][1]);
1718                     $openTagTail = (strlen($rawMatch) > 1 && '/' == $rawMatch[strlen($rawMatch) - 2])
1719                         ? '/>' : '>';
1720                     // different instructions for paired and unpaired tags
1721                     switch ($name)
1722                     {
1723                         case 'input':
1724                         case 'img':
1725                         case 'br':
1726                             $tag['paired'] = false;
1727                             $tag['length'] = strlen($tagMatch[0][0]);
1728                             $tag['body'] = null;
1729                             $tag['close'] = 2 == strlen($openTagTail);
1730                             break;
1731                         default:
1732                             $closeTag = '</' . $name . '>';
1733                             $closeTagLength = strlen($closeTag);
1734                             $tag['paired'] = true;
1735                             $end = strpos($content, $closeTag, $tag['position']);
1736                             if (false === $end)
1737                                 continue;
1738                             $openTagLength = strlen($tagMatch[0][0]);
1739                             $tag['body'] = substr($content, $tag['position'] + $openTagLength,
1740                                 $end - $openTagLength - $tag['position']);
1741                             $tag['length'] = $end + $closeTagLength - $tag['position'];
1742                             break;
1743                     }
1744                     // parse attributes
1745                     $rawAttributes = trim(substr($tagMatch[0][0], strlen($name) + 1,
1746                         strlen($tagMatch[0][0]) - strlen($name) - 1 - strlen($openTagTail)));
1747                     $attributes = array();
1748                     if (preg_match_all('~([^=\s]+)\s*=\s*(?:(")([^"]+)"|(\')([^\']+)\'|([^\s]+))~',
1749                         $rawAttributes, $attributeMatches, PREG_SET_ORDER))
1750                     {
1751                         foreach ($attributeMatches as $attrMatch) {
1752                             $attrName = $attrMatch[1];
1753                             $attrDelimeter = (isset($attrMatch[2]) && '' !== $attrMatch[2])
1754                                 ? $attrMatch[2]
1755                                 : ((isset($attrMatch[4]) && '' !== $attrMatch[4])
1756                                     ? $attrMatch[4] : '');
1757                             $attrValue = (isset($attrMatch[3]) && '' !== $attrMatch[3])
1758                                 ? $attrMatch[3]
1759                                 : ((isset($attrMatch[5]) && '' !== $attrMatch[5])
1760                                     ? $attrMatch[5] : $attrMatch[6]);
1761                             if ('class' == $attrName)
1762                                 $attrValue = explode(' ', preg_replace('~\s+~', ' ', $attrValue));
1763                             $attributes[$attrName] = array('delimeter' => $attrDelimeter,
1764                                 'value' => $attrValue);
1765                         }
1766                     }
1767                     // apply filter to attributes
1768                     $passed = true;
1769                     $filter = isset($filters[$name])
1770                         ? $filters[$name]
1771                         : (isset($filters['*']) ? $filters['*'] : array());
1772                     foreach ($filter as $key => $value) {
1773                         $criteria = is_array($value) ? $value : array($value);
1774                         for ($c = 0; $c < count($criteria) && $passed; $c++) {
1775                             $crit = $criteria[$c];
1776                             if ('' == $crit) {
1777                                 // attribute should be empty
1778                                 if ('class' == $key) {
1779                                     if (isset($attributes[$key]) && count($attributes[$key]['value']) != 0) {
1780                                         $passed = false;
1781                                         break;
1782                                     }
1783                                 } else {
1784                                     if (isset($attributes[$key]) && strlen($attributes[$key]['value']) != 0) {
1785                                         $passed = false;
1786                                         break;
1787                                     }
1788                                 }
1789                             } else if ('!' == $crit) {
1790                                 // attribute should be not set or empty
1791                                 if ('class' == $key) {
1792                                     if (!isset($attributes[$key]) || count($attributes[$key]['value']) == 0) {
1793                                         $passed = false;
1794                                         break;
1795                                     }
1796                                 } else {
1797                                     if (!isset($attributes[$key]) || strlen($attributes[$key]['value']) == 0) {
1798                                         $passed = false;
1799                                         break;
1800                                     }
1801                                 }
1802                             } else if ('!' == $crit[0]) {
1803                                 // * attribute should not contain value
1804                                 // * if attribute is empty, it does not contain value
1805                                 if ('class' == $key) {
1806                                     if (isset($attributes[$key]) && count($attributes[$key]['value']) != 0
1807                                         && in_array(substr($crit, 1), $attributes[$key]['value']))
1808                                     {
1809                                         $passed = false;
1810                                         break;
1811                                     }
1812                                 } else {
1813                                     if (isset($attributes[$key]) && strlen($attributes[$key]['value']) != 0
1814                                         && $crit == $attributes[$key]['value'])
1815                                     {
1816                                         $passed = false;
1817                                         break;
1818                                     }
1819                                 }
1820                             } else {
1821                                 // * attribute should contain value
1822                                 // * if attribute is empty, it does not contain value
1823                                 if ('class' == $key) {
1824                                     if (!isset($attributes[$key]) || count($attributes[$key]['value']) == 0) {
1825                                         $passed = false;
1826                                         break;
1827                                     }
1828                                     if (!in_array($crit, $attributes[$key]['value'])) {
1829                                         $passed = false;
1830                                         break;
1831                                     }
1832                                 } else {
1833                                     if (!isset($attributes[$key]) || strlen($attributes[$key]['value']) == 0) {
1834                                         $passed = false;
1835                                         break;
1836                                     }
1837                                     if ($crit != $attributes[$key]['value']) {
1838                                         $passed = false;
1839                                         break;
1840                                     }
1841                                 }
1842                             }
1843                         }
1844                         if (!$passed)
1845                             break;
1846                     }
1847                     if (!$passed)
1848                         continue;
1849                     // finalize tag info constrution
1850                     $tag['attributes'] = $attributes;
1851                     $result[$index] = substr($content, $position, $tag['position'] - $position);
1852                     $position = $tag['position'] + $tag['length'];
1853                     $index++;
1854                     $result[$index] = $tag;
1855                     $index++;
1856                 }
1857             }
1858             $result[$index] = $position < strlen($content) ? substr($content, $position) : '';
1859             return $result;
1860         }
1861     
1862         /**
1863          * Converts tag info created by artxFindTags back to text tag.
1864          *
1865          * @return string
1866          */
1867         function artxTagInfoToString($info)
1868         {
1869             $result = '<' . $info['name'];
1870             if (isset($info['attributes']) && 0 != count($info['attributes'])) {
1871                 $attributes = '';
1872                 foreach ($info['attributes'] as $key => $value)
1873                     $attributes .= ' ' . $key . '=' . $value['delimeter']
1874                         . (is_array($value['value']) ? implode(' ', $value['value']) : $value['value'])
1875                         . $value['delimeter'];
1876                 $result .= $attributes;
1877             }
1878             if ($info['paired']) {
1879                 $result .= '>';
1880                 $result .= $info['body'];
1881                 $result .= '</' . $info['name'] . '>';
1882             } else
1883                 $result .= ($info['close'] ? ' /' : '') . '>';
1884             return $result;
1885         }
1886     
1887         /**
1888          * Decorates the specified tag with artisteer button style.
1889          *
1890          * @param string $name tag name that should be decorated
1891          * @param array $filter select $name tags with attributes matching $filter
1892          * @return $content with replaced $name tags
1893          */
1894         function artxReplaceButtons($content, $filter = array('input' => array('class' => 'button')))
1895         {
1896             $result = '';
1897             foreach (artxFindTags($content, $filter) as $tag) {
1898                 if (is_string($tag))
1899                     $result .= $tag;
1900                 else {
1901                     $tag['attributes']['class']['value'][] = 'art-button';
1902                     $delimeter = '' == $tag['attributes']['class']['delimeter']
1903                         ? '"' : $tag['attributes']['class']['delimeter'];
1904                     $tag['attributes']['class']['delimeter'] = $delimeter;
1905                     $button = str_replace('"', $delimeter, '<span class="art-button-wrapper">'
1906                         . '<span class="art-button-l"> </span><span class="art-button-r"> </span>')
1907                         . artxTagInfoToString($tag) . '</span>';
1908                     $result .= $button;
1909                 }
1910             }
1911             return $result;
1912         }
1913     
1914         function artxLinkButton($data = array())
1915         {
1916             return '<span class="art-button-wrapper"><span class="art-button-l"> </span><span class="art-button-r"> </span>'
1917                 . '<a class="' . (isset($data['classes']) && isset($data['classes']['a']) ? $data['classes']['a'] . ' ' : '')
1918                 . 'art-button" href="' . $data['link'] . '">' . $data['content'] . '</a></span>';
1919         }
1920     
1921         function artxHtmlFixFormAction($content)
1922         {
1923             if (preg_match('~ action="([^"]+)" ~', $content, $matches, PREG_OFFSET_CAPTURE)) {
1924                 $content = substr($content, 0, $matches[0][1])
1925                     . ' action="' . artxUrlToHref($matches[1][0]) . '" '
1926                     . substr($content, $matches[0][1] + strlen($matches[0][0]));
1927             }
1928             return $content;
1929         }
1930     
1931         function artxTagBuilder($tag, $attributes, $content) {
1932             $result = '<' . $tag;
1933             foreach ($attributes as $name => $value) {
1934                 if (is_string($value)) {
1935                     if (!empty($value))
1936                         $result .= ' ' . $name . '="' . $value . '"';
1937                 } else if (is_array($value)) {
1938                     $values = array_filter($value);
1939                     if (count($values))
1940                         $result .= ' ' . $name . '="' . implode(' ', $value) . '"';
1941                 }
1942             }
1943             $result .= '>' . $content . '</' . $tag . '>';
1944             return $result;
1945         }
1946     
1947         $artxFragments = array();
1948     
1949         function artxFragmentBegin($head = '')
1950         {
1951             global $artxFragments;
1952             $artxFragments[] = array('head' => $head, 'content' => '', 'tail' => '');
1953         }
1954     
1955         function artxFragmentContent($content = '')
1956         {
1957             global $artxFragments;
1958             $artxFragments[count($artxFragments) - 1]['content'] = $content;
1959         }
1960     
1961         function artxFragmentEnd($tail = '', $separator = '', $return = false)
1962         {
1963             global $artxFragments;
1964             $fragment = array_pop($artxFragments);
1965             $fragment['tail'] = $tail;
1966             $content = trim($fragment['content']);
1967             if (count($artxFragments) == 0) {
1968                 if ($return)
1969                     return (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
1970                 echo (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
1971             } else {
1972                 $result = (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
1973                 $fragment =& $artxFragments[count($artxFragments) - 1];
1974                 $fragment['content'] .= (trim($fragment['content']) == '' ? '' : $separator) . $result;
1975             }
1976         }
1977     
1978         function artxFragment($head = '', $content = '', $tail = '', $separator = '', $return = false)
1979         {
1980             global $artxFragments;
1981             if ($head != '' && $content == '' && $tail == '' && $separator == '') {
1982                 $content = $head;
1983                 $head = '';
1984             } elseif ($head != '' && $content != '' && $tail == '' && $separator == '') {
1985                 $separator = $content;
1986                 $content = $head;
1987                 $head = '';
1988             }
1989             artxFragmentBegin($head);
1990             artxFragmentContent($content);
1991             artxFragmentEnd($tail, $separator, $return);
1992         }
1993     
1994
1995 function artxPostprocessBlockContent($content)
1996     {
1997         return artxPostprocessContent($content);
1998     }
1999     
2000     function artxPostprocessPostContent($content)
2001     {
2002         return artxPostprocessContent($content);
2003     }
2004     
2005     function artxPostprocessContent($content)
2006     {
2007         $content = artxReplaceButtons($content, array('input' => array('class' => array('button', '!art-button')),
2008             'button' => array('class' => array('button', '!art-button'))));
2009         return $content;
2010     }
2011     
2012
2013 }