Completed
Push — master ( fc3bc1...47a19f )
by kill
07:04
created
core/helpers/TimeAgo.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -50,6 +50,10 @@
 block discarded – undo
50 50
         $this->restoreTimezone();
51 51
     }
52 52
 
53
+    /**
54
+     * @param integer $past
55
+     * @param integer $now
56
+     */
53 57
     public function inStamp($past, $now = null) {
54 58
         if($now==null){
55 59
             $now=time();
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -10,15 +10,15 @@  discard block
 block discarded – undo
10 10
 class TimeAgo
11 11
 {
12 12
     // defines the number of seconds per "unit"
13
-    private $secondsPerMinute = 60;
14
-    private $secondsPerHour = 3600;
15
-    private $secondsPerDay = 86400;
16
-    private $secondsPerMonth = 2592000;
17
-    private $secondsPerYear = 31536000; // 31622400 seconds on leap years though...
13
+    private $secondsPerMinute=60;
14
+    private $secondsPerHour=3600;
15
+    private $secondsPerDay=86400;
16
+    private $secondsPerMonth=2592000;
17
+    private $secondsPerYear=31536000; // 31622400 seconds on leap years though...
18 18
     private $timezone;
19 19
     private $previousTimezone;
20 20
 
21
-    private static $timeAgoStrings = array(
21
+    private static $timeAgoStrings=array(
22 22
         'aboutOneDay' => "1 天前",
23 23
         'aboutOneHour' => "大约 1 小时前",
24 24
         'aboutOneMonth' => "大约 1 个月前",
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
      * TimeAgo constructor.
37 37
      * @param null|DateTimeZone $timezone the timezone to use (uses system if none is given)
38 38
      */
39
-    public function __construct($timezone = null)
39
+    public function __construct($timezone=null)
40 40
     {
41
-        $this->timezone = $timezone;
41
+        $this->timezone=$timezone;
42 42
         // sets the default timezone
43 43
         $this->changeTimezone();
44 44
     }
@@ -50,84 +50,84 @@  discard block
 block discarded – undo
50 50
         $this->restoreTimezone();
51 51
     }
52 52
 
53
-    public function inStamp($past, $now = null) {
54
-        if($now==null){
53
+    public function inStamp($past, $now=null) {
54
+        if ($now == null) {
55 55
             $now=time();
56 56
         }
57 57
         // creates the "time ago" string. This always starts with an "about..."
58
-        $timeAgo = "";
58
+        $timeAgo="";
59 59
 
60 60
         // finds the time difference
61
-        $timeDifference = $now - $past;
61
+        $timeDifference=$now - $past;
62 62
         // rule 0
63 63
         // $past is null or empty or ''
64
-        if ($past==0) {
65
-            $timeAgo = $this->translate('never');
64
+        if ($past == 0) {
65
+            $timeAgo=$this->translate('never');
66 66
         }
67 67
         // rule 1
68 68
         // less than 29secs
69 69
         else if ($this->isLessThan29Seconds($timeDifference)) {
70
-            $timeAgo = $this->translate('lessThanAMinute');
70
+            $timeAgo=$this->translate('lessThanAMinute');
71 71
         }
72 72
         // rule 2
73 73
         // more than 29secs and less than 1min29secss
74 74
         else if ($this->isLessThan1Min29Seconds($timeDifference)) {
75
-            $timeAgo = $this->translate('oneMinute');
75
+            $timeAgo=$this->translate('oneMinute');
76 76
         }
77 77
         // rule 3
78 78
         // between 1min30secs and 44mins29secs
79 79
         else if ($this->isLessThan44Min29Secs($timeDifference)) {
80
-            $minutes = round($timeDifference / $this->secondsPerMinute);
81
-            $timeAgo = $this->translate('lessThanOneHour', $minutes);
80
+            $minutes=round($timeDifference / $this->secondsPerMinute);
81
+            $timeAgo=$this->translate('lessThanOneHour', $minutes);
82 82
         }
83 83
         // rule 4
84 84
         // between 44mins30secs and 1hour29mins59secs
85 85
         else if ($this->isLessThan1Hour29Mins59Seconds($timeDifference)) {
86
-            $timeAgo = $this->translate('aboutOneHour');
86
+            $timeAgo=$this->translate('aboutOneHour');
87 87
         }
88 88
         // rule 5
89 89
         // between 1hour29mins59secs and 23hours59mins29secs
90 90
         else if ($this->isLessThan23Hours59Mins29Seconds($timeDifference)) {
91
-            $hours = round($timeDifference / $this->secondsPerHour);
92
-            $timeAgo = $this->translate('hours', $hours);
91
+            $hours=round($timeDifference / $this->secondsPerHour);
92
+            $timeAgo=$this->translate('hours', $hours);
93 93
         }
94 94
         // rule 6
95 95
         // between 23hours59mins30secs and 47hours59mins29secs
96 96
         else if ($this->isLessThan47Hours59Mins29Seconds($timeDifference)) {
97
-            $timeAgo = $this->translate('aboutOneDay');
97
+            $timeAgo=$this->translate('aboutOneDay');
98 98
         }
99 99
         // rule 7
100 100
         // between 47hours59mins30secs and 29days23hours59mins29secs
101 101
         else if ($this->isLessThan29Days23Hours59Mins29Seconds($timeDifference)) {
102
-            $days = round($timeDifference / $this->secondsPerDay);
103
-            $timeAgo = $this->translate('days', $days);
102
+            $days=round($timeDifference / $this->secondsPerDay);
103
+            $timeAgo=$this->translate('days', $days);
104 104
         }
105 105
         // rule 8
106 106
         // between 29days23hours59mins30secs and 59days23hours59mins29secs
107 107
         else if ($this->isLessThan59Days23Hours59Mins29Secs($timeDifference)) {
108
-            $timeAgo = $this->translate('aboutOneMonth');
108
+            $timeAgo=$this->translate('aboutOneMonth');
109 109
         }
110 110
         // rule 9
111 111
         // between 59days23hours59mins30secs and 1year (minus 1sec)
112 112
         else if ($this->isLessThan1Year($timeDifference)) {
113
-            $months = round($timeDifference / $this->secondsPerMonth);
113
+            $months=round($timeDifference / $this->secondsPerMonth);
114 114
             // if months is 1, then set it to 2, because we are "past" 1 month
115 115
             if ($months == 1) {
116
-                $months = 2;
116
+                $months=2;
117 117
             }
118 118
 
119
-            $timeAgo = $this->translate('months', $months);
119
+            $timeAgo=$this->translate('months', $months);
120 120
         }
121 121
         // rule 10
122 122
         // between 1year and 2years (minus 1sec)
123 123
         else if ($this->isLessThan2Years($timeDifference)) {
124
-            $timeAgo = $this->translate('aboutOneYear');
124
+            $timeAgo=$this->translate('aboutOneYear');
125 125
         }
126 126
         // rule 11
127 127
         // 2years or more
128 128
         else {
129
-            $years = floor($timeDifference / $this->secondsPerYear);
130
-            $timeAgo = $this->translate('years', $years);
129
+            $years=floor($timeDifference / $this->secondsPerYear);
130
+            $timeAgo=$this->translate('years', $years);
131 131
         }
132 132
 
133 133
         return $timeAgo;
@@ -139,18 +139,18 @@  discard block
 block discarded – undo
139 139
      * @param string $now the current time, defaults to now (can be an other time though)
140 140
      * @return string the difference in spoken format, e.g. 1 day ago
141 141
      */
142
-    public function inWords($past, $now = "now")
142
+    public function inWords($past, $now="now")
143 143
     {
144 144
 
145 145
         // finds the past in datetime
146
-        $past = strtotime($past);
146
+        $past=strtotime($past);
147 147
         // finds the current datetime
148
-        $now = strtotime($now);
148
+        $now=strtotime($now);
149 149
         if ($this->isPastEmpty($past)) {
150 150
             $past=0;
151 151
             $past=0;
152 152
         }
153
-        return $this->inStamp($past,$now);
153
+        return $this->inStamp($past, $now);
154 154
     }
155 155
 
156 156
     /**
@@ -161,23 +161,23 @@  discard block
 block discarded – undo
161 161
      * @param string $now the "now" time to parse
162 162
      * @return array the difference in dates, using the two dates
163 163
      */
164
-    public function dateDifference($past, $now = "now")
164
+    public function dateDifference($past, $now="now")
165 165
     {
166 166
         // initializes the placeholders for the different "times"
167
-        $seconds = 0;
168
-        $minutes = 0;
169
-        $hours = 0;
170
-        $days = 0;
171
-        $months = 0;
172
-        $years = 0;
167
+        $seconds=0;
168
+        $minutes=0;
169
+        $hours=0;
170
+        $days=0;
171
+        $months=0;
172
+        $years=0;
173 173
 
174 174
         // finds the past in datetime
175
-        $past = strtotime($past);
175
+        $past=strtotime($past);
176 176
         // finds the current datetime
177
-        $now = strtotime($now);
177
+        $now=strtotime($now);
178 178
 
179 179
         // calculates the difference
180
-        $timeDifference = $now - $past;
180
+        $timeDifference=$now - $past;
181 181
 
182 182
         // starts determining the time difference
183 183
         if ($timeDifference >= 0) {
@@ -185,46 +185,46 @@  discard block
 block discarded – undo
185 185
                 // finds the number of years
186 186
                 case ($timeDifference >= $this->secondsPerYear):
187 187
                     // uses floor to remove decimals
188
-                    $years = floor($timeDifference / $this->secondsPerYear);
188
+                    $years=floor($timeDifference / $this->secondsPerYear);
189 189
                     // saves the amount of seconds left
190
-                    $timeDifference = $timeDifference - ($years * $this->secondsPerYear);
190
+                    $timeDifference=$timeDifference - ($years * $this->secondsPerYear);
191 191
 
192 192
                 // finds the number of months
193 193
                 case ($timeDifference >= $this->secondsPerMonth && $timeDifference <= ($this->secondsPerYear - 1)):
194 194
                     // uses floor to remove decimals
195
-                    $months = floor($timeDifference / $this->secondsPerMonth);
195
+                    $months=floor($timeDifference / $this->secondsPerMonth);
196 196
                     // saves the amount of seconds left
197
-                    $timeDifference = $timeDifference - ($months * $this->secondsPerMonth);
197
+                    $timeDifference=$timeDifference - ($months * $this->secondsPerMonth);
198 198
 
199 199
                 // finds the number of days
200 200
                 case ($timeDifference >= $this->secondsPerDay && $timeDifference <= ($this->secondsPerYear - 1)):
201 201
                     // uses floor to remove decimals
202
-                    $days = floor($timeDifference / $this->secondsPerDay);
202
+                    $days=floor($timeDifference / $this->secondsPerDay);
203 203
                     // saves the amount of seconds left
204
-                    $timeDifference = $timeDifference - ($days * $this->secondsPerDay);
204
+                    $timeDifference=$timeDifference - ($days * $this->secondsPerDay);
205 205
 
206 206
                 // finds the number of hours
207 207
                 case ($timeDifference >= $this->secondsPerHour && $timeDifference <= ($this->secondsPerDay - 1)):
208 208
                     // uses floor to remove decimals
209
-                    $hours = floor($timeDifference / $this->secondsPerHour);
209
+                    $hours=floor($timeDifference / $this->secondsPerHour);
210 210
                     // saves the amount of seconds left
211
-                    $timeDifference = $timeDifference - ($hours * $this->secondsPerHour);
211
+                    $timeDifference=$timeDifference - ($hours * $this->secondsPerHour);
212 212
 
213 213
                 // finds the number of minutes
214 214
                 case ($timeDifference >= $this->secondsPerMinute && $timeDifference <= ($this->secondsPerHour - 1)):
215 215
                     // uses floor to remove decimals
216
-                    $minutes = floor($timeDifference / $this->secondsPerMinute);
216
+                    $minutes=floor($timeDifference / $this->secondsPerMinute);
217 217
                     // saves the amount of seconds left
218
-                    $timeDifference = $timeDifference - ($minutes * $this->secondsPerMinute);
218
+                    $timeDifference=$timeDifference - ($minutes * $this->secondsPerMinute);
219 219
 
220 220
                 // finds the number of seconds
221 221
                 case ($timeDifference <= ($this->secondsPerMinute - 1)):
222 222
                     // seconds is just what there is in the timeDifference variable
223
-                    $seconds = $timeDifference;
223
+                    $seconds=$timeDifference;
224 224
             }
225 225
         }
226 226
 
227
-        $difference = [
227
+        $difference=[
228 228
             "years" => $years,
229 229
             "months" => $months,
230 230
             "days" => $days,
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
      * @param string $time the time to add to the translated text.
243 243
      * @return string the translated label text including the time.
244 244
      */
245
-    protected function translate($label, $time = '')
245
+    protected function translate($label, $time='')
246 246
     {
247 247
         // handles a usecase introduced in #18, where a new translation was added.
248 248
         // This would cause an array-out-of-bound exception, since the index does not
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
      */
261 261
     protected function changeTimezone()
262 262
     {
263
-        $this->previousTimezone = false;
263
+        $this->previousTimezone=false;
264 264
         if ($this->timezone) {
265
-            $this->previousTimezone = date_default_timezone_get();
265
+            $this->previousTimezone=date_default_timezone_get();
266 266
             date_default_timezone_set($this->timezone);
267 267
         }
268 268
     }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
     {
275 275
         if ($this->previousTimezone) {
276 276
             date_default_timezone_set($this->previousTimezone);
277
-            $this->previousTimezone = false;
277
+            $this->previousTimezone=false;
278 278
         }
279 279
     }
280 280
 
Please login to merge, or discard this patch.
core/helpers/Chaos.php 4 patches
Doc Comments   +11 added lines patch added patch discarded remove patch
@@ -57,6 +57,9 @@  discard block
 block discarded – undo
57 57
 		$this->msg=$this->prefix.str_replace( '%%%%', $this->url, $this->msg);
58 58
 	}
59 59
 	
60
+	/**
61
+	 * @param string $url
62
+	 */
60 63
 	function setChacha($url ){
61 64
 		$url = strtolower($url);
62 65
 		$arr = array(
@@ -114,6 +117,10 @@  discard block
 block discarded – undo
114 117
 	}
115 118
 
116 119
 	//随机把一个字符转为拼音
120
+
121
+	/**
122
+	 * @param string $str
123
+	 */
117 124
 	function setPinyin($str) {
118 125
 		$py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1);
119 126
 		$t_str = iconv_substr( $str, $py, 1, 'UTF-8');
@@ -146,6 +153,10 @@  discard block
 block discarded – undo
146 153
 	}
147 154
 	
148 155
 	//随机插入不影响阅读的字符
156
+
157
+	/**
158
+	 * @param string $str
159
+	 */
149 160
 	function setBlankness($str) {
150 161
 		$blankness = array(" ", ' ', '҉','̅̅','̲','̲̲','̅','̲̲̅̅');
151 162
 		$len = iconv_strlen( $str, 'UTF-8' );
Please login to merge, or discard this patch.
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -1,180 +1,180 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace puck\helpers;
3 3
 class Chaos {
4
-	public $GbToBigArray;
5
-	public $_pinyin;
6
-	public $string;
7
-	public $url = '';
8
-	public $msg = '';
9
-	public $action;
10
-	private $prefix;
4
+    public $GbToBigArray;
5
+    public $_pinyin;
6
+    public $string;
7
+    public $url = '';
8
+    public $msg = '';
9
+    public $action;
10
+    private $prefix;
11 11
 	
12 12
     function __construct(){
13
-		$this->_pinyin = new PinYin();
14
-	}
13
+        $this->_pinyin = new PinYin();
14
+    }
15 15
 
16 16
     /**
17 17
      * @param array $prefix
18 18
      */
19 19
     public function addPrefix(array $prefix) {
20 20
         $this->prefix=$prefix[array_rand($prefix)];
21
-	}
21
+    }
22 22
 
23 23
     public function clearPrefix() {
24 24
         $this->prefix='';
25
-	}
25
+    }
26 26
     public function get($str) {
27 27
         $this->cutting($str);
28 28
         $this->convert();
29 29
         $this->clearPrefix();
30 30
         return $this->msg;
31
-	}
31
+    }
32 32
 
33
-	//分离URL
34
-	private function cutting($str){
33
+    //分离URL
34
+    private function cutting($str){
35 35
 
36
-		if(preg_match("@(http://[^\\s]+)@i", $str, $result)) {
37
-			$this->url = $result[1];
38
-			$this->msg = $str = str_replace($this->url, '%%%%', $str);
39
-		} else {
40
-			$this->msg = $str;
41
-		}
42
-	}
36
+        if(preg_match("@(http://[^\\s]+)@i", $str, $result)) {
37
+            $this->url = $result[1];
38
+            $this->msg = $str = str_replace($this->url, '%%%%', $str);
39
+        } else {
40
+            $this->msg = $str;
41
+        }
42
+    }
43 43
 	
44 44
 	
45 45
 	
46
-	private function convert( $method = 'msg' ){
47
-		if( $method == 'msg' || $method == 'all') {
48
-			$this->msg = $this->setPinyin($this->msg);
49
-			$this->msg = $this->setRepeat($this->msg);
50
-			//$this->msg = $this->GbToBig($this->msg);
51
-			$this->msg = $this->setBlankness($this->msg);
46
+    private function convert( $method = 'msg' ){
47
+        if( $method == 'msg' || $method == 'all') {
48
+            $this->msg = $this->setPinyin($this->msg);
49
+            $this->msg = $this->setRepeat($this->msg);
50
+            //$this->msg = $this->GbToBig($this->msg);
51
+            $this->msg = $this->setBlankness($this->msg);
52 52
 			
53
-		}
54
-		if( $method == 'url' || $method == 'all') {
55
-			$this->url = $this->setChacha($this->url);
56
-		}
57
-		$this->msg=$this->prefix.str_replace( '%%%%', $this->url, $this->msg);
58
-	}
53
+        }
54
+        if( $method == 'url' || $method == 'all') {
55
+            $this->url = $this->setChacha($this->url);
56
+        }
57
+        $this->msg=$this->prefix.str_replace( '%%%%', $this->url, $this->msg);
58
+    }
59 59
 	
60
-	function setChacha($url ){
61
-		$url = strtolower($url);
62
-		$arr = array(
63
-			'a' => array('a','A','a','A','Α','А','α'),
64
-			'b' => array('b','B','b','B','Β','В','Ь'),
65
-			'c' => array('c','C','c','C','С','с'),
66
-			'd' => array('d','D','d','D'),
67
-			'e' => array('e','E','e','E','Ε','Е','е'),
68
-			'f' => array('f','F','f','F'),
69
-			'g' => array('g','G','g','G'),
70
-			'h' => array('h','H','h','H','Η','Н','н'),
71
-			'i' => array('i','I','i','I','Ι','Ⅰ'),
72
-			'j' => array('j','J','j','J'),
73
-			'k' => array('k','K','k','K','Κ','κ','к','К'),
74
-			'l' => array('l','L','l','L','︱','︳','|'),
75
-			'm' => array('m','M','m','M','Μ','М','м'),
76
-			'n' => array('n','N','n','N','Ν','∩'),
77
-			'o' => array('o','O','o','O','Ο','О'),
78
-			'p' => array('p','P','p','P','Ρ','Р','р'),
79
-			'q' => array('q','Q','q','Q'),
80
-			'r' => array('r','R','r','R'),
81
-			's' => array('s','S','s','S'),
82
-			't' => array('t','T','t','T','Τ','Т','ㄒ'),
83
-			'u' => array('u','U','u','U','∪'),
84
-			'v' => array('v','V','v','V','∨','ν'),
85
-			'w' => array('w','W','w','W'),
86
-			'x' => array('x','X','x','X','Χ','χ','Х','х','Ⅹ','×'),
87
-			'y' => array('y','Y','y','Y','У'),
88
-			'z' => array('z','Z','z','Z','Ζ'),
60
+    function setChacha($url ){
61
+        $url = strtolower($url);
62
+        $arr = array(
63
+            'a' => array('a','A','a','A','Α','А','α'),
64
+            'b' => array('b','B','b','B','Β','В','Ь'),
65
+            'c' => array('c','C','c','C','С','с'),
66
+            'd' => array('d','D','d','D'),
67
+            'e' => array('e','E','e','E','Ε','Е','е'),
68
+            'f' => array('f','F','f','F'),
69
+            'g' => array('g','G','g','G'),
70
+            'h' => array('h','H','h','H','Η','Н','н'),
71
+            'i' => array('i','I','i','I','Ι','Ⅰ'),
72
+            'j' => array('j','J','j','J'),
73
+            'k' => array('k','K','k','K','Κ','κ','к','К'),
74
+            'l' => array('l','L','l','L','︱','︳','|'),
75
+            'm' => array('m','M','m','M','Μ','М','м'),
76
+            'n' => array('n','N','n','N','Ν','∩'),
77
+            'o' => array('o','O','o','O','Ο','О'),
78
+            'p' => array('p','P','p','P','Ρ','Р','р'),
79
+            'q' => array('q','Q','q','Q'),
80
+            'r' => array('r','R','r','R'),
81
+            's' => array('s','S','s','S'),
82
+            't' => array('t','T','t','T','Τ','Т','ㄒ'),
83
+            'u' => array('u','U','u','U','∪'),
84
+            'v' => array('v','V','v','V','∨','ν'),
85
+            'w' => array('w','W','w','W'),
86
+            'x' => array('x','X','x','X','Χ','χ','Х','х','Ⅹ','×'),
87
+            'y' => array('y','Y','y','Y','У'),
88
+            'z' => array('z','Z','z','Z','Ζ'),
89 89
 			
90
-			'1' => array('1','1'),
91
-			'2' => array('2','2'),
92
-			'3' => array('3','3'),
93
-			'4' => array('4','4'),
94
-			'5' => array('5','5'),
95
-			'6' => array('6','6'),
96
-			'7' => array('7','7'),
97
-			'8' => array('8','8'),
98
-			'9' => array('9','9'),
99
-			'0' => array('0','0'),
90
+            '1' => array('1','1'),
91
+            '2' => array('2','2'),
92
+            '3' => array('3','3'),
93
+            '4' => array('4','4'),
94
+            '5' => array('5','5'),
95
+            '6' => array('6','6'),
96
+            '7' => array('7','7'),
97
+            '8' => array('8','8'),
98
+            '9' => array('9','9'),
99
+            '0' => array('0','0'),
100 100
 			
101
-			':' => array(':',':','∶'),
102
-			'/' => array('/','/'),
103
-			'.' => array('。','·','.','、','﹒',',','丶')
101
+            ':' => array(':',':','∶'),
102
+            '/' => array('/','/'),
103
+            '.' => array('。','·','.','、','﹒',',','丶')
104 104
 		
105
-		);
106
-		$len = strlen( $url );
107
-		$temp = "\n\n";
108
-		for( $i=0; $i<$len; $i++){
109
-			$t_str = substr( $url, $i, 1 );
110
-			$sj = mt_rand( 0, count($arr[$t_str])-1 );
111
-			$temp .= $arr[$t_str][$sj];
112
-		}
113
-		return $temp;
114
-	}
105
+        );
106
+        $len = strlen( $url );
107
+        $temp = "\n\n";
108
+        for( $i=0; $i<$len; $i++){
109
+            $t_str = substr( $url, $i, 1 );
110
+            $sj = mt_rand( 0, count($arr[$t_str])-1 );
111
+            $temp .= $arr[$t_str][$sj];
112
+        }
113
+        return $temp;
114
+    }
115 115
 
116
-	//随机把一个字符转为拼音
117
-	function setPinyin($str) {
118
-		$py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1);
119
-		$t_str = iconv_substr( $str, $py, 1, 'UTF-8');
120
-		if(mt_rand(0,10) > 5) $pinyin = " ";
121
-		$pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE);
116
+    //随机把一个字符转为拼音
117
+    function setPinyin($str) {
118
+        $py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1);
119
+        $t_str = iconv_substr( $str, $py, 1, 'UTF-8');
120
+        if(mt_rand(0,10) > 5) $pinyin = " ";
121
+        $pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE);
122 122
         $pinyin=implode(" ",$pinyin);
123
-		if(mt_rand(0,10) > 5) $pinyin .= " ";
124
-		if($t_str != "%"){
125
-			$str = preg_replace("'$t_str'", $pinyin, $str, 1);
126
-		}
127
-		return $str;
128
-	}
123
+        if(mt_rand(0,10) > 5) $pinyin .= " ";
124
+        if($t_str != "%"){
125
+            $str = preg_replace("'$t_str'", $pinyin, $str, 1);
126
+        }
127
+        return $str;
128
+    }
129 129
 	
130
-	//随机重复一个字符
131
-	function setRepeat($str) {
132
-		$len = iconv_strlen( $str, 'UTF-8' );
133
-		$action = 0;
134
-		$temp = '';
135
-		for( $i=0;  $i<$len; $i++ ){
136
-			$t_str = iconv_substr( $str, $i, 1 ,'UTF-8');
137
-			if( mt_rand( 1, 50 ) > 48 && $action == 0) {
138
-				if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
139
-					$temp .= $t_str;
140
-					$action = 1;
141
-				}
142
-			}
143
-			$temp .= $t_str;
144
-		}
145
-		return $temp;
146
-	}
130
+    //随机重复一个字符
131
+    function setRepeat($str) {
132
+        $len = iconv_strlen( $str, 'UTF-8' );
133
+        $action = 0;
134
+        $temp = '';
135
+        for( $i=0;  $i<$len; $i++ ){
136
+            $t_str = iconv_substr( $str, $i, 1 ,'UTF-8');
137
+            if( mt_rand( 1, 50 ) > 48 && $action == 0) {
138
+                if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
139
+                    $temp .= $t_str;
140
+                    $action = 1;
141
+                }
142
+            }
143
+            $temp .= $t_str;
144
+        }
145
+        return $temp;
146
+    }
147 147
 	
148
-	//随机插入不影响阅读的字符
149
-	function setBlankness($str) {
150
-		$blankness = array(" ", ' ', '҉','̅̅','̲','̲̲','̅','̲̲̅̅');
151
-		$len = iconv_strlen( $str, 'UTF-8' );
152
-		$temp = '';
153
-		for( $i=0;  $i<$len; $i++ ){
154
-			$t_str = iconv_substr( $str, $i, 1 ,'UTF-8');
155
-			if( mt_rand( 1, 50 ) > 48 ) {
156
-				if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
157
-					$temp .= $blankness[mt_rand(0, 7)];
158
-				}
159
-			}
160
-			$temp .= $t_str;
161
-		}
162
-		return $temp;
163
-	}
148
+    //随机插入不影响阅读的字符
149
+    function setBlankness($str) {
150
+        $blankness = array(" ", ' ', '҉','̅̅','̲','̲̲','̅','̲̲̅̅');
151
+        $len = iconv_strlen( $str, 'UTF-8' );
152
+        $temp = '';
153
+        for( $i=0;  $i<$len; $i++ ){
154
+            $t_str = iconv_substr( $str, $i, 1 ,'UTF-8');
155
+            if( mt_rand( 1, 50 ) > 48 ) {
156
+                if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
157
+                    $temp .= $blankness[mt_rand(0, 7)];
158
+                }
159
+            }
160
+            $temp .= $t_str;
161
+        }
162
+        return $temp;
163
+    }
164 164
 	
