getGraphHeader.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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::execute(Database::get(), $query, __METHOD__, __LINE__);
  9. if ($result===false) return false;
  10. $row = $result->fetch_object();
  11. if ($row===null) {
  12. Log::error(Database::get(), __METHOD__, __LINE__, 'Could not find photo in database');
  13. return false;
  14. }
  15. if ($row->medium==='1') $dir = 'medium';
  16. else $dir = 'big';
  17. $parseUrl = parse_url('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
  18. $url = $parseUrl['scheme'] . '://' . $parseUrl['host'] . $parseUrl['path'] . '?' . $parseUrl['query'];
  19. $picture = $parseUrl['scheme'] . '://' . $parseUrl['host'] . $parseUrl['path'] . '/../uploads/' . $dir . '/' . $row->url;
  20. $url = htmlentities($url);
  21. $picture = htmlentities($picture);
  22. $row->title = htmlentities($row->title);
  23. $row->description = htmlentities($row->description);
  24. $return = '<!-- General Meta Data -->';
  25. $return .= '<meta name="title" content="' . $row->title . '">';
  26. $return .= '<meta name="description" content="' . $row->description . ' - via Lychee">';
  27. $return .= '<link rel="image_src" type="image/jpeg" href="' . $picture . '">';
  28. $return .= '<!-- Twitter Meta Data -->';
  29. $return .= '<meta name="twitter:card" content="photo">';
  30. $return .= '<meta name="twitter:title" content="' . $row->title . '">';
  31. $return .= '<meta name="twitter:image:src" content="' . $picture . '">';
  32. $return .= '<!-- Facebook Meta Data -->';
  33. $return .= '<meta property="og:title" content="' . $row->title . '">';
  34. $return .= '<meta property="og:description" content="' . $row->description . ' - via Lychee">';
  35. $return .= '<meta property="og:image" content="' . $picture . '">';
  36. $return .= '<meta property="og:url" content="' . $url . '">';
  37. return $return;
  38. }
  39. ?>