You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.9 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. class Images {
  3. function load($data){
  4. $db = new SQLiteDatabase("sql/imgorg.db");
  5. $tags = $data->tags;
  6. $album = $data->album;
  7. $qry = 'select i.filename as filename, i.url as url, i.id as id from Images i';
  8. $where = array();
  9. if ($tags) {
  10. for ($i = 0;$i < sizeof($tags);$i++) {
  11. $qry .= ' INNER JOIN Images_Tags it'.$i.' ON i.id = it'.$i.'.image_id';
  12. array_push($where,' it'.$i.'.tag_id = "'.$tags[$i].'"');
  13. }
  14. }
  15. if ($album) {
  16. $qry .= ' INNER JOIN Albums a ON i.album_id = a.id';
  17. array_push($where, ' a.id ="'.$album.'"');
  18. }
  19. if ($where) {
  20. $qry .= ' WHERE'.join(" AND", $where);
  21. }
  22. $res = $db->query($qry);
  23. return $res->fetchAll();
  24. // return $qry;
  25. }
  26. function upload($data, $files){
  27. $name = $files["Filedata"]["name"];
  28. $db = new SQLiteDatabase("sql/imgorg.db");
  29. $db->queryExec('INSERT INTO Images (filename, url) VALUES("'.$name.'","images/'.$name.'")');
  30. $q = $db->query('SELECT * FROM Images WHERE filename = "'.$name.'"');
  31. move_uploaded_file($files["Filedata"]["tmp_name"],"../images/".$name);
  32. return array(
  33. 'data' => $files["Filedata"],
  34. 'res' => $q->fetchObject()
  35. //,
  36. //'test' => $phm->getImageQuality()
  37. );
  38. }
  39. function addToAlbum($data) {
  40. $images = $data->images;
  41. $album = $data->album;
  42. $db = new SQLiteDatabase("sql/imgorg.db");
  43. for ($i = 0;$i < sizeof($images);$i++) {
  44. // $db->queryExec('INSERT INTO Albums_Images (image_id, album_id) VALUES ("'.$images[$i].'","'.$album.'")');
  45. $db->queryExec('UPDATE Images SET album_id = "'.$album.'" WHERE id ="'.$images[$i].'"');
  46. }
  47. return array('success' => true, 'images' => $images, 'album' => $album);
  48. }
  49. function tagImage($data) {
  50. $images = $data->images;
  51. $tag = $data->tag;
  52. $db = new SQLiteDatabase("sql/imgorg.db");
  53. // if it is a known tag the id is sent, otherwise a new string is, so we need to insert
  54. if (!is_numeric($tag)) {
  55. $db->queryExec('INSERT INTO Tags (text) VALUES ("'.$tag.'")');
  56. $q = $db->query('SELECT id FROM Tags WHERE text = "'.$tag.'"');
  57. $tag = $q->fetchObject()->id;
  58. }
  59. for ($i = 0;$i < sizeof($images);$i++) {
  60. $db->queryExec('INSERT INTO Images_Tags (image_id, tag_id) VALUES ("'.$images[$i].'","'.$tag.'")');
  61. }
  62. return array('success' => true, 'images' => $images, 'tag' => $tag);
  63. }
  64. function rename($data) {
  65. $db = new SQLiteDatabase("sql/imgorg.db");
  66. $image = $data->image;
  67. $name = $data->name;
  68. $url = $data->url;
  69. $urls = split('/',$url);
  70. array_pop($urls);
  71. $newUrl = (join('/',$urls)).'/'.$name;
  72. $db->queryExec('UPDATE Images SET url = "'.$newUrl.'", filename = "'.$name.'" WHERE id = "'.$image.'"');
  73. rename('../'.$url, '../'.$newUrl);
  74. return array('image' => $image, 'name' => $name, 'url' => $newUrl);
  75. }
  76. function remove($data) {
  77. $db = new SQLiteDatabase("sql/imgorg.db");
  78. $images = $data->images;
  79. for ($i = 0;$i < sizeof($images);$i++) {
  80. $res = $db->query('SELECT url FROM Images where id ="'.$images[$i].'"');
  81. $url = $res->fetchObject()->url;
  82. unlink('../'.$url);
  83. $db->queryExec('DELETE FROM Images WHERE id ="'.$images[$i].'"');
  84. $db->queryExec('DELETE FROM Images_Tags WHERE image_id ="'.$images[$i].'"');
  85. }
  86. }
  87. function getInfo($data) {
  88. $db = new SQLiteDatabase("sql/imgorg.db");
  89. $image = $data->image;
  90. $q = $db->query('SELECT url FROM Images WHERE id = "'.$image.'"');
  91. $path = $q->fetchObject()->url;
  92. $ret = exif_read_data('../'.$path);
  93. return $ret;
  94. }
  95. }