165
-	//随机进行繁体中文转换
166
-	function GbToBig( $str ){
167
-		$len = iconv_strlen( $str, 'UTF-8' );
168
-		$temp = '';
169
-		for( $i=0;  $i<$len; $i++ ){
170
-			$t_str = iconv_substr( $str, $i, 1 ,'UTF-8');
171
-			if( mt_rand( 1, 50 ) > 48 ) {
172
-				$t_str = strtr( $t_str, $this->GbToBigArray );
173
-			}
174
-			$temp .= $t_str;
175
-		}
176
-		return $temp;
177
-	}
165
+    //随机进行繁体中文转换
166
+    function GbToBig( $str ){
167
+        $len = iconv_strlen( $str, 'UTF-8' );
168
+        $temp = '';
169
+        for( $i=0;  $i<$len; $i++ ){
170
+            $t_str = iconv_substr( $str, $i, 1 ,'UTF-8');
171
+            if( mt_rand( 1, 50 ) > 48 ) {
172
+                $t_str = strtr( $t_str, $this->GbToBigArray );
173
+            }
174
+            $temp .= $t_str;
175
+        }
176
+        return $temp;
177
+    }
178 178
 }
179 179
 
180 180
 
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -4,13 +4,13 @@  discard block
 block discarded – undo
