40 parent::__construct($oConfig);
47 return $this->
getOne (
"SELECT `{$this->_sFieldId}` FROM `" . $this->_sPrefix . $this->_sTableMain .
"` WHERE `{$this->_sFieldStatus}` = 'approved' AND `{$this->_sFieldAllowViewTo}` = '" .
CH_WSB_PG_ALL .
"' LIMIT 1");
55 $sWhere =
" AND `{$this->_sFieldAuthorId}` = ? ";
56 $aBindings[] = $iOwner;
58 return $this->
getRow (
"SELECT * FROM `" . $this->_sPrefix . $this->_sTableMain .
"` WHERE `{$this->_sFieldId}` = ? $sWhere LIMIT 1", $aBindings);
68 return $this->
getPairs (
"SELECT `{$this->_sFieldId}` FROM `" . $this->_sPrefix . $this->_sTableMain .
"` WHERE `{$this->_sFieldAuthorId}` = '$iProfileId'", $this->_sFieldId, $this->_sFieldId);
73 return $this->
getOne (
"SELECT COUNT(*) FROM `" . $this->_sPrefix . $this->_sTableMain .
"` WHERE `{$this->_sFieldStatus}` = '$sStatus' AND `{$this->_sFieldAuthorId}` = '$iProfileId'");
78 return $this->
getRow (
"SELECT * FROM `" . $this->_sPrefix . $this->_sTableMain .
"` WHERE `{$this->_sFieldUri}` = ? LIMIT 1", [$sUri]);
83 $sWhere =
" AND `{$this->_sFieldFeatured}` = '1' ";
84 return $this->
getRow (
"SELECT * FROM `" . $this->_sPrefix . $this->_sTableMain .
"`
85 WHERE `{$this->_sFieldStatus}` = ? AND `{$this->_sFieldAllowViewTo}` = ? $sWhere ORDER BY `{$this->_sFieldCreated}` DESC LIMIT 1", [
'approved',
CH_WSB_PG_ALL]);
90 return $this->
getAll (
"SELECT *, DAYOFMONTH(FROM_UNIXTIME(`{$this->_sFieldCreated}`)) AS `Day`
91 FROM `" . $this->_sPrefix . $this->_sTableMain .
"`
92 WHERE `{$this->_sFieldCreated}` >= UNIX_TIMESTAMP('$iYear-$iMonth-1') AND `{$this->_sFieldCreated}` < UNIX_TIMESTAMP('$iNextYear-$iNextMonth-1') AND `{$this->_sFieldStatus}` = 'approved'");
99 $sWhere =
" AND `{$this->_sFieldAuthorId}` = '$iOwner' ";
100 if (!($iRet = $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableMain .
"` WHERE `{$this->_sFieldId}` = $iId $sWhere LIMIT 1")))
112 return $this->
query (
"UPDATE `" . $this->_sPrefix . $this->_sTableMain .
"` SET `{$this->_sFieldFeatured}` = (`{$this->_sFieldFeatured}` - 1)*(`{$this->_sFieldFeatured}` - 1) WHERE `{$this->_sFieldId}` = $iId LIMIT 1");
117 return $this->
query (
"UPDATE `" . $this->_sPrefix . $this->_sTableMain .
"` SET `{$this->_sFieldStatus}` = 'approved' WHERE `{$this->_sFieldId}` = $iId LIMIT 1");
122 function updateMedia ($iEntryId, $aMediaAdd, $aMediaDelete, $sMediaType)
124 $this->
deleteMedia ($iEntryId, $aMediaDelete, $sMediaType);
125 return $this->
insertMedia ($iEntryId, $aMediaAdd, $sMediaType);
132 if (is_array($aMedia))
133 $sValues = implode (
"), ($iEntryId, ", $aMedia);
135 $sValues = (int)$aMedia;
136 return $this->
query (
"INSERT IGNORE INTO `" . $this->_sPrefix . $this->_sTableMediaPrefix .
"{$sMediaType}` VALUES ($iEntryId, $sValues)");
143 if (is_array($aMedia))
144 $sValues = implode (
"') OR (`entry_id` = $iEntryId AND `media_id` = '", $aMedia);
146 $sValues = (int)$aMedia;
147 return $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix .
"{$sMediaType}` WHERE (`entry_id` = '$iEntryId' AND `media_id` = '$sValues')");
153 foreach ($a
as $iMediaId)
154 ChWsbService::call((
'images' == $sMediaType ?
'photos' : $sMediaType),
'remove_object', array($iMediaId));
155 return $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix .
"{$sMediaType}` WHERE `entry_id` = '$iEntryId'");
160 return $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix .
"{$sMediaType}` WHERE `media_id` = '$iMediaId'");
165 return $this->
getPairs (
"SELECT `media_id` FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix .
"{$sMediaType}` WHERE `entry_id` = '$iEntryId'",
'media_id',
'media_id');
170 return $this->
getOne (
"SELECT `entry_id` FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix .
"{$sMediaType}` WHERE `media_id` = '$iEntryId' LIMIT 1");
173 function getMedia ($iEntryId, $iMediaId, $sMediaType)
175 return $this->
getRow (
"SELECT `entry_id`, `media_id` FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix .
"{$sMediaType}` WHERE `entry_id` = ? AND `media_id` = ?", [$iEntryId, $iMediaId]);
181 $iOldThumbId = $this->
getOne (
"SELECT `{$this->_sFieldThumb}` FROM `" . $this->_sPrefix . $this->_sTableMain .
"` WHERE `{$this->_sFieldId}` = '$iEntryId' LIMIT 1");
182 if ($iOldThumbId > 0 && $this->
getOne(
"SELECT `entry_id` FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix.
"images` WHERE `media_id` = '$iOldThumbId' LIMIT 1") > 0)
184 $iImageId = $this->
getOne(
"SELECT `media_id` FROM `" . $this->_sPrefix . $this->_sTableMediaPrefix.
"images` WHERE `entry_id` = '$iEntryId' LIMIT 1");
189 return $this->
query (
"UPDATE `" . $this->_sPrefix . $this->_sTableMain .
"` SET `{$this->_sFieldThumb}` = '$iImageId' WHERE `{$this->_sFieldId}` = '$iEntryId' LIMIT 1");
196 return $this->
getRow (
"SELECT * FROM `" . $this->_sPrefix .
"forum` WHERE `forum_id` = ? LIMIT 1", [$iForumId]);
203 return $this->
query (
"INSERT INTO `" . $this->_sPrefix .
"forum` SET `forum_uri` = '{$aDataEntry[$this->_sFieldUri]}', `cat_id` = 1, `forum_title` = '{$sForumTitle}', `forum_desc` = '$sUsername', `forum_last` = UNIX_TIMESTAMP(), `forum_type` = 'public', `entry_id` = '{$aDataEntry[$this->_sFieldId]}'");
209 $gConf[
'db'][
'host'] = DATABASE_HOST;
210 $gConf[
'db'][
'db'] = DATABASE_NAME;
211 $gConf[
'db'][
'user'] = DATABASE_USER;
212 $gConf[
'db'][
'pwd'] = DATABASE_PASS;
213 $gConf[
'db'][
'port'] = DATABASE_PORT;
214 $gConf[
'db'][
'sock'] = DATABASE_SOCK;
217 require_once (CH_DIRECTORY_PATH_CLASSES .
'Thing.php');
218 if (!class_exists(
'ThingPage'))
219 require_once (CH_DIRECTORY_PATH_MODULES .
'cheetah/forum/classes/ThingPage.php');
220 if (!class_exists(
'Mistake'))
221 require_once (CH_DIRECTORY_PATH_MODULES .
'cheetah/forum/classes/Mistake.php');
222 if (!class_exists(
'ChDb'))
223 require_once (CH_DIRECTORY_PATH_MODULES .
'cheetah/forum/classes/ChDb.php');
224 if (!class_exists(
'DbAdmin'))
225 require_once (CH_DIRECTORY_PATH_MODULES .
'cheetah/forum/classes/DbAdmin.php');
228 $iForumId = $this->
getOne (
"SELECT `forum_id` FROM `" . $this->_sPrefix .
"forum` WHERE `entry_id` = '{$iEntryId}'");
229 return $db->deleteForumAll($iForumId);
237 return $a[
'NickName'];
242 if ($isProcessDbInput)
244 return $this->
getOne (
"SELECT `ID` FROM `Profiles` WHERE `NickName` = '$sNick' LIMIT 1");
251 return $this->
getOne(
"SELECT `ID` FROM `sys_options_cats` WHERE `name` = '{$sName}' LIMIT 1");
256 $a = $this->
getAllWithKey (
"SELECT `p`.`NickName`, `p`.`ID` FROM `sys_friend_list` AS `o` INNER JOIN `Profiles` AS `p` ON (`p`.`ID` = `o`.`ID` AND `o`.`Profile` = ?)",
'NickName', [
$iProfileId]);
257 $a = array_merge($a, $this->
getAllWithKey (
"SELECT `p`.`NickName`, `p`.`ID` FROM `sys_friend_list` AS `o` INNER JOIN `Profiles` AS `p` ON (`p`.`ID` = `o`.`Profile` AND `o`.`ID` = ?)",
'NickName', [
$iProfileId]));
258 $a = array_merge($a, $this->
getAllWithKey (
"SELECT `p`.`NickName`, `p`.`ID` FROM `sys_fave_list` AS `o` INNER JOIN `Profiles` AS `p` ON (`p`.`ID` = `o`.`ID` AND `o`.`Profile` = ?)",
'NickName', [
$iProfileId]));
259 $a = array_merge($a, $this->
getAllWithKey (
"SELECT `p`.`NickName`, `p`.`ID` FROM `sys_fave_list` AS `o` INNER JOIN `Profiles` AS `p` ON (`p`.`ID` = `o`.`Profile` AND `o`.`ID` = ?)",
'NickName', [
$iProfileId]));
260 $a = array_merge($a, $this->
getAllWithKey (
"SELECT `p`.`NickName`, `p`.`ID` FROM `sys_messages` AS `o` INNER JOIN `Profiles` AS `p` ON (`p`.`ID` = `o`.`Recipient` AND `o`.`Sender` = ?)",
'NickName', [
$iProfileId]));
261 foreach ($a
as $k => $r) {
275 return $this->
getAll (
"SELECT DISTINCT `p`.`ID`, `p`.`Email` FROM `" . $this->_sPrefix . $this->_sTableFans .
"` AS `f` INNER JOIN `Profiles` as `p` ON (`f`.`id_entry` = '$iEntryId' AND `f`.`id_profile` = `p`.`ID` AND `f`.`confirmed` = 1 AND `p`.`Status` = 'Active')");
280 $isConfirmed = $isConfirmed ? 1 : 0;
281 $iRet = $this->
query (
"INSERT IGNORE INTO `" . $this->_sPrefix . $this->_sTableFans .
"` SET `id_entry` = '$iEntryId', `id_profile` = '$iProfileId', `confirmed` = '$isConfirmed', `when` = '" .
time() .
"'");
282 if ($iRet && $isConfirmed)
283 $this->
query (
"UPDATE `" . $this->_sPrefix .
"main` SET `" . $this->_sFieldFansCount .
"` = `" . $this->_sFieldFansCount .
"` + 1 WHERE `id` = '$iEntryId'");
289 $isConfirmed = $this->
getOne (
"SELECT `confirmed` FROM `" . $this->_sPrefix . $this->_sTableFans .
"` WHERE `id_entry` = '$iEntryId' AND `id_profile` = '$iProfileId' LIMIT 1");
290 $iRet = $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableFans .
"` WHERE `id_entry` = '$iEntryId' AND `id_profile` = '$iProfileId'");
291 if ($iRet && $isConfirmed)
292 $this->
query (
"UPDATE `" . $this->_sPrefix .
"main` SET `" . $this->_sFieldFansCount .
"` = `" . $this->_sFieldFansCount .
"` - 1 WHERE `id` = '$iEntryId'");
298 $isConfirmed = $isConfirmed ? 1 : 0;
299 return $this->
getOne (
"SELECT `when` FROM `" . $this->_sPrefix . $this->_sTableFans .
"` WHERE `id_entry` = '$iEntryId' AND `id_profile` = '$iProfileId' AND `confirmed` = '$isConfirmed' LIMIT 1");
304 return $this->
getFans($aProfiles, $iEntryId,
true, $iStart, $iMaxNum);
307 function getFans(&$aProfiles, $iEntryId, $isConfirmed, $iStart, $iMaxNum, $aFilter = array())
309 $isConfirmed = $isConfirmed ? 1 : 0;
312 $s = implode (
' OR `f`.`id_profile` = ', $aFilter);
313 $sFilter =
' AND (`f`.`id_profile` = ' .
$s .
') ';
315 $aProfiles = $this->
getAll (
"SELECT SQL_CALC_FOUND_ROWS `p`.* FROM `Profiles` AS `p` INNER JOIN `" . $this->_sPrefix . $this->_sTableFans .
"` AS `f` ON (`f`.`id_entry` = '$iEntryId' AND `f`.`id_profile` = `p`.`ID` AND `f`.`confirmed` = $isConfirmed AND `p`.`Status` = 'Active' $sFilter) ORDER BY `f`.`when` DESC LIMIT $iStart, $iMaxNum");
316 return $this->
getOne(
"SELECT FOUND_ROWS()");
323 $s = implode (
' OR `id_profile` = ', $aProfileIds);
324 $iRet = $this->
query (
"UPDATE `" . $this->_sPrefix . $this->_sTableFans .
"` SET `confirmed` = 1 WHERE `id_entry` = '$iEntryId' AND `confirmed` = 0 AND (`id_profile` = $s)");
326 $this->
query (
"UPDATE `" . $this->_sPrefix .
"main` SET `" . $this->_sFieldFansCount .
"` = `" . $this->_sFieldFansCount .
"` + $iRet WHERE `id` = '$iEntryId'");
334 $s = implode (
' OR `id_profile` = ', $aProfileIds);
335 $iRet = $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableFans .
"` WHERE `id_entry` = '$iEntryId' AND `confirmed` = 1 AND (`id_profile` = $s)");
337 $this->
query (
"UPDATE `" . $this->_sPrefix .
"main` SET `" . $this->_sFieldFansCount .
"` = `" . $this->_sFieldFansCount .
"` - $iRet WHERE `id` = '$iEntryId'");
338 if ($iRet && $this->_sTableAdmins)
339 $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableAdmins .
"` WHERE `id_entry` = '$iEntryId' AND `id_profile` = $s");
350 $iDeleted = $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableFans .
"` WHERE `confirmed` = 0 AND `id_profile` = " .
$iProfileId);
353 $aEntries = $this->
getColumn(
"SELECT DISTINCT `id_entry` FROM `" . $this->_sPrefix . $this->_sTableFans .
"` WHERE `id_profile` = " .
$iProfileId);
354 foreach ($aEntries
as $iEntryId) {
367 return $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableAdmins .
"` WHERE `id_profile` = " .
$iProfileId);
374 $s = implode (
' OR `id_profile` = ', $aProfileIds);
375 return $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableFans .
"` WHERE `id_entry` = '$iEntryId' AND `confirmed` = 0 AND (`id_profile` = $s)");
378 function getAdmins(&$aProfiles, $iEntryId, $iStart, $iMaxNum, $aFilter = array())
382 $s = implode (
' OR `f`.`id_profile` = ', $aFilter);
383 $sFilter =
' AND (`f`.`id_profile` = ' .
$s .
') ';
385 $aProfiles = $this->
getAll (
"SELECT SQL_CALC_FOUND_ROWS `p`.* FROM `Profiles` AS `p` INNER JOIN `" . $this->_sPrefix . $this->_sTableAdmins .
"` AS `f` ON (`f`.`id_entry` = '$iEntryId' AND `f`.`id_profile` = `p`.`ID` AND `p`.`Status` = 'Active' $sFilter) ORDER BY `f`.`when` DESC LIMIT $iStart, $iMaxNum");
386 return $this->
getOne(
"SELECT FOUND_ROWS()");
391 return $this->
getOne (
"SELECT `when` FROM `" . $this->_sPrefix . $this->_sTableAdmins .
"` WHERE `id_entry` = '$iEntryId' AND `id_profile` = '$iProfileId' LIMIT 1");
396 if (is_array($aProfileIds)) {
399 $iRet += $this->
query (
"INSERT IGNORE INTO `" . $this->_sPrefix . $this->_sTableAdmins .
"` SET `id_entry` = '$iEntryId', `id_profile` = '$iProfileId', `when` = '" .
time() .
"'");
402 return $this->
query (
"INSERT IGNORE INTO `" . $this->_sPrefix . $this->_sTableAdmins .
"` SET `id_entry` = '$iEntryId', `id_profile` = '$aProfileIds', `when` = '" .
time() .
"'");
410 if (is_array($aProfileIds)) {
411 $s = implode (
' OR `id_profile` = ', $aProfileIds);
412 return $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableAdmins .
"` WHERE `id_entry` = '$iEntryId' AND (`id_profile` = $s)");
414 return $this->
query (
"DELETE FROM `" . $this->_sPrefix . $this->_sTableAdmins .
"` WHERE `id_entry` = '$iEntryId' AND `id_profile` = '$aProfileIds'");