get() статический публичный Метод

Gets an element of an array by key
static public get ( array $array, mixed $key, mixed $default = null ) : mixed
$array array The source array
$key mixed The key to look for
$default mixed Optional default value, which should be returned if no element has been found
Результат mixed
Пример #1
0
 function __construct($image, $options = array())
 {
     $this->root = c::get('thumb.cache.root', c::get('root') . '/thumbs');
     $this->url = c::get('thumb.cache.url', c::get('url') . '/thumbs');
     if (!$image) {
         return false;
     }
     $this->obj = $image;
     // set some values from the image
     $this->sourceWidth = $this->obj->width();
     $this->sourceHeight = $this->obj->height();
     $this->width = $this->sourceWidth;
     $this->height = $this->sourceHeight;
     $this->source = $this->obj->root();
     $this->mime = $this->obj->mime();
     // set the max width and height
     $this->maxWidth = @$options['width'];
     $this->maxHeight = @$options['height'];
     // set the quality
     $this->crop = @$options['crop'];
     // set the quality
     $this->quality = a::get($options, 'quality', c::get('thumb.quality', 100));
     // set the default upscale behavior
     $this->upscale = a::get($options, 'upscale', c::get('thumb.upscale', false));
     // set the alt text
     $this->alt = a::get($options, 'alt', $this->obj->name());
     // set the className text
     $this->className = @$options['class'];
     // set the new size
     $this->size();
     // create the thumbnail
     $this->create();
 }
Пример #2
0
 static function get($key = null, $default = null)
 {
     if ($key === null) {
         return (array) self::$vars;
     }
     return a::get(self::$vars, $key, $default);
 }
Пример #3
0
 public function update($data = array())
 {
     if (!panel()->user()->isAdmin() and !$this->isCurrent()) {
         throw new Exception(l('users.form.error.update.rights'));
     }
     // users which are not an admin cannot change their role
     if (!panel()->user()->isAdmin()) {
         unset($data['role']);
     }
     if (str::length(a::get($data, 'password')) > 0) {
         if (a::get($data, 'password') !== a::get($data, 'passwordconfirmation')) {
             throw new Exception(l('users.form.error.password.confirm'));
         }
     } else {
         unset($data['password']);
     }
     unset($data['passwordconfirmation']);
     if ($this->isLastAdmin() and a::get($data, 'role') !== 'admin') {
         // check the number of left admins to not convert the last one
         throw new Exception(l('user.error.lastadmin'));
     }
     parent::update($data);
     // flush the cache in case if the user data is
     // used somewhere on the site (i.e. for profiles)
     kirby()->cache()->flush();
     kirby()->trigger('panel.user.update', $this);
     return $this;
 }
Пример #4
0
 /**
  * Gets a value from the _SERVER array
  * 
  * <code>
  * 
  * server::get('document_root');
  * // sample output: /var/www/kirby
  * 
  * server::get();
  * // returns the whole server array
  *
  * </code>   
  *
  * @param  mixed    $key The key to look for. Pass false or null to return the entire server array. 
  * @param  mixed    $default Optional default value, which should be returned if no element has been found
  * @return mixed
  */
 public static function get($key = false, $default = null)
 {
     if (empty($key)) {
         return $_SERVER;
     }
     return a::get($_SERVER, str::upper($key), $default);
 }
Пример #5
0
 static function checkPassword($user, $password)
 {
     // check for empty passwords
     if (empty($password) || empty($user['password'])) {
         return false;
     }
     // get the encryption
     $encryption = a::get($user, 'encrypt', false);
     // handle the different
     // encryption types
     switch ($encryption) {
         // sha1 encoded
         case 'sha1':
             return sha1($password) == $user['password'] ? true : false;
             break;
             // md5 encoded
         // md5 encoded
         case 'md5':
             return md5($password) == $user['password'] ? true : false;
             break;
             // plain passwords
         // plain passwords
         default:
             return $password == $user['password'] ? true : false;
             break;
     }
     // we should never get here
     // but let's make sure
     return false;
 }
