| 1 |  |  | <?php | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | include 'php/DatabaseConnect.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | include 'php/Location.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | include 'php/JodelAccount.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | include 'php/Jodel.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | include 'php/View.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | include 'php/Requests/AbstractRequest.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | include 'php/Requests/CreateUser.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | include 'php/Requests/GetPosts.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | include 'php/Requests/GetKarma.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | include 'php/Requests/UpdateLocation.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | include 'php/Requests/Upvote.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | include 'php/Requests/Downvote.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | include 'php/Requests/GetPostDetails.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | include 'php/Requests/SendJodel.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | include 'php/Requests/GetCaptcha.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | include 'php/Requests/PostCaptcha.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | include 'php/Requests/GetUserConfig.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | include 'php/Requests/GetChannel.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | require_once 'php/Requests/libary/Requests.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | Requests::register_autoloader(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | $config = parse_ini_file('config/config.ini.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | $location = new Location(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | $location->setLat($config['default_lat']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | $location->setLng($config['default_lng']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | $location->setCityName($config['default_location']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | $lastPostId = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | //What is dude doing with my Server? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | if($_SERVER['REMOTE_ADDR'] == '94.231.103.52') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	echo('You are flooting my Server! Pls enable Cookies in your script and contact me: [email protected]'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	die(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | function isUserBot() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     return (isset($matches[0])) ? true : false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  | function configPropertyExists($config, $property) | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     if(!array_key_exists($property, $config) || !isset($config[$property]) || $config[$property] == '' || $config[$property] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         return FALSE; | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     else | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         return TRUE; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | function isDeviceUidInDatabase($deviceUid) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     $db = new DatabaseConnect();   | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid  . "'"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     if ($result->num_rows > 0) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         return TRUE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         return FALSE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	//Check if it's a Spider or Google Bot | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	if(configPropertyExists($config, 'botDeviceUid') && isUserBot()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		error_log('Spider or Bot checked in!'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		$jodelAccountForView = new JodelAccount($config['botDeviceUid'], TRUE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		if(!isset($_COOKIE['JodelDeviceId']) || !isDeviceUidInDatabase($_COOKIE['JodelDeviceId'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 			//$deviceUid = createAccount(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 			$jodelAccountForView = new JodelAccount(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 			setcookie('JodelDeviceId', $jodelAccountForView->deviceUid, time()+60*60*24*365*10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			error_log('Created account with JodelDeviceId:' . $jodelAccountForView->deviceUid .  ' for [' . $_SERVER ['HTTP_USER_AGENT'] . ']'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 			$jodelAccountForView = new JodelAccount($_COOKIE['JodelDeviceId']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 	if(configPropertyExists($config, 'karmaDeviceUid')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     	$jodelAccountForKarma = new JodelAccount($config['botDeviceUid']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     	error_log("No Karma deviceUid set in config file"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 		$jodelAccountForKarma = new JodelAccount($deviceUid); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	$newPositionStatus = $jodelAccountForView->location->getCityName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	//Cunstruct View | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	$viewTest = new View(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	//Set View | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 116 |  | View Code Duplication | 	if(isset($_GET['view'])) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		switch ($_GET['view']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 			case 'comment': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 				$view = 'comment'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 			case 'upVote': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 				$view = 'upVote'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 			default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 				$view = 'time'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 	else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 		$view = 'time'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 	//Verify Account | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 	if(isset($_GET['solution']) && isset($_GET['key'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 		$jodelAccountForKarma->verifyCaptcha(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	//Set Location | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 	if(isset($_GET['city'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 		$newPositionStatus = $jodelAccountForView->setLocation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 	//Vote | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 	if(isset($_GET['vote']) && isset($_GET['postID'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 		$jodelAccountForKarma->votePostId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 	//SendJodel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 	if(isset($_POST['message'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 		$jodelAccountForKarma->sendJodel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 162 |  | View Code Duplication | 	function getPosts($lastPostId, $accessToken, $url, $version = 'v2') | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 	{	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 		$accountCreator = new GetPosts(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 		$accountCreator->setLastPostId($lastPostId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 		$accountCreator->setAccessToken($accessToken); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 		$accountCreator->setUrl($url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 		$accountCreator->version = $version; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 		$config = parse_ini_file('config/config.ini.php'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 		$location = new Location(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 		$location->setLat($config['default_lat']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 		$location->setLng($config['default_lng']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 		$location->setCityName($config['default_location']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 		$accountCreator->location = $location; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  | 		$data = $accountCreator->execute(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 		return $data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 	$posts; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 	//Is Channel or City | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 	if(isset($_GET['city']) && substr($_GET['city'], 0, 1) === '#') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 		$channel = substr($_GET['city'], 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 		$accountCreator = new GetChannel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 		$accountCreator->setAccessToken($jodelAccountForView->accessToken); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 		$accountCreator->channel = $channel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 		$posts = $accountCreator->execute(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 		if(array_key_exists('recent', $posts)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 			$posts = $posts['recent']; | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 194 |  | View Code Duplication | 			if(!array_key_exists(0, $posts)) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | 				$posts[0] = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 			    "post_id" => "0", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 			    "discovered_by" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 			    "message" => "Not found", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | 			    "created_at" => "2017-02-11T16:44:50.385Z", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 			    "updated_at" => "2017-02-11T16:44:50.385Z", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 			    "pin_count" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 			    "color" => "FFBA00", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 			    "got_thanks" => FALSE, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 			    "post_own" => "friend", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 			    "discovered" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  | 			    "distance" => 9, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  | 			    "vote_count" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | 			    "location" => | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  | 			    array("name" => "Berlin", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  | 			      "loc_coordinates" => | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  | 			      array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | 			        "lat" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | 			        "lng" => 0 | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  | 			      ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  | 			      "loc_accuracy" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | 			      "country" => "", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | 			      "city" => "", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  | 			    ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | 			    "tags" => | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 			    array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | 			    "user_handle" => "0" | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | 			 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 		} | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 226 |  | View Code Duplication | 		else | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  | 			$posts = array(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | 			$posts[0] =  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | 			array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  | 			    "post_id" => "0", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  | 			    "discovered_by" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | 			    "message" => "Bad Request", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | 			    "created_at" => "2017-02-11T16:44:50.385Z", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | 			    "updated_at" => "2017-02-11T16:44:50.385Z", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | 			    "pin_count" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  | 			    "color" => "FFBA00", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  | 			    "got_thanks" => FALSE, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | 			    "post_own" => "friend", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 			    "discovered" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  | 			    "distance" => 9, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  | 			    "vote_count" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  | 			    "location" => | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | 			    array("name" => "Berlin", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  | 			      "loc_coordinates" => | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | 			      array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 			        "lat" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | 			        "lng" => 0 | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | 			      ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 			      "loc_accuracy" => 0, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 			      "country" => "", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  | 			      "city" => "", | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | 			    ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 			    "tags" => | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | 			    array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  | 			    "user_handle" => "0" | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 			 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 		$loops = 29; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | 		$isDetailedView = FALSE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | 	else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  | 		//Get Post Details | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 		if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | 			$userHandleBuffer = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  | 			$accountCreator = new GetPostDetails(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  | 			$accountCreator->setAccessToken($jodelAccountForView->accessToken); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  | 			$data = $accountCreator->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  | 			if(array_key_exists('status_code', $data) && $data->status_code == 404) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  | 				header('HTTP/1.1 410 Gone'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  | 				include './error-pages/410.html'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  | 				exit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  | 			$posts[0] = $data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  | 			if(array_key_exists('children', $data)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  | 				foreach($data['children'] as $key => $child) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  | 				{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  | 					 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  | 					if(!$child["parent_creator"] == 1) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  | 					{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  | 						$numberForUser = array_search($child['user_handle'], $userHandleBuffer); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  | 						if($numberForUser === FALSE) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  | 						{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  | 							array_push($userHandleBuffer, $child['user_handle']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  | 							$data['children'][$key]['user_handle'] = count($userHandleBuffer); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  | 						} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  | 						else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  | 						{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  | 							$data['children'][$key]['user_handle'] = $numberForUser + 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  | 						} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  | 					array_push($posts, $data['children'][$key]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  | 				$loops = $data['child_count'] + 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  | 			else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  | 				$loops = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  | 			$isDetailedView = TRUE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  | 		//Get Posts | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  | 		else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  | 			$version = 'v2'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  | 			if($view=='comment') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  | 				$url = "/v2/posts/location/discussed/"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  | 			else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  | 				if($view=='upVote') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  | 				{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  | 					$url = "/v2/posts/location/popular/"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  | 				else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  | 				{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  | 					$url = "/v3/posts/location/combo/"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  | 					$version = 'v3'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  | 			if($version == 'v3') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  | 				$posts = getPosts($lastPostId, $jodelAccountForView->accessToken, $url, $version)['recent']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  | 			else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  | 				$posts = getPosts($lastPostId, $jodelAccountForView->accessToken, $url, $version)['posts']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  | 			$loops = 29; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  | 			$isDetailedView = FALSE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  | 		} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 344 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 345 |  |  | ?> | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                        
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.