Inheritance: extends FireKit\Database\ActiveRecord\ActiveRecord
示例#1
0
 function __construct($item)
 {
     parent::__construct($item);
     $this->buildString();
     $this->runMethods();
     $this->showObject();
 }
示例#2
0
文件: auth.php 项目: LucasFyl/korakia
 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));
 }
示例#3
0
 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);
     }
 }
示例#4
0
文件: subpages.php 项目: dmak78/panel
 protected function sort($page)
 {
     // handle sorting
     if (r::is('post') and $action = get('action') and $id = get('id')) {
         $subpage = $this->page($page->id() . '/' . $id);
         switch ($action) {
             case 'sort':
                 try {
                     $subpage->sort(get('to'));
                 } catch (Exception $e) {
                     // no error handling, because if sorting
                     // breaks, the refresh will fix it.
                 }
                 break;
             case 'toggle':
                 try {
                     $subpage->toggle('last');
                 } catch (Exception $e) {
                     // no error handling, because if sorting
                     // breaks, the refresh will fix it.
                 }
                 break;
             case 'hide':
                 try {
                     $subpage->hide();
                 } catch (Exception $e) {
                     // no error handling, because if sorting
                     // breaks, the refresh will fix it.
                 }
                 break;
         }
         $this->redirect($page, 'subpages');
     }
 }
示例#5
0
 public function __construct()
 {
     $endpoint = $this;
     if ($page = page('webmention') and kirby()->path() == $page->uri()) {
         if (r::is('post')) {
             try {
                 $endpoint->start();
                 header::status(202);
                 tpl::set('status', 'success');
                 tpl::set('alert', null);
             } catch (Exception $e) {
                 header::status(400);
                 tpl::set('status', 'error');
                 tpl::set('alert', $e->getMessage());
             }
         } else {
             tpl::set('status', 'idle');
         }
     } else {
         kirby()->routes(array(array('pattern' => 'webmention', 'method' => 'GET|POST', 'action' => function () use($endpoint) {
             try {
                 $endpoint->start();
                 echo response::success('Yay', 202);
             } catch (Exception $e) {
                 echo response::error($e->getMessage());
             }
         })));
     }
 }
示例#6
0
 public function values($values = null)
 {
     if (is_null($values)) {
         return array_merge($this->values, r::data());
     }
     $this->values = array_merge($this->values, $values);
     return $this;
 }
示例#7
0
 public function index()
 {
     if (isset($this->index)) {
         return $this->index;
     }
     if (r::cli()) {
         return $this->index = '/';
     } else {
         return $this->index = url::base() . preg_replace('!\\/index\\.php$!i', '', server::get('SCRIPT_NAME'));
     }
 }
示例#8
0
 public function index()
 {
     if (isset($this->index)) {
         return $this->index;
     }
     // this value is used by the Panel
     $this->indexDetected = true;
     if (r::cli()) {
         return $this->index = '/';
     } else {
         return $this->index = url::base() . preg_replace('!\\/index\\.php$!i', '', server::get('SCRIPT_NAME'));
     }
 }
示例#9
0
 /**
  * Handle an incomming request.
  */
 public static function handle($pageId, $lang)
 {
     if (r::data('token') != c::get('slack.verify')) {
         return response::error('Forbidden', 403);
     }
     $history = static::api('channels.history', ['channel' => r::data('channel_id')]);
     if (!empty($history['error'])) {
         // Something went wrong ... maybe:
         $msg = ['channel_not_found' => ':lock: Sorry, but this is a private channel'];
         $err = $history['error'];
         return response::json(isset($msg[$err]) ? $msg[$err] : $err);
     }
     $messages = $history['messages'];
     if (!empty(r::data('text'))) {
         $messages = array_values(array_filter($messages, function ($m) {
             return stristr($m['text'], r::data('text'));
         }));
     }
     if (empty($messages)) {
         return response::json(":mag: Sorry, I couldn't find the post you're looking for");
     }
     $m = $messages[0];
     $a = @$m['attachments'][0];
     $img = @$a['image_url'];
     if (empty($img)) {
         $img = @$a['thumb_url'];
     }
     if (empty($img)) {
         return response::json(":warning: I'll only publish posts with images");
     }
     $page = site()->visit($pageId, $lang);
     $dir = $page->root();
     $ext = preg_replace('/.+?(\\.\\w+)($|[#?].*)/', '$1', $img);
     $file = $dir . DS . $m['ts'] . $ext;
     // Output success message early because of short slackbot timeouts
     $msg = ':metal: *' . r::data('text', 'last') . '* post is now live' . ' on <' . $page->url() . '>';
     echo $msg;
     flush();
     error_log($msg);
     $user = static::api('users.info', ['user' => $m['user']]);
     $meta = ['title' => $a['title'], 'date' => date('d.m.Y', $m['ts']), 'description' => @$a['text'], 'linkurl' => $a['from_url'], 'author' => $user['user']['profile']['real_name'], 'avatar' => $m['user'] . '.jpg', 'comment' => static::format(@$m['text']), 'slack' => '1'];
     data::write($file . '.txt', $meta, 'kd');
     // Download the avatar image
     $avatar = $dir . DS . $meta['avatar'];
     static::download($user['user']['profile']['image_72'], $avatar);
     // Download the image
     static::download($img, $file);
     // Response has already been sent
     return false;
 }
