Exemplo n.º 1
0
 protected function prepare()
 {
     $this->assign('wa_url', $this->system->getRootUrl());
     $this->assign('wa_backend_url', waSystem::getInstance()->getConfig()->getBackendUrl(true));
     $this->assign('wa_app', $this->system->getApp());
     $this->assign('wa_app_url', $this->system->getAppUrl(null, true));
     $this->assign('wa_app_static_url', $this->system->getAppStaticUrl());
     if (!$this->helper) {
         $this->helper = new waViewHelper($this);
     }
     $this->assign('wa', $this->helper);
 }
 public function execute()
 {
     if (!$this->getUser()->getRights('shop', 'settings')) {
         throw new waException(_w('Access denied'));
     }
     $plugin_id = waRequest::get('id', null);
     $plugins_count = 0;
     if ($plugin_id) {
         $plugins = $this->getConfig()->getPlugins();
         $plugins_count = count($plugins);
         if (isset($plugins[$plugin_id])) {
             /**
              * @var shopPlugin $plugin
              */
             $plugin = waSystem::getInstance()->getPlugin($plugin_id, true);
             $namespace = 'shop_' . $plugin_id;
             $params = array();
             $params['id'] = $plugin_id;
             $params['namespace'] = $namespace;
             $params['title_wrapper'] = '%s';
             $params['description_wrapper'] = '<br><span class="hint">%s</span>';
             $params['control_wrapper'] = '<div class="name">%s</div><div class="value">%s %s</div>';
             $settings_controls = $plugin->getControls($params);
             $this->getResponse()->setTitle(_w(sprintf('Plugin %s settings', $plugin->getName())));
             $this->view->assign('plugin_info', $plugins[$plugin_id]);
             $this->view->assign('plugin_id', $plugin_id);
             $this->view->assign('settings_controls', $settings_controls);
         }
         waSystem::popActivePlugin();
     }
     $this->view->assign('plugins_count', $plugins_count);
 }
Exemplo n.º 3
0
    public function authAdapters($return_array = false)
    {
        $adapters = $this->wa->getAuthAdapters();
        if ($return_array) {
            return $adapters;
        }
        if (!$adapters) {
            return '';
        }
        $html = '<div class="wa-auth-adapters"><ul>';
        $url = $this->wa->getRootUrl(false, true) . 'oauth.php?app=' . $this->app() . '&provider=';
        foreach ($adapters as $adapter) {
            /**
             * @var waAuthAdapter $adapter
             */
            $html .= '<li><a href="' . $url . $adapter->getId() . '"><img alt="' . $adapter->getName() . '" src="' . $adapter->getIcon() . '">' . $adapter->getName() . '</a></li>';
        }
        $html .= '</ul><p>';
        $html .= _ws("Authorize either by entering your contact information, or through one of the websites listed above.");
        $html .= '</p></div>';
        $html .= <<<HTML
<script>
\$("div.wa-auth-adapters a").click(function () {
    var left = (screen.width - 600) / 2;
    var top = (screen.height - 400) / 2;
    window.open(\$(this).attr('href'),'oauth', "width=600,height=400,left="+left+",top="+top+",status=no,toolbar=no,menubar=no");
    return false;
});
</script>
HTML;
        return $html;
    }
 public function execute()
 {
     $order_id = waRequest::post('order_id', null, waRequest::TYPE_INT);
     if ($order_id) {
         $order_model = new shopOrderModel();
         $order = $order_model->getOrder($order_id);
         $customer_model = new shopCustomerModel();
         $customer = $customer_model->getById($order['contact_id']);
         $customer_model->updateById($order['contact_id'], array('is_spamer' => 1));
         $plugin = waSystem::getInstance()->getPlugin('orderantispam');
         $action_id = $plugin->getSettings('action_id');
         $workflow = new shopWorkflow();
         $action = $workflow->getActionById($action_id);
         $action->run($order_id);
         // counters
         $state_counters = $order_model->getStateCounters();
         $pending_counters = (!empty($state_counters['new']) ? $state_counters['new'] : 0) + (!empty($state_counters['processing']) ? $state_counters['processing'] : 0) + (!empty($state_counters['paid']) ? $state_counters['paid'] : 0);
         // update app coutner
         wa('shop')->getConfig()->setCount($state_counters['new']);
         $script = "<script>";
         $script .= "\$.order_list.updateCounters(" . json_encode(array('state_counters' => $state_counters, 'common_counters' => array('pending_counters' => $pending_counters))) . ");";
         $script .= "\$.order.reload();</script>";
         $this->response['script'] = $script;
     }
 }
