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