public function getRelativePath(Io_Path $path_)
 {
     if ($this->isFile()) {
         $directory = $this->getParent();
     } else {
         $directory = $this;
     }
     if ($directory->isParentOf($path_)) {
         return Io::path(ltrim(String::replace($path_->m_path, str_pad($directory->m_path, 1, '/', STR_PAD_RIGHT), ''), '/'));
     }
     $level = 1;
     $segments = explode('/', $directory->m_path);
     $path = $path_->m_path;
     while (array_pop($segments)) {
         if (!($current = implode('/', $segments))) {
             $current = '/';
         }
         if (0 === mb_strpos($path, $current)) {
             if ('/' === $current) {
                 $subPath = $path;
             } else {
                 $subPath = String::replace($path, $current, '');
             }
             return str_repeat('../', $level) . ltrim($subPath, '/');
         }
         $level++;
     }
     return $file_->getPath();
 }
 /**
  * @param string $path_
  * @param integer $width_
  * @param integer $height_
  *
  * @return string
  */
 public static function imagePath($route_, Io_Path $path_, $width_ = null, $height_ = null)
 {
     $file = \str\encodeBase64Url(json_encode([(string) Io::path(Environment::pathWeb())->getRelativePath($path_), $width_, $height_])) . '.' . Io::fileExtension($path_);
     return Http_Router::path($route_) . "/{$file}";
 }
 /**
  * @see \Components\Media_Storage::copyCategory() \Components\Media_Storage::copyCategory()
  */
 public function copyCategory($categorySource_, $categoryTarget_)
 {
     $source = Io::path(Environment::pathResource("{$this->store->path}/{$categorySource_}"));
     if (false === $source->exists()) {
         return false;
     }
     $source->copy(Io::path(Environment::pathResource("{$this->store->path}/{$categoryTarget_}")));
     return true;
 }
 /**
  * Initializes / prepares unit test execution.
  */
 protected function initialize()
 {
     $this->addClass(__DIR__ . '/../../assertion.php');
     $this->addResultHandler(new Test_Unit_Result_Handler(Io::path($this->getBuildPath())->test->unit));
 }
 /**
  * @return \Components\Io_Path
  */
 public function getTempPath()
 {
     return Io::path($this->getBuildPath())->tmp;
 }
 private function stashFile(Io_File $file_, $subPath_ = null)
 {
     $mimeType = $file_->getMimetype();
     if (null === $mimeType) {
         $this->addError(I18n::translatef('ui/panel/upload/file/error/unknown_mimetype', $file_->getName()));
         $file_->delete();
         return;
     }
     if (!$this->isValidMimetype($mimeType) || !$this->isValidFileExtension($file_->getExtension())) {
         $this->addError(I18n::translatef('ui/panel/upload/file/error/illegal_mimetype', $mimeType->title(), $file_->getName()));
         $file_->delete();
         return;
     }
     if ($this->extractArchives && $mimeType->isArchive()) {
         if (false === isset(self::$implArchives[$mimeType->name()])) {
             $this->addError(I18n::translatef('ui/panel/upload/file/error/unsupported_archive', $mimeType->name()));
             $file_->delete();
             return;
         }
         $archiveId = md5($file_->getPathAsString());
         $archiveImpl = self::$implArchives[$mimeType->name()];
         $archivePath = self::uploadPath($archiveId);
         // TODO Io_Archive_Zip
         $archive = new $archiveImpl();
         $archive->open($file_->getPathAsString());
         $archive->extractTo($archivePath);
         $this->scanTemporaryUploadPath(Io::path($archivePath), $subPath_);
         $archive->close();
         $file_->delete();
         return;
     }
     $file = $file_->move(self::uploadPath($subPath_)->getFile($file_->getName()));
     $this->m_files[$subPath_ . $file->getName()] = $file;
 }
 /**
  * @return \Components\I18n_Location
  */
 protected function initialized()
 {
     if (null === $this->m_data) {
         if (false === ($this->m_data = Cache::get("i18n/location/{$this->m_name}"))) {
             if (null === self::$m_pathResource) {
                 self::$m_pathResource = Io::path(Environment::pathComponentsResource('i18n', 'resource', 'i18n', 'location'));
             }
             $file = null;
             $sub = [];
             $chunks = explode('_', strtolower($this->m_name));
             while (count($chunks)) {
                 $file = self::$m_pathResource->getFile(implode('/', $chunks) . '.json');
                 if ($file->exists()) {
                     break;
                 }
                 array_unshift($sub, array_pop($chunks));
             }
             if (false === $file->exists()) {
                 Cache::set("i18n/location/{$this->m_name}", []);
                 return $this;
             }
             $json = $file->getContent();
             $this->m_data = json_decode($json, true);
             if (0 < count($sub)) {
                 while ($next = array_shift($sub)) {
                     $this->m_data =& $this->m_data['children'][$next];
                 }
             }
             Cache::set("i18n/location/{$this->m_name}", $this->m_data);
         }
     }
     return $this;
 }