/** * getDefaultData * * @return array */ public function getFormDefaultData() { $sessionData = (array) $this['form.data']; $pk = $this['item.pk']; $item = User::get($pk); if (ArrayHelper::getValue($sessionData, 'id') == $item->id) { unset($sessionData['password']); unset($sessionData['password2']); return $sessionData; } unset($item->password); return $item->dump(); }
/** * getDefaultData * * @return array */ public function getFormDefaultData() { $sessionData = (array) $this['form.data']; try { $keyName = $this['keyName'] ?: $this->getKeyName(); } catch (\DomainException $e) { $keyName = null; } $keyName = $keyName ?: 'id'; $item = $this->getItem(); if ($sessionData && ArrayHelper::getValue($sessionData, $keyName) == $item->{$keyName}) { return $sessionData; } return $item->dump(true); }
public static function ipBlock() { $ezset = \Ezset::getInstance(); $blockType = $ezset->params->get('ipBlock', 0); if (!$blockType) { return; } $clients = $ezset->params->get('ipBlockClient'); if ($ezset->app->isSite() && !in_array('site', $clients)) { return; } if ($ezset->app->isAdmin() && !in_array('administrator', $clients)) { return; } $ips = $ezset->params->get('ipBlockList'); $ips = explode("\n", $ips); $ips = array_map('trim', $ips); $ips = static::addLocalhost($ips); $block = false; $currentIps = array(ArrayHelper::getValue($_SERVER, 'HTTP_CLIENT_IP'), ArrayHelper::getValue($_SERVER, 'HTTP_X_FORWARDED_FOR'), ArrayHelper::getValue($_SERVER, 'REMOTE_ADDR')); if (array_intersect($ips, $currentIps)) { if ($blockType == 'deny') { $block = true; } } else { if ($blockType == 'allow') { $block = true; } } $input = \JFactory::getApplication()->input; if ($ezset->app->isAdmin()) { if (isset($_GET[$ezset->params->get('adminSecureCode')]) || $input->get('task') == 'login' && $input->get('option') == 'com_login') { $block = false; } } if (!\JFactory::getUser()->guest && $ezset->app->isAdmin()) { $block = false; } if ($block) { header('HTTP/1.1 404'); die; } }
/** * onRouterBeforeRouteMatch * * @param Event $event * * @return void */ public function onRouterBeforeRouteMatch(Event $event) { /** @var MainRouter $router */ $router = $event['router']; $routing = $this->unidev->loadRouting(); foreach ($routing as $name => $route) { $name = $this->unidev->name . '@' . $name; $pattern = ArrayHelper::getValue($route, 'pattern'); $variables = ArrayHelper::getValue($route, 'variables', array()); $allowMethods = ArrayHelper::getValue($route, 'method', array()); if (isset($route['controller'])) { $route['extra']['controller'] = $route['controller']; } if (isset($route['action'])) { $route['extra']['action'] = $route['action']; } if (isset($route['hook'])) { $route['extra']['hook'] = $route['hook']; } $route['extra']['package'] = $this->unidev->name; $router->addRoute(new Route($name, $pattern, $variables, $allowMethods, $route)); } }
/** * Event after deleted. * * @param boolean $result The result of deleted. * * @return void */ public function onAfterDelete(&$result) { if (!$result) { return; } $parentTable = $this->parentTable; $dataset = $this->deleteTempDataset; if ($dataset instanceof \Traversable) { $dataset = iterator_to_array($dataset); } foreach ((array) $dataset as $data) { $parentTable->reset(); $parentTable->bind($data); /** @var AbstractRelationHandler $relation */ foreach ($parentTable->_relation->getRelations() as $relation) { $field = $relation->getField(); $parentTable->{$field} = ArrayHelper::getValue($data, $field); } $parentTable->_relation->delete(); } $this->deleteTempDataset = null; }
/** * backbone * * @param bool $noConflict * @param array $options * * @return void */ public static function backbone($noConflict = false, $options = array()) { $asset = static::getAsset(); if (!static::inited(__METHOD__)) { JQueryScript::core(ArrayHelper::getValue($options, 'jquery_no_conflict', false)); static::underscore(ArrayHelper::getValue($options, 'jquery_no_conflict', true)); $asset->addScript(static::phoenixName() . '/js/core/backbone.min.js'); } if (!static::inited(__METHOD__, (bool) $noConflict) && $noConflict) { $asset->internalScript(';var backbone = Backbone.noConflict();'); } }
/** * Build route by raw url. * * @param array &$queries * * @return array */ public function buildByRaw(&$queries) { if (empty($queries['view'])) { return array(); } foreach ($this->routes as $view => $map) { $vars = $map->getVariables(); if (ArrayHelper::getValue($vars, 'controller') == $queries['view']) { unset($queries['view']); return $this->generate($view, $map); break; } } return array(); }
/** * Test get value from an array. * * @param array $input Input array * @param mixed $index Element to pull, either by association or number * @param mixed $default The defualt value, if element not present * @param string $type The type of value returned * @param array $expect The expected results * @param string $message The failure message * @param bool $defaults Use the defaults (true) or full argument list * * @return void * * @dataProvider seedTestGetValue * @covers Windwalker\Utilities\ArrayHelper::getValue * @since 1.0 */ public function testGetValue($input, $index, $default, $type, $expect, $message, $defaults) { if ($defaults) { $output = ArrayHelper::getValue($input, $index); } else { $output = ArrayHelper::getValue($input, $index, $default, $type); } $this->assertEquals($expect, $output, $message); }
/** * Resolve alias. * * @param string $class Controller class. * * @return string Alias name. */ public function resolveAlias($class) { return ArrayHelper::getValue($this->aliases, $class, $class); }
/** * getUser * * @param string $name * @param string $label * @param string $value * @param array $option * * @return string */ public function getUser($name, $label, $value = '', $option = array()) { $left = ArrayHelper::getValue($option, 'left', 3); $right = ArrayHelper::getValue($option, 'right', 7); $placeholder = ArrayHelper::getValue($option, 'placeholder', $label); $disabled = ArrayHelper::getValue($option, 'disabled') ? 'disabled' : ''; $readonly = ArrayHelper::getValue($option, 'readonly') ? 'readonly' : ''; return <<<USER <div class="form-group"> <label for="input-category" class="col-lg-{$left} control-label">{$label}</label> <div class="col-lg-{$right}"> <div class="input-group"> {$this->getInput($name, $value, $placeholder, $disabled, $readonly)} <span class="input-group-btn"> <button class="btn btn-primary" type="button"><i class="glyphicon glyphicon-user"></i></button> </span> </div> </div> </div> USER; }
/** * doExecute * * @return mixed * * @throws \Exception * @throws \Throwable */ protected function doExecute() { // Get primary key from form data $pk = ArrayHelper::getValue((array) $this->data, $this->keyName); // If primary key not exists, this is a new record. $this->isNew = !$pk; $data = $this->getDataObject(); $data->bind($this->data); // Process pre save hook, you may add your own logic in this method $this->preSave($data); // Just dave it. $this->doSave($data); // Process post save hook, you may add your own logic in this method $this->postSave($data); return true; }