function index() { $datas['title'] = 'Medoo-MVC'; $hello = new index(); $datas['hello'] = $hello->hello(); $lib_class = new a(); $datas['hi'] = $lib_class->hi(); $this->display($datas); }
function main() { $b = new b(); $b->f($b); t::f($b); $b->set($b, 'new value'); t::set($b, 'newer value'); $a = new a(); $a->f($a); t::f($a); }
static function get($key = null, $default = null) { if ($key === null) { return (array) self::$vars; } return a::get(self::$vars, $key, $default); }
public function __construct($data = array()) { if (!isset($data['id'])) { throw new Exception('The role id is missing'); } if (!isset($data['name'])) { throw new Exception('The role name is missing'); } // required data $this->id = $data['id']; $this->name = $data['name']; if (isset($data['permissions']) and is_array($data['permissions'])) { $this->permissions = a::merge($this->permissions, $data['permissions']); } else { if (isset($data['permissions']) and $data['permissions'] === false) { $this->permissions = array_fill_keys(array_keys($this->permissions), false); } else { $this->permissions = $this->permissions; } } // fallback permissions support for old 'panel' role variable if (isset($data['panel']) and is_bool($data['panel'])) { $this->permissions['panel.access'] = $data['panel']; } // is this role the default role? if (isset($data['default'])) { $this->default = $data['default'] === true; } }
function tagcloud($parent, $options = array()) { global $site; // default values $defaults = array('limit' => false, 'field' => 'tags', 'children' => 'visible', 'baseurl' => $parent->url(), 'param' => 'tag', 'sort' => 'name', 'sortdir' => 'asc'); // merge defaults and options $options = array_merge($defaults, $options); switch ($options['children']) { case 'invisible': $children = $parent->children()->invisible(); break; case 'visible': $children = $parent->children()->visible(); break; default: $children = $parent->children(); break; } $cloud = array(); foreach ($children as $p) { $tags = str::split($p->{$options}['field']()); foreach ($tags as $t) { if (isset($cloud[$t])) { $cloud[$t]->results++; } else { $cloud[$t] = new obj(array('results' => 1, 'name' => $t, 'url' => $options['baseurl'] . '/' . $options['param'] . ':' . $t, 'isActive' => param($options['param']) == $t ? true : false)); } } } $cloud = a::sort($cloud, $options['sort'], $options['sortdir']); if ($options['limit']) { $cloud = array_slice($cloud, 0, $options['limit']); } return $cloud; }
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); } } }
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; }
function foo() { a::inFamilya(); a::inFamilyb(); a::notDefined(); c::notAClass(); }
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; } } } }
/** * 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); }
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(); }
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; }
/** * 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); }
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>×</i>'); return $toggle; }); s::remove('message'); return $element; } }
public function create($uid, $template, $content = array()) { if (empty($template)) { throw new Exception(l('pages.add.error.template')); } $uid = empty($uid) ? str::random(32) : $uid; $blueprint = new Blueprint($template); $data = array(); foreach ($blueprint->fields(null) as $key => $field) { $data[$key] = $field->default(); } $data = array_merge($data, $content); // create the new page and convert it to a page model $page = new Page($this->page, parent::create($uid, $template, $data)->dirname()); if (!$page) { throw new Exception(l('pages.add.error.create')); } kirby()->trigger('panel.page.create', $page); // subpage builder foreach ((array) $page->blueprint()->pages()->build() as $build) { $missing = a::missing($build, array('title', 'template', 'uid')); if (!empty($missing)) { continue; } $subpage = $page->children()->create($build['uid'], $build['template'], array('title' => $build['title'])); if (isset($build['num'])) { $subpage->sort($build['num']); } } return $page; }
function __construct() { a::y(); parent::y(); a::$x; parent::$x; }
function b() { $this->apublicButSBPrivate = $this->aprotected + $this->aprivate; $a->apublicButReally = 1; self::$aspublicButSBPrivateSelf = 1; static::$aspublicButSBPrivateStatic = 2; \a::$aspublicButSBPrivateFull = 3; }
/** * @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); }
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')))); }
/** * 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); }
/** * 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); } }
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')))); }
function foo() { a::inAA(); a::inA(); a::inB(); a::inTrait(); a::nowhere(); c::inC(); }
function foo() { \a::inAA(); \a::inA(); \a::inB(); \a::inTrait(); \a::nowhere(); \c::inC(); }
/** * Aggregates all the fields present in the given event object. * @param array $events An array of Event objects. */ private static function findEventFields($events) { $fields = array(); foreach ($events as $event) { $fields = a::merge($fields, $event->getFieldKeys()); } // make an associative array with the same keys as values return array_combine($fields, $fields); }
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; } }
public function testSort() { $users = $this->users; $users = a::sort($users, 'username', 'asc'); $first = a::first($users); $last = a::last($users); $this->assertEquals('mary', $first['username']); $this->assertEquals('peter', $last['username']); }
function ab() { $this->aprotectedButReally = $this->apublic + $this->aprivate; $a->aprotectedButReally = 1; self::$asprotectedButSBPrivateSelf = 1; static::$asprotectedButSBPrivateStatic = 2; \a::$asprotectedButSBPrivateFull = 3; \b::$asprotectedButSBPrivateChildren = 3; }
/** * Create a new CrazyMailer * * @var array $config data, accepts same as Email::__construct() */ public function __construct($config) { $defaults = ['to' => KirbyConfig::get('mailer.to'), 'from' => KirbyConfig::get('mailer.from'), 'service' => 'mailgun', 'options' => ['key' => KirbyConfig::get('mailgun.key'), 'domain' => KirbyConfig::get('mailgun.domain')]]; $this->emailer = new KirbyEmailer(KirbyArray::merge($defaults, $config)); $this->enabled = env('MAILER_ENABLED', false); $handler = new StreamHandler(kirby()->roots()->site() . '/../logs/emailer.log', Logger::WARNING); $this->logger = new Logger('crazy'); $this->logger->pushHandler($handler); }
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); }