/** 
  * 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;
 }
Example #2
0
 /** 
  * Shortcode display Quiz in front 
  *
  * @var 
  * (int) id : quiz's id
  *
  * (int) columns : number of columns
  *  
  */
 public static function viralQuiz($param)
 {
     global $wpdata;
     // Bad ID
     if (!is_numeric($param['id'])) {
         return;
     }
     // Show quiz only when on page
     if (!is_page() && !is_single()) {
         return;
     }
     // Load quizz
     $id = intval($param['id']);
     try {
         $type = WPVQGame::getTypeById($id);
         $quiz = new $type();
         $q = $quiz->load($id, true);
     } 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;
     if (isset($param['columns']) && is_numeric($param['columns'])) {
         $wpdata['columns'] = $param['columns'];
     } else {
         $wpdata['columns'] = 3;
     }
     $shortCode = ob_start();
     include dirname(__FILE__) . '/../views/WPVQShortcode.php';
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }