public function execute() { $this->getResponse()->addJs("js/jquery.pageless2.js?v=" . wa()->getVersion(), true); $this->view->assign('site_theme_url', wa()->getDataUrl('themes', true, 'site') . '/' . waRequest::param('theme', 'default') . '/'); $this->view->assign('action', $action = waRequest::param('action', 'default')); waRequest::setParam('action', $action); $params = waRequest::param(); /** * @event frontend_action_default * @event frontend_action_post * @event frontend_action_page * @event frontend_action_error * @param array[string]mixed $params request params * @return array[string][string]string $return['%plugin_id%'] * @return array[string][string]string $return['%plugin_id%'][nav_before] * @return array[string][string]string $return['%plugin_id%'][footer] * @return array[string][string]string $return['%plugin_id%'][head] * @return array[string][string]string $return['%plugin_id%'][sidebar] */ $this->view->assign('settlement_one_blog', isset($params['blog_id']) && $params['blog_url_type'] == $params['blog_id']); $this->view->assign('frontend_action', $res = wa()->event('frontend_action_' . $action, $params)); if (!$this->view->getVars('links')) { $this->view->assign('links', array()); } $this->setThemeTemplate('index.html'); }
private function initRouting() { $routing = wa()->getRouting(); $app_id = $this->getAppId(); $domain_routes = $routing->getByApp($app_id); $success = false; foreach ($domain_routes as $domain => $routes) { foreach ($routes as $route) { if ($domain . '/' . $route['url'] == $this->data['domain']) { $routing->setRoute($route, $domain); $this->data['type_id'] = ifempty($route['type_id'], array()); if ($this->data['type_id']) { $this->data['type_id'] = array_map('intval', $this->data['type_id']); } waRequest::setParam($route); $this->data['base_url'] = parse_url('http://' . preg_replace('@https?://@', '', $domain), PHP_URL_HOST); $success = true; break; } } } if (!$success) { throw new waException('Error while select routing'); } $app_settings_model = new waAppSettingsModel(); $this->data['app_settings'] = array('ignore_stock_count' => $app_settings_model->get($app_id, 'ignore_stock_count', 0)); }
public function execute() { $this->init(); $type = waRequest::param('type'); $this->hash = waRequest::param('hash'); if ($type == 'tag') { $this->view->assign('criteria', 'by-tag'); $this->view->assign('tag', waRequest::param('tag')); } else { if ($type == 'favorites') { $this->view->assign('criteria', 'favorites'); } } if (in_array($type, array('author', 'search', 'tag', 'favorites', 'id'))) { waRequest::setParam('disable_sidebar', true); $template = 'search.html'; } else { $template = 'home.html'; if (!file_exists($this->getTheme()->getPath() . '/' . $template)) { $template = 'view-thumbs.html'; // for backward compatibility reason } } if ($type != 'all' && $type != 'favorites') { waRequest::setParam('nofollow', true); } $layout = $this->getLayout(); if ($layout) { $layout->assign('hash', $this->hash); } $this->setThemeTemplate($template); $this->finite(); }
public function execute() { $this->init(); $url = trim(waRequest::param('url', '', waRequest::TYPE_STRING_TRIM), '/'); if (!$url) { throw new waException(_w('Page not found', 404)); } $this->route($url); if (!$this->album) { throw new waException(_w('Page not found', 404)); } $this->album = photosFrontendAlbum::escapeFields($this->album); // retrieve user params $album_params_model = new photosAlbumParamsModel(); $params = $album_params_model->get($this->album['id']); $params = photosPhoto::escape($params); $this->album += $params; // "childcrumbs" - list of childs (sub-albums). Use in 'plain' template $childcrumbs = $this->album_model->getChildcrumbs($this->album['id'], true); waRequest::setParam('breadcrumbs', $this->album_model->getBreadcrumbs($this->album['id'], true)); waRequest::setParam('nofollow', $this->album['status'] <= 0 ? true : false); waRequest::setParam('disable_sidebar', true); $this->setThemeTemplate('album.html'); $this->view->assign('album', $this->album); $this->view->assign('childcrumbs', $childcrumbs); $this->getResponse()->addJs('js/common.js?v=' . wa()->getVersion(), true); $this->finite(); }
public function execute() { $url = waRequest::param('url'); $this->album = waRequest::param('album'); $this->hash = waRequest::param('hash'); if (!$url) { throw new waException(_w('Page not found', 404)); } $this->photo_model = new photosPhotoModel(); $this->photo = $this->getPhoto($url); if (!$this->photo) { throw new waException(_w('Page not found'), 404); } $this->photo = photosPhoto::escapeFields($this->photo); if ($this->album && $this->album['status'] <= 0) { $this->album['full_url'] = photosCollection::frontendAlbumHashToUrl($this->hash); } // delegate work to special render helper $render_helper = new photosPhotoRenderHelper($this->photo, $this->private_hash); $result = $render_helper->workUp(array('album' => $this->album, 'hash' => $this->hash)); waRequest::setParam('title', $this->photo['name']); waRequest::setParam('nofollow', $this->isNeedNofollow()); waRequest::setParam('breadcrumbs', $this->getBreadcrumbs()); waRequest::setParam('disable_sidebar', true); // pull out work's up result $this->view->assign('photo', $result['photo']); $this->view->assign('albums', $result['blocks']['albums']); $this->view->assign('tags', $result['blocks']['tags']); $this->view->assign('exif', $result['blocks']['exif']); $this->view->assign('author', $result['blocks']['author']); $this->view->assign('stack_nav', $result['blocks']['stack_nav']); $this->view->assign('photo_stream', $result['blocks']['photo_stream']); // if we are not in album, than $album is null $this->view->assign('album', $this->album); /** * Add extra widgets to photo page * @event frontend_photo * @param string[array]mixed $photo photo data * @return array[string][string]string $return[%plugin_id%]['bottom'] In bottom, under photo - any widget * @return array[string][string]string $return[%plugin_id%]['sidebar'] * @return array[string][string]string $return[%plugin_id%]['top_left'] * @return array[string][string]string $return[%plugin_id%]['top_right'] */ $this->view->assign('frontend_photo', wa()->event('frontend_photo', $this->photo)); $version = wa()->getVersion(); $this->getResponse()->addJs('js/common.js?v=' . $version, true); $this->getResponse()->addJs('js/photo.stream.slider.js?v=' . $version, true); $this->getResponse()->addJs('js/frontend.photo.js?v=' . $version, true); }
/** * * @param $params array * @return array */ protected function castParams($params = array()) { waRequest::setParam($params); foreach ($this->params_definition as $param => $definition) { if (isset($definition['required']) && $definition['required']) { if (!isset($params[$param])) { throw new waApiException(100, sprintf('Param %s are required', $param)); } } $type = isset($definition['type']) && $definition['type'] ? $definition['type'] : null; $default = isset($definition['default']) ? $definition['default'] : false; waRequest::setParam($param, waRequest::param($param, $default, $type)); } return waRequest::param(); }
public function catalogAction() { /** * @var shopYandexmarketPlugin $plugin */ $plugin = wa()->getPlugin('yandexmarket'); $profile_helper = new shopImportexportHelper('yandexmarket'); list($path, $profile_id) = $plugin->getInfoByHash(waRequest::param('hash')); if ($profile_id) { $profile = $profile_helper->getConfig($profile_id); if (!$profile) { throw new waException('Profile not found', 404); } $lifetime = ifset($profile['config']['lifetime'], 0); if ($lifetime && (!file_exists($path) || time() - filemtime($path) > $lifetime)) { waRequest::setParam('profile_id', $profile_id); $runner = new shopYandexmarketPluginRunController(); $_POST['processId'] = null; $moved = false; $ready = false; do { ob_start(); if (empty($_POST['processId'])) { $_POST['processId'] = $runner->processId; } else { sleep(1); } if ($ready) { $_POST['cleanup'] = true; $moved = true; } $runner->execute(); $out = ob_get_clean(); $result = json_decode($out, true); $ready = !empty($result) && is_array($result) && ifempty($result['ready']); } while (!$ready || !$moved); //TODO check errors } } waFiles::readFile($path, waRequest::get('download') ? 'yandexmarket.xml' : null); }
/** * @param $params * @param $smarty * @return string|void */ function smarty_function_wa_action($params, &$smarty) { $current_app = waSystem::getInstance()->getApp(); $app = $params['app']; waSystem::getInstance($app)->setActive($app); if (isset($params['action'])) { $type = 'action'; $class_name = $app . ucfirst($params['module']) . ucfirst($params['action']) . 'Action'; } elseif (isset($params['controller'])) { $type = 'controller'; $class_name = $app . ucfirst($params['module']) . ucfirst($params['controller']) . 'Controller'; } $var = isset($params['var']) ? $params['var'] : false; if ($var) { unset($params['var']); } unset($params['app']); unset($params['module']); unset($params['action']); foreach ($params as $key => $value) { waRequest::setParam($key, $value); } $result = ''; try { if ($type == 'action') { $action = new $class_name(); $result = $action->display(); } elseif ($type == 'controller') { $controller = new $class_name(); $result = $controller->execute(); } } catch (Exception $e) { $result = $e->getMessage(); } waSystem::setActive($current_app); if ($var) { $smarty->assign($var, $result); } else { return $result; } }
public function finite() { $collection = new photosCollection($this->hash); $photos = $collection->getPhotos("*,thumb,frontend_link,tags", $this->offset, $this->photos_per_page); $photos = photosCollection::extendPhotos($photos); if ($this->hash) { $title = photosPhoto::escape($collection->getTitle()); waRequest::setParam('title', $title); $this->view->assign('title', $title); } else { $this->view->assign('title', ''); } $this->workupPhotos($photos); $total_count = $collection->count(); $this->view->assign('photos_per_page', $this->photos_per_page); $this->view->assign('pages_count', floor($total_count / $this->photos_per_page) + 1); $this->view->assign('total_photos_count', $total_count); $this->view->assign('offset', $this->offset); $this->view->assign('photos', $photos); $is_xhr = waRequest::isXMLHttpRequest(); $this->view->assign('is_xhr', $is_xhr); if ($is_xhr) { $this->view->assign('frontend_collection', array()); } else { /** * @event frontend_collection * @return array[string][string]string $return[%plugin_id%]['name'] Extra name info * @return array[string][string]string $return[%plugin_id%]['content'] Extra album description and etc * @return array[string][string]string $return[%plugin_id%]['footer'] Footer section * @return array[string][string]string $return[%plugin_id%]['sidebar'] Footer section * @return array[string][string]string $return[%plugin_id%]['footer'] Footer section */ $this->view->assign('frontend_collection', wa()->event('frontend_collection')); } $this->view->assign('lazy_load', !is_null(waRequest::get('lazy'))); $v = wa()->getVersion(); $this->getResponse()->addJs('js/lazy.load.js?v=' . $v, true); $this->getResponse()->addJs('js/frontend.photos.js?v=' . $v, true); }
public function execute() { if (waRequest::param('url_type') == 2) { $product_model = new shopProductModel(); if (waRequest::param('category_url')) { $category_model = new shopCategoryModel(); $c = $category_model->getByField('full_url', waRequest::param('category_url')); if ($c) { $product = $product_model->getByUrl(waRequest::param('product_url'), $c['id']); if ($product && $product['category_id'] != $c['id']) { $c = $category_model->getById($product['category_id']); if ($c) { $this->redirect(wa()->getRouteUrl('shop/frontend/product', array('category_url' => $c['full_url'], 'product_url' => $product['url']))); } else { $product = null; } } } else { $product = null; } } else { $product = $product_model->getByField('url', waRequest::param('product_url')); } if (!$product) { // try find page $url = waRequest::param('category_url'); $url_parts = explode('/', $url); waRequest::setParam('page_url', waRequest::param('product_url')); waRequest::setParam('product_url', end($url_parts)); $this->executeAction(new shopFrontendProductPageAction()); } else { $this->executeAction(new shopFrontendProductAction($product)); } } else { $this->executeAction(new shopFrontendProductAction()); } }
/** * @return array * array( * 'shop' => 'shop my nav html...', * 'helpdesk' => 'helpdesk my nav html...', * ... * ) */ public function myNav($ul_class = true) { $domain = wa()->getRouting()->getDomain(null, true); $domain_config_path = wa()->getConfig()->getConfigPath('domains/' . $domain . '.php', true, 'site'); if (file_exists($domain_config_path)) { $domain_config = (include $domain_config_path); } else { $domain_config = array(); } $routes = wa()->getRouting()->getRoutes(); $apps = wa()->getApps(); $result = array(); foreach ($routes as $r) { if (isset($r['app']) && !empty($apps[$r['app']]['my_account'])) { $result[$r['app']] = $r; } } if (isset($domain_config['personal'])) { $tmp = array(); foreach ($domain_config['personal'] as $app_id => $enabled) { if (!isset($result[$app_id])) { continue; } if ($enabled) { $tmp[$app_id] = $result[$app_id]; } else { unset($result[$app_id]); } } foreach ($result as $app_id => $r) { $tmp[$app_id] = $r; } $result = array_reverse($tmp, true); } $old_app = wa()->getApp(); $my_nav_selected = $this->view->getVars('my_nav_selected'); $old_params = waRequest::param(); $i = 0; foreach ($result as $app_id => $r) { unset($r['url']); unset($r['app']); if ($i || $old_app != $app_id) { waSystem::getInstance($app_id, null, true); waRequest::setParam($r); } $class_name = $app_id . 'MyNavAction'; if (class_exists($class_name)) { /** * @var waViewAction $action */ try { $action = new $class_name(); wa()->getView()->assign('my_nav_selected', $app_id == $old_app ? $my_nav_selected : ''); $result[$app_id] = $action->display(); } catch (Exception $e) { unset($result[$app_id]); } } else { unset($result[$app_id]); } $i++; } if (isset($app_id) && $old_app != $app_id) { waRequest::setParam($old_params); wa()->setActive($old_app); } $result = array_reverse($result, true); if ($ul_class) { $html = '<ul' . (is_string($ul_class) ? ' class="' . $ul_class . '"' : '') . '>'; foreach ($result as $app_result) { $html .= $app_result; } $html .= '</ul>'; return $html; } else { return $result; } }
public function execute() { $routing = wa()->getRouting(); $settlements = array(); $profile_helper = new shopImportexportHelper($this->plugin_id); $this->view->assign('profiles', $list = $profile_helper->getList()); $profile = $profile_helper->getConfig(); $profile['config'] += array('hash' => '', 'domain' => '', 'lifetime' => 0); $current_domain =& $profile['config']['domain']; $this->view->assign('current_domain', $current_domain); $domain_routes = $routing->getByApp('shop'); foreach ($domain_routes as $domain => $routes) { foreach ($routes as $route) { $settlement = $domain . '/' . $route['url']; if ($settlement == $current_domain || $current_domain === '') { $current_domain = $settlement; $routing->setRoute($route, $domain); waRequest::setParam($route); } $settlements[] = $settlement; } } $this->view->assign('profile', $profile); $info = array(); $this->view->assign('settlements', $settlements); if (!empty($profile['id'])) { $path = shopYandexmarketPlugin::path($profile['id'] . '.xml'); $info['exists'] = file_exists($path); $info['mtime'] = $info['exists'] ? filemtime($path) : null; } else { $info['mtime'] = $info['exists'] = null; } if ($info['exists']) { $route_params = array('plugin' => $this->plugin_id, 'hash' => $this->plugin()->getHash($profile['id'])); $info['url'] = $routing->getUrl('shop/frontend/catalog', $route_params, true); } else { $info['url'] = null; } $this->view->assign('info', $info); /** * @var shopConfig $config ; */ $config = wa('shop')->getConfig(); $this->view->assign('primary_currency', $config->getCurrency()); $this->view->assign('company', ifempty($profile['config']['company'], $config->getGeneralSettings('name'))); $this->view->assign('company_name', ifempty($profile['config']['company_name'], $config->getGeneralSettings('name'))); $type_model = new shopTypeModel(); $this->view->assign('types', $type_model->getAll()); $profile_map = ifset($profile['config']['map'], array()); $export = ifset($profile['config']['export'], array()); $set_model = new shopSetModel(); $map = $this->plugin()->map(array(), null, true); $params = array(); if ($profile_map) { foreach ($map as $type => &$type_map) { foreach ($type_map['fields'] as $field => &$info) { $info['source'] = ifempty($profile_map[$type][$field], 'skip:'); unset($profile_map[$type][$field]); unset($info); } if (!empty($type_map['fields']['param.*'])) { $params[$type] = -1; } unset($type_map); } foreach ($profile_map as $type => $fields) { foreach ($fields as $field => $source) { $info_field = strpos($field, 'param.') === 0 ? 'param.*' : $field; if (isset($map[$type]['fields'][$info_field])) { $info = $map[$type]['fields'][$info_field]; $info['source'] = ifempty($source, 'skip:'); $map[$type]['fields'][$field] = $info; $params[$type] = max(ifset($params[$type], -1), intval(preg_replace('@\\D+@', '', $field))); } } } } $this->view->assign('sets', $set_model->getAll()); $this->view->assign('type_map', $map); $this->view->assign('params', array('params' => $params)); $this->view->assign('export', $export); $this->view->assign('types_map', ifset($profile['config']['types'], array())); $app_settings_model = new waAppSettingsModel(); $app_settings = array('ignore_stock_count' => $app_settings_model->get('shop', 'ignore_stock_count', 0)); $this->view->assign('app_settings', $app_settings); $feature_model = new shopFeatureModel(); $config = wa('shop')->getConfig(); /** * @var shopConfig $config */ $limit = $config->getOption('features_per_page'); if ($feature_model->countByField(array('parent_id' => null)) < $limit) { $features = $feature_model->getFeatures(true); /*, true*/ foreach ($features as $id => $feature) { if ($feature['type'] == shopFeatureModel::TYPE_DIVIDER) { unset($features[$id]); } } } else { $this->view->assign('features_autocomplete', true); $features = array(); foreach ($map as $type_map) { foreach ($type_map['fields'] as $info) { if (!empty($info['source']) && preg_match('@^feature:([\\w\\d_\\-]+)$@', $info['source'], $matches)) { $features[] = $matches[1]; } } } if ($features = array_unique($features)) { $features = $feature_model->getFeatures('code', $features); } else { $features = array(); } } foreach ($features as $id => &$feature) { if (strpos($feature['type'], shopFeatureModel::TYPE_DIMENSION . '.') === 0) { $units = shopDimension::getUnits($feature['type']); $feature['units'] = array(); foreach ($units as $unit) { $feature['units'][] = $unit['title']; } $feature['units'] = implode(', ', $feature['units']); } elseif (preg_match('@\\(([^\\)]+)\\)$@', $feature['name'], $matches)) { $feature['units'] = trim($matches[1]); } unset($feature); } $this->view->assign('features', $features); $fields = array('name' => _w('Product name'), 'description' => _w('Description'), 'summary' => _w('Summary'), 'count' => _w('In stock'), 'sku' => _w('SKU code')); $this->view->assign('fields', $fields); }
protected function dispatchRoutes($routes, $url) { $result = null; foreach ($routes as $r) { if ($this->route && isset($this->route['module']) && (!isset($r['module']) || $r['module'] != $this->route['module'])) { continue; } $vars = array(); $pattern = str_replace(array(' ', '.', '('), array('\\s', '\\.', '(?:'), $r['url']); $pattern = preg_replace('/(^|[^\\.])\\*/ui', '$1.*?', $pattern); if (preg_match_all('/<([a-z_]+):?([^>]*)?>/ui', $pattern, $match, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { $offset = 0; foreach ($match as $m) { $vars[] = $m[1][0]; if ($m[2][0]) { $p = $m[2][0]; } else { $p = '.*?'; } $pattern = substr($pattern, 0, $offset + $m[0][1]) . '(' . $p . ')' . substr($pattern, $offset + $m[0][1] + strlen($m[0][0])); $offset = $offset + strlen($p) + 2 - strlen($m[0][0]); } } if (preg_match('!^' . $pattern . '$!ui', $url, $match)) { if (isset($r['redirect'])) { $p = str_replace('.*?', '(.*?)', $pattern); if ($p != $pattern) { preg_match('!^' . $p . '$!ui', $url, $m); if (isset($m[1])) { $r['redirect'] = str_replace('*', $m[1], $r['redirect']); if (waRequest::server('QUERY_STRING')) { $r['redirect'] .= '?' . waRequest::server('QUERY_STRING'); } } } wa()->getResponse()->redirect($r['redirect'], 301); } if ($vars) { array_shift($match); foreach ($vars as $i => $v) { if (isset($match[$i]) && !waRequest::param($v)) { waRequest::setParam($v, $match[$i]); } } } foreach ($r as $k => $v) { if ($k !== 'url') { waRequest::setParam($k, $v); } } $result = $r; break; } } return $result; }
public function execute($plugin = null, $module = null, $action = null, $default = false) { if (!$plugin && $module == 'frontend') { try { if (!waRequest::param('page_id')) { $request_url = parse_url($this->system->getRootUrl() . $this->system->getConfig()->getRequestUrl()); if (isset($request_url['path']) && $request_url['path'] && substr($request_url['path'], -1) != '/') { $request_url['path'] .= '/'; $this->system->getResponse()->redirect(implode('', $request_url), 301); } } #parse request URL $params = waRequest::param(); #determine blog ID which are dependent on routing settings $blog_model = new blogBlogModel(); $blogs = array(); $params['blog_url_type'] = waRequest::param('blog_url_type', 0, waRequest::TYPE_INT); if (!($title = waRequest::param('title'))) { $title = wa()->accountName(); } $blog_url = waRequest::param('blog_url', '', waRequest::TYPE_STRING_TRIM); $main_page = false; if ($params['blog_url_type'] > 0) { if ($blog = $blog_model->getByField(array('id' => $params['blog_url_type'], 'status' => blogBlogModel::STATUS_PUBLIC))) { $blogs[] = $blog; $main_page = true; } } elseif (strlen($blog_url)) { if ($blog = $blog_model->getBySlug($blog_url, true, array('id', 'name', 'url'))) { $blogs[] = $blog; } } else { $blogs = blogHelper::getAvailable(); if (!isset($params['post_url'])) { if (count($blogs) > 1 || $params['blog_url_type'] == 0) { $main_page = true; } } } if ($blogs) { if (count($blogs) == 1 && ($params['blog_url_type'] != 0 || strlen($blog_url))) { $blog = reset($blogs); $params['blog_id'] = intval($blog['id']); $params['blog_url'] = $blog['url']; if (!$main_page) { $routing = wa()->getRouting(); if ($params['blog_id'] != $routing->getRouteParam('blog_url_type') || isset($params['post_url'])) { $title = $blog['name']; } elseif (!$title) { $title = $blog['name']; } } } else { $params['blog_id'] = array_map('intval', array_keys($blogs)); } } else { throw new waException(_w('Blog not found'), 404); } wa()->getResponse()->setTitle($title); if ($main_page) { wa()->getResponse()->setMeta('keywords', waRequest::param('meta_keywords')); wa()->getResponse()->setMeta('description', waRequest::param('meta_description')); } waRequest::setParam($params); parent::execute($plugin, $module, $action, $default); } catch (Exception $e) { waRequest::setParam('exception', $e); parent::execute(null, 'frontend', 'error'); } } else { parent::execute($plugin, $module, $action, $default); } }
public function execute($plugin = null, $module = null, $action = null, $default = false) { try { if (!waRequest::param('page_id')) { if (!waRequest::isXMLHttpRequest()) { $request_url = parse_url($this->system->getRootUrl() . $this->system->getConfig()->getRequestUrl()); if (!empty($request_url['path']) && empty($request_url['query']) && substr($request_url['path'], -1) != '/') { $request_url['path'] .= '/'; $this->system->getResponse()->redirect(implode('', $request_url), 301); } } } if ($module == 'frontend' && $action != 'album') { // request params $id = waRequest::param('id', '', waRequest::TYPE_STRING_TRIM); $tag = waRequest::param('tag', '', waRequest::TYPE_STRING_TRIM); $author = waRequest::param('author', '', waRequest::TYPE_INT); $search = waRequest::param('search', '', waRequest::TYPE_STRING_TRIM); $favorites = waRequest::param('favorites', '', waRequest::TYPE_STRING_TRIM); $url = waRequest::param('url', '', waRequest::TYPE_STRING_TRIM); $type = 'all'; $hash = ''; $album = null; if ($author) { $hash = 'author/' . $author; $type = 'author'; } else { if ($search) { $hash = 'search/' . $search; $type = 'search'; } else { if ($id) { $hash = 'id/' . $id; $type = 'id'; } else { if ($tag) { $hash = 'tag/' . $tag; $type = 'tag'; } else { if ($favorites) { $hash = 'favorites'; $type = 'favorites'; } else { if ($url) { if (preg_match('/^([^\\s]+)\\/([^\\s\\/]+)/', trim($url, '/'), $m)) { $album_url = $m[1]; $url = $m[2]; $hash = photosCollection::frontendAlbumUrlToHash($album_url, $album); if (!$album) { throw new waException(_w('Page not found'), 404); } $type = 'album'; } } } } } } } $url = rtrim($url, '/'); waRequest::setParam('url', $url); waRequest::setParam('album', $album); waRequest::setParam('hash', $hash); waRequest::setParam('type', $type); } parent::execute($plugin, $module, $action, $default); } catch (Exception $e) { if ($module == 'frontend') { $action = new photosFrontendErrorAction($e); $action->display(); } else { throw $e; } } }
protected function dispatchRoutes($routes, $url) { $result = null; foreach ($routes as $r) { if ($this->route && isset($this->route['module']) && (!isset($r['module']) || $r['module'] != $this->route['module'])) { continue; } $vars = array(); $pattern = str_replace(array(' ', '.', '('), array('\\s', '\\.', '(?:'), $r['url']); $pattern = preg_replace('/(^|[^\\.])\\*/ui', '$1.*?', $pattern); if (preg_match_all('/<([a-z_]+):?([^>]*)?>/ui', $pattern, $match, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { $offset = 0; foreach ($match as $m) { $vars[] = $m[1][0]; if ($m[2][0]) { $p = $m[2][0]; } else { $p = '.*?'; } $pattern = substr($pattern, 0, $offset + $m[0][1]) . '(' . $p . ')' . substr($pattern, $offset + $m[0][1] + strlen($m[0][0])); $offset = $offset + strlen($p) + 2 - strlen($m[0][0]); } } if (preg_match('!^' . $pattern . '$!ui', $url, $match)) { if (isset($r['redirect'])) { $p = str_replace('.*?', '(.*?)', $pattern); if ($p != $pattern) { preg_match('!^' . $p . '$!ui', $url, $m); if (isset($m[1])) { $r['redirect'] = str_replace('*', $m[1], $r['redirect']); } } header("Location: " . $r['redirect']); exit; } if ($vars) { array_shift($match); foreach ($vars as $i => $v) { if (isset($match[$i]) && !waRequest::param($v)) { waRequest::setParam($v, $match[$i]); } } } foreach ($r as $k => $v) { if ($k !== 'url') { waRequest::setParam($k, $v); } } $result = $r; break; } } // Default routing via GET parameters if (waRequest::param('module') === null && ($module = waRequest::get('module'))) { waRequest::setParam('module', $module); } if (waRequest::param('action') === null && ($action = waRequest::get('action'))) { waRequest::setParam('action', $action); } if (waRequest::param('plugin') === null && ($plugin = waRequest::get('plugin'))) { waRequest::setParam('plugin', $plugin); } return $result; }
public function dispatchCli($argv) { $params = array(); $app = $argv[1]; $class = $app . ucfirst($argv[2]) . "Cli"; $argv = array_slice($argv, 3); while ($arg = array_shift($argv)) { if (mb_substr($arg, 0, 2) == '--') { $key = mb_substr($arg, 2); } else { if (mb_substr($arg, 0, 1) == '-') { $key = mb_substr($arg, 1); } else { $params[] = $arg; continue; } } $params[$key] = trim(array_shift($argv)); } waRequest::setParam($params); // Load system waSystem::getInstance('webasyst'); // Load app waSystem::getInstance($app, null, true); if (class_exists($class)) { /** * @var $cli waCliController */ $cli = new $class(); $cli->run(); } else { throw new waException("Class " . $class . " not found", 404); } }
private function checkCode() { $result = true; $info = array('functions' => array(), 'classes' => array(), 'vars' => array()); $variables_blacklist = array('^\\$_(POST|GET|REQUEST|COOKIE|SERVER)^' => 'Use waRequest or waStorage classes'); foreach ($this->files as $file) { if (pathinfo($file, PATHINFO_EXTENSION) == 'php') { $tokens = token_get_all(file_get_contents($this->path . '/' . $file)); foreach ($tokens as $id => $token) { if (is_array($token)) { switch ($token[0]) { case T_CLASS: $next_id = $id; do { $next = ifset($tokens[++$next_id]); } while (ifset($next[0]) != T_STRING); if (!isset($info['classes'][$next[1]])) { $info['classes'][$next[1]] = array(); } $info['classes'][$next[1]][] = $file; break; case T_STRING_VARNAME: case T_VARIABLE: foreach ($variables_blacklist as $pattern => $description) { if (preg_match($pattern, $token[1])) { $result = false; $this->tracef("Not allowed variable %s at %s:%d\n\t%s", $token[1], $file, $token[2], $description); } } break; case T_STRING: if (function_exists($token[1])) { if (!isset($info['functions'][$token[1]])) { $info['functions'][$token[1]] = array(); } $info['functions'][$token[1]][] = $file; $info['functions'][$token[1]] = array_unique($info['functions'][$token[1]]); } break; case T_EVAL: case T_EXIT: $this->tracef("Not allowed function %s at %s:%s", $token[1], $file, $token[2]); $result = false; break; case T_OPEN_TAG: if ($token[1] == '<?') { $result = false; $this->tracef("PHP short open tag not allowed at %s:%d", $file, $token[2]); } break; case T_CLOSE_TAG: $this->tracef("PHP closing tag not required at %s:%d", $file, $token[2]); break; } } } } } # 3. Check namespaces # 3.1 File names # 3.2 Class names switch ($this->type) { case 'plugin': $pattern = "@^" . waRequest::param('prefix', $this->app_id . ucfirst($this->extension_id)) . "\\w*\$@"; break; case 'app': $pattern = "@^{$this->app_id}\\w+\$@"; break; default: $pattern = null; break; } if ($pattern) { foreach ($info['classes'] as $class => $files) { if (!preg_match($pattern, $class)) { $result = false; $this->tracef("Invalid class name %s at %s", $class, implode(', ', $files)); } else { //verify file name for class } } } $functions_blacklist = array('@^mysqli?_\\.+@' => 'Use waModel instead', '@^call_user_func(_array)?$@' => 'Bad practice', '@^eregi?(_replace)$@' => 'Deprecated, use preg/preg_replace', '@^spliti?$@' => 'Deprecated, use explode'); foreach ($info['functions'] as $function => $files) { foreach ($functions_blacklist as $pattern => $description) { if (preg_match($pattern, $function)) { $this->tracef("Function %s not allowed\n\tHint:%s", $function, $description); $result = false; } } } $extensions = array(); if ($requirements = $this->getItemConfig('requirements')) { foreach ($requirements as $requirement => $requirement_info) { if (preg_match('@^php\\.(.+)$@', $requirement, $matches)) { $extensions[$matches[1]] = ifset($requirement_info['strict']); } } } waRequest::setParam('extensions', $extensions); $extensions = get_loaded_extensions(); $extensions = array_diff($extensions, array('standard', 'SPL', 'iconv', 'date', 'gettext', 'mbstring', 'mysql', 'mysqli', 'tokenizer')); $functions = array(); foreach ($extensions as $extension) { if ($extension_functions = get_extension_funcs($extension)) { foreach ($extension_functions as $function) { $functions[$function] = $extension; } } } return $result; }