Skip to content

Commit e12cf12

Browse files
committed
Update shouts_search.inc.php
Fix support of images in system chat
1 parent 9679941 commit e12cf12

1 file changed

Lines changed: 173 additions & 170 deletions

File tree

modules/shoutbox/shouts_search.inc.php

Lines changed: 173 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -3,199 +3,202 @@
33
* @version 0.2 (auto-set)
44
*/
55

6-
global $session;
6+
global $session;
77

8-
if ($this->owner->room_id) {
9-
$session->data['SHOUT_ROOM_ID']=$this->owner->room_id;
10-
}
8+
if ($this->owner->room_id) {
9+
$session->data['SHOUT_ROOM_ID'] = $this->owner->room_id;
10+
}
1111

12-
global $msg;
13-
global $getdata;
14-
global $clear;
15-
global $room_id;
12+
global $msg;
13+
global $getdata;
14+
global $clear;
15+
global $room_id;
1616

17-
if ($this->action=='admin' && $clear) {
18-
SQLExec("DELETE FROM shouts");
19-
$this->redirect("?");
20-
}
17+
if ($this->action == 'admin' && $clear) {
18+
SQLExec("DELETE FROM shouts");
19+
$this->redirect("?");
20+
}
2121

22-
if (!$session->data['SITE_USERNAME']) {
23-
$out['NOT_LOGGED']=1;
24-
}
22+
if (!$session->data['SITE_USERNAME']) {
23+
$out['NOT_LOGGED'] = 1;
24+
}
2525

