PluginProbe
Snippet Shortcodes / 3.0.2
Snippet Shortcodes v3.0.2
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 3.0.2, at includes/shortcode.presets.premium.php

330 lines 13.0 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-date' => [ 'class' => 'SC_DATE', 'description' => 'A shortcode that displays today\'s date with the ability to add or subtract days, months and years. To specify an interval to add or subtract onto the date use the parameter "interval" e.g. [sv slug="sc-date" interval="-1 year"], [sv slug="sc-date" interval="+5 days"], [sv slug="sc-date" interval="+3 months"]. Intervals are based upon PHP intervals and are outlined here <a href="https://www.php.net/manual/en/dateinterval.createfromdatestring.php" target="_blank">https://www.php.net/manual/en/dateinterval.createfromdatestring.php</a>. Default is UK format (DD/MM/YYYY). Format can be changed by adding the parameter format="m/d/Y" onto the shortcode. Format syntax is based upon PHP date: <a href="http://php.net/manual/en/function.date.php" target="_blank">http://php.net/manual/en/function.date.php</a>', 'premium' => true ],
13 'sc-site-language' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'Language code for the current site', 'args' => [ '_sh_cd_func' => 'language' ], 'premium' => true ],
14 'sc-site-description' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'Site tagline (set in Settings > General)', 'args' => [ '_sh_cd_func' => 'description' ], 'premium' => true ],
15 'sc-site-wp-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The WordPress address (URL) (set in Settings > General)', 'args' => [ '_sh_cd_func' => 'wpurl' ], 'premium' => true ],
16 '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 ],
17 'sc-site-wp-version' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The current WordPress version', 'args' => [ '_sh_cd_func' => 'version' ], 'premium' => true ],
18 '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 ],
19 '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 ],
20 'sc-site-stylesheet_directory' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'Directory path for the active theme.', 'args' => [ '_sh_cd_func' => 'stylesheet_directory' ], 'premium' => true ],
21 '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],
22 '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 ],
23 'sc-site-atom-feed' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The Atom feed URL (/feed/atom)', 'args' => [ '_sh_cd_func' => 'atom_url' ], 'premium' => true ],
24 '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 ],
25 '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 ],
26 'sc-site-rss2-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The RSS 2.0 feed URL (/feed)', 'args' => [ '_sh_cd_func' => 'rss2_url' ], 'premium' => true ],
27 '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 ],
28 '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 ],
29 '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 ],
30 '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 ],
31 '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 ],
32 '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 ],
33 '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 ],
34 '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 ],
35 '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 ],
36 'sc-php-info' => [ 'class' => 'SC_PHP_INFO', 'description' => 'Display PHP Info', 'premium' => true ],
37 'sc-post-id' => [ 'class' => 'SC_POST_ID', 'description' => 'Display ID for the current post.', 'premium' => true ],
38 '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 ],
39 '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 ],
40 'sc-user-counts' => [ 'class' => 'SC_USER_COUNTS', 'description' => 'Display a count of all WordPress users or the number of WordPress users for a given role e.g. [sv slug="sc-user-counts" role="subscriber"] or [sv slug="sc-user-counts"]', 'premium' => true ]
41
42 // '' => [ 'class' => '', 'description' => '', 'premium' => true ]
43 ];
44 }
45
46
47 /**
48 * Get data from get_bloginfo()
49 *
50 * Class SV_SC_SITE_TITLE
51 */
52 class SV_SC_BLOG_INFO extends SV_Preset {
53
54 protected function unsanitised() {
55
56 $args = $this->get_arguments();
57
58 $key = ( false === empty( $args['_sh_cd_func'] ) ) ? $args['_sh_cd_func'] : 'name';
59
60 return get_bloginfo( $key );
61 }
62 }
63
64 /**
65 * Get data from $_SERVER
66 *
67 * Class SV_SC_SERVER_INFO
68 */
69 class SV_SC_SERVER_INFO extends SV_Preset {
70
71 protected function unsanitised() {
72
73 $args = $this->get_arguments();
74
75 return ( false === empty( $_SERVER[ $args['field'] ] ) ) ? $_SERVER[ $args['field'] ] : '';
76 }
77 }
78
79 /**
80 * Get a unique ID
81 *
82 * Class SV_SC_UNIQUE_ID
83 */
84 class SV_SC_UNIQUE_ID extends SV_Preset {
85
86 protected function unsanitised() {
87
88 $args = $this->get_arguments();
89
90 $prefix = ( false === empty( $args['prefix'] ) ) ? $args['prefix'] : '';
91
92 return uniqid ( $prefix, true );
93 }
94 }
95
96 /**
97 * Get timestamp
98 *
99 * Class SV_SC_TIMESTAMP
100 */
101 class SV_SC_TIMESTAMP extends SV_Preset {
102
103 protected function unsanitised() {
104 return time();
105 }
106 }
107
108 /**
109 * Display PHP INFO
110 *
111 * Class SV_SC_PHP_INFO
112 */
113 class SV_SC_PHP_INFO extends SV_Preset {
114
115 protected function unsanitised() {
116 return phpinfo();
117 }
118 }
119
120 /**
121 * Random number
122 *
123 * Class SV_SC_RAND_NUMBER
124 */
125 class SV_SC_RAND_NUMBER extends SV_Preset {
126
127 protected function unsanitised() {
128
129 $args = $this->get_arguments();
130
131 $min = ( false === empty( $args['min'] ) ) ? (int) $args['min'] : 0;
132
133 $max = ( false === empty( $args['max'] ) ) ? (int) $args['max'] : getrandmax();
134
135 return rand( $min, $max );
136 }
137 }
138
139 /**
140 * Random string
141 *
142 * Based upon: https://stackoverflow.com/questions/4356289/php-random-string-generator
143 *
144 * Class SV_SC_RAND_STRING
145 */
146 class SV_SC_RAND_STRING extends SV_Preset {
147
148 protected function unsanitised() {
149
150 $args = $this->get_arguments();
151
152 $length = ( false === empty( $args['length'] ) ) ? (int) $args['length'] : 10;
153
154 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
155 $no_characters = strlen( $characters );
156 $random_string = '';
157
158 for ($i = 0; $i < $length; $i++) {
159 $random_string .= $characters[ rand( 0, $no_characters - 1 ) ];
160 }
161
162 return $random_string;
163 }
164 }
165
166 /**
167 * Fetch an item from the $_POST array
168 *
169 * Class SV_SC_POST_VALUE
170 */
171 class SV_SC_POST_VALUE extends SV_Preset {
172
173 protected function unsanitised() {
174
175 $args = $this->get_arguments();
176
177 $post_value = ( false === empty( $_POST[ $args['key'] ] ) ) ? $_POST[ $args['key'] ] : NULL;
178
179 if ( null !== $post_value ) {
180 return $post_value;
181 }
182
183 // Do we have a fall back default?
184 return ( false === empty( $args['default'] ) ) ? $args['default'] : '';
185
186 }
187 }
188
189 /**
190 * Fetch an item from the $_GET array
191 *
192 * Class SV_SC_GET_VALUE
193 */
194 class SV_SC_GET_VALUE extends SV_Preset {
195
196 protected function unsanitised() {
197
198 $args = $this->get_arguments();
199
200 $post_value = ( false === empty( $_GET[ $args['key'] ] ) ) ? $_GET[ $args['key'] ] : NULL;
201
202 if ( null !== $post_value ) {
203 return $post_value;
204 }
205
206 // Do we have a fall back default?
207 return ( false === empty( $args['default'] ) ) ? $args['default'] : '';
208
209 }
210 }
211
212 /**
213 * Display current Post ID
214 *
215 * Class SV_SC_POST_ID
216 */
217 class SV_SC_POST_ID extends SV_Preset {
218
219 protected function unsanitised() {
220 return get_the_ID();
221 }
222 }
223
224 /**
225 * Display author of current post
226 *
227 * Class SV_SC_POST_AUTHOR
228 */
229 class SV_SC_POST_AUTHOR extends SV_Preset {
230
231 protected function unsanitised() {
232
233 $args = $this->get_arguments();
234
235 switch ( $args['field'] ) {
236 case 'id':
237 return get_the_author_meta( 'ID' );
238 break;
239 default:
240 return get_the_author();
241 }
242 }
243 }
244
245 /**
246 * Display post counts
247 *
248 * Class SV_SC_POST_COUNTS
249 */
250 class SV_SC_POST_COUNTS extends SV_Preset {
251
252 protected function unsanitised() {
253
254 $args = $this->get_arguments();
255
256 $counts = wp_count_posts();
257
258 switch ( $args['status'] ) {
259 case 'future':
260 return $counts->future;
261 break;
262 case 'draft':
263 return $counts->draft;
264 break;
265 case 'pending':
266 return $counts->pending;
267 break;
268 case 'private':
269 return $counts->private;
270 break;
271 default:
272 return $counts->publish;
273 }
274 }
275 }
276
277 /**
278 * Get a User counts
279 *
280 * Class SV_SC_USER_COUNTS
281 */
282 class SV_SC_USER_COUNTS extends SV_Preset {
283
284 protected function unsanitised() {
285
286 $args = $this->get_arguments();
287
288 $role = ( false === empty( $args['role'] ) ) ? $args['role'] : NULL;
289
290 $users = count_users();
291
292 if ( false === empty( $role ) && true === isset( $users['avail_roles'][ $role ] ) ) {
293 return $users['avail_roles'][ $role ];
294 } if ( true === isset( $users['total_users'] ) ) {
295 return $users['total_users'];
296 }
297
298 return '';
299 }
300 }
301
302 /**
303 * Display a date and also support date arithmetic
304 *
305 * Class SV_SC_DATE
306 */
307 class SV_SC_DATE extends SV_Preset {
308
309 protected function unsanitised() {
310
311 $args = $this->get_arguments();
312
313 $todays_date = date_create();
314
315 // Do we have an interval?
316 if ( false === empty( $args['interval'] ) ) {
317
318 $interval = date_interval_create_from_date_string( $args['interval'] );
319
320 if ( $interval !== false ) {
321 $todays_date = date_add( $todays_date, $interval );
322 }
323
324 }
325
326 $date_format = ( false === empty( $args['format'] ) ) ? $args['format'] : 'd/m/Y';
327
328 return date_format( $todays_date, $date_format );
329 }
330 }