diff options
author | robocoder <anthon.pang@gmail.com> | 2010-07-06 22:28:19 +0400 |
---|---|---|
committer | robocoder <anthon.pang@gmail.com> | 2010-07-06 22:28:19 +0400 |
commit | 6c8f3b8d6c9a52e900567a92ebb6277188ed2174 (patch) | |
tree | d775d5bfe92944a799552a37d21b3539bfc8b00e | |
parent | 6ed0125bd7fc55d452cbb3ee6e467786fb18c379 (diff) |
fixes #1442 - all GPL license incompatibilities resolved
Live: Thanks to Remy Sharp, jquery.spy is now explicitly MIT licensed.
Installation: converted to use HTML_QuickForm2
Login: converted to use HTML_QuickForm2
git-svn-id: http://dev.piwik.org/svn/trunk@2438 59fd770c-687e-43c8-a1e3-f5a4ff64c105
-rw-r--r-- | LEGALNOTICE | 22 | ||||
-rw-r--r-- | core/QuickForm.php | 121 | ||||
-rw-r--r-- | core/QuickForm2.php | 111 | ||||
-rw-r--r-- | core/View.php | 26 | ||||
-rw-r--r-- | plugins/Installation/FormDatabaseSetup.php | 62 | ||||
-rw-r--r-- | plugins/Installation/FormFirstWebsiteSetup.php | 85 | ||||
-rw-r--r-- | plugins/Installation/FormGeneralSetup.php | 117 | ||||
-rw-r--r-- | plugins/Live/templates/scripts/MIT-LICENSE.txt | 19 | ||||
-rw-r--r-- | plugins/Login/Controller.php | 3 | ||||
-rw-r--r-- | plugins/Login/FormLogin.php | 25 | ||||
-rw-r--r-- | plugins/Login/FormPassword.php | 19 | ||||
-rw-r--r-- | plugins/Login/FormResetPassword.php | 51 | ||||
-rw-r--r-- | themes/default/genericForm.tpl | 76 |
13 files changed, 363 insertions, 374 deletions
diff --git a/LEGALNOTICE b/LEGALNOTICE index 4b751655a3..9ae423209a 100644 --- a/LEGALNOTICE +++ b/LEGALNOTICE @@ -64,7 +64,7 @@ THIRD-PARTY COMPONENTS AND LIBRARIES Name: jquery.spy Link: http://leftlogic.com/lounge/articles/jquery_spy2 - License: unspecified + License: MIT Name: Superfish Link: http://users.tpg.com.au/j_birch/plugins/superfish/ @@ -108,17 +108,17 @@ THIRD-PARTY COMPONENTS AND LIBRARIES Link: http://pear.php.net/package/Event_Dispatcher/ License: Modified BSD - Name: HTML Common - Link: http://pear.php.net/package/HTML_Common - License: PHP 3.01 - Notes: - - this license is not GPL v3 compatible + Name: HTML Common2 + Link: http://pear.php.net/package/HTML_Common2/ + License: Modified BSD - Name: HTML QuickForm - Link: http://pear.php.net/package/HTML_QuickForm/ - License: PHP 3.01 - Notes: - - this license is not GPL v3 compatible + Name: HTML QuickForm2 + Link: http://pear.php.net/package/HTML_QuickForm2/ + License: Modified BSD + + Name: HTML QuickForm2_Renderer_Smarty + Link: http://www.phcomp.co.uk/tmp/Smarty.phps + License: Modified BSD Name: Open Flash Chart Link: http://teethgrinder.co.uk/open-flash-chart-2/ diff --git a/core/QuickForm.php b/core/QuickForm.php deleted file mode 100644 index 4ad558171f..0000000000 --- a/core/QuickForm.php +++ /dev/null @@ -1,121 +0,0 @@ -<?php -/** - * Piwik - Open source web analytics - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later - * @version $Id$ - * - * @category Piwik - * @package Piwik - */ - -/** - * Parent class for forms to be included in Smarty - * - * For an example, @see Piwik_Login_FormLogin - * - * @package Piwik - * @see HTML_QuickForm, libs/HTML/QuickForm.php - * @link http://pear.php.net/package/HTML_QuickForm/ - */ -abstract class Piwik_QuickForm extends HTML_QuickForm -{ - protected $a_formElements = array(); - - function __construct( $action = '', $attributes = '' ) - { - if(empty($action)) - { - $action = Piwik_Url::getCurrentQueryString(); - } - parent::HTML_QuickForm('form', 'POST', $action, $target='', $attributes); - - $this->registerRule( 'checkEmail', 'function', 'Piwik_QuickForm_isValidEmailString'); - $this->registerRule( 'fieldHaveSameValue', 'function', 'Piwik_QuickForm_fieldHaveSameValue'); - - $this->init(); - } - - abstract function init(); - - function getElementList() - { - $listElements=array(); - foreach($this->a_formElements as $title => $a_parameters) - { - foreach($a_parameters as $parameters) - { - if($parameters[1] != 'headertext' - && $parameters[1] != 'submit') - { - // case radio : there are two labels but only record once, unique name - if( !isset($listElements[$title]) - || !in_array($parameters[1], $listElements[$title])) - { - $listElements[$title][] = $parameters[1]; - } - } - } - } - return $listElements; - } - - function addElements( $a_formElements, $sectionTitle = '' ) - { - foreach($a_formElements as $parameters) - { - call_user_func_array(array(&$this , "addElement"), $parameters ); - } - - $this->a_formElements = - array_merge( - $this->a_formElements, - array( - $sectionTitle => $a_formElements - ) - ); - } - - function addRules( $a_formRules) - { - foreach($a_formRules as $parameters) - { - call_user_func_array(array(&$this , "addRule"), $parameters ); - } - - } - - function setChecked( $nameElement ) - { - foreach( $this->_elements as $key => $value) - { - if($value->_attributes['name'] == $nameElement) - { - $this->_elements[$key]->_attributes['checked'] = 'checked'; - } - } - } - function setSelected( $nameElement, $value ) - { - foreach( $this->_elements as $key => $value) - { - if($value->_attributes['name'] == $nameElement) - { - $this->_elements[$key]->_attributes['selected'] = 'selected'; - } - } - } -} - -function Piwik_QuickForm_fieldHaveSameValue($element, $value, $arg) -{ - $value2 = Piwik_Common::getRequestVar( $arg, '', 'string'); - $value2 = Piwik_Common::unsanitizeInputValue($value2); - return $value === $value2; -} - -function Piwik_QuickForm_isValidEmailString( $element, $value ) -{ - return Piwik::isValidEmailString($value); -} diff --git a/core/QuickForm2.php b/core/QuickForm2.php new file mode 100644 index 0000000000..d39aa8a97b --- /dev/null +++ b/core/QuickForm2.php @@ -0,0 +1,111 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later + * @version $Id:$ + * + * @category Piwik + * @package Piwik + */ + +/** + * Parent class for forms to be included in Smarty + * + * For an example, @see Piwik_Login_FormLogin + * + * @package Piwik + * @see HTML_QuickForm2, libs/HTML/QuickForm2.php + * @link http://pear.php.net/package/HTML_QuickForm2/ + */ +abstract class Piwik_QuickForm2 extends HTML_QuickForm2 +{ + protected $a_formElements = array(); + + function __construct( $id, $method = 'post', $attributes = null, $trackSubmit = false) + { + if(!isset($attributes['action'])) + { + $attributes['action'] = Piwik_Url::getCurrentQueryString(); + } + if(!isset($attributes['name'])) + { + $attributes['name'] = $id; + } + parent::__construct($id, $method, $attributes, $trackSubmit); + + $this->init(); + } + + /** + * Class specific initialization + */ + abstract function init(); + + /** + * The elements in this form + * + * @return array Element names + */ + public function getElementList() + { + return $this->a_formElements; + } + + /** + * Wrapper around HTML_QuickForm2_Container's addElement() + * + * @param string|HTML_QuickForm2_Node Either type name (treated + * case-insensitively) or an element instance + * @param mixed Element name + * @param mixed Element attributes + * @param array Element-specific data + * @return HTML_QuickForm2_Node Added element + * @throws HTML_QuickForm2_InvalidArgumentException + * @throws HTML_QuickForm2_NotFoundException + */ + public function addElement($elementOrType, $name = null, $attributes = null, + array $data = array()) + { + if($name != 'submit') + { + $this->a_formElements[] = $name; + } + + return parent::addElement($elementOrType, $name, $attributes, $data); + } + + function setChecked( $nameElement ) + { + foreach( $this->_elements as $key => $value) + { + if($value->_attributes['name'] == $nameElement) + { + $this->_elements[$key]->_attributes['checked'] = 'checked'; + } + } + } + function setSelected( $nameElement, $value ) + { + foreach( $this->_elements as $key => $value) + { + if($value->_attributes['name'] == $nameElement) + { + $this->_elements[$key]->_attributes['selected'] = 'selected'; + } + } + } + + /** + * Ported from HTML_QuickForm to minimize changes to Controllers + * + * @param string $elementName + * @return mixed + */ + function getSubmitValue($elementName) + { + $value = $this->getValue(); + return isset($value[$elementName]) ? $value[$elementName] : null; + } +} diff --git a/core/View.php b/core/View.php index 443950d851..c5cd2390fa 100644 --- a/core/View.php +++ b/core/View.php @@ -162,19 +162,25 @@ class Piwik_View implements Piwik_iView /** * Add form to view * - * @param Piwik_QuickForm $form + * @param Piwik_QuickForm2 $form */ public function addForm( $form ) { - // Create the renderer object - $renderer = new HTML_QuickForm_Renderer_ArraySmarty($this->smarty, false, false); - - // build the HTML for the form - $form->accept($renderer); - - // assign array with form data - $this->smarty->assign('form_data', $renderer->toArray()); - $this->smarty->assign('element_list', $form->getElementList()); + if($form instanceof Piwik_QuickForm2) + { + HTML_QuickForm2_Renderer::register('smarty', 'HTML_QuickForm2_Renderer_Smarty'); + + // Create the renderer object + $renderer = HTML_QuickForm2_Renderer::factory('smarty'); + $renderer->setOption('group_errors', true); + + // build the HTML for the form + $form->render($renderer); + + // assign array with form data + $this->smarty->assign('form_data', $renderer->toArray()); + $this->smarty->assign('element_list', $form->getElementList()); + } } /** diff --git a/plugins/Installation/FormDatabaseSetup.php b/plugins/Installation/FormDatabaseSetup.php index f1b9855e53..faa7d76be7 100644 --- a/plugins/Installation/FormDatabaseSetup.php +++ b/plugins/Installation/FormDatabaseSetup.php @@ -14,14 +14,15 @@ * * @package Piwik_Installation */ -class Piwik_Installation_FormDatabaseSetup extends Piwik_QuickForm +class Piwik_Installation_FormDatabaseSetup extends Piwik_QuickForm2 { - function __construct( $action = '', $attributes = '' ) + function __construct( $id = 'databasesetupform', $method = 'post', $attributes = null, $trackSubmit = false) { - parent::__construct($action = '', $attributes = 'autocomplete="off"'); + parent::__construct($id, $method, $attributes = array('autocomplete' => 'off'), $trackSubmit); } + function init() - { + { $availableAdapters = Piwik_Db_Adapter::getAdapters(); $adapters = array(); foreach($availableAdapters as $adapter => $port) @@ -29,26 +30,35 @@ class Piwik_Installation_FormDatabaseSetup extends Piwik_QuickForm $adapters[$adapter] = $adapter; } - $formElements = array( - array('text', 'host', Piwik_Translate('Installation_DatabaseSetupServer'), 'value='.'localhost'), - array('text', 'username', Piwik_Translate('Installation_DatabaseSetupLogin')), - array('password', 'password', Piwik_Translate('Installation_DatabaseSetupPassword')), - array('text', 'dbname', Piwik_Translate('Installation_DatabaseSetupDatabaseName')), - array('text', 'tables_prefix', Piwik_Translate('Installation_DatabaseSetupTablePrefix'), 'value='.'piwik_'), - array('select', 'adapter', Piwik_Translate('Installation_DatabaseSetupAdapter'), $adapters), - ); - $this->addElements( $formElements ); - - $formRules = array(); - foreach($formElements as $row) - { - if($row[1] != 'password' && $row[1] != 'tables_prefix') - { - $formRules[] = array($row[1], Piwik_Translate('General_Required', $row[2]), 'required'); - } - } - $this->addRules( $formRules ); - - $this->addElement('submit', 'submit', Piwik_Translate('Installation_SubmitGo')); - } + $this->addElement('text', 'host') + ->setLabel(Piwik_Translate('Installation_DatabaseSetupServer')) + ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_DatabaseSetupServer'))); + + $this->addElement('text', 'username') + ->setLabel(Piwik_Translate('Installation_DatabaseSetupLogin')) + ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_DatabaseSetupLogin'))); + + $this->addElement('password', 'password') + ->setLabel(Piwik_Translate('Installation_DatabaseSetupPassword')); + + $this->addElement('text', 'dbname') + ->setLabel(Piwik_Translate('Installation_DatabaseSetupDatabaseName')) + ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_DatabaseSetupDatabaseName'))); + + $this->addElement('text', 'tables_prefix') + ->setLabel(Piwik_Translate('Installation_DatabaseSetupTablePrefix')); + + $this->addElement('select', 'adapter') + ->setLabel(Piwik_Translate('Installation_DatabaseSetupAdapter')) + ->loadOptions($adapters) + ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_DatabaseSetupAdapter'))); + + $this->addElement('submit', 'submit', array('value' => Piwik_Translate('Installation_SubmitGo'))); + + // default values + $this->addDataSource(new HTML_QuickForm2_DataSource_Array(array( + 'host' => 'localhost', + 'tables_prefix' => 'piwik', + ))); + } } diff --git a/plugins/Installation/FormFirstWebsiteSetup.php b/plugins/Installation/FormFirstWebsiteSetup.php index a44b51289c..4fd0eadfa8 100644 --- a/plugins/Installation/FormFirstWebsiteSetup.php +++ b/plugins/Installation/FormFirstWebsiteSetup.php @@ -14,55 +14,58 @@ * * @package Piwik_Installation */ -class Piwik_Installation_FormFirstWebsiteSetup extends Piwik_QuickForm +class Piwik_Installation_FormFirstWebsiteSetup extends Piwik_QuickForm2 { - function validate() + function __construct( $id = 'websitesetupform', $method = 'post', $attributes = null, $trackSubmit = false) { - try { - $timezone = $this->getSubmitValue('timezone'); - if(!empty($timezone)) - { - Piwik_SitesManager_API::getInstance()->setDefaultTimezone($timezone); - } - } catch(Exception $e) { - $this->_errors['timezone'] = Piwik_Translate('General_NotValid', Piwik_Translate('Installation_Timezone')); - } - return parent::validate(); + parent::__construct($id, $method, $attributes, $trackSubmit); } - + function init() { - $urlToGoAfter = 'index.php' . Piwik_Url::getCurrentQueryString(); + HTML_QuickForm2_Factory::registerRule('checkTimezone', 'Piwik_Installation_FormFirstWebsiteSetup_Rule_isValidTimezone'); $urlExample = 'http://example.org'; - $javascriptOnClickUrlExample = "\"javascript:if(this.value=='$urlExample'){this.value='http://';} this.style.color='black';\""; - + $javascriptOnClickUrlExample = "javascript:if(this.value=='$urlExample'){this.value='http://';} this.style.color='black';"; + $timezones = Piwik_SitesManager_API::getInstance()->getTimezonesList(); $timezones = array_merge(array('No timezone' => Piwik_Translate('SitesManager_SelectACity')), $timezones); - - $formElements = array( - array('text', 'siteName', Piwik_Translate('Installation_SetupWebSiteName')), - array('text', 'url', Piwik_Translate('Installation_SetupWebSiteURL'), "style='color:rgb(153, 153, 153);' value=$urlExample onfocus=".$javascriptOnClickUrlExample." onclick=".$javascriptOnClickUrlExample), - array('select', 'timezone', Piwik_Translate('Installation_Timezone'), $timezones), - - ); - $this->addElements( $formElements ); - - $formRules = array(); - foreach($formElements as $row) - { - $formRules[] = array($row[1], Piwik_Translate('General_Required', $row[2]), 'required'); - } - - - $submitTimezone = $this->getSubmitValue('timezone'); - if(!$this->isSubmitted() - || !empty($submitTimezone)) - { - $this->setSelected('timezone', $submitTimezone); - } - $this->addRules( $formRules ); - - $this->addElement('submit', 'submit', Piwik_Translate('Installation_SubmitGo')); + + $this->addElement('text', 'siteName') + ->setLabel(Piwik_Translate('Installation_SetupWebSiteName')) + ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_SetupWebSiteName'))); + + $url = $this->addElement('text', 'url') + ->setLabel(Piwik_Translate('Installation_SetupWebSiteURL')); + $url->setAttribute('style', 'color:rgb(153, 153, 153);'); + $url->setValue($urlExample); + $url->setAttribute('onfocus', $javascriptOnClickUrlExample); + $url->setAttribute('onclick', $javascriptOnClickUrlExample); + $url->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_SetupWebSiteURL'))); + + $tz = $this->addElement('select', 'timezone') + ->setLabel(Piwik_Translate('Installation_Timezone')) + ->loadOptions($timezones); + $tz->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_Timezone'))); + $tz->addRule('checkTimezone', Piwik_Translate('General_NotValid', Piwik_Translate('Installation_Timezone'))); + + $this->addElement('submit', 'submit', array('value' => Piwik_Translate('Installation_SubmitGo'))); } } + +class Piwik_Installation_FormFirstWebsiteSetup_Rule_isValidTimezone extends HTML_QuickForm2_Rule +{ + function validateOwner() + { + try { + $timezone = $this->owner->getValue(); + if(!empty($timezone)) + { + Piwik_SitesManager_API::getInstance()->setDefaultTimezone($timezone); + } + } catch(Exception $e) { + return false; + } + return true; + } +} diff --git a/plugins/Installation/FormGeneralSetup.php b/plugins/Installation/FormGeneralSetup.php index 45d066ef4b..8d1859308d 100644 --- a/plugins/Installation/FormGeneralSetup.php +++ b/plugins/Installation/FormGeneralSetup.php @@ -14,74 +14,77 @@ * * @package Piwik_Installation */ -class Piwik_Installation_FormGeneralSetup extends Piwik_QuickForm +class Piwik_Installation_FormGeneralSetup extends Piwik_QuickForm2 { - function __construct( $action = '', $attributes = '' ) + function __construct( $id = 'generalsetupform', $method = 'post', $attributes = null, $trackSubmit = false) { - parent::__construct($action = '', $attributes = 'autocomplete="off"'); + parent::__construct($id, $method, $attributes = array('autocomplete' => 'off'), $trackSubmit); } - - function validate() + + function init() + { + HTML_QuickForm2_Factory::registerRule('checkLogin', 'Piwik_Installation_FormGeneralSetup_Rule_isValidLoginString'); + HTML_QuickForm2_Factory::registerRule('checkEmail', 'Piwik_Installation_FormGeneralSetup_Rule_isValidEmailString'); + + $login = $this->addElement('text', 'login') + ->setLabel(Piwik_Translate('Installation_SuperUserLogin')); + $login->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_SuperUserLogin'))); + $login->addRule('checkLogin'); + + $password = $this->addElement('password', 'password') + ->setLabel(Piwik_Translate('Installation_Password')); + $password->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_Password'))); + + $passwordBis = $this->addElement('password', 'password_bis') + ->setLabel(Piwik_Translate('Installation_PasswordRepeat')); + $passwordBis->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_PasswordRepeat'))); + $passwordBis->addRule('eq', Piwik_Translate( 'Installation_PasswordDoNotMatch'), $password); + + $email = $this->addElement('text', 'email') + ->setLabel(Piwik_Translate('Installation_Email')); + $email->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_Email'))); + $email->addRule('checkEmail', Piwik_Translate( 'UsersManager_ExceptionInvalidEmail')); + + $this->addElement('checkbox', 'subscribe_newsletter_security', null, array( + 'content' => ' ' . Piwik_Translate('Installation_SecurityNewsletter'), + )); + + $this->addElement('checkbox', 'subscribe_newsletter_community', null, array( + 'content' => ' ' . Piwik_Translate('Installation_CommunityNewsletter'), + )); + + $this->addElement('submit', 'submit', array('value' => Piwik_Translate('Installation_SubmitGo'))); + + // default values + $this->addDataSource(new HTML_QuickForm2_DataSource_Array(array( + 'subscribe_newsletter_community' => 1, + 'subscribe_newsletter_security' => 1, + ))); + } +} + +class Piwik_Installation_FormGeneralSetup_Rule_isValidLoginString extends HTML_QuickForm2_Rule +{ + function validateOwner() { try { - $login = $this->getSubmitValue('login'); + $login = $this->owner->getValue(); if(!empty($login)) { Piwik::checkValidLoginString($login); } } catch(Exception $e) { - $this->_errors['login'] = $e->getMessage(); + $this->setMessage($e->getMessage()); + return false; } - return parent::validate(); + return true; } - - function init() - { - $urlToGoAfter = 'index.php' . Piwik_Url::getCurrentQueryString(); +} - $formElements = array( - array('text', 'login', Piwik_Translate('Installation_SuperUserLogin')), - array('password', 'password', Piwik_Translate('Installation_Password')), - array('password', 'password_bis', Piwik_Translate('Installation_PasswordRepeat')), - array('text', 'email', Piwik_Translate('Installation_Email')), - array('checkbox', 'subscribe_newsletter_security', '', ' ' . Piwik_Translate('Installation_SecurityNewsletter')), - array('checkbox', 'subscribe_newsletter_community', '', ' '. Piwik_Translate('Installation_CommunityNewsletter')), - ); - $this->addElements( $formElements ); - - if(!$this->isSubmitted() - || $this->getSubmitValue('subscribe_newsletter_community') == '1') - { - $this->setChecked('subscribe_newsletter_community'); - } - if(!$this->isSubmitted() - || $this->getSubmitValue('subscribe_newsletter_security') == '1') - { - $this->setChecked('subscribe_newsletter_security'); - } - - $formRules = array(); - foreach($formElements as $row) - { - // checkboxes are not required (form should validate when unchecked) - if(in_array($row[1],array('subscribe_newsletter_security','subscribe_newsletter_community'))) - { - continue; - } - $formRules[] = array($row[1], Piwik_Translate('General_Required', $row[2]), 'required'); - } - - $formRules[] = array( 'email', - Piwik_Translate( 'UsersManager_ExceptionInvalidEmail'), - 'checkEmail' - ); - $formRules[] = array( 'password', - Piwik_Translate( 'Installation_PasswordDoNotMatch'), - 'fieldHaveSameValue', - 'password_bis' - ); - - $this->addRules( $formRules ); - $this->addElement('submit', 'submit', Piwik_Translate('Installation_SubmitGo')); - } +class Piwik_Installation_FormGeneralSetup_Rule_isValidEmailString extends HTML_QuickForm2_Rule +{ + function validateOwner() + { + return Piwik::isValidEmailString($this->owner->getValue()); + } } diff --git a/plugins/Live/templates/scripts/MIT-LICENSE.txt b/plugins/Live/templates/scripts/MIT-LICENSE.txt new file mode 100644 index 0000000000..8d0022310a --- /dev/null +++ b/plugins/Live/templates/scripts/MIT-LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) 2006 Remy Sharp (leftlogic.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/plugins/Login/Controller.php b/plugins/Login/Controller.php index 874b55bc06..ceb7204a72 100644 --- a/plugins/Login/Controller.php +++ b/plugins/Login/Controller.php @@ -95,7 +95,6 @@ class Piwik_Login_Controller extends Piwik_Controller $view->nonce = Piwik_Nonce::getNonce('Piwik_Login.login'); $view->linkTitle = Piwik::getRandomTitle(); $view->addForm( $form ); - $view->subTemplate = 'genericForm.tpl'; echo $view->render(); } @@ -165,7 +164,6 @@ class Piwik_Login_Controller extends Piwik_Controller $view->AccessErrorString = $messageNoAccess; $view->linkTitle = Piwik::getRandomTitle(); $view->addForm( $form ); - $view->subTemplate = 'genericForm.tpl'; echo $view->render(); } @@ -256,7 +254,6 @@ class Piwik_Login_Controller extends Piwik_Controller $view->AccessErrorString = $messageNoAccess; $view->linkTitle = Piwik::getRandomTitle(); $view->addForm( $form ); - $view->subTemplate = 'genericForm.tpl'; echo $view->render(); } diff --git a/plugins/Login/FormLogin.php b/plugins/Login/FormLogin.php index d30bd86caa..0dfd83a661 100644 --- a/plugins/Login/FormLogin.php +++ b/plugins/Login/FormLogin.php @@ -14,29 +14,22 @@ * * @package Piwik_Login */ -class Piwik_Login_FormLogin extends Piwik_QuickForm +class Piwik_Login_FormLogin extends Piwik_QuickForm2 { - function __construct( $action = '', $attributes = '' ) + function __construct( $id = 'loginform', $method = 'post', $attributes = null, $trackSubmit = false) { - parent::__construct($action, $attributes); - // reset - $this->updateAttributes('id="loginform" name="loginform"'); + parent::__construct($id, $method, $attributes, $trackSubmit); } function init() { - $formElements = array( - array('text', 'form_login'), - array('password', 'form_password'), - array('hidden', 'form_nonce'), - ); - $this->addElements( $formElements ); + $this->addElement('text', 'form_login') + ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('General_Username'))); - $formRules = array( - array('form_login', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('General_Username')), 'required'), - array('form_password', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('Login_Password')), 'required'), - ); - $this->addRules( $formRules ); + $this->addElement('password', 'form_password') + ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Login_Password'))); + + $this->addElement('hidden', 'form_nonce'); $this->addElement('submit', 'submit'); } diff --git a/plugins/Login/FormPassword.php b/plugins/Login/FormPassword.php index a105c47296..6f7338dcb2 100644 --- a/plugins/Login/FormPassword.php +++ b/plugins/Login/FormPassword.php @@ -14,26 +14,17 @@ * * @package Piwik_Login */ -class Piwik_Login_FormPassword extends Piwik_QuickForm +class Piwik_Login_FormPassword extends Piwik_QuickForm2 { - function __construct( $action = '', $attributes = '' ) + function __construct( $id = 'lostpasswordform', $method = 'post', $attributes = null, $trackSubmit = false) { - parent::__construct($action, $attributes); - // reset - $this->updateAttributes('id="lostpasswordform" name="lostpasswordform"'); + parent::__construct($id, $method, $attributes, $trackSubmit); } function init() { - $formElements = array( - array('text', 'form_login'), - ); - $this->addElements( $formElements ); - - $formRules = array( - array('form_login', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('Login_LoginOrEmail')), 'required'), - ); - $this->addRules( $formRules ); + $this->addElement('text', 'form_login') + ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Login_LoginOrEmail'))); $this->addElement('submit', 'submit'); } diff --git a/plugins/Login/FormResetPassword.php b/plugins/Login/FormResetPassword.php index 444713fcf4..dbc080aa57 100644 --- a/plugins/Login/FormResetPassword.php +++ b/plugins/Login/FormResetPassword.php @@ -14,41 +14,38 @@ * * @package Piwik_Login */ -class Piwik_Login_FormResetPassword extends Piwik_QuickForm +class Piwik_Login_FormResetPassword extends Piwik_QuickForm2 { - function __construct( $action = '', $attributes = '' ) + function __construct( $id = 'resetpasswordform', $method = 'post', $attributes = null, $trackSubmit = false) { - parent::__construct($action, $attributes); - // reset - $this->updateAttributes('id="resetpasswordform" name="resetpasswordform"'); + parent::__construct($id, $method, $attributes, $trackSubmit); } function init() { - $resetToken = Piwik_Common::getRequestVar('token', '', 'string'); + $this->addElement('text', 'form_login') + ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('General_Username'))); + + $password = $this->addElement('password', 'form_password'); + $password->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Login_Password'))); + + $passwordBis = $this->addElement('password', 'form_password_bis'); + $passwordBis->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Login_PasswordRepeat'))); + $passwordBis->addRule('eq', Piwik_Translate( 'Login_PasswordsDoNotMatch'), $password); - $formElements = array( - array('text', 'form_login'), - array('password', 'form_password'), - array('password', 'form_password_bis'), - array('text', 'form_token'), - ); - $this->addElements( $formElements ); - - $defaults = array( - 'form_token' => $resetToken, - ); - $this->setDefaults($defaults); - - $formRules = array( - array('form_login', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('General_Username')), 'required'), - array('form_password', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('Login_Password')), 'required'), - array('form_password_bis', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('Login_PasswordRepeat')), 'required'), - array('form_token', sprintf(Piwik_Translate('General_Required'), Piwik_Translate('Login_PasswordResetToken')), 'required'), - array('form_password', Piwik_Translate( 'Login_PasswordsDoNotMatch'), 'fieldHaveSameValue', 'form_password_bis'), - ); - $this->addRules( $formRules ); + $this->addElement('text', 'form_token') + ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Login_PasswordResetToken'))); $this->addElement('submit', 'submit'); + + $resetToken = Piwik_Common::getRequestVar('token', '', 'string'); + if(!empty($resetToken)) { + // default values + $this->addDataSource(new HTML_QuickForm2_DataSource_Array(array( + 'form_token' => $resetToken, + ))); + + $this->attributes['action'] = Piwik_Url::getCurrentQueryStringWithParametersModified( array('token' => null) ); + } } } diff --git a/themes/default/genericForm.tpl b/themes/default/genericForm.tpl index fccbc45d60..668bf44723 100644 --- a/themes/default/genericForm.tpl +++ b/themes/default/genericForm.tpl @@ -1,58 +1,38 @@ - {if $form_data.errors} <div class="warning"> <img src="themes/default/images/warning_medium.png"> - <strong>{'Installation_PleaseFixTheFollowingErrors'|translate}:</strong> - <ul> - {foreach from=$form_data.errors item=data} - <li>{$data}</li> - {/foreach} - </ul> + <strong>{'Installation_PleaseFixTheFollowingErrors'|translate}:</strong> + <ul> + {foreach from=$form_data.errors item=data} + <li>{$data}</li> + {/foreach} + </ul> </div> {/if} -{* -{if isset($form_text)} -<p>{$form_text}</p> -{/if} -*} - <form {$form_data.attributes}> -<!-- Output hidden fields --> - -<!-- Display the fields --> -{foreach from=$element_list key=title item=data} - <h3>{$title}</h3> <div class="centrer"> - <table class="centrer"> - {foreach from=$data item=fieldname} - {* normal form *} - {if $form_data.$fieldname.type== 'checkbox'} - <tr> - <td colspan=2>{$form_data.$fieldname.html}</td> - </tr> - {elseif $form_data.$fieldname.label} - <tr> - <td>{$form_data.$fieldname.label}</td> - <td>{$form_data.$fieldname.html}</td> - </tr> - {elseif $form_data.$fieldname.type == 'hidden'} - <tr><td colspan=2>{$form_data.$fieldname.html}</td></tr> - {* radio form - {else} - {foreach from=$form_data.$fieldname key=key item=radio} - <tr> - <td>{$radio.label}</td> - <td>{$radio.html}</td> - </tr> - {/foreach}*} - {/if} - {/foreach} - </table> + <table class="centrer"> + {foreach from=$element_list item=fieldname} + {if $form_data.$fieldname.type== 'checkbox'} + <tr> + <td colspan=2>{$form_data.$fieldname.html}</td> + </tr> + {elseif $form_data.$fieldname.label} + <tr> + <td>{$form_data.$fieldname.label}</td> + <td>{$form_data.$fieldname.html}</td> + </tr> + {elseif $form_data.$fieldname.type == 'hidden'} + <tr> + <td colspan=2>{$form_data.$fieldname.html}</td> + </tr> + {/if} + {/foreach} + </table> </div> -{/foreach} -<div class="submit"> -{$form_data.submit.html} -</div> -</form> + <div class="submit"> + {$form_data.submit.html} + </div> +</form> |