X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=ifttt%2Fifttt.php;h=bdb2b6076234c2ab808179dcb1b2b687eb08eec1;hb=bfd8e37fb89c74bc1ba588845c8d7a7e817e0544;hp=ddd517e2603bcd333a965172a33fd6d0e2698597;hpb=c3e93f1ed9a487f823bcc75ddd43024334c25bfc;p=friendica-addons.git
diff --git a/ifttt/ifttt.php b/ifttt/ifttt.php
index ddd517e2..bdb2b607 100644
--- a/ifttt/ifttt.php
+++ b/ifttt/ifttt.php
@@ -1,181 +1,205 @@
*/
+require_once 'mod/item.php';
+require_once 'include/items.php';
+require_once 'include/text.php';
-require_once("mod/item.php");
-require_once("include/items.php");
-
+use Friendica\App;
+use Friendica\Core\Addon;
+use Friendica\Core\L10n;
use Friendica\Core\PConfig;
+use Friendica\Database\DBM;
-function ifttt_install() {
- register_hook('connector_settings', 'addon/ifttt/ifttt.php', 'ifttt_settings');
- register_hook('connector_settings_post','addon/ifttt/ifttt.php', 'ifttt_settings_post');
+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() {
- unregister_hook('connector_settings', 'addon/ifttt/ifttt.php', 'ifttt_settings');
- unregister_hook('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');
}
-function ifttt_module() {
-}
+function ifttt_module()
+{
-function ifttt_content(&$a) {
}
-function ifttt_settings(&$a,&$s) {
+function ifttt_content()
+{
- if(! local_user())
- return;
+}
+
+function ifttt_settings(App $a, &$s)
+{
+ if (!local_user()) {
+ return;
+ }
- $key = PConfig::get(local_user(),'ifttt','key');
+ $key = PConfig::get(local_user(), 'ifttt', 'key');
if (!$key) {
- $key = substr(random_string(),0,20);
- PConfig::set(local_user(),'ifttt','key', $key);
+ $key = random_string(20);
+ PConfig::set(local_user(), 'ifttt', 'key', $key);
}
$s .= '';
- $s .= ''. t('IFTTT Mirror').' ';
- $s .= ' ';
- $s .= '
';
- $s .= '
';
- $s .= ''. t('IFTTT Mirror').' ';
- $s .= ' ';
-
- $s .= '
';
- $s .= '
'.t("Create an account at IFTTT . Create three Facebook recipes that are connected with Maker (In the form 'if Facebook then Maker') with the following parameters:").'
';
+ $s .= '
' . L10n::t('IFTTT Mirror') . ' ';
+ $s .= '';
+ $s .= '
';
+ $s .= '
';
+ $s .= '' . L10n::t('IFTTT Mirror') . ' ';
+ $s .= ' ';
+
+ $s .= '
';
+ $s .= '
' . L10n::t('Create an account at IFTTT . Create three Facebook recipes that are connected with Maker (In the form "if Facebook then Maker") with the following parameters:') . '
';
$s .= '
URL ';
$s .= '
' . $a->get_baseurl() . '/ifttt/' . $a->user['nickname'] . '
';
$s .= '
Method ';
$s .= '
POST
';
$s .= '
Content Type ';
$s .= '
application/x-www-form-urlencoded
';
- $s .= '
'.t("Body for 'new status message'").' ';
- $s .= '
'.htmlentities('key='.$key.'&type=status&msg=<<<{{Message}}>>>&date=<<<{{UpdatedAt}}>>>&url=<<<{{PageUrl}}>>>').'
';
- $s .= '
'.t("Body for 'new photo upload'").' ';
- $s .= '
'.htmlentities('key='.$key.'&type=photo&link=<<<{{Link}}>>>&image=<<<{{ImageSource}}>>>&msg=<<<{{Caption}}>>>&date=<<<{{CreatedAt}}>>>&url=<<<{{PageUrl}}>>>').'
';
- $s .= '
'.t("Body for 'new link post'").' ';
- $s .= '
'.htmlentities('key='.$key.'&type=link&link=<<<{{Link}}>>>&title=<<<{{Title}}>>>&msg=<<<{{Message}}>>>&description=<<<{{Description}}>>>&date=<<<{{CreatedAt}}>>>&url=<<<{{PageUrl}}>>>').'
';
- $s .= '
';
-
- $s .= '
';
- $s .= '' . t('Generate new key') . ' ';
- $s .= ' ';
- $s .= '
';
-
- $s .= '
';
- $s .= '
';
-
+ $s .= '
' . L10n::t('Body for "new status message"') . ' ';
+ $s .= '
' . htmlentities('key=' . $key . '&type=status&msg=<<<{{Message}}>>>&date=<<<{{UpdatedAt}}>>>&url=<<<{{PageUrl}}>>>') . '
';
+ $s .= '
' . L10n::t('Body for "new photo upload"') . ' ';
+ $s .= '
' . htmlentities('key=' . $key . '&type=photo&link=<<<{{Link}}>>>&image=<<<{{ImageSource}}>>>&msg=<<<{{Caption}}>>>&date=<<<{{CreatedAt}}>>>&url=<<<{{PageUrl}}>>>') . '
';
+ $s .= '
' . L10n::t('Body for "new link post"') . ' ';
+ $s .= '
' . htmlentities('key=' . $key . '&type=link&link=<<<{{Link}}>>>&title=<<<{{Title}}>>>&msg=<<<{{Message}}>>>&description=<<<{{Description}}>>>&date=<<<{{CreatedAt}}>>>&url=<<<{{PageUrl}}>>>') . '
';
+ $s .= '
';
+
+ $s .= '
';
+ $s .= '' . L10n::t('Generate new key') . ' ';
+ $s .= ' ';
+ $s .= '
';
+
+ $s .= '
';
+ $s .= '
';
}
-function ifttt_settings_post(&$a,&$b) {
-
- if(x($_POST,'ifttt-submit'))
- if (isset($_POST['ifttt-rekey']))
- del_pconfig(local_user(), 'ifttt', 'key');
+function ifttt_settings_post()
+{
+ if (x($_POST, 'ifttt-submit') && isset($_POST['ifttt-rekey'])) {
+ PConfig::delete(local_user(), 'ifttt', 'key');
+ }
}
-function ifttt_post(&$a) {
- if ($a->argc != 2)
+function ifttt_post(App $a)
+{
+ if ($a->argc != 2) {
return;
+ }
- $user = $a->argv[1];
+ $nickname = $a->argv[1];
- $r = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1", dbesc($user));
- if (!$r) {
- logger("User ".$user." not found.", LOGGER_DEBUG);
+ $user = dba::selectFirst('user', ['uid'], ['nickname' => $nickname]);
+ if (!DBM::is_result($user)) {
+ logger('User ' . $nickname . ' not found.', LOGGER_DEBUG);
return;
}
- $uid = $r[0]["uid"];
+ $uid = $user['uid'];
- logger("Received a post for user ".$uid." from ifttt ".print_r($_REQUEST, true), LOGGER_DEBUG);
+ logger('Received a post for user ' . $uid . ' from ifttt ' . print_r($_REQUEST, true), LOGGER_DEBUG);
- if (!isset($_REQUEST["key"])) {
- logger("No key found.");
+ if (!isset($_REQUEST['key'])) {
+ logger('No key found.');
return;
}
- $key = $_REQUEST["key"];
+ $key = $_REQUEST['key'];
// Check the key
- if ($key != PConfig::get($uid,'ifttt','key')) {
- logger("Invalid key for user ".$uid, LOGGER_DEBUG);
+ if ($key != PConfig::get($uid, 'ifttt', 'key')) {
+ logger('Invalid key for user ' . $uid, LOGGER_DEBUG);
return;
}
- $item = array();
+ $item = [];
- if (isset($_REQUEST["type"]))
- $item["type"] = $_REQUEST["type"];
+ if (isset($_REQUEST['type'])) {
+ $item['type'] = $_REQUEST['type'];
+ }
- if (!in_array($item["type"], array("status", "link", "photo"))) {
- logger("Unknown item type ".$item["type"], LOGGER_DEBUG);
+ if (!in_array($item['type'], ['status', 'link', 'photo'])) {
+ logger('Unknown item type ' . $item['type'], LOGGER_DEBUG);
return;
}
- if (isset($_REQUEST["link"]))
- $item["link"] = trim($_REQUEST["link"]);
- if (isset($_REQUEST["image"]))
- $item["image"] = trim($_REQUEST["image"]);
- if (isset($_REQUEST["title"]))
- $item["title"] = trim($_REQUEST["title"]);
- if (isset($_REQUEST["msg"]))
- $item["msg"] = trim($_REQUEST["msg"]);
- if (isset($_REQUEST["description"]))
- $item["description"] = trim($_REQUEST["description"]);
- if (isset($_REQUEST["date"]))
- $item["date"] = date("c", strtotime($date = str_replace(" at ", ", ", $_REQUEST["date"])));
- if (isset($_REQUEST["url"]))
- $item["url"] = trim($_REQUEST["url"]);
-
- if ((substr($item["msg"], 0, 3) == "<<<") && (substr($item["msg"], -3, 3) == ">>>"))
- $item["msg"] = substr($item["msg"], 3, -3);
+ if (isset($_REQUEST['link'])) {
+ $item['link'] = trim($_REQUEST['link']);
+ }
+ if (isset($_REQUEST['image'])) {
+ $item['image'] = trim($_REQUEST['image']);
+ }
+ if (isset($_REQUEST['title'])) {
+ $item['title'] = trim($_REQUEST['title']);
+ }
+ if (isset($_REQUEST['msg'])) {
+ $item['msg'] = trim($_REQUEST['msg']);
+ }
+ if (isset($_REQUEST['description'])) {
+ $item['description'] = trim($_REQUEST['description']);
+ }
+ if (isset($_REQUEST['date'])) {
+ $item['date'] = date('c', strtotime($date = str_replace(' at ', ', ', $_REQUEST['date'])));
+ }
+ if (isset($_REQUEST['url'])) {
+ $item['url'] = trim($_REQUEST['url']);
+ }
+
+ if ((substr($item['msg'], 0, 3) == '<<<') && (substr($item['msg'], -3, 3) == '>>>')) {
+ $item['msg'] = substr($item['msg'], 3, -3);
+ }
ifttt_message($uid, $item);
}
-function ifttt_message($uid, $item) {
-
+function ifttt_message($uid, $item)
+{
$a = get_app();
- $_SESSION["authenticated"] = true;
- $_SESSION["uid"] = $uid;
+ $_SESSION['authenticated'] = true;
+ $_SESSION['uid'] = $uid;
unset($_REQUEST);
- $_REQUEST["type"] = "wall";
- $_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 (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);
+ $_REQUEST['type'] = 'wall';
+ $_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 (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 ($item["type"] == "link") {
- $data = query_page_info($item["link"]);
+ if ($item['type'] == 'link') {
+ $data = query_page_info($item['link']);
- if (isset($item["title"]) && (trim($item["title"]) != ""))
- $data["title"] = $item["title"];
+ if (isset($item['title']) && (trim($item['title']) != '')) {
+ $data['title'] = $item['title'];
+ }
- if (isset($item["description"]) && (trim($item["description"]) != ""))
- $data["text"] = $item["description"];
+ if (isset($item['description']) && (trim($item['description']) != '')) {
+ $data['text'] = $item['description'];
+ }
- $_REQUEST["body"] .= add_page_info_data($data);
- } elseif (($item["type"] == "photo") && ($item["image"] != ""))
- $_REQUEST["body"] .= "\n\n[img]".$item["image"]."[/img]\n";
+ $_REQUEST['body'] .= add_page_info_data($data);
+ } elseif (($item['type'] == 'photo') && ($item['image'] != '')) {
+ $_REQUEST['body'] .= "\n\n[img]" . $item['image'] . "[/img]\n";
+ }
- //print_r($_REQUEST);
item_post($a);
}