* @version $Id$
*/
+// {{{ smarty_modifier_number_format
/**
* smarty modifier:number_format()
*
}
return number_format($string);
}
+// }}}
+// {{{ smarty_modifier_strftime
/**
* smarty modifier:strftime()
*
}
return strftime($format, strtotime($string));
}
+// }}}
+// {{{ smarty_modifier_count
/**
* smarty modifier:count()
*
{
return count($array);
}
+// }}}
+// {{{ smarty_modifier_join
/**
* smarty modifier:join()
*
}
return implode($glue, $array);
}
+// }}}
+// {{{ smarty_modifier_filter
/**
* smarty modifier:filter()
*
}
return $tmp;
}
+// }}}
+// {{{ smarty_modifier_unique
/**
* smarty modifier:unique()
*
return array_unique($array);
}
}
+// }}}
+// {{{ smarty_modifier_wordwrap_i18n
/**
* smarty modifier:ʸ»úÎó¤Îwordwrap½èÍý
*
return $r;
}
+// }}}
+// {{{ smarty_modifier_truncate_i18n
/**
* smarty modifier:ʸ»úÎóÀÚ¤êµÍ¤á½èÍý(i18nÂбþ)
*
{
return mb_strimwidth($string, 0, $len, $postfix);
}
+// }}}
+// {{{ smarty_modifier_i18n
/**
* smarty modifier:i18n¥Õ¥£¥ë¥¿
*
return $i18n->get($string);
}
+// }}}
+// {{{ smarty_modifier_checkbox
/**
* smarty modifier:¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹ÍÑ¥Õ¥£¥ë¥¿
*
return "checked";
}
}
+// }}}
+// {{{ smarty_modifier_select
/**
* smarty modifier:¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÍÑ¥Õ¥£¥ë¥¿
*
function smarty_modifier_select($string, $value)
{
if ($string == $value) {
- print 'selected="true"';
+ return 'selected="true"';
}
}
+// }}}
+// {{{ smarty_modifier_form_value
/**
* smarty modifier:¥Õ¥©¡¼¥àÃͽÐÎÏ¥Õ¥£¥ë¥¿
*
return htmlspecialchars($r, ENT_QUOTES);
}
+// }}}
+// {{{ smarty_function_is_error
/**
* smarty function:»ØÄꤵ¤ì¤¿¥Õ¥©¡¼¥à¹àÌܤǥ¨¥é¡¼¤¬È¯À¸¤·¤Æ¤¤¤ë¤«¤É¤¦¤«¤òÊÖ¤¹
- *
- * sample:
- * <code>
- * {if is_error('name')}
- * ¥¨¥é¡¼
- * {/if}
- * </code>
+ * NOTE: {if is_error('name')} ¤Ï Ethna_Util.php ¤Î is_error() ¤Ç¤¢¤Ã¤Æ¡¢
+ * smarty_function_is_error() ¤Ç¤Ï¤Ê¤¤¤³¤È¤ËÃí°Õ
*
* @param string $name ¥Õ¥©¡¼¥à¹àÌÜ̾
*/
function smarty_function_is_error($params, &$smarty)
{
- $c =& Ethna_Controller::getInstance();
-
- extract($params);
-
- $action_error =& $c->getActionError();
-
- return $action_error->isError($name);
+ $name = isset($params['name']) ? $params['name'] : null;
+ return is_error($name);
}
+// }}}
+// {{{ smarty_function_message
/**
* smarty function:»ØÄꤵ¤ì¤¿¥Õ¥©¡¼¥à¹àÌܤËÂбþ¤¹¤ë¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤ò½ÐÎϤ¹¤ë
*
*/
function smarty_function_message($params, &$smarty)
{
- $c =& Ethna_Controller::getInstance();
-
- extract($params);
+ if (isset($params['name']) === false) {
+ return '';
+ }
+ $c =& Ethna_Controller::getInstance();
$action_error =& $c->getActionError();
- print htmlspecialchars($action_error->getMessage($name));
+ $message = $action_error->getMessage($params['name']);
+ if ($message === null) {
+ return '';
+ }
+
+ $id = isset($params['id']) ? $params['id']
+ : str_replace("_", "-", "ethna-error-" . $params['name']);
+ $class = isset($params['class']) ? $params['class'] : "ethna-error";
+ return sprintf('<span class="%s" id="%s">%s</span>',
+ $class, $id, htmlspecialchars($message));
}
+// }}}
+// {{{ smarty_function_uniqid
/**
* smarty function:¥æ¥Ë¡¼¥¯ID¤òÀ¸À®¤¹¤ë(double post¥Á¥§¥Ã¥¯ÍÑ)
*
*/
function smarty_function_uniqid($params, &$smarty)
{
- extract($params);
-
$uniqid = Ethna_Util::getRandom();
- if (isset($type) && $type == 'get') {
- print "uniqid=$uniqid";
+ if (isset($params['type']) && $params['type'] == 'get') {
+ return "uniqid=$uniqid";
} else {
- print "<input type=\"hidden\" name=\"uniqid\" value=\"$uniqid\" />\n";
+ return "<input type=\"hidden\" name=\"uniqid\" value=\"$uniqid\" />\n";
}
}
+// }}}
+// {{{ smarty_function_select
/**
* smarty function:¥»¥ì¥¯¥È¥Õ¥£¡¼¥ë¥ÉÀ¸À®
*
* @param string $name ¥Õ¥©¡¼¥à¹àÌÜ̾
* @param string $value ¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹¤ËÅϤµ¤ì¤¿¥Õ¥©¡¼¥àÃÍ
* @param string $empty ¶õ¥¨¥ó¥È¥ê(¡Ö---ÁªÂò¤·¤Æ²¼¤µ¤¤---¡×Åù)
+ * @deprecated
*/
function smarty_function_select($params, &$smarty)
{
}
print "</select>\n";
}
+// }}}
+// {{{ smarty_function_checkbox_list
/**
* smarty function:¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¥Õ¥£¥ë¥¿´Ø¿ô(ÇÛÎóÂбþ)
*
* @param string $form ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤ËÅϤµ¤ì¤¿¥Õ¥©¡¼¥àÃÍ
* @param string $key ɾ²ÁÂоݤÎÇÛÎ󥤥ó¥Ç¥Ã¥¯¥¹
* @param string $value ɾ²ÁÃÍ
+ * @deprecated
*/
function smarty_function_checkbox_list($params, &$smarty)
{
}
}
}
+// }}}
+// {{{ smarty_function_url
/**
* smarty function:urlÀ¸À®
*/
return $url;
}
+// }}}
+// {{{ smarty_function_form_name
/**
* smarty function:¥Õ¥©¡¼¥àɽ¼¨Ì¾À¸À®
*
*/
function smarty_function_form_name($params, &$smarty)
{
+ // name
if (isset($params['name']) == false) {
return null;
}
$name = $params['name'];
unset($params['name']);
+ // action
+ $action = null;
+ if (isset($params['action'])) {
+ $action = $params['action'];
+ unset($params['action']);
+ } else {
+ for ($i = count($smarty->_tag_stack); $i >= 0; --$i) {
+ if ($smarty->_tag_stack[$i][0] === 'form') {
+ if (isset($smarty->_tag_stack[$i][1]['ethna_action'])) {
+ $action = $smarty->_tag_stack[$i][1]['ethna_action'];
+ }
+ break;
+ }
+ }
+ }
+
$c =& Ethna_Controller::getInstance();
$view =& $c->getView();
if ($view === null) {
return null;
}
- print $view->getFormName($name, $params);
+ $view->addActionFormHelper($action);
+ return $view->getFormName($name, $action, $params);
}
+// }}}
+// {{{ smarty_function_form_submit
+/**
+ * smarty function:¥Õ¥©¡¼¥à¤Îsubmit¥Ü¥¿¥óÀ¸À®
+ *
+ * @param string $submit ¥Õ¥©¡¼¥à¹àÌÜ̾
+ */
+function smarty_function_form_submit($params, &$smarty)
+{
+ if (isset($params['name'])) {
+ $name = $params['name'];
+ unset($params['name']);
+ } else {
+ $name = 'submit';
+ }
+
+ $c =& Ethna_Controller::getInstance();
+ $view =& $c->getView();
+ if ($view === null) {
+ return null;
+ }
+ return $view->getFormSubmit($name, $params);
+}
+// }}}
+
+// {{{ smarty_function_form_input
/**
* smarty function:¥Õ¥©¡¼¥à¥¿¥°À¸À®
*
*/
function smarty_function_form_input($params, &$smarty)
{
- if (isset($params['name']) == false) {
+ // name
+ if (isset($params['name'])) {
+ $name = $params['name'];
+ unset($params['name']);
+ } else {
return null;
}
- $name = $params['name'];
- unset($params['name']);
+
+ // ¸½ºß¤Î{form_input}¤ò°Ï¤àform block¤¬¤¢¤ì¤Ð¥Ñ¥é¥á¡¼¥¿¤ò¼èÆÀ¤·¤Æ¤ª¤¯
+ // c.f. http://smarty.php.net/manual/en/plugins.block.functions.php
+ $block_params = null;
+ for ($i = count($smarty->_tag_stack); $i >= 0; --$i) {
+ if ($smarty->_tag_stack[$i][0] === 'form') {
+ $block_params = $smarty->_tag_stack[$i][1];
+ break;
+ }
+ }
+
+ // action
+ $action = null;
+ if (isset($params['action'])) {
+ $action = $params['action'];
+ unset($params['action']);
+ } else if (isset($block_params['ethna_action'])) {
+ $action = $block_params['ethna_action'];
+ }
+
+ // default
+ if (isset($params['default']) === false) {
+ // {form_input default="foo"} ¤Î»ØÄ꤬¤Ê¤¤¤È¤¤Ï
+ // ³°Â¦¤Î¥Ö¥í¥Ã¥¯¤«¤édefaultÃͤò¼èÆÀ
+ if (isset($block_params['default'][$name])) {
+ $params['default'] = $block_params['default'][$name];
+ }
+ }
$c =& Ethna_Controller::getInstance();
$view =& $c->getView();
if ($view === null) {
return null;
}
- print $view->getFormInput($name, $params);
+ $view->addActionFormHelper($action);
+ return $view->getFormInput($name, $action, $params);
}
+// }}}
+// {{{ smarty_block_form
/**
* smarty block:¥Õ¥©¡¼¥à¥¿¥°½ÐÎϥץ饰¥¤¥ó
*/
function smarty_block_form($params, $content, &$smarty, &$repeat)
{
- extract($params);
-
- $s = "";
if ($repeat) {
- $s = "<form";
-
- // fundamentals
- if ($action !== false) {
- if (isset($action) == false) {
- $action = basename($_SERVER['PHP_SELF']);
- }
- $s .= sprintf(' action="%s"', htmlspecialchars($action, ENT_QUOTES));
- }
- if ($method !== false) {
- if (isset($method) == false) {
- $method = "post";
- }
- $s .= sprintf(' method="%s"', htmlspecialchars($method, ENT_QUOTES));
+ return '';
+ } else {
+ $c =& Ethna_Controller::getInstance();
+ $view =& $c->getView();
+ if ($view === null) {
+ return null;
}
- // enctype¤Ïdefault off(-> "!=")
- // + Ãͤ¬¤á¤ó¤É¤¤¤Î¤Çά¾ÎÂбþ("file"¤È¤«...¤¦¤¥¤à?)
- if ($enctype != "") {
- if ($enctype == "file" || $enctype == "multipart") {
- $enctype = "multipart/form-data";
- } else if ($enctype == "url") {
- $enctype = "application/x-www-form-urlencoded";
- }
- $s .= sprintf(' enctype="%s"', htmlspecialchars($enctype, ENT_QUOTES));
+ // ethna_action
+ if (isset($params['ethna_action'])) {
+ $ethna_action = $params['ethna_action'];
+ unset($params['ethna_action']);
+
+ $view->addActionFormHelper($ethna_action);
+ $hidden = $c->getActionRequest($ethna_action, 'hidden');
+ $content = $hidden . $content;
}
- // additionals
- foreach (array('accept', 'accept-charset', 'autocomplete', 'class', 'id', 'lang', 'name', 'style', 'target', 'title', 'urn') as $key) {
- if (${$key} != "") {
- $s .= sprintf(' %s="%s"', $key, htmlspecialchars(${$key}, ENT_QUOTES));
+ // enctype ¤Îά¾ÎÂбþ
+ if (isset($params['enctype'])) {
+ if ($params['enctype'] == 'file'
+ || $params['enctype'] == 'multipart') {
+ $params['enctype'] = 'multipart/form-data';
+ } else if ($params['enctype'] == 'url') {
+ $params['enctype'] = 'application/x-www-form-urlencoded';
}
}
- $s .= ">";
-
- if ($ethna_action != "") {
- $c =& Ethna_Controller::getInstance();
- $s .= $c->getActionRequest($ethna_action, "hidden");
+ // ¤³¤Îdefault¤ÏblockÆâ¤Îform_input¤Ç¤Î¤ß»È¤¦
+ // ($smarty->_tag_stack¤¬ÊÝ»ý)
+ if (isset($params['default'])) {
+ unset($params['default']);
}
- } else {
- print $content;
- $s = "</form>";
+
+ return $view->getFormBlock($content, $params);
}
- print $s;
}
+// }}}
?>
/** @var object Ethna_I18N i18n¥ª¥Ö¥¸¥§¥¯¥È */
var $i18n;
+ /** @var object Ethna_Logger ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È */
+ var $logger;
+
/** @var object Ethna_ActionError ¥¢¥¯¥·¥ç¥ó¥¨¥é¡¼¥ª¥Ö¥¸¥§¥¯¥È */
var $action_error;
/**#@-*/
+ // {{{ Ethna_ViewClass
/**
* Ethna_ViewClass¤Î¥³¥ó¥¹¥È¥é¥¯¥¿
*
$this->backend =& $backend;
$this->config =& $this->backend->getConfig();
$this->i18n =& $this->backend->getI18N();
+ $this->logger =& $this->backend->getLogger();
$this->action_error =& $this->backend->getActionError();
$this->ae =& $this->action_error;
$this->helper_action_form[$key] =& $this->_getHelperActionForm($key);
}
}
+ // }}}
+ // {{{ preforward
/**
* ²èÌÌɽ¼¨Á°½èÍý
*
function preforward()
{
}
+ // }}}
+ // {{{ forward
/**
* Á«°Ü̾¤ËÂбþ¤¹¤ë²èÌ̤ò½ÐÎϤ¹¤ë
*
$this->_setDefault($renderer);
$renderer->perform($this->forward_path);
}
+ // }}}
+ // {{{ addActionFormHelper
/**
* helper¥¢¥¯¥·¥ç¥ó¥Õ¥©¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÀßÄꤹ¤ë
*
}
$this->helper_action_form[$action] =& $this->_getHelperActionForm($action);
}
+ // }}}
+ // {{{ clearActionFormHelper
/**
* helper¥¢¥¯¥·¥ç¥ó¥Õ¥©¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òºï½ü¤¹¤ë
*
{
unset($this->helper_action_form[$action]);
}
+ // }}}
+ // {{{ getFormName
/**
* »ØÄꤵ¤ì¤¿¥Õ¥©¡¼¥à¹àÌܤËÂбþ¤¹¤ë¥Õ¥©¡¼¥à̾(w/ ¥ì¥ó¥À¥ê¥ó¥°)¤ò¼èÆÀ¤¹¤ë
*
* @access public
*/
- function getFormName($name, $params)
+ function getFormName($name, $action, $params)
{
- $def = $this->_getHelperActionFormDef($name);
+ $def = $this->_getHelperActionFormDef($name, $action);
$form_name = null;
if (is_null($def) || isset($def['name']) == false) {
$form_name = $name;
return $form_name;
}
+ // }}}
+
+ // {{{ getFormSubmit
+ /**
+ * submit¥Ü¥¿¥ó¤ò¼èÆÀ¤¹¤ë(Á÷¿®À襢¥¯¥·¥ç¥ó¤Ç¼õ¤±¼è¤ë¤è¤¦
+ * ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¤È¤¤Ë¡¢¤¿¤ó¤Ësubmit¥Ü¥¿¥ó¤òºî¤ë¤Î¤Ë»È¤¦)
+ *
+ * @access public
+ */
+ function getFormSubmit($name, $params)
+ {
+ $def = array('form_type' => FORM_TYPE_SUBMIT);
+ $input = $this->_getFormInput_Submit($name, $def, $params);
+ return $input;
+ }
+ // }}}
+ // {{{ getFormInput
/**
* »ØÄꤵ¤ì¤¿¥Õ¥©¡¼¥à¹àÌܤËÂбþ¤¹¤ë¥Õ¥©¡¼¥à¥¿¥°¤ò¼èÆÀ¤¹¤ë
*
* @access public
* @todo form_type³Æ¼ïÂбþ/JavaScriptÂбþ...
*/
- function getFormInput($name, $params)
+ function getFormInput($name, $action, $params)
{
- $def = $this->_getHelperActionFormDef($name);
+ $def = $this->_getHelperActionFormDef($name, $action);
if (is_null($def)) {
return "";
}
if (isset($def['form_type']) == false) {
$def['form_type'] = FORM_TYPE_TEXT;
}
+
+ if (is_array($def['type'])) {
+ $name .= '[]';
+ }
switch ($def['form_type']) {
case FORM_TYPE_BUTTON:
$input = $this->_getFormInput_Button($name, $def, $params);
break;
case FORM_TYPE_CHECKBOX:
- // T.B.D.
+ $input = $this->_getFormInput_Checkbox($name, $def, $params);
break;
case FORM_TYPE_FILE:
$input = $this->_getFormInput_File($name, $def, $params);
$input = $this->_getFormInput_Password($name, $def, $params);
break;
case FORM_TYPE_RADIO:
- // T.B.D.
+ $input = $this->_getFormInput_Radio($name, $def, $params);
break;
case FORM_TYPE_SELECT:
- // T.B.D.
+ $input = $this->_getFormInput_Select($name, $def, $params);
break;
case FORM_TYPE_SUBMIT:
$input = $this->_getFormInput_Submit($name, $def, $params);
break;
}
- print $input;
+ return $input;
+ }
+ // }}}
+
+ // {{{ getFormBlock
+ /**
+ * ¥Õ¥©¡¼¥à¥¿¥°¤ò¼èÆÀ¤¹¤ë(type="form")
+ *
+ * @access protected
+ */
+ function getFormBlock($content, $params)
+ {
+ $attr = array();
+
+ // action
+ if (isset($params['action'])) {
+ $attr['action'] = htmlspecialchars($params['action'], ENT_QUOTES);
+ unset($params['action']);
+ } else {
+ $action = basename($_SERVER['PHP_SELF']);
+ }
+
+ // method
+ if (isset($params['method'])) {
+ $attr['method'] = htmlspecialchars($params['method'], ENT_QUOTES);
+ unset($params['method']);
+ } else {
+ $attr['method'] = 'post';
+ }
+
+ // enctype
+ if (isset($params['enctype'])) {
+ $attr['enctype'] = htmlspecialchars($params['enctype'], ENT_QUOTES);
+ unset($params['enctype']);
+ }
+
+ return $this->_getFormInput_Html('form', $attr, $params, $content, false);
}
+ // }}}
+ // {{{ _getHelperActionForm
/**
* ¥¢¥¯¥·¥ç¥ó¥Õ¥©¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È(helper)¤òÀ¸À®¤¹¤ë
*
$ctl =& Ethna_Controller::getInstance();
$form_name = $ctl->getActionFormName($action);
if ($form_name == null) {
- // TODO: logging
+ $this->logger->log(LOG_WARNING,
+ 'action form for the action [%s] not found.', $action);
return null;
}
$af =& new $form_name($ctl);
return $af;
}
+ // }}}
+ // {{{ _getHelperActionFormDef
/**
* ¥Õ¥©¡¼¥à¹àÌܤËÂбþ¤¹¤ë¥Õ¥©¡¼¥àÄêµÁ¤ò¼èÆÀ¤¹¤ë
*
* @access protected
*/
- function _getHelperActionFormDef($name)
+ function _getHelperActionFormDef($name, $action = null)
{
- $def = $this->af->getDef($name);
- if (is_null($def)) {
- foreach ($this->helper_action_form as $key => $value) {
- if (is_object($value) == false) {
- continue;
- }
- $def = $value->getDef($name);
- if (is_null($def) == false) {
- break;
+ $def = null;
+ if (is_null($action)) {
+ $def = $this->af->getDef($name);
+ if (is_null($def)) {
+ foreach ($this->helper_action_form as $key => $value) {
+ if (is_object($value) == false) {
+ continue;
+ }
+ $def = $value->getDef($name);
+ if (is_null($def) == false) {
+ break;
+ }
}
}
+ } else {
+ if (isset($this->helper_action_form[$action])
+ && is_object($this->helper_action_form[$action])) {
+ $af =& $this->helper_action_form[$action];
+ $def = $af->getDef($name);
+ }
+ }
+ if (is_null($def)) {
+ $this->logger->log(LOG_WARNING,
+ 'form definition [%s] not found in action [%s]', $name, $action);
}
return $def;
}
+ // }}}
+ // {{{ _getFormInput_Button
/**
* ¥Õ¥©¡¼¥à¥¿¥°¤ò¼èÆÀ¤¹¤ë(type="button")
*
*/
function _getFormInput_Button($name, $def, $params)
{
- $r = array();
- $r['type'] = "button";
- $r['name'] = $name;
+ $attr = array();
+ $attr['type'] = "button";
+ $attr['name'] = $name;
+
+ return $this->_getFormInput_Html("input", $attr, $params);
+ }
+ // }}}
+
+ // {{{ _getFormInput_Checkbox
+ /**
+ * ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¥¿¥°¤ò¼èÆÀ¤¹¤ë(type="check")
+ *
+ * @access protected
+ */
+ function _getFormInput_Checkbox($name, $def, $params)
+ {
+ $source = array();
+
+ // ¥ª¥×¥·¥ç¥ó¤Î°ìÍ÷(alist)¤ò¼èÆÀ
+ // XXX: experimental
+ if (isset($def['source'])) {
+ $source = $def['source'];
+ }
+
+ // defaultÃͤÎÀßÄê
+ if (isset($params['default'])) {
+ $current_value = $params['default'];
+ unset($params['default']);
+ }
+ $current_value = to_array($current_value);
+
+ // ¥¿¥°¤Î¥»¥Ñ¥ì¡¼¥¿
+ if (isset($params['separator'])) {
+ $separator = $params['separator'];
+ unset($params['separator']);
+ } else {
+ $separator = '';
+ }
+
+ $ret = array();
+ $i = 1;
+ foreach ($source as $key => $value) {
+ $attr = array();
+ $attr['type'] = 'checkbox';
+ $attr['name'] = $name;
+ $attr['value'] = $key;
+ $attr['id'] = $name . '_' . $i++;
+ if (in_array((string) $key, $current_value)) {
+ $attr['checked'] = 'checked';
+ }
+
+ // <input type="checkbox" />
+ $input_tag = $this->_getFormInput_Html('input', $attr, $params, $value);
+
+ // <label for="id">..</label>
+ $ret[] = $this->_getFormInput_Html('label', array('id' => $attr['id']),
+ $params, $input_tag, false);
+ }
- return $this->_getFormInput_Html("input", $r, $params);
+ return implode($separator, $ret);
}
+ // }}}
+ // {{{ _getFormInput_File
/**
* ¥Õ¥©¡¼¥à¥¿¥°¤ò¼èÆÀ¤¹¤ë(type="file")
*
*/
function _getFormInput_File($name, $def, $params)
{
- $r = array();
- $r['type'] = "file";
- $r['name'] = $name;
- $r['value'] = "";
+ $attr = array();
+ $attr['type'] = "file";
+ $attr['name'] = $name;
+ $attr['value'] = "";
- return $this->_getFormInput_Html("input", $r, $params);
+ return $this->_getFormInput_Html("input", $attr, $params);
}
+ // }}}
+ // {{{ _getFormInput_Hidden
/**
* ¥Õ¥©¡¼¥à¥¿¥°¤ò¼èÆÀ¤¹¤ë(type="hidden")
*
*/
function _getFormInput_Hidden($name, $def, $params)
{
- $r = array();
- $r['type'] = "hidden";
- $r['name'] = $name;
- $r['value'] = $this->af->get($name);
+ $attr = array();
+ $attr['type'] = "hidden";
+ $attr['name'] = $name;
+ if (isset($params['default'])) {
+ $attr['value'] = $params['default'];
+ unset($params['default']);
+ } else if (isset($params['value'])) {
+ $attr['value'] = $params['value'];
+ unset($params['value']);
+ }
- return $this->_getFormInput_Html("input", $r, $params);
+ return $this->_getFormInput_Html("input", $attr, $params);
}
+ // }}}
+ // {{{ _getFormInput_Password
/**
* ¥Õ¥©¡¼¥à¥¿¥°¤ò¼èÆÀ¤¹¤ë(type="password")
*
*/
function _getFormInput_Password($name, $def, $params)
{
- $r = array();
- $r['type'] = "password";
- $r['name'] = $name;
- $r['value'] = $this->af->get($name);
+ $attr = array();
+ $attr['type'] = "password";
+ $attr['name'] = $name;
+ if (isset($params['default'])) {
+ $attr['value'] = $params['default'];
+ unset($params['default']);
+ } else if (isset($params['value'])) {
+ $attr['value'] = $params['value'];
+ unset($params['value']);
+ }
+
+ return $this->_getFormInput_Html("input", $attr, $params);
+ }
+ // }}}
+
+ // {{{ _getFormInput_Radio
+ /**
+ * ¥é¥¸¥ª¥Ü¥¿¥ó¥¿¥°¤ò¼èÆÀ¤¹¤ë(type="radio")
+ *
+ * @access protected
+ */
+ function _getFormInput_Radio($name, $def, $params)
+ {
+ $source = array();
+
+ // ¥ª¥×¥·¥ç¥ó¤Î°ìÍ÷(alist)¤ò¼èÆÀ
+ // XXX: experimental
+ if (isset($def['source'])) {
+ $source = $def['source'];
+ }
+
+ // defaultÃͤÎÀßÄê
+ if (isset($params['default'])) {
+ $current_value = $params['default'];
+ unset($params['default']);
+ }
+
+ // ¥¿¥°¤Î¥»¥Ñ¥ì¡¼¥¿
+ if (isset($params['separator'])) {
+ $separator = $params['separator'];
+ unset($params['separator']);
+ } else {
+ $separator = '';
+ }
+
+ $ret = array();
+ $i = 1;
+ foreach ($source as $key => $value) {
+ $attr = array();
+ $attr['type'] = 'radio';
+ $attr['name'] = $name;
+ $attr['value'] = $key;
+ $attr['id'] = $name . '_' . $i++;
+ if ($current_value === (string) $key) {
+ $attr['checked'] = 'checked';
+ }
+
+ // <input type="radio" />
+ $input_tag = $this->_getFormInput_Html('input', $attr, $params, $value);
+
+ // <label for="id">..</label>
+ $ret[] = $this->_getFormInput_Html('label', array('id' => $attr['id']),
+ $params, $input_tag, false);
+ }
+
+ return implode($separator, $ret);
+ }
+ // }}}
+
+ // {{{ _getFormInput_Select
+ /**
+ * ¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹¥¿¥°¤ò¼èÆÀ¤¹¤ë(type="select")
+ *
+ * @access protected
+ */
+ function _getFormInput_Select($name, $def, $params)
+ {
+ $source = array();
+
+ // ¥ª¥×¥·¥ç¥ó¤Î°ìÍ÷(alist)¤ò¼èÆÀ
+ if (isset($def['source'])) {
+ $source = $def['source'];
+ } else if (isset($params['actionform'])) {
+ $method = sprintf('list%s', str_replace('_', '', $params['action_form']));
+ $source = $this->af->$method();
+ unset($params['actionform']);
+ } else if (isset($params['manager']) && is_array($params['manager'])) {
+ list($manager_key, $manager_attr) = $params['manager'];
+ $manager =& $this->backend->getManager($manager_key);
+ $source = $manager->getAttrList($manager_attr);
+ unset($params['manager']);
+ } else if (isset($params['callback']) && is_callable($params['callback'])) {
+ $source = call_user_func($params['callback']);
+ unset($params['callback']);
+ }
+
+ // defaultÃͤÎÀßÄê
+ if (isset($params['default'])) {
+ $current_value = $params['default'];
+ unset($params['default']);
+ }
+
+ // ¥¿¥°¤Î¥»¥Ñ¥ì¡¼¥¿
+ if (isset($params['separator'])) {
+ $separator = $params['separator'];
+ unset($params['separator']);
+ } else {
+ $separator = '';
+ }
+
+ // select¥¿¥°¤ÎÃæ¿È¤òºî¤ë
+ $contents = array();
+ foreach ($source as $key => $value) {
+ if ($current_value === (string) $key) {
+ $attr = array('value' => $key, 'selected' => null);
+ } else {
+ $attr = array('value' => $key);
+ }
+ $contents[] = $this->_getFormInput_Html('option', $attr, $params, $value);
+ }
- return $this->_getFormInput_Html("input", $r, $params);
+ $attr = array('name' => $name);
+ $element = $separator . implode($separator, $contents) . $separator;
+ return $this->_getFormInput_Html('select', $attr, $params, $element, false);
}
+ // }}}
+ // {{{ _getFormInput_Submit
/**
* ¥Õ¥©¡¼¥à¥¿¥°¤ò¼èÆÀ¤¹¤ë(type="submit")
*
*/
function _getFormInput_Submit($name, $def, $params)
{
- $r = array();
- $r['type'] = "submit";
- $r['name'] = $name;
- $r['value'] = $def['name'];
+ $attr = array();
+ $attr['type'] = "submit";
+ $attr['name'] = $name;
+ $attr['value'] = $def['name'];
- return $this->_getFormInput_Html("input", $r, $params);
+ return $this->_getFormInput_Html("input", $attr, $params);
}
+ // }}}
+ // {{{ _getFormInput_Textarea
/**
* ¥Õ¥©¡¼¥à¥¿¥°¤ò¼èÆÀ¤¹¤ë(textarea)
*
*/
function _getFormInput_Textarea($name, $def, $params)
{
- $r = array();
- $r['name'] = $name;
+ $attr = array();
+ $attr['name'] = $name;
+ if (isset($params['default'])) {
+ $element = $params['default'];
+ unset($params['default']);
+ } else if (isset($params['value'])) {
+ $element = $params['value'];
+ unset($params['value']);
+ }
- return $this->_getFormInput_Html("textarea", $r, $params, $this->af->get($name));
+ return $this->_getFormInput_Html("textarea", $attr, $params, $element);
}
+ // }}}
+ // {{{ _getFormInput_Text
/**
* ¥Õ¥©¡¼¥à¥¿¥°¤ò¼èÆÀ¤¹¤ë(type="text")
*
*/
function _getFormInput_Text($name, $def, $params)
{
- $r = array();
- $r['type'] = "text";
- $r['name'] = $name;
- $r['value'] = $this->af->get($name);
+ $attr = array();
+ $attr['type'] = "text";
+ $attr['name'] = $name;
+ if (isset($params['default'])) {
+ $attr['value'] = $params['default'];
+ unset($params['default']);
+ } else if (isset($params['value'])) {
+ $attr['value'] = $params['value'];
+ unset($params['value']);
+ }
if (isset($def['max']) && $def['max']) {
- $r['maxlength'] = $def['max'];
+ $attr['maxlength'] = $def['max'];
}
- return $this->_getFormInput_Html("input", $r, $params);
+ return $this->_getFormInput_Html("input", $attr, $params);
}
+ // }}}
+ // {{{ _getFormInput_Html
/**
* HTML¥¿¥°¤ò¼èÆÀ¤¹¤ë
*
* @access protected
*/
- function _getFormInput_Html($tag, $attr, $user_attr, $element = false)
+ function _getFormInput_Html($tag, $attr, $user_attr,
+ $element = null, $escape_elemet = true)
{
// user defs
foreach ($user_attr as $key => $value) {
- if ($key == "type" || $key == "name" || preg_match('/^[a-z0-9]+$/i', $key) == 0) {
+ if ($key == "type" || $key == "name"
+ || preg_match('/^[a-z0-9]+$/i', $key) == 0) {
continue;
}
$attr[$key] = $value;
$r = "<$tag";
foreach ($attr as $key => $value) {
- $r .= sprintf(' %s="%s"', $key, htmlspecialchars($value, ENT_QUOTES));
+ if (is_null($value)) {
+ $r .= sprintf(' %s', $key);
+ } else {
+ $r .= sprintf(' %s="%s"', $key, htmlspecialchars($value, ENT_QUOTES));
+ }
}
- if ($element !== false) {
- $r .= sprintf('>%s</%s>', htmlspecialchars($element, ENT_QUOTES), $tag);
- } else {
+ if (is_null($element)) {
$r .= " />";
+ } else {
+ $r .= sprintf('>%s</%s>', $escape_elemet
+ ? htmlspecialchars($element, ENT_QUOTES) : $element, $tag);
}
return $r;
}
+ // }}}
+ // {{{ _getRenderer
/**
* ¥ì¥ó¥À¥é¥ª¥Ö¥¸¥§¥¯¥È¤ò¼èÆÀ¤¹¤ë
*
$_ret_object =& $this->_getTemplateEngine();
return $_ret_object;
}
+ // }}}
+ // {{{ _getTemplateEngine
/**
* ¥ì¥ó¥À¥é¥ª¥Ö¥¸¥§¥¯¥È¤ò¼èÆÀ¤¹¤ë(¤½¤Î¤¦¤Á_getRenderer()¤ËÅý¹ç¤µ¤ì¤ëͽÄê)
*
$tmp_session = Ethna_Util::escapeHtml($_SESSION);
$renderer->setPropByRef('session', $tmp_session);
}
- $renderer->setProp('script', htmlspecialchars(basename($_SERVER['PHP_SELF']), ENT_QUOTES));
- $renderer->setProp('request_uri', htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES));
+ $renderer->setProp('script',
+ htmlspecialchars(basename($_SERVER['PHP_SELF']), ENT_QUOTES));
+ $renderer->setProp('request_uri',
+ htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES));
$renderer->setProp('config', $this->config->get());
return $renderer;
}
+ // }}}
+ // {{{ _setDefault
/**
* ¶¦ÄÌÃͤòÀßÄꤹ¤ë
*
function _setDefault(&$renderer)
{
}
+ // }}}
}
// }}}
?>