Album.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <?php
  2. ###
  3. # @name Album Module
  4. # @copyright 2015 by Tobias Reich
  5. ###
  6. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  7. class Album extends Module {
  8. private $database = null;
  9. private $settings = null;
  10. private $albumIDs = null;
  11. public function __construct($database, $plugins, $settings, $albumIDs) {
  12. # Init vars
  13. $this->database = $database;
  14. $this->plugins = $plugins;
  15. $this->settings = $settings;
  16. $this->albumIDs = $albumIDs;
  17. return true;
  18. }
  19. public function add($title = 'Untitled', $public = 0, $visible = 1) {
  20. # Check dependencies
  21. self::dependencies(isset($this->database));
  22. # Call plugins
  23. $this->plugins(__METHOD__, 0, func_get_args());
  24. # Parse
  25. if (strlen($title)>50) $title = substr($title, 0, 50);
  26. # Database
  27. $sysstamp = time();
  28. $query = Database::prepare($this->database, "INSERT INTO ? (title, sysstamp, public, visible) VALUES ('?', '?', '?', '?')", array(LYCHEE_TABLE_ALBUMS, $title, $sysstamp, $public, $visible));
  29. $result = $this->database->query($query);
  30. # Call plugins
  31. $this->plugins(__METHOD__, 1, func_get_args());
  32. if (!$result) {
  33. Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
  34. return false;
  35. }
  36. return $this->database->insert_id;
  37. }
  38. public static function prepareData($data) {
  39. # This function requires the following album-attributes and turns them
  40. # into a front-end friendly format: id, title, public, sysstamp, password
  41. # Note that some attributes remain unchanged
  42. # Check dependencies
  43. self::dependencies(isset($data));
  44. # Init
  45. $album = null;
  46. # Set unchanged attributes
  47. $album['id'] = $data['id'];
  48. $album['title'] = $data['title'];
  49. $album['public'] = $data['public'];
  50. # Parse date
  51. $album['sysdate'] = date('F Y', $data['sysstamp']);
  52. # Parse password
  53. $album['password'] = ($data['password']=='' ? '0' : '1');
  54. # Set placeholder for thumbs
  55. $album['thumbs'] = array();
  56. return $album;
  57. }
  58. public function get() {
  59. # Check dependencies
  60. self::dependencies(isset($this->database, $this->settings, $this->albumIDs));
  61. # Call plugins
  62. $this->plugins(__METHOD__, 0, func_get_args());
  63. # Get album information
  64. switch ($this->albumIDs) {
  65. case 'f': $return['public'] = '0';
  66. $query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE star = 1 " . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS));
  67. break;
  68. case 's': $return['public'] = '0';
  69. $query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE public = 1 " . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS));
  70. break;
  71. case 'r': $return['public'] = '0';
  72. $query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) " . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS));
  73. break;
  74. case '0': $return['public'] = '0';
  75. $query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = 0 " . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS));
  76. break;
  77. default: $query = Database::prepare($this->database, "SELECT * FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
  78. $albums = $this->database->query($query);
  79. $return = $albums->fetch_assoc();
  80. $return['sysdate'] = date('d M. Y', $return['sysstamp']);
  81. $return['password'] = ($return['password']=='' ? '0' : '1');
  82. $query = Database::prepare($this->database, "SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE album = '?' " . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
  83. break;
  84. }
  85. # Get photos
  86. $photos = $this->database->query($query);
  87. $previousPhotoID = '';
  88. while ($photo = $photos->fetch_assoc()) {
  89. # Turn data from the database into a front-end friendly format
  90. $photo = Photo::prepareData($photo);
  91. # Set previous and next photoID for navigation purposes
  92. $photo['previousPhoto'] = $previousPhotoID;
  93. $photo['nextPhoto'] = '';
  94. # Set current photoID as nextPhoto of previous photo
  95. if ($previousPhotoID!=='') $return['content'][$previousPhotoID]['nextPhoto'] = $photo['id'];
  96. $previousPhotoID = $photo['id'];
  97. # Add to return
  98. $return['content'][$photo['id']] = $photo;
  99. }
  100. if ($photos->num_rows===0) {
  101. # Album empty
  102. $return['content'] = false;
  103. } else {
  104. # Enable next and previous for the first and last photo
  105. $lastElement = end($return['content']);
  106. $lastElementId = $lastElement['id'];
  107. $firstElement = reset($return['content']);
  108. $firstElementId = $firstElement['id'];
  109. if ($lastElementId!==$firstElementId) {
  110. $return['content'][$lastElementId]['nextPhoto'] = $firstElementId;
  111. $return['content'][$firstElementId]['previousPhoto'] = $lastElementId;
  112. }
  113. }
  114. $return['id'] = $this->albumIDs;
  115. $return['num'] = $photos->num_rows;
  116. # Call plugins
  117. $this->plugins(__METHOD__, 1, func_get_args());
  118. return $return;
  119. }
  120. public function getAll($public) {
  121. # Check dependencies
  122. self::dependencies(isset($this->database, $this->settings, $public));
  123. # Call plugins
  124. $this->plugins(__METHOD__, 0, func_get_args());
  125. # Initialize return var
  126. $return = array(
  127. 'smartalbums' => null,
  128. 'albums' => null,
  129. 'num' => 0
  130. );
  131. # Get SmartAlbums
  132. if ($public===false) $return['smartalbums'] = $this->getSmartInfo();
  133. # Albums query
  134. $query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ? WHERE public = 1 AND visible <> 0', array(LYCHEE_TABLE_ALBUMS));
  135. if ($public===false) $query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ?', array(LYCHEE_TABLE_ALBUMS));
  136. # Execute query
  137. $albums = $this->database->query($query);
  138. if (!$albums) {
  139. Log::error($database, __METHOD__, __LINE__, 'Could not get all albums (' . $database->error . ')');
  140. exit('Error: ' . $this->database->error);
  141. }
  142. # For each album
  143. while ($album = $albums->fetch_assoc()) {
  144. # Turn data from the database into a front-end friendly format
  145. $album = Album::prepareData($album);
  146. # Thumbs
  147. if (($public===true&&$album['password']==='0')||
  148. ($public===false)) {
  149. # Execute query
  150. $query = Database::prepare($this->database, "SELECT thumbUrl FROM ? WHERE album = '?' ORDER BY star DESC, " . substr($this->settings['sorting'], 9) . " LIMIT 3", array(LYCHEE_TABLE_PHOTOS, $album['id']));
  151. $thumbs = $this->database->query($query);
  152. # For each thumb
  153. $k = 0;
  154. while ($thumb = $thumbs->fetch_object()) {
  155. $album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl;
  156. $k++;
  157. }
  158. }
  159. # Add to return
  160. $return['albums'][$album['id']] = $album;
  161. }
  162. # Num of albums
  163. $return['num'] = $albums->num_rows;
  164. # Call plugins
  165. $this->plugins(__METHOD__, 1, func_get_args());
  166. return $return;
  167. }
  168. private function getSmartInfo() {
  169. # Check dependencies
  170. self::dependencies(isset($this->database, $this->settings));
  171. # Initialize return var
  172. $return = array(
  173. 'unsorted' => null,
  174. 'public' => null,
  175. 'starred' => null,
  176. 'recent' => null
  177. );
  178. ###
  179. # Unsorted
  180. ###
  181. $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE album = 0 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS));
  182. $unsorted = $this->database->query($query);
  183. $i = 0;
  184. $return['unsorted'] = array(
  185. 'thumbs' => array(),
  186. 'num' => $unsorted->num_rows
  187. );
  188. while($row = $unsorted->fetch_object()) {
  189. if ($i<3) {
  190. $return['unsorted']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row->thumbUrl;
  191. $i++;
  192. } else break;
  193. }
  194. ###
  195. # Starred
  196. ###
  197. $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE star = 1 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS));
  198. $starred = $this->database->query($query);
  199. $i = 0;
  200. $return['starred'] = array(
  201. 'thumbs' => array(),
  202. 'num' => $starred->num_rows
  203. );
  204. while($row3 = $starred->fetch_object()) {
  205. if ($i<3) {
  206. $return['starred']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl;
  207. $i++;
  208. } else break;
  209. }
  210. ###
  211. # Public
  212. ###
  213. $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE public = 1 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS));
  214. $public = $this->database->query($query);
  215. $i = 0;
  216. $return['public'] = array(
  217. 'thumbs' => array(),
  218. 'num' => $public->num_rows
  219. );
  220. while($row2 = $public->fetch_object()) {
  221. if ($i<3) {
  222. $return['public']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row2->thumbUrl;
  223. $i++;
  224. } else break;
  225. }
  226. ###
  227. # Recent
  228. ###
  229. $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS));
  230. $recent = $this->database->query($query);
  231. $i = 0;
  232. $return['recent'] = array(
  233. 'thumbs' => array(),
  234. 'num' => $recent->num_rows
  235. );
  236. while($row3 = $recent->fetch_object()) {
  237. if ($i<3) {
  238. $return['recent']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl;
  239. $i++;
  240. } else break;
  241. }
  242. # Return SmartAlbums
  243. return $return;
  244. }
  245. public function getArchive() {
  246. # Check dependencies
  247. self::dependencies(isset($this->database, $this->albumIDs));
  248. # Call plugins
  249. $this->plugins(__METHOD__, 0, func_get_args());
  250. # Illicit chars
  251. $badChars = array_merge(
  252. array_map('chr', range(0,31)),
  253. array("<", ">", ":", '"', "/", "\\", "|", "?", "*")
  254. );
  255. # Photos query
  256. switch($this->albumIDs) {
  257. case 's':
  258. $photos = Database::prepare($this->database, 'SELECT title, url FROM ? WHERE public = 1', array(LYCHEE_TABLE_PHOTOS));
  259. $zipTitle = 'Public';
  260. break;
  261. case 'f':
  262. $photos = Database::prepare($this->database, 'SELECT title, url FROM ? WHERE star = 1', array(LYCHEE_TABLE_PHOTOS));
  263. $zipTitle = 'Starred';
  264. break;
  265. case 'r':
  266. $photos = Database::prepare($this->database, 'SELECT title, url FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) GROUP BY checksum', array(LYCHEE_TABLE_PHOTOS));
  267. $zipTitle = 'Recent';
  268. break;
  269. default:
  270. $photos = Database::prepare($this->database, "SELECT title, url FROM ? WHERE album = '?'", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
  271. $zipTitle = 'Unsorted';
  272. }
  273. # Get title from database when album is not a SmartAlbum
  274. if ($this->albumIDs!=0&&is_numeric($this->albumIDs)) {
  275. $query = Database::prepare($this->database, "SELECT title FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
  276. $album = $this->database->query($query);
  277. # Error in database query
  278. if (!$album) {
  279. Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
  280. return false;
  281. }
  282. # Fetch object
  283. $album = $album->fetch_object();
  284. # Photo not found
  285. if ($album===null) {
  286. Log::error($this->database, __METHOD__, __LINE__, 'Album not found. Cannot start download.');
  287. return false;
  288. }
  289. # Set title
  290. $zipTitle = $album->title;
  291. }
  292. # Escape title
  293. $zipTitle = str_replace($badChars, '', $zipTitle);
  294. $filename = LYCHEE_DATA . $zipTitle . '.zip';
  295. # Create zip
  296. $zip = new ZipArchive();
  297. if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
  298. Log::error($this->database, __METHOD__, __LINE__, 'Could not create ZipArchive');
  299. return false;
  300. }
  301. # Execute query
  302. $photos = $this->database->query($photos);
  303. # Check if album empty
  304. if ($photos->num_rows==0) {
  305. Log::error($this->database, __METHOD__, __LINE__, 'Could not create ZipArchive without images');
  306. return false;
  307. }
  308. # Parse each path
  309. $files = array();
  310. while ($photo = $photos->fetch_object()) {
  311. # Parse url
  312. $photo->url = LYCHEE_UPLOADS_BIG . $photo->url;
  313. # Parse title
  314. $photo->title = str_replace($badChars, '', $photo->title);
  315. if (!isset($photo->title)||$photo->title==='') $photo->title = 'Untitled';
  316. # Check if readable
  317. if (!@is_readable($photo->url)) continue;
  318. # Get extension of image
  319. $extension = getExtension($photo->url);
  320. # Set title for photo
  321. $zipFileName = $zipTitle . '/' . $photo->title . $extension;
  322. # Check for duplicates
  323. if (!empty($files)) {
  324. $i = 1;
  325. while (in_array($zipFileName, $files)) {
  326. # Set new title for photo
  327. $zipFileName = $zipTitle . '/' . $photo->title . '-' . $i . $extension;
  328. $i++;
  329. }
  330. }
  331. # Add to array
  332. $files[] = $zipFileName;
  333. # Add photo to zip
  334. $zip->addFile($photo->url, $zipFileName);
  335. }
  336. # Finish zip
  337. $zip->close();
  338. # Send zip
  339. header("Content-Type: application/zip");
  340. header("Content-Disposition: attachment; filename=\"$zipTitle.zip\"");
  341. header("Content-Length: " . filesize($filename));
  342. readfile($filename);
  343. # Delete zip
  344. unlink($filename);
  345. # Call plugins
  346. $this->plugins(__METHOD__, 1, func_get_args());
  347. return true;
  348. }
  349. public function setTitle($title = 'Untitled') {
  350. # Check dependencies
  351. self::dependencies(isset($this->database, $this->albumIDs));
  352. # Call plugins
  353. $this->plugins(__METHOD__, 0, func_get_args());
  354. # Parse
  355. if (strlen($title)>50) $title = substr($title, 0, 50);
  356. # Execute query
  357. $query = Database::prepare($this->database, "UPDATE ? SET title = '?' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $title, $this->albumIDs));
  358. $result = $this->database->query($query);
  359. # Call plugins
  360. $this->plugins(__METHOD__, 1, func_get_args());
  361. if (!$result) {
  362. Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
  363. return false;
  364. }
  365. return true;
  366. }
  367. public function setDescription($description = '') {
  368. # Check dependencies
  369. self::dependencies(isset($this->database, $this->albumIDs));
  370. # Call plugins
  371. $this->plugins(__METHOD__, 0, func_get_args());
  372. # Parse
  373. $description = htmlentities($description, ENT_COMPAT | ENT_HTML401, 'UTF-8');
  374. if (strlen($description)>1000) $description = substr($description, 0, 1000);
  375. # Execute query
  376. $query = Database::prepare($this->database, "UPDATE ? SET description = '?' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $description, $this->albumIDs));
  377. $result = $this->database->query($query);
  378. # Call plugins
  379. $this->plugins(__METHOD__, 1, func_get_args());
  380. if (!$result) {
  381. Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
  382. return false;
  383. }
  384. return true;
  385. }
  386. public function getPublic() {
  387. # Check dependencies
  388. self::dependencies(isset($this->database, $this->albumIDs));
  389. # Call plugins
  390. $this->plugins(__METHOD__, 0, func_get_args());
  391. if ($this->albumIDs==='0'||$this->albumIDs==='s'||$this->albumIDs==='f') return false;
  392. # Execute query
  393. $query = Database::prepare($this->database, "SELECT public FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
  394. $albums = $this->database->query($query);
  395. $album = $albums->fetch_object();
  396. # Call plugins
  397. $this->plugins(__METHOD__, 1, func_get_args());
  398. if ($album->public==1) return true;
  399. return false;
  400. }
  401. public function getDownloadable() {
  402. # Check dependencies
  403. self::dependencies(isset($this->database, $this->albumIDs));
  404. # Call plugins
  405. $this->plugins(__METHOD__, 0, func_get_args());
  406. if ($this->albumIDs==='0'||$this->albumIDs==='s'||$this->albumIDs==='f'||$this->albumIDs==='r') return false;
  407. # Execute query
  408. $query = Database::prepare($this->database, "SELECT downloadable FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
  409. $albums = $this->database->query($query);
  410. $album = $albums->fetch_object();
  411. # Call plugins
  412. $this->plugins(__METHOD__, 1, func_get_args());
  413. if ($album->downloadable==1) return true;
  414. return false;
  415. }
  416. public function setPublic($public, $password, $visible, $downloadable) {
  417. # Check dependencies
  418. self::dependencies(isset($this->database, $this->albumIDs));
  419. # Call plugins
  420. $this->plugins(__METHOD__, 0, func_get_args());
  421. # Convert values
  422. $public = ($public==='1' ? 1 : 0);
  423. $visible = ($visible==='1' ? 1 : 0);
  424. $downloadable = ($downloadable==='1' ? 1 : 0);
  425. # Set public
  426. $query = Database::prepare($this->database, "UPDATE ? SET public = '?', visible = '?', downloadable = '?', password = NULL WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $public, $visible, $downloadable, $this->albumIDs));
  427. $result = $this->database->query($query);
  428. if (!$result) {
  429. Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
  430. return false;
  431. }
  432. # Reset permissions for photos
  433. if ($public===1) {
  434. $query = Database::prepare($this->database, "UPDATE ? SET public = 0 WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
  435. $result = $this->database->query($query);
  436. if (!$result) {
  437. Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
  438. return false;
  439. }
  440. }
  441. # Call plugins
  442. $this->plugins(__METHOD__, 1, func_get_args());
  443. # Set password
  444. if (isset($password)&&strlen($password)>0) return $this->setPassword($password);
  445. return true;
  446. }
  447. private function setPassword($password) {
  448. # Check dependencies
  449. self::dependencies(isset($this->database, $this->albumIDs));
  450. # Call plugins
  451. $this->plugins(__METHOD__, 0, func_get_args());
  452. if (strlen($password)>0) {
  453. # Get hashed password
  454. $password = getHashedString($password);
  455. # Set hashed password
  456. # Do not prepare $password because it is hashed and save
  457. # Preparing (escaping) the password would destroy the hash
  458. $query = Database::prepare($this->database, "UPDATE ? SET password = '$password' WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
  459. } else {
  460. # Unset password
  461. $query = Database::prepare($this->database, "UPDATE ? SET password = NULL WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
  462. }
  463. # Execute query
  464. $result = $this->database->query($query);
  465. # Call plugins
  466. $this->plugins(__METHOD__, 1, func_get_args());
  467. if (!$result) {
  468. Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
  469. return false;
  470. }
  471. return true;
  472. }
  473. public function checkPassword($password) {
  474. # Check dependencies
  475. self::dependencies(isset($this->database, $this->albumIDs));
  476. # Call plugins
  477. $this->plugins(__METHOD__, 0, func_get_args());
  478. # Execute query
  479. $query = Database::prepare($this->database, "SELECT password FROM ? WHERE id = '?' LIMIT 1", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
  480. $albums = $this->database->query($query);
  481. $album = $albums->fetch_object();
  482. # Call plugins
  483. $this->plugins(__METHOD__, 1, func_get_args());
  484. if ($album->password=='') return true;
  485. else if ($album->password===crypt($password, $album->password)) return true;
  486. return false;
  487. }
  488. public function delete() {
  489. # Check dependencies
  490. self::dependencies(isset($this->database, $this->albumIDs));
  491. # Call plugins
  492. $this->plugins(__METHOD__, 0, func_get_args());
  493. # Init vars
  494. $error = false;
  495. # Execute query
  496. $query = Database::prepare($this->database, "SELECT id FROM ? WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
  497. $photos = $this->database->query($query);
  498. # For each album delete photo
  499. while ($row = $photos->fetch_object()) {
  500. $photo = new Photo($this->database, $this->plugins, null, $row->id);
  501. if (!$photo->delete($row->id)) $error = true;
  502. }
  503. # Delete albums
  504. $query = Database::prepare($this->database, "DELETE FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
  505. $result = $this->database->query($query);
  506. # Call plugins
  507. $this->plugins(__METHOD__, 1, func_get_args());
  508. if ($error) return false;
  509. if (!$result) {
  510. Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
  511. return false;
  512. }
  513. return true;
  514. }
  515. }
  516. ?>