Пример #1
0
 public function execute()
 {
     $path = $this->getConfig()->getConfigPath('data/welcome/', false);
     if (file_exists($path)) {
         $files = waFiles::listdir($path, false);
         $this->types = shopTypeModel::getTemplates();
         foreach ($files as $file) {
             if (preg_match('/^country_([a-z]{3})\\.php$/', $file, $matches)) {
                 $this->countries[$matches[1]] = $matches[1];
             }
         }
     }
     $locale_path = $path . 'locale/' . $this->getUser()->getLocale() . '.php';
     if (file_exists($locale_path)) {
         $this->translate = (include $locale_path);
         if (!is_array($this->translate)) {
             $this->translate = array();
         }
     }
     if (waRequest::post()) {
         $app_settings_model = new waAppSettingsModel();
         $app_settings_model->del('shop', 'welcome');
         $this->setup();
     } else {
         $this->overview();
     }
 }
 protected function flushCache()
 {
     $config = wa()->getConfig();
     $path_cache = $config->getPath('cache');
     waFiles::protect($path_cache);
     $caches = array();
     $paths = waFiles::listdir($path_cache);
     foreach ($paths as $path) {
         #skip long action & data path
         if ($path != 'temp') {
             $path = $path_cache . '/' . $path;
             if (is_dir($path)) {
                 $caches[] = $path;
             }
         }
     }
     $root_path = $config->getRootPath();
     $errors = array();
     foreach ($caches as $path) {
         try {
             waFiles::delete($path);
         } catch (Exception $ex) {
             $errors[] = str_replace($root_path . DIRECTORY_SEPARATOR, '', $ex->getMessage());
             waFiles::delete($path, true);
         }
     }
     waFiles::protect($path_cache);
     return $errors;
 }
Пример #3
0
 /**
  * Список доступных плагинов
  * @param $options array
  * @return array
  */
 public static function enumerate($options = array(), $type = null)
 {
     $plugins = array();
     foreach (waFiles::listdir(self::getPath($type)) as $id) {
         if ($info = self::info($id, $options = array(), $type)) {
             $plugins[$id] = $info;
         }
     }
     return $plugins;
 }
Пример #4
0
 public function execute()
 {
     $path = dirname(__FILE__);
     $files = waFiles::listdir($path);
     print "available CLI actions:\n";
     $callback = create_function('$m', 'return strtolower($m[1]);');
     $actions = array();
     foreach ($files as $file) {
         if (preg_match('/^webasyst(\\w+)\\.cli\\.php$/', $file, $matches)) {
             $action = preg_replace_callback('/^([\\w]{1})/', $callback, $matches[1]);
             $actions[] = $action;
         }
     }
     asort($actions);
     print implode("\n", $actions);
 }
 public 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'))) {
                     $images_path = wa()->getDataPath(null, true, 'webasyst');
                     if ($images = waFiles::listdir($images_path)) {
                         foreach ($images as $image) {
                             if (is_file($images_path . '/' . $image) && !preg_match('@\\.(jpe?g|png|gif|bmp)$@', $image)) {
                                 waFiles::delete($images_path . "/" . $image);
                             }
                         }
                         $message[] = _w('Image deleted');
                     }
                 } else {
                     $changed = true;
                 }
                 $model->del('webasyst', $setting);
             }
             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);
     }
 }
