This repository was archived by the owner on Nov 15, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwavelet.php
92 lines (77 loc) · 3.21 KB
/
wavelet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
// No direct access.
defined('_JEXEC') or die;
/**
* Email cloack wavelet class.
*
* @package Joomla.Plugin
* @subpackage Content.wavelet
*/
class plgContentWavelet extends JPlugin {
public function onContentPrepare($context, &$row, &$params, $page = 0) {
// Don't run this plugin when the content is being indexed
if ($context == 'com_finder.indexer') {
return true;
}
if (is_object($row)) {
return $this->_waveletDo($row->text, $params);
}
return $this->_waveletDo($row, $params);
}
protected function _waveletDo(&$text, &$params) {
$preps = $this->params->get('preps', 1);
$units = $this->params->get('units', 1);
$titles = $this->params->get('titles', 1);
$num_groups = $this->params->get('num_groups', 1);
$deg_perc = $this->params->get('deg_perc', 1);
$pattern = array();
$replace = array();
//Handle prepositions - generate patterns
if ($preps == 1) {
$PREPS = array("k", "s", "v", "z", "o", "u", "i", "a", "do", "ke", "ku", "na", "od", "po", "se", "ve", "za", "ze", "že", "až", "oč", "už", "K", "S", "V", "Z", "O", "U", "I", "A", "Do", "Ke", "Ku", "Na", "Od", "Po", "Se", "Ve", "Za", "Ze", "Že", "Až", "Oč", "Už");
for ($i = 0; $i < count($PREPS); $i++) {
$pattern[] = "/([ (\.>])$PREPS[$i] /";
$replace[] = '\1' . $PREPS[$i] . ' ';
}
}
if ($units == 1) {
//Handle units - generate patterns
$UNITS = array("cl", "cm", "dl", "dm", "g", "hl", "sk", "kg", "km", "ks", "l", "m", "mg", "ml", "mm", "t", "kč", "Kč");
for ($i = 0; $i < count($UNITS); $i++) {
$pattern[] = "/ $UNITS[$i]([ )\.<])/";
$replace[] = ' ' . $UNITS[$i] . '\1';
}
}
if ($titles == 1) {
//Handle titles - generate patterns
//before name
$TITLES = array("Doc", "Dr", "gen", "Ing", "JUDr", "kpt", "Mgr", "mjr", "MUDr", "MVDr", "p", "PaeDr", "PhDr", "pí", "ppor", "pplk", "Prof", "RNDr", "sl");
for ($i = 0; $i < count($TITLES); $i++) {
$pattern[] = "/([ (\.>])$TITLES[$i]\. /";
$replace[] = '\1' . $TITLES[$i] . '. ';
}
//after name
$TITLES = array("DiS\.", "dis\.", "Dis\.", "dr\. h\. c\.", "dr\.h\.c\.", "DrSc\.", "CSc\.", "Th\.D\.", "Ph\.D\.");
for ($i = 0; $i < count($TITLES); $i++) {
$pattern[] = "/([a-zěščřžýáíéúůďňť]) $TITLES[$i]/";
$replace[] = '\1 ' . $TITLES[$i];
}
}
if ($num_groups == 1) {
//Handle number groups - generate patterns
$pattern[] = "/(?<=[\d+]) (\d+)/";
$replace[] = ' \1';
}
if ($deg_perc == 1) {
//Handle degrees and percents
$pattern[] = "/(?<=[\d+|[:alpha:]]) ([%|°])/";
$replace[] = ' \1';
}
//Real replacement in text
if (count($pattern) > 0) {
$text = preg_replace($pattern, $replace, $text);
}
//END
return true;
}
}