/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { parent::prepare($args); $this->checkSessionToken(); if (!common_logged_in()) { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->clientError(_('Not logged in.')); } else { // Redirect to login. common_set_returnto($this->selfUrl()); $user = common_current_user(); if (Event::handle('RedirectToLogin', array($this, $user))) { common_redirect(common_local_url('login'), 303); } } return false; } $id = $this->trimmed('profileid'); if (!$id) { $this->clientError(_('No profile specified.')); return false; } $this->profile = Profile::staticGet('id', $id); if (!$this->profile) { $this->clientError(_('No profile with that ID.')); return false; } return true; }
public static function byProfile(Profile $target, $width = null, $height = null) { $width = intval($width); $height = !is_null($height) ? intval($height) : null; if (is_null($height)) { $height = $width; } $size = "{$width}x{$height}"; if (!isset(self::$_avatars[$target->id])) { self::$_avatars[$target->id] = array(); } elseif (isset(self::$_avatars[$target->id][$size])) { return self::$_avatars[$target->id][$size]; } $avatar = null; if (Event::handle('StartProfileGetAvatar', array($target, $width, &$avatar))) { $avatar = self::pkeyGet(array('profile_id' => $target->id, 'width' => $width, 'height' => $height)); Event::handle('EndProfileGetAvatar', array($target, $width, &$avatar)); } if (is_null($avatar)) { // Obviously we can't find an avatar, so let's resize the original! $avatar = Avatar::newSize($target, $width); } elseif (!$avatar instanceof Avatar) { throw new NoAvatarException($target, $avatar); } self::$_avatars[$target->id]["{$avatar->width}x{$avatar->height}"] = $avatar; return $avatar; }
function updateSchemaPlugins() { printfnq("Upgrading plugin schema..."); Event::handle('BeforePluginCheckSchema'); Event::handle('CheckSchema'); printfnq("DONE.\n"); }
protected function showContent() { if (Event::handle('ActivityVerbShowContent', array($this, $this->verb, $this->notice, $this->scoped))) { // TRANS: Error when a page for an activity verb has not been handled by a plugin. $this->element('div', 'error', sprintf(_('Could not show content for verb "%1$s".'), $this->verb)); } }
/** * Show the menu * * @return void */ function show() { $this->actionName = $this->action->trimmed('action'); $this->action->elementStart('ul', array('class' => 'nav')); if (Event::handle('StartPublicGroupNav', array($this))) { if (!common_config('singleuser', 'enabled')) { // TRANS: Menu item in search group navigation panel. $this->out->menuItem(common_local_url('public'), _m('MENU', 'Public'), _('Public timeline'), $this->actionName == 'public', 'nav_timeline_public'); } // TRANS: Menu item in search group navigation panel. $this->out->menuItem(common_local_url('groups'), _m('MENU', 'Groups'), _('User groups'), $this->actionName == 'groups', 'nav_groups'); if (!common_config('performance', 'high')) { // TRANS: Menu item in search group navigation panel. $this->out->menuItem(common_local_url('publictagcloud'), _m('MENU', 'Recent tags'), _('Recent tags'), $this->actionName == 'publictagcloud', 'nav_recent-tags'); } if (count(common_config('nickname', 'featured')) > 0) { // TRANS: Menu item in search group navigation panel. $this->out->menuItem(common_local_url('featured'), _m('MENU', 'Featured'), _('Featured users'), $this->actionName == 'featured', 'nav_featured'); } if (!common_config('singleuser', 'enabled')) { // TRANS: Menu item in search group navigation panel. $this->out->menuItem(common_local_url('favorited'), _m('MENU', 'Popular'), _('Popular notices'), $this->actionName == 'favorited', 'nav_timeline_favorited'); } Event::handle('EndPublicGroupNav', array($this)); } $this->action->elementEnd('ul'); }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); // User must be logged in. $user = common_current_user(); if (empty($user)) { throw new ClientException(_("You must be logged in to train spam."), 403); } // User must have the right to review spam if (!$user->hasRight(ActivitySpamPlugin::TRAINSPAM)) { throw new ClientException(_('You cannot review spam on this site.'), 403); } $id = $this->trimmed('notice'); $this->notice = Notice::getKV('id', $id); if (empty($this->notice)) { throw new ClientException(_("No such notice.")); } $this->checkSessionToken(); $filter = null; Event::handle('GetSpamFilter', array(&$filter)); if (empty($filter)) { throw new ServerException(_("No spam filter configured.")); } $this->filter = $filter; $this->category = $this->trimmed('category'); if ($this->category !== SpamFilter::SPAM && $this->category !== SpamFilter::HAM) { throw new ClientException(_("No such category.")); } return true; }
/** * Will call events as close as it gets to one hour. Event handlers * which use this MUST be as quick as possible, maybe only adding a * queue item to be handled later or something. Otherwise execution * will timeout for PHP - or at least cause unnecessary delays for * the unlucky user who visits the site exactly at one of these events. */ public function callTimedEvents() { $timers = array('minutely' => 60, 'hourly' => 3600, 'daily' => 86400, 'weekly' => 604800); foreach ($timers as $name => $interval) { $run = false; $lastrun = new Config(); $lastrun->section = 'cron'; $lastrun->setting = 'last_' . $name; $found = $lastrun->find(true); if (!$found) { $lastrun->value = time(); if ($lastrun->insert() === false) { common_log(LOG_WARNING, "Could not save 'cron' setting '{$name}'"); continue; } $run = true; } elseif ($lastrun->value < time() - $interval) { $orig = clone $lastrun; $lastrun->value = time(); $lastrun->update($orig); $run = true; } if ($run === true) { // such as CronHourly, CronDaily, CronWeekly Event::handle('Cron' . ucfirst($name)); } } }
static function get() { if (empty(self::$qm)) { if (Event::handle('StartNewQueueManager', array(&self::$qm))) { $enabled = common_config('queue', 'enabled'); $type = common_config('queue', 'subsystem'); if (!$enabled) { // does everything immediately self::$qm = new UnQueueManager(); } else { switch ($type) { case 'db': self::$qm = new DBQueueManager(); break; case 'stomp': self::$qm = new StompQueueManager(); break; default: throw new ServerException("No queue manager class for type '{$type}'"); } } } } return self::$qm; }
/** * Show the menu * * @return void */ function show() { $user = common_current_user(); if (empty($user)) { throw new ServerException('Cannot show personal group navigation without a current user.'); } $user_profile = $user->getProfile(); $nickname = $user->nickname; $name = $user_profile->getBestName(); $action = $this->actionName; $mine = $this->action->arg('nickname') == $nickname; // @fixme kinda vague $this->out->elementStart('ul', array('class' => 'nav')); if (Event::handle('StartPersonalGroupNav', array($this))) { $this->out->menuItem(common_local_url('all', array('nickname' => $nickname)), _m('MENU', 'Home'), sprintf(_('%s and friends'), $name), $mine && $action == 'all', 'nav_timeline_personal'); $this->out->menuItem(common_local_url('showstream', array('nickname' => $nickname)), _m('MENU', 'Profile'), _('Your profile'), $mine && $action == 'showstream', 'nav_profile'); $this->out->menuItem(common_local_url('replies', array('nickname' => $nickname)), _m('MENU', 'Replies'), sprintf(_('Replies to %s'), $name), $mine && $action == 'replies', 'nav_timeline_replies'); $this->out->menuItem(common_local_url('showfavorites', array('nickname' => $nickname)), _m('MENU', 'Favorites'), sprintf(_('%s\'s favorite notices'), $user_profile ? $name : _m('FIXME', 'User')), $mine && $action == 'showfavorites', 'nav_timeline_favorites'); $cur = common_current_user(); if ($cur && $cur->id == $user->id && !common_config('singleuser', 'enabled')) { $this->out->menuItem(common_local_url('inbox', array('nickname' => $nickname)), _m('MENU', 'Messages'), _('Your incoming messages'), $mine && $action == 'inbox'); } Event::handle('EndPersonalGroupNav', array($this)); } $this->out->elementEnd('ul'); }
/** * Handle input and output a page * * @param array $args $_REQUEST arguments * * @return void */ function handle($args) { parent::handle($args); if (!common_logged_in()) { $this->clientError(_('Not logged in.')); return; } else { if (!common_is_real_login()) { // Cookie theft means that automatic logins can't // change important settings or see private info, and // _all_ our settings are important common_set_returnto($this->selfUrl()); $user = common_current_user(); if (Event::handle('RedirectToLogin', array($this, $user))) { common_redirect(common_local_url('login'), 303); } } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->handlePost(); } else { $this->showForm(); } } } }
static function forTitle($title, $paths) { if (!is_array($paths)) { $paths = array($paths); } $filename = null; if (Event::handle('StartDocFileForTitle', array($title, &$paths, &$filename))) { foreach ($paths as $path) { $def = $path . '/' . $title; if (!file_exists($def)) { $def = null; } $lang = glob($path . '/' . $title . '.*'); if ($lang === false) { $lang = array(); } if (!empty($lang) || !empty($def)) { $filename = self::negotiateLanguage($lang, $def); break; } } Event::handle('EndDocFileForTitle', array($title, $paths, &$filename)); } if (empty($filename)) { return null; } else { return new DocFile($filename); } }
/** * Show the menu * * @return void */ function show() { $user = null; // FIXME: we should probably pass this in $action = $this->action->trimmed('action'); $nickname = $this->action->trimmed('nickname'); if ($nickname) { $user = User::staticGet('nickname', $nickname); $user_profile = $user->getProfile(); } else { $user_profile = false; } if (Event::handle('StartPersonalGroupNav', array($this))) { $cur = common_current_user(); if ($user && $cur && $cur->id == $user->id) { $this->out->elementStart('ul', array('class' => 'nav')); // $this->out->menuItem(common_local_url('outbox', array('nickname' => // $nickname)), // _('Outbox'), // _('Your sent messages'), // $action == 'outbox'); $this->out->elementEnd('ul'); } Event::handle('EndPersonalGroupNav', array($this)); } }
/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { parent::prepare($args); $this->checkSessionToken(); if (!common_logged_in()) { if ($_SERVER['REQUEST_METHOD'] == 'POST') { // TRANS: Error message displayed when trying to perform an action that requires a logged in user. $this->clientError(_('Not logged in.')); } else { // Redirect to login. common_set_returnto($this->selfUrl()); $user = common_current_user(); if (Event::handle('RedirectToLogin', array($this, $user))) { common_redirect(common_local_url('login'), 303); } } return false; } $id = $this->trimmed('profileid'); if (!$id) { // TRANS: Client error displayed when trying to change user options without specifying a user to work on. $this->clientError(_('No profile specified.')); return false; } $this->profile = Profile::staticGet('id', $id); if (!$this->profile) { // TRANS: Client error displayed when trying to change user options without specifying an existing user to work on. $this->clientError(_('No profile with that ID.')); return false; } return true; }
/** * Function comment * * @param * * @return */ function handle($data) { list($user, $author, $activity, $trusted) = $data; $this->trusted = $trusted; $done = null; try { if (Event::handle('StartImportActivity', array($user, $author, $activity, $trusted, &$done))) { switch ($activity->verb) { case ActivityVerb::FOLLOW: $this->subscribeProfile($user, $author, $activity); break; case ActivityVerb::JOIN: $this->joinGroup($user, $activity); break; case ActivityVerb::POST: $this->postNote($user, $author, $activity); break; default: // TRANS: Client exception thrown when using an unknown verb for the activity importer. throw new ClientException(sprintf(_("Unknown verb: \"%s\"."), $activity->verb)); } Event::handle('EndImportActivity', array($user, $author, $activity, $trusted)); $done = true; } } catch (Exception $e) { common_log(LOG_ERR, $e->getMessage()); $done = true; } return $done; }
static function fromXRD(XML_XRD $xrd) { $hints = array(); if (Event::handle('StartDiscoveryHintsFromXRD', array($xrd, &$hints))) { foreach ($xrd->links as $link) { switch ($link->rel) { case WebFingerResource_Profile::PROFILEPAGE: $hints['profileurl'] = $link->href; break; case Salmon::REL_SALMON: case Salmon::NS_MENTIONS: // XXX: deprecated, remove in the future // XXX: deprecated, remove in the future case Salmon::NS_REPLIES: // XXX: deprecated, remove in the future $hints['salmon'] = $link->href; break; case Discovery::UPDATESFROM: if (empty($link->type) || $link->type == 'application/atom+xml') { $hints['feedurl'] = $link->href; } break; case Discovery::HCARD: case Discovery::MF2_HCARD: $hints['hcard'] = $link->href; break; default: break; } } Event::handle('EndDiscoveryHintsFromXRD', array($xrd, &$hints)); } return $hints; }
function show() { $user = common_current_user(); $this->action->elementStart('ul', array('id' => 'nav_local_default')); if (Event::handle('StartDefaultLocalNav', array($this, $user))) { if (!empty($user)) { $pn = new PersonalGroupNav($this->action); // TRANS: Menu item in default local navigation panel. $this->submenu(_m('MENU', 'Home'), $pn); } $bn = new PublicGroupNav($this->action); // TRANS: Menu item in default local navigation panel. $this->submenu(_m('MENU', 'Public'), $bn); if (!empty($user)) { $sn = new GroupsNav($this->action, $user); if ($sn->haveGroups()) { // TRANS: Menu item in default local navigation panel. $this->submenu(_m('MENU', 'Groups'), $sn); } } if (!empty($user)) { $sn = new ListsNav($this->action, $user->getProfile()); if ($sn->hasLists()) { // TRANS: Menu item in default local navigation panel. $this->submenu(_m('MENU', 'Lists'), $sn); } } Event::handle('EndDefaultLocalNav', array($this, $user)); } $this->action->elementEnd('ul'); }
/** * Instead of showing notices, link to the original offsite profile. */ function showNotices() { $url = $this->profile->profileurl; $host = parse_url($url, PHP_URL_HOST); $markdown = sprintf(_m('This remote profile is registered on another site; see [%1$s\'s original profile page on %2$s](%3$s).'), $this->profile->nickname, $host, $url); $html = common_markup_to_html($markdown); $this->raw($html); if ($this->profile->hasRole(Profile_role::SILENCED)) { // TRANS: Message on blocked remote profile page. $markdown = _m('Site moderators have silenced this profile, which prevents delivery of new messages to any users on this site.'); $this->raw(common_markup_to_html($markdown)); } else { $pnl = null; if (Event::handle('ShowStreamNoticeList', array($this->notice, $this, &$pnl))) { $pnl = new ProfileNoticeList($this->notice, $this); } $cnt = $pnl->show(); if (0 == $cnt) { $this->showEmptyListMessage(); } $args = array('id' => $this->profile->id); if (!empty($this->tag)) { $args['tag'] = $this->tag; } $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->page, 'remoteprofile', $args); } }
/** * Show page, a template method. * * @return nothing */ function showPage() { if (Event::handle('StartShowBody', array($this))) { $this->showCore(); Event::handle('EndShowBody', array($this)); } }
/** * Show the menu * * @return void */ function show() { $cur = common_current_user(); $action = $this->action->trimmed('action'); $this->out->elementStart('ul', array('class' => 'nav')); if (Event::handle('StartSubGroupNav', array($this))) { $this->out->menuItem(common_local_url('showstream', array('nickname' => $this->user->nickname)), _m('MENU', 'Profile'), empty($profile) ? $this->user->nickname : $profile->getBestName(), $action == 'showstream', 'nav_profile'); $this->out->menuItem(common_local_url('subscriptions', array('nickname' => $this->user->nickname)), _m('MENU', 'Subscriptions'), sprintf(_('People %s subscribes to.'), $this->user->nickname), $action == 'subscriptions', 'nav_subscriptions'); $this->out->menuItem(common_local_url('subscribers', array('nickname' => $this->user->nickname)), _m('MENU', 'Subscribers'), sprintf(_('People subscribed to %s.'), $this->user->nickname), $action == 'subscribers', 'nav_subscribers'); if ($cur && $cur->id == $this->user->id) { // Possibly site admins should be able to get in here too $pending = $this->countPendingSubs(); if ($pending || $cur->subscribe_policy == User::SUBSCRIBE_POLICY_MODERATE) { $this->out->menuItem(common_local_url('subqueue', array('nickname' => $this->user->nickname)), sprintf(_m('MENU', 'Pending (%d)'), $pending), sprintf(_('Approve pending subscription requests.'), $this->user->nickname), $action == 'subqueueaction', 'nav_subscribers'); } } $this->out->menuItem(common_local_url('usergroups', array('nickname' => $this->user->nickname)), _m('MENU', 'Groups'), sprintf(_('Groups %s is a member of.'), $this->user->nickname), $action == 'usergroups', 'nav_usergroups'); $this->out->menuItem(common_local_url('peopletagsubscriptions', array('nickname' => $this->user->nickname)), _m('MENU', 'Lists'), sprintf(_('List subscriptions by %s.'), $this->user->nickname), in_array($action, array('peopletagsbyuser', 'peopletagsubscriptions', 'peopletagsforuser')), 'nav_timeline_peopletags'); if (common_config('invite', 'enabled') && !is_null($cur) && $this->user->id === $cur->id) { $this->out->menuItem(common_local_url('invite'), _m('MENU', 'Invite'), sprintf(_('Invite friends and colleagues to join you on %s.'), common_config('site', 'name')), $action == 'invite', 'nav_invite'); } Event::handle('EndSubGroupNav', array($this)); } $this->out->elementEnd('ul'); }
/** * Show body - override to add a special CSS class for the pin pages's * "desktop mode" (minimal display) * * Calls template methods * * @return nothing */ function showBody() { $bodyClasses = array(); if ($this->desktopMode) { $bodyClasses[] = 'oauth-desktop-mode'; } if (common_current_user()) { $bodyClasses[] = 'user_in'; } $attrs = array('id' => strtolower($this->trimmed('action'))); if (!empty($bodyClasses)) { $attrs['class'] = implode(' ', $bodyClasses); } $this->elementStart('body', $attrs); $this->elementStart('div', array('id' => 'wrap')); if (Event::handle('StartShowHeader', array($this))) { $this->showHeader(); Event::handle('EndShowHeader', array($this)); } $this->showCore(); if (Event::handle('StartShowFooter', array($this))) { $this->showFooter(); Event::handle('EndShowFooter', array($this)); } $this->elementEnd('div'); $this->showScripts(); $this->elementEnd('body'); }
/** * Handle distribution of a notice after we've saved it: * @li add to local recipient inboxes * @li send email notifications to local @-reply targets * @li run final EndNoticeSave plugin events * @li put any remaining post-processing into the queues * * If this function indicates failure, a warning will be logged * and the item is placed back in the queue to be re-run. * * @fixme addToInboxes is known to fail sometimes with large recipient sets * * @param Notice $notice * @return boolean true on success, false on failure */ function handle($notice) { try { $notice->addToInboxes(); } catch (Exception $e) { $this->logit($notice, $e); } try { $notice->sendReplyNotifications(); } catch (Exception $e) { $this->logit($notice, $e); } try { Event::handle('EndNoticeDistribute', array($notice)); } catch (Exception $e) { $this->logit($notice, $e); } try { Event::handle('EndNoticeSave', array($notice)); } catch (Exception $e) { $this->logit($notice, $e); } try { // Enqueue for other handlers common_enqueue_notice($notice); } catch (Exception $e) { $this->logit($notice, $e); } return true; }
public function updateXRD(XML_XRD $xrd) { if (Event::handle('StartWebFingerNoticeLinks', array($xrd, $this->object))) { $xrd->links[] = new XML_XRD_Element_Link('alternate', common_local_url('ApiStatusesShow', array('id' => $this->object->id, 'format' => 'atom')), 'application/atom+xml'); $xrd->links[] = new XML_XRD_Element_Link('alternate', common_local_url('ApiStatusesShow', array('id' => $this->object->id, 'format' => 'json')), 'application/json'); Event::handle('EndWebFingerNoticeLinks', array($xrd, $this->object)); } }
function showContent() { if (Event::handle('StartTagShowContent', array($this))) { $nl = new NoticeList($this->notice, $this); $cnt = $nl->show(); $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->page, 'tag', array('tag' => $this->tag)); Event::handle('EndTagShowContent', array($this)); } }
/** * Show content. * * NoticeList extended classes do most heavy lifting. Plugins can override. * * @return void */ function showContent() { if (Event::handle('StartShowConversation', array($this, $this->conv, $this->scoped))) { $notices = $this->conv->getNotices($this->scoped); $nl = new FullThreadedNoticeList($notices, $this, $this->scoped); $cnt = $nl->show(); } Event::handle('EndShowConversation', array($this, $this->conv, $this->scoped)); }
/** * 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'); }
/** * Cancel an outstanding subscription request to the other profile. */ public function abort() { $subscriber = Profile::staticGet('id', $this->subscriber); $subscribed = Profile::staticGet('id', $this->subscribed); if (Event::handle('StartCancelSubscription', array($subscriber, $subscribed))) { $this->delete(); Event::handle('EndCancelSubscription', array($subscriber, $subscribed)); } }
function getItems() { $items = array(); if (Event::handle('StartHomeStubNavItems', array($this->action, &$items))) { $items[] = array('top', array(), _m('MENU', 'Home'), _('Back to top'), 'nav_return_top'); Event::handle('EndHomeStubNavItems', array($this->action, &$items)); } return $items; }
/** * Class handler. * * @param array $args array of arguments * * @return nothing */ function handle($args) { parent::handle($args); $xrdsOutputter = new XRDSOutputter(); $xrdsOutputter->startXRDS(); Event::handle('StartPublicXRDS', array($this, &$xrdsOutputter)); Event::handle('EndPublicXRDS', array($this, &$xrdsOutputter)); $xrdsOutputter->endXRDS(); }
function handle($notice) { try { Event::handle('HandleQueuedNotice', array(&$notice)); } catch (UserNoProfileException $unp) { // We can't do anything about this, so just skip return true; } return true; }
function show() { $cnt = 0; if (Event::handle('StartProfileList', array($this))) { $this->startList(); $cnt = $this->showProfiles(); $this->endList(); Event::handle('EndProfileList', array($this)); } return $cnt; }