From: Roland Häder Date: Fri, 9 Jan 2015 08:13:14 +0000 (+0100) Subject: Merge branch 'master' into social-master X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f2bfcdc2c1d7bc4634bb06285380884a57075759;p=quix0rs-gnu-social.git Merge branch 'master' into social-master Conflicts: lib/menu.php plugins/AccountManager/AccountManagerPlugin.php plugins/ActivitySpam/ActivitySpamPlugin.php plugins/BitlyUrl/BitlyUrlPlugin.php plugins/Blacklist/BlacklistPlugin.php plugins/Blog/BlogPlugin.php plugins/Bookmark/BookmarkPlugin.php plugins/Directory/DirectoryPlugin.php plugins/Event/EventPlugin.php plugins/FacebookBridge/FacebookBridgePlugin.php plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php plugins/OStatus/OStatusPlugin.php plugins/Poll/PollPlugin.php plugins/QnA/QnAPlugin.php plugins/Realtime/RealtimePlugin.php plugins/Sample/SamplePlugin.php plugins/SearchSub/SearchSubPlugin.php plugins/Sitemap/SitemapPlugin.php plugins/SlicedFavorites/SlicedFavoritesPlugin.php plugins/SubMirror/SubMirrorPlugin.php plugins/TagSub/TagSubPlugin.php plugins/TwitterBridge/TwitterBridgePlugin.php plugins/UserFlag/UserFlagPlugin.php plugins/YammerImport/YammerImportPlugin.php Signed-off-by: Roland Häder --- f2bfcdc2c1d7bc4634bb06285380884a57075759 diff --cc lib/menu.php index 46e160562a,27503aa06b..b9dfb88c73 --- a/lib/menu.php +++ b/lib/menu.php @@@ -107,8 -103,8 +107,8 @@@ class Menu extends Widge Event::handle('EndNav', array($this, $tag, $items)); } } - + - function item($actionName, $args, $label, $description, $id=null, $cls=null) + function item($actionName, array $args, $label, $description, $id=null, $cls=null) { if (empty($id)) { $id = $this->menuItemID($actionName, $args); @@@ -144,11 -134,11 +144,11 @@@ return true; } -- ++ function menuItemID($actionName, $args = null) { $id = sprintf('nav_%s', $actionName); -- ++ if (!is_null($args)) { foreach ($args as $key => $value) { $id .= '_' . $key . '_' . $value; diff --cc plugins/DirectMessage/actions/apidirectmessage.php index 0000000000,c18559f49d..294f600def mode 000000,100644..100644 --- a/plugins/DirectMessage/actions/apidirectmessage.php +++ b/plugins/DirectMessage/actions/apidirectmessage.php @@@ -1,0 -1,463 +1,463 @@@ + . + * + * @category API + * @package StatusNet + * @author Adrian Lang + * @author Evan Prodromou + * @author Robin Millette + * @author Zach Copley + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + + if (!defined('STATUSNET')) { + exit(1); + } + + /** + * Show a list of direct messages from or to the authenticating user + * + * @category API + * @package StatusNet + * @author Adrian Lang + * @author Evan Prodromou + * @author Robin Millette + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + class ApiDirectMessageAction extends ApiAuthAction + { + var $messages = null; + var $title = null; + var $subtitle = null; + var $link = null; + var $selfuri_base = null; + var $id = null; + + /** + * Take arguments for running + * + * @param array $args $_REQUEST args + * + * @return boolean success flag + */ - function prepare($args) ++ function prepare(array $args=array()) + { + parent::prepare($args); + + $this->user = $this->auth_user; + + if (empty($this->user)) { + // TRANS: Client error given when a user was not found (404). + $this->clientError(_('No such user.'), 404); + } + + $server = common_root_url(); + $taguribase = TagURI::base(); + + if ($this->arg('sent')) { + + // Action was called by /api/direct_messages/sent.format + + $this->title = sprintf( + // TRANS: Title. %s is a user nickname. + _("Direct messages from %s"), + $this->user->nickname + ); + $this->subtitle = sprintf( + // TRANS: Subtitle. %s is a user nickname. + _("All the direct messages sent from %s"), + $this->user->nickname + ); + $this->link = $server . $this->user->nickname . '/outbox'; + $this->selfuri_base = common_root_url() . 'api/direct_messages/sent'; + $this->id = "tag:$taguribase:SentDirectMessages:" . $this->user->id; + } else { + $this->title = sprintf( + // TRANS: Title. %s is a user nickname. + _("Direct messages to %s"), + $this->user->nickname + ); + $this->subtitle = sprintf( + // TRANS: Subtitle. %s is a user nickname. + _("All the direct messages sent to %s"), + $this->user->nickname + ); + $this->link = $server . $this->user->nickname . '/inbox'; + $this->selfuri_base = common_root_url() . 'api/direct_messages'; + $this->id = "tag:$taguribase:DirectMessages:" . $this->user->id; + } + + $this->messages = $this->getMessages(); + + return true; + } + + /** + * Handle the request + * + * Show the messages + * + * @param array $args $_REQUEST data (unused) + * + * @return void + */ - function handle($args) ++ function handle(array $args=array()) + { + parent::handle($args); + $this->showMessages(); + } + + /** + * Show the messages + * + * @return void + */ + function showMessages() + { + switch($this->format) { + case 'xml': + $this->showXmlDirectMessages(); + break; + case 'rss': + $this->showRssDirectMessages(); + break; + case 'atom': + $this->showAtomDirectMessages(); + break; + case 'json': + $this->showJsonDirectMessages(); + break; + default: + // TRANS: Client error displayed when coming across a non-supported API method. + $this->clientError(_('API method not found.'), $code = 404); + break; + } + } + + /** + * Get notices + * + * @return array notices + */ + function getMessages() + { + $message = new Message(); + + if ($this->arg('sent')) { + $message->from_profile = $this->user->id; + } else { + $message->to_profile = $this->user->id; + } + + if (!empty($this->max_id)) { + $message->whereAdd('id <= ' . $this->max_id); + } + + if (!empty($this->since_id)) { + $message->whereAdd('id > ' . $this->since_id); + } + + $message->orderBy('created DESC, id DESC'); + $message->limit((($this->page - 1) * $this->count), $this->count); + $message->find(); + + $messages = array(); + + while ($message->fetch()) { + $messages[] = clone($message); + } + + return $messages; + } + + /** + * Is this action read only? + * + * @param array $args other arguments + * + * @return boolean true + */ - function isReadOnly($args) ++ function isReadOnly(array $args=array()) + { + return true; + } + + /** + * When was this notice last modified? + * + * @return string datestamp of the latest notice in the stream + */ + function lastModified() + { + if (!empty($this->messages)) { + return strtotime($this->messages[0]->created); + } + + return null; + } + + // BEGIN import from lib/apiaction.php + + function showSingleXmlDirectMessage($message) + { + $this->initDocument('xml'); + $dmsg = $this->directMessageArray($message); + $this->showXmlDirectMessage($dmsg, true); + $this->endDocument('xml'); + } + + function showSingleJsonDirectMessage($message) + { + $this->initDocument('json'); + $dmsg = $this->directMessageArray($message); + $this->showJsonObjects($dmsg); + $this->endDocument('json'); + } + + function showXmlDirectMessage($dm, $namespaces=false) + { + $attrs = array(); + if ($namespaces) { + $attrs['xmlns:statusnet'] = 'http://status.net/schema/api/1/'; + } + $this->elementStart('direct_message', $attrs); + foreach($dm as $element => $value) { + switch ($element) { + case 'sender': + case 'recipient': + $this->showTwitterXmlUser($value, $element); + break; + case 'text': + $this->element($element, null, common_xml_safe_str($value)); + break; + default: + $this->element($element, null, $value); + break; + } + } + $this->elementEnd('direct_message'); + } + + function directMessageArray($message) + { + $dmsg = array(); + + $from_profile = $message->getFrom(); + $to_profile = $message->getTo(); + + $dmsg['id'] = intval($message->id); + $dmsg['sender_id'] = intval($from_profile->id); + $dmsg['text'] = trim($message->content); + $dmsg['recipient_id'] = intval($to_profile->id); + $dmsg['created_at'] = $this->dateTwitter($message->created); + $dmsg['sender_screen_name'] = $from_profile->nickname; + $dmsg['recipient_screen_name'] = $to_profile->nickname; + $dmsg['sender'] = $this->twitterUserArray($from_profile, false); + $dmsg['recipient'] = $this->twitterUserArray($to_profile, false); + + return $dmsg; + } + + function rssDirectMessageArray($message) + { + $entry = array(); + + $from = $message->getFrom(); + + $entry['title'] = sprintf('Message from %1$s to %2$s', + $from->nickname, $message->getTo()->nickname); + + $entry['content'] = common_xml_safe_str($message->rendered); + $entry['link'] = common_local_url('showmessage', array('message' => $message->id)); + $entry['published'] = common_date_iso8601($message->created); + + $taguribase = TagURI::base(); + + $entry['id'] = "tag:$taguribase:$entry[link]"; + $entry['updated'] = $entry['published']; + + $entry['author-name'] = $from->getBestName(); + $entry['author-uri'] = $from->homepage; + + $entry['avatar'] = $from->avatarUrl(AVATAR_STREAM_SIZE); + try { + $avatar = $from->getAvatar(AVATAR_STREAM_SIZE); + $entry['avatar-type'] = $avatar->mediatype; + } catch (Exception $e) { + $entry['avatar-type'] = 'image/png'; + } + + // RSS item specific + + $entry['description'] = $entry['content']; + $entry['pubDate'] = common_date_rfc2822($message->created); + $entry['guid'] = $entry['link']; + + return $entry; + } + + // END import from lib/apiaction.php + + /** + * Shows a list of direct messages as Twitter-style XML array + * + * @return void + */ + function showXmlDirectMessages() + { + $this->initDocument('xml'); + $this->elementStart('direct-messages', array('type' => 'array', + 'xmlns:statusnet' => 'http://status.net/schema/api/1/')); + + foreach ($this->messages as $m) { + $dm_array = $this->directMessageArray($m); + $this->showXmlDirectMessage($dm_array); + } + + $this->elementEnd('direct-messages'); + $this->endDocument('xml'); + } + + /** + * Shows a list of direct messages as a JSON encoded array + * + * @return void + */ + function showJsonDirectMessages() + { + $this->initDocument('json'); + + $dmsgs = array(); + + foreach ($this->messages as $m) { + $dm_array = $this->directMessageArray($m); + array_push($dmsgs, $dm_array); + } + + $this->showJsonObjects($dmsgs); + $this->endDocument('json'); + } + + /** + * Shows a list of direct messages as RSS items + * + * @return void + */ + function showRssDirectMessages() + { + $this->initDocument('rss'); + + $this->element('title', null, $this->title); + + $this->element('link', null, $this->link); + $this->element('description', null, $this->subtitle); + $this->element('language', null, 'en-us'); + + $this->element( + 'atom:link', + array( + 'type' => 'application/rss+xml', + 'href' => $this->selfuri_base . '.rss', + 'rel' => self + ), + null + ); + $this->element('ttl', null, '40'); + + foreach ($this->messages as $m) { + $entry = $this->rssDirectMessageArray($m); + $this->showTwitterRssItem($entry); + } + + $this->endTwitterRss(); + } + + /** + * Shows a list of direct messages as Atom entries + * + * @return void + */ + function showAtomDirectMessages() + { + $this->initDocument('atom'); + + $this->element('title', null, $this->title); + $this->element('id', null, $this->id); + + $selfuri = common_root_url() . 'api/direct_messages.atom'; + + $this->element( + 'link', array( + 'href' => $this->link, + 'rel' => 'alternate', + 'type' => 'text/html'), + null + ); + $this->element( + 'link', array( + 'href' => $this->selfuri_base . '.atom', 'rel' => 'self', + 'type' => 'application/atom+xml'), + null + ); + $this->element('updated', null, common_date_iso8601('now')); + $this->element('subtitle', null, $this->subtitle); + + foreach ($this->messages as $m) { + $entry = $this->rssDirectMessageArray($m); + $this->showTwitterAtomEntry($entry); + } + + $this->endDocument('atom'); + } + + /** + * An entity tag for this notice + * + * Returns an Etag based on the action name, language, and + * timestamps of the notice + * + * @return string etag + */ + function etag() + { + if (!empty($this->messages)) { + + $last = count($this->messages) - 1; + + return '"' . implode( + ':', + array($this->arg('action'), + common_user_cache_hash($this->auth_user), + common_language(), + strtotime($this->messages[0]->created), + strtotime($this->messages[$last]->created) + ) + ) + . '"'; + } + + return null; + } + } diff --cc plugins/DirectMessage/actions/showmessage.php index 0000000000,86fbee8b73..0987ee3aa7 mode 000000,100644..100644 --- a/plugins/DirectMessage/actions/showmessage.php +++ b/plugins/DirectMessage/actions/showmessage.php @@@ -1,0 -1,163 +1,163 @@@ + . + * + * @category Personal + * @package StatusNet + * @author Evan Prodromou + * @copyright 2008-2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); + } + + /** + * Show a single message + * + * @category Personal + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + + class ShowmessageAction extends Action + { + /** + * Message object to show + */ + var $message = null; + + /** + * The current user + */ + + var $user = null; + + /** + * Load attributes based on database arguments + * + * Loads all the DB stuff + * + * @param array $args $_REQUEST array + * + * @return success flag + */ - function prepare($args) ++ function prepare(array $args=array()) + { + parent::prepare($args); + + $this->page = 1; + + $id = $this->trimmed('message'); + $this->message = Message::getKV('id', $id); + + if (!$this->message) { + // TRANS: Client error displayed requesting a single message that does not exist. + $this->clientError(_('No such message.'), 404); + } + + $this->user = common_current_user(); + + if (empty($this->user) || + ($this->user->id != $this->message->from_profile && + $this->user->id != $this->message->to_profile)) { + // TRANS: Client error displayed requesting a single direct message the requesting user was not a party in. + throw new ClientException(_('Only the sender and recipient ' . + 'may read this message.'), 403); + } + + return true; + } + - function handle($args) ++ function handle(array $args=array()) + { + $this->showPage(); + } + + function title() + { + if ($this->user->id == $this->message->from_profile) { + $to = $this->message->getTo(); + // @todo FIXME: Might be nice if the timestamp could be localised. + // TRANS: Page title for single direct message display when viewing user is the sender. + // TRANS: %1$s is the addressed user's nickname, $2$s is a timestamp. + return sprintf(_('Message to %1$s on %2$s'), + $to->nickname, + common_exact_date($this->message->created)); + } else if ($this->user->id == $this->message->to_profile) { + $from = $this->message->getFrom(); + // @todo FIXME: Might be nice if the timestamp could be localised. + // TRANS: Page title for single message display. + // TRANS: %1$s is the sending user's nickname, $2$s is a timestamp. + return sprintf(_('Message from %1$s on %2$s'), + $from->nickname, + common_exact_date($this->message->created)); + } + } + + + function showContent() + { + $this->elementStart('ul', 'notices messages'); + $ml = new ShowMessageListItem($this, $this->message, $this->user); + $ml->show(); + $this->elementEnd('ul'); + } + - function isReadOnly($args) ++ function isReadOnly(array $args=array()) + { + return true; + } + + /** + * Don't show aside + * + * @return void + */ + + function showAside() { + } + } + + class ShowMessageListItem extends MessageListItem + { + var $user; + + function __construct($out, $message, $user) + { + parent::__construct($out, $message); + $this->user = $user; + } + + function getMessageProfile() + { + if ($this->user->id == $this->message->from_profile) { + return $this->message->getTo(); + } else if ($this->user->id == $this->message->to_profile) { + return $this->message->getFrom(); + } else { + // This shouldn't happen + return null; + } + } + } diff --cc plugins/DirectMessage/lib/inboxmessagelist.php index 0000000000,3c7281e985..bc5ff76661 mode 000000,100644..100644 --- a/plugins/DirectMessage/lib/inboxmessagelist.php +++ b/plugins/DirectMessage/lib/inboxmessagelist.php @@@ -1,0 -1,167 +1,167 @@@ + . + * + * @category Message + * @package StatusNet + * @author Evan Prodromou + * @copyright 2008 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + + if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); + } + + /** + * common superclass for direct messages inbox and outbox + * + * @category Message + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + * @see InboxAction + * @see OutboxAction + */ + class MailboxAction extends Action + { + var $page = null; + - function prepare($args) ++ function prepare(array $args=array()) + { + parent::prepare($args); + + $nickname = common_canonical_nickname($this->arg('nickname')); + $this->user = User::getKV('nickname', $nickname); + $this->page = $this->trimmed('page'); + + if (!$this->page) { + $this->page = 1; + } + + common_set_returnto($this->selfUrl()); + + return true; + } + + /** + * output page based on arguments + * + * @param array $args HTTP arguments (from $_REQUEST) + * + * @return void + */ - function handle($args) ++ function handle(array $args=array()) + { + parent::handle($args); + + if (!$this->user) { + // TRANS: Client error displayed when trying to access a mailbox without providing a user. + $this->clientError(_('No such user.'), 404); + } + + $cur = common_current_user(); + + if (!$cur || $cur->id != $this->user->id) { + // TRANS: Client error displayed when trying to access a mailbox that is not of the logged in user. + $this->clientError(_('Only the user can read their own mailboxes.'), 403); + } + + $this->showPage(); + } + + function showNoticeForm() + { + $message_form = new MessageForm($this); + $message_form->show(); + } + + function showContent() + { + $message = $this->getMessages(); + + if ($message) { + + $ml = $this->getMessageList($message); + + $cnt = $ml->show(); + + $this->pagination($this->page > 1, + $cnt > MESSAGES_PER_PAGE, + $this->page, + $this->trimmed('action'), + array('nickname' => $this->user->nickname)); + } else { + $this->element('p', + 'guide', + // TRANS: Message displayed when there are no private messages in the inbox of a user. + _('You have no private messages. '. + 'You can send private message to engage other users in conversation. '. + 'People can send you messages for your eyes only.')); + } + } + + function getMessages() + { + return null; + } + + function getMessageList($message) + { + return null; + } + + /** + * Show the page notice + * + * Shows instructions for the page + * + * @return void + */ + function showPageNotice() + { + $instr = $this->getInstructions(); + $output = common_markup_to_html($instr); + + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + + /** + * Mailbox actions are read only + * + * @param array $args other arguments + * + * @return boolean + */ - function isReadOnly($args) ++ function isReadOnly(array $args=array()) + { + return true; + } + + function showObjectNav() + { + $mm = new MailboxMenu($this); + $mm->show(); + } + } diff --cc plugins/Directory/DirectoryPlugin.php index 5e1388f19f,7ac0f93265..bb4101139f --- a/plugins/Directory/DirectoryPlugin.php +++ b/plugins/Directory/DirectoryPlugin.php @@@ -76,15 -76,44 +76,43 @@@ class DirectoryPlugin extends Plugi * @return boolean hook value; true means continue processing, * false means stop. */ - function onRouterInitialized(URLMapper $m) + public function onRouterInitialized(URLMapper $m) { + $m->connect( + 'directory/users/:filter/sort_by/:sort/reverse/:reverse', + array('action' => 'userdirectory'), - array('filter' => '[0-9a-zA-Z]|(0-9)'), ++ array('filter' => '[0-9a-zA-Z]|(0-9)'), + array('sort' => '[a-z]+'), - array('reverse' => '[0-9]') ++ array('reverse' => '[0-9]') + ); + + $m->connect( + 'directory/users/:filter/sort_by/:sort', + array('action' => 'userdirectory'), - array('filter' => '[0-9a-zA-Z]|(0-9)'), - array('sort' => '[a-z]+') - ); - ++ array('filter' => '[0-9a-zA-Z]|(0-9)'), ++ array('sort' => '[a-z]+') ++ ); + $m->connect( 'directory/users/:filter', array('action' => 'userdirectory'), array('filter' => '[0-9a-zA-Z]|(0-9)') ); - + + $m->connect( + 'directory/users/sort_by/:sort/reverse/:reverse', + array('action' => 'userdirectory'), + array('sort' => '[a-z]+'), - array('reverse' => '[0-9]') ++ array('reverse' => '[0-9]') + ); + + $m->connect( + 'directory/users/sort_by/:sort', + array('action' => 'userdirectory'), - array('sort' => '[a-z]+') - ); ++ array('sort' => '[a-z]+') ++ ); + $m->connect( 'directory/users', array('action' => 'userdirectory') @@@ -101,6 -130,12 +129,11 @@@ array('action' => 'groupdirectory') ); + $m->connect( + 'groups/all', + array('action' => 'groupdirectory') + ); + - return true; }