shortcoder
Last commit date
images
10 years ago
js
10 years ago
languages
10 years ago
readme.txt
10 years ago
sc-admin-css.css
10 years ago
sc-admin-js.js
10 years ago
sc-insert.php
10 years ago
screenshot-1.png
10 years ago
screenshot-2.png
10 years ago
screenshot-3.png
10 years ago
screenshot-4.png
10 years ago
shortcoder.php
10 years ago
shortcoder.php
407 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: Shortcoder |
| 4 | Plugin URI: http://www.aakashweb.com |
| 5 | Description: Shortcoder is a plugin which allows to create a custom shortcode and store HTML, Javascript and other snippets in it. So if that shortcode is used in any post or pages, then the code stored in the shortcode get exceuted in that place. You can create a shortcode for Youtube videos, adsense ads, buttons and more. |
| 6 | Author: Aakash Chakravarthy |
| 7 | Version: 3.4.1 |
| 8 | Author URI: http://www.aakashweb.com/ |
| 9 | */ |
| 10 | |
| 11 | define('SC_VERSION', '3.4.1'); |
| 12 | define('SC_AUTHOR', 'Aakash Chakravarthy'); |
| 13 | define('SC_URL', plugins_url('',__FILE__) ); |
| 14 | define('SC_ADMIN', admin_url( 'options-general.php?page=shortcoder' ) ); |
| 15 | |
| 16 | $sc_donate_link = 'http://bit.ly/scDonate'; |
| 17 | |
| 18 | |
| 19 | |
| 20 | // Load languages |
| 21 | load_plugin_textdomain('shortcoder', false, basename(dirname(__FILE__)) . '/languages/'); |
| 22 | |
| 23 | |
| 24 | |
| 25 | // Add admin menu |
| 26 | function sc_add_menu() { |
| 27 | add_options_page( 'Shortcoder', 'Shortcoder', 'manage_options', 'shortcoder', 'sc_admin_page' ); |
| 28 | } |
| 29 | |
| 30 | add_action('admin_menu','sc_add_menu'); |
| 31 | |
| 32 | |
| 33 | |
| 34 | // Load the Javascripts |
| 35 | function sc_admin_js(){ |
| 36 | // Check whether the page is the Shortcoder admin page. |
| 37 | if (isset($_GET['page']) && $_GET['page'] == 'shortcoder'){ |
| 38 | wp_enqueue_script(array( |
| 39 | 'jquery', |
| 40 | 'jquery-ui-core', |
| 41 | 'jquery-ui-draggable', |
| 42 | 'jquery-ui-droppable' |
| 43 | )); |
| 44 | wp_enqueue_script('shortcoder-admin-js', SC_URL . '/sc-admin-js.js?v=' . SC_VERSION); |
| 45 | } |
| 46 | } |
| 47 | add_action('admin_print_scripts', 'sc_admin_js'); |
| 48 | |
| 49 | |
| 50 | |
| 51 | // Load the CSS |
| 52 | function sc_admin_css(){ |
| 53 | if (isset($_GET['page']) && $_GET['page'] == 'shortcoder') { |
| 54 | wp_enqueue_style('shortcoder-admin-css', SC_URL . '/sc-admin-css.css?v=' . SC_VERSION); |
| 55 | } |
| 56 | } |
| 57 | add_action('admin_print_styles', 'sc_admin_css'); |
| 58 | |
| 59 | |
| 60 | |
| 61 | // Plugin on activate fixes |
| 62 | function sc_onactivate(){ |
| 63 | $sc_options = get_option('shortcoder_data'); |
| 64 | $sc_flags = get_option('shortcoder_flags'); |
| 65 | |
| 66 | // Move the flag version fix to sc_flags option |
| 67 | if(isset($sc_options['_version_fix'])){ |
| 68 | unset($sc_options['_version_fix']); |
| 69 | update_option('shortcoder_data', $sc_options); |
| 70 | } |
| 71 | |
| 72 | $sc_flags['version'] = SC_VERSION; |
| 73 | update_option('shortcoder_flags', $sc_flags); |
| 74 | |
| 75 | } |
| 76 | register_activation_hook(__FILE__, 'sc_onactivate'); |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | // Register the shortcode |
| 82 | add_shortcode('sc', 'shortcoder'); |
| 83 | |
| 84 | function shortcoder_all_ok($name){ |
| 85 | |
| 86 | $sc_options = get_option('shortcoder_data'); |
| 87 | |
| 88 | if($sc_options[$name]['disabled'] == 0){ |
| 89 | if(current_user_can('level_10') && $sc_options[$name]['hide_admin'] == 1){ |
| 90 | return false; |
| 91 | }else{ |
| 92 | return true; |
| 93 | } |
| 94 | }else{ |
| 95 | return false; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // Main function |
| 100 | function shortcoder($atts, $content) { |
| 101 | |
| 102 | $sc_options = get_option('shortcoder_data'); |
| 103 | |
| 104 | // Get the Shortcode name |
| 105 | if(isset($atts[0])){ |
| 106 | $sc_name = str_replace(array('"', "'", ":"), '', $atts[0]); |
| 107 | unset($atts[0]); |
| 108 | }else{ |
| 109 | // Old version with "name" param support |
| 110 | if(array_key_exists("name", $atts)){ |
| 111 | $tVal = $atts['name']; |
| 112 | if(array_key_exists($tVal, $sc_options)){ |
| 113 | $sc_name = $tVal; |
| 114 | unset($atts['name']); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if(!isset($sc_name)){ |
| 120 | return ''; |
| 121 | } |
| 122 | |
| 123 | // Check whether shortcoder can execute |
| 124 | if(shortcoder_all_ok($sc_name)){ |
| 125 | |
| 126 | $sc_content_final = ''; |
| 127 | |
| 128 | // If SC has parameters, then replace it |
| 129 | if(!empty($atts)){ |
| 130 | $keys = array(); |
| 131 | $values = array(); |
| 132 | $i = 0; |
| 133 | |
| 134 | // Seperate Key and value from atts |
| 135 | foreach($atts as $k=>$v){ |
| 136 | if($k !== 0){ |
| 137 | $keys[$i] = "%%" . $k . "%%"; |
| 138 | $values[$i] = $v; |
| 139 | } |
| 140 | $i++; |
| 141 | } |
| 142 | |
| 143 | // Replace the params |
| 144 | $sc_content = $sc_options[$sc_name]['content']; |
| 145 | $sc_content_rep1 = str_replace($keys, $values, $sc_content); |
| 146 | $sc_content_final = preg_replace('/%%[^%\s]+%%/', '', $sc_content_rep1); |
| 147 | |
| 148 | } |
| 149 | else{ |
| 150 | |
| 151 | // If the SC has no params, then replace the %vars% |
| 152 | $sc_content = $sc_options[$sc_name]['content']; |
| 153 | $sc_content_final = preg_replace('/%%[^%\s]+%%/', '', $sc_content); |
| 154 | |
| 155 | } |
| 156 | |
| 157 | return "<!-- Start Shortcoder content -->" . do_shortcode( $sc_content_final ) . "<!-- End Shortcoder content -->"; |
| 158 | |
| 159 | }else{ |
| 160 | return ''; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | |
| 165 | // Workaround for shortcoder not working in WordPress 4.4 |
| 166 | function sc_replace_colon_content( $content ){ |
| 167 | return str_replace( '[sc:', '[sc name=', $content ); |
| 168 | } |
| 169 | add_filter( 'the_content', 'sc_replace_colon_content', 5 ); |
| 170 | |
| 171 | |
| 172 | // Shortcoder admin page |
| 173 | function sc_admin_page(){ |
| 174 | |
| 175 | $sc_updated = false; |
| 176 | $sc_options = get_option('shortcoder_data'); |
| 177 | $sc_flags = get_option('shortcoder_flags'); |
| 178 | |
| 179 | $title = __( "Create a Shortcode", 'shortcoder' ); |
| 180 | $button = __( "Create Shortcode", 'shortcoder' ); |
| 181 | $edit = 0; |
| 182 | $sc_content = ''; |
| 183 | $sc_disable = 0; |
| 184 | $sc_hide_admin = 0; |
| 185 | |
| 186 | // Insert shortcode |
| 187 | if (isset($_POST["sc_form_main"]) && $_POST["sc_form_main"] == '1' && check_admin_referer('shortcoder_create_form')){ |
| 188 | $sc_options = get_option('shortcoder_data'); |
| 189 | $sc_name = stripslashes($_POST['sc_name']); |
| 190 | |
| 191 | $sc_post_disabled = isset( $_POST['sc_disable'] ) ? intval( $_POST['sc_disable'] ) : 0; |
| 192 | $sc_post_hideadmin = isset( $_POST['sc_hide_admin'] ) ? intval( $_POST['sc_hide_admin'] ) : 0; |
| 193 | |
| 194 | $sc_options[$sc_name] = array( |
| 195 | 'content' => stripslashes($_POST['sc_content']), |
| 196 | 'disabled' => $sc_post_disabled, |
| 197 | 'hide_admin' => $sc_post_hideadmin |
| 198 | ); |
| 199 | |
| 200 | // Updating the DB |
| 201 | update_option("shortcoder_data", $sc_options); |
| 202 | $sc_updated = true; |
| 203 | |
| 204 | // Insert Message |
| 205 | if($sc_updated == 'true'){ |
| 206 | echo '<div class="message updated fade"><p>' . __('Shortcode updated successfully !', 'shortcoder') . '</p></div>'; |
| 207 | }else{ |
| 208 | echo '<div class="message error fade"><p>' . __('Unable to create shortcode !', 'shortcoder') . '</p></div>'; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // Edit shortcode |
| 213 | if (isset($_POST["sc_form_edit"]) && $_POST["sc_form_edit"] == '1' && check_admin_referer('shortcoder_edit_form')){ |
| 214 | $sc_options = get_option('shortcoder_data'); |
| 215 | $sc_name_edit = stripslashes($_POST['sc_name_edit']); |
| 216 | |
| 217 | if($_POST["sc_form_action"] == "edit"){ |
| 218 | $sc_content = stripslashes($sc_options[$sc_name_edit]['content']); |
| 219 | $sc_disable = $sc_options[$sc_name_edit]['disabled']; |
| 220 | $sc_hide_admin = $sc_options[$sc_name_edit]['hide_admin']; |
| 221 | |
| 222 | $title = __( 'Edit this Shortcode - ', 'shortcoder' ) . '<small>' . $sc_name_edit . '</small>'; |
| 223 | $button = __( 'Update Shortcode', 'shortcoder' ); |
| 224 | $edit = 1; |
| 225 | }else{ |
| 226 | unset($sc_options[$sc_name_edit]); |
| 227 | unset($sc_name_edit); |
| 228 | update_option("shortcoder_data", $sc_options); |
| 229 | echo '<div class="message updated fade"><p>' . __('Shortcode deleted successfully !', 'shortcoder') . '</p></div>'; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | |
| 234 | ?> |
| 235 | |
| 236 | <!-- Shortcoder Admin page --> |
| 237 | |
| 238 | <div class="sc_modal"> |
| 239 | <span class="sc_modal_close"></span> |
| 240 | <div></div> |
| 241 | </div> |
| 242 | |
| 243 | <div class="wrap"> |
| 244 | <?php sc_admin_buttons('fbrec'); ?> |
| 245 | <h2><img width="32" height="32" src="<?php echo SC_URL; ?>/images/shortcoder.png" align="absmiddle"/> Shortcoder<sup class="smallText"> v<?php echo SC_VERSION; ?></sup></h2> |
| 246 | |
| 247 | <ul class="sc_share_wrap"> |
| 248 | <li class="sc_donate" data-width="300" data-height="220" data-url="<?php echo SC_URL . '/js/share.php?i=1'; ?>"><a href="#"></a></li> |
| 249 | <li class="sc_share" data-width="350" data-height="85" data-url="<?php echo SC_URL . '/js/share.php?i=2'; ?>"><a href="#"></a></li> |
| 250 | </ul> |
| 251 | |
| 252 | <div id="content"> |
| 253 | |
| 254 | <h3><?php echo $title; ?> <?php if($edit == 1) echo '<span class="button sc_back"><< ' . __( "Back", 'shortcoder' ) . '</span>'; ?> </h3> |
| 255 | |
| 256 | <form method="post" id="sc_form"> |
| 257 | |
| 258 | <div class="sc_section"> |
| 259 | <label for="sc_name" class="sc_fld_title"><?php _e( "Title:", 'shortcoder' ); ?></label> |
| 260 | <span class="sc_name_wrap"><input type="text" name="sc_name" id="sc_name" value="<?php echo isset($sc_name_edit) ? $sc_name_edit : ''; ?>" placeholder="Enter a shortcode name" class="widefat" required="required"/><div id="sc_code"></div></span> |
| 261 | </div> |
| 262 | |
| 263 | |
| 264 | <div class="sc_section"> |
| 265 | <label for="sc_content" class="sc_fld_title"><?php _e( "Content:", 'shortcoder' ); ?></label> |
| 266 | <?php wp_editor( $sc_content, 'sc_content', array( 'wpautop'=> false, 'textarea_rows'=> 8 )); ?> |
| 267 | </div> |
| 268 | |
| 269 | |
| 270 | <div class="sc_section"><p><b>Note:</b> Use <strong style="color:#006600">%%someParameter%%</strong> to insert custom parameters. <a href="http://www.aakashweb.com/docs/shortcoder-doc/" target="_blank">Learn More</a></p></div> |
| 271 | |
| 272 | <div class="sc_section"> |
| 273 | |
| 274 | <table width="100%"><tr> |
| 275 | |
| 276 | <td width="50%" class="sc_settings"><label><input name="sc_disable" type="checkbox" value="1" <?php echo $sc_disable == "1" ? 'checked="checked"' : ""; ?>/> <?php _e( "Temporarily disable this shortcode", 'shortcoder' ); ?></label> |
| 277 | <label><input name="sc_hide_admin" type="checkbox" value="1" <?php echo $sc_hide_admin == "1" ? 'checked="checked"' : ""; ?>/> <?php _e( "Disable this Shortcode to admins", 'shortcoder' ); ?></label></td> |
| 278 | |
| 279 | <td><p align="right"><input type="submit" name="sc_submit" id="sc_submit" class="button-primary" value="<?php echo $button; ?>" /></p></td> |
| 280 | |
| 281 | </tr></table> |
| 282 | |
| 283 | </div> |
| 284 | |
| 285 | <?php wp_nonce_field('shortcoder_create_form'); ?> |
| 286 | <input name="sc_form_main" type="hidden" value="1" /> |
| 287 | </form> |
| 288 | |
| 289 | <h3><?php _e( "Created Shortcodes", 'shortcoder' ); ?> <small>(<?php _e( "Click to edit", 'shortcoder' ); ?>)</small></h3> |
| 290 | <form method="post" id="sc_edit_form"> |
| 291 | <ul id="sc_list" class="clearfix"> |
| 292 | <?php |
| 293 | $sc_options = get_option('shortcoder_data'); |
| 294 | if(is_array($sc_options)){ |
| 295 | foreach($sc_options as $key=>$value){ |
| 296 | echo '<li>' . $key . '</li>'; |
| 297 | } |
| 298 | } |
| 299 | ?> |
| 300 | </ul> |
| 301 | |
| 302 | <?php wp_nonce_field('shortcoder_edit_form'); ?> |
| 303 | <input name="sc_form_edit" type="hidden" value="1" /> |
| 304 | <input name="sc_form_action" id="sc_form_action" type="hidden" value="edit" /> |
| 305 | <input name="sc_name_edit" id="sc_name_edit" type="hidden" /> |
| 306 | </form> |
| 307 | |
| 308 | <div id="sc_delete" title="Drag & drop shortcodes to delete"></div> |
| 309 | |
| 310 | </div><!-- Content --> |
| 311 | |
| 312 | <br/> |
| 313 | <p align="center"> |
| 314 | <a href="http://www.aakashweb.com/forum/" target="_blank">Report bugs</a> | <a href="http://www.aakashweb.com/forum/" target="_blank">Support Forum</a> | <a href="http://www.aakashweb.com/wordpress-plugins/shortcoder/" target="_blank">Help</a> | <a href="http://bit.ly/scdonate" target="_blank">Donate</a><br/><br/> |
| 315 | <a href="#" class="sc_open_video">(Demo video)</a><br /><br /> |
| 316 | <a href="https://twitter.com/vaakash" target="_blank">Follow @vaakash</a><br/><br/> |
| 317 | <a href="http://www.aakashweb.com/" target="_blank" class="sc_credits">a plugin from Aakash Web</a> |
| 318 | </p> |
| 319 | |
| 320 | <script> |
| 321 | var sc_version = '<?php echo SC_VERSION; ?>'; |
| 322 | </script> |
| 323 | |
| 324 | </div><!-- Wrap --> |
| 325 | |
| 326 | <?php |
| 327 | } |
| 328 | |
| 329 | |
| 330 | |
| 331 | // Helper for SC TinyMCE button |
| 332 | function sc_admin_footer(){ |
| 333 | |
| 334 | if (isset($_GET['page']) && $_GET['page'] == 'shortcoder') |
| 335 | return; |
| 336 | |
| 337 | echo " |
| 338 | <script> |
| 339 | window.onload = function(){ |
| 340 | if( typeof QTags === 'function' ) |
| 341 | QTags.addButton( 'QT_sc_insert', 'Shortcoder', sc_show_insert ); |
| 342 | } |
| 343 | function sc_show_insert(){ |
| 344 | tb_show('Insert a Shortcode', '" . SC_URL . "/sc-insert.php?TB_iframe=true'); |
| 345 | } |
| 346 | </script> |
| 347 | "; |
| 348 | } |
| 349 | add_action('admin_footer', 'sc_admin_footer'); |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | function sc_admin_buttons($type){ |
| 355 | switch($type){ |
| 356 | case 'fbrec': |
| 357 | echo '<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffacebook.com%2Faakashweb&send=false&layout=button_count&width=130&show_faces=false&action=recommend&colorscheme=light&font=arial&height=21&appId=106994469342299" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width: 130px; height:21px;float: right;margin-top: 15px;" allowtransparency="true"></iframe>'; |
| 358 | break; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | // Action Links |
| 366 | function sc_plugin_actions($links, $file){ |
| 367 | static $this_plugin; |
| 368 | global $sc_donate_link; |
| 369 | |
| 370 | if(!$this_plugin) $this_plugin = plugin_basename(__FILE__); |
| 371 | if( $file == $this_plugin ){ |
| 372 | $settings_link = "<a href='$sc_donate_link' title='If you like this plugin, then just make a small Donation to continue this plugin development.' target='_blank'>" . __('Make Donations', 'shortcoder') . '</a> '; |
| 373 | $links = array_merge(array($settings_link), $links); |
| 374 | } |
| 375 | return $links; |
| 376 | } |
| 377 | add_filter('plugin_action_links', 'sc_plugin_actions', 10, 2); |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | // Shortcoder tinyMCE buttons |
| 383 | function sc_addbuttons() { |
| 384 | if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) |
| 385 | return; |
| 386 | |
| 387 | if (isset($_GET['page']) && $_GET['page'] == 'shortcoder') |
| 388 | return; |
| 389 | |
| 390 | if ( get_user_option('rich_editing') == 'true') { |
| 391 | add_filter("mce_external_plugins", "sc_add_tinymce_plugin"); |
| 392 | add_filter('mce_buttons', 'sc_register_button'); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | function sc_register_button($buttons) { |
| 397 | array_push($buttons, "separator", "scbutton"); |
| 398 | return $buttons; |
| 399 | } |
| 400 | |
| 401 | function sc_add_tinymce_plugin($plugin_array) { |
| 402 | $plugin_array['scbutton'] = SC_URL . '/js/tinymce/editor_plugin.js'; |
| 403 | return $plugin_array; |
| 404 | } |
| 405 | add_action('init', 'sc_addbuttons'); // init process for button control |
| 406 | |
| 407 | ?> |