forked from OtkurBiz/UyghurCharUtilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtendUyghurCharacters.class.php
132 lines (100 loc) · 2.42 KB
/
ExtendUyghurCharacters.class.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* Extend Uyghur characters Class for the mobile wap pages
*
* @author Alim Boyaq<boyaq@otkur.biz>
* @version 1.0.2
* @link
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class ExtendUyghurCharacters
{
/**
* devices that not support uyghur language by default
*
* @var array
**/
private $devices;
/**
* systems that not support uyghur language by default
*
* @var array
**/
private $systems;
/**
* browsers that not support uyghur language by default
*
* @var array
**/
private $browsers;
/**
* user agent of the client
*
* @var string
**/
private $ua;
private static $instance;
public static function getInstance()
{
if (null === static::$instance) {
static::$instance = new static();
}
return static::$instance;
}
protected function __construct()
{
$this->devices = require_once(dirname(__FILE__) . "/config/devices.php");
$this->systems = require_once(dirname(__FILE__) . "/config/systems.php");
$this->browsers = require_once(dirname(__FILE__) . "/config/browsers.php");
}
private function __clone()
{
}
private function __wakeup()
{
}
public function getExtendedMessage($text){
$this->ua = $_SERVER['HTTP_USER_AGENT'];
if( $this->isUnsupportedBrowser() || $this->isUnsupportedSystem() || $this->isUnsupportedDevice() ){
$text = $this->replaceSymbles($text);
$uyghurCharUtilities = new UyghurCharUtilities();
return $uyghurCharUtilities->getUyPFStr($text);
}
return $text;
}
public function replaceSymbles($text){
if(empty($text)) return $text;
$text = preg_replace("/،/", ", ", $text);
$text = preg_replace("/ـ/", "", $text);
$text = preg_replace("/؟/", "?", $text);
$text = preg_replace("/؛/", ";", $text);
$text = preg_replace("/»/", ">>", $text);
$text = preg_replace("/«/", "<<", $text);
$text = preg_replace("/&nbsp;/",' ', $text);
return $text;
}
protected function isUnsupportedBrowser(){
foreach($this->browsers as $browserUA){
if(strpos($this->ua, $browserUA) !== false){
return true;
}
}
return false;
}
protected function isUnsupportedSystem(){
foreach($this->systems as $systemUA){
if(strpos($this->ua, $systemUA) !== false){
return true;
}
}
return false;
}
protected function isUnsupportedDevice(){
foreach($this->devices as $deviceUA){
if(strpos($this->ua, $deviceUA) !== false){
return true;
}
}
return false;
}
}