From: Brion Vibber Date: Wed, 16 Mar 2011 23:42:12 +0000 (-0700) Subject: Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e36959d45126617fbf813bf585134982353f01d5;hp=74387e75cf1f521bfdea0a8d635730ee6fb49d9d;p=quix0rs-gnu-social.git Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x --- diff --git a/plugins/SearchSub/SearchSubPlugin.php b/plugins/SearchSub/SearchSubPlugin.php index 130600a41a..f7da8c44d9 100644 --- a/plugins/SearchSub/SearchSubPlugin.php +++ b/plugins/SearchSub/SearchSubPlugin.php @@ -78,6 +78,7 @@ class SearchSubPlugin extends Plugin return false; case 'SearchsubAction': case 'SearchunsubAction': + case 'SearchsubsAction': case 'SearchSubForm': case 'SearchUnsubForm': include_once $dir.'/'.strtolower($cls).'.php'; @@ -103,6 +104,9 @@ class SearchSubPlugin extends Plugin array('action' => 'searchunsub'), array('search' => Router::REGEX_TAG)); + $m->connect(':nickname/search-subscriptions', + array('action' => 'searchsubs'), + array('nickname' => Nickname::DISPLAY_FMT)); return true; } @@ -209,4 +213,60 @@ class SearchSubPlugin extends Plugin } return true; } + + /** + * Menu item for personal subscriptions/groups area + * + * @param Widget $widget Widget being executed + * + * @return boolean hook return + */ + + function onEndSubGroupNav($widget) + { + $action = $widget->out; + $action_name = $action->trimmed('action'); + + $action->menuItem(common_local_url('searchsubs', array('nickname' => $action->user->nickname)), + // TRANS: SearchSub plugin menu item on user settings page. + _m('MENU', 'Searches'), + // TRANS: SearchSub plugin tooltip for user settings menu item. + _m('Configure search subscriptions'), + $action_name == 'searchsubs' && $action->arg('nickname') == $action->user->nickname); + + return true; + } + + /** + * Add a count of mirrored feeds into a user's profile sidebar stats. + * + * @param Profile $profile + * @param array $stats + * @return boolean hook return value + */ + function onProfileStats($profile, &$stats) + { + $cur = common_current_user(); + if (!empty($cur) && $cur->id == $profile->id) { + $searchsub = new SearchSub(); + $searchsub ->profile_id = $profile->id; + $entry = array( + 'id' => 'searchsubs', + 'label' => _m('Search subscriptions'), + 'link' => common_local_url('searchsubs', array('nickname' => $profile->nickname)), + 'value' => $searchsub->count(), + ); + + $insertAt = count($stats); + foreach ($stats as $i => $row) { + if ($row['id'] == 'groups') { + // Slip us in after them. + $insertAt = $i + 1; + break; + } + } + array_splice($stats, $insertAt, 0, array($entry)); + } + return true; + } } diff --git a/plugins/SearchSub/searchsubsaction.php b/plugins/SearchSub/searchsubsaction.php new file mode 100644 index 0000000000..f888613349 --- /dev/null +++ b/plugins/SearchSub/searchsubsaction.php @@ -0,0 +1,194 @@ +. + * + * @category Social + * @package StatusNet + * @author Evan Prodromou + * @author Sarven Capadisli + * @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); +} + +/** + * A list of the user's subscriptions + * + * @category Social + * @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 SearchSubsAction extends GalleryAction +{ + function title() + { + if ($this->page == 1) { + // TRANS: Header for subscriptions overview for a user (first page). + // TRANS: %s is a user nickname. + return sprintf(_m('%s\'s search subscriptions'), $this->user->nickname); + } else { + // TRANS: Header for subscriptions overview for a user (not first page). + // TRANS: %1$s is a user nickname, %2$d is the page number. + return sprintf(_m('%1$s\'s search subscriptions, page %2$d'), + $this->user->nickname, + $this->page); + } + } + + function showPageNotice() + { + $user = common_current_user(); + if ($user && ($user->id == $this->profile->id)) { + $this->element('p', null, + // TRANS: Page notice for page with an overview of all search subscriptions + // TRANS: of the logged in user's own profile. + _m('You have subscribed to receive all notices on this site matching the following searches:')); + } else { + $this->element('p', null, + // TRANS: Page notice for page with an overview of all subscriptions of a user other + // TRANS: than the logged in user. %s is the user nickname. + sprintf(_m('%s has subscribed to receive all notices on this site matching the following searches:'), + $this->profile->nickname)); + } + } + + function showContent() + { + if (Event::handle('StartShowTagSubscriptionsContent', array($this))) { + parent::showContent(); + + $offset = ($this->page-1) * PROFILES_PER_PAGE; + $limit = PROFILES_PER_PAGE + 1; + + $cnt = 0; + + $searchsub = new SearchSub(); + $searchsub->profile_id = $this->user->id; + $searchsub->limit($limit, $offset); + $searchsub->find(); + + if ($searchsub->N) { + $list = new SearchSubscriptionsList($searchsub, $this->user, $this); + $cnt = $list->show(); + if (0 == $cnt) { + $this->showEmptyListMessage(); + } + } else { + $this->showEmptyListMessage(); + } + + $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE, + $this->page, 'searchsubs', + array('nickname' => $this->user->nickname)); + + + Event::handle('EndShowTagSubscriptionsContent', array($this)); + } + } + + function showEmptyListMessage() + { + if (common_logged_in()) { + $current_user = common_current_user(); + if ($this->user->id === $current_user->id) { + // TRANS: Search subscription list text when the logged in user has no search subscriptions. + $message = _('You\'re not subscribed to any text searches right now. You can push the "Subscribe" button ' . + 'on any notice text search to automatically receive any public messages on this site that match that ' . + 'search, even if you\'re not subscribed to the poster.'); + } else { + // TRANS: Search subscription list text when looking at the subscriptions for a of a user other + // TRANS: than the logged in user that has no search subscriptions. %s is the user nickname. + $message = sprintf(_('%s is not subscribed to any searches.'), $this->user->nickname); + } + } + else { + // TRANS: Subscription list text when looking at the subscriptions for a of a user that has none + // TRANS: as an anonymous user. %s is the user nickname. + $message = sprintf(_m('%s is not subscribed to any searches.'), $this->user->nickname); + } + + $this->elementStart('div', 'guide'); + $this->raw(common_markup_to_html($message)); + $this->elementEnd('div'); + } +} + +// XXX SubscriptionsList and SubscriptionList are dangerously close + +class SearchSubscriptionsList extends SubscriptionList +{ + function newListItem($searchsub) + { + return new SearchSubscriptionsListItem($searchsub, $this->owner, $this->action); + } +} + +class SearchSubscriptionsListItem extends SubscriptionListItem +{ + function startItem() + { + $this->out->elementStart('li', array('class' => 'searchsub')); + } + + function showProfile() + { + $searchsub = $this->profile; + $search = $searchsub->search; + + // Relevant portion! + $cur = common_current_user(); + if (!empty($cur) && $cur->id == $this->owner->id) { + $this->showOwnerControls(); + } + + $url = common_local_url('noticesearch', array('q' => $search)); + $linkline = sprintf(_m('"%s" since %s'), + htmlspecialchars($url), + htmlspecialchars($search), + common_date_string($searchsub->created)); + + $this->out->elementStart('div', 'searchsub-item'); + $this->out->raw($linkline); + $this->out->element('div', array('style' => 'clear: both')); + $this->out->elementEnd('div'); + } + + function showActions() + { + } + + function showOwnerControls() + { + $this->out->elementStart('div', 'entity_actions'); + + $searchsub = $this->profile; // ? + $form = new SearchUnsubForm($this->out, $searchsub->search); + $form->show(); + + $this->out->elementEnd('div'); + return; + } +}