X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=ifttt%2Fifttt.php;h=5021a63ed60cdd5482d7600e0505a27113bc2254;hb=c15b83d9c0ee3b0827e875da7817cb4557528478;hp=bdb2b6076234c2ab808179dcb1b2b687eb08eec1;hpb=dbe8118e406510d85404d9577f83d68782cfe2a0;p=friendica-addons.git diff --git a/ifttt/ifttt.php b/ifttt/ifttt.php index bdb2b607..5021a63e 100644 --- a/ifttt/ifttt.php +++ b/ifttt/ifttt.php @@ -7,25 +7,20 @@ * Author: Michael Vogel */ require_once 'mod/item.php'; -require_once 'include/items.php'; -require_once 'include/text.php'; - use Friendica\App; -use Friendica\Core\Addon; -use Friendica\Core\L10n; -use Friendica\Core\PConfig; -use Friendica\Database\DBM; +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\Util\Strings; function ifttt_install() { - Addon::registerHook('connector_settings', 'addon/ifttt/ifttt.php', 'ifttt_settings'); - Addon::registerHook('connector_settings_post', 'addon/ifttt/ifttt.php', 'ifttt_settings_post'); -} - -function ifttt_uninstall() -{ - Addon::unregisterHook('connector_settings', 'addon/ifttt/ifttt.php', 'ifttt_settings'); - Addon::unregisterHook('connector_settings_post', 'addon/ifttt/ifttt.php', 'ifttt_settings_post'); + Hook::register('connector_settings', 'addon/ifttt/ifttt.php', 'ifttt_settings'); + Hook::register('connector_settings_post', 'addon/ifttt/ifttt.php', 'ifttt_settings_post'); } function ifttt_module() @@ -44,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 = random_string(20); - PConfig::set(local_user(), 'ifttt', 'key', $key); + $key = Strings::getRandomHex(20); + 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 (x($_POST, 'ifttt-submit') && isset($_POST['ifttt-rekey'])) { - PConfig::delete(local_user(), 'ifttt', 'key'); + if (!empty($_POST['ifttt-submit']) && isset($_POST['ifttt-rekey'])) { + DI::pConfig()->delete(local_user(), 'ifttt', 'key'); } } @@ -99,26 +94,26 @@ function ifttt_post(App $a) $nickname = $a->argv[1]; - $user = dba::selectFirst('user', ['uid'], ['nickname' => $nickname]); - if (!DBM::is_result($user)) { - logger('User ' . $nickname . ' not found.', LOGGER_DEBUG); + $user = DBA::selectFirst('user', ['uid'], ['nickname' => $nickname]); + if (!DBA::isResult($user)) { + Logger::log('User ' . $nickname . ' not found.', Logger::DEBUG); return; } $uid = $user['uid']; - logger('Received a post for user ' . $uid . ' from ifttt ' . print_r($_REQUEST, true), LOGGER_DEBUG); + Logger::log('Received a post for user ' . $uid . ' from ifttt ' . print_r($_REQUEST, true), Logger::DEBUG); if (!isset($_REQUEST['key'])) { - logger('No key found.'); + Logger::log('No key found.'); return; } $key = $_REQUEST['key']; // Check the key - if ($key != PConfig::get($uid, 'ifttt', 'key')) { - logger('Invalid key for user ' . $uid, LOGGER_DEBUG); + if ($key != DI::pConfig()->get($uid, 'ifttt', 'key')) { + Logger::log('Invalid key for user ' . $uid, Logger::DEBUG); return; } @@ -129,7 +124,7 @@ function ifttt_post(App $a) } if (!in_array($item['type'], ['status', 'link', 'photo'])) { - logger('Unknown item type ' . $item['type'], LOGGER_DEBUG); + Logger::log('Unknown item type ' . $item['type'], Logger::DEBUG); return; } @@ -164,13 +159,12 @@ 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['type'] = 'wall'; $_REQUEST['api_source'] = true; $_REQUEST['profile_uid'] = $uid; $_REQUEST['source'] = 'IFTTT'; @@ -179,14 +173,14 @@ function ifttt_message($uid, $item) //$_REQUEST['date'] = $item['date']; //$_REQUEST['uri'] = $item['url']; - if (strstr($item['url'], 'facebook.com')) { - $hash = hash('ripemd128', item['url']); - $_REQUEST['extid'] = NETWORK_FACEBOOK; - $_REQUEST['message_id'] = item_new_uri($a->get_hostname(), $uid, NETWORK_FACEBOOK . ':' . $hash); + 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); } if ($item['type'] == 'link') { - $data = query_page_info($item['link']); + $data = PageInfo::queryUrl($item['link']); if (isset($item['title']) && (trim($item['title']) != '')) { $data['title'] = $item['title']; @@ -196,7 +190,7 @@ function ifttt_message($uid, $item) $data['text'] = $item['description']; } - $_REQUEST['body'] .= add_page_info_data($data); + $_REQUEST['body'] .= "\n" . PageInfo::getFooterFromData($data); } elseif (($item['type'] == 'photo') && ($item['image'] != '')) { $_REQUEST['body'] .= "\n\n[img]" . $item['image'] . "[/img]\n"; }