Completed
Push — master ( d04083...e19839 )
by mains
02:27
created
php/View.php 1 patch
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -2,112 +2,112 @@  discard block
 block discarded – undo
2 2
 
3 3
 class View
4 4
 {
5
-    public $country;
6
-    public $city;
7
-    public $hashtag;
5
+	public $country;
6
+	public $city;
7
+	public $hashtag;
8 8
 	public $view;
9
-    public $postId;
10
-    public $isDetailedView;
11
-    public $baseUrl;
12
-    public $rights;
9
+	public $postId;
10
+	public $isDetailedView;
11
+	public $baseUrl;
12
+	public $rights;
13 13
 
14 14
 	public $lastPostId = '';
15 15
 
16
-    function __construct($baseUrl, $country, $city, $hashtag = '%23all', $view = 'time', $postId = '')
17
-    {
18
-        $this->baseUrl = $baseUrl;
19
-        $this->country = $country;
20
-        $this->city = $city;
21
-        $this->hashtag = urldecode($hashtag);
22
-        $this->view = $view;
23
-        $this->postId = $postId;
16
+	function __construct($baseUrl, $country, $city, $hashtag = '%23all', $view = 'time', $postId = '')
17
+	{
18
+		$this->baseUrl = $baseUrl;
19
+		$this->country = $country;
20
+		$this->city = $city;
21
+		$this->hashtag = urldecode($hashtag);
22
+		$this->view = $view;
23
+		$this->postId = $postId;
24 24
 
25
-        if(isUserAdmin())
26
-        {
27
-            $this->rights = 'admin';
28
-        }
29
-        else if(isUserVoter())
30
-        {
31
-            $this->rights = 'voter';
32
-        }
33
-        else
34
-        {
35
-            $this->rights = 'user';
36
-        }
25
+		if(isUserAdmin())
26
+		{
27
+			$this->rights = 'admin';
28
+		}
29
+		else if(isUserVoter())
30
+		{
31
+			$this->rights = 'voter';
32
+		}
33
+		else
34
+		{
35
+			$this->rights = 'user';
36
+		}
37 37
 
38
-        if($postId == '')
39
-        {
40
-            $this->isDetailedView = FALSE;
41
-        }
42
-        else
43
-        {
44
-            $this->isDetailedView = TRUE;
45
-        }
46
-    }
38
+		if($postId == '')
39
+		{
40
+			$this->isDetailedView = FALSE;
41
+		}
42
+		else
43
+		{
44
+			$this->isDetailedView = TRUE;
45
+		}
46
+	}
47 47
 	/**
48 48
 	 * Compute HTML Code
49 49
 	 */
50 50
  	function jodelToHtml($post)
51
-    {   //ToDO
52
-        //Replace # with link
53
-        //preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text);
51
+	{   //ToDO
52
+		//Replace # with link
53
+		//preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text);
54 54
 
55
-        //Time to time difference
56
-        $now = new DateTime();
57
-        $d = new DateTime($post['created_at']);
58
-        $timediff = $now->diff($d);
55
+		//Time to time difference
56
+		$now = new DateTime();
57
+		$d = new DateTime($post['created_at']);
58
+		$timediff = $now->diff($d);
59 59
 
60
-        $timediff_inSeconds = (string)$timediff->format('%s');
61
-        $timediff_inMinutes = (string)$timediff->format('%i');
62
-        $timediff_inHours = (string)$timediff->format('%h');
63
-        $timediff_inDays = (string)$timediff->format('%d');
64
-        $timediff_inMonth = (string)$timediff->format('%m');
60
+		$timediff_inSeconds = (string)$timediff->format('%s');
61
+		$timediff_inMinutes = (string)$timediff->format('%i');
62
+		$timediff_inHours = (string)$timediff->format('%h');
63
+		$timediff_inDays = (string)$timediff->format('%d');
64
+		$timediff_inMonth = (string)$timediff->format('%m');
65 65
 
66
-        if($timediff_inMonth!=0)
67
-        {
68
-                $timediff = $timediff_inMonth . "m";
69
-        }
70
-        else
71
-        {
72
-            if($timediff_inDays!=0)
73
-            {
74
-                $timediff = $timediff_inDays . "d";
75
-            }
76
-            else
77
-            {
78
-                if($timediff_inHours!=0)
79
-                {
80
-                    $timediff = $timediff_inHours . "h";
81
-                }
82
-                else
83
-                {
84
-                    if($timediff_inMinutes!=0)
85
-                    {
86
-                        $timediff = $timediff_inMinutes . "m";
87
-                    }
88
-                    else
89
-                    {
90
-                        $timediff = $timediff_inSeconds . "s";
91
-                    }
92
-                }
93
-            }
94
-        }
66
+		if($timediff_inMonth!=0)
67
+		{
68
+				$timediff = $timediff_inMonth . "m";
69
+		}
70
+		else
71
+		{
72
+			if($timediff_inDays!=0)
73
+			{
74
+				$timediff = $timediff_inDays . "d";
75
+			}
76
+			else
77
+			{
78
+				if($timediff_inHours!=0)
79
+				{
80
+					$timediff = $timediff_inHours . "h";
81
+				}
82
+				else
83
+				{
84
+					if($timediff_inMinutes!=0)
85
+					{
86
+						$timediff = $timediff_inMinutes . "m";
87
+					}
88
+					else
89
+					{
90
+						$timediff = $timediff_inSeconds . "s";
91
+					}
92
+				}
93
+			}
94
+		}
95 95
 
96 96
 
97
-        ?>
97
+		?>
98 98
         <article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;">
99 99
             <content>
100 100
                 <?php 
101
-                if(isset($post['image_url']))
102
-                {
103
-                    $regexRest = '/[^\w$ .!?-]+/u';
101
+				if(isset($post['image_url']))
102
+				{
103
+					$regexRest = '/[^\w$ .!?-]+/u';
104 104
 
105
-                    echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">';
106
-                }
107
-                else {
108
-                    echo str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($post['message'])));
109
-                }
110
-                ?>
105
+					echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">';
106
+				}
107
+				else {
108
+					echo str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($post['message'])));
109
+				}
110
+				?>
111 111
             </content>
