add() public méthode

public add ( $attr )
 function check_return_comments()
 {
     global $rtmedia_query;
     if ($rtmedia_query->action_query->action != 'comment') {
         return;
     }
     if (isset($rtmedia_query->action_query->id) && count($_POST)) {
         /**
          * /media/comments [POST]
          * Post a comment to the album by post id
          */
         $nonce = $_REQUEST['rtmedia_comment_nonce'];
         if (wp_verify_nonce($nonce, 'rtmedia_comment_nonce')) {
             if (empty($_POST['comment_content'])) {
                 return false;
             }
             $comment = new RTMediaComment();
             $attr = $_POST;
             $mediaModel = new RTMediaModel();
             $result = $mediaModel->get(array('id' => $rtmedia_query->action_query->id));
             if (!isset($attr['comment_post_ID'])) {
                 $attr['comment_post_ID'] = $result[0]->media_id;
             }
             $id = $comment->add($attr);
             if ($result[0]->activity_id != null) {
                 global $rtmedia_buddypress_activity;
                 remove_action("bp_activity_comment_posted", array($rtmedia_buddypress_activity, "comment_sync"), 10, 2);
                 if (function_exists('bp_activity_new_comment')) {
                     $comment_activity_id = bp_activity_new_comment(array('content' => $_POST['comment_content'], 'activity_id' => $result[0]->activity_id));
                 }
             }
             if (!empty($comment_activity_id)) {
                 update_comment_meta($id, 'activity_id', $comment_activity_id);
             }
             if (isset($_POST["rtajax"])) {
                 global $wpdb;
                 $comments = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $id), ARRAY_A);
                 echo rmedia_single_comment($comments);
                 exit;
             }
         } else {
             _e('Ooops !!! Invalid access. No nonce was found !!', 'buddypress-media');
         }
     }
 }
 function comment_sync($comment_id, $param)
 {
     $user_id = '';
     $comment_author = '';
     extract($param);
     if (!empty($user_id)) {
         $user_data = get_userdata($user_id);
         $comment_author = $user_data->data->user_login;
     }
     $mediamodel = new RTMediaModel();
     $media = $mediamodel->get(array('activity_id' => $param['activity_id']));
     // if there is only single media in activity
     if (1 == sizeof($media) && isset($media[0]->media_id)) {
         $media_id = $media[0]->media_id;
         $comment = new RTMediaComment();
         $id = $comment->add(array('comment_content' => $param['content'], 'comment_post_ID' => $media_id, 'user_id' => $user_id, 'comment_author' => $comment_author));
         update_comment_meta($id, 'activity_id', $comment_id);
     }
 }
Exemple #3
0
 function check_return_comments()
 {
     global $rtmedia_query;
     if ('comment' !== $rtmedia_query->action_query->action) {
         return;
     }
     if (isset($rtmedia_query->action_query->id) && count($_POST)) {
         // @codingStandardsIgnoreLine
         /**
          * /media/comments [POST]
          * Post a comment to the album by post id
          */
         $nonce = isset($_REQUEST['rtmedia_comment_nonce']) ? wp_unslash($_REQUEST['rtmedia_comment_nonce']) : '';
         $comment_content = isset($_REQUEST['comment_content']) ? sanitize_text_field(wp_unslash($_REQUEST['comment_content'])) : '';
         if (wp_verify_nonce($nonce, 'rtmedia_comment_nonce')) {
             if (empty($comment_content)) {
                 return false;
             }
             $comment = new RTMediaComment();
             $attr = $_POST;
             $media_model = new RTMediaModel();
             $result = $media_model->get(array('id' => $rtmedia_query->action_query->id));
             if (!isset($attr['comment_post_ID'])) {
                 $attr['comment_post_ID'] = $result[0]->media_id;
             }
             $id = $comment->add($attr);
             if (!is_null($result[0]->activity_id)) {
                 global $rtmedia_buddypress_activity;
                 remove_action('bp_activity_comment_posted', array($rtmedia_buddypress_activity, 'comment_sync'), 10, 2);
                 if (function_exists('bp_activity_new_comment')) {
                     $comment_activity_id = bp_activity_new_comment(array('content' => $comment_content, 'activity_id' => $result[0]->activity_id));
                     do_action('rtm_bp_activity_comment_posted', $comment_activity_id, $result[0]);
                 }
             }
             if (!empty($comment_activity_id)) {
                 $rtmedia_activity_comment = rtmedia_activity_comment($comment_activity_id);
                 if ($rtmedia_activity_comment['content']) {
                     update_comment_meta($id, 'activity_comment_content', $rtmedia_activity_comment['content']);
                 }
                 update_comment_meta($id, 'activity_id', $comment_activity_id);
             }
             $_rt_ajax = filter_input(INPUT_POST, 'rtajax', FILTER_SANITIZE_STRING);
             if (!empty($_rt_ajax)) {
                 global $wpdb;
                 $comments = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d limit 100", $id), ARRAY_A);
                 echo rmedia_single_comment($comments);
                 // @codingStandardsIgnoreLine
                 exit;
             }
         } else {
             esc_html_e('Ooops !!! Invalid access. No nonce was found !!', 'buddypress-media');
         }
     }
 }
 function comment_sync($comment_id, $param)
 {
     $default_args = array('user_id' => '', 'comment_author' => '');
     $param = wp_parse_args($param, $default_args);
     $user_id = $param['user_id'];
     $comment_author = $param['comment_author'];
     if (!empty($user_id)) {
         $user_data = get_userdata($user_id);
         $comment_author = $user_data->data->user_login;
     }
     $mediamodel = new RTMediaModel();
     $media = $mediamodel->get(array('activity_id' => $param['activity_id']));
     // if there is only single media in activity
     if (1 === count($media) && isset($media[0]->media_id)) {
         $media_id = $media[0]->media_id;
         $comment = new RTMediaComment();
         $id = $comment->add(array('comment_content' => $param['content'], 'comment_post_ID' => $media_id, 'user_id' => $user_id, 'comment_author' => $comment_author));
         update_comment_meta($id, 'activity_id', $comment_id);
     }
 }