commit a3c6de0cfe31c8488ca62c87c7404bf05a02f59e Author: Marco Antonio Date: Wed Oct 1 23:56:12 2025 -0300 Criação diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/README.md b/README.md new file mode 100644 index 0000000..bff40f9 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Sistema de Parceiros Plugin + +## Description + +The Sistema de Parceiros plugin is designed to manage partners and partnerships within a WordPress site. It provides filtering capabilities and uses shortcodes to display partners on the frontend. + +## Features + +- **Partner Management:** Easily add, edit, and delete partners through the WordPress admin interface. +- **Customizable Display:** Use shortcodes to display partners on any page or post. +- **Filtering:** Filter partners by category or sector. +- **Responsive Design:** The plugin is designed to be responsive and look good on all devices. + +## Installation + +1. Upload the entire plugin directory to the `/wp-content/plugins/` directory. +2. Activate the plugin through the 'Plugins' menu in WordPress. + +## Usage + +### Shortcode + +Use the `[parceiros]` shortcode to display partners on any page or post. + +#### Attributes + +- `categoria`: Filter partners by category. +- `setor`: Filter partners by sector. +- `limite`: Limit the number of partners displayed. + +Example: `[parceiros categoria="Technology" limite="5"]` + +## Contributing + +Contributions are welcome! Please submit any issues or pull requests on the GitHub repository. \ No newline at end of file diff --git a/admin/form-parceiro.php b/admin/form-parceiro.php new file mode 100644 index 0000000..5f520c9 --- /dev/null +++ b/admin/form-parceiro.php @@ -0,0 +1,346 @@ +prefix . 'parceiros'; + +$parceiro = null; +$titulo_pagina = 'Adicionar Parceiro'; +$acao = 'adicionar_parceiro'; +$nonce_action = 'adicionar_parceiro'; + +// Verificar se é edição +if (isset($_GET['id']) && is_numeric($_GET['id'])) { + $id = intval($_GET['id']); + $parceiro = $wpdb->get_row($wpdb->prepare("SELECT * FROM $tabela_parceiros WHERE id = %d", $id)); + + if ($parceiro) { + $titulo_pagina = 'Editar Parceiro'; + $acao = 'editar_parceiro'; + $nonce_action = 'editar_parceiro'; + } +} + +// Obter setores e categorias existentes para sugestões +$setores_existentes = $wpdb->get_col("SELECT DISTINCT setor FROM $tabela_parceiros WHERE setor != '' ORDER BY setor"); +$categorias_existentes = $wpdb->get_col("SELECT DISTINCT categoria FROM $tabela_parceiros WHERE categoria != '' ORDER BY categoria"); +?> + +
+

+ +
+
+ + + + + + +
+ + +
+ +
+ + logo)): ?> +
+ Logo atual +
+ Logo atual +
+ + + Formatos: JPG, PNG, GIF. Tamanho máximo: 2MB +
+ +
+
+ + +
+ +
+ + +
+
+ +
+ + +
+ +
+
+ + + + + +
+ +
+ + + + + +
+
+ +
+ + +
+ +
+ + Desmarque para desativar este parceiro (não será exibido no site) +
+ +
+ + + + Cancelar + +
+
+
+
+ + + + \ No newline at end of file diff --git a/admin/lista-parceiros.php b/admin/lista-parceiros.php new file mode 100644 index 0000000..e938438 --- /dev/null +++ b/admin/lista-parceiros.php @@ -0,0 +1,80 @@ +
+

Gerenciar Parceiros

+ + + + Adicionar Novo Parceiro + + +
+

+ +