Пример #6
0
 public static function flushCache($apps = array())
 {
     $path_cache = waConfig::get('wa_path_cache');
     waFiles::protect($path_cache);
     $caches = array();
     $paths = waFiles::listdir($path_cache);
     foreach ($paths as $path) {
         #skip long action & data path
         if ($path != 'temp') {
             $path = $path_cache . '/' . $path;
             if (is_dir($path)) {
                 $caches[] = $path;
             }
         }
     }
     if ($apps) {
         $app_path = waConfig::get('wa_path_apps');
         foreach ($apps as $app) {
             if (!empty($app['installed'])) {
                 $caches[] = $app_path . '/' . $app['slug'] . '/js/compiled';
             }
         }
     }
     $caches[] = $path_cache . '/temp';
     $root_path = wa()->getConfig()->getRootPath();
     $errors = array();
     foreach ($caches as $path) {
         try {
             waFiles::delete($path);
         } catch (Exception $ex) {
             $errors[] = str_replace($root_path . DIRECTORY_SEPARATOR, '', $ex->getMessage());
             waFiles::delete($path, true);
         }
     }
     return $errors;
 }
 /**
  * Trigger event with given $name from current active application.
  *
  * @param  string    $name        Event name.
  * @param  mixed     $params      Parameters passed to event handlers.
  * @param  string[]  $array_keys  Array of expected template items for UI events.
  * @return  array  app_id or plugin_id => data returned from handler (unless null is returned)
  */
 public function event($name, &$params = null, $array_keys = null)
 {
     $result = array();
     if (is_array($name)) {
         $event_app_id = $name[0];
         $event_system = self::getInstance($event_app_id);
         $name = $name[1];
     } else {
         $event_app_id = $this->getConfig()->getApplication();
         $event_system = $this;
     }
     $event_prefix = wa($event_app_id)->getConfig()->getPrefix();
     if (!isset(self::$handlers['apps'])) {
         self::$handlers['apps'] = array();
         $cache_file = $this->config->getPath('cache', 'config/handlers');
         if (!waSystemConfig::isDebug() && file_exists($cache_file)) {
             self::$handlers['apps'] = (include $cache_file);
         }
         if (!self::$handlers['apps'] || !is_array(self::$handlers['apps'])) {
             $apps = $this->getApps();
             $path = $this->getConfig()->getPath('apps');
             foreach ($apps as $app_id => $app_info) {
                 $files = waFiles::listdir($path . '/' . $app_id . '/lib/handlers/');
                 foreach ($files as $file) {
                     if (substr($file, -12) == '.handler.php') {
                         $file = explode('.', substr($file, 0, -12), 2);
                         self::$handlers['apps'][$file[0]][$file[1]][] = $app_id;
                     }
                 }
             }
             if (!waSystemConfig::isDebug()) {
                 waUtils::varExportToFile(self::$handlers['apps'], $cache_file);
             }
         }
     }
     if (!isset(self::$handlers['plugins'][$event_app_id])) {
         self::$handlers['plugins'][$event_app_id] = array();
         $plugins = $event_system->getConfig()->getPlugins();
         foreach ($plugins as $plugin_id => $plugin) {
             if (!empty($plugin['handlers'])) {
                 foreach ($plugin['handlers'] as $handler_event => $handler_method) {
                     self::$handlers['plugins'][$event_app_id][$handler_event][$plugin_id] = $handler_method;
                 }
             }
         }
     }
     if (isset(self::$handlers['apps'][$event_app_id][$name])) {
         $path = $this->getConfig()->getPath('apps');
         foreach (self::$handlers['apps'][$event_app_id][$name] as $app_id) {
             $file_path = $path . '/' . $app_id . '/lib/handlers/' . $event_prefix . "." . $name . ".handler.php";
             if (!file_exists($file_path)) {
                 continue;
             }
             wa($app_id);
             include_once $file_path;
             $class_name = $name;
             if (strpos($name, '.') !== false) {
                 $class_name = strtok($class_name, '.') . ucfirst(strtok(''));
             }
             $class_name = $app_id . ucfirst($event_prefix) . ucfirst($class_name) . "Handler";
             /**
              * @var $handler waEventHandler
              */
             $handler = new $class_name();
             try {
                 $r = $handler->execute($params);
                 if ($r !== null) {
                     $result[$app_id] = $r;
                 }
             } catch (Exception $e) {
                 waLog::log('Event handling error in ' . $file_path . ': ' . $e->getMessage());
             }
         }
     }
     if (isset(self::$handlers['plugins'][$event_app_id][$name])) {
         $plugins = $event_system->getConfig()->getPlugins();
         foreach (self::$handlers['plugins'][$event_app_id][$name] as $plugin_id => $method) {
             if (!isset($plugins[$plugin_id])) {
                 continue;
             }
             $plugin = $plugins[$plugin_id];
             self::pushActivePlugin($plugin_id, $event_prefix);
             $class_name = $event_app_id . ucfirst($plugin_id) . 'Plugin';
             try {
                 $class = new $class_name($plugin);
                 // Load plugin locale if it exists
                 $locale_path = $this->getAppPath('plugins/' . $plugin_id . '/locale', $event_app_id);
                 if (is_dir($locale_path)) {
                     waLocale::load($this->getLocale(), $locale_path, self::getActiveLocaleDomain(), false);
                 }
                 if (method_exists($class, $method) && null !== ($r = $class->{$method}($params))) {
                     if ($array_keys && is_array($r)) {
                         foreach ($array_keys as $k) {
                             if (!isset($r[$k])) {
                                 $r[$k] = '';
                             }
                         }
                     }
                     $result[$plugin_id . '-plugin'] = $r;
                 }
             } catch (Exception $e) {
                 waLog::log('Event handling error in ' . $class_name . '->' . $name . '(): ' . $e->getMessage());
             }
             self::popActivePlugin();
         }
     }
     return $result;
 }
 public function getWidgets()
 {
     if ($this->widgets === null) {
         $locale = wa()->getLocale();
         $file = waConfig::get('wa_path_cache') . "/apps/" . $this->application . '/config/widgets.' . $locale . '.php';
         if (!file_exists($file) || SystemConfig::isDebug()) {
             $this->widgets = array();
             if ($this->application == 'webasyst') {
                 $path = $this->getRootPath() . '/wa-widgets';
             } else {
                 $path = $this->getAppPath('widgets');
             }
             foreach (waFiles::listdir($path) as $widget_id) {
                 $widget_dir = $this->getWidgetPath($widget_id);
                 $widget_config = $widget_dir . "/lib/config/widget.php";
                 if (!is_dir($widget_dir) || !file_exists($widget_config)) {
                     continue;
                 }
                 $widget_info = (include $widget_config);
                 $widget_info['has_settings'] = file_exists($this->getWidgetPath($widget_id) . "/lib/config/settings.php");
                 waSystem::pushActivePlugin($widget_id, $this->application == 'webasyst' ? 'widget' : $this->application . '_widget');
                 // Load widget locale if it exists
                 if ($this->application == 'webasyst') {
                     $locale_path = waConfig::get('wa_path_widgets') . '/' . $widget_id . '/locale';
                 } else {
                     $locale_path = wa()->getAppPath('widgets/' . $widget_id . '/locale', $this->application);
                 }
                 if (is_dir($locale_path)) {
                     waLocale::load($locale, $locale_path, wa()->getActiveLocaleDomain(), false);
                 }
                 $widget_info['name'] = _wp($widget_info['name']);
                 if (isset($plugin_info['title'])) {
                     $widget_info['title'] = _wp($widget_info['title']);
                 }
                 if (isset($widget_info['description'])) {
                     $widget_info['description'] = _wp($widget_info['description']);
                 }
                 if (isset($widget_info['size'])) {
                     $sizes = array();
                     foreach ((array) $widget_info['size'] as $s) {
                         $sizes[] = explode('x', $s);
                     }
                     $widget_info['sizes'] = $sizes;
                 } else {
                     $widget_info['sizes'] = array(array(1, 1));
                 }
                 waSystem::popActivePlugin();
                 $widget_info['widget'] = $widget_id;
                 $widget_info['app_id'] = $this->application;
                 if (isset($widget_info['img'])) {
                     if ($this->application == 'webasyst') {
                         $widget_info['img'] = 'wa-widgets/' . $widget_id . '/' . $widget_info['img'];
                     } else {
                         $widget_info['img'] = 'wa-apps/' . $this->application . '/widgets/' . $widget_id . '/' . $widget_info['img'];
                     }
                 }
                 $this->widgets[$widget_id] = $widget_info;
             }
             if (!SystemConfig::isDebug()) {
                 waUtils::varExportToFile($this->widgets, $file);
             } else {
                 waFiles::delete($file);
             }
         } else {
             $this->widgets = (include $file);
         }
     }
     return $this->widgets;
 }
 public function update($only_if_not_modified = true)
 {
     if (!$this->path_custom || $this->type != self::OVERRIDDEN) {
         return true;
     }
     $files = $this->getFiles();
     $modified = array();
     foreach ($files as $f_id => $f) {
         if (!empty($f['modified'])) {
             $modified[] = $f_id;
             break;
         }
     }
     if ($only_if_not_modified && $modified) {
         return false;
     }
     $img_files = array();
     foreach ($this->getSettings() as $s) {
         if (ifset($s['control_type']) == 'image' && !empty($s['value'])) {
             $img_files[] = $s['value'];
         }
     }
     $source_path = $this->path_original;
     $target_path = $this->path_custom;
     $list_files = waFiles::listdir($source_path);
     $skip_pattern = '/\\.(files\\.md5|cvs|svn|git|php\\d*)$/';
     foreach ($list_files as $f) {
         // ignore files
         if ($f !== 'build.php') {
             foreach ((array) $skip_pattern as $pattern) {
                 if (preg_match($pattern, $f)) {
                     continue 2;
                 }
             }
         }
         // ignore image settings and modified
         if ($f == 'theme.xml' || in_array($f, $img_files) || in_array($f, $modified)) {
             continue;
         }
         try {
             waFiles::copy($source_path . '/' . $f, $target_path . '/' . $f);
         } catch (waException $e) {
         }
     }
     if ($this->type == self::OVERRIDDEN) {
         $theme_original = new waTheme($this->id, $this->app_id, self::ORIGINAL);
         $this->version = $theme_original->version;
         foreach ($theme_original->getFiles(true) as $f_id => $f) {
             if (empty($files[$f_id])) {
                 $this->setFiles(array($f_id => $f));
             }
         }
         foreach ($theme_original->getSettings('full') as $var => $s) {
             if (!isset($this->info['settings'][$var])) {
                 $this->info['settings'][$var] = $s;
                 $this->settings[$var]['value'] = ifset($s['value'], '');
                 $this->changed['settings'][$var] = true;
             } else {
                 $old_s = $this->info['settings'][$var];
                 if (ifset($old_s['control_type']) != ifset($s['control_type']) || ifset($old_s['options']) != ifset($s['options'])) {
                     $s['value'] = ifset($old_s['value'], '');
                     $this->info['settings'][$var] = $s;
                     $this->settings[$var]['value'] = $s['value'];
                     $this->changed['settings'][$var] = true;
                 }
             }
         }
         $this->save();
     }
     return true;
 }
