public function execute(&$params)
 {
     if (!wa()->getUser()->getRights('shop', 'orders')) {
         return null;
     }
     $contact_id = $params;
     $om = new shopOrderModel();
     $total_orders = $om->countByField('contact_id', $contact_id);
     if (!$total_orders) {
         return null;
     }
     return array('html' => '', 'url' => wa()->getAppUrl('shop') . '?module=customers&action=profileTab&id=' . $contact_id, 'count' => 0, 'title' => _wd('shop', 'Shop') . ($total_orders ? ' (' . $total_orders . ')' : ''));
 }
 private function getOffInfo($id)
 {
     $app_config = wa()->getConfig()->getAppConfig('shop');
     $plugin_config = $app_config->getPluginPath($id) . "/lib/config/plugin.php";
     if (!file_exists($plugin_config)) {
         return;
     }
     $plugin_info = (include $plugin_config);
     foreach (array('name', 'description') as $field) {
         if (!empty($plugin_info[$field])) {
             $plugin_info[$field] = _wd('shop_' . $id, $plugin_info[$field]);
         }
     }
     return $plugin_info;
 }
 /**
  * Don't use this function!
  *
  * @param string $domain
  * @param string $locale
  * @param string $msgid
  * @deprecated
  * @return string translated string $msgid
  */
 public static function translate($domain, $locale, $msgid)
 {
     $old_locale = null;
     // load new locale
     if (self::$locale != $locale) {
         $old_locale = self::$locale;
     }
     self::loadByDomain($domain, $locale);
     $result = _wd($domain, $msgid);
     // load old locale
     if ($old_locale) {
         self::$locale = $old_locale;
         self::loadByDomain($domain, $old_locale);
     }
     return $result;
 }
 /**
  * @param array $params deleted contact_id
  * @return array|void
  */
 public function execute(&$params)
 {
     waLocale::loadByDomain('blog');
     $post_model = new blogPostModel();
     $comment_model = new blogCommentModel();
     $links = array();
     foreach ($params as $contact_id) {
         $links[$contact_id] = array();
         if ($count = $post_model->countByField('contact_id', $contact_id)) {
             $links[$contact_id][] = array('role' => _wd('blog', 'Posts author'), 'links_number' => $count);
         }
         if ($count = $comment_model->countByField('contact_id', $contact_id)) {
             $links[$contact_id][] = array('role' => _wd('blog', 'Comments author'), 'links_number' => $count);
         }
     }
     return $links;
 }
