PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/include/core.php

https://bitbucket.org/jeremejevs/ekselcom-website
PHP | 718 lines | 661 code | 37 blank | 20 comment | 88 complexity | 9b9dc8270732cf6baa145e43a18dd953 MD5 | raw file
  1. <?php
  2. class data
  3. {
  4. public static function database_connect()
  5. {
  6. mysql_connect('localhost', 'root', 'YOU HAVE BEEN RICKROLLD, LOL');
  7. mysql_set_charset('utf8');
  8. mysql_select_db('development');
  9. //mysql_select_db('production');
  10. }
  11. public static function parse_entry($entry)
  12. {
  13. if ($entry == false) return false;
  14. if ($entry['data'] != '')
  15. {
  16. $tmp_ids = json_decode($entry['data']);
  17. foreach ($tmp_ids as $tmp_name => $tmp_id)
  18. {
  19. $tmp_value = mysql_fetch_assoc(mysql_query('SELECT * FROM global_data WHERE id = '.$tmp_id));
  20. $entry[$tmp_name] = core::bb(core::hscd($tmp_value[core::$language]), ($tmp_name == 'content'));
  21. if ($entry[$tmp_name] == '')
  22. {
  23. foreach (core::$languages as $tmp_language)
  24. {
  25. if ($tmp_value[$tmp_language] != '')
  26. {
  27. $entry[$tmp_name] = core::bb(core::hscd($tmp_value[$tmp_language]), ($tmp_name == 'content'));
  28. break;
  29. }
  30. }
  31. }
  32. }
  33. }
  34. return $entry;
  35. }
  36. public static function get_entry_by_id($id)
  37. {
  38. $tmp_result = mysql_query('
  39. SELECT *
  40. FROM global_structure
  41. WHERE id = '.$id
  42. );
  43. return ($tmp_result ? data::parse_entry(mysql_fetch_assoc($tmp_result)) : false);
  44. }
  45. public static function get_entry_by_parent_and_url($parent_id, $url_name)
  46. {
  47. $tmp_result = mysql_query('
  48. SELECT *
  49. FROM global_structure
  50. WHERE parent_id = '.$parent_id.' AND url_name = "'.core::db($url_name).'"'
  51. );
  52. return ($tmp_result ? data::parse_entry(mysql_fetch_assoc($tmp_result)) : false);
  53. }
  54. public static function get_entries_by_parent($parent_id, $limit = false, $in_menu = false)
  55. {
  56. $tmp_result = mysql_query('
  57. SELECT *
  58. FROM global_structure
  59. WHERE parent_id = '.$parent_id.($in_menu != false ? ' AND in_menu = '.$in_menu : '').'
  60. ORDER BY position ASC, created_on DESC'.(is_int($limit) ? ' LIMIT 0, '.$limit : '')
  61. );
  62. $entries = array();
  63. if ($tmp_result) while ($tmp_entry = data::parse_entry(mysql_fetch_assoc($tmp_result))) { $entries[] = $tmp_entry; }
  64. else $entries = false;
  65. return $entries;
  66. }
  67. public static function get_translations($id, $data_name)
  68. {
  69. $tmp_entry = mysql_fetch_assoc(mysql_query('
  70. SELECT *
  71. FROM global_structure
  72. WHERE id = '.$id
  73. ));
  74. $tmp_data = json_decode($tmp_entry['data'], true);
  75. if (isset($tmp_data[$data_name]))
  76. {
  77. return mysql_fetch_assoc(mysql_query('
  78. SELECT *
  79. FROM global_data
  80. WHERE id = '.$tmp_data[$data_name]
  81. ));
  82. }
  83. else return false;
  84. }
  85. public static function add_entry($parent_id, $in_menu, $position, $controller, $url_name, $data)
  86. {
  87. foreach ($data as $tmp_key => $tmp_value)
  88. {
  89. mysql_query('
  90. INSERT INTO global_data (en)
  91. VALUES ("'.$tmp_value.'")
  92. ');
  93. $data[$tmp_key] = mysql_insert_id();
  94. }
  95. if ($position)
  96. {
  97. $tmp_position = mysql_fetch_array(mysql_query('
  98. SELECT MAX(position)
  99. FROM global_structure
  100. WHERE parent_id = '.$parent_id
  101. ));
  102. $position = $tmp_position[0] + 1;
  103. }
  104. else $position = 0;
  105. $url_postfix = 0;
  106. while (mysql_num_rows(mysql_query('
  107. SELECT id
  108. FROM global_structure
  109. WHERE parent_id = '.$parent_id.' AND url_name = "'.core::db($url_name.($url_postfix > 0 ? '-'.$url_postfix : '')).'"'
  110. )) > 0) ++$url_postfix;
  111. if ($url_postfix > 0) $url_name .= '-'.$url_postfix;
  112. mysql_query('
  113. INSERT INTO global_structure
  114. VALUES (
  115. NULL,
  116. '.$parent_id.',
  117. 200,
  118. '.$in_menu.',
  119. '.$position.',
  120. "'.core::db($controller).'",
  121. NOW(),
  122. "'.core::db($url_name).'",
  123. "'.core::db(json_encode($data)).'")
  124. ');
  125. }
  126. public static function set_entry_position($id, $is_up)
  127. {
  128. $tmp_entry = mysql_fetch_assoc(mysql_query('
  129. SELECT *
  130. FROM global_structure
  131. WHERE id = '.$id
  132. ));
  133. if ($is_up)
  134. {
  135. if ($tmp_entry['position'] > 0)
  136. {
  137. $tmp_entry_2 = mysql_fetch_assoc(mysql_query('
  138. SELECT *
  139. FROM global_structure
  140. WHERE parent_id = '.$tmp_entry['parent_id'].' AND position = '.($tmp_entry['position'] - 1)
  141. ));
  142. mysql_query('
  143. UPDATE global_structure
  144. SET position = '.$tmp_entry_2['position'].'
  145. WHERE id = '.$id
  146. );
  147. mysql_query('
  148. UPDATE global_structure
  149. SET position = '.$tmp_entry['position'].'
  150. WHERE id = '.$tmp_entry_2['id']
  151. );
  152. }
  153. }
  154. else
  155. {
  156. $tmp_position = mysql_fetch_array(mysql_query('
  157. SELECT MAX(position)
  158. FROM global_structure
  159. WHERE parent_id = '.$tmp_entry['parent_id']
  160. ));
  161. $tmp_position = $tmp_position[0];
  162. if ($tmp_entry['position'] < $tmp_position)
  163. {
  164. $tmp_entry_2 = mysql_fetch_assoc(mysql_query('
  165. SELECT *
  166. FROM global_structure
  167. WHERE parent_id = '.$tmp_entry['parent_id'].' AND position = '.($tmp_entry['position'] + 1)
  168. ));
  169. mysql_query('
  170. UPDATE global_structure
  171. SET position = '.$tmp_entry_2['position'].'
  172. WHERE id = '.$id
  173. );
  174. mysql_query('
  175. UPDATE global_structure
  176. SET position = '.$tmp_entry['position'].'
  177. WHERE id = '.$tmp_entry_2['id']
  178. );
  179. }
  180. }
  181. }
  182. public static function delete_entry($id, $is_first)
  183. {
  184. $tmp_result = mysql_query('
  185. SELECT *
  186. FROM global_structure
  187. WHERE parent_id = '.$id
  188. );
  189. while ($tmp_entry = mysql_fetch_assoc($tmp_result)) data::delete_entry($tmp_entry['id'], false);
  190. $tmp_entry = mysql_fetch_assoc(mysql_query('
  191. SELECT *
  192. FROM global_structure
  193. WHERE id = '.$id
  194. ));
  195. mysql_query('
  196. INSERT INTO trash_structure
  197. VALUES (
  198. NULL,
  199. '.$tmp_entry['parent_id'].',
  200. '.$tmp_entry['status'].',
  201. '.$tmp_entry['in_menu'].',
  202. '.$tmp_entry['position'].',
  203. "'.core::db($tmp_entry['controller']).'",
  204. '.$tmp_entry['created_on'].',
  205. "'.core::db($tmp_entry['url_name']).'",
  206. "'.core::db($tmp_entry['data']).'")
  207. ');
  208. mysql_query('
  209. DELETE FROM global_structure
  210. WHERE id = '.$id
  211. );
  212. if ($is_first)
  213. {
  214. $tmp_result = mysql_query('
  215. SELECT *
  216. FROM global_structure
  217. WHERE parent_id = '.$tmp_entry['parent_id'].' AND position > '.$tmp_entry['position']
  218. );
  219. while ($tmp_entry = mysql_fetch_assoc($tmp_result))
  220. {
  221. mysql_query('
  222. UPDATE global_structure
  223. SET position = '.($tmp_entry['position'] - 1).'
  224. WHERE id = '.$tmp_entry['id']
  225. );
  226. }
  227. }
  228. }
  229. public static function set_entry_url($id, $url_name)
  230. {
  231. $tmp_entry = mysql_fetch_assoc(mysql_query('
  232. SELECT *
  233. FROM global_structure
  234. WHERE id = '.$id
  235. ));
  236. if ($url_name != $tmp_entry['url_name'])
  237. {
  238. $url_postfix = 0;
  239. while (mysql_num_rows(mysql_query('
  240. SELECT id
  241. FROM global_structure
  242. WHERE parent_id = '.$tmp_entry['parent_id'].' AND url_name = "'.core::db($url_name.($url_postfix > 0 ? '-'.$url_postfix : '')).'"'
  243. )) > 0) ++$url_postfix;
  244. if ($url_postfix > 0) $url_name .= '-'.$url_postfix;
  245. mysql_query('
  246. UPDATE global_structure
  247. SET url_name = "'.$url_name.'"
  248. WHERE id = '.$id
  249. );
  250. }
  251. }
  252. public static function set_translations($id, $data_name, $translations)
  253. {
  254. $tmp_entry = mysql_fetch_assoc(mysql_query('
  255. SELECT *
  256. FROM global_structure
  257. WHERE id = '.$id
  258. ));
  259. $tmp_data = json_decode($tmp_entry['data'], true);
  260. $tmp_set = '';
  261. foreach ($translations as $tmp_language => $tmp_translation) $tmp_set .= ', '.$tmp_language.' = "'.core::db($tmp_translation).'"';
  262. $tmp_set = substr($tmp_set, 2);
  263. mysql_query('
  264. UPDATE global_data
  265. SET '.$tmp_set.'
  266. WHERE id = '.$tmp_data[$data_name]
  267. );
  268. }
  269. }
  270. class core
  271. {
  272. public static $status = 200;
  273. public static $languages = array('en', 'ru', 'lv');
  274. public static $language = '';
  275. public static $request = array();
  276. public static $request_count = 0;
  277. public static $request_real_count = 0;
  278. public static $request_url = array();
  279. public static $request_url_string = '';
  280. public static $controller = '';
  281. public static $has_map = false;
  282. public static $has_admin = false;
  283. public static function db($str) { return mysql_real_escape_string($str); }
  284. public static function hsc($str) { return htmlspecialchars($str); } //, ENT_COMPAT, 'UTF-8', false
  285. public static function hscd($str) { return htmlspecialchars_decode($str); }
  286. public static function url($str) { return rawurlencode($str); }
  287. public static function sha($str) { return hash_hmac('sha512', $str, '3DDA724D877F8D220F017C7002296BB8C1CFAFF1C75E63314D6BD2D1BAEAE794'); }
  288. public static function bb($str, $is_content)
  289. {
  290. if ($is_content && $str != '')
  291. {
  292. if ($str[0] == '[') $str = '[br-4]'.$str;
  293. if ($str[strlen($str) - 1] == ']') $str = $str.'[br-4]';
  294. $tmp_matches = array(array(), array());
  295. preg_match_all("/\]([^\[\]]+)\[/", ']'.$str.'[', $tmp_matches);
  296. foreach ($tmp_matches[1] as $tmp_key => $tmp_value) $tmp_matches[1][$tmp_key] = '][br-12]'.$tmp_value.'[';
  297. $str = str_replace($tmp_matches[0], $tmp_matches[1], ']'.$str.'[');
  298. $str = substr($str, 1, strlen($str) - 2);
  299. preg_match_all("/\[img=(\/public\/png\/content\/[\w\-]+\.png)\]/", $str, $tmp_matches);
  300. foreach ($tmp_matches[1] as $tmp_key => $tmp_value) $tmp_matches[1][$tmp_key] = '[br-12]<img src="'.$tmp_value.'" style="width: 100%; display: block" />';
  301. $str = str_replace($tmp_matches[0], $tmp_matches[1], $str);
  302. if (strpos($str, '[map]') != false)
  303. {
  304. $str = str_replace('[map]', '[br-12]<div id="map" style="width: 100%; height: 256px"></div>', $str);
  305. core::$has_map = true;
  306. }
  307. $tmp_search = array('[br-4]', '[br-8]', '[br-12]', '[br-16]');
  308. $tmp_replace = array('<div style="height: 4px"></div>', '<div style="height: 8px"></div>', '<div style="height: 12px"></div>', '<div style="height: 16px"></div>');
  309. return str_replace($tmp_search, $tmp_replace, $str);
  310. }
  311. else return $str;
  312. }
  313. public static function redirect_to($str)
  314. {
  315. header('Location: /'.$str);
  316. exit();
  317. }
  318. public static function parse_request()
  319. {
  320. $tmp = strlen($_SERVER['REQUEST_URI']) - 1;
  321. if ($tmp > 0 && $_SERVER['REQUEST_URI'][$tmp] == '/') --$tmp;
  322. core::$request_url = explode('/', substr($_SERVER['REQUEST_URI'], 1, $tmp));
  323. core::$language = array_shift(core::$request_url);
  324. if (!in_array(core::$language, core::$languages))
  325. {
  326. if (isset($_COOKIE['language']) && in_array($_COOKIE['language'], core::$languages)) core::redirect_to($_COOKIE['language']);
  327. core::redirect_to(core::$languages[0]);
  328. }
  329. setcookie('language', core::$language, time() + 60 * 60 * 24 * 30 * 60, '/');
  330. core::$request_count = count(core::$request_url);
  331. if (core::$request_count == 0) core::$request_url[0] = 'home';
  332. foreach (core::$request_url as $tmp) core::$request_url_string .= '/'.$tmp;
  333. core::$request_url_string = '/'.core::$language.core::$request_url_string;
  334. $parent_id = 0;
  335. foreach (core::$request_url as $tmp_request)
  336. {
  337. $tmp_entry = data::get_entry_by_parent_and_url($parent_id, $tmp_request);
  338. if ($tmp_entry)
  339. {
  340. core::$request[core::$request_real_count] = $tmp_entry;
  341. if (core::$request[core::$request_real_count]['status'] != 200 && core::$status == 200) core::$status = core::$request[core::$request_real_count]['status'];
  342. $parent_id = core::$request[core::$request_real_count]['id'];
  343. if (core::$request[core::$request_real_count++]['url_name'] == 'admin')
  344. {
  345. core::$has_admin = true;
  346. break;
  347. }
  348. }
  349. else
  350. {
  351. core::$status = 404;
  352. break;
  353. }
  354. }
  355. if (core::$status == 200) core::$controller = core::$request[core::$request_real_count - 1]['controller'];
  356. core::$has_admin = core::$has_admin || (isset($_POST['password']) && $_POST['password'] != '') || isset($_COOKIE['password']);
  357. if (core::$has_admin) admin::parse_request();
  358. }
  359. /*public static function check_email($str)
  360. {
  361. $tmp = db($str);
  362. if ($str != $tmp) return 3;
  363. $str = strtolower($tmp);
  364. if (strlen($str) <= 256 && preg_match("/^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/", $str))
  365. {
  366. if (mysql_num_rows(mysql_query("SELECT * FROM users WHERE email = '".$str."'"))) return 1;
  367. else return 0;
  368. }
  369. else return 2;
  370. }*/
  371. /*public static function unserialize($meta, $fields)
  372. {
  373. $tmp_meta = unserialize(core::hscd($meta));
  374. $tmp_result = array();
  375. foreach ($fields as $tmp_field) if (isset($tmp_meta[$tmp_field])) $tmp_result[$tmp_field] = core::hscd($tmp_meta[$tmp_field]); else $tmp_result[$tmp_field] = '';
  376. return $tmp_result;
  377. }*/
  378. }
  379. class admin
  380. {
  381. public static $is_admin = false;
  382. public static $image = false;
  383. public static $entries = array();
  384. public static function parse_request()
  385. {
  386. if (isset($_POST['password']))
  387. {
  388. if ($_POST['password'] == 'iamadmin')
  389. {
  390. setcookie('password', core::sha($_POST['password']), 0, '/');
  391. admin::$is_admin = true;
  392. }
  393. else setcookie('password', '', 1, '/');
  394. }
  395. else if (isset($_COOKIE['password']) && $_COOKIE['password'] == core::sha('iamadmin')) admin::$is_admin = true;
  396. if (core::$status == 200)
  397. {
  398. if (!admin::$is_admin && core::$controller == 'admin_category')
  399. {
  400. admin::$entries[] = array(
  401. 'name' => 'Log in',
  402. 'id' => 'log-in',
  403. 'url' => '',
  404. 'dialog' => true,
  405. 'params' => array(
  406. array('name' => 'password', 'type' => 'password', 'value' => '')
  407. )
  408. );
  409. }
  410. else
  411. {
  412. switch (core::$controller)
  413. {
  414. case 'admin_category':
  415. admin::$entries[] = array(
  416. 'name' => 'Log out',
  417. 'id' => 'log-out',
  418. 'url' => '',
  419. 'dialog' => false,
  420. 'params' => array(
  421. array('name' => 'password', 'type' => 'hidden', 'value' => '')
  422. )
  423. );
  424. if (isset($_POST['data']))
  425. {
  426. switch ($_POST['data'])
  427. {
  428. case 'upload-image':
  429. $tmp_image = false;
  430. switch (strtolower($_FILES['image']['type']))
  431. {
  432. case 'image/png':
  433. $tmp_image = imagecreatefrompng($_FILES['image']['tmp_name']);
  434. break;
  435. case 'image/jpeg':
  436. $tmp_image = imagecreatefromjpeg($_FILES['image']['tmp_name']);
  437. break;
  438. }
  439. if ($tmp_image !== false)
  440. {
  441. $tmp_image2 = imagecreatetruecolor(928, 256);
  442. imagecolortransparent($tmp_image2, imagecolorallocate($tmp_image2, 0, 0, 0));
  443. $src_w = imagesx($tmp_image);
  444. $src_h = imagesy($tmp_image);
  445. $src_c = $src_w / $src_h;
  446. $dst_c = 928 / 256;
  447. $dst_w = ($src_c > $dst_c ? 928 : (256 / $src_h) * $src_w);
  448. $dst_h = ($src_c > $dst_c ? (928 / $src_w) * $src_h : 256);
  449. $dst_x = ($src_c > $dst_c ? 0 : (928 - $dst_w) / 2);
  450. $dst_y = ($src_c > $dst_c ? (256 - $dst_h) / 2 : 0);
  451. imagecopyresampled($tmp_image2, $tmp_image, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
  452. $tmp_postfix = 0;
  453. $tmp_info = pathinfo($_FILES['image']['name']);
  454. $tmp_name = $_SERVER['DOCUMENT_ROOT'].'/public/png/content/'.preg_replace("/[^\w\-]+/", "-", basename(strtolower($_FILES['image']['name']), '.'.$tmp_info['extension']));
  455. while (file_exists($tmp_name.($tmp_postfix > 0 ? $tmp_postfix : '').'.png')) ++$tmp_postfix;
  456. admin::$image = $tmp_name.($tmp_postfix > 0 ? $tmp_postfix : '').'.png';
  457. imagepng($tmp_image2, admin::$image, 0);
  458. $matches = array();
  459. preg_match("/(\/public\/png\/content\/[\w\-]+\.png)/", admin::$image, $matches);
  460. admin::$image = $matches[0];
  461. }
  462. break;
  463. }
  464. }
  465. break;
  466. case 'products_category':
  467. admin::$entries[] = array(
  468. 'name' => 'Add category',
  469. 'id' => 'add-category',
  470. 'url' => '',
  471. 'dialog' => true,
  472. 'params' => array(
  473. array('name' => 'name', 'type' => 'text', 'value' => ''),
  474. array('name' => 'url_name', 'type' => 'text', 'value' => '')
  475. )
  476. );
  477. admin::$entries[] = array(
  478. 'name' => 'Add entry',
  479. 'id' => 'add-entry',
  480. 'url' => '',
  481. 'dialog' => true,
  482. 'params' => array(
  483. array('name' => 'name', 'type' => 'text', 'value' => ''),
  484. array('name' => 'subname', 'type' => 'text', 'value' => ''),
  485. array('name' => 'url_name', 'type' => 'text', 'value' => ''),
  486. array('name' => 'content', 'type' => 'textarea', 'value' => '')
  487. )
  488. );
  489. if (isset($_POST['data']))
  490. {
  491. switch ($_POST['data'])
  492. {
  493. case 'add-category':
  494. if (!preg_match("/[^\w\-\s,.!\?'\"]+/u", $_POST['name']) && !preg_match("/[^\w\-]+/u", $_POST['url_name']))
  495. {
  496. data::add_entry(
  497. core::$request[core::$request_real_count - 1]['id'],
  498. 1,
  499. true,
  500. 'products_category',
  501. preg_replace("/[_]+/", '-', strtolower($_POST['url_name'])),
  502. array('name' => $_POST['name']));
  503. }
  504. break;
  505. case 'add-entry':
  506. if (!preg_match("/[^\w\-\s,.!\?'\"]+/u", $_POST['name'].$_POST['subname']) && !preg_match("/[^\w\-]+/u", $_POST['url_name']))
  507. {
  508. data::add_entry(
  509. core::$request[core::$request_real_count - 1]['id'],
  510. 0,
  511. true,
  512. 'products_entry',
  513. preg_replace("/[_]+/", '-', strtolower($_POST['url_name'])),
  514. array('name' => $_POST['name'], 'subname' => $_POST['subname'], 'content' => $_POST['content']));
  515. }
  516. break;
  517. case 'position-up':
  518. data::set_entry_position($_POST['id'], true);
  519. break;
  520. case 'position-down':
  521. data::set_entry_position($_POST['id'], false);
  522. break;
  523. case 'delete-entry':
  524. data::delete_entry($_POST['id'], true);
  525. break;
  526. case 'set-url':
  527. data::set_entry_url($_POST['id'], $_POST['url_name']);
  528. break;
  529. case 'set-name':
  530. $tmp_translations = array();
  531. foreach (core::$languages as $tmp_language) $tmp_translations[$tmp_language] = $_POST[$tmp_language];
  532. data::set_translations($_POST['id'], 'name', $tmp_translations);
  533. break;
  534. case 'set-subname':
  535. $tmp_translations = array();
  536. foreach (core::$languages as $tmp_language) $tmp_translations[$tmp_language] = $_POST[$tmp_language];
  537. data::set_translations($_POST['id'], 'subname', $tmp_translations);
  538. break;
  539. case 'set-content':
  540. $tmp_translations = array();
  541. foreach (core::$languages as $tmp_language) $tmp_translations[$tmp_language] = $_POST[$tmp_language];
  542. data::set_translations($_POST['id'], 'content', $tmp_translations);
  543. break;
  544. }
  545. }
  546. break;
  547. case 'home_category':
  548. admin::$entries[] = array(
  549. 'name' => 'Add entry',
  550. 'id' => 'add-entry',
  551. 'url' => '',
  552. 'dialog' => true,
  553. 'params' => array(
  554. array('name' => 'name', 'type' => 'text', 'value' => ''),
  555. array('name' => 'url_name', 'type' => 'text', 'value' => ''),
  556. array('name' => 'content', 'type' => 'textarea', 'value' => '')
  557. )
  558. );
  559. if (isset($_POST['data']))
  560. {
  561. switch ($_POST['data'])
  562. {
  563. case 'add-entry':
  564. if (!preg_match("/[^\w\-\s,.!\?'\"]+/u", $_POST['name']) && !preg_match("/[^\w\-]+/u", $_POST['url_name']))
  565. {
  566. data::add_entry(
  567. core::$request[core::$request_real_count - 1]['id'],
  568. 0,
  569. false,
  570. 'home_entry',
  571. preg_replace("/[_]+/", '-', strtolower($_POST['url_name'])),
  572. array('name' => $_POST['name'], 'content' => $_POST['content']));
  573. }
  574. break;
  575. case 'delete-entry':
  576. data::delete_entry($_POST['id'], true);
  577. break;
  578. case 'set-url':
  579. data::set_entry_url($_POST['id'], $_POST['url_name']);
  580. break;
  581. case 'set-name':
  582. $tmp_translations = array();
  583. foreach (core::$languages as $tmp_language) $tmp_translations[$tmp_language] = $_POST[$tmp_language];
  584. data::set_translations($_POST['id'], 'name', $tmp_translations);
  585. break;
  586. case 'set-content':
  587. $tmp_translations = array();
  588. foreach (core::$languages as $tmp_language) $tmp_translations[$tmp_language] = $_POST[$tmp_language];
  589. data::set_translations($_POST['id'], 'content', $tmp_translations);
  590. break;
  591. }
  592. }
  593. break;
  594. case 'about_category':
  595. admin::$entries[] = array(
  596. 'name' => 'Add category',
  597. 'id' => 'add-category',
  598. 'url' => '',
  599. 'dialog' => true,
  600. 'params' => array(
  601. array('name' => 'name', 'type' => 'text', 'value' => ''),
  602. array('name' => 'url_name', 'type' => 'text', 'value' => '')
  603. )
  604. );
  605. admin::$entries[] = array(
  606. 'name' => 'Add entry',
  607. 'id' => 'add-entry',
  608. 'url' => '',
  609. 'dialog' => true,
  610. 'params' => array(
  611. array('name' => 'name', 'type' => 'text', 'value' => ''),
  612. array('name' => 'subname', 'type' => 'text', 'value' => ''),
  613. array('name' => 'url_name', 'type' => 'text', 'value' => ''),
  614. array('name' => 'content', 'type' => 'textarea', 'value' => '')
  615. )
  616. );
  617. if (isset($_POST['data']))
  618. {
  619. switch ($_POST['data'])
  620. {
  621. case 'add-category':
  622. if (!preg_match("/[^\w\-\s,.!\?'\"]+/u", $_POST['name']) && !preg_match("/[^\w\-]+/u", $_POST['url_name']))
  623. {
  624. data::add_entry(
  625. core::$request[core::$request_real_count - 1]['id'],
  626. 1,
  627. true,
  628. 'about_category',
  629. preg_replace("/[_]+/", '-', strtolower($_POST['url_name'])),
  630. array('name' => $_POST['name']));
  631. }
  632. break;
  633. case 'add-entry':
  634. if (!preg_match("/[^\w\-\s,.!\?'\"]+/u", $_POST['name'].$_POST['subname']) && !preg_match("/[^\w\-]+/u", $_POST['url_name']))
  635. {
  636. data::add_entry(
  637. core::$request[core::$request_real_count - 1]['id'],
  638. 0,
  639. true,
  640. 'about_entry',
  641. preg_replace("/[_]+/", '-', strtolower($_POST['url_name'])),
  642. array('name' => $_POST['name'], 'subname' => $_POST['subname'], 'content' => $_POST['content']));
  643. }
  644. break;
  645. case 'position-up':
  646. data::set_entry_position($_POST['id'], true);
  647. break;
  648. case 'position-down':
  649. data::set_entry_position($_POST['id'], false);
  650. break;
  651. case 'delete-entry':
  652. data::delete_entry($_POST['id'], true);
  653. break;
  654. case 'set-url':
  655. data::set_entry_url($_POST['id'], $_POST['url_name']);
  656. break;
  657. case 'set-name':
  658. $tmp_translations = array();
  659. foreach (core::$languages as $tmp_language) $tmp_translations[$tmp_language] = $_POST[$tmp_language];
  660. data::set_translations($_POST['id'], 'name', $tmp_translations);
  661. break;
  662. case 'set-subname':
  663. $tmp_translations = array();
  664. foreach (core::$languages as $tmp_language) $tmp_translations[$tmp_language] = $_POST[$tmp_language];
  665. data::set_translations($_POST['id'], 'subname', $tmp_translations);
  666. break;
  667. case 'set-content':
  668. $tmp_translations = array();
  669. foreach (core::$languages as $tmp_language) $tmp_translations[$tmp_language] = $_POST[$tmp_language];
  670. data::set_translations($_POST['id'], 'content', $tmp_translations);
  671. break;
  672. }
  673. }
  674. break;
  675. }
  676. }
  677. }
  678. }
  679. }