Ejemplo n.º 1
0
    /**
     * Plugin options page.
     *
     * Rendering goes here, checks for active tab and replaces key with the related
     * settings key. Uses the _options_tabs method to render the tabs.
     *
     * @since 2.0.0
     */
    public function settings_page()
    {
        $plugin = get_plugin_data(ZEROSPAM_PLUGIN);
        $tab = isset($_GET['tab']) ? $_GET['tab'] : 'zerospam_general_settings';
        $page = isset($_GET['p']) ? $_GET['p'] : 1;
        $action = is_plugin_active_for_network(plugin_basename(ZEROSPAM_PLUGIN)) ? 'edit.php?action=zerospam' : 'options.php';
        ?>
    <div class="wrap">
      <h2><?php 
        echo __('WordPress Zero Spam', 'zerospam');
        ?>
</h2>
      <?php 
        $this->option_tabs();
        ?>
      <div class="zerospam__row">
        <div class="zerospam__right">
        <?php 
        require_once ZEROSPAM_ROOT . 'inc/admin-sidebar.tpl.php';
        ?>
        </div>
        <div class="zerospam__left">
        <?php 
        if ('zerospam_spammer_logs' == $tab && '1' == $this->settings['log_spammers']) {
            $ajax_nonce = wp_create_nonce('zero-spam');
            $limit = 10;
            $args = array('limit' => $limit, 'offset' => ($page - 1) * $limit);
            $spam = zerospam_get_spam($args);
            $spam = zerospam_parse_spam_ary($spam);
            $all_spam = zerospam_all_spam_ary();
            if ($all_spam['raw']) {
                $starting_date = $all_spam['date_start'];
                // end( $all_spam['raw'] )->date;
                $num_days = zerospam_num_days($starting_date);
                $per_day = $num_days ? number_format(count($all_spam['raw']) / $num_days, 2) : 0;
            }
            if (isset($this->settings['ip_location_support']) && '1' == $this->settings['ip_location_support']) {
                $ip_location_support = true;
            } else {
                $ip_location_support = false;
            }
            require_once ZEROSPAM_ROOT . 'inc/spammer-logs.tpl.php';
        } elseif ($tab == 'zerospam_ip_block') {
            $limit = 10;
            $args = array('limit' => $limit, 'offset' => ($page - 1) * $limit);
            $ips = zerospam_get_blocked_ips($args);
            require_once ZEROSPAM_ROOT . 'inc/ip-block.tpl.php';
        } else {
            require_once ZEROSPAM_ROOT . 'inc/general-settings.tpl.php';
        }
        ?>
        </div>

      </div>
    </div>
    <?php 
    }
Ejemplo n.º 2
0
 /**
  * Uses wp_ajax_(action).
  *
  * Get's spam by IP.
  *
  * @since 2.0.0
  *
  * @link http://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)
  */
 public function wp_ajax_get_ip_spam()
 {
     global $wpdb;
     check_ajax_referer('zero-spam', 'security');
     // $spam = zerospam_get_spam();
     $spam = zerospam_all_spam_ary();
     $spam = $spam['by_spam_count'];
     $return = array('by_country' => array(), 'by_lat_long' => array());
     // API usage limit protection.
     $limit = 10;
     $cnt = 0;
     foreach ($spam as $key => $obj) {
         $cnt++;
         if ($cnt > 10) {
             break;
         }
         $loc = zerospam_get_ip_info($obj->ip);
         if ($loc) {
             if (!isset($return['by_country'][$loc->country_code])) {
                 $return['by_country'][$loc->country_code] = array('count' => 0, 'name' => $loc->country_name);
             }
             $return['by_country'][$loc->country_code]['count']++;
             if (!isset($return['by_lat_long'][$obj->ip])) {
                 $return['by_lat_long'][$obj->ip] = array('latLng' => array($loc->latitude, $loc->longitude), 'name' => $loc->country_name, 'count' => 1);
             }
         }
         sleep(1);
     }
     arsort($return['by_country']);
     echo json_encode($return);
     die;
 }