Post Snippets - Version 1.7.1

Version Description

Download this release

Release Info

Developer artstorm
Plugin Icon 128x128 Post Snippets
Version 1.7.1
Comparing to
See all releases

Code changes from version 1.7 to 1.7.1

Files changed (3) hide show
  1. assets/post-snippets.css +40 -0
  2. post-snippets.php +75 -101
  3. readme.txt +9 -2
assets/post-snippets.css ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Styling for the jQuery UI dialog used by Post Snippets
3
+ *
4
+ * @since Post Snippets 1.7.1
5
+ */
6
+ #post-snippets-tabs {
7
+ padding: 15px 15px 3px;
8
+ background-color: #f1f1f1;
9
+ border-bottom: 1px solid #dfdfdf;
10
+ }
11
+ #post-snippets-tabs li {
12
+ display: inline;
13
+ }
14
+ #post-snippets-tabs li {
15
+ color: #2583AD;
16
+ padding: 6px 6px 6px 6px;
17
+ border-width: 1px 1px 0;
18
+ border-style: solid solid none;
19
+ border-color: #f1f1f1;
20
+ }
21
+ #post-snippets-tabs li.ui-tabs-selected {
22
+ background-color: #fff;
23
+ border-color: #dfdfdf;
24
+ border-bottom-color: #fff;
25
+ color: #d54e21;
26
+ }
27
+ #post-snippets-tabs li.ui-state-hover {
28
+ color: #d54e21;
29
+ }
30
+ #post-snippets-tabs a {
31
+ text-decoration: none;
32
+ }
33
+ #post-snippets-tabs .ui-tabs-panel {
34
+ margin: 5px 0 0 0;
35
+ padding: 5px 20px 10px;
36
+ background-color: #fff;
37
+ border-left: 1px solid #dfdfdf;
38
+ border-bottom: 1px solid #dfdfdf;
39
+ border: 1px solid #dfdfdf;
40
+ }
post-snippets.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Post Snippets
4
  Plugin URI: http://wpstorm.net/wordpress-plugins/post-snippets/
5
  Description: Stores snippets of HTML code or reoccurring text that you often use in your posts. You can use predefined variables to replace parts of the snippet on insert. All snippets are available in the post editor with a TinyMCE button or Quicktags.
6
- Version: 1.7
7
  Author: Johan Steen
8
  Author URI: http://wpstorm.net/
9
  Text Domain: post-snippets
@@ -70,8 +70,7 @@ class post_snippets {
70
  $this->create_shortcodes();
71
 
72
  # Adds the JS and HTML code in the header and footer for the jQuery insert UI dialog in the editor
73
- add_action( 'admin_init', array(&$this,'enqueue_scripts') );
74
- add_action( 'admin_head', array(&$this,'jquery_ui_dialog_style') );
75
  add_action( 'admin_head', array(&$this,'jquery_ui_dialog') );
76
  add_action( 'admin_footer', array(&$this,'insert_ui_dialog') );
77
 
@@ -103,55 +102,20 @@ class post_snippets {
103
  }
104
 
105
  /**
106
- * Enqueues the necessary scripts for the insert dialogue
107
  *
108
  * @since Post Snippets 1.7
109
  *
110
  * @returns Nothing
111
  */
112
- function enqueue_scripts() {
113
  wp_enqueue_script( 'jquery-ui-dialog' );
114
  wp_enqueue_script( 'jquery-ui-tabs' );
115
- }
116
-
117
 
118
- /**
119
- * CSS Styling for the jQuert Dialog
120
- *
121
- * @since Post Snippets 1.7
122
- *
123
- * @returns Nothing
124
- */
125
- function jquery_ui_dialog_style() {
126
- ?>
127
- <style type="text/css">
128
- #post-snippets-tabs {
129
- padding: 15px 15px 3px;
130
- background-color: #f1f1f1;
131
- border-bottom: 1px solid #dfdfdf;
132
- }
133
- #post-snippets-tabs li {
134
- display: inline;
135
- }
136
- #post-snippets-tabs a.current {
137
- background-color: #fff;
138
- border-color: #dfdfdf;
139
- border-bottom-color: #fff;
140
- color: #d54e21;
141
- }
142
- #post-snippets-tabs a {
143
- color: #2583AD;
144
- padding: 6px;
145
- border-width: 1px 1px 0;
146
- border-style: solid solid none;
147
- border-color: #f1f1f1;
148
- text-decoration: none;
149
- }
150
- #post-snippets-tabs a:hover {
151
- color: #d54e21;
152
- }
153
- </style>
154
- <?php
155
  }
