Skip to content
This repository was archived by the owner on May 19, 2022. It is now read-only.

Commit b0b0ac7

Browse files
author
sbuckpesch
committed
update demo app files with lottery premium files
1 parent a335272 commit b0b0ac7

File tree

7 files changed

+367
-58
lines changed

7 files changed

+367
-58
lines changed

config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
$aa_api_key = "sbuckpesch";
1111

1212
// Step 3: App-Arena App-Id
13-
$aa_app_id = 41;
13+
$aa_app_id = 46;
1414

15+
// Advanced Settings
16+
$debugMode = false;
1517

1618
?>

footer.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
<div style="clear:both;"></div>
2-
<script src="http://connect.facebook.net/de_DE/all.js"></script>
3-
<script>
4-
FB.init({
5-
appId : '<?=$global->instance['fb_app_id']?>',
6-
status : true, // check login status
7-
cookie : true, // enable cookies to allow the server to access the session
8-
xfbml : true // parse XFBML
9-
});
10-
FB.Canvas.setAutoResize();
2+
<?php // Show admin panel, when page admin
3+
if ($session->fb_page['admin']) { ?>
4+
<hr />
5+
<a href="admin.php">Admin-Panel</a>
6+
<?php } ?>
7+
<div id="fb-root"></div>
8+
<script type="text/javascript">
9+
<!--
10+
window.fbAsyncInit = function() {
11+
FB.init({
12+
appId: '<?=$session->instance['fb_app_id']?>',
13+
status: true,
14+
cookie: true,
15+
xfbml: true
16+
});
17+
FB.Canvas.setAutoResize();
18+
};
19+
(function() {
20+
var e = document.createElement('script');
21+
e.type = 'text/javascript';
22+
e.src = document.location.protocol + '//connect.facebook.net/de_DE/all.js';
23+
e.async = true;
24+
document.getElementById('fb-root').appendChild(e);
25+
}());
26+
//-->
1127
</script>
28+
1229
</body>
1330
</html>

header.php

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,67 @@
11
<!DOCTYPE div PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2-
<html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
33
<head>
44
<!-- Include CSS-Files -->
55
<link href="lib/jFormer/jformer.css" rel="stylesheet" type="text/css" />
66
<link href="lib/Facebox/src/facebox.css" media="screen" rel="stylesheet" type="text/css" />
7+
<style type="text/css"><?=$session->design['base_style']?></style>
8+
79
<!-- Include Javascript-Files -->
8-
<script src="lib/jquery/jquery-1.5.min.js" type="text/javascript"></script>
10+
<script src="lib/AA/js/aa_fb_framework.js?12" type="text/javascript"></script>
11+
<script src="lib/jquery/jquery-1.6.min.js" type="text/javascript"></script>
912
<script src="lib/jFormer/jFormer.js" type="text/javascript"></script>
1013
<script src="lib/Facebox/src/facebox.js" type="text/javascript"></script>
1114

15+
<!-- Meta Data -->
16+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
17+
<!-- Facebook Meta Data -->
18+
<meta property="og:title" content="<?=$session->config['share_facebook_name']?>" />
19+
<meta property="og:type" content="website" />
20+
<meta property="og:url" content="<?=$session->fb_page['app_url']?>" />
21+
<meta property="og:image" content="<?=$session->config['share_facebook_picture']?>" />
22+
<meta property="og:site_name" content="<?=$session->config['share_facebook_caption']?>" />
23+
<meta property="og:description" content="<?=$session->config['share_facebook_desc']?>" />
1224
</head>
1325

1426
<body>
15-
<div id="fb-root"></div>
27+
<?php // No Fan Content (User who are not Fan of the Page see)
28+
if ($session->fb_page['liked'] == 0) { ?>
29+
<div class="page_non_fans_layer">
30+
<div style="position:absolute; top:50px; left:150px;">
31+
<?=$session->content['img_non_fans']?>
32+
</div>
33+
</div>
34+
<?php } ?>
35+
36+
<div id="header">
37+
<div id="logo">
38+
<a href="<?=$session->instance['fb_page_url']?>"><?=$session->content['img_logo']?></a>
39+
</div>
40+
<!-- Navigation -->
41+
<div class="fix" id="nav">
42+
<ul class="fix homebutton">
43+
<li class="page_item navfirst">
44+
<a style="background-image: url('images/home-icon-trans.png');" title="Home" href="<?=$session->fb_page['app_url']?>" target="_top" class="home">
45+
Pinnwand
46+
</a>
47+
</li>
48+
</ul>
49+
<div class="mnav dropdown fix">
50+
<ul>
51+
<li class="page_item page-item-12">
52+
<a title="Meine Lose" href="tickets.php">Meine Lose</a>
53+
</li>
54+
<li class="page_item page-item-5">
55+
<a title="Freunde einladen" href="invite.php">Freunde einladen</a>
56+
</li>
57+
<li class="page_item page-item-2">
58+
<a title="Teilnahmebedigungen" href="terms_and_conditions.php">Teilnahmebedigungen</a>
59+
</li>
60+
<li class="page_item page-item-2">
61+
<a title="Gewinner" href="winner.php">Gewinner</a>
62+
</li>
63+
</ul>
64+
</div>
65+
<div class="clear"></div>
66+
</div>
67+
</div>

