public function delete_attachments() { if (isset($_GET['d4pbbaction'])) { $nonce = wp_verify_nonce($_GET['_wpnonce'], 'd4p-bbpress-attachments'); if ($nonce) { global $user_ID; $action = $_GET['d4pbbaction']; $att_id = $_GET['att_id']; $bbp_id = $_GET['bbp_id']; $post = get_post($bbp_id); $author_ID = $post->post_author; $file = get_attached_file($att_id); $file = pathinfo($file, PATHINFO_BASENAME); $allow = 'no'; if (d4p_is_user_admin()) { $allow = d4p_bba_o('delete_visible_to_admins'); } else { if (d4p_is_user_moderator()) { $allow = d4p_bba_o('delete_visible_to_moderators'); } else { if ($author_ID == $user_ID) { $allow = d4p_bba_o('delete_visible_to_author'); } } } if ($action == 'delete' && ($allow == 'delete' || $allow == 'both')) { wp_delete_attachment($att_id); add_post_meta($bbp_id, '_bbp_attachment_log', array('code' => 'delete_attachment', 'user' => $user_ID, 'file' => $file)); } if ($action == 'detach' && ($allow == 'detach' || $allow == 'both')) { global $wpdb; $wpdb->update($wpdb->posts, array('post_parent' => 0), array('ID' => $att_id)); add_post_meta($bbp_id, '_bbp_attachment_log', array('code' => 'detach_attachment', 'user' => $user_ID, 'file' => $file)); } } $url = remove_query_arg(array('_wpnonce', 'd4pbbaction', 'att_id', 'bbp_id')); wp_redirect($url); exit; } }
<?php $attachments = d4p_get_post_attachments($post_ID); if (empty($attachments)) { _e("No attachments here.", "gd-bbpress-attachments"); } else { echo '<ul style="list-style: decimal outside; margin-left: 1.5em;">'; foreach ($attachments as $attachment) { $file = get_attached_file($attachment->ID); $filename = pathinfo($file, PATHINFO_BASENAME); echo '<li>' . $filename; echo ' - <a href="' . admin_url('media.php?action=edit&attachment_id=' . $attachment->ID) . '">' . __("edit", "gd-bbpress-attachments") . '</a>'; echo '</li>'; } echo '</ul>'; } if (d4p_bba_o("errors_visible_to_author") == 1 && $author_id == $user_ID || d4p_bba_o("errors_visible_to_admins") == 1 && d4p_is_user_admin() || d4p_bba_o("errors_visible_to_moderators") == 1 && d4p_is_user_moderator()) { $errors = get_post_meta($post_ID, "_bbp_attachment_upload_error"); if (!empty($errors)) { echo '<h4>' . __("Upload Errors", "gd-bbpress-attachments") . ':</h4>'; echo '<ul style="list-style: decimal outside; margin-left: 1.5em;">'; foreach ($errors as $error) { echo '<li><strong>' . $error["file"] . '</strong>:<br/>' . __($error["message"], "gd-bbpress-attachments") . '</li>'; } echo '</ul>'; } }
public function embed_attachments($content, $id) { global $gdbbpress_attachments, $user_ID; $attachments = d4p_get_post_attachments($id); $post = get_post($id); $author_id = $post->post_author; if (!empty($attachments)) { $content .= '<div class="bbp-attachments">'; $content .= '<h6>' . __("Attachments", "gd-bbpress-attachments") . ':</h6>'; if (!is_user_logged_in() && $gdbbpress_attachments->is_hidden_from_visitors()) { $content .= sprintf(__("You must be <a href='%s'>logged in</a> to view attached files.", "gd-bbpress-attachments"), wp_login_url(get_permalink())); } else { if (!empty($attachments)) { $listing = '<ol'; if (d4p_bba_o("attchment_icons") == 1) { $listing .= ' class="with-icons"'; } $listing .= '>'; $thumbnails = $listing; $images = $files = 0; foreach ($attachments as $attachment) { $actions = array(); $url = add_query_arg('_wpnonce', wp_create_nonce('d4p-bbpress-attachments')); $url = add_query_arg('att_id', $attachment->ID, $url); $url = add_query_arg('bbp_id', $id, $url); $allow = 'no'; if (d4p_is_user_admin()) { $allow = d4p_bba_o('delete_visible_to_admins'); } else { if (d4p_is_user_moderator()) { $allow = d4p_bba_o('delete_visible_to_moderators'); } else { if ($author_id == $user_ID) { $allow = d4p_bba_o('delete_visible_to_author'); } } } if ($allow == 'delete' || $allow == 'both') { $actions[] = '<a href="' . add_query_arg('d4pbbaction', 'delete', $url) . '">' . __("delete", "gd-bbpress-attachments") . '</a>'; } if ($allow == 'detach' || $allow == 'both') { $actions[] = '<a href="' . add_query_arg('d4pbbaction', 'detach', $url) . '">' . __("detach", "gd-bbpress-attachments") . '</a>'; } if (count($actions) > 0) { $actions = ' [' . join(' | ', $actions) . ']'; } else { $actions = ''; } $file = get_attached_file($attachment->ID); $ext = pathinfo($file, PATHINFO_EXTENSION); $filename = pathinfo($file, PATHINFO_BASENAME); $file_url = wp_get_attachment_url($attachment->ID); $html = $class_li = $class_a = $rel_a = ""; $a_title = $filename; $caption = false; $img = false; if (d4p_bba_o('image_thumbnail_active') == 1) { $html = wp_get_attachment_image($attachment->ID, 'd4p-bbp-thumb'); if ($html != "") { $img = true; $class_li = 'bbp-atthumb'; if (d4p_bba_o('image_thumbnail_inline') == 1) { $class_li .= ' bbp-inline'; } $class_a = d4p_bba_o('image_thumbnail_css'); $caption = d4p_bba_o('image_thumbnail_caption') == 1; $rel_a = ' rel="' . d4p_bba_o('image_thumbnail_rel') . '"'; $rel_a = str_replace('%ID%', $id, $rel_a); $rel_a = str_replace('%TOPIC%', bbp_get_topic_id(), $rel_a); } } if ($html == '') { $html = $filename; if (d4p_bba_o("attchment_icons") == 1) { $class_li = "bbp-atticon bbp-atticon-" . $this->icon($ext); } } $item = '<li id="d4p-bbp-attachment_' . $attachment->ID . '" class="d4p-bbp-attachment d4p-bbp-attachment-' . $ext . ' ' . $class_li . '">'; if ($caption) { $item .= '<div style="width: ' . d4p_bba_o("image_thumbnail_size_x") . 'px" class="wp-caption">'; } $item .= '<a class="' . $class_li . ' ' . $class_a . '"' . $rel_a . ' href="' . $file_url . '" title="' . $a_title . '">' . $html . '</a>'; if ($caption) { $item .= '<p class="wp-caption-text">' . $a_title . '<br/>' . $actions . '</p></div>'; } else { $item .= $actions; } $item .= '</li>'; if ($img) { $thumbnails .= $item; $images++; } else { $listing .= $item; $files++; } } $thumbnails .= '</ol>'; $listing .= '</ol>'; if ($images > 0) { $content .= $thumbnails; } if ($files > 0) { $content .= $listing; } } } $content .= '</div>'; } if (d4p_bba_o('errors_visible_to_author') == 1 && $author_id == $user_ID || d4p_bba_o('errors_visible_to_admins') == 1 && d4p_is_user_admin() || d4p_bba_o('errors_visible_to_moderators') == 1 && d4p_is_user_moderator()) { $errors = get_post_meta($id, '_bbp_attachment_upload_error'); if (!empty($errors)) { $content .= '<div class="bbp-attachments-errors">'; $content .= '<h6>' . __("Upload Errors", "gd-bbpress-attachments") . ':</h6>'; $content .= '<ol>'; foreach ($errors as $error) { $content .= '<li><strong>' . $error['file'] . '</strong>: ' . __($error['message'], "gd-bbpress-attachments") . '</li>'; } $content .= '</ol></div>'; } } return $content; }