コード例 #1
0
ファイル: main.php プロジェクト: SjayLiFe/CTRev
 /**
  * Генератор sitemap.xml
  * @return null
  */
 public function sitemap()
 {
     $file = main_page::sitemap;
     $r = db::o()->query('SELECT * FROM content');
     tpl::o()->assign('content', db::o()->fetch2array($r));
     $c = tpl::o()->fetch('content/sitemap.xtpl');
     file::o()->write_file($c, $file);
 }
コード例 #2
0
ファイル: class.furl.php プロジェクト: SjayLiFe/CTRev
 /**
  * Функция создания Человекопонятного URL, исходя из заданных параметров, 
  * по предустановленным правилам
  * @param string $module имя модуля
  * @param array $params массив параметров, например:
  * array('id' => 1, 'name' => 'CTRev', 'cat' => 'demo')
  * ключ slashes экранирует результат для JavaScript, иначе & заменяется на &
  * @param bool $page является ли указанный модуль ссылкой на документ?
  * @param bool $no_end нужно ли в конец добавлять .html/index.html?
  * @param bool $nobaseurl не добавлять в начало $baseurl
  * @return string ЧПУ
  */
 public function construct($module, $params = array(), $page = false, $no_end = false, $nobaseurl = false)
 {
     $baseurl = globals::g('baseurl');
     $burl = true;
     $assign = false;
     if (is_array($module)) {
         $module_t = $module['module'];
         if ($module['no_end']) {
             $no_end = $module['no_end'];
         }
         if ($module['assign']) {
             $assign = (string) $module['assign'];
         }
         if (!$module_t && $module['page']) {
             $module = $module['page'];
             $page = true;
         } elseif (!$module_t) {
             return;
         } else {
             unset($module['module']);
             $params = $module;
             $module = $module_t;
         }
     } elseif ($nobaseurl) {
         $burl = false;
     }
     if (!is_array($params)) {
         $params = array();
     }
     if ($params["_filetype"]) {
         $filetype = '.' . file::o()->get_filetype($params["_filetype"]);
     } else {
         $filetype = ".html";
     }
     $url = $burl ? $baseurl : "";
     if (config::o()->v('furl')) {
         $url .= $this->module_name($module) . ($page ? '' : "/");
         $function = $module . '_furl_rules';
     } else {
         $url .= 'index.php?module=' . ($this->rmodules[$module] ? $this->rmodules[$module] : $module);
         $function = $module . '_nfurl_rules';
     }
     $slashes = $params['slashes'];
     $noencode = $params['noencode'];
     $b = $this->is_callable($function);
     if ($b) {
         $params = $this->resort($module, $params);
     }
     $postfix = "";
     $surl = '';
     $ourl = $url;
     if ($params && !$page) {
         foreach ($params as $param => $value) {
             if ($this->postfixes[$module][$param]) {
                 $postfix .= $this->postfixes[$module][$param] . $value;
             }
             if ($b) {
                 $r = $this->call_method($function, array($param, $value, !$slashes && !$noencode));
             } elseif (!config::o()->v('furl')) {
                 $r = $param . "=" . $value;
             } else {
                 $r = $param . "-" . $value . "/";
             }
             if (!config::o()->v('furl') && $r) {
                 $surl .= '&' . $r;
                 $r = ($slashes || $noencode ? '&' : '&') . $r;
             }
             $url .= $r;
         }
     }
     if (!$surl) {
         $surl = $url;
     } else {
         $surl = $ourl . $surl;
     }
     $add = '';
     if (config::o()->v('furl')) {
         if (!$no_end && !$page && (!$params || !$b || preg_match('/\\/$/siu', $url))) {
             $add .= "index";
         }
         if (!$no_end) {
             $add .= $filetype;
         }
     }
     $add .= $postfix;
     $url = $url . $add;
     $surl = $surl . $add;
     $this->forlocation = array($surl, $url);
     if ($slashes) {
         $url = slashes_smarty($url);
     }
     if ($assign) {
         tpl::o()->assign($assign, $url);
     } else {
         return $url;
     }
 }
