PluginProbe
Snippet Shortcodes / 5.1.1
Snippet Shortcodes v5.1.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 / pages / page.list.php

page.list.php in Snippet Shortcodes 5.1.1, at includes/pages/page.list.php

270 lines 11.7 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 * Determine which page to show
7 */
8 function sh_cd_pages_your_shortcodes() {
9
10 $action = ( false === empty( $_GET['action'] ) ) ? $_GET['action'] : NULL;
11
12 $action = ( 'save' === $action && true === empty( $_POST ) ) ? '' : $action;
13
14 $save_result = NULL;
15
16 // Do we have a save event?
17 if ( 'save' === $action ) {
18
19 check_admin_referer( 'save-shortcode' );
20
21 $save_result = false;
22
23 if ( false === empty( $_POST[ 'id'] ) ||
24 false === sh_cd_reached_free_limit() ) {
25 $save_result = sh_cd_shortcodes_save_post();
26
27 // Success?
28 if ( true === $save_result ) {
29 $action = 'list';
30 }
31 }
32 }
33
34 switch ( $action ) {
35
36 case 'add':
37 case 'edit':
38 case 'save':
39 sh_cd_pages_your_shortcodes_edit( $action, $save_result );
40 break;
41 default:
42 sh_cd_pages_your_shortcodes_list( $action, $save_result );
43 }
44
45 }
46
47 /**
48 * Display all shortcodes
49 * @param null $action
50 * @param null $save_result
51 */
52 function sh_cd_pages_your_shortcodes_list($action = NULL, $save_result = NULL) {
53
54 sh_cd_permission_check();
55
56 // Cloning a shortcode?
57 if ( 'clone' === $action && false === empty( $_GET['id'] ) ) {
58 sh_cd_clone( (int) $_GET['id'] );
59 }
60
61 if ( true == $save_result ) {
62 sh_cd_message_display( __( 'Your shortcode has been saved!', SH_CD_SLUG ) );
63 }
64
65 ?>
66 <div class="wrap">
67 <div id="icon-options-general" class="icon32"></div>
68 <div id="poststuff">
69 <div id="post-body" class="metabox-holder columns-3">
70 <div id="post-body-content">
71 <div class="meta-box-sortables ui-sortable">
72 <div class="postbox">
73 <h3 class="postbox-header">
74 <span>
75 <?php echo __( 'Your Snippet Shortcodes', SH_CD_SLUG ); ?>
76 </span>
77 </h3>
78 <div style="padding: 0px 15px 0px 15px">
79 <table width="100%" style="margin-top: 10px">
80 <tr>
81 <td class="yk-ss-shortcode-stats">
82 <?php
83
84 if ( false === sh_cd_is_premium() ) {
85 printf( '%s %d %s %d %s. <i class="fa-regular fa-star"></i> <a href="%s">%s</a>',
86 __( 'Used', SH_CD_SLUG ),
87 sh_cd_db_shortcodes_count(),
88 __( 'of', SH_CD_SLUG ),
89 sh_cd_get_free_limit(),
90 __( 'shortcodes', SH_CD_SLUG ),
91 sh_cd_license_upgrade_link(),
92 __( 'Go unlimited!', SH_CD_SLUG )
93 );
94 }
95
96 ?>
97 </td>
98 <td align="right">
99 <?php
100 if ( false === sh_cd_is_premium() ) {
101 sh_cd_upgrade_button( 'sh-cd-hide', sh_cd_license_upgrade_link() );
102 }
103
104 sc_cd_display_add_button();
105 ?>
106 </td>
107 </tr>
108 </table>
109 <p style="text-align: right">
110
111 </p>
112
113 <table class="widefat sh-cd-table" width="100%">
114 <tr class="row-title">
115 <th class="row-title" width="20%"><?php echo __( 'Shortcode', SH_CD_SLUG ); ?></th>
116 <th width="*"><?php echo __( 'Content', SH_CD_SLUG ); ?></th>
117 <?php if ( sh_cd_is_multisite_enabled() ): ?>
118 <th width="60px" align="middle"><?php echo __( 'Global', SH_CD_SLUG ); ?></th>
119 <?php endif; ?>
120 <th width="60px" align="middle"><?php echo __( 'Enabled', SH_CD_SLUG ); ?></th>
121 <th width="70px" align="middle"><?php echo __( 'Options', SH_CD_SLUG ); ?></th>
122 </tr>
123 <?php
124
125 printf( '<tr class="sh-cd-hide" id="sh-cd-add-inline">
126 <td>
127 <input type="text" maxlength="100" placeholder="%1$s" class="sh-cd-slug-validation" id="sh-cd-add-inline-slug" title="Only letters, numbers, dashes and underscores are allowed." />
128 <p class="sh-cd-shortcode-slug sh-cd-hide">
129 <span id="sh-cd-test-shortcode-slug">[%6$s slug="<span id="sh-cd-shortcode-slug-preview"></span>"]</span>
130 <i class="far fa-copy sh-cd-copy-trigger" data-clipboard-text="[%6$s: slug=&quot;&quot;]"></i>
131 </p>
132 </td>
133 <td align="right">
134 <textarea class="large-text inline-text-shortcode" id="sh-cd-add-inline-text"></textarea>
135 <label for="sh-cd-add-inline-clear" >%3$s </label><input type="checkbox" id="sh-cd-add-inline-clear" value="true" checked="checked" />
136 </td>
137 %7$s
138 <td align="middle"><input type="checkbox" id="sh-cd-add-inline-enabled" value="true" checked="checked" /></td>
139 <td width="100">
140 <a class="button button-small sh-cd-inline-add-button" id="sh-cd-add-button" %5$s><i class="fas fa-save"></i> %2$s</a>
141 </td>
142 </tr>
143 <tr class="sh-cd-hide" id="sh-cd-add-inline-results">
144 <td></td>
145 <td cospan="4">
146 <p>%4$s</p>
147 </td>
148 </tr>
149
150 ',
151 __( 'Slug', SH_CD_SLUG ),
152 __( 'Add', SH_CD_SLUG ),
153 __( 'Clear form after save', SH_CD_SLUG ),
154 __( 'Your Shortcode has been added. Please refresh the page to edit it.', SH_CD_SLUG ),
155 ( false === sh_cd_is_premium() ) ? ' disabled="disabled"' : '',
156 SH_CD_SHORTCODE,
157 sh_cd_is_multisite_enabled() ? '<td align="middle"><input type="checkbox" id="sh-cd-add-inline-global" value="true" /></td>' : ''
158 );
159
160 $current_shortcodes = sh_cd_db_shortcodes_all();
161
162 if ( false === empty( $current_shortcodes ) ) {
163
164 $class = '';
165 $link = sh_cd_link_your_shortcodes();
166 $i = 0;
167 $limit_reached = sh_cd_reached_free_limit();
168 $is_premium = sh_cd_is_premium();
169
170 foreach ( $current_shortcodes as $shortcode ) {
171
172 // !! TOOO: This whole loop needs to be refactored! Especially the sprintf()s
173
174 $class = ($class == 'alternate') ? '' : 'alternate';
175 $id = (int) $shortcode['id'];
176 $icons = ( $is_premium ) ? sh_cd_icons_for_shortcode( $shortcode ) : '';
177 $multisite_column = '';
178
179 if ( true === sh_cd_is_multisite_enabled() ) {
180 $multisite_column = sprintf ( '<td align="middle"><a class="button button-small toggle-multisite sh-cd-toggle-%1$s sh-cd-tooltip" id="sc-cd-multisite-%2$s" data-id="%2$s" %1$s title="%3$s"><i class="fa-solid %4$s"></i></a></td>',
181 ( false === $is_premium ) ? 'disabled' : '',
182 $id,
183 __( 'Enable this shortcode for use across all sites within your WordPress multisite network.', SH_CD_SLUG ),
184 ( 1 === (int) $shortcode['multisite'] ) ? 'fa-check' : 'fa-times'
185 );
186 }
187
188 printf( '<tr class="%1$s yk-ss-row-%3$s sh-cd-shortcode-row" id="sh-cd-row-%8$s">
189 <td><a href="%2$s" class="slug-link">[%4$s slug="%3$s"]</a> <i class="far fa-copy sh-cd-copy-trigger sh-cd-tooltip" data-clipboard-text="[%4$s slug=&quot;%3$s&quot;]" title="%20$s"></i></td>
190 <td align="right">
191 <textarea class="large-text inline-text-shortcode sh-cd-toggle-%13$s" id="sh-cd-text-area-%8$d" data-id="%8$d" %13$s>%5$s</textarea>
192 <div class="sh-cd-icons">
193 %21$s
194 <a class="button button-small sh-cd-inline-save-button sh-cd-toggle-%13$s" id="sh-cd-save-button-%8$d" data-id="%8$d" %13$s><i class="fas fa-save"></i> %11$s</a>
195 </div>
196 </td>
197 %19$s
198 <td align="middle"><a class="button button-small toggle-disable sh-cd-toggle-%13$s sh-cd-tooltip" id="sc-cd-toggle-%8$s" data-id="%8$s" %13$s title="%18$s"><i class="fa-solid %6$s"></i></a></td>
199 <td width="100">
200 <a class="button button-small sh-cd-toggle-%13$s sh-cd-tooltip" %13$s href="%9$s" title="%17$s"><i class="far fa-clone"></i></a>
201 <a class="button button-small edit-shortcode sh-cd-tooltip" href="%2$s" title="%15$s"><i class="far fa-edit"></i></a>
202 <a id="delete-%8$s" class="button button-small delete-shortcode sh-cd-tooltip" data-id="%8$s" title="%16$s"><i class="fas fa-trash-alt"></i></a>
203 </td>
204 </tr>',
205 $class,
206 $link . '&action=edit&id=' . $id,
207 esc_html( $shortcode['slug'] ),
208 SH_CD_SHORTCODE,
209 ( $is_premium ) ? esc_html( stripslashes( $shortcode['data'] ) ) : __( 'Upgrade for inline editing and toggles.', SH_CD_SLUG ),
210 ( 1 === (int) $shortcode['disabled'] ) ? 'fa-times' : 'fa-check',
211 $link . '&action=delete&id=' . $id,
212 $id,
213 ( $is_premium ) ? $link . '&action=clone&id=' . $id : sh_cd_license_upgrade_link(),
214 ( 1 === (int) $shortcode['multisite'] ) ? 'fa-check' : 'fa-times',
215 __( 'Save', SH_CD_SLUG ),
216 __( 'Are you sure you want to delete this shortcode?', SH_CD_SLUG ),
217 ( false === $is_premium ) ? 'disabled' : '',
218 ( true === $limit_reached && $i > sh_cd_get_free_limit() ) ? 'disabled' : '',
219 __( 'Use the full Visual or Code editor to edit this shortcode.', SH_CD_SLUG ),
220 __( 'Permanently delete and remove this shortcode.', SH_CD_SLUG ),
221 __( 'Clone this shortcode to create an identical copy for editing', SH_CD_SLUG ),
222 __( 'Enable or disable a shortcode. When enabled, the shortcode will not be rendered on the website\'s public facing side.', SH_CD_SLUG ),
223 $multisite_column,
224 __( 'Copy to clipboard', SH_CD_SLUG ),
225 wp_kses( $icons, [ 'i' => [ 'class' => [], 'title' => [] ] ] )
226 );
227
228 $i++;
229 }
230 }
231 else {
232 printf( '<tr><td colspan="5" align="center">%1$s. <a href="%2$s">%3$s</a></td></tr>',
233 __( 'You haven\'t created any shortcodes yet', SH_CD_SLUG ),
234 sh_cd_link_your_shortcodes_add(),
235 __( 'Add one now!', SH_CD_SLUG )
236 );
237 }
238 ?>
239 </table>
240 <br clear="all" />
241 </div>
242 </div>
243 </div>
244 </div>
245 </div>
246 </div>
247 </div>
248 <?php
249 }
250
251 /**
252 * Render button for adding a shortcode
253 *
254 * @param bool $show_quick_add
255 */
256 function sc_cd_display_add_button( $show_quick_add = true ) {
257
258 $limit_reached = sh_cd_reached_free_limit();
259
260 if ( true === $show_quick_add ) {
261 printf( '&nbsp;<a class="button-primary sh-cd-button button-add-inline yk-ss-button-add-quick-editor"><i class="fa-solid fa-plus"></i> %1$s</a>', __( 'Quick Add', SH_CD_SLUG ) );
262 }
263
264 printf( '&nbsp;<a class="button-primary sh-cd-button yk-ss-button-add-full-editor sh-cd-tooltip" title="%3$s" href="%1$s"><i class="fa-solid fa-file-code"></i> %2$s</a>',
265 ( false === $limit_reached ) ? sh_cd_link_your_shortcodes_add() : sh_cd_license_upgrade_link(),
266 ( false === $limit_reached ) ? __( 'Add via full editor', SH_CD_SLUG ) : __( 'You must upgrade to add more shortcodes', SH_CD_SLUG ),
267 __( 'Use the full Visual or Code editor to add a new shortcode.', SH_CD_SLUG )
268 );
269 }
270