本文整理汇总了PHP中Notice::locationOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP Notice::locationOptions方法的具体用法?PHP Notice::locationOptions怎么用?PHP Notice::locationOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Notice
的用法示例。
在下文中一共展示了Notice::locationOptions方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle the request
*
* Make a new notice for the update, save it, and show it
*
* @return void
*/
protected function handle()
{
parent::handle();
// Workaround for PHP returning empty $_POST and $_FILES when POST
// length > post_max_size in php.ini
if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) {
// TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit.
// TRANS: %s is the number of bytes of the CONTENT_LENGTH.
$msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', intval($_SERVER['CONTENT_LENGTH']));
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
}
if (empty($this->status)) {
// TRANS: Client error displayed when the parameter "status" is missing.
$this->clientError(_('Client must provide a \'status\' parameter with a value.'));
}
if (is_null($this->scoped)) {
// TRANS: Client error displayed when updating a status for a non-existing user.
$this->clientError(_('No such user.'), 404);
}
/* Do not call shortenLinks until the whole notice has been build */
// Check for commands
$inter = new CommandInterpreter();
$cmd = $inter->handle_command($this->auth_user, $this->status);
if ($cmd) {
if ($this->supported($cmd)) {
$cmd->execute(new Channel());
}
// 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);
$this->status .= ' ' . $upload->shortUrl();
/* Do not call shortenLinks until the whole notice has been build */
} catch (NoUploadedMediaException $e) {
// There was no uploaded media for us today.
}
/* Do call shortenlinks here & check notice length since notice is about to be saved & sent */
$status_shortened = $this->auth_user->shortenLinks($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);
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();
}
示例2: 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();
}
示例3: 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);
}
}
示例4: handle
/**
* Handle the request
*
* Make a new notice for the update, save it, and show it
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
{
parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(_('This method requires a POST.'), 400, $this->format);
return;
}
// Workaround for PHP returning empty $_POST and $_FILES when POST
// length > post_max_size in php.ini
if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) {
$msg = _('The server was unable to handle that much POST ' . 'data (%s bytes) due to its current configuration.');
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
return;
}
if (empty($this->status)) {
$this->clientError('Client must provide a \'status\' parameter with a value.', 400, $this->format);
return;
}
if (empty($this->auth_user)) {
$this->clientError(_('No such user.'), 404, $this->format);
return;
}
$status_shortened = common_shorten_links($this->status);
if (Notice::contentTooLong($status_shortened)) {
// Note: Twitter truncates anything over 140, flags the status
// as "truncated."
$this->clientError(sprintf(_('That\'s too long. Max notice size is %d chars.'), Notice::maxContent()), 406, $this->format);
return;
}
// Check for commands
$inter = new CommandInterpreter();
$cmd = $inter->handle_command($this->auth_user, $status_shortened);
if ($cmd) {
if ($this->supported($cmd)) {
$cmd->execute(new Channel());
}
// 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::staticGet($this->in_reply_to_status_id);
if ($reply) {
$reply_to = $this->in_reply_to_status_id;
} else {
$this->clientError(_('Not found.'), $code = 404, $this->format);
return;
}
}
$upload = null;
try {
$upload = MediaFile::fromUpload('media', $this->auth_user);
} catch (ClientException $ce) {
$this->clientError($ce->getMessage());
return;
}
if (isset($upload)) {
$status_shortened .= ' ' . $upload->shortUrl();
if (Notice::contentTooLong($status_shortened)) {
$upload->delete();
$msg = _('Max notice size is %d chars, ' . 'including attachment URL.');
$this->clientError(sprintf($msg, Notice::maxContent()));
}
}
$content = html_entity_decode($status_shortened, ENT_NOQUOTES, 'UTF-8');
$options = array('reply_to' => $reply_to);
if ($this->auth_user->shareLocation()) {
$locOptions = Notice::locationOptions($this->lat, $this->lon, null, null, $this->auth_user->getProfile());
$options = array_merge($options, $locOptions);
}
try {
$this->notice = Notice::saveNew($this->auth_user->id, $content, $this->source, $options);
} catch (Exception $e) {
$this->clientError($e->getMessage());
return;
}
if (isset($upload)) {
$upload->attachToNotice($this->notice);
}
}
$this->showNotice();
}
示例5: 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...
$this->content = $this->trimmed('status_textarea');
$groupid = $this->trimmed('inreplyto');
$options = array();
if (!$this->content) {
// TRANS: Client error displayed trying to send a notice without content.
$this->clientError(_('Mensaje vacío!!'));
return;
}
$content_shortened = $user->shortenLinks($this->content);
if (Notice::contentTooLong($content_shortened)) {
// TRANS: Client error displayed when the parameter "status" is missing.
// TRANS: %d is the maximum number of character for a notice.
$this->clientError('Contenido demasiado largo! El tamaño máximo de caracteres es ' . Notice::maxContent() . '.');
}
$replyto = intval($this->trimmed('inreplyto'));
if ($replyto) {
$options['reply_to'] = $replyto;
}
$upload = null;
$upload = MediaFile::fromUpload('attach');
if (isset($upload)) {
$content_shortened .= ' ' . $upload->shortUrl();
if (Notice::contentTooLong($content_shortened)) {
$upload->delete();
// TRANS: Client error displayed exceeding the maximum notice length.
// TRANS: %d is the maximum length for a notice.
$this->clientError('Contenido demasiado largo! El tamaño máximo de caracteres ' . 'es ' . Notice::maxContent() . ', incluyendo la URL del adjunto.');
}
}
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);
}
$author_id = $user->id;
$text = $content_shortened;
// Does the heavy-lifting for getting "To:" information
$notice_to = $this->trimmed('notice_to');
$options['groups'] = array($notice_to);
$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');
// TRANS: Page title after sending a notice.
$this->element('title', null, _('Notice posted'));
$this->elementEnd('head');
$this->elementStart('body');
$this->element('p', array('class' => 'notice-task-posted'), 'Tarea completada correctamente, mensaje publicado.');
$this->elementEnd('body');
$this->elementEnd('html');
}
}
示例6: handle
/**
* Handle the request
*
* Make a new notice for the update, save it, and show it
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
{
parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(_('This method requires a POST.'), 400, $this->format);
return;
}
// Workaround for PHP returning empty $_POST and $_FILES when POST
// length > post_max_size in php.ini
if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) {
// TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit.
// TRANS: %s is the number of bytes of the CONTENT_LENGTH.
$msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', intval($_SERVER['CONTENT_LENGTH']));
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
return;
}
if (empty($this->status)) {
$this->clientError(_('Client must provide a \'status\' parameter with a value.'), 400, $this->format);
return;
}
if (empty($this->auth_user)) {
// TRANS: Client error displayed when updating a status for a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format);
return;
}
$status_shortened = $this->auth_user->shortenlinks($this->status);
if (Notice::contentTooLong($status_shortened)) {
// Note: Twitter truncates anything over 140, flags the status
// as "truncated."
$this->clientError(sprintf(_m('That\'s too long. Maximum notice size is %d character.', 'That\'s too long. Maximum notice size is %d characters.', Notice::maxContent()), Notice::maxContent()), 406, $this->format);
return;
}
// Check for commands
$inter = new CommandInterpreter();
$cmd = $inter->handle_command($this->auth_user, $status_shortened);
if ($cmd) {
if ($this->supported($cmd)) {
$cmd->execute(new Channel());
}
// 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::staticGet($this->in_reply_to_status_id);
if ($reply) {
$reply_to = $this->in_reply_to_status_id;
} else {
$this->clientError(_('Parent notice not found.'), $code = 404, $this->format);
return;
}
}
if (!empty($this->link)) {
try {
$post_url_file = MediaFile::fromLink($this->link, $this->auth_user);
} catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode(), $this->format);
return;
}
}
$upload2 = null;
try {
$upload2 = MediaFile::fromUpload('media2', $this->auth_user);
} catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode(), $this->format);
return;
}
$upload = null;
try {
$upload = MediaFile::fromUpload('media', $this->auth_user);
} catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode(), $this->format);
return;
}
if (isset($upload)) {
if (Notice::contentTooLong($status_shortened)) {
$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());
$this->clientError(sprintf($msg, Notice::maxContent()), 400, $this->format);
}
}
$content = html_entity_decode($status_shortened, ENT_NOQUOTES, 'UTF-8');
$options = array('reply_to' => $reply_to);
if ($this->auth_user->shareLocation()) {
$locOptions = Notice::locationOptions($this->lat, $this->lon, null, null, $this->auth_user->getProfile());
$options = array_merge($options, $locOptions);
//.........这里部分代码省略.........
示例7: doPost
/**
* This doPost saves 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
*/
protected function doPost()
{
assert($this->scoped instanceof Profile);
// XXX: maybe an error instead...
$user = $this->scoped->getUser();
$content = $this->trimmed('status_textarea');
$options = array();
Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
if (empty($content)) {
// TRANS: Client error displayed trying to send a notice without content.
$this->clientError(_('No content!'));
}
$inter = new CommandInterpreter();
$cmd = $inter->handle_command($user, $content);
if ($cmd) {
if (GNUsocial::isAjax()) {
$cmd->execute(new AjaxWebChannel($this));
} else {
$cmd->execute(new WebChannel($this));
}
return;
}
$content_shortened = $user->shortenLinks($content);
if (Notice::contentTooLong($content_shortened)) {
// TRANS: Client error displayed when the parameter "status" is missing.
// TRANS: %d is the maximum number of character for a notice.
$this->clientError(sprintf(_m('That\'s too long. Maximum notice size is %d character.', 'That\'s too long. Maximum notice size is %d characters.', Notice::maxContent()), Notice::maxContent()));
}
$replyto = $this->int('inreplyto');
if ($replyto) {
$options['reply_to'] = $replyto;
}
$upload = null;
try {
// throws exception on failure
$upload = MediaFile::fromUpload('attach', $this->scoped);
if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options))) {
$content_shortened .= ' ' . $upload->shortUrl();
}
Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options));
if (Notice::contentTooLong($content_shortened)) {
$upload->delete();
// TRANS: Client error displayed exceeding the maximum notice length.
// TRANS: %d is the maximum length for a notice.
$this->clientError(sprintf(_m('Maximum notice size is %d character, including attachment URL.', 'Maximum notice size is %d characters, including attachment URL.', Notice::maxContent()), Notice::maxContent()));
}
} catch (NoUploadedMediaException $e) {
// simply no attached media to the new notice
}
if ($this->scoped->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'), $this->scoped);
} else {
$locOptions = Notice::locationOptions(null, null, null, null, $this->scoped);
}
$options = array_merge($options, $locOptions);
}
$author_id = $this->scoped->id;
$text = $content_shortened;
// Does the heavy-lifting for getting "To:" information
ToSelector::fillOptions($this, $options);
if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
$this->stored = Notice::saveNew($this->scoped->id, $content_shortened, 'web', $options);
if ($upload instanceof MediaFile) {
$upload->attachToNotice($this->stored);
}
Event::handle('EndNoticeSaveWeb', array($this, $this->stored));
}
Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content_shortened, &$options));
if (!GNUsocial::isAjax()) {
$url = common_local_url('shownotice', array('notice' => $this->stored->id));
common_redirect($url, 303);
}
return _('Saved the notice!');
}
示例8: 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');
$options = array();
Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
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 = $user->shortenLinks($content);
if (Notice::contentTooLong($content_shortened)) {
// TRANS: Client error displayed when the parameter "status" is missing.
// TRANS: %d is the maximum number of character for a notice.
$this->clientError(sprintf(_m('That\'s too long. Maximum notice size is %d character.', 'That\'s too long. Maximum notice size is %d characters.', Notice::maxContent()), Notice::maxContent()));
}
$replyto = intval($this->trimmed('inreplyto'));
if ($replyto) {
$options['reply_to'] = $replyto;
}
$upload = null;
$upload = MediaFile::fromUpload('attach');
if (isset($upload)) {
if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options))) {
$content_shortened .= ' ' . $upload->shortUrl();
}
Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options));
if (Notice::contentTooLong($content_shortened)) {
$upload->delete();
$this->clientError(sprintf(_m('Maximum notice size is %d character, including attachment URL.', 'Maximum notice size is %d characters, including attachment URL.', Notice::maxContent()), Notice::maxContent()));
}
}
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);
}
$author_id = $user->id;
$text = $content_shortened;
if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
$notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
if (isset($upload)) {
$upload->attachToNotice($notice);
}
Event::handle('EndNoticeSaveWeb', array($this, $notice));
}
Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content_shortened, &$options));
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);
}
}
示例9: doPost
/**
* This doPost saves 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
*/
protected function doPost()
{
assert($this->scoped instanceof Profile);
// XXX: maybe an error instead...
$user = $this->scoped->getUser();
$content = $this->trimmed('status_textarea');
$options = array('source' => 'web');
Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
if (empty($content)) {
// TRANS: Client error displayed trying to send a notice without content.
$this->clientError(_('No content!'));
}
$inter = new CommandInterpreter();
$cmd = $inter->handle_command($user, $content);
if ($cmd) {
if (GNUsocial::isAjax()) {
$cmd->execute(new AjaxWebChannel($this));
} else {
$cmd->execute(new WebChannel($this));
}
return;
}
if ($this->int('inreplyto')) {
// Throws exception if the inreplyto Notice is given but not found.
$parent = Notice::getByID($this->int('inreplyto'));
} else {
$parent = null;
}
$act = new Activity();
$act->verb = ActivityVerb::POST;
$act->time = time();
$act->actor = $this->scoped->asActivityObject();
$upload = null;
try {
// throws exception on failure
$upload = MediaFile::fromUpload('attach', $this->scoped);
if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options))) {
$content .= ' ' . $upload->shortUrl();
}
Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options));
// We could check content length here if the URL was added, but I'll just let it slide for now...
$act->enclosures[] = $upload->getEnclosure();
} catch (NoUploadedMediaException $e) {
// simply no attached media to the new notice
}
// Reject notice if it is too long (without the HTML)
// This is done after MediaFile::fromUpload etc. just to act the same as the ApiStatusesUpdateAction
if (Notice::contentTooLong($content)) {
// TRANS: Client error displayed when the parameter "status" is missing.
// TRANS: %d is the maximum number of character for a notice.
throw new ClientException(sprintf(_m('That\'s too long. Maximum notice size is %d character.', 'That\'s too long. Maximum notice size is %d characters.', Notice::maxContent()), Notice::maxContent()));
}
$act->context = new ActivityContext();
if ($parent instanceof Notice) {
$act->context->replyToID = $parent->getUri();
$act->context->replyToUrl = $parent->getUrl(true);
// maybe we don't have to send true here to force a URL?
}
if ($this->scoped->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'), $this->scoped);
} else {
$locOptions = Notice::locationOptions(null, null, null, null, $this->scoped);
}
$act->context->location = Location::fromOptions($locOptions);
}
$content = $this->scoped->shortenLinks($content);
// FIXME: Make sure NoticeTitle plugin gets a change to add the title to our activityobject!
if (Event::handle('StartNoticeSaveWeb', array($this, $this->scoped, &$content, &$options))) {
// FIXME: We should be able to get the attentions from common_render_content!
// and maybe even directly save whether they're local or not!
$act->context->attention = common_get_attentions($content, $this->scoped, $parent);
$actobj = new ActivityObject();
$actobj->type = ActivityObject::NOTE;
$actobj->content = common_render_content($content, $this->scoped, $parent);
// Finally add the activity object to our activity
$act->objects[] = $actobj;
$this->stored = Notice::saveActivity($act, $this->scoped, $options);
if ($upload instanceof MediaFile) {
$upload->attachToNotice($this->stored);
}
Event::handle('EndNoticeSaveWeb', array($this, $this->stored));
}
Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content, &$options));
if (!GNUsocial::isAjax()) {
$url = common_local_url('shownotice', array('notice' => $this->stored->id));
common_redirect($url, 303);
}
//.........这里部分代码省略.........