summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
Diffstat (limited to 'actions')
-rw-r--r--actions/api.php1
-rw-r--r--actions/attachment.php12
-rw-r--r--actions/attachment_ajax.php22
-rw-r--r--actions/attachment_thumbnail.php (renamed from actions/attachments_ajax.php)87
-rw-r--r--actions/attachments.php292
-rw-r--r--actions/conversation.php203
-rw-r--r--actions/deletenotice.php4
-rw-r--r--actions/designsettings.php12
-rw-r--r--actions/facebookhome.php5
-rw-r--r--actions/facebookinvite.php65
-rw-r--r--actions/facebooksettings.php2
-rw-r--r--actions/file.php40
-rw-r--r--actions/newnotice.php109
-rw-r--r--actions/shownotice.php4
-rw-r--r--actions/tag.php2
15 files changed, 432 insertions, 428 deletions
diff --git a/actions/api.php b/actions/api.php
index 8762b4bcd..b25ba99f3 100644
--- a/actions/api.php
+++ b/actions/api.php
@@ -67,6 +67,7 @@ class ApiAction extends Action
$this->process_command();
} else {
# basic authentication failed
+ common_log(LOG_WARNING, "Failed API auth attempt, nickname: $nickname.");
$this->show_basic_auth_error();
}
}
diff --git a/actions/attachment.php b/actions/attachment.php
index b9187ff08..16ee723d9 100644
--- a/actions/attachment.php
+++ b/actions/attachment.php
@@ -31,8 +31,6 @@ if (!defined('LACONICA')) {
exit(1);
}
-//require_once INSTALLDIR.'/lib/personalgroupnav.php';
-//require_once INSTALLDIR.'/lib/feedlist.php';
require_once INSTALLDIR.'/lib/attachmentlist.php';
/**
@@ -67,11 +65,11 @@ class AttachmentAction extends Action
{
parent::prepare($args);
- $id = $this->arg('attachment');
-
- $this->attachment = File::staticGet($id);
+ if ($id = $this->trimmed('attachment')) {
+ $this->attachment = File::staticGet($id);
+ }
- if (!$this->attachment) {
+ if (empty($this->attachment)) {
$this->clientError(_('No such attachment.'), 404);
return false;
}
@@ -178,10 +176,8 @@ class AttachmentAction extends Action
function showContent()
{
- $this->elementStart('ul', array('class' => 'attachments'));
$ali = new Attachment($this->attachment, $this);
$cnt = $ali->show();
- $this->elementEnd('ul');
}
/**
diff --git a/actions/attachment_ajax.php b/actions/attachment_ajax.php
index 1620b27dd..3d83393c5 100644
--- a/actions/attachment_ajax.php
+++ b/actions/attachment_ajax.php
@@ -46,26 +46,6 @@ require_once INSTALLDIR.'/actions/attachment.php';
class Attachment_ajaxAction extends AttachmentAction
{
/**
- * Load attributes based on database arguments
- *
- * Loads all the DB stuff
- *
- * @param array $args $_REQUEST array
- *
- * @return success flag
- */
-
- function prepare($args)
- {
- parent::prepare($args);
- if (!$this->attachment) {
- $this->clientError(_('No such attachment.'), 404);
- return false;
- }
- return true;
- }
-
- /**
* Show page, a template method.
*
* @return nothing
@@ -95,8 +75,6 @@ class Attachment_ajaxAction extends AttachmentAction
$this->elementEnd('div');
}
-
-
/**
* Last-modified date for page
*
diff --git a/actions/attachments_ajax.php b/actions/attachment_thumbnail.php
index 402d8b5e7..b4070e747 100644
--- a/actions/attachments_ajax.php
+++ b/actions/attachment_thumbnail.php
@@ -31,9 +31,7 @@ if (!defined('LACONICA')) {
exit(1);
}
-//require_once INSTALLDIR.'/lib/personalgroupnav.php';
-//require_once INSTALLDIR.'/lib/feedlist.php';
-require_once INSTALLDIR.'/actions/attachments.php';
+require_once INSTALLDIR.'/actions/attachment.php';
/**
* Show notice attachments
@@ -45,39 +43,8 @@ require_once INSTALLDIR.'/actions/attachments.php';
* @link http://laconi.ca/
*/
-class Attachments_ajaxAction extends AttachmentsAction
+class Attachment_thumbnailAction extends AttachmentAction
{
- function showContent()
- {
- }
-
- /**
- * Fill the content area of the page
- *
- * Shows a single notice list item.
- *
- * @return void
- */
-
- function showContentBlock()
- {
- $al = new AttachmentList($this->notice, $this);
- $cnt = $al->show();
- }
-
- /**
- * Extra <head> content
- *
- * We show the microid(s) for the author, if any.
- *
- * @return void
- */
-
- function extraHead()
- {
- }
-
-
/**
* Show page, a template method.
*
@@ -100,16 +67,52 @@ class Attachments_ajaxAction extends AttachmentsAction
*/
function showCore()
{
- $this->elementStart('div', array('id' => 'core'));
- if (Event::handle('StartShowContentBlock', array($this))) {
- $this->showContentBlock();
- Event::handle('EndShowContentBlock', array($this));
+ $file_thumbnail = File_thumbnail::staticGet('file_id', $this->attachment->id);
+ if (empty($file_thumbnail->url)) {
+ return;
}
- $this->elementEnd('div');
+ $this->element('img', array('src' => $file_thumbnail->url, 'alt' => 'Thumbnail'));
}
+ /**
+ * Last-modified date for page
+ *
+ * When was the content of this page last modified? Based on notice,
+ * profile, avatar.
+ *
+ * @return int last-modified date as unix timestamp
+ */
+/*
+ function lastModified()
+ {
+ return max(strtotime($this->notice->created),
+ strtotime($this->profile->modified),
+ ($this->avatar) ? strtotime($this->avatar->modified) : 0);
+ }
+*/
-
-
+ /**
+ * An entity tag for this page
+ *
+ * Shows the ETag for the page, based on the notice ID and timestamps
+ * for the notice, profile, and avatar. It's weak, since we change
+ * the date text "one hour ago", etc.
+ *
+ * @return string etag
+ */
+/*
+ function etag()
+ {
+ $avtime = ($this->avatar) ?
+ strtotime($this->avatar->modified) : 0;
+
+ return 'W/"' . implode(':', array($this->arg('action'),
+ common_language(),
+ $this->notice->id,
+ strtotime($this->notice->created),
+ strtotime($this->profile->modified),
+ $avtime)) . '"';
+ }
+*/
}
diff --git a/actions/attachments.php b/actions/attachments.php
deleted file mode 100644
index 6b31c839d..000000000
--- a/actions/attachments.php
+++ /dev/null
@@ -1,292 +0,0 @@
-<?php
-/**
- * Laconica, the distributed open-source microblogging tool
- *
- * Show notice attachments
- *
- * 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 Personal
- * @package Laconica
- * @author Evan Prodromou <evan@controlyourself.ca>
- * @copyright 2008-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/personalgroupnav.php';
-//require_once INSTALLDIR.'/lib/feedlist.php';
-require_once INSTALLDIR.'/lib/attachmentlist.php';
-
-/**
- * Show notice attachments
- *
- * @category Personal
- * @package Laconica
- * @author Evan Prodromou <evan@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/
- */
-
-class AttachmentsAction extends Action
-{
- /**
- * Notice object to show
- */
-
- var $notice = null;
-
- /**
- * Profile of the notice object
- */
-
- var $profile = null;
-
- /**
- * Avatar of the profile of the notice object
- */
-
- var $avatar = null;
-
- /**
- * Is this action read-only?
- *
- * @return boolean true
- */
-
- function isReadOnly($args)
- {
- return true;
- }
-
- /**
- * Last-modified date for page
- *
- * When was the content of this page last modified? Based on notice,
- * profile, avatar.
- *
- * @return int last-modified date as unix timestamp
- */
-
- function lastModified()
- {
- return max(strtotime($this->notice->created),
- strtotime($this->profile->modified),
- ($this->avatar) ? strtotime($this->avatar->modified) : 0);
- }
-
- /**
- * An entity tag for this page
- *
- * Shows the ETag for the page, based on the notice ID and timestamps
- * for the notice, profile, and avatar. It's weak, since we change
- * the date text "one hour ago", etc.
- *
- * @return string etag
- */
-
- function etag()
- {
- $avtime = ($this->avatar) ?
- strtotime($this->avatar->modified) : 0;
-
- return 'W/"' . implode(':', array($this->arg('action'),
- common_language(),
- $this->notice->id,
- strtotime($this->notice->created),
- strtotime($this->profile->modified),
- $avtime)) . '"';
- }
-
- /**
- * Title of the page
- *
- * @return string title of the page
- */
-
- function title()
- {
- return sprintf(_('%1$s\'s status on %2$s'),
- $this->profile->nickname,
- common_exact_date($this->notice->created));
- }
-
-
- /**
- * Load attributes based on database arguments
- *
- * Loads all the DB stuff
- *
- * @param array $args $_REQUEST array
- *
- * @return success flag
- */
-
- function prepare($args)
- {
- parent::prepare($args);
-
- $id = $this->arg('notice');
-
- $this->notice = Notice::staticGet($id);
-
- if (!$this->notice) {
- $this->clientError(_('No such notice.'), 404);
- return false;
- }
-
-
-/*
-// STOP if there are no attachments
-// maybe even redirect if there's a single one
-// RYM FIXME TODO
- $this->clientError(_('No such attachment.'), 404);
- return false;
-
-*/
-
-
-
-
- $this->profile = $this->notice->getProfile();
-
- if (!$this->profile) {
- $this->serverError(_('Notice has no profile'), 500);
- return false;
- }
-
- $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
- return true;
- }
-
-
-
- /**
- * Handle input
- *
- * Only handles get, so just show the page.
- *
- * @param array $args $_REQUEST data (unused)
- *
- * @return void
- */
-
- function handle($args)
- {
- parent::handle($args);
-
- if ($this->notice->is_local == 0) {
- if (!empty($this->notice->url)) {
- common_redirect($this->notice->url, 301);
- } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
- common_redirect($this->notice->uri, 301);
- }
- } else {
- $f2p = new File_to_post;
- $f2p->post_id = $this->notice->id;
- $file = new File;
- $file->joinAdd($f2p);
- $file->selectAdd();
- $file->selectAdd('file.id as id');
- $count = $file->find(true);
- if (!$count) return;
- if (1 === $count) {
- common_redirect(common_local_url('attachment', array('attachment' => $file->id)), 301);
- } else {
- $this->showPage();
- }
- }
- }
-
- /**
- * Don't show local navigation
- *
- * @return void
- */
-
- function showLocalNavBlock()
- {
- }
-
- /**
- * Fill the content area of the page
- *
- * Shows a single notice list item.
- *
- * @return void
- */
-
- function showContent()
- {
- $al = new AttachmentList($this->notice, $this);
- $cnt = $al->show();
- }
-
- /**
- * Don't show page notice
- *
- * @return void
- */
-
- function showPageNoticeBlock()
- {
- }
-
- /**
- * Don't show aside
- *
- * @return void
- */
-
- function showAside() {
- }
-
- /**
- * Extra <head> content
- *
- * We show the microid(s) for the author, if any.
- *
- * @return void
- */
-
- function extraHead()
- {
- $user = User::staticGet($this->profile->id);
-
- if (!$user) {
- return;
- }
-
- if ($user->emailmicroid && $user->email && $this->notice->uri) {
- $id = new Microid('mailto:'. $user->email,
- $this->notice->uri);
- $this->element('meta', array('name' => 'microid',
- 'content' => $id->toString()));
- }
-
- if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
- $id = new Microid('xmpp:', $user->jabber,
- $this->notice->uri);
- $this->element('meta', array('name' => 'microid',
- 'content' => $id->toString()));
- }
- }
-}
-
diff --git a/actions/conversation.php b/actions/conversation.php
index 05cfb76e3..0d7cb9a87 100644
--- a/actions/conversation.php
+++ b/actions/conversation.php
@@ -11,7 +11,7 @@
* @link http://laconi.ca/
*
* Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, Controlez-Vous, Inc.
+ * Copyright (C) 2009, Control Yourself, Inc.
*
* 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
@@ -31,7 +31,7 @@ if (!defined('LACONICA')) {
exit(1);
}
-require_once(INSTALLDIR.'/lib/noticelist.php');
+require_once INSTALLDIR.'/lib/noticelist.php';
/**
* Conversation tree in the browser
@@ -42,9 +42,10 @@ require_once(INSTALLDIR.'/lib/noticelist.php');
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://laconi.ca/
*/
+
class ConversationAction extends Action
{
- var $id = null;
+ var $id = null;
var $page = null;
/**
@@ -69,24 +70,47 @@ class ConversationAction extends Action
return true;
}
+ /**
+ * Handle the action
+ *
+ * @param array $args Web and URL arguments
+ *
+ * @return void
+ */
+
function handle($args)
{
parent::handle($args);
$this->showPage();
}
+ /**
+ * Returns the page title
+ *
+ * @return string page title
+ */
+
function title()
{
return _("Conversation");
}
+ /**
+ * Show content.
+ *
+ * Display a hierarchical unordered list in the content area.
+ * Uses ConversationTree to do most of the heavy lifting.
+ *
+ * @return void
+ */
+
function showContent()
{
// FIXME this needs to be a tree, not a list
$qry = 'SELECT * FROM notice WHERE conversation = %s ';
- $offset = ($this->page-1)*NOTICES_PER_PAGE;
+ $offset = ($this->page-1) * NOTICES_PER_PAGE;
$limit = NOTICES_PER_PAGE + 1;
$txt = sprintf($qry, $this->id);
@@ -95,9 +119,9 @@ class ConversationAction extends Action
'notice:conversation:'.$this->id,
$offset, $limit);
- $nl = new NoticeList($notices, $this);
+ $ct = new ConversationTree($notices, $this);
- $cnt = $nl->show();
+ $cnt = $ct->show();
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
$this->page, 'conversation', array('id' => $this->id));
@@ -105,3 +129,170 @@ class ConversationAction extends Action
}
+/**
+ * Conversation tree
+ *
+ * The widget class for displaying a hierarchical list of notices.
+ *
+ * @category Widget
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link http://laconi.ca/
+ */
+
+class ConversationTree extends NoticeList
+{
+ var $tree = null;
+ var $table = null;
+
+ /**
+ * Show the tree of notices
+ *
+ * @return void
+ */
+
+ function show()
+ {
+ $cnt = 0;
+
+ $this->tree = array();
+ $this->table = array();
+
+ while ($this->notice->fetch()) {
+
+ $cnt++;
+
+ $id = $this->notice->id;
+ $notice = clone($this->notice);
+
+ $this->table[$id] = $notice;
+
+ if (is_null($notice->reply_to)) {
+ $this->tree['root'] = array($notice->id);
+ } else if (array_key_exists($notice->reply_to, $this->tree)) {
+ $this->tree[$notice->reply_to][] = $notice->id;
+ } else {
+ $this->tree[$notice->reply_to] = array($notice->id);
+ }
+ }
+
+ $this->out->elementStart('div', array('id' =>'notices_primary'));
+ $this->out->element('h2', null, _('Notices'));
+ $this->out->elementStart('ol', array('class' => 'notices xoxo'));
+
+ if (array_key_exists('root', $this->tree)) {
+ $rootid = $this->tree['root'][0];
+ $this->showNoticePlus($rootid);
+ }
+
+ $this->out->elementEnd('ol');
+ $this->out->elementEnd('div');
+
+ return $cnt;
+ }
+
+ /**
+ * Shows a notice plus its list of children.
+ *
+ * @param integer $id ID of the notice to show
+ *
+ * @return void
+ */
+
+ function showNoticePlus($id)
+ {
+ $notice = $this->table[$id];
+
+ // We take responsibility for doing the li
+
+ $this->out->elementStart('li', array('class' => 'hentry notice',
+ 'id' => 'notice-' . $this->notice->id));
+
+ $item = $this->newListItem($notice);
+ $item->show();
+
+ if (array_key_exists($id, $this->tree)) {
+ $children = $this->tree[$id];
+
+ $this->out->elementStart('ol', array('class' => 'notices'));
+
+ foreach ($children as $child) {
+ $this->showNoticePlus($child);
+ }
+
+ $this->out->elementEnd('ol');
+ }
+
+ $this->out->elementEnd('li');
+ }
+
+ /**
+ * Override parent class to return our preferred item.
+ *
+ * @param Notice $notice Notice to display
+ *
+ * @return NoticeListItem a list item to show
+ */
+
+ function newListItem($notice)
+ {
+ return new ConversationTreeItem($notice, $this->out);
+ }
+}
+
+/**
+ * Conversation tree list item
+ *
+ * Special class of NoticeListItem for use inside conversation trees.
+ *
+ * @category Widget
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link http://laconi.ca/
+ */
+
+class ConversationTreeItem extends NoticeListItem
+{
+ /**
+ * start a single notice.
+ *
+ * The default creates the <li>; we skip, since the ConversationTree
+ * takes care of that.
+ *
+ * @return void
+ */
+
+ function showStart()
+ {
+ return;
+ }
+
+ /**
+ * finish the notice
+ *
+ * The default closes the <li>; we skip, since the ConversationTree
+ * takes care of that.
+ *
+ * @return void
+ */
+
+ function showEnd()
+ {
+ return;
+ }
+
+ /**
+ * show link to notice conversation page
+ *
+ * Since we're only used on the conversation page, we skip this
+ *
+ * @return void
+ */
+
+ function showContext()
+ {
+ return;
+ }
+}
diff --git a/actions/deletenotice.php b/actions/deletenotice.php
index 6c350b33a..e733f9650 100644
--- a/actions/deletenotice.php
+++ b/actions/deletenotice.php
@@ -112,8 +112,8 @@ class DeletenoticeAction extends DeleteAction
$this->hidden('token', common_session_token());
$this->hidden('notice', $this->trimmed('notice'));
$this->element('p', null, _('Are you sure you want to delete this notice?'));
- $this->submit('form_action-yes', _('Yes'), 'submit form_action-primary', 'yes');
- $this->submit('form_action-no', _('No'), 'submit form_action-secondary', 'no');
+ $this->submit('form_action-no', _('No'), 'submit form_action-primary', 'no', _("Do not delete this notice"));
+ $this->submit('form_action-yes', _('Yes'), 'submit form_action-secondary', 'yes', _('Delete this notice'));
$this->elementEnd('fieldset');
$this->elementEnd('form');
}
diff --git a/actions/designsettings.php b/actions/designsettings.php
index a85b36a25..5774b8537 100644
--- a/actions/designsettings.php
+++ b/actions/designsettings.php
@@ -70,7 +70,7 @@ class DesignsettingsAction extends AccountSettingsAction
function showContent()
{
$user = common_current_user();
- $this->elementStart('form', array('method' => 'POST',
+ $this->elementStart('form', array('method' => 'post',
'id' => 'form_settings_design',
'class' => 'form_settings',
'action' =>
@@ -82,7 +82,7 @@ class DesignsettingsAction extends AccountSettingsAction
$this->element('legend', null, _('Change background image'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
- $this->element('label', array('for' => 'design_ background-image_file'),
+ $this->element('label', array('for' => 'design_background-image_file'),
_('Upload file'));
$this->element('input', array('name' => 'design_background-image_file',
'type' => 'file',
@@ -140,10 +140,12 @@ class DesignsettingsAction extends AccountSettingsAction
$this->elementEnd('ul');
$this->elementEnd('fieldset');
- $this->submit('save', _('Save'));
- $this->element('input', array('type' => 'reset',
+ $this->element('input', array('id' => 'settings_design_reset',
+ 'type' => 'reset',
'value' => 'Reset',
- 'class' => 'form_action-secondary'));
+ 'class' => 'submit form_action-primary',
+ 'title' => _('Reset back to default')));
+ $this->submit('save', _('Save'), 'submit form_action-secondary', 'save', _('Save design'));
/*TODO: Check submitted form values:
json_encode(form values)
diff --git a/actions/facebookhome.php b/actions/facebookhome.php
index 5946e6c98..00b35ef68 100644
--- a/actions/facebookhome.php
+++ b/actions/facebookhome.php
@@ -115,7 +115,7 @@ class FacebookhomeAction extends FacebookAction
$flink->foreign_id = $this->fbuid;
$flink->service = FACEBOOK_SERVICE;
$flink->created = common_sql_now();
- $flink->set_flags(true, false, false);
+ $flink->set_flags(true, false, false, false);
$flink_id = $flink->insert();
@@ -138,9 +138,6 @@ class FacebookhomeAction extends FacebookAction
function setDefaults()
{
- // A default prefix string for notices
- $this->facebook->api_client->data_setUserPreference(
- FACEBOOK_NOTICE_PREFIX, 'dented: ');
$this->facebook->api_client->data_setUserPreference(
FACEBOOK_PROMPTED_UPDATE_PREF, 'false');
}
diff --git a/actions/facebookinvite.php b/actions/facebookinvite.php
index 1302064ad..2207580f7 100644
--- a/actions/facebookinvite.php
+++ b/actions/facebookinvite.php
@@ -17,7 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('LACONICA')) {
+ exit(1);
+}
require_once(INSTALLDIR.'/lib/facebookaction.php');
@@ -67,7 +69,7 @@ class FacebookinviteAction extends FacebookAction
function showSuccessContent()
{
- $this->element('h2', null, sprintf(_('Thanks for inviting your friends to use %s'),
+ $this->element('h2', null, sprintf(_('Thanks for inviting your friends to use %s'),
common_config('site', 'name')));
$this->element('p', null, _('Invitations have been sent to the following users:'));
@@ -89,16 +91,6 @@ class FacebookinviteAction extends FacebookAction
function showFormContent()
{
-
- // Get a list of users who are already using the app for exclusion
- $exclude_ids = $this->facebook->api_client->friends_getAppUsers();
- $exclude_ids_csv = null;
-
- // fbml needs these as a csv string, not an array
- if ($exclude_ids) {
- $exclude_ids_csv = implode(',', $exclude_ids);
- }
-
$content = sprintf(_('You have been invited to %s'), common_config('site', 'name')) .
htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>');
@@ -109,36 +101,43 @@ class FacebookinviteAction extends FacebookAction
'content' => $content));
$this->hidden('invite', 'true');
$actiontext = sprintf(_('Invite your friends to use %s'), common_config('site', 'name'));
-
- $multi_params = array('showborder' => 'false');
+
+ $multi_params = array('showborder' => 'false');
$multi_params['actiontext'] = $actiontext;
-
- if ($exclude_ids_csv) {
+ $multi_params['bypass'] = 'cancel';
+
+ // Get a list of users who are already using the app for exclusion
+ $exclude_ids = $this->facebook->api_client->friends_getAppUsers();
+ $exclude_ids_csv = null;
+
+ // fbml needs these as a csv string, not an array
+ if ($exclude_ids) {
+ $exclude_ids_csv = implode(',', $exclude_ids);
$multi_params['exclude_ids'] = $exclude_ids_csv;
}
- $multi_params['bypass'] = 'cancel';
-
$this->element('fb:multi-friend-selector', $multi_params);
-
$this->elementEnd('fb:request-form');
- $this->element('h2', null, sprintf(_('Friends already using %s:'),
- common_config('site', 'name')));
- $this->elementStart('ul', array('id' => 'facebook-friends'));
-
- foreach ($exclude_ids as $friend) {
- $this->elementStart('li');
- $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
- $this->element('fb:name', array('uid' => $friend,
- 'capitalize' => 'true'));
- $this->elementEnd('li');
- }
+ if ($exclude_ids) {
- $this->elementEnd("ul");
+ $this->element('h2', null, sprintf(_('Friends already using %s:'),
+ common_config('site', 'name')));
+ $this->elementStart('ul', array('id' => 'facebook-friends'));
+
+ foreach ($exclude_ids as $friend) {
+ $this->elementStart('li');
+ $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
+ $this->element('fb:name', array('uid' => $friend,
+ 'capitalize' => 'true'));
+ $this->elementEnd('li');
+ }
+
+ $this->elementEnd("ul");
+ }
}
-
- function title()
+
+ function title()
{
return sprintf(_('Send invitations'));
}
diff --git a/actions/facebooksettings.php b/actions/facebooksettings.php
index 236460c1c..227e12316 100644
--- a/actions/facebooksettings.php
+++ b/actions/facebooksettings.php
@@ -55,7 +55,7 @@ class FacebooksettingsAction extends FacebookAction
$prefix = $this->trimmed('prefix');
$original = clone($this->flink);
- $this->flink->set_flags($noticesync, $replysync, false);
+ $this->flink->set_flags($noticesync, $replysync, false, false);
$result = $this->flink->update($original);
$this->facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX,
diff --git a/actions/file.php b/actions/file.php
new file mode 100644
index 000000000..1179dbe9a
--- /dev/null
+++ b/actions/file.php
@@ -0,0 +1,40 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ *
+ * 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/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
+
+require_once(INSTALLDIR.'/actions/shownotice.php');
+
+class FileAction extends ShowNoticeAction
+{
+ function showPage() {
+ $source_url = common_local_url('file', array('notice' => $this->notice->id));
+ $query = "select file_redirection.url as url from file join file_redirection on file.id = file_redirection.file_id where file.url = '$source_url'";
+ $file = new File_redirection;
+ $file->query($query);
+ $file->fetch();
+ if (empty($file->url)) {
+ die('nothing attached here');
+ } else {
+ header("Location: {$file->url}");
+ die();
+ }
+ }
+}
+
diff --git a/actions/newnotice.php b/actions/newnotice.php
index ae0ff9636..02976a2ae 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -84,20 +84,24 @@ class NewnoticeAction extends Action
function handle($args)
{
- parent::handle($args);
-
if (!common_logged_in()) {
$this->clientError(_('Not logged in.'));
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ // check for this before token since all POST and FILES data
+ // is losts when size is exceeded
+ if (empty($_POST) && $_SERVER['CONTENT_LENGTH']) {
+ $this->clientError(sprintf(_('The server was unable to handle ' .
+ 'that much POST data (%s bytes) due to its current configuration.'),
+ $_SERVER['CONTENT_LENGTH']));
+ }
+ parent::handle($args);
// CSRF protection
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->clientError(_('There was a problem with your session token. '.
'Try again, please.'));
- return;
}
-
try {
$this->saveNewNotice();
} catch (Exception $e) {
@@ -109,6 +113,30 @@ class NewnoticeAction extends Action
}
}
+ function getUploadedFileType() {
+ require_once 'MIME/Type.php';
+
+ $filetype = MIME_Type::autoDetect($_FILES['attach']['tmp_name']);
+ if (in_array($filetype, common_config('attachments', 'supported'))) {
+ return $filetype;
+ }
+ $media = MIME_Type::getMedia($filetype);
+ if ('application' !== $media) {
+ $hint = sprintf(_(' Try using another %s format.'), $media);
+ } else {
+ $hint = '';
+ }
+ $this->clientError(sprintf(
+ _('%s is not a supported filetype on this server.'), $filetype) . $hint);
+ }
+
+ function isRespectsQuota($user) {
+ $file = new File;
+ $ret = $file->isRespectsQuota($user);
+ if (true === $ret) return true;
+ $this->clientError($ret);
+ }
+
/**
* Save a new notice, based on arguments
*
@@ -131,7 +159,6 @@ class NewnoticeAction extends Action
$this->clientError(_('No content!'));
} else {
$content_shortened = common_shorten_links($content);
-
if (mb_strlen($content_shortened) > 140) {
$this->clientError(_('That\'s too long. '.
'Max notice size is 140 chars.'));
@@ -158,17 +185,53 @@ class NewnoticeAction extends Action
$replyto = 'false';
}
-// $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
+ if (isset($_FILES['attach']['error'])) {
+ switch ($_FILES['attach']['error']) {
+ case UPLOAD_ERR_NO_FILE:
+ // no file uploaded, nothing to do
+ break;
+
+ case UPLOAD_ERR_OK:
+ $mimetype = $this->getUploadedFileType();
+ if (!$this->isRespectsQuota($user)) {
+ die('clientError() should trigger an exception before reaching here.');
+ }
+ break;
+
+ case UPLOAD_ERR_INI_SIZE:
+ $this->clientError(_('The uploaded file exceeds the upload_max_filesize directive in php.ini.'));
+
+ case UPLOAD_ERR_FORM_SIZE:
+ $this->clientError(_('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'));
+
+ case UPLOAD_ERR_PARTIAL:
+ $this->clientError(_('The uploaded file was only partially uploaded.'));
+
+ case UPLOAD_ERR_NO_TMP_DIR:
+ $this->clientError(_('Missing a temporary folder.'));
+
+ case UPLOAD_ERR_CANT_WRITE:
+ $this->clientError(_('Failed to write file to disk.'));
+
+ case UPLOAD_ERR_EXTENSION:
+ $this->clientError(_('File upload stopped by extension.'));
+
+ default:
+ die('Should never reach here.');
+ }
+ }
+
$notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
($replyto == 'false') ? null : $replyto);
if (is_string($notice)) {
$this->clientError($notice);
- return;
}
+ if (isset($mimetype)) {
+ $this->storeFile($notice, $mimetype);
+ }
$this->saveUrls($notice);
-
common_broadcast_notice($notice);
if ($this->boolean('ajax')) {
@@ -194,6 +257,33 @@ class NewnoticeAction extends Action
}
}
+ function storeFile($notice, $mimetype) {
+ $filename = basename($_FILES['attach']['name']);
+ $destination = "file/{$notice->id}-$filename";
+ if (move_uploaded_file($_FILES['attach']['tmp_name'], INSTALLDIR . "/$destination")) {
+ $file = new File;
+ $file->url = common_local_url('file', array('notice' => $notice->id));
+ $file->size = filesize(INSTALLDIR . "/$destination");
+ $file->date = time();
+ $file->mimetype = $mimetype;
+ if ($file_id = $file->insert()) {
+ $file_redir = new File_redirection;
+ $file_redir->url = common_path($destination);
+ $file_redir->file_id = $file_id;
+ $file_redir->insert();
+
+ $f2p = new File_to_post;
+ $f2p->file_id = $file_id;
+ $f2p->post_id = $notice->id;
+ $f2p->insert();
+ } else {
+ $this->clientError(_('There was a database error while saving your file. Please try again.'));
+ }
+ } else {
+ $this->clientError(_('File could not be moved to destination directory.'));
+ }
+ }
+
/** save all urls in the notice to the db
*
* follow redirects and save all available file information
@@ -203,7 +293,7 @@ class NewnoticeAction extends Action
*
* @return void
*/
- function saveUrls($notice) {
+ function saveUrls($notice, $uploaded = null) {
common_replace_urls_callback($notice->content, array($this, 'saveUrl'), $notice->id);
}
@@ -316,3 +406,4 @@ class NewnoticeAction extends Action
$nli->show();
}
}
+
diff --git a/actions/shownotice.php b/actions/shownotice.php
index 2c469c9de..34c8a8e94 100644
--- a/actions/shownotice.php
+++ b/actions/shownotice.php
@@ -208,10 +208,10 @@ class ShownoticeAction extends Action
function showContent()
{
- $this->elementStart('ul', array('class' => 'notices'));
+ $this->elementStart('ol', array('class' => 'notices xoxo'));
$nli = new NoticeListItem($this->notice, $this);
$nli->show();
- $this->elementEnd('ul');
+ $this->elementEnd('ol');
}
/**
diff --git a/actions/tag.php b/actions/tag.php
index 47420e4c3..e9351d241 100644
--- a/actions/tag.php
+++ b/actions/tag.php
@@ -49,8 +49,6 @@ class TagAction extends Action
{
$pop = new PopularNoticeSection($this);
$pop->show();
- $freqatt = new FrequentAttachmentSection($this);
- $freqatt->show();
}
function title()