Пример #10
0
 /**
  * @return array
  */
 public static function getTemplates()
 {
     static $types = null;
     if ($types === null) {
         $types = array();
         $path = wa('shop')->getConfig()->getConfigPath('data/welcome/', false);
         if (file_exists($path)) {
             $files = waFiles::listdir($path, false);
             foreach ($files as $file) {
                 if (preg_match('/^type_([a-z]\\w+)\\.php$/', $file, $matches)) {
                     $types[$matches[1]] = (include $path . $file);
                 }
             }
         }
         $locale_path = $path . 'locale/' . wa()->getUser()->getLocale() . '.php';
         if (file_exists($locale_path)) {
             self::$translate = (include $locale_path);
             if (!is_array(self::$translate)) {
                 self::$translate = array();
             }
         }
         if (!empty($types)) {
             foreach ($types as $id => &$type) {
                 $name = ifempty($type['name'], $id);
                 $type['name'] = ifempty(self::$translate[$name], $name);
                 $type += array('icon' => '', 'description' => '');
             }
         }
     }
     return $types;
 }
 /**
  * @param bool $type
  * @param bool $enabled_only
  * @return array|null
  * @throws waException
  */
 public static function getAll($type = false, $enabled_only = true)
 {
     $locale_config = waSystem::getInstance()->getConfigPath() . '/locale.php';
     if (file_exists($locale_config)) {
         $enabled_locales = (include $locale_config);
         $ttl = time() - filemtime($locale_config);
     } else {
         $enabled_locales = array('en_US', 'ru_RU');
         $ttl = 86400;
     }
     $cache = new waSystemCache('config/locale', $ttl);
     if ($cache->isCached()) {
         $data = $cache->get();
     } else {
         $data = array();
         foreach ($enabled_locales as $locale) {
             if ($info = self::getInfo($locale)) {
                 $data[$locale] = $info;
             }
         }
         $files = waFiles::listdir(dirname(__FILE__) . "/data/");
         foreach ($files as $file) {
             if (preg_match('/^([a-zA-Z_]+)\\.php$/', $file, $matches)) {
                 $locale = $matches[1];
                 if (!isset($data[$locale]) && ($info = self::getInfo($locale))) {
                     $data[$locale] = $info;
                 }
             }
         }
         $cache->set($data);
     }
     if ($enabled_only) {
         $result = array();
         foreach ($enabled_locales as $locale) {
             if (isset($data[$locale])) {
                 $result[$locale] = $data[$locale];
             }
         }
         $data = $result;
     }
     if ($type === true) {
         $type = 'all';
     }
     switch ($type) {
         case 'name_region':
             foreach ($data as &$d) {
                 $d = $d['name'] . " (" . $d['region'] . ')';
             }
             asort($data);
             break;
         case 'name':
             foreach ($data as &$d) {
                 $d = $d['name'];
             }
             asort($data);
             break;
         case false:
             return array_keys($data);
         default:
             return $data;
     }
     return $data;
 }