112 112
             <aside>                    
113 113
                 <button onclick="vote('<?php echo $post['post_id'];?>', 'up', this)">
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
                                 <a href="<?php echo $this->changePostId($post['post_id'])->toUrl();?>">
137 137
                                     <i class="fa fa-commenting-o"></i>
138 138
                                     <?php if(array_key_exists("child_count", $post))
139
-                                    {
140
-                                        echo $post["child_count"];
141
-                                    } else echo "0";
142
-                                    ?>
139
+									{
140
+										echo $post["child_count"];
141
+									} else echo "0";
142
+									?>
143 143
                                 </a>
144 144
                             </span>
145 145
                             
@@ -159,18 +159,18 @@  discard block
 block discarded – undo
159 159
 						?>
160 160
                         <span class="distance">
161 161
                             <?php
162
-                                if($this->isDetailedView)
163
-                                {
164
-                                    if(isset($post['user_handle']) && $post['user_handle'] == 'OJ')
165
-                                    {
166
-                                        ?>
162
+								if($this->isDetailedView)
163
+								{
164
+									if(isset($post['user_handle']) && $post['user_handle'] == 'OJ')
165
+									{
166
+										?>
167 167
                                         <span data-tooltip="Author">
168 168
                                             <i class="fa fa-user-o"></i> OJ |
169 169
                                         </span>
170 170
                                         <?php 
171
-                                    }
172
-                                }
173
-                                ?>
171
+									}
172
+								}
173
+								?>
174 174
 
175 175
                             <span class="tip" data-tooltip="Distance">
176 176
                                 <i class="fa fa-map-marker"></i>
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
             </footer>
184 184
         </article>
185 185
     <?php
186
-    }
186
+	}
187 187
 
188 188
 
