Version Description
Download this release
Release Info
Developer | artstorm |
Plugin | Post Snippets |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- post-snippets-config.php +34 -0
- post-snippets.php +169 -0
- readme.txt +35 -0
- screenshot-1.jpg +0 -0
- screenshot-2.jpg +0 -0
- screenshot-3.jpg +0 -0
- tinymce/editor_plugin.js +64 -0
- tinymce/langs/en.js +4 -0
- tinymce/langs/en_US.js +4 -0
- tinymce/langs/en_en.js +4 -0
- tinymce/post-snippets.gif +0 -0
- tinymce/tinymce.php +59 -0
- tinymce/window.php +118 -0
- uninstall.php +8 -0
post-snippets-config.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Bootstrap file for getting the ABSPATH constant to wp-load.php
|
4 |
+
* This is requried when a plugin requires access not via the admin screen.
|
5 |
+
*
|
6 |
+
* If the wp-load.php file is not found, then an error will be displayed
|
7 |
+
*
|
8 |
+
* @package WordPress
|
9 |
+
* @since Version 2.6
|
10 |
+
*/
|
11 |
+
|
12 |
+
/** Define the server path to the file wp-config here, if you placed WP-CONTENT outside the classic file structure */
|
13 |
+
|
14 |
+
$path = ''; // It should be end with a trailing slash
|
15 |
+
|
16 |
+
/** That's all, stop editing from here **/
|
17 |
+
|
18 |
+
if ( !defined('WP_LOAD_PATH') ) {
|
19 |
+
|
20 |
+
/** classic root path if wp-content and plugins is below wp-config.php */
|
21 |
+
$classic_root = dirname(dirname(dirname(dirname(__FILE__)))) . '/' ;
|
22 |
+
|
23 |
+
if (file_exists( $classic_root . 'wp-load.php') )
|
24 |
+
define( 'WP_LOAD_PATH', $classic_root);
|
25 |
+
else
|
26 |
+
if (file_exists( $path . 'wp-load.php') )
|
27 |
+
define( 'WP_LOAD_PATH', $path);
|
28 |
+
else
|
29 |
+
exit("Could not find wp-load.php");
|
30 |
+
}
|
31 |
+
|
32 |
+
// let's load WordPress
|
33 |
+
require_once( WP_LOAD_PATH . 'wp-load.php');
|
34 |
+
?>
|
post-snippets.php
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Post Snippets
|
4 |
+
Plugin URI: http://coding.cglounge.com/wordpress-plugins/post-snippets/
|
5 |
+
Description: Stores snippets of HTML code or reoccurring text that you often use in your posts. You can use predefined variables to replace parts of the snippet on insert. All snippets are available in the post editor with a TinyMCE button.
|
6 |
+
Version: 1.0
|
7 |
+
Author: Johan Steen
|
8 |
+
Author URI: http://coding.cglounge.com/
|
9 |
+
|
10 |
+
|
11 |
+
Copyright 2009 Johan Steen (email : artstorm [at] gmail [dot] com)
|
12 |
+
|
13 |
+
This program is free software; you can redistribute it and/or modify
|
14 |
+
it under the terms of the GNU General Public License as published by
|
15 |
+
the Free Software Foundation; either version 2 of the License, or
|
16 |
+
(at your option) any later version.
|
17 |
+
|
18 |
+
This program is distributed in the hope that it will be useful,
|
19 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
GNU General Public License for more details.
|
22 |
+
|
23 |
+
You should have received a copy of the GNU General Public License
|
24 |
+
along with this program; if not, write to the Free Software
|
25 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
26 |
+
*/
|
27 |
+
|
28 |
+
class postSnippets {
|
29 |
+
var $plugin_options = "post_snippets_options";
|
30 |
+
|
31 |
+
function postSnippets()
|
32 |
+
{
|
33 |
+
// define URL
|
34 |
+
define('postSnippets_ABSPATH', WP_PLUGIN_DIR.'/'.plugin_basename( dirname(__FILE__) ).'/' );
|
35 |
+
define('postSnippets_URLPATH', WP_PLUGIN_URL.'/'.plugin_basename( dirname(__FILE__) ).'/' );
|
36 |
+
|
37 |
+
include_once (dirname (__FILE__)."/tinymce/tinymce.php");
|
38 |
+
|
39 |
+
$this->init_hooks();
|
40 |
+
}
|
41 |
+
|
42 |
+
function init_hooks(){
|
43 |
+
add_action('admin_menu', array(&$this,'wp_admin'));
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* The Admin Page and all it's functions
|
48 |
+
*
|
49 |
+
*/
|
50 |
+
function wp_admin() {
|
51 |
+
if (function_exists('add_options_page')) {
|
52 |
+
add_options_page( 'Post Snippets Options', 'Post Snippets', 10, __FILE__, array(&$this, 'options_page') );
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
function admin_message($message) {
|
57 |
+
if ( $message ) {
|
58 |
+
?>
|
59 |
+
<div class="updated"><p><strong><?php echo $message; ?></strong></p></div>
|
60 |
+
<?php
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
function options_page() {
|
65 |
+
// Add a new Snippet
|
66 |
+
if (isset($_POST['add-snippet'])) {
|
67 |
+
$snippets = get_option($this->plugin_options);
|
68 |
+
if (empty($snippets)) { $snippets = array(); }
|
69 |
+
array_push($snippets, array (
|
70 |
+
'title' => "Untitled",
|
71 |
+
'vars' => "",
|
72 |
+
'snippet' => ""));
|
73 |
+
update_option($this->plugin_options, $snippets);
|
74 |
+
$this->admin_message( __('A snippet named Untitled has been added.') );
|
75 |
+
}
|
76 |
+
|
77 |
+
// Update Snippets
|
78 |
+
if (isset($_POST['update-post-snippets'])) {
|
79 |
+
$snippets = get_option($this->plugin_options);
|
80 |
+
if (!empty($snippets)) {
|
81 |
+
for ($i=0; $i < count($snippets); $i++) {
|
82 |
+
$snippets[$i]['title'] = trim($_POST[$i.'_title']);
|
83 |
+
$snippets[$i]['vars'] = trim($_POST[$i.'_vars']);
|
84 |
+
$snippets[$i]['snippet'] = trim(stripslashes($_POST[$i.'_snippet']));
|
85 |
+
}
|
86 |
+
update_option($this->plugin_options, $snippets);
|
87 |
+
$this->admin_message( __('Snippets have been updated.') );
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
// Delete Snippets
|
92 |
+
if (isset($_POST['delete-selected'])) {
|
93 |
+
$snippets = get_option($this->plugin_options);
|
94 |
+
if (!empty($snippets)) {
|
95 |
+
$delete = $_POST['checked'];
|
96 |
+
$newsnippets = array();
|
97 |
+
for ($i=0; $i < count($snippets); $i++) {
|
98 |
+
if (in_array($i,$delete) == false) {
|
99 |
+
array_push($newsnippets,$snippets[$i]);
|
100 |
+
}
|
101 |
+
}
|
102 |
+
update_option($this->plugin_options, $newsnippets);
|
103 |
+
$this->admin_message( __('Selected snippets have been deleted.') );
|
104 |
+
}
|
105 |
+
}
|
106 |
+
?>
|
107 |
+
<div class=wrap>
|
108 |
+
<h2>Post Snippets</h2>
|
109 |
+
|
110 |
+
<form method="post" action="">
|
111 |
+
<?php wp_nonce_field('update-options'); ?>
|
112 |
+
|
113 |
+
<div class="tablenav">
|
114 |
+
<div class="alignleft actions">
|
115 |
+
<input type="submit" name="add-snippet" value="<?php _e('Add New Snippet') ?>" class="button-secondary" />
|
116 |
+
<input type="submit" name="delete-selected" value="<?php _e('Delete Selected') ?>" class="button-secondary" />
|
117 |
+
</div>
|
118 |
+
</div>
|
119 |
+
<div class="clear"></div>
|
120 |
+
|
121 |
+
<table class="widefat fixed" cellspacing="0">
|
122 |
+
<thead>
|
123 |
+
<tr>
|
124 |
+
<th scope="col" class="check-column"><input type="checkbox" /></th>
|
125 |
+
<th scope="col" style="width: 180px;"><?php _e('Title') ?></th>
|
126 |
+
<th scope="col" style="width: 180px;"><?php _e('Variables') ?></th>
|
127 |
+
<th scope="col"><?php _e('Snippet') ?></th>
|
128 |
+
</tr>
|
129 |
+
</thead>
|
130 |
+
|
131 |
+
<tfoot>
|
132 |
+
<tr>
|
133 |
+
<th scope="col" class="check-column"><input type="checkbox" /></th>
|
134 |
+
<th scope="col"><?php _e('Title') ?></th>
|
135 |
+
<th scope="col"><?php _e('Variables') ?></th>
|
136 |
+
<th scope="col"><?php _e('Snippet') ?></th>
|
137 |
+
</tr>
|
138 |
+
</tfoot>
|
139 |
+
|
140 |
+
<tbody>
|
141 |
+
<?php
|
142 |
+
$snippets = get_option($this->plugin_options);
|
143 |
+
if (!empty($snippets)) {
|
144 |
+
for ($i=0; $i < count($snippets); $i++) { ?>
|
145 |
+
<tr class='recent'>
|
146 |
+
<th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='<?= $i ?>' /></th>
|
147 |
+
<td class='row-title'><input type='text' name='<?= $i ?>_title' value='<?= $snippets[$i]['title'] ?>' /></td>
|
148 |
+
<td class='name'><input type='text' name='<?= $i ?>_vars' value='<?= $snippets[$i]['vars'] ?>' /></td>
|
149 |
+
<td class='desc'><textarea name="<?= $i ?>_snippet" class="large-text" rows="3"><?= $snippets[$i]['snippet'] ?></textarea></td>
|
150 |
+
</tr>
|
151 |
+
<?php
|
152 |
+
}
|
153 |
+
}
|
154 |
+
?>
|
155 |
+
</tbody>
|
156 |
+
</table>
|
157 |
+
<div class="submit">
|
158 |
+
<input type="submit" name="update-post-snippets" value="<?php _e('Update Snippets') ?>" class="button-primary" /></div>
|
159 |
+
</form>
|
160 |
+
<h3><?php _e('Help'); ?></h3>
|
161 |
+
<p><?php _e('<strong>Title</strong><br/>Give the snippet a title that helps you identify it in the post editor.<br/><br/><strong>Variables</strong><br/>A comma separated list of custom variables you can reference in your snippet.<br/><br/>Example:<br/>url,name<br/><br/><strong>Snippet</strong><br/>This is the block of text or HTML to insert in the post when you select the snippet from the insert button in the TinyMCE panel in the post editor. If you have entered predefined variables you can reference them from the snippet by enclosing them in {} brackets.<br/><br/>Example:<br/>To reference the variables in the example above, you would enter {url} and {name}.<br/><br/>So if you enter this snippet:<br/><i>This is the website of <a href="{url}">{name}</a></i><br/>You will get the option to replace url and name on insert if they are defined as variables.'); ?></p>
|
162 |
+
</div>
|
163 |
+
<?php
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
add_action( 'plugins_loaded', create_function( '', 'global $postSnippets; $postSnippets = new postSnippets();' ) );
|
168 |
+
|
169 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Post Snippets ===
|
2 |
+
Contributors: artstorm
|
3 |
+
Donate link: http://coding.cglounge.com/wordpress-plugins/post-snippets/
|
4 |
+
Tags: post, admin, snippet, snippets, html, custom, page, dynamic
|
5 |
+
Requires at least: 2.7
|
6 |
+
Tested up to: 2.7.1
|
7 |
+
Stable tag: 1.0
|
8 |
+
|
9 |
+
Store snippets of HTML code or reoccurring text that you often use in your posts.
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
|
13 |
+
This admin plugin stores snippets of HTML code or reoccurring text that you often use in your posts. You can use predefined variables to replace parts of the snippet on insert. All snippets are available in the post editor with a TinyMCE button.
|
14 |
+
|
15 |
+
For complete usage instructions see: [Post Snippets](http://coding.cglounge.com/wordpress-plugins/post-snippets/ "Complete Usage Instructions for Post Snippets")
|
16 |
+
|
17 |
+
|
18 |
+
== Installation ==
|
19 |
+
|
20 |
+
1. Upload the 'post-snippets' folder to the '/wp-content/plugins/' directory.
|
21 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
22 |
+
3. Go to Settings -> Post Snippets and start entering your snippets.
|
23 |
+
|
24 |
+
|
25 |
+
== Frequently Asked Questions ==
|
26 |
+
|
27 |
+
= What about foo bar? =
|
28 |
+
|
29 |
+
Answer to foo bar dilemma.
|
30 |
+
|
31 |
+
== Screenshots ==
|
32 |
+
|
33 |
+
1. The Admin page where you set up new snippets.
|
34 |
+
2. The TinyMCE button for Post Snippet.
|
35 |
+
3. The Post Snippet Insert Window.
|
screenshot-1.jpg
ADDED
Binary file
|
screenshot-2.jpg
ADDED
Binary file
|
screenshot-3.jpg
ADDED
Binary file
|
tinymce/editor_plugin.js
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Docu : http://wiki.moxiecode.com/index.php/TinyMCE:Create_plugin/3.x#Creating_your_own_plugins
|
2 |
+
|
3 |
+
(function() {
|
4 |
+
// Load plugin specific language pack
|
5 |
+
tinymce.PluginManager.requireLangPack('postSnippets');
|
6 |
+
|
7 |
+
tinymce.create('tinymce.plugins.postSnippets', {
|
8 |
+
/**
|
9 |
+
* Initializes the plugin, this will be executed after the plugin has been created.
|
10 |
+
* This call is done before the editor instance has finished it's initialization so use the onInit event
|
11 |
+
* of the editor instance to intercept that event.
|
12 |
+
*
|
13 |
+
* @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
|
14 |
+
* @param {string} url Absolute URL to where the plugin is located.
|
15 |
+
*/
|
16 |
+
init : function(ed, url) {
|
17 |
+
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
|
18 |
+
|
19 |
+
ed.addCommand('mcepostSnippets', function() {
|
20 |
+
ed.windowManager.open({
|
21 |
+
file : url + '/window.php',
|
22 |
+
width : 360 + ed.getLang('postSnippets.delta_width', 0),
|
23 |
+
height : 210 + ed.getLang('postSnippets.delta_height', 0),
|
24 |
+
inline : 1
|
25 |
+
}, {
|
26 |
+
plugin_url : url // Plugin absolute URL
|
27 |
+
});
|
28 |
+
});
|
29 |
+
|
30 |
+
// Register example button
|
31 |
+
ed.addButton('postSnippets', {
|
32 |
+
title : 'postSnippets.desc',
|
33 |
+
cmd : 'mcepostSnippets',
|
34 |
+
image : url + '/post-snippets.gif'
|
35 |
+
});
|
36 |
+
|
37 |
+
// Add a node change handler, selects the button in the UI when a image is selected
|
38 |
+
ed.onNodeChange.add(function(ed, cm, n) {
|
39 |
+
cm.setActive('postSnippets', n.nodeName == 'IMG');
|
40 |
+
});
|
41 |
+
},
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Returns information about the plugin as a name/value array.
|
45 |
+
* The current keys are longname, author, authorurl, infourl and version.
|
46 |
+
*
|
47 |
+
* @return {Object} Name/value array containing information about the plugin.
|
48 |
+
*/
|
49 |
+
getInfo : function() {
|
50 |
+
return {
|
51 |
+
longname : 'postSnippets',
|
52 |
+
author : 'Johan Steen',
|
53 |
+
authorurl : 'http://coding.cglounge.com/',
|
54 |
+
infourl : 'http://coding.cglounge.com/',
|
55 |
+
version : "1.0"
|
56 |
+
};
|
57 |
+
}
|
58 |
+
});
|
59 |
+
|
60 |
+
// Register plugin
|
61 |
+
tinymce.PluginManager.add('postSnippets', tinymce.plugins.postSnippets);
|
62 |
+
})();
|
63 |
+
|
64 |
+
|
tinymce/langs/en.js
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
tinyMCE.addI18n({en:{
|
2 |
+
postSnippets:{
|
3 |
+
desc : 'Insert a Post Snippet'
|
4 |
+
}}});
|
tinymce/langs/en_US.js
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
tinyMCE.addI18n({en_US:{
|
2 |
+
postSnippets:{
|
3 |
+
desc : 'Insert a Post Snippet'
|
4 |
+
}}});
|
tinymce/langs/en_en.js
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
tinyMCE.addI18n({en_US:{
|
2 |
+
postSnippets:{
|
3 |
+
desc : 'Insert a Post Snippet'
|
4 |
+
}}});
|
tinymce/post-snippets.gif
ADDED
Binary file
|
tinymce/tinymce.php
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @title TinyMCE V3 Button Integration (for Wp2.5)
|
5 |
+
* @author Alex Rabe
|
6 |
+
*/
|
7 |
+
|
8 |
+
class add_postSnippets_button {
|
9 |
+
|
10 |
+
var $pluginname = "postSnippets";
|
11 |
+
|
12 |
+
function add_postSnippets_button() {
|
13 |
+
// Modify the version when tinyMCE plugins are changed.
|
14 |
+
add_filter('tiny_mce_version', array (&$this, 'change_tinymce_version') );
|
15 |
+
|
16 |
+
// init process for button control
|
17 |
+
add_action('init', array (&$this, 'addbuttons') );
|
18 |
+
}
|
19 |
+
|
20 |
+
function addbuttons() {
|
21 |
+
|
22 |
+
// Don't bother doing this stuff if the current user lacks permissions
|
23 |
+
if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) return;
|
24 |
+
|
25 |
+
// Add only in Rich Editor mode
|
26 |
+
if ( get_user_option('rich_editing') == 'true') {
|
27 |
+
|
28 |
+
// add the button for wp2.5 in a new way
|
29 |
+
add_filter("mce_external_plugins", array (&$this, "add_tinymce_plugin" ), 5);
|
30 |
+
add_filter('mce_buttons', array (&$this, 'register_button' ), 5);
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
// used to insert button in wordpress 2.5x editor
|
35 |
+
function register_button($buttons) {
|
36 |
+
|
37 |
+
array_push($buttons, "separator", $this->pluginname );
|
38 |
+
|
39 |
+
return $buttons;
|
40 |
+
}
|
41 |
+
|
42 |
+
// Load the TinyMCE plugin : editor_plugin.js (wp2.5)
|
43 |
+
function add_tinymce_plugin($plugin_array) {
|
44 |
+
|
45 |
+
$plugin_array[$this->pluginname] = postSnippets_URLPATH.'tinymce/editor_plugin.js';
|
46 |
+
|
47 |
+
return $plugin_array;
|
48 |
+
}
|
49 |
+
|
50 |
+
function change_tinymce_version($version) {
|
51 |
+
return ++$version;
|
52 |
+
}
|
53 |
+
|
54 |
+
}
|
55 |
+
|
56 |
+
// Call it now
|
57 |
+
$tinymce_button = new add_postSnippets_button();
|
58 |
+
|
59 |
+
?>
|
tinymce/window.php
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// look up for the path
|
3 |
+
require_once( dirname( dirname(__FILE__) ) .'/post-snippets-config.php');
|
4 |
+
|
5 |
+
global $wpdb;
|
6 |
+
|
7 |
+
// check for rights
|
8 |
+
if ( !is_user_logged_in() || !current_user_can('edit_posts') )
|
9 |
+
wp_die(__("You are not allowed to be here"));
|
10 |
+
|
11 |
+
?>
|
12 |
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
13 |
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
14 |
+
<head>
|
15 |
+
<title>Post Snippets</title>
|
16 |
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
17 |
+
<script language="javascript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-includes/js/tinymce/tiny_mce_popup.js"></script>
|
18 |
+
<script language="javascript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-includes/js/tinymce/utils/mctabs.js"></script>
|
19 |
+
<script language="javascript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-includes/js/tinymce/utils/form_utils.js"></script>
|
20 |
+
<script language="javascript" type="text/javascript">
|
21 |
+
function init() {
|
22 |
+
tinyMCEPopup.resizeToInnerSize();
|
23 |
+
}
|
24 |
+
|
25 |
+
function insertSnippet() {
|
26 |
+
|
27 |
+
var insertString;
|
28 |
+
|
29 |
+
<?php
|
30 |
+
$snippets = get_option($postSnippets->plugin_options);
|
31 |
+
for ($i = 0; $i < count($snippets); $i++) { ?>
|
32 |
+
var panel<?= $i ?> = document.getElementById('ps_panel<?= $i ?>');
|
33 |
+
<?php } ?>
|
34 |
+
|
35 |
+
var rss = document.getElementById('ps_panel0');
|
36 |
+
|
37 |
+
<?php
|
38 |
+
$snippets = get_option($postSnippets->plugin_options);
|
39 |
+
for ($i = 0; $i < count($snippets); $i++) {
|
40 |
+
// Make it js safe
|
41 |
+
$theString = str_replace('"','\"',str_replace(Chr(13), '', str_replace(Chr(10), '', $snippets[$i]['snippet'])))
|
42 |
+
?>
|
43 |
+
|
44 |
+
if (panel<?= $i ?>.className.indexOf('current') != -1) {
|
45 |
+
insertString = "<?= $theString; ?>";
|
46 |
+
<?php
|
47 |
+
$var_arr = explode(",",$snippets[$i]['vars']);
|
48 |
+
if (!empty($var_arr[0])) {
|
49 |
+
for ($j = 0; $j < count($var_arr); $j++) { ?>
|
50 |
+
var var_<?= $i ?>_<?= $j ?> = document.getElementById('var_<?= $i ?>_<?= $j ?>').value;
|
51 |
+
insertString = insertString.replace(/{<?= $var_arr[$j] ?>}/g, var_<?= $i ?>_<?= $j ?>);
|
52 |
+
<?php } } ?>
|
53 |
+
}
|
54 |
+
<?php } ?>
|
55 |
+
|
56 |
+
|
57 |
+
if(window.tinyMCE) {
|
58 |
+
window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, insertString);
|
59 |
+
//Peforms a clean up of the current editor HTML.
|
60 |
+
//tinyMCEPopup.editor.execCommand('mceCleanup');
|
61 |
+
//Repaints the editor. Sometimes the browser has graphic glitches.
|
62 |
+
tinyMCEPopup.editor.execCommand('mceRepaint');
|
63 |
+
tinyMCEPopup.close();
|
64 |
+
}
|
65 |
+
|
66 |
+
return;
|
67 |
+
}
|
68 |
+
</script>
|
69 |
+
<base target="_self" />
|
70 |
+
</head>
|
71 |
+
<body id="link" onload="tinyMCEPopup.executeOnLoad('init();');document.body.style.display='';" style="display: none">
|
72 |
+
<!-- <form onsubmit="insertLink();return false;" action="#"> -->
|
73 |
+
<form name="postSnippets" action="#">
|
74 |
+
|
75 |
+
<div class="tabs">
|
76 |
+
<ul>
|
77 |
+
<?php
|
78 |
+
$snippets = get_option($postSnippets->plugin_options);
|
79 |
+
for ($i = 0; $i < count($snippets); $i++) { ?>
|
80 |
+
<li id="ps_tab<?= $i ?>"<?php if ($i == 0) {?> class="current"><?php } ?><span><a href="javascript:mcTabs.displayTab('ps_tab<?= $i ?>','ps_panel<?= $i ?>');" onmousedown="return false;"><?php echo $snippets[$i]['title']; ?></a></span></li>
|
81 |
+
<?php } ?>
|
82 |
+
</ul>
|
83 |
+
</div>
|
84 |
+
|
85 |
+
<div class="panel_wrapper">
|
86 |
+
<?php
|
87 |
+
$snippets = get_option($postSnippets->plugin_options);
|
88 |
+
for ($i = 0; $i < count($snippets); $i++) { ?>
|
89 |
+
<div id="ps_panel<?= $i ?>" class="panel<?php if ($i == 0) {?> current<?php } ?>">
|
90 |
+
<br />
|
91 |
+
<table border="0" cellpadding="4" cellspacing="0">
|
92 |
+
<?php
|
93 |
+
$var_arr = explode(",",$snippets[$i]['vars']);
|
94 |
+
if (!empty($var_arr[0])) {
|
95 |
+
for ($j = 0; $j < count($var_arr); $j++) { ?>
|
96 |
+
<tr>
|
97 |
+
<td nowrap="nowrap"><label for="var_<?= $i ?>_<?= $j ?>"><?php echo($var_arr[$j]);?>:</label></td>
|
98 |
+
<td><input type="text" id="var_<?= $i ?>_<?= $j ?>" name="var_<?= $i ?>_<?= $j ?>" style="width: 190px" />
|
99 |
+
</td>
|
100 |
+
</tr>
|
101 |
+
<?php } } ?>
|
102 |
+
</table>
|
103 |
+
</div>
|
104 |
+
<?php } ?>
|
105 |
+
</div>
|
106 |
+
|
107 |
+
<div class="mceActionPanel">
|
108 |
+
<div style="float: left">
|
109 |
+
<input type="button" id="cancel" name="cancel" value="<?php _e("Cancel"); ?>" onclick="tinyMCEPopup.close();" />
|
110 |
+
</div>
|
111 |
+
|
112 |
+
<div style="float: right">
|
113 |
+
<input type="submit" id="insert" name="insert" value="<?php _e("Insert"); ?>" onclick="insertSnippet();" />
|
114 |
+
</div>
|
115 |
+
</div>
|
116 |
+
</form>
|
117 |
+
</body>
|
118 |
+
</html>
|
uninstall.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Uninstall
|
4 |
+
* Clean up the WP DB by deleting the options created by the plugin.
|
5 |
+
*
|
6 |
+
*/
|
7 |
+
delete_option('post_snippets_options');
|
8 |
+
?>
|