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; - ?>

@@ -60,8 +58,8 @@ function overlay_filtro(id) var html = '
'; 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)) { ?> @@ -219,7 +217,7 @@ function delibera_filtros_get_filtros($tax, $value = false, $linha = "
") */ function delibera_filtros_archive_callback() { - global $wp_query, $deliberaThemes; + global $wp_query, $DeliberaThemes; $action = new stdClass(); $action->canQuery = true; @@ -234,7 +232,7 @@ function delibera_filtros_archive_callback() query_posts($args); ?>
- archiveLoop(); // Chama o loop do arquivo ?> + archiveLoop(); // Chama o loop do arquivo ?>
archiveLoop(); + global $DeliberaThemes; + $DeliberaThemes->archiveLoop(); global $wp_query; $big = 99999999; // need an unlikely integer diff --git a/themes/creta/delibera_comments_template.php b/themes/creta/delibera_comments_template.php index a6d2e9b..23dcb9f 100644 --- a/themes/creta/delibera_comments_template.php +++ b/themes/creta/delibera_comments_template.php @@ -21,7 +21,7 @@ class Delibera_Walker_Comment extends Walker_Comment */ function start_el(&$output, $comment, $depth = 0, $args = array(), $current_object_id = 0) { - global $deliberaThemes; + global $DeliberaThemes; $depth++; $GLOBALS['comment_depth'] = $depth; $args['avatar_size'] = '85'; @@ -179,7 +179,7 @@ function start_el(&$output, $comment, $depth = 0, $args = array(), $current_obje

comment_ID, $selecionados)) ? ' checked="checked" ' : ''; ?> /> - +

