edit.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. }
  30. //Check booleans and assign default values if not
  31. if ($comments == 'off'){
  32. $comments = 0;
  33. }
  34. else{
  35. $comments = 1;
  36. }
  37. if ($visible == 'off'){
  38. $visible = 0;
  39. }
  40. else{
  41. $visible = 1;
  42. }
  43. if ($admin == 'on'){
  44. $admin = 1;
  45. }
  46. else{
  47. $admin = 0;
  48. }
  49. // If no translations, same text in all languages
  50. if (strlen($text_eu) == 0){
  51. $text_eu = $text_es;
  52. $title_eu = $title_es;
  53. }
  54. if (strlen($text_en) == 0){
  55. $text_en = $text_es;
  56. $title_en = $title_es;
  57. }
  58. //Get database entry
  59. $q = mysqli_query($con, "SELECT * FROM post WHERE id = $id;");
  60. if (mysqli_num_rows($q) == 0)
  61. exit();
  62. $r = mysqli_fetch_array($q);
  63. if ($title_es != $r['title_es']){
  64. mysqli_query($con, "UPDATE post SET title_es = '$title_es' WHERE id = $id;");
  65. }
  66. if ($title_eu != $r['title_eu']){
  67. mysqli_query($con, "UPDATE post SET title_eu = '$title_eu' WHERE id = $id;");
  68. }
  69. if ($title_en != $r['title_en']){
  70. mysqli_query($con, "UPDATE post SET title_en = '$title_en' WHERE id = $id;");
  71. }
  72. if ($text_es != $r['text_es']){
  73. mysqli_query($con, "UPDATE post SET text_es = '$text_es' WHERE id = $id;");
  74. }
  75. if ($text_eu != $r['text_eu']){
  76. mysqli_query($con, "UPDATE post SET text_eu = '$text_eu' WHERE id = $id;");
  77. }
  78. if ($text_en != $r['text_en']){
  79. mysqli_query($con, "UPDATE post SET text_en = '$text_en' WHERE id = $id;");
  80. }
  81. if ($comments != $r['comments']){
  82. mysqli_query($con, "UPDATE post SET comments = $comments WHERE id = $id;");
  83. }
  84. if ($visible != $r['visible']){
  85. mysqli_query($con, "UPDATE post SET visible = $visible WHERE id = $id;");
  86. }
  87. while ($file_idx < 4 && $img_idx < 4){
  88. if ($_POST["delete_image_$file_idx"] == 'yes'){
  89. mysqli_query($con, "DELETE FROM pot_image WHERE post = $id AND idx = $file_idx;");
  90. }
  91. if (file_exists($image[$file_idx]['tmp_name']) > 0){
  92. //Convert to jpg
  93. $im = new imagick($image[$file_idx]['tmp_name']);
  94. $im->setImageFormat('jpg');
  95. $im->writeImage("../../../www/img/blog/$permalink-n$img_idx.jpg");
  96. $im->resizeImage(800, 800, Imagick::FILTER_POINT, false);
  97. $im->writeImage("../../../www/img/blog/view/$permalink-n$img_idx.jpg");
  98. $im->resizeImage(600, 600, Imagick::FILTER_POINT, false);
  99. $im->writeImage("../../../www/img/blog/preview/$permalink-n$img_idx.jpg");
  100. $im->resizeImage(350, 350, Imagick::FILTER_POINT, false);
  101. $im->writeImage("../../../www/img/blog/miniature/$permalink-n$img_idx.jpg");
  102. $im->resizeImage(200, 200, Imagick::FILTER_POINT, false);
  103. $im->writeImage("../../../www/img/blog/thumb/$permalink-n$img_idx.jpg");
  104. $im->clear();
  105. $im->destroy();
  106. //Database
  107. mysqli_query($con, "INSERT INTO post_image (post, image, idx) VALUES ($post_id, '$permalink-n$img_idx.jpg', $img_idx);");
  108. $img_idx ++;
  109. }
  110. $file_idx ++;
  111. }
  112. }
  113. ?>