Example #1
0
 /**
  * Deletes a file from upload dir
  * @param String $path The relative path to the file to delete. (relative to the upload directory)
  * @return boolean 
  */
 public static function delete($path = null)
 {
     if ($path == null) {
         throw new Exception('Trying to delete a file with an empty path.');
     }
     if (!\Orion::config()->defined('UPLOAD_DIR')) {
         throw new Exception('UPLOAD_DIR is not defined in Orion configuration.', E_ERROR, get_class());
     }
     $uploadDir = \Orion::config()->get('UPLOAD_DIR');
     if (!Tools::startWith($path, $uploadDir)) {
         $path = $uploadDir . $path;
     }
     if (!file_exists($path)) {
         throw new Exception('Trying to delete a file that does not exist');
     }
     if (!@unlink($path)) {
         throw new Exception('Internal error. Could not delete file.');
     }
     return true;
 }
Example #2
0
 /**
  * Get the relative URI (Base URI minus BASE_DIR)
  * @return string The relative URI
  */
 public static function getRelativeURI()
 {
     if (Tools::startWith(self::$URI, self::$BASE_DIR)) {
         return substr(self::$URI, strlen(self::$BASE_DIR));
     } else {
         return self::$URI;
     }
 }
Example #3
0
 /**
  * Security function name testing. (Not used as of now)
  *
  * @param string Function name to test
  * @deprecated
  * @see OrionSecurity
  */
 private function isRestrictedFunction($name)
 {
     return !Tools::startWith($function, '_') && Tools::match($function, $this->FUNCTION_NAME_MATCH) && in_array($function, $this->RESTRICTED_FUNCTIONS);
 }
Example #4
0
 /**
  * Extract sub array from base array, keeping only keys starting with $pattern
  * @param array<string,mixed> $array
  * @param string $pattern
  * @return array<key, mixed>
  */
 public static function extractArrayKeysStartingWith($array, $pattern)
 {
     $out = array();
     foreach ($array as $key => $value) {
         if (Tools::startWith($key, $pattern)) {
             $out[$key] = $value;
         }
     }
     return $out;
 }