本文整理汇总了PHP中Event::handle方法的典型用法代码示例。如果您正苦于以下问题:PHP Event::handle方法的具体用法?PHP Event::handle怎么用?PHP Event::handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Event
的用法示例。
在下文中一共展示了Event::handle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare
/**
* 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;
}
示例2: byProfile
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;
}
示例3: updateSchemaPlugins
function updateSchemaPlugins()
{
printfnq("Upgrading plugin schema...");
Event::handle('BeforePluginCheckSchema');
Event::handle('CheckSchema');
printfnq("DONE.\n");
}
示例4: showContent
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));
}
}
示例5: show
/**
* 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');
}
示例6: prepare
/**
* 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;
}
示例7: callTimedEvents
/**
* 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));
}
}
}
示例8: get
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;
}
示例9: show
/**
* 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');
}
示例10: handle
/**
* 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();
}
}
}
}
示例11: forTitle
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);
}
}
示例12: show
/**
* 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));
}
}
示例13: handle
/**
* 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;
}
示例14: fromXRD
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;
}
示例15: show
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');
}