static function modified_image($path, $mods) { if (is_string($mods)) { $mods = self::parse_modifiers($mods); } $ext = false; $name = false; if ($m = Core_Regexps::match_with_results('{(.+)\\.(jpe?g|gif|png|bmp)$}i', $path)) { $name = $m[1]; $ext = strtolower($m[2]); } if (!$ext || !IO_FS::exists($path)) { $path = '../tao/files/images/admin.gif'; $ext = 'gif'; $name = 'error'; } $name = preg_replace('{^\\.\\./}', 'up/', $name); $name = ltrim($name, '.'); $name = ltrim($name, '/'); $stat = IO_FS::Stat($path); $mtime = $stat->mtime->timestamp; $name .= "-{$stat->size}-{$mtime}-"; $name .= md5(serialize($mods)); $cache = self::$cache_dir . "/{$name}.{$ext}"; if (IO_FS::exists('./' . $cache)) { return '/' . $cache; } $dir = preg_replace('{/([^/]+)$}', '', $cache); if (!IO_FS::exists($dir)) { IO_FS::mkdir($dir); } $image = self::Image($path); $image->modify($mods); $image->save('./' . $cache); CMS::chmod_file('./' . $cache); return '/' . $cache; }
/** * @param $asset * @param $dir * @param $extension * @param int $timestamp * * @return string */ protected function compute_public_path($asset, $dir, $extension, $timestamp = false) { if ($asset[0] == '/' || strstr($asset, "://")) { return $asset; } $asset .= preg_match('{(?:gif|png|jpg|js|css)$}', $asset) ? '' : $extension; return "/{$dir}/{$asset}" . ($timestamp ? '?' . IO_FS::Stat("{$dir}/{$asset}")->mtime->timestamp : ''); }
/** * Возвращает значение свойства * * @param string $property * * @return mixed */ public function __get($property) { switch ($property) { case 'path': return $this->path; case 'dir_name': case 'dirname': return @dirname($this->path); case 'name': return @basename($this->path); case 'real_path': return @realpath($this->path); case 'stat': if (!$this->stat) { $this->stat = IO_FS::Stat($this->path); } return $this->stat; default: throw new Core_MissingPropertyException($property); } }