Cheetah
ChBlogsDb.php
Go to the documentation of this file.
1 <?php
2 
8 require_once( CH_DIRECTORY_PATH_CLASSES . 'ChWsbDb.php' );
9 
10 class ChBlogsDb extends ChWsbDb
11 {
12  var $_oConfig;
13 
14  /*
15  * Constructor.
16  */
17  function __construct(&$oConfig)
18  {
19  parent::__construct();
20 
21  $this->_oConfig = $oConfig;
22  }
23 
25  {
26  $sSql = "SELECT `ID` AS `id`, `Name` AS `name` FROM `sys_acl_actions` WHERE `Name`='use blog' OR `Name`='view blog'";
27  return $this->getAll($sSql);
28  }
29 
30  function getPostCaptionByID($iPostID)
31  {
32  $sSQL = "
33  SELECT `PostCaption`
34  FROM `{$this->_oConfig->sSQLPostsTable}`
35  WHERE `PostID`='{$iPostID}'
36  ";
37  return $this->getOne($sSQL);
38  }
39 
40  function getPostCaptionAndUriByID($iPostID)
41  {
42  $sSQL = "
43  SELECT `PostCaption`, `PostUri`
44  FROM `{$this->_oConfig->sSQLPostsTable}`
45  WHERE `PostID`= ?
46  ";
47  return $this->getRow($sSQL, [$iPostID]);
48  }
49 
50  function getPostCaptionByUri($sPostUri)
51  {
52  $sSQL = "
53  SELECT `PostCaption`
54  FROM `{$this->_oConfig->sSQLPostsTable}`
55  WHERE `PostUri`='{$sPostUri}'
56  ";
57  return $this->getOne($sSQL);
58  }
59 
60  function getAllBlogsCnt($sStatusFilter)
61  {
62  $sBlogsSQL = "
63  SELECT COUNT(DISTINCT(`{$this->_oConfig->sSQLBlogsTable}`.`ID`)) AS 'Cnt'
64  FROM `{$this->_oConfig->sSQLBlogsTable}`
65  INNER JOIN `{$this->_oConfig->sSQLPostsTable}` ON `{$this->_oConfig->sSQLPostsTable}`.`OwnerID` = `{$this->_oConfig->sSQLBlogsTable}`.`OwnerID`
66  WHERE {$sStatusFilter}
67  ";
68  return $this->getOne($sBlogsSQL);
69  }
70 
71  function getTopBlogs($sStatusFilter, $sqlLimit)
72  {
73  $sBlogsSQL = "
74  SELECT `{$this->_oConfig->sSQLBlogsTable}`.`ID`, `{$this->_oConfig->sSQLBlogsTable}`.`OwnerID`, `{$this->_oConfig->sSQLBlogsTable}`.`Description`, COUNT(`{$this->_oConfig->sSQLPostsTable}`.`PostID`) AS 'PostCount'
75  FROM `{$this->_oConfig->sSQLBlogsTable}`
76  INNER JOIN `{$this->_oConfig->sSQLPostsTable}` ON `{$this->_oConfig->sSQLPostsTable}`.`OwnerID` = `{$this->_oConfig->sSQLBlogsTable}`.`OwnerID`
77  WHERE {$sStatusFilter}
78  GROUP BY `{$this->_oConfig->sSQLBlogsTable}`.`ID`
79  ORDER BY `PostCount` DESC
80  {$sqlLimit}
81  ";
82  $vBlogsRes = db_res($sBlogsSQL);
83  return $vBlogsRes;
84  }
85 
86  function getLastBlogs($sStatusFilter, $sqlLimit)
87  {
88  $sBlogsSQL = "
89  SELECT `{$this->_oConfig->sSQLBlogsTable}`.`ID`, `{$this->_oConfig->sSQLBlogsTable}`.`OwnerID`, `{$this->_oConfig->sSQLBlogsTable}`.`Description`, COUNT(`{$this->_oConfig->sSQLPostsTable}`.`PostID`) AS 'PostCount'
90  FROM `{$this->_oConfig->sSQLBlogsTable}`
91  INNER JOIN `{$this->_oConfig->sSQLPostsTable}` ON `{$this->_oConfig->sSQLPostsTable}`.`OwnerID` = `{$this->_oConfig->sSQLBlogsTable}`.`OwnerID`
92  WHERE {$sStatusFilter}
93  GROUP BY `{$this->_oConfig->sSQLBlogsTable}`.`ID`
94  ORDER BY `PostDate` DESC
95  {$sqlLimit}
96  ";
97 
98  $vBlogsRes = db_res( $sBlogsSQL );
99  return $vBlogsRes;
100  }
101 
102  function getTagsInfo($iMemberID, $sStatusFilter, $sCategoryName)
103  {
104  $sCategJoin = $sCategFilter = '';
105  if ($sCategoryName != '') {
106  $sCategJoin = "
107  LEFT JOIN `{$this->_oConfig->sSQLCategoriesTable}` ON `{$this->_oConfig->sSQLCategoriesTable}`.`ID` = `{$this->_oConfig->sSQLPostsTable}`.`PostID`
108  ";
109  $sCategFilter = "
110  AND `{$this->_oConfig->sSQLCategoriesTable}`.`Category` = '{$sCategoryName}' AND {$this->_oConfig->sSQLCategoriesTable}`.`Type`='ch_blogs'
111  ";
112  }
113 
114  $sPostsSQL = "
115  SELECT
116  `Tags`,`OwnerID`
117  FROM `{$this->_oConfig->sSQLPostsTable}`
118  {$sCategJoin}
119  WHERE
120  `{$this->_oConfig->sSQLPostsTable}`.`OwnerID` = {$iMemberID}
121  {$sCategFilter}
122  {$sStatusFilter}
123  ";
124  $vTags = db_res($sPostsSQL);
125  return $vTags;
126  }
127 
128  function getPostsInCategory($sStatusFilter, $sCategoryName, $iOwnerID)
129  {
130  $sCategJoin = $sCategFilter = '';
131  if ($sCategoryName != '') {
132  $sCategJoin = "
133  LEFT JOIN `{$this->_oConfig->sSQLCategoriesTable}` ON `{$this->_oConfig->sSQLCategoriesTable}`.`ID` = `{$this->_oConfig->sSQLPostsTable}`.`PostID`
134  ";
135  $sCategFilter = "
136  AND `{$this->_oConfig->sSQLCategoriesTable}`.`Category` = '{$sCategoryName}' AND `{$this->_oConfig->sSQLCategoriesTable}`.`Type`='ch_blogs'
137  ";
138  }
139  $sPostsSQL = "
140  SELECT
141  `PostID`
142  FROM `{$this->_oConfig->sSQLPostsTable}`
143  {$sCategJoin}
144  WHERE
145  {$sStatusFilter}
146  {$sCategFilter}
147  AND `{$this->_oConfig->sSQLPostsTable}`.`OwnerID`='{$iOwnerID}'
148  ORDER BY `PostDate` ASC
149  ";
150  $vPostsInCat = db_res($sPostsSQL);
151 
152  $aPosts = array();
153  while ($aPost = $vPostsInCat->fetch()) {
154  $aPosts[] = (int)$aPost['PostID'];
155  }
156  return $aPosts;
157  }
158 
159  function getPostsCntInCategory($sCategoryName, $sStatusFilter, $iOwnerID)
160  {
161  $sCategJoin = "
162  LEFT JOIN `{$this->_oConfig->sSQLCategoriesTable}` ON `{$this->_oConfig->sSQLCategoriesTable}`.`ID` = `{$this->_oConfig->sSQLPostsTable}`.`PostID`
163  ";
164  $sCategFilter = "
165  AND `{$this->_oConfig->sSQLCategoriesTable}`.`Category` = '{$sCategoryName}' AND `{$this->_oConfig->sSQLCategoriesTable}`.`Type`='ch_blogs'
166  ";
167 
168  $sCountPostCatSQL = "
169  SELECT COUNT(*)
170  FROM `{$this->_oConfig->sSQLPostsTable}`
171  {$sCategJoin}
172  WHERE 1
173  {$sCategFilter}
174  AND `{$this->_oConfig->sSQLPostsTable}`.`OwnerID`='{$iOwnerID}'
175  {$sStatusFilter}
176  ";
177 
178  $iCountCatPost = (int)$this->getOne($sCountPostCatSQL);
179  return $iCountCatPost;
180  }
181 
182  function getFeaturedPosts($iMemberID)
183  {
184  $sFeaturedSQL = "
185  SELECT `{$this->_oConfig->sSQLPostsTable}`.*
186  FROM `{$this->_oConfig->sSQLPostsTable}`
187  WHERE `{$this->_oConfig->sSQLPostsTable}`.`OwnerID` = {$iMemberID} AND `{$this->_oConfig->sSQLPostsTable}`.`Featured`='1'
188  ORDER BY `PostDate` DESC
189  ";
190  $vFeaturedPosts = db_res($sFeaturedSQL);
191  return $vFeaturedPosts;
192  }
193 
194  function setPostStatus($iPostID, $sStatus = 'disapproval')
195  {
196  $sUpdateSQL = "
197  UPDATE `{$this->_oConfig->sSQLPostsTable}`
198  SET `PostStatus`='{$sStatus}'
199  WHERE `PostID`='{$iPostID}'
200  LIMIT 1";
201  return $this->query($sUpdateSQL);
202  }
203 
204  function getBlogInfo($iMemberID)
205  {
206  $sBlogsSQL = "
207  SELECT * FROM `{$this->_oConfig->sSQLBlogsTable}`
208  WHERE `{$this->_oConfig->sSQLBlogsTable}`.`OwnerID` = ?
209  LIMIT 1
210  ";
211 
212  return $this->getRow($sBlogsSQL, [$iMemberID]);
213  }
214 
215  function getPostOwnerByID($iPostID)
216  {
217  $sCheckPostSQL = "
218  SELECT `{$this->_oConfig->sSQLPostsTable}`.`OwnerID`
219  FROM `{$this->_oConfig->sSQLPostsTable}`
220  WHERE `PostID`='{$iPostID}'
221  ";
222  $iOwnerID = $this->getOne($sCheckPostSQL);
223  return $iOwnerID;
224  }
225 
226  function getOwnerByBlogID($iBlogID)
227  {
228  $sCheckSQL = "
229  SELECT `OwnerID`
230  FROM `{$this->_oConfig->sSQLBlogsTable}`
231  WHERE `ID`='{$iBlogID}'
232  ";
233  $iOwnerID = $this->getOne($sCheckSQL);
234  return $iOwnerID;
235  }
236 
237  function getPostPhotoByID($iPostID)
238  {
239  $sPhotosSQL = "SELECT `PostPhoto` FROM `{$this->_oConfig->sSQLPostsTable}` WHERE `PostID` = '{$iPostID}' LIMIT 1";
240  $sFileName = $this->getOne($sPhotosSQL);
241  return $sFileName;
242  }
243 
244  function performUpdatePostWithPhoto($iPostID, $sPhotoFilename = '')
245  {
246  $sUpdateSQL = "
247  UPDATE `{$this->_oConfig->sSQLPostsTable}` SET
248  `PostPhoto`='{$sPhotoFilename}'
249  WHERE `PostID`='{$iPostID}'
250  ";
251 
252  $vSqlRes = db_res($sUpdateSQL);
253  return $vSqlRes;
254  }
255 
256  function deletePost($iPostID)
257  {
258  $sDelSQL = "DELETE FROM `{$this->_oConfig->sSQLPostsTable}` WHERE `{$this->_oConfig->sSQLPostsTable}`.`PostID` = '{$iPostID}' LIMIT 1";
259  $vSqlRes = db_res($sDelSQL);
260  return $vSqlRes;
261  }
262 
263  function getPostIDByUri($sPostUri)
264  {
265  $sPostIdSQL = "SELECT `PostID` FROM `{$this->_oConfig->sSQLPostsTable}` WHERE `PostUri`='{$sPostUri}'";
266  $iPostID = (int)$this->getOne($sPostIdSQL);
267  return $iPostID;
268  }
269  function getPostUriByID($iPostID)
270  {
271  $sPostUriSQL = "SELECT `PostUri` FROM `{$this->_oConfig->sSQLPostsTable}` WHERE `PostID`='{$iPostID}'";
272  $sPostUri = $this->getOne($sPostUriSQL);
273  return $sPostUri;
274  }
275 
276  function getPostInfo($iPostID)
277  {
278  $sAllBlogPostInfoSQL = "
279  SELECT `{$this->_oConfig->sSQLPostsTable}`. * , `{$this->_oConfig->sSQLPostsTable}`.`PostCaption`
280  FROM `{$this->_oConfig->sSQLPostsTable}`
281  WHERE `{$this->_oConfig->sSQLPostsTable}`.`PostID` = ?
282  LIMIT 1
283  ";
284 
285  $aAllBlogPostInfo = $this->getRow($sAllBlogPostInfoSQL, [$iPostID]);
286  return $aAllBlogPostInfo;
287  }
288 
289  function getJustPostInfo($iPostID)
290  {
291  $sBlogPostsSQL = "SELECT * FROM `{$this->_oConfig->sSQLPostsTable}` WHERE `PostID` = ? LIMIT 1";
292  $aBlogPost = $this->getRow($sBlogPostsSQL, [$iPostID]);
293  return $aBlogPost;
294  }
295 
296  function getFeaturedStatus($iPostID)
297  {
298  $sCheckSQL = "
299  SELECT `Featured`
300  FROM `{$this->_oConfig->sSQLPostsTable}`
301  WHERE `PostID`='{$iPostID}'
302  ";
303  $iFeatured = $this->getOne($sCheckSQL);
304  return $iFeatured;
305  }
306 
307  function getActiveStatus($iPostID)
308  {
309  $sCheckSQL = "
310  SELECT `PostStatus`
311  FROM `{$this->_oConfig->sSQLPostsTable}`
312  WHERE `PostID`='{$iPostID}'
313  ";
314  $sStatus = $this->getOne($sCheckSQL);
315  return $sStatus;
316  }
317 
318  function performUpdateFeatureStatus($aParams)
319  {
320  $iPostID = $aParams['postID'];
321  $sStatus = $aParams['status'];
322 
323  $sUpdateSQL = "
324  UPDATE `{$this->_oConfig->sSQLPostsTable}`
325  SET
326  `Featured`='{$sStatus}'
327  WHERE
328  `PostID`='{$iPostID}'
329  ";
330  $this->query($sUpdateSQL);
331  }
332 
333  function performUpdateBlog($aParams)
334  {
335  $iBlogID = $aParams['blogID'];
336  $sDesc = $aParams['description'];
337 
338  $sUpdateSQL = "
339  UPDATE `{$this->_oConfig->sSQLBlogsTable}`
340  SET
341  `Description` = '{$sDesc}'
342  WHERE
343  `{$this->_oConfig->sSQLBlogsTable}`.`ID` = '{$iBlogID}'
344  LIMIT 1
345  ";
346  $this->query($sUpdateSQL);
347  }
348 
349  function deleteBlog($iBlogID)
350  {
351  $sDelSQL = "DELETE FROM `{$this->_oConfig->sSQLBlogsTable}` WHERE `ID` = '{$iBlogID}'";
352  $this->query($sDelSQL);
353  }
354 
355  function getMemberIDByNickname($sNickName)
356  {
357  $sCheckSQL = "SELECT `ID` FROM `Profiles` WHERE `NickName`='{$sNickName}'";
358  $iMemberID = (int)$this->getOne($sCheckSQL);
359  return $iMemberID;
360  }
361 
362  function getMemberPostsRSS($iPID)
363  {
364  $sUnitsSQL = "
365  SELECT DISTINCT `{$this->_oConfig->sSQLPostsTable}`.`PostID` AS 'UnitID',
366  `{$this->_oConfig->sSQLPostsTable}`.`OwnerID`,
367  `{$this->_oConfig->sSQLPostsTable}`.`PostCaption` AS 'UnitTitle',
368  `{$this->_oConfig->sSQLPostsTable}`.`PostUri` AS 'UnitUri',
369  `{$this->_oConfig->sSQLPostsTable}`.`PostText` AS 'UnitDesc',
370  `PostDate` AS 'UnitDateTimeUTS',
371  `{$this->_oConfig->sSQLPostsTable}`.`PostPhoto` AS 'UnitIcon'
372  FROM `{$this->_oConfig->sSQLPostsTable}`
373  WHERE `{$this->_oConfig->sSQLPostsTable}`.`PostStatus` = 'approval'
374  AND `{$this->_oConfig->sSQLPostsTable}`.`OwnerID` = '{$iPID}'
375  ORDER BY `{$this->_oConfig->sSQLPostsTable}`.`PostDate` DESC
376  LIMIT 10
377  ";
378  $aRssUnits = $this->getAll($sUnitsSQL);
379  return $aRssUnits;
380  }
381 
382  function getBlogPostsByMonth($iYear, $iMonth, $iNextYear, $iNextMonth, $sStatus = 'approval')
383  {
384  $sExtra = !empty($sStatus) ? " AND `{$this->_oConfig->sSQLPostsTable}`.`PostStatus` = " . $this -> escape($sStatus) : '';
385 
386  return $this->getAll ("
387  SELECT `{$this->_oConfig->sSQLPostsTable}`.*, DAYOFMONTH(FROM_UNIXTIME(`{$this->_oConfig->sSQLPostsTable}`.`PostDate`)) AS `Day`
388  FROM `{$this->_oConfig->sSQLPostsTable}`
389  WHERE
390  `{$this->_oConfig->sSQLPostsTable}`.`PostDate` >= UNIX_TIMESTAMP('{$iYear}-{$iMonth}-1')
391  AND `{$this->_oConfig->sSQLPostsTable}`.`PostDate` < UNIX_TIMESTAMP('{$iNextYear}-{$iNextMonth}-1')
392  $sExtra
393  ");
394  }
395 
396  function getMemberPostsCnt($iPID)
397  {
398  $sUnitsSQL = "
399  SELECT COUNT(`{$this->_oConfig->sSQLPostsTable}`.`PostID`)
400  FROM `{$this->_oConfig->sSQLPostsTable}`
401  WHERE `{$this->_oConfig->sSQLPostsTable}`.`PostStatus` = 'approval'
402  AND `{$this->_oConfig->sSQLPostsTable}`.`OwnerID` = '{$iPID}'
403  ";
404  return (int)$this->getOne($sUnitsSQL);
405  }
406 
408  {
409  return (int)$this->getOne("SELECT `ID` FROM `sys_options_cats` WHERE `name` = 'Blogs' LIMIT 1");
410  }
411 }
ChBlogsDb\getPostsCntInCategory
getPostsCntInCategory($sCategoryName, $sStatusFilter, $iOwnerID)
Definition: ChBlogsDb.php:159
ChBlogsDb\getOwnerByBlogID
getOwnerByBlogID($iBlogID)
Definition: ChBlogsDb.php:226
ChBlogsDb
Definition: ChBlogsDb.php:11
ChBlogsDb\getPostPhotoByID
getPostPhotoByID($iPostID)
Definition: ChBlogsDb.php:237
ChBlogsDb\setPostStatus
setPostStatus($iPostID, $sStatus='disapproval')
Definition: ChBlogsDb.php:194
ChBlogsDb\$_oConfig
$_oConfig
Definition: ChBlogsDb.php:12
ChBlogsDb\getAllBlogsCnt
getAllBlogsCnt($sStatusFilter)
Definition: ChBlogsDb.php:60
ChBlogsDb\performUpdateFeatureStatus
performUpdateFeatureStatus($aParams)
Definition: ChBlogsDb.php:318
ChBlogsDb\getPostUriByID
getPostUriByID($iPostID)
Definition: ChBlogsDb.php:269
$sSQL
$sSQL
Definition: ads_get_list.php:11
ChBlogsDb\getBlogInfo
getBlogInfo($iMemberID)
Definition: ChBlogsDb.php:204
ChBlogsDb\getTagsInfo
getTagsInfo($iMemberID, $sStatusFilter, $sCategoryName)
Definition: ChBlogsDb.php:102
php
ChWsbDb\getAll
getAll($sQuery, $aBindings=[], $iFetchType=PDO::FETCH_ASSOC)
Definition: ChWsbDb.php:206
ChBlogsDb\getMemberIDByNickname
getMemberIDByNickname($sNickName)
Definition: ChBlogsDb.php:355
ChBlogsDb\performUpdatePostWithPhoto
performUpdatePostWithPhoto($iPostID, $sPhotoFilename='')
Definition: ChBlogsDb.php:244
ChBlogsDb\getFeaturedPosts
getFeaturedPosts($iMemberID)
Definition: ChBlogsDb.php:182
ChBlogsDb\deletePost
deletePost($iPostID)
Definition: ChBlogsDb.php:256
ChBlogsDb\getPostCaptionByUri
getPostCaptionByUri($sPostUri)
Definition: ChBlogsDb.php:50
ChWsbDb\getRow
getRow($sQuery, $aBindings=[], $iFetchStyle=PDO::FETCH_ASSOC)
Definition: ChWsbDb.php:225
ChWsbDb\query
query($sQuery, $aBindings=[])
Definition: ChWsbDb.php:386
ChBlogsDb\getPostCaptionByID
getPostCaptionByID($iPostID)
Definition: ChBlogsDb.php:30
ChBlogsDb\getPostIDByUri
getPostIDByUri($sPostUri)
Definition: ChBlogsDb.php:263
ChBlogsDb\getFeaturedStatus
getFeaturedStatus($iPostID)
Definition: ChBlogsDb.php:296
ChBlogsDb\getMembershipActions
getMembershipActions()
Definition: ChBlogsDb.php:24
ChWsbDb\getOne
getOne($sQuery, $aBindings=[], $iIndex=0)
Definition: ChWsbDb.php:263
ChBlogsDb\getSettingsCategory
getSettingsCategory()
Definition: ChBlogsDb.php:407
ChBlogsDb\getJustPostInfo
getJustPostInfo($iPostID)
Definition: ChBlogsDb.php:289
ChBlogsDb\getBlogPostsByMonth
getBlogPostsByMonth($iYear, $iMonth, $iNextYear, $iNextMonth, $sStatus='approval')
Definition: ChBlogsDb.php:382
ChBlogsDb\getPostsInCategory
getPostsInCategory($sStatusFilter, $sCategoryName, $iOwnerID)
Definition: ChBlogsDb.php:128
ChBlogsDb\deleteBlog
deleteBlog($iBlogID)
Definition: ChBlogsDb.php:349
ChBlogsDb\getMemberPostsCnt
getMemberPostsCnt($iPID)
Definition: ChBlogsDb.php:396
ChBlogsDb\getTopBlogs
getTopBlogs($sStatusFilter, $sqlLimit)
Definition: ChBlogsDb.php:71
ChBlogsDb\getLastBlogs
getLastBlogs($sStatusFilter, $sqlLimit)
Definition: ChBlogsDb.php:86
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
ChBlogsDb\performUpdateBlog
performUpdateBlog($aParams)
Definition: ChBlogsDb.php:333
ChBlogsDb\getPostCaptionAndUriByID
getPostCaptionAndUriByID($iPostID)
Definition: ChBlogsDb.php:40
ChBlogsDb\getMemberPostsRSS
getMemberPostsRSS($iPID)
Definition: ChBlogsDb.php:362
ChBlogsDb\__construct
__construct(&$oConfig)
Definition: ChBlogsDb.php:17
ChBlogsDb\getPostInfo
getPostInfo($iPostID)
Definition: ChBlogsDb.php:276
ChBlogsDb\getPostOwnerByID
getPostOwnerByID($iPostID)
Definition: ChBlogsDb.php:215
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbDb
Definition: ChWsbDb.php:13
ChBlogsDb\getActiveStatus
getActiveStatus($iPostID)
Definition: ChBlogsDb.php:307
$sDesc
$sDesc
Definition: actions.inc.php:21
$sStatus
$sStatus
Definition: actions.inc.php:11
ChWsbDb\escape
escape($sText, $bReal=true)
Definition: ChWsbDb.php:624