OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / templates / art26_test1 / 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' => true, '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 class ArtxPageView
20     {
21
22         public $page;
23
24         protected function __construct($page) {
25             $this->page = $page;
26         }
27         
28         /**
29          * Returns version-specific body class: joomla15 or joomla16.
30          *
31          * Example:
32          *  <body class="joomla15">
33          */
34         abstract function bodyClass();
35         
36         /**
37          * Checks whether Joomla! has system messages to display.
38          */
39         abstract function hasMessages();
40
41         /**
42          * Returns true when one of the given positions contains at least one module.
43          * Example:
44          *  if ($obj->containsModules('top1', 'top2', 'top3')) {
45          *   // the following code will be executed when one of the positions contain modules:
46          *   ...
47          *  }
48          */
49         function containsModules()
50         {
51             foreach (func_get_args() as $position)
52                 if (0 != $this->page->countModules($position))
53                     return true;
54             return false;
55         }
56
57         /**
58          * Builds list of positions, collapsing the empty ones.
59          *
60          * Samples:
61          *  Four positions:
62          *   No empty positions: 25%:25%:25%:25%
63          *   With one empty positions: -:50%:25%:25%, 50%:-:25%:25%, 25%:50%:-:25%, 25%:25%:50%:-
64          *   With two empty positions: -:-:75%:25%, -:50%:-:50%, -:50%:50%:-, -:50%:50%:-, 75%:-:-:25%, 50%:-:50%:-, 25%:75%:-:-
65          *   One non-empty position: 100%
66          *  Three positions:
67          *   No empty positions: 33%:33%:34%
68          *   With one empty position: -:66%:34%, 50%:-:50%, 33%:67%:-
69          *   One non-empty position: 100%
70          */
71         function positions($positions, $style) {
72             // Build $cells by collapsing empty positions:
73             $cells = array();
74             $buffer = 0;
75             $cell = null;
76             foreach ($positions as $name => $width) {
77                 if ($this->containsModules($name)) {
78                     $cells[$name] = $buffer + $width;
79                     $buffer = 0;
80                     $cell = $name;
81                 } else if (null == $cell)
82                     $buffer += $width;
83                 else
84                     $cells[$cell] += $width;
85             }
86
87             // Backward compatibility:
88             //  For three equal width columns with empty center position width should be 50/50:
89             if (3 == count($positions) && 2 == count($cells)) {
90                 $columns1 = array_keys($positions);
91                 $columns2 = array_keys($cells);
92                 if (33 == $positions[$columns1[0]] && 33 == $positions[$columns1[1]] && 34 == $positions[$columns1[2]]
93                     && $columns2[0] == $columns1[0] && $columns2[1] == $columns1[2])
94                     $cells[$columns2[0]] = 50;
95                     $cells[$columns2[1]] = 50;
96             }
97
98             // Render $cells:
99             if (count($cells) == 0)
100                 return '';
101             if (count($cells) == 1)
102                 foreach ($cells as $name => $width)
103                     return $this->position($name, $style);
104             $result = '<table class="position" cellpadding="0" cellspacing="0" border="0">';
105             $result .= '<tr valign="top">';
106             foreach ($cells as $name => $width)
107                 $result .='<td width="' . $width. '%">' . $this->position($name, $style) . '</td>';
108             $result .= '</tr>';
109             $result .= '</table>';
110             return $result;
111         }
112
113         function position($position, $style = null)
114         {
115             return '<jdoc:include type="modules" name="' . $position . '"' . (null != $style ? ' style="artstyle" artstyle="' . $style . '"' : '') . ' />';
116         }
117
118         /**
119          * Preprocess component content before printing it.
120          */
121         function componentWrapper()
122         {
123         }
124
125         /**
126          * Checks layout sidebar cells and returns content cell class that expands content cell over empty sidebar.
127          */
128         function contentCellClass($cells)
129         {
130             $nonEmptyCells = array();
131             $emptyCells = array();
132             foreach ($cells as $name => $class) {
133                 if ('content' == $name)
134                     continue;
135                 if ($this->containsModules($name))
136                     $nonEmptyCells[] = $class;
137                 else
138                     $emptyCells[] = $class;
139             }
140             switch (count($emptyCells)) {
141                 case 2:
142                     return 'content-wide';
143                 case 1:
144                     if (count($nonEmptyCells))
145                         return 'content-' . $emptyCells[0];
146                     return 'content';
147             }
148             return 'content';
149         }
150     }
151     
152     class ArtxPage15 extends ArtxPageView
153     {
154         public function __construct($page) {
155             parent::__construct($page);
156         }
157     
158         function bodyClass() {
159             return 'joomla15';
160         }
161
162         function hasMessages()
163         {
164             global $mainframe;
165             $messages = $mainframe->getMessageQueue();
166             if (is_array($messages) && count($messages))
167                 foreach ($messages as $msg)
168                     if (isset($msg['type']) && isset($msg['message']))
169                         return true;
170             return false;
171         }
172         
173         /**
174          * Wraps component content into article style unless it is not wrapped already.
175          *
176          * The componentWrapper method gets the content of the 'component' buffer and search for the '<div class="art-post">' string in it.
177          * Then it replaces the componentheading DIV tag with span (to fix the w3.org validation) and replaces content of the buffer with
178          * wrapped content.
179          */
180         function componentWrapper()
181         {
182             if ($this->page->getType() != 'html')
183                 return;
184             $option = JRequest::getCmd('option');
185             $view = JRequest::getCmd('view');
186             $layout = JRequest::getCmd('layout');
187             if ('com_content' == $option && ('frontpage' == $view || 'article' == $view || ('category' == $view && 'blog' == $layout)))
188                     return;
189             $content = $this->page->getBuffer('component');
190             if (false === strpos($content, '<div class="art-post')) {
191                 $title = null;
192                 if (preg_match('~<div\s+class="(componentheading[^"]*)"([^>]*)>([^<]+)</div>~', $content, $matches, PREG_OFFSET_CAPTURE)) {
193                     $content = substr($content, 0, $matches[0][1]) . substr($content, $matches[0][1] + strlen($matches[0][0]));
194                     $title = '<span class="' . $matches[1][0] . '"' . $matches[2][0] . '>' . $matches[3][0] . '</span>';
195                 }
196                 $this->page->setBuffer(artxPost(array('header-text' => $title, 'content' => $content)), 'component');
197             }
198         }
199     }
200     
201     class ArtxPage16 extends ArtxPageView
202     {
203         public function __construct($page) {
204             parent::__construct($page);
205         }
206         
207         function bodyClass() {
208             return 'joomla16';
209         }
210
211         function hasMessages()
212         {
213             $messages = JFactory::getApplication()->getMessageQueue();
214             if (is_array($messages) && count($messages))
215                 foreach ($messages as $msg)
216                     if (isset($msg['type']) && isset($msg['message']))
217                         return true;
218             return false;
219         }
220                 
221         /**
222          * Wraps component content into article style unless it is not wrapped already.
223          *
224          * The componentWrapper method gets the content of the 'component' buffer and search for the '<div class="art-post">' string in it.
225          * Then it wraps content of the buffer with art-post.
226          */
227         function componentWrapper()
228         {
229             if ($this->page->getType() != 'html')
230                 return;
231             $option = JRequest::getCmd('option');
232             $view = JRequest::getCmd('view');
233             $layout = JRequest::getCmd('layout');
234             if ('com_content' == $option && ('featured' == $view || 'article' == $view || ('category' == $view && 'blog' == $layout)))
235                     return;
236             $content = $this->page->getBuffer('component');
237             if (false === strpos($content, '<div class="art-post'))
238                 $this->page->setBuffer(artxPost(array('header-text' => null, 'content' => $content)), 'component');
239         }
240     }
241     
242     /**
243      * Base class with content page routines for rendering page header and article factory.
244      */
245     abstract class ArtxContentView
246     {
247         protected $_component;
248         protected $_componentParams;
249         
250         /**
251          * Component page class suffix.
252          * @var string
253          */
254         public $pageClassSfx;
255         
256         /**
257          * @var boolean
258          */
259         public $showPageHeading;
260         
261         /**
262          * Page heading (or page title).
263          * @var string
264          */
265         public $pageHeading;
266         
267         protected function __construct($component, $params)
268         {
269             $this->_component = $component;
270             $this->_componentParams = $params;
271         }
272         
273         abstract function pageHeading($heading = null);
274         abstract function article($article, $print);
275         abstract function articleListItem($item);
276         
277         public function beginPageContainer($class)
278         {
279             return '<div class="' . $class . $this->pageClassSfx .'">';
280         }
281         
282         public function endPageContainer()
283         {
284             return '</div>';
285         }
286     }
287     
288     class ArtxContent15 extends ArtxContentView
289     {
290         public function __construct($component, $params)
291         {
292             parent::__construct($component, $params);
293             $this->pageClassSfx = $this->_componentParams->get('pageclass_sfx');
294             $this->showPageHeading = $this->_componentParams->def('show_page_title', 1);
295             $this->pageHeading = $this->showPageHeading ? $this->_componentParams->get('page_title') : '';
296         }
297         
298         function pageHeading($heading = null)
299         {
300             return artxPost(array('header-text' => null == $heading ? $this->pageHeading : $heading));
301         }
302         
303         function article($article, $print)
304         {
305             return new ArtxContentArticleView15($this->_component, $this->_componentParams, $article, $print);
306         }
307         
308         function articleListItem($item)
309         {
310             return new ArtxContentFrontpageItemView15($this->_component, $this->_componentParams, $item);
311         }
312     }
313     
314     class ArtxContent16 extends ArtxContentView
315     {
316         public function __construct($component, $params)
317         {
318             parent::__construct($component, $params);
319             $this->pageClassSfx = $this->_component->pageclass_sfx;
320             $this->showPageHeading = $this->_componentParams->def('show_page_heading', 1);
321             $this->pageHeading = $this->showPageHeading ? $this->_componentParams->get('page_heading') : '';
322         }
323         
324         function pageHeading($heading = null)
325         {
326             return artxPost(array('header-text' => null == $heading ? $this->pageHeading : $heading));
327         }
328         
329         function article($article, $print)
330         {
331             return new ArtxContentArticleView16($this->_component, $this->_componentParams, $article, $print);
332         }
333         
334         function articleListItem($item)
335         {
336             return new ArtxContentFeaturedItemView16($this->_component, $this->_componentParams, $item);
337         }
338     }
339
340     abstract class ArtxContentGeneralArticleView
341     {
342         protected $_component;
343         protected $_componentParams;
344         protected $_article;
345         
346         public $params;
347         public $isPublished;
348         public $canEdit;
349         public $title;
350         public $titleVisible;
351         public $titleLink;
352         public $hits;
353         public $print;
354         public $showCreateDate;
355         public $showModifyDate;
356         public $showPublishDate;
357         public $showAuthor;
358         public $showPdfIcon;
359         public $showPrintIcon;
360         public $showEmailIcon;
361         public $showHits;
362         public $showUrl;
363         public $showIntro;
364         public $showReadmore;
365         public $showParentCategory;
366         public $parentCategoryLink;
367         public $parentCategory;
368         public $showCategory;
369         public $categoryLink;
370         public $category;
371         
372         protected function __construct($component, $componentParams, $article)
373         {
374             // Initialization:
375             $this->_component = $component;
376             $this->_componentParams = $componentParams; 
377             $this->_article = $article;
378             // Calculate properties:
379             $this->isPublished = 0 != $this->_article->state;
380         }
381         
382         public function introText() { return ''; }
383         public function createDateInfo() { return ''; }
384         public function modifyDateInfo() { return ''; }
385         public function publishDateInfo() { return ''; }
386         public function authorInfo() { return ''; }
387         public function hitsInfo() { return ''; }
388         public function pdfIcon() { return ''; }
389         public function emailIcon() { return ''; }
390         public function editIcon() { return ''; }
391         public function printPopupIcon() { return ''; }
392         public function printScreenIcon() { return ''; }
393         public function readmore() { return ''; }
394         
395         public function beginUnpublishedArticle() { return '<div class="system-unpublished">'; }
396         public function endUnpublishedArticle() { return '</div>'; }
397         public function articleSeparator() { return '<div class="item-separator"></div>'; }
398         
399         public function categories()
400         {
401             $showParentCategory = $this->showParentCategory && !empty($this->parentCategory);
402             $showCategory = $this->showCategory && !empty($this->category);
403             $result = JText::_('Category') . ': ';
404             if ($showParentCategory) {
405                 $result .= '<span class="art-post-metadata-category-parent">';
406                 $title = $this->_component->escape($this->parentCategory);
407                 if (!empty($this->parentCategoryLink))
408                     $result .= '<a href="' . $this->parentCategoryLink . '">' . $title . '</a>';
409                 else
410                     $result .= $title;
411                 $result .= '</span>';
412             }
413             if ($showParentCategory && $showCategory)
414                 $result .= ' / ';
415             if ($showCategory) {
416                 $result .= '<span class="art-post-metadata-category-name">';
417                 $title = $this->_component->escape($this->category);
418                 if (!empty($this->categoryLink))
419                     $result .= '<a href="' . $this->categoryLink . '">' . $title . '</a>';
420                 else
421                     $result .= $title;
422                 $result .= '</span>';
423             }
424             return $result;
425         }
426         
427         public function urlInfo()
428         {
429             return '<a href="http://' . $this->_component->escape($this->_article->urls) . '" target="_blank">'
430                 . $this->_component->escape($this->_article->urls) . '</a>';
431         }
432         
433         public function getArticleViewParameters()
434         {
435             return array('metadata-header-icons' => array(), 'metadata-footer-icons' => array());
436         }
437         
438         public function event($name)
439         {
440             return $this->_article->event->{$name};
441         }
442         
443         public function article($article)
444         {
445             return artxPost($article);
446         }
447         
448         public function content()
449         {
450             return (isset($this->_article->toc) ? $this->_article->toc : '') . "<div class=\"art-article\">" . $this->_article->text . "</div>";
451         }
452         
453     }
454
455     class ArtxContentArticleView15 extends ArtxContentGeneralArticleView
456     {
457         function __construct($component, $componentParams, $article, $print)
458         {
459             parent::__construct($component, $componentParams, $article);
460             
461             $this->print = $print;
462             $this->canEdit = $this->_component->user->authorize('com_content', 'edit', 'content', 'all')
463                 || $this->_component->user->authorize('com_content', 'edit', 'content', 'own');
464             $this->title = $this->_article->title;
465             $this->titleVisible = $this->_componentParams->get('show_title') && strlen($this->title);
466             $this->titleLink = $this->_componentParams->get('link_titles') && '' != $this->_article->readmore_link
467                 ? $this->_article->readmore_link : '';
468             $this->showCreateDate = $this->_componentParams->get('show_create_date');
469             $this->showModifyDate = 0 != intval($this->_article->modified) && $this->_componentParams->get('show_modify_date');
470             $this->showPublishDate = false; // - not available in J! 1.5
471             $this->showAuthor = $this->_componentParams->get('show_author') && '' != $this->_article->author;
472             $this->showPdfIcon = $this->_componentParams->get('show_pdf_icon');
473             $this->showPrintIcon = $this->_componentParams->get('show_print_icon');
474             $this->showEmailIcon = $this->_componentParams->get('show_email_icon');
475             $this->showHits = false; // - not available in J! 1.5
476             $this->showUrl = $this->_componentParams->get('show_url') && $this->_article->urls;
477             $this->showIntro = $this->_componentParams->get('show_intro');
478             $this->showReadmore = false; // - no readmore in article
479             
480             $this->showParentCategory = $this->_componentParams->get('show_section') && $this->_article->sectionid && isset($this->_article->section);
481             $this->parentCategory = $this->showParentCategory ? $this->_article->section : '';
482             $this->parentCategoryLink = ($this->showParentCategory && $this->_componentParams->get('link_section'))
483                 ? JRoute::_(ContentHelperRoute::getSectionRoute($this->_article->sectionid)) : '';
484             $this->showCategory = $this->_componentParams->get('show_category') && $this->_article->catid;
485             $this->category = $this->showCategory ? $this->_article->category : '';
486             $this->categoryLink = ($this->showCategory && $this->_componentParams->get('link_category'))
487                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->catslug, $this->_article->sectionid)) : '';
488         }
489         
490         public function createDateInfo()
491         {
492             return JHTML::_('date', $this->_article->created, JText::_('DATE_FORMAT_LC2'));
493         }
494         
495         public function modifyDateInfo()
496         {
497             return JText::sprintf('LAST_UPDATED2', JHTML::_('date', $this->_article->modified, JText::_('DATE_FORMAT_LC2')));
498         }
499         
500         public function authorInfo()
501         {
502             return JText::sprintf('Written by', $this->_component->escape($this->_article->created_by_alias
503                 ? $this->_article->created_by_alias : $this->_article->author));
504         }
505         
506         public function pdfIcon()
507         {
508             return JHTML::_('icon.pdf', $this->_article, $this->_componentParams, $this->_component->access);
509         }
510         
511         public function emailIcon()
512         {
513             return JHTML::_('icon.email', $this->_article, $this->_componentParams, $this->_component->access);
514         }
515
516         public function editIcon()
517         {
518             return JHTML::_('icon.edit', $this->_article, $this->_componentParams, $this->_component->access);
519         }
520
521         public function printPopupIcon()
522         {
523             return JHTML::_('icon.print_popup', $this->_article, $this->_componentParams, $this->_component->access);
524         }
525         
526         public function printScreenIcon()
527         {
528             return JHtml::_('icon.print_screen', $this->_article, $this->_componentParams, $this->_component->access);
529         }
530     }
531
532     class ArtxContentArticleView16 extends ArtxContentGeneralArticleView
533     {
534         function __construct($component, $componentParams, $article, $print)
535         {
536             parent::__construct($component, $componentParams, $article);
537             
538             $this->print = $print;
539             $this->canEdit = $this->_article->params->get('access-edit');
540             $this->title = $this->_article->title;
541             $this->titleVisible = $this->_article->params->get('show_title') || $this->_article->params->get('access-edit');
542             $this->titleLink = $this->_article->params->get('link_titles') && !empty($this->_article->readmore_link)
543                 ? $this->_article->readmore_link : '';
544             $this->hits = $this->_article->hits;
545             $this->showCreateDate = $this->_article->params->get('show_create_date');
546             $this->showModifyDate = $this->_article->params->get('show_modify_date');
547             $this->showPublishDate = $this->_article->params->get('show_publish_date');
548             $this->showAuthor = $this->_article->params->get('show_author') && !empty($this->_article->author);
549             $this->showPdfIcon = false; // - not available in J! 1.6
550             $this->showPrintIcon = $this->_article->params->get('show_print_icon');
551             $this->showEmailIcon = $this->_article->params->get('show_email_icon');
552             $this->showHits = $this->_article->params->get('show_hits');
553             $this->showUrl = false; // - not available in J! 1.6
554             $this->showIntro = $this->_article->params->get('show_intro');
555             $this->showReadmore = false; // - no readmore in article
556             
557             $this->showParentCategory = $this->_article->params->get('show_parent_category') && $this->_article->parent_slug != '1:root';
558             $this->parentCategory = $this->showParentCategory ? $this->_article->parent_title : '';
559             $this->parentCategoryLink = ($this->showParentCategory && $this->_article->params->get('link_parent_category') && $this->_article->parent_slug)
560                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->parent_slug)) : '';
561             $this->showCategory = $this->_article->params->get('show_category');
562             $this->category = $this->showCategory ? $this->_article->category_title : '';
563             $this->categoryLink = ($this->showCategory && $this->_article->params->get('link_category') && $this->_article->catslug)
564                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->catslug)) : '';
565         }
566         
567         public function createDateInfo()
568         {
569             return JHtml::_('date', $this->_article->created, JText::_('DATE_FORMAT_LC2'));
570         }
571         
572         public function modifyDateInfo()
573         {
574             return JText::sprintf('COM_CONTENT_LAST_UPDATED', JHtml::_('date', $this->_article->modified, JText::_('DATE_FORMAT_LC2')));
575         }
576         
577         public function publishDateInfo()
578         {
579             return JText::sprintf('COM_CONTENT_PUBLISHED_DATE', JHtml::_('date', $this->_article->publish_up, JText::_('DATE_FORMAT_LC2')));
580         }
581         
582         public function authorInfo()
583         {
584             $author = $this->_article->created_by_alias ? $this->_article->created_by_alias : $this->_article->author;
585             if (!empty($this->_article->contactid) && $this->_article->params->get('link_author'))
586                 return JText::sprintf('COM_CONTENT_WRITTEN_BY', JHtml::_('link',
587                     JRoute::_('index.php?option=com_contact&view=contact&id=' . $this->_article->contactid), $author));
588             return JText::sprintf('COM_CONTENT_WRITTEN_BY', $author);
589         }
590         
591         public function emailIcon()
592         {
593             return JHtml::_('icon.email', $this->_article, $this->_article->params);
594         }
595
596         public function editIcon()
597         {
598             return JHtml::_('icon.edit', $this->_article, $this->_article->params);
599         }
600         
601         public function printPopupIcon()
602         {
603             return JHtml::_('icon.print_popup', $this->_article, $this->_article->params);
604         }
605         
606         public function printScreenIcon()
607         {
608             return JHtml::_('icon.print_screen', $this->_article, $this->_article->params);
609         }
610         
611         public function hitsInfo()
612         {
613             return JText::sprintf('COM_CONTENT_ARTICLE_HITS', $this->_article->hits);
614         }
615     }
616
617     /**
618      * Based on Joomla 1.5.22.
619      */
620     class ArtxContentFrontpageItemView15 extends ArtxContentGeneralArticleView
621     {
622         function __construct($component, $componentParams, $article)
623         {
624             parent::__construct($component, $componentParams, $article);
625             
626             $this->canEdit = $this->_component->user->authorize('com_content', 'edit', 'content', 'all')
627                 || $this->_component->user->authorize('com_content', 'edit', 'content', 'own');
628             $this->title = $this->_article->title;
629             $this->titleVisible = $this->_article->params->get('show_title') && strlen($this->title);
630             $this->titleLink = $this->_article->params->get('link_titles') && '' != $this->_article->readmore_link
631                 ? $this->_article->readmore_link : '';
632             $this->showCreateDate = $this->_article->params->get('show_create_date');
633             $this->showModifyDate = 0 != intval($this->_article->modified) && $this->_article->params->get('show_modify_date');
634             $this->showPublishDate = false; // - not available in J! 1.5
635             $this->showAuthor = $this->_article->params->get('show_author') && '' != $this->_article->author;
636             $this->showPdfIcon = $this->_article->params->get('show_pdf_icon');
637             $this->showPrintIcon = $this->_article->params->get('show_print_icon');
638             $this->showEmailIcon = $this->_article->params->get('show_email_icon');
639             $this->showHits = false; // - not available in J! 1.5
640             $this->showUrl = $this->_componentParams->get('show_url') && $this->_article->urls;
641             $this->showIntro = $this->_article->params->get('show_intro');
642             $this->showReadmore = $this->_article->params->get('show_readmore') && $this->_article->readmore;
643             
644             $this->showParentCategory = $this->_article->params->get('show_section') && $this->_article->sectionid && isset($this->_article->section);
645             $this->parentCategory = $this->showParentCategory ? $this->_article->section : '';
646             $this->parentCategoryLink = ($this->showParentCategory && $this->_article->params->get('link_section'))
647                 ? JRoute::_(ContentHelperRoute::getSectionRoute($this->_article->sectionid)) : '';
648             $this->showCategory = $this->_article->params->get('show_category') && $this->_article->catid;
649             $this->category = $this->showCategory ? $this->_article->category : '';
650             $this->categoryLink = ($this->showCategory && $this->_article->params->get('link_category'))
651                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->catslug, $this->_article->sectionid)) : '';
652         }
653         
654         public function createDateInfo()
655         {
656             return JHTML::_('date', $this->_article->created, JText::_('DATE_FORMAT_LC2'));
657         }
658         
659         public function modifyDateInfo()
660         {
661             return JText::sprintf('LAST_UPDATED2', JHTML::_('date', $this->_article->modified, JText::_('DATE_FORMAT_LC2')));
662         }
663         
664         public function authorInfo()
665         {
666             return JText::sprintf('Written by', $this->_component->escape($this->_article->created_by_alias
667                 ? $this->_article->created_by_alias : $this->_article->author));
668         }
669         
670         public function pdfIcon()
671         {
672             return JHTML::_('icon.pdf', $this->_article, $this->_article->params, $this->_component->access);
673         }
674         
675         public function emailIcon()
676         {
677             return JHTML::_('icon.email', $this->_article, $this->_article->params, $this->_component->access);
678         }
679         
680         public function editIcon()
681         {
682             return JHTML::_('icon.edit', $this->_article, $this->_article->params, $this->_component->access);
683         }
684
685         public function printPopupIcon()
686         {
687             return JHTML::_('icon.print_popup', $this->_article, $this->_article->params, $this->_component->access);
688         }
689         
690         public function introText()
691         {
692             return "<div class=\"art-article\">" . $this->_article->text . "</div>";
693         }
694         
695         public function readmore()
696         {
697             if ($this->_article->readmore_register)
698                 $text = JText::_('Register to read more...');
699             elseif ($readmore = $this->_article->params->get('readmore'))
700                 $text = $readmore;
701             else
702                 $text = JText::sprintf('Read more...');
703             return '<p class="readmore">' . artxLinkButton(array(
704                 'classes' => array('a' => 'readon'),
705                 'link' => $this->_article->readmore_link,
706                 'content' => str_replace(' ', '&#160;', $text))) . '</p>';
707         }
708     }
709     
710     /**
711      * Based on Joomla 1.6 RC1.
712      */
713     class ArtxContentFeaturedItemView16 extends ArtxContentGeneralArticleView
714     {
715         function __construct($component, $componentParams, $article)
716         {
717             parent::__construct($component, $componentParams, $article);
718             
719             $this->canEdit = $this->_article->params->get('access-edit');
720             $this->title = $this->_article->title;
721             $this->titleVisible = $this->_article->params->get('show_title') && strlen($this->title);
722             $this->titleLink = $this->_article->params->get('link_titles') && $this->_article->params->get('access-view')
723                 ? JRoute::_(ContentHelperRoute::getArticleRoute($this->_article->slug, $this->_article->catid)) : '';
724             $this->hits = $this->_article->hits;
725             $this->showCreateDate = $this->_article->params->get('show_create_date');
726             $this->showModifyDate = $this->_article->params->get('show_modify_date');
727             $this->showPublishDate = $this->_article->params->get('show_publish_date');
728             $this->showAuthor = $this->_article->params->get('show_author') && !empty($this->_article->author);
729             $this->showPdfIcon = false; // - not available in J! 1.6
730             $this->showPrintIcon = $this->_article->params->get('show_print_icon');
731             $this->showEmailIcon = $this->_article->params->get('show_email_icon');
732             $this->showHits = $this->_article->params->get('show_hits');
733             $this->showUrl = false; // - not available in J! 1.6
734             $this->showIntro = $this->_article->params->get('show_intro');
735             $this->showReadmore = $this->_article->params->get('show_readmore') && $this->_article->readmore;
736
737             // Because category blog layout view does not support catslug:
738             if (!isset($this->_article->catslug))
739                 $this->_article->catslug = $this->_article->category_alias ? ($this->_article->catid . ':' . $this->_article->category_alias) : $this->_article->catid;
740             if (!isset($this->_article->parent_slug))
741                 $this->_article->parent_slug = $this->_article->parent_alias ? ($this->_article->parent_id . ':' . $this->_article->parent_alias) : $this->_article->parent_id;
742
743             $this->showParentCategory = $this->_article->params->get('show_parent_category');
744             $this->parentCategory = $this->showParentCategory ? $this->_article->parent_title : '';
745             $this->parentCategoryLink = ($this->showParentCategory && $this->_article->params->get('link_parent_category') && $this->_article->parent_slug)
746                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->parent_slug)) : '';
747             $this->showCategory = $this->_article->params->get('show_category');
748             $this->category = $this->showCategory ? $this->_article->category_title : '';
749             $this->categoryLink = ($this->showCategory && $this->_article->params->get('link_category') && $this->_article->catslug)
750                 ? JRoute::_(ContentHelperRoute::getCategoryRoute($this->_article->catslug)) : '';
751         }
752         
753         public function createDateInfo()
754         {
755             return JHtml::_('date', $this->_article->created, JText::_('DATE_FORMAT_LC2'));
756         }
757         
758         public function modifyDateInfo()
759         {
760             return JText::sprintf('COM_CONTENT_LAST_UPDATED', JHtml::_('date', $this->_article->modified, JText::_('DATE_FORMAT_LC2')));
761         }
762         
763         public function publishDateInfo()
764         {
765             return JText::sprintf('COM_CONTENT_PUBLISHED_DATE', JHtml::_('date', $this->_article->publish_up, JText::_('DATE_FORMAT_LC2')));
766         }
767         
768         public function authorInfo()
769         {
770             $author = $this->_article->created_by_alias ? $this->_article->created_by_alias : $this->_article->author;
771             if (!empty($this->_article->contactid) && $this->_article->params->get('link_author'))
772                 return JText::sprintf('COM_CONTENT_WRITTEN_BY', JHtml::_('link',
773                     JRoute::_('index.php?option=com_contact&view=contact&id=' . $this->_article->contactid), $author));
774             return JText::sprintf('COM_CONTENT_WRITTEN_BY', $author);
775         }
776         
777         public function emailIcon()
778         {
779             return JHtml::_('icon.email', $this->_article, $this->_article->params);
780         }
781         
782         public function editIcon()
783         {
784             return JHtml::_('icon.edit', $this->_article, $this->_article->params);
785         }
786         
787         public function printPopupIcon()
788         {
789             return JHtml::_('icon.print_popup', $this->_article, $this->_article->params);
790         }
791         
792         public function hitsInfo()
793         {
794             return JText::sprintf('COM_CONTENT_ARTICLE_HITS', $this->_article->hits);
795         }
796         
797         public function introText()
798         {
799             return "<div class=\"art-article\">" . $this->_article->introtext . "</div>";
800         }
801         
802         public function readmore()
803         {
804             if ($this->_article->params->get('access-view')) {
805                 $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->_article->slug, $this->_article->catid));
806             } else {
807                 $menu = JFactory::getApplication()->getMenu();
808                 $active = $menu->getActive();
809                 $itemId = $active->id;
810                 $link1 = JRoute::_('index.php?option=com_users&view=login&&Itemid=' . $itemId);
811                 $returnURL = JRoute::_(ContentHelperRoute::getArticleRoute($this->_article->slug, $this->_article->catid));
812                 $link = new JURI($link1);
813                 $link->setVar('return', base64_encode($returnURL));
814             }
815             if (!$this->_article->params->get('access-view'))
816                 $text = JText::_('COM_CONTENT_REGISTER_TO_READ_MORE');
817             elseif ($readmore = $this->_article->alternative_readmore)
818                 $text = $readmore . JHtml::_('string.truncate', ($this->_article->title), $this->_article->params->get('readmore_limit'));
819             elseif ($this->_article->params->get('show_readmore_title', 0) == 0)
820                 $text = JText::sprintf('COM_CONTENT_READ_MORE_TITLE');
821             else
822                 $text = JText::_('COM_CONTENT_READ_MORE') . JHtml::_('string.truncate', $this->_article->title, $this->_article->params->get('readmore_limit'));
823             return '<p class="readmore">' . artxLinkButton(array(
824                 'classes' => array('a' => 'readon'),
825                 'link' => $link,
826                 'content' => str_replace(' ', '&#160;', $text))) . '</p>';
827         }
828     }
829     
830
831     /**
832      * Renders article or block in the Post style.
833      *
834      * Elements of the $data array:
835      *  'classes'
836      *  'header-text'
837      *  'header-icon'
838      *  'header-link'
839      *  'metadata-header-icons'
840      *  'metadata-footer-icons'
841      *  'content'
842      */
843     function artxPost($data)
844     {
845         if (is_string($data))
846                 $data = array('content' => $data);
847         $classes = isset($data['classes']) && strlen($data['classes']) ? $data['classes'] : '';
848         artxFragmentBegin(str_replace('class="art-post">', 'class="art-post' . $classes . '">', "<div class=\"art-post\">\r\n    <div class=\"art-post-tl\"></div>\r\n    <div class=\"art-post-tr\"></div>\r\n    <div class=\"art-post-bl\"></div>\r\n    <div class=\"art-post-br\"></div>\r\n    <div class=\"art-post-tc\"></div>\r\n    <div class=\"art-post-bc\"></div>\r\n    <div class=\"art-post-cl\"></div>\r\n    <div class=\"art-post-cr\"></div>\r\n    <div class=\"art-post-cc\"></div>\r\n    <div class=\"art-post-body\">\r\n<div class=\"art-post-inner\">\r\n"));
849         artxFragmentBegin("<h2 class=\"art-postheader\"> ");
850         artxFragmentBegin("");
851         if (isset($data['header-text']) && strlen($data['header-text'])) {
852                 if (isset($data['header-link']) && strlen($data['header-link']))
853                         artxFragmentContent('<a href="' . $data['header-link'] . '" class="PostHeader">' . $data['header-text'] . '</a>');
854                 else
855                         artxFragmentContent($data['header-text']);
856         }
857         artxFragmentEnd("\r\n");
858         artxFragmentEnd("</h2>\r\n");
859         artxFragmentBegin("<div class=\"art-postheadericons art-metadata-icons\">\r\n");
860         if (isset($data['metadata-header-icons']) && count($data['metadata-header-icons']))
861                 foreach ($data['metadata-header-icons'] as $icon)
862                         artxFragment('', $icon, '', ' | ');
863         artxFragmentEnd("\r\n</div>\r\n");
864         artxFragmentBegin("<div class=\"art-postcontent\">\r\n    <!-- article-content -->\r\n");
865         if (isset($data['content']) && strlen($data['content']))
866                 artxFragmentContent($data['content']);
867         artxFragmentEnd("\r\n    <!-- /article-content -->\r\n</div>\r\n<div class=\"cleared\"></div>\r\n");
868         artxFragmentBegin("<div class=\"art-postmetadatafooter\">\r\n");
869         artxFragmentBegin("<div class=\"art-postfootericons art-metadata-icons\">\r\n");
870         if (isset($data['metadata-footer-icons']) && count($data['metadata-footer-icons']))
871                 foreach ($data['metadata-footer-icons'] as $icon)
872                         artxFragment('', $icon, '', ' | ');
873         artxFragmentEnd("\r\n</div>\r\n");
874         artxFragmentEnd("\r\n</div>\r\n");
875         return artxFragmentEnd("\r\n</div>\r\n\r\n              <div class=\"cleared\"></div>\r\n    </div>\r\n</div>\r\n", '', true);
876     }
877
878     function artxBlock($caption, $content, $classes = '')
879     {
880         $hasCaption = ($GLOBALS['artx_settings']['block']['has_header']
881             && null !== $caption && strlen(trim($caption)) > 0);
882         $hasContent = (null !== $content && strlen(trim($content)) > 0);
883
884         if (!$hasCaption && !$hasContent)
885             return '';
886
887         ob_start();
888 ?>
889         <?php ob_start(); ?>
890 <div class="art-block">
891             <div class="art-block-body">
892         
893         <?php echo str_replace('class="art-block">', 'class="art-block' . $classes . '">', ob_get_clean()); ?>
894         <?php if ($hasCaption): ?>
895 <div class="art-blockheader">
896             <div class="l"></div>
897             <div class="r"></div>
898              <div class="t">
899         <?php echo $caption; ?>
900 </div>
901         </div>
902         
903         <?php endif; ?>
904         <?php if ($hasContent): ?>
905 <div class="art-blockcontent">
906             <div class="art-blockcontent-body">
907         <!-- block-content -->
908         
909         <?php echo artxReplaceButtons($content); ?>
910
911         <!-- /block-content -->
912         
913                         <div class="cleared"></div>
914             </div>
915         </div>
916         
917         <?php endif; ?>
918
919                         <div class="cleared"></div>
920             </div>
921         </div>
922         
923 <?php
924         return ob_get_clean();
925     }
926
927
928     function artxVMenuBlock($caption, $content)
929     {
930         if (null === $content || strlen(trim($content)) == 0)
931             return '';
932         ob_start();
933 ?><div class="art-vmenublock">
934     <div class="art-vmenublock-body">
935 <div class="art-vmenublockcontent">
936     <div class="art-vmenublockcontent-body">
937 <!-- block-content -->
938
939         <?php echo $content; ?>
940 <!-- /block-content -->
941
942                 <div class="cleared"></div>
943     </div>
944 </div>
945
946                 <div class="cleared"></div>
947     </div>
948 </div>
949
950 <?php
951         return ob_get_clean();
952     }
953
954     /**
955      * Depricated since Artisteer 3.0.
956      */
957     function artxCountModules(&$document, $position)
958     {
959         return $document->artx->countModules($position);
960     }
961
962     /**
963      * Depricated since Artisteer 3.0.
964      */
965     function artxPositions(&$document, $positions, $style)
966     {
967         ob_start();
968         if (count($positions) == 3) {
969             if (artxCountModules($document, $positions[0])
970                 && artxCountModules($document, $positions[1])
971                 && artxCountModules($document, $positions[2]))
972             {
973                 ?>
974 <table class="position" cellpadding="0" cellspacing="0" border="0">
975 <tr valign="top">
976   <td width="33%"><?php echo artxModules($document, $positions[0], $style); ?></td>
977   <td width="33%"><?php echo artxModules($document, $positions[1], $style); ?></td>
978   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
979 </tr>
980 </table>
981 <?php
982             } elseif (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[1])) {
983 ?>
984 <table class="position" cellpadding="0" cellspacing="0" border="0">
985 <tr valign="top">
986   <td width="33%"><?php echo artxModules($document, $positions[0], $style); ?></td>
987   <td><?php echo artxModules($document, $positions[1], $style); ?></td>
988 </tr>
989 </table>
990 <?php
991             } elseif (artxCountModules($document, $positions[1]) && artxCountModules($document, $positions[2])) {
992 ?>
993 <table class="position" cellpadding="0" cellspacing="0" border="0">
994 <tr valign="top">
995   <td width="67%"><?php echo artxModules($document, $positions[1], $style); ?></td>
996   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
997 </tr>
998 </table>
999 <?php
1000             } elseif (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[2])) {
1001 ?>
1002 <table class="position" cellpadding="0" cellspacing="0" border="0">
1003 <tr valign="top">
1004   <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
1005   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
1006 </tr>
1007 </table>
1008 <?php
1009             } else {
1010                 echo artxModules($document, $positions[0], $style);
1011                 echo artxModules($document, $positions[1], $style);
1012                 echo artxModules($document, $positions[2], $style);
1013             }
1014         } elseif (count($positions) == 2) {
1015             if (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[1])) {
1016 ?>
1017 <table class="position" cellpadding="0" cellspacing="0" border="0">
1018 <tr valign="top">
1019 <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
1020 <td><?php echo artxModules($document, $positions[1], $style); ?></td>
1021 </tr>
1022 </table>
1023 <?php
1024             } else {
1025                 echo artxModules($document, $positions[0], $style);
1026                 echo artxModules($document, $positions[1], $style);
1027             }
1028         } // count($positions)
1029         return ob_get_clean();
1030     }
1031
1032     /**
1033      * Depricated since Artisteer 3.0.
1034      */
1035     function artxComponentWrapper(&$document)
1036     {
1037         $this->artx->componentWrapper();
1038     }
1039
1040     /**
1041      * Depricated since Artisteer 3.0.
1042      */
1043     function artxModules(&$document, $position, $style = null)
1044     {
1045         $this->artx->position($position, $style);
1046     }
1047
1048
1049         function artxUrlToHref($url)
1050         {
1051                 $result = '';
1052                 $p = parse_url($url);
1053                 if (isset($p['scheme']) && isset($p['host'])) {
1054                         $result = $p['scheme'] . '://';
1055                         if (isset($p['user'])) {
1056                                 $result .= $p['user'];
1057                                 if (isset($p['pass']))
1058                                         $result .= ':' . $p['pass'];
1059                                 $result .= '@';
1060                         }
1061                         $result .= $p['host'];
1062                         if (isset($p['port']))
1063                                 $result .= ':' . $p['port'];
1064                         if (!isset($p['path']))
1065                                 $result .= '/';
1066                 }
1067                 if (isset($p['path']))
1068                         $result .= $p['path'];
1069                 if (isset($p['query'])) {
1070                         $result .= '?' . str_replace('&', '&amp;', $p['query']);
1071                 }
1072                 if (isset($p['fragment']))
1073                         $result .= '#' . $p['fragment'];
1074                 return $result;
1075         }
1076     
1077         function artxReplaceButtonsRegex() {
1078                 return '~<input\b[^>]*'
1079                         . '\bclass=(?:(")(?:[^"]*\s)?button(?:\s[^"]*)?"|(\')(?:[^\']*\s)?button(?:\s[^\']*)?\'|button(?=[/>\s]))'
1080                         . '[^>]*/?\s*>~i';
1081         }
1082     
1083         function artxReplaceButtons($content)
1084         {
1085                 $re = artxReplaceButtonsRegex();
1086                 if (!preg_match_all($re, $content, $matches, PREG_OFFSET_CAPTURE))
1087                         return $content;
1088                 $result = '';
1089                 $position = 0;
1090                 for ($index = 0; $index < count($matches[0]); $index++) {
1091                         $match = $matches[0][$index];
1092                         if (is_array($matches[1][$index]) && strlen($matches[1][$index][0]) > 0)
1093                                 $quote = $matches[1][$index][0];
1094                         else if (is_array($matches[2][$index]) && strlen($matches[2][$index][0]) > 0)
1095                                 $quote = $matches[2][$index][0];
1096                         else
1097                                 $quote = '"';
1098                         $result .= substr($content, $position, $match[1] - $position);
1099                         $position = $match[1] + strlen($match[0]);
1100                         $result .= str_replace('"', $quote, '<span class="art-button-wrapper"><span class="l"> </span><span class="r"> </span>')
1101                                 . preg_replace('~\bclass=(?:"([^"]*\s)?button(\s[^"]*)?"|\'([^\']*\s)?button(\s[^\']*)?\'|button(?=[/>\s]))~i',
1102                                         str_replace('"', $quote, 'class="\1\3button art-button\2\4"'), $match[0]) . '</span>';
1103                 }
1104                 $result .= substr($content, $position);
1105                 return $result;
1106         }
1107     
1108         function artxLinkButton($data = array())
1109         {
1110                 return '<span class="art-button-wrapper"><span class="l"> </span><span class="r"> </span>'
1111                         . '<a class="' . (isset($data['classes']) && isset($data['classes']['a']) ? $data['classes']['a'] . ' ' : '')
1112                         . 'art-button" href="' . $data['link'] . '">' . $data['content'] . '</a></span>';
1113         }
1114     
1115         function artxHtmlFixFormAction($content)
1116         {
1117                 if (preg_match('~ action="([^"]+)" ~', $content, $matches, PREG_OFFSET_CAPTURE)) {
1118                         $content = substr($content, 0, $matches[0][1])
1119                                 . ' action="' . artxUrlToHref($matches[1][0]) . '" '
1120                                 . substr($content, $matches[0][1] + strlen($matches[0][0]));
1121                 }
1122                 return $content;
1123         }
1124     
1125         function artxTagBuilder($tag, $attributes, $content) {
1126                 $result = '<' . $tag;
1127                 foreach ($attributes as $name => $value) {
1128                         if (is_string($value)) {
1129                                 if (!empty($value))
1130                                         $result .= ' ' . $name . '="' . $value . '"';
1131                         } else if (is_array($value)) {
1132                                 $values = array_filter($value);
1133                                 if (count($values))
1134                                         $result .= ' ' . $name . '="' . implode(' ', $value) . '"';
1135                         }
1136                 }
1137                 $result .= '>' . $content . '</' . $tag . '>';
1138                 return $result;
1139         }
1140     
1141         $artxFragments = array();
1142     
1143         function artxFragmentBegin($head = '')
1144         {
1145                 global $artxFragments;
1146                 $artxFragments[] = array('head' => $head, 'content' => '', 'tail' => '');
1147         }
1148     
1149         function artxFragmentContent($content = '')
1150         {
1151                 global $artxFragments;
1152                 $artxFragments[count($artxFragments) - 1]['content'] = $content;
1153         }
1154     
1155         function artxFragmentEnd($tail = '', $separator = '', $return = false)
1156         {
1157                 global $artxFragments;
1158                 $fragment = array_pop($artxFragments);
1159                 $fragment['tail'] = $tail;
1160                 $content = trim($fragment['content']);
1161                 if (count($artxFragments) == 0) {
1162                         if ($return)
1163                                 return (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
1164                         echo (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
1165                 } else {
1166                         $result = (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
1167                         $fragment =& $artxFragments[count($artxFragments) - 1];
1168                         $fragment['content'] .= (trim($fragment['content']) == '' ? '' : $separator) . $result;
1169                 }
1170         }
1171     
1172         function artxFragment($head = '', $content = '', $tail = '', $separator = '', $return = false)
1173         {
1174                 global $artxFragments;
1175                 if ($head != '' && $content == '' && $tail == '' && $separator == '') {
1176                         $content = $head;
1177                         $head = '';
1178                 } elseif ($head != '' && $content != '' && $tail == '' && $separator == '') {
1179                         $separator = $content;
1180                         $content = $head;
1181                         $head = '';
1182                 }
1183                 artxFragmentBegin($head);
1184                 artxFragmentContent($content);
1185                 artxFragmentEnd($tail, $separator, $return);
1186         }
1187     
1188
1189 }