C:\xampp\htdocs\landing\wp-content\plugins\totalpoll\src\Migrations\Polls\TotalPoll\Extract.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php

namespace TotalPoll\Migrations\Polls\TotalPoll;
defined'ABSPATH' ) && exit();


use 
TotalPoll\Contracts\Migrations\Poll\Extract as ExtractContract;
use 
TotalPoll\Contracts\Migrations\Poll\Template\Poll;

/**
 * Extract Polls.
 * @package TotalPoll\Migrations\Polls\TotalPoll
 */
class Extract implements ExtractContract {
    
/**
     * Count polls.
     *
     * @return int
     */
    
public function getCount() {
        return 
count$this->getPollsIds() );
    }

    
/**
     * Get polls.
     *
     * @return array
     */
    
public function getPolls() {
        
$pollsIds       array_slice$this->getPollsIds(), 0);
        
$extractedPolls = [];

        if ( ! empty( 
$pollsIds ) ):

            foreach ( 
$pollsIds as $pollId ):
                
$poll['id']       = $pollId;
                
$poll['title']    = get_the_title$pollId );
                
$poll['question'] = get_post_meta$pollId'question'true );

                
$poll['choices'] = [];
                
$choicesCount    = (int) get_post_meta$pollId'choices'true );
                for ( 
$choicesStart 0$choicesStart $choicesCount$choicesStart ++ ):
                    
$poll['choices'][ $choicesStart ]            = [];
                    
$poll['choices'][ $choicesStart ]['content'] = get_post_meta$pollId"choice_{$choicesStart}_content"true );
                    
$poll['choices'][ $choicesStart ]['votes']   = get_post_meta$pollId"choice_{$choicesStart}_votes"true );
                endfor;

                
$poll['options'] = [
                    
'limitations'   => get_post_meta$pollId'settings_limitations'true ),
                    
'results'       => get_post_meta$pollId'settings_results'true ),
                    
'choices'       => get_post_meta$pollId'settings_choices'true ),
                    
'fields'        => get_post_meta$pollId'settings_fields'true ),
                    
'design'        => get_post_meta$pollId'settings_design'true ),
                    
'screens'       => get_post_meta$pollId'settings_screens'true ),
                    
'logs'          => get_post_meta$pollId'settings_logs'true ),
                    
'notifications' => get_post_meta$pollId'settings_notifications'true ),
                ];

                
$extractedPolls[] = $poll;
            endforeach;

        endif;

        return 
$extractedPolls;
    }

    
/**
     * Get options.
     *
     * @return array
     */
    
public function getOptions() {
        
$options              = (array) get_option'totalpoll_options', [] );
        
$options['recaptcha'] = [
            
'key'    => get_option'_tp_options_captcha_site_key' ),
            
'secret' => get_option'_tp_options_captcha_site_secret' ),
        ];

        return 
$options;
    }

    
/**
     * Get polls ids array.
     *
     * @return array
     */
    
private function getPollsIds() {
        return 
get_posts(
            [
                
'post_type'      => 'poll',
                
'posts_per_page' => - 1,
                
'meta_key'       => 'choices',
                
'fields'         => 'ids',
                
'post_status'    => 'any',
                
'meta_query'     => [
                    [
                        
'key'     => 'choices',
                        
'compare' => 'EXISTS',
                    ],
                    [
                        
'key'     => '_migrated',
                        
'value'   => 'migrated',
                        
'compare' => 'NOT EXISTS',
                    ],
                ],
            ]
        );
    }

    
/**
     * @param Poll $poll
     *
     * @return array
     */
    
public function getLogEntriesPoll $poll ) {
        
$extractedLogEntries = [];
        
$choicesMap          = [];
        
$logsCount           = (int) get_post_meta$poll->getId(), '_mp_logs'true );

        foreach ( 
$poll['choices'] as $choice ):
            
$choicesMap$choice['uid'] ] = $choice['label'];
        endforeach;

        if ( 
$logsCount ):
            for ( 
$startOffset 0$startOffset $logsCount$startOffset ++ ):
                
$logEntry get_post_meta'_mp_logs_' $startOffset );
                if ( 
$logEntry ):
                    
$choices = [];
                    foreach ( 
$logEntry['choices'] as $choice ):
                        
$choiceUid array_search$choice$choicesMap );
                        if ( 
$choiceUid ):
                            
$choices[] = $choiceUid;
                        endif;
                    endforeach;
                    
$extractedLogEntries[] = [
                        
'ip'        => $logEntry['ip'],
                        
'useragent' => $logEntry['useragent'],
                        
'user_id'   => empty( $logEntry['details']['user_id'] ) ? trimstr_replace'User ID:'''$logEntry['details']['user_id'] ) ),
                        
'poll_id'   => $poll->getNewId(),
                        
'choices'   => $choices,
                        
'action'    => 'vote',
                        
'status'    => $logEntry['status'] ? 'accepted' 'rejected',
                        
'details'   => empty( $logEntry['details'] ) ? [] : $logEntry['details'],
                        
'date'      => TotalPoll'datetime', [ $logEntry['time'] ] ),
                    ];
                endif;
            endfor;
        endif;

        return 
$extractedLogEntries;
    }

    
/**
     * @param Poll $poll
     *
     * @return array
     */
    
public function getSubmissionsPoll $poll ) {
        
$extractedSubmissions = [];
        
$submissionsCount     = (int) get_post_meta$poll->getId(), '_mp_submissions'true );

        if ( 
$submissionsCount ):
            for ( 
$startOffset 0$startOffset $submissionsCount$startOffset ++ ):
                
$submission get_post_meta'_mp_submissions_' $startOffset );
                if ( 
$submission ):
                    
$extractedSubmissions[] = [
                        
'poll_id' => $poll->getNewId(),
                        
'log_id'  => 0,
                        
'user_id' => 0,
                        
'date'    => TotalPoll'datetime', [ $submission['__submission_date'] ] ),
                        
'fields'  => $submission['fields'],
                        
'details' => [],
                    ];
                endif;
            endfor;
        endif;

        return 
$extractedSubmissions;
    }

    
/**
     * Get migrated polls ids.
     *
     * @return array
     */
    
public function getMigratedPollsIds() {
        return [];
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586