X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=ifttt%2Fifttt.php;h=45ba2bf9a020a9cfc3cd61c7d3ea3203393ef8f8;hb=7509ce88b934a321369f5eeb5eb2b371b222878d;hp=2e48319ab777656663601ba9625472bd5c127198;hpb=1454abfdb48b8ba452d897d90f6979bb4f23912c;p=friendica-addons.git diff --git a/ifttt/ifttt.php b/ifttt/ifttt.php index 2e48319a..45ba2bf9 100644 --- a/ifttt/ifttt.php +++ b/ifttt/ifttt.php @@ -7,27 +7,25 @@ * 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\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'); + Hook::register('connector_settings', 'addon/ifttt/ifttt.php', 'ifttt_settings'); + Hook::register('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::unregister('connector_settings', 'addon/ifttt/ifttt.php', 'ifttt_settings'); + Hook::unregister('connector_settings_post', 'addon/ifttt/ifttt.php', 'ifttt_settings_post'); } function ifttt_module() @@ -46,50 +44,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'); } } @@ -103,24 +101,24 @@ function ifttt_post(App $a) $user = DBA::selectFirst('user', ['uid'], ['nickname' => $nickname]); if (!DBA::isResult($user)) { - logger('User ' . $nickname . ' not found.', LOGGER_DEBUG); + 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; } @@ -131,7 +129,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; } @@ -166,7 +164,7 @@ function ifttt_post(App $a) function ifttt_message($uid, $item) { - $a = get_app(); + $a = DI::app(); $_SESSION['authenticated'] = true; $_SESSION['uid'] = $uid;