Пример #1
0
function bp_group_documents_increment_download_count()
{
    $document_id = (string) $_POST['document_id'];
    if (isset($document_id) && ctype_digit($document_id)) {
        $document = new BP_Group_Documents($document_id);
        $document->increment_download_count();
    }
}
function bp_group_documents_forum_attachments_topic_text($topic_text)
{
    global $bp;
    if (!empty($_FILES)) {
        $document = new BP_Group_Documents();
        $document->user_id = get_current_user_id();
        $document->group_id = $bp->groups->current_group->id;
        $document->name = $_POST['bp_group_documents_name'];
        $document->description = $_POST['bp_group_documents_description'];
        if ($document->save()) {
            do_action('bp_group_documents_add_success', $document);
            bp_core_add_message(__('Document successfully uploaded', 'bp-group-documents'));
            return $topic_text . bp_group_documents_forum_attachments_document_link($document);
        }
    }
    return $topic_text;
}
/**
 *
 * @param type $topic_text
 * @return type
 * @version 1.2.2, stergatu 3/10/2013, sanitize_text_field
 * @since
 */
function bp_group_documents_forum_attachments_topic_text($topic_text)
{
    $bp = buddypress();
    if (!empty($_FILES)) {
        $document = new BP_Group_Documents();
        $document->user_id = get_current_user_id();
        $document->group_id = $bp->groups->current_group->id;
        /* Never trust an input box */
        //        $document->name =  $_POST['bp_group_documents_name'];
        //        $document->description = $_POST['bp_group_documents_description'];
        $document->name = sanitize_text_field($_POST['bp_group_documents_name']);
        $document->description = sanitize_text_field($_POST['bp_group_documents_description']);
        if ($document->save()) {
            do_action('bp_group_documents_add_success', $document);
            bp_core_add_message(__('Document successfully uploaded', 'bp-group-documents'));
            return $topic_text . bp_group_documents_forum_attachments_document_link($document);
        }
    }
    return $topic_text;
}
 function __construct()
 {
     global $bp;
     $nav_page_name = get_option('bp_group_documents_nav_page_name');
     $this->name = !empty($nav_page_name) ? $nav_page_name : __('Documents', 'bp-group-documents');
     $this->slug = BP_GROUP_DOCUMENTS_SLUG;
     /* For internal identification */
     $this->id = 'group_documents';
     $this->format_notification_function = 'bp_group_documents_format_notifications';
     if ($bp->groups->current_group) {
         $this->nav_item_name = $this->name . ' <span>' . BP_Group_Documents::get_total($bp->groups->current_group->id) . '</span>';
         $this->nav_item_position = 51;
     }
     $this->admin_name = !empty($nav_page_name) ? $nav_page_name : __('Documents', 'bp-group-documents');
     $this->admin_slug = BP_GROUP_DOCUMENTS_SLUG;
     if ('mods_decide' != get_option('bp_group_documents_upload_permission')) {
         $this->enable_create_step = false;
     } else {
         $this->create_step_position = 21;
     }
 }
 /**
  * @author
  * @since
  */
 private function do_paging_logic()
 {
     global $bp;
     do_action('bp_group_documents_template_do_paging_logic');
     $this->items_per_page = get_option('bp_group_documents_items_per_page');
     $this->total_records = BP_Group_Documents::get_total($bp->groups->current_group->id, $this->category);
     $this->total_pages = ceil($this->total_records / $this->items_per_page);
     if (isset($_GET['page']) && ctype_digit($_GET['page'])) {
         $this->page = $_GET['page'];
         $this->start_record = ($this->page - 1) * $this->items_per_page + 1;
     }
     $last_possible = $this->items_per_page * $this->page;
     $this->end_record = $this->total_records < $last_possible ? $this->total_records : $last_possible;
     $this->action_link = get_bloginfo('url') . '/' . bp_get_groups_root_slug() . '/' . $bp->current_item . '/' . $bp->current_action . '/';
 }
