openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

LastChanges.class.php (4509B)


      1 <?php
      2 // OpenRat Content Management System
      3 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de
      4 //
      5 // This program is free software; you can redistribute it and/or
      6 // modify it under the terms of the GNU General Public License
      7 // as published by the Free Software Foundation; either version 2
      8 // of the License, or (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU General Public License
     16 // along with this program; if not, write to the Free Software
     17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     18 use cms\model\BaseObject;
     19 use cms\model\Folder;
     20 use cms\model\Link;
     21 use cms\model\Page;
     22 use cms\model\Project;
     23 
     24 
     25 /**
     26  * Erstellen einer Teaser-Liste.
     27  *
     28  * @author Jan Dankert
     29  */
     30 class LastChanges extends Macro
     31 {
     32 	var $title_html_tag        = 'h3';
     33 	var $css_class             = 'macro-lastchanges';
     34 	var $teaserElementId       = '';
     35 	var $teaserMaxLength       = 100;
     36 	var $plaintext             = 'true';
     37 	var $linktitle             = 'true';
     38 	var $linktext              = 'true';
     39 	var $timeelementid         = 0;
     40 	var $folderid              = 0;
     41 	var $showPages             = true;
     42 	var $showLinks             = false;
     43 	var $includeTemplateIds    = array();
     44 	var $excludeTemplateIds    = array();
     45 	var $limit                 = -1;
     46 	
     47 	/**
     48 	 * Bitte immer eine Beschreibung benutzen, dies ist fuer den Web-Developer hilfreich.
     49 	 * @type String
     50 	 */
     51 	var $description = 'Creates a teaser list of pages in a folder';
     52 
     53 	// 
     54 	function execute()
     55 	{
     56 		if	( $this->folderid === 'self' )
     57 		{
     58 			$page = $this->getPage();
     59 			$page->load();
     60 			$folderid = $page->parentid;
     61 			$f = new Folder( $folderid );
     62 			$changes = $f->getLastChanges();
     63 		}
     64 		elseif	( $this->folderid > 0 )
     65 		{
     66 			$f = new Folder( $this->folderid );
     67 			$changes = $f->getLastChanges();
     68 		}
     69 		else
     70         {
     71             $project = new Project( $this->page->projectid );
     72             $changes = $project->getLastChanges();
     73         }
     74 
     75 				
     76 		$count = 0;
     77 		
     78 		foreach( $changes as $o )
     79 		{
     80 			if ($o['objectid'] == $this->getObjectId() )
     81 				continue;
     82 			
     83 			if	( ($o['typeid']==BaseObject::TYPEID_PAGE && istrue($this->showPages)) ||
     84 				  ($o['typeid']==BaseObject::TYPEID_LINK && istrue($this->showLinks))  ) // Nur wenn gewünschter Typ
     85 			{
     86 				if	( $o['typeid']==BaseObject::TYPEID_LINK ) {
     87 					$l = new Link( $o['objectid'] );
     88 					$l->load();
     89 
     90 					$p = new Page( $l->linkedObjectId );
     91 				}
     92 				elseif ( $o['typeid']==BaseObject::TYPEID_PAGE )
     93 				{
     94 					$p = new Page( $o['objectid'] );
     95 				}
     96 				else
     97 					continue;
     98 				
     99 				$p->load();
    100 
    101 				// Template zulässig?
    102 				if	( !empty($this->includeTemplateIds) )
    103 					if	( !in_array($p->templateid,$this->includeTemplateIds))
    104 						continue;
    105 				
    106 				// Template zulässig?
    107 				if	( !empty($this->excludeTemplateIds) )
    108 					if	( in_array($p->templateid,$this->excludeTemplateIds))
    109 						continue;
    110 				
    111 				$count++;
    112 				if	( $this->limit >= 0 && $count > $this->limit)
    113 					break; // Maximale Anzahl erreicht.
    114 				
    115 				$desc = $p->desc;
    116 				$p->generate_elements();
    117 				
    118 				if	( !empty($this->teaserElementId) )
    119 				{
    120 					$value = $p->values[$this->teaserElementId];
    121 					$desc = $value->value;
    122 					if	( istrue($this->plaintext)  )
    123 					{
    124 						$desc = strip_tags($desc);
    125 						// Und nur wenn die Tags raus sind duerfen wir nun den Text kuerzen.
    126 						// (sonst drohen offene Tags)
    127 						if	( is_numeric($this->teaserMaxLength) && $this->teaserMaxLength > 0 )
    128 							$desc = Text::maxLength($desc,$this->teaserMaxLength);
    129 					}
    130 				}
    131 
    132 				$time = '';
    133 				if	( !empty($this->timeelementid) )
    134 				{
    135 					$value = $p->values[$this->timeelementid];
    136 					$time = $value->value;
    137 				}
    138 
    139 				$this->output('<div class="'.$this->css_class.'">');
    140 				
    141 				if	( istrue($this->linktitle) )
    142 				{
    143 					$url = $this->pathToObject($o['objectid']);
    144 					$this->output( '<a href="'.$url.'"><div>' );
    145 				}
    146 				
    147 				$this->output('<h6>'.$time.'</h6>');
    148 				
    149 				
    150 				$this->output( '<h3>');
    151 				$this->output( $p->name );
    152 				$this->output( '</h3>' );
    153 					
    154 				$this->output( '<p>' );
    155 				$this->output( $desc );
    156 				$this->output( '</p>'   );
    157 				
    158 				if	( istrue($this->linktitle) )
    159 				{
    160 					$this->output( '</div></a>' );
    161 				}
    162 						
    163 				$this->output( '</div>' );
    164 			}
    165 		}
    166 	}
    167 }