edit.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. $http_host = $_SERVER['HTTP_HOST'];
  3. include("../../functions.php");
  4. $con = startdb('rw');
  5. if (!checkSession($con)){
  6. header("Location: /index.php");
  7. exit (-1);
  8. }
  9. else{
  10. //Get POST data
  11. $id = mysqli_real_escape_string($con, $_POST['id']);
  12. $title_es = mysqli_real_escape_string($con, $_POST['title_es']);
  13. $title_eu = mysqli_real_escape_string($con, $_POST['title_eu']);
  14. $title_en = mysqli_real_escape_string($con, $_POST['title_en']);
  15. $text_es = mysqli_real_escape_string($con, $_POST['text_es']);
  16. $text_eu = mysqli_real_escape_string($con, $_POST['text_eu']);
  17. $text_en = mysqli_real_escape_string($con, $_POST['text_en']);
  18. $image = array();
  19. $image[0] = $_FILES['image_0'];
  20. $image[1] = $_FILES['image_1'];
  21. $image[2] = $_FILES['image_2'];
  22. $image[3] = $_FILES['image_3'];
  23. $comments = mysqli_real_escape_string($con, $_POST['comments']);
  24. $visible = mysqli_real_escape_string($con, $_POST['visible']);
  25. $admin = mysqli_real_escape_string($con, $_POST['admin']);
  26. //Check spanish title
  27. if ($title_es == null)
  28. exit();
  29. //Check titles with no text
  30. if (strlen($title_eu) > 0 && strlen($text_eu) < 1)
  31. exit();
  32. if (strlen($title_en) > 0 && strlen($text_en) < 1)
  33. exit();
  34. //Check text with no titles
  35. if (strlen($text_eu) > 0 && strlen($title_eu) < 1)
  36. exit();
  37. if (strlen($text_en) > 0 && strlen($title_en) < 1)
  38. exit();
  39. //Check booleans and assign default values if not
  40. if ($comments == 'off')
  41. $comments = 0;
  42. else
  43. $comments = 1;
  44. if ($visible == 'off')
  45. $visible = 0;
  46. else
  47. $visible = 1;
  48. if ($admin == 'on')
  49. $admin = 1;
  50. else
  51. $admin = 0;
  52. // If no translations, same text in all languages
  53. if (strlen($text_eu) == 0){
  54. $text_eu = $text_es;
  55. $title_eu = $title_es;
  56. }
  57. if (strlen($text_en) == 0){
  58. $text_en = $text_es;
  59. $title_en = $title_es;
  60. }
  61. //Get database entry
  62. $q = mysqli_query($con, "SELECT * FROM post WHERE id = $id;");
  63. if (mysqli_num_rows($q) == 0)
  64. exit();
  65. $r = mysqli_fetch_array($q);
  66. if ($title_es != $r['title_es']){
  67. mysqli_query($con, "UPDATE post SET title_es = '$title_es' WHERE id = $id;");
  68. }
  69. if ($title_eu != $r['title_eu']){
  70. mysqli_query($con, "UPDATE post SET title_eu = '$title_eu' WHERE id = $id;");
  71. }
  72. if ($title_en != $r['title_en']){
  73. mysqli_query($con, "UPDATE post SET title_en = '$title_en' WHERE id = $id;");
  74. }
  75. if ($text_es != $r['text_es']){
  76. mysqli_query($con, "UPDATE post SET text_es = '$text_es' WHERE id = $id;");
  77. }
  78. if ($text_eu != $r['text_eu']){
  79. mysqli_query($con, "UPDATE post SET text_eu = '$text_eu' WHERE id = $id;");
  80. }
  81. if ($text_en != $r['text_en']){
  82. mysqli_query($con, "UPDATE post SET text_en = '$text_en' WHERE id = $id;");
  83. }
  84. if ($comments != $r['comments']){
  85. mysqli_query($con, "UPDATE post SET comments = $comments WHERE id = $id;");
  86. }
  87. if ($visible != $r['visible']){
  88. mysqli_query($con, "UPDATE post SET visible = $visible WHERE id = $id;");
  89. }
  90. while ($file_idx < 4 && $img_idx < 4){
  91. if ($_POST["delete_image_$file_idx"] == 'yes'){
  92. mysqli_query($con, "DELETE FROM pot_image WHERE post = $id AND idx = $file_idx;");
  93. //TODO: Maybe images should be sorted after this
  94. }
  95. if (file_exists($image[$file_idx]['tmp_name']) > 0){
  96. //Convert to jpg
  97. $im = new imagick($image[$file_idx]['tmp_name']);
  98. $im->setImageFormat('jpg');
  99. $im->writeImage("../../../www/img/blog/$permalink-n$img_idx.jpg");
  100. $im->resizeImage(800, 800, Imagick::FILTER_POINT, false);
  101. $im->writeImage("../../../www/img/blog/view/$permalink-n$img_idx.jpg");
  102. $im->resizeImage(600, 600, Imagick::FILTER_POINT, false);
  103. $im->writeImage("../../../www/img/blog/preview/$permalink-n$img_idx.jpg");
  104. $im->resizeImage(350, 350, Imagick::FILTER_POINT, false);
  105. $im->writeImage("../../../www/img/blog/miniature/$permalink-n$img_idx.jpg");
  106. $im->resizeImage(200, 200, Imagick::FILTER_POINT, false);
  107. $im->writeImage("../../../www/img/blog/thumb/$permalink-n$img_idx.jpg");
  108. $im->clear();
  109. $im->destroy();
  110. //Database
  111. mysqli_query($con, "INSERT INTO post_image (post, image, idx) VALUES ($post_id, '$permalink-n$img_idx.jpg', $img_idx);");
  112. $img_idx ++;
  113. }
  114. $file_idx ++;
  115. }
  116. version();
  117. }
  118. ?>