コード例 #3
0
ファイル: plugins.php プロジェクト: SjayLiFe/CTRev
 /**
  * Отображение списка включенных плагинов
  * @return null
  */
 protected function show()
 {
     $r = db::o()->query('SELECT file FROM plugins');
     tpl::o()->assign('res', db::o()->fetch2array($r, null, array('file')));
     $themes = file::o()->open_folder(THEMES_PATH, true);
     $n = !($y = true);
     foreach ($themes as $theme) {
         $r = file::o()->is_writable(THEMES_PATH . '/' . $theme . '/' . TEMPLATES_PATH, true, true);
         $y = $y || $r === true || $r === 2;
         $n = $n || !$r || $r === 1;
     }
     tpl::o()->assign('trewritable', $y + !$n);
     tpl::o()->register_modifier('pcompatibility', array($this, 'check'));
     tpl::o()->register_modifier('pvar', array(plugins::o()->manager, 'pvar'));
     tpl::o()->register_modifier('psettings', array(plugins::o()->manager, 'parsed_settings'));
     tpl::o()->register_modifier('plugin_selector', array($this, 'file_selector'));
     tpl::o()->display('admin/plugins/index.tpl');
 }
コード例 #4
0
ファイル: class.uploader.php プロジェクト: SjayLiFe/CTRev
 /**
  * Функция скачивания файла, защищенного .htaccess
  * @param string $filepath путь к файлу
  * @param string $filename имя файла
  * @return bool true, если всё прошло успешно, false - в случае неудачи
  * @throws EngineException 
  */
 public function download($filepath, $filename = "")
 {
     if (!$filename) {
         preg_match('/\\/(.*)$/siu', $filepath, $matches);
         $filename = $matches[2];
     }
     if (!file_exists($filepath)) {
         throw new EngineException('file_not_exists');
     }
     $content = @file_get_contents($filepath);
     $t = file::o()->get_content_type($filepath);
     $this->download_headers($content, $filename, $t);
 }
コード例 #5
0
ファイル: main.php プロジェクト: SjayLiFe/CTRev
 /**
  * Проверка стадий
  * @param array $data массив данных
  * @return null
  */
 protected function check_steps($data)
 {
     $error = array();
     db::o()->no_reset()->no_error();
     switch (INSTALL_PAGE) {
         case "license":
         case "finish":
             break;
         case "config":
             db::o()->connect();
             $this->config($data, $error);
             break;
         case "admin":
             db::o()->connect();
             $this->create_admin($data, $error);
             break;
         case "import":
             db::o()->connect();
             $this->import_db($error);
             break;
         case "database":
             if (!$this->write_db($data)) {
                 $error[] = lang::o()->v('install_error_cant_write_dbconn');
             }
             db::o()->connect();
         case "check":
             foreach ($this->chmod as $f) {
                 $r = file::o()->is_writable($f, true, true, true);
                 if ($r !== 2 && $r !== true) {
                     $error[] = sprintf(lang::o()->v('install_error_not_rewritable'), $f);
                 }
             }
             $ufs = ini_get('upload_max_filesize');
             $pms = ini_get('post_max_size');
             $s = $this->check_filesize($ufs, $pms) ? $pms : $ufs;
             if (!$this->check_filesize($s, self::need_filesize . 'M')) {
                 $error[] = lang::o()->v('install_error_upload_filesize');
             }
             if (!version_compare(PHP_VERSION, '5.0', '>=')) {
                 $error[] = lang::o()->v('install_error_php_version');
             }
             if (!in_array('mbstring', get_loaded_extensions())) {
                 $error[] = lang::o()->v('install_error_mbstring');
             }
             break;
     }
     if ($error) {
         die(implode('<br>', $error));
     }
 }
