本文整理汇总了PHP中response::error方法的典型用法代码示例。如果您正苦于以下问题:PHP response::error方法的具体用法?PHP response::error怎么用?PHP response::error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类response
的用法示例。
在下文中一共展示了response::error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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());
}
})));
}
}
示例2: run
function run($page)
{
$templates = c::get('autopublish.templates', array('project', 'item'));
if (!$templates || in_array($page->template(), $templates)) {
try {
$page->toggle('last');
} catch (Exception $e) {
return response::error($e->getMessage());
}
}
}
示例3: autocomplete
public function autocomplete($mode)
{
switch ($mode) {
case 'usernames':
$result = site()->users()->map(function ($user) {
return $user->username();
})->toArray();
break;
case 'emails':
$result = site()->users()->map(function ($user) {
return $user->email();
})->toArray();
break;
case 'uris':
$result = site()->index()->map(function ($page) {
return $page->id();
})->toArray();
// sort results alphabetically
sort($result);
break;
case 'field':
$index = get('index', 'siblings');
// siblings, children, template, all
$id = get('uri');
$page = page($id);
switch ($index) {
case 'siblings':
case 'children':
$pages = $page->{$index}();
break;
case 'template':
$template = get('template', $page->template());
$pages = site()->index()->filterBy('template', $template);
break;
case 'pages':
case 'all':
$pages = site()->index();
break;
default:
if ($page = site()->page($index)) {
$pages = $page->children();
} else {
return response::json(array());
}
}
$result = $pages->pluck(get('field', 'tags'), get('separator', true), true);
break;
default:
return response::error('Invalid autocomplete method');
}
return response::json(array_values($result));
}
示例4: delete
public function delete($username)
{
$user = $this->user($username);
if (!$user) {
return response::error(l('users.avatar.delete.error.missing'));
}
if ($avatar = $user->avatar()) {
if (f::remove($avatar->root())) {
return response::success(l('users.avatar.delete.success'));
}
}
return response::error(l('users.avatar.delete.error'));
}
示例5: delete
public function delete($username)
{
$user = $this->user($username);
if (!$user) {
return response::error(l('users.error.missing'));
}
try {
$user->delete();
return response::success('success');
} catch (Exception $e) {
return response::error(l('users.delete.error'));
}
}
示例6: 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;
}
示例7: avgimgcolorhook
function avgimgcolorhook($file)
{
if (!$file->isImage()) {
return;
}
try {
if ($file->avgcolor() == "") {
require_once kirby()->roots()->index() . '/vendor/autoload.php';
$color = \ColorThief\ColorThief::getColor($file->root(), 100);
$file->update(['avgcolor' => rgb2hex($color)]);
}
} catch (Exception $e) {
return response::error($e->getMessage());
}
}
示例8: autothumbhook
function autothumbhook($file)
{
if (!c::get('autothumb.enabled', false) || !$file->isImage()) {
return;
}
try {
$height = c::get('autothumb.height', 500);
$quality = c::get('autothumb.quality', 70);
$dimensions = clone $file->dimensions();
$dimensions->fitHeight($height);
$thumb = thumb($file, ['width' => $dimensions->width(), 'height' => $dimensions->height(), 'quality' => $quality]);
echo $thumb->root();
} catch (Exception $e) {
return response::error($e->getMessage());
}
}
示例9: delete
public function delete($username)
{
$user = $this->user($username);
if (!$user) {
return response::error(l('users.avatar.delete.error.missing'));
}
if (!site()->user()->isAdmin() and !$user->isCurrent()) {
return response::error('You are not allowed to delete the avatar of this user');
}
if ($avatar = $user->avatar()) {
if (f::remove($avatar->root())) {
return response::success(l('users.avatar.delete.success'));
}
}
return response::error(l('users.avatar.delete.error'));
}
示例10: delete
public function delete($username)
{
$user = $this->user($username);
if (!$user) {
return response::error(l('users.error.missing'));
}
if (!site()->user()->isAdmin() and !$user->isCurrent()) {
return response::error('You are not allowed to delete this user');
}
try {
$user->delete();
return response::success('success');
} catch (Exception $e) {
return response::error(l('users.delete.error'));
}
}
示例11: login
public function login()
{
$user = app::$site->users()->find(str::lower(get('username')));
$message = l('login.error');
if (!$user) {
return response::error($message);
}
try {
if (!$user->login(get('password'))) {
throw new Exception($message);
}
return response::success(l('login.success'));
} catch (Exception $e) {
return response::error($e->getMessage());
}
}
示例12: thumb
public function thumb($id, $filename)
{
$page = $this->page($id);
$file = $this->file($page, $filename);
$width = intval(get('width'));
$height = intval(get('height'));
if (!$file->canHavePreview()) {
return response::error('No preview available', 404);
}
if (!$file->canHaveThumb()) {
go($file->url());
}
if (get('crop') == true) {
$thumb = $file->crop($width, $height, 80);
} else {
$thumb = $file->resize($width, $height, 80);
}
go($thumb->url());
}
示例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: foreach
try {
// Make sure we're on a product page
if ($page->template() !== 'product') {
return true;
}
// Numeric stock, price and sale price
$variants = $page->variants()->yaml();
foreach ($variants as $key => $variant) {
if (!is_numeric($variant['price'])) {
$variants[$key]['price'] = preg_replace('/[^0-9.]/', '', $variant['price']);
}
if (!is_numeric($variant['sale_price'])) {
$variants[$key]['sale_price'] = preg_replace('/[^0-9.]/', '', $variant['sale_price']);
}
if (!is_numeric($variant['stock'])) {
$variants[$key]['stock'] = preg_replace('/[^0-9.]/', '', $variant['stock']);
}
}
// Numeric tax rates
$taxes = $page->tax()->yaml();
foreach ($taxes as $key => $tax) {
if (!is_numeric($tax['rate'])) {
$taxes[$key]['rate'] = preg_replace('/[^0-9.]/', '', $tax['rate']);
}
}
// Save changes
$page->update(['variants' => yaml::encode($variants), 'tax' => yaml::encode($taxes)]);
} catch (Exception $e) {
return response::error($e->getMessage());
}
});
示例15: set_error
public static function set_error($code = 1, $msg = '')
{
self::$error = self::code_to_msg($code, $msg);
return false;
}