summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEvan Prodromou <git@evanprodromou.name>2009-01-14 01:04:49 -0500
committerEvan Prodromou <git@evanprodromou.name>2009-01-14 01:04:49 -0500
commit19ae54775b0c7e210462363cc4bfc72bdeb8103f (patch)
tree2a692df5e3e7596d9626273e8dab15e9c0d26686 /lib
parente1907c9cb5324f7349de814c09728a64be589f3a (diff)
Move favor and disfavor form to their own classes
Diffstat (limited to 'lib')
-rw-r--r--lib/disfavorform.php130
-rw-r--r--lib/favorform.php130
-rw-r--r--lib/util.php89
3 files changed, 260 insertions, 89 deletions
diff --git a/lib/disfavorform.php b/lib/disfavorform.php
new file mode 100644
index 000000000..25f99f43c
--- /dev/null
+++ b/lib/disfavorform.php
@@ -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'));
+ }
+} \ No newline at end of file
diff --git a/lib/favorform.php b/lib/favorform.php
new file mode 100644
index 000000000..c67e18697
--- /dev/null
+++ b/lib/favorform.php
@@ -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'));
+ }
+} \ No newline at end of file
diff --git a/lib/util.php b/lib/util.php
index a1e325204..13117f8b1 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',