-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzjtk.php
79 lines (79 loc) · 2.23 KB
/
zjtk.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
<?php
/**
* ZJTK
*
* @author Zoxuyu
* @version 1.0.0
*/
class Alias
{
private $prefix_divider = "-";
private $suffix_divider = "-";
private $alias_replacements_prefixes = array();
private $language_suffixes = array();
private $alias;
function __construct()
{
$app = JFactory::getApplication();
$id = JRequest::getInt('id');
$article =& JTable::getInstance('content');
$article->load($id);
$alias = $article->get('alias');
if($alias == "")
{
$alias = $app->getMenu()->getActive()->alias;
}
$this->alias = $alias;
}
function AddPrefix($prefix, $replacement)
{
$this->alias_replacements_prefixes[$prefix] = $replacement;
}
function AddLanguage($suffix, $replacement)
{
$this->language_suffixes[$suffix] = $replacement;
}
function GetAlias() { return $this->alias; }
function GetPuredAlias()
{
$alias = $this->alias;
foreach($this->alias_replacements_prefixes as $shortsfx => $longsfx)
{
foreach($this->language_suffixes as $shortprx => $longprx)
{
$prefix_divider = $this->prefix_divider;
$suffix_divider = $this->suffix_divider;
if(preg_match("/{$shortsfx}{$prefix_divider}(.*){$suffix_divider}{$shortprx}/", $alias, $mtchs))
{
return "$longsfx $mtchs[1] $longprx";
}
}
if(preg_match("/{$shortsfx}{$prefix_divider}(.*)/", $alias, $mtchs))
{
return "$longsfx $mtchs[1]";
}
}
foreach($this->language_suffixes as $shortprx => $longprx)
{
$prefix_divider = $this->prefix_divider;
$suffix_divider = $this->suffix_divider;
if(preg_match("/(.*){$suffix_divider}{$shortprx}/", $alias, $mtchs))
{
return "$mtchs[1] $longprx";
}
}
return $alias;
}
function Config($what, $how)
{
if($what=="suffixDivider")
{
$this->suffix_divider = $how;
}
if($what=="prefixDivider")
{
$this->prefix_divider = $how;
}
}
}
?>