| 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 |
$save_result = NULL; |
| 13 |
|
| 14 |
// Do we have a save event? |
| 15 |
if ( 'save' === $action ) { |
| 16 |
|
| 17 |
check_admin_referer( 'save-shortcode' ); |
| 18 |
|
| 19 |
$save_result = false; |
| 20 |
|
| 21 |
if ( false === empty( $_POST[ 'id'] ) || |
| 22 |
false === sh_cd_reached_free_limit() ) { |
| 23 |
$save_result = sh_cd_shortcodes_save_post(); |
| 24 |
|
| 25 |
// Success? |
| 26 |
if ( true === $save_result ) { |
| 27 |
$action = 'list'; |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
switch ( $action ) { |
| 33 |
|
| 34 |
case 'add': |
| 35 |
case 'edit': |
| 36 |
case 'save': |
| 37 |
sh_cd_pages_your_shortcodes_edit( $action, $save_result ); |
| 38 |
break; |
| 39 |
default: |
| 40 |
sh_cd_pages_your_shortcodes_list( $action, $save_result ); |
| 41 |
} |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Display all shortcodes |
| 47 |
* @param null $action |
| 48 |
* @param null $save_result |
| 49 |
*/ |
| 50 |
function sh_cd_pages_your_shortcodes_list($action = NULL, $save_result = NULL) { |
| 51 |
|
| 52 |
sh_cd_permission_check(); |
| 53 |
|
| 54 |
// Cloning a shortcode? |
| 55 |
if ( 'clone' === $action && false === empty( $_GET['id'] ) ) { |
| 56 |
sh_cd_clone( (int) $_GET['id'] ); |
| 57 |
} |
| 58 |
|
| 59 |
if ( true == $save_result ) { |
| 60 |
sh_cd_message_display( __( 'Your shortcode has been saved!', SH_CD_SLUG ) ); |
| 61 |
} |
| 62 |
|
| 63 |
?> |
| 64 |
<div class="wrap"> |
| 65 |
<div id="icon-options-general" class="icon32"></div> |
| 66 |
<div id="poststuff"> |
| 67 |
<div id="post-body" class="metabox-holder columns-3"> |
| 68 |
<div id="post-body-content"> |
| 69 |
<div class="meta-box-sortables ui-sortable"> |
| 70 |
<div class="postbox"> |
| 71 |
<div class="postbox-header"> |
| 72 |
<h2 class="hndle"><span><?php echo __( 'Your existing Snippet Shortcodes', SH_CD_SLUG ); ?></span></h2> |
| 73 |
</div> |
| 74 |
<div style="padding: 0px 15px 0px 15px"> |
| 75 |
<table width="100%" style="margin-top: 10px"> |
| 76 |
<tr> |
| 77 |
<td> |
| 78 |
<?php |
| 79 |
|
| 80 |
if ( false === SH_CD_IS_PREMIUM ) { |
| 81 |
printf( '%s %d %s %d %s. <a href="%s">%s</a>', |
| 82 |
__( 'Used', SH_CD_SLUG ), |
| 83 |
sh_cd_db_shortcodes_count(), |
| 84 |
__( 'of', SH_CD_SLUG ), |
| 85 |
SH_CD_FREE_SHORTCODE_LIMIT, |
| 86 |
__( 'shortcodes', SH_CD_SLUG ), |
| 87 |
sh_cd_license_upgrade_link(), |
| 88 |
__( 'Go unlimited!', SH_CD_SLUG ) |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
?> |
| 93 |
</td> |
| 94 |
<td align="right"> |
| 95 |
<?php |
| 96 |
if ( false === SH_CD_IS_PREMIUM ) { |
| 97 |
sh_cd_upgrade_button( 'sh-cd-hide', sh_cd_license_upgrade_link() ); |
| 98 |
} |
| 99 |
|
| 100 |
sc_cd_display_add_button(); |
| 101 |
?> |
| 102 |
</td> |
| 103 |
</tr> |
| 104 |
</table> |
| 105 |
<p style="text-align: right"> |
| 106 |
|
| 107 |
</p> |
| 108 |
<table class="widefat sh-cd-table" width="100%"> |
| 109 |
<tr class="row-title"> |
| 110 |
<th class="row-title" width="20%"><?php echo __( 'Shortcode', SH_CD_SLUG ); ?></th> |
| 111 |
<th width="*"><?php echo __( 'Shortcode content', SH_CD_SLUG ); ?></th> |
| 112 |
<th width="60px" align="middle"><?php echo __( 'Global', SH_CD_SLUG ); ?></th> |
| 113 |
<th width="60px" align="middle"><?php echo __( 'Enabled', SH_CD_SLUG ); ?></th> |
| 114 |
<th width="70px" align="middle"><?php echo __( 'Options', SH_CD_SLUG ); ?></th> |
| 115 |
</tr> |
| 116 |
<?php |
| 117 |
|
| 118 |
printf( '<tr class="sh-cd-hide" id="sh-cd-add-inline"> |
| 119 |
<td><input type="text" maxlength="100" placeholder="%1$s" id="sh-cd-add-inline-slug" /></td> |
| 120 |
<td align="right"> |
| 121 |
<textarea class="large-text inline-text-shortcode" id="sh-cd-add-inline-text"></textarea> |
| 122 |
<label for="sh-cd-add-inline-clear" >%3$s </label><input type="checkbox" id="sh-cd-add-inline-clear" value="true" checked="checked" /> |
| 123 |
</td> |
| 124 |
<td align="middle"><input type="checkbox" id="sh-cd-add-inline-global" value="true" /></td> |
| 125 |
<td align="middle"><input type="checkbox" id="sh-cd-add-inline-enabled" value="true" checked="checked" /></td> |
| 126 |
<td width="100"> |
| 127 |
<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> |
| 128 |
</td> |
| 129 |
</tr> |
| 130 |
<tr class="sh-cd-hide" id="sh-cd-add-inline-results"> |
| 131 |
<td></td> |
| 132 |
<td cospan="4" id="sh-cd-add-inline-results-text"> |
| 133 |
<p><strong>%4$s:</strong></p> |
| 134 |
<span></span> |
| 135 |
</td> |
| 136 |
</tr> |
| 137 |
|
| 138 |
', |
| 139 |
__( 'Slug', SH_CD_SLUG ), |
| 140 |
__( 'Add', SH_CD_SLUG ), |
| 141 |
__( 'Clear form after save', SH_CD_SLUG ), |
| 142 |
__( 'Shortcode(s) added (refresh page to edit)', SH_CD_SLUG ), |
| 143 |
( false === SH_CD_IS_PREMIUM ) ? ' disabled="disabled"' : '' |
| 144 |
); |
| 145 |
|
| 146 |
$current_shortcodes = sh_cd_db_shortcodes_all(); |
| 147 |
|
| 148 |
if ( false === empty( $current_shortcodes ) ) { |
| 149 |
|
| 150 |
$class = ''; |
| 151 |
$link = sh_cd_link_your_shortcodes(); |
| 152 |
$i = 0; |
| 153 |
$limit_reached = sh_cd_reached_free_limit(); |
| 154 |
|
| 155 |
foreach ( $current_shortcodes as $shortcode ) { |
| 156 |
|
| 157 |
$class = ($class == 'alternate') ? '' : 'alternate'; |
| 158 |
|
| 159 |
$id = (int) $shortcode['id']; |
| 160 |
|
| 161 |
printf( '<tr class="%1$s" id="sh-cd-row-%8$s"> |
| 162 |
<td><a href="%2$s">[%4$s slug="%3$s"]</a></td> |
| 163 |
<td align="right"> |
| 164 |
<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> |
| 165 |
<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> |
| 166 |
</td> |
| 167 |
<td align="middle"><a class="button button-small toggle-multisite sh-cd-toggle-%13$s" id="sc-cd-multisite-%8$s" data-id="%8$s" %13$s ><i class="fas %10$s"></i></a></td> |
| 168 |
<td align="middle"><a class="button button-small toggle-disable sh-cd-toggle-%13$s" id="sc-cd-toggle-%8$s" data-id="%8$s" %13$s ><i class="fas %6$s"></i></a></td> |
| 169 |
<td width="100"> |
| 170 |
<a class="button button-small sh-cd-toggle-%13$s" %13$s href="%9$s"><i class="far fa-clone"></i></a> |
| 171 |
<a class="button button-small" href="%2$s" %14$s><i class="far fa-edit"></i></a> |
| 172 |
<a class="button button-small delete-shortcode" data-id="%8$s"><i class="fas fa-trash-alt"></i></a> |
| 173 |
</td> |
| 174 |
</tr>', |
| 175 |
$class, |
| 176 |
( true === $limit_reached && $i > SH_CD_FREE_SHORTCODE_LIMIT ) ? sh_cd_license_upgrade_link() : $link . '&action=edit&id=' . $id, |
| 177 |
esc_html( $shortcode['slug'] ), |
| 178 |
SH_CD_SHORTCODE, |
| 179 |
( true === SH_CD_IS_PREMIUM ) ? esc_html( stripslashes( $shortcode['data'] ) ) : __( 'Upgrade for inline editing and toggles.', SH_CD_SLUG ), |
| 180 |
( 1 === (int) $shortcode['disabled'] ) ? 'fa-times' : 'fa-check', |
| 181 |
$link . '&action=delete&id=' . $id, |
| 182 |
$id, |
| 183 |
( true === SH_CD_IS_PREMIUM ) ? $link . '&action=clone&id=' . $id : sh_cd_license_upgrade_link(), |
| 184 |
( 1 === (int) $shortcode['multisite'] ) ? 'fa-check' : 'fa-times', |
| 185 |
__( 'Save', SH_CD_SLUG ), |
| 186 |
__( 'Are you sure you want to delete this shortcode?', SH_CD_SLUG ), |
| 187 |
( false === SH_CD_IS_PREMIUM ) ? 'disabled' : '', |
| 188 |
( true === $limit_reached && $i > SH_CD_FREE_SHORTCODE_LIMIT ) ? 'disabled' : '' |
| 189 |
); |
| 190 |
|
| 191 |
$i++; |
| 192 |
} |
| 193 |
} |
| 194 |
else { |
| 195 |
printf( '<tr><td colspan="5" align="center">%1$s. <a href="%2$s">%3$s</a></td></tr>', |
| 196 |
__( 'You haven\'t created any shortcodes yet', SH_CD_SLUG ), |
| 197 |
sh_cd_link_your_shortcodes_add(), |
| 198 |
__( 'Add one now!', SH_CD_SLUG ) |
| 199 |
); |
| 200 |
} |
| 201 |
?> |
| 202 |
</table> |
| 203 |
<p style="text-align: right"> |
| 204 |
<?php sc_cd_display_add_button( false ); ?> |
| 205 |
</p> |
| 206 |
<br clear="all" /> |
| 207 |
</div> |
| 208 |
</div> |
| 209 |
</div> |
| 210 |
</div> |
| 211 |
</div> |
| 212 |
</div> |
| 213 |
</div> |
| 214 |
<?php |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* Render button for adding a shortcode |
| 219 |
* |
| 220 |
* @param bool $show_quick_add |
| 221 |
*/ |
| 222 |
function sc_cd_display_add_button( $show_quick_add = true ) { |
| 223 |
|
| 224 |
$limit_reached = sh_cd_reached_free_limit(); |
| 225 |
|
| 226 |
if ( true === $show_quick_add ) { |
| 227 |
printf( ' <a class="button-primary button-add-inline">%1$s</a>', __( 'Quick Add', SH_CD_SLUG ) ); |
| 228 |
} |
| 229 |
|
| 230 |
printf( ' <a class="button-primary" href="%1$s">%2$s</a>', |
| 231 |
( false === $limit_reached ) ? sh_cd_link_your_shortcodes_add() : sh_cd_license_upgrade_link(), |
| 232 |
( false === $limit_reached ) ? __( 'Add via Editor', SH_CD_SLUG ) : __( 'You must upgrade to add more shortcodes', SH_CD_SLUG ) |
| 233 |
); |
| 234 |
} |
| 235 |
|