Exemplo n.º 1
0
 public function getQRCodePackageURL($gameId)
 {
     $query = "SELECT * FROM qrcodes WHERE game_id = {$gameId}";
     $rsResult = Module::query($query);
     if (mysql_error()) {
         return new returnData(3, NULL, "SQL Error");
     }
     //Set up a tmp directory
     $relDir = "{$gameId}_qrcodes_" . date('Y_m_d_h_i_s');
     $tmpDir = Config::gamedataFSPath . "/backups/{$relDir}";
     $command = "mkdir {$tmpDir}";
     exec($command, $output, $return);
     if ($return) {
         return new returnData(4, NULL, "cannot create backup dir, check file permissions");
     }
     //Get all the images
     while ($qrCode = mysql_fetch_object($rsResult)) {
         //Look up the item to get a good file name
         $fileNameType = '';
         $fileNameId = '';
         $fileNameName = '';
         switch ($qrCode->link_type) {
             case 'Location':
                 $fileNameType = "Location";
                 $fileNameId = $qrCode->link_id;
                 $locationReturnData = Locations::getLocation($gameId, $qrCode->link_id);
                 $location = $locationReturnData->data;
                 switch ($location->type) {
                     case 'Npc':
                         $object = Npcs::getNpc($gameId, $location->type_id);
                         $fileNameName = $object->data->name;
                         break;
                     case 'Node':
                         $object = Nodes::getNode($gameId, $location->type_id);
                         $fileNameName = $object->data->title;
                         break;
                     case 'Item':
                         $object = Items::getItem($gameId, $location->type_id);
                         $fileNameName = $object->data->name;
                         break;
                 }
                 break;
             default:
                 $returnResult = new returnData(5, NULL, "Invalid QR Code Found.");
         }
         $fileName = "{$fileNameType}{$fileNameId}-{$fileNameName}.jpg";
         $command = "curl -s -o /{$tmpDir}/{$fileName} 'http://chart.apis.google.com/chart?chs=300x300&cht=qr&choe=UTF-8&chl={$qrCode->code}'";
         exec($command, $output, $return);
         if ($return) {
             return new returnData(4, NULL, "cannot download and save qr code image, check file permissions and url in console");
         }
     }
     //Zip up the whole directory
     $zipFileName = "aris_qr_codes.tar";
     $cwd = Config::gamedataFSPath . "/backups";
     chdir($cwd);
     $command = "tar -cf {$zipFileName} {$relDir}/";
     exec($command, $output, $return);
     if ($return) {
         return new returnData(5, NULL, "cannot compress backup dir, check that tar command is availabe.");
     }
     //Delete the Temp
     /*
       $rmCommand = "rm -rf {$tmpDir}";
       exec($rmCommand, $output, $return);
       if ($return) return new returnData(5, NULL, "cannot delete backup dir, check file permissions");
     */
     return new returnData(0, Config::gamedataWWWPath . "/backups/{$zipFileName}");
 }
 private function hydrateContent($content, $gameId)
 {
     if ($content->content_type == 'Node') {
         $contentDetails = Nodes::getNode($gameId, $content->content_id)->data;
         $content->name = $contentDetails->title;
     } else {
         if ($content->content_type == 'Item') {
             $contentDetails = Items::getItem($gameId, $content->content_id)->data;
             $content->name = $contentDetails->name;
         } else {
             if ($content->content_type == 'Npc') {
                 $contentDetails = Npcs::getNpc($gameId, $content->content_id)->data;
                 $content->name = $contentDetails->name;
             } else {
                 if ($content->content_type == 'WebPage') {
                     $contentDetails = WebPages::getWebPage($gameId, $content->content_id)->data;
                     $content->name = $contentDetails->name;
                     $content->media = NULL;
                     $content->media_id = NULL;
                 } else {
                     if ($content->content_type == 'AugBubble') {
                         $contentDetails = AugBubbles::getAugBubble($gameId, $content->content_id)->data;
                         $content->name = $contentDetails->name;
                         $content->media = NULL;
                         $content->media_id = NULL;
                     } else {
                         if ($content->content_type == 'CustomMap') {
                             $contentDetails = Overlays::getOverlay($gameId, $content->content_id)->data;
                             $content->name = $contentDetails->name;
                         } else {
                             if ($content->content_type == 'PlayerNote') {
                                 $contentDetails = Notes::getNoteById($content->content_id)->data;
                                 $content->name = $contentDetails->title;
                                 $content->icon_media_id = 5;
                                 $content->media = NULL;
                                 $content->media_id = NULL;
                             }
                         }
                     }
                 }
             }
         }
     }
     //Get the Icon Media
     $mediaHelper = new Media();
     $mediaReturnObject = $mediaHelper->getMediaObject($gameId, $contentDetails->icon_media_id);
     $media = $mediaReturnObject->data;
     $content->icon_media = $media;
     $content->icon_media_id = $contentDetails->icon_media_id;
     $content->is_spawnable = Spawnables::hasActiveSpawnable($gameId, $content->content_type, $content->content_id);
     if ($content->content_type != 'WebPage' && $content->content_type != 'PlayerNote' && $content->content_type != 'AugBubble' && $content->content_type != 'CustomMap') {
         //Get the Media
         $mediaHelper = new Media();
         $mediaReturnObject = $mediaHelper->getMediaObject($gameId, $contentDetails->media_id);
         $media = $mediaReturnObject->data;
         $content->media = $media;
         $content->media_id = $contentDetails->media_id;
     }
     /* Depricated
           if ($content->content_type == 'AugBubble'){
        //Get the Alignment Media
        $mediaHelper = new Media;
        $mediaReturnObject = $mediaHelper->getMediaObject($gameId, $contentDetails->alignment_media_id);
        $alignmentMedia = $mediaReturnObject->data;
        $content->alignment_media = $alignmentMedia;
        $content->alignment_media_id = $alignmentMedia->media_id;
        }
         */
     return $content;
 }