Skip to content

Commit f1166a6

Browse files
committed
Merge branch 'themeAccess'
2 parents 76ec924 + ac87d3b commit f1166a6

File tree

7 files changed

+70
-33
lines changed

7 files changed

+70
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wolfnet-idx-for-wordpress",
3-
"version": "1.19.0",
3+
"version": "1.19.1",
44
"description": "WolfNet IDX for WordPress",
55
"homepage": "https://github.com/wolfnet/wordpressplugin",
66
"bugs": "https://github.com/wolfnet/wordpressplugin/issues",

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Please upgrade to the latest version of the plugin as we will be disabling our o
8989

9090
## Changelog
9191

92+
### 1.19.1
93+
94+
* Security update to get custom styles via AJAX instead of via direct PHP execution
95+
9296
### 1.19.0
9397

9498
* Added a new "Settings" link on the plugins page

src/Ajax.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function registerAdminAjaxActions()
4747
'wolfnet_get_listings' => 'remoteListingsGet',
4848
'wolfnet_listing_photos' => 'remoteListingPhotos',
4949
'wolfnet_css' => 'remotePublicCss',
50+
'wolfnet_theme_custom_css' => 'remoteThemeCustomCss',
5051
'wolfnet_market_name' => 'remoteGetMarketName',
5152
'wolfnet_map_enabled' => 'remoteMapEnabled',
5253
'wolfnet_price_range' => 'remotePriceRange',
@@ -73,6 +74,7 @@ public function registerAjaxActions()
7374
'wolfnet_listing_photos' => 'remoteListingPhotos',
7475
'wolfnet_map_track' => 'remoteMapTrack',
7576
'wolfnet_css' => 'remotePublicCss',
77+
'wolfnet_theme_custom_css' => 'remoteThemeCustomCss',
7678
'wolfnet_base_url' => 'remoteGetBaseUrl',
7779
'wolfnet_price_range' => 'remotePriceRange',
7880
'wolfnet_route_quicksearch' => 'remoteRouteQuickSearch',
@@ -538,6 +540,43 @@ public function remotePublicCss()
538540
}
539541

540542

543+
public function remoteThemeCustomCss()
544+
{
545+
546+
try {
547+
548+
$args = array();
549+
550+
if (array_key_exists('colors', $_REQUEST)) {
551+
$colors = sanitize_text_field($_REQUEST['colors']);
552+
if (!empty($colors)) {
553+
$args['colors'] = explode(',', htmlspecialchars($colors));
554+
}
555+
}
556+
557+
if (array_key_exists('opacity', $_REQUEST)) {
558+
$opacity = sanitize_text_field($_REQUEST['opacity']);
559+
if (!empty($opacity) || ($opacity != 0)) {
560+
$args['opacity'] = $opacity;
561+
}
562+
}
563+
564+
$response = $GLOBALS['wolfnet']->views->getThemeCustomCSS($args);
565+
566+
} catch (Wolfnet_Exception $e) {
567+
status_header(500);
568+
echo $GLOBALS['wolfnet']->displayException($e);
569+
die;
570+
}
571+
572+
header('Content-type: text/css; charset: UTF-8');
573+
echo $response;
574+
575+
die;
576+
577+
}
578+
579+
541580
public function remotePriceRange()
542581
{
543582

src/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public function registerStyles()
254254
admin_url('admin-ajax.php') . '?action=wolfnet_css',
255255
),
256256
'wolfnet-theme-custom' => array(
257-
$this->url . 'css/wolfnet.theme.custom.php?' . $this->plugin->views->getThemeStyleArgs(),
257+
admin_url('admin-ajax.php') . '?action=wolfnet_theme_custom_css',
258258
),
259259
'wolfnet-jquery-ui' => array(
260260
$this->url . 'lib/jquery-ui/themes/wolfnet-wp/jquery-ui.min.css',

src/Views.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,20 @@ public function getThemeStyleArgs(array $args = array())
318318
}
319319

320320