189 189
 	/**
@@ -220,147 +220,147 @@  discard block
 block discarded – undo
220 220
 		return $description;
221 221
 	}
222 222
 
223
-    function toUrl($msg = '')
224
-    {
225
-        $url = $this->baseUrl . 'index.php?country=DE' .
226
-                            '&city=' . urlencode($this->city) .
227
-                            '&hashtag=' . urlencode($this->hashtag) . 
228
-                            '&view=' . $this->view;
229
-        if($this->postId != '')
230
-        {
231
-            $url .= '&postId=' . $this->postId . 
232
-                    '&getPostDetails=TRUE';
233
-        }
223
+	function toUrl($msg = '')
224
+	{
225
+		$url = $this->baseUrl . 'index.php?country=DE' .
226
+							'&city=' . urlencode($this->city) .
227
+							'&hashtag=' . urlencode($this->hashtag) . 
228
+							'&view=' . $this->view;
229
+		if($this->postId != '')
230
+		{
231
+			$url .= '&postId=' . $this->postId . 
232
+					'&getPostDetails=TRUE';
233
+		}
234 234
 
235
-        if($msg != '')
236
-        {
237
-            $url .= '&msg=' . urlencode($msg);
238
-        }
235
+		if($msg != '')
236
+		{
237
+			$url .= '&msg=' . urlencode($msg);
238
+		}
239 239
 
240
-        return $url;
241
-    }
240
+		return $url;
241
+	}
242 242
 
243
-    function changePostId($postId)
244
-    {
245
-        $tempView = clone $this;
246
-        $tempView->postId = $postId;
247
-        $tempView->isDetailedView = TRUE;
248
-        return $tempView;
249
-    }
243
+	function changePostId($postId)
244
+	{
245
+		$tempView = clone $this;
246
+		$tempView->postId = $postId;
247
+		$tempView->isDetailedView = TRUE;
248
+		return $tempView;
249
+	}
250 250
 
251
-    function back()
252
-    {
253
-        $tempView = clone $this;
254
-        $tempView->postId = '';
255
-        return $tempView;
256
-    }
251
+	function back()
252
+	{
253
+		$tempView = clone $this;
254
+		$tempView->postId = '';
255
+		return $tempView;
256
+	}
257 257
 
258
-    function changeView($view)
259
-    {
260
-        $tempView = clone $this;
261
-        $tempView->view = $view;
262
-        return $tempView;
263
-    }
258
+	function changeView($view)
259
+	{
260
+		$tempView = clone $this;
261
+		$tempView->view = $view;
262
+		return $tempView;
263
+	}
264 264
 
265 265
 	function getPosts($jodelAccount)
266 266
 	{
267
-        if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL)
268
-        {
269
-            $accountCreator = new GetChannel();
270
-            $accountCreator->view = $this->view;
271
-            $accountCreator->setAccessToken($jodelAccount->accessToken);
272
-            $accountCreator->channel = $this->hashtag;
273
-            $accountCreator->lastPostId = $this->lastPostId;
274
-            $data = $accountCreator->execute();
275
-        }
276
-        else
277
-        {
278
-            if($this->lastPostId == '' && $this->view == 'combo')
279
-            {
280
-                $url = "/v3/posts/location/combo";
281
-            }
282
-            else
283
-            {
284
-                if($this->view == 'discussed')
285
-                {
286
-                    $url = "/v2/posts/location/discussed/";
287
-                }
288
-                else
289
-                {
290
-                    if($this->view == 'popular')
291
-                    {
292
-                        $url = "/v2/posts/location/popular/";
293
-                    }
294
-                    else
295
-                    {
296
-                        $url = "/v2/posts/location/";
297
-                    }
298
-                }
299
-            }
267
+		if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL)
268
+		{
269
+			$accountCreator = new GetChannel();
270
+			$accountCreator->view = $this->view;
271
+			$accountCreator->setAccessToken($jodelAccount->accessToken);
272
+			$accountCreator->channel = $this->hashtag;
273
+			$accountCreator->lastPostId = $this->lastPostId;
274
+			$data = $accountCreator->execute();
275
+		}
276
+		else
277
+		{
278
+			if($this->lastPostId == '' && $this->view == 'combo')
279
+			{
280
+				$url = "/v3/posts/location/combo";
281
+			}
282
+			else
283
+			{
284
+				if($this->view == 'discussed')
285
+				{
286
+					$url = "/v2/posts/location/discussed/";
287
+				}
288
+				else
289
+				{
290
+					if($this->view == 'popular')
291
+					{
292
+						$url = "/v2/posts/location/popular/";
293
+					}
294
+					else
295
+					{
296
+						$url = "/v2/posts/location/";
297
+					}
298
+				}
299
+			}
300 300
 
301
-            $accountCreator = new GetPosts();
302
-            $accountCreator->setLastPostId($this->lastPostId);
303
-            $accountCreator->setAccessToken($jodelAccount->accessToken);
304
-            $accountCreator->setUrl($url);
305
-            $accountCreator->version = 'v3';
301
+			$accountCreator = new GetPosts();
302
+			$accountCreator->setLastPostId($this->lastPostId);
303
+			$accountCreator->setAccessToken($jodelAccount->accessToken);
304
+			$accountCreator->setUrl($url);
305
+			$accountCreator->version = 'v3';
306 306
 
307
-            $config = parse_ini_file('config/config.ini.php');
308
-            $location = new Location();
309
-            $location->setLat($config['default_lat']);
310
-            $location->setLng($config['default_lng']);
311
-            $location->setCityName($config['default_location']);
312
-            $accountCreator->location = $location;
313
-            $data = $accountCreator->execute();
314
-        }
315
-    	if(is_array($data) && array_key_exists('recent', $data) && array_key_exists(0, $data['recent']))
316
-        {
317
-            return $data['recent'];
318
-        }
319
-        else if(is_array($data) && array_key_exists('posts', $data)&& array_key_exists(0, $data['posts']))
320
-        {
321
-            return $data['posts'];
322
-        }
323
-        else
324
-        {
325
-            if($this->lastPostId == '')
326
-            {
327
-                error_log('Could not find Posts in: ' . $this->city . ' Error: ' . print_r($data, true));
328
-                //error_log(print_r($data, true));
307
+			$config = parse_ini_file('config/config.ini.php');
308
+			$location = new Location();
309
+			$location->setLat($config['default_lat']);
310
+			$location->setLng($config['default_lng']);
311
+			$location->setCityName($config['default_location']);
312
+			$accountCreator->location = $location;
313
+			$data = $accountCreator->execute();
314
+		}
315
+		if(is_array($data) && array_key_exists('recent', $data) && array_key_exists(0, $data['recent']))
316
+		{
317
+			return $data['recent'];
318
+		}
319
+		else if(is_array($data) && array_key_exists('posts', $data)&& array_key_exists(0, $data['posts']))
320
+		{
321
+			return $data['posts'];
322
+		}
323
+		else
324
+		{
325
+			if($this->lastPostId == '')
326
+			{
327
+				error_log('Could not find Posts in: ' . $this->city . ' Error: ' . print_r($data, true));
328
+				//error_log(print_r($data, true));
329 329
 
330
-                $notFound[0] = array(
331
-                    "post_id" => "0",
332
-                    "discovered_by" => 0,
333
-                    "message" => "No more Posts found",
334
-                    "created_at" => "2017-02-11T16:44:50.385Z",
335
-                    "updated_at" => "2017-02-11T16:44:50.385Z",
336
-                    "pin_count" => 0,
337
-                    "color" => "5682a3",
338
-                    "got_thanks" => FALSE,
339
-                    "post_own" => "friend",
340
-                    "discovered" => 0,
341
-                    "distance" => 9,
342
-                    "vote_count" => 0,
343
-                    "location" =>
344
-                    array("name" => "Berlin",
345
-                      "loc_coordinates" =>
346
-                      array(
347
-                        "lat" => 0,
348
-                        "lng" => 0
349
-                      ),
350
-                      "loc_accuracy" => 0,
351
-                      "country" => "",
352
-                      "city" => "",
353
-                    ),
354
-                    "tags" =>
355
-                    array(),
356
-                    "user_handle" => "0"
357
-                );
358
-                return $notFound;
359
-            }
360
-            else
361
-            {
362
-                return FALSE;
363
-            }
364
-        }
330
+				$notFound[0] = array(
331
+					"post_id" => "0",
332
+					"discovered_by" => 0,
333
+					"message" => "No more Posts found",
334
+					"created_at" => "2017-02-11T16:44:50.385Z",
335
+					"updated_at" => "2017-02-11T16:44:50.385Z",
336
+					"pin_count" => 0,
337
+					"color" => "5682a3",
338
+					"got_thanks" => FALSE,
339
+					"post_own" => "friend",
340
+					"discovered" => 0,
341
+					"distance" => 9,
342
+					"vote_count" => 0,
343
+					"location" =>
344
+					array("name" => "Berlin",
345
+					  "loc_coordinates" =>
346
+					  array(
347
+						"lat" => 0,
348
+						"lng" => 0
349
+					  ),
350
+					  "loc_accuracy" => 0,
351
+					  "country" => "",
352
+					  "city" => "",
353
+					),
354
+					"tags" =>
355
+					array(),
356
+					"user_handle" => "0"
357
+				);
358
+				return $notFound;
359
+			}
360
+			else
361
+			{
362
+				return FALSE;
363
+			}
364
+		}
365 365
 	}
366 366
 }
Please login to merge, or discard this patch.
php/jodel-web.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -49,27 +49,27 @@  discard block
 block discarded – undo
49 49
 
50 50
 function user_log($msg)
51 51
 {
52
-    $log  = $msg . PHP_EOL;
53
-    file_put_contents(realpath(__DIR__ . '/..') . '/logs/user_log-' . date("Y.n.j") . '.txt', $log, FILE_APPEND);
52
+	$log  = $msg . PHP_EOL;
53
+	file_put_contents(realpath(__DIR__ . '/..') . '/logs/user_log-' . date("Y.n.j") . '.txt', $log, FILE_APPEND);
54 54
 }
55 55
 
56 56
 function isUserBot()
57 57
 {
58
-    preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches);
58
+	preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches);
59 59
 
60
-    return (isset($matches[0])) ? true : false;
60
+	return (isset($matches[0])) ? true : false;
61 61
 }
62 62
 
63 63
 function configPropertyExists($config, $property)
64 64
 {
65
-    if(!array_key_exists($property, $config) || !isset($config[$property]) || $config[$property] == '' || $config[$property] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
66
-    {
67
-        return FALSE;
68
-    }
69
-    else
70
-    {
71
-        return TRUE;
72
-    }
65
+	if(!array_key_exists($property, $config) || !isset($config[$property]) || $config[$property] == '' || $config[$property] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
66
+	{
67
+		return FALSE;
68
+	}
69
+	else
70
+	{
71
+		return TRUE;
72
+	}
73 73
 }
74 74
 
75 75
 function isUserVoter()
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 
111 111
 function isDeviceUidInDatabase($deviceUid)
112 112
 {
113
-    $db = new DatabaseConnect();  
114
-    $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid  . "'");
113
+	$db = new DatabaseConnect();  
114
+	$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid  . "'");
115 115
 
116
-    if ($result->num_rows > 0)
117
-    {
118
-    	$db->close();
119
-        return TRUE;
120
-    }
121
-    else
122
-    {
123
-    	$db->close();
124
-        return FALSE;
125
-    }
116
+	if ($result->num_rows > 0)
117
+	{
118
+		$db->close();
119
+		return TRUE;
120
+	}
121
+	else
122
+	{
123
+		$db->close();
124
+		return FALSE;
125
+	}
126 126
 }
127 127
 
128 128
 	//Check if it's a Spider or Google Bot
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
 	}
150 150
 	
151 151
 	if(configPropertyExists($config, 'karmaDeviceUid'))
152
-    {
153
-    	$jodelAccountForKarma = new JodelAccount($config['karmaDeviceUid']);
154
-    }
155
-    else
156
-    {
157
-    	error_log("No Karma deviceUid set in config file");
152
+	{
153
+		$jodelAccountForKarma = new JodelAccount($config['karmaDeviceUid']);
154
+	}
155
+	else
156
+	{
157
+		error_log("No Karma deviceUid set in config file");
158 158
 		$jodelAccountForKarma = new JodelAccount($deviceUid);
159
-    }
159
+	}
160 160
 
161 161
 	/*
162 162
 	 * Cunstruct View
Please login to merge, or discard this patch.
php/Requests/AbstractRequest.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -2,22 +2,22 @@  discard block
 block discarded – undo
2 2
 
3 3
 abstract class AbstractRequest
4 4
 {	
5
-    const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26';
6
-    const APIURL = 'https://api.go-tellm.com/api';
5
+	const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26';
6
+	const APIURL = 'https://api.go-tellm.com/api';
7 7
 
8
-    const SECRET = 'hyTBJcvtpDLSgGUWjybbYUNKSSoVvMcfdjtjiQvf';
9
-    const USERAGENT = 'Jodel/4.47.0 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
10
-    const CLIENT_TYPE = 'android_4.47.0';
8
+	const SECRET = 'hyTBJcvtpDLSgGUWjybbYUNKSSoVvMcfdjtjiQvf';
9
+	const USERAGENT = 'Jodel/4.47.0 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
10
+	const CLIENT_TYPE = 'android_4.47.0';
11 11
     
12
-    private $accessToken = null;
13
-    private $payLoad;
14
-    public $expects = '';
15
-    public $version = 'v2';
16
-    public $hasPayload = FALSE;
17
-
18
-    public function execute()
19
-    {
20
-        $result = new \stdClass();
12
+	private $accessToken = null;
13
+	private $payLoad;
14
+	public $expects = '';
15
+	public $version = 'v2';
16
+	public $hasPayload = FALSE;
17
+
18
+	public function execute()
19
+	{
20
+		$result = new \stdClass();
21 21
 		        
22 22
 		$this->payLoad = $this->getPayload();
23 23
 		$device_uid = '';
@@ -26,16 +26,16 @@  discard block
 block discarded – undo
26 26
 		}
27 27
 				
28 28
 				
29
-        $this->payLoad = json_encode($this->payLoad);
30
-        $header = $this->getSignHeaders();
31
-        $url = $this->getFullUrl();
29
+		$this->payLoad = json_encode($this->payLoad);
30
+		$header = $this->getSignHeaders();
31
+		$url = $this->getFullUrl();
32 32
 
33
-        if ($this->getAccessToken()) {
34
-            $header['Authorization'] = "Bearer " . $this->getAccessToken();
35
-        }
36
-        //Comment out to debug the Request:
33
+		if ($this->getAccessToken()) {
34
+			$header['Authorization'] = "Bearer " . $this->getAccessToken();
35
+		}
36
+		//Comment out to debug the Request:
37 37
 
38
-        /*
38
+		/*
39 39
         printf("URL: ");
40 40
         var_dump($url);
41 41
         echo "<br />";
@@ -46,134 +46,134 @@  discard block
 block discarded – undo
46 46
         var_dump($this->payLoad);
47 47
         echo "<br />";
48 48
         */
