Version Description
Download this release
Release Info
Developer | miyauchi |
Plugin | TinyMCE Templates |
Version | 0.3 |
Comparing to | |
See all releases |
Code changes from version 0.2 to 0.3
- includes/MceTemplatesAdmin.class.php +43 -46
- includes/TinyMCETemplate.class.php +51 -42
- includes/addrewriterules.class.php +73 -0
- readme.txt +2 -2
- tinymce_templates.php +20 -23
includes/MceTemplatesAdmin.class.php
CHANGED
@@ -1,13 +1,8 @@
|
|
1 |
<?php
|
2 |
|
3 |
class MceTemplatesAdmin{
|
4 |
-
function
|
5 |
{
|
6 |
-
global $wpdb;
|
7 |
-
|
8 |
-
$this->domain = $class->name;
|
9 |
-
$this->table = $wpdb->prefix.$class->table;
|
10 |
-
|
11 |
echo '<link rel="stylesheet" href="'.TINYMCE_TEMPLATES_PLUGIN_URL.'/style.css" type="text/css" media="all" />';
|
12 |
|
13 |
echo '<div class="wrap">';
|
@@ -26,16 +21,16 @@ class MceTemplatesAdmin{
|
|
26 |
}
|
27 |
|
28 |
|
29 |
-
function editView()
|
30 |
{
|
31 |
global $wpdb;
|
32 |
global $current_user;
|
33 |
|
34 |
-
echo '<h2>'.__("Edit Templates",
|
35 |
|
36 |
if (isset($_POST['templates']) && is_array($_POST['templates'])) {
|
37 |
$this->delete();
|
38 |
-
echo '<div id="message" class="updated fade"><p>'.$n.__("Templates permanently deleted.",
|
39 |
}
|
40 |
|
41 |
echo "<form method=\"post\" action=\"{$_SERVER['REQUEST_URI']}\">";
|
@@ -43,24 +38,24 @@ class MceTemplatesAdmin{
|
|
43 |
echo '<thead>';
|
44 |
echo '<tr>';
|
45 |
echo '<th scope="col" class="column-cb check-column"><input type="checkbox" /></th>';
|
46 |
-
echo '<th scope="col">'.__('Name',
|
47 |
-
echo '<th scope="col">'.__('Description',
|
48 |
-
echo '<th scope="col">'.__('Author',
|
49 |
-
echo '<th scope="col">'.__('Share',
|
50 |
echo '</tr>';
|
51 |
echo '</thead>';
|
52 |
echo '<tfoot>';
|
53 |
echo '<tr>';
|
54 |
echo '<th scope="col" class="column-cb check-column"><input type="checkbox" /></th>';
|
55 |
-
echo '<th scope="col">'.__('Name',
|
56 |
-
echo '<th scope="col">'.__('Description',
|
57 |
-
echo '<th scope="col">'.__('Author',
|
58 |
-
echo '<th scope="col">'.__('Share',
|
59 |
echo '</tr>';
|
60 |
echo '</tfoot>';
|
61 |
echo '<tbody>';
|
62 |
|
63 |
-
$sql = "select * from
|
64 |
where `author`={$current_user->ID} or `share`=1 order by `modified` desc";
|
65 |
$row = $wpdb->get_results($sql);
|
66 |
|
@@ -91,28 +86,28 @@ class MceTemplatesAdmin{
|
|
91 |
$author = get_userdata($tpl->author);
|
92 |
echo '<td>'.esc_html($author->nickname).'</td>';
|
93 |
if ($tpl->share) {
|
94 |
-
echo '<td>'.__('Shared',
|
95 |
} else {
|
96 |
-
echo '<td>'.__('Private',
|
97 |
}
|
98 |
echo "</tr>";
|
99 |
$i = $i + 1;
|
100 |
}
|
101 |
echo "</tbody>";
|
102 |
echo "</table>";
|
103 |
-
echo '<input type="submit" value="'.__("Delete checked items",
|
104 |
echo "</form>";
|
105 |
}
|
106 |
|
107 |
-
function addView()
|
108 |
{
|
109 |
global $current_user;
|
110 |
|
111 |
if (isset($_POST['save']) && $_POST['save']) {
|
112 |
if ($this->validate() && $this->save()) {
|
113 |
-
echo "<div id=\"message\" class=\"updated fade\"><p><strong>".__("Template saved.",
|
114 |
global $wpdb;
|
115 |
-
$sql = $wpdb->prepare("select * from
|
116 |
where `id`=%s", $_POST['id']);
|
117 |
$r = $wpdb->get_row($sql);
|
118 |
$id = $r->ID;
|
@@ -121,7 +116,7 @@ class MceTemplatesAdmin{
|
|
121 |
$html = stripslashes($r->html);
|
122 |
$share = $r->share;
|
123 |
} else {
|
124 |
-
echo "<div id=\"message\" class=\"error fade\"><p><strong>".__("All entry must not be blank.",
|
125 |
$id = $_POST['id'];
|
126 |
$name = $_POST['name'];
|
127 |
$desc = $_POST['desc'];
|
@@ -131,8 +126,9 @@ class MceTemplatesAdmin{
|
|
131 |
} elseif (isset($_GET['page']) && $_GET['page'] == 'edittemplates'
|
132 |
&& isset($_GET['id']) && preg_match("/^[a-zA-Z0-9]{32}$/", $_GET['id'])) {
|
133 |
global $wpdb;
|
134 |
-
$sql = $wpdb->prepare("select * from
|
135 |
-
where `ID`=%s and author=%s",
|
|
|
136 |
$r = $wpdb->get_row($sql);
|
137 |
if ($r) {
|
138 |
$id = $r->ID;
|
@@ -153,36 +149,36 @@ class MceTemplatesAdmin{
|
|
153 |
|
154 |
if (isset($_GET['page']) && $_GET['page'] == 'edittemplates'
|
155 |
&& isset($_GET['id']) && preg_match("/^[a-zA-Z0-9]{32}$/", $_GET['id'])) {
|
156 |
-
echo '<h2>'.__("Edit Templates",
|
157 |
} else {
|
158 |
-
echo '<h2>'.__("Add New Templates",
|
159 |
}
|
160 |
echo "<form action=\"{$_SERVER["REQUEST_URI"]}\" method=\"post\">";
|
161 |
echo "<input type=\"hidden\" name=\"save\" value=\"1\" />";
|
162 |
echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />";
|
163 |
-
echo "<h3>".__("Template Name",
|
164 |
echo "<input type=\"text\" id=\"name\" name=\"name\" value=\"{$name}\" />";
|
165 |
-
echo "<h3>".__("Template Description",
|
166 |
echo "<textarea id=\"desc\" name=\"desc\">{$desc}</textarea>";
|
167 |
-
echo "<h3>".__("Template Contents",
|
168 |
echo "<textarea id=\"html\" name=\"html\">{$html}</textarea>";
|
169 |
-
echo "<h3>".__("Share",
|
170 |
echo "<select name=\"share\" id=\"share\">";
|
171 |
if ($share == 1) {
|
172 |
-
echo "<option value=\"1\" selected=\"selected\">".__("Share",
|
173 |
-
echo "<option value=\"0\">".__("Private",
|
174 |
} else {
|
175 |
-
echo "<option value=\"1\">".__("Share",
|
176 |
-
echo "<option value=\"0\" selected=\"selected\">".__("Private",
|
177 |
}
|
178 |
echo "</select>";
|
179 |
echo "<div id=\"save\">";
|
180 |
-
echo "<input type=\"submit\" value=\"".__("Save Template",
|
181 |
echo "</div>";
|
182 |
echo "</form>";
|
183 |
}
|
184 |
|
185 |
-
function save()
|
186 |
{
|
187 |
global $wpdb;
|
188 |
global $current_user;
|
@@ -191,7 +187,7 @@ class MceTemplatesAdmin{
|
|
191 |
return false;
|
192 |
}
|
193 |
|
194 |
-
$sql = "insert into
|
195 |
(`ID`, `name`, `desc`, `html`, `share`, `author`)
|
196 |
values
|
197 |
(%s, %s, %s, %s, %d, %d)
|
@@ -202,13 +198,14 @@ class MceTemplatesAdmin{
|
|
202 |
`html`=values(`html`),
|
203 |
`share`=values(`share`)
|
204 |
";
|
205 |
-
$sql = $wpdb->prepare($sql, $_POST['id'],
|
|
|
206 |
$_POST['html'], $_POST['share'], $current_user->ID);
|
207 |
$wpdb->query($sql);
|
208 |
return true;
|
209 |
}
|
210 |
|
211 |
-
function validate()
|
212 |
{
|
213 |
$pars = array('id', 'name', 'desc', 'html', 'share');
|
214 |
foreach ($pars as $par):
|
@@ -229,12 +226,12 @@ class MceTemplatesAdmin{
|
|
229 |
return true;
|
230 |
}
|
231 |
|
232 |
-
function checkAuth($id)
|
233 |
{
|
234 |
global $wpdb;
|
235 |
global $current_user;
|
236 |
|
237 |
-
$sql = $wpdb->prepare("select author from
|
238 |
$author = $wpdb->get_var($sql);
|
239 |
|
240 |
if (!$author || $author === $current_user->ID) {
|
@@ -244,13 +241,13 @@ class MceTemplatesAdmin{
|
|
244 |
}
|
245 |
}
|
246 |
|
247 |
-
function delete()
|
248 |
{
|
249 |
global $wpdb;
|
250 |
global $current_user;
|
251 |
|
252 |
foreach ($_POST['templates'] as $tpl) {
|
253 |
-
$sql = "delete from
|
254 |
$sql = $wpdb->prepare($sql, $tpl, $current_user->ID);
|
255 |
$wpdb->query($sql);
|
256 |
}
|
1 |
<?php
|
2 |
|
3 |
class MceTemplatesAdmin{
|
4 |
+
function __construct()
|
5 |
{
|
|
|
|
|
|
|
|
|
|
|
6 |
echo '<link rel="stylesheet" href="'.TINYMCE_TEMPLATES_PLUGIN_URL.'/style.css" type="text/css" media="all" />';
|
7 |
|
8 |
echo '<div class="wrap">';
|
21 |
}
|
22 |
|
23 |
|
24 |
+
public function editView()
|
25 |
{
|
26 |
global $wpdb;
|
27 |
global $current_user;
|
28 |
|
29 |
+
echo '<h2>'.__("Edit Templates", TINYMCE_TEMPLATES_DOMAIN).'</h2>';
|
30 |
|
31 |
if (isset($_POST['templates']) && is_array($_POST['templates'])) {
|
32 |
$this->delete();
|
33 |
+
echo '<div id="message" class="updated fade"><p>'.$n.__("Templates permanently deleted.", TINYMCE_TEMPLATES_DOMAIN).'</p></div>';
|
34 |
}
|
35 |
|
36 |
echo "<form method=\"post\" action=\"{$_SERVER['REQUEST_URI']}\">";
|
38 |
echo '<thead>';
|
39 |
echo '<tr>';
|
40 |
echo '<th scope="col" class="column-cb check-column"><input type="checkbox" /></th>';
|
41 |
+
echo '<th scope="col">'.__('Name', TINYMCE_TEMPLATES_DOMAIN).'</th>';
|
42 |
+
echo '<th scope="col">'.__('Description', TINYMCE_TEMPLATES_DOMAIN).'</th>';
|
43 |
+
echo '<th scope="col">'.__('Author', TINYMCE_TEMPLATES_DOMAIN).'</th>';
|
44 |
+
echo '<th scope="col">'.__('Share', TINYMCE_TEMPLATES_DOMAIN).'</th>';
|
45 |
echo '</tr>';
|
46 |
echo '</thead>';
|
47 |
echo '<tfoot>';
|
48 |
echo '<tr>';
|
49 |
echo '<th scope="col" class="column-cb check-column"><input type="checkbox" /></th>';
|
50 |
+
echo '<th scope="col">'.__('Name', TINYMCE_TEMPLATES_DOMAIN).'</th>';
|
51 |
+
echo '<th scope="col">'.__('Description', TINYMCE_TEMPLATES_DOMAIN).'</th>';
|
52 |
+
echo '<th scope="col">'.__('Author', TINYMCE_TEMPLATES_DOMAIN).'</th>';
|
53 |
+
echo '<th scope="col">'.__('Share', TINYMCE_TEMPLATES_DOMAIN).'</th>';
|
54 |
echo '</tr>';
|
55 |
echo '</tfoot>';
|
56 |
echo '<tbody>';
|
57 |
|
58 |
+
$sql = "select * from ".TINYMCE_TEMPLATES_TABLE."
|
59 |
where `author`={$current_user->ID} or `share`=1 order by `modified` desc";
|
60 |
$row = $wpdb->get_results($sql);
|
61 |
|
86 |
$author = get_userdata($tpl->author);
|
87 |
echo '<td>'.esc_html($author->nickname).'</td>';
|
88 |
if ($tpl->share) {
|
89 |
+
echo '<td>'.__('Shared', TINYMCE_TEMPLATES_DOMAIN).'</td>';
|
90 |
} else {
|
91 |
+
echo '<td>'.__('Private', TINYMCE_TEMPLATES_DOMAIN).'</td>';
|
92 |
}
|
93 |
echo "</tr>";
|
94 |
$i = $i + 1;
|
95 |
}
|
96 |
echo "</tbody>";
|
97 |
echo "</table>";
|
98 |
+
echo '<input type="submit" value="'.__("Delete checked items", TINYMCE_TEMPLATES_DOMAIN).'" class="button-secondary" />';
|
99 |
echo "</form>";
|
100 |
}
|
101 |
|
102 |
+
public function addView()
|
103 |
{
|
104 |
global $current_user;
|
105 |
|
106 |
if (isset($_POST['save']) && $_POST['save']) {
|
107 |
if ($this->validate() && $this->save()) {
|
108 |
+
echo "<div id=\"message\" class=\"updated fade\"><p><strong>".__("Template saved.", TINYMCE_TEMPLATES_DOMAIN)."</strong></p></div>";
|
109 |
global $wpdb;
|
110 |
+
$sql = $wpdb->prepare("select * from ".TINYMCE_TEMPLATES_TABLE."
|
111 |
where `id`=%s", $_POST['id']);
|
112 |
$r = $wpdb->get_row($sql);
|
113 |
$id = $r->ID;
|
116 |
$html = stripslashes($r->html);
|
117 |
$share = $r->share;
|
118 |
} else {
|
119 |
+
echo "<div id=\"message\" class=\"error fade\"><p><strong>".__("All entry must not be blank.", TINYMCE_TEMPLATES_DOMAIN)."</strong></p></div>";
|
120 |
$id = $_POST['id'];
|
121 |
$name = $_POST['name'];
|
122 |
$desc = $_POST['desc'];
|
126 |
} elseif (isset($_GET['page']) && $_GET['page'] == 'edittemplates'
|
127 |
&& isset($_GET['id']) && preg_match("/^[a-zA-Z0-9]{32}$/", $_GET['id'])) {
|
128 |
global $wpdb;
|
129 |
+
$sql = $wpdb->prepare("select * from ".TINYMCE_TEMPLATES_TABLE."
|
130 |
+
where `ID`=%s and author=%s",
|
131 |
+
$_GET['id'], $current_user->ID);
|
132 |
$r = $wpdb->get_row($sql);
|
133 |
if ($r) {
|
134 |
$id = $r->ID;
|
149 |
|
150 |
if (isset($_GET['page']) && $_GET['page'] == 'edittemplates'
|
151 |
&& isset($_GET['id']) && preg_match("/^[a-zA-Z0-9]{32}$/", $_GET['id'])) {
|
152 |
+
echo '<h2>'.__("Edit Templates", TINYMCE_TEMPLATES_DOMAIN).'</h2>';
|
153 |
} else {
|
154 |
+
echo '<h2>'.__("Add New Templates", TINYMCE_TEMPLATES_DOMAIN).'</h2>';
|
155 |
}
|
156 |
echo "<form action=\"{$_SERVER["REQUEST_URI"]}\" method=\"post\">";
|
157 |
echo "<input type=\"hidden\" name=\"save\" value=\"1\" />";
|
158 |
echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />";
|
159 |
+
echo "<h3>".__("Template Name", TINYMCE_TEMPLATES_DOMAIN)."</h3>";
|
160 |
echo "<input type=\"text\" id=\"name\" name=\"name\" value=\"{$name}\" />";
|
161 |
+
echo "<h3>".__("Template Description", TINYMCE_TEMPLATES_DOMAIN)."</h3>";
|
162 |
echo "<textarea id=\"desc\" name=\"desc\">{$desc}</textarea>";
|
163 |
+
echo "<h3>".__("Template Contents", TINYMCE_TEMPLATES_DOMAIN)." (HTML)</h3>";
|
164 |
echo "<textarea id=\"html\" name=\"html\">{$html}</textarea>";
|
165 |
+
echo "<h3>".__("Share", TINYMCE_TEMPLATES_DOMAIN)."</h3>";
|
166 |
echo "<select name=\"share\" id=\"share\">";
|
167 |
if ($share == 1) {
|
168 |
+
echo "<option value=\"1\" selected=\"selected\">".__("Share", TINYMCE_TEMPLATES_DOMAIN)."</option>";
|
169 |
+
echo "<option value=\"0\">".__("Private", TINYMCE_TEMPLATES_DOMAIN)."</option>";
|
170 |
} else {
|
171 |
+
echo "<option value=\"1\">".__("Share", TINYMCE_TEMPLATES_DOMAIN)."</option>";
|
172 |
+
echo "<option value=\"0\" selected=\"selected\">".__("Private", TINYMCE_TEMPLATES_DOMAIN)."</option>";
|
173 |
}
|
174 |
echo "</select>";
|
175 |
echo "<div id=\"save\">";
|
176 |
+
echo "<input type=\"submit\" value=\"".__("Save Template", TINYMCE_TEMPLATES_DOMAIN)."\" class=\"button-primary\" />";
|
177 |
echo "</div>";
|
178 |
echo "</form>";
|
179 |
}
|
180 |
|
181 |
+
private function save()
|
182 |
{
|
183 |
global $wpdb;
|
184 |
global $current_user;
|
187 |
return false;
|
188 |
}
|
189 |
|
190 |
+
$sql = "insert into ".TINYMCE_TEMPLATES_TABLE."
|
191 |
(`ID`, `name`, `desc`, `html`, `share`, `author`)
|
192 |
values
|
193 |
(%s, %s, %s, %s, %d, %d)
|
198 |
`html`=values(`html`),
|
199 |
`share`=values(`share`)
|
200 |
";
|
201 |
+
$sql = $wpdb->prepare($sql, $_POST['id'],
|
202 |
+
$_POST['name'], $_POST['desc'],
|
203 |
$_POST['html'], $_POST['share'], $current_user->ID);
|
204 |
$wpdb->query($sql);
|
205 |
return true;
|
206 |
}
|
207 |
|
208 |
+
private function validate()
|
209 |
{
|
210 |
$pars = array('id', 'name', 'desc', 'html', 'share');
|
211 |
foreach ($pars as $par):
|
226 |
return true;
|
227 |
}
|
228 |
|
229 |
+
private function checkAuth($id)
|
230 |
{
|
231 |
global $wpdb;
|
232 |
global $current_user;
|
233 |
|
234 |
+
$sql = $wpdb->prepare("select author from ".TINYMCE_TEMPLATES_TABLE." where ID=%s", $id);
|
235 |
$author = $wpdb->get_var($sql);
|
236 |
|
237 |
if (!$author || $author === $current_user->ID) {
|
241 |
}
|
242 |
}
|
243 |
|
244 |
+
private function delete()
|
245 |
{
|
246 |
global $wpdb;
|
247 |
global $current_user;
|
248 |
|
249 |
foreach ($_POST['templates'] as $tpl) {
|
250 |
+
$sql = "delete from ".TINYMCE_TEMPLATES_TABLE." where ID=%s and author=%s";
|
251 |
$sql = $wpdb->prepare($sql, $tpl, $current_user->ID);
|
252 |
$wpdb->query($sql);
|
253 |
}
|
includes/TinyMCETemplate.class.php
CHANGED
@@ -4,38 +4,33 @@ new TinyMCETemplate();
|
|
4 |
|
5 |
class TinyMCETemplate{
|
6 |
|
7 |
-
private $
|
8 |
|
9 |
function __construct()
|
10 |
{
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
$url = get_bloginfo('url');
|
16 |
-
$inits['template_external_list_url'] = $url.'/mce_templates.js';
|
17 |
-
$this->mce_css = TINYMCE_TEMPLATES_PLUGIN_URL.'/editor.css';
|
18 |
-
$inits['content_css'] = $this->mce_css;
|
19 |
-
new mcePlugins(
|
20 |
-
'template',
|
21 |
-
$plugin,
|
22 |
-
$lang,
|
23 |
-
array(&$this, 'add_button'),
|
24 |
-
$inits
|
25 |
);
|
26 |
-
|
27 |
-
|
28 |
-
add_filter('query_vars', array(&$this, 'query_vars'));
|
29 |
-
add_filter('rewrite_rules_array', array(&$this, 'rewrite_rules_array'));
|
30 |
-
add_action('init', array(&$this, 'init'));
|
31 |
-
add_action('wp', array(&$this, 'wp'));
|
32 |
}
|
33 |
|
34 |
-
|
|
|
|
|
|
|
35 |
{
|
36 |
-
|
|
|
|
|
|
|
37 |
}
|
38 |
|
|
|
|
|
|
|
39 |
public function add_button($buttons = array())
|
40 |
{
|
41 |
array_unshift($buttons, '|');
|
@@ -43,27 +38,36 @@ class TinyMCETemplate{
|
|
43 |
return $buttons;
|
44 |
}
|
45 |
|
46 |
-
|
|
|
|
|
|
|
47 |
global $wp_rewrite;
|
48 |
-
$
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
}
|
53 |
|
54 |
-
|
|
|
|
|
|
|
55 |
global $wp_rewrite;
|
56 |
-
$new_rules['mce_templates.js$'] = $wp_rewrite->index . '?mce_templates=1';
|
57 |
-
$rules = array_merge($new_rules, $rules);
|
58 |
-
return $rules;
|
59 |
-
}
|
60 |
-
|
61 |
-
public function query_vars($vars) {
|
62 |
-
$vars[] = 'mce_templates';
|
63 |
-
return $vars;
|
64 |
-
}
|
65 |
-
|
66 |
-
public function wp(){
|
67 |
if (get_query_var('mce_templates')) {
|
68 |
global $wpdb;
|
69 |
global $user_login;
|
@@ -75,7 +79,7 @@ class TinyMCETemplate{
|
|
75 |
}
|
76 |
|
77 |
if( isset($_GET['id']) && strlen($_GET['id']) ){
|
78 |
-
$sql = "select html from
|
79 |
where (`ID`=%s) and (`author`={$current_user->ID} or `share`=1)
|
80 |
order by `modified` desc";
|
81 |
$sql = $wpdb->prepare($sql, $_GET['id']);
|
@@ -86,7 +90,7 @@ class TinyMCETemplate{
|
|
86 |
exit;
|
87 |
}
|
88 |
|
89 |
-
$sql = "select * from
|
90 |
where `author`={$current_user->ID} or `share`=1
|
91 |
order by `modified` desc";
|
92 |
$row = $wpdb->get_results($sql);
|
@@ -94,11 +98,16 @@ class TinyMCETemplate{
|
|
94 |
header( 'Content-Type: application/x-javascript; charset=UTF-8' );
|
95 |
echo 'var tinyMCETemplateList = [';
|
96 |
$arr = array();
|
|
|
|
|
|
|
|
|
|
|
97 |
foreach ($row as $tpl) {
|
98 |
$ID = esc_html($tpl->ID);
|
99 |
$name = $tpl->name;
|
100 |
$desc = esc_html($tpl->desc);
|
101 |
-
$arr[] = "[\"{$name}\", \"
|
102 |
}
|
103 |
echo join(',', $arr);
|
104 |
echo ']';
|
4 |
|
5 |
class TinyMCETemplate{
|
6 |
|
7 |
+
private $list_url = null;
|
8 |
|
9 |
function __construct()
|
10 |
{
|
11 |
+
new AddRewriteRules(
|
12 |
+
'mce_templates.js$',
|
13 |
+
'mce_templates',
|
14 |
+
array(&$this, 'get_templates')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
);
|
16 |
+
add_filter('mce_css', array(&$this, 'addStyle'));
|
17 |
+
add_action('init', array(&$this, 'loadTinyMCEPlugin'));
|
|
|
|
|
|
|
|
|
18 |
}
|
19 |
|
20 |
+
//
|
21 |
+
// add css tinyMCE content
|
22 |
+
//
|
23 |
+
public function addStyle($css)
|
24 |
{
|
25 |
+
$files = preg_split("/,/", $css);
|
26 |
+
$files[] = TINYMCE_TEMPLATES_PLUGIN_URL.'/editor.css';
|
27 |
+
$files = array_map('trim', $files);
|
28 |
+
return join(",", $files);
|
29 |
}
|
30 |
|
31 |
+
//
|
32 |
+
// add button to tinyMCE editor
|
33 |
+
//
|
34 |
public function add_button($buttons = array())
|
35 |
{
|
36 |
array_unshift($buttons, '|');
|
38 |
return $buttons;
|
39 |
}
|
40 |
|
41 |
+
//
|
42 |
+
// load tinyMCE plugin
|
43 |
+
//
|
44 |
+
public function loadTinyMCEPlugin(){
|
45 |
global $wp_rewrite;
|
46 |
+
$plugin = TINYMCE_TEMPLATES_PLUGIN_URL.'/mce_plugins/plugins/template/editor_plugin.js';
|
47 |
+
$path = dirname(__FILE__).'/../mce_plugins/plugins';
|
48 |
+
$lang = $path.'/template/langs/langs.php';
|
49 |
+
$inits = array();
|
50 |
+
$url = get_bloginfo('url');
|
51 |
+
if ($wp_rewrite->using_permalinks()) {
|
52 |
+
$this->list_url = $url.'/mce_templates.js';
|
53 |
+
} else {
|
54 |
+
$this->list_url = $url.'/?mce_templates=1';
|
55 |
}
|
56 |
+
$inits['template_external_list_url'] = $this->list_url;
|
57 |
+
new mcePlugins(
|
58 |
+
'template',
|
59 |
+
$plugin,
|
60 |
+
$lang,
|
61 |
+
array(&$this, 'add_button'),
|
62 |
+
$inits
|
63 |
+
);
|
64 |
}
|
65 |
|
66 |
+
//
|
67 |
+
// return display templates as JSON
|
68 |
+
//
|
69 |
+
public function get_templates(){
|
70 |
global $wp_rewrite;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
if (get_query_var('mce_templates')) {
|
72 |
global $wpdb;
|
73 |
global $user_login;
|
79 |
}
|
80 |
|
81 |
if( isset($_GET['id']) && strlen($_GET['id']) ){
|
82 |
+
$sql = "select html from ".TINYMCE_TEMPLATES_TABLE."
|
83 |
where (`ID`=%s) and (`author`={$current_user->ID} or `share`=1)
|
84 |
order by `modified` desc";
|
85 |
$sql = $wpdb->prepare($sql, $_GET['id']);
|
90 |
exit;
|
91 |
}
|
92 |
|
93 |
+
$sql = "select * from ".TINYMCE_TEMPLATES_TABLE."
|
94 |
where `author`={$current_user->ID} or `share`=1
|
95 |
order by `modified` desc";
|
96 |
$row = $wpdb->get_results($sql);
|
98 |
header( 'Content-Type: application/x-javascript; charset=UTF-8' );
|
99 |
echo 'var tinyMCETemplateList = [';
|
100 |
$arr = array();
|
101 |
+
if ($wp_rewrite->using_permalinks()) {
|
102 |
+
$list_url = $this->list_url.'?';
|
103 |
+
} else {
|
104 |
+
$list_url = $this->list_url.'&';
|
105 |
+
}
|
106 |
foreach ($row as $tpl) {
|
107 |
$ID = esc_html($tpl->ID);
|
108 |
$name = $tpl->name;
|
109 |
$desc = esc_html($tpl->desc);
|
110 |
+
$arr[] = "[\"{$name}\", \"{$list_url}id={$ID}\", \"{$desc}\"]";
|
111 |
}
|
112 |
echo join(',', $arr);
|
113 |
echo ']';
|
includes/addrewriterules.class.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright (c) 2010 Takayuki Miyauchi (THETA NETWORKS Co,.Ltd).
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in
|
13 |
+
all copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21 |
+
THE SOFTWARE.
|
22 |
+
*/
|
23 |
+
|
24 |
+
if (!class_exists('AddRewriteRules')):
|
25 |
+
class AddRewriteRules{
|
26 |
+
|
27 |
+
private $rule = null;
|
28 |
+
private $query = null;
|
29 |
+
private $callback = null;
|
30 |
+
|
31 |
+
function __construct($rule, $query, $callback){
|
32 |
+
$this->rule = $rule;
|
33 |
+
$this->query = $query;
|
34 |
+
$this->callback = $callback;
|
35 |
+
add_filter('query_vars', array(&$this, 'query_vars'));
|
36 |
+
add_filter('rewrite_rules_array', array(&$this, 'rewrite_rules_array'));
|
37 |
+
add_action('init', array(&$this, 'init'));
|
38 |
+
add_action('wp', array(&$this, 'wp'));
|
39 |
+
}
|
40 |
+
|
41 |
+
public function init()
|
42 |
+
{
|
43 |
+
global $wp_rewrite;
|
44 |
+
$rules = $wp_rewrite->wp_rewrite_rules();
|
45 |
+
if (!isset($rules[$this->rule])) {
|
46 |
+
$wp_rewrite->flush_rules();
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
public function rewrite_rules_array($rules)
|
51 |
+
{
|
52 |
+
global $wp_rewrite;
|
53 |
+
$new_rules[$this->rule] = $wp_rewrite->index . '?'.$this->query.'=1';
|
54 |
+
$rules = array_merge($new_rules, $rules);
|
55 |
+
return $rules;
|
56 |
+
}
|
57 |
+
|
58 |
+
public function query_vars($vars)
|
59 |
+
{
|
60 |
+
$vars[] = $this->query;
|
61 |
+
return $vars;
|
62 |
+
}
|
63 |
+
|
64 |
+
public function wp()
|
65 |
+
{
|
66 |
+
if (get_query_var($this->query)) {
|
67 |
+
call_user_func($this->callback);
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
endif;
|
72 |
+
|
73 |
+
?>
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://firegoby.theta.ne.jp/
|
|
4 |
Tags: tinymce, Visual Editor, template
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.0
|
7 |
-
Stable tag: 0.
|
8 |
|
9 |
TinyMCE Template plugin will enable to use HTML template on WordPress Visual Editor.
|
10 |
You can edit and share this template with WordPress users.
|
@@ -17,7 +17,7 @@ You can edit and share this template with WordPress users.
|
|
17 |
If you will install this plugin, You will be very easy to edit posts and pages.
|
18 |
|
19 |
* [Plugin Homepage](http://firegoby.theta.ne.jp/wp/tinymce_templates) (Japanese)
|
20 |
-
* [Support](http://wordpress.org/tags/
|
21 |
|
22 |
= Some features: =
|
23 |
|
4 |
Tags: tinymce, Visual Editor, template
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.0
|
7 |
+
Stable tag: 0.3
|
8 |
|
9 |
TinyMCE Template plugin will enable to use HTML template on WordPress Visual Editor.
|
10 |
You can edit and share this template with WordPress users.
|
17 |
If you will install this plugin, You will be very easy to edit posts and pages.
|
18 |
|
19 |
* [Plugin Homepage](http://firegoby.theta.ne.jp/wp/tinymce_templates) (Japanese)
|
20 |
+
* [Support](http://wordpress.org/tags/tinymce-templates)
|
21 |
|
22 |
= Some features: =
|
23 |
|
tinymce_templates.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: TinyMCE Templates
|
4 |
-
Plugin URI: http://firegoby.theta.ne.jp/wp/
|
5 |
Description: Manage & Add Tiny MCE template.
|
6 |
Author: Takayuki Miyauchi (THETA NETWORKS Co,.Ltd)
|
7 |
-
Version: 0.
|
8 |
Author URI: http://firegoby.theta.ne.jp/
|
9 |
*/
|
10 |
|
@@ -31,7 +31,10 @@ THE SOFTWARE.
|
|
31 |
*/
|
32 |
|
33 |
define('TINYMCE_TEMPLATES_PLUGIN_URL', WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)));
|
|
|
|
|
34 |
|
|
|
35 |
require_once(dirname(__FILE__).'/includes/mceplugins.class.php');
|
36 |
require_once(dirname(__FILE__).'/includes/TinyMCETemplate.class.php');
|
37 |
require_once(dirname(__FILE__).'/includes/MceTemplatesAdmin.class.php');
|
@@ -42,24 +45,18 @@ register_deactivation_hook (__FILE__, array(&$MceTemplates, 'deactivation'));
|
|
42 |
|
43 |
class MceTemplates{
|
44 |
|
45 |
-
var $name = 'tinymce_templates';
|
46 |
-
var $table = 'mce_template';
|
47 |
-
|
48 |
//
|
49 |
// construct
|
50 |
//
|
51 |
-
function
|
52 |
{
|
53 |
add_action('admin_menu', array(&$this, 'loadAdmin'));
|
54 |
}
|
55 |
|
56 |
-
function activation()
|
57 |
{
|
58 |
global $wpdb;
|
59 |
-
|
60 |
-
$this->table = $wpdb->prefix.$this->table;
|
61 |
-
|
62 |
-
$sql = "CREATE TABLE ".$this->table." (
|
63 |
`ID` varchar(32) NOT NULL,
|
64 |
`name` varchar(50) NOT NULL,
|
65 |
`desc` varchar(100) NOT NULL,
|
@@ -76,7 +73,7 @@ class MceTemplates{
|
|
76 |
dbDelta($sql);
|
77 |
}
|
78 |
|
79 |
-
function deactivation()
|
80 |
{
|
81 |
// nothing to do
|
82 |
}
|
@@ -84,34 +81,34 @@ class MceTemplates{
|
|
84 |
//
|
85 |
// add admin menu
|
86 |
//
|
87 |
-
function loadAdmin()
|
88 |
{
|
89 |
load_plugin_textdomain(
|
90 |
-
|
91 |
PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/langs',
|
92 |
dirname(plugin_basename(__FILE__)).'/langs'
|
93 |
);
|
94 |
|
95 |
add_menu_page(
|
96 |
-
__('tinyMCE Templates',
|
97 |
-
__('Templates',
|
98 |
'edit_pages',
|
99 |
'edittemplates',
|
100 |
'',
|
101 |
-
|
102 |
);
|
103 |
add_submenu_page(
|
104 |
'edittemplates',
|
105 |
-
__('Edit Templates',
|
106 |
-
__('Edit',
|
107 |
'edit_pages',
|
108 |
'edittemplates',
|
109 |
array(&$this, 'adminPage')
|
110 |
);
|
111 |
add_submenu_page(
|
112 |
'edittemplates',
|
113 |
-
__('Add New Templates',
|
114 |
-
__('Add New',
|
115 |
'edit_pages',
|
116 |
'addnewtemplates',
|
117 |
array(&$this, 'adminPage')
|
@@ -122,9 +119,9 @@ class MceTemplates{
|
|
122 |
//
|
123 |
// display mcetemplates list
|
124 |
//
|
125 |
-
function adminPage()
|
126 |
{
|
127 |
-
new MceTemplatesAdmin(
|
128 |
}
|
129 |
|
130 |
}
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: TinyMCE Templates
|
4 |
+
Plugin URI: http://firegoby.theta.ne.jp/wp/tinymce_templates
|
5 |
Description: Manage & Add Tiny MCE template.
|
6 |
Author: Takayuki Miyauchi (THETA NETWORKS Co,.Ltd)
|
7 |
+
Version: 0.3
|
8 |
Author URI: http://firegoby.theta.ne.jp/
|
9 |
*/
|
10 |
|
31 |
*/
|
32 |
|
33 |
define('TINYMCE_TEMPLATES_PLUGIN_URL', WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)));
|
34 |
+
define('TINYMCE_TEMPLATES_TABLE', $wpdb->prefix.'mce_template');
|
35 |
+
define('TINYMCE_TEMPLATES_DOMAIN', 'tinymce_templates');
|
36 |
|
37 |
+
require_once(dirname(__FILE__).'/includes/addrewriterules.class.php');
|
38 |
require_once(dirname(__FILE__).'/includes/mceplugins.class.php');
|
39 |
require_once(dirname(__FILE__).'/includes/TinyMCETemplate.class.php');
|
40 |
require_once(dirname(__FILE__).'/includes/MceTemplatesAdmin.class.php');
|
45 |
|
46 |
class MceTemplates{
|
47 |
|
|
|
|
|
|
|
48 |
//
|
49 |
// construct
|
50 |
//
|
51 |
+
function __construct()
|
52 |
{
|
53 |
add_action('admin_menu', array(&$this, 'loadAdmin'));
|
54 |
}
|
55 |
|
56 |
+
public function activation()
|
57 |
{
|
58 |
global $wpdb;
|
59 |
+
$sql = "CREATE TABLE {$wpdb->prefix}mce_template (
|
|
|
|
|
|
|
60 |
`ID` varchar(32) NOT NULL,
|
61 |
`name` varchar(50) NOT NULL,
|
62 |
`desc` varchar(100) NOT NULL,
|
73 |
dbDelta($sql);
|
74 |
}
|
75 |
|
76 |
+
public function deactivation()
|
77 |
{
|
78 |
// nothing to do
|
79 |
}
|
81 |
//
|
82 |
// add admin menu
|
83 |
//
|
84 |
+
public function loadAdmin()
|
85 |
{
|
86 |
load_plugin_textdomain(
|
87 |
+
TINYMCE_TEMPLATES_DOMAIN,
|
88 |
PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/langs',
|
89 |
dirname(plugin_basename(__FILE__)).'/langs'
|
90 |
);
|
91 |
|
92 |
add_menu_page(
|
93 |
+
__('tinyMCE Templates', TINYMCE_TEMPLATES_DOMAIN),
|
94 |
+
__('Templates', TINYMCE_TEMPLATES_DOMAIN),
|
95 |
'edit_pages',
|
96 |
'edittemplates',
|
97 |
'',
|
98 |
+
TINYMCE_TEMPLATES_PLUGIN_URL.'/img/icon.png'
|
99 |
);
|
100 |
add_submenu_page(
|
101 |
'edittemplates',
|
102 |
+
__('Edit Templates', TINYMCE_TEMPLATES_DOMAIN),
|
103 |
+
__('Edit', TINYMCE_TEMPLATES_DOMAIN),
|
104 |
'edit_pages',
|
105 |
'edittemplates',
|
106 |
array(&$this, 'adminPage')
|
107 |
);
|
108 |
add_submenu_page(
|
109 |
'edittemplates',
|
110 |
+
__('Add New Templates', TINYMCE_TEMPLATES_DOMAIN),
|
111 |
+
__('Add New', TINYMCE_TEMPLATES_DOMAIN),
|
112 |
'edit_pages',
|
113 |
'addnewtemplates',
|
114 |
array(&$this, 'adminPage')
|
119 |
//
|
120 |
// display mcetemplates list
|
121 |
//
|
122 |
+
public function adminPage()
|
123 |
{
|
124 |
+
new MceTemplatesAdmin();
|
125 |
}
|
126 |
|
127 |
}
|