Пример #6
0
 public function fields()
 {
     $fields = $this->config->fields();
     $fields = new Fields($fields, $this->model);
     $fields = $fields->toArray();
     // make sure that no unwanted options or fields
     // are being included here
     foreach ($fields as $name => $field) {
         // remove all structure fields within structures
         if ($field['type'] == 'structure') {
             unset($fields[$name]);
             // remove invalid buttons from textareas
         } else {
             if ($field['type'] == 'textarea') {
                 $buttons = a::get($fields[$name], 'buttons');
                 if (is_array($buttons)) {
                     foreach ($buttons as $index => $value) {
                         if (in_array($value, array('link', 'email'))) {
                             unset($fields[$name]['buttons'][$index]);
                         }
                     }
                 } else {
                     if ($buttons !== false) {
                         $fields[$name]['buttons'] = array('bold', 'italic');
                     }
                 }
             }
         }
     }
     return $fields;
 }
Пример #7
0
 public function _default($default)
 {
     if (empty($default)) {
         return '';
     } else {
         if (is_string($default)) {
             return $default;
         } else {
             $type = a::get($default, 'type');
             switch ($type) {
                 case 'date':
                     $format = a::get($default, 'format', 'Y-m-d');
                     return date($format);
                     break;
                 case 'datetime':
                     $format = a::get($default, 'format', 'Y-m-d H:i:s');
                     return date($format);
                     break;
                 case 'user':
                     $user = isset($default['user']) ? site()->users()->find($default['user']) : site()->user();
                     if (!$user) {
                         return '';
                     }
                     return (isset($default['field']) and $default['field'] != 'password') ? $user->{$default['field']}() : $user->username();
                     break;
                 default:
                     return $default;
                     break;
             }
         }
     }
 }
Пример #8
0
 /**
  * Retreives a field info object from the registry
  * 
  * @param string|null $name If null, all registered fields will be returned as array
  * @param Obj|null|array
  */
 public function get($name = null)
 {
     if (is_null($name)) {
         return static::$fields;
     }
     return a::get(static::$fields, $name);
 }
Пример #9
0
 public function message()
 {
     if ($message = s::get('message') and is_array($message)) {
         $text = a::get($message, 'text');
         $type = a::get($message, 'type', 'notification');
         $element = new Brick('div');
         $element->addClass('message');
         if ($type == 'error') {
             $element->addClass('message-is-alert');
         } else {
             $element->addClass('message-is-notice');
         }
         $element->append(function () use($text) {
             $content = new Brick('span');
             $content->addClass('message-content');
             $content->text($text);
             return $content;
         });
         $element->append(function () {
             $toggle = new Brick('a');
             $toggle->attr('href', url::current());
             $toggle->addClass('message-toggle');
             $toggle->html('<i>&times;</i>');
             return $toggle;
         });
         s::remove('message');
         return $element;
     }
 }
Пример #10
0
 public function testGet()
 {
     $this->assertEquals('testuser', a::get($this->user, 'username'));
     // get an array of keys
     $array = a::get($this->user, array('username', 'email'));
     $this->assertEquals(array('username' => 'testuser', 'email' => '*****@*****.**'), $array);
 }
Пример #11
0
 public function __construct($params = array())
 {
     // start the fields collection
     $this->params = $params;
     if ($params === false) {
         $this->fields = array();
         $this->type = array();
         $this->size = false;
         $this->width = false;
         $this->height = false;
         $this->max = 0;
         $this->hide = true;
         $this->sortable = false;
     } else {
         if (is_array($params)) {
             $this->fields = a::get($params, 'fields', $this->fields);
             $this->type = a::get($params, 'type', $this->type);
             if (!is_array($this->type)) {
                 $this->type = array($this->type);
             }
             $this->size = a::get($params, 'size', $this->size);
             $this->width = a::get($params, 'width', $this->width);
             $this->height = a::get($params, 'height', $this->height);
             $this->max = a::get($params, 'max', $this->max);
             $this->hide = a::get($params, 'hide', $this->hide);
             $this->sort = a::get($params, 'sort', $this->sort);
             $this->sortable = a::get($params, 'sortable', $this->sortable);
             $this->sanitize = a::get($params, 'sanitize', true);
         }
     }
 }
Пример #12
0
 function get($part = null, $default = null)
 {
     $path = self::$path ? self::$path : self::path();
     if (!$part) {
         return $path;
     }
     return a::get($path, $part - 1, $default);
 }
