Beispiel #1
0
 public static function return_template_preview_html($template_id = '', $loc = 1)
 {
     if ('' == $template_id) {
         return "";
     } else {
         $uID = uniqid('t');
         $poll = new YOP_POLL_Poll_Model();
         $template_details = self::get_poll_template_from_database(intval($template_id));
         $template = $template_details['before_vote_template'];
         $template = stripslashes_deep($template);
         $template = str_ireplace('%POLL-NAME%', "Poll Name", $template);
         $template = str_ireplace('%POLL-VOTE-BUTTON%', '<button class="yop_poll_vote_button" onclick="return false;">Vote</button>', $template);
         $question = new YOP_POLL_Question_Model();
         $question->question = "Poll Question";
         $question->allow_multiple_answers = "no";
         $question->allow_other_answers = "no";
         for ($i = 0; $i < 5; $i++) {
             $a = new YOP_POLL_Answer_Model();
             $j = $i + 1;
             $a->ID = $i + 1;
             $a->answer = "Answer {$j}";
             $question->addAnswer($a);
             unset($a);
         }
         $poll->questions = $question;
         $t = $template;
         $pattern = '\\[(\\[?)(QUESTION_CONTAINER)\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)';
         preg_match("/{$pattern}/s", $t, $m);
         //print_r($m);
         $m = $m[5];
         $m = str_ireplace("%POLL-QUESTION%", $question->question, $m);
         $pattern = '/\\[(\\[?)(ANSWER_CONTAINER)\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)/';
         preg_match($pattern, $m, $m1);
         $m1 = $m1[5];
         $ts = "";
         /** Start Answer Description replace */
         $pattern = '\\[(\\[?)(ANSWER_DESCRIPTION_CONTAINER)\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)';
         $m1 = preg_replace("/{$pattern}/s", "", $m1);
         /** End Answer Description replace */
         /** Start Answer Result replace */
         $pattern = '\\[(\\[?)(ANSWER_RESULT_CONTAINER)\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)';
         $m1 = preg_replace("/{$pattern}/s", "", $m1);
         /** End Answer Result replace */
         foreach ($question->answers as $answer) {
             $temps = str_ireplace('%POLL-ANSWER-CHECK-INPUT%', '<input type="radio" value="' . $answer->ID . '" name="yop_poll_answer-' . $uID . '" id="yop-poll-answer-' . $uID . '-' . $answer->ID . '" />', $m1);
             $temps = str_ireplace('%POLL-ANSWER-LABEL%', '<label>' . $answer->answer . '</label>', $temps);
             $ts .= $temps;
         }
         $pattern = '/\\[(\\[?)(ANSWER_CONTAINER)\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)/';
         $m = preg_replace($pattern, $ts, $m);
         $pattern = '\\[(\\[?)(QUESTION_CONTAINER)\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)';
         $template = preg_replace("/{$pattern}/s", $m, $template);
         $pattern = array('/\\[(\\[?)(OTHER_ANSWER_CONTAINER)\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)/', '/\\[(\\[?)(CUSTOM_FIELD_CONTAINER)\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)/', '/\\[(\\[?)(ANSWER_RESULT_CONTAINER)\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)/', '/\\[(\\[?)(CAPTCHA_CONTAINER)\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)/');
         $template = preg_replace($pattern, "", $template);
         $template = preg_replace('/\\[\\/?QUESTION_CONTAINER\\]/', "", $template);
         $template = str_ireplace("%POLL-ID%", "preview-" . $uID, $template);
         $template = self::strip_all_tags($template);
         $t = '<style type="text/css">' . $poll->return_poll_css($template_details['css'], array("location" => 'page', 'preview' => true, 'template_id' => $uID, 'loc' => $loc)) . '</style>';
         $t .= '<div id="yop-poll-container-preview-' . $uID . '" class="yop-poll-container" style="position: relative; z-index: 1;">';
         $t .= '' . $template . '</div>';
         $qID = uniqid('q');
         $t = str_ireplace("%QUESTION-ID%", $qID, $t);
         return $t;
     }
 }