Initial commit
This commit is contained in:
66
pluf/src/Pluf/Form/Widget/CheckboxInput.php
Normal file
66
pluf/src/Pluf/Form/Widget/CheckboxInput.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Simple checkbox.
|
||||
*/
|
||||
class Pluf_Form_Widget_CheckboxInput extends Pluf_Form_Widget_Input
|
||||
{
|
||||
public $input_type = 'checkbox';
|
||||
|
||||
/**
|
||||
* Renders the HTML of the input.
|
||||
*
|
||||
* @param string Name of the field.
|
||||
* @param mixed Value for the field, can be a non valid value.
|
||||
* @param array Extra attributes to add to the input form (array())
|
||||
* @return string The HTML string of the input.
|
||||
*/
|
||||
public function render($name, $value, $extra_attrs=array())
|
||||
{
|
||||
if ((bool)$value) {
|
||||
// We consider that if a value can be boolean casted to
|
||||
// true, then we check the box.
|
||||
$extra_attrs['checked'] = 'checked';
|
||||
}
|
||||
// Value of a checkbox is always "1" but when not checked, the
|
||||
// corresponding key in the form associative array is not set.
|
||||
return parent::render($name, '1', $extra_attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* A non checked checkbox is simply not returned in the form array.
|
||||
*
|
||||
* @param string Name of the form.
|
||||
* @param array Submitted form data.
|
||||
* @return mixed Value or null if not defined.
|
||||
*/
|
||||
public function valueFromFormData($name, $data)
|
||||
{
|
||||
if (!isset($data[$name]) or false === $data[$name]
|
||||
or (string)$data[$name] === '0' or $data[$name] == '') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
50
pluf/src/Pluf/Form/Widget/DatetimeInput.php
Normal file
50
pluf/src/Pluf/Form/Widget/DatetimeInput.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Simple input of type datetime.
|
||||
*/
|
||||
class Pluf_Form_Widget_DatetimeInput extends Pluf_Form_Widget_Input
|
||||
{
|
||||
public $input_type = 'text';
|
||||
public $format = 'Y-m-d H:i'; // '2006-10-25 14:30' by default do
|
||||
// not show the seconds.
|
||||
|
||||
/**
|
||||
* Renders the HTML of the input.
|
||||
*
|
||||
* @param string Name of the field.
|
||||
* @param mixed Value for the field, can be a non valid value.
|
||||
* @param array Extra attributes to add to the input form (array())
|
||||
* @return string The HTML string of the input.
|
||||
*/
|
||||
public function render($name, $value, $extra_attrs=array())
|
||||
{
|
||||
// Internally we use GMT, so we convert back to the current
|
||||
// timezone.
|
||||
if (strlen($value) > 0) {
|
||||
$value = date($this->format, strtotime($value.' GMT'));
|
||||
}
|
||||
return parent::render($name, $value, $extra_attrs);
|
||||
}
|
||||
}
|
38
pluf/src/Pluf/Form/Widget/FileInput.php
Normal file
38
pluf/src/Pluf/Form/Widget/FileInput.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Simple input of type file.
|
||||
*/
|
||||
class Pluf_Form_Widget_FileInput extends Pluf_Form_Widget_Input
|
||||
{
|
||||
public $input_type = 'file';
|
||||
public $needs_multipart_form = true;
|
||||
|
||||
public function render($name, $value, $extra_attrs=array())
|
||||
{
|
||||
$value = '';
|
||||
return parent::render($name, $value, $extra_attrs);
|
||||
}
|
||||
|
||||
}
|
31
pluf/src/Pluf/Form/Widget/HiddenInput.php
Normal file
31
pluf/src/Pluf/Form/Widget/HiddenInput.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Simple input of type text.
|
||||
*/
|
||||
class Pluf_Form_Widget_HiddenInput extends Pluf_Form_Widget_Input
|
||||
{
|
||||
public $input_type = 'hidden';
|
||||
public $is_hidden = true;
|
||||
}
|
49
pluf/src/Pluf/Form/Widget/Input.php
Normal file
49
pluf/src/Pluf/Form/Widget/Input.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Base class for all the input widgets. (Except radio and checkbox).
|
||||
*/
|
||||
class Pluf_Form_Widget_Input extends Pluf_Form_Widget
|
||||
{
|
||||
/**
|
||||
* Renders the HTML of the input.
|
||||
*
|
||||
* @param string Name of the field.
|
||||
* @param mixed Value for the field, can be a non valid value.
|
||||
* @param array Extra attributes to add to the input form (array())
|
||||
* @return string The HTML string of the input.
|
||||
*/
|
||||
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');
|
||||
$final_attrs['value'] = $value;
|
||||
}
|
||||
return new Pluf_Template_SafeString('<input'.Pluf_Form_Widget_Attrs($final_attrs).' />', true);
|
||||
}
|
||||
}
|
46
pluf/src/Pluf/Form/Widget/PasswordInput.php
Normal file
46
pluf/src/Pluf/Form/Widget/PasswordInput.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Simple input of type text.
|
||||
*/
|
||||
class Pluf_Form_Widget_PasswordInput extends Pluf_Form_Widget_Input
|
||||
{
|
||||
public $input_type = 'password';
|
||||
public $render_value = true;
|
||||
|
||||
public function __construct($attrs=array())
|
||||
{
|
||||
$this->render_value = (isset($attrs['render_value'])) ? $attrs['render_value'] : $this->render_value;
|
||||
unset($attrs['render_value']);
|
||||
parent::__construct($attrs);
|
||||
}
|
||||
|
||||
public function render($name, $value, $extra_attrs=array())
|
||||
{
|
||||
if ($this->render_value === false) {
|
||||
$value = '';
|
||||
}
|
||||
return parent::render($name, $value, $extra_attrs);
|
||||
}
|
||||
}
|
106
pluf/src/Pluf/Form/Widget/ReCaptcha.php
Normal file
106
pluf/src/Pluf/Form/Widget/ReCaptcha.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* reCAPTCHA input for your forms.
|
||||
*
|
||||
* Based on http://recaptcha.googlecode.com/files/recaptcha-php-1.10.zip
|
||||
*
|
||||
* Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
|
||||
* AUTHORS:
|
||||
* Mike Crawford
|
||||
* Ben Maurer
|
||||
*
|
||||
* @see Pluf_Form_Field_ReCaptcha
|
||||
*
|
||||
*/
|
||||
class Pluf_Form_Widget_ReCaptcha extends Pluf_Form_Widget_Input
|
||||
{
|
||||
public $input_type = 'text';
|
||||
public $ssl = false;
|
||||
public $pubkey = '';
|
||||
|
||||
|
||||
/**
|
||||
* Renders the HTML of the input.
|
||||
*
|
||||
* @param string Name of the field.
|
||||
* @param mixed Value for the field, can be a non valid value.
|
||||
* @param array Extra attributes to add to the input form (array())
|
||||
* @return string The HTML string of the input.
|
||||
*/
|
||||
public function render($name, $value, $extra_attrs=array())
|
||||
{
|
||||
return Pluf_Template::markSafe(self::getHtml($this->attrs['pubkey']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the challenge HTML (javascript and non-javascript
|
||||
* version). This is called from the browser, and the resulting
|
||||
* reCAPTCHA HTML widget is embedded within the HTML form it was
|
||||
* called from.
|
||||
*
|
||||
* @param string A public key for reCAPTCHA
|
||||
* @param string The error given by reCAPTCHA (null)
|
||||
* @param boolean Should the request be made over ssl? (false)
|
||||
* @return string The HTML to be embedded in the user's form.
|
||||
*/
|
||||
public static function getHtml($pubkey, $error=null, $use_ssl=false)
|
||||
{
|
||||
$server = ($use_ssl) ? 'https://api-secure.recaptcha.net'
|
||||
: 'http://api.recaptcha.net';
|
||||
$errorpart = ($error) ? '&error='.$error : '';
|
||||
|
||||
return '<script type="text/javascript" src="'.$server.'/challenge?k='
|
||||
.$pubkey.$errorpart.'"></script>
|
||||
<noscript>
|
||||
<iframe src="'.$server.'/noscript?k='.$pubkey.$errorpart
|
||||
.'" height="300" width="500" frameborder="0"></iframe><br/>
|
||||
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
|
||||
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
|
||||
</noscript>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the form data from the reCaptcha fields.
|
||||
*
|
||||
* We need to get back two fields from the POST request
|
||||
* 'recaptcha_challenge_field' and 'recaptcha_response_field'.
|
||||
*
|
||||
* They are hardcoded, so we do not even bother checking something
|
||||
* else.
|
||||
*
|
||||
* @param string Name of the form
|
||||
* @param array Submitted form data
|
||||
* @return array Challenge and answer
|
||||
*/
|
||||
public function valueFromFormData($name, $data)
|
||||
{
|
||||
$res = array('', '');
|
||||
$res[0] = isset($data['recaptcha_challenge_field'])
|
||||
? $data['recaptcha_challenge_field'] : '';
|
||||
$res[1] = isset($data['recaptcha_response_field'])
|
||||
? $data['recaptcha_response_field'] : '';
|
||||
return $res;
|
||||
}
|
||||
}
|
78
pluf/src/Pluf/Form/Widget/SelectInput.php
Normal file
78
pluf/src/Pluf/Form/Widget/SelectInput.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Simple checkbox with grouping.
|
||||
*/
|
||||
class Pluf_Form_Widget_SelectInput extends Pluf_Form_Widget
|
||||
{
|
||||
public $choices = array();
|
||||
|
||||
public function __construct($attrs=array())
|
||||
{
|
||||
$this->choices = $attrs['choices'];
|
||||
unset($attrs['choices']);
|
||||
parent::__construct($attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the HTML of the input.
|
||||
*
|
||||
* @param string Name of the field.
|
||||
* @param mixed Value for the field, can be a non valid value.
|
||||
* @param array Extra attributes to add to the input form (array())
|
||||
* @param array Extra choices (array())
|
||||
* @return string The HTML string of the input.
|
||||
*/
|
||||
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'.Pluf_Form_Widget_Attrs($final_attrs).'>';
|
||||
$groups = $this->choices + $choices;
|
||||
foreach($groups as $option_group => $c) {
|
||||
if (!is_array($c)) {
|
||||
$subchoices = array($option_group => $c);
|
||||
} else {
|
||||
$output[] = '<optgroup label="'.htmlspecialchars($option_group, ENT_COMPAT, 'UTF-8').'">';
|
||||
$subchoices = $c;
|
||||
}
|
||||
foreach ($subchoices 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'));
|
||||
}
|
||||
if (is_array($c)) {
|
||||
$output[] = '</optgroup>';
|
||||
}
|
||||
}
|
||||
$output[] = '</select>';
|
||||
return new Pluf_Template_SafeString(implode("\n", $output), true);
|
||||
}
|
||||
}
|
79
pluf/src/Pluf/Form/Widget/SelectMultipleInput.php
Normal file
79
pluf/src/Pluf/Form/Widget/SelectMultipleInput.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Simple checkbox.
|
||||
*/
|
||||
class Pluf_Form_Widget_SelectMultipleInput extends Pluf_Form_Widget
|
||||
{
|
||||
public $choices = array();
|
||||
|
||||
public function __construct($attrs=array())
|
||||
{
|
||||
$this->choices = $attrs['choices'];
|
||||
unset($attrs['choices']);
|
||||
parent::__construct($attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the HTML of the input.
|
||||
*
|
||||
* @param string Name of the field.
|
||||
* @param array Value for the field, can be a non valid value.
|
||||
* @param array Extra attributes to add to the input form (array())
|
||||
* @param array Extra choices (array())
|
||||
* @return string The HTML string of the input.
|
||||
*/
|
||||
public function render($name, $value, $extra_attrs=array(),
|
||||
$choices=array())
|
||||
{
|
||||
$output = array();
|
||||
if ($value === null) {
|
||||
$value = array();
|
||||
}
|
||||
$final_attrs = $this->buildAttrs(array('name' => $name.'[]'),
|
||||
$extra_attrs);
|
||||
$output[] = '<select multiple="multiple"'
|
||||
.Pluf_Form_Widget_Attrs($final_attrs).'>';
|
||||
$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'));
|
||||
|
||||
}
|
||||
$output[] = '</select>';
|
||||
return new Pluf_Template_SafeString(implode("\n", $output), true);
|
||||
}
|
||||
|
||||
public function valueFromFormData($name, $data)
|
||||
{
|
||||
if (isset($data[$name]) and is_array($data[$name])) {
|
||||
return $data[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
74
pluf/src/Pluf/Form/Widget/SelectMultipleInput/Checkbox.php
Normal file
74
pluf/src/Pluf/Form/Widget/SelectMultipleInput/Checkbox.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Simple checkbox.
|
||||
*/
|
||||
class Pluf_Form_Widget_SelectMultipleInput_Checkbox extends Pluf_Form_Widget_SelectMultipleInput
|
||||
{
|
||||
/**
|
||||
* Renders the HTML of the input.
|
||||
*
|
||||
* @param string Name of the field.
|
||||
* @param array Value for the field, can be a non valid value.
|
||||
* @param array Extra attributes to add to the input form (array())
|
||||
* @param array Extra choices (array())
|
||||
* @return string The HTML string of the input.
|
||||
*/
|
||||
public function render($name, $value, $extra_attrs=array(),
|
||||
$choices=array())
|
||||
{
|
||||
$output = array();
|
||||
if ($value === null or $value == '') {
|
||||
$value = array();
|
||||
}
|
||||
$final_attrs = $this->buildAttrs($extra_attrs);
|
||||
$output[] = '<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 Pluf_Form_Widget_CheckboxInput($final_attrs);
|
||||
$rendered = $checkbox->render($name.'[]', in_array($option_value, $value));
|
||||
|
||||
$output[] = sprintf('<li><label>%s %s</label></li>', $rendered,
|
||||
htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8'));
|
||||
$i++;
|
||||
}
|
||||
$output[] = '</ul>';
|
||||
return new Pluf_Template_SafeString(implode("\n", $output), true);
|
||||
}
|
||||
|
||||
public function idForLabel($id)
|
||||
{
|
||||
if ($id) {
|
||||
$id += '_0';
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
|
||||
}
|
30
pluf/src/Pluf/Form/Widget/TextInput.php
Normal file
30
pluf/src/Pluf/Form/Widget/TextInput.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Simple input of type text.
|
||||
*/
|
||||
class Pluf_Form_Widget_TextInput extends Pluf_Form_Widget_Input
|
||||
{
|
||||
public $input_type = 'text';
|
||||
}
|
55
pluf/src/Pluf/Form/Widget/TextareaInput.php
Normal file
55
pluf/src/Pluf/Form/Widget/TextareaInput.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Textarea.
|
||||
*/
|
||||
class Pluf_Form_Widget_TextareaInput extends Pluf_Form_Widget
|
||||
{
|
||||
|
||||
public function __construct($attrs=array())
|
||||
{
|
||||
$this->attrs = array_merge(array('cols' => '40', 'rows' => '10'),
|
||||
$attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the HTML of the input.
|
||||
*
|
||||
* @param string Name of the field.
|
||||
* @param mixed Value for the field, can be a non valid value.
|
||||
* @param array Extra attributes to add to the input form (array())
|
||||
* @return string The HTML string of the input.
|
||||
*/
|
||||
public function render($name, $value, $extra_attrs=array())
|
||||
{
|
||||
if ($value === null) $value = '';
|
||||
$final_attrs = $this->buildAttrs(array('name' => $name),
|
||||
$extra_attrs);
|
||||
return new Pluf_Template_SafeString(
|
||||
sprintf('<textarea%s>%s</textarea>',
|
||||
Pluf_Form_Widget_Attrs($final_attrs),
|
||||
htmlspecialchars($value, ENT_COMPAT, 'UTF-8')),
|
||||
true);
|
||||
}
|
||||
}
|
98
pluf/src/Pluf/Form/Widget/TinyMCEInput.php
Normal file
98
pluf/src/Pluf/Form/Widget/TinyMCEInput.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of Plume Framework, a simple PHP Application Framework.
|
||||
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
|
||||
#
|
||||
# Plume Framework is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2.1 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Plume Framework is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Textarea with TinyMCE addition.
|
||||
*/
|
||||
class Pluf_Form_Widget_TinyMCEInput extends Pluf_Form_Widget
|
||||
{
|
||||
public $tiny_mceurl = '/media/js/editor/tiny_mce.js';
|
||||
public $mode = 'textareas';
|
||||
public $theme = 'simple';
|
||||
public $include_tinymce = true;
|
||||
|
||||
public function __construct($attrs=array())
|
||||
{
|
||||
$defaults = array('cols' => '70',
|
||||
'rows' => '20');
|
||||
$config = array('tinymce_url', 'mode', 'theme', 'include_tinymce');
|
||||
foreach ($config as $cfg) {
|
||||
if (isset($attrs[$cfg])) {
|
||||
$this->$cfg = $attrs[$cfg];
|
||||
unset($attrs[$cfg]);
|
||||
}
|
||||
}
|
||||
$this->attrs = array_merge($defaults, $attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the HTML of the input.
|
||||
*
|
||||
* @param string Name of the field.
|
||||
* @param mixed Value for the field, can be a non valid value.
|
||||
* @param array Extra attributes to add to the input form (array())
|
||||
* @return string The HTML string of the input.
|
||||
*/
|
||||
public function render($name, $value, $extra_attrs=array())
|
||||
{
|
||||
if ($value === null) $value = '';
|
||||
$extra_config = '';
|
||||
if (isset($this->attrs['editor_config'])) {
|
||||
$_ec = $this->attrs['editor_config'];
|
||||
unset($this->attrs['editor_config']);
|
||||
$_st = array();
|
||||
foreach ($_ec as $key=>$val) {
|
||||
if (is_bool($val)) {
|
||||
if ($val) {
|
||||
$_st[] = $key.' : true';
|
||||
} else {
|
||||
$_st[] = $key.' : false';
|
||||
}
|
||||
} else {
|
||||
$_st[] = $key.' : "'.$val.'"';
|
||||
}
|
||||
}
|
||||
if ($_st) {
|
||||
$extra_config = ",\n".implode(",\n", $_st);
|
||||
}
|
||||
}
|
||||
$final_attrs = $this->buildAttrs(array('name' => $name),
|
||||
$extra_attrs);
|
||||
// The special include for tinyMCE
|
||||
$out = '';
|
||||
if ($this->include_tinymce) {
|
||||
$out .= '<script language="javascript" type="text/javascript" src="'.$this->tinymce_url.'"></script>'."\n";
|
||||
}
|
||||
$out .='<script language="javascript" type="text/javascript">
|
||||
tinyMCE.init({
|
||||
mode : "'.$this->mode.'",
|
||||
theme : "'.$this->theme.'"'.$extra_config.'
|
||||
});
|
||||
</script>';
|
||||
return new Pluf_Template_SafeString(
|
||||
$out.sprintf('<textarea%s>%s</textarea>',
|
||||
Pluf_Form_Widget_Attrs($final_attrs),
|
||||
htmlspecialchars($value, ENT_COMPAT, 'UTF-8')),
|
||||
true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user