PluginProbe
URL Params / 2.3
URL Params v2.3
trunk 1.6 1.7 1.8 2.0 2.1 2.2 2.3 2.4 2.5 2.5-review
← All changes | urlparams.php +12 -153 trunk2.3 View file →
@@ -2,9 +2,9 @@
2 2 /*
3 3 Plugin Name: URL Params
4 4 Plugin URI: http://asandia.com/wordpress-plugins/urlparams/
5 5 Description: Short Code to grab any URL Parameter
6 -Version: 2.5
6 +Version: 2.3
7 7 Author: Jeremy B. Shapiro
8 8 Author URI: http://www.asandia.com/
9 9 */
10 10
@@ -9,9 +9,9 @@
9 9 */
10 10
11 11 /*
12 12 URL Params (Wordpress Plugin)
13 -Copyright (C) 2011-2026 Jeremy Shapiro
13 +Copyright (C) 2011-2022 Jeremy Shapiro
14 14
15 15 */
16 16
17 17 // error_reporting(E_ALL); // Helpful for checking for warnings that are TYPICALLY hidden but may be present on some installs
@@ -19,35 +19,8 @@
19 19 // Tell WordPress to register the shortcodes
20 20 add_shortcode("urlparam", "urlparam");
21 21 add_shortcode("ifurlparam", "ifurlparam");
22 22
23 -register_uninstall_hook(__FILE__, 'uninstall_urlparams');
24 -
25 -// If we're an admin, add a URL Params options page under Settings
26 -if (is_admin()) {
27 - add_action('admin_menu', 'urlparams_admin_menu');
28 - add_action('admin_init', 'admin_init_urlparams');
29 -}
30 -function urlparams_admin_menu()
31 -{
32 - add_options_page('URL Params', 'URL Params', 'manage_options', 'urlparams', 'options_page_urlparams');
33 -}
34 -
35 -// Add a link to the Options page from the Plugins page
36 -add_filter( 'plugin_action_links', 'urlparams_plugin_action_links', 10, 2 );
37 -function urlparams_plugin_action_links( $links, $file )
38 -{
39 - if ( $file == plugin_basename( __DIR__ .'/urlparams.php' ) ) {
40 - $links[] = '<a href="options-general.php?page=urlparams"><b>'.__('Settings').'</b></a>';
41 - }
42 - return $links;
43 -}
44 -
45 -function options_page_urlparams()
46 -{
47 - include __DIR__ .'/options.php';
48 -}
49 -
50 23 function urlparam($attributes, $content) {
51 24 $defaults = array(
52 25 'param' => '',
53 26 'default' => '',
@@ -55,15 +28,10 @@
55 28 'attr' => '',
56 29 'htmltag' => false,
57 30 );
58 31
59 - // If $attributes is an array, we merge it with our defaults
60 - if(is_array($attributes)) {
61 - // We used to use shortcode_atts(), but that would nuke an extra attributes that we don't know about but want. array_merge() keeps them all.
62 - $attributes = array_merge($defaults, $attributes);
63 - } else {
64 - $attributes = $defaults;
65 - }
32 + // We used to use shortcode_atts(), but that would nuke an extra attributes that we don't know about but want. array_merge() keeps them all.
33 + $attributes = array_merge($defaults, $attributes);
66 34
67 35 $params = preg_split('/,\s*/',$attributes['param']);
68 36
69 37 $return = false;
@@ -87,10 +55,10 @@
87 55 if(!$return) {
88 56 $return = $attributes['default'];
89 57 }
90 58
91 - if($attr = $attributes['attr']) {
92 - $return = ' ' . sanitize_key($attr) . '="' . esc_attr($return) . '" ';
59 + if($attributes['attr']) {
60 + $return = ' ' . $attributes['attr'] . '="' . $return . '" ';
93 61
94 62 if($attributes['htmltag']) {
95 63 $tagName = $attributes['htmltag'];
96 64
@@ -96,11 +64,12 @@
96 64
97 65 foreach(array_keys($defaults) as $key) {
98 66 unset($attributes[$key]);
99 67 }
68 +
100 69 $otherAttributes = "";
101 70 foreach($attributes as $key => $val) {
102 - $otherAttributes .= ' '.sanitize_key($key).'="'.esc_attr($val).'" ';
71 + $otherAttributes .= " $key=\"$val\"";
103 72 }
104 73
105 74 $return = "<$tagName $otherAttributes $return".($content ? ">$content</$tagName>" : "/>");
106 75 }
@@ -105,23 +74,9 @@
105 74 $return = "<$tagName $otherAttributes $return".($content ? ">$content</$tagName>" : "/>");
106 75 }
107 76 }
108 77
109 - $allowedHtml = wp_kses_allowed_html('post');
110 -
111 - // Do we have any custom tags set? Add those
112 - if($customTags = urlparams_get_customtags()) {
113 - foreach($customTags as $customTag => $attributes) {
114 - // Is this already an allowed tag? Merge our approved attributes in, too
115 - if(array_key_exists($customTag, $allowedHtml)) {
116 - $allowedHtml[$customTag] = array_merge($allowedHtml[$customTag], $attributes);
117 - } else {
118 - $allowedHtml[$customTag] = $attributes;
119 - }
120 - }
121 - }
122 -
123 - return wp_kses($return, $allowedHtml);
78 + return $return;
124 79 }
125 80
126 81 /*
127 82 * If 'param' is found and 'is' is set, compare the two and display the contact if they match
@@ -139,16 +94,15 @@
139 94 $params = preg_split('/,\s*/',$attributes['param']);
140 95
141 96 foreach($params as $param)
142 97 {
143 - if(isset($_REQUEST[$param])
144 - && ($value = $_REQUEST[$param]))
98 + if($_REQUEST[$param])
145 99 {
146 100 if($attributes['empty'])
147 101 {
148 102 return '';
149 - } elseif(!($isAttribute = $attributes['is'])
150 - || ($value == $isAttribute)
103 + } elseif(!$attributes['is']
104 + || ($_REQUEST[$param] == $attributes['is'])
151 105 ) {
152 106 return do_shortcode($content);
153 107 }
154 108 }
@@ -159,102 +113,7 @@
159 113 return do_shortcode($content);
160 114 }
161 115
162 116 return '';
163 -}
164 -
165 -function uninstall_urlparams() {
166 - delete_option('urlparams_customtags');
167 -
168 -}
169 -
170 -function admin_init_urlparams()
171 -{
172 - register_setting('urlparams', 'urlparams_customtags', [
173 - 'sanitize_callback' => 'urlparams_sanitize_customtags',
174 - ]);
175 -}
176 -
177 -/**
178 - *
179 - * Sanitize our custom tag options
180 - *
181 - * @param string $newCustomTags
182 - * @return string
183 - */
184 -function urlparams_sanitize_customtags($newCustomTags) {
185 - $isValid = true;
186 -
187 - $lines = explode("\n", $newCustomTags);
188 - $validLines = [];
189 -
190 - foreach($lines as $line) {
191 - $lineParts = explode(':', $line);
192 - if(count($lineParts) !== 2) {
193 - $isValid = false;
194 - continue;
195 - }
196 -
197 - if(!($tagName = trim(strtolower($lineParts[0])))) {
198 - $isValid = false;
199 - continue;
200 - }
201 -
202 - if(!($attributes = explode(',', $lineParts[1]))) {
203 - $isValid = false;
204 - continue;
205 - }
206 -
207 - $validAttributes = [];
208 - foreach($attributes as $attribute) {
209 - if($attribute = strtolower(trim($attribute))) {
210 - $validAttributes[] = $attribute;
211 - }
212 - }
213 -
214 - $validAttributes = array_unique($validAttributes);
215 -
216 - if(!$validAttributes) {
217 - $isValid = false;
218 - continue;
219 - }
220 -
221 - $validLines[] = $tagName.': '.implode(', ', $validAttributes);
222 - }
223 -
224 - if(!$isValid) {
225 - add_settings_error('urlparams_customtags', 'urlparams_customtags', __('Invalid Custom Tags were removed', 'urlparams'), 'warning');
226 - }
227 -
228 - return join("\n", $validLines);
229 -}
230 -
231 -/**
232 - *
233 - * Return our array of custom tag options
234 - *
235 - * @return array
236 - */
237 -function urlparams_get_customtags() {
238 - $lines = explode("\n", get_option('urlparams_customtags'));
239 - $customTags = [];
240 -
241 - foreach($lines as $line) {
242 - $lineParts = explode(':', $line);
243 - if(count($lineParts) !== 2) {
244 - continue;
245 - }
246 -
247 - $tagName = trim($lineParts[0]);
248 - $attributes = explode(',', $lineParts[1]);
249 -
250 - $customTags[$tagName] = [];
251 -
252 - foreach($attributes as $attribute) {
253 - $customTags[$tagName][trim($attribute)] = true;
254 - }
255 - }
256 -
257 - return $customTags;
258 117 }
259 118
260 119 ?>