Пример #13
0
 /**
  * @param array $options
  */
 public function __construct($options)
 {
     $this->preview = a::get($options, 'preview', true);
     $this->status = a::get($options, 'status', true);
     $this->template = a::get($options, 'template', true);
     $this->url = a::get($options, 'url', true);
     $this->delete = a::get($options, 'delete', true);
 }
Пример #14
0
 public function delete($id = null)
 {
     $filename = get('filename');
     $page = $this->page($id);
     $file = $this->file($page, $filename);
     $back = array('index' => purl('files/index/' . $page->id()), 'file' => purl($file, 'show'));
     return view('files/delete', array('p' => $page, 'f' => $file, 'back' => a::get($back, get('to'))));
 }
Пример #15
0
 public function avatar($username)
 {
     $user = $this->user($username);
     $back = array('users' => purl('users'), 'user' => purl($user, 'edit'), 'dashboard' => purl(''));
     if (!site()->user()->isAdmin() and !$user->isCurrent()) {
         goToErrorView('modal');
     }
     return view('users/avatar', array('user' => $user, 'uploadable' => is_writable(kirby()->roots()->avatars()), 'back' => a::get($back, get('to'))));
 }
Пример #16
0
 /**
  * Retrieve the file path for a registered snippet
  * 
  * @param string $name
  * @return string
  */
 public function get($name)
 {
     $file = $this->kirby->component('snippet')->file($name);
     if (file_exists($file)) {
         return $file;
     } else {
         return a::get(static::$snippets, $name);
     }
 }
Пример #17
0
 /**
  * Gets a value from the _SERVER array
  * 
  * <code>
  * 
  * server::get('document_root');
  * // sample output: /var/www/kirby
  * 
  * server::get();
  * // returns the whole server array
  *
  * </code>   
  *
  * @param  mixed    $key The key to look for. Pass false or null to return the entire server array. 
  * @param  mixed    $default Optional default value, which should be returned if no element has been found
  * @return mixed
  */
 public static function get($key = false, $default = null)
 {
     if (empty($key)) {
         return $_SERVER;
     }
     $key = str::upper($key);
     $value = a::get($_SERVER, $key, $default);
     return static::sanitize($key, $value);
 }
Пример #18
0
 public function get($field = null)
 {
     $data = (array) a::get($this->data(), $this->id());
     if (!is_null($field)) {
         return a::get($data, $field);
     } else {
         return $data;
     }
 }
Пример #19
0
 function get($key = '_global')
 {
     if (c::get('timer') === false) {
         return false;
     }
     $time = explode(' ', microtime());
     $time = (double) $time[1] + (double) $time[0];
     $timer = a::get(self::$timer, $key);
     return round($time - $timer, 5);
 }
Пример #20
0
 function find()
 {
     $args = func_get_args();
     $key = @$args[0];
     $default = @$args[1];
     if (!$key) {
         return $this->_;
     }
     return a::get($this->_, $key, $default);
 }
Пример #21
0
 public function field($key, $field = null)
 {
     if (is_null($field)) {
         $field = $key;
     }
     $value = a::get($this->data, $field);
     if ($key == 'url' and !v::url($value)) {
         $value = null;
     }
     $this->{$key} = new Field($this->page, $key, esc($value));
 }
Пример #22
0
 /**
  * Returns the URL key from the content file
  * if available and otherwise returns the page UID
  *
  * @param string $lang
  * @return string
  */
 public function urlKey($lang = null)
 {
     if ($content = $this->content($lang)) {
         // search for a translated url_key in that language
         if ($key = (string) a::get((array) $content->data(), 'url_key')) {
             // if available, use the translated url key as slug
             return $key;
         }
     }
     return $this->uid();
 }
Пример #23
0
 /**
  * Retreives a registered widget directory
  * 
  * @param string|null $name If null, all registered widgets will be returned as array
  * @return string|array
  */
 public function get($name = null)
 {
     if (is_null($name)) {
         return static::$widgets;
     }
     $file = $this->kirby->roots()->widgets() . DS . str_replace('/', DS, $name) . '.php';
     if (file_exists($file)) {
         return $file;
     } else {
         return a::get(static::$widgets, $name);
     }
 }
Пример #24
0
 /**
  * Retreives a registered blueprint file path 
  * 
  * @param string $name
  * @return string 
  */
 public function get($name = null)
 {
     if (is_null($name)) {
         return static::$blueprints;
     }
     $file = f::resolve($this->kirby->roots()->blueprints() . DS . str_replace('/', DS, $name), ['php', 'yml', 'yaml']);
     if (file_exists($file)) {
         return $file;
     } else {
         return a::get(static::$blueprints, $name);
     }
 }