示例#10
0
文件: urls.php 项目: nsteiner/kdoc
 public function index()
 {
     if (isset($this->index)) {
         return $this->index;
     }
     if (r::cli()) {
         $index = '/';
     } else {
         $index = url::base() . preg_replace('!\\/index\\.php$!i', '', server::get('SCRIPT_NAME'));
     }
     // fix index URL for the Panel
     if (function_exists('panel')) {
         $index = dirname($index);
     }
     return $this->index = $index;
 }
示例#11
0
 /**
  * Retourne un tableau des caractères de $sInputString sous leur forme ordinale.
  * 
  * @param string $sInputString Chaîne de caractères dont les caractères sont à retourner en ordinal.
  * @return array Tableau indexé.
  */
 protected function _getOrds($sInputString)
 {
     $aOrds = array();
     if ($this->_oString->getEncoding() === Encoding::UTF_8) {
         $sString = mb_convert_encoding($sInputString, Encoding::UCS_4BE, Encoding::UTF_8);
         for ($iCharIndex = 0; $iCharIndex < mb_strlen($sString, Encoding::UCS_4BE); $iCharIndex++) {
             // Calcul de la valeur totale des 4 bits
             $sStringChar = mb_substr($sString, $iCharIndex, 1, Encoding::UCS_4BE);
             $aUnpackedData = unpack('N', $sStringChar);
             $aOrds[] = $aUnpackedData[1];
         }
     } else {
         r::char()->setModifiers($this->_m())->matchAll($sInputString, $aChars);
         foreach ($aChars as $sChar) {
             $aOrds[] = ord($sChar);
         }
     }
     return $aOrds;
 }
示例#12
0
 /**
  * Dashboard /login action
  *
  * @return void
  */
 public function login()
 {
     if (site()->user()) {
         go('dashboard');
     }
     // save the flashed redirect
     flash('login.redirect', flash('login.redirect'));
     if (r::is('post')) {
         if ($this->form->validates()) {
             $user = site()->user($this->form->data('username'));
             if ($user && $user->login($this->form->data('password'))) {
                 flash('messages.success', 'Logged in!');
                 if (get('_redirect')) {
                     go(get('_redirect'));
                 }
             } else {
                 $this->form->addErrors(['login' => 'Invalid username and password']);
             }
         }
         go('login');
     }
     $this->render('dashboard/login', ['pageTitle' => 'Login', 'form' => $this->form, 'page' => page()]);
 }
示例#13
0
文件: terror.php 项目: chrishiam/LVSL
 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;
 }
示例#14
0
 /**
  * Starts the router, renders the page and returns the response
  *
  * @return mixed
  */
 public function launch()
 {
     // this will trigger the configuration
     $site = $this->site();
     // force secure connections if enabled
     if ($this->option('ssl') and !r::secure()) {
         // rebuild the current url with https
         go(url::build(array('scheme' => 'https')));
     }
     // set the timezone for all date functions
     date_default_timezone_set($this->options['timezone']);
     // load all extensions
     $this->extensions();
     // load all plugins
     $this->plugins();
     // load all models
     $this->models();
     // start the router
     $this->router = new Router($this->routes());
     $this->route = $this->router->run($this->path());
     // check for a valid route
     if (is_null($this->route)) {
         header::status('500');
         header::type('json');
         die(json_encode(array('status' => 'error', 'message' => 'Invalid route or request method')));
     }
     // call the router action with all arguments from the pattern
     $response = call($this->route->action(), $this->route->arguments());
     // load all language variables
     // this can only be loaded once the router action has been called
     // otherwise the current language is not yet available
     $this->localize();
     // build the response
     $this->response = $this->component('response')->make($response);
     // store the current language in the session
     if ($this->site()->multilang() && ($language = $this->site()->language())) {
         s::set('language', $language->code());
     }
     return $this->response;
 }