コード例 #6
0
ファイル: styles.php プロジェクト: SjayLiFe/CTRev
 /**
  * Клонирование темы
  * @param string $name имя темы
  * @param string $newname новое имя темы
  * @return null
  * @throws EngineException
  */
 public function copy($name, $newname)
 {
     lang::o()->get('admin/styles');
     if (!validword($newname)) {
         throw new EngineException('styles_invalid_new_name');
     }
     file::o()->copy_folder(THEMES_PATH . '/' . $name, THEMES_PATH . '/' . $newname);
     log_add('copied_style', 'admin', array($newname, $name));
 }
コード例 #7
0
ファイル: functions.php プロジェクト: SjayLiFe/CTRev
    /**
     * Очистка алиасов классов
     * @return null
     */
    function clear_aliases()
    {
        $content = '<?php
// Autogenerated file. DO NOT EDIT
?>';
        file::o()->write_file($content, CLASS_ALIASES);
    }
コード例 #8
0
ファイル: lang.php プロジェクト: SjayLiFe/CTRev
 /**
  * Клонирование языкового пакета
  * @param string $name имя языка
  * @param string $newname новое имя языка
  * @return null
  * @throws EngineException
  */
 public function copy($name, $newname)
 {
     lang::o()->get('admin/languages');
     if (!validword($newname)) {
         throw new EngineException('languages_invalid_new_name');
     }
     file::o()->copy_folder(LANGUAGES_PATH . '/' . $name, LANGUAGES_PATH . '/' . $newname);
     log_add('copied_language', 'admin', array($newname, $name));
 }
コード例 #9
0
ファイル: init.php プロジェクト: SjayLiFe/CTRev
tpl::o()->register_modifier('gval', 'smarty_group_value');
tpl::o()->register_modifier('null_text', array($input, 'set_null_text'));
tpl::o()->register_modifier('cut', array($display, "cut_text"));
tpl::o()->register_modifier('he', array($display, "html_encode"));
tpl::o()->register_modifier("ft", array($bbcodes, "format_text"));
tpl::o()->register_modifier("ge", array($display, "estimated_time"));
tpl::o()->register_modifier("ul", 'smarty_user_link');
tpl::o()->register_modifier('gc', array($display, "group_color"));
tpl::o()->register_modifier('gcl', 'smarty_group_color_link');
tpl::o()->register_modifier("ua", array($display, "useravatar"));
tpl::o()->register_modifier("pf", "smarty_print_format");
tpl::o()->register_modifier('cs', array($display, "convert_size"));
tpl::o()->register_modifier("zodiac_sign", array($display, 'zodiac_image'));
tpl::o()->register_modifier("decus", array(users::o(), 'decode_settings'));
tpl::o()->register_modifier("filetype", array(file::o(), 'get_filetype'));
tpl::o()->register_modifier("is_writable", array(file::o(), 'is_writable'));
tpl::o()->register_modifier('rnl', 'replace_newline');
/**
 * @note Создание тега для atom:id(для торрентов)(atom_tag)
 * params:
 * int time время постинга
 * string title заголовок
 * int id ID
 */
tpl::o()->register_function("atom_tag", "smarty_make_atom_tag");
/*
  tpl::o()->register_modifier("parse_array", array(
  $display,
  'parse_smarty_array')); */
/**
 * @note Вывод статистики запросов(query_stat)
コード例 #10
0
ファイル: class.bittorrent.php プロジェクト: SjayLiFe/CTRev
 /**
  * Проверка и загрузка торрент-файла
  * @param string $id ID торрент-файла
  * @param string $filevar файловая переменная($_FILES) для торрента
  * @param string $filelist ссылка на сериализованный список файлов в торренте
  * @param int $filesize ссылка на размер файла
  * @param string $announce_list ссылка на аннонсеры для мультитрекера
  * @return string инфохеш торрент файла
  */
 public function torrent_file($id, $filevar, &$filelist = null, &$filesize = null, &$announce_list = null)
 {
     n("uploader")->check($filevar, $tmp = 'torrents');
     $t = $filevar["tmp_name"];
     list($dict, $idict) = $this->check_dict($t, $filelist, $filesize, $announce_list);
     file::o()->write_file($this->benc($dict), config::o()->v('torrents_folder') . '/' . self::torrent_prefix . $id . ".torrent");
     return sha1($this->benc($idict));
 }
