OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / templates / art26_test2 / 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-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-postmetadataheader\">\r\n");
860         artxFragmentBegin("<div class=\"art-postheadericons art-metadata-icons\">\r\n");
861         if (isset($data['metadata-header-icons']) && count($data['metadata-header-icons']))
862                 foreach ($data['metadata-header-icons'] as $icon)
863                         artxFragment('', $icon, '', ' | ');
864         artxFragmentEnd("\r\n</div>\r\n");
865         artxFragmentEnd("\r\n</div>\r\n");
866         artxFragmentBegin("<div class=\"art-postcontent\">\r\n    <!-- article-content -->\r\n");
867         if (isset($data['content']) && strlen($data['content']))
868                 artxFragmentContent($data['content']);
869         artxFragmentEnd("\r\n    <!-- /article-content -->\r\n</div>\r\n<div class=\"cleared\"></div>\r\n");
870         artxFragmentBegin("<div class=\"art-postmetadatafooter\">\r\n");
871         artxFragmentBegin("<div class=\"art-postfootericons art-metadata-icons\">\r\n");
872         if (isset($data['metadata-footer-icons']) && count($data['metadata-footer-icons']))
873                 foreach ($data['metadata-footer-icons'] as $icon)
874                         artxFragment('', $icon, '', ' | ');
875         artxFragmentEnd("\r\n</div>\r\n");
876         artxFragmentEnd("\r\n</div>\r\n");
877         return artxFragmentEnd("\r\n</div>\r\n\r\n              <div class=\"cleared\"></div>\r\n    </div>\r\n</div>\r\n", '', true);
878     }
879
880     function artxBlock($caption, $content, $classes = '')
881     {
882         $hasCaption = ($GLOBALS['artx_settings']['block']['has_header']
883             && null !== $caption && strlen(trim($caption)) > 0);
884         $hasContent = (null !== $content && strlen(trim($content)) > 0);
885
886         if (!$hasCaption && !$hasContent)
887             return '';
888
889         ob_start();
890 ?>
891         <?php ob_start(); ?>
892 <div class="art-block">
893             <div class="art-block-body">
894         
895         <?php echo str_replace('class="art-block">', 'class="art-block' . $classes . '">', ob_get_clean()); ?>
896         <?php if ($hasCaption): ?>
897 <div class="art-blockheader">
898             <div class="l"></div>
899             <div class="r"></div>
900              <div class="t">
901         <?php echo $caption; ?>
902 </div>
903         </div>
904         
905         <?php endif; ?>
906         <?php if ($hasContent): ?>
907 <div class="art-blockcontent">
908             <div class="art-blockcontent-body">
909         <!-- block-content -->
910         
911         <?php echo artxReplaceButtons($content); ?>
912
913         <!-- /block-content -->
914         
915                         <div class="cleared"></div>
916             </div>
917         </div>
918         
919         <?php endif; ?>
920
921                         <div class="cleared"></div>
922             </div>
923         </div>
924         
925 <?php
926         return ob_get_clean();
927     }
928
929
930     function artxVMenuBlock($caption, $content, $classes = '')
931     {
932         $hasCaption = (null !== $caption && strlen(trim($caption)) > 0);
933         $hasContent = (null !== $content && strlen(trim($content)) > 0);
934
935         if (!$hasCaption && !$hasContent)
936             return '';
937
938         ob_start();
939 ?>
940     <?php ob_start(); ?><div class="art-vmenublock">
941     <div class="art-vmenublock-body">
942
943         <?php echo str_replace('class="art-vmenublock">', 'class="art-vmenublock' . $classes . '">', ob_get_clean()); ?>
944         <?php if ($hasCaption): ?><div class="art-vmenublockheader">
945     <div class="l"></div>
946     <div class="r"></div>
947      <div class="t">
948         <?php echo $caption; ?></div>
949 </div>
950
951         <?php endif; ?>
952         <?php if ($hasContent): ?><div class="art-vmenublockcontent">
953     <div class="art-vmenublockcontent-body">
954 <!-- block-content -->
955
956         <?php echo $content; ?>
957 <!-- /block-content -->
958
959                 <div class="cleared"></div>
960     </div>
961 </div>
962
963         <?php endif; ?>
964                 <div class="cleared"></div>
965     </div>
966 </div>
967
968 <?php
969         return ob_get_clean();
970     }
971
972     /**
973      * Depricated since Artisteer 3.0.
974      */
975     function artxCountModules(&$document, $position)
976     {
977         return $document->artx->countModules($position);
978     }
979
980     /**
981      * Depricated since Artisteer 3.0.
982      */
983     function artxPositions(&$document, $positions, $style)
984     {
985         ob_start();
986         if (count($positions) == 3) {
987             if (artxCountModules($document, $positions[0])
988                 && artxCountModules($document, $positions[1])
989                 && artxCountModules($document, $positions[2]))
990             {
991                 ?>
992 <table class="position" cellpadding="0" cellspacing="0" border="0">
993 <tr valign="top">
994   <td width="33%"><?php echo artxModules($document, $positions[0], $style); ?></td>
995   <td width="33%"><?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[1])) {
1001 ?>
1002 <table class="position" cellpadding="0" cellspacing="0" border="0">
1003 <tr valign="top">
1004   <td width="33%"><?php echo artxModules($document, $positions[0], $style); ?></td>
1005   <td><?php echo artxModules($document, $positions[1], $style); ?></td>
1006 </tr>
1007 </table>
1008 <?php
1009             } elseif (artxCountModules($document, $positions[1]) && artxCountModules($document, $positions[2])) {
1010 ?>
1011 <table class="position" cellpadding="0" cellspacing="0" border="0">
1012 <tr valign="top">
1013   <td width="67%"><?php echo artxModules($document, $positions[1], $style); ?></td>
1014   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
1015 </tr>
1016 </table>
1017 <?php
1018             } elseif (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[2])) {
1019 ?>
1020 <table class="position" cellpadding="0" cellspacing="0" border="0">
1021 <tr valign="top">
1022   <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
1023   <td><?php echo artxModules($document, $positions[2], $style); ?></td>
1024 </tr>
1025 </table>
1026 <?php
1027             } else {
1028                 echo artxModules($document, $positions[0], $style);
1029                 echo artxModules($document, $positions[1], $style);
1030                 echo artxModules($document, $positions[2], $style);
1031             }
1032         } elseif (count($positions) == 2) {
1033             if (artxCountModules($document, $positions[0]) && artxCountModules($document, $positions[1])) {
1034 ?>
1035 <table class="position" cellpadding="0" cellspacing="0" border="0">
1036 <tr valign="top">
1037 <td width="50%"><?php echo artxModules($document, $positions[0], $style); ?></td>
1038 <td><?php echo artxModules($document, $positions[1], $style); ?></td>
1039 </tr>
1040 </table>
1041 <?php
1042             } else {
1043                 echo artxModules($document, $positions[0], $style);
1044                 echo artxModules($document, $positions[1], $style);
1045             }
1046         } // count($positions)
1047         return ob_get_clean();
1048     }
1049
1050     /**
1051      * Depricated since Artisteer 3.0.
1052      */
1053     function artxComponentWrapper(&$document)
1054     {
1055         $this->artx->componentWrapper();
1056     }
1057
1058     /**
1059      * Depricated since Artisteer 3.0.
1060      */
1061     function artxModules(&$document, $position, $style = null)
1062     {
1063         $this->artx->position($position, $style);
1064     }
1065
1066
1067         function artxUrlToHref($url)
1068         {
1069                 $result = '';
1070                 $p = parse_url($url);
1071                 if (isset($p['scheme']) && isset($p['host'])) {
1072                         $result = $p['scheme'] . '://';
1073                         if (isset($p['user'])) {
1074                                 $result .= $p['user'];
1075                                 if (isset($p['pass']))
1076                                         $result .= ':' . $p['pass'];
1077                                 $result .= '@';
1078                         }
1079                         $result .= $p['host'];
1080                         if (isset($p['port']))
1081                                 $result .= ':' . $p['port'];
1082                         if (!isset($p['path']))
1083                                 $result .= '/';
1084                 }
1085                 if (isset($p['path']))
1086                         $result .= $p['path'];
1087                 if (isset($p['query'])) {
1088                         $result .= '?' . str_replace('&', '&amp;', $p['query']);
1089                 }
1090                 if (isset($p['fragment']))
1091                         $result .= '#' . $p['fragment'];
1092                 return $result;
1093         }
1094     
1095         function artxReplaceButtonsRegex() {
1096                 return '~<input\b[^>]*'
1097                         . '\bclass=(?:(")(?:[^"]*\s)?button(?:\s[^"]*)?"|(\')(?:[^\']*\s)?button(?:\s[^\']*)?\'|button(?=[/>\s]))'
1098                         . '[^>]*/?\s*>~i';
1099         }
1100     
1101         function artxReplaceButtons($content)
1102         {
1103                 $re = artxReplaceButtonsRegex();
1104                 if (!preg_match_all($re, $content, $matches, PREG_OFFSET_CAPTURE))
1105                         return $content;
1106                 $result = '';
1107                 $position = 0;
1108                 for ($index = 0; $index < count($matches[0]); $index++) {
1109                         $match = $matches[0][$index];
1110                         if (is_array($matches[1][$index]) && strlen($matches[1][$index][0]) > 0)
1111                                 $quote = $matches[1][$index][0];
1112                         else if (is_array($matches[2][$index]) && strlen($matches[2][$index][0]) > 0)
1113                                 $quote = $matches[2][$index][0];
1114                         else
1115                                 $quote = '"';
1116                         $result .= substr($content, $position, $match[1] - $position);
1117                         $position = $match[1] + strlen($match[0]);
1118                         $result .= str_replace('"', $quote, '<span class="art-button-wrapper"><span class="l"> </span><span class="r"> </span>')
1119                                 . preg_replace('~\bclass=(?:"([^"]*\s)?button(\s[^"]*)?"|\'([^\']*\s)?button(\s[^\']*)?\'|button(?=[/>\s]))~i',
1120                                         str_replace('"', $quote, 'class="\1\3button art-button\2\4"'), $match[0]) . '</span>';
1121                 }
1122                 $result .= substr($content, $position);
1123                 return $result;
1124         }
1125     
1126         function artxLinkButton($data = array())
1127         {
1128                 return '<span class="art-button-wrapper"><span class="l"> </span><span class="r"> </span>'
1129                         . '<a class="' . (isset($data['classes']) && isset($data['classes']['a']) ? $data['classes']['a'] . ' ' : '')
1130                         . 'art-button" href="' . $data['link'] . '">' . $data['content'] . '</a></span>';
1131         }
1132     
1133         function artxHtmlFixFormAction($content)
1134         {
1135                 if (preg_match('~ action="([^"]+)" ~', $content, $matches, PREG_OFFSET_CAPTURE)) {
1136                         $content = substr($content, 0, $matches[0][1])
1137                                 . ' action="' . artxUrlToHref($matches[1][0]) . '" '
1138                                 . substr($content, $matches[0][1] + strlen($matches[0][0]));
1139                 }
1140                 return $content;
1141         }
1142     
1143         function artxTagBuilder($tag, $attributes, $content) {
1144                 $result = '<' . $tag;
1145                 foreach ($attributes as $name => $value) {
1146                         if (is_string($value)) {
1147                                 if (!empty($value))
1148                                         $result .= ' ' . $name . '="' . $value . '"';
1149                         } else if (is_array($value)) {
1150                                 $values = array_filter($value);
1151                                 if (count($values))
1152                                         $result .= ' ' . $name . '="' . implode(' ', $value) . '"';
1153                         }
1154                 }
1155                 $result .= '>' . $content . '</' . $tag . '>';
1156                 return $result;
1157         }
1158     
1159         $artxFragments = array();
1160     
1161         function artxFragmentBegin($head = '')
1162         {
1163                 global $artxFragments;
1164                 $artxFragments[] = array('head' => $head, 'content' => '', 'tail' => '');
1165         }
1166     
1167         function artxFragmentContent($content = '')
1168         {
1169                 global $artxFragments;
1170                 $artxFragments[count($artxFragments) - 1]['content'] = $content;
1171         }
1172     
1173         function artxFragmentEnd($tail = '', $separator = '', $return = false)
1174         {
1175                 global $artxFragments;
1176                 $fragment = array_pop($artxFragments);
1177                 $fragment['tail'] = $tail;
1178                 $content = trim($fragment['content']);
1179                 if (count($artxFragments) == 0) {
1180                         if ($return)
1181                                 return (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
1182                         echo (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
1183                 } else {
1184                         $result = (trim($content) == '') ? '' : ($fragment['head'] . $content . $fragment['tail']);
1185                         $fragment =& $artxFragments[count($artxFragments) - 1];
1186                         $fragment['content'] .= (trim($fragment['content']) == '' ? '' : $separator) . $result;
1187                 }
1188         }
1189     
1190         function artxFragment($head = '', $content = '', $tail = '', $separator = '', $return = false)
1191         {
1192                 global $artxFragments;
1193                 if ($head != '' && $content == '' && $tail == '' && $separator == '') {
1194                         $content = $head;
1195                         $head = '';
1196                 } elseif ($head != '' && $content != '' && $tail == '' && $separator == '') {
1197                         $separator = $content;
1198                         $content = $head;
1199                         $head = '';
1200                 }
1201                 artxFragmentBegin($head);
1202                 artxFragmentContent($content);
1203                 artxFragmentEnd($tail, $separator, $return);
1204         }
1205     
1206
1207 }