FolderAction.class.php (38494B)
1 <?php 2 3 namespace cms\action; 4 5 use ArchiveTar; 6 use cms\model\Acl; 7 use cms\model\Image; 8 use cms\model\Language; 9 use cms\model\Project; 10 use cms\model\Template; 11 use cms\model\Page; 12 use cms\model\Folder; 13 use cms\model\BaseObject; 14 use cms\model\File; 15 use cms\model\Link; 16 17 use cms\model\Text; 18 use cms\model\Url; 19 use cms\publish\PublishPublic; 20 use Http; 21 use Publish; 22 use Session; 23 use \Html; 24 use Upload; 25 26 /** 27 * Action-Klasse zum Bearbeiten eines Ordners. 28 * 29 * @author Jan Dankert 30 */ 31 32 class FolderAction extends ObjectAction 33 { 34 public $security = Action::SECURITY_USER; 35 36 /** 37 * @var Folder 38 */ 39 private $folder; 40 41 public function __construct() 42 { 43 parent::__construct(); 44 } 45 46 47 public function init() 48 { 49 $folder = new Folder( $this->getRequestId() ); 50 $folder->languageid = $this->request->getLanguageId(); 51 $folder->load(); 52 53 $this->lastModified( $folder->lastchangeDate); 54 55 $this->setBaseObject($folder); 56 } 57 58 59 protected function setBaseObject($folder ) { 60 61 $this->folder = $folder; 62 63 parent::setBaseObject( $folder ); 64 } 65 66 67 public function createfolderPost() 68 { 69 $name = $this->getRequestVar('name' ); 70 $description = $this->getRequestVar('description'); 71 72 if ( !empty($name) ) 73 { 74 $f = new Folder(); 75 $f->projectid = $this->folder->projectid; 76 $f->languageid = $this->folder->languageid; 77 $f->name = $name; 78 $f->filename = BaseObject::urlify( $name ); 79 $f->desc = $description; 80 $f->parentid = $this->folder->objectid; 81 82 $f->add(); 83 $f->setNameForAllLanguages( $name,$description ); 84 85 $this->addNotice('folder',$f->name,'ADDED','ok'); 86 87 // Die neue Folder-Id (wichtig für API-Aufrufe). 88 $this->setTemplateVar('objectid',$f->objectid); 89 90 $this->folder->setTimestamp(); // Zeitstempel setzen. 91 } 92 else 93 { 94 $this->addValidationError('name'); 95 } 96 97 } 98 99 100 101 public function createfilePost() 102 { 103 $type = $this->getRequestVar('type' ); 104 $name = $this->getRequestVar('name' ); 105 $filename = $this->getRequestVar('filename' ); 106 $description = $this->getRequestVar('description'); 107 108 $file = new File(); 109 110 // Die neue Datei wird über eine URL geladen und dann im CMS gespeichert. 111 if ( $this->hasRequestVar('url') ) 112 { 113 $url = $this->getRequestVar('url'); 114 $http = new Http(); 115 $http->setUrl( $url ); 116 117 $ok = $http->request(); 118 119 if ( !$ok ) 120 { 121 $this->addValidationError('url','COMMON_VALIDATION_ERROR',array(),$http->error); 122 $this->callSubAction('createfile'); 123 return; 124 } 125 126 $file->desc = $description; 127 $file->filename = BaseObject::urlify( $name ); 128 $file->name = !empty($name)?$name:basename($url); 129 $file->size = strlen($http->body); 130 $file->value = $http->body; 131 $file->parentid = $this->folder->objectid; 132 $file->projectid = $this->folder->projectid; 133 } 134 elseif ( $this->hasRequestVar('value') ) 135 { 136 // New file is inserted. 137 $file->filename = BaseObject::urlify( $filename ); 138 $file->value = $this->getRequestVar('value'); 139 $file->size = strlen($file->value); 140 $file->parentid = $this->folder->objectid; 141 $file->projectid = $this->folder->projectid; 142 } 143 else 144 { 145 // File was uploaded. 146 $upload = new Upload('file'); 147 148 try 149 { 150 $upload->processUpload(); 151 } 152 catch( \Exception $e ) 153 { 154 // technical error. 155 throw new \RuntimeException('Exception while processing the upload: '.$e->getMessage(), 0, $e); 156 157 //throw new \ValidationException( $upload->parameterName ); 158 } 159 160 $file->desc = $description; 161 $file->filename = BaseObject::urlify( $upload->filename ); 162 $file->name = !empty($name)?$name:$upload->filename; 163 $file->extension = $upload->extension; 164 $file->size = $upload->size; 165 $file->parentid = $this->folder->objectid; 166 $file->projectid = $this->folder->projectid; 167 168 $file->value = $upload->value; 169 } 170 171 $file->add(); // Datei hinzufuegen 172 $file->setNameForAllLanguages( $name,$description ); 173 174 $this->addNotice('file',$file->filename,'ADDED','ok'); 175 $this->setTemplateVar('objectid',$file->objectid); 176 177 $this->folder->setTimestamp(); 178 } 179 180 181 182 public function createimagePost() 183 { 184 $type = $this->getRequestVar('type' ); 185 $name = $this->getRequestVar('name' ); 186 $filename = $this->getRequestVar('filename' ); 187 $description = $this->getRequestVar('description'); 188 189 $image = new Image(); 190 191 // Die neue Datei wird über eine URL geladen und dann im CMS gespeichert. 192 if ( $this->hasRequestVar('url') ) 193 { 194 $url = $this->getRequestVar('url'); 195 $http = new Http(); 196 $http->setUrl( $url ); 197 198 $ok = $http->request(); 199 200 if ( !$ok ) 201 { 202 $this->addValidationError('url','COMMON_VALIDATION_ERROR',array(),$http->error); 203 $this->callSubAction('createfile'); 204 return; 205 } 206 207 $image->desc = $description; 208 $image->filename = BaseObject::urlify( basename($url) ); 209 $image->name = !empty($name)?$name:basename($url); 210 $image->size = strlen($http->body); 211 $image->value = $http->body; 212 $image->parentid = $this->folder->objectid; 213 } 214 else 215 { 216 $upload = new Upload(); 217 218 try 219 { 220 $upload->processUpload(); 221 } 222 catch( \Exception $e ) 223 { 224 // technical error. 225 throw new \RuntimeException('Exception while processing the upload: '.$e->getMessage(), 0, $e); 226 227 //throw new \ValidationException( $upload->parameterName ); 228 } 229 230 $image->desc = $description; 231 $image->filename = BaseObject::urlify( $upload->filename ); 232 $image->name = !empty($name)?$name:$upload->filename; 233 $image->extension = $upload->extension; 234 $image->size = $upload->size; 235 $image->parentid = $this->folder->objectid; 236 $image->projectid = $this->folder->projectid; 237 238 $image->value = $upload->value; 239 } 240 241 $image->add(); // Datei hinzufuegen 242 $this->addNotice('file',$image->name,'ADDED','ok'); 243 $image->setNameForAllLanguages( $name,$description ); 244 $this->setTemplateVar('objectid',$image->objectid); 245 246 $this->folder->setTimestamp(); 247 } 248 249 250 251 public function createtextPost() 252 { 253 $name = $this->getRequestVar('name' ); 254 $description = $this->getRequestVar('description'); 255 256 $text = new Text(); 257 258 // Die neue Datei wird über eine URL geladen und dann im CMS gespeichert. 259 if ( $this->hasRequestVar('url') ) 260 { 261 $url = $this->getRequestVar('url'); 262 $http = new Http(); 263 $http->setUrl( $url ); 264 265 $ok = $http->request(); 266 267 if ( !$ok ) 268 { 269 $this->addValidationError('url','COMMON_VALIDATION_ERROR',array(),$http->error); 270 $this->callSubAction('createfile'); 271 return; 272 } 273 274 $text->desc = $description; 275 $text->filename = BaseObject::urlify( basename($url) ); 276 $text->name = !empty($name)?$name:basename($url); 277 $text->size = strlen($http->body); 278 $text->value = $http->body; 279 $text->parentid = $this->folder->objectid; 280 $text->projectid = $this->folder->projectid; 281 } 282 else 283 { 284 $upload = new Upload(); 285 286 try 287 { 288 $upload->processUpload(); 289 } 290 catch( \Exception $e ) 291 { 292 throw $e; 293 } 294 295 $text->desc = $description; 296 $text->filename = BaseObject::urlify( $upload->filename ); 297 $text->name = !empty($name)?$name:$upload->filename; 298 $text->extension = $upload->extension; 299 $text->size = $upload->size; 300 $text->parentid = $this->folder->objectid; 301 $text->projectid = $this->folder->projectid; 302 303 $text->value = $upload->value; 304 } 305 306 $text->add(); // Datei hinzufuegen 307 $text->setNameForAllLanguages( $name,$description ); 308 $this->addNotice('file',$text->name,'ADDED','ok'); 309 $this->setTemplateVar('objectid',$text->objectid); 310 311 $this->folder->setTimestamp(); 312 } 313 314 315 316 public function createlinkPost() 317 { 318 $name = $this->getRequestVar('name' ); 319 $description = $this->getRequestVar('description'); 320 321 if ( !empty($name) ) 322 { 323 $link = new Link(); 324 $link->filename = BaseObject::urlify( $name ); 325 $link->parentid = $this->folder->objectid; 326 327 $link->linkedObjectId = $this->getRequestVar('targetobjectid'); 328 $link->projectid = $this->folder->projectid; 329 330 $link->add(); 331 $link->setNameForAllLanguages( $name,$description ); 332 333 $this->addNotice('link',$link->name,'ADDED','ok'); 334 $this->setTemplateVar('objectid',$link->objectid); 335 } 336 else 337 { 338 $this->addValidationError('name'); 339 $this->callSubAction('createlink'); 340 return; 341 } 342 343 $this->folder->setTimestamp(); 344 } 345 346 public function createurlPost() 347 { 348 $name = $this->getRequestVar('name' ); 349 $description = $this->getRequestVar('description'); 350 $filename = $this->getRequestVar('filename' ); 351 352 if ( !empty($name) ) 353 { 354 $url = new Url(); 355 $url->filename = BaseObject::urlify( $name ); 356 $url->parentid = $this->folder->objectid; 357 $url->projectid = $this->folder->projectid; 358 359 $url->url = $this->getRequestVar('url'); 360 361 $url->add(); 362 $url->setNameForAllLanguages( $name,$description ); 363 364 $this->addNotice('url',$url->name,'ADDED','ok'); 365 $this->setTemplateVar('objectid',$url->objectid); 366 } 367 else 368 { 369 $this->addValidationError('name'); 370 $this->callSubAction('createurl'); 371 return; 372 } 373 374 $this->folder->setTimestamp(); 375 } 376 377 378 379 public function createpagePost() 380 { 381 $type = $this->getRequestVar('type' ); 382 $name = $this->getRequestVar('name' ); 383 $filename = $this->getRequestVar('filename' ); 384 $description = $this->getRequestVar('description'); 385 386 if ( $this->getRequestVar('name') != '' ) 387 { 388 $page = new Page(); 389 $page->name = $name; 390 $page->desc = $description; 391 $page->filename = BaseObject::urlify( $name ); 392 $page->templateid = $this->getRequestVar('templateid'); 393 $page->parentid = $this->folder->objectid; 394 $page->projectid = $this->folder->projectid; 395 396 397 $page->add(); 398 $page->setNameForAllLanguages( $name,$description ); 399 400 $this->addNotice('page',$page->name,'ADDED','ok'); 401 $this->setTemplateVar('objectid',$page->objectid); 402 } 403 else 404 { 405 $this->addValidationError('name'); 406 $this->callSubAction('createpage'); 407 return; 408 } 409 410 $this->folder->setTimestamp(); 411 } 412 413 414 415 /** 416 * Reihenfolge von Objekten aendern. 417 */ 418 public function orderPost() 419 { 420 $ids = $this->folder->getObjectIds(); 421 $seq = 0; 422 423 $order = explode(',',$this->getRequestVar('order') ); 424 425 foreach( $order as $objectid ) 426 { 427 if ( ! is_numeric($objectid) || ! in_array($objectid,$ids) ) 428 { 429 throw new \LogicException('Object-Id '.$objectid.' is not in this folder any more'); 430 } 431 $seq++; // Sequenz um 1 erhoehen 432 433 $o = new BaseObject( $objectid ); 434 $o->setOrderId( $seq ); 435 436 unset( $o ); // Selfmade Garbage Collection :-) 437 } 438 439 $this->addNotice($this->folder->getType(),$this->folder->name,'SEQUENCE_CHANGED','ok'); 440 $this->folder->setTimestamp(); 441 } 442 443 444 private function OLD__________editPost() 445 { 446 $type = $this->getRequestVar('type'); // Typ der Aktion, z.B "copy" oder "move" 447 448 switch( $type ) 449 { 450 case 'move': 451 case 'copy': 452 case 'link': 453 // Liste von m�glichen Zielordnern anzeigen 454 455 $otherfolder = array(); 456 foreach( $this->folder->getAllFolders() as $id ) 457 { 458 $f = new Folder( $id ); 459 460 // Beim Verkn�pfen muss im Zielordner die Berechtigung zum Erstellen 461 // von Verkn�pfungen vorhanden sein. 462 // 463 // Beim Verschieben und Kopieren muss im Zielordner die Berechtigung 464 // zum Erstellen von Ordner, Dateien oder Seiten vorhanden sein. 465 if ( ( $type=='link' && $f->hasRight( Acl::ACL_CREATE_LINK ) ) || 466 ( ( $type=='move' || $type == 'copy' ) && 467 ( $f->hasRight(Acl::ACL_CREATE_FOLDER) || $f->hasRight(Acl::ACL_CREATE_FILE) || $f->hasRight(Acl::ACL_CREATE_PAGE) ) ) ) 468 // Zielordner hinzuf�gen 469 $otherfolder[$id] = FILE_SEP.implode( FILE_SEP,$f->parentObjectNames(false,true) ); 470 } 471 472 // Zielordner-Liste alphabetisch sortieren 473 asort( $otherfolder ); 474 475 $this->setTemplateVar('folder',$otherfolder); 476 477 break; 478 479 case 'archive': 480 $this->setTemplateVar('ask_filename',''); 481 break; 482 483 case 'delete': 484 $this->setTemplateVar('ask_commit',''); 485 break; 486 487 default: 488 $this->addValidationError('type'); 489 return; 490 491 } // switch 492 493 $ids = $this->folder->getObjectIds(); 494 $objectList = array(); 495 496 foreach( $ids as $id ) 497 { 498 // Nur, wenn Objekt ausgewaehlt wurde 499 if ( !$this->hasRequestVar('obj'.$id) ) 500 continue; 501 502 $o = new BaseObject( $id ); 503 $o->load(); 504 505 // F�r die gew�nschte Aktion m�ssen pro Objekt die entsprechenden Rechte 506 // vorhanden sein. 507 if ( $type == 'copy' && $o->hasRight( Acl::ACL_READ ) || 508 $type == 'move' && $o->hasRight( Acl::ACL_DELETE ) || 509 $type == 'link' && $o->hasRight( Acl::ACL_READ ) || 510 $type == 'archive' && $o->hasRight( Acl::ACL_READ ) || 511 $type == 'delete' && $o->hasRight( Acl::ACL_DELETE ) ) 512 $objectList[ $id ] = $o->getProperties(); 513 } 514 515 $this->setTemplateVar('type' ,$type ); 516 $this->setTemplateVar('objectlist',$objectList ); 517 518 // Komma-separierte Liste von ausgew�hlten Objekt-Ids erzeugen 519 $this->setTemplateVar('ids',join(array_keys($objectList),',') ); 520 } 521 522 523 524 /** 525 * Verschieben/Kopieren/Loeschen/Verknuepfen von mehreren Dateien in diesem Ordner 526 */ 527 public function advancedPost() 528 { 529 $type = $this->getRequestVar('type'); 530 $ids = explode(',',$this->getRequestVar('ids')); 531 $targetObjectId = $this->getRequestVar('targetobjectid'); 532 533 // Prüfen, ob Schreibrechte im Zielordner bestehen. 534 switch( $type ) 535 { 536 case 'move': 537 case 'copy': 538 case 'link': 539 $f = new Folder( $targetObjectId ); 540 541 // Beim Verkn�pfen muss im Zielordner die Berechtigung zum Erstellen 542 // von Verkn�pfungen vorhanden sein. 543 // 544 // Beim Verschieben und Kopieren muss im Zielordner die Berechtigung 545 // zum Erstellen von Ordner, Dateien oder Seiten vorhanden sein. 546 if ( ( $type=='link' && $f->hasRight( Acl::ACL_CREATE_LINK ) ) || 547 ( ( $type=='move' || $type == 'copy' ) && 548 ( $f->hasRight(Acl::ACL_CREATE_FOLDER) || $f->hasRight(Acl::ACL_CREATE_FILE) || $f->hasRight(Acl::ACL_CREATE_PAGE) ) ) ) 549 { 550 // OK 551 } 552 else 553 { 554 $this->addValidationError('targetobjectid','no_rights'); 555 return; 556 } 557 558 break; 559 default: 560 } 561 562 563 $ids = $this->folder->getObjectIds(); 564 $objectList = array(); 565 566 foreach( $ids as $id ) 567 { 568 // Nur, wenn Objekt ausgewaehlt wurde 569 if ( !$this->hasRequestVar('obj'.$id) ) 570 continue; 571 572 $o = new BaseObject( $id ); 573 $o->load(); 574 575 // Fuer die gewuenschte Aktion muessen pro Objekt die entsprechenden Rechte 576 // vorhanden sein. 577 if ( $type == 'copy' && $o->hasRight( Acl::ACL_READ ) || 578 $type == 'move' && $o->hasRight( Acl::ACL_WRITE ) || 579 $type == 'link' && $o->hasRight( Acl::ACL_READ ) || 580 $type == 'archive' && $o->hasRight( Acl::ACL_READ ) || 581 $type == 'delete' && $o->hasRight( Acl::ACL_DELETE ) ) 582 $objectList[ $id ] = $o->getProperties(); 583 else 584 $this->addNotice($o->getType(),$o->name,'no_rights',OR_NOTICE_WARN); 585 } 586 587 $ids = array_keys($objectList); 588 589 if ( $type == 'archive' ) 590 { 591 require_once('serviceClasses/ArchiveTar.class.php'); 592 $tar = new ArchiveTar(); 593 $tar->files = array(); 594 595 foreach( $ids as $id ) 596 { 597 $o = new BaseObject( $id ); 598 $o->load(); 599 600 if ( $o->isFile ) 601 { 602 $file = new File($id); 603 $file->load(); 604 605 // Datei dem Archiv hinzufügen. 606 $info = array(); 607 $info['name'] = $file->filename(); 608 $info['file'] = $file->loadValue(); 609 $info['mode'] = 0600; 610 $info['size'] = $file->size; 611 $info['time'] = $file->lastchangeDate; 612 $info['user_id' ] = 1000; 613 $info['group_id'] = 1000; 614 $info['user_name' ] = 'nobody'; 615 $info['group_name'] = 'nobody'; 616 617 $tar->numFiles++; 618 $tar->files[]= $info; 619 } 620 else 621 { 622 // Was anderes als Dateien ignorieren. 623 $this->addNotice($o->getType(),$o->name,'NOTHING_DONE',OR_NOTICE_WARN); 624 } 625 626 } 627 628 // TAR speichern. 629 $tarFile = new File(); 630 $tarFile->name = lang('GLOBAL_ARCHIVE').' '.$this->getRequestVar('filename'); 631 $tarFile->filename = $this->getRequestVar('filename'); 632 $tarFile->extension = 'tar'; 633 $tarFile->parentid = $this->folder->objectid; 634 635 $tar->__generateTAR(); 636 $tarFile->value = $tar->tar_file; 637 $tarFile->add(); 638 } 639 else 640 { 641 foreach( $ids as $id ) 642 { 643 $o = new BaseObject( $id ); 644 $o->load(); 645 646 switch( $type ) 647 { 648 case 'move': 649 if ( $o->isFolder ) 650 { 651 $f = new Folder( $id ); 652 $allsubfolders = $f->getAllSubFolderIds(); 653 654 // Plausibilisierungsprüfung: 655 // 656 // Wenn 657 // - Das Zielverzeichnis sich nicht in einem Unterverzeichnis des zu verschiebenen Ordners liegt 658 // und 659 // - Das Zielverzeichnis nicht der zu verschiebene Ordner ist 660 // dann verschieben 661 if ( !in_array($targetObjectId,$allsubfolders) && $id != $targetObjectId ) 662 { 663 $this->addNotice($o->getType(),$o->name,'MOVED','ok'); 664 $o->setParentId( $targetObjectId ); 665 } 666 else 667 { 668 $this->addNotice($o->getType(),$o->name,'ERROR','error'); 669 } 670 } 671 else 672 { 673 $o->setParentId( $targetObjectId ); 674 $this->addNotice($o->getType(),$o->name,'MOVED','ok'); 675 } 676 break; 677 678 case 'copy': 679 switch( $o->getType() ) 680 { 681 case 'folder': 682 // Ordner zur Zeit nicht kopieren 683 // Funktion waere zu verwirrend 684 $this->addNotice($o->getType(),$o->name,'CANNOT_COPY_FOLDER','error'); 685 break; 686 687 case 'file': 688 $f = new File( $id ); 689 $f->load(); 690 $f->filename = ''; 691 $f->name = lang('COPY_OF').' '.$f->name; 692 $f->parentid = $targetObjectId; 693 $f->add(); 694 $f->copyValueFromFile( $id ); 695 696 $this->addNotice($o->getType(),$o->name,'COPIED','ok'); 697 break; 698 699 case 'page': 700 $p = new Page( $id ); 701 $p->load(); 702 $p->filename = ''; 703 $p->name = lang('COPY_OF').' '.$p->name; 704 $p->parentid = $targetObjectId; 705 $p->add(); 706 $p->copyValuesFromPage( $id ); 707 $this->addNotice($o->getType(),$o->name,'COPIED','ok'); 708 break; 709 710 case 'link': 711 $l = new Link( $id ); 712 $l->load(); 713 $l->filename = ''; 714 $l->name = lang('COPY_OF').' '.$l->name; 715 $l->parentid = $targetObjectId; 716 $l->add(); 717 $this->addNotice($o->getType(),$o->name,'COPIED','ok'); 718 break; 719 720 default: 721 throw new \LogicException('fatal: what type to delete?'); 722 } 723 $notices[] = lang('COPIED'); 724 break; 725 726 case 'link': 727 728 if ( $o->isFile || 729 $o->isImage || 730 $o->isText || 731 $o->isPage ) // Nur Seiten oder Dateien sind verknuepfbar 732 { 733 $link = new Link(); 734 $link->parentid = $targetObjectId; 735 736 $link->linkedObjectId = $id; 737 $link->isLinkToObject = true; 738 $link->name = lang('LINK_TO').' '.$o->name; 739 $link->add(); 740 $this->addNotice($o->getType(),$o->name,'LINKED','ok'); 741 } 742 else 743 { 744 $this->addNotice($o->getType(),$o->name,'ERROR','error'); 745 } 746 break; 747 748 case 'delete': 749 750 if ( $this->hasRequestVar('confirm') ) 751 { 752 switch( $o->getType() ) 753 { 754 case 'folder': 755 $f = new Folder( $id ); 756 $f->deleteAll(); 757 break; 758 759 case 'file': 760 $f = new File( $id ); 761 $f->delete(); 762 break; 763 764 case 'page': 765 $p = new Page( $id ); 766 $p->load(); 767 $p->delete(); 768 break; 769 770 case 'link': 771 $l = new Link( $id ); 772 $l->delete(); 773 break; 774 775 case 'url': 776 $u = new Url( $id ); 777 $u->delete(); 778 break; 779 780 default: 781 throw new \LogicException("Error while deleting: Unknown type: {$o->getType()}"); 782 } 783 $this->addNotice($o->getType(),$o->name,'DELETED',OR_NOTICE_OK); 784 } 785 else 786 { 787 $this->addNotice($o->getType(),$o->name,'NOTHING_DONE',OR_NOTICE_WARN); 788 } 789 790 break; 791 792 default: 793 $this->addNotice($o->getType(),$o->name,'ERROR','error'); 794 } 795 796 } 797 } 798 799 $this->folder->setTimestamp(); 800 } 801 802 803 804 805 /** 806 * Alias für Methode 'create'. 807 */ 808 public function addView() 809 { 810 $this->nextSubAction('create'); 811 } 812 813 814 /** 815 * Alias für Methode 'create'. 816 */ 817 public function addPost() 818 { 819 $this->nextSubAction('create'); 820 } 821 822 823 public function createView() 824 { 825 $this->setTemplateVar('mayCreateFolder',$this->folder->hasRight( Acl::ACL_CREATE_FOLDER ) ); 826 $this->setTemplateVar('mayCreateFile' ,$this->folder->hasRight( Acl::ACL_CREATE_FILE ) ); 827 $this->setTemplateVar('mayCreateText' ,$this->folder->hasRight( Acl::ACL_CREATE_FILE ) ); 828 $this->setTemplateVar('mayCreateImage' ,$this->folder->hasRight( Acl::ACL_CREATE_FILE ) ); 829 $this->setTemplateVar('mayCreatePage' ,$this->folder->hasRight( Acl::ACL_CREATE_PAGE ) ); 830 $this->setTemplateVar('mayCreateUrl' ,$this->folder->hasRight( Acl::ACL_CREATE_LINK ) ); 831 $this->setTemplateVar('mayCreateLink' ,$this->folder->hasRight( Acl::ACL_CREATE_LINK ) ); 832 833 } 834 835 836 837 public function createfolderView() 838 { 839 $this->setTemplateVar('objectid' ,$this->folder->objectid ); 840 $this->setTemplateVar('languageid',$this->folder->languageid ); 841 } 842 843 844 845 /** 846 * Ermittelt die maximale Gr��e einer hochzuladenden Datei.<br> 847 * Der Wert wird aus der PHP- und OpenRat-Konfiguration ermittelt.<br> 848 * 849 * @return Integer maximale Dateigroesse in Bytes 850 */ 851 private function maxFileSize() 852 { 853 global $conf; 854 855 // When querying memory size values: 856 // Many ini memory size values, such as upload_max_filesize, 857 // are stored in the php.ini file in shorthand notation. 858 // ini_get() will return the exact string stored in the php.ini file 859 // and NOT its integer equivalent. 860 $sizes = array(10*1024*1024*1024); // Init with 10GB enough? :) 861 862 foreach( array('upload_max_filesize','post_max_size','memory_limit') as $var ) 863 { 864 $v = $this->stringToBytes(ini_get($var)); 865 866 if ($v > 0 ) 867 $sizes[] = $v; 868 } 869 870 $confMaxSize = intval($conf['content']['file']['max_file_size'])*1024; 871 if ( $confMaxSize > 0 ) 872 $sizes[] = $confMaxSize; 873 874 return min($sizes); 875 } 876 877 878 /** 879 * Hochladen einer Datei. 880 * 881 */ 882 public function createfileView() 883 { 884 // Maximale Dateigroesse. 885 $maxSizeBytes = $this->maxFileSize(); 886 $this->setTemplateVar('max_size' ,($maxSizeBytes/1024).' KB' ); 887 $this->setTemplateVar('maxlength',$maxSizeBytes ); 888 889 $this->setTemplateVar('objectid',$this->folder->objectid ); 890 } 891 892 893 /** 894 * Hochladen einer Datei. 895 * 896 */ 897 public function createimageView() 898 { 899 // Maximale Dateigroesse. 900 $maxSizeBytes = $this->maxFileSize(); 901 $this->setTemplateVar('max_size' ,($maxSizeBytes/1024).' KB' ); 902 $this->setTemplateVar('maxlength',$maxSizeBytes ); 903 904 $this->setTemplateVar('objectid',$this->folder->objectid ); 905 } 906 907 908 /** 909 * Hochladen einer Datei. 910 * 911 */ 912 public function createtextView() 913 { 914 // Maximale Dateigroesse. 915 $maxSizeBytes = $this->maxFileSize(); 916 $this->setTemplateVar('max_size' ,($maxSizeBytes/1024).' KB' ); 917 $this->setTemplateVar('maxlength',$maxSizeBytes ); 918 919 $this->setTemplateVar('objectid',$this->folder->objectid ); 920 } 921 922 923 /** 924 * Umwandlung von abgek�rzten Bytewerten ("Shorthand Notation") wie 925 * "4M" oder "500K" in eine ganzzahlige Byteanzahl.<br> 926 * <br> 927 * Quelle: http://de.php.net/manual/de/function.ini-get.php 928 * 929 * @param String Abgek�rzter Bytewert 930 * @return Integer Byteanzahl 931 */ 932 private function stringToBytes($val) 933 { 934 $val = trim($val); 935 $last = strtolower($val{strlen($val)-1}); 936 $val = intval($val); 937 // Achtung: Der Trick ist das "Fallthrough", kein "break" vorhanden! 938 switch($last) 939 { 940 case 'g': 941 $val *= 1024; 942 case 'm': 943 $val *= 1024; 944 case 'k': 945 $val *= 1024; 946 } 947 948 return intval($val); 949 } 950 951 952 953 public function createlinkView() 954 { 955 $this->setTemplateVar('objectid' ,$this->folder->objectid ); 956 } 957 958 959 public function createurlView() 960 { 961 } 962 963 964 public function createpageView() 965 { 966 $project = new Project( $this->folder->projectid ); 967 968 $all_templates = $project->getTemplates(); 969 $this->setTemplateVar('templates' ,$all_templates ); 970 $this->setTemplateVar('objectid' ,$this->folder->objectid ); 971 972 if ( count($all_templates) == 0 ) 973 $this->addNotice('folder',$this->folder->name,'NO_TEMPLATES_AVAILABLE',OR_NOTICE_WARN); 974 } 975 976 977 /** 978 * Anzeigen des Inhaltes, der Inhalt wird samt Header direkt 979 * auf die Standardausgabe geschrieben 980 */ 981 private function previewViewUnused() 982 { 983 $this->setTemplateVar('preview_url',Html::url('folder','show',$this->folder->objectid,array('target'=>'none') ) ); 984 } 985 986 987 988 /** 989 * Anzeige aller Objekte in diesem Ordner. 990 */ 991 public function editView() 992 { 993 global $conf_php; 994 995 if ( ! $this->folder->isRoot ) 996 $this->setTemplateVar('parentid',$this->folder->parentid); 997 998 $list = array(); 999 1000 // Schleife ueber alle Objekte in diesem Ordner 1001 foreach( $this->folder->getObjects() as $o ) 1002 { 1003 /* @var $o BaseObject */ 1004 1005 $id = $o->objectid; 1006 1007 if ( $o->hasRight(Acl::ACL_READ) ) 1008 { 1009 $list[$id]['name'] = \Text::maxLength($o->name, 30); 1010 $list[$id]['filename'] = \Text::maxLength($o->filename, 20); 1011 $list[$id]['desc'] = \Text::maxLength($o->desc, 30); 1012 if ( $list[$id]['desc'] == '' ) 1013 $list[$id]['desc'] = lang('NO_DESCRIPTION_AVAILABLE'); 1014 $list[$id]['desc'] = $list[$id]['desc'].' - '.lang('IMAGE').' '.$id; 1015 1016 $list[$id]['type'] = $o->getType(); 1017 $list[$id]['id' ] = $id; 1018 1019 $list[$id]['icon' ] = $o->getType(); 1020 $list[$id]['class'] = $o->getType(); 1021 $list[$id]['url' ] = Html::url($o->getType(),'',$id); 1022 1023 if ( $o->getType() == 'file' ) 1024 { 1025 $file = new File( $id ); 1026 $file->load(); 1027 $list[$id]['desc'] .= ' - '.intval($file->size/1000).'kB'; 1028 1029 if ( $file->isImage() ) 1030 { 1031 $list[$id]['icon' ] = 'image'; 1032 $list[$id]['class'] = 'image'; 1033 //$list[$id]['url' ] = Html::url('file','show',$id) nur sinnvoll bei Lightbox-Anzeige 1034 } 1035 // if ( substr($file->mimeType(),0,5) == 'text/' ) 1036 // $list[$id]['icon'] = 'text'; 1037 } 1038 1039 $list[$id]['date'] = $o->lastchangeDate; 1040 $list[$id]['user'] = $o->lastchangeUser; 1041 } 1042 } 1043 1044 $this->setTemplateVar('object' ,$list ); 1045 } 1046 1047 1048 /** 1049 * Anzeige aller Objekte in diesem Ordner. 1050 */ 1051 public function contentView() 1052 { 1053 global $conf_php; 1054 1055 if ( ! $this->folder->isRoot ) 1056 $this->setTemplateVar('up_url',Html::url('folder','show',$this->folder->parentid)); 1057 1058 $this->setTemplateVar('writable',$this->folder->hasRight(Acl::ACL_WRITE) ); 1059 1060 $list = array(); 1061 1062 // Schleife ueber alle Objekte in diesem Ordner 1063 foreach( $this->folder->getObjects() as $o ) 1064 { 1065 /* @var $o BaseObject */ 1066 $id = $o->objectid; 1067 1068 if ( $o->hasRight(Acl::ACL_READ) ) 1069 { 1070 $list[$id]['name'] = \Text::maxLength($o->name, 30); 1071 $list[$id]['filename'] = \Text::maxLength($o->filename, 20); 1072 $list[$id]['desc'] = \Text::maxLength($o->desc, 30); 1073 if ( $list[$id]['desc'] == '' ) 1074 $list[$id]['desc'] = lang('NO_DESCRIPTION_AVAILABLE'); 1075 $list[$id]['desc'] = $list[$id]['desc'].' - '.lang('IMAGE').' '.$id; 1076 1077 $list[$id]['type'] = $o->getType(); 1078 $list[$id]['id' ] = $id; 1079 1080 $list[$id]['icon' ] = $o->getType(); 1081 $list[$id]['class'] = $o->getType(); 1082 $list[$id]['url' ] = Html::url($o->getType(),'',$id); 1083 1084 if ( $o->getType() == 'file' ) 1085 { 1086 $file = new File( $id ); 1087 $file->load(); 1088 $list[$id]['desc'] .= ' - '.intval($file->size/1000).'kB'; 1089 1090 if ( $file->isImage() ) 1091 { 1092 $list[$id]['icon' ] = 'image'; 1093 $list[$id]['class'] = 'image'; 1094 //$list[$id]['url' ] = Html::url('file','show',$id) nur sinnvoll bei Lightbox-Anzeige 1095 } 1096 // if ( substr($file->mimeType(),0,5) == 'text/' ) 1097 // $list[$id]['icon'] = 'text'; 1098 } 1099 1100 $list[$id]['date'] = $o->lastchangeDate; 1101 $list[$id]['user'] = $o->lastchangeUser; 1102 } 1103 } 1104 1105 $this->setTemplateVar('object' ,$list ); 1106 } 1107 1108 1109 public function advancedView() 1110 { 1111 $this->setTemplateVar('writable',$this->folder->hasRight(Acl::ACL_WRITE) ); 1112 1113 $list = array(); 1114 1115 // Schleife ueber alle Objekte in diesem Ordner 1116 foreach( $this->folder->getObjects() as $o ) 1117 { 1118 /* @var $o BaseObject */ 1119 $id = $o->objectid; 1120 1121 if ( $o->hasRight(Acl::ACL_READ) ) 1122 { 1123 $list[$id]['objectid'] = $id; 1124 $list[$id]['id' ] = 'obj'.$id; 1125 $list[$id]['name' ] = $o->name; 1126 $list[$id]['filename'] = $o->filename; 1127 $list[$id]['desc' ] = $o->desc; 1128 if ( $list[$id]['desc'] == '' ) 1129 $list[$id]['desc'] = lang('NO_DESCRIPTION_AVAILABLE'); 1130 $list[$id]['desc'] = 'ID '.$id.' - '.$list[$id]['desc']; 1131 1132 $list[$id]['type'] = $o->getType(); 1133 1134 $list[$id]['icon'] = $o->getType(); 1135 1136 $list[$id]['url' ] = Html::url($o->getType(),'',$id); 1137 $list[$id]['date'] = date( lang('DATE_FORMAT'),$o->lastchangeDate ); 1138 $list[$id]['user'] = $o->lastchangeUser; 1139 1140 if ( $this->hasRequestVar("markall") || $this->hasRequestVar('obj'.$id) ) 1141 $this->setTemplateVar('obj'.$id,'1'); 1142 } 1143 } 1144 1145 if ( $this->folder->hasRight(Acl::ACL_WRITE) ) 1146 { 1147 // Alle anderen Ordner ermitteln 1148 $otherfolder = array(); 1149 $project = new Project( $this->folder->projectid ); 1150 foreach( $project->getAllFolders() as $id ) 1151 { 1152 $f = new Folder( $id ); 1153 if ( $f->hasRight( Acl::ACL_WRITE ) ) 1154 $otherfolder[$id] = FILE_SEP.implode( FILE_SEP,$f->parentObjectNames(false,true) ); 1155 } 1156 asort( $otherfolder ); 1157 1158 $this->setTemplateVar('folder',$otherfolder); 1159 1160 // URLs zum Umsortieren der Eintraege 1161 $this->setTemplateVar('order_url' ,Html::url('folder','order',$this->folder->id) ); 1162 } 1163 1164 $actionList = array(); 1165 $actionList[] = 'copy'; 1166 $actionList[] = 'link'; 1167 $actionList[] = 'archive'; 1168 1169 if ( $this->folder->hasRight(Acl::ACL_WRITE) ) 1170 { 1171 $actionList[] = 'move'; 1172 $actionList[] = 'delete'; 1173 } 1174 1175 $this->setTemplateVar('actionlist',$actionList ); 1176 $this->setTemplateVar('defaulttype',$this->getRequestVar('type','alpha')); 1177 1178 $this->setTemplateVar('object' ,$list ); 1179 $this->setTemplateVar('act_objectid',$this->folder->id); 1180 1181 $project = new Project($this->folder->projectid); 1182 $rootFolder = new Folder( $project->getRootObjectId() ); 1183 $rootFolder->load(); 1184 1185 $this->setTemplateVar('properties' ,$this->folder->getProperties() ); 1186 $this->setTemplateVar('rootfolderid' ,$rootFolder->id ); 1187 $this->setTemplateVar('rootfoldername',$rootFolder->name); 1188 } 1189 1190 1191 1192 1193 public function rootView() 1194 { 1195 $project = new Project($this->folder->projectid); 1196 $rootFolder = new Folder( $project->getRootObjectId() ); 1197 $rootFolder->load(); 1198 1199 $this->setTemplateVar('rootfolderid' ,$rootFolder->id ); 1200 $this->setTemplateVar('rootfoldername',$rootFolder->name); 1201 } 1202 1203 1204 1205 /** 1206 * Reihenfolge bearbeiten. 1207 */ 1208 public function orderView() 1209 { 1210 global $conf_php; 1211 1212 $list = array(); 1213 $last_objectid = 0; 1214 1215 // Schleife ueber alle Objekte in diesem Ordner 1216 foreach( $this->folder->getObjects() as $o ) 1217 { 1218 /* @var $o BaseObject */ 1219 $id = $o->objectid; 1220 1221 if ( $o->hasRight(Acl::ACL_READ) ) 1222 { 1223 $list[$id]['id' ] = $id; 1224 $list[$id]['name'] = \Text::maxLength( $o->name ,30); 1225 $list[$id]['filename'] = \Text::maxLength( $o->filename ,20); 1226 $list[$id]['desc'] = \Text::maxLength( $o->desc ,30); 1227 if ( $list[$id]['desc'] == '' ) 1228 $list[$id]['desc'] = lang('NO_DESCRIPTION_AVAILABLE'); 1229 $list[$id]['desc'] = 'ID '.$id.' - '.$list[$id]['desc']; 1230 1231 $list[$id]['type'] = $o->getType(); 1232 1233 $list[$id]['icon'] = $o->getType(); 1234 1235 if ( $o->getType() == 'file' ) 1236 { 1237 $file = new File( $id ); 1238 $file->load(); 1239 $list[$id]['desc'] .= ' - '.intval($file->size/1000).'kB'; 1240 1241 if ( $file->isImage() ) 1242 $list[$id]['icon'] = 'image'; 1243 } 1244 1245 $list[$id]['url' ] = Html::url($o->getType(),'',$id); 1246 $list[$id]['date'] = $o->lastchangeDate; 1247 $list[$id]['user'] = $o->lastchangeUser; 1248 1249 $last_objectid = $id; 1250 } 1251 } 1252 1253 $this->setTemplateVar('object' ,$list ); 1254 $this->setTemplateVar('act_objectid',$this->folder->id); 1255 } 1256 1257 1258 1259 1260 /** 1261 * Liefert die Struktur zu diesem Ordner: 1262 * - Mit den übergeordneten Ordnern und 1263 * - den in diesem Ordner enthaltenen Objekten 1264 * 1265 * Beispiel: 1266 * <pre> 1267 * - A 1268 * - B 1269 * - C (dieser Ordner) 1270 * - Unterordner 1271 * - Seite 1272 * - Seite 1273 * - Datei 1274 * </pre> 1275 */ 1276 public function structureView() 1277 { 1278 1279 $structure = array(); 1280 $tmp = &$structure; 1281 $nr = 0; 1282 1283 $parents = $this->folder->parentObjectNames(false,true); 1284 1285 foreach( $parents as $id=>$name) 1286 { 1287 //Html::debug($name,"Name"); 1288 1289 unset($children); 1290 unset($o); 1291 $children = array(); 1292 $o = array('id'=>$id,'name'=>$name,'type'=>'folder','level'=>++$nr,'children'=>&$children); 1293 1294 if ( $id == $this->folder->objectid) 1295 $o['self'] = true; 1296 1297 $tmp[$id] = &$o;; 1298 1299 unset($tmp); 1300 1301 $tmp = &$children; 1302 } 1303 1304 1305 $contents = $this->folder->getObjects(); 1306 1307 unset($children); 1308 unset($o); 1309 1310 $children = array(); 1311 foreach( $contents as $o ) 1312 { 1313 /* @var $o BaseObject */ 1314 $children[$o->objectid] = array('id'=>$o->objectid,'name'=>$o->name,'type'=>$o->getType()); 1315 } 1316 $tmp+= $children; 1317 1318 //Html::debug($structure); 1319 1320 $this->setTemplateVar('outline',$structure); 1321 } 1322 1323 1324 public function pubView() 1325 { 1326 // Schalter nur anzeigen, wenn sinnvoll 1327 1328 // TODO texts, urls.... 1329 $this->setTemplateVar('files' ,count($this->folder->getFiles()) >= 0 ); 1330 $this->setTemplateVar('pages' ,count($this->folder->getPages()) > 0 ); 1331 $this->setTemplateVar('subdirs',count($this->folder->getSubFolderIds()) > 0 ); 1332 1333 //$this->setTemplateVar('clean' ,$this->folder->isRoot ); 1334 // Gefaehrliche Option, da dies bestehende Dateien, die evtl. nicht zum CMS gehören, überschreibt. 1335 // Daher deaktiviert. 1336 $this->setTemplateVar('clean' ,false ); 1337 } 1338 1339 1340 public function pubPost() 1341 { 1342 if ( !$this->folder->hasRight( Acl::ACL_PUBLISH ) ) 1343 throw new \SecurityException('no rights for publish'); 1344 1345 $subdirs = ( $this->hasRequestVar('subdirs') ); 1346 $pages = ( $this->hasRequestVar('pages' ) ); 1347 $files = ( $this->hasRequestVar('files' ) ); 1348 1349 Session::close(); 1350 $publisher = new PublishPublic( $this->folder->projectid ); 1351 1352 $this->folder->publisher = &$publisher; 1353 $this->folder->publish( $pages,$files,$subdirs ); 1354 1355 $publisher->close(); 1356 1357 1358 $list = array_map( 1359 function($obj) 1360 { 1361 return $obj['full_filename']; 1362 }, 1363 $publisher->publishedObjects 1364 ); 1365 1366 $this->addNotice('folder',$this->folder->getDefaultName()->name,'PUBLISHED',OR_NOTICE_OK,array(),$list); 1367 1368 // Wenn gewuenscht, das Zielverzeichnis aufraeumen 1369 if ( $this->hasRequestVar('clean') ) 1370 $publisher->clean(); 1371 } 1372 1373 1374 1375 public function checkMenu( $name ) 1376 { 1377 switch( $name) 1378 { 1379 case 'createfolder': 1380 return !readonly() && $this->folder->hasRight(Acl::ACL_CREATE_FOLDER); 1381 1382 case 'createfile': 1383 return !readonly() && $this->folder->hasRight(Acl::ACL_CREATE_FILE); 1384 1385 case 'createlink': 1386 return !readonly() && $this->folder->hasRight(Acl::ACL_CREATE_LINK); 1387 1388 case 'createpage': 1389 return !readonly() && $this->folder->hasRight(Acl::ACL_CREATE_PAGE); 1390 1391 case 'remove': 1392 return !readonly() && count($this->folder->getObjectIds()) == 0; 1393 1394 case 'select': 1395 case 'order': 1396 case 'aclform': 1397 return !readonly(); 1398 1399 default: 1400 return true; 1401 } 1402 } 1403 1404 1405 /** 1406 * Shows the folder content as html. 1407 */ 1408 public function showView() { 1409 1410 // Angabe Content-Type 1411 header('Content-Type: text/html' ); 1412 1413 header('X-Folder-Id: ' .$this->folder->folderid ); 1414 header('X-Id: ' .$this->folder->id ); 1415 header('Content-Description: '.$this->folder->filename() ); 1416 1417 echo '<html><body>'; 1418 echo '<h1>'.$this->folder->filename.'</h1>'; 1419 echo '<ul>'; 1420 1421 // Schleife ueber alle Objekte in diesem Ordner 1422 foreach( $this->folder->getObjects() as $o ) 1423 { 1424 /* @var $o BaseObject */ 1425 $id = $o->objectid; 1426 1427 if ( $o->hasRight(Acl::ACL_READ) ) 1428 { 1429 echo '<li><a href="'. Html::url($o->getType(),'',$id).'">'.$o->filename.'</a></li>'; 1430 1431 //echo date( lang('DATE_FORMAT'),$o->lastchangeDate ); 1432 //echo $o->lastchangeUser; 1433 } 1434 } 1435 1436 echo '</ul>'; 1437 echo '</body></html>'; 1438 1439 exit; 1440 } 1441 1442 1443 1444 public function removeView() 1445 { 1446 $this->setTemplateVar( 'name',$this->folder->filename ); 1447 $this->setTemplateVar( 'hasChildren', $this->folder->hasChildren() ); 1448 } 1449 1450 1451 public function removePost() 1452 { 1453 if ( !$this->hasRequestVar('delete') ) 1454 throw new \ValidationException("delete"); 1455 1456 if ( $this->hasRequestVar( 'withChildren')) 1457 $this->folder->deleteAll(); // Delete with children 1458 else 1459 if ( $this->folder->hasChildren() ) 1460 throw new \ValidationException("withChildren"); 1461 else 1462 $this->folder->delete(); // Only delete current folder. 1463 1464 $this->addNotice('folder',$this->folder->filename,'DELETED',OR_NOTICE_OK); 1465 } 1466 1467 }