$o = conversation($a, [array_merge($contact_record, $datarray)], 'search', false, true);
System::jsonExit(['preview' => $o]);
- } elseif (!empty($_REQUEST['scheduled_at'])) {
+ }
+
+ Hook::callAll('post_local',$datarray);
+
+ if (!empty($_REQUEST['scheduled_at'])) {
$scheduled_at = DateTimeFormat::convert($_REQUEST['scheduled_at'], 'UTC', $a->getTimezone());
if ($scheduled_at > DateTimeFormat::utcNow()) {
unset($datarray['created']);
unset($datarray['edit']);
unset($datarray['self']);
unset($datarray['api_source']);
-
- Post\Delayed::add($datarray['uri'], $datarray, PRIORITY_HIGH, false, $scheduled_at);
+
+ Post\Delayed::add($datarray['uri'], $datarray, PRIORITY_HIGH, Post\Delayed::PREPARED_NO_HOOK, $scheduled_at);
item_post_return(DI::baseUrl(), $api_source, $return_path);
}
}
- $datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']);
-
- Hook::callAll('post_local',$datarray);
-
if (!empty($datarray['cancel'])) {
Logger::info('mod_item: post cancelled by addon.');
if ($return_path) {
System::jsonExit($json);
}
+ $datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']);
+
if ($orig_post) {
// Fill the cache field
// This could be done in Item::update as well - but we have to check for the existance of some fields.
return GRAVITY_UNKNOWN; // Should not happen
}
- public static function insert($item, $notify = false, $dontcache = false)
+ public static function insert(array $item, bool $notify = false, bool $post_local = true)
{
$orig_item = $item;
$item["private"] = self::PRIVATE;
}
- if ($notify) {
+ if ($notify && $post_local) {
$item['edit'] = false;
$item['parent'] = $parent_id;
unset($_SESSION['authenticated']);
unset($_SESSION['uid']);
}
- } else {
+ } elseif (!$notify) {
Hook::callAll('post_remote', $item);
}
return 0;
}
- if (!$dontcache) {
- if ($notify) {
- if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == GRAVITY_COMMENT)) {
- Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']);
- }
- Hook::callAll('post_local_end', $posted_item);
- } else {
- Hook::callAll('post_remote_end', $posted_item);
+ if ($notify) {
+ if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == GRAVITY_COMMENT)) {
+ Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']);
}
+ Hook::callAll('post_local_end', $posted_item);
+ } else {
+ Hook::callAll('post_remote_end', $posted_item);
}
if ($posted_item['gravity'] === GRAVITY_PARENT) {
}
}
- $distributed = self::insert($item, $notify, true);
+ $distributed = self::insert($item, $notify);
if (!$distributed) {
Logger::info("Distributed item wasn't stored", ['uri-id' => $item['uri-id'], 'user' => $uid]);
$item['contact-id'] = $item['author-id'];
}
- $public_shadow = self::insert($item, false, true);
+ $public_shadow = self::insert($item);
Logger::info('Stored public shadow', ['thread' => $itemid, 'id' => $public_shadow]);
}
unset($item['post-reason']);
$item['contact-id'] = Contact::getIdForURL($item['author-link']);
- $public_shadow = self::insert($item, false, true);
+ $public_shadow = self::insert($item);
Logger::info('Stored public shadow', ['uri-id' => $item['uri-id'], 'id' => $public_shadow]);
class Delayed
{
+ const PREPARED = 0;
+ const UNPREPARED = 1;
+ const PREPARED_NO_HOOK = 2;
+
/**
* Insert a new delayed post
*
- * @param string $uri
- * @param array $item
- * @param integer $notify
- * @param bool $unprepared
- * @param string $delayed
- * @param array $taglist
- * @param array $attachments
- * @return int ID of the created delayed post entry
+ * @param string $uri
+ * @param array $item
+ * @param int $notify
+ * @param int $preparation_mode
+ * @param string $delayed
+ * @param array $taglist
+ * @param array $attachments
+ * @return int ID of the created delayed post entry
*/
- public static function add(string $uri, array $item, int $notify = 0, bool $unprepared = false, string $delayed = '', array $taglist = [], array $attachments = [])
+ public static function add(string $uri, array $item, int $notify = 0, int $preparation_mode = self::PREPARED, string $delayed = '', array $taglist = [], array $attachments = [])
{
if (empty($item['uid']) || self::exists($uri, $item['uid'])) {
Logger::notice('No uid or already found');
Logger::notice('Adding post for delayed publishing', ['uid' => $item['uid'], 'delayed' => $delayed, 'uri' => $uri]);
- $wid = Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments, $unprepared, $uri);
+ $wid = Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments, $preparation_mode, $uri);
if (!$wid) {
return 0;
}
/**
* Publish a delayed post
*
- * @param array $item
- * @param integer $notify
- * @param array $taglist
- * @param array $attachments
- * @param bool $unprepared
+ * @param array $item
+ * @param int $notify
+ * @param array $taglist
+ * @param array $attachments
+ * @param int $preparation_mode
* @param string $uri
* @return bool
*/
- public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false, string $uri = '')
+ public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = self::PREPARED, string $uri = '')
{
if (!empty($attachments)) {
$item['attachments'] = $attachments;
}
- if ($unprepared) {
+ if ($preparation_mode == self::UNPREPARED) {
$_SESSION['authenticated'] = true;
$_SESSION['uid'] = $item['uid'];
return $id;
}
- $id = Item::insert($item, $notify);
+
+ $id = Item::insert($item, $notify, $preparation_mode == self::PREPARED);
Logger::notice('Post stored', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id']]);
if (!empty($request['scheduled_at'])) {
$item['guid'] = Item::guid($item, true);
$item['uri'] = Item::newURI($item['uid'], $item['guid']);
- $id = Post\Delayed::add($item['uri'], $item, PRIORITY_HIGH, false, $request['scheduled_at']);
+ $id = Post\Delayed::add($item['uri'], $item, PRIORITY_HIGH, Post\Delayed::PREPARED, $request['scheduled_at']);
if (empty($id)) {
DI::mstdnError()->InternalError();
}
}
$publish_at = date(DateTimeFormat::MYSQL, $publish_time);
- if (Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], false, $publish_at, $posting['taglist'], $posting['attachments'])) {
+ if (Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], Post\Delayed::PREPARED, $publish_at, $posting['taglist'], $posting['attachments'])) {
DI::pConfig()->set($item['uid'], 'system', 'last_publish', $publish_time);
}
}
/**
* Publish a post, used for delayed postings
*
- * @param array $item
- * @param integer $notify
- * @param array $taglist
- * @param array $attachments
- * @param bool $unprepared
+ * @param array $item
+ * @param int $notify
+ * @param array $taglist
+ * @param array $attachments
+ * @param int $preparation_mode
* @param string $uri
* @return void
*/
- public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false, string $uri = '')
+ public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = Post\Delayed::PREPARED, string $uri = '')
{
- $id = Post\Delayed::publish($item, $notify, $taglist, $attachments, $unprepared, $uri);
- Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'notify' => $notify, 'unprepared' => $unprepared]);
+ $id = Post\Delayed::publish($item, $notify, $taglist, $attachments, $preparation_mode, $uri);
+ Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'notify' => $notify, 'unprepared' => $preparation_mode]);
}
}