PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 3.3
Shortcoder — Create Shortcodes for Anything v3.3
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
345 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.3
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.3');
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']) && is_array($sc_options) ){
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 $edit = 0;
172 $sc_content = '';
173 $sc_disable = 0;
174 $sc_hide_admin = 0;
175
176 // Insert shortcode
177 if (isset($_POST["sc_form_main"]) && $_POST["sc_form_main"] == '1' && check_admin_referer('shortcoder_create_form')){
178 $sc_options = get_option('shortcoder_data');
179 $sc_name = stripslashes($_POST['sc_name']);
180
181 $sc_options[$sc_name] = array(
182 'content' => stripslashes($_POST['sc_content']),
183 'disabled' => intval($_POST['sc_disable']),
184 'hide_admin' => intval($_POST['sc_hide_admin'])
185 );
186
187 // Updating the DB
188 update_option("shortcoder_data", $sc_options);
189 $sc_updated = true;
190
191 // Insert Message
192 if($sc_updated == 'true'){
193 echo '<div class="message updated fade"><p>' . __('Shortcode updated successfully !', 'sc') . '</p></div>';
194 }else{
195 echo '<div class="message error fade"><p>' . __('Unable to create shortcode !', 'sc') . '</p></div>';
196 }
197 }
198
199 // Edit shortcode
200 if (isset($_POST["sc_form_edit"]) && $_POST["sc_form_edit"] == '1' && check_admin_referer('shortcoder_edit_form')){
201 $sc_options = get_option('shortcoder_data');
202 $sc_name_edit = stripslashes($_POST['sc_name_edit']);
203
204 if($_POST["sc_form_action"] == "edit"){
205 $sc_content = htmlspecialchars(stripslashes($sc_options[$sc_name_edit]['content']));
206 $sc_disable = $sc_options[$sc_name_edit]['disabled'];
207 $sc_hide_admin = $sc_options[$sc_name_edit]['hide_admin'];
208
209 $title = "Edit this Shortcode - " . '<small>' . $sc_name_edit . '</small>';
210 $button = "Update Shortcode";
211 $edit = 1;
212 }else{
213 unset($sc_options[$sc_name_edit]);
214 unset($sc_name_edit);
215 update_option("shortcoder_data", $sc_options);
216 echo '<div class="message updated fade"><p>' . __('Shortcode deleted successfully !', 'sc') . '</p></div>';
217 }
218 }
219
220
221 ?>
222
223 <!-- Shortcoder Admin page -->
224
225 <div class="wrap">
226 <?php sc_admin_buttons('fbrec'); ?>
227 <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>
228
229 <ul class="sc_share_wrap">
230 <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>
231 <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>
232 </ul>
233
234 <div id="content">
235 <h3><?php echo $title; ?></h3>
236 <?php if($edit == 1) echo '<span class="sc_back">&lt;&lt; Back</span>'; ?>
237
238 <form method="post" id="sc_form">
239 <label>Name: <input type="text" name="sc_name" id="sc_name" value="<?php echo isset($sc_name_edit) ? $sc_name_edit : ''; ?>" placeholder="Enter a shortcode name"/></label>
240 <div id="sc_code"></div>
241 <label for="sc_content">Content:</label>
242 <ul class="sc_switch_editor"><li class="sc_editor_html">HTML</li><li class="sc_editor_visual">Visual</li></ul>
243
244 <div id="sc_editor">
245 <textarea name="sc_content" id="sc_content" placeholder="Enter the shortcode content here. " rows="6"><?php echo $sc_content; ?></textarea>
246 <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>
247 </div>
248
249 <div id="sc_settings">
250 <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 />
251 <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>
252 <input id="sc_submit" type="submit" name="sc_submit" value="<?php echo $button; ?>" />
253 </div>
254
255 <?php wp_nonce_field('shortcoder_create_form'); ?>
256 <input name="sc_form_main" type="hidden" value="1" />
257 </form>
258
259 <h3>Created shortcodes <small>(Click to edit)</small></h3>
260 <form method="post" id="sc_edit_form">
261 <ul id="sc_list" class="clearfix">
262 <?php
263 $sc_options = get_option('shortcoder_data');
264 if(is_array($sc_options)){
265 foreach($sc_options as $key=>$value){
266 echo '<li>' . $key . '</li>';
267 }
268 }
269 ?>
270 </ul>
271
272 <?php wp_nonce_field('shortcoder_edit_form'); ?>
273 <input name="sc_form_edit" type="hidden" value="1" />
274 <input name="sc_form_action" id="sc_form_action" type="hidden" value="edit" />
275 <input name="sc_name_edit" id="sc_name_edit" type="hidden" />
276 </form>
277
278 <div id="sc_delete" title="Drag & drop shortcodes to delete"></div>
279 </div><!-- Content -->
280
281 <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/>
282 <a href="#" class="sc_open_video">(Demo video)</a><br /><br />
283 <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/>
284 <a href="http://www.aakashweb.com/" target="_blank" class="sc_credits">a Aakash Web plugin</a></p>
285 <span class="sc_hidden_text"><?php echo SC_URL.'js/nicedit/nicEditorIcons.gif'; ?></span>
286
287 </div><!-- Wrap -->
288
289 <?php
290 }
291
292 function sc_admin_footer(){
293 if(in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php'))){
294 echo '<span id="sc_editorUrl" style="display:none;">' . SC_URL . 'sc-editor.php</span>';
295 }
296 }
297 add_action('admin_footer', 'sc_admin_footer');
298
299 function sc_admin_buttons($type){
300 switch($type){
301 case 'fbrec':
302 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>';
303 break;
304 }
305 }
306
307 // Action Links
308 function sc_plugin_actions($links, $file){
309 static $this_plugin;
310 global $sc_donate_link;
311
312 if(!$this_plugin) $this_plugin = plugin_basename(__FILE__);
313 if( $file == $this_plugin ){
314 $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> ';
315 $links = array_merge(array($settings_link), $links);
316 }
317 return $links;
318 }
319 add_filter('plugin_action_links', 'sc_plugin_actions', 10, 2);
320
321 // Shortcoder tinyMCE buttons
322 function sc_addbuttons() {
323 if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
324 return;
325
326 if ( get_user_option('rich_editing') == 'true') {
327 add_filter("mce_external_plugins", "sc_add_tinymce_plugin");
328 add_filter('mce_buttons', 'sc_register_button');
329 }
330 }
331
332 function sc_register_button($buttons) {
333 array_push($buttons, "|", "scbutton");
334 return $buttons;
335 }
336
337 function sc_add_tinymce_plugin($plugin_array) {
338 $plugin_array['scbutton'] = SC_URL . 'js/tinymce/editor_plugin.js';
339 return $plugin_array;
340 }
341
342 // init process for button control
343 add_action('init', 'sc_addbuttons');
344
345 ?>