156
 
157
  /**
@@ -280,6 +244,7 @@ function edOpenPostSnippets(myField) {
280
  <div id="post-snippets-tabs">
281
  <ul>
282
  <?php
 
283
  $snippets = get_option($this->plugin_options);
284
  for ($i = 0; $i < count($snippets); $i++) { ?>
285
  <li><a href="#ps-tabs-<?php echo $i; ?>"><?php echo $snippets[$i]['title']; ?></a></li>
@@ -287,34 +252,40 @@ function edOpenPostSnippets(myField) {
287
  </ul>
288
 
289
  <?php
 
290
  for ($i = 0; $i < count($snippets); $i++) { ?>
291
  <div id="ps-tabs-<?php echo $i; ?>">
292
- <h4><?php echo $snippets[$i]['title']; ?></h4>
293
- <!--<p>Snippet Description</p>-->
294
-
295
-
296
- <?php
297
- $var_arr = explode(",",$snippets[$i]['vars']);
298
- if (!empty($var_arr[0])) {
299
- for ($j = 0; $j < count($var_arr); $j++) { ?>
300
- <label for="var_<?php echo $i; ?>_<?php echo $j; ?>"><?php echo($var_arr[$j]);?>:</label>
301
- <input type="text" id="var_<?php echo $i; ?>_<?php echo $j; ?>" name="var_<?php echo $i; ?>_<?php echo $j; ?>" style="width: 190px" />
302
- <br/>
303
-
304
- <?php } } ?>
305
-
306
-
307
- </div>
308
- <?php } ?>
309
- </div>
310
 
311
- </div>
312
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  <?
314
  echo "\n<!-- END: Post Snippets UI Dialog -->\n";
315
  }
316
 
317
-
318
  /**
319
  * Adds a QuickTag button to the HTML editor
320
  *
@@ -354,7 +325,9 @@ function edOpenPostSnippets(myField) {
354
  $snippets = get_option($this->plugin_options);
355
  if (!empty($snippets)) {
356
  for ($i=0; $i < count($snippets); $i++) {
357
- if ($snippets[$i]['shortcode'] == true) {
 
 
358
  $vars = explode(",",$snippets[$i]['vars']);
359
  $vars_str = '';
360
  for ($j=0; $j < count($vars); $j++) {
@@ -516,9 +489,8 @@ JAVASCRIPT;
516
  *
517
  */
518
  function wp_admin() {
519
- if (function_exists('add_options_page')) {
520
- add_options_page( 'Post Snippets Options', 'Post Snippets', 'administrator', __FILE__, array(&$this, 'options_page') );
521
- }
522
  }
523
 
524
  function admin_message($message) {
@@ -529,6 +501,39 @@ JAVASCRIPT;
529
  }
530
  }
