Crowdsignal Dashboard – Polls, Surveys & more - Version 0.8

Version Description

  • Bug fix: prevent some PHP define errors
  • Bug fix: send content-length header when using wp_remote_post()
Download this release

Release Info

Developer mdawaffe
Plugin Icon 128x128 Crowdsignal Dashboard – Polls, Surveys & more
Version 0.8
Comparing to
See all releases

Version 0.8

Files changed (7) hide show
  1. polldaddy-client.php +740 -0
  2. polldaddy-xml.php +432 -0
  3. polldaddy.css +240 -0
  4. polldaddy.gif +0 -0
  5. polldaddy.js +77 -0
  6. polldaddy.php +1076 -0
  7. readme.txt +65 -0
polldaddy-client.php ADDED
@@ -0,0 +1,740 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once dirname( __FILE__ ) . '/polldaddy-xml.php';
4
+
5
+ // TODO: polls->poll should always be an array and similar bad typing
6
+ class PollDaddy_Client {
7
+ var $polldaddy_url = 'http://api.polldaddy.com/handler/';
8
+ var $partnerGUID;
9
+ var $userCode;
10
+
11
+ var $request = null;
12
+ var $response = null;
13
+ var $request_xml = '';
14
+ var $response_xml = '';
15
+
16
+ var $errors = array();
17
+
18
+ function PollDaddy_Client( $partnerGUID = '', $userCode = null ) {
19
+ $this->partnerGUID = $partnerGUID;
20
+ $this->userCode = $userCode;
21
+ }
22
+
23
+ function send_request() {
24
+ $this->request_xml = "<?xml version='1.0' encoding='utf-8' ?>\n";
25
+ $this->request_xml .= $this->request->xml( 'all' );
26
+
27
+ if ( function_exists( 'wp_remote_post' ) ) {
28
+ $response = wp_remote_post( $this->polldaddy_url, array(
29
+ 'headers' => array( 'Content-Type' => 'text/xml; charset=utf-8', 'Content-Length' => strlen( $this->request_xml ) ),
30
+ 'user-agent' => 'PollDaddy PHP Client/0.1',
31
+ 'body' => $this->request_xml
32
+ ) );
33
+ if ( !$response || is_wp_error( $response ) ) {
34
+ $errors[-1] = "Can't connect";
35
+ return false;
36
+ }
37
+ $this->response_xml = wp_remote_retrieve_body( $response );
38
+ } else {
39
+ $parsed = parse_url( $this->polldaddy_url );
40
+
41
+ $fp = fsockopen(
42
+ $parsed['host'],
43
+ $parsed['scheme'] == 'ssl' || $parsed['scheme'] == 'https' && extension_loaded('openssl') ? 443 : 80,
44
+ $err_num,
45
+ $err_str,
46
+ 3
47
+ );
48
+
49
+ if ( !$fp ) {
50
+ $errors[-1] = "Can't connect";
51
+ return false;
52
+ }
53
+
54
+ if ( function_exists( 'stream_set_timeout' ) )
55
+ stream_set_timeout( $fp, 3 );
56
+
57
+ if ( !$path = $parsed['path'] . ( isset($parsed['query']) ? '?' . $parsed['query'] : '' ) )
58
+ $path = '/';
59
+
60
+ $request = "POST $path HTTP/1.0\r\n";
61
+ $request .= "Host: {$parsed['host']}\r\n";
62
+ $request .= "User-agent: PollDaddy PHP Client/0.1\r\n";
63
+ $request .= "Content-Type: text/xml; charset=utf-8\r\n";
64
+ $request .= 'Content-Length: ' . strlen( $this->request_xml ) . "\r\n";
65
+
66
+ fwrite( $fp, "$request\r\n$this->request_xml" );
67
+
68
+ $response = '';
69
+ while ( !feof( $fp ) )
70
+ $response .= fread( $fp, 4096 );
71
+ fclose( $fp );
72
+
73
+
74
+ if ( !$response ) {
75
+ $errors[-2] = 'No Data';
76
+ }
77
+
78
+ list($headers, $this->response_xml) = explode( "\r\n\r\n", $response, 2 );
79
+ }
80
+
81
+ $parser = new PollDaddy_XML_Parser( $this->response_xml );
82
+ $this->response =& $parser->objects[0];
83
+ if ( isset( $this->response->errors->error ) ) {
84
+ if ( !is_array( $this->response->errors->error ) )
85
+ $this->response->errors->error = array( $this->response->errors->error );
86
+ foreach ( $this->response->errors->error as $error )
87
+ $this->errors[$error->_id] = $error->___content;
88
+ }
89
+ }
90
+
91
+ function response_part( $pos ) {
92
+ if ( !isset( $this->response->demands->demand ) )
93
+ return false;
94
+
95
+ if ( is_array( $this->response->demands->demand ) ) {
96
+ if ( isset( $this->response->demands->demand[$pos] ) )
97
+ return $this->response->demands->demand[$pos];
98
+ return false;
99
+ }
100
+
101
+ if ( 0 === $pos )
102
+ return $this->response->demands->demand;
103
+
104
+ return false;
105
+ }
106
+
107
+ function add_request( $demand, $object = null ) {
108
+ if ( !is_a( $this->request, 'PollDaddy_Request' ) )
109
+ $this->request = new PollDaddy_Request( array(
110
+ 'userCode' => $this->userCode,
111
+ 'demands' => new PollDaddy_Demands( array( 'demand' => array() ) )
112
+ ), array(
113
+ 'partnerGUID' => $this->partnerGUID
114
+ ) );
115
+
116
+ if ( is_a( $object, 'Ghetto_XML_Object' ) )
117
+ $args = array( $object->___name => &$object );
118
+ elseif ( is_array( $object ) )
119
+ $args =& $object;
120
+ else
121
+ $args = null;
122
+
123
+ $this->request->demands->demand[] = new PollDaddy_Demand( $args, array( 'id' => $demand ) );
124
+
125
+ return count( $this->request->demands->demand ) - 1;
126
+ }
127
+
128
+ function reset() {
129
+ $this->request = null;
130
+ $this->response = null;
131
+ $this->request_xml = '';
132
+ $this->response_xml = '';
133
+ $this->errors = array();
134
+ }
135
+
136
+ /* pdInitiate: Initiate API "connection" */
137
+
138
+ /**
139
+ * @param string $Email
140
+ * @param string $Password
141
+ * @param int $partnerUserID
142
+ * @return string|false PollDaddy userCode or false on failure
143
+ */
144
+ function Initiate( $Email, $Password, $partnerUserID ) {
145
+ $this->request = new PollDaddy_Initiate( compact( 'Email', 'Password' ), array( 'partnerGUID' => $this->partnerGUID, 'partnerUserID' => $partnerUserID ) );
146
+ $this->send_request();
147
+ if ( isset( $this->response->userCode ) )
148
+ return $this->response->userCode;
149
+ return false;
150
+ }
151
+
152
+
153
+ /* pdAccess: API Access Control */
154
+
155
+ /**
156
+ * @param string $partnerUserID
157
+ * @return string|false PollDaddy userCode or false on failure
158
+ */
159
+ function GetUserCode( $partnerUserID ) {
160
+ $this->request = new PollDaddy_Access( array(
161
+ // 'demands' => new PollDaddy_Demands( array( 'demand' => new PollDaddy_Demand( null, array( 'id' => __FUNCTION__ ) ) ) )
162
+ 'demands' => new PollDaddy_Demands( array( 'demand' => new PollDaddy_Demand( null, array( 'id' => 'GetUserCode' ) ) ) )
163
+ ), array(
164
+ 'partnerGUID' => $this->partnerGUID,
165
+ 'partnerUserID' => $partnerUserID
166
+ ) );
167
+ $this->send_request();
168
+ if ( isset( $this->response->userCode ) )
169
+ return $this->response->userCode;
170
+ return false;
171
+ }
172
+
173
+ // Not Implemented
174
+ function RemoveUserCode() {
175
+ return false;
176
+ }
177
+
178
+ /**
179
+ * @see polldaddy_account()
180
+ * @param int $partnerUserID
181
+ * @param array $args polldaddy_account() args
182
+ * @return string|false PollDaddy userCode or false on failure
183
+ */
184
+ function CreateAccount( $partnerUserID, $args ) {
185
+ if ( !$account = polldaddy_account( $args ) )
186
+ return false;
187
+
188
+ $this->request = new PollDaddy_Access( array(
189
+ // 'demands' => new PollDaddy_Demands( array( 'demand' => new PollDaddy_Demand( compact( 'account' ), array( 'id' => __FUNCTION__ ) ) ) )
190
+ 'demands' => new PollDaddy_Demands( array( 'demand' => new PollDaddy_Demand( compact( 'account' ), array( 'id' => 'CreateAccount' ) ) ) )
191
+ ), array(
192
+ 'partnerGUID' => $this->partnerGUID,
193
+ 'partnerUserID' => $partnerUserID
194
+ ) );
195
+ $this->send_request();
196
+ if ( isset( $this->response->userCode ) )
197
+ return $this->response->userCode;
198
+ return false;
199
+ }
200
+
201
+
202
+ /* pdRequest: Request API Objects */
203
+
204
+ /* Accounts */
205
+ /**
206
+ * @return object|false PollDaddy Account or false on failure
207
+ */
208
+ function GetAccount() {
209
+ // $pos = $this->add_request( __FUNCTION__ );
210
+ $pos = $this->add_request( 'GetAccount' );
211
+ $this->send_request();
212
+ $r = $this->response_part( $pos );
213
+ if ( isset( $r->account ) && !is_null( $r->account->email ) )
214
+ return $r->account;
215
+ return false;
216
+ }
217
+
218
+ /**
219
+ * @see polldaddy_account()
220
+ * @param array $args polldaddy_account() args
221
+ * @return string|false PollDaddy userCode or false on failure
222
+ */
223
+ function UpdateAccount( $args ) {
224
+ if ( !$account = polldaddy_account( $args ) )
225
+ return false;
226
+
227
+ // $this->add_request( __FUNCTION__, $account );
228
+ $this->add_request( 'UpdateAccount', $account );
229
+ $this->send_request();
230
+ if ( isset( $this->response->userCode ) )
231
+ return $this->response->userCode;
232
+ return false;
233
+ }
234
+
235
+ /* Polls */
236
+ /**
237
+ * @return array|false Array of PollDaddy Polls or false on failure
238
+ */
239
+ function ListPolls( $start = 0, $end = 0 ) {
240
+ $start = (int) $start;
241
+ $end = (int) $end;
242
+ if ( !$start && !$end )
243
+ // $pos = $this->add_request( __FUNCTION__ );
244
+ $pos = $this->add_request( 'ListPolls' );
245
+ else
246
+ // $pos = $this->add_request( __FUNCTION__, new PollDaddy_List( null, compact( 'start', 'end' ) ) );
247
+ $pos = $this->add_request( 'ListPolls', new PollDaddy_List( null, compact( 'start', 'end' ) ) );
248
+ $this->send_request();
249
+ $r = $this->response_part( $pos );
250
+ if ( isset( $r->polls ) ) {
251
+ if ( isset( $r->polls->poll ) ) {
252
+ if ( !is_array( $r->polls->poll ) )
253
+ $r->polls->poll = array( $r->polls->poll );
254
+ }
255
+ return $r->polls;
256
+ }
257
+ return false;
258
+ }
259
+
260
+ /**
261
+ * @return array|false Array of PollDaddy Polls or false on failure
262
+ */
263
+ function listPollsByBlog( $start = 0, $end = 0, $id = null ) {
264
+ $start = (int) $start;
265
+ $end = (int) $end;
266
+ if ( !is_numeric( $id ) )
267
+ $id = $GLOBALS['blog_id'];
268
+
269
+ if ( !$start && !$end )
270
+ // $pos = $this->add_request( __FUNCTION__ );
271
+ $pos = $this->add_request( 'listPollsByBlog', compact( 'id' ) );
272
+ else
273
+ // $pos = $this->add_request( __FUNCTION__, new PollDaddy_List( null, compact( 'start', 'end' ) ) );
274
+ $pos = $this->add_request( 'listPollsByBlog', new PollDaddy_List( null, compact( 'start', 'end', 'id' ) ) );
275
+ $this->send_request();
276
+ $r = $this->response_part( $pos );
277
+ if ( isset( $r->polls ) ) {
278
+ if ( isset( $r->polls->poll ) ) {
279
+ if ( !is_array( $r->polls->poll ) )
280
+ $r->polls->poll = array( $r->polls->poll );
281
+ }
282
+ return $r->polls;
283
+ }
284
+ return false;
285
+ }
286
+
287
+ /**
288
+ * @param int $id PollDaddy Poll ID
289
+ * @return array|false PollDaddy Poll or false on failure
290
+ */
291
+ function GetPoll( $id ) {
292
+ if ( !$id = (int) $id )
293
+ return false;
294
+
295
+ // $pos = $this->add_request( __FUNCTION__, new PollDaddy_Poll( null, compact( 'id' ) ) );
296
+ $pos = $this->add_request( 'GetPoll', new PollDaddy_Poll( null, compact( 'id' ) ) );
297
+ $this->send_request();
298
+
299
+ $demand = $this->response_part( $pos );
300
+ if ( is_a( $demand, 'Ghetto_XML_Object' ) && isset( $demand->poll ) && !is_null( $demand->poll->question ) ) {
301
+ if ( isset( $demand->poll->answers->answer ) && !is_array( $demand->poll->answers->answer ) ) {
302
+ if ( $demand->poll->answers->answer )
303
+ $demand->poll->answers->answer = array( $demand->poll->answers->answer );
304
+ else
305
+ $demand->poll->answers->answer = array();
306
+ }
307
+ return $demand->poll;
308
+ }
309
+ return false;
310
+ }
311
+
312
+ /**
313
+ * @param int $id PollDaddy Poll ID
314
+ * @return bool success
315
+ */
316
+ function DeletePoll( $id ) {
317
+ if ( !$id = (int) $id )
318
+ return false;
319
+
320
+ // $pos = $this->add_request( __FUNCTION__, new PollDaddy_Poll( null, compact( 'id' ) ) );
321
+ $pos = $this->add_request( 'DeletePoll', new PollDaddy_Poll( null, compact( 'id' ) ) );
322
+ $this->send_request();
323
+
324
+ return empty( $this->errors );
325
+ }
326
+
327
+ /**
328
+ * @see polldaddy_poll()
329
+ * @param array $args polldaddy_poll() args
330
+ * @return array|false PollDaddy Poll or false on failure
331
+ */
332
+ function CreatePoll( $args = null ) {
333
+ if ( !$poll = polldaddy_poll( $args ) )
334
+ return false;
335
+ // $pos = $this->add_request( __FUNCTION__, $poll );
336
+ $pos = $this->add_request( 'CreatePoll', $poll );
337
+ $this->send_request();
338
+ if ( !$demand = $this->response_part( $pos ) )
339
+ return $demand;
340
+ if ( !isset( $demand->poll ) )
341
+ return false;
342
+ return $demand->poll;
343
+
344
+ }
345
+
346
+ /**
347
+ * @see polldaddy_poll()
348
+ * @param int $id PollDaddy Poll ID
349
+ * @param array $args polldaddy_poll() args
350
+ * @return array|false PollDaddy Poll or false on failure
351
+ */
352
+ function UpdatePoll( $id, $args = null ) {
353
+ if ( !$id = (int) $id )
354
+ return false;
355
+
356
+ if ( !$poll = polldaddy_poll( $args, $id ) )
357
+ return false;
358
+
359
+ // $pos = $this->add_request( __FUNCTION__, $poll );
360
+ $pos = $this->add_request( 'UpdatePoll', $poll );
361
+ $this->send_request();
362
+ return $this->response_part( $pos );
363
+ }
364
+
365
+ function SearchPolls( $search ) {
366
+ // $pos = $this->add_request( __FUNCTION__, compact( 'search' ) );
367
+ $pos = $this->add_request( 'SearchPolls', compact( 'search' ) );
368
+ $this->send_request();
369
+
370
+ $r = $this->response_part( $pos );
371
+ if ( isset( $r->search ) ) {
372
+ if ( isset( $r->search->poll ) ) {
373
+ if ( is_array( $r->search->poll ) )
374
+ return $r->search->poll;
375
+ else
376
+ return array( $r->search->poll );
377
+ }
378
+ return array();
379
+ }
380
+ return false;
381
+ }
382
+
383
+ // Not Implemented
384
+ function ListSurveys() {
385
+ return false;
386
+ }
387
+
388
+ /* Poll Results */
389
+ /**
390
+ * @param int $id PollDaddy Poll ID
391
+ * @return object|false PollDaddy Result or false on failure
392
+ */
393
+ function GetPollResults( $id ) {
394
+ if ( !$id = (int) $id )
395
+ return false;
396
+
397
+ // $pos = $this->add_request( __FUNCTION__, new PollDaddy_Poll_Result( null, compact( 'id' ) ) );
398
+ $pos = $this->add_request( 'GetPollResults', new PollDaddy_Poll_Result( null, compact( 'id' ) ) );
399
+ $this->send_request();
400
+
401
+ $demand = $this->response_part( $pos );
402
+
403
+ if ( is_a( $demand, 'Ghetto_XML_Object' ) && isset( $demand->result ) ) {
404
+ $answers = $others = array();
405
+ if ( isset( $demand->result->answers ) ) {
406
+ if ( isset( $demand->result->answers->answer ) ) {
407
+ if ( is_array( $demand->result->answers->answer ) )
408
+ $answers = $demand->result->answers->answer;
409
+ else
410
+ $answers = array( $demand->result->answers->answer );
411
+ }
412
+ }
413
+ if ( isset( $demand->result->otherAnswers ) ) {
414
+ if ( isset( $demand->result->otherAnswers->otherAnswer ) ) {
415
+ if ( is_array( $demand->result->otherAnswers->otherAnswer ) )
416
+ $others = $demand->result->otherAnswers->otherAnswer;
417
+ else
418
+ $others = array( $demand->result->otherAnswers->othernswer );
419
+ }
420
+ }
421
+ return (object) compact( 'answers', 'others' );
422
+ }
423
+ return false;
424
+ }
425
+
426
+ /**
427
+ * @param int $id PollDaddy Poll ID
428
+ * @return object|false PollDaddy Result or false on failure
429
+ */
430
+ function ResetPollResults( $id ) {
431
+ if ( !$id = (int) $id )
432
+ return false;
433
+
434
+ // $pos = $this->add_request( __FUNCTION__, new PollDaddy_Poll_Result( null, compact( 'id' ) ) );
435
+ $pos = $this->add_request( 'ResetPollResults', new PollDaddy_Poll_Result( null, compact( 'id' ) ) );
436
+ $this->send_request();
437
+
438
+ return empty( $this->errors );
439
+ }
440
+
441
+ /* Poll Comments */
442
+ // Not Implemented
443
+ function GetPollComments() {
444
+ return false;
445
+ }
446
+
447
+ // Not Implemented
448
+ function ModerateComment() {
449
+ return false;
450
+ }
451
+
452
+ /* Extensions */
453
+
454
+ // Not Implemented
455
+ function GetAllExtensions() {
456
+ return false;
457
+ }
458
+
459
+ // Not Implemented
460
+ function GetLanguages() {
461
+ return false;
462
+ }
463
+
464
+ /* Language Packs */
465
+ // Not Implemented
466
+ function GetPacks() {
467
+ return false;
468
+ }
469
+
470
+ // Not Implemented
471
+ function GetPack() {
472
+ return false;
473
+ }
474
+
475
+ // Not Implemented
476
+ function DeletePack() {
477
+ return false;
478
+ }
479
+
480
+ // Not Implemented
481
+ function CreatePack() {
482
+ return false;
483
+ }
484
+
485
+ // Not Implemented
486
+ function UpdatePack() {
487
+ return false;
488
+ }
489
+
490
+ /* Styles */
491
+ // Not Implemented
492
+ function GetStyles() {
493
+ return false;
494
+ }
495
+
496
+ // Not Implemented
497
+ function GetStyle() {
498
+ return false;
499
+ }
500
+
501
+ // Not Implemented
502
+ function DeleteStyle() {
503
+ return false;
504
+ }
505
+
506
+ // Not Implemented
507
+ function CreateStyle() {
508
+ return false;
509
+ }
510
+
511
+ // Not Implemented
512
+ function UpdateStyle() {
513
+ return false;
514
+ }
515
+
516
+ /* Folders */
517
+ // Not Implemented
518
+ function GetFolders() {
519
+ return false;
520
+ }
521
+
522
+ /* Account Activities */
523
+ // Not Implemented
524
+ function GetActivity() {
525
+ return false;
526
+ }
527
+
528
+ // Not Implemented
529
+ function SetActivity() {
530
+ return false;
531
+ }
532
+ }
533
+
534
+ /**
535
+ * @param string $partnerUserID
536
+ * @param string $userName
537
+ * @param string $email
538
+ * @param string $password
539
+ * @param string $firstName
540
+ * @param string $lastName
541
+ * @param string $countryCode
542
+ * @param string $gender
543
+ * @param string $yearOfBirth
544
+ * @param string $websiteURL
545
+ * @param string $avatarURL
546
+ * @param string $bio
547
+ */
548
+ function &polldaddy_account( $args = null ) {
549
+ $false = false;
550
+ if ( is_a( $args, 'PollDaddy_Account' ) )
551
+ return $args;
552
+
553
+ $defaults = _polldaddy_account_defaults();
554
+
555
+ $args = wp_parse_args( $args, $defaults );
556
+
557
+ foreach ( array( 'userName', 'email' ) as $required )
558
+ if ( !is_string( $args[$required] ) || !$args[$required] )
559
+ return $false;
560
+
561
+ return new PollDaddy_Account( $args );
562
+ }
563
+
564
+ function _polldaddy_account_defaults() {
565
+ return array(
566
+ 'userName' => false,
567
+ 'email' => false,
568
+ 'password' => false,
569
+ 'firstName' => false,
570
+ 'lastName' => false,
571
+ 'countryCode' => 'nn',
572
+ 'gender' => 'male',
573
+ 'yearOfBirth' => 1901,
574
+ 'websiteURL' => false,
575
+ 'avatarURL' => false,
576
+ 'bio' => false
577
+ );
578
+ }
579
+
580
+ function &polldaddy_poll( $args = null, $id = null, $_require_data = true ) {
581
+ $false = false;
582
+ if ( is_a( $args, 'PollDaddy_Poll' ) ) {
583
+ if ( is_null( $id ) )
584
+ return $args;
585
+ if ( !$id = (int) $id )
586
+ return $false;
587
+ $args->_id = $id;
588
+ return $args;
589
+ }
590
+
591
+ $defaults = _polldaddy_poll_defaults();
592
+
593
+ if ( !is_null( $args ) ) {
594
+ $args = wp_parse_args( $args, $defaults );
595
+ $args['parentID'] = (int) $args['parentID'];
596
+
597
+ if ( $_require_data ) {
598
+ if ( !is_string( $args['question'] ) || !$args['question'] )
599
+ return $false;
600
+
601
+ if ( !is_array($args['answers']) || !$args['answers'] )
602
+ return $false;
603
+ }
604
+
605
+ foreach ( array( 'multipleChoice', 'randomiseAnswers', 'otherAnswer', 'makePublic', 'closePoll', 'closePollNow' ) as $bool ) {
606
+ if ( 'no' !== $args[$bool] && 'yes' !== $args[$bool] )
607
+ $args[$bool] = $defaults[$bool];
608
+ }
609
+
610
+ foreach ( array( 'styleID', 'packID', 'folderID', 'languageID' ) as $int )
611
+ if ( !is_numeric( $args[$int] ) )
612
+ $args[$bool] = $defaults[$int];
613
+
614
+ if ( !in_array( $args['resultsType'], array( 'show', 'percent', 'hide' ) ) )
615
+ $args['resultsType'] = $defaults['resultsType'];
616
+
617
+ if ( !in_array( $args['blockRepeatVotersType'], array( 'off', 'cookie', 'cookieIP' ) ) )
618
+ $args['blockRepeatVotersType'] = $defaults['blockRepeatVotersType'];
619
+
620
+ if ( !in_array( $args['comments'], array( 'off', 'allow', 'moderate' ) ) )
621
+ $args['comments'] = $defaults['comments'];
622
+
623
+ if ( is_numeric( $args['closeDate'] ) )
624
+ $args['closeDate'] = gmdate( 'Y-m-d\TH:i:s', $args['closeDate'] ) . 'Z';
625
+ if ( !$args['closeDate'] )
626
+ $args['closeDate'] = gmdate( 'Y-m-d\TH:i:s' ) . 'Z';
627
+
628
+ $args['answers'] = new PollDaddy_Poll_Answers( array( 'answer' => $args['answers'] ) );
629
+
630
+ if ( is_null( $id ) )
631
+ $id = $args['id'];
632
+ unset( $args['id'] );
633
+ }
634
+
635
+ return new PollDaddy_Poll( $args, compact( 'id' ) );
636
+ }
637
+
638
+ function _polldaddy_poll_defaults() {
639
+ return array(
640
+ 'id' => null,
641
+ 'question' => false,
642
+ 'multipleChoice' => 'no',
643
+ 'randomiseAnswers' => 'no',
644
+ 'otherAnswer' => 'no',
645
+ 'resultsType' => 'show',
646
+ 'blockRepeatVotersType' => 'cookie',
647
+ 'comments' => 'off',
648
+ 'makePublic' => 'yes',
649
+ 'closePoll' => 'no',
650
+ 'closePollNow' => 'no',
651
+ 'closeDate' => null,
652
+ 'styleID' => 0,
653
+ 'packID' => 0,
654
+ 'folderID' => 0,
655
+ 'languageID' => _polldaddy_poll_default_language_id(),
656
+ 'parentID' => (int) $GLOBALS['blog_id'],
657
+ 'answers' => array()
658
+ );
659
+ }
660
+
661
+ if ( !function_exists( '_polldaddy_poll_default_language_id' ) ) :
662
+ function _polldaddy_poll_default_language_id() {
663
+ return 1;
664
+ }
665
+ endif;
666
+
667
+ function &polldaddy_poll_answer( $answer, $id = null ) {
668
+ if ( !is_string( $answer ) || !$answer )
669
+ return false;
670
+
671
+ return new PollDaddy_Poll_Answer( $answer, compact( 'id' ) );
672
+ }
673
+
674
+ if ( !function_exists( 'wp_parse_args' ) ) :
675
+ /**
676
+ * Merge user defined arguments into defaults array.
677
+ *
678
+ * This function is used throughout WordPress to allow for both string or array
679
+ * to be merged into another array.
680
+ *
681
+ * @since 2.2.0
682
+ *
683
+ * @param string|array $args Value to merge with $defaults
684
+ * @param array $defaults Array that serves as the defaults.
685
+ * @return array Merged user defined values with defaults.
686
+ */
687
+ function wp_parse_args( $args, $defaults = '' ) {
688
+ if ( is_object( $args ) )
689
+ $r = get_object_vars( $args );
690
+ elseif ( is_array( $args ) )
691
+ $r =& $args;
692
+ else
693
+ wp_parse_str( $args, $r );
694
+
695
+ if ( is_array( $defaults ) )
696
+ return array_merge( $defaults, $r );
697
+ return $r;
698
+ }
699
+ endif;
700
+
701
+ if ( !function_exists( 'wp_parse_str' ) ) :
702
+ /**
703
+ * Parses a string into variables to be stored in an array.
704
+ *
705
+ * Uses {@link http://www.php.net/parse_str parse_str()} and stripslashes if
706
+ * {@link http://www.php.net/magic_quotes magic_quotes_gpc} is on.
707
+ *
708
+ * @since 2.2.1
709
+ * @uses apply_filters() for the 'wp_parse_str' filter.
710
+ *
711
+ * @param string $string The string to be parsed.
712
+ * @param array $array Variables will be stored in this array.
713
+ */
714
+ function wp_parse_str( $string, &$array ) {
715
+ parse_str( $string, $array );
716
+ if ( get_magic_quotes_gpc() )
717
+ $array = stripslashes_deep( $array );
718
+ return $array;
719
+
720
+ $array = apply_filters( 'wp_parse_str', $array );
721
+ }
722
+ endif;
723
+
724
+ if ( !function_exists( 'stripslashes_deep' ) ) :
725
+ /**
726
+ * Navigates through an array and removes slashes from the values.
727
+ *
728
+ * If an array is passed, the array_map() function causes a callback to pass the
729
+ * value back to the function. The slashes from this value will removed.
730
+ *
731
+ * @since 2.0.0
732
+ *
733
+ * @param array|string $value The array or string to be striped.
734
+ * @return array|string Stripped array (or string in the callback).
735
+ */
736
+ function stripslashes_deep($value) {
737
+ $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
738
+ return $value;
739
+ }
740
+ endif;
polldaddy-xml.php ADDED
@@ -0,0 +1,432 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ghetto_XML_Object {
4
+ function Ghetto_XML_Object( $args = null, $attributes = null ) {
5
+ if ( get_object_vars( $this ) )
6
+ $this->___restrict = true;
7
+ else
8
+ $this->___restrict = false;
9
+
10
+ if ( !is_null( $args ) )
11
+ $this->set_args( $args );
12
+ if ( !is_array( $attributes ) )
13
+ return false;
14
+
15
+ $atts = array();
16
+ foreach ( $attributes as $key => $value )
17
+ $atts["_$key"] = $value;
18
+
19
+ $this->set_args( $atts );
20
+ }
21
+
22
+ function xml( $prepend_ns = true, $pad = 0 ) {
23
+ $x = '';
24
+ $atts = get_object_vars( $this );
25
+
26
+ $ns = $atts['___ns'];
27
+ if ( $prepend_ns )
28
+ $name = "$ns:{$atts['___name']}";
29
+ else
30
+ $name = $atts['___name'];
31
+
32
+ $_prepend_ns = $prepend_ns;
33
+
34
+ $prepend_ns = 'all' === $prepend_ns;
35
+
36
+ if ( !$cdata = $atts['___cdata'] )
37
+ $cdata = array();
38
+
39
+ $x = "<$name";
40
+ if ( $atts['___content'] ) {
41
+ $inner = in_array( '___content', $cdata ) ? '<![CDATA[' . $atts['___content'] . ']]>' : $atts['___content'];
42
+ $empty = false;
43
+ } else {
44
+ $inner = "\n";
45
+ $empty = true;
46
+ }
47
+
48
+ unset($atts['___ns'], $atts['___name'], $atts['___content'], $atts['___ns_full'], $atts['___restrict'], $atts['___cdata']);
49
+
50
+ $_pad = str_repeat( "\t", $pad + 1 );
51
+
52
+ foreach ( $atts as $key => $value ) {
53
+ if ( is_null( $value ) )
54
+ continue;
55
+ if ( '_' == $key[0] ) {
56
+ $key = substr( $key, 1 );
57
+ $x .= " $key='$value'";
58
+ continue;
59
+ }
60
+
61
+ $_key = $key;
62
+ if ( $prepend_ns )
63
+ $key = "$ns:$key";
64
+
65
+ $empty = false;
66
+ if ( false === $value ) {
67
+ $inner .= "$_pad<$key />\n";
68
+ } elseif ( is_array( $value ) ) {
69
+ foreach ( $value as $array_value ) {
70
+ if ( is_a( $array_value, 'Ghetto_XML_Object' ) )
71
+ $inner .= $_pad . $array_value->xml( $_prepend_ns, $pad + 1 ) . "\n";
72
+ else
73
+ $inner .= in_array( $_key, $cdata ) ? "$_pad<$key>" . '<![CDATA[' . $array_value . ']]>' . "</$key>\n" : "$_pad<$key>$array_value</$key>\n";
74
+ }
75
+ } else {
76
+ if ( is_a( $value, 'Ghetto_XML_Object' ) )
77
+ $inner .= $_pad . $value->xml( $_prepend_ns, $pad + 1 ) . "\n";
78
+ else {
79
+ $inner .= in_array( $_key, $cdata ) ? "$_pad<$key>" . '<![CDATA[' . $value . ']]>' . "</$key>\n" : "$_pad<$key>$value</$key>\n";
80
+ }
81
+ }
82
+ }
83
+ if ( $empty )
84
+ return $x . ' />';
85
+ if ( "\n" == substr( $inner, -1 ) )
86
+ $inner .= str_repeat( "\t", $pad );
87
+
88
+ return $x . ">$inner</$name>";
89
+ }
90
+
91
+ function set_args( $array ) {
92
+ if ( is_scalar( $array ) ) {
93
+ $this->___content = $array;
94
+ return;
95
+ }
96
+
97
+ $atts = get_object_vars( $this );
98
+ foreach ( $array as $key => $value ) {
99
+ if ( 0 === strpos( $key, $this->___ns_full ) )
100
+ $key = substr( $key, strlen( $this->___ns_full ) + 1 );
101
+ if ( is_null( $value ) || ( $this->___restrict && !array_key_exists( $key, $atts ) ) )
102
+ continue;
103
+
104
+ $this->$key = $value;
105
+ }
106
+ }
107
+ }
108
+
109
+ class PollDaddy_XML_Object extends Ghetto_XML_Object {
110
+ var $___ns = 'pd';
111
+ var $___ns_full = 'http://api.polldaddy.com/pdapi.xsd';
112
+ }
113
+
114
+ class PollDaddy_XML_Root extends PollDaddy_XML_Object {
115
+ function xml( $prepend_ns = true, $pad = 0 ) {
116
+ $xml = parent::xml( $prepend_ns, $pad );
117
+ if ( !$pad ) {
118
+ $pos = strpos( $xml, '>' );
119
+ $xml = substr_replace( $xml, " xmlns:$this->___ns='$this->___ns_full'", $pos, 0 );
120
+ }
121
+ return $xml;
122
+ }
123
+ }
124
+
125
+ class PollDaddy_Access extends PollDaddy_XML_Root {
126
+ var $___name = 'pdAccess';
127
+
128
+ var $_partnerGUID;
129
+ var $_partnerUserID;
130
+
131
+ var $demands;
132
+ }
133
+
134
+ class PollDaddy_Initiate extends PollDaddy_XML_Root {
135
+ var $___cdata = array( 'Email', 'Password' );
136
+ var $___name = 'pdInitiate';
137
+
138
+ var $_partnerGUID;
139
+ var $_partnerUserID;
140
+
141
+ var $Email;
142
+ var $Password;
143
+ }
144
+
145
+ class PollDaddy_Request extends PollDaddy_XML_Root {
146
+ var $___name = 'pdRequest';
147
+
148
+ var $_partnerGUID;
149
+
150
+ var $userCode;
151
+ var $demands;
152
+ }
153
+
154
+ class PollDaddy_Response extends PollDaddy_XML_Root {
155
+ var $___name = 'pdResponse';
156
+
157
+ var $_partnerGUID;
158
+
159
+ var $userCode;
160
+ var $demands;
161
+ var $errors;
162
+ }
163
+
164
+ class PollDaddy_Errors extends PollDaddy_XML_Object {
165
+ var $___name = 'errors';
166
+
167
+ var $error;
168
+ }
169
+
170
+ class PollDaddy_Error extends PollDaddy_XML_Object {
171
+ var $___name = 'error';
172
+
173
+ var $___content;
174
+
175
+ var $_id;
176
+ }
177
+
178
+ class PollDaddy_Demands extends PollDaddy_XML_Object {
179
+ var $___name = 'demands';
180
+
181
+ var $demand;
182
+ }
183
+
184
+ class PollDaddy_Demand extends PollDaddy_XML_Object {
185
+ var $___name = 'demand';
186
+
187
+ var $_id;
188
+
189
+ var $account;
190
+ var $poll;
191
+ var $polls;
192
+ var $list;
193
+ var $search;
194
+ var $result;
195
+ }
196
+
197
+ class PollDaddy_Account extends PollDaddy_XML_Object {
198
+ var $___cdata = array( 'userName', 'password', 'firstName', 'lastName', 'websiteURL', 'avatarURL', 'bio' );
199
+ var $___name = 'account';
200
+
201
+ var $userName;
202
+ var $email;
203
+ var $password;
204
+ var $firstName;
205
+ var $lastName;
206
+ var $countryCode;
207
+ var $gender;
208
+ var $yearOfBirth;
209
+ var $websiteURL;
210
+ var $avatarURL;
211
+ var $bio;
212
+ }
213
+
214
+ class PollDaddy_List extends PollDaddy_XML_Object {
215
+ var $___name = 'list';
216
+
217
+ var $_start;
218
+ var $_end;
219
+ var $_id;
220
+ }
221
+
222
+ class PollDaddy_Polls extends PollDaddy_XML_Object {
223
+ var $___name = 'polls';
224
+
225
+ var $_total;
226
+
227
+ var $poll;
228
+ }
229
+
230
+ class PollDaddy_Search extends PollDaddy_XML_Object {
231
+ var $___cdata = array( '___content' );
232
+ var $___name = 'search';
233
+
234
+ var $___content;
235
+
236
+ var $poll;
237
+ }
238
+
239
+ class PollDaddy_Poll extends PollDaddy_XML_Object {
240
+ var $___cdata = array( '___content', 'question' );
241
+ var $___name = 'poll';
242
+
243
+ var $___content;
244
+
245
+ var $_id;
246
+ var $_created;
247
+ var $_responses;
248
+ var $_folderID;
249
+ var $_owner;
250
+
251
+ var $question;
252
+ var $multipleChoice;
253
+ var $randomiseAnswers;
254
+ var $otherAnswer;
255
+ var $resultsType;
256
+ var $blockRepeatVotersType;
257
+ var $comments;
258
+ var $makePublic;
259
+ var $closePoll;
260
+ var $closePollNow;
261
+ var $closeDate;
262
+ var $styleID;
263
+ var $packID;
264
+ var $folderID;
265
+ var $languageID;
266
+ var $parentID;
267
+ var $answers;
268
+
269
+ var $rank;
270
+ var $url;
271
+ }
272
+
273
+ class PollDaddy_Poll_Answers extends PollDaddy_XML_Object {
274
+ var $___name = 'answers';
275
+
276
+ var $answer;
277
+ }
278
+
279
+ class PollDaddy_Poll_Answer extends PollDaddy_XML_Object {
280
+ var $___cdata = array( '___content' );
281
+ var $___name = 'answer';
282
+
283
+ var $___content;
284
+
285
+ var $_id;
286
+ var $_total;
287
+ var $_percent;
288
+ }
289
+
290
+ class PollDaddy_Poll_Result extends PollDaddy_XML_Object {
291
+ var $___name = 'result';
292
+
293
+ var $_id;
294
+
295
+ var $answers;
296
+ var $otherAnswers;
297
+ }
298
+
299
+ class PollDaddy_Other_Answers extends PollDaddy_XML_Object {
300
+ var $___name = 'otherAnswers';
301
+
302
+ var $otherAnswer;
303
+ }
304
+
305
+ class PollDaddy_XML_Parser {
306
+ var $parser;
307
+ var $polldaddy_objects = array(
308
+ 'http://api.polldaddy.com/pdapi.xsd:pdAccess' => 'PollDaddy_Access',
309
+ 'http://api.polldaddy.com/pdapi.xsd:pdInitiate' => 'PollDaddy_Initiate',
310
+ 'http://api.polldaddy.com/pdapi.xsd:pdRequest' => 'PollDaddy_Request',
311
+ 'http://api.polldaddy.com/pdapi.xsd:pdResponse' => 'PollDaddy_Response',
312
+ 'http://api.polldaddy.com/pdapi.xsd:errors' => 'PollDaddy_Errors',
313
+ 'http://api.polldaddy.com/pdapi.xsd:error' => 'PollDaddy_Error',
314
+ 'http://api.polldaddy.com/pdapi.xsd:demands' => 'PollDaddy_Demands',
315
+ 'http://api.polldaddy.com/pdapi.xsd:demand' => 'PollDaddy_Demand',
316
+ 'http://api.polldaddy.com/pdapi.xsd:account' => 'PollDaddy_Account',
317
+ 'http://api.polldaddy.com/pdapi.xsd:list' => 'PollDaddy_List',
318
+ 'http://api.polldaddy.com/pdapi.xsd:polls' => 'PollDaddy_Polls',
319
+ 'http://api.polldaddy.com/pdapi.xsd:search' => 'PollDaddy_Search',
320
+ 'http://api.polldaddy.com/pdapi.xsd:poll' => 'PollDaddy_Poll',
321
+ 'http://api.polldaddy.com/pdapi.xsd:answers' => 'PollDaddy_Poll_Answers',
322
+ 'http://api.polldaddy.com/pdapi.xsd:answer' => 'PollDaddy_Poll_Answer',
323
+ 'http://api.polldaddy.com/pdapi.xsd:otherAnswers' => 'PollDaddy_Other_Answers',
324
+ 'http://api.polldaddy.com/pdapi.xsd:result' => 'PollDaddy_Poll_Result'
325
+ );
326
+
327
+ var $object_stack = array();
328
+ var $object_pos = null;
329
+
330
+ var $objects = array();
331
+
332
+ function PollDaddy_XML_Parser( $xml = null ) {
333
+ if ( is_null( $xml ) )
334
+ return;
335
+
336
+ return $this->parse( $xml );
337
+ }
338
+
339
+ function parse( $xml ) {
340
+ $this->parser = xml_parser_create_ns( 'UTF-8' );
341
+ xml_set_object( $this->parser, $this );
342
+ xml_set_element_handler( $this->parser, 'tag_open', 'tag_close' );
343
+ xml_set_character_data_handler( $this->parser, 'text' );
344
+ xml_parser_set_option( $this->parser, XML_OPTION_CASE_FOLDING, 0 );
345
+ xml_parser_set_option( $this->parser, XML_OPTION_SKIP_WHITE, 1 );
346
+
347
+ xml_parse( $this->parser, $xml );
348
+ xml_parser_free( $this->parser );
349
+ return $this->objects;
350
+ }
351
+
352
+ function tag_open( &$parser, $tag, $attributes ) {
353
+ $object_pos = $this->object_pos;
354
+ if ( $this->object_stack ) {
355
+ if ( isset( $this->object_stack[$object_pos]['args'][$tag] ) ) {
356
+ if ( is_array( $this->object_stack[$object_pos]['args'][$tag] ) ) {
357
+ $this->object_stack[$object_pos]['args'][$tag][] = false;
358
+ } else {
359
+ $this->object_stack[$object_pos]['args'][$tag] = array( $this->object_stack[$object_pos]['args'][$tag], false );
360
+ }
361
+ end( $this->object_stack[$object_pos]['args'][$tag] );
362
+ $this->object_stack[$object_pos]['args_tag_pos'] = key( $this->object_stack[$object_pos]['args'][$tag] );
363
+ } else {
364
+ $this->object_stack[$object_pos]['args'][$tag] = false;
365
+ }
366
+ $this->object_stack[$object_pos]['args_tag'] = $tag;
367
+ }
368
+
369
+ if ( isset( $this->polldaddy_objects[$tag] ) ) {
370
+ $this->object_stack[] = array(
371
+ 'tag' => $tag,
372
+ 'atts' => $attributes,
373
+ 'args' => array(),
374
+ 'parent' => $this->object_pos,
375
+ 'args_tag' => null,
376
+ 'args_tag_pos' => null
377
+ );
378
+ end( $this->object_stack );
379
+ $this->object_pos = key( $this->object_stack );
380
+ }
381
+ }
382
+
383
+ function text( &$parser, $text ) {
384
+ if ( !$this->object_stack )
385
+ return;
386
+
387
+ $text = trim( $text );
388
+ if ( !strlen( $text ) )
389
+ return;
390
+
391
+ if ( $this->object_stack[$this->object_pos]['args_tag_pos'] ) {
392
+ if ( isset($this->object_stack[$this->object_pos]['args'][$this->object_stack[$this->object_pos]['args_tag']][$this->object_stack[$this->object_pos]['args_tag_pos']]) )
393
+ $this->object_stack[$this->object_pos]['args'][$this->object_stack[$this->object_pos]['args_tag']][$this->object_stack[$this->object_pos]['args_tag_pos']] .= $text;
394
+ else
395
+ $this->object_stack[$this->object_pos]['args'][$this->object_stack[$this->object_pos]['args_tag']][$this->object_stack[$this->object_pos]['args_tag_pos']] = $text;
396
+ } elseif ( $this->object_stack[$this->object_pos]['args_tag'] ) {
397
+ if ( isset($this->object_stack[$this->object_pos]['args'][$this->object_stack[$this->object_pos]['args_tag']]) )
398
+ $this->object_stack[$this->object_pos]['args'][$this->object_stack[$this->object_pos]['args_tag']] .= $text;
399
+ else
400
+ $this->object_stack[$this->object_pos]['args'][$this->object_stack[$this->object_pos]['args_tag']] = $text;
401
+ } else {
402
+ if ( isset($this->object_stack[$this->object_pos]['args']['___content']) )
403
+ $this->object_stack[$this->object_pos]['args']['___content'] .= $text;
404
+ else
405
+ $this->object_stack[$this->object_pos]['args']['___content'] = $text;
406
+ }
407
+ }
408
+
409
+ function tag_close( &$parser, $tag ) {
410
+ if ( isset( $this->polldaddy_objects[$tag] ) ) {
411
+ if ( $tag !== $this->object_stack[$this->object_pos]['tag'] )
412
+ die( 'damn' );
413
+
414
+ $new = $this->polldaddy_objects[$tag];
415
+ $new_object =& new $new( $this->object_stack[$this->object_pos]['args'], $this->object_stack[$this->object_pos]['atts'] );
416
+
417
+ if ( is_numeric( $this->object_stack[$this->object_pos]['parent'] ) ) {
418
+ $this->object_pos = $this->object_stack[$this->object_pos]['parent'];
419
+ if ( $this->object_stack[$this->object_pos]['args_tag_pos'] ) {
420
+ $this->object_stack[$this->object_pos]['args'][$this->object_stack[$this->object_pos]['args_tag']][$this->object_stack[$this->object_pos]['args_tag_pos']] =& $new_object;
421
+ } elseif ( $this->object_stack[$this->object_pos]['args_tag'] ) {
422
+ $this->object_stack[$this->object_pos]['args'][$this->object_stack[$this->object_pos]['args_tag']] =& $new_object;
423
+ }
424
+ } else {
425
+ $this->object_pos = null;
426
+ $this->objects[] =& $new_object;
427
+ }
428
+
429
+ array_pop( $this->object_stack );
430
+ }
431
+ }
432
+ }
polldaddy.css ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ html, body {
2
+ height: auto !important;
3
+ }
4
+
5
+ body.poll-preview-iframe #sidemenu,
6
+ body.poll-preview-iframe #submenu,
7
+ body.poll-preview-iframe #wpcombar,
8
+ body.poll-preview-iframe #wphead,
9
+ body.poll-preview-iframe #gears-info-box,
10
+ body.poll-preview-iframe #user_info,
11
+ body.poll-preview-iframe #dashmenu,
12
+ body.poll-preview-iframe #adminmenu,
13
+ body.poll-preview-iframe #sidemenu-bg,
14
+ body.poll-preview-iframe #footer,
15
+ body.poll-preview-iframe #feedbacklink,
16
+ body.poll-preview-iframe #manage-polls h2#preview-header {
17
+ display: none;
18
+ }
19
+
20
+ body.poll-preview-iframe-editor #manage-polls h2#preview-header {
21
+ display: block;
22
+ }
23
+
24
+ h2#poll-list-header {
25
+ margin-bottom: 1.2em;
26
+ }
27
+
28
+ body.poll-preview-iframe {
29
+ margin: 0 !important;
30
+ padding: 0 !important;
31
+ }
32
+
33
+ body.poll-preview-iframe .wrap {
34
+ max-width: 100%;
35
+ }
36
+
37
+ body.poll-preview-iframe #wpwrap {
38
+ min-height: 0;
39
+ }
40
+
41
+ body.poll-preview-iframe div#wpcontent {
42
+ margin: 0;
43
+ padding: 0;
44
+ }
45
+
46
+ body.poll-preview-iframe div#wpbody {
47
+ margin: 0;
48
+ padding: 3em;
49
+ text-align: center;
50
+ }
51
+
52
+ body.poll-preview-iframe div#wpbody-content {
53
+ margin: 0;
54
+ padding: 0;
55
+ border: none;
56
+ }
57
+
58
+ body.poll-preview-iframe div#manage-polls.wrap {
59
+ text-align: left;
60
+ }
61
+
62
+ body.poll-preview-iframe .pds-box {
63
+ margin-left: auto;
64
+ margin-right: auto;
65
+ }
66
+
67
+ table td.post-title strong {
68
+ display: block;
69
+ }
70
+
71
+ table.poll-results .column-vote {
72
+ min-width: 50%;
73
+ padding: 3px 5px 3px 3px;
74
+ margin: 0;
75
+ }
76
+
77
+ table.poll-results div.result-holder {
78
+ position: relative;
79
+ }
80
+
81
+ table.poll-results span.result-bar {
82
+ display: block;
83
+ padding: 5px 0 4px 0;
84
+ margin: 0;
85
+ height: 100%;
86
+ border: 1px solid #EDB918;
87
+ background-color: #FBD55E;
88
+ }
89
+
90
+ table.poll-results span.result-total {
91
+ position: absolute;
92
+ left: .75em;
93
+ top: 6px;
94
+ }
95
+
96
+ table.poll-results span.result-percent {
97
+ position: absolute;
98
+ right: .75em;
99
+ top: 6px;
100
+ }
101
+
102
+ table.poll-others {
103
+ margin-top: 1.5em;
104
+ }
105
+
106
+ table.poll-others .column-vote {
107
+ min-width: 50%;
108
+ }
109
+
110
+ ul#answers, ul.poll-options {
111
+ list-style: none;
112
+ padding: 0;
113
+ }
114
+
115
+ ul#answers li {
116
+ position: relative;
117
+ }
118
+
119
+ ul#answers li div {
120
+ border: 1px solid #ccc;
121
+ padding: 2px 3px;
122
+ margin: 0 20px;
123
+ }
124
+
125
+ ul#answers li span.handle {
126
+ position: absolute;
127
+ left: 0;
128
+ top: 0;
129
+ width: 18px;
130
+ height: 100%;
131
+ background-color: #E4F2FD;
132
+ color: #70A6C4;
133
+ display: none;
134
+ cursor: move;
135
+ text-align: center;
136
+ line-height: 1.8em;
137
+ }
138
+
139
+ ul#answers li:hover span.handle {
140
+ display: block;
141
+ }
142
+
143
+ ul#answers li a.delete {
144
+ display: block;
145
+ position: absolute;
146
+ top: 0;
147
+ right: 0;
148
+ width: 18px;
149
+ height: 100%;
150
+ text-align: center;
151
+ line-height: 1.8em;
152
+ }
153
+
154
+ ul#answers li a.delete:hover {
155
+ color: white;
156
+ background-color: #f00;
157
+ }
158
+
159
+ ul#answers input {
160
+ padding: 0;
161
+ width: 100%;
162
+ border: none;
163
+ }
164
+
165
+ ul#answer-options {
166
+ list-style: none;
167
+ padding: 0;
168
+ margin-left: 20px;
169
+ }
170
+
171
+ ul#answer-options li {
172
+ display: inline;
173
+ margin-right: 1em;
174
+ white-space: nowrap;
175
+ }
176
+
177
+ p.submit input {
178
+ padding: 6px;
179
+ }
180
+
181
+ p#add-answer-holder {
182
+ display: none;
183
+ text-align: right;
184
+ }
185
+
186
+ #design {
187
+ text-align: center;
188
+ }
189
+
190
+ #design h3 {
191
+ text-align: left;
192
+ }
193
+
194
+ #design a {
195
+ width: 1em;
196
+ display: block;
197
+ font-size: 4em;
198
+ text-decoration: none;
199
+ }
200
+
201
+ .inner-sidebar {
202
+ clear: right;
203
+ float: right;
204
+ position: relative;
205
+ width: 220px;
206
+ margin-top: 10px;
207
+ }
208
+
209
+ #poststuff #post-body.has-sidebar, .has-sidebar {
210
+ clear: left;
211
+ float: left;
212
+ margin-right: -240px;
213
+ width: 100%;
214
+ }
215
+
216
+ .has-sidebar .has-sidebar-content {
217
+ margin-right: 245px;
218
+ }
219
+
220
+ #post-body-content #titlediv {
221
+ margin: 10px 0;
222
+ }
223
+
224
+ tr.polldaddy-shortcode-row {
225
+ background-color: #FFFEEB;
226
+ }
227
+
228
+ tr.polldaddy-shortcode-row h4 {
229
+ padding: 0;
230
+ margin: 0.3em 0;
231
+ clear: both;
232
+ }
233
+
234
+ tr.polldaddy-shortcode-row pre {
235
+ float: left;
236
+ background-color: #fff;
237
+ padding: .2em;
238
+ margin: 0 0 .5em;
239
+ border: 1px solid #ccc;
240
+ }
polldaddy.gif ADDED
Binary file
polldaddy.js ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(function($){
2
+ $('.hide-if-js').hide();
3
+ $('.hide-if-no-js').removeClass( 'hide-if-no-js' );
4
+
5
+ $('a.delete-poll').click( function() {
6
+ return confirm( 'Are you sure you want to delete "' + $(this).parents( 'td' ).find( 'strong' ).text() + '"?' );
7
+ } );
8
+
9
+ $('span.view a.thickbox').attr( 'href', function() {
10
+ return $(this).attr( 'href' ) + '&iframe&TB_iframe=true';
11
+ } );
12
+
13
+ var delAnswerPrep = function( context ) {
14
+ $('a.delete-answer', context || null ).click( function() {
15
+ if ( confirm( 'Are you sure you want to delete this answer?' ) ) {
16
+ $(this).parents( 'li' ).remove();
17
+ }
18
+ return false;
19
+ } );
20
+ };
21
+ delAnswerPrep();
22
+
23
+ $('#answers').sortable( {
24
+ axis: 'y',
25
+ containment: 'parent',
26
+ handle: '.handle',
27
+ tolerance: 'pointer'
28
+ } );
29
+
30
+ $('#add-answer-holder').show().find( 'button').click( function() {
31
+ var aa = ( 1 + $('#answers li').size() ).toString();
32
+ delAnswerPrep( $('#answers').append( '<li><span class="handle">&#x2195;</span><div><input type="text" name="answer[new' + aa + ']" size="30" tabindex="2" value="" autocomplete="off" /></div><a title="delete this answer" class="delete-answer delete" href="#">&times;</a></li>' ).find( 'li:last' ) );
33
+ return false;
34
+ } );
35
+
36
+ var win = window.dialogArguments || opener || parent || top;
37
+ $('.polldaddy-send-to-editor').click( function() {
38
+ var pollID = $(this).siblings('.polldaddy-poll-id').val();
39
+ if ( !pollID )
40
+ pollID = $('.polldaddy-poll-id:first').val();
41
+ win.send_to_editor( '[polldaddy poll=' + parseInt( pollID ).toString() + ']' );
42
+ } );
43
+
44
+ $('.polldaddy-show-shortcode').toggle( function() {
45
+ $(this).parents('tr:first').next('tr').fadeIn();
46
+ return false;
47
+ }, function() {
48
+ $(this).parents('tr:first').next('tr').fadeOut();
49
+ return false;
50
+ } );
51
+
52
+ var img1 = $('#design img:first');
53
+ if ( !img1.size() ) {
54
+ return;
55
+ }
56
+ var img2 = $('#design img:last');
57
+ var imgPath = 'http://polldaddy.com/Images/polls/';
58
+
59
+ var styles = $(':input[name=styleID]').remove();
60
+ var o = parseInt( styles.val() );
61
+ $('#design').append( '<input type="hidden" id="hidden-styleID" name="styleID" value="' + o.toString() + '" /><p><strong id="styleID-name">' + $(styles.find('option').get(o)).text() + '</strong><br /><span id="span-styleID">' + ( o + 1 ).toString() + '</span> of 19</p>');
62
+ var hiddenStyleID = $('#hidden-styleID');
63
+ var spanStyleID = $('#span-styleID');
64
+ var styleIDName = $('#styleID-name');
65
+
66
+ var changePreview = function( i ) {
67
+ var o = parseInt( img1.attr( 'src' ).substr( imgPath.length ) );
68
+ img1.attr( 'src', imgPath + ( ( i + o + 19 ) % 19 ).toString() + '.gif' );
69
+ img2.attr( 'src', imgPath + ( ( 2 * i + o + 19 ) % 19 ).toString() + '.gif' );
70
+ hiddenStyleID.val( ( ( i + o + 19 ) % 19 ).toString() );
71
+ spanStyleID.text( ( ( i + o + 19 ) % 19 + 1 ).toString() );
72
+ styleIDName.text( $(styles.find('option').get( ( i + o + 19 ) % 19 )).text() );
73
+ };
74
+
75
+ $('#design a.alignleft').click( function() { changePreview( -1 ); return false; } );
76
+ $('#design a.alignright').click( function() { changePreview( 1 ); return false; } );
77
+ });
polldaddy.php ADDED
@@ -0,0 +1,1076 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ Plugin Name: PollDaddy Polls
5
+ Description: Create and manage PollDaddy polls in WordPress
6
+ Author: Automattic, Inc.
7
+ Author URL: http://automattic.com/
8
+ Version: 0.8
9
+ */
10
+
11
+ // You can hardcode your PollDaddy PartnerGUID (API Key) here
12
+ //define( 'WP_POLLDADDY__PARTNERGUID', '12345...' );
13
+
14
+ if ( !defined( 'WP_POLLDADDY__CLASS' ) )
15
+ define( 'WP_POLLDADDY__CLASS', 'WP_PollDaddy' );
16
+
17
+ if ( !defined( 'WP_POLLDADDY__POLLDADDY_CLIENT_PATH' ) )
18
+ define( 'WP_POLLDADDY__POLLDADDY_CLIENT_PATH', dirname( __FILE__ ) . '/polldaddy-client.php' );
19
+
20
+ // TODO: when user changes PollDaddy password, userCode changes
21
+ class WP_PollDaddy {
22
+ var $errors;
23
+ var $polldaddy_client_class = 'PollDaddy_Client';
24
+ var $base_url = false;
25
+ var $version = '0.8';
26
+
27
+ function admin_menu() {
28
+ global $current_user;
29
+
30
+ $this->errors = new WP_Error;
31
+
32
+ if ( !$this->base_url )
33
+ $this->base_url = plugins_url() . '/' . dirname( plugin_basename( __FILE__ ) ) . '/';
34
+
35
+ if ( !defined( 'WP_POLLDADDY__PARTNERGUID' ) ) {
36
+ $guid = get_option( 'polldaddy_api_key' );
37
+ if ( !$guid || !is_string( $guid ) )
38
+ $guid = false;
39
+ define( 'WP_POLLDADDY__PARTNERGUID', $guid );
40
+ }
41
+
42
+ if ( !WP_POLLDADDY__PARTNERGUID ) {
43
+ $hook = add_management_page( __( 'Polls' ), __( 'Polls' ), 'edit_posts', 'polls', array( &$this, 'api_key_page' ) );
44
+ add_action( "load-$hook", array( &$this, 'api_key_page_load' ) );
45
+ if ( empty( $_GET['page'] ) || 'polls' != $_GET['page'] )
46
+ add_action( 'admin_notices', create_function( '', 'echo "<div class=\"error\"><p>" . sprintf( "You need to <a href=\"%s\">input your PollDaddy.com account details</a>.", "edit.php?page=polls" ) . "</p></div>";' ) );
47
+ return false;
48
+ }
49
+
50
+ if ( !defined( 'WP_POLLDADDY__USERCODE' ) ) {
51
+ define( 'WP_POLLDADDY__USERCODE',
52
+ isset( $current_user->data->polldaddy_account ) && is_string( $current_user->data->polldaddy_account ) ?
53
+ $current_user->data->polldaddy_account :
54
+ false
55
+ );
56
+ }
57
+ $hook = add_management_page( __( 'Polls' ), __( 'Polls' ), 'edit_posts', 'polls', array( &$this, 'management_page' ) );
58
+ add_action( "load-$hook", array( &$this, 'management_page_load' ) );
59
+
60
+ add_action( 'media_buttons', array( &$this, 'media_buttons' ) );
61
+ }
62
+
63
+ function api_key_page_load() {
64
+ if ( 'post' != strtolower( $_SERVER['REQUEST_METHOD'] ) || empty( $_POST['action'] ) || 'account' != $_POST['action'] )
65
+ return false;
66
+
67
+ check_admin_referer( 'polldaddy-account' );
68
+
69
+ $polldaddy_email = stripslashes( $_POST['polldaddy_email'] );
70
+ $polldaddy_password = stripslashes( $_POST['polldaddy_password'] );
71
+
72
+ if ( !$polldaddy_email )
73
+ $this->errors->add( 'polldaddy_email', __( 'Email address required' ) );
74
+
75
+ if ( !$polldaddy_password )
76
+ $this->errors->add( 'polldaddy_password', __( 'Password required' ) );
77
+
78
+ if ( $this->errors->get_error_codes() )
79
+ return false;
80
+
81
+ $details = array(
82
+ 'uName' => get_bloginfo( 'name' ),
83
+ 'uEmail' => $polldaddy_email,
84
+ 'uPass' => $polldaddy_password
85
+ );
86
+ if ( function_exists( 'wp_remote_post' ) ) {
87
+ $polldaddy_api_key = wp_remote_post( 'http://api.polldaddy.com/key/new.aspx', array(
88
+ 'body' => $details
89
+ ) );
90
+ } else {
91
+ $fp = fsockopen(
92
+ 'api.polldaddy.com',
93
+ 80,
94
+ $err_num,
95
+ $err_str,
96
+ 3
97
+ );
98
+
99
+ if ( !$fp ) {
100
+ $this->errors->add( 'connect', __( "Can't connect to PollDaddy.com" ) );
101
+ return false;
102
+ }
103
+
104
+ if ( function_exists( 'stream_set_timeout' ) )
105
+ stream_set_timeout( $fp, 3 );
106
+
107
+ global $wp_version;
108
+
109
+ $request_body = http_build_query( $details, null, '&' );
110
+
111
+ $request = "POST /key/new.aspx HTTP/1.0\r\n";
112
+ $request .= "Host: api.polldaddy.com\r\n";
113
+ $request .= "User-agent: WordPress/$wp_version\r\n";
114
+ $request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option('blog_charset') . "\r\n";
115
+ $request .= 'Content-Length: ' . strlen( $request_body ) . "\r\n";
116
+
117
+ fwrite( $fp, "$request\r\n$request_body" );
118
+
119
+ $response = '';
120
+ while ( !feof( $fp ) )
121
+ $response .= fread( $fp, 4096 );
122
+ fclose( $fp );
123
+ list($headers, $polldaddy_api_key) = explode( "\r\n\r\n", $response, 2 );
124
+ }
125
+
126
+ if ( !$polldaddy_api_key ) {
127
+ $this->errors->add( 'polldaddy_password', __( 'Invalid Account' ) );
128
+ return false;
129
+ }
130
+
131
+ update_option( 'polldaddy_api_key', $polldaddy_api_key );
132
+
133
+ require_once WP_POLLDADDY__POLLDADDY_CLIENT_PATH;
134
+
135
+ $polldaddy = new $this->polldaddy_client_class( $polldaddy_api_key );
136
+
137
+ if ( $polldaddy_account = $polldaddy->GetUserCode( 0 ) ) {
138
+ update_usermeta( $GLOBALS['user_ID'], 'polldaddy_account', $polldaddy_account );
139
+ } else {
140
+ $this->parse_errors( $polldaddy );
141
+ $this->errors->add( 'GetUserCode', __( 'Account could not be accessed. Are your email address and password correct?' ) );
142
+ return false;
143
+ }
144
+
145
+ return true;
146
+ }
147
+
148
+ function parse_errors( &$polldaddy ) {
149
+ if ( $polldaddy->errors )
150
+ foreach ( $polldaddy->errors as $code => $error )
151
+ $this->errors->add( $code, $error );
152
+ if ( isset( $this->errors->errors[4] ) ) {
153
+ $this->errors->errors[4] = array( sprintf( __( 'Obsolete PollDaddy User API Key: <a href="%s">Sign in again to re-authenticate</a>' ), add_query_arg( array( 'action' => 'signup', 'reaction' => empty( $_GET['action'] ) ? false : $_GET['action'] ) ) ) );
154
+ $this->errors->add_data( true, 4 );
155
+ }
156
+ }
157
+
158
+ function print_errors() {
159
+ if ( !$error_codes = $this->errors->get_error_codes() )
160
+ return;
161
+ ?>
162
+
163
+ <div class="error">
164
+
165
+ <?php
166
+
167
+ foreach ( $error_codes as $error_code ) :
168
+ foreach ( $this->errors->get_error_messages( $error_code ) as $error_message ) :
169
+ ?>
170
+
171
+ <p><?php echo $this->errors->get_error_data( $error_code ) ? $error_message : wp_specialchars( $error_message ); ?></p>
172
+
173
+ <?php
174
+ endforeach;
175
+ endforeach;
176
+ ?>
177
+
178
+ </div>
179
+ <br class="clear" />
180
+
181
+ <?php
182
+ }
183
+
184
+ function api_key_page() {
185
+
186
+ ?>
187
+
188
+ <div class="wrap">
189
+
190
+ <h2><?php _e( 'PollDaddy Account' ); ?></h2>
191
+
192
+ <p><?php printf( __('Before you can use the PollDaddy plugin, you need to enter your <a href="%s">PollDaddy.com</a> account details.' ), 'http://polldaddy.com/' ); ?></p>
193
+
194
+ <form action="" method="post">
195
+ <table class="form-table">
196
+ <tbody>
197
+ <tr class="form-field form-required">
198
+ <th valign="top" scope="row">
199
+ <label for="polldaddy-email">PollDaddy Email Address</label>
200
+ </th>
201
+ <td>
202
+ <input type="text" name="polldaddy_email" id="polldaddy-email" aria-required="true" size="40" />
203
+ </td>
204
+ </tr>
205
+ <tr class="form-field form-required">
206
+ <th valign="top" scope="row">
207
+ <label for="polldaddy-password">PollDaddy Password</label>
208
+ </th>
209
+ <td>
210
+ <input type="password" name="polldaddy_password" id="polldaddy-password" aria-required="true" size="40" />
211
+ </td>
212
+ </tr>
213
+ </tbody>
214
+ </table>
215
+ <p class="submit">
216
+ <?php wp_nonce_field( 'polldaddy-account' ); ?>
217
+ <input type="hidden" name="action" value="account" />
218
+ <input type="hidden" name="account" value="import" />
219
+ <input type="submit" value="<?php echo attribute_escape( __( 'Submit' ) ); ?>" />
220
+ </p>
221
+ </form>
222
+ </div>
223
+
224
+ <?php
225
+ }
226
+
227
+ function media_buttons() {
228
+ $title = __( 'Add Poll' );
229
+ echo "<a href='admin.php?page=polls&amp;iframe&amp;TB_iframe=true' id='add_poll' class='thickbox' title='$title'><img src='{$this->base_url}polldaddy.gif' alt='$title' /></a>";
230
+ }
231
+
232
+ function management_page_load() {
233
+ wp_reset_vars( array( 'action', 'poll' ) );
234
+ global $action, $poll;
235
+
236
+ if ( !WP_POLLDADDY__USERCODE )
237
+ $action = 'signup';
238
+
239
+ require_once WP_POLLDADDY__POLLDADDY_CLIENT_PATH;
240
+
241
+ wp_enqueue_script( 'polls', "{$this->base_url}polldaddy.js", array( 'jquery', 'jquery-ui-sortable' ), $this->version );
242
+ wp_enqueue_script( 'admin-forms' );
243
+ add_thickbox();
244
+
245
+ wp_enqueue_style( 'polls', "{$this->base_url}polldaddy.css", array(), $this->version );
246
+ add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
247
+
248
+ add_action( 'admin_notices', array( &$this, 'management_page_notices' ) );
249
+
250
+ $query_args = array();
251
+
252
+ $is_POST = 'post' == strtolower( $_SERVER['REQUEST_METHOD'] );
253
+
254
+ switch ( $action ) :
255
+ case 'signup' : // sign up for first time
256
+ case 'account' : // reauthenticate
257
+ if ( !$is_POST )
258
+ return;
259
+
260
+ check_admin_referer( 'polldaddy-account' );
261
+
262
+ if ( $new_args = $this->management_page_load_signup() )
263
+ $query_args = array_merge( $query_args, $new_args );
264
+ if ( $this->errors->get_error_codes() )
265
+ return false;
266
+
267
+ wp_reset_vars( array( 'action' ) );
268
+ if ( !empty( $_GET['reaction'] ) )
269
+ $query_args['action'] = $_GET['reaction'];
270
+ elseif ( !empty( $_GET['action'] ) && 'signup' != $_GET['action'] )
271
+ $query_args['action'] = $_GET['action'];
272
+ else
273
+ $query_args['action'] = false;
274
+ break;
275
+ case 'delete' :
276
+ global $current_user;
277
+
278
+ if ( empty( $poll ) )
279
+ return;
280
+
281
+ if ( is_array( $poll ) )
282
+ check_admin_referer( 'delete-poll_bulk' );
283
+ else
284
+ check_admin_referer( "delete-poll_$poll" );
285
+
286
+ $polldaddy = new $this->polldaddy_client_class( WP_POLLDADDY__PARTNERGUID, WP_POLLDADDY__USERCODE );
287
+
288
+ foreach ( (array) $_REQUEST['poll'] as $poll_id ) {
289
+ $poll_object = $polldaddy->GetPoll( $poll );
290
+
291
+ if ( !$this->can_edit( $poll_object ) ) {
292
+ $this->errors->add( 'permission', __( 'You are not allowed to delete this poll.' ) );
293
+ return false;
294
+ }
295
+
296
+ $polldaddy->reset();
297
+
298
+ // Send Poll Author credentials
299
+ if ( !empty( $poll_object->_owner ) && $current_user->ID != $poll_object->_owner ) {
300
+ if ( !$userCode = get_usermeta( $poll_object->_owner, 'polldaddy_account' ) ) {
301
+ $this->errors->add( 'no_usercode', __( 'Invalid Poll Author' ) );
302
+ }
303
+ $polldaddy->userCode = $userCode;
304
+ }
305
+
306
+ $polldaddy->DeletePoll( $poll_id );
307
+ $polldaddy->reset();
308
+ }
309
+
310
+ $query_args['message'] = 'deleted';
311
+ $query_args['deleted'] = count( (array) $poll );
312
+ break;
313
+ case 'edit-poll' : // TODO: use polldaddy_poll
314
+ if ( !$is_POST || !$poll = (int) $poll )
315
+ return;
316
+
317
+ check_admin_referer( "edit-poll_$poll" );
318
+
319
+ $polldaddy = new $this->polldaddy_client_class( WP_POLLDADDY__PARTNERGUID, WP_POLLDADDY__USERCODE );
320
+
321
+ $poll_object = $polldaddy->GetPoll( $poll );
322
+
323
+ if ( !$this->can_edit( $poll_object ) ) {
324
+ $this->errors->add( 'permission', __( 'You are not allowed to edit this poll.' ) );
325
+ return false;
326
+ }
327
+
328
+ // Send Poll Author credentials
329
+ if ( !empty( $poll_object->_owner ) && $current_user->ID != $poll_object->_owner ) {
330
+ if ( !$userCode = get_usermeta( $poll_object->_owner, 'polldaddy_account' ) ) {
331
+ $this->errors->add( 'no_usercode', __( 'Invalid Poll Author' ) );
332
+ }
333
+ $polldaddy->userCode = $userCode;
334
+ }
335
+
336
+ $this->parse_errors( $polldaddy );
337
+
338
+ if ( !$poll_object )
339
+ $this->errors->add( 'GetPoll', __( 'Poll not found' ) );
340
+
341
+ if ( $this->errors->get_error_codes() )
342
+ return false;
343
+
344
+ $poll_data = get_object_vars( $poll_object );
345
+ foreach ( $poll_data as $key => $value )
346
+ if ( '_' === $key[0] )
347
+ unset( $poll_data[$key] );
348
+
349
+ foreach ( array( 'multipleChoice', 'randomiseAnswers', 'otherAnswer' ) as $option ) {
350
+ if ( isset( $_POST[$option] ) && $_POST[$option] )
351
+ $poll_data[$option] = 'yes';
352
+ else
353
+ $poll_data[$option] = 'no';
354
+ }
355
+
356
+ $blocks = array( 'off', 'cookie', 'cookieIP' );
357
+ if ( isset( $_POST['blockRepeatVotersType'] ) && in_array( $_POST['blockRepeatVotersType'], $blocks ) )
358
+ $poll_data['blockRepeatVotersType'] = $_POST['blockRepeatVotersType'];
359
+
360
+ $results = array( 'show', 'percent', 'hide' );
361
+ if ( isset( $_POST['resultsType'] ) && in_array( $_POST['resultsType'], $results ) )
362
+ $poll_data['resultsType'] = $_POST['resultsType'];
363
+ $poll_data['question'] = stripslashes( $_POST['question'] );
364
+
365
+ if ( empty( $_POST['answer'] ) || !is_array( $_POST['answer'] ) )
366
+ $this->errors->add( 'answer', __( 'Invalid answers' ) );
367
+
368
+ $answers = array();
369
+ foreach ( $_POST['answer'] as $answer_id => $answer ) {
370
+ if ( !$answer = trim( stripslashes( $answer ) ) )
371
+ continue;
372
+
373
+ if ( is_numeric( $answer_id ) )
374
+ $answers[] = polldaddy_poll_answer( $answer, $answer_id );
375
+ else
376
+ $answers[] = polldaddy_poll_answer( $answer );
377
+ }
378
+
379
+ if ( 2 > count( $answers ) )
380
+ $this->errors->add( 'answer', __( 'You must include at least 2 answers' ) );
381
+
382
+ if ( $this->errors->get_error_codes() )
383
+ return false;
384
+
385
+ $poll_data['answers'] = $answers;
386
+ $poll_data['styleID'] = $_POST['styleID'];
387
+
388
+ $polldaddy->reset();
389
+
390
+ $update_response = $polldaddy->UpdatePoll( $poll, $poll_data );
391
+
392
+ $this->parse_errors( $polldaddy );
393
+
394
+ if ( !$update_response )
395
+ $this->errors->add( 'UpdatePoll', __( 'Poll could not be updated' ) );
396
+
397
+ if ( $this->errors->get_error_codes() )
398
+ return false;
399
+
400
+ $query_args['message'] = 'updated';
401
+ if ( isset($_POST['iframe']) )
402
+ $query_args['iframe'] = '';
403
+ break;
404
+ case 'create-poll' :
405
+ if ( !$is_POST )
406
+ return;
407
+
408
+ check_admin_referer( 'create-poll' );
409
+
410
+ $polldaddy = new $this->polldaddy_client_class( WP_POLLDADDY__PARTNERGUID, WP_POLLDADDY__USERCODE );
411
+
412
+ $answers = array();
413
+ foreach ( $_POST['answer'] as $answer )
414
+ if ( $answer = trim( stripslashes( $answer ) ) )
415
+ $answers[] = polldaddy_poll_answer( $answer );
416
+ if ( !$answers )
417
+ return false;
418
+
419
+ $poll_data = _polldaddy_poll_defaults();
420
+ foreach ( $poll_data as $key => $value )
421
+ if ( isset($_POST[$key]) )
422
+ $poll_data[$key] = stripslashes( $_POST[$key] );
423
+
424
+ $poll_data['answers'] = $answers;
425
+
426
+ $poll = $polldaddy->CreatePoll( $poll_data );
427
+ $this->parse_errors( $polldaddy );
428
+
429
+ if ( !$poll || empty( $poll->_id ) )
430
+ $this->errors->add( 'CreatePoll', __( 'Poll could not be created' ) );
431
+
432
+ if ( $this->errors->get_error_codes() )
433
+ return false;
434
+
435
+ $query_args['message'] = 'created';
436
+ $query_args['action'] = 'edit-poll';
437
+ $query_args['poll'] = $poll->_id;
438
+ if ( isset($_POST['iframe']) )
439
+ $query_args['iframe'] = '';
440
+ break;
441
+ default :
442
+ return;
443
+ endswitch;
444
+
445
+ wp_redirect( add_query_arg( $query_args, wp_get_referer() ) );
446
+ exit;
447
+ }
448
+
449
+ function management_page_load_signup() {
450
+ switch ( $_POST['account'] ) :
451
+ case 'import' :
452
+ $polldaddy = new $this->polldaddy_client_class( WP_POLLDADDY__PARTNERGUID );
453
+ $email = trim( stripslashes( $_POST['polldaddy_email'] ) );
454
+ $password = trim( stripslashes( $_POST['polldaddy_password'] ) );
455
+
456
+ if ( !is_email( $email ) )
457
+ $this->errors->add( 'polldaddy_email', __( 'Email address required' ) );
458
+
459
+ if ( !$password )
460
+ $this->errors->add( 'polldaddy_password', __( 'Password required' ) );
461
+
462
+ if ( $this->errors->get_error_codes() )
463
+ return false;
464
+
465
+ if ( $polldaddy_account = $polldaddy->Initiate( $email, $password, $GLOBALS['user_ID'] ) ) {
466
+ update_usermeta( $GLOBALS['user_ID'], 'polldaddy_account', $polldaddy_account );
467
+ } else {
468
+ $this->parse_errors( $polldaddy );
469
+ $this->errors->add( 'import-account', __( 'Account could not be imported. Are your email address and password correct?' ) );
470
+ return false;
471
+ }
472
+ break;
473
+ default :
474
+ return;
475
+ endswitch;
476
+ }
477
+
478
+ function admin_body_class( $class ) {
479
+ if ( isset( $_GET['iframe'] ) )
480
+ $class .= 'poll-preview-iframe ';
481
+ if ( isset( $_GET['TB_iframe'] ) )
482
+ $class .= 'poll-preview-iframe-editor ';
483
+ return $class;
484
+ }
485
+
486
+ function management_page_notices() {
487
+ $message = false;
488
+ switch ( (string) @$_GET['message'] ) :
489
+ case 'deleted' :
490
+ $deleted = (int) $_GET['deleted'];
491
+ if ( 1 == $deleted )
492
+ $message = __( 'Poll deleted.' );
493
+ else
494
+ $message = sprintf( __ngettext( '%s Poll Deleted.', '%s Polls Deleted.', $deleted ), number_format_i18n( $deleted ) );
495
+ break;
496
+ case 'updated' :
497
+ $message = __( 'Poll updated.' );
498
+ break;
499
+ case 'created' :
500
+ $message = __( 'Poll created.' );
501
+ if ( isset( $_GET['iframe'] ) )
502
+ $message .= ' <input type="button" class="button polldaddy-send-to-editor" value="' . attribute_escape( __( 'Send to Editor' ) ) . '" />';
503
+ break;
504
+ endswitch;
505
+
506
+ $is_POST = 'post' == strtolower( $_SERVER['REQUEST_METHOD'] );
507
+
508
+ if ( $is_POST ) {
509
+ switch ( $GLOBALS['action'] ) :
510
+ case 'create-poll' :
511
+ $message = __( 'Error: An error has occurred; Poll not created.' );
512
+ break;
513
+ case 'edit-poll' :
514
+ $message = __( 'Error: An error has occurred; Poll not updated.' );
515
+ break;
516
+ case 'account' :
517
+ if ( 'import' == $_POST['account'] )
518
+ $message = __( 'Error: An error has occurred; Account could not be imported. Perhaps your email address or password is incorrect?' );
519
+ else
520
+ $message = __( 'Error: An error has occurred; Account could not be created.' );
521
+ break;
522
+ endswitch;
523
+ }
524
+
525
+ if ( !$message )
526
+ return;
527
+ ?>
528
+ <div class='updated'><p><?php echo $message; ?></p></div>
529
+ <?php
530
+ $this->print_errors();
531
+ }
532
+
533
+ function management_page() {
534
+ global $action, $poll;
535
+ $poll = (int) $poll;
536
+
537
+ ?>
538
+
539
+ <div class="wrap" id="manage-polls">
540
+
541
+ <?php
542
+ switch ( $action ) :
543
+ case 'signup' :
544
+ case 'account' :
545
+ $this->signup();
546
+ break;
547
+ case 'preview' :
548
+ ?>
549
+
550
+ <h2 id="preview-header"><?php printf( __( 'Poll Preview (<a href="%s">Edit Poll</a>, <a href="%s">List Polls</a>)' ),
551
+ clean_url( add_query_arg( array( 'action' => 'edit', 'poll' => $poll, 'message' => false ) ) ),
552
+ clean_url( add_query_arg( array( 'action' => false, 'poll' => $poll, 'message' => false ) ) )
553
+ ); ?></h2>
554
+
555
+ <?php
556
+ echo do_shortcode( "[polldaddy poll=$poll]" );
557
+ break;
558
+ case 'results' :
559
+ ?>
560
+
561
+ <h2><?php printf( __( 'Poll Results (<a href="%s">Edit</a>)' ), clean_url( add_query_arg( array( 'action' => 'edit', 'poll' => $poll, 'message' => false ) ) ) ); ?></h2>
562
+
563
+ <?php
564
+ $this->poll_results_page( $poll );
565
+ break;
566
+ case 'edit' :
567
+ case 'edit-poll' :
568
+ ?>
569
+
570
+ <h2><?php printf( __('Edit Poll (<a href="%s">List Polls</a>)'), clean_url( add_query_arg( array( 'action' => false, 'poll' => $poll, 'message' => false ) ) ) ); ?></h2>
571
+
572
+ <?php
573
+
574
+ $this->poll_edit_form( $poll );
575
+ break;
576
+ case 'create-poll' :
577
+ ?>
578
+
579
+ <h2><?php printf( __('Create Poll (<a href="%s">List Polls</a>)'), clean_url( add_query_arg( array( 'action' => false, 'poll' => $poll, 'message' => false ) ) ) ); ?></h2>
580
+
581
+ <?php
582
+ $this->poll_edit_form();
583
+ break;
584
+ default :
585
+
586
+ ?>
587
+
588
+ <h2 id="poll-list-header"><?php printf( __( 'Polls (<a href="%s">Add New</a>)' ), clean_url( add_query_arg( array(
589
+ 'action' => 'create-poll',
590
+ 'poll' => false,
591
+ 'message' => false
592
+ ) ) ) ); ?></h2>
593
+
594
+ <?php
595
+ $this->polls_table( isset( $_GET['view'] ) && 'user' == $_GET['view'] ? 'user' : 'blog' );
596
+ endswitch;
597
+ ?>
598
+
599
+ </div>
600
+
601
+ <?php
602
+
603
+ }
604
+
605
+ function polls_table( $view = 'blog' ) {
606
+ $page = absint($_GET['paged']);
607
+ if ( !$page )
608
+ $page = 1;
609
+ $polldaddy = new $this->polldaddy_client_class( WP_POLLDADDY__PARTNERGUID, WP_POLLDADDY__USERCODE );
610
+ if ( 'user' == $view )
611
+ $polls_object = $polldaddy->listPolls( ( $page - 1 ) * 10 + 1, $page * 10 );
612
+ else
613
+ $polls_object = $polldaddy->listPollsByBlog( ( $page - 1 ) * 10 + 1, $page * 10 );
614
+ $this->parse_errors( $polldaddy );
615
+ $this->print_errors();
616
+ $polls = & $polls_object->poll;
617
+ $total_polls = $polls_object->_total;
618
+ $class = '';
619
+
620
+ $page_links = paginate_links( array(
621
+ 'base' => add_query_arg( 'paged', '%#%' ),
622
+ 'format' => '',
623
+ 'total' => ceil( $total_polls / 10 ),
624
+ 'current' => $page
625
+ ) );
626
+
627
+ ?>
628
+
629
+ <ul class="view-switch">
630
+ <li<?php if ( 'blog' == $view ) echo ' class="current"'; ?>><a href="<?php echo clean_url( add_query_arg( 'view', false ) ); ?>"><?php _e( "All Blog's Polls" ); ?></a></li>
631
+ <li<?php if ( 'user' == $view ) echo ' class="current"'; ?>><a href="<?php echo clean_url( add_query_arg( 'view', 'user' ) ); ?>"><?php _e( "All My Polls" ); ?></a></li>
632
+ </ul>
633
+ <form method="post" action="">
634
+ <div class="tablenav">
635
+ <div class="alignleft">
636
+ <select name="action">
637
+ <option selected="selected" value=""><?php _e( 'Actions' ); ?></option>
638
+ <option value="delete"><?php _e( 'Delete' ); ?></option>
639
+ </select>
640
+ <input class="button-secondary action" type="submit" name="doaction" value="<?php _e( 'Apply' ); ?>" />
641
+ <?php wp_nonce_field( 'delete-poll_bulk' ); ?>
642
+ </div>
643
+ <div class="tablenav-pages"><?php echo $page_links; ?></div>
644
+ </div>
645
+ <br class="clear" />
646
+ <table class="widefat">
647
+ <thead>
648
+ <tr>
649
+ <th id="cb" class="manage-column column-cb check-column" scope="col" /><input type="checkbox" /></th>
650
+ <th id="title" class="manage-column column-title" scope="col">Poll</th>
651
+ <th id="votes" class="manage-column column-vote" scope="col">Votes</th>
652
+ <th id="date" class="manage-column column-date" scope="col">Created</th>
653
+ </tr>
654
+ </thead>
655
+ <tbody>
656
+
657
+ <?php
658
+ if ( $polls ) :
659
+ foreach ( $polls as $poll ) :
660
+ $poll_id = (int) $poll->_id;
661
+
662
+ if ( $this->can_edit( $poll ) )
663
+ $edit_link = clean_url( add_query_arg( array( 'action' => 'edit', 'poll' => $poll_id, 'message' => false ) ) );
664
+ else
665
+ $edit_link = false;
666
+
667
+ $class = $class ? '' : ' class="alternate"';
668
+ $results_link = clean_url( add_query_arg( array( 'action' => 'results', 'poll' => $poll_id, 'message' => false ) ) );
669
+ $delete_link = clean_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'poll' => $poll_id, 'message' => false ) ), "delete-poll_$poll_id" ) );
670
+ $preview_link = clean_url( add_query_arg( array( 'action' => 'preview', 'poll' => $poll_id, 'message' => false ) ) ); //, 'iframe' => '', 'TB_iframe' => 'true' ) ) );
671
+ list($poll_time) = explode( '.', $poll->_created );
672
+ $poll_time = strtotime( $poll_time );
673
+ ?>
674
+
675
+ <tr<?php echo $class; ?>>
676
+ <th class="check-column" scope="row"><input type="checkbox" value="<?php echo (int) $poll_id; ?>" name="poll[]" /></th>
677
+ <td class="post-title column-title">
678
+ <?php if ( $edit_link ) : ?>
679
+ <strong><a class="row-title" href="<?php echo $edit_link; ?>"><?php echo wp_specialchars( $poll->___content ); ?></a></strong>
680
+ <span class="edit"><a href="<?php echo $edit_link; ?>"><?php _e( 'Edit' ); ?></a> | </span>
681
+ <?php else : ?>
682
+ <strong><?php echo wp_specialchars( $poll->___content ); ?></strong>
683
+ <?php endif; ?>
684
+
685
+ <span class="results"><a href="<?php echo $results_link; ?>"><?php _e( 'Results' ); ?></a> | </span>
686
+ <span class="delete"><a class="delete-poll delete" href="<?php echo $delete_link; ?>"><?php _e( 'Delete' ); ?></a> | </span>
687
+ <?php if ( isset( $_GET['iframe'] ) ) : ?>
688
+ <span class="view"><a href="<?php echo $preview_link; ?>"><?php _e( 'Preview' ); ?></a> | </span>
689
+ <span class="editor">
690
+ <a href="#" class="polldaddy-send-to-editor"><?php _e( 'Send to editor' ); ?></a>
691
+ <input type="hidden" class="polldaddy-poll-id hack" value="<?php echo (int) $poll_id; ?>" /> |
692
+ </span>
693
+ <?php else : ?>
694
+ <span class="view"><a class="thickbox" href="<?php echo $preview_link; ?>"><?php _e( 'Preview' ); ?></a> | </span>
695
+ <?php endif; ?>
696
+ <span class="shortcode"><a href="#" class="polldaddy-show-shortcode"><?php _e( 'HTML code' ); ?></a></span>
697
+ </td>
698
+ <td class="poll-votes column-vote"><?php echo number_format_i18n( $poll->_responses ); ?></td>
699
+ <td class="date column-date"><abbr title="<?php echo date( __('Y/m/d g:i:s A'), $poll_time ); ?>"><?php echo date( __('Y/m/d'), $poll_time ); ?></abbr></td>
700
+ </tr>
701
+ <tr class="polldaddy-shortcode-row" style="display: none;">
702
+ <td colspan="4">
703
+ <h4><?php _e( 'Shortcode' ); ?></h4>
704
+ <pre>[polldaddy poll=<?php echo (int) $poll_id; ?>]</pre>
705
+
706
+ <h4><?php _e( 'JavaScript' ); ?></h4>
707
+ <pre>&lt;script type="text/javascript" language="javascript"
708
+ src="http://static.polldaddy.com/p/<?php echo (int) $poll_id; ?>.js"&gt;&lt;/script&gt;
709
+ &lt;noscript&gt;
710
+ &lt;a href="http://answers.polldaddy.com/poll/1000076/"&gt;<?php echo wp_specialchars( $poll->___content ); ?>&lt;/a&gt;&lt;br/&gt;
711
+ &lt;span style="font:9px;"&gt;(&lt;a href="http://www.polldaddy.com"&gt;polls&lt;/a&gt;)&lt;/span&gt;
712
+ &lt;/noscript&gt;</pre>
713
+ </td>
714
+ </tr>
715
+
716
+ <?php
717
+ endforeach;
718
+ elseif ( $total_polls ) : // $polls
719
+ ?>
720
+
721
+ <tr>
722
+ <td colspan="4"><?php printf( __( 'What are you doing here? <a href="%s">Go back</a>.' ), clean_url( add_query_arg( 'paged', false ) ) ); ?></td>
723
+ </tr>
724
+
725
+ <?php
726
+ else : // $polls
727
+ ?>
728
+
729
+ <tr>
730
+ <td colspan="4"><?php printf( __( 'No polls yet. <a href="%s">Create one</a>' ), clean_url( add_query_arg( array( 'action' => 'create-poll' ) ) ) ); ?></td>
731
+ </tr>
732
+ <?php endif; // $polls ?>
733
+
734
+ </tbody>
735
+ </table>
736
+ </form>
737
+ <div class="tablenav">
738
+ <div class="tablenav-pages"><?php echo $page_links; ?></div>
739
+ </div>
740
+ <br class="clear" />
741
+
742
+ <?php
743
+ }
744
+
745
+ function poll_edit_form( $poll_id = 0 ) {
746
+ $poll_id = (int) $poll_id;
747
+
748
+ $polldaddy = new $this->polldaddy_client_class( WP_POLLDADDY__PARTNERGUID, WP_POLLDADDY__USERCODE );
749
+
750
+ $is_POST = 'post' == strtolower( $_SERVER['REQUEST_METHOD'] );
751
+
752
+ if ( $poll_id ) {
753
+ $poll = $polldaddy->GetPoll( $poll_id );
754
+ $this->parse_errors( $polldaddy );
755
+ if ( !$this->can_edit( $poll ) ) {
756
+ $this->errors->add( 'permission', __( 'You are not allowed to edit this poll.' ) );
757
+ }
758
+ } else {
759
+ $poll = polldaddy_poll( array(), null, false );
760
+ }
761
+
762
+ $question = $is_POST ? attribute_escape( stripslashes( $_POST['question'] ) ) : attribute_escape( $poll->question );
763
+
764
+ $this->print_errors();
765
+ ?>
766
+
767
+ <form action="" method="post">
768
+ <div id="poststuff"><div id="post-body" class="has-sidebar">
769
+
770
+ <div class="inner-sidebar" id="side-info-column">
771
+ <h3><?php _e( 'Poll results' ); ?></h3>
772
+ <div class="inside">
773
+ <ul class="poll-options">
774
+
775
+ <?php
776
+ foreach ( array( 'show' => __( 'Show results to voters' ), 'percent' => __( 'Only show percentages' ), 'hide' => __( 'Hide all results' ) ) as $value => $label ) :
777
+ if ( $is_POST )
778
+ $checked = $value === $_POST['resultsType'] ? ' checked="checked"' : '';
779
+ else
780
+ $checked = $value === $poll->resultsType ? ' checked="checked"' : '';
781
+ ?>
782
+
783
+ <li>
784
+ <label for="resultsType-<?php echo $value; ?>"><input type="radio"<?php echo $checked; ?> value="<?php echo $value; ?>" name="resultsType" id="resultsType-<?php echo $value; ?>" /> <?php echo wp_specialchars( $label ); ?></label>
785
+ </li>
786
+
787
+ <?php endforeach; ?>
788
+
789
+ </ul>
790
+ </div>
791
+
792
+ <h3><?php _e( 'Block repeat voters' ); ?></h3>
793
+ <div class="inside">
794
+ <ul class="poll-options">
795
+
796
+ <?php
797
+ foreach ( array( 'off' => __( "Don't block repeat voters" ), 'cookie' => __( 'Block by cookie (recommended)' ), 'cookieIP' => __( 'Block by cookie and by IP address' ) ) as $value => $label ) :
798
+ if ( $is_POST )
799
+ $checked = $value === $_POST['blockRepeatVotersType'] ? ' checked="checked"' : '';
800
+ else
801
+ $checked = $value === $poll->blockRepeatVotersType ? ' checked="checked"' : '';
802
+ ?>
803
+
804
+ <li>
805
+ <label for="blockRepeatVotersType-<?php echo $value; ?>"><input type="radio"<?php echo $checked; ?> value="<?php echo $value; ?>" name="blockRepeatVotersType" id="blockRepeatVotersType-<?php echo $value; ?>" /> <?php echo wp_specialchars( $label ); ?></label>
806
+ </li>
807
+
808
+ <?php endforeach; ?>
809
+
810
+ </ul>
811
+ <p>Note: Blocking by cookie and IP address can be problematic for some voters.</p>
812
+ </div>
813
+ </div>
814
+
815
+
816
+ <div id="post-body-content" class="has-sidebar-content">
817
+
818
+ <div id="titlediv">
819
+ <h3><label for="title"><?php _e( 'Question' ); ?></label></h3>
820
+ <div id="titlewrap">
821
+ <input type="text" autocomplete="off" id="title" value="<?php echo $question; ?>" tabindex="1" size="30" name="question" />
822
+ </div>
823
+ </div>
824
+
825
+ <div id="answersdiv">
826
+ <h3><?php _e( 'Answers' ); ?></h3>
827
+
828
+ <div id="answerswrap">
829
+ <ul id="answers">
830
+ <?php
831
+ $a = 0;
832
+ $answers = array();
833
+ if ( $is_POST && $_POST['answer'] ) {
834
+ foreach( $_POST['answer'] as $answer_id => $answer )
835
+ $answers[attribute_escape($answer_id)] = attribute_escape( stripslashes($answer) );
836
+ } elseif ( isset( $poll->answers->answer ) ) {
837
+ foreach ( $poll->answers->answer as $answer )
838
+ $answers[(int) $answer->_id] = attribute_escape( $answer->___content );
839
+ }
840
+
841
+ foreach ( $answers as $answer_id => $answer ) :
842
+ $a++;
843
+ $delete_link = clean_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete-answer', 'poll' => $poll_id, 'answer' => $answer_id, 'message' => false ) ), "delete-answer_$answer_id" ) );
844
+ ?>
845
+
846
+ <li>
847
+ <span class="handle" title="<?php echo attribute_escape( 'click and drag to move' ); ?>">&#x2195;</span>
848
+ <div><input type="text" autocomplete="off" id="answer-<?php echo $answer_id; ?>" value="<?php echo $answer; ?>" tabindex="2" size="30" name="answer[<?php echo $answer_id; ?>]" /></div>
849
+ <a href="<?php echo $delete_link; ?>" class="delete-answer delete" title="<?php echo attribute_escape( 'delete this answer' ); ?>">&times;</a>
850
+ </li>
851
+
852
+ <?php
853
+ endforeach;
854
+
855
+ while ( 3 - $a > 0 ) :
856
+ $a++;
857
+ ?>
858
+
859
+ <li>
860
+ <span class="handle" title="<?php echo attribute_escape( 'click and drag to move' ); ?>">&#x2195;</span>
861
+ <div><input type="text" autocomplete="off" value="" tabindex="2" size="30" name="answer[new<?php echo $a; ?>]" /></div>
862
+ <a href="#" class="delete-answer delete" title="<?php echo attribute_escape( 'delete this answer' ); ?>">&times;</a>
863
+ </li>
864
+
865
+ <?php
866
+ endwhile;
867
+ ?>
868
+
869
+ </ul>
870
+
871
+ <p id="add-answer-holder">
872
+ <button class="button"><?php echo wp_specialchars( __( 'Add another' ) ); ?></button>
873
+ </p>
874
+
875
+ <ul id="answer-options">
876
+
877
+ <?php
878
+ foreach ( array( 'multipleChoice' => __( 'Multiple choice' ), 'randomiseAnswers' => __( 'Randomize answer order' ), 'otherAnswer' => __( 'Allow other answers' ) ) as $option => $label ) :
879
+ if ( $is_POST )
880
+ $checked = 'yes' === $_POST[$option] ? ' checked="checked"' : '';
881
+ else
882
+ $checked = 'yes' === $poll->$option ? ' checked="checked"' : '';
883
+ ?>
884
+
885
+ <li>
886
+ <label for="<?php echo $option; ?>"><input type="checkbox"<?php echo $checked; ?> value="yes" id="<?php echo $option; ?>" name="<?php echo $option; ?>" /> <?php echo wp_specialchars( $label ); ?></label>
887
+ </li>
888
+
889
+ <?php endforeach; ?>
890
+
891
+ </ul>
892
+ </div>
893
+ </div>
894
+
895
+ <div id="design">
896
+
897
+ <?php $style_ID = (int) ( $is_POST ? $_POST['styleID'] : $poll->styleID ); ?>
898
+
899
+ <h3><?php _e( 'Design' ); ?></h3>
900
+
901
+ <div class="hide-if-no-js">
902
+ <a class="alignleft" href="#previous">&#171;</a>
903
+ <a class="alignright" href="#next">&#187;</a>
904
+ <img src="http://polldaddy.com/Images/polls/<?php echo $style_ID; ?>.gif" />
905
+ <img class="hide-if-js" src="http://polldaddy.com/Images/polls/<?php echo 1 + $style_ID; ?>.gif" />
906
+ </div>
907
+
908
+ <p class="hide-if-js" id="no-js-styleID">
909
+ <select name="styleID">
910
+
911
+ <?php
912
+ $options = array(
913
+ 0 => 'Grey Plastic Standard',
914
+ 1 => 'White Plastic Standard',
915
+ 2 => 'Black Plastic Standard',
916
+ 3 => 'Simple Grey',
917
+ 4 => 'Simple White',
918
+ 5 => 'Simple Dark',
919
+ 6 => 'Thinking 1',
920
+ 7 => 'Thinking 2',
921
+ 8 => 'Manga',
922
+ 9 => 'Working 1',
923
+ 10 => 'Working 2',
924
+ 11 => 'SideBar Narrow (Dark)',
925
+ 12 => 'SideBar Narrow (Light)',
926
+ 13 => 'SideBar Narrow (Grey)',
927
+ 14 => 'Skulls',
928
+ 15 => 'Music',
929
+ 16 => 'Sunset',
930
+ 17 => 'Pink Butterflies',
931
+ 18 => 'Map'
932
+ );
933
+ foreach ( $options as $styleID => $label ) :
934
+ $selected = $styleID == $style_ID ? ' selected="selected"' : '';
935
+ ?>
936
+ <option value="<?php echo (int) $styleID; ?>"<?php echo $selected; ?>><?php echo wp_specialchars( $label ); ?></option>
937
+ <?php endforeach; ?>
938
+
939
+ </select>
940
+ </p>
941
+ </div>
942
+
943
+ <p class="submit">
944
+ <?php wp_nonce_field( $poll_id ? "edit-poll_$poll_id" : 'create-poll' ); ?>
945
+ <input type="hidden" name="action" value="<?php echo $poll_id ? 'edit-poll' : 'create-poll'; ?>" />
946
+ <input type="hidden" class="polldaddy-poll-id" name="poll" value="<?php echo $poll_id; ?>" />
947
+ <input type="submit" class="button button-highlighted" value="<?php echo attribute_escape( __( 'Save Poll' ) ); ?>" />
948
+
949
+ <?php if ( isset( $_GET['iframe'] ) && $poll_id ) : ?>
950
+
951
+ <input type="button" class="button polldaddy-send-to-editor" value="<?php echo attribute_escape( __( 'Send to Editor' ) ); ?>" />
952
+
953
+ <?php endif; ?>
954
+
955
+ </p>
956
+
957
+ </div></div></div>
958
+ </form>
959
+ <br class="clear" />
960
+
961
+ <?php
962
+ }
963
+
964
+ function poll_results_page( $poll_id ) {
965
+ $polldaddy = new $this->polldaddy_client_class( WP_POLLDADDY__PARTNERGUID, WP_POLLDADDY__USERCODE );
966
+
967
+ $results = $polldaddy->GetPollResults( $poll_id );
968
+ ?>
969
+
970
+ <table class="poll-results widefat">
971
+ <thead>
972
+ <tr>
973
+ <th scope="col" class="column-title"><?php _e( 'Answer' ); ?></th>
974
+ <th scope="col" class="column-vote"><?php _e( 'Votes' ); ?></th>
975
+ </tr>
976
+ </thead>
977
+ <tbody>
978
+
979
+ <?php
980
+ $class = '';
981
+ foreach ( $results->answers as $answer ) :
982
+ $class = $class ? '' : ' class="alternate"';
983
+ $content = $results->others && 'Other answer...' === $answer->___content ? sprintf( __( 'Other (<a href="%s">see below</a>)' ), '#other-answers-results' ) : wp_specialchars( $answer->___content );
984
+
985
+ ?>
986
+
987
+ <tr<?php echo $class; ?>>
988
+ <th scope="row" class="column-title"><?php echo $content; ?></th>
989
+ <td class="column-vote">
990
+ <div class="result-holder">
991
+ <span class="result-bar" style="width: <?php echo number_format( $answer->_percent, 2 ); ?>%;">&nbsp;</span>
992
+ <span class="result-total alignleft"><?php echo number_format_i18n( $answer->_total ); ?></span>
993
+ <span class="result-percent alignright"><?php echo number_format_i18n( $answer->_percent ); ?>%</span>
994
+ </div>
995
+ </td>
996
+ </tr>
997
+ <?php
998
+ endforeach;
999
+ ?>
1000
+
1001
+ </tbody>
1002
+ </table>
1003
+
1004
+ <?php
1005
+
1006
+ if ( !$results->others )
1007
+ return;
1008
+ ?>
1009
+
1010
+ <table id="other-answers-results" class="poll-others widefat">
1011
+ <thead>
1012
+ <tr>
1013
+ <th scope="col" class="column-title"><?php _e( 'Other Answer' ); ?></th>
1014
+ <th scope="col" class="column-vote"><?php _e( 'Votes' ); ?></th>
1015
+ </tr>
1016
+ </thead>
1017
+ <tbody>
1018
+
1019
+ <?php
1020
+ $class = '';
1021
+ $others = array_count_values( $results->others );
1022
+ arsort( $others );
1023
+ foreach ( $others as $other => $freq ) :
1024
+ $class = $class ? '' : ' class="alternate"';
1025
+ ?>
1026
+
1027
+ <tr<?php echo $class; ?>>
1028
+ <th scope="row" class="column-title"><?php echo wp_specialchars( $other ); ?></th>
1029
+ <td class="column-vote"><?php echo number_format_i18n( $freq ); ?></td>
1030
+ </tr>
1031
+ <?php
1032
+ endforeach;
1033
+ ?>
1034
+
1035
+ </tbody>
1036
+ </table>
1037
+
1038
+ <?php
1039
+ }
1040
+
1041
+ function signup() {
1042
+ return $this->api_key_page();
1043
+ }
1044
+
1045
+ function can_edit( &$poll ) {
1046
+ global $current_user;
1047
+ if ( empty( $poll->_owner ) )
1048
+ return true;
1049
+
1050
+ if ( $current_user->ID == $poll->_owner )
1051
+ return true;
1052
+
1053
+ return current_user_can( 'edit_others_posts' );
1054
+ }
1055
+ }
1056
+
1057
+ function polldaddy_loader() {
1058
+ global $polldaddy_object;
1059
+ $polldaddy_class = WP_POLLDADDY__CLASS;
1060
+ $polldaddy_object = new $polldaddy_class;
1061
+ add_action( 'admin_menu', array( &$polldaddy_object, 'admin_menu' ) );
1062
+ }
1063
+
1064
+ add_action( 'init', 'polldaddy_loader' );
1065
+
1066
+ function polldaddy_shortcode($atts, $content=null) {
1067
+ extract(shortcode_atts(array(
1068
+ 'poll' => 'empty',
1069
+ ), $atts));
1070
+
1071
+ $poll = (int) $poll;
1072
+
1073
+ return "<script type='text/javascript' language='javascript' src='http://s3.polldaddy.com/p/$poll.js'></script><noscript> <a href='http://answers.polldaddy.com/poll/$poll/'>View Poll</a></noscript>";
1074
+ }
1075
+
1076
+ add_shortcode('polldaddy', 'polldaddy_shortcode');
readme.txt ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === PollDaddy ===
2
+ Contributors: mdawaffe
3
+ Tags: poll, polls, polldaddy, WordPress.com
4
+ Requires at least: 2.6
5
+ Tested up to: 2.6.3
6
+ Stable tag: 0.8
7
+
8
+ Create and manage PollDaddy polls from within WordPress.
9
+
10
+ == Description ==
11
+
12
+ The PollDaddy plugin allows you to create and manage your [PollDaddy.com](http://polldaddy.com/) polls from within your WordPress blog's administration area.
13
+
14
+ == Installation ==
15
+
16
+ Upload the plugin to your blog, Activate it, then enter your PollDaddy.com email address and password.
17
+
18
+ == Frequently Asked Questions ==
19
+
20
+ = I have multiple authors on my blog? What happens? =
21
+
22
+ Each author that wants to create polls will need his or her own PollDaddy.com account.
23
+
24
+ = But, as an Administrator, can I edit my Authors' polls =
25
+
26
+ Yes. You'll be able to edit the polls they create from your blog. (You won't be able to edit any of their non-blog, personal polls they create through PollDaddy.com.)
27
+
28
+ = Neat! Um... can my Authors edit MY blog polls? =
29
+
30
+ Nope. The permissions are the same as for posts. So Editors and Administrators can edit anyone's polls for that blog. Authors can only edit their own.
31
+
32
+ == Change Log ==
33
+
34
+ = 0.8 =
35
+ * Bug fix: prevent some PHP define errors
36
+ * Bug fix: send content-length header when using wp_remote_post()
37
+
38
+ = 0.7 =
39
+ * Potential bug fix: Maybe get rid of 'Invalid Poll Author' error... again.
40
+
41
+ = 0.6 =
42
+ * Bug fix: Allow reauthentication with PollDaddy email address and PollDaddy password. This is necessary because the stored PollDaddy User API key is invalidated if the user's details change on PollDaddy.com.
43
+ * Buf fix: Speed up CSS and JS.
44
+ * Feature: Link to view Shortcode and JavaScript code for each poll.
45
+
46
+ = 0.5 =
47
+ * A few more helpful error messages.
48
+ * Bug fix: Password field should be a password field, not a text field.
49
+ * Potential bug fix: Maybe get rid of 'Invalid Poll Author' error.
50
+
51
+ = 0.4 =
52
+ * Bug fix: Shortcode handler was commented out in earlier versions.
53
+ * Bug fix: PHP Warning: in_array() [function.in-array]: Wrong datatype for second argument in polldaddy-xml.php on line 78
54
+
55
+ = 0.3 =
56
+ * Bug fix: Send text data escaped in CDATA to prevent XML errors.
57
+ * Bug fix: Append to text value, don't overwrite it. XML parser can call text handler many times per node.
58
+ * Bug fix: No more slashes when a poll reloads in the edit form after an error.
59
+
60
+ = 0.2 =
61
+ * Bug fix: Get rid of slashes.
62
+ * Bug fix: PHP Fatal Error: call to undefined function
63
+
64
+ = 0.1 =
65
+ * Initial release