-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Criada primeira versão do plugin FAQ
- Loading branch information
Showing
9 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
######################################################### | ||
# # | ||
# CHANGELOG PLUGIN FAQ # | ||
# # | ||
######################################################### | ||
|
||
|
||
/---------------------------------------------------------/ | ||
1.0 | ||
04/10/2012 | ||
Criada a primeira versão do plugin | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
class Faq | ||
{ | ||
public $name = 'Faq'; | ||
|
||
|
||
function obterListaFaq($ordenacao) | ||
{ | ||
$dadosFaq = array(); | ||
$obterFaq = "select * from rs_faq order by $ordenacao->campo $ordenacao->ordem"; | ||
$obterFaq = mysql_query($obterFaq) or die('Erro: '.mysql_error()); | ||
|
||
if(mysql_affected_rows()) | ||
{ | ||
while($filaFaq = mysql_fetch_object($obterFaq)) | ||
{ | ||
$dadosFaq[] = $filaFaq; | ||
} | ||
} | ||
return $dadosFaq; | ||
} | ||
|
||
|
||
|
||
function detalhesFaq($idFaq) | ||
{ | ||
$dadosFaq = ''; | ||
$buscaDadosFaq = "select * from rs_faq where id='$idFaq'"; | ||
$buscaDadosFaq = mysql_query($buscaDadosFaq) or die('Erro: '.mysql_error()); | ||
|
||
if(mysql_affected_rows()) | ||
{ | ||
$dadosFaq = mysql_fetch_object($buscaDadosFaq); | ||
} | ||
return $dadosFaq; | ||
} | ||
|
||
|
||
function verificaExistenciaFaq($dadosFaq) | ||
{ | ||
if($dadosFaq->pergunta && $dadosFaq->solucao) | ||
{ | ||
$verificaFaq = "select * from rs_faq where pergunta='$dadosFaq->pergunta'"; | ||
|
||
$verificaFaq = mysql_query($verificaFaq) or die('Erro: '.mysql_error()); | ||
|
||
if(!mysql_affected_rows() && empty($dadosFaq->idFaq)) | ||
{ | ||
if( $this->salvar($dadosFaq) ) | ||
{ | ||
return true; | ||
} | ||
} | ||
else | ||
{ | ||
if( $this->editar($dadosFaq) ) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
private function salvar($dadosFaq) | ||
{ | ||
$gravarDadosFaq = "insert into rs_faq set | ||
pergunta='$dadosFaq->pergunta', | ||
solucao='$dadosFaq->solucao' | ||
"; | ||
$gravarDadosFaq = mysql_query($gravarDadosFaq) or die('Erro: '.mysql_error()); | ||
|
||
if(mysql_affected_rows()) | ||
{ | ||
return true; | ||
} | ||
|
||
} | ||
|
||
|
||
private function editar($dadosFaq) | ||
{ | ||
$atualizaFaq = "update rs_faq set | ||
pergunta='$dadosFaq->pergunta', | ||
solucao='$dadosFaq->solucao' | ||
where id='$dadosFaq->id' | ||
"; | ||
$atualizaFaq = mysql_query($atualizaFaq) or die('Erro: '.mysql_error()); | ||
|
||
if(mysql_affected_rows()) | ||
{ | ||
return true; | ||
} | ||
|
||
|
||
} | ||
|
||
function remover($idRemover) | ||
{ | ||
$removeFaq = "delete from rs_faq where id='$idRemover'"; | ||
$removeFaq = mysql_query($removeFaq) or die('Erro: '.mysql_error()); | ||
|
||
if(mysql_affected_rows()) | ||
{ | ||
return true; | ||
} | ||
|
||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
include_once 'core/faq-core.php'; | ||
|
||
$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>'; | ||
$botao = 'Gravar alterações'; | ||
} | ||
|
||
$idFaq = isset($_GET['id_faq']) ? (int)$_GET['id_faq'] : '' ; | ||
|
||
$Faq = new Faq(); | ||
|
||
$dadosFaq = $Faq->detalhesFaq($idFaq); | ||
|
||
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( $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>"; | ||
} | ||
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>"; | ||
} | ||
} | ||
?> | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
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 | ||
} | ||
} | ||
} | ||
|
||
$ordenacaoBusca->campo = 'id'; | ||
$ordenacaoBusca->ordem = 'desc'; | ||
|
||
if( $dadosFaq = $Faq->obterListaFaq($ordenacaoBusca) ) | ||
{ | ||
?> | ||
|
||
<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; | ||
} | ||
?> | ||
<tr> | ||
<td> | ||
<?php echo (int)$dadosFaq->id ; ?> | ||
</td> | ||
<td> | ||
<?php echo $dadosFaq->pergunta ; ?> | ||
</td> | ||
<td> | ||
<?php echo $dadosFaq->solucao ; ?> | ||
</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?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 | ||
*/ | ||
|
||
|
||
function menuFAQ() | ||
{ | ||
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'); | ||
} | ||
|
||
// adding menu | ||
add_action('admin_menu', 'menuFAQ'); | ||
|
||
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')) | ||
{ | ||
@copy('../wp-content/plugins/faq/theme-pages/page-faq.php',$themePath.'/page-faq.php'); | ||
} | ||
|
||
?> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Schema para o plugin Perguntas e respostas | ||
* @version 1.0 | ||
* @since 1.0 | ||
*/ | ||
|
||
$faq = "CREATE TABLE IF NOT EXISTS `rs_faq` ( | ||
`id` INT UNSIGNED AUTO_INCREMENT, | ||
`pergunta` VARCHAR(255) COLLATE utf8_unicode_ci, | ||
`solucao` TEXT COLLATE utf8_unicode_ci, | ||
`imagem` VARCHAR(255) COLLATE utf8_unicode_ci, | ||
PRIMARY KEY (`id`) | ||
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; | ||
|
||
@mysql_query($faq); | ||
|
||
$popularTabela = "insert into rs_faq set pergunta='teste', solucao='esta é a solução', imagem=''"; | ||
for($cont = 0; $cont < 10; $cont++) | ||
{ | ||
//mysql_query($popularTabela) or die(mysql_error()); | ||
} | ||
|
||
//$limparTabela = "delete from rs_faq"; | ||
//@mysql_query($limparTabela); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Template Name: Faq | ||
* Description: Aqui será montado o layout para apresentação das perguntas e respostas | ||
* frequentes | ||
*/ | ||
|
||
include_once 'wp-content/plugins/faq/core/faq-core.php'; | ||
$Faq = new Faq(); | ||
|
||
$dadosFaq = $Faq->obterListaFaq(); | ||
|
||
get_header(); ?> | ||
<div class="meio clearfix"> | ||
<div class="conteudo-1005"> | ||
<div class="titulo-faq"> | ||
<h2>Perguntas e respostas</h2> | ||
</div> | ||
|
||
<div class="conteudo clearfix"> | ||
<?php | ||
|
||
if($dadosFaq) | ||
{ | ||
foreach($dadosFaq as $dadosFaq) | ||
{?> | ||
<div class="conteudo-faq clearfix"> | ||
<h2><?php echo ucfirst($dadosFaq->pergunta); ?></h2> | ||
<div class="resposta" > | ||
<?php echo $dadosFaq->solucao; ?> | ||
</div> | ||
|
||
<?php | ||
} | ||
} | ||
?> | ||
<div class="fio"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<?php get_footer(); ?> |