-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreceive.php
87 lines (74 loc) · 2.35 KB
/
receive.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/*
* This is the program to receive the mail via MailGun routes
*/
require_once __DIR__.'/src/autoloader.php';
use peter\social\PostFeed;
header("Content-type: text/plain");
$mailGun = parse_ini_file(__DIR__.'/api-key.ini');
$apiKey = $mailGun['api_key'];
$sender = $mailGun['sender'];
$from = $mailGun['sandbox_address'];
$event = null;
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$isSender = (isset($_POST['sender']) ? $_POST['sender']:'') === $sender;
$isFrom = (isset($_POST['recipient']) ? $_POST['recipient']:'') === $from;
if(!$isSender && !$isFrom) {
echo 'The sender and from email address is invalid!';
exit;
}
} else {
echo 'We do not accept this request method!';
exit;
}
$bodyPlain = isset($_POST['body-plain']) ? $_POST['body-plain']:'';
$bodyPlain = str_replace('\r\n', PHP_EOL, $bodyPlain);
if($bodyPlain == '') {
echo 'the message body is plain.';
exit;
}
$iniList = parse_ini_string($bodyPlain, true);
$facebook = $iniList['facebook']['post'];
$twitter = $iniList['twitter']['post'];
$plurk = $iniList['plurk']['post'];
$message = $iniList['feed']['content'];
$link = $iniList['feed']['link'];
// parse the api-key.ini file to get the socail website credentials.
$apiKey = parse_ini_file('./api-key.ini', true);
// sync and post feed to Twitter, Facebook and Plurk.
$feed = new PostFeed();
$feed->setMessage($message);
$feed->setLink($link);
// Facebook
if($facebook === 'yes') {
$serviceName = 'Facebook';
foreach($apiKey[$serviceName] as $key => $value) {
$feed->setSettings($key, $value);
}
$feed->setServiceName($serviceName);
$feed->postFeed();
$httpCode = $feed->getHttpStatusCode();
$responseMsg = $feed->getResponseMessage();
}
// Twitter
if($twitter === 'yes') {
$serviceName = 'Twitter';
foreach($apiKey[$serviceName] as $key => $value) {
$feed->setSettings($key, $value);
}
$feed->setServiceName($serviceName);
$feed->postFeed();
$httpCode = $feed->getHttpStatusCode();
$responseMsg = $feed->getResponseMessage();
}
// Plurk
if($plurk === 'yes') {
$serviceName = 'Plurk';
foreach($apiKey[$serviceName] as $key => $value) {
$feed->setSettings($key, $value);
}
$feed->setServiceName($serviceName);
$feed->postFeed();
$httpCode = $feed->getHttpStatusCode();
$responseMsg = $feed->getResponseMessage();
}