コード例 #11
0
ファイル: class.search.php プロジェクト: SjayLiFe/CTRev
 /**
  * Поиск/замена в файлах
  * @param string|array $dir путь к дирректории или массив файлов
  * @param string $what что ищем? (рег. выражение без делимиттеров)
  * @param bool $regexp регулярное выражение?
  * @param int $where где ищем?(для массива, 0 - в значениях, 1 - в ключах, 2 - и там, и там)
  * если указать -1, то не будет проверяться, слово ли ключ, а поиск будет по значению
  * @param callback $callback callback функция для получения контента файла
  * единственный параметр функции - путь к файлу
  * @param string $was пред. путь(для рекурсии)
  * @return array массив файлов(ключи) и подсвеченных результатов(значения)
  */
 public function search_infiles($dir, $what, $regexp = false, $where = null, $callback = null, $was = '')
 {
     if (!$dir || !$what) {
         return;
     }
     if (!is_array($dir) && is_dir(ROOT . $dir)) {
         $files = file::o()->open_folder($dir);
     } else {
         $dir = $files = (array) $dir;
     }
     $r = array();
     if (!$regexp) {
         $what = mpc($what);
         $regexp = true;
     } elseif (!$was) {
         $what = str_replace('/', '\\/', $what);
     }
     $owhat = $what;
     if (is_null($this->infiles_replace)) {
         $what = display::o()->html_encode($what);
     }
     $what = '/(' . $what . ')/siu';
     $where = (int) $where;
     foreach ($files as $f) {
         if (!is_array($dir)) {
             $nf = $dir . '/' . $f;
             $wf = ($was ? $was . '/' : '') . $f;
         } else {
             $wf = $nf = $f;
         }
         if (!$f) {
             return;
         }
         $fr = ROOT . $nf;
         if (is_dir($fr)) {
             if (!is_array($dir)) {
                 $r = array_merge($r, $this->search_infiles($nf, $owhat, $regexp, $where, $callback, $wf));
             }
             continue;
         }
         if ($callback) {
             $c = call_user_func($callback, $nf);
         } else {
             $c = file_get_contents($fr);
         }
         if (!$c) {
             continue;
         }
         if (!is_array($c)) {
             $this->search_infiles_na($r, $fr, $what, $nf, $wf);
             continue;
         }
         if (!is_null($this->infiles_replace) && !$this->infiles_replace_cb) {
             continue;
         }
         $this->search_infiles_a($r, $c, $what, $where, $nf, $wf);
     }
     if (!$was) {
         $this->replace_infiles(null, null);
     }
     return $r;
 }
コード例 #12
0
ファイル: class.cache.php プロジェクト: SjayLiFe/CTRev
 /**
  * Очистка от скомпилированных шаблонов
  * @return bool true, если успешно очищено
  */
 public function clear_tpl()
 {
     return @file::o()->unlink_folder('include/cache/' . TEMPLATES_PATH, true, '.gitignore');
 }
