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