index.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
<?php
22
// Load all config values and necessary classes
33
require_once ('init.php');
4-
// Include Header Part
5-
include 'header.php';
4+
?>
5+
<!DOCTYPE div PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
6+
<html>
7+
<head>
8+
<!-- Include CSS-Files -->
9+
<link href="lib/jFormer/jformer.css" rel="stylesheet" type="text/css" />
10+
<link href="lib/Facebox/src/facebox.css" media="screen" rel="stylesheet" type="text/css" />
11+
<style type="text/css"><?=$session->design['base_style']?></style>
612

7-
/*
8-
* Integrate a Content from App-Arena App-Manager
9-
* Four Arrays of Content-Elements are available
10-
* 1. $global->app['instance'] --> All Instance Base Data
11-
* 2. $global->app['content'] --> All content elements
12-
* 3. $global->app['config'] --> All configuration values
13-
* 4. $global->app['design'] --> All Design elements
14-
* The name in the second bracket is the "identifier" which has been setup in App-Manager.
15-
* E.g. echo $global->app['content']['home']; --> shows the App-Manager content-element with the identifier "home"
16-
* To show all available data just uncomment the following line
17-
*/
18-
//echo '<h1>All available App-Arena data</h1><pre>', print_r($global->app), '</pre>';
13+
<!-- Include Javascript-Files -->
14+
<script src="lib/AA/js/aa_fb_framework.js?12" type="text/javascript"></script>
15+
<script src="lib/jquery/jquery-1.6.min.js" type="text/javascript"></script>
16+
<script src="lib/jFormer/jFormer.js" type="text/javascript"></script>
17+
<script src="lib/Facebox/src/facebox.js" type="text/javascript"></script>
1918

20-
echo $global->app['content']['home'];
19+
<!-- Meta Data -->
20+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
21+
</head>
22+
23+
<body>
24+
<?php // No Fan Content (User who are not Fan of the Page see)
25+
if ($session->fb_page['liked'] == 0) { ?>
26+
<div class="page_non_fans_layer">
27+
<div style="position:absolute; top:50px; left:150px;">
28+
<?=$session->content['img_non_fans']?>
29+
</div>
30+
</div>
31+
<?php }
32+
33+
include 'welcome.php';
2134

2235
// Include Footer Part
2336
include 'footer.php';

init.php

Lines changed: 72 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?php
2-
error_reporting(E_ALL|E_STRICT);
3-
ini_set('display_errors', 1);
4-
date_default_timezone_set('Europe/Berlin');
2+
// Enable Cookies for Internet Explorer in iframes
3+
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
54

65
// Load config
76
require_once dirname(__FILE__).'/config.php';
8-
require_once dirname(__FILE__).'/functions.php';
7+
require_once 'lib/fb-php-sdk/src/facebook.php';
8+
9+
// General Settings
10+
error_reporting(E_ALL|E_STRICT);
11+
if ($debugMode)
12+
ini_set('display_errors', 1);
13+
else ini_set('display_errors', 0);
14+
date_default_timezone_set('Europe/Berlin');
915

1016
//set include path
1117
define("ROOT_PATH",realpath(dirname(__FILE__)));
@@ -17,44 +23,80 @@
1723
require_once "Zend/Loader/Autoloader.php";
1824
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);
1925

20-
//setup database
26+
// Set global variable
27+
$global = new ArrayObject();
28+
29+
// Init Session if already exists
30+
$session = new Zend_Session_Namespace('aa_session' . $aa_app_id);
31+
$session->setExpirationSeconds(60*60); // Session lives one hour
32+
33+
// Init Database connection
2134
$db_config=array(
2235
'host'=>$database_host,
2336
'username'=>$database_user,
2437
'password'=>$database_pass,
2538
'dbname'=>$database_name
2639
);
27-
2840
$db = Zend_Db::factory('mysqli',$db_config);
2941
$db->query('set names utf8');
3042
Zend_Db_Table::setDefaultAdapter($db);
43+
$global->db = $db;
3144

32-
//set global variable
33-
$global=new ArrayObject();
34-
$global->db=$db;
35-
36-
require_once 'app-arena/Helper.php';
37-
$helper = new Helper();
45+
// Initialize App-Arena Connection and get all data if not available in session
46+
require_once 'AA/client/soap_client.php';
47+
// Request data from app-arena system
48+
//if ($debugMode || !isset($session->instance) || !isset($session->design) || !isset($session->content) || !isset($session->config)) {
49+
$soap = new Client($aa_api_key);
50+
$global->soap = $soap;
51+
$aa_app = $soap->getData($aa_app_id, $aa_api_key);
52+
// Save App-Arena Data to Session
53+
try {
54+
$session->instance = $aa_app['instance'];
55+
$session->instance['id'] = $aa_app['instance']['instance_id'];
56+
$session->config = $aa_app['config'];
57+
$session->content = $aa_app['content'];
58+
$session->design = $aa_app['design'];
59+
} catch (Exception $e) {
60+
throw new Exception("SOAP connection to App-Arena service could not be established.");
61+
}
62+
//}
3863

