8 require_once( CH_DIRECTORY_PATH_CLASSES .
'ChWsbModuleDb.php' );
18 parent::__construct();
20 $this->_oConfig = $oConfig;
21 $this->_sPrefix = $oConfig->getDbPrefix();
25 foreach($aData[
'handlers']
as $aHandler) {
27 $this->
deleteEvent(array(
'type' => $aHandler[
'alert_unit'],
'action' => $aHandler[
'alert_action']));
30 $this->
query(
"INSERT INTO `" . $this->_sPrefix .
"handlers`(`alert_unit`, `alert_action`, `module_uri`, `module_class`, `module_method`, `groupable`, `group_by`, `timeline`, `outline`) VALUES('" . $aHandler[
'alert_unit'] .
"', '" . $aHandler[
'alert_action'] .
"', '" . $aHandler[
'module_uri'] .
"', '" . $aHandler[
'module_class'] .
"', '" . $aHandler[
'module_method'] .
"', '" . $aHandler[
'groupable'] .
"', '" . $aHandler[
'group_by'] .
"', '" . $aHandler[
'timeline'] .
"', '" . $aHandler[
'outline'] .
"')");
34 $iHandlerId = (int)$this->
getOne(
"SELECT `id` FROM `sys_alerts_handlers` WHERE `name`='" . $this->_oConfig->getAlertSystemName() .
"' LIMIT 1");
36 foreach($aData[
'alerts']
as $aAlert)
37 $this->
query(
"INSERT INTO `sys_alerts`(`unit`, `action`, `handler_id`) VALUES('" . $aAlert[
'unit'] .
"', '" . $aAlert[
'action'] .
"', '" . $iHandlerId .
"')");
41 foreach($aData[
'handlers']
as $aHandler) {
43 $this->
deleteEvent(array(
'type' => $aHandler[
'alert_unit'],
'action' => $aHandler[
'alert_action']));
46 $this->
query(
"DELETE FROM `" . $this->_sPrefix .
"handlers` WHERE `alert_unit`='" . $aHandler[
'alert_unit'] .
"' AND `alert_action`='" . $aHandler[
'alert_action'] .
"' AND `module_uri`='" . $aHandler[
'module_uri'] .
"' AND `module_class`='" . $aHandler[
'module_class'] .
"' AND `module_method`='" . $aHandler[
'module_method'] .
"' LIMIT 1");
50 $iHandlerId = (int)$this->
getOne(
"SELECT `id` FROM `sys_alerts_handlers` WHERE `name`='" . $this->_oConfig->getAlertSystemName() .
"' LIMIT 1");
52 foreach($aData[
'alerts']
as $aAlert)
53 $this->
query(
"DELETE FROM `sys_alerts` WHERE `unit`='" . $aAlert[
'unit'] .
"' AND `action`='" . $aAlert[
'action'] .
"' AND `handler_id`='" . $iHandlerId .
"' LIMIT 1");
58 foreach($aParams
as $sKey => $sValue)
59 $aSet[] =
"`" . $sKey .
"`='" . $sValue .
"'";
60 if(!array_key_exists(
'date', $aParams))
61 $aSet[] =
"`date`=UNIX_TIMESTAMP()";
63 if((
int)$this->
query(
"INSERT INTO `" . $this->_sPrefix .
"events` SET " . implode(
", ", $aSet)) <= 0)
67 if(
$iId > 0 && isset($aParams[
'owner_id']) && (int)$aParams[
'owner_id'] > 0) {
70 $oAlert =
new ChWsbAlerts(
'ch_' . $this->_oConfig->getUri(),
'update', $aParams[
'owner_id']);
80 foreach($aParams
as $sKey => $sValue)
81 $aUpdate[] =
"`" . $sKey .
"`='" . $sValue .
"'";
82 $sSql =
"UPDATE `" . $this->_sPrefix .
"events` SET " . implode(
", ", $aUpdate) .
" WHERE `id`='" .
$iId .
"'";
83 return $this->
query($sSql);
88 foreach($aParams
as $sKey => $sValue)
89 $aWhere[] =
"`" . $sKey .
"`='" . $sValue .
"'";
90 $sSql =
"DELETE FROM `" . $this->_sPrefix .
"events` WHERE " . implode(
" AND ", $aWhere) . $sWhereAddon;
91 return $this->
query($sSql);
95 return $this->
deleteEvent($aParams,
" AND `type` LIKE '" . $this->_oConfig->getCommonPostPrefix() .
"%'");
102 $sWhereClause =
"`ID`= ?";
103 $aBindings = [$mixed];
106 $sWhereClause =
"`NickName`= ?";
107 $aBindings = [$mixed];
111 $sSql =
"SELECT `ID` AS `id`, `Couple` AS `couple`, `NickName` AS `username`, `Password` AS `password`, `Email` AS `email`, `Sex` AS `sex`, `Status` AS `status` FROM `Profiles` WHERE " . $sWhereClause .
" LIMIT 1";
115 $aUser = array(
'id' => 0,
'couple' => 0,
'username' =>
_t(
'_wall_anonymous'),
'password' =>
'',
'email' =>
'',
'sex' =>
'male');
126 switch($aParams[
'type']) {
128 $sWhereClause =
"AND `timeline`='1'";
131 $sWhereClause =
"AND `outline`='1'";
134 $sWhereClause =
"AND `module_uri`='" . $aParams[
'value'] .
"'";
140 `alert_unit` AS `alert_unit`,
141 `alert_action` AS `alert_action`,
142 `module_uri` AS `module_uri`,
143 `module_class` AS `module_class`,
144 `module_method` AS `module_method`,
145 `groupable` AS `groupable`,
146 `group_by` AS `group_by`,
147 `timeline` AS `timeline`,
148 `outline` AS `outline`
149 FROM `" . $this->_sPrefix .
"handlers`
150 WHERE 1 AND `alert_unit` NOT LIKE ('wall_common_%') " . $sWhereClause;
151 return $this->$sMethod($sSql);
157 $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause =
"";
159 $sWhereClause .=
"AND `te`.`active`='1' AND `te`.`hidden`<>'1' ";
161 $sWhereModuleFilter =
'';
162 if(isset($aParams[
'modules']) && !
empty($aParams[
'modules']) && is_array($aParams[
'modules']))
163 $sWhereModuleFilter =
"AND `type` IN ('" . implode(
"','", $aParams[
'modules']) .
"') ";
168 $iNowMorning = mktime(0, 0, 0, date(
'm'), date(
'd'), date(
'Y'));
169 $iNowEvening = mktime(23, 59, 59, date(
'm'), date(
'd'), date(
'Y'));
170 $sWhereClause .=
"AND `date`>='" . ($iNowMorning - 86400 * $iTLEnd) .
"' AND `date`<='" . ($iNowEvening - 86400 * $iTLStart) .
"' ";
173 switch($aParams[
'browse']) {
176 $sWhereClause =
"AND `te`.`id`='" . $aParams[
'object_id'] .
"' ";
177 $sLimitClause =
"LIMIT 1";
181 if($sWhereModuleFilter ==
'') {
183 $sWhereModuleFilter =
"AND `th`.`timeline`='1' AND `th`.`id` NOT IN ('" . implode(
"','", $aHidden) .
"') ";
186 if(!
empty($aParams[
'owner_id'])) {
187 if(is_array($aParams[
'owner_id'])) {
188 $sIds = implode(
"','", $aParams[
'owner_id']);
190 $sWhereClause .=
"AND (`te`.`owner_id` IN ('" . $sIds .
"') OR (`te`.`owner_id`='0' AND `te`.`object_id` IN ('" . $sIds .
"'))) ";
193 $sWhereClause .=
"AND (`te`.`owner_id`='" . $aParams[
'owner_id'] .
"' OR (`te`.`owner_id`='0' AND `te`.`object_id`='" . $aParams[
'owner_id'] .
"')) ";
196 $sWhereClause .=
"AND NOT(`te`.`owner_id`<>'0' AND `te`.`type` LIKE '" . $this->_oConfig->getCommonPostPrefix() .
"%' AND `te`.`action`='') ";
198 $sWhereClause .= isset($aParams[
'filter']) ? $this->
_getFilterAddon($aParams[
'owner_id'], $aParams[
'filter']) :
'';
199 $sWhereClause .= $sWhereModuleFilter;
200 $sOrderClause = isset($aParams[
'order']) ?
"ORDER BY `te`.`date` " . strtoupper($aParams[
'order']) :
"";
201 $sLimitClause = isset($aParams[
'count']) ?
"LIMIT " . $aParams[
'start'] .
", " . $aParams[
'count'] :
"";
207 if($sWhereModuleFilter ==
'') {
209 $sWhereModuleFilter =
"AND `th`.`timeline`='1' AND `th`.`id` NOT IN ('" . implode(
"','", $aHidden) .
"') ";
212 if(!
empty($aParams[
'owner_id'])) {
213 if(is_array($aParams[
'owner_id'])) {
214 $sIds = implode(
"','", $aParams[
'owner_id']);
216 $sWhereClause .=
"AND (`te`.`owner_id` IN ('" . $sIds .
"') OR (`te`.`owner_id`='0' AND `te`.`object_id` IN ('" . $sIds .
"'))) ";
219 $sWhereClause .=
"AND (`te`.`owner_id`='" . $aParams[
'owner_id'] .
"' OR (`te`.`owner_id`='0' AND `te`.`object_id`='" . $aParams[
'owner_id'] .
"')) ";
222 $sWhereClause .=
"AND NOT(`te`.`owner_id`<>'0' AND `te`.`type` LIKE '" . $this->_oConfig->getCommonPostPrefix() .
"%' AND `te`.`action`='') ";
224 $sWhereClause .= isset($aParams[
'filter']) ? $this->
_getFilterAddon($aParams[
'owner_id'], $aParams[
'filter']) :
'';
225 $sWhereClause .= $sWhereModuleFilter;
226 $sOrderClause =
"ORDER BY `te`.`date` ASC";
227 $sLimitClause =
"LIMIT 1";
234 if(isset($aParams[
'type']))
235 $sWhereClause .=
"AND `te`.`type`='" . $aParams[
'type'] .
"' ";
236 if(isset($aParams[
'action']))
237 $sWhereClause .=
"AND `te`.`action`='" . $aParams[
'action'] .
"' ";
238 if(isset($aParams[
'object_id']))
239 $sWhereClause .=
"AND `te`.`object_id`='" . $aParams[
'object_id'] .
"' ";
241 $sLimitClause =
"LIMIT 1";
244 case 'reposted_by_descriptor':
247 if(isset($aParams[
'type']))
248 $sWhereClause .=
"AND `te`.`content` LIKE '%" . $this->
escape($aParams[
'type'],
false) .
"%'";
250 if(isset($aParams[
'action']))
251 $sWhereClause .=
"AND `te`.`content` LIKE '%" . $this->
escape($aParams[
'action'],
false) .
"%'";
255 if($sWhereModuleFilter ==
'') {
257 $sWhereModuleFilter =
"AND `th`.`outline`='1' AND `th`.`id` NOT IN ('" . implode(
"','", $aHidden) .
"') ";
260 $sJoinClause =
"LEFT JOIN `Profiles` AS `tp` ON `te`.`owner_id`=`tp`.`ID`";
261 $sWhereClause .=
"AND `tp`.`Status`='Active' ";
262 $sWhereClause .= isset($aParams[
'filter']) ? $this->
_getFilterAddon($aParams[
'owner_id'], $aParams[
'filter']) :
'';
263 $sWhereClause .= $sWhereModuleFilter;
264 $sOrderClause = isset($aParams[
'order']) ?
"ORDER BY `te`.`date` " . strtoupper($aParams[
'order']) :
"";
265 $sLimitClause = isset($aParams[
'count']) ?
"LIMIT " . $aParams[
'start'] .
", " . $aParams[
'count'] :
"";
271 `te`.`owner_id` AS `owner_id`,
272 `te`.`object_id` AS `object_id`,
273 `te`.`type` AS `type`,
274 `te`.`action` AS `action`,
275 `te`.`content` AS `content`,
276 `te`.`title` AS `title`,
277 `te`.`description` AS `description`,
278 `te`.`reposts` AS `reposts`,
279 `te`.`date` AS `date`,
280 `te`.`active` AS `active`,
281 `te`.`hidden` AS `hidden`,
282 DATE_FORMAT(FROM_UNIXTIME(`te`.`date`), '" . $this->_oConfig->getDividerDateFormat() .
"') AS `print_date`,
283 DAYOFYEAR(FROM_UNIXTIME(`te`.`date`)) AS `days`,
284 DAYOFYEAR(NOW()) AS `today`,
285 (UNIX_TIMESTAMP() - `te`.`date`) AS `ago`,
286 ROUND((UNIX_TIMESTAMP() - `te`.`date`)/86400) AS `ago_days`
287 FROM `" . $this->_sPrefix .
"events` AS `te`
288 LEFT JOIN `" . $this->_sPrefix .
"handlers` AS `th` ON `te`.`type`=`th`.`alert_unit` AND `te`.`action`=`th`.`alert_action` " . $sJoinClause .
"
289 WHERE 1 " . $sWhereClause .
" " . $sOrderClause .
" " . $sLimitClause;
291 $aEvents = $this->$sMethod($sSql);
292 if(
empty($aEvents) || !is_array($aEvents))
295 if($sMethod ==
'getRow')
298 foreach($aEvents
as $iKey => $aEvent)
307 if(!
empty($iOwnerId)) {
308 if(!is_array($iOwnerId))
309 $sWhereClause =
"`owner_id`='" . $iOwnerId .
"' ";
311 $sWhereClause =
"`owner_id` IN ('" . implode(
"','", $iOwnerId) .
"') ";
317 $iNowMorning = mktime(0, 0, 0, date(
'm'), date(
'd'), date(
'Y'));
318 $iNowEvening = mktime(23, 59, 59, date(
'm'), date(
'd'), date(
'Y'));
319 $sWhereClause .=
"AND `date`>='" . ($iNowMorning - 86400 * $iTLEnd) .
"' AND `date`<='" . ($iNowEvening - 86400 * $iTLStart) .
"' ";
323 $sWhereClause .=
"AND `type` IN ('" . implode(
"','",
$aModules) .
"') ";
327 $sSql =
"SELECT COUNT(*) FROM `" . $this->_sPrefix .
"events` WHERE " . $sWhereClause .
" LIMIT 1";
328 return $this->
getOne($sSql);
337 $aHandler = $this->_oConfig->getHandlers(
$sType .
'_' .
$sAction);
338 if(
empty($aHandler) || !is_array($aHandler) || (
int)$aHandler[
'groupable'] != 1)
342 if(isset($aHandler[
'group_by']) && !
empty($aHandler[
'group_by']) && (!isset(
$oAlert->aExtras[$aHandler[
'group_by']]) ||
empty(
$oAlert->aExtras[$aHandler[
'group_by']])))
348 $iDayStart = mktime(0, 0, 0, date(
'm'), date(
'd'), date(
'Y'));
349 $iDayEnd = mktime(23, 59, 59, date(
'm'), date(
'd'), date(
'Y'));
350 $sWhereClause .=
"AND `date`>" . $iDayStart .
" AND `date`<" . $iDayEnd .
" ";
354 if(isset($aHandler[
'group_by']))
355 $sWhereClause .=
"AND `content` LIKE '%" .
$oAlert->aExtras[$aHandler[
'group_by']] .
"%' ";
357 $sSql =
"UPDATE `" . $this->_sPrefix .
"events`
362 `date`=UNIX_TIMESTAMP()
364 `id`<>'" .
$iId .
"' AND
365 `owner_id`='" .
$oAlert->iSender .
"' AND
366 `type`='" .
$sType .
"' AND
367 `action`='" .
$sAction .
"' " . $sWhereClause;
368 $mixedResult = $this->
query($sSql);
370 if((
int)$mixedResult > 0)
379 $sSql =
"SELECT COUNT(`cmt_id`) FROM `" . $this->_sPrefix .
"comments` WHERE `cmt_object_id`='" .
$iId .
"' AND `cmt_parent_id`='0' LIMIT 1";
380 return (
int)$this->
getOne($sSql);
387 'sharedPhoto' => array(
'table' =>
'ch_shared_photo_files',
'id' =>
'medID'),
388 'sharedSound' => array(
'table' =>
'RayMp3Files',
'id' =>
'ID'),
389 'sharedVideo' => array(
'table' =>
'RayVideoFiles',
'id' =>
'ID')
392 $sSql =
"SELECT `Categories` FROM `" . $aType2Db[
$sType][
'table'] .
"` WHERE `" . $aType2Db[
$sType][
'id'] .
"`='" .
$iId .
"' LIMIT 1";
393 return $this->
getOne($sSql);
402 $iAuthorNip = ip2long($sAuthorIp);
403 return (
int)$this->
query(
"INSERT INTO `" . $this->_sPrefix .
"repost_track` SET `event_id`='" . $iEventId .
"', `author_id`='" . $iAuthorId .
"', `author_nip`='" . $iAuthorNip .
"', `reposted_id`='" . $iRepostedId .
"', `date`='" . $iNow .
"'") > 0;
408 return (
int)$this->
query(
"DELETE FROM `" . $this->_sPrefix .
"repost_track` WHERE `event_id`='" . $iEventId .
"'") > 0;
413 $iReposts = (int)$iCounter + $iIncrement;
417 return (
int)$this->
updateEvent(array(
'reposts' => $iReposts),
$iId) > 0;
424 $aParams = array(
'browse' =>
'descriptor',
'type' =>
$sType,
'action' =>
$sAction,
'object_id' => $iObjectId);
426 $aParams = array(
'browse' =>
'id',
'object_id' => $iObjectId);
429 if($bSystem && (
empty($aReposted) || !is_array($aReposted))) {
434 $mixedResult = $this->_oConfig->getSystemDataByDescriptor(
$sType,
$sAction, $iObjectId);
435 if(is_array($mixedResult)) {
436 $iOwnerId = !
empty($mixedResult[
'owner_id']) ? (int)$mixedResult[
'owner_id'] : 0;
437 $iDate = !
empty($mixedResult[
'date']) ? (int)$mixedResult[
'date'] : 0;
443 'owner_id' => $iOwnerId,
446 'object_id' => $iObjectId,
454 $aReposted = $this->
getEvents(array(
'browse' =>
'id',
'object_id' =>
$iId));
462 return $this->
getColumn(
"SELECT `author_id` FROM `" . $this->_sPrefix .
"repost_track` WHERE `reposted_id`='" . $iRepostedId .
"'");
469 FROM `" . $this->_sPrefix .
"repost_track` AS `trt`
470 LEFT JOIN `" . $this->_sPrefix .
"events` AS `te` ON `trt`.`event_id`=`te`.`id`
471 WHERE `trt`.`author_id`='" . $iAuthorId .
"' AND `trt`.`reposted_id`='" . $iRepostedId .
"' AND `te`.`owner_id`='" . $iOwnerId .
"'";
473 return (
int)$this->
getOne($sQuery) > 0;
481 $sFilterAddon =
" AND `te`.`action`='' AND `te`.`object_id`='" . $iOwnerId .
"' ";
484 $sFilterAddon =
" AND `te`.`action`='' AND `te`.`object_id`<>'" . $iOwnerId .
"' ";
490 return $sFilterAddon;
496 $aEvent[
'content'] = str_replace(
"[ray_url]",
$sHomeUrl, $aEvent[
'content']);