Example #1
0
     $NameofActivity->nodeValue = $_POST['theme'];
     $xml->save("../config.xml") or die("Couldn't change the theme");
     echo "Theme has been changed successfully!";
 } elseif (!empty($_POST['beforeimageupload'])) {
 } elseif (!empty($_POST['updateWords'])) {
     //	addWord
     addWord($_POST['word'], $_POST['category'], $_POST['tags'], '4pics1');
     //	getLastWordDetails
     $mslno = getLastWordDetails();
     //	updateFolderName
     updateWordFolder($_POST['loc'], $mslno);
     echo "Your word has been added to database successfully !";
 } elseif (!empty($_FILES)) {
     //	$mime_type=check_mime_content_type($_FILES["activity-file"]["name"]);
     //	echo $mime_type;
     if (is_zip_file($_FILES["activity-file"]["name"]) && zipIsValid($_FILES["activity-file"]["tmp_name"])) {
         //		echo "VALID";
         //		pr($_FILES);
         //		echo $mime_type;
         $zip = new ZipArchive();
         $filedetail = pathinfo($_FILES["activity-file"]["name"]);
         if ($zip->open($_FILES["activity-file"]["tmp_name"]) === TRUE) {
             $zip->extractTo('../assets/Games/' . $filedetail["filename"] . "/");
             recurse_copy("../assets/support_files/", '../assets/Games/' . $filedetail["filename"] . "/");
             $zip->close();
             echo 'Activity Uploaded Successfully!';
         } else {
             echo 'Error occured while extracting zip file.';
         }
     } else {
         echo "Please upload only zip files(*.zip).";
Example #2
0
 public static function import($url)
 {
     $upload_dir = wp_upload_dir();
     $upload_url = $upload_dir['url'];
     $upload_path = $upload_dir['path'];
     $dirname = pathinfo($url, PATHINFO_FILENAME);
     // filename without extension
     $basename = pathinfo($url, PATHINFO_BASENAME);
     // file with extension
     // Download file
     if (file_put_contents($upload_path . '/' . $basename, file_get_contents($url)) === FALSE) {
         die('Error : can\'t upload.');
     }
     // Check file type
     if (!zipIsValid($upload_path . '/' . $basename)) {
         die('Wrong file.');
     }
     // Extract archive
     $zip = new ZipArchive();
     $res = $zip->open($upload_path . '/' . $basename);
     // new dirname based on real directory on the zip
     $dirname = dirname(trim($zip->getNameIndex(0), '/'));
     if ($dirname == '.') {
         // In some cases (when zip is not generated via export),
         // the getNameIndex already returns the perfect dirname
         // so applying dirname() returns "."
         $dirname = trim($zip->getNameIndex(0), '/');
     }
     if ($res === TRUE) {
         $zip->extractTo($upload_path);
         $zip->close();
     } else {
         die('Error : can\'t upload.');
     }
     // Get the json file
     $exportJson = file_get_contents($upload_path . '/' . $dirname . '/export.json');
     if ($exportJson === FALSE) {
         die('Error : can\'t upload.');
     }
     // Parse raw to json
     $exportJson = json_decode($exportJson, true);
     if ($exportJson == NULL) {
         die('Wrong file.');
     }
     // Import Quiz
     if (!isset($exportJson['settings']['type'])) {
         die('Wrong file.');
     }
     $quizType = $exportJson['settings']['type'];
     $quiz = new $quizType();
     $quiz->add($exportJson['settings']);
     // Upload pictures
     foreach (glob("{$upload_path}/{$dirname}/*.{jpg,png,gif}", GLOB_BRACE) as $key => $file) {
         $basename = pathinfo($file, PATHINFO_BASENAME);
         $oldId = pathinfo($file, PATHINFO_FILENAME);
         $newId = custom_media_sideload_image("{$upload_url}/{$dirname}/{$basename}");
         array_replace_only_for_key($exportJson['content'], 'pictureId', $oldId, $newId);
     }
     // Appreciations
     foreach ($exportJson['appreciations'] as $appreciation) {
         $matches = array();
         preg_match_all('#%%export(.*)%%#', $appreciation['content'], $matches);
         foreach ($matches[1] as $match) {
             $newId = custom_media_sideload_image("{$upload_url}/{$dirname}/{$match}");
             $url = wp_get_attachment_url($newId);
             $appreciation['content'] = str_replace('%%export' . $match . '%%', $url, $appreciation['content']);
         }
         $newAppr = $quiz->addAppreciation($appreciation);
         $oldId = $appreciation['id'];
         $newId = $newAppr->getId();
         array_replace_only_for_key($exportJson['content'], 'appreciationId', $oldId, $newId);
     }
     // Questions + answers
     foreach ($exportJson['content'] as $content) {
         $question = $content['question'];
         $question = $quiz->addQuestion($question);
         // Answers
         foreach ($content['answers'] as $index => $answer) {
             $multipliers = $quizType == 'WPVQGameTrueFalse' ? array() : $answer['multipliers'];
             $question->addAnswer($answer, NULL, $multipliers);
         }
     }
     // ExtraOptions
     if (isset($exportJson['extraOptions'])) {
         foreach ($exportJson['extraOptions'] as $name => $option) {
             self::updateExtraOption($quiz->getId(), $name, $option);
         }
     }
 }