PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 3.4
Shortcoder — Create Shortcodes for Anything v3.4
trunk 3.0 3.0.1 3.1 3.2 3.3 3.4 3.4.1 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.3 4.4 4.5 4.6 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.1 5.2 5.2.1 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.4 5.5 5.6 5.7 5.8 6.0 6.1 6.2 6.3 6.3.1 6.3.2 6.4 6.5 6.5.1 6.5.2 6.5.3
shortcoder / shortcoder.php
shortcoder Last commit date
images 12 years ago js 12 years ago languages 12 years ago readme.txt 12 years ago sc-admin-css.css 12 years ago sc-admin-js.js 12 years ago sc-insert.php 12 years ago screenshot-1.png 12 years ago screenshot-2.png 12 years ago screenshot-3.png 12 years ago screenshot-4.png 12 years ago shortcoder.php 12 years ago
shortcoder.php
393 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
8 Author URI: http://www.aakashweb.com/
9 */
10
11 define('SC_VERSION', '3.4');
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
166 // Shortcoder admin page
167 function sc_admin_page(){
168
169 $sc_updated = false;
170 $sc_options = get_option('shortcoder_data');
171 $sc_flags = get_option('shortcoder_flags');
172
173 $title = __( "Create a Shortcode", 'shortcoder' );
174 $button = __( "Create Shortcode", 'shortcoder' );
175 $edit = 0;
176 $sc_content = '';
177 $sc_disable = 0;
178 $sc_hide_admin = 0;
179
180 // Insert shortcode
181 if (isset($_POST["sc_form_main"]) && $_POST["sc_form_main"] == '1' && check_admin_referer('shortcoder_create_form')){
182 $sc_options = get_option('shortcoder_data');
183 $sc_name = stripslashes($_POST['sc_name']);
184
185 $sc_post_disabled = isset( $_POST['sc_disable'] ) ? intval( $_POST['sc_disable'] ) : 0;
186 $sc_post_hideadmin = isset( $_POST['sc_hide_admin'] ) ? intval( $_POST['sc_hide_admin'] ) : 0;
187
188 $sc_options[$sc_name] = array(
189 'content' => stripslashes($_POST['sc_content']),
190 'disabled' => $sc_post_disabled,
191 'hide_admin' => $sc_post_hideadmin
192 );
193
194 // Updating the DB
195 update_option("shortcoder_data", $sc_options);
196 $sc_updated = true;
197
198 // Insert Message
199 if($sc_updated == 'true'){
200 echo '<div class="message updated fade"><p>' . __('Shortcode updated successfully !', 'shortcoder') . '</p></div>';
201 }else{
202 echo '<div class="message error fade"><p>' . __('Unable to create shortcode !', 'shortcoder') . '</p></div>';
203 }
204 }
205
206 // Edit shortcode
207 if (isset($_POST["sc_form_edit"]) && $_POST["sc_form_edit"] == '1' && check_admin_referer('shortcoder_edit_form')){
208 $sc_options = get_option('shortcoder_data');
209 $sc_name_edit = stripslashes($_POST['sc_name_edit']);
210
211 if($_POST["sc_form_action"] == "edit"){
212 $sc_content = stripslashes($sc_options[$sc_name_edit]['content']);
213 $sc_disable = $sc_options[$sc_name_edit]['disabled'];
214 $sc_hide_admin = $sc_options[$sc_name_edit]['hide_admin'];
215
216 $title = __( 'Edit this Shortcode - ', 'shortcoder' ) . '<small>' . $sc_name_edit . '</small>';
217 $button = __( 'Update Shortcode', 'shortcoder' );
218 $edit = 1;
219 }else{
220 unset($sc_options[$sc_name_edit]);
221 unset($sc_name_edit);
222 update_option("shortcoder_data", $sc_options);
223 echo '<div class="message updated fade"><p>' . __('Shortcode deleted successfully !', 'shortcoder') . '</p></div>';
224 }
225 }
226
227
228 ?>
229
230 <!-- Shortcoder Admin page -->
231
232 <div class="wrap">
233 <?php sc_admin_buttons('fbrec'); ?>
234 <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>
235
236 <ul class="sc_share_wrap">
237 <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>
238 <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>
239 </ul>
240
241 <div id="content">
242
243 <h3><?php echo $title; ?> <?php if($edit == 1) echo '<span class="button sc_back">&lt;&lt; ' . __( "Back", 'shortcoder' ) . '</span>'; ?> </h3>
244
245 <form method="post" id="sc_form">
246
247 <div class="sc_section">
248 <label for="sc_name" class="sc_fld_title"><?php _e( "Title:", 'shortcoder' ); ?>:</label>
249 <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>
250 </div>
251
252
253 <div class="sc_section">
254 <label for="sc_content" class="sc_fld_title"><?php _e( "Content:", 'shortcoder' ); ?>:</label>
255 <?php wp_editor( $sc_content, 'sc_content', array( 'wpautop'=> false, 'textarea_rows'=> 8 )); ?>
256 </div>
257
258
259 <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>
260
261 <div class="sc_section">
262
263 <table width="100%"><tr>
264
265 <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>
266 <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>
267
268 <td><p align="right"><input type="submit" name="sc_submit" id="sc_submit" class="button-primary" value="<?php echo $button; ?>" /></p></td>
269
270 </tr></table>
271
272 </div>
273
274 <?php wp_nonce_field('shortcoder_create_form'); ?>
275 <input name="sc_form_main" type="hidden" value="1" />
276 </form>
277
278 <h3><?php _e( "Created Shortcodes", 'shortcoder' ); ?> <small>(<?php _e( "Click to edit", 'shortcoder' ); ?>)</small></h3>
279 <form method="post" id="sc_edit_form">
280 <ul id="sc_list" class="clearfix">
281 <?php
282 $sc_options = get_option('shortcoder_data');
283 if(is_array($sc_options)){
284 foreach($sc_options as $key=>$value){
285 echo '<li>' . $key . '</li>';
286 }
287 }
288 ?>
289 </ul>
290
291 <?php wp_nonce_field('shortcoder_edit_form'); ?>
292 <input name="sc_form_edit" type="hidden" value="1" />
293 <input name="sc_form_action" id="sc_form_action" type="hidden" value="edit" />
294 <input name="sc_name_edit" id="sc_name_edit" type="hidden" />
295 </form>
296
297 <div id="sc_delete" title="Drag & drop shortcodes to delete"></div>
298
299 </div><!-- Content -->
300
301 <br/>
302 <p align="center">
303 <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/>
304 <a href="#" class="sc_open_video">(Demo video)</a><br /><br />
305 <a href="https://twitter.com/vaakash" target="_blank">Follow @vaakash</a><br/><br/>
306 <a href="http://www.aakashweb.com/" target="_blank" class="sc_credits">a plugin from Aakash Web</a>
307 </p>
308
309
310 </div><!-- Wrap -->
311
312 <?php
313 }
314
315
316
317 // Helper for SC TinyMCE button
318 function sc_admin_footer(){
319
320 if (isset($_GET['page']) && $_GET['page'] == 'shortcoder')
321 return;
322
323 echo "
324 <script>
325 window.onload = function(){
326 if( typeof QTags === 'function' )
327 QTags.addButton( 'QT_sc_insert', 'Shortcoder', sc_show_insert );
328 }
329 function sc_show_insert(){
330 tb_show('Insert a Shortcode', '" . SC_URL . "/sc-insert.php?TB_iframe=true');
331 }
332 </script>
333 ";
334 }
335 add_action('admin_footer', 'sc_admin_footer');
336
337
338
339
340 function sc_admin_buttons($type){
341 switch($type){
342 case 'fbrec':
343 echo '<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffacebook.com%2Faakashweb&amp;send=false&amp;layout=button_count&amp;width=130&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21&amp;appId=106994469342299" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width: 130px; height:21px;float: right;margin-top: 15px;" allowtransparency="true"></iframe>';
344 break;
345 }
346 }
347
348
349
350
351 // Action Links
352 function sc_plugin_actions($links, $file){
353 static $this_plugin;
354 global $sc_donate_link;
355
356 if(!$this_plugin) $this_plugin = plugin_basename(__FILE__);
357 if( $file == $this_plugin ){
358 $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> ';
359 $links = array_merge(array($settings_link), $links);
360 }
361 return $links;
362 }
363 add_filter('plugin_action_links', 'sc_plugin_actions', 10, 2);
364
365
366
367
368 // Shortcoder tinyMCE buttons
369 function sc_addbuttons() {
370 if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') )
371 return;
372
373 if (isset($_GET['page']) && $_GET['page'] == 'shortcoder')
374 return;
375
376 if ( get_user_option('rich_editing') == 'true') {
377 add_filter("mce_external_plugins", "sc_add_tinymce_plugin");
378 add_filter('mce_buttons', 'sc_register_button');
379 }
380 }
381
382 function sc_register_button($buttons) {
383 array_push($buttons, "separator", "scbutton");
384 return $buttons;
385 }
386
387 function sc_add_tinymce_plugin($plugin_array) {
388 $plugin_array['scbutton'] = SC_URL . '/js/tinymce/editor_plugin.js';
389 return $plugin_array;
390 }
391 add_action('init', 'sc_addbuttons'); // init process for button control
392
393 ?>