diff options
Diffstat (limited to 'actions')
30 files changed, 1690 insertions, 440 deletions
diff --git a/actions/attachment.php b/actions/attachment.php new file mode 100644 index 000000000..16ee723d9 --- /dev/null +++ b/actions/attachment.php @@ -0,0 +1,205 @@ +<?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/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 AttachmentAction extends Action +{ + /** + * Attachment object to show + */ + + var $attachment = null; + + /** + * 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 ($id = $this->trimmed('attachment')) { + $this->attachment = File::staticGet($id); + } + + if (empty($this->attachment)) { + $this->clientError(_('No such attachment.'), 404); + return false; + } + return true; + } + + /** + * Is this action read-only? + * + * @return boolean true + */ + + function isReadOnly($args) + { + return true; + } + + /** + * Title of the page + * + * @return string title of the page + */ + function title() + { + $a = new Attachment($this->attachment); + return $a->title(); + } + + /** + * 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)) . '"'; + } +*/ + + + /** + * Handle input + * + * Only handles get, so just show the page. + * + * @param array $args $_REQUEST data (unused) + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + $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() + { + $ali = new Attachment($this->attachment, $this); + $cnt = $ali->show(); + } + + /** + * Don't show page notice + * + * @return void + */ + + function showPageNoticeBlock() + { + } + + /** + * Show aside: this attachments appears in what notices + * + * @return void + */ + function showSections() { + $ns = new AttachmentNoticeSection($this); + $ns->show(); + $atcs = new AttachmentTagCloudSection($this); + $atcs->show(); + } +} + diff --git a/actions/attachment_ajax.php b/actions/attachment_ajax.php new file mode 100644 index 000000000..3d83393c5 --- /dev/null +++ b/actions/attachment_ajax.php @@ -0,0 +1,119 @@ +<?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.'/actions/attachment.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 Attachment_ajaxAction extends AttachmentAction +{ + /** + * Show page, a template method. + * + * @return nothing + */ + function showPage() + { + if (Event::handle('StartShowBody', array($this))) { + $this->showCore(); + Event::handle('EndShowBody', array($this)); + } + } + + /** + * Show core. + * + * Shows local navigation, content block and aside. + * + * @return nothing + */ + function showCore() + { + $this->elementStart('div', array('id' => 'core')); + if (Event::handle('StartShowContentBlock', array($this))) { + $this->showContentBlock(); + Event::handle('EndShowContentBlock', array($this)); + } + $this->elementEnd('div'); + } + + /** + * 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/attachment_thumbnail.php b/actions/attachment_thumbnail.php new file mode 100644 index 000000000..b4070e747 --- /dev/null +++ b/actions/attachment_thumbnail.php @@ -0,0 +1,118 @@ +<?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.'/actions/attachment.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 Attachment_thumbnailAction extends AttachmentAction +{ + /** + * Show page, a template method. + * + * @return nothing + */ + function showPage() + { + if (Event::handle('StartShowBody', array($this))) { + $this->showCore(); + Event::handle('EndShowBody', array($this)); + } + } + + /** + * Show core. + * + * Shows local navigation, content block and aside. + * + * @return nothing + */ + function showCore() + { + $file_thumbnail = File_thumbnail::staticGet('file_id', $this->attachment->id); + if (empty($file_thumbnail->url)) { + return; + } + $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/conversation.php b/actions/conversation.php new file mode 100644 index 000000000..20c68986c --- /dev/null +++ b/actions/conversation.php @@ -0,0 +1,298 @@ +<?php +/** + * Display a conversation in the browser + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * + * Laconica - a distributed open-source microblogging tool + * 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 + * 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.'/lib/noticelist.php'; + +/** + * Conversation tree in the browser + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ + +class ConversationAction extends Action +{ + var $id = null; + var $page = null; + + /** + * Initialization. + * + * @param array $args Web and URL arguments + * + * @return boolean false if id not passed in + */ + + function prepare($args) + { + parent::prepare($args); + $this->id = $this->trimmed('id'); + if (empty($this->id)) { + return false; + } + $this->page = $this->trimmed('page'); + if (empty($this->page)) { + $this->page = 1; + } + 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; + $limit = NOTICES_PER_PAGE + 1; + + $txt = sprintf($qry, $this->id); + + $notices = Notice::getStream($txt, + 'notice:conversation:'.$this->id, + $offset, $limit); + + $ct = new ConversationTree($notices, $this); + + $cnt = $ct->show(); + + $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'conversation', array('id' => $this->id)); + } + +} + +/** + * 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-' . $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 new file mode 100644 index 000000000..5774b8537 --- /dev/null +++ b/actions/designsettings.php @@ -0,0 +1,264 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Change user password + * + * 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 Settings + * @package Laconica + * @author Sarven Capadisli <csarven@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/accountsettingsaction.php'; + + + +class DesignsettingsAction extends AccountSettingsAction +{ + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + return _('Profile design'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('Customize the way your profile looks with a background image and a colour palette of your choice.'); + } + + /** + * Content area of the page + * + * Shows a form for changing the password + * + * @return void + */ + + function showContent() + { + $user = common_current_user(); + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_settings_design', + 'class' => 'form_settings', + 'action' => + common_local_url('designsettings'))); + $this->elementStart('fieldset'); + $this->hidden('token', common_session_token()); + + $this->elementStart('fieldset', array('id' => 'settings_design_background-image')); + $this->element('legend', null, _('Change background image')); + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->element('label', array('for' => 'design_background-image_file'), + _('Upload file')); + $this->element('input', array('name' => 'design_background-image_file', + 'type' => 'file', + 'id' => 'design_background-image_file')); + $this->element('p', 'form_guide', _('You can upload your personal background image. The maximum file size is 2Mb.')); + $this->element('input', array('name' => 'MAX_FILE_SIZE', + 'type' => 'hidden', + 'id' => 'MAX_FILE_SIZE', + 'value' => ImageFile::maxFileSizeInt())); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->elementEnd('fieldset'); + + $this->elementStart('fieldset', array('id' => 'settings_design_color')); + $this->element('legend', null, _('Change colours')); + $this->elementStart('ul', 'form_data'); + + //This is a JSON object in the DB field. Here for testing. Remove later. + $userSwatch = '{"body":{"background-color":"#F0F2F5"}, + "#content":{"background-color":"#FFFFFF"}, + "#aside_primary":{"background-color":"#CEE1E9"}, + "html body":{"color":"#000000"}, + "a":{"color":"#002E6E"}}'; + + //Default theme swatch -- Where should this be stored? + $defaultSwatch = array('body' => array('background-color' => '#F0F2F5'), + '#content' => array('background-color' => '#FFFFFF'), + '#aside_primary' => array('background-color' => '#CEE1E9'), + 'html body' => array('color' => '#000000'), + 'a' => array('color' => '#002E6E')); + + $userSwatch = ($userSwatch) ? json_decode($userSwatch, true) : $defaultSwatch; + + $s = 0; + $labelSwatch = array('Background', + 'Content', + 'Sidebar', + 'Text', + 'Links'); + foreach($userSwatch as $propertyvalue => $value) { + $foo = array_values($value); + $this->elementStart('li'); + $this->element('label', array('for' => 'swatch-'.$s), _($labelSwatch[$s])); + $this->element('input', array('name' => 'swatch-'.$s, //prefer swatch[$s] ? + 'type' => 'text', + 'id' => 'swatch-'.$s, + 'class' => 'swatch', + 'maxlength' => '7', + 'size' => '7', + 'value' => $foo[0])); + $this->elementEnd('li'); + $s++; + } + + $this->elementEnd('ul'); + $this->elementEnd('fieldset'); + + $this->element('input', array('id' => 'settings_design_reset', + 'type' => 'reset', + 'value' => 'Reset', + '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) +if submitted Swatch == DefaultSwatch, don't store in DB. +else store in BD +*/ + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + + } + + /** + * Handle a post + * + * Validate input and save changes. Reload the form with a success + * or error message. + * + * @return void + */ + + function handlePost() + { + /* + // CSRF protection + + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + + $user = common_current_user(); + assert(!is_null($user)); // should already be checked + + // FIXME: scrub input + + $newpassword = $this->arg('newpassword'); + $confirm = $this->arg('confirm'); + + # Some validation + + if (strlen($newpassword) < 6) { + $this->showForm(_('Password must be 6 or more characters.')); + return; + } else if (0 != strcmp($newpassword, $confirm)) { + $this->showForm(_('Passwords don\'t match.')); + return; + } + + if ($user->password) { + $oldpassword = $this->arg('oldpassword'); + + if (!common_check_user($user->nickname, $oldpassword)) { + $this->showForm(_('Incorrect old password')); + return; + } + } + + $original = clone($user); + + $user->password = common_munge_password($newpassword, $user->id); + + $val = $user->validate(); + if ($val !== true) { + $this->showForm(_('Error saving user; invalid.')); + return; + } + + if (!$user->update($original)) { + $this->serverError(_('Can\'t save new password.')); + return; + } + + $this->showForm(_('Password saved.'), true); + */ + } + + + /** + * Add the Farbtastic stylesheet + * + * @return void + */ + + function showStylesheets() + { + parent::showStylesheets(); + $farbtasticStyle = + common_path('theme/base/css/farbtastic.css?version='.LACONICA_VERSION); + + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => $farbtasticStyle, + 'media' => 'screen, projection, tv')); + } + + /** + * Add the Farbtastic scripts + * + * @return void + */ + + function showScripts() + { + parent::showScripts(); + + $farbtasticPack = common_path('js/farbtastic/farbtastic.js'); + $farbtasticGo = common_path('js/farbtastic/farbtastic.go.js'); + + $this->element('script', array('type' => 'text/javascript', + 'src' => $farbtasticPack)); + $this->element('script', array('type' => 'text/javascript', + 'src' => $farbtasticGo)); + } +} diff --git a/actions/facebookhome.php b/actions/facebookhome.php index 4c2b26355..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(); 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/foaf.php b/actions/foaf.php index 2d5b78d12..fb0172eb9 100644 --- a/actions/foaf.php +++ b/actions/foaf.php @@ -82,14 +82,18 @@ class FoafAction extends Action 'http://www.w3.org/2000/01/rdf-schema#', 'xmlns:geo' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', + 'xmlns:bio' => + 'http://purl.org/vocab/bio/0.1/', + 'xmlns:sioc' => + 'http://rdfs.org/sioc/ns#', 'xmlns' => 'http://xmlns.com/foaf/0.1/')); // This is the document about the user $this->showPpd('', $this->user->uri); - // XXX: might not be a person - $this->elementStart('Person', array('rdf:about' => + // Would be nice to tell if they were a Person or not (e.g. a #person usertag?) + $this->elementStart('Agent', array('rdf:about' => $this->user->uri)); $this->element('mbox_sha1sum', null, sha1('mailto:' . $this->user->email)); if ($this->profile->fullname) { @@ -98,8 +102,11 @@ class FoafAction extends Action if ($this->profile->homepage) { $this->element('homepage', array('rdf:resource' => $this->profile->homepage)); } + if ($this->profile->profileurl) { + $this->element('weblog', array('rdf:resource' => $this->profile->profileurl)); + } if ($this->profile->bio) { - $this->element('rdfs:comment', null, $this->profile->bio); + $this->element('bio:olb', null, $this->profile->bio); } // XXX: more structured location data if ($this->profile->location) { @@ -110,10 +117,7 @@ class FoafAction extends Action $this->elementEnd('based_near'); } - $this->showMicrobloggingAccount($this->profile, common_root_url()); - $avatar = $this->profile->getOriginalAvatar(); - if ($avatar) { $this->elementStart('img'); $this->elementStart('Image', array('rdf:about' => $avatar->url)); @@ -129,39 +133,8 @@ class FoafAction extends Action $this->elementEnd('img'); } - // Get people user is subscribed to - - $person = array(); - - $sub = new Subscription(); - $sub->subscriber = $this->profile->id; - $sub->whereAdd('subscriber != subscribed'); - - if ($sub->find()) { - while ($sub->fetch()) { - if (!empty($sub->token)) { - $other = Remote_profile::staticGet('id', $sub->subscribed); - } else { - $other = User::staticGet('id', $sub->subscribed); - } - if (empty($other)) { - common_debug('Got a bad subscription: '.print_r($sub,true)); - continue; - } - $this->element('knows', array('rdf:resource' => $other->uri)); - $person[$other->uri] = array(LISTENEE, - $other->id, - $other->nickname, - (empty($sub->token)) ? 'User' : 'Remote_profile'); - $other->free(); - $other = null; - unset($other); - } - } - - $sub->free(); - $sub = null; - unset($sub); + $person = $this->showMicrobloggingAccount($this->profile, + common_root_url(), $this->user->uri, false); // Get people who subscribe to user @@ -198,7 +171,15 @@ class FoafAction extends Action $sub = null; unset($sub); - $this->elementEnd('Person'); + foreach ($person as $uri => $p) { + list($type, $id, $nickname, $cls) = $p; + if ($type == BOTH) { + $this->element('knows', array('rdf:resource' => $uri)); + } + } + + $this->elementEnd('Agent'); + foreach ($person as $uri => $p) { $foaf_url = null; @@ -207,16 +188,18 @@ class FoafAction extends Action $foaf_url = common_local_url('foaf', array('nickname' => $nickname)); } $profile = Profile::staticGet($id); - $this->elementStart('Person', array('rdf:about' => $uri)); - if ($type == LISTENER || $type == BOTH) { + $this->elementStart('Agent', array('rdf:about' => $uri)); + if ($type == BOTH) { $this->element('knows', array('rdf:resource' => $this->user->uri)); } - $this->showMicrobloggingAccount($profile, ($cls == 'User') ? - common_root_url() : null); + $this->showMicrobloggingAccount($profile, + ($cls == 'User') ? common_root_url() : null, + $uri, + true); if ($foaf_url) { $this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url)); } - $this->elementEnd('Person'); + $this->elementEnd('Agent'); if ($foaf_url) { $this->showPpd($foaf_url, $uri); } @@ -237,18 +220,66 @@ class FoafAction extends Action $this->elementEnd('PersonalProfileDocument'); } - function showMicrobloggingAccount($profile, $service=null) + function showMicrobloggingAccount($profile, $service=null, $useruri=null, $isSubscriber=false) { + $attr = array(); + if ($useruri) { + $attr['rdf:about'] = $useruri . '#acct'; + } + // Their account $this->elementStart('holdsAccount'); - $this->elementStart('OnlineAccount'); + $this->elementStart('OnlineAccount', $attr); if ($service) { $this->element('accountServiceHomepage', array('rdf:resource' => $service)); } $this->element('accountName', null, $profile->nickname); - $this->element('homepage', array('rdf:resource' => $profile->profileurl)); + $this->element('accountProfilePage', array('rdf:resource' => $profile->profileurl)); + if ($useruri) { + $this->element('sioc:account_of', array('rdf:resource'=>$useruri)); + } + + $person = array(); + + if ($isSubscriber) { + $this->element('sioc:follows', array('rdf:resource'=>$this->user->uri . '#acct')); + } else { + // Get people user is subscribed to + $sub = new Subscription(); + $sub->subscriber = $profile->id; + $sub->whereAdd('subscriber != subscribed'); + + if ($sub->find()) { + while ($sub->fetch()) { + if (!empty($sub->token)) { + $other = Remote_profile::staticGet('id', $sub->subscribed); + } else { + $other = User::staticGet('id', $sub->subscribed); + } + if (empty($other)) { + common_debug('Got a bad subscription: '.print_r($sub,true)); + continue; + } + $this->element('sioc:follows', array('rdf:resource' => $other->uri.'#acct')); + $person[$other->uri] = array(LISTENEE, + $other->id, + $other->nickname, + (empty($sub->token)) ? 'User' : 'Remote_profile'); + $other->free(); + $other = null; + unset($other); + } + } + + $sub->free(); + $sub = null; + unset($sub); + } + $this->elementEnd('OnlineAccount'); $this->elementEnd('holdsAccount'); + + return $person; } } diff --git a/actions/groupmembers.php b/actions/groupmembers.php index 21e5ebbaa..53fee3129 100644 --- a/actions/groupmembers.php +++ b/actions/groupmembers.php @@ -127,7 +127,7 @@ class GroupmembersAction extends Action $members = $this->group->getMembers($offset, $limit); if ($members) { - $member_list = new ProfileList($members, null, $this); + $member_list = new GroupMemberList($members, $this->group, $this); $cnt = $member_list->show(); } @@ -138,3 +138,15 @@ class GroupmembersAction extends Action array('nickname' => $this->group->nickname)); } } + +class GroupMemberList extends ProfileList { + + var $group = null; + + function __construct($profile, $group=null, $action=null) + { + parent::__construct($profile, $action); + + $this->group = $group; + } +} diff --git a/actions/logout.php b/actions/logout.php index 9f3bfe247..c34b10987 100644 --- a/actions/logout.php +++ b/actions/logout.php @@ -70,10 +70,20 @@ class LogoutAction extends Action if (!common_logged_in()) { $this->clientError(_('Not logged in.')); } else { - common_set_user(null); - common_real_login(false); // not logged in - common_forgetme(); // don't log back in! + if (Event::handle('StartLogout', array($this))) { + $this->logout(); + } + Event::handle('EndLogout', array($this)); + common_redirect(common_local_url('public'), 303); } } + + function logout() + { + common_set_user(null); + common_real_login(false); // not logged in + common_forgetme(); // don't log back in! + } + } diff --git a/actions/newnotice.php b/actions/newnotice.php index cbd04c58b..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,14 +185,53 @@ class NewnoticeAction extends Action $replyto = 'false'; } - $notice = Notice::saveNew($user->id, $content, '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')) { @@ -191,6 +257,51 @@ 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 + * (mimetype, date, size, oembed, etc.) + * + * @param class $notice Notice to pull URLs from + * + * @return void + */ + function saveUrls($notice, $uploaded = null) { + common_replace_urls_callback($notice->content, array($this, 'saveUrl'), $notice->id); + } + + function saveUrl($data) { + list($url, $notice_id) = $data; + $zzz = File::processNew($url, $notice_id); + } + /** * Show an Ajax-y error message * @@ -295,3 +406,4 @@ class NewnoticeAction extends Action $nli->show(); } } + diff --git a/actions/register.php b/actions/register.php index 033cf557f..dcbbbdb6a 100644 --- a/actions/register.php +++ b/actions/register.php @@ -382,6 +382,19 @@ class RegisterAction extends Action function showFormContent() { + $code = $this->trimmed('code'); + + $invite = null; + + if ($code) { + $invite = Invitation::staticGet($code); + } + + if (common_config('site', 'inviteonly') && !($code && $invite)) { + $this->clientError(_('Sorry, only invited people can register.')); + return; + } + $this->elementStart('form', array('method' => 'post', 'id' => 'form_register', 'class' => 'form_settings', diff --git a/actions/showgroup.php b/actions/showgroup.php index 29b6fa1e6..3ce45adc6 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -344,7 +344,7 @@ class ShowgroupAction extends Action $this->element('h2', null, _('Members')); - $pml = new ProfileMiniList($member, null, $this); + $pml = new ProfileMiniList($member, $this); $cnt = $pml->show(); if ($cnt == 0) { $this->element('p', null, _('(None)')); diff --git a/actions/shownotice.php b/actions/shownotice.php index 1be1e2414..b0d973a99 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/showstream.php b/actions/showstream.php index 641228bc7..72316b259 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -68,6 +68,9 @@ class ShowstreamAction extends ProfileAction } else { $base = $this->user->nickname; } + if (!empty($this->tag)) { + $base .= sprintf(_(' tagged %s'), $this->tag); + } if ($this->page == 1) { return $base; @@ -110,6 +113,15 @@ class ShowstreamAction extends ProfileAction function getFeeds() { + if (!empty($this->tag)) { + return array(new Feed(Feed::RSS1, + common_local_url('userrss', + array('nickname' => $this->user->nickname, + 'tag' => $this->tag)), + sprintf(_('Notice feed for %s tagged %s (RSS 1.0)'), + $this->user->nickname, $this->tag))); + } + return array(new Feed(Feed::RSS1, common_local_url('userrss', array('nickname' => $this->user->nickname)), @@ -356,7 +368,9 @@ class ShowstreamAction extends ProfileAction function showNotices() { - $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + $notice = empty($this->tag) + ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1) + : $this->user->getTaggedNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null, $this->tag); $pnl = new ProfileNoticeList($notice, $this); $cnt = $pnl->show(); diff --git a/actions/subscribers.php b/actions/subscribers.php index 4482de9a7..66ac00fb1 100644 --- a/actions/subscribers.php +++ b/actions/subscribers.php @@ -130,18 +130,34 @@ class SubscribersAction extends GalleryAction } } -class SubscribersList extends ProfileList +class SubscribersList extends SubscriptionList { - function showBlockForm() + function newListItem($profile) { - $bf = new BlockForm($this->out, $this->profile, - array('action' => 'subscribers', - 'nickname' => $this->owner->nickname)); - $bf->show(); + return new SubscribersListItem($profile, $this->owner, $this->action); } +} - function isReadOnly($args) +class SubscribersListItem extends SubscriptionListItem +{ + function showActions() { - return true; + $this->startActions(); + $this->showSubscribeButton(); + // Relevant code! + $this->showBlockForm(); + $this->endActions(); + } + + function showBlockForm() + { + $user = common_current_user(); + + if (!empty($user) && $this->owner->id == $user->id) { + $bf = new BlockForm($this->out, $this->profile, + array('action' => 'subscribers', + 'nickname' => $this->owner->nickname)); + $bf->show(); + } } } diff --git a/actions/subscriptions.php b/actions/subscriptions.php index 095b18ad8..4124abea4 100644 --- a/actions/subscriptions.php +++ b/actions/subscriptions.php @@ -137,22 +137,46 @@ class SubscriptionsAction extends GalleryAction } } -class SubscriptionsList extends ProfileList +// XXX SubscriptionsList and SubscriptionList are dangerously close + +class SubscriptionsList extends SubscriptionList { - function showOwnerControls($profile) + function newListItem($profile) + { + return new SubscriptionsListItem($profile, $this->owner, $this->action); + } +} + +class SubscriptionsListItem extends SubscriptionListItem +{ + function showProfile() + { + $this->startProfile(); + $this->showAvatar(); + $this->showFullName(); + $this->showLocation(); + $this->showHomepage(); + $this->showBio(); + $this->showTags(); + // Relevant portion! + $this->showOwnerControls(); + $this->endProfile(); + } + + function showOwnerControls() { $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id, - 'subscribed' => $profile->id)); + 'subscribed' => $this->profile->id)); if (!$sub) { return; } - $this->out->elementStart('form', array('id' => 'subedit-' . $profile->id, + $this->out->elementStart('form', array('id' => 'subedit-' . $this->profile->id, 'method' => 'post', 'class' => 'form_subscription_edit', 'action' => common_local_url('subedit'))); $this->out->hidden('token', common_session_token()); - $this->out->hidden('profile', $profile->id); + $this->out->hidden('profile', $this->profile->id); $this->out->checkbox('jabber', _('Jabber'), $sub->jabber); $this->out->checkbox('sms', _('SMS'), $sub->sms); $this->out->submit('save', _('Save')); diff --git a/actions/tag.php b/actions/tag.php index f5ca06f05..d0ad797eb 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -76,11 +76,6 @@ class TagAction extends Action sprintf(_('Feed for tag %s'), $this->tag))); } - function showPageNotice() - { - return sprintf(_('Messages tagged "%s", most recent first'), $this->tag); - } - function showContent() { $notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); diff --git a/actions/twitapiaccount.php b/actions/twitapiaccount.php index 8b956f897..b5e7b91da 100644 --- a/actions/twitapiaccount.php +++ b/actions/twitapiaccount.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/twitterapi.php'); @@ -51,7 +53,8 @@ class TwitapiaccountAction extends TwitterapiAction parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { - $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']); + $this->clientError(_('This method requires a POST.'), + 400, $apidata['content-type']); return; } @@ -60,24 +63,20 @@ class TwitapiaccountAction extends TwitterapiAction if (!is_null($location) && mb_strlen($location) > 255) { // XXX: But Twitter just truncates and runs with it. -- Zach - $this->clientError(_('That\'s too long. Max notice size is 255 chars.'), 406, $apidate['content-type']); + $this->clientError(_('That\'s too long. Max notice size is 255 chars.'), + 406, $apidate['content-type']); return; } - $user = $apidata['user']; + $user = $apidata['user']; // Always the auth user $profile = $user->getProfile(); - if (!$profile) { - $this->serverError(_('User has no profile.')); - return; - } - $orig_profile = clone($profile); $profile->location = $location; $result = $profile->update($orig_profile); - if (!$result) { + if (empty($result)) { common_log_db_error($profile, 'UPDATE', __FILE__); $this->serverError(_('Couldn\'t save profile.')); return; diff --git a/actions/twitapiblocks.php b/actions/twitapiblocks.php index 8135adef3..0e3509162 100644 --- a/actions/twitapiblocks.php +++ b/actions/twitapiblocks.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/twitterapi.php'); @@ -31,12 +33,12 @@ class TwitapiblocksAction extends TwitterapiAction $blockee = $this->get_user($apidata['api_arg'], $apidata); - if (!$blockee) { + if (empty($blockee)) { $this->clientError('Not Found', 404, $apidata['content-type']); return; } - $user = $apidata['user']; + $user = $apidata['user']; // Always the auth user if ($user->hasBlocked($blockee) || $user->block($blockee)) { $type = $apidata['content-type']; @@ -53,7 +55,7 @@ class TwitapiblocksAction extends TwitterapiAction parent::handle($args); $blockee = $this->get_user($apidata['api_arg'], $apidata); - if (!$blockee) { + if (empty($blockee)) { $this->clientError('Not Found', 404, $apidata['content-type']); return; } diff --git a/actions/twitapidirect_messages.php b/actions/twitapidirect_messages.php index d2dbdb619..85c788d6a 100644 --- a/actions/twitapidirect_messages.php +++ b/actions/twitapidirect_messages.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/twitterapi.php'); @@ -38,42 +40,34 @@ class Twitapidirect_messagesAction extends TwitterapiAction function show_messages($args, $apidata, $type) { - $user = $apidata['user']; - - $count = $this->arg('count'); - $since = $this->arg('since'); - $since_id = $this->arg('since_id'); - $max_id = $this->arg('max_id'); - - $page = $this->arg('page'); - - if (!$page) { - $page = 1; - } + $user = $apidata['user']; // Always the auth user - if (!$count) { - $count = 20; - } - - $message = new Message(); - - $title = null; + $message = new Message(); + $title = null; $subtitle = null; - $link = null; - $server = common_root_url(); + $link = null; + $server = common_root_url(); if ($type == 'received') { $message->to_profile = $user->id; $title = sprintf(_("Direct messages to %s"), $user->nickname); - $subtitle = sprintf(_("All the direct messages sent to %s"), $user->nickname); + $subtitle = sprintf(_("All the direct messages sent to %s"), + $user->nickname); $link = $server . $user->nickname . '/inbox'; } else { $message->from_profile = $user->id; $title = _('Direct Messages You\'ve Sent'); - $subtitle = sprintf(_("All the direct messages sent from %s"), $user->nickname); + $subtitle = sprintf(_("All the direct messages sent from %s"), + $user->nickname); $link = $server . $user->nickname . '/outbox'; } + $page = (int)$this->arg('page', 1); + $count = (int)$this->arg('count', 20); + $max_id = (int)$this->arg('max_id', 0); + $since_id = (int)$this->arg('since_id', 0); + $since = $this->arg('since'); + if ($max_id) { $message->whereAdd("id <= $max_id"); } @@ -82,25 +76,23 @@ class Twitapidirect_messagesAction extends TwitterapiAction $message->whereAdd("id > $since_id"); } - $since = strtotime($this->arg('since')); - if ($since) { $d = date('Y-m-d H:i:s', $since); $message->whereAdd("created > '$d'"); } $message->orderBy('created DESC, id DESC'); - $message->limit((($page-1)*20), $count); + $message->limit((($page-1)*$count), $count); $message->find(); switch($apidata['content-type']) { - case 'xml': + case 'xml': $this->show_xml_dmsgs($message); break; - case 'rss': + case 'rss': $this->show_rss_dmsgs($message, $title, $link, $subtitle); break; - case 'atom': + case 'atom': $selfuri = common_root_url() . 'api/direct_messages'; $selfuri .= ($type == 'received') ? '.atom' : '/sent.atom'; $taguribase = common_config('integration', 'taguri'); @@ -111,12 +103,13 @@ class Twitapidirect_messagesAction extends TwitterapiAction $id = "tag:$taguribase:DirectMessages:" . $user->id; } - $this->show_atom_dmsgs($message, $title, $link, $subtitle, $selfuri, $id); + $this->show_atom_dmsgs($message, $title, $link, $subtitle, + $selfuri, $id); break; - case 'json': + case 'json': $this->show_json_dmsgs($message); break; - default: + default: $this->clientError(_('API method not found!'), $code = 404); } @@ -128,22 +121,24 @@ class Twitapidirect_messagesAction extends TwitterapiAction parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { - $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']); + $this->clientError(_('This method requires a POST.'), + 400, $apidata['content-type']); return; } $user = $apidata['user']; - $source = $this->trimmed('source'); // Not supported by Twitter. + $source = $this->trimmed('source'); // Not supported by Twitter. $reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api'); - if (!$source || in_array($source, $reserved_sources)) { + if (empty($source) || in_array($source, $reserved_sources)) { $source = 'api'; } $content = $this->trimmed('text'); - if (!$content) { - $this->clientError(_('No message text!'), $code = 406, $apidata['content-type']); + if (empty($content)) { + $this->clientError(_('No message text!'), + $code = 406, $apidata['content-type']); } else { $content_shortened = common_shorten_links($content); if (mb_strlen($content_shortened) > 140) { @@ -155,8 +150,9 @@ class Twitapidirect_messagesAction extends TwitterapiAction $other = $this->get_user($this->trimmed('user')); - if (!$other) { - $this->clientError(_('Recipient user not found.'), $code = 403, $apidata['content-type']); + if (empty($other)) { + $this->clientError(_('Recipient user not found.'), + $code = 403, $apidata['content-type']); return; } else if (!$user->mutuallySubscribed($other)) { $this->clientError(_('Can\'t send direct messages to users who aren\'t your friend.'), diff --git a/actions/twitapifavorites.php b/actions/twitapifavorites.php index 31dce341b..8656adbe8 100644 --- a/actions/twitapifavorites.php +++ b/actions/twitapifavorites.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/twitterapi.php'); @@ -31,50 +33,39 @@ class TwitapifavoritesAction extends TwitterapiAction $this->auth_user = $apidata['user']; $user = $this->get_user($apidata['api_arg'], $apidata); - if (!$user) { + if (empty($user)) { $this->clientError('Not Found', 404, $apidata['content-type']); return; } $profile = $user->getProfile(); - if (!$profile) { - $this->serverError(_('User has no profile.')); - return; - } - - $page = $this->arg('page'); - - if (!$page) { - $page = 1; - } - - if (!$count) { - $count = 20; - } + $sitename = common_config('site', 'name'); + $title = sprintf(_('%s / Favorites from %s'), $sitename, + $user->nickname); + $taguribase = common_config('integration', 'taguri'); + $id = "tag:$taguribase:Favorites:".$user->id; + $link = common_local_url('favorites', + array('nickname' => $user->nickname)); + $subtitle = sprintf(_('%s updates favorited by %s / %s.'), $sitename, + $profile->getBestName(), $user->nickname); - $notice = $user->favoriteNotices((($page-1)*20), $count); + $page = (int)$this->arg('page', 1); + $count = (int)$this->arg('count', 20); + $max_id = (int)$this->arg('max_id', 0); + $since_id = (int)$this->arg('since_id', 0); + $since = $this->arg('since'); - if (!$notice) { - $this->serverError(_('Could not retrieve favorite notices.')); - return; - } - - $sitename = common_config('site', 'name'); - $title = sprintf(_('%s / Favorites from %s'), $sitename, $user->nickname); - $taguribase = common_config('integration', 'taguri'); - $id = "tag:$taguribase:Favorites:".$user->id; - $link = common_local_url('favorites', array('nickname' => $user->nickname)); - $subtitle = sprintf(_('%s updates favorited by %s / %s.'), $sitename, $profile->getBestName(), $user->nickname); + $notice = $user->favoriteNotices(($page-1)*$count, $count); switch($apidata['content-type']) { - case 'xml': + case 'xml': $this->show_xml_timeline($notice); break; - case 'rss': + case 'rss': $this->show_rss_timeline($notice, $title, $link, $subtitle); break; - case 'atom': + case 'atom': if (isset($apidata['api_arg'])) { $selfuri = $selfuri = common_root_url() . 'api/favorites/' . $apidata['api_arg'] . '.atom'; @@ -82,12 +73,13 @@ class TwitapifavoritesAction extends TwitterapiAction $selfuri = $selfuri = common_root_url() . 'api/favorites.atom'; } - $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri); + $this->show_atom_timeline($notice, $title, $id, $link, + $subtitle, null, $selfuri); break; - case 'json': + case 'json': $this->show_json_timeline($notice); break; - default: + default: $this->clientError(_('API method not found!'), $code = 404); } @@ -100,7 +92,8 @@ class TwitapifavoritesAction extends TwitterapiAction // Check for RESTfulness if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) { // XXX: Twitter just prints the err msg, no XML / JSON. - $this->clientError(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']); + $this->clientError(_('This method requires a POST or DELETE.'), + 400, $apidata['content-type']); return; } @@ -109,25 +102,27 @@ class TwitapifavoritesAction extends TwitterapiAction return; } - $this->auth_user = $apidata['user']; - $user = $this->auth_user; + $user = $apidata['user']; // Always the auth user + $notice_id = $apidata['api_arg']; $notice = Notice::staticGet($notice_id); - if (!$notice) { - $this->clientError(_('No status found with that ID.'), 404, $apidata['content-type']); + if (empty($notice)) { + $this->clientError(_('No status found with that ID.'), + 404, $apidata['content-type']); return; } // XXX: Twitter lets you fave things repeatedly via api. if ($user->hasFave($notice)) { - $this->clientError(_('This notice is already a favorite!'), 403, $apidata['content-type']); + $this->clientError(_('This notice is already a favorite!'), + 403, $apidata['content-type']); return; } $fave = Fave::addNew($user, $notice); - if (!$fave) { + if (empty($fave)) { $this->serverError(_('Could not create favorite.')); return; } @@ -149,7 +144,8 @@ class TwitapifavoritesAction extends TwitterapiAction $this->serverError(_('API method under construction.'), $code=501); } - // XXX: these two funcs swiped from faves. Maybe put in util.php, or some common base class? + // XXX: these two funcs swiped from faves. + // Maybe put in util.php, or some common base class? function notify($fave, $notice, $user) { diff --git a/actions/twitapifriendships.php b/actions/twitapifriendships.php index 2f8250e0d..b1c277748 100644 --- a/actions/twitapifriendships.php +++ b/actions/twitapifriendships.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/twitterapi.php'); @@ -29,23 +31,25 @@ class TwitapifriendshipsAction extends TwitterapiAction parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { - $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']); + $this->clientError(_('This method requires a POST.'), + 400, $apidata['content-type']); return; } - $id = $apidata['api_arg']; - + $id = $apidata['api_arg']; $other = $this->get_user($id); - if (!$other) { - $this->clientError(_('Could not follow user: User not found.'), 403, $apidata['content-type']); + if (empty($other)) { + $this->clientError(_('Could not follow user: User not found.'), + 403, $apidata['content-type']); return; } $user = $apidata['user']; if ($user->isSubscribed($other)) { - $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname); + $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), + $other->nickname); $this->clientError($errmsg, 403, $apidata['content-type']); return; } @@ -60,8 +64,9 @@ class TwitapifriendshipsAction extends TwitterapiAction $result = $sub->insert(); - if (!$result) { - $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname); + if (empty($result)) { + $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), + $other->nickname); $this->clientError($errmsg, 400, $apidata['content-type']); return; } @@ -82,7 +87,8 @@ class TwitapifriendshipsAction extends TwitterapiAction parent::handle($args); if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) { - $this->clientError(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']); + $this->clientError(_('This method requires a POST or DELETE.'), + 400, $apidata['content-type']); return; } @@ -91,7 +97,7 @@ class TwitapifriendshipsAction extends TwitterapiAction # We can't subscribe to a remote person, but we can unsub $other = $this->get_profile($id); - $user = $apidata['user']; + $user = $apidata['user']; // Alwyas the auth user $sub = new Subscription(); $sub->subscriber = $user->id; @@ -102,7 +108,8 @@ class TwitapifriendshipsAction extends TwitterapiAction $sub->delete(); $sub->query('COMMIT'); } else { - $this->clientError(_('You are not friends with the specified user.'), 403, $apidata['content-type']); + $this->clientError(_('You are not friends with the specified user.'), + 403, $apidata['content-type']); return; } @@ -128,8 +135,9 @@ class TwitapifriendshipsAction extends TwitterapiAction $user_a = $this->get_user($user_a_id); $user_b = $this->get_user($user_b_id); - if (!$user_a || !$user_b) { - $this->clientError(_('Two user ids or screen_names must be supplied.'), 400, $apidata['content-type']); + if (empty($user_a) || empty($user_b)) { + $this->clientError(_('Two user ids or screen_names must be supplied.'), + 400, $apidata['content-type']); return; } diff --git a/actions/twitapihelp.php b/actions/twitapihelp.php index db5892baf..bdef1314a 100644 --- a/actions/twitapihelp.php +++ b/actions/twitapihelp.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/twitterapi.php'); diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 1fbde6639..94f624afb 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.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/twitterapi.php'); @@ -26,64 +28,45 @@ class TwitapistatusesAction extends TwitterapiAction function public_timeline($args, $apidata) { - parent::handle($args); - - $sitename = common_config('site', 'name'); - $title = sprintf(_("%s public timeline"), $sitename); - - $taguribase = common_config('integration', 'taguri'); - $id = "tag:$taguribase:PublicTimeline"; - $link = common_root_url(); - - $subtitle = sprintf(_("%s updates from everyone!"), $sitename); - - // Number of public statuses to return by default -- Twitter sends 20 - $MAX_PUBSTATUSES = 20; - - // FIXME: To really live up to the spec we need to build a list + // XXX: To really live up to the spec we need to build a list // of notices by users who have custom avatars, so fix this SQL -- Zach - $page = $this->arg('page'); - $since_id = $this->arg('since_id'); - $max_id = $this->arg('max_id'); - - if (!$page) { - $page = 1; - } - if (!$since_id) { - $since_id = 0; - } - if (!$max_id) { - $max_id = 0; - } + parent::handle($args); - $since = strtotime($this->arg('since')); + $sitename = common_config('site', 'name'); + $title = sprintf(_("%s public timeline"), $sitename); + $taguribase = common_config('integration', 'taguri'); + $id = "tag:$taguribase:PublicTimeline"; + $link = common_root_url(); + $subtitle = sprintf(_("%s updates from everyone!"), $sitename); - $notice = Notice::publicStream((($page-1)*$MAX_PUBSTATUSES), $MAX_PUBSTATUSES, $since_id, $max_id, $since); + $page = (int)$this->arg('page', 1); + $count = (int)$this->arg('count', 20); + $max_id = (int)$this->arg('max_id', 0); + $since_id = (int)$this->arg('since_id', 0); + $since = $this->arg('since'); - if ($notice) { + $notice = Notice::publicStream(($page-1)*$count, $count, $since_id, + $max_id, $since); - switch($apidata['content-type']) { - case 'xml': - $this->show_xml_timeline($notice); - break; - case 'rss': - $this->show_rss_timeline($notice, $title, $link, $subtitle); - break; - case 'atom': - $selfuri = common_root_url() . 'api/statuses/public_timeline.atom'; - $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri); - break; - case 'json': - $this->show_json_timeline($notice); - break; - default: - $this->clientError(_('API method not found!'), $code = 404); - break; - } - - } else { - $this->serverError(_('Couldn\'t find any statuses.'), $code = 503); + switch($apidata['content-type']) { + case 'xml': + $this->show_xml_timeline($notice); + break; + case 'rss': + $this->show_rss_timeline($notice, $title, $link, $subtitle); + break; + case 'atom': + $selfuri = common_root_url() . 'api/statuses/public_timeline.atom'; + $this->show_atom_timeline($notice, $title, $id, $link, + $subtitle, null, $selfuri); + break; + case 'json': + $this->show_json_timeline($notice); + break; + default: + $this->clientError(_('API method not found!'), $code = 404); + break; } } @@ -92,68 +75,57 @@ class TwitapistatusesAction extends TwitterapiAction { parent::handle($args); - $since = $this->arg('since'); - $since_id = $this->arg('since_id'); - $count = $this->arg('count'); - $page = $this->arg('page'); - $max_id = $this->arg('max_id'); - - if (!$page) { - $page = 1; - } - - if (!$count) { - $count = 20; - } - - if (!$since_id) { - $since_id = 0; - } - - if (!$max_id) { - $max_id = 0; - } - - $since = strtotime($this->arg('since')); $user = $this->get_user($apidata['api_arg'], $apidata); $this->auth_user = $user; if (empty($user)) { - $this->clientError(_('No such user!'), 404, $apidata['content-type']); + $this->clientError(_('No such user!'), 404, + $apidata['content-type']); return; } - $profile = $user->getProfile(); - $sitename = common_config('site', 'name'); - $title = sprintf(_("%s and friends"), $user->nickname); + $profile = $user->getProfile(); + $sitename = common_config('site', 'name'); + $title = sprintf(_("%s and friends"), $user->nickname); $taguribase = common_config('integration', 'taguri'); - $id = "tag:$taguribase:FriendsTimeline:" . $user->id; - $link = common_local_url('all', array('nickname' => $user->nickname)); - $subtitle = sprintf(_('Updates from %1$s and friends on %2$s!'), $user->nickname, $sitename); + $id = "tag:$taguribase:FriendsTimeline:" . $user->id; + $link = common_local_url('all', + array('nickname' => $user->nickname)); + $subtitle = sprintf(_('Updates from %1$s and friends on %2$s!'), + $user->nickname, $sitename); + + $page = (int)$this->arg('page', 1); + $count = (int)$this->arg('count', 20); + $max_id = (int)$this->arg('max_id', 0); + $since_id = (int)$this->arg('since_id', 0); + $since = $this->arg('since'); - $notice = $user->noticesWithFriends(($page-1)*20, $count, $since_id, $max_id, $since); + $notice = $user->noticesWithFriends(($page-1)*$count, + $count, $since_id, $max_id,$since); switch($apidata['content-type']) { - case 'xml': + case 'xml': $this->show_xml_timeline($notice); break; - case 'rss': + case 'rss': $this->show_rss_timeline($notice, $title, $link, $subtitle); break; - case 'atom': + case 'atom': if (isset($apidata['api_arg'])) { $selfuri = common_root_url() . - 'api/statuses/friends_timeline/' . $apidata['api_arg'] . '.atom'; + 'api/statuses/friends_timeline/' . + $apidata['api_arg'] . '.atom'; } else { $selfuri = common_root_url() . 'api/statuses/friends_timeline.atom'; } - $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri); + $this->show_atom_timeline($notice, $title, $id, $link, + $subtitle, null, $selfuri); break; - case 'json': + case 'json': $this->show_json_timeline($notice); break; - default: + default: $this->clientError(_('API method not found!'), $code = 404); } @@ -166,48 +138,21 @@ class TwitapistatusesAction extends TwitterapiAction $this->auth_user = $apidata['user']; $user = $this->get_user($apidata['api_arg'], $apidata); - if (!$user) { + if (empty($user)) { $this->clientError('Not Found', 404, $apidata['content-type']); return; } $profile = $user->getProfile(); - if (!$profile) { - $this->serverError(_('User has no profile.')); - return; - } - - $count = $this->arg('count'); - $since = $this->arg('since'); - $since_id = $this->arg('since_id'); - $page = $this->arg('page'); - $max_id = $this->arg('max_id'); - - if (!$page) { - $page = 1; - } - - if (!$count) { - $count = 20; - } - - if (!$since_id) { - $since_id = 0; - } - - if (!$max_id) { - $max_id = 0; - } - - $since = strtotime($this->arg('since')); - - $sitename = common_config('site', 'name'); - $title = sprintf(_("%s timeline"), $user->nickname); + $sitename = common_config('site', 'name'); + $title = sprintf(_("%s timeline"), $user->nickname); $taguribase = common_config('integration', 'taguri'); - $id = "tag:$taguribase:UserTimeline:".$user->id; - $link = common_local_url('showstream', array('nickname' => $user->nickname)); - $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $user->nickname, $sitename); + $id = "tag:$taguribase:UserTimeline:".$user->id; + $link = common_local_url('showstream', + array('nickname' => $user->nickname)); + $subtitle = sprintf(_('Updates from %1$s on %2$s!'), + $user->nickname, $sitename); # FriendFeed's SUP protocol # Also added RSS and Atom feeds @@ -215,26 +160,34 @@ class TwitapistatusesAction extends TwitterapiAction $suplink = common_local_url('sup', null, null, $user->id); header('X-SUP-ID: '.$suplink); - # XXX: since + $page = (int)$this->arg('page', 1); + $count = (int)$this->arg('count', 20); + $max_id = (int)$this->arg('max_id', 0); + $since_id = (int)$this->arg('since_id', 0); + $since = $this->arg('since'); - $notice = $user->getNotices((($page-1)*20), $count, $since_id, $max_id, $since); + $notice = $user->getNotices(($page-1)*$count, + $count, $since_id, $max_id, $since); switch($apidata['content-type']) { case 'xml': $this->show_xml_timeline($notice); break; case 'rss': - $this->show_rss_timeline($notice, $title, $link, $subtitle, $suplink); + $this->show_rss_timeline($notice, $title, $link, + $subtitle, $suplink); break; case 'atom': if (isset($apidata['api_arg'])) { $selfuri = common_root_url() . - 'api/statuses/user_timeline/' . $apidata['api_arg'] . '.atom'; + 'api/statuses/user_timeline/' . + $apidata['api_arg'] . '.atom'; } else { $selfuri = common_root_url() . 'api/statuses/user_timeline.atom'; } - $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink, $selfuri); + $this->show_atom_timeline($notice, $title, $id, $link, + $subtitle, $suplink, $selfuri); break; case 'json': $this->show_json_timeline($notice); @@ -247,7 +200,6 @@ class TwitapistatusesAction extends TwitterapiAction function update($args, $apidata) { - parent::handle($args); if (!in_array($apidata['content-type'], array('xml', 'json'))) { @@ -256,21 +208,24 @@ class TwitapistatusesAction extends TwitterapiAction } if ($_SERVER['REQUEST_METHOD'] != 'POST') { - $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']); + $this->clientError(_('This method requires a POST.'), + 400, $apidata['content-type']); return; } - $this->auth_user = $apidata['user']; - $user = $this->auth_user; + $user = $apidata['user']; // Always the auth user + $status = $this->trimmed('status'); $source = $this->trimmed('source'); - $in_reply_to_status_id = intval($this->trimmed('in_reply_to_status_id')); + $in_reply_to_status_id = + intval($this->trimmed('in_reply_to_status_id')); $reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api'); - if (!$source || in_array($source, $reserved_sources)) { + + if (empty($source) || in_array($source, $reserved_sources)) { $source = 'api'; } - if (!$status) { + if (empty($status)) { // XXX: Note: In this case, Twitter simply returns '200 OK' // No error is given, but the status is not posted to the @@ -288,9 +243,9 @@ class TwitapistatusesAction extends TwitterapiAction // as "truncated." Sending this error may screw up some clients // that assume Twitter will truncate for them. Should we just // truncate too? -- Zach - $this->clientError(_('That\'s too long. Max notice size is 140 chars.'), $code = 406, $apidata['content-type']); + $this->clientError(_('That\'s too long. Max notice size is 140 chars.'), + $code = 406, $apidata['content-type']); return; - } } @@ -321,13 +276,15 @@ class TwitapistatusesAction extends TwitterapiAction if ($reply) { $reply_to = $in_reply_to_status_id; } else { - $this->clientError(_('Not found'), $code = 404, $apidata['content-type']); + $this->clientError(_('Not found'), $code = 404, + $apidata['content-type']); return; } } - $notice = Notice::saveNew($user->id, html_entity_decode($status, ENT_NOQUOTES, 'UTF-8'), - $source, 1, $reply_to); + $notice = Notice::saveNew($user->id, + html_entity_decode($status, ENT_NOQUOTES, 'UTF-8'), + $source, 1, $reply_to); if (is_string($notice)) { $this->serverError($notice); @@ -343,71 +300,55 @@ class TwitapistatusesAction extends TwitterapiAction function mentions($args, $apidata) { - parent::handle($args); - $since = $this->arg('since'); - $count = $this->arg('count'); - $page = $this->arg('page'); - $since_id = $this->arg('since_id'); - $max_id = $this->arg('max_id'); - $user = $this->get_user($apidata['api_arg'], $apidata); $this->auth_user = $apidata['user']; + + if (empty($user)) { + $this->clientError(_('No such user!'), 404, + $apidata['content-type']); + return; + } + $profile = $user->getProfile(); - $sitename = common_config('site', 'name'); - $title = sprintf(_('%1$s / Updates mentioning %2$s'), + $sitename = common_config('site', 'name'); + $title = sprintf(_('%1$s / Updates mentioning %2$s'), $sitename, $user->nickname); $taguribase = common_config('integration', 'taguri'); - $id = "tag:$taguribase:Mentions:".$user->id; - $link = common_local_url('replies', array('nickname' => $user->nickname)); - $subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'), + $id = "tag:$taguribase:Mentions:".$user->id; + $link = common_local_url('replies', + array('nickname' => $user->nickname)); + $subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'), $sitename, $user->nickname, $profile->getBestName()); - if (!$page) { - $page = 1; - } + $page = (int)$this->arg('page', 1); + $count = (int)$this->arg('count', 20); + $max_id = (int)$this->arg('max_id', 0); + $since_id = (int)$this->arg('since_id', 0); + $since = $this->arg('since'); - if (!$count) { - $count = 20; - } - - if (!$since_id) { - $since_id = 0; - } - - if (!$max_id) { - $max_id = 0; - } - - $since = strtotime($this->arg('since')); - - $notice = $user->getReplies((($page-1)*20), + $notice = $user->getReplies(($page-1)*$count, $count, $since_id, $max_id, $since); - $notices = array(); - - while ($notice->fetch()) { - $notices[] = clone($notice); - } switch($apidata['content-type']) { - case 'xml': - $this->show_xml_timeline($notices); + case 'xml': + $this->show_xml_timeline($notice); break; - case 'rss': - $this->show_rss_timeline($notices, $title, $link, $subtitle); + case 'rss': + $this->show_rss_timeline($notice, $title, $link, $subtitle); break; - case 'atom': + case 'atom': $selfuri = common_root_url() . ltrim($_SERVER['QUERY_STRING'], 'p='); - $this->show_atom_timeline($notices, $title, $id, $link, $subtitle, + $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri); break; - case 'json': - $this->show_json_timeline($notices); + case 'json': + $this->show_json_timeline($notice); break; - default: + default: $this->clientError(_('API method not found!'), $code = 404); } @@ -428,8 +369,8 @@ class TwitapistatusesAction extends TwitterapiAction } $this->auth_user = $apidata['user']; - $notice_id = $apidata['api_arg']; - $notice = Notice::staticGet($notice_id); + $notice_id = $apidata['api_arg']; + $notice = Notice::staticGet($notice_id); if ($notice) { if ($apidata['content-type'] == 'xml') { @@ -438,15 +379,16 @@ class TwitapistatusesAction extends TwitterapiAction $this->show_single_json_status($notice); } } else { - // XXX: Twitter just sets a 404 header and doens't bother to return an err msg - $this->clientError(_('No status with that ID found.'), 404, $apidata['content-type']); + // XXX: Twitter just sets a 404 header and doens't bother + // to return an err msg + $this->clientError(_('No status with that ID found.'), + 404, $apidata['content-type']); } } function destroy($args, $apidata) { - parent::handle($args); if (!in_array($apidata['content-type'], array('xml', 'json'))) { @@ -457,17 +399,18 @@ class TwitapistatusesAction extends TwitterapiAction // Check for RESTfulness if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) { // XXX: Twitter just prints the err msg, no XML / JSON. - $this->clientError(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']); + $this->clientError(_('This method requires a POST or DELETE.'), + 400, $apidata['content-type']); return; } - $this->auth_user = $apidata['user']; - $user = $this->auth_user; + $user = $apidata['user']; // Always the auth user $notice_id = $apidata['api_arg']; - $notice = Notice::staticGet($notice_id); + $notice = Notice::staticGet($notice_id); - if (!$notice) { - $this->clientError(_('No status found with that ID.'), 404, $apidata['content-type']); + if (empty($notice)) { + $this->clientError(_('No status found with that ID.'), + 404, $apidata['content-type']); return; } @@ -483,7 +426,8 @@ class TwitapistatusesAction extends TwitterapiAction $this->show_single_json_status($notice); } } else { - $this->clientError(_('You may not delete another user\'s status.'), 403, $apidata['content-type']); + $this->clientError(_('You may not delete another user\'s status.'), + 403, $apidata['content-type']); } } @@ -514,42 +458,41 @@ class TwitapistatusesAction extends TwitterapiAction function subscriptions($apidata, $other_attr, $user_attr, $onlyIDs=false) { - $this->auth_user = $apidata['user']; $user = $this->get_user($apidata['api_arg'], $apidata); - if (!$user) { + if (empty($user)) { $this->clientError('Not Found', 404, $apidata['content-type']); return; } - $page = $this->trimmed('page'); - - if (!$page || !is_numeric($page)) { - $page = 1; - } - $profile = $user->getProfile(); - if (!$profile) { - $this->serverError(_('User has no profile.')); - return; - } - $sub = new Subscription(); $sub->$user_attr = $profile->id; - $since = strtotime($this->trimmed('since')); - - if ($since) { - $d = date('Y-m-d H:i:s', $since); - $sub->whereAdd("created > '$d'"); - } - $sub->orderBy('created DESC'); + // Normally, page 100 friends at a time + if (!$onlyIDs) { - $sub->limit(($page-1)*100, 100); + $page = $this->arg('page', 1); + $count = $this->arg('count', 100); + $sub->limit(($page-1)*$count, $count); + } else { + + // If we're just looking at IDs, return + // ALL of them, unless the user specifies a page, + // in which case, return 500 per page. + + $page = $this->arg('page'); + if (!empty($page)) { + if ($page < 1) { + $page = 1; + } + $count = 500; + $sub->limit(($page-1)*$count, $count); + } } $others = array(); @@ -578,21 +521,21 @@ class TwitapistatusesAction extends TwitterapiAction function show_profiles($profiles, $type) { switch ($type) { - case 'xml': + case 'xml': $this->elementStart('users', array('type' => 'array')); foreach ($profiles as $profile) { $this->show_profile($profile); } $this->elementEnd('users'); break; - case 'json': + case 'json': $arrays = array(); foreach ($profiles as $profile) { $arrays[] = $this->twitter_user_array($profile, true); } print json_encode($arrays); break; - default: + default: $this->clientError(_('unsupported file type')); } } @@ -600,21 +543,21 @@ class TwitapistatusesAction extends TwitterapiAction function showIDs($profiles, $type) { switch ($type) { - case 'xml': + case 'xml': $this->elementStart('ids'); foreach ($profiles as $profile) { $this->element('id', null, $profile->id); } $this->elementEnd('ids'); break; - case 'json': + case 'json': $ids = array(); foreach ($profiles as $profile) { $ids[] = (int)$profile->id; } print json_encode($ids); break; - default: + default: $this->clientError(_('unsupported file type')); } } @@ -627,8 +570,8 @@ class TwitapistatusesAction extends TwitterapiAction function supported($cmd) { - - $cmdlist = array('MessageCommand', 'SubCommand', 'UnsubCommand', 'FavCommand', 'OnCommand', 'OffCommand'); + $cmdlist = array('MessageCommand', 'SubCommand', 'UnsubCommand', + 'FavCommand', 'OnCommand', 'OffCommand'); if (in_array(get_class($cmd), $cmdlist)) { return true; diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php index b90bbfa98..13a8746cd 100644 --- a/actions/twitapiusers.php +++ b/actions/twitapiusers.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/twitterapi.php'); @@ -51,18 +53,11 @@ class TwitapiusersAction extends TwitterapiAction $user = $apidata['user']; } - if (!$user) { + if (empty($user)) { $this->client_error(_('Not found.'), 404, $apidata['content-type']); return; } - $profile = $user->getProfile(); - - if (!$profile) { - common_server_error(_('User has no profile.')); - return; - } - $twitter_user = $this->twitter_user_array($profile, true); if ($apidata['content-type'] == 'xml') { diff --git a/actions/twittersettings.php b/actions/twittersettings.php index 0b98eef59..2b742788e 100644 --- a/actions/twittersettings.php +++ b/actions/twittersettings.php @@ -138,7 +138,7 @@ class TwittersettingsAction extends ConnectSettingsAction $this->elementStart('ul', 'form_data'); $this->elementStart('li'); - $this->checkbox('noticesync', + $this->checkbox('noticesend', _('Automatically send my notices to Twitter.'), ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : @@ -158,6 +158,22 @@ class TwittersettingsAction extends ConnectSettingsAction ($flink->friendsync & FOREIGN_FRIEND_RECV) : false); $this->elementEnd('li'); + + if (common_config('twitterbridge','enabled')) { + $this->elementStart('li'); + $this->checkbox('noticerecv', + _('Import my Friends Timeline.'), + ($flink) ? + ($flink->noticesync & FOREIGN_NOTICE_RECV) : + false); + $this->elementEnd('li'); + } else { + // preserve setting even if bidrection bridge toggled off + if ($flink && ($flink->noticesync & FOREIGN_NOTICE_RECV)) { + $this->hidden('noticerecv', true, 'noticerecv'); + } + } + $this->elementEnd('ul'); if ($flink) { @@ -320,7 +336,8 @@ class TwittersettingsAction extends ConnectSettingsAction { $screen_name = $this->trimmed('twitter_username'); $password = $this->trimmed('twitter_password'); - $noticesync = $this->boolean('noticesync'); + $noticesend = $this->boolean('noticesend'); + $noticerecv = $this->boolean('noticerecv'); $replysync = $this->boolean('replysync'); $friendsync = $this->boolean('friendsync'); @@ -363,7 +380,7 @@ class TwittersettingsAction extends ConnectSettingsAction $flink->credentials = $password; $flink->created = common_sql_now(); - $flink->set_flags($noticesync, $replysync, $friendsync); + $flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync); $flink_id = $flink->insert(); @@ -421,7 +438,8 @@ class TwittersettingsAction extends ConnectSettingsAction function savePreferences() { - $noticesync = $this->boolean('noticesync'); + $noticesend = $this->boolean('noticesend'); + $noticerecv = $this->boolean('noticerecv'); $friendsync = $this->boolean('friendsync'); $replysync = $this->boolean('replysync'); @@ -450,7 +468,7 @@ class TwittersettingsAction extends ConnectSettingsAction $original = clone($flink); - $flink->set_flags($noticesync, $replysync, $friendsync); + $flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync); $result = $flink->update($original); diff --git a/actions/userrss.php b/actions/userrss.php index 5861d9ee3..2280509b2 100644 --- a/actions/userrss.php +++ b/actions/userrss.php @@ -25,14 +25,15 @@ require_once(INSTALLDIR.'/lib/rssaction.php'); class UserrssAction extends Rss10Action { - var $user = null; + var $tag = null; function prepare($args) { parent::prepare($args); - $nickname = $this->trimmed('nickname'); + $nickname = $this->trimmed('nickname'); $this->user = User::staticGet('nickname', $nickname); + $this->tag = $this->trimmed('tag'); if (!$this->user) { $this->clientError(_('No such user.')); @@ -42,6 +43,25 @@ class UserrssAction extends Rss10Action } } + function getTaggedNotices($tag = null, $limit=0) + { + $user = $this->user; + + if (is_null($user)) { + return null; + } + + $notice = $user->getTaggedNotices(0, ($limit == 0) ? NOTICES_PER_PAGE : $limit, 0, 0, null, $tag); + + $notices = array(); + while ($notice->fetch()) { + $notices[] = clone($notice); + } + + return $notices; + } + + function getNotices($limit=0) { |