Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 5 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
2  html.class.php
@@ -193,7 +193,7 @@ public function make_html($mysqli)
193 193
 		$query = @mysqli_query($this->mysqli, 'select `date` as `date_max`, `l_total` as `l_max` from `channel` where `l_total` = (select max(`l_total`) from `channel`)') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
194 194
 		$result = mysqli_fetch_object($query);
195 195
 		$this->date_max = $result->date_max;
196  
-		$this->l_max = $result->l_max;
  196
+		$this->l_max = (int) $result->l_max;
197 197
 		$this->output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n\n"
198 198
 			      . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'."\n\n"
199 199
 			      . '<head>'."\n".'<title>'.htmlspecialchars($this->channel).', seriously.</title>'."\n"
2  nick.class.php
@@ -266,7 +266,7 @@ public function write_data($mysqli)
266 266
 			@mysqli_query($this->mysqli, 'insert into `user_status` set `uid` = '.$this->uid.', `ruid` = '.$this->uid.', `status` = 0') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
267 267
 		} else {
268 268
 			$result = mysqli_fetch_object($query);
269  
-			$this->uid = $result->uid;
  269
+			$this->uid = (int) $result->uid;
270 270
 
271 271
 			/**
272 272
 			 * Explicitly not update $csnick if "seen" data hasn't changed. Prevents lowercase $prevnick from becoming new $csnick.
74  nicklinker.php
@@ -91,13 +91,10 @@ public function __construct()
91 91
 		@mysqli_close($this->mysqli);
92 92
 	}
93 93
 
94  
-	/**
95  
-	 * Export nicks sorted on lines typed. Unlinked nicks are in alphabetical order.
96  
-	 */
97 94
 	private function export($file)
98 95
 	{
99 96
 		$this->output('notice', 'export(): exporting nicks');
100  
-		$query = @mysqli_query($this->mysqli, 'select `user_status`.`uid`, `ruid`, `status`, `csnick` from `user_status` join `user_details` on `user_status`.`uid` = `user_details`.`uid` left join `user_lines` on `user_status`.`uid` = `user_lines`.`uid` order by `l_total` desc, `csnick` asc') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
  97
+		$query = @mysqli_query($this->mysqli, 'select `user_details`.`uid`, `ruid`, `csnick`, `status` from `user_details` join `user_status` on `user_details`.`uid` = `user_status`.`uid` order by `csnick` asc') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
101 98
 		$rows = mysqli_num_rows($query);
102 99
 
103 100
 		if (empty($rows)) {
@@ -105,33 +102,38 @@ private function export($file)
105 102
 		}
106 103
 
107 104
 		while ($result = mysqli_fetch_object($query)) {
108  
-			$statuses[$result->uid] = (int) $result->status;
109  
-			$users[$result->ruid][] = strtolower($result->csnick);
  105
+			if ((int) $result->status == 1 || (int) $result->status == 3) {
  106
+				$registered[strtolower($result->csnick)] = (int) $result->uid;
  107
+				$statuses[(int) $result->uid] = (int) $result->status;
  108
+			} elseif ((int) $result->status == 2) {
  109
+				$aliases[(int) $result->ruid][] = strtolower($result->csnick);
  110
+			} else {
  111
+				$unlinked[] = strtolower($result->csnick);
  112
+			}
110 113
 		}
111 114
 
112 115
 		$output = '';
113 116
 		$i = 0;
114 117
 
115  
-		foreach ($users as $ruid => $aliases) {
116  
-			if ($statuses[$ruid] == 1 || $statuses[$ruid] == 3) {
117  
-				$output .= $statuses[$ruid];
  118
+		if (!empty($registered)) {
  119
+			ksort($registered);
  120
+
  121
+			foreach ($registered as $user => $uid) {
  122
+				$output .= $statuses[$uid].','.$user;
  123
+				$i++;
118 124
 
119  
-				foreach ($aliases as $nick) {
120  
-					$output .= ','.$nick;
121  
-					$i++;
  125
+				if (!empty($aliases[$uid])) {
  126
+					foreach ($aliases[$uid] as $alias) {
  127
+						$output .= ','.$alias;
  128
+						$i++;
  129
+					}
122 130
 				}
123 131
 
124 132
 				$output .= "\n";
125  
-			} else {
126  
-				/**
127  
-				 * There is only one nick linked to a user with status 0; itself. Other options fail at the end of this method.
128  
-				 */
129  
-				$unlinked[] = $aliases[0];
130 133
 			}
131 134
 		}
132 135
 
133 136
 		if (!empty($unlinked)) {
134  
-			sort($unlinked);
135 137
 			$output .= '*';
136 138
 
137 139
 			foreach ($unlinked as $nick) {
@@ -169,7 +171,7 @@ private function import($file)
169 171
 		}
170 172
 
171 173
 		while ($result = mysqli_fetch_object($query)) {
172  
-			$uids[strtolower($result->csnick)] = $result->uid;
  174
+			$uids[strtolower($result->csnick)] = (int) $result->uid;
173 175
 		}
174 176
 
175 177
 		if (($rp = realpath($file)) === false) {
@@ -200,31 +202,29 @@ private function import($file)
200 202
 						$linked2uid[$nick] = $uid;
201 203
 					}
202 204
 				}
203  
-			} elseif ($lineparts[0] == '*') {
204  
-				for ($i = 1, $j = count($lineparts); $i < $j; $i++) {
205  
-					if (!empty($lineparts[$i])) {
206  
-						$nick = $lineparts[$i];
207  
-						$unlinked[] = $nick;
208  
-					}
209  
-				}
210 205
 			}
211 206
 		}
212 207
 
213  
-		/**
214  
-		 * Set all nicks to their default status before updating them according to new data.
215  
-		 */
216  
-		@mysqli_query($this->mysqli, 'update `user_status` set `ruid` = `uid`, `status` = 0') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
  208
+		fclose($fp);
  209
+
  210
+		if (empty($users)) {
  211
+			$this->output('warning', 'import(): no user relations found to import');
  212
+		} else {
  213
+			/**
  214
+			 * Set all nicks to their default status before updating them according to new data.
  215
+			 */
  216
+			@mysqli_query($this->mysqli, 'update `user_status` set `ruid` = `uid`, `status` = 0') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
217 217
 
218  
-		foreach ($users as $uid => $aliases) {
219  
-			@mysqli_query($this->mysqli, 'update `user_status` set `ruid` = `uid`, `status` = '.$statuses[$uid].' where `uid` = '.$uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
  218
+			foreach ($users as $uid => $aliases) {
  219
+				@mysqli_query($this->mysqli, 'update `user_status` set `ruid` = `uid`, `status` = '.$statuses[$uid].' where `uid` = '.$uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
220 220
 
221  
-			for ($i = 1, $j = count($aliases); $i < $j; $i++) {
222  
-				@mysqli_query($this->mysqli, 'update `user_status` set `ruid` = '.$uid.', `status` = 2 where `uid` = '.$uids[$aliases[$i]]) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
  221
+				for ($i = 1, $j = count($aliases); $i < $j; $i++) {
  222
+					@mysqli_query($this->mysqli, 'update `user_status` set `ruid` = '.$uid.', `status` = 2 where `uid` = '.$uids[$aliases[$i]]) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
  223
+				}
223 224
 			}
224  
-		}
225 225
 
226  
-		fclose($fp);
227  
-		$this->output('notice', 'import(): import completed, don\'t forget to run "php sss.php -m"');
  226
+			$this->output('notice', 'import(): import completed, don\'t forget to run "php sss.php -m"');
  227
+		}
228 228
 	}
229 229
 
230 230
 	private function print_manual()
17  sss.php
@@ -177,6 +177,12 @@ private function link_nicks()
177 177
 			}
178 178
 		}
179 179
 
  180
+		if (empty($strippednicks)) {
  181
+			return;
  182
+		}
  183
+
  184
+		$nickslinked = 0;
  185
+
180 186
 		foreach ($strippednicks as $uids) {
181 187
 			/**
182 188
 			 * If there is only one uid for the stripped nick we don't have anything to link.
@@ -189,20 +195,25 @@ private function link_nicks()
189 195
 			 * We use the ruid belonging to the first uid in the array to link all succeeding unlinked uids to.
190 196
 			 * If the first uid is unlinked (status = 0) we update its record to become a registered nick (status = 1) when there is at least one new alias found for it (any succeeding uid with status = 0).
191 197
 			 */
192  
-			$newaliases = false;
  198
+			$aliasfound = false;
193 199
 
194 200
 			for ($i = 1, $j = count($uids); $i < $j; $i++) {
195 201
 				if ($nicks[$uids[$i]]['status'] == 0) {
196 202
 					@mysqli_query($this->mysqli, 'update `user_status` set `ruid` = '.$nicks[$uids[0]]['ruid'].', `status` = 2 where `uid` = '.$uids[$i]) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
197 203
 					$this->output('debug', 'link_nicks(): linked \''.$nicks[$uids[$i]]['nick'].'\' to \''.$nicks[$nicks[$uids[0]]['ruid']]['nick'].'\'');
198  
-					$newaliases = true;
  204
+					$nickslinked++;
  205
+					$aliasfound = true;
199 206
 				}
200 207
 			}
201 208
 
202  
-			if ($newaliases && $nicks[$uids[0]]['status'] == 0) {
  209
+			if ($aliasfound && $nicks[$uids[0]]['status'] == 0) {
203 210
 				@mysqli_query($this->mysqli, 'update `user_status` set `status` = 1 where `uid` = '.$uids[0]) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
204 211
 			}
205 212
 		}
  213
+
  214
+		if ($nickslinked == 0) {
  215
+			$this->output('notice', 'link_nicks(): no new aliases found');
  216
+		}
206 217
 	}
207 218
 
208 219
 	private function make_html($file)
5  www/history.php
@@ -115,10 +115,7 @@ private function get_activity() {
115 115
 		$query = @mysqli_query($this->mysqli, 'select substring(`date`, 1, 4) as `year`, substring(`date`, 6, 2) as `month`, sum(`l_total`) as `l_total` from `q_activity_by_month` group by substring(`date`, 1, 4), substring(`date`, 6, 2) having `l_total` != 0 order by `year` asc, `month` asc') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
116 116
 
117 117
 		while ($result = mysqli_fetch_object($query)) {
118  
-			if (strpos($result->month, '0') === 0) {
119  
-				$result->month = substr($result->month, 1);
120  
-			}
121  
-
  118
+			$result->month = preg_replace('/^0/', '', $result->month);
122 119
 			$this->activity[(int) $result->year][(int) $result->month] = (int) $result->l_total;
123 120
 
124 121
 			if (!isset($this->activity[(int) $result->year][0])) {

No commit comments for this range

Something went wrong with that request. Please try again.