示例#15
0
<?php

return function ($site, $pages, $page) {
    // don't show the login screen to already logged in users
    if ($site->user()) {
        go('/');
    }
    // handle the form submission
    if (r::is('post') and get('login')) {
        // fetch the user by username and run the
        // login method with the password
        if ($user = $site->user(get('username')) and $user->login(get('password'))) {
            // redirect to the homepage
            // if the login was successful
            go('/');
        } else {
            // make sure the alert is being
            // displayed in the template
            $error = true;
        }
    } else {
        // nothing has been submitted
        // nothing has gone wrong
        $error = false;
    }
    return array('error' => $error);
};
示例#16
0
/**
 * Dumps any array or object in a human readable way
 *
 * @param mixed $variable Whatever you like to inspect
 * @param boolean $echo
 * @return string
 */
function dump($variable, $echo = true)
{
    if (r::cli()) {
        $output = print_r($variable, true) . PHP_EOL;
    } else {
        $output = '<pre>' . print_r($variable, true) . '</pre>';
    }
    if ($echo == true) {
        echo $output;
    }
    return $output;
}
示例#17
0
文件: kirby.php 项目: sdvig/kirbycms
 /** 
  * Sets a request value by key
  *
  * @param  mixed   $key The key to define
  * @param  mixed   $value The value for the passed key
  */
 static function set($key, $value = null)
 {
     $data = self::data();
     if (is_array($key)) {
         self::$_ = array_merge($data, $key);
     } else {
         self::$_[$key] = $value;
     }
 }
示例#18
0
 public function on($action, $callback)
 {
     // auto-trigger the submit event when the form is being echoed
     if (r::is('post')) {
         $callback($this);
     }
     $this->fields->append('csrf', static::field('hidden', array('name' => 'csrf', 'value' => panel()->csrf())));
 }
示例#19
0
 /**
  * Create a new model instance from the $_POST input.
  *
  * @return  static
  */
 public static function fromInput()
 {
     $model = new static();
     return $model->fill(r::data());
 }
示例#20
0
 /**
  * Test if any of the honeypot fields are filled.
  *
  * @return  boolean
  */
 protected function isBot()
 {
     // Honeypot spam prevention
     $config = $this->hub()->config();
     $method = $config->get('honeypot');
     switch ($method) {
         case 'css':
             $field = $config->get('honeypot.name', 'url');
             $value = r::get($field);
             return !empty($value);
         case 'js':
             $field = $config->get('honeypot.name', 'legit');
             $value = r::get($field);
             return 1 !== intval($value);
     }
     // Time based spam prevention
     $threshold = $config->get('requiredReadingTime', 0);
     if ($threshold > 0) {
         $now = time();
         $time = r::get('tictoc');
         return $now - $time < $threshold;
     }
     return false;
 }
示例#21
0
文件: kirby.php 项目: andywenk/kirby
function get($key, $default = null)
{
    return r::get($key, $default);
}
示例#22
0
<?php

use Crazy\Form;
return function ($site, $pages, $page) {
    $event = $page->parent();
    $order = new CrazyEventOrder($event);
    $form = new Form(['guest' => []]);
    if (r::is('post')) {
        // Add a new guest
        if (get('add_guest') && ($guest = get('guest'))) {
            if ($event->seatsAvailable(1 + count($order->guests()))) {
                $order->addGuest(htmlspecialchars($guest));
            } else {
                $form->addError('guest', 'Sorry, there are no more seats available.');
            }
        }
        // Remove a guest
        if ($removeId = get('remove_guest')) {
            // the field is submitted as "id-[$id]"
            $id = substr($removeId, 3);
            $order->removeGuest($id);
        }
        go($page->url());
    }
    return ['event' => $event, 'studio' => $order->studio(), 'form' => $form, 'order' => $order];
};
示例#23
0
            // Update password
            $user = $site->user()->update(array('password' => get('password')));
        }
        echo l::get('account-success');
    } catch (Exception $e) {
        echo l::get('account-failure');
    }
    ?>
        </p>
      </div>
    <?php 
}
?>

    <?php 
