Skip to content

Commit

Permalink
Merge pull request #1 from ValkyriaTech/dev
Browse files Browse the repository at this point in the history
wordpress deploy
  • Loading branch information
victorandeloci authored May 7, 2022
2 parents 223090b + ded65cf commit be7e4c8
Show file tree
Hide file tree
Showing 22 changed files with 95 additions and 9,637 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Attachments for WordPress Posts & Pages
# File Attachments for Posts & Pages
Custom metabox controller to upload and manage posts / pages attachments

The custom metabox name is <code>wppa_attachment_list</code>. It's saved as a JSON *object* list:
The custom metabox name is <code>fapp_attachment_list</code>. It's saved as a JSON *object* list:

```json
{
Expand All @@ -12,4 +12,15 @@ The custom metabox name is <code>wppa_attachment_list</code>. It's saved as a JS
}
```

### Supported file types
```php
[
'text/plain',
'text/csv',
'application/pdf',
'application/vnd.oasis.opendocument.text',
'application/msword'
]
```

**Just download the source and install it as a plugin.**
5 changes: 0 additions & 5 deletions css/all.min.css

This file was deleted.

7 changes: 4 additions & 3 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@
height: auto;
border-radius: .2rem;
}
#attachmentDialog .row .column #wppa_attachmentCoverImage {
#attachmentDialog .row .column #fapp_attachmentCoverImage {
display: none;
}
#attachmentDialog .row .column #wppa_attachmentCoverImageLabel i {
#attachmentDialog .row .column #fapp_attachmentCoverImageLabel i {
margin-right: .5rem;
font-size: 120%;
}
Expand All @@ -107,7 +107,7 @@
width: 90%;
margin-bottom: 2rem;
}
#attachmentDialog .row .column #wppa_attachmentSend {
#attachmentDialog .row .column #fapp_attachmentSend {
width: 5rem;
margin-top: 3rem;
display: flex;
Expand Down Expand Up @@ -151,4 +151,5 @@
margin-left: .5rem;
margin-right: 1rem;
width: 7.5rem;
overflow: hidden;
}
2 changes: 1 addition & 1 deletion css/style.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 44 additions & 47 deletions wordpress-post-pdf-files.php → file-attachments-posts-pages.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

