getGraphHeader.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. use Lychee\Modules\Database;
  3. use Lychee\Modules\Photo;
  4. function getGraphHeader($photoID) {
  5. $photo = new Photo($photoID);
  6. if ($photo->getPublic('')===false) return false;
  7. $query = Database::prepare(Database::get(), "SELECT title, description, url, medium FROM ? WHERE id = '?'", array(LYCHEE_TABLE_PHOTOS, $photoID));
  8. $result = Database::get()->query($query);
  9. if ($result===false) {
  10. Log::error(__METHOD__, __LINE__, Database::get()->error);
  11. return false;
  12. }
  13. $row = $result->fetch_object();
  14. if ($row===null) {
  15. Log::error(__METHOD__, __LINE__, 'Could not find photo in database');
  16. return false;
  17. }
  18. if ($row->medium==='1') $dir = 'medium';
  19. else $dir = 'big';
  20. $parseUrl = parse_url('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
  21. $url = $parseUrl['scheme'] . '://' . $parseUrl['host'] . $parseUrl['path'] . '?' . $parseUrl['query'];
  22. $picture = $parseUrl['scheme'] . '://' . $parseUrl['host'] . $parseUrl['path'] . '/../uploads/' . $dir . '/' . $row->url;
  23. $url = htmlentities($url);
  24. $picture = htmlentities($picture);
  25. $row->title = htmlentities($row->title);
  26. $row->description = htmlentities($row->description);
  27. $return = '<!-- General Meta Data -->';
  28. $return .= '<meta name="title" content="' . $row->title . '">';
  29. $return .= '<meta name="description" content="' . $row->description . ' - via Lychee">';
  30. $return .= '<link rel="image_src" type="image/jpeg" href="' . $picture . '">';
  31. $return .= '<!-- Twitter Meta Data -->';
  32. $return .= '<meta name="twitter:card" content="photo">';
  33. $return .= '<meta name="twitter:title" content="' . $row->title . '">';
  34. $return .= '<meta name="twitter:image:src" content="' . $picture . '">';
  35. $return .= '<!-- Facebook Meta Data -->';
  36. $return .= '<meta property="og:title" content="' . $row->title . '">';
  37. $return .= '<meta property="og:description" content="' . $row->description . ' - via Lychee">';
  38. $return .= '<meta property="og:image" content="' . $picture . '">';
  39. $return .= '<meta property="og:url" content="' . $url . '">';
  40. return $return;
  41. }
  42. ?>