public function route($url = null, $context = null) { if ($url instanceof \Floxim\Main\Page\Entity) { $url = fx::collection(array($url)); } if ($url instanceof \Floxim\Floxim\System\Collection) { $path = $url; $url = $path->last()->get('url'); } else { $url = preg_replace("~^/~", '', $url); $path = $this->getPath($url, $context['site_id']); if (!$path) { return; } } $page = $path->last(); if (!$page) { return null; } else { $url = preg_replace("~\\?.+\$~", '', $url); if ($url && !$page->hasVirtualPath() && urldecode($url) != $page['url'] && $page['url'] !== '404/') { fx::http()->redirect($page['url'], 301); fx::debug($url, '!=', $page['url']); die; } } fx::env('page', $page); fx::http()->status('200'); $layout_ib = $this->getLayoutInfoblock($page); fx::trigger('before_layout_render', array('layout_infoblock' => $layout_ib)); $res = $layout_ib->render(); return $res; }
public function route($url = null, $context = null) { $site_id = isset($context['site_id']) ? $context['site_id'] : fx::env('site'); $error_page = $this->getErrorPage($site_id); $ctr = fx::router('front')->route($error_page['url'], $context); fx::http()->status('404'); return $ctr; }
public function route($url = null, $context = null) { if (!fx::isAdmin()) { return null; } if (!preg_match("~^/\\~ib/(\\d+|fake(?:\\-\\d+)?)@(\\d+)~", $url, $ib_info)) { return null; } $c_url = fx::input()->fetchGetPost('_ajax_base_url'); if ($c_url) { $_SERVER['REQUEST_URI'] = $c_url; $path = fx::router()->getPath(fx::path()->removeBase($c_url)); if ($path) { fx::env('page', $path->last()); } else { fx::env('page', fx::router('error')->getErrorPage()); } $c_url = parse_url($c_url); if (isset($c_url['query'])) { parse_str($c_url['query'], $_GET); } } $ib_id = $ib_info[1]; $page_id = $ib_info[2]; if (!fx::env('page') && $page_id) { $page = fx::data('floxim.main.content', $page_id); fx::env('page', $page); } fx::env('ajax', true); $page_infoblocks = fx::router('front')->getPageInfoblocks($page_id, fx::env('layout')); fx::page()->setInfoblocks($page_infoblocks); // import layout template to recreate real env fx::router('front')->importLayoutTemplate(); // front end can try to reload the layout which is out of date // when updating from "layout settings" panel $infoblock = fx::data('infoblock', $ib_id); if (!$infoblock && isset($_POST['infoblock_is_layout']) || $infoblock->isLayout()) { //$infoblock = $layout_infoblock; $infoblock = fx::router('front')->getLayoutInfoblock(fx::env('page')); } fx::http()->status('200'); $infoblock_overs = null; if (fx::isAdmin() && isset($_POST['override_infoblock'])) { $infoblock_overs = fx::input('post', 'override_infoblock'); if (is_string($infoblock_overs)) { parse_str($infoblock_overs, $infoblock_overs); $infoblock_overs = fx::input()->prepareSuperglobal($infoblock_overs); } $infoblock->override($infoblock_overs); } $infoblock->overrideParam('ajax_mode', true); $res = $infoblock->render(); return $res; }
public function uploadSave($input) { $path = 'upload'; $result = fx::files()->saveFile($input['file'], $path); if (!$result) { $result = array('error_message' => 'Can not load this file'); fx::http()->status(500); } if (isset($input['format']) && !empty($input['format']) && isset($result['path'])) { $result['formatted_value'] = fx::image($result['path'], $input['format']); } return $result; }
public function doAdd() { if (isset($_POST["addcomment"]) && isset($_POST["user_name"]) && !empty($_POST["user_name"]) && isset($_POST["comment_text"]) && !empty($_POST["comment_text"])) { $comments = fx::data('comment')->create(array('user_name' => $_POST["user_name"], 'comment_text' => $_POST["comment_text"], 'publish_date' => date("Y-m-d H:i:s"), 'parent_id' => $this->getParentId(), 'infoblock_id' => $this->getParam('target_infoblock_id'))); $comments->save(); if (!isset($_COOKIE["own_comments"])) { setcookie('own_comments', $comments["id"], time() + 60 * 60 * 24 * 30); } else { setcookie('own_comments', $_COOKIE["own_comments"] . ',' . $comments["id"], time() + 60 * 60 * 24 * 30); } fx::http()->refresh(); } }
public function route($url = null, $context = null) { $adm_path = '/' . fx::config('path.admin_dir_name') . '/'; if (trim($url, '/') === trim($adm_path, '/') && $url !== $adm_path) { fx::http()->redirect(fx::config('paht.admin'), 301); } if ($url !== $adm_path) { return null; } $input = fx::input()->makeInput(); $entity = fx::input()->fetchPost('entity'); $action = fx::input()->fetchPost('action'); if (!$entity || !$action) { fx::page()->setBaseUrl(FX_BASE_URL . '/' . trim($adm_path, '/')); return new Controller\Admin(); } $base_url = fx::input()->fetchPost('_base_url'); if ($base_url) { $base_path = fx::router()->getPath(fx::path()->removeBase($base_url)); if ($base_path) { fx::env('page', $base_path->last()); } } fx::env('ajax', true); $posting = fx::input()->fetchPost('posting'); if (!preg_match("~^module_~", $entity) || fx::input()->fetchPost('fx_admin')) { $entity = 'admin_' . $entity; } if ($posting && $posting !== 'false') { $action .= "_save"; } $path = explode('_', $entity, 2); if ($path[0] == 'admin') { $classname = 'Floxim\\Floxim\\Admin\\Controller\\' . fx::util()->underscoreToCamel($path[1]); } else { // todo: psr0 what? } try { $controller = new $classname($input, $action); } catch (\Exception $e) { die("Error! Entity: " . htmlspecialchars($entity)); } //header("Content-type: application/json; charset=utf-8"); return $controller; }
public function route($url = null, $context = null) { $path = fx::router()->getPath($url, $context['site_id']); if (!$path) { return; } $page = $path->last(); if (!$page) { return null; } else { $url = preg_replace("~\\?.+\$~", '', $url); if ($url && !$page->hasVirtualPath() && urldecode($url) != $page['url'] && $page['url'] !== '/404/') { fx::http()->redirect($page['url'], 301); exit; } } fx::env('page', $page); fx::http()->status('200'); $layout_ib = $this->getLayoutInfoblock($page); fx::trigger('before_layout_render', array('layout_infoblock' => $layout_ib)); $res = $layout_ib->render(); return $res; }
public function doFormCreate() { $user = fx::env('user'); $item = $this->getFinder()->create(); $form = $this->initDataForm('create'); $target_infoblock = $this->getParam('target_infoblock'); $item['infoblock_id'] = $target_infoblock; if (!$user->can('see_create_form', $item)) { return false; } $this->assign('form', $form); $this->assign('item', $item); $fields = $item->getFormFields(); $form->addFields($fields); $this->trigger('form_ready', array('form' => $form, 'action' => 'create')); if ($form->isSent() && !$form->hasErrors()) { if ($user->can('create', $item)) { $this->trigger('form_sent', array('form' => $form, 'action' => 'create')); $item->loadFromForm($form); if ($item->validateWithForm()) { $item->save(); $this->trigger('form_completed', array('form' => $form, 'action' => 'create', 'entity' => $item)); if (fx::env('ajax')) { $form->finish(); return; } $target_type = $this->getParam('redirect_to'); switch ($target_type) { case 'refresh': fx::http()->refresh(); break; case 'new_page': fx::http()->redirect($item['url']); break; case 'parent_page': fx::http()->redirect($item['parent']['url']); break; } } else { $form->addError(fx::alang('Unable to save ', 'controller_component') . $item['component']->getItemName('add')); } } else { $form->addError('Permission denied'); } } }
public function doLogout() { $user = fx::user(); $user->logout(); $back_url = $this->getParam('back_url', '@home/'); fx::http()->redirect($back_url, 302); }