From 19ae54775b0c7e210462363cc4bfc72bdeb8103f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 14 Jan 2009 01:04:49 -0500 Subject: [PATCH] Move favor and disfavor form to their own classes --- lib/disfavorform.php | 130 +++++++++++++++++++++++++++++++++++++++++++ lib/favorform.php | 130 +++++++++++++++++++++++++++++++++++++++++++ lib/util.php | 89 ----------------------------- 3 files changed, 260 insertions(+), 89 deletions(-) create mode 100644 lib/disfavorform.php create mode 100644 lib/favorform.php diff --git a/lib/disfavorform.php b/lib/disfavorform.php new file mode 100644 index 0000000000..25f99f43c1 --- /dev/null +++ b/lib/disfavorform.php @@ -0,0 +1,130 @@ +. + * + * @category Form + * @package Laconica + * @author Evan Prodromou + * @author Sarven Capadisli + * @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 + * @author Sarven Capadisli + * @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')); + } +} \ No newline at end of file diff --git a/lib/favorform.php b/lib/favorform.php new file mode 100644 index 0000000000..c67e186974 --- /dev/null +++ b/lib/favorform.php @@ -0,0 +1,130 @@ +. + * + * @category Form + * @package Laconica + * @author Evan Prodromou + * @author Sarven Capadisli + * @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 + * @author Sarven Capadisli + * @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')); + } +} \ No newline at end of file diff --git a/lib/util.php b/lib/util.php index a1e325204a..13117f8b19 100644 --- a/lib/util.php +++ b/lib/util.php @@ -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',