Skip to content

Commit 97baa36

Browse files
author
aslikeyou
committed
finishing prepare files
1 parent 873ff62 commit 97baa36

9 files changed

+87
-6
lines changed

core/Core.php

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ function __construct($config = array())
2828
}
2929

3030
/**
31+
* @param string $key
32+
*
3133
* @return array
3234
*/
3335
public static function getConfig($key = '')
@@ -38,6 +40,12 @@ public static function getConfig($key = '')
3840
return self::$config;
3941
}
4042

43+
public static function getAppId() {
44+
if(!empty(self::$config) && isset(self::$config['fb']['appId']))
45+
return self::$config['fb']['appId'];
46+
return false;
47+
}
48+
4149
/**
4250
* @param $config array
4351
*/

deleteSubscription.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
require_once './init.php';
4+
5+
$param = array('access_token' => AppDataReader::getField('access_token'));
6+
$subs = Core::app()->getFb()->api('/'.Core::getAppId().'/subscriptions', 'DELETE', $param);
7+
8+
print_r($subs);

enquireSubscription.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
require_once './init.php';
4+
5+
$param = array('access_token' => AppDataReader::getField('access_token'));
6+
$subs = Core::app()->getFb()->api('/'.Core::getAppId().'/subscriptions', $param);
7+
8+
print_r($subs);

getAccessToken.php

+4
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@
2525
$db->prepare(
2626
"INSERT INTO app_data VALUES (null, access_token, :access_token)"
2727
)->execute(array(':access_token' => $accessToken));
28+
29+
echo "Returned value: ".$returnValue;
30+
echo "<br>";
31+
echo "Value to db: ".$accessToken;

index.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@
5353
<div class="nav-collapse collapse">
5454
<ul class="nav">
5555
<li class="active"><a href="#">Home</a></li>
56-
<li><a href="#">Get Access Token</a></li>
56+
<li><a href="/getAccessToken.php">Get Access Token</a></li>
57+
<li><a href="/subscribeForUpdates.php">Subscribe for updates</a></li>
58+
<li><a href="/enquireSubscription.php">Enquiring the Current Subscription</a></li>
59+
<li><a href="/deleteSubscription.php">Deleting the Current Subscription</a></li>
5760
</ul>
5861
</div><!--/.nav-collapse -->
5962
</div>

liveUpdates.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
<?php
22

3-
require_once './core/FB.php';
3+
require_once './core/Core.php';
44

55
$app = new Core();
66

7-
$verify_token = '123';
8-
97
if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['hub_mode'])
108
&& $_GET['hub_mode'] == 'subscribe' && isset($_GET['hub_verify_token'])
11-
&& $_GET['hub_verify_token'] == $verify_token) {
9+
&& $_GET['hub_verify_token'] == AppDataReader::getField('verify_token')) {
1210
echo $_GET['hub_challenge'];
1311
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
1412
$post_body = file_get_contents('php://input');
1513
//$obj = json_decode($post_body, true);
16-
$app->getDb()->prepare("INSERT INTO test (json) VALUES ('$post_body')")->execute();
14+
$app->getDb()->prepare("INSERT INTO test (json) VALUES (':data')")
15+
->execute(array(':data' => $post_body));
1716
}
1817

1918
$app->getDb()->prepare("INSERT INTO test (json) VALUES ('refresh page')")->execute();

private/components/AppDataReader.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
class AppDataReader
4+
{
5+
private static $table = 'app_data';
6+
7+
8+
/**
9+
* @param $fieldName
10+
*
11+
* @return bool|string
12+
*/
13+
public static function getField($fieldName)
14+
{
15+
$table = self::$table;
16+
$statement = Core::app()->getDb()->prepare("SELECT value FROM {$table} WHERE field = :field");
17+
if(!$statement->execute(array(':field' => $fieldName)))
18+
return false;
19+
20+
return $statement->fetchColumn();
21+
}
22+
23+
/**
24+
* @param $token
25+
*
26+
* @return bool
27+
*/
28+
public static function setField($token)
29+
{
30+
$table = self::$table;
31+
$statement = Core::app()->getDb()->prepare("UPDATE {$table} SET value = :value WHERE field = access_token");
32+
return $statement->execute(array(':value' => $token));
33+
}
34+
35+
}

private/config/main.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
return array(
4+
'host' => $_SERVER['SERVER_NAME'],
45
'db' => array(
56
'connectString' => 'mysql:host=raccoon.mysql.ukraine.com.ua;dbname=raccoon_facebook',
67
'user' => 'raccoon_facebook',

subscribeForUpdates.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
require_once './init.php';
4+
5+
$param = array('access_token' => AppDataReader::getField('access_token'),
6+
'object' => 'user',
7+
'fields' => 'name,feed,email',
8+
'callback_url' => Core::getConfig('host').'/liveUpdates.php',
9+
'verify_token' => AppDataReader::getField('verify_token')
10+
);
11+
$fbConf = Core::getConfig('fb');
12+
$appId = $fbConf['appId'];
13+
$subs = Core::app()->getFb()->api('/'.$appId.'/subscriptions', 'POST', $param);
14+
15+
print_r($subs);

0 commit comments

Comments
 (0)