+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NomeSetorCategoriaTelefoneEmailStatusAções
Nenhum parceiro cadastrado.
nome); ?>setor); ?>categoria); ?>telefone); ?>email); ?>ativo ? 'Ativo' : 'Inativo'; ?> +
+ + + + +
+ +
+ + + + +
+
+
+
\ No newline at end of file diff --git a/css/parceiros.css b/css/parceiros.css new file mode 100644 index 0000000..d9d46a7 --- /dev/null +++ b/css/parceiros.css @@ -0,0 +1,308 @@ +/* Sistema de Parceiros - Estilos Modernos */ +.parceiros-container { + max-width: 1200px; + margin: 0 auto; + padding: 20px; + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; +} + +.parceiros-filtros { + background: #f8f9fa; + padding: 20px; + border-radius: 10px; + margin-bottom: 30px; + box-shadow: 0 2px 10px rgba(0,0,0,0.1); +} + +.filtro-grupo { + margin-bottom: 15px; +} + +.filtro-grupo label { + display: block; + margin-bottom: 5px; + font-weight: 600; + color: #333; +} + +.filtro-grupo input, +.filtro-grupo select { + width: 100%; + padding: 10px; + border: 1px solid #ddd; + border-radius: 5px; + font-size: 14px; +} + +.botao-filtrar { + background: #007cba; + color: white; + border: none; + padding: 10px 20px; + border-radius: 5px; + cursor: pointer; + font-size: 14px; + transition: background 0.3s; +} + +.botao-filtrar:hover { + background: #005a87; +} + +.grid-parceiros { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); + gap: 25px; + margin-top: 30px; +} + +.card-parceiro { + background: white; + border-radius: 12px; + padding: 25px; + box-shadow: 0 4px 15px rgba(0,0,0,0.1); + transition: transform 0.3s, box-shadow 0.3s; + border: 1px solid #eaeaea; +} + +.card-parceiro:hover { + transform: translateY(-5px); + box-shadow: 0 8px 25px rgba(0,0,0,0.15); +} + +.parceiro-logo { + text-align: center; + margin-bottom: 20px; +} + +.parceiro-logo img { + max-width: 120px; + max-height: 80px; + object-fit: contain; +} + +.parceiro-logo .logo-placeholder { + width: 120px; + height: 80px; + background: #f0f0f0; + display: inline-flex; + align-items: center; + justify-content: center; + border-radius: 8px; + color: #999; + font-size: 12px; +} + +.parceiro-nome { + font-size: 18px; + font-weight: 700; + color: #333; + margin-bottom: 15px; + text-align: center; +} + +.parceiro-info { + margin-bottom: 12px; + display: flex; + align-items: flex-start; +} + +.parceiro-info i { + width: 20px; + margin-right: 10px; + color: #007cba; + text-align: center; +} + +.parceiro-setor, +.parceiro-categoria { + display: inline-block; + background: #e9f7fe; + color: #007cba; + padding: 4px 10px; + border-radius: 20px; + font-size: 12px; + margin-right: 8px; + margin-bottom: 8px; +} + +.parceiro-acoes { + margin-top: 20px; + text-align: center; +} + +.botao-contato { + display: inline-block; + background: #28a745; + color: white; + padding: 8px 16px; + border-radius: 5px; + text-decoration: none; + font-size: 14px; + transition: background 0.3s; +} + +.botao-contato:hover { + background: #218838; + color: white; +} + +.sem-parceiros { + text-align: center; + padding: 40px; + color: #666; + font-style: italic; +} + +.search-box { + margin-bottom: 20px; + display: flex; +} + +.search-box input[type="search"] { + flex-grow: 1; + padding: 10px; + border: 1px solid #ddd; + border-radius: 4px 0 0 4px; +} + +.search-box input[type="submit"] { + background: #007cba; + color: white; + border-radius: 0 4px 4px 0; +} + +/* Responsividade */ +@media (max-width: 768px) { + .grid-parceiros { + grid-template-columns: 1fr; + } + + .parceiros-filtros { + padding: 15px; + } +} + +/* Admin Styles */ +.wrap h1 { + color: #23282d; +} + +.parceiros-lista-admin { + background: white; + border-radius: 8px; + overflow: hidden; + box-shadow: 0 1px 3px rgba(0,0,0,0.1); + margin-bottom: 20px; +} + +.parceiros-lista-admin table { + width: 100%; + border-collapse: collapse; +} + +.parceiros-lista-admin th { + background: #f8f9fa; + padding: 15px; + text-align: left; + border-bottom: 1px solid #eaeaea; + font-weight: 600; +} + + +.parceiros-lista-admin td { + padding: 12px; + border-bottom: 1px solid #eaeaea; +} + +.parceiros-lista-admin tr:hover { + background: #f8f9fa; +} + +/* Melhorias responsivas para a tabela */ +@media screen and (max-width: 782px) { + .parceiros-lista-admin table { + display: block; + overflow-x: auto; /* Adiciona barra de rolagem horizontal em telas pequenas */ + white-space: nowrap; /* Evita que as células quebrem o layout */ + } + +} + +.acao-botao { + padding: 6px 12px; + border: none; + border-radius: 4px; + cursor: pointer; + font-size: 12px; + margin-right: 5px; + text-decoration: none; +} + +.botao-editar { + background: #007cba; + color: white; +} + +.botao-excluir { + padding: 6px 12px; + border: none; + border-radius: 4px; + cursor: pointer; + background: #dc3545; + color: white; +} + +.botao-adicionar { + background: #28a745; + color: white; + padding: 10px 20px; + text-decoration: none; + border-radius: 5px; + display: inline-block; + font-size: 14px; + margin-bottom: 20px; +} + +.form-parceiro { + background: white; + padding: 30px; + border-radius: 8px; + box-shadow: 0 1px 3px rgba(0,0,0,0.1); + max-width: 700px; +} + +.form-grupo { + margin-bottom: 20px; +} + +.form-grupo label { + display: block; + margin-bottom: 5px; + font-weight: 600; +} + +.form-grupo input, +.form-grupo select, +.form-grupo textarea { + width: 100%; + padding: 8px 12px; + border: 1px solid #ddd; + border-radius: 4px; + font-size: 14px; +} + +.form-grupo textarea { + height: 100px; + resize: vertical; +} + +.botao-submit { + background: #007cba; + color: white; + padding: 10px 20px; + border: none; + border-radius: 4px; + cursor: pointer; + font-size: 14px; +} \ No newline at end of file diff --git a/js/parceiros.js b/js/parceiros.js new file mode 100644 index 0000000..1fbdee2 --- /dev/null +++ b/js/parceiros.js @@ -0,0 +1,48 @@ +jQuery(document).ready(function($) { + // Filtros em tempo real + $('#pesquisa-parceiros').on('input', function() { + filtrarParceiros(); + }); + + $('#filtro-setor, #filtro-categoria').on('change', function() { + filtrarParceiros(); + }); + + function filtrarParceiros() { + var pesquisa = $('#pesquisa-parceiros').val().toLowerCase(); + var setor = $('#filtro-setor').val(); + var categoria = $('#filtro-categoria').val(); + + $('.card-parceiro').each(function() { + var $card = $(this); + var nome = $card.find('.parceiro-nome').text().toLowerCase(); + var cardSetor = $card.data('setor'); + var cardCategoria = $card.data('categoria'); + + var correspondePesquisa = nome.indexOf(pesquisa) > -1 || pesquisa === ''; + var correspondeSetor = setor === '' || cardSetor === setor; + var correspondeCategoria = categoria === '' || cardCategoria === categoria; + + if (correspondePesquisa && correspondeSetor && correspondeCategoria) { + $card.show(); + } else { + $card.hide(); + } + }); + + // Mostrar mensagem se não houver resultados + var cardsVisiveis = $('.card-parceiro:visible').length; + if (cardsVisiveis === 0) { + $('.sem-parceiros').show(); + } else { + $('.sem-parceiros').hide(); + } + } + + // Confirmação para exclusão + $('.botao-excluir').on('click', function(e) { + if (!confirm('Tem certeza que deseja excluir este parceiro?')) { + e.preventDefault(); + } + }); +}); \ No newline at end of file diff --git a/sistema-parceiros.php b/sistema-parceiros.php new file mode 100644 index 0000000..2e50301 --- /dev/null +++ b/sistema-parceiros.php @@ -0,0 +1,359 @@ +criar_tabela_parceiros(); + $this->inserir_dados_exemplo(); + } + + // Inicializar o plugin + public function init() { + add_action('wp_enqueue_scripts', array($this, 'carregar_recursos')); + add_shortcode('parceiros', array($this, 'shortcode_parceiros')); + + // Para área administrativa + if (is_admin()) { + add_action('admin_menu', array($this, 'adicionar_menu_admin')); + add_action('admin_post_adicionar_parceiro', array($this, 'processar_form_adicionar')); + add_action('admin_post_editar_parceiro', array($this, 'processar_form_editar')); + add_action('admin_post_excluir_parceiro', array($this, 'processar_form_excluir')); + } + } + + // Carregar CSS e JS + public function carregar_recursos() { + wp_enqueue_style('parceiros-css', plugin_dir_url(__FILE__) . 'css/parceiros.css'); + wp_enqueue_script('parceiros-js', plugin_dir_url(__FILE__) . 'js/parceiros.js', array('jquery'), '1.0', true); + + // Localizar script para AJAX + wp_localize_script('parceiros-js', 'parceiros_ajax', array( + 'ajax_url' => admin_url('admin-ajax.php'), + 'nonce' => wp_create_nonce('parceiros_nonce') + )); + } + + // Criar tabela no banco de dados + private function criar_tabela_parceiros() { + global $wpdb; + + $tabela_parceiros = $wpdb->prefix . 'parceiros'; + + $charset_collate = $wpdb->get_charset_collate(); + + $sql = "CREATE TABLE $tabela_parceiros ( + id mediumint(9) NOT NULL AUTO_INCREMENT, + nome varchar(255) NOT NULL, + logo varchar(255), + telefone varchar(20), + endereco text, + email varchar(100), + site varchar(255), + setor varchar(100), + categoria varchar(100), + ativo tinyint(1) DEFAULT 1, + data_criacao datetime DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (id) + ) $charset_collate;"; + + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); + dbDelta($sql); + } + + // Inserir dados de exemplo + private function inserir_dados_exemplo() { + global $wpdb; + $tabela_parceiros = $wpdb->prefix . 'parceiros'; + + $parceiros_exemplo = array( + array( + 'nome' => 'Empresa Tech Solutions', + 'logo' => '', + 'telefone' => '(11) 1234-5678', + 'endereco' => 'Av. Paulista, 1000 - São Paulo, SP', + 'email' => 'contato@techsolutions.com', + 'site' => 'https://techsolutions.com', + 'setor' => 'Tecnologia', + 'categoria' => 'Desenvolvimento' + ), + array( + 'nome' => 'Marketing Digital Pro', + 'logo' => '', + 'telefone' => '(21) 9876-5432', + 'endereco' => 'Rua do Ouvidor, 50 - Rio de Janeiro, RJ', + 'email' => 'contato@marketingpro.com', + 'site' => 'https://marketingpro.com', + 'setor' => 'Marketing', + 'categoria' => 'Digital' + ) + ); + + foreach ($parceiros_exemplo as $parceiro) { + $wpdb->insert($tabela_parceiros, $parceiro); + } + } + + // Shortcode para exibir parceiros + public function shortcode_parceiros($atts) { + $atts = shortcode_atts(array( + 'categoria' => '', + 'setor' => '', + 'limite' => -1 + ), $atts); + + ob_start(); + $this->exibir_parceiros($atts); + return ob_get_clean(); + } + + // Exibir parceiros no frontend + private function exibir_parceiros($filtros = array()) { + global $wpdb; + $tabela_parceiros = $wpdb->prefix . 'parceiros'; + + // Construir query com filtros + $where = "WHERE ativo = 1"; + if (!empty($filtros['categoria'])) { + $where .= $wpdb->prepare(" AND categoria = %s", $filtros['categoria']); + } + if (!empty($filtros['setor'])) { + $where .= $wpdb->prepare(" AND setor = %s", $filtros['setor']); + } + + $limite = ''; + if ($filtros['limite'] > 0) { + $limite = "LIMIT " . intval($filtros['limite']); + } + + $parceiros = $wpdb->get_results(" + SELECT * FROM $tabela_parceiros + $where + ORDER BY nome + $limite + "); + + // Obter setores e categorias únicas para os filtros + $setores = $wpdb->get_col("SELECT DISTINCT setor FROM $tabela_parceiros WHERE ativo = 1 AND setor != '' ORDER BY setor"); + $categorias = $wpdb->get_col("SELECT DISTINCT categoria FROM $tabela_parceiros WHERE ativo = 1 AND categoria != '' ORDER BY categoria"); + + // Incluir template + include plugin_dir_path(__FILE__) . 'templates/lista-parceiros.php'; + } + + // Adicionar menu administrativo + public function adicionar_menu_admin() { + add_menu_page( + 'Parceiros', + 'Parceiros', + 'manage_options', + 'parceiros', + array($this, 'pagina_admin_parceiros'), + 'dashicons-groups', + 30 + ); + + add_submenu_page( + 'parceiros', + 'Todos os Parceiros', + 'Todos os Parceiros', + 'manage_options', + 'parceiros', + array($this, 'pagina_admin_parceiros') + ); + + add_submenu_page( + 'parceiros', + 'Adicionar Parceiro', + 'Adicionar Parceiro', + 'manage_options', + 'adicionar-parceiro', + array($this, 'pagina_adicionar_parceiro') + ); + } + + // Página administrativa principal + public function pagina_admin_parceiros() { + global $wpdb; + $tabela_parceiros = $wpdb->prefix . 'parceiros'; + + $search_term = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; + $sql = "SELECT * FROM $tabela_parceiros"; + if (!empty($search_term)) { + $sql .= $wpdb->prepare(" WHERE nome LIKE '%%%s%%'", $search_term); + } + $sql .= " ORDER BY nome"; + $parceiros = $wpdb->get_results($sql); + + include plugin_dir_path(__FILE__) . 'admin/lista-parceiros.php'; + } + + // Página para adicionar parceiro + public function pagina_adicionar_parceiro() { + include plugin_dir_path(__FILE__) . 'admin/form-parceiro.php'; + } + + // Processar formulário de adicionar parceiro + public function processar_form_adicionar() { + if (!current_user_can('manage_options')) { + wp_die('Sem permissão'); + } + + check_admin_referer('adicionar_parceiro'); + + global $wpdb; + $tabela_parceiros = $wpdb->prefix . 'parceiros'; + + $dados = array( + 'nome' => sanitize_text_field($_POST['nome']), + 'telefone' => sanitize_text_field($_POST['telefone']), + 'endereco' => sanitize_textarea_field($_POST['endereco']), + 'email' => sanitize_email($_POST['email']), + 'site' => esc_url_raw($_POST['site']), + 'setor' => sanitize_text_field($_POST['setor']), + 'categoria' => sanitize_text_field($_POST['categoria']), + 'ativo' => isset($_POST['ativo']) ? 1 : 0 + ); + + // Processar upload de logo + if (!empty($_FILES['logo']['name'])) { + $file = $_FILES['logo']; + $allowed_types = array('jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif'); + $max_size = 2 * 1024 * 1024; // 2MB + + // Validate file type + $file_type = wp_check_filetype($file['name']); + if (!array_key_exists($file_type['ext'], $allowed_types)) { + wp_die("Erro: Formato de arquivo inválido. Apenas JPG, PNG e GIF são permitidos."); + } + + // Validate file size + if ($file['size'] > $max_size) { + wp_die("Erro: O arquivo é muito grande. O tamanho máximo permitido é 2MB."); + } + + // Handle the upload + $upload = wp_handle_upload($file, array('test_form' => false)); + + if ($upload && !isset($upload['error'])) { + $dados['logo'] = $upload['url']; + } else + wp_die('Erro ao fazer upload do logo: ' . $upload['error']); + } + + $wpdb->insert($tabela_parceiros, $dados); + + wp_redirect(admin_url('admin.php?page=parceiros&mensagem=adicionado')); + exit; + } + + // Processar formulário de editar parceiro + public function processar_form_editar() { + if (!current_user_can('manage_options')) { + wp_die('Sem permissão'); + } + + check_admin_referer('editar_parceiro'); + + global $wpdb; + $tabela_parceiros = $wpdb->prefix . 'parceiros'; + + $id = intval($_POST['id']); + + $dados = array( + 'nome' => sanitize_text_field($_POST['nome']), + 'telefone' => sanitize_text_field($_POST['telefone']), + 'endereco' => sanitize_textarea_field($_POST['endereco']), + 'email' => sanitize_email($_POST['email']), + 'site' => esc_url_raw($_POST['site']), + 'setor' => sanitize_text_field($_POST['setor']), + 'categoria' => sanitize_text_field($_POST['categoria']), + 'ativo' => isset($_POST['ativo']) ? 1 : 0 + ); + + // Processar upload de logo + if (!empty($_FILES['logo']['name'])) { + $file = $_FILES['logo']; + $allowed_types = array('jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif'); + $max_size = 2 * 1024 * 1024; // 2MB + + // Validate file type + $file_type = wp_check_filetype($file['name']); + if (!array_key_exists($file_type['ext'], $allowed_types)) { + wp_die("Erro: Formato de arquivo inválido. Apenas JPG, PNG e GIF são permitidos."); + } + + // Validate file size + if ($file['size'] > $max_size) { + wp_die("Erro: O arquivo é muito grande. O tamanho máximo permitido é 2MB."); + } + + // Handle the upload + $upload = wp_handle_upload($file, array('test_form' => false)); + + if ($upload && !isset($upload['error'])) { + $dados['logo'] = $upload['url']; + } else + wp_die('Erro ao fazer upload do logo: ' . $upload['error']); + } + + $wpdb->update($tabela_parceiros, $dados, array('id' => $id)); + + wp_redirect(admin_url('admin.php?page=parceiros&mensagem=editado')); + exit; + } + + // Processar exclusão de parceiro + public function processar_form_excluir() { + if (!current_user_can('manage_options')) { + wp_die('Sem permissão'); + } + + check_admin_referer('excluir_parceiro'); + + global $wpdb; + $tabela_parceiros = $wpdb->prefix . 'parceiros'; + + $id = intval($_POST['id']); + $wpdb->delete($tabela_parceiros, array('id' => $id)); + + wp_redirect(admin_url('admin.php?page=parceiros&mensagem=excluido')); + exit; + } +} + +// Inicializar o plugin +new SistemaParceiros(); + +// Funções auxiliares +function obter_parceiros($filtros = array()) { + global $wpdb; + $tabela_parceiros = $wpdb->prefix . 'parceiros'; + + $where = "WHERE ativo = 1"; + if (!empty($filtros['categoria'])) { + $where .= $wpdb->prepare(" AND categoria = %s", $filtros['categoria']); + } + if (!empty($filtros['setor'])) { + $where .= $wpdb->prepare(" AND setor = %s", $filtros['setor']); + } + + return $wpdb->get_results("SELECT * FROM $tabela_parceiros $where ORDER BY nome"); +} +?> \ No newline at end of file diff --git a/templates/lista-parceiros.php b/templates/lista-parceiros.php new file mode 100644 index 0000000..b21bca0 --- /dev/null +++ b/templates/lista-parceiros.php @@ -0,0 +1,88 @@ +
+
+
+ + +
+ +
+
+ + +
+ +
+ + +
+
+
+ + +
+ Nenhum parceiro encontrado. +
+ +
+ +
+ + +

nome); ?>

+ + setor)): ?> + setor); ?> + + + categoria)): ?> + categoria); ?> + + +
+ 📞 + telefone); ?> +
+ + endereco)): ?> +
+ 📍 + endereco); ?> +
+ + +
+ ✉️ + email); ?> +
+ + site)): ?> +
+ 🌐 + Visitar Site +
+ + + +
+ +
+ +
\ No newline at end of file