Snazzy Maps - Version 1.1.5

Version Description

Release Date: August 1st, 2018

  • Update: Additional security fixes.
  • Update: Minimum supported version of WordPress has been increased from 2.8 to 3.0.
Download this release

Release Info

Developer atmistinc
Plugin Icon 128x128 Snazzy Maps
Version 1.1.5
Comparing to
See all releases

Code changes from version 1.1.4 to 1.1.5

additional_php/SnazzyMaps_Services_JSON.php CHANGED
@@ -55,7 +55,7 @@
55
  * @license http://www.opensource.org/licenses/bsd-license.php
56
  * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
57
  */
58
-
59
  /**
60
  * Marker constant for SnazzyMaps_Services_JSON::decode(), used to flag stack state
61
  */
@@ -619,7 +619,7 @@ class SnazzyMaps_Services_JSON
619
  $obj = array();
620
  } else {
621
  $stk = array(SnazzyMaps_Services_JSON_IN_OBJ);
622
- $obj = new stdClass();
623
  }
624
  }
625
 
55
  * @license http://www.opensource.org/licenses/bsd-license.php
56
  * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
57
  */
58
+ namespace SnazzyMaps;
59
  /**
60
  * Marker constant for SnazzyMaps_Services_JSON::decode(), used to flag stack state
61
  */
619
  $obj = array();
620
  } else {
621
  $stk = array(SnazzyMaps_Services_JSON_IN_OBJ);
622
+ $obj = new \stdClass();
623
  }
624
  }
625
 
admin/explore.php CHANGED
@@ -1,130 +1,131 @@
1
  <?php
 
2
  defined( 'ABSPATH' ) OR exit;
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- define('PAGE_SIZE', 3);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- function render_options($options, $selected){
8
- foreach((array)$options as $value => $text){
9
- ?>
10
- <option value="<?php echo esc_attr($value);?>" <?php echo esc_attr($value == $selected ? 'selected' : '') ?>>
11
- <?php echo esc_html($text);?>
12
- </option>
13
- <?php
14
- }
15
- }
16
 
17
- function admin_explore_head($tab){
18
-
19
- }
20
-
21
- function admin_explore_tab($tab){
22
-
23
- $sort = isset($_GET['sort']) ? $_GET['sort'] : '';
24
- $tag = isset($_GET['tag']) ? $_GET['tag'] : '';
25
- $color = isset($_GET['color']) ? $_GET['color'] : '';
26
- $type = isset($_GET['type']) ? $_GET['type'] : 'all';
27
- $text = isset($_GET['text']) ? $_GET['text'] : '';
28
- ?>
29
-
30
- <div id="explore-list">
31
- <form id="search-form" class="clearfix">
32
- <div class="search-box">
33
- <input name="text" type="text" placeholder="Search..." value="<?php echo esc_attr($text) ?>"/>
34
- <button class="button" type="submit">Search Styles</button>
35
- </div>
36
- </form>
37
- <div id="filters" class="clearfix">
38
- <select name="type">
39
- <?php
40
- $options = array("all" => "All Styles",
41
- "my-styles" => "My Styles",
42
- "my-favorites" => "My Favorites");
43
- render_options($options, $type);
44
- ?>
45
- </select>
46
- <select name="sort">
47
- <option value="">Sort by...</option>
48
- <?php
49
- $options = array("popular" => "Popular",
50
- "recent" => "Recent",
51
- "name" => "Name");
52
- render_options($options, $sort);
53
- ?>
54
- </select>
55
- <select name="tag">
56
- <option value="">Filter by Tag</option>
57
- <?php
58
- $options = array("colorful" => "Colorful",
59
- "complex" => "Complex",
60
- "dark" => "Dark",
61
- "greyscale" => "Greyscale",
62
- "light" => "Light",
63
- "monochrome" => "Monochrome",
64
- "no-labels" => "No Labels",
65
- "simple" => "Simple",
66
- "two-tone" => "Dark",
67
- "dark" => "Two Tone");
68
- render_options($options, $tag);
69
- ?>
70
- </select>
71
- <select name="color">
72
- <option value="">Filter By Color</option>
73
- <?php
74
- $options = array("black" => "Black",
75
- "blue" => "Blue",
76
- "gray" => "Gray",
77
- "green" => "Green",
78
- "multi" => "Multi",
79
- "orange" => "Orange",
80
- "purple" => "Purple",
81
- "red" => "Red",
82
- "white" => "White",
83
- "yellow" => "Yellow");
84
- render_options($options, $color);
85
- ?>
86
- </select>
87
- </div>
88
- <div class="tablenav top clearfix">
89
- <div class="tablenav-pages">
90
- <span class="displaying-num"># items</span>
91
- <span class="pagination-links">
92
- <a class="first-page" title="Go to the first page" href="#">«</a>
93
- <a class="prev-page" title="Go to the previous page" href="#">‹</a>
94
- <span class="paging-input">
95
- <label for="current-page-selector" class="screen-reader-text">Select Page</label>
96
- <input class="current-page" id="current-page-selector" title="Current page" type="text" name="paged" value="1" size="1">
97
- of
98
- <span class="total-pages">#</span>
99
- </span>
100
- <a class="next-page" title="Go to the next page" href="#">›</a>
101
- <a class="last-page" title="Go to the last page" href="#">»</a>
102
- </span>
103
- </div>
104
- </div>
105
-
106
- <div class="results row">
107
- </div>
108
- <div class="search-error nothing" style="display:none;">
109
- <p>No styles were found matching your current filters. Try widening your search a bit!</p>
110
- </div>
111
-
112
- <div class="tablenav bottom clearfix">
113
- <div class="tablenav-pages">
114
- <span class="displaying-num"># items</span>
115
- <span class="pagination-links">
116
- <a class="first-page" title="Go to the first page" href="#">«</a>
117
- <a class="prev-page" title="Go to the previous page" href="#">‹</a>
118
- <span class="paging-input">
119
- <label for="current-page-selector" class="screen-reader-text">Select Page</label>
120
- <input class="current-page" id="current-page-selector" title="Current page" type="text" name="paged" value="1" size="1">
121
- of
122
- <span class="total-pages">#</span>
123
- </span>
124
- <a class="next-page" title="Go to the next page" href="#">›</a>
125
- <a class="last-page" title="Go to the last page" href="#">»</a>
126
- </span>
127
- </div>
128
- </div>
129
- </div>
130
- <?php } ?>
1
  <?php
2
+ namespace SnazzyMaps;
3
  defined( 'ABSPATH' ) OR exit;
4
 
