Post Snippets - Version 1.5

Version Description

Download this release

Release Info

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

Code changes from version 1.4.9.1 to 1.5

Files changed (2) hide show
  1. post-snippets.php +88 -60
  2. readme.txt +5 -2
post-snippets.php CHANGED
@@ -3,12 +3,12 @@
3
  Plugin Name: Post Snippets
4
  Plugin URI: http://coding.cglounge.com/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.4.9.1
7
  Author: Johan Steen
8
  Author URI: http://coding.cglounge.com/
9
  Text Domain: post-snippets
10
 
11
- Copyright 2009 Johan Steen (email : artstorm [at] gmail [dot] com)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License as published by
@@ -58,7 +58,8 @@ class post_snippets {
58
  */
59
  function init_hooks() {
60
  add_action('admin_menu', array(&$this,'wp_admin'));
61
- add_action('admin_footer', array(&$this,'quicktags'));
 
62
  $this->create_shortcodes();
63
  }
64
 
@@ -110,63 +111,92 @@ class post_snippets {
110
  *
111
  */
112
  function quicktags() {
113
- $quicktag_pages = array( 'post.php', 'post-new.php', 'page-new.php', 'page.php', 'comment.php' );
114
- for($i = 0; $i < count($quicktag_pages); $i++) {
115
- if( strpos($_SERVER['REQUEST_URI'], $quicktag_pages[$i]) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
- $snippets = get_option($this->plugin_options);
118
- if (!empty($snippets)) {
119
- echo '
120
- <script type="text/javascript">
121
- <!--
122
- if (postSnippetsToolbar = document.getElementById("ed_toolbar")) {
123
- var postSnippetsNr, postSnippetsButton;
124
- ';
125
- for ($i = 0; $i < count($snippets); $i++) {
126
- if ($snippets[$i]['quicktag']) {
127
- // Make it js safe
128
- $theSnippet = str_replace('"','\"',str_replace(Chr(13), '', str_replace(Chr(10), '', $snippets[$i]['snippet'])));
129
- //$theSnippet = str_replace('<', '\x3C', str_replace('>', '\x3E', $theSnippet));
130
- $var_arr = explode(",",$snippets[$i]['vars']);
131
- $theVariables = "";
132
- if (!empty($var_arr[0])) {
133
- for ($j = 0; $j < count($var_arr); $j++) {
134
- $theVariables = $theVariables . "'" . $var_arr[$j] . "'";
135
- if ( $j < (count($var_arr) -1) )
136
- $theVariables = $theVariables . ", ";
137
-
138
- }
139
- }
140
 
141
- if ($snippets[$i]['shortcode']) {
142
- echo "var variables" . $i ." = new Array(".$theVariables.");";
143
- echo "var insertString" . $i ." = createShortcode('".$snippets[$i]['title']."', variables".$i.");";
144
- }else{
145
- //echo "var insertString" . $i ." = '" . addslashes(stripslashes($theSnippet)). "';";
146
- echo "var insertString" . $i ." = '" . str_replace('<', '\x3C', str_replace('>', '\x3E', addslashes(stripslashes($theSnippet)) )). "';";
147
- }
148
- echo '
149
- postSnippetsNr = edButtons.length;
150
- edButtons[postSnippetsNr] = new edButton(\'ed_ps'. $i . '\', \'' . $snippets[$i]['title'] . '\', insertString'. $i .', \'\', \'\', -1);
151
- var postSnippetsButton = postSnippetsToolbar.lastChild;
152
-
153
- while (postSnippetsButton.nodeType != 1) {
154
- postSnippetsButton = postSnippetsButton.previousSibling;
155
- }
156
-
157
- postSnippetsButton = postSnippetsButton.cloneNode(true);
158
- postSnippetsToolbar.appendChild(postSnippetsButton);
159
- postSnippetsButton.value = \'' . $snippets[$i]['title'] . '\';
160
- postSnippetsButton.title = postSnippetsNr;
161
- var variables' . $i .' = new Array('.$theVariables.');
162
- postSnippetsButton.onclick = function () {edInsertSnippet(edCanvas, insertString' . $i .', variables' . $i .', parseInt(this.title));}
163
- postSnippetsButton.id = "ed_ps' . $i .'";
164
- ';
165
- } // End if
166
- } // Next
167
- // echo '
168
- echo <<<JAVASCRIPT
 
 
 
 
 
 
 
 
 
 
169
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  function createShortcode(shortcodeTag, shortcodeAtts) {
171
  theSnippet = '[' + shortcodeTag;
172
  for (x in shortcodeAtts)
@@ -198,12 +228,10 @@ echo <<<JAVASCRIPT
198
  //-->
199
  </script>
200
  JAVASCRIPT;
201
- }
202
- break;
203
- }
204
  }
205
  }
206
 
 
207
  /**
208
  * The Admin Page and all it's functions
209
  *
3
  Plugin Name: Post Snippets
4
  Plugin URI: http://coding.cglounge.com/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.5
7
  Author: Johan Steen
8
  Author URI: http://coding.cglounge.com/
9
  Text Domain: post-snippets
10
 
11
+ Copyright 2009-2010 Johan Steen (email : artstorm [at] gmail [dot] com)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License as published by
58
  */
59
  function init_hooks() {
60
  add_action('admin_menu', array(&$this,'wp_admin'));
61
+ add_action('admin_head', array(&$this,'quicktags'));
62
+ // add_action('admin_footer', array(&$this,'quicktags'));
63
  $this->create_shortcodes();
64
  }
65
 
111
  *
112
  */
113
  function quicktags() {
114
+ $snippets = get_option($this->plugin_options);
115
+ if (!empty($snippets)) { ?>
116
+ <script type="text/javascript">
117
+ if(typeof(edButtons)!='undefined') {
118
+ var postSnippetsNr, postSnippetsButton; <?php
119
+ for ($i = 0; $i < count($snippets); $i++) {
120
+ if ($snippets[$i]['quicktag']) {
121
+ // Make it js safe
122
+ $theSnippet = str_replace('"','\"',str_replace(Chr(13), '', str_replace(Chr(10), '', $snippets[$i]['snippet'])));
123
+ //$theSnippet = str_replace('<', '\x3C', str_replace('>', '\x3E', $theSnippet));
124
+ $var_arr = explode(",",$snippets[$i]['vars']);
125
+ $theVariables = "";
126
+ if (!empty($var_arr[0])) {
127
+ for ($j = 0; $j < count($var_arr); $j++) {
128
+ $theVariables = $theVariables . "'" . $var_arr[$j] . "'";
129
+ if ( $j < (count($var_arr) -1) )
130
+ $theVariables = $theVariables . ", ";
131
+ }
132
+ }
133
 
134
+ if ($snippets[$i]['shortcode']) {
135
+ echo "var variables" . $i ." = new Array(".$theVariables.");";
136
+ echo "var insertString" . $i ." = createShortcode('".$snippets[$i]['title']."', variables".$i.");";
137
+ }else{
138
+ //echo "var insertString" . $i ." = '" . addslashes(stripslashes($theSnippet)). "';";
139
+ echo "var insertString" . $i ." = '" . str_replace('<', '\x3C', str_replace('>', '\x3E', addslashes(stripslashes($theSnippet)) )). "';";
140
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
+ echo '
143
+ postSnippetsNr = edButtons.length;
144
+ edButtons[postSnippetsNr] = new edButton(\'ed_psnip'. $i . '\', \'' . $snippets[$i]['title'] . '\', insertString'. $i .', \'\', \'\', -1);
145
+
146
+ ';
147
+ /* postSnippetsNr = edButtons.length;
148
+ edButtons[postSnippetsNr] = new edButton(\'ed_ps'. $i . '\', \'' . $snippets[$i]['title'] . '\', insertString'. $i .', \'\', \'\', -1);
149
+ var postSnippetsButton = postSnippetsToolbar.lastChild;
150
+
151
+ while (postSnippetsButton.nodeType != 1) {
152
+ postSnippetsButton = postSnippetsButton.previousSibling;
153
+ }
154
+
155
+ postSnippetsButton = postSnippetsButton.cloneNode(true);
156
+ postSnippetsToolbar.appendChild(postSnippetsButton);
157
+ postSnippetsButton.value = \'' . $snippets[$i]['title'] . '\';
158
+ postSnippetsButton.title = postSnippetsNr;
159
+ var variables' . $i .' = new Array('.$theVariables.');
160
+ postSnippetsButton.onclick = function () {edInsertSnippet(edCanvas, insertString' . $i .', variables' . $i .', parseInt(this.title));}
161
+ postSnippetsButton.id = "ed_ps' . $i .'"; */
162
+ } // end if
163
+ } //next ?>
164
+ };
165
+ window.onload = ps_quicktags;
166
+ function ps_quicktags() { <?php
167
+ for ($i = 0; $i < count($snippets); $i++) {
168
+ if ($snippets[$i]['quicktag']) {
169
+ // Make it js safe
170
+ $theSnippet = str_replace('"','\"',str_replace(Chr(13), '', str_replace(Chr(10), '', $snippets[$i]['snippet'])));
171
+ //$theSnippet = str_replace('<', '\x3C', str_replace('>', '\x3E', $theSnippet));
172
+ $var_arr = explode(",",$snippets[$i]['vars']);
173
+ $theVariables = "";
174
+ if (!empty($var_arr[0])) {
175
+ for ($j = 0; $j < count($var_arr); $j++) {
176
+ $theVariables = $theVariables . "'" . $var_arr[$j] . "'";
177
+ if ( $j < (count($var_arr) -1) )
178
+ $theVariables = $theVariables . ", ";
179
+ }
180
  }
181
+ if ($snippets[$i]['shortcode']) {
182
+ echo "var variables" . $i ." = new Array(".$theVariables.");";
183
+ echo "var insertString" . $i ." = createShortcode('".$snippets[$i]['title']."', variables".$i.");";
184
+ }else{
185
+ //echo "var insertString" . $i ." = '" . addslashes(stripslashes($theSnippet)). "';";
186
+ echo "var insertString" . $i ." = '" . str_replace('<', '\x3C', str_replace('>', '\x3E', addslashes(stripslashes($theSnippet)) )). "';";
187
+ }
188
+ ?>
189
+ var postSnippetsButton = document.getElementById('ed_psnip<?php echo $i; ?>');
190
+ var variables<?php echo $i; ?> = new Array(<?php echo $theVariables; ?>);
191
+ postSnippetsButton.onclick = function () {edInsertSnippet(edCanvas, insertString<?php echo $i; ?>, variables<?php echo $i; ?>, parseInt(this.title));}
192
+ <?php
193
+ } // end if
194
+ } // next ?>
195
+ }
196
+
197
+
198
+ <?php
199
+ echo <<<JAVASCRIPT
200
  function createShortcode(shortcodeTag, shortcodeAtts) {
201
  theSnippet = '[' + shortcodeTag;
202
  for (x in shortcodeAtts)
228
  //-->
229
  </script>
230
  JAVASCRIPT;
 
 
 
231
  }
232
  }
233
 
234
+
235
  /**
236
  * The Admin Page and all it's functions
237
  *
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: artstorm
3
  Donate link: http://coding.cglounge.com/wordpress-plugins/post-snippets/#pintware
4
  Tags: post, admin, snippet, html, custom, page, dynamic, editor, quicktag
5
  Requires at least: 2.7
6
- Tested up to: 2.8.4
7
- Stable tag: 1.4.9.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,6 +52,9 @@ Please visit [Post Snippets' Comments](http://coding.cglounge.com/wordpress-plug
52
 
53
  == Changelog ==
54
 
 
 
 
55
  = Version 1.4.9.1 - 5 Sep 2009 =
56
  * Included French translation by [Thomas Cailhe (Oyabi)](http://www.oyabi.fr/).
57
 
3
  Donate link: http://coding.cglounge.com/wordpress-plugins/post-snippets/#pintware
4
  Tags: post, admin, snippet, html, custom, page, dynamic, editor, quicktag
5
  Requires at least: 2.7
6
+ Tested up to: 2.9.1
7
+ Stable tag: 1.5
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.5 - 12 Jan 2010 =
56
+ * Updated the plugin so it works with WordPress 2.9.x (the quicktags didn't work in 2.9, now fixed.).
57
+
58
  = Version 1.4.9.1 - 5 Sep 2009 =
59
  * Included French translation by [Thomas Cailhe (Oyabi)](http://www.oyabi.fr/).
60