Changeset 2580769
- Timestamp:
- 08/10/2021 09:51:14 AM (5 years ago)
- Location:
- newsplugin
- Files:
-
- 8 added
- 12 edited
- 1 copied
-
tags/1.1.0 (copied) (copied from newsplugin/trunk)
-
tags/1.1.0/.editorconfig (added)
-
tags/1.1.0/composer.json (added)
-
tags/1.1.0/composer.lock (added)
-
tags/1.1.0/news-plugin-utils.php (modified) (24 diffs)
-
tags/1.1.0/news-plugin-widget.php (modified) (47 diffs)
-
tags/1.1.0/news-plugin.php (modified) (41 diffs)
-
tags/1.1.0/phpcs.xml.dist (added)
-
tags/1.1.0/readme.txt (modified) (2 diffs)
-
tags/1.1.0/save_style.php (modified) (2 diffs)
-
tags/1.1.0/send_feedback.php (modified) (7 diffs)
-
trunk/.editorconfig (added)
-
trunk/composer.json (added)
-
trunk/composer.lock (added)
-
trunk/news-plugin-utils.php (modified) (24 diffs)
-
trunk/news-plugin-widget.php (modified) (47 diffs)
-
trunk/news-plugin.php (modified) (41 diffs)
-
trunk/phpcs.xml.dist (added)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/save_style.php (modified) (2 diffs)
-
trunk/send_feedback.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
newsplugin/tags/1.1.0/news-plugin-utils.php
r2384451 r2580769 1 1 <?php 2 3 /** 4 * Utils 5 * 6 * @package WordPress 7 * @subpackage News Plugin 8 * @since 1.0.0 9 */ 2 10 3 11 // Prevent ourselves from being run directly. … … 5 13 6 14 if (!function_exists('json_last_error_msg')) { 15 16 /** 17 * Get error message 18 * 19 * @return string 20 */ 7 21 function json_last_error_msg() 8 22 { 9 static $ERRORS = array(23 static $ERRORS = [ 10 24 JSON_ERROR_NONE => 'No error', 11 25 JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', … … 14 28 JSON_ERROR_SYNTAX => 'Syntax error', 15 29 JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded' 16 );30 ]; 17 31 18 32 $error = json_last_error(); … … 21 35 } 22 36 37 /** 38 * Utils 39 * 40 * @package News Plugin 41 */ 23 42 class 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() 29 58 { 30 59 if (self::$np_version) { 31 60 return (self::$np_version); 32 61 } 62 // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found 33 63 if (self::$np_version = get_option('news_plugin_version')) { 34 64 return (self::$np_version); … … 37 67 } 38 68 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() 40 75 { 41 76 if (!function_exists('get_plugin_data')) { … … 49 84 } 50 85 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) 52 93 { 53 94 global $wp_version; … … 56 97 } 57 98 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) 59 108 { 60 109 if (!function_exists('curl_version')) { 61 return ( array('', 'Error: CURL disabled or not installed'));110 return (['', 'Error: CURL disabled or not installed']); 62 111 } 63 112 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']); 65 114 } 66 115 $ch = curl_init($url); … … 75 124 } 76 125 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) 81 136 { 82 137 if (!function_exists('stream_socket_client')) { 83 return ( array('', 'Error: Socket disabled'));138 return (['', 'Error: Socket disabled']); 84 139 } 85 140 $aURL = parse_url($url); 86 141 $addr = $aURL['host']; 87 $secure_transport = ($aURL['scheme'] == 'ssl' || $aURL['scheme']== 'https');142 $secure_transport = ($aURL['scheme'] === 'ssl' || $aURL['scheme'] === 'https'); 88 143 if (!isset($aURL['port'])) { 89 144 if ($secure_transport) { … … 100 155 $socket = stream_socket_client($proto . $addr . ':' . $aURL['port'], $errno, $errorMessage, 10, STREAM_CLIENT_CONNECT); 101 156 if ($socket === false) { 102 return ( array('', 'Socket error: ' . $errorMessage));157 return (['', 'Socket error: ' . $errorMessage]); 103 158 } 104 159 $url = $aURL['path']; … … 113 168 fclose($socket); 114 169 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) 121 183 { 122 184 if ((!$ret[1]) && (!preg_match('/var swfobject=function()/s', $ret[0]))) { … … 127 189 } 128 190 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() 132 205 { 133 206 $ret = self::http_remote_get_curl(self::$test_url); … … 135 208 } 136 209 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() 138 217 { 139 218 $ret = self::http_remote_get_socket(self::$test_url); … … 141 220 } 142 221 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() 146 236 { 147 237 $ret = self::http_remote_get_curl(self::$test_url_ssl); … … 149 239 } 150 240 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() 152 248 { 153 249 $ret = self::http_remote_get_socket(self::$test_url_ssl); … … 155 251 } 156 252 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) 161 274 { 162 275 $output = $var[0]; … … 174 287 } 175 288 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() 177 295 { 178 296 $var = self::http_remote_get_curl(self::$api_root . self::$api_ping_path); … … 180 298 } 181 299 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() 183 306 { 184 307 $var = self::http_remote_get_socket(self::$api_root . self::$api_ping_path); … … 186 309 } 187 310 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) 189 319 { 190 320 switch ($method) { 191 321 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')]); 193 323 if (is_array($ret)) { 194 return ( array($ret['body'], ''));324 return ([$ret['body'], '']); 195 325 } 196 326 $ret = self::generic_remote_get($url, 'curl'); … … 209 339 } 210 340 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) 212 349 { 213 350 $key = get_option('news_plugin_api_key'); 214 $args = $args ? $args : array();351 $args = $args ? $args : []; 215 352 $args['k'] = $key; 216 353 $url = self::$api_root . $path; … … 219 356 $ret = self::generic_remote_get($url, $method ? $method : 'wp'); 220 357 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 222 360 $backtrace = debug_backtrace(); 361 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log 223 362 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); 225 364 } 226 365 return (json_decode($ret[0])); 227 366 } 228 367 229 static function get_user_info() 368 /** 369 * Get user info 370 * 371 * @return mixed 372 */ 373 public static function get_user_info() 230 374 { 231 375 return (self::generic_api_call('user_info')); 232 376 } 233 377 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() 235 383 { 236 384 return (1.0002); 237 385 } 238 386 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; 242 395 243 396 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 ([ 249 403 'mysql_method' => 'mysqli', 250 404 'mysql_server_info' => mysqli_get_server_info($wpdb->dbh), 251 405 'mysql_client_info' => mysqli_get_client_info($wpdb->dbh), 252 406 'mysql_proto_info' => mysqli_get_proto_info($wpdb->dbh), 253 ));407 ]); 254 408 } else { 255 return ( array(409 return ([ 256 410 'mysql_method' => 'mysql', 411 // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved 257 412 'mysql_server_info' => mysql_get_server_info(), 413 // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved 258 414 'mysql_client_info' => mysql_get_client_info(), 415 // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved 259 416 '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() 265 427 { 266 428 $my_theme = wp_get_theme(); … … 285 447 $db_info = self::get_system_db_info(); 286 448 287 $system_info = array(449 $system_info = [ 288 450 'info_version' => self::get_system_info_version(), 289 451 'api_key' => get_option('news_plugin_api_key'), /* We need to refresh on api key change ... */ 290 'wordpress_env' => array(452 'wordpress_env' => [ 291 453 'siteurl' => get_bloginfo('url'), 292 454 'version' => get_bloginfo('version'), … … 296 458 'theme_version' => $my_theme->get('Version'), 297 459 'theme_AuthorURI' => $my_theme->get('AuthorURI'), 298 ),299 'system_env' => array(460 ], 461 'system_env' => [ 300 462 '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, 302 464 '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, 308 470 'memory_limit' => ini_get('memory_limit'), 309 471 'execution_time' => ini_get('max_execution_time'), … … 320 482 'socket_status' => $socket_test[1] ? $socket_test[1] : 'OK', 321 483 'socket_status_ssl' => $socket_test_ssl[1] ? $socket_test_ssl[1] : 'OK', 322 ),323 'newsplugin_env' => array(484 ], 485 'newsplugin_env' => [ 324 486 'REGISTERED EMAIL' => $user_info ? $user_info->email : 'error or unregistered', 325 487 'USER STATUS' => $user_info ? $user_info->status : 'error or unregistered', … … 327 489 'curl_ping' => $curl_ping[1] ? $curl_ping[1] : ('OK from ' . $curl_ping[0]->client), 328 490 '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]) { 332 494 unset($system_info['system_env']['curl_status_ssl']); 333 495 } 334 if ($socket_test[1] == $socket_test_ssl[1]) {496 if ($socket_test[1] === $socket_test_ssl[1]) { 335 497 unset($system_info['system_env']['socket_status_ssl']); 336 498 } -
newsplugin/tags/1.1.0/news-plugin-widget.php
r2384451 r2580769 1 1 <?php 2 3 /** 4 * Widget 5 * 6 * @package WordPress 7 * @subpackage News Plugin 8 * @since 1.0.0 9 */ 2 10 3 11 // Prevent ourselves from being run directly. … … 13 21 * Register widget with WordPress. 14 22 */ 15 function __construct()23 public function __construct() 16 24 { 17 25 parent::__construct( 18 26 'news_plugin_widget', 19 27 __('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'),] 21 29 ); 22 30 } … … 40 48 private function current_options() 41 49 { 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()] : []; 44 52 return $opts; 45 53 } … … 47 55 /** 48 56 * Update the private options specific for this widget. 57 * 58 * @param mixed $args Arguments. 59 * @return mixed 49 60 */ 50 61 private function update_options($args) 51 62 { 52 $opts = get_option('news_plugin_widget_options', array());63 $opts = get_option('news_plugin_widget_options', []); 53 64 $opts[$this->widget_id()] = $args; 54 65 update_option('news_plugin_widget_options', $opts); … … 62 73 { 63 74 $opts = $this->current_options(); 64 $posts = (isset($opts['excluded'])) ? $opts['excluded'] : array();75 $posts = (isset($opts['excluded'])) ? $opts['excluded'] : []; 65 76 return $posts; 66 77 } … … 68 79 /** 69 80 * Add given id to the list of excluded posts. 81 * 82 * @param int $id ID. 83 * @param int $limit Limit. 84 * @return array 70 85 */ 71 86 private function exclude_post($id, $limit = 100) … … 86 101 { 87 102 $opts = $this->current_options(); 88 $posts = array();103 $posts = []; 89 104 $opts['excluded'] = $posts; 90 105 $this->update_options($opts); … … 98 113 { 99 114 $opts = $this->current_options(); 100 $posts = (isset($opts['favorite'])) ? $opts['favorite'] : array();115 $posts = (isset($opts['favorite'])) ? $opts['favorite'] : []; 101 116 return $posts; 102 117 } … … 104 119 /** 105 120 * Add given id to the list of favorite posts. 121 * 122 * @param int $id ID. 123 * @param int $limit Limit. 124 * @return array 106 125 */ 107 126 private function star_favorite_post($id, $limit = 100) … … 118 137 /** 119 138 * Remove given id from the list of favorite posts. 139 * 140 * @param int $id ID. 141 * @return mixed 120 142 */ 121 143 private function unstar_favorite_post($id) … … 123 145 $opts = $this->current_options(); 124 146 $posts = $this->favorite_posts(); 125 $posts = array_diff($posts, array($id));147 $posts = array_diff($posts, [$id]); 126 148 $opts['favorite'] = $posts; 127 149 $this->update_options($opts); … … 135 157 { 136 158 $opts = $this->current_options(); 137 $posts = array();159 $posts = []; 138 160 $opts['favorite'] = $posts; 139 161 $this->update_options($opts); … … 152 174 /** 153 175 * Set the timestamp of the last publishing in manual publishing mode. 176 * 177 * @param int $time Timestamp. 178 * @return mixed 154 179 */ 155 180 private function update_publish_time($time) … … 163 188 /** 164 189 * 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 165 194 */ 166 195 private function create_action_args($action, $arg = 0) 167 196 { 168 return array(197 return [ 169 198 'news_plugin_instance' => $this->widget_id(), 170 199 'news_plugin_action' => $action, 171 200 'news_plugin_arg' => $arg, 172 ); 201 '_wpnonce' => wp_create_nonce('news_plugin_url_nonce'), 202 ]; 173 203 } 174 204 … … 178 208 private function parse_action_args() 179 209 { 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 ]; 187 223 } 188 224 … … 220 256 private function edit_mode_enabled() 221 257 { 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 222 264 if (isset($_GET['news_plugin_action'])) { 223 $action = $_GET['news_plugin_action'];265 $action = sanitize_key(wp_unslash($_GET['news_plugin_action'])); 224 266 return !empty($action); 225 267 } … … 228 270 /** 229 271 * Manage the feed as necessary. 272 * 273 * @param mixed $opts Options. 274 * @return void 230 275 */ 231 276 private function manage($opts) 232 277 { 233 278 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; 261 301 } 262 302 } … … 264 304 /** 265 305 * 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() 268 310 { 269 311 return 3600; … … 272 314 /** 273 315 * 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 274 321 */ 275 322 private function get_feed($time, $opts, $limit = 100) … … 277 324 $key = get_option('news_plugin_api_key'); 278 325 279 $args = array(326 $args = [ 280 327 'k' => $key, 281 328 'q' => $opts['keywords'], … … 283 330 'c' => $opts['count'], 284 331 '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') { 291 338 if (!($this->can_manage() && $this->edit_mode_enabled())) { 292 339 $time = $this->publish_time(); … … 328 375 329 376 // 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']; 331 378 add_filter('wp_feed_cache_transient_lifetime', $cache_filter); 332 379 $feed = fetch_feed($url); 333 380 remove_filter('wp_feed_cache_transient_lifetime', $cache_filter); 334 381 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 */ 338 392 private function compute_style_helper($style, $type) 339 393 { … … 343 397 $ret = ''; 344 398 if ($style[$type]['size']) { 345 $ret .= 'font-size: ' . $style[$type]['size'] . 'px;';399 $ret .= 'font-size:' . $style[$type]['size'] . 'px;'; 346 400 } 347 401 if ($style[$type]['color']) { … … 351 405 $ret .= 'font-family:' . $style[$type]['font_family'] . ';'; 352 406 } 353 if (!$ret) { 354 return ($ret); 355 } 356 return (' style="' . $ret . '"'); 407 if ($ret) { 408 return ' style=' . $ret ; 409 } 357 410 } 358 411 … … 370 423 371 424 if (!isset($rss)) { 372 _e('Feed fetch failed ', 'news_plugin');425 esc_html_e('Feed fetch failed ', 'news_plugin'); 373 426 return; 374 427 } 375 428 376 $manual_mode = ($opts['feed_mode'] == 'manual');429 $manual_mode = ($opts['feed_mode'] === 'manual'); 377 430 378 431 $exclude = array_fill_keys($this->excluded_posts(), true); … … 393 446 $args = $this->create_action_args('reset'); 394 447 echo '<a href="' . esc_attr(add_query_arg($args)) . '">'; 395 e cho 'Reset';448 esc_html_e('Reset', 'news_plugin'); 396 449 echo '</a>'; 397 450 … … 400 453 echo ' | '; 401 454 echo '<a href="' . esc_attr(add_query_arg($args)) . '">'; 402 e cho 'Publish Headlines';455 esc_html_e('Publish Headlines', 'news_plugin'); 403 456 echo '</a>'; 404 457 } 405 458 406 $args = $this->create_action_args( NULL, NULL);459 $args = $this->create_action_args(null, null); 407 460 echo ' | '; 408 461 echo '<a href="' . esc_attr(add_query_arg($args)) . '">'; 409 e cho 'Leave Edit Newsfeed Mode';462 esc_html_e('Leave Edit Newsfeed Mode', 'news_plugin'); 410 463 echo '</a>'; 411 464 … … 415 468 echo '<p class="news-plugin-edit-buttons">'; 416 469 echo '<a href="' . esc_attr(add_query_arg($args)) . '">'; 417 e cho 'Edit Newsfeed Mode';470 esc_html_e('Edit Newsfeed Mode', 'news_plugin'); 418 471 echo '</a>'; 419 472 } … … 421 474 if ($manual_mode) { 422 475 $t = $this->publish_time(); 423 if ($t == 0) {476 if ($t === 0) { 424 477 if ($this->edit_mode_enabled()) { 425 478 echo '<p>'; 426 e cho 'No headlines published yet.';479 esc_html_e('No headlines published yet.', 'news_plugin'); 427 480 echo '</p>'; 428 481 } else { 429 482 echo '<p>'; 430 e cho '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'); 431 484 echo '</p>'; 432 485 } 433 486 } else { 434 $t = date('d M Y H:i', $t); 487 // TODO localize properly. 488 $t = gmdate('d M Y H:i', $t); 435 489 echo '<p>'; 436 echo "Headlines last published on {$t}."; 490 // TODO localize properly. 491 echo esc_html("Headlines last published on {$t}."); 437 492 echo '</p>'; 438 493 } … … 442 497 if ($manual_mode) { 443 498 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. 445 502 echo ' You can <span style="font-size:110%;">☆</span> Star individual headlines to move them to the top or ✕ Remove them from the feed. Click Reset to undo these changes.'; 446 e cho ' 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'); 447 504 echo '</p>'; 448 505 } else { 449 506 echo '<p>'; 507 // TODO localize properly. 450 508 echo 'You can <span style="font-size:110%;">☆</span> Star individual headlines to move them to the top or ✕ Remove them from the feed. Click Reset to undo these changes.'; 451 509 echo '</p>'; … … 460 518 $index = 0; 461 519 462 if ($opts['wp_uid'] && (intval($opts['wp_uid']) != 0)) {520 if ($opts['wp_uid'] && (intval($opts['wp_uid']) !== 0)) { 463 521 $userID = intval($opts['wp_uid']); 464 522 } else { … … 479 537 } 480 538 481 if (!empty($favorite[$id]) xor ($pass == 0)) {539 if (!empty($favorite[$id]) xor ($pass === 0)) { 482 540 continue; 483 541 } 484 542 485 if ($index == $limit) {543 if ($index === $limit) { 486 544 echo '<hr>'; 487 545 } 488 546 489 547 echo '<li>'; 490 if ($opts['link_follow'] == 'no') {548 if ($opts['link_follow'] === 'no') { 491 549 $s_follow = ' rel="nofollow"'; 492 550 } else { … … 498 556 $s_target = ''; 499 557 } 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) . '>'; 501 559 $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) . '>'; 503 561 echo esc_html($item->get_title()); 504 562 echo '</span>'; … … 507 565 echo "\n"; 508 566 $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) . '>'; 510 568 echo esc_html($item->get_date(get_option('date_format') . ' ' . get_option('time_format'))); 511 569 echo '</span>'; … … 513 571 if ($opts['show_source']) { 514 572 // Because RSS doesn't support the source field, we use the author field. 515 // $source = $item->get_source() ;516 573 $source = $item->get_author(); 517 if ($source) $source = $source->get_email(); 574 if ($source) { 575 $source = $source->get_email(); 576 } 518 577 if (!empty($source)) { 519 578 echo "\n"; 520 579 $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) . '>'; 522 581 echo esc_html($source); 523 582 echo '</span>'; … … 527 586 echo "\n"; 528 587 $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) . '>'; 530 589 echo esc_html($item->get_description()); 531 590 echo '</span>'; … … 535 594 $args = $this->create_action_args('exclude', $id); 536 595 echo ' <a href="' . esc_attr(add_query_arg($args)) . '">'; 537 // echo 'X' ;538 596 echo '<span style="text-decoration: underline;">'; 539 597 echo '✕ Remove'; … … 543 601 $args = $this->create_action_args('unstar', $id); 544 602 echo ' <a href="' . esc_attr(add_query_arg($args)) . '">'; 545 // echo '-' ;546 603 echo '<span style="text-decoration: underline;">'; 547 604 echo '<span style="font-size:110%;">★</span> Unstar'; … … 551 608 $args = $this->create_action_args('star', $id); 552 609 echo ' <a href="' . esc_attr(add_query_arg($args)) . '">'; 553 // echo '+' ;554 610 echo '<span style="text-decoration: underline;">'; 555 611 echo '<span style="font-size:110%;">☆</span> Star'; … … 565 621 } 566 622 echo '</ul>'; 567 568 //Error in Option Page569 // newserroforwp_log("NewsPlugin Option Page");570 623 } 571 624 … … 589 642 if (empty($key)) { 590 643 if ($this->can_manage()) { 591 ?>644 ?> 592 645 <p> 593 Your feed is currently inactive.594 Please enter your Activation Key on the595 <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'); ?>. 597 650 </p> 598 <?php651 <?php 599 652 } 600 653 return; … … 607 660 $title = apply_filters('widget_title', $opts['title']); 608 661 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 } 612 666 $this->content($opts); 613 echo $args['after_widget'];667 echo wp_kses_post($args['after_widget']); 614 668 } 615 669 … … 627 681 ?> 628 682 <p> 629 Please enter your Activation Key on the630 <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'); ?> 632 686 </p> 633 <?php687 <?php 634 688 return; 635 689 } … … 726 780 727 781 // Force expert user mode for now. 728 // $user_mode = get_option( 'news_plugin_user_mode' ) ;782 // $user_mode = get_option( 'news_plugin_user_mode' ); . 729 783 $user_mode = 2; 730 784 731 785 ?> 732 786 <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); ?>"> 735 789 <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> 737 791 <br> 738 <small> Example: Canada Solar Energy News</small>792 <small><?php esc_html_e('Example: Canada Solar Energy News', 'news_plugin'); ?></small> 739 793 </p> 740 794 <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); ?>"> 743 797 <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> 745 799 <br> 746 <small> Example: canada & "solar energy"</small>800 <small><?php esc_html_e('Example: canada & "solar energy"', 'news_plugin'); ?></small> 747 801 <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> 749 803 </p> 750 804 <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); ?>"> 753 807 <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> 755 809 <br> 756 <small> Example: 10</small>810 <small><?php esc_html_e('Example: 10', 'news_plugin'); ?></small> 757 811 </p> 758 812 <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> 761 817 </p> 762 818 <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> 765 823 </p> 766 824 <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> 769 829 <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> 771 831 <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> 773 833 </p> 774 834 <?php 775 835 if ($user_mode > 0) { 776 777 836 /* 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 ?> 797 856 <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 & 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 & Full Text', 'news_plugin'); ?></option> 803 866 </select> 804 867 <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> 806 869 </p> 807 870 808 871 <?php 809 872 /* 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 */ 822 885 ?> 823 886 824 887 <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> 830 897 </select> 831 898 <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> 833 900 </p> 834 901 <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); ?>"> 837 904 <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> 839 906 </p> 840 907 <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> 846 917 </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> 852 927 </select> 853 928 854 929 <?php 855 856 930 /* 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 */ 871 945 872 946 ?> … … 876 950 ?> 877 951 <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> 883 961 </select> 884 962 <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> 886 964 </p> 887 <?php965 <?php 888 966 } 889 967 } … … 901 979 public function update($new_opts, $old_opts) 902 980 { 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']) : ''; 906 984 $opts['count'] = (!empty($new_opts['count'])) ? absint($new_opts['count']) : 5; 907 985 $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']) : ''; 916 994 $opts['show_date'] = !empty($new_opts['show_date']); 917 995 $opts['show_source'] = !empty($new_opts['show_source']); 918 996 $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']) : ''; 920 998 $opts['wp_uid'] = (!isset($new_opts['wp_uid']) || empty($new_opts['wp_uid'])) ? get_current_user_id() : $new_opts['wp_uid']; 921 999 … … 923 1001 } 924 1002 } 925 ?>1003 ?> -
newsplugin/tags/1.1.0/news-plugin.php
r2384451 r2580769 1 1 <?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 */ 10 17 11 18 // Prevent ourselves from being run directly. … … 27 34 * Register plugin with WordPress. 28 35 */ 29 function __construct() 30 { 36 public function __construct() 37 { 38 39 add_action('init', [$this, 'localize']); 40 31 41 // 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']); 55 65 $usc = get_option('newsPlugin_system_info'); 56 66 $api_key = get_option('news_plugin_api_key'); … … 58 68 !$usc || 59 69 !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) 61 71 ) { 62 72 update_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info()); … … 64 74 } 65 75 66 function userSystemCheck_create() 76 /** 77 * Do on user system check creation 78 * 79 * @return void 80 */ 81 public function userSystemCheck_create() 67 82 { 68 83 add_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info()); 69 84 add_option('news_plugin_url_method', false); 70 85 } 71 function userSystemCheck_deactivation() 86 87 /** 88 * Do on system check deactivation 89 * 90 * @return void 91 */ 92 public function userSystemCheck_deactivation() 72 93 { 73 94 delete_option('newsPlugin_system_info'); 74 95 } 75 96 76 function refresh_plugin_version() 97 /** 98 * Refresh plugin version 99 * 100 * @return void 101 */ 102 public function refresh_plugin_version() 77 103 { 78 104 if (function_exists('get_plugin_data')) { … … 86 112 87 113 /** 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 /** 88 124 * Register the plugin widget, widget areas and widget shorcodes. 89 125 */ 90 function widgets_init()126 public function widgets_init() 91 127 { 92 128 register_widget('News_Plugin_Widget'); 93 129 for ($area = 1; $area <= 4; $area++) { 94 register_sidebar( array(130 register_sidebar([ 95 131 'name' => "NewsPlugin Widget Area {$area}", 96 132 'id' => "newsplugin_widgets_{$area}", … … 98 134 'before_widget' => '<div id="%1$s" class="widget %2$s">', 99 135 'after_widget' => '</div>' 100 ));136 ]); 101 137 } 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']); 104 140 } 105 141 106 142 /** 107 143 * 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); 112 151 $sidebar = "newsplugin_widgets_{$a['area']}"; 113 152 ob_start(); … … 121 160 122 161 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=""] 124 163 125 164 /** 126 165 * 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([ 131 173 'id' => '', 132 174 'title' => '', … … 147 189 'feed_mode' => '', 148 190 'wp_uid' => '' 149 ), $attrs);191 ], $attrs); 150 192 $newswid = new News_Plugin_Widget(); 151 $a = $newswid->update($attrs, array());193 $a = $newswid->update($attrs, []); 152 194 $a['id'] = $attrs['id']; 153 195 ob_start(); 154 the_widget('News_Plugin_Widget', $a, array());196 the_widget('News_Plugin_Widget', $a, []); 155 197 return ob_get_clean(); 156 198 } … … 159 201 * Register the plugin CSS style. 160 202 */ 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"); 164 206 wp_enqueue_style('news-plugin'); 165 207 } 166 208 167 function register_admin_scripts() 209 /** 210 * Register admin scripts 211 * 212 * @return void 213 */ 214 public function register_admin_scripts() 168 215 { 169 216 $assets_path = plugin_dir_url(__FILE__) . 'assets/'; 217 // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion 170 218 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); 172 221 } 173 222 … … 175 224 * Register the plugin options. 176 225 */ 177 function admin_init()226 public function admin_init() 178 227 { 179 228 add_settings_section( 180 229 'default', 181 NULL,182 NULL,230 null, 231 null, 183 232 'news-plugin-settings' 184 233 ); … … 187 236 'news_plugin_api_key', 188 237 __('Activation Key:', 'news_plugin'), 189 array($this, 'settings_api_key'),238 [$this, 'settings_api_key'], 190 239 'news-plugin-settings', 191 240 'default' … … 194 243 'news-plugin-settings', 195 244 'news_plugin_api_key', 196 array($this, 'validate_api_key')245 [$this, 'validate_api_key'] 197 246 ); 198 247 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 */ 213 263 } 214 264 … … 216 266 * Register the plugin menu. 217 267 */ 218 function admin_menu()268 public function admin_menu() 219 269 { 220 270 add_menu_page( … … 223 273 'manage_options', 224 274 'news-plugin-settings', 225 array($this, 'newsplugin_options_page'),275 [$this, 'newsplugin_options_page'], 226 276 'dashicons-megaphone', 227 277 '3' 228 278 ); 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']); 230 280 } 231 281 … … 235 285 * when registering settings 236 286 */ 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 */ 238 298 private $feed_settings_key = 'newsplugin_feed_settings'; 299 /** 300 * Key - style 301 * 302 * @var string 303 */ 239 304 private $style_settings_key = 'newsplugin_style_settings'; 305 /** 306 * Key - activation 307 * 308 * @var string 309 */ 240 310 private $activation_settings_key = 'newsplugin_activation_settings'; 311 /** 312 * Key - shortcode 313 * 314 * @var string 315 */ 241 316 private $shortcode_settings_key = 'newsplugin_shortcode_settings'; 317 /** 318 * Key - help 319 * 320 * @var string 321 */ 242 322 private $help_settings_key = 'newsplugin_help_settings'; 323 /** 324 * Key - key 325 * 326 * @var string 327 */ 243 328 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() 250 342 { 251 343 $this->plugin_settings_tabs[$this->status_settings_key] = 'Server Information'; 252 344 } 253 function register_feed_section() 345 /** 346 * Registering the sections - feed 347 * 348 * @return void 349 */ 350 public function register_feed_section() 254 351 { 255 352 $this->plugin_settings_tabs[$this->feed_settings_key] = 'Send Feedback'; 256 353 } 257 function register_style_section() 354 /** 355 * Registering the sections - style 356 * 357 * @return void 358 */ 359 public function register_style_section() 258 360 { 259 361 $this->plugin_settings_tabs[$this->style_settings_key] = 'Customize Styles'; 260 362 } 261 function register_activation_section() 363 /** 364 * Registering the sections - activation 365 * 366 * @return void 367 */ 368 public function register_activation_section() 262 369 { 263 370 $this->plugin_settings_tabs[$this->activation_settings_key] = 'Activate NewsPlugin'; 264 371 } 265 function register_shortcode_section() 372 /** 373 * Registering the sections - shortcode 374 * 375 * @return void 376 */ 377 public function register_shortcode_section() 266 378 { 267 379 $this->plugin_settings_tabs[$this->shortcode_settings_key] = 'Generate Shortcode'; 268 380 } 269 function register_help_section() 381 /** 382 * Registering the sections - help 383 * 384 * @return void 385 */ 386 public function register_help_section() 270 387 { 271 388 $this->plugin_settings_tabs[$this->help_settings_key] = 'Instructions!'; 272 389 } 273 390 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 */ 276 403 if (!is_array($arr)) { 277 404 return $def; … … 286 413 } 287 414 288 /* 415 /** 289 416 * Plugin Options page rendering goes here, checks 290 417 * for active tab and replaces key with the related 291 418 * settings key. Uses the plugin_options_tabs method 292 419 * 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 ?> 298 429 <div class="wrap"> 299 430 <h2>NewsPlugin Settings</h2> … … 302 433 if (empty($key)) { ?> 303 434 <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> 305 436 </div> 306 437 <?php } ?> … … 312 443 <?php submit_button(); ?> 313 444 </form> 314 <?php } else if ($tab === $this->shortcode_settings_key && !empty($key)) { ?>445 <?php } elseif ($tab === $this->shortcode_settings_key && !empty($key)) { ?> 315 446 <table id="shortcodeTable" class="form-table"> 316 447 <tr> … … 546 677 shortcode_params += " age='" + newsplugin_age + "'"; 547 678 } 548 shortcode_params += " wp_uid='<?php echo get_current_user_id(); ?>'";679 shortcode_params += " wp_uid='<?php echo esc_attr(get_current_user_id()); ?>'"; 549 680 var html = "<p>Press Ctrl+C to copy to clipboard and paste it in your posts or pages.</p>"; 550 681 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>"; … … 555 686 } 556 687 </script> 557 <?php } else if ($tab === $this->help_settings_key) { ?>688 <?php } elseif ($tab === $this->help_settings_key) { ?> 558 689 <h3>Instructions</h3> 559 690 <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 > 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 > 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> 562 693 <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> 563 694 <h3>Support</h3> … … 569 700 $style_news = get_user_meta($userID, 'news_style_dashbord_style', 'true'); 570 701 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> 575 706 <div class="news-row-style"> 576 707 <div class="style_left"> 577 708 <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'); ?> 578 710 <input type="hidden" name="action" value="news_plugin_save_style"> 579 711 <h3>Newsfeed Title</h3> 580 712 <h4>Color</h4> 581 713 <?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>'; 583 715 echo '<h4>Size</h4>'; 584 716 echo '<select name="title_size" id="title_size">'; 585 717 $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>'; 587 719 for ($i = 10; $i <= 50; $i++) { 588 if ($i == $v) {720 if ($i === $v) { 589 721 } else { 590 echo '<option value="' . $i . '">' . $i. '</option>';722 echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; 591 723 } 592 724 } … … 595 727 echo '<select name="title_font" id="title_font">'; 596 728 $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>'; 598 730 if ($v) { 599 731 echo '<option value="">Unchanged (theme default)</option>'; 600 732 } 601 733 foreach ($font_family as $fonts) { 602 if ($fonts == $v) {734 if ($fonts === $v) { 603 735 } else { 604 echo '<option value="' . $fonts . '">' . $fonts. '</option>';736 echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>'; 605 737 } 606 738 } … … 608 740 echo '<h3>Article Headline</h3>'; 609 741 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>'; 611 743 echo '<h4>Size</h4>'; 612 744 echo '<select name="news_title_size" id="news_title_size">'; 613 745 $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>'; 615 747 for ($i = 10; $i <= 50; $i++) { 616 if ($i == $v) {748 if ($i === $v) { 617 749 } else { 618 echo '<option value="' . $i . '">' . $i. '</option>';750 echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; 619 751 } 620 752 } … … 623 755 echo '<select name="news_title_family" id="news_title_family">'; 624 756 $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>'; 626 758 if ($v) { 627 759 echo '<option value="">Unchanged (theme default)</option>'; 628 760 } 629 761 foreach ($font_family as $fonts) { 630 if ($fonts == $v) {762 if ($fonts === $v) { 631 763 } else { 632 echo '<option value="' . $fonts . '">' . $fonts. '</option>';764 echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>'; 633 765 } 634 766 } … … 636 768 echo '<h3>Article Abstract</h3>'; 637 769 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>'; 639 771 echo '<h4>Size</h4>'; 640 772 echo '<select name="abstract_font_size" id="abstract_font_size">'; 641 773 $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>'; 643 775 for ($i = 10; $i <= 50; $i++) { 644 if ($i == $v) {776 if ($i === $v) { 645 777 } else { 646 echo '<option value="' . $i . '">' . $i. '</option>';778 echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; 647 779 } 648 780 } … … 651 783 echo '<select name="abstract_font_family" id="abstract_font_family">'; 652 784 $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>'; 654 786 if ($v) { 655 787 echo '<option value="">Unchanged (theme default)</option>'; 656 788 } 657 789 foreach ($font_family as $fonts) { 658 if ($fonts == $v) {790 if ($fonts === $v) { 659 791 } else { 660 echo '<option value="' . $fonts . '">' . $fonts. '</option>';792 echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>'; 661 793 } 662 794 } … … 668 800 echo '<h4>Color</h4>'; 669 801 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>'; 671 803 672 804 echo '<h4>Size</h4>'; … … 675 807 676 808 $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>'; 678 810 679 811 for ($i = 10; $i <= 50; $i++) { 680 681 if ($i == $v) { 812 if ($i === $v) { 682 813 } else { 683 684 echo '<option value="' . $i . '">' . $i . '</option>'; 814 echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; 685 815 } 686 816 } … … 690 820 echo '<select name="date_font" id="date_font">'; 691 821 $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>'; 693 823 if ($v) { 694 824 echo '<option value="">Unchanged (theme default)</option>'; 695 825 } 696 826 foreach ($font_family as $fonts) { 697 if ($fonts == $v) {827 if ($fonts === $v) { 698 828 } else { 699 echo '<option value="' . $fonts . '">' . $fonts. '</option>';829 echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>'; 700 830 } 701 831 } … … 706 836 echo '<h4>Color</h4>'; 707 837 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>'; 709 839 710 840 echo '<h4>Size</h4>'; … … 713 843 714 844 $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>'; 716 846 717 847 for ($i = 10; $i <= 50; $i++) { 718 719 if ($i == $v) { 848 if ($i === $v) { 720 849 } else { 721 722 echo '<option value="' . $i . '">' . $i . '</option>'; 850 echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; 723 851 } 724 852 } … … 728 856 echo '<select name="source_font" id="source_font">'; 729 857 $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>'; 731 859 if ($v) { 732 860 echo '<option value="">Unchanged (theme default)</option>'; 733 861 } 734 862 foreach ($font_family as $fonts) { 735 if ($fonts == $v) {863 if ($fonts === $v) { 736 864 } else { 737 echo '<option value="' . $fonts . '">' . $fonts. '</option>';865 echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>'; 738 866 } 739 867 } … … 751 879 ?> 752 880 753 <?php } elseif ($tab === $this->feed_settings_key) {881 <?php } elseif ($tab === $this->feed_settings_key) { 754 882 echo '<div class="feeds-row-style">'; 755 883 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 } ?> 763 893 </div> 764 894 <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'); ?> 765 896 <input type="hidden" name="action" value="news_plugin_send_feedback"> 766 897 <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>'; 774 906 echo '<h3>Subject</h3>'; 775 907 echo '<input class="text notsobig" name="feed_subject" id="feed_subject" type="text" size="64" /><br>'; 776 908 echo '<h3>Description</h3>'; 777 909 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>'; */780 910 echo '</textarea><br>'; 781 911 echo '<p class="submit">'; … … 799 929 800 930 $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> 806 936 </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> 813 943 </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> 820 950 </tr>'; 821 }951 } 822 952 823 953 echo '</tbody>'; … … 826 956 echo '<div class="log_div">'; 827 957 $myfilename = plugin_dir_url(__FILE__) . "logs/plugin-logs.txt"; 958 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents 828 959 $content = file_exists($myfilename) ? file_get_contents($myfilename) : false; 829 960 $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>'; 831 962 echo '</div>'; 832 963 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 } 837 968 echo '</div>'; 838 969 echo '</div>'; … … 840 971 841 972 echo '</div>'; 842 ?>973 ?> 843 974 <script> 844 975 function showDiv(box) { … … 867 998 </script> 868 999 869 <?php } elseif ($tab === $this->status_settings_key) { ?>1000 <?php } elseif ($tab === $this->status_settings_key) { ?> 870 1001 <form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post"> 1002 <?php wp_nonce_field('news_plugin_update_system_info'); ?> 871 1003 <input type="hidden" name="action" value="news_plugin_update_system_info"> 872 1004 <p class="submit"> … … 882 1014 $key_Name = str_replace('_', ' ', $key); 883 1015 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> 886 1018 </tr>'; 887 1019 } … … 890 1022 $key_Name = str_replace('_', ' ', $key); 891 1023 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> 894 1026 </tr>'; 895 1027 } … … 898 1030 $key_Name = str_replace('_', ' ', $key); 899 1031 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> 902 1034 </tr>'; 903 1035 } … … 906 1038 907 1039 ?> 908 <?php } ?>1040 <?php } ?> 909 1041 </div> 910 1042 <?php 911 }912 913 /*1043 } 1044 1045 /** 914 1046 * Renders our tabs in the plugin options page, 915 1047 * walks through the object's tabs array and prints 916 1048 * them one by one. Provides the heading for the 917 1049 * 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 & 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>'; 1001 1060 } 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 & 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. 1004 1165 new News_Plugin(); 1005 1166 1006 ?>1167 ?> -
newsplugin/tags/1.1.0/readme.txt
r2492225 r2580769 3 3 Tags: news, news plugin, news feed, news feeds, newsfeed, newsfeeds, news syndication 4 4 Requires at least: 3.9 5 Tested up to: 5. 76 Stable tag: 1. 0.185 Tested up to: 5.8 6 Stable tag: 1.1.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 73 73 == Changelog == 74 74 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) = 76 85 77 86 * Improvement: Format date & time according to WP settings -
newsplugin/tags/1.1.0/save_style.php
r2384451 r2580769 1 1 <?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; 13 if (! $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')); 7 15 } 8 $userID = $current_user->ID;9 16 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 38 48 if (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 ]; 66 76 update_user_meta($userID, 'news_style_dashbord_style', $default_values); 67 77 } else { … … 70 80 71 81 $redirect = admin_url('admin.php') . '?page=news-plugin-settings&tab=newsplugin_style_settings'; 72 wp_redirect($redirect); 82 wp_safe_redirect($redirect); 83 exit(); -
newsplugin/tags/1.1.0/send_feedback.php
r2384451 r2580769 1 1 <?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; 13 if (!$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; 8 23 9 24 if (!$from) { 10 if ($user_info = News_Plugin_Utils::get_user_info()) { 25 $user_info = News_Plugin_Utils::get_user_info(); 26 if ($user_info) { 11 27 $from = $user_info->email; 12 28 } … … 23 39 24 40 if (isset($errors_logs)) { 25 26 41 $message .= "<tr style='background: #eee;'><strong>Errors on plugin :</strong></tr>\n"; 27 42 $message .= '<tr><p>' . $errors_logs . '</p></tr>' . "\n"; 28 43 } 29 44 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"; 35 47 foreach ($results['wordpress_env'] as $key => $value) { 36 37 48 $key_Name = str_replace('_', ' ', $key); 38 49 $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n"; … … 40 51 $message .= "<tr style='background: #eee;'><td cellspan='2'><strong>SYSTEM ENVIRONMENT :</strong></td></tr>\n"; 41 52 foreach ($results['system_env'] as $key => $value) { 42 43 53 $key_Name = str_replace('_', ' ', $key); 44 54 $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n"; … … 46 56 $message .= "<tr style='background: #eee;'><td cellspan='2'><strong>NEWSPLUGIN ENVIRONMENT :</strong></td></tr>\n"; 47 57 foreach ($results['newsplugin_env'] as $key => $value) { 48 49 58 $key_Name = str_replace('_', ' ', $key); 50 59 $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n"; 51 60 } 52 // }53 61 54 62 $message .= '</tbody>'; … … 56 64 $message .= "</body></html>"; 57 65 66 /** 67 * Set content type helper 68 * 69 * @return string 70 */ 58 71 function news_plugin_wp_set_content_type() 59 72 { … … 61 74 } 62 75 add_filter('wp_mail_content_type', 'news_plugin_wp_set_content_type'); 76 63 77 $headers .= news_plugin_wp_set_content_type(); 64 78 … … 71 85 72 86 remove_filter('wp_mail_content_type', 'news_plugin_wp_set_content_type'); 73 wp_redirect($redirect); 87 wp_safe_redirect($redirect); 88 exit(); -
newsplugin/trunk/news-plugin-utils.php
r2384451 r2580769 1 1 <?php 2 3 /** 4 * Utils 5 * 6 * @package WordPress 7 * @subpackage News Plugin 8 * @since 1.0.0 9 */ 2 10 3 11 // Prevent ourselves from being run directly. … … 5 13 6 14 if (!function_exists('json_last_error_msg')) { 15 16 /** 17 * Get error message 18 * 19 * @return string 20 */ 7 21 function json_last_error_msg() 8 22 { 9 static $ERRORS = array(23 static $ERRORS = [ 10 24 JSON_ERROR_NONE => 'No error', 11 25 JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', … … 14 28 JSON_ERROR_SYNTAX => 'Syntax error', 15 29 JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded' 16 );30 ]; 17 31 18 32 $error = json_last_error(); … … 21 35 } 22 36 37 /** 38 * Utils 39 * 40 * @package News Plugin 41 */ 23 42 class 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() 29 58 { 30 59 if (self::$np_version) { 31 60 return (self::$np_version); 32 61 } 62 // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found 33 63 if (self::$np_version = get_option('news_plugin_version')) { 34 64 return (self::$np_version); … … 37 67 } 38 68 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() 40 75 { 41 76 if (!function_exists('get_plugin_data')) { … … 49 84 } 50 85 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) 52 93 { 53 94 global $wp_version; … … 56 97 } 57 98 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) 59 108 { 60 109 if (!function_exists('curl_version')) { 61 return ( array('', 'Error: CURL disabled or not installed'));110 return (['', 'Error: CURL disabled or not installed']); 62 111 } 63 112 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']); 65 114 } 66 115 $ch = curl_init($url); … … 75 124 } 76 125 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) 81 136 { 82 137 if (!function_exists('stream_socket_client')) { 83 return ( array('', 'Error: Socket disabled'));138 return (['', 'Error: Socket disabled']); 84 139 } 85 140 $aURL = parse_url($url); 86 141 $addr = $aURL['host']; 87 $secure_transport = ($aURL['scheme'] == 'ssl' || $aURL['scheme']== 'https');142 $secure_transport = ($aURL['scheme'] === 'ssl' || $aURL['scheme'] === 'https'); 88 143 if (!isset($aURL['port'])) { 89 144 if ($secure_transport) { … … 100 155 $socket = stream_socket_client($proto . $addr . ':' . $aURL['port'], $errno, $errorMessage, 10, STREAM_CLIENT_CONNECT); 101 156 if ($socket === false) { 102 return ( array('', 'Socket error: ' . $errorMessage));157 return (['', 'Socket error: ' . $errorMessage]); 103 158 } 104 159 $url = $aURL['path']; … … 113 168 fclose($socket); 114 169 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) 121 183 { 122 184 if ((!$ret[1]) && (!preg_match('/var swfobject=function()/s', $ret[0]))) { … … 127 189 } 128 190 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() 132 205 { 133 206 $ret = self::http_remote_get_curl(self::$test_url); … … 135 208 } 136 209 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() 138 217 { 139 218 $ret = self::http_remote_get_socket(self::$test_url); … … 141 220 } 142 221 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() 146 236 { 147 237 $ret = self::http_remote_get_curl(self::$test_url_ssl); … … 149 239 } 150 240 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() 152 248 { 153 249 $ret = self::http_remote_get_socket(self::$test_url_ssl); … … 155 251 } 156 252 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) 161 274 { 162 275 $output = $var[0]; … … 174 287 } 175 288 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() 177 295 { 178 296 $var = self::http_remote_get_curl(self::$api_root . self::$api_ping_path); … … 180 298 } 181 299 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() 183 306 { 184 307 $var = self::http_remote_get_socket(self::$api_root . self::$api_ping_path); … … 186 309 } 187 310 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) 189 319 { 190 320 switch ($method) { 191 321 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')]); 193 323 if (is_array($ret)) { 194 return ( array($ret['body'], ''));324 return ([$ret['body'], '']); 195 325 } 196 326 $ret = self::generic_remote_get($url, 'curl'); … … 209 339 } 210 340 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) 212 349 { 213 350 $key = get_option('news_plugin_api_key'); 214 $args = $args ? $args : array();351 $args = $args ? $args : []; 215 352 $args['k'] = $key; 216 353 $url = self::$api_root . $path; … … 219 356 $ret = self::generic_remote_get($url, $method ? $method : 'wp'); 220 357 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 222 360 $backtrace = debug_backtrace(); 361 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log 223 362 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); 225 364 } 226 365 return (json_decode($ret[0])); 227 366 } 228 367 229 static function get_user_info() 368 /** 369 * Get user info 370 * 371 * @return mixed 372 */ 373 public static function get_user_info() 230 374 { 231 375 return (self::generic_api_call('user_info')); 232 376 } 233 377 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() 235 383 { 236 384 return (1.0002); 237 385 } 238 386 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; 242 395 243 396 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 ([ 249 403 'mysql_method' => 'mysqli', 250 404 'mysql_server_info' => mysqli_get_server_info($wpdb->dbh), 251 405 'mysql_client_info' => mysqli_get_client_info($wpdb->dbh), 252 406 'mysql_proto_info' => mysqli_get_proto_info($wpdb->dbh), 253 ));407 ]); 254 408 } else { 255 return ( array(409 return ([ 256 410 'mysql_method' => 'mysql', 411 // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved 257 412 'mysql_server_info' => mysql_get_server_info(), 413 // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved 258 414 'mysql_client_info' => mysql_get_client_info(), 415 // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved 259 416 '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() 265 427 { 266 428 $my_theme = wp_get_theme(); … … 285 447 $db_info = self::get_system_db_info(); 286 448 287 $system_info = array(449 $system_info = [ 288 450 'info_version' => self::get_system_info_version(), 289 451 'api_key' => get_option('news_plugin_api_key'), /* We need to refresh on api key change ... */ 290 'wordpress_env' => array(452 'wordpress_env' => [ 291 453 'siteurl' => get_bloginfo('url'), 292 454 'version' => get_bloginfo('version'), … … 296 458 'theme_version' => $my_theme->get('Version'), 297 459 'theme_AuthorURI' => $my_theme->get('AuthorURI'), 298 ),299 'system_env' => array(460 ], 461 'system_env' => [ 300 462 '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, 302 464 '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, 308 470 'memory_limit' => ini_get('memory_limit'), 309 471 'execution_time' => ini_get('max_execution_time'), … … 320 482 'socket_status' => $socket_test[1] ? $socket_test[1] : 'OK', 321 483 'socket_status_ssl' => $socket_test_ssl[1] ? $socket_test_ssl[1] : 'OK', 322 ),323 'newsplugin_env' => array(484 ], 485 'newsplugin_env' => [ 324 486 'REGISTERED EMAIL' => $user_info ? $user_info->email : 'error or unregistered', 325 487 'USER STATUS' => $user_info ? $user_info->status : 'error or unregistered', … … 327 489 'curl_ping' => $curl_ping[1] ? $curl_ping[1] : ('OK from ' . $curl_ping[0]->client), 328 490 '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]) { 332 494 unset($system_info['system_env']['curl_status_ssl']); 333 495 } 334 if ($socket_test[1] == $socket_test_ssl[1]) {496 if ($socket_test[1] === $socket_test_ssl[1]) { 335 497 unset($system_info['system_env']['socket_status_ssl']); 336 498 } -
newsplugin/trunk/news-plugin-widget.php
r2384451 r2580769 1 1 <?php 2 3 /** 4 * Widget 5 * 6 * @package WordPress 7 * @subpackage News Plugin 8 * @since 1.0.0 9 */ 2 10 3 11 // Prevent ourselves from being run directly. … … 13 21 * Register widget with WordPress. 14 22 */ 15 function __construct()23 public function __construct() 16 24 { 17 25 parent::__construct( 18 26 'news_plugin_widget', 19 27 __('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'),] 21 29 ); 22 30 } … … 40 48 private function current_options() 41 49 { 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()] : []; 44 52 return $opts; 45 53 } … … 47 55 /** 48 56 * Update the private options specific for this widget. 57 * 58 * @param mixed $args Arguments. 59 * @return mixed 49 60 */ 50 61 private function update_options($args) 51 62 { 52 $opts = get_option('news_plugin_widget_options', array());63 $opts = get_option('news_plugin_widget_options', []); 53 64 $opts[$this->widget_id()] = $args; 54 65 update_option('news_plugin_widget_options', $opts); … … 62 73 { 63 74 $opts = $this->current_options(); 64 $posts = (isset($opts['excluded'])) ? $opts['excluded'] : array();75 $posts = (isset($opts['excluded'])) ? $opts['excluded'] : []; 65 76 return $posts; 66 77 } … … 68 79 /** 69 80 * Add given id to the list of excluded posts. 81 * 82 * @param int $id ID. 83 * @param int $limit Limit. 84 * @return array 70 85 */ 71 86 private function exclude_post($id, $limit = 100) … … 86 101 { 87 102 $opts = $this->current_options(); 88 $posts = array();103 $posts = []; 89 104 $opts['excluded'] = $posts; 90 105 $this->update_options($opts); … … 98 113 { 99 114 $opts = $this->current_options(); 100 $posts = (isset($opts['favorite'])) ? $opts['favorite'] : array();115 $posts = (isset($opts['favorite'])) ? $opts['favorite'] : []; 101 116 return $posts; 102 117 } … … 104 119 /** 105 120 * Add given id to the list of favorite posts. 121 * 122 * @param int $id ID. 123 * @param int $limit Limit. 124 * @return array 106 125 */ 107 126 private function star_favorite_post($id, $limit = 100) … … 118 137 /** 119 138 * Remove given id from the list of favorite posts. 139 * 140 * @param int $id ID. 141 * @return mixed 120 142 */ 121 143 private function unstar_favorite_post($id) … … 123 145 $opts = $this->current_options(); 124 146 $posts = $this->favorite_posts(); 125 $posts = array_diff($posts, array($id));147 $posts = array_diff($posts, [$id]); 126 148 $opts['favorite'] = $posts; 127 149 $this->update_options($opts); … … 135 157 { 136 158 $opts = $this->current_options(); 137 $posts = array();159 $posts = []; 138 160 $opts['favorite'] = $posts; 139 161 $this->update_options($opts); … … 152 174 /** 153 175 * Set the timestamp of the last publishing in manual publishing mode. 176 * 177 * @param int $time Timestamp. 178 * @return mixed 154 179 */ 155 180 private function update_publish_time($time) … … 163 188 /** 164 189 * 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 165 194 */ 166 195 private function create_action_args($action, $arg = 0) 167 196 { 168 return array(197 return [ 169 198 'news_plugin_instance' => $this->widget_id(), 170 199 'news_plugin_action' => $action, 171 200 'news_plugin_arg' => $arg, 172 ); 201 '_wpnonce' => wp_create_nonce('news_plugin_url_nonce'), 202 ]; 173 203 } 174 204 … … 178 208 private function parse_action_args() 179 209 { 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 ]; 187 223 } 188 224 … … 220 256 private function edit_mode_enabled() 221 257 { 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 222 264 if (isset($_GET['news_plugin_action'])) { 223 $action = $_GET['news_plugin_action'];265 $action = sanitize_key(wp_unslash($_GET['news_plugin_action'])); 224 266 return !empty($action); 225 267 } … … 228 270 /** 229 271 * Manage the feed as necessary. 272 * 273 * @param mixed $opts Options. 274 * @return void 230 275 */ 231 276 private function manage($opts) 232 277 { 233 278 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; 261 301 } 262 302 } … … 264 304 /** 265 305 * 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() 268 310 { 269 311 return 3600; … … 272 314 /** 273 315 * 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 274 321 */ 275 322 private function get_feed($time, $opts, $limit = 100) … … 277 324 $key = get_option('news_plugin_api_key'); 278 325 279 $args = array(326 $args = [ 280 327 'k' => $key, 281 328 'q' => $opts['keywords'], … … 283 330 'c' => $opts['count'], 284 331 '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') { 291 338 if (!($this->can_manage() && $this->edit_mode_enabled())) { 292 339 $time = $this->publish_time(); … … 328 375 329 376 // 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']; 331 378 add_filter('wp_feed_cache_transient_lifetime', $cache_filter); 332 379 $feed = fetch_feed($url); 333 380 remove_filter('wp_feed_cache_transient_lifetime', $cache_filter); 334 381 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 */ 338 392 private function compute_style_helper($style, $type) 339 393 { … … 343 397 $ret = ''; 344 398 if ($style[$type]['size']) { 345 $ret .= 'font-size: ' . $style[$type]['size'] . 'px;';399 $ret .= 'font-size:' . $style[$type]['size'] . 'px;'; 346 400 } 347 401 if ($style[$type]['color']) { … … 351 405 $ret .= 'font-family:' . $style[$type]['font_family'] . ';'; 352 406 } 353 if (!$ret) { 354 return ($ret); 355 } 356 return (' style="' . $ret . '"'); 407 if ($ret) { 408 return ' style=' . $ret ; 409 } 357 410 } 358 411 … … 370 423 371 424 if (!isset($rss)) { 372 _e('Feed fetch failed ', 'news_plugin');425 esc_html_e('Feed fetch failed ', 'news_plugin'); 373 426 return; 374 427 } 375 428 376 $manual_mode = ($opts['feed_mode'] == 'manual');429 $manual_mode = ($opts['feed_mode'] === 'manual'); 377 430 378 431 $exclude = array_fill_keys($this->excluded_posts(), true); … … 393 446 $args = $this->create_action_args('reset'); 394 447 echo '<a href="' . esc_attr(add_query_arg($args)) . '">'; 395 e cho 'Reset';448 esc_html_e('Reset', 'news_plugin'); 396 449 echo '</a>'; 397 450 … … 400 453 echo ' | '; 401 454 echo '<a href="' . esc_attr(add_query_arg($args)) . '">'; 402 e cho 'Publish Headlines';455 esc_html_e('Publish Headlines', 'news_plugin'); 403 456 echo '</a>'; 404 457 } 405 458 406 $args = $this->create_action_args( NULL, NULL);459 $args = $this->create_action_args(null, null); 407 460 echo ' | '; 408 461 echo '<a href="' . esc_attr(add_query_arg($args)) . '">'; 409 e cho 'Leave Edit Newsfeed Mode';462 esc_html_e('Leave Edit Newsfeed Mode', 'news_plugin'); 410 463 echo '</a>'; 411 464 … … 415 468 echo '<p class="news-plugin-edit-buttons">'; 416 469 echo '<a href="' . esc_attr(add_query_arg($args)) . '">'; 417 e cho 'Edit Newsfeed Mode';470 esc_html_e('Edit Newsfeed Mode', 'news_plugin'); 418 471 echo '</a>'; 419 472 } … … 421 474 if ($manual_mode) { 422 475 $t = $this->publish_time(); 423 if ($t == 0) {476 if ($t === 0) { 424 477 if ($this->edit_mode_enabled()) { 425 478 echo '<p>'; 426 e cho 'No headlines published yet.';479 esc_html_e('No headlines published yet.', 'news_plugin'); 427 480 echo '</p>'; 428 481 } else { 429 482 echo '<p>'; 430 e cho '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'); 431 484 echo '</p>'; 432 485 } 433 486 } else { 434 $t = date('d M Y H:i', $t); 487 // TODO localize properly. 488 $t = gmdate('d M Y H:i', $t); 435 489 echo '<p>'; 436 echo "Headlines last published on {$t}."; 490 // TODO localize properly. 491 echo esc_html("Headlines last published on {$t}."); 437 492 echo '</p>'; 438 493 } … … 442 497 if ($manual_mode) { 443 498 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. 445 502 echo ' You can <span style="font-size:110%;">☆</span> Star individual headlines to move them to the top or ✕ Remove them from the feed. Click Reset to undo these changes.'; 446 e cho ' 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'); 447 504 echo '</p>'; 448 505 } else { 449 506 echo '<p>'; 507 // TODO localize properly. 450 508 echo 'You can <span style="font-size:110%;">☆</span> Star individual headlines to move them to the top or ✕ Remove them from the feed. Click Reset to undo these changes.'; 451 509 echo '</p>'; … … 460 518 $index = 0; 461 519 462 if ($opts['wp_uid'] && (intval($opts['wp_uid']) != 0)) {520 if ($opts['wp_uid'] && (intval($opts['wp_uid']) !== 0)) { 463 521 $userID = intval($opts['wp_uid']); 464 522 } else { … … 479 537 } 480 538 481 if (!empty($favorite[$id]) xor ($pass == 0)) {539 if (!empty($favorite[$id]) xor ($pass === 0)) { 482 540 continue; 483 541 } 484 542 485 if ($index == $limit) {543 if ($index === $limit) { 486 544 echo '<hr>'; 487 545 } 488 546 489 547 echo '<li>'; 490 if ($opts['link_follow'] == 'no') {548 if ($opts['link_follow'] === 'no') { 491 549 $s_follow = ' rel="nofollow"'; 492 550 } else { … … 498 556 $s_target = ''; 499 557 } 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) . '>'; 501 559 $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) . '>'; 503 561 echo esc_html($item->get_title()); 504 562 echo '</span>'; … … 507 565 echo "\n"; 508 566 $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) . '>'; 510 568 echo esc_html($item->get_date(get_option('date_format') . ' ' . get_option('time_format'))); 511 569 echo '</span>'; … … 513 571 if ($opts['show_source']) { 514 572 // Because RSS doesn't support the source field, we use the author field. 515 // $source = $item->get_source() ;516 573 $source = $item->get_author(); 517 if ($source) $source = $source->get_email(); 574 if ($source) { 575 $source = $source->get_email(); 576 } 518 577 if (!empty($source)) { 519 578 echo "\n"; 520 579 $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) . '>'; 522 581 echo esc_html($source); 523 582 echo '</span>'; … … 527 586 echo "\n"; 528 587 $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) . '>'; 530 589 echo esc_html($item->get_description()); 531 590 echo '</span>'; … … 535 594 $args = $this->create_action_args('exclude', $id); 536 595 echo ' <a href="' . esc_attr(add_query_arg($args)) . '">'; 537 // echo 'X' ;538 596 echo '<span style="text-decoration: underline;">'; 539 597 echo '✕ Remove'; … … 543 601 $args = $this->create_action_args('unstar', $id); 544 602 echo ' <a href="' . esc_attr(add_query_arg($args)) . '">'; 545 // echo '-' ;546 603 echo '<span style="text-decoration: underline;">'; 547 604 echo '<span style="font-size:110%;">★</span> Unstar'; … … 551 608 $args = $this->create_action_args('star', $id); 552 609 echo ' <a href="' . esc_attr(add_query_arg($args)) . '">'; 553 // echo '+' ;554 610 echo '<span style="text-decoration: underline;">'; 555 611 echo '<span style="font-size:110%;">☆</span> Star'; … … 565 621 } 566 622 echo '</ul>'; 567 568 //Error in Option Page569 // newserroforwp_log("NewsPlugin Option Page");570 623 } 571 624 … … 589 642 if (empty($key)) { 590 643 if ($this->can_manage()) { 591 ?>644 ?> 592 645 <p> 593 Your feed is currently inactive.594 Please enter your Activation Key on the595 <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'); ?>. 597 650 </p> 598 <?php651 <?php 599 652 } 600 653 return; … … 607 660 $title = apply_filters('widget_title', $opts['title']); 608 661 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 } 612 666 $this->content($opts); 613 echo $args['after_widget'];667 echo wp_kses_post($args['after_widget']); 614 668 } 615 669 … … 627 681 ?> 628 682 <p> 629 Please enter your Activation Key on the630 <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'); ?> 632 686 </p> 633 <?php687 <?php 634 688 return; 635 689 } … … 726 780 727 781 // Force expert user mode for now. 728 // $user_mode = get_option( 'news_plugin_user_mode' ) ;782 // $user_mode = get_option( 'news_plugin_user_mode' ); . 729 783 $user_mode = 2; 730 784 731 785 ?> 732 786 <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); ?>"> 735 789 <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> 737 791 <br> 738 <small> Example: Canada Solar Energy News</small>792 <small><?php esc_html_e('Example: Canada Solar Energy News', 'news_plugin'); ?></small> 739 793 </p> 740 794 <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); ?>"> 743 797 <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> 745 799 <br> 746 <small> Example: canada & "solar energy"</small>800 <small><?php esc_html_e('Example: canada & "solar energy"', 'news_plugin'); ?></small> 747 801 <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> 749 803 </p> 750 804 <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); ?>"> 753 807 <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> 755 809 <br> 756 <small> Example: 10</small>810 <small><?php esc_html_e('Example: 10', 'news_plugin'); ?></small> 757 811 </p> 758 812 <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> 761 817 </p> 762 818 <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> 765 823 </p> 766 824 <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> 769 829 <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> 771 831 <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> 773 833 </p> 774 834 <?php 775 835 if ($user_mode > 0) { 776 777 836 /* 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 ?> 797 856 <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 & 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 & Full Text', 'news_plugin'); ?></option> 803 866 </select> 804 867 <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> 806 869 </p> 807 870 808 871 <?php 809 872 /* 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 */ 822 885 ?> 823 886 824 887 <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> 830 897 </select> 831 898 <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> 833 900 </p> 834 901 <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); ?>"> 837 904 <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> 839 906 </p> 840 907 <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> 846 917 </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> 852 927 </select> 853 928 854 929 <?php 855 856 930 /* 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 */ 871 945 872 946 ?> … … 876 950 ?> 877 951 <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> 883 961 </select> 884 962 <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> 886 964 </p> 887 <?php965 <?php 888 966 } 889 967 } … … 901 979 public function update($new_opts, $old_opts) 902 980 { 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']) : ''; 906 984 $opts['count'] = (!empty($new_opts['count'])) ? absint($new_opts['count']) : 5; 907 985 $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']) : ''; 916 994 $opts['show_date'] = !empty($new_opts['show_date']); 917 995 $opts['show_source'] = !empty($new_opts['show_source']); 918 996 $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']) : ''; 920 998 $opts['wp_uid'] = (!isset($new_opts['wp_uid']) || empty($new_opts['wp_uid'])) ? get_current_user_id() : $new_opts['wp_uid']; 921 999 … … 923 1001 } 924 1002 } 925 ?>1003 ?> -
newsplugin/trunk/news-plugin.php
r2384451 r2580769 1 1 <?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 */ 10 17 11 18 // Prevent ourselves from being run directly. … … 27 34 * Register plugin with WordPress. 28 35 */ 29 function __construct() 30 { 36 public function __construct() 37 { 38 39 add_action('init', [$this, 'localize']); 40 31 41 // 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']); 55 65 $usc = get_option('newsPlugin_system_info'); 56 66 $api_key = get_option('news_plugin_api_key'); … … 58 68 !$usc || 59 69 !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) 61 71 ) { 62 72 update_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info()); … … 64 74 } 65 75 66 function userSystemCheck_create() 76 /** 77 * Do on user system check creation 78 * 79 * @return void 80 */ 81 public function userSystemCheck_create() 67 82 { 68 83 add_option('newsPlugin_system_info', News_Plugin_Utils::get_system_info()); 69 84 add_option('news_plugin_url_method', false); 70 85 } 71 function userSystemCheck_deactivation() 86 87 /** 88 * Do on system check deactivation 89 * 90 * @return void 91 */ 92 public function userSystemCheck_deactivation() 72 93 { 73 94 delete_option('newsPlugin_system_info'); 74 95 } 75 96 76 function refresh_plugin_version() 97 /** 98 * Refresh plugin version 99 * 100 * @return void 101 */ 102 public function refresh_plugin_version() 77 103 { 78 104 if (function_exists('get_plugin_data')) { … … 86 112 87 113 /** 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 /** 88 124 * Register the plugin widget, widget areas and widget shorcodes. 89 125 */ 90 function widgets_init()126 public function widgets_init() 91 127 { 92 128 register_widget('News_Plugin_Widget'); 93 129 for ($area = 1; $area <= 4; $area++) { 94 register_sidebar( array(130 register_sidebar([ 95 131 'name' => "NewsPlugin Widget Area {$area}", 96 132 'id' => "newsplugin_widgets_{$area}", … … 98 134 'before_widget' => '<div id="%1$s" class="widget %2$s">', 99 135 'after_widget' => '</div>' 100 ));136 ]); 101 137 } 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']); 104 140 } 105 141 106 142 /** 107 143 * 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); 112 151 $sidebar = "newsplugin_widgets_{$a['area']}"; 113 152 ob_start(); … … 121 160 122 161 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=""] 124 163 125 164 /** 126 165 * 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([ 131 173 'id' => '', 132 174 'title' => '', … … 147 189 'feed_mode' => '', 148 190 'wp_uid' => '' 149 ), $attrs);191 ], $attrs); 150 192 $newswid = new News_Plugin_Widget(); 151 $a = $newswid->update($attrs, array());193 $a = $newswid->update($attrs, []); 152 194 $a['id'] = $attrs['id']; 153 195 ob_start(); 154 the_widget('News_Plugin_Widget', $a, array());196 the_widget('News_Plugin_Widget', $a, []); 155 197 return ob_get_clean(); 156 198 } … … 159 201 * Register the plugin CSS style. 160 202 */ 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"); 164 206 wp_enqueue_style('news-plugin'); 165 207 } 166 208 167 function register_admin_scripts() 209 /** 210 * Register admin scripts 211 * 212 * @return void 213 */ 214 public function register_admin_scripts() 168 215 { 169 216 $assets_path = plugin_dir_url(__FILE__) . 'assets/'; 217 // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion 170 218 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); 172 221 } 173 222 … … 175 224 * Register the plugin options. 176 225 */ 177 function admin_init()226 public function admin_init() 178 227 { 179 228 add_settings_section( 180 229 'default', 181 NULL,182 NULL,230 null, 231 null, 183 232 'news-plugin-settings' 184 233 ); … … 187 236 'news_plugin_api_key', 188 237 __('Activation Key:', 'news_plugin'), 189 array($this, 'settings_api_key'),238 [$this, 'settings_api_key'], 190 239 'news-plugin-settings', 191 240 'default' … … 194 243 'news-plugin-settings', 195 244 'news_plugin_api_key', 196 array($this, 'validate_api_key')245 [$this, 'validate_api_key'] 197 246 ); 198 247 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 */ 213 263 } 214 264 … … 216 266 * Register the plugin menu. 217 267 */ 218 function admin_menu()268 public function admin_menu() 219 269 { 220 270 add_menu_page( … … 223 273 'manage_options', 224 274 'news-plugin-settings', 225 array($this, 'newsplugin_options_page'),275 [$this, 'newsplugin_options_page'], 226 276 'dashicons-megaphone', 227 277 '3' 228 278 ); 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']); 230 280 } 231 281 … … 235 285 * when registering settings 236 286 */ 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 */ 238 298 private $feed_settings_key = 'newsplugin_feed_settings'; 299 /** 300 * Key - style 301 * 302 * @var string 303 */ 239 304 private $style_settings_key = 'newsplugin_style_settings'; 305 /** 306 * Key - activation 307 * 308 * @var string 309 */ 240 310 private $activation_settings_key = 'newsplugin_activation_settings'; 311 /** 312 * Key - shortcode 313 * 314 * @var string 315 */ 241 316 private $shortcode_settings_key = 'newsplugin_shortcode_settings'; 317 /** 318 * Key - help 319 * 320 * @var string 321 */ 242 322 private $help_settings_key = 'newsplugin_help_settings'; 323 /** 324 * Key - key 325 * 326 * @var string 327 */ 243 328 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() 250 342 { 251 343 $this->plugin_settings_tabs[$this->status_settings_key] = 'Server Information'; 252 344 } 253 function register_feed_section() 345 /** 346 * Registering the sections - feed 347 * 348 * @return void 349 */ 350 public function register_feed_section() 254 351 { 255 352 $this->plugin_settings_tabs[$this->feed_settings_key] = 'Send Feedback'; 256 353 } 257 function register_style_section() 354 /** 355 * Registering the sections - style 356 * 357 * @return void 358 */ 359 public function register_style_section() 258 360 { 259 361 $this->plugin_settings_tabs[$this->style_settings_key] = 'Customize Styles'; 260 362 } 261 function register_activation_section() 363 /** 364 * Registering the sections - activation 365 * 366 * @return void 367 */ 368 public function register_activation_section() 262 369 { 263 370 $this->plugin_settings_tabs[$this->activation_settings_key] = 'Activate NewsPlugin'; 264 371 } 265 function register_shortcode_section() 372 /** 373 * Registering the sections - shortcode 374 * 375 * @return void 376 */ 377 public function register_shortcode_section() 266 378 { 267 379 $this->plugin_settings_tabs[$this->shortcode_settings_key] = 'Generate Shortcode'; 268 380 } 269 function register_help_section() 381 /** 382 * Registering the sections - help 383 * 384 * @return void 385 */ 386 public function register_help_section() 270 387 { 271 388 $this->plugin_settings_tabs[$this->help_settings_key] = 'Instructions!'; 272 389 } 273 390 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 */ 276 403 if (!is_array($arr)) { 277 404 return $def; … … 286 413 } 287 414 288 /* 415 /** 289 416 * Plugin Options page rendering goes here, checks 290 417 * for active tab and replaces key with the related 291 418 * settings key. Uses the plugin_options_tabs method 292 419 * 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 ?> 298 429 <div class="wrap"> 299 430 <h2>NewsPlugin Settings</h2> … … 302 433 if (empty($key)) { ?> 303 434 <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> 305 436 </div> 306 437 <?php } ?> … … 312 443 <?php submit_button(); ?> 313 444 </form> 314 <?php } else if ($tab === $this->shortcode_settings_key && !empty($key)) { ?>445 <?php } elseif ($tab === $this->shortcode_settings_key && !empty($key)) { ?> 315 446 <table id="shortcodeTable" class="form-table"> 316 447 <tr> … … 546 677 shortcode_params += " age='" + newsplugin_age + "'"; 547 678 } 548 shortcode_params += " wp_uid='<?php echo get_current_user_id(); ?>'";679 shortcode_params += " wp_uid='<?php echo esc_attr(get_current_user_id()); ?>'"; 549 680 var html = "<p>Press Ctrl+C to copy to clipboard and paste it in your posts or pages.</p>"; 550 681 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>"; … … 555 686 } 556 687 </script> 557 <?php } else if ($tab === $this->help_settings_key) { ?>688 <?php } elseif ($tab === $this->help_settings_key) { ?> 558 689 <h3>Instructions</h3> 559 690 <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 > 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 > 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> 562 693 <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> 563 694 <h3>Support</h3> … … 569 700 $style_news = get_user_meta($userID, 'news_style_dashbord_style', 'true'); 570 701 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> 575 706 <div class="news-row-style"> 576 707 <div class="style_left"> 577 708 <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'); ?> 578 710 <input type="hidden" name="action" value="news_plugin_save_style"> 579 711 <h3>Newsfeed Title</h3> 580 712 <h4>Color</h4> 581 713 <?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>'; 583 715 echo '<h4>Size</h4>'; 584 716 echo '<select name="title_size" id="title_size">'; 585 717 $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>'; 587 719 for ($i = 10; $i <= 50; $i++) { 588 if ($i == $v) {720 if ($i === $v) { 589 721 } else { 590 echo '<option value="' . $i . '">' . $i. '</option>';722 echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; 591 723 } 592 724 } … … 595 727 echo '<select name="title_font" id="title_font">'; 596 728 $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>'; 598 730 if ($v) { 599 731 echo '<option value="">Unchanged (theme default)</option>'; 600 732 } 601 733 foreach ($font_family as $fonts) { 602 if ($fonts == $v) {734 if ($fonts === $v) { 603 735 } else { 604 echo '<option value="' . $fonts . '">' . $fonts. '</option>';736 echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>'; 605 737 } 606 738 } … … 608 740 echo '<h3>Article Headline</h3>'; 609 741 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>'; 611 743 echo '<h4>Size</h4>'; 612 744 echo '<select name="news_title_size" id="news_title_size">'; 613 745 $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>'; 615 747 for ($i = 10; $i <= 50; $i++) { 616 if ($i == $v) {748 if ($i === $v) { 617 749 } else { 618 echo '<option value="' . $i . '">' . $i. '</option>';750 echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; 619 751 } 620 752 } … … 623 755 echo '<select name="news_title_family" id="news_title_family">'; 624 756 $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>'; 626 758 if ($v) { 627 759 echo '<option value="">Unchanged (theme default)</option>'; 628 760 } 629 761 foreach ($font_family as $fonts) { 630 if ($fonts == $v) {762 if ($fonts === $v) { 631 763 } else { 632 echo '<option value="' . $fonts . '">' . $fonts. '</option>';764 echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>'; 633 765 } 634 766 } … … 636 768 echo '<h3>Article Abstract</h3>'; 637 769 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>'; 639 771 echo '<h4>Size</h4>'; 640 772 echo '<select name="abstract_font_size" id="abstract_font_size">'; 641 773 $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>'; 643 775 for ($i = 10; $i <= 50; $i++) { 644 if ($i == $v) {776 if ($i === $v) { 645 777 } else { 646 echo '<option value="' . $i . '">' . $i. '</option>';778 echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; 647 779 } 648 780 } … … 651 783 echo '<select name="abstract_font_family" id="abstract_font_family">'; 652 784 $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>'; 654 786 if ($v) { 655 787 echo '<option value="">Unchanged (theme default)</option>'; 656 788 } 657 789 foreach ($font_family as $fonts) { 658 if ($fonts == $v) {790 if ($fonts === $v) { 659 791 } else { 660 echo '<option value="' . $fonts . '">' . $fonts. '</option>';792 echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>'; 661 793 } 662 794 } … … 668 800 echo '<h4>Color</h4>'; 669 801 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>'; 671 803 672 804 echo '<h4>Size</h4>'; … … 675 807 676 808 $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>'; 678 810 679 811 for ($i = 10; $i <= 50; $i++) { 680 681 if ($i == $v) { 812 if ($i === $v) { 682 813 } else { 683 684 echo '<option value="' . $i . '">' . $i . '</option>'; 814 echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; 685 815 } 686 816 } … … 690 820 echo '<select name="date_font" id="date_font">'; 691 821 $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>'; 693 823 if ($v) { 694 824 echo '<option value="">Unchanged (theme default)</option>'; 695 825 } 696 826 foreach ($font_family as $fonts) { 697 if ($fonts == $v) {827 if ($fonts === $v) { 698 828 } else { 699 echo '<option value="' . $fonts . '">' . $fonts. '</option>';829 echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>'; 700 830 } 701 831 } … … 706 836 echo '<h4>Color</h4>'; 707 837 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>'; 709 839 710 840 echo '<h4>Size</h4>'; … … 713 843 714 844 $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>'; 716 846 717 847 for ($i = 10; $i <= 50; $i++) { 718 719 if ($i == $v) { 848 if ($i === $v) { 720 849 } else { 721 722 echo '<option value="' . $i . '">' . $i . '</option>'; 850 echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; 723 851 } 724 852 } … … 728 856 echo '<select name="source_font" id="source_font">'; 729 857 $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>'; 731 859 if ($v) { 732 860 echo '<option value="">Unchanged (theme default)</option>'; 733 861 } 734 862 foreach ($font_family as $fonts) { 735 if ($fonts == $v) {863 if ($fonts === $v) { 736 864 } else { 737 echo '<option value="' . $fonts . '">' . $fonts. '</option>';865 echo '<option value="' . esc_attr($fonts) . '">' . esc_html($fonts) . '</option>'; 738 866 } 739 867 } … … 751 879 ?> 752 880 753 <?php } elseif ($tab === $this->feed_settings_key) {881 <?php } elseif ($tab === $this->feed_settings_key) { 754 882 echo '<div class="feeds-row-style">'; 755 883 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 } ?> 763 893 </div> 764 894 <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'); ?> 765 896 <input type="hidden" name="action" value="news_plugin_send_feedback"> 766 897 <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>'; 774 906 echo '<h3>Subject</h3>'; 775 907 echo '<input class="text notsobig" name="feed_subject" id="feed_subject" type="text" size="64" /><br>'; 776 908 echo '<h3>Description</h3>'; 777 909 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>'; */780 910 echo '</textarea><br>'; 781 911 echo '<p class="submit">'; … … 799 929 800 930 $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> 806 936 </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> 813 943 </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> 820 950 </tr>'; 821 }951 } 822 952 823 953 echo '</tbody>'; … … 826 956 echo '<div class="log_div">'; 827 957 $myfilename = plugin_dir_url(__FILE__) . "logs/plugin-logs.txt"; 958 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents 828 959 $content = file_exists($myfilename) ? file_get_contents($myfilename) : false; 829 960 $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>'; 831 962 echo '</div>'; 832 963 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 } 837 968 echo '</div>'; 838 969 echo '</div>'; … … 840 971 841 972 echo '</div>'; 842 ?>973 ?> 843 974 <script> 844 975 function showDiv(box) { … … 867 998 </script> 868 999 869 <?php } elseif ($tab === $this->status_settings_key) { ?>1000 <?php } elseif ($tab === $this->status_settings_key) { ?> 870 1001 <form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post"> 1002 <?php wp_nonce_field('news_plugin_update_system_info'); ?> 871 1003 <input type="hidden" name="action" value="news_plugin_update_system_info"> 872 1004 <p class="submit"> … … 882 1014 $key_Name = str_replace('_', ' ', $key); 883 1015 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> 886 1018 </tr>'; 887 1019 } … … 890 1022 $key_Name = str_replace('_', ' ', $key); 891 1023 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> 894 1026 </tr>'; 895 1027 } … … 898 1030 $key_Name = str_replace('_', ' ', $key); 899 1031 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> 902 1034 </tr>'; 903 1035 } … … 906 1038 907 1039 ?> 908 <?php } ?>1040 <?php } ?> 909 1041 </div> 910 1042 <?php 911 }912 913 /*1043 } 1044 1045 /** 914 1046 * Renders our tabs in the plugin options page, 915 1047 * walks through the object's tabs array and prints 916 1048 * them one by one. Provides the heading for the 917 1049 * 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 & 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>'; 1001 1060 } 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 & 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. 1004 1165 new News_Plugin(); 1005 1166 1006 ?>1167 ?> -
newsplugin/trunk/readme.txt
r2492225 r2580769 3 3 Tags: news, news plugin, news feed, news feeds, newsfeed, newsfeeds, news syndication 4 4 Requires at least: 3.9 5 Tested up to: 5. 76 Stable tag: 1. 0.185 Tested up to: 5.8 6 Stable tag: 1.1.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 73 73 == Changelog == 74 74 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) = 76 85 77 86 * Improvement: Format date & time according to WP settings -
newsplugin/trunk/save_style.php
r2384451 r2580769 1 1 <?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; 13 if (! $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')); 7 15 } 8 $userID = $current_user->ID;9 16 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 38 48 if (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 ]; 66 76 update_user_meta($userID, 'news_style_dashbord_style', $default_values); 67 77 } else { … … 70 80 71 81 $redirect = admin_url('admin.php') . '?page=news-plugin-settings&tab=newsplugin_style_settings'; 72 wp_redirect($redirect); 82 wp_safe_redirect($redirect); 83 exit(); -
newsplugin/trunk/send_feedback.php
r2384451 r2580769 1 1 <?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; 13 if (!$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; 8 23 9 24 if (!$from) { 10 if ($user_info = News_Plugin_Utils::get_user_info()) { 25 $user_info = News_Plugin_Utils::get_user_info(); 26 if ($user_info) { 11 27 $from = $user_info->email; 12 28 } … … 23 39 24 40 if (isset($errors_logs)) { 25 26 41 $message .= "<tr style='background: #eee;'><strong>Errors on plugin :</strong></tr>\n"; 27 42 $message .= '<tr><p>' . $errors_logs . '</p></tr>' . "\n"; 28 43 } 29 44 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"; 35 47 foreach ($results['wordpress_env'] as $key => $value) { 36 37 48 $key_Name = str_replace('_', ' ', $key); 38 49 $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n"; … … 40 51 $message .= "<tr style='background: #eee;'><td cellspan='2'><strong>SYSTEM ENVIRONMENT :</strong></td></tr>\n"; 41 52 foreach ($results['system_env'] as $key => $value) { 42 43 53 $key_Name = str_replace('_', ' ', $key); 44 54 $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n"; … … 46 56 $message .= "<tr style='background: #eee;'><td cellspan='2'><strong>NEWSPLUGIN ENVIRONMENT :</strong></td></tr>\n"; 47 57 foreach ($results['newsplugin_env'] as $key => $value) { 48 49 58 $key_Name = str_replace('_', ' ', $key); 50 59 $message .= '<tr><td><strong>' . strtoupper($key_Name) . '</strong> </td><td>' . $value . '</td></tr>' . "\n"; 51 60 } 52 // }53 61 54 62 $message .= '</tbody>'; … … 56 64 $message .= "</body></html>"; 57 65 66 /** 67 * Set content type helper 68 * 69 * @return string 70 */ 58 71 function news_plugin_wp_set_content_type() 59 72 { … … 61 74 } 62 75 add_filter('wp_mail_content_type', 'news_plugin_wp_set_content_type'); 76 63 77 $headers .= news_plugin_wp_set_content_type(); 64 78 … … 71 85 72 86 remove_filter('wp_mail_content_type', 'news_plugin_wp_set_content_type'); 73 wp_redirect($redirect); 87 wp_safe_redirect($redirect); 88 exit();
Note: See TracChangeset
for help on using the changeset viewer.