/**
 * The Last Audit Panel Content
 *
 * @access public
 * @return string $output The HTML ouput of the last audit panel.
 */
function msa_dashboard_panel_last_audit_content()
{
    // Get the latest Audit.
    $audit_model = new MSA_Audits_Model();
    $audit = $audit_model->get_latest();
    if (isset($audit)) {
        $output = '<div class="msa-left-column">
			<div class="msa-left-column-content">
				<div class="msa-circle msa-circle-border msa-post-status-border-' . msa_get_score_status($audit['score']) . '">
				     <div class="msa-circle-inner">
				         <div class="msa-score-text msa-post-status-text-' . msa_get_score_status($audit['score']) . '">' . round(100 * $audit['score']) . '%</div>
				     </div>
				</div>
			</div>
		</div>';
        $output .= '<div class="msa-right-column">
			<div class="msa-right-column-content">
				<table class="wp-list-table widefat striped">
					<tbody>';
        $user = get_userdata($audit['user']);
        $output .= '<tr><td>' . __('Name', 'msa') . '</td> <td><a href="' . msa_get_single_audit_link($audit['id']) . '">' . $audit['name'] . '</a></td></tr>';
        $output .= '<tr><td>' . __('Created On', 'msa') . '</td> <td>' . date('M d Y, h:i:s', strtotime($audit['date'])) . '</td></tr>';
        $output .= '<tr><td>' . __('Number of Posts', 'msa') . '</td> <td>' . $audit['num_posts'] . '</td></tr>';
        $output .= '<tr><td>' . __('Created By', 'msa') . '</td> <td>' . $user->display_name . '</td></tr>';
        $output .= '</tbody>
				</table>
			</div>
		</div>';
    } else {
        $output = '<p>' . __('You do not have any audits yet.', 'msa') . ' <a href="' . get_admin_url() . 'admin.php?page=msa-all-audits">' . __('Create one now!', 'msa') . '</a></p>';
    }
    return $output;
}
Exemple #2
0
/**
 * Post Type Attribute options for the filters
 *
 * @access public
 * @param mixed $content  The un-filtered content.
 * @return mixed $content The filtered content.
 */
function msa_filter_attribute_post_type_options($content)
{
    $audit = -1;
    if (isset($_GET['audit'])) {
        // Input var okay.
        $audit = sanitize_text_field(wp_unslash($_GET['audit']));
        // Input var okay.
        // Get all the post types for this audit.
        $audit_model = new MSA_Audits_Model();
        $audit = $audit_model->get_data_from_id($audit);
        $form_fields = json_decode($audit['args']['form_fields'], true);
        foreach ($form_fields['post-types'] as $post_type) {
            $content[] = array('name' => ucfirst($post_type), 'value' => $post_type);
        }
    }
    return $content;
}
/**
 * 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');
}
        /**
         * Return the output for the Name column
         *
         * @access public
         * @param mixed $item The Audit.
         */
        public function column_name($item)
        {
            if (isset($item['status']) && 'in-progress' === $item['status']) {
                return apply_filters('msa_all_audits_table_column_name_extension', $item['name']);
            }
            if (!isset($item['extension'])) {
                $audit_model = new MSA_Audits_Model();
                $audit = $audit_model->get_data_from_id($item['id']);
                $condition = $audit['args']['conditions'];
                $actions = array();
                $actions['delete'] = '<a href="' . wp_nonce_url(get_admin_url() . 'admin.php?page=msa-all-audits&action=delete&audit=' . $item['id'], 'msa-delete-audit') . '">' . __('Delete', 'msa') . '</a>';
                $condition_modal = '<a href="#" class="msa-audit-conditions-button" data-id="' . $item['id'] . '">' . __('Conditions', 'msa') . '</a>
				<div class="msa-audit-conditions-modal" data-id="' . $item['id'] . '">
					<div class="msa-audit-conditions-modal-container">

						<h3 class="msa-audit-conditions-modal-heading">' . __('Conditions', 'msa') . '</h3>

						<div class="msa-audit-conditions">
							<table class="wp-list-table widefat striped fixed">

								<thead>
									<tr>
										<th scope="col">' . __('Name', 'msa') . '</th>
										<th scope="col">' . __('Weight', 'msa') . '</th>
										<th scope="col">' . __('Comparison', 'msa') . '</th>
										<th scope="col">' . __('Value', 'msa') . '</th>
										<th scope="col">' . __('Minimum', 'msa') . '</th>
										<th scope="col">' . __('Maximum', 'msa') . '</th>
									</tr>
								</thead>

								<tbody>';
                foreach (json_decode($audit['args']['conditions'], true) as $condition) {
                    $min = isset($condition['units']) ? $condition['min'] . ' ' . $condition['units'] : $condition['min'];
                    $max = isset($condition['units']) ? $condition['max'] . ' ' . $condition['units'] : $condition['max'];
                    if (1 === $condition['comparison']) {
                        $comparison = __('Greater Than', 'msa');
                        $max = '';
                    } else {
                        if (2 === $condition['comparison']) {
                            $comparison = __('Less Than', 'msa');
                            $min = '';
                        } else {
                            if (3 === $condition['comparison']) {
                                $comparison = __('In Between', 'msa');
                            }
                        }
                    }
                    $value = __('Pass or Fail', 'msa');
                    if (2 === $condition['value']) {
                        $value = __('Percentage', 'msa');
                    }
                    $condition_modal .= '<tr>
						<td>' . (isset($condition['name']) ? $condition['name'] : '') . '</td>
						<td>' . (isset($condition['weight']) ? $condition['weight'] : '') . '</td>
						<td>' . $comparison . '</td>
						<td>' . $value . '</td>
						<td>' . $min . '</td>
						<td>' . $max . '</td>
					</tr>';
                }
                $condition_modal .= '</tbody>
							</table>
						</div>
					</div>
				</div>';
                $actions['edit'] = $condition_modal;
                return apply_filters('msa_all_audits_table_column_name', sprintf('%1$s %2$s', '<a href="' . msa_get_single_audit_link($item['id']) . '">' . $item['name'] . '</a><small style="opacity:0.5;padding-left:4px;">id:(' . $item['id'] . ')</small>', $this->row_actions($actions)));
            }
            return apply_filters('msa_all_audits_table_column_name_extension', '<a href="' . $item['extension-link'] . '" target="_blank">' . $item['name'] . '</a>');
        }