4 4
 	public $GbToBigArray;
5 5
 	public $_pinyin;
6 6
 	public $string;
7
-	public $url = '';
8
-	public $msg = '';
7
+	public $url='';
8
+	public $msg='';
9 9
 	public $action;
10 10
 	private $prefix;
11 11
 	
12
-    function __construct(){
13
-		$this->_pinyin = new PinYin();
12
+    function __construct() {
13
+		$this->_pinyin=new PinYin();
14 14
 	}
15 15
 
16 16
     /**
@@ -31,147 +31,147 @@  discard block
 block discarded – undo
31 31
 	}
32 32
 
33 33
 	//分离URL
34
-	private function cutting($str){
34
+	private function cutting($str) {
35 35
 
36
-		if(preg_match("@(http://[^\\s]+)@i", $str, $result)) {
37
-			$this->url = $result[1];
38
-			$this->msg = $str = str_replace($this->url, '%%%%', $str);
36
+		if (preg_match("@(http://[^\\s]+)@i", $str, $result)) {
37
+			$this->url=$result[1];
38
+			$this->msg=$str=str_replace($this->url, '%%%%', $str);
39 39
 		} else {
40
-			$this->msg = $str;
40
+			$this->msg=$str;
41 41
 		}
42 42
 	}
43 43
 	
44 44
 	
45 45
 	
46
-	private function convert( $method = 'msg' ){
47
-		if( $method == 'msg' || $method == 'all') {
48
-			$this->msg = $this->setPinyin($this->msg);
49
-			$this->msg = $this->setRepeat($this->msg);
46
+	private function convert($method='msg') {
47
+		if ($method == 'msg' || $method == 'all') {
48
+			$this->msg=$this->setPinyin($this->msg);
49
+			$this->msg=$this->setRepeat($this->msg);
50 50
 			//$this->msg = $this->GbToBig($this->msg);
51
-			$this->msg = $this->setBlankness($this->msg);
51
+			$this->msg=$this->setBlankness($this->msg);
52 52
 			
53 53
 		}
54
-		if( $method == 'url' || $method == 'all') {
55
-			$this->url = $this->setChacha($this->url);
54
+		if ($method == 'url' || $method == 'all') {
55
+			$this->url=$this->setChacha($this->url);
56 56
 		}
57
-		$this->msg=$this->prefix.str_replace( '%%%%', $this->url, $this->msg);
57
+		$this->msg=$this->prefix.str_replace('%%%%', $this->url, $this->msg);
58 58
 	}
59 59
 	
60
-	function setChacha($url ){
61
-		$url = strtolower($url);
62
-		$arr = array(
63
-			'a' => array('a','A','a','A','Α','А','α'),
64
-			'b' => array('b','B','b','B','Β','В','Ь'),
65
-			'c' => array('c','C','c','C','С','с'),
66
-			'd' => array('d','D','d','D'),
67
-			'e' => array('e','E','e','E','Ε','Е','е'),
68
-			'f' => array('f','F','f','F'),
69
-			'g' => array('g','G','g','G'),
70
-			'h' => array('h','H','h','H','Η','Н','н'),
71
-			'i' => array('i','I','i','I','Ι','Ⅰ'),
72
-			'j' => array('j','J','j','J'),
73
-			'k' => array('k','K','k','K','Κ','κ','к','К'),
74
-			'l' => array('l','L','l','L','︱','︳','|'),
75
-			'm' => array('m','M','m','M','Μ','М','м'),
76
-			'n' => array('n','N','n','N','Ν','∩'),
77
-			'o' => array('o','O','o','O','Ο','О'),
78
-			'p' => array('p','P','p','P','Ρ','Р','р'),
79
-			'q' => array('q','Q','q','Q'),
80
-			'r' => array('r','R','r','R'),
81
-			's' => array('s','S','s','S'),
82
-			't' => array('t','T','t','T','Τ','Т','ㄒ'),
83
-			'u' => array('u','U','u','U','∪'),
84
-			'v' => array('v','V','v','V','∨','ν'),
85
-			'w' => array('w','W','w','W'),
86
-			'x' => array('x','X','x','X','Χ','χ','Х','х','Ⅹ','×'),
87
-			'y' => array('y','Y','y','Y','У'),
88
-			'z' => array('z','Z','z','Z','Ζ'),
60
+	function setChacha($url) {
61
+		$url=strtolower($url);
62
+		$arr=array(
63
+			'a' => array('a', 'A', 'a', 'A', 'Α', 'А', 'α'),
64
+			'b' => array('b', 'B', 'b', 'B', 'Β', 'В', 'Ь'),
65
+			'c' => array('c', 'C', 'c', 'C', 'С', 'с'),
66
+			'd' => array('d', 'D', 'd', 'D'),
67
+			'e' => array('e', 'E', 'e', 'E', 'Ε', 'Е', 'е'),
68
+			'f' => array('f', 'F', 'f', 'F'),
69
+			'g' => array('g', 'G', 'g', 'G'),
70
+			'h' => array('h', 'H', 'h', 'H', 'Η', 'Н', 'н'),
71
+			'i' => array('i', 'I', 'i', 'I', 'Ι', 'Ⅰ'),
72
+			'j' => array('j', 'J', 'j', 'J'),
73
+			'k' => array('k', 'K', 'k', 'K', 'Κ', 'κ', 'к', 'К'),
74
+			'l' => array('l', 'L', 'l', 'L', '︱', '︳', '|'),
75
+			'm' => array('m', 'M', 'm', 'M', 'Μ', 'М', 'м'),
76
+			'n' => array('n', 'N', 'n', 'N', 'Ν', '∩'),
77
+			'o' => array('o', 'O', 'o', 'O', 'Ο', 'О'),
78
+			'p' => array('p', 'P', 'p', 'P', 'Ρ', 'Р', 'р'),
79
+			'q' => array('q', 'Q', 'q', 'Q'),
80
+			'r' => array('r', 'R', 'r', 'R'),
81
+			's' => array('s', 'S', 's', 'S'),
82
+			't' => array('t', 'T', 't', 'T', 'Τ', 'Т', 'ㄒ'),
83
+			'u' => array('u', 'U', 'u', 'U', '∪'),
84
+			'v' => array('v', 'V', 'v', 'V', '∨', 'ν'),
85
+			'w' => array('w', 'W', 'w', 'W'),
86
+			'x' => array('x', 'X', 'x', 'X', 'Χ', 'χ', 'Х', 'х', 'Ⅹ', '×'),
87
+			'y' => array('y', 'Y', 'y', 'Y', 'У'),
88
+			'z' => array('z', 'Z', 'z', 'Z', 'Ζ'),
89 89
 			
90
-			'1' => array('1','1'),
91
-			'2' => array('2','2'),
92
-			'3' => array('3','3'),
93
-			'4' => array('4','4'),
94
-			'5' => array('5','5'),
95
-			'6' => array('6','6'),
96
-			'7' => array('7','7'),
97
-			'8' => array('8','8'),
98
-			'9' => array('9','9'),
99
-			'0' => array('0','0'),
90
+			'1' => array('1', '1'),
91
+			'2' => array('2', '2'),
92
+			'3' => array('3', '3'),
93
+			'4' => array('4', '4'),
94
+			'5' => array('5', '5'),
95
+			'6' => array('6', '6'),
96
+			'7' => array('7', '7'),
97
+			'8' => array('8', '8'),
98
+			'9' => array('9', '9'),
99
+			'0' => array('0', '0'),
100 100
 			
101
-			':' => array(':',':','∶'),
102
-			'/' => array('/','/'),
103
-			'.' => array('。','·','.','、','﹒',',','丶')
101
+			':' => array(':', ':', '∶'),
102
+			'/' => array('/', '/'),
103
+			'.' => array('。', '·', '.', '、', '﹒', ',', '丶')
104 104
 		
105 105
 		);
106
-		$len = strlen( $url );
107
-		$temp = "\n\n";
108
-		for( $i=0; $i<$len; $i++){
109
-			$t_str = substr( $url, $i, 1 );
110
-			$sj = mt_rand( 0, count($arr[$t_str])-1 );
111
-			$temp .= $arr[$t_str][$sj];
106
+		$len=strlen($url);
107
+		$temp="\n\n";
108
+		for ($i=0; $i < $len; $i++) {
109
+			$t_str=substr($url, $i, 1);
110
+			$sj=mt_rand(0, count($arr[$t_str]) - 1);
111
+			$temp.=$arr[$t_str][$sj];
112 112
 		}
113 113
 		return $temp;
114 114
 	}
115 115
 
116 116
 	//随机把一个字符转为拼音
117 117
 	function setPinyin($str) {
118
-		$py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1);
119
-		$t_str = iconv_substr( $str, $py, 1, 'UTF-8');
120
-		if(mt_rand(0,10) > 5) $pinyin = " ";
121
-		$pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE);
122
-        $pinyin=implode(" ",$pinyin);
123
-		if(mt_rand(0,10) > 5) $pinyin .= " ";
124
-		if($t_str != "%"){
125
-			$str = preg_replace("'$t_str'", $pinyin, $str, 1);
118
+		$py=mt_rand(0, iconv_strlen($str, 'UTF-8') - 1);
119
+		$t_str=iconv_substr($str, $py, 1, 'UTF-8');
120
+		if (mt_rand(0, 10) > 5) $pinyin=" ";
121
+		$pinyin=$this->_pinyin->convert($t_str, PINYIN_UNICODE);
122
+        $pinyin=implode(" ", $pinyin);
123
+		if (mt_rand(0, 10) > 5) $pinyin.=" ";
124
+		if ($t_str != "%") {
125
+			$str=preg_replace("'$t_str'", $pinyin, $str, 1);
126 126
 		}
127 127
 		return $str;
128 128
 	}
129 129
 	
130 130
 	//随机重复一个字符
131 131
 	function setRepeat($str) {
132
-		$len = iconv_strlen( $str, 'UTF-8' );
133
-		$action = 0;
134
-		$temp = '';
135
-		for( $i=0;  $i<$len; $i++ ){
136
-			$t_str = iconv_substr( $str, $i, 1 ,'UTF-8');
137
-			if( mt_rand( 1, 50 ) > 48 && $action == 0) {
138
-				if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
139
-					$temp .= $t_str;
140
-					$action = 1;
132
+		$len=iconv_strlen($str, 'UTF-8');
133
+		$action=0;
134
+		$temp='';
135
+		for ($i=0; $i < $len; $i++) {
136
+			$t_str=iconv_substr($str, $i, 1, 'UTF-8');
137
+			if (mt_rand(1, 50) > 48 && $action == 0) {
138
+				if (!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
139
+					$temp.=$t_str;
140
+					$action=1;
141 141
 				}
142 142
 			}
143
-			$temp .= $t_str;
143
+			$temp.=$t_str;
144 144
 		}
145 145
 		return $temp;
146 146
 	}
147 147
 	
148 148
 	//随机插入不影响阅读的字符
149 149
 	function setBlankness($str) {
150
-		$blankness = array(" ", ' ', '҉','̅̅','̲','̲̲','̅','̲̲̅̅');
151
-		$len = iconv_strlen( $str, 'UTF-8' );
152
-		$temp = '';
153
-		for( $i=0;  $i<$len; $i++ ){
154
-			$t_str = iconv_substr( $str, $i, 1 ,'UTF-8');
155
-			if( mt_rand( 1, 50 ) > 48 ) {
156
-				if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
157
-					$temp .= $blankness[mt_rand(0, 7)];
150
+		$blankness=array(" ", ' ', '҉', '̅̅', '̲', '̲̲', '̅', '̲̲̅̅');
151
+		$len=iconv_strlen($str, 'UTF-8');
152
+		$temp='';
153
+		for ($i=0; $i < $len; $i++) {
154
+			$t_str=iconv_substr($str, $i, 1, 'UTF-8');
155
+			if (mt_rand(1, 50) > 48) {
156
+				if (!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
157
+					$temp.=$blankness[mt_rand(0, 7)];
158 158
 				}
159 159
 			}
160
-			$temp .= $t_str;
160
+			$temp.=$t_str;
161 161
 		}
162 162
 		return $temp;
163 163
 	}
164 164
 	
165 165
 	//随机进行繁体中文转换
166
-	function GbToBig( $str ){
167
-		$len = iconv_strlen( $str, 'UTF-8' );
168
-		$temp = '';
169
-		for( $i=0;  $i<$len; $i++ ){
170
-			$t_str = iconv_substr( $str, $i, 1 ,'UTF-8');
171
-			if( mt_rand( 1, 50 ) > 48 ) {
172
-				$t_str = strtr( $t_str, $this->GbToBigArray );
166
+	function GbToBig($str) {
167
+		$len=iconv_strlen($str, 'UTF-8');
168
+		$temp='';
169
+		for ($i=0; $i < $len; $i++) {
170
+			$t_str=iconv_substr($str, $i, 1, 'UTF-8');
171
+			if (mt_rand(1, 50) > 48) {
172
+				$t_str=strtr($t_str, $this->GbToBigArray);
173 173
 			}
174
-			$temp .= $t_str;
174
+			$temp.=$t_str;
175 175
 		}
176 176
 		return $temp;
177 177
 	}
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -117,10 +117,14 @@
 block discarded – undo
117 117
 	function setPinyin($str) {
118 118
 		$py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1);
119 119
 		$t_str = iconv_substr( $str, $py, 1, 'UTF-8');
120
-		if(mt_rand(0,10) > 5) $pinyin = " ";
120
+		if(mt_rand(0,10) > 5) {
121
+		    $pinyin = " ";
122
+		}
121 123
 		$pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE);
122 124
         $pinyin=implode(" ",$pinyin);
123
-		if(mt_rand(0,10) > 5) $pinyin .= " ";
125
+		if(mt_rand(0,10) > 5) {
126
+		    $pinyin .= " ";
127
+		}
124 128
 		if($t_str != "%"){
125 129
 			$str = preg_replace("'$t_str'", $pinyin, $str, 1);
126 130
 		}
Please login to merge, or discard this patch.