531
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
532
  function options_page() {
533
  // Add a new Snippet
534
  if (isset($_POST['add-snippet'])) {
@@ -596,6 +601,7 @@ JAVASCRIPT;
596
  <div class="alignleft actions">
597
  <input type="submit" name="add-snippet" value="<?php _e( 'Add New Snippet', 'post-snippets' ) ?>" class="button-secondary" />
598
  <input type="submit" name="delete-selected" value="<?php _e( 'Delete Selected', 'post-snippets' ) ?>" class="button-secondary" />
 
599
  </div>
600
  </div>
601
  <div class="clear"></div>
@@ -645,38 +651,6 @@ JAVASCRIPT;
645
  <div class="submit">
646
  <input type="submit" name="update-post-snippets" value="<?php _e( 'Update Snippets', 'post-snippets' ) ?>" class="button-primary" /></div>
647
  </form>
648
-
649
- <div id="poststuff" class="ui-sortable">
650
- <div class="postbox">
651
- <h3><?php _e( 'Help', 'post-snippets' ); ?></h3>
652
- <div class="inside">
653
- <p><?php _e( '<strong>Title</strong><br/>Give the snippet a title that helps you identify it in the post editor.', 'post-snippets' ); ?></p>
654
-
655
- <p><?php _e( '<strong>Variables</strong><br/>A comma separated list of custom variables you can reference in your snippet.<br/><br/>Example:<br/>url,name', 'post-snippets' ); ?></p>
656
-
657
- <p><?php _e( '<strong>Snippet</strong><br/>This is the block of text or HTML to insert in the post when you select the snippet from the insert button in the TinyMCE panel in the post editor. If you have entered predefined variables you can reference them from the snippet by enclosing them in {} brackets.<br/><br/>Example:<br/>To reference the variables in the example above, you would enter {url} and {name}.<br/><br/>So if you enter this snippet:<br/><i>This is the website of &lt;a href="{url}"&gt;{name}&lt;/a&gt;</i><br/>You will get the option to replace url and name on insert if they are defined as variables.', 'post-snippets' ); ?></p>
658
-
659
- <p><?php _e( '<strong>SC</strong><br/>Treats the snippet as a shortcode. The name for the shortcode is the same as the title of the snippet (spaces not allowed) and will be used on insert.', 'post-snippets' ); ?></p>
660
-
661
- <p><?php _e( '<strong>QT</strong><br/>Enables the snippet to be available as a quicktag in the HTML editor.', 'post-snippets' ); ?></p>
662
-
663
- <p><?php _e( '<strong>About Post Snippets</strong><br/>Visit my <a href="http://coding.cglounge.com/wordpress-plugins/post-snippets/">Post Snippets</a> page for additional information.', 'post-snippets' ); ?></p>
664
- </div>
665
- </div>
666
- </div>
667
-
668
- <script type="text/javascript">
669
- <!--
670
- <?php global $wp_version; ?>
671
- <?php if ( version_compare( $wp_version, '2.6.999', '<' ) ) { ?>
672
- jQuery('.postbox h3').prepend('<a class="togbox">+</a> ');
673
- <?php } ?>
674
- jQuery('.postbox h3').click( function() { jQuery(jQuery(this).parent().get(0)).toggleClass('closed'); } );
675
- jQuery('.postbox.close-me').each(function(){
676
- jQuery(this).addClass("closed");
677
- });
678
- //-->
679
- </script>
680
  </div>
681
  <?php
682
  }
3
  Plugin Name: Post Snippets
4
  Plugin URI: http://wpstorm.net/wordpress-plugins/post-snippets/
5
  Description: Stores snippets of HTML code or reoccurring text that you often use in your posts. You can use predefined variables to replace parts of the snippet on insert. All snippets are available in the post editor with a TinyMCE button or Quicktags.
6
+ Version: 1.7.1
7
  Author: Johan Steen
8
  Author URI: http://wpstorm.net/
9
  Text Domain: post-snippets
70
  $this->create_shortcodes();
71
 
72
  # Adds the JS and HTML code in the header and footer for the jQuery insert UI dialog in the editor
73
+ add_action( 'admin_init', array(&$this,'enqueue_assets') );
 
74
  add_action( 'admin_head', array(&$this,'jquery_ui_dialog') );
75
  add_action( 'admin_footer', array(&$this,'insert_ui_dialog') );
76
 
102
  }
103
 
104
  /**
105
+ * Enqueues the necessary scripts and styles for the plugins
106
  *
107
  * @since Post Snippets 1.7
108
  *
109
  * @returns Nothing
110
  */
111
+ function enqueue_assets() {
112
  wp_enqueue_script( 'jquery-ui-dialog' );
113
  wp_enqueue_script( 'jquery-ui-tabs' );
 
 
114
 
115
+ # Adds the CSS stylesheet for the jQuery UI dialog
116
+ $style_url = plugins_url( '/assets/post-snippets.css', __FILE__);
117
+ wp_register_style('post-snippets-css', $style_url);
118
+ wp_enqueue_style( 'post-snippets-css');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  }
120
 
