Skip to content
Newer
Older
100644 42 lines (37 sloc) 1.43 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)
4f9ff89 @vrana Plugins
authored Feb 9, 2011
4 * @author Jakub Vrana, http://www.vrana.cz/
5 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
6 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
7 */
8 class AdminerSlugify {
7578342 @vrana Comment
authored Aug 11, 2011
9 /** @access protected */
4f9ff89 @vrana Plugins
authored Feb 9, 2011
10 var $from, $to;
11
12 /**
13 * @param string find these characters ...
14 * @param string ... and replace them by these
15 */
16 function AdminerSlugify($from = 'áčďéěíňóřšťúůýž', $to = 'acdeeinorstuuyz') {
17 $this->from = $from;
18 $this->to = $to;
19 }
20
21 function editInput($table, $field, $attrs, $value) {
22 static $slugify;
23 if (!$_GET["select"] && !$_GET["where"]) {
6591d48 @vrana Replace isset($var) by $var !== null
authored May 13, 2012
24 if ($slugify === null) {
4f9ff89 @vrana Plugins
authored Feb 9, 2011
25 $slugify = array();
26 $prev = null;
1c768e8 @vrana Typo (bug #3366317)
authored Jul 14, 2011
27 foreach (fields($table) as $name => $val) {
4f9ff89 @vrana Plugins
authored Feb 9, 2011
28 if ($prev && ereg('(^|_)slug(_|$)', $name)) {
29 $slugify[$prev] = $name;
30 }
31 $prev = $name;
32 }
33 }
34 $slug = $slugify[$field["field"]];
6591d48 @vrana Replace isset($var) by $var !== null
authored May 14, 2012
35 if ($slug !== null) {
4f9ff89 @vrana Plugins
authored Feb 9, 2011
36 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]);\">";
37 }
38 }
39 }
40
41 }
Something went wrong with that request. Please try again.