/*
* Plugin Name: PDF Attachments for WordPress Posts & Pages
* Plugin URI: https://github.com/ValkyriaTech/wordpress-post-pdf-files/
* Plugin Name: File Attachments for Posts & Pages
* Plugin URI: https://github.com/ValkyriaTech/file-attachments-posts-pages/
* Description:
* Version: 2.1.3
* Version: 2.2.0
* Author: ValkyriaTech
* Author URI: https://github.com/ValkyriaTech
* License: GPLv3
Expand All @@ -24,15 +24,7 @@ function loadPdfFilesBox() {
'main',
plugin_dir_url(__FILE__) . 'js/main.min.js',
null,
'2.1.3'
);

wp_enqueue_style(
'fontawesome-css',
plugin_dir_url(__FILE__) . 'css/all.min.css',
null,
'5.15.1',
'screen'
'2.2.0'
);

wp_enqueue_style(
Expand All @@ -47,33 +39,33 @@ function loadPdfFilesBox() {
'style',
plugin_dir_url(__FILE__) . 'css/style.min.css',
null,
'2.1.3',
'2.2.0',
'screen'
);

//custom metabox
add_meta_box(
'wppa_attachments_block',
'fapp_attachments_block',
'Anexos',
'wppa_attachments_block',
'fapp_attachments_block',
'post',
'side'
);

add_meta_box(
'wppa_attachments_block',
'fapp_attachments_block',
'Anexos',
'wppa_attachments_block',
'fapp_attachments_block',
'page',
'side'
);

}
add_action('add_meta_boxes', 'loadPdfFilesBox');

function wppa_attachments_block(){
function fapp_attachments_block() {

$attachments = get_post_meta(get_the_ID(), 'wppa_attachment_list', true) ?? '';
$attachments = get_post_meta(get_the_ID(), 'fapp_attachment_list', true) ?? '';

$attachmentsListBlock = '';
if(!empty($attachments)) {
Expand All @@ -82,9 +74,9 @@ function wppa_attachments_block(){
$attachmentsListBlock .= '<li class="att-item" id="attachment_' . $key . '">
<span>' . $attachment->name . '</span>
<div class="action-btns">
<a title="Abrir" class="link-btn" href="' . $attachment->url . '" target="blank" rel="noopener noreferrer"><i class="fas fa-link"></i></a>
<i title="Detalhes" data-key="' . $key . '" class="fas fa-edit edit-btn"></i>
<i title="Remover" data-key="' . $key . '" class="fas fa-times remove-btn"></i>
<a title="Open" class="link-btn" href="' . $attachment->url . '" target="blank" rel="noopener noreferrer"><i>🔗</i></a>
<i title="Details" data-key="' . $key . '" class="edit-btn">&#128393;</i>
<i title="Remove" data-key="' . $key . '" class="remove-btn"></i>
</div>
</li>';
}
Expand All @@ -98,58 +90,63 @@ function wppa_attachments_block(){
</button>
<div class="row">
<div class="column">
<h3 id="wppa_attachmentTitleShow">Attachment Cover</h3>
<img title="Imagem de capa do anexo" id="wppa_attachmentCoverImageShow" src="<?= plugin_dir_url(__FILE__) . 'img/default.jpg' ?>" alt="Attachment Cover">
<h3 id="fapp_attachmentTitleShow">Attachment Cover</h3>
<img title="Imagem de capa do anexo" id="fapp_attachmentCoverImageShow" src="<?= plugin_dir_url(__FILE__) . 'img/default.jpg' ?>" alt="Attachment Cover">
</div>
<div class="column">
<h3>Detalhes do anexo:</h3>
<input placeholder="Título" type="text" name="wppa_attachmentTitle" id="wppa_attachmentTitle">
<input placeholder="Título" type="text" name="fapp_attachmentTitle" id="fapp_attachmentTitle">
<br>
<textarea placeholder="Descrição" type="text" name="wppa_attachmentDescription" id="wppa_attachmentDescription"></textarea>
<textarea placeholder="Descrição" type="text" name="fapp_attachmentDescription" id="fapp_attachmentDescription"></textarea>
<br>
<label for="wppa_attachmentCoverImage" class="components-button is-secondary" id="wppa_attachmentCoverImageLabel" >
<label for="fapp_attachmentCoverImage" class="components-button is-secondary" id="fapp_attachmentCoverImageLabel" >
<i class="far fa-file-image"></i>
Alterar imagem de capa
</label>
<input type="file" id="wppa_attachmentCoverImage" name="wppa_attachmentCoverImage" value="" size="25"/>
<input type="hidden" name="wppa_attachmentFileUrl" id="wppa_attachmentFileUrl" value="">
<button class="components-button is-primary" type="button" name="wppa_attachmentSend" id="wppa_attachmentSend">Salvar</button>
<input type="file" id="fapp_attachmentCoverImage" name="fapp_attachmentCoverImage" value="" size="25"/>
<input type="hidden" name="fapp_attachmentFileUrl" id="fapp_attachmentFileUrl" value="">
<button class="components-button is-primary" type="button" name="fapp_attachmentSend" id="fapp_attachmentSend">Salvar</button>
</div>
</div>
</div>

<div action="<?= get_site_url() . '/wp-admin/admin-ajax.php?action=wppaUploadFile' ?>" id="attachmentDropzone" class="dropzone"></div>
<div action="<?= get_site_url() . '/wp-admin/admin-ajax.php?action=fappUploadFile' ?>" id="attachmentDropzone" class="dropzone"></div>
<ul id="attachmentsContainer"><?= $attachmentsListBlock ?></ul>
<input type="hidden" id="wppa_attachment_list" name="wppa_attachment_list" value='<?= $attachments ?>'/>
<input type="hidden" id="fapp_attachment_list" name="fapp_attachment_list" value='<?= $attachments ?>'/>
<script>
var wpApiUrl = '<?= get_site_url() ?>/wp-admin/admin-ajax.php';
var fileList = <?= (!empty($attachments) ? json_encode($attachments) : '""') ?>;
</script>
<?php
}

function wppa_metabox_save( $post_id ) {
function fapp_metabox_save( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( $parent_id = wp_is_post_revision( $post_id ) ) {
$post_id = $parent_id;
}
$fields = [
'wppa_attachment_list'
'fapp_attachment_list'
];
foreach ( $fields as $field ) {
if ( array_key_exists( $field, $_POST ) ) {
update_post_meta( $post_id, $field, sanitize_text_field( $_POST[$field] ) );
}
}
if ( array_key_exists( $field, $_POST ) ) {
update_post_meta( $post_id, $field, sanitize_text_field( $_POST[$field] ) );
}
}
}
add_action( 'save_post', 'wppa_metabox_save' );
add_action('save_post', 'fapp_metabox_save');

function wppaUploadFile() {
function fappUploadFile() {

$attachments = $_FILES['file'];

// Setup the array of supported file types. In this case, it's just PDF.
$supported_types = array('application/pdf', 'application/vnd.oasis.opendocument.text', 'application/msword');
$supported_types = [
'text/plain',
'text/csv',
'application/pdf',
'application/vnd.oasis.opendocument.text',
'application/msword'
];

// Get the file type of the upload
$arr_file_type = wp_check_filetype(basename($attachments['name']));
Expand All @@ -173,10 +170,10 @@ function wppaUploadFile() {

die();
}
add_action('wp_ajax_wppaUploadFile', 'wppaUploadFile');
add_action('wp_ajax_nopriv_wppaUploadFile', 'wppaUploadFile');
add_action('wp_ajax_fappUploadFile', 'fappUploadFile');
add_action('wp_ajax_nopriv_fappUploadFile', 'fappUploadFile');

function wppaUploadImage() {
function fappUploadImage() {

$attachments = $_FILES['file'];

Expand Down Expand Up @@ -205,7 +202,7 @@ function wppaUploadImage() {

die();
}
add_action('wp_ajax_wppaUploadImage', 'wppaUploadImage');
add_action('wp_ajax_nopriv_wppaUploadImage', 'wppaUploadImage');
add_action('wp_ajax_fappUploadImage', 'fappUploadImage');
add_action('wp_ajax_nopriv_fappUploadImage', 'fappUploadImage');

?>
Loading

0 comments on commit be7e4c8

Please sign in to comment.