本文整理汇总了PHP中Notice::saveNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Notice::saveNew方法的具体用法?PHP Notice::saveNew怎么用?PHP Notice::saveNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Notice
的用法示例。
在下文中一共展示了Notice::saveNew方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveNew
static function saveNew(Profile $profile, $url, $options = array())
{
$vid = new Video();
$vid->id = UUID::gen();
$vid->profile_id = $profile->id;
$vid->url = $url;
$options['object_type'] = Video::OBJECT_TYPE;
if (!array_key_exists('uri', $options)) {
$options['uri'] = common_local_url('showvideo', array('id' => $vid->id));
}
if (!array_key_exists('rendered', $options)) {
$options['rendered'] = sprintf("<video src=\"%s\">Sorry, your browser doesn't support the video tag.</video>", $url);
}
$vid->uri = $options['uri'];
$vid->insert();
return Notice::saveNew($profile->id, '', 'web', $options);
}
示例2: save_notice
function save_notice(&$req, &$consumer, &$token)
{
$version = $req->get_parameter('omb_version');
if ($version != OMB_VERSION_01) {
$this->clientError(_('Unsupported OMB version'), 400);
return false;
}
# First, check to see
$listenee = $req->get_parameter('omb_listenee');
$remote_profile = Remote_profile::staticGet('uri', $listenee);
if (!$remote_profile) {
$this->clientError(_('Profile unknown'), 403);
return false;
}
$sub = Subscription::staticGet('token', $token->key);
if (!$sub) {
$this->clientError(_('No such subscription'), 403);
return false;
}
$content = $req->get_parameter('omb_notice_content');
$content_shortened = common_shorten_links($content);
if (mb_strlen($content_shortened) > 140) {
$this->clientError(_('Invalid notice content'), 400);
return false;
}
$notice_uri = $req->get_parameter('omb_notice');
if (!Validate::uri($notice_uri) && !common_valid_tag($notice_uri)) {
$this->clientError(_('Invalid notice uri'), 400);
return false;
}
$notice_url = $req->get_parameter('omb_notice_url');
if ($notice_url && !common_valid_http_url($notice_url)) {
$this->clientError(_('Invalid notice url'), 400);
return false;
}
$notice = Notice::staticGet('uri', $notice_uri);
if (!$notice) {
$notice = Notice::saveNew($remote_profile->id, $content, 'omb', false, null, $notice_uri);
if (is_string($notice)) {
common_server_serror($notice, 500);
return false;
}
common_broadcast_notice($notice, true);
}
return true;
}
示例3: saveNew
static function saveNew(Profile $profile, $photo_uri, $thumb_uri, $title, $description, $options = array())
{
$photo = new Photo();
$photo->id = UUID::gen();
$photo->profile_id = $profile->id;
$photo->photo_uri = $photo_uri;
$photo->thumb_uri = $thumb_uri;
$options['object_type'] = Photo::OBJECT_TYPE;
if (!array_key_exists('uri', $options)) {
$options['uri'] = common_local_url('showphoto', array('id' => $photo->id));
}
if (!array_key_exists('rendered', $options)) {
$options['rendered'] = sprintf("<img src=\"%s\" alt=\"%s\"></img>", $photo_uri, $title);
}
$photo->uri = $options['uri'];
$photo->insert();
return Notice::saveNew($profile->id, '', 'web', $options);
}
示例4: importActivityStream
function importActivityStream($user, $doc)
{
$feed = $doc->documentElement;
$entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry');
for ($i = $entries->length - 1; $i >= 0; $i--) {
$entry = $entries->item($i);
$activity = new Activity($entry, $feed);
$object = $activity->objects[0];
if (!have_option('q', 'quiet')) {
print $activity->content . "\n";
}
$html = getTweetHtml($object->link);
$config = array('safe' => 1, 'deny_attribute' => 'class,rel,id,style,on*');
$html = htmLawed($html, $config);
$content = html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8');
$notice = Notice::saveNew($user->id, $content, 'importtwitter', array('uri' => $object->id, 'url' => $object->link, 'rendered' => $html, 'created' => common_sql_date($activity->time), 'replies' => array(), 'groups' => array()));
}
}
示例5: newNotice
function newNotice($i, $tagmax)
{
global $userprefix;
$n = rand(0, $i - 1);
$user = User::staticGet('nickname', sprintf('%s%d', $userprefix, $n));
$is_reply = rand(0, 4);
$content = 'Test notice content';
if ($is_reply == 0) {
$n = rand(0, $i - 1);
$content = "@{$userprefix}{$n} " . $content;
}
$has_hash = rand(0, 2);
if ($has_hash == 0) {
$hashcount = rand(0, 2);
for ($j = 0; $j < $hashcount; $j++) {
$h = rand(0, $tagmax);
$content .= " #tag{$h}";
}
}
$notice = Notice::saveNew($user->id, $content, 'system');
$user->free();
$notice->free();
}
示例6: saveNotice
/**
* Save passed notice
*
* Stores the OMB notice $notice. The datastore may change the passed notice.
* This might by neccessary for URIs depending on a database key. Note that
* it is the user’s duty to present a mechanism for his OMB_Datastore to
* appropriately change his OMB_Notice.
* Throws exceptions in case of error.
*
* @param OMB_Notice $notice The OMB notice which should be saved
*
* @access public
**/
public function saveNotice(&$omb_notice)
{
if (Notice::staticGet('uri', $omb_notice->getIdentifierURI())) {
// TRANS: Exception thrown when a notice is denied because it has been sent before.
throw new Exception(_('Duplicate notice.'));
}
$author_uri = $omb_notice->getAuthor()->getIdentifierURI();
common_log(LOG_DEBUG, $author_uri, __FILE__);
$author = Remote_profile::staticGet('uri', $author_uri);
if (!$author) {
$author = User::staticGet('uri', $author_uri);
}
if (!$author) {
throw new Exception('No such user.');
}
common_log(LOG_DEBUG, print_r($author, true), __FILE__);
$notice = Notice::saveNew($author->id, $omb_notice->getContent(), 'omb', array('is_local' => Notice::REMOTE_OMB, 'uri' => $omb_notice->getIdentifierURI()));
}
示例7: postNote
function postNote($user, $author, $activity)
{
$note = $activity->objects[0];
$sourceUri = $note->id;
$notice = Notice::getKV('uri', $sourceUri);
if ($notice instanceof Notice) {
common_log(LOG_INFO, "Notice {$sourceUri} already exists.");
if ($this->trusted) {
$profile = $notice->getProfile();
$uri = $profile->getUri();
if ($uri === $author->id) {
common_log(LOG_INFO, sprintf('Updating notice author from %s to %s', $author->id, $user->getUri()));
$orig = clone $notice;
$notice->profile_id = $user->id;
$notice->update($orig);
return;
} else {
// TRANS: Client exception thrown when trying to import a notice by another user.
// TRANS: %1$s is the source URI of the notice, %2$s is the URI of the author.
throw new ClientException(sprintf(_('Already know about notice %1$s and ' . ' it has a different author %2$s.'), $sourceUri, $uri));
}
} else {
// TRANS: Client exception thrown when trying to overwrite the author information for a non-trusted user during import.
throw new ClientException(_('Not overwriting author info for non-trusted user.'));
}
}
// Use summary as fallback for content
if (!empty($note->content)) {
$sourceContent = $note->content;
} else {
if (!empty($note->summary)) {
$sourceContent = $note->summary;
} else {
if (!empty($note->title)) {
$sourceContent = $note->title;
} else {
// @fixme fetch from $sourceUrl?
// TRANS: Client exception thrown when trying to import a notice without content.
// TRANS: %s is the notice URI.
throw new ClientException(sprintf(_('No content for notice %s.'), $sourceUri));
}
}
}
// Get (safe!) HTML and text versions of the content
$rendered = common_purify($sourceContent);
$content = common_strip_html($rendered);
$shortened = $user->shortenLinks($content);
$options = array('is_local' => Notice::LOCAL_PUBLIC, 'uri' => $sourceUri, 'rendered' => $rendered, 'replies' => array(), 'groups' => array(), 'tags' => array(), 'urls' => array(), 'distribute' => false);
// Check for optional attributes...
if (!empty($activity->time)) {
$options['created'] = common_sql_date($activity->time);
}
if ($activity->context) {
// Any individual or group attn: targets?
list($options['groups'], $options['replies']) = $this->filterAttention($activity->context->attention);
// Maintain direct reply associations
// @fixme what about conversation ID?
if (!empty($activity->context->replyToID)) {
$orig = Notice::getKV('uri', $activity->context->replyToID);
if ($orig instanceof Notice) {
$options['reply_to'] = $orig->id;
}
}
$location = $activity->context->location;
if ($location) {
$options['lat'] = $location->lat;
$options['lon'] = $location->lon;
if ($location->location_id) {
$options['location_ns'] = $location->location_ns;
$options['location_id'] = $location->location_id;
}
}
}
// Atom categories <-> hashtags
foreach ($activity->categories as $cat) {
if ($cat->term) {
$term = common_canonical_tag($cat->term);
if ($term) {
$options['tags'][] = $term;
}
}
}
// Atom enclosures -> attachment URLs
foreach ($activity->enclosures as $href) {
// @fixme save these locally or....?
$options['urls'][] = $href;
}
common_log(LOG_INFO, "Saving notice {$options['uri']}");
$saved = Notice::saveNew($user->id, $content, 'restore', $options);
return $saved;
}
示例8: handle
//.........这里部分代码省略.........
// Cmd not supported? Twitter just returns your latest status.
// And, it returns your last status whether the cmd was successful
// or not!
$this->notice = $this->auth_user->getCurrentNotice();
} else {
$reply_to = null;
if (!empty($this->in_reply_to_status_id)) {
// Check whether notice actually exists
$reply = Notice::getKV($this->in_reply_to_status_id);
if ($reply) {
$reply_to = $this->in_reply_to_status_id;
} else {
// TRANS: Client error displayed when replying to a non-existing notice.
$this->clientError(_('Parent notice not found.'), 404);
}
}
$upload = null;
try {
$upload = MediaFile::fromUpload('media', $this->scoped);
} catch (NoUploadedMediaException $e) {
// There was no uploaded media for us today.
}
if (isset($upload)) {
$this->status .= ' ' . $upload->shortUrl();
/* Do not call shortenlinks until the whole notice has been build */
}
// in Qvitter we shorten _before_ posting, so disble shortening here
$status_shortened = $this->status;
if (Notice::contentTooLong($status_shortened)) {
if ($upload instanceof MediaFile) {
$upload->delete();
}
// TRANS: Client error displayed exceeding the maximum notice length.
// TRANS: %d is the maximum lenth for a notice.
$msg = _m('Maximum notice size is %d character, including attachment URL.', 'Maximum notice size is %d characters, including attachment URL.', Notice::maxContent());
/* Use HTTP 413 error code (Request Entity Too Large)
* instead of basic 400 for better understanding
*/
$this->clientError(sprintf($msg, Notice::maxContent()), 413);
}
$content = html_entity_decode($status_shortened, ENT_NOQUOTES, 'UTF-8');
$options = array('reply_to' => $reply_to);
// -------------------------------------------------------------
// -------- Qvitter's post-to-the-right-group stuff! -----------
// -------------------------------------------------------------
// guess the groups by the content first, if we don't have group id:s as meta data
$profile = Profile::getKV('id', $this->scoped->id);
$guessed_groups = User_group::groupsFromText($content, $profile);
// if the user has specified any group id:s, correct the guesswork
if (strlen($this->post_to_groups) > 0) {
// get the groups that the user wants to post to
$group_ids = explode(':', $this->post_to_groups);
$correct_groups = array();
foreach ($group_ids as $group_id) {
$correct_groups[] = User_group::getKV('id', $group_id);
}
// correct the guesses
$corrected_group_ids = array();
foreach ($guessed_groups as $guessed_group) {
$id_to_keep = $guessed_group->id;
foreach ($correct_groups as $k => $correct_group) {
if ($correct_group->nickname == $guessed_group->nickname) {
$id_to_keep = $correct_group->id;
unset($correct_groups[$k]);
break;
}
}
$corrected_group_ids[$id_to_keep] = true;
}
// but we still want to post to all of the groups that the user specified by id
// even if we couldn't use it to correct a bad guess
foreach ($correct_groups as $correct_group) {
$corrected_group_ids[$correct_group->id] = true;
}
$options['groups'] = array_keys($corrected_group_ids);
} else {
$guessed_ids = array();
foreach ($guessed_groups as $guessed_group) {
$guessed_ids[$guessed_group->id] = true;
}
$options['groups'] = array_keys($guessed_ids);
}
// -------------------------------------------------------------
// ------ End of Qvitter's post-to-the-right-group stuff! ------
// -------------------------------------------------------------
if ($this->scoped->shareLocation()) {
$locOptions = Notice::locationOptions($this->lat, $this->lon, null, null, $this->scoped);
$options = array_merge($options, $locOptions);
}
try {
$this->notice = Notice::saveNew($this->scoped->id, $content, $this->source, $options);
} catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode());
}
if (isset($upload)) {
$upload->attachToNotice($this->notice);
}
}
$this->showNotice();
}
示例9: handle
function handle($channel)
{
$notice = $this->getNotice($this->other);
$recipient = $notice->getProfile();
$len = mb_strlen($this->text);
if ($len == 0) {
$channel->error($this->user, _('No content!'));
return;
}
$this->text = common_shorten_links($this->text);
if (Notice::contentTooLong($this->text)) {
$channel->error($this->user, sprintf(_('Notice too long - maximum is %d characters, you sent %d'), Notice::maxContent(), mb_strlen($this->text)));
return;
}
$notice = Notice::saveNew($this->user->id, $this->text, $channel->source(), array('reply_to' => $notice->id));
if ($notice) {
$channel->output($this->user, sprintf(_('Reply to %s sent'), $recipient->nickname));
} else {
$channel->error($this->user, _('Error saving notice.'));
}
}
示例10: postNote
function postNote($activity)
{
$note = $activity->objects[0];
// Use summary as fallback for content
if (!empty($note->content)) {
$sourceContent = $note->content;
} else {
if (!empty($note->summary)) {
$sourceContent = $note->summary;
} else {
if (!empty($note->title)) {
$sourceContent = $note->title;
} else {
// @fixme fetch from $sourceUrl?
// TRANS: Client error displayed when posting a notice without content through the API.
// TRANS: %d is the notice ID (number).
$this->clientError(sprintf(_('No content for notice %d.'), $note->id));
}
}
}
// Get (safe!) HTML and text versions of the content
$rendered = common_purify($sourceContent);
$content = common_strip_html($rendered);
$shortened = $this->auth_user->shortenLinks($content);
$options = array('is_local' => Notice::LOCAL_PUBLIC, 'rendered' => $rendered, 'replies' => array(), 'groups' => array(), 'tags' => array(), 'urls' => array());
// accept remote URI (not necessarily a good idea)
common_debug("Note ID is {$note->id}");
if (!empty($note->id)) {
$notice = Notice::getKV('uri', trim($note->id));
if (!empty($notice)) {
// TRANS: Client error displayed when using another format than AtomPub.
// TRANS: %s is the notice URI.
$this->clientError(sprintf(_('Notice with URI "%s" already exists.'), $note->id));
}
common_log(LOG_NOTICE, "Saving client-supplied notice URI '{$note->id}'");
$options['uri'] = $note->id;
}
// accept remote create time (also maybe not such a good idea)
if (!empty($activity->time)) {
common_log(LOG_NOTICE, "Saving client-supplied create time {$activity->time}");
$options['created'] = common_sql_date($activity->time);
}
// Check for optional attributes...
if ($activity->context instanceof ActivityContext) {
foreach ($activity->context->attention as $uri => $type) {
try {
$profile = Profile::fromUri($uri);
if ($profile->isGroup()) {
$options['groups'][] = $profile->id;
} else {
$options['replies'][] = $uri;
}
} catch (UnknownUriException $e) {
common_log(LOG_WARNING, sprintf('AtomPub post with unknown attention URI %s', $uri));
}
}
// Maintain direct reply associations
// @fixme what about conversation ID?
if (!empty($activity->context->replyToID)) {
$orig = Notice::getKV('uri', $activity->context->replyToID);
if (!empty($orig)) {
$options['reply_to'] = $orig->id;
}
}
$location = $activity->context->location;
if ($location) {
$options['lat'] = $location->lat;
$options['lon'] = $location->lon;
if ($location->location_id) {
$options['location_ns'] = $location->location_ns;
$options['location_id'] = $location->location_id;
}
}
}
// Atom categories <-> hashtags
foreach ($activity->categories as $cat) {
if ($cat->term) {
$term = common_canonical_tag($cat->term);
if ($term) {
$options['tags'][] = $term;
}
}
}
// Atom enclosures -> attachment URLs
foreach ($activity->enclosures as $href) {
// @fixme save these locally or....?
$options['urls'][] = $href;
}
$saved = Notice::saveNew($this->target->id, $content, 'atompub', $options);
return $saved;
}
示例11: saveNewNotice
function saveNewNotice()
{
$user = $this->flink->getUser();
$content = $this->trimmed('status_textarea');
if (!$content) {
$this->showPage(_m('No notice content!'));
return;
} else {
$content_shortened = common_shorten_links($content);
if (Notice::contentTooLong($content_shortened)) {
$this->showPage(sprintf(_m('That\'s too long. Max notice size is %d chars.'), Notice::maxContent()));
return;
}
}
$inter = new CommandInterpreter();
$cmd = $inter->handle_command($user, $content_shortened);
if ($cmd) {
// XXX fix this
$cmd->execute(new WebChannel());
return;
}
$replyto = $this->trimmed('inreplyto');
try {
$notice = Notice::saveNew($user->id, $content, 'web', array('reply_to' => $replyto == 'false' ? null : $replyto));
} catch (Exception $e) {
$this->showPage($e->getMessage());
return;
}
}
示例12: processPost
//.........这里部分代码省略.........
$sourceUrl = $note->id;
}
}
}
// Use summary as fallback for content
if (!empty($note->content)) {
$sourceContent = $note->content;
} else {
if (!empty($note->summary)) {
$sourceContent = $note->summary;
} else {
if (!empty($note->title)) {
$sourceContent = $note->title;
} else {
// @fixme fetch from $sourceUrl?
throw new ClientException("No content for notice {$sourceUri}");
}
}
}
// Get (safe!) HTML and text versions of the content
$rendered = $this->purify($sourceContent);
$content = html_entity_decode(strip_tags($rendered));
$shortened = common_shorten_links($content);
// If it's too long, try using the summary, and make the
// HTML an attachment.
$attachment = null;
if (Notice::contentTooLong($shortened)) {
$attachment = $this->saveHTMLFile($note->title, $rendered);
$summary = html_entity_decode(strip_tags($note->summary));
if (empty($summary)) {
$summary = $content;
}
$shortSummary = common_shorten_links($summary);
if (Notice::contentTooLong($shortSummary)) {
$url = common_shorten_url($sourceUrl);
$shortSummary = substr($shortSummary, 0, Notice::maxContent() - (mb_strlen($url) + 2));
$content = $shortSummary . ' ' . $url;
// We mark up the attachment link specially for the HTML output
// so we can fold-out the full version inline.
$attachUrl = common_local_url('attachment', array('attachment' => $attachment->id));
$rendered = common_render_text($shortSummary) . '<a href="' . htmlspecialchars($attachUrl) . '"' . ' class="attachment more"' . ' title="' . htmlspecialchars(_m('Show more')) . '">' . '…' . '</a>';
}
}
$options = array('is_local' => Notice::REMOTE_OMB, 'url' => $sourceUrl, 'uri' => $sourceUri, 'rendered' => $rendered, 'replies' => array(), 'groups' => array(), 'tags' => array(), 'urls' => array());
// Check for optional attributes...
if (!empty($activity->time)) {
$options['created'] = common_sql_date($activity->time);
}
if ($activity->context) {
// Any individual or group attn: targets?
$replies = $activity->context->attention;
$options['groups'] = $this->filterReplies($oprofile, $replies);
$options['replies'] = $replies;
// Maintain direct reply associations
// @fixme what about conversation ID?
if (!empty($activity->context->replyToID)) {
$orig = Notice::staticGet('uri', $activity->context->replyToID);
if (!empty($orig)) {
$options['reply_to'] = $orig->id;
}
}
$location = $activity->context->location;
if ($location) {
$options['lat'] = $location->lat;
$options['lon'] = $location->lon;
if ($location->location_id) {
$options['location_ns'] = $location->location_ns;
$options['location_id'] = $location->location_id;
}
}
}
// Atom categories <-> hashtags
foreach ($activity->categories as $cat) {
if ($cat->term) {
$term = common_canonical_tag($cat->term);
if ($term) {
$options['tags'][] = $term;
}
}
}
// Atom enclosures -> attachment URLs
foreach ($activity->enclosures as $href) {
// @fixme save these locally or....?
$options['urls'][] = $href;
}
try {
$saved = Notice::saveNew($oprofile->profile_id, $content, 'ostatus', $options);
if ($saved) {
Ostatus_source::saveNew($saved, $this, $method);
if (!empty($attachment)) {
File_to_post::processNew($attachment->id, $saved->id);
}
}
} catch (Exception $e) {
common_log(LOG_ERR, "OStatus save of remote message {$sourceUri} failed: " . $e->getMessage());
throw $e;
}
common_log(LOG_INFO, "OStatus saved remote message {$sourceUri} as notice id {$saved->id}");
return $saved;
}
示例13: saveNewNotice
/**
* Save a new notice, based on arguments
*
* If successful, will show the notice, or return an Ajax-y result.
* If not, it will show an error message -- possibly Ajax-y.
*
* Also, if the notice input looks like a command, it will run the
* command and show the results -- again, possibly ajaxy.
*
* @return void
*/
function saveNewNotice()
{
$user = common_current_user();
assert($user);
// XXX: maybe an error instead...
$content = $this->trimmed('status_textarea');
if (!$content) {
$this->clientError(_('No content!'));
return;
}
$inter = new CommandInterpreter();
$cmd = $inter->handle_command($user, $content);
if ($cmd) {
if ($this->boolean('ajax')) {
$cmd->execute(new AjaxWebChannel($this));
} else {
$cmd->execute(new WebChannel($this));
}
return;
}
$content_shortened = common_shorten_links($content);
if (Notice::contentTooLong($content_shortened)) {
$this->clientError(sprintf(_('That\'s too long. ' . 'Max notice size is %d chars.'), Notice::maxContent()));
}
$replyto = $this->trimmed('inreplyto');
#If an ID of 0 is wrongly passed here, it will cause a database error,
#so override it...
if ($replyto == 0) {
$replyto = 'false';
}
$upload = null;
$upload = MediaFile::fromUpload('attach');
if (isset($upload)) {
$content_shortened .= ' ' . $upload->shortUrl();
if (Notice::contentTooLong($content_shortened)) {
$upload->delete();
$this->clientError(sprintf(_('Max notice size is %d chars, including attachment URL.'), Notice::maxContent()));
}
}
$options = array('reply_to' => $replyto == 'false' ? null : $replyto);
if ($user->shareLocation()) {
// use browser data if checked; otherwise profile data
if ($this->arg('notice_data-geo')) {
$locOptions = Notice::locationOptions($this->trimmed('lat'), $this->trimmed('lon'), $this->trimmed('location_id'), $this->trimmed('location_ns'), $user->getProfile());
} else {
$locOptions = Notice::locationOptions(null, null, null, null, $user->getProfile());
}
$options = array_merge($options, $locOptions);
}
$notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
if (isset($upload)) {
$upload->attachToNotice($notice);
}
if ($this->boolean('ajax')) {
header('Content-Type: text/xml;charset=utf-8');
$this->xw->startDocument('1.0', 'UTF-8');
$this->elementStart('html');
$this->elementStart('head');
$this->element('title', null, _('Notice posted'));
$this->elementEnd('head');
$this->elementStart('body');
$this->showNotice($notice);
$this->elementEnd('body');
$this->elementEnd('html');
} else {
$returnto = $this->trimmed('returnto');
if ($returnto) {
$url = common_local_url($returnto, array('nickname' => $user->nickname));
} else {
$url = common_local_url('shownotice', array('notice' => $notice->id));
}
common_redirect($url, 303);
}
}
示例14: add_notice
function add_notice(&$user, &$pl)
{
$body = trim($pl['body']);
$content_shortened = $user->shortenLinks($body);
if (Notice::contentTooLong($content_shortened)) {
$from = jabber_normalize_jid($pl['from']);
// TRANS: Response to XMPP source when it sent too long a message.
// TRANS: %1$d the maximum number of allowed characters (used for plural), %2$d is the sent number.
$this->from_site($from, sprintf(_m('Message too long. Maximum is %1$d character, you sent %2$d.', 'Message too long. Maximum is %1$d characters, you sent %2$d.', Notice::maxContent()), Notice::maxContent(), mb_strlen($content_shortened)));
return;
}
try {
$notice = Notice::saveNew($user->id, $content_shortened, 'xmpp');
} catch (Exception $e) {
$this->log(LOG_ERR, $e->getMessage());
$this->from_site($user->jabber, $e->getMessage());
return;
}
common_broadcast_notice($notice);
$this->log(LOG_INFO, 'Added notice ' . $notice->id . ' from user ' . $user->nickname);
$notice->free();
unset($notice);
}
示例15: register
//.........这里部分代码省略.........
}
// This flag is ignored but still set to 1
$user->inboxed = 1;
// Set default-on options here, otherwise they'll be disabled
// initially for sites using caching, since the initial encache
// doesn't know about the defaults in the database.
$user->emailnotifysub = 1;
$user->emailnotifyfav = 1;
$user->emailnotifynudge = 1;
$user->emailnotifymsg = 1;
$user->emailnotifyattn = 1;
$user->emailmicroid = 1;
$user->emailpost = 1;
$user->jabbermicroid = 1;
$user->viewdesigns = 1;
$user->created = common_sql_now();
if (Event::handle('StartUserRegister', array(&$user, &$profile))) {
$profile->query('BEGIN');
$id = $profile->insert();
if (empty($id)) {
common_log_db_error($profile, 'INSERT', __FILE__);
return false;
}
$user->id = $id;
if (!empty($uri)) {
$user->uri = $uri;
} else {
$user->uri = common_user_uri($user);
}
if (!empty($password)) {
// may not have a password for OpenID users
$user->password = common_munge_password($password, $id);
}
$result = $user->insert();
if (!$result) {
common_log_db_error($user, 'INSERT', __FILE__);
return false;
}
// Everyone gets an inbox
$inbox = new Inbox();
$inbox->user_id = $user->id;
$inbox->notice_ids = '';
$result = $inbox->insert();
if (!$result) {
common_log_db_error($inbox, 'INSERT', __FILE__);
return false;
}
// Everyone is subscribed to themself
$subscription = new Subscription();
$subscription->subscriber = $user->id;
$subscription->subscribed = $user->id;
$subscription->created = $user->created;
$result = $subscription->insert();
if (!$result) {
common_log_db_error($subscription, 'INSERT', __FILE__);
return false;
}
if (!empty($email) && !$user->email) {
$confirm = new Confirm_address();
$confirm->code = common_confirmation_code(128);
$confirm->user_id = $user->id;
$confirm->address = $email;
$confirm->address_type = 'email';
$result = $confirm->insert();
if (!$result) {
common_log_db_error($confirm, 'INSERT', __FILE__);
return false;
}
}
if (!empty($code) && $user->email) {
$user->emailChanged();
}
// Default system subscription
$defnick = common_config('newuser', 'default');
if (!empty($defnick)) {
$defuser = User::staticGet('nickname', $defnick);
if (empty($defuser)) {
common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick), __FILE__);
} else {
Subscription::start($user, $defuser);
}
}
$profile->query('COMMIT');
if (!empty($email) && !$user->email) {
mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
}
// Welcome message
$welcome = common_config('newuser', 'welcome');
if (!empty($welcome)) {
$welcomeuser = User::staticGet('nickname', $welcome);
if (empty($welcomeuser)) {
common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick), __FILE__);
} else {
$notice = Notice::saveNew($welcomeuser->id, sprintf(_('Welcome to %1$s, @%2$s!'), common_config('site', 'name'), $user->nickname), 'system');
}
}
Event::handle('EndUserRegister', array(&$profile, &$user));
}
return $user;
}