-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·236 lines (192 loc) · 7.16 KB
/
index.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
define("SUB_DIR", "");
session_name("memeja");
ob_start();
ini_set("memory_limit","16M");
ini_set('display_errors', true);
error_reporting(E_ALL + E_NOTICE);
$report = array ('stats' => array ());
define("THROUGH_CONTROLLER", 1);
define("AJAX", 0);
define("AFIXI_ROOT", $_SERVER['DOCUMENT_ROOT']."/".SUB_DIR."flexycms/");
define("AFIXI_CORE", $_SERVER['DOCUMENT_ROOT'].'/flexycms/flexycms_core/');
include (AFIXI_CORE."common5.php");
// Code for set multilanguage
if($GLOBALS['conf']['MULTI_LANG']['islang']){
$_SESSION['multi_language']=$_SESSION['multi_language']?$_SESSION['multi_language']:"default";
}else{
$_SESSION['multi_language']="";
}
// End code for set multilanguage
include ($_SERVER['DOCUMENT_ROOT'].'/flexycms/common_files.php');
if(defined("SITE_USED") && file_exists(AFIXI_ROOT.'../'.SITE_USED.'.php')){
include_once(AFIXI_ROOT.'../'.SITE_USED.'.php');
}else{
include_once(AFIXI_ROOT.'../site.php');
}
if(!($_SESSION['domain'])){
$_SESSION['domain'] = SITE_USED;
}
//var_dump($_COOKIE);
$site = new site; // called from site.php
$site->init(); // calls function in instance 'site'
$smarty = getSmarty(); // from common5.php, assigned to $smarty
$site->smarty= &$smarty;
$site->cache_id= &$cache_id;
if(isset($_COOKIE['username']) && !($_SESSION['username'])){
$sql = get_search_sql("user","email = '".$_COOKIE['username']."' LIMIT 1");
$query = mysqli_query($link,$sql);
$result = mysqli_fetch_assoc($query);
$_SESSION['fname']=$result['fname'];
$_SESSION['lname']=$result['lname'];
$_SESSION['email'] = $result['email'];
$_SESSION['username'] = $result['username'];
$_SESSION['dupe_username'] = $result['dupe_username'];
if ($result['fb_pic_normal']) {
$_SESSION['fb_pic_normal'] = $result['fb_pic_normal'];
}
else {
$_SESSION['avatar'] = $result['avatar'] ? $result['avatar']:($result['gender']=='M'?'memeja_male.png':'memeja_female.png');
}
$_SESSION['gender']=$result['gender'];
$_SESSION['id_user'] = $result['id_user'];
$_SESSION['uid'] = $result['uid'];
$_SESSION['exp_point'] = $result['exp_point'];
$_SESSION['level'] = $result['level'];
// $_SESSION['xp_to_level'] = $_COOKIE['xp_to_level'];
// $_SESSION['previous_xp_to_level'] = $_COOKIE['xp_to_level'];
// $_SESSION['one_less_rank'] = $_COOKIE['one_less_rank'];
// $_SESSION['one_less_user'] = $_COOKIE['one_less_user'];
// $_SESSION['one_less_dupe_username'] = $_COOKIE['one_less_dupe_username'];
// $_SESSION['one_less_pic'] = $_COOKIE['one_less_pic'];
// $_SESSION['one_less_avatar'] = $_COOKIE['one_less_avatar'];
// $_SESSION['one_less_gender'] = $_COOKIE['one_less_gender'];
}
if ($_input['mod']) {
$result = user_templates::get_mod($_input,'',"ACTION");
unset($_input['choice']);
if ($result) {
if(is_array($result)){
redirect($result['redirect_url']);
}else{
$mgr = $_input['mgr'];
if($mgr){
$_input[$mgr.'_choice'] = str_replace('choice_', '', $_input['success']);
}else{
$_input['choice'] = str_replace('choice_', '', $_input['success']);
}
}
} else {
$mgr = $_input['mgr'];
$_input['choice'] = str_replace('choice_', '', $_input['fail']);
}
}
$page = isset ($_input['page']) ? $_input['page'] : 'common';
if (isset($_input['id'])){
global $link;
$sanitize_id = mysql_real_escape_string($_input['id']);
$sql = get_search_sql("user","dupe_username = '".$sanitize_id."' LIMIT 1");
$temp_data = getrows($sql,$err);
$profile_data = $temp_data[0];
if ($profile_data['id_user']){
$_SESSION['profile'] = $profile_data['username']; //username
$_SESSION['profile_id'] = $profile_data['id_user'];
$_SESSION['profile_uid'] = $profile_data['uid'];
$_SESSION['profile_picture'] = $profile_data['fb_pic_normal'];
$_SESSION['profile_dupe_username'] = $profile_data['dupe_username'];
// count followers
$page_sql="SELECT COUNT(*) FROM memeje__friends WHERE following=".$_SESSION['profile_id'];
$page_res=mysqli_query($link,$page_sql);
if ($page_res){
$page_row = $page_res->fetch_row();
$_SESSION['profile_follower_count'] = $page_row[0];
} else {
$_SESSION['profile_follower_count'] = '0';
}
if ($_SESSION['id_user'] && $_SESSION['profile_id'] != $_SESSION['id_user']){
// check if already following profile user
$sql = get_search_sql("friends"," following=".$_SESSION['profile_id']." AND id_user=".$_SESSION['id_user']);
$check = getrows($sql, $err);
if ($check){
$_SESSION['following'] = 'y';
} else {
$_SESSION['following'] = 'n';
}
} else {
$_SESSION['following'] = 'self';
}
// requests to view a meme
if ($_input['meme']){
$input_meme = mysql_real_escape_string($_input['meme']);
$sql = get_search_sql("meme","id_meme = '".$input_meme."' LIMIT 1");
$temp_meme = getrows($sql,$err);
$profile_meme = $temp_meme[0];
if ($profile_meme['id_user'] == $profile_data['id_user']){
//fb($profile_meme, 'profile meme is found');
$_SESSION['profile_meme_title'] = $profile_meme['title'];
$_SESSION['profile_meme_image'] = $profile_meme['image'];
$_SESSION['profile_meme_id'] = $profile_meme['id_meme'];
if ($profile_meme['tagged_user']){
$tagged_data = explode(',',$profile_meme['tagged_user']);
foreach($tagged_data as $key => $value){
$tagged_data[$key] = array();
$tagged_data[$key]['id'] = $value;
$tagged_data[$key]['name'] = json_decode(file_get_contents('http://graph.facebook.com/'.$value))->name;
}
$_SESSION['profile_meme_tagged'] = $tagged_data;
}
}
}
} else {
$_SESSION['profile'] = 'invalid'; // stop rendering, profile does not exist
//fb('profile is deactivated');
}
} else {
$_SESSION['profile'] = 0;
$_SESSION['profile_id'] = 0;
$_SESSION['profile_uid'] = 0;
$_SESSION['profile_picture'] = 0;
$_SESSION['profile_meme_title'] = 0;
$_SESSION['profile_meme_image'] = 0;
$_SESSION['profile_meme_tagged'] = 0;
$_SESSION['following'] = 0;
}
$site->handle_page($page); //sets default_tpl to $page/home UNLESS static
$smarty->assign('page_title', $page_title);
if (isset($_input['ce']) ) {
$site->set_container_enabled($_input['ce']);
}
$file_test = TEMPLATE_DIR.$_SESSION['multi_language']."/".$site->default_tpl.TEMPLATE_EXTENSION;
if($page =='user' || file_exists($file_test)) {
if ($site->is_container_enabled()) {
// $content used in common.tpl.html to show live feed/meme editor
$smarty->assign('content', $smarty->add_theme_to_template($site->default_tpl));
$tpl = isset ($_GET['c_tpl']) ? $_GET['c_tpl'] : $site->get_container_tpl();
} else {
$tpl = $site->default_tpl;
}
if (!empty ($_SESSION['CACHE_OUTPUT'])) {
ob_start();
}
restore_error_handler();
$report['debug'] = 0;
$report['end_code'] = getmicrotime();
$smarty->assign_by_ref('report', $report);
$smarty->debugging_ctrl='URL';
$smarty->display($tpl, $cache_id); //display func in AfixiSmarty.php; executes template
$time_end = getmicrotime();
unset ($_SESSION['raise_message']);
if (!empty ($_SESSION['CACHE_OUTPUT'])) {
ob_end_flush();
unset ($_SESSION['CACHE_OUTPUT']);
}
} else {
// Error handling because file does not exist
if(!($page =='templates' || $page =='image')){
$_SESSION['raise_message']['global'] = "<h2>Herp a derp?<h2>";
redirect(LBL_SITE_URL);
}else{
return;
}
}
ob_end_flush();