openrat-cms

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

UrlAction.class.php (4658B)


      1 <?php
      2 
      3 namespace cms\action;
      4 
      5 use cms\model\BaseObject;
      6 use cms\model\Folder;
      7 use cms\model\Url;
      8 
      9 
     10 use Html;
     11 use Session;
     12 
     13 // OpenRat Content Management System
     14 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de
     15 //
     16 // This program is free software; you can redistribute it and/or
     17 // modify it under the terms of the GNU General Public License
     18 // as published by the Free Software Foundation; either version 2
     19 // of the License, or (at your option) any later version.
     20 //
     21 // This program is distributed in the hope that it will be useful,
     22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 // GNU General Public License for more details.
     25 //
     26 // You should have received a copy of the GNU General Public License
     27 // along with this program; if not, write to the Free Software
     28 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     29 
     30 
     31 /**
     32  * Action-Klasse f?r Verkn?pfungen
     33  * @version $Id$
     34  * @author $Author$
     35  * @package openrat.actions
     36  */
     37 class UrlAction extends ObjectAction
     38 {
     39 	public $security = Action::SECURITY_USER;
     40 
     41     /**
     42      * @var Url
     43      */
     44 	private $url;
     45 
     46 	/**
     47 	 * Konstruktor
     48 	 */
     49 	function __construct()
     50 	{
     51         parent::__construct();
     52 
     53     }
     54 
     55 
     56     public function init()
     57     {
     58 		$url = new Url( $this->getRequestId() );
     59 		$url->load();
     60 
     61 		$this->setBaseObject( $url );
     62     }
     63 
     64 	protected function setBaseObject( $url ) {
     65 
     66 		$this->url = $url;
     67 
     68 		parent::setBaseObject( $url );
     69 	}
     70 
     71 
     72 	function remove()
     73 	{
     74 		$this->setTemplateVars( $this->url->getProperties() );
     75 	}
     76 	
     77 
     78 
     79 	function delete()
     80 	{
     81 		if	( $this->hasRequestVar("delete") )
     82 		{
     83 			$this->url->delete();
     84 			$this->addNotice('url',$this->url->name,'DELETED');
     85 		}
     86 	}
     87 
     88 
     89 
     90     public function removeView()
     91     {
     92         $this->setTemplateVar( 'name',$this->url->filename );
     93     }
     94 
     95 
     96     public function removePost()
     97     {
     98         if   ( $this->getRequestVar('delete') != '' )
     99         {
    100             $this->url->delete();
    101             $this->addNotice('url',$this->url->filename,'DELETED',OR_NOTICE_OK);
    102         }
    103         else
    104         {
    105             $this->addNotice('url',$this->url->filename,'CANCELED',OR_NOTICE_WARN);
    106         }
    107     }
    108 
    109 
    110 	/**
    111 	 * Abspeichern der Eigenschaften
    112 	 */
    113 	function editPost()
    114 	{
    115         $this->url->url            = $this->getRequestVar('url');
    116         $this->url->save();
    117         $this->url->setTimestamp();
    118 
    119         $this->addNotice('url',$this->url->name,'SAVED',OR_NOTICE_OK);
    120 	}
    121 
    122 
    123 
    124 	public function editView()
    125 	{
    126 		$this->setTemplateVars( $this->url->getProperties() );
    127 
    128 		// Typ der Verknuepfung
    129 		$this->setTemplateVar('type'            ,$this->url->getType()     );
    130 		$this->setTemplateVar('url'             ,$this->url->url           );
    131 	}
    132 
    133 
    134 	
    135 	
    136 	/**
    137 	 * Liefert die Struktur zu diesem Ordner:
    138 	 * - Mit den übergeordneten Ordnern und
    139 	 * - den in diesem Ordner enthaltenen Objekten
    140 	 * 
    141 	 * Beispiel:
    142 	 * <pre>
    143 	 * - A
    144 	 *   - B
    145 	 *     - C (dieser Ordner)
    146 	 *       - Unterordner
    147 	 *       - Seite
    148 	 *       - Seite
    149 	 *       - Datei
    150 	 * </pre> 
    151 	 */
    152 	public function structureView()
    153 	{
    154 
    155 		$structure = array();
    156 		$tmp = &$structure;
    157 		$nr  = 0;
    158 		
    159 		$folder = new Folder( $this->url->parentid );
    160 		$parents = $folder->parentObjectNames(false,true);
    161 		
    162 		foreach( $parents as $id=>$name)
    163 		{
    164 			unset($children);
    165 			unset($o);
    166 			$children = array();
    167 			$o = array('id'=>$id,'name'=>$name,'type'=>'folder','level'=>++$nr,'children'=>&$children);
    168 			
    169 			$tmp[$id] = &$o;;
    170 			
    171 			unset($tmp);
    172 			
    173 			$tmp = &$children; 
    174 		}
    175 		
    176 		
    177 		
    178 		unset($children);
    179 		unset($id);
    180 		unset($name);
    181 		
    182 		$elementChildren = array();
    183 		
    184 		$tmp[ $this->url->objectid ] = array('id'=>$this->url->objectid,'name'=>$this->url->name,'type'=>'url','self'=>true,'children'=>&$elementChildren);
    185 		
    186 		// 
    187 		//$elementChildren[$id] = array('id'=>$this->page->objectid.'_'.$id,'name'=>$name,'type'=>'pageelement','children'=>array() );
    188 		
    189 		//Html::debug($structure);
    190 		
    191 		$this->setTemplateVar('outline',$structure);
    192 	}
    193 
    194 
    195 	public function showView()
    196     {
    197         // Angabe Content-Type
    198         header('Content-Type: text/html' );
    199 
    200         header('X-Url-Id: '   .$this->url->urlid );
    201         header('X-Id: '       .$this->url->id    );
    202         header('Content-Description: '.$this->url->filename() );
    203 
    204         echo '<html><body>';
    205         echo '<h1>'.$this->url->filename.'</h1>';
    206         echo '<hr />';
    207         echo '<a href="'.$this->url->url.'">'.$this->url->url.'</a>';
    208         echo '</body></html>';
    209 
    210         exit;
    211 
    212     }
    213 
    214 
    215 
    216     /**
    217      * Vorschau anzeigen
    218      */
    219     function previewView()
    220     {
    221         $this->setTemplateVar('preview_url',$this->url->url );
    222     }
    223 
    224 
    225 }