PageRenderTime 57ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 1ms

/blog/wp-content/plugins/polldaddy/polldaddy.php

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 4477 lines | 4068 code | 396 blank | 13 comment | 524 complexity | 4570197ed0b395937eb9f34b958eae9b MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. Plugin Name: PollDaddy Polls
  4. Description: Create and manage PollDaddy polls and ratings in WordPress
  5. Author: Automattic, Inc.
  6. Author URL: http://automattic.com/
  7. Version: 1.8.9
  8. */
  9. // You can hardcode your PollDaddy PartnerGUID (API Key) here
  10. //define( 'WP_POLLDADDY__PARTNERGUID', '12345...' );
  11. class WP_PollDaddy {
  12. var $errors;
  13. var $base_url;
  14. var $is_admin;
  15. var $is_author;
  16. var $scheme;
  17. var $version;
  18. var $polldaddy_client_class;
  19. var $polldaddy_clients;
  20. var $id;
  21. var $multiple_accounts;
  22. var $user_code;
  23. var $rating_user_code;
  24. function WP_PollDaddy(){
  25. $this ->__construct();
  26. }
  27. function __construct() {
  28. global $current_user;
  29. $this->errors = new WP_Error;
  30. $this->scheme = 'https';
  31. $this->version = '1.8.8';
  32. $this->multiple_accounts = true;
  33. $this->polldaddy_client_class = 'api_client';
  34. $this->polldaddy_clients = array();
  35. $this->is_admin = (bool) current_user_can('manage_options');
  36. $this->is_author = true;
  37. $this->id = (int) $current_user->ID;
  38. $this->user_code = null;
  39. $this->rating_user_code = null;
  40. }
  41. function &get_client( $api_key, $userCode = null ) {
  42. if ( isset( $this->polldaddy_clients[$api_key] ) ) {
  43. if ( !is_null( $userCode ) )
  44. $this->polldaddy_clients[$api_key]->userCode = $userCode;
  45. return $this->polldaddy_clients[$api_key];
  46. }
  47. require_once WP_POLLDADDY__POLLDADDY_CLIENT_PATH;
  48. $this->polldaddy_clients[$api_key] = $this->config_client( new $this->polldaddy_client_class( $api_key, $userCode ) );
  49. return $this->polldaddy_clients[$api_key];
  50. }
  51. function config_client( $client ){
  52. return $client;
  53. }
  54. function admin_menu() {
  55. if ( !defined( 'WP_POLLDADDY__PARTNERGUID' ) ) {
  56. $guid = get_option( 'polldaddy_api_key' );
  57. if ( !$guid || !is_string( $guid ) )
  58. $guid = false;
  59. define( 'WP_POLLDADDY__PARTNERGUID', $guid );
  60. }
  61. if ( !WP_POLLDADDY__PARTNERGUID ) {
  62. if ( function_exists( 'add_object_page' ) ) // WP 2.7+
  63. $hook = add_object_page( __( 'Ratings', 'polldaddy' ), __( 'Ratings', 'polldaddy' ), 'edit_posts', 'ratings', array( &$this, 'api_key_page' ), "{$this->base_url}polldaddy.png" );
  64. else
  65. $hook = add_management_page( __( 'Ratings', 'polldaddy' ), __( 'Ratings', 'polldaddy' ), 'edit_posts', 'ratings', array( &$this, 'api_key_page' ) );
  66. add_action( "load-$hook", array( &$this, 'api_key_page_load' ) );
  67. if ( function_exists( 'add_object_page' ) ) // WP 2.7+
  68. $hook = add_object_page( __( 'Polls', 'polldaddy' ), __( 'Polls', 'polldaddy' ), 'edit_posts', 'polls', array( &$this, 'api_key_page' ), "{$this->base_url}polldaddy.png" );
  69. else
  70. $hook = add_management_page( __( 'Polls', 'polldaddy' ), __( 'Polls', 'polldaddy' ), 'edit_posts', 'polls', array( &$this, 'api_key_page' ) );
  71. add_action( "load-$hook", array( &$this, 'api_key_page_load' ) );
  72. if ( ( empty( $_GET['page'] ) || 'polls' != $_GET['page'] ) && ( empty( $_GET['page'] ) || 'ratings' != $_GET['page'] ) )
  73. 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>";' ) );
  74. return false;
  75. }
  76. if ( function_exists( 'add_object_page' ) ) // WP 2.7+
  77. $hook = add_object_page( __( 'Ratings', 'polldaddy' ), __( 'Ratings', 'polldaddy' ), 'edit_posts', 'ratings', array( &$this, 'management_page' ), "{$this->base_url}polldaddy.png" );
  78. else
  79. $hook = add_management_page( __( 'Ratings', 'polldaddy' ), __( 'Ratings', 'polldaddy' ), 'edit_posts', 'ratings', array( &$this, 'management_page' ) );
  80. add_action( "load-$hook", array( &$this, 'management_page_load' ) );
  81. if ( function_exists( 'add_object_page' ) ) // WP 2.7+
  82. $hook = add_object_page( __( 'Polls', 'polldaddy' ), __( 'Polls', 'polldaddy' ), 'edit_posts', 'polls', array( &$this, 'management_page' ), "{$this->base_url}polldaddy.png" );
  83. else
  84. $hook = add_management_page( __( 'Polls', 'polldaddy' ), __( 'Polls', 'polldaddy' ), 'edit_posts', 'polls', array( &$this, 'management_page' ) );
  85. add_action( "load-$hook", array( &$this, 'management_page_load' ) );
  86. if ( $this->is_admin ) {
  87. add_submenu_page( 'ratings', __( 'Ratings &ndash; Settings', 'polldaddy' ), __( 'Settings', 'polldaddy' ), 'edit_posts', 'ratings', array( &$this, 'management_page' ) );
  88. add_submenu_page( 'ratings', __( 'Ratings &ndash; Reports', 'polldaddy' ), __( 'Reports', 'polldaddy' ), 'edit_posts', 'ratings&amp;action=reports', array( &$this, 'management_page' ) );
  89. }
  90. else{
  91. add_submenu_page( 'ratings', __( 'Ratings &ndash; Reports', 'polldaddy' ), __( 'Reports', 'polldaddy' ), 'edit_posts', 'ratings', array( &$this, 'management_page' ) );
  92. }
  93. add_submenu_page( 'polls', __( 'Polls', 'polldaddy' ), __( 'Edit', 'polldaddy' ), 'edit_posts', 'polls', array( &$this, 'management_page' ) );
  94. if ( $this->is_author ) {
  95. add_submenu_page( 'polls', __( 'Add New Poll', 'polldaddy' ), __( 'Add New', 'polldaddy' ), 'edit_posts', 'polls&amp;action=create-poll', array( &$this, 'management_page' ) );
  96. add_submenu_page( 'polls', __( 'Custom Styles', 'polldaddy' ), __( 'Custom Styles', 'polldaddy' ), 'edit_posts', 'polls&amp;action=list-styles', array( &$this, 'management_page' ) );
  97. add_submenu_page( 'polls', __( 'Options', 'polldaddy' ), __( 'Options', 'polldaddy' ), 'edit_posts', 'polls&amp;action=options', array( &$this, 'management_page' ) );
  98. }
  99. add_action( 'media_buttons', array( &$this, 'media_buttons' ) );
  100. }
  101. function api_key_page_load() {
  102. if ( 'post' != strtolower( $_SERVER['REQUEST_METHOD'] ) || empty( $_POST['action'] ) || 'account' != $_POST['action'] )
  103. return false;
  104. check_admin_referer( 'polldaddy-account' );
  105. $polldaddy_email = stripslashes( $_POST['polldaddy_email'] );
  106. $polldaddy_password = stripslashes( $_POST['polldaddy_password'] );
  107. if ( !$polldaddy_email )
  108. $this->errors->add( 'polldaddy_email', __( 'Email address required', 'polldaddy' ) );
  109. if ( !$polldaddy_password )
  110. $this->errors->add( 'polldaddy_password', __( 'Password required', 'polldaddy' ) );
  111. if ( $this->errors->get_error_codes() )
  112. return false;
  113. $details = array(
  114. 'uName' => get_bloginfo( 'name' ),
  115. 'uEmail' => $polldaddy_email,
  116. 'uPass' => $polldaddy_password,
  117. 'partner_userid' => $this->id
  118. );
  119. if ( function_exists( 'wp_remote_post' ) ) { // WP 2.7+
  120. $polldaddy_api_key = wp_remote_post( $this->scheme . '://api.polldaddy.com/key.php', array(
  121. 'body' => $details
  122. ) );
  123. if ( is_wp_error( $polldaddy_api_key ) ) {
  124. $this->errors = $polldaddy_api_key;
  125. return false;
  126. }
  127. $polldaddy_api_key = wp_remote_retrieve_body( $polldaddy_api_key );
  128. } else {
  129. $fp = fsockopen(
  130. 'api.polldaddy.com',
  131. 80,
  132. $err_num,
  133. $err_str,
  134. 3
  135. );
  136. if ( !$fp ) {
  137. $this->errors->add( 'connect', __( "Can't connect to PollDaddy.com", 'polldaddy' ) );
  138. return false;
  139. }
  140. if ( function_exists( 'stream_set_timeout' ) )
  141. stream_set_timeout( $fp, 3 );
  142. global $wp_version;
  143. $request_body = http_build_query( $details, null, '&' );
  144. $request = "POST /key.php HTTP/1.0\r\n";
  145. $request .= "Host: api.polldaddy.com\r\n";
  146. $request .= "User-agent: WordPress/$wp_version\r\n";
  147. $request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option('blog_charset') . "\r\n";
  148. $request .= 'Content-Length: ' . strlen( $request_body ) . "\r\n";
  149. fwrite( $fp, "$request\r\n$request_body" );
  150. $response = '';
  151. while ( !feof( $fp ) )
  152. $response .= fread( $fp, 4096 );
  153. fclose( $fp );
  154. list($headers, $polldaddy_api_key) = explode( "\r\n\r\n", $response, 2 );
  155. }
  156. if ( !$polldaddy_api_key ) {
  157. $this->errors->add( 'polldaddy_password', __( 'Invalid Account', 'polldaddy' ) );
  158. return false;
  159. }
  160. update_option( 'polldaddy_api_key', $polldaddy_api_key );
  161. $polldaddy = $this->get_client( $polldaddy_api_key );
  162. $polldaddy->reset();
  163. if ( !$polldaddy->get_usercode( $this->id ) ) {
  164. $this->parse_errors( $polldaddy );
  165. $this->errors->add( 'GetUserCode', __( 'Account could not be accessed. Are your email address and password correct?', 'polldaddy' ) );
  166. return false;
  167. }
  168. return true;
  169. }
  170. function parse_errors( &$polldaddy ) {
  171. if ( $polldaddy->errors )
  172. foreach ( $polldaddy->errors as $code => $error )
  173. $this->errors->add( $code, $error );
  174. if ( isset( $this->errors->errors[4] ) ) {
  175. $this->errors->errors[4] = array( sprintf( __( 'Obsolete PollDaddy User API Key: <a href="%s">Sign in again to re-authenticate</a>', 'polldaddy' ), add_query_arg( array( 'action' => 'signup', 'reaction' => empty( $_GET['action'] ) ? false : $_GET['action'] ) ) ) );
  176. $this->errors->add_data( true, 4 );
  177. }
  178. }
  179. function print_errors() {
  180. if ( !$error_codes = $this->errors->get_error_codes() )
  181. return;
  182. ?>
  183. <div class="error">
  184. <?php
  185. foreach ( $error_codes as $error_code ) :
  186. foreach ( $this->errors->get_error_messages( $error_code ) as $error_message ) :
  187. ?>
  188. <p><?php echo $this->errors->get_error_data( $error_code ) ? $error_message : wp_specialchars( $error_message ); ?></p>
  189. <?php
  190. endforeach;
  191. endforeach;
  192. $this->errors = new WP_Error;
  193. ?>
  194. </div>
  195. <br class="clear" />
  196. <?php
  197. }
  198. function api_key_page() {
  199. $this->print_errors();
  200. ?>
  201. <div class="wrap">
  202. <h2><?php _e( 'PollDaddy Account', 'polldaddy' ); ?></h2>
  203. <p><?php printf( __( 'Before you can use the PollDaddy plugin, you need to enter your <a href="%s">PollDaddy.com</a> account details.', 'polldaddy' ), 'http://polldaddy.com/' ); ?></p>
  204. <form action="" method="post">
  205. <table class="form-table">
  206. <tbody>
  207. <tr class="form-field form-required">
  208. <th valign="top" scope="row">
  209. <label for="polldaddy-email"><?php _e( 'PollDaddy Email Address', 'polldaddy' ); ?></label>
  210. </th>
  211. <td>
  212. <input type="text" name="polldaddy_email" id="polldaddy-email" aria-required="true" size="40" />
  213. </td>
  214. </tr>
  215. <tr class="form-field form-required">
  216. <th valign="top" scope="row">
  217. <label for="polldaddy-password"><?php _e( 'PollDaddy Password', 'polldaddy' ); ?></label>
  218. </th>
  219. <td>
  220. <input type="password" name="polldaddy_password" id="polldaddy-password" aria-required="true" size="40" />
  221. </td>
  222. </tr>
  223. </tbody>
  224. </table>
  225. <p class="submit">
  226. <?php wp_nonce_field( 'polldaddy-account' ); ?>
  227. <input type="hidden" name="action" value="account" />
  228. <input type="hidden" name="account" value="import" />
  229. <input type="submit" value="<?php echo attribute_escape( __( 'Submit', 'polldaddy' ) ); ?>" />
  230. </p>
  231. </form>
  232. </div>
  233. <?php
  234. }
  235. function media_buttons() {
  236. $title = __( 'Add Poll', 'polldaddy' );
  237. echo "<a href='admin.php?page=polls&amp;iframe&amp;TB_iframe=true' onclick='return false;' id='add_poll' class='thickbox' title='$title'><img src='{$this->base_url}polldaddy.png' alt='$title' /></a>";
  238. }
  239. function set_api_user_code(){
  240. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID );
  241. $polldaddy->reset();
  242. if ( empty( $this->user_code ) ){
  243. $this->user_code = $polldaddy->get_usercode( $this->id );
  244. }
  245. }
  246. function management_page_load() {
  247. wp_reset_vars( array( 'page', 'action', 'poll', 'style', 'rating', 'id' ) );
  248. global $plugin_page, $page, $action, $poll, $style, $rating, $id, $wp_locale;
  249. $this->set_api_user_code();
  250. if ( empty( $this->user_code ) && $page == 'polls' ){
  251. $action = 'signup';
  252. }
  253. require_once WP_POLLDADDY__POLLDADDY_CLIENT_PATH;
  254. wp_enqueue_script( 'polls', "{$this->base_url}polldaddy.js", array( 'jquery', 'jquery-ui-sortable' ), $this->version );
  255. wp_enqueue_script( 'polls-common', "{$this->base_url}common.js", array(), $this->version );
  256. if( $page == 'polls' ) {
  257. if ( !$this->is_author && in_array( $action, array( 'edit', 'edit-poll', 'create-poll', 'edit-style', 'create-style', 'list-styles', 'options', 'update-options', 'import-account' ) ) ) {//check user privileges has access to action
  258. $action = '';
  259. }
  260. switch ( $action ) :
  261. case 'edit' :
  262. case 'edit-poll' :
  263. case 'create-poll' :
  264. wp_enqueue_script( 'polls-style', "http://i.polldaddy.com/js/poll-style-picker.js", array(), $this->version );
  265. if ( $action == 'create-poll' )
  266. $plugin_page = 'polls&amp;action=create-poll';
  267. break;
  268. case 'edit-style' :
  269. case 'create-style' :
  270. wp_enqueue_script( 'polls-style', "http://i.polldaddy.com/js/style-editor.js", array(), $this->version );
  271. wp_enqueue_script( 'polls-style-color', "http://i.polldaddy.com/js/jquery/jscolor.js", array(), $this->version );
  272. wp_enqueue_style( 'polls', "{$this->base_url}style-editor.css", array(), $this->version );
  273. $plugin_page = 'polls&amp;action=list-styles';
  274. break;
  275. case 'list-styles' :
  276. $plugin_page = 'polls&amp;action=list-styles';
  277. break;
  278. case 'options' :
  279. case 'update-options' :
  280. case 'import-account' :
  281. $plugin_page = 'polls&amp;action=options';
  282. break;
  283. endswitch;
  284. } elseif( $page == 'ratings' ) {
  285. if ( !$this->is_admin && !in_array( $action, array( 'reports', 'delete' ) ) ) {//check user privileges has access to action
  286. $action = 'reports';
  287. }
  288. switch ( $action ) :
  289. case 'delete' :
  290. case 'reports' :
  291. $plugin_page = 'ratings&amp;action=reports';
  292. break;
  293. default :
  294. wp_enqueue_script( 'rating-text-color', "http://i.polldaddy.com/js/jquery/jscolor.js", array(), $this->version );
  295. wp_enqueue_script( 'ratings', 'http://i.polldaddy.com/ratings/rating.js', array(), $this->version );
  296. wp_localize_script( 'polls-common', 'adminRatingsL10n', array(
  297. 'star_colors' => __( 'Star Colors', 'polldaddy' ), 'star_size' => __( 'Star Size', 'polldaddy' ),
  298. 'nero_type' => __( 'Nero Type', 'polldaddy' ), 'nero_size' => __( 'Nero Size', 'polldaddy' ), ) );
  299. endswitch;
  300. }
  301. wp_enqueue_script( 'admin-forms' );
  302. add_thickbox();
  303. wp_enqueue_style( 'polls', "{$this->base_url}polldaddy.css", array( 'global', 'wp-admin' ), $this->version );
  304. if ( isset($wp_locale->text_direction) && 'rtl' == $wp_locale->text_direction )
  305. wp_enqueue_style( 'polls-rtl', "{$this->base_url}polldaddy-rtl.css", array( 'global', 'wp-admin' ), $this->version );
  306. add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
  307. add_action( 'admin_notices', array( &$this, 'management_page_notices' ) );
  308. $query_args = array();
  309. $args = array();
  310. $allowedtags = array(
  311. 'a' => array(
  312. 'href' => array (),
  313. 'title' => array (),
  314. 'target' => array ()),
  315. 'img' => array(
  316. 'alt' => array (),
  317. 'align' => array (),
  318. 'border' => array (),
  319. 'class' => array (),
  320. 'height' => array (),
  321. 'hspace' => array (),
  322. 'longdesc' => array (),
  323. 'vspace' => array (),
  324. 'src' => array (),
  325. 'width' => array ()),
  326. 'abbr' => array(
  327. 'title' => array ()),
  328. 'acronym' => array(
  329. 'title' => array ()),
  330. 'b' => array(),
  331. 'blockquote' => array(
  332. 'cite' => array ()),
  333. 'cite' => array (),
  334. 'em' => array (),
  335. 'i' => array (),
  336. 'q' => array(
  337. 'cite' => array ()),
  338. 'strike' => array(),
  339. 'strong' => array()
  340. );
  341. $is_POST = 'post' == strtolower( $_SERVER['REQUEST_METHOD'] );
  342. if( $page == 'polls' ) {
  343. switch ( $action ) :
  344. case 'signup' : // sign up for first time
  345. case 'account' : // reauthenticate
  346. case 'import-account' : // reauthenticate
  347. if ( !$is_POST )
  348. return;
  349. check_admin_referer( 'polldaddy-account' );
  350. if ( $new_args = $this->management_page_load_signup() )
  351. $query_args = array_merge( $query_args, $new_args );
  352. if ( $this->errors->get_error_codes() )
  353. return false;
  354. $query_args['message'] = 'imported-account';
  355. wp_reset_vars( array( 'action' ) );
  356. if ( !empty( $_GET['reaction'] ) )
  357. $query_args['action'] = $_GET['reaction'];
  358. elseif ( !empty( $_GET['action'] ) && 'account' == $_GET['action'] )
  359. $query_args['action'] = $_GET['action'];
  360. else
  361. $query_args['action'] = false;
  362. break;
  363. case 'delete' :
  364. if ( empty( $poll ) )
  365. return;
  366. if ( is_array( $poll ) )
  367. check_admin_referer( 'action-poll_bulk' );
  368. else
  369. check_admin_referer( "delete-poll_$poll" );
  370. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->user_code );
  371. foreach ( (array) $_REQUEST['poll'] as $poll_id ) {
  372. $polldaddy->reset();
  373. $poll_object = $polldaddy->get_poll( $poll );
  374. if ( !$this->can_edit( $poll_object ) ) {
  375. $this->errors->add( 'permission', __( 'You are not allowed to delete this poll.', 'polldaddy' ) );
  376. return false;
  377. }
  378. // Send Poll Author credentials
  379. if ( !empty( $poll_object->_owner ) && $this->id != $poll_object->_owner ) {
  380. $polldaddy->reset();
  381. if ( !$userCode = $polldaddy->get_usercode( $poll_object->_owner ) ) {
  382. $this->errors->add( 'no_usercode', __( 'Invalid Poll Author', 'polldaddy' ) );
  383. }
  384. $polldaddy->userCode = $userCode;
  385. }
  386. $polldaddy->reset();
  387. $polldaddy->delete_poll( $poll_id );
  388. }
  389. $query_args['message'] = 'deleted';
  390. $query_args['deleted'] = count( (array) $poll );
  391. break;
  392. case 'open' :
  393. if ( empty( $poll ) )
  394. return;
  395. if ( is_array( $poll ) )
  396. check_admin_referer( 'action-poll_bulk' );
  397. else
  398. check_admin_referer( "open-poll_$poll" );
  399. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->user_code );
  400. foreach ( (array) $_REQUEST['poll'] as $poll_id ) {
  401. $polldaddy->reset();
  402. $poll_object = $polldaddy->get_poll( $poll );
  403. if ( !$this->can_edit( $poll_object ) ) {
  404. $this->errors->add( 'permission', __( 'You are not allowed to open this poll.', 'polldaddy' ) );
  405. return false;
  406. }
  407. // Send Poll Author credentials
  408. if ( !empty( $poll_object->_owner ) && $this->id != $poll_object->_owner ) {
  409. $polldaddy->reset();
  410. if ( !$userCode = $polldaddy->get_usercode( $poll_object->_owner ) ) {
  411. $this->errors->add( 'no_usercode', __( 'Invalid Poll Author', 'polldaddy' ) );
  412. }
  413. $polldaddy->userCode = $userCode;
  414. }
  415. $polldaddy->reset();
  416. $polldaddy->open_poll( $poll_id );
  417. }
  418. $query_args['message'] = 'opened';
  419. $query_args['opened'] = count( (array) $poll );
  420. break;
  421. case 'close' :
  422. if ( empty( $poll ) )
  423. return;
  424. if ( is_array( $poll ) )
  425. check_admin_referer( 'action-poll_bulk' );
  426. else
  427. check_admin_referer( "close-poll_$poll" );
  428. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->user_code );
  429. foreach ( (array) $_REQUEST['poll'] as $poll_id ) {
  430. $polldaddy->reset();
  431. $poll_object = $polldaddy->get_poll( $poll );
  432. if ( !$this->can_edit( $poll_object ) ) {
  433. $this->errors->add( 'permission', __( 'You are not allowed to close this poll.', 'polldaddy' ) );
  434. return false;
  435. }
  436. // Send Poll Author credentials
  437. if ( !empty( $poll_object->_owner ) && $this->id != $poll_object->_owner ) {
  438. $polldaddy->reset();
  439. if ( !$userCode = $polldaddy->get_usercode( $poll_object->_owner ) ) {
  440. $this->errors->add( 'no_usercode', __( 'Invalid Poll Author', 'polldaddy' ) );
  441. }
  442. $polldaddy->userCode = $userCode;
  443. }
  444. $polldaddy->reset();
  445. $polldaddy->close_poll( $poll_id );
  446. }
  447. $query_args['message'] = 'closed';
  448. $query_args['closed'] = count( (array) $poll );
  449. break;
  450. case 'edit-poll' : // TODO: use polldaddy_poll
  451. if ( !$is_POST || !$poll = (int) $poll )
  452. return;
  453. check_admin_referer( "edit-poll_$poll" );
  454. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->user_code );
  455. $polldaddy->reset();
  456. $poll_object = $polldaddy->get_poll( $poll );
  457. $this->parse_errors( $polldaddy );
  458. if ( !$this->can_edit( $poll_object ) ) {
  459. $this->errors->add( 'permission', __( 'You are not allowed to edit this poll.', 'polldaddy' ) );
  460. return false;
  461. }
  462. // Send Poll Author credentials
  463. if ( !empty( $poll_object->_owner ) && $this->id != $poll_object->_owner ) {
  464. $polldaddy->reset();
  465. if ( !$userCode = $polldaddy->get_usercode( $poll_object->_owner ) ) {
  466. $this->errors->add( 'no_usercode', __( 'Invalid Poll Author', 'polldaddy' ) );
  467. }
  468. $this->parse_errors( $polldaddy );
  469. $polldaddy->userCode = $userCode;
  470. }
  471. if ( !$poll_object )
  472. $this->errors->add( 'GetPoll', __( 'Poll not found', 'polldaddy' ) );
  473. if ( $this->errors->get_error_codes() )
  474. return false;
  475. $poll_data = get_object_vars( $poll_object );
  476. foreach ( $poll_data as $key => $value )
  477. if ( '_' === $key[0] )
  478. unset( $poll_data[$key] );
  479. foreach ( array( 'multipleChoice', 'randomiseAnswers', 'otherAnswer', 'sharing' ) as $option ) {
  480. if ( isset( $_POST[$option] ) && $_POST[$option] )
  481. $poll_data[$option] = 'yes';
  482. else
  483. $poll_data[$option] = 'no';
  484. }
  485. $blocks = array( 'off', 'cookie', 'cookieip' );
  486. if ( isset( $_POST['blockRepeatVotersType'] ) && in_array( $_POST['blockRepeatVotersType'], $blocks ) )
  487. $poll_data['blockRepeatVotersType'] = $_POST['blockRepeatVotersType'];
  488. $results = array( 'show', 'percent', 'hide' );
  489. if ( isset( $_POST['resultsType'] ) && in_array( $_POST['resultsType'], $results ) )
  490. $poll_data['resultsType'] = $_POST['resultsType'];
  491. $poll_data['question'] = stripslashes( $_POST['question'] );
  492. if ( empty( $_POST['answer'] ) || !is_array( $_POST['answer'] ) )
  493. $this->errors->add( 'answer', __( 'Invalid answers', 'polldaddy' ) );
  494. $answers = array();
  495. foreach ( $_POST['answer'] as $answer_id => $answer ) {
  496. if ( !$answer = trim( stripslashes( $answer ) ) )
  497. continue;
  498. $args['text'] = wp_kses( $answer, $allowedtags );
  499. if ( is_numeric( $answer_id ) )
  500. $answers[] = polldaddy_poll_answer( $args, $answer_id );
  501. else
  502. $answers[] = polldaddy_poll_answer( $args );
  503. }
  504. if ( 2 > count( $answers ) )
  505. $this->errors->add( 'answer', __( 'You must include at least 2 answers', 'polldaddy' ) );
  506. if ( $this->errors->get_error_codes() )
  507. return false;
  508. $poll_data['answers'] = $answers;
  509. $poll_data['question'] = wp_kses( $poll_data['question'], $allowedtags );
  510. if ( isset ( $_POST['styleID'] ) ){
  511. if ( $_POST['styleID'] == 'x' ){
  512. $this->errors->add( 'UpdatePoll', __( 'Please choose a poll style', 'polldaddy' ) );
  513. return false;
  514. }
  515. }
  516. $poll_data['styleID'] = (int) $_POST['styleID'];
  517. $poll_data['choices'] = (int) $_POST['choices'];
  518. if ( $poll_data['blockRepeatVotersType'] == 'cookie' ){
  519. if( isset( $_POST['cookieip_expiration'] ) )
  520. $poll_data['blockExpiration'] = (int) $_POST['cookieip_expiration'];
  521. } elseif ( $poll_data['blockRepeatVotersType'] == 'cookieip' ){
  522. if( isset( $_POST['cookieip_expiration'] ) )
  523. $poll_data['blockExpiration'] = (int) $_POST['cookieip_expiration'];
  524. }
  525. $polldaddy->reset();
  526. $update_response = $polldaddy->update_poll( $poll, $poll_data );
  527. $this->parse_errors( $polldaddy );
  528. if ( !$update_response )
  529. $this->errors->add( 'UpdatePoll', __( 'Poll could not be updated', 'polldaddy' ) );
  530. if ( $this->errors->get_error_codes() )
  531. return false;
  532. $query_args['message'] = 'updated';
  533. if ( isset($_POST['iframe']) )
  534. $query_args['iframe'] = '';
  535. break;
  536. case 'create-poll' :
  537. if ( !$is_POST )
  538. return;
  539. check_admin_referer( 'create-poll' );
  540. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->user_code );
  541. $polldaddy->reset();
  542. $answers = array();
  543. foreach ( $_POST['answer'] as $answer ){
  544. if ( !$answer = trim( stripslashes( $answer ) ) )
  545. continue;
  546. $args['text'] = wp_kses( $answer, $allowedtags );
  547. $answers[] = polldaddy_poll_answer( $args );
  548. }
  549. if ( !$answers )
  550. return false;
  551. $poll_data = _polldaddy_poll_defaults();
  552. foreach ( array( 'multipleChoice', 'randomiseAnswers', 'otherAnswer', 'sharing' ) as $option ) {
  553. if ( isset( $_POST[$option] ) && $_POST[$option] )
  554. $poll_data[$option] = 'yes';
  555. else
  556. $poll_data[$option] = 'no';
  557. }
  558. $blocks = array( 'off', 'cookie', 'cookieip' );
  559. if ( isset( $_POST['blockRepeatVotersType'] ) && in_array( $_POST['blockRepeatVotersType'], $blocks ) )
  560. $poll_data['blockRepeatVotersType'] = $_POST['blockRepeatVotersType'];
  561. $results = array( 'show', 'percent', 'hide' );
  562. if ( isset( $_POST['resultsType'] ) && in_array( $_POST['resultsType'], $results ) )
  563. $poll_data['resultsType'] = $_POST['resultsType'];
  564. $poll_data['answers'] = $answers;
  565. $poll_data['question'] = stripslashes( $_POST['question'] );
  566. $poll_data['question'] = wp_kses( $poll_data['question'], $allowedtags );
  567. if ( isset ( $_POST['styleID'] ) ){
  568. if ( $_POST['styleID'] == 'x' ){
  569. $this->errors->add( 'UpdatePoll', __( 'Please choose a poll style', 'polldaddy' ) );
  570. return false;
  571. }
  572. }
  573. $poll_data['styleID'] = (int) $_POST['styleID'];
  574. $poll_data['choices'] = (int) $_POST['choices'];
  575. if ( $poll_data['blockRepeatVotersType'] == 'cookie' ){
  576. if( isset( $_POST['cookieip_expiration'] ) )
  577. $poll_data['blockExpiration'] = (int) $_POST['cookieip_expiration'];
  578. } elseif ( $poll_data['blockRepeatVotersType'] == 'cookieip' ){
  579. if( isset( $_POST['cookieip_expiration'] ) )
  580. $poll_data['blockExpiration'] = (int) $_POST['cookieip_expiration'];
  581. }
  582. $poll = $polldaddy->create_poll( $poll_data );
  583. $this->parse_errors( $polldaddy );
  584. if ( !$poll || empty( $poll->_id ) )
  585. $this->errors->add( 'CreatePoll', __( 'Poll could not be created', 'polldaddy' ) );
  586. if ( $this->errors->get_error_codes() )
  587. return false;
  588. $query_args['message'] = 'created';
  589. $query_args['action'] = 'edit-poll';
  590. $query_args['poll'] = $poll->_id;
  591. if ( isset($_POST['iframe']) )
  592. $query_args['iframe'] = '';
  593. break;
  594. case 'delete-style' :
  595. if ( empty( $style ) )
  596. return;
  597. if ( is_array( $style ) )
  598. check_admin_referer( 'action-style_bulk' );
  599. else
  600. check_admin_referer( "delete-style_$style" );
  601. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->user_code );
  602. foreach ( (array) $_REQUEST['style'] as $style_id ) {
  603. $polldaddy->reset();
  604. $polldaddy->delete_style( $style_id );
  605. }
  606. $query_args['message'] = 'deleted-style';
  607. $query_args['deleted'] = count( (array) $style );
  608. break;
  609. case 'edit-style' :
  610. if ( !$is_POST || !$style = (int) $style )
  611. return;
  612. check_admin_referer( "edit-style$style" );
  613. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->user_code );
  614. $polldaddy->reset();
  615. $style_data = _polldaddy_style_defaults();
  616. if ( isset($_POST['style-title'] ) )
  617. $style_data['title'] = stripslashes( trim ( (string) $_POST['style-title'] ) );
  618. if ( isset($_POST['CSSXML'] ) )
  619. $style_data['css'] = urlencode( stripslashes( trim ( (string) $_POST['CSSXML'] ) ) );
  620. if ( isset($_REQUEST['updatePollCheck'] ) && $_REQUEST['updatePollCheck'] == 'on' )
  621. $style_data['retro'] = 1;
  622. $update_response = $polldaddy->update_style( $style, $style_data );
  623. $this->parse_errors( $polldaddy );
  624. if ( !$update_response )
  625. $this->errors->add( 'UpdateStyle', __( 'Style could not be updated', 'polldaddy' ) );
  626. if ( $this->errors->get_error_codes() )
  627. return false;
  628. $query_args['message'] = 'updated-style';
  629. if ( isset($_POST['iframe']) )
  630. $query_args['iframe'] = '';
  631. break;
  632. case 'create-style' :
  633. if ( !$is_POST )
  634. return;
  635. check_admin_referer( 'create-style' );
  636. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->user_code );
  637. $polldaddy->reset();
  638. $style_data = _polldaddy_style_defaults();
  639. if ( isset($_POST['style-title'] ) )
  640. $style_data['title'] = stripslashes( strip_tags( trim ( (string) $_POST['style-title'] ) ) );
  641. if ( isset($_POST['CSSXML'] ) )
  642. $style_data['css'] = urlencode( stripslashes( trim ( (string) $_POST['CSSXML'] ) ) );
  643. $style = $polldaddy->create_style( $style_data );
  644. $this->parse_errors( $polldaddy );
  645. if ( !$style || empty( $style->_id ) )
  646. $this->errors->add( 'CreateStyle', __( 'Style could not be created', 'polldaddy' ) );
  647. if ( $this->errors->get_error_codes() )
  648. return false;
  649. $query_args['message'] = 'created-style';
  650. $query_args['action'] = 'edit-style';
  651. $query_args['style'] = $style->_id;
  652. if ( isset($_POST['iframe']) )
  653. $query_args['iframe'] = '';
  654. break;
  655. case 'update-options' :
  656. if ( !$is_POST )
  657. return;
  658. check_admin_referer( 'polldaddy-account' );
  659. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->user_code );
  660. $polldaddy->reset();
  661. $poll_defaults = _polldaddy_poll_defaults();
  662. $user_defaults = array();
  663. foreach( array( "multipleChoice", "randomiseAnswers", "otherAnswer", "sharing", "resultsType", "styleID", "blockRepeatVotersType", "blockExpiration" ) as $option ){
  664. if ( isset( $poll_defaults[$option] ) && $poll_defaults[$option] )
  665. $user_defaults[$option] = $poll_defaults[$option];
  666. }
  667. foreach ( array( 'multipleChoice', 'randomiseAnswers', 'otherAnswer', 'sharing' ) as $option ) {
  668. if ( isset( $_POST[$option] ) && $_POST[$option] )
  669. $user_defaults[$option] = 'yes';
  670. else
  671. $user_defaults[$option] = 'no';
  672. }
  673. $results = array( 'show', 'percent', 'hide' );
  674. if ( isset( $_POST['resultsType'] ) && in_array( $_POST['resultsType'], $results ) )
  675. $user_defaults['resultsType'] = $_POST['resultsType'];
  676. if ( isset ( $_POST['styleID'] ) ){
  677. $user_defaults['styleID'] = (int) $_POST['styleID'];
  678. }
  679. $blocks = array( 'off', 'cookie', 'cookieip' );
  680. if ( isset( $_POST['blockRepeatVotersType'] ) && in_array( $_POST['blockRepeatVotersType'], $blocks ) )
  681. $user_defaults['blockRepeatVotersType'] = $_POST['blockRepeatVotersType'];
  682. if( isset( $_POST['blockExpiration'] ) )
  683. $user_defaults['blockExpiration'] = (int) $_POST['blockExpiration'];
  684. $polldaddy->update_poll_defaults( 0, $user_defaults );
  685. $this->parse_errors( $polldaddy );
  686. if ( $this->errors->get_error_codes() )
  687. return false;
  688. $query_args['message'] = 'updated-options';
  689. break;
  690. default :
  691. return;
  692. endswitch;
  693. } elseif( $page == 'ratings' ) {
  694. switch ( $action ) :
  695. case 'delete' :
  696. if ( empty( $id ) )
  697. return;
  698. if ( empty( $rating ) )
  699. return;
  700. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->rating_user_code );
  701. if ( is_array( $rating ) ) {
  702. check_admin_referer( 'action-rating_bulk' );
  703. foreach( $rating as $key => $value ){
  704. $polldaddy->reset();
  705. $polldaddy->delete_rating_result( $id, $value );
  706. }
  707. } else {
  708. check_admin_referer( "delete-rating_$rating" );
  709. $polldaddy->delete_rating_result( $id, $rating );
  710. }
  711. if ( isset( $_REQUEST['filter'] ) )
  712. $query_args['filter'] = $_REQUEST['filter'];
  713. if ( isset( $_REQUEST['change-report-to'] ) )
  714. $query_args['change-report-to'] = $_REQUEST['change-report-to'];
  715. $query_args['message'] = 'deleted-rating';
  716. $query_args['deleted'] = count( (array) $rating );
  717. break;
  718. default :
  719. return;
  720. endswitch;
  721. }
  722. wp_redirect( add_query_arg( $query_args, wp_get_referer() ) );
  723. exit;
  724. }
  725. function management_page_load_signup() {
  726. switch ( $_POST['account'] ) :
  727. case 'import' :
  728. return $this->import_account();
  729. break;
  730. default :
  731. return;
  732. endswitch;
  733. }
  734. function import_account(){
  735. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID );
  736. $polldaddy->reset();
  737. $email = trim( stripslashes( $_POST['polldaddy_email'] ) );
  738. $password = trim( stripslashes( $_POST['polldaddy_password'] ) );
  739. if ( !is_email( $email ) )
  740. $this->errors->add( 'polldaddy_email', __( 'Email address required', 'polldaddy' ) );
  741. if ( !$password )
  742. $this->errors->add( 'polldaddy_password', __( 'Password required', 'polldaddy' ) );
  743. if ( $this->errors->get_error_codes() )
  744. return false;
  745. if ( $usercode = $polldaddy->initiate( $email, $password, $this->id ) ) {
  746. $this->user_code = $usercode;
  747. } else {
  748. $this->parse_errors( $polldaddy );
  749. $this->errors->add( 'import-account', __( 'Account could not be imported. Are your email address and password correct?', 'polldaddy' ) );
  750. return false;
  751. }
  752. }
  753. function admin_body_class( $class ) {
  754. if ( isset( $_GET['iframe'] ) )
  755. $class .= 'poll-preview-iframe ';
  756. if ( isset( $_GET['TB_iframe'] ) )
  757. $class .= 'poll-preview-iframe-editor ';
  758. return $class;
  759. }
  760. function management_page_notices( $message = false ) {
  761. switch ( (string) @$_GET['message'] ) :
  762. case 'deleted' :
  763. $deleted = (int) $_GET['deleted'];
  764. if ( 1 == $deleted )
  765. $message = __( 'Poll deleted.', 'polldaddy' );
  766. else
  767. $message = sprintf( __ngettext( '%s Poll Deleted.', '%s Polls Deleted.', $deleted ), number_format_i18n( $deleted ) );
  768. break;
  769. case 'opened' :
  770. $opened = (int) $_GET['opened'];
  771. if ( 1 == $opened )
  772. $message = __( 'Poll opened.', 'polldaddy' );
  773. else
  774. $message = sprintf( __ngettext( '%s Poll Opened.', '%s Polls Opened.', $opened ), number_format_i18n( $opened ) );
  775. break;
  776. case 'closed' :
  777. $closed = (int) $_GET['closed'];
  778. if ( 1 == $closed )
  779. $message = __( 'Poll closed.', 'polldaddy' );
  780. else
  781. $message = sprintf( __ngettext( '%s Poll Closed.', '%s Polls Closed.', $closed ), number_format_i18n( $closed ) );
  782. break;
  783. case 'updated' :
  784. $message = __( 'Poll updated.', 'polldaddy' );
  785. break;
  786. case 'created' :
  787. $message = __( 'Poll created.', 'polldaddy' );
  788. if ( isset( $_GET['iframe'] ) )
  789. $message .= ' <input type="button" class="button polldaddy-send-to-editor" value="' . attribute_escape( __( 'Send to Editor', 'polldaddy' ) ) . '" />';
  790. break;
  791. case 'updated-style' :
  792. $message = __( 'Custom Style updated.', 'polldaddy' );
  793. break;
  794. case 'created-style' :
  795. $message = __( 'Custom Style created.', 'polldaddy' );
  796. break;
  797. case 'deleted-style' :
  798. $deleted = (int) $_GET['deleted'];
  799. if ( 1 == $deleted )
  800. $message = __( 'Custom Style deleted.', 'polldaddy' );
  801. else
  802. $message = sprintf( __ngettext( '%s Style Deleted.', '%s Custom Styles Deleted.', $deleted ), number_format_i18n( $deleted ) );
  803. break;
  804. case 'imported-account' :
  805. $message = __( 'Account Imported.', 'polldaddy' );
  806. break;
  807. case 'updated-options' :
  808. $message = __( 'Options Updated.', 'polldaddy' );
  809. break;
  810. case 'deleted-rating' :
  811. $deleted = (int) $_GET['deleted'];
  812. if ( 1 == $deleted )
  813. $message = __( 'Rating deleted.', 'polldaddy' );
  814. else
  815. $message = sprintf( __ngettext( '%s Rating Deleted.', '%s Ratings Deleted.', $deleted ), number_format_i18n( $deleted ) );
  816. break;
  817. endswitch;
  818. $is_POST = 'post' == strtolower( $_SERVER['REQUEST_METHOD'] );
  819. if ( $is_POST ) {
  820. switch ( $GLOBALS['action'] ) :
  821. case 'create-poll' :
  822. $message = __( 'Error: An error has occurred; Poll not created.', 'polldaddy' );
  823. break;
  824. case 'edit-poll' :
  825. $message = __( 'Error: An error has occurred; Poll not updated.', 'polldaddy' );
  826. break;
  827. case 'account' :
  828. if ( 'import' == $_POST['account'] )
  829. $message = __( 'Error: An error has occurred; Account could not be imported. Perhaps your email address or password is incorrect?', 'polldaddy' );
  830. else
  831. $message = __( 'Error: An error has occurred; Account could not be created.', 'polldaddy' );
  832. break;
  833. endswitch;
  834. }
  835. if ( !$message )
  836. return;
  837. ?>
  838. <div class='updated'><p><?php echo $message; ?></p></div>
  839. <?php
  840. $this->print_errors();
  841. }
  842. function management_page() {
  843. global $page, $action, $poll, $style, $rating;
  844. $poll = (int) $poll;
  845. $style = (int) $style;
  846. $rating = wp_specialchars( $rating );
  847. ?>
  848. <div class="wrap" id="manage-polls">
  849. <?php
  850. if( $page == 'polls' ) {
  851. if ( !$this->is_author && in_array( $action, array( 'edit', 'edit-poll', 'create-poll', 'edit-style', 'create-style', 'list-styles', 'options', 'update-options', 'import-account' ) ) ) {//check user privileges has access to action
  852. $action = '';
  853. }
  854. switch ( $action ) :
  855. case 'signup' :
  856. case 'account' :
  857. $this->signup();
  858. break;
  859. case 'preview' :
  860. ?>
  861. <h2 id="preview-header"><?php
  862. if( $this->is_author )
  863. printf( __( 'Poll Preview (<a href="%s">Edit Poll</a>, <a href="%s">List Polls</a>)', 'polldaddy' ),
  864. clean_url( add_query_arg( array( 'action' => 'edit', 'poll' => $poll, 'message' => false ) ) ),
  865. clean_url( add_query_arg( array( 'action' => false, 'poll' => false, 'message' => false ) ) ));
  866. else
  867. printf( __( 'Poll Preview (<a href="%s">List Polls</a>)', 'polldaddy'), clean_url( add_query_arg( array( 'action' => false, 'poll' => false, 'message' => false ) ) ) ); ?></h2>
  868. <?php
  869. echo do_shortcode( "[polldaddy poll=$poll cb=1]" );
  870. break;
  871. case 'results' :
  872. ?>
  873. <h2><?php
  874. if( $this->is_author )
  875. printf( __( 'Poll Results (<a href="%s">Edit Poll</a>)', 'polldaddy' ), clean_url( add_query_arg( array( 'action' => 'edit', 'poll' => $poll, 'message' => false ) ) ) );
  876. else
  877. printf( __( 'Poll Results (<a href="%s">List Polls</a>)', 'polldaddy'), clean_url( add_query_arg( array( 'action' => false, 'poll' => false, 'message' => false ) ) ) ); ?></h2>
  878. <?php
  879. $this->poll_results_page( $poll );
  880. break;
  881. case 'edit' :
  882. case 'edit-poll' :
  883. ?>
  884. <h2><?php printf( __('Edit Poll (<a href="%s">List Polls</a>)', 'polldaddy'), clean_url( add_query_arg( array( 'action' => false, 'poll' => false, 'message' => false ) ) ) ); ?></h2>
  885. <?php
  886. $this->poll_edit_form( $poll );
  887. break;
  888. case 'create-poll' :
  889. ?>
  890. <h2><?php printf( __('Create Poll (<a href="%s">List Polls</a>)', 'polldaddy'), clean_url( add_query_arg( array( 'action' => false, 'poll' => false, 'message' => false ) ) ) ); ?></h2>
  891. <?php
  892. $this->poll_edit_form();
  893. break;
  894. case 'list-styles' :
  895. ?>
  896. <h2><?php
  897. if( $this->is_author )
  898. printf( __('Custom Styles (<a href="%s">Add New</a>)', 'polldaddy'), clean_url( add_query_arg( array( 'action' => 'create-style', 'poll' => false, 'message' => false ) ) ) );
  899. else
  900. _e('Custom Styles', 'polldaddy'); ?></h2>
  901. <?php
  902. $this->styles_table();
  903. break;
  904. case 'edit-style' :
  905. ?>
  906. <h2><?php printf( __('Edit Style (<a href="%s">List Styles</a>)', 'polldaddy'), clean_url( add_query_arg( array( 'action' => 'list-styles', 'style' => false, 'message' => false, 'preload' => false ) ) ) ); ?></h2>
  907. <?php
  908. $this->style_edit_form( $style );
  909. break;
  910. case 'create-style' :
  911. ?>
  912. <h2><?php printf( __('Create Style (<a href="%s">List Styles</a>)', 'polldaddy'), clean_url( add_query_arg( array( 'action' => 'list-styles', 'style' => false, 'message' => false, 'preload' => false ) ) ) ); ?></h2>
  913. <?php
  914. $this->style_edit_form();
  915. break;
  916. case 'options' :
  917. case 'import-account' :
  918. case 'update-options' :
  919. $this->plugin_options();
  920. break;
  921. default :
  922. ?>
  923. <h2 id="poll-list-header"><?php
  924. if( $this->is_author )
  925. printf( __( 'Polls (<a href="%s">Add New</a>)', 'polldaddy' ), clean_url( add_query_arg( array('action' => 'create-poll','poll' => false,'message' => false) ) ) );
  926. else
  927. _e( 'Polls', 'polldaddy'); ?></h2>
  928. <?php
  929. $this->polls_table( isset( $_GET['view'] ) && 'user' == $_GET['view'] ? 'user' : 'blog' );
  930. endswitch;
  931. } elseif( $page == 'ratings' ) {
  932. if ( !$this->is_admin && !in_array( $action, array( 'delete', 'reports' ) ) ) {//check user privileges has access to action
  933. $action = 'reports';
  934. }
  935. switch ( $action ) :
  936. case 'delete' :
  937. case 'reports' :
  938. $this->rating_reports();
  939. break;
  940. case 'update-rating' :
  941. $this->update_rating();
  942. $this->rating_settings( $action );
  943. break;
  944. default :
  945. $this->rating_settings();
  946. endswitch;
  947. }
  948. ?>
  949. </div>
  950. <?php
  951. }
  952. function polls_table( $view = 'blog' ) {
  953. $page = 1;
  954. if ( isset( $_GET['paged'] ) )
  955. $page = absint($_GET['paged']);
  956. $polldaddy = $this->get_client( WP_POLLDADDY__PARTNERGUID, $this->user_code );
  957. $polldaddy->reset();
  958. if( !$this->is_author )
  959. $view = '';
  960. if ( 'user' == $view )
  961. $polls_object = $polldaddy->get_polls( ( $page - 1 ) * 10 + 1, $page * 10 );
  962. else
  963. $polls_object = $polldaddy->get_polls_by_parent_id( ( $page - 1 ) * 10 + 1, $page * 10 );
  964. $this->parse_errors( $polldaddy );
  965. $this->print_errors();
  966. $polls = & $polls_object->poll;
  967. if( isset( $polls_object->_total ) )
  968. $total_polls = $polls_object->_total;
  969. else
  970. $total_polls = count( $polls );
  971. $class = '';
  972. $page_links = paginate_links( array(
  973. 'base' => add_query_arg( 'paged', '%#%' ),
  974. 'format' => '',
  975. 'total' => ceil( $total_polls / 10 ),
  976. 'current' => $page
  977. ) );
  978. if( $this->is_author ){ ?>
  979. <ul class="subsubsub">
  980. <li><a href="<?php echo clean_url( add_query_arg( array( 'view' => false, 'paged' => false ) ) ); ?>"<?php if ( 'blog' == $view ) echo ' class="current"'; ?>><?php _e( "All Blog's Polls", 'polldaddy' ); ?></a> | </li>
  981. <li><a href="<?php echo clean_url( add_query_arg( array( 'view' => 'user', 'paged' => false ) ) ); ?>"<?php if ( 'user' == $view ) echo ' class="current"'; ?>><?php _e( "All My Polls", 'polldaddy' ); ?></a></li>
  982. </ul>
  983. <?php } ?>
  984. <form method="post" action="">
  985. <?php if( $this->is_author ){ ?>
  986. <div class="tablenav">
  987. <div class="alignleft">
  988. <select name="action">
  989. <option selected="selected" value=""><?php _e( 'Actions', 'polldaddy' ); ?></option>
  990. <option value="delete"><?php _e( 'Delete', 'polldaddy' ); ?></option>
  991. <option value="close"><?php _e( 'Close', 'polldaddy' ); ?></option>
  992. <option value="open"><?php _e( 'Open', 'polldaddy' ); ?></option>
  993. </select>
  994. <input class="button-secondary action" type="submit" name="doaction" value="<?php _e( 'Apply', 'polldaddy' ); ?>" />
  995. <?php wp_nonce_field( 'action-poll_bulk' ); ?>
  996. </div>
  997. <div class="tablenav-pages"><?php echo $page_links; ?></div>
  998. </div>
  999. <br class="clear" />
  1000. <?php } ?>
  1001. <table class="widefat">
  1002. <thead>
  1003. <tr>
  1004. <th id="cb" class="manage-column column-cb check-column" scope="col" /><?php if( $this->is_author ){ ?><input type="checkbox" /><?php } ?></th>
  1005. <th id="title" class="manage-column column-title" scope="col"><?php _e( 'Poll', 'polldaddy' ); ?></th>
  1006. <th id="votes" class="manage-column column-vote num" scope="col"><?php _e( 'Votes', 'polldaddy' ); ?></th>
  1007. <th id="date" class="manage-column column-date" scope="col"><?php _e( 'Created', 'polldaddy' ); ?></th>
  1008. </tr>
  1009. </thead>
  1010. <tbody>
  1011. <?php
  1012. if ( $polls ) :
  1013. foreach ( $polls as $poll ) :
  1014. $poll_id = (int) $poll->_id;
  1015. $poll->___content = trim( strip_tags( $poll->___content ) );
  1016. if( strlen( $poll->___content ) == 0 ){
  1017. $poll->___content = '-- empty HTML tag --';
  1018. }
  1019. $poll_closed = (int) $poll->_closed;
  1020. if ( $this->is_author and $this->can_edit( $poll ) ) {
  1021. $edit_link = clean_url( add_query_arg( array( 'action' => 'edit', 'poll' => $poll_id, 'message' => false ) ) );
  1022. $delete_link = clean_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'poll' => $poll_id, 'message' => false ) ), "delete-poll_$poll_id" ) );
  1023. $open_link = clean_url( wp_nonce_url( add_query_arg( array( 'action' => 'open', 'poll' => $poll_id, 'message' => false ) ), "open-poll_$poll_id" ) );
  1024. $close_link = clean_url( wp_nonce_url( add_query_arg( array( 'action' => 'close', 'poll' => $poll_id, 'message' => false ) ), "close-poll_$poll_id" ) );
  1025. }
  1026. else {
  1027. $edit_link = false;
  1028. $delete_link = false;
  1029. $open_link = false;
  1030. $close_link = false;
  1031. }
  1032. $class = $class ? '' : ' class="alternate"';
  1033. $results_link = clean_url( add_query_arg( array( 'action' => 'results', 'poll' => $poll_id, 'message' => false ) ) );
  1034. $preview_link = clean_url( add_query_arg( array( 'action' => 'preview', 'poll' => $poll_id, 'message' => false ) ) ); //, 'iframe' => '', 'TB_iframe' => 'true' ) ) );
  1035. list($poll_time) = explode( '.', $poll->_created );
  1036. $poll_time = strtotime( $poll_time );
  1037. ?>
  1038. <tr<?php echo $class; ?>>
  1039. <th class="check-column" scope="row"><?php if( $this->is_author and $this->can_edit( $poll ) ){ ?><input type="checkbox" value="<?php echo (int) $poll_id; ?>" name="poll[]" /><?php } ?></th>
  1040. <td class="post-title column-title">
  1041. <?php if ( $edit_link ) { ?>
  1042. <strong><a class="row-title" href="<?php echo $edit_link; ?>"><?php echo wp_specialchars( $poll->___content ); ?></a></strong>
  1043. <div class="row-actions">
  1044. <span class="edit"><a href="<?php echo $edit_link; ?>"><?php _e( 'Edit', 'polldaddy' ); ?></a> | </span>
  1045. <?php } else { ?>
  1046. <strong><?php echo wp_specialchars( $poll->___content ); ?></strong>
  1047. <div class="row-actions">
  1048. <?php } ?>
  1049. <span class="results"><a href="<?php echo $results_link; ?>"><?php _e( 'Results', 'polldaddy' ); ?></a> | </span>
  1050. <?php if ( $delete_link ) { ?>
  1051. <span class="delete"><a class="delete-poll delete" href="<?php echo $delete_link; ?>"><?php _e( 'Delete', 'polldaddy' ); ?></a> | </span>
  1052. <?php }
  1053. if ( $poll_closed == 2 ) {
  1054. if ( $open_link ) { ?>
  1055. <span class="open"><a class="open-poll" href="<?php echo $open_link; ?>"><?php _e( 'Open', 'polldaddy' ); ?></a> | </span>
  1056. <?php } } else {
  1057. if ( $close_link ) { ?>
  1058. <span class="close"><a class="close-poll" href="<?php echo $close_link; ?>"><?php _e( 'Close', 'polldaddy' ); ?></a> | </span>
  1059. <?php } } ?>
  1060. <?php if ( isset( $_GET['iframe'] ) ) { ?>
  1061. <span class="view"><a href="<?php echo $preview_link; ?>"><?php _e( 'Preview', 'polldaddy' ); ?></a> | </span>
  1062. <span class="editor">
  1063. <a href="#" class="polldaddy-send-to-editor"><?php _e( 'Send to editor', 'polldaddy' ); ?></a>
  1064. <input type="hidden" class="polldaddy-poll-id hack" value="<?php echo (int) $poll_id; ?>" /> |
  1065. </span>
  1066. <?php } else { ?>
  1067. <span class="view"><a class="thickbox" href="<?php echo $preview_link; ?>"><?php _e( 'Preview', 'polldaddy' ); ?></a> | </span>
  1068. <?php } ?>
  1069. <span class="shortcode"><a href="#" class="polldaddy-show-shortcode"><?php _e( 'Share-Embed', 'polldaddy' ); ?></a></span>
  1070. <?php $this->poll_table_add_option( $poll_id ); ?>
  1071. </div>
  1072. </td>
  1073. <td class="poll-votes column-vote num"><?php echo number_format_i18n( $poll->_responses ); ?></td>
  1074. <td class="date column-date"><abbr title="<?php echo date( __('Y/m/d g:i:s A', 'polldaddy'), $poll_time ); ?>"><?php echo date( __('Y/m/d', 'polldaddy'), $poll_time ); ?></abbr></td>
  1075. </tr>
  1076. <tr class="polldaddy-shortcode-row" style="display: none;">
  1077. <td colspan="4">
  1078. <h4><?php _e( 'WordPress Shortcode', 'polldaddy' ); ?></h4>
  1079. <input type="text" readonly="readonly" style="width: 175px;" onclick="this.select();" value="[polldaddy poll=<?php echo (int) $poll_id; ?>]"/>
  1080. <h4><?php _e( 'JavaScript', 'polldaddy' ); ?></h4>
  1081. <pre>&lt;script type="text/javascript" language="javascript"
  1082. src="http://static.polldaddy.com/p/<?php echo (int) $poll_id; ?>.js"&gt;&lt;/script&gt;
  1083. &lt;noscript&gt;
  1084. &lt;a href="http://polldaddy.com/poll/<?php echo (int) $poll_id; ?>/"&gt;<?php echo trim( strip_tags( $poll->___content ) ); ?>&lt;/a&gt;&lt;br/&gt;
  1085. &lt;span style="font:9px;"&gt;(&lt;a href="http://www.polldaddy.com"&gt;polls&lt;/a&gt;)&lt;/span&gt;
  1086. &lt;/noscript&gt;</pre>
  1087. <h4><?php _e( 'Short URL (Good for Twitter etc.)', 'polldaddy' ); ?></h4>
  1088. <input type="text" readonly="readonly" style="width: 175px;" onclick="this.select();" value="http://poll.fm/<?php echo base_convert( $poll_id, 10, 36 ); ?>"/>
  1089. <h4><?php _e( 'Facebook URL', 'polldaddy' ); ?></h4>
  1090. <input type="text" readonly="readonly" style="width: 175px;" onclick="this.se…

Large files files are truncated, but you can click here to view the full file