Skip to content

Fix#117 #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions delibera_conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ function delibera_get_config() {
*/
function delibera_get_main_config($config = array()) {
$opt = array();
$opt['theme'] = plugin_dir_path(__FILE__)."/themes/generic";

$opt['criar_pauta_pelo_front_end'] = 'S';
$opt['representante_define_prazos'] = 'S';
$opt['dias_novo_prazo'] = '2';
Expand Down Expand Up @@ -76,8 +74,6 @@ function delibera_get_main_config($config = array()) {
*/
function delibera_conf_page()
{
global $deliberaThemes;

$mensagem = '';

if ($_SERVER['REQUEST_METHOD']=='POST') {
Expand Down Expand Up @@ -140,11 +136,6 @@ function delibera_conf_page()
"content" => '<input type="checkbox" name="plan_restriction" id="plan_restriction" value="S" '. ( htmlspecialchars_decode($opt['plan_restriction']) == "S" ? "checked='checked'" : "" ).'/>',
);
}
$rows[] = array(
"id" => "theme",
"label" => __('Tema', 'delibera'),
"content" => $deliberaThemes->getSelectBox($opt['theme']) . '<p class="description">' . __('É possível criar um tema para o Delibera criando uma pasta com o nome "delibera" dentro da pasta do tema atual do Wordpress. Esse tema aparecerá nesta listagem com o nome do tema atual.', 'delibera'). '</p>',
);
$rows[] = array(
"id" => "criar_pauta_pelo_front_end",
"label" => __('Habilitar a criação de pautas pelo front-end?', 'delibera'),
Expand Down
231 changes: 43 additions & 188 deletions delibera_conf_themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,20 @@
* Inicializa gerenciamento dos temas do plugin.
*/

/**
* Controla os distintos temas do Delibera disponíveis.
*
* Os temas do Delibera podem ser salvos em dois lugares distintos.
* Na pasta themes dentro da pasta do plugin. Cada tema deve estar dentro
* de uma sub pasta cujo o nome é o nome do tema. Um tema do Delibera
* também pode ser salvo dentro de uma pasta chamada delibera dentro
* do tema atual do Wordpress.
* @package Tema
*/
class DeliberaThemes
{
/**
* Diretório onde ficam os temas
* dentro do plugin
* @var string
*/
public $baseDir;

/**
* URL do diretório onde ficam
* os temas dentro do plugin
* @var string
*/
public $baseUrl;

/**
* Caminho para o diretório
* do tema padrão
* @var string
*/
public $defaultThemePath;

/**
* URL para o diretório do
* tema padrão
* @var string
*/
public $defaultThemeUrl;

/**
* Caminho para o tema do Delibera
* dentro do tema atual do WP.
* @var string
*/
public $wpThemePath;
// PHP 5.3 and later:
namespace Delibera;

/**
* Url para o diretório do tema do Delibera
* dentro do tema atual do WP
* @var string
*/
public $wpThemeUrl;

/**
* Nome do tema atual do Wordpress
* @var string
*/
public $wpThemeName;

/**
* Define variáveis obrigatórias para funcionamento correto
*/
class Themes
{
function __construct()
{
$this->baseDir = __DIR__ . '/themes/';
$this->baseUrl = plugins_url('/delibera/themes/');
$this->defaultThemePath = $this->baseDir . 'generic/';
$this->defaultThemeUrl = $this->baseUrl . 'generic/';

$this->wpThemePath = get_stylesheet_directory() . '/delibera';
$this->wpThemeUrl = get_stylesheet_directory_uri() . '/delibera';
$this->wpThemeName = wp_get_theme()->get_stylesheet();
add_filter('archive_template', array($this, 'archiveTemplate'));
add_filter('single_template', array($this, 'singleTemplate'));
add_action('admin_print_styles', array($this, 'adminPrintStyles'));
add_action('wp_enqueue_scripts', array($this, 'publicStyles'), 100);

add_filter('comments_template', array($this, 'commentsTemplate'));

}

/**
Expand All @@ -86,21 +27,9 @@ function __construct()
* @param string $themeName
* @return string
*/
public function getThemeDir($themeName = '')
public static function getThemeDir($themeName = '')
{
if (!empty($themeName)) {
$themePath = $this->baseDir . $themeName;
} else {
$conf = delibera_get_config();
$themePath = $conf['theme'];
$themePath = $this->checkPath($themePath);
}

if (file_exists($themePath)) {
return $themePath;
} else {
return $this->defaultThemePath;
}
return plugin_dir_path(__FILE__).'/themes/generic';
}

/**
Expand All @@ -109,22 +38,9 @@ public function getThemeDir($themeName = '')
*
* @return string
*/
public function getThemeUrl()
public static function getThemeUrl()
{
$conf = delibera_get_config();

if (file_exists($conf['theme'])) {
// TODO: melhorar a separacao entre tema distribuido junto com o plugin e tema do delibera dentro do tema do wp
if (strpos($conf['theme'], '/wp-content/themes') === false) {
// tema distribuido junto com o plugin
return $this->baseUrl . basename($conf['theme']);
} else {
// tema dentro do tema atual do wp
return $this->wpThemeUrl;
}
} else {
return $this->defaultThemeUrl;
}
return plugin_dir_url(__FILE__).'/themes/generic';
}

/**
Expand All @@ -136,15 +52,15 @@ public function getThemeUrl()
* @param string $file_name
* @return string
*/
public function themeFilePath($fileName)
public static function themeFilePath($fileName)
{
$filePath = $this->getThemeDir() . '/' . $fileName;
$filePath = self::getThemeDir() . '/' . $fileName;

if (file_exists($filePath)) {
if (file_exists($filePath))
{
return $filePath;
} else {
return $this->defaultThemePath . $fileName;
}
return false;
}

/**
Expand All @@ -155,15 +71,14 @@ public function themeFilePath($fileName)
* @param string $file_name
* @return string
*/
public function themeFileUrl($fileName)
public static function themeFileUrl($fileName)
{
$filePath = $this->getThemeDir() . '/' . $fileName;
$filePath = self::getThemeDir() . '/' . $fileName;

if (file_exists($filePath)) {
return $this->getThemeUrl() . '/' . $fileName;
} else {
return $this->defaultThemeUrl . $fileName;
return self::getThemeUrl() . '/' . $fileName;
}
return false;
}

/**
Expand All @@ -186,7 +101,7 @@ public function archiveTemplate($archiveTemplate)
}
else
{
$archiveTemplate = $this->themeFilePath('archive-pauta.php');
$archiveTemplate = self::themeFilePath('archive-pauta.php');
}
}

Expand All @@ -213,7 +128,7 @@ public function singleTemplate($singleTemplate)
}
else
{
$singleTemplate = $this->themeFilePath('single-pauta.php');
$singleTemplate = self::themeFilePath('single-pauta.php');
}
}

Expand All @@ -237,7 +152,7 @@ public function publicStyles()
}
else
{
wp_enqueue_style('delibera_style', $this->themeFileUrl('delibera_style.css'));
wp_enqueue_style('delibera_style', self::themeFileUrl('delibera_style.css'));
}
}
}
Expand All @@ -250,7 +165,7 @@ public function publicStyles()
*/
public function adminPrintStyles()
{
wp_enqueue_style('delibera_admin_style', $this->themeFileUrl('delibera_admin.css'));
wp_enqueue_style('delibera_admin_style', self::themeFileUrl('delibera_admin.css'));
}

/**
Expand All @@ -268,52 +183,25 @@ public function archiveLoop()
}
else
{
load_template($this->themeFilePath('delibera-loop-archive.php'), true);
load_template(self::themeFilePath('delibera-loop-archive.php'), true);
}
}

/**
* Retorna um array com os temas disponíveis.
* Usa o template de comentário do Delibera
* no lugar do padrão do Wordpress para as pautas
*
* @return array
*/
public function getAvailableThemes()
{
$themes = array();
$dirs = glob($this->baseDir . '*', GLOB_ONLYDIR);

foreach ($dirs as $dir) {
$themes[$dir] = basename($dir);
}

// adiciona o tema do delibera de dentro do tema atual do wp se um existir
if (file_exists($this->wpThemePath)) {
$themes[$this->wpThemePath] = $this->wpThemeName;
}

return $themes;
}

/**
* Gera o select box com os temas disponíveis
* para a interface de admin do Delibera.
*
* @param string $currentTheme o tema atual
* @param string $path
* @return string
* @package Tema
*/
public function getSelectBox($currentTheme)
function commentsTemplate($path)
{
$themes = $this->getAvailableThemes();

$html = "<select name='theme' id='theme'>";

foreach ($themes as $themePath => $themeName) {
$html .= "<option value='{$themePath}'" . selected($themePath, $currentTheme, false) . ">{$themeName}</option>";
}

$html .= "</select>";

return $html;
if (get_post_type() == 'pauta') {
return self::themeFilePath('delibera_comments.php');
}

return $path;
}

public function checkPath($path)
Expand All @@ -326,43 +214,10 @@ public function checkPath($path)
return $path;
}
}
global $deliberaThemes;
$deliberaThemes = new DeliberaThemes;

add_filter('archive_template', array($deliberaThemes, 'archiveTemplate'));
add_filter('single_template', array($deliberaThemes, 'singleTemplate'));
add_action('admin_print_styles', array($deliberaThemes, 'adminPrintStyles'));
add_action('wp_enqueue_scripts', array($deliberaThemes, 'publicStyles'), 100);
global $DeliberaThemes;
$DeliberaThemes = new \Delibera\Themes();

// inclui arquivos específicos do tema
require_once($deliberaThemes->themeFilePath('functions.php'));

if(file_exists(get_stylesheet_directory()."/delibera_comments_template.php"))
{
require_once(get_stylesheet_directory()."/delibera_comments_template.php");
}
else
{
require_once($deliberaThemes->themeFilePath('delibera_comments_template.php'));
}
require_once(\Delibera\Themes::themeFilePath('functions.php'));
require_once(\Delibera\Themes::themeFilePath('delibera_comments_template.php'));


/**
* Usa o template de comentário do Delibera
* no lugar do padrão do Wordpress para as pautas
*
* @param string $path
* @return string
* @package Tema
*/
function delibera_comments_template($path)
{
global $deliberaThemes;

if (get_post_type() == 'pauta') {
return $deliberaThemes->themeFilePath('delibera_comments.php');
}

return $path;
}
add_filter('comments_template', 'delibera_comments_template');
10 changes: 4 additions & 6 deletions delibera_filtros.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*/
function delibera_filtros_gerar()
{
global $deliberaThemes;

?>
<div id="filtro-horizontal">
<h4><?php _e( 'Filtros de conteúdo', 'delibera' ); ?><span id="delibera-filtros-archive-mostrar" onclick="delibera_filtros_archive_mostrar()" class="delibera-filtros-mostrar" style="display: none" title="Mostrar Filtros" ></span><span id="delibera-filtros-archive-esconder" onclick="delibera_filtros_archive_esconder()" class="delibera-filtros-esconder" title="Esconder Filtros"></span></h4>
Expand Down Expand Up @@ -60,8 +58,8 @@ function overlay_filtro(id)
var html = '<div id="'+id+'">';
<?php

$iloader = $deliberaThemes->getThemeDir() . "/images/ajax-loader.gif";
$iloader_padrao = $deliberaThemes->getThemeUrl() . "/images/ajax-loader.gif";
$iloader = \Delibera\Themes::getThemeDir() . "/images/ajax-loader.gif";
$iloader_padrao = \Delibera\Themes::getThemeUrl() . "/images/ajax-loader.gif";
if(file_exists($iloader))
{
?>
Expand Down Expand Up @@ -219,7 +217,7 @@ function delibera_filtros_get_filtros($tax, $value = false, $linha = "<br/>")
*/
function delibera_filtros_archive_callback()
{
global $wp_query, $deliberaThemes;
global $wp_query, $DeliberaThemes;

$action = new stdClass();
$action->canQuery = true;
Expand All @@ -234,7 +232,7 @@ function delibera_filtros_archive_callback()
query_posts($args);
?>
<div id="lista-de-pautas">
<?php $deliberaThemes->archiveLoop(); // Chama o loop do arquivo ?>
<?php $DeliberaThemes->archiveLoop(); // Chama o loop do arquivo ?>

<div id="nav-below" class="navigation">
<?php if ( function_exists( 'wp_pagenavi' ) ) wp_pagenavi(); ?>
Expand Down
Loading