Plugin Directory

Changeset 2580769


Ignore:
Timestamp:
08/10/2021 09:51:14 AM (5 years ago)
Author:
newsplugin.com
Message:

Update to version 1.1.0 from GitHub

Location:
newsplugin
Files:
8 added
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • newsplugin/tags/1.1.0/news-plugin-utils.php

    r2384451 r2580769  
    11<?php
     2
     3/**
     4 * Utils
     5 *
     6 * @package    WordPress
     7 * @subpackage News Plugin
     8 * @since 1.0.0
     9 */
    210
    311// Prevent ourselves from being run directly.
     
    513
    614if (!function_exists('json_last_error_msg')) {
     15
     16    /**
     17     * Get error message
     18     *
     19     * @return string
     20     */
    721    function json_last_error_msg()
    822    {
    9         static $ERRORS = array(
     23        static $ERRORS = [
    1024            JSON_ERROR_NONE => 'No error',
    1125            JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
     
    1428            JSON_ERROR_SYNTAX => 'Syntax error',
    1529            JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
    16         );
     30        ];
    1731
    1832        $error = json_last_error();
     
    2135}
    2236
     37/**
     38 * Utils
     39 *
     40 * @package News Plugin
     41 */
    2342class News_Plugin_Utils
    24 { // Although maybe namespace would suffice
    25 
    26     static $np_version = NULL;
    27 
    28     static function np_version()
     43{
     44
     45    /**
     46     * Plugin version
     47     *
     48     * @var mixed
     49     */
     50    public static $np_version = null;
     51
     52    /**
     53     * Get plugin version
     54     *
     55     * @return mixed
     56     */
     57    public static function np_version()
    2958    {
    3059        if (self::$np_version) {
    3160            return (self::$np_version);
    3261        }
     62        // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
    3363        if (self::$np_version = get_option('news_plugin_version')) {
    3464            return (self::$np_version);
     
    3767    }
    3868
    39     static function np_version_hard()
     69    /**
     70     * Get plugin version from plugin file
     71     *
     72     * @return mixed
     73     */
     74    public static function np_version_hard()
    4075    {
    4176        if (!function_exists('get_plugin_data')) {
     
    4984    }
    5085
    51     static function user_agent($type)
     86    /**
     87     * Create a plugin specific user agent
     88     *
     89     * @param string $type Type of the user agent.
     90     * @return string
     91     */
     92    public static function user_agent($type)
    5293    {
    5394        global $wp_version;
     
    5697    }
    5798
    58     static function http_remote_get_curl($url)
     99    /**
     100     * CURL request
     101     *
     102     * TODO: replace with WP function
     103     *
     104     * @param string $url Request URL.
     105     * @return string[]|(string|bool)[]
     106     */
     107    public static function http_remote_get_curl($url)
    59108    {
    60109        if (!function_exists('curl_version')) {
    61             return (array('', 'Error: CURL disabled or not installed'));
     110            return (['', 'Error: CURL disabled or not installed']);
    62111        }
    63112        if (!function_exists('curl_init') || !function_exists('curl_exec')) {
    64             return (array('', 'Error: CURL disabled by security settings'));
     113            return (['', 'Error: CURL disabled by security settings']);
    65114        }
    66115        $ch = curl_init($url);
     
    75124        }
    76125        curl_close($ch);
    77         return array($output, $error);
    78     }
    79 
    80     static function http_remote_get_socket($url)
     126        return [$output, $error];
     127    }
     128
     129    /**
     130     * Get socket request
     131     *
     132     * @param string $url Request URL.
     133     * @return string[]
     134     */
     135    public static function http_remote_get_socket($url)
    81136    {
    82137        if (!function_exists('stream_socket_client')) {
    83             return (array('', 'Error: Socket disabled'));
     138            return (['', 'Error: Socket disabled']);
    84139        }
    85140        $aURL = parse_url($url);
    86141        $addr = $aURL['host'];
    87         $secure_transport = ($aURL['scheme'] == 'ssl' || $aURL['scheme'] == 'https');
     142        $secure_transport = ($aURL['scheme'] === 'ssl' || $aURL['scheme'] === 'https');
    88143        if (!isset($aURL['port'])) {
    89144            if ($secure_transport) {
     
    100155        $socket = stream_socket_client($proto . $addr . ':' . $aURL['port'], $errno, $errorMessage, 10, STREAM_CLIENT_CONNECT);
    101156        if ($socket === false) {
    102             return (array('', 'Socket error: ' . $errorMessage));
     157            return (['', 'Socket error: ' . $errorMessage]);
    103158        }
    104159        $url = $aURL['path'];
     
    113168        fclose($socket);
    114169        if (preg_match('/^(.*?)\r?\n\r?\n(.*)$/s', $output, $m)) {
    115             return (array($m[2], ''));
    116         }
    117         return (array($output, ''));
    118     }
    119 
    120     static function http_test_evaluate($ret)
     170            return ([$m[2], '']);
     171        }
     172        return ([$output, '']);
     173    }
     174
     175    /**
     176     * Test content checker
     177     * TODO - move to proper testing suit
     178     *
     179     * @param mixed $ret Retrieved content.
     180     * @return mixed
     181     */
     182    public static function http_test_evaluate($ret)
    121183    {
    122184        if ((!$ret[1]) && (!preg_match('/var swfobject=function()/s', $ret[0]))) {
     
    127189    }
    128190
    129     static $test_url = 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
    130 
    131     static function http_remote_get_curl_test()
     191    /**
     192     * Test URL
     193     *
     194     * @var string
     195     */
     196    public static $test_url = 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
     197
     198    /**
     199     * Test Curl funcion
     200     * TODO - move to proper testing suit
     201     *
     202     * @return mixed
     203     */
     204    public static function http_remote_get_curl_test()
    132205    {
    133206        $ret = self::http_remote_get_curl(self::$test_url);
     
    135208    }
    136209
    137     static function http_remote_get_socket_test()
     210    /**
     211     * Test Get Socket
     212     * TODO - move to proper testing suit
     213     *
     214     * @return mixed
     215     */
     216    public static function http_remote_get_socket_test()
    138217    {
    139218        $ret = self::http_remote_get_socket(self::$test_url);
     
    141220    }
    142221
    143     static $test_url_ssl = 'https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
    144 
    145     static function http_remote_get_curl_test_ssl()
     222    /**
     223     * Test URL for SSL
     224     *
     225     * @var string
     226     */
     227    public static $test_url_ssl = 'https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
     228
     229    /**
     230     * Test Curl with SSL
     231     * TODO - move to proper testing suit
     232     *
     233     * @return mixed
     234     */
     235    public static function http_remote_get_curl_test_ssl()
    146236    {
    147237        $ret = self::http_remote_get_curl(self::$test_url_ssl);
     
    149239    }
    150240
    151     static function http_remote_get_socket_test_ssl()
     241    /**
     242     * Test Get Socket with SSL
     243     * TODO - move to proper testing suit
     244     *
     245     * @return mixed
     246     */
     247    public static function http_remote_get_socket_test_ssl()
    152248    {
    153249        $ret = self::http_remote_get_socket(self::$test_url_ssl);
     
    155251    }
    156252
    157     static $api_root = 'http://api.newsplugin.com/';
    158     static $api_ping_path = 'ping';
    159 
    160     static function http_ping_evaluate($var)
     253    /**
     254     * API root
     255     *
     256     * @var string
     257     */
     258    public static $api_root = 'http://api.newsplugin.com/';
     259
     260    /**
     261     * API ping PATH
     262     *
     263     * @var string
     264     */
     265    public static $api_ping_path = 'ping';
     266
     267    /**
     268     * Evaluate HTTP ping
     269     *
     270     * @param mixed $var Variable.
     271     * @return mixed
     272     */
     273    public static function http_ping_evaluate($var)
    161274    {
    162275        $output = $var[0];
     
    174287    }
    175288
    176     static function http_remote_get_curl_ping()
     289    /**
     290     * CURL ping
     291     *
     292     * @return mixed
     293     */
     294    public static function http_remote_get_curl_ping()
    177295    {
    178296        $var = self::http_remote_get_curl(self::$api_root . self::$api_ping_path);
     
    180298    }
    181299
    182     static function http_remote_get_socket_ping()
     300    /**
     301     * Get Socket ping
     302     *
     303     * @return mixed
     304     */
     305    public static function http_remote_get_socket_ping()
    183306    {
    184307        $var = self::http_remote_get_socket(self::$api_root . self::$api_ping_path);
     
    186309    }
    187310
    188     static function generic_remote_get($url, $method)
     311    /**
     312     * Remote GET request
     313     *
     314     * @param string $url Request URL.
     315     * @param string $method Method type.
     316     * @return mixed
     317     */
     318    public static function generic_remote_get($url, $method)
    189319    {
    190320        switch ($method) {
    191321            case 'wp':
    192                 $ret = wp_remote_get($url, array('timeout' => 10, 'user-agent' => self::user_agent('wp')));
     322                $ret = wp_remote_get($url, ['timeout' => 10, 'user-agent' => self::user_agent('wp')]);
    193323                if (is_array($ret)) {
    194                     return (array($ret['body'], ''));
     324                    return ([$ret['body'], '']);
    195325                }
    196326                $ret = self::generic_remote_get($url, 'curl');
     
    209339    }
    210340
    211     static function generic_api_call($path, $args = NULL)
     341    /**
     342     * Call API
     343     *
     344     * @param string     $path Path withing the URL.
     345     * @param mixed|null $args Arguments.
     346     * @return mixed
     347     */
     348    public static function generic_api_call($path, $args = null)
    212349    {
    213350        $key = get_option('news_plugin_api_key');
    214         $args = $args ? $args : array();
     351        $args = $args ? $args : [];
    215352        $args['k'] = $key;
    216353        $url = self::$api_root . $path;
     
    219356        $ret = self::generic_remote_get($url, $method ? $method : 'wp');
    220357        if ($ret[1]) {
    221             $currentTime = date('y-m-d h:i:s', time());
     358            $currentTime = gmdate('y-m-d h:i:s', time());
     359            // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.Changed, WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
    222360            $backtrace = debug_backtrace();
     361            // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
    223362            error_log("$currentTime  -->   " . "Error accessing API point " . self::$api_root . "$path: " . $ret[1] . "  Log Generation Details :      Filename: " . $backtrace[0]['file'] . "   at Line number : " . $backtrace[0]['line'] . "\n\n", 3, __DIR__ . "/logs/plugin-logs.txt");
    224             return (NULL);
     363            return (null);
    225364        }
    226365        return (json_decode($ret[0]));
    227366    }
    228367
    229     static function get_user_info()
     368    /**
     369     * Get user info
     370     *
     371     * @return mixed
     372     */
     373    public static function get_user_info()
    230374    {
    231375        return (self::generic_api_call('user_info'));
    232376    }
    233377
    234     static function get_system_info_version()
     378    /**
     379     * Get system info version
     380     * TODO: What a magic constant it is?
     381     */
     382    public static function get_system_info_version()
    235383    {
    236384        return (1.0002);
    237385    }
    238386
    239     static function get_system_db_info()
    240     {
    241         global $wpdb; /* Recommended by https://codex.wordpress.org/Class_Reference/wpdb */
     387    /**
     388     * Get System DB info
     389     *
     390     * @return array
     391     */
     392    public static function get_system_db_info()
     393    {
     394        global $wpdb;
    242395
    243396        if (!empty($wpdb->use_mysqli)) {
    244             /* See also http://fw2s.com/how-to-get-complete-mysql-version-in-wordpress/
    245                Note: use_mysqli is private and dbh is protected, BUT wpdb class is allowing
    246                to access then through getters and setters anyway. Backward compatibility.
    247              */
    248             return (array(
     397            /*
     398             See also http://fw2s.com/how-to-get-complete-mysql-version-in-wordpress/
     399               Note: use_mysqli is private and dbh is protected, BUT wpdb class is allowing
     400               to access then through getters and setters anyway. Backward compatibility.
     401             */
     402            return ([
    249403                'mysql_method'          => 'mysqli',
    250404                'mysql_server_info'     => mysqli_get_server_info($wpdb->dbh),
    251405                'mysql_client_info'     => mysqli_get_client_info($wpdb->dbh),
    252406                'mysql_proto_info'      => mysqli_get_proto_info($wpdb->dbh),
    253             ));
     407            ]);
    254408        } else {
    255             return (array(
     409            return ([
    256410                'mysql_method'          => 'mysql',
     411                // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
    257412                'mysql_server_info'     => mysql_get_server_info(),
     413                // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
    258414                'mysql_client_info'     => mysql_get_client_info(),
     415                // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
    259416                'mysql_proto_info'      => mysql_get_proto_info(),
    260             ));
    261         }
    262     }
    263 
    264     static function get_system_info()
     417            ]);
     418        }
     419    }
     420
     421    /**
     422     * Get system info
     423     *
     424     * @return array
     425     */
     426    public static function get_system_info()
    265427    {
    266428        $my_theme = wp_get_theme();
     
    285447        $db_info = self::get_system_db_info();
    286448
    287         $system_info = array(
     449        $system_info = [
    288450            'info_version' => self::get_system_info_version(),
    289451            'api_key'      => get_option('news_plugin_api_key'), /* We need to refresh on api key change ... */
    290             'wordpress_env' => array(
     452            'wordpress_env' => [
    291453                'siteurl'               => get_bloginfo('url'),
    292454                'version'               => get_bloginfo('version'),
     
    296458                'theme_version'         => $my_theme->get('Version'),
    297459                'theme_AuthorURI'       => $my_theme->get('AuthorURI'),
    298             ),
    299             'system_env' => array(
     460            ],
     461            'system_env' => [
    300462                'php_version'           => phpversion(),
    301                 'SERVER_SOFTWARE'       => $_SERVER['SERVER_SOFTWARE'],
     463                'SERVER_SOFTWARE'       => isset($_SERVER['SERVER_SOFTWARE']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : null,
    302464                'SERVER_OS'             => PHP_OS,
    303                 'SERVER_IP_ADDRESS'     => $_SERVER['SERVER_ADDR'],
    304                 'HTTP_HOST'             => $_SERVER['HTTP_HOST'],
    305                 'SERVER_NAME'           => $_SERVER['SERVER_NAME'],
    306                 'HTTP_USER_AGENT'       => $_SERVER['HTTP_USER_AGENT'],
    307                 'HTTP_ACCEPT'           => $_SERVER['HTTP_ACCEPT'],
     465                'SERVER_IP_ADDRESS'     => isset($_SERVER['SERVER_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_ADDR'])) : null,
     466                'HTTP_HOST'             => isset($_SERVER['HTTP_HOST']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST'])) : null,
     467                'SERVER_NAME'           => isset($_SERVER['SERVER_NAME']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])) : null,
     468                'HTTP_USER_AGENT'       => isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])) : null,
     469                'HTTP_ACCEPT'           => isset($_SERVER['HTTP_ACCEPT']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_ACCEPT'])) : null,
    308470                'memory_limit'          => ini_get('memory_limit'),
    309471                'execution_time'        => ini_get('max_execution_time'),
     
    320482                'socket_status'         => $socket_test[1] ? $socket_test[1] : 'OK',
    321483                'socket_status_ssl'     => $socket_test_ssl[1] ? $socket_test_ssl[1] : 'OK',
    322             ),
    323             'newsplugin_env' => array(
     484            ],
     485            'newsplugin_env' => [
    324486                'REGISTERED EMAIL'      => $user_info ? $user_info->email : 'error or unregistered',
    325487                'USER STATUS'           => $user_info ? $user_info->status : 'error or unregistered',
     
    327489                'curl_ping'             => $curl_ping[1] ? $curl_ping[1] : ('OK from ' . $curl_ping[0]->client),
    328490                'socket_ping'           => $socket_ping[1] ? $socket_ping[1] : ('OK from ' . $socket_ping[0]->client),
    329             )
    330         );
    331         if ($curl_test[1] == $curl_test_ssl[1]) {
     491            ]
     492        ];
     493        if ($curl_test[1] === $curl_test_ssl[1]) {
    332494            unset($system_info['system_env']['curl_status_ssl']);
    333495        }
    334         if ($socket_test[1] == $socket_test_ssl[1]) {
     496        if ($socket_test[1] === $socket_test_ssl[1]) {
    335497            unset($system_info['system_env']['socket_status_ssl']);
    336498        }
  • newsplugin/tags/1.1.0/news-plugin-widget.php

    r2384451 r2580769  
    11<?php
     2
     3/**
     4 * Widget
     5 *
     6 * @package    WordPress
     7 * @subpackage News Plugin
     8 * @since 1.0.0
     9 */
    210
    311// Prevent ourselves from being run directly.
     
    1321     * Register widget with WordPress.
    1422     */
    15     function __construct()
     23    public function __construct()
    1624    {
    1725        parent::__construct(
    1826            'news_plugin_widget',
    1927            __('NewsPlugin', 'news_plugin'),
    20             array('description' => __('Create custom newsfeeds and let fresh relevant news appear on your website (or approve and publish them manually).', 'news_plugin'),)
     28            ['description' => __('Create custom newsfeeds and let fresh relevant news appear on your website (or approve and publish them manually).', 'news_plugin'),]
    2129        );
    2230    }
     
    4048    private function current_options()
    4149    {
    42         $opts = get_option('news_plugin_widget_options', array());
    43         $opts = (isset($opts[$this->widget_id()])) ? $opts[$this->widget_id()] : array();
     50        $opts = get_option('news_plugin_widget_options', []);
     51        $opts = (isset($opts[$this->widget_id()])) ? $opts[$this->widget_id()] : [];
    4452        return $opts;
    4553    }
     
    4755    /**
    4856     * Update the private options specific for this widget.
     57     *
     58     * @param mixed $args Arguments.
     59     * @return mixed
    4960     */
    5061    private function update_options($args)
    5162    {
    52         $opts = get_option('news_plugin_widget_options', array());
     63        $opts = get_option('news_plugin_widget_options', []);
    5364        $opts[$this->widget_id()] = $args;
    5465        update_option('news_plugin_widget_options', $opts);
     
    6273    {
    6374        $opts = $this->current_options();
    64         $posts = (isset($opts['excluded'])) ? $opts['excluded'] : array();
     75        $posts = (isset($opts['excluded'])) ? $opts['excluded'] : [];
    6576        return $posts;
    6677    }
     
    6879    /**
    6980     * Add given id to the list of excluded posts.
     81     *
     82     * @param int $id ID.
     83     * @param int $limit Limit.
     84     * @return array
    7085     */
    7186    private function exclude_post($id, $limit = 100)
     
    86101    {
    87102        $opts = $this->current_options();
    88         $posts = array();
     103        $posts = [];
    89104        $opts['excluded'] = $posts;
    90105        $this->update_options($opts);
     
    98113    {
    99114        $opts = $this->current_options();
    100         $posts = (isset($opts['favorite'])) ? $opts['favorite'] : array();
     115        $posts = (isset($opts['favorite'])) ? $opts['favorite'] : [];
    101116        return $posts;
    102117    }
     
    104119    /**
    105120     * Add given id to the list of favorite posts.
     121     *
     122     * @param int $id ID.
     123     * @param int $limit Limit.
     124     * @return array
    106125     */
    107126    private function star_favorite_post($id, $limit = 100)
     
    118137    /**
    119138     * Remove given id from the list of favorite posts.
     139     *
     140     * @param int $id ID.
     141     * @return mixed
    120142     */
    121143    private function unstar_favorite_post($id)
     
    123145        $opts = $this->current_options();
    124146        $posts = $this->favorite_posts();
    125         $posts = array_diff($posts, array($id));
     147        $posts = array_diff($posts, [$id]);
    126148        $opts['favorite'] = $posts;
    127149        $this->update_options($opts);
     
    135157    {
    136158        $opts = $this->current_options();
    137         $posts = array();
     159        $posts = [];
    138160        $opts['favorite'] = $posts;
    139161        $this->update_options($opts);
     
    152174    /**
    153175     * Set the timestamp of the last publishing in manual publishing mode.
     176     *
     177     * @param int $time Timestamp.
     178     * @return mixed
    154179     */
    155180    private function update_publish_time($time)
     
    163188    /**
    164189     * Prepare the args for URL managing posts of this widget.
     190     *
     191     * @param string $action Action name.
     192     * @param int    $arg Number of arguments.
     193     * @return array
    165194     */
    166195    private function create_action_args($action, $arg = 0)
    167196    {
    168         return array(
     197        return [
    169198            'news_plugin_instance' => $this->widget_id(),
    170199            'news_plugin_action' => $action,
    171200            'news_plugin_arg' => $arg,
    172         );
     201            '_wpnonce' => wp_create_nonce('news_plugin_url_nonce'),
     202        ];
    173203    }
    174204
     
    178208    private function parse_action_args()
    179209    {
    180         if ((!isset($_GET['news_plugin_instance'])) || ($_GET['news_plugin_instance'] != $this->widget_id())) {
    181             return array();
    182         }
    183         return array(
    184             'action' => isset($_GET['news_plugin_action']) ? $_GET['news_plugin_action'] : '',
    185             'arg' => isset($_GET['news_plugin_arg']) ? $_GET['news_plugin_arg'] : '',
    186         );
     210        // Verify nonce.
     211        $nonce = isset($_GET['news_plugin_url_nonce']) ? sanitize_key($_GET['news_plugin_url_nonce']) : null;
     212        if ($nonce && !wp_verify_nonce($nonce) && $_GET['news_plugin_instance']) {
     213            die(esc_html__('1 - Security check failed. Try to submit the form once again.', 'news_plugin'));
     214        }
     215
     216        if ((!isset($_GET['news_plugin_instance'])) || ($_GET['news_plugin_instance'] !== $this->widget_id())) {
     217            return [];
     218        }
     219        return [
     220            'action' => isset($_GET['news_plugin_action']) ? sanitize_key(wp_unslash($_GET['news_plugin_action'])) : '',
     221            'arg' => isset($_GET['news_plugin_arg']) ? sanitize_key(wp_unslash($_GET['news_plugin_arg'])) : '',
     222        ];
    187223    }
    188224
     
    220256    private function edit_mode_enabled()
    221257    {
     258        // Verify nonce.
     259        $nonce = isset($_GET['news_plugin_url_nonce']) ? sanitize_key($_GET['news_plugin_url_nonce']) : null;
     260        if ($nonce && !wp_verify_nonce($nonce) && isset($_GET['news_plugin_action']) ) {
     261            die(esc_html__('2 - Security check failed. Try to submit the form once again.', 'news_plugin'));
     262        }
     263
    222264        if (isset($_GET['news_plugin_action'])) {
    223             $action = $_GET['news_plugin_action'];
     265            $action = sanitize_key(wp_unslash($_GET['news_plugin_action']));
    224266            return !empty($action);
    225267        }
     
    228270    /**
    229271     * Manage the feed as necessary.
     272     *
     273     * @param mixed $opts Options.
     274     * @return void
    230275     */
    231276    private function manage($opts)
    232277    {
    233278        switch ($this->current_action()) {
    234             case 'exclude': {
    235                     $id = sanitize_key($this->current_arg());
    236                     $limit = max(100, 2 * $opts['count']);
    237                     $this->exclude_post($id, $limit);
    238                     break;
    239                 }
    240             case 'star': {
    241                     $id = sanitize_key($this->current_arg());
    242                     $limit = max(100, 2 * $opts['count']);
    243                     $this->star_favorite_post($id, $limit);
    244                     break;
    245                 }
    246             case 'unstar': {
    247                     $id = sanitize_key($this->current_arg());
    248                     $this->unstar_favorite_post($id);
    249                     break;
    250                 }
    251             case 'reset': {
    252                     $this->reset_excluded_posts();
    253                     $this->reset_favorite_posts();
    254                     break;
    255                 }
    256             case 'publish': {
    257                     $time = min(time(), absint($this->current_arg()));
    258                     $this->update_publish_time($time);
    259                     break;
    260                 }
     279            case 'exclude':
     280                $id = sanitize_key($this->current_arg());
     281                $limit = max(100, 2 * $opts['count']);
     282                $this->exclude_post($id, $limit);
     283                break;
     284            case 'star':
     285                $id = sanitize_key($this->current_arg());
     286                $limit = max(100, 2 * $opts['count']);
     287                $this->star_favorite_post($id, $limit);
     288                break;
     289            case 'unstar':
     290                $id = sanitize_key($this->current_arg());
     291                $this->unstar_favorite_post($id);
     292                break;
     293            case 'reset':
     294                $this->reset_excluded_posts();
     295                $this->reset_favorite_posts();
     296                break;
     297            case 'publish':
     298                $time = min(time(), absint($this->current_arg()));
     299                $this->update_publish_time($time);
     300                break;
    261301        }
    262302    }
     
    264304    /**
    265305     * Silly helper for returning caching duration for fetch_feed().
    266      */
    267     function get_feed_caching_duration($seconds)
     306     *
     307     * @return int
     308     */
     309    public function get_feed_caching_duration()
    268310    {
    269311        return 3600;
     
    272314    /**
    273315     * Get our data feed.
     316     *
     317     * @param int   $time Time.
     318     * @param mixed $opts Options.
     319     * @param int   $limit Limit.
     320     * @return SimplePie|WP_Error|null
    274321     */
    275322    private function get_feed($time, $opts, $limit = 100)
     
    277324        $key = get_option('news_plugin_api_key');
    278325
    279         $args = array(
     326        $args = [
    280327            'k' => $key,
    281328            'q' => $opts['keywords'],
     
    283330            'c' => $opts['count'],
    284331            't' => $opts['title']
    285             // o offset
    286             // a after
    287             // b before
    288         );
    289 
    290         if ($opts['feed_mode'] == 'manual') {
     332            // o offset.
     333            // a after.
     334            // b before.
     335        ];
     336
     337        if ($opts['feed_mode'] === 'manual') {
    291338            if (!($this->can_manage() && $this->edit_mode_enabled())) {
    292339                $time = $this->publish_time();
     
    328375
    329376        // Talk about stupid API. Like if the cache duration couldn't be a simple parameter.
    330         $cache_filter = array($this, 'get_feed_caching_duration');
     377        $cache_filter = [$this, 'get_feed_caching_duration'];
    331378        add_filter('wp_feed_cache_transient_lifetime', $cache_filter);
    332379        $feed = fetch_feed($url);
    333380        remove_filter('wp_feed_cache_transient_lifetime', $cache_filter);
    334381
    335         return (is_wp_error($feed) ? NULL : $feed);
    336     }
    337 
     382        return (is_wp_error($feed) ? null : $feed);
     383    }
     384
     385    /**
     386     * CSS style helpers
     387     *
     388     * @param mixed $style Style.
     389     * @param mixed $type Type.
     390     * @return string
     391     */
    338392    private function compute_style_helper($style, $type)
    339393    {
     
    343397        $ret = '';
    344398        if ($style[$type]['size']) {
    345             $ret .= 'font-size: ' . $style[$type]['size'] . 'px;';
     399            $ret .= 'font-size:' . $style[$type]['size'] . 'px;';
    346400        }
    347401        if ($style[$type]['color']) {
     
    351405            $ret .= 'font-family:' . $style[$type]['font_family'] . ';';
    352406        }
    353         if (!$ret) {
    354             return ($ret);
    355         }
    356         return (' style="' . $ret . '"');
     407        if ($ret) {
     408            return ' style=' . $ret ;
     409        }
    357410    }
    358411
     
    370423
    371424        if (!isset($rss)) {
    372             _e('Feed fetch failed ', 'news_plugin');
     425            esc_html_e('Feed fetch failed ', 'news_plugin');
    373426            return;
    374427        }
    375428
    376         $manual_mode = ($opts['feed_mode'] == 'manual');
     429        $manual_mode = ($opts['feed_mode'] === 'manual');
    377430
    378431        $exclude = array_fill_keys($this->excluded_posts(), true);
     
    393446                $args = $this->create_action_args('reset');
    394447                echo '<a href="' . esc_attr(add_query_arg($args)) . '">';
    395                 echo 'Reset';
     448                esc_html_e('Reset', 'news_plugin');
    396449                echo '</a>';
    397450
     
    400453                    echo ' | ';
    401454                    echo '<a href="' . esc_attr(add_query_arg($args)) . '">';
    402                     echo 'Publish Headlines';
     455                    esc_html_e('Publish Headlines', 'news_plugin');
    403456                    echo '</a>';
    404457                }
    405458
    406                 $args = $this->create_action_args(NULL, NULL);
     459                $args = $this->create_action_args(null, null);
    407460                echo ' | ';
    408461                echo '<a href="' . esc_attr(add_query_arg($args)) . '">';
    409                 echo 'Leave Edit Newsfeed Mode';
     462                esc_html_e('Leave Edit Newsfeed Mode', 'news_plugin');
    410463                echo '</a>';
    411464
     
    415468                echo '<p class="news-plugin-edit-buttons">';
    416469                echo '<a href="' . esc_attr(add_query_arg($args)) . '">';
    417                 echo 'Edit Newsfeed Mode';
     470                esc_html_e('Edit Newsfeed Mode', 'news_plugin');
    418471                echo '</a>';
    419472            }
     
    421474            if ($manual_mode) {
    422475                $t = $this->publish_time();
    423                 if ($t == 0) {
     476                if ($t === 0) {
    424477                    if ($this->edit_mode_enabled()) {
    425478                        echo '<p>';
    426                         echo 'No headlines published yet.';
     479                        esc_html_e('No headlines published yet.', 'news_plugin');
    427480                        echo '</p>';
    428481                    } else {
    429482                        echo '<p>';
    430                         echo 'No headlines published yet. Use the Edit Newsfeed Mode to edit and publish your feed.';
     483                        esc_html_e('No headlines published yet. Use the Edit Newsfeed Mode to edit and publish your feed.', 'news_plugin');
    431484                        echo '</p>';
    432485                    }
    433486                } else {
    434                     $t = date('d M Y H:i', $t);
     487                    // TODO localize properly.
     488                    $t = gmdate('d M Y H:i', $t);
    435489                    echo '<p>';
    436                     echo "Headlines last published on {$t}.";
     490                    // TODO localize properly.
     491                    echo esc_html("Headlines last published on {$t}.");
    437492                    echo '</p>';
    438493                }
     
    442497                if ($manual_mode) {
    443498                    echo '<p>';
    444                     echo "Once published, only the first {$limit} headline" . ($limit == 1 ? '' : 's') . " will be displayed in your feed.";
     499                    // TODO localize properly.
     500                    echo esc_html("Once published, only the first {$limit} headline" . ($limit === 1 ? '' : 's') . " will be displayed in your feed.");
     501                    // TODO localize properly.
    445502                    echo ' You can <span style="font-size:110%;">&#9734;</span>&nbsp;Star individual headlines to move them to the top or &#10005;&nbsp;Remove them from the feed. Click Reset to undo these changes.';
    446                     echo ' Don’t forget to Publish Headlines when you are done.';
     503                    esc_html_e(' Don’t forget to Publish Headlines when you are done.', 'news_plugin');
    447504                    echo '</p>';
    448505                } else {
    449506                    echo '<p>';
     507                    // TODO localize properly.
    450508                    echo 'You can <span style="font-size:110%;">&#9734;</span>&nbsp;Star individual headlines to move them to the top or &#10005;&nbsp;Remove them from the feed. Click Reset to undo these changes.';
    451509                    echo '</p>';
     
    460518        $index = 0;
    461519
    462         if ($opts['wp_uid'] && (intval($opts['wp_uid']) != 0)) {
     520        if ($opts['wp_uid'] && (intval($opts['wp_uid']) !== 0)) {
    463521            $userID = intval($opts['wp_uid']);
    464522        } else {
     
    479537                }
    480538
    481                 if (!empty($favorite[$id]) xor ($pass == 0)) {
     539                if (!empty($favorite[$id]) xor ($pass === 0)) {
    482540                    continue;
    483541                }
    484542
    485                 if ($index == $limit) {
     543                if ($index === $limit) {
    486544                    echo '<hr>';
    487545                }
    488546
    489547                echo '<li>';
    490                 if ($opts['link_follow'] == 'no') {
     548                if ($opts['link_follow'] === 'no') {
    491549                    $s_follow = ' rel="nofollow"';
    492550                } else {
     
    498556                    $s_target = '';
    499557                }
    500                 echo '<a href="' . esc_attr($item->get_permalink()) . '"' . $s_target . $s_follow . '>';
     558                echo '<a href="' . esc_url($item->get_permalink()) . '"' . esc_attr($s_target) . esc_attr($s_follow) . '>';
    501559                $style = $this->compute_style_helper($style_news, 'article_headline');
    502                 echo '<span class="news-plugin-title"' . $style . '>';
     560                echo '<span class="news-plugin-title"' . esc_attr($style) . '>';
    503561                echo esc_html($item->get_title());
    504562                echo '</span>';
     
    507565                    echo "\n";
    508566                    $style = $this->compute_style_helper($style_news, 'article_date');
    509                     echo '<span class="news-plugin-date"' . $style . '>';
     567                    echo '<span class="news-plugin-date"' . esc_attr($style) . '>';
    510568                    echo esc_html($item->get_date(get_option('date_format') . ' ' . get_option('time_format')));
    511569                    echo '</span>';
     
    513571                if ($opts['show_source']) {
    514572                    // Because RSS doesn't support the source field, we use the author field.
    515                     // $source = $item->get_source() ;
    516573                    $source = $item->get_author();
    517                     if ($source) $source = $source->get_email();
     574                    if ($source) {
     575                        $source = $source->get_email();
     576                    }
    518577                    if (!empty($source)) {
    519578                        echo "\n";
    520579                        $style = $this->compute_style_helper($style_news, 'article_sources');
    521                         echo '<span class="news-plugin-source"' . $style . '>';
     580                        echo '<span class="news-plugin-source"' . esc_attr($style) . '>';
    522581                        echo esc_html($source);
    523582                        echo '</span>';
     
    527586                    echo "\n";
    528587                    $style = $this->compute_style_helper($style_news, 'article_abstract');
    529                     echo '<span class="news-plugin-abstract"' . $style . '>';
     588                    echo '<span class="news-plugin-abstract"' . esc_attr($style) . '>';
    530589                    echo esc_html($item->get_description());
    531590                    echo '</span>';
     
    535594                    $args = $this->create_action_args('exclude', $id);
    536595                    echo ' &nbsp; <a href="' . esc_attr(add_query_arg($args)) . '">';
    537                     // echo 'X' ;
    538596                    echo '<span style="text-decoration: underline;">';
    539597                    echo '&#10005;&nbsp;Remove';
     
    543601                        $args = $this->create_action_args('unstar', $id);
    544602                        echo ' <a href="' . esc_attr(add_query_arg($args)) . '">';
    545                         // echo '-' ;
    546603                        echo '<span style="text-decoration: underline;">';
    547604                        echo '<span style="font-size:110%;">&#9733;</span>&nbsp;Unstar';
     
    551608                        $args = $this->create_action_args('star', $id);
    552609                        echo ' <a href="' . esc_attr(add_query_arg($args)) . '">';
    553                         // echo '+' ;
    554610                        echo '<span style="text-decoration: underline;">';
    555611                        echo '<span style="font-size:110%;">&#9734;</span>&nbsp;Star';
     
    565621        }
    566622        echo '</ul>';
    567 
    568         //Error in Option Page
    569         // newserroforwp_log("NewsPlugin Option Page");
    570623    }
    571624
     
    589642        if (empty($key)) {
    590643            if ($this->can_manage()) {
    591 ?>
     644                ?>
    592645                <p>
    593                     Your feed is currently inactive.
    594                     Please enter your Activation Key on the
    595                     <a href="<?php echo admin_url('admin.php?page=news-plugin-settings') ?>">NewsPlugin Settings</a>
    596                     page first.
     646                    <?php esc_html_e('Your feed is currently inactive.', 'news_plugin'); ?>
     647                    <?php esc_html_e('Please enter your Activation Key on the', 'news_plugin'); ?>
     648                    <a href="<?php echo esc_url(admin_url('admin.php?page=news-plugin-settings')) ?>"><?php esc_html_e('NewsPlugin Settings', 'news_plugin'); ?></a>
     649                    <?php esc_html_e('page first', 'news_plugin'); ?>.
    597650                </p>
    598             <?php
     651                <?php
    599652            }
    600653            return;
     
    607660        $title = apply_filters('widget_title', $opts['title']);
    608661
    609         echo $args['before_widget'];
    610         if (!empty($title))
    611             echo $args['before_title'] . $title . $args['after_title'];
     662        echo wp_kses_post($args['before_widget']);
     663        if (!empty($title)) {
     664            echo wp_kses_post($args['before_title'] . $title . $args['after_title']);
     665        }
    612666        $this->content($opts);
    613         echo $args['after_widget'];
     667        echo wp_kses_post($args['after_widget']);
    614668    }
    615669
     
    627681            ?>
    628682            <p>
    629                 Please enter your Activation Key on the
    630                 <a href="<?php echo admin_url('admin.php?page=news-plugin-settings') ?>">NewsPlugin Settings</a>
    631                 page first.
     683                <?php esc_html_e('Please enter your Activation Key on the', 'news_plugin'); ?>
     684                <a href="<?php echo esc_url(admin_url('admin.php?page=news-plugin-settings')); ?>"><?php esc_html_e('NewsPlugin Settings', 'news_plugin'); ?></a>
     685                <?php esc_html_e('page first.', 'news_plugin'); ?>
    632686            </p>
    633         <?php
     687            <?php
    634688            return;
    635689        }
     
    726780
    727781        // Force expert user mode for now.
    728         // $user_mode = get_option( 'news_plugin_user_mode' ) ;
     782        // $user_mode = get_option( 'news_plugin_user_mode' ); .
    729783        $user_mode = 2;
    730784
    731785        ?>
    732786        <p>
    733             <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Newsfeed Name:'); ?></label>
    734             <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>">
     787            <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Newsfeed Name:', 'news_plugin'); ?></label>
     788            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>">
    735789            <br>
    736             <small>Give your feed a good name.</small>
     790            <small><?php esc_html_e('Give your feed a good name.', 'news_plugin'); ?></small>
    737791            <br>
    738             <small>Example: Canada Solar Energy News</small>
     792            <small><?php esc_html_e('Example: Canada Solar Energy News', 'news_plugin'); ?></small>
    739793        </p>
    740794        <p>
    741             <label for="<?php echo $this->get_field_id('keywords'); ?>"><?php _e('Keywords:'); ?></label>
    742             <input class="widefat" id="<?php echo $this->get_field_id('keywords'); ?>" name="<?php echo $this->get_field_name('keywords'); ?>" type="text" value="<?php echo esc_attr($keywords); ?>">
     795            <label for="<?php echo esc_attr($this->get_field_id('keywords')); ?>"><?php esc_html_e('Keywords:', 'news_plugin'); ?></label>
     796            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('keywords')); ?>" name="<?php echo esc_attr($this->get_field_name('keywords')); ?>" type="text" value="<?php echo esc_attr($keywords); ?>">
    743797            <br>
    744             <small>Use keywords to find relevant news.</small>
     798            <small><?php esc_html_e('Use keywords to find relevant news.', 'news_plugin'); ?></small>
    745799            <br>
    746             <small>Example: canada &amp; "solar energy"</small>
     800            <small><?php esc_html_e('Example: canada &amp; "solar energy"', 'news_plugin'); ?></small>
    747801            <br>
    748             <small>Read the <a href="http://newsplugin.com/faq#keyword-tips" target="_blank">FAQ</a> for more keywords tips and examples.</small>
     802            <small><?php printf(esc_html__('Read the %S for more keywords tips and examples.', 'news_plugin'), '<a href="http://newsplugin.com/faq#keyword-tips" target="_blank">' . esc_html__('FAQ', 'news_plugin') . '</a'); ?></small>
    749803        </p>
    750804        <p>
    751             <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Number of Articles:'); ?></label>
    752             <input class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo $count; ?>">
     805            <label for="<?php echo esc_attr($this->get_field_id('count')); ?>"><?php esc_html_e('Number of Articles:', 'news_plugin'); ?></label>
     806            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('count')); ?>" name="<?php echo esc_attr($this->get_field_name('count')); ?>" type="text" value="<?php echo esc_attr($count); ?>">
    753807            <br>
    754             <small>Set how many headlines to show in your feed.</small>
     808            <small><?php esc_html_e('Set how many headlines to show in your feed.', 'news_plugin'); ?></small>
    755809            <br>
    756             <small>Example: 10</small>
     810            <small><?php esc_html_e('Example: 10', 'news_plugin'); ?></small>
    757811        </p>
    758812        <p>
    759             <input id="<?php echo $this->get_field_id('show_date'); ?>" name="<?php echo $this->get_field_name('show_date'); ?>" type="checkbox" <?php if ($show_date) echo 'checked="checked"' ?>>
    760             <label for="<?php echo $this->get_field_id('show_date'); ?>"><?php _e('Show Dates'); ?></label>
     813            <input id="<?php echo esc_attr($this->get_field_id('show_date')); ?>" name="<?php echo esc_attr($this->get_field_name('show_date')); ?>" type="checkbox" <?php if ($show_date) {
     814                echo 'checked="checked"';
     815                       } ?>>
     816            <label for="<?php echo esc_attr($this->get_field_id('show_date')); ?>"><?php esc_html_e('Show Dates', 'news_plugin'); ?></label>
    761817        </p>
    762818        <p>
    763             <input id="<?php echo $this->get_field_id('show_source'); ?>" name="<?php echo $this->get_field_name('show_source'); ?>" type="checkbox" <?php if ($show_source) echo 'checked="checked"' ?>>
    764             <label for="<?php echo $this->get_field_id('show_source'); ?>"><?php _e('Show Sources'); ?></label>
     819            <input id="<?php echo esc_attr($this->get_field_id('show_source')); ?>" name="<?php echo esc_attr($this->get_field_name('show_source')); ?>" type="checkbox" <?php if ($show_source) {
     820                echo 'checked="checked"';
     821                       } ?>>
     822            <label for="<?php echo esc_attr($this->get_field_id('show_source')); ?>"><?php esc_html_e('Show Sources', 'news_plugin'); ?></label>
    765823        </p>
    766824        <p>
    767             <input id="<?php echo $this->get_field_id('show_abstract'); ?>" name="<?php echo $this->get_field_name('show_abstract'); ?>" type="checkbox" <?php if ($show_abstract) echo 'checked="checked"' ?>>
    768             <label for="<?php echo $this->get_field_id('show_abstract'); ?>"><?php _e('Show Abstracts'); ?></label>
     825            <input id="<?php echo esc_attr($this->get_field_id('show_abstract')); ?>" name="<?php echo esc_attr($this->get_field_name('show_abstract')); ?>" type="checkbox" <?php if ($show_abstract) {
     826                echo 'checked="checked"';
     827                       } ?>>
     828            <label for="<?php echo esc_attr($this->get_field_id('show_abstract')); ?>"><?php esc_html_e('Show Abstracts', 'news_plugin'); ?></label>
    769829            <br>
    770             <small>By default, your feed displays headlines only. You can add more information.</small>
     830            <small><?php esc_html_e('By default, your feed displays headlines only. You can add more information.', 'news_plugin'); ?></small>
    771831            <br>
    772             <small>Example: New Reports on Canada Solar Energy, 12 Feb 2015 (BBC)</small>
     832            <small><?php esc_html_e('Example: New Reports on Canada Solar Energy, 12 Feb 2015 (BBC)', 'news_plugin'); ?></small>
    773833        </p>
    774834        <?php
    775835        if ($user_mode > 0) {
    776 
    777836            /*
    778         <p>
    779         <label for="<?php echo $this->get_field_id( 'sources' ); ?>"><?php _e( 'Sources:' ); ?></label>
    780         <input class="widefat" id="<?php echo $this->get_field_id( 'sources' ); ?>" name="<?php echo $this->get_field_name( 'sources' ); ?>" type="text" value="<?php echo esc_attr( $sources ) ; ?>">
    781         <br>
    782         <small>Show news from only selected sources. Leave blank for all sources.</small>
    783         <br>
    784         <small>Example: BBC</small>
    785         </p>
    786         <p>
    787         <label for="<?php echo $this->get_field_id( 'excluded_sources' ); ?>"><?php _e( 'Excluded Sources:' ); ?></label>
    788         <input class="widefat" id="<?php echo $this->get_field_id( 'excluded_sources' ); ?>" name="<?php echo $this->get_field_name( 'excluded_sources' ); ?>" type="text" value="<?php echo esc_attr( $excluded_sources ) ; ?>">
    789         <br>
    790         <small>Don’t show news from selected sources.</small>
    791         <br>
    792         <small>Example: BBC</small>
    793         </p>
    794         */
    795 
    796         ?>
     837        <p>
     838        <label for="<?php echo $this->get_field_id( 'sources' ); ?>"><?php _e( 'Sources:' ); ?></label>
     839        <input class="widefat" id="<?php echo $this->get_field_id( 'sources' ); ?>" name="<?php echo $this->get_field_name( 'sources' ); ?>" type="text" value="<?php echo esc_attr( $sources ) ; ?>">
     840        <br>
     841        <small>Show news from only selected sources. Leave blank for all sources.</small>
     842        <br>
     843        <small>Example: BBC</small>
     844        </p>
     845        <p>
     846        <label for="<?php echo $this->get_field_id( 'excluded_sources' ); ?>"><?php _e( 'Excluded Sources:' ); ?></label>
     847        <input class="widefat" id="<?php echo $this->get_field_id( 'excluded_sources' ); ?>" name="<?php echo $this->get_field_name( 'excluded_sources' ); ?>" type="text" value="<?php echo esc_attr( $excluded_sources ) ; ?>">
     848        <br>
     849        <small>Don’t show news from selected sources.</small>
     850        <br>
     851        <small>Example: BBC</small>
     852        </p>
     853        */
     854
     855            ?>
    797856            <p>
    798                 <label for="<?php echo $this->get_field_id('search_mode'); ?>"><?php _e('Search Mode:'); ?></label>
    799                 <select class="widefat" id="<?php echo $this->get_field_id('search_mode'); ?>" name="<?php echo $this->get_field_name('search_mode'); ?>">
    800                     <option value="">Default</option>
    801                     <option value="title" <?php if ($search_mode == "title") echo 'selected="selected"' ?>>Headlines Only</option>
    802                     <option value="text" <?php if ($search_mode == "text") echo 'selected="selected"' ?>>Headlines &amp; Full Text</option>
     857                <label for="<?php echo esc_attr($this->get_field_id('search_mode')); ?>"><?php esc_html_e('Search Mode:', 'news_plugin'); ?></label>
     858                <select class="widefat" id="<?php echo esc_attr($this->get_field_id('search_mode')); ?>" name="<?php echo esc_attr($this->get_field_name('search_mode')); ?>">
     859                    <option value=""><?php esc_html_e('Default', 'news_plugin'); ?></option>
     860                    <option value="title" <?php if ($search_mode === "title") {
     861                        echo 'selected="selected"';
     862                                          } ?>><?php esc_html_e('Headlines Only', 'news_plugin'); ?></option>
     863                    <option value="text" <?php if ($search_mode === "text") {
     864                        echo 'selected="selected"';
     865                                         } ?>><?php esc_html_e('Headlines &amp; Full Text', 'news_plugin'); ?></option>
    803866                </select>
    804867                <br>
    805                 <small>Show news that has your keywords in a headline or anywhere in an article. Default is headlines and full text.</small>
     868                <small><?php esc_html_e('Show news that has your keywords in a headline or anywhere in an article. Default is headlines and full text.', 'news_plugin'); ?></small>
    806869            </p>
    807870
    808871            <?php
    809872            /*
    810         <p>
    811         <label for="<?php echo $this->get_field_id( 'search_type' ); ?>"><?php _e( 'Search Type:' ); ?></label>
    812         <select class="widefat" id="<?php echo $this->get_field_id( 'search_type' ); ?>" name="<?php echo $this->get_field_name( 'search_type' ); ?>">
    813         <option value="">Default</option>
    814         <option value="news" <?php if ( $search_type == "news" ) echo 'selected="selected"' ?>>News</option>
    815         <option value="pr" <?php if ( $search_type == "pr" ) echo 'selected="selected"' ?>>Press Releases</option>
    816         <option value="event"<?php if ( $search_type == "event" ) echo 'selected="selected"' ?>>Events</option>
    817         </select>
    818         <br>
    819         <small>Show only selected types of news. Default is a combination of all types.</small>
    820         </p>
    821         */
     873        <p>
     874        <label for="<?php echo $this->get_field_id( 'search_type' ); ?>"><?php _e( 'Search Type:' ); ?></label>
     875        <select class="widefat" id="<?php echo $this->get_field_id( 'search_type' ); ?>" name="<?php echo $this->get_field_name( 'search_type' ); ?>">
     876        <option value="">Default</option>
     877        <option value="news" <?php if ( $search_type == "news" ) echo 'selected="selected"' ?>>News</option>
     878        <option value="pr" <?php if ( $search_type == "pr" ) echo 'selected="selected"' ?>>Press Releases</option>
     879        <option value="event"<?php if ( $search_type == "event" ) echo 'selected="selected"' ?>>Events</option>
     880        </select>
     881        <br>
     882        <small>Show only selected types of news. Default is a combination of all types.</small>
     883        </p>
     884        */
    822885            ?>
    823886
    824887            <p>
    825                 <label for="<?php echo $this->get_field_id('sort_mode'); ?>"><?php _e('Sort Mode:'); ?></label>
    826                 <select class="widefat" id="<?php echo $this->get_field_id('sort_mode'); ?>" name="<?php echo $this->get_field_name('sort_mode'); ?>">
    827                     <option value="">Default</option>
    828                     <option value="relevance" <?php if ($sort_mode == "relevance") echo 'selected="selected"' ?>>Relevance</option>
    829                     <option value="date" <?php if ($sort_mode == "date") echo 'selected="selected"' ?>>Date</option>
     888                <label for="<?php echo esc_attr($this->get_field_id('sort_mode')); ?>"><?php esc_html_e('Sort Mode:', 'news_plugin'); ?></label>
     889                <select class="widefat" id="<?php echo esc_attr($this->get_field_id('sort_mode')); ?>" name="<?php echo esc_attr($this->get_field_name('sort_mode')); ?>">
     890                    <option value=""><?php esc_html_e('Default', 'news_plugin'); ?></option>
     891                    <option value="relevance" <?php if ($sort_mode === "relevance") {
     892                        echo 'selected="selected"';
     893                                              } ?>><?php esc_html_e('Relevance', 'news_plugin'); ?></option>
     894                    <option value="date" <?php if ($sort_mode === "date") {
     895                        echo 'selected="selected"';
     896                                         } ?>><?php esc_html_e('Date', 'news_plugin'); ?></option>
    830897                </select>
    831898                <br>
    832                 <small>Show headlines sorted by date or relevance. Default is by relevance.</small>
     899                <small><?php esc_html_e('Show headlines sorted by date or relevance. Default is by relevance.', 'news_plugin'); ?></small>
    833900            </p>
    834901            <p>
    835                 <label for="<?php echo $this->get_field_id('age'); ?>"><?php _e('News Age Limit (in hours):'); ?></label>
    836                 <input class="widefat" id="<?php echo $this->get_field_id('age'); ?>" name="<?php echo $this->get_field_name('age'); ?>" type="text" value="<?php echo $age; ?>">
     902                <label for="<?php echo esc_attr($this->get_field_id('age')); ?>"><?php esc_html_e('News Age Limit (in hours):', 'news_plugin'); ?></label>
     903                <input class="widefat" id="<?php echo esc_attr($this->get_field_id('age')); ?>" name="<?php echo esc_attr($this->get_field_name('age')); ?>" type="text" value="<?php echo esc_attr($age); ?>">
    837904                <br>
    838                 <small>Don’t show articles older than given period. 0 means no limit.</small>
     905                <small><?php esc_html_e('Don’t show articles older than given period. 0 means no limit.', 'news_plugin'); ?></small>
    839906            </p>
    840907            <p>
    841                 <label for="<?php echo $this->get_field_id('link_open_mode'); ?>"><?php _e('Link mode:'); ?></label>
    842                 <select class="widefat" id="<?php echo $this->get_field_id('link_open_mode'); ?>" name="<?php echo $this->get_field_name('link_open_mode'); ?>">
    843                     <option value="">Default</option>
    844                     <option value="_self" <?php if ($link_open_mode == "_self") echo 'selected="selected"' ?>>Same Window</option>
    845                     <option value="_blank" <?php if ($link_open_mode == "_blank") echo 'selected="selected"' ?>>New Tab</option>
     908                <label for="<?php echo esc_attr($this->get_field_id('link_open_mode')); ?>"><?php esc_html_e('Link mode:', 'news_plugin'); ?></label>
     909                <select class="widefat" id="<?php echo esc_attr($this->get_field_id('link_open_mode')); ?>" name="<?php echo esc_attr($this->get_field_name('link_open_mode')); ?>">
     910                    <option value=""><?php esc_html_e('Default', 'news_plugin'); ?></option>
     911                    <option value="_self" <?php if ($link_open_mode === "_self") {
     912                        echo 'selected="selected"';
     913                                          } ?>><?php esc_html_e('Same Window', 'news_plugin'); ?></option>
     914                    <option value="_blank" <?php if ($link_open_mode === "_blank") {
     915                        echo 'selected="selected"';
     916                                           } ?>><?php esc_html_e('New Tab', 'news_plugin'); ?></option>
    846917                </select>
    847                 <label for="<?php echo $this->get_field_id('link_follow'); ?>"><?php _e('Follow mode:'); ?></label>
    848                 <select class="widefat" id="<?php echo $this->get_field_id('link_follow'); ?>" name="<?php echo $this->get_field_name('link_follow'); ?>">
    849                     <option value="">Default</option>
    850                     <option value="yes" <?php if ($link_follow == "yes") echo 'selected="selected"' ?>>Follow</option>
    851                     <option value="no" <?php if ($link_follow == "no") echo 'selected="selected"' ?>>Nofollow</option>
     918                <label for="<?php echo esc_attr($this->get_field_id('link_follow')); ?>"><?php esc_html_e('Follow mode:', 'news_plugin'); ?></label>
     919                <select class="widefat" id="<?php echo esc_attr($this->get_field_id('link_follow')); ?>" name="<?php echo esc_attr($this->get_field_name('link_follow')); ?>">
     920                    <option value=""><?php esc_html_e('Default', 'news_plugin'); ?></option>
     921                    <option value="yes" <?php if ($link_follow === "yes") {
     922                        echo 'selected="selected"';
     923                                        } ?>><?php esc_html_e('Follow', 'news_plugin'); ?></option>
     924                    <option value="no" <?php if ($link_follow === "no") {
     925                        echo 'selected="selected"';
     926                                       } ?>><?php esc_html_e('Nofollow', 'news_plugin'); ?></option>
    852927                </select>
    853928
    854929                <?php
    855 
    856930                /*
    857         <br>
    858         <small>Choose where headlines in your feed link to. These can be either direct links to original articles (bbc.co.uk) or those articles can be framed with your custom name/links.</small>
    859         </p>
    860         <p>
    861         <label for="<?php echo $this->get_field_id( 'link_type' ); ?>"><?php _e( 'Link mode:' ); ?></label>
    862         <select class="widefat" id="<?php echo $this->get_field_id( 'link_type' ); ?>" name="<?php echo $this->get_field_name( 'link_type' ); ?>">
    863         <option value="">Default</option>
    864         <option value="frame" <?php if ( $link_type == "frame" ) echo 'selected="selected"' ?>>Framed</option>
    865         <option value="orig"<?php if ( $link_type == "orig" ) echo 'selected="selected"' ?>>Original</option>
    866         </select>
    867         <br>
    868         <small>Choose where headlines in your feed link to. These can be either direct links to original articles (bbc.co.uk) or those articles can be framed with your custom name/links.</small>
    869         </p>
    870         */
     931        <br>
     932        <small>Choose where headlines in your feed link to. These can be either direct links to original articles (bbc.co.uk) or those articles can be framed with your custom name/links.</small>
     933        </p>
     934        <p>
     935        <label for="<?php echo $this->get_field_id( 'link_type' ); ?>"><?php _e( 'Link mode:' ); ?></label>
     936        <select class="widefat" id="<?php echo $this->get_field_id( 'link_type' ); ?>" name="<?php echo $this->get_field_name( 'link_type' ); ?>">
     937        <option value="">Default</option>
     938        <option value="frame" <?php if ( $link_type == "frame" ) echo 'selected="selected"' ?>>Framed</option>
     939        <option value="orig"<?php if ( $link_type == "orig" ) echo 'selected="selected"' ?>>Original</option>
     940        </select>
     941        <br>
     942        <small>Choose where headlines in your feed link to. These can be either direct links to original articles (bbc.co.uk) or those articles can be framed with your custom name/links.</small>
     943        </p>
     944        */
    871945
    872946                ?>
     
    876950            ?>
    877951                <p>
    878                     <label for="<?php echo $this->get_field_id('feed_mode'); ?>"><?php _e('Feed publishing:'); ?></label>
    879                     <select class="widefat" id="<?php echo $this->get_field_id('feed_mode'); ?>" name="<?php echo $this->get_field_name('feed_mode'); ?>">
    880                         <option value="">Default</option>
    881                         <option value="auto" <?php if ($feed_mode == "auto") echo 'selected="selected"' ?>>Automatic</option>
    882                         <option value="manual" <?php if ($feed_mode == "manual") echo 'selected="selected"' ?>>Manual</option>
     952                    <label for="<?php echo esc_attr($this->get_field_id('feed_mode')); ?>"><?php esc_html_e('Feed publishing:', 'news_plugin'); ?></label>
     953                    <select class="widefat" id="<?php echo esc_attr($this->get_field_id('feed_mode')); ?>" name="<?php echo esc_attr($this->get_field_name('feed_mode')); ?>">
     954                        <option value=""><?php esc_html_e('Default', 'news_plugin'); ?></option>
     955                        <option value="auto" <?php if ($feed_mode === "auto") {
     956                            echo 'selected="selected"';
     957                                             } ?>><?php esc_html_e('Automatic', 'news_plugin'); ?></option>
     958                        <option value="manual" <?php if ($feed_mode === "manual") {
     959                            echo 'selected="selected"';
     960                                               } ?>><?php esc_html_e('Manual', 'news_plugin'); ?></option>
    883961                    </select>
    884962                    <br>
    885                     <small>Your feed can be automatically updated with new headlines, or you can choose headlines and publish them manually using news buffering. Default is automatic.</small>
     963                    <small><?php esc_html_e('Your feed can be automatically updated with new headlines, or you can choose headlines and publish them manually using news buffering. Default is automatic.', 'news_plugin'); ?></small>
    886964                </p>
    887     <?php
     965            <?php
    888966        }
    889967    }
     
    901979    public function update($new_opts, $old_opts)
    902980    {
    903         $opts = array();
    904         $opts['title'] = (!empty($new_opts['title'])) ? strip_tags($new_opts['title']) : '';
    905         $opts['keywords'] = (!empty($new_opts['keywords'])) ? strip_tags($new_opts['keywords']) : '';
     981        $opts = [];
     982        $opts['title'] = (!empty($new_opts['title'])) ? wp_strip_all_tags($new_opts['title']) : '';
     983        $opts['keywords'] = (!empty($new_opts['keywords'])) ? wp_strip_all_tags($new_opts['keywords']) : '';
    906984        $opts['count'] = (!empty($new_opts['count'])) ? absint($new_opts['count']) : 5;
    907985        $opts['age'] = (!empty($new_opts['age'])) ? absint($new_opts['age']) : 0;
    908         $opts['sources'] = (!empty($new_opts['sources'])) ? strip_tags($new_opts['sources']) : '';
    909         $opts['excluded_sources'] = (!empty($new_opts['excluded_sources'])) ? strip_tags($new_opts['excluded_sources']) : '';
    910         $opts['search_mode'] = (!empty($new_opts['search_mode'])) ? strip_tags($new_opts['search_mode']) : '';
    911         $opts['search_type'] = (!empty($new_opts['search_type'])) ? strip_tags($new_opts['search_type']) : '';
    912         $opts['sort_mode'] = (!empty($new_opts['sort_mode'])) ? strip_tags($new_opts['sort_mode']) : '';
    913         $opts['link_open_mode'] = (!empty($new_opts['link_open_mode'])) ? strip_tags($new_opts['link_open_mode']) : '';
    914         $opts['link_follow'] = (!empty($new_opts['link_follow'])) ? strip_tags($new_opts['link_follow']) : '';
    915         $opts['link_type'] = (!empty($new_opts['link_type'])) ? strip_tags($new_opts['link_type']) : '';
     986        $opts['sources'] = (!empty($new_opts['sources'])) ? wp_strip_all_tags($new_opts['sources']) : '';
     987        $opts['excluded_sources'] = (!empty($new_opts['excluded_sources'])) ? wp_strip_all_tags($new_opts['excluded_sources']) : '';
     988        $opts['search_mode'] = (!empty($new_opts['search_mode'])) ? wp_strip_all_tags($new_opts['search_mode']) : '';
     989        $opts['search_type'] = (!empty($new_opts['search_type'])) ? wp_strip_all_tags($new_opts['search_type']) : '';
     990        $opts['sort_mode'] = (!empty($new_opts['sort_mode'])) ? wp_strip_all_tags($new_opts['sort_mode']) : '';
     991        $opts['link_open_mode'] = (!empty($new_opts['link_open_mode'])) ? wp_strip_all_tags($new_opts['link_open_mode']) : '';
     992        $opts['link_follow'] = (!empty($new_opts['link_follow'])) ? wp_strip_all_tags($new_opts['link_follow']) : '';
     993        $opts['link_type'] = (!empty($new_opts['link_type'])) ? wp_strip_all_tags($new_opts['link_type']) : '';
    916994        $opts['show_date'] = !empty($new_opts['show_date']);
    917995        $opts['show_source'] = !empty($new_opts['show_source']);
    918996        $opts['show_abstract'] = !empty($new_opts['show_abstract']);
    919         $opts['feed_mode'] = (!empty($new_opts['feed_mode'])) ? strip_tags($new_opts['feed_mode']) : '';
     997        $opts['feed_mode'] = (!empty($new_opts['feed_mode'])) ? wp_strip_all_tags($new_opts['feed_mode']) : '';
    920998        $opts['wp_uid'] = (!isset($new_opts['wp_uid']) || empty($new_opts['wp_uid'])) ? get_current_user_id() : $new_opts['wp_uid'];
    921999
     
    9231001    }
    9241002}
    925     ?>
     1003?>
  • newsplugin/tags/1.1.0/news-plugin.php

    r2384451 r2580769  
    11<?php
    2 /*
    3 Plugin Name: NewsPlugin
    4 Plugin URI: http://newsplugin.com/
    5 Description: Create custom newsfeeds for your website. Choose keywords, number of articles and other settings, put the feed wherever you want using widgets or shortcodes, and watch the fresh relevant news headlines appear on your pages (or approve and publish them manually). You can always shape the news right from your website, remove unwanted articles or star the good ones. Thanks for using the NewsPlugin, and we hope you like it.
    6 Author: newsplugin.com
    7 Version: 1.0.18
    8 Author URI: http://newsplugin.com/
    9 */
     2
     3/**
     4 * Plugin Name: NewsPlugin
     5 * Plugin URI: http://newsplugin.com/
     6 * Description: Create custom newsfeeds for your website. Choose keywords, number of articles and  * other settings, put the feed wherever you want using widgets or shortcodes, and watch the fresh  * relevant news headlines appear on your pages (or approve and publish them manually).
     7 * Author: newsplugin.com
     8 * Text Domain: news_plugin
     9 * Domain Path: /languages
     10 * Version: 1.1.0
     11 * Author URI: http://newsplugin.com/
     12 *
     13 * @package    WordPress
     14 * @subpackage News Plugin
     15 * @since 1.0.0
     16 */
    1017
    1118// Prevent ourselves from being run directly.
     
    2734     * Register plugin with WordPress.
    2835     */
    29     function __construct()
    30     {
     36    public function __construct()
     37    {
     38
     39        add_action('init', [$this, 'localize']);
     40
    3141        // Widgets.
    32         add_action('widgets_init', array($this, 'widgets_init'));
    33         add_action('admin_init', array($this, 'admin_init'));
    34         add_action('admin_menu', array($this, 'admin_menu'));
    35         add_action('admin_init', array(&$this, 'register_help_section'));
    36         add_action('admin_init', array(&$this, 'register_activation_section'));
    37         add_action('admin_init', array(&$this, 'register_shortcode_section'));
    38         add_action('admin_init', array(&$this, 'register_style_section'));
    39         add_action('admin_init', array(&$this, 'register_feed_section'));
    40         add_action('admin_init', array(&$this, 'register_status_section'));
    41         add_action('admin_enqueue_scripts', array($this, 'register_admin_scripts'));
    42         add_action('wp_enqueue_scripts', array($this, 'register_styles'));
    43 
    44         add_action('admin_post_nopriv_news_plugin_save_style', array($this, 'handle_save_style'));
    45         add_action('admin_post_news_plugin_save_style', array($this, 'handle_save_style'));
    46         add_action('admin_post_nopriv_news_plugin_send_feedback', array($this, 'handle_send_feedback'));
    47         add_action('admin_post_news_plugin_send_feedback', array($this, 'handle_send_feedback'));
    48         add_action('admin_post_nopriv_news_plugin_update_system_info', array($this, 'handle_update_system_info'));
    49         add_action('admin_post_news_plugin_update_system_info', array($this, 'handle_update_system_info'));
    50 
    51         add_action('admin_init', array($this, 'refresh_plugin_version'));
    52 
    53         register_activation_hook(__FILE__, array($this, 'userSystemCheck_create'));
    54         register_deactivation_hook(__FILE__, array($this, 'userSystemCheck_deactivation'));
     42        add_action('widgets_init', [$this, 'widgets_init']);
     43        add_action('admin_init', [$this, 'admin_init']);
     44        add_action('admin_menu', [$this, 'admin_menu']);
     45        add_action('admin_init', [&$this, 'register_help_section']);
     46        add_action('admin_init', [&$this, 'register_activation_section']);
     47        add_action('admin_init', [&$this, 'register_shortcode_section']);
     48        add_action('admin_init', [&$this, 'register_style_section']);
     49        add_action('admin_init', [&$this, 'register_feed_section']);
     50        add_action('admin_init', [&$this, 'register_status_section']);
     51        add_action('admin_enqueue_scripts', [$this, 'register_admin_scripts']);
     52        add_action('wp_enqueue_scripts', [$this, 'register_styles']);
     53
     54        add_action('admin_post_nopriv_news_plugin_save_style', [$this, 'handle_save_style']);
     55        add_action('admin_post_news_plugin_save_style', [$this, 'handle_save_style']);
     56        add_action('admin_post_nopriv_news_plugin_send_feedback', [$this, 'handle_send_feedback']);
     57        add_action('admin_post_news_plugin_send_feedback', [$this, 'handle_send_feedback']);
     58        add_action('admin_post_nopriv_news_plugin_update_system_info', [$this, 'handle_update_system_info']);
     59        add_action('admin_post_news_plugin_update_system_info', [$this, 'handle_update_system_info']);
     60
     61        add_action('admin_init', [$this, 'refresh_plugin_version']);
     62
     63        register_activation_hook(__FILE__, [$this, 'userSystemCheck_create']);
     64        register_deactivation_hook(__FILE__, [$this, 'userSystemCheck_deactivation']);
    5565        $usc = get_option('newsPlugin_system_info');
    5666        $api_key = get_option('news_plugin_api_key');
     
    5868            !$usc ||
    5969            !isset($usc['info_version']) || ($usc['info_version'] < News_Plugin_Utils::get_system_info_version()) ||
    60             !isset($usc['api_key']) || ($usc['api_key'] != $api_key)
     70            !isset($usc['api_key']) || ($usc['api_key'] !== $api_key)
    6171        ) {
    6272            update_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info());
     
    6474    }
    6575
    66     function userSystemCheck_create()
     76    /**
     77     * Do on user system check creation
     78     *
     79     * @return void
     80     */
     81    public function userSystemCheck_create()
    6782    {
    6883        add_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info());
    6984        add_option('news_plugin_url_method', false);
    7085    }
    71     function userSystemCheck_deactivation()
     86
     87    /**
     88     * Do on system check deactivation
     89     *
     90     * @return void
     91     */
     92    public function userSystemCheck_deactivation()
    7293    {
    7394        delete_option('newsPlugin_system_info');
    7495    }
    7596
    76     function refresh_plugin_version()
     97    /**
     98     * Refresh plugin version
     99     *
     100     * @return void
     101     */
     102    public function refresh_plugin_version()
    77103    {
    78104        if (function_exists('get_plugin_data')) {
     
    86112
    87113    /**
     114     * Load plugin textdomain
     115     *
     116     * @return void
     117     */
     118    public function localize()
     119    {
     120        load_plugin_textdomain('news_plugin', false, basename(dirname(__FILE__)) . '/languages');
     121    }
     122
     123    /**
    88124     * Register the plugin widget, widget areas and widget shorcodes.
    89125     */
    90     function widgets_init()
     126    public function widgets_init()
    91127    {
    92128        register_widget('News_Plugin_Widget');
    93129        for ($area = 1; $area <= 4; $area++) {
    94             register_sidebar(array(
     130            register_sidebar([
    95131                'name' => "NewsPlugin Widget Area {$area}",
    96132                'id' => "newsplugin_widgets_{$area}",
     
    98134                'before_widget' => '<div id="%1$s" class="widget %2$s">',
    99135                'after_widget' => '</div>'
    100             ));
     136            ]);
    101137        }
    102         add_shortcode('newsplugin_widgets', array($this, 'widget_area_shortcode'));
    103         add_shortcode('newsplugin_feed', array($this, 'feed_shortcode'));
     138        add_shortcode('newsplugin_widgets', [$this, 'widget_area_shortcode']);
     139        add_shortcode('newsplugin_feed', [$this, 'feed_shortcode']);
    104140    }
    105141
    106142    /**
    107143     * Process the widget area shortcode.
    108      */
    109     function widget_area_shortcode($attrs)
    110     {
    111         $a = shortcode_atts(array('area' => '1'), $attrs);
     144     *
     145     * @param array $attrs Attributes.
     146     * @return string|false
     147     */
     148    public function widget_area_shortcode($attrs)
     149    {
     150        $a = shortcode_atts(['area' => '1'], $attrs);
    112151        $sidebar = "newsplugin_widgets_{$a['area']}";
    113152        ob_start();
     
    121160
    122161
    123     //[feed_shortcode title="" keywords="News" count="" age="" sources="" excluded_sources="" search_mode="" search_type="" sort_mode="" link_type="" show_date="" show_source="" show_abstract="" feed_mode=""]
     162    // [feed_shortcode title="" keywords="News" count="" age="" sources="" excluded_sources="" search_mode="" search_type="" sort_mode="" link_type="" show_date="" show_source="" show_abstract="" feed_mode=""]
    124163
    125164    /**
    126165     * Process the newsfeed shortcode.
    127      */
    128     function feed_shortcode($attrs)
    129     {
    130         $attrs = shortcode_atts(array(
     166     *
     167     * @param array $attrs Attributes.
     168     * @return string|false
     169     */
     170    public function feed_shortcode($attrs)
     171    {
     172        $attrs = shortcode_atts([
    131173            'id' => '',
    132174            'title' => '',
     
    147189            'feed_mode' => '',
    148190            'wp_uid' => ''
    149         ), $attrs);
     191        ], $attrs);
    150192        $newswid = new News_Plugin_Widget();
    151         $a = $newswid->update($attrs, array());
     193        $a = $newswid->update($attrs, []);
    152194        $a['id'] = $attrs['id'];
    153195        ob_start();
    154         the_widget('News_Plugin_Widget', $a, array());
     196        the_widget('News_Plugin_Widget', $a, []);
    155197        return ob_get_clean();
    156198    }
     
    159201     * Register the plugin CSS style.
    160202     */
    161     function register_styles()
    162     {
    163         wp_register_style('news-plugin', plugin_dir_url(__FILE__) . 'assets/css/news-plugin.css', array(), "0.1");
     203    public function register_styles()
     204    {
     205        wp_register_style('news-plugin', plugin_dir_url(__FILE__) . 'assets/css/news-plugin.css', [], "0.1");
    164206        wp_enqueue_style('news-plugin');
    165207    }
    166208
    167     function register_admin_scripts()
     209    /**
     210     * Register admin scripts
     211     *
     212     * @return void
     213     */
     214    public function register_admin_scripts()
    168215    {
    169216        $assets_path = plugin_dir_url(__FILE__) . 'assets/';
     217        // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
    170218        wp_enqueue_style('news-plugin', $assets_path . 'css/news-plugin.css');
    171         wp_enqueue_script('news-plugin', $assets_path . 'js/jscolor.min.js');
     219        // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion, WordPress.WP.EnqueuedResourceParameters.NoExplicitVersion
     220        wp_enqueue_script('news-plugin', $assets_path . 'js/jscolor.min.js', [], false, true);
    172221    }
    173222
     
    175224     * Register the plugin options.
    176225     */
    177     function admin_init()
     226    public function admin_init()
    178227    {
    179228        add_settings_section(
    180229            'default',
    181             NULL,
    182             NULL,
     230            null,
     231            null,
    183232            'news-plugin-settings'
    184233        );
     
    187236            'news_plugin_api_key',
    188237            __('Activation Key:', 'news_plugin'),
    189             array($this, 'settings_api_key'),
     238            [$this, 'settings_api_key'],
    190239            'news-plugin-settings',
    191240            'default'
     
    194243            'news-plugin-settings',
    195244            'news_plugin_api_key',
    196             array($this, 'validate_api_key')
     245            [$this, 'validate_api_key']
    197246        );
    198247
    199         /* Disable User Mode for now.
    200        add_settings_field(
    201            'news_plugin_user_mode',
    202            __('Choose User Mode:','news_plugin'),
    203            array( $this, 'settings_user_mode' ),
    204            'news-plugin-settings',
    205            'default'
    206        );
    207        register_setting(
    208            'news-plugin-settings',
    209            'news_plugin_user_mode',
    210            array( $this, 'validate_user_mode' )
    211        );
    212        */
     248        /*
     249         Disable User Mode for now.
     250       add_settings_field(
     251           'news_plugin_user_mode',
     252           __('Choose User Mode:','news_plugin'),
     253           array( $this, 'settings_user_mode' ),
     254           'news-plugin-settings',
     255           'default'
     256       );
     257       register_setting(
     258           'news-plugin-settings',
     259           'news_plugin_user_mode',
     260           array( $this, 'validate_user_mode' )
     261       );
     262       */
    213263    }
    214264
     
    216266     * Register the plugin menu.
    217267     */
    218     function admin_menu()
     268    public function admin_menu()
    219269    {
    220270        add_menu_page(
     
    223273            'manage_options',
    224274            'news-plugin-settings',
    225             array($this, 'newsplugin_options_page'),
     275            [$this, 'newsplugin_options_page'],
    226276            'dashicons-megaphone',
    227277            '3'
    228278        );
    229         add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'add_action_links'));
     279        add_filter('plugin_action_links_' . plugin_basename(__FILE__), [$this, 'add_action_links']);
    230280    }
    231281
     
    235285     * when registering settings
    236286     */
    237     private $status_settings_key = 'newsplugin_status_settings';
     287    /**
     288     * Key - $status
     289     *
     290     * @var string
     291     */
     292     private $status_settings_key = 'newsplugin_status_settings';
     293    /**
     294     * Key - feed
     295     *
     296     * @var string
     297     */
    238298    private $feed_settings_key = 'newsplugin_feed_settings';
     299    /**
     300     * Key - style
     301     *
     302     * @var string
     303     */
    239304    private $style_settings_key = 'newsplugin_style_settings';
     305    /**
     306     * Key - activation
     307     *
     308     * @var string
     309     */
    240310    private $activation_settings_key = 'newsplugin_activation_settings';
     311    /**
     312     * Key - shortcode
     313     *
     314     * @var string
     315     */
    241316    private $shortcode_settings_key = 'newsplugin_shortcode_settings';
     317    /**
     318     * Key - help
     319     *
     320     * @var string
     321     */
    242322    private $help_settings_key = 'newsplugin_help_settings';
     323    /**
     324     * Key - key
     325     *
     326     * @var string
     327     */
    243328    private $plugin_options_key = 'news-plugin-settings';
    244     private $plugin_settings_tabs = array();
    245 
    246     /*
    247      * Registering the sections.
    248      */
    249     function register_status_section()
     329    /**
     330     * Key - tabs
     331     *
     332     * @var array
     333     */
     334    private $plugin_settings_tabs = [];
     335
     336    /**
     337     * Registering the sections - status
     338     *
     339     * @return void
     340     */
     341    public function register_status_section()
    250342    {
    251343        $this->plugin_settings_tabs[$this->status_settings_key] = 'Server Information';
    252344    }
    253     function register_feed_section()
     345    /**
     346     * Registering the sections - feed
     347     *
     348     * @return void
     349     */
     350    public function register_feed_section()
    254351    {
    255352        $this->plugin_settings_tabs[$this->feed_settings_key] = 'Send Feedback';
    256353    }
    257     function register_style_section()
     354    /**
     355     * Registering the sections - style
     356     *
     357     * @return void
     358     */
     359    public function register_style_section()
    258360    {
    259361        $this->plugin_settings_tabs[$this->style_settings_key] = 'Customize Styles';
    260362    }
    261     function register_activation_section()
     363    /**
     364     * Registering the sections - activation
     365     *
     366     * @return void
     367     */
     368    public function register_activation_section()
    262369    {
    263370        $this->plugin_settings_tabs[$this->activation_settings_key] = 'Activate NewsPlugin';
    264371    }
    265     function register_shortcode_section()
     372    /**
     373     * Registering the sections - shortcode
     374     *
     375     * @return void
     376     */
     377    public function register_shortcode_section()
    266378    {
    267379        $this->plugin_settings_tabs[$this->shortcode_settings_key] = 'Generate Shortcode';
    268380    }
    269     function register_help_section()
     381    /**
     382     * Registering the sections - help
     383     *
     384     * @return void
     385     */
     386    public function register_help_section()
    270387    {
    271388        $this->plugin_settings_tabs[$this->help_settings_key] = 'Instructions!';
    272389    }
    273390
    274     function get_with_default($arr, $a, $b, $def)
    275     { /* Grrr this should be language construct ... oh. It will be. PHP 7. https://wiki.php.net/rfc/isset_ternary */
     391    /**
     392     * Get value with default
     393     *
     394     * @param array  $arr Array.
     395     * @param string $a First index.
     396     * @param string $b Second index.
     397     * @param mixed  $def Default.
     398     * @return mixed
     399     */
     400    public function get_with_default($arr, $a, $b, $def)
     401    {
     402 /* Grrr this should be language construct ... oh. It will be. PHP 7. https://wiki.php.net/rfc/isset_ternary */
    276403        if (!is_array($arr)) {
    277404            return $def;
     
    286413    }
    287414
    288     /*
     415    /**
    289416     * Plugin Options page rendering goes here, checks
    290417     * for active tab and replaces key with the related
    291418     * settings key. Uses the plugin_options_tabs method
    292419     * to render the tabs.
    293      */
    294     function newsplugin_options_page()
    295     {
    296         $tab = isset($_GET['tab']) ? $_GET['tab'] : $this->help_settings_key;
    297 ?>
     420     *
     421     * @return void
     422     */
     423    public function newsplugin_options_page()
     424    {
     425
     426        // phpcs:ignore WordPress.Security.NonceVerification.Recommended
     427        $tab = isset($_GET['tab']) ? sanitize_title_with_dashes(wp_unslash($_GET['tab'])) : $this->help_settings_key;
     428        ?>
    298429        <div class="wrap">
    299430            <h2>NewsPlugin Settings</h2>
     
    302433            if (empty($key)) { ?>
    303434                <div class="error">
    304                     <p><a href="<?php echo admin_url('admin.php?page=news-plugin-settings&tab=newsplugin_activation_settings'); ?>">Add Activation Key</a> to the NewsPlugin. Otherwise, the generated shortcodes or NewsPlugin widgets will not work!</p>
     435                    <p><a href="<?php echo esc_url(admin_url('admin.php?page=news-plugin-settings&tab=newsplugin_activation_settings')); ?>">Add Activation Key</a> to the NewsPlugin. Otherwise, the generated shortcodes or NewsPlugin widgets will not work!</p>
    305436                </div>
    306437            <?php } ?>
     
    312443                    <?php submit_button(); ?>
    313444                </form>
    314             <?php } else if ($tab === $this->shortcode_settings_key && !empty($key)) { ?>
     445            <?php } elseif ($tab === $this->shortcode_settings_key && !empty($key)) { ?>
    315446                <table id="shortcodeTable" class="form-table">
    316447                    <tr>
     
    546677                            shortcode_params += " age='" + newsplugin_age + "'";
    547678                        }
    548                         shortcode_params += " wp_uid='<?php echo get_current_user_id(); ?>'";
     679                        shortcode_params += " wp_uid='<?php echo esc_attr(get_current_user_id()); ?>'";
    549680                        var html = "<p>Press Ctrl+C to copy to clipboard and paste it in your posts or pages.</p>";
    550681                        html += "<p><textarea id='shortcode-field' onfocus='this.select()' onclick='this.select()' readonly='readonly' style='width:400px; height:200px; max-width:400px; max-height:200px; min-width:400px; min-height:200px;'>[newsplugin_feed id='" + new Date().valueOf() + "'" + shortcode_params + "]</textarea></p>";
     
    555686                    }
    556687                </script>
    557             <?php } else if ($tab === $this->help_settings_key) { ?>
     688            <?php } elseif ($tab === $this->help_settings_key) { ?>
    558689                <h3>Instructions</h3>
    559690                <p>Please read the instructions below carefully to easily setup and use the NewsPlugin.</p>
    560                 <p><strong>1. Enter Activation Key:</strong><br>First of all, enter your Activation Key in the <a href="<?php echo admin_url('admin.php?page=news-plugin-settings&tab=' . $this->activation_settings_key) ?>">Activate</a> tab.</p>
    561                 <p><strong>2. Create Newsfeeds:</strong><br>Create your newsfeed by generating a shortcode from <a href="<?php echo admin_url('admin.php?page=news-plugin-settings&tab=' . $this->shortcode_settings_key) ?>">Generate Shortcode</a> tab. Put that shortcode in posts or pages where you want to display your newsfeed.<br>OR<br>create your newsfeed from <a href="<?php echo admin_url('widgets.php') ?>">Appearance &gt; Widgets</a>. From the widgets panel drag the "NewsPlugin" widget to the desired sidebar or widget area where you want to show your newsfeed. Edit the widget features to create/edit your newsfeed. Choose the name, number of headlines, keywords and other settings.</p>
     691                <p><strong>1. Enter Activation Key:</strong><br>First of all, enter your Activation Key in the <a href="<?php echo esc_url(admin_url('admin.php?page=news-plugin-settings&tab=' . $this->activation_settings_key)); ?>">Activate</a> tab.</p>
     692                <p><strong>2. Create Newsfeeds:</strong><br>Create your newsfeed by generating a shortcode from <a href="<?php echo esc_url(admin_url('admin.php?page=news-plugin-settings&tab=' . $this->shortcode_settings_key)); ?>">Generate Shortcode</a> tab. Put that shortcode in posts or pages where you want to display your newsfeed.<br>OR<br>create your newsfeed from <a href="<?php echo esc_url(admin_url('widgets.php')); ?>">Appearance &gt; Widgets</a>. From the widgets panel drag the "NewsPlugin" widget to the desired sidebar or widget area where you want to show your newsfeed. Edit the widget features to create/edit your newsfeed. Choose the name, number of headlines, keywords and other settings.</p>
    562693                <p><strong>3. Edit Headlines (if you want to):</strong><br>You can remove unwanted headlines or star the good ones right from your site. Note that you must be logged in to WordPress as an administrator or an editor to see the 'Edit Newsfeed Mode' link on your page (next to your newsfeed).</p>
    563694                <h3>Support</h3>
     
    569700                $style_news = get_user_meta($userID, 'news_style_dashbord_style', 'true');
    570701
    571                 $font_family = array();
    572                 $font_family = array("Arial", "Cambria", "Algerian", "Copperplate", "Lucida Console", "Times New Roman", "Impact", "Monaco", "Georgia", "Optima");
    573             ?>
    574                 <h3>Style news plugin widgets created by user <?php echo $user->display_name; ?></h3>
     702                $font_family = [];
     703                $font_family = ["Arial", "Cambria", "Algerian", "Copperplate", "Lucida Console", "Times New Roman", "Impact", "Monaco", "Georgia", "Optima"];
     704                ?>
     705                <h3>Style news plugin widgets created by user <?php echo esc_html($user->display_name); ?></h3>
    575706                <div class="news-row-style">
    576707                    <div class="style_left">
    577708                        <form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
     709                            <?php wp_nonce_field('news_plugin_save_style', 'news_plugin_save_style_field'); ?>
    578710                            <input type="hidden" name="action" value="news_plugin_save_style">
    579711                            <h3>Newsfeed Title</h3>
    580712                            <h4>Color</h4>
    581713                            <?php
    582                             echo '<input class="jscolor" name="title_color" id="title_color" type="text" value="' . $this->get_with_default($style_news, 'newsfeed_title', 'color', '') . '" /><br>';
     714                            echo '<input class="jscolor" name="title_color" id="title_color" type="text" value="' . esc_attr($this->get_with_default($style_news, 'newsfeed_title', 'color', '')) . '" /><br>';
    583715                            echo '<h4>Size</h4>';
    584716                            echo '<select name="title_size" id="title_size">';
    585717                            $v = $this->get_with_default($style_news, 'newsfeed_title', 'size', '');
    586                             echo '<option value="' . $v . '">' . $v . '</option>';
     718                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    587719                            for ($i = 10; $i <= 50; $i++) {
    588                                 if ($i == $v) {
     720                                if ($i === $v) {
    589721                                } else {
    590                                     echo '<option value="' . $i . '">' . $i . '</option>';
     722                                    echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
    591723                                }
    592724                            }
     
    595727                            echo '<select name="title_font" id="title_font">';
    596728                            $v = $this->get_with_default($style_news, 'newsfeed_title', 'font_family', '');
    597                             echo '<option value="' . $v . '">' . $v . '</option>';
     729                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    598730                            if ($v) {
    599731                                echo '<option value="">Unchanged (theme default)</option>';
    600732                            }
    601733                            foreach ($font_family as $fonts) {
    602                                 if ($fonts == $v) {
     734                                if ($fonts === $v) {
    603735                                } else {
    604                                     echo '<option value="' . $fonts . '">' . $fonts . '</option>';
     736                                    echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>';
    605737                                }
    606738                            }
     
    608740                            echo '<h3>Article Headline</h3>';
    609741                            echo '<h4>Color</h4>';
    610                             echo '<input class="jscolor" name="news_title_color" id="news_title_color" type="text" value="' . $this->get_with_default($style_news, 'article_headline', 'color', '') . '" /><br>';
     742                            echo '<input class="jscolor" name="news_title_color" id="news_title_color" type="text" value="' . esc_attr($this->get_with_default($style_news, 'article_headline', 'color', '')) . '" /><br>';
    611743                            echo '<h4>Size</h4>';
    612744                            echo '<select name="news_title_size" id="news_title_size">';
    613745                            $v = $this->get_with_default($style_news, 'article_headline', 'size', '');
    614                             echo '<option value="' . $v . '">' . $v . '</option>';
     746                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    615747                            for ($i = 10; $i <= 50; $i++) {
    616                                 if ($i == $v) {
     748                                if ($i === $v) {
    617749                                } else {
    618                                     echo '<option value="' . $i . '">' . $i . '</option>';
     750                                    echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
    619751                                }
    620752                            }
     
    623755                            echo '<select name="news_title_family" id="news_title_family">';
    624756                            $v = $this->get_with_default($style_news, 'article_headline', 'font_family', '');
    625                             echo '<option value="' . $v . '">' . $v . '</option>';
     757                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    626758                            if ($v) {
    627759                                echo '<option value="">Unchanged (theme default)</option>';
    628760                            }
    629761                            foreach ($font_family as $fonts) {
    630                                 if ($fonts == $v) {
     762                                if ($fonts === $v) {
    631763                                } else {
    632                                     echo '<option value="' . $fonts . '">' . $fonts . '</option>';
     764                                    echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>';
    633765                                }
    634766                            }
     
    636768                            echo '<h3>Article Abstract</h3>';
    637769                            echo '<h4>Color</h4>';
    638                             echo '<input class="jscolor" name="abstract_font_color" id="abstract_font_color" type="text" value="' . $this->get_with_default($style_news, 'article_abstract', 'color', '') . '" /><br>';
     770                            echo '<input class="jscolor" name="abstract_font_color" id="abstract_font_color" type="text" value="' . esc_attr($this->get_with_default($style_news, 'article_abstract', 'color', '')) . '" /><br>';
    639771                            echo '<h4>Size</h4>';
    640772                            echo '<select name="abstract_font_size" id="abstract_font_size">';
    641773                            $v = $this->get_with_default($style_news, 'article_abstract', 'size', '');
    642                             echo '<option value="' . $v . '">' . $v . '</option>';
     774                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    643775                            for ($i = 10; $i <= 50; $i++) {
    644                                 if ($i == $v) {
     776                                if ($i === $v) {
    645777                                } else {
    646                                     echo '<option value="' . $i . '">' . $i . '</option>';
     778                                    echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
    647779                                }
    648780                            }
     
    651783                            echo '<select name="abstract_font_family" id="abstract_font_family">';
    652784                            $v = $this->get_with_default($style_news, 'article_abstract', 'font_family', '');
    653                             echo '<option value="' . $v . '">' . $v . '</option>';
     785                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    654786                            if ($v) {
    655787                                echo '<option value="">Unchanged (theme default)</option>';
    656788                            }
    657789                            foreach ($font_family as $fonts) {
    658                                 if ($fonts == $v) {
     790                                if ($fonts === $v) {
    659791                                } else {
    660                                     echo '<option value="' . $fonts . '">' . $fonts . '</option>';
     792                                    echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>';
    661793                                }
    662794                            }
     
    668800                            echo '<h4>Color</h4>';
    669801
    670                             echo '<input class="jscolor" name="news_date_color" id="news_date_color" type="text" value="' . $this->get_with_default($style_news, 'article_date', 'color', '') . '" /><br>';
     802                            echo '<input class="jscolor" name="news_date_color" id="news_date_color" type="text" value="' . esc_attr($this->get_with_default($style_news, 'article_date', 'color', '')) . '" /><br>';
    671803
    672804                            echo '<h4>Size</h4>';
     
    675807
    676808                            $v = $this->get_with_default($style_news, 'article_date', 'size', '');
    677                             echo '<option value="' . $v . '">' . $v . '</option>';
     809                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    678810
    679811                            for ($i = 10; $i <= 50; $i++) {
    680 
    681                                 if ($i == $v) {
     812                                if ($i === $v) {
    682813                                } else {
    683 
    684                                     echo '<option value="' . $i . '">' . $i . '</option>';
     814                                    echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
    685815                                }
    686816                            }
     
    690820                            echo '<select name="date_font" id="date_font">';
    691821                            $v = $this->get_with_default($style_news, 'article_date', 'font_family', '');
    692                             echo '<option value="' . $v . '">' . $v . '</option>';
     822                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    693823                            if ($v) {
    694824                                echo '<option value="">Unchanged (theme default)</option>';
    695825                            }
    696826                            foreach ($font_family as $fonts) {
    697                                 if ($fonts == $v) {
     827                                if ($fonts === $v) {
    698828                                } else {
    699                                     echo '<option value="' . $fonts . '">' . $fonts . '</option>';
     829                                    echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>';
    700830                                }
    701831                            }
     
    706836                            echo '<h4>Color</h4>';
    707837
    708                             echo '<input class="jscolor" name="source_color" id="source_color" type="text" value="' . $this->get_with_default($style_news, 'article_sources', 'color', '') . '" /><br>';
     838                            echo '<input class="jscolor" name="source_color" id="source_color" type="text" value="' . esc_attr($this->get_with_default($style_news, 'article_sources', 'color', '')) . '" /><br>';
    709839
    710840                            echo '<h4>Size</h4>';
     
    713843
    714844                            $v = $this->get_with_default($style_news, 'article_sources', 'size', '');
    715                             echo '<option value="' . $v . '">' . $v . '</option>';
     845                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    716846
    717847                            for ($i = 10; $i <= 50; $i++) {
    718 
    719                                 if ($i == $v) {
     848                                if ($i === $v) {
    720849                                } else {
    721 
    722                                     echo '<option value="' . $i . '">' . $i . '</option>';
     850                                    echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
    723851                                }
    724852                            }
     
    728856                            echo '<select name="source_font" id="source_font">';
    729857                            $v = $this->get_with_default($style_news, 'article_sources', 'font_family', '');
    730                             echo '<option value="' . $v . '">' . $v . '</option>';
     858                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    731859                            if ($v) {
    732860                                echo '<option value="">Unchanged (theme default)</option>';
    733861                            }
    734862                            foreach ($font_family as $fonts) {
    735                                 if ($fonts == $v) {
     863                                if ($fonts === $v) {
    736864                                } else {
    737                                     echo '<option value="' . $fonts . '">' . $fonts . '</option>';
     865                                    echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>';
    738866                                }
    739867                            }
     
    751879                            ?>
    752880
    753                         <?php } elseif ($tab === $this->feed_settings_key) {
     881            <?php } elseif ($tab === $this->feed_settings_key) {
    754882                        echo '<div class="feeds-row-style">';
    755883                        echo '<div>';
    756                         if (isset($_GET['status'])) {
    757                             if ($_GET['status'] == 1) {
    758                                 echo '<span><h3>Your message has been sent.<br/>Thank you.</h3></span>';
    759                             } else {
    760                                 echo '<span><h3>Error sending message. Please use the form at <a href="https://www.newsplugin.com/contact/">https://www.newsplugin.com/contact/</a>, don' . "'" . 't forget to include the server informations and mention that the plugin feedback page failed.</span></h3>';
    761                             }
    762                         } ?>
     884                // phpcs:ignore WordPress.Security.NonceVerification.Recommended
     885                if (isset($_GET['status'])) {
     886                    // phpcs:ignore WordPress.Security.NonceVerification.Recommended
     887                    if (intval($_GET['status']) === 1) {
     888                        echo '<span><h3>Your message has been sent.<br/>Thank you.</h3></span>';
     889                    } else {
     890                        echo '<span><h3>Error sending message. Please use the form at <a href="https://www.newsplugin.com/contact/">https://www.newsplugin.com/contact/</a>, don' . "'" . 't forget to include the server informations and mention that the plugin feedback page failed.</span></h3>';
     891                    }
     892                } ?>
    763893                    </div>
    764894                    <form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post" id="feed_form">
     895                        <?php wp_nonce_field('news_plugin_send_feedback', 'news_plugin_send_feedback_field'); ?>
    765896                        <input type="hidden" name="action" value="news_plugin_send_feedback">
    766897                        <div class="feed_left">
    767                             <h3>From</h3><?php
    768                                             if ($user_info = News_Plugin_Utils::get_user_info()) {
    769                                                 $email = $user_info->email;
    770                                             } else {
    771                                                 $email = '';
    772                                             }
    773                                             echo '<input class="text notsobig" name="feed_from" id="feed_from" type="email" size="64" value="' . $email . '"/><br>';
     898                            <h3><?php esc_html_e('Email', 'news_plugin'); ?></h3><?php
     899                            $user_info = News_Plugin_Utils::get_user_info();
     900                            if ($user_info) {
     901                                $email = $user_info->email;
     902                            } else {
     903                                $email = '';
     904                            }
     905                                            echo '<input class="text notsobig" name="feed_from" id="feed_from" type="email" size="64" value="' . esc_attr($email) . '"/><br>';
    774906                                            echo '<h3>Subject</h3>';
    775907                                            echo '<input class="text notsobig" name="feed_subject" id="feed_subject" type="text" size="64" /><br>';
    776908                                            echo '<h3>Description</h3>';
    777909                                            echo '<textarea form="feed_form" class="notsobig" name="feed_desc" id="taid" cols="64" rows="10">';
    778                                             /* echo '<div id="sys_status_data">';
    779                 echo '</div>'; */
    780910                                            echo '</textarea><br>';
    781911                                            echo '<p class="submit">';
     
    799929
    800930                                            $results = get_option('newsPlugin_system_info');
    801                                             foreach ($results['wordpress_env'] as $key => $value) {
    802                                                 $key_Name = str_replace('_', ' ', $key);
    803                                                 echo '<tr>
    804                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    805                             <td>' . $value . '</td>
     931                            foreach ($results['wordpress_env'] as $key => $value) {
     932                                $key_Name = str_replace('_', ' ', $key);
     933                                echo '<tr>
     934                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     935                            <td>' . esc_html($value) . '</td>
    806936                        </tr>';
    807                                             }
    808                                             foreach ($results['system_env'] as $key => $value) {
    809                                                 $key_Name = str_replace('_', ' ', $key);
    810                                                 echo '<tr>
    811                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    812                             <td>' . $value . '</td>
     937                            }
     938                            foreach ($results['system_env'] as $key => $value) {
     939                                $key_Name = str_replace('_', ' ', $key);
     940                                echo '<tr>
     941                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     942                            <td>' . esc_html($value) . '</td>
    813943                        </tr>';
    814                                             }
    815                                             foreach ($results['newsplugin_env'] as $key => $value) {
    816                                                 $key_Name = str_replace('_', ' ', $key);
    817                                                 echo '<tr>
    818                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    819                             <td>' . $value . '</td>
     944                            }
     945                            foreach ($results['newsplugin_env'] as $key => $value) {
     946                                $key_Name = str_replace('_', ' ', $key);
     947                                echo '<tr>
     948                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     949                            <td>' . esc_html($value) . '</td>
    820950                        </tr>';
    821                                             }
     951                            }
    822952
    823953                                            echo '</tbody>';
     
    826956                                            echo '<div class="log_div">';
    827957                                            $myfilename = plugin_dir_url(__FILE__) . "logs/plugin-logs.txt";
     958                                            // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
    828959                                            $content = file_exists($myfilename) ? file_get_contents($myfilename) : false;
    829960                                            $v = ($content === false) ? '' : ' checked="checked"';
    830                                             echo '<h2><input type="checkbox" id="errors_div" onclick="showError(this)"' . $v . '/> Include Custom Logs</h2>';
     961                                            echo '<h2><input type="checkbox" id="errors_div" onclick="showError(this)"' . esc_html($v) . '/> Include Custom Logs</h2>';
    831962                                            echo '</div>';
    832963                                            echo '<div class="feed_system_preview" id="error_show_div">';
    833                                             echo '<textarea id="errors_logs" name="noLog_errors" form="feed_form" style="display:none;">"' . $content . '"</textarea>';
    834                                             if ($content !== false) {
    835                                                 echo '<p><strong>"' . $content . '"</strong></p>';
    836                                             }
     964                                            echo '<textarea id="errors_logs" name="noLog_errors" form="feed_form" style="display:none;">"' . esc_html($content) . '"</textarea>';
     965                            if ($content !== false) {
     966                                echo '<p><strong>"' . esc_html($content) . '"</strong></p>';
     967                            }
    837968                                            echo '</div>';
    838969                                            echo '</div>';
     
    840971
    841972                                            echo '</div>';
    842                                             ?>
     973                            ?>
    843974                            <script>
    844975                                function showDiv(box) {
     
    867998                            </script>
    868999
    869                         <?php } elseif ($tab === $this->status_settings_key) { ?>
     1000            <?php } elseif ($tab === $this->status_settings_key) { ?>
    8701001                            <form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
     1002                                <?php wp_nonce_field('news_plugin_update_system_info'); ?>
    8711003                                <input type="hidden" name="action" value="news_plugin_update_system_info">
    8721004                                <p class="submit">
     
    8821014                                        $key_Name = str_replace('_', ' ', $key);
    8831015                                        echo '<tr>
    884                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    885                             <td>' . $value . '</td>
     1016                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     1017                            <td>' . esc_html($value) . '</td>
    8861018                        </tr>';
    8871019                                    }
     
    8901022                                        $key_Name = str_replace('_', ' ', $key);
    8911023                                        echo '<tr>
    892                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    893                             <td>' . $value . '</td>
     1024                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     1025                            <td>' . esc_html($value) . '</td>
    8941026                        </tr>';
    8951027                                    }
     
    8981030                                        $key_Name = str_replace('_', ' ', $key);
    8991031                                        echo '<tr>
    900                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    901                             <td>' . $value . '</td>
     1032                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     1033                            <td>' . esc_html($value) . '</td>
    9021034                        </tr>';
    9031035                                    }
     
    9061038
    9071039                                    ?>
    908                                 <?php } ?>
     1040            <?php } ?>
    9091041                        </div>
    9101042                <?php
    911             }
    912 
    913             /*
     1043    }
     1044
     1045    /**
    9141046     * Renders our tabs in the plugin options page,
    9151047     * walks through the object's tabs array and prints
    9161048     * them one by one. Provides the heading for the
    9171049     * plugin_options_page method.
    918      */
    919             function newsplugin_options_tabs($current_tab)
    920             {
    921                 echo '<h2 class="nav-tab-wrapper">';
    922                 foreach ($this->plugin_settings_tabs as $tab_key => $tab_caption) {
    923                     $active = $current_tab == $tab_key ? 'nav-tab-active' : '';
    924                     echo '<a class="nav-tab ' . $active . '" href="?page=' . $this->plugin_options_key . '&tab=' . $tab_key . '">' . $tab_caption . '</a>';
    925                 }
    926                 echo '</h2>';
    927             }
    928 
    929             /**
    930              * Add link to the options page to the plugin action links.
    931              */
    932             function add_action_links($default_links)
    933             {
    934                 $links = array(
    935                     '<a href="' . admin_url('admin.php?page=news-plugin-settings') . '">Settings</a>',
    936                 );
    937                 return array_merge($links, $default_links);
    938             }
    939 
    940             /**
    941              * Render the API key settings.
    942              */
    943             function settings_api_key()
    944             {
    945                 $v = get_option('news_plugin_api_key');
    946                 echo '<input class="regular-text" name="news_plugin_api_key" id="news_plugin_api_key" type="text" size="64" value="' . esc_attr($v) . '" />';
    947                 echo '<p class="description">';
    948                 echo 'You can get it at <a href="http://my.newsplugin.com/register" target="_blank">http://my.newsplugin.com/register</a>.';
    949                 echo '</p>';
    950             }
    951 
    952             /**
    953              * Validate the API key settings.
    954              */
    955             function validate_api_key($input)
    956             {
    957                 return sanitize_text_field($input);
    958             }
    959 
    960             /**
    961              * Render the user mode settings.
    962              */
    963             function settings_user_mode()
    964             {
    965                 $v = get_option('news_plugin_user_mode');
    966                 echo '<p>';
    967                 echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_0" value="0"', ($v == 0 ? ' checked="checked"' : ''), '>';
    968                 echo '<label for="news_plugin_user_mode_0">Basic - Simple &amp; easy way to start with.</label>';
    969                 echo '<br>';
    970                 echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_1" value="1"', ($v == 1 ? ' checked="checked"' : ''), '>';
    971                 echo '<label for="news_plugin_user_mode_1">Advanced - More features for advanced users.</label>';
    972                 echo '<br>';
    973                 echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_2" value="2"', ($v == 2 ? ' checked="checked"' : ''), '>';
    974                 echo '<label for="news_plugin_user_mode_2">Expert - Manual publishing mode for professionals.</label>';
    975                 echo '</p>';
    976             }
    977 
    978             /**
    979              * Validate the user mode settings.
    980              */
    981             function validate_user_mode($input)
    982             {
    983                 $v = absint($input);
    984                 return ($v < 3 ? $v : 0);
    985             }
    986 
    987             function handle_update_system_info()
    988             {
    989                 update_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info());
    990                 $redirect = admin_url('admin.php') . '?page=news-plugin-settings&tab=newsplugin_status_settings';
    991                 wp_redirect($redirect);
    992             }
    993             function handle_save_style()
    994             {
    995                 include(plugin_dir_path(__FILE__) . 'save_style.php');
    996             }
    997             function handle_send_feedback()
    998             {
    999                 include(plugin_dir_path(__FILE__) . 'send_feedback.php');
    1000             }
     1050     *
     1051     * @param string $current_tab Current tab ID.
     1052     * @return void
     1053     */
     1054    public function newsplugin_options_tabs($current_tab)
     1055    {
     1056        echo '<h2 class="nav-tab-wrapper">';
     1057        foreach ($this->plugin_settings_tabs as $tab_key => $tab_caption) {
     1058            $active = $current_tab === $tab_key ? 'nav-tab-active' : '';
     1059            echo '<a class="nav-tab ' . esc_attr($active) . '" href="?page=' . esc_attr($this->plugin_options_key) . '&tab=' . esc_attr($tab_key) . '">' . esc_html($tab_caption) . '</a>';
    10011060        }
    1002 
    1003         // Hook ourselves into the Wordpress.
     1061        echo '</h2>';
     1062    }
     1063
     1064    /**
     1065     * Add link to the options page to the plugin action links.
     1066     *
     1067     * @param array $default_links Default links.
     1068     * @return array
     1069     */
     1070    public function add_action_links($default_links)
     1071    {
     1072        $links = [
     1073            '<a href="' . admin_url('admin.php?page=news-plugin-settings') . '">Settings</a>',
     1074        ];
     1075        return array_merge($links, $default_links);
     1076    }
     1077
     1078    /**
     1079     * Render the API key settings.
     1080     */
     1081    public function settings_api_key()
     1082    {
     1083        $v = get_option('news_plugin_api_key');
     1084        echo '<input class="regular-text" name="news_plugin_api_key" id="news_plugin_api_key" type="text" size="64" value="' . esc_attr($v) . '" />';
     1085        echo '<p class="description">';
     1086        echo 'You can get it at <a href="http://my.newsplugin.com/register" target="_blank">http://my.newsplugin.com/register</a>.';
     1087        echo '</p>';
     1088    }
     1089
     1090    /**
     1091     * Validate the API key settings.
     1092     *
     1093     * @param string $input API key.
     1094     * @return string
     1095     */
     1096    public function validate_api_key($input)
     1097    {
     1098        return sanitize_text_field($input);
     1099    }
     1100
     1101    /**
     1102     * Render the user mode settings.
     1103     */
     1104    public function settings_user_mode()
     1105    {
     1106        $v = get_option('news_plugin_user_mode');
     1107        echo '<p>';
     1108        echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_0" value="0"', ($v === 0 ? ' checked="checked"' : ''), '>';
     1109        echo '<label for="news_plugin_user_mode_0">Basic - Simple &amp; easy way to start with.</label>';
     1110        echo '<br>';
     1111        echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_1" value="1"', ($v === 1 ? ' checked="checked"' : ''), '>';
     1112        echo '<label for="news_plugin_user_mode_1">Advanced - More features for advanced users.</label>';
     1113        echo '<br>';
     1114        echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_2" value="2"', ($v === 2 ? ' checked="checked"' : ''), '>';
     1115        echo '<label for="news_plugin_user_mode_2">Expert - Manual publishing mode for professionals.</label>';
     1116        echo '</p>';
     1117    }
     1118
     1119    /**
     1120     * Validate the user mode settings.
     1121     *
     1122     * @param int $input User mode ID (?).
     1123     * @return int
     1124     */
     1125    public function validate_user_mode($input)
     1126    {
     1127        $v = absint($input);
     1128        return ($v < 3 ? $v : 0);
     1129    }
     1130
     1131    /**
     1132     * Update stystem info
     1133     *
     1134     * @return void
     1135     */
     1136    public function handle_update_system_info()
     1137    {
     1138        update_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info());
     1139        $redirect = admin_url('admin.php') . '?page=news-plugin-settings&tab=newsplugin_status_settings';
     1140        wp_safe_redirect($redirect);
     1141    }
     1142
     1143    /**
     1144     * Save CSS styles
     1145     *
     1146     * @return void
     1147     */
     1148    public function handle_save_style()
     1149    {
     1150        include(plugin_dir_path(__FILE__) . 'save_style.php');
     1151    }
     1152
     1153    /**
     1154     * Send feedback
     1155     *
     1156     * @return void
     1157     */
     1158    public function handle_send_feedback()
     1159    {
     1160        include(plugin_dir_path(__FILE__) . 'send_feedback.php');
     1161    }
     1162}
     1163
     1164        // Hook ourselves into the WordPress.
    10041165        new News_Plugin();
    10051166
    1006                 ?>
     1167?>
  • newsplugin/tags/1.1.0/readme.txt

    r2492225 r2580769  
    33Tags: news, news plugin, news feed, news feeds, newsfeed, newsfeeds, news syndication
    44Requires at least: 3.9
    5 Tested up to: 5.7
    6 Stable tag: 1.0.18
     5Tested up to: 5.8
     6Stable tag: 1.1.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7373== Changelog ==
    7474
    75 = 1.0.18 (September 18, 2020 )=
     75= 1.1.0 =
     76
     77* Vulnerability fixes:
     78    * All output should be run through an escaping function
     79    * Sanitize content
     80    * Strictly check types
     81    * Process forms with nonces
     82* Improvement: Enable plugin localization & make at least some strings localizable
     83
     84= 1.0.18 (September 18, 2020) =
    7685
    7786* Improvement: Format date & time according to WP settings
  • newsplugin/tags/1.1.0/save_style.php

    r2384451 r2580769  
    11<?php
    2 if (function_exists('wp_get_current_user')) {
    3     $current_user = wp_get_current_user();
    4 } else {
    5     global $current_user;
    6     wp_get_current_user();
     2
     3/**
     4 * Save CSS styles
     5 *
     6 * @package    WordPress
     7 * @subpackage News Plugin
     8 * @since 1.0.0
     9 */
     10
     11// Verify nonce.
     12$nonce = isset($_POST['news_plugin_save_style_field']) ? sanitize_key($_POST['news_plugin_save_style_field']) : null;
     13if (! $nonce || ! wp_verify_nonce($nonce, 'news_plugin_save_style')) {
     14    die(esc_html__('4 - Security check failed. Try to submit the form once again.', 'news_plugin'));
    715}
    8 $userID = $current_user->ID;
    916
    10 $default_Value = $_POST['default_values_style'];
    11 $styleDash = array(
    12     'newsfeed_title' => array(
    13         'color'         =>  $_POST['title_color'],
    14         'size'          =>  $_POST['title_size'],
    15         'font_family'   =>  $_POST['title_font']
    16     ),
    17     'article_headline' => array(
    18         'color'         =>  $_POST['news_title_color'],
    19         'size'          =>  $_POST['news_title_size'],
    20         'font_family'   =>  $_POST['news_title_family']
    21     ),
    22     'article_abstract' => array(
    23         'color'         =>  $_POST['abstract_font_color'],
    24         'size'          =>  $_POST['abstract_font_size'],
    25         'font_family'   =>  $_POST['abstract_font_family']
    26     ),
    27     'article_date' => array(
    28         'color'         =>  $_POST['news_date_color'],
    29         'size'          =>  $_POST['news_date_size'],
    30         'font_family'   =>  $_POST['date_font']
    31     ),
    32     'article_sources' => array(
    33         'color'         =>  $_POST['source_color'],
    34         'size'          =>  $_POST['source_size'],
    35         'font_family'   =>  $_POST['source_font']
    36     )
    37 );
     17$user = wp_get_current_user();
     18$userID = $user->ID;
     19$default_Value = isset($_POST['default_values_style']) ? sanitize_key(wp_unslash($_POST['default_values_style'])) : null;
     20$styleDash = [
     21 'newsfeed_title' => [
     22      'color'         =>  isset($_POST['title_color']) ? sanitize_key(wp_unslash($_POST['title_color'])) : null,
     23     'size'          =>  isset($_POST['title_size']) ? sanitize_key(wp_unslash($_POST['title_size'])) : null,
     24      'font_family'   =>  isset($_POST['title_font']) ? sanitize_key(wp_unslash($_POST['title_font'])) : null
     25  ],
     26 'article_headline' => [
     27        'color'         =>  isset($_POST['news_title_color']) ? sanitize_key(wp_unslash($_POST['news_title_color'])) : null,
     28        'size'          =>  isset($_POST['news_title_size']) ? sanitize_key(wp_unslash($_POST['news_title_size'])) : null,
     29     'font_family'   =>  isset($_POST['news_title_family']) ? sanitize_key(wp_unslash($_POST['news_title_family'])) : null
     30 ],
     31 'article_abstract' => [
     32        'color'         =>  isset($_POST['abstract_font_color']) ? sanitize_key(wp_unslash($_POST['abstract_font_color'])) : null,
     33     'size'          =>  isset($_POST['abstract_font_size']) ? sanitize_key(wp_unslash($_POST['abstract_font_size'])) : null,
     34      'font_family'   =>  isset($_POST['abstract_font_family']) ? sanitize_key(wp_unslash($_POST['abstract_font_family'])) : null,
     35 ],
     36 'article_date' => [
     37        'color'         =>  isset($_POST['news_date_color']) ? sanitize_key(wp_unslash($_POST['news_date_color'])) : null,
     38     'size'          =>  isset($_POST['news_date_size']) ? sanitize_key(wp_unslash($_POST['news_date_size'])) : null,
     39      'font_family'   =>  isset($_POST['date_font']) ? sanitize_key(wp_unslash($_POST['date_font'])) : null,
     40 ],
     41 'article_sources' => [
     42     'color'         =>  isset($_POST['source_color']) ? sanitize_key(wp_unslash($_POST['source_color'])) : null,
     43        'size'          =>  isset($_POST['source_size']) ? sanitize_key(wp_unslash($_POST['source_size'])) : null,
     44     'font_family'   =>  isset($_POST['source_font']) ? sanitize_key(wp_unslash($_POST['source_font'])) : null,
     45 ]
     46];
     47
    3848if (isset($default_Value)) {
    39     $default_values = array(
    40         'newsfeed_title' => array(
    41             'color'         =>  '000000',
    42             'size'          =>  22,
    43             'font_family'   =>  'Times New Roman'
    44         ),
    45         'article_headline' => array(
    46             'color'         =>  '000000',
    47             'size'          =>  18,
    48             'font_family'   =>  'Times New Roman'
    49         ),
    50         'article_abstract' => array(
    51             'color'         =>  '000000',
    52             'size'          =>  14,
    53             'font_family'   =>  'Times New Roman'
    54         ),
    55         'article_date' => array(
    56             'color'         =>  '000000',
    57             'size'          =>  12,
    58             'font_family'   =>  'Times New Roman'
    59         ),
    60         'article_sources' => array(
    61             'color'         =>  '000000',
    62             'size'          =>  12,
    63             'font_family'   =>  'Times New Roman'
    64         )
    65     );
     49    $default_values = [
     50        'newsfeed_title' => [
     51            'color'         =>  '000000',
     52            'size'          =>  22,
     53    'font_family'   =>  'Times New Roman'
     54        ],
     55        'article_headline' => [
     56            'color'         =>  '000000',
     57            'size'          =>  18,
     58            'font_family'   =>  'Times New Roman'
     59        ],
     60        'article_abstract' => [
     61            'color'         =>  '000000',
     62            'size'          =>  14,
     63            'font_family'   =>  'Times New Roman'
     64        ],
     65        'article_date' => [
     66            'color'         =>  '000000',
     67            'size'          =>  12,
     68            'font_family'   =>  'Times New Roman'
     69        ],
     70        'article_sources' => [
     71            'color'         =>  '000000',
     72            'size'          =>  12,
     73            'font_family'   =>  'Times New Roman'
     74        ]
     75    ];
    6676    update_user_meta($userID, 'news_style_dashbord_style', $default_values);
    6777} else {
     
    7080
    7181$redirect = admin_url('admin.php') . '?page=news-plugin-settings&tab=newsplugin_style_settings';
    72 wp_redirect($redirect);
     82wp_safe_redirect($redirect);
     83exit();
  • newsplugin/tags/1.1.0/send_feedback.php

    r2384451 r2580769  
    11<?php
    2 $to         = '[email protected]';
    3 $from           = $_POST['feed_from'];
    4 $subject        = $_POST['feed_subject'];
    5 $description        = $_POST['feed_desc'];
    6 $errors_logs        = isset($_POST['errors_logs']) ? $_POST['errors_logs'] : false;
    7 $insert_sys_info    = isset($_POST['insert_sys_info']) ? $_POST['insert_sys_info'] : false;
     2
     3/**
     4 * Send Feedback
     5 *
     6 * @package    WordPress
     7 * @subpackage News Plugin
     8 * @since 1.0.0
     9 */
     10
     11// Verify nonce.
     12$nonce = isset($_POST['news_plugin_send_feedback_field']) ? sanitize_key($_POST['news_plugin_send_feedback_field']) : null;
     13if (!$nonce || !wp_verify_nonce($nonce, 'news_plugin_send_feedback')) {
     14    die(esc_html__('5 - Security check failed. Try to submit the form once again.', 'news_plugin'));
     15}
     16
     17$to         = '[email protected]';
     18$from           = isset($_POST['feed_from']) ? sanitize_text_field(wp_unslash($_POST['feed_from'])) : '';
     19$subject        = isset($_POST['feed_subject']) ? sanitize_text_field(wp_unslash($_POST['feed_subject'])) : '';
     20$description        = isset($_POST['feed_desc']) ? sanitize_text_field(wp_unslash($_POST['feed_desc'])) : '';
     21$errors_logs        = isset($_POST['errors_logs']) ? sanitize_text_field(wp_unslash($_POST['errors_logs'])) : false;
     22$insert_sys_info    = isset($_POST['insert_sys_info']) ? sanitize_text_field(wp_unslash($_POST['insert_sys_info'])) : false;
    823
    924if (!$from) {
    10     if ($user_info = News_Plugin_Utils::get_user_info()) {
     25    $user_info = News_Plugin_Utils::get_user_info();
     26    if ($user_info) {
    1127        $from = $user_info->email;
    1228    }
     
    2339
    2440if (isset($errors_logs)) {
    25 
    2641    $message .= "<tr style='background: #eee;'><strong>Errors on plugin :</strong></tr>\n";
    2742    $message .= '<tr><p>' . $errors_logs . '</p></tr>' . "\n";
    2843}
    2944
    30 // if(isset($insert_sys_info)) {
    31 
    32 // $results = get_option( 'newsPlugin_system_info' );
    33 $results = News_Plugin_Utils::get_system_info(); // Always get fresh
    34 $message .= "<tr style='background: #eee;'><td cellspan='2'><strong>WORDPRESS ENVIRONMENT :</strong></td></tr>\n";
     45$results = News_Plugin_Utils::get_system_info(); // Always get fresh.
     46$message .= "<tr style='background: #eee;'><td cellspan='2'><strong>WordPress ENVIRONMENT :</strong></td></tr>\n";
    3547foreach ($results['wordpress_env'] as $key => $value) {
    36 
    3748    $key_Name = str_replace('_', ' ', $key);
    3849    $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n";
     
    4051$message .= "<tr style='background: #eee;'><td cellspan='2'><strong>SYSTEM ENVIRONMENT :</strong></td></tr>\n";
    4152foreach ($results['system_env'] as $key => $value) {
    42 
    4353    $key_Name = str_replace('_', ' ', $key);
    4454    $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n";
     
    4656$message .= "<tr style='background: #eee;'><td cellspan='2'><strong>NEWSPLUGIN ENVIRONMENT :</strong></td></tr>\n";
    4757foreach ($results['newsplugin_env'] as $key => $value) {
    48 
    4958    $key_Name = str_replace('_', ' ', $key);
    5059    $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n";
    5160}
    52 // }
    5361
    5462$message .= '</tbody>';
     
    5664$message .= "</body></html>";
    5765
     66/**
     67 * Set content type helper
     68 *
     69 * @return string
     70 */
    5871function news_plugin_wp_set_content_type()
    5972{
     
    6174}
    6275add_filter('wp_mail_content_type', 'news_plugin_wp_set_content_type');
     76
    6377$headers .= news_plugin_wp_set_content_type();
    6478
     
    7185
    7286remove_filter('wp_mail_content_type', 'news_plugin_wp_set_content_type');
    73 wp_redirect($redirect);
     87wp_safe_redirect($redirect);
     88exit();
  • newsplugin/trunk/news-plugin-utils.php

    r2384451 r2580769  
    11<?php
     2
     3/**
     4 * Utils
     5 *
     6 * @package    WordPress
     7 * @subpackage News Plugin
     8 * @since 1.0.0
     9 */
    210
    311// Prevent ourselves from being run directly.
     
    513
    614if (!function_exists('json_last_error_msg')) {
     15
     16    /**
     17     * Get error message
     18     *
     19     * @return string
     20     */
    721    function json_last_error_msg()
    822    {
    9         static $ERRORS = array(
     23        static $ERRORS = [
    1024            JSON_ERROR_NONE => 'No error',
    1125            JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
     
    1428            JSON_ERROR_SYNTAX => 'Syntax error',
    1529            JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
    16         );
     30        ];
    1731
    1832        $error = json_last_error();
     
    2135}
    2236
     37/**
     38 * Utils
     39 *
     40 * @package News Plugin
     41 */
    2342class News_Plugin_Utils
    24 { // Although maybe namespace would suffice
    25 
    26     static $np_version = NULL;
    27 
    28     static function np_version()
     43{
     44
     45    /**
     46     * Plugin version
     47     *
     48     * @var mixed
     49     */
     50    public static $np_version = null;
     51
     52    /**
     53     * Get plugin version
     54     *
     55     * @return mixed
     56     */
     57    public static function np_version()
    2958    {
    3059        if (self::$np_version) {
    3160            return (self::$np_version);
    3261        }
     62        // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
    3363        if (self::$np_version = get_option('news_plugin_version')) {
    3464            return (self::$np_version);
     
    3767    }
    3868
    39     static function np_version_hard()
     69    /**
     70     * Get plugin version from plugin file
     71     *
     72     * @return mixed
     73     */
     74    public static function np_version_hard()
    4075    {
    4176        if (!function_exists('get_plugin_data')) {
     
    4984    }
    5085
    51     static function user_agent($type)
     86    /**
     87     * Create a plugin specific user agent
     88     *
     89     * @param string $type Type of the user agent.
     90     * @return string
     91     */
     92    public static function user_agent($type)
    5293    {
    5394        global $wp_version;
     
    5697    }
    5798
    58     static function http_remote_get_curl($url)
     99    /**
     100     * CURL request
     101     *
     102     * TODO: replace with WP function
     103     *
     104     * @param string $url Request URL.
     105     * @return string[]|(string|bool)[]
     106     */
     107    public static function http_remote_get_curl($url)
    59108    {
    60109        if (!function_exists('curl_version')) {
    61             return (array('', 'Error: CURL disabled or not installed'));
     110            return (['', 'Error: CURL disabled or not installed']);
    62111        }
    63112        if (!function_exists('curl_init') || !function_exists('curl_exec')) {
    64             return (array('', 'Error: CURL disabled by security settings'));
     113            return (['', 'Error: CURL disabled by security settings']);
    65114        }
    66115        $ch = curl_init($url);
     
    75124        }
    76125        curl_close($ch);
    77         return array($output, $error);
    78     }
    79 
    80     static function http_remote_get_socket($url)
     126        return [$output, $error];
     127    }
     128
     129    /**
     130     * Get socket request
     131     *
     132     * @param string $url Request URL.
     133     * @return string[]
     134     */
     135    public static function http_remote_get_socket($url)
    81136    {
    82137        if (!function_exists('stream_socket_client')) {
    83             return (array('', 'Error: Socket disabled'));
     138            return (['', 'Error: Socket disabled']);
    84139        }
    85140        $aURL = parse_url($url);
    86141        $addr = $aURL['host'];
    87         $secure_transport = ($aURL['scheme'] == 'ssl' || $aURL['scheme'] == 'https');
     142        $secure_transport = ($aURL['scheme'] === 'ssl' || $aURL['scheme'] === 'https');
    88143        if (!isset($aURL['port'])) {
    89144            if ($secure_transport) {
     
    100155        $socket = stream_socket_client($proto . $addr . ':' . $aURL['port'], $errno, $errorMessage, 10, STREAM_CLIENT_CONNECT);
    101156        if ($socket === false) {
    102             return (array('', 'Socket error: ' . $errorMessage));
     157            return (['', 'Socket error: ' . $errorMessage]);
    103158        }
    104159        $url = $aURL['path'];
     
    113168        fclose($socket);
    114169        if (preg_match('/^(.*?)\r?\n\r?\n(.*)$/s', $output, $m)) {
    115             return (array($m[2], ''));
    116         }
    117         return (array($output, ''));
    118     }
    119 
    120     static function http_test_evaluate($ret)
     170            return ([$m[2], '']);
     171        }
     172        return ([$output, '']);
     173    }
     174
     175    /**
     176     * Test content checker
     177     * TODO - move to proper testing suit
     178     *
     179     * @param mixed $ret Retrieved content.
     180     * @return mixed
     181     */
     182    public static function http_test_evaluate($ret)
    121183    {
    122184        if ((!$ret[1]) && (!preg_match('/var swfobject=function()/s', $ret[0]))) {
     
    127189    }
    128190
    129     static $test_url = 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
    130 
    131     static function http_remote_get_curl_test()
     191    /**
     192     * Test URL
     193     *
     194     * @var string
     195     */
     196    public static $test_url = 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
     197
     198    /**
     199     * Test Curl funcion
     200     * TODO - move to proper testing suit
     201     *
     202     * @return mixed
     203     */
     204    public static function http_remote_get_curl_test()
    132205    {
    133206        $ret = self::http_remote_get_curl(self::$test_url);
     
    135208    }
    136209
    137     static function http_remote_get_socket_test()
     210    /**
     211     * Test Get Socket
     212     * TODO - move to proper testing suit
     213     *
     214     * @return mixed
     215     */
     216    public static function http_remote_get_socket_test()
    138217    {
    139218        $ret = self::http_remote_get_socket(self::$test_url);
     
    141220    }
    142221
    143     static $test_url_ssl = 'https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
    144 
    145     static function http_remote_get_curl_test_ssl()
     222    /**
     223     * Test URL for SSL
     224     *
     225     * @var string
     226     */
     227    public static $test_url_ssl = 'https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
     228
     229    /**
     230     * Test Curl with SSL
     231     * TODO - move to proper testing suit
     232     *
     233     * @return mixed
     234     */
     235    public static function http_remote_get_curl_test_ssl()
    146236    {
    147237        $ret = self::http_remote_get_curl(self::$test_url_ssl);
     
    149239    }
    150240
    151     static function http_remote_get_socket_test_ssl()
     241    /**
     242     * Test Get Socket with SSL
     243     * TODO - move to proper testing suit
     244     *
     245     * @return mixed
     246     */
     247    public static function http_remote_get_socket_test_ssl()
    152248    {
    153249        $ret = self::http_remote_get_socket(self::$test_url_ssl);
     
    155251    }
    156252
    157     static $api_root = 'http://api.newsplugin.com/';
    158     static $api_ping_path = 'ping';
    159 
    160     static function http_ping_evaluate($var)
     253    /**
     254     * API root
     255     *
     256     * @var string
     257     */
     258    public static $api_root = 'http://api.newsplugin.com/';
     259
     260    /**
     261     * API ping PATH
     262     *
     263     * @var string
     264     */
     265    public static $api_ping_path = 'ping';
     266
     267    /**
     268     * Evaluate HTTP ping
     269     *
     270     * @param mixed $var Variable.
     271     * @return mixed
     272     */
     273    public static function http_ping_evaluate($var)
    161274    {
    162275        $output = $var[0];
     
    174287    }
    175288
    176     static function http_remote_get_curl_ping()
     289    /**
     290     * CURL ping
     291     *
     292     * @return mixed
     293     */
     294    public static function http_remote_get_curl_ping()
    177295    {
    178296        $var = self::http_remote_get_curl(self::$api_root . self::$api_ping_path);
     
    180298    }
    181299
    182     static function http_remote_get_socket_ping()
     300    /**
     301     * Get Socket ping
     302     *
     303     * @return mixed
     304     */
     305    public static function http_remote_get_socket_ping()
    183306    {
    184307        $var = self::http_remote_get_socket(self::$api_root . self::$api_ping_path);
     
    186309    }
    187310
    188     static function generic_remote_get($url, $method)
     311    /**
     312     * Remote GET request
     313     *
     314     * @param string $url Request URL.
     315     * @param string $method Method type.
     316     * @return mixed
     317     */
     318    public static function generic_remote_get($url, $method)
    189319    {
    190320        switch ($method) {
    191321            case 'wp':
    192                 $ret = wp_remote_get($url, array('timeout' => 10, 'user-agent' => self::user_agent('wp')));
     322                $ret = wp_remote_get($url, ['timeout' => 10, 'user-agent' => self::user_agent('wp')]);
    193323                if (is_array($ret)) {
    194                     return (array($ret['body'], ''));
     324                    return ([$ret['body'], '']);
    195325                }
    196326                $ret = self::generic_remote_get($url, 'curl');
     
    209339    }
    210340
    211     static function generic_api_call($path, $args = NULL)
     341    /**
     342     * Call API
     343     *
     344     * @param string     $path Path withing the URL.
     345     * @param mixed|null $args Arguments.
     346     * @return mixed
     347     */
     348    public static function generic_api_call($path, $args = null)
    212349    {
    213350        $key = get_option('news_plugin_api_key');
    214         $args = $args ? $args : array();
     351        $args = $args ? $args : [];
    215352        $args['k'] = $key;
    216353        $url = self::$api_root . $path;
     
    219356        $ret = self::generic_remote_get($url, $method ? $method : 'wp');
    220357        if ($ret[1]) {
    221             $currentTime = date('y-m-d h:i:s', time());
     358            $currentTime = gmdate('y-m-d h:i:s', time());
     359            // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.Changed, WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
    222360            $backtrace = debug_backtrace();
     361            // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
    223362            error_log("$currentTime  -->   " . "Error accessing API point " . self::$api_root . "$path: " . $ret[1] . "  Log Generation Details :      Filename: " . $backtrace[0]['file'] . "   at Line number : " . $backtrace[0]['line'] . "\n\n", 3, __DIR__ . "/logs/plugin-logs.txt");
    224             return (NULL);
     363            return (null);
    225364        }
    226365        return (json_decode($ret[0]));
    227366    }
    228367
    229     static function get_user_info()
     368    /**
     369     * Get user info
     370     *
     371     * @return mixed
     372     */
     373    public static function get_user_info()
    230374    {
    231375        return (self::generic_api_call('user_info'));
    232376    }
    233377
    234     static function get_system_info_version()
     378    /**
     379     * Get system info version
     380     * TODO: What a magic constant it is?
     381     */
     382    public static function get_system_info_version()
    235383    {
    236384        return (1.0002);
    237385    }
    238386
    239     static function get_system_db_info()
    240     {
    241         global $wpdb; /* Recommended by https://codex.wordpress.org/Class_Reference/wpdb */
     387    /**
     388     * Get System DB info
     389     *
     390     * @return array
     391     */
     392    public static function get_system_db_info()
     393    {
     394        global $wpdb;
    242395
    243396        if (!empty($wpdb->use_mysqli)) {
    244             /* See also http://fw2s.com/how-to-get-complete-mysql-version-in-wordpress/
    245                Note: use_mysqli is private and dbh is protected, BUT wpdb class is allowing
    246                to access then through getters and setters anyway. Backward compatibility.
    247              */
    248             return (array(
     397            /*
     398             See also http://fw2s.com/how-to-get-complete-mysql-version-in-wordpress/
     399               Note: use_mysqli is private and dbh is protected, BUT wpdb class is allowing
     400               to access then through getters and setters anyway. Backward compatibility.
     401             */
     402            return ([
    249403                'mysql_method'          => 'mysqli',
    250404                'mysql_server_info'     => mysqli_get_server_info($wpdb->dbh),
    251405                'mysql_client_info'     => mysqli_get_client_info($wpdb->dbh),
    252406                'mysql_proto_info'      => mysqli_get_proto_info($wpdb->dbh),
    253             ));
     407            ]);
    254408        } else {
    255             return (array(
     409            return ([
    256410                'mysql_method'          => 'mysql',
     411                // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
    257412                'mysql_server_info'     => mysql_get_server_info(),
     413                // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
    258414                'mysql_client_info'     => mysql_get_client_info(),
     415                // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
    259416                'mysql_proto_info'      => mysql_get_proto_info(),
    260             ));
    261         }
    262     }
    263 
    264     static function get_system_info()
     417            ]);
     418        }
     419    }
     420
     421    /**
     422     * Get system info
     423     *
     424     * @return array
     425     */
     426    public static function get_system_info()
    265427    {
    266428        $my_theme = wp_get_theme();
     
    285447        $db_info = self::get_system_db_info();
    286448
    287         $system_info = array(
     449        $system_info = [
    288450            'info_version' => self::get_system_info_version(),
    289451            'api_key'      => get_option('news_plugin_api_key'), /* We need to refresh on api key change ... */
    290             'wordpress_env' => array(
     452            'wordpress_env' => [
    291453                'siteurl'               => get_bloginfo('url'),
    292454                'version'               => get_bloginfo('version'),
     
    296458                'theme_version'         => $my_theme->get('Version'),
    297459                'theme_AuthorURI'       => $my_theme->get('AuthorURI'),
    298             ),
    299             'system_env' => array(
     460            ],
     461            'system_env' => [
    300462                'php_version'           => phpversion(),
    301                 'SERVER_SOFTWARE'       => $_SERVER['SERVER_SOFTWARE'],
     463                'SERVER_SOFTWARE'       => isset($_SERVER['SERVER_SOFTWARE']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : null,
    302464                'SERVER_OS'             => PHP_OS,
    303                 'SERVER_IP_ADDRESS'     => $_SERVER['SERVER_ADDR'],
    304                 'HTTP_HOST'             => $_SERVER['HTTP_HOST'],
    305                 'SERVER_NAME'           => $_SERVER['SERVER_NAME'],
    306                 'HTTP_USER_AGENT'       => $_SERVER['HTTP_USER_AGENT'],
    307                 'HTTP_ACCEPT'           => $_SERVER['HTTP_ACCEPT'],
     465                'SERVER_IP_ADDRESS'     => isset($_SERVER['SERVER_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_ADDR'])) : null,
     466                'HTTP_HOST'             => isset($_SERVER['HTTP_HOST']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST'])) : null,
     467                'SERVER_NAME'           => isset($_SERVER['SERVER_NAME']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'])) : null,
     468                'HTTP_USER_AGENT'       => isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])) : null,
     469                'HTTP_ACCEPT'           => isset($_SERVER['HTTP_ACCEPT']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_ACCEPT'])) : null,
    308470                'memory_limit'          => ini_get('memory_limit'),
    309471                'execution_time'        => ini_get('max_execution_time'),
     
    320482                'socket_status'         => $socket_test[1] ? $socket_test[1] : 'OK',
    321483                'socket_status_ssl'     => $socket_test_ssl[1] ? $socket_test_ssl[1] : 'OK',
    322             ),
    323             'newsplugin_env' => array(
     484            ],
     485            'newsplugin_env' => [
    324486                'REGISTERED EMAIL'      => $user_info ? $user_info->email : 'error or unregistered',
    325487                'USER STATUS'           => $user_info ? $user_info->status : 'error or unregistered',
     
    327489                'curl_ping'             => $curl_ping[1] ? $curl_ping[1] : ('OK from ' . $curl_ping[0]->client),
    328490                'socket_ping'           => $socket_ping[1] ? $socket_ping[1] : ('OK from ' . $socket_ping[0]->client),
    329             )
    330         );
    331         if ($curl_test[1] == $curl_test_ssl[1]) {
     491            ]
     492        ];
     493        if ($curl_test[1] === $curl_test_ssl[1]) {
    332494            unset($system_info['system_env']['curl_status_ssl']);
    333495        }
    334         if ($socket_test[1] == $socket_test_ssl[1]) {
     496        if ($socket_test[1] === $socket_test_ssl[1]) {
    335497            unset($system_info['system_env']['socket_status_ssl']);
    336498        }
  • newsplugin/trunk/news-plugin-widget.php

    r2384451 r2580769  
    11<?php
     2
     3/**
     4 * Widget
     5 *
     6 * @package    WordPress
     7 * @subpackage News Plugin
     8 * @since 1.0.0
     9 */
    210
    311// Prevent ourselves from being run directly.
     
    1321     * Register widget with WordPress.
    1422     */
    15     function __construct()
     23    public function __construct()
    1624    {
    1725        parent::__construct(
    1826            'news_plugin_widget',
    1927            __('NewsPlugin', 'news_plugin'),
    20             array('description' => __('Create custom newsfeeds and let fresh relevant news appear on your website (or approve and publish them manually).', 'news_plugin'),)
     28            ['description' => __('Create custom newsfeeds and let fresh relevant news appear on your website (or approve and publish them manually).', 'news_plugin'),]
    2129        );
    2230    }
     
    4048    private function current_options()
    4149    {
    42         $opts = get_option('news_plugin_widget_options', array());
    43         $opts = (isset($opts[$this->widget_id()])) ? $opts[$this->widget_id()] : array();
     50        $opts = get_option('news_plugin_widget_options', []);
     51        $opts = (isset($opts[$this->widget_id()])) ? $opts[$this->widget_id()] : [];
    4452        return $opts;
    4553    }
     
    4755    /**
    4856     * Update the private options specific for this widget.
     57     *
     58     * @param mixed $args Arguments.
     59     * @return mixed
    4960     */
    5061    private function update_options($args)
    5162    {
    52         $opts = get_option('news_plugin_widget_options', array());
     63        $opts = get_option('news_plugin_widget_options', []);
    5364        $opts[$this->widget_id()] = $args;
    5465        update_option('news_plugin_widget_options', $opts);
     
    6273    {
    6374        $opts = $this->current_options();
    64         $posts = (isset($opts['excluded'])) ? $opts['excluded'] : array();
     75        $posts = (isset($opts['excluded'])) ? $opts['excluded'] : [];
    6576        return $posts;
    6677    }
     
    6879    /**
    6980     * Add given id to the list of excluded posts.
     81     *
     82     * @param int $id ID.
     83     * @param int $limit Limit.
     84     * @return array
    7085     */
    7186    private function exclude_post($id, $limit = 100)
     
    86101    {
    87102        $opts = $this->current_options();
    88         $posts = array();
     103        $posts = [];
    89104        $opts['excluded'] = $posts;
    90105        $this->update_options($opts);
     
    98113    {
    99114        $opts = $this->current_options();
    100         $posts = (isset($opts['favorite'])) ? $opts['favorite'] : array();
     115        $posts = (isset($opts['favorite'])) ? $opts['favorite'] : [];
    101116        return $posts;
    102117    }
     
    104119    /**
    105120     * Add given id to the list of favorite posts.
     121     *
     122     * @param int $id ID.
     123     * @param int $limit Limit.
     124     * @return array
    106125     */
    107126    private function star_favorite_post($id, $limit = 100)
     
    118137    /**
    119138     * Remove given id from the list of favorite posts.
     139     *
     140     * @param int $id ID.
     141     * @return mixed
    120142     */
    121143    private function unstar_favorite_post($id)
     
    123145        $opts = $this->current_options();
    124146        $posts = $this->favorite_posts();
    125         $posts = array_diff($posts, array($id));
     147        $posts = array_diff($posts, [$id]);
    126148        $opts['favorite'] = $posts;
    127149        $this->update_options($opts);
     
    135157    {
    136158        $opts = $this->current_options();
    137         $posts = array();
     159        $posts = [];
    138160        $opts['favorite'] = $posts;
    139161        $this->update_options($opts);
     
    152174    /**
    153175     * Set the timestamp of the last publishing in manual publishing mode.
     176     *
     177     * @param int $time Timestamp.
     178     * @return mixed
    154179     */
    155180    private function update_publish_time($time)
     
    163188    /**
    164189     * Prepare the args for URL managing posts of this widget.
     190     *
     191     * @param string $action Action name.
     192     * @param int    $arg Number of arguments.
     193     * @return array
    165194     */
    166195    private function create_action_args($action, $arg = 0)
    167196    {
    168         return array(
     197        return [
    169198            'news_plugin_instance' => $this->widget_id(),
    170199            'news_plugin_action' => $action,
    171200            'news_plugin_arg' => $arg,
    172         );
     201            '_wpnonce' => wp_create_nonce('news_plugin_url_nonce'),
     202        ];
    173203    }
    174204
     
    178208    private function parse_action_args()
    179209    {
    180         if ((!isset($_GET['news_plugin_instance'])) || ($_GET['news_plugin_instance'] != $this->widget_id())) {
    181             return array();
    182         }
    183         return array(
    184             'action' => isset($_GET['news_plugin_action']) ? $_GET['news_plugin_action'] : '',
    185             'arg' => isset($_GET['news_plugin_arg']) ? $_GET['news_plugin_arg'] : '',
    186         );
     210        // Verify nonce.
     211        $nonce = isset($_GET['news_plugin_url_nonce']) ? sanitize_key($_GET['news_plugin_url_nonce']) : null;
     212        if ($nonce && !wp_verify_nonce($nonce) && $_GET['news_plugin_instance']) {
     213            die(esc_html__('1 - Security check failed. Try to submit the form once again.', 'news_plugin'));
     214        }
     215
     216        if ((!isset($_GET['news_plugin_instance'])) || ($_GET['news_plugin_instance'] !== $this->widget_id())) {
     217            return [];
     218        }
     219        return [
     220            'action' => isset($_GET['news_plugin_action']) ? sanitize_key(wp_unslash($_GET['news_plugin_action'])) : '',
     221            'arg' => isset($_GET['news_plugin_arg']) ? sanitize_key(wp_unslash($_GET['news_plugin_arg'])) : '',
     222        ];
    187223    }
    188224
     
    220256    private function edit_mode_enabled()
    221257    {
     258        // Verify nonce.
     259        $nonce = isset($_GET['news_plugin_url_nonce']) ? sanitize_key($_GET['news_plugin_url_nonce']) : null;
     260        if ($nonce && !wp_verify_nonce($nonce) && isset($_GET['news_plugin_action']) ) {
     261            die(esc_html__('2 - Security check failed. Try to submit the form once again.', 'news_plugin'));
     262        }
     263
    222264        if (isset($_GET['news_plugin_action'])) {
    223             $action = $_GET['news_plugin_action'];
     265            $action = sanitize_key(wp_unslash($_GET['news_plugin_action']));
    224266            return !empty($action);
    225267        }
     
    228270    /**
    229271     * Manage the feed as necessary.
     272     *
     273     * @param mixed $opts Options.
     274     * @return void
    230275     */
    231276    private function manage($opts)
    232277    {
    233278        switch ($this->current_action()) {
    234             case 'exclude': {
    235                     $id = sanitize_key($this->current_arg());
    236                     $limit = max(100, 2 * $opts['count']);
    237                     $this->exclude_post($id, $limit);
    238                     break;
    239                 }
    240             case 'star': {
    241                     $id = sanitize_key($this->current_arg());
    242                     $limit = max(100, 2 * $opts['count']);
    243                     $this->star_favorite_post($id, $limit);
    244                     break;
    245                 }
    246             case 'unstar': {
    247                     $id = sanitize_key($this->current_arg());
    248                     $this->unstar_favorite_post($id);
    249                     break;
    250                 }
    251             case 'reset': {
    252                     $this->reset_excluded_posts();
    253                     $this->reset_favorite_posts();
    254                     break;
    255                 }
    256             case 'publish': {
    257                     $time = min(time(), absint($this->current_arg()));
    258                     $this->update_publish_time($time);
    259                     break;
    260                 }
     279            case 'exclude':
     280                $id = sanitize_key($this->current_arg());
     281                $limit = max(100, 2 * $opts['count']);
     282                $this->exclude_post($id, $limit);
     283                break;
     284            case 'star':
     285                $id = sanitize_key($this->current_arg());
     286                $limit = max(100, 2 * $opts['count']);
     287                $this->star_favorite_post($id, $limit);
     288                break;
     289            case 'unstar':
     290                $id = sanitize_key($this->current_arg());
     291                $this->unstar_favorite_post($id);
     292                break;
     293            case 'reset':
     294                $this->reset_excluded_posts();
     295                $this->reset_favorite_posts();
     296                break;
     297            case 'publish':
     298                $time = min(time(), absint($this->current_arg()));
     299                $this->update_publish_time($time);
     300                break;
    261301        }
    262302    }
     
    264304    /**
    265305     * Silly helper for returning caching duration for fetch_feed().
    266      */
    267     function get_feed_caching_duration($seconds)
     306     *
     307     * @return int
     308     */
     309    public function get_feed_caching_duration()
    268310    {
    269311        return 3600;
     
    272314    /**
    273315     * Get our data feed.
     316     *
     317     * @param int   $time Time.
     318     * @param mixed $opts Options.
     319     * @param int   $limit Limit.
     320     * @return SimplePie|WP_Error|null
    274321     */
    275322    private function get_feed($time, $opts, $limit = 100)
     
    277324        $key = get_option('news_plugin_api_key');
    278325
    279         $args = array(
     326        $args = [
    280327            'k' => $key,
    281328            'q' => $opts['keywords'],
     
    283330            'c' => $opts['count'],
    284331            't' => $opts['title']
    285             // o offset
    286             // a after
    287             // b before
    288         );
    289 
    290         if ($opts['feed_mode'] == 'manual') {
     332            // o offset.
     333            // a after.
     334            // b before.
     335        ];
     336
     337        if ($opts['feed_mode'] === 'manual') {
    291338            if (!($this->can_manage() && $this->edit_mode_enabled())) {
    292339                $time = $this->publish_time();
     
    328375
    329376        // Talk about stupid API. Like if the cache duration couldn't be a simple parameter.
    330         $cache_filter = array($this, 'get_feed_caching_duration');
     377        $cache_filter = [$this, 'get_feed_caching_duration'];
    331378        add_filter('wp_feed_cache_transient_lifetime', $cache_filter);
    332379        $feed = fetch_feed($url);
    333380        remove_filter('wp_feed_cache_transient_lifetime', $cache_filter);
    334381
    335         return (is_wp_error($feed) ? NULL : $feed);
    336     }
    337 
     382        return (is_wp_error($feed) ? null : $feed);
     383    }
     384
     385    /**
     386     * CSS style helpers
     387     *
     388     * @param mixed $style Style.
     389     * @param mixed $type Type.
     390     * @return string
     391     */
    338392    private function compute_style_helper($style, $type)
    339393    {
     
    343397        $ret = '';
    344398        if ($style[$type]['size']) {
    345             $ret .= 'font-size: ' . $style[$type]['size'] . 'px;';
     399            $ret .= 'font-size:' . $style[$type]['size'] . 'px;';
    346400        }
    347401        if ($style[$type]['color']) {
     
    351405            $ret .= 'font-family:' . $style[$type]['font_family'] . ';';
    352406        }
    353         if (!$ret) {
    354             return ($ret);
    355         }
    356         return (' style="' . $ret . '"');
     407        if ($ret) {
     408            return ' style=' . $ret ;
     409        }
    357410    }
    358411
     
    370423
    371424        if (!isset($rss)) {
    372             _e('Feed fetch failed ', 'news_plugin');
     425            esc_html_e('Feed fetch failed ', 'news_plugin');
    373426            return;
    374427        }
    375428
    376         $manual_mode = ($opts['feed_mode'] == 'manual');
     429        $manual_mode = ($opts['feed_mode'] === 'manual');
    377430
    378431        $exclude = array_fill_keys($this->excluded_posts(), true);
     
    393446                $args = $this->create_action_args('reset');
    394447                echo '<a href="' . esc_attr(add_query_arg($args)) . '">';
    395                 echo 'Reset';
     448                esc_html_e('Reset', 'news_plugin');
    396449                echo '</a>';
    397450
     
    400453                    echo ' | ';
    401454                    echo '<a href="' . esc_attr(add_query_arg($args)) . '">';
    402                     echo 'Publish Headlines';
     455                    esc_html_e('Publish Headlines', 'news_plugin');
    403456                    echo '</a>';
    404457                }
    405458
    406                 $args = $this->create_action_args(NULL, NULL);
     459                $args = $this->create_action_args(null, null);
    407460                echo ' | ';
    408461                echo '<a href="' . esc_attr(add_query_arg($args)) . '">';
    409                 echo 'Leave Edit Newsfeed Mode';
     462                esc_html_e('Leave Edit Newsfeed Mode', 'news_plugin');
    410463                echo '</a>';
    411464
     
    415468                echo '<p class="news-plugin-edit-buttons">';
    416469                echo '<a href="' . esc_attr(add_query_arg($args)) . '">';
    417                 echo 'Edit Newsfeed Mode';
     470                esc_html_e('Edit Newsfeed Mode', 'news_plugin');
    418471                echo '</a>';
    419472            }
     
    421474            if ($manual_mode) {
    422475                $t = $this->publish_time();
    423                 if ($t == 0) {
     476                if ($t === 0) {
    424477                    if ($this->edit_mode_enabled()) {
    425478                        echo '<p>';
    426                         echo 'No headlines published yet.';
     479                        esc_html_e('No headlines published yet.', 'news_plugin');
    427480                        echo '</p>';
    428481                    } else {
    429482                        echo '<p>';
    430                         echo 'No headlines published yet. Use the Edit Newsfeed Mode to edit and publish your feed.';
     483                        esc_html_e('No headlines published yet. Use the Edit Newsfeed Mode to edit and publish your feed.', 'news_plugin');
    431484                        echo '</p>';
    432485                    }
    433486                } else {
    434                     $t = date('d M Y H:i', $t);
     487                    // TODO localize properly.
     488                    $t = gmdate('d M Y H:i', $t);
    435489                    echo '<p>';
    436                     echo "Headlines last published on {$t}.";
     490                    // TODO localize properly.
     491                    echo esc_html("Headlines last published on {$t}.");
    437492                    echo '</p>';
    438493                }
     
    442497                if ($manual_mode) {
    443498                    echo '<p>';
    444                     echo "Once published, only the first {$limit} headline" . ($limit == 1 ? '' : 's') . " will be displayed in your feed.";
     499                    // TODO localize properly.
     500                    echo esc_html("Once published, only the first {$limit} headline" . ($limit === 1 ? '' : 's') . " will be displayed in your feed.");
     501                    // TODO localize properly.
    445502                    echo ' You can <span style="font-size:110%;">&#9734;</span>&nbsp;Star individual headlines to move them to the top or &#10005;&nbsp;Remove them from the feed. Click Reset to undo these changes.';
    446                     echo ' Don’t forget to Publish Headlines when you are done.';
     503                    esc_html_e(' Don’t forget to Publish Headlines when you are done.', 'news_plugin');
    447504                    echo '</p>';
    448505                } else {
    449506                    echo '<p>';
     507                    // TODO localize properly.
    450508                    echo 'You can <span style="font-size:110%;">&#9734;</span>&nbsp;Star individual headlines to move them to the top or &#10005;&nbsp;Remove them from the feed. Click Reset to undo these changes.';
    451509                    echo '</p>';
     
    460518        $index = 0;
    461519
    462         if ($opts['wp_uid'] && (intval($opts['wp_uid']) != 0)) {
     520        if ($opts['wp_uid'] && (intval($opts['wp_uid']) !== 0)) {
    463521            $userID = intval($opts['wp_uid']);
    464522        } else {
     
    479537                }
    480538
    481                 if (!empty($favorite[$id]) xor ($pass == 0)) {
     539                if (!empty($favorite[$id]) xor ($pass === 0)) {
    482540                    continue;
    483541                }
    484542
    485                 if ($index == $limit) {
     543                if ($index === $limit) {
    486544                    echo '<hr>';
    487545                }
    488546
    489547                echo '<li>';
    490                 if ($opts['link_follow'] == 'no') {
     548                if ($opts['link_follow'] === 'no') {
    491549                    $s_follow = ' rel="nofollow"';
    492550                } else {
     
    498556                    $s_target = '';
    499557                }
    500                 echo '<a href="' . esc_attr($item->get_permalink()) . '"' . $s_target . $s_follow . '>';
     558                echo '<a href="' . esc_url($item->get_permalink()) . '"' . esc_attr($s_target) . esc_attr($s_follow) . '>';
    501559                $style = $this->compute_style_helper($style_news, 'article_headline');
    502                 echo '<span class="news-plugin-title"' . $style . '>';
     560                echo '<span class="news-plugin-title"' . esc_attr($style) . '>';
    503561                echo esc_html($item->get_title());
    504562                echo '</span>';
     
    507565                    echo "\n";
    508566                    $style = $this->compute_style_helper($style_news, 'article_date');
    509                     echo '<span class="news-plugin-date"' . $style . '>';
     567                    echo '<span class="news-plugin-date"' . esc_attr($style) . '>';
    510568                    echo esc_html($item->get_date(get_option('date_format') . ' ' . get_option('time_format')));
    511569                    echo '</span>';
     
    513571                if ($opts['show_source']) {
    514572                    // Because RSS doesn't support the source field, we use the author field.
    515                     // $source = $item->get_source() ;
    516573                    $source = $item->get_author();
    517                     if ($source) $source = $source->get_email();
     574                    if ($source) {
     575                        $source = $source->get_email();
     576                    }
    518577                    if (!empty($source)) {
    519578                        echo "\n";
    520579                        $style = $this->compute_style_helper($style_news, 'article_sources');
    521                         echo '<span class="news-plugin-source"' . $style . '>';
     580                        echo '<span class="news-plugin-source"' . esc_attr($style) . '>';
    522581                        echo esc_html($source);
    523582                        echo '</span>';
     
    527586                    echo "\n";
    528587                    $style = $this->compute_style_helper($style_news, 'article_abstract');
    529                     echo '<span class="news-plugin-abstract"' . $style . '>';
     588                    echo '<span class="news-plugin-abstract"' . esc_attr($style) . '>';
    530589                    echo esc_html($item->get_description());
    531590                    echo '</span>';
     
    535594                    $args = $this->create_action_args('exclude', $id);
    536595                    echo ' &nbsp; <a href="' . esc_attr(add_query_arg($args)) . '">';
    537                     // echo 'X' ;
    538596                    echo '<span style="text-decoration: underline;">';
    539597                    echo '&#10005;&nbsp;Remove';
     
    543601                        $args = $this->create_action_args('unstar', $id);
    544602                        echo ' <a href="' . esc_attr(add_query_arg($args)) . '">';
    545                         // echo '-' ;
    546603                        echo '<span style="text-decoration: underline;">';
    547604                        echo '<span style="font-size:110%;">&#9733;</span>&nbsp;Unstar';
     
    551608                        $args = $this->create_action_args('star', $id);
    552609                        echo ' <a href="' . esc_attr(add_query_arg($args)) . '">';
    553                         // echo '+' ;
    554610                        echo '<span style="text-decoration: underline;">';
    555611                        echo '<span style="font-size:110%;">&#9734;</span>&nbsp;Star';
     
    565621        }
    566622        echo '</ul>';
    567 
    568         //Error in Option Page
    569         // newserroforwp_log("NewsPlugin Option Page");
    570623    }
    571624
     
    589642        if (empty($key)) {
    590643            if ($this->can_manage()) {
    591 ?>
     644                ?>
    592645                <p>
    593                     Your feed is currently inactive.
    594                     Please enter your Activation Key on the
    595                     <a href="<?php echo admin_url('admin.php?page=news-plugin-settings') ?>">NewsPlugin Settings</a>
    596                     page first.
     646                    <?php esc_html_e('Your feed is currently inactive.', 'news_plugin'); ?>
     647                    <?php esc_html_e('Please enter your Activation Key on the', 'news_plugin'); ?>
     648                    <a href="<?php echo esc_url(admin_url('admin.php?page=news-plugin-settings')) ?>"><?php esc_html_e('NewsPlugin Settings', 'news_plugin'); ?></a>
     649                    <?php esc_html_e('page first', 'news_plugin'); ?>.
    597650                </p>
    598             <?php
     651                <?php
    599652            }
    600653            return;
     
    607660        $title = apply_filters('widget_title', $opts['title']);
    608661
    609         echo $args['before_widget'];
    610         if (!empty($title))
    611             echo $args['before_title'] . $title . $args['after_title'];
     662        echo wp_kses_post($args['before_widget']);
     663        if (!empty($title)) {
     664            echo wp_kses_post($args['before_title'] . $title . $args['after_title']);
     665        }
    612666        $this->content($opts);
    613         echo $args['after_widget'];
     667        echo wp_kses_post($args['after_widget']);
    614668    }
    615669
     
    627681            ?>
    628682            <p>
    629                 Please enter your Activation Key on the
    630                 <a href="<?php echo admin_url('admin.php?page=news-plugin-settings') ?>">NewsPlugin Settings</a>
    631                 page first.
     683                <?php esc_html_e('Please enter your Activation Key on the', 'news_plugin'); ?>
     684                <a href="<?php echo esc_url(admin_url('admin.php?page=news-plugin-settings')); ?>"><?php esc_html_e('NewsPlugin Settings', 'news_plugin'); ?></a>
     685                <?php esc_html_e('page first.', 'news_plugin'); ?>
    632686            </p>
    633         <?php
     687            <?php
    634688            return;
    635689        }
     
    726780
    727781        // Force expert user mode for now.
    728         // $user_mode = get_option( 'news_plugin_user_mode' ) ;
     782        // $user_mode = get_option( 'news_plugin_user_mode' ); .
    729783        $user_mode = 2;
    730784
    731785        ?>
    732786        <p>
    733             <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Newsfeed Name:'); ?></label>
    734             <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>">
     787            <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Newsfeed Name:', 'news_plugin'); ?></label>
     788            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>">
    735789            <br>
    736             <small>Give your feed a good name.</small>
     790            <small><?php esc_html_e('Give your feed a good name.', 'news_plugin'); ?></small>
    737791            <br>
    738             <small>Example: Canada Solar Energy News</small>
     792            <small><?php esc_html_e('Example: Canada Solar Energy News', 'news_plugin'); ?></small>
    739793        </p>
    740794        <p>
    741             <label for="<?php echo $this->get_field_id('keywords'); ?>"><?php _e('Keywords:'); ?></label>
    742             <input class="widefat" id="<?php echo $this->get_field_id('keywords'); ?>" name="<?php echo $this->get_field_name('keywords'); ?>" type="text" value="<?php echo esc_attr($keywords); ?>">
     795            <label for="<?php echo esc_attr($this->get_field_id('keywords')); ?>"><?php esc_html_e('Keywords:', 'news_plugin'); ?></label>
     796            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('keywords')); ?>" name="<?php echo esc_attr($this->get_field_name('keywords')); ?>" type="text" value="<?php echo esc_attr($keywords); ?>">
    743797            <br>
    744             <small>Use keywords to find relevant news.</small>
     798            <small><?php esc_html_e('Use keywords to find relevant news.', 'news_plugin'); ?></small>
    745799            <br>
    746             <small>Example: canada &amp; "solar energy"</small>
     800            <small><?php esc_html_e('Example: canada &amp; "solar energy"', 'news_plugin'); ?></small>
    747801            <br>
    748             <small>Read the <a href="http://newsplugin.com/faq#keyword-tips" target="_blank">FAQ</a> for more keywords tips and examples.</small>
     802            <small><?php printf(esc_html__('Read the %S for more keywords tips and examples.', 'news_plugin'), '<a href="http://newsplugin.com/faq#keyword-tips" target="_blank">' . esc_html__('FAQ', 'news_plugin') . '</a'); ?></small>
    749803        </p>
    750804        <p>
    751             <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Number of Articles:'); ?></label>
    752             <input class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo $count; ?>">
     805            <label for="<?php echo esc_attr($this->get_field_id('count')); ?>"><?php esc_html_e('Number of Articles:', 'news_plugin'); ?></label>
     806            <input class="widefat" id="<?php echo esc_attr($this->get_field_id('count')); ?>" name="<?php echo esc_attr($this->get_field_name('count')); ?>" type="text" value="<?php echo esc_attr($count); ?>">
    753807            <br>
    754             <small>Set how many headlines to show in your feed.</small>
     808            <small><?php esc_html_e('Set how many headlines to show in your feed.', 'news_plugin'); ?></small>
    755809            <br>
    756             <small>Example: 10</small>
     810            <small><?php esc_html_e('Example: 10', 'news_plugin'); ?></small>
    757811        </p>
    758812        <p>
    759             <input id="<?php echo $this->get_field_id('show_date'); ?>" name="<?php echo $this->get_field_name('show_date'); ?>" type="checkbox" <?php if ($show_date) echo 'checked="checked"' ?>>
    760             <label for="<?php echo $this->get_field_id('show_date'); ?>"><?php _e('Show Dates'); ?></label>
     813            <input id="<?php echo esc_attr($this->get_field_id('show_date')); ?>" name="<?php echo esc_attr($this->get_field_name('show_date')); ?>" type="checkbox" <?php if ($show_date) {
     814                echo 'checked="checked"';
     815                       } ?>>
     816            <label for="<?php echo esc_attr($this->get_field_id('show_date')); ?>"><?php esc_html_e('Show Dates', 'news_plugin'); ?></label>
    761817        </p>
    762818        <p>
    763             <input id="<?php echo $this->get_field_id('show_source'); ?>" name="<?php echo $this->get_field_name('show_source'); ?>" type="checkbox" <?php if ($show_source) echo 'checked="checked"' ?>>
    764             <label for="<?php echo $this->get_field_id('show_source'); ?>"><?php _e('Show Sources'); ?></label>
     819            <input id="<?php echo esc_attr($this->get_field_id('show_source')); ?>" name="<?php echo esc_attr($this->get_field_name('show_source')); ?>" type="checkbox" <?php if ($show_source) {
     820                echo 'checked="checked"';
     821                       } ?>>
     822            <label for="<?php echo esc_attr($this->get_field_id('show_source')); ?>"><?php esc_html_e('Show Sources', 'news_plugin'); ?></label>
    765823        </p>
    766824        <p>
    767             <input id="<?php echo $this->get_field_id('show_abstract'); ?>" name="<?php echo $this->get_field_name('show_abstract'); ?>" type="checkbox" <?php if ($show_abstract) echo 'checked="checked"' ?>>
    768             <label for="<?php echo $this->get_field_id('show_abstract'); ?>"><?php _e('Show Abstracts'); ?></label>
     825            <input id="<?php echo esc_attr($this->get_field_id('show_abstract')); ?>" name="<?php echo esc_attr($this->get_field_name('show_abstract')); ?>" type="checkbox" <?php if ($show_abstract) {
     826                echo 'checked="checked"';
     827                       } ?>>
     828            <label for="<?php echo esc_attr($this->get_field_id('show_abstract')); ?>"><?php esc_html_e('Show Abstracts', 'news_plugin'); ?></label>
    769829            <br>
    770             <small>By default, your feed displays headlines only. You can add more information.</small>
     830            <small><?php esc_html_e('By default, your feed displays headlines only. You can add more information.', 'news_plugin'); ?></small>
    771831            <br>
    772             <small>Example: New Reports on Canada Solar Energy, 12 Feb 2015 (BBC)</small>
     832            <small><?php esc_html_e('Example: New Reports on Canada Solar Energy, 12 Feb 2015 (BBC)', 'news_plugin'); ?></small>
    773833        </p>
    774834        <?php
    775835        if ($user_mode > 0) {
    776 
    777836            /*
    778         <p>
    779         <label for="<?php echo $this->get_field_id( 'sources' ); ?>"><?php _e( 'Sources:' ); ?></label>
    780         <input class="widefat" id="<?php echo $this->get_field_id( 'sources' ); ?>" name="<?php echo $this->get_field_name( 'sources' ); ?>" type="text" value="<?php echo esc_attr( $sources ) ; ?>">
    781         <br>
    782         <small>Show news from only selected sources. Leave blank for all sources.</small>
    783         <br>
    784         <small>Example: BBC</small>
    785         </p>
    786         <p>
    787         <label for="<?php echo $this->get_field_id( 'excluded_sources' ); ?>"><?php _e( 'Excluded Sources:' ); ?></label>
    788         <input class="widefat" id="<?php echo $this->get_field_id( 'excluded_sources' ); ?>" name="<?php echo $this->get_field_name( 'excluded_sources' ); ?>" type="text" value="<?php echo esc_attr( $excluded_sources ) ; ?>">
    789         <br>
    790         <small>Don’t show news from selected sources.</small>
    791         <br>
    792         <small>Example: BBC</small>
    793         </p>
    794         */
    795 
    796         ?>
     837        <p>
     838        <label for="<?php echo $this->get_field_id( 'sources' ); ?>"><?php _e( 'Sources:' ); ?></label>
     839        <input class="widefat" id="<?php echo $this->get_field_id( 'sources' ); ?>" name="<?php echo $this->get_field_name( 'sources' ); ?>" type="text" value="<?php echo esc_attr( $sources ) ; ?>">
     840        <br>
     841        <small>Show news from only selected sources. Leave blank for all sources.</small>
     842        <br>
     843        <small>Example: BBC</small>
     844        </p>
     845        <p>
     846        <label for="<?php echo $this->get_field_id( 'excluded_sources' ); ?>"><?php _e( 'Excluded Sources:' ); ?></label>
     847        <input class="widefat" id="<?php echo $this->get_field_id( 'excluded_sources' ); ?>" name="<?php echo $this->get_field_name( 'excluded_sources' ); ?>" type="text" value="<?php echo esc_attr( $excluded_sources ) ; ?>">
     848        <br>
     849        <small>Don’t show news from selected sources.</small>
     850        <br>
     851        <small>Example: BBC</small>
     852        </p>
     853        */
     854
     855            ?>
    797856            <p>
    798                 <label for="<?php echo $this->get_field_id('search_mode'); ?>"><?php _e('Search Mode:'); ?></label>
    799                 <select class="widefat" id="<?php echo $this->get_field_id('search_mode'); ?>" name="<?php echo $this->get_field_name('search_mode'); ?>">
    800                     <option value="">Default</option>
    801                     <option value="title" <?php if ($search_mode == "title") echo 'selected="selected"' ?>>Headlines Only</option>
    802                     <option value="text" <?php if ($search_mode == "text") echo 'selected="selected"' ?>>Headlines &amp; Full Text</option>
     857                <label for="<?php echo esc_attr($this->get_field_id('search_mode')); ?>"><?php esc_html_e('Search Mode:', 'news_plugin'); ?></label>
     858                <select class="widefat" id="<?php echo esc_attr($this->get_field_id('search_mode')); ?>" name="<?php echo esc_attr($this->get_field_name('search_mode')); ?>">
     859                    <option value=""><?php esc_html_e('Default', 'news_plugin'); ?></option>
     860                    <option value="title" <?php if ($search_mode === "title") {
     861                        echo 'selected="selected"';
     862                                          } ?>><?php esc_html_e('Headlines Only', 'news_plugin'); ?></option>
     863                    <option value="text" <?php if ($search_mode === "text") {
     864                        echo 'selected="selected"';
     865                                         } ?>><?php esc_html_e('Headlines &amp; Full Text', 'news_plugin'); ?></option>
    803866                </select>
    804867                <br>
    805                 <small>Show news that has your keywords in a headline or anywhere in an article. Default is headlines and full text.</small>
     868                <small><?php esc_html_e('Show news that has your keywords in a headline or anywhere in an article. Default is headlines and full text.', 'news_plugin'); ?></small>
    806869            </p>
    807870
    808871            <?php
    809872            /*
    810         <p>
    811         <label for="<?php echo $this->get_field_id( 'search_type' ); ?>"><?php _e( 'Search Type:' ); ?></label>
    812         <select class="widefat" id="<?php echo $this->get_field_id( 'search_type' ); ?>" name="<?php echo $this->get_field_name( 'search_type' ); ?>">
    813         <option value="">Default</option>
    814         <option value="news" <?php if ( $search_type == "news" ) echo 'selected="selected"' ?>>News</option>
    815         <option value="pr" <?php if ( $search_type == "pr" ) echo 'selected="selected"' ?>>Press Releases</option>
    816         <option value="event"<?php if ( $search_type == "event" ) echo 'selected="selected"' ?>>Events</option>
    817         </select>
    818         <br>
    819         <small>Show only selected types of news. Default is a combination of all types.</small>
    820         </p>
    821         */
     873        <p>
     874        <label for="<?php echo $this->get_field_id( 'search_type' ); ?>"><?php _e( 'Search Type:' ); ?></label>
     875        <select class="widefat" id="<?php echo $this->get_field_id( 'search_type' ); ?>" name="<?php echo $this->get_field_name( 'search_type' ); ?>">
     876        <option value="">Default</option>
     877        <option value="news" <?php if ( $search_type == "news" ) echo 'selected="selected"' ?>>News</option>
     878        <option value="pr" <?php if ( $search_type == "pr" ) echo 'selected="selected"' ?>>Press Releases</option>
     879        <option value="event"<?php if ( $search_type == "event" ) echo 'selected="selected"' ?>>Events</option>
     880        </select>
     881        <br>
     882        <small>Show only selected types of news. Default is a combination of all types.</small>
     883        </p>
     884        */
    822885            ?>
    823886
    824887            <p>
    825                 <label for="<?php echo $this->get_field_id('sort_mode'); ?>"><?php _e('Sort Mode:'); ?></label>
    826                 <select class="widefat" id="<?php echo $this->get_field_id('sort_mode'); ?>" name="<?php echo $this->get_field_name('sort_mode'); ?>">
    827                     <option value="">Default</option>
    828                     <option value="relevance" <?php if ($sort_mode == "relevance") echo 'selected="selected"' ?>>Relevance</option>
    829                     <option value="date" <?php if ($sort_mode == "date") echo 'selected="selected"' ?>>Date</option>
     888                <label for="<?php echo esc_attr($this->get_field_id('sort_mode')); ?>"><?php esc_html_e('Sort Mode:', 'news_plugin'); ?></label>
     889                <select class="widefat" id="<?php echo esc_attr($this->get_field_id('sort_mode')); ?>" name="<?php echo esc_attr($this->get_field_name('sort_mode')); ?>">
     890                    <option value=""><?php esc_html_e('Default', 'news_plugin'); ?></option>
     891                    <option value="relevance" <?php if ($sort_mode === "relevance") {
     892                        echo 'selected="selected"';
     893                                              } ?>><?php esc_html_e('Relevance', 'news_plugin'); ?></option>
     894                    <option value="date" <?php if ($sort_mode === "date") {
     895                        echo 'selected="selected"';
     896                                         } ?>><?php esc_html_e('Date', 'news_plugin'); ?></option>
    830897                </select>
    831898                <br>
    832                 <small>Show headlines sorted by date or relevance. Default is by relevance.</small>
     899                <small><?php esc_html_e('Show headlines sorted by date or relevance. Default is by relevance.', 'news_plugin'); ?></small>
    833900            </p>
    834901            <p>
    835                 <label for="<?php echo $this->get_field_id('age'); ?>"><?php _e('News Age Limit (in hours):'); ?></label>
    836                 <input class="widefat" id="<?php echo $this->get_field_id('age'); ?>" name="<?php echo $this->get_field_name('age'); ?>" type="text" value="<?php echo $age; ?>">
     902                <label for="<?php echo esc_attr($this->get_field_id('age')); ?>"><?php esc_html_e('News Age Limit (in hours):', 'news_plugin'); ?></label>
     903                <input class="widefat" id="<?php echo esc_attr($this->get_field_id('age')); ?>" name="<?php echo esc_attr($this->get_field_name('age')); ?>" type="text" value="<?php echo esc_attr($age); ?>">
    837904                <br>
    838                 <small>Don’t show articles older than given period. 0 means no limit.</small>
     905                <small><?php esc_html_e('Don’t show articles older than given period. 0 means no limit.', 'news_plugin'); ?></small>
    839906            </p>
    840907            <p>
    841                 <label for="<?php echo $this->get_field_id('link_open_mode'); ?>"><?php _e('Link mode:'); ?></label>
    842                 <select class="widefat" id="<?php echo $this->get_field_id('link_open_mode'); ?>" name="<?php echo $this->get_field_name('link_open_mode'); ?>">
    843                     <option value="">Default</option>
    844                     <option value="_self" <?php if ($link_open_mode == "_self") echo 'selected="selected"' ?>>Same Window</option>
    845                     <option value="_blank" <?php if ($link_open_mode == "_blank") echo 'selected="selected"' ?>>New Tab</option>
     908                <label for="<?php echo esc_attr($this->get_field_id('link_open_mode')); ?>"><?php esc_html_e('Link mode:', 'news_plugin'); ?></label>
     909                <select class="widefat" id="<?php echo esc_attr($this->get_field_id('link_open_mode')); ?>" name="<?php echo esc_attr($this->get_field_name('link_open_mode')); ?>">
     910                    <option value=""><?php esc_html_e('Default', 'news_plugin'); ?></option>
     911                    <option value="_self" <?php if ($link_open_mode === "_self") {
     912                        echo 'selected="selected"';
     913                                          } ?>><?php esc_html_e('Same Window', 'news_plugin'); ?></option>
     914                    <option value="_blank" <?php if ($link_open_mode === "_blank") {
     915                        echo 'selected="selected"';
     916                                           } ?>><?php esc_html_e('New Tab', 'news_plugin'); ?></option>
    846917                </select>
    847                 <label for="<?php echo $this->get_field_id('link_follow'); ?>"><?php _e('Follow mode:'); ?></label>
    848                 <select class="widefat" id="<?php echo $this->get_field_id('link_follow'); ?>" name="<?php echo $this->get_field_name('link_follow'); ?>">
    849                     <option value="">Default</option>
    850                     <option value="yes" <?php if ($link_follow == "yes") echo 'selected="selected"' ?>>Follow</option>
    851                     <option value="no" <?php if ($link_follow == "no") echo 'selected="selected"' ?>>Nofollow</option>
     918                <label for="<?php echo esc_attr($this->get_field_id('link_follow')); ?>"><?php esc_html_e('Follow mode:', 'news_plugin'); ?></label>
     919                <select class="widefat" id="<?php echo esc_attr($this->get_field_id('link_follow')); ?>" name="<?php echo esc_attr($this->get_field_name('link_follow')); ?>">
     920                    <option value=""><?php esc_html_e('Default', 'news_plugin'); ?></option>
     921                    <option value="yes" <?php if ($link_follow === "yes") {
     922                        echo 'selected="selected"';
     923                                        } ?>><?php esc_html_e('Follow', 'news_plugin'); ?></option>
     924                    <option value="no" <?php if ($link_follow === "no") {
     925                        echo 'selected="selected"';
     926                                       } ?>><?php esc_html_e('Nofollow', 'news_plugin'); ?></option>
    852927                </select>
    853928
    854929                <?php
    855 
    856930                /*
    857         <br>
    858         <small>Choose where headlines in your feed link to. These can be either direct links to original articles (bbc.co.uk) or those articles can be framed with your custom name/links.</small>
    859         </p>
    860         <p>
    861         <label for="<?php echo $this->get_field_id( 'link_type' ); ?>"><?php _e( 'Link mode:' ); ?></label>
    862         <select class="widefat" id="<?php echo $this->get_field_id( 'link_type' ); ?>" name="<?php echo $this->get_field_name( 'link_type' ); ?>">
    863         <option value="">Default</option>
    864         <option value="frame" <?php if ( $link_type == "frame" ) echo 'selected="selected"' ?>>Framed</option>
    865         <option value="orig"<?php if ( $link_type == "orig" ) echo 'selected="selected"' ?>>Original</option>
    866         </select>
    867         <br>
    868         <small>Choose where headlines in your feed link to. These can be either direct links to original articles (bbc.co.uk) or those articles can be framed with your custom name/links.</small>
    869         </p>
    870         */
     931        <br>
     932        <small>Choose where headlines in your feed link to. These can be either direct links to original articles (bbc.co.uk) or those articles can be framed with your custom name/links.</small>
     933        </p>
     934        <p>
     935        <label for="<?php echo $this->get_field_id( 'link_type' ); ?>"><?php _e( 'Link mode:' ); ?></label>
     936        <select class="widefat" id="<?php echo $this->get_field_id( 'link_type' ); ?>" name="<?php echo $this->get_field_name( 'link_type' ); ?>">
     937        <option value="">Default</option>
     938        <option value="frame" <?php if ( $link_type == "frame" ) echo 'selected="selected"' ?>>Framed</option>
     939        <option value="orig"<?php if ( $link_type == "orig" ) echo 'selected="selected"' ?>>Original</option>
     940        </select>
     941        <br>
     942        <small>Choose where headlines in your feed link to. These can be either direct links to original articles (bbc.co.uk) or those articles can be framed with your custom name/links.</small>
     943        </p>
     944        */
    871945
    872946                ?>
     
    876950            ?>
    877951                <p>
    878                     <label for="<?php echo $this->get_field_id('feed_mode'); ?>"><?php _e('Feed publishing:'); ?></label>
    879                     <select class="widefat" id="<?php echo $this->get_field_id('feed_mode'); ?>" name="<?php echo $this->get_field_name('feed_mode'); ?>">
    880                         <option value="">Default</option>
    881                         <option value="auto" <?php if ($feed_mode == "auto") echo 'selected="selected"' ?>>Automatic</option>
    882                         <option value="manual" <?php if ($feed_mode == "manual") echo 'selected="selected"' ?>>Manual</option>
     952                    <label for="<?php echo esc_attr($this->get_field_id('feed_mode')); ?>"><?php esc_html_e('Feed publishing:', 'news_plugin'); ?></label>
     953                    <select class="widefat" id="<?php echo esc_attr($this->get_field_id('feed_mode')); ?>" name="<?php echo esc_attr($this->get_field_name('feed_mode')); ?>">
     954                        <option value=""><?php esc_html_e('Default', 'news_plugin'); ?></option>
     955                        <option value="auto" <?php if ($feed_mode === "auto") {
     956                            echo 'selected="selected"';
     957                                             } ?>><?php esc_html_e('Automatic', 'news_plugin'); ?></option>
     958                        <option value="manual" <?php if ($feed_mode === "manual") {
     959                            echo 'selected="selected"';
     960                                               } ?>><?php esc_html_e('Manual', 'news_plugin'); ?></option>
    883961                    </select>
    884962                    <br>
    885                     <small>Your feed can be automatically updated with new headlines, or you can choose headlines and publish them manually using news buffering. Default is automatic.</small>
     963                    <small><?php esc_html_e('Your feed can be automatically updated with new headlines, or you can choose headlines and publish them manually using news buffering. Default is automatic.', 'news_plugin'); ?></small>
    886964                </p>
    887     <?php
     965            <?php
    888966        }
    889967    }
     
    901979    public function update($new_opts, $old_opts)
    902980    {
    903         $opts = array();
    904         $opts['title'] = (!empty($new_opts['title'])) ? strip_tags($new_opts['title']) : '';
    905         $opts['keywords'] = (!empty($new_opts['keywords'])) ? strip_tags($new_opts['keywords']) : '';
     981        $opts = [];
     982        $opts['title'] = (!empty($new_opts['title'])) ? wp_strip_all_tags($new_opts['title']) : '';
     983        $opts['keywords'] = (!empty($new_opts['keywords'])) ? wp_strip_all_tags($new_opts['keywords']) : '';
    906984        $opts['count'] = (!empty($new_opts['count'])) ? absint($new_opts['count']) : 5;
    907985        $opts['age'] = (!empty($new_opts['age'])) ? absint($new_opts['age']) : 0;
    908         $opts['sources'] = (!empty($new_opts['sources'])) ? strip_tags($new_opts['sources']) : '';
    909         $opts['excluded_sources'] = (!empty($new_opts['excluded_sources'])) ? strip_tags($new_opts['excluded_sources']) : '';
    910         $opts['search_mode'] = (!empty($new_opts['search_mode'])) ? strip_tags($new_opts['search_mode']) : '';
    911         $opts['search_type'] = (!empty($new_opts['search_type'])) ? strip_tags($new_opts['search_type']) : '';
    912         $opts['sort_mode'] = (!empty($new_opts['sort_mode'])) ? strip_tags($new_opts['sort_mode']) : '';
    913         $opts['link_open_mode'] = (!empty($new_opts['link_open_mode'])) ? strip_tags($new_opts['link_open_mode']) : '';
    914         $opts['link_follow'] = (!empty($new_opts['link_follow'])) ? strip_tags($new_opts['link_follow']) : '';
    915         $opts['link_type'] = (!empty($new_opts['link_type'])) ? strip_tags($new_opts['link_type']) : '';
     986        $opts['sources'] = (!empty($new_opts['sources'])) ? wp_strip_all_tags($new_opts['sources']) : '';
     987        $opts['excluded_sources'] = (!empty($new_opts['excluded_sources'])) ? wp_strip_all_tags($new_opts['excluded_sources']) : '';
     988        $opts['search_mode'] = (!empty($new_opts['search_mode'])) ? wp_strip_all_tags($new_opts['search_mode']) : '';
     989        $opts['search_type'] = (!empty($new_opts['search_type'])) ? wp_strip_all_tags($new_opts['search_type']) : '';
     990        $opts['sort_mode'] = (!empty($new_opts['sort_mode'])) ? wp_strip_all_tags($new_opts['sort_mode']) : '';
     991        $opts['link_open_mode'] = (!empty($new_opts['link_open_mode'])) ? wp_strip_all_tags($new_opts['link_open_mode']) : '';
     992        $opts['link_follow'] = (!empty($new_opts['link_follow'])) ? wp_strip_all_tags($new_opts['link_follow']) : '';
     993        $opts['link_type'] = (!empty($new_opts['link_type'])) ? wp_strip_all_tags($new_opts['link_type']) : '';
    916994        $opts['show_date'] = !empty($new_opts['show_date']);
    917995        $opts['show_source'] = !empty($new_opts['show_source']);
    918996        $opts['show_abstract'] = !empty($new_opts['show_abstract']);
    919         $opts['feed_mode'] = (!empty($new_opts['feed_mode'])) ? strip_tags($new_opts['feed_mode']) : '';
     997        $opts['feed_mode'] = (!empty($new_opts['feed_mode'])) ? wp_strip_all_tags($new_opts['feed_mode']) : '';
    920998        $opts['wp_uid'] = (!isset($new_opts['wp_uid']) || empty($new_opts['wp_uid'])) ? get_current_user_id() : $new_opts['wp_uid'];
    921999
     
    9231001    }
    9241002}
    925     ?>
     1003?>
  • newsplugin/trunk/news-plugin.php

    r2384451 r2580769  
    11<?php
    2 /*
    3 Plugin Name: NewsPlugin
    4 Plugin URI: http://newsplugin.com/
    5 Description: Create custom newsfeeds for your website. Choose keywords, number of articles and other settings, put the feed wherever you want using widgets or shortcodes, and watch the fresh relevant news headlines appear on your pages (or approve and publish them manually). You can always shape the news right from your website, remove unwanted articles or star the good ones. Thanks for using the NewsPlugin, and we hope you like it.
    6 Author: newsplugin.com
    7 Version: 1.0.18
    8 Author URI: http://newsplugin.com/
    9 */
     2
     3/**
     4 * Plugin Name: NewsPlugin
     5 * Plugin URI: http://newsplugin.com/
     6 * Description: Create custom newsfeeds for your website. Choose keywords, number of articles and  * other settings, put the feed wherever you want using widgets or shortcodes, and watch the fresh  * relevant news headlines appear on your pages (or approve and publish them manually).
     7 * Author: newsplugin.com
     8 * Text Domain: news_plugin
     9 * Domain Path: /languages
     10 * Version: 1.1.0
     11 * Author URI: http://newsplugin.com/
     12 *
     13 * @package    WordPress
     14 * @subpackage News Plugin
     15 * @since 1.0.0
     16 */
    1017
    1118// Prevent ourselves from being run directly.
     
    2734     * Register plugin with WordPress.
    2835     */
    29     function __construct()
    30     {
     36    public function __construct()
     37    {
     38
     39        add_action('init', [$this, 'localize']);
     40
    3141        // Widgets.
    32         add_action('widgets_init', array($this, 'widgets_init'));
    33         add_action('admin_init', array($this, 'admin_init'));
    34         add_action('admin_menu', array($this, 'admin_menu'));
    35         add_action('admin_init', array(&$this, 'register_help_section'));
    36         add_action('admin_init', array(&$this, 'register_activation_section'));
    37         add_action('admin_init', array(&$this, 'register_shortcode_section'));
    38         add_action('admin_init', array(&$this, 'register_style_section'));
    39         add_action('admin_init', array(&$this, 'register_feed_section'));
    40         add_action('admin_init', array(&$this, 'register_status_section'));
    41         add_action('admin_enqueue_scripts', array($this, 'register_admin_scripts'));
    42         add_action('wp_enqueue_scripts', array($this, 'register_styles'));
    43 
    44         add_action('admin_post_nopriv_news_plugin_save_style', array($this, 'handle_save_style'));
    45         add_action('admin_post_news_plugin_save_style', array($this, 'handle_save_style'));
    46         add_action('admin_post_nopriv_news_plugin_send_feedback', array($this, 'handle_send_feedback'));
    47         add_action('admin_post_news_plugin_send_feedback', array($this, 'handle_send_feedback'));
    48         add_action('admin_post_nopriv_news_plugin_update_system_info', array($this, 'handle_update_system_info'));
    49         add_action('admin_post_news_plugin_update_system_info', array($this, 'handle_update_system_info'));
    50 
    51         add_action('admin_init', array($this, 'refresh_plugin_version'));
    52 
    53         register_activation_hook(__FILE__, array($this, 'userSystemCheck_create'));
    54         register_deactivation_hook(__FILE__, array($this, 'userSystemCheck_deactivation'));
     42        add_action('widgets_init', [$this, 'widgets_init']);
     43        add_action('admin_init', [$this, 'admin_init']);
     44        add_action('admin_menu', [$this, 'admin_menu']);
     45        add_action('admin_init', [&$this, 'register_help_section']);
     46        add_action('admin_init', [&$this, 'register_activation_section']);
     47        add_action('admin_init', [&$this, 'register_shortcode_section']);
     48        add_action('admin_init', [&$this, 'register_style_section']);
     49        add_action('admin_init', [&$this, 'register_feed_section']);
     50        add_action('admin_init', [&$this, 'register_status_section']);
     51        add_action('admin_enqueue_scripts', [$this, 'register_admin_scripts']);
     52        add_action('wp_enqueue_scripts', [$this, 'register_styles']);
     53
     54        add_action('admin_post_nopriv_news_plugin_save_style', [$this, 'handle_save_style']);
     55        add_action('admin_post_news_plugin_save_style', [$this, 'handle_save_style']);
     56        add_action('admin_post_nopriv_news_plugin_send_feedback', [$this, 'handle_send_feedback']);
     57        add_action('admin_post_news_plugin_send_feedback', [$this, 'handle_send_feedback']);
     58        add_action('admin_post_nopriv_news_plugin_update_system_info', [$this, 'handle_update_system_info']);
     59        add_action('admin_post_news_plugin_update_system_info', [$this, 'handle_update_system_info']);
     60
     61        add_action('admin_init', [$this, 'refresh_plugin_version']);
     62
     63        register_activation_hook(__FILE__, [$this, 'userSystemCheck_create']);
     64        register_deactivation_hook(__FILE__, [$this, 'userSystemCheck_deactivation']);
    5565        $usc = get_option('newsPlugin_system_info');
    5666        $api_key = get_option('news_plugin_api_key');
     
    5868            !$usc ||
    5969            !isset($usc['info_version']) || ($usc['info_version'] < News_Plugin_Utils::get_system_info_version()) ||
    60             !isset($usc['api_key']) || ($usc['api_key'] != $api_key)
     70            !isset($usc['api_key']) || ($usc['api_key'] !== $api_key)
    6171        ) {
    6272            update_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info());
     
    6474    }
    6575
    66     function userSystemCheck_create()
     76    /**
     77     * Do on user system check creation
     78     *
     79     * @return void
     80     */
     81    public function userSystemCheck_create()
    6782    {
    6883        add_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info());
    6984        add_option('news_plugin_url_method', false);
    7085    }
    71     function userSystemCheck_deactivation()
     86
     87    /**
     88     * Do on system check deactivation
     89     *
     90     * @return void
     91     */
     92    public function userSystemCheck_deactivation()
    7293    {
    7394        delete_option('newsPlugin_system_info');
    7495    }
    7596
    76     function refresh_plugin_version()
     97    /**
     98     * Refresh plugin version
     99     *
     100     * @return void
     101     */
     102    public function refresh_plugin_version()
    77103    {
    78104        if (function_exists('get_plugin_data')) {
     
    86112
    87113    /**
     114     * Load plugin textdomain
     115     *
     116     * @return void
     117     */
     118    public function localize()
     119    {
     120        load_plugin_textdomain('news_plugin', false, basename(dirname(__FILE__)) . '/languages');
     121    }
     122
     123    /**
    88124     * Register the plugin widget, widget areas and widget shorcodes.
    89125     */
    90     function widgets_init()
     126    public function widgets_init()
    91127    {
    92128        register_widget('News_Plugin_Widget');
    93129        for ($area = 1; $area <= 4; $area++) {
    94             register_sidebar(array(
     130            register_sidebar([
    95131                'name' => "NewsPlugin Widget Area {$area}",
    96132                'id' => "newsplugin_widgets_{$area}",
     
    98134                'before_widget' => '<div id="%1$s" class="widget %2$s">',
    99135                'after_widget' => '</div>'
    100             ));
     136            ]);
    101137        }
    102         add_shortcode('newsplugin_widgets', array($this, 'widget_area_shortcode'));
    103         add_shortcode('newsplugin_feed', array($this, 'feed_shortcode'));
     138        add_shortcode('newsplugin_widgets', [$this, 'widget_area_shortcode']);
     139        add_shortcode('newsplugin_feed', [$this, 'feed_shortcode']);
    104140    }
    105141
    106142    /**
    107143     * Process the widget area shortcode.
    108      */
    109     function widget_area_shortcode($attrs)
    110     {
    111         $a = shortcode_atts(array('area' => '1'), $attrs);
     144     *
     145     * @param array $attrs Attributes.
     146     * @return string|false
     147     */
     148    public function widget_area_shortcode($attrs)
     149    {
     150        $a = shortcode_atts(['area' => '1'], $attrs);
    112151        $sidebar = "newsplugin_widgets_{$a['area']}";
    113152        ob_start();
     
    121160
    122161
    123     //[feed_shortcode title="" keywords="News" count="" age="" sources="" excluded_sources="" search_mode="" search_type="" sort_mode="" link_type="" show_date="" show_source="" show_abstract="" feed_mode=""]
     162    // [feed_shortcode title="" keywords="News" count="" age="" sources="" excluded_sources="" search_mode="" search_type="" sort_mode="" link_type="" show_date="" show_source="" show_abstract="" feed_mode=""]
    124163
    125164    /**
    126165     * Process the newsfeed shortcode.
    127      */
    128     function feed_shortcode($attrs)
    129     {
    130         $attrs = shortcode_atts(array(
     166     *
     167     * @param array $attrs Attributes.
     168     * @return string|false
     169     */
     170    public function feed_shortcode($attrs)
     171    {
     172        $attrs = shortcode_atts([
    131173            'id' => '',
    132174            'title' => '',
     
    147189            'feed_mode' => '',
    148190            'wp_uid' => ''
    149         ), $attrs);
     191        ], $attrs);
    150192        $newswid = new News_Plugin_Widget();
    151         $a = $newswid->update($attrs, array());
     193        $a = $newswid->update($attrs, []);
    152194        $a['id'] = $attrs['id'];
    153195        ob_start();
    154         the_widget('News_Plugin_Widget', $a, array());
     196        the_widget('News_Plugin_Widget', $a, []);
    155197        return ob_get_clean();
    156198    }
     
    159201     * Register the plugin CSS style.
    160202     */
    161     function register_styles()
    162     {
    163         wp_register_style('news-plugin', plugin_dir_url(__FILE__) . 'assets/css/news-plugin.css', array(), "0.1");
     203    public function register_styles()
     204    {
     205        wp_register_style('news-plugin', plugin_dir_url(__FILE__) . 'assets/css/news-plugin.css', [], "0.1");
    164206        wp_enqueue_style('news-plugin');
    165207    }
    166208
    167     function register_admin_scripts()
     209    /**
     210     * Register admin scripts
     211     *
     212     * @return void
     213     */
     214    public function register_admin_scripts()
    168215    {
    169216        $assets_path = plugin_dir_url(__FILE__) . 'assets/';
     217        // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
    170218        wp_enqueue_style('news-plugin', $assets_path . 'css/news-plugin.css');
    171         wp_enqueue_script('news-plugin', $assets_path . 'js/jscolor.min.js');
     219        // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion, WordPress.WP.EnqueuedResourceParameters.NoExplicitVersion
     220        wp_enqueue_script('news-plugin', $assets_path . 'js/jscolor.min.js', [], false, true);
    172221    }
    173222
     
    175224     * Register the plugin options.
    176225     */
    177     function admin_init()
     226    public function admin_init()
    178227    {
    179228        add_settings_section(
    180229            'default',
    181             NULL,
    182             NULL,
     230            null,
     231            null,
    183232            'news-plugin-settings'
    184233        );
     
    187236            'news_plugin_api_key',
    188237            __('Activation Key:', 'news_plugin'),
    189             array($this, 'settings_api_key'),
     238            [$this, 'settings_api_key'],
    190239            'news-plugin-settings',
    191240            'default'
     
    194243            'news-plugin-settings',
    195244            'news_plugin_api_key',
    196             array($this, 'validate_api_key')
     245            [$this, 'validate_api_key']
    197246        );
    198247
    199         /* Disable User Mode for now.
    200        add_settings_field(
    201            'news_plugin_user_mode',
    202            __('Choose User Mode:','news_plugin'),
    203            array( $this, 'settings_user_mode' ),
    204            'news-plugin-settings',
    205            'default'
    206        );
    207        register_setting(
    208            'news-plugin-settings',
    209            'news_plugin_user_mode',
    210            array( $this, 'validate_user_mode' )
    211        );
    212        */
     248        /*
     249         Disable User Mode for now.
     250       add_settings_field(
     251           'news_plugin_user_mode',
     252           __('Choose User Mode:','news_plugin'),
     253           array( $this, 'settings_user_mode' ),
     254           'news-plugin-settings',
     255           'default'
     256       );
     257       register_setting(
     258           'news-plugin-settings',
     259           'news_plugin_user_mode',
     260           array( $this, 'validate_user_mode' )
     261       );
     262       */
    213263    }
    214264
     
    216266     * Register the plugin menu.
    217267     */
    218     function admin_menu()
     268    public function admin_menu()
    219269    {
    220270        add_menu_page(
     
    223273            'manage_options',
    224274            'news-plugin-settings',
    225             array($this, 'newsplugin_options_page'),
     275            [$this, 'newsplugin_options_page'],
    226276            'dashicons-megaphone',
    227277            '3'
    228278        );
    229         add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'add_action_links'));
     279        add_filter('plugin_action_links_' . plugin_basename(__FILE__), [$this, 'add_action_links']);
    230280    }
    231281
     
    235285     * when registering settings
    236286     */
    237     private $status_settings_key = 'newsplugin_status_settings';
     287    /**
     288     * Key - $status
     289     *
     290     * @var string
     291     */
     292     private $status_settings_key = 'newsplugin_status_settings';
     293    /**
     294     * Key - feed
     295     *
     296     * @var string
     297     */
    238298    private $feed_settings_key = 'newsplugin_feed_settings';
     299    /**
     300     * Key - style
     301     *
     302     * @var string
     303     */
    239304    private $style_settings_key = 'newsplugin_style_settings';
     305    /**
     306     * Key - activation
     307     *
     308     * @var string
     309     */
    240310    private $activation_settings_key = 'newsplugin_activation_settings';
     311    /**
     312     * Key - shortcode
     313     *
     314     * @var string
     315     */
    241316    private $shortcode_settings_key = 'newsplugin_shortcode_settings';
     317    /**
     318     * Key - help
     319     *
     320     * @var string
     321     */
    242322    private $help_settings_key = 'newsplugin_help_settings';
     323    /**
     324     * Key - key
     325     *
     326     * @var string
     327     */
    243328    private $plugin_options_key = 'news-plugin-settings';
    244     private $plugin_settings_tabs = array();
    245 
    246     /*
    247      * Registering the sections.
    248      */
    249     function register_status_section()
     329    /**
     330     * Key - tabs
     331     *
     332     * @var array
     333     */
     334    private $plugin_settings_tabs = [];
     335
     336    /**
     337     * Registering the sections - status
     338     *
     339     * @return void
     340     */
     341    public function register_status_section()
    250342    {
    251343        $this->plugin_settings_tabs[$this->status_settings_key] = 'Server Information';
    252344    }
    253     function register_feed_section()
     345    /**
     346     * Registering the sections - feed
     347     *
     348     * @return void
     349     */
     350    public function register_feed_section()
    254351    {
    255352        $this->plugin_settings_tabs[$this->feed_settings_key] = 'Send Feedback';
    256353    }
    257     function register_style_section()
     354    /**
     355     * Registering the sections - style
     356     *
     357     * @return void
     358     */
     359    public function register_style_section()
    258360    {
    259361        $this->plugin_settings_tabs[$this->style_settings_key] = 'Customize Styles';
    260362    }
    261     function register_activation_section()
     363    /**
     364     * Registering the sections - activation
     365     *
     366     * @return void
     367     */
     368    public function register_activation_section()
    262369    {
    263370        $this->plugin_settings_tabs[$this->activation_settings_key] = 'Activate NewsPlugin';
    264371    }
    265     function register_shortcode_section()
     372    /**
     373     * Registering the sections - shortcode
     374     *
     375     * @return void
     376     */
     377    public function register_shortcode_section()
    266378    {
    267379        $this->plugin_settings_tabs[$this->shortcode_settings_key] = 'Generate Shortcode';
    268380    }
    269     function register_help_section()
     381    /**
     382     * Registering the sections - help
     383     *
     384     * @return void
     385     */
     386    public function register_help_section()
    270387    {
    271388        $this->plugin_settings_tabs[$this->help_settings_key] = 'Instructions!';
    272389    }
    273390
    274     function get_with_default($arr, $a, $b, $def)
    275     { /* Grrr this should be language construct ... oh. It will be. PHP 7. https://wiki.php.net/rfc/isset_ternary */
     391    /**
     392     * Get value with default
     393     *
     394     * @param array  $arr Array.
     395     * @param string $a First index.
     396     * @param string $b Second index.
     397     * @param mixed  $def Default.
     398     * @return mixed
     399     */
     400    public function get_with_default($arr, $a, $b, $def)
     401    {
     402 /* Grrr this should be language construct ... oh. It will be. PHP 7. https://wiki.php.net/rfc/isset_ternary */
    276403        if (!is_array($arr)) {
    277404            return $def;
     
    286413    }
    287414
    288     /*
     415    /**
    289416     * Plugin Options page rendering goes here, checks
    290417     * for active tab and replaces key with the related
    291418     * settings key. Uses the plugin_options_tabs method
    292419     * to render the tabs.
    293      */
    294     function newsplugin_options_page()
    295     {
    296         $tab = isset($_GET['tab']) ? $_GET['tab'] : $this->help_settings_key;
    297 ?>
     420     *
     421     * @return void
     422     */
     423    public function newsplugin_options_page()
     424    {
     425
     426        // phpcs:ignore WordPress.Security.NonceVerification.Recommended
     427        $tab = isset($_GET['tab']) ? sanitize_title_with_dashes(wp_unslash($_GET['tab'])) : $this->help_settings_key;
     428        ?>
    298429        <div class="wrap">
    299430            <h2>NewsPlugin Settings</h2>
     
    302433            if (empty($key)) { ?>
    303434                <div class="error">
    304                     <p><a href="<?php echo admin_url('admin.php?page=news-plugin-settings&tab=newsplugin_activation_settings'); ?>">Add Activation Key</a> to the NewsPlugin. Otherwise, the generated shortcodes or NewsPlugin widgets will not work!</p>
     435                    <p><a href="<?php echo esc_url(admin_url('admin.php?page=news-plugin-settings&tab=newsplugin_activation_settings')); ?>">Add Activation Key</a> to the NewsPlugin. Otherwise, the generated shortcodes or NewsPlugin widgets will not work!</p>
    305436                </div>
    306437            <?php } ?>
     
    312443                    <?php submit_button(); ?>
    313444                </form>
    314             <?php } else if ($tab === $this->shortcode_settings_key && !empty($key)) { ?>
     445            <?php } elseif ($tab === $this->shortcode_settings_key && !empty($key)) { ?>
    315446                <table id="shortcodeTable" class="form-table">
    316447                    <tr>
     
    546677                            shortcode_params += " age='" + newsplugin_age + "'";
    547678                        }
    548                         shortcode_params += " wp_uid='<?php echo get_current_user_id(); ?>'";
     679                        shortcode_params += " wp_uid='<?php echo esc_attr(get_current_user_id()); ?>'";
    549680                        var html = "<p>Press Ctrl+C to copy to clipboard and paste it in your posts or pages.</p>";
    550681                        html += "<p><textarea id='shortcode-field' onfocus='this.select()' onclick='this.select()' readonly='readonly' style='width:400px; height:200px; max-width:400px; max-height:200px; min-width:400px; min-height:200px;'>[newsplugin_feed id='" + new Date().valueOf() + "'" + shortcode_params + "]</textarea></p>";
     
    555686                    }
    556687                </script>
    557             <?php } else if ($tab === $this->help_settings_key) { ?>
     688            <?php } elseif ($tab === $this->help_settings_key) { ?>
    558689                <h3>Instructions</h3>
    559690                <p>Please read the instructions below carefully to easily setup and use the NewsPlugin.</p>
    560                 <p><strong>1. Enter Activation Key:</strong><br>First of all, enter your Activation Key in the <a href="<?php echo admin_url('admin.php?page=news-plugin-settings&tab=' . $this->activation_settings_key) ?>">Activate</a> tab.</p>
    561                 <p><strong>2. Create Newsfeeds:</strong><br>Create your newsfeed by generating a shortcode from <a href="<?php echo admin_url('admin.php?page=news-plugin-settings&tab=' . $this->shortcode_settings_key) ?>">Generate Shortcode</a> tab. Put that shortcode in posts or pages where you want to display your newsfeed.<br>OR<br>create your newsfeed from <a href="<?php echo admin_url('widgets.php') ?>">Appearance &gt; Widgets</a>. From the widgets panel drag the "NewsPlugin" widget to the desired sidebar or widget area where you want to show your newsfeed. Edit the widget features to create/edit your newsfeed. Choose the name, number of headlines, keywords and other settings.</p>
     691                <p><strong>1. Enter Activation Key:</strong><br>First of all, enter your Activation Key in the <a href="<?php echo esc_url(admin_url('admin.php?page=news-plugin-settings&tab=' . $this->activation_settings_key)); ?>">Activate</a> tab.</p>
     692                <p><strong>2. Create Newsfeeds:</strong><br>Create your newsfeed by generating a shortcode from <a href="<?php echo esc_url(admin_url('admin.php?page=news-plugin-settings&tab=' . $this->shortcode_settings_key)); ?>">Generate Shortcode</a> tab. Put that shortcode in posts or pages where you want to display your newsfeed.<br>OR<br>create your newsfeed from <a href="<?php echo esc_url(admin_url('widgets.php')); ?>">Appearance &gt; Widgets</a>. From the widgets panel drag the "NewsPlugin" widget to the desired sidebar or widget area where you want to show your newsfeed. Edit the widget features to create/edit your newsfeed. Choose the name, number of headlines, keywords and other settings.</p>
    562693                <p><strong>3. Edit Headlines (if you want to):</strong><br>You can remove unwanted headlines or star the good ones right from your site. Note that you must be logged in to WordPress as an administrator or an editor to see the 'Edit Newsfeed Mode' link on your page (next to your newsfeed).</p>
    563694                <h3>Support</h3>
     
    569700                $style_news = get_user_meta($userID, 'news_style_dashbord_style', 'true');
    570701
    571                 $font_family = array();
    572                 $font_family = array("Arial", "Cambria", "Algerian", "Copperplate", "Lucida Console", "Times New Roman", "Impact", "Monaco", "Georgia", "Optima");
    573             ?>
    574                 <h3>Style news plugin widgets created by user <?php echo $user->display_name; ?></h3>
     702                $font_family = [];
     703                $font_family = ["Arial", "Cambria", "Algerian", "Copperplate", "Lucida Console", "Times New Roman", "Impact", "Monaco", "Georgia", "Optima"];
     704                ?>
     705                <h3>Style news plugin widgets created by user <?php echo esc_html($user->display_name); ?></h3>
    575706                <div class="news-row-style">
    576707                    <div class="style_left">
    577708                        <form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
     709                            <?php wp_nonce_field('news_plugin_save_style', 'news_plugin_save_style_field'); ?>
    578710                            <input type="hidden" name="action" value="news_plugin_save_style">
    579711                            <h3>Newsfeed Title</h3>
    580712                            <h4>Color</h4>
    581713                            <?php
    582                             echo '<input class="jscolor" name="title_color" id="title_color" type="text" value="' . $this->get_with_default($style_news, 'newsfeed_title', 'color', '') . '" /><br>';
     714                            echo '<input class="jscolor" name="title_color" id="title_color" type="text" value="' . esc_attr($this->get_with_default($style_news, 'newsfeed_title', 'color', '')) . '" /><br>';
    583715                            echo '<h4>Size</h4>';
    584716                            echo '<select name="title_size" id="title_size">';
    585717                            $v = $this->get_with_default($style_news, 'newsfeed_title', 'size', '');
    586                             echo '<option value="' . $v . '">' . $v . '</option>';
     718                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    587719                            for ($i = 10; $i <= 50; $i++) {
    588                                 if ($i == $v) {
     720                                if ($i === $v) {
    589721                                } else {
    590                                     echo '<option value="' . $i . '">' . $i . '</option>';
     722                                    echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
    591723                                }
    592724                            }
     
    595727                            echo '<select name="title_font" id="title_font">';
    596728                            $v = $this->get_with_default($style_news, 'newsfeed_title', 'font_family', '');
    597                             echo '<option value="' . $v . '">' . $v . '</option>';
     729                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    598730                            if ($v) {
    599731                                echo '<option value="">Unchanged (theme default)</option>';
    600732                            }
    601733                            foreach ($font_family as $fonts) {
    602                                 if ($fonts == $v) {
     734                                if ($fonts === $v) {
    603735                                } else {
    604                                     echo '<option value="' . $fonts . '">' . $fonts . '</option>';
     736                                    echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>';
    605737                                }
    606738                            }
     
    608740                            echo '<h3>Article Headline</h3>';
    609741                            echo '<h4>Color</h4>';
    610                             echo '<input class="jscolor" name="news_title_color" id="news_title_color" type="text" value="' . $this->get_with_default($style_news, 'article_headline', 'color', '') . '" /><br>';
     742                            echo '<input class="jscolor" name="news_title_color" id="news_title_color" type="text" value="' . esc_attr($this->get_with_default($style_news, 'article_headline', 'color', '')) . '" /><br>';
    611743                            echo '<h4>Size</h4>';
    612744                            echo '<select name="news_title_size" id="news_title_size">';
    613745                            $v = $this->get_with_default($style_news, 'article_headline', 'size', '');
    614                             echo '<option value="' . $v . '">' . $v . '</option>';
     746                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    615747                            for ($i = 10; $i <= 50; $i++) {
    616                                 if ($i == $v) {
     748                                if ($i === $v) {
    617749                                } else {
    618                                     echo '<option value="' . $i . '">' . $i . '</option>';
     750                                    echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
    619751                                }
    620752                            }
     
    623755                            echo '<select name="news_title_family" id="news_title_family">';
    624756                            $v = $this->get_with_default($style_news, 'article_headline', 'font_family', '');
    625                             echo '<option value="' . $v . '">' . $v . '</option>';
     757                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    626758                            if ($v) {
    627759                                echo '<option value="">Unchanged (theme default)</option>';
    628760                            }
    629761                            foreach ($font_family as $fonts) {
    630                                 if ($fonts == $v) {
     762                                if ($fonts === $v) {
    631763                                } else {
    632                                     echo '<option value="' . $fonts . '">' . $fonts . '</option>';
     764                                    echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>';
    633765                                }
    634766                            }
     
    636768                            echo '<h3>Article Abstract</h3>';
    637769                            echo '<h4>Color</h4>';
    638                             echo '<input class="jscolor" name="abstract_font_color" id="abstract_font_color" type="text" value="' . $this->get_with_default($style_news, 'article_abstract', 'color', '') . '" /><br>';
     770                            echo '<input class="jscolor" name="abstract_font_color" id="abstract_font_color" type="text" value="' . esc_attr($this->get_with_default($style_news, 'article_abstract', 'color', '')) . '" /><br>';
    639771                            echo '<h4>Size</h4>';
    640772                            echo '<select name="abstract_font_size" id="abstract_font_size">';
    641773                            $v = $this->get_with_default($style_news, 'article_abstract', 'size', '');
    642                             echo '<option value="' . $v . '">' . $v . '</option>';
     774                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    643775                            for ($i = 10; $i <= 50; $i++) {
    644                                 if ($i == $v) {
     776                                if ($i === $v) {
    645777                                } else {
    646                                     echo '<option value="' . $i . '">' . $i . '</option>';
     778                                    echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
    647779                                }
    648780                            }
     
    651783                            echo '<select name="abstract_font_family" id="abstract_font_family">';
    652784                            $v = $this->get_with_default($style_news, 'article_abstract', 'font_family', '');
    653                             echo '<option value="' . $v . '">' . $v . '</option>';
     785                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    654786                            if ($v) {
    655787                                echo '<option value="">Unchanged (theme default)</option>';
    656788                            }
    657789                            foreach ($font_family as $fonts) {
    658                                 if ($fonts == $v) {
     790                                if ($fonts === $v) {
    659791                                } else {
    660                                     echo '<option value="' . $fonts . '">' . $fonts . '</option>';
     792                                    echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>';
    661793                                }
    662794                            }
     
    668800                            echo '<h4>Color</h4>';
    669801
    670                             echo '<input class="jscolor" name="news_date_color" id="news_date_color" type="text" value="' . $this->get_with_default($style_news, 'article_date', 'color', '') . '" /><br>';
     802                            echo '<input class="jscolor" name="news_date_color" id="news_date_color" type="text" value="' . esc_attr($this->get_with_default($style_news, 'article_date', 'color', '')) . '" /><br>';
    671803
    672804                            echo '<h4>Size</h4>';
     
    675807
    676808                            $v = $this->get_with_default($style_news, 'article_date', 'size', '');
    677                             echo '<option value="' . $v . '">' . $v . '</option>';
     809                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    678810
    679811                            for ($i = 10; $i <= 50; $i++) {
    680 
    681                                 if ($i == $v) {
     812                                if ($i === $v) {
    682813                                } else {
    683 
    684                                     echo '<option value="' . $i . '">' . $i . '</option>';
     814                                    echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
    685815                                }
    686816                            }
     
    690820                            echo '<select name="date_font" id="date_font">';
    691821                            $v = $this->get_with_default($style_news, 'article_date', 'font_family', '');
    692                             echo '<option value="' . $v . '">' . $v . '</option>';
     822                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    693823                            if ($v) {
    694824                                echo '<option value="">Unchanged (theme default)</option>';
    695825                            }
    696826                            foreach ($font_family as $fonts) {
    697                                 if ($fonts == $v) {
     827                                if ($fonts === $v) {
    698828                                } else {
    699                                     echo '<option value="' . $fonts . '">' . $fonts . '</option>';
     829                                    echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>';
    700830                                }
    701831                            }
     
    706836                            echo '<h4>Color</h4>';
    707837
    708                             echo '<input class="jscolor" name="source_color" id="source_color" type="text" value="' . $this->get_with_default($style_news, 'article_sources', 'color', '') . '" /><br>';
     838                            echo '<input class="jscolor" name="source_color" id="source_color" type="text" value="' . esc_attr($this->get_with_default($style_news, 'article_sources', 'color', '')) . '" /><br>';
    709839
    710840                            echo '<h4>Size</h4>';
     
    713843
    714844                            $v = $this->get_with_default($style_news, 'article_sources', 'size', '');
    715                             echo '<option value="' . $v . '">' . $v . '</option>';
     845                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    716846
    717847                            for ($i = 10; $i <= 50; $i++) {
    718 
    719                                 if ($i == $v) {
     848                                if ($i === $v) {
    720849                                } else {
    721 
    722                                     echo '<option value="' . $i . '">' . $i . '</option>';
     850                                    echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>';
    723851                                }
    724852                            }
     
    728856                            echo '<select name="source_font" id="source_font">';
    729857                            $v = $this->get_with_default($style_news, 'article_sources', 'font_family', '');
    730                             echo '<option value="' . $v . '">' . $v . '</option>';
     858                            echo '<option value="' . esc_attr($v) . '">' . esc_html($v) . '</option>';
    731859                            if ($v) {
    732860                                echo '<option value="">Unchanged (theme default)</option>';
    733861                            }
    734862                            foreach ($font_family as $fonts) {
    735                                 if ($fonts == $v) {
     863                                if ($fonts === $v) {
    736864                                } else {
    737                                     echo '<option value="' . $fonts . '">' . $fonts . '</option>';
     865                                    echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>';
    738866                                }
    739867                            }
     
    751879                            ?>
    752880
    753                         <?php } elseif ($tab === $this->feed_settings_key) {
     881            <?php } elseif ($tab === $this->feed_settings_key) {
    754882                        echo '<div class="feeds-row-style">';
    755883                        echo '<div>';
    756                         if (isset($_GET['status'])) {
    757                             if ($_GET['status'] == 1) {
    758                                 echo '<span><h3>Your message has been sent.<br/>Thank you.</h3></span>';
    759                             } else {
    760                                 echo '<span><h3>Error sending message. Please use the form at <a href="https://www.newsplugin.com/contact/">https://www.newsplugin.com/contact/</a>, don' . "'" . 't forget to include the server informations and mention that the plugin feedback page failed.</span></h3>';
    761                             }
    762                         } ?>
     884                // phpcs:ignore WordPress.Security.NonceVerification.Recommended
     885                if (isset($_GET['status'])) {
     886                    // phpcs:ignore WordPress.Security.NonceVerification.Recommended
     887                    if (intval($_GET['status']) === 1) {
     888                        echo '<span><h3>Your message has been sent.<br/>Thank you.</h3></span>';
     889                    } else {
     890                        echo '<span><h3>Error sending message. Please use the form at <a href="https://www.newsplugin.com/contact/">https://www.newsplugin.com/contact/</a>, don' . "'" . 't forget to include the server informations and mention that the plugin feedback page failed.</span></h3>';
     891                    }
     892                } ?>
    763893                    </div>
    764894                    <form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post" id="feed_form">
     895                        <?php wp_nonce_field('news_plugin_send_feedback', 'news_plugin_send_feedback_field'); ?>
    765896                        <input type="hidden" name="action" value="news_plugin_send_feedback">
    766897                        <div class="feed_left">
    767                             <h3>From</h3><?php
    768                                             if ($user_info = News_Plugin_Utils::get_user_info()) {
    769                                                 $email = $user_info->email;
    770                                             } else {
    771                                                 $email = '';
    772                                             }
    773                                             echo '<input class="text notsobig" name="feed_from" id="feed_from" type="email" size="64" value="' . $email . '"/><br>';
     898                            <h3><?php esc_html_e('Email', 'news_plugin'); ?></h3><?php
     899                            $user_info = News_Plugin_Utils::get_user_info();
     900                            if ($user_info) {
     901                                $email = $user_info->email;
     902                            } else {
     903                                $email = '';
     904                            }
     905                                            echo '<input class="text notsobig" name="feed_from" id="feed_from" type="email" size="64" value="' . esc_attr($email) . '"/><br>';
    774906                                            echo '<h3>Subject</h3>';
    775907                                            echo '<input class="text notsobig" name="feed_subject" id="feed_subject" type="text" size="64" /><br>';
    776908                                            echo '<h3>Description</h3>';
    777909                                            echo '<textarea form="feed_form" class="notsobig" name="feed_desc" id="taid" cols="64" rows="10">';
    778                                             /* echo '<div id="sys_status_data">';
    779                 echo '</div>'; */
    780910                                            echo '</textarea><br>';
    781911                                            echo '<p class="submit">';
     
    799929
    800930                                            $results = get_option('newsPlugin_system_info');
    801                                             foreach ($results['wordpress_env'] as $key => $value) {
    802                                                 $key_Name = str_replace('_', ' ', $key);
    803                                                 echo '<tr>
    804                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    805                             <td>' . $value . '</td>
     931                            foreach ($results['wordpress_env'] as $key => $value) {
     932                                $key_Name = str_replace('_', ' ', $key);
     933                                echo '<tr>
     934                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     935                            <td>' . esc_html($value) . '</td>
    806936                        </tr>';
    807                                             }
    808                                             foreach ($results['system_env'] as $key => $value) {
    809                                                 $key_Name = str_replace('_', ' ', $key);
    810                                                 echo '<tr>
    811                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    812                             <td>' . $value . '</td>
     937                            }
     938                            foreach ($results['system_env'] as $key => $value) {
     939                                $key_Name = str_replace('_', ' ', $key);
     940                                echo '<tr>
     941                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     942                            <td>' . esc_html($value) . '</td>
    813943                        </tr>';
    814                                             }
    815                                             foreach ($results['newsplugin_env'] as $key => $value) {
    816                                                 $key_Name = str_replace('_', ' ', $key);
    817                                                 echo '<tr>
    818                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    819                             <td>' . $value . '</td>
     944                            }
     945                            foreach ($results['newsplugin_env'] as $key => $value) {
     946                                $key_Name = str_replace('_', ' ', $key);
     947                                echo '<tr>
     948                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     949                            <td>' . esc_html($value) . '</td>
    820950                        </tr>';
    821                                             }
     951                            }
    822952
    823953                                            echo '</tbody>';
     
    826956                                            echo '<div class="log_div">';
    827957                                            $myfilename = plugin_dir_url(__FILE__) . "logs/plugin-logs.txt";
     958                                            // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
    828959                                            $content = file_exists($myfilename) ? file_get_contents($myfilename) : false;
    829960                                            $v = ($content === false) ? '' : ' checked="checked"';
    830                                             echo '<h2><input type="checkbox" id="errors_div" onclick="showError(this)"' . $v . '/> Include Custom Logs</h2>';
     961                                            echo '<h2><input type="checkbox" id="errors_div" onclick="showError(this)"' . esc_html($v) . '/> Include Custom Logs</h2>';
    831962                                            echo '</div>';
    832963                                            echo '<div class="feed_system_preview" id="error_show_div">';
    833                                             echo '<textarea id="errors_logs" name="noLog_errors" form="feed_form" style="display:none;">"' . $content . '"</textarea>';
    834                                             if ($content !== false) {
    835                                                 echo '<p><strong>"' . $content . '"</strong></p>';
    836                                             }
     964                                            echo '<textarea id="errors_logs" name="noLog_errors" form="feed_form" style="display:none;">"' . esc_html($content) . '"</textarea>';
     965                            if ($content !== false) {
     966                                echo '<p><strong>"' . esc_html($content) . '"</strong></p>';
     967                            }
    837968                                            echo '</div>';
    838969                                            echo '</div>';
     
    840971
    841972                                            echo '</div>';
    842                                             ?>
     973                            ?>
    843974                            <script>
    844975                                function showDiv(box) {
     
    867998                            </script>
    868999
    869                         <?php } elseif ($tab === $this->status_settings_key) { ?>
     1000            <?php } elseif ($tab === $this->status_settings_key) { ?>
    8701001                            <form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
     1002                                <?php wp_nonce_field('news_plugin_update_system_info'); ?>
    8711003                                <input type="hidden" name="action" value="news_plugin_update_system_info">
    8721004                                <p class="submit">
     
    8821014                                        $key_Name = str_replace('_', ' ', $key);
    8831015                                        echo '<tr>
    884                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    885                             <td>' . $value . '</td>
     1016                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     1017                            <td>' . esc_html($value) . '</td>
    8861018                        </tr>';
    8871019                                    }
     
    8901022                                        $key_Name = str_replace('_', ' ', $key);
    8911023                                        echo '<tr>
    892                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    893                             <td>' . $value . '</td>
     1024                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     1025                            <td>' . esc_html($value) . '</td>
    8941026                        </tr>';
    8951027                                    }
     
    8981030                                        $key_Name = str_replace('_', ' ', $key);
    8991031                                        echo '<tr>
    900                             <td data-export-label="' . $key . '">' . strtoupper($key_Name) . ' :</td>
    901                             <td>' . $value . '</td>
     1032                            <td data-export-label="' . esc_attr($key) . '">' . esc_html(strtoupper($key_Name)) . ' :</td>
     1033                            <td>' . esc_html($value) . '</td>
    9021034                        </tr>';
    9031035                                    }
     
    9061038
    9071039                                    ?>
    908                                 <?php } ?>
     1040            <?php } ?>
    9091041                        </div>
    9101042                <?php
    911             }
    912 
    913             /*
     1043    }
     1044
     1045    /**
    9141046     * Renders our tabs in the plugin options page,
    9151047     * walks through the object's tabs array and prints
    9161048     * them one by one. Provides the heading for the
    9171049     * plugin_options_page method.
    918      */
    919             function newsplugin_options_tabs($current_tab)
    920             {
    921                 echo '<h2 class="nav-tab-wrapper">';
    922                 foreach ($this->plugin_settings_tabs as $tab_key => $tab_caption) {
    923                     $active = $current_tab == $tab_key ? 'nav-tab-active' : '';
    924                     echo '<a class="nav-tab ' . $active . '" href="?page=' . $this->plugin_options_key . '&tab=' . $tab_key . '">' . $tab_caption . '</a>';
    925                 }
    926                 echo '</h2>';
    927             }
    928 
    929             /**
    930              * Add link to the options page to the plugin action links.
    931              */
    932             function add_action_links($default_links)
    933             {
    934                 $links = array(
    935                     '<a href="' . admin_url('admin.php?page=news-plugin-settings') . '">Settings</a>',
    936                 );
    937                 return array_merge($links, $default_links);
    938             }
    939 
    940             /**
    941              * Render the API key settings.
    942              */
    943             function settings_api_key()
    944             {
    945                 $v = get_option('news_plugin_api_key');
    946                 echo '<input class="regular-text" name="news_plugin_api_key" id="news_plugin_api_key" type="text" size="64" value="' . esc_attr($v) . '" />';
    947                 echo '<p class="description">';
    948                 echo 'You can get it at <a href="http://my.newsplugin.com/register" target="_blank">http://my.newsplugin.com/register</a>.';
    949                 echo '</p>';
    950             }
    951 
    952             /**
    953              * Validate the API key settings.
    954              */
    955             function validate_api_key($input)
    956             {
    957                 return sanitize_text_field($input);
    958             }
    959 
    960             /**
    961              * Render the user mode settings.
    962              */
    963             function settings_user_mode()
    964             {
    965                 $v = get_option('news_plugin_user_mode');
    966                 echo '<p>';
    967                 echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_0" value="0"', ($v == 0 ? ' checked="checked"' : ''), '>';
    968                 echo '<label for="news_plugin_user_mode_0">Basic - Simple &amp; easy way to start with.</label>';
    969                 echo '<br>';
    970                 echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_1" value="1"', ($v == 1 ? ' checked="checked"' : ''), '>';
    971                 echo '<label for="news_plugin_user_mode_1">Advanced - More features for advanced users.</label>';
    972                 echo '<br>';
    973                 echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_2" value="2"', ($v == 2 ? ' checked="checked"' : ''), '>';
    974                 echo '<label for="news_plugin_user_mode_2">Expert - Manual publishing mode for professionals.</label>';
    975                 echo '</p>';
    976             }
    977 
    978             /**
    979              * Validate the user mode settings.
    980              */
    981             function validate_user_mode($input)
    982             {
    983                 $v = absint($input);
    984                 return ($v < 3 ? $v : 0);
    985             }
    986 
    987             function handle_update_system_info()
    988             {
    989                 update_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info());
    990                 $redirect = admin_url('admin.php') . '?page=news-plugin-settings&tab=newsplugin_status_settings';
    991                 wp_redirect($redirect);
    992             }
    993             function handle_save_style()
    994             {
    995                 include(plugin_dir_path(__FILE__) . 'save_style.php');
    996             }
    997             function handle_send_feedback()
    998             {
    999                 include(plugin_dir_path(__FILE__) . 'send_feedback.php');
    1000             }
     1050     *
     1051     * @param string $current_tab Current tab ID.
     1052     * @return void
     1053     */
     1054    public function newsplugin_options_tabs($current_tab)
     1055    {
     1056        echo '<h2 class="nav-tab-wrapper">';
     1057        foreach ($this->plugin_settings_tabs as $tab_key => $tab_caption) {
     1058            $active = $current_tab === $tab_key ? 'nav-tab-active' : '';
     1059            echo '<a class="nav-tab ' . esc_attr($active) . '" href="?page=' . esc_attr($this->plugin_options_key) . '&tab=' . esc_attr($tab_key) . '">' . esc_html($tab_caption) . '</a>';
    10011060        }
    1002 
    1003         // Hook ourselves into the Wordpress.
     1061        echo '</h2>';
     1062    }
     1063
     1064    /**
     1065     * Add link to the options page to the plugin action links.
     1066     *
     1067     * @param array $default_links Default links.
     1068     * @return array
     1069     */
     1070    public function add_action_links($default_links)
     1071    {
     1072        $links = [
     1073            '<a href="' . admin_url('admin.php?page=news-plugin-settings') . '">Settings</a>',
     1074        ];
     1075        return array_merge($links, $default_links);
     1076    }
     1077
     1078    /**
     1079     * Render the API key settings.
     1080     */
     1081    public function settings_api_key()
     1082    {
     1083        $v = get_option('news_plugin_api_key');
     1084        echo '<input class="regular-text" name="news_plugin_api_key" id="news_plugin_api_key" type="text" size="64" value="' . esc_attr($v) . '" />';
     1085        echo '<p class="description">';
     1086        echo 'You can get it at <a href="http://my.newsplugin.com/register" target="_blank">http://my.newsplugin.com/register</a>.';
     1087        echo '</p>';
     1088    }
     1089
     1090    /**
     1091     * Validate the API key settings.
     1092     *
     1093     * @param string $input API key.
     1094     * @return string
     1095     */
     1096    public function validate_api_key($input)
     1097    {
     1098        return sanitize_text_field($input);
     1099    }
     1100
     1101    /**
     1102     * Render the user mode settings.
     1103     */
     1104    public function settings_user_mode()
     1105    {
     1106        $v = get_option('news_plugin_user_mode');
     1107        echo '<p>';
     1108        echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_0" value="0"', ($v === 0 ? ' checked="checked"' : ''), '>';
     1109        echo '<label for="news_plugin_user_mode_0">Basic - Simple &amp; easy way to start with.</label>';
     1110        echo '<br>';
     1111        echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_1" value="1"', ($v === 1 ? ' checked="checked"' : ''), '>';
     1112        echo '<label for="news_plugin_user_mode_1">Advanced - More features for advanced users.</label>';
     1113        echo '<br>';
     1114        echo '<input type="radio" name="news_plugin_user_mode" id="news_plugin_user_mode_2" value="2"', ($v === 2 ? ' checked="checked"' : ''), '>';
     1115        echo '<label for="news_plugin_user_mode_2">Expert - Manual publishing mode for professionals.</label>';
     1116        echo '</p>';
     1117    }
     1118
     1119    /**
     1120     * Validate the user mode settings.
     1121     *
     1122     * @param int $input User mode ID (?).
     1123     * @return int
     1124     */
     1125    public function validate_user_mode($input)
     1126    {
     1127        $v = absint($input);
     1128        return ($v < 3 ? $v : 0);
     1129    }
     1130
     1131    /**
     1132     * Update stystem info
     1133     *
     1134     * @return void
     1135     */
     1136    public function handle_update_system_info()
     1137    {
     1138        update_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info());
     1139        $redirect = admin_url('admin.php') . '?page=news-plugin-settings&tab=newsplugin_status_settings';
     1140        wp_safe_redirect($redirect);
     1141    }
     1142
     1143    /**
     1144     * Save CSS styles
     1145     *
     1146     * @return void
     1147     */
     1148    public function handle_save_style()
     1149    {
     1150        include(plugin_dir_path(__FILE__) . 'save_style.php');
     1151    }
     1152
     1153    /**
     1154     * Send feedback
     1155     *
     1156     * @return void
     1157     */
     1158    public function handle_send_feedback()
     1159    {
     1160        include(plugin_dir_path(__FILE__) . 'send_feedback.php');
     1161    }
     1162}
     1163
     1164        // Hook ourselves into the WordPress.
    10041165        new News_Plugin();
    10051166
    1006                 ?>
     1167?>
  • newsplugin/trunk/readme.txt

    r2492225 r2580769  
    33Tags: news, news plugin, news feed, news feeds, newsfeed, newsfeeds, news syndication
    44Requires at least: 3.9
    5 Tested up to: 5.7
    6 Stable tag: 1.0.18
     5Tested up to: 5.8
     6Stable tag: 1.1.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7373== Changelog ==
    7474
    75 = 1.0.18 (September 18, 2020 )=
     75= 1.1.0 =
     76
     77* Vulnerability fixes:
     78    * All output should be run through an escaping function
     79    * Sanitize content
     80    * Strictly check types
     81    * Process forms with nonces
     82* Improvement: Enable plugin localization & make at least some strings localizable
     83
     84= 1.0.18 (September 18, 2020) =
    7685
    7786* Improvement: Format date & time according to WP settings
  • newsplugin/trunk/save_style.php

    r2384451 r2580769  
    11<?php
    2 if (function_exists('wp_get_current_user')) {
    3     $current_user = wp_get_current_user();
    4 } else {
    5     global $current_user;
    6     wp_get_current_user();
     2
     3/**
     4 * Save CSS styles
     5 *
     6 * @package    WordPress
     7 * @subpackage News Plugin
     8 * @since 1.0.0
     9 */
     10
     11// Verify nonce.
     12$nonce = isset($_POST['news_plugin_save_style_field']) ? sanitize_key($_POST['news_plugin_save_style_field']) : null;
     13if (! $nonce || ! wp_verify_nonce($nonce, 'news_plugin_save_style')) {
     14    die(esc_html__('4 - Security check failed. Try to submit the form once again.', 'news_plugin'));
    715}
    8 $userID = $current_user->ID;
    916
    10 $default_Value = $_POST['default_values_style'];
    11 $styleDash = array(
    12     'newsfeed_title' => array(
    13         'color'         =>  $_POST['title_color'],
    14         'size'          =>  $_POST['title_size'],
    15         'font_family'   =>  $_POST['title_font']
    16     ),
    17     'article_headline' => array(
    18         'color'         =>  $_POST['news_title_color'],
    19         'size'          =>  $_POST['news_title_size'],
    20         'font_family'   =>  $_POST['news_title_family']
    21     ),
    22     'article_abstract' => array(
    23         'color'         =>  $_POST['abstract_font_color'],
    24         'size'          =>  $_POST['abstract_font_size'],
    25         'font_family'   =>  $_POST['abstract_font_family']
    26     ),
    27     'article_date' => array(
    28         'color'         =>  $_POST['news_date_color'],
    29         'size'          =>  $_POST['news_date_size'],
    30         'font_family'   =>  $_POST['date_font']
    31     ),
    32     'article_sources' => array(
    33         'color'         =>  $_POST['source_color'],
    34         'size'          =>  $_POST['source_size'],
    35         'font_family'   =>  $_POST['source_font']
    36     )
    37 );
     17$user = wp_get_current_user();
     18$userID = $user->ID;
     19$default_Value = isset($_POST['default_values_style']) ? sanitize_key(wp_unslash($_POST['default_values_style'])) : null;
     20$styleDash = [
     21 'newsfeed_title' => [
     22      'color'         =>  isset($_POST['title_color']) ? sanitize_key(wp_unslash($_POST['title_color'])) : null,
     23     'size'          =>  isset($_POST['title_size']) ? sanitize_key(wp_unslash($_POST['title_size'])) : null,
     24      'font_family'   =>  isset($_POST['title_font']) ? sanitize_key(wp_unslash($_POST['title_font'])) : null
     25  ],
     26 'article_headline' => [
     27        'color'         =>  isset($_POST['news_title_color']) ? sanitize_key(wp_unslash($_POST['news_title_color'])) : null,
     28        'size'          =>  isset($_POST['news_title_size']) ? sanitize_key(wp_unslash($_POST['news_title_size'])) : null,
     29     'font_family'   =>  isset($_POST['news_title_family']) ? sanitize_key(wp_unslash($_POST['news_title_family'])) : null
     30 ],
     31 'article_abstract' => [
     32        'color'         =>  isset($_POST['abstract_font_color']) ? sanitize_key(wp_unslash($_POST['abstract_font_color'])) : null,
     33     'size'          =>  isset($_POST['abstract_font_size']) ? sanitize_key(wp_unslash($_POST['abstract_font_size'])) : null,
     34      'font_family'   =>  isset($_POST['abstract_font_family']) ? sanitize_key(wp_unslash($_POST['abstract_font_family'])) : null,
     35 ],
     36 'article_date' => [
     37        'color'         =>  isset($_POST['news_date_color']) ? sanitize_key(wp_unslash($_POST['news_date_color'])) : null,
     38     'size'          =>  isset($_POST['news_date_size']) ? sanitize_key(wp_unslash($_POST['news_date_size'])) : null,
     39      'font_family'   =>  isset($_POST['date_font']) ? sanitize_key(wp_unslash($_POST['date_font'])) : null,
     40 ],
     41 'article_sources' => [
     42     'color'         =>  isset($_POST['source_color']) ? sanitize_key(wp_unslash($_POST['source_color'])) : null,
     43        'size'          =>  isset($_POST['source_size']) ? sanitize_key(wp_unslash($_POST['source_size'])) : null,
     44     'font_family'   =>  isset($_POST['source_font']) ? sanitize_key(wp_unslash($_POST['source_font'])) : null,
     45 ]
     46];
     47
    3848if (isset($default_Value)) {
    39     $default_values = array(
    40         'newsfeed_title' => array(
    41             'color'         =>  '000000',
    42             'size'          =>  22,
    43             'font_family'   =>  'Times New Roman'
    44         ),
    45         'article_headline' => array(
    46             'color'         =>  '000000',
    47             'size'          =>  18,
    48             'font_family'   =>  'Times New Roman'
    49         ),
    50         'article_abstract' => array(
    51             'color'         =>  '000000',
    52             'size'          =>  14,
    53             'font_family'   =>  'Times New Roman'
    54         ),
    55         'article_date' => array(
    56             'color'         =>  '000000',
    57             'size'          =>  12,
    58             'font_family'   =>  'Times New Roman'
    59         ),
    60         'article_sources' => array(
    61             'color'         =>  '000000',
    62             'size'          =>  12,
    63             'font_family'   =>  'Times New Roman'
    64         )
    65     );
     49    $default_values = [
     50        'newsfeed_title' => [
     51            'color'         =>  '000000',
     52            'size'          =>  22,
     53    'font_family'   =>  'Times New Roman'
     54        ],
     55        'article_headline' => [
     56            'color'         =>  '000000',
     57            'size'          =>  18,
     58            'font_family'   =>  'Times New Roman'
     59        ],
     60        'article_abstract' => [
     61            'color'         =>  '000000',
     62            'size'          =>  14,
     63            'font_family'   =>  'Times New Roman'
     64        ],
     65        'article_date' => [
     66            'color'         =>  '000000',
     67            'size'          =>  12,
     68            'font_family'   =>  'Times New Roman'
     69        ],
     70        'article_sources' => [
     71            'color'         =>  '000000',
     72            'size'          =>  12,
     73            'font_family'   =>  'Times New Roman'
     74        ]
     75    ];
    6676    update_user_meta($userID, 'news_style_dashbord_style', $default_values);
    6777} else {
     
    7080
    7181$redirect = admin_url('admin.php') . '?page=news-plugin-settings&tab=newsplugin_style_settings';
    72 wp_redirect($redirect);
     82wp_safe_redirect($redirect);
     83exit();
  • newsplugin/trunk/send_feedback.php

    r2384451 r2580769  
    11<?php
    2 $to         = '[email protected]';
    3 $from           = $_POST['feed_from'];
    4 $subject        = $_POST['feed_subject'];
    5 $description        = $_POST['feed_desc'];
    6 $errors_logs        = isset($_POST['errors_logs']) ? $_POST['errors_logs'] : false;
    7 $insert_sys_info    = isset($_POST['insert_sys_info']) ? $_POST['insert_sys_info'] : false;
     2
     3/**
     4 * Send Feedback
     5 *
     6 * @package    WordPress
     7 * @subpackage News Plugin
     8 * @since 1.0.0
     9 */
     10
     11// Verify nonce.
     12$nonce = isset($_POST['news_plugin_send_feedback_field']) ? sanitize_key($_POST['news_plugin_send_feedback_field']) : null;
     13if (!$nonce || !wp_verify_nonce($nonce, 'news_plugin_send_feedback')) {
     14    die(esc_html__('5 - Security check failed. Try to submit the form once again.', 'news_plugin'));
     15}
     16
     17$to         = '[email protected]';
     18$from           = isset($_POST['feed_from']) ? sanitize_text_field(wp_unslash($_POST['feed_from'])) : '';
     19$subject        = isset($_POST['feed_subject']) ? sanitize_text_field(wp_unslash($_POST['feed_subject'])) : '';
     20$description        = isset($_POST['feed_desc']) ? sanitize_text_field(wp_unslash($_POST['feed_desc'])) : '';
     21$errors_logs        = isset($_POST['errors_logs']) ? sanitize_text_field(wp_unslash($_POST['errors_logs'])) : false;
     22$insert_sys_info    = isset($_POST['insert_sys_info']) ? sanitize_text_field(wp_unslash($_POST['insert_sys_info'])) : false;
    823
    924if (!$from) {
    10     if ($user_info = News_Plugin_Utils::get_user_info()) {
     25    $user_info = News_Plugin_Utils::get_user_info();
     26    if ($user_info) {
    1127        $from = $user_info->email;
    1228    }
     
    2339
    2440if (isset($errors_logs)) {
    25 
    2641    $message .= "<tr style='background: #eee;'><strong>Errors on plugin :</strong></tr>\n";
    2742    $message .= '<tr><p>' . $errors_logs . '</p></tr>' . "\n";
    2843}
    2944
    30 // if(isset($insert_sys_info)) {
    31 
    32 // $results = get_option( 'newsPlugin_system_info' );
    33 $results = News_Plugin_Utils::get_system_info(); // Always get fresh
    34 $message .= "<tr style='background: #eee;'><td cellspan='2'><strong>WORDPRESS ENVIRONMENT :</strong></td></tr>\n";
     45$results = News_Plugin_Utils::get_system_info(); // Always get fresh.
     46$message .= "<tr style='background: #eee;'><td cellspan='2'><strong>WordPress ENVIRONMENT :</strong></td></tr>\n";
    3547foreach ($results['wordpress_env'] as $key => $value) {
    36 
    3748    $key_Name = str_replace('_', ' ', $key);
    3849    $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n";
     
    4051$message .= "<tr style='background: #eee;'><td cellspan='2'><strong>SYSTEM ENVIRONMENT :</strong></td></tr>\n";
    4152foreach ($results['system_env'] as $key => $value) {
    42 
    4353    $key_Name = str_replace('_', ' ', $key);
    4454    $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n";
     
    4656$message .= "<tr style='background: #eee;'><td cellspan='2'><strong>NEWSPLUGIN ENVIRONMENT :</strong></td></tr>\n";
    4757foreach ($results['newsplugin_env'] as $key => $value) {
    48 
    4958    $key_Name = str_replace('_', ' ', $key);
    5059    $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n";
    5160}
    52 // }
    5361
    5462$message .= '</tbody>';
     
    5664$message .= "</body></html>";
    5765
     66/**
     67 * Set content type helper
     68 *
     69 * @return string
     70 */
    5871function news_plugin_wp_set_content_type()
    5972{
     
    6174}
    6275add_filter('wp_mail_content_type', 'news_plugin_wp_set_content_type');
     76
    6377$headers .= news_plugin_wp_set_content_type();
    6478
     
    7185
    7286remove_filter('wp_mail_content_type', 'news_plugin_wp_set_content_type');
    73 wp_redirect($redirect);
     87wp_safe_redirect($redirect);
     88exit();
Note: See TracChangeset for help on using the changeset viewer.