@@ -14,7 +14,7 @@ // chama o formulário de nova pauta if (is_user_logged_in()) { - include $deliberaThemes->themeFilePath('form-nova-pauta.php'); + include $DeliberaThemes->themeFilePath('form-nova-pauta.php'); } ?> diff --git a/themes/creta/functions.php b/themes/creta/functions.php index fa865ea..5ee55f9 100644 --- a/themes/creta/functions.php +++ b/themes/creta/functions.php @@ -303,17 +303,17 @@ function delibera_comment_form($defaults) add_filter('comment_form_defaults', 'delibera_comment_form'); add_action('wp_enqueue_scripts', function() { - global $deliberaThemes, $post; + global $DeliberaThemes, $post; if (get_post_type() == 'pauta') { $situacao = delibera_get_situacao($post->ID); - wp_enqueue_script('creta', $deliberaThemes->getThemeUrl() . '/js/creta.js', array('delibera')); + wp_enqueue_script('creta', $DeliberaThemes->getThemeUrl() . '/js/creta.js', array('delibera')); if ($situacao->slug == 'relatoria') { - wp_enqueue_script('creta-relatoria', $deliberaThemes->getThemeUrl() . '/js/creta-relatoria.js', array('delibera')); + wp_enqueue_script('creta-relatoria', $DeliberaThemes->getThemeUrl() . '/js/creta-relatoria.js', array('delibera')); } else if ($situacao->slug == 'emvotacao') { - wp_enqueue_script('creta-votacao', $deliberaThemes->getThemeUrl() . '/js/creta-votacao.js', array('delibera')); + wp_enqueue_script('creta-votacao', $DeliberaThemes->getThemeUrl() . '/js/creta-votacao.js', array('delibera')); } } }); diff --git a/themes/creta/single-pauta.php b/themes/creta/single-pauta.php index bf7bb2b..4ba9e4f 100644 --- a/themes/creta/single-pauta.php +++ b/themes/creta/single-pauta.php @@ -15,8 +15,8 @@ } else { - global $deliberaThemes; - load_template($deliberaThemes->themeFilePath('content-pauta.php'), true); + global $DeliberaThemes; + load_template($DeliberaThemes->themeFilePath('content-pauta.php'), true); } ?> diff --git a/themes/generic/archive-pauta.php b/themes/generic/archive-pauta.php index fcd404f..cfe0daf 100644 --- a/themes/generic/archive-pauta.php +++ b/themes/generic/archive-pauta.php @@ -18,8 +18,8 @@
archiveLoop(); + global $DeliberaThemes; + $DeliberaThemes->archiveLoop(); $default_flow = isset($options_plugin_delibera['delibera_flow']) ? $options_plugin_delibera['delibera_flow'] : array(); $default_flow = apply_filters('delibera_flow_list', $default_flow); diff --git a/themes/generic/delibera_nova_pauta.php b/themes/generic/delibera_nova_pauta.php index f3ab920..6d0005b 100644 --- a/themes/generic/delibera_nova_pauta.php +++ b/themes/generic/delibera_nova_pauta.php @@ -1,17 +1,18 @@ - -
-
- themeFilePath('form-nova-pauta.php'); +
+
+ +
diff --git a/themes/generic/functions.php b/themes/generic/functions.php index 4634fa3..eea9a9b 100644 --- a/themes/generic/functions.php +++ b/themes/generic/functions.php @@ -282,18 +282,18 @@ function delibera_comment_form($defaults) add_action('wp_enqueue_scripts', function() { - if (get_post_type() == 'pauta') - { - global $deliberaThemes, $post; + if (get_post_type() == 'pauta') + { + global $DeliberaThemes, $post; - $situacao = delibera_get_situacao($post->ID); - wp_enqueue_script('atenas', $deliberaThemes->getThemeUrl() . '/js/atenas.js', array('jquery')); + $situacao = delibera_get_situacao($post->ID); + wp_enqueue_script('atenas', \Delibera\Themes::getThemeUrl() . '/js/atenas.js', array('jquery')); - if ($situacao->slug == 'relatoria') - { + if ($situacao->slug == 'relatoria') + { wp_enqueue_script('delibera_relatoria_js', plugin_dir_url(__FILE__) . '/../../../js/delibera_relatoria.js', array('jquery')); - } - } + } + } }); /** @@ -376,7 +376,7 @@ function delibera_gerar_curtir($ID, $type ='pauta') $num_curtiu = intval($type == 'pauta' || $type == 'post' ? get_post_meta($ID, 'delibera_numero_curtir', true) : get_comment_meta($ID, 'delibera_numero_curtir', true)); $situacao = delibera_get_situacao($postID); - global $deliberaThemes; + global $DeliberaThemes; $html = '
'; @@ -453,7 +453,7 @@ function delibera_gerar_discordar($ID, $type ='pauta') $ndiscordou = intval($type == 'pauta' || $type == 'post' ? get_post_meta($ID, 'delibera_numero_discordar', true) : get_comment_meta($ID, 'delibera_numero_discordar', true)); $situacao = delibera_get_situacao($postID); - global $deliberaThemes; + global $DeliberaThemes; $html = '
'; if ($ndiscordou > 0) { $html .= '' . $ndiscordou .''; diff --git a/themes/generic/page-author-pautas.php b/themes/generic/page-author-pautas.php index 7dc065b..f66966d 100644 --- a/themes/generic/page-author-pautas.php +++ b/themes/generic/page-author-pautas.php @@ -69,8 +69,8 @@ ?>
archiveLoop(); + global $DeliberaThemes; + $DeliberaThemes->archiveLoop(); //pagination hack $big = 99999999; // need an unlikely integer diff --git a/themes/generic/single-pauta.php b/themes/generic/single-pauta.php index 6d8d459..1f94098 100644 --- a/themes/generic/single-pauta.php +++ b/themes/generic/single-pauta.php @@ -14,8 +14,8 @@ } else { - global $deliberaThemes; - load_template($deliberaThemes->themeFilePath('content-pauta.php'), true); + global $DeliberaThemes; + load_template($DeliberaThemes->themeFilePath('content-pauta.php'), true); } ?>