Exemple #1
0
function bebop_create_buffer_item($params)
{
    global $bp, $wpdb;
    if (is_array($params)) {
        if (!bebop_tables::check_existing_content_id($params['user_id'], $params['extension'], $params['item_id'])) {
            $original_text = $params['content'];
            if (!bebop_tables::bebop_check_existing_content_buffer($params['user_id'], $params['extension'], $original_text)) {
                $content = '';
                if ($params['content_oembed'] == true) {
                    $content = $original_text;
                } else {
                    $content = '<div class="bebop_activity_container ' . $params['extension'] . '">' . $original_text . '</div>';
                }
                $action = '<a href="' . bp_core_get_user_domain($params['user_id']) . '" title="' . bp_core_get_username($params['user_id']) . '">' . bp_core_get_user_displayname($params['user_id']) . '</a>';
                $action .= ' ' . __('posted a', 'bebop');
                $action .= '<a href="' . $params['actionlink'] . '" target="_blank" rel="external"> ' . __($params['type'], 'bebop_' . $params['extension']);
                $action .= '</a>: ';
                $date_imported = gmdate('Y-m-d H:i:s', time());
                //extra check to be sure we don't have an empty activity
                $clean_comment = '';
                $clean_comment = trim(strip_tags($content));
                //controls how user content is verified.
                $should_users_verify_content = bebop_tables::get_option_value('bebop_' . $params['extension'] . '_content_user_verification');
                if ($should_users_verify_content == 'no') {
                    $oer_status = 'verified';
                } else {
                    $oer_status = 'unverified';
                }
                $hide_sitewide = bebop_tables::get_option_value('bebop_' . $params['extension'] . '_hide_sitewide');
                if ($hide_sitewide == 'yes') {
                    $oer_hide_sitewide = 1;
                } else {
                    $oer_hide_sitewide = 0;
                }
                if (!empty($clean_comment)) {
                    if (bebop_filters::day_increase($params['extension'], $params['user_id'], $params['username'])) {
                        if ($wpdb->query($wpdb->prepare('INSERT INTO ' . bp_core_get_table_prefix() . 'bp_bebop_oer_manager ( user_id, status, type, action, content, secondary_item_id, date_imported, date_recorded, hide_sitewide ) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s )', $wpdb->escape($params['user_id']), $oer_status, $wpdb->escape($params['extension']), $wpdb->escape($action), $wpdb->escape($content), $wpdb->escape($params['item_id']), $wpdb->escape($date_imported), $wpdb->escape($params['raw_date']), $wpdb->escape($oer_hide_sitewide)))) {
                            $id = $wpdb->insert_id;
                            //if users shouldn't verify content, add it to the activity stream immediately.
                            if ($should_users_verify_content == 'no') {
                                $new_activity_item = array('user_id' => $params['user_id'], 'component' => 'bebop_oer_plugin', 'type' => $params['extension'], 'action' => $action, 'content' => $content, 'item_id' => $id, 'date_recorded' => $date_imported, 'hide_sitewide' => $oer_hide_sitewide);
                                if (bp_activity_add($new_activity_item)) {
                                    bebop_tables::update_oer_data($id, 'activity_stream_id', $activity_stream_id = $wpdb->insert_id);
                                }
                            }
                            return true;
                        } else {
                            bebop_tables::log_error(__('Importer', 'bebop'), __('Import query error', 'bebop'));
                        }
                    } else {
                        bebop_tables::log_error(__('Importer', 'bebop'), __('Could not import as a daycounter could not be found.', 'bebop'));
                    }
                } else {
                    bebop_tables::log_error(__('Importer', 'bebop'), __('Could not import, content already exists.', 'bebop'));
                }
            }
        }
    }
    return false;
}