Version Description
Note that at least WordPress v3.3 are required for Post Snippets v2.2.
Download this release
Release Info
Developer | artstorm |
Plugin | Post Snippets |
Version | 2.2 |
Comparing to | |
See all releases |
Code changes from version 2.1.1 to 2.2
- lang/post-snippets.pot +154 -163
- lib/PostSnippets/Admin.php +384 -422
- lib/PostSnippets/Help.php +104 -263
- lib/PostSnippets/ImportExport.php +173 -116
- lib/PostSnippets/View.php +29 -0
- phpunit.xml +0 -12
- post-snippets.php +590 -680
- readme.txt +19 -10
- screenshot-1.jpg +0 -0
- screenshot-2.jpg +0 -0
- screenshot-3.jpg +0 -0
- screenshot-4.jpg +0 -0
- unittest/PostSnippetsTest.php +0 -66
- unittest/bootstrap.php +0 -8
- views/admin_snippets.php +73 -0
- views/help_advanced.php +26 -0
- views/help_basic.php +32 -0
- views/help_php.php +24 -0
- views/help_shortcode.php +19 -0
- views/help_sidebar.php +15 -0
- views/jquery-ui-dialog.php +56 -0
lang/post-snippets.pot
CHANGED
@@ -1,154 +1,141 @@
|
|
1 |
-
#
|
2 |
-
#
|
|
|
|
|
|
|
|
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
-
"Project-Id-Version:
|
6 |
-
"Report-Msgid-Bugs-To:
|
7 |
-
"POT-Creation-Date:
|
8 |
-
"
|
9 |
-
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
-
"Content-Transfer-Encoding: 8bit\n"
|
11 |
-
"PO-Revision-Date: 2012-MO-DA HO:MI+ZONE\n"
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
|
|
|
|
|
|
14 |
|
15 |
-
#:
|
16 |
-
msgid "
|
17 |
msgstr ""
|
18 |
|
19 |
-
#:
|
20 |
-
|
|
|
21 |
msgstr ""
|
22 |
|
23 |
-
#:
|
24 |
-
|
|
|
25 |
msgstr ""
|
26 |
|
27 |
-
#:
|
28 |
-
|
|
|
29 |
msgstr ""
|
30 |
|
31 |
-
#:
|
32 |
-
msgid "
|
33 |
msgstr ""
|
34 |
|
35 |
-
#:
|
36 |
-
msgid "
|
37 |
msgstr ""
|
38 |
|
39 |
-
#:
|
40 |
-
msgid "
|
41 |
msgstr ""
|
42 |
|
43 |
-
#:
|
44 |
-
msgid "
|
45 |
msgstr ""
|
46 |
|
47 |
-
#:
|
48 |
-
msgid ""
|
49 |
-
"Give the snippet a title that helps you identify it in the post editor. This "
|
50 |
-
"also becomes the name of the shortcode if you enable that option"
|
51 |
msgstr ""
|
52 |
|
53 |
-
#:
|
54 |
-
|
55 |
-
msgid "Variables"
|
56 |
msgstr ""
|
57 |
|
58 |
-
#:
|
59 |
msgid ""
|
60 |
-
"
|
61 |
-
"
|
62 |
-
"in the insert window by using the equal sign, variable=default."
|
63 |
-
msgstr ""
|
64 |
-
|
65 |
-
#: classes/help.php:104 classes/help.php:115 classes/help.php:230
|
66 |
-
msgid "Example"
|
67 |
msgstr ""
|
68 |
|
69 |
-
#:
|
70 |
-
|
71 |
-
msgid "Snippet"
|
72 |
msgstr ""
|
73 |
|
74 |
-
#:
|
75 |
-
msgid ""
|
76 |
-
"This is the block of text, HTML or PHP to insert in the post or as a "
|
77 |
-
"shortcode. If you have entered predefined variables you can reference them "
|
78 |
-
"from the snippet by enclosing them in {} brackets."
|
79 |
msgstr ""
|
80 |
|
81 |
-
#:
|
82 |
-
msgid ""
|
83 |
-
"To reference the variables in the example above, you would enter {url} and "
|
84 |
-
"{name}. So if you enter this snippet:"
|
85 |
msgstr ""
|
86 |
|
87 |
-
#:
|
88 |
msgid ""
|
89 |
-
"
|
90 |
-
"defined as variables."
|
91 |
msgstr ""
|
92 |
|
93 |
-
#:
|
94 |
-
msgid "
|
95 |
msgstr ""
|
96 |
|
97 |
-
#:
|
98 |
msgid ""
|
99 |
-
"
|
100 |
-
"
|
101 |
msgstr ""
|
102 |
|
103 |
-
#:
|
104 |
msgid ""
|
105 |
-
"
|
106 |
-
"
|
107 |
-
"
|
108 |
-
"the site, and update the content from one single place."
|
109 |
msgstr ""
|
110 |
|
111 |
-
#:
|
112 |
msgid ""
|
113 |
-
"
|
114 |
-
"
|
115 |
-
"
|
116 |
msgstr ""
|
117 |
|
118 |
-
#:
|
119 |
msgid ""
|
120 |
-
"
|
121 |
-
"
|
122 |
-
"variable is reserved, so don't use it in the variables field."
|
123 |
-
msgstr ""
|
124 |
-
|
125 |
-
#: classes/help.php:152 classes/settings.php:366
|
126 |
-
msgid "Options"
|
127 |
msgstr ""
|
128 |
|
129 |
-
#:
|
130 |
-
msgid "
|
|
|
|
|
131 |
msgstr ""
|
132 |
|
133 |
-
#:
|
134 |
msgid ""
|
135 |
-
"
|
136 |
-
"
|
137 |
-
"trademark symbol, and the multiplication symbol."
|
138 |
msgstr ""
|
139 |
|
140 |
-
#:
|
141 |
msgid ""
|
142 |
"Snippets defined as shortcodes can optionally also be evaluated as PHP Code "
|
143 |
"by enabling the PHP checkbox. PHP snippets is only available when treating "
|
144 |
"the snippet as a shortcode."
|
145 |
msgstr ""
|
146 |
|
147 |
-
#:
|
148 |
msgid "Example PHP Snippet"
|
149 |
msgstr ""
|
150 |
|
151 |
-
#:
|
152 |
msgid ""
|
153 |
"With a snippet defined like the one above, you can call it with its "
|
154 |
"shortcode definition in a post. Let's pretend that the example snippet is "
|
@@ -156,131 +143,119 @@ msgid ""
|
|
156 |
"like this from a post:"
|
157 |
msgstr ""
|
158 |
|
159 |
-
#:
|
160 |
msgid ""
|
161 |
"When the shortcode is executed the loop_me variable will be replaced with "
|
162 |
"the string supplied in the shortcode and then the PHP code will be "
|
163 |
"evaluated. (Outputting the string five times in this case. Wow!)"
|
164 |
msgstr ""
|
165 |
|
166 |
-
#:
|
167 |
msgid ""
|
168 |
"Note the evaluation order, any snippet variables will be replaced before the "
|
169 |
"snippet is evaluated as PHP code. Also note that a PHP snippet don't need to "
|
170 |
"be wrapped in <?php #code; ?>."
|
171 |
msgstr ""
|
172 |
|
173 |
-
#:
|
174 |
msgid ""
|
175 |
-
"
|
176 |
-
"
|
177 |
-
|
178 |
-
|
179 |
-
#: classes/help.php:209
|
180 |
-
msgid "Usage"
|
181 |
msgstr ""
|
182 |
|
183 |
-
#:
|
184 |
-
msgid "
|
|
|
|
|
|
|
185 |
msgstr ""
|
186 |
|
187 |
-
#:
|
188 |
-
msgid "
|
|
|
|
|
|
|
189 |
msgstr ""
|
190 |
|
191 |
-
#:
|
192 |
-
msgid ""
|
193 |
-
"(string) The variables to pass to the snippet, formatted as a query string."
|
194 |
msgstr ""
|
195 |
|
196 |
-
#:
|
197 |
-
msgid "
|
198 |
msgstr ""
|
199 |
|
200 |
-
#:
|
|
|
201 |
msgid ""
|
202 |
-
"
|
203 |
-
"
|
|
|
204 |
msgstr ""
|
205 |
|
206 |
-
#:
|
207 |
-
msgid "
|
208 |
msgstr ""
|
209 |
|
210 |
-
#:
|
211 |
-
msgid "
|
212 |
msgstr ""
|
213 |
|
214 |
-
#:
|
215 |
-
|
216 |
-
msgid "Snippets could not be imported:"
|
217 |
msgstr ""
|
218 |
|
219 |
-
#:
|
220 |
-
msgid "
|
221 |
msgstr ""
|
222 |
|
223 |
-
#:
|
224 |
-
msgid "
|
225 |
msgstr ""
|
226 |
|
227 |
-
#:
|
228 |
msgid "A snippet named Untitled has been added."
|
229 |
msgstr ""
|
230 |
|
231 |
-
#:
|
232 |
msgid "Nothing selected to delete."
|
233 |
msgstr ""
|
234 |
|
235 |
-
#:
|
236 |
msgid "Selected snippets have been deleted."
|
237 |
msgstr ""
|
238 |
|
239 |
-
#:
|
240 |
msgid "Snippets have been updated."
|
241 |
msgstr ""
|
242 |
|
243 |
-
#:
|
244 |
msgid "Manage Snippets"
|
245 |
msgstr ""
|
246 |
|
247 |
-
#:
|
248 |
msgid "Import/Export"
|
249 |
msgstr ""
|
250 |
|
251 |
-
#:
|
252 |
msgid "Use the help dropdown button for additional information."
|
253 |
msgstr ""
|
254 |
|
255 |
-
#:
|
256 |
-
msgid "PHP Code"
|
257 |
-
msgstr ""
|
258 |
-
|
259 |
-
#: classes/settings.php:282
|
260 |
-
msgid "Update Snippets"
|
261 |
-
msgstr ""
|
262 |
-
|
263 |
-
#: classes/settings.php:283
|
264 |
-
msgid "Add New Snippet"
|
265 |
-
msgstr ""
|
266 |
-
|
267 |
-
#: classes/settings.php:284
|
268 |
-
msgid "Delete Selected"
|
269 |
-
msgstr ""
|
270 |
-
|
271 |
-
#: classes/settings.php:299
|
272 |
msgid "Export"
|
273 |
msgstr ""
|
274 |
|
275 |
-
#:
|
276 |
msgid "Export your snippets for backup or to import them on another site."
|
277 |
msgstr ""
|
278 |
|
279 |
-
#:
|
280 |
msgid "Export Snippets"
|
281 |
msgstr ""
|
282 |
|
283 |
-
#:
|
284 |
msgid ""
|
285 |
"This is an overview of all snippets defined for this site. These snippets "
|
286 |
"are inserted into posts from the post editor using the Post Snippets button. "
|
@@ -291,41 +266,57 @@ msgid ""
|
|
291 |
"recommended to keep this option disabled."
|
292 |
msgstr ""
|
293 |
|
294 |
-
#:
|
295 |
msgid "Display rendered snippets"
|
296 |
msgstr ""
|
297 |
|
298 |
-
#:
|
299 |
msgid "Update"
|
300 |
msgstr ""
|
301 |
|
302 |
-
#:
|
303 |
-
msgid "
|
304 |
msgstr ""
|
305 |
|
306 |
-
#:
|
307 |
-
msgid "
|
308 |
msgstr ""
|
309 |
|
310 |
-
|
311 |
-
msgid "
|
312 |
msgstr ""
|
313 |
|
314 |
-
|
315 |
-
msgid "
|
|
|
|
|
|
|
|
|
316 |
msgstr ""
|
317 |
|
318 |
-
|
319 |
msgid ""
|
320 |
-
"
|
321 |
-
"
|
322 |
-
|
|
|
|
|
|
|
323 |
msgstr ""
|
324 |
|
325 |
-
|
326 |
-
msgid "
|
|
|
|
|
|
|
|
|
|
|
327 |
msgstr ""
|
328 |
|
329 |
-
|
330 |
-
msgid "
|
|
|
|
|
|
|
|
|
331 |
msgstr ""
|
1 |
+
# SOME DESCRIPTIVE TITLE.
|
2 |
+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
3 |
+
# This file is distributed under the same license as the PACKAGE package.
|
4 |
+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
5 |
+
#
|
6 |
+
#, fuzzy
|
7 |
msgid ""
|
8 |
msgstr ""
|
9 |
+
"Project-Id-Version: PACKAGE VERSION\n"
|
10 |
+
"Report-Msgid-Bugs-To: \n"
|
11 |
+
"POT-Creation-Date: 2013-04-26 10:36+0700\n"
|
12 |
+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
|
|
|
|
|
|
13 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
15 |
+
"MIME-Version: 1.0\n"
|
16 |
+
"Content-Type: text/plain; charset=CHARSET\n"
|
17 |
+
"Content-Transfer-Encoding: 8bit\n"
|
18 |
|
19 |
+
#: post-snippets.php:168
|
20 |
+
msgid "Settings"
|
21 |
msgstr ""
|
22 |
|
23 |
+
#: views/admin_snippets.php:8 views/admin_snippets.php:17
|
24 |
+
#: views/help_basic.php:1
|
25 |
+
msgid "Title"
|
26 |
msgstr ""
|
27 |
|
28 |
+
#: views/admin_snippets.php:9 views/admin_snippets.php:18
|
29 |
+
#: views/help_basic.php:6 lib/PostSnippets/Admin.php:316
|
30 |
+
msgid "Variables"
|
31 |
msgstr ""
|
32 |
|
33 |
+
#: views/admin_snippets.php:10 views/admin_snippets.php:19
|
34 |
+
#: views/help_basic.php:16 lib/PostSnippets/Admin.php:335
|
35 |
+
msgid "Snippet"
|
36 |
msgstr ""
|
37 |
|
38 |
+
#: views/admin_snippets.php:39 lib/PostSnippets/Help.php:40
|
39 |
+
msgid "Shortcode"
|
40 |
msgstr ""
|
41 |
|
42 |
+
#: views/admin_snippets.php:46
|
43 |
+
msgid "PHP Code"
|
44 |
msgstr ""
|
45 |
|
46 |
+
#: views/admin_snippets.php:58 views/help_basic.php:29
|
47 |
+
msgid "Description"
|
48 |
msgstr ""
|
49 |
|
50 |
+
#: views/admin_snippets.php:70
|
51 |
+
msgid "Update Snippets"
|
52 |
msgstr ""
|
53 |
|
54 |
+
#: views/admin_snippets.php:71
|
55 |
+
msgid "Add New Snippet"
|
|
|
|
|
56 |
msgstr ""
|
57 |
|
58 |
+
#: views/admin_snippets.php:72
|
59 |
+
msgid "Delete Selected"
|
|
|
60 |
msgstr ""
|
61 |
|
62 |
+
#: views/help_advanced.php:2
|
63 |
msgid ""
|
64 |
+
"You can retrieve a Post Snippet directly from PHP, in a theme for instance, "
|
65 |
+
"by using the PostSnippets::getSnippet() method."
|
|
|
|
|
|
|
|
|
|
|
66 |
msgstr ""
|
67 |
|
68 |
+
#: views/help_advanced.php:5
|
69 |
+
msgid "Usage"
|
|
|
70 |
msgstr ""
|
71 |
|
72 |
+
#: views/help_advanced.php:11
|
73 |
+
msgid "Parameters"
|
|
|
|
|
|
|
74 |
msgstr ""
|
75 |
|
76 |
+
#: views/help_advanced.php:14
|
77 |
+
msgid "(string) (required) The name of the snippet to retrieve."
|
|
|
|
|
78 |
msgstr ""
|
79 |
|
80 |
+
#: views/help_advanced.php:17
|
81 |
msgid ""
|
82 |
+
"(string) The variables to pass to the snippet, formatted as a query string."
|
|
|
83 |
msgstr ""
|
84 |
|
85 |
+
#: views/help_advanced.php:20 views/help_basic.php:12 views/help_basic.php:21
|
86 |
+
msgid "Example"
|
87 |
msgstr ""
|
88 |
|
89 |
+
#: views/help_basic.php:3
|
90 |
msgid ""
|
91 |
+
"Give the snippet a title that helps you identify it in the post editor. This "
|
92 |
+
"also becomes the name of the shortcode if you enable that option"
|
93 |
msgstr ""
|
94 |
|
95 |
+
#: views/help_basic.php:8
|
96 |
msgid ""
|
97 |
+
"A comma separated list of custom variables you can reference in your "
|
98 |
+
"snippet. A variable can also be assigned a default value that will be used "
|
99 |
+
"in the insert window by using the equal sign, variable=default."
|
|
|
100 |
msgstr ""
|
101 |
|
102 |
+
#: views/help_basic.php:18
|
103 |
msgid ""
|
104 |
+
"This is the block of text, HTML or PHP to insert in the post or as a "
|
105 |
+
"shortcode. If you have entered predefined variables you can reference them "
|
106 |
+
"from the snippet by enclosing them in {} brackets."
|
107 |
msgstr ""
|
108 |
|
109 |
+
#: views/help_basic.php:22
|
110 |
msgid ""
|
111 |
+
"To reference the variables in the example above, you would enter {url} and "
|
112 |
+
"{name}. So if you enter this snippet:"
|
|
|
|
|
|
|
|
|
|
|
113 |
msgstr ""
|
114 |
|
115 |
+
#: views/help_basic.php:26
|
116 |
+
msgid ""
|
117 |
+
"You will get the option to replace url and name on insert if they are "
|
118 |
+
"defined as variables."
|
119 |
msgstr ""
|
120 |
|
121 |
+
#: views/help_basic.php:31
|
122 |
msgid ""
|
123 |
+
"An optional description for the Snippet. If filled out, the description will "
|
124 |
+
"be displayed in the snippets insert window in the post editor."
|
|
|
125 |
msgstr ""
|
126 |
|
127 |
+
#: views/help_php.php:2
|
128 |
msgid ""
|
129 |
"Snippets defined as shortcodes can optionally also be evaluated as PHP Code "
|
130 |
"by enabling the PHP checkbox. PHP snippets is only available when treating "
|
131 |
"the snippet as a shortcode."
|
132 |
msgstr ""
|
133 |
|
134 |
+
#: views/help_php.php:5
|
135 |
msgid "Example PHP Snippet"
|
136 |
msgstr ""
|
137 |
|
138 |
+
#: views/help_php.php:13
|
139 |
msgid ""
|
140 |
"With a snippet defined like the one above, you can call it with its "
|
141 |
"shortcode definition in a post. Let's pretend that the example snippet is "
|
143 |
"like this from a post:"
|
144 |
msgstr ""
|
145 |
|
146 |
+
#: views/help_php.php:19
|
147 |
msgid ""
|
148 |
"When the shortcode is executed the loop_me variable will be replaced with "
|
149 |
"the string supplied in the shortcode and then the PHP code will be "
|
150 |
"evaluated. (Outputting the string five times in this case. Wow!)"
|
151 |
msgstr ""
|
152 |
|
153 |
+
#: views/help_php.php:23
|
154 |
msgid ""
|
155 |
"Note the evaluation order, any snippet variables will be replaced before the "
|
156 |
"snippet is evaluated as PHP code. Also note that a PHP snippet don't need to "
|
157 |
"be wrapped in <?php #code; ?>."
|
158 |
msgstr ""
|
159 |
|
160 |
+
#: views/help_shortcode.php:2
|
161 |
msgid ""
|
162 |
+
"When enabling the shortcode checkbox, the snippet is no longer inserted "
|
163 |
+
"directly but instead inserted as a shortcode. The obvious advantage of this "
|
164 |
+
"is of course that you can insert a block of text or code in many places on "
|
165 |
+
"the site, and update the content from one single place."
|
|
|
|
|
166 |
msgstr ""
|
167 |
|
168 |
+
#: views/help_shortcode.php:6
|
169 |
+
msgid ""
|
170 |
+
"The name to use the shortcode is the same as the title of the snippet "
|
171 |
+
"(spaces are not allowed). When inserting a shortcode snippet, the shortcode "
|
172 |
+
"and not the content will be inserted in the post."
|
173 |
msgstr ""
|
174 |
|
175 |
+
#: views/help_shortcode.php:10
|
176 |
+
msgid ""
|
177 |
+
"If you enclose the shortcode in your posts, you can access the enclosed "
|
178 |
+
"content by using the variable {content} in your snippet. The {content} "
|
179 |
+
"variable is reserved, so don't use it in the variables field."
|
180 |
msgstr ""
|
181 |
|
182 |
+
#: views/help_shortcode.php:13 lib/PostSnippets/Admin.php:332
|
183 |
+
msgid "Options"
|
|
|
184 |
msgstr ""
|
185 |
|
186 |
+
#: views/help_shortcode.php:15
|
187 |
+
msgid "See the dedicated help section for information about PHP shortcodes."
|
188 |
msgstr ""
|
189 |
|
190 |
+
#: views/help_shortcode.php:18
|
191 |
+
#, php-format
|
192 |
msgid ""
|
193 |
+
"Before the shortcode is outputted, it can optionally be formatted with %s, "
|
194 |
+
"to transform quotes to smart quotes, apostrophes, dashes, ellipses, the "
|
195 |
+
"trademark symbol, and the multiplication symbol."
|
196 |
msgstr ""
|
197 |
|
198 |
+
#: views/help_sidebar.php:2
|
199 |
+
msgid "For more information:"
|
200 |
msgstr ""
|
201 |
|
202 |
+
#: views/help_sidebar.php:6
|
203 |
+
msgid "Documentation"
|
204 |
msgstr ""
|
205 |
|
206 |
+
#: views/help_sidebar.php:10
|
207 |
+
msgid "Support Forums"
|
|
|
208 |
msgstr ""
|
209 |
|
210 |
+
#: views/help_sidebar.php:14
|
211 |
+
msgid "GitHub Contribution"
|
212 |
msgstr ""
|
213 |
|
214 |
+
#: views/jquery-ui-dialog.php:47
|
215 |
+
msgid "This snippet is insert only, no variables defined."
|
216 |
msgstr ""
|
217 |
|
218 |
+
#: lib/PostSnippets/Admin.php:47
|
219 |
msgid "A snippet named Untitled has been added."
|
220 |
msgstr ""
|
221 |
|
222 |
+
#: lib/PostSnippets/Admin.php:67
|
223 |
msgid "Nothing selected to delete."
|
224 |
msgstr ""
|
225 |
|
226 |
+
#: lib/PostSnippets/Admin.php:83
|
227 |
msgid "Selected snippets have been deleted."
|
228 |
msgstr ""
|
229 |
|
230 |
+
#: lib/PostSnippets/Admin.php:118
|
231 |
msgid "Snippets have been updated."
|
232 |
msgstr ""
|
233 |
|
234 |
+
#: lib/PostSnippets/Admin.php:216
|
235 |
msgid "Manage Snippets"
|
236 |
msgstr ""
|
237 |
|
238 |
+
#: lib/PostSnippets/Admin.php:216 lib/PostSnippets/Admin.php:259
|
239 |
msgid "Import/Export"
|
240 |
msgstr ""
|
241 |
|
242 |
+
#: lib/PostSnippets/Admin.php:224
|
243 |
msgid "Use the help dropdown button for additional information."
|
244 |
msgstr ""
|
245 |
|
246 |
+
#: lib/PostSnippets/Admin.php:260
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
msgid "Export"
|
248 |
msgstr ""
|
249 |
|
250 |
+
#: lib/PostSnippets/Admin.php:263
|
251 |
msgid "Export your snippets for backup or to import them on another site."
|
252 |
msgstr ""
|
253 |
|
254 |
+
#: lib/PostSnippets/Admin.php:265
|
255 |
msgid "Export Snippets"
|
256 |
msgstr ""
|
257 |
|
258 |
+
#: lib/PostSnippets/Admin.php:288
|
259 |
msgid ""
|
260 |
"This is an overview of all snippets defined for this site. These snippets "
|
261 |
"are inserted into posts from the post editor using the Post Snippets button. "
|
266 |
"recommended to keep this option disabled."
|
267 |
msgstr ""
|
268 |
|
269 |
+
#: lib/PostSnippets/Admin.php:298
|
270 |
msgid "Display rendered snippets"
|
271 |
msgstr ""
|
272 |
|
273 |
+
#: lib/PostSnippets/Admin.php:299
|
274 |
msgid "Update"
|
275 |
msgstr ""
|
276 |
|
277 |
+
#: lib/PostSnippets/Help.php:33
|
278 |
+
msgid "Basic"
|
279 |
msgstr ""
|
280 |
|
281 |
+
#: lib/PostSnippets/Help.php:48
|
282 |
+
msgid "PHP"
|
283 |
msgstr ""
|
284 |
|
285 |
+
#: lib/PostSnippets/Help.php:56
|
286 |
+
msgid "Advanced"
|
287 |
msgstr ""
|
288 |
|
289 |
+
#: lib/PostSnippets/ImportExport.php:38
|
290 |
+
msgid "Error: "
|
291 |
+
msgstr ""
|
292 |
+
|
293 |
+
#: lib/PostSnippets/ImportExport.php:61
|
294 |
+
msgid "Import"
|
295 |
msgstr ""
|
296 |
|
297 |
+
#: lib/PostSnippets/ImportExport.php:67
|
298 |
msgid ""
|
299 |
+
"Import snippets from a post-snippets-export.zip file. Importing overwrites "
|
300 |
+
"any existing snippets."
|
301 |
+
msgstr ""
|
302 |
+
|
303 |
+
#: lib/PostSnippets/ImportExport.php:74
|
304 |
+
msgid "Import Snippets"
|
305 |
msgstr ""
|
306 |
|
307 |
+
#: lib/PostSnippets/ImportExport.php:113
|
308 |
+
msgid "Snippets successfully imported."
|
309 |
+
msgstr ""
|
310 |
+
|
311 |
+
#: lib/PostSnippets/ImportExport.php:118 lib/PostSnippets/ImportExport.php:127
|
312 |
+
#: lib/PostSnippets/ImportExport.php:133
|
313 |
+
msgid "Snippets could not be imported:"
|
314 |
msgstr ""
|
315 |
|
316 |
+
#: lib/PostSnippets/ImportExport.php:120
|
317 |
+
msgid "Unzipping failed."
|
318 |
+
msgstr ""
|
319 |
+
|
320 |
+
#: lib/PostSnippets/ImportExport.php:135
|
321 |
+
msgid "Upload failed."
|
322 |
msgstr ""
|
lib/PostSnippets/Admin.php
CHANGED
@@ -5,430 +5,392 @@
|
|
5 |
* Class that renders out the HTML for the settings screen and contains helpful
|
6 |
* methods to simply the maintainance of the admin screen.
|
7 |
*
|
8 |
-
* @
|
9 |
-
* @
|
10 |
-
* @since Post Snippets 1.8.8
|
11 |
*/
|
12 |
class PostSnippets_Admin
|
13 |
{
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
<?php _e( 'Description', 'post-snippets' ) ?>:
|
278 |
-
<input type='text' style='width: 100%;' name='<?php echo $key; ?>_description' value='<?php if (isset( $snippet['description'] ) ) echo esc_html($snippet['description']); ?>' /><br/>
|
279 |
-
</td>
|
280 |
-
</tr>
|
281 |
-
<?php
|
282 |
-
}
|
283 |
-
}
|
284 |
-
?>
|
285 |
-
</tbody>
|
286 |
-
</table>
|
287 |
-
|
288 |
-
<?php
|
289 |
-
$this->submit( 'update-snippets', __('Update Snippets', 'post-snippets') );
|
290 |
-
$this->submit( 'add-snippet', __('Add New Snippet', 'post-snippets'), 'button-secondary', false );
|
291 |
-
$this->submit( 'delete-snippets', __('Delete Selected', 'post-snippets'), 'button-secondary', false );
|
292 |
-
echo '</form>';
|
293 |
-
}
|
294 |
-
|
295 |
-
/**
|
296 |
-
* Tab for Import/Export
|
297 |
-
*
|
298 |
-
* @since Post Snippets 2.0
|
299 |
-
*/
|
300 |
-
private function tab_tools()
|
301 |
-
{
|
302 |
-
$ie = new PostSnippets_ImportExport();
|
303 |
-
|
304 |
-
// Create header and export html form
|
305 |
-
printf( "<h3>%s</h3>", __( 'Import/Export', 'post-snippets' ));
|
306 |
-
printf( "<h4>%s</h4>", __( 'Export', 'post-snippets' ));
|
307 |
-
echo '<form method="post">';
|
308 |
-
echo '<p>';
|
309 |
-
_e( 'Export your snippets for backup or to import them on another site.', 'post-snippets' );
|
310 |
-
echo '</p>';
|
311 |
-
printf("<input type='submit' class='button' name='postsnippets_export' value='%s' />", __( 'Export Snippets', 'post-snippets') );
|
312 |
-
echo '</form>';
|
313 |
-
|
314 |
-
// Export logic, and import html form and logic
|
315 |
-
$ie->export_snippets();
|
316 |
-
echo $ie->import_snippets();
|
317 |
-
}
|
318 |
-
|
319 |
-
|
320 |
-
/**
|
321 |
-
* Creates a read-only overview page.
|
322 |
-
*
|
323 |
-
* For users with edit_posts capability but without manage_options
|
324 |
-
* capability.
|
325 |
-
*
|
326 |
-
* @since Post Snippets 1.9.7
|
327 |
-
*/
|
328 |
-
private function overview_page()
|
329 |
-
{
|
330 |
-
// Header
|
331 |
-
echo '<div class="wrap">';
|
332 |
-
echo '<h2>Post Snippets</h2>';
|
333 |
-
echo '<p>';
|
334 |
-
_e( 'This is an overview of all snippets defined for this site. These snippets are inserted into posts from the post editor using the Post Snippets button. You can choose to see the snippets here as-is or as they are actually rendered on the website. Enabling rendered snippets for this overview might look strange if the snippet have dependencies on variables, CSS or other parameters only available on the frontend. If that is the case it is recommended to keep this option disabled.', 'post-snippets' );
|
335 |
-
echo '</p>';
|
336 |
-
|
337 |
-
// Form
|
338 |
-
$this->set_user_options();
|
339 |
-
$render = $this->get_user_options();
|
340 |
-
|
341 |
-
echo '<form method="post" action="">';
|
342 |
-
wp_nonce_field( 'post_snippets_user_options', 'post_snippets_user_nonce' );
|
343 |
-
|
344 |
-
$this->checkbox(__('Display rendered snippets', 'post-snippets'), 'render', $render );
|
345 |
-
$this->submit( 'update-post-snippets-user', __('Update', 'post-snippets') );
|
346 |
-
echo '</form>';
|
347 |
-
|
348 |
-
// Snippet List
|
349 |
-
$snippets = get_option( PostSnippets::optionDBKey() );
|
350 |
-
if (!empty($snippets)) {
|
351 |
-
foreach ($snippets as $key => $snippet) {
|
352 |
-
|
353 |
-
echo "<hr style='border: none;border-top:1px dashed #aaa; margin:24px 0;' />";
|
354 |
-
|
355 |
-
echo "<h3>{$snippet['title']}";
|
356 |
-
if ($snippet['description'])
|
357 |
-
echo "<span class='description'> {$snippet['description']}</span>";
|
358 |
-
echo "</h3>";
|
359 |
-
|
360 |
-
if ($snippet['vars'])
|
361 |
-
printf( "<strong>%s:</strong> {$snippet['vars']}<br/>", __('Variables', 'post-snippets') );
|
362 |
-
|
363 |
-
// echo "<strong>Variables:</strong> {$snippet['vars']}<br/>";
|
364 |
-
|
365 |
-
$options = array();
|
366 |
-
if ($snippet['shortcode'])
|
367 |
-
array_push($options, 'Shortcode');
|
368 |
-
if ($snippet['php'])
|
369 |
-
array_push($options, 'PHP');
|
370 |
-
if ($snippet['wptexturize'])
|
371 |
-
array_push($options, 'wptexturize');
|
372 |
-
if ($options)
|
373 |
-
printf ( "<strong>%s:</strong> %s<br/>", __('Options', 'post-snippets'), implode(', ', $options) );
|
374 |
-
|
375 |
-
printf( "<br/><strong>%s:</strong><br/>", __('Snippet', 'post-snippets') );
|
376 |
-
if ( $render ) {
|
377 |
-
echo do_shortcode( $snippet['snippet'] );
|
378 |
-
} else {
|
379 |
-
echo "<code>";
|
380 |
-
echo nl2br( htmlspecialchars($snippet['snippet'], ENT_NOQUOTES) );
|
381 |
-
echo "</code>";
|
382 |
-
}
|
383 |
-
}
|
384 |
-
}
|
385 |
-
|
386 |
-
// Close
|
387 |
-
echo '</div>';
|
388 |
-
}
|
389 |
-
|
390 |
-
|
391 |
-
// -------------------------------------------------------------------------
|
392 |
-
// HTML and Form element methods
|
393 |
-
// -------------------------------------------------------------------------
|
394 |
-
|
395 |
-
/**
|
396 |
-
* Checkbox.
|
397 |
-
*
|
398 |
-
* Renders the HTML for an input checkbox.
|
399 |
-
*
|
400 |
-
* @param string $label The label rendered to screen
|
401 |
-
* @param string $name The unique name and id to identify the input
|
402 |
-
* @param boolean $checked If the input is checked or not
|
403 |
-
*/
|
404 |
-
private function checkbox( $label, $name, $checked )
|
405 |
-
{
|
406 |
-
echo "<label for=\"{$name}\">";
|
407 |
-
printf( '<input type="checkbox" name="%1$s" id="%1$s" value="true"', $name );
|
408 |
-
if ($checked)
|
409 |
-
echo ' checked';
|
410 |
-
echo ' />';
|
411 |
-
echo " {$label}</label><br/>";
|
412 |
-
}
|
413 |
-
|
414 |
-
/**
|
415 |
-
* Submit.
|
416 |
-
*
|
417 |
-
* Renders the HTML for a submit button.
|
418 |
-
*
|
419 |
-
* @since Post Snippets 1.9.7
|
420 |
-
* @param string $name The name that identifies the button on submit
|
421 |
-
* @param string $label The label rendered on the button
|
422 |
-
* @param string $class Optional. Button class. Default: button-primary
|
423 |
-
* @param boolean $wrap Optional. Wrap in a submit div. Default: true
|
424 |
-
*/
|
425 |
-
private function submit( $name, $label, $class='button-primary', $wrap=true )
|
426 |
-
{
|
427 |
-
$btn = sprintf( '<input type="submit" name="%s" value="%s" class="%s" />', $name, $label, $class );
|
428 |
-
|
429 |
-
if ($wrap)
|
430 |
-
$btn = "<div class=\"submit\">{$btn}</div>";
|
431 |
-
|
432 |
-
echo $btn;
|
433 |
-
}
|
434 |
}
|
5 |
* Class that renders out the HTML for the settings screen and contains helpful
|
6 |
* methods to simply the maintainance of the admin screen.
|
7 |
*
|
8 |
+
* @author Johan Steen <artstorm at gmail dot com>
|
9 |
+
* @link http://johansteen.se/
|
|
|
10 |
*/
|
11 |
class PostSnippets_Admin
|
12 |
{
|
13 |
+
// -------------------------------------------------------------------------
|
14 |
+
// Handle form submissions
|
15 |
+
// -------------------------------------------------------------------------
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Add New Snippet.
|
19 |
+
*/
|
20 |
+
private function add()
|
21 |
+
{
|
22 |
+
if (isset($_POST['add-snippet'])
|
23 |
+
&& isset($_POST['update_snippets_nonce'])
|
24 |
+
&& wp_verify_nonce($_POST['update_snippets_nonce'], 'update_snippets')
|
25 |
+
) {
|
26 |
+
$snippets = get_option(PostSnippets::OPTION_KEY);
|
27 |
+
if (empty($snippets)) {
|
28 |
+
$snippets = array();
|
29 |
+
}
|
30 |
+
|
31 |
+
array_push(
|
32 |
+
$snippets,
|
33 |
+
array(
|
34 |
+
'title' => 'Untitled',
|
35 |
+
'vars' => '',
|
36 |
+
'description' => '',
|
37 |
+
'shortcode' => false,
|
38 |
+
'php' => false,
|
39 |
+
'wptexturize' => false,
|
40 |
+
'snippet' => ''
|
41 |
+
)
|
42 |
+
);
|
43 |
+
|
44 |
+
update_option(PostSnippets::OPTION_KEY, $snippets);
|
45 |
+
$this->message(
|
46 |
+
__(
|
47 |
+
'A snippet named Untitled has been added.',
|
48 |
+
PostSnippets::TEXT_DOMAIN
|
49 |
+
)
|
50 |
+
);
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Delete Snippet/s.
|
56 |
+
*/
|
57 |
+
private function delete()
|
58 |
+
{
|
59 |
+
if (isset($_POST['delete-snippets'])
|
60 |
+
&& isset($_POST['update_snippets_nonce'])
|
61 |
+
&& wp_verify_nonce($_POST['update_snippets_nonce'], 'update_snippets')
|
62 |
+
) {
|
63 |
+
$snippets = get_option(PostSnippets::OPTION_KEY);
|
64 |
+
|
65 |
+
if (empty($snippets) || !isset($_POST['checked'])) {
|
66 |
+
$this->message(
|
67 |
+
__('Nothing selected to delete.', PostSnippets::TEXT_DOMAIN)
|
68 |
+
);
|
69 |
+
return;
|
70 |
+
}
|
71 |
+
|
72 |
+
$delete = $_POST['checked'];
|
73 |
+
$newsnippets = array();
|
74 |
+
foreach ($snippets as $key => $snippet) {
|
75 |
+
if (in_array($key, $delete) == false) {
|
76 |
+
array_push($newsnippets, $snippet);
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
update_option(PostSnippets::OPTION_KEY, $newsnippets);
|
81 |
+
$this->message(
|
82 |
+
__(
|
83 |
+
'Selected snippets have been deleted.',
|
84 |
+
PostSnippets::TEXT_DOMAIN
|
85 |
+
)
|
86 |
+
);
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Update Snippet/s.
|
92 |
+
*/
|
93 |
+
private function update()
|
94 |
+
{
|
95 |
+
if (isset($_POST['update-snippets'])
|
96 |
+
&& isset($_POST['update_snippets_nonce'])
|
97 |
+
&& wp_verify_nonce($_POST['update_snippets_nonce'], 'update_snippets')
|
98 |
+
) {
|
99 |
+
$snippets = get_option(PostSnippets::OPTION_KEY);
|
100 |
+
if (!empty($snippets)) {
|
101 |
+
foreach ($snippets as $key => $value) {
|
102 |
+
$new_snippets[$key]['title'] = trim($_POST[$key.'_title']);
|
103 |
+
$new_snippets[$key]['vars'] = str_replace(' ', '', trim($_POST[$key.'_vars']));
|
104 |
+
$new_snippets[$key]['shortcode'] = isset($_POST[$key.'_shortcode']) ? true : false;
|
105 |
+
|
106 |
+
if (PostSnippets::canExecutePHP()) {
|
107 |
+
$new_snippets[$key]['php'] = isset($_POST[$key.'_php']) ? true : false;
|
108 |
+
} else {
|
109 |
+
$new_snippets[$key]['php'] = isset($snippets[$key]['php']) ? $snippets[$key]['php'] : false;
|
110 |
+
}
|
111 |
+
|
112 |
+
$new_snippets[$key]['wptexturize'] = isset($_POST[$key.'_wptexturize']) ? true : false;
|
113 |
+
|
114 |
+
$new_snippets[$key]['snippet'] = wp_specialchars_decode(trim(stripslashes($_POST[$key.'_snippet'])), ENT_NOQUOTES);
|
115 |
+
$new_snippets[$key]['description'] = wp_specialchars_decode(trim(stripslashes($_POST[$key.'_description'])), ENT_NOQUOTES);
|
116 |
+
}
|
117 |
+
update_option(PostSnippets::OPTION_KEY, $new_snippets);
|
118 |
+
$this->message(__('Snippets have been updated.', PostSnippets::TEXT_DOMAIN));
|
119 |
+
}
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Update User Option.
|
125 |
+
*
|
126 |
+
* Sets the per user option for the read-only overview page.
|
127 |
+
*
|
128 |
+
* @since Post Snippets 1.9.7
|
129 |
+
*/
|
130 |
+
private function setUserOptions()
|
131 |
+
{
|
132 |
+
if (isset($_POST['post_snippets_user_nonce'])
|
133 |
+
&& wp_verify_nonce($_POST['post_snippets_user_nonce'], 'post_snippets_user_options')
|
134 |
+
) {
|
135 |
+
$id = get_current_user_id();
|
136 |
+
$render = isset( $_POST['render'] ) ? true : false;
|
137 |
+
update_user_meta($id, PostSnippets::USER_META_KEY, $render);
|
138 |
+
}
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Get User Option.
|
143 |
+
*
|
144 |
+
* Gets the per user option for the read-only overview page.
|
145 |
+
*
|
146 |
+
* @since Post Snippets 1.9.7
|
147 |
+
* @return boolean If overview should be rendered on output or not
|
148 |
+
*/
|
149 |
+
private function getUserOptions()
|
150 |
+
{
|
151 |
+
$id = get_current_user_id();
|
152 |
+
$options = get_user_meta($id, PostSnippets::USER_META_KEY, true);
|
153 |
+
return $options;
|
154 |
+
}
|
155 |
+
|
156 |
+
|
157 |
+
// -------------------------------------------------------------------------
|
158 |
+
// HTML generation for option pages
|
159 |
+
// -------------------------------------------------------------------------
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Render the options page.
|
163 |
+
*
|
164 |
+
* @since Post Snippets 1.9.7
|
165 |
+
* @param string $page Admin page to render. Default: options
|
166 |
+
*/
|
167 |
+
public function render($page)
|
168 |
+
{
|
169 |
+
switch ($page) {
|
170 |
+
case 'options':
|
171 |
+
$this->optionsPage();
|
172 |
+
break;
|
173 |
+
default:
|
174 |
+
$this->overviewPage();
|
175 |
+
break;
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Display Flashing Message.
|
181 |
+
*
|
182 |
+
* @param string $message Message to display to the user.
|
183 |
+
*/
|
184 |
+
private function message($message)
|
185 |
+
{
|
186 |
+
if ($message) {
|
187 |
+
echo "<div class='updated'><p><strong>{$message}</strong></p></div>";
|
188 |
+
}
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Creates the snippets administration page.
|
193 |
+
*
|
194 |
+
* For users with manage_options capability (admin, super admin).
|
195 |
+
*
|
196 |
+
* @since Post Snippets 1.8.8
|
197 |
+
*/
|
198 |
+
private function optionsPage()
|
199 |
+
{
|
200 |
+
// Handle Form Submits
|
201 |
+
$this->add();
|
202 |
+
$this->delete();
|
203 |
+
$this->update();
|
204 |
+
|
205 |
+
// Header
|
206 |
+
echo '
|
207 |
+
<!-- Create a header in the default WordPress \'wrap\' container -->
|
208 |
+
<div class="wrap">
|
209 |
+
<div id="icon-plugins" class="icon32"></div>
|
210 |
+
<h2>Post Snippets</h2>
|
211 |
+
';
|
212 |
+
|
213 |
+
// Tabs
|
214 |
+
$active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'snippets';
|
215 |
+
$base_url = '?page=post-snippets/post-snippets.php&tab=';
|
216 |
+
$tabs = array('snippets' => __('Manage Snippets', PostSnippets::TEXT_DOMAIN), 'tools' => __('Import/Export', PostSnippets::TEXT_DOMAIN));
|
217 |
+
echo '<h2 class="nav-tab-wrapper">';
|
218 |
+
foreach ($tabs as $tab => $title) {
|
219 |
+
$active = ( $active_tab == $tab ) ? ' nav-tab-active' : '';
|
220 |
+
echo "<a href='{$base_url}{$tab}' class='nav-tab {$active}'>{$title}</a>";
|
221 |
+
}
|
222 |
+
echo '</h2>';
|
223 |
+
echo '<p class="description">';
|
224 |
+
_e('Use the help dropdown button for additional information.', PostSnippets::TEXT_DOMAIN);
|
225 |
+
echo '</p>';
|
226 |
+
|
227 |
+
// Tab content
|
228 |
+
if ($active_tab == 'snippets') {
|
229 |
+
$this->tabSnippets();
|
230 |
+
} else {
|
231 |
+
$this->tabTools();
|
232 |
+
}
|
233 |
+
|
234 |
+
// Close it
|
235 |
+
echo '</div>';
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Tab to Manage Snippets.
|
240 |
+
*
|
241 |
+
* @since Post Snippets 2.0
|
242 |
+
*/
|
243 |
+
private function tabSnippets()
|
244 |
+
{
|
245 |
+
$data = array();
|
246 |
+
echo PostSnippets_View::render('admin_snippets', $data);
|
247 |
+
}
|
248 |
+
|
249 |
+
/**
|
250 |
+
* Tab for Import/Export
|
251 |
+
*
|
252 |
+
* @since Post Snippets 2.0
|
253 |
+
*/
|
254 |
+
private function tabTools()
|
255 |
+
{
|
256 |
+
$ie = new PostSnippets_ImportExport();
|
257 |
+
|
258 |
+
// Create header and export html form
|
259 |
+
printf("<h3>%s</h3>", __('Import/Export', PostSnippets::TEXT_DOMAIN));
|
260 |
+
printf("<h4>%s</h4>", __('Export', PostSnippets::TEXT_DOMAIN));
|
261 |
+
echo '<form method="post">';
|
262 |
+
echo '<p>';
|
263 |
+
_e('Export your snippets for backup or to import them on another site.', PostSnippets::TEXT_DOMAIN);
|
264 |
+
echo '</p>';
|
265 |
+
printf("<input type='submit' class='button' name='postsnippets_export' value='%s' />", __('Export Snippets', PostSnippets::TEXT_DOMAIN));
|
266 |
+
echo '</form>';
|
267 |
+
|
268 |
+
// Export logic, and import html form and logic
|
269 |
+
$ie->exportSnippets();
|
270 |
+
echo $ie->importSnippets();
|
271 |
+
}
|
272 |
+
|
273 |
+
|
274 |
+
/**
|
275 |
+
* Creates a read-only overview page.
|
276 |
+
*
|
277 |
+
* For users with edit_posts capability but without manage_options
|
278 |
+
* capability.
|
279 |
+
*
|
280 |
+
* @since Post Snippets 1.9.7
|
281 |
+
*/
|
282 |
+
private function overviewPage()
|
283 |
+
{
|
284 |
+
// Header
|
285 |
+
echo '<div class="wrap">';
|
286 |
+
echo '<h2>Post Snippets</h2>';
|
287 |
+
echo '<p>';
|
288 |
+
_e('This is an overview of all snippets defined for this site. These snippets are inserted into posts from the post editor using the Post Snippets button. You can choose to see the snippets here as-is or as they are actually rendered on the website. Enabling rendered snippets for this overview might look strange if the snippet have dependencies on variables, CSS or other parameters only available on the frontend. If that is the case it is recommended to keep this option disabled.', PostSnippets::TEXT_DOMAIN);
|
289 |
+
echo '</p>';
|
290 |
+
|
291 |
+
// Form
|
292 |
+
$this->setUserOptions();
|
293 |
+
$render = $this->getUserOptions();
|
294 |
+
|
295 |
+
echo '<form method="post" action="">';
|
296 |
+
wp_nonce_field('post_snippets_user_options', 'post_snippets_user_nonce');
|
297 |
+
|
298 |
+
$this->checkbox(__('Display rendered snippets', PostSnippets::TEXT_DOMAIN), 'render', $render);
|
299 |
+
$this->submit('update-post-snippets-user', __('Update', PostSnippets::TEXT_DOMAIN));
|
300 |
+
echo '</form>';
|
301 |
+
|
302 |
+
// Snippet List
|
303 |
+
$snippets = get_option(PostSnippets::OPTION_KEY);
|
304 |
+
if (!empty($snippets)) {
|
305 |
+
foreach ($snippets as $key => $snippet) {
|
306 |
+
|
307 |
+
echo "<hr style='border: none;border-top:1px dashed #aaa; margin:24px 0;' />";
|
308 |
+
|
309 |
+
echo "<h3>{$snippet['title']}";
|
310 |
+
if ($snippet['description']) {
|
311 |
+
echo "<span class='description'> {$snippet['description']}</span>";
|
312 |
+
}
|
313 |
+
echo "</h3>";
|
314 |
+
|
315 |
+
if ($snippet['vars']) {
|
316 |
+
printf("<strong>%s:</strong> {$snippet['vars']}<br/>", __('Variables', PostSnippets::TEXT_DOMAIN));
|
317 |
+
}
|
318 |
+
|
319 |
+
// echo "<strong>Variables:</strong> {$snippet['vars']}<br/>";
|
320 |
+
|
321 |
+
$options = array();
|
322 |
+
if ($snippet['shortcode']) {
|
323 |
+
array_push($options, 'Shortcode');
|
324 |
+
}
|
325 |
+
if ($snippet['php']) {
|
326 |
+
array_push($options, 'PHP');
|
327 |
+
}
|
328 |
+
if ($snippet['wptexturize']) {
|
329 |
+
array_push($options, 'wptexturize');
|
330 |
+
}
|
331 |
+
if ($options) {
|
332 |
+
printf("<strong>%s:</strong> %s<br/>", __('Options', PostSnippets::TEXT_DOMAIN), implode(', ', $options));
|
333 |
+
}
|
334 |
+
|
335 |
+
printf("<br/><strong>%s:</strong><br/>", __('Snippet', PostSnippets::TEXT_DOMAIN));
|
336 |
+
if ($render) {
|
337 |
+
echo do_shortcode($snippet['snippet']);
|
338 |
+
} else {
|
339 |
+
echo "<code>";
|
340 |
+
echo nl2br(htmlspecialchars($snippet['snippet'], ENT_NOQUOTES));
|
341 |
+
echo "</code>";
|
342 |
+
}
|
343 |
+
}
|
344 |
+
}
|
345 |
+
|
346 |
+
// Close
|
347 |
+
echo '</div>';
|
348 |
+
}
|
349 |
+
|
350 |
+
|
351 |
+
// -------------------------------------------------------------------------
|
352 |
+
// HTML and Form element methods
|
353 |
+
// -------------------------------------------------------------------------
|
354 |
|
355 |
+
/**
|
356 |
+
* Checkbox.
|
357 |
+
*
|
358 |
+
* Renders the HTML for an input checkbox.
|
359 |
+
*
|
360 |
+
* @param string $label The label rendered to screen
|
361 |
+
* @param string $name The unique name and id to identify the input
|
362 |
+
* @param boolean $checked If the input is checked or not
|
363 |
+
*/
|
364 |
+
public static function checkbox($label, $name, $checked)
|
365 |
+
{
|
366 |
+
echo "<label for=\"{$name}\">";
|
367 |
+
printf('<input type="checkbox" name="%1$s" id="%1$s" value="true"', $name);
|
368 |
+
if ($checked) {
|
369 |
+
echo ' checked';
|
370 |
+
}
|
371 |
+
echo ' />';
|
372 |
+
echo " {$label}</label><br/>";
|
373 |
+
}
|
374 |
+
|
375 |
+
/**
|
376 |
+
* Submit.
|
377 |
+
*
|
378 |
+
* Renders the HTML for a submit button.
|
379 |
+
*
|
380 |
+
* @since Post Snippets 1.9.7
|
381 |
+
* @param string $name The name that identifies the button on submit
|
382 |
+
* @param string $label The label rendered on the button
|
383 |
+
* @param string $class Optional. Button class. Default: button-primary
|
384 |
+
* @param boolean $wrap Optional. Wrap in a submit div. Default: true
|
385 |
+
*/
|
386 |
+
public static function submit($name, $label, $class = 'button-primary', $wrap = true)
|
387 |
+
{
|
388 |
+
$btn = sprintf('<input type="submit" name="%s" value="%s" class="%s" />', $name, $label, $class);
|
389 |
+
|
390 |
+
if ($wrap) {
|
391 |
+
$btn = "<div class=\"submit\">{$btn}</div>";
|
392 |
+
}
|
393 |
+
|
394 |
+
echo $btn;
|
395 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
}
|
lib/PostSnippets/Help.php
CHANGED
@@ -1,270 +1,111 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
4 |
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
* @package Post Snippets
|
8 |
-
* @author Johan Steen <artstorm at gmail dot com>
|
9 |
-
* @since Post Snippets 1.8.9
|
10 |
*/
|
11 |
class PostSnippets_Help
|
12 |
{
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
<p>'.
|
115 |
-
__('This is the block of text, HTML or PHP to insert in the post or as a shortcode. If you have entered predefined variables you can reference them from the snippet by enclosing them in {} brackets.', 'post-snippets' ).
|
116 |
-
'</p>
|
117 |
-
<p><strong>'.
|
118 |
-
__( 'Example', 'post-snippets' ).
|
119 |
-
'</strong><br/>'.
|
120 |
-
__( 'To reference the variables in the example above, you would enter {url} and {name}. So if you enter this snippet:', 'post-snippets' ).
|
121 |
-
'<br/>
|
122 |
-
<code>This is the website of <a href="{url}">{name}</a></code>
|
123 |
-
<br/>'.
|
124 |
-
__( 'You will get the option to replace url and name on insert if they are defined as variables.', 'post-snippets').
|
125 |
-
'</p>
|
126 |
-
|
127 |
-
<h2>'
|
128 |
-
. __( 'Description', 'post-snippets' ).
|
129 |
-
'</h2>
|
130 |
-
<p>'.
|
131 |
-
__( 'An optional description for the Snippet. If filled out, the description will be displayed in the snippets insert window in the post editor.', 'post-snippets').
|
132 |
-
'</p>';
|
133 |
-
}
|
134 |
-
|
135 |
-
/**
|
136 |
-
* The shortcode help tab.
|
137 |
-
*
|
138 |
-
* @since Post Snippets 1.9.1
|
139 |
-
* @return string The help text
|
140 |
-
*/
|
141 |
-
public function help_shortcode()
|
142 |
-
{
|
143 |
-
return '<p>'.
|
144 |
-
__( 'When enabling the shortcode checkbox, the snippet is no longer inserted directly but instead inserted as a shortcode. The obvious advantage of this is of course that you can insert a block of text or code in many places on the site, and update the content from one single place.', 'post-snippets' ).
|
145 |
-
'</p>
|
146 |
-
|
147 |
-
<p>'.
|
148 |
-
__( 'The name to use the shortcode is the same as the title of the snippet (spaces are not allowed). When inserting a shortcode snippet, the shortcode and not the content will be inserted in the post.', 'post-snippets' ).
|
149 |
-
'</p>
|
150 |
-
<p>'.
|
151 |
-
__( 'If you enclose the shortcode in your posts, you can access the enclosed content by using the variable {content} in your snippet. The {content} variable is reserved, so don\'t use it in the variables field.', 'post-snippets' ).
|
152 |
-
'</p>
|
153 |
-
|
154 |
-
<h2>'
|
155 |
-
. __( 'Options', 'post-snippets' ).
|
156 |
-
'</h2>
|
157 |
-
<p><strong>PHP</strong><br/>'.
|
158 |
-
__( 'See the dedicated help section for information about PHP shortcodes.', 'post-snippets' ).
|
159 |
-
'</p>
|
160 |
-
<p><strong>wptexturize</strong><br/>'.
|
161 |
-
sprintf(__( 'Before the shortcode is outputted, it can optionally be formatted with %s, to transform quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol.', 'post-snippets' ), '<a href="http://codex.wordpress.org/Function_Reference/wptexturize">wptexturize</a>' ).
|
162 |
-
'</p>';
|
163 |
-
}
|
164 |
-
|
165 |
-
/**
|
166 |
-
* The PHP help tab.
|
167 |
-
*
|
168 |
-
* @since Post Snippets 1.9.1
|
169 |
-
* @return string The help text
|
170 |
-
*/
|
171 |
-
public function help_php()
|
172 |
-
{
|
173 |
-
return '<p>'.
|
174 |
-
__('Snippets defined as shortcodes can optionally also be evaluated as PHP Code by enabling the PHP checkbox. PHP snippets is only available when treating the snippet as a shortcode.', 'post-snippets' ).
|
175 |
-
'</p>
|
176 |
-
<p><strong>'.
|
177 |
-
__( 'Example PHP Snippet', 'post-snippets' ).
|
178 |
-
'</strong><br/>
|
179 |
-
<code>
|
180 |
-
for ($i=1; $i<5; $i++) {<br/>
|
181 |
-
echo "{loop_me}<br/>";<br/>
|
182 |
-
};
|
183 |
-
</code></p>
|
184 |
-
|
185 |
-
<p>'.
|
186 |
-
__( 'With a snippet defined like the one above, you can call it with its shortcode definition in a post. Let\'s pretend that the example snippet is named phpcode and have one variable defined loop_me, then it would be called like this from a post:' , 'post-snippets' ).
|
187 |
-
'</p>
|
188 |
-
|
189 |
-
<code>[phpcode loop_me="post snippet with PHP!"]</code>
|
190 |
-
|
191 |
-
<p>'.
|
192 |
-
__( 'When the shortcode is executed the loop_me variable will be replaced with the string supplied in the shortcode and then the PHP code will be evaluated. (Outputting the string five times in this case. Wow!)', 'post-snippets' ).
|
193 |
-
'</p>
|
194 |
-
<p>'.
|
195 |
-
__( 'Note the evaluation order, any snippet variables will be replaced before the snippet is evaluated as PHP code. Also note that a PHP snippet don\'t need to be wrapped in <?php #code; ?>.', 'post-snippets' ).
|
196 |
-
'</p>';
|
197 |
-
}
|
198 |
-
|
199 |
-
/**
|
200 |
-
* The advanced help tab.
|
201 |
-
*
|
202 |
-
* @since Post Snippets 1.9.1
|
203 |
-
* @return string The help text
|
204 |
-
*/
|
205 |
-
public function help_advanced()
|
206 |
-
{
|
207 |
-
return '<p>'.
|
208 |
-
__('You can retrieve a Post Snippet directly from PHP, in a theme for instance, by using the get_post_snippet() function.', 'post-snippets').
|
209 |
-
'</p>
|
210 |
-
|
211 |
-
<h2>'.
|
212 |
-
__('Usage', 'post-snippets').
|
213 |
-
'</h2>
|
214 |
-
<p>'.
|
215 |
-
'<code>
|
216 |
-
<?php $my_snippet = get_post_snippet( $snippet_name, $snippet_vars ); ?>
|
217 |
-
</code></p>
|
218 |
-
|
219 |
-
<h2>'.
|
220 |
-
__('Parameters', 'post-snippets').
|
221 |
-
'</h2>
|
222 |
-
<p>
|
223 |
-
<code>$snippet_name</code><br/>'.
|
224 |
-
__('(string) (required) The name of the snippet to retrieve.', 'post-snippets').
|
225 |
-
|
226 |
-
'<br/><br/><code>'.
|
227 |
-
'$snippet_vars
|
228 |
-
</code><br/>'.
|
229 |
-
__('(string) The variables to pass to the snippet, formatted as a query string.', 'post-snippets').
|
230 |
-
'</p>
|
231 |
-
|
232 |
-
<h2>'.
|
233 |
-
__('Example', 'post-snippets').
|
234 |
-
'</h2>
|
235 |
-
<p><code>
|
236 |
-
<?php<br/>
|
237 |
-
$my_snippet = get_post_snippet( \'internal-link\', \'title=Awesome&url=2011/02/awesome/\' );<br/>
|
238 |
-
echo $my_snippet;<br/>
|
239 |
-
?>
|
240 |
-
</code></p>';
|
241 |
-
}
|
242 |
-
|
243 |
-
|
244 |
-
// -------------------------------------------------------------------------
|
245 |
-
// For compability with WordPress before v3.3.
|
246 |
-
// -------------------------------------------------------------------------
|
247 |
-
|
248 |
-
/**
|
249 |
-
* Contextual Help for WP < v3.3.
|
250 |
-
*
|
251 |
-
* Combines the help tabs above into one long help text for the help tab
|
252 |
-
* when run on WordPress versions before v3.3.
|
253 |
-
*
|
254 |
-
* @since Post Snippets 1.7.1
|
255 |
-
* @return string The Contextual Help
|
256 |
-
*/
|
257 |
-
public function add_help($contextual_help, $screen_id, $screen) {
|
258 |
-
if ( $screen->id == 'settings_page_post-snippets/post-snippets' ) {
|
259 |
-
$contextual_help = '<h1>'.__( 'Basic', 'post-snippets' ).'</h1>';
|
260 |
-
$contextual_help .= $this->help_basic();
|
261 |
-
$contextual_help .= '<h1>'.__( 'Shortcode', 'post-snippets' ).'</h1>';
|
262 |
-
$contextual_help .= $this->help_shortcode();
|
263 |
-
$contextual_help .= '<h1>'.__( 'PHP', 'post-snippets' ).'</h1>';
|
264 |
-
$contextual_help .= $this->help_php();
|
265 |
-
$contextual_help .= '<h1>'.__( 'Advanced', 'post-snippets' ).'</h1>';
|
266 |
-
$contextual_help .= $this->help_advanced();
|
267 |
-
}
|
268 |
-
return $contextual_help;
|
269 |
-
}
|
270 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Handles the plugin help screen.
|
4 |
*
|
5 |
+
* @author Johan Steen <artstorm at gmail dot com>
|
6 |
+
* @link http://johansteen.se/
|
|
|
|
|
|
|
7 |
*/
|
8 |
class PostSnippets_Help
|
9 |
{
|
10 |
+
/**
|
11 |
+
* Constructor.
|
12 |
+
*
|
13 |
+
* @since Post Snippets 1.8.9
|
14 |
+
* @param string The option page to load the help text on
|
15 |
+
*/
|
16 |
+
public function __construct($optionPage)
|
17 |
+
{
|
18 |
+
add_action('load-'.$optionPage, array(&$this,'addHelpTabs'));
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Setup the help tabs and sidebar.
|
23 |
+
*
|
24 |
+
* @since Post Snippets 1.8.9
|
25 |
+
*/
|
26 |
+
public function addHelpTabs()
|
27 |
+
{
|
28 |
+
$screen = get_current_screen();
|
29 |
+
$screen->set_help_sidebar($this->helpSidebar());
|
30 |
+
$screen->add_help_tab(
|
31 |
+
array(
|
32 |
+
'id' => 'basic-plugin-help',
|
33 |
+
'title' => __('Basic', PostSnippets::TEXT_DOMAIN),
|
34 |
+
'content' => $this->helpBasic()
|
35 |
+
)
|
36 |
+
);
|
37 |
+
$screen->add_help_tab(
|
38 |
+
array(
|
39 |
+
'id' => 'shortcode-plugin-help',
|
40 |
+
'title' => __('Shortcode', PostSnippets::TEXT_DOMAIN),
|
41 |
+
'content' => $this->helpShortcode()
|
42 |
+
)
|
43 |
+
);
|
44 |
+
if (PostSnippets::canExecutePHP()) {
|
45 |
+
$screen->add_help_tab(
|
46 |
+
array(
|
47 |
+
'id' => 'php-plugin-help',
|
48 |
+
'title' => __('PHP', PostSnippets::TEXT_DOMAIN),
|
49 |
+
'content' => $this->helpPhp()
|
50 |
+
)
|
51 |
+
);
|
52 |
+
}
|
53 |
+
$screen->add_help_tab(
|
54 |
+
array(
|
55 |
+
'id' => 'advanced-plugin-help',
|
56 |
+
'title' => __('Advanced', PostSnippets::TEXT_DOMAIN),
|
57 |
+
'content' => $this->helpAdvanced()
|
58 |
+
)
|
59 |
+
);
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* The right sidebar help text.
|
64 |
+
*
|
65 |
+
* @return string The help text
|
66 |
+
*/
|
67 |
+
public function helpSidebar()
|
68 |
+
{
|
69 |
+
return PostSnippets_View::render('help_sidebar');
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* The basic help tab.
|
74 |
+
*
|
75 |
+
* @return string The help text
|
76 |
+
*/
|
77 |
+
public function helpBasic()
|
78 |
+
{
|
79 |
+
return PostSnippets_View::render('help_basic');
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* The shortcode help tab.
|
84 |
+
*
|
85 |
+
* @return string The help text
|
86 |
+
*/
|
87 |
+
public function helpShortcode()
|
88 |
+
{
|
89 |
+
return PostSnippets_View::render('help_shortcode');
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* The PHP help tab.
|
94 |
+
*
|
95 |
+
* @return string The help text
|
96 |
+
*/
|
97 |
+
public function helpPhp()
|
98 |
+
{
|
99 |
+
return PostSnippets_View::render('help_php');
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* The advanced help tab.
|
104 |
+
*
|
105 |
+
* @return string The help text
|
106 |
+
*/
|
107 |
+
public function helpAdvanced()
|
108 |
+
{
|
109 |
+
return PostSnippets_View::render('help_advanced');
|
110 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
}
|
lib/PostSnippets/ImportExport.php
CHANGED
@@ -4,133 +4,190 @@
|
|
4 |
*
|
5 |
* Class to handle import and export of Snippets.
|
6 |
*
|
7 |
-
* @
|
8 |
-
* @
|
9 |
-
* @since Post Snippets 2.0
|
10 |
*/
|
11 |
class PostSnippets_ImportExport
|
12 |
{
|
13 |
-
|
14 |
-
|
15 |
-
*
|
16 |
-
* Check if an export file shall be created, or if a download url should be
|
17 |
-
* pushed to the footer. Also checks for old export files laying around and
|
18 |
-
* deletes them (for security).
|
19 |
-
*
|
20 |
-
* @since Post Snippets 1.8
|
21 |
-
*/
|
22 |
-
public function export_snippets() {
|
23 |
-
if ( isset($_POST['postsnippets_export']) ) {
|
24 |
-
$url = $this->create_export_file();
|
25 |
-
if ($url) {
|
26 |
-
define('PSURL', $url);
|
27 |
-
function psnippets_footer() {
|
28 |
-
$export = '<script type="text/javascript">
|
29 |
-
document.location = \''.PSURL.'\';
|
30 |
-
</script>';
|
31 |
-
echo $export;
|
32 |
-
}
|
33 |
-
add_action('admin_footer', 'psnippets_footer', 10000);
|
34 |
|
35 |
-
|
36 |
-
$export .= 'Error: '.$url;
|
37 |
-
}
|
38 |
-
} else {
|
39 |
-
// Check if there is any old export files to delete
|
40 |
-
$dir = wp_upload_dir();
|
41 |
-
$upload_dir = $dir['basedir'] . '/';
|
42 |
-
chdir($upload_dir);
|
43 |
-
if (file_exists ( './post-snippets-export.zip' ) )
|
44 |
-
unlink('./post-snippets-export.zip');
|
45 |
-
}
|
46 |
-
}
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
return $upload_url.'post-snippets-export.zip';
|
81 |
-
}
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
$import .= '<p>'.__( 'Import snippets from a post-snippets-export.zip file. Importing overwrites any existing snippets.', 'post-snippets' ).'</p>';
|
94 |
-
$import .= '<form method="post" enctype="multipart/form-data">';
|
95 |
-
$import .= '<input type="file" name="postsnippets_import_file"/>';
|
96 |
-
$import .= '<input type="hidden" name="action" value="wp_handle_upload"/>';
|
97 |
-
$import .= '<input type="submit" class="button" value="'.__( 'Import Snippets', 'post-snippets' ).'"/>';
|
98 |
-
$import .= '</form>';
|
99 |
-
} else {
|
100 |
-
$file = wp_handle_upload( $_FILES['postsnippets_import_file'] );
|
101 |
-
|
102 |
-
if ( isset( $file['file'] ) && !is_wp_error($file) ) {
|
103 |
-
require_once (ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
104 |
-
$zip = new PclZip( $file['file'] );
|
105 |
-
$dir = wp_upload_dir();
|
106 |
-
$upload_dir = $dir['basedir'] . '/';
|
107 |
-
chdir($upload_dir);
|
108 |
-
$unzipped = $zip->extract();
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
unlink($file['file']);
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
}
|
4 |
*
|
5 |
* Class to handle import and export of Snippets.
|
6 |
*
|
7 |
+
* @author Johan Steen <artstorm at gmail dot com>
|
8 |
+
* @link http://johansteen.se/
|
|
|
9 |
*/
|
10 |
class PostSnippets_ImportExport
|
11 |
{
|
12 |
+
const FILE_CFG = 'post-snippets-export.cfg';
|
13 |
+
const FILE_ZIP = 'post-snippets-export.zip';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
private $downloadUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
/**
|
18 |
+
* Export Snippets.
|
19 |
+
*
|
20 |
+
* Check if an export file shall be created, or if a download url should be
|
21 |
+
* pushed to the footer. Also checks for old export files laying around and
|
22 |
+
* deletes them (for security).
|
23 |
+
*
|
24 |
+
* @return void
|
25 |
+
*/
|
26 |
+
public function exportSnippets()
|
27 |
+
{
|
28 |
+
if (isset($_POST['postsnippets_export'])) {
|
29 |
+
$url = $this->createExportFile();
|
30 |
+
if ($url) {
|
31 |
+
$this->downloadUrl = $url;
|
32 |
+
add_action(
|
33 |
+
'admin_footer',
|
34 |
+
array(&$this, 'psnippetsFooter'),
|
35 |
+
10000
|
36 |
+
);
|
37 |
+
} else {
|
38 |
+
echo __('Error: ', PostSnippets::TEXT_DOMAIN).$url;
|
39 |
+
}
|
40 |
+
} else {
|
41 |
+
// Check if there is any old export files to delete
|
42 |
+
$dir = wp_upload_dir();
|
43 |
+
$upload_dir = $dir['basedir'] . '/';
|
44 |
+
chdir($upload_dir);
|
45 |
+
if (file_exists('./'.self::FILE_ZIP)) {
|
46 |
+
unlink('./'.self::FILE_ZIP);
|
47 |
+
}
|
48 |
+
}
|
49 |
+
}
|
50 |
|
51 |
+
/**
|
52 |
+
* Handles uploading of post snippets archive and import the snippets.
|
53 |
+
*
|
54 |
+
* @uses wp_handle_upload() in wp-admin/includes/file.php
|
55 |
+
* @return string HTML to handle the import
|
56 |
+
*/
|
57 |
+
public function importSnippets()
|
58 |
+
{
|
59 |
+
$import =
|
60 |
+
'<br/><br/><strong>'.
|
61 |
+
__('Import', PostSnippets::TEXT_DOMAIN).
|
62 |
+
'</strong><br/>';
|
63 |
+
if (!isset($_FILES['postsnippets_import_file'])
|
64 |
+
|| empty($_FILES['postsnippets_import_file'])
|
65 |
+
) {
|
66 |
+
$import .=
|
67 |
+
'<p>'.__('Import snippets from a post-snippets-export.zip file. Importing overwrites any existing snippets.', PostSnippets::TEXT_DOMAIN).
|
68 |
+
'</p>';
|
69 |
+
$import .= '<form method="post" enctype="multipart/form-data">';
|
70 |
+
$import .= '<input type="file" name="postsnippets_import_file"/>';
|
71 |
+
$import .= '<input type="hidden" name="action" value="wp_handle_upload"/>';
|
72 |
+
$import .=
|
73 |
+
'<input type="submit" class="button" value="'.
|
74 |
+
__('Import Snippets', PostSnippets::TEXT_DOMAIN).'"/>';
|
75 |
+
$import .= '</form>';
|
76 |
+
} else {
|
77 |
+
$file = wp_handle_upload($_FILES['postsnippets_import_file']);
|
78 |
+
|
79 |
+
if (isset($file['file']) && !is_wp_error($file)) {
|
80 |
+
require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
81 |
+
$zip = new PclZip($file['file']);
|
82 |
+
$dir = wp_upload_dir();
|
83 |
+
$upload_dir = $dir['basedir'] . '/';
|
84 |
+
chdir($upload_dir);
|
85 |
+
$unzipped = $zip->extract();
|
86 |
|
87 |
+
if ($unzipped[0]['stored_filename'] == self::FILE_CFG
|
88 |
+
&& $unzipped[0]['status'] == 'ok'
|
89 |
+
) {
|
90 |
+
// Delete the uploaded archive
|
91 |
+
unlink($file['file']);
|
92 |
|
93 |
+
$snippets = file_get_contents(
|
94 |
+
$upload_dir.self::FILE_CFG
|
95 |
+
);
|
|
|
|
|
96 |
|
97 |
+
if ($snippets) {
|
98 |
+
$snippets = apply_filters(
|
99 |
+
'post_snippets_import',
|
100 |
+
$snippets
|
101 |
+
);
|
102 |
+
update_option(
|
103 |
+
PostSnippets::OPTION_KEY,
|
104 |
+
unserialize($snippets)
|
105 |
+
);
|
106 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
+
// Delete the snippet file
|
109 |
+
unlink('./'.self::FILE_CFG);
|
|
|
110 |
|
111 |
+
$import .=
|
112 |
+
'<p><strong>'.
|
113 |
+
__('Snippets successfully imported.', PostSnippets::TEXT_DOMAIN).
|
114 |
+
'</strong></p>';
|
115 |
+
} else {
|
116 |
+
$import .=
|
117 |
+
'<p><strong>'.
|
118 |
+
__('Snippets could not be imported:', PostSnippets::TEXT_DOMAIN).
|
119 |
+
' '.
|
120 |
+
__('Unzipping failed.', PostSnippets::TEXT_DOMAIN).
|
121 |
+
'</strong></p>';
|
122 |
+
}
|
123 |
+
} else {
|
124 |
+
if ($file['error'] || is_wp_error($file)) {
|
125 |
+
$import .=
|
126 |
+
'<p><strong>'.
|
127 |
+
__('Snippets could not be imported:', PostSnippets::TEXT_DOMAIN).
|
128 |
+
' '.
|
129 |
+
$file['error'].'</strong></p>';
|
130 |
+
} else {
|
131 |
+
$import .=
|
132 |
+
'<p><strong>'.
|
133 |
+
__('Snippets could not be imported:', PostSnippets::TEXT_DOMAIN).
|
134 |
+
' '.
|
135 |
+
__('Upload failed.', PostSnippets::TEXT_DOMAIN).
|
136 |
+
'</strong></p>';
|
137 |
+
}
|
138 |
+
}
|
139 |
+
}
|
140 |
+
return $import;
|
141 |
+
}
|
142 |
|
143 |
+
/**
|
144 |
+
* Create a zipped filed containing all Post Snippets, for export.
|
145 |
+
*
|
146 |
+
* @return string URL to the exported snippets
|
147 |
+
*/
|
148 |
+
private function createExportFile()
|
149 |
+
{
|
150 |
+
$snippets = serialize(get_option(PostSnippets::OPTION_KEY));
|
151 |
+
$snippets = apply_filters('post_snippets_export', $snippets);
|
152 |
+
$dir = wp_upload_dir();
|
153 |
+
$upload_dir = $dir['basedir'] . '/';
|
154 |
+
$upload_url = $dir['baseurl'] . '/';
|
155 |
+
|
156 |
+
// Open a file stream and write the serialized options to it.
|
157 |
+
if (!$handle = fopen($upload_dir.'./'.self::FILE_CFG, 'w')) {
|
158 |
+
die();
|
159 |
+
}
|
160 |
+
if (!fwrite($handle, $snippets)) {
|
161 |
+
die();
|
162 |
+
}
|
163 |
+
fclose($handle);
|
164 |
|
165 |
+
// Create a zip archive
|
166 |
+
require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
167 |
+
chdir($upload_dir);
|
168 |
+
$zip = new PclZip('./'.self::FILE_ZIP);
|
169 |
+
$zipped = $zip->create('./'.self::FILE_CFG);
|
170 |
+
|
171 |
+
// Delete the snippet file
|
172 |
+
unlink('./'.self::FILE_CFG);
|
173 |
+
|
174 |
+
if (!$zipped) {
|
175 |
+
return false;
|
176 |
+
}
|
177 |
+
|
178 |
+
return $upload_url.'./'.self::FILE_ZIP;
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Generates the javascript to trigger the download of the file.
|
183 |
+
*
|
184 |
+
* @return void
|
185 |
+
*/
|
186 |
+
public function psnippetsFooter()
|
187 |
+
{
|
188 |
+
$export = '<script type="text/javascript">
|
189 |
+
document.location = \''.$this->downloadUrl.'\';
|
190 |
+
</script>';
|
191 |
+
echo $export;
|
192 |
+
}
|
193 |
}
|
lib/PostSnippets/View.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MVC like View Handling in WordPress.
|
4 |
+
*
|
5 |
+
* @author Johan Steen <artstorm at gmail dot com>
|
6 |
+
* @link http://johansteen.se/
|
7 |
+
*/
|
8 |
+
class PostSnippets_View
|
9 |
+
{
|
10 |
+
/**
|
11 |
+
* Render a View.
|
12 |
+
*
|
13 |
+
* @param string $view View to render.
|
14 |
+
* @param array $data Data to be used within the view.
|
15 |
+
* @return string The processed view.
|
16 |
+
*/
|
17 |
+
public static function render($view, $data = null)
|
18 |
+
{
|
19 |
+
// Handle data
|
20 |
+
($data) ? extract($data) : null;
|
21 |
+
|
22 |
+
ob_start();
|
23 |
+
include(plugin_dir_path(__FILE__).'../../views/'.$view.'.php');
|
24 |
+
$view = ob_get_contents();
|
25 |
+
ob_end_clean();
|
26 |
+
|
27 |
+
return $view;
|
28 |
+
}
|
29 |
+
}
|
phpunit.xml
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
-
<phpunit
|
3 |
-
colors="true"
|
4 |
-
stopOnFailure="false"
|
5 |
-
bootstrap="unittest/bootstrap.php">
|
6 |
-
backupGlobals="false"
|
7 |
-
<testsuites>
|
8 |
-
<testsuite name="complete">
|
9 |
-
<directory>unittest</directory>
|
10 |
-
</testsuite>
|
11 |
-
</testsuites>
|
12 |
-
</phpunit>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
post-snippets.php
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Post Snippets
|
4 |
-
Plugin URI: http://
|
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 |
Author: Johan Steen
|
7 |
Author URI: http://johansteen.se/
|
8 |
-
Version: 2.
|
9 |
License: GPLv2 or later
|
10 |
Text Domain: post-snippets
|
11 |
|
@@ -30,22 +30,22 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
30 |
spl_autoload_register('PostSnippets::autoload');
|
31 |
|
32 |
/**
|
33 |
-
* Init Singleton Class
|
34 |
*
|
35 |
-
* @package Post Snippets
|
36 |
* @author Johan Steen <artstorm at gmail dot com>
|
|
|
37 |
*/
|
38 |
class PostSnippets
|
39 |
{
|
40 |
private static $instance = false;
|
41 |
|
42 |
-
const MIN_PHP_VERSION
|
43 |
-
const MIN_WP_VERSION
|
44 |
-
const
|
45 |
-
const USER_META_KEY
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
|
50 |
/**
|
51 |
* Singleton class
|
@@ -59,12 +59,10 @@ class PostSnippets
|
|
59 |
}
|
60 |
|
61 |
/**
|
62 |
-
*
|
63 |
-
* Initializes the plugin by setting localization, filters, and
|
64 |
-
* administration functions.
|
65 |
*/
|
66 |
-
|
67 |
-
|
68 |
if (!$this->testHost()) {
|
69 |
return;
|
70 |
}
|
@@ -72,49 +70,40 @@ class PostSnippets
|
|
72 |
add_action('init', array($this, 'textDomain'));
|
73 |
register_uninstall_hook(__FILE__, array(__CLASS__, 'uninstall'));
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
add_action( 'admin_print_footer_scripts',
|
99 |
-
array(&$this,'add_quicktag_button'), 100 );
|
100 |
-
} else {
|
101 |
-
add_action( 'edit_form_advanced', array(&$this,'add_quicktag_button_pre33') );
|
102 |
-
add_action( 'edit_page_form', array(&$this,'add_quicktag_button_pre33') );
|
103 |
-
}
|
104 |
-
}
|
105 |
|
106 |
/**
|
107 |
* PSR-0 compliant autoloader to load classes as needed.
|
108 |
*
|
109 |
-
* @since 2.1
|
110 |
-
*
|
111 |
* @param string $classname The name of the class
|
112 |
* @return null Return early if the class name does not start with the
|
113 |
* correct prefix
|
114 |
*/
|
115 |
public static function autoload($className)
|
116 |
{
|
117 |
-
if (
|
118 |
return;
|
119 |
}
|
120 |
$className = ltrim($className, '\\');
|
@@ -133,11 +122,11 @@ class PostSnippets
|
|
133 |
}
|
134 |
|
135 |
/**
|
136 |
-
* Loads the text domain for translation
|
137 |
*/
|
138 |
public function textDomain()
|
139 |
{
|
140 |
-
$domain =
|
141 |
$locale = apply_filters('plugin_locale', get_locale(), $domain);
|
142 |
load_textdomain(
|
143 |
$domain,
|
@@ -155,621 +144,526 @@ class PostSnippets
|
|
155 |
*/
|
156 |
public function uninstall()
|
157 |
{
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
/**
|
172 |
-
* Quick link to the Post Snippets Settings page from the Plugins page.
|
173 |
-
*
|
174 |
-
* @return Array with all the plugin's action links
|
175 |
-
*/
|
176 |
-
function plugin_action_links( $links, $file ) {
|
177 |
-
if ( $file == plugin_basename( dirname(__FILE__).'/post-snippets.php' ) ) {
|
178 |
-
$links[] = '<a href="options-general.php?page=post-snippets/post-snippets.php">'.__('Settings', 'post-snippets').'</a>';
|
179 |
-
}
|
180 |
-
return $links;
|
181 |
-
}
|
182 |
-
|
183 |
-
|
184 |
-
/**
|
185 |
-
* Enqueues the necessary scripts and styles for the plugins
|
186 |
-
*
|
187 |
-
* @since Post Snippets 1.7
|
188 |
-
*/
|
189 |
-
function enqueue_assets() {
|
190 |
-
wp_enqueue_script( 'jquery-ui-dialog' );
|
191 |
-
wp_enqueue_script( 'jquery-ui-tabs' );
|
192 |
-
wp_enqueue_style( 'wp-jquery-ui-dialog' );
|
193 |
-
|
194 |
-
# Adds the CSS stylesheet for the jQuery UI dialog
|
195 |
-
$style_url = plugins_url( '/assets/post-snippets.css', __FILE__ );
|
196 |
-
wp_register_style( 'post-snippets', $style_url, false, '2.0' );
|
197 |
-
wp_enqueue_style( 'post-snippets' );
|
198 |
-
}
|
199 |
-
|
200 |
-
|
201 |
-
// -------------------------------------------------------------------------
|
202 |
-
// WordPress Editor Buttons
|
203 |
-
// -------------------------------------------------------------------------
|
204 |
-
|
205 |
-
/**
|
206 |
-
* Add TinyMCE button.
|
207 |
-
*
|
208 |
-
* Adds filters to add custom buttons to the TinyMCE editor (Visual Editor)
|
209 |
-
* in WordPress.
|
210 |
-
*
|
211 |
-
* @since Post Snippets 1.8.7
|
212 |
-
*/
|
213 |
-
public function add_tinymce_button()
|
214 |
-
{
|
215 |
-
// Don't bother doing this stuff if the current user lacks permissions
|
216 |
-
if ( !current_user_can('edit_posts') &&
|
217 |
-
!current_user_can('edit_pages') )
|
218 |
-
return;
|
219 |
-
|
220 |
-
// Add only in Rich Editor mode
|
221 |
-
if ( get_user_option('rich_editing') == 'true') {
|
222 |
-
add_filter('mce_external_plugins',
|
223 |
-
array(&$this, 'register_tinymce_plugin') );
|
224 |
-
add_filter('mce_buttons',
|
225 |
-
array(&$this, 'register_tinymce_button') );
|
226 |
-
}
|
227 |
-
}
|
228 |
-
|
229 |
-
/**
|
230 |
-
* Register TinyMCE button.
|
231 |
-
*
|
232 |
-
* Pushes the custom TinyMCE button into the array of with button names.
|
233 |
-
* 'separator' or '|' can be pushed to the array as well. See the link
|
234 |
-
* for all available TinyMCE controls.
|
235 |
-
*
|
236 |
-
* @see wp-includes/class-wp-editor.php
|
237 |
-
* @link http://www.tinymce.com/wiki.php/Buttons/controls
|
238 |
-
* @since Post Snippets 1.8.7
|
239 |
-
*
|
240 |
-
* @param array $buttons Filter supplied array of buttons to modify
|
241 |
-
* @return array The modified array with buttons
|
242 |
-
*/
|
243 |
-
public function register_tinymce_button( $buttons )
|
244 |
-
{
|
245 |
-
array_push( $buttons, 'separator', self::TINYMCE_PLUGIN_NAME );
|
246 |
-
return $buttons;
|
247 |
-
}
|
248 |
-
|
249 |
-
/**
|
250 |
-
* Register TinyMCE plugin.
|
251 |
-
*
|
252 |
-
* Adds the absolute URL for the TinyMCE plugin to the associative array of
|
253 |
-
* plugins. Array structure: 'plugin_name' => 'plugin_url'
|
254 |
-
*
|
255 |
-
* @see wp-includes/class-wp-editor.php
|
256 |
-
* @since Post Snippets 1.8.7
|
257 |
-
*
|
258 |
-
* @param array $plugins Filter supplied array of plugins to modify
|
259 |
-
* @return array The modified array with plugins
|
260 |
-
*/
|
261 |
-
public function register_tinymce_plugin( $plugins )
|
262 |
-
{
|
263 |
-
// Load the TinyMCE plugin, editor_plugin.js, into the array
|
264 |
-
$plugins[self::TINYMCE_PLUGIN_NAME] =
|
265 |
-
plugins_url('/tinymce/editor_plugin.js?ver=1.9', __FILE__);
|
266 |
-
|
267 |
-
return $plugins;
|
268 |
-
}
|
269 |
-
|
270 |
-
/**
|
271 |
-
* Adds a QuickTag button to the HTML editor.
|
272 |
-
*
|
273 |
-
* Compatible with WordPress 3.3 and newer.
|
274 |
-
*
|
275 |
-
* @see wp-includes/js/quicktags.dev.js -> qt.addButton()
|
276 |
-
* @since Post Snippets 1.8.6
|
277 |
-
*/
|
278 |
-
public function add_quicktag_button()
|
279 |
-
{
|
280 |
-
// Only run the function on post edit screens
|
281 |
-
if ( function_exists( 'get_current_screen' ) ) {
|
282 |
-
$screen = get_current_screen();
|
283 |
-
if ($screen->base != 'post')
|
284 |
-
return;
|
285 |
-
}
|
286 |
-
|
287 |
-
echo "\n<!-- START: Add QuickTag button for Post Snippets -->\n";
|
288 |
-
?>
|
289 |
-
<script type="text/javascript" charset="utf-8">
|
290 |
-
QTags.addButton( 'post_snippets_id', 'Post Snippets', qt_post_snippets );
|
291 |
-
function qt_post_snippets() {
|
292 |
-
post_snippets_caller = 'html';
|
293 |
-
jQuery( "#post-snippets-dialog" ).dialog( "open" );
|
294 |
-
}
|
295 |
-
</script>
|
296 |
-
<?php
|
297 |
-
echo "\n<!-- END: Add QuickTag button for Post Snippets -->\n";
|
298 |
-
}
|
299 |
-
|
300 |
-
|
301 |
-
/**
|
302 |
-
* Adds a QuickTag button to the HTML editor.
|
303 |
-
*
|
304 |
-
* Used when running on WordPress lower than version 3.3.
|
305 |
-
*
|
306 |
-
* @see wp-includes/js/quicktags.dev.js
|
307 |
-
* @since Post Snippets 1.7
|
308 |
-
* @deprecated Since 1.8.6
|
309 |
-
*/
|
310 |
-
function add_quicktag_button_pre33() {
|
311 |
-
// Only run the function on post edit screens
|
312 |
-
if ( function_exists( 'get_current_screen' ) ) {
|
313 |
-
$screen = get_current_screen();
|
314 |
-
if ($screen->base != 'post')
|
315 |
-
return;
|
316 |
-
}
|
317 |
-
|
318 |
-
echo "\n<!-- START: Post Snippets QuickTag button -->\n";
|
319 |
-
?>
|
320 |
-
<script type="text/javascript" charset="utf-8">
|
321 |
-
// <![CDATA[
|
322 |
-
//edButton(id, display, tagStart, tagEnd, access, open)
|
323 |
-
edbuttonlength = edButtons.length;
|
324 |
-
edButtons[edbuttonlength++] = new edButton('ed_postsnippets', 'Post Snippets', '', '', '', -1);
|
325 |
-
(function(){
|
326 |
-
if (typeof jQuery === 'undefined') {
|
327 |
-
return;
|
328 |
-
}
|
329 |
-
jQuery(document).ready(function(){
|
330 |
-
jQuery("#ed_toolbar").append('<input type="button" value="Post Snippets" id="ed_postsnippets" class="ed_button" onclick="edOpenPostSnippets(edCanvas);" title="Post Snippets" />');
|
331 |
-
});
|
332 |
-
}());
|
333 |
-
// ]]>
|
334 |
-
</script>
|
335 |
-
<?php
|
336 |
-
echo "\n<!-- END: Post Snippets QuickTag button -->\n";
|
337 |
-
}
|
338 |
-
|
339 |
-
|
340 |
-
// -------------------------------------------------------------------------
|
341 |
-
// JavaScript / jQuery handling for the post editor
|
342 |
-
// -------------------------------------------------------------------------
|
343 |
-
|
344 |
-
/**
|
345 |
-
* jQuery control for the dialog and Javascript needed to insert snippets into the editor
|
346 |
-
*
|
347 |
-
* @since Post Snippets 1.7
|
348 |
-
*/
|
349 |
-
public function jquery_ui_dialog()
|
350 |
-
{
|
351 |
-
// Only run the function on post edit screens
|
352 |
-
if ( function_exists( 'get_current_screen' ) ) {
|
353 |
-
$screen = get_current_screen();
|
354 |
-
if ($screen->base != 'post')
|
355 |
-
return;
|
356 |
-
}
|
357 |
-
|
358 |
-
echo "\n<!-- START: Post Snippets jQuery UI and related functions -->\n";
|
359 |
-
echo "<script type='text/javascript'>\n";
|
360 |
-
|
361 |
-
# Prepare the snippets and shortcodes into javascript variables
|
362 |
-
# so they can be inserted into the editor, and get the variables replaced
|
363 |
-
# with user defined strings.
|
364 |
-
$snippets = get_option( self::OPTION_DB_KEY );
|
365 |
-
foreach ($snippets as $key => $snippet) {
|
366 |
-
if ($snippet['shortcode']) {
|
367 |
-
# Build a long string of the variables, ie: varname1={varname1} varname2={varname2}
|
368 |
-
# so {varnameX} can be replaced at runtime.
|
369 |
-
$var_arr = explode(",",$snippet['vars']);
|
370 |
-
$variables = '';
|
371 |
-
if (!empty($var_arr[0])) {
|
372 |
-
foreach ($var_arr as $var) {
|
373 |
-
// '[test2 yet="{yet}" mupp=per="{mupp=per}" content="{content}"]';
|
374 |
-
$var = $this->strip_default_val( $var );
|
375 |
-
|
376 |
-
$variables .= ' ' . $var . '="{' . $var . '}"';
|
377 |
-
}
|
378 |
-
}
|
379 |
-
$shortcode = $snippet['title'] . $variables;
|
380 |
-
echo "var postsnippet_{$key} = '[" . $shortcode . "]';\n";
|
381 |
-
} else {
|
382 |
-
// To use $snippet is probably not a good naming convention here.
|
383 |
-
// rename to js_snippet or something?
|
384 |
-
$snippet = $snippet['snippet'];
|
385 |
-
# Fixes for potential collisions:
|
386 |
-
/* Replace <> with char codes, otherwise </script> in a snippet will break it */
|
387 |
-
$snippet = str_replace( '<', '\x3C', str_replace( '>', '\x3E', $snippet ) );
|
388 |
-
/* Escape " with \" */
|
389 |
-
$snippet = str_replace( '"', '\"', $snippet );
|
390 |
-
/* Remove CR and replace LF with \n to keep formatting */
|
391 |
-
$snippet = str_replace( chr(13), '', str_replace( chr(10), '\n', $snippet ) );
|
392 |
-
# Print out the variable containing the snippet
|
393 |
-
echo "var postsnippet_{$key} = \"" . $snippet . "\";\n";
|
394 |
-
}
|
395 |
-
}
|
396 |
-
?>
|
397 |
-
|
398 |
-
jQuery(document).ready(function($){
|
399 |
-
<?php
|
400 |
-
# Create js variables for all form fields
|
401 |
-
foreach ($snippets as $key => $snippet) {
|
402 |
-
$var_arr = explode(",",$snippet['vars']);
|
403 |
-
if (!empty($var_arr[0])) {
|
404 |
-
foreach ($var_arr as $key_2 => $var) {
|
405 |
-
$varname = "var_" . $key . "_" . $key_2;
|
406 |
-
echo "var {$varname} = $( \"#{$varname}\" );\n";
|
407 |
-
}
|
408 |
-
}
|
409 |
-
}
|
410 |
-
?>
|
411 |
-
|
412 |
-
var $tabs = $("#post-snippets-tabs").tabs();
|
413 |
-
|
414 |
-
$(function() {
|
415 |
-
$( "#post-snippets-dialog" ).dialog({
|
416 |
-
autoOpen: false,
|
417 |
-
modal: true,
|
418 |
-
dialogClass: 'wp-dialog',
|
419 |
-
buttons: {
|
420 |
-
Cancel: function() {
|
421 |
-
$( this ).dialog( "close" );
|
422 |
-
},
|
423 |
-
"Insert": function() {
|
424 |
-
$( this ).dialog( "close" );
|
425 |
-
var selected = $tabs.tabs('option', 'selected');
|
426 |
-
<?php
|
427 |
-
foreach ($snippets as $key => $snippet) {
|
428 |
-
?>
|
429 |
-
if (selected == <?php echo $key; ?>) {
|
430 |
-
insert_snippet = postsnippet_<?php echo $key; ?>;
|
431 |
-
<?php
|
432 |
-
$var_arr = explode(",",$snippet['vars']);
|
433 |
-
if (!empty($var_arr[0])) {
|
434 |
-
foreach ($var_arr as $key_2 => $var) {
|
435 |
-
$varname = "var_" . $key . "_" . $key_2; ?>
|
436 |
-
insert_snippet = insert_snippet.replace(/\{<?php echo $this->strip_default_val( $var ); ?>\}/g, <?php echo $varname; ?>.val());
|
437 |
-
<?php
|
438 |
-
echo "\n";
|
439 |
-
}
|
440 |
-
}
|
441 |
-
?>
|
442 |
-
}
|
443 |
-
<?php
|
444 |
-
}
|
445 |
-
?>
|
446 |
-
|
447 |
-
// Decide what method to use to insert the snippet depending
|
448 |
-
// from what editor the window was opened from
|
449 |
-
if (post_snippets_caller == 'html') {
|
450 |
-
// HTML editor in WordPress 3.3 and greater
|
451 |
-
QTags.insertContent(insert_snippet);
|
452 |
-
} else if (post_snippets_caller == 'html_pre33') {
|
453 |
-
// HTML editor in WordPress below 3.3.
|
454 |
-
edInsertContent(post_snippets_canvas, insert_snippet);
|
455 |
-
} else {
|
456 |
-
// Visual Editor
|
457 |
-
post_snippets_canvas.execCommand('mceInsertContent', false, insert_snippet);
|
458 |
-
}
|
459 |
-
|
460 |
-
}
|
461 |
-
},
|
462 |
-
width: 500,
|
463 |
-
});
|
464 |
-
});
|
465 |
-
});
|
466 |
-
|
467 |
-
// Global variables to keep track on the canvas instance and from what editor
|
468 |
-
// that opened the Post Snippets popup.
|
469 |
-
var post_snippets_canvas;
|
470 |
-
var post_snippets_caller = '';
|
471 |
|
472 |
-
/**
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
function
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
}
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
773 |
|
774 |
|
775 |
// -------------------------------------------------------------------------
|
@@ -784,14 +678,14 @@ function edOpenPostSnippets(myField) {
|
|
784 |
// Check if PHP is too old
|
785 |
if (version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '<')) {
|
786 |
// Display notice
|
787 |
-
add_action(
|
788 |
return false;
|
789 |
}
|
790 |
|
791 |
// Check if WordPress is too old
|
792 |
global $wp_version;
|
793 |
if (version_compare($wp_version, self::MIN_WP_VERSION, '<')) {
|
794 |
-
add_action(
|
795 |
return false;
|
796 |
}
|
797 |
return true;
|
@@ -804,9 +698,12 @@ function edOpenPostSnippets(myField) {
|
|
804 |
{
|
805 |
echo '<div class="error"><p><strong>';
|
806 |
printf(
|
807 |
-
'Error:
|
808 |
'Your installed PHP version: %2$s',
|
809 |
-
self::MIN_PHP_VERSION,
|
|
|
|
|
|
|
810 |
echo '</strong></p></div>';
|
811 |
}
|
812 |
|
@@ -817,10 +714,23 @@ function edOpenPostSnippets(myField) {
|
|
817 |
{
|
818 |
echo '<div class="error"><p><strong>';
|
819 |
printf(
|
820 |
-
'Error:
|
821 |
-
self::MIN_WP_VERSION
|
|
|
|
|
822 |
echo '</strong></p></div>';
|
823 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
824 |
}
|
825 |
|
826 |
add_action('plugins_loaded', array('PostSnippets', 'getInstance'));
|
@@ -833,18 +743,18 @@ add_action('plugins_loaded', array('PostSnippets', 'getInstance'));
|
|
833 |
* Allow snippets to be retrieved directly from PHP.
|
834 |
* This function is a wrapper for Post_Snippets::get_snippet().
|
835 |
*
|
836 |
-
* @since
|
837 |
* @deprecated Post Snippets 2.1
|
838 |
*
|
839 |
-
* @param
|
840 |
-
*
|
841 |
-
* @param
|
842 |
-
*
|
843 |
-
* @return
|
844 |
-
*
|
845 |
*/
|
846 |
function get_post_snippet($snippet_name, $snippet_vars = '')
|
847 |
{
|
848 |
-
|
849 |
-
|
850 |
}
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Post Snippets
|
4 |
+
Plugin URI: http://johansteen.se/code/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 |
Author: Johan Steen
|
7 |
Author URI: http://johansteen.se/
|
8 |
+
Version: 2.2
|
9 |
License: GPLv2 or later
|
10 |
Text Domain: post-snippets
|
11 |
|
30 |
spl_autoload_register('PostSnippets::autoload');
|
31 |
|
32 |
/**
|
33 |
+
* Init Singleton Class.
|
34 |
*
|
|
|
35 |
* @author Johan Steen <artstorm at gmail dot com>
|
36 |
+
* @link http://johansteen.se/
|
37 |
*/
|
38 |
class PostSnippets
|
39 |
{
|
40 |
private static $instance = false;
|
41 |
|
42 |
+
const MIN_PHP_VERSION = '5.2.4';
|
43 |
+
const MIN_WP_VERSION = '3.3';
|
44 |
+
const OPTION_KEY = 'post_snippets_options';
|
45 |
+
const USER_META_KEY = 'post_snippets';
|
46 |
+
const TINYMCE_PLUGIN_NAME = 'post_snippets';
|
47 |
+
const TEXT_DOMAIN = 'post-snippets';
|
48 |
+
const FILE = __FILE__;
|
49 |
|
50 |
/**
|
51 |
* Singleton class
|
59 |
}
|
60 |
|
61 |
/**
|
62 |
+
* Initializes the plugin.
|
|
|
|
|
63 |
*/
|
64 |
+
private function __construct()
|
65 |
+
{
|
66 |
if (!$this->testHost()) {
|
67 |
return;
|
68 |
}
|
70 |
add_action('init', array($this, 'textDomain'));
|
71 |
register_uninstall_hook(__FILE__, array(__CLASS__, 'uninstall'));
|
72 |
|
73 |
+
// Add TinyMCE button
|
74 |
+
add_action('init', array(&$this, 'addTinymceButton'));
|
75 |
+
|
76 |
+
// Settings link on plugins list
|
77 |
+
add_filter('plugin_action_links', array(&$this, 'actionLinks'), 10, 2);
|
78 |
+
// Options Page
|
79 |
+
add_action('admin_menu', array(&$this,'wpAdmin'));
|
80 |
+
|
81 |
+
$this->createShortcodes();
|
82 |
+
|
83 |
+
// Adds the JS and HTML code in the header and footer for the jQuery
|
84 |
+
// insert UI dialog in the editor
|
85 |
+
add_action('admin_init', array(&$this,'enqueueAssets'));
|
86 |
+
add_action('admin_head', array(&$this,'jqueryUiDialog'));
|
87 |
+
add_action('admin_footer', array(&$this,'addJqueryUiDialog'));
|
88 |
+
|
89 |
+
// Add Editor QuickTag button:
|
90 |
+
add_action(
|
91 |
+
'admin_print_footer_scripts',
|
92 |
+
array(&$this,'addQuicktagButton'),
|
93 |
+
100
|
94 |
+
);
|
95 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
/**
|
98 |
* PSR-0 compliant autoloader to load classes as needed.
|
99 |
*
|
|
|
|
|
100 |
* @param string $classname The name of the class
|
101 |
* @return null Return early if the class name does not start with the
|
102 |
* correct prefix
|
103 |
*/
|
104 |
public static function autoload($className)
|
105 |
{
|
106 |
+
if (__CLASS__ !== mb_substr($className, 0, strlen(__CLASS__))) {
|
107 |
return;
|
108 |
}
|
109 |
$className = ltrim($className, '\\');
|
122 |
}
|
123 |
|
124 |
/**
|
125 |
+
* Loads the plugin text domain for translation
|
126 |
*/
|
127 |
public function textDomain()
|
128 |
{
|
129 |
+
$domain = self::TEXT_DOMAIN;
|
130 |
$locale = apply_filters('plugin_locale', get_locale(), $domain);
|
131 |
load_textdomain(
|
132 |
$domain,
|
144 |
*/
|
145 |
public function uninstall()
|
146 |
{
|
147 |
+
// Delete all snippets
|
148 |
+
delete_option('post_snippets_options');
|
149 |
+
|
150 |
+
// Delete any per user settings
|
151 |
+
global $wpdb;
|
152 |
+
$wpdb->query(
|
153 |
+
"
|
154 |
+
DELETE FROM $wpdb->usermeta
|
155 |
+
WHERE meta_key = 'post_snippets'
|
156 |
+
"
|
157 |
+
);
|
158 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
+
/**
|
161 |
+
* Quick link to the Post Snippets Settings page from the Plugins page.
|
162 |
+
*
|
163 |
+
* @return Array with all the plugin's action links
|
164 |
+
*/
|
165 |
+
public function actionLinks($links, $file)
|
166 |
+
{
|
167 |
+
if ($file == plugin_basename(dirname(__FILE__).'/post-snippets.php')) {
|
168 |
+
$links[] = '<a href="options-general.php?page=post-snippets/post-snippets.php">'.__('Settings', PostSnippets::TEXT_DOMAIN).'</a>';
|
169 |
+
}
|
170 |
+
return $links;
|
171 |
+
}
|
172 |
+
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Enqueues the necessary scripts and styles for the plugins
|
176 |
+
*
|
177 |
+
* @since Post Snippets 1.7
|
178 |
+
*/
|
179 |
+
public function enqueueAssets()
|
180 |
+
{
|
181 |
+
wp_enqueue_script('jquery-ui-dialog');
|
182 |
+
wp_enqueue_script('jquery-ui-tabs');
|
183 |
+
wp_enqueue_style('wp-jquery-ui-dialog');
|
184 |
+
|
185 |
+
# Adds the CSS stylesheet for the jQuery UI dialog
|
186 |
+
$style_url = plugins_url('/assets/post-snippets.css', __FILE__);
|
187 |
+
wp_register_style('post-snippets', $style_url, false, '2.0');
|
188 |
+
wp_enqueue_style('post-snippets');
|
189 |
+
}
|
190 |
+
|
191 |
+
|
192 |
+
// -------------------------------------------------------------------------
|
193 |
+
// WordPress Editor Buttons
|
194 |
+
// -------------------------------------------------------------------------
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Add TinyMCE button.
|
198 |
+
*
|
199 |
+
* Adds filters to add custom buttons to the TinyMCE editor (Visual Editor)
|
200 |
+
* in WordPress.
|
201 |
+
*
|
202 |
+
* @since Post Snippets 1.8.7
|
203 |
+
*/
|
204 |
+
public function addTinymceButton()
|
205 |
+
{
|
206 |
+
// Don't bother doing this stuff if the current user lacks permissions
|
207 |
+
if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
|
208 |
+
return;
|
209 |
+
}
|
210 |
+
|
211 |
+
// Add only in Rich Editor mode
|
212 |
+
if (get_user_option('rich_editing') == 'true') {
|
213 |
+
add_filter(
|
214 |
+
'mce_external_plugins',
|
215 |
+
array(&$this, 'registerTinymcePlugin')
|
216 |
+
);
|
217 |
+
add_filter(
|
218 |
+
'mce_buttons',
|
219 |
+
array(&$this, 'registerTinymceButton')
|
220 |
+
);
|
221 |
+
}
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Register TinyMCE button.
|
226 |
+
*
|
227 |
+
* Pushes the custom TinyMCE button into the array of with button names.
|
228 |
+
* 'separator' or '|' can be pushed to the array as well. See the link
|
229 |
+
* for all available TinyMCE controls.
|
230 |
+
*
|
231 |
+
* @see wp-includes/class-wp-editor.php
|
232 |
+
* @link http://www.tinymce.com/wiki.php/Buttons/controls
|
233 |
+
* @since Post Snippets 1.8.7
|
234 |
+
*
|
235 |
+
* @param array $buttons Filter supplied array of buttons to modify
|
236 |
+
* @return array The modified array with buttons
|
237 |
+
*/
|
238 |
+
public function registerTinymceButton($buttons)
|
239 |
+
{
|
240 |
+
array_push($buttons, 'separator', self::TINYMCE_PLUGIN_NAME);
|
241 |
+
return $buttons;
|
242 |
+
}
|
243 |
+
|
244 |
+
/**
|
245 |
+
* Register TinyMCE plugin.
|
246 |
+
*
|
247 |
+
* Adds the absolute URL for the TinyMCE plugin to the associative array of
|
248 |
+
* plugins. Array structure: 'plugin_name' => 'plugin_url'
|
249 |
+
*
|
250 |
+
* @see wp-includes/class-wp-editor.php
|
251 |
+
* @since Post Snippets 1.8.7
|
252 |
+
*
|
253 |
+
* @param array $plugins Filter supplied array of plugins to modify
|
254 |
+
* @return array The modified array with plugins
|
255 |
+
*/
|
256 |
+
public function registerTinymcePlugin($plugins)
|
257 |
+
{
|
258 |
+
// Load the TinyMCE plugin, editor_plugin.js, into the array
|
259 |
+
$plugins[self::TINYMCE_PLUGIN_NAME] =
|
260 |
+
plugins_url('/tinymce/editor_plugin.js?ver=1.9', __FILE__);
|
261 |
+
|
262 |
+
return $plugins;
|
263 |
+
}
|
264 |
+
|
265 |
+
/**
|
266 |
+
* Adds a QuickTag button to the HTML editor.
|
267 |
+
*
|
268 |
+
* Compatible with WordPress 3.3 and newer.
|
269 |
+
*
|
270 |
+
* @see wp-includes/js/quicktags.dev.js -> qt.addButton()
|
271 |
+
* @since Post Snippets 1.8.6
|
272 |
+
*/
|
273 |
+
public function addQuicktagButton()
|
274 |
+
{
|
275 |
+
// Only run the function on post edit screens
|
276 |
+
if (function_exists('get_current_screen')) {
|
277 |
+
$screen = get_current_screen();
|
278 |
+
if ($screen->base != 'post') {
|
279 |
+
return;
|
280 |
+
}
|
281 |
+
}
|
282 |
+
|
283 |
+
echo "\n<!-- START: Add QuickTag button for Post Snippets -->\n";
|
284 |
+
?>
|
285 |
+
<script type="text/javascript" charset="utf-8">
|
286 |
+
QTags.addButton( 'post_snippets_id', 'Post Snippets', qt_post_snippets );
|
287 |
+
function qt_post_snippets() {
|
288 |
+
post_snippets_caller = 'html';
|
289 |
+
jQuery( "#post-snippets-dialog" ).dialog( "open" );
|
290 |
+
}
|
291 |
+
</script>
|
292 |
+
<?php
|
293 |
+
echo "\n<!-- END: Add QuickTag button for Post Snippets -->\n";
|
294 |
+
}
|
295 |
+
|
296 |
+
// -------------------------------------------------------------------------
|
297 |
+
// JavaScript / jQuery handling for the post editor
|
298 |
+
// -------------------------------------------------------------------------
|
299 |
+
|
300 |
+
/**
|
301 |
+
* jQuery control for the dialog and Javascript needed to insert snippets into the editor
|
302 |
+
*
|
303 |
+
* @since Post Snippets 1.7
|
304 |
+
*/
|
305 |
+
public function jqueryUiDialog()
|
306 |
+
{
|
307 |
+
// Only run the function on post edit screens
|
308 |
+
if (function_exists('get_current_screen')) {
|
309 |
+
$screen = get_current_screen();
|
310 |
+
if ($screen->base != 'post') {
|
311 |
+
return;
|
312 |
+
}
|
313 |
+
}
|
314 |
+
|
315 |
+
echo "\n<!-- START: Post Snippets jQuery UI and related functions -->\n";
|
316 |
+
echo "<script type='text/javascript'>\n";
|
317 |
+
|
318 |
+
# Prepare the snippets and shortcodes into javascript variables
|
319 |
+
# so they can be inserted into the editor, and get the variables replaced
|
320 |
+
# with user defined strings.
|
321 |
+
$snippets = get_option(self::OPTION_KEY, array());
|
322 |
+
foreach ($snippets as $key => $snippet) {
|
323 |
+
if ($snippet['shortcode']) {
|
324 |
+
# Build a long string of the variables, ie: varname1={varname1} varname2={varname2}
|
325 |
+
# so {varnameX} can be replaced at runtime.
|
326 |
+
$var_arr = explode(",", $snippet['vars']);
|
327 |
+
$variables = '';
|
328 |
+
if (!empty($var_arr[0])) {
|
329 |
+
foreach ($var_arr as $var) {
|
330 |
+
// '[test2 yet="{yet}" mupp=per="{mupp=per}" content="{content}"]';
|
331 |
+
$var = $this->stripDefaultVal($var);
|
332 |
+
|
333 |
+
$variables .= ' ' . $var . '="{' . $var . '}"';
|
334 |
+
}
|
335 |
+
}
|
336 |
+
$shortcode = $snippet['title'] . $variables;
|
337 |
+
echo "var postsnippet_{$key} = '[" . $shortcode . "]';\n";
|
338 |
+
} else {
|
339 |
+
// To use $snippet is probably not a good naming convention here.
|
340 |
+
// rename to js_snippet or something?
|
341 |
+
$snippet = $snippet['snippet'];
|
342 |
+
# Fixes for potential collisions:
|
343 |
+
/* Replace <> with char codes, otherwise </script> in a snippet will break it */
|
344 |
+
$snippet = str_replace('<', '\x3C', str_replace('>', '\x3E', $snippet));
|
345 |
+
/* Escape " with \" */
|
346 |
+
$snippet = str_replace('"', '\"', $snippet);
|
347 |
+
/* Remove CR and replace LF with \n to keep formatting */
|
348 |
+
$snippet = str_replace(chr(13), '', str_replace(chr(10), '\n', $snippet));
|
349 |
+
# Print out the variable containing the snippet
|
350 |
+
echo "var postsnippet_{$key} = \"" . $snippet . "\";\n";
|
351 |
+
}
|
352 |
+
}
|
353 |
+
?>
|
354 |
+
|
355 |
+
jQuery(document).ready(function($){
|
356 |
+
<?php
|
357 |
+
# Create js variables for all form fields
|
358 |
+
foreach ($snippets as $key => $snippet) {
|
359 |
+
$var_arr = explode(",", $snippet['vars']);
|
360 |
+
if (!empty($var_arr[0])) {
|
361 |
+
foreach ($var_arr as $key_2 => $var) {
|
362 |
+
$varname = "var_" . $key . "_" . $key_2;
|
363 |
+
echo "var {$varname} = $( \"#{$varname}\" );\n";
|
364 |
+
}
|
365 |
+
}
|
366 |
+
}
|
367 |
+
?>
|
368 |
+
|
369 |
+
var $tabs = $("#post-snippets-tabs").tabs();
|
370 |
+
|
371 |
+
$(function() {
|
372 |
+
$( "#post-snippets-dialog" ).dialog({
|
373 |
+
autoOpen: false,
|
374 |
+
modal: true,
|
375 |
+
dialogClass: 'wp-dialog',
|
376 |
+
buttons: {
|
377 |
+
Cancel: function() {
|
378 |
+
$( this ).dialog( "close" );
|
379 |
+
},
|
380 |
+
"Insert": function() {
|
381 |
+
$( this ).dialog( "close" );
|
382 |
+
var selected = $tabs.tabs('option', 'selected');
|
383 |
+
<?php
|
384 |
+
foreach ($snippets as $key => $snippet) {
|
385 |
+
?>
|
386 |
+
if (selected == <?php echo $key; ?>) {
|
387 |
+
insert_snippet = postsnippet_<?php echo $key; ?>;
|
388 |
+
<?php
|
389 |
+
$var_arr = explode(",", $snippet['vars']);
|
390 |
+
if (!empty($var_arr[0])) {
|
391 |
+
foreach ($var_arr as $key_2 => $var) {
|
392 |
+
$varname = "var_" . $key . "_" . $key_2; ?>
|
393 |
+
insert_snippet = insert_snippet.replace(/\{<?php
|
394 |
+
echo $this->stripDefaultVal($var);
|
395 |
+
?>\}/g, <?php echo $varname; ?>.val());
|
396 |
+
<?php
|
397 |
+
echo "\n";
|
398 |
+
}
|
399 |
+
}
|
400 |
+
?>
|
401 |
+
}
|
402 |
+
<?php
|
403 |
+
}
|
404 |
+
?>
|
405 |
+
|
406 |
+
// Decide what method to use to insert the snippet depending
|
407 |
+
// from what editor the window was opened from
|
408 |
+
if (post_snippets_caller == 'html') {
|
409 |
+
// HTML editor in WordPress 3.3 and greater
|
410 |
+
QTags.insertContent(insert_snippet);
|
411 |
+
} else if (post_snippets_caller == 'html_pre33') {
|
412 |
+
// HTML editor in WordPress below 3.3.
|
413 |
+
edInsertContent(post_snippets_canvas, insert_snippet);
|
414 |
+
} else {
|
415 |
+
// Visual Editor
|
416 |
+
post_snippets_canvas.execCommand('mceInsertContent', false, insert_snippet);
|
417 |
+
}
|
418 |
+
|
419 |
+
}
|
420 |
+
},
|
421 |
+
width: 500,
|
422 |
+
});
|
423 |
+
});
|
424 |
+
});
|
425 |
+
|
426 |
+
// Global variables to keep track on the canvas instance and from what editor
|
427 |
+
// that opened the Post Snippets popup.
|
428 |
+
var post_snippets_canvas;
|
429 |
+
var post_snippets_caller = '';
|
430 |
+
|
431 |
+
<?php
|
432 |
+
echo "</script>\n";
|
433 |
+
echo "\n<!-- END: Post Snippets jQuery UI and related functions -->\n";
|
434 |
+
}
|
435 |
+
|
436 |
+
/**
|
437 |
+
* Build jQuery UI Window.
|
438 |
+
*
|
439 |
+
* Creates the jQuery for Post Editor popup window, its snippet tabs and the
|
440 |
+
* form fields to enter variables.
|
441 |
+
*
|
442 |
+
* @since Post Snippets 1.7
|
443 |
+
*/
|
444 |
+
public function addJqueryUiDialog()
|
445 |
+
{
|
446 |
+
// Only run the function on post edit screens
|
447 |
+
if (function_exists('get_current_screen')) {
|
448 |
+
$screen = get_current_screen();
|
449 |
+
if ($screen->base != 'post') {
|
450 |
+
return;
|
451 |
+
}
|
452 |
+
}
|
453 |
+
|
454 |
+
$data = array('snippets' => get_option(self::OPTION_KEY, array()));
|
455 |
+
echo PostSnippets_View::render('jquery-ui-dialog', $data);
|
456 |
+
}
|
457 |
+
|
458 |
+
/**
|
459 |
+
* Strip Default Value.
|
460 |
+
*
|
461 |
+
* Checks if a variable string contains a default value, and if it does it
|
462 |
+
* will strip it away and return the string with only the variable name
|
463 |
+
* kept.
|
464 |
+
*
|
465 |
+
* @since Post Snippets 1.9.3
|
466 |
+
* @param string $variable The variable to check for default value
|
467 |
+
* @return string The variable without any default value
|
468 |
+
*/
|
469 |
+
public function stripDefaultVal($variable)
|
470 |
+
{
|
471 |
+
// Check if variable contains a default defintion
|
472 |
+
$def_pos = strpos($variable, '=');
|
473 |
+
|
474 |
+
if ($def_pos !== false) {
|
475 |
+
$split = str_split($variable, $def_pos);
|
476 |
+
$variable = $split[0];
|
477 |
+
}
|
478 |
+
return $variable;
|
479 |
+
}
|
480 |
+
|
481 |
+
// -------------------------------------------------------------------------
|
482 |
+
// Shortcode
|
483 |
+
// -------------------------------------------------------------------------
|
484 |
+
|
485 |
+
/**
|
486 |
+
* Create the functions for shortcodes dynamically and register them
|
487 |
+
*/
|
488 |
+
public function createShortcodes()
|
489 |
+
{
|
490 |
+
$snippets = get_option(self::OPTION_KEY);
|
491 |
+
if (!empty($snippets)) {
|
492 |
+
foreach ($snippets as $snippet) {
|
493 |
+
// If shortcode is enabled for the snippet, and a snippet has been entered, register it as a shortcode.
|
494 |
+
if ($snippet['shortcode'] && !empty($snippet['snippet'])) {
|
495 |
+
|
496 |
+
$vars = explode(",", $snippet['vars']);
|
497 |
+
$vars_str = "";
|
498 |
+
foreach ($vars as $var) {
|
499 |
+
$attribute = explode('=', $var);
|
500 |
+
$default_value = (count($attribute) > 1) ? $attribute[1] : '';
|
501 |
+
$vars_str .= "\"{$attribute[0]}\" => \"{$default_value}\",";
|
502 |
+
}
|
503 |
+
|
504 |
+
// Get the wptexturize setting
|
505 |
+
$texturize = isset( $snippet["wptexturize"] ) ? $snippet["wptexturize"] : false;
|
506 |
+
|
507 |
+
add_shortcode(
|
508 |
+
$snippet['title'],
|
509 |
+
create_function(
|
510 |
+
'$atts,$content=null',
|
511 |
+
'$shortcode_symbols = array('.$vars_str.');
|
512 |
+
extract(shortcode_atts($shortcode_symbols, $atts));
|
513 |
+
|
514 |
+
$attributes = compact( array_keys($shortcode_symbols) );
|
515 |
+
|
516 |
+
// Add enclosed content if available to the attributes array
|
517 |
+
if ( $content != null )
|
518 |
+
$attributes["content"] = $content;
|
519 |
+
|
520 |
+
|
521 |
+
$snippet = \''. addslashes($snippet["snippet"]) .'\';
|
522 |
+
// Disables auto conversion from & to & as that should be done in snippet, not code (destroys php etc).
|
523 |
+
// $snippet = str_replace("&", "&", $snippet);
|
524 |
+
|
525 |
+
foreach ($attributes as $key => $val) {
|
526 |
+
$snippet = str_replace("{".$key."}", $val, $snippet);
|
527 |
+
}
|
528 |
+
|
529 |
+
// Handle PHP shortcodes
|
530 |
+
$php = "'. $snippet["php"] .'";
|
531 |
+
if ($php == true) {
|
532 |
+
$snippet = PostSnippets::phpEval( $snippet );
|
533 |
+
}
|
534 |
+
|
535 |
+
// Strip escaping and execute nested shortcodes
|
536 |
+
$snippet = do_shortcode(stripslashes($snippet));
|
537 |
+
|
538 |
+
// WPTexturize the Snippet
|
539 |
+
$texturize = "'. $texturize .'";
|
540 |
+
if ($texturize == true) {
|
541 |
+
$snippet = wptexturize( $snippet );
|
542 |
+
}
|
543 |
+
|
544 |
+
return $snippet;'
|
545 |
+
)
|
546 |
+
);
|
547 |
+
}
|
548 |
+
}
|
549 |
+
}
|
550 |
+
}
|
551 |
+
|
552 |
+
/**
|
553 |
+
* Evaluate a snippet as PHP code.
|
554 |
+
*
|
555 |
+
* @since Post Snippets 1.9
|
556 |
+
* @param string $content The snippet to evaluate
|
557 |
+
* @return string The result of the evaluation
|
558 |
+
*/
|
559 |
+
public static function phpEval($content)
|
560 |
+
{
|
561 |
+
if (!self::canExecutePHP()) {
|
562 |
+
return $content;
|
563 |
+
}
|
564 |
+
|
565 |
+
$content = stripslashes($content);
|
566 |
+
|
567 |
+
ob_start();
|
568 |
+
eval ($content);
|
569 |
+
$content = ob_get_clean();
|
570 |
+
|
571 |
+
return addslashes($content);
|
572 |
+
}
|
573 |
+
|
574 |
+
|
575 |
+
// -------------------------------------------------------------------------
|
576 |
+
// Admin
|
577 |
+
// -------------------------------------------------------------------------
|
578 |
+
|
579 |
+
/**
|
580 |
+
* The Admin Page.
|
581 |
+
*/
|
582 |
+
public function wpAdmin()
|
583 |
+
{
|
584 |
+
if (current_user_can('manage_options')) {
|
585 |
+
// If user can manage options, display the admin page
|
586 |
+
$option_page = add_options_page('Post Snippets Options', 'Post Snippets', 'administrator', __FILE__, array(&$this, 'optionsPage'));
|
587 |
+
if ($option_page and class_exists('PostSnippets_Help')) {
|
588 |
+
$help = new PostSnippets_Help($option_page);
|
589 |
+
}
|
590 |
+
} else {
|
591 |
+
// If user can't manage options, but can edit posts, display the overview page
|
592 |
+
$option_page = add_options_page('Post Snippets', 'Post Snippets', 'edit_posts', __FILE__, array(&$this, 'overviewPage'));
|
593 |
+
}
|
594 |
+
}
|
595 |
+
|
596 |
+
/**
|
597 |
+
* The options Overview page.
|
598 |
+
*
|
599 |
+
* For users without manage_options cap but with edit_posts cap. A read-only
|
600 |
+
* view.
|
601 |
+
*
|
602 |
+
* @since Post Snippets 1.9.7
|
603 |
+
*/
|
604 |
+
public function overviewPage()
|
605 |
+
{
|
606 |
+
$settings = new PostSnippets_Admin();
|
607 |
+
$settings->render('overview');
|
608 |
+
}
|
609 |
+
|
610 |
+
/**
|
611 |
+
* The options Admin page.
|
612 |
+
*
|
613 |
+
* For users with manage_options capability.
|
614 |
+
*/
|
615 |
+
public function optionsPage()
|
616 |
+
{
|
617 |
+
$settings = new PostSnippets_Admin();
|
618 |
+
$settings->render('options');
|
619 |
+
}
|
620 |
+
|
621 |
+
|
622 |
+
// -------------------------------------------------------------------------
|
623 |
+
// Helpers
|
624 |
+
// -------------------------------------------------------------------------
|
625 |
+
|
626 |
+
/**
|
627 |
+
* Allow snippets to be retrieved directly from PHP.
|
628 |
+
*
|
629 |
+
* @since Post Snippets 1.8.9.1
|
630 |
+
*
|
631 |
+
* @param string $snippet_name
|
632 |
+
* The name of the snippet to retrieve
|
633 |
+
* @param string $snippet_vars
|
634 |
+
* The variables to pass to the snippet, formatted as a query string.
|
635 |
+
* @return string
|
636 |
+
* The Snippet
|
637 |
+
*/
|
638 |
+
public static function getSnippet($snippet_name, $snippet_vars = '')
|
639 |
+
{
|
640 |
+
$snippets = get_option(self::OPTION_KEY, array());
|
641 |
+
for ($i = 0; $i < count($snippets); $i++) {
|
642 |
+
if ($snippets[$i]['title'] == $snippet_name) {
|
643 |
+
parse_str(htmlspecialchars_decode($snippet_vars), $snippet_output);
|
644 |
+
$snippet = $snippets[$i]['snippet'];
|
645 |
+
$var_arr = explode(",", $snippets[$i]['vars']);
|
646 |
+
|
647 |
+
if (!empty($var_arr[0])) {
|
648 |
+
for ($j = 0; $j < count($var_arr); $j++) {
|
649 |
+
$snippet = str_replace("{".$var_arr[$j]."}", $snippet_output[$var_arr[$j]], $snippet);
|
650 |
+
}
|
651 |
+
}
|
652 |
+
}
|
653 |
+
}
|
654 |
+
return do_shortcode($snippet);
|
655 |
+
}
|
656 |
+
|
657 |
+
/**
|
658 |
+
* Allow other plugins to disable the PHP Code execution feature.
|
659 |
+
*
|
660 |
+
* @see http://wordpress.org/extend/plugins/post-snippets/faq/
|
661 |
+
* @since 2.1
|
662 |
+
*/
|
663 |
+
public static function canExecutePHP()
|
664 |
+
{
|
665 |
+
return apply_filters('post_snippets_php_execution_enabled', true);
|
666 |
+
}
|
667 |
|
668 |
|
669 |
// -------------------------------------------------------------------------
|
678 |
// Check if PHP is too old
|
679 |
if (version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '<')) {
|
680 |
// Display notice
|
681 |
+
add_action('admin_notices', array(&$this, 'phpVersionError'));
|
682 |
return false;
|
683 |
}
|
684 |
|
685 |
// Check if WordPress is too old
|
686 |
global $wp_version;
|
687 |
if (version_compare($wp_version, self::MIN_WP_VERSION, '<')) {
|
688 |
+
add_action('admin_notices', array(&$this, 'wpVersionError'));
|
689 |
return false;
|
690 |
}
|
691 |
return true;
|
698 |
{
|
699 |
echo '<div class="error"><p><strong>';
|
700 |
printf(
|
701 |
+
'Error: %3$s requires PHP version %1$s or greater.<br/>'.
|
702 |
'Your installed PHP version: %2$s',
|
703 |
+
self::MIN_PHP_VERSION,
|
704 |
+
PHP_VERSION,
|
705 |
+
$this->getPluginName()
|
706 |
+
);
|
707 |
echo '</strong></p></div>';
|
708 |
}
|
709 |
|
714 |
{
|
715 |
echo '<div class="error"><p><strong>';
|
716 |
printf(
|
717 |
+
'Error: %2$s requires WordPress version %1$s or greater.',
|
718 |
+
self::MIN_WP_VERSION,
|
719 |
+
$this->getPluginName()
|
720 |
+
);
|
721 |
echo '</strong></p></div>';
|
722 |
}
|
723 |
+
|
724 |
+
/**
|
725 |
+
* Get the name of this plugin.
|
726 |
+
*
|
727 |
+
* @return string The plugin name.
|
728 |
+
*/
|
729 |
+
private function getPluginName()
|
730 |
+
{
|
731 |
+
$data = get_plugin_data(self::FILE);
|
732 |
+
return $data['Name'];
|
733 |
+
}
|
734 |
}
|
735 |
|
736 |
add_action('plugins_loaded', array('PostSnippets', 'getInstance'));
|
743 |
* Allow snippets to be retrieved directly from PHP.
|
744 |
* This function is a wrapper for Post_Snippets::get_snippet().
|
745 |
*
|
746 |
+
* @since Post Snippets 1.6
|
747 |
* @deprecated Post Snippets 2.1
|
748 |
*
|
749 |
+
* @param string $snippet_name
|
750 |
+
* The name of the snippet to retrieve
|
751 |
+
* @param string $snippet_vars
|
752 |
+
* The variables to pass to the snippet, formatted as a query string.
|
753 |
+
* @return string
|
754 |
+
* The Snippet
|
755 |
*/
|
756 |
function get_post_snippet($snippet_name, $snippet_vars = '')
|
757 |
{
|
758 |
+
_deprecated_function(__FUNCTION__, '2.1', 'PostSnippets::getSnippet()');
|
759 |
+
return PostSnippets::getSnippet($snippet_name, $snippet_vars);
|
760 |
}
|
readme.txt
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
=== Post Snippets ===
|
2 |
Contributors: artstorm
|
|
|
3 |
Tags: post, admin, snippet, shortcode, html, custom, page, dynamic, editor, php, code
|
4 |
-
Requires at least: 3.
|
5 |
Tested up to: 3.5.1
|
6 |
-
Stable tag: 2.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -37,23 +38,20 @@ updating the snippet. PHP code is supported for snippets inserted as shortcodes.
|
|
37 |
|
38 |
= Related Links =
|
39 |
|
40 |
-
* [Documentation](http://
|
41 |
-
"
|
42 |
-
* [Support Forum](http://wordpress.org/
|
43 |
"Use this for support and feature requests")
|
44 |
-
* [GitHub](https://github.com/artstorm/post-snippets
|
45 |
"Develop and contribute your code or report bugs")
|
46 |
|
47 |
-
See the [Changelog](http://wordpress.org/extend/plugins/post-snippets/changelog/)
|
48 |
-
for what's new. Available [Translations](http://wpstorm.net/wordpress-plugins/post-snippets/#translations).
|
49 |
-
|
50 |
|
51 |
== Installation ==
|
52 |
|
53 |
= Requirements =
|
54 |
|
55 |
* PHP version 5.2.4 or greater.
|
56 |
-
* WordPress version 3.
|
57 |
|
58 |
= Install =
|
59 |
|
@@ -119,6 +117,14 @@ Contributions are appreciated and encouraged.
|
|
119 |
|
120 |
== Changelog ==
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
= Version 2.1.1 - 23 Feb 2013 =
|
123 |
* Fixes a bug that PHP snippets called an old class definition.
|
124 |
|
@@ -399,3 +405,6 @@ replaces the old function. `get_post_snippet()` will be removed in a future
|
|
399 |
version.
|
400 |
|
401 |
Most users are not affected by this change.
|
|
|
|
|
|
1 |
=== Post Snippets ===
|
2 |
Contributors: artstorm
|
3 |
+
Donate link: http://johansteen.se/donate/
|
4 |
Tags: post, admin, snippet, shortcode, html, custom, page, dynamic, editor, php, code
|
5 |
+
Requires at least: 3.3
|
6 |
Tested up to: 3.5.1
|
7 |
+
Stable tag: 2.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
38 |
|
39 |
= Related Links =
|
40 |
|
41 |
+
* [Documentation](http://johansteen.se/code/post-snippets/
|
42 |
+
"Usage instructions")
|
43 |
+
* [Support Forum](http://wordpress.org/support/plugin/post-snippets
|
44 |
"Use this for support and feature requests")
|
45 |
+
* [GitHub](https://github.com/artstorm/post-snippets
|
46 |
"Develop and contribute your code or report bugs")
|
47 |
|
|
|
|
|
|
|
48 |
|
49 |
== Installation ==
|
50 |
|
51 |
= Requirements =
|
52 |
|
53 |
* PHP version 5.2.4 or greater.
|
54 |
+
* WordPress version 3.3 or greater.
|
55 |
|
56 |
= Install =
|
57 |
|
117 |
|
118 |
== Changelog ==
|
119 |
|
120 |
+
= Version 2.2 - 26 Apr 2013 =
|
121 |
+
* Bumps required WordPress version to v3.3.
|
122 |
+
* Fixes a problem with using some HTML entities in snippets.
|
123 |
+
* Removes the screenshots from the plugin archive, to make a smaller archive.
|
124 |
+
* Updates help text for `PostSnippets::getSnippet()`.
|
125 |
+
* Fixes a PHP warning that occurred when no post snippets exist.
|
126 |
+
* Makes the plugin PSR-2 compliant and introduces Travis CI for testing.
|
127 |
+
|
128 |
= Version 2.1.1 - 23 Feb 2013 =
|
129 |
* Fixes a bug that PHP snippets called an old class definition.
|
130 |
|
405 |
version.
|
406 |
|
407 |
Most users are not affected by this change.
|
408 |
+
|
409 |
+
= 2.2 =
|
410 |
+
Note that at least WordPress v3.3 are required for Post Snippets v2.2.
|
screenshot-1.jpg
DELETED
Binary file
|
screenshot-2.jpg
DELETED
Binary file
|
screenshot-3.jpg
DELETED
Binary file
|
screenshot-4.jpg
DELETED
Binary file
|
unittest/PostSnippetsTest.php
DELETED
@@ -1,66 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Post Snippets Unit Tests.
|
4 |
-
*/
|
5 |
-
class PostSnippetsTest extends WP_UnitTestCase {
|
6 |
-
|
7 |
-
private $plugin = 'post-snippets';
|
8 |
-
|
9 |
-
public function setUp()
|
10 |
-
{
|
11 |
-
parent::setUp();
|
12 |
-
|
13 |
-
$snippets = array();
|
14 |
-
array_push($snippets, array(
|
15 |
-
'title' => "TestTmp",
|
16 |
-
'vars' => "",
|
17 |
-
'description' => "",
|
18 |
-
'shortcode' => false,
|
19 |
-
'php' => false,
|
20 |
-
'snippet' => "A test snippet..."));
|
21 |
-
update_option('post_snippets_options', $snippets);
|
22 |
-
}
|
23 |
-
|
24 |
-
// -------------------------------------------------------------------------
|
25 |
-
// Tests
|
26 |
-
// -------------------------------------------------------------------------
|
27 |
-
|
28 |
-
public function testPluginInitialization()
|
29 |
-
{
|
30 |
-
$this->assertFalse( null == $this->plugin );
|
31 |
-
}
|
32 |
-
|
33 |
-
public function teast_Yo()
|
34 |
-
{
|
35 |
-
$this->assertTrue(true);
|
36 |
-
}
|
37 |
-
|
38 |
-
public function teast_Yos()
|
39 |
-
{
|
40 |
-
$this->assertTrue(true);
|
41 |
-
}
|
42 |
-
|
43 |
-
/**
|
44 |
-
* @dataProvider provider
|
45 |
-
*/
|
46 |
-
public function teast_data_inline($a, $b, $c)
|
47 |
-
{
|
48 |
-
// var_dump($c);
|
49 |
-
}
|
50 |
-
public function praovider()
|
51 |
-
{
|
52 |
-
return array(
|
53 |
-
array(0, 0, 0),
|
54 |
-
array(0, 1, 1),
|
55 |
-
array(1, 0, 1),
|
56 |
-
array(1, 1, 3)
|
57 |
-
);
|
58 |
-
}
|
59 |
-
|
60 |
-
public function test_get_post_snippet()
|
61 |
-
{
|
62 |
-
$test = get_post_snippet('TestTmp');
|
63 |
-
$this->assertTrue(is_string($test));
|
64 |
-
$this->assertEquals($test, 'A test snippet...');
|
65 |
-
}
|
66 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unittest/bootstrap.php
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
$GLOBALS['wp_tests_options'] = array(
|
3 |
-
'active_plugins' => array( 'post-snippets/post-snippets.php' ),
|
4 |
-
'template' => 'twentyeleven',
|
5 |
-
'stylesheet' => 'twentyeleven',
|
6 |
-
);
|
7 |
-
|
8 |
-
require_once('D:/Dropbox/Code/_Tools/UniformServer/www/wordpress.dev/wordpress-tests/bootstrap.php');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
views/admin_snippets.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<form method="post" action="">
|
2 |
+
<?php wp_nonce_field('update_snippets', 'update_snippets_nonce'); ?>
|
3 |
+
|
4 |
+
<table class="widefat fixed" cellspacing="0">
|
5 |
+
<thead>
|
6 |
+
<tr>
|
7 |
+
<th scope="col" class="check-column"><input type="checkbox" /></th>
|
8 |
+
<th scope="col" style="width: 180px;"><?php _e('Title', PostSnippets::TEXT_DOMAIN); ?></th>
|
9 |
+
<th scope="col" style="width: 180px;"><?php _e('Variables', PostSnippets::TEXT_DOMAIN); ?></th>
|
10 |
+
<th scope="col"><?php _e('Snippet', PostSnippets::TEXT_DOMAIN); ?></th>
|
11 |
+
</tr>
|
12 |
+
</thead>
|
13 |
+
|
14 |
+
<tfoot>
|
15 |
+
<tr>
|
16 |
+
<th scope="col" class="check-column"><input type="checkbox" /></th>
|
17 |
+
<th scope="col"><?php _e('Title', PostSnippets::TEXT_DOMAIN) ?></th>
|
18 |
+
<th scope="col"><?php _e('Variables', PostSnippets::TEXT_DOMAIN) ?></th>
|
19 |
+
<th scope="col"><?php _e('Snippet', PostSnippets::TEXT_DOMAIN) ?></th>
|
20 |
+
</tr>
|
21 |
+
</tfoot>
|
22 |
+
|
23 |
+
<tbody>
|
24 |
+
<?php
|
25 |
+
$snippets = get_option(PostSnippets::OPTION_KEY);
|
26 |
+
if (!empty($snippets)) {
|
27 |
+
foreach ($snippets as $key => $snippet) {
|
28 |
+
?>
|
29 |
+
<tr class='recent'>
|
30 |
+
<th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='<?php echo $key; ?>' /></th>
|
31 |
+
<td class='row-title'>
|
32 |
+
<input type='text' name='<?php echo $key; ?>_title' value='<?php echo $snippet['title']; ?>' />
|
33 |
+
</td>
|
34 |
+
<td class='name'>
|
35 |
+
<input type='text' name='<?php echo $key; ?>_vars' value='<?php echo $snippet['vars']; ?>' />
|
36 |
+
<br/>
|
37 |
+
<br/>
|
38 |
+
<?php
|
39 |
+
PostSnippets_Admin::checkbox(__('Shortcode', PostSnippets::TEXT_DOMAIN), $key.'_shortcode',
|
40 |
+
$snippet['shortcode']);
|
41 |
+
|
42 |
+
echo '<br/><strong>Shortcode Options:</strong><br/>';
|
43 |
+
|
44 |
+
if (PostSnippets::canExecutePHP()) {
|
45 |
+
PostSnippets_Admin::checkbox(
|
46 |
+
__('PHP Code', PostSnippets::TEXT_DOMAIN),
|
47 |
+
$key.'_php',
|
48 |
+
$snippet['php']
|
49 |
+
);
|
50 |
+
}
|
51 |
+
|
52 |
+
$wptexturize = isset( $snippet['wptexturize'] ) ? $snippet['wptexturize'] : false;
|
53 |
+
PostSnippets_Admin::checkbox('wptexturize', $key.'_wptexturize', $wptexturize);
|
54 |
+
?>
|
55 |
+
</td>
|
56 |
+
<td class='desc'>
|
57 |
+
<textarea name="<?php echo $key; ?>_snippet" class="large-text" style='width: 100%;' rows="5"><?php echo htmlspecialchars($snippet['snippet'], ENT_NOQUOTES); ?></textarea>
|
58 |
+
<?php _e( 'Description', PostSnippets::TEXT_DOMAIN ) ?>:
|
59 |
+
<input type='text' style='width: 100%;' name='<?php echo $key; ?>_description' value='<?php if (isset( $snippet['description'] ) ) echo esc_html($snippet['description']); ?>' /><br/>
|
60 |
+
</td>
|
61 |
+
</tr>
|
62 |
+
<?php
|
63 |
+
}
|
64 |
+
}
|
65 |
+
?>
|
66 |
+
</tbody>
|
67 |
+
</table>
|
68 |
+
|
69 |
+
<?php
|
70 |
+
PostSnippets_Admin::submit('update-snippets', __('Update Snippets', PostSnippets::TEXT_DOMAIN));
|
71 |
+
PostSnippets_Admin::submit('add-snippet', __('Add New Snippet', PostSnippets::TEXT_DOMAIN), 'button-secondary', false);
|
72 |
+
PostSnippets_Admin::submit('delete-snippets', __('Delete Selected', PostSnippets::TEXT_DOMAIN), 'button-secondary', false);
|
73 |
+
echo '</form>';
|
views/help_advanced.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p>
|
2 |
+
<?php _e('You can retrieve a Post Snippet directly from PHP, in a theme for instance, by using the PostSnippets::getSnippet() method.', PostSnippets::TEXT_DOMAIN); ?>
|
3 |
+
</p>
|
4 |
+
|
5 |
+
<h2><?php _e('Usage', PostSnippets::TEXT_DOMAIN); ?></h2>
|
6 |
+
<p>
|
7 |
+
<code>
|
8 |
+
<?php $my_snippet = PostSnippets::getSnippet( $snippet_name, $snippet_vars ); ?>
|
9 |
+
</code></p>
|
10 |
+
|
11 |
+
<h2><?php _e('Parameters', PostSnippets::TEXT_DOMAIN); ?></h2>
|
12 |
+
<p>
|
13 |
+
<code>$snippet_name</code><br/>
|
14 |
+
<?php _e('(string) (required) The name of the snippet to retrieve.', PostSnippets::TEXT_DOMAIN); ?>
|
15 |
+
<br/><br/>
|
16 |
+
<code>$snippet_vars</code><br/>
|
17 |
+
<?php _e('(string) The variables to pass to the snippet, formatted as a query string.', PostSnippets::TEXT_DOMAIN); ?>
|
18 |
+
</p>
|
19 |
+
|
20 |
+
<h2><?php _e('Example', PostSnippets::TEXT_DOMAIN); ?></h2>
|
21 |
+
<p><code>
|
22 |
+
<?php<br/>
|
23 |
+
$my_snippet = PostSnippets::getSnippet( 'internal-link', 'title=Awesome&url=2011/02/awesome/' );<br/>
|
24 |
+
echo $my_snippet;<br/>
|
25 |
+
?>
|
26 |
+
</code></p>
|
views/help_basic.php
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<h2><?php _e('Title', PostSnippets::TEXT_DOMAIN); ?></h2>
|
2 |
+
<p>
|
3 |
+
<?php _e('Give the snippet a title that helps you identify it in the post editor. This also becomes the name of the shortcode if you enable that option', PostSnippets::TEXT_DOMAIN); ?>
|
4 |
+
</p>
|
5 |
+
|
6 |
+
<h2><?php _e('Variables', PostSnippets::TEXT_DOMAIN); ?></h2>
|
7 |
+
<p>
|
8 |
+
<?php _e('A comma separated list of custom variables you can reference in your snippet. A variable can also be assigned a default value that will be used in the insert window by using the equal sign, variable=default.', PostSnippets::TEXT_DOMAIN); ?>
|
9 |
+
</p>
|
10 |
+
|
11 |
+
<p>
|
12 |
+
<strong><?php _e('Example', PostSnippets::TEXT_DOMAIN); ?></strong><br/>
|
13 |
+
<code>url,name,role=user,title</code>
|
14 |
+
</p>
|
15 |
+
|
16 |
+
<h2><?php _e('Snippet', PostSnippets::TEXT_DOMAIN); ?></h2>
|
17 |
+
<p>
|
18 |
+
<?php _e('This is the block of text, HTML or PHP to insert in the post or as a shortcode. If you have entered predefined variables you can reference them from the snippet by enclosing them in {} brackets.', PostSnippets::TEXT_DOMAIN); ?>
|
19 |
+
</p>
|
20 |
+
|
21 |
+
<p><strong><?php _e('Example', PostSnippets::TEXT_DOMAIN); ?></strong><br/>
|
22 |
+
<?php _e('To reference the variables in the example above, you would enter {url} and {name}. So if you enter this snippet:', PostSnippets::TEXT_DOMAIN); ?>
|
23 |
+
<br/>
|
24 |
+
<code>This is the website of <a href="{url}">{name}</a></code>
|
25 |
+
<br/>
|
26 |
+
<?php _e('You will get the option to replace url and name on insert if they are defined as variables.', PostSnippets::TEXT_DOMAIN); ?>
|
27 |
+
</p>
|
28 |
+
|
29 |
+
<h2><?php _e('Description', PostSnippets::TEXT_DOMAIN); ?></h2>
|
30 |
+
<p>
|
31 |
+
<?php _e('An optional description for the Snippet. If filled out, the description will be displayed in the snippets insert window in the post editor.', PostSnippets::TEXT_DOMAIN); ?>
|
32 |
+
</p>
|
views/help_php.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p>
|
2 |
+
<?php _e('Snippets defined as shortcodes can optionally also be evaluated as PHP Code by enabling the PHP checkbox. PHP snippets is only available when treating the snippet as a shortcode.', PostSnippets::TEXT_DOMAIN); ?>
|
3 |
+
</p>
|
4 |
+
|
5 |
+
<p><strong><?php _e('Example PHP Snippet', PostSnippets::TEXT_DOMAIN); ?></strong><br/>
|
6 |
+
<code>
|
7 |
+
for ($i=1; $i<5; $i++) {<br/>
|
8 |
+
echo "{loop_me}<br/>";<br/>
|
9 |
+
};
|
10 |
+
</code></p>
|
11 |
+
|
12 |
+
<p>
|
13 |
+
<?php _e('With a snippet defined like the one above, you can call it with its shortcode definition in a post. Let\'s pretend that the example snippet is named phpcode and have one variable defined loop_me, then it would be called like this from a post:', PostSnippets::TEXT_DOMAIN); ?>
|
14 |
+
</p>
|
15 |
+
|
16 |
+
<code>[phpcode loop_me="post snippet with PHP!"]</code>
|
17 |
+
|
18 |
+
<p>
|
19 |
+
<?php _e('When the shortcode is executed the loop_me variable will be replaced with the string supplied in the shortcode and then the PHP code will be evaluated. (Outputting the string five times in this case. Wow!)', PostSnippets::TEXT_DOMAIN); ?>
|
20 |
+
</p>
|
21 |
+
|
22 |
+
<p>
|
23 |
+
<?php _e('Note the evaluation order, any snippet variables will be replaced before the snippet is evaluated as PHP code. Also note that a PHP snippet don\'t need to be wrapped in <?php #code; ?>.', PostSnippets::TEXT_DOMAIN); ?>
|
24 |
+
</p>
|
views/help_shortcode.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p>
|
2 |
+
<?php _e('When enabling the shortcode checkbox, the snippet is no longer inserted directly but instead inserted as a shortcode. The obvious advantage of this is of course that you can insert a block of text or code in many places on the site, and update the content from one single place.', PostSnippets::TEXT_DOMAIN); ?>
|
3 |
+
</p>
|
4 |
+
|
5 |
+
<p>
|
6 |
+
<?php _e('The name to use the shortcode is the same as the title of the snippet (spaces are not allowed). When inserting a shortcode snippet, the shortcode and not the content will be inserted in the post.', PostSnippets::TEXT_DOMAIN); ?>
|
7 |
+
</p>
|
8 |
+
|
9 |
+
<p>
|
10 |
+
<?php _e('If you enclose the shortcode in your posts, you can access the enclosed content by using the variable {content} in your snippet. The {content} variable is reserved, so don\'t use it in the variables field.', PostSnippets::TEXT_DOMAIN); ?>
|
11 |
+
</p>
|
12 |
+
|
13 |
+
<h2><?php _e('Options', PostSnippets::TEXT_DOMAIN); ?></h2>
|
14 |
+
<p><strong>PHP</strong><br/>
|
15 |
+
<?php _e('See the dedicated help section for information about PHP shortcodes.', PostSnippets::TEXT_DOMAIN); ?>
|
16 |
+
</p>
|
17 |
+
<p><strong>wptexturize</strong><br/>
|
18 |
+
<?php printf(__('Before the shortcode is outputted, it can optionally be formatted with %s, to transform quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol.', PostSnippets::TEXT_DOMAIN), '<a href="http://codex.wordpress.org/Function_Reference/wptexturize">wptexturize</a>'); ?>
|
19 |
+
</p>
|
views/help_sidebar.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p><strong>
|
2 |
+
<?php _e('For more information:', PostSnippets::TEXT_DOMAIN); ?>
|
3 |
+
</strong></p>
|
4 |
+
|
5 |
+
<p><a href="http://johansteen.se/code/post-snippets/" target="_blank"><?php
|
6 |
+
_e('Documentation', PostSnippets::TEXT_DOMAIN);
|
7 |
+
?></a></p>
|
8 |
+
|
9 |
+
<p><a href="http://wordpress.org/support/plugin/post-snippets" target="_blank"><?php
|
10 |
+
_e('Support Forums', PostSnippets::TEXT_DOMAIN);
|
11 |
+
?></a></p>
|
12 |
+
|
13 |
+
<p><a href="https://github.com/artstorm/post-snippets" target="_blank"><?php
|
14 |
+
_e('GitHub Contribution', PostSnippets::TEXT_DOMAIN);
|
15 |
+
?></a></p>
|
views/jquery-ui-dialog.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!-- START: Post Snippets UI Dialog -->
|
2 |
+
<?php // Setup the dialog divs ?>
|
3 |
+
<div class="hidden">
|
4 |
+
<div id="post-snippets-dialog" title="Post Snippets">
|
5 |
+
<?php // Init the tabs div ?>
|
6 |
+
<div id="post-snippets-tabs">
|
7 |
+
<ul>
|
8 |
+
<?php
|
9 |
+
// Create a tab for each available snippet
|
10 |
+
foreach ($snippets as $key => $snippet) { ?>
|
11 |
+
<li><a href="#ps-tabs-<?php echo $key; ?>"><?php echo $snippet['title']; ?></a></li>
|
12 |
+
<?php } ?>
|
13 |
+
</ul>
|
14 |
+
|
15 |
+
<?php
|
16 |
+
// Create a panel with form fields for each available snippet
|
17 |
+
foreach ($snippets as $key => $snippet) { ?>
|
18 |
+
<div id="ps-tabs-<?php echo $key; ?>">
|
19 |
+
<?php
|
20 |
+
// Print a snippet description is available
|
21 |
+
if (isset($snippet['description'])) { ?>
|
22 |
+
<p class="howto"><?php echo $snippet['description']; ?></p>
|
23 |
+
<?php }
|
24 |
+
|
25 |
+
// Get all variables defined for the snippet and output them as
|
26 |
+
// input fields
|
27 |
+
$var_arr = explode(',', $snippet['vars']);
|
28 |
+
if (!empty($var_arr[0])) {
|
29 |
+
foreach ($var_arr as $key_2 => $var) {
|
30 |
+
// Default value exists?
|
31 |
+
$def_pos = strpos($var, '=');
|
32 |
+
if ($def_pos !== false) {
|
33 |
+
$split = explode('=', $var);
|
34 |
+
$var = $split[0];
|
35 |
+
$def = $split[1];
|
36 |
+
} else {
|
37 |
+
$def = '';
|
38 |
+
} ?>
|
39 |
+
<label for="var_<?php echo $key.'_'.$key_2; ?>"><?php echo $var; ?>:</label>
|
40 |
+
<input type="text" id="var_<?php echo $key.'_'.$key_2; ?>" name="var_<?php echo $key.'_'.$key_2; ?>" value="<?php echo $def; ?>" style="width: 190px" />
|
41 |
+
<br/>
|
42 |
+
<?php }
|
43 |
+
} else {
|
44 |
+
// If no variables and no description available, output a text
|
45 |
+
// to inform the user that it's an insert snippet only.
|
46 |
+
if (empty($snippet['description'])) { ?>
|
47 |
+
<p class="howto"><?php _e('This snippet is insert only, no variables defined.', PostSnippets::TEXT_DOMAIN); ?></p>
|
48 |
+
<?php }
|
49 |
+
} ?>
|
50 |
+
</div><!-- #ps-tabs-<?php echo $key; ?> -->
|
51 |
+
<?php }
|
52 |
+
// Close the tabs and dialog divs ?>
|
53 |
+
</div><!-- #post-snippets-tabs -->
|
54 |
+
</div><!-- #post-snippets-dialog -->
|
55 |
+
</div><!-- .hidden -->
|
56 |
+
<!-- END: Post Snippets UI Dialog -->
|