Skip to content

Commit

Permalink
Refeito plugin de FAQ e alteradas permissões gerais
Browse files Browse the repository at this point in the history
  • Loading branch information
andrebian committed Jul 22, 2013
1 parent bcb0912 commit ed5cc40
Show file tree
Hide file tree
Showing 103 changed files with 193 additions and 181 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nbproject/*
src/nbproject/*
Empty file modified README
100644 → 100755
Empty file.
Empty file modified bin/empty
100644 → 100755
Empty file.
Empty file modified doc/empty
100644 → 100755
Empty file.
Empty file modified src/destaque-home/destaque.php
100644 → 100755
Empty file.
Empty file modified src/destaque-home/plugin-destaque-home.php
100644 → 100755
Empty file.
Empty file modified src/destaque-home/sources/imagens/destaque-home.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/destaque-home/sources/imagens/plugin-icon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/destaque-home/sources/theme-pages/index.php
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions src/faq/changelog
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@


/---------------------------------------------------------/

2.0
22/07/2013
Refeito todo o plugin

1.0
04/10/2012
Criada a primeira versão do plugin
Expand Down
103 changes: 59 additions & 44 deletions src/faq/nova-pergunta.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,65 +1,80 @@
<?php
/**
* @since 1.0
*/

include_once 'core/faq-core.php';
global $current_user;

$cabecalho = '<h3>Bem vindo(a) ao cadastro de perguntas e respostas.</h3>';
$botao = 'Gravar';

