)/', '', $obj); return $str; } //страртует таймер function Start_Timer() { $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; return $mtime; } //окончание таймера и вывод времени генерации страницы function End_Timer($start_time) { global $timer_view; if ($timer_view) { $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $totaltime = $mtime - $start_time; $ret = '
Страница сгенерирована за ' . $totaltime . ' секунд.
'; return $ret; } } //стартует архивировние function Start_Gzip() { global $use_gzip; if ($use_gzip) { if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== FALSE) { $GLOBALS["gzip_encoding"] = 'x-gzip'; } else if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) { $GLOBALS["gzip_encoding"] = 'gzip'; } if ($GLOBALS["gzip_encoding"]) { ob_start(); ob_implicit_flush(FALSE); } } } //заканчивает архивирование function End_Gzip() { global $use_gzip; if ($use_gzip && ($GLOBALS["gzip_encoding"])) { $contents = ob_get_contents(); ob_end_clean(); header("Content-Encoding: " . $GLOBALS["gzip_encoding"]); print "\x1f\x8b\x08\x00\x00\x00\x00\x00"; $size = strlen($contents); $crc = crc32($contents); $contents = gzcompress($contents, 9); $contents = substr($contents, 0, strlen($contents) - 4); print $contents; print pack('V', $crc); print pack('V', $size); } } //зашифровка function object_to_crypt($crpt) { if (!isset($crpt)) return; $z = serialize($crpt); $z = @gzcompress($z); $z = base64_encode($z); $z = urlencode($z); return $z; } //расшифровка function object_to_decrypt($crpt) { if (!isset($crpt)) return; $z = urldecode($crpt); $z = base64_decode($z); $z = @gzuncompress($z); $z = unserialize($z); return $z; } //получение списка модулей function getModule() { $dirName = ROOT_DIR . "/module/"; $d = dir($dirName); while ($entry = $d->read()) { if ($entry != "." and $entry != ".." and $entry != ".htaccess") { if (is_file($dirName . $entry . "/index.php")) { $file_arr[] = $entry; } } } $d->close(); sort($file_arr); reset($file_arr); return $file_arr; } //получение списка модулей с админкой function getModuleAdmin($arr) { $file_arr = false; $dirName = ROOT_DIR . "/module/"; $d = dir($dirName); if (is_array($arr)) { for ($i = 0; $i < count($arr); $i++) { if (is_file($dirName . $arr[$i] . "/admin/index.php")) { $file_arr[] = $arr[$i]; } } $d->close(); return $file_arr; } else { return NULL; } } //запуск модулей function &modules($name, $queryMod) { global $lang, $path, $nick, $page, $meta, $body, $auth; $moduleName = $name; $smarty = new Smarty; $smarty->debugging = false; $smarty->caching = false; $smarty->template_dir = MODULE_DIR . $name . '/templates/'; $smarty->compile_dir = MODULE_DIR . $name . '/templates_c/'; $smarty->left_delimiter = ''; $smarty->assign('head_js', array()); $smarty->assign('head_css', array()); $smarty->assign('IS_AUTH', $auth->valid); if($auth->valid){ $smarty->assign('SYSTEM_USER', $auth->obj); } if (is_file(ROOT_DIR . "/module/" . $name . "/index.php")) { ob_start(); require(ROOT_DIR . '/module/' . $name . '/index.php'); $value = ob_get_contents(); ob_end_clean(); $toret = security($value); if ($smarty) { $head_js = $smarty->get_template_vars('head_js'); if (is_array($head_js)) $page->setHeadJS(implode('', $head_js)); $head_css = $smarty->get_template_vars('head_css'); if (is_array($head_css)) $page->setHeadCSS(implode('', $head_css)); } return $toret; } else { return 'Module ' . $name . ' not found
'; } } //отображение ошибки function msgDisplay($message) { $dirName = ROOT_DIR . "/module/"; if (is_file($dirName . "error/index.php")) { require($dirName . "error/index.php"); } } //модуление массива от запроса к базе function getArray($sql) { $res = @$GLOBALS['mysql']['query']->Query($sql); return @mysql_fetch_array($res); } //Изменение размореов картинки function resizeImage($source, $lrsize, $bywidth = FALSE, $type = 1, $crop = false, $height = false) { //$type values: 1 - for JPEG, 0 - for GIF $imginfo = getimagesize($source); if ($type === 1) $photoImage = imagecreatefromjpeg($source); elseif ($type === 0) $photoImage = imagecreatefromgif($source); elseif ($type === 2) $photoImage = imagecreatefrompng($source); $photoImageWoriginal = $imginfo[0]; $photoImageHoriginal = $imginfo[1]; if ($photoImageWoriginal > $lrsize or $photoImageHoriginal > $lrsize) { if ($bywidth == FALSE) { if ($photoImageWoriginal > $photoImageHoriginal) { $thW = $lrsize; $thH = $photoImageHoriginal / ($photoImageWoriginal / $lrsize); } elseif ($photoImageHoriginal > $photoImageWoriginal) { $thH = $lrsize; $thW = $photoImageWoriginal / ($photoImageHoriginal / $lrsize); } else { $thW = $lrsize; $thH = $lrsize; } } elseif ($bywidth == "h") { $thH = $lrsize; $thW = $photoImageWoriginal / ($photoImageHoriginal / $lrsize); } else { $thW = $lrsize; $thH = $photoImageHoriginal / ($photoImageWoriginal / $lrsize); } if ($crop && $height) { $ratio = (($photoImageWoriginal / $photoImageHoriginal) < ($lrsize / $height)) ? $lrsize / $photoImageWoriginal : $height / $photoImageHoriginal; $x = max(0, round($photoImageWoriginal / 2 - ($lrsize / 2) / $ratio)); $y = max(0, round($photoImageHoriginal / 2 - ($height / 2) / $ratio)); $thumb = ImageCreateTrueColor($thW, $height); } else { $x = $y = 0; $thumb = ImageCreateTrueColor($thW, $thH); } if (function_exists("imagecopyresampled")) { imagecopyresampled($thumb, $photoImage, 0, 0, $x, $y, $thW, $thH, $photoImageWoriginal, $photoImageHoriginal); } else { imagecopyresized($thumb, $photoImage, 0, 0, $x, $y, $thW, $thH, $photoImageWoriginal, $photoImageHoriginal); } if ($type === 1) ImageJPEG($thumb, $source, 90); elseif ($type === 0) ImageGIF($thumb, $source); elseif ($type === 2) ImagePNG($thumb, $source); ImageDestroy($thumb); } } function cropImage($nw, $nh, $source, $stype, $dest) { $size = getimagesize($source); $w = $size[0]; $h = $size[1]; switch ($stype) { case 'gif': $simg = imagecreatefromgif($source); break; case 'jpg': $simg = imagecreatefromjpeg($source); break; case 'png': $simg = imagecreatefrompng($source); break; } $dimg = imagecreatetruecolor($nw, $nh); if ($stype == "gif" or $stype == "png") { imagecolortransparent($dimg, imagecolorallocatealpha($dimg, 0, 0, 0, 127)); imagealphablending($dimg, false); imagesavealpha($dimg, true); } $ratio = max($nw / $w, $nh / $h); $h = $nh / $ratio; $x = ($w - $nw / $ratio) / 2; $y = ($h - $nh / $ratio) / 2; $w = $nw / $ratio; if($y<0){ $y = 0; } imagecopyresampled($dimg, $simg, 0, 0, $x, $y, $nw, $nh, $w, $h); if ($stype == 'jpg') { imagejpeg($dimg, $dest, 90); } elseif ($stype == 'gif') { imagegif($dimg, $dest); } elseif ($stype == 'png') { imagepng($dimg, $dest); } ImageDestroy($dimg); } //отправка мыла function XMail($from, $to, $subj, $text, $filename = '') { if ($filename) $f = fopen($filename, "rb"); $un = strtoupper(uniqid(time())); $head = "From: $from\n"; $head .= "To: $to\n"; $head .= "Subject: $subj\n"; $head .= "X-Mailer: PHPMail Tool\n"; $head .= "Reply-To: $from\n"; $head .= "Mime-Version: 1.0\n"; if ($filename) { $head .= "Content-Type:multipart/mixed;"; $head .= "boundary=\"----------" . $un . "\"\n\n"; } if ($filename) { $zag = "------------" . $un . "\nContent-Type:text/html; charset=utf-8\n"; $zag .= "Content-Transfer-Encoding: 8bit\n\n$text\n\n"; $zag .= "------------" . $un . "\n"; $zag .= "Content-Type: application/octet-stream;"; $zag .= "name=\"" . basename($filename) . "\"\n"; $zag .= "Content-Transfer-Encoding:base64\n"; $zag .= "Content-Disposition:attachment;"; $zag .= "filename=\"" . basename($filename) . "\"\n\n"; $zag .= chunk_split(base64_encode(fread($f, filesize($filename)))) . "\n"; } else { $head .= "Content-Type:text/html; charset=utf-8\n"; $zag = $text; } return mail("$to", "$subj", $zag, $head); } //функции для фильтрации внешних данных function html_full_clear_xss($text) { $text = mysql_real_escape_string(htmlspecialchars($text, ENT_QUOTES)); $text = str_replace("&", "&", $text); return $text; } function html_clear_xss($text) { $text = htmlspecialchars($text); $text = str_replace("&", "&", $text); return $text; } function clean_text($string) { $replacement = ""; return preg_replace(TXT_PATTERN, $replacement, $string); } //вывод массива в иде таблицы с заданим числом колонок function ColumnTable($array, $cols, $table_prop = 'width="100%" border="0"') { $html = ''; for ($i = 0; $i < ceil(count($array) / $cols); $i++) { $html .= ''; for ($j = 0; $j < $cols; $j++) { $el = (($i * ($cols)) + $j); $html .= ''; } $html .= ''; } $html .= '
' . ((isset($array[$el])) ? $array[$el] : '') . '
'; return $html; } function get_multi_keys($array, $key) { $ans = false; if (is_array($array) and !empty($array)) foreach ($array as $num => $arr) $ans[] = $arr[$key]; return $ans; } function getSettings($key, $type) { $sql = "select * from settings where name='" . $key . "'"; $res = mysql_query($sql); if ($res) { $data = mysql_fetch_array($res); switch ($type) { case 'array': $tmp = unserialize($data['param']); return is_array($tmp) ? $tmp : array(); break; default: return array($data['param'] => $data['value']); } } return array(); } function translit($string) { $table = array( 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'YO', 'Ж' => 'ZH', 'З' => 'Z', 'И' => 'I', 'Й' => 'J', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'CH', 'Ш' => 'SH', 'Щ' => 'CSH', 'Ь' => '', 'Ы' => 'Y', 'Ъ' => '', 'Э' => 'E', 'Ю' => 'YU', 'Я' => 'YA', 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'csh', 'ь' => '', 'ы' => 'y', 'ъ' => '', 'э' => 'e', 'ю' => 'yu', 'я' => 'ya', ); $output = str_replace( array_keys($table), array_values($table), $string ); return $output; } function getListDB($table) { $sql = "select * from " . $table . " order by name"; $res = mysql_query($sql); $ret = array(); for ($i = 0; $i < mysql_num_rows($res); $i++) { $row = mysql_fetch_array($res); $ret[$row['id']] = $row['name']; } return $ret; } function rgb2hex($rgb) { // rgb(0, 0, 153) $t = str_replace(", ", ",", $rgb); $cols = explode(',', $t); $hex = "#"; for ($i = 0; $i < count($cols); $i++) { $cols[$i] = base_convert(trim($cols[$i]), 10, 16); if (strlen($cols[$i]) < 2) $cols[$i] = "0" . $cols[$i]; $hex .= $cols[$i]; } return $hex; } function getSystemEmail() { $sql = "SELECT * FROM `settings` WHERE `name` = 'email'"; $res = mysql_query($sql); if ($res && mysql_num_rows($res) > 0) { $f = mysql_fetch_array($res); $result = unserialize(trim($f['param'])); if ($result) { return $result['email']; } } return false; } function multi_sort_array($array, $key, $order_by = NULL) { $compare = create_function('$a,$b', 'if ($a["' . $key . '"] == $b["' . $key . '"]) {return 0;}else {return ($a["' . $key . '"] > $b["' . $key . '"]) ? -1 : 1;}'); usort($array, $compare); if ($order_by == 'ASC') $array = array_reverse($array); return $array; } function isPost() { return (strtolower($_SERVER['REQUEST_METHOD']) == 'post'); } function isAjax() { return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'); } function htmlwrap($str, $width = 15, $break = "", $cut = false) { $newstr = ''; $str_array = preg_split('/(<[^>]*>)/', $str, null, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); for ($s1 = 0; $s1 < count($str_array); $s1++) { if (preg_match('/^", $cut = false) { $buf = ""; $k = 0; $n = 0; $iskanji = 0; for ($i = 0; $i <= mb_strlen($str); $i++) { if ($k && $k >= $width) { $buf .= mb_substr($str, $n, $k) . $break; $n += $k; $k = 0; } if ($str[$i] <= "~") { $iskanji = 0; $k += 1; } else { $iskanji++; if ($iskanji == 2) { $iskanji = 0; $k += 2; } } } $buf .= mb_substr($str, $n, $width); return $buf; } function russian_date($tdate, $use_time=true, $short_month = false) { if(mb_strlen($tdate)==0)return ''; if (!is_numeric($tdate))$tdate = strtotime($tdate); $Y = date('Y', $tdate); $n = date('n', $tdate); $j = date('j', $tdate); $time = date('H:i', $tdate); $month = array( 1 => "января", 2 => "февраля", 3 => "марта", 4 => "апреля", 5 => "мая", 6 => "июня", 7 => "июля", 8 => "августа", 9 => "сентября", 10 => "октября", 11 => "ноября", 12 => "декабря"); $short_month = array( 1 => "янв.", 2 => "фев.", 3 => "мар.", 4 => "апр.", 5 => "мая", 6 => "июн.", 7 => "июл.", 8 => "авг.", 9 => "сен.", 10 => "окт.", 11 => "ноя.", 12 => "дек."); if($short_month){ $month = $short_month; } return $j.' '.$month[$n].' '.$Y.' г.'.($use_time? ' '.$time:''); } class Mail { private $smtpServer = 'mail.svoboda.kg'; private $port = '25'; private $timeout = '45'; private $username = 'info@svoboda.kg'; private $password = 'rym.c2012'; private $newline = "\r\n"; private $localdomain = 'svoboda.kg'; private $charset = 'utf-8'; private $contentTransferEncoding = false; // Do not change anything below private $smtpConnect = false; private $to = false; private $subject = false; private $message = false; private $headers = false; private $logArray = array(); // Array response message for debug private $Error = ''; public function __construct($to, $subject, $message) { $this->to = &$to; $this->subject = &$subject; $this->message = &$message; // Connect to server if(!$this->Connect2Server()) { // Display error message echo $this->Error.$this->newline.''.$this->newline; return false; } return true; } private function Connect2Server() { // Connect to server $this->smtpConnect = fsockopen($this->smtpServer,$this->port,$errno,$error,$this->timeout); $this->logArray['CONNECT_RESPONSE'] = $this->readResponse(); if (!is_resource($this->smtpConnect)) { return false; } $this->logArray['connection'] = "Connection accepted: $smtpResponse"; // Hi, server! $this->sendCommand("EHLO $this->localdomain"); $this->logArray['EHLO'] = $this->readResponse(); // Let's know each other $this->sendCommand('AUTH LOGIN'); $this->logArray['AUTH_REQUEST'] = $this->readResponse(); // My name... $this->sendCommand(base64_encode($this->username)); $this->logArray['REQUEST_USER'] = $this->readResponse(); // My password.. $this->sendCommand(base64_encode($this->password)); $this->logArray['REQUEST_PASSWD'] = $this->readResponse(); // If error in response auth... if (substr($this->logArray['REQUEST_PASSWD'],0,3)!='235') { $this->Error .= 'Authorization error! '.$this->logArray['REQUEST_PASSWD'].$this->newline; return false; } // "From" mail... $this->sendCommand("MAIL FROM: $this->username"); $this->logArray['MAIL_FROM_RESPONSE'] = $this->readResponse(); if (substr($this->logArray['MAIL_FROM_RESPONSE'],0,3)!='250') { $this->Error .= 'Mistake in sender\'s address! '.$this->logArray['MAIL_FROM_RESPONSE'].$this->newline; return false; } // "To" address $this->sendCommand("RCPT TO: $this->to"); $this->logArray['RCPT_TO_RESPONCE'] = $this->readResponse(); if (substr($this->logArray['RCPT_TO_RESPONCE'],0,3)!='250') { $this->Error .= 'Mistake in reciepent address! '.$this->logArray['RCPT_TO_RESPONCE'].$this->newline; } // Send data to server $this->sendCommand('DATA'); $this->logArray['DATA_RESPONSE'] = $this->readResponse(); // Send mail message if (!$this->sendMail()) return false; // Good bye server! =) $this->sendCommand('QUIT'); $this->logArray['QUIT_RESPONSE'] = $this->readResponse(); // Close smtp connect fclose($this->smtpConnect); return true; } // Function send mail private function sendMail() { $this->sendHeaders(); $this->sendCommand($this->message); $this->sendCommand('.'); $this->logArray['SEND_DATA_RESPONSE'] = $this->readResponse(); if(substr($this->logArray['SEND_DATA_RESPONSE'],0,3)!='250') { $this->Error .= 'Mistake in sending data! '.$this->logArray['SEND_DATA_RESPONSE'].$this->newline; return false; } return true; } // Function read response private function readResponse() { $data=""; while($str = fgets($this->smtpConnect,4096)) { $data .= $str; if(substr($str,3,1) == " ") { break; } } return $data; } // function send command to server private function sendCommand($string) { fputs($this->smtpConnect,$string.$this->newline); return ; } // function send headers private function sendHeaders() { $this->sendCommand("Date: ".date("D, j M Y G:i:s")." +0700"); $this->sendCommand("From: <$this->username>"); $this->sendCommand("Reply-To: <$this->username>"); $this->sendCommand("To: <$this->to>"); $this->sendCommand("Subject: $this->subject"); $this->sendCommand("MIME-Version: 1.0"); $this->sendCommand("Content-Type: text/html; charset=$this->charset"); if ($this->contentTransferEncoding) $this->sendCommand("Content-Transfer-Encoding: $this->contentTransferEncoding"); $this->sendCommand($this->newline); return ; } public function __destruct() { if (is_resource($this->smtpConnect)) fclose($this->smtpConnect); } } ?>