Created
May 19, 2017 21:16
-
-
Save mislavjakopovic/88336f92b30bb8e5b540bfab037d38bf to your computer and use it in GitHub Desktop.
how not to do your projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function actionExport() | |
| { | |
| //get all the rooms | |
| $rooms = Room::model()->findAll(array('order'=>'orderby')); | |
| foreach ($rooms as $r) { | |
| $rslug = $r->slug; | |
| $$rslug = <<<HTMLComposeMessage | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <panorama id="node1"> | |
| <input levelingroll="0" levelingpitch="0" width="1024" overlap="1" height="1024" levelbias="0.400" levelbiashidpi="0.400" leveltilesize="510" leveltileurl="tiles/$rslug/cf_%c/l_%l/c_%x/tile_%y.jpg"> | |
| <level width="1024" height="1024" preload="0" predecode="0"/> | |
| <level width="512" height="512" preload="0" predecode="0"/> | |
| <level width="256" height="256" preload="1" predecode="1"/> | |
| <preview color="0x808080" strip="1"/> | |
| </input> | |
| <view pannorth="0" fovmode="0"> | |
| <start fov="70" pan="$r->startPan" tilt="$r->startTilt"/> | |
| <min tilt="-90" pan="0" fov="70"/> | |
| <max tilt="90" pan="360" fov="85"/> | |
| </view> | |
| <userdata title="" latitude="" author="" tags="stiched_images" longitude="" info="" description="" source="" copyright="" comment="" datetime=""/> | |
| <hotspots width="180" height="20" wordwrap="1"> | |
| HTMLComposeMessage; | |
| } | |
| $finalString = "var jsonPano = ["; | |
| $arRoom = Room::model()->findAll(); | |
| foreach ($arRoom as $room) { | |
| if((isset($room->id)) and (!empty($room->id))){ | |
| $roomId=$room->id; | |
| }else{ | |
| $roomId=""; | |
| } | |
| if((isset($room->name)) and (!empty($room->name))){ | |
| $title=$room->name; | |
| }else{ | |
| $title=""; | |
| } | |
| if((isset($room->slug)) and (!empty($room->slug))){ | |
| $slug=$room->slug; | |
| }else{ | |
| $slug=""; | |
| } | |
| $finalString .= <<<HTMLComposeMessage | |
| { | |
| "id":$roomId, | |
| "mapX":$room->mapX, | |
| "mapY":$room->mapY, | |
| "title":"$title", | |
| "slug":"$slug" | |
| }, | |
| HTMLComposeMessage; | |
| } | |
| $finalString .= " ]; "; | |
| $finalString .= " var jsonCont = ["; | |
| $arZoom = Zoom::model()->findAll(); | |
| foreach ($arZoom as $zoom) { | |
| $zoomId = 100000 + (int)$zoom->id; | |
| if ($zoom->video) { | |
| $video = $zoom->video; | |
| } else { | |
| $video = ""; | |
| } | |
| if (strpos($zoom->icon, '.') !== false) { | |
| $icon = $zoom->icon; | |
| } else { | |
| $icon = ""; | |
| } | |
| if((isset($zoom->slug)) and (!empty($zoom->slug))){ | |
| $slug=$zoom->slug; | |
| }else{ | |
| $slug=""; | |
| } | |
| if((isset($zoom->roomId)) and (!empty($zoom->roomId))){ | |
| $roomId=$zoom->roomId; | |
| }else{ | |
| $roomId=""; | |
| } | |
| if((isset($zoom->pin_color)) and (!empty($zoom->pin_color))){ | |
| $pin_color=$zoom->pin_color; | |
| }else{ | |
| $pin_color=""; | |
| } | |
| if((isset($zoom->icon_headline)) and (!empty($zoom->icon_headline))){ | |
| $icon_headline=$zoom->icon_headline; | |
| }else{ | |
| $icon_headline=""; | |
| } | |
| if((isset($zoom->name)) and (!empty($zoom->name))){ | |
| $title=$zoom->name; | |
| }else{ | |
| $title=""; | |
| } | |
| if((isset($zoom->path)) and (!empty($zoom->path))){ | |
| $path=$zoom->path; | |
| }else{ | |
| $path=""; | |
| } | |
| $finalString .= <<<HTMLComposeMessage | |
| { | |
| "id":$zoomId, | |
| "slug":"$slug", | |
| "idPano":$roomId, | |
| "idZoom":false, | |
| "pinX":$zoom->pan, | |
| "pinY":$zoom->tilt, | |
| "pinImg":"$icon", | |
| "pinColor":"$pin_color", | |
| "pinText":"$icon_headline", | |
| "contentTemplate":"zoom", | |
| "contentTitle":"$title", | |
| "contentText":"", | |
| "contentImg":"$path", | |
| "contentVideo":"$video", | |
| "link":"" | |
| }, | |
| HTMLComposeMessage; | |
| //build the xml files | |
| $roomSlug = $zoom->room0->slug; | |
| $finalSlug = "/" . $roomSlug . "/zoom-" . $zoom->slug; | |
| $$roomSlug .= <<<HTMLComposeMessage | |
| <hotspot | |
| custom_id="$zoomId" | |
| title="$title" | |
| skinid="ht_url" | |
| pan="$zoom->pan" | |
| tilt="$zoom->tilt" | |
| id="$slug" | |
| url="$finalSlug" /> | |
| HTMLComposeMessage; | |
| } | |
| //get all the transfers | |
| $allTrans = Transfer::model()->findAll(); | |
| if(isset($allTrans) and !empty($allTrans)) { | |
| foreach ($allTrans as $trans) { | |
| $fromRoom = $trans->roomFrom->slug; | |
| $toSlug = $trans->roomTo->slug; | |
| $id = (int)$trans->id + 200000; | |
| if ((isset($trans->icon)) and (!empty($trans->icon))) { | |
| $icon = $trans->icon; | |
| } else { | |
| $icon = ""; | |
| } | |
| $finalString .= <<<HTMLComposeMessage | |
| { | |
| "id":$id, | |
| "slug":"", | |
| "idPano":$trans->fromRoomId, | |
| "idZoom":false, | |
| "pinX":$trans->pan, | |
| "pinY":$trans->tilt, | |
| "pinImg":"$icon", | |
| "pinColor":"", | |
| "pinText":"", | |
| "contentTemplate":"transfer", | |
| "contentTitle":"", | |
| "contentText":"", | |
| "contentImg":"", | |
| "contentVideo":"", | |
| "link":"/$toSlug" | |
| }, | |
| HTMLComposeMessage; | |
| $$fromRoom .= <<<HTMLComposeMessage | |
| <hotspot | |
| custom_id="$id" | |
| title="" | |
| skinid="ht_url" | |
| pan="$trans->pan" | |
| tilt="$trans->tilt" | |
| id="" | |
| url="/$toSlug" /> | |
| HTMLComposeMessage; | |
| } | |
| } | |
| $allArs = Content::model()->findAllByAttributes(array('active' => 1)); | |
| if(isset($allArs) and !empty($allArs)) { | |
| foreach ($allArs as $content) { | |
| if (isset($content->zoomId)) { | |
| $zoomId = $content->zoomId; | |
| } else { | |
| $zoomId = "false"; | |
| } | |
| $category = $content->category0; | |
| if ($category !== null) { | |
| $template = $content->category0->name; | |
| } else { | |
| $template = false; | |
| } | |
| if ((!isset($content->zoomId)) or ($content->zoomId == null) or ($content->zoomId == 0)) { | |
| $nZoomId = "false"; | |
| } else { | |
| $nZoomId = 100000 + (int)$content->zoomId; | |
| } | |
| if (strpos($content->icon, '.') !== false) { | |
| $icon = $content->icon; | |
| } else { | |
| $icon = ""; | |
| } | |
| if (strlen($content->image) < 12) { | |
| $imagePath = ""; | |
| } else { | |
| $imagePath = $content->image; | |
| } | |
| if ($content->video) { | |
| $video = $content->video; | |
| } else { | |
| $video = ""; | |
| } | |
| $newCOntent = preg_replace("/\r|\n/", "", $content->content); | |
| $newCOntent = str_replace('"', "", $newCOntent); | |
| $newCOntent = addslashes($newCOntent); | |
| if ((isset($content->slug)) and (!empty($content->slug))) { | |
| $slug = $content->slug; | |
| } else { | |
| $slug = ""; | |
| } | |
| if ((isset($content->pin_color)) and (!empty($content->pin_color))) { | |
| $pin_color = $content->pin_color; | |
| } else { | |
| $pin_color = ""; | |
| } | |
| if ((isset($content->icon_headline)) and (!empty($content->icon_headline))) { | |
| $icon_headline = $content->icon_headline; | |
| } else { | |
| $icon_headline = ""; | |
| } | |
| if ((isset($content->header)) and (!empty($content->header))) { | |
| $title = $content->header; | |
| } else { | |
| $title = ""; | |
| } | |
| if ((isset($content->link)) and (!empty($content->link))) { | |
| $link = $content->link; | |
| } else { | |
| $link = ""; | |
| } | |
| $finalString .= <<<HTMLComposeMessage | |
| { | |
| "id":$content->id, | |
| "slug":"$slug", | |
| "idPano":$content->roomId, | |
| "idZoom":$nZoomId, | |
| "pinX":$content->pan, | |
| "pinY":$content->tilt, | |
| "pinImg":"$icon", | |
| "pinColor":"$pin_color", | |
| "pinText":"$icon_headline", | |
| "contentTemplate":"$template", | |
| "contentTitle":"$title", | |
| "contentText":"$newCOntent", | |
| "contentImg":"$imagePath", | |
| "contentVideo":"$video", | |
| "link":"$link" | |
| }, | |
| HTMLComposeMessage; | |
| //build the xml files | |
| if ((!isset($content->zoomId)) or ($content->zoomId == null) or ($content->zoomId == 0)) { | |
| $roomSlug = $content->room0->slug; | |
| if ($nZoomId) { | |
| if ($nZoomId > 100000) { | |
| $finalSlug = "/" . $roomSlug . "/zoom-" . $content->slug; | |
| } else { | |
| $finalSlug = "/" . $roomSlug . "/" . $content->slug; | |
| } | |
| } | |
| $$roomSlug .= <<<HTMLComposeMessage | |
| <hotspot | |
| custom_id="$content->id" | |
| title="$title" | |
| skinid="ht_url" | |
| pan="$content->pan" | |
| tilt="$content->tilt" | |
| id="$slug" | |
| url="$finalSlug" /> | |
| HTMLComposeMessage; | |
| } | |
| } | |
| $finalString .= "];"; | |
| } | |
| //$finalString = str_replace("-", "", $finalString); | |
| if(strpos($_SERVER["SERVER_NAME"], ".sk")) | |
| { | |
| $exportpath = "../sk/export.js"; | |
| } | |
| else | |
| { | |
| $exportpath = "../cz/export.js"; | |
| } | |
| $myfile = fopen($exportpath, "w"); | |
| fwrite($myfile, $finalString); | |
| fclose($myfile); | |
| echo "Exported!<br>"; | |
| $rooms = Room::model()->findAll(); | |
| foreach ($rooms as $r) { | |
| $rslug = $r->slug; | |
| $$rslug .= <<<HTMLComposeMessage | |
| </hotspots> | |
| <media/> | |
| <transition blendtime="1" blendcolor="0x000000" zoomin="0" zoomoutpause="1" type="crossdissolve" zoomfov="20" zoomout="0" zoomspeed="2" enabled="0" softedge="0"/> | |
| <control dblclickfullscreen="0" sensitivity="8" simulatemass="1" lockedmouse="0" lockedkeyboard="1" contextfullscreen="0" lockedwheel="0" invertwheel="1" lockedkeyboardzoom="1" speedwheel="1" hideabout="0" invertcontrol="1"/> | |
| </panorama> | |
| HTMLComposeMessage; | |
| if(strpos($_SERVER["SERVER_NAME"], ".sk")) | |
| { | |
| $fileName = "../panoramas/sk/" . $rslug . ".xml"; | |
| } | |
| else | |
| { | |
| $fileName = "../panoramas/cz/" . $rslug . ".xml"; | |
| } | |
| $myfile = fopen($fileName, "w"); | |
| fwrite($myfile, $$rslug); | |
| fclose($myfile); | |
| echo "Exported!<br>"; | |
| } | |
| $quiz = Quiz::model()->findAll(); | |
| if(isset($quiz) and !empty($quiz)) { | |
| $zoomResult = " | |
| var questions = ["; | |
| foreach ($quiz as $zoom) { | |
| $cont = Content::model()->findAllByAttributes(array('quizId' => $zoom->id)); | |
| if(isset($cont) and !empty($cont)) { | |
| $qid = $cont[0]->id; | |
| $question = str_replace('"', "'", $zoom->question); | |
| $textCorrect = str_replace('"', "'", $zoom->textCorrect); | |
| $textWrong = str_replace('"', "'", $zoom->textWrong); | |
| $zoomResult .= <<<HTMLComposeMessage | |
| { | |
| id:$qid, | |
| question: "$question", | |
| choices: ["$zoom->a1", "$zoom->a2", "$zoom->a3"], | |
| images: ["$zoom->p1", "$zoom->p2", "$zoom->p3"], | |
| correct:"$textCorrect", | |
| wrong:"$textWrong", | |
| correctAnswer: $zoom->correct | |
| }, | |
| HTMLComposeMessage; | |
| } | |
| } | |
| $zoomResult .= "];"; | |
| } | |
| //$finalString=str_replace("-","",$finalString); | |
| $finalString .= $zoomResult; | |
| if(strpos($_SERVER["SERVER_NAME"], ".sk")) | |
| { | |
| $exportpath = "../panoramas/sk/export.js"; | |
| } | |
| else | |
| { | |
| $exportpath = "../panoramas/cz/export.js"; | |
| } | |
| $myfile = fopen($exportpath, "w"); | |
| fwrite($myfile, $finalString); | |
| fclose($myfile); | |
| echo "Exported!<br>"; | |
| // GIT | |
| if(strpos($_SERVER["SERVER_NAME"], ".sk")) | |
| { | |
| echo shell_exec("cd ../..; ./push-static-sk.sh;")."<br>"; | |
| } | |
| else | |
| { | |
| echo shell_exec("cd ../..; ./push-static-cz.sh;")."<br>"; | |
| } | |
| } |
Author
mislavjakopovic
commented
May 20, 2017

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment