get() static public méthode

Gets a request value by key
static public get ( mixed $key = false, mixed $default = null ) : mixed
$key mixed The key to look for. Pass false or null to return the entire request array.
$default mixed Optional default value, which should be returned if no element has been found
Résultat mixed
Exemple #1
0
/**
 * 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
 * @package Kirby
 */
function get($key = false, $default = null)
{
    return r::get($key, $default);
}
 /**
  * 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;
     }
 }
 /**
  * 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;
 }
Exemple #4
0
 static function fetchData($template = false, $input = false)
 {
     if (!$input) {
         $input = r::get();
     }
     if ($template) {
         $params = settings::load($template);
         $fields = $params['fields'];
     } else {
         global $settings;
         $fields = $settings->fields;
     }
     $data = array();
     foreach ($fields as $key => $value) {
         $data[$key] = a::get($input, $key);
     }
     return $data;
 }
Exemple #5
0
 public function testRemove()
 {
     r::remove('testvar');
     $this->assertFalse(isset($_REQUEST['testvar']));
     $this->assertNull(r::get('testvar'));
 }
Exemple #6
0
$giphy_json = json_decode(file_get_contents($giphy_endpoint . $term));
$giphy_data = $giphy_json->data;
if (!count($giphy_data)) {
    echo "No gifs for " . $term;
    return;
} else {
    if (empty($term)) {
        $url = $giphy_data->image_original_url;
    } else {
        if (is_array($giphy_data)) {
            $url = $giphy_data[array_rand($giphy_data)]->images->original->url;
        } else {
            $url = $giphy_data->images->original->url;
        }
    }
}
header("HTTP/1.1 200 OK");
$json = array('payload' => json_encode(array('unfurl_links' => true, 'text' => '<' . $url . '|' . (!empty($text) ? $text : '') . '>', 'channel' => !empty($channel_name) ? '#' . $channel_name : null, 'username' => $botname . ($show_name && !empty($user_name) ? ' :: ' . $user_name : ''))));
// If no slack request token, just render out the gif result to the page
if (!r::get('token', null)) {
    echo '<img src="' . $url . '" />';
} else {
    // Get cURL resource
    $curl = curl_init();
    // Set some options - we are passing in a useragent too here
    curl_setopt_array($curl, array(CURLOPT_URL => $webhook_url, CURLOPT_POST => 1, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => $json));
    // Send the request & save response to $resp
    $resp = curl_exec($curl);
    // Close request to clear up some resources
    curl_close($curl);
}