Пример #12
0
 public function getClasses()
 {
     $cache_file = waConfig::get('wa_path_cache') . '/apps/' . $this->application . '/config/autoload.php';
     if (self::isDebug() || !file_exists($cache_file)) {
         waFiles::create(waConfig::get('wa_path_cache') . '/apps/' . $this->application . '/config');
         $paths = array($this->getAppPath() . '/lib/');
         $all_plugins = waFiles::listdir($this->getAppPath() . '/plugins');
         foreach ($all_plugins as $plugin_id) {
             $path = $this->getPluginPath($plugin_id) . '/lib/';
             if (file_exists($path)) {
                 $paths[] = $path;
             }
         }
         if (file_exists($this->getAppPath() . '/api')) {
             $v = waRequest::request('v', 1, 'int');
             if (file_exists($this->getAppPath() . '/api/v' . $v)) {
                 $paths[] = $this->getAppPath() . '/api/v' . $v . '/';
             }
         }
         $result = array();
         $length = strlen($this->getRootPath());
         foreach ($paths as $path) {
             $files = $this->getPHPFiles($path);
             foreach ($files as $file) {
                 $class = $this->getClassByFilename(basename($file));
                 if ($class) {
                     $result[$class] = substr($file, $length + 1);
                 }
             }
         }
         if (!self::isDebug()) {
             waUtils::varExportToFile($result, $cache_file);
         } else {
             waFiles::delete($cache_file);
         }
         return $result;
     }
     return include $cache_file;
 }