if (r::is('post') and get('delete')) {
    ?>
      <div class="uk-alert uk-alert-danger">
        <p>
          <?php 
    try {
        $user = $site->user();
        $user->logout();
        $site->user($user->username())->delete();
        go('/register');
    } catch (Exception $e) {
        echo l::get('account-delete-error');
    }
    ?>
        </p>
      </div>
示例#24
0
 /**
  * Nobody can remember if it is written with on or two r
  *
  * @return string
  */
 public static function referer()
 {
     return r::referer();
 }
 $fd = fopen('.htaccess', 'w');
 if ($fd === FALSE) {
     @unlink('class/config.php');
     header('HTTP/1.1 500 Internal Error');
     exit;
 }
 fputs($fd, 'RewriteEngine on' . PHP_EOL . 'Options -Indexes +FollowSymlinks' . PHP_EOL);
 fputs($fd, 'RewriteBase ' . ($dir === '' ? '/' : $dir) . PHP_EOL);
 fputs($fd, 'RewriteRule ^(ajax.*) $1 [L,NC,QSA]' . PHP_EOL . 'RewriteRule ^(assets)/(.*) $1/$2 [L,NC]' . PHP_EOL . 'RewriteRule ^.*$ index.php [L,QSA]' . PHP_EOL);
 fclose($fd);
 /*
  * Try opening the database and setting up the User table
  */
 require 'rb.php';
 try {
     $now = r::isodatetime(time() - date('Z'));
     # make sure the timestamp is in UTC (this should fix a weird problem with some XAMPP installations)
     $vals['dbhost'] = $cvalue['dbhost'];
     $vals['dbname'] = $cvalue['dbname'];
     $vals['dbuser'] = $cvalue['dbuser'];
     R::setup('mysql:host=' . $cvalue['dbhost'] . ';dbname=' . $cvalue['dbname'], $cvalue['dbuser'], $cvalue['dbpass']);
     # mysql initialiser
     R::freeze(FALSE);
     R::nuke();
     # clear everything.....
     $user = R::dispense('user');
     $user->email = $cvalue['email'];
     $user->login = $cvalue['admin'];
     $user->password = password_hash($cvalue['adminpw'], PASSWORD_DEFAULT);
     $user->active = 1;
     $user->confirm = 1;
示例#26
0
<?php

return function ($site, $pages, $page) {
    // handle the form submission
    if (r::is('post') and get('register')) {
        try {
            $user = $site->users()->create(array('username' => get('username'), 'email' => get('email'), 'password' => get('password'), 'language' => 'en'));
            // make sure the alert is being
            // displayed in the template
            $success = true;
        } catch (Exception $e) {
            // make sure the alert is being
            // displayed in the template
            $error = true;
        }
    } else {
        // nothing has been submitted
        // nothing has gone wrong
        $error = false;
    }
    return array('error' => $error, 'success' => $success);
};
示例#27
0
 /**
  * Redirect to a specific page.
  *
  * @param   string  $target   Page to redirect to.
  * @param   array   $data     Optional data to save in a users session.
  */
 protected function redirect($target, $data = null)
 {
     // Write optional session data
     if ($data instanceof Messages) {
         Session::flash('errors', $data->toArray());
     } else {
         if (is_array($data)) {
             Session::flash($data);
         } else {
             if (!is_null($data)) {
                 Session::flash('data', $data);
             }
         }
     }
     // Allow to specify the redirect uri as parameter
     $url = r::get('redirect_to');
     if (!empty($url)) {
         redirect::to($url);
     }
     // Perform redirect
     switch ($target) {
         case 'home':
             redirect::home();
             break;
         case 'back':
             redirect::back();
             break;
         case '404':
             $page = site()->errorPage();
             redirect::to($page->uri());
             break;
         case 'referer':
             $referer = server::get('HTTP_REFERER');
             redirect::to($referer);
             break;
         default:
             redirect::to($target);
             break;
     }
 }
示例#28
0
/* 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'));
})));
示例#29
0
 function __construct($item)
 {
     parent::__construct($item);
     $this->buildNumber();
     $this->runMethods();
 }
示例#30
0
文件: url.php 项目: LucasFyl/korakia
 /**
  * Returns the URL for document root no 
  * matter what the path is. 
  * 
  * @return string
  */
 public static function index()
 {
     if (r::cli()) {
         return '/';
     } else {
         return static::base() . preg_replace('!\\/index\\.php$!i', '', server::get('SCRIPT_NAME'));
     }
 }