public function layout($type, $data = array()) { $version = panel()->version(); $base = panel()->urls()->index(); $cssbase = panel()->urls()->css(); $jsbase = panel()->urls()->js(); $defaults = array('title' => panel()->site()->title() . ' | Panel', 'direction' => panel()->direction(), 'meta' => $this->snippet('meta'), 'css' => css($cssbase . '/panel.css?v=' . $version), 'js' => js($jsbase . '/dist/panel.min.js?v=' . $version), 'content' => '', 'bodyclass' => ''); switch ($type) { case 'app': $defaults['topbar'] = ''; $defaults['csrf'] = panel()->csrf(); $defaults['formcss'] = css($cssbase . '/form.min.css?v=' . $version); $defaults['formjs'] = js($jsbase . '/dist/form.min.js?v=' . $version); $defaults['appjs'] = js($jsbase . '/dist/app.min.js?v=' . $version); // plugin stuff $defaults['pluginscss'] = css($base . '/plugins/css?v=' . $version); $defaults['pluginsjs'] = js($base . '/plugins/js?v=' . $version); break; case 'base': break; } $data = array_merge($defaults, $data); if (r::ajax() and $type == 'app') { $panel = panel(); $user = $panel->site()->user(); $response = array('user' => $user ? $user->username() : false, 'direction' => $panel->direction(), 'title' => $data['title'], 'content' => $data['topbar'] . $data['content']); return response::json($response); } else { return new Layout($type, $data); } }
public static function error($message, $type, $file, $line) { // remove everything that has been rendered so far if (ob_get_level()) { ob_end_clean(); } if (class_exists('kirby') and !is_null(kirby::$instance)) { $kirby = kirby::$instance; } else { $kirby = null; } if (r::ajax()) { if (terror::debug()) { echo response::error($message, 400, array('type' => $type, 'file' => $file, 'line' => $line)); } else { echo response::error('Unexpected error', 400); } } else { header::status(400); static::view($message, $type, $file, $line, $kirby); } die; }
/* Custom Panel Stylesheet --------------------------------------- Define a custom stylesheet to load in to the panel. See: getkirby.com/docs/cheatsheet/options/panel.stylesheet */ c::set('panel.stylesheet', 'assets/css/panel.css'); /* Kirby Configuration --------------------------------------- By default you don't have to configure anything to make Kirby work. For more fine-grained configuration please check out getkirby.com/docs/advanced/options and getkirby.com/blog/multi-environment-setup */ // Routes // c::set('routes', array(array('pattern' => '(:any)', 'method' => 'ALL', 'action' => function ($path) { if (!r::ajax()) { header::notfound(); return site()->visit($path); } $page = page($path); $has_api_method = method_exists($page, 'api'); return response::json(array('has_api_method' => $has_api_method)); }), array('pattern' => 'get/users.json', 'method' => 'ALL', 'action' => function () { // if(!r::ajax()) { // return header::forbidden(); // } // $users = site()->users()->toArray(); // $r = array_combine($users,site()->users()->toArray()); // format for kirby select field return response::json(array("first" => 'Rafe', "middle" => 'Jackson', "last" => 'Goldberg')); })));
/** * Iterate through every route to find a matching route. * * @param string $path Optional path to match against * @return Route */ public function run($path = null) { $method = r::method(); $ajax = r::ajax(); $https = r::ssl(); $routes = a::get($this->routes, $method, array()); // detect path if not set manually if ($path === null) { $path = implode('/', (array) url::fragments(detect::path())); } // empty urls should never happen if (empty($path)) { $path = '/'; } foreach ($routes as $route) { if ($route->https and !$https) { continue; } if ($route->ajax and !$ajax) { continue; } // handle exact matches if ($route->pattern == $path) { $this->route = $route; break; } // We only need to check routes with regular expression since all others // would have been able to be matched by the search for literal matches // we just did before we started searching. if (strpos($route->pattern, '(') === false) { continue; } $preg = '#^' . $this->wildcards($route->pattern) . '$#u'; // If we get a match we'll return the route and slice off the first // parameter match, as preg_match sets the first array item to the // full-text match of the pattern. if (preg_match($preg, $path, $parameters)) { $this->route = $route; $this->route->arguments = array_slice($parameters, 1); break; } } if ($this->route and $this->filterer($this->route->filter) !== false) { return $this->route; } else { return null; } }
public function redirect($obj = '/', $action = false, $force = false) { if ($force === false and $redirect = get('_redirect')) { $url = purl($redirect); } else { $url = purl($obj, $action); } if (r::ajax()) { $user = $this->site()->user(); die(response::json(array('direction' => $this->direction(), 'user' => $user ? $user->username() : false, 'url' => $url))); } else { go($url); } }
<?php return function ($site, $pages, $page) { //set variables $url = null; $data = null; $status = null; //if page is accessed thorugh ajax if (r::ajax()) { //store sanitized $_POST variables $currentTestData = r::postData(array('test', 'user', 'data')); //get logged user (if any) if ($user = Auth::loggedUser()) { //get user's session page $userSession = site()->find(implode(DS, array(c::get('sessions.folder'), $user->session()))); //istantiate testSession object $tSession = new testSession($userSession, $user->username()); //get user's current session status $userSessionStatus = $user->status(); //if ajaxed $currentTestData equals user's current session status if (str::lower($currentTestData['test']) == str::lower($userSessionStatus)) { //if it was possitble to update user's results file (by appending $currentTestData) if (f::append($tSession->getUserResultsFile(), PHP_EOL . a::json($currentTestData))) { //set updated user's session status to next avalibale test $updatedStatus = $tSession->getNextTest($currentTestData['test']); //if there aren't tests available, set user's session statuts to completed session if (!$updatedStatus) { $updatedStatus = c::get('session.status.completed'); } //update user's session status to next avalibale test $user->update(array('status' => $updatedStatus));
public function testAjax() { $this->assertFalse(r::ajax()); }
public function redirect($obj = '/', $action = false, $force = false) { if ($force === false and $redirect = get('_redirect')) { $url = purl($redirect); } else { $url = purl($obj, $action); } if (r::ajax()) { // set the username of the current user if ($user = site()->user()) { header('Panel-User: '******'url' => $url))); } else { go($url); } }