Esempio n. 1
0
 /**
  * Setups tabs
  *
  * @return void
  */
 function init_tabs()
 {
     $this->tabs->add('reports', __('Reports', APP_TD));
     $fields = array(array('title' => __('Registered Users Only', APP_TD), 'name' => array('reports', 'users_only'), 'type' => 'checkbox', 'desc' => __('Only allow registered users to report problems.', APP_TD), 'tip' => ''), array('title' => __('Notification Email', APP_TD), 'name' => array('reports', 'send_email'), 'type' => 'checkbox', 'desc' => __('Send me an email when a problem has been reported.', APP_TD), 'tip' => ''), array('title' => __('Report Post Values', APP_TD), 'desc' => '<br />' . __('Enter the different options you want available for the report feature. Enter one per line.', APP_TD), 'type' => 'textarea', 'sanitize' => array($this, 'report_options_clean'), 'name' => array('reports', 'post_options'), 'extra' => array('rows' => 10, 'cols' => 50, 'class' => 'large-text'), 'tip' => ''));
     if (appthemes_reports_get_args('users')) {
         $fields[] = array('title' => __('Report User Options', APP_TD), 'desc' => '<br />' . __('Enter the different options you want available for the report feature. Enter one per line.', APP_TD), 'type' => 'textarea', 'sanitize' => array($this, 'report_options_clean'), 'name' => array('reports', 'user_options'), 'extra' => array('rows' => 10, 'cols' => 50, 'class' => 'large-text'), 'tip' => '');
     }
     $this->tab_sections['reports']['general'] = array('title' => '', 'fields' => $fields);
 }
Esempio n. 2
0
 /**
  * Sets the CPT as parent page in menu.
  *
  * @param string $parent_file
  *
  * @return string
  */
 public function reports_set_menu_parent_page($parent_file)
 {
     global $pagenow, $submenu_file;
     $post_types = appthemes_reports_get_args('post_type');
     foreach ($post_types as $post_type) {
         $page_parent = $post_type == 'post' ? 'edit.php' : 'edit.php?post_type=' . $post_type;
         if (!isset($_GET['post_type']) || !isset($_GET['comment_type'])) {
             break;
         }
         if ($pagenow == 'edit-comments.php' && $_GET['post_type'] == $post_type && $_GET['comment_type'] == APP_REPORTS_CTYPE) {
             // highlight menu item
             $submenu_file = add_query_arg($_GET, 'edit-comments.php');
             return $page_parent;
         }
     }
     return $parent_file;
 }
Esempio n. 3
0
 /**
  * Setups reports post metabox
  *
  * @return void
  */
 public function __construct()
 {
     parent::__construct('reports-post', __('Reports', APP_TD), appthemes_reports_get_args('post_type'), 'normal', 'default');
 }
