Move favor and disfavor form to their own classes

This commit is contained in:
Evan Prodromou 2009-01-14 01:04:49 -05:00
parent e1907c9cb5
commit 19ae54775b
3 changed files with 260 additions and 89 deletions

130
lib/disfavorform.php Normal file
View File

@ -0,0 +1,130 @@
<?php
/**
* Laconica, the distributed open-source microblogging tool
*
* Form for disfavoring a notice
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Form
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Sarven Capadisli <csarven@controlyourself.ca>
* @copyright 2009 Control Yourself, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*/
if (!defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/form.php';
/**
* Form for disfavoring a notice
*
* @category Form
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Sarven Capadisli <csarven@controlyourself.ca>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*
* @see FavorForm
*/
class DisfavorForm extends Form
{
/**
* Notice to disfavor
*/
var $notice = null;
/**
* Constructor
*
* @param HTMLOutputter $out output channel
* @param Notice $notice notice to disfavor
*/
function __construct($out=null, $notice=null)
{
parent::__construct($out);
$this->notice = $notice;
}
/**
* ID of the form
*
* @return int ID of the form
*/
function id()
{
return 'disfavor-' . $this->notice->id;
}
/**
* Action of the form
*
* @return string URL of the action
*/
function action()
{
common_local_url('disfavor');
}
/**
* Include a session token for CSRF protection
*
* @return void
*/
function sessionToken()
{
$this->out->hidden('token-' . $this->notice->id,
common_session_token());
}
/**
* Data elements
*
* @return void
*/
function formData()
{
$this->out->hidden('notice-n'.$this->notice->id,
$this->notice->id,
'notice');
}
/**
* Action elements
*
* @return void
*/
function formActions()
{
$this->out->submit('disfavor-submit-' . $this->notice->id,
_('Disfavor favorite'));
}
}

130
lib/favorform.php Normal file
View File

@ -0,0 +1,130 @@
<?php
/**
* Laconica, the distributed open-source microblogging tool
*
* Form for favoring a notice
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Form
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Sarven Capadisli <csarven@controlyourself.ca>
* @copyright 2009 Control Yourself, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*/
if (!defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/form.php';
/**
* Form for favoring a notice
*
* @category Form
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Sarven Capadisli <csarven@controlyourself.ca>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*
* @see DisfavorForm
*/
class FavorForm extends Form
{
/**
* Notice to favor
*/
var $notice = null;
/**
* Constructor
*
* @param HTMLOutputter $out output channel
* @param Notice $notice notice to favor
*/
function __construct($out=null, $notice=null)
{
parent::__construct($out);
$this->notice = $notice;
}
/**
* ID of the form
*
* @return int ID of the form
*/
function id()
{
return 'favor-' . $this->notice->id;
}
/**
* Action of the form
*
* @return string URL of the action
*/
function action()
{
common_local_url('favor');
}
/**
* Include a session token for CSRF protection
*
* @return void
*/
function sessionToken()
{
$this->out->hidden('token-' . $this->notice->id,
common_session_token());
}
/**
* Data elements
*
* @return void
*/
function formData()
{
$this->out->hidden('notice-n'.$this->notice->id,
$this->notice->id,
'notice');
}
/**
* Action elements
*
* @return void
*/
function formActions()
{
$this->out->submit('favor-submit-' . $this->notice->id,
_('Make a favorite'));
}
}

View File

@ -1295,39 +1295,6 @@ function common_profile_url($nickname)
return common_local_url('showstream', array('nickname' => $nickname));
}
// Don't call if nobody's logged in
function common_notice_form($action=null, $content=null)
{
$user = common_current_user();
assert(!is_null($user));
common_element_start('form', array('id' => 'status_form',
'method' => 'post',
'action' => common_local_url('newnotice')));
common_element_start('p');
common_element('label', array('for' => 'status_textarea',
'id' => 'status_label'),
sprintf(_('What\'s up, %s?'), $user->nickname));
common_element('span', array('id' => 'counter', 'class' => 'counter'), '140');
common_element('textarea', array('id' => 'status_textarea',
'cols' => 60,
'rows' => 3,
'name' => 'status_textarea'),
($content) ? $content : '');
common_hidden('token', common_session_token());
if ($action) {
common_hidden('returnto', $action);
}
// set by JavaScript
common_hidden('inreplyto', 'false');
common_element('input', array('id' => 'status_submit',
'name' => 'status_submit',
'type' => 'submit',
'value' => _('Send')));
common_element_end('p');
common_element_end('form');
}
// Should make up a reasonable root URL
function common_root_url()
@ -1671,62 +1638,6 @@ function common_session_token()
return $_SESSION['token'];
}
function common_disfavor_form($notice)
{
common_element_start('form', array('id' => 'disfavor-' . $notice->id,
'method' => 'post',
'class' => 'disfavor',
'action' => common_local_url('disfavor')));
common_element('input', array('type' => 'hidden',
'name' => 'token-'. $notice->id,
'id' => 'token-'. $notice->id,
'class' => 'token',
'value' => common_session_token()));
common_element('input', array('type' => 'hidden',
'name' => 'notice',
'id' => 'notice-n'. $notice->id,
'class' => 'notice',
'value' => $notice->id));
common_element('input', array('type' => 'submit',
'id' => 'disfavor-submit-' . $notice->id,
'name' => 'disfavor-submit-' . $notice->id,
'class' => 'disfavor',
'value' => 'Disfavor favorite',
'title' => 'Remove this message from favorites'));
common_element_end('form');
}
function common_favor_form($notice)
{
common_element_start('form', array('id' => 'favor-' . $notice->id,
'method' => 'post',
'class' => 'favor',
'action' => common_local_url('favor')));
common_element('input', array('type' => 'hidden',
'name' => 'token-'. $notice->id,
'id' => 'token-'. $notice->id,
'class' => 'token',
'value' => common_session_token()));
common_element('input', array('type' => 'hidden',
'name' => 'notice',
'id' => 'notice-n'. $notice->id,
'class' => 'notice',
'value' => $notice->id));
common_element('input', array('type' => 'submit',
'id' => 'favor-submit-' . $notice->id,
'name' => 'favor-submit-' . $notice->id,
'class' => 'favor',
'value' => 'Add to favorites',
'title' => 'Add this message to favorites'));
common_element_end('form');
}
function common_nudge_form($profile)
{
common_element_start('form', array('id' => 'nudge', 'method' => 'post',