misc.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. if (!is_numeric($photoID)) return false;
  13. $result = $database->query("SELECT title, description, url FROM lychee_photos WHERE id = '$photoID';");
  14. $row = $result->fetch_object();
  15. $parseUrl = parse_url("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  16. $picture = $parseUrl['scheme']."://".$parseUrl['host'].$parseUrl['path']."/../uploads/big/".$row->url;
  17. $return = '<!-- General Meta Data -->';
  18. $return .= '<meta name="title" content="'.$row->title.'" />';
  19. $return .= '<meta name="description" content="'.$row->description.' - via Lychee" />';
  20. $return .= '<link rel="image_src" type="image/jpeg" href="'.$picture.'" />';
  21. $return .= '<!-- Twitter Meta Data -->';
  22. $return .= '<meta name="twitter:card" content="photo">';
  23. $return .= '<meta name="twitter:title" content="'.$row->title.'">';
  24. $return .= '<meta name="twitter:image:src" content="'.$picture.'">';
  25. $return .= '<!-- Facebook Meta Data -->';
  26. $return .= '<meta property="og:title" content="'.$row->title.'">';
  27. $return .= '<meta property="og:image" content="'.$picture.'">';
  28. return $return;
  29. }
  30. function search($term) {
  31. global $database, $settings;
  32. $return['albums'] = '';
  33. // Photos
  34. $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%';");
  35. while($row = $result->fetch_array()) {
  36. $return['photos'][$row['id']] = $row;
  37. $return['photos'][$row['id']]['sysdate'] = date('d F Y', strtotime($row['sysdate']));
  38. }
  39. // Albums
  40. $result = $database->query("SELECT id, title, public, sysdate, password FROM lychee_albums WHERE title like '%$term%' OR description like '%$term%';");
  41. $i = 0;
  42. while($row = $result->fetch_object()) {
  43. // Info
  44. $return['albums'][$row->id]['id'] = $row->id;
  45. $return['albums'][$row->id]['title'] = $row->title;
  46. $return['albums'][$row->id]['public'] = $row->public;
  47. $return['albums'][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
  48. $return['albums'][$row->id]['password'] = ($row->password=='' ? false : true);
  49. // Thumbs
  50. $result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '" . $row->id . "' " . $settings['sorting'] . " LIMIT 0, 3;");
  51. $k = 0;
  52. while($row2 = $result2->fetch_object()){
  53. $return['albums'][$row->id]["thumb$k"] = $row2->thumbUrl;
  54. $k++;
  55. }
  56. $i++;
  57. }
  58. return $return;
  59. }
  60. function update() {
  61. global $database;
  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. if($database->query("SELECT `description` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` CHANGE `description` `description` VARCHAR( 1000 ) NULL DEFAULT ''");
  67. if(!$database->query("SELECT `tags` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` ADD `tags` VARCHAR( 1000 ) NULL DEFAULT ''");
  68. $database->query("UPDATE `lychee_photos` SET url = replace(url, 'uploads/big/', ''), thumbUrl = replace(thumbUrl, 'uploads/thumb/', '')");
  69. return true;
  70. }
  71. ?>