* Version: 0.1
* Author: Michael Vogel <https://pirati.ca/profile/heluecht>
*/
-require_once 'mod/item.php';
use Friendica\App;
+use Friendica\Content\PageInfo;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
+use Friendica\Model\Post;
use Friendica\Util\Strings;
function ifttt_install()
Hook::register('connector_settings_post', 'addon/ifttt/ifttt.php', 'ifttt_settings_post');
}
-function ifttt_uninstall()
-{
- Hook::unregister('connector_settings', 'addon/ifttt/ifttt.php', 'ifttt_settings');
- Hook::unregister('connector_settings_post', 'addon/ifttt/ifttt.php', 'ifttt_settings_post');
-}
-
function ifttt_module()
{
{
$a = DI::app();
- $_SESSION['authenticated'] = true;
- $_SESSION['uid'] = $uid;
-
- unset($_REQUEST);
- $_REQUEST['api_source'] = true;
- $_REQUEST['profile_uid'] = $uid;
- $_REQUEST['source'] = 'IFTTT';
- $_REQUEST['title'] = '';
- $_REQUEST['body'] = $item['msg'];
- //$_REQUEST['date'] = $item['date'];
- //$_REQUEST['uri'] = $item['url'];
-
- if (!empty($item['url']) && strstr($item['url'], 'facebook.com')) {
- $hash = hash('ripemd128', $item['url']);
- $_REQUEST['extid'] = Protocol::FACEBOOK;
- $_REQUEST['message_id'] = Item::newURI($uid, Protocol::FACEBOOK . ':' . $hash);
- }
+ $post = [];
+ $post['uid'] = $uid;
+ $post['app'] = 'IFTTT';
+ $post['title'] = '';
+ $post['body'] = $item['msg'];
+ //$post['date'] = $item['date'];
+ //$post['uri'] = $item['url'];
if ($item['type'] == 'link') {
- $data = query_page_info($item['link']);
+ $link = $item['link'];
+ $data = PageInfo::queryUrl($item['link']);
if (isset($item['title']) && (trim($item['title']) != '')) {
$data['title'] = $item['title'];
$data['text'] = $item['description'];
}
- $_REQUEST['body'] .= add_page_info_data($data);
+ $post['body'] .= "\n" . PageInfo::getFooterFromData($data);
} 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);
}