Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
 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'];
 }
Ejemplo n.º 3
0
 /**
  * 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();
 }
Ejemplo n.º 4
0
 /**
  * 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());
 }
Ejemplo n.º 5
0
 /**
  * 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());
 }
Ejemplo n.º 6
0
 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));
 }
Ejemplo n.º 7
0
 /**
  *  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);
 }
Ejemplo n.º 8
0
 /**
  *  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>';
 }
Ejemplo n.º 9
0
 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');
 }
Ejemplo n.º 10
0
 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);
                 }
             }
         }
     });
 }
Ejemplo n.º 11
0
 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));
 }
Ejemplo n.º 12
0
 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));
 }
Ejemplo n.º 13
0
 /**
  *  DISPLAY
  */
 public static function show($args = array())
 {
     if ($user = site()->user() and $user->hasPanelAccess()) {
         $self = new self($args);
         return $self->_output();
     }
 }
Ejemplo n.º 14
0
 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;
 }
Ejemplo n.º 15
0
 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'));
 }
Ejemplo n.º 16
0
 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);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     });
 }
Ejemplo n.º 17
0
 public static function bodyClass()
 {
     $classes = [];
     $classes[] = 'page--' . site()->page()->slug();
     $classes[] = 'template--' . site()->page()->template();
     return join(' ', $classes);
 }
Ejemplo n.º 18
0
 public function __construct($output, $assets)
 {
     $this->site = site();
     $this->page = page();
     $this->output = $output;
     $this->assets = $assets;
 }
Ejemplo n.º 19
0
 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;
             }
         }
     }
 }
Ejemplo n.º 20
0
 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);
 }
Ejemplo n.º 21
0
/**
 *  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;
}
Ejemplo n.º 22
0
 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;
 }
Ejemplo n.º 23
0
 protected function user($username)
 {
     if ($user = site()->user($username)) {
         return $user;
     } else {
         throw new Exception(l('users.error.missing'));
     }
 }
Ejemplo n.º 24
0
 protected function page($id)
 {
     $page = !$id ? site() : page($id);
     if (!$page) {
         throw new Exception(l('subpages.error.missing'));
     }
     return $page;
 }
Ejemplo n.º 25
0
 /**
  * Get the document title
  *
  * @return string
  */
 public static function title()
 {
     $title = site()->title();
     if (page()->title()->isNotEmpty()) {
         $title = page()->title() . ' - ' . $title;
     }
     return $title;
 }
Ejemplo n.º 26
0
 public function __toString()
 {
     $user = site()->user();
     if ($user->hasRole('admin')) {
         return parent::__toString();
     }
     return "";
 }
Ejemplo n.º 27
0
 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'];
 }
Ejemplo n.º 28
0
 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));
 }
Ejemplo n.º 29
0
 /**
  * Log out the user
  *
  * @return void
  */
 public function logout()
 {
     if (site()->user()) {
         site()->user()->logout();
     }
     flash('messages.success', 'Logged out!');
     go('login');
 }
Ejemplo n.º 30
0
 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');
     }
 }