Skip to content
Newer
Older
100644 43 lines (38 sloc) 1.47 KB
4f9ff89 @vrana Plugins
authored Feb 9, 2011
1 <?php
2
cd6d2fc @vrana Typos
authored Feb 9, 2011
3 /** Prefill field containing "_slug" with slugified value of a previous field (JavaScript)
091a4d0 @vrana Link to documentation
authored Jun 30, 2012
4 * @link http://www.adminer.org/plugins/#use
4f9ff89 @vrana Plugins
authored Feb 9, 2011
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 AdminerSlugify {
7578342 @vrana Comment
authored Aug 11, 2011
10 /** @access protected */
4f9ff89 @vrana Plugins
authored Feb 9, 2011
11 var $from, $to;
12
13 /**
14 * @param string find these characters ...
15 * @param string ... and replace them by these
16 */
17 function AdminerSlugify($from = 'áčďéěíňóřšťúůýž', $to = 'acdeeinorstuuyz') {
18 $this->from = $from;
19 $this->to = $to;
20 }
21
22 function editInput($table, $field, $attrs, $value) {
23 static $slugify;
24 if (!$_GET["select"] && !$_GET["where"]) {
6591d48 @vrana Replace isset($var) by $var !== null
authored May 13, 2012
25 if ($slugify === null) {
4f9ff89 @vrana Plugins
authored Feb 9, 2011
26 $slugify = array();
27 $prev = null;
1c768e8 @vrana Typo (bug #3366317)
authored Jul 14, 2011
28 foreach (fields($table) as $name => $val) {
4f9ff89 @vrana Plugins
authored Feb 9, 2011
29 if ($prev && ereg('(^|_)slug(_|$)', $name)) {
30 $slugify[$prev] = $name;
31 }
32 $prev = $name;
33 }
34 }
35 $slug = $slugify[$field["field"]];
6591d48 @vrana Replace isset($var) by $var !== null
authored May 14, 2012
36 if ($slug !== null) {
4f9ff89 @vrana Plugins
authored Feb 9, 2011
37 return "<input value='" . h($value) . "' maxlength='$field[length]' size='40'$attrs onchange=\"var find = '$this->from'; var repl = '$this->to'; this.form['fields[$slug]'].value = this.value.toLowerCase().replace(new RegExp('[' + find + ']', 'g'), function (str) { return repl[find.indexOf(str)]; }).replace(/[^a-z0-9_]+/g, '-').replace(/^-|-\$/g, '').substr(0, $field[length]);\">";
38 }
39 }
40 }
41
42 }
Something went wrong with that request. Please try again.