Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.45 KB | None | 0 0
  1. <?php
  2. if (!defined("_VALID_PHP")) { die('Direct access to this location is not allowed.'); }
  3.  
  4. /** =========================================================
  5. * Class Core
  6. * ========================================================== */
  7. class Core
  8. {
  9. public $short_date = '%d %b %Y';
  10. public $long_date = '%d %b %Y - %H:%M';
  11.  
  12. public $site_id = 1;
  13. public $id = '1';
  14. public $do = null;
  15. public $slug = 'home';
  16. public $action = null;
  17. public $site_dir = false;
  18. public $sTable = "settings";
  19. public $quantity_alert = 1;
  20. public $shipping_price = 0;
  21. public $send_email_for_new_orders = 1;
  22.  
  23. function __construct()
  24. {
  25. $this->get_settings();
  26. $this->get_id();
  27. $this->get_do();
  28. $this->get_slug();
  29. $this->get_action();
  30. }
  31.  
  32.  
  33. ////////////////////////////////////////////////////////////////
  34. private function getSettings()
  35. {
  36. global $db;
  37. $sql = "SELECT * FROM " . $this->sTable;
  38. $row = $db->first($sql);
  39.  
  40. $this->site_name = cleanOut($row['site_name']);
  41. $this->items_per_page = cleanOut($row['site_name']);
  42. $this->company_name = cleanOut($row['company_name']);
  43. $this->site_url = $row['site_url'];
  44. $this->site_email = $row['site_email'];
  45. $this->site_phone = $row['site_phone'];
  46. $this->no_reply_email = $row['no_reply_email'];
  47. $this->orders_email = $row['orders_email'];
  48. $this->send_email_for_new_orders = $row['send_email_for_new_orders'];
  49. $this->quantity_alert = $row['quantity_alert'];
  50. $this->theme = $row['theme'];
  51. $this->results_perpage_products = $row['results_perpage_products'];
  52. $this->commenting = $row['commenting'];
  53. $this->facebook_page = $row['facebook_page'];
  54. $this->facebook_appID = $row['facebook_appID'];
  55. $this->facebook_appSecret = $row['facebook_appSecret'];
  56. $this->google_analytics = $row['google_analytics'];
  57. $this->company = $row['company'];
  58. $this->city = $row['city'];
  59. $this->address = $row['address'];
  60. $this->eik = $row['eik'];
  61. $this->mailer = $row['mailer'];
  62. $this->sendmail = $row['sendmail'];
  63. $this->smtp_host = $row['smtp_host'];
  64. $this->smtp_user = $row['smtp_user'];
  65. $this->smtp_pass = $row['smtp_pass'];
  66. $this->smtp_port = $row['smtp_port'];
  67. $this->ver = $row['ver'];
  68. $this->google_ua = $row['google_ua'];
  69. }
  70.  
  71. /** =========================================================
  72. * Function : get_settings()
  73. * ========================================================== */
  74. private function get_settings()
  75. {
  76. global $db;
  77.  
  78. $current_url = parse_url(get_url($_SERVER));
  79. $current_url = $current_url['scheme'] . '://' . $current_url['host'];
  80.  
  81. if(!$current_url) {
  82. $current_url = "http://adoresensation.bg";
  83. }
  84.  
  85. $sql = "SELECT * FROM " . TABLE_SETTINGS . " WHERE site_url = '" . $current_url . "'";
  86. $rows = $db->first($sql);
  87.  
  88. $this->site_id = $rows['id'];
  89.  
  90. unset($rows['id']);
  91.  
  92. if($rows) {
  93. foreach ($rows as $key => $row) {
  94. $this->{$key} = $row;
  95. }
  96. }
  97. }
  98.  
  99. /** =========================================================
  100. * Function : process_settings()
  101. * @return array
  102. ========================================================== */
  103. public function process_settings()
  104. {
  105. global $db, $lang, $core;
  106.  
  107. $msgs = array();
  108. $return = array();
  109.  
  110. if (empty(post('site_name'))) {
  111. $msgs['[name="site_name"]'] = _SETTINGS_ERROR_SITE_TITLE;
  112. }
  113.  
  114. if (empty(post('site_url'))) {
  115. $msgs['[name="site_url"]'] = _SETTINGS_ERROR_SITE_URL;
  116. }
  117.  
  118. if (empty(post('site_email'))) {
  119. $msgs['[name="site_email"]'] = _SETTINGS_ERROR_SITE_EMAIL;
  120. }
  121.  
  122. if (empty($this->msgs)){
  123. $data = array(
  124. 'site_name' => sanitize(post('site_name')),
  125. 'site_url' => sanitize(post('site_url')),
  126. 'site_email' => sanitize(post('site_email')),
  127. 'lang' => sanitize(post('lang')),
  128. 'commenting' => sanitize(post('commenting')),
  129. 'facebook_page' => sanitize(post('facebook_page')),
  130. 'facebook_appID' => sanitize(post('facebook_appID')),
  131. 'facebook_appSecret' => sanitize(post('facebook_appSecret')),
  132. 'google_analytics' => post('google_analytics'),
  133. 'company' => post('company'),
  134. 'city' => post('city'),
  135. 'address' => post('address'),
  136. 'eik' => post('eik'),
  137. 'code' => post('code'),
  138. 'results_perpage_products' => post('results_perpage_products'),
  139. 'free_delivery' => post('free_delivery'),
  140. 'quantity_alert' => post('quantity_alert'),
  141. 'google_ua' => post('google_ua')
  142. );
  143.  
  144. $db->update(TABLE_SETTINGS, $data, "id='" . (int) $core->site_id . "'");
  145. $message = _SETTINGS_SUCCESS_UPDATE;
  146.  
  147. if ($db->affected()){
  148. $return = array(
  149. 'status' => 1,
  150. 'msg' => $message,
  151. );
  152. } else {
  153. $return = array(
  154. 'status' => 0,
  155. 'msg' => _ERROR_NO_CHANGES,
  156. );
  157. }
  158. } else {
  159. $return = array(
  160. 'status' => 0,
  161. 'error_fields' => $msgs,
  162. );
  163. }
  164.  
  165. return $return;
  166. }
  167.  
  168. ////////////////////////////////////////////////////////// //////
  169. public function msgAdminOk($msg, $fader = true, $altholder = false)
  170. {
  171. $this->showMsg = "<div class=\"alert alert-success\" role=\"alert\">" . $msg . "</div>";
  172. if ($fader == true)
  173. {
  174. $this->showMsg .= "
  175. <script type=\"text/javascript\">
  176. // <![CDATA[
  177. setTimeout(function() {
  178. $(\".alert-success\").fadeOut(\"slow\",
  179. function() {
  180. $(\".alert-success\").remove();
  181. });
  182. },
  183. 4000);
  184. // ]]>
  185. </script>";
  186. }
  187.  
  188. return ($altholder) ? '<div id="alt-msgholder">' . $this->showMsg . '</div>' : $this->showMsg;
  189. }
  190.  
  191. ////////////////////////////////////////////////////////////////
  192. public function msgStatus($fader = false)
  193. {
  194. //Възникна проблем при обработката на Вашата заявка:
  195. $this->showMsg = "<div class=\"alert alert-error alert-danger alert_box error\" role=\"alert\"><ul class=\"error\" style=\"list-style: none; margin: 0; padding: 0;\">";
  196. foreach ($this->msgs as $msg)
  197. {
  198. $this->showMsg .= "<li>* " . $msg . "</li>\n";
  199. }
  200. $this->showMsg .= "</ul></div>";
  201.  
  202. if ($fader == true)
  203. {
  204. $this->showMsg .= "
  205. <script type=\"text/javascript\">
  206. // <![CDATA[
  207. setTimeout(function() {
  208. $(\".alert_box.error\").fadeOut(\"slow\",
  209. function() {
  210. $(\".alert_box.error\").remove();
  211. });
  212. },
  213. 4000);
  214. // ]]>
  215. </script>";
  216. }
  217.  
  218. return $this->showMsg;
  219. }
  220.  
  221. ////////////////////////////////////////////////////////////////
  222. public function msgAdminAlert($msg, $fader = true, $altholder = false)
  223. {
  224. $this->showMsg = "<div class=\"alert alert-warning\" role=\"alert\">" . $msg . "</div>";
  225. if ($fader == true)
  226. {
  227. $this->showMsg .= "
  228. <script type=\"text/javascript\">
  229. // <![CDATA[
  230. setTimeout(function() {
  231. $(\".alert-warning\").fadeOut(\"slow\",
  232. function() {
  233. $(\".alert-warning\").remove();
  234. });
  235. },
  236. 4000);
  237. // ]]>
  238. </script>";
  239. }
  240.  
  241. return ($altholder) ? '<div id="alt-msgholder">' . $this->showMsg . '</div>' : $this->showMsg;
  242. }
  243.  
  244. /** =========================================================
  245. * Function : process_email_template()
  246. * @return array
  247. ========================================================== */
  248. public function process_email_template()
  249. {
  250. global $db, $core;
  251.  
  252. $msgs = array();
  253. $return = array();
  254.  
  255. if (empty($_POST['name']))
  256. $msgs['[name="name"]'] = 'Моля, въведете заглавие на темлейта.';
  257.  
  258. if (empty($_POST['subject']))
  259. $msgs['[name="subject"]'] = 'Моля, въведете тема на темлейта.';
  260.  
  261. if (empty($_POST['body']) || $_POST['body'] == "&lt;p&gt;&lt;br&gt;&lt;/p&gt;")
  262. $msgs['#summernote'] = 'Моля, въведете съдържание на темлейта.';
  263.  
  264. if (empty($msgs)) {
  265. $data = array(
  266. 'name' => sanitize($_POST['name']),
  267. 'subject' => sanitize($_POST['subject']),
  268. 'body' => $_POST['body'],
  269. 'help' => sanitize($_POST['help'])
  270. );
  271.  
  272. $db->update(TABLE_EMAIL_TEMPLATES, $data, "id='" . (int)$core->id . "'");
  273.  
  274. if(($db->affected())){
  275. $return = array(
  276. 'status' => 1,
  277. 'msg' => 'Email темлейта бе обновен успешно!'
  278. );
  279. } else {
  280. $return = array(
  281. 'status' => 0,
  282. 'msg' => "Не бяха открити промени."
  283. );
  284. }
  285. } else {
  286. $return = array(
  287. 'status' => 0,
  288. 'error_fields' => $msgs
  289. );
  290. }
  291.  
  292. return $return;
  293. }
  294.  
  295. /** =========================================================
  296. * Function : get_sites()
  297. * ========================================================== */
  298. public function get_sites()
  299. {
  300. global $db;
  301.  
  302. $sql = "SELECT
  303. id AS site_id,
  304. site_name,
  305. site_url,
  306. lang AS site_lang"
  307. . "\n FROM " . TABLE_SETTINGS . ""
  308. . "\n WHERE id != '0'"
  309. . "\n ORDER BY id ASC";
  310. $rows = $db->fetch_all($sql);
  311.  
  312. return ($rows) ? $rows : 0;
  313. }
  314.  
  315. /** =======================================================
  316. * Function : get_id()
  317. * @return mixed
  318. ========================================================== */
  319. private function get_id()
  320. {
  321. if (isset($_GET['id'])) {
  322. $id = ((int)$_GET['id']) ? (int)$_GET['id'] : false;
  323. $id = sanitize($id);
  324.  
  325. if ($id == false) {
  326. $this->error("Invalid Method", "Core::get_id()");
  327. } else
  328. return $this->id = $id;
  329. }
  330. }
  331.  
  332. /** =======================================================
  333. * Function : get_do()
  334. * @return mixed
  335. ========================================================== */
  336. private function get_do()
  337. {
  338. if (isset($_GET['do'])) {
  339. $do = ((string)$_GET['do']) ? (string)$_GET['do'] : false;
  340. $do = sanitize($do);
  341.  
  342. if ($do == false) {
  343. $this->error("Invalid Method", "Core::get_do()");
  344. } else
  345. return $this->do = $do;
  346. }
  347. }
  348.  
  349. /** =========================================================
  350. * Function : get_slug()
  351. * @return array|string
  352. ========================================================== */
  353. private function get_slug()
  354. {
  355. global $db;
  356.  
  357. if (isset($_GET['slug'])) {
  358. $this->slug = sanitize($_GET['slug']);
  359. return $db->escape($this->slug);
  360. }
  361. }
  362.  
  363. /** =========================================================
  364. * Function : get_action()
  365. * @return array|string
  366. ========================================================== */
  367. private function get_action()
  368. {
  369. global $db;
  370.  
  371. if (isset($_GET['action'])) {
  372. $this->action = sanitize($_GET['action']);
  373. return $db->escape($this->action);
  374. }
  375. }
  376.  
  377. /** =======================================================
  378. * Function : error()
  379. *
  380. * @param $message
  381. * @param $source
  382. ========================================================== */
  383. public function error($message, $source)
  384. {
  385. $error_msg = '<div>';
  386. $error_msg .= '<span>System ERROR!</span><br />';
  387. $error_msg .= 'System Error : ' . $message . ' <br />';
  388. $error_msg .= 'More Information : <br />';
  389. $error_msg .= '<ul>';
  390. $error_msg .= '<li>Date : ' . date("F j, Y, g:i a") . '</li>';
  391. $error_msg .= '<li>Function : ' . $source . '</li>';
  392. $error_msg .= '<li>Script : ' . $_SERVER['REQUEST_URI'] . '</li>';
  393. $error_msg .= '</ul>';
  394. $error_msg .= '&lsaquo; <a href="javascript:history.go(-1)"><strong>Go Back</strong></a>';
  395. $error_msg .= '</div>';
  396.  
  397. //print $error_msg;
  398. die($error_msg);
  399. }
  400. /** =======================================================
  401. * Function : dodate()
  402. *
  403. * @param $format, $date
  404. * @return string
  405. ========================================================== */
  406. public function dodate($format, $date)
  407. {
  408. return strftime($format, strtotime($date));
  409. }
  410. }
  411. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement