Post Snippets - Version 1.2

Version Description

  • Added support for Quicktags so the snippets can be made available in the HTML editor as well.
Download this release

Release Info

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

Code changes from version 1.1 to 1.2

languages/post-snippets-sv_SE.po CHANGED
@@ -7,7 +7,7 @@ msgstr ""
7
  "Project-Id-Version: Post Snippets\n"
8
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/post-snippets\n"
9
  "POT-Creation-Date: 2009-03-24 09:38+0000\n"
10
- "PO-Revision-Date: 2009-03-24 11:57+0100\n"
11
  "Last-Translator: Johan Steen <artstorm@gmail.com>\n"
12
  "Language-Team: <artstorm@gmail.com>\n"
13
  "MIME-Version: 1.0\n"
7
  "Project-Id-Version: Post Snippets\n"
8
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/post-snippets\n"
9
  "POT-Creation-Date: 2009-03-24 09:38+0000\n"
10
+ "PO-Revision-Date: 2009-04-01 13:03+0100\n"
11
  "Last-Translator: Johan Steen <artstorm@gmail.com>\n"
12
  "Language-Team: <artstorm@gmail.com>\n"
13
  "MIME-Version: 1.0\n"
post-snippets.php CHANGED
@@ -3,7 +3,7 @@
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.
6
- Version: 1.1
7
  Author: Johan Steen
8
  Author URI: http://coding.cglounge.com/
9
  Text Domain: post-snippets
@@ -39,9 +39,88 @@ class postSnippets {
39
  $this->init_hooks();
40
  }
41
 
