PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 3.1
Shortcoder — Create Shortcodes for Anything v3.1
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 13 years ago js 13 years ago languages 13 years ago readme.txt 13 years ago sc-admin-css.css 13 years ago sc-admin-js.js 13 years ago sc-editor.php 13 years ago screenshot-1.png 13 years ago screenshot-2.png 13 years ago screenshot-3.png 13 years ago screenshot-4.png 13 years ago shortcoder.php 13 years ago
shortcoder.php
339 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. <a href="http://www.youtube.com/watch?v=GrlRADfvjII" title="Shortcoder demo video" target="_blank">Check out the demo video</a>.
6 Author: Aakash Chakravarthy
7 Version: 3.1
8 Author URI: http://www.aakashweb.com/
9 License: GPLv2 or later
10 */
11
12 if(!defined('WP_CONTENT_URL')) {
13 $sc_url = get_option('siteurl') . '/wp-content/plugins/' . plugin_basename(dirname(__FILE__)).'/';
14 }else{
15 $sc_url = WP_CONTENT_URL . '/plugins/' . plugin_basename(dirname(__FILE__)) . '/';
16 }
17
18 define('SC_VERSION', '3.1');
19 define('SC_AUTHOR', 'Aakash Chakravarthy');
20 define('SC_URL', $sc_url);
21
22 $sc_donate_link = 'http://bit.ly/scdonate';
23
24 // Load languages
25 load_plugin_textdomain('sc', false, basename(dirname(__FILE__)) . '/languages/');
26
27 // Add admin menu
28 function sc_add_menu() {
29 add_menu_page('Shortcoder','Shortcoder','manage_options','shortcoder', 'sc_admin_page', SC_URL . 'images/shortcoder-2.png');
30 }
31
32 add_action('admin_menu','sc_add_menu');
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');
45 wp_enqueue_script('shortcoder-nicedit-js', SC_URL . 'js/nicedit/nicEdit.js');
46 }
47 }
48 add_action('admin_print_scripts', 'sc_admin_js');
49
50 // Load the CSS
51 function sc_admin_css(){
52 if (isset($_GET['page']) && $_GET['page'] == 'shortcoder') {
53 wp_enqueue_style('shortcoder-admin-css', SC_URL . 'sc-admin-css.css');
54 }
55 }
56 add_action('admin_print_styles', 'sc_admin_css');
57
58 // Register the shortcode
59 add_shortcode('sc', 'shortcoder');
60
61 function shortcoder_all_ok($name){
62
63 $sc_options = get_option('shortcoder_data');
64
65 if($sc_options[$name]['disabled'] == 0){
66 if(current_user_can('level_10') && $sc_options[$name]['hide_admin'] == 1){
67 return false;
68 }else{
69 return true;
70 }
71 }else{
72 return false;
73 }
74 }
75
76 // Main function
77 function shortcoder($atts, $content) {
78
79 $sc_options = get_option('shortcoder_data');
80
81 // Get the Shortcode name
82 if(isset($atts[0])){
83 $sc_name = str_replace(array('"', "'", ":"), '', $atts[0]);
84 unset($atts[0]);
85 }else{
86 // Old version with "name" param support
87 if(array_key_exists("name", $atts)){
88 $tVal = $atts['name'];
89 if(array_key_exists($tVal, $sc_options)){
90 $sc_name = $tVal;
91 unset($atts['name']);
92 }
93 }
94 }
95
96 if(!isset($sc_name)){
97 return '';
98 }
99
100 // Check whether shortcoder can execute
101 if(shortcoder_all_ok($sc_name)){
102
103 // If SC has parameters, then replace it
104 if(!empty($atts)){
105 $keys = array();
106 $values = array();
107 $i = 0;
108
109 // Seperate Key and value from atts
110 foreach($atts as $k=>$v){
111 if($k !== 0){
112 $keys[$i] = "%%" . $k . "%%";
113 $values[$i] = $v;
114 }
115 $i++;
116 }
117
118 // Replace the params
119 $sc_content = $sc_options[$sc_name]['content'];
120 $sc_content_rep1 = str_replace($keys, $values, $sc_content);
121 $sc_content_rep2 = preg_replace('/%%[^%\s]+%%/', '', $sc_content_rep1);
122 return "<!-- Start Shortcoder content -->" . $sc_content_rep2 . "<!-- End Shortcoder content -->";
123 }
124 else{
125
126 // If the SC has no params, then replace the %vars%
127 $sc_content = $sc_options[$sc_name]['content'];
128 $sc_content_rep = preg_replace('/%%[^%\s]+%%/', '', $sc_content);
129 return "<!-- Start Shortcoder content -->" . $sc_content_rep . "<!-- End Shortcoder content -->";
130 }
131
132 }else{
133 return '';
134 }
135 }
136
137 // Plugin on activate fixes
138 function sc_onactivate(){
139 $sc_options = get_option('shortcoder_data');
140 $sc_flags = get_option('shortcoder_flags');
141
142 // Move the flag version fix to sc_flags option
143 if(isset($sc_options['_version_fix'])){
144 unset($sc_options['_version_fix']);
145 update_option('shortcoder_data', $sc_options);
146 }
147
148 // Double percentage fix and flag
149 if(!isset($sc_flags['double_percent'])){
150 foreach($sc_options as $key => $val){
151 $temp = str_replace('%', '%%', $sc_options[$key]['content']);
152 $sc_options[$key]['content'] = $temp;
153 }
154
155 update_option('shortcoder_data', $sc_options);
156 $sc_flags['double_percent'] = 1;
157 update_option('shortcoder_flags', $sc_flags);
158 }
159 }
160 register_activation_hook(__FILE__, 'sc_onactivate');
161
162 // Shortcoder admin page
163 function sc_admin_page(){
164
165 $sc_updated = false;
166 $sc_options = get_option('shortcoder_data');
167 $sc_flags = get_option('shortcoder_flags');
168
169 $title = "Create a Shortcode";
170 $button = "Create Shortcode";
171 $sc_content = '';
172 $sc_disable = 0;
173 $sc_hide_admin = 0;
174
175 // Insert shortcode
176 if (isset($_POST["sc_form_main"]) && $_POST["sc_form_main"] == '1' && check_admin_referer('shortcoder_create_form')){
177 $sc_options = get_option('shortcoder_data');
178 $sc_name = stripslashes($_POST['sc_name']);
179
180 $sc_options[$sc_name] = array(
181 'content' => stripslashes($_POST['sc_content']),
182 'disabled' => intval($_POST['sc_disable']),
183 'hide_admin' => intval($_POST['sc_hide_admin'])
184 );
185
186 // Updating the DB
187 update_option("shortcoder_data", $sc_options);
188 $sc_updated = true;
189
190 // Insert Message
191 if($sc_updated == 'true'){
192 echo '<div class="message updated fade"><p>' . __('Shortcode updated successfully !', 'sc') . '</p></div>';
193 }else{
194 echo '<div class="message error fade"><p>' . __('Unable to create shortcode !', 'sc') . '</p></div>';
195 }
196 }
197
198 // Edit shortcode
199 if (isset($_POST["sc_form_edit"]) && $_POST["sc_form_edit"] == '1' && check_admin_referer('shortcoder_edit_form')){
200 $sc_options = get_option('shortcoder_data');
201 $sc_name_edit = stripslashes($_POST['sc_name_edit']);
202
203 if($_POST["sc_form_action"] == "edit"){
204 $sc_content = stripslashes($sc_options[$sc_name_edit]['content']);
205 $sc_disable = $sc_options[$sc_name_edit]['disabled'];
206 $sc_hide_admin = $sc_options[$sc_name_edit]['hide_admin'];
207
208 $title = "Edit this Shortcode - " . '<small>' . $sc_name_edit . '</small>';
209 $button = "Update Shortcode";
210 $edit = 1;
211 }else{
212 unset($sc_options[$sc_name_edit]);
213 unset($sc_name_edit);
214 update_option("shortcoder_data", $sc_options);
215 echo '<div class="message updated fade"><p>' . __('Shortcode deleted successfully !', 'sc') . '</p></div>';
216 }
217 }
218
219
220 ?>
221
222 <!-- Shortcoder Admin page -->
223
224 <div class="wrap">
225 <?php sc_admin_buttons('fbrec'); ?>
226 <h2><img width="32" height="32" src="<?php echo SC_URL; ?>images/shortcoder.png" align="absmiddle"/> Shortcoder<span class="smallText"> v<?php echo SC_VERSION; ?></span></h2>
227
228 <ul class="sc_share_wrap">
229 <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>
230 <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>
231 </ul>
232
233 <div id="content">
234 <h3><?php echo $title; ?></h3>
235 <?php if($edit == 1) echo '<span class="sc_back">&lt;&lt; Back</span>'; ?>
236
237 <form method="post" id="sc_form">
238 <label>Name: <input type="text" name="sc_name" id="sc_name" value="<?php echo $sc_name_edit; ?>" placeholder="Enter a shortcode name"/></label>
239 <div id="sc_code"></div>
240 <label for="sc_content">Content:</label>
241 <ul class="sc_switch_editor"><li class="sc_editor_html">HTML</li><li class="sc_editor_visual">Visual</li></ul>
242 <div id="sc_editor"><textarea name="sc_content" id="sc_content" placeholder="Enter the shortcode content here. " rows="6"><?php echo $sc_content; ?></textarea></div>
243
244 <div id="sc_settings">
245 <label class="smallText"><input name="sc_disable" id="sc_disable" type="checkbox" value="1" <?php echo $sc_disable == "1" ? 'checked="checked"' : ""; ?>/> Temporarily disable this shortcode</label><br />
246 <label class="smallText"><input name="sc_hide_admin" id="sc_hide_admin" type="checkbox" value="1" <?php echo $sc_hide_admin == "1" ? 'checked="checked"' : ""; ?>/> Disable this Shortcode to admins</label>
247 <input id="sc_submit" type="submit" name="sc_submit" value="<?php echo $button; ?>" />
248 </div>
249
250 <?php wp_nonce_field('shortcoder_create_form'); ?>
251 <input name="sc_form_main" type="hidden" value="1" />
252 <small class="grey">Note: Use <strong style="color:#006600">%%someParameter%%</strong> to insert custom parameters. <a href="http://www.aakashweb.com/faqs/wordpress-plugins/shortcoder/using-attributes/" target="_blank">Learn More</a>. Custom parameter format is now changed as in previous line (<a href="http://www.aakashweb.com/forum/shortcoder-f8/change-parameter-symbol-t1532.html" target="_blank">Issue: 2526</a>)</small>
253 </form>
254
255 <h3>Created shortcodes <small>(Click to edit)</small></h3>
256 <form method="post" id="sc_edit_form">
257 <ul id="sc_list" class="clearfix">
258 <?php
259 $sc_options = get_option('shortcoder_data');
260 foreach($sc_options as $key=>$value){
261 echo '<li>' . $key . '</li>';
262 }
263 ?>
264 </ul>
265
266 <?php wp_nonce_field('shortcoder_edit_form'); ?>
267 <input name="sc_form_edit" type="hidden" value="1" />
268 <input name="sc_form_action" id="sc_form_action" type="hidden" value="edit" />
269 <input name="sc_name_edit" id="sc_name_edit" type="hidden" />
270 </form>
271
272 <div id="sc_delete" title="Drag & drop shortcodes to delete"></div>
273 </div><!-- Content -->
274
275 <p align="center"><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">Documentation</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/>
276 <a href="#" class="sc_open_video">(Demo video)</a><br /><br />
277 <a href="https://twitter.com/vaakash" target="_blank" class="twitter-follow-button" data-show-count="false" data-width="130px" data-align="center">Follow @vaakash</a><br/><br/>
278 <a href="http://www.aakashweb.com/" target="_blank" class="sc_credits">a Aakash Web plugin</a></p>
279 <span class="sc_hidden_text"><?php echo SC_URL.'js/nicedit/nicEditorIcons.gif'; ?></span>
280
281 </div><!-- Wrap -->
282
283 <?php
284 }
285
286 function sc_admin_footer(){
287 if(in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php'))){
288 echo '<span id="sc_editorUrl" style="display:none;">' . SC_URL . 'sc-editor.php</span>';
289 }
290 }
291 add_action('admin_footer', 'sc_admin_footer');
292
293 function sc_admin_buttons($type){
294 switch($type){
295 case 'fbrec':
296 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=450&amp;show_faces=true&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: 126px; height:21px;float: right;margin-top: 15px;" allowtransparency="true"></iframe>';
297 break;
298 }
299 }
300
301 // Action Links
302 function sc_plugin_actions($links, $file){
303 static $this_plugin;
304 global $sc_donate_link;
305
306 if(!$this_plugin) $this_plugin = plugin_basename(__FILE__);
307 if( $file == $this_plugin ){
308 $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', 'hja') . '</a> ';
309 $links = array_merge(array($settings_link), $links);
310 }
311 return $links;
312 }
313 add_filter('plugin_action_links', 'sc_plugin_actions', 10, 2);
314
315 // Shortcoder tinyMCE buttons
316 function sc_addbuttons() {
317 if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
318 return;
319
320 if ( get_user_option('rich_editing') == 'true') {
321 add_filter("mce_external_plugins", "sc_add_tinymce_plugin");
322 add_filter('mce_buttons', 'sc_register_button');
323 }
324 }
325
326 function sc_register_button($buttons) {
327 array_push($buttons, "|", "scbutton");
328 return $buttons;
329 }
330
331 function sc_add_tinymce_plugin($plugin_array) {
332 $plugin_array['scbutton'] = SC_URL . 'js/tinymce/editor_plugin.js';
333 return $plugin_array;
334 }
335
336 // init process for button control
337 add_action('init', 'sc_addbuttons');
338
339 ?>