Post Snippets - Version 1.9.3

Version Description

Download this release

Release Info

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

Code changes from version 1.9.2 to 1.9.3

Files changed (2) hide show
  1. post-snippets.php +36 -8
  2. readme.txt +7 -3
post-snippets.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
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.9.2
7
  Author: Johan Steen
8
  Author URI: http://johansteen.se/
9
  Text Domain: post-snippets
@@ -238,7 +238,7 @@ class Post_Snippets {
238
  *
239
  * @since Post Snippets 1.7
240
  */
241
- function jquery_ui_dialog() {
242
  echo "\n<!-- START: Post Snippets jQuery UI and related functions -->\n";
243
  echo "<script type='text/javascript'>\n";
244
 
@@ -254,6 +254,9 @@ class Post_Snippets {
254
  $variables = '';
255
  if (!empty($var_arr[0])) {
256
  foreach ($var_arr as $var) {
 
 
 
257
  $variables .= ' ' . $var . '="{' . $var . '}"';
258
  }
259
  }
@@ -314,7 +317,7 @@ class Post_Snippets {
314
  if (!empty($var_arr[0])) {
315
  foreach ($var_arr as $key_2 => $var) {
316
  $varname = "var_" . $key . "_" . $key_2; ?>
317
- insert_snippet = insert_snippet.replace(/\{<?php echo $var; ?>\}/g, <?php echo $varname; ?>.val());
318
  <?php
319
  echo "\n";
320
  }
@@ -406,10 +409,13 @@ function edOpenPostSnippets(myField) {
406
  if (!empty($var_arr[0])) {
407
  foreach ($var_arr as $key_2 => $var) {
408
  // Default value exists?
409
- if (strpos($var, '=') !== false) {
410
- $result = explode('=', $var);
411
- $var = $result[0];
412
- $def = $result[1];
 
 
 
413
  } else {
414
  $def = '';
415
  }
@@ -433,6 +439,28 @@ function edOpenPostSnippets(myField) {
433
  echo "<!-- END: Post Snippets UI Dialog -->\n\n";
434
  }
435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
 
437
  // -------------------------------------------------------------------------
438
  // XXXXXX
2
  /*
3
  Plugin Name: Post Snippets
4
  Plugin URI: http://wpstorm.net/wordpress-plugins/post-snippets/
5
+ Description: Build a library with snippets of HTML, PHP code or reoccurring text that you often use in your posts. Variables to replace parts of the snippet on insert can be used. The snippets can be inserted as-is or as shortcodes.
6
+ Version: 1.9.3
7
  Author: Johan Steen
8
  Author URI: http://johansteen.se/
9
  Text Domain: post-snippets
238
  *
239
  * @since Post Snippets 1.7
240
  */
241
+ public function jquery_ui_dialog() {
242
  echo "\n<!-- START: Post Snippets jQuery UI and related functions -->\n";
243
  echo "<script type='text/javascript'>\n";
244
 
254
  $variables = '';
255
  if (!empty($var_arr[0])) {
256
  foreach ($var_arr as $var) {
257
+ // '[test2 yet="{yet}" mupp=per="{mupp=per}" content="{content}"]';
258
+ $var = $this->strip_default_val( $var );
259
+
260
  $variables .= ' ' . $var . '="{' . $var . '}"';
261
  }
262
  }
317
  if (!empty($var_arr[0])) {
318
  foreach ($var_arr as $key_2 => $var) {
319
  $varname = "var_" . $key . "_" . $key_2; ?>
320
+ insert_snippet = insert_snippet.replace(/\{<?php echo $this->strip_default_val( $var ); ?>\}/g, <?php echo $varname; ?>.val());
321
  <?php
322
  echo "\n";
323
  }
409
  if (!empty($var_arr[0])) {
410
  foreach ($var_arr as $key_2 => $var) {
411
  // Default value exists?
412
+ $def_pos = strpos( $var, '=' );
413
+ if ( $def_pos !== false ) {
414
+ $split = str_split( $var, $def_pos );
415
+ $var = $split[0];
416
+ $def = $split[1];
417
+ // Remove the = (first char) in the default value
418
+ $def = substr( $def, 1 );
419
  } else {
420
  $def = '';
421
  }
439
  echo "<!-- END: Post Snippets UI Dialog -->\n\n";
440
  }
441
 
442
+ /**
443
+ * Strip Default Value.
444
+ *
445
+ * Checks if a variable string contains a default value, and if it does it
446
+ * will strip it away and return the string with only the variable name
447
+ * kept.
448
+ *
449
+ * @since Post Snippets 1.9.3
450
+ * @param string $variable The variable to check for default value
451
+ * @return string The variable without any default value
452
+ */
453
+ public function strip_default_val( $variable )
454
+ {
455
+ // Check if variable contains a default defintion
456
+ $def_pos = strpos( $variable, '=' );
457
+
458
+ if ( $def_pos !== false ) {
459
+ $split = str_split( $variable, $def_pos );
460
+ $variable = $split[0];
461
+ }
462
+ return $variable;
463
+ }
464
 
465
  // -------------------------------------------------------------------------
466
  // XXXXXX
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://wpstorm.net/wordpress-plugins/post-snippets/#donation
4
  Tags: post, admin, snippet, shortcode, html, custom, page, dynamic, editor, php, code
5
  Requires at least: 3.0
6
  Tested up to: 3.3.1
7
- Stable tag: 1.9.2
8
 
9
  Keep a snippet library of text, HTML or PHP code to be used in posts. Variables
10
  can be set for more flexibility. Inserts directly or as shortcodes.
@@ -69,7 +69,8 @@ See the [Changelog](http://wordpress.org/extend/plugins/post-snippets/changelog/
69
 
70
  = Why do importing Snippets on a multi site install fail? =
71
 
72
- Upload of zip files must be allowed, enable this in Sites Network Admin -> Settings -> Upload Settings -> Upload file types.
 
73
 
74
  = How can I use the content in an enclosed shortcode? =
75
 
@@ -91,7 +92,10 @@ for questions, answers, support and feature requests.
91
 
92
  == Changelog ==
93
 
94
- = Version 1.9.2 - 30 Jan 2012 =
 
 
 
95
  * A variable can now be assigned a default value that will be used in the
96
  insert window. Use the = sign to give a variable a default value. Ie.
97
  var1,var2=default,var3.
4
  Tags: post, admin, snippet, shortcode, html, custom, page, dynamic, editor, php, code
5
  Requires at least: 3.0
6
  Tested up to: 3.3.1
7
+ Stable tag: 1.9.3
8
 
9
  Keep a snippet library of text, HTML or PHP code to be used in posts. Variables
10
  can be set for more flexibility. Inserts directly or as shortcodes.
69
 
70
  = Why do importing Snippets on a multi site install fail? =
71
 
72
+ Upload of zip files must be allowed, enable this in Sites Network Admin ->
73
+ Settings -> Upload Settings -> Upload file types.
74
 
75
  = How can I use the content in an enclosed shortcode? =
76
 
92
 
93
  == Changelog ==
94
 
95
+ = Version 1.9.3 - 30 Jan 2012 =
96
+ * Fixed a bug that variables using a default value wasn't inserted properly.
97
+
98
+ = Version 1.9.2 - 29 Jan 2012 =
99
  * A variable can now be assigned a default value that will be used in the
100
  insert window. Use the = sign to give a variable a default value. Ie.
101
  var1,var2=default,var3.