diff --git a/EVENTS.txt b/EVENTS.txt index 6719ba737a..f675c199a0 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -1057,3 +1057,43 @@ StartCloseNoticeListItemElement: Before the closing of a notice list eleme EndCloseNoticeListItemElement: After the closing of a notice list element - $nli: The notice list item being shown + +StartGroupEditFormData: Beginning the group edit form entries +- $form: The form widget being shown + +EndGroupEditFormData: Ending the group edit form entries +- $form: The form widget being shown + +StartGroupSave: After initializing but before saving a group +- &$group: group about to be saved + +EndGroupSave: After saving a group, aliases, and first member +- $group: group that was saved + +StartInterpretCommand: Before running a command +- $cmd: First word in the string, 'foo' in 'foo argument' +- $arg: Argument, if any, like 'argument' in 'foo argument' +- $user: User who issued the command +- &$result: Resulting command; you can set this! + +EndInterpretCommand: Before running a command +- $cmd: First word in the string, 'foo' in 'foo argument' +- $arg: Argument, if any, like 'argument' in 'foo argument' +- $user: User who issued the command +- $result: Resulting command + +StartGroupActionsList: Start the list of actions on a group profile page (after , after last ) +- $action: action being executed (for output and params) +- $group: group for the page + +StartGroupProfileElements: Start showing stuff about the group on its profile page +- $action: action being executed (for output and params) +- $group: group for the page + +EndGroupProfileElements: Start showing stuff about the group on its profile page +- $action: action being executed (for output and params) +- $group: group for the page diff --git a/README b/README index d972bf5676..f290ef4244 100644 --- a/README +++ b/README @@ -1279,7 +1279,7 @@ biolimit: max character length of bio; 0 means no limit; null means to use backup: whether users can backup their own profiles. Defaults to true. restore: whether users can restore their profiles from backup files. Defaults to true. -delete: whether users can delete their own accounts. Defaults to true. +delete: whether users can delete their own accounts. Defaults to false. move: whether users can move their accounts to another server. Defaults to true. @@ -1572,6 +1572,23 @@ proxy_user: Username to use for authenticating to the HTTP proxy. Default null. proxy_password: Password to use for authenticating to the HTTP proxy. Default null. proxy_auth_scheme: Scheme to use for authenticating to the HTTP proxy. Default null. +plugins +------- + +default: associative array mapping plugin name to array of arguments. To disable + a default plugin, unset its value in this array. +locale_path: path for finding plugin locale files. In the plugin's directory + by default. +server: Server to find static files for a plugin when the page is plain old HTTP. + Defaults to site/server (same as pages). Use this to move plugin CSS and + JS files to a CDN. +sslserver: Server to find static files for a plugin when the page is HTTPS. Defaults + to site/server (same as pages). Use this to move plugin CSS and JS files + to a CDN. +path: Path to the plugin files. defaults to site/path + '/plugins/'. Expects that + each plugin will have a subdirectory at plugins/NameOfPlugin. Change this + if you're using a CDN. + Plugins ======= diff --git a/actions/editgroup.php b/actions/editgroup.php index ab4dbb2836..0e04170051 100644 --- a/actions/editgroup.php +++ b/actions/editgroup.php @@ -177,116 +177,121 @@ class EditgroupAction extends GroupDesignAction return; } - $nickname = Nickname::normalize($this->trimmed('nickname')); - $fullname = $this->trimmed('fullname'); - $homepage = $this->trimmed('homepage'); - $description = $this->trimmed('description'); - $location = $this->trimmed('location'); - $aliasstring = $this->trimmed('aliases'); + if (Event::handle('StartGroupSaveForm', array($this))) { - if ($this->nicknameExists($nickname)) { - // TRANS: Group edit form validation error. - $this->showForm(_('Nickname already in use. Try another one.')); - return; - } else if (!User_group::allowedNickname($nickname)) { - // TRANS: Group edit form validation error. - $this->showForm(_('Not a valid nickname.')); - return; - } else if (!is_null($homepage) && (strlen($homepage) > 0) && - !Validate::uri($homepage, - array('allowed_schemes' => - array('http', 'https')))) { - // TRANS: Group edit form validation error. - $this->showForm(_('Homepage is not a valid URL.')); - return; - } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { - // TRANS: Group edit form validation error. - $this->showForm(_('Full name is too long (maximum 255 characters).')); - return; - } else if (User_group::descriptionTooLong($description)) { - $this->showForm(sprintf( + $nickname = Nickname::normalize($this->trimmed('nickname')); + $fullname = $this->trimmed('fullname'); + $homepage = $this->trimmed('homepage'); + $description = $this->trimmed('description'); + $location = $this->trimmed('location'); + $aliasstring = $this->trimmed('aliases'); + + if ($this->nicknameExists($nickname)) { // TRANS: Group edit form validation error. - _m('Description is too long (maximum %d character).', - 'Description is too long (maximum %d characters).', - User_group::maxDescription()), + $this->showForm(_('Nickname already in use. Try another one.')); + return; + } else if (!User_group::allowedNickname($nickname)) { + // TRANS: Group edit form validation error. + $this->showForm(_('Not a valid nickname.')); + return; + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, + array('allowed_schemes' => + array('http', 'https')))) { + // TRANS: Group edit form validation error. + $this->showForm(_('Homepage is not a valid URL.')); + return; + } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { + // TRANS: Group edit form validation error. + $this->showForm(_('Full name is too long (maximum 255 characters).')); + return; + } else if (User_group::descriptionTooLong($description)) { + $this->showForm(sprintf( + // TRANS: Group edit form validation error. + _m('Description is too long (maximum %d character).', + 'Description is too long (maximum %d characters).', + User_group::maxDescription()), User_group::maxDescription())); - return; - } else if (!is_null($location) && mb_strlen($location) > 255) { - // TRANS: Group edit form validation error. - $this->showForm(_('Location is too long (maximum 255 characters).')); - return; - } - - if (!empty($aliasstring)) { - $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\s,]+/', $aliasstring))); - } else { - $aliases = array(); - } - - if (count($aliases) > common_config('group', 'maxaliases')) { - // TRANS: Group edit form validation error. - // TRANS: %d is the maximum number of allowed aliases. - $this->showForm(sprintf(_m('Too many aliases! Maximum %d allowed.', - 'Too many aliases! Maximum %d allowed.', - common_config('group', 'maxaliases')), - common_config('group', 'maxaliases'))); - return; - } - - foreach ($aliases as $alias) { - if (!Nickname::isValid($alias)) { + return; + } else if (!is_null($location) && mb_strlen($location) > 255) { // TRANS: Group edit form validation error. - $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias)); + $this->showForm(_('Location is too long (maximum 255 characters).')); return; } - if ($this->nicknameExists($alias)) { + + if (!empty($aliasstring)) { + $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\s,]+/', $aliasstring))); + } else { + $aliases = array(); + } + + if (count($aliases) > common_config('group', 'maxaliases')) { // TRANS: Group edit form validation error. - $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), - $alias)); + // TRANS: %d is the maximum number of allowed aliases. + $this->showForm(sprintf(_m('Too many aliases! Maximum %d allowed.', + 'Too many aliases! Maximum %d allowed.', + common_config('group', 'maxaliases')), + common_config('group', 'maxaliases'))); return; } - // XXX assumes alphanum nicknames - if (strcmp($alias, $nickname) == 0) { - // TRANS: Group edit form validation error. - $this->showForm(_('Alias can\'t be the same as nickname.')); - return; + + foreach ($aliases as $alias) { + if (!Nickname::isValid($alias)) { + // TRANS: Group edit form validation error. + $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias)); + return; + } + if ($this->nicknameExists($alias)) { + // TRANS: Group edit form validation error. + $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), + $alias)); + return; + } + // XXX assumes alphanum nicknames + if (strcmp($alias, $nickname) == 0) { + // TRANS: Group edit form validation error. + $this->showForm(_('Alias can\'t be the same as nickname.')); + return; + } } + + $this->group->query('BEGIN'); + + $orig = clone($this->group); + + $this->group->nickname = $nickname; + $this->group->fullname = $fullname; + $this->group->homepage = $homepage; + $this->group->description = $description; + $this->group->location = $location; + $this->group->mainpage = common_local_url('showgroup', array('nickname' => $nickname)); + + $result = $this->group->update($orig); + + if (!$result) { + common_log_db_error($this->group, 'UPDATE', __FILE__); + // TRANS: Server error displayed when editing a group fails. + $this->serverError(_('Could not update group.')); + } + + $result = $this->group->setAliases($aliases); + + if (!$result) { + // TRANS: Server error displayed when group aliases could not be added. + $this->serverError(_('Could not create aliases.')); + } + + if ($nickname != $orig->nickname) { + common_log(LOG_INFO, "Saving local group info."); + $local = Local_group::staticGet('group_id', $this->group->id); + $local->setNickname($nickname); + } + + $this->group->query('COMMIT'); + + Event::handle('EndGroupSaveForm', array($this)); } - $this->group->query('BEGIN'); - - $orig = clone($this->group); - - $this->group->nickname = $nickname; - $this->group->fullname = $fullname; - $this->group->homepage = $homepage; - $this->group->description = $description; - $this->group->location = $location; - $this->group->mainpage = common_local_url('showgroup', array('nickname' => $nickname)); - - $result = $this->group->update($orig); - - if (!$result) { - common_log_db_error($this->group, 'UPDATE', __FILE__); - // TRANS: Server error displayed when editing a group fails. - $this->serverError(_('Could not update group.')); - } - - $result = $this->group->setAliases($aliases); - - if (!$result) { - // TRANS: Server error displayed when group aliases could not be added. - $this->serverError(_('Could not create aliases.')); - } - - if ($nickname != $orig->nickname) { - common_log(LOG_INFO, "Saving local group info."); - $local = Local_group::staticGet('group_id', $this->group->id); - $local->setNickname($nickname); - } - - $this->group->query('COMMIT'); - if ($this->group->nickname != $orig->nickname) { common_redirect(common_local_url('editgroup', array('nickname' => $nickname)), diff --git a/actions/inbox.php b/actions/inbox.php index 3a50f4964f..6ab58f9751 100644 --- a/actions/inbox.php +++ b/actions/inbox.php @@ -90,18 +90,9 @@ class InboxAction extends MailboxAction } } - /** - * Returns the profile we want to show with the message - * - * For inboxes, we show the sender; for outboxes, the recipient. - * - * @param Message $message The message to get the profile for - * - * @return Profile The profile that matches the message - */ - function getMessageProfile($message) + function getMessageList($message) { - return $message->getFrom(); + return new InboxMessageList($this, $message); } /** @@ -115,3 +106,24 @@ class InboxAction extends MailboxAction return _('This is your inbox, which lists your incoming private messages.'); } } + +class InboxMessageList extends MessageList +{ + function newItem($message) + { + return new InboxMessageListItem($this->out, $message); + } +} + +class InboxMessageListItem extends MessageListItem +{ + /** + * Returns the profile we want to show with the message + * + * @return Profile The profile that matches the message + */ + function getMessageProfile() + { + return $this->message->getFrom(); + } +} \ No newline at end of file diff --git a/actions/newgroup.php b/actions/newgroup.php index 53c95d03f0..9682b875cb 100644 --- a/actions/newgroup.php +++ b/actions/newgroup.php @@ -120,103 +120,109 @@ class NewgroupAction extends Action function trySave() { - try { - $nickname = Nickname::normalize($this->trimmed('nickname')); - } catch (NicknameException $e) { - $this->showForm($e->getMessage()); - } - $fullname = $this->trimmed('fullname'); - $homepage = $this->trimmed('homepage'); - $description = $this->trimmed('description'); - $location = $this->trimmed('location'); - $aliasstring = $this->trimmed('aliases'); + if (Event::handle('StartGroupSaveForm', array($this))) { + try { + $nickname = Nickname::normalize($this->trimmed('nickname')); + } catch (NicknameException $e) { + $this->showForm($e->getMessage()); + } + $fullname = $this->trimmed('fullname'); + $homepage = $this->trimmed('homepage'); + $description = $this->trimmed('description'); + $location = $this->trimmed('location'); + $aliasstring = $this->trimmed('aliases'); - if ($this->nicknameExists($nickname)) { - // TRANS: Group create form validation error. - $this->showForm(_('Nickname already in use. Try another one.')); - return; - } else if (!User_group::allowedNickname($nickname)) { - // TRANS: Group create form validation error. - $this->showForm(_('Not a valid nickname.')); - return; - } else if (!is_null($homepage) && (strlen($homepage) > 0) && - !Validate::uri($homepage, - array('allowed_schemes' => - array('http', 'https')))) { - // TRANS: Group create form validation error. - $this->showForm(_('Homepage is not a valid URL.')); - return; - } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { - // TRANS: Group create form validation error. - $this->showForm(_('Full name is too long (maximum 255 characters).')); - return; - } else if (User_group::descriptionTooLong($description)) { - // TRANS: Group create form validation error. - // TRANS: %d is the maximum number of allowed characters. - $this->showForm(sprintf(_m('Description is too long (maximum %d character).', - 'Description is too long (maximum %d characters).', - User_group::maxDescription()), - User_group::maxDescription())); - return; - } else if (!is_null($location) && mb_strlen($location) > 255) { - // TRANS: Group create form validation error. - $this->showForm(_('Location is too long (maximum 255 characters).')); - return; - } - - if (!empty($aliasstring)) { - $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\s,]+/', $aliasstring))); - } else { - $aliases = array(); - } - - if (count($aliases) > common_config('group', 'maxaliases')) { - // TRANS: Group create form validation error. - // TRANS: %d is the maximum number of allowed aliases. - $this->showForm(sprintf(_m('Too many aliases! Maximum %d allowed.', - 'Too many aliases! Maximum %d allowed.', - common_config('group', 'maxaliases')), - common_config('group', 'maxaliases'))); - return; - } - - foreach ($aliases as $alias) { - if (!Nickname::isValid($alias)) { + if ($this->nicknameExists($nickname)) { // TRANS: Group create form validation error. - // TRANS: %s is the invalid alias. - $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias)); + $this->showForm(_('Nickname already in use. Try another one.')); return; - } - if ($this->nicknameExists($alias)) { - // TRANS: Group create form validation error. %s is the already used alias. - $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), - $alias)); - return; - } - // XXX assumes alphanum nicknames - if (strcmp($alias, $nickname) == 0) { + } else if (!User_group::allowedNickname($nickname)) { // TRANS: Group create form validation error. - $this->showForm(_('Alias cannot be the same as nickname.')); + $this->showForm(_('Not a valid nickname.')); + return; + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, + array('allowed_schemes' => + array('http', 'https')))) { + // TRANS: Group create form validation error. + $this->showForm(_('Homepage is not a valid URL.')); + return; + } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { + // TRANS: Group create form validation error. + $this->showForm(_('Full name is too long (maximum 255 characters).')); + return; + } else if (User_group::descriptionTooLong($description)) { + // TRANS: Group create form validation error. + // TRANS: %d is the maximum number of allowed characters. + $this->showForm(sprintf(_m('Description is too long (maximum %d character).', + 'Description is too long (maximum %d characters).', + User_group::maxDescription()), + User_group::maxDescription())); + return; + } else if (!is_null($location) && mb_strlen($location) > 255) { + // TRANS: Group create form validation error. + $this->showForm(_('Location is too long (maximum 255 characters).')); return; } + + if (!empty($aliasstring)) { + $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\s,]+/', $aliasstring))); + } else { + $aliases = array(); + } + + if (count($aliases) > common_config('group', 'maxaliases')) { + // TRANS: Group create form validation error. + // TRANS: %d is the maximum number of allowed aliases. + $this->showForm(sprintf(_m('Too many aliases! Maximum %d allowed.', + 'Too many aliases! Maximum %d allowed.', + common_config('group', 'maxaliases')), + common_config('group', 'maxaliases'))); + return; + } + + foreach ($aliases as $alias) { + if (!Nickname::isValid($alias)) { + // TRANS: Group create form validation error. + // TRANS: %s is the invalid alias. + $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias)); + return; + } + if ($this->nicknameExists($alias)) { + // TRANS: Group create form validation error. %s is the already used alias. + $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), + $alias)); + return; + } + // XXX assumes alphanum nicknames + if (strcmp($alias, $nickname) == 0) { + // TRANS: Group create form validation error. + $this->showForm(_('Alias cannot be the same as nickname.')); + return; + } + } + + $cur = common_current_user(); + + // Checked in prepare() above + + assert(!is_null($cur)); + + $group = User_group::register(array('nickname' => $nickname, + 'fullname' => $fullname, + 'homepage' => $homepage, + 'description' => $description, + 'location' => $location, + 'aliases' => $aliases, + 'userid' => $cur->id, + 'local' => true)); + + $this->group = $group; + + Event::handle('EndGroupSaveForm', array($this)); + + common_redirect($group->homeUrl(), 303); } - - $cur = common_current_user(); - - // Checked in prepare() above - - assert(!is_null($cur)); - - $group = User_group::register(array('nickname' => $nickname, - 'fullname' => $fullname, - 'homepage' => $homepage, - 'description' => $description, - 'location' => $location, - 'aliases' => $aliases, - 'userid' => $cur->id, - 'local' => true)); - - common_redirect($group->homeUrl(), 303); } function nicknameExists($nickname) diff --git a/actions/outbox.php b/actions/outbox.php index b81d4b9d0d..cad19bba24 100644 --- a/actions/outbox.php +++ b/actions/outbox.php @@ -88,21 +88,9 @@ class OutboxAction extends MailboxAction } } - /** - * returns the profile we want to show with the message - * - * For outboxes, we show the recipient. - * - * @param Message $message The message to get the profile for - * - * @return Profile The profile of the message recipient - * - * @see MailboxAction::getMessageProfile() - */ - - function getMessageProfile($message) + function getMessageList($message) { - return $message->getTo(); + return new OutboxMessageList($this, $message); } /** @@ -116,3 +104,24 @@ class OutboxAction extends MailboxAction return _('This is your outbox, which lists private messages you have sent.'); } } + +class OutboxMessageList extends MessageList +{ + function newItem($message) + { + return new OutboxMessageListItem($this->out, $message); + } +} + +class OutboxMessageListItem extends MessageListItem +{ + /** + * Returns the profile we want to show with the message + * + * @return Profile The profile that matches the message + */ + function getMessageProfile() + { + return $this->message->getTo(); + } +} \ No newline at end of file diff --git a/actions/showgroup.php b/actions/showgroup.php index f38cd420ac..2806944452 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -181,6 +181,7 @@ class ShowgroupAction extends GroupDesignAction function showContent() { $this->showGroupProfile(); + $this->showGroupActions(); $this->showGroupNotices(); } @@ -216,112 +217,123 @@ class ShowgroupAction extends GroupDesignAction $this->elementStart('div', array('id' => 'i', 'class' => 'entity_profile vcard author')); - // TRANS: Group profile header (h2). Text hidden by default. - $this->element('h2', null, _('Group profile')); + if (Event::handle('StartGroupProfileElements', array($this, $this->group))) { - $this->elementStart('dl', 'entity_depiction'); - // TRANS: Label for group avatar (dt). Text hidden by default. - $this->element('dt', null, _('Avatar')); - $this->elementStart('dd'); + // TRANS: Group profile header (h2). Text hidden by default. + $this->element('h2', null, _('Group profile')); - $logo = ($this->group->homepage_logo) ? - $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE); - - $this->element('img', array('src' => $logo, - 'class' => 'photo avatar', - 'width' => AVATAR_PROFILE_SIZE, - 'height' => AVATAR_PROFILE_SIZE, - 'alt' => $this->group->nickname)); - $this->elementEnd('dd'); - $this->elementEnd('dl'); - - $this->elementStart('dl', 'entity_nickname'); - // TRANS: Label for group nickname (dt). Text hidden by default. - $this->element('dt', null, _('Nickname')); - $this->elementStart('dd'); - $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid'; - $this->element('a', array('href' => $this->group->homeUrl(), - 'rel' => 'me', 'class' => $hasFN), - $this->group->nickname); - $this->elementEnd('dd'); - $this->elementEnd('dl'); - - if ($this->group->fullname) { - $this->elementStart('dl', 'entity_fn'); - // TRANS: Label for full group name (dt). Text hidden by default. - $this->element('dt', null, _('Full name')); + $this->elementStart('dl', 'entity_depiction'); + // TRANS: Label for group avatar (dt). Text hidden by default. + $this->element('dt', null, _('Avatar')); $this->elementStart('dd'); - $this->element('span', 'fn org', $this->group->fullname); + + $logo = ($this->group->homepage_logo) ? + $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE); + + $this->element('img', array('src' => $logo, + 'class' => 'photo avatar', + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $this->group->nickname)); $this->elementEnd('dd'); $this->elementEnd('dl'); - } - if ($this->group->location) { - $this->elementStart('dl', 'entity_location'); - // TRANS: Label for group location (dt). Text hidden by default. - $this->element('dt', null, _('Location')); - $this->element('dd', 'label', $this->group->location); - $this->elementEnd('dl'); - } - - if ($this->group->homepage) { - $this->elementStart('dl', 'entity_url'); - // TRANS: Label for group URL (dt). Text hidden by default. - $this->element('dt', null, _('URL')); + $this->elementStart('dl', 'entity_nickname'); + // TRANS: Label for group nickname (dt). Text hidden by default. + $this->element('dt', null, _('Nickname')); $this->elementStart('dd'); - $this->element('a', array('href' => $this->group->homepage, - 'rel' => 'me', 'class' => 'url'), - $this->group->homepage); + $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid'; + $this->element('a', array('href' => $this->group->homeUrl(), + 'rel' => 'me', 'class' => $hasFN), + $this->group->nickname); $this->elementEnd('dd'); $this->elementEnd('dl'); - } - if ($this->group->description) { - $this->elementStart('dl', 'entity_note'); - // TRANS: Label for group description or group note (dt). Text hidden by default. - $this->element('dt', null, _('Note')); - $this->element('dd', 'note', $this->group->description); - $this->elementEnd('dl'); - } - - if (common_config('group', 'maxaliases') > 0) { - $aliases = $this->group->getAliases(); - - if (!empty($aliases)) { - $this->elementStart('dl', 'entity_aliases'); - // TRANS: Label for group aliases (dt). Text hidden by default. - $this->element('dt', null, _('Aliases')); - $this->element('dd', 'aliases', implode(' ', $aliases)); + if ($this->group->fullname) { + $this->elementStart('dl', 'entity_fn'); + // TRANS: Label for full group name (dt). Text hidden by default. + $this->element('dt', null, _('Full name')); + $this->elementStart('dd'); + $this->element('span', 'fn org', $this->group->fullname); + $this->elementEnd('dd'); $this->elementEnd('dl'); } + + if ($this->group->location) { + $this->elementStart('dl', 'entity_location'); + // TRANS: Label for group location (dt). Text hidden by default. + $this->element('dt', null, _('Location')); + $this->element('dd', 'label', $this->group->location); + $this->elementEnd('dl'); + } + + if ($this->group->homepage) { + $this->elementStart('dl', 'entity_url'); + // TRANS: Label for group URL (dt). Text hidden by default. + $this->element('dt', null, _('URL')); + $this->elementStart('dd'); + $this->element('a', array('href' => $this->group->homepage, + 'rel' => 'me', 'class' => 'url'), + $this->group->homepage); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + + if ($this->group->description) { + $this->elementStart('dl', 'entity_note'); + // TRANS: Label for group description or group note (dt). Text hidden by default. + $this->element('dt', null, _('Note')); + $this->element('dd', 'note', $this->group->description); + $this->elementEnd('dl'); + } + + if (common_config('group', 'maxaliases') > 0) { + $aliases = $this->group->getAliases(); + + if (!empty($aliases)) { + $this->elementStart('dl', 'entity_aliases'); + // TRANS: Label for group aliases (dt). Text hidden by default. + $this->element('dt', null, _('Aliases')); + $this->element('dd', 'aliases', implode(' ', $aliases)); + $this->elementEnd('dl'); + } + } + + Event::handle('EndGroupProfileElements', array($this, $this->group)); } $this->elementEnd('div'); + } + function showGroupActions() + { $cur = common_current_user(); $this->elementStart('div', 'entity_actions'); // TRANS: Group actions header (h2). Text hidden by default. $this->element('h2', null, _('Group actions')); $this->elementStart('ul'); - $this->elementStart('li', 'entity_subscribe'); - if (Event::handle('StartGroupSubscribe', array($this, $this->group))) { - if ($cur) { - if ($cur->isMember($this->group)) { - $lf = new LeaveForm($this, $this->group); - $lf->show(); - } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) { - $jf = new JoinForm($this, $this->group); - $jf->show(); + if (Event::handle('StartGroupActionsList', array($this, $this->group))) { + $this->elementStart('li', 'entity_subscribe'); + if (Event::handle('StartGroupSubscribe', array($this, $this->group))) { + if ($cur) { + if ($cur->isMember($this->group)) { + $lf = new LeaveForm($this, $this->group); + $lf->show(); + } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) { + $jf = new JoinForm($this, $this->group); + $jf->show(); + } } + Event::handle('EndGroupSubscribe', array($this, $this->group)); } - Event::handle('EndGroupSubscribe', array($this, $this->group)); - } - $this->elementEnd('li'); - if ($cur && $cur->hasRight(Right::DELETEGROUP)) { - $this->elementStart('li', 'entity_delete'); - $df = new DeleteGroupForm($this, $this->group); - $df->show(); $this->elementEnd('li'); + if ($cur && $cur->hasRight(Right::DELETEGROUP)) { + $this->elementStart('li', 'entity_delete'); + $df = new DeleteGroupForm($this, $this->group); + $df->show(); + $this->elementEnd('li'); + } + Event::handle('EndGroupActionsList', array($this, $this->group)); } $this->elementEnd('ul'); $this->elementEnd('div'); diff --git a/actions/showmessage.php b/actions/showmessage.php index d737f85d3a..1c867af119 100644 --- a/actions/showmessage.php +++ b/actions/showmessage.php @@ -30,20 +30,17 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/lib/mailbox.php'; - /** * Show a single message * - * // XXX: It is totally weird how this works! - * * @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 MailboxAction + +class ShowmessageAction extends Action { /** * Message object to show @@ -82,22 +79,20 @@ class ShowmessageAction extends MailboxAction $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) { - Action::handle($args); - - if ($this->user && ($this->user->id == $this->message->from_profile || - $this->user->id == $this->message->to_profile)) { - $this->showPage(); - } else { - // TRANS: Client error displayed requesting a single direct message the requesting user was not a party in. - $this->clientError(_('Only the sender and recipient ' . - 'may read this message.'), 403); - return; - } + $this->showPage(); } function title() @@ -121,12 +116,38 @@ class ShowmessageAction extends MailboxAction } } - function getMessages() + + function showContent() { - $message = new Message(); - $message->id = $this->message->id; - $message->find(); - return $message; + $this->elementStart('ul', 'notices messages'); + $ml = new ShowMessageListItem($this, $this->message, $this->user); + $ml->show(); + $this->elementEnd('ul'); + } + + function isReadOnly($args) + { + 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() @@ -140,46 +161,4 @@ class ShowmessageAction extends MailboxAction return null; } } - - /** - * Don't show local navigation - * - * @return void - */ - function showLocalNavBlock() - { - } - - /** - * Don't show page notice - * - * @return void - */ - function showPageNoticeBlock() - { - } - - /** - * Don't show aside - * - * @return void - */ - function showAside() - { - } - - /** - * Don't show any instructions - * - * @return string - */ - function getInstructions() - { - return ''; - } - - function isReadOnly($args) - { - return true; - } } diff --git a/classes/File.php b/classes/File.php index 29a8f0f1c5..e9a0131c4e 100644 --- a/classes/File.php +++ b/classes/File.php @@ -55,14 +55,20 @@ class File extends Memcached_DataObject return 'http://www.facebook.com/login.php' === $url; } - function getAttachments($post_id) { - $query = "select file.* from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $this->escape($post_id); - $this->query($query); + /** + * Get the attachments for a particlar notice. + * + * @param int $post_id + * @return array of File objects + */ + static function getAttachments($post_id) { + $file = new File(); + $query = "select file.* from file join file_to_post on (file_id = file.id) where post_id = " . $file->escape($post_id); + $file = Memcached_DataObject::cachedQuery('File', $query); $att = array(); - while ($this->fetch()) { - $att[] = clone($this); + while ($file->fetch()) { + $att[] = clone($file); } - $this->free(); return $att; } diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index a3c2de8e64..867b40cf3c 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -340,6 +340,7 @@ class Memcached_DataObject extends Safe_DataObject $start = microtime(true); $result = null; if (Event::handle('StartDBQuery', array($this, $string, &$result))) { + common_perf_counter('query', $string); $result = parent::_query($string); Event::handle('EndDBQuery', array($this, $string, &$result)); } diff --git a/classes/Notice.php b/classes/Notice.php index e9ea479e14..4522d1fc38 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -446,7 +446,10 @@ class Notice extends Memcached_DataObject function blowOnInsert($conversation = false) { self::blow('profile:notice_ids:%d', $this->profile_id); - self::blow('public'); + + if ($this->isPublic()) { + self::blow('public'); + } // XXX: Before we were blowing the casche only if the notice id // was not the root of the conversation. What to do now? @@ -481,7 +484,10 @@ class Notice extends Memcached_DataObject $this->blowOnInsert(); self::blow('profile:notice_ids:%d;last', $this->profile_id); - self::blow('public;last'); + + if ($this->isPublic()) { + self::blow('public;last'); + } } /** save all urls in the notice to the db @@ -958,7 +964,7 @@ class Notice extends Memcached_DataObject $groups = array(); /* extract all !group */ - $count = preg_match_all('/(?:^|\s)!([A-Za-z0-9]{1,64})/', + $count = preg_match_all('/(?:^|\s)!(' . Nickname::DISPLAY_FMT . ')/', strtolower($this->content), $match); if (!$count) { @@ -2107,4 +2113,14 @@ class Notice extends Memcached_DataObject $obj->whereAdd($max); } } + + function isPublic() + { + if (common_config('public', 'localonly')) { + return ($this->is_local == Notice::LOCAL_PUBLIC); + } else { + return (($this->is_local != Notice::LOCAL_NONPUBLIC) && + ($this->is_local != Notice::GATEWAY)); + } + } } diff --git a/classes/Profile.php b/classes/Profile.php index adad0c6157..03f9300962 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -918,6 +918,31 @@ class Profile extends Memcached_DataObject return $xs->getString(); } + /** + * Extra profile info for atom entries + * + * Clients use some extra profile info in the atom stream. + * This gives it to them. + * + * @param User $cur Current user + * + * @return array representation of element + */ + + function profileInfo($cur) + { + $profileInfoAttr = array(); + + if ($cur != null) { + // Whether the current user is a subscribed to this profile + $profileInfoAttr['following'] = $cur->isSubscribed($this) ? 'true' : 'false'; + // Whether the current user is has blocked this profile + $profileInfoAttr['blocking'] = $cur->hasBlocked($this) ? 'true' : 'false'; + } + + return array('statusnet:profile_info', $profileInfoAttr, null); + } + /** * Returns an XML string fragment with profile information as an * Activity Streams element. diff --git a/classes/Session.php b/classes/Session.php index e1c83ad4dc..166b89815a 100644 --- a/classes/Session.php +++ b/classes/Session.php @@ -156,6 +156,13 @@ class Session extends Memcached_DataObject $session->selectAdd(); $session->selectAdd('id'); + $limit = common_config('sessions', 'gc_limit'); + if ($limit > 0) { + // On large sites, too many sessions to expire + // at once will just result in failure. + $session->limit($limit); + } + $session->find(); while ($session->fetch()) { diff --git a/classes/User_group.php b/classes/User_group.php index d402ed4773..5a9991fe9e 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -512,64 +512,70 @@ class User_group extends Memcached_DataObject $group->mainpage = $mainpage; $group->created = common_sql_now(); - $result = $group->insert(); + if (Event::handle('StartGroupSave', array(&$group))) { - if (!$result) { - common_log_db_error($group, 'INSERT', __FILE__); - // TRANS: Server exception thrown when creating a group failed. - throw new ServerException(_('Could not create group.')); - } - - if (!isset($uri) || empty($uri)) { - $orig = clone($group); - $group->uri = common_local_url('groupbyid', array('id' => $group->id)); - $result = $group->update($orig); - if (!$result) { - common_log_db_error($group, 'UPDATE', __FILE__); - // TRANS: Server exception thrown when updating a group URI failed. - throw new ServerException(_('Could not set group URI.')); - } - } - - $result = $group->setAliases($aliases); - - if (!$result) { - // TRANS: Server exception thrown when creating group aliases failed. - throw new ServerException(_('Could not create aliases.')); - } - - $member = new Group_member(); - - $member->group_id = $group->id; - $member->profile_id = $userid; - $member->is_admin = 1; - $member->created = $group->created; - - $result = $member->insert(); - - if (!$result) { - common_log_db_error($member, 'INSERT', __FILE__); - // TRANS: Server exception thrown when setting group membership failed. - throw new ServerException(_('Could not set group membership.')); - } - - if ($local) { - $local_group = new Local_group(); - - $local_group->group_id = $group->id; - $local_group->nickname = $nickname; - $local_group->created = common_sql_now(); - - $result = $local_group->insert(); + $result = $group->insert(); if (!$result) { - common_log_db_error($local_group, 'INSERT', __FILE__); - // TRANS: Server exception thrown when saving local group information failed. - throw new ServerException(_('Could not save local group info.')); + common_log_db_error($group, 'INSERT', __FILE__); + // TRANS: Server exception thrown when creating a group failed. + throw new ServerException(_('Could not create group.')); } + + if (!isset($uri) || empty($uri)) { + $orig = clone($group); + $group->uri = common_local_url('groupbyid', array('id' => $group->id)); + $result = $group->update($orig); + if (!$result) { + common_log_db_error($group, 'UPDATE', __FILE__); + // TRANS: Server exception thrown when updating a group URI failed. + throw new ServerException(_('Could not set group URI.')); + } + } + + $result = $group->setAliases($aliases); + + if (!$result) { + // TRANS: Server exception thrown when creating group aliases failed. + throw new ServerException(_('Could not create aliases.')); + } + + $member = new Group_member(); + + $member->group_id = $group->id; + $member->profile_id = $userid; + $member->is_admin = 1; + $member->created = $group->created; + + $result = $member->insert(); + + if (!$result) { + common_log_db_error($member, 'INSERT', __FILE__); + // TRANS: Server exception thrown when setting group membership failed. + throw new ServerException(_('Could not set group membership.')); + } + + if ($local) { + $local_group = new Local_group(); + + $local_group->group_id = $group->id; + $local_group->nickname = $nickname; + $local_group->created = common_sql_now(); + + $result = $local_group->insert(); + + if (!$result) { + common_log_db_error($local_group, 'INSERT', __FILE__); + // TRANS: Server exception thrown when saving local group information failed. + throw new ServerException(_('Could not save local group info.')); + } + } + + $group->query('COMMIT'); + + Event::handle('EndGroupSave', array($group)); } - $group->query('COMMIT'); return $group; } diff --git a/extlib/Auth/SASL.php b/extlib/Auth/SASL.php new file mode 100644 index 0000000000..e70f0146bc --- /dev/null +++ b/extlib/Auth/SASL.php @@ -0,0 +1,104 @@ + | +// +-----------------------------------------------------------------------+ +// +// $Id: SASL.php 286825 2009-08-05 06:23:42Z cweiske $ + +/** +* Client implementation of various SASL mechanisms +* +* @author Richard Heyes +* @access public +* @version 1.0 +* @package Auth_SASL +*/ + +require_once('PEAR.php'); + +class Auth_SASL +{ + /** + * Factory class. Returns an object of the request + * type. + * + * @param string $type One of: Anonymous + * Plain + * CramMD5 + * DigestMD5 + * Types are not case sensitive + */ + function &factory($type) + { + switch (strtolower($type)) { + case 'anonymous': + $filename = 'Auth/SASL/Anonymous.php'; + $classname = 'Auth_SASL_Anonymous'; + break; + + case 'login': + $filename = 'Auth/SASL/Login.php'; + $classname = 'Auth_SASL_Login'; + break; + + case 'plain': + $filename = 'Auth/SASL/Plain.php'; + $classname = 'Auth_SASL_Plain'; + break; + + case 'external': + $filename = 'Auth/SASL/External.php'; + $classname = 'Auth_SASL_External'; + break; + + case 'crammd5': + $filename = 'Auth/SASL/CramMD5.php'; + $classname = 'Auth_SASL_CramMD5'; + break; + + case 'digestmd5': + $filename = 'Auth/SASL/DigestMD5.php'; + $classname = 'Auth_SASL_DigestMD5'; + break; + + default: + return PEAR::raiseError('Invalid SASL mechanism type'); + break; + } + + require_once($filename); + $obj = new $classname(); + return $obj; + } +} + +?> diff --git a/extlib/Auth/SASL/Anonymous.php b/extlib/Auth/SASL/Anonymous.php new file mode 100644 index 0000000000..4eaaa399e6 --- /dev/null +++ b/extlib/Auth/SASL/Anonymous.php @@ -0,0 +1,71 @@ + | +// +-----------------------------------------------------------------------+ +// +// $Id: Anonymous.php 286825 2009-08-05 06:23:42Z cweiske $ + +/** +* Implmentation of ANONYMOUS SASL mechanism +* +* @author Richard Heyes +* @access public +* @version 1.0 +* @package Auth_SASL +*/ + +require_once('Auth/SASL/Common.php'); + +class Auth_SASL_Anonymous extends Auth_SASL_Common +{ + /** + * Not much to do here except return the token supplied. + * No encoding, hashing or encryption takes place for this + * mechanism, simply one of: + * o An email address + * o An opaque string not containing "@" that can be interpreted + * by the sysadmin + * o Nothing + * + * We could have some logic here for the second option, but this + * would by no means create something interpretable. + * + * @param string $token Optional email address or string to provide + * as trace information. + * @return string The unaltered input token + */ + function getResponse($token = '') + { + return $token; + } +} +?> \ No newline at end of file diff --git a/extlib/Auth/SASL/Common.php b/extlib/Auth/SASL/Common.php new file mode 100644 index 0000000000..44181645c4 --- /dev/null +++ b/extlib/Auth/SASL/Common.php @@ -0,0 +1,74 @@ + | +// +-----------------------------------------------------------------------+ +// +// $Id: Common.php 286825 2009-08-05 06:23:42Z cweiske $ + +/** +* Common functionality to SASL mechanisms +* +* @author Richard Heyes +* @access public +* @version 1.0 +* @package Auth_SASL +*/ + +class Auth_SASL_Common +{ + /** + * Function which implements HMAC MD5 digest + * + * @param string $key The secret key + * @param string $data The data to protect + * @return string The HMAC MD5 digest + */ + function _HMAC_MD5($key, $data) + { + if (strlen($key) > 64) { + $key = pack('H32', md5($key)); + } + + if (strlen($key) < 64) { + $key = str_pad($key, 64, chr(0)); + } + + $k_ipad = substr($key, 0, 64) ^ str_repeat(chr(0x36), 64); + $k_opad = substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64); + + $inner = pack('H32', md5($k_ipad . $data)); + $digest = md5($k_opad . $inner); + + return $digest; + } +} +?> diff --git a/extlib/Auth/SASL/CramMD5.php b/extlib/Auth/SASL/CramMD5.php new file mode 100644 index 0000000000..177279c06b --- /dev/null +++ b/extlib/Auth/SASL/CramMD5.php @@ -0,0 +1,68 @@ + | +// +-----------------------------------------------------------------------+ +// +// $Id: CramMD5.php 286825 2009-08-05 06:23:42Z cweiske $ + +/** +* Implmentation of CRAM-MD5 SASL mechanism +* +* @author Richard Heyes +* @access public +* @version 1.0 +* @package Auth_SASL +*/ + +require_once('Auth/SASL/Common.php'); + +class Auth_SASL_CramMD5 extends Auth_SASL_Common +{ + /** + * Implements the CRAM-MD5 SASL mechanism + * This DOES NOT base64 encode the return value, + * you will need to do that yourself. + * + * @param string $user Username + * @param string $pass Password + * @param string $challenge The challenge supplied by the server. + * this should be already base64_decoded. + * + * @return string The string to pass back to the server, of the form + * " ". This is NOT base64_encoded. + */ + function getResponse($user, $pass, $challenge) + { + return $user . ' ' . $this->_HMAC_MD5($pass, $challenge); + } +} +?> \ No newline at end of file diff --git a/extlib/Auth/SASL/DigestMD5.php b/extlib/Auth/SASL/DigestMD5.php new file mode 100644 index 0000000000..8c58787dfe --- /dev/null +++ b/extlib/Auth/SASL/DigestMD5.php @@ -0,0 +1,197 @@ + | +// +-----------------------------------------------------------------------+ +// +// $Id: DigestMD5.php 294702 2010-02-07 16:03:55Z cweiske $ + +/** +* Implmentation of DIGEST-MD5 SASL mechanism +* +* @author Richard Heyes +* @access public +* @version 1.0 +* @package Auth_SASL +*/ + +require_once('Auth/SASL/Common.php'); + +class Auth_SASL_DigestMD5 extends Auth_SASL_Common +{ + /** + * Provides the (main) client response for DIGEST-MD5 + * requires a few extra parameters than the other + * mechanisms, which are unavoidable. + * + * @param string $authcid Authentication id (username) + * @param string $pass Password + * @param string $challenge The digest challenge sent by the server + * @param string $hostname The hostname of the machine you're connecting to + * @param string $service The servicename (eg. imap, pop, acap etc) + * @param string $authzid Authorization id (username to proxy as) + * @return string The digest response (NOT base64 encoded) + * @access public + */ + function getResponse($authcid, $pass, $challenge, $hostname, $service, $authzid = '') + { + $challenge = $this->_parseChallenge($challenge); + $authzid_string = ''; + if ($authzid != '') { + $authzid_string = ',authzid="' . $authzid . '"'; + } + + if (!empty($challenge)) { + $cnonce = $this->_getCnonce(); + $digest_uri = sprintf('%s/%s', $service, $hostname); + $response_value = $this->_getResponseValue($authcid, $pass, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $authzid); + + if ($challenge['realm']) { + return sprintf('username="%s",realm="%s"' . $authzid_string . +',nonce="%s",cnonce="%s",nc=00000001,qop=auth,digest-uri="%s",response=%s,maxbuf=%d', $authcid, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']); + } else { + return sprintf('username="%s"' . $authzid_string . ',nonce="%s",cnonce="%s",nc=00000001,qop=auth,digest-uri="%s",response=%s,maxbuf=%d', $authcid, $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']); + } + } else { + return PEAR::raiseError('Invalid digest challenge'); + } + } + + /** + * Parses and verifies the digest challenge* + * + * @param string $challenge The digest challenge + * @return array The parsed challenge as an assoc + * array in the form "directive => value". + * @access private + */ + function _parseChallenge($challenge) + { + $tokens = array(); + while (preg_match('/^([a-z-]+)=("[^"]+(? diff --git a/extlib/Auth/SASL/External.php b/extlib/Auth/SASL/External.php new file mode 100644 index 0000000000..86a17cb7ab --- /dev/null +++ b/extlib/Auth/SASL/External.php @@ -0,0 +1,63 @@ + | +// +-----------------------------------------------------------------------+ +// +// $Id: External.php 286825 2009-08-05 06:23:42Z cweiske $ + +/** +* Implmentation of EXTERNAL SASL mechanism +* +* @author Christoph Schulz +* @access public +* @version 1.0.3 +* @package Auth_SASL +*/ + +require_once('Auth/SASL/Common.php'); + +class Auth_SASL_External extends Auth_SASL_Common +{ + /** + * Returns EXTERNAL response + * + * @param string $authcid Authentication id (username) + * @param string $pass Password + * @param string $authzid Autorization id + * @return string EXTERNAL Response + */ + function getResponse($authcid, $pass, $authzid = '') + { + return $authzid; + } +} +?> diff --git a/extlib/Auth/SASL/Login.php b/extlib/Auth/SASL/Login.php new file mode 100644 index 0000000000..a925f53a79 --- /dev/null +++ b/extlib/Auth/SASL/Login.php @@ -0,0 +1,65 @@ + | +// +-----------------------------------------------------------------------+ +// +// $Id: Login.php 286825 2009-08-05 06:23:42Z cweiske $ + +/** +* This is technically not a SASL mechanism, however +* it's used by Net_Sieve, Net_Cyrus and potentially +* other protocols , so here is a good place to abstract +* it. +* +* @author Richard Heyes +* @access public +* @version 1.0 +* @package Auth_SASL +*/ + +require_once('Auth/SASL/Common.php'); + +class Auth_SASL_Login extends Auth_SASL_Common +{ + /** + * Pseudo SASL LOGIN mechanism + * + * @param string $user Username + * @param string $pass Password + * @return string LOGIN string + */ + function getResponse($user, $pass) + { + return sprintf('LOGIN %s %s', $user, $pass); + } +} +?> \ No newline at end of file diff --git a/extlib/Auth/SASL/Plain.php b/extlib/Auth/SASL/Plain.php new file mode 100644 index 0000000000..912710169e --- /dev/null +++ b/extlib/Auth/SASL/Plain.php @@ -0,0 +1,63 @@ + | +// +-----------------------------------------------------------------------+ +// +// $Id: Plain.php 286825 2009-08-05 06:23:42Z cweiske $ + +/** +* Implmentation of PLAIN SASL mechanism +* +* @author Richard Heyes +* @access public +* @version 1.0 +* @package Auth_SASL +*/ + +require_once('Auth/SASL/Common.php'); + +class Auth_SASL_Plain extends Auth_SASL_Common +{ + /** + * Returns PLAIN response + * + * @param string $authcid Authentication id (username) + * @param string $pass Password + * @param string $authzid Autorization id + * @return string PLAIN Response + */ + function getResponse($authcid, $pass, $authzid = '') + { + return $authzid . chr(0) . $authcid . chr(0) . $pass; + } +} +?> diff --git a/index.php b/index.php index 37c157b01f..7f2afffb5a 100644 --- a/index.php +++ b/index.php @@ -38,6 +38,7 @@ */ $_startTime = microtime(true); +$_perfCounters = array(); define('INSTALLDIR', dirname(__FILE__)); define('STATUSNET', true); @@ -45,6 +46,8 @@ define('LACONICA', true); // compatibility require_once INSTALLDIR . '/lib/common.php'; +register_shutdown_function('common_log_perf_counters'); + $user = null; $action = null; diff --git a/js/jquery.form.js b/js/jquery.form.js index 14e14572af..936b847abe 100644 --- a/js/jquery.form.js +++ b/js/jquery.form.js @@ -1,803 +1,632 @@ -/*! - * jQuery Form Plugin - * version: 2.63 (29-JAN-2011) - * @requires jQuery v1.3.2 or later - * - * Examples and documentation at: http://malsup.com/jquery/form/ - * Dual licensed under the MIT and GPL licenses: - * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html - */ -;(function($) { - -/* - Usage Note: - ----------- - Do not use both ajaxSubmit and ajaxForm on the same form. These - functions are intended to be exclusive. Use ajaxSubmit if you want - to bind your own submit handler to the form. For example, - - $(document).ready(function() { - $('#myForm').bind('submit', function(e) { - e.preventDefault(); // <-- important - $(this).ajaxSubmit({ - target: '#output' - }); - }); - }); - - Use ajaxForm when you want the plugin to manage all the event binding - for you. For example, - - $(document).ready(function() { - $('#myForm').ajaxForm({ - target: '#output' - }); - }); - - When using ajaxForm, the ajaxSubmit function will be invoked for you - at the appropriate time. -*/ - -/** - * ajaxSubmit() provides a mechanism for immediately submitting - * an HTML form using AJAX. - */ -$.fn.ajaxSubmit = function(options) { - // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) - if (!this.length) { - log('ajaxSubmit: skipping submit process - no element selected'); - return this; - } - - if (typeof options == 'function') { - options = { success: options }; - } - - var action = this.attr('action'); - var url = (typeof action === 'string') ? $.trim(action) : ''; - if (url) { - // clean url (don't include hash vaue) - url = (url.match(/^([^#]+)/)||[])[1]; - } - url = url || window.location.href || ''; - - options = $.extend(true, { - url: url, - type: this[0].getAttribute('method') || 'GET', // IE7 massage (see issue 57) - iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank' - }, options); - - // hook for manipulating the form data before it is extracted; - // convenient for use with rich editors like tinyMCE or FCKEditor - var veto = {}; - this.trigger('form-pre-serialize', [this, options, veto]); - if (veto.veto) { - log('ajaxSubmit: submit vetoed via form-pre-serialize trigger'); - return this; - } - - // provide opportunity to alter form data before it is serialized - if (options.beforeSerialize && options.beforeSerialize(this, options) === false) { - log('ajaxSubmit: submit aborted via beforeSerialize callback'); - return this; - } - - var n,v,a = this.formToArray(options.semantic); - if (options.data) { - options.extraData = options.data; - for (n in options.data) { - if(options.data[n] instanceof Array) { - for (var k in options.data[n]) { - a.push( { name: n, value: options.data[n][k] } ); - } - } - else { - v = options.data[n]; - v = $.isFunction(v) ? v() : v; // if value is fn, invoke it - a.push( { name: n, value: v } ); - } - } - } - - // give pre-submit callback an opportunity to abort the submit - if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) { - log('ajaxSubmit: submit aborted via beforeSubmit callback'); - return this; - } - - // fire vetoable 'validate' event - this.trigger('form-submit-validate', [a, this, options, veto]); - if (veto.veto) { - log('ajaxSubmit: submit vetoed via form-submit-validate trigger'); - return this; - } - - var q = $.param(a); - - if (options.type.toUpperCase() == 'GET') { - options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; - options.data = null; // data is null for 'get' - } - else { - options.data = q; // data is the query string for 'post' - } - - var $form = this, callbacks = []; - if (options.resetForm) { - callbacks.push(function() { $form.resetForm(); }); - } - if (options.clearForm) { - callbacks.push(function() { $form.clearForm(); }); - } - - // perform a load on the target only if dataType is not provided - if (!options.dataType && options.target) { - var oldSuccess = options.success || function(){}; - callbacks.push(function(data) { - var fn = options.replaceTarget ? 'replaceWith' : 'html'; - $(options.target)[fn](data).each(oldSuccess, arguments); - }); - } - else if (options.success) { - callbacks.push(options.success); - } - - options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg - var context = options.context || options; // jQuery 1.4+ supports scope context - for (var i=0, max=callbacks.length; i < max; i++) { - callbacks[i].apply(context, [data, status, xhr || $form, $form]); - } - }; - - // are there files to upload? - var fileInputs = $('input:file', this).length > 0; - var mp = 'multipart/form-data'; - var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp); - - // options.iframe allows user to force iframe mode - // 06-NOV-09: now defaulting to iframe mode if file input is detected - if (options.iframe !== false && (fileInputs || options.iframe || multipart)) { - // hack to fix Safari hang (thanks to Tim Molendijk for this) - // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d - if (options.closeKeepAlive) { - $.get(options.closeKeepAlive, fileUpload); - } - else { - fileUpload(); - } - } - else { - $.ajax(options); - } - - // fire 'notify' event - this.trigger('form-submit-notify', [this, options]); - return this; - - - // private function for handling file uploads (hat tip to YAHOO!) - function fileUpload() { - var form = $form[0]; - - if ($(':input[name=submit],:input[id=submit]', form).length) { - // if there is an input with a name or id of 'submit' then we won't be - // able to invoke the submit fn on the form (at least not x-browser) - alert('Error: Form elements must not have name or id of "submit".'); - return; - } - - var s = $.extend(true, {}, $.ajaxSettings, options); - s.context = s.context || s; - var id = 'jqFormIO' + (new Date().getTime()), fn = '_'+id; - var $io = $('