Skip to content

Commit

Permalink
v1.0.2 - Settings Improvements
Browse files Browse the repository at this point in the history
Removed use of eval() and replaced with do_processing(). Also fixed Settings page check.
  • Loading branch information
morehawes committed Sep 7, 2022
1 parent 3052d1a commit 91329e3
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 42 deletions.
6 changes: 3 additions & 3 deletions App/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct() {
'prepend' => 'share.garmin.com/',
//Remove all non-alphanemeric
'input_processing' => [
'preg_replace("/[^\da-z]/i", "", $param_value);'
'strip_special'
]
],
'mapshare_password' => [
Expand Down Expand Up @@ -85,10 +85,10 @@ public function __construct() {
'title' => esc_html__('Basemap Attribution', Joe_Config::get_item('plugin_text_domain')),
'tip' => esc_html__('Mapping services often have the requirement that attribution is displayed by the map. Text and HTML links are supported.', Joe_Config::get_item('plugin_text_domain')),
'input_processing' => array(
'(! strpos($param_value, "&")) ? htmlspecialchars($param_value) : $param_value'
'encode_special'
),
'output_processing' => array(
'(! strpos($param_value, "&")) ? htmlspecialchars($param_value) : $param_value'
'encode_special'
)
]
]
Expand Down
2 changes: 1 addition & 1 deletion Joe
Submodule Joe updated 2 files
+21 −6 inc/Input.php
+20 −5 inc/Settings.php
6 changes: 3 additions & 3 deletions build/App/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct() {
'prepend' => 'share.garmin.com/',
//Remove all non-alphanemeric
'input_processing' => [
'preg_replace("/[^\da-z]/i", "", $param_value);'
'strip_special'
]
],
'mapshare_password' => [
Expand Down Expand Up @@ -85,10 +85,10 @@ public function __construct() {
'title' => esc_html__('Basemap Attribution', Joe_v1_0_Config::get_item('plugin_text_domain')),
'tip' => esc_html__('Mapping services often have the requirement that attribution is displayed by the map. Text and HTML links are supported.', Joe_v1_0_Config::get_item('plugin_text_domain')),
'input_processing' => array(
'(! strpos($param_value, "&")) ? htmlspecialchars($param_value) : $param_value'
'encode_special'
),
'output_processing' => array(
'(! strpos($param_value, "&")) ? htmlspecialchars($param_value) : $param_value'
'encode_special'
)
]
]
Expand Down
27 changes: 21 additions & 6 deletions build/Joe/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static function create_parameter_groups($fields, $groups = array(), $data = arra
static function process_input($param_def, $param_value) {
//Do processing
if(array_key_exists('input_processing', $param_def)) {
$param_value = static::eval_processes_on_param_value($param_def['input_processing'], $param_value);
$param_value = static::process_param_value($param_def['input_processing'], $param_value);
}

return $param_value;
Expand All @@ -441,13 +441,13 @@ static function process_input($param_def, $param_value) {
static function process_output($param_def, $param_value) {
//Do processing
if(array_key_exists('output_processing', $param_def)) {
$param_value = static::eval_processes_on_param_value($param_def['output_processing'], $param_value);
$param_value = static::process_param_value($param_def['output_processing'], $param_value);
}

return $param_value;
}

static function eval_processes_on_param_value($processes, $param_value) {
static function process_param_value($processes, $param_value) {
if(is_array($processes)) {
foreach($processes as $process) {
//Values stored in array
Expand All @@ -459,7 +459,7 @@ static function eval_processes_on_param_value($processes, $param_value) {

//Process
$param_value = trim($param_value);
eval("\$param_value = $process;");
$param_value = self::do_processing($param_value, $process);

//Back into array
$param_value = array($param_value);
Expand All @@ -471,7 +471,7 @@ static function eval_processes_on_param_value($processes, $param_value) {
foreach($param_values as $param_value) {
//Process each value
$param_value = trim($param_value);
eval("\$param_value = $process;");
$param_value = self::do_processing($param_value, $process);

$param_value_out[] = $param_value;
}
Expand All @@ -482,7 +482,7 @@ static function eval_processes_on_param_value($processes, $param_value) {
//Single value stored in string
} else {
$param_value = trim($param_value);
eval("\$param_value = $process;");
$param_value = self::do_processing($param_value, $process);
}
}
}
Expand Down Expand Up @@ -541,4 +541,19 @@ public static function allowable_file($ext = '', $mime = '', $file_image = 'file

return false;
}

public static function do_processing($param_value = '', $process = '') {
switch($process) {
case 'encode_special' :
$param_value = (! strpos($param_value, "&")) ? htmlspecialchars($param_value) : $param_value;

break;
case 'strip_special' :
$param_value = preg_replace("/[^\da-z]/i", "", $param_value);

break;
}

return $param_value;
}
}
25 changes: 20 additions & 5 deletions build/Joe/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,27 @@ public function __construct() {
//Add Menu link
add_action( 'admin_menu', [ $this, 'admin_menu'] );
add_action( 'admin_init', [ $this, 'register_settings'] );

//Only continue if we are on *OUR* Settings page

//Get
if(! sizeof($_POST)) {
if($pagenow != $this->slug) {
return false;
}

//Only continue if we are on the Settings page
if($pagenow != $this->slug || ! isset($_GET['page']) || $_GET['page'] != $this->submenu_slug) {
return false;
//Check URL
if(! isset($_GET['page']) || $_GET['page'] != $this->submenu_slug) {
return false;
}
//Post
} else {
//Check submission
if(! isset($_POST['option_page']) || $_POST['option_page'] != Joe_v1_0_Config::get_item('settings_id')) {
return false;
}
}

//Joe Plugin
$this->add_setting_tab('joe', [
'sections' => [
Expand Down Expand Up @@ -299,7 +314,7 @@ public function sanitize_callback($input_data) {
//If no input processing specified
if(! array_key_exists('input_processing', $field_definition)) {
//Make safe by default
$field_definition['input_processing'][] = 'htmlspecialchars($param_value)';
$field_definition['input_processing'][] = 'encode_special';
}

//Process the input
Expand Down
2 changes: 1 addition & 1 deletion build/assets/css/leaflet.min.css

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions build/assets/css/shortcode.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
}
.inmap-wrap .inmap-map.inmap-info,
.inmap-wrap .inmap-info.inmap-info {
overflow: scroll;
overflow-y: auto;
}
@media screen and (min-width: 481px) {
.inmap-wrap .inmap-map.inmap-info .inmap-info-item.inmap-last,
Expand Down Expand Up @@ -221,7 +221,7 @@
border-bottom: 1px solid #ddd;
}
.inmap-wrap .inmap-info .inmap-info-item.inmap-active {
overflow: scroll;
overflow-y: auto;
max-height: 320px;
}
.inmap-wrap .inmap-info .inmap-info-item .inmap-icon {
Expand All @@ -235,7 +235,7 @@
.inmap-wrap .inmap-info .inmap-info-item .inmap-info-desc {
padding: 8px;
padding-left: 15px;
overflow: scroll;
overflow-y: auto;
margin-left: 17px;
border-left: 1px solid #439500;
}
Expand Down Expand Up @@ -366,6 +366,7 @@
.inmap-wrap .inmap-info .inmap-info-item.inmap-hover .inmap-info-title span {
color: #fff !important;
}
body.inmap-has-single #joe-settings-nav,
body.inmap-has-single .leaflet-map {
display: none;
}
Expand All @@ -390,6 +391,7 @@ body.inmap-has-single.admin-bar #wpadminbar {
max-width: unset !important;
max-height: unset !important;
overflow: hidden !important;
margin: 0 !important;
}
.inmap-wrap.inmap-fullscreen .inmap-map,
.inmap-wrap.inmap-fullscreen .inmap-info {
Expand Down
2 changes: 1 addition & 1 deletion build/assets/css/shortcode.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/assets/js/leaflet.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/inreach-mapshare.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin Name: inReach MapShare
Plugin URI: https://github.com/morehawes/inreach-mapshare
Description: Display inReach MapShare data on your WordPress site. Visit the <a href="options-general.php?page=inreach-mapshare-settings">Settings</a> page to create and customise Shortcodes.
Version: 1.0.1
Version: 1.0.2
Text Domain: inreach-mapshare
Author: Joe Hawes
Author URI: https://www.morehawes.co.uk/
Expand Down Expand Up @@ -50,7 +50,7 @@
'plugin_slug' => $plugin_slug,
'plugin_text_domain' => $plugin_slug,
'plugin_name' => $plugin_name,
'plugin_version' => '1.0.1',
'plugin_version' => '1.0.2',
'settings_id' => 'inmap_settings',
'settings_default_tab' => 'joe-settings-tab-mapshare',
'site_url' => 'https://wordpress.org/plugins/' . $plugin_slug . '/',
Expand Down
2 changes: 1 addition & 1 deletion build/inreach-mapshare.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is distributed under the same license as the inReach MapShare package.
msgid ""
msgstr ""
"Project-Id-Version: inReach MapShare 1.0.1\n"
"Project-Id-Version: inReach MapShare 1.0.2\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/build\n"
"POT-Creation-Date: 2022-08-29 20:49:10+00:00\n"
"MIME-Version: 1.0\n"
Expand Down
12 changes: 8 additions & 4 deletions build/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: inreach, mapshare, embed, map, share, location
Requires at least: 4.6
Tested up to: 6.0
Requires PHP: 7.4
Stable tag: 1.0.1
Stable tag: 1.0.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -88,10 +88,14 @@ This plugin requests data from your MapShare page and embeds it anywhere Shortco

== Changelog ==

= 1.0 =
= 1.0.2 =

Initial plugin release.
Settings improvements.

= 1.0.1 =

Plugin review improvements.
Plugin review improvements.

= 1.0 =

Initial plugin release.
4 changes: 2 additions & 2 deletions inreach-mapshare.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin Name: inReach MapShare
Plugin URI: https://github.com/morehawes/inreach-mapshare
Description: Display inReach MapShare data on your WordPress site. Visit the <a href="options-general.php?page=inreach-mapshare-settings">Settings</a> page to create and customise Shortcodes.
Version: 1.0.1
Version: 1.0.2
Text Domain: inreach-mapshare
Author: Joe Hawes
Author URI: https://www.morehawes.co.uk/
Expand Down Expand Up @@ -50,7 +50,7 @@
'plugin_slug' => $plugin_slug,
'plugin_text_domain' => $plugin_slug,
'plugin_name' => $plugin_name,
'plugin_version' => '1.0.1',
'plugin_version' => '1.0.2',
'settings_id' => 'inmap_settings',
'settings_default_tab' => 'joe-settings-tab-mapshare',
'site_url' => 'https://wordpress.org/plugins/' . $plugin_slug . '/',
Expand Down
Binary file modified inreach-mapshare.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"grunt": "^1.5.3",
"grunt-cli": "^1.4.3",
"grunt-contrib-compress": "^2.0.0",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-concat": "^1.0.2",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^3.0.0",
"grunt-contrib-less": "^2.0.0",
Expand Down
12 changes: 8 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
**Requires at least:** 4.6
**Tested up to:** 6.0
**Requires PHP:** 7.4
**Stable tag:** 1.0.1
**Stable tag:** 1.0.2
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -88,10 +88,14 @@ This plugin requests data from your MapShare page and embeds it anywhere Shortco

## Changelog ##

### 1.0 ###
### 1.0.2 ###

Initial plugin release.
Settings improvements.

### 1.0.1 ###

Plugin review improvements.
Plugin review improvements.

### 1.0 ###

Initial plugin release.
12 changes: 8 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: inreach, mapshare, embed, map, share, location
Requires at least: 4.6
Tested up to: 6.0
Requires PHP: 7.4
Stable tag: 1.0.1
Stable tag: 1.0.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -88,10 +88,14 @@ This plugin requests data from your MapShare page and embeds it anywhere Shortco

== Changelog ==

= 1.0 =
= 1.0.2 =

Initial plugin release.
Settings improvements.

= 1.0.1 =

Plugin review improvements.
Plugin review improvements.

= 1.0 =

Initial plugin release.

0 comments on commit 91329e3

Please sign in to comment.