/** * On the scheduled action hook, run a function. */ function polldaddy_rating_update() { if (false == get_option('pd-rich-snippets', 1)) { return false; } global $polldaddy_object; $polldaddy = $polldaddy_object->get_client(WP_POLLDADDY__PARTNERGUID, get_option('pd-rating-usercode')); $rating_id = get_option('pd-rating-posts-id'); $finished = false; $c = 0; while (!$finished) { $response = $polldaddy->get_rating_results($rating_id, 2, $c, 50); $ratings = $response->rating; if (false == is_array($ratings)) { $finished = true; } else { polldaddy_update_ratings_cache($ratings); } $c += 50; if ($c > 1000) { // gotta stop somewhere $finished = true; } } return true; }
function rating_reports() { if (!defined('WP_POLLDADDY__PARTNERGUID') || WP_POLLDADDY__PARTNERGUID == false) { return false; } $polldaddy = $this->get_client(WP_POLLDADDY__PARTNERGUID, $this->rating_user_code); $rating_id = get_option('pd-rating-posts-id'); $report_type = 'posts'; $period = '7'; $show_rating = 0; if (isset($_REQUEST['change-report-to'])) { switch ($_REQUEST['change-report-to']) { case 'pages': $report_type = 'pages'; $rating_id = (int) get_option('pd-rating-pages-id'); break; case 'comments': $report_type = 'comments'; $rating_id = get_option('pd-rating-comments-id'); break; case 'posts': $report_type = 'posts'; $rating_id = get_option('pd-rating-posts-id'); break; } //end switch } if (isset($_REQUEST['filter']) && $_REQUEST['filter']) { switch ($_REQUEST['filter']) { case '1': $period = '1'; break; case '7': $period = '7'; break; case '31': $period = '31'; break; case '90': $period = '90'; break; case '365': $period = '365'; break; case 'all': $period = 'all'; break; } //end switch } $page_size = 15; $current_page = 1; if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'change-report') { $current_page = 1; } else { if (isset($_REQUEST['paged'])) { $current_page = (int) $_REQUEST['paged']; if ($current_page == 0) { $current_page = 1; } } } $start = $current_page * $page_size - $page_size; $end = $page_size; $response = $polldaddy->get_rating_results($rating_id, $period, $start, $end); $total = $total_pages = 0; $ratings = null; if (!empty($response)) { $ratings = $response->rating; $total = (int) $response->_total; $total_pages = ceil($total / $page_size); } $page_links = paginate_links(array('base' => add_query_arg(array('paged' => '%#%', 'change-report-to' => $report_type, 'filter' => $period)), 'format' => '', 'prev_text' => __('«', 'polldaddy'), 'next_text' => __('»', 'polldaddy'), 'total' => $total_pages, 'current' => $current_page)); ?> <div class="wrap"> <?php if ($this->is_admin) { ?> <h2 id="polldaddy-header"><?php printf(__('Rating Results <a href="%s" class="add-new-h2">Settings</a>', 'polldaddy'), esc_url('options-general.php?page=ratings&action=options')); ?> </h2> <?php } else { ?> <h2 id="polldaddy-header"><?php _e('Rating Results', 'polldaddy'); ?> </h2> <?php } ?> <div class="clear"></div> <form method="post" action=""> <div class="tablenav"> <div class="alignleft actions"> <?php if ($this->is_editor) { ?> <select name="action"> <option selected="selected" value=""><?php _e('Actions', 'polldaddy'); ?> </option> <option value="delete"><?php _e('Delete', 'polldaddy'); ?> </option> </select> <input type="hidden" name="id" id="id" value="<?php echo (int) $rating_id; ?> " /> <input class="button-secondary action" type="submit" name="doaction" value="<?php _e('Apply', 'polldaddy'); ?> " /> <?php wp_nonce_field('action-rating_bulk'); ?> <?php } ?> <select name="change-report-to"><?php $select = array(__('Posts', 'polldaddy') => "posts", __('Pages', 'polldaddy') => "pages", __('Comments', 'polldaddy') => "comments"); foreach ($select as $option => $value) { $selected = ''; if ($value == $report_type) { $selected = ' selected="selected"'; } ?> <option value="<?php echo $value; ?> " <?php echo $selected; ?> ><?php echo $option; ?> </option> <?php } ?> </select> <select name="filter"><?php $select = array(__('Last 24 hours', 'polldaddy') => "1", __('Last 7 days', 'polldaddy') => "7", __('Last 31 days', 'polldaddy') => "31", __('Last 3 months', 'polldaddy') => "90", __('Last 12 months', 'polldaddy') => "365", __('All time', 'polldaddy') => "all"); foreach ($select as $option => $value) { $selected = ''; if ($value == $period) { $selected = ' selected="selected"'; } ?> <option value="<?php echo $value; ?> " <?php echo $selected; ?> ><?php echo $option; ?> </option> <?php } ?> </select> <input class="button-secondary action" type="submit" value="<?php _e('Filter', 'polldaddy'); ?> " /> <?php if (in_array($period, array(1, 7))) { ?> <label><?php _e('* The results are cached and are updated every hour'); ?> </label> <?php } elseif ($period == 31) { ?> <label><?php _e('* The results are cached and are updated every day'); ?> </label> <?php } else { ?> <label><?php _e('* The results are cached and are updated every 3 days'); ?> </label> <?php } ?> </div> <div class="alignright"> <div class="tablenav-pages"> <?php echo $page_links; ?> </div> </div> </div> <table class="widefat"><?php if (empty($ratings)) { ?> <tbody> <tr> <td colspan="4"><?php printf(__('No ratings have been collected for your %s yet.', 'polldaddy'), $report_type); ?> </td> </tr> </tbody><?php } else { polldaddy_update_ratings_cache($ratings); ?> <thead> <tr> <?php if ($this->is_editor) { ?> <th scope="col" class="manage-column column-cb check-column" id="cb"><input type="checkbox"></th> <?php } else { ?> <th scope="col" class="manage-column column-cb check-column" id="cb"></th> <?php } ?> <th scope="col" class="manage-column column-title" id="title"><?php _e('Title', 'polldaddy'); ?> </th> <th scope="col" class="manage-column column-id" id="id"><?php _e('Unique ID', 'polldaddy'); ?> </th> <th scope="col" class="manage-column column-date" id="date"><?php _e('Start Date', 'polldaddy'); ?> </th> <th scope="col" class="manage-column column-vote num" id="votes"><?php _e('Votes', 'polldaddy'); ?> </th> <th scope="col" class="manage-column column-rating num" id="rating"><?php _e('Average Rating', 'polldaddy'); ?> </th> </tr> </thead> <tbody><?php $alt_counter = 0; $alt = ''; foreach ($ratings as $rating) { $delete_link = esc_url(wp_nonce_url(add_query_arg(array('action' => 'delete', 'id' => $rating_id, 'rating' => $rating->uid, 'change-report-to' => $report_type, 'message' => false)), "delete-rating_{$rating->uid}")); $alt_counter++; ?> <tr <?php echo $alt_counter & 1 ? ' class="alternate"' : ''; ?> > <th class="check-column" scope="row"><input type="checkbox" value="<?php echo esc_html($rating->uid); ?> " name="rating[]" /></th> <td class="post-title column-title"> <strong><a href="<?php echo esc_url($rating->permalink); ?> "><?php echo strlen(esc_html($rating->title)) > 75 ? substr(esc_html($rating->title), 0, 72) . '&hellip' : esc_html($rating->title); ?> </a></strong> <div class="row-actions"> <?php if ($this->is_editor && $delete_link) { ?> <span class="delete"><a class="delete-rating delete" href="<?php echo $delete_link; ?> "><?php _e('Delete', 'polldaddy'); ?> </a></span> <?php } ?> </div> </td> <td class="column-id"> <?php echo esc_html($rating->uid); ?> </td> <td class="date column-date"> <abbr title="<?php echo date(__('Y/m/d g:i:s A', 'polldaddy'), $rating->date); ?> "><?php echo str_replace('-', '/', substr(esc_html($rating->date), 0, 10)); ?> </abbr> </td> <td class="column-vote num"><?php echo number_format($rating->_votes); ?> </td> <td class="column-rating num"><table width="100%"><tr align="center"><td style="border:none;"><?php if ($rating->_type == 0) { $avg_rating = $this->round($rating->average_rating, 0.5); ?> <div style="width:100px"><?php $image_pos = ''; for ($c = 1; $c <= 5; $c++) { if ($avg_rating > 0) { if ($avg_rating < $c) { $image_pos = 'bottom left'; } if ($avg_rating == $c - 1 + 0.5) { $image_pos = 'center left'; } } ?> <div style="width: 20px; height: 20px; background: url(<?php echo plugins_url('img/star-yellow-med.png', __FILE__); ?> ) <?php echo $image_pos; ?> ; float: left;"></div><?php } ?> <br class="clear" /> </div><?php } else { ?> <div> <div style="margin: 0px 0px 0px 20px; background: transparent url(<?php echo plugins_url('img/rate-graph-up.png', __FILE__); ?> ); width: 20px; height: 20px; float: left;"></div> <div style="float:left; line-height: 20px; padding: 0px 10px 0px 5px;"><?php echo number_format($rating->total1); ?> </div> <div style="margin: 0px; background: transparent url(<?php echo plugins_url('img/rate-graph-dn.png', __FILE__); ?> ); width: 20px; height: 20px; float: left;"></div> <div style="float:left; line-height: 20px; padding: 0px 10px 0px 5px;"><?php echo number_format($rating->total2); ?> </div> <br class="clear" /> </div><?php } ?> </td></tr></table> </td> </tr><?php } ?> </tbody><?php } ?> </table> <div class="tablenav"> <div class="alignright"> <div class="tablenav-pages"> <?php echo $page_links; ?> </div> </div> </div> </form> </div> <p></p> <script language="javascript"> jQuery( document ).ready(function(){ plugin = new Plugin( { delete_rating: '<?php echo esc_attr(__('Are you sure you want to delete the rating for "%s"?', 'polldaddy')); ?> ', delete_poll: '<?php echo esc_attr(__('Are you sure you want to delete "%s"?', 'polldaddy')); ?> ', delete_answer: '<?php echo esc_attr(__('Are you sure you want to delete this answer?', 'polldaddy')); ?> ', delete_answer_title: '<?php echo esc_attr(__('delete this answer', 'polldaddy')); ?> ', standard_styles: '<?php echo esc_attr(__('Standard Styles', 'polldaddy')); ?> ', custom_styles: '<?php echo esc_attr(__('Custom Styles', 'polldaddy')); ?> ' } ); }); </script><?php }