49
-        /*
49
+		/*
50 50
         $options = array(
51 51
             'timeout' => 100,
52 52
             'connect_timeout' => 100,
53 53
             'proxy' => '186.103.169.165:8080',
54 54
         );*/
55 55
 
56
-        switch ($this->getMethod()) {
57
-            case 'POST':
58
-                $result = Requests::post($url, $header, $this->payLoad);
59
-                break;
60
-            case 'GET':
61
-                if($this->hasPayload)
62
-                {
63
-                    $result = Requests::get($url, $header, $this->payLoad);
64
-                }
65
-                else
66
-                {
67
-                    $result = Requests::get($url, $header);
68
-                }
69
-                break;
70
-            case 'PUT':
71
-                $result = Requests::put($url, $header, $this->payLoad);
72
-                break;
73
-        }
74
-
75
-        http_response_code($result->status_code);
76
-
77
-        switch ($result->status_code) {
78
-            case 200:
79
-                $result = json_decode($result->body, true);
80
-                break;
81
-            case 204:
82
-                $result = 'Success';
83
-                http_response_code(200);
84
-                break;
85
-            case 400:
86
-                $result = json_decode($result->body, true);
87
-                error_log('Error 400 - ' . print_r($result, true));
88
-                break;
89
-            case 401:
90
-
91
-                if($result == "Unauthorized")
92
-                {
93
-                    error_log("Error 401: Unauthorized");
94
-                }
95
-                else
96
-                {
97
-                    $result = json_decode($result->body, true);
98
-
99
-                    if(is_array($result) && $result['error'] == 'length')
100
-                    {
101
-
102
-                    }
103
-                    else
104
-                    {
105
-                        error_log('Error 401 - ' . print_r($result, true));
106
-                    }
107
-                }
108
-
109
-
110
-                break;
111
-            case 404:
112
-
113
-
114
-                error_log('Error 404 - ' . print_r($result, true));
115
-                $result = json_decode($result->body, true);
116
-
117
-                if(array_key_exists('error', $result) && $result['error'] == 'post_blocked')
118
-                {
119
-                    header('HTTP/1.0 404 Not Found');
120
-                    include('error-pages/404.php');
121
-                    exit();
122
-                }
123
-
124
-                break;
56
+		switch ($this->getMethod()) {
57
+			case 'POST':
58
+				$result = Requests::post($url, $header, $this->payLoad);
59
+				break;
60
+			case 'GET':
61
+				if($this->hasPayload)
62
+				{
63
+					$result = Requests::get($url, $header, $this->payLoad);
64
+				}
65
+				else
66
+				{
67
+					$result = Requests::get($url, $header);
68
+				}
69
+				break;
70
+			case 'PUT':
71
+				$result = Requests::put($url, $header, $this->payLoad);
72
+				break;
73
+		}
74
+
75
+		http_response_code($result->status_code);
76
+
77
+		switch ($result->status_code) {
78
+			case 200:
79
+				$result = json_decode($result->body, true);
80
+				break;
81
+			case 204:
82
+				$result = 'Success';
83
+				http_response_code(200);
84
+				break;
85
+			case 400:
86
+				$result = json_decode($result->body, true);
87
+				error_log('Error 400 - ' . print_r($result, true));
88
+				break;
89
+			case 401:
90
+
91
+				if($result == "Unauthorized")
92
+				{
93
+					error_log("Error 401: Unauthorized");
94
+				}
95
+				else
96
+				{
97
+					$result = json_decode($result->body, true);
98
+
99
+					if(is_array($result) && $result['error'] == 'length')
100
+					{
101
+
102
+					}
103
+					else
104
+					{
105
+						error_log('Error 401 - ' . print_r($result, true));
106
+					}
107
+				}
108
+
109
+
110
+				break;
111
+			case 404:
112
+
113
+
114
+				error_log('Error 404 - ' . print_r($result, true));
115
+				$result = json_decode($result->body, true);
116
+
117
+				if(array_key_exists('error', $result) && $result['error'] == 'post_blocked')
118
+				{
119
+					header('HTTP/1.0 404 Not Found');
120
+					include('error-pages/404.php');
121
+					exit();
122
+				}
123
+
124
+				break;
125 125
 			case 477:
126
-                $result = json_decode($result->body, true);
127
-                error_log('Error 477 - ' . print_r($result, true));
128
-                break;
129
-            case 429:
130
-                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
131
-            	exit("Error 429: Too Many Requests");
132
-            	break;
133
-            case 403:
134
-                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
135
-                $result = json_decode($result->body, true);
136
-                break;
137
-            case 502:
138
-                error_log('Error 502 - ' . print_r($result, true));
139
-                $result = json_decode($result->body, true);
140
-                header('location:'.$_SERVER['PHP_SELF']);
141
-                break;
142
-            case 503:
143
-                error_log('Error 503 - ' . print_r($result, true));
144
-                $result = json_decode($result->body, true);
145
-
146
-                if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
147
-                {
148
-                    header('location:'.$_SERVER['PHP_SELF']); 
149
-                }
150
-                break;
151
-            default:
152
-                error_log('Error '.$result->status_code.' - unknown error');
153
-                $result = json_decode($result->body, true);
154
-        }
155
-
156
-        //important for account refresh
157
-        if($device_uid != '')
158
-        {
126
+				$result = json_decode($result->body, true);
127
+				error_log('Error 477 - ' . print_r($result, true));
128
+				break;
129
+			case 429:
130
+				error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
131
+				exit("Error 429: Too Many Requests");
132
+				break;
133
+			case 403:
134
+				error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
135
+				$result = json_decode($result->body, true);
136
+				break;
137
+			case 502:
138
+				error_log('Error 502 - ' . print_r($result, true));
139
+				$result = json_decode($result->body, true);
140
+				header('location:'.$_SERVER['PHP_SELF']);
141
+				break;
142
+			case 503:
143
+				error_log('Error 503 - ' . print_r($result, true));
144
+				$result = json_decode($result->body, true);
145
+
146
+				if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
147
+				{
148
+					header('location:'.$_SERVER['PHP_SELF']); 
149
+				}
150
+				break;
151
+			default:
152
+				error_log('Error '.$result->status_code.' - unknown error');
153
+				$result = json_decode($result->body, true);
154
+		}
155
+
156
+		//important for account refresh
157
+		if($device_uid != '')
158
+		{
159 159
 			$result[0] = $result;
160 160
 			$result[1] = $device_uid;
161
-        }
161
+		}
162 162
 
