/** * Register shortcodes * @filename Generating shortcode file path for include shortcode file * @shortcode_tag Generating shortcode tag for use in class * @shortcode_class Making class name for call the shortcode * @su_add_shortcode() Registering shortcode */ function register_shortcodes() { // Prepare compatibility mode prefix $prefix = su_cmpt(); // Template shortcode verible $get_tmpl_shortcode = JPATH_ROOT . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . BDT_SU_CTMPL; foreach ((array) Su_Data::shortcodes() as $id => $data) { $template_shortcode = $get_tmpl_shortcode . DIRECTORY_SEPARATOR . 'html' . DIRECTORY_SEPARATOR . 'plg_bdthemes_shortcodes' . DIRECTORY_SEPARATOR . 'shortcodes' . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR . 'shortcode.php'; $core_shortcode = BDT_SU_ROOT . DIRECTORY_SEPARATOR . 'shortcodes' . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR . 'shortcode.php'; if (file_exists($template_shortcode)) { require_once $template_shortcode; } elseif (file_exists($core_shortcode)) { require_once $core_shortcode; } if (isset($data['function']) && is_callable($data['function'])) { $func = $data['function']; } elseif (is_callable(array('Su_Shortcode_' . $id, $id))) { $func = array('Su_Shortcode_' . $id, $id); } elseif (is_callable(array('Su_Shortcode_' . $id, 'su_' . $id))) { $func = array('Su_Shortcode_' . $id, 'su_' . $id); } else { continue; } // Register shortcode su_add_shortcode($prefix . $id, $func); } }
/** * Register shortcodes */ public static function register() { // Prepare compatibility mode prefix $prefix = su_cmpt(); // Loop through shortcodes foreach ((array) Su_Data::shortcodes() as $id => $data) { if (isset($data['function']) && is_callable($data['function'])) { $func = $data['function']; } elseif (is_callable(array('Su_Shortcodes', $id))) { $func = array('Su_Shortcodes', $id); } elseif (is_callable(array('Su_Shortcodes', 'su_' . $id))) { $func = array('Su_Shortcodes', 'su_' . $id); } else { continue; } // Register shortcode add_shortcode($prefix . $id, $func); } // Register [media] manually // 3.x add_shortcode($prefix . 'media', array('Su_Shortcodes', 'media')); }
public static function cheatsheet($field, $config) { // Prepare print button $print = '<div><a href="javascript:;" id="su-cheatsheet-print" class="su-cheatsheet-switch button button-primary button-large">' . __('Printable version', 'shortcodes-ultimate') . '</a><div id="su-cheatsheet-print-head"><h1>' . __('Shortcodes Ultimate', 'shortcodes-ultimate') . ': ' . __('Cheatsheet', 'shortcodes-ultimate') . '</h1><a href="javascript:;" class="su-cheatsheet-switch">← ' . __('Back to Dashboard', 'shortcodes-ultimate') . '</a></div></div>'; // Prepare table array $table = array(); // Table start $table[] = '<table><tr><th style="width:20%;">' . __('Shortcode', 'shortcodes-ultimate') . '</th><th style="width:50%">' . __('Attributes', 'shortcodes-ultimate') . '</th><th style="width:30%">' . __('Example code', 'shortcodes-ultimate') . '</th></tr>'; // Loop through shortcodes foreach ((array) Su_Data::shortcodes() as $name => $shortcode) { // Prepare vars $icon = isset($shortcode['icon']) ? $shortcode['icon'] : 'puzzle-piece'; $shortcode['name'] = isset($shortcode['name']) ? $shortcode['name'] : $name; $attributes = array(); $example = array(); $icons = 'icon: music, icon: envelope … <a href="http://fortawesome.github.io/Font-Awesome/icons/" target="_blank">' . __('full list', 'shortcodes-ultimate') . '</a>'; // Loop through attributes if (is_array($shortcode['atts'])) { foreach ($shortcode['atts'] as $id => $data) { // Prepare default value $default = isset($data['default']) && $data['default'] !== '' ? '<p><em>' . __('Default value', 'shortcodes-ultimate') . ':</em> ' . $data['default'] . '</p>' : ''; // Check type is set if (empty($data['type'])) { $data['type'] = 'text'; } // Switch attribute types switch ($data['type']) { // Select case 'select': $value = implode(', ', array_keys($data['values'])); break; // Slider and number // Slider and number case 'slider': case 'number': $value = $data['min'] . '…' . $data['max']; break; // Bool // Bool case 'bool': $value = 'yes | no'; break; // Icon // Icon case 'icon': $value = $icons; break; // Color // Color case 'color': $value = __('#RGB and rgba() colors'); break; // Default value // Default value default: $value = $data['default']; break; } // Check empty value if ($value === '') { $value = __('Any text value', 'shortcodes-ultimate'); } // Extra CSS class if ($id === 'class') { $value = __('Any custom CSS classes', 'shortcodes-ultimate'); } // Add attribute $attributes[] = '<div class="su-shortcode-attribute"><strong>' . $data['name'] . ' <em>– ' . $id . '</em></strong><p><em>' . __('Possible values', 'shortcodes-ultimate') . ':</em> ' . $value . '</p>' . $default . '</div>'; // Add attribute to the example code $example[] = $id . '="' . $data['default'] . '"'; } } // Prepare example code $example = '[%prefix_' . $name . ' ' . implode(' ', $example) . ']'; // Prepare content value if (empty($shortcode['content'])) { $shortcode['content'] = ''; } // Add wrapping code if ($shortcode['type'] === 'wrap') { $example .= esc_textarea($shortcode['content']) . '[/%prefix_' . $name . ']'; } // Change compatibility prefix $example = str_replace(array('%prefix_', '__'), su_cmpt(), $example); // Shortcode $table[] = '<td>' . '<span class="su-shortcode-icon">' . Su_Tools::icon($icon) . '</span>' . $shortcode['name'] . '<br/><em class="su-shortcode-desc">' . $shortcode['desc'] . '</em></td>'; // Attributes $table[] = '<td>' . implode('', $attributes) . '</td>'; // Example code $table[] = '<td><code contenteditable="true">' . $example . '</code></td></tr>'; } // Table end $table[] = '</table>'; // Query assets su_query_asset('css', array('font-awesome', 'su-cheatsheet')); su_query_asset('js', array('jquery', 'su-options-page')); // Return output return '<div id="su-cheatsheet-screen">' . $print . implode('', $table) . '</div>'; }
/** * Process AJAX request */ public static function settings() { self::access(); // Param check if (empty($_REQUEST['shortcode'])) { wp_die(__('Shortcode not specified', 'su')); } // Get cache $output = get_transient('su/generator/settings/' . sanitize_text_field($_REQUEST['shortcode'])); if ($output && SU_ENABLE_CACHE) { echo $output; } else { // Request queried shortcode $shortcode = Su_Data::shortcodes(sanitize_key($_REQUEST['shortcode'])); // Prepare skip-if-default option $skip = get_option('su_option_skip') === 'on' ? ' su-generator-skip' : ' su-generator-skip'; // Prepare actions $actions = apply_filters('su/generator/actions', array('insert' => '<a href="javascript:void(0);" class="button button-primary button-large su-generator-insert"><i class="fa fa-check"></i> ' . __('Insert shortcode', 'su') . '</a>', 'preview' => '<a href="javascript:void(0);" class="button button-large su-generator-toggle-preview"><i class="fa fa-eye"></i> ' . __('Live preview', 'su') . '</a>')); // Shortcode header $return = '<div id="su-generator-breadcrumbs">'; $return .= apply_filters('su/generator/breadcrumbs', '<a href="javascript:void(0);" class="su-generator-home" title="' . __('Click to return to the shortcodes list', 'su') . '">' . __('All shortcodes', 'su') . '</a> → <span>' . $shortcode['name'] . '</span> <small class="alignright">' . $shortcode['desc'] . '</small><div class="su-generator-clear"></div>'); $return .= '</div>'; // Shortcode has atts if (count($shortcode['atts']) && $shortcode['atts']) { // Loop through shortcode parameters foreach ($shortcode['atts'] as $attr_name => $attr_info) { // Prepare default value $default = (string) isset($attr_info['default']) ? $attr_info['default'] : ''; $attr_info['name'] = isset($attr_info['name']) ? $attr_info['name'] : $attr_name; $return .= '<div class="su-generator-attr-container' . $skip . '" data-default="' . esc_attr($default) . '">'; $return .= '<h5>' . $attr_info['name'] . '</h5>'; // Create field types if (!isset($attr_info['type']) && isset($attr_info['values']) && is_array($attr_info['values']) && count($attr_info['values'])) { $attr_info['type'] = 'select'; } elseif (!isset($attr_info['type'])) { $attr_info['type'] = 'text'; } if (is_callable(array('Su_Generator_Views', $attr_info['type']))) { $return .= call_user_func(array('Su_Generator_Views', $attr_info['type']), $attr_name, $attr_info); } elseif (isset($attr_info['callback']) && is_callable($attr_info['callback'])) { $return .= call_user_func($attr_info['callback'], $attr_name, $attr_info); } if (isset($attr_info['desc'])) { $return .= '<div class="su-generator-attr-desc">' . str_replace('<b%value>', '<b class="su-generator-set-value" title="' . __('Click to set this value', 'su') . '">', $attr_info['desc']) . '</div>'; } $return .= '</div>'; } } // Single shortcode (not closed) if ($shortcode['type'] == 'single') { $return .= '<input type="hidden" name="su-generator-content" id="su-generator-content" value="false" />'; } else { $return .= '<div class="su-generator-attr-container"><h5>' . __('Content', 'su') . '</h5><textarea name="su-generator-content" id="su-generator-content" rows="3">' . esc_attr(str_replace('%prefix_', su_cmpt(), $shortcode['content'])) . '</textarea></div>'; } $return .= '<div id="su-generator-preview"></div>'; $return .= '<div class="su-generator-actions su-generator-clearfix">' . implode(' ', array_values($actions)) . '</div>'; set_transient('su/generator/settings/' . sanitize_text_field($_REQUEST['shortcode']), $return, 2 * DAY_IN_SECONDS); echo $return; } exit; }
public static function example() { // Check authentication self::access(); // Check incoming data if (!isset($_REQUEST['code']) || !isset($_REQUEST['id'])) { return; } // Check for cache $output = get_transient('su/examples/render/' . sanitize_key($_REQUEST['id'])); if ($output && SU_ENABLE_CACHE) { echo $output; } else { ob_start(); // Prepare data $code = file_get_contents(sanitize_text_field($_REQUEST['code'])); // Check for code if (!$code) { die('<p class="su-examples-error">' . __('Example code does not found, please check it later', 'su') . '</p>'); } // Clean-up the code $code = str_replace(array("\t", '%su_'), array(' ', su_cmpt()), $code); // Split code $chunks = explode('-----', $code); // Show snippets do_action('su/examples/preview/before'); foreach ($chunks as $chunk) { // Clean-up new lines $chunk = trim($chunk, "\n\r"); // Calc textarea rows $rows = substr_count($chunk, "\n"); $rows = $rows < 4 ? '4' : (string) ($rows + 1); $rows = $rows > 20 ? '20' : (string) ($rows + 1); echo wpautop(do_shortcode($chunk)); echo '<div style="clear:both"></div>'; echo '<div class="su-examples-code"><span class="su-examples-get-code button"><i class="fa fa-code"></i> ' . __('Get the code', 'su') . '</span><textarea rows="' . $rows . '">' . esc_textarea($chunk) . '</textarea></div>'; } do_action('su/examples/preview/after'); $output = ob_get_contents(); ob_end_clean(); set_transient('su/examples/render/' . sanitize_key($_REQUEST['id']), $output); echo $output; } die; }
/** * Custom formatter function * * @param string $content * * @return string Formatted content with clean shortcodes content */ function su_clean_shortcodes($content) { $p = su_cmpt(); $array = array('<p>[' => '[', ']</p>' => ']', ']<br />' => ']'); $content = strtr($content, $array); return $content; }
/** * Process AJAX request */ public static function settings() { // Request queried shortcode $shortcode = Su_Data::shortcodes($_REQUEST['shortcode']); $sueid = $_REQUEST["e_name"]; // Prepare actions $actions = array('insert' => '<a href="javascript:void(0);" class="btn btn-primary su-generator-insert" data-sueid="' . $sueid . '"><i class="fa fa-check"></i> ' . JText::_('PLG_SYSTEM_BDTHEMES_SHORTCODES_INSERT_SORTCODE') . '</a>', 'preview' => '<a href="javascript:void(0);" class="btn su-generator-toggle-preview"><i class="fa fa-eye"></i> ' . JText::_('PLG_SYSTEM_BDTHEMES_SHORTCODES_LIVE_PREVIEW') . '</a>', 'showcode' => '<a href="javascript:void(0);" class="btn su-generator-shortcode-preview"><i class="fa fa-code"></i> ' . JText::_('PLG_SYSTEM_BDTHEMES_SHORTCODES_SHOW_CODE') . '</a>'); // Shortcode header $return = '<div id="su-generator-breadcrumbs">'; $return .= '<a href="javascript:void(0);" class="su-generator-home" title="' . JText::_('PLG_SYSTEM_BDTHEMES_SHORTCODES_ALL_SHORTCODE_DESC') . '">' . JText::_('PLG_SYSTEM_BDTHEMES_SHORTCODES_ALL_SHORTCODE') . '</a> → <span>' . $shortcode['name'] . '</span> <small class="alignright">' . $shortcode['desc'] . '</small><div class="su-generator-clear"></div>'; $return .= '</div>'; // Shortcode has atts if (count($shortcode['atts']) && $shortcode['atts']) { // Loop through shortcode parameters foreach ($shortcode['atts'] as $attr_name => $attr_info) { if (!empty($attr_info["child"]) && is_array($attr_info["child"]) && count($attr_info["child"]) > 0) { $return .= '<div class="su-generator-field-group">'; } $return .= self::GetOptionByAttr($attr_name, $attr_info); if (!empty($attr_info["child"]) && is_array($attr_info["child"]) && count($attr_info["child"]) > 0) { foreach ($attr_info["child"] as $attr_name_child => $attr_info_child) { $return .= self::GetOptionByAttr($attr_name_child, $attr_info_child); } $return .= '</div>'; } } } // Single shortcode (not closed) if ($shortcode['type'] == 'single') { $return .= '<input type="hidden" name="su-generator-content" id="su-generator-content" value="false" />'; } else { $return .= '<div class="su-generator-field-container"><h5>' . JText::_('PLG_SYSTEM_BDTHEMES_SHORTCODES_CONTENT') . '</h5><textarea name="su-generator-content" id="su-generator-content" rows="5">' . esc_attr(str_replace(array('%prefix_', '__'), su_cmpt(), $shortcode['content'])) . '</textarea></div>'; } $return .= '<div id="su-generator-preview"></div>'; $return .= '<div class="su-generator-actions su-generator-clearfix">' . implode(' ', array_values($actions)); $return .= '<div data-shortcode="gmap" class="su-generator-presets alignright"> <a class="button button-large su-gp-button btn btn-success" href="javascript:void(0);"><i class="fa fa-bars"></i> ' . JText::_("PLG_SYSTEM_BDTHEMES_SHORTCODES_PRESETS") . '</a> <div class="su-gp-popup" style="display: none;"> <div class="su-gp-head"> <a class="btn btn-small btn-success su-gp-new" href="javascript:void(0);">' . JText::_("PLG_SYSTEM_BDTHEMES_SHORTCODES_PRESETS_DESC") . '</a> </div> <div class="su-gp-list"> <b>' . JText::_("PLG_SYSTEM_BDTHEMES_SHORTCODES_PRESETS_NOT_FOUND") . '</b> </div> </div> </div> </div>'; echo $return; exit; }