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
url-params / urlparams.php

urlparams.php in URL Params 2.3, at urlparams.php

120 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: URL Params
4 Plugin URI: http://asandia.com/wordpress-plugins/urlparams/
5 Description: Short Code to grab any URL Parameter
6 Version: 2.3
7 Author: Jeremy B. Shapiro
8 Author URI: http://www.asandia.com/
9 */
10
11 /*
12 URL Params (Wordpress Plugin)
13 Copyright (C) 2011-2022 Jeremy Shapiro
14
15 */
16
17 // error_reporting(E_ALL); // Helpful for checking for warnings that are TYPICALLY hidden but may be present on some installs
18
19 // Tell WordPress to register the shortcodes
20 add_shortcode("urlparam", "urlparam");
21 add_shortcode("ifurlparam", "ifurlparam");
22
23 function urlparam($attributes, $content) {
24 $defaults = array(
25 'param' => '',
26 'default' => '',
27 'dateformat' => '',
28 'attr' => '',
29 'htmltag' => false,
30 );
31
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);
34
35 $params = preg_split('/,\s*/',$attributes['param']);
36
37 $return = false;
38
39 foreach($params as $param)
40 {
41 if(!$return
42 && array_key_exists($param, $_REQUEST)
43 && ($rawText = $_REQUEST[$param])
44 ) {
45 if(($attributes['dateformat'] != '')
46 && strtotime($rawText)
47 ) {
48 $return = date($attributes['dateformat'], strtotime($rawText));
49 } else {
50 $return = esc_html($rawText);
51 }
52 }
53 }
54
55 if(!$return) {
56 $return = $attributes['default'];
57 }
58
59 if($attributes['attr']) {
60 $return = ' ' . $attributes['attr'] . '="' . $return . '" ';
61
62 if($attributes['htmltag']) {
63 $tagName = $attributes['htmltag'];
64
65 foreach(array_keys($defaults) as $key) {
66 unset($attributes[$key]);
67 }
68
69 $otherAttributes = "";
70 foreach($attributes as $key => $val) {
71 $otherAttributes .= " $key=\"$val\"";
72 }
73
74 $return = "<$tagName $otherAttributes $return".($content ? ">$content</$tagName>" : "/>");
75 }
76 }
77
78 return $return;
79 }
80
81 /*
82 * If 'param' is found and 'is' is set, compare the two and display the contact if they match
83 * If 'param' is found and 'is' isn't set, display the content between the tags
84 * If 'param' is not found and 'empty' is set, display the content between the tags
85 *
86 */
87 function ifurlparam($attributes, $content) {
88 $attributes = shortcode_atts(array(
89 'param' => '',
90 'empty' => false,
91 'is' => false,
92 ), $attributes);
93
94 $params = preg_split('/,\s*/',$attributes['param']);
95
96 foreach($params as $param)
97 {
98 if($_REQUEST[$param])
99 {
100 if($attributes['empty'])
101 {
102 return '';
103 } elseif(!$attributes['is']
104 || ($_REQUEST[$param] == $attributes['is'])
105 ) {
106 return do_shortcode($content);
107 }
108 }
109 }
110
111 if ($attributes['empty'])
112 {
113 return do_shortcode($content);
114 }
115
116 return '';
117 }
118
119 ?>
120