Пример #25
0
 public function update($id, $data)
 {
     if ($entry = a::get($this->data, $id)) {
         foreach ($data as $key => $value) {
             $entry[$key] = $value;
         }
         $this->data[$id] = $entry;
         $this->save();
         return $entry;
     } else {
         return false;
     }
 }
Пример #26
0
 /**
  * Sets and returns query-specific bindings
  *
  * @param string $query SQL query string that contains the bindings
  * @param array $values Array of bindings to set (null to get the bindings)
  * @return array
  */
 public function bindings($query, $values = null)
 {
     if (is_null($values)) {
         return a::get($this->bindings, $query, array());
     } else {
         if (!is_null($query)) {
             $this->bindings[$query] = $values;
         }
         // directly register bindings if possible
         if ($this->dbquery) {
             $this->dbquery->bindings($values);
         }
     }
 }
Пример #27
0
 public function content()
 {
     if (is_array($this->value())) {
         $timestamp = strtotime($this->result());
     } else {
         $timestamp = strtotime($this->value());
     }
     $date = form::field('date', array('name' => $this->name() . '[date]', 'value' => $timestamp ? date('Y-m-d', $timestamp) : null, 'format' => a::get($this->date, 'format', 'YYYY-MM-DD'), 'id' => 'form-field-' . $this->name() . '-date'));
     $time = form::field('time', array('name' => $this->name() . '[time]', 'value' => $timestamp ? date('H:i', $timestamp) : null, 'format' => a::get($this->time, 'format', 24), 'interval' => a::get($this->time, 'interval', 60), 'id' => 'form-field-' . $this->name() . '-time'));
     $grid = '<div class="field-grid">';
     $grid .= '<div class="field-grid-item field-grid-item-1-2">' . $date->content() . '</div>';
     $grid .= '<div class="field-grid-item field-grid-item-1-2">' . $time->content() . '</div>';
     $grid .= '</div>';
     return $grid;
 }
Пример #28
0
 public static function subpages($pages, $blueprint)
 {
     switch ($blueprint->pages()->sort()) {
         case 'flip':
             $pages = $pages->flip();
             break;
         default:
             $parts = str::split($blueprint->pages()->sort(), ' ');
             $field = a::get($parts, 0);
             $order = a::get($parts, 1);
             if ($field) {
                 $pages = $pages->sortBy($field, $order);
             }
             break;
     }
     return $pages;
 }
Пример #29
0
 public function _default($default)
 {
     if ($default === true) {
         return 'true';
     } else {
         if ($default === false) {
             return 'false';
         } else {
             if (empty($default) and strlen($default) == 0) {
                 return '';
             } else {
                 if (is_string($default)) {
                     return $default;
                 } else {
                     $type = a::get($default, 'type');
                     switch ($type) {
                         case 'date':
                             $format = a::get($default, 'format', 'Y-m-d');
                             return date($format);
                             break;
                         case 'datetime':
                             $format = a::get($default, 'format', 'Y-m-d H:i:s');
                             return date($format);
                             break;
                         case 'user':
                             $user = isset($default['user']) ? site()->users()->find($default['user']) : site()->user();
                             if (!$user) {
                                 return '';
                             }
                             return (isset($default['field']) and $default['field'] != 'password') ? $user->{$default['field']}() : $user->username();
                             break;
                         case 'structure':
                             return "\n" . \data::encode(array($default), 'yaml') . "\n";
                             break;
                         default:
                             return $default;
                             break;
                     }
                 }
             }
         }
     }
 }
Пример #30
0
 public function __construct($params = array())
 {
     // start the fields collection
     $this->params = $params;
     if ($params === false) {
         $this->max = 0;
         $this->sortable = false;
         $this->hide = true;
         $this->fields = array();
     } else {
         if (is_array($params)) {
             $this->max = a::get($params, 'max', $this->max);
             $this->hide = a::get($params, 'hide', $this->hide);
             $this->sort = a::get($params, 'sort', $this->sort);
             $this->sortable = a::get($params, 'sortable', $this->sortable);
             $this->fields = a::get($params, 'fields', array());
         }
     }
 }