X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=ifttt%2Fifttt.php;h=a0cc1ae806af1ad818d948cf263c867f338d8fc3;hb=f4f61aa1518857247f012f27e28e45a9d0813090;hp=a18914994a0b705307b14c77104ccdd127a48856;hpb=c27b1cb66fd0877da0947edfdad1a62dfaf41888;p=friendica-addons.git diff --git a/ifttt/ifttt.php b/ifttt/ifttt.php index a1891499..a0cc1ae8 100644 --- a/ifttt/ifttt.php +++ b/ifttt/ifttt.php @@ -6,18 +6,15 @@ * Version: 0.1 * Author: Michael Vogel */ -require_once 'mod/item.php'; -require_once 'include/items.php'; -require_once 'include/text.php'; - use Friendica\App; +use Friendica\Content\PageInfo; use Friendica\Core\Hook; -use Friendica\Core\L10n; use Friendica\Core\Logger; -use Friendica\Core\PConfig; 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() @@ -26,12 +23,6 @@ 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() { @@ -48,50 +39,50 @@ function ifttt_settings(App $a, &$s) return; } - $key = PConfig::get(local_user(), 'ifttt', 'key'); + $key = DI::pConfig()->get(local_user(), 'ifttt', 'key'); if (!$key) { $key = Strings::getRandomHex(20); - PConfig::set(local_user(), 'ifttt', 'key', $key); + DI::pConfig()->set(local_user(), 'ifttt', 'key', $key); } $s .= ''; - $s .= '

' . L10n::t('IFTTT Mirror') . '

'; + $s .= '

' . DI::l10n()->t('IFTTT Mirror') . '

'; $s .= '
'; $s .= ''; } function ifttt_settings_post() { if (!empty($_POST['ifttt-submit']) && isset($_POST['ifttt-rekey'])) { - PConfig::delete(local_user(), 'ifttt', 'key'); + DI::pConfig()->delete(local_user(), 'ifttt', 'key'); } } @@ -121,7 +112,7 @@ function ifttt_post(App $a) $key = $_REQUEST['key']; // Check the key - if ($key != PConfig::get($uid, 'ifttt', 'key')) { + if ($key != DI::pConfig()->get($uid, 'ifttt', 'key')) { Logger::log('Invalid key for user ' . $uid, Logger::DEBUG); return; } @@ -168,28 +159,19 @@ function ifttt_post(App $a) function ifttt_message($uid, $item) { - $a = get_app(); + $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']; @@ -199,10 +181,15 @@ function ifttt_message($uid, $item) $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); }