misc.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * @name Misc Module
  4. * @author Philipp Maurer
  5. * @author Tobias Reich
  6. * @copyright 2014 by Philipp Maurer, Tobias Reich
  7. */
  8. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  9. function openGraphHeader($photoID) {
  10. global $database;
  11. $photoID = mysqli_real_escape_string($database, $photoID);
  12. $result = $database->query("SELECT title, description, url FROM lychee_photos WHERE id = '$photoID';");
  13. $row = $result->fetch_object();
  14. $parseUrl = parse_url("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  15. $picture = $parseUrl['scheme']."://".$parseUrl['host'].$parseUrl['path']."/../uploads/big/".$row->url;
  16. $return = '<!-- General Meta Data -->';
  17. $return .= '<meta name="title" content="'.$row->title.'" />';
  18. $return .= '<meta name="description" content="'.$row->description.' - via Lychee" />';
  19. $return .= '<link rel="image_src" type="image/jpeg" href="'.$picture.'" />';
  20. $return .= '<!-- Twitter Meta Data -->';
  21. $return .= '<meta name="twitter:card" content="photo">';
  22. $return .= '<meta name="twitter:title" content="'.$row->title.'">';
  23. $return .= '<meta name="twitter:image:src" content="'.$picture.'">';
  24. $return .= '<!-- Facebook Meta Data -->';
  25. $return .= '<meta property="og:title" content="'.$row->title.'">';
  26. $return .= '<meta property="og:image" content="'.$picture.'">';
  27. return $return;
  28. }
  29. function search($term) {
  30. global $database, $settings;
  31. $return['albums'] = '';
  32. // Photos
  33. $result = $database->query("SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE title like '%$term%' OR description like '%$term%' OR tags like '%$term%';");
  34. while($row = $result->fetch_array()) {
  35. $return['photos'][$row['id']] = $row;
  36. $return['photos'][$row['id']]['sysdate'] = date('d F Y', strtotime($row['sysdate']));
  37. }
  38. // Albums
  39. $result = $database->query("SELECT id, title, public, sysdate, password FROM lychee_albums WHERE title like '%$term%' OR description like '%$term%';");
  40. $i = 0;
  41. while($row = $result->fetch_object()) {
  42. // Info
  43. $return['albums'][$row->id]['id'] = $row->id;
  44. $return['albums'][$row->id]['title'] = $row->title;
  45. $return['albums'][$row->id]['public'] = $row->public;
  46. $return['albums'][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
  47. $return['albums'][$row->id]['password'] = ($row->password=='' ? false : true);
  48. // Thumbs
  49. $result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '" . $row->id . "' " . $settings['sorting'] . " LIMIT 0, 3;");
  50. $k = 0;
  51. while($row2 = $result2->fetch_object()){
  52. $return['albums'][$row->id]["thumb$k"] = $row2->thumbUrl;
  53. $k++;
  54. }
  55. $i++;
  56. }
  57. return $return;
  58. }
  59. function update($version = '') {
  60. global $database, $configVersion;
  61. // Albums
  62. if(!$database->query("SELECT `public` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `public` TINYINT( 1 ) NOT NULL DEFAULT '0'");
  63. if(!$database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `password` VARCHAR( 100 ) NULL DEFAULT ''");
  64. if(!$database->query("SELECT `description` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `description` VARCHAR( 1000 ) NULL DEFAULT ''");
  65. if($database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` CHANGE `password` `password` VARCHAR( 100 ) NULL DEFAULT ''");
  66. // Photos
  67. if($database->query("SELECT `description` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` CHANGE `description` `description` VARCHAR( 1000 ) NULL DEFAULT ''");
  68. if(!$database->query("SELECT `tags` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` ADD `tags` VARCHAR( 1000 ) NULL DEFAULT ''");
  69. $database->query("UPDATE `lychee_photos` SET url = replace(url, 'uploads/big/', ''), thumbUrl = replace(thumbUrl, 'uploads/thumb/', '')");
  70. // Settings
  71. $result = $database->query("SELECT `key` FROM `lychee_settings` WHERE `key` = 'dropboxKey' LIMIT 1;");
  72. if ($result->num_rows===0) $database->query("INSERT INTO `lychee_settings` (`key`, `value`) VALUES ('dropboxKey', '')");
  73. // Config
  74. if ($version!==''&&$configVersion!==$version) {
  75. $data = file_get_contents('../data/config.php');
  76. $data = preg_replace('/\$configVersion = \'[\w. ]*\';/', "\$configVersion = '$version';", $data);
  77. if (file_put_contents('../data/config.php', $data)===false) return 'Error: Could not save updated config!';
  78. }
  79. return true;
  80. }
  81. ?>