/inc/function.cms.php
PHP | 483 lines | 458 code | 25 blank | 0 comment | 89 complexity | e49667e6e19eec4340e99e3ecc318c60 MD5 | raw file
- <?
- function c10($comp,$comp1)
- {
- global $p_type;
- if ($comp1==$p_type || $comp1==0)
- if (file_exists('components/'.$comp.'.php'))
- include 'components/'.$comp.'.php';
- else
- echo 'Компонент '.$comp.' не найден';
- }
- function c11($comp)
- {
- global $p_type,$p_id,$pref;
- $query=mysql_query("select * from {$pref}db_components where name='{$comp}' and status=1 limit 1");
- if (mysql_num_rows($query)>0)
- {
- $res=mysql_fetch_array($query);
- if ($res['pid']>0)
- {
- if ($res['pid']==$p_id)
- {
- if (file_exists('components/'.$res['comp']))
- include 'components/'.$res['comp'];
- else
- echo 'Компонент '.$comp.' не найден';
- }
- }
- elseif ($res['ptype']==$p_type || $res['ptype']==0)
- {
- if (file_exists('components/'.$res['comp']))
- include 'components/'.$res['comp'];
- else
- echo 'Компонент '.$comp.' не найден';
- }
- }
- else echo 'Компонент '.$comp.' не найден';
- }
- function c12($pos){
- global $p_type,$p_id,$pref,$tpl_user;
- $tmpl=substr($tpl_user, 14);
- $query_components=mysql_query("select * from {$pref}db_components where position='{$pos}' and tmpl='{$tmpl}' and status=1 order by sort,id");
- if (mysql_num_rows($query_components)>0){
- while ($res_query_components=mysql_fetch_array($query_components)){
- $ptype = explode(',', $res_query_components['ptype']);
- $pid = explode(',', $res_query_components['pid']);
- $exc = explode(',', $res_query_components['exception']);
- $except = false;
- foreach ($exc as $key => $value) {
- if ($value==$p_id) $except = true;
- }
- if (!$except){
- if (!empty($pid[0])){
- if (in_array($p_id, $pid))
- {
- if (file_exists('components/'.$tmpl.'/'.$res_query_components['comp']) && $res_query_components['comp']!='')
- include 'components/'.$tmpl.'/'.$res_query_components['comp'];
- else
- echo 'Компонент '.$res_query_components['name'].' не найден';
- }
- }
- elseif (in_array($p_type, $ptype) || $res_query_components['ptype']=='0')
- {
- if (file_exists('components/'.$tmpl.'/'.$res_query_components['comp']) && $res_query_components['comp']!='')
- include 'components/'.$tmpl.'/'.$res_query_components['comp'];
- else
- echo 'Компонент '.$res_query_components['name'].' не найден';
- }
- }
- }
- }
- }
- function c13($pos){
- global $p_type,$p_id,$pref,$tpl_user;
- $tmpl=substr($tpl_user, 14);
- $query_components=mysql_query("select * from {$pref}db_components where position='{$pos}' and tmpl='{$tmpl}' and status=1 order by sort,id");
- if (mysql_num_rows($query_components)>0){
- while ($res_query_components=mysql_fetch_array($query_components)){
- if (file_exists('components/'.$tmpl.'/'.$res_query_components['comp']) && $res_query_components['comp']!='')
- include 'components/'.$tmpl.'/'.$res_query_components['comp'];
- else
- echo 'Компонент '.$res_query_components['name'].' не найден';
- }
- }
- }
- function date2sql($dd)
- {
- $ddo = substr($dd,6,4)."-".substr($dd,3,2)."-".substr($dd,0,2)." ".substr($dd,11,5).":".date('s');
- return ($ddo);
- }
- function sql2date($dd)
- {
- $ddo = substr($dd,8,2).".".substr($dd,5,2).".".substr($dd,0,4)." ".substr($dd,11,8);
- return ($ddo);
- }
- function sql2date1($dd)
- {
- $ddo = substr($dd,8,2).".".substr($dd,5,2).".".substr($dd,0,4)." ".substr($dd,11,8);
- return (substr($ddo,0,10));
- }
- function sql2dateICMS($dd,$type)
- {
- $m_arr = array("января","февраля","марта","апреля","мая","июня","июля","августа","сентября","октября","ноября","декабря");
- $m_arr_short = array("янв","фев","мар","апр","мая","июн","июл","авг","сен","окт","ноя","дек");
- $day = substr($dd,8,2);
- $month_let = $m_arr[substr($dd,5,2)-1];
- $month_sh = $m_arr_short[substr($dd,5,2)-1];
- $month = substr($dd,5,2);
- $year = substr($dd,0,4);
- $year_short = substr($dd,2,2);
- switch ($type)
- {
- case 1:
- $ddo = $day.".".$month.".".$year;
- break;
- case 2:
- $ddo = $day." ".$month_let." ".$year;
- break;
- case 3:
- $ddo = $day." ".$month_let." ".$year." г.";
- break;
- case 4:
- $ddo = $day." ".$month_sh." ".$year;
- break;
- case 5:
- $ddo = $day." ".$month_sh." ".$year." г.";
- break;
- case 6:
- $ddo = $day.".".$month.".".$year_short;
- break;
- case 7:
- $ddo = $day."/".$month."/".$year;
- break;
- case 8:
- $ddo = $day."/".$month;
- break;
- case 9:
- $ddo = $day."-".$month."-".$year;
- break;
- }
- return ($ddo);
- }
- function paging_m($total,$lim,$p)
- {
- global $href,$arg_no_p;
- $total = ceil($total/$lim);
- print '<ul class="paging">';
- $p1=1;
- $total1=$total;
- if ($total>16){
- $p1=$p-8;
- if ($p1<1) $p1=1;
- $total1=$p1+16;
- if ($total1>$total) $total1=$total;
- }
- if ($p>9)
- print '<li><a href="'.$href.'?'.$arg_no_p.'&p='.($p1-1).'">...</a></li>';
- for ($i=$p1;$i<=$total1;$i++) {
- if ($p==($i)) $act='active';else $act='';
- print '<li class="'.$act.'"><a href="'.$href.'?'.$arg_no_p.'&p='.($i);
- print '">'.($i).'</a></li>';
- }
- if ($p<$total-8)
- print '<li><a href="'.$href.'?'.$arg_no_p.'&p='.($p1+17).'">...</a></li>';
- print '</ul>';
- }
- function getUser($id,$t){
- global $pref;
- $sql = mysql_query("select * from {$pref}db_users where id='{$id}' limit 1");
- if ($sql && mysql_num_rows($sql)>0)
- return mysql_result($sql,0, $t);
- }
- function getUserType(){
- if (isset($_SESSION['user_id'])){
- global $pref;
- $sql = "select * from {$pref}db_users where id='{$_SESSION['user_id']}' limit 1";
- return mysql_result(mysql_query($sql),0, 'type');
- }
- }
- function getStatusUser($id){
- global $pref;
- $d1= time();
- $d1=$d1-180;
- $d1 = date('Y-m-d H:i:s',$d1);
- if (mysql_result(mysql_query("select count(*) from {$pref}db_session where user='{$id}'"),0,'count(*)')>0){
- $sql="select * from {$pref}db_session where user='{$id}' and date>='{$d1}'";
- if (mysql_num_rows(mysql_query($sql))>0) return 'Онлайн'; else {
- $sql="select * from {$pref}db_session where user='{$id}'";
- return 'Был в сети:'.sql2date(mysql_result(mysql_query($sql),0 ,'date'));
- }
- }
- }
- function compare_version($name){
- $modul =$name;
- global $pref,$cms_ver,$cmspatch;
- require_once "{$_SERVER['DOCUMENT_ROOT']}/{$cmspatch}/{$name}/instal/var.php";
- if ($name=='modules')
- if (($mod_ver!= $ver)||($cms_ver!='1.3')||mysql_num_rows(mysql_query("select * from {$pref}db_modules"))!=17)
- return 'red';
- if ($name!='modules')
- if (($mod_ver!= $ver)||($cms_ver!='1.3'))
- return 'red';
- }
- function get_all_pic_modules($id_type,$id_el){
- global $pref;
- $return="
- <table class='tablesorter' cellspacing='0' >
- <thead>
- <tr>
- <th>ID</th>
- <th>Изображение</th>
- <th>Сортировка</th>
- <th>Удалить</th>
- </tr>
- </thead>
- <tbody class='picmodules'>
- ";
- $sql = "select * from {$pref}db_pic where id_type='{$id_type}' and id_el='{$id_el}' order by sort, id";
- $query = mysql_query($sql);
- if ($query && mysql_num_rows($query)>0){
- while ($res = mysql_fetch_array($query)) {
- $return.="
- <tr id='trpic{$res['id']}'>
- <td>{$res['id']}</td>
- <td><img src='http://{$res['domain']}/resize/?pic=../files/images/{$id_type}/{$res['pic']}&w=100&h=100&tp=2'/></td>
- <td><input class='sortpic' id='{$res['id']}' type='text' size='3' value='{$res['sort']}' /></td>
- <td><input class='deletepic' id='{$res['id']}' type='image' src='../templates/img/icn_trash.png' title='Удалить'></td>
- </tr>
- ";
- }
- }
- $return.="
- </tbody>
- </table>
- ";
- return $return;
- }
- function get_pic_modules($id_type,$id_el,$s,$l){
- global $pref;
- $sql = "select * from {$pref}db_pic where id_type='{$id_type}' and id_el='{$id_el}' order by sort,id limit $s,$l";
- $query = mysql_query($sql);
- if ($query && mysql_num_rows($query)>0){
- $return=array();
- while ($res = mysql_fetch_array($query)) {
- $return1.=",{$res['pic']}";
- $return2.=",{$res['domain']}";
- }
- }
- $return1 = substr($return1, 1);
- $return1 = explode(',', $return1);
- $return2 = substr($return2, 1);
- $return2 = explode(',', $return2);
- $return['pic']=$return1;
- $return['domain']=$return2;
- return $return;
- }
- function tree($id,$lev,$g_id,$db,$name) //Дерево
- {
- global $pref;
- $sql01 = "select * from {$pref}db_{$db} where pid=$id order by sort,id";
- $result01 = mysql_query($sql01);
- while ($rowo01 = mysql_fetch_array($result01)) {
- $id = $rowo01['id'];
- $pid=$rowo01['pid'];
- $name1=$rowo01[$name];
- $a=str_repeat(" ",$lev*3);
- ?>
- <option value="<?=$id?>" <?if ($id==$g_id) echo 'selected';?>><?=$a.$name1?></option>
- <?
- tree($id,($lev+1),$g_id,$db,$name);
- }
- }
- function tree2($id,$lev,$g_id,$db,$name) //Дерево2
- {
- global $pref,$parent_home;
- if (!empty($parent_home))
- $sql01 = "select * from {$pref}db_{$db} where pid=$id and parentid=$parent_home order by sort,id";
- else
- $sql01 = "select * from {$pref}db_{$db} where pid=$id order by sort,id";
- $result01 = mysql_query($sql01);
- while ($rowo01 = mysql_fetch_array($result01)){
- if ($rowo01['status']>0){
- $id = $rowo01['id'];
- $pid=$rowo01['pid'];
- $name1=$rowo01[$name];
- $a=str_repeat(" ",$lev*3);
- ?>
- <option value="<?=$id?>" <?if ($id==$g_id) echo 'selected';?>><?=$a.$name1?></option>
- <?
- tree($id,($lev+1),$g_id,$db,$name);
- }}
- }
- function map($id,$lev,$g_id,$db,$name) //карта сайта
- {
- global $pref;
- $sql01 = "select * from {$pref}db_{$db} where pid=$id and status=1 order by sort,id";
- $result01 = mysql_query($sql01);
- while ($rowo01 = mysql_fetch_array($result01)) {
- $id = $rowo01['id'];
- $pid=$rowo01['pid'];
- $href=$rowo01['href'];
- $name1=$rowo01[$name];
- $a=str_repeat(" ",$lev*3);
- ?>
- <p><?=$a?><a href="<?=$href?>"><?=$name1?></a></p>
- <?
- map($id,($lev+1),$g_id,$db,$name);
- }
- }
- function incude_comp($usl){
- ob_start();
- include $_SERVER['DOCUMENT_ROOT'].'/components/'.$usl;
- $page = ob_get_contents();
- ob_end_clean();
- return $page;
- }
- function getdb($db,$id,$name){
- global $pref;
- $sql = "select * from {$pref}{$db} where id='{$id}'";
- $query = mysql_query($sql);
- if ($query && mysql_num_rows($query)>0){
- return mysql_result($query,0, $name);
- }
- }
- function resize($file_input, $file_output, $w_o, $h_o, $percent = false, $typ) {
- list($w_i, $h_i, $type) = getimagesize($file_input);
- if (!$w_i || !$h_i) {
- echo 'Невозможно получить длину и ширину изображения';
- return;
- }
- $types = array('','gif','jpeg','png');
- $ext = $types[$type];
- if ($ext) {
- $func = 'imagecreatefrom'.$ext;
- $img = $func($file_input);
- } else {
- echo 'Некорректный формат файла';
- return;
- }
- if ($percent) {
- $w_o *= $w_i / 100;
- $h_o *= $h_i / 100;
- }
- if (!$h_o) $h_o = $w_o/($w_i/$h_i);
- if (!$w_o) $w_o = $h_o/($h_i/$w_i);
- $img_o = imagecreatetruecolor($w_o, $h_o);
- imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_o, $h_o, $w_i, $h_i);
- if ($type == 2) {
- return imagejpeg($img_o,$file_output,100);
- } else {
- if (!empty($typ))
- $func = 'image'.$typ;
- else
- $func = 'image'.$ext;
- return $func($img_o,$file_output);
- }
- }
- function addstamp($file_input, $file_output, $typ, $stamp) {
- list($w_i, $h_i, $type) = getimagesize($file_input);
- if (!$w_i || !$h_i) {
- echo 'Невозможно получить длину и ширину изображения';
- return;
- }
- $types = array('','gif','jpeg','png');
- $ext = $types[$type];
- if ($ext) {
- $func = 'imagecreatefrom'.$ext;
- $img = $func($file_input);
- } else {
- echo 'Некорректный формат файла';
- return;
- }
- $img_o = imagecreatetruecolor($w_i, $h_i);
- imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_i, $h_i, $w_i, $h_i);
- $stamp = imagecreatefrompng($_SERVER['DOCUMENT_ROOT'].$stamp);
- $marge_right = 10;
- $marge_bottom = 10;
- $sx = imagesx($stamp);
- $sy = imagesy($stamp);
- imagecopy($img_o, $stamp, $marge_right, imagesy($img_o) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
- if ($type == 2) {
- return imagejpeg($img_o,$file_output,100);
- } else {
- if (!empty($typ))
- $func = 'image'.$typ;
- else
- $func = 'image'.$ext;
- return $func($img_o,$file_output);
- }
- }
- function crop($file_input, $file_output, $crop = 'square',$percent = false) {
- list($w_i, $h_i, $type) = getimagesize($file_input);
- if (!$w_i || !$h_i) {
- echo 'Невозможно получить длину и ширину изображения';
- return;
- }
- $types = array('','gif','jpeg','png');
- $ext = $types[$type];
- if ($ext) {
- $func = 'imagecreatefrom'.$ext;
- $img = $func($file_input);
- } else {
- echo 'Некорректный формат файла';
- return;
- }
- if ($crop == 'square') {
- $min = $w_i;
- if ($w_i > $h_i) $min = $h_i;
- $w_o = $h_o = $min;
- } else {
- list($x_o, $y_o, $w_o, $h_o) = $crop;
- if ($percent) {
- $w_o *= $w_i / 100;
- $h_o *= $h_i / 100;
- $x_o *= $w_i / 100;
- $y_o *= $h_i / 100;
- }
- if ($w_o < 0) $w_o += $w_i;
- $w_o -= $x_o;
- if ($h_o < 0) $h_o += $h_i;
- $h_o -= $y_o;
- }
- $img_o = imagecreatetruecolor($w_o, $h_o);
- imagecopy($img_o, $img, 0, 0, $x_o, $y_o, $w_o, $h_o);
- if ($type == 2) {
- return imagejpeg($img_o,$file_output,100);
- } else {
- $func = 'image'.$ext;
- return $func($img_o,$file_output);
- }
- }
- function safehtml($txt){
- $txt = trim($txt);
- $txt = htmlspecialchars($txt);
- $txt = stripslashes($txt);
- $txt = str_replace("\r\n","<br>",$txt);
- return ($txt);
- }
- function translitIt($str)
- {
- $tr = array(
- "А"=>"a","Б"=>"b","В"=>"v","Г"=>"g",
- "Д"=>"d","Е"=>"e","Ж"=>"j","З"=>"z","И"=>"i",
- "Й"=>"y","К"=>"k","Л"=>"l","М"=>"m","Н"=>"n",
- "О"=>"o","П"=>"p","Р"=>"r","С"=>"s","Т"=>"t",
- "У"=>"u","Ф"=>"f","Х"=>"h","Ц"=>"ts","Ч"=>"ch",
- "Ш"=>"sh","Щ"=>"sch","Ъ"=>"","Ы"=>"yi","Ь"=>"",
- "Э"=>"e","Ю"=>"yu","Я"=>"ya","а"=>"a","б"=>"b",
- "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"j",
- "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
- "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
- "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
- "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"y",
- "ы"=>"yi","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya",
- " "=> "_", "."=> ""
- );
- return strtr($str,$tr);
- }
- ?>