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; }
/** * 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; }
/** * Shortcut for r::get() * * @param mixed $key The key to look for. Pass false or null to return the entire request array. * @param mixed $default Optional default value, which should be returned if no element has been found * @return mixed */ function get($key = null, $default = null) { return r::data($key, $default); }
/** * Create a new model instance from the $_POST input. * * @return static */ public static function fromInput() { $model = new static(); return $model->fill(r::data()); }
/** * Update the specified comment entry in the database. * * @param string $hash Unique hash value of the parent page. * @param integer $id Id of the comment to retrieve. * * @return Response */ public function update($hash, $id) { $page = $this->findPageByHash($hash); $comment = comment::find($id); if (!$comment) { $msg = l('comments.error.notfound', 'Comment not found'); return $this->error($msg, 400, array('id' => $id, 'hash' => $hash)); } $data = r::data(); $comment->fill($data); if ($comment->save()) { $msg = l('comments.success.saved', 'Comment saved'); return $this->success($msg, 200, array('id' => $comment->id())); } else { $msg = l('comments.error.save', 'Could not save comment'); return $this->error($msg, 400, array('input' => $comment->toArray(), 'errors' => $comment->errors()->toArray())); } }
static function updateFileinfo($file, $destination) { global $panel, $settings; $fields = $settings->filefields; $data = array(); $input = r::data(); if (empty($fields)) { false; } foreach ($fields as $key => $value) { $v = a::get($input, $key); if (is_array($v)) { $data[$key] = implode(', ', $v); } else { $data[$key] = trim($v); } } return self::write($destination, $data); }
/** * Run the wizard dialog. * * @param integer $index * @return string */ public function launch($index = 0) { // Retrieve active view if (!($view = $this->nth($index))) { return false; } // Trigger submit event if (get('token') && csfr(get('token'))) { $form = r::data(); $validator = new Validator($form, $view->rules()); $valid = $validator->passes(); // Goto next wizard step or display validation errors if ($valid && $view->trigger('submit', compact('form'))) { $next = $view->index() + 1; redirect::to($this->url($next)); } else { if (!$valid) { $view->errors($validator->errors()); } } } // Generate view and return the contents return $this->with(array('url' => $this->url(), 'content' => $view->content())); }
public function testData() { $this->assertTrue(is_array(r::data())); }