C:\xampp\htdocs\landing\wp-content\plugins\totalpoll\src\Admin\Ajax\Dashboard.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
<?php

namespace TotalPoll\Admin\Ajax;
defined'ABSPATH' ) && exit();


use 
TotalPollVendors\TotalCore\Contracts\Admin\Account;
use 
TotalPoll\Contracts\Entry\Repository as EntryRepository;
use 
TotalPoll\Contracts\Poll\Model;
use 
TotalPoll\Contracts\Poll\Repository as PollRepository;
use 
TotalPollVendors\TotalCore\Contracts\Admin\Activation;
use 
TotalPollVendors\TotalCore\Contracts\Http\Request;

/**
 * Class Dashboard
 * @package TotalPoll\Admin\Ajax
 * @since   1.0.0
 */
class Dashboard {
    
/**
     * @var Request $request
     */
    
protected $request;
    
/**
     * @var Activation $activation
     */
    
protected $activation;
    
/**
     * @var Account $account
     */
    
protected $account;
    
/**
     * @var PollRepository $pollRepository
     */
    
private $pollRepository;
    
/**
     * @var EntryRepository $entryRepository
     */
    
private $entryRepository;

    
/**
     * Dashboard constructor.
     *
     * @param Request         $request
     * @param Activation      $activation
     * @param Account         $account
     * @param PollRepository  $pollRepository
     * @param EntryRepository $entryRepository
     */
    
public function __constructRequest $requestActivation $activationAccount $accountPollRepository $pollRepositoryEntryRepository $entryRepository ) {
        
$this->request         $request;
        
$this->activation      $activation;
        
$this->account         $account;
        
$this->pollRepository  $pollRepository;
        
$this->entryRepository $entryRepository;
    }

    
/**
     * Activation AJAX endpoint.
     * @action-callback wp_ajax_totalpoll_dashboard_activate
     */
    
public function activate() {
        
        
$licenseKey   = (string) $this->request->request'key' );
        
$licenseEmail = (string) $this->request->request'email' );
        
$validity     $this->activation->checkLicenseValidity$licenseKey$licenseEmail );

        if ( empty( 
$licenseKey ) || empty( $licenseEmail ) || ! is_email$licenseEmail ) ):
            
wp_send_json_error__'Invalid key or email.''totalpoll' ) );
        endif;

        if ( ! 
is_wp_error$validity ) ):
            
$this->activation->setLicenseKey$licenseKey );
            
$this->activation->setLicenseEmail$licenseEmail );
            
$this->activation->setLicenseStatustrue );
            
wp_send_json_success'Activated' );
        endif;

        
wp_send_json_error$validity->get_error_message() );
        
    }

    
/**
     * Get polls AJAX endpoint.
     * @action-callback wp_ajax_totalpoll_dashboard_polls_overview
     */
    
public function polls() {
        
$polls array_map(
            function ( 
$poll ) {
                
/**
                 * Filters the poll object sent to dashboard.
                 *
                 * @param array $pollRepresentation The representation of a poll.
                 * @param Model $poll               Poll model object.
                 *
                 * @since 4.0.0
                 * @return array
                 */
                
return apply_filters(
                    
'totalpoll/filters/admin/dashboard/poll',
                    [
                        
'id'         => $poll->getId(),
                        
'title'      => $poll->getTitle(),
                        
'status'     => get_post_status$poll->getPollPost() ),
                        
'permalink'  => $poll->getPermalink(),
                        
'editLink'   => admin_url'post.php?post=' $poll->getId() . '&action=edit' ),
                        
'statistics' => [
                            
'votes'   => $poll->getTotalVotes(),
                            
'entries' => $this->entryRepository->count( [ 'conditions' => [ 'poll_id' => $poll->getId() ] ] ),
                        ],
                    ],
                    
$poll,
                    
$this
                
);
            },
            
$this->pollRepository->get( [ 'status' => 'any''perPage' => 100 ] )
        );

        
/**
         * Filters the polls list sent to dashboard.
         *
         * @param Model[] $polls Array of poll models.
         *
         * @since 4.0.0
         * @return array
         */
        
$polls apply_filters'totalpoll/filters/admin/dashboard/polls'$polls );

        
wp_send_json$polls );
    }

    
/**
     * TotalSuite Account AJAX endpoint.
     */
    
public function account() {
        
        
$accessToken = (string) $this->request->request'access_token' );

        if ( empty( 
$accessToken ) ):
            
wp_send_json_error__'Invalid access token.''totalpoll' ) );
        endif;

        
$accessTokenDetails $this->account->checkAccessToken$accessToken );

        if ( ! 
is_wp_error$accessTokenDetails ) ):
            
$this->account->set$accessTokenDetails );
            
wp_send_json_success$accessTokenDetails );
        endif;

        
wp_send_json_error$accessTokenDetails->get_error_message() );
        
    }
}
x

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