121
  /**
244
  <div id="post-snippets-tabs">
245
  <ul>
246
  <?php
247
+ # Create a tab for each available snippet
248
  $snippets = get_option($this->plugin_options);
249
  for ($i = 0; $i < count($snippets); $i++) { ?>
250
  <li><a href="#ps-tabs-<?php echo $i; ?>"><?php echo $snippets[$i]['title']; ?></a></li>
252
  </ul>
253
 
254
  <?php
255
+ # Create a panel with form fields for each available snippet
256
  for ($i = 0; $i < count($snippets); $i++) { ?>
257
  <div id="ps-tabs-<?php echo $i; ?>">
258
+ <?php
259
+ // Print a snippet description is available
260
+ if ( isset($snippets[$i]['description']) )
261
+ echo "<p>" . $snippets[$i]['description'] . "</p>\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
 
263
+ // Get all variables defined for the snippet and output them as input fields
264
+ $var_arr = explode(",",$snippets[$i]['vars']);
265
+ if (!empty($var_arr[0])) {
266
+ for ($j = 0; $j < count($var_arr); $j++) { ?>
267
+ <label for="var_<?php echo $i; ?>_<?php echo $j; ?>"><?php echo($var_arr[$j]);?>:</label>
268
+ <input type="text" id="var_<?php echo $i; ?>_<?php echo $j; ?>" name="var_<?php echo $i; ?>_<?php echo $j; ?>" style="width: 190px" />
269
+ <br/>
270
+ <?php
271
+ }
272
+ } else {
273
+ // If no variables and no description available, output a text to inform the user that it's an insert snippet only
274
+ if ( empty($snippets[$i]['description']) )
275
+ echo "<p>" . __('This snippet is insert only, no variables defined.', 'post-snippets') . "</p>";
276
+ }
277
+ ?>
278
+ </div><!-- #ps-tabs-## -->
279
+ <?php
280
+ }
281
+ ?>
282
+ </div><!-- #post-snippets-tabs -->
283
+ </div><!-- #post-snippets-dialog -->
284
+ </div><!-- .hidden -->
285
  <?
286
  echo "\n<!-- END: Post Snippets UI Dialog -->\n";
287
  }
288
 
 
289
  /**
290
  * Adds a QuickTag button to the HTML editor
291
  *
325
  $snippets = get_option($this->plugin_options);
326
  if (!empty($snippets)) {
327
  for ($i=0; $i < count($snippets); $i++) {
328
+ // If shortcode is enabled for the snippet, and a snippet has been entered, register it as a shortcode.
329
+ if ( $snippets[$i]['shortcode'] && !empty($snippets[$i]['snippet']) ) {
330
+
331
  $vars = explode(",",$snippets[$i]['vars']);
332
  $vars_str = '';
333
  for ($j=0; $j < count($vars); $j++) {
489
  *
490
  */
491
  function wp_admin() {
492
+ add_action( 'contextual_help', array(&$this,'add_help_text'), 10, 3 );
493
+ add_options_page( 'Post Snippets Options', 'Post Snippets', 'administrator', __FILE__, array(&$this, 'options_page') );
 
494
  }
495
 
496
  function admin_message($message) {
501
  }
502
  }
503
 
