PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 3.2
Shortcoder — Create Shortcodes for Anything v3.2
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
342 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>. Administration page is <a href="options-general.php?page=shortcoder">moved here</a>.
6 Author: Aakash Chakravarthy
7 Version: 3.2
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.2');
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_options_page( 'Shortcoder', 'Shortcoder', 'manage_options', 'shortcoder', 'sc_admin_page' );
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?v=' . SC_VERSION);
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?v=' . SC_VERSION);
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 = htmlspecialchars(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
243 <div id="sc_editor">
244 <textarea name="sc_content" id="sc_content" placeholder="Enter the shortcode content here. " rows="6"><?php echo $sc_content; ?></textarea>
245 <div class="grey sc_edit_note">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>.</div>
246 </div>
247
248 <div id="sc_settings">
249 <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 />
250 <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>
251 <input id="sc_submit" type="submit" name="sc_submit" value="<?php echo $button; ?>" />
252 </div>
253
254 <?php wp_nonce_field('shortcoder_create_form'); ?>
255 <input name="sc_form_main" type="hidden" value="1" />
256 </form>
257
258 <h3>Created shortcodes <small>(Click to edit)</small></h3>
259 <form method="post" id="sc_edit_form">
260 <ul id="sc_list" class="clearfix">
261 <?php
262 $sc_options = get_option('shortcoder_data');
263 foreach($sc_options as $key=>$value){
264 echo '<li>' . $key . '</li>';
265 }
266 ?>
267 </ul>
268
269 <?php wp_nonce_field('shortcoder_edit_form'); ?>
270 <input name="sc_form_edit" type="hidden" value="1" />
271 <input name="sc_form_action" id="sc_form_action" type="hidden" value="edit" />
272 <input name="sc_name_edit" id="sc_name_edit" type="hidden" />
273 </form>
274
275 <div id="sc_delete" title="Drag & drop shortcodes to delete"></div>
276 </div><!-- Content -->
277
278 <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/>
279 <a href="#" class="sc_open_video">(Demo video)</a><br /><br />
280 <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/>
281 <a href="http://www.aakashweb.com/" target="_blank" class="sc_credits">a Aakash Web plugin</a></p>
282 <span class="sc_hidden_text"><?php echo SC_URL.'js/nicedit/nicEditorIcons.gif'; ?></span>
283
284 </div><!-- Wrap -->
285
286 <?php
287 }
288
289 function sc_admin_footer(){
290 if(in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php'))){
291 echo '<span id="sc_editorUrl" style="display:none;">' . SC_URL . 'sc-editor.php</span>';
292 }
293 }
294 add_action('admin_footer', 'sc_admin_footer');
295
296 function sc_admin_buttons($type){
297 switch($type){
298 case 'fbrec':
299 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>';
300 break;
301 }
302 }
303
304 // Action Links
305 function sc_plugin_actions($links, $file){
306 static $this_plugin;
307 global $sc_donate_link;
308
309 if(!$this_plugin) $this_plugin = plugin_basename(__FILE__);
310 if( $file == $this_plugin ){
311 $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> ';
312 $links = array_merge(array($settings_link), $links);
313 }
314 return $links;
315 }
316 add_filter('plugin_action_links', 'sc_plugin_actions', 10, 2);
317
318 // Shortcoder tinyMCE buttons
319 function sc_addbuttons() {
320 if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
321 return;
322
323 if ( get_user_option('rich_editing') == 'true') {
324 add_filter("mce_external_plugins", "sc_add_tinymce_plugin");
325 add_filter('mce_buttons', 'sc_register_button');
326 }
327 }
328
329 function sc_register_button($buttons) {
330 array_push($buttons, "|", "scbutton");
331 return $buttons;
332 }
333
334 function sc_add_tinymce_plugin($plugin_array) {
335 $plugin_array['scbutton'] = SC_URL . 'js/tinymce/editor_plugin.js';
336 return $plugin_array;
337 }
338
339 // init process for button control
340 add_action('init', 'sc_addbuttons');
341
342 ?>