PluginProbe
Snippet Shortcodes / 2.0.1
Snippet Shortcodes v2.0.1
5.2.1 5.2 5.1.8 5.1.6 5.1.7 5.1.5 trunk 1.0 1.1 1.2 1.3 1.3.1 1.4 1.5 1.5.1 1.6 1.6.1 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 2.0 2.0.1 All 74 releases
shortcode-variables / includes / shortcode.presets.premium.php

shortcode.presets.premium.php in Snippet Shortcodes 2.0.1, at includes/shortcode.presets.premium.php

274 lines 10.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') or die("Jog on!");
4
5 /**
6 * Return a list of slugs / titles for free presets
7 * @return array
8 */
9 function sh_cd_shortcode_presets_premium_list() {
10
11 return [
12 'sc-site-language' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'Language code for the current site', 'args' => [ '_sh_cd_func' => 'language' ], 'premium' => true ],
13 'sc-site-description' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'Site tagline (set in Settings > General)', 'args' => [ '_sh_cd_func' => 'description' ], 'premium' => true ],
14 'sc-site-wp-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The WordPress address (URL) (set in Settings > General)', 'args' => [ '_sh_cd_func' => 'wpurl' ], 'premium' => true ],
15 'sc-site-charset' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The "Encoding for pages and feeds" (set in Settings > Reading)', 'args' => [ '_sh_cd_func' => 'charset' ], 'premium' => true ],
16 'sc-site-wp-version' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The current WordPress version', 'args' => [ '_sh_cd_func' => 'version' ], 'premium' => true ],
17 'sc-site-html-type' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The content-type (default: "text/html"). Themes and plugins', 'args' => [ '_sh_cd_func' => 'html_type' ], 'premium' => true ],
18 'sc-site-stylesheet-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'URL to the stylesheet for the active theme.', 'args' => [ '_sh_cd_func' => 'stylesheet_url' ], 'premium' => true ],
19 'sc-site-stylesheet_directory' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'Directory path for the active theme.', 'args' => [ '_sh_cd_func' => 'stylesheet_directory' ], 'premium' => true ],
20 'sc-site-template-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The URL of the active theme\'s directory.', 'args' => [ '_sh_cd_func' => 'template_url' ], 'premium' => true],
21 'sc-site-pingback-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The pingback XML-RPC file URL (xmlrpc.php)', 'args' => [ '_sh_cd_func' => 'pingback_url' ], 'premium' => true ],
22 'sc-site-atom-feed' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The Atom feed URL (/feed/atom)', 'args' => [ '_sh_cd_func' => 'atom_url' ], 'premium' => true ],
23 'sc-site-rdf-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The RDF/RSS 1.0 feed URL (/feed/rfd)', 'args' => [ '_sh_cd_func' => 'rdf_url' ], 'premium' => true ],
24 'sc-site-rss-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The RSS 0.92 feed URL (/feed/rss)', 'args' => [ '_sh_cd_func' => 'rss_url' ], 'premium' => true ],
25 'sc-site-rss2-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The RSS 2.0 feed URL (/feed)', 'args' => [ '_sh_cd_func' => 'rss2_url' ], 'premium' => true ],
26 'sc-site-comments-atom-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The comments Atom feed URL (/comments/feed)', 'args' => [ '_sh_cd_func' => 'comments_atom_url' ], 'premium' => true ],
27 'sc-site-comments-rss2-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The comments RSS 2.0 feed URL (/comments/feed)', 'args' => [ '_sh_cd_func' => 'comments_rss2_url' ], 'premium' => true ],
28 'sc-php-server-info' => [ 'class' => 'SC_SERVER_INFO', 'description' => 'Display data from the PHP $_SERVER global e.g. [sv slug="sc-server-info" field="SERVER_SOFTWARE"]. <a href="http://php.net/manual/en/reserved.variables.server.php" rel="noopener" target="_blank">Allowed values for field attribute</a>.', 'premium' => true ],
29 'sc-php-unique-id' => [ 'class' => 'SC_UNIQUE_ID', 'description' => 'Generate a unique ID. Based upon <a href="http://php.net/manual/en/function.uniqid.php" rel="noopener" target="_blank">uniqid()</a>. If you wish the unique ID to be prefixed, add a the prefix attribute e.g. [sv slug="sc-php-unique-id" prefix="yeken"]', 'premium' => true ],
30 'sc-php-timestamp' => [ 'class' => 'SC_TIMESTAMP', 'description' => 'Display the current unix timestamp. Based upon <a href="http://php.net/manual/en/function.time.php" rel="noopener" target="_blank">time()</a>.', 'premium' => true ],
31 'sc-php-random-number' => [ 'class' => 'SC_RAND_NUMBER', 'description' => 'Display a random number. Based upon <a href="http://php.net/manual/en/function.rand.php" rel="noopener" target="_blank">rand()</a>. It also supports the optional arguments of min and max e.g. [sv slug="sc-php-random-number" min="5" max="20" ]', 'premium' => true ],
32 'sc-php-random-string' => [ 'class' => 'SC_RAND_STRING', 'description' => 'Display a random string of characters. It also supports the optional argument of "length". This specifies the number of characters you wish to display (default is 10) [sv slug="sc-php-random-string" length="15"]', 'premium' => true ],
33 'sc-php-post-value' => [ 'class' => 'SC_POST_VALUE', 'description' => 'Display a value from the $_POST array. The "key" arguments specifies which array value to render. It also supports the optional arguments of "default". If there is no value in the array for the given "key" then the "default" will be displayed. [sv slug="sc-php-post-value" key="username" default="Not Found"]', 'premium' => true ],
34 'sc-php-get-value' => [ 'class' => 'SC_GET_VALUE', 'description' => 'Display a value from the $_GET array. The "key" arguments specifies which array value to render. It also supports the optional arguments of "default". If there is no value in the array for the given "key" then the "default" will be displayed. [sv slug="sc-php-get-value" key="username" default="Not Found"]', 'premium' => true ],
35 'sc-php-info' => [ 'class' => 'SC_PHP_INFO', 'description' => 'Display PHP Info', 'premium' => true ],
36 'sc-post-id' => [ 'class' => 'SC_POST_ID', 'description' => 'Display ID for the current post.', 'premium' => true ],
37 'sc-post-author' => [ 'class' => 'SC_POST_AUTHOR', 'description' => 'Display the author\'s display name or ID. The optional argument "field" allows you to specify whether you wish to display the author\'s "display-name" or "id". [sv slug="sc-post-author" field="id" ]', 'premium' => true ],
38 'sc-post-counts' => [ 'class' => 'SC_POST_COUNTS', 'description' => 'Display a count of posts for certain statuses. Using the argument status, specify whether to return a count for all posts that have a status of "publish" (default), "future", "draft", "pending" or "private". [sv slug="sc-post-counts" status="draft"]', 'premium' => true ]
39
40 // '' => [ 'class' => '', 'description' => '', 'premium' => true ]
41 ];
42 }
43
44
45 /**
46 * Get data from get_bloginfo()
47 *
48 * Class SV_SC_SITE_TITLE
49 */
50 class SV_SC_BLOG_INFO extends SV_Preset {
51
52 protected function unsanitised() {
53
54 $args = $this->get_arguments();
55
56 $key = ( false === empty( $args['_sh_cd_func'] ) ) ? $args['_sh_cd_func'] : 'name';
57
58 return get_bloginfo( $key );
59 }
60 }
61
62 /**
63 * Get data from $_SERVER
64 *
65 * Class SV_SC_SERVER_INFO
66 */
67 class SV_SC_SERVER_INFO extends SV_Preset {
68
69 protected function unsanitised() {
70
71 $args = $this->get_arguments();
72
73 return ( false === empty( $_SERVER[ $args['field'] ] ) ) ? $_SERVER[ $args['field'] ] : '';
74 }
75 }
76
77 /**
78 * Get a unique ID
79 *
80 * Class SV_SC_UNIQUE_ID
81 */
82 class SV_SC_UNIQUE_ID extends SV_Preset {
83
84 protected function unsanitised() {
85
86 $args = $this->get_arguments();
87
88 $prefix = ( false === empty( $args['prefix'] ) ) ? $args['prefix'] : '';
89
90 return uniqid ( $prefix, true );
91 }
92 }
93
94 /**
95 * Get timestamp
96 *
97 * Class SV_SC_TIMESTAMP
98 */
99 class SV_SC_TIMESTAMP extends SV_Preset {
100
101 protected function unsanitised() {
102 return time();
103 }
104 }
105
106 /**
107 * Display PHP INFO
108 *
109 * Class SV_SC_PHP_INFO
110 */
111 class SV_SC_PHP_INFO extends SV_Preset {
112
113 protected function unsanitised() {
114 return phpinfo();
115 }
116 }
117
118 /**
119 * Random number
120 *
121 * Class SV_SC_RAND_NUMBER
122 */
123 class SV_SC_RAND_NUMBER extends SV_Preset {
124
125 protected function unsanitised() {
126
127 $args = $this->get_arguments();
128
129 $min = ( false === empty( $args['min'] ) ) ? (int) $args['min'] : 0;
130
131 $max = ( false === empty( $args['max'] ) ) ? (int) $args['max'] : getrandmax();
132
133 return rand( $min, $max );
134 }
135 }
136
137 /**
138 * Random string
139 *
140 * Based upon: https://stackoverflow.com/questions/4356289/php-random-string-generator
141 *
142 * Class SV_SC_RAND_STRING
143 */
144 class SV_SC_RAND_STRING extends SV_Preset {
145
146 protected function unsanitised() {
147
148 $args = $this->get_arguments();
149
150 $length = ( false === empty( $args['length'] ) ) ? (int) $args['length'] : 10;
151
152 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
153 $no_characters = strlen( $characters );
154 $random_string = '';
155
156 for ($i = 0; $i < $length; $i++) {
157 $random_string .= $characters[ rand( 0, $no_characters - 1 ) ];
158 }
159
160 return $random_string;
161 }
162 }
163
164 /**
165 * Fetch an item from the $_POST array
166 *
167 * Class SV_SC_POST_VALUE
168 */
169 class SV_SC_POST_VALUE extends SV_Preset {
170
171 protected function unsanitised() {
172
173 $args = $this->get_arguments();
174
175 $post_value = ( false === empty( $_POST[ $args['key'] ] ) ) ? $_POST[ $args['key'] ] : NULL;
176
177 if ( null !== $post_value ) {
178 return $post_value;
179 }
180
181 // Do we have a fall back default?
182 return ( false === empty( $args['default'] ) ) ? $args['default'] : '';
183
184 }
185 }
186
187 /**
188 * Fetch an item from the $_GET array
189 *
190 * Class SV_SC_GET_VALUE
191 */
192 class SV_SC_GET_VALUE extends SV_Preset {
193
194 protected function unsanitised() {
195
196 $args = $this->get_arguments();
197
198 $post_value = ( false === empty( $_GET[ $args['key'] ] ) ) ? $_GET[ $args['key'] ] : NULL;
199
200 if ( null !== $post_value ) {
201 return $post_value;
202 }
203
204 // Do we have a fall back default?
205 return ( false === empty( $args['default'] ) ) ? $args['default'] : '';
206
207 }
208 }
209
210 /**
211 * Display current Post ID
212 *
213 * Class SV_SC_POST_ID
214 */
215 class SV_SC_POST_ID extends SV_Preset {
216
217 protected function unsanitised() {
218 return get_the_ID();
219 }
220 }
221
222 /**
223 * Display author of current post
224 *
225 * Class SV_SC_POST_AUTHOR
226 */
227 class SV_SC_POST_AUTHOR extends SV_Preset {
228
229 protected function unsanitised() {
230
231 $args = $this->get_arguments();
232
233 switch ( $args['field'] ) {
234 case 'id':
235 return get_the_author_meta( 'ID' );
236 break;
237 default:
238 return get_the_author();
239 }
240 }
241 }
242
243 /**
244 * Display post counts
245 *
246 * Class SV_SC_POST_COUNTS
247 */
248 class SV_SC_POST_COUNTS extends SV_Preset {
249
250 protected function unsanitised() {
251
252 $args = $this->get_arguments();
253
254 $counts = wp_count_posts();
255
256 switch ( $args['status'] ) {
257 case 'future':
258 return $counts->future;
259 break;
260 case 'draft':
261 return $counts->draft;
262 break;
263 case 'pending':
264 return $counts->pending;
265 break;
266 case 'private':
267 return $counts->private;
268 break;
269 default:
270 return $counts->publish;
271 }
272 }
273 }
274