39-
// Initialize App-Arena Connection
40-
require_once 'app-arena/client/soap_client.php';
41-
$apparena = new Client($aa_api_key);
42-
$instance_id = 0;
43-
$page_id=get_page_id();
64+
// Get Facebook User data, signed_request from session or from $_REQUEST
65+
// Update Session, if the user data has changed
4466

45-
$apparena->setInstanceId($aa_app_id, $instance_id,$page_id);
46-
$result = $apparena->getData();
4767

48-
//result[0] is the error ,0 successful 1 for error
49-
if($result[0] == 1)
50-
{
51-
echo $result[1];
52-
exit();
68+
$signed_request = false;
69+
$user = false;
70+
if (isset($session->fb_api['signed_request']))
71+
// If signed request contains actualized data, update user data
72+
if (isset($_REQUEST['signed_request']) && $_REQUEST['signed_request'] <> $session->fb_api['signed_request'])
73+
$signed_request = $_REQUEST['signed_request'];
74+
else
75+
$signed_request = $session->fb_api['signed_request'];
76+
else if (isset($_REQUEST['signed_request']))
77+
$signed_request = $_REQUEST['signed_request'];
78+
if ($signed_request){
79+
try {
80+
$user = new AA_Fb_User($signed_request, $session->instance['fb_app_secret'], $session->instance['fb_app_id']);
81+
} catch (Exception $e) {
82+
throw Exception("Could not get User Data from Facebook API.");
83+
}
84+
// Gathering user data for the session
85+
$global->user = $user;
86+
$session->user = $user->request_data['user'];
87+
$session->fb_api['signed_request'] = $signed_request;
88+
if (isset($user->request_data['user_id'])){
89+
$session->user['id'] = $user->request_data['user_id'];
90+
} else {
91+
if (isset($user->user_id)) {
92+
$session->user['id'] = $user->user_id;
93+
}
94+
}
95+
// Gathering available page data for the session
96+
if (isset($user->request_data['page'])){
97+
$session->fb_page = $user->request_data['page'];
98+
$session->fb_page['url'] = "https://www.facebook.com/" . $session->instance['fb_page_url'];
99+
$session->fb_page['app_url'] = $session->fb_page['url'] . "?sk=app_" . $session->instance['fb_app_id'];
100+
}
53101
}
54-
else
55-
{
56-
$global->app = $result[1];
57-
}
58-
59-
$global->instid=$global->app['instance']['instance_id'];
60102
?>

showcase_data.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
include 'init.php';
3+
include 'header.php';
4+
?>
5+
6+
<div id="content">
7+
<h1>Which data I can get from the App-Arena Session?</h1>
8+
<h2>Decoded Signed Request ($session-&gt;fb_api)</h2>
9+
<?php Zend_Debug::dump($session->fb_api, "FB API: "); ?>
10+
<h2>Fanpage Data ($session-&gt;fb_page)</h2>
11+
<?php Zend_Debug::dump($session->fb_page, "Page: "); ?>
12+
<h2>User Data ($session-&gt;user)</h2>
13+
<?php Zend_Debug::dump($session->user, "User: "); ?>
14+
<h2>Data about the Instance ($session-&gt;instance)</h2>
15+
<?php Zend_Debug::dump($session->instance, "Instance: ");?>
16+
<h2>All config values ($session-&gt;config)</h2>
17+
<?php Zend_Debug::dump($session->config, "Config: ");?>
18+
<h2>All the Design data ($session-&gt;design)</h2>
19+
<?php Zend_Debug::dump($session->design, "Design: ");?>
20+
<h2>All the content ($session-&gt;content)</h2>
21+
<?php Zend_Debug::dump($session->content, "Content: ");?>
22+
<h2>All the global values</h2>
23+
<?php Zend_Debug::dump($global, "Global: ");?>
24+
<h2>Facebook Cookie</h2>
25+
<?php Zend_Debug::dump($cookie, "Cookie: ");?>
26+
</div>
27+
<?
28+
//Get Facebook Cookie
29+
30+
function get_facebook_cookie($app_id, $app_secret) {
31+
$args = array();
32+
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
33+
ksort($args);
34+
$payload = '';
35+
foreach ($args as $key => $value) {
36+
if ($key != 'sig') {
37+
$payload .= $key . '=' . $value;
38+
}
39+
}
40+
if (md5($payload . $app_secret) != $args['sig']) {
41+
return null;
42+
}
43+
return $args;
44+
}
45+
46+
$cookie = get_facebook_cookie($session->instance['fb_app_id'], $session->instance['fb_app_secret']);
47+
48+
49+
include 'footer.php';
50+
?>

0 commit comments

Comments
 (0)