321+
public function getThemeCustomCSS(array $args = array())
322+
{
323+
$defaultArgs = array(
324+
'colors' => $this->getThemeColors(),
325+
'opacity' => $this->getThemeOpacity(),
326+
);
327+
328+
$args = array_merge($defaultArgs, $args);
329+
330+
return $this->parseTemplate('themeCustomCss', $args);
331+
332+
}
333+
334+
321335
/**
322336
* This method is used in the context of admin_print_styles to output custom CSS.
323337
* @return void

src/template/adminStyle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888

8989
var updatePreviewTimeout;
9090

91-
var themeStylesheetBaseUrl = '<?php echo $url; ?>/css/wolfnet.theme.custom.php',
91+
var themeStylesheetBaseUrl = '<?php echo admin_url('admin-ajax.php') . '?action=wolfnet_theme_custom_css'; ?>',
9292
colorOptionsUrl = '<?php echo $colorOptionsUrl; ?>';
9393

9494
var $previewBox = $('#wolfnet-color-options-preview'),
Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
<?php
22

3-
header('Content-type: text/css; charset: UTF-8');
4-
5-
$styleDefaults = array(
6-
'colors' => array('#333'),
7-
'opacity' => 80,
8-
);
9-
10-
$userOptions = array();
11-
12-
if (!empty($_REQUEST['colors'])) {
13-
$userOptions['colors'] = explode(',', htmlspecialchars($_REQUEST['colors']));
14-
}
15-
16-
if (!empty($_REQUEST['opacity'])) {
17-
$userOptions['opacity'] = htmlspecialchars($_REQUEST['opacity']);
18-
}
19-
20-
$args = array_merge($styleDefaults, $userOptions);
21-
22-
233
function getColorPartDec ($colorPartHex, $colorPartLen = 2) {
244

255
// Convert single-digit values to multiples of hex 11
@@ -112,58 +92,58 @@ function vertGradient(array $startColor, array $endColor, $startOpacity=1, $endO
11292

11393

11494
// Get the color parts
115-
foreach ($args['colors'] as $colorKey => $colorVal) {
116-
$args['colors'][$colorKey] = getColorParts($colorVal);
95+
foreach ($colors as $colorKey => $colorVal) {
96+
$colors[$colorKey] = getColorParts($colorVal);
11797
}
11898

11999
// Make the opacity a percentage
120-
$args['opacity'] /= 100;
100+
$opacity /= 100;
121101

122102
?>
123103

124104
/* Agent Pages */
125105

126106
.wolfnet_widget.wolfnet_ao .wnt-btn.wnt-btn-primary,
127107
.wolfnet_widget.wolfnet_ao .wnt-btn.wnt-btn-active {
128-
background-color: <?php echo getHex($args['colors'][0]); ?>;
108+
background-color: <?php echo getHex($colors[0]); ?>;
129109
}
130110

131111
.wolfnet_widget.wolfnet_ao hr {
132-
border-color: <?php echo getHex($args['colors'][0]); ?>;
112+
border-color: <?php echo getHex($colors[0]); ?>;
133113
}
134114

135115
.wolfnet_widget.wolfnet_ao ul.wolfnet_aoLinks li .wnt-icon,
136116
.wolfnet_widget.wolfnet_ao ul.wolfnet_aoLinks li a,
137117
.wolfnet_widget.wolfnet_ao ul.wolfnet_aoLinks li a:hover,
138118
.wolfnet_widget.wolfnet_ao ul.wolfnet_aoLinks li a:active,
139119
.wolfnet_widget.wolfnet_ao ul.wolfnet_aoLinks li a:visited {
140-
color: <?php echo getHex($args['colors'][0]); ?>;
120+
color: <?php echo getHex($colors[0]); ?>;
141121
}
142122

143123
.wolfnet_widget.wolfnet_ao .wolfnet_aoSocial .wnt-icon {
144-
color: <?php echo getHex($args['colors'][0]); ?>;
124+
color: <?php echo getHex($colors[0]); ?>;
145125
}
146126

147127

148128
/* Birch Theme (Modern Lite) */
149129

150130
.wolfnet_widget.wolfnet-theme-birch.wolfnet_featuredListings .wolfnet_listing .wolfnet_listingHead .wolfnet_listingInfo,
151131
.wolfnet_widget.wolfnet-theme-birch.wolfnet_listingGrid .wolfnet_listing .wolfnet_listingHead .wolfnet_listingInfo {
152-
<?php echo vertGradient($args['colors'][0], $args['colors'][0], 0, $args['opacity']); ?>
132+
<?php echo vertGradient($colors[0], $colors[0], 0, $opacity); ?>
153133
}
154134

155135

156136
/* Cedar Theme (Modern Contrast) */
157137

158138
.wolfnet_widget.wolfnet-theme-cedar.wolfnet_featuredListings .wolfnet_listing .wolfnet_listingHead .wolfnet_listingInfo,
159139
.wolfnet_widget.wolfnet-theme-cedar.wolfnet_listingGrid .wolfnet_listing .wolfnet_listingHead .wolfnet_listingInfo {
160-
background-color: rgba(<?php echo getRGBA($args['colors'][0], $args['opacity']); ?>);
140+
background-color: rgba(<?php echo getRGBA($colors[0], $opacity); ?>);
161141
}
162142

163143

164144
/* Dogwood Theme (Modern Tile) */
165145

166146
.wolfnet_widget.wolfnet-theme-dogwood.wolfnet_featuredListings .wolfnet_listing .wolfnet_listingHead .wolfnet_listingInfo .wolfnet_price_rooms,
167147
.wolfnet_widget.wolfnet-theme-dogwood.wolfnet_listingGrid .wolfnet_listing .wolfnet_listingHead .wolfnet_listingInfo .wolfnet_price_rooms {
168-
background-color: rgba(<?php echo getRGBA($args['colors'][0], $args['opacity']); ?>);
148+
background-color: rgba(<?php echo getRGBA($colors[0], $opacity); ?>);
169149
}

0 commit comments

Comments
 (0)