/** * Show form to authorize user on all sites */ public function doCrossSiteAuthForm() { if (!preg_match("~/\\~ajax~", $_SERVER['REQUEST_URI'])) { return false; } if (!fx::user()->isAdmin()) { fx::http()->redirect('@home'); } $sites = fx::data('site')->all(); $hosts = array(); foreach ($sites as $site) { foreach ($site->getAllHosts() as $host) { if ($host === fx::env('host')) { continue; } $hosts[] = $host; } } fx::env('ajax', false); $target_location = fx::input()->fetchCookie('fx_target_location'); // unset cookie fx::input()->setCookie('fx_target_location', '', 1); if (!$target_location) { $target_location = '/'; } if (count($hosts) === 0) { fx::http()->redirect($target_location); } return array('hosts' => $hosts, 'auth_url' => fx::path()->http('@home/~ajax/floxim.user.user:cross_site_auth'), 'target_location' => $target_location, 'session_key' => fx::data('session')->load()->get('session_key')); }
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 stop() { $session_key = fx::input()->fetchCookie($this->cookie_name); if (!$session_key) { return; } $this->setCookie(null, null); $session = $this->getByKey($session_key); if (!$session) { return; } $session->delete(); }
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 addSave($input) { $result = array(); $site = fx::data('site')->create(array('name' => $input['name'], 'domain' => $input['domain'], 'layout_id' => $input['layout_id'], 'mirrors' => $input['mirrors'], 'language' => $input['language'], 'checked' => 1)); if (!$site->validate()) { $result['status'] = 'error'; $result['errors'] = $site->getValidateErrors(); return $result; } $site->save(); $index_page = fx::data('page')->create(array('name' => fx::alang('Cover Page', 'system'), 'url' => '/', 'site_id' => $site['id']))->save(); $error_page = fx::data('page')->create(array('name' => fx::alang('Page not found', 'system'), 'url' => '/404', 'site_id' => $site['id'], 'parent_id' => $index_page['id']))->save(); $site['error_page_id'] = $error_page['id']; $site['index_page_id'] = $index_page['id']; fx::data('infoblock')->create(array('controller' => 'layout', 'action' => 'show', 'name' => 'Layout', 'site_id' => $site['id']))->save(); $site->save(); fx::input()->setCookie('fx_target_location', '/floxim/#admin.site.all'); $result = array('status' => 'ok', 'reload' => '/~ajax/user:cross_site_auth_form'); return $result; }
public function route($url = null, $context = null) { $action_info = null; if (!preg_match("~^/\\~ajax/([a-z0-9_\\.\\:\\@-]+)?~", $url, $action_info)) { return null; } fx::env('ajax', true); $c_url = fx::input()->fetchGetPost('_ajax_base_url'); if ($c_url) { $c_url = preg_replace("~^https?://[^/]+~", '', $c_url); $_SERVER['REQUEST_URI'] = $c_url; $base_path = fx::router()->getPath($c_url); if ($base_path) { $page = $base_path->last(); fx::env('page', $page); } 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); } } // import layout template to recreate real env fx::router('front')->importLayoutTemplate(); $page_infoblocks = fx::router('front')->getPageInfoblocks($page_id, $layout_id); fx::page()->setInfoblocks($page_infoblocks); $controller_params = fx::input()->fetchGetPost('_ajax_controller_params'); $c_infoblock_id = fx::input()->fetchGetPost('_ajax_infoblock_id'); if ($c_infoblock_id) { $infoblock = fx::data('infoblock', $c_infoblock_id); if ($infoblock) { if ($controller_params) { $infoblock->override(array('params' => $controller_params)); } $res = $infoblock->render(); return $res; } } $template = null; if ($action_info && !empty($action_info[1])) { $action = $action_info[1]; $action = explode("@", $action); if (count($action) == 2) { $template = $action[1]; $action = $action[0]; } else { $action = $action[0]; } } elseif (isset($_POST['_ajax_controller'])) { $action = $_POST['_ajax_controller']; } else { return null; } $action = explode(":", $action); $controller_name = $action[0]; if (preg_match("~^widget_~", $controller_name) && !isset($action[1])) { $action[1] = 'show'; } $action_name = $action[1]; $controller = fx::controller($controller_name . ':' . $action_name, $controller_params); if (!$template) { $template = fx::input()->fetchGetPost('_ajax_template'); } if (!$template) { $tpls = $controller->getAvailableTemplates(); if (count($tpls) > 0) { $template = $tpls[0]['full_id']; } } $res = $controller->process(); if ($template) { $tpl = fx::template($template); if ($tpl) { $res = $tpl->render($res); } } return $res ? $res : true; }