163 163
         
164
-        /*
164
+		/*
165 165
         var_dump($result);
166 166
         */
167 167
         
168
-        return $result;
169
-    }
170
-    abstract function getPayload();
171
-    /**
172
-     * Gets Sign headers
173
-     * @return array headers
174
-     */
175
-    private function getSignHeaders()
176
-    {
168
+		return $result;
169
+	}
170
+	abstract function getPayload();
171
+	/**
172
+	 * Gets Sign headers
173
+	 * @return array headers
174
+	 */
175
+	private function getSignHeaders()
176
+	{
177 177
 			if($this->getAccessToken() == null) {
178 178
 				$payload_accessToken = "";
179 179
 			}
@@ -182,54 +182,54 @@  discard block
 block discarded – undo
182 182
 			}
183 183
 			
184 184
 			
185
-        $headers = array(
186
-            "Connection" => "keep-alive",
187
-            "Accept-Encoding" => "gzip",
188
-            "Content-Type" => "application/json; charset=UTF-8",
189
-            "User-Agent" => self::USERAGENT
190
-        );
191
-        $timestamp = new DateTime();
192
-        $timestamp = $timestamp->format(DateTime::ATOM);
193
-        $timestamp = substr($timestamp, 0, -6);
194
-        $timestamp .= "Z";
195
-        $urlParts = parse_url($this->getFullUrl());
196
-        $url2 = "";
197
-        $req = [$this->getMethod(),
198
-            $urlParts['host'],
199
-            "443",
200
-            $urlParts['path'],
201
-            $payload_accessToken,
202
-            $timestamp,
203
-            $url2,
204
-            $this->payLoad];
205
-        $reqString = implode("%", $req);
206
-        $secret = self::SECRET;
207
-        $signature = hash_hmac('sha1', $reqString, $secret);
208
-        $signature = strtoupper($signature);
209
-        $headers['X-Authorization'] = 'HMAC ' . $signature;
210
-        $headers['X-Client-Type'] = self::CLIENT_TYPE;
211
-        $headers['X-Timestamp'] = $timestamp;
212
-        $headers['X-Api-Version'] = '0.2';
213
-        return $headers;
214
-    }
215
-    private function getFullUrl()
216
-    {
217
-        return self::APIURL . $this->getApiEndPoint();
218
-    }
219
-    abstract function getApiEndPoint();
220
-    abstract function getMethod();
221
-    /**
222
-     * @return string
223
-     */
224
-    private function getAccessToken()
225
-    {
226
-        return $this->accessToken;
227
-    }
228
-    /**
229
-     * @param string $accessToken
230
-     */
231
-    public function setAccessToken($accessToken)
232
-    {
233
-        $this->accessToken = $accessToken;
234
-    }
185
+		$headers = array(
186
+			"Connection" => "keep-alive",
187
+			"Accept-Encoding" => "gzip",
188
+			"Content-Type" => "application/json; charset=UTF-8",
189
+			"User-Agent" => self::USERAGENT
190
+		);
191
+		$timestamp = new DateTime();
192
+		$timestamp = $timestamp->format(DateTime::ATOM);
193
+		$timestamp = substr($timestamp, 0, -6);
194
+		$timestamp .= "Z";
195
+		$urlParts = parse_url($this->getFullUrl());
196
+		$url2 = "";
197
+		$req = [$this->getMethod(),
198
+			$urlParts['host'],
199
+			"443",
200
+			$urlParts['path'],
201
+			$payload_accessToken,
202
+			$timestamp,
203
+			$url2,
204
+			$this->payLoad];
205
+		$reqString = implode("%", $req);
206
+		$secret = self::SECRET;
207
+		$signature = hash_hmac('sha1', $reqString, $secret);
208
+		$signature = strtoupper($signature);
209
+		$headers['X-Authorization'] = 'HMAC ' . $signature;
210
+		$headers['X-Client-Type'] = self::CLIENT_TYPE;
211
+		$headers['X-Timestamp'] = $timestamp;
212
+		$headers['X-Api-Version'] = '0.2';
213
+		return $headers;
214
+	}
215
+	private function getFullUrl()
216
+	{
217
+		return self::APIURL . $this->getApiEndPoint();
218
+	}
219
+	abstract function getApiEndPoint();
220
+	abstract function getMethod();
221
+	/**
222
+	 * @return string
223
+	 */
224
+	private function getAccessToken()
225
+	{
226
+		return $this->accessToken;
227
+	}
228
+	/**
229
+	 * @param string $accessToken
230
+	 */
231
+	public function setAccessToken($accessToken)
232
+	{
233
+		$this->accessToken = $accessToken;
234
+	}
235 235
 }
Please login to merge, or discard this patch.