Viewing file: core5.php (56.69 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<? error_reporting(0); global $ULANG, $ALANG, $ulang, $alang, $_LANG_ID; session_start(); define('SMARTY_DIR', 'modules-alien/smarty/libs/'); require_once(SMARTY_DIR.'Smarty.class.php'); //if ($_SESSION['user']['user_id'] == 25) die("You must die!"); include "database.php"; $conn = mysql_connect(DB_HOSTNAME, DB_USER, DB_PASSWORD) or trigger_error(mysql_error(), E_USER_ERROR); mysql_select_db(DB_NAME); mysql_query("SET NAMES utf8", $conn); $_LANG_ID = unserialize(GetParam("Languages"));
$params = explode("&",$_SERVER['QUERY_STRING']); foreach($params as $key => $value) { $param = explode("=", $value); if ($param[0] == "lang") $_SESSION['user_language'] = $param[1]; }
if (isset($_SESSION['user_language']) && trim($_SESSION['user_language']) != "") $ulang = $_SESSION['user_language']; else $ulang = GetParam("DefaultLanguage"); if (isset($_SESSION['admin_language']) && trim($_SESSION['admin_language']) != "") $alang = $_SESSION['admin_language']; else $alang = GetParam("DefaultLanguage"); if (!isset($_SESSION['admin'])) $alang = $ulang; GetAdminLanguageCaptions($alang); GetUserLanguageCaptions ($ulang);
$directory = opendir("modules"); include_once("user/languages/core-$ulang.php"); while ($s = readdir($directory)) { if ($s == "." || $s == "..") continue; $modulefile = "modules/".$s."/module.php"; if (file_exists($modulefile)) include_once $modulefile; $languagefile = "user/languages/".$s."-$ulang.php"; if (file_exists($languagefile)) { include_once $languagefile; } }
function GetUserSmarty($module) { $module = strtolower($module); global $ALANG, $ULANG, $alang, $ulang, $AMCMS_Config, $_LANG_ID; $smarty = new Smarty(); $smarty->template_dir = "user/templates/".$module."/"; $smarty->compile_dir = "tmp/_compile_user/".$module."/"; $smarty->cache_dir = "tmp/_cache_user/".$module."/"; $smarty->assign('ULANG', $ULANG); $smarty->assign('ALANG', $ALANG); $smarty->assign("languages", $_LANG_ID); $smarty->assign('alang', $alang); $smarty->assign('ulang', $ulang); if (count($AMCMS_Config) > 0) foreach($AMCMS_Config as $key => $value) $smarty->assign($key, $value); return $smarty; }
function GetAdminSmarty($module) { global $ALANG, $ULANG, $alang, $ulang, $AMCMS_Config, $_LANG_ID; $smarty = new Smarty(); $smarty->template_dir = strtolower("modules/{$module}/templates/"); $smarty->compile_dir = strtolower("tmp/_compile_admin/".$module."/"); $smarty->cache_dir = strtolower("tmp/_cache_admin/".$module."/"); $smarty->assign('ULANG', $ULANG); $smarty->assign('ALANG', $ALANG); $smarty->assign('alang', $alang); $smarty->assign("languages", $_LANG_ID); $smarty->assign('ulang', $ulang); if (count($AMCMS_Config) > 0) foreach($AMCMS_Config as $key => $value) $smarty->assign($key, $value); return $smarty; }
class watermark3{
# given two images, return a blended watermarked image function create_watermark( $main_img_obj, $watermark_img_obj, $alpha_level = 100 ) { $alpha_level /= 100; # convert 0-100 (%) alpha to decimal
# calculate our images dimensions $main_img_obj_w = imagesx( $main_img_obj ); $main_img_obj_h = imagesy( $main_img_obj ); $watermark_img_obj_w = imagesx( $watermark_img_obj ); $watermark_img_obj_h = imagesy( $watermark_img_obj );
# determine center position coordinates /* $main_img_obj_min_x = floor( ( $main_img_obj_w / 2 ) - ( $watermark_img_obj_w / 2 ) ); $main_img_obj_max_x = ceil( ( $main_img_obj_w / 2) + ( $watermark_img_obj_w / 2 ) ); $main_img_obj_min_y = floor( ( $main_img_obj_h / 2) - ( $watermark_img_obj_h / 2 ) ); $main_img_obj_max_y = ceil( ( $main_img_obj_h /2 ) + ( $watermark_img_obj_h / 2 ) ); */
$main_img_obj_min_x = $main_img_obj_w - $watermark_img_obj_w - 10; $main_img_obj_min_y = $main_img_obj_h - $watermark_img_obj_h - 10; $main_img_obj_max_x = $main_img_obj_w; $main_img_obj_max_y = $main_img_obj_h;
# create new image to hold merged changes $return_img = imagecreatetruecolor( $main_img_obj_w, $main_img_obj_h );
# walk through main image for( $y = 0; $y < $main_img_obj_h; $y++ ) { for( $x = 0; $x < $main_img_obj_w; $x++ ) { $return_color = NULL;
# determine the correct pixel location within our watermark $watermark_x = $x - $main_img_obj_min_x; $watermark_y = $y - $main_img_obj_min_y;
# fetch color information for both of our images $main_rgb = imagecolorsforindex( $main_img_obj, imagecolorat( $main_img_obj, $x, $y ) );
# if our watermark has a non-transparent value at this pixel intersection # and we're still within the bounds of the watermark image if ( $watermark_x >= 0 && $watermark_x < $watermark_img_obj_w && $watermark_y >= 0 && $watermark_y < $watermark_img_obj_h ) { $watermark_rbg = imagecolorsforindex( $watermark_img_obj, imagecolorat( $watermark_img_obj, $watermark_x, $watermark_y ) );
# using image alpha, and user specified alpha, calculate average $watermark_alpha = round( ( ( 127 - $watermark_rbg['alpha'] ) / 127 ), 2 ); $watermark_alpha = $watermark_alpha * $alpha_level;
# calculate the color 'average' between the two - taking into account the specified alpha level $avg_red = $this->_get_ave_color( $main_rgb['red'], $watermark_rbg['red'], $watermark_alpha ); $avg_green = $this->_get_ave_color( $main_rgb['green'], $watermark_rbg['green'], $watermark_alpha ); $avg_blue = $this->_get_ave_color( $main_rgb['blue'], $watermark_rbg['blue'], $watermark_alpha );
# calculate a color index value using the average RGB values we've determined $return_color = $this->_get_image_color( $return_img, $avg_red, $avg_green, $avg_blue );
# if we're not dealing with an average color here, then let's just copy over the main color } else { $return_color = imagecolorat( $main_img_obj, $x, $y );
} # END if watermark
# draw the appropriate color onto the return image imagesetpixel( $return_img, $x, $y, $return_color );
} # END for each X pixel } # END for each Y pixel
# return the resulting, watermarked image for display return $return_img;
} # END create_watermark()
# average two colors given an alpha function _get_ave_color( $color_a, $color_b, $alpha_level ) { return round( ( ( $color_a * ( 1 - $alpha_level ) ) + ( $color_b * $alpha_level ) ) ); } # END _get_ave_color()
# return closest pallette-color match for RGB values function _get_image_color($im, $r, $g, $b) { $c=imagecolorexact($im, $r, $g, $b); if ($c!=-1) return $c; $c=imagecolorallocate($im, $r, $g, $b); if ($c!=-1) return $c; return imagecolorclosest($im, $r, $g, $b); } # EBD _get_image_color()
} # END watermark API
function GetParam($paramName, $paramLanguage = "all") { $res = mysql_query("SELECT * FROM AMCMS_params WHERE param_name = '{$paramName}' AND param_language = '{$paramLanguage}'"); $arr = mysql_fetch_assoc($res); return $arr['param_value']; }
function SetParam($paramName, $paramValue, $paramLanguage = "all") { $res = mysql_query("SELECT * FROM AMCMS_params WHERE param_name = '{$paramName}' AND param_language = '{$paramLanguage}'"); $arr = mysql_fetch_assoc($res); if ($arr == null) $res = mysql_query("INSERT INTO AMCMS_params (param_value, param_name, param_language) VALUES ('{$paramValue}', '{$paramName}', '{$paramLanguage}')"); else $res = mysql_query("UPDATE AMCMS_params SET param_value = '{$paramValue}' WHERE param_name = '{$paramName}' AND param_language = '{$paramLanguage}'"); }
function GetAdminLanguageCaptions($language) { global $ALANG; $res = mysql_query("SELECT * FROM `AMCMS_admin_languages`"); while ($row = mysql_fetch_array($res)) $ALANG[$row['caption_name']] = $row['caption_'.$language]; // include "data/languages/{$language}-admin.inc.php"; }
function GetUserLanguageCaptions($language) { global $ULANG; $res = mysql_query("SELECT * FROM `AMCMS_user_languages`"); while ($row = mysql_fetch_array($res)) $ULANG[$row['caption_name']] = $row['caption_'.$language]; // include "data/languages/{$language}-admin.inc.php"; }
function GetCurrentDateAndTime() { $time = strtotime(GetParam("TimeOffset")); $fecha = date("Y-m-d H:i:s", $time); return $fecha; } function GetYesterday() { $time = strtotime("-1 day ".GetParam("TimeOffset")); $fecha = date("Y-m-d", $time); return $fecha; } function GetCurrentYear() { $time = strtotime(GetParam("TimeOffset")); $fecha = date("Y", $time); return $fecha; } function GetCurrentMonth() { $time = strtotime(GetParam("TimeOffset")); $fecha = date("m", $time); return $fecha; } function GetCurrentDay() { $time = strtotime(GetParam("TimeOffset")); $fecha = date("d", $time); return $fecha; } function GetCurrentDayOfWeek() { $time = strtotime(GetParam("TimeOffset")); $fecha = date("D", $time); switch ($fecha) { case 'Mon': return 1; case 'Tue': return 2; case 'Wed': return 3; case 'Thu': return 4; case 'Fri': return 5; case 'Sat': return 6; case 'Sun': return 7; } return $fecha; } function GetCurrentHours() { $time = strtotime(GetParam("TimeOffset")); $fecha = date("H", $time); return $fecha; } function GetCurrentMinutes() { $time = strtotime(GetParam("TimeOffset")); $fecha = date("i", $time); return $fecha; } function DateConvert($year, $month, $day, $hours = 0 , $minutes = 0) { $date = ""; if ($year != 0) { $date = "{$year}-{$month}-{$day} "; if ($hours != 0 || $minutes != 0) { $date .= "{$hours}:{$minutes}"; } } return $date; } function DateExplode($dateString) { $date_components = explode(" ", $dateString); $date = explode("-", $date_components[0]); $time = explode(":", $date_components[1]); return array($date[0], $date[1], $date[2], $time[0], $time[1], $time[2]); }
function GetUsefulDate($dateString, $showdate = true, $showtime = true) { global $ULANG; $html = ""; $parts = DateExplode($dateString); if ($showdate) { $html .= (int)$parts[2]." ".$ULANG['CoreMonthRP'.((int)$parts[1])]." ".$parts[0]." ".$ULANG['CoreYearRP']; } if ($showdate and $showtime) $html .= " ".$ULANG['CoreDateTimeDelimiter']; if ($showtime) { $html .= " ".$parts[3].":".$parts[4]; } return $html; }
function SimpleDateEcho($dateString) { global $ULANG; $html = ""; $parts = DateExplode($dateString); //$html .= "{$parts[2]}.{$parts[1]}.{$parts[0]} {$ULANG['CoreDateTimeDelimiter']}"; //$html .= " ".$parts[3].":".$parts[4].":".$parts[5]; $html .= "{$parts[2]}.{$parts[1]}.{$parts[0]}";
return $html; }
///////////
class AMNavigator{ var $Fields; function AMNavigator() { $this->Fields = array(); } function AddLink($title, $link) { $this->Fields[] = array('title' => $title, 'link' => $link); } function Fetch() { $html = ""; $html .= "<div class=\"Navigator\">"; $filename = "/"; $html .= "<a href=\"{$filename}\"><img src=\"/user/icons/m-home1.gif\" border=\"0\" align=\"absmiddle\" /></a>"; foreach ($this->Fields as $key => $value) { $html .= "<span class=\"delimiter\">›››</span> "; $html .= "<a href=\"{$value['link']}\">{$value['title']}</a> "; } $html .= "</div>"; return $html; } function GetTitleForPage() { global $ULANG, $ulang; $html = ""; foreach($this->Fields as $key => $value) $html .= " | ".$value['title']; return GetParam("SiteName", $ulang).$html; } }
//////
class AMTable2 { var $TableName; var $IndexField; var $PositionField; var $Fields; var $Module; var $ParentField; function AMTable2($tableName) { $this->TableName = $tableName; $this->Fields = array(); $res = mysql_list_fields(DB_NAME, $this->TableName); while ($row = mysql_fetch_field($res)) $this->Fields[] .= $row->name; } function AddIndexField($indexField) { $this->IndexField = $indexField; } function AddPositionField($positionField) { $this->PositionField = $positionField; } function GetRows($order = "", $where = "", $limit = "", $tables = "") { $wherePart = ""; $orderPart = ""; $limitPart = ""; if (is_array($where)) $wherePart = "WHERE (".implode(") AND (", $where).")"; else if ($where != "") $wherePart = "WHERE ".$where; if ($order != "") $orderPart = "ORDER BY ".$order; if ($limit != "") $limitPart = "LIMIT ".$limit; if (is_array($tables)) $tablesPart = ",".implode(",",$tables); $sql = "SELECT * FROM {$this->TableName}{$tablesPart} {$wherePart} {$orderPart} {$limitPart}"; $res = mysql_query($sql); $rows = array(); while ($row = @mysql_fetch_assoc($res)) { $rows[] = $row; } return $rows; } function GetRowById($id) { $id = (int)$id; if ($id <= 0) return; $sql = "SELECT * FROM {$this->TableName} WHERE {$this->IndexField} = '{$id}'"; $res = mysql_query($sql); $row = mysql_fetch_assoc($res); return $row; } function GetTableName() { return $this->TableName; } function Insert($arr) { $fields = array(); $values = array(); foreach($arr as $key => $value) if (in_array($key, $this->Fields)) { $fields[] .= $key; $values[] .= "'".($value)."'"; } $sql = "INSERT INTO {$this->TableName} (".implode(",", $fields).") VALUES (".implode(",", $values).")" ; mysql_query($sql); $id = mysql_insert_id(); if (strlen($this->PositionField) > 0) { mysql_query("UPDATE {$this->TableName} SET {$this->PositionField} = '{$id}' WHERE {$this->IndexField} = '$id'"); } return $id; } function Update($arr, $id) { if (isset($this->ParentField)) { if ($id == 1) return; $row = $this->tree[$id]; $this->tree = array(); $rows = $this->CreateTree($id); if ($id == $arr[$this->ParentField]) $arr[$this->ParentField] = $row[$this->ParentField]; foreach($rows as $key => $value) if ($value[$this->IndexField] == $arr[$this->ParentField]) $arr[$this->ParentField] = $row[$this->ParentField]; } $values = array(); foreach($arr as $key => $value) if (in_array($key, $this->Fields)) { $values[] .= "$key = '".($value)."'"; } $sql = "UPDATE {$this->TableName} SET ".implode(",", $values)." WHERE {$this->IndexField} = '{$id}'"; // echo "<option>asd</option>"; mysql_query($sql); return $id; } function Module($mod) { $this->Module = $mod; } function SetParentField($field) { $this->ParentField = $field; }
var $depth = -1; var $tree; function GetPrevRecord($id, $where = "") { $whereStatement = ""; if ($where != "") $whereStatement = "AND ({$where})"; $query = "SELECT * FROM {$this->TableName} WHERE ({$this->PositionField} > '{$id}') {$whereStatement} ORDER BY {$this->PositionField} ASC LIMIT 0,1"; $query_result = mysql_query($query); $row = mysql_fetch_assoc($query_result); return $row; } function GetNextRecord($id, $where = "") { $whereStatement = ""; if ($where != "") $whereStatement = "AND ({$where})"; $query = "SELECT * FROM {$this->TableName} WHERE ({$this->PositionField} < '{$id}') {$whereStatement} ORDER BY {$this->PositionField} DESC LIMIT 0,1"; $query_result = mysql_query($query); $row = mysql_fetch_array($query_result); return $row; } function MoveRecordUp($id, $where = "") { $row1 = $this->GetRowById($id); $row2 = $this->GetNextRecord($row1[$this->PositionField], $where); if ($row2 == null || $row1 == null) return; $id1 = $row1[$this->IndexField]; $id2 = $row2[$this->IndexField]; $pos1 = $row1[$this->PositionField]; $pos2 = $row2[$this->PositionField]; $query = "UPDATE {$this->TableName} SET {$this->PositionField} = '{$pos2}' WHERE {$this->IndexField} = '{$id1}'"; mysql_query($query) or die(mysql_error()); $query = "UPDATE {$this->TableName} SET {$this->PositionField} = '{$pos1}' WHERE {$this->IndexField} = '{$id2}'"; mysql_query($query) or die(mysql_error()); } function MoveRecordDown($id, $where = "") { $row1 = $this->GetRowById($id); $row2 = $this->GetPrevRecord($row1[$this->PositionField], $where); if ($row2 == null || $row1 == null) return; $id1 = $row1[$this->IndexField]; $id2 = $row2[$this->IndexField]; $pos1 = $row1[$this->PositionField]; $pos2 = $row2[$this->PositionField]; $query = "UPDATE {$this->TableName} SET {$this->PositionField} = '{$pos2}' WHERE {$this->IndexField} = '{$id1}'"; mysql_query($query) or die(mysql_error()); $query = "UPDATE {$this->TableName} SET {$this->PositionField} = '{$pos1}' WHERE {$this->IndexField} = '{$id2}'"; mysql_query($query) or die(mysql_error()); } function CreateTree($id) { global $alang; $this->depth++; $res = mysql_query("SELECT * FROM {$this->TableName} WHERE {$this->ParentField} = '{$id}' ORDER BY {$this->PositionField} ASC"); while ($row = mysql_fetch_assoc($res)) { $row['depth'] = $this->depth; $text = ""; for ($i = 0; $i < $this->depth; $i++) $text .= " "; $row['preffix'] = $text."└ "; $this->tree[$row[$this->IndexField]] = $row; $this->CreateTree($row[$this->IndexField]); } $this->depth--; return $this->tree; } function GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple = "", $params = "") { global $ALANG; if (isset($params['tree'])) $rows = $this->tree; else $rows = $this->GetRows($order, $conditions, "", $params["tables"]); $sortable = ""; if (isset($params['tree'])) { $tree = null; $this->CreateTree(0); } if (isset($params['id'])) $par = " id=\"{$params['id']}\""; if (isset($params['sortable'])) $sortable = "sortable"; if (isset($this->Module)) $par .= " mod=\"{$this->Module}\""; $html = "<table class=\"admin-table {$sortable}\" align=\"center\" {$par} table=\"{$this->TableName}\">"; $html .= "<thead>"; $html .= "<tr>"; for($i = 0; $i < count($links); $i++) $html .= "<th> </th>"; for($i = 0; $i < count($captions); $i++) $html .= "<th>{$captions[$i]}</th>"; $index = 1; $html .= "</tr>"; $html .= "</thead>"; $html .= "<tbody>"; foreach($rows as $key => $value) { if (isset($params["function"])) { $params["function"]($value); } $html .= "<tr id=\"{$value[$this->IndexField]}\">"; for($i = 0; $i < count($links); $i++) { switch($links[$i]) { case 'up' : $html .= "<td><a href=\"admin.php?mod={$this->Module}&{$this->IndexField}={$value[$this->IndexField]}&up\" class=\"up\">{$ALANG['CoreUp']}</a></td>"; break; case 'down' : $html .= "<td><a href=\"admin.php?mod={$this->Module}&{$this->IndexField}={$value[$this->IndexField]}&down\" class=\"down\">{$ALANG['CoreDown']}</a></td>"; break; case 'checkbox' : $html .= "<td><input type=\"checkbox\" name=\"{$this->IndexField}\" value=\"{$value[$this->IndexField]}\"/></td>"; break; case 'edit' : $html .= "<td><a href=\"admin.php?mod={$this->Module}&{$this->IndexField}={$value[$this->IndexField]}&edit\" class=\"edit\">{$ALANG['CoreEdit']}</a></td>"; break; case 'delete' : $html .= "<td><a href=\"#\" class=\"ajax delete\" oper=\"delete\">{$ALANG['CoreDelete']}</a></td>"; break; case 'toarhive' : $html .= "<td align=\"center\"><a href=\"#\" class=\"ajax arhive\" oper=\"toarchive\">{$ALANG['CoreToArchive']}</a></td>"; break; case 'fromarhive' : $html .= "<td align=\"center\"><a href=\"#\" class=\"ajax arhive\" oper=\"fromarchive\">{$ALANG['CoreFromArchive']}</a></td>"; break; } } for($i = 0; $i < count($fields); $i++) { $preffix = ""; $postfix = ""; if (isset($paramss['tree']) && $fields[$i] == $params['tree']) $preffix = $this->tree[$value[$this->IndexField]]['preffix']; if ($i == count($fields) - 1 && isset($params["postfix"])) { foreach($params["postfix"] as $key2 => $value2) { $postfix .= "<div class=\"{$value2['class']}\"><a href=\"/admin.php?mod={$this->Module}&{$value2['preffix']}&{$this->IndexField}={$value[$this->IndexField]}\">".$value2["title"]."</a></div>"; } } $html .= "<td>{$preffix}{$value[$fields[$i]]}{$postfix}</td>"; } $html .= "</tr>"; $index++; if ($index > 2) $index = 1; } $html .= "</tbody>"; $html .= "</table>"; /* if (count($multiple) > 0) { for($i = 0; $i < count($multiple); $i++) { switch($multiple[$i]) { case 'delete' : $html .= "<td><a href=\"#\" class=\"ajax delete\" oper=\"delete\">{$ALANG['CoreDelete']}</a></td>"; break; case 'toarhive' : $html .= "<td align=\"center\"><a href=\"#\" class=\"ajax arhive\" oper=\"toarchive\">{$ALANG['CoreToArchive']}</a></td>"; break; case 'fromarhive' : $html .= "<td align=\"center\"><a href=\"#\" class=\"ajax arhive\" oper=\"fromarchive\">{$ALANG['CoreFromArchive']}</a></td>"; break; } } }*/ return $html; } function Run($arr) { if ($arr['table'] != $this->TableName) return; if ($arr['oper'] == "sorting") { $fields = explode('&', $arr['ids']); $order = 0; $fields = array_reverse($fields); $ids = array(); $order = 0; foreach($fields as $field) { $order++; $field_key_value = explode('=', $field); $level = urldecode($field_key_value[0]); $id = urldecode($field_key_value[1]); if ($id > 0) $ids[] .= $id; } sort($ids); $order = 0; foreach($fields as $field) { $field_key_value = explode('=', $field); $level = urldecode($field_key_value[0]); $id = urldecode($field_key_value[1]); if ($id <= 0) continue; mysql_query("UPDATE {$this->TableName} SET {$this->PositionField}='{$ids[$order]}' WHERE {$this->IndexField} = '$id'"); echo "UPDATE {$this->TableName} SET {$this->PositionField}='{$ids[$order]}' WHERE {$this->IndexField} = '$id'"; $order++; } echo "{\"status\" : \"ok\"}"; die; } if ($arr['oper'] == "delete") { $this->Delete($arr['id']); echo "{\"status\" : \"ok\", \"code\" : \"{$arr['id']}\"}"; die; } if ($arr['oper'] == "up") { $row = $this->GetRowById($arr['id']); $pid = $row[$this->ParentField]; $this->MoveRecordUp($arr['id'], "{$this->ParentField} = '$pid'"); echo "{\"status\" : \"ok\", \"code\" : \"{$arr['id']}\"}"; die; } if ($arr['oper'] == "down") { $row = $this->GetRowById($arr['id']); $pid = $row[$this->ParentField]; $this->MoveRecordDown($arr['id'], "{$this->ParentField} = '$pid'"); echo "{\"status\" : \"ok\", \"code\" : \"{$arr['id']}\"}"; die; } } function Delete($id) { if (isset($this->ParentField) && $id == 1) return; mysql_query("DELETE FROM {$this->TableName} WHERE {$this->IndexField} = '{$id}'"); } function DeleteRows($where) { mysql_query("DELETE FROM {$this->TableName} WHERE {$where}"); } }
function ParseDate($date, $what) { $arr = DateExplode($date); switch($what) { case "year" : return $arr[0]; case "month" : return $arr[1]; case "day" : return $arr[2]; case "hours" : return $arr[3]; case "minutes" : return $arr[4]; case "seconds" : return $arr[5]; } } function ImageResize($src, $dest, $width, $height, $rgb=0xFFFFFF, $quality=100) { if (!file_exists($src)) return false; $size = getimagesize($src); if ($size === false) return false; // ?????????? ???????? ?????? ?? MIME-??????????, ??????????????? // ???????? getimagesize, ? ???????? ??????????????? ??????? // imagecreatefrom-???????. $format = strtolower(substr($size['mime'], strpos($size['mime'], '/')+1)); $icfunc = "imagecreatefrom" . $format; if (!function_exists($icfunc)) return false; $x_ratio = $width / $size[0]; $y_ratio = $height / $size[1]; $ratio = min($x_ratio, $y_ratio); $use_x_ratio = ($x_ratio == $ratio); /*$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);*/ $new_width = floor($size[0] * $ratio); $new_height = floor($size[1] * $ratio); $new_left = 0; $new_top = 0; $isrc = $icfunc($src); $idest = imagecreatetruecolor($new_width, $new_height); imagefill($idest, 0, 0, $rgb); imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0, $new_width, $new_height, $size[0], $size[1]); imagejpeg($idest, $dest, $quality); imagedestroy($isrc); imagedestroy($idest); return true; }
function GetYearSelectForm($name, $method = "get", $selectedYear = "", $startYear = "") { if ($startYear == "") $startYear = GetParam("StartYear"); global $ALANG; if ($selectedYear == "") $selectedYear = GetCurrentYear(); $option1 = ""; for($i = GetCurrentYear() + 1; $i >= $startYear; $i--) { $selected = ""; if ($i == $selectedYear) $selected = "selected=\"selected\""; $option1 .= "<option {$selected} value=\"{$i}\">".$i." ".$ALANG['CoreYear']."</option>"; } $select1 = "<select name=\"{$name}\" id=\"{$name}\" onchange=\"submit1.click();\">{$option1}</select> "; $input = "<input style=\"display:none;\" type=\"submit\" name=\"submit1\" id=\"submit1\" value=\"".$ALANG['CoreSelect'] ."\" />"; $selectorHtml = "<div style=\"text-align:center\"><form style=\"margin-bottom:20px\" name=\"datefrm\" method=\"{$method}\"> ".$ALANG['CoreSelect'].": {$select1} {$select2} {$input}</form></div>"; return $selectorHtml;
}
function ClearStringForTitle($title) { $str_win = iconv("utf-8","cp1251", $title); $str_win = trim($str_win); $str_win = str_replace("\n", " ", $str_win); $str_win = str_replace("\r", " ", $str_win); $str_win = ereg_replace(" +", " ",$str_win); return iconv("cp1251","utf-8", $str_win); }
/////////////// МОИ модули ///////// class AMPhotomanager { var $Module; var $ModuleParams; var $Params; var $Table; function AMPhotomanager($params) { $this->Table = new AMTable2("AMCMS_photomanager"); $this->Table->AddIndexField("photo_id"); $this->Table->AddPositionField("photo_position"); $this->Params = $params; } function Run($post, $files, $mod, $params) { if (isset($this->Params['main'])) { if (strlen($files['mainphoto']['name']) > 0) { $src = $files['mainphoto']['tmp_name']; $dest = tempnam_sfx("data/photomanager",""); $row['photo_filename'] = $dest; @unlink($dest); $dest1 = $dest."_main.jpg"; $dest2 = $dest."_main_big.jpg"; $size1 = explode("x", $this->Params['main']); ImageResize($src, $dest1, $size1[0], $size1[1], 0xFFFFFF, 90); ImageResize($src, $dest2, 1280, 1024, 0xFFFFFF, 70); $watermark = new watermark3(); $img = imagecreatefromjpeg($dest2); $water = imagecreatefrompng("user/copyright.png"); $im=$watermark->create_watermark($img,$water,90); imagejpeg($im, $dest2); } $rows = $this->Table->GetRows("", array("photo_module = '$mod'", "photo_module_params = '{$params}'", "photo_type='main'")); $row['photo_title_rus'] = $post['mainphoto_title_rus']; $row['photo_title_ukr'] = $post['mainphoto_title_ukr']; $row['photo_title_eng'] = $post['mainphoto_title_eng']; $row['photo_description_rus'] = $post['mainphoto_description_rus']; $row['photo_description_ukr'] = $post['mainphoto_description_ukr']; $row['photo_description_eng'] = $post['mainphoto_description_eng']; $row['photo_align'] = $post['mainphoto_align']; $row['photo_module'] = $mod; $row['photo_module_params'] = $params; $row['photo_type'] = "main"; if (count($rows) == 0) $this->Table->Insert($row); else { $this->Table->Update($row, $rows[0]['photo_id']); if (strlen($row['photo_filename']) > 0) { @unlink($rows[0]['photo_filename']."_main.jpg"); @unlink($rows[0]['photo_filename']."_main_big.jpg"); } } } if (isset($this->Params['text'])) { $index = 0; // var_dump($post); for($i = 0; $i < count($post['photo_title_rus']); $i++) { // $rows = $this->Table->GetRows("", array("photo_module = '$mod'", "photo_module_params = '{$params}'")); if (is_numeric($post['photo_id'][$i])) { $row = array(); $row['photo_title_rus'] = $post['photo_title_rus'][$i]; $row['photo_title_ukr'] = $post['photo_title_ukr'][$i]; $row['photo_title_eng'] = $post['hoto_title_eng'][$i]; $row['photo_description_rus'] = $post['photo_description_rus'][$i]; $row['photo_description_ukr'] = $post['photo_description_ukr'][$i]; $row['photo_description_eng'] = $post['photo_description_eng'][$i]; $row['photo_align'] = $post['photo_align']; $row['photo_module'] = $mod; $row['photo_module_params'] = $params; $row['photo_type'] = "text"; if (strlen($files['photo']['name'][$i]) > 0) { $r = $this->Table->GetRowById($post['photo_id'][$i]); @unlink($r['photo_filename']."_big.jpg"); @unlink($r['photo_filename']."_small.jpg"); $src = $files['photo']['tmp_name'][$i]; $dest = tempnam_sfx("data/photomanager",""); @unlink($dest); $destSmall = $dest."_small.jpg"; $destBig = $dest."_big.jpg"; $sizeSmall = explode("x", $this->Params['text']['small']); $sizeBig = explode("x", $this->Params['text']['big']); ImageResize($src, $destSmall, $sizeSmall[0], $sizeSmall[1], 0xFFFFFF, 90); ImageResize($src, $destBig, 1280, 1024, 0xFFFFFF, 70); $watermark = new watermark3(); $img = imagecreatefromjpeg($destBig); $water = imagecreatefrompng("user/copyright.png"); $im=$watermark->create_watermark($img,$water,90); imagejpeg($im, $destBig); $row['photo_filename'] = $dest; } $this->Table->Update($row, $post['photo_id'][$i]); } else if ($post['photo_id'][$i] != 'delete') { $row = array(); $row['photo_title_rus'] = $post['photo_title_rus'][$i]; $row['photo_title_ukr'] = $post['photo_title_ukr'][$i]; $row['photo_title_eng'] = $post['hoto_title_eng'][$i]; $row['photo_description_rus'] = $post['photo_description_rus'][$i]; $row['photo_description_ukr'] = $post['photo_description_ukr'][$i]; $row['photo_description_eng'] = $post['photo_description_eng'][$i]; $row['photo_align'] = $post['photo_align']; $row['photo_module'] = $mod; $row['photo_module_params'] = $params; $row['photo_type'] = "text"; if (strlen($files['photo']['name'][$i]) > 0) { $src = $files['photo']['tmp_name'][$i]; $dest = tempnam_sfx("data/photomanager",""); @unlink($dest); $destSmall = $dest."_small.jpg"; $destBig = $dest."_big.jpg"; $sizeSmall = explode("x", $this->Params['text']['small']); $sizeBig = explode("x", $this->Params['text']['big']); ImageResize($src, $destSmall, $sizeSmall[0], $sizeSmall[1], 0xFFFFFF, 90); ImageResize($src, $destBig, 1280, 1024, 0xFFFFFF, 70); $watermark = new watermark3(); $img = imagecreatefromjpeg($destBig); $water = imagecreatefrompng("user/copyright.png"); $im=$watermark->create_watermark($img,$water,90); imagejpeg($im, $destBig); $row['photo_filename'] = $dest; } $this->Table->Insert($row); } } } } function GetAdminTable($mod, $params, $type = "all") { $smarty = GetAdminSmarty("Photomanager"); $rows_main = $this->Table->GetRows("", array("photo_module = '$mod'", "photo_module_params = '{$params}'", "photo_type = 'main'")); $rows_photos = $this->Table->GetRows("photo_position DESC", array("photo_module = '$mod'", "photo_module_params = '{$params}'", "photo_type = 'text'")); if (count($rows_main) > 0) $smarty->assign("mainphoto", $rows_main[0]); if (count($rows_photos) > 0) $smarty->assign("photos", $rows_photos); $html = ""; if (isset($this->Params['main'])) $res['main'] = $smarty->fetch("photomanager-main-photo.tpl"); if (isset($this->Params['text'])) $res['photos'] = $smarty->fetch("photomanager-photos.tpl"); if ($type == "all") return $res['main'].$res['photos']; if ($type == "main") return $res['main']; if ($type == "photos") return $res['photos']; } function GetMainPhoto($mod, $params) { $rows_main = $this->Table->GetRows("", array("photo_module = '$mod'", "photo_module_params = '{$params}'", "photo_type = 'main'")); if (count($rows_main) > 0) { $rows_main[0]['photo_filename'] = $rows_main[0]['photo_filename']."_main.jpg"; return $rows_main[0]; } return ""; } function GetPhotos($mod, $params) { $rows = $this->Table->GetRows("photo_position DESC", array("photo_module = '$mod'", "photo_module_params = '{$params}'", "photo_type = 'text'")); for($i = 0; $i < count($rows); $i++) { $rows[$i]['photo_filename_small'] = $rows[$i]['photo_filename']."_small.jpg"; $rows[$i]['photo_filename_big'] = $rows[$i]['photo_filename']."_big.jpg"; } return $rows; } } function tempnam_sfx($path, $suffix) { do { $file = $path."/".mt_rand().$suffix; $fp = @fopen($file, 'x'); } while(!$fp);
fclose($fp); return $file; } function SearchOnSite($words, $selectFields, $indexField, $fields, $tableName) { $field = implode(",", $fields); $titleField = implode(",", $selectFields); $text = $words; $sql = "SELECT $indexField, $titleField, MATCH ($field) AGAINST ('$text' IN BOOLEAN MODE) AS relev FROM $tableName WHERE MATCH ($field) AGAINST ('$text' IN BOOLEAN MODE)"; $res = mysql_query($sql); while ($row = @mysql_fetch_assoc($res)) $rows [] = $row; return $rows; }
class AMPageNavigator { var $RowsByPage; // кол. строк на страницу var $CurPage; // тек. страница var $CountOfRows; // общее кол. строк var $MaxPage; // максимальные номер страницы
function AMPageNavigator($countOfRows, $curpage = 1, $rowsByPage = 10) { $this->RowsByPage = $rowsByPage; $this->CountOfRows = $countOfRows; $this->CalculateMaxPage(); $this->CurPage = $this->NormalizePageNumber($curpage); } function CalculateMaxPage() { $this->MaxPage = @ceil($this->CountOfRows / $this->RowsByPage); } function NormalizePageNumber($pageNum) { if ($pageNum == 'last') $pageNum = $this->MaxPage; if ($pageNum < 1) return 1; if ($pageNum > $this->MaxPage) return $this->MaxPage; return (int) $pageNum; } function GetLimitStatement() { return "LIMIT ".$this->GetStartIndex().",".$this->RowsByPage; } function GetLimit() { return $this->GetStartIndex().",".$this->RowsByPage; } function GetCountOfPages() { return $this->MaxPage; } function TestNumberOfPage($pageNum) { if ($pageNum < 1) return false; if ($pageNum > $this->MaxPage) return false; return true; } function GetStartIndex() { return ($this->CurPage - 1)*$this->RowsByPage; } function GetNavigator($addressPreffix = null) { global $ULANG, $ulang; $this->CurPage = $this->NormalizePageNumber($this->CurPage); $input = "<span class=\"page-field\"><input type=\"text\" class=\"input-back-content\" title=\"Введите номер страницы и нажмите на клавищу Enter\" defval=\"Страница №\" name=\"pageNum\" value=\"Страница №\" /><input type=\"image\" src=\"/user/icons/enter-icon.gif\" align=\"absmiddle\" title=\"Кликните для перехода к указанной странице\"/></span>"; $rows = array(); $comp = explode("?",$_SERVER['REQUEST_URI']); $addrBase = $comp[0]; if ($addressPreffix != null) $addrBase = $addressPreffix; $addrRequest = $comp[1]; $parComponents = explode("&", $addrRequest); $params = array(); foreach($parComponents as $key => $value) { $par = explode("=", $value); if ($par[0] != "mod" && $par[0] != "pageNum") { if ($value != "") $params[] = $value; } } if ($this->GetCountOfPages() <= 5) { for ($i = 1; $i <= $this->GetCountOfPages(); $i++) { if ($i == $this->GetCountOfPages()) array_push($params, "pageNum=last"); else array_push($params, "pageNum=$i"); $row['link'] = $addrBase."?".implode("&", $params); array_pop($params); $row['title'] = $i; $row['page'] = $i; if ($i == $this->CurPage) $row['class'] = "selected"; else $row['class'] = ""; array_push($rows, $row); } } else { if ($this->CurPage <= 3) { $start1 = 1; $end1 = 3; } else { $start1 = $this->CurPage - 2; $end1 = $start1 + 2; array_push($params, "pageNum=1"); $row['link'] = $addrBase."?".implode("&", $params); array_pop($params); $row['title'] = "«"; $row['page'] = $this->GetCountOfPages(); if ($i == $this->CurPage) $row['class'] = "selected"; else $row['class'] = ""; array_push($rows, $row); $start2 = $end1 + 1; $end2 = $this->NormalizePageNumber($start2 + 1); } for ($i = $start1; $i <= $end1; $i++) { if ($i == $this->GetCountOfPages()) array_push($params, "pageNum=last"); else array_push($params, "pageNum=$i"); $row['link'] = $addrBase."?".implode("&", $params); array_pop($params); $row['title'] = $i; $row['page'] = $i; if ($i == $this->CurPage) $row['class'] = "selected"; else $row['class'] = ""; array_push($rows, $row); } $row = array('title' => $input); array_push($rows, $row); if ($this->CurPage == 1) { $start2 = $this->GetCountOfPages() - 1; $end2 = $start2 + 1; } else { $start2 = $end1 + 1; $end2 = $this->NormalizePageNumber($start2 + 1); } for ($i = $start2; $i <= $end2; $i++) { if ($i == $this->GetCountOfPages()) array_push($params, "pageNum=last"); else array_push($params, "pageNum=$i"); $row['link'] = $addrBase."?".implode("&", $params); array_pop($params); $row['title'] = $i; $row['page'] = $i; if ($i == $this->CurPage) $row['class'] = "selected"; else $row['class'] = ""; array_push($rows, $row); } if ($end2 < $this->GetCountOfPages()) { array_push($params, "pageNum=last"/*.$this->GetCountOfPages()*/); $row['link'] = $addrBase."?".implode("&", $params); array_pop($params); $row['title'] = "»"; $row['page'] = $this->GetCountOfPages(); if ($i == $this->CurPage) $row['class'] = "selected"; else $row['class'] = ""; array_push($rows, $row); } } $i = 0; $links = array(); foreach($rows as $key => $value) { $class = ""; if (!empty($value['class'])) $class = " class=\"{$value['class']}\""; if (!empty($value['link'])) $links[] = "<a href=\"{$value['link']}#comments\"$class>{$value['title']}</a>"; else $links[] = $value['title']; } $linksStr = implode("",$links); if (strlen($linksStr) > 0) return "<form method=\"get\"><div class=\"page-navigator\"><strong>{$ULANG['AMCMS_core']['Pages']}:</strong> {$linksStr}</div></form>"; } }
class CPageNavigator { var $CurrentPage; var $RowsInPage; var $CountOfRows; function CPageNavigator($countOfRows, $curpage = 1, $rowsInPage = 10) { if ($curpage <= 0) $curpage = 1; $this->CurrentPage = $curpage; $this->RowsInPage = $rowsInPage; $this->CountOfRows = $countOfRows; } function GetLimitStatement() { $st = ($this->CurrentPage - 1)*$this->RowsInPage; return "LIMIT ".$st.",".$this->RowsInPage; } function GetCountOfPages() { return @ceil($this->CountOfRows / $this->RowsInPage); } function TestNumberOfPage($page) { if ($page <= 0) return false; if ($page > $this->GetCountOfPages()) return false; return true; } function GetStartIndex() { return $st = ($this->CurrentPage - 1)*$this->RowsInPage; } function GetNavigator($addressPreffix, $caption = "") { if ($this->GetCountOfPages() <= 1) return ""; if (strlen($caption) > 0) $caption = $caption + ":"; $increment = 2; $rows = array(); $comp = explode("?",$_SERVER['REQUEST_URI']); $addrBase = $comp[0]; $addrRequest = $comp[1]; $parComponents = explode("&", $addrRequest); $params = array(); $input = "<input type=\"text\" class=\"input-back-content\" title=\"Введите номер страницы и нажмите на клавищу Enter\" defval=\"Страница #\" name=\"pageNum\" value=\"Страница #\" />"; $inputPos = -1; if ($this->CurrentPage + $increment < $this->GetCountOfPages()) $inputPos = "r"; if ($this->CurrentPage - $increment > 1) $inputPos = "l"; if (($this->CurrentPage + $increment < $this->GetCountOfPages()) && ($this->CurrentPage - $increment > 1)) $inputPos = "c";
foreach($parComponents as $key => $value) { $par = explode("=", $value); if ($par[0] != "mod" && $par[0] != "pageNum") { if ($value != "") $params[] = $value; } } $par = $params; if ($this->CurrentPage - $increment > 1) { $row['title'] = "«"; $row['page'] = 1; $params[] = "pageNum=1"; $addrRequest = implode("&", $params); $row['link'] = $addrBase."?".$addrRequest; array_push($rows, $row); /* if ($inputPos == "l") { $row = array(); $row['title'] = "$input"; array_push($rows, $row); }*/ $params = $par; } if ($this->CurrentPage == 2) $increment = 3;
for ($i = -$increment; $i <= $increment; $i++) if ($this->TestNumberOfPage($this->CurrentPage + $i)) { $row['title'] = $this->CurrentPage + $i; $row['page'] = $this->CurrentPage + $i; $params[] = "pageNum=".$row['page']; $addrRequest = implode("&", $params); $row['link'] = $addrBase."?".$addrRequest; array_push($rows, $row); $params = $par; } if ($this->CurrentPage == 1) { for ($i = $this->GetCountOfPages() - 2; $i < $this->GetCountOfPages(); $i++) if ($this->TestNumberOfPage($this->CurrentPage + $i)) { $row['title'] = $this->CurrentPage + $i; $row['page'] = $this->CurrentPage + $i; $params[] = "pageNum=".$row['page']; $addrRequest = implode("&", $params); $row['link'] = $addrBase."?".$addrRequest; array_push($rows, $row); $params = $par; } } else if ($this->CurrentPage + $increment < $this->GetCountOfPages()) { /*if ($inputPos == "r") { $row = array(); $row['title'] = "$input"; array_push($rows, $row); }*/ $row['title'] = "»"; $row['page'] = $this->GetCountOfPages(); $params[] = "pageNum=".$row['page']; $addrRequest = implode("&", $params); $row['link'] = $addrBase."?".$addrRequest; array_push($rows, $row); $params = $par; } $i = 0; $f = 0; foreach($rows as $key => $value) { $class = ""; $title = $value['title']; if ($value['page'] == $this->CurrentPage) $class = " class=\"selected\""; $link = $value['link']; if (!empty($link)) $str .= "<a href=\"{$link}\" {$class}>{$title}</a>"; else $str .= $title; if ((($value['page'] == $this->CurrentPage) && ($i >= 2)) || (($i == 2) && $this->CurrentPage <= 2)) { $str .= "$input"; $f = 1; } $i++; } if (count($rows) > 1) return "<form><div class=\"page-navigator\"><span class=\"title\">{$caption}</span> {$str}</div></form>"; else return ""; } }
function detect_browser($HTTP_USER_AGENT) { // Браузер и его версия $data[] = array("regexp" => "(Opera Mini/)([0-9]{1,2}).([0-9]{1,3})", "browser" => "Opera Mini", "version" => 2, "subversion" => 3); $data[] = array("regexp" => "(Opera(/){0,1}[ ]{0,1})([0-9]{1,2}).[0-9]{1,3}", "browser" => "Opera", "version" => 3, "subversion" => 4); $data[] = array("regexp" => "(Opera/)([0-9]{1,2}).([0-9]{1,3})", "browser" => "Opera", "version" => 2, "subversion" => 3); $data[] = array("regexp" => "(METASpider)", "browser" => "BOT", "version" => "METASpider"); $data[] = array("regexp" => "(Yandex)", "browser" => "BOT", "version" => "Yandex"); $data[] = array("regexp" => "(HostTracker.com)", "browser" => "BOT", "version" => "HostTracker.com"); $data[] = array("regexp" => "(Aport)", "browser" => "BOT", "version" => "Aport"); $data[] = array("regexp" => "(Googlebot/)([0-9]{1,2}.[0-9]{1,3}){0,1}", "browser" => "BOT", "version" => "Google"); $data[] = array("regexp" => "(SurveyBot/)([0-9]{1,2}.[0-9]{1,3}){0,1}", "browser" => "BOT", "version" => "SurveyBot (Whois)", "subversion" => 2); $data[] = array("regexp" => "(Konqueror)/([0-9]{1,2}).([0-9]{1,3})", "browser" => "Konqueror", "version" => 2, "subversion" => 3); $data[] = array("regexp" => "(Chrome)/([0-9]{1,2}).([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})", "browser" => "Google Chrome", "version" => 2, "subversion" => 3); $data[] = array("regexp" => "(msie) ([0-9]{1,2}).([0-9]{1,3})", "browser" => "MSIE", "version" => 2, "subversion" => 3); $data[] = array("regexp" => "(Twiceler-)([0-9]{1,2}.[0-9]{1,3}){0,1}", "browser" => "BOT", "version" => "Twiceler"); $data[] = array("regexp" => "(StackRambler/)([0-9]{1,2}.[0-9]{1,3}){0,1}", "browser" => "BOT", "version" => "Rambler"); $data[] = array("regexp" => "(Gigabot/)([0-9]{1,2}.[0-9]{1,3}){0,1}", "browser" => "BOT", "version" => "Gigabot"); $data[] = array("regexp" => "(ia_archiver)", "browser" => "BOT", "version" => "ia_archiver"); $data[] = array("regexp" => "(ProBCE.NET)", "browser" => "BOT", "version" => "ProBCE.NET"); $data[] = array("regexp" => "(Yanga WorldSearch Bot)", "browser" => "BOT", "version" => "Yanga WorldSearch Bot"); $data[] = array("regexp" => "(Baiduspider)", "browser" => "BOT", "version" => "Baiduspider"); $data[] = array("regexp" => "(Firefox)/([0-9]{1,2}).([0-9]{1,3}(.[0-9]{1,3}){0,1})", "browser" => "Firefox", "version" => 2); $data[] = array("regexp" => "(Minefield)/([0-9]{1,2}).([0-9]{1,3}(.[0-9]{1,3}){0,1})", "browser" => "Minefield", "version" => 2); $data[] = array("regexp" => "(OOZBOT)", "browser" => "BOT", "version" => "OOZBOT"); $data[] = array("regexp" => "(FollowSite Bot)", "browser" => "BOT", "version" => "FollowSite"); $data[] = array("regexp" => "(RusCorpusbot)", "browser" => "BOT", "version" => "RusCorpusbot"); $data[] = array("regexp" => "(CCBot)", "browser" => "BOT", "version" => "CCBot"); $data[] = array("regexp" => "(Yahoo!)", "browser" => "BOT", "version" => "Yahoo!"); $data[] = array("regexp" => "(ePochta_Extractor)", "browser" => "BOT", "version" => "ePochta_Extractor"); $data[] = array("regexp" => "(Servage Robot)", "browser" => "BOT", "version" => "Servage Robot"); $data[] = array("regexp" => "(psbot)", "browser" => "BOT", "version" => "psbot"); $data[] = array("regexp" => "(safari)/([0-9]{1,2}).([0-9]{1,3})", "browser" => "Safari", "version" => 2); $data[] = array("regexp" => "(K-Meleon)/([0-9]{1,2}).([0-9]{1,3})", "browser" => "K-Meleon", "version" => 2); $data[] = array("regexp" => "(Netscape)/([0-9]{1,2}).([0-9]{1,3})", "browser" => "Netscape", "version" => 2); $data[] = array("regexp" => "(Thunderbird)/([0-9]{1,2}).([0-9]{1,3})", "browser" => "Thunderbird", "version" => 2); $data[] = array("regexp" => "(SeaMonkey)/([0-9]{1,2}).([0-9]{1,3})", "browser" => "SeaMonkey", "version" => 2); $data[] = array("regexp" => "(Phoenix)/([0-9]{1,2}).([0-9]{1,3})", "browser" => "Phoenix", "version" => 2); $data[] = array("regexp" => "(Crawler)", "browser" => "BOT", "version" => "Crawler"); $data[] = array("regexp" => "(Microsoft Data Access Internet Publishing Provider Protocol Discovery)", "browser" => "BOT", "version" => "MDAI-PPPD"); $data[] = array("regexp" => "(ovalebot3.ovale.ru facepage)", "browser" => "BOT", "version" => "ovalebot"); $data[] = array("regexp" => "(ovalebot)", "browser" => "BOT", "version" => "ovalebot"); $data[] = array("regexp" => "(Linguee Bot)", "browser" => "BOT", "version" => "Linguee"); $data[] = array("regexp" => "(Yeti)", "browser" => "BOT", "version" => "Yeti"); $data[] = array("regexp" => "(msnbot)", "browser" => "BOT", "version" => "MSN"); $data[] = array("regexp" => "(google_web)", "browser" => "BOT", "version" => "Google"); $data[] = array("regexp" => "(Bot)", "browser" => "BOT", "version" => "Unknown"); $data[] = array("regexp" => "(bot)", "browser" => "BOT", "version" => "Unknown"); $data[] = array("regexp" => "(crawl)", "browser" => "BOT", "version" => "Unknown"); $data[] = array("regexp" => "(google)", "browser" => "BOT", "version" => "Google"); $data[] = array("regexp" => "(Mozilla)/([3-4]).([0-9]{1,2})", "browser" => "Netscape", "version" => 2); $data[] = array("regexp" => "(Mozilla)", "browser" => "Firefox", "version" => "Unknown"); $data[] = array("regexp" => "(Nokia)", "browser" => "Nokia browser", "version" => ""); $data[] = array("regexp" => "(NOKIA)", "browser" => "Nokia browser", "version" => ""); $browser["name"] = "Unknown"; $browser["version"] = "Unknown"; $dataos []= array("regexp" => "[lL]inux", "os" => "Linux"); $dataos []= array("regexp" => "Opera Mini", "os" => "Mobile Device"); $dataos []= array("regexp" => "win32", "os" => "Windows"); $dataos []= array("regexp" => "(win)([0-9]{2}", "os" => "Windows", "version" => 2); $dataos []= array("regexp" => "(windows) ([0-9]{2})", "os" => "Windows", "version" => 2); $dataos []= array("regexp" => "(winnt)([0-9]{1,2}.[0-9]{1,2}){0,1}", "os" => "Windows", "version" => 2); $dataos []= array("regexp" => "(windows nt)( ){0,1}([0-9]{1,2}.[0-9]{1,2}){0,1}", "os" => "Windows", "version" => 3); $dataos []= array("regexp" => "mac", "os" => "Macintosh"); $dataos []= array("regexp" => "(sunos) ([0-9]{1,2}.[0-9]{1,2}){0,1}", "os" => "SunOS", "version" => 2); $dataos []= array("regexp" => "(beos) r([0-9]{1,2}.[0-9]{1,2}){0,1}", "os" => "BeOS", "version" => 2); $dataos []= array("regexp" => "freebsd", "os" => "FreeBSD"); $dataos []= array("regexp" => "openbsd", "os" => "OpenBSD"); $dataos []= array("regexp" => "irix", "os" => "IRIX"); $dataos []= array("regexp" => "os/2", "os" => "OS/2"); $dataos[] = array("regexp" => "plan9", "os" => "Plan9"); $dataos []= array("regexp" => "unix", "os" => "Unix"); foreach($data as $key => $value) { if (@eregi($value['regexp'], $HTTP_USER_AGENT, $match)) { $browser["name"] = $value["browser"]; if ((int)($value["version"]) > 0) $browser["version"] = $match[$value["version"]]; else $browser["version"] = $value["version"]; if ($browser["name"] != "BOT") { foreach($dataos as $key2 => $value2) if (eregi($value['regexp'], $HTTP_USER_AGENT, $match2)) { $browser["os"] = $value2["os"]; /* if ((int)($value2["version"]) > 0) $browser["os_version"] = $match[$value2["version"]]; else $browser["os_version"] = $value2["version"];*/ break; } } else { $browser["os"] = "BOT"; $browser["version"] = ""; } break; } } return $browser; } function addzero($value, $charCount) { $v = $value; for ($i = strlen($value); $i < $charCount; $i++) { $v = "0".$v; } return $v; } function shorttext($text, $len) { $ntext = utf8_decode($text); if (strlen($ntext) < $len) return $text; return mb_substr($text, 0, $len, 'UTF-8')."..."; } function IsUserBlacklisted($id) { $sql = "SELECT * FROM AMCMS_users WHERE user_id = '{$id}'"; $res = mysql_query($sql); $row = mysql_fetch_assoc($res); return $row['user_blacklisted'] == 1; } class AMCMS_Cache { static function Save($module, $chapter, $page, $data) { $date = GetCurrentDateAndTime(); $sql = "SELECT COUNT(*) as count FROM AMCMS_cache WHERE cache_module = '{$module}' AND cache_chapter = '{$chapter}' AND cache_page = '{$page}'"; $res = mysql_query($sql); $row = mysql_fetch_assoc($res); $data = addslashes($data); if ($row['count'] == 0) { $sql = "INSERT INTO AMCMS_cache (cache_module, cache_chapter, cache_page, cache_date, cache_data) VALUES ('{$module}', '{$chapter}', '{$page}', '{$date}', '{$data}')"; mysql_query($sql); } else { $sql = "UPDATE AMCMS_cache SET cache_data = '{$data}', $cahce_date = '{$date}' WHERE cache_module = '{$module}' AND cache_chapter = '{$chapter}' AND cache_page = '{$page}'"; mysql_query($sql); } } static function Load($module, $chapter, $page) { $sql = "SELECT * FROM AMCMS_cache WHERE cache_module = '{$module}' AND cache_chapter = '{$chapter}' AND cache_page = '{$page}'"; $res = mysql_query($sql); $row = mysql_fetch_assoc($res); return $row['cache_data']; } static function GetCacheFlag($module, $chapter, $page) { $sql = "SELECT cache_update FROM AMCMS_cache WHERE cache_module = '{$module}' AND cache_chapter = '{$chapter}' AND cache_page = '{$page}'"; $res = mysql_query($sql); $row = mysql_fetch_assoc($res); return $row['cache_update']; } static function SetCacheFlag($module, $chapter, $page, $value) { $sql = "UPDATE AMCMS_cache SET cache_update = '{$value}' WHERE cache_module = '{$module}' AND cache_chapter = '{$chapter}' AND cache_page = '{$page}'"; mysql_query($sql); } } function AssumeNumber($val, $arr) { $r = 0; $a1 = $val % 100; $a2 = $val % 10; switch ($a2) { case 0: $r = 0; break; case 1: $r = 1; break; case 2: $r = 2; break; case 3: $r = 2; break; case 4: $r = 2; break; case 5: $r = 0; break; case 6: $r = 0; break; case 7: $r = 0; break; case 8: $r = 0; break; case 9: $r = 0; break; } if ($a1 > 10 && $a1 < 20) $r = 0; return $arr[$r]; } function Gender($gender, $arr) { if ($gender == 'm' || $gender == 'M' || $gender == 'мужской' || $gender == 'Мужской') return $arr[0]; else return $arr[1]; } function ReplaceLinks($text) { return preg_replace('#((?:http|https):\/\/[^\s]+)#i','<a href="$1" target="_blank">$1</a>', $text); } function ReplaceImages($text) { return preg_replace('/(http:\/\/zt4ever.org.ua\/(.){0,40}\#photo([0-9]+))/i','<span class="thumb"><a href="#photo$3" target="_blank" class="amviewer" val="$3"><img src="/user-asynch.php?mod=Photochapter&oper=showsmallphoto&id=$3"/></a></span><span style="display:none;">$1</span>', $text); } function generate_password($number) { $arr = array('a','b','c','d','e','f', 'g','h','i','j','k','l', 'm','n','o','p','r','s', 't','u','v','x','y','z', 'A','B','C','D','E','F', 'G','H','I','J','K','L', 'M','N','O','P','R','S', 'T','U','V','X','Y','Z', '1','2','3','4','5','6', '7','8','9','0','.',',', '(',')','[',']','!','?', '&','^','%','@','*','$', '<','>','/','|','+','-', '{','}','`','~'); // Генерируем пароль $pass = ""; for($i = 0; $i < $number; $i++) { // Вычисляем случайный индекс массива $index = rand(0, count($arr) - 1); $pass .= $arr[$index]; } return $pass; } function json_encode_cyr($str) { $arr_replace_utf = array('\u0410', '\u0430','\u0411','\u0431','\u0412','\u0432', '\u0413','\u0433','\u0414','\u0434','\u0415','\u0435','\u0401','\u0451','\u0416', '\u0436','\u0417','\u0437','\u0418','\u0438','\u0419','\u0439','\u041a','\u043a', '\u041b','\u043b','\u041c','\u043c','\u041d','\u043d','\u041e','\u043e','\u041f', '\u043f','\u0420','\u0440','\u0421','\u0441','\u0422','\u0442','\u0423','\u0443', '\u0424','\u0444','\u0425','\u0445','\u0426','\u0446','\u0427','\u0447','\u0428', '\u0448','\u0429','\u0449','\u042a','\u044a','\u042b','\u044b','\u042c','\u044c', '\u042d','\u044d','\u042e','\u044e','\u042f','\u044f'); $arr_replace_cyr = array('А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Е', 'е', 'Ё', 'ё', 'Ж','ж','З','з','И','и','Й','й','К','к','Л','л','М','м','Н','н','О','о', 'П','п','Р','р','С','с','Т','т','У','у','Ф','ф','Х','х','Ц','ц','Ч','ч','Ш','ш', 'Щ','щ','Ъ','ъ','Ы','ы','Ь','ь','Э','э','Ю','ю','Я','я'); $str1 = json_encode($str); $str2 = str_replace($arr_replace_utf,$arr_replace_cyr,$str1); return $str2; } ?>
|