Advertisement
Guest User

Untitled

a guest
Sep 19th, 2013
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.60 KB | None | 0 0
  1. <?php
  2.  
  3. function existLang($lang)
  4. {
  5. if (sEmpty($lang) || $lang == "." || $lang == "..") {
  6. return false;
  7. }
  8. return is_dir("tpl/{$lang}");
  9. }
  10.  
  11. function getLang($lang = "")
  12. {
  13. global $_GS;
  14. if ($lang == "") {
  15. $lang = $_GS['lang'];
  16. } else if ($lang == "*") {
  17. $lang = $_GS['default_lang'];
  18. }
  19. if (existlang($lang)) {
  20. return $lang;
  21. }
  22. return $_GS['default_lang'];
  23. }
  24.  
  25. function getLangDir($lang = "")
  26. {
  27. global $_GS;
  28. $dir = "tpl/";
  29. foreach (array(
  30. getlang($lang),
  31. $_GS['mode'],
  32. $_GS['theme']
  33. ) as $d) {
  34. if (sEmpty($d)) {
  35. break;
  36. }
  37. if (is_dir($dir . $d)) {
  38. $dir .= $d . "/";
  39. } else {
  40. break;
  41. break;
  42. }
  43. }
  44. return $dir;
  45. }
  46.  
  47. function prepVal(&$vl, $conv)
  48. {
  49. global $_GS;
  50. if (!is_array($vl)) {
  51. if ($conv & 1) {
  52. $vl = textLangFilter($vl, $_GS['lang']);
  53. }
  54. if ($conv & 2) {
  55. $vl = htmlspecialchars($vl, ENT_QUOTES);
  56. } else {
  57. if ($conv & 4) {
  58. $vl = strip_tags($vl);
  59. }
  60. }
  61. } else {
  62. foreach ($vl as $f => $v) {
  63. prepVal($vl[$f], $conv);
  64. }
  65. }
  66. }
  67.  
  68. function setPage($par, $val, $conv = 3)
  69. {
  70. global $tpl_page;
  71. if (0 < $conv) {
  72. prepval(&$val, $conv);
  73. }
  74. $tpl_page->assign($par, $val);
  75. }
  76.  
  77. function showPage($templ = "", $module = false, $exit_after = true)
  78. {
  79. global $tpl_page;
  80. global $tpl_errors;
  81. global $_IN;
  82. global $_GS;
  83. global $_DF;
  84. global $_cfg;
  85. if ($module === false) {
  86. $module = $_GS['module'];
  87. }
  88. setpage("tpl_module", $module);
  89. setpage("tpl_vmodule", $_GS['vmodule']);
  90. if (file_exists($_GS['module_dir'] . $module . ".php")) {
  91. $t = cutElemR($module, "/");
  92. if (!$templ) {
  93. $templ = $t;
  94. }
  95. } else if (!$templ) {
  96. $templ = "index";
  97. }
  98. setpage("tpl_name", $templ);
  99. $templ = $module . "/" . $templ;
  100. setpage("tpl_filename", $templ);
  101. loadDateFormat($lang);
  102. setpage("InputDateFormatLong", trim($_DF[$lang][3]));
  103. setpage("InputDateFormat", trim($_DF[$lang][4]));
  104. setpage("tpl_time", time() + $_GS['TZ']);
  105. setpage("_IN", $_IN);
  106. setpage("tpl_info", getInfoData("*"));
  107. setpage("tpl_errors", $tpl_errors);
  108. $tpl_page->template_dir = $_GS['lang_dir'];
  109. if (1 < abs(chklic(5) - time())) {
  110. exit();
  111. }
  112. if ($_cfg['Sys_ForceCharset']) {
  113. header("Content-Type: text/html; charset=utf-8");
  114. }
  115. $tpl_page->display($templ . ".tpl");
  116. if ($exit_after) {
  117. exit();
  118. }
  119. }
  120.  
  121. function showInfo($code = "Completed", $url = "*", $data = array())
  122. {
  123. $url = fullURL($url);
  124. $_SESSION['_show_info'][$url] = array(
  125. $code,
  126. $data
  127. );
  128. goToURL($url);
  129. }
  130.  
  131. function showSplash($code = "Completed", $url = "*", $data = array(), $Var_72 = "splash", $tm = 0)
  132. {
  133. $url = fullURL($url);
  134. $_SESSION['_show_info'][$url] = array(
  135. $code,
  136. $data
  137. );
  138. if ($tm < 1) {
  139. $tm = substr($code, 0, 1) == "*" ? 3 : 1;
  140. }
  141. refreshToURL($tm, $url);
  142. setpage("url", $url);
  143. showpage($templ);
  144. }
  145.  
  146. function showFormInfo($code = "Completed", $form = "", $data = array())
  147. {
  148. $_SESSION['_show_info'][getFormName()] = array(
  149. $code,
  150. $data
  151. );
  152. goToURL(fullURL());
  153. }
  154.  
  155. function getInfoData($id = "", $and_unset = true)
  156. {
  157. $id = $id == "*" ? fullURL() : getFormName($id);
  158. $info = @$_SESSION['_show_info'][$id];
  159. if ($and_unset) {
  160. unset($_SESSION['_show_info'][$id]);
  161. }
  162. return $info;
  163. }
  164.  
  165. function getFormName($form = "")
  166. {
  167. global $_GS;
  168. if (!$form || is_int($form)) {
  169. return $_GS['module'] . "_frm" . $form;
  170. }
  171. return $form;
  172. }
  173.  
  174. function sendedForm($btn = "", $form = "")
  175. {
  176. global $_IN;
  177. $form = getformname($form) . "_btn" . $btn;
  178. unset($_IN[$form]);
  179. return $res;
  180. }
  181.  
  182. function setError($e, $form = "", $and_break = true)
  183. {
  184. if (!is_string($e)) {
  185. } else {
  186. global $tpl_errors;
  187. $tpl_errors[getformname($form)][] = $e;
  188. if ($and_break) {
  189. xAbort($e);
  190. }
  191. }
  192. }
  193.  
  194. function breakIfError($form = "", $e = "Error")
  195. {
  196. global $tpl_errors;
  197. if (0 < count($tpl_errors[getformname($form)])) {
  198. xAbort($e);
  199. }
  200. }
  201.  
  202. function loadText($section, $file = "texts", $lang = "")
  203. {
  204. $file = getlangdir($lang) . "{$file}.lng";
  205. if (!file_exists($file)) {
  206. return false;
  207. }
  208. $res = array();
  209. $celem = "";
  210. $is = false;
  211. $h = fopen($file, "r");
  212. while (!feof($h)) {
  213. $s = trim(fgets($h, 4096));
  214. if (substr($s, 0, 2) == "//") {
  215. continue;
  216. }
  217. if (substr($s, 0, 1) == "[" && substr($s, 0 - 1) == "]") {
  218. if ($is && textPos(".", $celem) < 0) {
  219. break;
  220. }
  221. $celem = trim(substr($s, 1, 0 - 1));
  222. $is = get1ElemL($celem, ".") == $section;
  223. } else if ($is) {
  224. $res .= $celem;
  225. }
  226. }
  227. fclose($h);
  228. return $res;
  229. }
  230.  
  231. function sendMailToUser($mail, $section, $consts = array(), $lang = "", $fname = "e-mails")
  232. {
  233. global $_GS;
  234. global $_cfg;
  235. if (!validMail($mail) || !$section) {
  236. return false;
  237. }
  238. $lang = getlang($lang);
  239. $txt = loadtext($section, $fname, $lang);
  240. if (!$txt["{$section}.message"]) {
  241. return false;
  242. }
  243. $hdr = loadtext("_header", $fname, $lang);
  244. $ftr = loadtext("_footer", $fname, $lang);
  245. $consts['date'] = timeToStr(time(), 0, $lang);
  246. $consts['ip'] = $_GS['client_ip'];
  247. $consts['rooturl'] = $_GS['root_url'];
  248. $consts['sitename'] = $_cfg['Sys_SiteName'];
  249. prepval(&$consts, 2);
  250. return sendMail();
  251. }
  252.  
  253. function sendMailToAdmin($section, $consts = array())
  254. {
  255. global $_cfg;
  256. return sendmailtouser($_cfg['Sys_AdminMail'], $section, $consts, $_cfg['Sys_AdminLang'], "admin/e-mails");
  257. }
  258.  
  259. function loadDateFormat(&$lang)
  260. {
  261. global $_DF;
  262. $lang = getlang($lang);
  263. if (isset($_DF[$lang])) {
  264. } else {
  265. $df = getlangdir($lang) . "date.lng";
  266. if (file_exists($df)) {
  267. $a = @file(@$df);
  268. $l1 = explode("|", @$a[0], 5);
  269. $l2 = explode("|", @$a[1], 12);
  270. $l3 = explode("|", @$a[2], 6);
  271. if (3 <= count($l1) && count($l2) == 12) {
  272. $_DF[$lang] = $l1;
  273. $_DF[$lang]['m'] = $l2;
  274. $_DF[$lang]['f'] = $l3;
  275. }
  276. }
  277. if (!isset($_DF[$lang])) {
  278. $lang = 0;
  279. }
  280. }
  281. }
  282.  
  283. function timeToStr($t, $format = 0, $lang = "", $tz = "")
  284. {
  285. if (!$t) {
  286. return "";
  287. }
  288. global $_GS;
  289. global $_DF;
  290. loaddateformat(&$lang);
  291. $s = "";
  292. if ($tz === "") {
  293. $tz = $_GS['TZ'];
  294. }
  295. $t += $tz;
  296. $t0 = time() + $tz;
  297. if ($format == 2) {
  298. $fc = floor(count($_DF[$lang]['f']) / 2);
  299. if (0 - $fc <= $n && $n <= $fc) {
  300. $s = $_DF[$lang]['f'][$n + $fc];
  301. }
  302. }
  303. if (!$s) {
  304. $s = gmdate($_DF[$lang][1], $t);
  305. $m = $_DF[$lang]['m'][0 - 1 + gmdate("m", $t)];
  306. $s = textReplace($s, "*", $m);
  307. }
  308. if ($format != 1) {
  309. $s = textReplace(gmdate($_DF[$lang][0], $t), "%", $s);
  310. }
  311. return $s;
  312. }
  313.  
  314. function textToTime($sd, $format = 0, $lang = "", $tz = "")
  315. {
  316. global $_GS;
  317. global $_DF;
  318. if (!$sd) {
  319. return "";
  320. }
  321. foreach (array(
  322. "/",
  323. "-",
  324. ":",
  325. " ",
  326. ",",
  327. ";"
  328. ) as $d) {
  329. $sd = textReplace($sd, $d, ".");
  330. }
  331. $sd = textReplace($sd, "..", ".");
  332. loaddateformat(&$lang);
  333. $sd = textUp($_DF[$lang][2]);
  334. $a = array(
  335. 0,
  336. 0,
  337. 0,
  338. 0,
  339. 0
  340. );
  341. foreach (array(
  342. "Y",
  343. "M",
  344. "D",
  345. "H",
  346. "I"
  347. ) as $i => $c) {
  348. $a[$i] = $d[TextPos(@$c, @$sd)];
  349. }
  350. if ($tz === "") {
  351. $tz = $_GS['TZ'];
  352. }
  353. $t0 = time() + $tz;
  354. if (3 <= textLen($d[0])) {
  355. foreach ($_DF[$lang]['f'] as $n => $m) {
  356. if (textPos(textUp($d[0]), textUp($m)) == 0) {
  357. $Var_2256 = $t0 + HS2_UNIX_DAY * ($n - floor(count($_DF[$lang]['f']) / 2));
  358. $a = array(
  359. gmdate("Y", $t),
  360. gmdate("n", $t),
  361. gmdate("j", $t),
  362. $d[1],
  363. $d[2]
  364. );
  365. break;
  366. break;
  367. }
  368. }
  369. }
  370. if (!intval($a[2])) {
  371. return "";
  372. }
  373. if (3 <= textLen($a[1])) {
  374. foreach ($_DF[$lang]['m'] as $n => $m) {
  375. if (textPos(textUp($a[1]), textUp($m)) == 0) {
  376. $a[1] = $n + 1;
  377. break;
  378. break;
  379. }
  380. }
  381. }
  382. if (0 < $format) {
  383. $a[3] = 0;
  384. $a[4] = 0;
  385. }
  386. if ($a[2] && !$a[0]) {
  387. $a[0] = gmdate("Y", $t0);
  388. if (!intval($a[1])) {
  389. $a[1] = gmdate("n", $t0);
  390. }
  391. }
  392. if ($t = gmmktime(intval($a[3]), intval($a[4]), 0, intval($a[1]), intval($a[2]), intval($a[0]))) {
  393. if ($format == 2 && 0 < $t) {
  394. $t += HS2_UNIX_DAY - 1;
  395. }
  396. $t -= $tz;
  397. }
  398. return $t;
  399. }
  400.  
  401. function stampArrayToStr(&$a, $keys, $format = 2, $lang = "")
  402. {
  403. if (is_array($a) && $a) {
  404. foreach (asArray($keys) as $k) {
  405. $a[$k] = timetostr(stampToTime($a[$k]), $format, $lang);
  406. }
  407. }
  408. }
  409.  
  410. function stampTableToStr(&$a, $keys, $format = 2, $lang = "")
  411. {
  412. if (is_array($a) && $a && ($keys = asArray($keys))) {
  413. foreach ($a as $i => $r) {
  414. stamparraytostr(&$a[$i], $keys, $format, $lang);
  415. }
  416. }
  417. }
  418.  
  419. function strArrayToStamp(&$a, $keys, $format = 0, $lang = "")
  420. {
  421. if (is_array($a) && $a) {
  422. foreach (asArray($keys) as $k) {
  423. $a[$k] = timeToStamp(texttotime($a[$k], $format, $lang));
  424. }
  425. }
  426. }
  427.  
  428. function getFormCert($form = "")
  429. {
  430. if (!isset($_SESSION)) {
  431. return false;
  432. }
  433. $form = getformname($form);
  434. $s = substr(md5(time() . rand()), 0, 8);
  435. $_SESSION['_cert'][$form] = $s;
  436. if (10 < count($_SESSION['_cert'])) {
  437. array_shift($_SESSION['_cert']);
  438. }
  439. return "<input name=\"__Cert\" value=\"{$s}\" type=\"hidden\">";
  440. }
  441.  
  442. function chkFormCert($s, $form = "")
  443. {
  444. if (!isset($_SESSION) || !$s) {
  445. return false;
  446. }
  447. $form = getformname($form);
  448. if (!isset($_SESSION['_cert'][$form])) {
  449. return false;
  450. }
  451. $res = $_SESSION['_cert'][$form] === $s;
  452. unset($_SESSION['_cert'][$form]);
  453. return $res;
  454. }
  455.  
  456. function checkFormSecurity($form = "")
  457. {
  458. $form = getformname($form);
  459. if (!chkformcert(_IN("__Cert"), $form)) {
  460. xSysStop("Security: Wrong form certificate", true);
  461. }
  462. global $_IN;
  463. unset($_IN['__Cert']);
  464. if (function_exists("chkCaptcha") && !chkCaptcha($form)) {
  465. seterror("captcha_wrong", $form);
  466. }
  467. }
  468.  
  469. function tplFormSecurity($params, $tpl_page)
  470. {
  471. $form = getformname($params['form']);
  472. if (function_exists("getCaptcha")) {
  473. $tpl_page->assign("__Capt", getCaptcha(0 + $params['captcha'], $form));
  474. }
  475. return getformcert($form);
  476. }
  477.  
  478. require_once("smarty3/Smarty.class.php");
  479. global $tpl_page;
  480. global $tpl_errors;
  481.  
  482. $tpl_page = $Var_168;
  483. $tpl_page->compile_check = true;
  484. $tpl_page->caching = false;
  485. $tpl_page->debugging = false;
  486. $tpl_page->compile_dir = "tpl_c";
  487. $tpl_page->template_dir = "tpl";
  488. $tpl_errors = array();
  489. require_once("lib/main.php");
  490. if (1 < abs(chklic() - time())) {
  491. exit();
  492. }
  493. global $_DF;
  494. $_DF = array(
  495. 0 => array(
  496. "% H:i",
  497. "* j, Y",
  498. "MDYHI",
  499. "m/d/y h:m",
  500. "m/d/y",
  501. "m" => array(
  502. "Jan",
  503. "Feb",
  504. "Mar",
  505. "Apr",
  506. "May",
  507. "Jun",
  508. "Jul",
  509. "Aug",
  510. "Sep",
  511. "Oct",
  512. "Nov",
  513. "Dec"
  514. ),
  515. "f" => array(
  516. "yesterday",
  517. "today",
  518. "tomorrow"
  519. )
  520. )
  521. );
  522. $tpl_page->registerPlugin("function", "_getFormSecurity", "tplFormSecurity");
  523. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement