mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-19 21:23:41 +00:00
IFTTT/Twitter: Support delayed posts
This commit is contained in:
parent
610d11d719
commit
fb6207f01f
2 changed files with 25 additions and 32 deletions
|
@ -6,7 +6,6 @@
|
||||||
* Version: 0.1
|
* Version: 0.1
|
||||||
* Author: Michael Vogel <https://pirati.ca/profile/heluecht>
|
* Author: Michael Vogel <https://pirati.ca/profile/heluecht>
|
||||||
*/
|
*/
|
||||||
require_once 'mod/item.php';
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Content\PageInfo;
|
use Friendica\Content\PageInfo;
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
|
@ -15,6 +14,7 @@ use Friendica\Core\Protocol;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
|
use Friendica\Model\Post;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
function ifttt_install()
|
function ifttt_install()
|
||||||
|
@ -161,25 +161,22 @@ function ifttt_message($uid, $item)
|
||||||
{
|
{
|
||||||
$a = DI::app();
|
$a = DI::app();
|
||||||
|
|
||||||
$_SESSION['authenticated'] = true;
|
$post = [];
|
||||||
$_SESSION['uid'] = $uid;
|
$post['uid'] = $uid;
|
||||||
|
$post['app'] = 'IFTTT';
|
||||||
unset($_REQUEST);
|
$post['title'] = '';
|
||||||
$_REQUEST['api_source'] = true;
|
$post['body'] = $item['msg'];
|
||||||
$_REQUEST['profile_uid'] = $uid;
|
//$post['date'] = $item['date'];
|
||||||
$_REQUEST['source'] = 'IFTTT';
|
//$post['uri'] = $item['url'];
|
||||||
$_REQUEST['title'] = '';
|
|
||||||
$_REQUEST['body'] = $item['msg'];
|
|
||||||
//$_REQUEST['date'] = $item['date'];
|
|
||||||
//$_REQUEST['uri'] = $item['url'];
|
|
||||||
|
|
||||||
if (!empty($item['url']) && strstr($item['url'], 'facebook.com')) {
|
if (!empty($item['url']) && strstr($item['url'], 'facebook.com')) {
|
||||||
$hash = hash('ripemd128', $item['url']);
|
$hash = hash('ripemd128', $item['url']);
|
||||||
$_REQUEST['extid'] = Protocol::FACEBOOK;
|
$post['extid'] = Protocol::FACEBOOK;
|
||||||
$_REQUEST['message_id'] = Item::newURI($uid, Protocol::FACEBOOK . ':' . $hash);
|
$post['message_id'] = Item::newURI($uid, Protocol::FACEBOOK . ':' . $hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($item['type'] == 'link') {
|
if ($item['type'] == 'link') {
|
||||||
|
$link = $item['link'];
|
||||||
$data = PageInfo::queryUrl($item['link']);
|
$data = PageInfo::queryUrl($item['link']);
|
||||||
|
|
||||||
if (isset($item['title']) && (trim($item['title']) != '')) {
|
if (isset($item['title']) && (trim($item['title']) != '')) {
|
||||||
|
@ -190,10 +187,15 @@ function ifttt_message($uid, $item)
|
||||||
$data['text'] = $item['description'];
|
$data['text'] = $item['description'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$_REQUEST['body'] .= "\n" . PageInfo::getFooterFromData($data);
|
$post['body'] .= "\n" . PageInfo::getFooterFromData($data);
|
||||||
} elseif (($item['type'] == 'photo') && ($item['image'] != '')) {
|
} elseif (($item['type'] == 'photo') && ($item['image'] != '')) {
|
||||||
$_REQUEST['body'] .= "\n\n[img]" . $item['image'] . "[/img]\n";
|
$link = $item['image'];
|
||||||
|
$post['body'] .= "\n\n[img]" . $item['image'] . "[/img]\n";
|
||||||
|
} elseif (!empty($item['url'])) {
|
||||||
|
$link = $item['url'];
|
||||||
|
} else {
|
||||||
|
$link = hash('ripemd128', $item['msg']);
|
||||||
}
|
}
|
||||||
|
|
||||||
item_post($a);
|
Post\Delayed::add($link, $post, PRIORITY_MEDIUM, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,7 @@ use Friendica\Model\Group;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\ItemContent;
|
use Friendica\Model\ItemContent;
|
||||||
use Friendica\Model\ItemURI;
|
use Friendica\Model\ItemURI;
|
||||||
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\Tag;
|
use Friendica\Model\Tag;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
|
@ -1004,11 +1005,7 @@ function twitter_parse_link(App $a, array &$b)
|
||||||
*/
|
*/
|
||||||
function twitter_do_mirrorpost(App $a, $uid, $post)
|
function twitter_do_mirrorpost(App $a, $uid, $post)
|
||||||
{
|
{
|
||||||
$datarray['api_source'] = true;
|
|
||||||
$datarray['profile_uid'] = $uid;
|
|
||||||
$datarray['extid'] = 'twitter::' . $post->id;
|
$datarray['extid'] = 'twitter::' . $post->id;
|
||||||
$datarray['protocol'] = Conversation::PARCEL_TWITTER;
|
|
||||||
$datarray['source'] = json_encode($post);
|
|
||||||
$datarray['title'] = '';
|
$datarray['title'] = '';
|
||||||
|
|
||||||
if (!empty($post->retweeted_status)) {
|
if (!empty($post->retweeted_status)) {
|
||||||
|
@ -1038,7 +1035,7 @@ function twitter_do_mirrorpost(App $a, $uid, $post)
|
||||||
$datarray['body'] = $item['body'];
|
$datarray['body'] = $item['body'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$datarray['source'] = $item['app'];
|
$datarray['app'] = $item['app'];
|
||||||
$datarray['verb'] = $item['verb'];
|
$datarray['verb'] = $item['verb'];
|
||||||
|
|
||||||
if (isset($item['location'])) {
|
if (isset($item['location'])) {
|
||||||
|
@ -1066,9 +1063,6 @@ function twitter_fetchtimeline(App $a, $uid)
|
||||||
$application_name = DI::baseUrl()->getHostname();
|
$application_name = DI::baseUrl()->getHostname();
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once 'mod/item.php';
|
|
||||||
require_once 'mod/share.php';
|
|
||||||
|
|
||||||
$connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
|
$connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
|
||||||
|
|
||||||
$parameters = ["exclude_replies" => true, "trim_user" => false, "contributor_details" => true, "include_rts" => true, "tweet_mode" => "extended", "include_ext_alt_text" => true];
|
$parameters = ["exclude_replies" => true, "trim_user" => false, "contributor_details" => true, "include_rts" => true, "tweet_mode" => "extended", "include_ext_alt_text" => true];
|
||||||
|
@ -1107,20 +1101,17 @@ function twitter_fetchtimeline(App $a, $uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stristr($post->source, $application_name)) {
|
if (!stristr($post->source, $application_name)) {
|
||||||
$_SESSION["authenticated"] = true;
|
|
||||||
$_SESSION["uid"] = $uid;
|
|
||||||
|
|
||||||
Logger::info('Preparing mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]);
|
Logger::info('Preparing mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]);
|
||||||
|
|
||||||
$_REQUEST = twitter_do_mirrorpost($a, $uid, $post);
|
$mirrorpost = twitter_do_mirrorpost($a, $uid, $post);
|
||||||
|
|
||||||
if (empty($_REQUEST['body'])) {
|
if (empty($mirrorpost['body'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::info('Posting mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]);
|
Logger::info('Posting mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]);
|
||||||
|
|
||||||
item_post($a);
|
Post\Delayed::add($mirrorpost['extid'], $mirrorpost, PRIORITY_MEDIUM, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue