Facebook to email

Facebook to email Commit Details

Date:2014-10-09 21:01:50 (5 years 1 month ago)
Author:Grégory Soutadé
Branch:master
Commit:7fb8bd851c2fdf05cef3fa83167b4a3829ac0072
Parents: 116e946f652c8c26179b95810215c853f64b95f3
Message:Allow , and ; as email separator Don't displays all emails in "to" field, send one by one Fix a bug token expiration (exception not caught)

Changes:
Mindex.php (1 diff)
Mmodules/email.php (3 diffs)
Mrun.php (6 diffs)

File differences

index.php
279279
280280
281281
282
282
283283
284284
285285
</head>
<body>
<div id="overlay"></div>
<center><h1><a class="title_link" href="https://indefero.soutade.fr/p/f2email">Facebook to email</a></h1></center>
<center><h1><a class="title_link" href="http://indefero.soutade.fr/p/f2email">Facebook to email</a></h1></center>
<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>&nbsp;&nbsp;&nbsp;
modules/email.php
2727
2828
2929
30
30
3131
3232
3333
......
4141
4242
4343
44
44
4545
4646
4747
......
8989
9090
9191
92
92
9393
9494
9595
96
96
97
9798
9899
99100
{
function getName() { return "Email"; }
function getDescription() { return "Sends an email for each new notification"; }
function getHelp() { return "Global preference is the default email to send to (if a local one has not been specified).<br/>\nYou can use multiples emails addresses separated by a comma (\",\")";}
function getHelp() { return "Global preference is the default email to send to (if a local one has not been specified).<br/>\nYou can use multiples emails addresses separated by a comma or a semicolon (\",\" ot \";\")";}
function hasGlobalPref() { return 1; }
function hasLocalPref() { return 1; }
function validatePref($pref)
{
foreach(split(",", $pref) as $email)
foreach(preg_split("/[,;]/", $pref) as $email)
{
if (!filter_var(trim($email), FILTER_VALIDATE_EMAIL))
return false;
else
$message .= '<br/><a href="https://www.facebook.com/' . $notification["id"] . '">https://www.facebook.com/' . $notification["id"] . "</a>";
echo "</html></body>";
$message .= "</body></html>";
$headers = "Message-ID: <" . $notification['id'] . "@f2email>";
send_email($to, $subject, $message, $headers);
foreach(preg_split("/[,;]/", $to) as $email)
send_email($email, $subject, $message, $headers);
}
}
?>
run.php
3333
3434
3535
36
37
38
39
40
41
3642
3743
3844
......
6369
6470
6571
72
73
74
75
76
77
78
79
80
81
6682
6783
6884
69
85
7086
7187
7288
......
8096
8197
8298
99
100
83101
84102
85103
86104
87
88
89
90
105
106
107
108
109
91110
92
111
93112
94
95
113
114
115
96116
97
117
118
119
120
121
122
123
98124
99
125
126
127
100128
101129
102130
......
122150
123151
124152
153
154
125155
126156
127157
......
131161
132162
133163
134
164
135165
136166
137167
......
192222
193223
194224
225
195226
227
228
229
196230
197231
198232
199233
200234
201235
202
203
236
237
238
204239
205240
$headers .= "\r\n" . $extra_header;
mail($to, "=?UTF-8?B?" . base64_encode($subject) . "?=", $message, $headers);
if (PHP_SAPI === 'cli')
{
echo "Mail to $to\n";
echo $message;
}
}
function endsWith( $str, $sub ) {
return $plugins;
}
function token_error($db, $user)
{
global $WEBSITE_URL;
print "Token expired for user " . $user['id'] . "\n";
send_email($user['email'], "f2email : Access token expired", 'Your Facebook token has expired, please reconnect to <a href="'.$WEBSITE_URL.'">'.$WEBSITE_URL.'</a>.<br/>Your account will be automatically removed within a month if not.');
$db->disable_user($user);
}
function run($user_id = 0, $target_object_id = 0)
{
global $DATABASE_ADDRESS, $DATABASE_USER, $DATABASE_PASSWORD, $DATABASE_DATABASE;
global $APP_ID, $SECRET, $WEBSITE_URL, $FROM_ADDRESS;
global $APP_ID, $SECRET, $WEBSITE_URL, $FROM_ADDRESS, $ADMIN_EMAIL;
$plugins = array();
$db = new Database($DATABASE_ADDRESS, $DATABASE_USER, $DATABASE_PASSWORD, $DATABASE_DATABASE);
{
while ($user = $result->fetch_assoc())
{
$user_profile = null;
if ($user['token_expired']) continue;
if ($user_id != 0 && $user_id != $user['id']) continue;
$facebook = new Facebook(array(
'appId' => $APP_ID,
'secret' => $SECRET
));
try {
$facebook = new Facebook(array(
'appId' => $APP_ID,
'secret' => $SECRET
));
$facebook->setAccessToken($user['access_token']);
$facebook->setAccessToken($user['access_token']);
$user_profile = $facebook->api('/me?fields=id,likes');
if (array_key_exists("error", $user_profile))
$user_profile = $facebook->api('/me?fields=id,likes');
}
catch(FacebookApiException $e)
{
send_email($user['email'], "f2email : Access token expired", 'Your Facebook token has expired, please reconnect to <a href="http://soutade.fr/f2email">http://soutade.fr/f2email</a>.<br/>Your account will be automatically removed within a month if not.');
token_error($db, $user);
continue;
}
catch(Exception $e)
{
send_email($ADMIN_EMAIL, "f2email : Exception raised", $e->getMessage());
}
$db->disable_user($user);
if (array_key_exists("error", $user_profile))
{
token_error($db, $user);
continue;
}
if ($plugin == null)
{
$ret .= "No plugin found for ID " . $fb_object_id . "\n";
if (PHP_SAPI === 'cli')
print "No plugin found for ID " . $fb_object_id . "\n";
continue;
}
if (!array_key_exists("feed", $feeds))
{
$ret .= "Empty feeds for $fb_object_id\n";
if (PHP_SAPI === 'cli')
if (PHP_SAPI === 'cli')
echo "Empty feeds for $fb_object_id\n";
continue;
}
}
}
else
{
$ret .= "No user with ID " . $user_id . "\n";
if (PHP_SAPI === 'cli')
echo "No user with ID " . $user_id . "\n";
}
if ($ret == "") $ret = "OK";
return $ret;
}
if (PHP_SAPI === 'cli')
run(0);
if (PHP_SAPI === 'cli')
run(0, 1268300218);
//run();
?>

Archive Download the corresponding diff file

Branches