openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

FolderAction.class.php (2667B)


      1 <?php
      2 
      3 namespace cms\action;
      4 
      5 use cms\base\Configuration;
      6 use cms\model\Permission;
      7 use cms\model\Folder;
      8 
      9 /**
     10  * Action-Klasse zum Bearbeiten eines Ordners.
     11  *
     12  * @author Jan Dankert
     13  */
     14 
     15 class FolderAction extends ObjectAction
     16 {
     17     /**
     18      * @var Folder
     19      */
     20 	protected $folder;
     21 
     22     public function __construct()
     23 	{
     24         parent::__construct();
     25     }
     26 
     27 
     28     public function init()
     29     {
     30 		$folder = new Folder( $this->request->getId() );
     31 		$folder->load();
     32 
     33 		$this->lastModified( $folder->lastchangeDate);
     34 
     35 		$this->setBaseObject($folder);
     36 	}
     37 
     38 
     39 	protected function setBaseObject($folder ) {
     40 
     41 		$this->folder = $folder;
     42 
     43 		parent::setBaseObject( $folder );
     44 	}
     45 
     46 
     47 
     48 
     49 
     50 	/**
     51 	 * Ermittelt die maximale Gr��e einer hochzuladenden Datei.<br>
     52 	 * Der Wert wird aus der PHP- und OpenRat-Konfiguration ermittelt.<br>
     53 	 *
     54 	 * @return Integer maximale Dateigroesse in Bytes
     55 	 */
     56 	protected function maxFileSize()
     57 	{
     58 		// When querying memory size values:
     59 		// Many ini memory size values, such as upload_max_filesize,
     60 		// are stored in the php.ini file in shorthand notation.
     61 		// ini_get() will return the exact string stored in the php.ini file
     62 		// and NOT its integer equivalent.
     63 
     64 		$_10GB = 10 * 1024 * 1024 * 1024; // 10GB
     65 		$sizes = [];
     66 
     67 		foreach( ['upload_max_filesize','post_max_size','memory_limit'] as $setting )
     68 		{
     69 			$memLimit = $this->stringToBytes(ini_get($setting));
     70 
     71 			if	($memLimit )
     72 				$sizes[] = $memLimit;
     73 		}
     74 
     75 		$confMaxSize = Configuration::subset(['content','file'])->get('max_file_size',$_10GB) * 1024;
     76 
     77 		if	( $confMaxSize )
     78 			$sizes[] = $confMaxSize;
     79 
     80 		return min($sizes); // Using the minimum of all sizes.
     81 	}
     82 
     83 	/**
     84 	 * Umwandlung von abgek�rzten Bytewerten ("Shorthand Notation") wie
     85 	 * "4M" oder "500K" in eine ganzzahlige Byteanzahl.<br>
     86 	 * <br>
     87 	 * Quelle: http://de.php.net/manual/de/function.ini-get.php
     88 	 *
     89 	 * @param String Abgek�rzter Bytewert
     90 	 * @return Integer Byteanzahl
     91 	 */
     92 	protected function stringToBytes($val)
     93 	{
     94 		$val  = trim($val);
     95 		$last = strtolower($val[strlen($val)-1]);
     96 		$val  = intval($val);
     97 		// Achtung: Der Trick ist das "Fallthrough", kein "break" vorhanden!
     98 		switch($last)
     99 		{
    100 			case 'g':
    101 				$val *= 1024;
    102 			case 'm':
    103 				$val *= 1024;
    104 			case 'k':
    105 				$val *= 1024;
    106 		}
    107 
    108      	return intval($val);
    109 	}
    110 
    111 
    112 	/**
    113 	 * Is it allowed to add a new object?
    114 	 * @return bool
    115 	 */
    116 	protected function hasPermissionToAddAnyObject() {
    117 
    118 		return
    119 			$this->folder->hasRight( Permission::ACL_CREATE_FILE   ) ||
    120 			$this->folder->hasRight( Permission::ACL_CREATE_FOLDER ) ||
    121 			$this->folder->hasRight( Permission::ACL_CREATE_LINK   ) ||
    122 			$this->folder->hasRight( Permission::ACL_CREATE_PAGE   );
    123 	}
    124 }