Exemplo n.º 5
0
 public function display(array $data, $template = null, $return = false)
 {
     $view = waSystem::getInstance()->getView();
     if ($template === null) {
         $template = ucfirst($this->action);
     }
     if (strpbrk($template, '/:') === false) {
         $match = array();
         preg_match("/[A-Z][^A-Z]+/", get_class($this), $match);
         $template = $this->getPluginRoot() . 'templates/actions/' . strtolower($match[0]) . "/" . $match[0] . $template . $view->getPostfix();
     }
     // assign vars
     $view->assign($data);
     if ($this->layout && $this->layout instanceof waLayout) {
         // assign result to layout
         $this->layout->setBlock('content', $view->fetch($template));
         $this->layout->display();
     } else {
         // send headers
         $this->getResponse()->sendHeaders();
         // display
         if ($return) {
             return $view->fetch($template);
         } else {
             $view->display($template);
         }
     }
 }
 public function execute()
 {
     if (!$this->getUser()->getRights('shop', 'settings')) {
         throw new waException(_w('Access denied'));
     }
     $plugin_id = waRequest::get('id');
     if (!$plugin_id) {
         throw new waException(_ws("Can't save plugin settings: unknown plugin id"));
     }
     $namespace = 'shop_' . $plugin_id;
     /**
      * @var shopPlugin $plugin
      */
     $plugin = waSystem::getInstance()->getPlugin($plugin_id);
     $settings = (array) $this->getRequest()->post($namespace);
     $files = waRequest::file($namespace);
     $settings_defenitions = $plugin->getSettings();
     foreach ($files as $name => $file) {
         if (isset($settings_defenitions[$name])) {
             $settings[$name] = $file;
         }
     }
     try {
         $this->response = $plugin->saveSettings($settings);
         $this->response['message'] = _w('Saved');
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
Exemplo n.º 7
0
 public function load($locale, $locale_path, $domain, $textdomain = true)
 {
     $file = $locale_path . '/' . $locale . '/LC_MESSAGES/' . $domain . '.po';
     $cache_file = waSystem::getInstance()->getConfig()->getPath('cache') . '/apps/' . $domain . '/locale/' . $locale . '.php';
     if (isset(self::$cache[$locale][$domain])) {
     } elseif (!file_exists($file)) {
         self::$cache[$locale][$domain] = array();
     } elseif (file_exists($cache_file) && filemtime($cache_file) > filemtime($file)) {
         self::$cache[$locale][$domain] = (include $cache_file);
     } else {
         if (file_exists($file)) {
             $gettext = new waGettext($file);
             self::$cache[$locale][$domain] = $gettext->read();
         } else {
             self::$cache[$locale][$domain] = array();
         }
         waFiles::create($cache_file);
         waUtils::varExportToFile(self::$cache[$locale][$domain], $cache_file);
     }
     if (isset(self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']) && self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']) {
         self::$cache[$locale][$domain]['meta']['f'] = create_function('$n', self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']);
     }
     if ($textdomain) {
         self::$domain = $domain;
         self::$locale = $locale;
     }
     if (!self::$locale) {
         self::$locale = $locale;
     }
 }
Exemplo n.º 8
0
 protected function execute($app, $method_name)
 {
     if ($format = waRequest::get('format')) {
         $format = strtoupper($format);
         if (!in_array($format, array('JSON', 'XML'))) {
             $this->response(array('error' => 'invalid_request', 'error_description' => 'Invalid response format: ' . $format));
             return;
         }
         $this->format = $format;
     }
     // check access token and scope
     $token = $this->checkToken();
     // check app access
     if (!waSystem::getInstance()->appExists($app)) {
         throw new waAPIException('invalid_request', 'Application ' . $app . ' not exists');
     }
     // check scope
     $scope = explode(',', $token['scope']);
     if (!in_array($app, $scope)) {
         throw new waAPIException('access_denied', 403);
     }
     // init app
     waSystem::getInstance($app, null, true);
     $class_name = $app . implode('', array_map('ucfirst', explode('.', $method_name))) . "Method";
     if (!class_exists($class_name)) {
         throw new waAPIException('invalid_method', 'Unknown method: ' . $app . '.' . htmlspecialchars($method_name), 404);
     }
     /**
      * Execute method of the API
      * @var waAPIMethod $method
      */
     $method = new $class_name();
     $this->response($method->getResponse());
 }
Exemplo n.º 9
0
 protected function getDomain()
 {
     if (!$this->domain) {
         $this->domain = waSystem::getInstance()->getRouting()->getDomain();
     }
     return $this->domain;
 }
 public function execute()
 {
     $plugin_id = waRequest::get('id');
     if (!$plugin_id) {
         throw new waException(_ws("Can't save plugin settings: unknown plugin id"));
     }
     $namespace = 'photos_' . $plugin_id;
     /**
      * @var photosPlugin $plugin
      */
     $plugin = waSystem::getInstance()->getPlugin($plugin_id);
     $settings = (array) $this->getRequest()->post($namespace);
     $files = waRequest::file($namespace);
     $settings_defenitions = $plugin->getSettings();
     foreach ($files as $name => $file) {
         if (isset($settings_defenitions[$name])) {
             $settings[$name] = $file;
         }
     }
     try {
         $plugin->saveSettings($settings);
     } catch (Exception $e) {
         $this->errors = $e->getMessage();
     }
 }
 public function execute()
 {
     $plugin_id = waRequest::get('id', null);
     $plugins_count = 0;
     if ($plugin_id) {
         $plugins = $this->getConfig()->getPlugins();
         $plugins_count = count($plugins);
         if (isset($plugins[$plugin_id])) {
             /**
              * @var photosPlugin $plugin
              */
             $plugin = waSystem::getInstance()->getPlugin($plugin_id);
             waSystem::pushActivePlugin($plugin_id, 'photos');
             $namespace = 'photos_' . $plugin_id;
             $params = array();
             $params['id'] = $plugin_id;
             $params['namespace'] = $namespace;
             $params['title_wrapper'] = '%s';
             $params['description_wrapper'] = '<br><span class="hint">%s</span>';
             $params['control_wrapper'] = '<div class="name">%s</div><div class="value">%s %s</div>';
             $settings_controls = $plugin->getControls($params);
             $this->getResponse()->setTitle(_w(sprintf('Plugin %s settings', $plugin->getName())));
             $this->view->assign('plugin_info', $plugins[$plugin_id]);
             $this->view->assign('plugin_id', $plugin_id);
             $this->view->assign('settings_controls', $settings_controls);
             waSystem::popActivePlugin();
         }
     }
     $this->view->assign('plugins_count', $plugins_count);
 }
Exemplo n.º 12
0
 public function init($options = null)
 {
     $cookie_defaults = session_get_cookie_params();
     if (!isset($options['session_cookie_path']) && class_exists("waSystem")) {
         $options['session_cookie_path'] = waSystem::getInstance()->getRootUrl();
     }
     $options = array_merge(array('session_id' => null, 'auto_start' => true, 'session_cookie_lifetime' => $cookie_defaults['lifetime'], 'session_cookie_path' => $cookie_defaults['path'], 'session_cookie_domain' => $cookie_defaults['domain'], 'session_cookie_secure' => $cookie_defaults['secure'], 'session_cookie_httponly' => true, 'session_cache_limiter' => 'none'), $options);
     // initialize parent
     parent::init($options);
     if (isset($this->options['session_name'])) {
         session_name($this->options['session_name']);
     }
     if (!(bool) ini_get('session.use_cookies') && ($session_id = $this->options['session_id'])) {
         session_id($session_id);
     }
     $lifetime = $this->options['session_cookie_lifetime'];
     $path = $this->options['session_cookie_path'];
     $domain = $this->options['session_cookie_domain'];
     $secure = $this->options['session_cookie_secure'];
     $http_only = $this->options['session_cookie_httponly'];
     session_set_cookie_params($lifetime, $path, $domain, $secure, $http_only);
     if (null !== $this->options['session_cache_limiter']) {
         session_cache_limiter($this->options['session_cache_limiter']);
     }
     if ($this->options['auto_start']) {
         if (isset($_COOKIE[session_name()])) {
             $this->open();
         }
     }
 }
 public function saveAction()
 {
     $plugin_id = waRequest::get('id');
     if (!$plugin_id) {
         throw new waException(_ws("Can't save plugin settings: unknown plugin id"));
     }
     $namespace = $this->getAppId() . '_' . $plugin_id;
     /**
      * @var shopPlugin $plugin
      */
     $plugin = waSystem::getInstance()->getPlugin($plugin_id);
     $settings = (array) $this->getRequest()->post($namespace);
     $files = waRequest::file($namespace);
     $settings_defenitions = $plugin->getSettings();
     foreach ($files as $name => $file) {
         if (isset($settings_defenitions[$name])) {
             $settings[$name] = $file;
         }
     }
     try {
         $response = $plugin->saveSettings($settings);
         $response['message'] = _w('Saved');
         $this->displayJson($response);
     } catch (Exception $e) {
         $this->setError($e->getMessage());
         $this->displayJson(array(), $e->getMessage());
     }
 }
Exemplo n.º 14
0
 public function execute()
 {
     $cache = null;
     if ($cache_time = $this->getConfig()->getOption('cache_time')) {
         //$cache = new waSerializeCache('pages/'.$domain.$url.'page');
     }
     $page = array();
     if ($cache && $cache->isCached()) {
         $page = $cache->get();
     } else {
         $site = new siteFrontend();
         if (waRequest::param('error')) {
             $page = array();
         } else {
             $page = $site->getPage(waRequest::param('url', ''));
         }
         if ($page && $cache) {
             $cache->set($page);
         }
     }
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new siteFrontendLayout());
     }
     try {
         $this->executeAction(new siteFrontendAction($page));
     } catch (Exception $e) {
         if (waSystemConfig::isDebug()) {
             echo $e;
         } else {
             waSystem::setActive('site');
             $this->executeAction(new siteFrontendAction($e));
         }
     }
 }
 protected function removeExtras($app_id, $extras_id, $info)
 {
     try {
         $paths = array();
         $plugin_instance = waSystem::getInstance($app_id)->getPlugin($extras_id);
         if (!$plugin_instance) {
             return false;
         }
         $plugin_instance->uninstall();
         $this->installer->updateAppPluginsConfig($app_id, $extras_id, null);
         //wa-apps/$app_id/plugins/$slug
         $paths[] = wa()->getAppPath("{$this->extras_type}/{$extras_id}", $app_id);
         $paths[] = wa()->getTempPath(null, $app_id);
         //wa-cache/temp/$app_id/
         $paths[] = wa()->getAppCachePath(null, $app_id);
         //wa-cache/apps/$app_id/
         foreach ($paths as $path) {
             waFiles::delete($path, true);
         }
         return true;
     } catch (Exception $ex) {
         //TODO check config
         $this->installer->updateAppPluginsConfig($app_id, $extras_id, true);
         throw $ex;
     }
 }
Exemplo n.º 16
0
 private static function getView()
 {
     if (!isset(self::$view)) {
         self::$view = waSystem::getInstance()->getView();
     }
     return self::$view;
 }
 protected function getItems($app_id, &$link = null)
 {
     $old_app = wa()->getApp();
     if ($old_app != $app_id) {
         waSystem::getInstance($app_id, null, true);
     }
     $class_name = $app_id . 'MyNavAction';
     $result = array();
     if (class_exists($class_name)) {
         /**
          * @var waViewAction $action
          */
         try {
             $action = new $class_name();
             wa()->getView()->assign('my_nav_selected', '');
             $html = $action->display();
             $link = '';
             if (preg_match_all('/<li.*?>(.*?)<\\/li>/uis', $html, $match)) {
                 foreach ($match[1] as $m) {
                     if (!$link && preg_match('/href="(.*?)"/uis', $m, $link_m)) {
                         $link = $link_m[1];
                     }
                     $result[] = trim(strip_tags($m));
                 }
             }
         } catch (Exception $e) {
         }
     }
     if ($old_app != $app_id) {
         wa()->setActive($old_app);
     }
     return $result;
 }
Exemplo n.º 18
0
 /**
  * Initialize $this->view (unless already initialized) and return it.
  * @return waSmarty3View
  */
 protected function getView()
 {
     if (!$this->view) {
         $this->view = waSystem::getInstance()->getView();
         $this->view->assign('action', $this);
     }
     return $this->view;
 }
Exemplo n.º 19
0
 private function __construct()
 {
     $this->storage = waSystem::getInstance()->getStorage();
     $this->messages = $this->storage->read(__CLASS__);
     if (!is_array($this->messages)) {
         $this->messages = array();
     }
 }
Exemplo n.º 20
0
 public function getCount($id)
 {
     $row = $this->getByField(array('album_id' => $id, 'contact_id' => waSystem::getInstance()->getUser()->getId()));
     if ($row) {
         return $row['count'];
     }
     return null;
 }
Exemplo n.º 21
0
 public function execute()
 {
     $route_id = waRequest::get('route');
     $routes = wa()->getRouting()->getRoutes(siteHelper::getDomain());
     if (!isset($routes[$route_id])) {
         throw new waException('Route not found', 404);
     }
     $route = $routes[$route_id];
     $app_id = $routes[$route_id]['app'];
     $path = $this->getConfig()->getAppsPath($app_id, 'lib/config/site.php');
     $app = wa()->getAppInfo($app_id);
     if (file_exists($path)) {
         // load locale of the app
         if ($app_id != 'site') {
             waSystem::getInstance($app_id)->setActive($app_id);
         }
         $app['site'] = (include $path);
         // return old locale of the site
         if ($app_id != 'site') {
             waSystem::setActive('site');
         }
     }
     if (isset($app['site']['params'])) {
         $params = $this->getParams($route_id, $app['site']['params'], $route);
     } else {
         $params = array();
     }
     $themes = siteHelper::getThemes($app_id);
     if (!isset($route['theme']) && $themes) {
         $route['theme'] = 'default';
     }
     if (!isset($route['theme_mobile']) && $themes) {
         $route['theme_mobile'] = $route['theme'];
     }
     if (!isset($route['locale'])) {
         $route['locale'] = '';
     }
     if (!isset($route['_name'])) {
         if ($app_id == 'site') {
             if ($title = siteHelper::getDomain('title')) {
                 $route['_name'] = $title;
             } else {
                 $app_settings_model = new waAppSettingsModel();
                 $route['_name'] = $app_settings_model->get('webasyst', 'name', 'Webasyst');
             }
         } else {
             $route['_name'] = $app['name'];
         }
     }
     $this->view->assign('route_id', $route_id);
     $this->view->assign('route', $route);
     $this->view->assign('params', $params);
     $this->view->assign('app_id', $app_id);
     $this->view->assign('app', $app);
     $this->view->assign('domain_id', siteHelper::getDomainId());
     $this->view->assign('domain', siteHelper::getDomain());
     $this->view->assign('locales', array('' => _w('Auto')) + waLocale::getAll('name'));
 }
Exemplo n.º 22
0
 /**
  * Sets a cookie value.
  *
  * @param   string  $name       Cookie name
  * @param   mixed   $value      Cookie value
  * @param   int     $expire     Expiration time
  * @param   string  $path       Path to URL "subdirectory" within which cookie must be valid
  * @param   string  $domain     Domain name for which cookie must be valid
  * @param   bool    $secure     Flag making cookie value available only if passed over HTTPS
  * @param   bool    $http_only  Flag making cookie value accessible only via HTTP and not accessible to client scripts (JavaScript)
  * @return  waResponse  Instance of waResponse class
  */
 public function setCookie($name, $value, $expire = 0, $path = '', $domain = '', $secure = false, $http_only = false)
 {
     if (!$path) {
         $path = waSystem::getInstance()->getRootUrl();
     }
     setcookie((string) $name, (string) $value, (int) $expire, (string) $path, (string) $domain, (bool) $secure, (bool) $http_only);
     $_COOKIE[$name] = $value;
     return $this;
 }
 function __construct()
 {
     $this->user = $this->getUser();
     $this->app_id = waSystem::getInstance()->getApp();
     if (!$this->user->isAdmin($this->app_id) && !$this->user->getRights($this->app_id)) {
         throw new waException(null, 403);
     }
     parent::__construct();
 }
 public function preExecute()
 {
     parent::preExecute();
     $user = $this->getUser();
     $this->app_id = waSystem::getInstance()->getApp();
     if (!$user->isAdmin($this->app_id) && !$user->getRights($this->app_id)) {
         throw new waException(null, 403);
     }
 }
 public function resetAction()
 {
     $plugin_id = waRequest::post('id');
     $plugin = waSystem::getInstance()->getPlugin($plugin_id);
     if (!$plugin) {
         throw new waException(_w("Unknown plugin"));
     }
     $plugin->resetTemplate();
     $this->response['template'] = $plugin->getTemplate();
 }
 /**
  *
  * @param $sheet_id int
  * @param $sticky_data array
  * @return int sticky ID
  */
 public function create($sheet_id, $sticky_data = array())
 {
     self::availableSheet($sheet_id);
     $default_data = array('sheet_id' => $sheet_id, 'creator_contact_id' => waSystem::getInstance()->getUser()->getId(), 'create_datetime' => waDateTime::date('Y-m-d H:i:s'), 'update_datetime' => waDateTime::date('Y-m-d H:i:s'));
     $sticky_data = array_merge($sticky_data, $default_data);
     $sticky_data['id'] = $this->insert($sticky_data);
     $sheet = new stickiesSheetModel();
     $sheet->refresh($sheet_id, $this->countByField('sheet_id', $sheet_id));
     return $sticky_data;
 }
 public function insert($data, $type = 0)
 {
     if (!isset($data['application_id'])) {
         $data['application_id'] = waSystem::getInstance()->getApp();
     }
     if (!isset($data['create_datetime'])) {
         $data['create_datetime'] = date('Y-m-d H:i:s');
     }
     return parent::insert($data);
 }
 public function execute()
 {
     /**
      * @deprecated
      * For backward compatibility reason
      */
     $this->view->assign('cron_schedule_time', waSystem::getSetting('cron_schedule', 0, 'blog'));
     $this->view->assign('last_emailsubscription_cron_time', waSystem::getSetting('last_emailsubscription_cron_time', 0, array('blog', 'emailsubscription')));
     $this->view->assign('cron_command', 'php ' . wa()->getConfig()->getRootPath() . '/cli.php blog emailsubscription');
 }
Exemplo n.º 29
0
 public function setCookie($name, $value, $expire = null, $path = null, $domain = '', $secure = false, $http_only = false)
 {
     if ($expire !== null) {
         $expire = (int) $expire;
     }
     if ($path === null) {
         $path = waSystem::getInstance()->getRootUrl();
     }
     $this->cookies[$name] = array('name' => $name, 'value' => $value, 'expire' => $expire, 'path' => $path, 'domain' => $domain, 'secure' => $secure ? true : false, 'http_only' => $http_only);
     setcookie($name, $value, $expire, $path, $domain, $secure, $http_only);
 }
 public function __construct($coupon = array())
 {
     waLocale::loadByDomain(array('shop', 'coupon'));
     waSystem::pushActivePlugin('coupon', 'shop');
     $this->data['code'] = ifempty($coupon['code'], '');
     $this->data['expire'] = ifempty($coupon['expire_datetime']);
     $curm = new shopCurrencyModel();
     $currencies = $curm->getAll('code');
     $this->data['discount'] = shopCouponPlugin::formatValue($coupon, $currencies);
     waSystem::popActivePlugin();
 }