| 1 |
<?php |
| 2 |
|
| 3 |
defined('ABSPATH') or die("Jog on!"); |
| 4 |
|
| 5 |
/** |
| 6 |
* Determine if the slug belongs to a preset |
| 7 |
* @param $slug |
| 8 |
*/ |
| 9 |
function sh_cd_is_preset( $slug ) { |
| 10 |
|
| 11 |
// Free preset? |
| 12 |
if ( true === array_key_exists( $slug, sh_cd_shortcode_presets_free_list() ) ) { |
| 13 |
return 'free'; |
| 14 |
} |
| 15 |
|
| 16 |
// Premium preset? |
| 17 |
if ( true === array_key_exists( $slug, sh_cd_shortcode_presets_premium_list() ) ) { |
| 18 |
return 'premium'; |
| 19 |
} |
| 20 |
|
| 21 |
return false; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Return all free and premium premade shortcodes |
| 26 |
* |
| 27 |
* @return array |
| 28 |
*/ |
| 29 |
function sh_cd_presets_both_lists() { |
| 30 |
|
| 31 |
$both = array_merge( sh_cd_shortcode_presets_free_list(), sh_cd_shortcode_presets_premium_list() ); |
| 32 |
|
| 33 |
ksort( $both ); |
| 34 |
|
| 35 |
return $both; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* For a given preset, look up the class information, if valid, initiate the class and render |
| 40 |
* |
| 41 |
* @param $args |
| 42 |
* |
| 43 |
* @return string |
| 44 |
*/ |
| 45 |
function sh_cd_shortcode_presets_render( $args ) { |
| 46 |
|
| 47 |
$preset = sh_cd_shortcode_presets_fetch( $args[ 'slug' ] ); |
| 48 |
|
| 49 |
// Not a preset? |
| 50 |
if ( false === $preset ) { |
| 51 |
return ''; |
| 52 |
} |
| 53 |
|
| 54 |
// Is this a premium shortcode but no license? |
| 55 |
if ( 'premium' === $preset['sh-cd-type'] && false === sh_cd_license_is_premium() ) { |
| 56 |
return sprintf( '<p><strong>%s</strong> %s. <a href="%s">%s</a>.<p>', |
| 57 |
__( 'Ooops!', SH_CD_SLUG ), |
| 58 |
__('Unfortunately this is a Premium shortcode. You need to upgrade "Shortcode Variables" to use it', SH_CD_SLUG ), |
| 59 |
sh_cd_license_upgrade_link(), |
| 60 |
__('Upgrade now', SH_CD_SLUG ) |
| 61 |
); |
| 62 |
} |
| 63 |
|
| 64 |
$class_name = 'SV_' . $preset[ 'class' ]; |
| 65 |
|
| 66 |
if ( true === class_exists( $class_name ) ) { |
| 67 |
|
| 68 |
$shortcode = new $class_name(); |
| 69 |
|
| 70 |
// Any plugin arguments? |
| 71 |
if ( false === empty( $preset['args'] ) ) { |
| 72 |
$args = array_merge( $args, $preset['args'] ); |
| 73 |
} |
| 74 |
|
| 75 |
$shortcode->set_arguments( $args ); |
| 76 |
|
| 77 |
$shortcode->init(); |
| 78 |
|
| 79 |
return $shortcode->sanitised(); |
| 80 |
} |
| 81 |
|
| 82 |
return ''; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* For a given slug, fetch the preset information regarding it. |
| 87 |
* |
| 88 |
* @param $slug |
| 89 |
* |
| 90 |
* @return bool |
| 91 |
*/ |
| 92 |
function sh_cd_shortcode_presets_fetch( $slug ) { |
| 93 |
|
| 94 |
$free_presets = sh_cd_shortcode_presets_free_list(); |
| 95 |
|
| 96 |
// Free preset? |
| 97 |
if ( true === array_key_exists( $slug, $free_presets ) ) { |
| 98 |
|
| 99 |
$preset = $free_presets[ $slug ]; |
| 100 |
$preset['sh-cd-type'] = 'free'; |
| 101 |
|
| 102 |
return $preset; |
| 103 |
} |
| 104 |
|
| 105 |
$premium_presents = sh_cd_shortcode_presets_premium_list(); |
| 106 |
|
| 107 |
// Premium preset? |
| 108 |
if ( true === array_key_exists( $slug, $premium_presents ) ) { |
| 109 |
|
| 110 |
$preset = $premium_presents[ $slug ]; |
| 111 |
$preset['sh-cd-type'] = 'premium'; |
| 112 |
|
| 113 |
return $preset; |
| 114 |
} |
| 115 |
|
| 116 |
return false; |
| 117 |
|
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Render text file for promo |
| 122 |
*/ |
| 123 |
function sh_cd_shortcode_render_text() { |
| 124 |
|
| 125 |
$output = '**Premium Shortcodes**' . PHP_EOL; |
| 126 |
|
| 127 |
$shortcodes = sh_cd_shortcode_presets_premium_list(); |
| 128 |
|
| 129 |
foreach ( $shortcodes as $key => $data ) { |
| 130 |
$output .= sprintf('- %s - %s' . PHP_EOL , $key, $data['description'] ); |
| 131 |
} |
| 132 |
|
| 133 |
$output .= '**Free Shortcodes**' . PHP_EOL; |
| 134 |
|
| 135 |
$shortcodes = sh_cd_shortcode_presets_free_list(); |
| 136 |
|
| 137 |
foreach ( $shortcodes as $key => $data ) { |
| 138 |
$output .= sprintf('- %s - %s' . PHP_EOL , $key, $data['description'] ); |
| 139 |
} |
| 140 |
|
| 141 |
return $output; |
| 142 |
|
| 143 |
} |
| 144 |
add_shortcode( 'sv-promo', 'sh_cd_shortcode_render_text' ); |
| 145 |
|
| 146 |
/** |
| 147 |
* Shortcode to render free shortcodes (more for promo purposes) |
| 148 |
* |
| 149 |
* @return string |
| 150 |
*/ |
| 151 |
function sh_cd_shortcode_render_table_free() { |
| 152 |
|
| 153 |
return sh_cd_display_premade_shortcodes( 'free' ); |
| 154 |
|
| 155 |
} |
| 156 |
add_shortcode( 'sv-promo-free', 'sh_cd_shortcode_render_table_free'); |
| 157 |
|
| 158 |
/** |
| 159 |
* Shortcode to render premium shortcodes (more for promo purposes) |
| 160 |
* |
| 161 |
* @return string |
| 162 |
*/ |
| 163 |
function sh_cd_shortcode_render_table_premium() { |
| 164 |
|
| 165 |
return sh_cd_display_premade_shortcodes( 'premium' ); |
| 166 |
|
| 167 |
} |
| 168 |
add_shortcode( 'sv-promo-premium', 'sh_cd_shortcode_render_table_premium'); |
| 169 |
|
| 170 |
/** |
| 171 |
* Shortcode to render all shortcodes (more for promo purposes) |
| 172 |
* |
| 173 |
* @return string |
| 174 |
*/ |
| 175 |
function sh_cd_shortcode_render_table_all() { |
| 176 |
|
| 177 |
return sh_cd_display_premade_shortcodes(); |
| 178 |
|
| 179 |
} |
| 180 |
add_shortcode( 'sv-promo-all', 'sh_cd_shortcode_render_table_all'); |