diff --git a/delibera_conf.php b/delibera_conf.php index f83b72e..60f27db 100644 --- a/delibera_conf.php +++ b/delibera_conf.php @@ -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'; @@ -76,8 +74,6 @@ function delibera_get_main_config($config = array()) { */ function delibera_conf_page() { - global $deliberaThemes; - $mensagem = ''; if ($_SERVER['REQUEST_METHOD']=='POST') { @@ -140,11 +136,6 @@ function delibera_conf_page() "content" => '', ); } - $rows[] = array( - "id" => "theme", - "label" => __('Tema', 'delibera'), - "content" => $deliberaThemes->getSelectBox($opt['theme']) . '
' . __('É 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'). '
', - ); $rows[] = array( "id" => "criar_pauta_pelo_front_end", "label" => __('Habilitar a criação de pautas pelo front-end?', 'delibera'), diff --git a/delibera_conf_themes.php b/delibera_conf_themes.php index eb2708b..f894f1c 100644 --- a/delibera_conf_themes.php +++ b/delibera_conf_themes.php @@ -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')); + } /** @@ -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'; } /** @@ -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'; } /** @@ -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; } /** @@ -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; } /** @@ -186,7 +101,7 @@ public function archiveTemplate($archiveTemplate) } else { - $archiveTemplate = $this->themeFilePath('archive-pauta.php'); + $archiveTemplate = self::themeFilePath('archive-pauta.php'); } } @@ -213,7 +128,7 @@ public function singleTemplate($singleTemplate) } else { - $singleTemplate = $this->themeFilePath('single-pauta.php'); + $singleTemplate = self::themeFilePath('single-pauta.php'); } } @@ -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')); } } } @@ -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')); } /** @@ -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 = ""; - - return $html; + if (get_post_type() == 'pauta') { + return self::themeFilePath('delibera_comments.php'); + } + + return $path; } public function checkPath($path) @@ -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'); diff --git a/delibera_filtros.php b/delibera_filtros.php index 5633310..fa11fb6 100644 --- a/delibera_filtros.php +++ b/delibera_filtros.php @@ -10,8 +10,6 @@ */ function delibera_filtros_gerar() { - global $deliberaThemes; - ?>comment_ID, $selecionados)) ? ' checked="checked" ' : ''; ?> /> -
+