if(!empty($_GET['id_faq']) && is_numeric($_GET['id_faq']))
{
$cabecalho = '<h3>Alterando Pergunta com ID '.(int)$_GET['id_faq'].'</h3>';
if (!empty($_GET['id_faq']) && is_numeric($_GET['id_faq'])) {
$cabecalho = '<h3>Alterando Pergunta com ID ' . (int) $_GET['id_faq'] . '</h3>';
$botao = 'Gravar alterações';
}

$idFaq = isset($_GET['id_faq']) ? (int)$_GET['id_faq'] : '' ;
$id_faq = isset($_GET['id_faq']) ? (int) $_GET['id_faq'] : '';
$dados_faq = null;

$Faq = new Faq();
if ( !empty($id_faq) ) {
$dados_faq = get_post($id_faq);
}

if (isset($_POST['pergunta']) && !empty($_POST['pergunta']) && isset($_POST['solucao']) && !empty($_POST['pergunta'])) {

$dadosFaq = $Faq->detalhesFaq($idFaq);
$post = array(
'menu_order' => '0',
'comment_status' => 'closed',
'ping_status' => 'open',
'post_author' => $current_user->ID,
'post_content' => sanitize_text_field($_POST['solucao']),
'post_excerpt' => substr(sanitize_text_field($_POST['solucao']), 0, 200),
'post_name' => sanitize_title($_POST['pergunta']),
'post_status' => 'publish',
'post_title' => $_POST['pergunta'],
'post_type' => 'faq',
);

if(isset($_POST['solucao']) && isset($_POST['pergunta']))
{
$dadosFaq->pergunta = addslashes(isset($_POST['pergunta']) ? $_POST['pergunta'] : '');
$dadosFaq->solucao = addslashes(isset($_POST['solucao']) ? $_POST['solucao'] : '');
$dadosFaq->idFaq = addslashes(isset($_POST['id_faq']) ? $_POST['id_faq'] : '');
if ( isset($_POST['id_faq']) && !empty($_POST['id_faq']) ) {
$post['ID'] = (int) $_POST['id_faq'];
}

if( $Faq->verificaExistenciaFaq($dadosFaq) )
{
echo "<meta http-equiv='refresh' content='1; ?page=faq/perguntas.php' ><div class='update-nag' style='background: green; color: white; font-size: 16px;'>Dados do FAQ gravados com sucesso!</div>";
if ( wp_update_post($post) ) {
echo '<script>alert("Faq atualizado com sucesso!"); window.location.href="?page=faq/nova-pergunta.php";</script>';
}
else
{
echo "<div class='update-nag' style='background: orange; font-size: 16px;'>Não foi possível salvar os dados do FAQ, por favor preencha os campos obrigatórios</div>";
if (wp_insert_post($post)) {
echo '<script>alert("Faq cadastrado com sucesso!"); window.location.href="?page=faq/nova-pergunta.php";</script>';
}

}
?>
<br />

<form action="" method="post">
<table class="wp-list-table widefat fixed pages" cellspacing="0" style="width:95%;">
<thead>
<tr>
<th>
<?php echo $cabecalho; ?>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="hidden" name="id_faq" value="<?php echo $idFaq; ?>" />
Pergunta<br />
<input type="text" name="pergunta" maxlength="255" value="<?php echo @$dadosFaq->pergunta; ?>" style="width: 90%"/>
<br /><br />
Solução<br />
<textarea style="width: 90%; height: 100px;" name="solucao"><?php echo @$dadosFaq->solucao; ?></textarea>
<br /><br />
<input type="submit" value="<?php echo @$botao; ?>" class="button-primary"/>
<br />
</td>
</tr>
</tbody>
</table>
</form>
<thead>
<tr>
<th>
<?php echo $cabecalho; ?>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="hidden" name="id_faq" value="<?php echo @$dados_faq->ID; ?>" />
Pergunta<br />
<input type="text" name="pergunta" maxlength="255" value="<?php echo @$dados_faq->post_title; ?>" style="width: 90%"/>
<br /><br />

Solução<br />
<textarea style="width: 90%; height: 100px;" name="solucao"><?php echo @$dados_faq->post_content; ?></textarea>
<br /><br />

<input type="submit" value="<?php echo @$botao; ?>" class="button button-primary"/>
<br />
</td>
</tr>
</tbody>
</table>
</form>
122 changes: 33 additions & 89 deletions src/faq/perguntas.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,104 +1,48 @@
<?php
/**
* @since 1.0
*/

include_once 'core/faq-core.php';

$Faq = new Faq();

if(isset($_GET['acao']) && is_numeric($_GET['id_faq']))
{
if($_GET['acao'] == 'remover')
{
$idRemover = (int)$_GET['id_faq'];
if( $Faq->remover($idRemover) )
{
?>
<script type="text/javascript">
alert('Pergunta removida com sucesso!');
window.location.href="?page=faq/perguntas.php";
</script>
<?php
}
if (isset($_GET['id_faq']) && !empty($_GET['id_faq']) && $_GET['acao'] == 'remover') {
if (wp_delete_post($_GET['id_faq'])) {
echo '<script>alert("Faq removido com sucesso!"); window.location.href="?page=faq/perguntas.php";</script>';
}
}

$ordenacaoBusca->campo = 'id';
$ordenacaoBusca->ordem = 'desc';

if( $dadosFaq = $Faq->obterListaFaq($ordenacaoBusca) )
{
?>
if ($dadosFaq = get_posts(array('post_type' => 'faq'))) : ?>

<h3>Listando as Perguntas e respostas (FAQ) já cadastradas</h3>
<br />
<h3>Listando as Perguntas e respostas (FAQ) já cadastradas</h3>
<br />

<table class="wp-list-table widefat fixed pages" cellspacing="0" style="width:95%;">
<thead>
<tr>
<th>
ID
</th>
<th>
Pergunta
</th>
<th>
Solução
</th>
<th>
Ações
</th>
</tr>
</thead>
<tbody>
<?php
foreach($dadosFaq as $dadosFaq){

$imagem = '../wp-content/plugins/faq/sources/images/no-image.png';
if( $dadosFaq->imagem != '' )
{
$imagem = 'wp-content/uploads/faq/'.$dadosFaq->imagem;
}
?>
<thead>
<tr>
<th>Pergunta</th>
<th>Solução</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
<?php foreach ($dadosFaq as $dadosFaq) { ?>
<tr>
<td>
<?php echo (int)$dadosFaq->id ; ?>
<?php echo $dadosFaq->post_title; ?>
</td>
<td>
<?php echo $dadosFaq->pergunta ; ?>
<?php echo $dadosFaq->post_content; ?>
</td>
<td>
<?php echo $dadosFaq->solucao ; ?>
<a href="?page=faq/nova-pergunta.php&id_faq=<?php echo (int) $dadosFaq->ID; ?>">Editar</a> |
<a href="?page=faq/perguntas.php&acao=remover&id_faq=<?php echo (int) $dadosFaq->ID; ?>"
onclick="return confirm('Deseja realmente remover este FAQ?')">Remover</a>
</td>
<!--<td>
<img src="<?php echo $imagem ; ?>" width="64" />
</td> -->
<td>
<a href="?page=faq/nova-pergunta.php&id_faq=<?php echo (int)$dadosFaq->id; ?>">Editar</a> |
<a href="?page=faq/perguntas.php&acao=remover&id_faq=<?php echo (int)$dadosFaq->id; ?>" onclick="return confirmaRemocao();">Remover</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
else
{
echo "<h3>No momento não há Perguntas e respostas (FAQ) cadastradas</h3>";
}
?>
<script type="text/javascript">
function confirmaRemocao()
{
var decisao = confirm('Deseja realmente remover esta pergunta??');
if(decisao)
{
return true;
}
else
{
return false;
}
}
</script>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
else :
echo "<h3>No momento não há Perguntas e respostas (FAQ) cadastradas</h3>";
endif;
62 changes: 46 additions & 16 deletions src/faq/plugin-faq.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,32 +1,62 @@
<?php

<?php
/*
* Plugin Name: Perguntas e respostas
* Description: O plugin Perguntas e respostas facilita o cadastro de perguntas frequentes em seu Blog/Site
* Author: Redsuns Design e Tecnologia Web
* Author URI: http://www.redsuns.com.br
* Date: 2012-10-04
* Version: 1.0
* Date: 2013-07-22
* Version: 2.0
*/


function menuFAQ()
/**
* @since 2.0
*/
function codex_custom_init()
{
add_menu_page('Perguntas e respostas', 'Perguntas e respostas', 7, 'faq/perguntas.php','','../wp-content/plugins/faq/sources/images/question.png');
add_submenu_page('faq/perguntas.php', 'Nova pegunta','Nova pergunta', 7, 'faq/nova-pergunta.php');
$args = array('public' => true, 'label' => 'Faq');
register_post_type('faq', $args);
}

// adding menu
add_action('admin_menu', 'menuFAQ');
add_action('init', 'codex_custom_init');

include_once 'sources/schemas/default-schema-for-faq.php';

$url = get_bloginfo('url');
$themePath = str_replace($url,'..',get_bloginfo('template_url'));

if(!file_exists($themePath.'/page-faq.php'))
/**
* @#since 2.0
*/
function faq()
{
@copy('../wp-content/plugins/faq/theme-pages/page-faq.php',$themePath.'/page-faq.php');
show_faq();
}

?>
add_shortcode('faq', 'faq');


/**
* @since 2.0
*/
function show_faq()
{
$faqs = get_posts(array('post_type' => 'faq', 'orderby' => 'post_date', 'order' => 'ASC'));

if (!empty($faqs)) :
?>
<div class="faq">
<ul>
<?php foreach ($faqs as $faq) : ?>
<li>
<div class="content" id="<?php echo $faq->ID; ?>">
<a href="#" class="content-link" id="<?php echo $faq->ID; ?>"><h4><?php echo $faq->post_title; ?></h4></a>
<div class="answer" id="content_<?php echo $faq->ID; ?>" style="display:none;">
<p>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $faq->post_content; ?></p>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
</div>

<?php else : ?>
<h4>Não há perguntas e respostas cadastradas</h4>
<?php endif; ?>
<?php }
Loading

0 comments on commit ed5cc40

Please sign in to comment.