PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/function.cms.php

https://bitbucket.org/ssimpledecision/simpledecision
PHP | 483 lines | 458 code | 25 blank | 0 comment | 89 complexity | e49667e6e19eec4340e99e3ecc318c60 MD5 | raw file
  1. <?
  2. function c10($comp,$comp1)
  3. {
  4. global $p_type;
  5. if ($comp1==$p_type || $comp1==0)
  6. if (file_exists('components/'.$comp.'.php'))
  7. include 'components/'.$comp.'.php';
  8. else
  9. echo 'Компонент '.$comp.' не найден';
  10. }
  11. function c11($comp)
  12. {
  13. global $p_type,$p_id,$pref;
  14. $query=mysql_query("select * from {$pref}db_components where name='{$comp}' and status=1 limit 1");
  15. if (mysql_num_rows($query)>0)
  16. {
  17. $res=mysql_fetch_array($query);
  18. if ($res['pid']>0)
  19. {
  20. if ($res['pid']==$p_id)
  21. {
  22. if (file_exists('components/'.$res['comp']))
  23. include 'components/'.$res['comp'];
  24. else
  25. echo 'Компонент '.$comp.' не найден';
  26. }
  27. }
  28. elseif ($res['ptype']==$p_type || $res['ptype']==0)
  29. {
  30. if (file_exists('components/'.$res['comp']))
  31. include 'components/'.$res['comp'];
  32. else
  33. echo 'Компонент '.$comp.' не найден';
  34. }
  35. }
  36. else echo 'Компонент '.$comp.' не найден';
  37. }
  38. function c12($pos){
  39. global $p_type,$p_id,$pref,$tpl_user;
  40. $tmpl=substr($tpl_user, 14);
  41. $query_components=mysql_query("select * from {$pref}db_components where position='{$pos}' and tmpl='{$tmpl}' and status=1 order by sort,id");
  42. if (mysql_num_rows($query_components)>0){
  43. while ($res_query_components=mysql_fetch_array($query_components)){
  44. $ptype = explode(',', $res_query_components['ptype']);
  45. $pid = explode(',', $res_query_components['pid']);
  46. $exc = explode(',', $res_query_components['exception']);
  47. $except = false;
  48. foreach ($exc as $key => $value) {
  49. if ($value==$p_id) $except = true;
  50. }
  51. if (!$except){
  52. if (!empty($pid[0])){
  53. if (in_array($p_id, $pid))
  54. {
  55. if (file_exists('components/'.$tmpl.'/'.$res_query_components['comp']) && $res_query_components['comp']!='')
  56. include 'components/'.$tmpl.'/'.$res_query_components['comp'];
  57. else
  58. echo 'Компонент '.$res_query_components['name'].' не найден';
  59. }
  60. }
  61. elseif (in_array($p_type, $ptype) || $res_query_components['ptype']=='0')
  62. {
  63. if (file_exists('components/'.$tmpl.'/'.$res_query_components['comp']) && $res_query_components['comp']!='')
  64. include 'components/'.$tmpl.'/'.$res_query_components['comp'];
  65. else
  66. echo 'Компонент '.$res_query_components['name'].' не найден';
  67. }
  68. }
  69. }
  70. }
  71. }
  72. function c13($pos){
  73. global $p_type,$p_id,$pref,$tpl_user;
  74. $tmpl=substr($tpl_user, 14);
  75. $query_components=mysql_query("select * from {$pref}db_components where position='{$pos}' and tmpl='{$tmpl}' and status=1 order by sort,id");
  76. if (mysql_num_rows($query_components)>0){
  77. while ($res_query_components=mysql_fetch_array($query_components)){
  78. if (file_exists('components/'.$tmpl.'/'.$res_query_components['comp']) && $res_query_components['comp']!='')
  79. include 'components/'.$tmpl.'/'.$res_query_components['comp'];
  80. else
  81. echo 'Компонент '.$res_query_components['name'].' не найден';
  82. }
  83. }
  84. }
  85. function date2sql($dd)
  86. {
  87. $ddo = substr($dd,6,4)."-".substr($dd,3,2)."-".substr($dd,0,2)." ".substr($dd,11,5).":".date('s');
  88. return ($ddo);
  89. }
  90. function sql2date($dd)
  91. {
  92. $ddo = substr($dd,8,2).".".substr($dd,5,2).".".substr($dd,0,4)." ".substr($dd,11,8);
  93. return ($ddo);
  94. }
  95. function sql2date1($dd)
  96. {
  97. $ddo = substr($dd,8,2).".".substr($dd,5,2).".".substr($dd,0,4)." ".substr($dd,11,8);
  98. return (substr($ddo,0,10));
  99. }
  100. function sql2dateICMS($dd,$type)
  101. {
  102. $m_arr = array("января","февраля","марта","апреля","мая","июня","июля","августа","сентября","октября","ноября","декабря");
  103. $m_arr_short = array("янв","фев","мар","апр","мая","июн","июл","авг","сен","окт","ноя","дек");
  104. $day = substr($dd,8,2);
  105. $month_let = $m_arr[substr($dd,5,2)-1];
  106. $month_sh = $m_arr_short[substr($dd,5,2)-1];
  107. $month = substr($dd,5,2);
  108. $year = substr($dd,0,4);
  109. $year_short = substr($dd,2,2);
  110. switch ($type)
  111. {
  112. case 1:
  113. $ddo = $day.".".$month.".".$year;
  114. break;
  115. case 2:
  116. $ddo = $day." ".$month_let." ".$year;
  117. break;
  118. case 3:
  119. $ddo = $day." ".$month_let." ".$year." г.";
  120. break;
  121. case 4:
  122. $ddo = $day." ".$month_sh." ".$year;
  123. break;
  124. case 5:
  125. $ddo = $day." ".$month_sh." ".$year." г.";
  126. break;
  127. case 6:
  128. $ddo = $day.".".$month.".".$year_short;
  129. break;
  130. case 7:
  131. $ddo = $day."/".$month."/".$year;
  132. break;
  133. case 8:
  134. $ddo = $day."/".$month;
  135. break;
  136. case 9:
  137. $ddo = $day."-".$month."-".$year;
  138. break;
  139. }
  140. return ($ddo);
  141. }
  142. function paging_m($total,$lim,$p)
  143. {
  144. global $href,$arg_no_p;
  145. $total = ceil($total/$lim);
  146. print '<ul class="paging">';
  147. $p1=1;
  148. $total1=$total;
  149. if ($total>16){
  150. $p1=$p-8;
  151. if ($p1<1) $p1=1;
  152. $total1=$p1+16;
  153. if ($total1>$total) $total1=$total;
  154. }
  155. if ($p>9)
  156. print '<li><a href="'.$href.'?'.$arg_no_p.'&p='.($p1-1).'">...</a></li>';
  157. for ($i=$p1;$i<=$total1;$i++) {
  158. if ($p==($i)) $act='active';else $act='';
  159. print '<li class="'.$act.'"><a href="'.$href.'?'.$arg_no_p.'&p='.($i);
  160. print '">'.($i).'</a></li>';
  161. }
  162. if ($p<$total-8)
  163. print '<li><a href="'.$href.'?'.$arg_no_p.'&p='.($p1+17).'">...</a></li>';
  164. print '</ul>';
  165. }
  166. function getUser($id,$t){
  167. global $pref;
  168. $sql = mysql_query("select * from {$pref}db_users where id='{$id}' limit 1");
  169. if ($sql && mysql_num_rows($sql)>0)
  170. return mysql_result($sql,0, $t);
  171. }
  172. function getUserType(){
  173. if (isset($_SESSION['user_id'])){
  174. global $pref;
  175. $sql = "select * from {$pref}db_users where id='{$_SESSION['user_id']}' limit 1";
  176. return mysql_result(mysql_query($sql),0, 'type');
  177. }
  178. }
  179. function getStatusUser($id){
  180. global $pref;
  181. $d1= time();
  182. $d1=$d1-180;
  183. $d1 = date('Y-m-d H:i:s',$d1);
  184. if (mysql_result(mysql_query("select count(*) from {$pref}db_session where user='{$id}'"),0,'count(*)')>0){
  185. $sql="select * from {$pref}db_session where user='{$id}' and date>='{$d1}'";
  186. if (mysql_num_rows(mysql_query($sql))>0) return 'Онлайн'; else {
  187. $sql="select * from {$pref}db_session where user='{$id}'";
  188. return 'Был в сети:'.sql2date(mysql_result(mysql_query($sql),0 ,'date'));
  189. }
  190. }
  191. }
  192. function compare_version($name){
  193. $modul =$name;
  194. global $pref,$cms_ver,$cmspatch;
  195. require_once "{$_SERVER['DOCUMENT_ROOT']}/{$cmspatch}/{$name}/instal/var.php";
  196. if ($name=='modules')
  197. if (($mod_ver!= $ver)||($cms_ver!='1.3')||mysql_num_rows(mysql_query("select * from {$pref}db_modules"))!=17)
  198. return 'red';
  199. if ($name!='modules')
  200. if (($mod_ver!= $ver)||($cms_ver!='1.3'))
  201. return 'red';
  202. }
  203. function get_all_pic_modules($id_type,$id_el){
  204. global $pref;
  205. $return="
  206. <table class='tablesorter' cellspacing='0' >
  207. <thead>
  208. <tr>
  209. <th>ID</th>
  210. <th>Изображение</th>
  211. <th>Сортировка</th>
  212. <th>Удалить</th>
  213. </tr>
  214. </thead>
  215. <tbody class='picmodules'>
  216. ";
  217. $sql = "select * from {$pref}db_pic where id_type='{$id_type}' and id_el='{$id_el}' order by sort, id";
  218. $query = mysql_query($sql);
  219. if ($query && mysql_num_rows($query)>0){
  220. while ($res = mysql_fetch_array($query)) {
  221. $return.="
  222. <tr id='trpic{$res['id']}'>
  223. <td>{$res['id']}</td>
  224. <td><img src='http://{$res['domain']}/resize/?pic=../files/images/{$id_type}/{$res['pic']}&w=100&h=100&tp=2'/></td>
  225. <td><input class='sortpic' id='{$res['id']}' type='text' size='3' value='{$res['sort']}' /></td>
  226. <td><input class='deletepic' id='{$res['id']}' type='image' src='../templates/img/icn_trash.png' title='Удалить'></td>
  227. </tr>
  228. ";
  229. }
  230. }
  231. $return.="
  232. </tbody>
  233. </table>
  234. ";
  235. return $return;
  236. }
  237. function get_pic_modules($id_type,$id_el,$s,$l){
  238. global $pref;
  239. $sql = "select * from {$pref}db_pic where id_type='{$id_type}' and id_el='{$id_el}' order by sort,id limit $s,$l";
  240. $query = mysql_query($sql);
  241. if ($query && mysql_num_rows($query)>0){
  242. $return=array();
  243. while ($res = mysql_fetch_array($query)) {
  244. $return1.=",{$res['pic']}";
  245. $return2.=",{$res['domain']}";
  246. }
  247. }
  248. $return1 = substr($return1, 1);
  249. $return1 = explode(',', $return1);
  250. $return2 = substr($return2, 1);
  251. $return2 = explode(',', $return2);
  252. $return['pic']=$return1;
  253. $return['domain']=$return2;
  254. return $return;
  255. }
  256. function tree($id,$lev,$g_id,$db,$name) //Дерево
  257. {
  258. global $pref;
  259. $sql01 = "select * from {$pref}db_{$db} where pid=$id order by sort,id";
  260. $result01 = mysql_query($sql01);
  261. while ($rowo01 = mysql_fetch_array($result01)) {
  262. $id = $rowo01['id'];
  263. $pid=$rowo01['pid'];
  264. $name1=$rowo01[$name];
  265. $a=str_repeat("&nbsp;",$lev*3);
  266. ?>
  267. <option value="<?=$id?>" <?if ($id==$g_id) echo 'selected';?>><?=$a.$name1?></option>
  268. <?
  269. tree($id,($lev+1),$g_id,$db,$name);
  270. }
  271. }
  272. function tree2($id,$lev,$g_id,$db,$name) //Дерево2
  273. {
  274. global $pref,$parent_home;
  275. if (!empty($parent_home))
  276. $sql01 = "select * from {$pref}db_{$db} where pid=$id and parentid=$parent_home order by sort,id";
  277. else
  278. $sql01 = "select * from {$pref}db_{$db} where pid=$id order by sort,id";
  279. $result01 = mysql_query($sql01);
  280. while ($rowo01 = mysql_fetch_array($result01)){
  281. if ($rowo01['status']>0){
  282. $id = $rowo01['id'];
  283. $pid=$rowo01['pid'];
  284. $name1=$rowo01[$name];
  285. $a=str_repeat("&nbsp;",$lev*3);
  286. ?>
  287. <option value="<?=$id?>" <?if ($id==$g_id) echo 'selected';?>><?=$a.$name1?></option>
  288. <?
  289. tree($id,($lev+1),$g_id,$db,$name);
  290. }}
  291. }
  292. function map($id,$lev,$g_id,$db,$name) //карта сайта
  293. {
  294. global $pref;
  295. $sql01 = "select * from {$pref}db_{$db} where pid=$id and status=1 order by sort,id";
  296. $result01 = mysql_query($sql01);
  297. while ($rowo01 = mysql_fetch_array($result01)) {
  298. $id = $rowo01['id'];
  299. $pid=$rowo01['pid'];
  300. $href=$rowo01['href'];
  301. $name1=$rowo01[$name];
  302. $a=str_repeat("&nbsp;",$lev*3);
  303. ?>
  304. <p><?=$a?><a href="<?=$href?>"><?=$name1?></a></p>
  305. <?
  306. map($id,($lev+1),$g_id,$db,$name);
  307. }
  308. }
  309. function incude_comp($usl){
  310. ob_start();
  311. include $_SERVER['DOCUMENT_ROOT'].'/components/'.$usl;
  312. $page = ob_get_contents();
  313. ob_end_clean();
  314. return $page;
  315. }
  316. function getdb($db,$id,$name){
  317. global $pref;
  318. $sql = "select * from {$pref}{$db} where id='{$id}'";
  319. $query = mysql_query($sql);
  320. if ($query && mysql_num_rows($query)>0){
  321. return mysql_result($query,0, $name);
  322. }
  323. }
  324. function resize($file_input, $file_output, $w_o, $h_o, $percent = false, $typ) {
  325. list($w_i, $h_i, $type) = getimagesize($file_input);
  326. if (!$w_i || !$h_i) {
  327. echo 'Невозможно получить длину и ширину изображения';
  328. return;
  329. }
  330. $types = array('','gif','jpeg','png');
  331. $ext = $types[$type];
  332. if ($ext) {
  333. $func = 'imagecreatefrom'.$ext;
  334. $img = $func($file_input);
  335. } else {
  336. echo 'Некорректный формат файла';
  337. return;
  338. }
  339. if ($percent) {
  340. $w_o *= $w_i / 100;
  341. $h_o *= $h_i / 100;
  342. }
  343. if (!$h_o) $h_o = $w_o/($w_i/$h_i);
  344. if (!$w_o) $w_o = $h_o/($h_i/$w_i);
  345. $img_o = imagecreatetruecolor($w_o, $h_o);
  346. imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_o, $h_o, $w_i, $h_i);
  347. if ($type == 2) {
  348. return imagejpeg($img_o,$file_output,100);
  349. } else {
  350. if (!empty($typ))
  351. $func = 'image'.$typ;
  352. else
  353. $func = 'image'.$ext;
  354. return $func($img_o,$file_output);
  355. }
  356. }
  357. function addstamp($file_input, $file_output, $typ, $stamp) {
  358. list($w_i, $h_i, $type) = getimagesize($file_input);
  359. if (!$w_i || !$h_i) {
  360. echo 'Невозможно получить длину и ширину изображения';
  361. return;
  362. }
  363. $types = array('','gif','jpeg','png');
  364. $ext = $types[$type];
  365. if ($ext) {
  366. $func = 'imagecreatefrom'.$ext;
  367. $img = $func($file_input);
  368. } else {
  369. echo 'Некорректный формат файла';
  370. return;
  371. }
  372. $img_o = imagecreatetruecolor($w_i, $h_i);
  373. imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_i, $h_i, $w_i, $h_i);
  374. $stamp = imagecreatefrompng($_SERVER['DOCUMENT_ROOT'].$stamp);
  375. $marge_right = 10;
  376. $marge_bottom = 10;
  377. $sx = imagesx($stamp);
  378. $sy = imagesy($stamp);
  379. imagecopy($img_o, $stamp, $marge_right, imagesy($img_o) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
  380. if ($type == 2) {
  381. return imagejpeg($img_o,$file_output,100);
  382. } else {
  383. if (!empty($typ))
  384. $func = 'image'.$typ;
  385. else
  386. $func = 'image'.$ext;
  387. return $func($img_o,$file_output);
  388. }
  389. }
  390. function crop($file_input, $file_output, $crop = 'square',$percent = false) {
  391. list($w_i, $h_i, $type) = getimagesize($file_input);
  392. if (!$w_i || !$h_i) {
  393. echo 'Невозможно получить длину и ширину изображения';
  394. return;
  395. }
  396. $types = array('','gif','jpeg','png');
  397. $ext = $types[$type];
  398. if ($ext) {
  399. $func = 'imagecreatefrom'.$ext;
  400. $img = $func($file_input);
  401. } else {
  402. echo 'Некорректный формат файла';
  403. return;
  404. }
  405. if ($crop == 'square') {
  406. $min = $w_i;
  407. if ($w_i > $h_i) $min = $h_i;
  408. $w_o = $h_o = $min;
  409. } else {
  410. list($x_o, $y_o, $w_o, $h_o) = $crop;
  411. if ($percent) {
  412. $w_o *= $w_i / 100;
  413. $h_o *= $h_i / 100;
  414. $x_o *= $w_i / 100;
  415. $y_o *= $h_i / 100;
  416. }
  417. if ($w_o < 0) $w_o += $w_i;
  418. $w_o -= $x_o;
  419. if ($h_o < 0) $h_o += $h_i;
  420. $h_o -= $y_o;
  421. }
  422. $img_o = imagecreatetruecolor($w_o, $h_o);
  423. imagecopy($img_o, $img, 0, 0, $x_o, $y_o, $w_o, $h_o);
  424. if ($type == 2) {
  425. return imagejpeg($img_o,$file_output,100);
  426. } else {
  427. $func = 'image'.$ext;
  428. return $func($img_o,$file_output);
  429. }
  430. }
  431. function safehtml($txt){
  432. $txt = trim($txt);
  433. $txt = htmlspecialchars($txt);
  434. $txt = stripslashes($txt);
  435. $txt = str_replace("\r\n","<br>",$txt);
  436. return ($txt);
  437. }
  438. function translitIt($str)
  439. {
  440. $tr = array(
  441. "А"=>"a","Б"=>"b","В"=>"v","Г"=>"g",
  442. "Д"=>"d","Е"=>"e","Ж"=>"j","З"=>"z","И"=>"i",
  443. "Й"=>"y","К"=>"k","Л"=>"l","М"=>"m","Н"=>"n",
  444. "О"=>"o","П"=>"p","Р"=>"r","С"=>"s","Т"=>"t",
  445. "У"=>"u","Ф"=>"f","Х"=>"h","Ц"=>"ts","Ч"=>"ch",
  446. "Ш"=>"sh","Щ"=>"sch","Ъ"=>"","Ы"=>"yi","Ь"=>"",
  447. "Э"=>"e","Ю"=>"yu","Я"=>"ya","а"=>"a","б"=>"b",
  448. "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"j",
  449. "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
  450. "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
  451. "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
  452. "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"y",
  453. "ы"=>"yi","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya",
  454. " "=> "_", "."=> ""
  455. );
  456. return strtr($str,$tr);
  457. }
  458. ?>