Inheritance: extends RTDBModel
Example #1
0
 function rtm_change_activity_privacy()
 {
     $data = $_POST;
     if (wp_verify_nonce($data['nonce'], 'rtmedia_activity_privacy_nonce')) {
         $rtm_activity_model = new RTMediaActivityModel();
         $is_ac_privacy_exist = $rtm_activity_model->check($data['activity_id']);
         $privacy = intval($data['privacy']);
         $activity_id = intval($data['activity_id']);
         if (!$is_ac_privacy_exist) {
             // Very first privacy entry for this activity
             $status = $rtm_activity_model->insert(array('privacy' => $privacy, 'activity_id' => $activity_id, 'user_id' => get_current_user_id()));
         } else {
             // Just update the existing value
             $status = $rtm_activity_model->update(array('privacy' => $privacy), array('activity_id' => $activity_id));
         }
         // update privacy of corresponding media
         $media_model = new RTMediaModel();
         $activity_media = $media_model->get(array('activity_id' => $activity_id));
         if (!empty($activity_media) && is_array($activity_media)) {
             foreach ($activity_media as $single_media) {
                 $where = array('id' => $single_media->id);
                 $columns = array('privacy' => $privacy);
                 // update media privacy
                 $media_model->update($columns, $where);
             }
         }
         if ($status === false) {
             $status = 'false';
         } else {
             $status = 'true';
         }
         echo $status;
         wp_die();
     }
 }
 function rtmedia_activity_upgrade($lastid = 0, $limit = 1)
 {
     global $wpdb;
     if (wp_verify_nonce($_REQUEST['nonce'], 'rtmedia_media_activity_upgrade_nonce')) {
         $rtmedia_model = new RTMediaModel();
         $rtmedia_activity_model = new RTMediaActivityModel();
         $activity_sql = " SELECT *, max(privacy) as max_privacy FROM {$rtmedia_model->table_name} WHERE activity_id is NOT NULL GROUP BY activity_id ORDER BY id limit " . $limit;
         if (isset($_REQUEST['last_id'])) {
             $lastid = intval($_REQUEST['last_id']);
         }
         if ($lastid) {
             $activity_sql = " SELECT *, max(privacy) as max_privacy FROM {$rtmedia_model->table_name} WHERE activity_id > " . $lastid . ' AND activity_id is NOT NULL GROUP BY activity_id ORDER BY id limit ' . $limit;
         }
         $activity_data = $wpdb->get_results($activity_sql);
         if (is_array($activity_data) && !empty($activity_data)) {
             $rtmedia_activity_model->insert(array('activity_id' => $activity_data[0]->activity_id, 'user_id' => $activity_data[0]->media_author, 'privacy' => $activity_data[0]->max_privacy));
         }
         $this->return_upgrade($activity_data[0]);
     } else {
         echo '0';
         wp_die();
     }
 }
