/** * Header favicon tag constructor * @param string|array $name Examples: 'keywords', 'description', 'copyright', or an associative array ('name' => 'keywords', 'content' => 'example keyword list') * @param string $content * @throws Kohana_Exception */ public function __construct($href) { if (!is_array($href)) { $this->attributes['href'] = (string) $href; } else { $this->attributes = Arr::overwrite($this->attributes, $href); } }
public function __construct($config = NULL) { include_once Kohana::find_file('vendor', 'recaptcha/recaptchalib'); $this->_config = Kohana::$config->load('recaptcha'); if (is_array($config)) { $this->_config = Arr::overwrite($this->_config, $config); } return $this; }
/** * Create a new field * @param string $name * @param string $id * @param string $label * @param array $config * @param array $attributes * @param array $extra */ public function __construct($name, $id, $label, array $config = NULL, array $attributes = NULL, array $extra = NULL) { $this->_attributes = $this->_attributes + (array) $attributes; $this->_config = Arr::overwrite($this->_config, (array) $config); $this->_extra = (array) $extra; $this->_name = $name; $this->_label = $label; $this->_id = $id; }
/** * Sube el comentario * * @param array $datos Los datos recibitos por POST * @return int Retorna el ID del envio si hubo exito, sino retorna 0 o FALSE */ public function subir(array $datos) { $exito = FALSE; // Hace la validacion if ($this->values($datos)->check()) { // Los datos han sido validados y los guardamos $this->save(); $exito = $this->id; } // Llenamos los vectores con los valores que seran mostrados en los campos $this->errores = Arr::overwrite($this->errores, $this->validate()->errors("")); $this->formulario = Arr::overwrite($this->formulario, $datos); return $exito; }
/** * Vista de registro de nuevas informaciones */ public function action_editar($id) { Model_Usuario::otorgar_acceso($this->request); $this->set_titulo("Editar evío"); $envio = ORM::factory("envio", $id); if ($_POST) { if ($this->editar_info($id)) { $this->request->redirect("noticia/ver/" . $id); } } else { $this->formulario_subir_info = Arr::overwrite($this->formulario_subir_info, $envio->as_array()); } $vista = View::factory("envio/subir")->set("usuario_id", $envio->usuario->id)->set("cat", NULL)->set("errores", $this->errores_subir_info)->set("formulario", $this->formulario_subir_info); $this->contenido = $vista; }
/** * Valida los datos ingresados para la solicitud de Constancia de Residencia */ private function validar_const_resid() { $persona = ORM::factory("persona"); $datos = Validate::factory($_POST)->filter("cedula_solic", "trim")->rule("cedula_solic", "digit")->rule("cedula_solic", "not_empty")->callback("cedula_solic", array($persona, "existe"))->filter("testigo_a", "trim")->rule("testigo_a", "digit")->rule("testigo_a", "not_empty")->callback("testigo_a", array($persona, "existe"))->filter("testigo_b", "trim")->rule("testigo_b", "digit")->rule("testigo_b", "not_empty")->callback("testigo_b", array($persona, "existe"))->rule("destinatario", "not_empty"); if ($datos->check()) { $solic = ORM::factory("persona")->where("cedula", "=", $_POST['cedula_solic'])->find(); $testigo_a = ORM::factory("persona")->where("cedula", "=", $_POST['testigo_a'])->find(); $testigo_b = ORM::factory("persona")->where("cedula", "=", $_POST['testigo_b'])->find(); // Los datos son validos y se puede otorgar la constancia $this->request->redirect("pdf/constancia_residencia/" . "?s=" . $solic->id . "&a=" . $testigo_a->id . "&b=" . $testigo_b->id . "&dest=" . $datos['destinatario']); } // Si llega aqui es porque hubo un error // Llenamos los vectores con los valores que seran mostrados en los campos $this->err_const_resid = $datos->errors("persona"); $this->form_const_resid = Arr::overwrite($this->form_const_resid, $_POST); }
private function _set_active_pos() { $this->_fields_required = Arr::overwrite($this->_fields_required, $this->_pos_data); }
/** * * @test * @dataProvider provider_overwrite */ public function test_overwrite($expected, $arr1, $arr2, $arr3 = array(), $arr4 = array()) { $this->assertSame($expected, Arr::overwrite($arr1, $arr2, $arr3, $arr4)); }
/** * Getter/setter for the data. Stores only expected array keys. * * @return array */ public function data(array $data = NULL) { if ($data !== NULL) { // Only take keys that we actually expect. $this->_data = Arr::overwrite(array_fill_keys(array_keys($this->_fields), NULL), $data); } return $this->_data; }
/** * Instantiate a new menu * * @param string $config_file File name in config/menu/ * @throws Kohana_Exception * @return Menu * @since 2.0 */ public static function factory($config_file = 'bootstrap', $config = array()) { // Get already created instance if (array_key_exists($config_file, self::$_instances)) { return self::$_instances[$config_file]; } // Load menu config $menu_config = self::_get_menu_config($config_file); // Add custom options $menu_config = Arr::overwrite($menu_config, $config); // Auto-detect view path when no view file given if (Arr::get($menu_config, 'view') === NULL) { $view_file = Kohana::find_file('views/' . self::VIEWS_DIR, $config_file) ? $config_file : self::DEFAULT_VIEW; $menu_config['view'] = self::VIEWS_DIR . DIRECTORY_SEPARATOR . $view_file; } return self::$_instances[$config_file] = new Menu($menu_config); }
public function action_database() { $action = Route::get('install')->uri(array('action' => 'database')); $view = View::factory('install/database')->bind('form', $form)->set('action', $action); $this->template->content = $view; $this->template->title = __('Database Configuration'); $this->template->_activity = __('60'); $this->template->menu = array(HTML::anchor(Route::get('install')->uri(), __('Welcome')), HTML::anchor(Route::get('install')->uri(array('action' => 'systemcheck')), __('System Check')), HTML::anchor(Route::get('install')->uri(array('action' => 'database')), __('Database')), __('Install'), __('Finish')); $form = array('user' => '', 'pass' => '', 'hostname' => 'localhost', 'database' => 'gleezcms', 'table_prefix' => 'gl_'); if (isset($_POST['db'])) { $data = array('user' => $username = $_POST['user'], 'pass' => $password = $_POST['pass'], 'hostname' => $hostname = $_POST['hostname'], 'database' => $database = $_POST['database'], 'table_prefix' => $table_prefix = $_POST['table_prefix']); try { $this->check_database($username, $password, $hostname, $database); $this->_session->set('database_data', $data); $this->request->redirect(Route::get('install')->uri(array('action' => 'install'))); } catch (Exception $e) { $form = Arr::overwrite($form, $_POST); $error = $e->getMessage(); // TODO create better error messages // Try to use mysql_errno. // Error message of East Asian character sets will display garbled text on utf-8 web page switch ($error) { case 'access': $this->template->error = __('Wrong username or password'); break; case 'unknown_host': $this->template->error = __('Could not find the host'); break; case 'connect_to_host': $this->template->error = __('Could not connect to host'); break; case 'select': $this->template->error = __('Could not select the database'); break; case 'version': $this->template->error = __('Gleez requires at least MySQL version 5.0.0. You\'re using version :version', array(':version' => $this->mysql_version(1))); break; default: $this->template->error = $error; } } } }
/** * Create fields automatically */ protected function _z_create_fields() { foreach ($this->_belongs_to as $column => $data) { // Field has already been set in if (isset($this->_z_fields[$data['foreign_key']]) or in_array($data['foreign_key'], $this->_z_exclude)) { continue; } // Assign label if (!isset($this->_z_labels[$data['foreign_key']])) { $this->_z_labels[$data['foreign_key']] = ucfirst(Inflector::humanize($column)); } // Field type is set if (isset($this->_z_field_config[$data['foreign_key']]['type'])) { continue; } $options = ORM::factory($data['model']); $pk = Arr::overwrite(array($options->primary_key(), $options->primary_key()), (array) Arr::get($data, 'zform_pk')); $label = Arr::overwrite(array('name', 'name'), (array) Arr::get($data, 'zform_label')); $options = $options->select($pk)->select($label); $options = $options->find_all()->as_array($pk[1], $label[1]); $attributes = Arr::get($this->_z_attributes, $data['foreign_key']); $name = $this->field_name($data['foreign_key']); $id = $this->field_id($data['foreign_key']); $label = Arr::get($this->_z_labels, $data['foreign_key'], ucfirst(Inflector::humanize($column))); $config = array('options' => $options); $this->_z_fields[$data['foreign_key']] = new ZForm_Field_Enum($name, $id, $label, $config, $attributes, $data); } foreach ($this->_table_columns as $column => $field) { // Field has already been set or has been excluded if (isset($this->_z_fields[$column]) or in_array($column, $this->_z_exclude)) { $this->_z_labels[$column] = Arr::get($this->_z_labels, $column, ucfirst(Inflector::humanize($column))); continue; } $data_type = explode(' ', $field['data_type']); $data_type = $data_type[0]; // Get additional config items, and add the default data $config = Arr::merge(Kohana::$config->load('zcolumns.default.default_column'), (array) Kohana::$config->load('zcolumns.default.' . $data_type)); $config = Arr::merge($config, (array) Arr::get($this->_z_field_config, $column)); $type = 'ZForm_Field_' . $config['type']; $attributes = Arr::get($this->_z_attributes, $column); $name = $this->field_name($column); $id = $this->field_id($column); $label = Arr::get($this->_z_labels, $column, ucfirst(Inflector::humanize($column))); $this->_z_labels[$column] = $label; $this->_z_fields[$column] = new $type($name, $id, $label, $config, $attributes, $field); } }
/** * @param array $options */ public function __construct(array $options) { $this->options = \Arr::overwrite($this->options, $options); }
public function hacer_registro_persona($id = NULL) { $exito = FALSE; $persona = $id == NULL ? Model::factory("persona") : Model::factory("persona", $id); // Hace la validacion if ($persona->values($_POST)->check()) { // Los datos han sido validados $persona->save(); $exito = $persona->id; } // Llenamos los vectores con los valores que seran mostrados en los campos $this->errores_persona = $persona->validate()->errors("usuario"); $this->formulario_persona = Arr::overwrite($this->formulario_persona, $_POST); return $exito; }
public function action_csv() { $this->auto_render = FALSE; $id = (int) Request::current()->param('id'); $orm_form = ORM::factory('form', $id); if (!$orm_form->loaded()) { throw new HTTP_Exception_404(); } $fields = array_flip(array('id', 'email', 'text', 'created')); $labels = Arr::overwrite($fields, $orm_form->responses->labels()); $list = $orm_form->responses->find_all(); $queue = array(); Database::instance()->set_charset('cp1251'); foreach ($list as $_orm) { $_values = array_map('Helper_CSV::escape', $_orm->as_array()); $_values = array_intersect_key($_values, $fields); $_item = array_combine($labels, $_values); $queue[] = array_filter($_item); } Database::instance()->set_charset('utf8'); Helper_CSV::instance()->send($queue); }
/** * Compiles the rules based on the scope into a single rule. * * @return void */ protected function compile() { // Initialize an array for the applicable rules $applicable_rules = array(); // Get the scope for this instance of ACL $scope = $this->scope(); // Resolve rules that currently have wildcards ACL::resolve_rules($scope); // Re-index the scope array with numbers for looping $scope = array_values($scope); // Get all the rules that could apply to this request for ($i = 2; $i >= 0; $i--) { // Get the key for the scope $key = ACL::key($scope); // Look in the rules array for a rule matching the key if ($rule = Arr::get(self::$_rules, $key, FALSE)) { $applicable_rules[$key] = $rule; } // Remove part of the scope so the next iteration can cascade to another rule $scope[$i] = ''; } // Get default rule $default_key = ACL::KEY_SEPARATOR . ACL::KEY_SEPARATOR; $applicable_rules[$default_key] = Arr::get(self::$_rules, $default_key); // Reverse the rules. Compile from the bottom up $applicable_rules = array_reverse($applicable_rules); // Compile the rule foreach ($applicable_rules as $rule) { $this->rule = Arr::overwrite($this->rule, $rule->as_array()); } }
protected function _set_value($value) { if (!$value) { return; } // Coming in from $_POST if (is_array($value)) { $this->_date = Arr::overwrite($this->_date, $value); } elseif (is_numeric($value)) { // do nothing } elseif (method_exists('DateTime', 'createFromFormat')) { $date = DateTime::createFromFormat($this->_config['format'], $value); if ($date instanceof DateTime) { $value = $date->format('U'); } else { $value = 0; } } elseif (preg_match("/([0-9]{2}):([0-9]{2}):([0-9]{2})/", $value)) { $value = strtotime(date('Y-m-d ') . $value); } else { $value = strtotime($value); } if (is_numeric($value)) { $this->_date = array('year' => date('Y', $value), 'month' => date('n', $value), 'day' => date('j', $value), 'hour' => date('h', $value), 'minute' => date('i', $value), 'second' => date('s', $value), 'meridien' => date('A', $value)); } $value = $this->_value_from_date(); parent::_set_value($value); }
public function __construct($config = NULL) { $this->_actions = Arr::overwrite($this->_actions, Arr::get($config, 'actions', array())); $this->_pos_data = Arr::overwrite($this->_pos_data, $config); }