Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1216

Přidáno uživatelem Ondřej Fibich před asi 13 roky(ů)

Novinky:

- dokonceni registrace instalace na FreeNetIS.org

Zobrazit rozdíly:

freenetis/branches/testing/application/libraries/Form_Upload.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Upload label(string $label)
* @method Form_Upload rules(string $rules)
* @method Form_Upload class(string $class)
* @method Form_Upload value(string $value)
*/
class Form_Upload extends Form_Input {
freenetis/branches/testing/application/libraries/Form_Checkbox.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Checkbox label(string $label)
* @method Form_Checkbox rules(string $rules)
* @method Form_Checkbox class(string $class)
* @method Form_Checkbox value(string $value)
* @method Form_Checkbox checked(bool $checked)
*/
class Form_Checkbox extends Form_Input {
freenetis/branches/testing/application/libraries/Form_Hidden.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Hidden rules(string $rules)
* @method Form_Hidden class(string $class)
* @method Form_GHidden value(string $value)
*/
class Form_Hidden extends Form_Input {
freenetis/branches/testing/application/libraries/Form_Html_textarea.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Html_textarea label(string $label)
* @method Form_Html_textarea rules(string $rules)
* @method Form_Html_textarea class(string $class)
* @method Form_Html_textarea value(string $value)
*/
class Form_Html_textarea extends Form_Input {
freenetis/branches/testing/application/libraries/Form_Submit.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Submit class(string $class)
* @method Form_Submit value(string $value)
*/
class Form_Submit extends Form_Input {
freenetis/branches/testing/application/libraries/Form_Checklist.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Checklist label(string $label)
* @method Form_Checklist rules(string $rules)
* @method Form_Checklist class(string $class)
* @method Form_Checklist value(string $value)
* @method Form_Checklist options(array $options)
*/
class Form_Checklist extends Form_Input {
freenetis/branches/testing/application/libraries/Form_Dateselect.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Dateselect label(string $label)
* @method Form_Dateselect rules(string $rules)
* @method Form_Dateselect class(string $class)
* @method Form_Dateselect months()
* @method Form_Dateselect days()
* @method Form_Dateselect years()
* @method Form_Dateselect hours()
* @method Form_Dateselect minutes()
* @method Form_Dateselect am_pms()
*/
class Form_Dateselect extends Form_Input {
freenetis/branches/testing/application/libraries/Form_Date.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
*
* @method Form_Date label(string $label)
* @method Form_Date rules(string $rules)
* @method Form_Date class(string $class)
* @method Form_Date months(int $month)
* @method Form_Date days(int $day)
* @method Form_Date years(int $year)
*/
class Form_Date extends Form_Input {
freenetis/branches/testing/application/libraries/Form_Textarea.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Textarea label(string $label)
* @method Form_Textarea rules(string $rules)
* @method Form_Textarea class(string $class)
* @method Form_Textarea value(string $value)
*/
class Form_Textarea extends Form_Input {
freenetis/branches/testing/application/libraries/Form_Group.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Group label(string $label)
* @method Form_Group rules(string $rules)
* @method Form_Group class(string $class)
* @method Form_Group value(string $value)
* @method Form_Group message(string $message)
*/
class Form_Group extends Forge {
......
$this->$key = $val;
}
/**
*
* @param string $val
* @return Form_Group
*/
public function label($val = NULL)
{
if ($val === NULL)
freenetis/branches/testing/application/libraries/Form_Dropdown.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Dropdown label(string $label)
* @method Form_Dropdown rules(string $rules)
* @method Form_Dropdown class(string $class)
* @method Form_Dropdown options(array $options)
* @method Form_Dropdown selected(int $selected_index)
*/
class Form_Dropdown extends Form_Input {
freenetis/branches/testing/application/libraries/Form_Radio.php
<?php defined('SYSPATH') or die('No direct script access.');
<?php defined('SYSPATH') or die('No direct script access.');
/**
* FORGE dropdown input library.
*
* @method Form_Radio label(string $label)
* @method Form_Radio rules(string $rules)
* @method Form_Radio class(string $class)
* @method Form_Radio value(string $value)
* @method Form_Radio options(array $options)
* @method Form_Radio onclick(string $script)
*/
class Form_Radio extends Form_Input
{
protected $data = array
(
'name' => '',
'class' => 'radio',
'type' => 'radio',
'options' => array(),
'onclick' => ''
);
protected $protect = array('type');
/** * FORGE dropdown input library. * */
public function __get($key)
{
if ($key == 'value')
{
return $this->selected;
}
return parent::__get($key);
}
class Form_Radio extends Form_Input {
public function html_element()
{
// Import base data
$data = $this->data;
protected $data = array (
'name' => '',
'class' => 'radio',
'type'=>'radio',
'options'=>array(),
'onclick' => ''
);
protected $protect = array('type');
public function __get($key)
{
if ($key == 'value')
{
return $this->selected;
}
return parent::__get($key);
}
public function html_element()
{
// Import base data
$data = $this->data;
// Get the options and default selection
$options = arr::remove('options', $data);
$selected = arr::remove('selected', $data);
$options = arr::remove('options', $data);
$selected = arr::remove('selected', $data);
// martin hack
unset($data['label']);
unset($data['help']);
......
switch ($rule)
{
case 'valid_numeric':
$data['class'][] = 'number';
break;
$data['class'][] = 'number';
break;
case 'valid_email':
$data['class'][] = 'email';
break;
$data['class'][] = 'email';
break;
case 'valid_mac_address':
$data['class'][] = 'mac_address';
break;
$data['class'][] = 'mac_address';
break;
case 'valid_ip_address':
$data['class'][] = 'ip_address';
break;
$data['class'][] = 'ip_address';
break;
case 'valid_suffix':
$data['class'][] = 'suffix';
break;
$data['class'][] = 'suffix';
break;
case 'valid_clean_urls':
$data['class'][] = 'clean_urls';
break;
$data['class'][] = 'clean_urls';
break;
default:
if (preg_match ("/length\[([0-9]+),([0-9]+)\]/", $rule, $matches))
{
$data['minlength'] = $matches[1];
$data['maxlength'] = $matches[2];
}
break;
if (preg_match("/length\[([0-9]+),([0-9]+)\]/", $rule, $matches))
{
$data['minlength'] = $matches[1];
$data['maxlength'] = $matches[2];
}
break;
}
}
$data['class'] = implode (' ',$data['class']);
$data['class'] = implode(' ', $data['class']);
$next_data = '';
$next = false;
$next_data = '';
$next=false;
foreach ($data as $key=>$val) {
if ($key == 'type') $next = true;
if ($next) $next_data .= $key.'="'.$val.'"';
foreach ($data as $key => $val)
{
if ($key == 'type')
$next = true;
if ($next)
$next_data .= $key . '="' . $val . '"';
}
$html ='';
foreach($options as $option=>$labelText)
{
$html = '';
foreach ($options as $option => $labelText)
{
$html .= form::radio(array
(
'name' => $data['name'],
'class' => $data['class'],
'id' => $data['name'] . "_" . $option
), $option, $this->value ? $this->value == $option : $data['default'] == $option, $next_data);
$html .= form::radio(array ('name'=>$data['name'], 'class'=>$data['class'], 'id'=>$data['name']."_".$option) , $option , $this->value? $this->value==$option: $data['default']==$option,$next_data). form::label($data['name']."_".$option , $labelText)." ";
}
return $html;
}
protected function load_value()
{
if (is_bool($this->valid)) return;
$this->data['selected'] = $this->input_value($this->name);
}
} // End Form radio
$html .= form::label($data['name'] . "_" . $option, $labelText) . " ";
}
return $html;
}
protected function load_value()
{
if (is_bool($this->valid))
return;
$this->data['selected'] = $this->input_value($this->name);
}
}
// End Form radio
freenetis/branches/testing/application/libraries/Form_Input.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Input rules(string $rules)
* @method Form_Input name(string $name)
* @method Form_Input type(string $type)
* @method Form_Input class(string $class)
* @method Form_Input value(string $value)
*/
class Form_Input {
class Form_Input
{
// Input method
public $method;
// Element data
protected $data = array
(
'type' => 'text',
'class' => 'textbox',
'value' => ''
'type' => 'text',
'class' => 'textbox',
'value' => ''
);
// Protected data keys
protected $protect = array();
// Validation rules, matches, and callbacks
protected $rules = array();
protected $matches = array();
protected $callbacks = array();
// Validation check
protected $is_valid;
// Errors
protected $errors = array();
protected $error_messages = array();
......
return $this->rules;
// Set rules and action
$rules = $args[0];
$rules = $args[0];
$action = substr($rules, 0, 1);
if (in_array($action, array('-', '+', '=')))
......
*/
public function matches($input)
{
if ( ! in_array($input, $this->matches, TRUE))
if (!in_array($input, $this->matches, TRUE))
{
$this->matches[] = $input;
}
......
*/
public function callback($callback)
{
if ( ! in_array($callback, $this->callbacks, TRUE))
if (!in_array($callback, $this->callbacks, TRUE))
{
$this->callbacks[] = $callback;
}
......
}
}
public function help($val = NULL)
{
if ($val === NULL)
{
if (isset($this->data['help']))
public function help($val = NULL)
{
if ($val === NULL)
{
if (isset($this->data['help']))
return $this->data['help'];
}
else
{
$this->data['help'] = $val;
return $this;
}
}
}
else
{
$this->data['help'] = $val;
return $this;
}
}
public function script($type, $val = NULL)
{
if ($val === NULL)
{
if (isset($this->data[$type]))
{
if ($val === NULL)
{
if (isset($this->data[$type]))
return $this->data[$type];
}
else
{
$this->data[$type] = $val;
return $this;
}
}
}
else
{
$this->data[$type] = $val;
return $this;
}
}
/**
* Set or return the error message.
*
......
foreach ($this->rules as $rule)
{
if (substr($rule,0,6)=='valid_')
if (substr($rule, 0, 6) == 'valid_')
{
$arr = explode('_',$rule);
$arr = explode('_', $rule);
array_shift($arr);
$rule = implode('_',$arr);
$rule = implode('_', $arr);
$rule = (isset($alias[$rule])) ? $alias[$rule] : $rule;
......
}
else
{
if (preg_match ("/length\[([0-9]+),([0-9]+)\]/", $rule, $matches))
if (preg_match("/length\[([0-9]+),([0-9]+)\]/", $rule, $matches))
{
$data['minlength'] = $matches[1];
$data['maxlength'] = $matches[2];
$data['minlength'] = $matches[1];
$data['maxlength'] = $matches[2];
}
}
}
......
foreach ($this->callbacks as $callback)
{
$callback = $callback[1];
if (substr($callback,0,6)=='valid_')
if (substr($callback, 0, 6) == 'valid_')
{
$arr = explode('_',$callback);
$arr = explode('_', $callback);
array_shift($arr);
$callback = implode('_',$arr);
$callback = implode('_', $arr);
$callback = (isset($alias[$callback])) ? $alias[$callback] : $callback;
......
}
}
$data['class'] = implode (' ',$data['class']);
$data['class'] = implode(' ', $data['class']);
return form::input($data);
}
......
* @param array rules to change
* @param string action to use: replace, remove, append
*/
protected function add_rules( array $rules, $action)
protected function add_rules(array $rules, $action)
{
if ($action === '=')
{
......
return;
}
foreach($rules as $rule)
foreach ($rules as $rule)
{
if ($action === '-')
{
......
}
else
{
if ( ! in_array($rule, $this->rules))
if (!in_array($rule, $this->rules))
{
if ($action == '+')
{
......
*/
public function add_error($key, $val)
{
if ( ! isset($this->errors[$key]))
if (!isset($this->errors[$key]))
{
$this->errors[$key] = $val;
}
......
public function error_messages($func = NULL, $message = NULL)
{
// Set custom error messages
if ( ! empty($func))
if (!empty($func))
{
if (is_array($func))
{
......
is_null($this->is_valid) and $this->validate();
// Return single error
if ( ! is_array($this->error_messages) AND ! empty($this->errors))
if (!is_array($this->error_messages) AND !empty($this->errors))
return array($this->error_messages);
$messages = array();
foreach($this->errors as $func => $args)
foreach ($this->errors as $func => $args)
{
if (is_string($args))
{
......
else
{
// Get the proper i18n entry, very hacky but it works
switch($func)
switch ($func)
{
case 'valid_url':
case 'valid_email':
case 'valid_ip':
// Fetch an i18n error message
$error = Kohana::lang('validation.'.$func, $args);
$error = Kohana::lang('validation.' . $func, $args);
break;
case 'valid_suffix':
$error = Kohana::lang('validation.valid_suffix', $args);
......
case 'digit':
case 'numeric':
// i18n strings have to be inserted into valid_type
$args[] = Kohana::lang('validation.'.$func);
$args[] = Kohana::lang('validation.' . $func);
$error = Kohana::lang('validation.valid_type', $args);
break;
default:
$error = Kohana::lang('validation.'.$func, $args);
$error = Kohana::lang('validation.' . $func, $args);
}
}
}
......
{
$name = func_get_arg(0);
if (preg_match ("/^([^\[]+)(\[([0-9]+)\])+$/", $name, $matches))
if (preg_match("/^([^\[]+)(\[([0-9]+)\])+$/", $name, $matches))
{
$name = $matches[1];
$value = $input->$method($name);
......
}
return $input->$method($name);
}
else
return $input->$method();
......
// No data to validate
if ($this->input_value() == FALSE)
return $this->is_valid = FALSE;
// Load the submitted value
$this->load_value();
......
if (count($this->rules) == 0 AND count($this->matches) == 0 AND count($this->callbacks) == 0)
return $this->is_valid = TRUE;
if ( ! empty($this->rules))
if (!empty($this->rules))
{
foreach($this->rules as $rule)
foreach ($this->rules as $rule)
{
if (($offset = strpos($rule, '[')) !== FALSE)
{
......
{
$func = substr($rule, 6);
if ($this->value AND ! valid::$func($this->value))
if ($this->value AND !valid::$func($this->value))
{
$this->errors[$rule] = TRUE;
}
}
elseif (method_exists($this, 'rule_'.$rule))
elseif (method_exists($this, 'rule_' . $rule))
{
// The rule function is always prefixed with rule_
$rule = 'rule_'.$rule;
$rule = 'rule_' . $rule;
if (isset($args))
{
// Manually call up to 2 args for speed
switch(count($args))
switch (count($args))
{
case 1:
$this->$rule($args[0]);
break;
break;
case 2:
$this->$rule($args[0], $args[1]);
break;
break;
default:
call_user_func_array(array($this, $rule), $args);
break;
break;
}
}
else
......
}
// Stop when an error occurs
if ( ! empty($this->errors))
if (!empty($this->errors))
break;
}
}
if ( ! empty($this->matches))
if (!empty($this->matches))
{
foreach($this->matches as $input)
foreach ($this->matches as $input)
{
if ($this->value != $input->value)
{
......
}
}
if ( ! empty($this->callbacks))
if (!empty($this->callbacks))
{
foreach($this->callbacks as $callback)
foreach ($this->callbacks as $callback)
{
call_user_func($callback, $this);
// Stop when an error occurs
if ( ! empty($this->errors))
if (!empty($this->errors))
break;
}
}
......
{
if ($this->value)
{
if (preg_match("/^[0-9]+\.[0-9]+$/", strval($this->value)) == 0)
if (preg_match("/^[0-9]+\.[0-9]+$/", strval($this->value)) == 0)
{
if (! gps::is_valid_degrees_coordinate(strval($this->value)))
if (!gps::is_valid_degrees_coordinate(strval($this->value)))
{
$this->errors['gps'] = TRUE;
}
......
{
$this->errors['min_length'] = array($min);
}
elseif($length > $max)
elseif ($length > $max)
{
$this->errors['max_length'] = array($max);
}
}
}
} // End Form Input
}
// End Form Input
freenetis/branches/testing/application/libraries/Form_Password.php
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*
* @method Form_Password label(string $label)
* @method Form_Password rules(string $rules)
* @method Form_Password class(string $class)
* @method Form_Password value(string $value)
*/
class Form_Password extends Form_Input {

Také k dispozici: Unified diff