Example #3
0
 function rtm_change_activity_privacy()
 {
     $nonce = filter_input(INPUT_POST, 'nonce', FILTER_SANITIZE_STRING);
     $privacy = filter_input(INPUT_POST, 'privacy', FILTER_SANITIZE_NUMBER_INT);
     $activity_id = filter_input(INPUT_POST, 'activity_id', FILTER_SANITIZE_NUMBER_INT);
     if (wp_verify_nonce($nonce, 'rtmedia_activity_privacy_nonce')) {
         $rtm_activity_model = new RTMediaActivityModel();
         $is_ac_privacy_exist = $rtm_activity_model->check($activity_id);
         $privacy = intval($privacy);
         $activity_id = intval($activity_id);
         if (!$is_ac_privacy_exist) {
             // Very first privacy entry for this activity
             $status = $rtm_activity_model->insert(array('privacy' => $privacy, 'activity_id' => $activity_id, 'user_id' => get_current_user_id()));
         } else {
             // Just update the existing value
             $status = $rtm_activity_model->update(array('privacy' => $privacy), array('activity_id' => $activity_id));
         }
         // update privacy of corresponding media
         $media_model = new RTMediaModel();
         $activity_media = $media_model->get(array('activity_id' => $activity_id));
         if (!empty($activity_media) && is_array($activity_media)) {
             foreach ($activity_media as $single_media) {
                 $where = array('id' => $single_media->id);
                 $columns = array('privacy' => $privacy);
                 // update media privacy
                 $media_model->update($columns, $where);
             }
         }
         if (false === $status) {
             $status = 'false';
         } else {
             $status = 'true';
         }
         echo esc_html($status);
         wp_die();
     }
 }
 function rtmedia_activity_upgrade($lastid = 0, $limit = 1)
 {
     global $wpdb;
     if (check_ajax_referer('rtmedia_media_activity_upgrade_nonce', 'nonce')) {
         $rtmedia_model = new RTMediaModel();
         $rtmedia_activity_model = new RTMediaActivityModel();
         $activity_sql = $wpdb->prepare(" SELECT *, max(privacy) as max_privacy FROM {$rtmedia_model->table_name} WHERE activity_id is NOT NULL GROUP BY activity_id ORDER BY id limit %d", $limit);
         // @codingStandardsIgnoreLine
         $lastid = filter_input(INPUT_POST, 'last_id', FILTER_SANITIZE_NUMBER_INT);
         if (!empty($lastid)) {
             $activity_sql = $wpdb->prepare(" SELECT *, max(privacy) as max_privacy FROM {$rtmedia_model->table_name} WHERE activity_id > %d AND activity_id is NOT NULL GROUP BY activity_id ORDER BY id limit %d", $lastid, $limit);
             // @codingStandardsIgnoreLine
         }
         $activity_data = $wpdb->get_results($activity_sql);
         // @codingStandardsIgnoreLine
         if (is_array($activity_data) && !empty($activity_data)) {
             $rtmedia_activity_model->insert(array('activity_id' => $activity_data[0]->activity_id, 'user_id' => $activity_data[0]->media_author, 'privacy' => $activity_data[0]->max_privacy));
         }
         $this->return_upgrade($activity_data[0]);
     } else {
         echo '0';
         wp_die();
     }
 }
 /**
  * Update `bp_latest_update` user meta with lasted public update.
  *
  * @param $content
  * @param $user_id
  * @param $activity_id
  */
 function manage_user_last_activity_update($content, $user_id, $activity_id)
 {
     global $wpdb, $bp;
     // do not proceed if not allowed
     if (!apply_filters('rtm_manage_user_last_activity_update', true, $activity_id)) {
         return;
     }
     $rtm_activity_model = new RTMediaActivityModel();
     $rtm_activity_obj = $rtm_activity_model->get(array('activity_id' => $activity_id));
     if (!empty($rtm_activity_obj)) {
         if (isset($rtm_activity_obj[0]->privacy) && $rtm_activity_obj[0]->privacy > 0) {
             $get_columns = array('activity_id' => array('compare' => '<', 'value' => $activity_id), 'user_id' => $user_id, 'privacy' => array('compare' => '<=', 'value' => 0));
             // get user's latest public activity update
             $new_last_activity_obj = $rtm_activity_model->get($get_columns, 0, 1);
             if (!empty($new_last_activity_obj)) {
                 // latest public activity id
                 $public_activity_id = $new_last_activity_obj[0]->activity_id;
                 // latest public activity content
                 $activity_content = bp_activity_get_meta($public_activity_id, 'bp_activity_text');
                 if (empty($activity_content)) {
                     $activity_content = $wpdb->get_var("SELECT content FROM {$bp->activity->table_name} WHERE id = {$public_activity_id}");
                 }
                 $activity_content = apply_filters('bp_activity_latest_update_content', $activity_content, $activity_content);
                 // update user's latest update
                 bp_update_user_meta($user_id, 'bp_latest_update', array('id' => $public_activity_id, 'content' => $activity_content));
             }
         }
     }
 }
 function bp_activity_posted_update($content, $user_id, $activity_id)
 {
     global $wpdb, $bp;
     $updated_content = '';
     // hook for rtmedia buddypress before activity posted
     do_action('rtmedia_bp_before_activity_posted', $content, $user_id, $activity_id);
     if (isset($_POST['rtMedia_attached_files']) && is_array($_POST['rtMedia_attached_files'])) {
         $updated_content = $wpdb->get_var("select content from  {$bp->activity->table_name} where  id= {$activity_id}");
         $objActivity = new RTMediaActivity($_POST['rtMedia_attached_files'], 0, $updated_content);
         $html_content = $objActivity->create_activity_html();
         bp_activity_update_meta($activity_id, 'bp_old_activity_content', $html_content);
         bp_activity_update_meta($activity_id, 'bp_activity_text', $updated_content);
         $wpdb->update($bp->activity->table_name, array('type' => 'rtmedia_update', 'content' => $html_content), array('id' => $activity_id));
         $mediaObj = new RTMediaModel();
         $sql = "update {$mediaObj->table_name} set activity_id = '" . $activity_id . "' where blog_id = '" . get_current_blog_id() . "' and id in (" . implode(',', $_POST['rtMedia_attached_files']) . ')';
         $wpdb->query($sql);
     }
     // hook for rtmedia buddypress after activity posted
     do_action('rtmedia_bp_activity_posted', $updated_content, $user_id, $activity_id);
     if (isset($_POST['rtmedia-privacy'])) {
         $privacy = -1;
         if (is_rtmedia_privacy_enable()) {
             if (is_rtmedia_privacy_user_overide()) {
                 $privacy = $_POST['rtmedia-privacy'];
             } else {
                 $privacy = get_rtmedia_default_privacy();
             }
         }
         bp_activity_update_meta($activity_id, 'rtmedia_privacy', $privacy);
         // insert/update activity details in rtmedia activity table
         $rtmedia_activity_model = new RTMediaActivityModel();
         if (!$rtmedia_activity_model->check($activity_id)) {
             $rtmedia_activity_model->insert(array('activity_id' => $activity_id, 'user_id' => $user_id, 'privacy' => $privacy));
         } else {
             $rtmedia_activity_model->update(array('activity_id' => $activity_id, 'user_id' => $user_id, 'privacy' => $privacy), array('activity_id' => $activity_id));
         }
     }
 }