Esempio n. 5
0
 /**
  * @param array $params deleted contact_id
  * @return array|void
  */
 public function execute(&$params)
 {
     waLocale::loadByDomain('shop');
     // TODO: take a look to other models related with contacts
     $links = array();
     $product_reviews_model = new shopProductReviewsModel();
     $order_model = new shopOrderModel();
     foreach ($params as $contact_id) {
         $links[$contact_id] = array();
         if ($count = $product_reviews_model->countByField('contact_id', $contact_id)) {
             $links[$contact_id][] = array('role' => _wd('shop', 'Reviews author'), 'links_number' => $count);
         }
         if ($count = $order_model->countByField('contact_id', $contact_id)) {
             $links[$contact_id][] = array('role' => _wd('shop', 'Order customer'), 'links_number' => $count);
         }
     }
     return $links;
 }
 public function getLogActions($full = false, $ignore_system = false)
 {
     if ($this->log_actions === null) {
         $path = $this->getAppPath() . '/lib/config/logs.php';
         if (file_exists($path)) {
             $this->log_actions = (include $path);
             if ($full) {
                 foreach ($this->log_actions as &$info) {
                     if (!empty($info['name'])) {
                         $info['name'] = _wd($this->getApplication(), $info['name']);
                     }
                 }
                 unset($info);
             }
         } else {
             $this->log_actions = array();
         }
     }
     if (!$ignore_system) {
         $system_actions = $this->getSystemLogActions();
         return array_merge($this->log_actions, $system_actions);
     }
     return $this->log_actions;
 }
 public function getApps($system = false)
 {
     if (self::$apps === null) {
         $locale = $this->getUser()->getLocale();
         $file = $this->config->getPath('cache', 'config/apps' . $locale);
         if (!file_exists($this->getConfig()->getPath('config', 'apps'))) {
             self::$apps = array();
             throw new waException('File wa-config/apps.php not found.', 600);
         }
         if (!file_exists($file) || filemtime($file) < filemtime($this->getConfig()->getPath('config', 'apps')) || waSystemConfig::isDebug()) {
             waFiles::create($this->getConfig()->getPath('cache') . '/config');
             $all_apps = (include $this->getConfig()->getPath('config', 'apps'));
             $all_apps['webasyst'] = true;
             self::$apps = array();
             foreach ($all_apps as $app => $enabled) {
                 if ($enabled) {
                     waLocale::loadByDomain($app, $locale);
                     $app_config = $this->getAppPath('lib/config/app.php', $app);
                     if (!file_exists($app_config)) {
                         if (false && SystemConfig::isDebug()) {
                             throw new waException("Config not found. Create config by path " . $app_config);
                         }
                         continue;
                     }
                     $app_info = (include $app_config);
                     $build_file = $app_config = $this->getAppPath('lib/config/build.php', $app);
                     if (file_exists($build_file)) {
                         $app_info['build'] = (include $build_file);
                     } else {
                         if (SystemConfig::isDebug()) {
                             $app_info['build'] = time();
                         } else {
                             $app_info['build'] = 0;
                         }
                     }
                     $app_info['id'] = $app;
                     $app_info['name'] = _wd($app, $app_info['name']);
                     if (isset($app_info['icon'])) {
                         if (is_array($app_info['icon'])) {
                             foreach ($app_info['icon'] as $size => $url) {
                                 $app_info['icon'][$size] = 'wa-apps/' . $app . '/' . $url;
                             }
                         } else {
                             $app_info['icon'] = array(48 => 'wa-apps/' . $app . '/' . $app_info['icon']);
                         }
                     } else {
                         $app_info['icon'] = array();
                     }
                     if (isset($app_info['img'])) {
                         $app_info['img'] = 'wa-apps/' . $app . '/' . $app_info['img'];
                     } else {
                         $app_info['img'] = isset($app_info['icon'][48]) ? $app_info['icon'][48] : 'wa-apps/' . $app . '/img/' . $app . ".png";
                     }
                     if (!isset($app_info['icon'][48])) {
                         $app_info['icon'][48] = $app_info['img'];
                     }
                     if (!isset($app_info['icon'][24])) {
                         $app_info['icon'][24] = $app_info['icon'][48];
                     }
                     if (!isset($app_info['icon'][16])) {
                         $app_info['icon'][16] = $app_info['icon'][24];
                     }
                     self::$apps[$app] = $app_info;
                 }
             }
             if (!file_exists($file) || filemtime($file) < filemtime($this->getConfig()->getPath('config', 'apps'))) {
                 waUtils::varExportToFile(self::$apps, $file);
             }
         } else {
             self::$apps = (include $file);
             waLocale::loadByDomain('webasyst', $locale);
         }
     }
     if ($system) {
         return self::$apps;
     } else {
         $apps = self::$apps;
         unset($apps['webasyst']);
         return $apps;
     }
 }
 /**
  *
  * @param $path
  * @param $slug
  * @return array
  */
 private static function getRequirements($path, $slug)
 {
     if (!($requirements = false && self::getCacheValue($slug, null, $path))) {
         $requirements = self::getConfig($path);
         $fields = array('name', 'description');
         foreach ($requirements as &$requirement) {
             foreach ($fields as $field) {
                 if (isset($requirement[$field]) && is_array($requirement[$field])) {
                     if (self::$locale && isset($requirement[$field][self::$locale])) {
                         $value = $requirement[$field][self::$locale];
                     } elseif (isset($requirement[$field]['en_US'])) {
                         $value = $requirement[$field]['en_US'];
                     } else {
                         $value = array_shift($requirement[$field]);
                     }
                     $requirement[$field] = $value;
                 } elseif (!isset($requirement[$field])) {
                     $requirement[$field] = '';
                 } else {
                     $requirement[$field] = _wd($slug, $requirement[$field]);
                 }
             }
             if (!isset($requirement['strict'])) {
                 $requirement['strict'] = false;
             }
             unset($requirement);
         }
         //self::setCacheValue($slug,$requirements,$path);
     }
     return $requirements;
 }
 public function getPrintForms(waOrder $order = null)
 {
     return array('delivery_list' => array('name' => _wd('shipping_courier', 'Packing list'), 'description' => _wd('shipping_courier', 'Order summary for courier shipping')));
 }
 private function deleteApp($app_id)
 {
     //remove db tables and etc
     $paths = array();
     /**
      * @var waAppConfig
      */
     $system = wa($app_id);
     $system->setActive($app_id);
     $app = SystemConfig::getAppConfig($app_id);
     $info = $app->getInfo();
     $name = _wd($app_id, $info['name']);
     /**
      * @var waAppConfig $config ;
      */
     $config = $system->getConfig();
     if (!empty($info['plugins'])) {
         $plugins = $config->getPlugins();
         foreach ($plugins as $plugin => $enabled) {
             try {
                 if ($enabled && ($plugin_instance = $system->getPlugin($plugin))) {
                     $plugin_instance->uninstall();
                 }
             } catch (Exception $ex) {
                 waLog::log($ex->getMessage(), 'installer.log');
             }
             $this->apps->updateAppPluginsConfig($app_id, $plugin, null);
             //wa-apps/$app_id/plugins/$slug
             $paths[] = wa()->getAppPath("plugins/" . $plugin, $app_id);
             while ($path = array_shift($paths)) {
                 waFiles::delete($path, true);
             }
             $paths = array();
         }
     }
     $config->uninstall();
     $this->apps->updateAppConfig($app_id, null);
     $paths[] = wa()->getTempPath(null, $app_id);
     //wa-cache/temp/$app_id/
     $paths[] = wa()->getAppCachePath(null, $app_id);
     //wa-cache/apps/$app_id/
     $paths[] = wa()->getDataPath(null, true, $app_id);
     //wa-data/public/$app_id/
     $paths[] = wa()->getDataPath(null, false, $app_id);
     //wa-data/protected/$app_id/
     if ($this->options['log']) {
         $paths[] = wa()->getConfig()->getPath('log') . '/' . $app_id;
         //wa-log/$app_id/
     }
     if ($this->options['config']) {
         $paths[] = wa()->getConfigPath($app_id);
         //wa-config/$app_id/
     }
     $paths[] = wa()->getAppPath(null, $app_id);
     //wa-apps/$app_id/
     $paths[] = wa()->getAppCachePath(null, 'webasyst');
     //wa-cache/apps/webasyst/
     foreach ($paths as $path) {
         try {
             waFiles::delete($path, true);
         } catch (waException $ex) {
         }
     }
     return $name;
 }
 public function execute()
 {
     $this->init();
     $extras_ids = waRequest::post('extras_id');
     try {
         /*
         _w('Application themes not found');
         _w('Application plugins not found');
         */
         foreach ($extras_ids as &$info) {
             if (!is_array($info)) {
                 $info = array('vendor' => $info);
             }
             unset($info);
         }
         $options = array('installed' => true, 'local' => true);
         if ($this->extras_type == 'plugins') {
             $options['system'] = true;
         }
         $this->installer = installerHelper::getInstaller();
         $app_list = $this->installer->getItems($options);
         $queue = array();
         foreach ($extras_ids as $slug => $info) {
             $slug_chunks = explode('/', $slug);
             if ($slug_chunks[0] == 'wa-plugins') {
                 $app_id = $slug_chunks[0] . '/' . $slug_chunks[1];
             } else {
                 $app_id = reset($slug_chunks);
             }
             if (isset($app_list[$app_id]) || $slug_chunks == 'wa-plugins') {
                 $app = $app_list[$app_id];
                 if (($installed = $this->installer->getItemInfo($slug, $options)) && $info['vendor'] == $installed['vendor']) {
                     if (!empty($installed['installed']['system'])) {
                         /*
                         _w("Can not delete system application's themes \"%s\"");
                         _w("Can not delete system application's plugins \"%s\"");
                         */
                         $message = "Can not delete system application's {$this->extras_type} \"%s\"";
                         throw new waException(sprintf(_w($message), _wd($slug, isset($info['name']) ? $info['name'] : '???')));
                     }
                     $queue[] = array('app_slug' => $app_id, 'ext_id' => $installed['id'], 'name' => sprintf("%s (%s)", _wd($slug, $installed['installed']['name']), _wd($app_id, $app['name'])));
                     unset($extras_ids[$slug]);
                 }
             }
         }
         $deleted_extras = array();
         foreach ($queue as $q) {
             if ($this->removeExtras($q['app_slug'], $q['ext_id'])) {
                 $deleted_extras[] = $q['name'];
             }
         }
         if (!$deleted_extras) {
             $message = sprintf('Application %s not found', $this->extras_type);
             throw new waException(_w($message));
         }
         /*
         _w('Application plugin %s has been deleted', 'Applications plugins %s have been deleted');
         _w('Application theme %s has been deleted', 'Applications themes %s have been deleted');
         */
         $message_singular = sprintf('Application %s %%s has been deleted', preg_replace('/s$/', '', $this->extras_type));
         $message_plural = sprintf('Applications %a %%s have been deleted', $this->extras_type);
         $message = sprintf(_w($message_singular, $message_plural, count($deleted_extras), false), implode(', ', $deleted_extras));
         $msg = installerMessage::getInstance()->raiseMessage($message);
         $this->redirect('?msg=' . $msg . '#/' . $this->extras_type . '/');
     } catch (Exception $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $this->redirect('?msg=' . $msg . '#/' . $this->extras_type . '/');
     }
 }
    public function postForm($id = null)
    {
        $html = false;
        if (blogHelper::checkRights() >= blogRightConfig::RIGHT_READ_WRITE) {
            $url = wa()->getAppUrl('blog') . '?module=post&action=edit';
            $submit = _wd('blog', 'New post');
            $html = <<<HTML

        <form action="{$url}" method="POST" id="{$id}">
        <p>
        \t<input type="text" name="title"/><br/>
        \t<textarea name="text" cols="60" rows="20"></textarea><br/>
        \t{$this->wa->getView()->getHelper()->csrf()}
        \t<input type="submit" value="{$submit}"/>
        </p>
        </form>
HTML;
        }
        return $html;
    }
