本文整理汇总了PHP中r类的典型用法代码示例。如果您正苦于以下问题:PHP r类的具体用法?PHP r怎么用?PHP r使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了r类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
function __construct($item)
{
parent::__construct($item);
$this->buildString();
$this->runMethods();
$this->showObject();
}
示例2: login
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: layout
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: sort
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: __construct
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: values
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: index
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: index
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: handle
/**
* 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: index
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: _getOrds
/**
* 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: login
/**
* 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: error
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: launch
/**
* 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: function
<?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);
};