26-
if ($this->action=='' && $session->data['SITE_USER_ID'] && $msg!='') {
26+
if ($this->action == '' && $session->data['SITE_USER_ID'] && $msg != '') {
2727

28-
if ($session->data['TERMINAL']) {
29-
$terminal_rec = getTerminalsByName($session->data['TERMINAL'], 1)[0];
28+
if ($session->data['TERMINAL']) {
29+
$terminal_rec = getTerminalsByName($session->data['TERMINAL'], 1)[0];
3030

31-
if ($terminal_rec['ID']) {
32-
$terminal_rec['LATEST_ACTIVITY']=date('Y-m-d H:i:s');
33-
$terminal_rec['LATEST_REQUEST_TIME']=$terminal_rec['LATEST_ACTIVITY'];
34-
$terminal_rec['LATEST_REQUEST']=$rec['MESSAGE'].'';
35-
$terminal_rec['IS_ONLINE']=1;
36-
SQLUpdate('terminals', $terminal_rec);
31+
if ($terminal_rec['ID']) {
32+
$terminal_rec['LATEST_ACTIVITY'] = date('Y-m-d H:i:s');
33+
$terminal_rec['LATEST_REQUEST_TIME'] = $terminal_rec['LATEST_ACTIVITY'];
34+
$terminal_rec['LATEST_REQUEST'] = $rec['MESSAGE'] . '';
35+
$terminal_rec['IS_ONLINE'] = 1;
36+
SQLUpdate('terminals', $terminal_rec);
37+
}
3738
}
38-
}
39-
say(htmlspecialchars($msg), 0, $session->data['SITE_USER_ID'], 'terminal'.$terminal_rec['ID']);
40-
/*
41-
$rec=array();
42-
$rec['ROOM_ID']=(int)$room_id;
43-
$rec['MEMBER_ID']=$session->data['logged_user'];
44-
$rec['MESSAGE']=htmlspecialchars($msg);
45-
$rec['ADDED']=date('Y-m-d H:i:s');
46-
SQLInsert('shouts', $rec);
47-
*/
48-
49-
50-
/*
51-
include_once(DIR_MODULES.'patterns/patterns.class.php');
52-
$pt=new patterns();
53-
$res=$pt->checkAllPatterns($rec['MEMBER_ID']);
54-
if (!$res) {
55-
processCommand($msg);
56-
}
57-
*/
58-
$getdata=1;
59-
}
60-
61-
if ($this->owner->name=='panel') {
62-
$out['CONTROLPANEL']=1;
63-
}
64-
$qry="1";
65-
66-
if ($room_id) {
67-
$qry.=" AND ROOM_ID=".(int)$room_id;
68-
$session->data['SHOUT_ROOM_ID']=(int)$room_id;
69-
}
70-
71-
// search filters
72-
// QUERY READY
73-
global $save_qry;
74-
if ($save_qry) {
75-
$qry=$session->data['shouts_qry'];
76-
} else {
77-
$session->data['shouts_qry']=$qry;
78-
}
79-
if (!$qry) $qry="1";
80-
// FIELDS ORDER
81-
global $sortby;
82-
if (!$sortby) {
83-
$sortby=$session->data['shouts_sort'];
84-
} else {
85-
if ($session->data['shouts_sort']==$sortby) {
86-
if (Is_Integer(strpos($sortby, ' DESC'))) {
87-
$sortby=str_replace(' DESC', '', $sortby);
88-
} else {
89-
$sortby=$sortby." DESC";
39+
say(htmlspecialchars($msg), 0, $session->data['SITE_USER_ID'], 'terminal' . $terminal_rec['ID']);
40+
/*
41+
$rec=array();
42+
$rec['ROOM_ID']=(int)$room_id;
43+
$rec['MEMBER_ID']=$session->data['logged_user'];
44+
$rec['MESSAGE']=htmlspecialchars($msg);
45+
$rec['ADDED']=date('Y-m-d H:i:s');
46+
SQLInsert('shouts', $rec);
47+
*/
48+
49+
50+
/*
51+
include_once(DIR_MODULES.'patterns/patterns.class.php');
52+
$pt=new patterns();
53+
$res=$pt->checkAllPatterns($rec['MEMBER_ID']);
54+
if (!$res) {
55+
processCommand($msg);
9056
}
91-
}
92-
$session->data['shouts_sort']=$sortby;
93-
}
94-
if (!$sortby) $sortby="shouts.ADDED DESC";
95-
$out['SORTBY']=$sortby;
96-
// SEARCH RESULTS
97-
if ($this->action!='admin') {
98-
$limit="LIMIT 50";
99-
}
57+
*/
58+
$getdata = 1;
59+
}
10060

101-
global $limit;
102-
if ($limit) {
103-
$this->limit=$limit;
104-
}
61+
if ($this->owner->name == 'panel') {
62+
$out['CONTROLPANEL'] = 1;
63+
}
64+
$qry = "1";
65+
66+
if ($room_id) {
67+
$qry .= " AND ROOM_ID=" . (int)$room_id;
68+
$session->data['SHOUT_ROOM_ID'] = (int)$room_id;
69+
}
10570

106-
if ($this->limit) {
107-
$limit="LIMIT ".$this->limit;
108-
} else {
109-
$limit="LIMIT 50";
110-
}
111-
$limit=str_replace('LIMIT LIMIT', 'LIMIT', $limit);
71+
// search filters
72+
// QUERY READY
73+
global $save_qry;
74+
if ($save_qry) {
75+
$qry = $session->data['shouts_qry'];
76+
} else {
77+
$session->data['shouts_qry'] = $qry;
78+
}
79+
if (!$qry) $qry = "1";
80+
// FIELDS ORDER
81+
global $sortby;
82+
if (!$sortby) {
83+
$sortby = $session->data['shouts_sort'];
84+
} else {
85+
if ($session->data['shouts_sort'] == $sortby) {
86+
if (Is_Integer(strpos($sortby, ' DESC'))) {
87+
$sortby = str_replace(' DESC', '', $sortby);
88+
} else {
89+
$sortby = $sortby . " DESC";
90+
}
91+
}
92+
$session->data['shouts_sort'] = $sortby;
93+
}
94+
if (!$sortby) $sortby = "shouts.ADDED DESC";
95+
$out['SORTBY'] = $sortby;
96+
// SEARCH RESULTS
97+
if ($this->action != 'admin') {
98+
$limit = "LIMIT 50";
99+
}
100+
101+
global $limit;
102+
if ($limit) {
103+
$this->limit = $limit;
104+
}
105+
106+
if ($this->limit) {
107+
$limit = "LIMIT " . $this->limit;
108+
} else {
109+
$limit = "LIMIT 50";
110+
}
111+
$limit = str_replace('LIMIT LIMIT', 'LIMIT', $limit);
112112

113-
$out['LIMIT']=$this->limit;
113+
$out['LIMIT'] = $this->limit;
114114

115115

116-
$res=SQLSelect("SELECT shouts.*, DATE_FORMAT(shouts.ADDED, '%H:%i') as DAT, TO_DAYS(shouts.ADDED) as DT, users.NAME, users.COLOR FROM shouts LEFT JOIN users ON shouts.MEMBER_ID=users.ID WHERE $qry ORDER BY shouts.ADDED DESC, ID DESC $limit");
116+
$res = SQLSelect("SELECT shouts.*, DATE_FORMAT(shouts.ADDED, '%H:%i') as DAT, TO_DAYS(shouts.ADDED) as DT, users.NAME, users.COLOR FROM shouts LEFT JOIN users ON shouts.MEMBER_ID=users.ID WHERE $qry ORDER BY shouts.ADDED DESC, ID DESC $limit");
117117

118118

119119
// if ($_GET['reverse']) {
120-
$this->reverse=1;
120+
$this->reverse = 1;
121121
// }
122122

123-
if (!$this->reverse) {
124-
$res=array_reverse($res);
125-
} else {
126-
$out['REVERSE']=1;
127-
}
128-
$txtdata='';
129-
130-
if ($this->mobile) {
131-
$out['MOBILE']=1;
132-
}
133-
134-
if ($session->data['SHOUT_ROOM_ID'] && LOGGED_USER) {
135-
$room=SQLSelectOne("SELECT * FROM shoutrooms WHERE ID='".(int)$session->data['SHOUT_ROOM_ID']."'");
136-
//print_r($room);
137-
if ($room['ADDED_BY']==LOGGED_USER_ID) {
138-
$txtdata.="<small>[ <a href='/chat.html?delete_room=".$room['ID']."' onClick=\"return confirm('".LANG_STRING_DELETE_CONFIRM."')\">".LANG_STRING_DELETE."</a> ]</small>&nbsp;&nbsp;&nbsp;";
139-
$roomType = $room['IS_PUBLIC']?LANG_SHOUTROOMS_STRING_PRIVATE:LANG_SHOUTROOMS_STRING_PUBLIC;
140-
$txtdata.="<small>[ <a href='/chat.html?change_visibility=".$room['ID']."' onClick=\"return confirm('".LANG_STRING_OPERATION_CONFIRM."')\">$roomType</a> ]</small><br><br>";
141-
}
142-
}
143-
144-
if (defined('SETTINGS_GENERAL_ALICE_NAME') && SETTINGS_GENERAL_ALICE_NAME!='') {
145-
$comp_name=SETTINGS_GENERAL_ALICE_NAME;
123+
if (!$this->reverse) {
124+
$res = array_reverse($res);
146125
} else {
147-
$comp_name=LANG_DEFAULT_COMPUTER_NAME;
148-
}
149-
150-
if ($res[0]['ID']) {
151-
$old_dt=$res[0]['DT'];
152-
$total=count($res);
153-
for($i=0;$i<$total;$i++) {
154-
// some action for every record if required
155-
$tmp=explode(' ', $res[$i]['ADDED']);
156-
$res[$i]['ADDED']=fromDBDate($tmp[0])." ".$tmp[1];
157-
if ($res[$i]['DT']!=$old_dt) {
158-
$txtdata.="<hr size=1><b>".$tmp[0]."</b><br>";
159-
$old_dt=$res[$i]['DT'];
160-
}
161-
if ($res[$i]['MEMBER_ID']==0) {
162-
$res[$i]['NAME']=$comp_name;
126+
$out['REVERSE'] = 1;
127+
}
128+
$txtdata = '';
129+
130+
if ($this->mobile) {
131+
$out['MOBILE'] = 1;
132+
}
133+
134+
if ($session->data['SHOUT_ROOM_ID'] && LOGGED_USER) {
135+
$room = SQLSelectOne("SELECT * FROM shoutrooms WHERE ID='" . (int)$session->data['SHOUT_ROOM_ID'] . "'");
136+
//print_r($room);
137+
if ($room['ADDED_BY'] == LOGGED_USER_ID) {
138+
$txtdata .= "<small>[ <a href='/chat.html?delete_room=" . $room['ID'] . "' onClick=\"return confirm('" . LANG_STRING_DELETE_CONFIRM . "')\">" . LANG_STRING_DELETE . "</a> ]</small>&nbsp;&nbsp;&nbsp;";
139+
$roomType = $room['IS_PUBLIC'] ? LANG_SHOUTROOMS_STRING_PRIVATE : LANG_SHOUTROOMS_STRING_PUBLIC;
140+
$txtdata .= "<small>[ <a href='/chat.html?change_visibility=" . $room['ID'] . "' onClick=\"return confirm('" . LANG_STRING_OPERATION_CONFIRM . "')\">$roomType</a> ]</small><br><br>";
163141
}
164-
$stl='';
165-
if (trim($res[$i]['COLOR'])) {
166-
$stl=' style="color:'.$res[$i]['COLOR'].'"';
142+
}
143+
144+
if (defined('SETTINGS_GENERAL_ALICE_NAME') && SETTINGS_GENERAL_ALICE_NAME != '') {
145+
$comp_name = SETTINGS_GENERAL_ALICE_NAME;
146+
} else {
147+
$comp_name = LANG_DEFAULT_COMPUTER_NAME;
148+
}
149+
150+
if ($res[0]['ID']) {
151+
$old_dt = $res[0]['DT'];
152+
$total = count($res);
153+
for ($i = 0; $i < $total; $i++) {
154+
// some action for every record if required
155+
$tmp = explode(' ', $res[$i]['ADDED']);
156+
$res[$i]['ADDED'] = fromDBDate($tmp[0]) . " " . $tmp[1];
157+
if ($res[$i]['DT'] != $old_dt) {
158+
$txtdata .= "<hr size=1><b>" . $tmp[0] . "</b><br>";
159+
$old_dt = $res[$i]['DT'];
160+
}
161+
if ($res[$i]['MEMBER_ID'] == 0) {
162+
$res[$i]['NAME'] = $comp_name;
163+
}
164+
$stl = '';
165+
if (trim($res[$i]['COLOR'])) {
166+
$stl = ' style="color:' . $res[$i]['COLOR'] . '"';
167+
}
168+
$txtdata .= "<span$stl>" . $res[$i]['DAT'] . " <b>" . $res[$i]['NAME'] . "</b>: " . nl2br($res[$i]['MESSAGE']) . "</span><br>";
169+
if ($res[$i]['IMAGE'] != '' && file_exists($res[$i]['IMAGE'])) {
170+
if (preg_match('/^\//is', $res[$i]['IMAGE'])) {
171+
$res[$i]['IMAGE'] = str_replace(ROOT, ROOTHTML, $res[$i]['IMAGE']);
172+
}
173+
$txtdata .= "<div class='thumbnail' style='max-width: 600px'><img src='" . $res[$i]['IMAGE'] . "' alt=''/></div>";
174+
}
167175
}
168-
$txtdata.="<span$stl>".$res[$i]['DAT']." <b>".$res[$i]['NAME']."</b>: ".nl2br($res[$i]['MESSAGE'])."</span><br>";
169-
if ($res[$i]['IMAGE']!='' && file_exists($res[$i]['IMAGE'])) {
170-
$txtdata.="<div class='thumbnail' style='max-width: 600px'><img src='".$res[$i]['IMAGE']."' alt=''/></div>";
176+
$out['RESULT'] = $res;
177+
$out['TXT_DATA'] = $txtdata;
178+
} else {
179+
$txtdata .= 'No data';
180+
}
181+
182+
$rooms = SQLSelect("SELECT * FROM shoutrooms WHERE (IS_PUBLIC=1) OR (IS_PUBLIC=0 AND ADDED_BY=" . (int)$session->data['logged_user'] . ") OR (IS_PUBLIC=0 AND ID=" . (int)$session->data['SHOUT_ROOM_ID'] . ") ORDER BY PRIORITY DESC, TITLE");
183+
if ($rooms[0]['ID']) {
184+
$rooms[0]['FIRST'] = 1;
185+
$out['ROOMS'] = $rooms;
186+
if ($session->data['SHOUT_ROOM_ID']) {
187+
$out['INIT_ROOM_ID'] = $session->data['SHOUT_ROOM_ID'];
188+
} else {
189+
$out['INIT_ROOM_ID'] = $rooms[0]['ID'];
171190
}
172-
}
173-
$out['RESULT']=$res;
174-
$out['TXT_DATA']=$txtdata;
175-
} else {
176-
$txtdata.='No data';
177-
}
178-
179-
$rooms=SQLSelect("SELECT * FROM shoutrooms WHERE (IS_PUBLIC=1) OR (IS_PUBLIC=0 AND ADDED_BY=".(int)$session->data['logged_user'].") OR (IS_PUBLIC=0 AND ID=".(int)$session->data['SHOUT_ROOM_ID'].") ORDER BY PRIORITY DESC, TITLE");
180-
if ($rooms[0]['ID']) {
181-
$rooms[0]['FIRST']=1;
182-
$out['ROOMS']=$rooms;
183-
if ($session->data['SHOUT_ROOM_ID']) {
184-
$out['INIT_ROOM_ID']=$session->data['SHOUT_ROOM_ID'];
185-
} else {
186-
$out['INIT_ROOM_ID']=$rooms[0]['ID'];
187-
}
188-
}
189-
190-
$out['SERVER_NAME']=$_SERVER['SERVER_NAME'];
191-
192-
if ($this->action=='' && $getdata!='') {
193-
header ("HTTP/1.0: 200 OK\n");
194-
header ('Content-Type: text/html; charset=utf-8');
195-
echo $txtdata;
196-
$session->save();
197-
exit;
198-
}
191+
}
192+
193+
$out['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
194+
195+
if ($this->action == '' && $getdata != '') {
196+
header("HTTP/1.0: 200 OK\n");
197+
header('Content-Type: text/html; charset=utf-8');
198+
echo $txtdata;
199+
$session->save();
200+
exit;
201+
}
199202

200203

201204
?>

0 commit comments

Comments
 (0)