/**
 * 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']);
}
Exemple #6
0
/**
 * This file is run when the plugin is uninstalled and it will remove all data
 * 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}");
        echo isset($_REQUEST['audit']) ? esc_attr__(sanitize_text_field(wp_unslash($_REQUEST['audit']))) : '';
        // Input var okay.
        ?>
" />
		<?php 
        $all_posts_table = new MSA_All_Posts_Table();
        $all_posts_table->prepare_items();
        $all_posts_table->search_box('Search Posts', 'msa');
        $all_posts_table->display();
        wp_nonce_field('msa-all-audit-posts-table');
        ?>
	</form>

<?php 
    } else {
        $audit_model = new MSA_Audits_Model();
        $audit_status = 'all';
        if (isset($_GET['audit_status'])) {
            // Input var okay.
            $audit_status = sanitize_text_field(wp_unslash($_GET['audit_status']));
            // Input var okay.
        }
        ?>

	<h1><?php 
        esc_attr_e('All Audits', 'msa');
        ?>
		<a href="#" class="page-title-action msa-add-new-audit" <?php 
        if (false !== ($in_progress = get_transient('msa_running_audit'))) {
            ?>
 onclick="alert('<?php 
/**
 * 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');
}
Exemple #9
0
/**
 * Check to see if we can add a new audit
 *
 * @access public
 * @param mixed $data      The audit data.
 * @return bool true|false Determine if the audit can be added.
 */
function msa_add_new_audit_check($data)
{
    $audit_model = new MSA_Audits_Model();
    $audits = $audit_model->get_data();
    if (count($audits) >= msa_get_max_audits()) {
        return false;
    }
    return true;
}
Exemple #10
0
/**
 *  Delete an audit
 */
if (isset($_GET['action']) && 'delete' === $_GET['action'] && check_admin_referer('msa-delete-audit')) {
    // Input var okay.
    $audit = -1;
    if (isset($_GET['audit'])) {
        // Input var okay.
        $audit = sanitize_text_field(wp_unslash($_GET['audit']));
        // Input var okay.
    }
    $audit_model = new MSA_Audits_Model();
    $audit_model->delete_data($audit);
    msa_force_redirect(get_admin_url() . 'admin.php?page=msa-all-audits');
}
/**
 *  Force Stop an audit
 */
if (isset($_GET['action']) && 'force_stop_audit' === $_GET['action'] && check_admin_referer('msa-force-stop-audit')) {
    // Input var okay.
    delete_transient('msa_running_audit');
    $audit_model = new MSA_Audits_Model();
    $audits = $audit_model->get_data(array('status' => 'in-progress'));
    if (isset($audits[0])) {
        $audit = $audits[0];
        $audit['status'] = 'completed';
        $audit_model->update_data($audit['id'], $audit);
    }
    msa_force_redirect(get_admin_url() . 'admin.php?page=msa-all-audits');
}
include_once MY_SITE_AUDIT_PLUGIN_DIR . 'views/all-audits.php';