コード例 #13
0
ファイル: smilies.php プロジェクト: SjayLiFe/CTRev
 /**
  * Сохранение смайлов
  * @param array $data массив данных
  * @return null
  * @throws EngineException 
  */
 public function save($data)
 {
     $admin_file = globals::g('admin_file');
     $cols = array('id', 'name', 'code', 'image', 'sb' => 'show_bbeditor');
     extract(rex($data, $cols));
     $id = (int) $id;
     $name = (array) $name;
     $code = (array) $code;
     $image = (array) $image;
     $sb = (array) $sb;
     $c = count($name);
     if ($id && $c != 1) {
         throw new EngineException('smilies_empty_data');
     }
     if (!$name || $c != count($code) || $c != count($image)) {
         throw new EngineException('smilies_empty_data');
     }
     foreach ($name as $i => $iname) {
         $icode = trim($code[$i]);
         $iname = trim($iname);
         $iimage = trim($image[$i]);
         $isb = (bool) $sb[$i];
         if (!$icode || !$iname || !$iimage) {
             continue;
         }
         if (!file_exists(ROOT . config::o()->v('smilies_folder') . '/' . $iimage) || !in_array(file::o()->get_filetype($iimage), $this->allowed_types)) {
             continue;
         }
         if (db::o()->p($icode, $id)->count_rows('smilies', 'code = ?' . ($id ? ' AND id<>?' : ''))) {
             continue;
         }
         $update = array('code' => $icode, 'name' => $iname, 'image' => $iimage, 'show_bbeditor' => $isb);
         try {
             plugins::o()->pass_data(array("update" => &$update, "id" => $id), true)->run_hook('admin_smilies_save');
         } catch (PReturn $e) {
             if (!$e->r()) {
                 continue;
             }
             return $e->r();
         }
         if (!$id) {
             db::o()->insert($update, 'smilies', true);
         } else {
             db::o()->p($id)->update($update, 'smilies', 'WHERE id=? LIMIT 1');
         }
     }
     cache::o()->remove('smilies');
     if (!$id) {
         db::o()->save_last_table();
         furl::o()->location($admin_file);
     } else {
         $this->show($id);
         return;
     }
 }
コード例 #14
0
ファイル: class.plugins.php プロジェクト: SjayLiFe/CTRev
 /**
  * Обратная замена
  * @param string $plugin_name имя плагина
  * @return bool статус
  */
 public function revert_replace($plugin_name)
 {
     $b = ROOT . PLUGINS_PATH . '/' . PLUGINS_REPLACED . '/repl.' . $plugin_name . '.back';
     if (!file_exists($b)) {
         return true;
     }
     $replaced = unserialize(file_get_contents($b));
     if (!$replaced) {
         return true;
     }
     $r = 0;
     $i = 0;
     foreach ($replaced as $f => $arr) {
         if (!$arr) {
             continue;
         }
         if (!file_exists(ROOT . $f)) {
             continue;
         }
         $contents = file_get_contents(ROOT . $f);
         foreach ((array) $arr as $cur) {
             if (!$cur) {
                 continue;
             }
             foreach ((array) $cur as $per) {
                 list($what, $with) = $per;
                 $c = 1;
                 // reference
                 $contents = str_replace($with, $what, $contents, $c);
             }
         }
         $r += file::o()->write_file($contents, $f);
         $i++;
     }
     $r += @unlink($b);
     $i++;
     return $r == $i;
 }
コード例 #15
0
ファイル: class.input.php プロジェクト: SjayLiFe/CTRev
 /**
  * Выборка дирректорий
  * Параметры: current, null
  * @param string $name имя селектора
  * @param string $folder дирректория
  * @param bool $onlydir искать только дирректории?
  * @param string $regexp рег. выражение для выборки файлов(с делимиттерами)
  * @param int $match значение из рег. выражения
  * @return string HTML код селектора
  */
 public function select_folder($name = "theme", $folder = THEMES_PATH, $onlydir = false, $regexp = '', $match = '')
 {
     if (!is_array($name)) {
         $this->join_params($name, array('folder' => $folder, 'onlydir' => $onlydir, 'regexp' => $regexp, 'match' => $match));
     }
     $current = $name["current"];
     $folder = $name["folder"];
     $null = $name["null"];
     if (!is_null($name["onlydir"])) {
         $onlydir = $name["onlydir"];
     }
     $regexp = $name["regexp"];
     $match = $name["match"];
     $name = $name["name"];
     if (!$name) {
         $name = "lang";
     }
     if (!$folder) {
         $folder = THEMES_PATH;
     }
     if ($folder == LANGUAGES_PATH || $folder == THEMES_PATH) {
         $onlydir = true;
     }
     $res = file::o()->open_folder($folder, $onlydir);
     $count = count($res);
     $options = "";
     for ($i = 0; $i < $count; $i++) {
         $cur = $res[$i];
         $value = $cur;
         $matches = array();
         if ($folder == LANGUAGES_PATH && lang::o()->visset("lang_" . $cur)) {
             $value = lang::o()->v("lang_" . $cur);
         }
         if ($folder == THEMES_PATH && strtolower($value) == strtolower(ADMIN_THEME)) {
             continue;
         }
         if ($regexp && !preg_match($regexp, $cur, $matches)) {
             continue;
         }
         if ($matches && $match) {
             $value = $cur = $matches[$match];
         }
         $options .= "<option value='" . $cur . "'" . ($cur == $current ? " selected='selected'" : "") . ">" . $value . "</option>";
     }
     if (!$options) {
         return;
     }
     if ($null) {
         $options = $this->get_null_text() . $options;
     }
     $html = "<select name=\"" . $name . "\">" . $options . "</select>";
     return $html;
 }