5
+ class SnazzyMaps_Explore {
6
+ public static function render_options($options, $selected){
7
+ foreach((array)$options as $value => $text){
8
+ ?>
9
+ <option value="<?php echo esc_attr($value);?>" <?php echo esc_attr($value == $selected ? 'selected' : '') ?>>
10
+ <?php echo esc_html($text);?>
11
+ </option>
12
+ <?php
13
+ }
14
+ }
15
+
16
+ public static function admin_explore_head($tab){
17
+
18
+ }
19
 
20
+ public static function admin_explore_tab($tab){
21
+
22
+ $sort = isset($_GET['sort']) ? sanitize_text_field($_GET['sort']) : '';
23
+ $tag = isset($_GET['tag']) ? sanitize_text_field($_GET['tag']) : '';
24
+ $color = isset($_GET['color']) ? sanitize_text_field($_GET['color']) : '';
25
+ $type = isset($_GET['type']) ? sanitize_text_field($_GET['type']) : 'all';
26
+ $text = isset($_GET['text']) ? sanitize_text_field($_GET['text']) : '';
27
+ ?>
28
+
29
+ <div id="explore-list">
30
+ <form id="search-form" class="clearfix">
31
+ <div class="search-box">
32
+ <input name="text" type="text" placeholder="Search..." value="<?php echo esc_attr($text) ?>"/>
33
+ <button class="button" type="submit">Search Styles</button>
34
+ </div>
35
+ </form>
36
+ <div id="filters" class="clearfix">
37
+ <select name="type">
38
+ <?php
39
+ $options = array("all" => "All Styles",
40
+ "my-styles" => "My Styles",
41
+ "my-favorites" => "My Favorites");
42
+ \SnazzyMaps\SnazzyMaps_Explore::render_options($options, $type);
43
+ ?>
44
+ </select>
45
+ <select name="sort">
46
+ <option value="">Sort by...</option>
47
+ <?php
48
+ $options = array("popular" => "Popular",
49
+ "recent" => "Recent",
50
+ "name" => "Name");
51
+ \SnazzyMaps\SnazzyMaps_Explore::render_options($options, $sort);
52
+ ?>
53
+ </select>
54
+ <select name="tag">
55
+ <option value="">Filter by Tag</option>
56
+ <?php
57
+ $options = array("colorful" => "Colorful",
58
+ "complex" => "Complex",
59
+ "dark" => "Dark",
60
+ "greyscale" => "Greyscale",
61
+ "light" => "Light",
62
+ "monochrome" => "Monochrome",
63
+ "no-labels" => "No Labels",
64
+ "simple" => "Simple",
65
+ "two-tone" => "Dark",
66
+ "dark" => "Two Tone");
67
+ \SnazzyMaps\SnazzyMaps_Explore::render_options($options, $tag);
68
+ ?>
69
+ </select>
70
+ <select name="color">
71
+ <option value="">Filter By Color</option>
72
+ <?php
73
+ $options = array("black" => "Black",
74
+ "blue" => "Blue",
75
+ "gray" => "Gray",
76
+ "green" => "Green",
77
+ "multi" => "Multi",
78
+ "orange" => "Orange",
79
+ "purple" => "Purple",
80
+ "red" => "Red",
81
+ "white" => "White",
82
+ "yellow" => "Yellow");
83
+ \SnazzyMaps\SnazzyMaps_Explore::render_options($options, $color);
84
+ ?>
85
+ </select>
86
+ </div>
87
+ <div class="tablenav top clearfix">
88
+ <div class="tablenav-pages">
89
+ <span class="displaying-num"># items</span>
90
+ <span class="pagination-links">
91
+ <a class="first-page" title="Go to the first page" href="#">«</a>
92
+ <a class="prev-page" title="Go to the previous page" href="#">‹</a>
93
+ <span class="paging-input">
94
+ <label for="current-page-selector" class="screen-reader-text">Select Page</label>
95
+ <input class="current-page" id="current-page-selector" title="Current page" type="text" name="paged" value="1" size="1">
96
+ of
97
+ <span class="total-pages">#</span>
98
+ </span>
99
+ <a class="next-page" title="Go to the next page" href="#">›</a>
100
+ <a class="last-page" title="Go to the last page" href="#">»</a>
101
+ </span>
102
+ </div>
103
+ </div>
104
 
105
+ <div class="results row">
106
+ </div>
107
+ <div class="search-error nothing" style="display:none;">
108
+ <p>No styles were found matching your current filters. Try widening your search a bit!</p>
109
+ </div>
 
 
 
 
110
 
111
+ <div class="tablenav bottom clearfix">
112
+ <div class="tablenav-pages">
113
+ <span class="displaying-num"># items</span>
114
+ <span class="pagination-links">
115
+ <a class="first-page" title="Go to the first page" href="#">«</a>
116
+ <a class="prev-page" title="Go to the previous page" href="#">‹</a>
117
+ <span class="paging-input">
118
+ <label for="current-page-selector" class="screen-reader-text">Select Page</label>
119
+ <input class="current-page" id="current-page-selector" title="Current page" type="text" name="paged" value="1" size="1">
120
+ of
121
+ <span class="total-pages">#</span>
122
+ </span>
123
+ <a class="next-page" title="Go to the next page" href="#">›</a>
124
+ <a class="last-page" title="Go to the last page" href="#">»</a>
125
+ </span>
126
+ </div>
127
+ </div>
128
+ </div>
129
+ <?php
130
+ }
131
+ } ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/help.php CHANGED
@@ -1,13 +1,15 @@
1
  <?php
 
2
  defined( 'ABSPATH' ) OR exit;
3
 
4
 
 
5
 
6
- function admin_help_head($tab){
7
 
8
  }
9
 
10
- function admin_help_tab($tab){
11
  ?>
12
 
13
  <div class="row">
@@ -55,4 +57,7 @@ defined( 'ABSPATH' ) OR exit;
55
  </div>
56
  </div>
57
 
58
- <?php } ?>
 
 
 
1
  <?php
2
+ namespace SnazzyMaps;
3
  defined( 'ABSPATH' ) OR exit;
4
 
5
 
6
+ class SnazzyMaps_Help {
7
 
8
+ public static function admin_help_head($tab){
9
 
10
  }
11
 
12
+ public static function admin_help_tab($tab){
13
  ?>
14
 
15
  <div class="row">
57
  </div>
58
  </div>
59
 
60
+ <?php
61
+ }
62
+ }
63
+ ?>
admin/helpers.php CHANGED
@@ -1,7 +1,11 @@
1
  <?php
 
 
2
  defined( 'ABSPATH' ) OR exit;
3
 
4
- function esc_rel_url($url){
5
- return preg_replace('/^http:\/\//', '', esc_url($url));
 
 
6
  }
7
  ?>
1
  <?php
2
+ namespace SnazzyMaps;
3
+
4
  defined( 'ABSPATH' ) OR exit;
5
 
6
+ class SnazzyMaps_Helpers {
7
+ public static function esc_rel_url($url){
8
+ return preg_replace('/^http:\/\//', '', esc_url($url));
9
+ }
10
  }
11
  ?>
