<?php
-use \PFF\HtmlBuilder\Tag as Tag;
-
class IPF_Admin_App extends IPF_Application
{
public function __construct()
return $perms;
}
-
- public static function renderForm($form)
- {
- return $form->renderLayout(new IPF_Admin_Form_Layout, false);
- }
-}
-
-class IPF_Admin_Form_Layout extends IPF_Form_LayoutAdapter
-{
- public function startForm($form)
- {
- $errors = $this->commonErrors($form);
- return $this->errors($errors) .
- $this->hiddenWidgets($form);
- }
-
- public function startGroup($label)
- {
- if ($label)
- return Tag::div(array('class' => 'form-group-title'), $label)->html();
- else
- return '';
- }
-
- public function field($boundField, $label)
- {
- if ($boundField->help_text) {
- $help_text = Tag::p(array('class' => 'help'))
- ->raw($boundField->help_text);
- } else {
- $help_text = '';
- }
-
- return $this->errors($boundField->errors) .
- Tag::div(array('class' => 'form-row'),
- Tag::div()
- ->raw($label)
- ->raw(' ')
- ->raw($boundField->render_w())
- ->append($help_text));
- }
-
- private function errors($errors)
- {
- if (!count($errors))
- return '';
-
- $ul = Tag::ul(array('class' => 'errorlist'));
- foreach ($errors as $err)
- $ul->append(Tag::li(null, $err));
- return Tag::div(null, $ul);
- }
}
--- /dev/null
+<?php
+
+use \PFF\HtmlBuilder\Tag as Tag;
+
+
+class IFP_Admin_ModelForm extends IPF_Form_Model
+{
+ public function unescape($html)
+ {
+ return new IPF_Template_SafeString($html, true);
+ }
+
+ public function render()
+ {
+ return $this->renderLayout(new IPF_Admin_Form_Layout, false);
+ }
+
+ public static function GetFormForModel($model, $data=null, $extra=array(), $label_suffix=null)
+ {
+ $extra['model'] = $model;
+ return new self($data, $extra, $label_suffix);
+ }
+}
+
+
+class IPF_Admin_Form_Layout extends IPF_Form_LayoutAdapter
+{
+ public function startForm($form)
+ {
+ $errors = $this->commonErrors($form);
+ return $this->errors($errors) .
+ $this->hiddenWidgets($form);
+ }
+
+ public function startGroup($label)
+ {
+ if ($label)
+ return Tag::div(array('class' => 'form-group-title'), $label)->html();
+ else
+ return '';
+ }
+
+ public function field($boundField, $label)
+ {
+ if ($boundField->help_text) {
+ $help_text = Tag::p(array('class' => 'help'))
+ ->raw($boundField->help_text);
+ } else {
+ $help_text = '';
+ }
+
+ return $this->errors($boundField->errors) .
+ Tag::div(array('class' => 'form-row'),
+ Tag::div()
+ ->raw($label)
+ ->raw(' ')
+ ->raw($boundField->render())
+ ->append($help_text));
+ }
+
+ private function errors($errors)
+ {
+ if (!count($errors))
+ return '';
+
+ $ul = Tag::ul(array('class' => 'errorlist'));
+ foreach ($errors as $err)
+ $ul->append(Tag::li(null, $err));
+ return Tag::div(null, $ul);
+ }
+}
+
protected function _getForm($model_obj, $data, $extra)
{
- return IPF_Shortcuts::GetFormForModel($model_obj,$data,$extra);
+ return IFP_Admin_ModelForm::GetFormForModel($model_obj, $data, $extra);
}
protected function _getEditForm($model_obj, $data, $extra)
'page_title'=>$this->titleAdd(),
'classname'=>$this->verbose_name(),
'form' => $form,
- 'form_html' => IPF_Admin_App::renderForm($form),
'extra_js' => $extraMedia['js'],
'extra_css' => $extraMedia['css'],
'inlineInstances'=>$this->inlineInstances,
'classname'=>$this->verbose_name(),
'object'=>$o,
'form' => $form,
- 'form_html' => IPF_Admin_App::renderForm($form),
'extra_js' => $extraMedia['js'],
'extra_css' => $extraMedia['css'],
'inlineInstances'=>$this->inlineInstances,
protected function _getForm($model_obj, $data, $extra)
{
- return IPF_Shortcuts::GetFormForModel($model_obj, $data, $extra);
+ return IFP_Admin_ModelForm::GetFormForModel($model_obj, $data, $extra);
}
function getFkName()
{/if}
<fieldset class="module aligned">
{block form}
- {$form_html}
+ {$form->render()}
{/block}
</fieldset>
{if $inlineInstances}
<p class="errornote">Please correct the error below.</p>
{/if}
<fieldset class="module aligned">
- {$form_html}
+ {$form->render()}
</fieldset>
<div class="submit-row">
<input type="submit" value="Change password" class="default" />
<div id="content" class="colM">
<div id="content-main">
<form method="post">
- {$form_html}
+ {$form->render()}
<div class="submit-row">
<input type="submit" value="Sign In" class="default" />
</div>
'classname'=>'User',
'object'=>$user,
'form' => $form,
- 'form_html' => IPF_Admin_App::renderForm($form),
'extra_js' => array(),
'lapp'=>$lapp,
'lmodel'=>$lmodel,
$context = array(
'page_title' => IPF::get('admin_title'),
'form' => $form,
- 'form_html' => IPF_Admin_App::renderForm($form),
'extra_js' => $form->extra_js(),
);
return IPF_Shortcuts::RenderToResponse('admin/login.html', $context, $request);
}
}
-class IPFAdminRoleForm extends IPF_Form_Model
+class IPFAdminRoleForm extends IFP_Admin_ModelForm
{
public function add__Permissions__field()
{
<?php
-class IPFAuthAdminUserForm extends IPF_Form_Model
+class IPFAuthAdminUserForm extends IFP_Admin_ModelForm
{
function initFields($extra=array())
{
$profileTable = IPF::get('auth_profile_model');
if ($profileTable) {
$table = IPF_ORM::getTable($profileTable);
- $profileFields = IPF_Form_Model::suggestFields($table);
+ $profileFields = self::suggestFields($table);
$fieldGroup = array();
foreach ($profileFields as $field) {
if ($raw)
return $errors;
else
- return new IPF_Template_SafeString($errors, true);
+ return $this->unescape($errors);
}
public function get_top_errors()
$output .= $layout->startGroup($groupLabel);
foreach ($group['fields'] as $name=>$field) {
+ if ($field->widget->is_hidden)
+ continue;
+
$bf = new IPF_Form_BoundField($this, $field, $name);
- if (!$field->widget->is_hidden) {
-
- if (strlen($bf->label) > 0) {
- $label = htmlspecialchars($bf->label, ENT_COMPAT, 'UTF-8');
- if ($this->label_suffix) {
- if (!in_array(mb_substr($label, -1, 1),
- array(':','?','.','!'))) {
- $label .= $this->label_suffix;
- }
- }
- if ($field->required)
- $label_attrs = array('class'=>'required');
- else
- $label_attrs = array();
- $label = $bf->labelTagRaw($label, $label_attrs);
- } else {
- $label = '';
+ $label = $field->label;
+ if ($this->label_suffix) {
+ if (!in_array(mb_substr($label, -1, 1),
+ array(':','?','.','!'))) {
+ $label .= $this->label_suffix;
}
-
- $output .= $layout->field($bf, $label);
}
+
+ if ($field->required)
+ $label_attrs = array('class'=>'required');
+ else
+ $label_attrs = null;
+ $label = $bf->labelTag($label, $label_attrs, true);
+
+ $output .= $layout->field($bf, $label);
}
$output .= $layout->endGroup($groupLabel);
}
$output .= $layout->endForm($this);
if (!$raw)
- $output = new IPF_Template_SafeString($output, true);
+ $output = $this->unescape($output);
return $output;
}
$ul = Tag::ul(array('class' => 'errorlist'));
foreach ($errors as $err)
$ul->append(Tag::li(null, $err));
- return $ul;
+ return $ul->html();
}
-}
-function IPF_Form_htmlspecialcharsArray(&$item, $key)
-{
- $item = htmlspecialchars($item, ENT_COMPAT, 'UTF-8');
+ public function unescape($html)
+ {
+ // Do nothing
+ return $html;
+ }
}
return $this->form->initial($this->name);
}
+ public function render()
+ {
+ $widget = $this->field->widget;
+
+ $extra_attrs = array();
+ if (array_key_exists('id', $widget->attrs)) {
+ $extra_attrs['id'] = $this->autoId();
+ }
+
+ return $widget->render($this->html_name, $this->value(), $extra_attrs);
+ }
+
public function render_w($widget=null, $attrs=array())
{
if ($widget === null) {
and !array_key_exists('id', $widget->attrs)) {
$attrs['id'] = $id;
}
- return $widget->render($this->html_name, $this->value(), $attrs);
+
+ $code = $widget->render($this->html_name, $this->value(), $attrs);
+
+ return $this->form->unescape($code);
}
- public function labelTag($contents=null, $attrs=array(), $raw=false)
+ public function labelTag($contents=null, $attrs=null, $raw=false)
{
$label = Tag::label($attrs);
$label->attr('for', $widget->idForLabel($id));
- if ($this->field->required)
- $label->addClass('req');
-
if ($raw)
- return $label;
+ return $label->html();
else
- return new IPF_Template_SafeString($label, true);
+ return $this->form->unescape($label->html());
}
public function autoId()
if ($raw)
return $errors;
else
- return new IPF_Template_SafeString($errors, true);
+ return $this->form->unescape($errors);
}
public function __get($prop)
{
$hiddenWidgets = '';
foreach ($form->hiddenFields() as $field_name)
- $hiddenWidgets .= $form->field($field_name)->render_w();
+ $hiddenWidgets .= $form->field($field_name)->render();
return $hiddenWidgets;
}
Tag::p()
->raw($label)
->raw(' ')
- ->raw($boundField->render_w())
+ ->raw($boundField->render())
->raw(' ')
->raw($boundField->help_text);
}
->raw($this->errorList($boundField->errors))
->raw($label)
->raw(' ')
- ->raw($boundField->render_w())
+ ->raw($boundField->render())
->raw($help_text);
}
Tag::td()
->raw($this->takeDeferred())
->raw($this->errorList($boundField->errors))
- ->raw($boundField->render_w())
+ ->raw($boundField->render())
->raw($help_text));
}
}
}
-function IPF_Form_Widget_Attrs($attrs)
-{
- $_tmp = array();
- foreach ($attrs as $attr=>$val) {
- $_tmp[] = $attr.'="'.$val.'"';
- }
- return ' '.implode(' ', $_tmp);
-}
-
<?php
+use \PFF\HtmlBuilder\Tag as Tag;
+
class IPF_Form_Widget_FileInput extends IPF_Form_Widget_Input
{
public $input_type = 'file';
protected function viewCurrentValue($filename)
{
if ($filename)
- return '<a target="_blank" href="'.IPF::getUploadUrl().$filename.'">view</a>';
+ return Tag::a(array('target' => '_blank', 'href' => IPF::getUploadUrl().$filename), 'view')->html();
else
return '';
}
return '';
if ($this->allow_extended) {
- $sim = 'Currently: <input name="'.$name.'_name" value="'.$filename.'" type="hidden" /><input name="'.$name.'_rename" value="'.$filename.'" id="id_'.$name.'_rename" type="text" style="width:150px;" /> ' .
+ $sim = 'Currently: ' .
+ Tag::input(array('name' => "{$name}_name", 'value' => $filename, 'type' => 'hidden')) .
+ Tag::input(array('name' => "{$name}_rename", 'value' => $filename, 'id' => "id_{$name}_rename", 'type' => 'text', 'style' => 'width:150px;')) .
$this->viewCurrentValue($filename);
+
if ($this->allow_delete)
- $sim .= ' | <input name="'.$name.'_remove" value="1" id="id_'.$name.'_remove" type="checkbox" /> <label class="file_remove" for="id_'.$name.'_remove">Remove</label>';
+ $sim .= ' | ' .
+ Tag::input(array('name' => "{$name}_remove", 'value' => 1, 'id' => "id_{$name}_remove", 'type' => 'checkbox')) .
+ ' ' .
+ Tag::label(array('class' => 'file_remove', 'for' => "id_{$name}_remove"), 'Remove');
+
$sim .= ' Change:';
+
return $sim;
} else {
- return 'Currently: <b>'.$filename.'</b><br> Change: ';
+ return 'Currently: ' . Tag::b(null, $filename) . '<br> Change: ';
}
}
<?php
+use \PFF\HtmlBuilder\Tag as Tag;
+
class IPF_Form_Widget_HTMLInput extends IPF_Form_Widget
{
public $mode = 'textareas';
}
}
$final_attrs = $this->buildAttrs(array('name' => $name), $extra_attrs);
- return new IPF_Template_SafeString('<textarea'.IPF_Form_Widget_Attrs($final_attrs).' class="htmlEditor'.($this->force_absolute_urls ? 'Abs' : '').'">'.htmlspecialchars($value, ENT_COMPAT, 'UTF-8').'</textarea>', true);
+
+ return Tag::textarea($final_attrs)
+ ->addClass($this->force_absolute_urls ? 'htmlEditorAbs' : 'htmlEditor')
+ ->append($value)
+ ->html();
}
public function extra_js()
<?php
+use \PFF\HtmlBuilder\Tag as Tag;
+
class IPF_Form_Widget_Image extends IPF_Form_Widget_FileInput
{
protected function viewCurrentValue($filename)
{
- if ($filename) {
- $url = IPF::getUploadUrl() . $filename;
- return ' <a target="_blank" href="'.$url.'"><img src="'.$url.'" style="max-width:64px;max-height:64px"/></a> ';
- } else {
+ if (!$filename)
return '';
- }
+
+ $url = IPF::getUploadUrl() . $filename;
+ return ' ' .
+ Tag::a(array('target' => '_blank', 'href' => $url),
+ Tag::img(array('src' => $url, 'style' => 'max-width:64px;max-height:64px')))
+ ->html() .
+ ' ';
}
}
<?php
+use \PFF\HtmlBuilder\Tag as Tag;
+
class IPF_Form_Widget_Input extends IPF_Form_Widget
{
public function render($name, $value, $extra_attrs=array())
{
- if ($value === null) $value = '';
$final_attrs = $this->buildAttrs(array('name' => $name,
'type' => $this->input_type),
$extra_attrs);
- if ($value !== '') {
- $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
+ if ($value)
$final_attrs['value'] = $value;
- }
- return new IPF_Template_SafeString('<input'.IPF_Form_Widget_Attrs($final_attrs).' />', true);
+
+ return Tag::input($final_attrs);
}
-}
\ No newline at end of file
+}
+
<?php
+use \PFF\HtmlBuilder\Tag as Tag;
+
class IPF_Form_Widget_RadioInput extends IPF_Form_Widget
{
public $choices = array();
parent::__construct($attrs);
}
- public function render($name, $value, $extra_attrs=array(),
- $choices=array())
+ public function render($name, $value, $extra_attrs=array(), $choices=array())
{
$output = array();
if ($value === null) {
$value = '';
}
- // $final_attrs = $this->buildAttrs($extra_attrs);
- $output[] = '<ul>'; // '.IPF_Form_Widget_Attrs($final_attrs).'
+ $output = Tag::ul(); // ->attrs($this->buildAttrs($extra_attrs));
$choices = $this->choices + $choices;
$index = 1;
- foreach ($choices as $option_label=>$option_value) {
- $selected = ($option_value == $value) ? ' checked="checked"':'';
- $output[] = sprintf('<input type="radio" name="%s" id="id_%s-%s" value="%s"%s/><label for="id_%s-%s">%s</label>',
- $name,
- $name,
- $index,
- htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8'),
- $selected,
- $name,
- $index,
- htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8'));
+ foreach ($choices as $option_label => $option_value) {
+ $optionId = "id_$name-$index";
+
+ $radio = Tag::input(array('type' => 'radio', 'name' => $name, 'id' => $optionId, 'value' => $option_value));
+ if ($option_value == $value)
+ $radio->attr('checked', 'checked');
+
+ $output->append(Tag::li(null,
+ $radio,
+ Tag::label(array('for' => $optionId), $option_label)));
+
$index++;
}
- $output[] = '</ul>';
- return new IPF_Template_SafeString(implode("\n", $output), true);
+ return $output->html();
}
}
<?php
+use \PFF\HtmlBuilder\Tag as Tag;
+
class IPF_Form_Widget_SelectInput extends IPF_Form_Widget
{
public $choices = array();
parent::__construct($attrs);
}
- public function render($name, $value, $extra_attrs=array(),
- $choices=array())
+ public function render($name, $value, $extra_attrs=array(), $choices=array())
{
$output = array();
if ($value === null) {
$value = '';
}
- $final_attrs = $this->buildAttrs(array('name' => $name), $extra_attrs);
- $output[] = '<select'.IPF_Form_Widget_Attrs($final_attrs).'>';
+ $select = Tag::select($this->attrs)
+ ->attrs($extra_attrs)
+ ->attr('name', $name);
$choices = $this->choices + $choices;
- foreach ($choices as $option_label=>$option_value) {
- $selected = ($option_value == $value) ? ' selected="selected"':'';
- $output[] = sprintf('<option value="%s"%s>%s</option>',
- htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8'),
- $selected,
- htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8'));
+ foreach ($choices as $option_label => $option_value) {
+ $option = Tag::option()
+ ->attr('value', $option_value)
+ ->append($option_label);
+ if ($option_value == $value)
+ $option->attr('selected', 'selected');
+ $select->append($option);
}
- $output[] = '</select>';
- return new IPF_Template_SafeString(implode("\n", $output), true);
+ return $select->html();
}
-}
\ No newline at end of file
+}
+
<?php
+use \PFF\HtmlBuilder\Tag as Tag;
+
class IPF_Form_Widget_SelectMultipleInput extends IPF_Form_Widget
{
public $choices = array();
if ($value === null) {
$value = array();
}
- $final_attrs = $this->buildAttrs(array('name' => $name.'[]'),
- $extra_attrs);
- $output[] = '<select multiple="multiple"'
- .IPF_Form_Widget_Attrs($final_attrs).'>';
+ $select = Tag::select($this->attrs)
+ ->attrs($extra_attrs)
+ ->attr('name', $name.'[]')
+ ->attr('multiple', 'multiple');
$choices = array_merge($this->choices, $choices);
-
- foreach ($choices as $option_label=>$option_value) {
- $selected = (@in_array($option_value, $value)) ? ' selected="selected"':'';
- $output[] = sprintf('<option value="%s"%s>%s</option>',
- htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8'),
- $selected,
- htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8'));
-
+ foreach ($choices as $option_label => $option_value) {
+ $option = Tag::option()->attr('value', $option_value)->append($option_label);
+ if (@in_array($option_value, $value))
+ $option->attr('selected', 'selected');
+ $select->append($option);
}
- $output[] = '</select>';
- return new IPF_Template_SafeString(implode("\n", $output), true);
+ return $select->html();
}
public function valueFromFormData($name, &$data)
<?php
+use \PFF\HtmlBuilder\Tag as Tag;
+
class IPF_Form_Widget_SelectMultipleInputCheckbox extends IPF_Form_Widget_SelectMultipleInput
{
public function render($name, $value, $extra_attrs=array(), $choices=array())
{
- $output = array();
if ($value === null || $value == '')
$value = array();
$final_attrs = $this->buildAttrs($extra_attrs);
- $output[] = '<ul>';
+ $output = Tag::ul();
$choices = array_merge($this->choices, $choices);
$i=0;
$base_id = $final_attrs['id'];
- foreach ($choices as $option_label=>$option_value) {
- $final_attrs['id'] = $base_id.'_'.$i;
- $final_attrs['value'] = htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8');
- $checkbox = new IPF_Form_Widget_CheckboxInput($final_attrs);
- $rendered = $checkbox->render($name.'[]', in_array($option_value, $value), array('value'=>$option_value));
- $output[] = sprintf('<li><label>%s %s</label></li>',
- $rendered,
- htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8'));
+ foreach ($choices as $option_label => $option_value) {
+ $selected = in_array($option_value, $value);
+
+ $checkbox = Tag::input($final_attrs)
+ ->attr('type', 'checkbox')
+ ->attr('name', "{$name}[]")
+ ->attr('id', $base_id.'_'.$i)
+ ->attr('value', $option_value);
+ if ($selected)
+ $checkbox->attr('checked', 'checked');
+
+ $output->append(Tag::li(null,
+ Tag::label(null, $checkbox, ' ', $option_label)));
$i++;
}
- $output[] = '</ul>';
- return new IPF_Template_SafeString(implode("\n", $output), true);
+ return $output->html();
}
public function idForLabel($id)
<?php
+use \PFF\HtmlBuilder\Tag as Tag;
+
class IPF_Form_Widget_TextareaInput extends IPF_Form_Widget
{
-
public function __construct($attrs=array())
{
- $this->attrs = array_merge(array('cols' => '40', 'rows' => '10'),
- $attrs);
+ $this->attrs = array_merge(array('cols' => '40', 'rows' => '10'), $attrs);
}
public function render($name, $value, $extra_attrs=array())
{
- if ($value === null) $value = '';
- $final_attrs = $this->buildAttrs(array('name' => $name),
- $extra_attrs);
- return new IPF_Template_SafeString(
- sprintf('<textarea%s>%s</textarea>',
- IPF_Form_Widget_Attrs($final_attrs),
- htmlspecialchars($value, ENT_COMPAT, 'UTF-8')),
- true);
+ if ($value === null)
+ $value = '';
+ $final_attrs = $this->buildAttrs(array('name' => $name), $extra_attrs);
+ return Tag::textarea($final_attrs, $value)->html();
}
}
+
+++ /dev/null
-<?php
-
-class IPF_Form_Widget_TupleInput extends IPF_Form_Widget
-{
- var $headers = array('');
- var $rows = 3;
-
- public function __construct($attrs=array()){
-
- parent::__construct($attrs);
-
- if (isset($attrs['headers']))
- $this->headers = $attrs['headers'];
-
- if (isset($attrs['rows']))
- $this->rows = $attrs['rows'];
- }
-
- protected function isHeadLabels(){
- foreach ($this->headers as &$h){
- if ($h=='')
- return false;
- }
- return true;
- }
-
- public function render($name, $value, $extra_attrs=array())
- {
- $data = array();
- $lines = explode("\n",$value);
- foreach ($lines as $line){
- $data[] = explode('|', $line);
- }
- if ($value === null) $value = '';
- $s = '<table class="tuplegrid">';
- if ($this->isHeadLabels()){
- $s .= '<tr>';
- foreach ($this->headers as &$h){
- $s .= '<th>'.$h.'</th>';
- }
- $s .= '</tr>';
- }
- for ($i=0; $i<$this->rows; $i++){
- $s .= '<tr>';
- for ($j=0; $j<count($this->headers); $j++){
- $v = @$data[$i][$j];
- $s .= '<td><input name="'.$name.'_'.$i.'_'.$j.'" value="'.$v.'"></td>';
- }
- $s .= '<tr>';
- }
- $s .= '</table>';
- return new IPF_Template_SafeString($s,true);
- }
-
- public function valueFromFormData($name, &$data)
- {
- $s = '';
- for ($i=0; $i<$this->rows; $i++){
- if ($i>0) $s .= "\n";
- for ($j=0; $j<count($this->headers); $j++){
- if ($j>0) $s.='|';
- $s .= @$data[$name.'_'.$i.'_'.$j];
- }
- }
- return $s;
- }
-}
-