예제 #1
0
 public function onCount()
 {
     return;
     $settings_model = new waAppSettingsModel();
     $settings = $settings_model->get('wacab');
     if (!isset($settings['count']) || $settings['count'] == 0) {
         return null;
     }
     if (!isset($settings['count_ts'])) {
         $settings_model->set('wacab', 'count_ts', time());
         return null;
     }
     if (!isset($settings['timeout'])) {
         $settings['timeout'] = 60;
     }
     if (time() - $settings['count_ts'] < $settings['timeout'] * 60) {
         return null;
     }
     $auth = new wacabWaauth();
     $new = new wacabGetpayment();
     $ps = $new->getPayment($auth);
     if (isset($settings['new_count'])) {
         $newcount = $settings['new_count'] + $ps;
     } else {
         $newcount = 0;
     }
     $settings_model->set('wacab', 'new_count', $newcount);
     $settings['count_ts'] = time();
     unset($auth);
     if ($newcount == 0) {
         return null;
     } else {
         return array('count' => $newcount, 'url' => wa()->getUrl(true) . 'wacab/#/transactions/');
     }
 }
 public function execute()
 {
     $model = new shopStockModel();
     foreach ($this->getEditData() as $id => $item) {
         $model->updateById($id, $item);
     }
     $inventory_stock_id = null;
     foreach ($this->getAddData() as $before_id => $data) {
         foreach ($data as $item) {
             $id = $model->add($item, $before_id);
             if (!empty($item['inventory'])) {
                 $inventory_stock_id = $id;
             }
         }
     }
     if ($inventory_stock_id) {
         // Assign all inventory to this stock
         $product_stocks_model = new shopProductStocksModel();
         $product_stocks_model->insertFromSkus($inventory_stock_id);
     }
     $app_id = $this->getAppId();
     $app_settings_model = new waAppSettingsModel();
     if (waRequest::post('ignore_stock_count')) {
         $app_settings_model->set($app_id, 'ignore_stock_count', 1);
     } else {
         $app_settings_model->set($app_id, 'ignore_stock_count', 0);
     }
     if (waRequest::post('update_stock_count_on_create_order')) {
         $app_settings_model->set($app_id, 'update_stock_count_on_create_order', 1);
     } else {
         $app_settings_model->set($app_id, 'update_stock_count_on_create_order', 0);
     }
 }
 public function setCount($n = null)
 {
     wa()->getStorage()->open();
     $model = new waAppSettingsModel();
     $app_id = $this->getApplication();
     $model->set($app_id, 'update_counter', $n);
     $model->set($app_id, 'update_counter_timestamp', $n === false ? 0 : time());
     return parent::setCount($n);
 }
 public function execute()
 {
     $plugin_id = array('shop', 'orderstock');
     try {
         $app_settings_model = new waAppSettingsModel();
         $settings = waRequest::post('settings');
         $state_ids = implode(',', $settings['states']);
         $app_settings_model->set($plugin_id, 'status', (int) $settings['status']);
         $app_settings_model->set($plugin_id, 'state_ids', $state_ids);
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
 public function execute()
 {
     if (wa()->getUser()->getRights('wacab', 'backend') >= 2) {
         $settings = waRequest::get('settings');
         $settings_model = new waAppSettingsModel();
         foreach ($settings as $key => $s) {
             if (is_array($s)) {
                 $settings_model->set('wacab', $key, json_encode($s));
             } else {
                 $settings_model->set('wacab', $key, $s);
             }
         }
     } else {
         $this->setError(_wp('No permission to add the server'));
     }
 }
 function execute()
 {
     try {
         $message = array();
         $settings = waRequest::get('setting');
         if ($settings) {
             $model = new waAppSettingsModel();
             $changed = false;
             foreach ((array) $settings as $setting) {
                 if (in_array($setting, array('auth_form_background'))) {
                     if ($value = $model->get('webasyst', $setting)) {
                         waFiles::delete(wa()->getDataPath($value, true, 'webasyst'));
                         $message[] = _w('Image deleted');
                     }
                 } else {
                     $changed = true;
                 }
                 $model->set('webasyst', $setting, false);
             }
             if ($changed) {
                 $message[] = _w('Settings saved');
             }
         }
         $params = array('module' => 'settings', 'msg' => installerMessage::getInstance()->raiseMessage(implode(', ', $message)));
         $this->redirect($params);
     } catch (waException $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $params = array('module' => 'settings', 'msg' => $msg);
         $this->redirect($params);
     }
 }
예제 #7
0
 public function execute()
 {
     ob_start();
     $app = $this->getApp();
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->set($app, 'cron_schedule', time());
     waFiles::create($this->getConfig()->getPath('log') . '/' . $app . '/');
     $log_file = "{$app}/cron.txt";
     $post_model = new blogPostModel();
     $params = array('datetime' => date("Y-m-d H:i:s"), 'status' => blogPostModel::STATUS_SCHEDULED);
     $posts_schedule = $post_model->select("id,blog_id,contact_id,status,datetime")->where('datetime <= s:datetime AND status=s:status', $params)->fetchAll();
     if ($posts_schedule) {
         foreach ($posts_schedule as $post) {
             try {
                 waLog::log("Attempt publishing post with id [{$post['id']}]", $log_file);
                 $data = array("status" => blogPostModel::STATUS_PUBLISHED);
                 waLog::log($post_model->updateItem($post['id'], $data, $post) ? "success" : "fail", $log_file);
             } catch (Exception $ex) {
                 waLog::log($ex->getMessage(), $log_file);
                 waLog::log($ex->getTraceAsString(), $log_file);
             }
         }
     }
     $action = __FUNCTION__;
     /**
      * @event cron_action
      * @param string $action
      * @return void
      */
     wa()->event('cron_action', $action);
     if ($log = ob_get_clean()) {
         waLog::log($log, $log_file);
     }
 }
 public function postPublishAction($params)
 {
     $post_id = (int) $params['id'];
     $blog_id = (int) $params['blog_id'];
     // check rights for this blog at first and unsubscribe user if he hasn't
     $sql = "SELECT c.id FROM blog_emailsubscription s\n        JOIN wa_contact c ON s.contact_id = c.id\n        WHERE s.blog_id = " . $blog_id;
     $model = new waModel();
     $unsubscribe_contact_ids = array();
     foreach ($model->query($sql) as $row) {
         $rights = 1;
         try {
             $rights = blogHelper::checkRights($blog_id, $row['id'], blogRightConfig::RIGHT_READ);
         } catch (Exception $e) {
             $rights = 0;
         }
         if (!$rights) {
             $unsubscribe_contact_ids[] = $row['id'];
         }
     }
     if ($unsubscribe_contact_ids) {
         $em = new blogEmailsubscriptionModel();
         $em->deleteByField(array('contact_id' => $unsubscribe_contact_ids, 'blog_id' => $blog_id));
     }
     // add subscribers to queue
     $sql = "REPLACE INTO blog_emailsubscription_log (post_id, contact_id, name, email, datetime)\n                SELECT " . $post_id . ", c.id, c.name, e.email, '" . date('Y-m-d H:i:s') . "' FROM blog_emailsubscription s\n                JOIN wa_contact c ON s.contact_id = c.id\n                JOIN wa_contact_emails e ON c.id = e.contact_id AND e.sort = 0\n                WHERE s.blog_id = " . $blog_id;
     $model->exec($sql);
     // save backend url for cron
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->set(array($this->app_id, $this->id), 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
 }
 public function execute()
 {
     $type = waRequest::request('type');
     if (!$type) {
         return;
     }
     $asm = new waAppSettingsModel();
     $asm->set('shop', 'discount_' . $type, waRequest::request('enable') ? 1 : null);
 }
예제 #10
0
 public static function saveDomainsSettings($domains_settings)
 {
     $app_settings_model = new waAppSettingsModel();
     $routing = wa()->getRouting();
     $domains_routes = $routing->getByApp('shop');
     $app_settings_model->set(shopPricePlugin::$plugin_id, 'domains_settings', json_encode($domains_settings));
     $cache = new waSerializeCache('shopPricePlugin');
     if ($cache && $cache->isCached()) {
         $cache->delete();
     }
 }
 public function postPublishAction($params)
 {
     $post_id = (int) $params['id'];
     $blog_id = (int) $params['blog_id'];
     // add subscribers to queue
     $sql = "REPLACE INTO blog_emailsubscription_log (post_id, contact_id, name, email, datetime)\n                SELECT " . $post_id . ", c.id, c.name, e.email, '" . date('Y-m-d H:i:s') . "' FROM blog_emailsubscription s\n                JOIN wa_contact c ON s.contact_id = c.id\n                JOIN wa_contact_emails e ON c.id = e.contact_id AND e.sort = 0\n                WHERE s.blog_id = " . $blog_id;
     $model = new waModel();
     $model->exec($sql);
     // save backend url for cron
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->set(array($this->app_id, $this->id), 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
 }
 public function execute()
 {
     $asm = new waAppSettingsModel();
     if (waRequest::post()) {
         $conf = waRequest::post('conf');
         if ($conf && is_array($conf)) {
             $conf['affiliate_credit_rate'] = str_replace(',', '.', (double) str_replace(',', '.', ifset($conf['affiliate_credit_rate'], '0')));
             $conf['affiliate_usage_rate'] = str_replace(',', '.', (double) str_replace(',', '.', ifset($conf['affiliate_usage_rate'], '0')));
             foreach ($conf as $k => $v) {
                 $asm->set('shop', $k, $v);
             }
         }
     }
     $enabled = shopAffiliate::isEnabled();
     $def_cur = waCurrency::getInfo(wa()->getConfig()->getCurrency());
     $tm = new shopTypeModel();
     $product_types = $tm->getAll();
     $conf = $asm->get('shop');
     if (!empty($conf['affiliate_product_types'])) {
         $conf['affiliate_product_types'] = array_fill_keys(explode(',', $conf['affiliate_product_types']), true);
     } else {
         $conf['affiliate_product_types'] = array();
     }
     $this->view->assign('conf', $conf);
     $this->view->assign('enabled', $enabled);
     $this->view->assign('product_types', $product_types);
     $this->view->assign('def_cur_sym', ifset($def_cur['sign'], wa()->getConfig()->getCurrency()));
     /**
      * Backend affiliate settings
      *
      * Plugins are expected to return one item or a list of items to to add to affiliate menu.
      * Each item is represented by an array:
      * array(
      *   'id'   => string,  // Required.
      *   'name' => string,  // Required.
      *   'url'  => string,  // Required (unless you hack into JS using 'html' parameter). Content for settings page is fetched from this URL.
      * )
      *
      * @event backend_settings_discounts
      */
     $plugins = wa()->event('backend_settings_affiliate');
     $config = wa('shop')->getConfig();
     foreach ($plugins as $k => &$p) {
         if (substr($k, -7) == '-plugin') {
             $plugin_id = substr($k, 0, -7);
             $plugin_info = $config->getPluginInfo($plugin_id);
             $p['img'] = $plugin_info['img'];
         }
     }
     $this->view->assign('plugins', $plugins);
     $this->view->assign('installer', $this->getUser()->getRights('installer', 'backend'));
 }
 public function execute()
 {
     $plugin_id = array('shop', 'deliveryshop');
     try {
         $app_settings_model = new waAppSettingsModel();
         $settings = waRequest::post('settings');
         $app_settings_model->set($plugin_id, 'status', (int) $settings['status']);
         $model = new waModel();
         $domains = $model->query("SELECT * FROM site_domain")->fetchAll();
         $reset_tpls = waRequest::post('reset_tpls');
         $template = waRequest::post('template');
         $prices = waRequest::post('prices');
         $this->response['pri'] = $prices;
         foreach ($domains as $d) {
             $id_price = $model->query("SELECT id FROM shop_deliveryshop_delivery WHERE domain = '" . $d['name'] . "'")->fetchField();
             if ($id_price) {
                 $model->query("UPDATE shop_deliveryshop_delivery SET price = '" . $prices[$d['name']]['price'] . "' WHERE domain = '" . $d['name'] . "'");
             } else {
                 $model->query("INSERT INTO shop_deliveryshop_delivery (domain, price)\n                                   VALUES ('" . $d['name'] . "', '" . $prices[$d['name']]['price'] . "')");
             }
             if (isset($reset_tpls[$d['name']])) {
                 $template_path = wa()->getDataPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka' . $d['id'] . '.html', false, 'shop', true);
                 @unlink($template_path);
             } else {
                 if (!isset($template[$d['name']])) {
                     throw new waException('Не определён шаблон');
                 }
                 $template_path = wa()->getDataPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka' . $d['id'] . '.html', false, 'shop', true);
                 if (!file_exists($template_path)) {
                     $template_path = wa()->getAppPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka.html', 'shop');
                 }
                 $template_content = file_get_contents($template_path);
                 if ($template_content != $template[$d['name']]) {
                     $template_path = wa()->getDataPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka' . $d['id'] . '.html', false, 'shop', true);
                     $f = fopen($template_path, 'w');
                     if (!$f) {
                         throw new waException('Не удаётся сохранить шаблон. Проверьте права на запись ' . $template_path);
                     }
                     fwrite($f, $template[$d['name']]);
                     fclose($f);
                 }
             }
             $this->response['template'] = $template;
         }
         $this->response['message'] = "Сохранено";
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
 public function run($params = NULL)
 {
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->set(array('blog', 'emailsubscription'), 'last_emailsubscription_cron_time', time());
     $model = new blogEmailsubscriptionLogModel();
     $row = $model->getByField('status', 0);
     if ($row) {
         $post_id = $row['post_id'];
         $post_model = new blogPostModel();
         $post = $post_model->getById($post_id);
         $blog_model = new blogBlogModel();
         $blog = $blog_model->getById($post['blog_id']);
         $subject = $blog['name'] . ': ' . $post['title'];
         $post_title = htmlspecialchars($post['title']);
         if ($blog['status'] == blogBlogModel::STATUS_PUBLIC) {
             $post_url = blogPost::getUrl($post);
         } else {
             $app_settings_model = new waAppSettingsModel();
             $post_url = $app_settings_model->get(array('blog', 'emailsubscription'), 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
             $post_url .= "/blog/?module=post&id=" . $post_id;
         }
         $blog_name = htmlspecialchars($blog['name']);
         $body = '<html><body>' . sprintf(_wp("New post in the blog “%s”"), $blog_name) . ': <strong><a href="' . $post_url . '">' . $post_title . '</a></strong></body></html>';
         $message = new waMailMessage();
         $message->setEncoder(Swift_Encoding::getBase64Encoding());
         $message->setSubject($subject);
         $message->setBody($body);
         $rows = $model->getByField(array('status' => 0, 'post_id' => $post_id), true);
         $message_count = 0;
         foreach ($rows as $row) {
             try {
                 $message->setTo($row['email'], $row['name']);
                 $status = $message->send() ? 1 : -1;
                 $model->setStatus($row['id'], $status);
                 if ($status) {
                     $message_count++;
                 }
             } catch (Exception $e) {
                 $model->setStatus($row['id'], -1, $e->getMessage());
             }
         }
         /**
          * Notify plugins about sending emailsubscripition
          * @event followup_send
          * @return void
          */
         wa()->event('emailsubscription_send', $message_count);
     }
 }
 public function execute()
 {
     try {
         $app_settings_model = new waAppSettingsModel();
         $shop_price = waRequest::post('shop_price');
         $domains_settings = waRequest::post('domains_settings', array());
         foreach ($shop_price as $key => $value) {
             $app_settings_model->set(shopPricePlugin::$plugin_id, $key, $value);
         }
         shopPrice::saveDomainsSettings($domains_settings);
         $this->response['message'] = "Сохранено";
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
예제 #16
0
 public function execute()
 {
     if (waRequest::post()) {
         $app_settings = new waAppSettingsModel();
         foreach ($this->getData() as $name => $value) {
             $app_settings->set('shop', $name, $value);
         }
         $sms = waRequest::post('sms', array());
         $path = $this->getConfig()->getPath('config', 'sms');
         $save = array();
         foreach ($sms as $s) {
             $from = $s['from'];
             $adapter = $s['adapter'];
             unset($s['from']);
             unset($s['adapter']);
             $empty = true;
             foreach ($s as $v) {
                 if ($v) {
                     $empty = false;
                     break;
                 }
             }
             if (!$empty) {
                 if (!$from) {
                     $from = '*';
                 }
                 foreach (explode("\n", $from) as $from) {
                     $from = trim($from);
                     $save[$from] = $s;
                     $save[$from]['adapter'] = $adapter;
                 }
             }
         }
         waUtils::varExportToFile($save, $path);
     }
     $cm = new waCountryModel();
     $this->view->assign('countries', $cm->all());
     $this->view->assign($this->getConfig()->getGeneralSettings());
     $workhours = wa()->getSetting('workhours', null);
     if ($workhours) {
         $workhours = json_decode($workhours, true);
     }
     $this->view->assign('workhours', $workhours);
     $sms_adapters = $this->getSMSAdapters();
     $this->view->assign('sms_adapters', $sms_adapters);
     $this->view->assign('saved', waRequest::post());
 }
예제 #17
0
 public function execute()
 {
     $settings_model = new waAppSettingsModel();
     $settings = $settings_model->get('wacab');
     if (isset($settings['count'])) {
         $settings_model->set('wacab', 'new_count', 0);
     }
     $apps_count = wa()->getStorage()->read('apps-count');
     unset($apps_count['wacab']);
     wa()->getStorage()->set('apps-count', $apps_count);
     //        $new = new wacabGetpayment();
     //        $ps = $new->getPayment();
     $model = new wacabPaymentModel();
     $pays = $model->query('SELECT * FROM wacab_payment ORDER BY date DESC')->fetchAll();
     $this->view->assign('pays', $pays);
     $this->setTemplate(wacabHelper::getAppPath() . '/templates/actions/transactions/Transactions_page.html');
 }
 public function run()
 {
     $app_settings_model = new waAppSettingsModel();
     $contact_settings_model = new waContactSettingsModel();
     $app_settings_model->set('blog', 'last_reminder_cron_time', time());
     // remider settings for all users
     $reminders = $contact_settings_model->select('contact_id, value')->where("app_id='blog' AND name='reminder'")->fetchAll('contact_id', true);
     if (!$reminders) {
         return;
     }
     $time = time();
     // do job no more one time in 24 hours
     $last_cron_times = $contact_settings_model->select('contact_id')->where("app_id='blog' AND name='last_reminder_cron_time' AND value <= " . ($time - 86400))->fetchAll('contact_id', true);
     $reminders_allowed = array_keys($last_cron_times);
     if (!$reminders_allowed) {
         return;
     }
     $post_model = new blogPostModel();
     $backend_url = $app_settings_model->get('blog', 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
     $message_count = 0;
     foreach ($reminders_allowed as $contact_id) {
         $days = $reminders[$contact_id];
         // get all deadline posts for this contact
         $posts = $post_model->select("id, title, datetime")->where("status='" . blogPostModel::STATUS_DEADLINE . "' AND contact_id=" . $contact_id . " AND datetime < '" . date('Y-m-d H:i:s', $time + $days * 86400) . "'")->order('datetime')->fetchAll();
         if ($posts) {
             $contact = new waContact($contact_id);
             $email = $contact->get('email', 'default');
             $message = new waMailMessage(_w('Scheduled blog posts'), $this->getMessage($posts, $time, $backend_url));
             try {
                 $message->setTo($email);
                 if ($message->send()) {
                     $message_count++;
                 }
             } catch (Exception $e) {
             }
         }
         $contact_settings_model->set($contact_id, 'blog', 'last_reminder_cron_time', $time);
     }
     /**
      * Notify plugins about sending reminder
      * @event followup_send
      * @return void
      */
     wa()->event('reminder_send', $message_count);
 }
 public function execute()
 {
     try {
         $app_settings_model = new waAppSettingsModel();
         $settings = waRequest::post('shop_onestep', array());
         $domains_settings = waRequest::post('domains_settings', array());
         $reset = waRequest::post('reset');
         foreach ($settings as $name => $value) {
             $app_settings_model->set(shopOnestepPlugin::$plugin_id, $name, $value);
         }
         if ($reset) {
             $domains_settings = array();
         }
         shopOnestep::saveDomainsSettings($domains_settings);
         $this->response['message'] = "Сохранено";
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
 public function execute()
 {
     try {
         $app_settings_model = new waAppSettingsModel();
         $shop_discountcards = waRequest::post('shop_discountcards');
         foreach ($shop_discountcards as $name => $value) {
             if (is_array($value)) {
                 $value = json_encode($value);
             }
             $app_settings_model->set(shopDiscountcardsPlugin::$plugin_id, $name, $value);
         }
         $templates = waRequest::post('templates');
         foreach ($templates as $template_id => $template) {
             $s_template = $this->templates[$template_id];
             $tpl_full_path = $s_template['tpl_path'] . $s_template['tpl_name'] . '.' . $s_template['tpl_ext'];
             $template_path = wa()->getDataPath($tpl_full_path, $s_template['public'], 'shop', true);
             if (!file_exists($template_path)) {
                 $template_path = wa()->getAppPath($tpl_full_path, 'shop');
             }
             $content = file_get_contents($template_path);
             if (!empty($template['reset_tpl'])) {
                 @unlink($template_path);
             } elseif (!empty($template['template']) && $template['template'] != $content) {
                 $template_path = wa()->getDataPath($tpl_full_path, $s_template['public'], 'shop', true);
                 $f = fopen($template_path, 'w');
                 if (!$f) {
                     throw new waException('Не удаётся сохранить шаблон. Проверьте права на запись ' . $template_path);
                 }
                 fwrite($f, $template['template']);
                 fclose($f);
             }
         }
         $this->response['message'] = "Сохранено";
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
 public function execute()
 {
     try {
         $app_settings_model = new waAppSettingsModel();
         $shop_smartsearch = waRequest::post('shop_smartsearch');
         foreach ($shop_smartsearch as $name => $value) {
             $app_settings_model->set($this->plugin_id, $name, $value);
         }
         if (waRequest::post('reset_tpl')) {
             $template_path = wa()->getDataPath($this->tmp_path, false, 'shop', true);
             @unlink($template_path);
         } else {
             $post_template = waRequest::post('template');
             if (!$post_template) {
                 throw new waException('Не определён шаблон');
             }
             $template_path = wa()->getDataPath($this->tmp_path, false, 'shop', true);
             if (!file_exists($template_path)) {
                 $template_path = wa()->getAppPath($this->tmp_path, 'shop');
             }
             $template = file_get_contents($template_path);
             if ($template != $post_template) {
                 $template_path = wa()->getDataPath($this->tmp_path, false, 'shop', true);
                 $f = fopen($template_path, 'w');
                 if (!$f) {
                     throw new waException('Не удаётся сохранить шаблон. Проверьте права на запись ' . $template_path);
                 }
                 fwrite($f, $post_template);
                 fclose($f);
             }
         }
         $this->response['message'] = "Сохранено";
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
예제 #22
0
 public function run($params = NULL)
 {
     $app = $this->getApp();
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->set($app, 'last_schedule_cron_time', time());
     waFiles::create($this->getConfig()->getPath('log') . '/' . $app . '/');
     $log_file = "{$app}/schedule.txt";
     $post_model = new blogPostModel();
     $params = array('datetime' => date("Y-m-d H:i:s"), 'status' => blogPostModel::STATUS_SCHEDULED);
     $posts_schedule = $post_model->select("id, blog_id, contact_id, status, datetime")->where('datetime <= s:datetime AND status=s:status', $params)->fetchAll();
     if ($posts_schedule) {
         foreach ($posts_schedule as $post) {
             try {
                 waLog::log("Attempt publishing post with id [{$post['id']}]", $log_file);
                 $data = array("status" => blogPostModel::STATUS_PUBLISHED, "datetime" => date("Y-m-d H:i:s"));
                 $r = $post_model->updateItem($post['id'], $data, $post);
                 waLog::log($r ? "success" : "fail", $log_file);
             } catch (Exception $ex) {
                 waLog::log($ex->getMessage(), $log_file);
                 waLog::log($ex->getTraceAsString(), $log_file);
             }
         }
     }
 }
예제 #23
0
<?php

$model = new waAppSettingsModel();
if (!$model->get('webasyst', 'sender')) {
    $email = $model->get('webasyst', 'email');
    if ($email) {
        $model->set('webasyst', 'sender', $email);
    }
}
 public function checkUpdates()
 {
     try {
         $app_settings_model = new waAppSettingsModel();
         $time = $app_settings_model->get($this->application, 'update_time');
     } catch (waDbException $e) {
         // Can't connect to MySQL server
         if ($e->getCode() == 2002) {
             throw $e;
         } elseif (!empty($app_settings_model)) {
             $time = null;
             $row = $app_settings_model->getByField(array('app_id' => $this->application, 'name' => 'update_time'));
             if ($row) {
                 $time = $row['value'];
             }
         } elseif ($this->application != 'webasyst' && $this->environment == 'frontend') {
             wa('webasyst');
         }
     } catch (waException $e) {
         return;
     }
     if (empty($time)) {
         try {
             $this->install();
         } catch (waException $e) {
             waLog::log($e->__toString());
             throw $e;
         }
         $ignore_all = true;
         $time = null;
     } else {
         $ignore_all = false;
     }
     if (!self::isDebug()) {
         $cache = new waVarExportCache('updates', 0, $this->application);
         if ($cache->isCached() && $cache->get() <= $time) {
             return;
         }
     }
     $path = $this->getAppPath() . '/lib/updates';
     $cache_database_dir = $this->getPath('cache') . '/db';
     if (file_exists($path)) {
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
         $files = array();
         foreach ($iterator as $file) {
             /**
              * @var SplFileInfo $file
              */
             if ($file->isFile() && preg_match('/^[0-9]+\\.php$/', $file->getFilename())) {
                 $t = substr($file->getFilename(), 0, -4);
                 if ($t > $time) {
                     $files[$t] = $file->getPathname();
                 }
             }
         }
         ksort($files);
         if (!self::isDebug()) {
             // get last time
             if ($files) {
                 $keys = array_keys($files);
                 $cache->set(end($keys));
             } else {
                 $cache->set($time ? $time : 1);
             }
         }
         foreach ($files as $t => $file) {
             try {
                 if (!$ignore_all) {
                     $this->includeUpdate($file);
                     waFiles::delete($cache_database_dir);
                     $app_settings_model->set($this->application, 'update_time', $t);
                 }
             } catch (Exception $e) {
                 if (waSystemConfig::isDebug()) {
                     echo $e;
                 }
                 // log errors
                 waLog::log($e->__toString());
                 break;
             }
         }
     } else {
         $t = 1;
     }
     if ($ignore_all) {
         if (!isset($t) || !$t) {
             $t = 1;
         }
         if (!isset($app_settings_model)) {
             $app_settings_model = new waAppSettingsModel();
         }
         $app_settings_model->set($this->application, 'update_time', $t);
     }
     if (isset($this->info['edition']) && $this->info['edition']) {
         if (!isset($app_settings_model)) {
             $app_settings_model = new waAppSettingsModel();
         }
         if (!$app_settings_model->get($this->application, 'edition')) {
             $app_settings_model->set($this->application, 'edition', $this->info['edition']);
         }
     }
 }
 private function initImport()
 {
     $name = basename(waRequest::post('file'));
     if (empty($name)) {
         throw new waException('Empty import filename');
     }
     $config = wa('shop')->getConfig();
     /**
      * @var shopConfig $config ;
      */
     //TODO detect emulate & type of control
     $file = wa()->getTempPath('csv/upload/' . $name);
     $this->data['emulate'] = waRequest::post('emulate') ? array() : null;
     $this->data['rights'] = $this->getUser()->getRights('shop', 'settings');
     $this->data['new_features'] = array();
     $this->data['currencies'] = $config->getCurrencies();
     $this->data['type_id'] = waRequest::post('type_id', null, waRequest::TYPE_INT);
     if ($this->data['type_id'] && !in_array($this->data['type_id'], $this->data['types'])) {
         $this->data['type_id'] = reset($this->data['types']);
     }
     $map = waRequest::post('csv_map');
     if ($this->emulate()) {
         $this->reader = shopCsvReader::snapshot($file);
         if (!$this->reader) {
             throw new waException('CSV file not found');
         }
         $this->reader->rewind();
     } else {
         /*, waRequest::post('encoding', 'utf-8')*/
         //after upload encoding converted into utf-8
         $this->reader = new shopCsvReader($file, waRequest::post('delimiter', ';'));
         $header = $this->reader->header();
         foreach ($map as $id => &$target) {
             if (preg_match('@^f\\+:(.+)$@', $target, $matches)) {
                 if ($this->data['rights']) {
                     $id = preg_replace('@\\D.*$@', '', $id);
                     $feature = array('name' => ifset($header[$id], 'csv feature'), 'type' => shopFeatureModel::TYPE_VARCHAR, 'multiple' => 0, 'selectable' => 0);
                     list($feature['type'], $feature['multiple'], $feature['selectable']) = explode(':', $matches[1]);
                     $feature['type'] = preg_replace('@([^\\.]+\\.)\\1@', '$1', $feature['type']);
                     if (empty($feature_model)) {
                         $feature_model = new shopFeatureModel();
                     }
                     if (empty($type_features_model)) {
                         $type_features_model = new shopTypeFeaturesModel();
                     }
                     $feature['id'] = $feature_model->save($feature);
                     if ($this->data['type_id']) {
                         $type_features_model->updateByFeature($feature['id'], array($this->data['type_id']), false);
                     }
                     $target = 'features:' . $feature['code'];
                     $this->data['new_features'][$feature['code']] = array('id' => $feature['id'], 'types' => (array) $this->data['type_id']);
                 } else {
                     unset($map[$id]);
                 }
             }
         }
         unset($target);
     }
     $map = array_flip($map);
     $this->reader->setMap($map);
     $this->data['file'] = serialize($this->reader);
     $this->data['primary'] = waRequest::post('primary', 'name');
     $this->data['secondary'] = waRequest::post('secondary', 'skus:-1:sku');
     $this->data['extra_secondary'] = false;
     switch ($this->data['secondary']) {
         case 'skus:-1:sku':
             if (isset($map['skus:-1:name']) && intval($map['skus:-1:name']) >= 0) {
                 $this->data['extra_secondary'] = 'skus:-1:name';
             }
             break;
         case 'skus:-1:name':
             if (isset($map['skus:-1:sku']) && intval($map['skus:-1:sku']) >= 0) {
                 $this->data['extra_secondary'] = 'skus:-1:sku';
             }
             break;
     }
     $upload_app = waRequest::post('upload_app', 'shop', waRequest::TYPE_STRING_TRIM);
     if ($upload_app != 'site') {
         $upload_app = 'shop';
     }
     $this->data['upload_path'] = preg_replace('@[\\\\/]+$@', '/', waRequest::post('upload_path', 'upload/images/') . '/');
     $this->data['upload_path'] = preg_replace('@(^|/)(\\.\\.)/@', '$1/', $this->data['upload_path']);
     if (waSystem::getSetting('csv.upload_path') != $this->data['upload_path']) {
         $app_settings = new waAppSettingsModel();
         $app_settings->set('shop', 'csv.upload_path', $this->data['upload_path']);
     }
     $this->data['virtual_sku_stock'] = waRequest::post('virtual_sku_stock', '', waRequest::TYPE_STRING_TRIM);
     if ($upload_app == 'site') {
         $this->data['upload_path'] = wa()->getDataPath($this->data['upload_path'], true, 'site');
     } else {
         $this->data['upload_path'] = wa()->getDataPath($this->data['upload_path'], false, 'shop');
     }
     if (waSystem::getSetting('csv.upload_app') != $upload_app) {
         if (empty($app_settings)) {
             $app_settings = new waAppSettingsModel();
         }
         $app_settings->set('shop', 'csv.upload_app', $upload_app);
     }
     $this->data['ignore_category'] = !!waRequest::post('ignore_category', 0, waRequest::TYPE_INT);
     if (!in_array($this->data['primary'], array('name', 'url', 'null'))) {
         throw new waException(_w('Invalid primary field'));
     }
     if ($this->data['primary'] == 'null') {
         $this->data['primary'] = null;
     }
     if (!in_array($this->data['secondary'], array('skus:-1:sku', 'skus:-1:name'))) {
         throw new waException(_w('Invalid secondary field'));
     }
     $current = $this->reader->current();
     if (!empty($this->data['primary']) && self::getData($current, $this->data['primary']) === null) {
         throw new waException(_w('Empty primary CSV column'));
     }
     if (empty($this->data['primary']) && self::getData($current, $this->data['secondary']) === null) {
         throw new waException(_w('Empty secondary CSV column'));
     }
     $this->data['count'] = array(self::STAGE_FILE => $this->reader ? $this->reader->size() : null, self::STAGE_CATEGORY => null, self::STAGE_PRODUCT => null, self::STAGE_SKU => null, self::STAGE_IMAGE => null);
 }
 public static function getPreviewHash($options, $regen_if_expired = true)
 {
     $app = wa()->getApp();
     $app_settings_model = new waAppSettingsModel();
     // preview_hash is the salt that takes into account live-time
     $hash = $app_settings_model->get($app, 'preview_hash');
     if ($hash) {
         $hash_parts = explode('.', $hash);
         if ($regen_if_expired && time() - $hash_parts[1] > 14400) {
             $hash = '';
         }
     }
     if (!$hash) {
         $hash = uniqid() . '.' . time();
         $app_settings_model->set($app, 'preview_hash', $hash);
     }
     $options += array('contact_id' => '', 'blog_id' => '', 'post_id' => '', 'user_id' => '');
     $hash = md5($hash . $options['contact_id'] . $options['blog_id'] . $options['post_id'] . $options['user_id']);
     return $hash;
 }
예제 #27
0
 private function _save($type = 'frontend', $settings)
 {
     $app = $this->getApp();
     if ($type == 'frontend') {
         $settings_model = new waAppSettingsModel();
         foreach ($settings as $name => $value) {
             $settings_model->set($app, $name, $value);
         }
     } elseif ($type == 'user') {
         $user = waSystem::getInstance()->getUser();
         foreach ($settings as $name => $value) {
             if ($value !== null) {
                 $user->setSettings($app, $name, $value);
             } else {
                 $user->delSettings($app, $name);
             }
             if ($name === 'reminder') {
                 if ($value !== null) {
                     $user->setSettings($app, 'last_reminder_cron_time', 0);
                     /**
                      * Notify plugins about saving reminder settings
                      * @event reminder_save
                      * @return void
                      */
                     wa()->event('reminder_save');
                 } else {
                     $user->delSettings($app, 'last_reminder_cron_time');
                 }
             }
         }
     }
     // save backend url for cron
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->set('blog', 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
 }
예제 #28
0
 protected function getThemeHash()
 {
     $hash = $this->appSettings('theme_hash');
     if ($hash) {
         $hash_parts = explode('.', $hash);
         if (time() - $hash_parts[1] > 14400) {
             $hash = '';
         }
     }
     if (!$hash) {
         $hash = uniqid() . '.' . time();
         $app_settings_model = new waAppSettingsModel();
         $app_settings_model->set($this->getAppId(), 'theme_hash', $hash);
     }
     return md5($hash);
 }
예제 #29
0
<?php

$plugin_id = array('shop', 'onestep');
$app_settings_model = new waAppSettingsModel();
$app_settings_model->set($plugin_id, 'status', '1');
예제 #30
0
 protected function checkUpdates()
 {
     try {
         $app_settings_model = new waAppSettingsModel();
         $time = $app_settings_model->get($this->application, 'update_time');
     } catch (waDbException $e) {
         if ($e->getCode() == 2002 && !waSystemConfig::isDebug()) {
             return;
         } else {
             // table doesn't exist
             $time = null;
         }
     } catch (waException $e) {
         return;
     }
     if (!$time) {
         try {
             $this->install();
         } catch (waException $e) {
             waLog::log($e->__toString());
             throw $e;
         }
         $ignore_all = true;
     } else {
         $ignore_all = false;
     }
     if (!self::isDebug()) {
         $cache = new waVarExportCache('updates', 0, $this->application);
         if ($cache->isCached() && $cache->get() <= $time) {
             return;
         }
     }
     $path = $this->getAppPath() . '/lib/updates';
     $cache_database_dir = $this->getPath('cache') . '/db';
     if (file_exists($path)) {
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
         $files = array();
         foreach ($iterator as $file) {
             /**
              * @var SplFileInfo $file
              */
             if ($file->isFile() && preg_match('/^[0-9]+\\.php$/', $file->getFilename())) {
                 $t = substr($file->getFilename(), 0, -4);
                 if ($t > $time) {
                     $files[$t] = $file->getPathname();
                 }
             }
         }
         ksort($files);
         if (!self::isDebug()) {
             // get last time
             if ($files) {
                 $keys = array_keys($files);
                 $cache->set(end($keys));
             } else {
                 $cache->set($time ? $time : 1);
             }
         }
         foreach ($files as $t => $file) {
             try {
                 if (!$ignore_all) {
                     include $file;
                     waFiles::delete($cache_database_dir);
                     $app_settings_model->set($this->application, 'update_time', $t);
                 }
             } catch (Exception $e) {
                 if (waSystemConfig::isDebug()) {
                     echo $e;
                 }
                 // log errors
                 waLog::log($e->__toString());
                 break;
             }
         }
     } else {
         $t = 1;
     }
     if ($ignore_all) {
         if (!isset($t) || !$t) {
             $t = 1;
         }
         if (!isset($app_settings_model)) {
             $app_settings_model = new waAppSettingsModel();
         }
         $app_settings_model->set($this->application, 'update_time', $t);
     }
     if (isset($this->info['edition']) && $this->info['edition']) {
         if (!isset($app_settings_model)) {
             $app_settings_model = new waAppSettingsModel();
         }
         if (!$app_settings_model->get($this->application, 'edition')) {
             $file_sql = $this->getAppPath('lib/config/app.' . $this->info['edition'] . '.sql');
             if (file_exists($file_sql)) {
                 self::executeSQL($file_sql, 1);
             }
             $app_settings_model->set($this->application, 'edition', $this->info['edition']);
         }
     }
 }