/** * * @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')); } } } } } }
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')); } } } }