Ejemplo n.º 1
0
function bp_group_documents_check_uploads_submit($msg_fmt = true)
{
    //if user is submitting form
    if (isset($_POST['file']) && isset($_POST['group'])) {
        if ('0' == $_POST['group']) {
            _e('You must choose a group for the file.', 'bp-group-documents');
            return false;
        }
        //get rid of extra slashes
        if (get_magic_quotes_gpc()) {
            $_POST = array_map('stripslashes_deep', $_POST);
        }
        //create and populate a shiney new object
        $document = new BP_Group_Documents();
        $document->user_id = get_current_user_id();
        $document->group_id = $_POST['group'];
        $document->file = apply_filters('bp_group_documents_filename_in', $_POST['file']);
        if ($_POST['name']) {
            $document->name = $_POST['name'];
        } else {
            $document->name = $_POST['file'];
        }
        $document->description = apply_filters('bp_group_documents_description_in', $_POST['description']);
        $current_path = WP_PLUGIN_DIR . '/buddypress-group-documents/uploads/' . $_POST['file'];
        if (rename($current_path, $document->get_path(0, 1))) {
            if ($document->save(false)) {
                //passing false tells it not to look for uplaods
                _e('Document moved successfully.', 'bp-group-documents');
                do_action('bp_group_documents_admin_upload_success', $document);
            } else {
                _e('There was a problem saving the file info.', 'bp-group-documents');
            }
        } else {
            _e('There was a problem moving the file.', 'bp-group-documents');
        }
    }
}
Ejemplo n.º 2
0
/** bp_group_documents_check_legacy_paths()
 *
 * checks if there are any documents in the old location (documents folder in plugin)
 * and if so, moves them to the new location (wp-content/blogs.dir)
 *
 * This will only fire when the admin page is viewed to save on overhead
 * @version 2, 3/9/2013 fix BP_GROUP_DOCUMENTS_DIR
 * @deprecated since version 1.2.2
 */
function bp_group_documents_check_legacy_paths()
{
    if (defined('BP_GROUP_DOCUMENTS_PATH')) {
        $legacy_path = BP_GROUP_DOCUMENTS_PATH;
    } else {
        $legacy_path = WP_PLUGIN_DIR . '/' . BP_GROUP_DOCUMENTS_DIR . '/documents/';
    }
    if ($dh = @opendir($legacy_path)) {
        $moved_count = 0;
        while (false !== ($file = readdir($dh))) {
            if ($file != "." && $file != "..") {
                $document = new BP_Group_Documents();
                if ($document->populate_by_file($file)) {
                    rename($legacy_path . $file, $document->get_path(0, 1));
                    ++$moved_count;
                }
            }
        }
    }
}
Ejemplo n.º 3
0
/**
 * Defines if the user can download the document
 * @
 * @return type
 * @since 0.5
 * @version 1.9.2, 9/3/2015, fix for download count
 * v1.9.1, 16/1/2015, add bp_group_documents_download_access filter
 */
function cac_catch_group_doc_request()
{
    $error = false;
    if (empty($_GET['get_group_doc'])) {
        return;
    }
    $doc_id = $_GET['get_group_doc'];
    // Check to see whether the current user has access to the doc in question
    $file_deets = explode('/', $doc_id);
    $group_id = $file_deets[0];
    $group = new BP_Groups_Group($group_id);
    $doc_name = $file_deets[1];
    if (empty($group->id)) {
        $error = array('message' => __('That group does not exist.', 'bp-group-documents'), 'redirect' => bp_get_root_domain());
    } else {
        if ($group->status != 'public') {
            // If the group is not public,
            if (!is_super_admin()) {
                //then the user must be logged in and
                // a member of the group to download the document
                if (!is_user_logged_in() || !groups_is_user_member(bp_loggedin_user_id(), $group_id)) {
                    $error = array('message' => sprintf(__('You must be a logged-in member of the group %s to access this document. If you are a member of the group, please log into the site and try again.', 'bp-group-documents'), $group->name), 'redirect' => bp_get_group_permalink($group));
                }
            }
        }
        /**
         * Filter the error.
         *
         * @since 1.9.1
         *
         * @param array $error A compacted array of $error arguments, including the "message" and
         *                    "redirect" values.
         */
        $error = apply_filters('bp_group_documents_download_access', $error);
        //
        // If we have gotten this far without an error, then the download can go through
        if (!$error) {
            $document = new BP_Group_Documents();
            $document->populate_by_file($doc_name);
            $doc_path = $document->get_path();
            clearstatcache();
            if (file_exists($doc_path)) {
                $document->increment_download_count();
                $mime_type = mime_content_type($doc_path);
                $doc_size = filesize($doc_path);
                header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0");
                header("Pragma: hack");
                header("Content-Type: {$mime_type}; name='" . $file_deets[1] . "'");
                header("Content-Length: " . $doc_size);
                header('Content-Disposition: inline; filename="' . $file_deets[1] . '"');
                header("Content-Transfer-Encoding: binary");
                ob_clean();
                flush();
                readfile($doc_path);
                die;
            } else {
                // File does not exist
                $error = array('message' => _e('The file could not be found.', 'bp-group-documents'), 'redirect' => bp_get_group_permalink($group) . 'documents');
            }
        }
    }
    // If we have gotten this far, there was an error. Add a message and redirect
    bp_core_add_message($error['message'], 'error');
    bp_core_redirect($error['redirect']);
}
/**
 * Moves the documents to a place recognized by Group Documents plugin
 * and saves them.
 */
function bpfb_documents_move($docs)
{
    if (!$docs) {
        return false;
    }
    if (!is_array($docs)) {
        $docs = array($docs);
    }
    if (!(int) @$_POST['group_id']) {
        return false;
    }
    $group = new BP_Groups_Group((int) @$_POST['group_id']);
    if (!bpfb_documents_allowed($group)) {
        return false;
    }
    global $bp;
    $ret = array();
    // Construct the needed data
    $user = wp_get_current_user();
    $data = array('user_id' => $user->ID, 'group_id' => (int) @$_POST['group_id'], 'created_ts' => time(), 'modified_ts' => time(), 'file' => '', 'name' => '', 'description' => @$_POST['content']);
    foreach ($docs as $doc) {
        $doc_obj = new BP_Group_Documents();
        foreach ($data as $key => $val) {
            $doc_obj->{$key} = $val;
        }
        $doc_obj->name = $doc;
        $doc_obj->file = apply_filters('bp_group_documents_filename_in', $doc);
        $tmp_doc = realpath(BPFB_TEMP_IMAGE_DIR . $doc);
        $new_doc = $doc_obj->get_path(0, 1);
        if (@rename($tmp_doc, $new_doc) && $doc_obj->save(false)) {
            $ret[] = $doc_obj;
        }
    }
    return $ret;
}