/** * Get meta description of the table and generate fields array * @return array */ public function getMetadata() { if ($this->table && !$this->fields) { $runtime_cache = new waRuntimeCache('db/' . $this->table); if ($this->fields = $runtime_cache->get()) { return $this->fields; } if (SystemConfig::isDebug()) { $this->fields = $this->getFields(); } else { $cache = new waSystemCache('db/' . $this->table); if (!($this->fields = $cache->get())) { $this->fields = $this->getFields(); $cache->set($this->fields); } } $runtime_cache->set($this->fields); } return $this->fields; }
/** * Returns waPlugin object by plugin id. * * @param string $plugin_id * @throws waException * @return waPlugin */ public function getPlugin($plugin_id, $set_active = false) { $app_id = $this->getConfig()->getApplication(); $path = $this->getConfig()->getPluginPath($plugin_id) . '/lib/config/plugin.php'; if (file_exists($path)) { $class = $app_id . ucfirst($plugin_id) . 'Plugin'; $plugin_info = (include $path); $plugin_info['id'] = $plugin_id; if (isset($plugin_info['img'])) { $plugin_info['img'] = 'wa-apps/' . $app_id . '/plugins/' . $plugin_id . '/' . $plugin_info['img']; } if (!isset($plugin_info['app_id'])) { $plugin_info['app_id'] = $app_id; } $build_file = $this->getConfig()->getPluginPath($plugin_id) . 'lib/config/build.php'; if (file_exists($build_file)) { $plugin_info['build'] = (include $build_file); } else { if (SystemConfig::isDebug()) { $plugin_info['build'] = time(); } else { $plugin_info['build'] = 0; } } // load locale $locale_path = $this->getAppPath('plugins/' . $plugin_id . '/locale', $app_id); if (is_dir($locale_path)) { waLocale::load($this->getLocale(), $locale_path, $app_id . '_' . $plugin_id, false); } if ($set_active) { self::pushActivePlugin($plugin_id, $app_id); } return new $class($plugin_info); } else { throw new waException('Plugin ' . $plugin_id . ' not found'); } }
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'); } } if ($system) { return self::$apps; } else { $apps = self::$apps; unset($apps['webasyst']); return $apps; } }
/** * Returns information about all app's installed plugins as an associative array. * * @return array */ public function getPlugins() { if ($this->plugins === null) { $locale = wa()->getLocale(); $file = waConfig::get('wa_path_cache') . "/apps/" . $this->application . '/config/plugins.' . $locale . '.php'; if (!file_exists($file) || SystemConfig::isDebug()) { waFiles::create(waConfig::get('wa_path_cache') . "/apps/" . $this->application . '/config'); // read plugins from file wa-config/[APP_ID]/plugins.php $path = $this->getConfigPath('plugins.php', true); if (!file_exists($path)) { $this->plugins = array(); return $this->plugins; } $all_plugins = (include $path); $this->plugins = array(); foreach ($all_plugins as $plugin_id => $enabled) { if ($enabled) { $plugin_config = $this->getPluginPath($plugin_id) . "/lib/config/plugin.php"; if (!file_exists($plugin_config)) { continue; } $plugin_info = (include $plugin_config); waSystem::pushActivePlugin($plugin_id, $this->application); // Load plugin locale if it exists $locale_path = wa()->getAppPath('plugins/' . $plugin_id . '/locale', $this->application); if (is_dir($locale_path)) { waLocale::load($locale, $locale_path, wa()->getActiveLocaleDomain(), false); } $plugin_info['name'] = _wp($plugin_info['name']); if (isset($plugin_info['title'])) { $plugin_info['title'] = _wp($plugin_info['title']); } if (isset($plugin_info['description'])) { $plugin_info['description'] = _wp($plugin_info['description']); } waSystem::popActivePlugin(); $plugin_info['id'] = $plugin_id; $plugin_info['app_id'] = $this->application; if (isset($plugin_info['img'])) { $plugin_info['img'] = 'wa-apps/' . $this->application . '/plugins/' . $plugin_id . '/' . $plugin_info['img']; } if (isset($plugin_info['rights']) && $plugin_info['rights']) { $plugin_info['handlers']['rights.config'] = 'rightsConfig'; } if (isset($plugin_info['frontend']) && $plugin_info['frontend']) { $plugin_info['handlers']['routing'] = 'routing'; } if (!empty($plugin_info[$this->application . '_settings'])) { $plugin_info['custom_settings'] = $plugin_info[$this->application . '_settings']; } $this->plugins[$plugin_id] = $plugin_info; } } if (!SystemConfig::isDebug()) { waUtils::varExportToFile($this->plugins, $file); } else { waFiles::delete($file); } } else { $this->plugins = (include $file); } } return $this->plugins; }
public function version($edition = false) { static $build; $this->init(); if ($this->_version === null || $edition) { $this->_version = !empty($this->info['version']) ? $this->info['version'] : '0.0.1'; if (SystemConfig::isDebug()) { $this->_version .= "." . time(); } else { if ($edition === true) { $edition = $this->edition; } if ($build === null) { $file = $this->path . '/build.php'; if (file_exists($file)) { $build = (include $file); } else { $build = 0; } } if ($build) { if ($edition) { $build += $edition; return $this->_version . '.' . $build; } $this->_version .= '.' . $build; } elseif ($edition) { return $this->_version . '.' . $edition; } } } return $this->_version; }
function smarty_block_wa_js($params, $content, &$smarty) { if (!$content) { return ''; } // jquery ui custom bundle $ui_custom = array('core' => 0, 'widget' => 0, 'mouse' => 0, 'draggable' => 0, 'droppable' => 0, 'sortable' => 0, 'datepicker' => 1); $files = explode("\n", $content); $wa = waSystem::getInstance(); $jquery_ui_path = "wa-content/js/jquery-ui/jquery.ui."; $jquery_ui_path_n = strlen($jquery_ui_path); $n = strlen($wa->getRootUrl()); $locale = $wa->getLocale(); // // Non-debug mode: merge all files into one cache // if (!SystemConfig::isDebug() && isset($params['file'])) { $root_path = $wa->getConfig()->getRootPath(); $app_path = $wa->getConfig()->getAppPath(); $result = ''; $files_combine = array(); $mtime = file_exists($app_path . '/' . $params['file']) ? filemtime($app_path . '/' . $params['file']) : 0; $r = true; foreach ($files as $f) { $f = trim($f); $f = substr($f, $n); if ($f) { if (substr($f, 0, $jquery_ui_path_n) == $jquery_ui_path) { $jquery_f = substr($f, $jquery_ui_path_n); if (substr($jquery_f, -7) == '.min.js') { $jquery_f = substr($jquery_f, 0, -7); } if (isset($ui_custom[$jquery_f])) { if (!$result) { $result = '<script type="text/javascript" src="' . $wa->getRootUrl() . 'wa-content/js/jquery-ui/jquery-ui.custom.min.js"></script>' . "\n"; } // include locale if ($ui_custom[$jquery_f] && $locale != 'en_US') { $result .= '<script type="text/javascript" src="' . $wa->getRootUrl() . 'wa-content/js/jquery-ui/i18n/jquery.ui.' . $jquery_f . '-' . $locale . '.js"></script>' . "\n"; } continue; } } if (!file_exists($f)) { $r = false; break; } $files_combine[] = $f; if ($mtime && filemtime($root_path . '/' . $f) > $mtime) { $mtime = 0; } } } if ($files_combine) { if ($r && !$mtime && waFiles::create($app_path . '/' . $params['file'])) { // check Google Closure Compiler // https://developers.google.com/closure/compiler/docs/gettingstarted_app if ($compiler = waSystemConfig::systemOption('js_compiler')) { $cmd = 'java -jar "' . $compiler . '"'; foreach ($files_combine as $file) { $cmd .= ' --js "' . $root_path . '/' . $file . '"'; } $cmd .= ' --js_output_file "' . $app_path . '/' . $params['file'] . '"'; system($cmd, $res); $r = !$res; if (!$r) { waLog::log("Error occured while compress files:\n\t" . implode("\n\t", $files_combine) . "\n\t{$params['file']}\n\ncommand:\n{$cmd}", __FUNCTION__ . '.log'); } } else { $r = false; } if (!$r) { $data = ""; foreach ($files_combine as $file) { $data .= file_get_contents($root_path . '/' . $file) . ";\n"; } $r = @file_put_contents($app_path . '/' . $params['file'], $data); if (!$r) { waLog::log("Error occured while compress files:\n\t" . implode("\n\t", $files_combine) . "\n\t{$params['file']}", __FUNCTION__ . '.log'); } } } } if ($r) { if ($files_combine) { $result .= '<script type="text/javascript" src="' . $wa->getAppStaticUrl() . $params['file'] . '?v' . $wa->getVersion() . '"></script>' . "\n"; } return $result; } } // // Debug mode (or no file specified): include all files separately // $result = ""; foreach ($files as $f) { $f = trim($f); if ($f) { // Add ?version to circumvent browser caching if (substr($f, $n, 10) !== 'wa-content') { $f .= '?v' . $wa->getVersion(); } $result .= '<script type="text/javascript" src="' . $f . '"></script>' . "\n"; // Add datepicker localization automatically // !!! This is not really a good idea since it will break in non-debug mode anyways if (substr($f, $n) == $jquery_ui_path . 'datepicker.min.js' && $locale != 'en_US') { $result .= '<script type="text/javascript" src="' . $wa->getRootUrl() . 'wa-content/js/jquery-ui/i18n/jquery.ui.datepicker-' . $locale . '.js"></script>' . "\n"; } } } return $result; }
/** * @param bool|string $app_id - true for system version * @return string */ public function version($app_id = null) { if ($app_id === true) { $app_info = wa()->getAppInfo('webasyst'); return isset($app_info['version']) ? $app_info['version'] : '0.0.1'; } else { if ($this->version === null) { $app_info = wa()->getAppInfo($app_id); $this->version = isset($app_info['version']) ? $app_info['version'] : '0.0.1'; if (SystemConfig::isDebug()) { $this->version .= "." . time(); } else { $file = wa()->getAppPath('lib/config/build.php', $app_id); if (file_exists($file)) { $build = (include $file); $this->version .= '.' . $build; } } } return $this->version; } }
public function version() { $this->init(); if ($this->_version === null) { $this->_version = !empty($this->info['version']) ? $this->info['version'] : '0.0.1'; if (SystemConfig::isDebug()) { $this->_version .= "." . time(); } else { $file = $this->path . '/build.php'; if (file_exists($file)) { $build = (include $file); $this->_version .= '.' . $build; } } } return $this->_version; }
protected function getCache($app_id) { // cache one day return new waVarExportCache('app_settings/' . $app_id, SystemConfig::isDebug() ? 600 : 86400, 'webasyst'); }
<?php $sqls = array(); $sqls[] = <<<SQL UPDATE `wa_app_settings` SET app_id = CONCAT('blog.', SUBSTR(name, 8, POSITION('.' IN SUBSTR(name, 8)) - 1)), name = SUBSTR(name, 8 + POSITION('.' IN SUBSTR(name, 8))) WHERE `app_id`= 'blog' AND `name` LIKE 'plugin.%' SQL; $model = new waModel(); foreach ($sqls as $sql) { try { $model->exec($sql); } catch (Exception $ex) { if (class_exists('waLog')) { waLog::log(basename(__FILE__) . ': ' . $ex->getMessage(), 'blog-update.log'); } } } $cache = new waSerializeCache('app_settings/blog', SystemConfig::isDebug() ? 600 : 86400, 'webasyst'); $cache->delete();
/** * * Get plugin description * @param string $id * @return array[string]string * @return array['name']string * @return array['description']string * @return array['version']string * @return array['build']string * @return array['logo']string * @return array['icon'][int]string * @return array['img']string */ public static function info($id, $options = array(), $type = null) { $base_path = self::getPath($type, $id); $config_path = $base_path . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'plugin.php'; $plugin = null; if ($config_path && file_exists($config_path) && ($config = (include $config_path))) { $default = array('name' => preg_replace('@[A-Z]@', ' $1', $id), 'description' => ''); if (!is_array($config)) { $config = array(); } $build_file = $base_path . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'build.php'; if (file_exists($build_file)) { $config['build'] = (include $build_file); } else { if (SystemConfig::isDebug()) { $config['build'] = time(); } else { $config['build'] = 0; } } if (!empty($config['version'])) { $config['version'] .= '.' . $config['build']; } if (!empty($config['icon'])) { if (is_array($config['icon'])) { foreach ($config['icon'] as $size => $url) { $config['icon'][$size] = wa()->getRootUrl() . 'wa-plugins/' . $type . '/' . $id . '/' . $url; } } else { $config['icon'] = array(48 => wa()->getRootUrl() . 'wa-plugins/' . $type . '/' . $id . '/' . $config['icon']); } } else { $config['icon'] = array(); } if (!empty($config['img'])) { $config['img'] = wa()->getRootUrl() . 'wa-plugins/' . $type . '/' . $id . '/' . $config['img']; } else { $config['img'] = isset($config['icon'][48]) ? $config['icon'][48] : false; } if (!isset($config['icon'][48])) { $config['icon'][48] = $config['img']; } if (!isset($config['icon'][24])) { $config['icon'][24] = $config['icon'][48]; } if (!isset($config['icon'][16])) { $config['icon'][16] = $config['icon'][24]; } if (!isset($config['logo'])) { $config['logo'] = $config['icon'][48]; } elseif (!empty($config['logo'])) { $config['logo'] = wa()->getRootUrl() . 'wa-plugins/' . $type . '/' . $id . '/' . $config['logo']; } $plugin = array_merge($default, $config); foreach (array('name', 'description') as $field) { if (!empty($plugin[$field])) { $plugin[$field] = self::__w($plugin[$field], $type, $id, $base_path); } } } return $plugin; }
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); } }