]> git.mxchange.org Git - friendica-addons.git/blobdiff - ifttt/ifttt.php
[pageheader] code cleanup
[friendica-addons.git] / ifttt / ifttt.php
index 14add12a28a4adadf18ec7a589bd5120ab018b28..3bb55f3568b99362a5585442e92da12f88ed4b71 100644 (file)
@@ -7,26 +7,26 @@
  * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
  */
 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\Hook;
 use Friendica\Core\L10n;
+use Friendica\Core\Logger;
 use Friendica\Core\PConfig;
+use Friendica\Core\Protocol;
 use Friendica\Database\DBA;
 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()
@@ -48,7 +48,7 @@ function ifttt_settings(App $a, &$s)
        $key = PConfig::get(local_user(), 'ifttt', 'key');
 
        if (!$key) {
-               $key = random_string(20);
+               $key = Strings::getRandomHex(20);
                PConfig::set(local_user(), 'ifttt', 'key', $key);
        }
 
@@ -63,7 +63,7 @@ function ifttt_settings(App $a, &$s)
        $s .= '<div id="ifttt-configuration-wrapper">';
        $s .= '<p>' . L10n::t('Create an account at <a href="http://www.ifttt.com">IFTTT</a>. Create three Facebook recipes that are connected with <a href="https://ifttt.com/maker">Maker</a> (In the form "if Facebook then Maker") with the following parameters:') . '</p>';
        $s .= '<h4>URL</h4>';
-       $s .= '<p>' . $a->get_baseurl() . '/ifttt/' . $a->user['nickname'] . '</p>';
+       $s .= '<p>' . $a->getBaseURL() . '/ifttt/' . $a->user['nickname'] . '</p>';
        $s .= '<h4>Method</h4>';
        $s .= '<p>POST</p>';
        $s .= '<h4>Content Type</h4>';
@@ -87,7 +87,7 @@ function ifttt_settings(App $a, &$s)
 
 function ifttt_settings_post()
 {
-       if (x($_POST, 'ifttt-submit') && isset($_POST['ifttt-rekey'])) {
+       if (!empty($_POST['ifttt-submit']) && isset($_POST['ifttt-rekey'])) {
                PConfig::delete(local_user(), 'ifttt', 'key');
        }
 }
@@ -102,16 +102,16 @@ 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;
        }
 
@@ -119,7 +119,7 @@ function ifttt_post(App $a)
 
        // Check the key
        if ($key != PConfig::get($uid, 'ifttt', 'key')) {
-               logger('Invalid key for user ' . $uid, LOGGER_DEBUG);
+               Logger::log('Invalid key for user ' . $uid, Logger::DEBUG);
                return;
        }
 
@@ -130,7 +130,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;
        }
 
@@ -165,7 +165,7 @@ function ifttt_post(App $a)
 
 function ifttt_message($uid, $item)
 {
-       $a = get_app();
+       $a = \get_app();
 
        $_SESSION['authenticated'] = true;
        $_SESSION['uid'] = $uid;
@@ -179,10 +179,10 @@ 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::newURI($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') {