/** * Prepare all the items to be displayed * * @access public * @return void */ public function prepare_items() { $columns = $this->get_columns(); $sortable = $this->get_sortable_columns(); $hidden = array(); $this->_column_headers = array($columns, $hidden, $sortable); // Get the audit data. $audit_posts_model = new MSA_Audit_Posts_Model(); $per_page = $this->get_items_per_page('posts_per_page', 50); $current_page = $this->get_pagenum(); $args = array('per_page' => $per_page, 'current_page' => $current_page); /** * Search term */ if (isset($_POST['s']) && check_admin_referer('msa-all-audit-posts-table')) { // Input var okay. $args['s'] = sanitize_text_field(wp_unslash($_POST['s'])); // Input var okay. } /** * Get Posts */ $audit = -1; if (isset($_GET['audit'])) { // Input var okay. $audit = sanitize_text_field(wp_unslash($_GET['audit'])); // Input var okay. } $posts = $audit_posts_model->get_data($audit, $args); foreach ($posts as $post) { $this->items[] = array('score' => $post['score'], 'post' => $post['post'], 'data' => $post['data']); } /** * Filter Posts */ $this->items = msa_filter_posts($this->items); /** * Sort Posts */ if (count($this->items) > 0) { usort($this->items, array(&$this, 'usort_reorder')); } $total_items = count($this->items); $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page)); if (is_array($this->items) && count($this->items) > 0) { $this->items = array_slice($this->items, ($current_page - 1) * $per_page, $per_page); } }
/** * The plugin is activated * * @access public * @return void */ function msa_activation() { // Add the version number to the database. if (function_exists('is_multisite') && is_multisite()) { update_site_option('msa_version', MY_SITE_AUDIT_VERSION); } else { update_option('msa_version', MY_SITE_AUDIT_VERSION); } // Create the audits table. $audit_model = new MSA_Audits_Model(); $audit_model->create_table(); // Create the audit posts table. $audit_posts_model = new MSA_Audit_Posts_Model(); $audit_posts_model->create_table(); // Add the transient to redirect. set_transient('_msa_activation_redirect', true, 30); // Add Upgraded From Option. update_option('msa_version_upgraded_from', MY_SITE_AUDIT_VERSION); delete_transient('msa_running_audit'); }
/** * Create an Audit * * @access public * @param array $audit_data The attributes for an audit. * @return void */ function msa_create_audit($audit_data) { // Set the transient to say that we are running an audit. set_transient('msa_running_audit', true); delete_transient('msa_schedule_audit'); // Include all the files we need. require_once plugin_dir_path(__FILE__) . 'functions/common.php'; require_once plugin_dir_path(__FILE__) . 'model/audits.php'; require_once plugin_dir_path(__FILE__) . 'model/audit-posts.php'; require_once plugin_dir_path(__FILE__) . 'functions/audit-data.php'; require_once plugin_dir_path(__FILE__) . 'functions/condition.php'; require_once plugin_dir_path(__FILE__) . 'functions/condition-category.php'; require_once plugin_dir_path(__FILE__) . 'functions/attribute.php'; require_once plugin_dir_path(__FILE__) . 'functions/score-status.php'; require_once plugin_dir_path(__FILE__) . 'functions/create-audit.php'; require_once plugin_dir_path(__FILE__) . 'functions/notifications.php'; msa_create_initial_conditions(); msa_create_initial_condition_categories(); $audit_model = new MSA_Audits_Model(); $audit_posts_model = new MSA_Audit_Posts_Model(); // Get all the data from the user. $audit = array(); $audit['name'] = $audit_data['name']; $audit['score'] = 0; $audit['date'] = date('Y-m-d H:i:s'); $audit['status'] = 'in-progress'; $audit['user'] = $audit_data['user']; $audit['num_posts'] = 0; $audit['args']['conditions'] = wp_json_encode(msa_get_conditions()); $audit['args']['before_date'] = $audit_data['after-date']; $audit['args']['before_date'] = $audit_data['before-date']; $audit['args']['post_types'] = $audit_data['post-types']; $audit['args']['max_posts'] = $audit_data['max-posts']; $audit_data['after-date'] = '' !== $audit_data['after-date'] ? strip_tags($audit_data['after-date']) : date('m/d/Y', strtotime('-1 years')); $audit_data['before-date'] = '' !== $audit_data['before-date'] ? strip_tags($audit_data['before-date']) : date('m/d/Y', strtotime('today')); $audit['args']['form_fields'] = wp_json_encode($audit_data); // Get all the posts that we are going to perform an audit on. $page = 1; $posts_per_page = 25; $total_posts = 0; $audit_score = 0; $args = array('public' => true, 'date_query' => array(array('after' => $audit_data['after-date'], 'before' => $audit_data['before-date'], 'inclusive' => true)), 'post_type' => $audit_data['post-types'], 'posts_per_page' => $posts_per_page, 'paged' => $page); $posts = get_posts($args); // Create the audit. if (count($posts) > 0) { $audit_id = $audit_model->add_data($audit); } // Only perform the audit if there are posts to perform the audit on. while (count($posts) > 0) { if ($audit_id) { foreach ($posts as $post) { if (-1 !== $audit_data['max-posts'] && $total_posts >= $audit_data['max-posts']) { break 2; } $data = msa_get_post_audit_data($post); $score = msa_calculate_score($post, $data); $data['score'] = $score['score']; // Add a new record in the audit posts table. $audit_posts_model->add_data(array('audit_id' => $audit_id, 'post' => $post, 'data' => array('score' => $score, 'values' => $data))); $audit_score += $score['score']; $total_posts++; } } $page++; $args = array('public' => true, 'date_query' => array(array('after' => $audit_data['after-date'], 'before' => $audit_data['before-date'], 'inclusive' => true)), 'post_type' => $audit_data['post-types'], 'posts_per_page' => $posts_per_page, 'paged' => $page); $posts = get_posts($args); } $audit_score = round($audit_score / $total_posts, 10); $audit['num_posts'] = $total_posts; $audit['score'] = round($audit_score, 10); $audit['status'] = 'completed'; $audit_model->update_data($audit_id, $audit); // Remove the transient once we are done with the audit. delete_transient('msa_running_audit'); /** * Runs when the audit is completed * * @param int $audit_id The Audit ID. * @param string $audit['name'] The Audit name. */ do_action('msa_audit_completed', $audit_id, $audit['name']); }
* related to this plugin. * * @package Uninstall */ if (!defined('ABSPATH')) { exit; } if (!defined('WP_UNINSTALL_PLUGIN')) { exit; } do_action('msa_uninstall'); require_once plugin_dir_path(__FILE__) . 'model/audits.php'; require_once plugin_dir_path(__FILE__) . 'model/audit-posts.php'; $audit_model = new MSA_Audits_Model(); $audit_model->delete_table(); $audit_posts_model = new MSA_Audit_Posts_Model(); $audit_posts_model->delete_table(); global $wpdb; /** * Perform separate actions for multisite or single site */ if (function_exists('is_multisite') && !is_multisite()) { delete_option('msa_version'); delete_option('msa_version_upgraded_from'); $wpdb->query('DELETE FROM `' . $wpdb->prefix . "options` WHERE `option_name` LIKE '%msa_dashboard_panel_order_%'"); $wpdb->query('DELETE FROM `' . $wpdb->prefix . "options` WHERE `option_name` LIKE '%msa_show_columns_%'"); } else { delete_site_option('msa_version'); $blog_ids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}"); foreach ($blog_ids as $blog_id) { switch_to_blog($blog_id);
</div> </div> <?php } else { if (isset($_GET['audit']) && check_admin_referer('msa-single-audit')) { // Input var okay. $audit_id = sanitize_text_field(wp_unslash($_GET['audit'])); // Input var okay. // Get the Audit. $audit_model = new MSA_Audits_Model(); $audit = $audit_model->get_data_from_id($audit_id); $form_fields = json_decode($audit['args']['form_fields'], true); // Get the posts for an audit. $audit_posts_model = new MSA_Audit_Posts_Model(); $posts = $audit_posts_model->get_data($audit_id); // Get all the current filters. $current_filters = ''; $conditions = msa_get_conditions(); $attributes = msa_get_attributes(); foreach ($conditions as $key => $condition) { if (isset($condition['filter']['name']) && isset($_GET[$condition['filter']['name']])) { // Input var okay. $current_filters .= '&' . $condition['filter']['name'] . '=' . sanitize_text_field(wp_unslash($_GET[$condition['filter']['name']])); // Input var okay. } } foreach ($attributes as $key => $attribute) { if (isset($attribute['filter']['name']) && isset($_GET[$attribute['filter']['name']])) { // Input var okay.
/** * Prints the box content. * * @access public * @param object $post A WP_Post obejct. * @return void */ function msa_meta_box_callback($post) { // Get the latest audit. $audit_model = new MSA_Audits_Model(); $audit = $audit_model->get_latest(); // Check to see if we have an audit. if (isset($audit)) { $post_id = -1; if (isset($_GET['post'])) { // Input var okay. $post_id = sanitize_text_field(wp_unslash($_GET['post'])); // Input var okay. } $audit = $audit_model->get_data_from_id($audit['id']); $audit_posts_model = new MSA_Audit_Posts_Model(); $audit_post = $audit_posts_model->get_data_from_id($audit['id'], $post_id); if ($audit_post) { $post = (object) $audit_post['post']; $data = $audit_post['data']['values']; $score = $audit_post['data']['score']; $condition_categories = msa_get_condition_categories(); $user = get_userdata($audit['user']); do_action('msa_before_post_meta_box', $audit['id'], $post_id); ?> <div class="msa-post-meta-container msa-post-meta-audit-meta-attributes"> <p class="msa-post-meta-attribute"><?php esc_attr_e('Score: ', 'msa'); ?> </p> <p class="msa-post-meta-attribute"><?php esc_attr_e('From Audit: ', 'msa'); ?> </p> <p class="msa-post-meta-attribute"><?php esc_attr_e('Created On: ', 'msa'); ?> </p> <p class="msa-post-meta-attribute"><?php esc_attr_e('Created By: ', 'msa'); ?> </p> </div> <div class="msa-post-meta-container msa-post-meta-audit-meta-values"> <p class="msa-post-meta-value msa-post-status-bg msa-post-status-bg-<?php esc_attr_e(msa_get_score_status($score['score'])); ?> "><?php esc_attr_e(round($score['score'] * 100, 2)); ?> %</p> <p class="msa-post-meta-value"><a href="<?php esc_attr_e(msa_get_single_audit_link($audit['id'])); ?> " target="_blank"><?php esc_attr_e($audit['name']); ?> </a></p> <p class="msa-post-meta-value"><?php esc_attr_e(date('M j, Y', strtotime($audit['date']))); ?> </p> <p class="msa-post-meta-value"><?php esc_attr_e($user->display_name); ?> </p> </div><?php foreach ($condition_categories as $key => $condition_category) { ?> <div class="postbox" id="<?php esc_attr_e($key); ?> " style="pointer-events: none;"> <?php echo apply_filters('msa_condition_category_content', $key, $post, $data, $score); // WPCS: XSS ok. ?> </div><?php } do_action('msa_after_post_meta_box', $audit['id'], $post_id); } } wp_enqueue_style('msa-all-audits-css', MY_SITE_AUDIT_PLUGIN_URL . '/css/all-audits.css'); wp_enqueue_style('msa-post-meta-css', MY_SITE_AUDIT_PLUGIN_URL . '/css/post-meta.css'); wp_enqueue_style('msa-common-css', MY_SITE_AUDIT_PLUGIN_URL . '/css/common.css'); }
/** * Author Attribute options for the filters * * @access public * @param mixed $content The un-filtered content. * @return mixed $content The filtered content. */ function msa_filter_attribute_author_options($content) { $audit = -1; if (isset($_GET['audit'])) { // Input var okay. $audit = sanitize_text_field(wp_unslash($_GET['audit'])); // Input var okay. // Get all authors within an audit. $audit_posts_model = new MSA_Audit_Posts_Model(); $authors = $audit_posts_model->get_authors_in_audit($audit); $content = array(); foreach ($authors as $author) { $author_data = get_userdata($author['post_author']); $content[] = array('name' => $author_data->display_name, 'value' => $author['post_author']); } } return $content; }
/** * Delete some data * * @param mixed $id The audit id. * @return void */ function delete_data($id) { global $wpdb; // $sql = $wpdb->prepare( 'DELETE FROM `' . $this->get_table_name() . '` WHERE `id` = %d', $id ); $wpdb->delete($this->get_table_name(), array('id' => $id)); // Delete all the posts in the Audit Posts Table. $audit_posts_model = new MSA_Audit_Posts_Model(); $audit_posts_model->delete_data($id); }