LinkAction.class.php (4522B)
1 <?php 2 3 namespace cms\action; 4 5 use cms\model\BaseObject; 6 use cms\model\Folder; 7 use cms\model\Link; 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 LinkAction extends ObjectAction 38 { 39 public $security = Action::SECURITY_USER; 40 41 /** 42 * @var Link 43 */ 44 private $link; 45 46 /** 47 * Konstruktor 48 */ 49 function __construct() 50 { 51 parent::__construct(); 52 53 } 54 55 56 public function init() 57 { 58 $link = new Link( $this->getRequestId() ); 59 $link->load(); 60 61 $this->setBaseObject( $link ); 62 } 63 64 65 protected function setBaseObject( $link ) { 66 67 $this->link = $link; 68 69 parent::setBaseObject( $link ); 70 } 71 72 73 74 /** 75 * Abspeichern der Eigenschaften 76 */ 77 function editPost() 78 { 79 $this->link->linkedObjectId = $this->getRequestVar('targetobjectid'); 80 $this->link->save(); 81 82 $this->addNotice('link',$this->link->name,'SAVED',OR_NOTICE_OK); 83 } 84 85 86 87 public function editView() 88 { 89 $this->setTemplateVars( $this->link->getProperties() ); 90 91 // Typ der Verknuepfung 92 $this->setTemplateVar('type' ,$this->link->getType() ); 93 $this->setTemplateVar('targetobjectid' ,$this->link->linkedObjectId); 94 $this->setTemplateVar('targetobjectname',$this->link->name ); 95 } 96 97 98 99 100 101 /** 102 * Liefert die Struktur zu diesem Ordner: 103 * - Mit den übergeordneten Ordnern und 104 * - den in diesem Ordner enthaltenen Objekten 105 * 106 * Beispiel: 107 * <pre> 108 * - A 109 * - B 110 * - C (dieser Ordner) 111 * - Unterordner 112 * - Seite 113 * - Seite 114 * - Datei 115 * </pre> 116 */ 117 public function structureView() 118 { 119 120 $structure = array(); 121 $tmp = &$structure; 122 $nr = 0; 123 124 $folder = new Folder( $this->link->parentid ); 125 $parents = $folder->parentObjectNames(false,true); 126 127 foreach( $parents as $id=>$name) 128 { 129 unset($children); 130 unset($o); 131 $children = array(); 132 $o = array('id'=>$id,'name'=>$name,'type'=>'folder','level'=>++$nr,'children'=>&$children); 133 134 $tmp[$id] = &$o;; 135 136 unset($tmp); 137 138 $tmp = &$children; 139 } 140 141 142 143 unset($children); 144 unset($id); 145 unset($name); 146 147 $elementChildren = array(); 148 149 $tmp[ $this->link->objectid ] = array('id'=>$this->link->objectid,'name'=>$this->link->name,'type'=>'link','self'=>true,'children'=>&$elementChildren); 150 151 // 152 //$elementChildren[$id] = array('id'=>$this->page->objectid.'_'.$id,'name'=>$name,'type'=>'pageelement','children'=>array() ); 153 154 //Html::debug($structure); 155 156 $this->setTemplateVar('outline',$structure); 157 } 158 159 public function removeView() 160 { 161 $this->setTemplateVar( 'name',$this->link->filename ); 162 } 163 164 165 public function removePost() 166 { 167 if ($this->getRequestVar('delete') != '') { 168 $this->link->delete(); 169 $this->addNotice('link', $this->link->filename, 'DELETED', OR_NOTICE_OK); 170 } else { 171 $this->addNotice('link', $this->link->filename, 'CANCELED', OR_NOTICE_WARN); 172 } 173 } 174 175 176 public function showView() 177 { 178 header('Content-Type: text/html' ); 179 180 header('X-Link-Id: ' .$this->link->linkid ); 181 header('X-Id: ' .$this->link->id ); 182 header('Content-Description: '.$this->link->filename() ); 183 184 echo '<html><body>'; 185 echo '<h1>'.$this->link->filename.'</h1>'; 186 echo '<hr />'; 187 188 try { 189 $o = new BaseObject( $this->link->linkedObjectId ); 190 $o->load(); 191 echo '<a href="'.Html::url($o->getType(),'show',$o->objectid).'">'.$o->filename.'</a>'; 192 } 193 catch( \ObjectNotFoundException $e ) { 194 echo '-'; 195 } 196 197 echo '</body></html>'; 198 199 exit; 200 } 201 202 }