Plugin Directory

Changeset 2450387


Ignore:
Timestamp:
01/05/2021 07:25:24 AM (5 years ago)
Author:
drew010
Message:

PSR-12 code style fixes

Location:
vigilantor/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • vigilantor/trunk/templates/admin.phtml

    r2303090 r2450387  
    206206          <?php _e('Exit list update frequency:', 'vigilantor') ?>
    207207          <select name="vitor_el_update_frequency">
    208             <?php foreach($this->_updateFrequencies as $name => $freq): ?>
     208            <?php foreach($this->updateFrequencies as $name => $freq): ?>
    209209            <option value="<?php echo $name ?>"<?php if ($name == get_option('vitor_el_update_frequency', '_10m')): ?> selected="selected"<?php endif; ?>><?php echo $freq['display'] ?></option>
    210210            <?php endforeach; ?>
     
    218218        <br>
    219219        <em>
    220         <?php if ($this->_hasUdpSupport()): ?>
     220        <?php if ($this->hasUdpSupport()): ?>
    221221        <?php printf(__('You can use the real-time checks as %s streams are enabled.'), '<code>udp://</code>'); ?>
    222222        <?php else: ?>
     
    289289        toggleShowBlockedMessage();
    290290
    291         <?php if (!$this->_hasUdpSupport()): ?>
     291        <?php if (!$this->hasUdpSupport()): ?>
    292292        jQuery('#vitor_enable_realtime').prop('disabled', true);
    293293        jQuery('#vitor_realtime_timeout').prop('disabled', true);
  • vigilantor/trunk/templates/flagged_users.phtml

    r1700970 r2450387  
    11<h3>Flagged Registrations</h3>
    22
    3 <?php $users = $this->_getFlaggedRegistrations(); ?>
     3<?php $users = $this->getFlaggedRegistrations(); ?>
    44
    55<div id="vitor_no_flagged_registrations"<?php if (sizeof($users) > 0) echo ' style="display: none"'; ?>>
  • vigilantor/trunk/vigilantor.php

    r2450376 r2450387  
    4545class VigilanTorWP
    4646{
    47     private $_wpdb;
    48     private $_menuSlug = 'vigilantor';
    49     private $_updateFrequencies;
    50     private $_exitList;
    51     private $_customBlockList;
    52     private $_realtimeEnabled = false;
    53     private $_useCustomBlockList = false;
    54     private $_blockedByCustomList = false;
    55     private $_cloudflareEnabled = false;
    56     private static $_instance = null;
     47    private $wpdb;
     48    private $menuSlug = 'vigilantor';
     49    private $updateFrequencies;
     50    private $exitList;
     51    private $customBlockList;
     52    private $realtimeEnabled = false;
     53    private $useCustomBlockList = false;
     54    private $blockedByCustomList = false;
     55    private $cloudflareEnabled = false;
     56    private static $instance = null;
    5757
    5858    // These lists contain all addresses from the Tor bulk exit list in addition to IPv6 exit addresses and exit nodes
     
    6767        global $wpdb;
    6868
    69         $this->_wpdb = $wpdb;
    70 
    71         $this->_updateFrequencies = array(
     69        $this->wpdb = $wpdb;
     70
     71        $this->updateFrequencies = array(
    7272            '_10m'  => array('interval' => 600,  'display' => __('Every 10 minutes')),
    7373            '_20m'  => array('interval' => 1200, 'display' => __('Every 20 minutes')),
     
    8383        add_action   ('wp_ajax_vitor_clear_flag', array(&$this, 'clearFlagAction'));
    8484        add_filter   ('widget_text', 'do_shortcode');
    85         add_filter   ('cron_schedules', array(&$this, '_addSchedules'));
     85        add_filter   ('cron_schedules', array(&$this, 'addSchedules'));
    8686        add_shortcode('tor_users', array(&$this, 'doTorUserShortcode'));
    8787        add_shortcode('non_tor_users', array(&$this, 'doNonTorUserShortcode'));
     
    8989
    9090        if (true == get_option('vitor_enable_realtime', 0)) {
    91             $this->_realtimeEnabled = true;
     91            $this->realtimeEnabled = true;
    9292        }
    9393
    9494        if (true == get_option('vitor_custom_blocklist_enabled', 0)) {
    95             $this->_useCustomBlockList= true;
     95            $this->useCustomBlockList= true;
    9696        }
    9797
     
    111111                add_action('bp_signup_validate', array(&$this, 'processBPRegistrationAction'), 0);
    112112            }
    113         } else if (true == get_option('vitor_flag_registration', 0)) {
     113        } elseif (true == get_option('vitor_flag_registration', 0)) {
    114114            global $wp_version;
    115115
     
    131131
    132132        if (true == get_option('vitor_cloudflare_enabled', 0)) {
    133             $this->_cloudflareEnabled = true;
    134         }
    135     }
    136 
    137     public function wpAuthCallback(&$username, &$password) {
    138         // get instance (PHP 5.3). PHP 5.4+ could reference $this here
    139         $vt = VigilanTorWP::run();
    140         if ($vt->isTorUser()) {
    141             $vt->_blockLogin    = true;
     133            $this->cloudflareEnabled = true;
     134        }
     135    }
     136
     137    public function wpAuthCallback(&$username, &$password)
     138    {
     139        if ($this->isTorUser()) {
     140            $this->blockLogin = true;
    142141            $username = $password = null;
    143142        }
     
    146145    public static function run()
    147146    {
    148         if (self::$_instance) {
    149             return self::$_instance;
     147        if (self::$instance) {
     148            return self::$instance;
    150149        } else {
    151             self::$_instance = new self();
    152             return self::$_instance;
     150            self::$instance = new self();
     151            return self::$instance;
    153152        }
    154153    }
     
    166165            $updated = 0;
    167166            // only update if the list is older than the update interval
    168             if (time() - $lastUpdate > $this->_updateFrequencies[$frequency]['interval']) {
     167            if (time() - $lastUpdate > $this->updateFrequencies[$frequency]['interval']) {
    169168                $this->updateExitList();
    170169                $updated = 1;
     
    188187
    189188        if (!empty($captchaType)) {
    190             if ($this->_checkCookie() === true) {
     189            if ($this->checkCookie() === true) {
    191190                return ;
    192191            }
    193192
    194             $captcha = $this->_getCaptchaHtml($captchaType);
     193            $captcha = $this->getCaptchaHtml($captchaType);
    195194        }
    196195
     
    200199
    201200        if ($block_page_id == 0 || !($post = get_post($block_page_id))) {
    202             if ($this->_blockedByCustomList) {
     201            if ($this->blockedByCustomList) {
    203202                $message = get_option('vitor_custom_block_message', null);
    204203                if (empty($message)) {
     
    356355        global $bp;
    357356
    358         $error = '';
    359357        if ($this->isTorUser()) {
    360358            update_site_option('vitor_stat_registration', (int)get_site_option('vitor_stat_registration') + 1);
    361359            $error = __('Sorry, you are not allowed to register for this site while using Tor!', 'vigilantor');
    362360            $bp->signup->errors['vitor'] = $error; // have to set some error otherwise registration is allowed
    363             $GLOBALS['_vitor_bp_registration_error'] = $error;
     361            $GLOBALS['vitor_bp_registration_error'] = $error;
    364362            add_action('bp_before_account_details_fields', array(&$this, 'bpOutputRegistrationError'));
    365363            return false;
     
    369367    }
    370368
    371     public function bpOutputRegistrationError() {
    372         global $_vitor_bp_registration_error;
    373 
    374         echo "<div><div class='error'>{$_vitor_bp_registration_error}</div></div>";
     369    public function bpOutputRegistrationError()
     370    {
     371        global $vitor_bp_registration_error;
     372
     373        echo "<div><div class='error'>{$vitor_bp_registration_error}</div></div>";
    375374    }
    376375
     
    391390    public function processLoginAction($user, $username, $password)
    392391    {
    393         if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($this->_blockLogin) && $this->_blockLogin === true) {
     392        if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($this->blockLogin) && $this->blockLogin === true) {
    394393            update_site_option('vitor_stat_login', (int)get_site_option('vitor_stat_login') + 1);
    395394            $error = new WP_Error();
     
    426425        $frequency  = get_option('vitor_el_update_frequency', '_10m');
    427426
    428         if (time() - $lastUpdate > $this->_updateFrequencies[$frequency]['interval']) {
     427        if (time() - $lastUpdate > $this->updateFrequencies[$frequency]['interval']) {
    429428            // workaround for sites where wp-cron isn't working for one reason or another
    430429            if (!$called) {
     
    442441        $ip     = $this->getClientIpAddress();
    443442
    444         if ($this->_realtimeEnabled) {
     443        if ($this->realtimeEnabled) {
    445444            if ($this->doRealTimeLookup($ip) === true) {
    446445                return true;
     
    452451        }
    453452
    454         if ($this->_useCustomBlockList) {
     453        if ($this->useCustomBlockList) {
    455454            if ($this->findInCustomBlocklist($ip)) {
    456                 $this->_blockedByCustomList = true;
     455                $this->blockedByCustomList = true;
    457456                return true;
    458457            }
     
    499498        }
    500499
    501         $hook = add_options_page('Tor Blocking Settings', 'VigilanTor Settings', 'manage_options', $this->_menuSlug, array(&$this, 'adminPage'));
     500        $hook = add_options_page('Tor Blocking Settings', 'VigilanTor Settings', 'manage_options', $this->menuSlug, array(&$this, 'adminPage'));
    502501        add_action('admin_init', array(&$this, 'registerSettings'));
    503502        add_action('load-' . $hook, array(&$this, 'addHelpMenu'));
     
    590589
    591590        if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true') {
    592             $this->_scheduleUpdate();
     591            $this->scheduleUpdate();
    593592        }
    594593
     
    650649    public function getPluginSettingsUrl()
    651650    {
    652         return network_admin_url() . 'options-general.php?page=' . $this->_menuSlug;
     651        return network_admin_url() . 'options-general.php?page=' . $this->menuSlug;
    653652    }
    654653
     
    663662    {
    664663        $instance = self::run();
    665         $instance->_install();
     664        $instance->doInstall();
    666665    }
    667666
     
    672671    }
    673672
    674     public function _scheduleUpdate()
     673    public function scheduleUpdate()
    675674    {
    676675        wp_clear_scheduled_hook('vitor_update_lists');
     
    680679    }
    681680
    682     private function _install()
    683     {
    684         $this->_scheduleUpdate();
     681    private function doInstall()
     682    {
     683        $this->scheduleUpdate();
    685684        $this->updateExitList();
    686685    }
     
    696695            $message = __('No user ID given', 'vigilantor');
    697696        } else {
    698             $deleted = $this->_wpdb->delete(
    699                 $this->_wpdb->base_prefix . 'usermeta',
     697            $deleted = $this->wpdb->delete(
     698                $this->wpdb->base_prefix . 'usermeta',
    700699                array('user_id' => $user_id, 'meta_key' => 'vitor_flagged_registration'),
    701700                array('%d', '%s')
     
    718717    }
    719718
    720     public function _addSchedules($schedules)
    721     {
    722         $temp = $this->_updateFrequencies;
     719    public function addSchedules($schedules)
     720    {
     721        $temp = $this->updateFrequencies;
    723722        unset($temp['_60m']);
    724723
     
    728727    private function findInExitList($ip_address)
    729728    {
    730         return false !== $this->_arrayBinarySearch($ip_address, $this->getExitList());
     729        return false !== $this->arrayBinarySearch($ip_address, $this->getExitList());
    731730    }
    732731
     
    803802        set_site_transient('vitor_list_updating', '1', 30);
    804803
    805         $list = $this->_downloadExitList();
     804        $list = $this->downloadExitList();
    806805        if (!$list) return false;
    807806
     
    834833    public function getExitList()
    835834    {
    836         if ($this->_exitList !== null) {
    837             return $this->_exitList;
     835        if ($this->exitList !== null) {
     836            return $this->exitList;
    838837        }
    839838
     
    841840
    842841        if ($list === false) {
    843             if ($this->_downloadExitList()) {
     842            if ($this->downloadExitList()) {
    844843                $list = get_option('vitor_exit_list');
    845844            }
     
    847846
    848847        if (is_array($list) && sizeof($list) > 0) {
    849             $this->_exitList = $list;
     848            $this->exitList = $list;
    850849        }
    851850
     
    855854    public function getCustomBlocklist()
    856855    {
    857         if ($this->_customBlockList !== null) {
    858             return $this->_customBlockList;
     856        if ($this->customBlockList !== null) {
     857            return $this->customBlockList;
    859858        }
    860859
     
    884883    }
    885884
    886     private function _downloadExitList()
     885    private function downloadExitList()
    887886    {
    888887        $use_ssl = false;
     
    893892                $use_ssl = true;
    894893            }
    895         } else if (in_array('https', stream_get_wrappers())) {
     894        } elseif (in_array('https', stream_get_wrappers())) {
    896895            $use_ssl = true;
    897896        }
     
    933932        $ipAddress = $_SERVER['REMOTE_ADDR'];
    934933
    935         if ($this->_cloudflareEnabled) {
     934        if ($this->cloudflareEnabled) {
    936935            // NB: If the cloudflare setting is enabled and the site is not using cloudflare, this header cannot be trusted.
    937936            if (!empty($_SERVER['HTTP_CF_REQUEST_ID']) && !empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
     
    945944    }
    946945
    947     private function _getFlaggedRegistrations()
     946    private function getFlaggedRegistrations()
    948947    {
    949948        $query = "SELECT t1.user_id, t1.meta_value AS tor_ip, t2.user_login, t2.user_email, t2.user_registered "
     
    951950                ."WHERE meta_key = 'vitor_flagged_registration'";
    952951
    953         $t1    = $this->_wpdb->base_prefix . 'usermeta';
    954         $t2    = $this->_wpdb->base_prefix . 'users';
    955         $users = $this->_wpdb->get_results(sprintf($query, $t1, $t2));
     952        $t1    = $this->wpdb->base_prefix . 'usermeta';
     953        $t2    = $this->wpdb->base_prefix . 'users';
     954        $users = $this->wpdb->get_results(sprintf($query, $t1, $t2));
    956955
    957956        return $users;
     
    964963     * @return bool true if the cookie is valid, false if not or not set
    965964     */
    966     private function _checkCookie()
     965    private function checkCookie()
    967966    {
    968967        if (isset($_COOKIE['_vitor_access_token']) &&
     
    979978                $t = get_site_transient('vitor_token:' . $token_id);
    980979                if ($t === $value) {
    981                     $this->_setVitorCookie($token_id); // update cookie with new value (prevents sharing cookies)
     980                    $this->setVitorCookie($token_id); // update cookie with new value (prevents sharing cookies)
    982981                    return true;
    983982                }
     
    10491048    }
    10501049
    1051     private function _getCaptchaHtml($captchaType)
     1050    private function getCaptchaHtml($captchaType)
    10521051    {
    10531052        $captcha_error = '';
     
    10871086
    10881087            if ($valid) {
    1089                 $this->_setVitorCookie();
     1088                $this->setVitorCookie();
    10901089                $_SERVER['REQUEST_METHOD'] = 'GET';
    10911090                wp_redirect($_SERVER['REQUEST_URI']);
     
    11041103    }
    11051104
    1106     private function _setVitorCookie()
     1105    private function setVitorCookie()
    11071106    {
    11081107        $token_id    = sha1(sha1(wp_generate_password(mt_rand(64, 128), true, true)) . sha1(wp_generate_password(mt_rand(128, 256), true, true)));
     
    11321131     * @return boolean|number false if not found, or index if found
    11331132     */
    1134     private function _arrayBinarySearch($needle, $haystack)
     1133    protected function arrayBinarySearch($needle, $haystack)
    11351134    {
    11361135        $high = count($haystack);
     
    11531152    }
    11541153
    1155     private function _hasUdpSupport()
     1154    private function hasUdpSupport()
    11561155    {
    11571156        return in_array('udp', stream_get_transports());
Note: See TracChangeset for help on using the changeset viewer.