Пример #6
0
    function widget($args, $instance)
    {
        global $bp;
        $instance['group_id'] = bp_get_current_group_id();
        if ($instance['group_id'] > 0) {
            $group = $bp->groups->current_group;
            // If the group  public, or the user is super_admin or the user is member of group
            if ($group->status == 'public' || is_super_admin() || groups_is_user_member(bp_loggedin_user_id(), $group_id)) {
                extract($args);
                $title = apply_filters('widget_title', empty($instance['title']) ? sprintf(__('Recent %s for the group', 'bp-group-documents'), $this->bp_group_documents_name) : sanitize_text_field($instance['title']));
                echo $before_widget . $before_title . $title . $after_title;
                do_action('bp_group_documents_current_group_widget_before_html');
                $document_list = BP_Group_Documents::get_list_for_newest_widget(absint($instance['num_items']), $instance['group_id'], (bool) $instance['featured']);
                if ($document_list && count($document_list) >= 1) {
                    echo '<ul id="bp-group-documents-current-group" class="bp-group-documents-list">';
                    foreach ($document_list as $item) {
                        $document = new BP_Group_Documents($item['id']);
                        echo '<li>';
                        if (get_option('bp_group_documents_display_icons')) {
                            $document->icon();
                        }
                        ?>
                                                <a class="bp-group-documents-title" id="group-document-link-<?php 
                        echo $document->id;
                        ?>
" href="<?php 
                        $document->url();
                        ?>
" target="_blank"><?php 
                        echo esc_html($document->name);
                        ?>

                                                    <?php 
                        if (get_option('bp_group_documents_display_file_size')) {
                            echo ' <span class="group-documents-filesize">(' . get_file_size($document) . ')</span>';
                        }
                        ?>
</a> &nbsp;<div class="bp-group-documents-meta">
                                                    <?php 
                        $document->categories();
                        printf(__('Uploaded by %s on %s', 'bp-group-documents'), bp_core_get_userlink($document->user_id), date_i18n(get_option('date_format'), $document->created_ts));
                        ?>
                                                    <?php 
                        echo '</li>';
                    }
                    echo '</ul>';
                } else {
                    echo '<div class="widget-error">' . sprintf(__('There are no %s to display.', 'bp-group-documents'), $this->bp_group_documents_name) . '</div></p>';
                }
                echo '<div class="view-all"><a href="' . bp_get_group_permalink($bp->groups->current_group) . BP_GROUP_DOCUMENTS_SLUG . '#object-nav">' . __("View all", 'bp-group-documents') . '</a></div>';
                echo $after_widget;
            }
        }
    }
Пример #7
0
/**
 * bp_group_documents_remove_data()
 *
 * Cleans out both the files and the database records when a group is deleted
 */
function bp_group_documents_remove_data($group_id)
{
    $results = BP_Group_Documents::get_list_by_group($group_id);
    if (count($results) >= 1) {
        foreach ($results as $document_params) {
            $document = new BP_Group_Documents($document_params['id'], $document_params);
            $document->delete();
            do_action('bp_group_documents_delete_with_group', $document);
        }
    }
}
Пример #8
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');
        }
    }
}
Пример #9
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']);
}
Пример #10
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;
                }
            }
        }
    }
}
/**
 * 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;
}
Пример #12
0
    function widget($args, $instance)
    {
        global $bp;
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Popular Group Documents', 'bp-group-documents') : $instance['title']);
        echo $before_widget;
        echo $before_title . $title . $after_title;
        ?>

	<?php 
        do_action('bp_group_documents_popular_widget_before_html');
        /***
         * Main HTML Display
         */
        $document_list = BP_Group_Documents::get_list_for_popular_widget($instance['num_items'], $instance['group_filter'], $instance['featured']);
        if ($document_list && count($document_list) >= 1) {
            echo '<ul class="group-documents-popular">';
            foreach ($document_list as $item) {
                $document = new BP_Group_Documents($item['id']);
                $group = new BP_Groups_Group($document->group_id);
                echo '<li>';
                if ($instance['group_filter']) {
                    echo '<a href="' . $document->get_url() . '">' . $document->icon() . ' ' . esc_attr($document->name) . '</a>';
                } else {
                    echo sprintf(__('%s posted in %s', 'bp-group-documents'), '<a href="' . $document->get_url() . '">' . esc_attr($document->name) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>');
                }
                echo '</li>';
            }
            echo '</ul>';
        } else {
            echo '<div class="widget-error">' . __('There are no documents to display.', 'bp-group-documents') . '</div></p>';
        }
        ?>

	<?php 
        echo $after_widget;
        ?>
	<?php 
    }