private function generateDescriptors($mediaId, $gameId) { //Get the filename for the media if ($mediaId) { $query = "SELECT file_path FROM media WHERE media_id = '{$mediaId}' LIMIT 1"; $result = Module::query($query); $fileName = mysql_fetch_object($result)->file_path; $gameMediaAndDescriptorsPath = Media::getMediaDirectory($gameId)->data; $execCommand = '../../ImageMatcher/ImageMatcher generate ' . $gameMediaAndDescriptorsPath . $fileName; $console = exec($execCommand); } }
<p>file: <input type="file" name="file" size="30"></p> <p><input type="submit" value="Upload"></p> <body></html>'; if (!$_FILES['file']) { die($form); } $media = new Media(); //Check for Errors if ($_FILES['file']['error']) { die("file upload error"); } if (isset($_POST['gameID'])) { $_POST['path'] = $_POST['gameID']; } // for legacy use. - Phil 10/12/2012 $gameMediaDirectory = $media->getMediaDirectory($_POST['path'])->data; $pathInfo = ''; if (@$_REQUEST['fileName']) { $pathInfo = pathinfo($_REQUEST['fileName']); } else { $pathInfo = pathinfo($_FILES['file']['name']); } //We are coming from the form $newMediaFileName = 'aris' . md5(date("YmdGisu") . substr((string) microtime(), 2, 6) . strtolower($_FILES['file']['name'])) . '.' . strtolower($pathInfo['extension']); if ($pathInfo['extension'] == '') { $newMediaFileName = $newMediaFileName . 'jpg'; } // blobs from YOI map in jpg form aren't coming through with file a extension. This is a band-aid. $newMediaFilePath = $gameMediaDirectory . "/" . $newMediaFileName; if (!move_uploaded_file($_FILES['file']['tmp_name'], $newMediaFilePath)) { die("error moving file");
public function getBestImageMatchNearbyObjectForPlayer($gameId, $intPlayerId, $strFileName) { $gameMediaAndDescriptorsPath = Media::getMediaDirectory($gameId)->data; $execCommand = '../../ImageMatcher/ImageMatcher match ' . $gameMediaAndDescriptorsPath . $strFileName . ' ' . $gameMediaAndDescriptorsPath; $console = exec($execCommand); //Run it $consoleJSON = json_decode($console, true); $fileName = $consoleJSON['filename']; $pathParts = pathinfo($fileName); $fileName = $pathParts['filename']; // requires PHP 5.2.0 $similarity = $consoleJSON['similarity']; if ($similarity > 0.2) { return new returnData(0, NULL, "No match found. Best simularity was {$similarity}"); } $query = "SELECT game_qrcodes.* \n FROM (SELECT * FROM qrcodes WHERE game_id = {$gameId}) AS game_qrcodes \n JOIN media \n ON (game_qrcodes.match_media_id = media.media_id)\n WHERE media.file_path = '{$fileName}.jpg'\n OR media.file_path = '{$fileName}.png'\n LIMIT 1"; $rsResult = Module::query($query); if (mysql_error()) { return new returnData(3, NULL, "SQL Error: " . mysql_error()); } $qrcode = @mysql_fetch_object($rsResult); //Check for a valid QR Code if (!$qrcode) { Module::appendLog($intPlayerId, $gameId, Module::kLOG_ENTER_QRCODE, $fileName, 'INVALID'); return new returnData(0, NULL, "invalid QRCode code"); } //Check the requirements of the QR Code's link object if (!$this->objectMeetsRequirements($gameId, $intPlayerId, $qrcode->link_type, $qrcode->link_id)) { Module::appendLog($intPlayerId, $gameId, Module::kLOG_ENTER_QRCODE, $fileName, 'REQS_OR_QTY_NOT_MET'); return new returnData(0, NULL, "QRCode requirements not met"); } Module::appendLog($intPlayerId, $gameId, Module::kLOG_ENTER_QRCODE, $fileName, 'SUCCESSFUL'); $returnResult = new returnData(0, $qrcode); //Get the data switch ($qrcode->link_type) { case 'Location': $returnResult->data->object = Locations::getLocation($gameId, $qrcode->link_id)->data; if (!$returnResult->data->object) { return new returnData(5, NULL, "bad link in qr code, no matching location found"); } break; default: return new returnData(5, NULL, "Invalid QR Code Record. link_type not recognized"); } return $returnResult; //Delete the file since we will never use it again //unlink($strFileName); }
public function createMediaFromJSON($glob) { $path = $glob->path; $filename = $glob->filename; $data = $glob->data; $resizeTo = isset($glob->resizeTo) ? $glob->resizeTo : null; $gameMediaDirectory = Media::getMediaDirectory($path)->data; $md5 = md5((string) microtime() . $filename); $ext = strtolower(substr($filename, -3)); $newMediaFileName = 'aris' . $md5 . '.' . $ext; $resizedMediaFileName = 'aris' . $md5 . '_128.' . $ext; if ($ext != "jpg" && $ext != "png" && $ext != "gif" && $ext != "mp4" && $ext != "mov" && $ext != "m4v" && $ext != "3gp" && $ext != "caf" && $ext != "mp3" && $ext != "aac" && $ext != "m4a" && $ext != "zip") { return new returnData(1, NULL, "Invalid filetype:{$ext}"); } $fullFilePath = $gameMediaDirectory . "/" . $newMediaFileName; if (isset($resizeTo) && ($ext == "jpg" || $ext == "png" || $ext == "gif")) { $bigFilePath = $gameMediaDirectory . "/big_" . $newMediaFileName; $fp = fopen($bigFilePath, 'w'); if (!$fp) { return new returnData(1, NULL, "Couldn't open file:{$bigFilePath}"); } fwrite($fp, base64_decode($data)); fclose($fp); $image = new Imagick($bigFilePath); // Reorient based on EXIF tag switch ($image->getImageOrientation()) { case Imagick::ORIENTATION_UNDEFINED: // We assume normal orientation break; case Imagick::ORIENTATION_TOPLEFT: // All good break; case Imagick::ORIENTATION_TOPRIGHT: $image->flopImage(); break; case Imagick::ORIENTATION_BOTTOMRIGHT: $image->rotateImage('#000', 180); break; case Imagick::ORIENTATION_BOTTOMLEFT: $image->rotateImage('#000', 180); $image->flopImage(); break; case Imagick::ORIENTATION_LEFTTOP: $image->rotateImage('#000', 90); $image->flopImage(); break; case Imagick::ORIENTATION_RIGHTTOP: $image->rotateImage('#000', 90); break; case Imagick::ORIENTATION_RIGHTBOTTOM: $image->rotateImage('#000', -90); $image->flopImage(); break; case Imagick::ORIENTATION_LEFTBOTTOM: $image->rotateImage('#000', -90); break; } $image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT); // Resize image proportionally so min(width, height) == $resizeTo if ($image->getImageWidth() < $image->getImageHeight()) { $image->resizeImage($resizeTo, 0, Imagick::FILTER_LANCZOS, 1); } else { $image->resizeImage(0, $resizeTo, Imagick::FILTER_LANCZOS, 1); } $image->setImageCompression(Imagick::COMPRESSION_JPEG); $image->setImageCompressionQuality(40); $image->writeImage($fullFilePath); unlink($bigFilePath); } else { $fp = fopen($fullFilePath, 'w'); if (!$fp) { return new returnData(1, NULL, "Couldn't open file:{$fullFilePath}"); } fwrite($fp, base64_decode($data)); fclose($fp); } if ($ext == "jpg" || $ext == "png" || $ext == "gif") { $img = WideImage::load($fullFilePath); $img = $img->resize(128, 128, 'outside'); $img = $img->crop('center', 'center', 128, 128); $img->saveToFile($gameMediaDirectory . "/" . $resizedMediaFileName); } else { if ($ext == "mp4") { /* $ffmpeg = '../../libraries/ffmpeg'; $videoFilePath = $gameMediaDirectory."/".$newMediaFileName; $tempImageFilePath = $gameMediaDirectory."/temp_".$resizedMediaFileName; $imageFilePath = $gameMediaDirectory."/".$resizedMediaFileName; $cmd = "$ffmpeg -i $videoFilePath 2>&1"; $thumbTime = 1; if(preg_match('/Duration: ((\d+):(\d+):(\d+))/s', shell_exec($cmd), $videoLength)) $thumbTime = (($videoLength[2] * 3600) + ($videoLength[3] * 60) + $videoLength[4])/2; $cmd = "$ffmpeg -i $videoFilePath -deinterlace -an -ss $thumbTime -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $tempImageFilePath 2>&1"; shell_exec($cmd); $img = WideImage::load($tempImageFilePath); $img = $img->resize(128, 128, 'outside'); $img = $img->crop('center','center',128,128); $img->saveToFile($imageFilePath); */ } } $m = Media::createMedia($path, "UploadedMedia", $newMediaFileName, 0); return new returnData(0, $m->data); }
public function createGame($name, $description, $iconMediaId, $mediaId, $readyForPublic, $isLocational, $introNodeId, $completeNodeId, $shareToMap, $shareToBook, $allowPlayerTags, $allowNoteComments, $allowNoteLikes, $pcMediaId, $usePlayerPic, $mapType, $showPlayerOnMap, $allLocQuickTravel, $inventoryWeightCap, $allowTrading, $editorId, $editorToken) { if (!Module::authenticateEditor($editorId, $editorToken, "read_write")) { return new returnData(6, NULL, "Failed Authentication"); } $name = addslashes($name); $description = addslashes($description); if ($g = Module::queryObject("SELECT * FROM games WHERE name = '" . $name . "'")) { return new returnData(4, $g->game_id, 'duplicate name'); } $query = "INSERT INTO games (\n name, description,\n icon_media_id, media_id,\n ready_for_public, is_locational,\n on_launch_node_id, game_complete_node_id,\n allow_share_note_to_map, allow_share_note_to_book, allow_player_tags, allow_note_comments, allow_note_likes,\n pc_media_id, use_player_pic,\n map_type, show_player_location,\n full_quick_travel,\n inventory_weight_cap, allow_trading,\n created\n ) VALUES (\n '" . $name . "', '" . $description . "',\n '" . $iconMediaId . "', '" . $mediaId . "',\n '" . $readyForPublic . "', '" . $isLocational . "',\n '" . $introNodeId . "', '" . $completeNodeId . "',\n '" . $shareToMap . "', '" . $shareToBook . "', '" . $allowPlayerTags . "', '" . $allowNoteComments . "', '" . $allowNoteLikes . "',\n '" . $pcMediaId . "', '" . $usePlayerPic . "',\n '" . $mapType . "', '" . $showPlayerOnMap . "',\n '" . $allLocQuickTravel . "',\n '" . $inventoryWeightCap . "', '" . $allowTrading . "',\n NOW())"; Module::query($query); if (mysql_error()) { return new returnData(6, NULL, "cannot create game record using SQL: {$query}"); } $newGameId = mysql_insert_id(); Module::query("INSERT INTO game_editors (game_id,editor_id) VALUES ('{$newGameId}','{$editorId}')"); if (mysql_error()) { return new returnData(6, NULL, 'cannot create game_editors record'); } Module::query("INSERT INTO `game_tab_data` (`game_id` ,`tab` ,`tab_index`) VALUES ('{$newGameId}', 'QUESTS', '1')"); Module::query("INSERT INTO `game_tab_data` (`game_id` ,`tab` ,`tab_index`) VALUES ('{$newGameId}', 'GPS', '2')"); Module::query("INSERT INTO `game_tab_data` (`game_id` ,`tab` ,`tab_index`) VALUES ('{$newGameId}', 'INVENTORY', '3')"); Module::query("INSERT INTO `game_tab_data` (`game_id` ,`tab` ,`tab_index`) VALUES ('{$newGameId}', 'QR', '4')"); Module::query("INSERT INTO `game_tab_data` (`game_id` ,`tab` ,`tab_index`) VALUES ('{$newGameId}', 'PLAYER', '5')"); Module::query("INSERT INTO `game_tab_data` (`game_id` ,`tab` ,`tab_index`) VALUES ('{$newGameId}', 'NOTE', '6')"); Module::query("INSERT INTO `game_tab_data` (`game_id` ,`tab` ,`tab_index`) VALUES ('{$newGameId}', 'STARTOVER', '998')"); Module::query("INSERT INTO `game_tab_data` (`game_id` ,`tab` ,`tab_index`) VALUES ('{$newGameId}', 'PICKGAME', '9999')"); $newGameDirectory = Media::getMediaDirectory($newGameId)->data; mkdir($newGameDirectory, 0777); return new returnData(0, $newGameId, NULL); }