コード例 #16
0
ファイル: class.lang.php プロジェクト: SjayLiFe/CTRev
 /**
  * Замена языкового файла
  * @param string $f изменяемый файл(!тип файла не указывается!)
  * @param array $arr новый массив
  * @param string $folder дирректория языка
  * @return null
  */
 public function set($f, $arr, $folder = null)
 {
     if (!$folder) {
         $folder = $this->folder;
     }
     $out = '$languages = array(';
     foreach ($arr as $key => $value) {
         if (is_numeric($key)) {
             $out .= "\$this->splitter(" . var_export($this->cut_splitter($value), true) . "),\n";
         } else {
             $out .= "\t" . var_export($key, true) . " => " . var_export($value, true) . ",\n";
         }
     }
     $out = "<?php\n" . rtrim($out, ",\n") . ");\n?>";
     file::o()->write_file($out, LANGUAGES_PATH . '/' . $folder . '/' . $f . '.php');
 }
コード例 #17
0
ファイル: class.file.php プロジェクト: SjayLiFe/CTRev
 /**
  * Получение объекта класса
  * @return file $this
  */
 public static function o()
 {
     if (!self::$o) {
         self::$o = new self();
     }
     return self::$o;
 }
コード例 #18
0
ファイル: class.display.php プロジェクト: SjayLiFe/CTRev
 /**
  * Выборка файлов(для АЦ)
  * @param string $path путь к дирректории
  * @param string $name имя дирректории
  * @param string $folder выбранная дирректория
  * @param array $apaths разрешённые дирректории внутри основной
  * @param bool $deny_delete запретить удалять?
  * @return null
  */
 public function filechooser($path, $name, $folder = null, $apaths = null, $deny_delete = false)
 {
     $ajax = globals::g('ajax');
     if (!validfolder($name, $path)) {
         return;
     }
     lang::o()->get('admin/filechooser');
     $npath = ($path ? $path . '/' : '') . $name;
     if ($apaths) {
         $apaths = (array) $apaths;
     }
     if ($folder) {
         $folder = preg_replace('/(?:^|^(.*)\\/)[^\\/]+\\/\\.\\.\\/$/siu', '\\1', $folder);
         $folder = rtrim($folder, '/');
         $folder = validpath($folder . '/', false, $apaths);
         $folder = rtrim($folder, '/');
         if ($folder) {
             $npath .= "/" . rtrim($folder, '/');
         }
     }
     $rows = file::o()->open_folder($npath, false, '^.+(\\.[a-z]+)?$');
     if ($rows === false) {
         return;
     }
     file::o()->sort($npath, $rows);
     $arr = array();
     foreach ($rows as $row) {
         $f = ROOT . $npath . '/' . $row;
         if (!$folder && $apaths && !validpath($row . '/', false, $apaths)) {
             continue;
         }
         if ($row == 'index.html') {
             continue;
         }
         $arr[$row] = array(is_dir($f), is_writable($f), filesize($f), filemtime($f));
     }
     tpl::o()->assign('id', $name);
     tpl::o()->assign('files', $arr);
     tpl::o()->assign('deny_add', false);
     if ($folder) {
         tpl::o()->assign('parent', $folder . '/');
     } elseif ($apaths) {
         tpl::o()->assign('deny_modify', true);
     }
     tpl::o()->assign('deny_delete', (bool) $deny_delete);
     if ($ajax) {
         ok(true);
     }
     tpl::o()->display('admin/filechooser.tpl');
 }
コード例 #19
0
ファイル: class.image.php プロジェクト: SjayLiFe/CTRev
 /**
  * Функция для изменения размера изображения
  * @param string|array $filepath путь к файлу
  * если массив, то первый элемент - путь, второй - с типом изображения
  * @param int $maxwidth макс. ширина изображения
  * @param int $maxheight макс. высота изображения
  * @param int $curwidth текущая ширина изображения
  * @param int $curheight текущая высота изображения
  * @param string $new_name путь, куда будет сохраняться уменьшенное изображение
  * @param bool $cut обрезать до размеров превью? 
  * @return bool true, в случае успешного выполения функции
  * @throws EngineException 
  */
 public function resize($filepath, $maxwidth = "", $maxheight = "", $curwidth = "", $curheight = "", $new_name = "", $cut = false)
 {
     lang::o()->get('file');
     if (is_array($filepath)) {
         list($filepath, $type) = $filepath;
         $type = file::o()->get_filetype($type);
     } else {
         $type = file::o()->get_filetype($filepath);
     }
     if ($type == "jpg") {
         $type = "jpeg";
     }
     if (!$type) {
         throw new EngineException("file_false_name");
     }
     if (!$curwidth || !$curheight) {
         $wh = $this->is_image(ROOT . $filepath, true);
         $curwidth = $wh[0];
         $curheight = $wh[1];
     }
     if (!$maxheight && !$maxwidth || !($curwidth >= $maxwidth && $maxwidth || $curheight >= $maxheight && $maxheight)) {
         throw new EngineException('file_unknown_resize', array($maxwidth ? $maxwidth : unended, $maxheight ? $maxheight : unended));
     }
     $imagecftype = 'imagecreatefrom' . $type;
     $imagetype = 'image' . $type;
     if (!function_exists($imagecftype) || !function_exists($imagetype)) {
         throw new EngineException(lang::o()->v('file_unknown_type') . lang::o()->v('file_ft_images'));
     }
     $source = @$imagecftype($filepath);
     if (!$source) {
         throw new EngineException(lang::o()->v('file_unknown_type') . lang::o()->v('file_ft_images'));
     }
     $source_x = $source_y = 0;
     $ratio = $curwidth / $curheight;
     $new_w = $maxwidth;
     $new_h = $maxheight;
     $ratio_n = $new_h ? $new_w / $new_h : 0;
     if (!$maxheight || $ratio > $ratio_n) {
         $new_h = longval($new_w / $ratio);
     } else {
         $new_w = longval($new_h * $ratio);
     }
     if ($cut && $ratio_n && $ratio_n != $ratio) {
         if ($new_w == $maxwidth) {
             $delta = $curheight * $ratio_n;
             $source_x = longval(($curwidth - $delta) / 2);
             $curwidth = longval($delta);
         } else {
             $delta = $curwidth / $ratio_n;
             $source_y = longval(($curheight - $delta) / 2);
             $curheight = longval($delta);
         }
         $new_w = $maxwidth;
         $new_h = $maxheight;
     }
     $target = imagecreatetruecolor($new_w, $new_h);
     @imagecopyresampled($target, $source, 0, 0, $source_x, $source_y, $new_w, $new_h, $curwidth, $curheight);
     $ret = $imagetype($target, ROOT . (!$new_name ? $filepath : $new_name));
     @imagedestroy($target);
     @imagedestroy($source);
     if (!$ret) {
         throw new EngineException("file_unknown_error");
     }
     return true;
 }