misc.php 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. if (!is_numeric($photoID)) return false;
  12. $result = $database->query("SELECT * 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. $result = $database->query("SELECT * FROM lychee_photos WHERE title like '%$term%' OR description like '%$term%';");
  33. while($row = $result->fetch_array()) {
  34. $return['photos'][$row['id']] = $row;
  35. $return['photos'][$row['id']]['sysdate'] = date('d F Y', strtotime($row['sysdate']));
  36. }
  37. $result = $database->query("SELECT * FROM lychee_albums WHERE title like '%$term%';");
  38. $i=0;
  39. while($row = $result->fetch_object()) {
  40. $return["albums"][$row->id]['id'] = $row->id;
  41. $return["albums"][$row->id]['title'] = $row->title;
  42. $return["albums"][$row->id]['public'] = $row->public;
  43. $return["albums"][$row->id]['sysdate'] = date('F Y', strtotime($row->sysdate));
  44. if ($row->password=="") $return["albums"][$row->id]['password'] = false;
  45. else $return["albums"][$row->id]['password'] = true;
  46. $result2 = $database->query("SELECT thumbUrl FROM lychee_photos WHERE album = '" . $row->id . "' " . $settings['sorting'] . " LIMIT 0, 3;");
  47. $k = 0;
  48. while($row2 = $result2->fetch_object()){
  49. $return['albums'][$row->id]["thumb$k"] = $row2->thumbUrl;
  50. $k++;
  51. }
  52. $i++;
  53. }
  54. return $return;
  55. }
  56. function update() {
  57. global $database;
  58. if(!$database->query("SELECT `public` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `public` TINYINT( 1 ) NOT NULL DEFAULT '0'");
  59. if(!$database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `password` VARCHAR( 100 ) NULL DEFAULT ''");
  60. if(!$database->query("SELECT `description` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` ADD `description` VARCHAR( 1000 ) NULL DEFAULT ''");
  61. if($database->query("SELECT `password` FROM `lychee_albums` LIMIT 1;")) $database->query("ALTER TABLE `lychee_albums` CHANGE `password` `password` VARCHAR( 100 ) NULL DEFAULT ''");
  62. if($database->query("SELECT `description` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` CHANGE `description` `description` VARCHAR( 1000 ) NULL DEFAULT ''");
  63. if($database->query("SELECT `shortlink` FROM `lychee_photos` LIMIT 1;")) $database->query("ALTER TABLE `lychee_photos` DROP `shortlink`");
  64. $database->query("UPDATE `lychee_photos` SET url = replace(url, 'uploads/big/', ''), thumbUrl = replace(thumbUrl, 'uploads/thumb/', '')");
  65. $result = $database->query("SELECT `value` FROM `lychee_settings` WHERE `key` = 'importFilename' LIMIT 1;");
  66. if ($result->fetch_object()!==true) $database->query("INSERT INTO `lychee_settings` (`key`, `value`) VALUES ('importFilename', '1')");
  67. return true;
  68. }
  69. ?>