/**
  *
  * @global type $bp
  * @version 1.2.2 add security, fix misplayed error messages
  * v1.2.1, 1/8/2013, stergatu, implement  direct call to  add document functionality
  * @since version 0.8
  *
  */
 private function do_url_logic()
 {
     global $bp;
     do_action('bp_group_documents_template_do_url_logic');
     //figure out what to display in the bottom "detail" area based on url
     //assume we are adding a new document
     $document = new BP_Group_Documents();
     if ($document->current_user_can('add')) {
         $this->header = __('Upload a New Document', 'bp-group-documents');
         $this->show_detail = 1;
     }
     //if we're editing, grab existing data
     //
     if ($bp->current_action == BP_GROUP_DOCUMENTS_SLUG) {
         if (count($bp->action_variables) > 0) {
             //stergatu add on 1/8/2013
             //implement direct call to  document file functionality
             if ($bp->action_variables[0] == 'add') {
                 if ($document->current_user_can('add')) {
                     ?>
                                             <script language="javascript">
                         jQuery(document).ready(function($) {
                             $('#bp-group-documents-upload-button').slideUp();
                             $('#bp-group-documents-upload-new').slideDown();
                             $('html, body').animate({
                                 scrollTop: $("#bp-group-documents-upload-new").offset().top
                             }, 2000);
                         });
                     </script>
                     <?php 
                 } else {
                     bp_core_add_message(__("You don't have permission to upload files", 'bp-group-documents'), 'error');
                 }
             }
             if (count($bp->action_variables) > 1) {
                 if ($bp->action_variables[0] == 'edit') {
                     if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'group-documents-edit-link')) {
                         bp_core_add_message(__('There was a security problem', 'bp-group-documents'), 'error');
                         return false;
                     }
                     if (!ctype_digit($bp->action_variables[1])) {
                         bp_core_add_message(__('The item to edit could not be found', 'bp-group-documents'), 'error');
                         return false;
                     }
                     if (ctype_digit($bp->action_variables[1])) {
                         $document = new BP_Group_Documents($bp->action_variables[1]);
                         $this->name = apply_filters('bp_group_documents_name_out', $document->name);
                         $this->description = apply_filters('bp_group_documents_description_out', $document->description);
                         $this->featured = apply_filters('bp_group_documents_featured_out', $document->featured);
                         $this->doc_categories = wp_get_object_terms($document->id, 'group-documents-category');
                         $this->operation = 'edit';
                         $this->id = $bp->action_variables[1];
                         $this->header = __('Edit Document', 'bp-group-documents');
                     }
                     //otherwise, we might be deleting
                 }
                 if ($bp->action_variables[0] == 'delete') {
                     if (!ctype_digit($bp->action_variables[1])) {
                         bp_core_add_message(__('The item to delete could not be found', 'bp-group-documents'), 'error');
                         return false;
                     }
                     if (bp_group_documents_delete($bp->action_variables[1])) {
                         bp_core_add_message(__('Document successfully deleted', 'bp-group-documents'));
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 private function do_url_logic()
 {
     global $bp;
     do_action('bp_group_documents_template_do_url_logic');
     //figure out what to display in the bottom "detail" area based on url
     //assume we are adding a new document
     $document = new BP_Group_Documents();
     if ($document->current_user_can('add')) {
         $this->header = __('Upload a New Document', 'bp-group-documents');
         $this->show_detail = 1;
     }
     //if we're editing, grab existing data
     if ($bp->current_action == $bp->group_documents->slug && (isset($bp->action_variables[0]) && $bp->action_variables[0] == 'edit')) {
         if (ctype_digit($bp->action_variables[1])) {
             $document = new BP_Group_Documents($bp->action_variables[1]);
             $this->name = apply_filters('bp_group_documents_name_out', $document->name);
             $this->description = apply_filters('bp_group_documents_description_out', $document->description);
             $this->featured = apply_filters('bp_group_documents_featured_out', $document->featured);
             $this->doc_categories = wp_get_object_terms($document->id, 'group-documents-category');
             $this->operation = 'edit';
             $this->id = $bp->action_variables[1];
             $this->header = __('Edit Document', 'bp-group-documents');
         }
         //otherwise, we might be deleting
     } else {
         if ($bp->current_action == $bp->group_documents->slug && isset($bp->action_variables[0]) && $bp->action_variables[0] == 'delete') {
             if (bp_group_documents_delete($bp->action_variables[1])) {
                 bp_core_add_message(__('Document successfully deleted', 'bp-group-documents'));
             }
         }
     }
 }
예제 #3
0
function bp_group_documents_delete($id)
{
    if (!ctype_digit($id)) {
        bp_core_add_message(__('The item to delete could not be found', 'bp-group-documents'), 'error');
        return false;
    }
    //check nonce
    if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'group-documents-delete-link')) {
        bp_core_add_message(__('There was a security problem', 'bp-group-documents'), 'error');
        return false;
    }
    $document = new BP_Group_Documents($id);
    if ($document->current_user_can('delete')) {
        if ($document->delete()) {
            do_action('bp_group_documents_delete_success', $document);
            return true;
        }
    }
    return false;
}
예제 #4
0
    /**
     *
     * @param type $args
     * @param array $instance
     * @version 3, 6/4/2015 fix for hidden groups
     * v2, 24/4/2014
     */
    function widget($args, $instance)
    {
        $bp = buddypress();
        $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(), $instance['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) : $instance['title']);
                echo $before_widget . $before_title . esc_html($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 esc_attr($document->id);
                        ?>
" href="<?php 
                        $document->url();
                        ?>
" target="_blank"><?php 
                        echo str_replace("\\", "", esc_html(stripslashes($document->name)));
                        ?>

						    <?php 
                        if (get_option('bp_group_documents_display_file_size')) {
                            echo ' <span class="group-documents-filesize">(' . esc_html(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>';
                }
                if (is_user_logged_in()) {
                    if (BP_Group_Documents::current_user_can('add', $instance['group_id'])) {
                        $url = bp_get_group_permalink($bp->groups->current_group) . BP_GROUP_DOCUMENTS_SLUG . '/add';
                        ?>
										<div class="generic-button group-button public"><a href="<?php 
                        echo esc_url($url);
                        ?>
" class="generic-button"><?php 
                        _e("Add New", 'buddypress');
                        ?>
</a></div>
							<?php 
                    }
                }
                echo '<div class="view-all"><a href="' . esc_url(bp_get_group_permalink($bp->groups->current_group)) . BP_GROUP_DOCUMENTS_SLUG . '#object-nav">' . __("View all", 'bp-group-documents') . '</a></div>';
                echo $after_widget;
            }
        }
    }