Esempio n. 1
0
 /**
  * @param $info
  * @return array|null
  * @throws \Ip\Exception
  */
 public static function ipRouteAction_150($info)
 {
     $requestFile = ipFile('') . $info['relativeUri'];
     $fileDir = ipFile('file/');
     if (ipRequest()->getRelativePath() != $info['relativeUri']) {
         return null;
         //language specific url.
     }
     if (mb_strpos($requestFile, $fileDir) !== 0) {
         return null;
     }
     $reflection = mb_substr($requestFile, mb_strlen($fileDir));
     $reflection = urldecode($reflection);
     $reflectionModel = ReflectionModel::instance();
     $reflectionRecord = $reflectionModel->getReflectionByReflection($reflection);
     if ($reflectionRecord) {
         $reflectionModel->createReflection($reflectionRecord['original'], $reflectionRecord['reflection'], json_decode($reflectionRecord['options'], true));
         if (is_file(ipFile('file/' . $reflection))) {
             //supply file route
             $result['page'] = null;
             $result['plugin'] = 'Repository';
             $result['controller'] = 'PublicController';
             $result['action'] = 'download';
             return $result;
         }
     }
 }
Esempio n. 2
0
 public static function unbindFile($file, $plugin, $instanceId, $baseDir = 'file/repository/')
 {
     $condition = array('fileName' => $file, 'plugin' => $plugin, 'instanceId' => $instanceId, 'baseDir' => $baseDir);
     $sql = 'DELETE FROM ' . ipTable('repository_file') . '
             WHERE filename = :fileName
             AND plugin = :plugin
             AND instanceId = :instanceId
             AND baseDir = :baseDir
             LIMIT 1';
     // it is important to delete only one record
     ipDb()->execute($sql, $condition);
     $usages = self::whoUsesFile($file);
     if (empty($usages)) {
         $reflectionModel = ReflectionModel::instance();
         $reflectionModel->removeReflections($file);
     }
 }
Esempio n. 3
0
 /**
  * @param string $file relative path from file/repository
  * @param array $options - image cropping options
  * @param string $desiredName - desired file name. If reflection is missing, service will try to create new one with name as possible similar to desired
  * @param bool $onDemand transformation will be create on the fly when image accessed for the first time
  * @return string - file name from BASE_DIR
  * @throws \Ip\Exception\Repository\Transform
  */
 public function getReflection($file, $options, $desiredName = null, $onDemand = true)
 {
     $reflectionModel = ReflectionModel::instance();
     try {
         $reflection = $reflectionModel->getReflection($file, $options, $desiredName, $onDemand);
         if (ipConfig()->get('rewritesDisabled') && !is_file(ipFile('file/' . $reflection)) || !ipConfig()->get('realTimeReflections', true)) {
             //create reflections immediately if mod_rewrite is disabled
             $reflectionRecord = $reflectionModel->getReflectionByReflection($reflection);
             $reflectionModel->createReflection($reflectionRecord['original'], $reflectionRecord['reflection'], json_decode($reflectionRecord['options'], true));
         }
     } catch (\Exception $e) {
         ipLog()->error($e->getMessage(), array('errorTrace' => $e->getTraceAsString()));
         $this->lastException = $e;
         return false;
     }
     return 'file/' . $reflection;
 }
Esempio n. 4
0
 private function removeFile($file, $secure, $forced = false)
 {
     if (basename($file) == '.htaccess') {
         //for security reasons we don't allow to remove .htaccess files
         return false;
     }
     $baseDir = 'file/repository/';
     if ($secure) {
         $baseDir = 'file/secure/';
     }
     $realFile = realpath(ipFile($baseDir . $file));
     if (strpos($realFile, realpath(ipFile($baseDir))) !== 0) {
         return false;
     }
     $model = Model::instance();
     $usages = $model->whoUsesFile($file);
     if (!$forced && !empty($usages)) {
         return false;
     }
     if (!$secure) {
         $reflectionModel = ReflectionModel::instance();
         $reflectionModel->removeReflections($file);
     }
     if (file_exists($realFile) && is_file($realFile) && is_writable($realFile)) {
         unlink($realFile);
     }
     return true;
 }