Added HTML class
This commit is contained in:
parent
2cb9577ca2
commit
e70dccafd7
4 changed files with 299 additions and 6 deletions
|
@ -9,7 +9,7 @@
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <pickles@joshtronic.com>
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
* @copyright Copyright 2007-2012, Josh Sherman
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @package PICKLES
|
* @package PICKLES
|
||||||
* @link https://github.com/joshtronic/pickles
|
* @link https://github.com/joshtronic/pickles
|
||||||
|
@ -71,11 +71,13 @@ class Display_PHP extends Display_Common
|
||||||
$__fluid = $this->fluid;
|
$__fluid = $this->fluid;
|
||||||
|
|
||||||
// Creates (possibly overwritten) objects
|
// Creates (possibly overwritten) objects
|
||||||
$form_class = (class_exists('CustomForm') ? 'CustomForm' : 'Form');
|
|
||||||
$dynamic_class = (class_exists('CustomDynamic') ? 'CustomDynamic' : 'Dynamic');
|
$dynamic_class = (class_exists('CustomDynamic') ? 'CustomDynamic' : 'Dynamic');
|
||||||
|
$form_class = (class_exists('CustomForm') ? 'CustomForm' : 'Form');
|
||||||
|
$html_class = (class_exists('CustomHTML') ? 'CustomHTML' : 'HTML');
|
||||||
|
|
||||||
$__form = new $form_class();
|
|
||||||
$__dynamic = new $dynamic_class();
|
$__dynamic = new $dynamic_class();
|
||||||
|
$__form = new $form_class();
|
||||||
|
$__html = new $html_class();
|
||||||
|
|
||||||
// Loads the template
|
// Loads the template
|
||||||
if ($this->parent_template != null)
|
if ($this->parent_template != null)
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
*
|
*
|
||||||
* This class contains methods for easily generating form elements. There is a
|
* This class contains methods for easily generating form elements. There is a
|
||||||
* heavy focus on select boxes as they have the most overhead for a developer.
|
* heavy focus on select boxes as they have the most overhead for a developer.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
class Form extends Object
|
class Form extends Object
|
||||||
{
|
{
|
||||||
|
|
144
classes/HTML.php
Normal file
144
classes/HTML.php
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML Class File for PICKLES
|
||||||
|
*
|
||||||
|
* PHP version 5
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
|
* @package PICKLES
|
||||||
|
* @link https://github.com/joshtronic/pickles
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML Class
|
||||||
|
*
|
||||||
|
* This class contains methods for easily generating HTML elements.
|
||||||
|
*/
|
||||||
|
class HTML extends Object
|
||||||
|
{
|
||||||
|
private $self_closing = array('br', 'hr', 'img', 'input', 'link', 'meta');
|
||||||
|
|
||||||
|
public function __call($method, $arguments)
|
||||||
|
{
|
||||||
|
|
||||||
|
$attributes = null;
|
||||||
|
$contents = null;
|
||||||
|
|
||||||
|
if (isset($arguments[0]))
|
||||||
|
{
|
||||||
|
$attributes = $arguments[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($arguments[1]))
|
||||||
|
{
|
||||||
|
$contents = $arguments[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ->inputType('name', $attributes);
|
||||||
|
if (preg_match('/^input/', $method))
|
||||||
|
{
|
||||||
|
$type = strtolower(str_replace('input', '', $method));
|
||||||
|
|
||||||
|
switch ($type)
|
||||||
|
{
|
||||||
|
case 'datetimelocal': $type = 'datetime-local'; break;
|
||||||
|
case '': $type = 'text'; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($attributes))
|
||||||
|
{
|
||||||
|
$attributes['type'] = $type;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$attributes = array('type' => $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($attributes['label'], $attributes['name']))
|
||||||
|
{
|
||||||
|
$label = $this->label(array('for' => $attributes['name']), $attributes['label']);
|
||||||
|
unset($attributes['label']);
|
||||||
|
|
||||||
|
return $label . $this->div($this->input($attributes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->element($method, $attributes, $contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
// {{{ Get Instance
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Instance
|
||||||
|
*
|
||||||
|
* Gets an instance of the Form class
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param string $class name of the class to get an instance of
|
||||||
|
* @return object instance of the class
|
||||||
|
*/
|
||||||
|
public static function getInstance($class = 'HTML')
|
||||||
|
{
|
||||||
|
return parent::getInstance($class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
public function element($element)
|
||||||
|
{
|
||||||
|
$attributes = null;
|
||||||
|
$contents = null;
|
||||||
|
|
||||||
|
foreach (func_get_args() as $key => $value)
|
||||||
|
{
|
||||||
|
if ($key && $key < 3)
|
||||||
|
{
|
||||||
|
if (is_array($value))
|
||||||
|
{
|
||||||
|
$attributes = $value;
|
||||||
|
}
|
||||||
|
elseif ($value)
|
||||||
|
{
|
||||||
|
$contents = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = strtolower($element);
|
||||||
|
$html = '<' . $element;
|
||||||
|
|
||||||
|
if ($attributes)
|
||||||
|
{
|
||||||
|
if (is_array($attributes))
|
||||||
|
{
|
||||||
|
foreach ($attributes as $attribute => $value)
|
||||||
|
{
|
||||||
|
$html .= ' ' . $attribute . '="' . str_replace('"', '\"', $value) . '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception('Attributes must be an array.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($contents || !in_array($element, $this->self_closing))
|
||||||
|
{
|
||||||
|
$html .= '>' . $contents . '</' . $element . '>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$html .= ' />';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
151
jar.php
151
jar.php
|
@ -2588,7 +2588,7 @@ class Display_JSON extends Display_Common
|
||||||
* Redistribution of these files must retain the above copyright notice.
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @author Josh Sherman <pickles@joshtronic.com>
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
* @copyright Copyright 2007-2012, Josh Sherman
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
* @package PICKLES
|
* @package PICKLES
|
||||||
* @link https://github.com/joshtronic/pickles
|
* @link https://github.com/joshtronic/pickles
|
||||||
|
@ -2650,11 +2650,13 @@ class Display_PHP extends Display_Common
|
||||||
$__fluid = $this->fluid;
|
$__fluid = $this->fluid;
|
||||||
|
|
||||||
// Creates (possibly overwritten) objects
|
// Creates (possibly overwritten) objects
|
||||||
$form_class = (class_exists('CustomForm') ? 'CustomForm' : 'Form');
|
|
||||||
$dynamic_class = (class_exists('CustomDynamic') ? 'CustomDynamic' : 'Dynamic');
|
$dynamic_class = (class_exists('CustomDynamic') ? 'CustomDynamic' : 'Dynamic');
|
||||||
|
$form_class = (class_exists('CustomForm') ? 'CustomForm' : 'Form');
|
||||||
|
$html_class = (class_exists('CustomHTML') ? 'CustomHTML' : 'HTML');
|
||||||
|
|
||||||
$__form = new $form_class();
|
|
||||||
$__dynamic = new $dynamic_class();
|
$__dynamic = new $dynamic_class();
|
||||||
|
$__form = new $form_class();
|
||||||
|
$__html = new $html_class();
|
||||||
|
|
||||||
// Loads the template
|
// Loads the template
|
||||||
if ($this->parent_template != null)
|
if ($this->parent_template != null)
|
||||||
|
@ -3489,6 +3491,8 @@ class File
|
||||||
*
|
*
|
||||||
* This class contains methods for easily generating form elements. There is a
|
* This class contains methods for easily generating form elements. There is a
|
||||||
* heavy focus on select boxes as they have the most overhead for a developer.
|
* heavy focus on select boxes as they have the most overhead for a developer.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
class Form extends Object
|
class Form extends Object
|
||||||
{
|
{
|
||||||
|
@ -4146,6 +4150,147 @@ class Form extends Object
|
||||||
// }}}
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML Class File for PICKLES
|
||||||
|
*
|
||||||
|
* PHP version 5
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistribution of these files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @author Josh Sherman <pickles@joshtronic.com>
|
||||||
|
* @copyright Copyright 2007-2013, Josh Sherman
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.html
|
||||||
|
* @package PICKLES
|
||||||
|
* @link https://github.com/joshtronic/pickles
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML Class
|
||||||
|
*
|
||||||
|
* This class contains methods for easily generating HTML elements.
|
||||||
|
*/
|
||||||
|
class HTML extends Object
|
||||||
|
{
|
||||||
|
private $self_closing = array('br', 'hr', 'img', 'input', 'link', 'meta');
|
||||||
|
|
||||||
|
public function __call($method, $arguments)
|
||||||
|
{
|
||||||
|
|
||||||
|
$attributes = null;
|
||||||
|
$contents = null;
|
||||||
|
|
||||||
|
if (isset($arguments[0]))
|
||||||
|
{
|
||||||
|
$attributes = $arguments[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($arguments[1]))
|
||||||
|
{
|
||||||
|
$contents = $arguments[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ->inputType('name', $attributes);
|
||||||
|
if (preg_match('/^input/', $method))
|
||||||
|
{
|
||||||
|
$type = strtolower(str_replace('input', '', $method));
|
||||||
|
|
||||||
|
switch ($type)
|
||||||
|
{
|
||||||
|
case 'datetimelocal': $type = 'datetime-local'; break;
|
||||||
|
case '': $type = 'text'; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($attributes))
|
||||||
|
{
|
||||||
|
$attributes['type'] = $type;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$attributes = array('type' => $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($attributes['label'], $attributes['name']))
|
||||||
|
{
|
||||||
|
$label = $this->label(array('for' => $attributes['name']), $attributes['label']);
|
||||||
|
unset($attributes['label']);
|
||||||
|
|
||||||
|
return $label . $this->div($this->input($attributes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->element($method, $attributes, $contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
// {{{ Get Instance
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Instance
|
||||||
|
*
|
||||||
|
* Gets an instance of the Form class
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param string $class name of the class to get an instance of
|
||||||
|
* @return object instance of the class
|
||||||
|
*/
|
||||||
|
public static function getInstance($class = 'HTML')
|
||||||
|
{
|
||||||
|
return parent::getInstance($class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
public function element($element)
|
||||||
|
{
|
||||||
|
$attributes = null;
|
||||||
|
$contents = null;
|
||||||
|
|
||||||
|
foreach (func_get_args() as $key => $value)
|
||||||
|
{
|
||||||
|
if ($key && $key < 3)
|
||||||
|
{
|
||||||
|
if (is_array($value))
|
||||||
|
{
|
||||||
|
$attributes = $value;
|
||||||
|
}
|
||||||
|
elseif ($value)
|
||||||
|
{
|
||||||
|
$contents = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = strtolower($element);
|
||||||
|
$html = '<' . $element;
|
||||||
|
|
||||||
|
if ($attributes)
|
||||||
|
{
|
||||||
|
if (is_array($attributes))
|
||||||
|
{
|
||||||
|
foreach ($attributes as $attribute => $value)
|
||||||
|
{
|
||||||
|
$html .= ' ' . $attribute . '="' . str_replace('"', '\"', $value) . '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception('Attributes must be an array.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($contents || !in_array($element, $this->self_closing))
|
||||||
|
{
|
||||||
|
$html .= '>' . $contents . '</' . $element . '>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$html .= ' />';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logging System for PICKLES
|
* Logging System for PICKLES
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue