Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 82 lines (76 sloc) 2.804 kb
4f9ff89f »
2011-02-09 Plugins
1 <?php
2
cd6d2fc7 »
2011-02-09 Typos
3 /** Edit all fields containing "_html" by HTML editor TinyMCE and display the HTML in select
35c8c922 »
2011-02-18 Escaping
4 * @uses TinyMCE, http://tinymce.moxiecode.com/
4f9ff89f »
2011-02-09 Plugins
5 * @author Jakub Vrana, http://www.vrana.cz/
6 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
8 */
9 class AdminerTinymce {
75783421 »
2011-08-11 Comment
10 /** @access protected */
4f9ff89f »
2011-02-09 Plugins
11 var $path;
12
13 /**
14 * @param string
15 */
16 function AdminerTinymce($path = "tiny_mce/tiny_mce.js") {
17 $this->path = $path;
18 }
19
00342a15 »
2011-05-31 Init TinyMCE in head
20 function head() {
21 $lang = "en";
22 if (function_exists('get_lang')) { // since Adminer 3.2.0
23 $lang = get_lang();
24 $lang = ($lang == "zh" ? "zh-cn" : ($lang == "zh-tw" ? "zh" : $lang));
25 if (!file_exists(dirname($this->path) . "/langs/$lang.js")) {
26 $lang = "en";
27 }
28 }
29 ?>
30 <script type="text/javascript" src="<?php echo h($this->path); ?>"></script>
31 <script type="text/javascript">
32 tinyMCE.init({
33 mode: 'none',
34 theme: 'advanced',
35 plugins: 'contextmenu,paste,table',
36 entity_encoding: 'raw',
37 theme_advanced_buttons1: 'bold,italic,link,unlink,|,sub,sup,|,bullist,numlist,|,cleanup,code',
38 theme_advanced_buttons2: 'tablecontrols',
39 theme_advanced_buttons3: '',
40 theme_advanced_toolbar_location: 'top',
41 theme_advanced_toolbar_align: 'left',
42 language: '<?php echo $lang; ?>'
43 });
44 </script>
45 <?php
46 }
47
4f9ff89f »
2011-02-09 Plugins
48 function selectVal(&$val, $link, $field) {
49 if (ereg("_html", $field["field"]) && $val != '&nbsp;') {
374e39eb »
2011-04-12 Close opened tags
50 $shortened = (substr($val, -10) == "<i>...</i>");
51 if ($shortened) {
52 $val = substr($val, 0, -10);
53 }
54 //! shorten with regard to HTML tags - http://php.vrana.cz/zkraceni-textu-s-xhtml-znackami.php
55 $val = preg_replace('~<[^>]*$~', '', html_entity_decode($val, ENT_QUOTES)); // remove ending incomplete tag (text can be shortened)
56 if ($shortened) {
57 $val .= "<i>...</i>";
58 }
59 if (class_exists('DOMDocument')) { // close all opened tags
60 $dom = new DOMDocument;
61 if (@$dom->loadHTML("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head>$val")) { // @ - $val can contain errors
62 $val = preg_replace('~.*<body[^>]*>(.*)</body>.*~is', '\\1', $dom->saveHTML());
63 }
64 }
4f9ff89f »
2011-02-09 Plugins
65 }
66 }
67
68 function editInput($table, $field, $attrs, $value) {
69 if (ereg("text", $field["type"]) && ereg("_html", $field["field"])) {
c2965bc8 »
2011-06-13 Save TinyMCE under AJAX
70 return "<textarea$attrs id='fields-" . h($field["field"]) . "' rows='12' cols='50'>" . h($value) . "</textarea><script type='text/javascript'>
71 tinyMCE.remove(tinyMCE.get('fields-" . js_escape($field["field"]) . "') || { });
72 tinyMCE.execCommand('mceAddControl', true, 'fields-" . js_escape($field["field"]) . "');
73 document.getElementById('form').onsubmit = function () {
74 tinyMCE.each(tinyMCE.editors, function (ed) {
75 ed.remove();
76 });
77 };
78 </script>";
4f9ff89f »
2011-02-09 Plugins
79 }
80 }
81
82 }
Something went wrong with that request. Please try again.