-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_one.php
64 lines (50 loc) · 2.28 KB
/
update_one.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
<?php
define('TMVC_MYAPPDIR', '/var/www/androidreviews/myapp/');
include_once('myapp/plugins/tools.php');
include_once('myapp/plugins/consumer.php');
include_once('myapp/plugins/AndroidMarket.class.php');
include_once('myapp/plugins/updateTracking.php');
include_once('myapp/configs/config_database.php');
include_once('Mail.php');
function sendMailNewReview($email, $appid, $review) {
global $config;
$content = '
<center>
<h1><span style="color:#9acd32">A</span>ndroid <span style="color:#9acd32">R</span>eviews <span style="color:#9acd32">M</span>anager</h1>
<i style="color:#9acd32">The Android Developer\'s best friend</i>
</center>
<br><br>
Hello,<br>
<br>
You\'ve got a new review!<br>
<a href="'.$config['website']['url'].'apps/reviews?id='.$appid.'"
style="display: inline-block; color: #ffffff; text-decoration: none; font-weight: bold; padding: 20px; background-color: #9acd32; border-radius: 10px; margin: 10px;">
Read it</a>
<br><br>
<small style="color: #cccccc;">You received this email because you follow an app on <a href="'.$config['website']['url'].'">AndroidReviewsManager</a>. Unfollow this app to stop receiving this kind of emails.</small>
</center>
';
$headers['From'] = '[email protected]';
$headers['To'] = $email;
$headers['Subject'] = 'New Review';
$content = utf8_encode($content);
$headers['Content-Type'] = "text/html; charset=\"UTF-8\"";
$headers['Content-Transfer-Encoding'] = "8bit";
$params['sendmail_path'] = '/usr/lib/sendmail';
$mail_object =& Mail::factory('sendmail', $params);
$mail_object->send($headers['To'], $headers, $content);
echo 'New review, email sent! '.$email.' '.$appid.' '.$review."\n";
}
$market = new AndroidMarket();
$db = new PDO('mysql:host='.$config['default']['host'].';dbname='.$config['default']['name'],
$config['default']['user'], $config['default']['pass']);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$r = $db->prepare('SELECT * FROM apps_tracker');
$r->execute();
$r = $r->fetchAll();
foreach ($r as $app) {
echo '# Update reviews for: '.$app['user'], $app['app_id']."\n";
$newReviews = updateTracking($db, $market, $app['user'], $app['app_id']);
foreach ($newReviews as $newReview)
sendMailNewReview($app['user'], $app['app_id'], $newReview);
}