Esempio n. 4
0
 /**
  * Handles adding reports via ajax
  *
  * @return void
  */
 public static function ajax_add_report()
 {
     if ('POST' != $_SERVER['REQUEST_METHOD']) {
         die(json_encode(array('success' => false, 'message' => __('Sorry, only post method allowed.', APP_TD))));
     }
     $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
     if ($id < 1) {
         die(json_encode(array('success' => false, 'message' => __('Sorry, item does not exist.', APP_TD))));
     }
     if (!isset($_POST['type']) || !in_array($_POST['type'], array('post', 'user'))) {
         die(json_encode(array('success' => false, 'message' => __('Sorry, invalid item type.', APP_TD))));
     }
     if ($_POST['type'] == 'user' && !appthemes_reports_get_args('users')) {
         die(json_encode(array('success' => false, 'message' => __('Sorry, invalid item type.', APP_TD))));
     }
     if (!isset($_POST['report']) || appthemes_clean($_POST['report']) != $_POST['report']) {
         die(json_encode(array('success' => false, 'message' => __('Sorry, invalid report message.', APP_TD))));
     }
     if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'add-report')) {
         die(json_encode(array('success' => false, 'message' => __('Sorry, invalid request.', APP_TD))));
     }
     $item = $_POST['type'] == 'post' ? get_post($id) : get_userdata($id);
     if (!$item) {
         die(json_encode(array('success' => false, 'message' => __('Sorry, item does not exist.', APP_TD))));
     }
     $options = appthemes_load_reports_options();
     if ($options->get(array('reports', 'users_only')) && !is_user_logged_in()) {
         die(json_encode(array('success' => false, 'message' => __('Sorry, only registered users can report.', APP_TD))));
     }
     $comment = array('comment_content' => appthemes_clean($_POST['report']));
     if ($_POST['type'] == 'post') {
         $comment['comment_post_ID'] = $id;
         $report = appthemes_create_report($comment);
         if (!$report) {
             die(json_encode(array('success' => false, 'message' => __('Sorry, could not create report.', APP_TD))));
         }
         APP_Report_Comments_Email_Notify::notify_admin($report);
     } else {
         $report = appthemes_create_user_report($id, $comment);
         if (!$report) {
             die(json_encode(array('success' => false, 'message' => __('Sorry, could not create report.', APP_TD))));
         }
     }
     die(json_encode(array('success' => true, 'message' => __('Thank you. Report has been submitted.', APP_TD))));
 }
Esempio n. 5
0
 /**
  * Helper method to retrieve reports comment types
  *
  * @param array	$args (optional) WP_Comment_Query args to be used to fetch the reports
  *
  * @return array List of comments
  */
 private static function _get_reports($args = array())
 {
     $defaults = array('status' => 'approve');
     $args = wp_parse_args($args, $defaults);
     $args['type'] = appthemes_reports_get_args('comment_type');
     return get_comments($args);
 }
Esempio n. 6
0
/**
 * Registers and enqueue the default styles
 *
 * @return void
 */
function appthemes_reports_enqueue_styles()
{
    $url = appthemes_reports_get_args('url');
    wp_enqueue_style('app-reports', $url . '/style.css', null, APP_REPORTS_VERSION);
}
Esempio n. 7
0
/**
 * Returns an HTML form for reporting item
 *
 * @param int $id The post or user ID
 * @param string $type (optional) Type of reported item, post or user
 *
 * @return string The report form
 */
function appthemes_get_reports_form($id, $type = 'post')
{
    $options = appthemes_load_reports_options();
    $select_options_type = $type == 'post' ? 'post_options' : 'user_options';
    $select_options = $options->get(array('reports', $select_options_type));
    if (empty($select_options)) {
        return false;
    }
    if ($type == 'user' && !appthemes_reports_get_args('users')) {
        return false;
    }
    if ($options->get(array('reports', 'users_only')) && !is_user_logged_in()) {
        return false;
    }
    $select_options = explode("\n", $select_options);
    $select_html = '';
    foreach ($select_options as $option) {
        $select_html .= html('option', array('value' => $option), $option);
    }
    $select_html = html('select', array('name' => 'report'), $select_html);
    $nonce = wp_create_nonce('add-report');
    $form = '<div class="reports_message"><span class="spinner"></span>' . __('Processing your request, Please wait....', APP_TD) . '</div>';
    $form .= '<div class="reports_form">';
    $form .= '<form method="post" enctype="text/plain">';
    $form .= $select_html;
    $form .= html('input', array('type' => 'submit', 'name' => 'submit', 'value' => __('Report', APP_TD)));
    $form .= html('input', array('type' => 'hidden', 'name' => 'type', 'value' => $type));
    $form .= html('input', array('type' => 'hidden', 'name' => 'id', 'value' => $id));
    $form .= html('input', array('type' => 'hidden', 'name' => 'nonce', 'value' => $nonce));
    $form .= '</form>';
    $form .= '</div>';
    return $form;
}