Файл: adultscript-2.0.3-pro/files/mobile/templates/default/extend/ajax/photo_comment_delete.plugin.php
Строк: 40
<?php
defined('_VALID') or die('Restricted Access!');
function ajax_plugin_photo_comment_delete()
{
    $data = array('status' => 0, 'code' => '', 'msg' => '', 'debug' => '');
    if (isset($_POST['comment_id'])) {
          $user_id = (VAuth::loggedin()) ? (int) $_SESSION['user_id'] : 0;
          if ($user_id) {
              VLanguage::load('frontend.mobile');
          
              $comment_id = (int) trim($_POST['comment_id']);
              
              $db = VF::factory('database');
              $db->query("SELECT c.photo_id, c.user_id, a.user_id AS owner_id
                          FROM #__photo_comments AS c
                          LEFT JOIN #__photo AS p ON (p.photo_id = c.photo_id AND p.status = '1')
                          LEFT JOIN #__photo_albums AS a ON (a.album_id = p.album_id)
                          WHERE c.comment_id = ".$comment_id."
                          LIMIT 1");
              if ($db->affected_rows()) {
                  $data        = $db->fetch_assoc();
                  $photo_id    = (int) $data['photo_id'];
                  $cuser_id    = (int) $data['user_id'];
                  $owner_id    = (int) $data['owner_id'];
                  
                  if ($user_id == $cuser_id or $user_id = $owner_id) {
                      $db->query("UPDATE #__photo
                                  SET total_comments = total_comments-1
                                  WHERE photo_id = ".$photo_id."
                                  LIMIT 1");
                      $db->query("DELETE FROM #__photo_comments
                                  WHERE comment_id = ".$comment_id."
                                  LIMIT 1");
                      
                      $data['msg']    = __('comment-delete-success');
                      $data['status']    = 1;
                  } else {
                      $data['msg'] = __('comment-delete-access');
                  }
              } else {
                  $data['msg'] = __('comment-missing');
              }
          } else {
              $data['msg'] = __('comment-login-delete');
          }
    } else {
          $data['msg'] = 'Invalid ajax request!?';
    }
    
    return json_encode($data);
}