Example #7
0
 function insert_activity($id, $media)
 {
     if (!$this->activity_enabled()) {
         return false;
     }
     $activity = new RTMediaActivity($media->id, $media->privacy);
     $activity_content = $activity->create_activity_html();
     $user = get_userdata($media->media_author);
     $username = '******' . get_rtmedia_user_link($media->media_author) . '">' . $user->user_nicename . '</a>';
     $count = count($id);
     $media_const = 'RTMEDIA_' . strtoupper($media->media_type);
     if ($count > 1) {
         $media_const .= '_PLURAL';
     }
     $media_const .= '_LABEL';
     $media_str = constant($media_const);
     $action = sprintf($count == 1 ? __('%1$s added a %2$s', 'rtmedia') : __('%1$s added %4$d %3$s', 'rtmedia'), $username, $media->media_type, $media_str, $count);
     $action = apply_filters('rtmedia_buddypress_action_text_fitler', $action, $username, $count, $user->user_nicename, $media->media_type);
     $activity_args = array('user_id' => $user->ID, 'action' => $action, 'content' => $activity_content, 'type' => 'rtmedia_update', 'primary_link' => '', 'item_id' => $id);
     if ($media->context == "group" && function_exists("bp_get_group_status") && bp_get_group_status(groups_get_group(array("group_id" => $media->context_id))) != "public") {
         $activity_args["hide_sitewide"] = true;
     }
     if ($media->context == 'group' || 'profile') {
         $activity_args['component'] = $media->context;
         if ($media->context == 'group') {
             $activity_args['component'] = "groups";
             $activity_args['item_id'] = $media->context_id;
         }
     }
     $activity_id = bp_activity_add($activity_args);
     bp_activity_update_meta($activity_id, 'rtmedia_privacy', $media->privacy == 0 ? -1 : $media->privacy);
     $this->model->update(array('activity_id' => $activity_id), array('id' => $media->id));
     // insert/update activity details in rtmedia activity table
     $rtmedia_activity_model = new RTMediaActivityModel();
     if (!$rtmedia_activity_model->check($activity_id)) {
         $rtmedia_activity_model->insert(array('activity_id' => $activity_id, 'user_id' => $media->media_author, 'privacy' => $media->privacy));
     } else {
         $rtmedia_activity_model->update(array('activity_id' => $activity_id, 'user_id' => $media->media_author, 'privacy' => $media->privacy), array('activity_id' => $activity_id));
     }
     return $activity_id;
 }