Cheetah
ChWsbAlbums.php
Go to the documentation of this file.
1 <?php
2 
9 {
13  var $sType;
15  var $iOwnerId;
16 
17  function __construct($sType, $iOwnerId = 0)
18  {
19  $this->iOwnerId = (int)$iOwnerId;
20  $this->sType = process_db_input($sType, CH_TAGS_STRIP);
21  $this->sAlbumTable = 'sys_albums';
22  $this->sAlbumObjectsTable = 'sys_albums_objects';
23  $this->aAlbumFields = array(
24  'ID',
25  'Caption',
26  'Uri',
27  'Location',
28  'Description',
29  'Type',
30  'Owner',
31  'Status',
32  'Date',
33  'AllowAlbumView',
34  'ObjCount',
35  'LastObjId'
36  );
37  $this->sAlbumCoverParam = 'sys_make_album_cover_last';
38  }
39 
40  public static function getAbumName($sName, $iUserId)
41  {
42  $aReplacement = array(
43  '{nickname}' => getUsername($iUserId),
44  '{fullname}' => getNickName($iUserId)
45  );
46 
47  return str_replace(array_keys($aReplacement), array_values($aReplacement), $sName);
48  }
49 
50  public static function getAbumUri($sName, $iUserId)
51  {
52  return uriFilter(ChWsbAlbums::getAbumName($sName, $iUserId));
53  }
54 
55  // inner methods
56  function _getSqlPart($aFields = array(), $sBound = ', ', $bUseEmptyValues = false)
57  {
58  $sqlBody = "";
59  foreach ($aFields as $sKey => $sValue) {
60  if (in_array($sKey, $this->aAlbumFields) && ($bUseEmptyValues || strlen($sValue))) {
61  switch ($sKey) {
62  case 'description':
63  case 'Description':
64  $sValue = process_db_input($sValue, CH_TAGS_STRIP_AND_NL2BR);
65  break;
66 
67  default:
68  $sValue = process_db_input($sValue, CH_TAGS_STRIP);
69  break;
70  }
71 
72  $sqlBody .= "`{$this->sAlbumTable}`.`{$sKey}` = '$sValue'" . $sBound;
73  }
74  }
75 
76  return trim($sqlBody, $sBound);
77  }
78 
79  function _getSqlSpec($aData)
80  {
81  $aRes = array(
82  'vis' => '',
83  'empty' => '',
84  'def' => ''
85  );
86  if (isset($aData['allow_view']) && is_array($aData['allow_view'])) {
87  $aRes['vis'] = " AND `{$this->sAlbumTable}`.`AllowAlbumView` IN (" . implode(',',
88  $aData['allow_view']) . ")";
89  }
90  if (isset($aData['hide_default']) && $aData['hide_default'] === true) {
91  $aRes['def'] = " AND `{$this->sAlbumTable}`.`AllowAlbumView` <> " . CH_WSB_PG_HIDDEN;
92  }
93  if (!isset($aData['show_empty']) || $aData['show_empty'] === false) {
94  if (!isset($aData['obj_count']['min'])) {
95  $aData['obj_count']['min'] = 0;
96  }
97  }
98  if (isset($aData['obj_count'])) {
99  if (!is_array($aData['obj_count'])) {
100  $aData['obj_count']['min'] = (int)$aData['obj_count'];
101  }
102  $sqlObjMain = " AND `{$this->sAlbumTable}`.`ObjCount`";
103  $sqlMin = isset($aData['obj_count']['min']) ? "$sqlObjMain > " . (int)$aData['obj_count']['min'] : "";
104  $sqlMax = isset($aData['obj_count']['max']) ? "$sqlObjMain < " . (int)$aData['obj_count']['max'] : "";
105  $aRes['empty'] = "$sqlObjMain $sqlMin $sqlMax";
106  }
107 
108  return $aRes;
109  }
110 
111  // album methods
112  function addAlbum($aData = array(), $bCheck = true)
113  {
114  // Deano - This is temp fix for album caption quoting problem.
115  // I am still looking for the source of the problem.
116  $aData['caption'] = str_replace('\\','', $aData['caption']);
117 
118  if ($bCheck) {
119  $iCheck = $this->_checkAlbumExistence($aData);
120  if ($iCheck != 0) {
121  return $iCheck;
122  }
123  }
124  $iOwner = (int)$aData['owner'];
125 
126  if (isset($aData['AllowAlbumView'])) {
127  $iAllowAlbumView = (int)$aData['AllowAlbumView'];
128  } elseif (strpos($aData['caption'], getUsername($iOwner)) !== false) {
129  ch_import('ChWsbPrivacyQuery');
130  $oPrivacy = new ChWsbPrivacyQuery();
131  $iAllowAlbumView = $oPrivacy->getDefaultValueModule(str_replace('ch_', '', $this->sType), 'album_view');
132  if (!$iAllowAlbumView) {
133  $iAllowAlbumView = CH_WSB_PG_ALL;
134  }
135  } else {
136  $iAllowAlbumView = CH_WSB_PG_NOBODY;
137  }
138 
139  $sUri = $this->getCorrectUri($aData['caption'], $iOwner, $bCheck);
140  $GLOBALS['MySQL']->res("INSERT INTO `{$this->sAlbumTable}` SET " . $this->_getSqlPart(array(
141  'Caption' => $aData['caption'],
142  'Uri' => $sUri,
143  'Location' => $aData['location'],
144  'Description' => $aData['description'],
145  'AllowAlbumView' => $iAllowAlbumView,
146  'Type' => $this->sType,
147  'Owner' => $iOwner,
148  'Status' => 'active',
149  'Date' => time(),
150  'LastObjId' => isset($aData['lastObjId']) ? (int)$aData['last_obj'] : 0
151  )));
152 
153  $iResult = $GLOBALS['MySQL']->lastId();
154  if($iResult > 0) {
155  $oAlert = new ChWsbAlerts('album', 'add', $iResult, $iOwner, array('Type' => $this->sType, 'Uri' => $sUri));
156  $oAlert->alert();
157 
158  $oAlert = new ChWsbAlerts($this->sType, 'addAlbum', $iResult, $iOwner, array('Uri' => $sUri));
159  $oAlert->alert();
160  }
161 
162  return $iResult;
163  }
164 
165  function getCorrectUri($sCaption, $iOwnerId = 0, $bCheck = true)
166  {
167  $sUri = uriFilter($sCaption);
168  if (!$sUri) {
169  $sUri = '-';
170  }
171  if (!$bCheck) {
172  return $sUri;
173  }
174  if ($this->checkUriUniq($sUri, $iOwnerId)) {
175  return $sUri;
176  }
177  if (get_mb_len($sUri) > 240) {
178  $sUri = get_mb_substr($sUri, 0, 240);
179  }
180  $sUri .= '-' . date('Y-m-d');
181  if ($this->checkUriUniq($sUri, $iOwnerId)) {
182  return $sUri;
183  }
184  for ($i = 0; $i < 999; ++$i) {
185  if ($this->checkUriUniq($sUri . '-' . $i, $iOwnerId)) {
186  return ($sUri . '-' . $i);
187  }
188  }
189 
190  return time();
191  }
192 
193  function checkUriUniq($sUri, $iOwnerId)
194  {
195  $sUri = process_db_input($sUri, CH_TAGS_STRIP);
196  $iOwnerId = (int)$iOwnerId;
197 
198  return !$GLOBALS['MySQL']->getRow("SELECT 1 FROM $this->sAlbumTable WHERE `Uri` = ? AND `Owner` = ? AND `Type` = ? LIMIT 1",
199  [$sUri, $iOwnerId, $this->sType]);
200  }
201 
202  function updateAlbum($mixedIdent, $aData)
203  {
204  $sUri = process_db_input($mixedIdent, CH_TAGS_STRIP);
205  $iOwner = (int)$aData['Owner'] ? (int)$aData['Owner'] : $this->iOwnerId;
206  $aAlbum = $this->getAlbumInfo(array('fileUri' => $sUri, 'owner' => $iOwner), array('ID', 'Uri', 'Type'));
207 
208  return $this->_updateAlbum($aAlbum, $aData);
209  }
210 
211  function updateAlbumById ($iId, $aData)
212  {
213  $iId = (int)$iId;
214  $iOwner = (int)$aData['Owner'] ? (int)$aData['Owner'] : $this->iOwnerId;
215  $aAlbum = $this->getAlbumInfo(array('fileid' => $iId, 'owner' => $iOwner), array('ID', 'Uri', 'Type'));
216 
217  return $this->_updateAlbum($aAlbum, $aData);
218  }
219 
220  function _updateAlbum ($aAlbum, $aData)
221  {
222  if(empty($aAlbum) || !is_array($aAlbum))
223  return false;
224 
225  $sSetClause = $this->_getSqlPart($aData, ', ', true);
226  $sWhereClause = "`ID` = '" . $aAlbum['ID'] . "'";
227 
228  $mixedResult = $GLOBALS['MySQL']->res("UPDATE `{$this->sAlbumTable}` SET " . $sSetClause . " WHERE " . $sWhereClause . " LIMIT 1");
229  if((int)$mixedResult > 0) {
230  $iUserId = getLoggedId();
231 
232  $oAlert = new ChWsbAlerts('album', 'change', $aAlbum['ID'], $iUserId, array('Type' => $aAlbum['Type'], 'Uri' => $aAlbum['Uri']));
233  $oAlert->alert();
234 
235  $oAlert = new ChWsbAlerts($aAlbum['Type'], 'changeAlbum', $aAlbum['ID'], $iUserId, array('Uri' => $aAlbum['Uri']));
236  $oAlert->alert();
237  }
238 
239  return $mixedResult;
240  }
241 
242  function removeAlbum ($iAlbumId)
243  {
244  $iAlbumId = (int)$iAlbumId;
245 
246  $aObj = $this->getAlbumObjList($iAlbumId);
247  $this->removeObject($iAlbumId, $aObj);
248 
249  $aAlbum = $this->getAlbumInfo(array('fileid' => $iAlbumId), array('ID', 'Uri', 'Type'));
250  if(empty($aAlbum) || !is_array($aAlbum))
251  return true;
252 
253  $mixedResult = $GLOBALS['MySQL']->res("DELETE FROM `{$this->sAlbumTable}` WHERE `ID`='" . $iAlbumId . "'");
254  if((int)$mixedResult > 0) {
255  $iUserId = getLoggedId();
256 
257  $oAlert = new ChWsbAlerts('album', 'delete', $iAlbumId, $iUserId, array('Type' => $aAlbum['Type'], 'Uri' => $aAlbum['Uri']));
258  $oAlert->alert();
259 
260  $oAlert = new ChWsbAlerts($aAlbum['Type'], 'deleteAlbum', $iAlbumId, $iUserId, array('Uri' => $aAlbum['Uri']));
261  $oAlert->alert();
262  }
263 
264  return $mixedResult;
265  }
266 
267  function _checkAlbumExistence($aData)
268  {
269  $aFields = array(
270  'Caption' => $aData['caption'],
271  'Type' => $this->sType,
272  'Owner' => (int)$aData['owner'],
273  );
274  $sqlBody = $this->_getSqlPart($aFields, ' AND');
275  $sqlQuery = "SELECT `ID` FROM {$this->sAlbumTable} WHERE $sqlBody";
276 
277  return (int)$GLOBALS['MySQL']->getOne($sqlQuery);
278  }
279 
280  function getAlbumObjList($mixedAlbum)
281  {
282  $sqlJoin = "";
283  if ((int)$mixedAlbum > 0) {
284  $sqlWhere = "`id_album`='" . (int)$mixedAlbum . "'";
285  } else {
286  $sqlJoin = "LEFT JOIN `sys_albums` ON `sys_albums_objects`.`id_album` = `sys_albums`.`ID`";
287  $sqlWhere = "`sys_albums`.`Uri` = '" . process_db_input($mixedAlbum, CH_TAGS_STRIP) . "'";
288  }
289  $sqlQuery = "SELECT `id_object` FROM `{$this->sAlbumObjectsTable}` $sqlJoin WHERE $sqlWhere";
290 
291  return $GLOBALS['MySQL']->getPairs($sqlQuery, 'id_object', 'id_object');
292  }
293 
294  function getAlbumCoverFiles($iAlbumId, $aJoin = array(), $aJoinCond = array(), $iLimit = 4)
295  {
296  $iAlbumId = (int)$iAlbumId;
297  $iLimit = (int)$iLimit;
298  $sqlWhere = "`id_album`='$iAlbumId'";
299  $sqlAddFields = '';
300  if (is_array($aJoin)) {
301  $sqlJoin = "INNER JOIN `{$aJoin['table']}` ON `{$aJoin['table']}`.`{$aJoin['field']}`=`{$this->sAlbumObjectsTable}`.`id_object`";
302  if (is_array($aJoinCond)) {
303  foreach ($aJoinCond as $aValue) {
304  $sqlWhere .= " AND `{$aJoin['table']}`.`{$aValue['field']}`='{$aValue['value']}'";
305  }
306  }
307  if (is_array($aJoin['fields_list'])) {
308  $sqlAddFields = ", `" . implode("`, `", $aJoin['fields_list']) . "`";
309  }
310  }
311  $sqlQuery = "SELECT `id_object` $sqlAddFields FROM `{$this->sAlbumObjectsTable}` $sqlJoin WHERE $sqlWhere ORDER BY `obj_order`, `id_object` DESC LIMIT $iLimit";
312 
313  return $GLOBALS['MySQL']->getAll($sqlQuery);
314  }
315 
316  function getAlbumList($aData = array(), $iPage = 1, $iPerPage = 10, $bSimple = false)
317  {
318  $aFields = array(
319  'Type' => $this->sType,
320  'Status' => !isset($aData['status']) ? 'active' : $aData['status'],
321  'Caption' => isset($aData['caption']) ? $aData['caption'] : '',
322  );
323  if ($aFields['Status'] == 'any') {
324  unset($aFields['Status']);
325  }
326  if (isset($aData['owner']) && strlen($aData['owner']) > 0) {
327  if ((int)$aData['owner'] == 0) {
328  $iUserId = getID($aData['owner']);
329  $aFields['Owner'] = $iUserId > 0 ? $iUserId : '';
330  } else {
331  $aFields['Owner'] = (int)$aData['owner'];
332  }
333  }
334 
335  $aSqlSpec = $this->_getSqlSpec($aData);
336 
337  $sqlLimit = "";
338  if (!$bSimple) {
339  $iPage = (int)$iPage;
340  $iPerPage = (int)$iPerPage;
341  if ($iPage < 1) {
342  $iPage = 1;
343  }
344  if ($iPerPage < 1) {
345  $iPerPage = 10;
346  }
347 
348  $sqlLimit = "LIMIT " . ($iPage - 1) * $iPerPage . ", " . $iPerPage;
349  }
350 
351  $sqlJoin = "";
352  $sqlJoinWhere = "";
353  if (isset($aData['ownerStatus'])) {
354  $sqlJoin = "LEFT JOIN `Profiles` ON `Profiles`.`ID`=`{$this->sAlbumTable}`.`Owner`";
355  $sqlJoinWhere = "AND `Profiles`.`Status` ";
356  if (is_array($aData['ownerStatus'])) {
357  $sqlJoinWhere .= "NOT IN ('" . implode("','", $aData['ownerStatus']) . "')";
358  } else {
359  $sqlJoinWhere .= "<> '{$aData['ownerStatus']}'";
360  }
361  }
362 
363  $sqlBegin = "SELECT `{$this->sAlbumTable}`.* FROM `{$this->sAlbumTable}` $sqlJoin";
364  $sqlCond = "WHERE " . $this->_getSqlPart($aFields, ' AND ');
365  $sqlOrder = "ORDER BY `{$this->sAlbumTable}`.`Date` DESC";
366  $sqlQuery = "$sqlBegin $sqlCond {$aSqlSpec['vis']} {$aSqlSpec['def']} {$aSqlSpec['empty']} $sqlJoinWhere $sqlOrder $sqlLimit";
367 
368  return $GLOBALS['MySQL']->getAll($sqlQuery);
369  }
370 
371  function getAlbumCount($aData = array())
372  {
373  // Create the Friends only album if it does not exist.
374  $iProfileId = (int)$aData['owner'];
375  if($iProfileId) {
376  $aNew = array(
377  'caption' => _t('_sys_album_select_friends'),
378  'AllowAlbumView' => 5,
379  'owner' => $iProfileId,
380  );
381  $this->addAlbum($aNew);
382 
383  // Create the Private album if it does not exist.
384  $aNew = array(
385  'caption' => _t('_sys_album_select_private'),
386  'AllowAlbumView' => 2,
387  'owner' => $iProfileId,
388  );
389  $this->addAlbum($aNew);
390  }
391 
392  $aFields = array(
393  'Type' => $this->sType,
394  'Status' => !isset($aData['status']) ? 'active' : $aData['status'],
395  );
396  if (isset($aData['owner']) && strlen($aData['owner']) > 0) {
397  if ((int)$aData['owner'] == 0) {
398  $iUserId = getID($aData['owner']);
399  $aFields['Owner'] = $iUserId > 0 ? $iUserId : '';
400  } else {
401  $aFields['Owner'] = (int)$aData['owner'];
402  }
403  }
404  $aSqlSpec = $this->_getSqlSpec($aData);
405 
406  $sqlJoin = "";
407  $sqlJoinWhere = "";
408  if (isset($aData['ownerStatus'])) {
409  $sqlJoin = "LEFT JOIN `Profiles` ON `Profiles`.`ID`=`{$this->sAlbumTable}`.`Owner`";
410  $sqlJoinWhere = "AND `Profiles`.`Status` ";
411  if (is_array($aData['ownerStatus'])) {
412  $sqlJoinWhere .= "NOT IN ('" . implode("','", $aData['ownerStatus']) . "')";
413  } else {
414  $sqlJoinWhere .= "<> '{$aData['ownerStatus']}'";
415  }
416  }
417 
418  $sqlBegin = "SELECT COUNT(*) FROM `{$this->sAlbumTable}` $sqlJoin";
419  $sqlCond = "WHERE " . $this->_getSqlPart($aFields, ' AND ');
420  $sqlQuery = "$sqlBegin $sqlCond {$aSqlSpec['vis']} {$aSqlSpec['def']} {$aSqlSpec['empty']} $sqlJoinWhere";
421 
422  return $GLOBALS['MySQL']->getOne($sqlQuery);
423  }
424 
425  function getAlbumInfo($aIdent = array(), $aFields = array())
426  {
427  $sqlCondition = "`{$this->sAlbumTable}`.`Type`= ?";
428  $aBindings = [$this->sType];
429  $aParams = array();
430  // TODO: need dynamic pdo bindings
431  foreach ($aIdent as $sKey => $sValue) {
432  switch (strtolower($sKey)) {
433  case 'fileuri':
434  $aParams['Uri'] = $sValue;
435  break;
436  case 'fileid':
437  $aParams['ID'] = (int)$sValue;
438  break;
439  case 'owner':
440  $aParams['Owner'] = (int)$sValue;
441  break;
442  default:
443  $aParams[$sKey] = $sValue;
444  }
445  }
446  $aParams['Type'] = $this->sType;
447  if (count($aFields) == 0) {
449  }
450  $sqlCondition = $this->_getSqlPart($aParams, ' AND ');
451  foreach ($aFields as $sValue) {
452  if (in_array($sValue, $this->aAlbumFields)) {
453  $sqlFields .= "`{$this->sAlbumTable}`.`$sValue`, ";
454  }
455  }
456  $sqlFields = trim($sqlFields, ', ');
457  $sqlQuery = "SELECT $sqlFields FROM `{$this->sAlbumTable}` WHERE $sqlCondition LIMIT 1";
458 
459  return $GLOBALS['MySQL']->getRow($sqlQuery);
460  }
461 
462  function getAlbumName($iAlbumId)
463  {
464  $aValue = $this->getAlbumInfo(array('fileId' => (int)$iAlbumId), array('Caption'));
465 
466  return $aValue['Caption'];
467  }
468 
470  {
471  return getParam('sys_album_default_name');
472  }
473 
474  // album's objects methods
475  function addObject($iAlbumId, $mixedObj, $bUpdateCount = true)
476  {
477  $iAlbumId = (int)$iAlbumId;
478  if ($iAlbumId == 0) {
479  return;
480  }
481  $sqlFields = "`id_album`, `id_object`, `obj_order`";
482  $sqlBody = "";
483  $iLastObjId = $this->getLastObj($iAlbumId);
484  $iCount = 0;
485  if (is_array($mixedObj)) {
486  foreach ($mixedObj as $iValue) {
487  $iValue = (int)$iValue;
488  $sqlBody .= "('$iAlbumId', '$iValue', '$iValue'), ";
489  $iCount++;
490  }
491  } else {
492  $iValue = (int)$mixedObj;
493  $sqlBody = "('$iAlbumId', '$iValue', '$iValue')";
494  $iCount++;
495  }
496  $sqlQuery = "INSERT INTO `{$this->sAlbumObjectsTable}` ($sqlFields) VALUES " . trim($sqlBody, ', ');
497  $iRes = $GLOBALS['MySQL']->query($sqlQuery);
498 
499  if ($bUpdateCount) {
500  $this->updateObjCounter($iAlbumId, $iCount);
501  if ($iLastObjId == 0) {
502  $this->updateLastObj($iAlbumId, $iValue);
503  } elseif ($iLastObjId != 0 && getParam($this->sAlbumCoverParam) == 'on') {
504  $this->updateLastObj($iAlbumId, $iValue);
505  }
506  }
507 
508  return $iRes;
509  }
510 
511  function moveObject($iAlbumId, $iNewAlbumId, $mixedObj)
512  {
513  $iAlbumId = (int)$iAlbumId;
514  $iNewAlbumId = (int)$iNewAlbumId;
515  $sqlBody = "";
516  $iLastObjId = $this->getLastObj($iAlbumId);
517  if (!empty($mixedObj)) {
518  $iCount = 0;
519  if (is_array($mixedObj)) {
520  if (in_array($iLastObjId, $mixedObj)) {
521  $bUpdateLastObj = true;
522  }
523  foreach ($mixedObj as $iValue) {
524  $iValue = (int)$iValue;
525  $sqlBody .= "'$iValue', ";
526  $iCount++;
527  }
528  } else {
529  $iValue = (int)$mixedObj;
530  $sqlBody = "'$iValue'";
531  $iCount++;
532  if ($iValue == $iLastObjId) {
533  $bUpdateLastObj = true;
534  }
535  }
536  $sqlQuery = "UPDATE `{$this->sAlbumObjectsTable}`, `{$this->sAlbumTable}`
537  SET `{$this->sAlbumObjectsTable}`.`id_album` = $iNewAlbumId
538  WHERE `{$this->sAlbumObjectsTable}`.`id_album`=`{$this->sAlbumTable}`.`ID`
539  AND `{$this->sAlbumTable}`.`Type` = '$this->sType' AND `{$this->sAlbumObjectsTable}`.`id_object` IN (" . trim($sqlBody,
540  ', ') . ")";
541  $GLOBALS['MySQL']->res($sqlQuery);
542  if ($bUpdateLastObj) {
543  $this->updateLastObj($iAlbumId);
544  }
545  $this->updateLastObj($iNewAlbumId);
546 
547  $sqlQuery = "UPDATE `{$this->sAlbumTable}` SET `ObjCount` = CASE
548  WHEN `ID`={$iAlbumId} THEN `ObjCount`-$iCount
549  WHEN `ID`={$iNewAlbumId} THEN `ObjCount`+$iCount END
550  WHERE `ID` IN ($iAlbumId, $iNewAlbumId)";
551  $GLOBALS['MySQL']->res($sqlQuery);
552  }
553  }
554 
555  function removeObject($iAlbumId, $mixedObj, $bUpdateCount = true)
556  {
557  $iAlbumId = (int)$iAlbumId;
558  $sqlBody = "";
559  $iLastObjId = $this->getLastObj($iAlbumId);
560  $iCount = 0;
561  if (!empty($mixedObj)) {
562  if (is_array($mixedObj)) {
563  if (in_array($iLastObjId, $mixedObj)) {
564  $bUpdateLastObj = true;
565  }
566  foreach ($mixedObj as $iValue) {
567  $iValue = (int)$iValue;
568  $sqlBody .= "'$iValue', ";
569  $iCount++;
570  }
571  } else {
572  $iValue = (int)$mixedObj;
573  $sqlBody = "'$iValue'";
574  if ($iValue == $iLastObjId) {
575  $bUpdateLastObj = true;
576  }
577  $iCount++;
578  }
579  $sqlQuery = "DELETE `{$this->sAlbumObjectsTable}`
580  FROM `{$this->sAlbumObjectsTable}`, `{$this->sAlbumTable}`
581  WHERE `{$this->sAlbumObjectsTable}`.`id_album`=`{$this->sAlbumTable}`.`ID`
582  AND `{$this->sAlbumTable}`.`Type` = '$this->sType' AND `{$this->sAlbumObjectsTable}`.`id_object` IN (" . trim($sqlBody,
583  ', ') . ")";
584  $GLOBALS['MySQL']->res($sqlQuery);
585  if ($bUpdateLastObj) {
586  $this->updateLastObj($iAlbumId);
587  }
588  if ($bUpdateCount) {
589  $this->updateObjCounter($iAlbumId, $iCount, false);
590  }
591  }
592  }
593 
594  function removeObjectTotal($iObj, $bUpdateCounter = true)
595  {
596  $iObj = (int)$iObj;
597  $sqlQuery = "SELECT `id_album` as `ID`, `ObjCount`, `LastObjId`
598  FROM `{$this->sAlbumObjectsTable}`
599  LEFT JOIN `{$this->sAlbumTable}` ON `{$this->sAlbumTable}`.`ID` = `{$this->sAlbumObjectsTable}`.`id_album`
600  WHERE `id_object` = ? AND `$this->sAlbumTable`.`Type` = ?";
601  $aInfo = $GLOBALS['MySQL']->getRow($sqlQuery, [$iObj, $this->sType]);
602  $sqlDelete = "DELETE FROM `{$this->sAlbumObjectsTable}` WHERE `id_album`='{$aInfo['ID']}' AND `id_object`='$iObj' LIMIT 1";
603  $GLOBALS['MySQL']->res($sqlDelete);
604  if ($aInfo['ObjCount'] > 0 && $bUpdateCounter) {
605  $this->updateObjCounter($aInfo['ID'], 1, false);
606  }
607  if ($aInfo['LastObjId'] == $iObj) {
608  $this->updateLastObj($aInfo['ID']);
609  }
610  }
611 
612  function sortObjects($sAlbumUri, $aSort = array())
613  {
614  $aAlbumInfo = $this->getAlbumInfo(array('fileUri' => $sAlbumUri, 'owner' => $this->iOwnerId), array('ID'));
615  $sqlBegin = "UPDATE `{$this->sAlbumObjectsTable}` SET `obj_order` = ";
616  $sqlAlbumPart = " `id_album`='{$aAlbumInfo['ID']}'";
617  $iNum = is_array($aSort) ? count($aSort) : 0;
618  if ($iNum > 0) {
619  $sqlBegin .= " CASE ";
620  $sqlWhere = "WHERE `id_object` IN (";
621  for ($i = 0; $i < $iNum; $i++) {
622  $iElem = (int)$aSort[$i];
623  $sqlBegin .= " WHEN `id_object`='$iElem' THEN '$i'";
624  $sqlWhere .= "$iElem, ";
625  }
626  $sqlQuery = $sqlBegin . " END " . trim($sqlWhere, ', ') . ") AND $sqlAlbumPart";
627  } else {
628  $sqlQuery = $sqlBegin . " `id_object` WHERE $sqlAlbumPart";
629  }
630  $GLOBALS['MySQL']->query($sqlQuery);
631  }
632 
633  function updateLastObj($iAlbumId, $iObjId = 0)
634  {
635  $iAlbumId = (int)$iAlbumId;
636  $iObjId = (int)$iObjId;
637  if ($iObjId == 0) {
638  $sqlQuery = "SELECT MAX(`id_object`) FROM `{$this->sAlbumObjectsTable}` WHERE `id_album` = '{$iAlbumId}'";
639  $iObjId = (int)db_value($sqlQuery);
640  }
641  $sqlQuery = "UPDATE `{$this->sAlbumTable}` SET `LastObjId`='$iObjId' WHERE `ID`='{$iAlbumId}'";
642 
643  return $GLOBALS['MySQL']->query($sqlQuery);
644  }
645 
646  function updateLastObjById($iObjId)
647  {
648  $iObjId = (int)$iObjId;
649  $sqlQuery = "UPDATE `{$this->sAlbumTable}`, `{$this->sAlbumObjectsTable}`
650  SET `LastObjId` = $iObjId
651  WHERE `{$this->sAlbumTable}`.`ID`=`{$this->sAlbumObjectsTable}`.`id_album`
652  AND `{$this->sAlbumObjectsTable}`.`id_object`=$iObjId
653  AND `{$this->sAlbumTable}`.`Type`='{$this->sType}'";
654 
655  return $GLOBALS['MySQL']->query($sqlQuery);
656  }
657 
658  function getLastObj($iAlbumId)
659  {
660  $iAlbumId = (int)$iAlbumId;
661  $sqlQuery = "SELECT `LastObjId` FROM `{$this->sAlbumTable}` WHERE `ID`='{$iAlbumId}' AND `Type`='{$this->sType}'";
662 
663  return $GLOBALS['MySQL']->getOne($sqlQuery);
664  }
665 
666  // calculate closest object in album for current element
667  function getClosestObj($iAlbumId, $iObjectId, $sType = 'next', $iOrder = 0, $aExcludeIds = array())
668  {
669  $iAlbumId = (int)$iAlbumId;
670  $iObjectId = (int)$iObjectId;
671  $iOrder = (int)$iOrder;
672  $sType = strip_tags($sType);
673  $bOrder = true;
674  if ($iOrder == 0) {
675  $sqlCheck = "SELECT COUNT(*) FROM `$this->sAlbumObjectsTable` WHERE `id_album`=$iAlbumId AND `obj_order`>0";
676  $iCheck = (int)db_value($sqlCheck);
677  $bOrder = $iCheck > 0 ? true : false;
678  }
679 
680  if ($iOrder == 0 && !$bOrder) {
681  $sqlField = "id_object";
682  $sqlValue = $iObjectId;
683  $sKey = 'prev';
684  } else {
685  $sqlField = "obj_order";
686  $sqlValue = $iOrder;
687  $sKey = 'next';
688  }
689 
690  if ($sType == $sKey) {
691  $sSign = ">";
692  $sqlType = "ASC";
693  } else {
694  $sSign = "<";
695  $sqlType = "DESC";
696  }
697 
698  $sqlIds = "";
699  if (is_array($aExcludeIds) && !empty($aExcludeIds)) {
700  $sqlIds = "AND `id_object` NOT IN ('" . implode("','", $aExcludeIds) . "')";
701  }
702 
703  $sqlQuery = "SELECT `id_object` FROM `$this->sAlbumObjectsTable`
704  WHERE `id_album`=$iAlbumId AND `$sqlField`$sSign $sqlValue $sqlIds
705  ORDER BY `$sqlField` $sqlType LIMIT 1";
706 
707  return (int)db_value($sqlQuery);
708  }
709 
710  function getObjCount($aIdent)
711  {
712  $aInfo = $this->getAlbumInfo($aIdent, array('ObjCount'));
713 
714  return $aInfo['ObjCount'];
715  }
716 
717  function getObjTotalCount($aData = array())
718  {
719  $aFields = array(
720  'Type' => $this->sType,
721  'Status' => !isset($aData['status']) ? 'active' : $aData['status'],
722  );
723  if (isset($aData['owner'])) {
724  if ((int)$aData['owner'] == 0) {
725  $iUserId = getID($aData['owner']);
726  $aFields['Owner'] = $iUserId > 0 ? $iUserId : '';
727  } else {
728  $aFields['Owner'] = (int)$aData['owner'];
729  }
730  }
731  $sqlQuery = "SELECT SUM(`ObjCount`) FROM `{$this->sAlbumTable}` WHERE " . $this->_getSqlPart($aFields, ' AND ');
732 
733  return (int)$GLOBALS['MySQL']->getOne($sqlQuery);
734  }
735 
736  function calcObjCount($iAlbumId)
737  {
738  $iAlbumId = (int)$iAlbumId;
739  $sqlQuery = "SELECT COUNT(*) FROM `{$this->sAlbumObjectsTable}` WHERE `id_album`='$iAlbumId'";
740 
741  return $GLOBALS['MySQL']->getOne($sqlQuery);
742  }
743 
744  function updateObjCounter($iAlbumId, $iNumber, $bIncrease = true)
745  {
746  $iAlbumId = (int)$iAlbumId;
747  $iNumber = (int)$iNumber;
748  $sOperator = $bIncrease ? '+' : '-';
749  $sqlQuery = "UPDATE `{$this->sAlbumTable}` SET `ObjCount`=`ObjCount` $sOperator $iNumber WHERE `ID`='{$iAlbumId}'";
750  $GLOBALS['MySQL']->res($sqlQuery);
751  }
752 
753  function updateObjCounterById($iObjId, $bIncrease = true)
754  {
755  $iObjId = (int)$iObjId;
756  $sOperator = $bIncrease ? '+' : '-';
757  $sqlQuery = "UPDATE `{$this->sAlbumTable}`, `{$this->sAlbumObjectsTable}`
758  SET `ObjCount` = `ObjCount` $sOperator 1
759  WHERE `{$this->sAlbumTable}`.`ID`=`{$this->sAlbumObjectsTable}`.`id_album`
760  AND `{$this->sAlbumObjectsTable}`.`id_object`=$iObjId
761  AND `{$this->sAlbumTable}`.`Type`='{$this->sType}'";
762  $GLOBALS['MySQL']->res($sqlQuery);
763  }
764 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
ChWsbAlbums\getObjCount
getObjCount($aIdent)
Definition: ChWsbAlbums.php:710
ChWsbAlbums\getAlbumCoverFiles
getAlbumCoverFiles($iAlbumId, $aJoin=array(), $aJoinCond=array(), $iLimit=4)
Definition: ChWsbAlbums.php:294
true
if(!defined("TRUE_VAL")) define("TRUE_VAL" true
Definition: constants.inc.php:8
ChWsbAlbums\_checkAlbumExistence
_checkAlbumExistence($aData)
Definition: ChWsbAlbums.php:267
get_mb_substr
get_mb_substr($s, $iStart, $iLen)
Definition: utils.inc.php:964
ChWsbAlbums\$sAlbumCoverParam
$sAlbumCoverParam
Definition: ChWsbAlbums.php:14
ChWsbAlbums\addObject
addObject($iAlbumId, $mixedObj, $bUpdateCount=true)
Definition: ChWsbAlbums.php:475
ChWsbAlbums\getAlbumInfo
getAlbumInfo($aIdent=array(), $aFields=array())
Definition: ChWsbAlbums.php:425
ChWsbAlbums\addAlbum
addAlbum($aData=array(), $bCheck=true)
Definition: ChWsbAlbums.php:112
ChWsbAlbums\getAlbumObjList
getAlbumObjList($mixedAlbum)
Definition: ChWsbAlbums.php:280
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$oAlert
$oAlert
Definition: embed.php:15
ChWsbPrivacyQuery
Definition: ChWsbPrivacyQuery.php:11
ChWsbAlbums\calcObjCount
calcObjCount($iAlbumId)
Definition: ChWsbAlbums.php:736
php
ChWsbAlbums\updateObjCounter
updateObjCounter($iAlbumId, $iNumber, $bIncrease=true)
Definition: ChWsbAlbums.php:744
CH_WSB_PG_HIDDEN
const CH_WSB_PG_HIDDEN
Definition: ChWsbPrivacy.php:17
$iId
$iId
Definition: license.php:15
ChWsbAlbums\getObjTotalCount
getObjTotalCount($aData=array())
Definition: ChWsbAlbums.php:717
ChWsbAlbums\getAbumName
static getAbumName($sName, $iUserId)
Definition: ChWsbAlbums.php:40
ChWsbAlbums\$aAlbumFields
$aAlbumFields
Definition: ChWsbAlbums.php:12
$iPerPage
else $iPerPage
Definition: browse.php:61
ChWsbAlbums\getClosestObj
getClosestObj($iAlbumId, $iObjectId, $sType='next', $iOrder=0, $aExcludeIds=array())
Definition: ChWsbAlbums.php:667
ChWsbAlbums\_getSqlPart
_getSqlPart($aFields=array(), $sBound=', ', $bUseEmptyValues=false)
Definition: ChWsbAlbums.php:56
CH_TAGS_STRIP_AND_NL2BR
const CH_TAGS_STRIP_AND_NL2BR
Definition: utils.inc.php:25
$aInfo
$aInfo
Definition: constants.inc.php:21
ChWsbAlbums\getAlbumList
getAlbumList($aData=array(), $iPage=1, $iPerPage=10, $bSimple=false)
Definition: ChWsbAlbums.php:316
ChWsbAlbums\getCorrectUri
getCorrectUri($sCaption, $iOwnerId=0, $bCheck=true)
Definition: ChWsbAlbums.php:165
ChWsbAlerts
Definition: ChWsbAlerts.php:39
ChWsbAlbums\removeAlbum
removeAlbum($iAlbumId)
Definition: ChWsbAlbums.php:242
$aFields
$aFields
Definition: preValues.php:19
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
ChWsbAlbums\updateLastObjById
updateLastObjById($iObjId)
Definition: ChWsbAlbums.php:646
CH_WSB_PG_NOBODY
const CH_WSB_PG_NOBODY
Definition: ChWsbPrivacy.php:11
ChWsbAlbums\$iOwnerId
$iOwnerId
Definition: ChWsbAlbums.php:15
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
ChWsbAlbums
Definition: ChWsbAlbums.php:9
ChWsbAlbums\updateLastObj
updateLastObj($iAlbumId, $iObjId=0)
Definition: ChWsbAlbums.php:633
ChWsbAlbums\$sAlbumTable
$sAlbumTable
Definition: ChWsbAlbums.php:10
ChWsbAlbums\getLastObj
getLastObj($iAlbumId)
Definition: ChWsbAlbums.php:658
uriFilter
uriFilter($s)
Definition: utils.inc.php:931
getUsername
getUsername( $ID='')
Definition: profiles.inc.php:443
ChWsbAlbums\getAlbumName
getAlbumName($iAlbumId)
Definition: ChWsbAlbums.php:462
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChWsbAlbums\updateAlbum
updateAlbum($mixedIdent, $aData)
Definition: ChWsbAlbums.php:202
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
CH_WSB_PG_ALL
const CH_WSB_PG_ALL
Definition: ChWsbPrivacy.php:12
CH_TAGS_STRIP
const CH_TAGS_STRIP
Definition: utils.inc.php:22
ChWsbAlbums\$sType
$sType
Definition: ChWsbAlbums.php:13
ChWsbAlbums\sortObjects
sortObjects($sAlbumUri, $aSort=array())
Definition: ChWsbAlbums.php:612
ChWsbAlbums\$sAlbumObjectsTable
$sAlbumObjectsTable
Definition: ChWsbAlbums.php:11
ChWsbAlbums\updateObjCounterById
updateObjCounterById($iObjId, $bIncrease=true)
Definition: ChWsbAlbums.php:753
ChWsbAlbums\moveObject
moveObject($iAlbumId, $iNewAlbumId, $mixedObj)
Definition: ChWsbAlbums.php:511
$iPage
$iPage
Definition: browse.php:50
db_value
db_value($query, $bindings=[], $error_checking=true, $index=0)
Definition: db.inc.php:98
getID
getID( $str, $with_email=1)
Definition: admin.inc.php:139
ChWsbAlbums\removeObject
removeObject($iAlbumId, $mixedObj, $bUpdateCount=true)
Definition: ChWsbAlbums.php:555
ChWsbAlbums\removeObjectTotal
removeObjectTotal($iObj, $bUpdateCounter=true)
Definition: ChWsbAlbums.php:594
ChWsbAlbums\_getSqlSpec
_getSqlSpec($aData)
Definition: ChWsbAlbums.php:79
$sCaption
$sCaption
Definition: tellfriend.php:39
get_mb_len
get_mb_len($s)
Definition: utils.inc.php:959
ChWsbAlbums\updateAlbumById
updateAlbumById($iId, $aData)
Definition: ChWsbAlbums.php:211
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbAlbums\checkUriUniq
checkUriUniq($sUri, $iOwnerId)
Definition: ChWsbAlbums.php:193
$sName
$sName
Definition: ChWsbAdminTools.php:853
ChWsbAlbums\_updateAlbum
_updateAlbum($aAlbum, $aData)
Definition: ChWsbAlbums.php:220
ChWsbAlbums\getAlbumDefaultName
getAlbumDefaultName()
Definition: ChWsbAlbums.php:469
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
ChWsbAlbums\__construct
__construct($sType, $iOwnerId=0)
Definition: ChWsbAlbums.php:17
ChWsbAlbums\getAbumUri
static getAbumUri($sName, $iUserId)
Definition: ChWsbAlbums.php:50
ChWsbAlbums\getAlbumCount
getAlbumCount($aData=array())
Definition: ChWsbAlbums.php:371