/** * Shortcode display Quiz's Results in front */ public static function viralQuizResults() { global $wpdata; // Data helpful to debug : // $array = array( // 'quizId' => 98, // 'resultValue' => 1, // ); // echo base64_encode(json_encode($array)); // No URL parameters if (!isset($_GET['wpvqdataresults'])) { return; } $results = json_decode(base64_decode($_GET['wpvqdataresults']), true); if (!is_array($results) || !isset($results['quizId']) || !isset($results['resultValue'])) { return; } // Load quizz $id = intval($results['quizId']); try { $type = WPVQGame::getTypeById($id); $quiz = new $type(); $q = $quiz->load($id, false); } catch (Exception $e) { echo "ERROR : Quiz #{$param['id']} doesn't exist."; die; } // Useful to load JS script self::$isShortcodeLoaded = true; self::$quiz = $q; $wpdata['quiz'] = $q; $wpdata['type'] = $type; // Fetch results if ($type == 'WPVQGameTrueFalse') { $wpdata['results'] = json_decode(WPVQShortcode::getTrueFalseAppreciation($id, $results['resultValue']), true); } else { if ($type == 'WPVQGamePersonality') { $wpdata['results'] = json_decode(WPVQShortcode::choosePersonality($results['resultValue']), true); } } // Also keep the main value (score, personality, ...) $wpdata['results']['resultValue'] = $results['resultValue']; $shortCode = ob_start(); include dirname(__FILE__) . '/../views/WPVQShortcodeResults.php'; $output = ob_get_contents(); ob_end_clean(); return $output; }