42
- function init_hooks(){
43
  load_plugin_textdomain( 'post-snippets', false, dirname(plugin_basename(__FILE__)) . '/languages/');
44
  add_action('admin_menu', array(&$this,'wp_admin'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  }
46
 
47
  /**
@@ -165,6 +244,7 @@ class postSnippets {
165
  }
166
  }
167
 
 
168
  add_action( 'plugins_loaded', create_function( '', 'global $postSnippets; $postSnippets = new postSnippets();' ) );
169
 
170
  ?>
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.
6
+ Version: 1.2
7
  Author: Johan Steen
8
  Author URI: http://coding.cglounge.com/
9
  Text Domain: post-snippets
39
  $this->init_hooks();
40
  }
41
 
42
+ function init_hooks() {
43
  load_plugin_textdomain( 'post-snippets', false, dirname(plugin_basename(__FILE__)) . '/languages/');
44
  add_action('admin_menu', array(&$this,'wp_admin'));
45
+ add_action('admin_footer', array(&$this,'quicktags'));
46
+ }
47
+
48
+ /**
49
+ * Handling of QuickTags in the HTML editor
50
+ *
51
+ */
52
+ function quicktags() {
53
+ $quicktag_pages = array( 'post.php', 'post-new.php', 'page-new.php', 'page.php', 'comment.php' );
54
+ for($i = 0; $i < count($quicktag_pages); $i++) {
55
+ if( strpos($_SERVER['REQUEST_URI'], $quicktag_pages[$i]) ) {
56
+
57
+ $snippets = get_option($this->plugin_options);
58
+ if (!empty($snippets)) {
59
+ echo '
60
+ <script type="text/javascript">
61
+ <!--
62
+ if (postSnippetsToolbar = document.getElementById("ed_toolbar")) {
63
+ var postSnippetsNr, postSnippetsButton;
64
+ ';
65
+ for ($i = 0; $i < count($snippets); $i++) {
66
+
67
+ // Make it js safe
68
+ $theSnippet = str_replace('"','\"',str_replace(Chr(13), '', str_replace(Chr(10), '', $snippets[$i]['snippet'])));
69
+ $var_arr = explode(",",$snippets[$i]['vars']);
70
+ $theVariables = "";
71
+ if (!empty($var_arr[0])) {
72
+ for ($j = 0; $j < count($var_arr); $j++) {
73
+ $theVariables = $theVariables . "'" . $var_arr[$j] . "'";
74
+ if ( $j < (count($var_arr) -1) )
75
+ $theVariables = $theVariables . ", ";
76
+
77
+ }
78
+ }
79
+
80
+ echo '
81
+ postSnippetsNr = edButtons.length;
82
+ edButtons[postSnippetsNr] = new edButton(\'ed_ps'. $i . '\', \'' . $snippets[$i]['title'] . '\', \''.$snippets[$i]['snippet'].'\', \'\', \'\', -1);
83
+ var postSnippetsButton = postSnippetsToolbar.lastChild;
84
+
85
+ while (postSnippetsButton.nodeType != 1) {
86
+ postSnippetsButton = postSnippetsButton.previousSibling;
87
+ }
88
+
89
+ postSnippetsButton = postSnippetsButton.cloneNode(true);
90
+ postSnippetsToolbar.appendChild(postSnippetsButton);
91
+ postSnippetsButton.value = \'' . $snippets[$i]['title'] . '\';
92
+ postSnippetsButton.title = postSnippetsNr;
93
+ var variables' . $i .' = new Array('.$theVariables.');
94
+ postSnippetsButton.onclick = function () {edInsertSnippet(edCanvas, \''.$theSnippet.'\', variables' . $i .', parseInt(this.title));}
95
+ postSnippetsButton.id = "ed_ps' . $i .'";
96
+ ';
97
+ }
98
+ echo '
99
+ }
100
+ function edInsertSnippet(myField,theSnippet,theVariables) {
101
+ var myValue;
102
+ var insertString;
103
+ insertString = theSnippet;
104
+ for (x in theVariables)
105
+ {
106
+ myValue = prompt(theVariables[x]);
107
+ var searchfor = \'{\' + theVariables[x] + \'}\';
108
+ var re = new RegExp(searchfor, \'g\');
109
+ insertString = insertString.replace(re, myValue);
110
+
111
+ }
112
+ theSnippet = insertString;
113
+ if (theSnippet) {
114
+ edInsertContent(myField, theSnippet);
115
+ }
116
+ }
117
+ //-->
118
+ </script>
119
+ ';
120
+ }
121
+ break;
122
+ }
123
+ }
124
  }
125
 
126
  /**
244
  }
245
  }
246
 
247
+
248
  add_action( 'plugins_loaded', create_function( '', 'global $postSnippets; $postSnippets = new postSnippets();' ) );
249
 
250
  ?>
readme.txt CHANGED
@@ -1,12 +1,12 @@
1
  === Post Snippets ===
2
  Contributors: artstorm
3
  Donate link: http://coding.cglounge.com/wordpress-plugins/post-snippets/
4
- Tags: post, admin, snippet, snippets, html, custom, page, dynamic
5
  Requires at least: 2.7
6
  Tested up to: 2.7.1
7
- Stable tag: 1.1
8
 
9
- Store snippets of HTML code or reoccurring text that you often use in your posts.
10
 
11
  == Description ==
12
 
@@ -16,9 +16,10 @@ For complete usage instructions see: [Post Snippets](http://coding.cglounge.com/
16
 
17
  Some features:
18
 
19
- * **Insert** All defined snippets are available through a window via a TinyMCE button in the post editor.
 
20
  * **Admin** Easy to use administration panel where you can add, edit and remove snippets.
21
- * **Variables** Each snippet can have as many custom variables as you like, which can used on insert.
22
  * **Uninstall** If you delete the plugin from your plugins panel it cleans up all data it has created in the Wordpress database.
23
 
24
 
@@ -43,6 +44,9 @@ Meditation.
43
 
44
  == Changelog ==
45
 
 
 
 
46
  = 1.1 =
47
  * Included Swedish translation.
48
  * Added TextDomain functionality for I18n.
1
  === Post Snippets ===
2
  Contributors: artstorm
3
  Donate link: http://coding.cglounge.com/wordpress-plugins/post-snippets/
4
+ Tags: post, admin, snippet, snippets, html, custom, page, dynamic, editor, quicktag
5
  Requires at least: 2.7
6
  Tested up to: 2.7.1
7
+ Stable tag: 1.2
8
 
9
+ Store snippets of HTML code or reoccurring text that you often use in your posts. Custom variables can be used.
10
 
11
  == Description ==
12
 
16
 
17
  Some features:
18
 
19
+ * **Insert** All defined snippets is inserted from a button directly in the post editor.
20
+ * **Buttons** The snippets are available in the viusal editor with a TinyMCE button and in the HTML editor with quicktag buttons.
21
  * **Admin** Easy to use administration panel where you can add, edit and remove snippets.
22
+ * **Variables** Each snippet can have as many custom variables as you like, which can be used on insert.
23
  * **Uninstall** If you delete the plugin from your plugins panel it cleans up all data it has created in the Wordpress database.
24
 
25
 
44
 
45
  == Changelog ==
46
 
47
+ = 1.2 =
48
+ * Added support for Quicktags so the snippets can be made available in the HTML editor as well.
49
+
50
  = 1.1 =
51
  * Included Swedish translation.
52
  * Added TextDomain functionality for I18n.