From b8a720775332c0a80a909bb11d6a7f5ee234e9a2 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 11 Oct 2015 21:07:40 +0200 Subject: [PATCH 1/2] IFTTT: New plugin --- ifttt/ifttt.php | 177 ++++++++++++++++++++++++++++++++++++++++++++++++ ifttt/ifttt.png | Bin 0 -> 7733 bytes 2 files changed, 177 insertions(+) create mode 100644 ifttt/ifttt.php create mode 100644 ifttt/ifttt.png diff --git a/ifttt/ifttt.php b/ifttt/ifttt.php new file mode 100644 index 00000000..3203fec4 --- /dev/null +++ b/ifttt/ifttt.php @@ -0,0 +1,177 @@ + + */ + +require_once("mod/item.php"); +require_once("include/items.php"); + +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_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_module() { +} + +function ifttt_content(&$a) { +} + +function ifttt_settings(&$a,&$s) { + + if(! local_user()) + return; + + $key = get_pconfig(local_user(),'ifttt','key'); + + if (!$key) { + $key = substr(random_string(),0,20); + set_pconfig(local_user(),'ifttt','key', $key); + } + + $s .= ''; + $s .= '

'. t('IFTTT Mirror').'

'; + $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_post(&$a) { + if ($a->argc != 2) + return; + + $user = $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); + return; + } + + $uid = $r[0]["uid"]; + + logger("Received a post for user ".$uid." from ifttt ".print_r($_REQUEST, true), LOGGER_DEBUG); + + if (!isset($_REQUEST["key"])) { + logger("No key found."); + return; + } + + $key = $_REQUEST["key"]; + + // Check the key + if ($key != get_pconfig($uid,'ifttt','key')) { + logger("Invalid key for user ".$uid, LOGGER_DEBUG); + return; + } + + $item = array(); + + 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); + 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) == "<<<") AND (substr($item["msg"], -3, 3) == ">>>")) + $item["msg"] = substr($item["msg"], 3, -3); + + ifttt_message($uid, $item); +} + +function ifttt_message($uid, $item) { + + $a = get_app(); + + $_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")) + $_REQUEST["extid"] = NETWORK_FACEBOOK; + + if ($item["type"] == "link") { + $data = query_page_info($item["link"]); + + if (isset($item["title"]) AND (trim($item["title"]) != "")) + $data["title"] = $item["title"]; + + if (isset($item["description"]) AND (trim($item["description"]) != "")) + $data["text"] = $item["description"]; + + $_REQUEST["body"] .= add_page_info_data($data); + } elseif (($item["type"] == "photo") AND ($item["image"] != "")) + $_REQUEST["body"] .= "\n\n[img]".$item["image"]."[/img]\n"; + + //print_r($_REQUEST); + item_post($a); +} +?> diff --git a/ifttt/ifttt.png b/ifttt/ifttt.png new file mode 100644 index 0000000000000000000000000000000000000000..364edb0884b33249be670ccfb31a797652f012eb GIT binary patch literal 7733 zcmb7pby!qixA2)^fMEa~x?yOL2I(5Q8!43z>6V5;q!ADhrBgyc=>|~=X$0vSq(w?X zB=7Kh-}~PC{dd24&OB$wioMoeYwfkpj@8vxA%s!G001CVQ&rRl01&1L0-!jU*CVeo z``ezkzKT5XeuQ=#)4}slHT4Dne3IKg2*}K)!~mE&8k+c+XlY8=xV!RN*}7ZX@%p=Z zV4wj&%3lK0bhY!bLioG7xOq$XOEdigA%SV%4)ZY~{sHlEmS!^1(nTn^d)Xm`dGGV` zGs(aZ2!xcEt-XZ4qVm7dF+FLfCq6zN5`27qetx`uLcH!?4txUQ;^KV#f_#F4JQxTb z?*KO+D}Nq0Z{~jy`ENRkcHTB#jvhXa?rw-%x>nZizCO}SOt*~w^ZVC2eH`uohm)K4 zzs14`$ag!#C&0_k_aE9ARH@rh2^}v-I}GPr`Z5Ai|3LmfWB=wO#dpj6e=X);lKwM_ z5mg2z#rGez$-p!}vzr0{t*@G*oS{ExHzz28ZZf2AbZDWY&Cl=3#D;*f`dCH}q5= zEC46Ou-@4N4+7^p^NYQ`kdfm*SwW+L!P0ep8w&y185eXrOBv$c^dFD@<}Clo&Ip<| zhPogC@c-}A!fshSj@2j7orkCJD5PtK>$GH?g&GttMJ$H613er!SGg?rcy1*Y@Jpd@ zW82YtKeUgS_HqUZKnh9nXFP3UtT_W$JXn9+)fNmK9ZC@P-l^ho{Je*o{qkpIUmx3a zQX*`Sx`w@P)!kSmN*cPBfO`B;V5la}#^^QOH#gCW(w`^&Hd)TN`@)&ETtT^^t@rC3 zbR_p4$W?|nJ7gwg=lFGphqww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L=uo;m9~hLZdL_(8l3gijBO> zDTVLVtM~g}XeUHvUCqvLSZuGfb5pMOcjV<((x1(Z3tPwrs|4)4wW#UUpxMoQVo+yP zOg#&}y$kpT6)SW#dOm6HmgCYcWs$UJhtA;P{{ zC5anqM}e zNoqmAFdx`(*wMYDJ>-2RJ3ih80l#J#F8O-sC#5{kkH4|?vCwINpwjp%M8F=l@zAG5 za@@Rk?q}%T%Wr7P_^yGM3^z|#6;D)xEo#rVQL7uJf5uLAeQ$3iS_Qrkt&Q1xYkInP zCQNRa|K)*Qhq0)WiQ?R)ubdFTmF=@Hwv7Kxfcp7Vl$SXVH?2EJ)+A%5w!Hm#*Zn)+ z^}@1w>-tFBzQ90H9=BFv?tZe=%UwO!>!mn zv|TipEhP{=k^>w;hCvG44yp8jH5qbyK}wr)?tEgZvtaQTr{E!^ wAapGXMc_qs*&;w2^$dWb{tu6>Hu?sXmI|YjU+f~iy~|Zo(pG#gZ~5%M03*?l%K!iX literal 0 HcmV?d00001 From 685487cd18885c171d9acf4cc2abef88383e1443 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 12 Oct 2015 19:42:25 +0200 Subject: [PATCH 2/2] Added README --- ifttt/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ifttt/README.md diff --git a/ifttt/README.md b/ifttt/README.md new file mode 100644 index 00000000..3455116a --- /dev/null +++ b/ifttt/README.md @@ -0,0 +1,20 @@ +IFTTT Connector +=============== + +The purpose of this connector is to use [IFTTT](http://www.ifttt.com) +to mirror posts from remote networks like Facebook. + +IFTTT (IF This Then That) is a service that triggers commands on +definable conditions. + +Its main purpose is to mirror your own posts from Facebook as if they +would have been posted directly on Friendica but it should be possible +to mirror posts from other networks as well. + +Every time when IFTTT detects that there is a new post on the remote +network, it triggers an HTTP POST call on the Friendica server that +creates a post from the connected account. + +By now there is a posting loop detection for Facebook but not for any +other network. So please be careful to not mirror from networks where +you post your items via Friendica.