/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (!$request->isSecure() && noah_installed() && site('forceSsl') == '1') { return redirect($request->path(), 302, [], true); } return $next($request); }
public function rules() { $site_id = site()->id; $publicable = true; request()->merge(compact('site_id', 'publicable')); return ['key' => 'required|unique:' . $this->getTable() . ',key,' . (string) $this->id . ',id,site_id,' . $site_id, 'value' => 'required']; }
/** * Redirect user to the related service auth. * * @param $service * @return \Illuminate\Http\Response * * @author Cali */ public function socialLogin($service) { if (site($service . 'On') != '1') { return redirect('/'); } return Socialite::with($service)->redirect(); }
/** * Get the item's poster image object or a default image * * @return string */ public function posterImage() { if ($this->poster()->isNotEmpty()) { return $this->image($this->poster()); } return site()->image(site()->defaultPlaceImage()); }
/** * Get the category image for calendar use * * @return File */ public function categoryImage() { if ($this->hasCalendarImage()) { return $this->image($this->calendarImage()); } return site()->image(site()->eventDefaultImage()); }
public function index() { if (site()->users()->count() > 0) { go(panel()->urls()->login()); } if ($problems = installation::check()) { $content = view('installation/check', array('problems' => $problems)); } else { $form = panel()->form('installation', array('language' => kirby()->option('panel.language', 'en'))); $form->cancel = false; $form->save = l('installation.signup.button'); $form->centered = true; foreach (panel()->languages() as $lang) { $form->fields()->get('language')->options[$lang->code()] = $lang->title(); } $form->on('submit', function ($form) { try { // fetch all the form data $data = $form->serialize(); // make sure that the first user is an admin $data['role'] = 'admin'; // try to create the new user $user = panel()->site()->users()->create($data); // store the new username for the login screen s::set('username', $user->username()); // redirect to the login go(panel()->urls()->login() . '/welcome'); } catch (Exception $e) { $form->alert($e->getMessage()); } }); $content = view('installation/signup', array('form' => $form)); } return layout('installation', array('meta' => new Snippet('meta'), 'content' => $content)); }
/** * Gatekeeper function that validates input forms and prevents csrf attacks. * Call this from your form action code. * * @param string $targetURL The URL of the form action that brought us here. * @param boolean $haltExecutionOnBadRequest If set to true, the function halts all execution if the form doesn't validate. (True by default.) * @return true|false */ public static function validateToken($action = '', $haltExecutionOnBadRequest = true) { if (site()->session()->isAPIRequest()) { return true; } return parent::validateToken($action, $haltExecutionOnBadRequest); }
/** * DISPLAY */ public function css() { if ($language = site()->language() and $language->direction() === 'rtl') { $this->assets->setHook('css', tools::load('css', 'components/rtl')); } return '<style>' . $this->fontPaths($this->getHooks('css')) . '</style>'; }
function registerPages() { site()->addPageHandler('/admin/?', '\\Idno\\Pages\\Admin\\Home'); site()->addPageHandler('/admin/plugins/?', '\\Idno\\Pages\\Admin\\Plugins'); site()->addPageHandler('/admin/dependencies/?', '\\Idno\\Pages\\Admin\\Dependencies'); site()->addPageHandler('/admin/about/?', '\\Idno\\Pages\\Admin\\About'); }
function registerEvents() { \Idno\Core\site()->addEventHook('saved', function (\Idno\Core\Event $event) { $eventdata = $event->data(); if ($object = $eventdata['object']) { if (site()->session()->isLoggedOn()) { if (!empty(site()->session()->currentUser()->robot_state)) { $user = site()->session()->currentUser(); switch ($user->robot_state) { case '1': if (class_exists('IdnoPlugins\\Status') && $object instanceof \IdnoPlugins\Status) { $user->robot_state = '2a'; } else { $user->robot_state = '2b'; } self::$changed_state = 1; break; case '2a': if (class_exists('IdnoPlugins\\Photo') && $object instanceof \IdnoPlugins\Photo) { $user->robot_state = '3a'; } self::$changed_state = 1; break; case '2b': $user->robot_state = '3b'; self::$changed_state = 1; break; } $user->save(); site()->session()->refreshSessionUser($user); } } } }); }
public function login($welcome = null) { if ($user = panel()->site()->user()) { go(panel()->urls()->index()); } $message = l('login.error'); $error = false; $form = panel()->form('login'); $form->cancel = false; $form->save = l('login.button'); $form->centered = true; if (r::is('post') and get('_csfr') and csfr(get('_csfr'))) { $data = $form->serialize(); $user = site()->user(str::lower($data['username'])); if (!$user) { $error = true; } else { if (!$user->hasPanelAccess()) { $error = true; } else { if (!$user->login(get('password'))) { $error = true; } else { go(panel()->urls()->index()); } } } } if ($username = s::get('username')) { $form->fields->username->value = html($username, false); } return layout('login', array('meta' => new Snippet('meta'), 'welcome' => $welcome ? l('login.welcome') : '', 'form' => $form, 'error' => $error ? $message : false)); }
public function structure($id, $fieldName, $context) { $page = empty($id) ? site() : page($id); if (!$page) { throw new Exception('The page could not be found'); } $blueprint = blueprint::find($page); $field = null; $fields = $context == 'file' ? $blueprint->files()->fields() : $blueprint->fields(); // make sure to get fields by case insensitive field names foreach ($fields as $f) { if (strtolower($f->name) == strtolower($fieldName)) { $field = $f; } } if (!$field) { throw new Exception('The field could not be found'); } $fields = new Blueprint\Fields($field->fields(), $page); $fields = $fields->toArray(); foreach ($fields as $key => $field) { if ($field['type'] == 'textarea') { $fields[$key]['buttons'] = false; } } $form = new Form($fields, null, $fieldName); $form->save = get('_id') ? l('fields.structure.save') : l('fields.structure.add'); return view('editor/structure', array('page' => $page, 'form' => $form)); }
/** * DISPLAY */ public static function show($args = array()) { if ($user = site()->user() and $user->hasPanelAccess()) { $self = new self($args); return $self->_output(); } }
protected function items($page, $method) { switch ($method) { case 'visibleChildren': $items = $page->children()->visible(); break; case 'invisibleChildren': $items = $page->children()->invisible(); break; case 'siblings': $items = $page->siblings()->not($page); break; case 'pages': $items = site()->index(); $items = $items->sortBy('title', 'asc'); break; case 'index': $items = $page->index(); $items = $items->sortBy('title', 'asc'); break; case 'children': case 'files': case 'images': case 'documents': case 'videos': case 'audio': case 'code': case 'archives': $items = $page->{$method}(); break; } return $items; }
protected function signup() { $self = $this; $form = $this->form('installation/signup', array(), function ($form) use($self) { $form->validate(); if (!$form->isValid()) { return false; } try { // fetch all the form data $data = $form->serialize(); // make sure that the first user is an admin $data['role'] = 'admin'; // try to create the new user $user = site()->users()->create($data); // store the new username for the login screen s::set('username', $user->username()); // try to login the user automatically if ($user->hasPanelAccess()) { $user->login($data['password']); } // redirect to the login $self->redirect('login'); } catch (Exception $e) { $form->alert($e->getMessage()); } }); return $this->modal('index', compact('form')); }
function registerEventHooks() { \Idno\Core\Idno::site()->events()->addListener('syndicate', function (\Idno\Core\Event $event) { $eventdata = $event->data(); if (!empty($eventdata['object'])) { $content_type = $eventdata['object']->getActivityStreamsObjectType(); if ($services = \Idno\Core\Idno::site()->syndication()->getServices($content_type)) { if ($selected_services = \Idno\Core\Idno::site()->currentPage()->getInput('syndication')) { if (!empty($selected_services) && is_array($selected_services)) { foreach ($selected_services as $selected_service) { $eventdata['syndication_account'] = false; if (in_array($selected_service, $services)) { site()->queue()->enqueue('default', 'post/' . $content_type . '/' . $selected_service, $eventdata); } else { if ($implied_service = $this->getServiceByAccountString($selected_service)) { $eventdata['syndication_account'] = $this->getAccountFromAccountString($selected_service); site()->queue()->enqueue('default', 'post/' . $content_type . '/' . $implied_service, $eventdata); } } } } } } } }); }
public static function bodyClass() { $classes = []; $classes[] = 'page--' . site()->page()->slug(); $classes[] = 'template--' . site()->page()->template(); return join(' ', $classes); }
public function __construct($output, $assets) { $this->site = site(); $this->page = page(); $this->output = $output; $this->assets = $assets; }
public function _default($default) { if (empty($default)) { return ''; } else { if (is_string($default)) { return $default; } else { $type = a::get($default, 'type'); switch ($type) { case 'date': $format = a::get($default, 'format', 'Y-m-d'); return date($format); break; case 'datetime': $format = a::get($default, 'format', 'Y-m-d H:i:s'); return date($format); break; case 'user': $user = isset($default['user']) ? site()->users()->find($default['user']) : site()->user(); if (!$user) { return ''; } return (isset($default['field']) and $default['field'] != 'password') ? $user->{$default['field']}() : $user->username(); break; default: return $default; break; } } } }
protected function form($user = null) { $mode = $user ? 'edit' : 'add'; $fields = data::read(panel()->roots()->forms() . DS . 'user.' . $mode . '.php', 'yaml'); $content = $user ? $user->data() : array(); // add all languages $fields['language']['options'] = array(); $fields['language']['default'] = kirby()->option('panel.language', 'en'); foreach (panel()->languages() as $code => $lang) { $fields['language']['options'][$code] = $lang->title(); } // add all roles $fields['role']['options'] = array(); $fields['role']['default'] = site()->roles()->findDefault()->id(); foreach (site()->roles() as $role) { $fields['role']['options'][$role->id()] = $role->name(); } // make the role selector readonly when the user is not an admin if (!site()->user()->isAdmin()) { $fields['role']['readonly'] = true; } // make sure the password is never shown in the form unset($content['password']); return new Form($fields, $content); }
/** * Helpfer function relativeDate() */ function relativeDate($date, $args = array()) { // default for $args $defaults = array('lang' => count(site()->languages()) >= 1 ? site()->language()->code() : c::get('relativedate.lang', 'en'), 'length' => c::get('relativedate.length', 2), 'threshold' => c::get('relativedate.threshold', false), 'fuzzy' => c::get('relativedate.fuzzy', true), 'format' => c::get('relativedate.format', 'd.m.Y')); $args = array_merge($defaults, $args); // check if $date is a timestamp if (RelativeDate::isTimestamp($date)) { $date = date(DATE_ATOM, $date); } // only convert to relative if time difference no exceeds threshold if ($args['threshold'] === false or abs(strtotime($date) - time()) <= $args['threshold']) { try { $relative = new RelativeDate($date, $args); $result = $relative->get($args['length']); } catch (Exception $e) { $result = $date; } } else { $result = $date; } // if we had no change to date due to any bug or exceeding threshold if ($result === $date) { $date = new Datetime($date); $result = $date->format($args['format']); } return $result; }
public static function get() { $history = site()->user()->history(); if (empty($history) or !is_array($history)) { return array(); } $update = false; $result = array(); foreach ($history as $item) { $page = page($item); if (!$page) { $update = true; } else { $result[] = $page; } } if ($update) { $history = array_map(function ($item) { return $item->id(); }, $result); try { site()->user()->update(array('history' => $history)); } catch (Exception $e) { } } return $result; }
protected function user($username) { if ($user = site()->user($username)) { return $user; } else { throw new Exception(l('users.error.missing')); } }
protected function page($id) { $page = !$id ? site() : page($id); if (!$page) { throw new Exception(l('subpages.error.missing')); } return $page; }
/** * Get the document title * * @return string */ public static function title() { $title = site()->title(); if (page()->title()->isNotEmpty()) { $title = page()->title() . ' - ' . $title; } return $title; }
public function __toString() { $user = site()->user(); if ($user->hasRole('admin')) { return parent::__toString(); } return ""; }
public function rules() { $this->slugify('title'); $published_at = $this->published_at ?: Carbon::now(); $author_id = $this->author_id ?: auth()->user()->id; request()->merge(compact('published_at', 'author_id')); return ['title' => $this->uniqify('title'), 'slug' => $this->uniqify('slug'), 'permalink' => 'unique:permalinks,permalink,' . ($this->permalink ? $this->permalink->id : 'NULL') . ',id,site_id,' . (site()->id == null ? 'NULL' : site()->id), 'content' => 'required', 'picture' => 'image|max:5120', 'published_at' => 'required']; }
public function index() { $site = site(); $blueprint = blueprint::find($site); $fields = $blueprint->fields()->toArray(); $content = $site->content()->toArray(); return view('metatags/index', array('topbar' => new Snippet('pages/topbar', array('breadcrumb' => new Snippet('breadcrumb', array('items' => array(array('title' => l('metatags'), 'url' => purl('metatags/'))))), 'search' => purl('pages/search/'))), 'form' => new Form($fields, $content), 's' => $site)); }
/** * Log out the user * * @return void */ public function logout() { if (site()->user()) { site()->user()->logout(); } flash('messages.success', 'Logged out!'); go('login'); }
function init() { // Account management site()->addPageHandler('/account/settings', '\\Idno\\Pages\\Account\\Settings'); // Basic registration, if we're allowing it if (\Idno\Core\site()->config()->open_registration == true) { site()->addPageHandler('/account/register', '\\Idno\\Pages\\Account\\Register'); } }