504
+ /**
505
+ * Display contextual help in the help drop down menu at the options page.
506
+ *
507
+ * @since Post Snippets 1.7.1
508
+ *
509
+ * @returns string The Contextual Help
510
+ */
511
+ function add_help_text($contextual_help, $screen_id, $screen) {
512
+ //$contextual_help .= var_dump($screen); // use this to help determine $screen->id
513
+ if ( $screen->id == 'settings_page_post-snippets/post-snippets' ) {
514
+ $contextual_help =
515
+ '<p><strong>' . __('Title', 'post-snippets') . '</strong></p>' .
516
+ '<p>' . __('Give the snippet a title that helps you identify it in the post editor. If you make it into a shortcode, this is the name of the shortcode as well.', 'post-snippets') . '</p>' .
517
+
518
+ '<p><strong>' . __('Variables', 'post-snippets') . '</strong></p>' .
519
+ '<p>' . __('A comma separated list of custom variables you can reference in your snippet.<br/><br/>Example:<br/>url,name', 'post-snippets') . '</p>' .
520
+
521
+ '<p><strong>' . __('Snippet', 'post-snippets') . '</strong></p>' .
522
+ '<p>' . __('This is the block of text or HTML to insert in the post when you select the snippet from the insert button in the TinyMCE panel in the post editor. If you have entered predefined variables you can reference them from the snippet by enclosing them in {} brackets.<br/><br/>Example:<br/>To reference the variables in the example above, you would enter {url} and {name}.<br/><br/>So if you enter this snippet:<br/><i>This is the website of &lt;a href="{url}"&gt;{name}&lt;/a&gt;</i><br/>You will get the option to replace url and name on insert if they are defined as variables.', 'post-snippets') . '</p>' .
523
+
524
+ '<p><strong>' . __('SC', 'post-snippets') . '</strong></p>' .
525
+ '<p>' . __('Treats the snippet as a shortcode. The name for the shortcode is the same as the title of the snippet (spaces not allowed) and will be used on insert.', 'post-snippets') . '</p>' .
526
+
527
+ '<p><strong>' . __('Advanced', 'post-snippets') . '</strong></p>' .
528
+ '<p>' . __('The snippets can be retrieved directly from PHP, in a theme for instance, with the get_post_snippet() function. Visit the Post Snippets link under more information for instructions.', 'post-snippets') . '</p>' .
529
+
530
+ '<p><strong>' . __('For more information:', 'post-snippets') . '</strong></p>' .
531
+ '<p>' . __('Visit my <a href="http://wpstorm.net/wordpress-plugins/post-snippets/">Post Snippets</a> page for additional information.', 'post-snippets') . '</p>';
532
+ }
533
+ return $contextual_help;
534
+ }
535
+
536
+
537
  function options_page() {
538
  // Add a new Snippet
539
  if (isset($_POST['add-snippet'])) {
601
  <div class="alignleft actions">
602
  <input type="submit" name="add-snippet" value="<?php _e( 'Add New Snippet', 'post-snippets' ) ?>" class="button-secondary" />
603
  <input type="submit" name="delete-selected" value="<?php _e( 'Delete Selected', 'post-snippets' ) ?>" class="button-secondary" />
604
+ <span class="description"><?php _e( '(Use the help dropdown button above for additional information.)', 'post-snippets' ); ?></span>
605
  </div>
606
  </div>
607
  <div class="clear"></div>
651
  <div class="submit">
652
  <input type="submit" name="update-post-snippets" value="<?php _e( 'Update Snippets', 'post-snippets' ) ?>" class="button-primary" /></div>
653
  </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
654
  </div>
655
  <?php
656
  }
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: artstorm
3
  Donate link: http://wpstorm.net/wordpress-plugins/post-snippets/#donation
4
  Tags: post, admin, snippet, html, custom, page, dynamic, editor, quicktag
5
- Requires at least: 2.7
6
  Tested up to: 3.1
7
- Stable tag: 1.7
8
 
9
  Store snippets of HTML code or reoccurring text that you often use in your posts. Custom variables can be used.
10
 
@@ -52,6 +52,13 @@ Please visit [Post Snippets' Comments](http://wpstorm.net/wordpress-plugins/post
52
 
53
  == Changelog ==
54
 
 
 
 
 
 
 
 
55
  = Version 1.7 - 26 Feb 2011 =
56
  * Complete rewrite of the QuickTags insert functionality. It now uses jQuery UI to display a similar tabbed window as the TinyMCE button does. There is now one 'Post Snippets' button in the HTML editor instead of a separate button for each snippet. As the QuickTags function is completely rewritten, and this is the initial release of the new method, please report if you encounter any problems with it.
57
  * Fixed QuickTags compability with WordPress 3.1.
2
  Contributors: artstorm
3
  Donate link: http://wpstorm.net/wordpress-plugins/post-snippets/#donation
4
  Tags: post, admin, snippet, html, custom, page, dynamic, editor, quicktag
5
+ Requires at least: 3.0
6
  Tested up to: 3.1
7
+ Stable tag: 1.7.1
8
 
9
  Store snippets of HTML code or reoccurring text that you often use in your posts. Custom variables can be used.
10
 
52
 
53
  == Changelog ==
54
 
55
+ = Version 1.7.1 - 26 Feb 2011 =
56
+ * Added styling to the Tabs in the Quicktag jQuery dialog window to make them more "tab-like".
57
+ * Added the possibility to use a description for each snippet to display for the user when opening the Quicktag jQuery dialog window. Snippets without description and variables, has a default information message.
58
+ * Moved the help text from below the snippets to the contextual help dropdown menu at the top of the settings page.
59
+ * **Changed the required version of WordPress to 3.0**.
60
+ * Request by proximity2008: A snippet without anything entered in the snippet field will not be registered as a shortcode.
61
+
62
  = Version 1.7 - 26 Feb 2011 =
63
  * Complete rewrite of the QuickTags insert functionality. It now uses jQuery UI to display a similar tabbed window as the TinyMCE button does. There is now one 'Post Snippets' button in the HTML editor instead of a separate button for each snippet. As the QuickTags function is completely rewritten, and this is the initial release of the new method, please report if you encounter any problems with it.
64
  * Fixed QuickTags compability with WordPress 3.1.