Пример #13
0
    private function reset()
    {
        /**
         * @event reset
         *
         * Notify plugins about reset all settings
         *
         * @param void
         * @return void
         */
        wa()->event('reset');
        //XXX hardcode
        $tables = array('shop_page', 'shop_page_params', 'shop_category', 'shop_category_params', 'shop_category_products', 'shop_category_routes', 'shop_product', 'shop_product_params', 'shop_product_features', 'shop_product_features_selectable', 'shop_product_images', 'shop_product_pages', 'shop_product_related', 'shop_product_reviews', 'shop_product_services', 'shop_product_skus', 'shop_product_stocks', 'shop_product_stocks_log', 'shop_search_index', 'shop_search_word', 'shop_tag', 'shop_product_tags', 'shop_set', 'shop_set_products', 'shop_stock', 'shop_feature', 'shop_feature_values_dimension', 'shop_feature_values_double', 'shop_feature_values_text', 'shop_feature_values_varchar', 'shop_feature_values_color', 'shop_feature_values_range', 'shop_type', 'shop_type_features', 'shop_type_services', 'shop_type_upselling', 'shop_service', 'shop_service_variants', 'shop_currency', 'shop_customer', 'shop_cart_items', 'shop_order', 'shop_order_items', 'shop_order_log', 'shop_order_log_params', 'shop_order_params', 'shop_affiliate_transaction', 'shop_checkout_flow', 'shop_notification', 'shop_notification_params', 'shop_coupon', 'shop_discount_by_sum', 'shop_tax', 'shop_tax_regions', 'shop_tax_zip_codes', 'shop_affiliate_transaction', 'shop_importexport');
        $model = new waModel();
        foreach ($tables as $table) {
            $exist = false;
            try {
                $model->query(sprintf("SELECT * FROM `%s` WHERE 0", $table));
                $exist = true;
                $model->query(sprintf("TRUNCATE `%s`", $table));
            } catch (waDbException $ex) {
                if ($exist) {
                    throw $ex;
                }
            }
        }
        $sqls = array();
        $sqls[] = 'UPDATE`shop_type` SET`count` = 0';
        $sqls[] = 'UPDATE`shop_set` SET`count` = 0';
        foreach ($sqls as $sql) {
            $model->query($sql);
        }
        $ccm = new waContactCategoryModel();
        $ccm->deleteByField('app_id', 'shop');
        $app_settings_model = new waAppSettingsModel();
        $currency_model = new shopCurrencyModel();
        $currency_model->insert(array('code' => 'USD', 'rate' => 1.0, 'sort' => 1), 2);
        $app_settings_model->set('shop', 'currency', 'USD');
        $app_settings_model->set('shop', 'use_product_currency', true);
        $paths = array();
        $paths[] = wa()->getDataPath('products', false, 'shop');
        $paths[] = wa()->getDataPath('products', true, 'shop');
        $paths[] = wa()->getTempPath();
        $config_path = wa()->getConfigPath('shop');
        foreach (waFiles::listdir($config_path, true) as $path) {
            if (!in_array($path, array('plugins.php', '..', '.'))) {
                $paths[] = $config_path . '/' . $path;
            }
        }
        $paths[] = wa()->getCachePath(null, 'shop');
        foreach ($paths as $path) {
            waFiles::delete($path, true);
        }
        $path = wa()->getDataPath('products', true, 'shop');
        waFiles::write($path . '/thumb.php', '<?php
$file = realpath(dirname(__FILE__)."/../../../../")."/wa-apps/shop/lib/config/data/thumb.php";

if (file_exists($file)) {
    include($file);
} else {
    header("HTTP/1.0 404 Not Found");
}
');
        waFiles::copy($this->getConfig()->getAppPath('lib/config/data/.htaccess'), $path . '/.htaccess');
        echo json_encode(array('result' => 'ok', 'redirect' => '?action=welcome'));
        exit;
    }
Пример #14
0
 private function initPath()
 {
     $type = preg_replace('@s$@', '', $this->type);
     switch ($type) {
         case 'app':
             $namespace = $this->app_id;
             $this->path = wa()->getConfig()->getAppsPath($this->app_id, null);
             break;
         case 'plugin':
         case 'theme':
             $namespace = $this->app_id . ucfirst($this->extension_id);
             $this->path = wa()->getConfig()->getAppsPath($this->app_id, $this->type . '/' . $this->extension_id);
             break;
         case 'shipping':
         case 'payment':
             $namespace = $this->extension_id . ucfirst($this->type);
             $this->path = wa()->getConfig()->getPath('plugins') . '/' . $this->type . '/' . $this->extension_id;
             break;
         case 'sms':
             $namespace = $this->extension_id . strtoupper($this->type);
             $this->path = wa()->getConfig()->getPath('plugins') . '/' . $this->type . '/' . $this->extension_id;
             break;
         default:
             throw new waException('');
     }
     if (!file_exists($this->path) || !is_dir($this->path)) {
         throw new waException('Invalid SLUG: path not found');
     }
     $this->type = $type;
     $this->folder = $this->extension_id ? $this->extension_id : $this->app_id;
     $this->archive_path = $this->path . '/' . $this->folder . '.tar.gz';
     $this->config = $this->getItemConfig($this->type);
     $this->files = waFiles::listdir($this->path, true);
     sort($this->files);
     $blacklist = array();
     if ($this->type == 'app') {
         $blacklist['@^plugins/.+@'] = 'application\'s plugins';
         if (true) {
             $blacklist['@^themes/(?!default).+@'] = 'application\'s themes';
         }
     }
     waRequest::setParam(array('namespace' => $namespace, 'prefix' => isset($this->config['prefix']) ? $this->config['prefix'] : null, 'type' => $this->type, 'app' => $this->app_id, 'app_id' => $this->app_id, 'extension' => $this->extension_id));
     return $this->filter($this->files, $blacklist);
 }
Пример #15
0
 private static function listDir($dir, $recursive = false)
 {
     $result = waFiles::listdir($dir, $recursive);
     $result = array_filter($result, create_function('$item', 'return basename($item) != ".htaccess";'));
     return $result;
 }
 protected static function getData()
 {
     if (self::$data === null) {
         $config = wa()->getConfig()->getConfigFile('currency');
         $config_path = wa()->getConfig()->getPath('config') . '/currency.php';
         $cache = new waSystemCache('config/currency' . wa()->getLocale());
         if ($config && filemtime($config_path) > $cache->getFilemtime()) {
             self::$data = array();
         } else {
             self::$data = $cache->get();
         }
         if (!self::$data) {
             self::$data = array();
             $files = waFiles::listdir(dirname(__FILE__) . "/data/");
             foreach ($files as $file) {
                 if (preg_match('/^([A-Z]{3})\\.php$/', $file, $matches)) {
                     $currency = $matches[1];
                     $file = wa()->getConfig()->getPath('system') . "/currency/data/" . $currency . ".php";
                     if (file_exists($file)) {
                         $info = (include $file);
                         $info['title'] = _ws($info['title']);
                     } else {
                         $info = array('sign' => $currency, 'title' => $currency);
                     }
                     self::$data[$currency] = $info;
                 }
             }
             foreach ($config as $cur => $info) {
                 if (!isset(self::$data[$cur])) {
                     self::$data[$cur] = $info;
                 } else {
                     foreach ($info as $k => $v) {
                         self::$data[$cur][$k] = $v;
                     }
                 }
             }
             $cache->set(self::$data);
         }
     }
     return self::$data;
 }
Пример #17
0
 private function getImages($path)
 {
     $files = waFiles::listdir($path);
     foreach ($files as $id => $file) {
         if (!is_file($path . '/' . $file) || !preg_match('@\\.(jpe?g|png|gif|bmp)$@', $file)) {
             unset($files[$id]);
         }
     }
     return array_values($files);
 }
 protected function generateSchema($app_id, $tables = array())
 {
     $plugin_id = false;
     if (strpos($app_id, '/') !== false) {
         list($app_id, $plugin_id) = explode('/', $app_id, 2);
         $path = wa()->getConfig()->getAppsPath($app_id, 'plugins/' . $plugin_id . '/lib/config/db.php');
     } else {
         $path = wa()->getConfig()->getAppsPath($app_id, 'lib/config/db.php');
     }
     $exists_schema = array();
     if (file_exists($path)) {
         $schema = (include $path);
         $exists_schema = $schema;
         $exists_tables = array_keys($schema);
     } else {
         $exists_tables = array();
     }
     $exclude_patterns = array();
     if (!in_array($this->getParam('update'), array('all', 'none'))) {
         if (!$tables) {
             $tables = $exists_tables;
         }
     } elseif ($tables) {
         if (!is_array($tables)) {
             $tables = array($tables);
         }
         //TODO add pattern support
     } else {
         $exclude = array();
         if ($app_id == 'webasyst') {
             $prefix = 'wa';
         } else {
             $prefix = $app_id;
             if ($plugin_id) {
                 $prefix .= '_' . $plugin_id;
             } else {
                 if (SystemConfig::isDebug()) {
                     $plugins = waFiles::listdir(wa()->getConfig()->getAppsPath($app_id, 'plugins/'));
                     foreach ($plugins as $_id => $plugin_id) {
                         if (!preg_match('@^[a-z][a-z0-9_]+$@', $plugin_id)) {
                             unset($plugins[$_id]);
                         }
                     }
                     $plugins = array_values($plugins);
                 } else {
                     $plugins = wa($app_id)->getConfig()->getPlugins();
                     $plugins = array_keys($plugins);
                 }
                 foreach ($plugins as $plugin_id) {
                     if ($this->getParam('ignore') == 'pattern') {
                         $plugin_prefix = $app_id . '_' . $plugin_id;
                         if (in_array($plugin_prefix, $exists_tables)) {
                             print sprintf("Warning: Plugin %s has conflicted table namespace\n", $plugin_id);
                         }
                         $exclude = array_merge($exclude, $this->getTables($plugin_prefix));
                     } elseif ($this->getParam('ignore') == 'config') {
                         $plugin_path = wa()->getConfig()->getAppsPath($app_id, 'plugins/' . $plugin_id . '/lib/config/db.php');
                         if (file_exists($plugin_path)) {
                             $exclude_tables = (include $plugin_path);
                             if (is_array($exclude_tables)) {
                                 $exclude = array_merge($exclude, array_keys($exclude_tables));
                             }
                         }
                     }
                     $exclude_patterns[] = sprintf('@(^%1$s$|^%1$s_|_%1$s$)@', $plugin_id);
                 }
             }
         }
         $tables = $this->getTables($prefix);
         $tables = array_diff($tables, $exclude);
     }
     print str_repeat('-', 120) . "\n";
     echo sprintf("%s\n", $app_id);
     $schema = array();
     if ($exists_tables || $tables) {
         $max = max(array_map('strlen', array_merge($exists_tables, array_keys($tables), array('12345678'))));
         $format = "%s|%-{$max}s|%8s|%30s|%30s\n";
         print str_repeat('-', 120) . "\n";
         echo sprintf($format, 'S', 'TABLE', 'STATUS', 'FIELDS', 'KEYS');
         print str_repeat('-', 120) . "\n";
         foreach ($tables as $t) {
             try {
                 $schema[$t] = $this->model->describe($t, 1);
                 if (in_array($t, $exists_tables)) {
                     $compare = $this->compareTable($schema[$t], $exists_schema[$t], $exclude_patterns);
                 } else {
                     $compare = array('s' => '+', 'c' => 'ADDED');
                 }
             } catch (waDbException $ex) {
                 $compare = array('s' => '!', 'c' => 'ERROR: ' . $ex->getMessage());
             }
             if ($compare['s'] !== '=' || $this->getParam('view') == 'all') {
                 echo sprintf($format, $compare['s'], $t, $compare['c'], ifset($compare['r']['FIELDS']), ifset($compare['r']['KEYS']));
             }
         }
         foreach ($exists_tables as $t) {
             if (!isset($schema[$t])) {
                 $s = '-';
                 $c = 'DELETED';
                 echo sprintf($format, $s, $t, $c, '', '');
             }
         }
     } else {
         echo sprintf("There no tables for %s\n", $app_id);
     }
     print str_repeat('-', 120) . "\n";
     if ($schema && $this->getParam('update') != 'none') {
         echo sprintf("Schema saved for %s\n", $app_id);
         if ($exclude_patterns) {
             foreach ($schema as &$table_schema) {
                 $table_schema = $this->cleanupSchema($table_schema, $exclude_patterns);
             }
             unset($table_schema);
         }
         // save schema to lib/config/db.php of the app
         waUtils::varExportToFile($this->schemaToString($schema), $path, false);
     }
 }
Пример #19
0
if (!file_exists($root . '/.svn') && !file_exists($root . '/.git')) {
    $plugin_types = array('shipping', 'payment');
    foreach ($plugin_types as $type) {
        $base_path = $path . '/' . $type . '/';
        foreach (waFiles::listdir($path . '/' . $type) as $plugin) {
            if (preg_match('/[A-Z]/', $plugin)) {
                try {
                    $plugin_path = $base_path . $plugin;
                    $file_name = $plugin_path . '/lib/' . $plugin . ucfirst($type) . '.class.php';
                    $plugin = strtolower($plugin);
                    $dest_file_name = $plugin_path . '/lib/' . $plugin . ucfirst($type) . '.class.php';
                    $dest_plugin_path = $base_path . $plugin;
                    waFiles::move($file_name, $dest_file_name);
                    waFiles::move($plugin_path, $dest_plugin_path);
                } catch (Exception $e) {
                    waLog::log($e->getMessage());
                }
            }
        }
        foreach (waFiles::listdir($path . '/' . $type) as $plugin) {
            if (preg_match('/[A-Z]/', $plugin)) {
                $plugin_path = $base_path . $plugin;
                try {
                    waFiles::delete($plugin_path);
                } catch (Exception $e) {
                    waLog::log($e->getMessage());
                }
            }
        }
    }
}
Пример #20
0
 public static function getAll($type = 'title')
 {
     // @todo: support wa-config/currency.php
     $cache = new waVarExportCache(__CLASS__ . wa()->getLocale());
     $data = $cache->get();
     if (!$data) {
         $data = array();
         $files = waFiles::listdir(dirname(__FILE__) . "/data/");
         foreach ($files as $file) {
             if (preg_match('/^([A-Z]{3})\\.php$/', $file, $matches)) {
                 $currency = $matches[1];
                 $data[$currency] = self::getInfo($currency);
             }
         }
         $cache->set($data);
     }
     if ($type === true) {
         $type = 'all';
     }
     switch ($type) {
         case 'code':
         case 'sign':
         case 'title':
             foreach ($data as &$d) {
                 $d = $d[$type];
             }
             return $data;
         default:
             return $data;
     }
 }
Пример #21
0
 public function execute()
 {
     $direction = waRequest::request('direction', 'import') == 'export' ? 'export' : 'import';
     $profile_helper = new shopImportexportHelper('csv:product:' . $direction);
     $this->view->assign('profiles', $profile_helper->getList());
     $profile = $profile_helper->getConfig();
     if ($direction == 'export') {
         //export section TODO
         $profile['config'] += array('encoding' => 'UTF-8', 'images' => true, 'features' => true, 'domain' => null, 'delimiter' => ';', 'hash' => '');
         $info = array();
         if (!empty($profile['id'])) {
             $path = wa()->getTempPath('csv/download/' . $profile['id']);
             $files = waFiles::listdir($path);
             foreach ($files as $file) {
                 $file_path = $path . '/' . $file;
                 $info[] = array('name' => $file, 'mtime' => filemtime($file_path), 'size' => filesize($file_path));
             }
             usort($info, create_function('$a, $b', 'return (max(-1, min(1, $a["mtime"] - $b["mtime"])));'));
         }
         $this->view->assign('info', array_slice($info, -5, 5, true));
         $set_model = new shopSetModel();
         $this->view->assign('sets', $set_model->getAll());
         $routing = wa()->getRouting();
         $settlements = array();
         $current_domain = null;
         $domain_routes = $routing->getByApp('shop');
         foreach ($domain_routes as $domain => $routes) {
             foreach ($routes as $route) {
                 $settlement = $domain . '/' . $route['url'];
                 if ($current_domain === null) {
                     $current_domain = $settlement;
                 } elseif ($settlement == $profile['config']['domain']) {
                     $current_domain = $settlement;
                 }
                 $settlements[] = $settlement;
             }
         }
         $this->view->assign('current_domain', $current_domain);
         $this->view->assign('settlements', $settlements);
     } else {
         $profile['config'] += array('encoding' => 'UTF-8', 'delimiter' => ';', 'map' => array());
         $base_path = wa()->getConfig()->getPath('root');
         $app_path = array('shop' => wa()->getDataPath(null, false, 'shop'), 'site' => wa()->getDataPath(null, true, 'site'));
         foreach ($app_path as &$path) {
             $path = preg_replace('@^([\\\\/])@', '', str_replace($base_path, '', $path . '/'));
         }
         unset($path);
         $this->view->assign('upload_path', waSystem::getSetting('csv.upload_path', 'path/to/folder/with/source/images/'));
         $this->view->assign('upload_app', waSystem::getSetting('csv.upload_app', 'shop'));
         $this->view->assign('app_path', $app_path);
     }
     $this->view->assign('profile', $profile);
     $type_model = new shopTypeModel();
     $this->view->assign('types', $type_model->getTypes());
     $encoding = array_diff(mb_list_encodings(), array('pass', 'wchar', 'byte2be', 'byte2le', 'byte4be', 'byte4le', 'BASE64', 'UUENCODE', 'HTML-ENTITIES', 'Quoted-Printable', '7bit', '8bit', 'auto'));
     $popular = array_intersect(array('UTF-8', 'Windows-1251', 'ISO-8859-1'), $encoding);
     asort($encoding);
     $encoding = array_unique(array_merge($popular, $encoding));
     $this->view->assign('encoding', $encoding);
     $plugins = wa()->getConfig()->getPlugins();
     $this->view->assign('direction', $direction);
     $this->view->assign('plugin', ifempty($plugins['csvproducts'], array()));
 }