Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!defined("_VALID_PHP")) { die('Direct access to this location is not allowed.'); }
- /** =========================================================
- * Class Core
- * ========================================================== */
- class Core
- {
- public $short_date = '%d %b %Y';
- public $long_date = '%d %b %Y - %H:%M';
- public $site_id = 1;
- public $id = '1';
- public $do = null;
- public $slug = 'home';
- public $action = null;
- public $site_dir = false;
- public $sTable = "settings";
- public $quantity_alert = 1;
- public $shipping_price = 0;
- public $send_email_for_new_orders = 1;
- function __construct()
- {
- $this->get_settings();
- $this->get_id();
- $this->get_do();
- $this->get_slug();
- $this->get_action();
- }
- ////////////////////////////////////////////////////////////////
- private function getSettings()
- {
- global $db;
- $sql = "SELECT * FROM " . $this->sTable;
- $row = $db->first($sql);
- $this->site_name = cleanOut($row['site_name']);
- $this->items_per_page = cleanOut($row['site_name']);
- $this->company_name = cleanOut($row['company_name']);
- $this->site_url = $row['site_url'];
- $this->site_email = $row['site_email'];
- $this->site_phone = $row['site_phone'];
- $this->no_reply_email = $row['no_reply_email'];
- $this->orders_email = $row['orders_email'];
- $this->send_email_for_new_orders = $row['send_email_for_new_orders'];
- $this->quantity_alert = $row['quantity_alert'];
- $this->theme = $row['theme'];
- $this->results_perpage_products = $row['results_perpage_products'];
- $this->commenting = $row['commenting'];
- $this->facebook_page = $row['facebook_page'];
- $this->facebook_appID = $row['facebook_appID'];
- $this->facebook_appSecret = $row['facebook_appSecret'];
- $this->google_analytics = $row['google_analytics'];
- $this->company = $row['company'];
- $this->city = $row['city'];
- $this->address = $row['address'];
- $this->eik = $row['eik'];
- $this->mailer = $row['mailer'];
- $this->sendmail = $row['sendmail'];
- $this->smtp_host = $row['smtp_host'];
- $this->smtp_user = $row['smtp_user'];
- $this->smtp_pass = $row['smtp_pass'];
- $this->smtp_port = $row['smtp_port'];
- $this->ver = $row['ver'];
- $this->google_ua = $row['google_ua'];
- }
- /** =========================================================
- * Function : get_settings()
- * ========================================================== */
- private function get_settings()
- {
- global $db;
- $current_url = parse_url(get_url($_SERVER));
- $current_url = $current_url['scheme'] . '://' . $current_url['host'];
- if(!$current_url) {
- $current_url = "http://adoresensation.bg";
- }
- $sql = "SELECT * FROM " . TABLE_SETTINGS . " WHERE site_url = '" . $current_url . "'";
- $rows = $db->first($sql);
- $this->site_id = $rows['id'];
- unset($rows['id']);
- if($rows) {
- foreach ($rows as $key => $row) {
- $this->{$key} = $row;
- }
- }
- }
- /** =========================================================
- * Function : process_settings()
- * @return array
- ========================================================== */
- public function process_settings()
- {
- global $db, $lang, $core;
- $msgs = array();
- $return = array();
- if (empty(post('site_name'))) {
- $msgs['[name="site_name"]'] = _SETTINGS_ERROR_SITE_TITLE;
- }
- if (empty(post('site_url'))) {
- $msgs['[name="site_url"]'] = _SETTINGS_ERROR_SITE_URL;
- }
- if (empty(post('site_email'))) {
- $msgs['[name="site_email"]'] = _SETTINGS_ERROR_SITE_EMAIL;
- }
- if (empty($this->msgs)){
- $data = array(
- 'site_name' => sanitize(post('site_name')),
- 'site_url' => sanitize(post('site_url')),
- 'site_email' => sanitize(post('site_email')),
- 'lang' => sanitize(post('lang')),
- 'commenting' => sanitize(post('commenting')),
- 'facebook_page' => sanitize(post('facebook_page')),
- 'facebook_appID' => sanitize(post('facebook_appID')),
- 'facebook_appSecret' => sanitize(post('facebook_appSecret')),
- 'google_analytics' => post('google_analytics'),
- 'company' => post('company'),
- 'city' => post('city'),
- 'address' => post('address'),
- 'eik' => post('eik'),
- 'code' => post('code'),
- 'results_perpage_products' => post('results_perpage_products'),
- 'free_delivery' => post('free_delivery'),
- 'quantity_alert' => post('quantity_alert'),
- 'google_ua' => post('google_ua')
- );
- $db->update(TABLE_SETTINGS, $data, "id='" . (int) $core->site_id . "'");
- $message = _SETTINGS_SUCCESS_UPDATE;
- if ($db->affected()){
- $return = array(
- 'status' => 1,
- 'msg' => $message,
- );
- } else {
- $return = array(
- 'status' => 0,
- 'msg' => _ERROR_NO_CHANGES,
- );
- }
- } else {
- $return = array(
- 'status' => 0,
- 'error_fields' => $msgs,
- );
- }
- return $return;
- }
- ////////////////////////////////////////////////////////// //////
- public function msgAdminOk($msg, $fader = true, $altholder = false)
- {
- $this->showMsg = "<div class=\"alert alert-success\" role=\"alert\">" . $msg . "</div>";
- if ($fader == true)
- {
- $this->showMsg .= "
- <script type=\"text/javascript\">
- // <![CDATA[
- setTimeout(function() {
- $(\".alert-success\").fadeOut(\"slow\",
- function() {
- $(\".alert-success\").remove();
- });
- },
- 4000);
- // ]]>
- </script>";
- }
- return ($altholder) ? '<div id="alt-msgholder">' . $this->showMsg . '</div>' : $this->showMsg;
- }
- ////////////////////////////////////////////////////////////////
- public function msgStatus($fader = false)
- {
- //Възникна проблем при обработката на Вашата заявка:
- $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;\">";
- foreach ($this->msgs as $msg)
- {
- $this->showMsg .= "<li>* " . $msg . "</li>\n";
- }
- $this->showMsg .= "</ul></div>";
- if ($fader == true)
- {
- $this->showMsg .= "
- <script type=\"text/javascript\">
- // <![CDATA[
- setTimeout(function() {
- $(\".alert_box.error\").fadeOut(\"slow\",
- function() {
- $(\".alert_box.error\").remove();
- });
- },
- 4000);
- // ]]>
- </script>";
- }
- return $this->showMsg;
- }
- ////////////////////////////////////////////////////////////////
- public function msgAdminAlert($msg, $fader = true, $altholder = false)
- {
- $this->showMsg = "<div class=\"alert alert-warning\" role=\"alert\">" . $msg . "</div>";
- if ($fader == true)
- {
- $this->showMsg .= "
- <script type=\"text/javascript\">
- // <![CDATA[
- setTimeout(function() {
- $(\".alert-warning\").fadeOut(\"slow\",
- function() {
- $(\".alert-warning\").remove();
- });
- },
- 4000);
- // ]]>
- </script>";
- }
- return ($altholder) ? '<div id="alt-msgholder">' . $this->showMsg . '</div>' : $this->showMsg;
- }
- /** =========================================================
- * Function : process_email_template()
- * @return array
- ========================================================== */
- public function process_email_template()
- {
- global $db, $core;
- $msgs = array();
- $return = array();
- if (empty($_POST['name']))
- $msgs['[name="name"]'] = 'Моля, въведете заглавие на темлейта.';
- if (empty($_POST['subject']))
- $msgs['[name="subject"]'] = 'Моля, въведете тема на темлейта.';
- if (empty($_POST['body']) || $_POST['body'] == "<p><br></p>")
- $msgs['#summernote'] = 'Моля, въведете съдържание на темлейта.';
- if (empty($msgs)) {
- $data = array(
- 'name' => sanitize($_POST['name']),
- 'subject' => sanitize($_POST['subject']),
- 'body' => $_POST['body'],
- 'help' => sanitize($_POST['help'])
- );
- $db->update(TABLE_EMAIL_TEMPLATES, $data, "id='" . (int)$core->id . "'");
- if(($db->affected())){
- $return = array(
- 'status' => 1,
- 'msg' => 'Email темлейта бе обновен успешно!'
- );
- } else {
- $return = array(
- 'status' => 0,
- 'msg' => "Не бяха открити промени."
- );
- }
- } else {
- $return = array(
- 'status' => 0,
- 'error_fields' => $msgs
- );
- }
- return $return;
- }
- /** =========================================================
- * Function : get_sites()
- * ========================================================== */
- public function get_sites()
- {
- global $db;
- $sql = "SELECT
- id AS site_id,
- site_name,
- site_url,
- lang AS site_lang"
- . "\n FROM " . TABLE_SETTINGS . ""
- . "\n WHERE id != '0'"
- . "\n ORDER BY id ASC";
- $rows = $db->fetch_all($sql);
- return ($rows) ? $rows : 0;
- }
- /** =======================================================
- * Function : get_id()
- * @return mixed
- ========================================================== */
- private function get_id()
- {
- if (isset($_GET['id'])) {
- $id = ((int)$_GET['id']) ? (int)$_GET['id'] : false;
- $id = sanitize($id);
- if ($id == false) {
- $this->error("Invalid Method", "Core::get_id()");
- } else
- return $this->id = $id;
- }
- }
- /** =======================================================
- * Function : get_do()
- * @return mixed
- ========================================================== */
- private function get_do()
- {
- if (isset($_GET['do'])) {
- $do = ((string)$_GET['do']) ? (string)$_GET['do'] : false;
- $do = sanitize($do);
- if ($do == false) {
- $this->error("Invalid Method", "Core::get_do()");
- } else
- return $this->do = $do;
- }
- }
- /** =========================================================
- * Function : get_slug()
- * @return array|string
- ========================================================== */
- private function get_slug()
- {
- global $db;
- if (isset($_GET['slug'])) {
- $this->slug = sanitize($_GET['slug']);
- return $db->escape($this->slug);
- }
- }
- /** =========================================================
- * Function : get_action()
- * @return array|string
- ========================================================== */
- private function get_action()
- {
- global $db;
- if (isset($_GET['action'])) {
- $this->action = sanitize($_GET['action']);
- return $db->escape($this->action);
- }
- }
- /** =======================================================
- * Function : error()
- *
- * @param $message
- * @param $source
- ========================================================== */
- public function error($message, $source)
- {
- $error_msg = '<div>';
- $error_msg .= '<span>System ERROR!</span><br />';
- $error_msg .= 'System Error : ' . $message . ' <br />';
- $error_msg .= 'More Information : <br />';
- $error_msg .= '<ul>';
- $error_msg .= '<li>Date : ' . date("F j, Y, g:i a") . '</li>';
- $error_msg .= '<li>Function : ' . $source . '</li>';
- $error_msg .= '<li>Script : ' . $_SERVER['REQUEST_URI'] . '</li>';
- $error_msg .= '</ul>';
- $error_msg .= '‹ <a href="javascript:history.go(-1)"><strong>Go Back</strong></a>';
- $error_msg .= '</div>';
- //print $error_msg;
- die($error_msg);
- }
- /** =======================================================
- * Function : dodate()
- *
- * @param $format, $date
- * @return string
- ========================================================== */
- public function dodate($format, $date)
- {
- return strftime($format, strtotime($date));
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement