if (!isset($app['sys']['local']))
$app['sys']['local'] = $_SERVER['REMOTE_ADDR'] == '127.0.0.1';
$app['path']['go'] = '/go/';
// Rewrite
function rewrite_ext($path, $ext)
{
$pos = strpos($path, '?');
if ($pos != false)
{
$param = substr($path, $pos);
$path = substr($path, 0, $pos);
}
else
$param = '';
if ($ext && (substr($path, -1, 1) == '/') && ($path != '/'))
return substr($path, 0, -1).'.'.$ext.$param;
else
return $path.$param;
}
function rewrite_ext_remove($path, $ext)
{
if ($ext && (substr($path, -(strlen($ext) + 1)) == '.'.$ext))
return substr($path, 0, -(strlen($ext) + 1)).'/';
else
return $path;
}
function rewrite_auto_ext($path)
{
global $app;
return rewrite_ext($path, $app['path']['auto-ext']);
}
function rewrite_auto_ext_remove($path)
{
global $app;
return rewrite_ext_remove($path, $app['path']['auto-ext']);
}
function redirect($url)
{
if (function_exists('save_settings'))
save_settings();
if (isset($url))
Header("Location: ".$url);
else
Header("Location: .");
die();
}
function file_ext($filename)
{
$file_ext = pathinfo($filename);
$file_ext = strtolower($file_ext['extension']);
return $file_ext;
}
function mime_ext($filename)
{
$filename = file_ext($filename);
$a = array(
'txt' => 'text/plain; charset=windows-1251',
'css' => 'text/css; charset=windows-1251',
'js' => 'application/javascript; charset=windows-1251',
'xml' => 'text/xml; charset=windows-1251',
'gif' => 'image/gif',
'jpg' => 'image/jpg',
'png' => 'image/png'
);
$res = isset($a[$filename]) ? $a[$filename] : 'application/octet-stream';
return $res;
}
$url = @parse_url($_SERVER["REQUEST_URI"]);
if (strpos($url['path'], '/exe/') === 0)
{
include $app['path']['cms'].'/exe/'.substr($url['path'], 5);
die();
}
if (strpos($url['path'], '/res/') === 0)
{
$file = $app['path']['cms'].'/res/'.substr($url['path'], 5);
if (is_file($file))
{
$mime = mime_ext($file);
header('Content-type:'.($mime ? ' '.$mime : ''));
header('Cache-Control: must-revalidate');
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($file)).' GMT');
header('X-Powered-By:');
header('Pragma:');
readfile($file);
}
else
{
header("Content-type:");
header('Cache-Control: must-revalidate');
header('HTTP/1.0 404 Not Found');
}
die();
}
if (strpos($_SERVER["REQUEST_URI"], '/video-file/') === 0)
{
include $app['path']['cms'].'/video.php';
die();
}
session_name('session');
session_start();
$page['number'] = isset($_GET['page']) ? (int)$_GET['page'] - 1 : 0;
if (!$app['site']['url'])
$app['site']['url'] = $_SERVER['SERVER_NAME']; // URL сайта
$app['site']['url-http'] = 'https://'.$app['site']['url'].'/';
$page['fullpath'] = strpos($_SERVER["REQUEST_URI"], '?');
$page['fullpath'] = urldecode($page['fullpath'] ? substr($_SERVER["REQUEST_URI"], 0, $page['fullpath']) : $_SERVER["REQUEST_URI"]);
$page['realpath'] = $page['fullpath'];
$page['fullpath'] = rewrite_auto_ext_remove($page['fullpath']);
$page['fullpath-all'] = $page['fullpath']; // С номером страницы
if ($app['pager']['type'] == '.')
{
$page['number'] = 0;
if ($page['fullpath'] != '/')
{
if ($ps = strrpos($page['fullpath'], '.'))
{
$page['number'] = +substr($page['fullpath'], $ps + 1, -1);
$page['fullpath'] = substr($page['fullpath'], 0, $ps).'/';
if ($page['number'])
$page['number']--;
}
}
}
$page['path'] = $page['fullpath'];
function antispam()
{
$spamcontrol_length = 4;
$spamcontrol_size = '5';
header("Content-Type: image/gif");
$font_size = $spamcontrol_size;
$width = imagefontwidth($font_size) * $spamcontrol_length * 2 + 24;
$height = 24;
$img = imagecreatetruecolor($width, $height);
$bg = imagecolorallocate($img, 255, 255, 255);
imagefilledrectangle($img, 0, 0, $width-1, $height-1, $bg);
/*for($i = 0; $i < $spamcontrol_length; $i++)
{
$c = rand(0, 64);
$font_color = imagecolorallocate($img, $c, $c, $c);
imagestring($img, 1, rand(0, imagefontwidth($font_size)), imagefontheight($font_size) * $i + rand(0, imagefontheight($font_size) / 2), "Preved AntiSPAM!!!", $font_color);
}*/
$antispam = '';//'Antispam Protector ';
for($i = 0; $i < $spamcontrol_length; $i++)
{
$c = rand(0, 64);
$font_color = imagecolorallocate($img, $c, $c, $c);
$xpos = imagefontwidth($font_size) + 2 * $i * imagefontwidth($font_size) + rand(0, imagefontwidth($font_size));
$ypos = 4;// + rand(0, 0);
$str = rand(0, 9);
imagechar($img, $font_size, $xpos, $ypos, $str, $font_color);
$antispam .= $str;
}
$img2=imagecreatetruecolor($width, $height);
// случайные параметры (можно поэкспериментировать с коэффициентами):
// частоты
$rand1 = mt_rand(700000, 1000000) / 15000000;
$rand2 = mt_rand(700000, 1000000) / 15000000;
$rand3 = mt_rand(700000, 1000000) / 15000000;
$rand4 = mt_rand(700000, 1000000) / 15000000;
// фазы
$rand5 = mt_rand(0, 3141592) / 1000000;
$rand6 = mt_rand(0, 3141592) / 1000000;
$rand7 = mt_rand(0, 3141592) / 1000000;
$rand8 = mt_rand(0, 3141592) / 1000000;
// амплитуды
$rand9 = mt_rand(100, 400) / 100;
$rand10 = mt_rand(100, 400) / 100;
for($x = 0; $x < $width; $x++){
for($y = 0; $y < $height; $y++){
// координаты пикселя-первообраза.
$sx = $x + ( sin($x * $rand1 + $rand5) + sin($y * $rand3 + $rand6) ) * $rand9;
$sy = $y + ( sin($x * $rand2 + $rand7) + sin($y * $rand4 + $rand8) ) * $rand10;
// первообраз за пределами изображения
if($sx < 0 || $sy < 0 || $sx >= $width - 1 || $sy >= $height - 1){
$color = 255;
$color_x = 255;
$color_y = 255;
$color_xy = 255;
}else{ // цвета основного пикселя и его 3-х соседей для лучшего антиалиасинга
$color = (imagecolorat($img, $sx, $sy) >> 16) & 0xFF;
$color_x = (imagecolorat($img, $sx + 1, $sy) >> 16) & 0xFF;
$color_y = (imagecolorat($img, $sx, $sy + 1) >> 16) & 0xFF;
$color_xy = (imagecolorat($img, $sx + 1, $sy + 1) >> 16) & 0xFF;
}
//$color = 0;
//$color += 2;
// сглаживаем только точки, цвета соседей которых отличается
if($color == $color_x && $color == $color_y && $color == $color_xy){
{
$newcolor=$color;
}
}
else
{
$frsx = $sx - floor($sx); //отклонение координат первообраза от целого
$frsy = $sy - floor($sy);
$frsx1 = 1 - $frsx;
$frsy1 = 1 - $frsy;
// вычисление цвета нового пикселя как пропорции от цвета основного пикселя и его соседей
$newcolor = floor( $color * $frsx1 * $frsy1 +
$color_x * $frsx * $frsy1 +
$color_y * $frsx1 * $frsy +
$color_xy * $frsx * $frsy );
}
//if (rand(0, 100) > 90)
if ($newcolor < 150)
$newcolor = rand(0, 150);
imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newcolor * 1, $newcolor * 1, $newcolor * 1));
}
}
$_SESSION['antispam'] = $antispam;
imagegif($img2);
imagedestroy($img);
imagedestroy($img2);
die();
}
if ($page['path'] == '/antispam/')
{
antispam();
die();
}
if ($page['path'] == $app['path']['go'])
{
redirect($_SERVER['QUERY_STRING']);
die();
}
if (strrpos($url['path'], '/') === strlen($url['path']) - 1)
{
switch (substr($url['path'], -5, -1))
{
case '.jpg':
case '.gif':
case '.png':
include_once $app['path']['cms'].'/tpl/pic.htm';
die();
break;
}
}
define("cr", CHR(13).CHR(10));
$root = $_SERVER['DOCUMENT_ROOT'];
$app['app']['version'] = '1.2';
$app['option']['correct-path'] = true;
// Таблица данных
$app['grid']['active-label'][true] = 'да';
$app['grid']['active-label'][false] = '';
/**/
/*$app['layout']['comment']['']['block']['comment'] = 'comment';
$app['layout']['comment']['']['title'] = 'Комментарии';
$app['layout']['comment']['hide'] = true;*/
/**/
$app['layout']['']['']['block'][''] = 'text';
$app['layout']['']['']['block']['comment'] = 'comment';
$app['layout']['']['']['title'] = 'Текст';
$app['layout']['']['admin']['block'][''] = 'text';
$app['layout']['']['admin']['title'] = 'Текст';
$app['layout']['']['admin']['template'] = 'admin';
$app['layout']['silent']['']['block'][''] = 'silent';
$app['layout']['silent']['']['title'] = 'Пусто';
$app['layout']['silent']['admin']['block'][''] = 'silent';
$app['layout']['silent']['admin']['title'] = 'Пусто';
$app['layout']['silent']['admin']['template'] = 'admin';
$app['layout']['map']['']['block'][''] = 'map';
$app['layout']['map']['']['title'] = 'Карта сайта';
$app['layout']['poll']['']['block'][''] = 'poll';
$app['layout']['poll']['']['title'] = 'Опрос';
$app['layout']['good']['']['block'][''] = 'good';
$app['layout']['good']['']['title'] = 'Товары';
$app['layout']['search']['']['block'][''] = 'search';
$app['layout']['search']['']['title'] = 'Поиск';
$app['layout']['feedback']['']['block'][''] = 'feedback';
$app['layout']['feedback']['']['block']['comment'] = 'comment';
$app['layout']['feedback']['']['title'] = 'Обратная связь';
$app['layout']['catalog']['']['block'][''] = 'catalog';
$app['layout']['catalog']['']['title'] = 'Каталог';
$app['layout']['fcatalog']['']['block'][''] = 'fcatalog';
$app['layout']['fcatalog']['']['title'] = 'Каталог фирм';
$app['layout']['fcatalog']['admin']['block'][''] = 'fcatalog';
$app['layout']['fcatalog']['admin']['title'] = 'Каталог фирм';
$app['layout']['fcatalog']['admin']['template'] = 'admin';
$app['layout']['catalog-puh']['']['block'][''] = 'catalog-puh';
$app['layout']['catalog-puh']['']['title'] = 'Каталог пух';
$app['layout']['catalog-puh']['admin']['block'][''] = 'catalog-puh';
$app['layout']['catalog-puh']['admin']['title'] = 'Каталог пух';
$app['layout']['catalog-puh']['admin']['template'] = 'admin';
$app['layout']['feedback']['admin']['block'][''] = 'feedback';
$app['layout']['feedback']['admin']['title'] = 'Обратная связь';
$app['layout']['feedback']['admin']['template'] = 'admin';
$app['layout']['app']['admin']['block'][''] = 'app';
$app['layout']['app']['admin']['title'] = 'Приложение';
$app['layout']['app']['admin']['template'] = 'admin';
$app['layout']['admin']['admin']['block'][''] = 'admin';
$app['layout']['admin']['admin']['title'] = 'Админка';
$app['layout']['page']['admin']['template'] = 'admin';
$app['layout']['page']['admin']['block'][''] = 'page';
$app['layout']['page']['admin']['title'] = 'Страницы';
$app['page']['/admin/']['title'] = 'Управление сайтом';
$app['page']['/admin/']['active'] = true;
$app['page']['/admin/']['layout'] = 'admin';
$app['page']['/admin/app/']['title'] = 'Приложение';
$app['page']['/admin/app/']['active'] = true;
$app['page']['/admin/app/']['layout'] = 'app';
$app['page']['/admin/page/']['title'] = 'Страницы';
$app['page']['/admin/page/']['active'] = true;
$app['page']['/admin/page/']['layout'] = 'page';
$app['page']['/admin/catalog-puh/']['title'] = 'Каталог пух';
$app['page']['/admin/catalog-puh/']['active'] = true;
$app['page']['/admin/catalog-puh/']['layout'] = 'catalog-puh';
$app['page']['/admin/feedback/']['title'] = 'Обратная связь';
$app['page']['/admin/feedback/']['active'] = true;
$app['page']['/admin/feedback/']['layout'] = 'feedback';
// Меню админки
$app['menu']['admin'] = array(
'/' => array('title' => 'Главная'),
'/admin/' => array('title' => 'Управление', items => array(
'/admin/page/' => array('title' => 'Страницы'),
'/admin/menu/' => array('title' => 'Меню'),
'/admin/app/' => array('title' => 'Приложение'),
'/admin/page/?map' => array('title' => 'Анкоры'),
'/admin/page/?catcms' => array('title' => 'Экспорт в catcms'),
'/admin/page/?hamstercms' => array('title' => 'Экспорт в hamster.cms')
))
);
function on_load_settings()
{
global $settings;
}
?>
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
elseif (isset($_SERVER['HTTP_X_REAL_IP']))
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
$PREFER_DEFLATE = false;
$FORCE_COMPRESSION = false;
function compress_output_gzip($output)
{
return gzencode($output);
}
function compress_output_deflate($output)
{
return gzdeflate($output, 9);
}
if(isset($_SERVER['HTTP_ACCEPT_ENCODING']))
$AE = $_SERVER['HTTP_ACCEPT_ENCODING'];
else
$AE = $_SERVER['HTTP_TE'];
$support_gzip = (strpos($AE, 'gzip') !== FALSE) || $FORCE_COMPRESSION;
$support_deflate = (strpos($AE, 'deflate') !== FALSE) || $FORCE_COMPRESSION;
if($support_gzip && $support_deflate)
{
$support_deflate = $PREFER_DEFLATE;
}
if ($support_deflate)
{
header("Content-Encoding: deflate");
ob_start("compress_output_deflate");
}
else
{
if($support_gzip)
{
header("Content-Encoding: gzip");
ob_start("compress_output_gzip");
} else
{
ob_start();
}
}
$auth_ok = false;
$auth_user = 'public';
$auth_user_title = 'Посетитель';
$auth_admin = false;
if (isset($_SESSION['auth_ok']) and $_SESSION['auth_ok'])
{
$auth_ok = true;
$auth_user = $_SESSION['auth_user'];
$auth_user_title = $_SESSION['auth_user_title'];
}
$auth_admin = $auth_user == 'admin';
function base64_url_encode($input)
{
return strtr(base64_encode($input), '+/=', '-_,');
}
function base64_url_decode($input)
{
return base64_decode(strtr($input, '-_,', '+/='));
}
function cyrtoupper($content)
{
$content = strtr($content, 'абвгдеёжзийклмнорпстуфхцчшщъьыэюя', 'АБВГДЕЁЖЗИЙКЛМНОРПСТУФХЦЧШЩЪЬЫЭЮЯ');
return strtoupper($content);
}
function cyrtolower($content)
{
$content = strtr($content, 'АБВГДЕЁЖЗИЙКЛМНОРПСТУФХЦЧШЩЪЬЫЭЮЯ', 'абвгдеёжзийклмнорпстуфхцчшщъьыэюя');
return strtolower($content);
}
function cyrtolower_auto($content)
{
if ($content == cyrtoupper($content))
$content = cyrtolower($content);
return $content;
}
function cyrcapitalize($content)
{
$st = 'абвгдеёжзийклмнорпстуфхцчшщъьыэюяАБВГДЕЁЖЗИЙКЛМНОРПСТУФХЦЧШЩЪЬЫЭЮЯabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$s = strtr($content, $st, str_repeat('a', strlen($st)));
$pos = strpos($s, 'a');
$content = substr($content, 0, $pos).cyrtoupper(substr($content, $pos, 1)).substr($content, $pos + 1);
return $content;
}
function cyruncapitalize($content)
{
$st = 'абвгдеёжзийклмнорпстуфхцчшщъьыэюяАБВГДЕЁЖЗИЙКЛМНОРПСТУФХЦЧШЩЪЬЫЭЮЯabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$s = strtr($content, $st, str_repeat('a', strlen($st)));
$pos = strpos($s, 'a');
$content = substr($content, 0, $pos).cyrtolower(substr($content, $pos, 1)).substr($content, $pos + 1);
return $content;
}
// Добавить http
function url_http($url)
{
if (strpos($url, 'http://') !== 0)
$url = 'http://'.$url;
return $url;
}
// Ссылка через редирект
function go($url)
{
global $app;
return html_escape(rewrite_auto_ext($app['path']['go']).'?'.url_http($url));
}
function html_escape($text)
{
return htmlspecialchars($text, ENT_QUOTES,'cp1251', true);
}
function utf2win($str)
{
for ($i = 144; $i <= 191; $i++)
$cp1251[chr(208).chr($i)] = chr(192 + ($i - 144));
for ($i = 128; $i <= 143; $i++)
$cp1251[chr(209).chr($i)] = chr(240 + ($i - 128));
$cp1251[chr(208).chr(129)] = 'Ё';
$cp1251[chr(209).chr(145)] = 'ё';
$cp1251[chr(208).chr(129)] = 'Ё';
$cp1251[chr(209).chr(145)] = 'ё';
$tmp = '';
for ($i = 1, $len = strlen($str); $i < $len; $i++)
{
$c1 = $str[$i - 1];
$c2 = $str[$i];
if ($c1 == chr(208) || $c1 == chr(209))
{
$c = $cp1251[$c1.$c2];
$tmp .= (isset($c) ? $c : "?");
$i++;
}
else
$tmp .= $c1;
}
return $tmp;
}
// Удалить множественные пробелы
function remove_multispace($text)
{
return preg_replace('/[ ]+/', ' ', $text);
}
if (!$_SESSION['app']['referer'])
$_SESSION['app']['referer'] = utf2win(urldecode($_SERVER['HTTP_REFERER'].' '));
if (!$_SESSION['app']['firstpage'])
$_SESSION['app']['firstpage'] = utf2win(urldecode($_SERVER['REQUEST_URI'].' '));
// Date
function date_timestamp($value = '')
{
if ($value)
return date("d.m.Y", strtotime($value)).' '.date("H:i:s", strtotime($value));
else
return date("d.m.Y", time()).' '.date("H:i:s", time());
}
function date_date($value = '')
{
if ($value)
return date("d.m.Y", strtotime($value));
else
return date("d.m.Y", time());
}
function date_str_to_int($value)
{
if (!$value)
return NULL;
$date = sscanf($value, '%d.%d.%d %d:%d:%d');
return date('YmdHis', mktime($date[3], $date[4], $date[5], $date[1], $date[0], $date[2]));
}
function date_to_int($value = '')
{
if ($value)
return date('YmdHis', strtotime($value));
else
return date('YmdHis', time());
}
function date_only_to_int($value)
{
return date('Ymd', strtotime($value)).'000000';
}
// Currency
function str_to_currency($text)
{
$result = str_replace(',', '.', $text) + 0.0;
return $result;
}
function currency_to_str($curr)
{
return sprintf("%01.2f", $curr);
}
// Загрузка файла в строку
function file_to_string($filename)
{
return file_get_contents($filename);
}
// Сохранение строки в файл
function string_to_file($filename, $value)
{
if (!$handle = fopen($filename, 'wb'))
return;
if (flock($handle, LOCK_EX))
{
$result = @fwrite($handle, $value);
flock($handle, LOCK_UN);
}
else
$result = false;
fclose($handle);
return $result;
}
// Максимальный ключ в массиве
function max_array_key(&$arr)
{
$id = 0;
foreach ($arr as $key => $value)
{
$key = (int)$key;
if ($key > $id)
$id = $key;
}
return $id;
}
//
function antispam_ok()
{
return isset($_POST['antispam']) && isset($_SESSION['antispam']) && ($_POST['antispam'] == $_SESSION['antispam']);
}
function antispam_reset()
{
unset($_SESSION['antispam']);
}
$out = array();
$out_index = array();
function start_out($index = '')
{
global $out_index;
global $out;
if (count($out_index))
$out[$out_index[count($out_index) - 1]] .= ob_get_contents();
$out_index[] = $index;
$out[$index] = '';
ob_clean();
}
function end_out()
{
global $out;
global $out_index;
$index = array_pop($out_index);
$out[$index] .= ob_get_contents();
ob_clean();
return $out[$index];
}
ob_start();
function cms_boot($module)
{
global $app;
if ($app['boot'][$module]['boot'])
return;
$app['boot'][$module]['boot'] = true;
include_once $app['path']['cms'].'/mod/'.$module.'/boot.php';
}
function is_my_module($id = '')
{
global $page;
if ($id == '')
$id = $_GET['mod'];
return $page['layout-block'] == $id;
}
function is_mod_cmd()
{
return isset($_GET['act']) && is_my_module();
}
function mod_cmd()
{
return $_GET['act'];
}
function mod_form_id()
{
global $page;
return 'fm_'.html_escape($page['layout-block']);
}
function mod_link($act = '')
{
global $page;
$result = $page['layout-block'] ? '?mod='.html_escape($page['layout-block']) : '';
$result .= $act ? ($result ? '&' : '?').'act='.html_escape($act) : '';
return $result;
}
function get_mod_form_start($action = '')
{
global $page;
$act = $page['layout-block'] ? '?mod='.html_escape($page['layout-block']) : '';
$act .= ($action ? ($act ? '&' : '?').'act='.$action : '');
return '
';
}
function mod_form_end()
{
echo get_mod_form_end();
}
function mod_form_param($name, $value = '')
{
echo '';
}
function mod_form_buttons($buttons)
{
foreach ($buttons as $button)
{
if (isset($button['act']))
{
$url = $button['url'];
if ($button['title'] != '')
$title = $button['title'];
else
{
$title = array('ok' => 'OK', 'cancel' => 'Отмена', 'back' => 'Назад');
$title = $title[$button['act']];
}
echo ' ';
};
}
}
function mod_edit_table_start()
{
echo '';
}
function mod_edit_table_end()
{
echo '
';
}
function mod_edit_table_select($id)
{
echo '';;
}
function mod_edit_table_focus($id)
{
echo '';;
}
// Таблица данных
unset($data_table);
function data_table_start($params)
{
global $data_table;
$data_table['button'] = $params['button'];
$data_table['column'] = $params['column'];
$data_table['row'] = 0;
admin_data_tool($data_table);
echo '';
admin_data_tool($data_table);
}
function pager_links($url, $num_pages, $page_num)
{
global $app;
if ($app['pager']['type'] == '.')
{
$url = rtrim($url, '/');
if ($num_pages > 1)
{
echo '';
}
}
else
{
if ($url == '')
$url = '.';
else
$url = rewrite_auto_ext($url);
if (strrpos('1'.$url, '?') || strpos('1'.$url, '&'))
{
$url .= '&';
}
else
$url .= '?';
if ($num_pages > 1)
{
echo '';
}
}
}
// Преобразовать страницы в меню
function pages_menu(&$pages, $hide)
{
$ret = array();
foreach ($pages as $path => $pg)
{
if (!$pg['active'] || in_array($path, $hide))
continue;
$ret[$path] = array(
'title' => $pg['heading'] == '' ? $pg['title'] : $pg['heading']
);
}
return $ret;
}
// Вывод меню
function render_menu($menu, $tpl, $tpl_active, $tpl_sub=' ', $max_level=0, $show_active_sub=1, $splitter='')
{
if (!$menu)
return;
global $app, $settings, $page;
global $page;
$ret = '';
$ppath = $page['path'];
if (!$settings['page'][$ppath])
{
$pos = strrpos(rtrim($ppath, '/'), '/');
$spos = substr($ppath, 0, $pos + 1);
$ppath = $spos;
}
$hr = 0;
foreach ($menu as $key => $value)
{
$active = (($key == '/') && ($key == $ppath)) || (($key != '/') && (strpos($ppath, $key) === 0));
$level = max(count(explode('/', $key)) - 3 + (substr($key, -1, 1) == '/' ? 0 : 1), 0);
$plevel = max(count(explode('/', $ppath)) - 3 + (substr($ppath, -1, 1) == '/' ? 0 : 1), 0);
$pos = strrpos(rtrim($ppath, '/'), '/');
$spos = substr($ppath, 0, $pos + 1);
if (!(($level == $plevel) && (strpos($key, $spos) === 0)))
if ($max_level && ($level >= $max_level))
{
if ($show_active_sub && ($level - $plevel > $show_active_sub))
continue;
if ($ppath == '/')
continue;
if (!((strpos($ppath, $key) === 0) || (strpos($key, $ppath) === 0)))
continue;
}
if ($settings['page'][$key]['stop'] || ($app['sys']['date'] < $settings['page'][$key]['date']))
continue;
if ($hr)
$ret .= $splitter;
if ($active)
$ret .= strtr($tpl_active, array('[url]' => rewrite_auto_ext($key), '[title]' => $value['title'], '[sub]' => str_repeat($tpl_sub, $level)));
else
$ret .= strtr($tpl, array('[url]' => rewrite_auto_ext($key), '[title]' => $value['title'], '[sub]' => str_repeat($tpl_sub, $level)));
$hr++;
}
return $ret;
}
// Путь к следующей или предыдущей странице данного уровня
function relink_link($page_path='', $next=true)
{
global $page, $settings;
if ($page_path == '')
$page_path = $page['path'];
$plist = array();
$level = substr_count($page_path, '/');
$par = strrpos(rtrim($page_path, '/'), '/');
$par = substr($page_path, 0, $par + 1);
foreach ($settings['page'] as $path => $pg)
{
if (!$pg['active'])
continue;
if ((substr_count($path, '/') == $level) && (strpos($path, $par) === 0))
{
$plist[$path] = $pg['sort'].CHR(0).(($pg['heading'] ? $pg['heading'] : $pg['title']).CHR(0));
}
}
asort($plist);
$hr = 0;
$prev = '';
$plist[''] = '';
foreach ($plist as $path => $tmp)
{
if ($hr)
{
if (!$next)
$path = $prev;
return $path;
}
if ($path == $page_path)
$hr = true;
if ($path != $page_path)
$prev = $path;
}
return '';
}
function relink($page_path='', $tpl='')
{
global $settings;
if ($tpl == '')
$tpl = '{<}{>}
';
$l = relink_link($page_path, false);
if (!$settings['page'][$l]['relink'])
$l = '';
$r = relink_link($page_path);
if (!$settings['page'][$r]['relink'])
$r = '';
if (($l == '') && ($r == ''))
return '';
$ls = $settings['page'][$l]['heading'] ? $settings['page'][$l]['heading'] : $settings['page'][$l]['title'];
$rs = $settings['page'][$r]['heading'] ? $settings['page'][$r]['heading'] : $settings['page'][$r]['title'];
$l = ''.html_escape($ls).'';
$r = ''.html_escape($rs).'';
return strtr($tpl, array('{<}' => $l, '{>}' => $r));
}
function sape($active, $user, $blocks, $tpl='{text}')
{
global $app;
if ($app['sys']['local'])
{
foreach ($blocks as $key => $value)
{
for ($i=1; $i<=$value; $i++)
$app['sape']['text'][$key + 1] .= ($i > 1 ? ' ' : '').'В этом месте сапоссылка №'.($key + 1).($value > 1 ? '-'.$i : '').' сидит.';
$app['sape']['text'][$key + 1] = strtr($tpl, array('{text}' => $app['sape']['text'][$key + 1]));
}
$app['sape']['text'][0] = 'Здесь оставшиеся сапоссылки: здесь. И вот тут.';
$app['sape']['text'][0] = strtr($tpl, array('{text}' => $app['sape']['text'][0]));
}
elseif ($active)
{
define('_SAPE_USER', $user);
require_once($_SERVER['DOCUMENT_ROOT'].'/'._SAPE_USER.'/sape.php');
$o = array();
$o['request_uri'] = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER["REQUEST_URI"], '?'));
if (($app['pager']['type'] != '.') && (int)$_GET['page'])
$o['request_uri'] .= '?page='.(int)$_GET['page'];
$o['charset'] = mb_internal_encoding();
$sape = new SAPE_client($o);
foreach ($blocks as $key => $value)
{
$app['sape']['text'][$key + 1] = $sape->return_links($value);
}
$app['sape']['text'][0] = $sape->return_links();
$app['sape']['text'][0] = strtr($tpl, array('{text}' => $app['sape']['text'][0]));
}
}
$css_list = array();
function use_css($url = '')
{
global $css_list;
global $page;
if (!$url)
$url = '/ui/'.html_escape($page['layout-mod']).'/main.css';
$css_list[$url] = true;
}
function use_css_write()
{
global $css_list;
foreach ($css_list as $url => $url2)
echo ''.cr;
}
function use_template()
{
global $root;
global $page;
if (is_file($root.'/ui/'.$page['layout-mod'].'/main.php'))
include_once $root.'/ui/'.$page['layout-mod'].'/main.php';
else
echo 'Ошибка. Файл шаблона модуля '.$page['layout-mod'].' не найден.';
}
function template($name, $params = NULL)
{
if (function_exists($name))
call_user_func($name, $params);
}
$smiles = array();
include_once $app['path']['cms'].'/bb.php';
function my_tag($value)
{
global $smiles;
$bb = new bbcode($value);
$bb -> mnemonics = $smiles;
return $bb -> get_html();
}
function text_format($value)
{
global $smiles;
$bb = new bbcode($value);
$bb -> mnemonics = $smiles;
return $bb -> get_html();
}
function text_normalize($value)
{
return str_replace(
array(chr(0x93), chr(0x94), ' - ', chr(0x0d).chr(0x0a).'-', ' '.chr(0x0d).chr(0x0a), '¬'),
array('"', '"', ' '.chr(0x97).' ', chr(0x0d).chr(0x0a).chr(0x97), chr(0x0d).chr(0x0a), ''),
$value);
}
function text_to_textarea($value)
{
//return str_replace('[br]', cr, chop(html_escape($value)));
return chop(html_escape($value));
}
function text_to_html($value)
{
return str_replace(cr, '
', chop(html_escape($value)));
}
function tpl($tpl, $var)
{
if (!$var)
return;
foreach ($var as $key => $value)
{
$v['<#'.$key.'#>'] = $value;
}
return strtr($tpl, $v);
}
$translit = array();
$translit['0'] = '0';
$translit['1'] = '1';
$translit['2'] = '2';
$translit['3'] = '3';
$translit['4'] = '4';
$translit['5'] = '5';
$translit['6'] = '6';
$translit['7'] = '7';
$translit['8'] = '8';
$translit['9'] = '9';
$translit['A'] = 'a';
$translit['a'] = 'a';
$translit['B'] = 'b';
$translit['b'] = 'b';
$translit['C'] = 'c';
$translit['c'] = 'c';
$translit['D'] = 'd';
$translit['d'] = 'd';
$translit['E'] = 'e';
$translit['e'] = 'e';
$translit['F'] = 'f';
$translit['f'] = 'f';
$translit['G'] = 'g';
$translit['g'] = 'g';
$translit['H'] = 'h';
$translit['h'] = 'h';
$translit['I'] = 'i';
$translit['i'] = 'i';
$translit['J'] = 'j';
$translit['j'] = 'j';
$translit['K'] = 'k';
$translit['k'] = 'k';
$translit['L'] = 'l';
$translit['l'] = 'l';
$translit['M'] = 'm';
$translit['m'] = 'm';
$translit['N'] = 'n';
$translit['n'] = 'n';
$translit['O'] = 'o';
$translit['o'] = 'o';
$translit['P'] = 'p';
$translit['p'] = 'p';
$translit['Q'] = 'q';
$translit['q'] = 'q';
$translit['R'] = 'r';
$translit['r'] = 'r';
$translit['S'] = 's';
$translit['s'] = 's';
$translit['T'] = 't';
$translit['t'] = 't';
$translit['U'] = 'u';
$translit['u'] = 'u';
$translit['V'] = 'v';
$translit['v'] = 'v';
$translit['W'] = 'w';
$translit['w'] = 'w';
$translit['X'] = 'x';
$translit['x'] = 'x';
$translit['Y'] = 'y';
$translit['y'] = 'y';
$translit['Z'] = 'z';
$translit['z'] = 'z';
$translit['А'] = 'a';
$translit['а'] = 'a';
$translit['Б'] = 'b';
$translit['б'] = 'b';
$translit['В'] = 'v';
$translit['в'] = 'v';
$translit['Г'] = 'g';
$translit['г'] = 'g';
$translit['Д'] = 'd';
$translit['д'] = 'd';
$translit['Е'] = 'e';
$translit['е'] = 'e';
$translit['Ё'] = 'e';
$translit['ё'] = 'e';
$translit['Ж'] = 'j';
$translit['ж'] = 'j';
$translit['З'] = 'z';
$translit['з'] = 'z';
$translit['И'] = 'i';
$translit['и'] = 'i';
$translit['Й'] = 'y';
$translit['й'] = 'y';
$translit['К'] = 'k';
$translit['к'] = 'k';
$translit['Л'] = 'l';
$translit['л'] = 'l';
$translit['М'] = 'm';
$translit['м'] = 'm';
$translit['Н'] = 'n';
$translit['н'] = 'n';
$translit['О'] = 'o';
$translit['о'] = 'o';
$translit['П'] = 'p';
$translit['п'] = 'p';
$translit['Р'] = 'r';
$translit['р'] = 'r';
$translit['С'] = 's';
$translit['с'] = 's';
$translit['Т'] = 't';
$translit['т'] = 't';
$translit['У'] = 'u';
$translit['у'] = 'u';
$translit['Ф'] = 'f';
$translit['ф'] = 'f';
$translit['Х'] = 'h';
$translit['х'] = 'h';
$translit['Ц'] = 'c';
$translit['ц'] = 'c';
$translit['Ч'] = 'ch';
$translit['ч'] = 'ch';
$translit['Ш'] = 'sh';
$translit['ш'] = 'sh';
$translit['Щ'] = 'sch';
$translit['щ'] = 'sch';
$translit['Ъ'] = '';
$translit['ъ'] = '';
$translit['Ы'] = 'y';
$translit['ы'] = 'y';
$translit['Ь'] = '';
$translit['ь'] = '';
$translit['Э'] = 'e';
$translit['э'] = 'e';
$translit['Ю'] = 'yu';
$translit['ю'] = 'yu';
$translit['Я'] = 'ya';
$translit['я'] = 'ya';
$translit[' '] = '-';
$translit_path = $translit;
$translit_path['/'] = '/';
$translit_path['.'] = '.';
function title_to_path($title)
{
global $translit;
$result = '';
$last = false;
for($i=0;$i '', CHR(0) => CHR(0).'00','\\(' => CHR(0).'01', '\\)' => CHR(0).'02', '\\|' => CHR(0).'03', '\\#' => CHR(0).'04'));
while (preg_match($pattern, $data) != 0)
{
$alternate_stop = false;
$data = preg_replace_callback($pattern, alternate_callback, $data);
}
return strtr($data, array(CHR(0).'00' => CHR(0), CHR(0).'01' => '(', CHR(0).'02' => ')', CHR(0).'03' => '|', CHR(0).'04' => '#'));
}
function load_settings($mod)
{
global $root;
global $settings;
global $settings_bkup;
$settings[$mod] = unserialize(@file_get_contents($root.'/data/'.$mod));
$settings_bkup[$mod] = $settings[$mod];
on_load_settings();
}
function clear_settings()
{
global $app;
global $settings;
foreach ($settings['text']['page'] as $path => $value)
if (!isset($settings['page'][$path]) && !isset($app['page'][$path]))
unset($settings['text']['page'][$path]);
}
function save_settings()
{
global $root;
global $settings;
global $settings_bkup;
clear_settings();
foreach ($settings as $key => $value)
if ($value != $settings_bkup[$key])
string_to_file($root.'/data/'.$key, serialize($value));
}
// SQL
function sql_escape($text)
{
return mysql_escape_string($text);
}
function sql_query($text)
{
return mysql_query($text);
}
function sql_fetch($data)
{
return mysql_fetch_array($data);
}
function sql_num_rows($data)
{
return mysql_num_rows($data);
}
function sql_insert_id()
{
return mysql_insert_id();
}
function sql_line($table, $id, $where = '')
{
$id = mysql_escape_string($id);
$data = mysql_query("select * from $table where id='$id'".($where ? " and ".$where : ""));
if ($line = mysql_fetch_array($data))
{
return $line;
}
return false;
}
function sql_parent_id($table, $id)
{
$line = sql_line($table, $id);
if (isset($line))
{
return $line['parent_id'];
}
return 0;
}
function sql_parent_line($table, $id)
{
if ($line = sql_line($table, $id))
{
if ($line = sql_line($table, $line['parent_id']))
return $line;
}
return false;
}
function sql_is_ancestor($table, $id, $root)
{
while ($id)
{
if ($id == $root)
return true;
$id = sql_parent_id($table, $id);
}
return false;
}
function sql_change_parent($table, $ids, $parent_id)
{
if (!isset($ids))
return;
foreach ($ids as $id => $value)
{
if (!sql_is_ancestor($table, $parent_id, $id))
mysql_query("update $table set parent_id='".mysql_escape_string($parent_id)."' where id='".mysql_escape_string($id)."'");
}
}
function sql_count($table, $where = '')
{
$data = mysql_query("select count(*) from $table".($where ? " where $where" : ""));
if ($line = mysql_fetch_array($data))
return $line[0];
return false;
}
function sql_delete($table, $ids)
{
if (!isset($ids))
return;
foreach ($ids as $id => $value)
{
$id = mysql_escape_string($id);
mysql_query("delete from $table where id='$id'");
}
}
function sql_delete_tree($table, $ids)
{
if (!isset($ids))
return;
foreach ($ids as $id => $value)
{
$id = mysql_escape_string($id);
mysql_query("delete from $table where id='$id'");
mysql_query("drop temporary table if exists t_tree_clear");
mysql_query("create temporary table t_tree_clear (id int(11))");
mysql_query("insert into t_tree_clear (id) (select id from $table where ((parent_id <> 0) and not (parent_id in (select id from $table))))");
mysql_query("delete from $table where id in (select id from t_tree_clear)");
mysql_query("drop temporary table if exists t_tree_clear");
}
}
// Получить список элементов поддеревьев как массив элементов (id, folder)
function sql_flat_tree($table, $ids)
{
$res = array();
if (!isset($ids))
return $res;
foreach ($ids as $id => $value)
{
$id = (int)$id;
if ($line = sql_line($table, $id))
{
$id = array($id, $line['folder']);
$items = array($id);
while (count($items))
{
$id = array_shift($items);
array_push($res, $id);
if ($id[1] < 1)
continue;
$data = mysql_query("select id, folder from $table where parent_id='".$id[0]."'");
while ($line = mysql_fetch_array($data))
{
array_push($items, array($line['id'], $line['folder']));
}
}
}
}
return $res;
}
function sql_move_up($table, $ids, $parent_field = 'parent_id')
{
if (!isset($ids))
return;
foreach ($ids as $id => $value)
{
$id = mysql_escape_string($id);
mysql_query("select @pos1 := pos, @pid := $parent_field from $table where id='$id'");
mysql_query("select @id2 := id, @pos2 := pos from $table where ($parent_field = @pid) and (pos < @pos1) order by pos desc limit 0, 1");
mysql_query("update $table set pos=0 where id=@id2");
mysql_query("update $table set pos=@pos2 where @id2<>0 and id='$id'");
mysql_query("update $table set pos=@pos1 where @id2<>0 and id=@id2");
}
}
function sql_move_down($table, $ids, $parent_field = 'parent_id')
{
if (!isset($ids))
return;
foreach (array_reverse($ids, true) as $id => $value)
{
$id = mysql_escape_string($id);
mysql_query("select @pos1 := pos, @pid := $parent_field from $table where id='$id'");
mysql_query("select @id2 := id, @pos2 := pos from $table where ($parent_field = @pid) and (pos > @pos1) order by pos limit 0, 1");
mysql_query("update $table set pos=0 where id=@id2");
mysql_query("update $table set pos=@pos2 where @id2<>0 and id='$id'");
mysql_query("update $table set pos=@pos1 where @id2<>0 and id=@id2");
}
}
//
function page_path()
{
global $settings;
global $page;
$result = '';
$p = explode('/', trim($page['path'], '/'));
if (count($p) < 2)
return;
$pt = '/';
$hr = 0;
foreach ($p as $value)
{
$pt .= $value.'/';
if ($value == '')
continue;
if ($hr)
$result .= ' / ';
$title = $settings['page'][$pt]['heading'] ? $settings['page'][$pt]['heading'] : $app['page'][$pt]['heading'];
if (!$title)
$title = $settings['page'][$pt]['title'] ? $settings['page'][$pt]['title'] : $app['page'][$pt]['title'];
if ($hr == count($p) - 1)
{
$result .= ''.html_escape($title).'';
}
else
$result .= ''.html_escape($title).'';
$hr++;
}
return $result;
}
// Start
load_settings('app');
if ($settings['app']['version'] != $app['app']['version'])
{
include $app['path']['cms'].'/convert/main.php';
die();
}
load_settings('page');
load_settings('text');
$page_path_last = '';
if ($app['page'])
{
foreach ($app['page'] as $key => $value)
if ((strpos($page['path'], $key) === 0) && (strlen($key) > strlen($page_path_last)))
$page_path_last = $key;
$page['line'] = $app['page'][$page_path_last];
}
$page_path_last2 = '';
foreach ($settings['page'] as $key => $value)
if ((strpos($page['path'], $key) === 0) && (strlen($key) > strlen($page_path_last2)))
$page_path_last2 = $key;
if (strlen($page_path_last2) > strlen($page_path_last))
{
$page_path_last = $page_path_last2;
$page['line'] = $settings['page'][$page_path_last];
}
$page['mode'] = '';
if (strpos($page['fullpath'], '/admin/') === 0)
{
$page['mode'] = 'admin';
}
$page['param'] = substr($page['path'], strlen($page_path_last));
$page['path'] = $page_path_last;
$page_path_last = $page['param'];
if (substr($page['param'], -1, 1) == '/')
$page['param'] = substr($page['param'], 0, -1);
$page['param'] = $page_path_last != '' ? explode('/', $page['param']) : array();
function write_headers()
{
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
}
if ($app['db']['active'])
{
$link=@mysql_connect($app['db']['host'], $app['db']['login'], $app['db']['password']);
if (!$link) die("Can't connect to db.");
@mysql_select_db($app['db']['name']) or die("Can't select db.");
@mysql_query("SET NAMES 'cp1251'");
@mysql_query("SET CHARACTER SET 'cp1251'");
@mysql_query("set charaset 'cp1251'");
mysql_set_charset('cp1251',$link);
}
function cms_start()
{
global $app;
global $root;
global $settings;
global $page;
global $auth_ok;
global $out;
write_headers();
if (!$page['line']['active'] || !$auth_ok && ($page['path'] != '/admin/') && (strpos($page['path'], '/admin/') === 0) || ((rewrite_auto_ext($page['fullpath']) != $page['realpath']) && (strpos($page['path'], '/admin/') !== 0)))
{
if ($page['path'] != '/forbidden/')
redirect(rewrite_auto_ext('/forbidden/'));
}
if ($auth_ok)
{
$app['menu']['admin']['/admin/page/'.base64_url_encode($page['path']).'/?act=new&goto-page'] = array('title' => 'Добавить страницу');
$app['menu']['admin']['/admin/page/'.base64_url_encode($page['path']).'/?act=edit&goto-page'] = array('title' => 'Изменить страницу');
}
if (($page['path'] == '/') && count($page['param']))
$under_construction = true;
$page['layout'] = $page['line']['layout'];
$out['page']['title'] = $page['line']['title'];
$out['page']['heading'] = $page['line']['heading'] ? $page['line']['heading'] : $page['line']['title'];
$out['page']['keywords'] = $page['line']['keywords'] ? $page['line']['keywords'] : $settings['app']['keywords'];
$out['page']['description'] = $page['line']['description'] ? $page['line']['description'] : $settings['app']['description'];
if ($page['line']['code'])
{
$page['layout-block'] = 'code';
start_out('code');
eval($page['line']['code']);
start_out();
}
if (isset($app['layout'][$page['layout']]))
{
if ($page['layout'] != 'silent')
{
foreach ($app['layout'][$page['layout']][$page['mode']]['block'] as $page['layout-block'] => $page['layout-mod'])
{
start_out($page['layout-block']);
if (is_file($app['path']['cms'].'/mod/'.$page['layout-mod'].'/'.(strpos($page['path'], '/admin/') === 0 ? 'admin' : 'main').'.php'))
{
if (!isset($settings[$page['layout-mod']]))
load_settings($page['layout-mod']);
include $app['path']['cms'].'/mod/'.$page['layout-mod'].'/'.(strpos($page['path'], '/admin/') === 0 ? 'admin' : 'main').'.php';
}
else
echo 'Ошибка. Файл модуля '.$page['layout-mod'].' не найден.';
end_out();
}
}
if ($auth_ok)
{
start_out('admin_panel');
include_once $app['path']['cms'].'/mod/admin_panel/main.php';
end_out();
}
$template = $app['layout'][$page['layout']][$page['mode']]['template'];
if ($page['number'])
$out['page']['title'] .= ' (страница №'.($page['number'] + 1).')';
start_out('full-page');
$out[''] = $out['code'].$out[''];
include_once $root.'/ui/'.$template.'.htm';
end_out();
ob_end_clean();
echo $out['full-page'];
}
else
{
ob_end_clean();
echo 'Ошибка. Привязка модулей '.$page['layout'].' не найдена.';
}
save_settings();
}
// Image
// mode 0 - не обрезать, 1 - обрезать, 2 - по ширине, 3 -, 4 - автовыбор ориентации с обрезанием, 5 - автовыбор ориентации без обрезания
// -1 - не менять размер, 6 - не обрезать и без фона
function img_resize($src, $dest, $width, $height, $mode=1, $rgb=0xffffff, $quality=71)
{
if (!file_exists($src))
return false;
$img_resize_result = array();
$size = getimagesize($src);
if ($size === false)
return false;
$format = strtolower(substr($size['mime'], strpos($size['mime'], '/')+1));
$icfunc = "imagecreatefrom" . $format;
if (!function_exists($icfunc))
return false;
if($mode == -1)
{
$width = $size[0];
$height = $size[1];
}
if($mode == 5)
{
$mode = 0;
if (($width > $height) && ($size[0] < $size[1]))
{
$tmp = $width;
$width = $height;
$height = $tmp;
}
}
if($mode == 4)
{
$mode = 1;
if (($width > $height) && ($size[0] < $size[1]))
{
$tmp = $width;
$width = $height;
$height = $tmp;
}
}
if($mode == 3)
{
$mode = $size[0] > $size[1] ? 1 : 0;
}
$x_ratio = $width / $size[0];
$y_ratio = $height / $size[1];
if($mode == 0)
$ratio = min($x_ratio, $y_ratio);
else
$ratio = max($x_ratio, $y_ratio);
$use_x_ratio = ($x_ratio == $ratio);
if($mode == 2)
{
$new_width = $width;
$height = floor($width * $size[1] / $size[0]);
$new_height = $height;
$new_left = 0;
$new_top = 0;
}
else
{
$new_width = $use_x_ratio ? $width : floor($size[0] * $ratio);
$new_height = !$use_x_ratio ? $height : floor($size[1] * $ratio);
$new_left = $use_x_ratio ? 0 : floor(($width - $new_width) / 2);
$new_top = !$use_x_ratio ? 0 : floor(($height - $new_height) / 2);
}
if($mode == 6)
{
$ratio = min($x_ratio, $y_ratio);
$new_width = floor($size[0] * $ratio);
$new_height = floor($size[1] * $ratio);
$new_left = 0;
$new_top = 0;
$width = $new_width;
$height = $new_height;
}
$img_resize_result['width'] = $width;
$img_resize_result['height'] = $width;
$isrc = $icfunc($src);
$idest = imagecreatetruecolor($width, $height);
imagefill($idest, 0, 0, $rgb);
imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0,
$new_width, $new_height, $size[0], $size[1]);
if (file_exists($dest))
unlink($dest);
imagejpeg($idest, $dest, $quality);
imagedestroy($isrc);
imagedestroy($idest);
return $img_resize_result;
}
?>