Exemplo n.º 1
0
 private function import_wp_polls()
 {
     if (check_admin_referer('yop-poll-import', 'yop-poll-imports')) {
         if (current_user_can('import_wp_polls')) {
             $current_date = date('Y/m/d H:i:s');
             $wp_polls = self::get_wp_polls_from_db();
             foreach ($wp_polls as $wp_poll) {
                 $poll = new YOP_POLL_Poll_Model(0);
                 $answers = self::get_wp_poll_answers_from_db_by_id($wp_poll->pollq_id);
                 $poll->poll_title = $wp_poll->pollq_question;
                 $poll->poll_name = $wp_poll->pollq_question;
                 $poll->poll_author = get_current_user_id();
                 $poll->poll_start_date = date("Y-m-d H:i:s", $wp_poll['pollq_timestamp']);
                 if ($wp_poll['pollq_expiry'] != "") {
                     $poll->poll_end_date = date("Y-m-d H:i:s", $wp_poll['pollq_expiry']);
                 } else {
                     $poll->poll_end_date = "01-01-2038 23:59:59";
                 }
                 $poll->poll_status = "active";
                 $poll->poll_date = $current_date;
                 $poll->poll_modified = $current_date;
                 $poll->poll_total_votes = $wp_poll->pollq_totalvotes;
                 $question = new YOP_POLL_Question_Model();
                 $poll_id = $poll->save();
                 $question->poll_d = $poll_id;
                 $question->question = $wp_poll->pollq_question;
                 $question->question_status = "active";
                 $question->question_author = get_current_user_id();
                 $question->poll_order = 1;
                 $question->question_date = $current_date;
                 $question->question_modified = $current_date;
                 $question->save();
                 foreach ($answers as $answer) {
                     $poll_answer = new YOP_POLL_Answer_Model();
                     $poll_answer->poll_id = $poll_id;
                     $poll_answer->question_id = $question->ID;
                     $poll_answer->answer = $answer['polla_answers'];
                     $poll_answer->answer_status = "active";
                     $poll_answer->question_order = 1;
                     $poll_answer->answer_author = get_current_user_id();
                     $poll_answer->votes = $answer['polla_votes'];
                     $poll_answer->answer_date = $current_date;
                     $poll_answer->answer_modified = $current_date;
                     $poll_answer->save();
                     unset($log_details);
                     $log_details = self::get_log_from_db_by_poll_id($wp_poll->pollq_id, $answer['polla_aid']);
                     foreach ($log_details as $log) {
                         $arg['poll_id'] = $poll->ID;
                         $arg['ip'] = $log['pollip_ip'];
                         if ($log['pollip_user'] == 'Guest') {
                             $arg['user_type'] = 'anonymous';
                         } else {
                             $arg['user_type'] = "wordpress";
                         }
                         $arg['user_id'] = $log['pollip_userid'];
                         $arg['vote_date'] = $log['pollip_timestamp'];
                         $a = self::get_answer_from_db_by_id($log['pollip_aid']);
                         $arg[1]["q-" . $question->ID]['a'][0] = $poll_answer->ID;
                         $arg[1]["q-" . $question->ID]['answers'][0] = $a[0]['polla_answers'];
                         $q = self::get_question_from_db_by_id($log['pollip_qid']);
                         $arg[1]["q-" . $question->ID]['question'] = $q[0]['pollq_question'];
                         $arg['vote_details'] = json_encode($arg[1]);
                         $message = $this->insert_log_in_db($arg);
                         if ($message['error'] != "" || $message['success'] != "") {
                             $data['message'] = $message;
                         }
                         unset($arg);
                     }
                 }
             }
         } else {
             wp_die(__yop_poll('You do not have enough permission to import a Wp-poll'));
         }
     } else {
         wp_die(__yop_poll('You do not have enough permission to import a Wp-poll'));
     }
     $data['title'] = __yop_poll("Import Polls from Wp-Poll");
     $this->display('imports.html', $data);
 }