misc.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 getGraphHeader($database, $photoID) {
  10. if (!isset($database, $photoID)) return false;
  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($database, $settings, $term) {
  30. if (!isset($database, $settings, $term)) return false;
  31. $return['albums'] = '';
  32. // Photos
  33. $result = $database->query("SELECT id, title, tags, public, star, album, thumbUrl FROM lychee_photos WHERE title like '%$term%' OR description like '%$term%' OR tags like '%$term%';");
  34. while($row = $result->fetch_assoc()) {
  35. $return['photos'][$row['id']] = $row;
  36. $return['photos'][$row['id']]['sysdate'] = date('d M. Y', substr($row['id'], 0, -4));
  37. }
  38. // Albums
  39. $result = $database->query("SELECT id, title, public, sysstamp, 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', $row->sysstamp);
  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 get_hashed_password($password) {
  60. # Inspired by http://alias.io/2010/01/store-passwords-safely-with-php-and-mysql/
  61. # A higher $cost is more secure but consumes more processing power
  62. $cost = 10;
  63. # Create a random salt
  64. if (extension_loaded('openssl')) {
  65. $salt = strtr(substr(base64_encode(openssl_random_pseudo_bytes(17)),0,22), '+', '.');
  66. } elseif (extension_loaded('mcrypt')) {
  67. $salt = strtr(substr(base64_encode(mcrypt_create_iv(17, MCRYPT_DEV_URANDOM)),0,22), '+', '.');
  68. } else {
  69. $salt = "";
  70. for ($i = 0; $i < 22; $i++) {
  71. $salt .= substr("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", mt_rand(0, 63), 1);
  72. }
  73. }
  74. # Prefix information about the hash so PHP knows how to verify it later.
  75. # "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter.
  76. $salt = sprintf("$2a$%02d$", $cost) . $salt;
  77. # Hash the password with the salt
  78. return crypt($password, $salt);
  79. }
  80. ?>