Esempio n. 13
0
 /**
  * Adds one control to the form that the default implementation of getHTML will return.
  *
  * Type: checkbox
  * - cssclass: CSS class for <tr>
  *
  * Type: list - list of checkboxes with $label being a header above them.
  * - cssclass: CSS class for <tr>
  * - items: array(access_key => human readable name) - checkboxes to show in the list.
  * - hint1: string to show above left checkbox col;
  *          'all_checkbox' will show a checkbox to check everything at once, and its status
  *          will be saved with access_key $name.all
  * - hint2: string to show above right checkbox col, if it's present
  *
  * @param string $name access_key to store in DB
  * @param string $label human readable name for a field
  * @param string $type control type; currently checkbox|list
  * @param array $params parameters passed to getItemHTML
  */
 public function addItem($name, $label, $type = 'checkbox', $params = array())
 {
     $this->items[] = array('name' => $name, 'label' => _wd($this->app, $label), 'type' => $type, 'params' => $params);
 }
Esempio n. 14
0
 private static function getCurl($url, $curl_options = array())
 {
     $ch = null;
     if (extension_loaded('curl') && function_exists('curl_init')) {
         if (!($ch = curl_init())) {
             throw new Exception(_wd('system', "Error cUrl init"));
         }
         if (curl_errno($ch) != 0) {
             throw new Exception(_wd('system', "Error cUrl init") . ' ' . curl_errno($ch) . ' ' . curl_error($ch));
         }
         if (!is_array($curl_options)) {
             $curl_options = array();
         }
         $curl_default_options = array(CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 10, CURLOPT_CONNECTTIMEOUT => 10, CURLE_OPERATION_TIMEOUTED => 10, CURLOPT_DNS_CACHE_TIMEOUT => 3600);
         if ((version_compare(PHP_VERSION, '5.4', '>=') || !ini_get('safe_mode')) && !ini_get('open_basedir')) {
             $curl_default_options[CURLOPT_FOLLOWLOCATION] = true;
         }
         foreach ($curl_default_options as $option => $value) {
             if (!isset($curl_options[$option])) {
                 $curl_options[$option] = $value;
             }
         }
         if ($post = self::getPost($url)) {
             $curl_options[CURLOPT_POST] = 1;
             $curl_options[CURLOPT_POSTFIELDS] = $post;
             if (isset($curl_default_options[CURLOPT_FOLLOWLOCATION])) {
                 //redirect doesn't work properly with POST
                 unset($curl_default_options[CURLOPT_FOLLOWLOCATION]);
             }
         }
         $curl_options[CURLOPT_URL] = $url;
         //TODO read proxy settings from generic config
         $options = array();
         if (isset($options['host']) && strlen($options['host'])) {
             $curl_options[CURLOPT_HTTPPROXYTUNNEL] = true;
             $curl_options[CURLOPT_PROXY] = sprintf("%s%s", $options['host'], isset($options['port']) && $options['port'] ? ':' . $options['port'] : '');
             if (isset($options['user']) && strlen($options['user'])) {
                 $curl_options[CURLOPT_PROXYUSERPWD] = sprintf("%s:%s", $options['user'], $options['password']);
             }
         }
         foreach ($curl_options as $param => $option) {
             curl_setopt($ch, $param, $option);
         }
     }
     return $ch;
 }
 public function contactsLinks($params)
 {
     waLocale::loadByDomain('photos');
     // TODO: take a look to other models related with contacts
     $links = array();
     $comments_model = new photosCommentModel();
     foreach ($params as $contact_id) {
         $links[$contact_id] = array();
         if ($count = $comments_model->countByField('contact_id', $contact_id)) {
             $links[$contact_id][] = array('role' => _wd('photos', 'Comments author'), 'links_number' => $count);
         }
     }
     return $links;
 }