setTemplateDir('./templates'); $smarty->setCompileDir('./templates/tmp/templates_c'); $mobileLink = "http://www.LoveSpotter.de/"; use \ForceUTF8\Encoding; if (preg_match('#^([0-9]+).lovespotter.de$#i', $_SERVER["HTTP_HOST"], $result)) { $idLocation = stripAll($result[1]); $location = dbobject::getById("Location", $idLocation); if (issetAndNotEmpty($location) && issetAndNotEmpty($location->id)) { $searchURL = "/" . urlencode($location->city) . "/" . urlencode($location->name) . "-" . $location->id; header("Location: http://www.LoveSpotter.de/#loveSpott" . $searchURL); exit(); } else { header("Location: http://www.LoveSpotter.de/#loveSpott"); exit(); } } if (issetAndNotEmpty($_GET["login"])) { $_SESSION["login"] = $_GET["login"]; header("Location: ./"); exit(); //TODO //exit("LOGIN: " . $_GET["login"]); } if (strcmp($_SERVER['REQUEST_METHOD'], "POST") == 0 && strcmp($_POST["do"], "uploadUserImage") != 0 && strcmp($_POST["do"], "uploadLocationImage") != 0) { $postToken = stripAll($_POST["securityToken"]); if (issetAndNotEmpty($postToken) && strcmp($postToken, $_SESSION["requestSecurityToken"]) == 0) { unset($_SESSION["requestSecurityToken"]); } else { //request fehlerhaft // exit("invalid request"); } } if ($_GET["do"] == "mtest") { error_reporting(E_ALL); $smarty->assign('request', $newRequest); $smarty->assign('baseURL', $baseURL); $smarty->assign('loveSession', $loveSession); $smarty->assign('isFlirt', $isFlirt); $smarty->assign('isLoveSpott', $isLoveSpott); $content = $smarty->fetch('templates/mail_message_newRequest-test.tpl'); echo("Content: " . $content); exit("TEST"); } if ($_GET["do"] == "qr") { $location = dbObject::getById("Location", issetAndNotEmpty($_GET["id"]) ? $_GET["id"] : "38"); $qrObjectId = getQRCodeLocation(QRCODE_SIZE_BIG, $location, "loveSpott", true); exit(); } if (!issetAndNotEmpty($_SESSION["requestSecurityToken"])) { $_SESSION["requestSecurityToken"] = generateToken(); } if (strcmp(stripAll($_GET["do"]), "getQR") == 0 && issetAndNotEmpty(stripAll($_GET["id"]))) { $qrId = stripAll($_GET["id"]); header("Content-Type: image/png"); echo file_get_contents("qr/" . $qrId . ".png"); exit(); } $attributes = array(); $attributes["baseURL"] = $baseURL; $attributes["securityToken"] = $_SESSION["requestSecurityToken"]; $attributes["uniqueLoginID"] = $_SESSION["login"]; if ($_GET["do"] == "testFB") { $request = dbobject::getById("Request", "16"); postRequestToFacebookSite($request); exit(); } //if ($_GET["do"] == "exchangeFBToken") { // $accessToken = "a9b63cbb835a4127984d5201945e6fd5"; // $clientId = "248275301975660"; // $clientSecret = "a9b63cbb835a4127984d5201945e6fd5"; // // $fbAuthToken = getFBAuthToken(); // $cache->save($cache_key, $fbAuthToken, array( // Nette\Caching\Cache::EXPIRE => '+ 65 minutes' // accepts also seconds or a timestamp. // )); // // echo "TOKEN:".$fbAuthToken; // exit(); //} //$cache_key = md5("fbAuthToken"); //$fbAuthToken = null;//$cache->load($cache_key); //if ($fbAuthToken == null) { // $fbAuthToken = getFBAuthToken(); // $cache->save($cache_key, $fbAuthToken, array( // Nette\Caching\Cache::EXPIRE => '+ 65 minutes' // accepts also seconds or a timestamp. // )); //} // //if (issetAndNotEmpty($fbAuthToken)) { // $attributes["fbAuthToken"] = $fbAuthToken; //} if (issetAndNotEmpty($_GET["getTmpImage"])) { $image = stripAll($_GET["getTmpImage"]); header('Content-Type: image/png'); switch (stripAll($_GET["type"])) { case "thumbnail": $image = IMG_PATH_THUMBNAIL . "/" . $image; echo file_get_contents($image); break; case "original": default: $image = IMG_PATH_ORIGINAL . "/" . $image; echo file_get_contents($image); break; } exit(); } if (issetAndNotEmpty($_GET["getImageForUser"])) { $requestId = stripAll($_GET["getImageForUser"]); if (!issetAndNotEmpty($requestId)) { exit(); } $request = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$requestId."'"); if (!issetAndNotEmpty($request)) { exit(); } header('Content-Type: image/png'); if (!issetAndNotEmpty($request->image) && !issetAndNotEmpty($request->imageThumbnailURL)) { if ($request->isMale()) { $image = "img/ersatzbild-m.jpg"; } else { $image = "img/ersatzbild-w.jpg"; } echo file_get_contents($image); exit(); } switch (stripAll($_GET["type"])) { case "thumbnail": $image = null; if (issetAndNotEmpty($request->image)) { $image = IMG_PATH_THUMBNAIL . "/" . $request->image; } else if (issetAndNotEmpty($request->imageThumbnailURL)) { $image = $request->imageThumbnailURL; } if ($image == null) { exit(); } echo file_get_contents($image); break; case "original": default: $image = null; if (issetAndNotEmpty($request->image)) { $image = IMG_PATH_ORIGINAL . "/" . $request->image; } else if (issetAndNotEmpty($request->imagePreviewURL)) { $image = $request->imagePreviewURL; } if ($image == null) { exit(); } echo file_get_contents($image); break; } exit(); } if ($_GET["do"] == "test") { echo "TMP: " . $tmp_dir . "
"; echo "Test Before: " . $cache->load("test"); echo "
"; // $cache->save("test", "das ist ein test"); $cache->save("test", "das ist ein test", array( Nette\Caching\Cache::EXPIRE => '+ 60 minutes', // accepts also seconds or a timestamp. )); echo "Test After: " . $cache->load("test"); echo "
"; exit(); } if (issetAndNotEmpty($_GET["getImageForLocation"])) { $imageName = stripAll($_GET["getImageForLocation"]); header('Content-Type: image/png'); switch (stripAll($_GET["type"])) { case "original": echo file_get_contents(IMG_PATH_ORIGINAL . "/" . $imageName); break; case "preview": echo file_get_contents(IMG_PATH_PREVIEW . "/" . $imageName); break; default: echo file_get_contents(IMG_PATH_THUMBNAIL . "/" . $imageName); } exit(); } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "uploadUserImage") == 0) { $upload_handler = new UploadHandler("user", null); header('Pragma: no ache'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Content-Disposition: inline; filename = "files.json"'); header('X-Content-Type-Options: nosniff'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE'); header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size'); switch ($_SERVER['REQUEST_METHOD']) { case 'OPTIONS': break; case 'HEAD': case 'GET': $upload_handler->get(); break; case 'POST': if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') { $upload_handler->delete(); } else { $info = $upload_handler->post(); } break; case 'DELETE': $upload_handler->delete(); break; default: header('HTTP / 1.1 405 Method Not Allowed'); } exit(); } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "uploadLocationImage") == 0) { $upload_handler = new UploadHandler("location", null); header('Pragma: no ache'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Content-Disposition: inline; filename = "files.json"'); header('X-Content-Type-Options: nosniff'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE'); header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size'); switch ($_SERVER['REQUEST_METHOD']) { case 'OPTIONS': break; case 'HEAD': case 'GET': $upload_handler->get(); break; case 'POST': if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') { $upload_handler->delete(); } else { $info = $upload_handler->post(); } break; case 'DELETE': $upload_handler->delete(); break; default: header('HTTP / 1.1 405 Method Not Allowed'); } exit(); } if (issetAndNotEmpty($_GET["do"]) && strcmp($_GET["do"], "searchLocation") == 0) { $callback = $_GET["callback"]; $city = $_GET["city"]; $type = $_GET["type"]; $startsWith = stripAll($_GET["query"]); $fqLocations = array(); $result = array(); $lat = stripAll($_GET["lat"]); $long = stripAll($_GET["long"]); $ll = (issetAndNotEmpty($lat) && issetAndNotEmpty($long) ? $lat . "," . $long : ""); if (issetAndNotEmpty($startsWith) && issetAndNotEmpty($lat) && issetAndNotEmpty($long)) { $locations = fetchMatchedLocationsByGeometry($lat, $long, 10, $startsWith); // $locations = dbobject::getAll("Location", "WHERE `name` LIKE '%" . $startsWith . "%' AND `city` LIKE '%".$city."%'"); if (issetAndNotEmpty($locations)) { foreach ($locations as $location) { $item = array("id" => $location->id, "fqId" => $location->fqId, "name" => $location->name, "city" => $location->city, "address" => $location->address); array_push($result, $item); if (issetAndNotEmpty($location->fqId)) { array_push($fqLocations, $location->fqId); } } } } // if (strcmp($type, "own") == 0 || strcmp($type, "both") == 0) { // // } if (strcmp($type, "fq") == 0 || strcmp($type, "both") == 0) { if (issetAndNotEmpty($ll) || issetAndNotEmpty($city)) { $url = ""; if (issetAndNotEmpty($ll)) { $url = "https://api.foursquare.com/v2/venues/explore" . "?client_id=" . FQ_CLIENT_ID . "&client_secret=" . FQ_CLIENT_SECRET . "&ll=" . $ll . "&v=".date("Ymd") . "&query=" . $startsWith; } else { $url = "https://api.foursquare.com/v2/venues/explore" . "?client_id=" . FQ_CLIENT_ID . "&client_secret=" . FQ_CLIENT_SECRET . "&near=" . urlencode($city) . "&v=".date("Ymd") . "&query=" . $startsWith; } //echo "URL: $url"; //exit(); $cache_key = md5($url); $response = $cache->load($cache_key); //echo "$response: $response"; if(!$response) { $curlhandle = curl_init(); curl_setopt($curlhandle, CURLOPT_URL, $url); curl_setopt($curlhandle, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($curlhandle); curl_close($curlhandle); $cache->save($cache_key, $response, array( Nette\Caching\Cache::EXPIRE => '+ 60 minutes' // accepts also seconds or a timestamp. )); //save_cache($response, $cache_key, $timestamp); } $json = json_decode($response); foreach ($json->response->groups as $group) { foreach ($group->items as $item) { //echo "ITEM: $item"; if (!issetAndNotEmpty($item->venue) || !issetAndNotEmpty($item->venue->location)) { continue; } $fqId = $item->venue->id; $name = $item->venue->name; $city = $item->venue->location->city; $address = $item->venue->location->address; if (in_array($fqId, $fqLocations)) { continue; } if (!issetAndNotEmpty($fqId) || !issetAndNotEmpty($name) || !issetAndNotEmpty($city) || !issetAndNotEmpty(address)) { continue; } $item = array("id" => "", "fqId" => $fqId, "name" => $name, "city" => $city, "address" => $address); array_push($result, $item); } } } } echo $callback . "(" . json_encode($result) . ")"; exit(); } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "getLastSearch") == 0) { if (strcmp(stripAll($_POST["isFlirt"]), "true") == 0) { $lastSearchFlirt = unserialize($_SESSION["lastSearchFlirt"]); exitWithToken(json_encode($lastSearchFlirt)); } else if (strcmp(stripAll($_POST["isLoveSpott"]), "true") == 0) { $lastSearchSpott = unserialize($_SESSION["lastSearchLoveSpott"]); exitWithToken(json_encode($lastSearchSpott)); } else { $lastSearchLocation = unserialize($_SESSION["lastSearchLocation"]); $result = array("searchLocationName" => $lastSearchLocation->name, "searchLocationCity" => $lastSearchLocation->city, "searchLocationCityFQID" => $lastSearchLocation->fqId, "searchLocationID" => $lastSearchLocation->id, "searchDate" => $_SESSION["lastSearchDate"]); exitWithToken(json_encode($result)); } } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "getObjectsForFBPost") == 0) { $requestId = stripAll($_POST["requestId"]); $type = stripAll($_POST["type"]); $request = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$requestId."'"); if ($request != null) { $isFlirt = (strcmp($request->requestType, Request::$typeFlirt) == 0 ? true : false); $location = $request->toLocation(); if ($location == null && !$isFlirt) { exitWithToken("false2"); } // $values = array( // 'message' => 'Helft mir bei www.LoveSpotter.de mein Glück zu finden:', // 'name' => ucfirst($request->name) . ", " . $request->age . " sucht", // 'caption' => "am " . date("d.m.Y", $request->when) ." bei " . $location->name . " " . $location->city, // 'link' => "http://www.lovespotter.de/#search/".$location->city."/".$location->name."-" . $location->id, // 'description' => str_replace("\n", "
", stripAllWitHTMLAllowed(base64_decode($request->text))), // //'privacy' => array("value" => "SELF"), // 'picture' => "http://www.lovespotter.de/?type=thumbnail&getImageForUser=" . $request->uniqueId, // 'actions' => array(array("name" => 'LoveSpotter on Facebook', "link" => 'https://www.facebook.com/pages/Spotted-Lovespotter-Die-Suchmaschine-für-verpasste-Chancen/345467155562216?fref=ts')) // ); $link = $baseURL."/#search/".$location->city."/".$location->name."-" . $location->id; $text = "Helft mir bei www.LoveSpotter.de mein Glück zu finden:"; if (strcmp($type, "details") == 0) { $link = $baseURL."/#show/".$request->uniqueId; } if ($isFlirt) { $values = array( 'message' => $link, 'name' => ucfirst($request->name) . ", " . $request->age . " sucht", 'caption' => "aus " . $request->where . ($location != null ? " bei " . $location->name : ""), 'link' => $baseURL."/#search/". ($location != null ? $location->city."/".$location->name."-" . $location->id : $request->where . "/" . $request->whereLat . "," . $request->whereLong), 'description' => str_replace("\n", "
", stripAllWitHTMLAllowed(base64_decode($request->text))), //'privacy' => array("value" => "SELF"), 'picture' => $baseURL."/?type=thumbnail&getImageForUser=" . $request->uniqueId, 'actions' => array(array("name" => 'LoveSpotter on Facebook', "link" => 'https://www.facebook.com/pages/Spotted-Lovespotter-Die-Suchmaschine-für-verpasste-Chancen/345467155562216?fref=ts')) ); } else { $values = array( 'message' => $text, 'name' => ucfirst($request->name) . ", " . $request->age . " sucht", 'caption' => "am " . date("d.m.Y", $request->when) ." bei " . $location->name . " " . $location->city, 'link' => $link, 'description' => str_replace("\n", "
", stripAllWitHTMLAllowed(base64_decode($request->text))), //'privacy' => array("value" => "SELF"), 'picture' => $baseURL."/?type=thumbnail&getImageForUser=" . $request->uniqueId, 'actions' => array(array("name" => 'LoveSpotter on Facebook', "link" => 'https://www.facebook.com/pages/Spotted-Lovespotter-Die-Suchmaschine-für-verpasste-Chancen/345467155562216?fref=ts')) ); } exitWithToken(json_encode($values)); } exitWithToken("false1"); } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "deleteRequest") == 0) { $securityCode = stripAll($_POST["securityCode"]); $uniqueId = stripAll($_POST["uniqueId"]); $confirmed = stripAll($_POST["confirmed"]); if (!issetAndNotEmpty($securityCode) || !issetAndNotEmpty($uniqueId)) { exitWithToken("false"); } $request = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$uniqueId."'"); if ($request == null || strcmp($request->securityCode, $securityCode) != 0) { exitWithToken("false"); } if ($confirmed == "true") { $request->delete(); exitWithToken("true"); } else { exitWithToken("false:needConfirmation"); } } if (issetAndNotEmpty($_GET["do"]) && strcmp($_GET["do"], "getPage") == 0) { $pageString = stripAll($_GET["page"]); if (issetAndNotEmpty(stripAll($_GET["isFlirtPage"]))) { $isFlirtPage = (stripAll($_GET["isFlirtPage"]) == "true" ? true : false); } $attributes = parseAttr($attributes); switch ($pageString) { case "start": $attributes["lastSearchLocation"] = unserialize($_SESSION["lastSearchLocation"]); $attributes["lastSearchDate"] = $_SESSION["lastSearchDate"]; if (preg_match("#([0-9]{2})\.([0-9]{2})\.([0-9]{4})#", $_SESSION["lastSearchDate"], $result)) { $attributes["lastSearchDateForMobile"] = $result[3] . "-" . $result[2] . "-" . $result[1]; } if ($isFlirtPage == true) { show("index_flirt_start.tpl", $attributes); } else { show("index_start.tpl", $attributes); } exit(); case "searchLoveSpott": $isLoveSpott = true; $attributes["searchCity"] = Encoding::toUTF8(urldecode($attributes["searchCity"])); if (issetAndNotEmpty($attributes["searchLocationID"])) { // $location = dbobject::getOne("Location", " WHERE `id` = ".$attributes["searchLocationID"]." AND `name` LIKE '".$attributes["searchLocation"]."'"); $location = dbobject::getOne("Location", " WHERE `id` = ".$attributes["searchLocationID"]); if (issetAndNotEmpty($location)) { $location->city = utf8_encode($location->city); $attributes["searchLat"] = $location->fqLat; $attributes["searchLong"] = $location->fqLong; $locationRequests = dbobject::getAll("Request", "WHERE `idLocation` = ".$location->id . " AND `confirmed` = 1"); if (issetAndNotEmpty($attributes["searchRadius"])) { $locationRadiusRequests = fetchMatchedLoveSpottRequests($location->city, $location->fqLat, $location->fqLong, $attributes["searchRadius"]); $requests = array_merge($locationRequests, $locationRadiusRequests); } else { $requests = $locationRequests; } $attributes["matchedRequests"] = array_unique($requests); $attributes["searchCity"] = $city; $attributes["searchLocation"] = html_entity_decode($location->name); $attributes["location"] = $location; } else { $attributes["matchedRequests"] = array(); show("index_loveSpott_overview.tpl", $attributes); exit(); } } else { if (!issetAndNotEmpty($attributes["searchRadius"])) { $attributes["searchRadius"] = "5"; } $attributes["matchedRequests"] = fetchMatchedLoveSpottRequests($attributes["searchCity"], $attributes["searchLat"], $attributes["searchLong"], $attributes["searchRadius"]); } $lastSearch = new LastLoveSpottSearch(); $lastSearch->searchCity = $attributes["searchCity"]; $lastSearch->searchLat = $attributes["searchLat"]; $lastSearch->searchLong = $attributes["searchLong"]; $lastSearch->searchRadius = $attributes["searchRadius"]; $_SESSION["lastSearchLoveSpott"] = serialize($lastSearch); show("index_loveSpott_overview.tpl", $attributes); exit(); break; case "searchFlirt": $attributes["searchFlirtCity"] = Encoding::toUTF8(urldecode($attributes["searchFlirtCity"])); if (!issetAndNotEmpty($attributes["searchFlirtRadius"])) { $attributes["searchFlirtRadius"] = "10"; } $lastFlirtSearch = new LastFlirtSearch(); $lastFlirtSearch->searchFlirtCity = $attributes["searchFlirtCity"]; $lastFlirtSearch->searchFlirtLat = $attributes["searchFlirtLat"]; $lastFlirtSearch->searchFlirtLong = $attributes["searchFlirtLong"]; $lastFlirtSearch->searchFlirtRadius = $attributes["searchFlirtRadius"]; $lastFlirtSearch->searchFlirtOwnGender = $attributes["searchFlirtOwnGender"]; $lastFlirtSearch->searchFlirtSearchGender = $attributes["searchFlirtSearchGender"]; $_SESSION["lastSearchFlirt"] = serialize($lastFlirtSearch); $attributes["matchedRequests"] = fetchMatchedFlirtRequests($attributes["searchFlirtCity"], $attributes["searchFlirtLat"], $attributes["searchFlirtLong"], $attributes["searchFlirtRadius"], $attributes["searchFlirtOwnGender"], $attributes["searchFlirtSearchGender"]); show("index_flirt_overview.tpl", $attributes); exit(); break; /* case "search": $attributes["searchCity"] = urldecode($attributes["searchCity"]); $searchCity = $attributes["searchCity"]; if (issetAndNotEmpty($searchCity)) { $_SESSION["lastSearchLocation"] = serialize($location); $_SESSION["lastSearchDate"] = $searchDate; $attributes["matchedRequests"] = fetchMatchedRequestsForCity($searchCity); show("index_overview.tpl", $attributes); exit(); } else { exitWithToken("false:invalidLocation"); } */ case "search": if (preg_match("#([0-9]{4})-([0-9]{2})-([0-9]{2})#", $attributes["searchDate"], $result)) { $attributes["searchDateForMobile"] = $attributes["searchDate"]; $attributes["searchDate"] = $result[3] . "." . $result[2] . "." . $result[1]; } else if (preg_match("#([0-9]{2})\.([0-9]{2})\.([0-9]{4})#", $_SESSION["lastSearchDate"], $result)) { $attributes["searchDateForMobile"] = $result[3] . "-" . $result[2] . "-" . $result[1]; } $attributes["searchCity"] = Encoding::toUTF8(urldecode($attributes["searchCity"])); $attributes["searchLocation"] = Encoding::toUTF8(urldecode($attributes["searchLocation"])); $searchCity = $attributes["searchCity"]; $searchLocation = $attributes["searchLocation"]; $searchLocationID = ""; if (preg_match("#^(.+)-([0-9]+)$#", $searchLocation, $result)) { $searchLocation = $result[1]; $searchLocationID = $result[2]; $searchDate = $attributes["searchDate"]; //`name` LIKE '".$searchLocation."' AND // http://lovespotter.de/#search/D%FCsseldorf/D%FCsseldorf%20Hauptbahnhof-16 $location = dbobject::getOne("Location", "WHERE `id` = ".$searchLocationID); } if (issetAndNotEmpty($location)) { $_SESSION["lastSearchLocation"] = serialize($location); $_SESSION["lastSearchDate"] = $searchDate; $attributes["searchURL"] = ("#search/".urlencode($searchCity).(issetAndNotEmpty($searchLocation) ? "/".urlencode($searchLocation) : "").(issetAndNotEmpty($searchDate) ? "/".urlencode($searchDate) : ""))."-".$location->id; $attributes["location"] = $location; $attributes["matchedRequests"] = fetchMatchedRequests($location, $searchDate); show("index_overview.tpl", $attributes); exit(); } else if (issetAndNotEmpty($searchCity)) { $tmpLocation = new Location(); $tmpLocation->city = $searchCity; $_SESSION["lastSearchLocation"] = serialize($location); $_SESSION["lastSearchDate"] = $searchDate; $attributes["location"] = $tmpLocation; $attributes["matchedRequests"] = fetchMatchedRequestsForCity($searchCity); show("index_overview.tpl", $attributes); exit(); } else { exitWithToken("false:invalidLocation"); } case "newReport": if (!issetAndNotEmpty($attributes["uniqueId"])) { exitWithToken("false"); } $request = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$attributes["uniqueId"]."'"); if ($request == null) { exitWithToken("false"); } $attributes["request"] = $request; show("index_newReport.tpl", $attributes); exit(); case "chooseNew": show("index_chooseNew.tpl", $attributes); exit(); case "newLocation": show("index_newLocation.tpl", $attributes); exit(); case "newSpott": if (issetAndNotEmpty($attributes["locationId"])) { $location = dbobject::getById("Location", $attributes["locationId"]); if (issetAndNotEmpty($location)) { $attributes["location"] = $location; } } show("index_newLoveSpott.tpl", $attributes); exit(); case "newRequest": if (issetAndNotEmpty($attributes["locationId"])) { $location = dbobject::getById("Location", $attributes["locationId"]); if (issetAndNotEmpty($location)) { $attributes["location"] = $location; } } if (issetAndNotEmpty($attributes["searchDate"])){ if (preg_match("#([0-9]{2})\.([0-9]{2})\.([0-9]{4})#", $attributes["searchDate"], $result)) { $attributes["searchDateForMobile"] = $result[3] . "-" . $result[2] . "-" . $result[1]; } } $attributes["isEditRequestFlirt"] = false; show("index_newOrEditRequest.tpl", $attributes); exit(); case "newFlirt": if (issetAndNotEmpty($attributes["locationId"])) { $location = dbobject::getById("Location", $attributes["locationId"]); if (issetAndNotEmpty($location)) { $attributes["location"] = $location; } } $attributes["isEditRequestFlirt"] = false; $attributes["isFlirt"] = true; show("index_newOrEditRequest.tpl", $attributes); exit(); case "showRequest": if (!issetAndNotEmpty($attributes["uniqueId"])) { exitWithToken("false"); } $request = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$attributes["uniqueId"]."'"); if ($request == null) { exitWithToken("false"); } $location = dbobject::getById("Location", $request->idLocation); $attributes["request"] = $request; $attributes["location"] = $location; show("index_requestDetails.tpl", $attributes); exit(); case "editRequest": if (!issetAndNotEmpty($attributes["uniqueId"])) { exitWithToken("false"); } $request = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$attributes["uniqueId"]."'"); if ($request == null) { exitWithToken("false"); } $location = dbobject::getById("Location", $request->idLocation); if (issetAndNotEmpty($attributes["securityCode"]) && strcmp($request->securityCode,$attributes["securityCode"]) == 0 ) { $attributes["isEditRequestFlirt"] = true; $attributes["editRequestFlirt"] = $request; $attributes["location"] = $location; show("index_newOrEditRequest.tpl", $attributes); exit(); } show("index_editRequestWithoutLink.tpl", $attributes); exit(); case "requestConfirmLoveSpott": if (issetAndNotEmpty($attributes["locationId"])) { $location = dbobject::getById("Location", $attributes["locationId"]); if (issetAndNotEmpty($location)) { $attributes["location"] = $location; $qrObjectId = getQRCodeLocation(QRCODE_SIZE_BIG, $location, "loveSpott", false); $attributes["qrCodeLink"] = "?do=getQR&id=" . $qrObjectId; show("index_newLoveSpottConfirm.tpl", $attributes); exit(); } } exit("false"); case "requestConfirmDelete": show("index_deleteRequestConfirm.tpl", $attributes); exit(); case "requestConfirm": show("index_newRequestConfirm.tpl", $attributes); exit(); case "requestConfirmChanged": $attributes["isEdit"] = true; show("index _newRequestConfirm.tpl", $attributes); exit(); case "requestConfirmCodeSent": show("index_confirmCodeSent.tpl", $attributes); exit(); case "newMailConfirm": show("index_newMailConfirm.tpl", $attributes); exit(); case "newReportConfirm": show("index_newReportConfirm.tpl", $attributes); exit(); case "newMail": if (!issetAndNotEmpty($attributes["uniqueId"])) { exitWithToken("false"); } $request = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$attributes["uniqueId"]."'"); if ($request == null) { exitWithToken("false"); } $attributes["receiverRequest"] = $request; show("index_newMail.tpl", $attributes); exit(); case "confirmRequest": if (!issetAndNotEmpty($attributes["uniqueId"])) { exit("false"); } $request = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$attributes["uniqueId"]."'"); if ($request == null) { exit("false"); } if (strcmp($attributes["isFlirt"], "true") == 0) { $lastFlirtSearch = new LastFlirtSearch(); $lastFlirtSearch->searchFlirtCity = $request->where; $lastFlirtSearch->searchFlirtLat = $request->whereLat; $lastFlirtSearch->searchFlirtLong = $request->whereLong; $lastFlirtSearch->searchFlirtRadius = "10"; $lastFlirtSearch->searchFlirtSearchGender = $request->gender; $lastFlirtSearch->searchFlirtOwnGender = $request->searchGender; $_SESSION["lastSearchFlirt"] = serialize($lastFlirtSearch); if (strcmp($attributes["isLocationLoveSpott"], "true") == 0) { $location = $request->toLocation(); if ($location != null) { $lastSearch->searchLocationId = $location->id; $lastSearch->searchLocationName = $location->name; $lastSearch->searchCity = $location->city; $lastSearch->searchLat = $location->fqLat; $lastSearch->searchLong = $location->fqLong; } } $_SESSION["lastSearchLoveSpott"] = serialize($lastSearch); } else if (strcmp($attributes["isLoveSpott"], "true") == 0) { $lastSearch = new LastLoveSpottSearch(); $lastSearch->searchCity = $request->where; $lastSearch->searchLat = $request->whereLat; $lastSearch->searchLong = $request->whereLong; $lastSearch->searchRadius = 10; if (strcmp($attributes["isLocationLoveSpott"], "true") == 0) { $location = $request->toLocation(); if ($location != null) { $lastSearch->searchLocationId = $location->id; $lastSearch->searchLocationName = $location->name; $lastSearch->searchCity = $location->city; $lastSearch->searchLat = $location->fqLat; $lastSearch->searchLong = $location->fqLong; } } $_SESSION["lastSearchLoveSpott"] = serialize($lastSearch); } else { $_SESSION["lastSearchLocation"] = serialize($request->toLocation()); $_SESSION["lastSearchDate"] = date("d.m.Y", $request->when); } // if ($request->confirmed == 1) { // exit("false:alreadyConfirmed"); // } $request->confirmed = 1; $request->needPostToFB = 1; $request->update(); $attributes["request"] = $request; show("index_newRequestActivated.tpl", $attributes); exit(); } } if (issetAndNotEmpty($_GET["do"]) && strcmp($_GET["do"], "test") == 0) { $curlhandle = curl_init(); curl_setopt($curlhandle, CURLOPT_URL, "https://api.foursquare.com/v2/venues/4ba792bcf964a5209d9e39e3?client_id=1DQFLEYVBERFE5EAAIRC3Z33TOSSEXHGWIK33N0QHUTASUOF&client_secret=LULW1KAOT43EK0N4X4BQSK0EMXL3ECZ00HLO34LPCUWMRWZ3&v=20130301"); curl_setopt($curlhandle, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($curlhandle); curl_close($curlhandle); $json = json_decode($response); $fqLocName = $json->response->venue->name; $fqLocAddress = $json->response->venue->location->address; $fqLocCity = $json->response->venue->location->city; $fqLocLat = str_replace(",", ".", $json->response->venue->location->lat); $fqLocLong = str_replace(",", ".",$json->response->venue->location->lng); $image = ""; $maxSize = 0; foreach ($json->response->venue->photos->groups as $group) { foreach ($group->items as $item) { $size = ($item->height + $item->width); if ($item->visibility == "public" && $size > $maxSize) { $image = $item->prefix . "800x800" . $item->suffix; } //echo $item->prefix . "" . $item->suffix . " H: " .$item->height . " W: " . $item->width . " Size: ".$size."
"; } } echo "Image: $image"; exit(); // photos->groups->items-> "prefix":"https:\/\/irs1.4sqi.net\/img\/general\/", "suffix":"\/7233379_Hh5KnG5-yRfKOw1KdOtYrOWWyQE2XHnUiCbaZrqrAd0.jpg", "width":540, "height":540, } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "getLocationIdForFQLocation") == 0) { $fqLocationID = stripAll($_POST["fqId"]); if (issetAndNotEmpty($fqLocationID)) { $location = getOrCreateLocationFromFQId($fqLocationID); if ($location != null) { exitWithToken("true:".$location->city . "/" . $location->name . "-" . $location->id); } } exitWithToken("false"); } function getOrCreateLocationFromFQId($fqId) { if (issetAndNotEmpty($fqId)) { $existingLocation = dbobject::getOne("Location", "WHERE `fqId` LIKE '".$fqId."'"); if ($existingLocation == null) { $curlhandle = curl_init(); //$url = "https://api.foursquare.com/v2/venues/" . $fqId . "?client_id=" . FQ_CLIENT_ID . "&client_secret=" . FQ_CLIENT_SECRET . "&v=".date("Ymd"); curl_setopt($curlhandle, CURLOPT_URL, "https://api.foursquare.com/v2/venues/" . $fqId . "?client_id=" . FQ_CLIENT_ID . "&client_secret=" . FQ_CLIENT_SECRET . "&v=".date("Ymd")); curl_setopt($curlhandle, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($curlhandle); curl_close($curlhandle); $json = json_decode($response); $fqLocName = $json->response->venue->name; $fqLocAddress = $json->response->venue->location->address; $fqLocCity = $json->response->venue->location->city; $fqLocLat = str_replace(",", ".", $json->response->venue->location->lat); $fqLocLong = str_replace(",", ".",$json->response->venue->location->lng); $fqImage = ""; $maxSize = 0; foreach ($json->response->venue->photos->groups as $group) { foreach ($group->items as $item) { $size = ($item->height + $item->width); if ($item->visibility == "public" && $size > $maxSize) { $fqImage = $item->prefix . "800x800" . $item->suffix; } //echo $item->prefix . "" . $item->suffix . " H: " .$item->height . " W: " . $item->width . " Size: ".$size."
"; } } $newLocation = new Location(); $newLocation->name = $fqLocName; $newLocation->address = $fqLocAddress; $newLocation->image = ""; $newLocation->fqImage = $fqImage; $newLocation->city = $fqLocCity; $newLocation->fqId = $fqId; $newLocation->fqLat = $fqLocLat; $newLocation->fqLong = $fqLocLong; $result = $newLocation->insertToDB(); if ($result != null) { return $newLocation; } } else { return $existingLocation; } } return null; } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "doNewEditLocation") == 0) { $locationId = stripAll($_POST["locationId"]); $isEdit = preg_match("#([0-9]+)#", $locationId); if (issetAndNotEmpty($locationId) && !$isEdit) { exitWithToken("false"); } if ($isEdit) { $newLocation = dbobject::getById("Location", $locationId); } else { $newLocation = new Location(); } $newLocation->name = stripAll($_POST["name"]); $newLocation->address = stripAll($_POST["address"]); $newLocation->city = stripAll($_POST["city"]); $newLocation->zipCode = stripAll($_POST["zipCode"]); $newLocation->fqLat = stripAll($_POST["lat"]); $newLocation->fqLong = stripAll($_POST["long"]); $newLocation->image = stripAll($_POST["image"]); if (!issetAndNotEmpty($newLocation->name)) { exitWithToken("false:requiredFields"); } // if (!issetAndNotEmpty($newLocation->address)) { exitWithToken("false:requiredFields"); } if (!issetAndNotEmpty($newLocation->city)) { exitWithToken("false:requiredFields"); } if (!issetAndNotEmpty($newLocation->fqLat)) { exitWithToken("false:requiredFields"); } if (!issetAndNotEmpty($newLocation->fqLong)) { exitWithToken("false:requiredFields"); } if ($isEdit) { $result = $newLocation->update(); // if ($isNewMailAddress && $result != null) { // $smarty->assign('request', $newRequest); // $mail = new QRMail(); // $mail->subject = "LoveSpotter - Gesuch aktivieren"; // $mail->content = $smarty->fetch('mail_message_confirmEditedRequest.tpl'); // $mail->receiverName = $newRequest->name; // $mail->receiverEmail = $newRequest->email; // $mail->senderName = "LoveSpotter"; // $mail->senderEmail = "do.not.reply@lovespotter.de"; // $result = $mail->sendMail(); // // if ($result) { // exitWithToken("true:newMail"); // } // } } else { $result = $newLocation->insertToDB(); // if ($result != null) { // $smarty->assign('request', $newRequest); // $mail = new QRMail(); // $mail->subject = "LoveSpotter - Gesuch aktivieren"; // $mail->content = $smarty->fetch('mail_message_newRequest.tpl'); // $mail->receiverName = $newRequest->name; // $mail->receiverEmail = $newRequest->email; // $mail->senderName = "LoveSpotter"; // $mail->senderEmail = "do.not.reply@lovespotter.de"; // $result = $mail->sendMail(); // if ($result) { // exitWithToken("true"); // } // } } if (issetAndNotEmpty($result)) { exitWithToken("true:" . $newLocation->id); } exitWithToken("false"); } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "doNewEditRequestFlirt") == 0) { list ($gender, $searchGender) = explode(";", stripAll($_POST["gender"])); $requestID = stripAll($_POST["requestId"]); $isEdit = preg_match("#([0-9a-zA-Z]+\.[0-9a-zA-Z]+)#", $requestID); $isFlirt = (strcmp(stripAll($_POST["isFlirt"]), "true") == 0 ? true : false); $isLoveSpott = (strcmp(stripAll($_POST["isLoveSpott"]), "true") == 0 ? true : false); if (issetAndNotEmpty($requestID) && !$isEdit) { exitWithToken("false"); } if ($isEdit) { $newRequest = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$requestID."'"); } else { $newRequest = new Request(); $newRequest->created = time(); $newRequest->uniqueId = UUID(); $newRequest->securityCode = createRandomPassword(); $newRequest->requestType = ($isFlirt ? Request::$typeFlirt : Request::$typeRequest); } $isNewMailAddress = (strcmp($newRequest->email, stripAll($_POST["email"])) != 0); $newRequest->gender = $gender; $newRequest->searchGender = $searchGender; $newRequest->text = base64_encode($_POST["message"]); $newRequest->name = stripAll($_POST["name"]); $newRequest->email = stripAll($_POST["email"]); $newRequest->searchType = stripAll($_POST["searchType"]); $newRequest->image = stripAll($_POST["image"]); $newRequest->imageThumbnailURL = stripAll($_POST["imageThumbnailURL"]); $newRequest->imagePreviewURL = stripAll($_POST["imagePreviewURL"]); $newRequest->age = stripAll($_POST["age"]); $newRequest->where = stripAll($_POST["location"]); $newRequest->when = strtotime(stripAll($_POST["when"])); if (!$isEdit) { $newRequest->postOnUserFB = (strcmp(stripAll($_POST["postOnUserFB"]), "1") == 0 ? 1 : 0); $newRequest->needPostToFB = 0; } // postValues["location"] = searchLocation; // postValues["locationCity"] = searchLocationCity; // postValues["locationId"] = searchLocationID; // postValues["fqLocationId"] = searchFQID; // if (!$isEdit) { $locationId = stripAll($_POST["locationId"]); $fqLocationId = stripAll($_POST["fqLocationId"]); if (issetAndNotempty($locationId)) { $location = dbobject::getById("Location", $locationId); if ($location != null) { $newRequest->idLocation = $location->id; } } else if (issetAndNotempty($fqLocationId)) { //TODO CREATE NEW location from fq id! $location = getOrCreateLocationFromFQId($fqLocationId); //echo "Location for fqid: $fqLocationId : $location"; if ($location != null) { $newRequest->idLocation = $location->id; } } if ($isFlirt) { $newRequest->whereLat = stripAll($_POST["fqLocationLat"]); $newRequest->whereLong = stripAll($_POST["fqLocationLong"]); $newRequest->where = stripAll($_POST["locationCity"]); } else { if (!issetAndNotEmpty($location)) { exitWithToken("false:requiredFields"); } } // } if (!issetAndNotEmpty($newRequest->text)) { exitWithToken("false:requiredFields"); } if (!issetAndNotEmpty($newRequest->name)) { exitWithToken("false:requiredFields"); } if (!issetAndNotEmpty($newRequest->email)) { exitWithToken("false:requiredFields"); } if (!issetAndNotEmpty($newRequest->searchType)) { exitWithToken("false:requiredFields"); } //if (!issetAndNotEmpty($newRequest->image)) { exitWithToken("false:requiredFields"); } // if (!issetAndNotEmpty($newRequest->where)) { exitWithToken("false:requiredFields"); } if ($isFlirt && (!issetAndNotEmpty($newRequest->whereLat) || !issetAndNotEmpty($newRequest->whereLong))) { exitWithToken("false:requiredFields"); } if (!$isFlirt && !issetAndNotEmpty($newRequest->idLocation)) { exitWithToken("false:requiredFields"); } if (!$isFlirt && !issetAndNotEmpty($newRequest->when)) { exitWithToken("false:requiredFields"); } if (!issetAndNotEmpty($newRequest->gender)) { exitWithToken("false:requiredFields"); } if (!issetAndNotEmpty($newRequest->searchGender)) { exitWithToken("false:requiredFields"); } if (!issetAndNotEmpty($_SESSION["lastSearchLocation"])) { $_SESSION["lastSearchLocation"] = serialize($location); $_SESSION["lastSearchDate"] = $request->date; } if ($isEdit) { if ($isNewMailAddress) { $newRequest->confirmed = 0; //$newRequest->securityCode = createRandomPassword(); } $result = $newRequest->update(); if ($isNewMailAddress && $result != null) { $smarty->assign('request', $newRequest); $smarty->assign('baseURL', $baseURL); $smarty->assign('isFlirt', $isFlirt); $smarty->assign('isLoveSpott', $isLoveSpott); $mail = new QRMail(); $mail->subject = "LoveSpotter - ".($isFlirt ? "Kontaktanzeige" : "Gesuch")." aktivieren"; $mail->content = $smarty->fetch('mail_message_confirmEditedRequest.tpl'); $mail->receiverName = $newRequest->name; $mail->receiverEmail = $newRequest->email; $mail->senderName = "LoveSpotter"; $mail->senderEmail = "do.not.reply@lovespotter.de"; $result = $mail->sendMail(); if ($result) { exitWithToken("true:newMail"); } } } else { $newRequest->confirmed = 0; $newRequest->idLocation = $location->id; $_SESSION["lastSearchLocation"] = serialize($location); $result = $newRequest->insertToDB(); if ($result != null) { $loveSession = dbobject::getOne("LoveSession", "WHERE `email` LIKE '".$newRequest->email."'"); if (!issetAndNotEmpty($loveSession)) { $loveSession = new LoveSession(); $loveSession->email = $newRequest->email; $loveSession->uniqueId = hash("sha256", uniqid() . uniqid() . mt_rand()); $loveSession->insertToDB(); } $smarty->assign('request', $newRequest); $smarty->assign('baseURL', $baseURL); $smarty->assign('loveSession', $loveSession); $smarty->assign('isFlirt', $isFlirt); $smarty->assign('isLoveSpott', $isLoveSpott); $mail = new QRMail(); $mail->subject = "LoveSpotter - ".($isFlirt ? "Kontaktanzeige" : "Gesuch")." aktivieren"; $mail->content = $smarty->fetch('mail_message_newRequest.tpl'); $mail->receiverName = $newRequest->name; $mail->receiverEmail = $newRequest->email; $mail->senderName = "LoveSpotter"; $mail->senderEmail = "do.not.reply@lovespotter.de"; $result = $mail->sendMail(); if ($result) { exitWithToken("true"); } } } if (issetAndNotEmpty($result)) { exitWithToken("true"); } exitWithToken("false"); } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "doNewMail") == 0) { list ($gender, $searchGender) = explode(";", stripAll($_POST["gender"])); $email = stripAll($_POST["email"]); $message = stripAllWitHTMLAllowed(nl2br($_POST["message"])); $name = stripAll($_POST["name"]); $receiverId = stripAll($_POST["receiverId"]); if (!issetAndNotEmpty($email) || !issetAndNotEmpty($message) || !issetAndNotEmpty($name)) { exitWithToken("false:requiredFields"); } $request = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$receiverId."'"); if ($request != null) { $mailReceiver = MailReceiver::createOrGetByEmail($request->name, $request->email, $request->id); $mailSender = MailReceiver::createOrGetByEmail($name, $email, $request->id); if ($mailSender == null) { exitWithToken("false:invalidSender"); } if ($mailReceiver == null) { exitWithToken("false:invalidReceiver"); } $smarty->assign('message', nl2br($message)); $smarty->assign('name', $name); $smarty->assign('mailReceiver', $mailReceiver); $smarty->assign('mailSender', $mailSender); $smarty->assign('request', $request); $smarty->assign('baseURL', $baseURL); $smarty->assign('request', $request); $mail = new QRMail(); $mail->subject = "LoveSpotter - Kontaktanfrage"; $mail->content = $smarty->fetch('mail_message_answer.tpl'); $mail->receiverName = $request->name; $mail->receiverEmail = $request->email; // $mail->senderName = $name; // $mail->senderEmail = $email; $mail->senderName = "LoveSpotter"; $mail->senderEmail = "do.not.reply@lovespotter.de"; $result = $mail->sendMail(); if ($result) { exitWithToken("true"); } } exitWithToken("false"); } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "doNewReport") == 0) { $email = stripAll($_POST["email"]); $message = stripAllWitHTMLAllowed(nl2br($_POST["message"])); $name = stripAll($_POST["name"]); $requestId = stripAll($_POST["requestId"]); $isFlirt = (strcmp(stripAll($_POST["isFlirt"]), "true") == 0 ? true : false); if (!issetAndNotEmpty($email) || !issetAndNotEmpty($message) || !issetAndNotEmpty($name)) { exitWithToken("false:requiredFields"); } $smarty->assign('email', $email); $smarty->assign('message', nl2br($message)); $smarty->assign('name', $name); $smarty->assign('baseURL', $baseURL); $request = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$requestId."'"); if ($request != null) { $smarty->assign('request', $request); $smarty->assign('isFlirt', $isFlirt); $mail = new QRMail(); $mail->subject = "LoveSpotter - Meldung"; $mail->content = $smarty->fetch('mail_message_report.tpl'); $mail->receiverName = "Administrator"; $mail->receiverEmail = "info@lovespotter.de"; $mail->senderName = "LoveSpotter"; $mail->senderEmail = "do.not.reply@lovespotter.de"; $result = $mail->sendMail(); if ($result) { exitWithToken("true"); } } exitWithToken("false"); } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "getEditRequest") == 0) { $securityCode = stripAll($_POST["securityCode"]); $requestId = stripAll($_POST["requestId"]); if (!issetAndNotEmpty($requestId) || !issetAndNotEmpty($securityCode)) { exitWithToken("false:invalidCode"); } $request = dbobject::getOne("Request", "WHERE `uniqueId` LIKE '".$requestId."'"); if ($request == null) { exitWithToken("false"); } if (strcmp($request->securityCode, $securityCode) == 0) { exitWithToken("true"); } exitWithToken("false:invalidCode"); } if (issetAndNotEmpty($_POST["do"]) && strcmp($_POST["do"], "doSendSecurityCode") == 0) { $email = stripAll($_POST["email"]); $uniqueId = stripAll($_POST["uniqueId"]); if (!issetAndNotEmpty($uniqueId) || !issetAndNotEmpty($uniqueId)) { exitWithToken("false"); } $requests = dbobject::getAll("Request", "WHERE `email` LIKE '".$email."'"); if ($requests == null && count($requests) == 0) { exitWithToken("false"); } reset($requests); $firstRequest = current($requests); $smarty->assign('requests', $requests); $smarty->assign('baseURL', $baseURL); $mail = new QRMail(); $mail->subject = "LoveSpotter - Code-Erinnerung"; $mail->content = $smarty->fetch('mail_message_securityCode.tpl'); $mail->receiverName = $firstRequest->name; $mail->receiverEmail = $firstRequest->email; $mail->senderName = "LoveSpotter"; $mail->senderEmail = "do.not.reply@lovespotter.de"; $result = $mail->sendMail(); if ($result) { exitWithToken("true"); } exitWithToken("false"); } $showTemplate = "index.tpl"; show($showTemplate, $attributes); function show($showTemplate, $attributes = array()) { global $smarty, $showError, $isFlirtPage, $isLoveSpott; $smarty->assign('showError', ($showError ? 'true' : 'false')); $smarty->assign('baseURL', $baseURL); $detect = new Mobile_Detect(); $smarty->assign('isMobile', $detect->isMobile()); $smarty->assign('isFlirtPage', $isFlirtPage); $smarty->assign('isLoveSpott', $isLoveSpott); foreach ($attributes as $attrName => $attrValue) { $smarty->assign($attrName, $attrValue); } $smarty->display($showTemplate); } function fetchMatchedRequests($location, $date) { $sqlDate = issetAndNotEmpty($date) ? " AND `when` LIKE '".strtotime($date)."'" : ""; $requests = dbobject::getAll("Request", "WHERE `idLocation` = ".$location->id . $sqlDate . " AND `confirmed` = 1 AND `requestType` LIKE '".Request::$typeRequest."'"); return $requests; } function fetchMatchedRequestsForCity($city) { $requests = dbobject::getAll("Request", " wHERE `idLocation` in (select `id` from `Location` where `city` like '%".$city."%') AND `confirmed` = 1 AND `requestType` LIKE '".Request::$typeRequest."'"); return $requests; } function fetchMatchedFlirtRequests($city, $lat, $long, $radius, $ownGender, $searchGender) { //TODO: Umkreis! $genderMatch = " AND `gender` LIKE '".$searchGender."' AND `searchGender` LIKE '".$ownGender."'"; if (issetAndNotEmpty($lat) && issetAndNotEmpty($long) && issetAndNotEmpty($radius)) { $fullSQL = "SELECT *, ACOS( SIN(RADIANS(".$lat.")) * SIN(RADIANS(`whereLat`)) + COS(RADIANS(".$lat.")) * COS(RADIANS(`whereLat`)) * COS(RADIANS(".$long.") - RADIANS(`whereLong`)) ) * 6380 AS distance FROM `Request` WHERE `whereLat` IS NOT NULL AND `whereLong` IS NOT NULL AND `confirmed` = 1 AND `requestType` LIKE '".Request::$typeFlirt."' ". $genderMatch ." HAVING distance < ".$radius." ORDER BY distance"; //echo "SQL: $fullSQL"; $requests = dbobject::getAll("Request", $fullSQL, true); } else { $requests = dbobject::getAll("Request", "WHERE `where` LIKE '". $city . "' AND `confirmed` = 1 AND `requestType` LIKE '".Request::$typeFlirt."'" . $genderMatch); } return $requests; } function fetchMatchedLoveSpottRequests($city, $lat, $long, $radius) { if (issetAndNotEmpty($lat) && issetAndNotEmpty($long) && issetAndNotEmpty($radius)) { $fullSQL = "SELECT `Request`.*, `Location`.`fqLat`, `Location`.`fqLong`, ACOS( SIN(RADIANS(".$lat.")) * SIN(RADIANS(`whereLat`)) + COS(RADIANS(".$lat.")) * COS(RADIANS(`whereLat`)) * COS(RADIANS(".$long.") - RADIANS(`whereLong`)) ) * 6380 AS distance, ACOS( SIN(RADIANS(".$lat.")) * SIN(RADIANS(`fqLat`)) + COS(RADIANS(".$lat.")) * COS(RADIANS(`fqLat`)) * COS(RADIANS(".$long.") - RADIANS(`fqLong`)) ) * 6380 AS distanceLoc FROM `Request` LEFT JOIN `Location` ON (`Location`.`id` = `Request`.idLocation) WHERE ((`whereLat` IS NOT NULL AND `whereLong` IS NOT NULL) OR (`fqLat` IS NOT NULL AND `fqLong` IS NOT NULL)) AND `confirmed` = 1 HAVING distance < ".$radius." OR distanceLoc < ".$radius." ORDER BY distance, distanceLoc, created;"; $requests = dbobject::getAll("Request", $fullSQL, true); } else { $requests = dbobject::getAll("Request", "WHERE `where` LIKE '". $city . "' AND `confirmed` = 1"); } return $requests; } function fetchMatchedLocationsByGeometry($lat, $long, $radius = 10, $name = null) { if (issetAndNotEmpty($lat) && issetAndNotEmpty($long) && issetAndNotEmpty($radius)) { $fullSQL = "SELECT *, ACOS( SIN(RADIANS(".$lat.")) * SIN(RADIANS(`fqLat`)) + COS(RADIANS(".$lat.")) * COS(RADIANS(`fqLat`)) * COS(RADIANS(".$long.") - RADIANS(`fqLong`)) ) * 6380 AS distance FROM `Location` WHERE `fqLat` IS NOT NULL AND `fqLong` IS NOT NULL ".(issetAndNotEmpty($name) ? "AND `name` LIKE '%".$name."%'" : "")." HAVING distance < ".$radius." ORDER BY distance;"; return dbobject::getAll("Location", $fullSQL, true); } return array(); } function parseAttr($attributes) { $attrString = stripAll($_GET["attr"]); $attrList = explode(";", $attrString); foreach ($attrList as $attr) { list ($attrName, $attrValue) = explode(":", $attr); /* switch ($attrName) { case "uniqueId": $attrName = "uniqueId"; $attrValue = $attrValue; break; } */ $attributes[stripAll($attrName)] = $attrValue; } return $attributes; } /* QR Codes */ function getQRCodeLocation($qrSize, $location, $type, $show = false) { global $mobileLink; $realQRSize = $qrSize - 45; $logoSizePercent = 40; $originalLogoSizeX = 361; $originalLogoSizeY = 361; //$qrSizeRaster = (($qrSize == QRCODE_SIZE_SMALL) ? 9.6 : 19.2); $qrCode = ""; $locationLabel = $location->name . " (".$location->address.", " .(issetAndNotEmpty($location->zipCode) ? $location->zipCode." " : "") . $location->city.")"; switch ($type) { case "loveSpott": $qrCode = "#loveSpott/" . urlencode($location->city) . "/" . urlencode($location->name) . "-" . $location->id; $description = "LoveSpott für Deine Location: " . $locationLabel; break; case "flirt": $qrCode = "#searchFlirt/" . urlencode($location->city) . "/" . urlencode($location->name) . "." - $location->id; $description = "Flirt-Suche für Deine Location: " . $locationLabel; break; default: $qrCode = "#search/" . $location->city . "/" . $location->name . "." - $location->id; $description = "Suche für Deine Location: " . $locationLabel; } $qrCodeLink = "http://".$location->id.".LoveSpotter.de";// . "/" . $qrCode; $image = QRcode::png($qrCodeLink, false, QR_ECLEVEL_Q, 15.0, 0, false, true); $logo = imagecreatefrompng('img/logo-loveSpott_qr.png'); $new = imagecreatetruecolor($qrSize, $qrSize); $bgColor = ImageColorAllocate($new, 255, 255, 255); imagefill($new, 0, 0, $bgColor); imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); imagealphablending($new, true); imagesavealpha($new, true); $logoSize = ($realQRSize * $logoSizePercent / 100); // echo "QRSize: $qrSize LogoSize: " . $logoSize . " REal Logo X: " . imagesx($logo) . " Y: " . imagesy($logo); $logoPositionMiddle = ($realQRSize / 2) - ($logoSize / 2); imagecopyresampled($new, $image, 20, 20, 0, 0, $realQRSize, $realQRSize, imagesx($image), imagesx($image)); imagecopyresampled($new, $logo, 20 + $logoPositionMiddle, 20 + $logoPositionMiddle, 0, 0, $logoSize, $logoSize, $originalLogoSizeX, $originalLogoSizeY); $black = ImageColorAllocate($new, 0, 0, 0); ImageTTFText($new, 15, 0, 10, $qrSize - 5, $black, "./Arial.ttf", $description); $qrCodeID = sha1(uniqid() . uniqid() . mt_rand()); $qrCodeFile = "qr/".$qrCodeID.".png"; if ($show) { header('Content-Type: image/png'); imagepng($new); } else { imagepng($new, $qrCodeFile); return $qrCodeID; } } ?>