This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.php
224 lines (193 loc) · 6.07 KB
/
helpers.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
function getUserInfo($username = '.')
{
if ($username == '.') {
$username = Auth::user()->username;
}
$info = irc('nickserv')->getInfo($username);
if (array_get($info, '0', false) == false) {
return [];
}
$info = explode("\n", $info[1]);
$userInfo = array();
foreach ($info as $val) {
if (!preg_match('~^(.*) :\s(.*)\s\((.*)\)$~U', $val, $m) && !preg_match('~^(.*) : (.*)$~U', $val, $m)) {
continue;
}
$userInfo[strtolower(trim($m[1]))] = $m[2];
}
if (preg_match('~\(account (.*)\)~U', $info[0], $m)) {
$userInfo['acct name'] = $m[1];
}
//Session::set('userInfo', $userInfo);
return $userInfo;
}
function irc($module)
{
$module = 'Cysha\Modules\Darchoods\Helpers\IRC\\'.$module;
return with(new $module);
}
function profile($username)
{
if (empty($username)) {
return 'Unknown';
}
return $username; // no profile page yet
return Cache::remember('users.'.$username, 60, function () use ($username) {
$authModel = Config::get('auth.model');
$objUser = $authModel::whereNick($username)->get()->first();
if ($objUser !== null) {
return array_get($objUser->transform(), 'link');
}
return $username;
});
}
//functions for this page to work
function compare($x, $y)
{
if($x['count'] == $y['count']){
return 0;
}else if($x['count'] < $y['count']){
return 1;
}else{
return -1;
}
}
function denora_colorconvert($body)
{
$lines = explode("\n", $body);
$out = '';
foreach($lines as $line) {
$line = nl2br($line);
// replace control codes
$line = preg_replace('/[\003](\d{0,2})(,\d{1,2})?([^\003\x0F]*)(?:[\003](?!\d))?/', '<font color="\\1">\\3</font>', $line);
$line = preg_replace('/[\002]([^\002\x0F]*)(?:[\002])?/', '<font style="font-weight: bold;">$1</font>', $line);
$line = preg_replace('/[\x1F]([^\x1F\x0F]*)(?:[\x1F])?/', '<span style="text-decoration: underline;">$1</span>', $line);
$line = preg_replace('/[\x12]([^\x12\x0F]*)(?:[\x12])?/', '<span style="text-decoration: line-through;">$1</span>', $line);
$line = preg_replace('/[\x16]([^\x16\x0F]*)(?:[\x16])?/', '<span style="font-style: italic;">$1</span>', $line);
$line = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\S+]*(\?\S+)?)?)?)@', '<a href="$1" class="topic" rel="nofollow" target="_blank">$1</a>', e($line));
// remove dirt
$line = preg_replace('/[\x00-\x1F]/', '', $line);
$line = preg_replace('/[\x7F-\xFF]/', '', $line);
// append line
if($line != '') { $out .= $line; }
}
return $out;
}
/**
* Retreives part of a string
*
* @version 1.0
* @since 1.0.0
*
* @param string $begin
* @param string $end
* @param string $contents
*
* @return string
*/
function inBetween($begin, $end, $contents)
{
$pos1 = strpos($contents, $begin);
if($pos1 !== false){
$pos1 += strlen($begin);
$pos2 = strpos($contents, $end, $pos1);
if ($pos2 !== false) {
$substr = substr($contents, $pos1, $pos2 - $pos1);
return $substr;
}
}
return false;
}
/* Returns channel modes */
function chan_modes($query)
{
$i = 0;
$array = array();
$cmodes = '';
$j = 97;
$array[$i] = (array)$query;
for ($i = 0; $i <= count($array) - 1; $i++) {
while ($j <= 122) {
if (array_get($array, $i.'.mode_l'.chr($j)) == 'Y') {
$cmodes .= chr($j);
}
if (array_get($array, $i.'.mode_u'.chr($j)) == 'Y') {
$cmodes .= chr($j - 32);
}
$j++;
}
if (array_get($array, $i.'.mode_lf_data', null) !== null) {
$cmodes .= ' '.$array[$i]['mode_lf_data'];
}
if (array_get($array, $i.'.mode_lj_data', null) !== null) {
$cmodes .= ' '.$array[$i]['mode_lj_data'];
}
if (array_get($array, $i.'.mode_ll_data', null) !== null) {
$cmodes .= ' '.$array[$i]['mode_ll_data'];
}
if (array_get($array, $i.'.mode_uf_data', null) !== null) {
$cmodes .= ' '.$array[$i]['mode_uf_data'];
}
if (array_get($array, $i.'.mode_uj_data', null) !== null) {
$cmodes .= ' '.$array[$i]['mode_uj_data'];
}
if (array_get($array, $i.'.mode_ul_data', null) !== null) {
$cmodes .= ' '.$array[$i]['mode_ul_data'];
}
}
if (!empty($cmodes)) {
$cmodes = '+'.$cmodes;
}
return $cmodes;
}
function secs_to_h($secs)
{
$units = array(
'year' => 365*24*3600,
'month' => 30*24*3600,
'week' => 7*24*3600,
'day' => 24*3600,
'hour' => 3600,
'minute' => 60,
'second' => 1,
);
// specifically handle zero
if ($secs == 0) {
return '0 seconds';
}
$s = '';
foreach ($units as $name => $divisor) {
if ($quot = intval($secs / $divisor)) {
$s .= $quot.' '.$name;
$s .= (abs($quot) > 1 ? 's' : '') . ', ';
$secs -= $quot * $divisor;
}
}
return substr($s, 0, -2);
}
function MultiSort($data, $sortCriteria, $caseInSensitive = true)
{
if (!is_array($data) || !is_array($sortCriteria)) {
return false;
}
$args = [];
$i = 0;
foreach ($sortCriteria as $sortColumn => $sortAttributes) {
$colLists = [];
foreach ($data as $key => $row) {
$convertToLower = $caseInSensitive && (in_array(SORT_STRING, $sortAttributes) || in_array(SORT_REGULAR, $sortAttributes));
$rowData = $convertToLower ? strtolower($row[$sortColumn]) : $row[$sortColumn];
$colLists[$sortColumn][$key] = $rowData;
}
$args[] = &$colLists[$sortColumn];
foreach ($sortAttributes as $sortAttribute) {
$tmp[$i] = $sortAttribute;
$args[] = &$tmp[$i];
$i++;
}
}
$args[] = &$data;
call_user_func_array('array_multisort', $args);
return end($args);
}