admin/index.js CHANGED
@@ -1,199 +1,215 @@
1
- jQuery(document).ready(function($){
2
-
3
- var showError = function(message){
4
- $(".search-error").html(message).show();
5
- $(".results").hide();
6
- $(".tablenav-pages").hide();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  }
8
- var hideError = function(){
9
- $(".search-error").hide();
10
- $(".results").show();
11
- $(".tablenav-pages").show();
 
 
 
 
12
  }
13
-
14
- //Style list with pagination and filtering
15
- var refreshExplore = function(){
16
- var params = simpleQueryString.parse(location.search);
17
- var data = {};
18
- data['pageSize'] = 12;
19
- data['page'] = params.ppage;
20
- data['sort'] = params.sort;
21
- data['color'] = params.color;
22
- data['tag'] = params.tag;
23
- data['text'] = params.text;
24
-
25
- var endPoint = '';
26
- if(params.type == 'my-styles'){
27
- endPoint = 'my-styles.json';
28
- data['key'] = SnazzyData['USER_API_KEY'];
29
- if(SnazzyData['USER_API_KEY'] == null){
30
- showError('<p>You need to add your API key in the <a href="?page=snazzy_maps&tab=2">Settings</a> tab.</p>');
31
- return;
32
- }
33
-
34
- }else if(params.type == 'my-favorites'){
35
- endPoint = 'favorites.json';
36
- data['key'] = SnazzyData['USER_API_KEY'];
37
- if(SnazzyData['USER_API_KEY'] == null){
38
- showError('<p>You need to add your API key in the <a href="?page=snazzy_maps&tab=2">Settings</a> tab.</p>');
39
- return;
40
- }
41
  }
42
- else{
43
- endPoint = 'explore.json';
44
- data['key'] = SnazzyData['API_KEY'];
45
- $('.missing-api-key').hide();
46
- $('.results').show();
47
- $('.pagination').show();
48
- }
49
-
50
-
51
- //Clean up the data before getting the response
52
- for(var key in data){
53
- if(data[key] == undefined || data[key] == null || data[key] == "undefined"){
54
- delete data[key];
55
- }
56
- }
57
-
58
- var failedTimeout = setTimeout(function(){
59
- showError("<p>Oops, it seems that Snazzy Maps is temporarily down or your API key is incorrect.</p>");
60
- }, 3000);
61
- $.ajax({
62
- url: SnazzyData['API_BASE'] + endPoint,
63
- jsonp: 'callback',
64
- data: data,
65
- dataType: 'jsonp',
66
- success: function(response) {
67
- clearTimeout(failedTimeout);
68
-
69
- if('statusCode' in response && response['statusCode'] != 200){
70
- showError("<p>Oops, it seems that Snazzy Maps is temporarily down or your API key is incorrect.</p>");
71
- }else{
72
- updatePagination(response['pagination']);
73
- renderStyles($('#explore-list').find('.results'), response['styles']);
74
- }
75
- },
76
- error: function(response){
77
- clearTimeout(failedTimeout);
78
- showError("<p>Oops, it seems that Snazzy Maps is temporarily down or your API key is incorrect.</p>");
79
- }
80
- });
81
-
82
- //JSONP doesn't support native jQuery errors
83
- };
84
-
85
- var styleTemplate = $('#style-template').html();
86
- var renderStyles = function(container, styles){
87
- container.html('');
88
- $.each(styles, function(i,style){
89
- var data = {
90
- name: style['name'],
91
- imageUrl: style['imageUrl'],
92
- url: style['url'],
93
- author: style['createdBy']['name'],
94
- views: style['views'],
95
- favorites: style['favorites']
96
- };
97
-
98
- //Add to the last row
99
- container.append($(Mustache.to_html(styleTemplate, data)).data('style', style));
100
- });
101
- };
102
-
103
- History.Adapter.bind(window,'statechange', function(){
104
- refreshExplore();
105
- });
106
- $(window).trigger('statechange');
107
-
108
- //An easy way to replace the GET parameters and also replace the state at the same time
109
- var replaceGET = function(params){
110
- var oldParams = simpleQueryString.parse(location.search);
111
- for(var key in params)
112
- {
113
- oldParams[key] = params[key];
114
- }
115
- History.replaceState(oldParams, document.title, '?' + simpleQueryString.stringify(oldParams));
116
- };
117
-
118
- $('#explore-list select').live('change', function(){
119
- var q = {};
120
- q[this.name] = $(this).val();
121
- q['ppage'] = 1; //Reset the page number because we are changing the results
122
- replaceGET(q);
123
- });
124
- $('#search-form').live('submit', function(){
125
- replaceGET({
126
- text: $(this).find('input[name="text"]').val(),
127
- ppage: 1 //Reset the page number because we are changing the results
128
- });
129
- return false;
130
  });
131
-
132
- $('.style').live('submit', function(){
133
- $(this).find('input[name="new_style"]')
134
- .val(encodeURIComponent(JSON.stringify($(this).data('style'))));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  });
136
-
137
- //Pagination
138
- $('.tablenav-pages a').live('click', function(){
139
- replaceGET({ ppage: $(this).data('page') });
140
- return false;
141
- });
142
-
143
- $('.current-page').live('change', function(){
144
-
145
- var start = $('.first-page').data('page');
146
- var end = $('.last-page').data('page');
147
- var page = parseInt($(this).val(), 10);
148
- if ($(this).val() == page && page >= start && page <= end){
149
- replaceGET({ ppage: page });
150
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  });
152
-
153
- var updatePagination = function (options){
154
-
155
- var page = options['currentPage'];
156
-
157
- if(options['totalItems'] == 0){
158
- showError('<p>No styles were found matching your current filters. Try widening your search a bit!</p>');
159
- return;
160
- }
161
- else{
162
- hideError();
163
- }
164
-
165
- $('.first-page').toggleClass('disabled', options['currentPage'] <= 1);
166
- $('.first-page').data('page', 1);
167
-
168
- $('.prev-page').toggleClass('disabled', options['currentPage'] <= 1);
169
- $('.prev-page').data('page', options['currentPage']*1 - 1);
170
-
171
- $('.next-page').toggleClass('disabled', options['currentPage'] >= options['totalPages']);
172
- $('.next-page').data('page', options['currentPage']*1 + 1);
173
-
174
- $('.last-page').toggleClass('disabled', options['currentPage'] >= options['totalPages']);
175
- $('.last-page').data('page', options['totalPages']);
176
-
177
- if(options['totalItems'] > 1){
178
- $('.tablenav-pages .displaying-num').html(options['totalItems'] + ' items');
179
- }
180
- else if(options['totalItems'] == 1){
181
- $('.tablenav-pages .displaying-num').html('1 item');
182
- }
183
- else{
184
- $('.tablenav-pages .displaying-num').html('0 items');
185
- }
186
-
187
- $('.tablenav-pages .total-pages').html(options['totalPages']);
188
- if(options['totalPages'] > 0){
189
- $('.current-page').val(options['currentPage']);
190
- $('.current-page').attr('disabled', false);
191
- }
192
- else{
193
- $('.current-page').val(0);
194
- $('.current-page').attr('disabled', true);
195
- }
196
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  }
 
198
  });
199
-
1
+ jQuery(document).ready(function($) {
2
+ var showError = function(message) {
3
+ $(".search-error").html(message).show();
4
+ $(".results").hide();
5
+ $(".tablenav-pages").hide();
6
+ };
7
+ var hideError = function() {
8
+ $(".search-error").hide();
9
+ $(".results").show();
10
+ $(".tablenav-pages").show();
11
+ };
12
+
13
+ //Style list with pagination and filtering
14
+ var refreshExplore = function() {
15
+ var params = simpleQueryString.parse(location.search);
16
+ var data = {};
17
+ data["pageSize"] = 12;
18
+ data["page"] = params.ppage;
19
+ data["sort"] = params.sort;
20
+ data["color"] = params.color;
21
+ data["tag"] = params.tag;
22
+ data["text"] = params.text;
23
+
24
+ var endPoint = "";
25
+ if (params.type == "my-styles") {
26
+ endPoint = "my-styles.json";
27
+ data["key"] = SnazzyData["USER_API_KEY"];
28
+ if (SnazzyData["USER_API_KEY"] == null) {
29
+ showError(
30
+ '<p>You need to add your API key in the <a href="?page=snazzy_maps&tab=2">Settings</a> tab.</p>'
31
+ );
32
+ return;
33
+ }
34
+ } else if (params.type == "my-favorites") {
35
+ endPoint = "favorites.json";
36
+ data["key"] = SnazzyData["USER_API_KEY"];
37
+ if (SnazzyData["USER_API_KEY"] == null) {
38
+ showError(
39
+ '<p>You need to add your API key in the <a href="?page=snazzy_maps&tab=2">Settings</a> tab.</p>'
40
+ );
41
+ return;
42
+ }
43
+ } else {
44
+ endPoint = "explore.json";
45
+ data["key"] = SnazzyData["API_KEY"];
46
+ $(".missing-api-key").hide();
47
+ $(".results").show();
48
+ $(".pagination").show();
49
  }
50
+
51
+ //Clean up the data before getting the response
52
+ for (var key in data) {
53
+ if (
54
+ data[key] == undefined || data[key] == null || data[key] == "undefined"
55
+ ) {
56
+ delete data[key];
57
+ }
58
  }
59
+
60
+ var failedTimeout = setTimeout(function() {
61
+ showError(
62
+ "<p>Oops, it seems that Snazzy Maps is temporarily down or your API key is incorrect.</p>"
63
+ );
64
+ }, 3000);
65
+ $.ajax({
66
+ url: SnazzyData["API_BASE"] + endPoint,
67
+ jsonp: "callback",
68
+ data: data,
69
+ dataType: "jsonp",
70
+ success: function(response) {
71
+ clearTimeout(failedTimeout);
72
+
73
+ if ("statusCode" in response && response["statusCode"] != 200) {
74
+ showError(
75
+ "<p>Oops, it seems that Snazzy Maps is temporarily down or your API key is incorrect.</p>"
76
+ );
77
+ } else {
78
+ updatePagination(response["pagination"]);
79
+ renderStyles($("#explore-list").find(".results"), response["styles"]);
 
 
 
 
 
 
 
80
  }
81
+ },
82
+ error: function(response) {
83
+ clearTimeout(failedTimeout);
84
+ showError(
85
+ "<p>Oops, it seems that Snazzy Maps is temporarily down or your API key is incorrect.</p>"
86
+ );
87
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  });
89
+
90
+ //JSONP doesn't support native jQuery errors
91
+ };
92
+
93
+ var styleTemplate = $("#style-template").html();
94
+ var renderStyles = function(container, styles) {
95
+ container.html("");
96
+ $.each(styles, function(i, style) {
97
+ var data = {
98
+ name: style["name"],
99
+ imageUrl: style["imageUrl"],
100
+ url: style["url"],
101
+ author: style["createdBy"]["name"],
102
+ views: style["views"],
103
+ favorites: style["favorites"]
104
+ };
105
+
106
+ //Add to the last row
107
+ container.append(
108
+ $(Mustache.to_html(styleTemplate, data)).data("style", style)
109
+ );
110
  });
111
+ };
112
+
113
+ History.Adapter.bind(window, "statechange", function() {
114
+ refreshExplore();
115
+ });
116
+ $(window).trigger("statechange");
117
+
118
+ //An easy way to replace the GET parameters and also replace the state at the same time
119
+ var replaceGET = function(params) {
120
+ var oldParams = simpleQueryString.parse(location.search);
121
+ for (var key in params) {
122
+ oldParams[key] = params[key];
123
+ }
124
+ History.replaceState(
125
+ oldParams,
126
+ document.title,
127
+ "?" + simpleQueryString.stringify(oldParams)
128
+ );
129
+ };
130
+
131
+ $("#explore-list select").live("change", function() {
132
+ var q = {};
133
+ q[this.name] = $(this).val();
134
+ q["ppage"] = 1; //Reset the page number because we are changing the results
135
+ replaceGET(q);
136
+ });
137
+ $("#search-form").live("submit", function() {
138
+ replaceGET({
139
+ text: $(this).find('input[name="text"]').val(),
140
+ ppage: 1 //Reset the page number because we are changing the results
141
  });
142
+ return false;
143
+ });
144
+
145
+ $(".style").live("submit", function() {
146
+ $(this)
147
+ .find('input[name="new_style"]')
148
+ .val(encodeURIComponent(JSON.stringify($(this).data("style"))));
149
+ });
150
+
151
+ //Pagination
152
+ $(".tablenav-pages a").live("click", function() {
153
+ replaceGET({ ppage: $(this).data("page") });
154
+ return false;
155
+ });
156
+
157
+ $(".current-page").live("change", function() {
158
+ var start = $(".first-page").data("page");
159
+ var end = $(".last-page").data("page");
160
+ var page = parseInt($(this).val(), 10);
161
+ if ($(this).val() == page && page >= start && page <= end) {
162
+ replaceGET({ ppage: page });
163
+ }
164
+ });
165
+
166
+ var updatePagination = function(options) {
167
+ var page = options["currentPage"];
168
+
169
+ if (options["totalItems"] == 0) {
170
+ showError(
171
+ "<p>No styles were found matching your current filters. Try widening your search a bit!</p>"
172
+ );
173
+ return;
174
+ } else {
175
+ hideError();
176
+ }
177
+
178
+ $(".first-page").toggleClass("disabled", options["currentPage"] <= 1);
179
+ $(".first-page").data("page", 1);
180
+
181
+ $(".prev-page").toggleClass("disabled", options["currentPage"] <= 1);
182
+ $(".prev-page").data("page", options["currentPage"] * 1 - 1);
183
+
184
+ $(".next-page").toggleClass(
185
+ "disabled",
186
+ options["currentPage"] >= options["totalPages"]
187
+ );
188
+ $(".next-page").data("page", options["currentPage"] * 1 + 1);
189
+
190
+ $(".last-page").toggleClass(
191
+ "disabled",
192
+ options["currentPage"] >= options["totalPages"]
193
+ );
194
+ $(".last-page").data("page", options["totalPages"]);
195
+
196
+ if (options["totalItems"] > 1) {
197
+ $(".tablenav-pages .displaying-num").html(
198
+ options["totalItems"] + " items"
199
+ );
200
+ } else if (options["totalItems"] == 1) {
201
+ $(".tablenav-pages .displaying-num").html("1 item");
202
+ } else {
203
+ $(".tablenav-pages .displaying-num").html("0 items");
204
+ }
205
+
206
+ $(".tablenav-pages .total-pages").html(options["totalPages"]);
207
+ if (options["totalPages"] > 0) {
208
+ $(".current-page").val(options["currentPage"]);
209
+ $(".current-page").attr("disabled", false);
210
+ } else {
211
+ $(".current-page").val(0);
212
+ $(".current-page").attr("disabled", true);
213
  }
214
+ };
215
  });
 
admin/index.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
  defined( 'ABSPATH' ) OR exit;
3
 
4
  include_once(plugin_dir_path(__FILE__) . _DS . 'styles.php');
@@ -7,138 +9,143 @@ include_once(plugin_dir_path(__FILE__) . _DS . 'settings.php');
7
  include_once(plugin_dir_path(__FILE__) . _DS . 'help.php');
8
  include_once(plugin_dir_path(__FILE__) . _DS . 'helpers.php');
9
 
 
10
 
11
- function admin_perform_post (){
12
- if($_SERVER['REQUEST_METHOD'] === 'POST'){
13
-
14
- //Perform the post for the tab that was selected
15
- $active_tab = isset($_GET['tab']) ? $_GET['tab'] : null;
16
-
17
- if($active_tab == 0){ admin_styles_head(0); }
18
- if($active_tab == 1){ admin_explore_head(1); }
19
- if($active_tab == 2){ admin_my_snazzymaps_head(2); }
20
- if($active_tab == 3){ admin_help_head(3); }
21
-
22
- //Redirect to the next page
23
- if(!headers_sent()){
24
- header('Location: '. $_SERVER['REQUEST_URI']);
25
- exit();
26
- }
27
- }
28
- }
29
 
30
- function admin_enqueue_script($hook){
31
 
32
- //Only include the javascript in our page
33
- if($hook != 'appearance_page_snazzy_maps') return;
34
-
35
- //Include the javascript
36
- $handle = 'admin-snazzymaps-js';
37
- wp_enqueue_script($handle, plugins_url('index.js', __FILE__), $deps = array('jquery'),
38
- $ver = SNAZZY_VERSION_NUMBER);
39
- wp_localize_script($handle, 'SnazzyData', array('API_KEY' => API_KEY,
40
- 'API_BASE' => API_BASE,
41
- 'USER_API_KEY' => get_option('MySnazzyAPIKey', null)));
42
-
43
- //Include the bower components
44
- $bower_components = array(
45
- //history js
46
- 'history.js' . _DS . 'scripts' .
47
- _DS . 'bundled' . _DS . 'html5' .
48
- _DS . 'native.history.js',
49
- //simplequerystring
50
- 'simple-query-string' . _DS . 'src' .
51
- _DS . 'simplequerystring.min.js',
52
- //mustache
53
- 'mustache' . _DS . 'mustache.min.js'
54
- );
55
- foreach((array)$bower_components as $index => $bower_component){
56
- wp_enqueue_script("admin-bower-component-$index",
57
- resourceURL('bower_components' . _DS . $bower_component),
58
- $deps = array(),
59
- $ver = SNAZZY_VERSION_NUMBER);
60
- }
61
-
62
- //Include the css
63
- wp_enqueue_style('admin-snazzymaps-css',
64
- plugins_url('index.css', __FILE__),
65
- $deps = array(),
66
- $ver = SNAZZY_VERSION_NUMBER);
67
- }
68
 
69
- function admin_add_custom_content(){
70
- $active_tab = isset($_GET['tab']) ? $_GET['tab'] : '0';
71
-
72
- if(isset($_GET['welcome'])) {
73
- update_option('HideWelcomeMessage', $_GET['welcome'] == 'hide');
74
- }
75
- ?>
76
- <div class="wrap sm-plugin">
77
- <h2>Snazzy Maps</h2>
78
- <script id="style-template" type="text/template">
79
- <form action="?page=snazzy_maps&tab=0" method="POST" class="col-sm-6 col-md-4 style">
80
- <div class="sm-style">
81
- <div class="sm-map">
82
- <img src="{{imageUrl}}" alt="{{name}}"/>
83
- </div>
84
- <div class="sm-content info">
85
- <h3><a href="{{url}}" class="title" target="_blank" title="Check out {{name}} on Snazzy Maps">{{name}}</a></h3>
86
- <div class="author">by {{author}}</div>
87
- <div class="stats">
88
- <div class="views"><span class="icon-eye" title="Views"></span>{{views}}</div>
89
- <div class="favorites"><span class="icon-star" title="Favorites"></span>{{favorites}} favorites</div>
90
- </div>
91
- <button class="button button-primary button-large" type="submit">SAVE STYLE</button>
92
- <input type="hidden" name="new_style" value=""/>
93
- </div>
94
- </div>
95
- </form>
96
- </script>
97
- <?php if(!get_option('HideWelcomeMessage', false)) { ?>
98
- <div id="welcome-panel" class="box-shadow-cell welcome-panel">
99
- <a href="<?php echo esc_rel_url('?page=snazzy_maps&tab=' . $active_tab . '&welcome=hide'); ?>" class="welcome-panel-close">Dismiss</a>
100
- <div class="row">
101
- <div class="col-md-10 col-lg-6">
102
- <h3>Welcome!</h3>
103
- <p>
104
- Thanks for installing the Snazzy Maps plugin! <a href="?page=snazzy_maps&tab=1">Explore</a> some styles to get started
105
- or check out the <a href="?page=snazzy_maps&tab=3">Help</a> page for detailed instructions and frequently asked questions.
106
- </p>
107
- </div>
108
- </div>
109
- </div>
110
- <?php } ?>
111
- <div class="row">
112
- <div class="nav-tab-container col-md-12">
113
- <h2 class="nav-tab-wrapper">
114
- <?php
115
- $tabs = array('Site Styles', 'Explore', 'Settings', 'Help');
116
- foreach((array)$tabs as $index => $tab){
117
- ?>
118
- <a href="<?php echo esc_rel_url('?page=snazzy_maps&tab=' . $index);?>"
119
- class="nav-tab <?php echo esc_attr($active_tab == $index ? 'nav-tab-active' : '');?>">
120
- <?php echo esc_html($tab);?>
121
- </a>
122
- <?php
123
- }
124
- ?>
125
- </h2>
126
- <?php if($active_tab == 0) { admin_styles_tab(0); } ?>
127
- <?php if($active_tab == 1) { admin_explore_tab(1); } ?>
128
- <?php if($active_tab == 2) { admin_my_snazzymaps_tab(2); } ?>
129
- <?php if($active_tab == 3) { admin_help_tab(3); } ?>
130
- </div>
131
- </div>
132
- <div class="footer">
133
- <div class="container-fluid">
134
- <a href="https://snazzymaps.com/" class="icon-brand" target="_blank"></a>
135
- <div class="social clearfix">
136
- <a href="https://twitter.com/snazzymaps" class="icon-twitter" target="_blank"></a>
137
- <a href="https://www.facebook.com/SnazzyMaps" class="icon-facebook" target="_blank"></a>
138
- <a href="https://google.com/+SnazzyMaps" class="icon-googleplus" target="_blank"></a>
139
- <a href="mailto:support@snazzymaps.com" class="icon-mail" target="_blank"></a>
140
- </div>
141
- </div>
142
- </div>
143
- </div>
144
- <?php } ?>
 
 
 
 
1
  <?php
2
+ namespace SnazzyMaps;
3
+
4
  defined( 'ABSPATH' ) OR exit;
5
 
6
  include_once(plugin_dir_path(__FILE__) . _DS . 'styles.php');
9
  include_once(plugin_dir_path(__FILE__) . _DS . 'help.php');
10
  include_once(plugin_dir_path(__FILE__) . _DS . 'helpers.php');
11
 
12
+ class SnazzyMaps_Index {
13
 
14
+ public static function admin_perform_post (){
15
+ if($_SERVER['REQUEST_METHOD'] === 'POST'){
16
+
17
+ //Perform the post for the tab that was selected
18
+ $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : null;
19
+
20
+ if($active_tab == 0){ \SnazzyMaps\SnazzyMaps_Styles::admin_styles_head(0); }
21
+ if($active_tab == 1){ \SnazzyMaps\SnazzyMaps_Explore::admin_explore_head(1); }
22
+ if($active_tab == 2){ \SnazzyMaps\SnazzyMaps_Settings::admin_my_snazzymaps_head(2); }
23
+ if($active_tab == 3){ \SnazzyMaps\SnazzyMaps_Help::admin_help_head(3); }
24
+
25
+ //Redirect to the next page
26
+ if(!headers_sent()){
27
+ header('Location: '. $_SERVER['REQUEST_URI']);
28
+ exit();
29
+ }
30
+ }
31
+ }
32
 
33
+ public static function admin_enqueue_script($hook){
34
 
35
+ //Only include the javascript in our page
36
+ if($hook != 'appearance_page_snazzy_maps') return;
37
+
38
+ //Include the javascript
39
+ $handle = 'admin-snazzymaps-js';
40
+ wp_enqueue_script($handle, plugins_url('index.js', __FILE__), $deps = array('jquery'),
41
+ $ver = SNAZZY_MAPS_VERSION_NUMBER);
42
+ wp_localize_script($handle, 'SnazzyData', array('API_KEY' => SNAZZY_MAPS_API_KEY,
43
+ 'API_BASE' => SNAZZY_MAPS_API_BASE,
44
+ 'USER_API_KEY' => get_option('MySnazzyAPIKey', null)));
45
+
46
+ //Include the bower components
47
+ $bower_components = array(
48
+ //history js
49
+ 'history.js' . _DS . 'scripts' .
50
+ _DS . 'bundled' . _DS . 'html5' .
51
+ _DS . 'native.history.js',
52
+ //simplequerystring
53
+ 'simple-query-string' . _DS . 'src' .
54
+ _DS . 'simplequerystring.min.js',
55
+ //mustache
56
+ 'mustache' . _DS . 'mustache.min.js'
57
+ );
58
+ foreach((array)$bower_components as $index => $bower_component){
59
+ wp_enqueue_script("admin-bower-component-$index",
60
+ \SnazzyMaps\SnazzyMaps_Main::resourceURL('bower_components' . _DS . $bower_component),
61
+ $deps = array(),
62
+ $ver = SNAZZY_MAPS_VERSION_NUMBER);
63
+ }
64
+
65
+ //Include the css
66
+ wp_enqueue_style('admin-snazzymaps-css',
67
+ plugins_url('index.css', __FILE__),
68
+ $deps = array(),
69
+ $ver = SNAZZY_MAPS_VERSION_NUMBER);
70
+ }
71
 
72
+ public static function admin_add_custom_content(){
73
+ $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : '0';
74
+
75
+ if(isset($_GET['welcome'])) {
76
+ update_option('HideWelcomeMessage', sanitize_text_field($_GET['welcome']) == 'hide');
77
+ }
78
+ ?>
79
+ <div class="wrap sm-plugin">
80
+ <h2>Snazzy Maps</h2>
81
+ <script id="style-template" type="text/template">
82
+ <form action="?page=snazzy_maps&tab=0" method="POST" class="col-sm-6 col-md-4 style">
83
+ <div class="sm-style">
84
+ <div class="sm-map">
85
+ <img src="{{imageUrl}}" alt="{{name}}"/>
86
+ </div>
87
+ <div class="sm-content info">
88
+ <h3><a href="{{url}}" class="title" target="_blank" title="Check out {{name}} on Snazzy Maps">{{name}}</a></h3>
89
+ <div class="author">by {{author}}</div>
90
+ <div class="stats">
91
+ <div class="views"><span class="icon-eye" title="Views"></span>{{views}}</div>
92
+ <div class="favorites"><span class="icon-star" title="Favorites"></span>{{favorites}} favorites</div>
93
+ </div>
94
+ <button class="button button-primary button-large" type="submit">SAVE STYLE</button>
95
+ <input type="hidden" name="new_style" value=""/>
96
+ <?php wp_nonce_field( 'snazzy_maps_save_style' ); ?>
97
+ </div>
98
+ </div>
99
+ </form>
100
+ </script>
101
+ <?php if(!get_option('HideWelcomeMessage', false)) { ?>
102
+ <div id="welcome-panel" class="box-shadow-cell welcome-panel">
103
+ <a href="<?php echo \SnazzyMaps\SnazzyMaps_Helpers::esc_rel_url('?page=snazzy_maps&tab=' . $active_tab . '&welcome=hide'); ?>" class="welcome-panel-close">Dismiss</a>
104
+ <div class="row">
105
+ <div class="col-md-10 col-lg-6">
106
+ <h3>Welcome!</h3>
107
+ <p>
108
+ Thanks for installing the Snazzy Maps plugin! <a href="?page=snazzy_maps&tab=1">Explore</a> some styles to get started
109
+ or check out the <a href="?page=snazzy_maps&tab=3">Help</a> page for detailed instructions and frequently asked questions.
110
+ </p>
111
+ </div>
112
+ </div>
113
+ </div>
114
+ <?php } ?>
115
+ <div class="row">
116
+ <div class="nav-tab-container col-md-12">
117
+ <h2 class="nav-tab-wrapper">
118
+ <?php
119
+ $tabs = array('Site Styles', 'Explore', 'Settings', 'Help');
120
+ foreach((array)$tabs as $index => $tab){
121
+ ?>
122
+ <a href="<?php echo \SnazzyMaps\SnazzyMaps_Helpers::esc_rel_url('?page=snazzy_maps&tab=' . $index);?>"
123
+ class="nav-tab <?php echo esc_attr($active_tab == $index ? 'nav-tab-active' : '');?>">
124
+ <?php echo esc_html($tab);?>
125
+ </a>
126
+ <?php
127
+ }
128
+ ?>
129
+ </h2>
130
+ <?php if($active_tab == 0) { \SnazzyMaps\SnazzyMaps_Styles::admin_styles_tab(0); } ?>
131
+ <?php if($active_tab == 1) { \SnazzyMaps\SnazzyMaps_Explore::admin_explore_tab(1); } ?>
132
+ <?php if($active_tab == 2) { \SnazzyMaps\SnazzyMaps_Settings::admin_my_snazzymaps_tab(2); } ?>
133
+ <?php if($active_tab == 3) { \SnazzyMaps\SnazzyMaps_Help::admin_help_tab(3); } ?>
134
+ </div>
135
+ </div>
136
+ <div class="footer">
137
+ <div class="container-fluid">
138
+ <a href="https://snazzymaps.com/" class="icon-brand" target="_blank"></a>
139
+ <div class="social clearfix">
140
+ <a href="https://twitter.com/snazzymaps" class="icon-twitter" target="_blank"></a>
141
+ <a href="https://www.facebook.com/SnazzyMaps" class="icon-facebook" target="_blank"></a>
142
+ <a href="https://google.com/+SnazzyMaps" class="icon-googleplus" target="_blank"></a>
143
+ <a href="mailto:support@snazzymaps.com" class="icon-mail" target="_blank"></a>
144
+ </div>
145
+ </div>
146
+ </div>
147
+ </div>
148
+ <?php
149
+ }
150
+ }
151
+ ?>
admin/settings.php CHANGED
@@ -1,16 +1,17 @@
1
  <?php
 
2
  defined( 'ABSPATH' ) OR exit;
3
 
4
 
5
-
6
- function admin_my_snazzymaps_head($tab){
7
- if(isset($_POST['api_key'])){
8
- update_option('MySnazzyAPIKey', $_POST['api_key']);
9
  }
10
  }
11
 
12
- function admin_my_snazzymaps_tab($tab){
13
- if(isset($_GET['action']) && $_GET['action'] == 'delete_key'){
14
  delete_option('MySnazzyAPIKey');
15
  }
16
  $api_key = get_option('MySnazzyAPIKey', null);
@@ -29,6 +30,7 @@ defined( 'ABSPATH' ) OR exit;
29
  <label for="api_key"><strong>API Key</strong></label>
30
  <input type="text" id="api_key" name="api_key"
31
  placeholder="Enter your API Key" value="<?php echo esc_attr($api_key); ?>"/>
 
32
  <button type="submit" class="button button-primary">SAVE</button>
33
  <?php if(!is_null($api_key)){ ?>
34
  <a href="?page=snazzy_maps&tab=2&action=delete_key"
@@ -38,4 +40,7 @@ defined( 'ABSPATH' ) OR exit;
38
  </div>
39
  </div>
40
 
41
- <?php } ?>
 
 
 
1
  <?php
2
+ namespace SnazzyMaps;
3
  defined( 'ABSPATH' ) OR exit;
4
 
5
 
6
+ class SnazzyMaps_Settings {
7
+ public static function admin_my_snazzymaps_head($tab){
8
+ if(isset($_POST['api_key']) && check_admin_referer('snazzy_maps_save_api_key')){
9
+ update_option('MySnazzyAPIKey', sanitize_text_field($_POST['api_key']));
10
  }
11
  }
12
 
13
+ public static function admin_my_snazzymaps_tab($tab){
14
+ if(isset($_GET['action']) && sanitize_text_field($_GET['action']) == 'delete_key'){
15
  delete_option('MySnazzyAPIKey');
16
  }
17
  $api_key = get_option('MySnazzyAPIKey', null);
30
  <label for="api_key"><strong>API Key</strong></label>
31
  <input type="text" id="api_key" name="api_key"
32
  placeholder="Enter your API Key" value="<?php echo esc_attr($api_key); ?>"/>
33
+ <?php wp_nonce_field( 'snazzy_maps_save_api_key' ); ?>
34
  <button type="submit" class="button button-primary">SAVE</button>
35
  <?php if(!is_null($api_key)){ ?>
36
  <a href="?page=snazzy_maps&tab=2&action=delete_key"
40
  </div>
41
  </div>
42
 
43
+ <?php
44
+ }
45
+ }
46
+ ?>
admin/styles.php CHANGED
@@ -1,9 +1,11 @@
1
  <?php
 
2
  defined( 'ABSPATH' ) OR exit;
3
  include_once(plugin_dir_path(__FILE__) . _DS . 'helpers.php');
4
 
 
5
  //Removed closures for PHP 5.0.x support
6
- function _getStyleIndex(&$styles, $id){
7
  foreach((array)$styles as $index => $style){
8
  if($style['id'] == $id){
9
  return $index;
@@ -11,16 +13,16 @@ include_once(plugin_dir_path(__FILE__) . _DS . 'helpers.php');
11
  }
12
  return null;
13
  }
14
- function _getStyle(&$styles, $id){
15
- $index = _getStyleIndex($styles, $id);
16
  return !is_null($index) ? $styles[$index] : null;
17
  }
18
 
19
- function _styleAction(&$style, $action){
20
- return esc_rel_url("?page=snazzy_maps&tab=0&action=$action&style=" . $style['id']);
21
- };
22
 
23
- function admin_styles_head($tab){
24
 
25
  $styles = get_option('SnazzyMapStyles', null);
26
  if($styles == null){
@@ -29,17 +31,17 @@ include_once(plugin_dir_path(__FILE__) . _DS . 'helpers.php');
29
 
30
 
31
  //When a new style is selected we have to go through some checks
32
- if(isset($_POST['new_style'])){
33
- $json = new SnazzyMaps_Services_JSON();
34
- $newStyle = _object_to_array($json->decode(urldecode($_POST['new_style'])));
35
- if(!_getStyle($styles, $newStyle['id'])){
36
  $styles[] = $newStyle;
37
  update_option('SnazzyMapStyles', $styles);
38
  }
39
  }
40
  }
41
 
42
- function admin_styles_tab($tab){
43
 
44
  $styles = get_option('SnazzyMapStyles', null);
45
  if($styles == null){
@@ -48,8 +50,8 @@ include_once(plugin_dir_path(__FILE__) . _DS . 'helpers.php');
48
 
49
 
50
  //Delete the specified style from the array
51
- if(isset($_GET['action']) && $_GET['action'] == 'delete_style'){
52
- $index = _getStyleIndex($styles, $_GET['style']);
53
  $defaultStyle = get_option('SnazzyMapDefaultStyle', null);
54
  if(!is_null($index)){
55
  $oldStyle = $styles[$index];
@@ -64,16 +66,16 @@ include_once(plugin_dir_path(__FILE__) . _DS . 'helpers.php');
64
  }
65
 
66
  //Enable the specified style
67
- if(isset($_GET['action']) && $_GET['action'] == 'enable_style'){
68
- $index = _getStyleIndex($styles, $_GET['style']);
69
  if(!is_null($index)){
70
  update_option('SnazzyMapDefaultStyle', $styles[$index]);
71
  }
72
  }
73
 
74
  //Disable the specified style
75
- if(isset($_GET['action']) && $_GET['action'] == 'disable_style'){
76
- $index = _getStyleIndex($styles, $_GET['style']);
77
  $defaultStyle = get_option('SnazzyMapDefaultStyle', null);
78
  if(!is_null($index) && !is_null($defaultStyle)
79
  && $styles[$index]['id'] == $defaultStyle['id']){
@@ -131,17 +133,17 @@ include_once(plugin_dir_path(__FILE__) . _DS . 'helpers.php');
131
  <?php
132
  if($isEnabled){
133
  ?>
134
- <a href="<?php echo _styleAction($style, 'disable_style'); ?>"
135
  class="button button-secondary button-large">Disable</a>
136
  <?php
137
  }
138
  else{
139
  ?>
140
- <a href="<?php echo _styleAction($style, 'enable_style'); ?>"
141
  class="button button-primary button-large">Enable</a>
142
  <?php
143
  } ?>
144
- <a href="<?php echo _styleAction($style, 'delete_style'); ?>"
145
  class="delete button button-error button-large">Remove</a>
146
  </div>
147
  </div>
@@ -155,4 +157,7 @@ include_once(plugin_dir_path(__FILE__) . _DS . 'helpers.php');
155
  </div>
156
  <?php } ?>
157
 
158
- <?php } ?>
 
 
 
1
  <?php
2
+ namespace SnazzyMaps;
3
  defined( 'ABSPATH' ) OR exit;
4
  include_once(plugin_dir_path(__FILE__) . _DS . 'helpers.php');
5
 
6
+ class SnazzyMaps_Styles {
7
  //Removed closures for PHP 5.0.x support
8
+ public static function _getStyleIndex(&$styles, $id){
9
  foreach((array)$styles as $index => $style){
10
  if($style['id'] == $id){
11
  return $index;
13
  }
14
  return null;
15
  }
16
+ public static function _getStyle(&$styles, $id){
17
+ $index = \SnazzyMaps\SnazzyMaps_Styles::_getStyleIndex($styles, $id);
18
  return !is_null($index) ? $styles[$index] : null;
19
  }
20
 
21
+ public static function _styleAction(&$style, $action){
22
+ return \SnazzyMaps\SnazzyMaps_Helpers::esc_rel_url("?page=snazzy_maps&tab=0&action=$action&style=" . $style['id']);
23
+ }
24
 
25
+ public static function admin_styles_head($tab){
26
 
27
  $styles = get_option('SnazzyMapStyles', null);
28
  if($styles == null){
31
 
32
 
33
  //When a new style is selected we have to go through some checks
34
+ if(isset($_POST['new_style']) && check_admin_referer('snazzy_maps_save_style')){
35
+ $json = new \SnazzyMaps\SnazzyMaps_Services_JSON();
36
+ $newStyle = \SnazzyMaps\SnazzyMaps_Main::object_to_array($json->decode(urldecode($_POST['new_style'])));
37
+ if(!\SnazzyMaps\SnazzyMaps_Styles::_getStyle($styles, $newStyle['id'])){
38
  $styles[] = $newStyle;
39
  update_option('SnazzyMapStyles', $styles);
40
  }
41
  }
42
  }
43
 
44
+ public static function admin_styles_tab($tab){
45
 
46
  $styles = get_option('SnazzyMapStyles', null);
47
  if($styles == null){
50
 
51
 
52
  //Delete the specified style from the array
53
+ if(isset($_GET['action']) && sanitize_text_field($_GET['action']) == 'delete_style'){
54
+ $index = \SnazzyMaps\SnazzyMaps_Styles::_getStyleIndex($styles, sanitize_text_field($_GET['style']));
55
  $defaultStyle = get_option('SnazzyMapDefaultStyle', null);
56
  if(!is_null($index)){
57
  $oldStyle = $styles[$index];
66
  }
67
 
68
  //Enable the specified style
69
+ if(isset($_GET['action']) && sanitize_text_field($_GET['action']) == 'enable_style'){
70
+ $index = \SnazzyMaps\SnazzyMaps_Styles::_getStyleIndex($styles, sanitize_text_field($_GET['style']));
71
  if(!is_null($index)){
72
  update_option('SnazzyMapDefaultStyle', $styles[$index]);
73
  }
74
  }
75
 
76
  //Disable the specified style
77
+ if(isset($_GET['action']) && sanitize_text_field($_GET['action']) == 'disable_style'){
78
+ $index = \SnazzyMaps\SnazzyMaps_Styles::_getStyleIndex($styles, sanitize_text_field($_GET['style']));
79
  $defaultStyle = get_option('SnazzyMapDefaultStyle', null);
80
  if(!is_null($index) && !is_null($defaultStyle)
81
  && $styles[$index]['id'] == $defaultStyle['id']){
133
  <?php
134
  if($isEnabled){
135
  ?>
136
+ <a href="<?php echo \SnazzyMaps\SnazzyMaps_Styles::_styleAction($style, 'disable_style'); ?>"
137
  class="button button-secondary button-large">Disable</a>
138
  <?php
139
  }
140
  else{
141
  ?>
142
+ <a href="<?php echo \SnazzyMaps\SnazzyMaps_Styles::_styleAction($style, 'enable_style'); ?>"
143
  class="button button-primary button-large">Enable</a>
144
  <?php
145
  } ?>
146
+ <a href="<?php echo \SnazzyMaps\SnazzyMaps_Styles::_styleAction($style, 'delete_style'); ?>"
147
  class="delete button button-error button-large">Remove</a>
148
  </div>
149
  </div>
157
  </div>
158
  <?php } ?>
159
 
160
+ <?php
161
+ }
162
+ }
163
+ ?>
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: atmistinc
3
  Donate link: https://snazzymaps.com/about
4
  Tags: google,maps,google maps,styled maps,styles,color,schemes,themes
5
- Requires at least: 2.8
6
  Tested up to: 4.9.7
7
- Stable tag: 1.1.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -98,6 +98,12 @@ If you happen to find any other map plugins that don't work please send us an em
98
 
99
  == Changelog ==
100
 
 
 
 
 
 
 
101
  = 1.1.4 =
102
  Release Date: July 31st, 2018
103
 
2
  Contributors: atmistinc
3
  Donate link: https://snazzymaps.com/about
4
  Tags: google,maps,google maps,styled maps,styles,color,schemes,themes
5
+ Requires at least: 3.0
6
  Tested up to: 4.9.7
7
+ Stable tag: 1.1.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
98
 
99
  == Changelog ==
100
 
101
+ = 1.1.5 =
102
+ Release Date: August 1st, 2018
103
+
104
+ * Update: Additional security fixes.
105
+ * Update: Minimum supported version of WordPress has been increased from 2.8 to 3.0.
106
+
107
  = 1.1.4 =
108
  Release Date: July 31st, 2018
109
 
snazzymaps.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Snazzy Maps
4
  * Plugin URI: https://snazzymaps.com/plugins
5
  * Description: Apply styles to your Google Maps with the official Snazzy Maps WordPress plugin.
6
- * Version: 1.1.4
7
  * Author: Atmist
8
  * Author URI: http://atmist.com/
9
  * License: GPL2
@@ -23,90 +23,97 @@
23
  along with this program; if not, write to the Free Software
24
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
-
27
  //Recommended by wordpress
28
  defined( 'ABSPATH' ) OR exit;
29
 
30
  //This API key is used to explore the styles in snazzy maps
31
- define('API_BASE', 'https://snazzymaps.com/');
32
- define('API_KEY', 'ecaccc3c-44fa-486c-9503-5d473587a493');
33
- define('SNAZZY_VERSION_NUMBER', '1.1.4');
34
 
35
  if(!defined('_DS')) {
36
  define('_DS', '/');
37
  }
38
 
39
  include_once(plugin_dir_path(__FILE__) . _DS . 'admin' . _DS . 'index.php');
40
- if (!class_exists('SnazzyMaps_Services_JSON'))
41
  {
42
  include_once(plugin_dir_path(__FILE__) . _DS . 'additional_php' . _DS . 'SnazzyMaps_Services_JSON.php');
43
  }
44
- //Required for converting the data returned by the JSON Service
45
- function _object_to_array($object)
46
- {
47
- if (is_array($object) OR is_object($object))
48
- {
49
- $result = array();
50
- foreach((array)$object as $key => $value)
51
- {
52
- $result[$key] = _object_to_array($value);
53
- }
54
- return $result;
55
- }
56
- return $object;
57
- }
58
-
59
- function resourceURL($file){
60
- return plugins_url($file, __FILE__);
61
- }
62
-
63
 
64
- function init_plugin(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  }
66
- add_action('init', 'init_plugin');
67
 
68
  //Pass the style information into the javascript file on the main page
69
  if (!function_exists('enqueue_script')) {
70
- function enqueue_script() {
71
- _deprecated_function(__FUNCTION__, '1.1.3', 'snazzy_enqueue_script()');
72
- snazzy_enqueue_script();
73
- }
74
  }
75
- function snazzy_enqueue_script() {
76
- $uniqueStyle = get_option('SnazzyMapDefaultStyle');
77
- if(!empty($uniqueStyle) && !is_null($uniqueStyle)){
78
- $handle = 'snazzymaps-js';
79
- wp_enqueue_script($handle,
80
- plugins_url('snazzymaps.js', __FILE__),
81
- $deps = array('jquery'),
82
- $ver = SNAZZY_VERSION_NUMBER,
83
- $in_footer = false);
84
-
85
- //We have to use l10n_print_after so we can support older versions of WordPress
86
- $json = new SnazzyMaps_Services_JSON();
87
- wp_localize_script($handle, 'SnazzyDataForSnazzyMaps',
88
- array('l10n_print_after' => 'SnazzyDataForSnazzyMaps=' . $json->encode($uniqueStyle)));
89
- }
90
- }
91
- add_action( 'wp_enqueue_scripts', 'snazzy_enqueue_script');
92
 
93
 
94
  //Found in admin/index.php
95
- add_action( 'admin_enqueue_scripts', 'admin_enqueue_script');
96
 
97
- function admin_add_custom_menu(){
98
- add_theme_page('Snazzy Maps', 'Snazzy Maps', 'manage_options', 'snazzy_maps', 'admin_add_custom_content');
99
- }
100
- add_action( 'admin_menu', 'admin_add_custom_menu');
101
 
102
  // Add a settings link to the plugin listing page
103
- add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'my_plugin_action_links' );
104
-
105
- function my_plugin_action_links( $links ) {
106
- array_unshift($links, '<a href="'. admin_url('themes.php?page=snazzy_maps') .'">Settings</a>');
107
- return $links;
108
- }
109
 
110
  //The post method is performed by the tab before redirecting
111
- add_action ('admin_head-appearance_page_snazzy_maps', 'admin_perform_post');
112
  ?>
3
  * Plugin Name: Snazzy Maps
4
  * Plugin URI: https://snazzymaps.com/plugins
5
  * Description: Apply styles to your Google Maps with the official Snazzy Maps WordPress plugin.
6
+ * Version: 1.1.5
7
  * Author: Atmist
8
  * Author URI: http://atmist.com/
9
  * License: GPL2
23
  along with this program; if not, write to the Free Software
24
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
+ namespace SnazzyMaps;
27
  //Recommended by wordpress
28
  defined( 'ABSPATH' ) OR exit;
29
 
30
  //This API key is used to explore the styles in snazzy maps
31
+ define('SNAZZY_MAPS_API_BASE', 'https://snazzymaps.com/');
32
+ define('SNAZZY_MAPS_API_KEY', 'ecaccc3c-44fa-486c-9503-5d473587a493');
33
+ define('SNAZZY_MAPS_VERSION_NUMBER', '1.1.5');
34
 
35
  if(!defined('_DS')) {
36
  define('_DS', '/');
37
  }
38
 
39
  include_once(plugin_dir_path(__FILE__) . _DS . 'admin' . _DS . 'index.php');
40
+ if (!class_exists('\SnazzyMaps\SnazzyMaps_Services_JSON'))
41
  {
42
  include_once(plugin_dir_path(__FILE__) . _DS . 'additional_php' . _DS . 'SnazzyMaps_Services_JSON.php');
43
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
+ class SnazzyMaps_Main {
46
+ //Required for converting the data returned by the JSON Service
47
+ public static function object_to_array($object)
48
+ {
49
+ if (is_array($object) OR is_object($object))
50
+ {
51
+ $result = array();
52
+ foreach((array)$object as $key => $value)
53
+ {
54
+ $result[$key] = \SnazzyMaps\SnazzyMaps_Main::object_to_array($value);
55
+ }
56
+ return $result;
57
+ }
58
+ return $object;
59
+ }
60
+
61
+
62
+ public static function admin_add_custom_menu(){
63
+ add_theme_page('Snazzy Maps', 'Snazzy Maps', 'manage_options', 'snazzy_maps', '\SnazzyMaps\SnazzyMaps_Index::admin_add_custom_content');
64
+ }
65
+
66
+ public static function resourceURL($file){
67
+ return plugins_url($file, __FILE__);
68
+ }
69
+
70
+ public static function init_plugin(){
71
+ }
72
+
73
+ public static function snazzy_enqueue_script() {
74
+ $uniqueStyle = get_option('SnazzyMapDefaultStyle');
75
+ if(!empty($uniqueStyle) && !is_null($uniqueStyle)){
76
+ $handle = 'snazzymaps-js';
77
+ wp_enqueue_script($handle,
78
+ plugins_url('snazzymaps.js', __FILE__),
79
+ $deps = array('jquery'),
80
+ $ver = SNAZZY_MAPS_VERSION_NUMBER,
81
+ $in_footer = false);
82
+
83
+ //We have to use l10n_print_after so we can support older versions of WordPress
84
+ $json = new \SnazzyMaps\SnazzyMaps_Services_JSON();
85
+ wp_localize_script($handle, 'SnazzyDataForSnazzyMaps',
86
+ array('l10n_print_after' => 'SnazzyDataForSnazzyMaps=' . $json->encode($uniqueStyle)));
87
+ }
88
+ }
89
+
90
+ public static function my_plugin_action_links( $links ) {
91
+ array_unshift($links, '<a href="'. admin_url('themes.php?page=snazzy_maps') .'">Settings</a>');
92
+ return $links;
93
+ }
94
  }
 
95
 
96
  //Pass the style information into the javascript file on the main page
97
  if (!function_exists('enqueue_script')) {
98
+ function enqueue_script() {
99
+ _deprecated_function(__FUNCTION__, '1.1.3', '\SnazzyMaps\SnazzyMaps_Main::snazzy_enqueue_script()');
100
+ \SnazzyMaps\SnazzyMaps_Main::snazzy_enqueue_script();
101
+ }
102
  }
103
+
104
+ add_action('init', '\SnazzyMaps\SnazzyMaps_Main::init_plugin');
105
+
106
+ add_action( 'wp_enqueue_scripts', '\SnazzyMaps\SnazzyMaps_Main::snazzy_enqueue_script');
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
 
109
  //Found in admin/index.php
110
+ add_action( 'admin_enqueue_scripts', '\SnazzyMaps\SnazzyMaps_Index::admin_enqueue_script');
111
 
112
+ add_action( 'admin_menu', '\SnazzyMaps\SnazzyMaps_Main::admin_add_custom_menu');
 
 
 
113
 
114
  // Add a settings link to the plugin listing page
115
+ add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), '\SnazzyMaps\SnazzyMaps_Main::my_plugin_action_links' );
 
 
 
 
 
116
 
117
  //The post method is performed by the tab before redirecting
118
+ add_action ('admin_head-appearance_page_snazzy_maps', '\SnazzyMaps\SnazzyMaps_Index::admin_perform_post');
119
  ?>