diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..bca85c2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true +indent_style = tab +indent_size = 2 +charset = utf-8 diff --git a/.gitignore b/.gitignore index e00540d..360f4af 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ Thumbs.db .project .settings .buildpath - +.idea/* +*~ diff --git a/README.md b/README.md index 9a9acca..7ab1631 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Stories in Ready](https://badge.waffle.io/redelivre/delibera.png?label=ready&title=Ready)](https://waffle.io/redelivre/delibera) + +[![Build Status](http://jenkins.beta.redelivre.org.br:8081/buildStatus/icon?job=Beta%20Delibera)](https://github.com/redelivre/delibera) Delibera ======== @@ -18,10 +21,33 @@ Como usar? ========== Tudo o que você precisa para rodar este plugin é ter uma instalação de WordPress funcionando e saber como instalar um plugin. Para mais informações veja a [documentação](https://github.com/redelivre/delibera/wiki/Home). - + +Acessando pautas: + +Post type = pauta + +Exemplo sem links customizados: +http://www.exemplo.com/?post_type=pauta + +Exemplo com links customizados: +http://www.exemplo.com/pauta/ + Como Colaborar? =============== Existem algumas maneiras de colaborar com o desenvolvimento deste plugin. Se você é um usuário, você pode ter encontrado um problema (bug) ou ter tido alguma idéia de uma nova funcionalidade. Em qualquer um dos casos, entre em contato com os desenvolvedores criando uma [issue](https://github.com/redelivre/delibera/issues). Se você é um desenvolvedor, sinta-se livre para fazer um fork e contribuir com o desenvolvimento. Se quiser, dê uma olhada se você pode resolver alguma das [issues abertas](https://github.com/redelivre/delibera/issues). + + +### Situações possíveis da pauta + +| Slugs | Module | Descrição | +| --------------- |:---------------:| -----:| +| validacao | Mod. validation | Proposta de pauta, precisa ser validada para ser continuar no fluxo, comentário é apenas se valida | +| naovalidada | Mod. validation | Proposta recusada por prazo sem minimo de validação ou forçada pelo admin | +| discussao | Mod. Discussion | Pauta em discussão, aceita comentários do tipo padrão ou encaminhamento | +| eleicao_relator | Mod. rapporteur | Pauta que precisa de relator, mas antes o relator precisa ser eleito (não implementado) | +| relatoria | Mod. rapporteur | o Relator vai editar os encaminhamentos para criar opções válidas para votação | +| emvotacao | Mod. vote | Pauta em votação, aqui o comentário é um voto simples | +| comresolucao | Mod. result | Pauta chegou ao fim, apresentar resultado | diff --git a/admin/css/flow.css b/admin/css/flow.css new file mode 100644 index 0000000..220bab5 --- /dev/null +++ b/admin/css/flow.css @@ -0,0 +1,81 @@ +@CHARSET "UTF-8"; + + +.delibera-flow-panel.delibera-flow-panel-post { + display: block; + float: none; + overflow: hidden; + position: relative; +} + +.delibera-flow-panel .delibera-flow-column{ + width:49%; + margin-right:.5%; + min-height:150px; + background:#fff; + float:left; +} +.delibera-flow-panel .delibera-flow-column .dragbox{ + margin:5px 2px 20px; + background:#fff; + position:"relative"; + border:1px solid #946553; + -moz-border-radius:5px; + -webkit-border-radius:5px; +} +#poststuff .delibera-flow-panel .delibera-flow-column .dragbox h2, +.delibera-flow-panel .delibera-flow-column .dragbox h2 { + margin:0; + font-size:12px; + background:#946553; + color:#fff; + border-bottom:1px solid #946553; + font-family:Verdana; + cursor:move; + padding:5px; +} + +.delibera-flow-panel .dragbox-content{ + background:#fff; + min-height:100px; margin:5px; + font-family:'Lucida Grande', Verdana; font-size:0.8em; line-height:1.5em; +} +.delibera-flow-panel .delibera-flow-column .placeholder{ + background: #EED5B7; + border:1px dashed #946553; +} + +.delibera-flow-panel .opIcons +{ +background-image: url('../images/iconSpirite.gif')!important; +background-repeat: no-repeat; +float:right; +height:13px; +width:13px; +margin:0px 2px; +} + +.delibera-flow-panel .maxmin +{ + background-position:-26px 1px; + cursor: pointer; +} + +.delibera-flow-panel .delete +{ + background-position:-269px center; + padding-top:1px; + cursor: pointer; +} + +.delibera-flow-panel-config #delibera-flow-column2 .ui-sortable-handle span:last-child { + display: none; +} + +.delibera-flow-panel-config #delibera-flow-column2 .dragbox-content { + display: none; +} + +.delibera-flow-panel-post #delibera-flow-column1 h2 span { + display: none; +} diff --git a/admin/delibera_admin_functions.php b/admin/delibera_admin_functions.php new file mode 100644 index 0000000..4089dbc --- /dev/null +++ b/admin/delibera_admin_functions.php @@ -0,0 +1,268 @@ +post_type == 'pauta' && $current_screen->id == "edit-pauta") { + ?> + + current_action(); + + switch($action) { + case 'set_prazodiscussao': + check_admin_referer('bulk-posts'); + + $pautas_ids = $_REQUEST['post']; + $novo_prazo_discussao = $_REQUEST['novo_prazo_discussao']; + $inovo_prazo_discussao = DateTime::createFromFormat('d/m/Y', $novo_prazo_discussao)->getTimestamp(); + $pautas_afetadas = 0; + + foreach($pautas_ids as $pauta_id) { + + delibera_set_novo_prazo_discussao_relatoria($pauta_id, $inovo_prazo_discussao, delibera_get_config()); + + $pautas_afetadas++; + } + + $sendback = admin_url( "edit.php?post_type=pauta&pautas_afetadas=$pautas_afetadas&novo_prazo=$novo_prazo_discussao"); + + wp_redirect($sendback); + + exit(); + + break; + } +} + +add_action('load-edit.php', 'delibera_custom_bulk_action'); + +/** + * Função que exibe a mensagem de confirmação da alteração em massa + * + */ +function delibera_custom_bulk_admin_notices() { + + $current_screen = get_current_screen(); + + if($current_screen->post_type == 'pauta' && $current_screen->id == "edit-pauta" && + isset($_REQUEST['pautas_afetadas']) && (int) $_REQUEST['pautas_afetadas']) { + $mensagem = sprintf( '%s pautas definidas para o prazo de %s.', number_format_i18n( $_REQUEST['pautas_afetadas']), $_REQUEST['novo_prazo'] ); + echo "

{$mensagem}

"; + } +} + +add_action('admin_notices', 'delibera_custom_bulk_admin_notices'); + +/** + * + * Comentário na tela de Edição na administração + * @param WP_comment $comment + * + * @property add_meta_boxes_comment + */ +function delibera_edit_comment($comment) +{ + if(get_post_type($comment->comment_post_ID) == "pauta") + { + $tipo = get_comment_meta($comment->comment_ID, "delibera_comment_tipo", true); + switch ($tipo) + { + case 'validacao': + { + $validacao = get_comment_meta($comment->comment_ID, "delibera_validacao", true); + $sim = ($validacao == "S" ? true : false); + ?> +
+ + + + + +
+ + comment_ID, "delibera_comment_tipo", true); + $checked = $tipo == "discussao" ? "" : ' checked="checked" '; + ?> + + + + + + ID, "tema"); + break; + case 'situacao': + echo delibera_get_situacao($post->ID)->name; + break; + case 'prazo': + $data = ""; + $prazo = \Delibera\Flow::getDeadlineDays($post->ID, $data); + if($prazo <= -1) + { + echo __('Encerrado', 'delibera'); + } + elseif($data != "") + { + echo $data." (".$prazo.($prazo == 1 ? __(" dia", 'delibera') : __(" dias", 'delibera')).")"; + } + break; + } + +} + +add_action('manage_posts_custom_column', 'delibera_post_custom_column'); + +/** + * Inclui novas ações na lista do wp admin + * @param $columns + * @param $post + * + */ +function delibera_admin_list_options($actions, $post) +{ + if(get_post_type($post) == 'pauta' && $post->post_status == 'publish' ) + { + if(current_user_can('forcar_prazo')) + { + $url = 'admin.php?action=delibera_forca_fim_prazo_action&post='.$post->ID; + $url = wp_nonce_url($url, 'delibera_forca_fim_prazo_action'.$post->ID); + $actions['forcar_prazo'] = ''.__('Forçar fim de prazo','delibera').''; + + $url = 'admin.php?action=delibera_nao_validado_action&post='.$post->ID; + $url = wp_nonce_url($url, 'delibera_nao_validado_action'.$post->ID); + $actions['nao_validado'] = ''.__('Invalidar','delibera').''; + + } + if(delibera_get_situacao($post->ID)->slug == 'naovalidada' && current_user_can('delibera_reabrir_pauta')) + { + $url = 'admin.php?action=delibera_reabrir_pauta_action&post='.$post->ID; + $url = wp_nonce_url($url, 'delibera_reabrir_pauta_action'.$post->ID); + $actions['reabrir'] = ''.__('Reabrir','delibera').''; + } + + } + + //print_r(_get_cron_array()); + return $actions; +} + +add_filter('post_row_actions','delibera_admin_list_options', 10, 2); + +/** + * Preenche lista de valores disponíveis para filtro da listagem do WP admin + * + */ +function delibera_restrict_listings() +{ + global $typenow; + global $wp_query; + if ($typenow=='pauta') + { + $taxonomy = 'situacao'; + $situacao_taxonomy = get_taxonomy($taxonomy); + wp_dropdown_categories(array( + 'show_option_all' => sprintf(__('Mostrar todas as %s','delibera'),$situacao_taxonomy->label), + 'taxonomy' => $taxonomy, + 'name' => 'situacao', + 'orderby' => 'id', + 'selected' => isset($_REQUEST['situacao']) ? $_REQUEST['situacao'] : '', + 'hierarchical' => false, + 'depth' => 1, + 'show_count' => true, // This will give a view + 'hide_empty' => true, // This will give false positives, i.e. one's not empty related to the other terms. + )); + } +} +add_action('restrict_manage_posts','delibera_restrict_listings'); \ No newline at end of file diff --git a/admin/delibera_conf_permission.php b/admin/delibera_conf_permission.php new file mode 100644 index 0000000..3f47bf5 --- /dev/null +++ b/admin/delibera_conf_permission.php @@ -0,0 +1,307 @@ +roleList = array( + array( + 'id' => 'delete_pautas', + 'label' => __('remover pautas','delibera'), + ), + array( + 'id' => 'delete_private_pautas', + 'label' => __('remover pautas privadas','delibera'), + ), + array( + 'id' => 'edit_pauta', + 'label' => __('editar pauta','delibera'), + ), + array( + 'id' => 'edit_pautas', + 'label' => __('editar multiplas pautas','delibera'), + ), + array( + 'id' => 'edit_private_pautas', + 'label' => __('editar multiplas pautas privadas','delibera'), + ), + array( + 'id' => 'publish_pautas', + 'label' => __('publicar pautas','delibera'), + ), + array( + 'id' => 'read_pauta', + 'label' => __('visualizar pautas','delibera'), + ), + array( + 'id' => 'read_private_pautas', + 'label' => __('visualizar pautas privadas','delibera'), + ), + array( + 'id' => 'delete_published_pautas', + 'label' => __('remover pautas publicadas','delibera'), + ), + array( + 'id' => 'forcar_prazo', + 'label' => __('forcar o final de prazo','delibera'), + ), + array( + 'id' => 'delibera_reabrir_pauta', + 'label' => __('reabrir pauta','delibera'), + ), + array( + 'id' => 'edit_published_pautas', + 'label' => __('editar multiplas pautas publicadas','delibera'), + ), + array( + 'id' => 'edit_published_pauta', + 'label' => __('editar pauta publicada','delibera'), + ), + array( + 'id' => 'edit_encaminhamento', + 'label' => __('editar encaminhamentos','delibera'), + ), + array( + 'id' => 'votar', + 'label' => __('votar','delibera'), + ), + array( + 'id' => 'relatoria', + 'label' => __('fazer relatoria','delibera'), + ), + array( + 'id' => 'edit_others_pautas', + 'label' => __('editar multiplas pautas de outras pessoas','delibera'), + ), + array( + 'id' => 'edit_others_pauta', + 'label' => __('editar pauta de outras pessoas','delibera'), + ), + array( + 'id' => 'delete_others_pautas', + 'label' => __('remover multiplas pautas de outras pessoas','delibera'), + ), + array( + 'id' => 'manage_tema_term', + 'label' => __('gerenciar temas','delibera'), + ), + array( + 'id' => 'edit_tema_term', + 'label' => __('editar temas','delibera'), + ), + array( + 'id' => 'delete_tema_term', + 'label' => __('remover temas','delibera'), + ), + array( + 'id' => 'assign_tema_term', + 'label' => __('atribuir temas','delibera'), + ), + array( + 'id' => 'manage_delibera_cat_term', + 'label' => __('gerenciar categorias','delibera'), + ), + array( + 'id' => 'edit_delibera_cat_term', + 'label' => __('editar categorias','delibera'), + ), + array( + 'id' => 'delete_delibera_cat_term', + 'label' => __('remover categorias','delibera'), + ), + array( + 'id' => 'assign_delibera_cat_term', + 'label' => __('atribuir categorias','delibera'), + ), + ); + add_action('init', array($this, 'admin_init')); + add_action( 'registered_taxonomy', array($this, 'setTaxonomyCaps'), 10, 3 ); + } + + public function admin_init() + { + add_action('delibera_menu_itens', array($this, 'addMenu')); + } + + public function addMenu($base_page) + { + add_submenu_page($base_page, __('Delibera Permissões','delibera'),__('Delibera Permissões','delibera'), 'manage_options', 'delibera-perm', array($this, 'confPage')); + } + + public function confPage() + { + if ($_SERVER['REQUEST_METHOD']=='POST') + { + if (!current_user_can('manage_options')) + { + die(__('Você não pode editar as configurações do delibera.','delibera')); + } + check_admin_referer('delibera-permission-nonce'); + $this->save(); + } + $this->html(); + } + + /** + * * Copied from Sendpress ** + */ + function str_lreplace($search, $replace, $subject) + { + $pos = strrpos($subject, $search); + + if($pos !== false) + { + $subject = substr_replace($subject, $replace, $pos, strlen($search)); + } + + return $subject; + } + + function save() + { + foreach($this->get_editable_roles() as $role => $role_name) + { + if(is_super_admin() || $role != 'administrator') + { + $saverole = get_role($role); + foreach ($this->roleList as $rolearray) + { + if( isset($_POST[$role . "_{$rolearray['id']}"] )) + { + $saverole->add_cap( $rolearray['id']); + } + else + { + $saverole->remove_cap($rolearray['id']); + } + } + } + } + } + + function GenerateCheckbox($id, $role, $echo = false, $label = "", $checked = '') + { + $listrole = get_role(sanitize_title($role)); + if($listrole->has_cap($id)) + { + $checked = 'checked'; + } + $output = " + + ". + ''.$label.''. + "" + ; + if($echo) echo $output; + return $output; + } + + function html() + { + $roles = array(); + foreach ($this->roleList as $cap) + { + foreach($this->get_editable_roles() as $role => $role_name) + { + if(is_super_admin() || $role != 'administrator') + { + if(!array_key_exists($cap['label'], $roles)) $roles[$cap['label']] = array(); + $roles[$cap['label']][$role] = $cap['id']; + } + } + } + $header = reset($roles); + //echo '
';print_r($roles);die();
+		?>
+		
+ +

+ + '; + + foreach (array_keys($header) as $head) + { + echo ''; + } + echo ''; + foreach($roles as $rolelabel => $rolelist) + { + echo ''; + foreach ($rolelist as $group => $roleid) + { + $this->GenerateCheckbox($roleid, $group,true); + //echo '
';print_r($group);print_r($roleid);die();
+					}
+					echo '
'; + } + echo "
 '.$head.'
'.$rolelabel.'
"; + /* + * echo "
";
+				 * foreach ($this->get_editable_roles() as $role)
+				 * {
+				 * if($role['name'] != 'Administrator'){
+				 * print_r($role);
+				 * }
+				 * }
+				 * echo "
"; + */ + ?> + + +
security_check(); + global $wp_roles; + + if(! isset($wp_roles)) + $wp_roles = new WP_Roles(); + + return $wp_roles->get_role($role); + } + + function get_editable_roles() + { + // $this->security_check(); + global $wp_roles; + + if(! isset($wp_roles)) + $wp_roles = new WP_Roles(); + + $all_roles = $wp_roles->get_names(); + $editable_roles = apply_filters('editable_roles', $all_roles); + + return $all_roles; + } + /*** End Copied from Sendpress ***/ + + public function setTaxonomyCaps( $taxonomy, $object_type, $args ) + { + global $wp_taxonomies; + if ( 'tema' == $taxonomy && ( ( is_string($object_type) && 'pauta' == $object_type ) || (is_array($object_type) && in_array('pauta', $object_type) ) ) ) + { + $wp_taxonomies[ 'category' ]->cap->manage_terms = 'manage_delibera_cat_term'; + $wp_taxonomies[ 'category' ]->cap->edit_terms = 'edit_delibera_cat_term'; + $wp_taxonomies[ 'category' ]->cap->delete_terms = 'delete_delibera_cat_term'; + $wp_taxonomies[ 'category' ]->cap->assign_terms = 'assign_delibera_cat_term'; + } + } + +} + +$DeliberaConfPermission = new \Delibera\Conf\Permission(); diff --git a/admin/delibera_cron.php b/admin/delibera_cron.php new file mode 100644 index 0000000..b3aa308 --- /dev/null +++ b/admin/delibera_cron.php @@ -0,0 +1,230 @@ +getTimestamp(); + + $exec = 0; + foreach ($crons as $key => $values) + { + if($key <= $now) + { + foreach ($values as $value) + { + $exec++; + try + { + if(is_array($value['call_back'])) + { + if(method_exists($value['call_back'][0], $value['call_back'][1])) + { + call_user_func($value['call_back'], $value['args']); + } + } + else + { + if(function_exists($value['call_back'])) + { + call_user_func($value['call_back'], $value['args']); + } + } + } + catch (Exception $e) + { + $error = __('Erro no cron Delibera: ','delibera').$e->getMessage()."\n".$e->getCode()."\n".$e->getTraceAsString()."\n".$e->getLine()."\n".$e->getFile(); + wp_mail("jacson@ethymos.com.br", get_bloginfo('name'), $error); + file_put_contents('/tmp/delibera_cron.log', $error, FILE_APPEND); + } + } + } + else + { + $new_crons[$key] = $values; + } + } + update_option('delibera-cron', $new_crons); + + //wp_mail("jacson@ethymos.com.br", get_bloginfo('name'),"Foram executadas $exec tarefa(s)"); + } + + /** + * Registry a cron event check hourly + */ + function registry() + { + if ( !wp_next_scheduled( 'admin_action_delibera_cron_action' ) ) // if already been scheduled, will return a time + { + wp_schedule_event(time(), 'hourly', 'admin_action_delibera_cron_action'); + } + } + + /** + * Simple text list of cron jobs + */ + function cronList() + { + ?> +
+ +
 $values)
+			{
+				echo "\n
[$key]: ".date("d/m/Y H:i:s", $key); + foreach ($values as $key2 => $value) + { + echo "\n
\t   [$key2]"; + foreach ($value as $ki => $item) + { + echo "\n
\t\t      [$ki]"; + if(is_array($item)) + { + if(array_key_exists('post_ID', $item)) + { + $post = get_post($item['post_ID']); + $title = get_the_title($post); + echo "\n$title"; + } + echo "\n
\t\t         ".print_r($item, true); + } + else + { + echo "\n
\t\t         $item"; + } + } + } + }?> +
+
0) + { + $crons = get_option('delibera-cron', array()); + if(!is_array($crons)) $crons = array(); + + if(!array_key_exists($data, $crons)) + { + $crons[$data] = array(); + } + $crons[$data][] = array('call_back' => $call_back, "args" => $args); + ksort($crons); + if(!update_option('delibera-cron', $crons)) + { + throw new \Exception("Cron not updated on $data, values:".print_r($crons[$data],true)); + } + } + } + + /** + * Remove a cron trigger + * @param int $postID + * @param function $callback function name or array($object, 'functio-name') + */ + static function del($postID, $callback = false) + { + $crons = get_option('delibera-cron', array()); + if(!is_array($crons)) $crons = array(); + + if( is_array($callback) ) + { + $callback = $callback[0].'_'.$callback[1]; + } + + $crons_new = array(); + foreach($crons as $cron_data => $cron_value) + { + $new_cron = array(); + foreach ($cron_value as $call) + { + $cron_callback = $call['call_back']; + if( is_array($call['call_back']) ) + { + $cron_callback = $call['call_back'][0].'_'.$call['call_back'][1]; + } + + if(array_key_exists('post_id', $call['args'])) $call['args']['post_ID'] = $call['args']['post_id']; + + if($call['args']['post_ID'] != $postID || ($callback !== false && $callback != $cron_callback )) + { + $new_cron[] = $call; + } + } + if(count($new_cron) > 0) + { + $crons_new[$cron_data] = $new_cron; + } + } + + ksort($crons_new); + update_option('delibera-cron', $crons_new); + } + + public function addMenu($base_page) + { + add_submenu_page($base_page, __('Delibera Cron','delibera'),__('Delibera Cron','delibera'), 'manage_options', 'delibera-cron', array($this, 'confPage')); + } + + public function confPage() + { + $this->cronList(); + } + + public function init() + { + if(is_super_admin()) // TODO load after init + { + add_action('delibera_menu_itens', array($this, 'addMenu')); + } + } + +} + +$DeliberaCron = new \Delibera\Cron(); + +// Force cron exec +/*if(array_key_exists("delibera_cron_action", $_REQUEST) && !defined('DOING_DELIBERA_CRON')) + { + ignore_user_abort(true); + define('DOING_DELIBERA_CRON', true); + delibera_cron_action(); + }*/ +//update_option('delibera-cron', array()); //delete cron +?> \ No newline at end of file diff --git a/admin/delibera_flow.php b/admin/delibera_flow.php new file mode 100644 index 0000000..8164801 --- /dev/null +++ b/admin/delibera_flow.php @@ -0,0 +1,688 @@ + "delibera_flow", + "label" => __('Fluxo padrão de uma pauta?', 'delibera'), + "content" => '' + ); + return $rows; + } + + /** + * Filter main config option before save + * @param unknown $opts + */ + public function preMainConfigSave($opts) + { + $save_opts = delibera_get_config(); + + if(array_key_exists('delibera_flow', $opts) && is_string($opts['delibera_flow']) && strlen($opts['delibera_flow']) > 1) + { + $opts['delibera_flow'] = explode(',', trim($opts['delibera_flow'])); + } + + if( empty($opts['delibera_flow']) || (is_string($opts['delibera_flow']) && strlen($opts['delibera_flow']) < 2 ) ) + { + if(empty($save_opts['delibera_flow'])) + { + $opts = $this->getMainConfig($opts); + } + else + { + $opts['delibera_flow'] = $save_opts['delibera_flow']; + } + } + return $opts; + } + + /** + * + * Post Meta Fields display + * + * @param \WP_Post $post + * @param array $custom post custom fields + * @param array $options_plugin_delibera Delibera options array + * @param WP_Term $situacao + * @param bool $disable_edicao + */ + public function topicMeta($post, $custom, $options_plugin_delibera, $situacao, $disable_edicao) + { + $flow = implode(',', array_map("htmlspecialchars", $this->get($post->ID)) ); + /*?> +

+ + id="delibera_flow" name="delibera_flow" class="delibera_flow widefat" value=""/> +

+ confPage(); + } + + /** + * get topic flow sequence + * @param string $post_id + */ + public function get($post_id = false) + { + $options_plugin_delibera = delibera_get_config(); + + $default_flow = isset($options_plugin_delibera['delibera_flow']) ? $options_plugin_delibera['delibera_flow'] : array(); + $default_flow = apply_filters('delibera_flow_list', $default_flow); + + if($post_id == false) + { + $post_id = get_the_ID(); + if($post_id == false) + { + return $default_flow; + } + } + + if(array_key_exists($post_id, $this->flow)) return $this->flow[$post_id]; + + $flow = get_post_meta($post_id, 'delibera_flow', true); + if(is_array($flow) && count($flow) > 0) + { + $flow = apply_filters('delibera_flow_list', $flow); + $this->flow[$post_id] = $flow; + return $flow; + } + else + { + $this->flow[$post_id] = $default_flow; + return $default_flow; + } + } + + /** + * List of Modules and each situation for get information about the module, like deadline + * + * @return \Delibera\Modules\ModuleBase[] + */ + public function getFlowModules() + { + $modules = array(); + /* Modules need to register to make part of flow + * Form: $modules['situacao'] = ModuleObject; + */ + $modules = apply_filters('delibera_register_flow_module', $modules); + return $modules; + } + + /** + * Get the last deadline before current module + * @param string $situacao + * @param int $post_id + * + * @return string date (dd/mm/YYYY) + */ + public static function getLastDeadline($situacao, $post_id = false) + { + global $DeliberaFlow; + if(is_object($situacao)) + { + $situacao = $situacao->slug; + } + + if($post_id == false) + { + $post_id = get_the_ID(); + } + $flow = $DeliberaFlow->get($post_id); + $modules = $DeliberaFlow->getFlowModules(); + + $now = array_search($situacao, $flow); + if(($now - 1) >= 0 && array_key_exists($now - 1, $flow) && array_key_exists($flow[$now - 1], $modules) && method_exists($modules[$flow[$now - 1]], 'getDeadline')) + { + return $modules[$flow[$now - 1]]->getDeadline(); + } + else + { + return date('d/m/Y'); + } + } + + /** + * Save post meta filter + * @param array $events_meta metas to save + * @param array $opt delibera config options + * + * @return array return filtered $events_meta array + */ + public function savePostMetas($events_meta, $opt, $post_id) + { + if(array_key_exists('delibera_flow', $_POST) ) + { + $flow = $_POST['delibera_flow']; + + if(is_string($flow)) + { + $flow = explode(',', trim($_POST['delibera_flow'])); + } + $events_meta['delibera_flow'] = $flow; + + $modules = $this->getFlowModules(); + foreach ($flow as $situacao) + { + if(array_key_exists($situacao, $modules)) + { + $events_meta = $modules[$situacao]->savePostMetas($events_meta, $opt); + } + } + } + return $events_meta; + } + + /** + * Create a new date triggers for current module + * @param int $post_id + * @param string $appendDays number of day to append or false to get config option default + */ + public function newDeadline($post_id, $appendDays = false) + { + $module = $this->getCurrentModule($post_id); + $module->newDeadline($post_id, $appendDays); + } + + /** + * Action when pauta is saved + * @param int $post_id + * @param \WP_Post $post + * @param array $opt delibera config options + */ + public function savePost($post_id, $post, $opt) + { + $this->newDeadline($post_id, 0); + } + + /** + * When the topic is published + * @param int $postID + * @param array $opt delibera configs + * @param bool $alterar has been altered + */ + public function publishPauta($postID, $opt) + { + /** + * Update flow meta after publish because is before save metas + */ + if(array_key_exists('delibera_flow', $_POST)) + { + $flow = array(); + if(is_array($_POST['delibera_flow'])) + { + $flow = array_map("strip_tags", $_POST['delibera_flow']); + } + else + { + $flow = explode(',', trim(strip_tags($_POST['delibera_flow']))); + } + update_post_meta($postID, 'delibera_flow', $flow); + //file_put_contents('/tmp/publish.log', date('Ymd H:i:s').$postID."\n", FILE_APPEND); + self::reabrirPauta($postID, false); + } + } + + /** + * Return Current Flow Module + * @param int $post_id + * @return \Delibera\Modules\ModuleBase + */ + public static function getCurrentModule($post_id) + { + global $DeliberaFlow; + + $flow = $DeliberaFlow->get($post_id); + $situacao = delibera_get_situacao($post_id); + $current = array_search($situacao->slug, $flow); + $modules = $DeliberaFlow->getFlowModules(); //TODO cache? + + if($current === false) + { + $situacoes = array(); + foreach ($modules as $module) + { + foreach ($module->situacao as $sit) + { + $situacoes[$sit] = $module; + } + } + if (array_key_exists($situacao->slug, $situacoes)) + { + return $situacoes[$situacao->slug]; + } + $current = 0; + } + if(array_key_exists($current, $flow) && array_key_exists($flow[$current], $modules)) + { + return $modules[$flow[$current]]; + } + else + { + return array_shift($modules); + } + } + + /** + * Go to the next module on flow + * @param string $post_id + */ + public static function next($post_id = false) + { + global $DeliberaFlow; + + $flow = $DeliberaFlow->get($post_id); + $situacao = delibera_get_situacao($post_id); + $current = array_search($situacao->slug, $flow); + $modules = $DeliberaFlow->getFlowModules(); //TODO cache? + + if(array_key_exists($current+1, $flow)) + { + $modules[$flow[$current+1]]->initModule($post_id); + } + else + { + //TODO the end? + } + } + + /** + * Trigger module deadline + * @param int $post_id + */ + public static function forcarFimPrazo($post_id) + { + if(is_object($post_id)) $post_id = $post_id->ID; + + $current = \Delibera\Flow::getCurrentModule($post_id); + \Delibera\Cron::del($post_id); + call_user_func(array(get_class($current), 'deadline'), array('post_ID' => $post_id, 'prazo' => date('d/m/Y'), 'force' => true) ); + } + + /** + * Reopen finished topic + * @param int $postID + * @param bool $new_deadline_days if is true will add days to new dateline + */ + public static function reabrirPauta($postID, $new_deadline_days = false) + { + global $DeliberaFlow; + $flow = $DeliberaFlow->get($postID); + $modules = $DeliberaFlow->getFlowModules(); + $modules[$flow[0]]->initModule($postID); + if($new_deadline_days) $modules[$flow[0]]->newDeadline($postID, false); + } + + /** + * Check if module has bean remove or altered + * @param array $flows + * @return array + */ + public function filterFlowList($flow) + { + if(is_array($flow)) + { + $modules = $this->getFlowModules(); + $flow = array_values(array_intersect($flow, array_keys($modules))); + return $flow; + } + else + { + return array(); + } + } + + /** + * Return module deadline days for the current post (until 1 minute, we return 1) + * @param int $post_id + * @return mixed|string deadline date + */ + public static function getDeadlineDays($post_id = false, &$data = null) + { + $module = \Delibera\Flow::getCurrentModule($post_id); + + $deadline = $module->getDeadline($post_id); + + if($deadline == -1) return $deadline; + + $dateTimeNow = new \DateTime(); + $deadlineDate = \DateTime::createFromFormat('d/m/Y H:i:s', $deadline." 23:59:59"); + + $diff = $dateTimeNow->diff($deadlineDate); + if(!is_null($data)) + { + $data = $deadlineDate->format('d/m/Y'); + } + if($diff->d > 0) + { + return $diff->format('%r%a'); + } + if($diff->d < 1 && ($diff->i || $diff->h || $diff->s)) + { + return 1; + } + else + { + return -1; + } + + } + + public function addMenu($base_page) + { + add_submenu_page($base_page, __('Delibera Flow','delibera'),__('Delibera Flow','delibera'), 'manage_options', 'delibera-flow', array($this, 'confPage')); + } + + public function listModulesConfigBoxes($post = null, $flow = false) + { + $is_post_meta = !is_null($post); + + /** + * Create Defaults value for topicMeta like in action TODO check if value is need after make this work + */ + $custom = array(); + $options_plugin_delibera = delibera_get_config(); + $situacao = ""; + $disable_edicao = false; + + if(is_null($post)) + { + $post = new \WP_Post(new \stdClass()); + } + else + { + $custom = get_post_meta($post->ID); + $situacao = delibera_get_situacao($post->ID); + } + + $modules = $this->getFlowModules(); + + if( $flow != false && is_array($flow) ) + { + $allmodules = $modules; + $modules = array(); + foreach ($flow as $step) + { + $modules[$step] = $allmodules[$step]; + } + } + + foreach ($modules as $key => $module) + { + $situacao = get_term_by('slug', $key, 'situacao'); + ?> +
+

name; ?> + + +

+
" > + topicMeta($post, $custom, $options_plugin_delibera, $situacao, $disable_edicao); + } + else + { + $rows = array(); + $rows = $module->configPageRows($rows, $options_plugin_delibera); + $table = delibera_form_table($rows); + if(has_filter('delibera_config_form')) + { + $table = apply_filters('delibera_config_form', $table, $opt); + } + echo $table; + } + if(!$is_post_meta) // Use post save + {?> + + +
+ +
+ get(); + ?> +
+ + +
+ listModulesConfigBoxes($post); + ?> +
+ +
+ listModulesConfigBoxes($post, $flow); + ?> +
+
+ id; + if(strpos($screenid, 'page_delibera') !== false || $screenid == 'pauta' ) + { + $post_id = get_the_ID(); + wp_enqueue_script('delibera-admin-flow', plugin_dir_url(__FILE__).'/js/flow.js', array( 'jquery-ui-core', 'jquery-ui-sortable')); + $data = array( + 'ajax_url' => admin_url('admin-ajax.php'), + 'post_id' => $post_id + ); + + wp_localize_script('delibera-admin-flow', 'delibera_admin_flow', $data); + wp_enqueue_script('jquery-ui-datepicker-ptbr', DELIBERA_DIR_URL.'/js/jquery.ui.datepicker-pt-BR.js', array('jquery-ui-datepicker')); + wp_enqueue_script('delibera-admin', plugin_dir_url(__FILE__).'/js/admin_scripts.js', array( 'jquery-ui-datepicker-ptbr')); + + wp_enqueue_style('delibera-admin-flow',plugin_dir_url(__FILE__).'/css/flow.css'); + } + } + + /** + * Validate topic required data + * @param array $errors erros report array + * @param array $opt Delibera configs + * @param bool $autosave is autosave? + * @return array erros report array append if needed + */ + public function checkPostData($errors, $opt, $autosave) + { + if(array_key_exists('delibera_flow', $_POST) ) + { + $flow = $_POST['delibera_flow']; + if(is_string($flow)) + { + $flow = explode(',', strip_tags($_POST['delibera_flow'])); + } + $valida = is_array($flow) ? count($flow) : false; + if(!$autosave && ($valida === false || $valida < 1)) + { + $errors[] = __("É necessário definir corretamente o fluxo da pauta", "delibera"); + } + else + { + $modules = $this->getFlowModules(); + foreach ($flow as $situacao) + { + if(array_key_exists($situacao, $modules)) + { + $errors = $modules[$situacao]->checkPostData($errors, $opt, false); + } + } + } + } + else + { + $errors[] = __("É necessário definir corretamente o fluxo da pauta", "delibera"); + } + return $errors; + } + + public function saveFlowCallback() + { + $flow = explode(',', strip_tags($_POST['delibera_flow'])); + $post_id = intval(strip_tags($_POST['post_id'])); + $opt = delibera_get_config(); + $all_errors = array(); + + if($post_id > 0) + { + $modules = $this->getFlowModules(); + $events_meta = array(); + foreach ($flow as $situacao) + { + $errors = array(); + if(array_key_exists($situacao, $modules)) + { + $errors = $modules[$situacao]->checkPostData($errors, $opt, false); + if(count($errors) == 0) + { + $events_meta = $modules[$situacao]->savePostMetas($events_meta, $opt); + } + else + { + $all_errors = array_merge($all_errors,$errors); + } + } + } + if(count($all_errors) > 0) + { + if ( defined( 'DOING_AJAX' ) ) { + die(json_encode($all_errors));//TODO error notice and parser + } + wp_die( implode('
', $errors) ); + + } + foreach ($events_meta as $key => $value) // Buscar dados + { + update_post_meta($post_id, $key, $value); // Atualiza + } + } + else + { + $rows = array(); + $rows = $this->configPageRows($rows, $opt); + $modules = \Delibera\Flow::getFlowModules(); + foreach ($modules as $module) + { + $rows = $module->configPageRows($rows, $opt); + } + $oldFlow = implode(',', $opt['delibera_flow']); + $configs_to_save = array_value_recursive('id', $rows); + foreach ($configs_to_save as $option_name) //TODO better way to do this + { + if (isset($_POST[$option_name])) + { + $opt[$option_name] = htmlspecialchars($_POST[$option_name]); + } + else // checkbox maybe + { + $opt[$option_name] = "N"; + } + } + $opt['delibera_flow'] = $flow; + if(! update_option('delibera-config', $opt) && $oldFlow != implode(',', $flow) ) + { + $all_errors = array(__('can not update modules configs', 'delibera')); + } + + if(count($all_errors) > 0) + { + die(json_encode($all_errors));//TODO error notice and parser + } + } + die('ok'); + } + + /** + * return list of Deadlines of a post in format: array of [situacao] => [date] + * @param int $post_id + * @return array + */ + public static function getDeadlineDates($post_id) + { + global $DeliberaFlow; + + $dates = array(); + $flow = $DeliberaFlow->get($post_id); + $modules = $DeliberaFlow->getFlowModules(); + foreach ($flow as $situacao) + { + if(array_key_exists($situacao, $modules)) + { + $dates[$situacao] = $modules[$situacao]->getDeadline($post_id); + } + } + return $dates; + } + +} + +global $DeliberaFlow; +$DeliberaFlow = new \Delibera\Flow(); diff --git a/delibera_user_painel.php b/admin/delibera_user_painel.php similarity index 100% rename from delibera_user_painel.php rename to admin/delibera_user_painel.php diff --git a/admin/images/iconSpirite.gif b/admin/images/iconSpirite.gif new file mode 100644 index 0000000..8057c18 Binary files /dev/null and b/admin/images/iconSpirite.gif differ diff --git a/js/admin_notifica_scripts.js b/admin/js/admin_notifica_scripts.js similarity index 100% rename from js/admin_notifica_scripts.js rename to admin/js/admin_notifica_scripts.js diff --git a/js/admin_scripts.js b/admin/js/admin_scripts.js similarity index 100% rename from js/admin_scripts.js rename to admin/js/admin_scripts.js diff --git a/admin/js/flow.js b/admin/js/flow.js new file mode 100644 index 0000000..66cb007 --- /dev/null +++ b/admin/js/flow.js @@ -0,0 +1,238 @@ +/** + * + */ + +function deliberaIsConfig() +{ + return delibera_admin_flow.post_id == ''; +} + +function deliberaFlowToggle(element) +{ + jQuery(element).parent().siblings('.dragbox-content').toggle(); +} + +function deliberaFlowRemove(element) +{ + var sel = confirm('do you want to delete this step?'); + if (sel) { + jQuery(element).parent().parent().remove(); + deliberaUpdateFlow(); + } +} + +var sortorder = ''; +function deliberaUpdateFlow() +{ + sortorder = ''; + jQuery('.delibera-flow-panel').find('#delibera-flow-column2').each(function() + { + var itemorder = jQuery(this).sortable('toArray', { attribute: 'class'} ); + for (i = 0; i < itemorder.length; i++) + { + var tmp = itemorder[i].replace("dragbox ", "").replace(" clone", ""); + itemorder[i] = tmp; + } + sortorder += itemorder.toString(); + }); + jQuery('#delibera_flow').val(sortorder); + jQuery('#delibera-flow-column2').trigger('deliberaUpdateFlow'); + if(deliberaIsConfig()) + { + updateDates(); + deliberaHideUsedModules() + + } +} + +function deliberaUsedModule(id) +{ + if(jQuery('.delibera-flow-panel').find("#delibera-flow-column2").find("."+id).length > 1) + { + return true; + } + return false; +} + +function deliberaHideUsedModules() +{ + /** remove after multiple of the same has implemented **/ + if(!deliberaIsConfig()) + { + var boxes = jQuery('#delibera-flow-column2').find('.dragbox'); + jQuery('.delibera-flow-panel').find("#delibera-flow-column1").find('.dragbox').show(); + for (var i = 0; i < boxes.length; i++) + { + var itemclass = jQuery(boxes[i]).attr('class').replace("dragbox ", "").replace(" clone", ""); + //console.log(itemclass); + jQuery('.delibera-flow-panel').find("#delibera-flow-column1").find("."+itemclass).hide(); + } + /** END remove after multiple of the same has implemented **/ + } +} + +Date.prototype.addDays = function(days) +{ + var dat = new Date(this.valueOf()); + dat.setDate(dat.getDate() + days); + return dat; +} + +function updateDates() +{ + var boxes = jQuery('#delibera-flow-column2').find('.dragbox'); + var lastDate = new Date(); + for (var i = 0; i < boxes.length; i++) + { + var dateinput = jQuery(boxes[i]).find('input.hasDatepicker'); + var daysinput = jQuery(boxes[i]).find('input.delibera_flow_module_days'); + var daysToAdd = Number(jQuery(daysinput).val()); + lastDate = lastDate.addDays(daysToAdd); + jQuery(dateinput).val( ('00' + lastDate.getDate()).slice(-2) + "/" + ('00' + (lastDate.getMonth()+1)).slice(-2) + "/" + lastDate.getFullYear()); + } +} + +jQuery(document).ready(function() { + deliberaHideUsedModules(); + jQuery('.delibera-flow-panel').find('span.maxmin').click(function() { + deliberaFlowToggle(this); + }); + + jQuery('.delibera-flow-panel').find('span.delete').click(function() { + deliberaFlowRemove(this); + }); + + jQuery('.delibera-flow-column').sortable({ + connectWith : '.delibera-flow-column', + handle : 'h2', + cursor : 'move', + placeholder : 'placeholder', + forcePlaceholderSize : true, + opacity : 0.4, + helper : function(e, div) { + copyHelper = div.clone().insertAfter(div); + jQuery(copyHelper).find('span.maxmin').click(function() { + deliberaFlowToggle(this); + }); + jQuery(copyHelper).find('span.delete').click(function() { + deliberaFlowRemove(this); + }); + jQuery(copyHelper).find('.hasdatepicker:not([readonly])').removeAttr('id'); + jQuery(copyHelper).find('.hasdatepicker:not([readonly])').removeClass('hasDatepicker').datepicker({ + userLang : 'pt-BR', + americanMode: false, + }); + div_copy = div.clone(); + return div_copy; + }, + stop : function(event, ui) { + copyHelper && copyHelper.remove(); + jQuery(ui.item).addClass('clone'); + jQuery(ui.item).find('h2').click(); + sortorder = ''; + jQuery(ui.item).find('.hasdatepicker:not([readonly])').removeClass('hasDatepicker').datepicker({ + userLang : 'pt-BR', + americanMode: false, + }); + jQuery(ui.item).find("input").prop('disabled', false); + deliberaUpdateFlow(); + if(!deliberaIsConfig() && ui.item.parent().attr('id') != 'delibera-flow-column1' ) { + jQuery(ui.item).find('.dragbox-content').show(); + } + } + }); + jQuery('.delibera-flow-panel').find("#delibera-flow-column2").sortable({ + receive : function(e, ui) { + copyHelper = null; + var id = ui.item.attr('class').replace("dragbox ", "").replace(" clone", ""); + if(deliberaUsedModule(id)) + { + ui.sender.sortable("cancel"); + } + } + }); + jQuery('.delibera-flow-panel').find("#delibera-flow-column1").sortable({ + receive : function(e, ui) { + if(ui.item.hasClass("clone")) + { + ui.sender.sortable("cancel"); + } + } + }); + if(deliberaIsConfig()) + { + jQuery('.delibera-flow-panel').find("#delibera-flow-column2").find("input").prop('disabled', true); + } + else + { + jQuery('.delibera-flow-panel').find("#delibera-flow-column1").find("input").prop('disabled', true); + } + + jQuery('.delibera-flow-panel').find("input.dragbox-bt-save").click(function(){ + deliberaUpdateFlow(); + var data = { + action : "delibera_save_flow", + delibera_flow: sortorder, + post_id: jQuery('#delibera-flow-postid').val(), + nonce: jQuery('#_delibera-flow-nonce').val() + }; + if(deliberaIsConfig()) + { + jQuery('.delibera-flow-panel').find('#delibera-flow-column1').find('input:not(input[type=button], input[type=submit], input[type=reset]), textarea, select').each(function(){ + if(this.type == 'checkbox') + { + if(this.checked) data[this.name] = this.value; + } + else + { + data[this.name] = this.value; + } + }); + } + else + { + jQuery('.delibera-flow-panel').find('#delibera-flow-column2').find('input:not(input[type=button], input[type=submit], input[type=reset]), textarea, select').each(function(){ + if(this.name.indexOf('[') > -1) + { + if(data[this.name] == null) + { + data[this.name] = [[ + this.id, + this.value + ]]; + } + else + { + data[this.name].push([ + this.id, + this.value + ]); + } + } + else + { + if(this.type == 'checkbox') + { + if(this.checked) data[this.name] = this.value; + } + else + { + data[this.name] = this.value; + } + } + }); + } + + jQuery.post( + delibera_admin_flow.ajax_url, + data, + function(response) { + if(response == 'ok') + alert("Saved"); + //window.location.reload(true); + else + alert("Errors"); + } + ); + }); +}); \ No newline at end of file diff --git a/css/delibera.css b/css/delibera.css index 466311e..f274bf6 100644 --- a/css/delibera.css +++ b/css/delibera.css @@ -40,4 +40,4 @@ background:url('../qtranslate/flags/es.png') left bottom no-repeat; .delibera-config-mensagem { height: 140px; -} \ No newline at end of file +} diff --git a/css/fonts/fontello-6acce062/LICENSE.txt b/css/fonts/fontello-6acce062/LICENSE.txt new file mode 100755 index 0000000..2e7737a --- /dev/null +++ b/css/fonts/fontello-6acce062/LICENSE.txt @@ -0,0 +1,30 @@ +Font license info + + +## Fontelico + + Copyright (C) 2012 by Fontello project + + Author: Crowdsourced, for Fontello project + License: SIL (http://scripts.sil.org/OFL) + Homepage: http://fontello.com + + +## Font Awesome + + Copyright (C) 2012 by Dave Gandy + + Author: Dave Gandy + License: SIL () + Homepage: http://fortawesome.github.com/Font-Awesome/ + + +## Entypo + + Copyright (C) 2012 by Daniel Bruce + + Author: Daniel Bruce + License: SIL (http://scripts.sil.org/OFL) + Homepage: http://www.entypo.com + + diff --git a/css/fonts/fontello-6acce062/README.txt b/css/fonts/fontello-6acce062/README.txt new file mode 100755 index 0000000..beaab33 --- /dev/null +++ b/css/fonts/fontello-6acce062/README.txt @@ -0,0 +1,75 @@ +This webfont is generated by http://fontello.com open source project. + + +================================================================================ +Please, note, that you should obey original font licenses, used to make this +webfont pack. Details available in LICENSE.txt file. + +- Usually, it's enough to publish content of LICENSE.txt file somewhere on your + site in "About" section. + +- If your project is open-source, usually, it will be ok to make LICENSE.txt + file publicly available in your repository. + +- Fonts, used in Fontello, don't require a clickable link on your site. + But any kind of additional authors crediting is welcome. +================================================================================ + + +Comments on archive content +--------------------------- + +- /font/* - fonts in different formats + +- /css/* - different kinds of css, for all situations. Should be ok with + twitter bootstrap. Also, you can skip style and assign icon classes + directly to text elements, if you don't mind about IE7. + +- demo.html - demo file, to show your webfont content + +- LICENSE.txt - license info about source fonts, used to build your one. + +- config.json - keeps your settings. You can import it back into fontello + anytime, to continue your work + + +Why so many CSS files ? +----------------------- + +Because we like to fit all your needs :) + +- basic file, .css - is usually enough, it contains @font-face + and character code definitions + +- *-ie7.css - if you need IE7 support, but still don't wish to put char codes + directly into html + +- *-codes.css and *-ie7-codes.css - if you like to use your own @font-face + rules, but still wish to benefit from css generation. That can be very + convenient for automated asset build systems. When you need to update font - + no need to manually edit files, just override old version with archive + content. See fontello source code for examples. + +- *-embedded.css - basic css file, but with embedded WOFF font, to avoid + CORS issues in Firefox and IE9+, when fonts are hosted on the separate domain. + We strongly recommend to resolve this issue by `Access-Control-Allow-Origin` + server headers. But if you ok with dirty hack - this file is for you. Note, + that data url moved to separate @font-face to avoid problems with + + + + + + + +
+

+ delibera + font demo +

+ +
+
+
+
delibera-icon-spin20xe800
+
delibera-icon-ok0xe801
+
delibera-icon-plus0xe802
+
delibera-icon-print0xe803
+
+
+
delibera-icon-down-open0xe804
+
delibera-icon-left-open0xe805
+
delibera-icon-right-open0xe806
+
delibera-icon-up-open0xe807
+
+
+
delibera-icon-thumbs-up-alt0xe808
+
delibera-icon-thumbs-down-alt0xe809
+
delibera-icon-reply0xe80a
+
delibera-icon-trash0xe80b
+
+
+
delibera-icon-attach0xe80c
+
delibera-icon-users0xe80d
+
delibera-icon-chat0xe80e
+
delibera-icon-calendar0xe80f
+
+
+
delibera-icon-newspaper0xe810
+
delibera-icon-key0xe811
+
delibera-icon-cancel0xe812
+
delibera-icon-thumbs-up0xe813
+
+
+
delibera-icon-thumbs-down0xe814
+
delibera-icon-chat-empty0xe815
+
delibera-icon-cog0xe816
+
delibera-icon-facebook-official0xe817
+
+
+
delibera-icon-facebook0xe818
+
delibera-icon-gplus-squared0xe819
+
delibera-icon-gplus0xe81a
+
delibera-icon-twitter0xe81b
+
+
+
delibera-icon-twitter-squared0xe81c
+
delibera-icon-whatsapp0xe81d
+
delibera-icon-edit0xe81e
+
+
+ + + \ No newline at end of file diff --git a/css/fonts/fontello-6acce062/font/delibera.eot b/css/fonts/fontello-6acce062/font/delibera.eot new file mode 100755 index 0000000..8f04a5c Binary files /dev/null and b/css/fonts/fontello-6acce062/font/delibera.eot differ diff --git a/css/fonts/fontello-6acce062/font/delibera.svg b/css/fonts/fontello-6acce062/font/delibera.svg new file mode 100755 index 0000000..e086ead --- /dev/null +++ b/css/fonts/fontello-6acce062/font/delibera.svg @@ -0,0 +1,72 @@ + + + +Copyright (C) 2016 by original authors @ fontello.com + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/css/fonts/fontello-6acce062/font/delibera.ttf b/css/fonts/fontello-6acce062/font/delibera.ttf new file mode 100755 index 0000000..118ecb5 Binary files /dev/null and b/css/fonts/fontello-6acce062/font/delibera.ttf differ diff --git a/css/fonts/fontello-6acce062/font/delibera.woff b/css/fonts/fontello-6acce062/font/delibera.woff new file mode 100755 index 0000000..d0c9f96 Binary files /dev/null and b/css/fonts/fontello-6acce062/font/delibera.woff differ diff --git a/css/fonts/fontello-6acce062/font/delibera.woff2 b/css/fonts/fontello-6acce062/font/delibera.woff2 new file mode 100755 index 0000000..2964224 Binary files /dev/null and b/css/fonts/fontello-6acce062/font/delibera.woff2 differ diff --git a/delibera-edit-form-comment.php b/delibera-edit-form-comment.php index 096d167..611f6d4 100644 --- a/delibera-edit-form-comment.php +++ b/delibera-edit-form-comment.php @@ -1,17 +1,31 @@ + + +
+ Nova Pauta: {post_title} +
+ Leia a Pauta: {post_title} em {site_name}','delibera'); $opt['mensagem_validacao_assunto'] = __('Novo voto de validação: Pauta {post_title}','delibera'); $opt['mensagem_validacao'] = __( -'A validação do usuário xxx na pauta {post_title} foi registrada no sistema. Acesse a pauta para verificar a situação: -{post_url}', 'delibera'); + '

Novo voto de validação: Pauta «{post_title}»

+
+ A validação do usuário xxx na pauta {post_title} foi registrada no sistema. Acesse a pauta para verificar a situação. +
+ Leia a Pauta: {post_title} em {site_name}', 'delibera'); $opt['mensagem_validacao_concluida_assunto'] = __('Nova pauta validada: Pauta {post_title}','delibera'); $opt['mensagem_validacao_concluida'] = __( -'Olá {display_name}, -a pauta "{post_title}" foi validada, agora você poderá fazer comentários e propostas. Além disto poderá inserir arquivos em diversos formatos, seja em texto, imagem, áudio ou vídeo. -Seus comentários poderão ser avaliados pelos demais membros, já as propostas, além de avaliadas previamente, poderão ir a votação onde todos os usuários poderão votar. Caso exista uma relatoria, esta poderá fazer a sistematização, mesclando propostas similares e ajustando a redação para a melhor compreensão, tudo garantindo o controle social do processo com o histórico de propostas originais. + '

Nova pauta validada: Pauta «{post_title}»

+
+ Olá {display_name}, -Agora vai em frente! Debata, proponha, fortaleça a democracia digital! + A pauta "{post_title}" foi validada, agora você poderá fazer comentários e propostas. Além disto poderá inserir arquivos em diversos formatos, seja em texto, imagem, áudio ou vídeo. + Seus comentários poderão ser avaliados pelos demais membros, já as propostas, além de avaliadas previamente, poderão ir a votação onde todos os usuários poderão votar. Caso exista uma relatoria, esta poderá fazer a sistematização, mesclando propostas similares e ajustando a redação para a melhor compreensão, tudo garantindo o controle social do processo com o histórico de propostas originais. -{post_url}', 'delibera'); + Agora vai em frente! Debata, proponha, fortaleça a democracia digital! +
+ Leia a Pauta: {post_title} em {site_name}', 'delibera'); $opt['mensagem_pauta_recusada_assunto'] = __('Pauta Recusada: Pauta {post_title}','delibera'); $opt['mensagem_pauta_recusada'] = __( -'Olá {display_name}, - -a pauta {post_title} não obteve o apoio necessário, por isto ela não entrará em debate desta vez. + '

Pauta Recusada: Pauta «{post_title}»

+
+ Olá {display_name}, -{post_url}', 'delibera'); + a pauta {post_title} não obteve o apoio necessário, por isto ela não entrará em debate desta vez. +
+ Leia a Pauta: {post_title} em {site_name}', 'delibera'); $opt['mensagem_fim_prazo_validacao_assunto'] = 'Fim de prazo para Validação: Pauta {post_title}'; - $opt['mensagem_fim_prazo_validacao'] = 'Olá {display_name}, + $opt['mensagem_fim_prazo_validacao'] = '

Fim de prazo para Validação: Pauta «{post_title}»

+
+ Olá {display_name}, -falta apenas 1 dia para o fim do prazo para validação da pauta {post_title}. Caso não tenha votado aproveite agora para fazê-lo, ou chame seus conhecidos! - -{post_url}'; + Falta apenas 1 dia para o fim do prazo para validação da pauta {post_title}. Caso não tenha votado aproveite agora para fazê-lo, ou chame seus conhecidos! +
+ Leia a Pauta: {post_title} em {site_name}'; $opt['mensagem_novo_comentario_assunto'] = __('Novo Comentário em {post_title}','delibera'); - $opt['mensagem_novo_comentario'] = __('Há um novo comentário na pauta seguida: ','delibera'); - $opt['mensagem_fim_prazo_discussao_assunto'] = 'Fim de prazo para Discussão: Pauta {post_title}'; - $opt['mensagem_fim_prazo_discussao'] = 'Olá {display_name}, + $opt['mensagem_novo_comentario'] = __('

Novo Comentário em «{post_title}»

+
+ Olá {display_name}, -falta apenas 1 dia para o fim do prazo de discussão da pauta {post_title}. Caso ainda queira comentar aproveite agora para fazê-lo agora! + Há um novo comentário na pauta {post_title}. +
+ Leia a Pauta: {post_title} em {site_name}','delibera'); + $opt['mensagem_fim_prazo_discussao_assunto'] = 'Fim de prazo para Discussão: Pauta {post_title}'; + $opt['mensagem_fim_prazo_discussao'] = '

Fim de prazo para Discussão: Pauta «{post_title}»

+
+ Olá {display_name}, -{post_url}'; + Falta apenas 1 dia para o fim do prazo de discussão da pauta {post_title}. Caso ainda queira comentar aproveite agora para fazê-lo agora!
+ Leia a Pauta: {post_title} em {site_name}'; $opt['mensagem_discussao_concluida_rel_assunto'] = __('Término da Discussão e início da relatoria: Pauta {post_title}','delibera'); $opt['mensagem_discussao_concluida_rel'] = __( -'Olá {display_name}, + '

Término da Discussão e início da relatoria: Pauta «{post_title}»

+
+ Olá {display_name}, -o prazo para discussão da pauta {post_title} terminou, agora o relator terá o prazo de {report_deadline} para sistematizar as propostas e colocar em votação. Você continua pondendo visualizar o que foi discutido nesta pauta: - -{post_url}', 'delibera'); + O prazo para discussão da pauta {post_title} terminou, agora o relator terá o prazo de {report_deadline} para sistematizar as propostas e colocar em votação. Você continua podendo visualizar o que foi discutido nesta pauta. +
+ Leia a Pauta: {post_title} em {site_name}', 'delibera'); $opt['mensagem_discussao_concluida_assunto'] = __('Término da Discussão: Pauta {post_title}','delibera'); $opt['mensagem_discussao_concluida'] = __( -'Olá {display_name}, - -o prazo para discussão da pauta {post_title} terminou, agora você poderá votar nas propostas que foram encaminhadas durante o processo de discussão. + '

Término da Discussão: Pauta «{post_title}»

+
+ Olá {display_name}, -{post_url}', 'delibera'); + O prazo para discussão da pauta {post_title} terminou, agora você poderá votar nas propostas que foram encaminhadas durante o processo de discussão. +
+ Leia a Pauta: {post_title} em {site_name}', 'delibera'); $opt['mensagem_relatoria_concluida_assunto'] = __('Fim do prazo da relatoria: Pauta {post_title}','delibera'); $opt['mensagem_relatoria_concluida'] = __( -'Olá {display_name}, - -o prazo para a relatoria da pauta {post_title} terminou, agora você poderá votar nas propostas que foram encaminhadas durante o processo de discussão e sistematizadas pela relatoria. -Você pode acompanhar a origem de todas as propostas, de modo que garanta o controle social da sistematização das propostas. + '

Fim do prazo da relatoria: Pauta «{post_title}»

+
+ Olá {display_name}, -{post_url}', 'delibera'); + O prazo para a relatoria da pauta {post_title} terminou, agora você poderá votar nas propostas que foram encaminhadas durante o processo de discussão e sistematizadas pela relatoria. + Você pode acompanhar a origem de todas as propostas, de modo que garanta o controle social da sistematização das propostas. +
+ Leia a Pauta: {post_title} em {site_name}', 'delibera'); $opt['mensagem_fim_prazo_relatoria_assunto'] = 'Fim do prazo da relatoria: Pauta {post_title}'; - $opt['mensagem_fim_prazo_relatoria'] = 'Olá {display_name}, + $opt['mensagem_fim_prazo_relatoria'] = '

Fim do prazo da relatoria: Pauta «{post_title}»

+
+ Olá {display_name}, -O prazo para a relatoria da pauta "{post_title}" terminou, agora você poderá votar nas propostas que foram encaminhadas durante o processo de discussão e sistematizadas pela relatoria. -Você pode acompanhar a origem de todas as propostas, de modo que garanta o controle social da sistematização das propostas. - -{post_url}'; + O prazo para a relatoria da pauta {post_title} terminou, agora você poderá votar nas propostas que foram encaminhadas durante o processo de discussão e sistematizadas pela relatoria. + Você pode acompanhar a origem de todas as propostas, de modo que garanta o controle social da sistematização das propostas. +
+ Leia a Pauta: {post_title} em {site_name}'; $opt['mensagem_fim_prazo_votacao_assunto'] = 'Fim de prazo para Votação: Pauta {post_title}'; - $opt['mensagem_fim_prazo_votacao'] = 'Olá {display_name}, - -falta apenas 1 dia para o fim do prazo de votação da pauta {post_title}. Se ainda não votou, aproveite agora para fazê-lo agora. Sua participação é muito importante! + $opt['mensagem_fim_prazo_votacao'] = '

Fim de prazo para Votação: Pauta «{post_title}»

+
+ Olá {display_name}, -{post_url}'; + Falta apenas 1 dia para o fim do prazo de votação da pauta {post_title}. Se ainda não votou, aproveite para fazê-lo agora. Sua participação é muito importante! +
+ Leia a Pauta: {post_title} em {site_name}'; $opt['mensagem_votacao_concluida_assunto'] = __('Votação Concluída, veja as resoluções: Pauta {post_title}','delibera'); $opt['mensagem_votacao_concluida'] = __( -'Olá {display_name}, + '

Votação Concluída, veja as resoluções: Pauta «{post_title}»

+
+ Olá {display_name}, + + O prazo para votação da pauta {post_title} encerrou, confira as resoluções do processo. + + Obrigado por sua participação! +
+ Leia a Pauta: {post_title} em {site_name}', 'delibera'); -O prazo para votação da pauta {post_title} encerrou, confira as resoluções do processo. -Obrigado por sua participação! + $langs = delibera_get_available_languages(); -{post_url}', 'delibera'); - - $langs = delibera_get_available_languages(); - - foreach ($langs as $lang) - { + foreach ($langs as $lang) + { foreach (delibera_nofiticar_get_tipos() as $notif) { $opt["{$notif['mensagem']}_assunto-$lang"] = $opt["{$notif['mensagem']}_assunto"]; $opt["{$notif['mensagem']}-$lang"] = $opt[$notif['mensagem']]; - } + } } - + return array_merge($opt, $config); } add_filter('delibera_get_config', 'delibera_get_notification_config'); function delibeta_nofiticar_config_page_row(&$rows, $opt, $tipo, $label = '', $lang = '') { - + if($label == '') $label = $tipo; $label = "".$label.""; - + $rows2 = array(); - + $rows2[] = array( - "id" => "mensagem_{$tipo}_assunto".$lang, - "row-id" => "row-mensagem_{$tipo}_assunto".$lang, - "label" => __('Assunto da mensagem padrão de notificação de ' . $label . ':', 'delibera'), - "content" => '' - ); + "id" => "mensagem_{$tipo}_assunto".$lang, + "row-id" => "row-mensagem_{$tipo}_assunto".$lang, + "label" => __('Assunto da mensagem padrão de notificação de ' . $label . ':', 'delibera'), + "content" => '' + ); $rows2[] = array( - "id" => "mensagem_{$tipo}".$lang, - "row-id" => "row-mensagem_{$tipo}".$lang, - "label" => __('Mensagem padrão de notificação de ' . $label . ':', 'delibera'), - "content" => '' - ); - + "id" => "mensagem_{$tipo}".$lang, + "row-id" => "row-mensagem_{$tipo}".$lang, + "label" => __('Mensagem padrão de notificação de ' . $label . ':', 'delibera'), + "content" => htmlspecialchars_decode($opt['mensagem_'.$tipo.$lang]), + "type" => 'wp_editor' + ); + $rows[] = $rows2; } function delibera_nofiticar_config_page_campos($opt, $lang = '') { if($lang != '') $lang = "-".$lang; - + $rows = array(); - + foreach (delibera_nofiticar_get_tipos() as $notif) { delibeta_nofiticar_config_page_row($rows, $opt, $notif['tipo'], $notif['dica'], $lang); } - + return $rows; } @@ -238,37 +371,37 @@ function delibera_nofiticar_config_page() { $table = ''; $opt = delibera_get_config(); - + $rows = array(); $rows[] = array( - "id" => "notificacoes", - "label" => __('Permitir notificações por e-mail?','delibera'), - "content" => '' - ); + "id" => "notificacoes", + "label" => __('Permitir notificações por e-mail?','delibera'), + "content" => '' + ); $table .= delibera_form_table($rows); $rows_lang = array(); - + if(function_exists('qtrans_enableLanguage')) { $head = "
"; global $q_config; - + foreach ($q_config['enabled_languages'] as $lang) { $display = "none"; $ativa = ""; - + if($lang == $q_config['default_language']) { $display = "block"; $ativa = "active"; } - + $onclick="switch_mensagem_box('".$lang."');"; $head .= ''; - + $rows_lang[$lang] = delibera_nofiticar_config_page_campos($opt, $lang); - + if($lang == $q_config['default_language']) { $rows_lang[$lang]['default'] = true; @@ -278,48 +411,50 @@ function delibera_nofiticar_config_page() } else { - + $lang = get_locale(); - + $display = "block"; $ativa = "active"; - + $rows_lang[$lang] = delibera_nofiticar_config_page_campos($opt, $lang); - + $rows_lang[$lang]['default'] = true; - + $table; } $table .= '
'; $rows = array(); $i = 0; - + foreach (delibera_nofiticar_get_tipos() as $notif) { delibera_nofiticar_config_page_create_checkbox($rows, - "{$notif['mensagem']}-enabled", - $notif['dica_permicao'], - $opt, - $rows_lang, $i++ - ); + "{$notif['mensagem']}-enabled", + $notif['dica_permicao'], + $opt, + $rows_lang, $i++ + ); } - + echo '
';	
+	print_r($rows);
+	echo '
'; $table .= delibera_form_table($rows); $table .= '
'; - + return $table; } function delibera_nofiticar_config_page_create_checkbox(&$rows, $id, $label, $opt, $rows_lang, $index) { $rows[] = array( - "id" => $id, - "label" => $label, - "content" => '' - ); - - + "id" => $id, + "label" => $label, + "content" => '' + ); + + foreach($rows_lang as $lang => $row_lang) { $active = false; @@ -354,31 +489,31 @@ function delibera_notificar_get_mensagem_link($post, $link = false) function delibera_notificar_nova_pauta($post = false) { - $message = ''; - delibera_notificar_representantes($message, 'mensagem_criacao_pauta', $post); + $message = ''; + delibera_notificar_representantes($message, 'mensagem_criacao_pauta', $post); } function delibera_notificar_situacao($post = false) { - /*$message = 'Situação: '.delibera_get_situacao($post)->name; - delibera_notificar_representantes($message, 'mensagem_mudanca_situacao', $post);*/ + /*$message = 'Situação: '.delibera_get_situacao($post)->name; + delibera_notificar_representantes($message, 'mensagem_mudanca_situacao', $post);*/ } function delibera_notificar_nova_validacao($post = false) { - delibera_notificar_representantes('', 'validacao', $post); + delibera_notificar_representantes('', 'validacao', $post); } add_action('delibera_validacao', 'delibera_notificar_nova_validacao'); function delibera_notificar_pauta_recusada($post = false) { - delibera_notificar_representantes('', 'pauta_recusada', $post); + delibera_notificar_representantes('', 'pauta_recusada', $post); } add_action('delibera_pauta_recusada', 'delibera_notificar_pauta_recusada'); function delibera_notificar_validacao_concluida($post = false) { - delibera_notificar_representantes('', 'validacao_concluida', $post); + delibera_notificar_representantes('', 'validacao_concluida', $post); } add_action('delibera_validacao_concluida', 'delibera_notificar_validacao_concluida'); @@ -415,10 +550,10 @@ function delibera_notificar_fim_prazo($args) { $post = get_post($post); } - $message = ''; - $situacao = delibera_get_situacao($post->ID); - - delibera_notificar_representantes($message, "mensagem_fim_prazo_{$situacao->slug}", $post); + $message = ''; + $situacao = delibera_get_situacao($post->ID); + + delibera_notificar_representantes($message, "mensagem_fim_prazo_{$situacao->slug}", $post); } function delibera_notificar_representantes($mensage, $tipo, $post = false, $users = false, $link = false) { @@ -430,61 +565,61 @@ function delibera_notificar_representantes($mensage, $tipo, $post = false, $user $post = get_post(); } - if(is_numeric($post)) + if(!is_object($post)) { $post = get_post($post); } - if($post->post_status == 'publish') + if(is_object($post) && $post->post_status == 'publish') { - + $options_plugin_delibera = delibera_get_config(); - + if( - $options_plugin_delibera["notificacoes"] == "N" || // Notificações estão desabilitadas OU - !array_key_exists("$tipo-enabled", $options_plugin_delibera) || - $options_plugin_delibera["$tipo-enabled"] == "N" // Esse tipo de notificação está desabilitada - ) + $options_plugin_delibera["notificacoes"] == "N" || // Notificações estão desabilitadas OU + !array_key_exists("$tipo-enabled", $options_plugin_delibera) || + $options_plugin_delibera["$tipo-enabled"] == "N" // Esse tipo de notificação está desabilitada + ) { return false; } $subject_default = htmlspecialchars_decode($options_plugin_delibera["{$tipo}_assunto"]); $mensage_default = htmlspecialchars_decode($options_plugin_delibera[$tipo]).$mensage.delibera_notificar_get_mensagem_link($post, $link); - + if(!is_array($users)) { $users = get_users(); } - + if(!is_array($users)) { $users = array(); } - + $autor_id = get_current_user_id(); - + $seguiram = delibera_get_quem_seguiu($post->ID, 'ids'); - + foreach ($users as $user) { if(user_can($user->ID, 'votar') && isset($user->user_email) && $user->ID != $autor_id) { $segue = array_search($user->ID, $seguiram); - + $user_notificacoes = get_user_meta($user->ID, 'delibera_notificacoes_email', true); - + if(!$segue && ($user_notificacoes == "N" || get_user_meta($user->ID, "$tipo-enabled", true) == "N")) { continue; } - + $mensage_tmp = $mensage_default; $subject_tmp = $subject_default; - + $lang = get_user_meta($user->ID, 'user_idioma', true); - + if(strlen($lang) == 0) $lang = defined('WPLANG') && strlen(WPLANG) > 0 ? WPLANG : get_locale(); - + if(array_key_exists("$tipo-$lang", $options_plugin_delibera)) { $mensage_tmp = htmlspecialchars_decode($options_plugin_delibera["$tipo-$lang"]).$mensage; @@ -493,14 +628,14 @@ function delibera_notificar_representantes($mensage, $tipo, $post = false, $user { $subject_tmp = htmlspecialchars_decode($options_plugin_delibera["{$tipo}_assunto-$lang"]); } - + $subject_tmp = delibera_notificar_replace_vars($subject_tmp, $user, $post); $mensage_tmp = delibera_notificar_replace_vars($mensage_tmp, $user, $post); wp_mail($user->user_email, $subject_tmp, $mensage_tmp); } } } - + } function delibera_notificar_novo_comentario($comment) @@ -512,9 +647,9 @@ function delibera_notificar_novo_comentario($comment) } $seguiram = get_post_meta($comment->comment_post_ID, 'delibera_seguiram', true); $users = array(); - + if(!is_array($seguiram)) $seguiram = array(); // Ops, não tem o plugin ou não tem seguidores - + foreach ($seguiram as $hora => $seguiram) { foreach ($seguiram as $user) @@ -525,16 +660,16 @@ function delibera_notificar_novo_comentario($comment) } } } - + $autor = get_user_by('id', $post->post_author); - + $users = is_array($users) ? array_merge($users, array($autor)) : array($autor); - + $mensage = '
'.__('Autor', 'delibera').": ".$autor->display_name.'
'; $mensage .= get_comment_text($comment->comment_ID)."
"; - + $link = delibera_get_comment_link($comment); - + delibera_notificar_representantes($mensage, "mensagem_novo_comentario", $post, $users, $link); } @@ -546,13 +681,13 @@ function delibera_notificar_replace_vars($subject, $user, $postReport) { $postReport = get_post($postReport); } - + $post = $postReport; - + $opt = delibera_get_config(); - + $author = get_user_by('id', $post->post_author); - + $subject = str_ireplace("{first_name}", $user->user_firstname, $subject); $subject = str_ireplace("{last_name}", $user->user_lastname, $subject); $subject = str_ireplace("{display_name}", $user->display_name, $subject); @@ -566,7 +701,9 @@ function delibera_notificar_replace_vars($subject, $user, $postReport) $subject = str_ireplace("{post_author}", $author->user_firstname, $subject); $subject = str_ireplace("{post_content}", get_the_content(), $subject); $subject = str_ireplace("{post_excerpt}", get_the_excerpt(), $subject); - + $subject = str_ireplace("{site_url}", get_site_url(), $subject); + $subject = str_ireplace("{site_name}", get_bloginfo( 'name' ), $subject); + $campos = delibera_get_user_campos_form_registro(); if($campos > 0) { @@ -599,7 +736,7 @@ function delibera_notificar_replace_vars($subject, $user, $postReport) $valor_replace = $desc; } } - break; + break; case 'CheckBox': $valor = true; if(is_array($campo['dados']) && count($campo['dados']) > 0) @@ -629,11 +766,11 @@ function delibera_notificar_replace_vars($subject, $user, $postReport) { $valor_replace = __("Não", 'delibera'); } - break; + break; case 'Texto': default: - $valor_replace = ( get_user_meta( $user->ID,$campo['id'], true ) ); - break; + $valor_replace = ( get_user_meta( $user->ID,$campo['id'], true ) ); + break; } } $subject = str_ireplace("{".$campo['id']."}", $valor_replace, $subject); @@ -645,143 +782,143 @@ function delibera_notificar_replace_vars($subject, $user, $postReport) function delibera_nofiticar_get_tipos() { return array( - array( - 'tipo' => 'criacao_pauta', - 'mensagem' => 'mensagem_criacao_pauta', - 'dica' => __('criação de pauta', 'delibera'), - 'dica_permicao' => __('Permitir notificações na criação de uma pauta?', 'delibera'), - 'user_panel_text' => __('Receber mensagem de criação de novas pautas?', 'delibera') - ), - array( - 'tipo' => 'validacao', - 'mensagem' => 'mensagem_validacao', - 'dica' => __('quando a pauta recebe uma validação', 'delibera'), - 'dica_permicao' => __('Permitir notificações de cada validação de uma pauta?', 'delibera'), - 'user_panel_text' => __('Receber mensagem para cada validação de uma pauta?', 'delibera') - ), - array( - 'tipo' => 'validacao_concluida', - 'mensagem' => 'mensagem_validacao_concluida', - 'dica' => __('quando a pauta é validada', 'delibera'), - 'dica_permicao' => __('Permitir notificações quando a pauta é validada?', 'delibera'), - 'user_panel_text' => __('Receber mensagem quando uma pauta for aprovada?', 'delibera') - ), - array( - 'tipo' => 'pauta_recusada', - 'mensagem' => 'mensagem_pauta_recusada', - 'dica' => __('quando a pauta é recusada (não obteve validações necessárias)', 'delibera'), - 'dica_permicao' => __('Permitir notificações quando a pauta é recusada?', 'delibera'), - 'user_panel_text' => __('Receber mensagem quando uma pauta for recusada?', 'delibera') - ), - array( - 'tipo' => 'fim_prazo_validacao', - 'mensagem' => 'mensagem_fim_prazo_validacao', - 'dica' => __('', 'delibera'), - 'dica_permicao' => __('Permitir notificações quando o fim do prazo para validações estiver próximo?', 'delibera'), - 'user_panel_text' => __('Receber mensagem quando o fim do prazo para validações estiver próximo?', 'delibera') - ), - array( - 'tipo' => 'novo_comentario', - 'mensagem' => 'mensagem_novo_comentario', - 'dica' => __('novo comentário', 'delibera'), - 'dica_permicao' => __('Permitir notificações quando houver interações na discussão de uma pauta?', 'delibera'), - 'user_panel_text' => __('Receber mensagem quando houver interações na discussão de uma pauta?', 'delibera') - ), - array( - 'tipo' => 'discussao_concluida', - 'mensagem' => 'mensagem_discussao_concluida', - 'dica' => __('', 'delibera'), - 'dica_permicao' => __('Permitir notificações quando a discussão for encerrada?', 'delibera'), - 'user_panel_text' => __('Receber mensagem quando a discussão for encerrada?', 'delibera') - ), - array( - 'tipo' => 'fim_prazo_discussao', - 'mensagem' => 'mensagem_fim_prazo_discussao', - 'dica' => __('', 'delibera'), - 'dica_permicao' => __('Permitir notificações quando o fim do prazo para discussão estiver próximo?', 'delibera'), - 'user_panel_text' => __('Receber mensagem quando o fim do prazo para discussão estiver próximo?', 'delibera') - ), - array( - 'tipo' => 'discussao_concluida_rel', - 'mensagem' => 'mensagem_discussao_concluida_rel', - 'dica' => __('', 'delibera'), - 'dica_permicao' => __('Permitir notificações quando a discussão for encerrada?', 'delibera'), - 'user_panel_text' => __('Receber mensagem quando a discussão for encerrada?', 'delibera') - ), - array( - 'tipo' => 'relatoria_concluida', - 'mensagem' => 'mensagem_relatoria_concluida', - 'dica' => __('', 'delibera'), - 'dica_permicao' => __('Permitir notificações quando a relatoria for encerrada?', 'delibera'), - 'user_panel_text' => __('Receber mensagem quando a relatoria for encerrada?', 'delibera') - ), - array( - 'tipo' => 'fim_prazo_relatoria', - 'mensagem' => 'mensagem_fim_prazo_relatoria', - 'dica' => __('', 'delibera'), - 'dica_permicao' => __('Permitir notificações quando o fim do prazo para relatoria estiver próximo?', 'delibera'), - 'user_panel_text' => __('Receber mensagem quando o fim do prazo para relatoria estiver próximo?', 'delibera') - ), - array( - 'tipo' => 'fim_prazo_votacao', - 'mensagem' => 'mensagem_fim_prazo_votacao', - 'dica' => __('', 'delibera'), - 'dica_permicao' => __('Permitir notificações quando o fim do prazo para votação estiver próximo?', 'delibera'), - 'user_panel_text' => __('Receber mensagem quando o fim do prazo para votação estiver próximo?', 'delibera') - ), - array( - 'tipo' => 'votacao_concluida', - 'mensagem' => 'mensagem_votacao_concluida', - 'dica' => __('', 'delibera'), - 'dica_permicao' => __('Permitir notificações quando a votação for encerrada?', 'delibera'), - 'user_panel_text' => __('Receber mensagem quando a votação for encerrada?', 'delibera') - ) - ); + array( + 'tipo' => 'criacao_pauta', + 'mensagem' => 'mensagem_criacao_pauta', + 'dica' => __('criação de pauta', 'delibera'), + 'dica_permicao' => __('Permitir notificações na criação de uma pauta?', 'delibera'), + 'user_panel_text' => __('Receber mensagem de criação de novas pautas?', 'delibera') + ), + array( + 'tipo' => 'validacao', + 'mensagem' => 'mensagem_validacao', + 'dica' => __('quando a pauta recebe uma validação', 'delibera'), + 'dica_permicao' => __('Permitir notificações de cada validação de uma pauta?', 'delibera'), + 'user_panel_text' => __('Receber mensagem para cada validação de uma pauta?', 'delibera') + ), + array( + 'tipo' => 'validacao_concluida', + 'mensagem' => 'mensagem_validacao_concluida', + 'dica' => __('quando a pauta é validada', 'delibera'), + 'dica_permicao' => __('Permitir notificações quando a pauta é validada?', 'delibera'), + 'user_panel_text' => __('Receber mensagem quando uma pauta for aprovada?', 'delibera') + ), + array( + 'tipo' => 'pauta_recusada', + 'mensagem' => 'mensagem_pauta_recusada', + 'dica' => __('quando a pauta é recusada (não obteve validações necessárias)', 'delibera'), + 'dica_permicao' => __('Permitir notificações quando a pauta é recusada?', 'delibera'), + 'user_panel_text' => __('Receber mensagem quando uma pauta for recusada?', 'delibera') + ), + array( + 'tipo' => 'fim_prazo_validacao', + 'mensagem' => 'mensagem_fim_prazo_validacao', + 'dica' => __('', 'delibera'), + 'dica_permicao' => __('Permitir notificações quando o fim do prazo para validações estiver próximo?', 'delibera'), + 'user_panel_text' => __('Receber mensagem quando o fim do prazo para validações estiver próximo?', 'delibera') + ), + array( + 'tipo' => 'novo_comentario', + 'mensagem' => 'mensagem_novo_comentario', + 'dica' => __('novo comentário', 'delibera'), + 'dica_permicao' => __('Permitir notificações quando houver interações na discussão de uma pauta?', 'delibera'), + 'user_panel_text' => __('Receber mensagem quando houver interações na discussão de uma pauta?', 'delibera') + ), + array( + 'tipo' => 'discussao_concluida', + 'mensagem' => 'mensagem_discussao_concluida', + 'dica' => __('', 'delibera'), + 'dica_permicao' => __('Permitir notificações quando a discussão for encerrada?', 'delibera'), + 'user_panel_text' => __('Receber mensagem quando a discussão for encerrada?', 'delibera') + ), + array( + 'tipo' => 'fim_prazo_discussao', + 'mensagem' => 'mensagem_fim_prazo_discussao', + 'dica' => __('', 'delibera'), + 'dica_permicao' => __('Permitir notificações quando o fim do prazo para discussão estiver próximo?', 'delibera'), + 'user_panel_text' => __('Receber mensagem quando o fim do prazo para discussão estiver próximo?', 'delibera') + ), + array( + 'tipo' => 'discussao_concluida_rel', + 'mensagem' => 'mensagem_discussao_concluida_rel', + 'dica' => __('', 'delibera'), + 'dica_permicao' => __('Permitir notificações quando a discussão for encerrada?', 'delibera'), + 'user_panel_text' => __('Receber mensagem quando a discussão for encerrada?', 'delibera') + ), + array( + 'tipo' => 'relatoria_concluida', + 'mensagem' => 'mensagem_relatoria_concluida', + 'dica' => __('', 'delibera'), + 'dica_permicao' => __('Permitir notificações quando a relatoria for encerrada?', 'delibera'), + 'user_panel_text' => __('Receber mensagem quando a relatoria for encerrada?', 'delibera') + ), + array( + 'tipo' => 'fim_prazo_relatoria', + 'mensagem' => 'mensagem_fim_prazo_relatoria', + 'dica' => __('', 'delibera'), + 'dica_permicao' => __('Permitir notificações quando o fim do prazo para relatoria estiver próximo?', 'delibera'), + 'user_panel_text' => __('Receber mensagem quando o fim do prazo para relatoria estiver próximo?', 'delibera') + ), + array( + 'tipo' => 'fim_prazo_votacao', + 'mensagem' => 'mensagem_fim_prazo_votacao', + 'dica' => __('', 'delibera'), + 'dica_permicao' => __('Permitir notificações quando o fim do prazo para votação estiver próximo?', 'delibera'), + 'user_panel_text' => __('Receber mensagem quando o fim do prazo para votação estiver próximo?', 'delibera') + ), + array( + 'tipo' => 'votacao_concluida', + 'mensagem' => 'mensagem_votacao_concluida', + 'dica' => __('', 'delibera'), + 'dica_permicao' => __('Permitir notificações quando a votação for encerrada?', 'delibera'), + 'user_panel_text' => __('Receber mensagem quando a votação for encerrada?', 'delibera') + ) + ); } function delibera_nofitica_user_panel($forms) { /*$campos = array( - array( - 'novo' => true, - 'id' => 'mensagem_criacao_pauta-enabled', - 'nome' => __('Receber mensagem de criação de novas pauta?', 'delibera'), - 'registro' => false, - 'tipo_painel' => 'CheckBox', - 'dados' => array("S" => "S", "N" => "N") - ), - array( - 'novo' => true, - 'id' => 'mensagem_mudanca_situacao-enabled', - 'nome' => __('Receber mensagem nova situação das pautas?', 'delibera'), - 'registro' => false, - 'tipo_painel' => 'CheckBox', - 'dados' => array("S" => "S", "N" => "N") - ), - array( - 'novo' => true, - 'id' => 'mensagem_fim_prazo-enabled', - 'nome' => __('Receber mensagem fim de prazo próximo?', 'delibera'), - 'registro' => false, - 'tipo_painel' => 'CheckBox', - 'dados' => array("S" => "S", "N" => "N") - ) - );*/ + array( + 'novo' => true, + 'id' => 'mensagem_criacao_pauta-enabled', + 'nome' => __('Receber mensagem de criação de novas pauta?', 'delibera'), + 'registro' => false, + 'tipo_painel' => 'CheckBox', + 'dados' => array("S" => "S", "N" => "N") + ), + array( + 'novo' => true, + 'id' => 'mensagem_mudanca_situacao-enabled', + 'nome' => __('Receber mensagem nova situação das pautas?', 'delibera'), + 'registro' => false, + 'tipo_painel' => 'CheckBox', + 'dados' => array("S" => "S", "N" => "N") + ), + array( + 'novo' => true, + 'id' => 'mensagem_fim_prazo-enabled', + 'nome' => __('Receber mensagem fim de prazo próximo?', 'delibera'), + 'registro' => false, + 'tipo_painel' => 'CheckBox', + 'dados' => array("S" => "S", "N" => "N") + ) + );*/ if(!is_array($forms)) $forms = array(); - + foreach (delibera_nofiticar_get_tipos() as $notif) { $forms[] = array( - 'novo' => true, - 'id' => $notif['mensagem'].'-enabled', - 'nome' => $notif['user_panel_text'], - 'registro' => false, - 'tipo_painel' => 'CheckBox', - 'dados' => array("S" => "S", "N" => "N"), - 'default' => 'S' - ); + 'novo' => true, + 'id' => $notif['mensagem'].'-enabled', + 'nome' => $notif['user_panel_text'], + 'registro' => false, + 'tipo_painel' => 'CheckBox', + 'dados' => array("S" => "S", "N" => "N"), + 'default' => 'S' + ); } - + return $forms; } add_filter('delibera_user_painel_campos', 'delibera_nofitica_user_panel', 10, 1) diff --git a/delibera_permission.php b/delibera_permission.php new file mode 100644 index 0000000..5190893 --- /dev/null +++ b/delibera_permission.php @@ -0,0 +1,60 @@ +ID) == -1) { + return false; + } else if (is_multisite() && $options['todos_usuarios_logados_podem_participar'] == 'S') { + return is_user_logged_in(); + } else { + return current_user_can($permissao); + } +} + +/** + * Verifica se pauta está aberta para comentários + * + * @param string $postID + * + * @package Pauta + */ +function delibera_can_comment($postID = '') +{ + if(is_admin()) return true; + + if(is_null($postID)) + { + $post = get_post($postID); + $postID = $post->ID; + } + + $situacoes_validas = array('validacao' => true, 'discussao' => true, 'emvotacao' => true, 'elegerelator' => true); + $situacao = delibera_get_situacao($postID); + + if(array_key_exists($situacao->slug, $situacoes_validas)) + { + return delibera_current_user_can_participate(); + } + elseif($situacao->slug == 'relatoria') + { + return current_user_can('relatoria'); + } + return false; +} \ No newline at end of file diff --git a/delibera_plan.php b/delibera_plan.php index adc87ac..8160529 100644 --- a/delibera_plan.php +++ b/delibera_plan.php @@ -198,4 +198,23 @@ function delibera_plan_config_page() add_action('delibera_config_page_extra', 'delibera_plan_config_page'); +function delibera_get_plan_config() +{ + $plan = 'N'; + + if( is_multisite() && get_current_blog_id() != 1 ) + { + switch_to_blog(1); + $opt = delibera_get_config(); + $plan = $opt['plan_restriction']; + restore_current_blog(); + } + else + { + $opt = delibera_get_config(); + $plan = $opt['plan_restriction']; + } + + return $plan; +} ?> diff --git a/delibera_theme_selector.php b/delibera_plan_theme.php similarity index 100% rename from delibera_theme_selector.php rename to delibera_plan_theme.php diff --git a/delibera_registered_users_only.php b/delibera_plan_users_only.php similarity index 100% rename from delibera_registered_users_only.php rename to delibera_plan_users_only.php diff --git a/delibera_relatorio.php b/delibera_relatorio.php index bdf2f22..521d578 100644 --- a/delibera_relatorio.php +++ b/delibera_relatorio.php @@ -1,4 +1,9 @@

- +

- +

- 'pauta', 'post_status' => 'publish')); -$comments = array(); +//$pautas = get_posts(array('post_type' => 'pauta', 'post_status' => 'publish')); +$pautas_query = new WP_Query(array( + 'post_type' => 'pauta', + 'post_status' => 'publish', + 'posts_per_page' => -1 +)); -foreach ($pautas as $pauta) { - $comments = array_merge( - $comments, - delibera_get_comments($pauta->ID, array('discussao', 'encaminhamento', 'encaminhamento_selecionado', 'resolucao')) - ); -} +$comments = array(); +/* @var $pauta WP_POST */ -foreach ($comments as $comment) { - $situacao = delibera_get_situacao($comment->comment_post_ID); - - $comment->pauta_title = get_the_title($comment->comment_post_ID); - $comment->pauta_status = $situacao->name; - $comment->type = delibera_get_comment_type_label($comment, false, false); - $comment->link = get_comment_link($comment); - $comment->concordaram = (int) get_comment_meta($comment->comment_ID, 'delibera_numero_curtir', true); - $comment->discordaram = (int) get_comment_meta($comment->comment_ID, 'delibera_numero_discordar', true); - $comment->votes_count = (int) get_comment_meta($comment->comment_ID, "delibera_comment_numero_votos", true);; +if($pautas_query->have_posts()) +{ + global $post; + while ($pautas_query->have_posts()) + { + $pautas_query->the_post(); + $pauta = $post; + + $situacao = delibera_get_situacao($pauta->ID); + $comment_fake = new stdClass(); + $comment_fake->pauta_title = get_the_title($pauta->ID); + $comment_fake->pauta_status = $situacao->name; + $comment_fake->type = 'Pauta'; + $comment_fake->link = get_permalink($pauta); + $comment_fake->concordaram = (int) get_post_meta($pauta->ID, 'delibera_numero_curtir', true); + $comment_fake->discordaram = (int) get_post_meta($pauta->ID, 'delibera_numero_discordar', true); + $comment_fake->votes_count = (int) get_post_meta($pauta->ID, "delibera_numero_comments_votos", true); + $comment_fake->comment_author = get_the_author(); + $comment_fake->comment_author_email = get_the_author_meta('email', $pauta->post_author); + $comment_fake->comment_content = get_the_content(); + $temas = wp_get_object_terms($pauta->ID, 'tema', array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'names')); + $comment_fake->temas = is_array($temas) ? implode(', ', $temas) : ''; + $tags = wp_get_object_terms($pauta->ID, 'post_tag', array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'names')); + $comment_fake->tags = is_array($tags) ? implode(', ', $tags) : ''; + $cats = wp_get_object_terms($pauta->ID, 'category', array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'names')); + $comment_fake->cats = is_array($cats) ? implode(', ', $cats) : ''; + $comment_fake->delibera_dates = \Delibera\Flow::getDeadlineDates($pauta->ID); + + $comment_tmp = delibera_get_comments($pauta->ID, array('discussao', 'encaminhamento', 'encaminhamento_selecionado', 'resolucao')); + $comments = array_merge( + $comments, + array($comment_fake), + $comment_tmp + ); + } + foreach ($comments as $comment) //TODO with this get bigger, we will have memory problem, better read pauta, comments and write, read next... + { + if($comment->type == 'Pauta') continue; + + $situacao = delibera_get_situacao($comment->comment_post_ID); + $comment->pauta_title = get_the_title($comment->comment_post_ID); + $comment->pauta_status = $situacao->name; + $comment->type = delibera_get_comment_type_label($comment, false, false); + $comment->link = get_comment_link($comment); + $comment->concordaram = (int) get_comment_meta($comment->comment_ID, 'delibera_numero_curtir', true); + $comment->discordaram = (int) get_comment_meta($comment->comment_ID, 'delibera_numero_discordar', true); + $comment->votes_count = (int) get_comment_meta($comment->comment_ID, "delibera_comment_numero_votos", true); + $comment->temas = ''; + $comment->tags = ''; + $comment->cats = ''; + } } header('Pragma: public'); @@ -43,44 +84,73 @@ header('Content-Transfer-Encoding: none'); header('Content-Type: application/vnd.ms-excel; charset=UTF-8'); // This should work for IE & Opera header("Content-type: application/x-msexcel; charset=UTF-8"); // This should work for the rest -header('Content-Disposition: attachment; filename=relatorio.xls'); +header('Content-Disposition: attachment; filename='.date('Ymd_His').'_'.__('relatorio', 'delibera').'.xls'); -echo utf8_decode(" - - - - - - - - - - - - - " -); - -?> - +ob_start(); - - +$situacoes = get_terms('situacao', array('hide_empty' => false)); +?> +
PautaSituaçãoNomeE-mailTipo de comentárioComentárioLinkConcordaramDiscordaramVotos
- - - - - - - - -
- - - - - - -
pauta_title; ?>pauta_status; ?>comment_author; ?>comment_author_email; ?>type; ?>comment_content; ?>link; ?>concordaram; ?>discordaram; ?>votes_count; ?>
\ No newline at end of file + + + + + + + + + + + + + + + + name; ?> + + + pauta_title; ?> + pauta_status; ?> + comment_author; ?> + comment_author_email; ?> + type; ?> + comment_content; ?> + link; ?> + concordaram; ?> + discordaram; ?> + votes_count; ?> + temas; ?> + tags; ?> + cats; ?>delibera_dates)) + {?> + delibera_dates)); ?>slug, $comment->delibera_dates)) + {?> + delibera_dates[$situacao->slug] == -1 ? '' : $comment->delibera_dates[$situacao->slug]; ?> + + + diff --git a/delibera_seguir.php b/delibera_seguir.php index dd21fc4..a9d127c 100644 --- a/delibera_seguir.php +++ b/delibera_seguir.php @@ -1,9 +1,21 @@ \ No newline at end of file diff --git a/delibera_setup.php b/delibera_setup.php index f480b88..f16956c 100644 --- a/delibera_setup.php +++ b/delibera_setup.php @@ -44,10 +44,10 @@ function delibera_install_roles() $opt = delibera_get_config(); update_option('delibera-config', $opt); - if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'delibera_roles.php')) + if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'delibera_conf_roles.php')) { $delibera_permissoes = array(); - require_once __DIR__.DIRECTORY_SEPARATOR.'delibera_roles.php'; + include __DIR__.DIRECTORY_SEPARATOR.'delibera_conf_roles.php'; delibera_roles_install($delibera_permissoes); } } diff --git a/delibera_shortcodes.php b/delibera_shortcodes.php index 4ac732c..204f781 100644 --- a/delibera_shortcodes.php +++ b/delibera_shortcodes.php @@ -1,109 +1,26 @@ -'; - foreach ( $wp_posts as $wp_post ) - { - $post = $wp_post; - include 'delibera_loop_pauta.php'; - } - echo '
'; - $post = $old; - - return ''; // Retornar código da representação -} -add_shortcode( 'delibera_lista_de_propostas', 'delibera_replace_propostas' ); - -function delibera_replace_pautas($matches) -{ - $temp = explode(',', $matches[1]); // configurações da shorttag - $count = count($temp); - - $param = array(); // TODO Tratar Parametros - - $html = delibera_get_pautas($param); - $wp_posts = $html; - global $post; - $old = $post; - echo '
'; - foreach ( $wp_posts as $wp_post ) - { - $post = $wp_post; - include 'delibera_loop_pauta.php'; - } - echo '
'; - $post = $old; - - return ''; // Retornar código da representação -} -add_shortcode( 'delibera_lista_de_pautas', 'delibera_replace_pautas' ); - -function delibera_replace_resolucoes($matches) -{ - $temp = explode(',', $matches[1]); // configurações da shorttag - $count = count($temp); - - $param = array(); // TODO Tratar Parametros - - $html = delibera_get_resolucoes($param); - $wp_posts = $html; - global $post; - $old = $post; - echo '
'; - foreach ( $wp_posts as $wp_post ) - { - $post = $wp_post; - include 'delibera_loop_pauta.php'; - } - echo '
'; - $post = $old; - - return ''; // Retornar código da representação -} -add_shortcode( 'delibera_lista_de_resolucoes', 'delibera_replace_resolucoes' ); - function delibera_replace_agendamentos($matches) -{ +{ global $wp_filter; $temp = explode(',', $matches[1]); // configurações da shorttag $count = count($temp); - + $param = array(); // TODO Tratar Parametros - + $html = print_r($wp_filter, true); - + return $html; // Retornar código da representação } add_shortcode( 'delibera_lista_de_agendamentos', 'delibera_replace_agendamentos' ); -function delibera_replace_timeline($args) -{ - $atts = array('post_id' => false, 'tipo_data' => false); - $atts = array_merge($atts, $args); - - return delibera_timeline($atts['post_id'], $atts['tipo_data']); -} -add_shortcode( 'delibera_timeline', 'delibera_replace_timeline' ); - function delibera_replace_like($matches) { $temp = explode(',', $matches[1]); // configurações da shorttag $count = count($temp); $param = array(); // TODO Tratar Parametros - + return delibera_gerar_curtir(get_the_ID()); } add_shortcode( 'delibera_like', 'delibera_replace_like' ); @@ -113,7 +30,7 @@ function delibera_replace_unlike($matches) $temp = explode(',', $matches[1]); // configurações da shorttag $count = count($temp); $param = array(); // TODO Tratar Parametros - + return delibera_gerar_discordar(get_the_ID()); } add_shortcode( 'delibera_unlike', 'delibera_replace_unlike' ); @@ -123,7 +40,7 @@ function delibera_replace_seguir($matches) $temp = explode(',', $matches[1]); // configurações da shorttag $count = count($temp); $param = array(); // TODO Tratar Parametros - + return delibera_gerar_seguir(get_the_ID()); } add_shortcode( 'delibera_seguir', 'delibera_replace_seguir' ); @@ -137,12 +54,11 @@ function delibera_replace_basear($args) $server = $_SERVER['SERVER_NAME']; $endereco = $_SERVER ['REQUEST_URI']; $site_url = "http".(array_key_exists('HTTPS', $_SERVER))."://".$server.$endereco; - + $html = ''; - + return $html; } add_shortcode( 'delibera_basear', 'delibera_replace_basear' ); - // End Parse shorttag ?> \ No newline at end of file diff --git a/delibera_taxs.php b/delibera_taxs.php index 1543980..d82473f 100644 --- a/delibera_taxs.php +++ b/delibera_taxs.php @@ -1,5 +1,2 @@ \ No newline at end of file diff --git a/delibera_template.php b/delibera_template.php index 660e5e2..7916149 100644 --- a/delibera_template.php +++ b/delibera_template.php @@ -1,15 +1,28 @@ \ No newline at end of file + add_submenu_page($base_page, __('Templates','delibera'), __('Templates Padrões','delibera'), 'manage_options', 'delibera-templates', 'delibera_template_page' ); +} +add_action('delibera_menu_itens', 'delibera_template_menu_action', 10, 1); + +/** + * Carrega template de listagem de pautas + * + * @deprecated - não tem nenhuma implementação, está comentado + */ +function delibera_template_page() +{ + //load_template(dirname(__FILE__).DIRECTORY_SEPARATOR.'themes'.DIRECTORY_SEPARATOR.'archive-pauta.php', true); +} \ No newline at end of file diff --git a/delibera_topic.php b/delibera_topic.php new file mode 100644 index 0000000..19d796c --- /dev/null +++ b/delibera_topic.php @@ -0,0 +1,610 @@ + 0) + { + $ret = array_pop($situacao); + } + + if(!is_object($ret)) // if term situacao does not exists + { + $ret = new stdClass(); + $ret->slug = ''; + $ret->name = ''; + } + + if(has_filter('delibera_get_situacao')) + { + return apply_filters('delibera_get_situacao', $ret); + } + + return $ret; +} + +/** + * Retorna o label do botão com a situação da + * pauta. + * + * @param int $postId + * @return string + */ +function delibera_get_situation_button($postId) +{ + $situacao = get_the_terms($postId, 'situacao'); + + if (is_array($situacao) && !empty($situacao)) + { + $situacao = array_pop($situacao); + } + return apply_filters('delibera_situation_button_text', $situacao->slug); +} + +function delibera_update_edit_form() { + echo ' enctype="multipart/form-data"'; +} // end update_edit_form +add_action('post_edit_form_tag', 'delibera_update_edit_form'); + +function delibera_pauta_meta() +{ + global $post; + + $custom = get_post_custom($post->ID); + $options_plugin_delibera = delibera_get_config(); + + if(!is_array($custom)) $custom = array(); + $situacao = delibera_get_situacao($post->ID); + + $pauta_pdf_file = get_post_meta($post->ID, 'pauta_pdf_contribution', true); + + // Recupera arquivo caso já tenha sido adicionados + $pdf_html = "

"; + if( $pauta_pdf_file ) { + $pdf_html .= "Arquivo Atual
"; + } + $pdf_html .= "

"; + echo $pdf_html; + + $now = strtotime(date('Y/m/d')." 11:59:59"); + + if ( + $options_plugin_delibera['representante_define_prazos'] == "N" && + !($post->post_status == 'draft' || + $post->post_status == 'auto-draft' || + $post->post_status == 'pending') + ) + { + $disable_edicao = 'readonly="readonly"'; + } else { + $disable_edicao = ''; + } + + do_action('delibera_topic_meta', $post, $custom, $options_plugin_delibera, $situacao, $disable_edicao); + +} + + +function delibera_publish_pauta($post) +{ + $postID = $post->ID; + if(get_post_type( $postID ) != "pauta") + { + return $postID; + } + + $opt = delibera_get_config(); + + do_action('delibera_publish_pauta', $postID, $opt); + + $curtir = get_post_meta($postID, 'delibera_numero_curtir', true); + if($curtir == "" || $curtir === false || is_null($curtir)) + { + $events_meta['delibera_numero_comments_padroes'] = 0; + $events_meta['delibera_numero_curtir'] = 0; + $events_meta['delibera_curtiram'] = array(); + $events_meta['delibera_numero_discordar'] = 0; + $events_meta['delibera_discordaram'] = array(); + $events_meta['delibera_numero_seguir'] = 0; + $events_meta['delibera_seguiram'] = array(); + } + + delibera_notificar_nova_pauta($postID); +} +add_action ('draft_to_publish', 'delibera_publish_pauta', 1, 1); +add_action ('pending_to_publish', 'delibera_publish_pauta', 1, 1); +add_action ('auto-draft_to_publish', 'delibera_publish_pauta', 1, 1); +add_action ('new_to_publish', 'delibera_publish_pauta', 1, 1); + +/** + * + * @param unknown $data + * @param unknown $postarr + */ +function delibera_check_post_data($data, $postarr) +{ + $opt = delibera_get_config(); + $errors = array(); + $autosave = ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ); + if(get_post_type() == 'pauta' && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'trash')) + { + + $errors = apply_filters('delibera_check_post_data', $errors, $opt, $autosave); + + if(count($errors) == 0) + { + return $data; + } + else + { + //wp_die(__('Erro ao salvar dados da pauta, faltando informações de prazos e validações mínimas!','delibera')); + wp_die(implode("
", $errors)); + } + } + return $data; +} + +add_filter('wp_insert_post_data', 'delibera_check_post_data', 10, 2); + +/** + * + * Retorna post do tipo pauta em uma determinada situacao, usando um filtro + * @param array $filtro + * @param string $situacao + * + * @return array of posts of type pauta + * + */ +function delibera_get_pautas_em($filtro = array(), $situacao = false) +{ + $filtro['post_type'] = "pauta"; + $filtro['post_status'] = "publish"; + $tax_query = array(); + + if(array_key_exists("tax_query", $filtro) && $situacao !== false) + { + $tax_query = $filtro['tax_query']; + $tax_query['relation'] = 'AND'; + } + if($situacao !== false) + { + $tax_query[] = array( + 'taxonomy' => 'situacao', + 'field' => 'slug', + 'terms' => $situacao + ); + $filtro['tax_query'] = $tax_query; + } + return get_posts($filtro); +} + +function delibera_des_filtro_qtranslate($where) +{ + if(is_archive()) + { + global $q_config, $wpdb; + if($q_config['hide_untranslated'] && !is_singular()) { + $where = str_replace(" AND $wpdb->posts.post_content LIKE '%%'", '', $where); + } + } + return $where; +} + +add_filter('posts_where_request', 'delibera_des_filtro_qtranslate', 11); + +/** + * + * Save o post da pauta + * @param $post_id int + * @param $post + */ +function delibera_save_post($post_id, $post) +{ + if(get_post_type( $post_id ) != "pauta") + { + return $post_id; + } + $opt = delibera_get_config(); + $autosave = ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ); + + $events_meta = array(); + + + + /* ######### START ######### */ + /* ######### FOR PDF UPLOAD FILE ######### */ + // Setup the array of supported file types. In this case, it's just PDF. + $supported_types = array('application/pdf'); + + if (! $autosave && array_key_exists('pauta_pdf_contribution', $_FILES)) + { + // Get the file type of the upload + $arr_uploaded_file_type = wp_check_filetype ( basename ( $_FILES ['pauta_pdf_contribution'] ['name'] ) ); + $uploaded_file_type = $arr_uploaded_file_type ['type']; + + if (isset ( $_FILES ['pauta_pdf_contribution'] ['name'] ) && $_FILES ['pauta_pdf_contribution'] ['name'] != '') { + if (! in_array ( $uploaded_file_type, $supported_types )) { + // TODO: Improve this message and avoid wp_die + wp_die ( "O arquivo para web não é um PDF (formato permitido)." ); + } + + // Use the WordPress API to upload the file + $upload_pauta_pdf = wp_upload_bits ( $_FILES ['pauta_pdf_contribution'] ['name'], null, file_get_contents ( $_FILES ['pauta_pdf_contribution'] ['tmp_name'] ) ); + + if (isset ( $upload_pauta_pdf ['error'] ) && $upload_pauta_pdf ['error'] != 0) { + $events_meta ['pauta_pdf_contribution'] = none; + wp_die ( 'Erro ao salvar arquivo para Web. O erro foi: ' . $upload_pauta_pdf ['error'] ); + } else { + $events_meta ['pauta_pdf_contribution'] = $upload_pauta_pdf ['url']; + + global $wpdb; + + $wpdb->query ( $wpdb->prepare ( "UPDATE " . $wpdb->prefix . "posts SET post_content=%s WHERE ID=%d", '', $post->ID ) ); + } + } + } + /* ######### FOR PDF UPLOAD FILE ######### */ + /* ######### END ######### */ + + $events_meta = apply_filters('delibera_save_post_metas', $events_meta, $opt, $post_id); + + foreach ($events_meta as $key => $value) // Buscar dados + { + update_post_meta($post->ID, $key, $value); // Atualiza + } + + do_action('delibera_save_post', $post_id, $post, $opt); + + if( + array_key_exists('delibera_fim_prazo', $_POST) && + $_POST['delibera_fim_prazo'] == 'S' && + current_user_can('forcar_prazo') + ) + { + \Delibera\Flow::forcarFimPrazo($post->ID); + } + +} + +add_action ('save_post', 'delibera_save_post', 1, 2); + +/*** + * Verifica se as pautas devem suportar sugestão de encaminhamento ou se + * as propostas entram apenas como opinião. Muito útil para consultas públicas. + * + * @return bool + */ +function delibera_pautas_suportam_encaminhamento() +{ + $options = delibera_get_config(); + + if ( $options['pauta_suporta_encaminhamento'] == 'S' ) { + return true; + } else { + return false; + } +} + +add_action('init', 'delibera_nova_pauta_create_action'); +function delibera_nova_pauta_create_action() +{ + $opt = delibera_get_config(); + if($opt['criar_pauta_pelo_front_end'] == 'S' && is_user_logged_in() && + isset($_POST['_wpnonce']) && + wp_verify_nonce($_POST['_wpnonce'], 'delibera_nova_pauta')) + { + $title = $_POST['nova-pauta-titulo']; + $content = $_POST['nova-pauta-conteudo']; + $excerpt = $_POST['nova-pauta-resumo']; + + $pauta = array(); + $pauta['post_title'] = $title; + $pauta['post_excerpt'] = $excerpt; + $pauta['post_type'] = 'pauta'; + + // Check if there is any file uploaded + // If there is any, then ignore 'content' and use File. + // else do add 'pauta' with the text content + if(! empty($_FILES['post_pdf_contribution']['name'])) + { + // Setup the array of supported file types. In this case, it's just + // PDF. + $supported_types = array( + 'application/pdf' + ); + // Get the file type of the upload + $pdf_contribution = wp_check_filetype( + basename($_FILES['post_pdf_contribution']['name'])); + $sent_file_type = $pdf_contribution['type']; + // Check if the type is supported. If not, throw an error. + if(! in_array($sent_file_type, $supported_types)) + { + // TODO: Improve this message and avoid wp_die + wp_die("O arquivo para web não é um PDF (formato permitido)."); + } + $uploaded_file = wp_upload_bits( + $_FILES['pauta_pdf_contribution']['name'], null, + file_get_contents( + $_FILES['pauta_pdf_contribution']['tmp_name'])); + if(isset($uploaded_file['error']) && $uploaded_file['error'] != 0) + { + wp_die( + 'Erro ao salvar arquivo para Web. O erro foi: ' . + $upload['error']); + } + else + { + $pauta['pauta_pdf_contribution'] = $uploaded_file['url']; + } + } + else + { + $pauta['post_content'] = $content; + } + + // para que a situação da pauta seja criada corretamente, + // é necessário criar a pauta como rascunho para depois publicar no + // final desta função + $pauta['post_status'] = 'draft'; + + $pauta_id = wp_insert_post($pauta); + + if(is_int($pauta_id) && $pauta_id > 0) + { + + do_action('delibera_create_pauta_frontend', $opt); + + // isto é necessário por causa do if da função + // delibera_publish_pauta() + $_POST['publish'] = 'Publicar'; + $_POST['prev_status'] = 'draft'; + + // verifica se todos os temas enviados por post são válidos + $temas = get_terms('tema', array( + 'hide_empty' => true + )); + $temas_ids = array(); + + if(isset($_POST['tema']) && is_array($_POST['tema'])) + foreach($temas as $tema) + if(in_array($tema->term_id, $_POST['tema'])) + $temas_ids[] = $tema->term_id; + + // coloca o s termos de temas no post + wp_set_post_terms($pauta_id, $temas_ids, 'tema'); + + // publica o post + wp_publish_post($pauta_id); + + // isto serve para criar o slug corretamente, + // já que no wp _ insert_post não cria o slug quando o status é + // draft e o wp_publish_post tb não cria o slug + unset($pauta['post_status']); + $pauta['ID'] = $pauta_id; + $pauta['post_name'] = sanitize_post_field('post_name', $title, + $pauta_id, 'save'); + wp_update_post($pauta); + + // redireciona para a pauta criada + $permalink = get_post_permalink($pauta_id); + wp_safe_redirect($permalink); + die(); + } + } +} + +/** + * + * @param array $args + * array with: + * post_title, + * post_excerpt, + * post_content, + * redirect (true or false), + * redirect_to (url to redirect or will redirect to new created pauta, + * delibera_flow is a comma separated list of situations, install + * default is: 'validacao,discussao,relatoria,emvotacao,comresolucao' + * modules config, check function savePostMetas on each module will be used, ex: + * prazo_validacao: date format dd/mm/yyyy, + * min_validacoes int ex: 10, + * prazo_discussao: date format dd/mm/yyyy, + * prazo_relatoria: date format dd/mm/yyyy, + * prazo_votacao: date format dd/mm/yyyy, + * + */ +function deliberaCreateTopic($args = array()) +{ + $opt = delibera_get_config(); + if($opt['criar_pauta_pelo_front_end'] == 'S' && is_user_logged_in() ) + { + $defaults = array( + 'post_title' => '', + 'post_excerpt' => '', + 'post_content' => '', + 'redirect' => false, + 'redirect_to' => '', + 'delibera_flow' => $opt['delibera_flow'], + ); + + $args = array_merge($defaults, $args); + if(!is_array($args['delibera_flow'])) $args['delibera_flow'] = explode(',', $args['delibera_flow']); + + $title = $args['post_title']; + $content = $args['post_content']; + $excerpt = $args['post_excerpt']; + + $pauta = array(); + $pauta['post_title'] = $title; + $pauta['post_excerpt'] = $excerpt; + $pauta['post_type'] = 'pauta'; + $pauta['post_name'] = sanitize_title($title); + $pauta['post_content'] = $content; + + // para que a situação da pauta seja criada corretamente, + // é necessário criar a pauta como rascunho para depois publicar no + // final desta função + $pauta['post_status'] = 'draft'; + if(array_key_exists('tags_input', $args)) + { + $pauta['tags_input'] = $args['tags_input']; + } + if(array_key_exists('tags_input', $args)) + { + $pauta['tags_input'] = $args['tags_input']; + } + if(array_key_exists('post_category', $args)) + { + $pauta['post_category'] = $args['post_category']; + } + + // Load defaults modules values at $_POST + do_action('delibera_create_pauta_frontend', $opt); + + // Load args values at $_POST for save_meta action + foreach (array_diff_key($args, $defaults) as $key => $arg) + { + if(array_key_exists($key, $_POST)) + { + $_POST[$key] = $args[$key]; + } + } + $_POST['delibera_flow'] = $args['delibera_flow']; + $pauta_id = 0; + + if(array_key_exists('post_id', $args) && $args['post_id'] > 0) + { + $pauta_id = $args['post_id']; + } + else + { + $pauta_id = wp_insert_post($pauta); + } + + if(is_int($pauta_id) && $pauta_id > 0) + { + // isto é necessário por causa do if da função + // delibera_publish_pauta() + $_POST['publish'] = 'Publicar'; + $_POST['prev_status'] = 'draft'; + + //TODO tratar as categorias e tags + deliberaAddTerms($pauta_id, $args, 'tema', true); + + if(defined('WP_DEBUG') && WP_DEBUG) + { + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + error_reporting(E_ALL & ~E_STRICT); + } + + // publica o post + wp_publish_post($pauta_id); + + // isto serve para criar o slug corretamente, + // já que no wp _ insert_post não cria o slug quando o status é + // draft e o wp_publish_post tb não cria o slug + unset($pauta['post_status']); + $pauta['ID'] = $pauta_id; + wp_update_post($pauta); + + if(array_key_exists('redirect', $args) && $args['redirect']) + { + if(array_key_exists('redirect_to', $args) && + ! empty($args['redirect_to'])) + { + wp_safe_redirect($args['redirect_to']); + die(); + } + else + { + // redireciona para a pauta criada + $permalink = get_post_permalink($pauta_id); + wp_safe_redirect($permalink); + die(); + } + } + return $pauta_id; + } + } + elseif($opt['criar_pauta_pelo_front_end'] == 'S') + { + wp_die(__('Criação de pauta fora do painel está desabilitada, favor contactar o administrador e pedir sua ativação.', 'delibera')); + } +} + +/** + * Add terms to a topic/pauta + * + * @param int $pauta_id + * @param array $args with $taxonomy as key with array ex: $taxonomy = 'category so $args['category'] = array(id1, id2) or $args['post_tags'] = array(id1, id2) + * @param string $taxonomy like 'tema' or 'category' + * @param bool $insert insert or not on pauta + * + * @return valids ids + */ +function deliberaAddTerms($pauta_id, $args, $taxonomy = 'tema', $insert = true ) +{ + $terms_ids = array(); + + if(array_key_exists($taxonomy, $args)) + { + // check array of terms itens + $itens = $args[$taxonomy]; + if(!is_array($itens) && is_string($itens)) + { + if(strpos($itens, ',') != false) + { + $itens = explode(',', $itens); + } + else + { + $itens = array($itens); + } + } + + $terms = get_terms( $taxonomy, + array( + 'hide_empty' => false + ) + ); + + if(is_array($itens)) + { + // verifica se todos os temas enviados por post são válidos + foreach($terms as $term) + { + if(in_array($term->term_id, $itens)) + { + $terms_ids[] = $term->term_id; + } + } + + // coloca os termos no post + if($insert && count($terms_ids) > 0) wp_set_post_terms($pauta_id, $terms_ids, 'tema'); + } + } + return $terms_ids; +} + +?> \ No newline at end of file diff --git a/delibera_topic_deadline.php b/delibera_topic_deadline.php new file mode 100644 index 0000000..332278d --- /dev/null +++ b/delibera_topic_deadline.php @@ -0,0 +1,50 @@ + 'post_count' , 'order' => 'DESC' ); + case "newest": + return array( 'orderby' => 'registered' , 'order' => 'DESC' ); + default: + return array( 'orderby' => 'display_name' , 'order' => 'ASC' ); + } + } + + public static function getPaginator($total, $page) + { + return paginate_links( array( + 'base' => add_query_arg( 'paged', '%#%' ), + 'format' => '', + 'prev_text' => __('«'), + 'next_text' => __('»'), + 'show_all' => false , + 'total' => $total, + 'current' => $page + )); + } + + public static function getNumberOfPages( $total_users , $users_per_page ) + { + return ($total_users/$users_per_page); + } + + public static function getUsers($order_by , $search , $per_page , $paged) + { + return new WP_User_Query( + array( + 'number' => $per_page , + 'offset' => $paged, + 'fields' => array( 'display_name', 'user_login' , 'ID' ), + 'search' => $search . '*', + 'search_columns' => array( 'ID' , 'user_nicename' , 'user_login' , 'user_email' ), + 'orderby' => $order_by['orderby'], + 'order' => $order_by['order'], + ) + ); + } + + public static function getLastPauta($user) + { + $args = array( + 'author' => $user->ID, + 'post_type' => 'pauta', + 'posts_per_page' => 1 , + 'orderby' => 'post_date', + 'order' => 'ASC' + ); + $current_user_posts = get_posts( $args ); + + return $current_user_posts? $current_user_posts[0] : null; + } + + public static function get_comment_meta($id, $control) + { + $string = 'delibera_' . $control; + return get_comment_meta( $id , $string , true); + } + + public static function parse_comment_type($id, $control) + { + $string = 'delibera_comment_' . $control; + $type = get_comment_meta( $id , $string , true); + //echo "DEBUG Tipo: " . $type; + switch($type) + { + case 'encaminhamento': + return __('Proposta de Encaminhamento','delibera'); + case 'discussao': + return __('Discussão','delibera'); + case 'validacao': + return __('Validação','delibera'); + case 'voto': + return __('Votação','delibera'); + case 'relatoria': + return __('Em Relatoria','delibera'); + } + } + + public static function getUserComments($user, $search, $per_page, $paged) + { + $args = array( + 'user_id' => $user->ID, + 'number' => $per_page, + 'post_type' => 'pauta', + 'status' => 'approve', + 'search' => $search, + 'offset' => $paged + ); + + return get_comments( $args ); + } + +} +global $user_display; +$user_display = new \Delibera\Theme\UserDisplay(); + diff --git a/delibera_utils.php b/delibera_utils.php new file mode 100644 index 0000000..308f908 --- /dev/null +++ b/delibera_utils.php @@ -0,0 +1,295 @@ +format( ($int ? 'U' : 'Y-m-d H:i:s')); + } + else + { + return false; + } +} + +/** + * + * Revemos acentos do texto + * @param string $texto + * @return string + */ +function delibera_tiracento($texto) +{ + $trocarIsso = array('à','á','â','ã','ä','å','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ü','ú','ÿ','À','Á','Â','Ã','Ä','Å','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ü','Ú','Ÿ',); + $porIsso = array('a','a','a','a','a','a','c','e','e','e','e','i','i','i','i','n','o','o','o','o','o','u','u','u','y','A','A','A','A','A','A','C','E','E','E','E','I','I','I','I','N','O','O','O','O','O','U','U','U','Y',); + $titletext = str_replace($trocarIsso, $porIsso, $texto); + return $titletext; +} + +function delibera_slug_under($label) +{ + $slug = delibera_tiracento($label); + $slug = str_replace(array("'",'"','.',',',';','!'), '', $slug); + $slug = str_replace(array(' ', '-'), '_', $slug); + return strtolower($slug); +} + +function is_pauta($post = false) +{ + return get_post_type($post) == 'pauta' ? true : false; +} + +/** + * + * + * @param string $text String to truncate. + * @param integer $length Length of returned string, including ellipsis. + * @param string $ending Ending to be appended to the trimmed string. + * @param boolean $exact If false, $text will not be cut mid-word + * @param boolean $considerHtml If true, HTML tags would be handled correctly + * @return string Trimmed string. + */ + +function truncate($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) { + if ($considerHtml) { + // if the plain text is shorter than the maximum length, return the whole text + if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) { + return $text; + } + // splits all html-tags to scanable lines + preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER); + $total_length = strlen($ending); + $open_tags = array(); + $truncate = ''; + foreach ($lines as $line_matchings) { + // if there is any html-tag in this line, handle it and add it (uncounted) to the output + if (!empty($line_matchings[1])) { + // if it's an "empty element" with or without xhtml-conform closing slash + if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) { + // do nothing + // if tag is a closing tag + } else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) { + // delete tag from $open_tags list + $pos = array_search($tag_matchings[1], $open_tags); + if ($pos !== false) { + unset($open_tags[$pos]); + } + // if tag is an opening tag + } else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) { + // add tag to the beginning of $open_tags list + array_unshift($open_tags, strtolower($tag_matchings[1])); + } + // add html-tag to $truncate'd text + $truncate .= $line_matchings[1]; + } + // calculate the length of the plain text part of the line; handle entities as one character + $content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2])); + if ($total_length+$content_length> $length) { + // the number of characters which are left + $left = $length - $total_length; + $entities_length = 0; + // search for html entities + if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) { + // calculate the real length of all entities in the legal range + foreach ($entities[0] as $entity) { + if ($entity[1]+1-$entities_length <= $left) { + $left--; + $entities_length += strlen($entity[0]); + } else { + // no more characters left + break; + } + } + } + $truncate .= substr($line_matchings[2], 0, $left+$entities_length); + // maximum lenght is reached, so get off the loop + break; + } else { + $truncate .= $line_matchings[2]; + $total_length += $content_length; + } + // if the maximum length is reached, get off the loop + if($total_length>= $length) { + break; + } + } + } else { + if (strlen($text) <= $length) { + return $text; + } else { + $truncate = substr($text, 0, $length - strlen($ending)); + } + } + // if the words shouldn't be cut in the middle... + if (!$exact) { + // ...search the last occurance of a space... + $spacepos = strrpos($truncate, ' '); + if (isset($spacepos)) { + // ...and cut the text in this position + $truncate = substr($truncate, 0, $spacepos); + } + } + // add the defined ending to the text + $truncate .= $ending; + if($considerHtml) { + // close all unclosed html-tags + foreach ($open_tags as $tag) { + $truncate .= ''; + } + } + return $truncate; +} + +/** + * Create a form table from an array of rows + */ +function delibera_form_table($rows) { + $content = ''; + foreach ($rows as $row) { + $content .= ''; + } + $content .= '
'; + + if (isset($row['id']) && $row['id'] != '') { + $content .= ''; + } else { + $content .= $row['label']; + } + + if (isset($row['desc']) && $row['desc'] != '') { + $content .= '
'.$row['desc'].''; + } + + $content .= '
'; + $content .= $row['content']; + $content .= '
'; + return $content; +} + +/** + * + * Pega os ultimos conteúdos + * @param string $tipo (option) 'pauta' ou 'comments', padrão 'pauta' + * @param array $args (option) query padrão do post ou do comments + * @param int $count (option) padrão 5 + */ +function delibera_ultimas($tipo = 'pauta', $args = array(), $count = 5) +{ + switch($tipo) + { + case 'pauta': + $filtro = array('orderby' => 'modified', 'order' => 'DESC', 'posts_per_page' => $count); + $filtro = array_merge($filtro, $args); + return delibera_get_pautas_em($filtro, false); + break; + case 'comments': + $filtro = array('orderby' => 'comment_date_gmt', 'order' => 'DESC', 'number' => $count, 'post_type' => 'pauta'); + $filtro = array_merge($filtro, $args); + return delibera_wp_get_comments($filtro); + break; + } +} + +if(!function_exists('array_object_value_recursive')) +{ + /** + * Get all values from specific key in a multidimensional array of objects + * based on php.net http://php.net/manual/en/function.array-values.php + * + * @param $key string + * @param $arr array + * @return array + */ + function array_object_value_recursive($key, array $arr) + { + $val = array(); + array_walk_recursive($arr, function($v, $k) use($key, &$val) + { + if(is_object($v) && property_exists($v, $key) ) + { + array_push($val, $v->$key); + } + }); + return $val; + } +} + +if(!function_exists('array_value_recursive')) +{ + /** + * Get all values from specific key in a multidimensional array + * based on php.net http://php.net/manual/en/function.array-values.php + * + * @param $key string + * @param $arr array + * @return null|string|array + */ + function array_value_recursive($key, array $arr){ + $val = array(); + array_walk_recursive($arr, function($v, $k) use($key, &$val){ + if($k == $key) array_push($val, $v); + }); + return count($val) > 1 ? $val : array_pop($val); + } +} + +//http://www.smarttutorials.net/encrypt-and-decrypt-stringtextids-for-url-using-php/ +function deliberaEncryptor($action, $string) { + $output = false; + + $encrypt_method = "AES-256-CBC"; + //pls set your unique hashing key + $secret_key = AUTH_KEY.get_current_blog_id(); + $secret_iv = SECURE_AUTH_KEY.get_current_blog_id(); + + // hash + $key = hash('sha256', $secret_key); + + // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning + $iv = substr(hash('sha256', $secret_iv), 0, 16); + + //do the encyption given text/string/number + if( $action == 'encrypt' ) { + $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv); + $output = base64_encode($output); + } + else if( $action == 'decrypt' ){ + //decrypt the given text/string/number + $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); + } + + return $output; +} + +// função que modifica o array global $mcaAuthors do plugin mentions, dependencia do delibera +include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); +if(is_plugin_active('mention-comments-authors/mention-comments-authors.php')) +{ + add_action( 'comment_form' , 'delibera_mca_printnames', 11 ); + + function delibera_mca_printnames() + { + $users = get_users( array( 'number' => 1000 , 'fields' => array ( 'user_login' ) ) ); + foreach( $users as $user ) + $authors[] = array( 'val' => $user->user_login, 'meta' => $user->user_login); + wp_localize_script( 'mca-comment-script', 'mcaAuthors', $authors ); + } +} + + diff --git a/delibera_widgets.php b/delibera_widgets.php index eae093c..05bbd8b 100644 --- a/delibera_widgets.php +++ b/delibera_widgets.php @@ -1,59 +1,86 @@ - -
-

- -
- + +
+

+ +
+ \ No newline at end of file diff --git a/includes/api/wp-api.php b/includes/api/wp-api.php new file mode 100644 index 0000000..3e2c69d --- /dev/null +++ b/includes/api/wp-api.php @@ -0,0 +1,164 @@ + 'slug_get_situacao', + 'update_callback' => null, + 'schema' => null + )); + register_rest_field('pauta', 'user_name', + array( + 'get_callback' => 'delibera_api_user_name', + 'update_callback' => null, + 'schema' => null + )); + register_rest_field('pauta', 'avatar', + array( + 'get_callback' => 'delibera_api_avatar', + 'update_callback' => null, + 'schema' => null + )); +} + +/** + * Get the value of the "situação" field + * + * @param array $object + * Details of current . + * @param string $field_name + * Name of field. + * @param WP_REST_Request $request + * Current request + * + * @return mixed + */ +function slug_get_situacao($object, $field_name, $request) +{ + return delibera_get_situacao( $object[ 'id' ] )->slug; +} + +/** + * Get the value of the "user_name" field + * + * @param array $object + * Details of current . + * @param string $field_name + * Name of field. + * @param WP_REST_Request $request + * Current request + * + * @return mixed + */ +function delibera_api_user_name($object, $field_name, $request) +{ + $pauta = get_post($object['id']); + $user = get_author_name($pauta->post_author); + return $user; +} + +/** + * Get the value of the "situação" field + * + * @param array $object + * Details of current . + * @param string $field_name + * Name of field. + * @param WP_REST_Request $request + * Current request + * + * @return mixed + */ +function delibera_api_avatar($object, $field_name, $request) +{ + $pauta = get_post($object['id']); + $avatar = get_avatar_url($pauta->post_author); + return $avatar; +} + +function delibera_like_pauta_api($data) +{ + if(is_object($data)) + { + return delibera_curtir($data->get_param('id')); + } + return "ops, need id"; +} + +function delibera_unlike_pauta_api($data) +{ + if(is_object($data)) + { + return delibera_discordar($data->get_param('id')); + } + return "ops, need id"; +} + +function delibera_like_comment_api($data) +{ + if(is_object($data)) + { + return delibera_curtir($data->get_param('id'), 'comment'); + } + return "ops, need id"; +} + +function delibera_unlike_comment_api($data) +{ + if(is_object($data)) + { + return delibera_discordar($data->get_param('id'), 'comment'); + } + return "ops, need id"; +} + +add_action( 'rest_api_init', function () { + register_rest_route( 'wp/v2', '/pautas/(?P\d+)/like', array( + 'methods' => 'POST', + 'callback' => 'delibera_like_pauta_api', + ) ); + register_rest_route( 'wp/v2', '/pautas/(?P\d+)/unlike', array( + 'methods' => 'POST', + 'callback' => 'delibera_unlike_pauta_api', + ) ); + register_rest_route( 'wp/v2', '/comments/(?P\d+)/like', array( + 'methods' => 'POST', + 'callback' => 'delibera_like_comment_api', + ) ); + register_rest_route( 'wp/v2', '/comments/(?P\d+)/unlike', array( + 'methods' => 'POST', + 'callback' => 'delibera_unlike_comment_api', + ) ); +} ); + +/** + * + * @param WP_Post $post + * @param WP_REST_Request $request + */ +function deliberaApiCreate($post, $request) +{ + $args = $request->get_params(); + $args['post_id'] = $post->ID; + + deliberaCreateTopic($args); + return $post; +} +add_action('rest_insert_pauta', 'deliberaApiCreate', 10, 2); + +/** + * + * @param WP_Post $prepared_post + * @param WP_REST_Request $request + */ +function deliberaApiPreInsertPauta($prepared_post, $request) +{ + if(empty($prepared_post->post_name)) + { + $prepared_post->post_name = sanitize_title($prepared_post->post_title); + } + return $prepared_post; +} +add_filter('rest_pre_insert_pauta', 'deliberaApiPreInsertPauta', 10, 2); \ No newline at end of file diff --git a/includes/class-tgm-plugin-activation.php b/includes/class-tgm-plugin-activation.php new file mode 100755 index 0000000..ee6eb73 --- /dev/null +++ b/includes/class-tgm-plugin-activation.php @@ -0,0 +1,3618 @@ +wp_version = $GLOBALS['wp_version']; + + // Announce that the class is ready, and pass the object (for advanced use). + do_action_ref_array( 'tgmpa_init', array( $this ) ); + + // When the rest of WP has loaded, kick-start the rest of the class. + add_action( 'init', array( $this, 'init' ) ); + } + + /** + * Magic method to (not) set protected properties from outside of this class. + * + * @internal hackedihack... There is a serious bug in v2.3.2 - 2.3.6 where the `menu` property + * is being assigned rather than tested in a conditional, effectively rendering it useless. + * This 'hack' prevents this from happening. + * + * @see https://github.com/TGMPA/TGM-Plugin-Activation/blob/2.3.6/tgm-plugin-activation/class-tgm-plugin-activation.php#L1593 + * + * @param string $name Name of an inaccessible property. + * @param mixed $value Value to assign to the property. + * @return void Silently fail to set the property when this is tried from outside of this class context. + * (Inside this class context, the __set() method if not used as there is direct access.) + */ + public function __set( $name, $value ) { + return; + } + + /** + * Magic method to get the value of a protected property outside of this class context. + * + * @param string $name Name of an inaccessible property. + * @return mixed The property value. + */ + public function __get( $name ) { + return $this->{$name}; + } + + /** + * Initialise the interactions between this class and WordPress. + * + * Hooks in three new methods for the class: admin_menu, notices and styles. + * + * @since 2.0.0 + * + * @see TGM_Plugin_Activation::admin_menu() + * @see TGM_Plugin_Activation::notices() + * @see TGM_Plugin_Activation::styles() + */ + public function init() { + /** + * By default TGMPA only loads on the WP back-end and not in an Ajax call. Using this filter + * you can overrule that behaviour. + * + * @since 2.5.0 + * + * @param bool $load Whether or not TGMPA should load. + * Defaults to the return of `is_admin() && ! defined( 'DOING_AJAX' )`. + */ + if ( true !== apply_filters( 'tgmpa_load', ( is_admin() && ! defined( 'DOING_AJAX' ) ) ) ) { + return; + } + + // Load class strings. + $this->strings = array( + 'page_title' => __( 'Install Required Plugins', 'tgmpa' ), + 'menu_title' => __( 'Install Plugins', 'tgmpa' ), + 'installing' => __( 'Installing Plugin: %s', 'tgmpa' ), + 'oops' => __( 'Something went wrong with the plugin API.', 'tgmpa' ), + 'notice_can_install_required' => _n_noop( + 'This theme requires the following plugin: %1$s.', + 'This theme requires the following plugins: %1$s.', + 'tgmpa' + ), + 'notice_can_install_recommended' => _n_noop( + 'This theme recommends the following plugin: %1$s.', + 'This theme recommends the following plugins: %1$s.', + 'tgmpa' + ), + 'notice_cannot_install' => _n_noop( + 'Sorry, but you do not have the correct permissions to install the %1$s plugin.', + 'Sorry, but you do not have the correct permissions to install the %1$s plugins.', + 'tgmpa' + ), + 'notice_ask_to_update' => _n_noop( + 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', + 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', + 'tgmpa' + ), + 'notice_ask_to_update_maybe' => _n_noop( + 'There is an update available for: %1$s.', + 'There are updates available for the following plugins: %1$s.', + 'tgmpa' + ), + 'notice_cannot_update' => _n_noop( + 'Sorry, but you do not have the correct permissions to update the %1$s plugin.', + 'Sorry, but you do not have the correct permissions to update the %1$s plugins.', + 'tgmpa' + ), + 'notice_can_activate_required' => _n_noop( + 'The following required plugin is currently inactive: %1$s.', + 'The following required plugins are currently inactive: %1$s.', + 'tgmpa' + ), + 'notice_can_activate_recommended' => _n_noop( + 'The following recommended plugin is currently inactive: %1$s.', + 'The following recommended plugins are currently inactive: %1$s.', + 'tgmpa' + ), + 'notice_cannot_activate' => _n_noop( + 'Sorry, but you do not have the correct permissions to activate the %1$s plugin.', + 'Sorry, but you do not have the correct permissions to activate the %1$s plugins.', + 'tgmpa' + ), + 'install_link' => _n_noop( + 'Begin installing plugin', + 'Begin installing plugins', + 'tgmpa' + ), + 'update_link' => _n_noop( + 'Begin updating plugin', + 'Begin updating plugins', + 'tgmpa' + ), + 'activate_link' => _n_noop( + 'Begin activating plugin', + 'Begin activating plugins', + 'tgmpa' + ), + 'return' => __( 'Return to Required Plugins Installer', 'tgmpa' ), + 'dashboard' => __( 'Return to the dashboard', 'tgmpa' ), + 'plugin_activated' => __( 'Plugin activated successfully.', 'tgmpa' ), + 'activated_successfully' => __( 'The following plugin was activated successfully:', 'tgmpa' ), + 'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'tgmpa' ), + 'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'tgmpa' ), + 'complete' => __( 'All plugins installed and activated successfully. %1$s', 'tgmpa' ), + 'dismiss' => __( 'Dismiss this notice', 'tgmpa' ), + 'contact_admin' => __( 'Please contact the administrator of this site for help.', 'tgmpa' ), + ); + + do_action( 'tgmpa_register' ); + + /* After this point, the plugins should be registered and the configuration set. */ + + // Proceed only if we have plugins to handle. + if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) { + return; + } + + // Set up the menu and notices if we still have outstanding actions. + if ( true !== $this->is_tgmpa_complete() ) { + // Sort the plugins. + array_multisort( $this->sort_order, SORT_ASC, $this->plugins ); + + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); + add_action( 'admin_head', array( $this, 'dismiss' ) ); + + // Prevent the normal links from showing underneath a single install/update page. + add_filter( 'install_plugin_complete_actions', array( $this, 'actions' ) ); + add_filter( 'update_plugin_complete_actions', array( $this, 'actions' ) ); + + if ( $this->has_notices ) { + add_action( 'admin_notices', array( $this, 'notices' ) ); + add_action( 'admin_init', array( $this, 'admin_init' ), 1 ); + add_action( 'admin_enqueue_scripts', array( $this, 'thickbox' ) ); + } + + add_action( 'load-plugins.php', array( $this, 'add_plugin_action_link_filters' ), 1 ); + } + + // Make sure things get reset on switch theme. + add_action( 'switch_theme', array( $this, 'flush_plugins_cache' ) ); + + if ( $this->has_notices ) { + add_action( 'switch_theme', array( $this, 'update_dismiss' ) ); + } + + // Setup the force activation hook. + if ( true === $this->has_forced_activation ) { + add_action( 'admin_init', array( $this, 'force_activation' ) ); + } + + // Setup the force deactivation hook. + if ( true === $this->has_forced_deactivation ) { + add_action( 'switch_theme', array( $this, 'force_deactivation' ) ); + } + } + + /** + * Prevent activation of plugins which don't meet the minimum version requirement from the + * WP native plugins page. + * + * @since 2.5.0 + */ + public function add_plugin_action_link_filters() { + foreach ( $this->plugins as $slug => $plugin ) { + if ( false === $this->can_plugin_activate( $slug ) ) { + add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_activate' ), 20 ); + } + + if ( true === $plugin['force_activation'] ) { + add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_deactivate' ), 20 ); + } + + if ( false !== $this->does_plugin_require_update( $slug ) ) { + add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_update' ), 20 ); + } + } + } + + /** + * Remove the 'Activate' link on the WP native plugins page if the plugin does not meet the + * minimum version requirements. + * + * @since 2.5.0 + * + * @param array $actions Action links. + * @return array + */ + public function filter_plugin_action_links_activate( $actions ) { + unset( $actions['activate'] ); + + return $actions; + } + + /** + * Remove the 'Deactivate' link on the WP native plugins page if the plugin has been set to force activate. + * + * @since 2.5.0 + * + * @param array $actions Action links. + * @return array + */ + public function filter_plugin_action_links_deactivate( $actions ) { + unset( $actions['deactivate'] ); + + return $actions; + } + + /** + * Add a 'Requires update' link on the WP native plugins page if the plugin does not meet the + * minimum version requirements. + * + * @since 2.5.0 + * + * @param array $actions Action links. + * @return array + */ + public function filter_plugin_action_links_update( $actions ) { + $actions['update'] = sprintf( + '%3$s', + esc_url( $this->get_tgmpa_status_url( 'update' ) ), + esc_attr__( 'This plugin needs to be updated to be compatible with your theme.', 'tgmpa' ), + esc_html__( 'Update Required', 'tgmpa' ) + ); + + return $actions; + } + + /** + * Handles calls to show plugin information via links in the notices. + * + * We get the links in the admin notices to point to the TGMPA page, rather + * than the typical plugin-install.php file, so we can prepare everything + * beforehand. + * + * WP does not make it easy to show the plugin information in the thickbox - + * here we have to require a file that includes a function that does the + * main work of displaying it, enqueue some styles, set up some globals and + * finally call that function before exiting. + * + * Down right easy once you know how... + * + * Returns early if not the TGMPA page. + * + * @since 2.1.0 + * + * @global string $tab Used as iframe div class names, helps with styling + * @global string $body_id Used as the iframe body ID, helps with styling + * + * @return null Returns early if not the TGMPA page. + */ + public function admin_init() { + if ( ! $this->is_tgmpa_page() ) { + return; + } + + if ( isset( $_REQUEST['tab'] ) && 'plugin-information' === $_REQUEST['tab'] ) { + // Needed for install_plugin_information(). + require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; + + wp_enqueue_style( 'plugin-install' ); + + global $tab, $body_id; + $body_id = 'plugin-information'; + // @codingStandardsIgnoreStart + $tab = 'plugin-information'; + // @codingStandardsIgnoreEnd + + install_plugin_information(); + + exit; + } + } + + /** + * Enqueue thickbox scripts/styles for plugin info. + * + * Thickbox is not automatically included on all admin pages, so we must + * manually enqueue it for those pages. + * + * Thickbox is only loaded if the user has not dismissed the admin + * notice or if there are any plugins left to install and activate. + * + * @since 2.1.0 + */ + public function thickbox() { + if ( ! get_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, true ) ) { + add_thickbox(); + } + } + + /** + * Adds submenu page if there are plugin actions to take. + * + * This method adds the submenu page letting users know that a required + * plugin needs to be installed. + * + * This page disappears once the plugin has been installed and activated. + * + * @since 1.0.0 + * + * @see TGM_Plugin_Activation::init() + * @see TGM_Plugin_Activation::install_plugins_page() + * + * @return null Return early if user lacks capability to install a plugin. + */ + public function admin_menu() { + // Make sure privileges are correct to see the page. + if ( ! current_user_can( 'install_plugins' ) ) { + return; + } + + $args = apply_filters( + 'tgmpa_admin_menu_args', + array( + 'parent_slug' => $this->parent_slug, // Parent Menu slug. + 'page_title' => $this->strings['page_title'], // Page title. + 'menu_title' => $this->strings['menu_title'], // Menu title. + 'capability' => $this->capability, // Capability. + 'menu_slug' => $this->menu, // Menu slug. + 'function' => array( $this, 'install_plugins_page' ), // Callback. + ) + ); + + $this->add_admin_menu( $args ); + } + + /** + * Add the menu item. + * + * @since 2.5.0 + * + * @param array $args Menu item configuration. + */ + protected function add_admin_menu( array $args ) { + if ( has_filter( 'tgmpa_admin_menu_use_add_theme_page' ) ) { + _deprecated_function( 'The "tgmpa_admin_menu_use_add_theme_page" filter', '2.5.0', esc_html__( 'Set the parent_slug config variable instead.', 'tgmpa' ) ); + } + + if ( 'themes.php' === $this->parent_slug ) { + $this->page_hook = call_user_func( 'add_theme_page', $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] ); + } else { + $this->page_hook = call_user_func( 'add_submenu_page', $args['parent_slug'], $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] ); + } + } + + /** + * Echoes plugin installation form. + * + * This method is the callback for the admin_menu method function. + * This displays the admin page and form area where the user can select to install and activate the plugin. + * Aborts early if we're processing a plugin installation action. + * + * @since 1.0.0 + * + * @return null Aborts early if we're processing a plugin installation action. + */ + public function install_plugins_page() { + // Store new instance of plugin table in object. + $plugin_table = new TGMPA_List_Table; + + // Return early if processing a plugin installation action. + if ( ( ( 'tgmpa-bulk-install' === $plugin_table->current_action() || 'tgmpa-bulk-update' === $plugin_table->current_action() ) && $plugin_table->process_bulk_actions() ) || $this->do_plugin_install() ) { + return; + } + + // Force refresh of available plugin information so we'll know about manual updates/deletes. + wp_clean_plugins_cache( false ); + + ?> +
+

+ prepare_items(); ?> + + message ) && is_string( $this->message ) ) { + echo wp_kses_post( $this->message ); + } + ?> + views(); ?> + +
+ + + display(); ?> +
+
+ sanitize_key( urldecode( $_GET['plugin'] ) ); + + if ( ! isset( $this->plugins[ $slug ] ) ) { + return false; + } + + // Was an install or upgrade action link clicked? + if ( ( isset( $_GET['tgmpa-install'] ) && 'install-plugin' === $_GET['tgmpa-install'] ) || ( isset( $_GET['tgmpa-update'] ) && 'update-plugin' === $_GET['tgmpa-update'] ) ) { + + $install_type = 'install'; + if ( isset( $_GET['tgmpa-update'] ) && 'update-plugin' === $_GET['tgmpa-update'] ) { + $install_type = 'update'; + } + + check_admin_referer( 'tgmpa-' . $install_type, 'tgmpa-nonce' ); + + // Pass necessary information via URL if WP_Filesystem is needed. + $url = wp_nonce_url( + add_query_arg( + array( + 'plugin' => urlencode( $slug ), + 'tgmpa-' . $install_type => $install_type . '-plugin', + ), + $this->get_tgmpa_url() + ), + 'tgmpa-' . $install_type, + 'tgmpa-nonce' + ); + + $method = ''; // Leave blank so WP_Filesystem can populate it as necessary. + + if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, array() ) ) ) { + return true; + } + + if ( ! WP_Filesystem( $creds ) ) { + request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, array() ); // Setup WP_Filesystem. + return true; + } + + /* If we arrive here, we have the filesystem. */ + + // Prep variables for Plugin_Installer_Skin class. + $extra = array(); + $extra['slug'] = $slug; // Needed for potentially renaming of directory name. + $source = $this->get_download_url( $slug ); + $api = ( 'repo' === $this->plugins[ $slug ]['source_type'] ) ? $this->get_plugins_api( $slug ) : null; + $api = ( false !== $api ) ? $api : null; + + $url = add_query_arg( + array( + 'action' => $install_type . '-plugin', + 'plugin' => urlencode( $slug ), + ), + 'update.php' + ); + + if ( ! class_exists( 'Plugin_Upgrader', false ) ) { + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; + } + + $skin_args = array( + 'type' => ( 'bundled' !== $this->plugins[ $slug ]['source_type'] ) ? 'web' : 'upload', + 'title' => sprintf( $this->strings['installing'], $this->plugins[ $slug ]['name'] ), + 'url' => esc_url_raw( $url ), + 'nonce' => $install_type . '-plugin_' . $slug, + 'plugin' => '', + 'api' => $api, + 'extra' => $extra, + ); + + if ( 'update' === $install_type ) { + $skin_args['plugin'] = $this->plugins[ $slug ]['file_path']; + $skin = new Plugin_Upgrader_Skin( $skin_args ); + } else { + $skin = new Plugin_Installer_Skin( $skin_args ); + } + + // Create a new instance of Plugin_Upgrader. + $upgrader = new Plugin_Upgrader( $skin ); + + // Perform the action and install the plugin from the $source urldecode(). + add_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1, 3 ); + + if ( 'update' === $install_type ) { + // Inject our info into the update transient. + $to_inject = array( $slug => $this->plugins[ $slug ] ); + $to_inject[ $slug ]['source'] = $source; + $this->inject_update_info( $to_inject ); + + $upgrader->upgrade( $this->plugins[ $slug ]['file_path'] ); + } else { + $upgrader->install( $source ); + } + + remove_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1, 3 ); + + // Make sure we have the correct file path now the plugin is installed/updated. + $this->populate_file_path( $slug ); + + // Only activate plugins if the config option is set to true and the plugin isn't + // already active (upgrade). + if ( $this->is_automatic && ! $this->is_plugin_active( $slug ) ) { + $plugin_activate = $upgrader->plugin_info(); // Grab the plugin info from the Plugin_Upgrader method. + if ( false === $this->activate_single_plugin( $plugin_activate, $slug, true ) ) { + return true; // Finish execution of the function early as we encountered an error. + } + } + + $this->show_tgmpa_version(); + + // Display message based on if all plugins are now active or not. + if ( $this->is_tgmpa_complete() ) { + echo '

', sprintf( esc_html( $this->strings['complete'] ), '' . esc_html__( 'Return to the Dashboard', 'tgmpa' ) . '' ), '

'; + echo ''; + } else { + echo '

', esc_html( $this->strings['return'] ), '

'; + } + + return true; + } elseif ( isset( $this->plugins[ $slug ]['file_path'], $_GET['tgmpa-activate'] ) && 'activate-plugin' === $_GET['tgmpa-activate'] ) { + // Activate action link was clicked. + check_admin_referer( 'tgmpa-activate', 'tgmpa-nonce' ); + + if ( false === $this->activate_single_plugin( $this->plugins[ $slug ]['file_path'], $slug ) ) { + return true; // Finish execution of the function early as we encountered an error. + } + } + + return false; + } + + /** + * Inject information into the 'update_plugins' site transient as WP checks that before running an update. + * + * @since 2.5.0 + * + * @param array $plugins The plugin information for the plugins which are to be updated. + */ + public function inject_update_info( $plugins ) { + $repo_updates = get_site_transient( 'update_plugins' ); + + if ( ! is_object( $repo_updates ) ) { + $repo_updates = new stdClass; + } + + foreach ( $plugins as $slug => $plugin ) { + $file_path = $plugin['file_path']; + + if ( empty( $repo_updates->response[ $file_path ] ) ) { + $repo_updates->response[ $file_path ] = new stdClass; + } + + // We only really need to set package, but let's do all we can in case WP changes something. + $repo_updates->response[ $file_path ]->slug = $slug; + $repo_updates->response[ $file_path ]->plugin = $file_path; + $repo_updates->response[ $file_path ]->new_version = $plugin['version']; + $repo_updates->response[ $file_path ]->package = $plugin['source']; + if ( empty( $repo_updates->response[ $file_path ]->url ) && ! empty( $plugin['external_url'] ) ) { + $repo_updates->response[ $file_path ]->url = $plugin['external_url']; + } + } + + set_site_transient( 'update_plugins', $repo_updates ); + } + + /** + * Adjust the plugin directory name if necessary. + * + * The final destination directory of a plugin is based on the subdirectory name found in the + * (un)zipped source. In some cases - most notably GitHub repository plugin downloads -, this + * subdirectory name is not the same as the expected slug and the plugin will not be recognized + * as installed. This is fixed by adjusting the temporary unzipped source subdirectory name to + * the expected plugin slug. + * + * @since 2.5.0 + * + * @param string $source Path to upgrade/zip-file-name.tmp/subdirectory/. + * @param string $remote_source Path to upgrade/zip-file-name.tmp. + * @param \WP_Upgrader $upgrader Instance of the upgrader which installs the plugin. + * @return string $source + */ + public function maybe_adjust_source_dir( $source, $remote_source, $upgrader ) { + if ( ! $this->is_tgmpa_page() || ! is_object( $GLOBALS['wp_filesystem'] ) ) { + return $source; + } + + // Check for single file plugins. + $source_files = array_keys( $GLOBALS['wp_filesystem']->dirlist( $remote_source ) ); + if ( 1 === count( $source_files ) && false === $GLOBALS['wp_filesystem']->is_dir( $source ) ) { + return $source; + } + + // Multi-file plugin, let's see if the directory is correctly named. + $desired_slug = ''; + + // Figure out what the slug is supposed to be. + if ( false === $upgrader->bulk && ! empty( $upgrader->skin->options['extra']['slug'] ) ) { + $desired_slug = $upgrader->skin->options['extra']['slug']; + } else { + // Bulk installer contains less info, so fall back on the info registered here. + foreach ( $this->plugins as $slug => $plugin ) { + if ( ! empty( $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) && $plugin['name'] === $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) { + $desired_slug = $slug; + break; + } + } + unset( $slug, $plugin ); + } + + if ( ! empty( $desired_slug ) ) { + $subdir_name = untrailingslashit( str_replace( trailingslashit( $remote_source ), '', $source ) ); + + if ( ! empty( $subdir_name ) && $subdir_name !== $desired_slug ) { + $from = untrailingslashit( $source ); + $to = trailingslashit( $remote_source ) . $desired_slug; + + if ( true === $GLOBALS['wp_filesystem']->move( $from, $to ) ) { + return trailingslashit( $to ); + } else { + return new WP_Error( 'rename_failed', esc_html__( 'The remote plugin package does not contain a folder with the desired slug and renaming did not work.', 'tgmpa' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'tgmpa' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) ); + } + } elseif ( empty( $subdir_name ) ) { + return new WP_Error( 'packaged_wrong', esc_html__( 'The remote plugin package consists of more than one file, but the files are not packaged in a folder.', 'tgmpa' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'tgmpa' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) ); + } + } + + return $source; + } + + /** + * Activate a single plugin and send feedback about the result to the screen. + * + * @since 2.5.0 + * + * @param string $file_path Path within wp-plugins/ to main plugin file. + * @param string $slug Plugin slug. + * @param bool $automatic Whether this is an automatic activation after an install. Defaults to false. + * This determines the styling of the output messages. + * @return bool False if an error was encountered, true otherwise. + */ + protected function activate_single_plugin( $file_path, $slug, $automatic = false ) { + if ( $this->can_plugin_activate( $slug ) ) { + $activate = activate_plugin( $file_path ); + + if ( is_wp_error( $activate ) ) { + echo '

', wp_kses_post( $activate->get_error_message() ), '

', + '

', esc_html( $this->strings['return'] ), '

'; + + return false; // End it here if there is an error with activation. + } else { + if ( ! $automatic ) { + // Make sure message doesn't display again if bulk activation is performed + // immediately after a single activation. + if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK. + echo '

', esc_html( $this->strings['activated_successfully'] ), ' ', esc_html( $this->plugins[ $slug ]['name'] ), '.

'; + } + } else { + // Simpler message layout for use on the plugin install page. + echo '

', esc_html( $this->strings['plugin_activated'] ), '

'; + } + } + } elseif ( $this->is_plugin_active( $slug ) ) { + // No simpler message format provided as this message should never be encountered + // on the plugin install page. + echo '

', + sprintf( + esc_html( $this->strings['plugin_already_active'] ), + '' . esc_html( $this->plugins[ $slug ]['name'] ) . '' + ), + '

'; + } elseif ( $this->does_plugin_require_update( $slug ) ) { + if ( ! $automatic ) { + // Make sure message doesn't display again if bulk activation is performed + // immediately after a single activation. + if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK. + echo '

', + sprintf( + esc_html( $this->strings['plugin_needs_higher_version'] ), + '' . esc_html( $this->plugins[ $slug ]['name'] ) . '' + ), + '

'; + } + } else { + // Simpler message layout for use on the plugin install page. + echo '

', sprintf( esc_html( $this->strings['plugin_needs_higher_version'] ), esc_html( $this->plugins[ $slug ]['name'] ) ), '

'; + } + } + + return true; + } + + /** + * Echoes required plugin notice. + * + * Outputs a message telling users that a specific plugin is required for + * their theme. If appropriate, it includes a link to the form page where + * users can install and activate the plugin. + * + * Returns early if we're on the Install page. + * + * @since 1.0.0 + * + * @global object $current_screen + * + * @return null Returns early if we're on the Install page. + */ + public function notices() { + // Remove nag on the install page / Return early if the nag message has been dismissed. + if ( $this->is_tgmpa_page() || get_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, true ) ) { + return; + } + + // Store for the plugin slugs by message type. + $message = array(); + + // Initialize counters used to determine plurality of action link texts. + $install_link_count = 0; + $update_link_count = 0; + $activate_link_count = 0; + + foreach ( $this->plugins as $slug => $plugin ) { + if ( $this->is_plugin_active( $slug ) && false === $this->does_plugin_have_update( $slug ) ) { + continue; + } + + if ( ! $this->is_plugin_installed( $slug ) ) { + if ( current_user_can( 'install_plugins' ) ) { + $install_link_count++; + + if ( true === $plugin['required'] ) { + $message['notice_can_install_required'][] = $slug; + } else { + $message['notice_can_install_recommended'][] = $slug; + } + } else { + // Need higher privileges to install the plugin. + $message['notice_cannot_install'][] = $slug; + } + } else { + if ( ! $this->is_plugin_active( $slug ) && $this->can_plugin_activate( $slug ) ) { + if ( current_user_can( 'activate_plugins' ) ) { + $activate_link_count++; + + if ( true === $plugin['required'] ) { + $message['notice_can_activate_required'][] = $slug; + } else { + $message['notice_can_activate_recommended'][] = $slug; + } + } else { + // Need higher privileges to activate the plugin. + $message['notice_cannot_activate'][] = $slug; + } + } + + if ( $this->does_plugin_require_update( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) { + + if ( current_user_can( 'install_plugins' ) ) { + $update_link_count++; + + if ( $this->does_plugin_require_update( $slug ) ) { + $message['notice_ask_to_update'][] = $slug; + } elseif ( false !== $this->does_plugin_have_update( $slug ) ) { + $message['notice_ask_to_update_maybe'][] = $slug; + } + } else { + // Need higher privileges to update the plugin. + $message['notice_cannot_update'][] = $slug; + } + } + } + } + unset( $slug, $plugin ); + + // If we have notices to display, we move forward. + if ( ! empty( $message ) ) { + krsort( $message ); // Sort messages. + $rendered = ''; + + // As add_settings_error() wraps the final message in a

and as the final message can't be + // filtered, using

's in our html would render invalid html output. + $line_template = '%s' . "\n"; + + // If dismissable is false and a message is set, output it now. + if ( ! $this->dismissable && ! empty( $this->dismiss_msg ) ) { + $rendered .= sprintf( $line_template, wp_kses_post( $this->dismiss_msg ) ); + } + + // Render the individual message lines for the notice. + foreach ( $message as $type => $plugin_group ) { + $linked_plugins = array(); + + // Get the external info link for a plugin if one is available. + foreach ( $plugin_group as $plugin_slug ) { + $linked_plugins[] = $this->get_info_link( $plugin_slug ); + } + unset( $plugin_slug ); + + $count = count( $plugin_group ); + $linked_plugins = array_map( array( 'TGMPA_Utils', 'wrap_in_em' ), $linked_plugins ); + $last_plugin = array_pop( $linked_plugins ); // Pop off last name to prep for readability. + $imploded = empty( $linked_plugins ) ? $last_plugin : ( implode( ', ', $linked_plugins ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'tgmpa' ) . ' ' . $last_plugin ); + + $rendered .= sprintf( + $line_template, + sprintf( + translate_nooped_plural( $this->strings[ $type ], $count, 'tgmpa' ), + $imploded, + $count + ) + ); + + if ( 0 === strpos( $type, 'notice_cannot' ) ) { + $rendered .= $this->strings['contact_admin']; + } + } + unset( $type, $plugin_group, $linked_plugins, $count, $last_plugin, $imploded ); + + // Setup action links. + $action_links = array( + 'install' => '', + 'update' => '', + 'activate' => '', + 'dismiss' => $this->dismissable ? '' . esc_html( $this->strings['dismiss'] ) . '' : '', + ); + + $link_template = '%1$s'; + + if ( current_user_can( 'install_plugins' ) ) { + if ( $install_link_count > 0 ) { + $action_links['install'] = sprintf( + $link_template, + translate_nooped_plural( $this->strings['install_link'], $install_link_count, 'tgmpa' ), + esc_url( $this->get_tgmpa_status_url( 'install' ) ) + ); + } + if ( $update_link_count > 0 ) { + $action_links['update'] = sprintf( + $link_template, + translate_nooped_plural( $this->strings['update_link'], $update_link_count, 'tgmpa' ), + esc_url( $this->get_tgmpa_status_url( 'update' ) ) + ); + } + } + + if ( current_user_can( 'activate_plugins' ) && $activate_link_count > 0 ) { + $action_links['activate'] = sprintf( + $link_template, + translate_nooped_plural( $this->strings['activate_link'], $activate_link_count, 'tgmpa' ), + esc_url( $this->get_tgmpa_status_url( 'activate' ) ) + ); + } + + $action_links = apply_filters( 'tgmpa_notice_action_links', $action_links ); + + $action_links = array_filter( (array) $action_links ); // Remove any empty array items. + + if ( ! empty( $action_links ) && is_array( $action_links ) ) { + $action_links = sprintf( $line_template, implode( ' | ', $action_links ) ); + $rendered .= apply_filters( 'tgmpa_notice_rendered_action_links', $action_links ); + } + + // Register the nag messages and prepare them to be processed. + if ( ! empty( $this->strings['nag_type'] ) ) { + add_settings_error( 'tgmpa', 'tgmpa', $rendered, sanitize_html_class( strtolower( $this->strings['nag_type'] ) ) ); + } else { + $nag_class = version_compare( $this->wp_version, '3.8', '<' ) ? 'updated' : 'update-nag'; + add_settings_error( 'tgmpa', 'tgmpa', $rendered, $nag_class ); + } + } + + // Admin options pages already output settings_errors, so this is to avoid duplication. + if ( 'options-general' !== $GLOBALS['current_screen']->parent_base ) { + $this->display_settings_errors(); + } + } + + /** + * Display settings errors and remove those which have been displayed to avoid duplicate messages showing + * + * @since 2.5.0 + */ + protected function display_settings_errors() { + global $wp_settings_errors; + + settings_errors( 'tgmpa' ); + + foreach ( (array) $wp_settings_errors as $key => $details ) { + if ( 'tgmpa' === $details['setting'] ) { + unset( $wp_settings_errors[ $key ] ); + break; + } + } + } + + /** + * Add dismissable admin notices. + * + * Appends a link to the admin nag messages. If clicked, the admin notice disappears and no longer is visible to users. + * + * @since 2.1.0 + */ + public function dismiss() { + if ( isset( $_GET['tgmpa-dismiss'] ) ) { + update_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice_' . $this->id, 1 ); + } + } + + /** + * Add individual plugin to our collection of plugins. + * + * If the required keys are not set or the plugin has already + * been registered, the plugin is not added. + * + * @since 2.0.0 + * + * @param array|null $plugin Array of plugin arguments or null if invalid argument. + * @return null Return early if incorrect argument. + */ + public function register( $plugin ) { + if ( empty( $plugin['slug'] ) || empty( $plugin['name'] ) ) { + return; + } + + if ( empty( $plugin['slug'] ) || ! is_string( $plugin['slug'] ) || isset( $this->plugins[ $plugin['slug'] ] ) ) { + return; + } + + $defaults = array( + 'name' => '', // String + 'slug' => '', // String + 'source' => 'repo', // String + 'required' => false, // Boolean + 'version' => '', // String + 'force_activation' => false, // Boolean + 'force_deactivation' => false, // Boolean + 'external_url' => '', // String + 'is_callable' => '', // String|Array. + ); + + // Prepare the received data. + $plugin = wp_parse_args( $plugin, $defaults ); + + // Standardize the received slug. + $plugin['slug'] = $this->sanitize_key( $plugin['slug'] ); + + // Forgive users for using string versions of booleans or floats for version number. + $plugin['version'] = (string) $plugin['version']; + $plugin['source'] = empty( $plugin['source'] ) ? 'repo' : $plugin['source']; + $plugin['required'] = TGMPA_Utils::validate_bool( $plugin['required'] ); + $plugin['force_activation'] = TGMPA_Utils::validate_bool( $plugin['force_activation'] ); + $plugin['force_deactivation'] = TGMPA_Utils::validate_bool( $plugin['force_deactivation'] ); + + // Enrich the received data. + $plugin['file_path'] = $this->_get_plugin_basename_from_slug( $plugin['slug'] ); + $plugin['source_type'] = $this->get_plugin_source_type( $plugin['source'] ); + + // Set the class properties. + $this->plugins[ $plugin['slug'] ] = $plugin; + $this->sort_order[ $plugin['slug'] ] = $plugin['name']; + + // Should we add the force activation hook ? + if ( true === $plugin['force_activation'] ) { + $this->has_forced_activation = true; + } + + // Should we add the force deactivation hook ? + if ( true === $plugin['force_deactivation'] ) { + $this->has_forced_deactivation = true; + } + } + + /** + * Determine what type of source the plugin comes from. + * + * @since 2.5.0 + * + * @param string $source The source of the plugin as provided, either empty (= WP repo), a file path + * (= bundled) or an external URL. + * @return string 'repo', 'external', or 'bundled' + */ + protected function get_plugin_source_type( $source ) { + if ( 'repo' === $source || preg_match( self::WP_REPO_REGEX, $source ) ) { + return 'repo'; + } elseif ( preg_match( self::IS_URL_REGEX, $source ) ) { + return 'external'; + } else { + return 'bundled'; + } + } + + /** + * Sanitizes a string key. + * + * Near duplicate of WP Core `sanitize_key()`. The difference is that uppercase characters *are* + * allowed, so as not to break upgrade paths from non-standard bundled plugins using uppercase + * characters in the plugin directory path/slug. Silly them. + * + * @see https://developer.wordpress.org/reference/hooks/sanitize_key/ + * + * @since 2.5.0 + * + * @param string $key String key. + * @return string Sanitized key + */ + public function sanitize_key( $key ) { + $raw_key = $key; + $key = preg_replace( '`[^A-Za-z0-9_-]`', '', $key ); + + /** + * Filter a sanitized key string. + * + * @since 3.0.0 + * + * @param string $key Sanitized key. + * @param string $raw_key The key prior to sanitization. + */ + return apply_filters( 'tgmpa_sanitize_key', $key, $raw_key ); + } + + /** + * Amend default configuration settings. + * + * @since 2.0.0 + * + * @param array $config Array of config options to pass as class properties. + */ + public function config( $config ) { + $keys = array( + 'id', + 'default_path', + 'has_notices', + 'dismissable', + 'dismiss_msg', + 'menu', + 'parent_slug', + 'capability', + 'is_automatic', + 'message', + 'strings', + ); + + foreach ( $keys as $key ) { + if ( isset( $config[ $key ] ) ) { + if ( is_array( $config[ $key ] ) ) { + $this->$key = array_merge( $this->$key, $config[ $key ] ); + } else { + $this->$key = $config[ $key ]; + } + } + } + } + + /** + * Amend action link after plugin installation. + * + * @since 2.0.0 + * + * @param array $install_actions Existing array of actions. + * @return array Amended array of actions. + */ + public function actions( $install_actions ) { + // Remove action links on the TGMPA install page. + if ( $this->is_tgmpa_page() ) { + return false; + } + + return $install_actions; + } + + /** + * Flushes the plugins cache on theme switch to prevent stale entries + * from remaining in the plugin table. + * + * @since 2.4.0 + * + * @param bool $clear_update_cache Optional. Whether to clear the Plugin updates cache. + * Parameter added in v2.5.0. + */ + public function flush_plugins_cache( $clear_update_cache = true ) { + wp_clean_plugins_cache( $clear_update_cache ); + } + + /** + * Set file_path key for each installed plugin. + * + * @since 2.1.0 + * + * @param string $plugin_slug Optional. If set, only (re-)populates the file path for that specific plugin. + * Parameter added in v2.5.0. + */ + public function populate_file_path( $plugin_slug = '' ) { + if ( ! empty( $plugin_slug ) && is_string( $plugin_slug ) && isset( $this->plugins[ $plugin_slug ] ) ) { + $this->plugins[ $plugin_slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $plugin_slug ); + } else { + // Add file_path key for all plugins. + foreach ( $this->plugins as $slug => $values ) { + $this->plugins[ $slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $slug ); + } + } + } + + /** + * Helper function to extract the file path of the plugin file from the + * plugin slug, if the plugin is installed. + * + * @since 2.0.0 + * + * @param string $slug Plugin slug (typically folder name) as provided by the developer. + * @return string Either file path for plugin if installed, or just the plugin slug. + */ + protected function _get_plugin_basename_from_slug( $slug ) { + $keys = array_keys( $this->get_plugins() ); + + foreach ( $keys as $key ) { + if ( preg_match( '|^' . $slug . '/|', $key ) ) { + return $key; + } + } + + return $slug; + } + + /** + * Retrieve plugin data, given the plugin name. + * + * Loops through the registered plugins looking for $name. If it finds it, + * it returns the $data from that plugin. Otherwise, returns false. + * + * @since 2.1.0 + * + * @param string $name Name of the plugin, as it was registered. + * @param string $data Optional. Array key of plugin data to return. Default is slug. + * @return string|boolean Plugin slug if found, false otherwise. + */ + public function _get_plugin_data_from_name( $name, $data = 'slug' ) { + foreach ( $this->plugins as $values ) { + if ( $name === $values['name'] && isset( $values[ $data ] ) ) { + return $values[ $data ]; + } + } + + return false; + } + + /** + * Retrieve the download URL for a package. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return string Plugin download URL or path to local file or empty string if undetermined. + */ + public function get_download_url( $slug ) { + $dl_source = ''; + + switch ( $this->plugins[ $slug ]['source_type'] ) { + case 'repo': + return $this->get_wp_repo_download_url( $slug ); + case 'external': + return $this->plugins[ $slug ]['source']; + case 'bundled': + return $this->default_path . $this->plugins[ $slug ]['source']; + } + + return $dl_source; // Should never happen. + } + + /** + * Retrieve the download URL for a WP repo package. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return string Plugin download URL. + */ + protected function get_wp_repo_download_url( $slug ) { + $source = ''; + $api = $this->get_plugins_api( $slug ); + + if ( false !== $api && isset( $api->download_link ) ) { + $source = $api->download_link; + } + + return $source; + } + + /** + * Try to grab information from WordPress API. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return object Plugins_api response object on success, WP_Error on failure. + */ + protected function get_plugins_api( $slug ) { + static $api = array(); // Cache received responses. + + if ( ! isset( $api[ $slug ] ) ) { + if ( ! function_exists( 'plugins_api' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; + } + + $response = plugins_api( 'plugin_information', array( 'slug' => $slug, 'fields' => array( 'sections' => false ) ) ); + + $api[ $slug ] = false; + + if ( is_wp_error( $response ) ) { + wp_die( esc_html( $this->strings['oops'] ) ); + } else { + $api[ $slug ] = $response; + } + } + + return $api[ $slug ]; + } + + /** + * Retrieve a link to a plugin information page. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return string Fully formed html link to a plugin information page if available + * or the plugin name if not. + */ + public function get_info_link( $slug ) { + if ( ! empty( $this->plugins[ $slug ]['external_url'] ) && preg_match( self::IS_URL_REGEX, $this->plugins[ $slug ]['external_url'] ) ) { + $link = sprintf( + '%2$s', + esc_url( $this->plugins[ $slug ]['external_url'] ), + esc_html( $this->plugins[ $slug ]['name'] ) + ); + } elseif ( 'repo' === $this->plugins[ $slug ]['source_type'] ) { + $url = add_query_arg( + array( + 'tab' => 'plugin-information', + 'plugin' => urlencode( $slug ), + 'TB_iframe' => 'true', + 'width' => '640', + 'height' => '500', + ), + self_admin_url( 'plugin-install.php' ) + ); + + $link = sprintf( + '%2$s', + esc_url( $url ), + esc_html( $this->plugins[ $slug ]['name'] ) + ); + } else { + $link = esc_html( $this->plugins[ $slug ]['name'] ); // No hyperlink. + } + + return $link; + } + + /** + * Determine if we're on the TGMPA Install page. + * + * @since 2.1.0 + * + * @return boolean True when on the TGMPA page, false otherwise. + */ + protected function is_tgmpa_page() { + return isset( $_GET['page'] ) && $this->menu === $_GET['page']; + } + + /** + * Retrieve the URL to the TGMPA Install page. + * + * I.e. depending on the config settings passed something along the lines of: + * http://example.com/wp-admin/themes.php?page=tgmpa-install-plugins + * + * @since 2.5.0 + * + * @return string Properly encoded URL (not escaped). + */ + public function get_tgmpa_url() { + static $url; + + if ( ! isset( $url ) ) { + $parent = $this->parent_slug; + if ( false === strpos( $parent, '.php' ) ) { + $parent = 'admin.php'; + } + $url = add_query_arg( + array( + 'page' => urlencode( $this->menu ), + ), + self_admin_url( $parent ) + ); + } + + return $url; + } + + /** + * Retrieve the URL to the TGMPA Install page for a specific plugin status (view). + * + * I.e. depending on the config settings passed something along the lines of: + * http://example.com/wp-admin/themes.php?page=tgmpa-install-plugins&plugin_status=install + * + * @since 2.5.0 + * + * @param string $status Plugin status - either 'install', 'update' or 'activate'. + * @return string Properly encoded URL (not escaped). + */ + public function get_tgmpa_status_url( $status ) { + return add_query_arg( + array( + 'plugin_status' => urlencode( $status ), + ), + $this->get_tgmpa_url() + ); + } + + /** + * Determine whether there are open actions for plugins registered with TGMPA. + * + * @since 2.5.0 + * + * @return bool True if complete, i.e. no outstanding actions. False otherwise. + */ + public function is_tgmpa_complete() { + $complete = true; + foreach ( $this->plugins as $slug => $plugin ) { + if ( ! $this->is_plugin_active( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) { + $complete = false; + break; + } + } + + return $complete; + } + + /** + * Check if a plugin is installed. Does not take must-use plugins into account. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return bool True if installed, false otherwise. + */ + public function is_plugin_installed( $slug ) { + $installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached). + + return ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ] ) ); + } + + /** + * Check if a plugin is active. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return bool True if active, false otherwise. + */ + public function is_plugin_active( $slug ) { + return ( ( ! empty( $this->plugins[ $slug ]['is_callable'] ) && is_callable( $this->plugins[ $slug ]['is_callable'] ) ) || is_plugin_active( $this->plugins[ $slug ]['file_path'] ) ); + } + + /** + * Check if a plugin can be updated, i.e. if we have information on the minimum WP version required + * available, check whether the current install meets them. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return bool True if OK to update, false otherwise. + */ + public function can_plugin_update( $slug ) { + // We currently can't get reliable info on non-WP-repo plugins - issue #380. + if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { + return true; + } + + $api = $this->get_plugins_api( $slug ); + + if ( false !== $api && isset( $api->requires ) ) { + return version_compare( $GLOBALS['wp_version'], $api->requires, '>=' ); + } + + // No usable info received from the plugins API, presume we can update. + return true; + } + + /** + * Check if a plugin can be activated, i.e. is not currently active and meets the minimum + * plugin version requirements set in TGMPA (if any). + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return bool True if OK to activate, false otherwise. + */ + public function can_plugin_activate( $slug ) { + return ( ! $this->is_plugin_active( $slug ) && ! $this->does_plugin_require_update( $slug ) ); + } + + /** + * Retrieve the version number of an installed plugin. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return string Version number as string or an empty string if the plugin is not installed + * or version unknown (plugins which don't comply with the plugin header standard). + */ + public function get_installed_version( $slug ) { + $installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached). + + if ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version'] ) ) { + return $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version']; + } + + return ''; + } + + /** + * Check whether a plugin complies with the minimum version requirements. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return bool True when a plugin needs to be updated, otherwise false. + */ + public function does_plugin_require_update( $slug ) { + $installed_version = $this->get_installed_version( $slug ); + $minimum_version = $this->plugins[ $slug ]['version']; + + return version_compare( $minimum_version, $installed_version, '>' ); + } + + /** + * Check whether there is an update available for a plugin. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return false|string Version number string of the available update or false if no update available. + */ + public function does_plugin_have_update( $slug ) { + // Presume bundled and external plugins will point to a package which meets the minimum required version. + if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { + if ( $this->does_plugin_require_update( $slug ) ) { + return $this->plugins[ $slug ]['version']; + } + + return false; + } + + $repo_updates = get_site_transient( 'update_plugins' ); + + if ( isset( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version ) ) { + return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version; + } + + return false; + } + + /** + * Retrieve potential upgrade notice for a plugin. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return string The upgrade notice or an empty string if no message was available or provided. + */ + public function get_upgrade_notice( $slug ) { + // We currently can't get reliable info on non-WP-repo plugins - issue #380. + if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { + return ''; + } + + $repo_updates = get_site_transient( 'update_plugins' ); + + if ( ! empty( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice ) ) { + return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice; + } + + return ''; + } + + /** + * Wrapper around the core WP get_plugins function, making sure it's actually available. + * + * @since 2.5.0 + * + * @param string $plugin_folder Optional. Relative path to single plugin folder. + * @return array Array of installed plugins with plugin information. + */ + public function get_plugins( $plugin_folder = '' ) { + if ( ! function_exists( 'get_plugins' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + + return get_plugins( $plugin_folder ); + } + + /** + * Delete dismissable nag option when theme is switched. + * + * This ensures that the user(s) is/are again reminded via nag of required + * and/or recommended plugins if they re-activate the theme. + * + * @since 2.1.1 + */ + public function update_dismiss() { + delete_metadata( 'user', null, 'tgmpa_dismissed_notice_' . $this->id, null, true ); + } + + /** + * Forces plugin activation if the parameter 'force_activation' is + * set to true. + * + * This allows theme authors to specify certain plugins that must be + * active at all times while using the current theme. + * + * Please take special care when using this parameter as it has the + * potential to be harmful if not used correctly. Setting this parameter + * to true will not allow the specified plugin to be deactivated unless + * the user switches themes. + * + * @since 2.2.0 + */ + public function force_activation() { + foreach ( $this->plugins as $slug => $plugin ) { + if ( true === $plugin['force_activation'] ) { + if ( ! $this->is_plugin_installed( $slug ) ) { + // Oops, plugin isn't there so iterate to next condition. + continue; + } elseif ( $this->can_plugin_activate( $slug ) ) { + // There we go, activate the plugin. + activate_plugin( $plugin['file_path'] ); + } + } + } + } + + /** + * Forces plugin deactivation if the parameter 'force_deactivation' + * is set to true. + * + * This allows theme authors to specify certain plugins that must be + * deactivated upon switching from the current theme to another. + * + * Please take special care when using this parameter as it has the + * potential to be harmful if not used correctly. + * + * @since 2.2.0 + */ + public function force_deactivation() { + foreach ( $this->plugins as $slug => $plugin ) { + // Only proceed forward if the parameter is set to true and plugin is active. + if ( true === $plugin['force_deactivation'] && $this->is_plugin_active( $slug ) ) { + deactivate_plugins( $plugin['file_path'] ); + } + } + } + + /** + * Echo the current TGMPA version number to the page. + */ + public function show_tgmpa_version() { + echo '

', + esc_html( sprintf( _x( 'TGMPA v%s', '%s = version number', 'tgmpa' ), self::TGMPA_VERSION ) ), + '

'; + } + + /** + * Returns the singleton instance of the class. + * + * @since 2.4.0 + * + * @return object The TGM_Plugin_Activation object. + */ + public static function get_instance() { + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { + self::$instance = new self(); + } + + return self::$instance; + } + } + + if ( ! function_exists( 'load_tgm_plugin_activation' ) ) { + /** + * Ensure only one instance of the class is ever invoked. + */ + function load_tgm_plugin_activation() { + $GLOBALS['tgmpa'] = TGM_Plugin_Activation::get_instance(); + } + } + + if ( did_action( 'plugins_loaded' ) ) { + load_tgm_plugin_activation(); + } else { + add_action( 'plugins_loaded', 'load_tgm_plugin_activation' ); + } +} + +if ( ! function_exists( 'tgmpa' ) ) { + /** + * Helper function to register a collection of required plugins. + * + * @since 2.0.0 + * @api + * + * @param array $plugins An array of plugin arrays. + * @param array $config Optional. An array of configuration values. + */ + function tgmpa( $plugins, $config = array() ) { + $instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) ); + + foreach ( $plugins as $plugin ) { + call_user_func( array( $instance, 'register' ), $plugin ); + } + + if ( ! empty( $config ) && is_array( $config ) ) { + // Send out notices for deprecated arguments passed. + if ( isset( $config['notices'] ) ) { + _deprecated_argument( __FUNCTION__, '2.2.0', 'The `notices` config parameter was renamed to `has_notices` in TGMPA 2.2.0. Please adjust your configuration.' ); + if ( ! isset( $config['has_notices'] ) ) { + $config['has_notices'] = $config['notices']; + } + } + + if ( isset( $config['parent_menu_slug'] ) ) { + _deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_menu_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' ); + } + if ( isset( $config['parent_url_slug'] ) ) { + _deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_url_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' ); + } + + call_user_func( array( $instance, 'config' ), $config ); + } + } +} + +/** + * WP_List_Table isn't always available. If it isn't available, + * we load it here. + * + * @since 2.2.0 + */ +if ( ! class_exists( 'WP_List_Table' ) ) { + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; +} + +if ( ! class_exists( 'TGMPA_List_Table' ) ) { + + /** + * List table class for handling plugins. + * + * Extends the WP_List_Table class to provide a future-compatible + * way of listing out all required/recommended plugins. + * + * Gives users an interface similar to the Plugin Administration + * area with similar (albeit stripped down) capabilities. + * + * This class also allows for the bulk install of plugins. + * + * @since 2.2.0 + * + * @package TGM-Plugin-Activation + * @author Thomas Griffin + * @author Gary Jones + */ + class TGMPA_List_Table extends WP_List_Table { + /** + * TGMPA instance. + * + * @since 2.5.0 + * + * @var object + */ + protected $tgmpa; + + /** + * The currently chosen view. + * + * @since 2.5.0 + * + * @var string One of: 'all', 'install', 'update', 'activate' + */ + public $view_context = 'all'; + + /** + * The plugin counts for the various views. + * + * @since 2.5.0 + * + * @var array + */ + protected $view_totals = array( + 'all' => 0, + 'install' => 0, + 'update' => 0, + 'activate' => 0, + ); + + /** + * References parent constructor and sets defaults for class. + * + * @since 2.2.0 + */ + public function __construct() { + $this->tgmpa = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) ); + + parent::__construct( + array( + 'singular' => 'plugin', + 'plural' => 'plugins', + 'ajax' => false, + ) + ); + + if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'install', 'update', 'activate' ), true ) ) { + $this->view_context = sanitize_key( $_REQUEST['plugin_status'] ); + } + + add_filter( 'tgmpa_table_data_items', array( $this, 'sort_table_items' ) ); + } + + /** + * Get a list of CSS classes for the tag. + * + * Overruled to prevent the 'plural' argument from being added. + * + * @since 2.5.0 + * + * @return array CSS classnames. + */ + public function get_table_classes() { + return array( 'widefat', 'fixed' ); + } + + /** + * Gathers and renames all of our plugin information to be used by WP_List_Table to create our table. + * + * @since 2.2.0 + * + * @return array $table_data Information for use in table. + */ + protected function _gather_plugin_data() { + // Load thickbox for plugin links. + $this->tgmpa->admin_init(); + $this->tgmpa->thickbox(); + + // Categorize the plugins which have open actions. + $plugins = $this->categorize_plugins_to_views(); + + // Set the counts for the view links. + $this->set_view_totals( $plugins ); + + // Prep variables for use and grab list of all installed plugins. + $table_data = array(); + $i = 0; + + // Redirect to the 'all' view if no plugins were found for the selected view context. + if ( empty( $plugins[ $this->view_context ] ) ) { + $this->view_context = 'all'; + } + + foreach ( $plugins[ $this->view_context ] as $slug => $plugin ) { + $table_data[ $i ]['sanitized_plugin'] = $plugin['name']; + $table_data[ $i ]['slug'] = $slug; + $table_data[ $i ]['plugin'] = '' . $this->tgmpa->get_info_link( $slug ) . ''; + $table_data[ $i ]['source'] = $this->get_plugin_source_type_text( $plugin['source_type'] ); + $table_data[ $i ]['type'] = $this->get_plugin_advise_type_text( $plugin['required'] ); + $table_data[ $i ]['status'] = $this->get_plugin_status_text( $slug ); + $table_data[ $i ]['installed_version'] = $this->tgmpa->get_installed_version( $slug ); + $table_data[ $i ]['minimum_version'] = $plugin['version']; + $table_data[ $i ]['available_version'] = $this->tgmpa->does_plugin_have_update( $slug ); + + // Prep the upgrade notice info. + $upgrade_notice = $this->tgmpa->get_upgrade_notice( $slug ); + if ( ! empty( $upgrade_notice ) ) { + $table_data[ $i ]['upgrade_notice'] = $upgrade_notice; + + add_action( "tgmpa_after_plugin_row_$slug", array( $this, 'wp_plugin_update_row' ), 10, 2 ); + } + + $table_data[ $i ] = apply_filters( 'tgmpa_table_data_item', $table_data[ $i ], $plugin ); + + $i++; + } + + return $table_data; + } + + /** + * Categorize the plugins which have open actions into views for the TGMPA page. + * + * @since 2.5.0 + */ + protected function categorize_plugins_to_views() { + $plugins = array( + 'all' => array(), // Meaning: all plugins which still have open actions. + 'install' => array(), + 'update' => array(), + 'activate' => array(), + ); + + foreach ( $this->tgmpa->plugins as $slug => $plugin ) { + if ( $this->tgmpa->is_plugin_active( $slug ) && false === $this->tgmpa->does_plugin_have_update( $slug ) ) { + // No need to display plugins if they are installed, up-to-date and active. + continue; + } else { + $plugins['all'][ $slug ] = $plugin; + + if ( ! $this->tgmpa->is_plugin_installed( $slug ) ) { + $plugins['install'][ $slug ] = $plugin; + } else { + if ( false !== $this->tgmpa->does_plugin_have_update( $slug ) ) { + $plugins['update'][ $slug ] = $plugin; + } + + if ( $this->tgmpa->can_plugin_activate( $slug ) ) { + $plugins['activate'][ $slug ] = $plugin; + } + } + } + } + + return $plugins; + } + + /** + * Set the counts for the view links. + * + * @since 2.5.0 + * + * @param array $plugins Plugins order by view. + */ + protected function set_view_totals( $plugins ) { + foreach ( $plugins as $type => $list ) { + $this->view_totals[ $type ] = count( $list ); + } + } + + /** + * Get the plugin required/recommended text string. + * + * @since 2.5.0 + * + * @param string $required Plugin required setting. + * @return string + */ + protected function get_plugin_advise_type_text( $required ) { + if ( true === $required ) { + return __( 'Required', 'tgmpa' ); + } + + return __( 'Recommended', 'tgmpa' ); + } + + /** + * Get the plugin source type text string. + * + * @since 2.5.0 + * + * @param string $type Plugin type. + * @return string + */ + protected function get_plugin_source_type_text( $type ) { + $string = ''; + + switch ( $type ) { + case 'repo': + $string = __( 'WordPress Repository', 'tgmpa' ); + break; + case 'external': + $string = __( 'External Source', 'tgmpa' ); + break; + case 'bundled': + $string = __( 'Pre-Packaged', 'tgmpa' ); + break; + } + + return $string; + } + + /** + * Determine the plugin status message. + * + * @since 2.5.0 + * + * @param string $slug Plugin slug. + * @return string + */ + protected function get_plugin_status_text( $slug ) { + if ( ! $this->tgmpa->is_plugin_installed( $slug ) ) { + return __( 'Not Installed', 'tgmpa' ); + } + + if ( ! $this->tgmpa->is_plugin_active( $slug ) ) { + $install_status = __( 'Installed But Not Activated', 'tgmpa' ); + } else { + $install_status = __( 'Active', 'tgmpa' ); + } + + $update_status = ''; + + if ( $this->tgmpa->does_plugin_require_update( $slug ) && false === $this->tgmpa->does_plugin_have_update( $slug ) ) { + $update_status = __( 'Required Update not Available', 'tgmpa' ); + + } elseif ( $this->tgmpa->does_plugin_require_update( $slug ) ) { + $update_status = __( 'Requires Update', 'tgmpa' ); + + } elseif ( false !== $this->tgmpa->does_plugin_have_update( $slug ) ) { + $update_status = __( 'Update recommended', 'tgmpa' ); + } + + if ( '' === $update_status ) { + return $install_status; + } + + return sprintf( + _x( '%1$s, %2$s', '%1$s = install status, %2$s = update status', 'tgmpa' ), + $install_status, + $update_status + ); + } + + /** + * Sort plugins by Required/Recommended type and by alphabetical plugin name within each type. + * + * @since 2.5.0 + * + * @param array $items Prepared table items. + * @return array Sorted table items. + */ + public function sort_table_items( $items ) { + $type = array(); + $name = array(); + + foreach ( $items as $i => $plugin ) { + $type[ $i ] = $plugin['type']; // Required / recommended. + $name[ $i ] = $plugin['sanitized_plugin']; + } + + array_multisort( $type, SORT_DESC, $name, SORT_ASC, $items ); + + return $items; + } + + /** + * Get an associative array ( id => link ) of the views available on this table. + * + * @since 2.5.0 + * + * @return array + */ + public function get_views() { + $status_links = array(); + + foreach ( $this->view_totals as $type => $count ) { + if ( $count < 1 ) { + continue; + } + + switch ( $type ) { + case 'all': + $text = _nx( 'All (%s)', 'All (%s)', $count, 'plugins', 'tgmpa' ); + break; + case 'install': + $text = _n( 'To Install (%s)', 'To Install (%s)', $count, 'tgmpa' ); + break; + case 'update': + $text = _n( 'Update Available (%s)', 'Update Available (%s)', $count, 'tgmpa' ); + break; + case 'activate': + $text = _n( 'To Activate (%s)', 'To Activate (%s)', $count, 'tgmpa' ); + break; + default: + $text = ''; + break; + } + + if ( ! empty( $text ) ) { + + $status_links[ $type ] = sprintf( + '%s', + esc_url( $this->tgmpa->get_tgmpa_status_url( $type ) ), + ( $type === $this->view_context ) ? ' class="current"' : '', + sprintf( $text, number_format_i18n( $count ) ) + ); + } + } + + return $status_links; + } + + /** + * Create default columns to display important plugin information + * like type, action and status. + * + * @since 2.2.0 + * + * @param array $item Array of item data. + * @param string $column_name The name of the column. + * @return string + */ + public function column_default( $item, $column_name ) { + return $item[ $column_name ]; + } + + /** + * Required for bulk installing. + * + * Adds a checkbox for each plugin. + * + * @since 2.2.0 + * + * @param array $item Array of item data. + * @return string The input checkbox with all necessary info. + */ + public function column_cb( $item ) { + return sprintf( + '', + esc_attr( $this->_args['singular'] ), + esc_attr( $item['slug'] ), + esc_attr( $item['sanitized_plugin'] ) + ); + } + + /** + * Create default title column along with the action links. + * + * @since 2.2.0 + * + * @param array $item Array of item data. + * @return string The plugin name and action links. + */ + public function column_plugin( $item ) { + return sprintf( + '%1$s %2$s', + $item['plugin'], + $this->row_actions( $this->get_row_actions( $item ), true ) + ); + } + + /** + * Create version information column. + * + * @since 2.5.0 + * + * @param array $item Array of item data. + * @return string HTML-formatted version information. + */ + public function column_version( $item ) { + $output = array(); + + if ( $this->tgmpa->is_plugin_installed( $item['slug'] ) ) { + $installed = ! empty( $item['installed_version'] ) ? $item['installed_version'] : _x( 'unknown', 'as in: "version nr unknown"', 'tgmpa' ); + + $color = ''; + if ( ! empty( $item['minimum_version'] ) && $this->tgmpa->does_plugin_require_update( $item['slug'] ) ) { + $color = ' color: #ff0000; font-weight: bold;'; + } + + $output[] = sprintf( + '

%2$s' . __( 'Installed version:', 'tgmpa' ) . '

', + $color, + $installed + ); + } + + if ( ! empty( $item['minimum_version'] ) ) { + $output[] = sprintf( + '

%1$s' . __( 'Minimum required version:', 'tgmpa' ) . '

', + $item['minimum_version'] + ); + } + + if ( ! empty( $item['available_version'] ) ) { + $color = ''; + if ( ! empty( $item['minimum_version'] ) && version_compare( $item['available_version'], $item['minimum_version'], '>=' ) ) { + $color = ' color: #71C671; font-weight: bold;'; + } + + $output[] = sprintf( + '

%2$s' . __( 'Available version:', 'tgmpa' ) . '

', + $color, + $item['available_version'] + ); + } + + if ( empty( $output ) ) { + return ' '; // Let's not break the table layout. + } else { + return implode( "\n", $output ); + } + } + + /** + * Sets default message within the plugins table if no plugins + * are left for interaction. + * + * Hides the menu item to prevent the user from clicking and + * getting a permissions error. + * + * @since 2.2.0 + */ + public function no_items() { + printf( wp_kses_post( __( 'No plugins to install, update or activate. Return to the Dashboard', 'tgmpa' ) ), esc_url( self_admin_url() ) ); + echo ''; + } + + /** + * Output all the column information within the table. + * + * @since 2.2.0 + * + * @return array $columns The column names. + */ + public function get_columns() { + $columns = array( + 'cb' => '', + 'plugin' => __( 'Plugin', 'tgmpa' ), + 'source' => __( 'Source', 'tgmpa' ), + 'type' => __( 'Type', 'tgmpa' ), + ); + + if ( 'all' === $this->view_context || 'update' === $this->view_context ) { + $columns['version'] = __( 'Version', 'tgmpa' ); + $columns['status'] = __( 'Status', 'tgmpa' ); + } + + return apply_filters( 'tgmpa_table_columns', $columns ); + } + + /** + * Get name of default primary column + * + * @since 2.5.0 / WP 4.3+ compatibility + * @access protected + * + * @return string + */ + protected function get_default_primary_column_name() { + return 'plugin'; + } + + /** + * Get the name of the primary column. + * + * @since 2.5.0 / WP 4.3+ compatibility + * @access protected + * + * @return string The name of the primary column. + */ + protected function get_primary_column_name() { + if ( method_exists( 'WP_List_Table', 'get_primary_column_name' ) ) { + return parent::get_primary_column_name(); + } else { + return $this->get_default_primary_column_name(); + } + } + + /** + * Get the actions which are relevant for a specific plugin row. + * + * @since 2.5.0 + * + * @param array $item Array of item data. + * @return array Array with relevant action links. + */ + protected function get_row_actions( $item ) { + $actions = array(); + $action_links = array(); + + // Display the 'Install' action link if the plugin is not yet available. + if ( ! $this->tgmpa->is_plugin_installed( $item['slug'] ) ) { + $actions['install'] = _x( 'Install %2$s', '%2$s = plugin name in screen reader markup', 'tgmpa' ); + } else { + // Display the 'Update' action link if an update is available and WP complies with plugin minimum. + if ( false !== $this->tgmpa->does_plugin_have_update( $item['slug'] ) && $this->tgmpa->can_plugin_update( $item['slug'] ) ) { + $actions['update'] = _x( 'Update %2$s', '%2$s = plugin name in screen reader markup', 'tgmpa' ); + } + + // Display the 'Activate' action link, but only if the plugin meets the minimum version. + if ( $this->tgmpa->can_plugin_activate( $item['slug'] ) ) { + $actions['activate'] = _x( 'Activate %2$s', '%2$s = plugin name in screen reader markup', 'tgmpa' ); + } + } + + // Create the actual links. + foreach ( $actions as $action => $text ) { + $nonce_url = wp_nonce_url( + add_query_arg( + array( + 'plugin' => urlencode( $item['slug'] ), + 'tgmpa-' . $action => $action . '-plugin', + ), + $this->tgmpa->get_tgmpa_url() + ), + 'tgmpa-' . $action, + 'tgmpa-nonce' + ); + + $action_links[ $action ] = sprintf( + '' . esc_html( $text ) . '', + esc_url( $nonce_url ), + '' . esc_html( $item['sanitized_plugin'] ) . '' + ); + } + + $prefix = ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) ? 'network_admin_' : ''; + return apply_filters( "tgmpa_{$prefix}plugin_action_links", array_filter( $action_links ), $item['slug'], $item, $this->view_context ); + } + + /** + * Generates content for a single row of the table. + * + * @since 2.5.0 + * + * @param object $item The current item. + */ + public function single_row( $item ) { + parent::single_row( $item ); + + /** + * Fires after each specific row in the TGMPA Plugins list table. + * + * The dynamic portion of the hook name, `$item['slug']`, refers to the slug + * for the plugin. + * + * @since 2.5.0 + */ + do_action( "tgmpa_after_plugin_row_{$item['slug']}", $item['slug'], $item, $this->view_context ); + } + + /** + * Show the upgrade notice below a plugin row if there is one. + * + * @since 2.5.0 + * + * @see /wp-admin/includes/update.php + * + * @param string $slug Plugin slug. + * @param array $item The information available in this table row. + * @return null Return early if upgrade notice is empty. + */ + public function wp_plugin_update_row( $slug, $item ) { + if ( empty( $item['upgrade_notice'] ) ) { + return; + } + + echo ' + + + '; + } + + /** + * Extra controls to be displayed between bulk actions and pagination. + * + * @since 2.5.0 + * + * @param string $which 'top' or 'bottom' table navigation. + */ + public function extra_tablenav( $which ) { + if ( 'bottom' === $which ) { + $this->tgmpa->show_tgmpa_version(); + } + } + + /** + * Defines the bulk actions for handling registered plugins. + * + * @since 2.2.0 + * + * @return array $actions The bulk actions for the plugin install table. + */ + public function get_bulk_actions() { + + $actions = array(); + + if ( 'update' !== $this->view_context && 'activate' !== $this->view_context ) { + if ( current_user_can( 'install_plugins' ) ) { + $actions['tgmpa-bulk-install'] = __( 'Install', 'tgmpa' ); + } + } + + if ( 'install' !== $this->view_context ) { + if ( current_user_can( 'update_plugins' ) ) { + $actions['tgmpa-bulk-update'] = __( 'Update', 'tgmpa' ); + } + if ( current_user_can( 'activate_plugins' ) ) { + $actions['tgmpa-bulk-activate'] = __( 'Activate', 'tgmpa' ); + } + } + + return $actions; + } + + /** + * Processes bulk installation and activation actions. + * + * The bulk installation process looks for the $_POST information and passes that + * through if a user has to use WP_Filesystem to enter their credentials. + * + * @since 2.2.0 + */ + public function process_bulk_actions() { + // Bulk installation process. + if ( 'tgmpa-bulk-install' === $this->current_action() || 'tgmpa-bulk-update' === $this->current_action() ) { + + check_admin_referer( 'bulk-' . $this->_args['plural'] ); + + $install_type = 'install'; + if ( 'tgmpa-bulk-update' === $this->current_action() ) { + $install_type = 'update'; + } + + $plugins_to_install = array(); + + // Did user actually select any plugins to install/update ? + if ( empty( $_POST['plugin'] ) ) { + if ( 'install' === $install_type ) { + $message = __( 'No plugins were selected to be installed. No action taken.', 'tgmpa' ); + } else { + $message = __( 'No plugins were selected to be updated. No action taken.', 'tgmpa' ); + } + + echo '

', esc_html( $message ), '

'; + + return false; + } + + if ( is_array( $_POST['plugin'] ) ) { + $plugins_to_install = (array) $_POST['plugin']; + } elseif ( is_string( $_POST['plugin'] ) ) { + // Received via Filesystem page - un-flatten array (WP bug #19643). + $plugins_to_install = explode( ',', $_POST['plugin'] ); + } + + // Sanitize the received input. + $plugins_to_install = array_map( 'urldecode', $plugins_to_install ); + $plugins_to_install = array_map( array( $this->tgmpa, 'sanitize_key' ), $plugins_to_install ); + + // Validate the received input. + foreach ( $plugins_to_install as $key => $slug ) { + // Check if the plugin was registered with TGMPA and remove if not. + if ( ! isset( $this->tgmpa->plugins[ $slug ] ) ) { + unset( $plugins_to_install[ $key ] ); + continue; + } + + // For updates: make sure this is a plugin we *can* update (update available and WP version ok). + if ( 'update' === $install_type && ( $this->tgmpa->is_plugin_installed( $slug ) && ( false === $this->tgmpa->does_plugin_have_update( $slug ) || ! $this->tgmpa->can_plugin_update( $slug ) ) ) ) { + unset( $plugins_to_install[ $key ] ); + } + } + + // No need to proceed further if we have no plugins to handle. + if ( empty( $plugins_to_install ) ) { + if ( 'install' === $install_type ) { + $message = __( 'No plugins are available to be installed at this time.', 'tgmpa' ); + } else { + $message = __( 'No plugins are available to be updated at this time.', 'tgmpa' ); + } + + echo '

', esc_html( $message ), '

'; + + return false; + } + + // Pass all necessary information if WP_Filesystem is needed. + $url = wp_nonce_url( + $this->tgmpa->get_tgmpa_url(), + 'bulk-' . $this->_args['plural'] + ); + + // Give validated data back to $_POST which is the only place the filesystem looks for extra fields. + $_POST['plugin'] = implode( ',', $plugins_to_install ); // Work around for WP bug #19643. + + $method = ''; // Leave blank so WP_Filesystem can populate it as necessary. + $fields = array_keys( $_POST ); // Extra fields to pass to WP_Filesystem. + + if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, $fields ) ) ) { + return true; // Stop the normal page form from displaying, credential request form will be shown. + } + + // Now we have some credentials, setup WP_Filesystem. + if ( ! WP_Filesystem( $creds ) ) { + // Our credentials were no good, ask the user for them again. + request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, $fields ); + + return true; + } + + /* If we arrive here, we have the filesystem */ + + // Store all information in arrays since we are processing a bulk installation. + $names = array(); + $sources = array(); // Needed for installs. + $file_paths = array(); // Needed for upgrades. + $to_inject = array(); // Information to inject into the update_plugins transient. + + // Prepare the data for validated plugins for the install/upgrade. + foreach ( $plugins_to_install as $slug ) { + $name = $this->tgmpa->plugins[ $slug ]['name']; + $source = $this->tgmpa->get_download_url( $slug ); + + if ( ! empty( $name ) && ! empty( $source ) ) { + $names[] = $name; + + switch ( $install_type ) { + + case 'install': + $sources[] = $source; + break; + + case 'update': + $file_paths[] = $this->tgmpa->plugins[ $slug ]['file_path']; + $to_inject[ $slug ] = $this->tgmpa->plugins[ $slug ]; + $to_inject[ $slug ]['source'] = $source; + break; + } + } + } + unset( $slug, $name, $source ); + + // Create a new instance of TGMPA_Bulk_Installer. + $installer = new TGMPA_Bulk_Installer( + new TGMPA_Bulk_Installer_Skin( + array( + 'url' => esc_url_raw( $this->tgmpa->get_tgmpa_url() ), + 'nonce' => 'bulk-' . $this->_args['plural'], + 'names' => $names, + 'install_type' => $install_type, + ) + ) + ); + + // Wrap the install process with the appropriate HTML. + echo '
', + '

', esc_html( get_admin_page_title() ), '

'; + + // Process the bulk installation submissions. + add_filter( 'upgrader_source_selection', array( $this->tgmpa, 'maybe_adjust_source_dir' ), 1, 3 ); + + if ( 'tgmpa-bulk-update' === $this->current_action() ) { + // Inject our info into the update transient. + $this->tgmpa->inject_update_info( $to_inject ); + + $installer->bulk_upgrade( $file_paths ); + } else { + $installer->bulk_install( $sources ); + } + + remove_filter( 'upgrader_source_selection', array( $this->tgmpa, 'maybe_adjust_source_dir' ), 1, 3 ); + + echo '
'; + + return true; + } + + // Bulk activation process. + if ( 'tgmpa-bulk-activate' === $this->current_action() ) { + check_admin_referer( 'bulk-' . $this->_args['plural'] ); + + // Did user actually select any plugins to activate ? + if ( empty( $_POST['plugin'] ) ) { + echo '

', esc_html__( 'No plugins were selected to be activated. No action taken.', 'tgmpa' ), '

'; + + return false; + } + + // Grab plugin data from $_POST. + $plugins = array(); + if ( isset( $_POST['plugin'] ) ) { + $plugins = array_map( 'urldecode', (array) $_POST['plugin'] ); + $plugins = array_map( array( $this->tgmpa, 'sanitize_key' ), $plugins ); + } + + $plugins_to_activate = array(); + $plugin_names = array(); + + // Grab the file paths for the selected & inactive plugins from the registration array. + foreach ( $plugins as $slug ) { + if ( $this->tgmpa->can_plugin_activate( $slug ) ) { + $plugins_to_activate[] = $this->tgmpa->plugins[ $slug ]['file_path']; + $plugin_names[] = $this->tgmpa->plugins[ $slug ]['name']; + } + } + unset( $slug ); + + // Return early if there are no plugins to activate. + if ( empty( $plugins_to_activate ) ) { + echo '

', esc_html__( 'No plugins are available to be activated at this time.', 'tgmpa' ), '

'; + + return false; + } + + // Now we are good to go - let's start activating plugins. + $activate = activate_plugins( $plugins_to_activate ); + + if ( is_wp_error( $activate ) ) { + echo '

', wp_kses_post( $activate->get_error_message() ), '

'; + } else { + $count = count( $plugin_names ); // Count so we can use _n function. + $plugin_names = array_map( array( 'TGMPA_Utils', 'wrap_in_strong' ), $plugin_names ); + $last_plugin = array_pop( $plugin_names ); // Pop off last name to prep for readability. + $imploded = empty( $plugin_names ) ? $last_plugin : ( implode( ', ', $plugin_names ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'tgmpa' ) . ' ' . $last_plugin ); + + printf( // WPCS: xss ok. + '

%1$s %2$s.

', + esc_html( _n( 'The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, 'tgmpa' ) ), + $imploded + ); + + // Update recently activated plugins option. + $recent = (array) get_option( 'recently_activated' ); + foreach ( $plugins_to_activate as $plugin => $time ) { + if ( isset( $recent[ $plugin ] ) ) { + unset( $recent[ $plugin ] ); + } + } + update_option( 'recently_activated', $recent ); + } + + unset( $_POST ); // Reset the $_POST variable in case user wants to perform one action after another. + + return true; + } + + return false; + } + + /** + * Prepares all of our information to be outputted into a usable table. + * + * @since 2.2.0 + */ + public function prepare_items() { + $columns = $this->get_columns(); // Get all necessary column information. + $hidden = array(); // No columns to hide, but we must set as an array. + $sortable = array(); // No reason to make sortable columns. + $primary = $this->get_primary_column_name(); // Column which has the row actions. + $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); // Get all necessary column headers. + + // Process our bulk activations here. + if ( 'tgmpa-bulk-activate' === $this->current_action() ) { + $this->process_bulk_actions(); + } + + // Store all of our plugin data into $items array so WP_List_Table can use it. + $this->items = apply_filters( 'tgmpa_table_data_items', $this->_gather_plugin_data() ); + } + + /* *********** DEPRECATED METHODS *********** */ + + /** + * Retrieve plugin data, given the plugin name. + * + * @since 2.2.0 + * @deprecated 2.5.0 use {@see TGM_Plugin_Activation::_get_plugin_data_from_name()} instead. + * @see TGM_Plugin_Activation::_get_plugin_data_from_name() + * + * @param string $name Name of the plugin, as it was registered. + * @param string $data Optional. Array key of plugin data to return. Default is slug. + * @return string|boolean Plugin slug if found, false otherwise. + */ + protected function _get_plugin_data_from_name( $name, $data = 'slug' ) { + _deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'TGM_Plugin_Activation::_get_plugin_data_from_name()' ); + + return $this->tgmpa->_get_plugin_data_from_name( $name, $data ); + } + } +} + + +if ( ! class_exists( 'TGM_Bulk_Installer' ) ) { + + /** + * Hack: Prevent TGMPA v2.4.1- bulk installer class from being loaded if 2.4.1- is loaded after 2.5+. + */ + class TGM_Bulk_Installer { + } +} +if ( ! class_exists( 'TGM_Bulk_Installer_Skin' ) ) { + + /** + * Hack: Prevent TGMPA v2.4.1- bulk installer skin class from being loaded if 2.4.1- is loaded after 2.5+. + */ + class TGM_Bulk_Installer_Skin { + } +} + +/** + * The WP_Upgrader file isn't always available. If it isn't available, + * we load it here. + * + * We check to make sure no action or activation keys are set so that WordPress + * does not try to re-include the class when processing upgrades or installs outside + * of the class. + * + * @since 2.2.0 + */ +add_action( 'admin_init', 'tgmpa_load_bulk_installer' ); +if ( ! function_exists( 'tgmpa_load_bulk_installer' ) ) { + /** + * Load bulk installer + */ + function tgmpa_load_bulk_installer() { + // Silently fail if 2.5+ is loaded *after* an older version. + if ( ! isset( $GLOBALS['tgmpa'] ) ) { + return; + } + + // Get TGMPA class instance. + $tgmpa_instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) ); + + if ( isset( $_GET['page'] ) && $tgmpa_instance->menu === $_GET['page'] ) { + if ( ! class_exists( 'Plugin_Upgrader', false ) ) { + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; + } + + if ( ! class_exists( 'TGMPA_Bulk_Installer' ) ) { + + /** + * Installer class to handle bulk plugin installations. + * + * Extends WP_Upgrader and customizes to suit the installation of multiple + * plugins. + * + * @since 2.2.0 + * + * @internal Since 2.5.0 the class is an extension of Plugin_Upgrader rather than WP_Upgrader + * @internal Since 2.5.2 the class has been renamed from TGM_Bulk_Installer to TGMPA_Bulk_Installer. + * This was done to prevent backward compatibility issues with v2.3.6. + * + * @package TGM-Plugin-Activation + * @author Thomas Griffin + * @author Gary Jones + */ + class TGMPA_Bulk_Installer extends Plugin_Upgrader { + /** + * Holds result of bulk plugin installation. + * + * @since 2.2.0 + * + * @var string + */ + public $result; + + /** + * Flag to check if bulk installation is occurring or not. + * + * @since 2.2.0 + * + * @var boolean + */ + public $bulk = false; + + /** + * TGMPA instance + * + * @since 2.5.0 + * + * @var object + */ + protected $tgmpa; + + /** + * Whether or not the destination directory needs to be cleared ( = on update). + * + * @since 2.5.0 + * + * @var bool + */ + protected $clear_destination = false; + + /** + * References parent constructor and sets defaults for class. + * + * @since 2.2.0 + * + * @param \Bulk_Upgrader_Skin|null $skin Installer skin. + */ + public function __construct( $skin = null ) { + // Get TGMPA class instance. + $this->tgmpa = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) ); + + parent::__construct( $skin ); + + if ( isset( $this->skin->options['install_type'] ) && 'update' === $this->skin->options['install_type'] ) { + $this->clear_destination = true; + } + + if ( $this->tgmpa->is_automatic ) { + $this->activate_strings(); + } + + add_action( 'upgrader_process_complete', array( $this->tgmpa, 'populate_file_path' ) ); + } + + /** + * Sets the correct activation strings for the installer skin to use. + * + * @since 2.2.0 + */ + public function activate_strings() { + $this->strings['activation_failed'] = __( 'Plugin activation failed.', 'tgmpa' ); + $this->strings['activation_success'] = __( 'Plugin activated successfully.', 'tgmpa' ); + } + + /** + * Performs the actual installation of each plugin. + * + * @since 2.2.0 + * + * @see WP_Upgrader::run() + * + * @param array $options The installation config options. + * @return null|array Return early if error, array of installation data on success. + */ + public function run( $options ) { + $result = parent::run( $options ); + + // Reset the strings in case we changed one during automatic activation. + if ( $this->tgmpa->is_automatic ) { + if ( 'update' === $this->skin->options['install_type'] ) { + $this->upgrade_strings(); + } else { + $this->install_strings(); + } + } + + return $result; + } + + /** + * Processes the bulk installation of plugins. + * + * @since 2.2.0 + * + * @internal This is basically a near identical copy of the WP Core Plugin_Upgrader::bulk_upgrade() + * method, with minor adjustments to deal with new installs instead of upgrades. + * For ease of future synchronizations, the adjustments are clearly commented, but no other + * comments are added. Code style has been made to comply. + * + * @see Plugin_Upgrader::bulk_upgrade() + * @see https://core.trac.wordpress.org/browser/tags/4.2.1/src/wp-admin/includes/class-wp-upgrader.php#L838 + * + * @param array $plugins The plugin sources needed for installation. + * @param array $args Arbitrary passed extra arguments. + * @return string|bool Install confirmation messages on success, false on failure. + */ + public function bulk_install( $plugins, $args = array() ) { + // [TGMPA + ] Hook auto-activation in. + add_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); + + $defaults = array( + 'clear_update_cache' => true, + ); + $parsed_args = wp_parse_args( $args, $defaults ); + + $this->init(); + $this->bulk = true; + + $this->install_strings(); // [TGMPA + ] adjusted. + + /* [TGMPA - ] $current = get_site_transient( 'update_plugins' ); */ + + /* [TGMPA - ] add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4); */ + + $this->skin->header(); + + // Connect to the Filesystem first. + $res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) ); + if ( ! $res ) { + $this->skin->footer(); + + return false; + } + + $this->skin->bulk_header(); + + // Only start maintenance mode if: + // - running Multisite and there are one or more plugins specified, OR + // - a plugin with an update available is currently active. + // @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible. + $maintenance = ( is_multisite() && ! empty( $plugins ) ); + + /* + [TGMPA - ] + foreach ( $plugins as $plugin ) + $maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin] ) ); + */ + if ( $maintenance ) { + $this->maintenance_mode( true ); + } + + $results = array(); + + $this->update_count = count( $plugins ); + $this->update_current = 0; + foreach ( $plugins as $plugin ) { + $this->update_current++; + + /* + [TGMPA - ] + $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true); + + if ( !isset( $current->response[ $plugin ] ) ) { + $this->skin->set_result('up_to_date'); + $this->skin->before(); + $this->skin->feedback('up_to_date'); + $this->skin->after(); + $results[$plugin] = true; + continue; + } + + // Get the URL to the zip file + $r = $current->response[ $plugin ]; + + $this->skin->plugin_active = is_plugin_active($plugin); + */ + + $result = $this->run( array( + 'package' => $plugin, // [TGMPA + ] adjusted. + 'destination' => WP_PLUGIN_DIR, + 'clear_destination' => false, // [TGMPA + ] adjusted. + 'clear_working' => true, + 'is_multi' => true, + 'hook_extra' => array( + 'plugin' => $plugin, + ), + ) ); + + $results[ $plugin ] = $this->result; + + // Prevent credentials auth screen from displaying multiple times. + if ( false === $result ) { + break; + } + } //end foreach $plugins + + $this->maintenance_mode( false ); + + /** + * Fires when the bulk upgrader process is complete. + * + * @since WP 3.6.0 / TGMPA 2.5.0 + * + * @param Plugin_Upgrader $this Plugin_Upgrader instance. In other contexts, $this, might + * be a Theme_Upgrader or Core_Upgrade instance. + * @param array $data { + * Array of bulk item update data. + * + * @type string $action Type of action. Default 'update'. + * @type string $type Type of update process. Accepts 'plugin', 'theme', or 'core'. + * @type bool $bulk Whether the update process is a bulk update. Default true. + * @type array $packages Array of plugin, theme, or core packages to update. + * } + */ + do_action( 'upgrader_process_complete', $this, array( + 'action' => 'install', // [TGMPA + ] adjusted. + 'type' => 'plugin', + 'bulk' => true, + 'plugins' => $plugins, + ) ); + + $this->skin->bulk_footer(); + + $this->skin->footer(); + + // Cleanup our hooks, in case something else does a upgrade on this connection. + /* [TGMPA - ] remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin')); */ + + // [TGMPA + ] Remove our auto-activation hook. + remove_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); + + // Force refresh of plugin update information. + wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); + + return $results; + } + + /** + * Handle a bulk upgrade request. + * + * @since 2.5.0 + * + * @see Plugin_Upgrader::bulk_upgrade() + * + * @param array $plugins The local WP file_path's of the plugins which should be upgraded. + * @param array $args Arbitrary passed extra arguments. + * @return string|bool Install confirmation messages on success, false on failure. + */ + public function bulk_upgrade( $plugins, $args = array() ) { + + add_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); + + $result = parent::bulk_upgrade( $plugins, $args ); + + remove_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); + + return $result; + } + + /** + * Abuse a filter to auto-activate plugins after installation. + * + * Hooked into the 'upgrader_post_install' filter hook. + * + * @since 2.5.0 + * + * @param bool $bool The value we need to give back (true). + * @return bool + */ + public function auto_activate( $bool ) { + // Only process the activation of installed plugins if the automatic flag is set to true. + if ( $this->tgmpa->is_automatic ) { + // Flush plugins cache so the headers of the newly installed plugins will be read correctly. + wp_clean_plugins_cache(); + + // Get the installed plugin file. + $plugin_info = $this->plugin_info(); + + // Don't try to activate on upgrade of active plugin as WP will do this already. + if ( ! is_plugin_active( $plugin_info ) ) { + $activate = activate_plugin( $plugin_info ); + + // Adjust the success string based on the activation result. + $this->strings['process_success'] = $this->strings['process_success'] . "
\n"; + + if ( is_wp_error( $activate ) ) { + $this->skin->error( $activate ); + $this->strings['process_success'] .= $this->strings['activation_failed']; + } else { + $this->strings['process_success'] .= $this->strings['activation_success']; + } + } + } + + return $bool; + } + } + } + + if ( ! class_exists( 'TGMPA_Bulk_Installer_Skin' ) ) { + + /** + * Installer skin to set strings for the bulk plugin installations.. + * + * Extends Bulk_Upgrader_Skin and customizes to suit the installation of multiple + * plugins. + * + * @since 2.2.0 + * + * @internal Since 2.5.2 the class has been renamed from TGM_Bulk_Installer_Skin to + * TGMPA_Bulk_Installer_Skin. + * This was done to prevent backward compatibility issues with v2.3.6. + * + * @see https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/class-wp-upgrader-skins.php + * + * @package TGM-Plugin-Activation + * @author Thomas Griffin + * @author Gary Jones + */ + class TGMPA_Bulk_Installer_Skin extends Bulk_Upgrader_Skin { + /** + * Holds plugin info for each individual plugin installation. + * + * @since 2.2.0 + * + * @var array + */ + public $plugin_info = array(); + + /** + * Holds names of plugins that are undergoing bulk installations. + * + * @since 2.2.0 + * + * @var array + */ + public $plugin_names = array(); + + /** + * Integer to use for iteration through each plugin installation. + * + * @since 2.2.0 + * + * @var integer + */ + public $i = 0; + + /** + * TGMPA instance + * + * @since 2.5.0 + * + * @var object + */ + protected $tgmpa; + + /** + * Constructor. Parses default args with new ones and extracts them for use. + * + * @since 2.2.0 + * + * @param array $args Arguments to pass for use within the class. + */ + public function __construct( $args = array() ) { + // Get TGMPA class instance. + $this->tgmpa = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) ); + + // Parse default and new args. + $defaults = array( + 'url' => '', + 'nonce' => '', + 'names' => array(), + 'install_type' => 'install', + ); + $args = wp_parse_args( $args, $defaults ); + + // Set plugin names to $this->plugin_names property. + $this->plugin_names = $args['names']; + + // Extract the new args. + parent::__construct( $args ); + } + + /** + * Sets install skin strings for each individual plugin. + * + * Checks to see if the automatic activation flag is set and uses the + * the proper strings accordingly. + * + * @since 2.2.0 + */ + public function add_strings() { + if ( 'update' === $this->options['install_type'] ) { + parent::add_strings(); + $this->upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)', 'tgmpa' ); + } else { + $this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while installing %1$s: %2$s.', 'tgmpa' ); + $this->upgrader->strings['skin_update_failed'] = __( 'The installation of %1$s failed.', 'tgmpa' ); + + if ( $this->tgmpa->is_automatic ) { + // Automatic activation strings. + $this->upgrader->strings['skin_upgrade_start'] = __( 'The installation and activation process is starting. This process may take a while on some hosts, so please be patient.', 'tgmpa' ); + $this->upgrader->strings['skin_update_successful'] = __( '%1$s installed and activated successfully.', 'tgmpa' ) . ' ' . esc_html__( 'Show Details', 'tgmpa' ) . '.'; + $this->upgrader->strings['skin_upgrade_end'] = __( 'All installations and activations have been completed.', 'tgmpa' ); + $this->upgrader->strings['skin_before_update_header'] = __( 'Installing and Activating Plugin %1$s (%2$d/%3$d)', 'tgmpa' ); + } else { + // Default installation strings. + $this->upgrader->strings['skin_upgrade_start'] = __( 'The installation process is starting. This process may take a while on some hosts, so please be patient.', 'tgmpa' ); + $this->upgrader->strings['skin_update_successful'] = esc_html__( '%1$s installed successfully.', 'tgmpa' ) . ' ' . esc_html__( 'Show Details', 'tgmpa' ) . '.'; + $this->upgrader->strings['skin_upgrade_end'] = __( 'All installations have been completed.', 'tgmpa' ); + $this->upgrader->strings['skin_before_update_header'] = __( 'Installing Plugin %1$s (%2$d/%3$d)', 'tgmpa' ); + } + } + } + + /** + * Outputs the header strings and necessary JS before each plugin installation. + * + * @since 2.2.0 + * + * @param string $title Unused in this implementation. + */ + public function before( $title = '' ) { + if ( empty( $title ) ) { + $title = esc_html( $this->plugin_names[ $this->i ] ); + } + parent::before( $title ); + } + + /** + * Outputs the footer strings and necessary JS after each plugin installation. + * + * Checks for any errors and outputs them if they exist, else output + * success strings. + * + * @since 2.2.0 + * + * @param string $title Unused in this implementation. + */ + public function after( $title = '' ) { + if ( empty( $title ) ) { + $title = esc_html( $this->plugin_names[ $this->i ] ); + } + parent::after( $title ); + + $this->i++; + } + + /** + * Outputs links after bulk plugin installation is complete. + * + * @since 2.2.0 + */ + public function bulk_footer() { + // Serve up the string to say installations (and possibly activations) are complete. + parent::bulk_footer(); + + // Flush plugins cache so we can make sure that the installed plugins list is always up to date. + wp_clean_plugins_cache(); + + $this->tgmpa->show_tgmpa_version(); + + // Display message based on if all plugins are now active or not. + $update_actions = array(); + + if ( $this->tgmpa->is_tgmpa_complete() ) { + // All plugins are active, so we display the complete string and hide the menu to protect users. + echo ''; + $update_actions['dashboard'] = sprintf( + esc_html( $this->tgmpa->strings['complete'] ), + '' . esc_html__( 'Return to the Dashboard', 'tgmpa' ) . '' + ); + } else { + $update_actions['tgmpa_page'] = '' . esc_html( $this->tgmpa->strings['return'] ) . ''; + } + + /** + * Filter the list of action links available following bulk plugin installs/updates. + * + * @since 2.5.0 + * + * @param array $update_actions Array of plugin action links. + * @param array $plugin_info Array of information for the last-handled plugin. + */ + $update_actions = apply_filters( 'tgmpa_update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info ); + + if ( ! empty( $update_actions ) ) { + $this->feedback( implode( ' | ', (array) $update_actions ) ); + } + } + + /* *********** DEPRECATED METHODS *********** */ + + /** + * Flush header output buffer. + * + * @since 2.2.0 + * @deprecated 2.5.0 use {@see Bulk_Upgrader_Skin::flush_output()} instead + * @see Bulk_Upgrader_Skin::flush_output() + */ + public function before_flush_output() { + _deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' ); + $this->flush_output(); + } + + /** + * Flush footer output buffer and iterate $this->i to make sure the + * installation strings reference the correct plugin. + * + * @since 2.2.0 + * @deprecated 2.5.0 use {@see Bulk_Upgrader_Skin::flush_output()} instead + * @see Bulk_Upgrader_Skin::flush_output() + */ + public function after_flush_output() { + _deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' ); + $this->flush_output(); + $this->i++; + } + } + } + } + } +} + +if ( ! class_exists( 'TGMPA_Utils' ) ) { + + /** + * Generic utilities for TGMPA. + * + * All methods are static, poor-dev name-spacing class wrapper. + * + * Class was called TGM_Utils in 2.5.0 but renamed TGMPA_Utils in 2.5.1 as this was conflicting with Soliloquy. + * + * @since 2.5.0 + * + * @package TGM-Plugin-Activation + * @author Juliette Reinders Folmer + */ + class TGMPA_Utils { + /** + * Whether the PHP filter extension is enabled. + * + * @see http://php.net/book.filter + * + * @since 2.5.0 + * + * @static + * + * @var bool $has_filters True is the extension is enabled. + */ + public static $has_filters; + + /** + * Wrap an arbitrary string in tags. Meant to be used in combination with array_map(). + * + * @since 2.5.0 + * + * @static + * + * @param string $string Text to be wrapped. + * @return string + */ + public static function wrap_in_em( $string ) { + return '' . wp_kses_post( $string ) . ''; + } + + /** + * Wrap an arbitrary string in tags. Meant to be used in combination with array_map(). + * + * @since 2.5.0 + * + * @static + * + * @param string $string Text to be wrapped. + * @return string + */ + public static function wrap_in_strong( $string ) { + return '' . wp_kses_post( $string ) . ''; + } + + /** + * Helper function: Validate a value as boolean + * + * @since 2.5.0 + * + * @static + * + * @param mixed $value Arbitrary value. + * @return bool + */ + public static function validate_bool( $value ) { + if ( ! isset( self::$has_filters ) ) { + self::$has_filters = extension_loaded( 'filter' ); + } + + if ( self::$has_filters ) { + return filter_var( $value, FILTER_VALIDATE_BOOLEAN ); + } else { + return self::emulate_filter_bool( $value ); + } + } + + /** + * Helper function: Cast a value to bool + * + * @since 2.5.0 + * + * @static + * + * @param mixed $value Value to cast. + * @return bool + */ + protected static function emulate_filter_bool( $value ) { + // @codingStandardsIgnoreStart + static $true = array( + '1', + 'true', 'True', 'TRUE', + 'y', 'Y', + 'yes', 'Yes', 'YES', + 'on', 'On', 'ON', + ); + static $false = array( + '0', + 'false', 'False', 'FALSE', + 'n', 'N', + 'no', 'No', 'NO', + 'off', 'Off', 'OFF', + ); + // @codingStandardsIgnoreEnd + + if ( is_bool( $value ) ) { + return $value; + } else if ( is_int( $value ) && ( 0 === $value || 1 === $value ) ) { + return (bool) $value; + } else if ( ( is_float( $value ) && ! is_nan( $value ) ) && ( (float) 0 === $value || (float) 1 === $value ) ) { + return (bool) $value; + } else if ( is_string( $value ) ) { + $value = trim( $value ); + if ( in_array( $value, $true, true ) ) { + return true; + } else if ( in_array( $value, $false, true ) ) { + return false; + } else { + return false; + } + } + + return false; + } + } // End of class TGMPA_Utils +} // End of class_exists wrapper diff --git a/includes/oembed-in-comments.php b/includes/oembed-in-comments.php new file mode 100644 index 0000000..6bdc9e4 --- /dev/null +++ b/includes/oembed-in-comments.php @@ -0,0 +1,52 @@ +add_filter(); + } + + /** + * Setup filter with correct priority to do oEmbed in comments + */ + function add_filter() { + // make_clickable breaks oEmbed regex, make sure we go earlier + $clickable = has_filter( 'get_comment_text', 'make_clickable' ); + $priority = ( $clickable ) ? $clickable - 1 : 10; + + add_filter( 'get_comment_text', array( $this, 'oembed_filter' ), $priority ); + } + + /** + * Safely add oEmbed media to a comment + */ + function oembed_filter( $comment_text ) { + global $wp_embed; + + // Automatic discovery would be a security risk, safety first + add_filter( 'embed_oembed_discover', '__return_false', 999 ); + $comment_text = $wp_embed->autoembed( $comment_text ); + + // ...but don't break your posts if you use it + remove_filter( 'embed_oembed_discover', '__return_false', 999 ); + + return $comment_text; + } +} + +new ES_oEmbed_Comments; diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Categoria2/ET_Builder_Module_Delibera_Categoria2.php b/includes/wp-divi/ET_Builder_Module_Delibera_Categoria2/ET_Builder_Module_Delibera_Categoria2.php new file mode 100644 index 0000000..83b30fe --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Categoria2/ET_Builder_Module_Delibera_Categoria2.php @@ -0,0 +1,358 @@ +name = esc_html__( 'Delibera categoria2', 'et_builder' ); + $this->slug = 'et_pb_delibera_categoria2'; + + $this->whitelisted_fields = array( + 'name', + 'position', + 'image_url', + 'animation', + 'background_layout', + 'content_new', + 'admin_label', + 'module_id', + 'module_class', + 'icon_color', + 'icon_hover_color', + 'include_categories', + 'texto', + 'url_tema', + 'background_color', + 'button_image_url', + 'orderby', + 'order', + 'num_posts', + 'border', + 'shadow' + ); + + $this->fields_defaults = array( + 'animation' => array( 'off' ), + 'background_layout' => array( 'light' ), + 'background_color' => array( '#ffffff' ), + 'button_image_url' => array( '' ), + 'orderby' => array( 'date' ), + 'order' => array( 'DESC' ), + 'num_posts' => array( '12' ) + ); + + $this->main_css_element = '%%order_class%%.et_pb_delibera_categoria'; + $this->advanced_options = array( + 'fonts' => array( + 'header' => array( + 'label' => esc_html__( 'Header', 'et_builder' ), + 'css' => array( + 'main' => "{$this->main_css_element} h4", + ), + ), + 'body' => array( + 'label' => esc_html__( 'Body', 'et_builder' ), + 'css' => array( + 'main' => "{$this->main_css_element} *", + ), + ), + ), + 'border' => array(), + 'custom_margin_padding' => array( + 'css' => array( + 'important' => 'all', + ), + ), + ); + $this->custom_css_options = array( + 'member_image' => array( + 'label' => esc_html__( 'Member Image', 'et_builder' ), + 'selector' => '.et_pb_delibera_member_image', + ), + 'member_description' => array( + 'label' => esc_html__( 'Member Description', 'et_builder' ), + 'selector' => '.et_pb_delibera_member_description', + ), + 'title' => array( + 'label' => esc_html__( 'Title', 'et_builder' ), + 'selector' => '.et_pb_delibera_member_description h4', + ), + 'member_position' => array( + 'label' => esc_html__( 'Member Position', 'et_builder' ), + 'selector' => '.et_pb_member_position', + ), + 'member_social_links' => array( + 'label' => esc_html__( 'Member Social Links', 'et_builder' ), + 'selector' => '.et_pb_member_social_links', + ), + ); + add_action('wp_enqueue_scripts', array($this, 'cssFiles'), 1000); + } + + function cssFiles() + { + wp_enqueue_style('ET_Builder_Module_Delibera_Categoria2', plugins_url("frontend/css", __FILE__)."/ET_Builder_Module_Delibera_Categoria2.css"); + } + + function get_fields() { + $fields = array( + 'include_categories' => array( + 'label' => esc_html__( 'Incluir Temas', 'et_builder' ), + 'renderer' => 'et_builder_include_categories_delibera_option', + 'option_category' => 'basic_option', + 'renderer_options' => array( + 'use_terms' => true, + 'term_name' => 'tema', + 'post_type'=>'pauta' + ), + 'description' => esc_html__( 'Escolha qual o Tema você quer incluir na grade de pautas', 'et_builder' ), + ), + 'border' => array( + 'label' => esc_html__( 'Borda Arredondada', 'et_builder' ), + 'type' => 'yes_no_button', + 'option_category' => 'configuration', + 'options' => array( + 'on' => esc_html__( 'Yes', 'et_builder' ), + 'off' => esc_html__( 'No', 'et_builder' ), + ), + 'description' => esc_html__( 'Habilite ou desabilite as bordas arredondas.', 'et_builder' ), + ), + 'shadow' => array( + 'label' => esc_html__( 'Sombra', 'et_builder' ), + 'type' => 'yes_no_button', + 'option_category' => 'configuration', + 'options' => array( + 'on' => esc_html__( 'Yes', 'et_builder' ), + 'off' => esc_html__( 'No', 'et_builder' ), + ), + 'description' => esc_html__( 'Habilite ou desabilite a sombra nos cards.', 'et_builder' ), + ), + 'name' => array( + 'label' => esc_html__( 'Title', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'basic_option', + 'description' => 'Insira um título', + ), + 'url_tema' => array( + 'label' => esc_html__( 'Texto', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'basic_option', + 'description' => 'Se preenchida sobreescreve a url do tema', + ), + 'position' => array( + 'label' => esc_html__( 'Subtitle', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'basic_option', + 'description' =>'insira um subtitulo', + ), + 'image_url' => array( + 'label' => esc_html__( 'Image URL', 'et_builder' ), + 'type' => 'upload', + 'option_category' => 'basic_option', + 'upload_button_text' => esc_attr__( 'Upload an image', 'et_builder' ), + 'choose_text' => esc_attr__( 'Choose an Image', 'et_builder' ), + 'update_text' => esc_attr__( 'Set As Image', 'et_builder' ), + 'description' => esc_html__( 'Upload your desired image, or type in the URL to the image you would like to display.', 'et_builder' ), + ), + 'animation' => array( + 'label' => esc_html__( 'Animation', 'et_builder' ), + 'type' => 'select', + 'option_category' => 'configuration', + 'options' => array( + 'off' => esc_html__( 'No Animation', 'et_builder' ), + 'fade_in' => esc_html__( 'Fade In', 'et_builder' ), + 'left' => esc_html__( 'Left To Right', 'et_builder' ), + 'right' => esc_html__( 'Right To Left', 'et_builder' ), + 'top' => esc_html__( 'Top To Bottom', 'et_builder' ), + 'bottom' => esc_html__( 'Bottom To Top', 'et_builder' ), + ), + 'description' => esc_html__( 'This controls the direction of the lazy-loading animation.', 'et_builder' ), + ), + 'background_layout' => array( + 'label' => esc_html__( 'Text Color', 'et_builder' ), + 'type' => 'select', + 'option_category' => 'color_option', + 'options' => array( + 'light' => esc_html__( 'Dark', 'et_builder' ), + 'dark' => esc_html__( 'Light', 'et_builder' ), + ), + 'description' => esc_html__( 'Here you can choose the value of your text. If you are working with a dark background, then your text should be set to light. If you are working with a light background, then your text should be dark.', 'et_builder' ), + ), + 'content_new' => array( + 'label' => esc_html__( 'Description', 'et_builder' ), + 'type' => 'tiny_mce', + 'option_category' => 'basic_option', + 'description' => esc_html__( 'Input the main text content for your module here.', 'et_builder' ), + ), + 'icon_color' => array( + 'label' => esc_html__( 'Icon Color', 'et_builder' ), + 'type' => 'color', + 'custom_color' => true, + 'tab_slug' => 'advanced', + ), + 'icon_hover_color' => array( + 'label' => esc_html__( 'Icon Hover Color', 'et_builder' ), + 'type' => 'color', + 'custom_color' => true, + 'tab_slug' => 'advanced', + ), + 'disabled_on' => array( + 'label' => esc_html__( 'Disable on', 'et_builder' ), + 'type' => 'multiple_checkboxes', + 'options' => array( + 'phone' => esc_html__( 'Phone', 'et_builder' ), + 'tablet' => esc_html__( 'Tablet', 'et_builder' ), + 'desktop' => esc_html__( 'Desktop', 'et_builder' ), + ), + 'additional_att' => 'disable_on', + 'option_category' => 'configuration', + 'description' => esc_html__( 'This will disable the module on selected devices', 'et_builder' ), + ), + 'admin_label' => array( + 'label' => esc_html__( 'Admin Label', 'et_builder' ), + 'type' => 'text', + 'description' => esc_html__( 'This will change the label of the module in the builder for easy identification.', 'et_builder' ), + ), + 'module_id' => array( + 'label' => esc_html__( 'CSS ID', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'configuration', + 'tab_slug' => 'custom_css', + 'option_class' => 'et_pb_custom_css_regular', + ), + 'module_class' => array( + 'label' => esc_html__( 'CSS Class', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'configuration', + 'tab_slug' => 'custom_css', + 'option_class' => 'et_pb_custom_css_regular', + ), + 'background_color' => array( + 'label' => esc_html__( 'Background Color', 'et_builder' ), + 'type' => 'color-alpha', + 'description' => esc_html__( 'Use the color picker to choose a background color for this module.', 'et_builder' ), + ), + 'button_image_url' => array( + 'label' => esc_html__( 'Button Image URL', 'et_builder' ), + 'type' => 'upload', + 'option_category' => 'basic_option', + 'upload_button_text' => esc_attr__( 'Upload an image', 'et_builder' ), + 'choose_text' => esc_attr__( 'Choose an Image', 'et_builder' ), + 'update_text' => esc_attr__( 'Set As Image', 'et_builder' ), + 'description' => esc_html__( 'Upload your desired image, or type in the URL to the image you would like to display as link button.', 'et_builder' ), + ), + 'url_tema' => array( + 'label' => esc_html__( 'URL Tema', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'basic_option', + 'description' => 'Se preenchida sobreescreve a url do tema', + ), + 'orderby' => array( + 'label' => esc_html__( 'Ordenar por', 'et_builder' ), + 'type' => 'select', + 'option_category' => 'basic_option', + 'options' => array( + 'date' => esc_html__( 'Cronológico, última ou primeira criada', 'et_builder' ), + 'rand' => esc_html__( 'Randômicas', 'et_builder' ), + ), + 'description' => esc_html__( 'Ordem de onde pegar as pautas', 'et_builder' ), + ), + 'order' => array( + 'label' => esc_html__( 'Ordem', 'et_builder' ), + 'type' => 'select', + 'option_category' => 'basic_option', + 'options' => array( + 'DESC' => esc_html__( 'Descendete', 'et_builder' ), + 'ASC' => esc_html__( 'Acendente', 'et_builder' ), + ), + 'description' => esc_html__( 'Ordem', 'et_builder' ), + ), + 'num_posts' => array( + 'label' => esc_html__( 'Número de Pautas', 'et_builder' ), + 'description' => esc_html__( 'Número máximo de pautas que devem ser exibidas', 'et_builder' ), + 'type' => 'range', + 'default' => 12, + 'range_settings' => array( + 'min' => '1', + 'max' => '120', + 'step' => '1', + ), + ), + ); + return $fields; + } + + function shortcode_callback( $atts, $content = null, $function_name ) { + $module_id = $this->shortcode_atts['module_id']; + $module_class = $this->shortcode_atts['module_class']; + $name = $this->shortcode_atts['name']; + $position = $this->shortcode_atts['position']; + $image_url = $this->shortcode_atts['image_url']; + $animation = $this->shortcode_atts['animation']; + $background_layout = $this->shortcode_atts['background_layout']; + $icon_color = $this->shortcode_atts['icon_color']; + $icon_hover_color = $this->shortcode_atts['icon_hover_color']; + $include_categories = $this->shortcode_atts['include_categories']; + $texto = $this->shortcode_atts['texto']; + $background_color = $this->shortcode_atts['background_color']; + $url_tema = $this->shortcode_atts['url_tema']; + $button_image_url = $this->shortcode_atts['button_image_url']; + $orderby = $this->shortcode_atts['orderby']; + $order = $this->shortcode_atts['order']; + $num_posts = $this->shortcode_atts['num_posts']; + $border = $this->shortcode_atts['border']; + $shadow = $this->shortcode_atts['shadow']; + + $module_class = ET_Builder_Element::add_module_order_class( $module_class, $function_name ); + + $image = $social_links = ''; + + $args = array( + 'post_type' => 'pauta', + 'orderby' => $orderby, + 'order' => $order, + 'post_status' => 'publish', + 'posts_per_page' => $num_posts + ); + + if($include_categories) + { + $args['tax_query'] = array( + array( + 'taxonomy' => 'tema', + 'field' => 'tag_id', + 'terms' => $include_categories, + 'include_children' => false + ) + ); + } + + $wp_posts = get_posts($args); + + $output = ""; + + $auxClose = ''; + + $i = 0; + + $ignore_keys = array('orderby', 'order', 'pauta_id'); + + foreach($wp_posts as $key=>$value) + { + + $output .= '[et_pb_delibera_pauta22v orderby="pauta" pauta_id="'.$wp_posts[$key]->ID.'" '; + foreach ($this->shortcode_atts as $key => $value) + { + if(!empty($value) && !in_array($key, $ignore_keys)) + { + $output .= $key.'="'.$value.'" '; + } + } + $output .= '][/et_pb_delibera_pauta22v]'; + } + $output = do_shortcode($output); + + $output = '
'.$output.'
'; + + return $output; + } +} +new ET_Builder_Module_Delibera_Categoria2; diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Categoria2/frontend/css/ET_Builder_Module_Delibera_Categoria2.css b/includes/wp-divi/ET_Builder_Module_Delibera_Categoria2/frontend/css/ET_Builder_Module_Delibera_Categoria2.css new file mode 100644 index 0000000..807bd5a --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Categoria2/frontend/css/ET_Builder_Module_Delibera_Categoria2.css @@ -0,0 +1,97 @@ +@media all and (min-width: 981px) { + .et_pb_column_1_2 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_1_2 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 48%; + } + + .et_pb_column_4_4 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_4_4 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 24.5%; + } + .et_pb_column_1_3 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_1_3 .et_pb_delibera_categoria .et_pb_delibera_member_border { + width: 100%; + } + .et_pb_column_1_4 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_1_4 .et_pb_delibera_categoria .et_pb_delibera_member_border { + width: 100%; + } + .et_pb_column_2_3 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_2_3 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 48%; + } + .et_pb_column_3_4 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_3_4 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 48%; + } +} +@media all and (min-width: 768px) and (max-width: 980px) { + .et_pb_column_1_2 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_1_2 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 32%; + } + + .et_pb_column_4_4 .et_pb_delibera_categoria .et_pb_delibera_member + .et_pb_column_4_4 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 32%; + } + .et_pb_column_1_3 .et_pb_delibera_categoria .et_pb_delibera_member + .et_pb_column_1_3 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 32%; + } + .et_pb_column_1_4 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_1_4 .et_pb_delibera_categoria .et_pb_delibera_member_border { + width: 100%; + } + .et_pb_column_2_3 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_2_3 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 32%; + } + .et_pb_column_3_4 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_3_4 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 32%; + } +} +@media all and (max-width: 767px) { + .et_pb_column_1_2 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_1_2 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 48%; + } + + .et_pb_column_4_4 .et_pb_delibera_categoria .et_pb_delibera_member + .et_pb_column_4_4 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 48%; + } + .et_pb_column_1_3 .et_pb_delibera_categoria .et_pb_delibera_member + .et_pb_column_1_3 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 48%; + } + .et_pb_column_1_4 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_1_4 .et_pb_delibera_categoria .et_pb_delibera_member_border { + width: 100%; + } + .et_pb_column_2_3 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_2_3 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 48%; + } + .et_pb_column_3_4 .et_pb_delibera_categoria .et_pb_delibera_member, + .et_pb_column_3_4 .et_pb_delibera_categoria .et_pb_delibera_member_border { + margin-right: 5px; + width: 48%; + } +} +@media all and (max-width: 479px) { +} \ No newline at end of file diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/.name b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/.name new file mode 100644 index 0000000..a939c0a --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/.name @@ -0,0 +1 @@ +ET_Builder_Module_Delibera_Member \ No newline at end of file diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/ET_Builder_Module_Delibera_Member.iml b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/ET_Builder_Module_Delibera_Member.iml new file mode 100644 index 0000000..6b8184f --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/ET_Builder_Module_Delibera_Member.iml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/encodings.xml b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/misc.xml b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/misc.xml new file mode 100644 index 0000000..b63c394 --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/misc.xml @@ -0,0 +1,22 @@ + + + + + + + diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/modules.xml b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/modules.xml new file mode 100644 index 0000000..102c098 --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/scopes/scope_settings.xml b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/vcs.xml b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/workspace.xml b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/workspace.xml new file mode 100644 index 0000000..04a4e4e --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Member/.idea/workspace.xml @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1464025142522 + 1464025142522 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Member/ET_Builder_Module_Delibera_Member.php b/includes/wp-divi/ET_Builder_Module_Delibera_Member/ET_Builder_Module_Delibera_Member.php new file mode 100644 index 0000000..2b363e3 --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Member/ET_Builder_Module_Delibera_Member.php @@ -0,0 +1,539 @@ +name = esc_html__( 'Delibera', 'et_builder' ); + $this->slug = 'et_pb_delibera_pauta22v'; + + $this->whitelisted_fields = array( + 'name', + 'position', + 'image_url', + 'animation', + 'background_layout', + 'content_new', + 'admin_label', + 'module_id', + 'module_class', + 'icon_color', + 'icon_hover_color', + 'include_categories', + 'url_tema', + 'background_color', + 'button_image_url', + 'orderby', + 'order', + 'pauta_id', + 'border', + 'shadow' + ); + + $this->fields_defaults = array( + 'animation' => array( 'off' ), + 'background_layout' => array( 'light' ), + 'background_color' => array( '#ffffff' ), + 'button_image_url' => array( '' ), + 'orderby' => array( 'date' ), + 'order' => array( 'DESC' ), + 'pauta_id' => array( false ) + ); + + $this->main_css_element = '%%order_class%%.et_pb_delibera_member'; + $this->advanced_options = array( + 'fonts' => array( + 'header' => array( + 'label' => esc_html__( 'Header', 'et_builder' ), + 'css' => array( + 'main' => "{$this->main_css_element} h4", + ), + ), + 'body' => array( + 'label' => esc_html__( 'Body', 'et_builder' ), + 'css' => array( + 'main' => "{$this->main_css_element} *", + ), + ), + ), + 'border' => array(), + 'custom_margin_padding' => array( + 'css' => array( + 'important' => 'all', + ), + ), + ); + $this->custom_css_options = array( + 'member_image' => array( + 'label' => esc_html__( 'Member Image', 'et_builder' ), + 'selector' => '.et_pb_delibera_member_image', + ), + 'member_description' => array( + 'label' => esc_html__( 'Member Description', 'et_builder' ), + 'selector' => '.et_pb_delibera_member_description', + ), + 'title' => array( + 'label' => esc_html__( 'Title', 'et_builder' ), + 'selector' => '.et_pb_delibera_member_description h4', + ), + 'member_position' => array( + 'label' => esc_html__( 'Member Position', 'et_builder' ), + 'selector' => '.et_pb_member_position', + ), + 'member_social_links' => array( + 'label' => esc_html__( 'Member Social Links', 'et_builder' ), + 'selector' => '.et_pb_member_social_links', + ), + ); + + add_action('wp_enqueue_scripts', array($this, 'cssFiles'), 1000); + add_action('wp_enqueue_scripts', array($this, 'javascriptFiles'), 1000); + } + + function get_fields() { + $fields = array( + 'include_categories' => array( + 'label' => esc_html__( 'Include Categories', 'et_builder' ), + 'renderer' => 'et_builder_include_categories_delibera_option', + 'option_category' => 'basic_option', + 'renderer_options' => array( + 'use_terms' => true, + 'term_name' => 'tema', + 'post_type'=>'pauta' + ), + 'description' => esc_html__( 'Choose which categories you would like to include in the feed.', 'et_builder' ), + ), + 'border' => array( + 'label' => esc_html__( 'Borda Arredondada', 'et_builder' ), + 'type' => 'yes_no_button', + 'option_category' => 'configuration', + 'options' => array( + 'on' => esc_html__( 'Yes', 'et_builder' ), + 'off' => esc_html__( 'No', 'et_builder' ), + ), + 'description' => esc_html__( 'Habilite ou desabilite as bordas arredondas nos cards.', 'et_builder' ), + ), + 'shadow' => array( + 'label' => esc_html__( 'Sombra', 'et_builder' ), + 'type' => 'yes_no_button', + 'option_category' => 'configuration', + 'options' => array( + 'on' => esc_html__( 'Yes', 'et_builder' ), + 'off' => esc_html__( 'No', 'et_builder' ), + ), + 'description' => esc_html__( 'Habilite ou desabilite a sombra nos cards.', 'et_builder' ), + ), + 'name' => array( + 'label' => esc_html__( 'Title', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'basic_option', + 'description' => 'Insira um título', + ), + 'url_tema' => array( + 'label' => esc_html__( 'URL Tema', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'basic_option', + 'description' => 'Se preenchida sobreescreve a url do tema', + ), + 'position' => array( + 'label' => esc_html__( 'Subtitle', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'basic_option', + 'description' =>'insira um subtitulo', + ), + 'image_url' => array( + 'label' => esc_html__( 'Image URL', 'et_builder' ), + 'type' => 'upload', + 'option_category' => 'basic_option', + 'upload_button_text' => esc_attr__( 'Upload an image', 'et_builder' ), + 'choose_text' => esc_attr__( 'Choose an Image', 'et_builder' ), + 'update_text' => esc_attr__( 'Set As Image', 'et_builder' ), + 'description' => esc_html__( 'Upload your desired image, or type in the URL to the image you would like to display.', 'et_builder' ), + ), + 'animation' => array( + 'label' => esc_html__( 'Animation', 'et_builder' ), + 'type' => 'select', + 'option_category' => 'configuration', + 'options' => array( + 'off' => esc_html__( 'No Animation', 'et_builder' ), + 'fade_in' => esc_html__( 'Fade In', 'et_builder' ), + 'left' => esc_html__( 'Left To Right', 'et_builder' ), + 'right' => esc_html__( 'Right To Left', 'et_builder' ), + 'top' => esc_html__( 'Top To Bottom', 'et_builder' ), + 'bottom' => esc_html__( 'Bottom To Top', 'et_builder' ), + ), + 'description' => esc_html__( 'This controls the direction of the lazy-loading animation.', 'et_builder' ), + ), + 'background_layout' => array( + 'label' => esc_html__( 'Text Color', 'et_builder' ), + 'type' => 'select', + 'option_category' => 'color_option', + 'options' => array( + 'light' => esc_html__( 'Dark', 'et_builder' ), + 'dark' => esc_html__( 'Light', 'et_builder' ), + ), + 'description' => esc_html__( 'Here you can choose the value of your text. If you are working with a dark background, then your text should be set to light. If you are working with a light background, then your text should be dark.', 'et_builder' ), + ), + 'background_color' => array( + 'label' => esc_html__( 'Background Color', 'et_builder' ), + 'type' => 'color-alpha', + 'description' => esc_html__( 'Use the color picker to choose a background color for this module.', 'et_builder' ), + ), + 'content_new' => array( + 'label' => esc_html__( 'Description', 'et_builder' ), + 'type' => 'tiny_mce', + 'option_category' => 'basic_option', + 'description' => esc_html__( 'Input the main text content for your module here.', 'et_builder' ), + ), + 'icon_color' => array( + 'label' => esc_html__( 'Icon Color', 'et_builder' ), + 'type' => 'color', + 'custom_color' => true, + 'tab_slug' => 'advanced', + ), + 'icon_hover_color' => array( + 'label' => esc_html__( 'Icon Hover Color', 'et_builder' ), + 'type' => 'color', + 'custom_color' => true, + 'tab_slug' => 'advanced', + ), + 'disabled_on' => array( + 'label' => esc_html__( 'Disable on', 'et_builder' ), + 'type' => 'multiple_checkboxes', + 'options' => array( + 'phone' => esc_html__( 'Phone', 'et_builder' ), + 'tablet' => esc_html__( 'Tablet', 'et_builder' ), + 'desktop' => esc_html__( 'Desktop', 'et_builder' ), + ), + 'additional_att' => 'disable_on', + 'option_category' => 'configuration', + 'description' => esc_html__( 'This will disable the module on selected devices', 'et_builder' ), + ), + 'admin_label' => array( + 'label' => esc_html__( 'Admin Label', 'et_builder' ), + 'type' => 'text', + 'description' => esc_html__( 'This will change the label of the module in the builder for easy identification.', 'et_builder' ), + ), + 'module_id' => array( + 'label' => esc_html__( 'CSS ID', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'configuration', + 'tab_slug' => 'custom_css', + 'option_class' => 'et_pb_custom_css_regular', + ), + 'module_class' => array( + 'label' => esc_html__( 'CSS Class', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'configuration', + 'tab_slug' => 'custom_css', + 'option_class' => 'et_pb_custom_css_regular', + ), + 'button_image_url' => array( + 'label' => esc_html__( 'Button Image URL', 'et_builder' ), + 'type' => 'upload', + 'option_category' => 'basic_option', + 'upload_button_text' => esc_attr__( 'Upload an image', 'et_builder' ), + 'choose_text' => esc_attr__( 'Choose an Image', 'et_builder' ), + 'update_text' => esc_attr__( 'Set As Image', 'et_builder' ), + 'description' => esc_html__( 'Upload your desired image, or type in the URL to the image you would like to display as link button.', 'et_builder' ), + ), + 'orderby' => array( + 'label' => esc_html__( 'Ordenar por', 'et_builder' ), + 'type' => 'select', + 'option_category' => 'basic_option', + 'options' => array( + 'date' => esc_html__( 'Cronológico, última ou primeira criada', 'et_builder' ), + 'rand' => esc_html__( 'Randômico', 'et_builder' ), + 'pauta' => esc_html__( 'Pauta Selecionada', 'et_builder' ), + ), + 'description' => esc_html__( 'Ordem de onde pegar a pauta', 'et_builder' ), + ), + 'order' => array( + 'label' => esc_html__( 'Ordem', 'et_builder' ), + 'type' => 'select', + 'option_category' => 'basic_option', + 'options' => array( + 'DESC' => esc_html__( 'Descendete', 'et_builder' ), + 'ASC' => esc_html__( 'Acendente', 'et_builder' ), + ), + 'description' => esc_html__( 'Ordem', 'et_builder' ), + ), + 'pauta_id' => array( + 'label' => esc_html__( 'Selecionar uma pauta', 'et_builder' ), + 'type' => 'select', + 'option_category' => 'basic_option', + 'renderer_options' => array( + 'post_type' => 'pauta' + ), + 'options' => $this->get_pautas(), + 'description' => esc_html__( 'Escolha qual pauta deve mostrar na caixa.', 'et_builder' ), + ), + ); + return $fields; + } + + function cssFiles() + { + if (!is_pauta()) + { + if(file_exists(get_stylesheet_directory()."/delibera_style.css")) + { + wp_enqueue_style('delibera_style', get_stylesheet_directory_uri()."/delibera_style.css"); + } + else + { + global $deliberaThemes; + wp_enqueue_style('delibera_style', $deliberaThemes->themeFileUrl('delibera_style.css')); + } + } + wp_enqueue_style('ET_Builder_Module_Delibera_Member', plugins_url("frontend/css", __FILE__)."/ET_Builder_Module_Delibera_Member.css"); + } + + function javascriptFiles() + { + if (!is_pauta()) + { + wp_enqueue_script('delibera-concordar', DELIBERA_DIR_URL . '/js/delibera_concordar.js', array('jquery')); + + $data = array( + 'ajax_url' => admin_url('admin-ajax.php'), + ); + wp_localize_script('delibera-concordar', 'delibera', $data); + } + } + + function shortcode_callback( $atts, $content = null, $function_name ) { + $module_id = $this->shortcode_atts['module_id']; + $module_class = $this->shortcode_atts['module_class']; + $name = $this->shortcode_atts['name']; + $position = $this->shortcode_atts['position']; + $image_url = $this->shortcode_atts['image_url']; + $animation = $this->shortcode_atts['animation']; + $background_layout = $this->shortcode_atts['background_layout']; + $background_color = $this->shortcode_atts['background_color']; + $icon_color = $this->shortcode_atts['icon_color']; + $icon_hover_color = $this->shortcode_atts['icon_hover_color']; + $include_categories = $this->shortcode_atts['include_categories']; + $url_tema = $this->shortcode_atts['url_tema']; + $button_image_url = $this->shortcode_atts['button_image_url']; + $orderby = $this->shortcode_atts['orderby']; + $order = $this->shortcode_atts['order']; + $pauta_id = $this->shortcode_atts['pauta_id']; + $border = $this->shortcode_atts['border']; + $shadow = $this->shortcode_atts['shadow']; + + + $module_class = ET_Builder_Element::add_module_order_class( $module_class, $function_name ); + + $image = $social_links = ''; + + $args = array( + 'post_type' => 'pauta', + 'orderby' => $orderby, + 'order' => $order, + 'post_status' => 'publish', + 'posts_per_page' => 1, + ); + + if($include_categories) + { + $args['tax_query'] = array( + array( + 'taxonomy' => 'tema', + 'field' => 'tag_ID', + 'terms' => $include_categories, + 'include_children' => false + ) + ); + } + + $wp_posts = array(); + + if($orderby == 'pauta' && $pauta_id != false && $pauta_id > 0) + { + $post = get_post($pauta_id); + if(!is_object($post)) + { + $args['orderby'] = 'rand'; + $post = get_posts($args); + $post->post_title = __("Error: invalid pauta id!", 'et_builder'); + } + $wp_posts = array($post); + } + else + { + $wp_posts = get_posts($args); + } + + $image_code = ''; + $pauta_url = ""; + $titulo = ""; + $tema = ''; + $temaLink = ""; + $autor = ""; + $tags = ""; + $avatar = ""; + $except = ""; + $output = ""; + + foreach($wp_posts as $key=>$value) + { + + $term_list = wp_get_post_terms($wp_posts[$key]->ID, 'tema', array("fields" => "all")); + //print_r($term_list); + if(is_array($term_list) && count($term_list) > 0) + { + $tema = $term_list[0]->name; + $temaLink = get_term_link($term_list[0]->slug,"tema"); + } + + $autor = get_userdata($wp_posts[$key]->post_author)->display_name; + + $tags = get_the_tag_list('#',' #','',$wp_posts[$key]->ID); + + $autor_url = \Delibera\Member\MemberPath::getAuthorPautasUrl($wp_posts[$key]->post_author); + + $avatar = get_avatar( $wp_posts[$key]->post_author, '32'); + + if (has_post_thumbnail( $wp_posts[$key]->ID ) ){ + $image_pauta_url = wp_get_attachment_image_src( get_post_thumbnail_id( $wp_posts[$key]->ID ), 'thumbnail' ); + $image_code = $image_pauta_url[0]; + $module_class .= ' has-thumbnail'; + } + $pauta_url = $wp_posts[$key]->guid; + $titulo = get_the_title($wp_posts[$key]); + $except = apply_filters( 'get_the_excerpt', $wp_posts[$key]->post_excerpt ); + + + if($url_tema!=="") + $temaLink = $url_tema; + + if ( '' !== $icon_color ) { + ET_Builder_Element::set_style( $function_name, array( + 'selector' => '%%order_class%% .et_pb_member_social_links a', + 'declaration' => sprintf( + 'color: %1$s;', + esc_html( $icon_color ) + ), + ) ); + } + + if ( '' !== $icon_hover_color ) { + ET_Builder_Element::set_style( $function_name, array( + 'selector' => '%%order_class%% .et_pb_member_social_links a:hover', + 'declaration' => sprintf( + 'color: %1$s;', + esc_html( $icon_hover_color ) + ), + ) ); + } + + if($image_code !='') + $image_url = $image_code; + + if ( '' !== $image_url ) { + $image = sprintf( + '
+ +
', + esc_url( $image_url ), + esc_attr( $titulo ), + esc_attr( " et_pb_animation_{$animation}" ) + ); + } + + + + $style = $class = ''; + + if ( '' !== $background_color ) { + $style .= sprintf( 'background-color:%s;', + esc_attr( $background_color ) + ); + } + + $style = '' !== $style ? " style='{$style}'" : ''; + + global $deliberaThemes; + $svg = $deliberaThemes->themeFileUrl('images/icons.svg'); + $like = delibera_gerar_curtir($wp_posts[$key]->ID); + $unlike = delibera_gerar_discordar($wp_posts[$key]->ID); + $comment_count = delibera_comment_number($wp_posts[$key]->ID,'todos'); + + $button = $button_image_url != '' ? '' : __('Participar', 'et_builder'); + + $output = sprintf( + ' + %2$s + +
+ + %5$s + %6$s + %1$s + %7$s + +
%14$s
+ +
+
%15$s
+
%13$s
+
+
+ %16$s + %17$s +
%18$s
+
+
%21$s
+ ', + $this->shortcode_content, + ( '' !== $image ? $image : '' ), + ( '' !== $module_id ? sprintf( ' id="%1$s"', esc_attr( $module_id ) ) : '' ), + ( '' !== $module_class ? sprintf( ' %1$s', esc_attr( str_replace("delibera","team",$module_class) ) ) : '' ), + ( '' !== $titulo ? sprintf( '

%1$s

', esc_html( $titulo ) ) : '' ), + ( '' !== $position ? sprintf( '

%1$s

', esc_html( $position ) ) : '' ), + $social_links, + $background_layout, + ( '' === $image ? ' et_pb_delibera_member_no_image' : '' ), + $pauta_url, + $tema, + $temaLink, + $autor, + $tags, + $avatar, + $like, + $unlike, + $comment_count, + $svg, + ( '' !== $style ? $style : '' ), + $button, + $autor_url + ); + } + return $output; + } + + /** + * @return array array of pauta in format: id => tittle + */ + function get_pautas() + { + $pautas = get_posts(array( + 'post_type' => 'pauta', + 'posts_per_page' => -1, + 'orderby' => 'date', + 'order' => 'DESC', + 'post_status' => 'publish', + )); + $ret = array('-1' => __('Selecione uma pauta', 'et_builder')); + if(is_array($pautas)) + { + /** @var WP_POST $pauta **/ + foreach ($pautas as $pauta) + { + $ret[$pauta->ID] = get_the_title($pauta); + } + } + return $ret; + } +} +new ET_Builder_Module_Delibera_Member; + diff --git a/includes/wp-divi/ET_Builder_Module_Delibera_Member/frontend/css/ET_Builder_Module_Delibera_Member.css b/includes/wp-divi/ET_Builder_Module_Delibera_Member/frontend/css/ET_Builder_Module_Delibera_Member.css new file mode 100644 index 0000000..6763c89 --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Delibera_Member/frontend/css/ET_Builder_Module_Delibera_Member.css @@ -0,0 +1,149 @@ +@CHARSET "UTF-8"; + +.et_pb_module.et_pb_delibera_member { + border-style: solid; + display: block; + margin: 0 auto; + padding: 2px; + position: relative; + text-align: center; + float: left; + width: 100%; +} + +.et_pb_module.et_pb_delibera_member_border { + border-radius: 12px; + border-style: solid; + display: block; + margin: 0 auto; + padding: 2px; + position: relative; + text-align: center; + float: left; + width: 100%; +} + +.et_pb_delibera_shadow { + box-shadow: 5px 5px 5px #888888; +} + +.et_pb_delibera_border{ + border: 1px solid; +} + + +.et_pb_delibera_categoria { + display: block; + position: relative; + float:left; + width: 100%; +} + +.et_pb_module.et_pb_delibera_member .comments, .et_pb_module.et_pb_delibera_member_border .comments { + display: inline-block; + position: relative; +} + +.et_pb_module.et_pb_delibera_member .et_pb_delibera_member_image img { + display: block; + position: relative; +} + +.et_pb_module.et_pb_delibera_member .et_pb_delibera_member_image { + display: block; + float: left; + position: relative; + background-position: center center; + background-repeat: no-repeat; + width: 100%; + background-size: 100% auto; +} + +.et_pb_module.et_pb_delibera_member_border .et_pb_delibera_member_image_border { + display: block; + float: left; + position: relative; + border-top-left-radius: 10px; + border-top-right-radius: 10px; + background-position: center center; + background-repeat: no-repeat; + width: 100%; + background-size: 100% auto; +} + +.et_pb_module.et_pb_delibera_member .tema a, +.et_pb_module.et_pb_delibera_member_border .tema a { + color: #000; + font-size: 1.6em; + font-weight: bolder; + text-transform: uppercase; +} + +.et_pb_module.et_pb_delibera_member .tema, +.et_pb_module.et_pb_delibera_member_border .tema { + padding: 10px 0; + border-top-left-radius: 10px; + border-top-right-radius: 10px; + position: relative; + display: block; + float: left; + width: 100%; +} + +.et_pb_module.et_pb_delibera_member.has-thumbnail .tema, +.et_pb_module.et_pb_delibera_member_border.has-thumbnail .tema{ + border-top-left-radius: unset; + border-top-right-radius: unset; +} + +.et_pb_module.et_pb_delibera_member .et_pb_delibera_member_description h4, +.et_pb_module.et_pb_delibera_member_border .et_pb_delibera_member_description h4 { + color: #000 !important; +} + +.et_pb_module.et_pb_delibera_member .et_pb_delibera_member_description, +.et_pb_module.et_pb_delibera_member_border .et_pb_delibera_member_description { + color: #000; + padding: 10px 20px; + text-align: left; + border-top-left-radius: 10px; + border-top-right-radius: 10px; +} + +.et_pb_module.et_pb_delibera_member .user div, +.et_pb_module.et_pb_delibera_member .user div { + display: inline-block; + margin: 10px; + vertical-align: top; + text-transform: capitalize; + color: #000; +} + +.et_pb_module.et_pb_delibera_member .faixa, +.et_pb_module.et_pb_delibera_member_border .faixa { + border-bottom-left-radius: 10px; + border-bottom-right-radius: 10px; + padding: 8px 20px 8px 8px; + text-align: right; +} + +.delibera-like .delibera-icon-thumbs-up, .delibera-unlike .delibera-icon-thumbs-down, +a.delibera-like-login .delibera-icon-thumbs-up, a.delibera-unlike-login .delibera-icon-thumbs-down { + color: #000000; +} + +.delibera-like .delibera-icon-thumbs-up:hover, .delibera-unlike .delibera-icon-thumbs-down:hover, +a.delibera-like-login .delibera-icon-thumbs-up:hover, a.delibera-unlike-login .delibera-icon-thumbs-down:hover { + color: #cccccc; +} + +.delibera-like .delibera-icon-thumbs-up.active, +a.delibera-like-login .delibera-icon-thumbs-up.active { + color: blue; +} + +.delibera-unlike .delibera-icon-thumbs-down.active, +a.delibera-unlike-login .delibera-icon-thumbs-down.active { + color: red; +} + diff --git a/includes/wp-divi/ET_Builder_Module_Formulario/ET_Builder_Module_Formulario.php b/includes/wp-divi/ET_Builder_Module_Formulario/ET_Builder_Module_Formulario.php new file mode 100644 index 0000000..9b11f3c --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Formulario/ET_Builder_Module_Formulario.php @@ -0,0 +1,662 @@ +name = esc_html__( 'Inserção de pauta', 'et_builder' ); + $this->slug = 'et_pb_formulariooasxqzx'; + $this->child_slug = 'et_pb_contact_field_delibera'; + $this->child_item_text = esc_html__( 'Field', 'et_builder' ); + + $this->whitelisted_fields = array( + 'include_categories', + 'captcha', + 'email', + 'title', + 'admin_label', + 'module_id', + 'module_class', + 'form_background_color', + 'input_border_radius', + 'use_redirect', + 'redirect_url', + 'success_message' + ); + + $this->fields_defaults = array( + 'captcha' => array( 'off' ), + 'use_redirect' => array( 'on' ), + 'redirect_url' => 'pauta' + ); + + $this->main_css_element = '%%order_class%%.et_pb_delibera_form_container'; + $this->advanced_options = array( + 'fonts' => array( + 'title' => array( + 'label' => esc_html__( 'Title', 'et_builder' ), + 'css' => array( + 'main' => "{$this->main_css_element} h1", + ), + ), + 'form_field' => array( + 'label' => esc_html__( 'Form Field', 'et_builder' ), + 'css' => array( + 'main' => "{$this->main_css_element} .input", + ), + ), + ), + 'border' => array( + 'css' => array( + 'main' => "{$this->main_css_element} .input", + ), + 'settings' => array( + 'color' => 'alpha', + ), + ), + 'button' => array( + 'button' => array( + 'label' => esc_html__( 'Button', 'et_builder' ), + ), + ), + ); + $this->custom_css_options = array( + 'contact_title' => array( + 'label' => esc_html__( 'Contact Title', 'et_builder' ), + 'selector' => '.et_pb_contact_main_title', + ), + 'contact_button' => array( + 'label' => esc_html__( 'Contact Button', 'et_builder' ), + 'selector' => '.et_pb_contact_submit', + ), + 'contact_fields' => array( + 'label' => esc_html__( 'Form Fields', 'et_builder' ), + 'selector' => '.et_pb_contact_left input', + ), + 'text_field' => array( + 'label' => esc_html__( 'Message Field', 'et_builder' ), + 'selector' => 'textarea.et_pb_contact_message', + ), + 'captcha_field' => array( + 'label' => esc_html__( 'Captcha Field', 'et_builder' ), + 'selector' => 'input.et_pb_contact_captcha', + ), + 'captcha_label' => array( + 'label' => esc_html__( 'Captcha Text', 'et_builder' ), + 'selector' => '.et_pb_contact_right p', + ), + ); + + add_action('wp_enqueue_scripts', array($this, 'javascriptFiles'), 1001); + } + + function get_fields() { + $fields = array( + 'include_categories' => array( + 'label' => esc_html__( 'Include Categories', 'et_builder' ), + 'renderer' => 'et_builder_include_categories_delibera_form_option_radio', + 'option_category' => 'basic_option', + 'renderer_options' => array( + 'use_terms' => true, + 'term_name' => 'tema', + 'post_type'=>'pauta' + ), + 'description' => esc_html__( 'Choose which categories you would like to include in the feed.', 'et_builder' ), + ), + 'captcha' => array( + 'label' => esc_html__( 'Display Captcha', 'et_builder' ), + 'type' => 'yes_no_button', + 'option_category' => 'configuration', + 'options' => array( + 'on' => esc_html__( 'Yes', 'et_builder' ), + 'off' => esc_html__( 'No', 'et_builder' ), + ), + 'description' => esc_html__( 'Turn the captcha on or off using this option.', 'et_builder' ), + ), + 'email' => array( + 'label' => esc_html__( 'Email', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'basic_option', + 'description' => esc_html__( 'Input the email address where messages should be sent.', 'et_builder' ), + ), + 'title' => array( + 'label' => esc_html__( 'Title', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'basic_option', + 'description' => esc_html__( 'Define a title for your form.', 'et_builder' ), + ), + + 'use_redirect' => array( + 'label' => esc_html__( 'Enable Redirect URL', 'et_builder' ), + 'type' => 'yes_no_button', + 'option_category' => 'configuration', + 'options' => array( + 'off' => esc_html__( 'No', 'et_builder' ), + 'on' => esc_html__( 'Yes', 'et_builder' ), + ), + 'affects' => array( + '#et_pb_redirect_url', + ), + 'description' => esc_html__( 'Redirect users after successful form submission.', 'et_builder' ), + ), + 'redirect_url' => array( + 'label' => esc_html__( 'Redirect URL', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'configuration', + 'depends_show_if' => 'on', + 'description' => esc_html__( 'Type the Redirect URL', 'et_builder' ), + ), + 'success_message' => array( + 'label' => esc_html__( 'Success Message', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'configuration', + 'description' => esc_html__( 'Type the message you want to display after successful form submission. Leave blank for default', 'et_builder' ), + ), + 'form_background_color' => array( + 'label' => esc_html__( 'Form Background Color', 'et_builder' ), + 'type' => 'color-alpha', + 'custom_color' => true, + 'tab_slug' => 'advanced', + ), + 'input_border_radius' => array( + 'label' => esc_html__( 'Input Border Radius', 'et_builder' ), + 'type' => 'range', + 'default' => '0', + 'range_settings' => array( + 'min' => '0', + 'max' => '100', + 'step' => '1', + ), + 'option_category' => 'layout', + 'tab_slug' => 'advanced', + ), + 'disabled_on' => array( + 'label' => esc_html__( 'Disable on', 'et_builder' ), + 'type' => 'multiple_checkboxes', + 'options' => array( + 'phone' => esc_html__( 'Phone', 'et_builder' ), + 'tablet' => esc_html__( 'Tablet', 'et_builder' ), + 'desktop' => esc_html__( 'Desktop', 'et_builder' ), + ), + 'additional_att' => 'disable_on', + 'option_category' => 'configuration', + 'description' => esc_html__( 'This will disable the module on selected devices', 'et_builder' ), + ), + 'admin_label' => array( + 'label' => esc_html__( 'Admin Label', 'et_builder' ), + 'type' => 'text', + 'description' => esc_html__( 'This will change the label of the module in the builder for easy identification.', 'et_builder' ), + ), + 'module_id' => array( + 'label' => esc_html__( 'CSS ID', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'configuration', + 'tab_slug' => 'custom_css', + 'option_class' => 'et_pb_custom_css_regular', + ), + 'module_class' => array( + 'label' => esc_html__( 'CSS Class', 'et_builder' ), + 'type' => 'text', + 'option_category' => 'configuration', + 'tab_slug' => 'custom_css', + 'option_class' => 'et_pb_custom_css_regular', + ), + ); + return $fields; + } + + function predefined_child_modules() { + + $output = sprintf( + '[et_pb_contact_field_delibera field_title="%1$s" field_type="input" field_id="Titulo" required_mark="on" fullwidth_field="off" /][et_pb_contact_field_delibera field_title="%2$s" field_type="input" field_id="Tags" required_mark="on" fullwidth_field="off" /][et_pb_contact_field_delibera field_title="%3$s" field_type="text" field_id="Descricao" required_mark="on" /]', + esc_attr__( 'Título', 'et_builder' ), + esc_attr__( 'Tags', 'et_builder' ), + esc_attr__( 'Descricao', 'et_builder' ) + ); + + return $output; + } + + function shortcode_callback( $atts, $content = null, $function_name ) { + $include_categories = $this->shortcode_atts['include_categories']; + $module_id = $this->shortcode_atts['module_id']; + $module_class = $this->shortcode_atts['module_class']; + $captcha = $this->shortcode_atts['captcha']; + $email = $this->shortcode_atts['email']; + $title = $this->shortcode_atts['title']; + $form_background_color = $this->shortcode_atts['form_background_color']; + $input_border_radius = $this->shortcode_atts['input_border_radius']; + $button_custom = $this->shortcode_atts['custom_button']; + $custom_icon = $this->shortcode_atts['button_icon']; + $use_redirect = $this->shortcode_atts['use_redirect']; + $redirect_url = $this->shortcode_atts['redirect_url']; + $success_message = $this->shortcode_atts['success_message']; + + global $et_pb_contact_form_num; + + $module_class = ET_Builder_Element::add_module_order_class( $module_class, $function_name ); + + if ( '' !== $form_background_color ) { + ET_Builder_Element::set_style( $function_name, array( + 'selector' => '%%order_class%% .input', + 'declaration' => sprintf( + 'background-color: %1$s;', + esc_html( $form_background_color ) + ), + ) ); + } + + if ( ! in_array( $input_border_radius, array( '', '0' ) ) ) { + ET_Builder_Element::set_style( $function_name, array( + 'selector' => '%%order_class%% .input', + 'declaration' => sprintf( + '-moz-border-radius: %1$s; -webkit-border-radius: %1$s; border-radius: %1$s;', + esc_html( et_builder_process_range_value( $input_border_radius ) ) + ), + ) ); + } + + $success_message = '' !== $success_message ? $success_message : esc_html__( 'Thanks for contacting us', 'et_builder' ); + + $et_pb_contact_form_num = $this->shortcode_callback_num(); + + $content = $this->shortcode_content; + + $et_error_message = ''; + $et_contact_error = false; + $current_form_fields = isset( $_POST['et_pb_contact_email_fields_' . $et_pb_contact_form_num] ) ? $_POST['et_pb_contact_email_fields_' . $et_pb_contact_form_num] : ''; + $contact_email = ''; + $processed_fields_values = array(); + + $nonce_result = isset( $_POST['_wpnonce-et-pb-contact-form-submitted'] ) && wp_verify_nonce( $_POST['_wpnonce-et-pb-contact-form-submitted'], 'et-pb-contact-form-submit' ) ? true : false; + + // check that the form was submitted and et_pb_contactform_validate field is empty to protect from spam + if ( $nonce_result && isset( $_POST['et_pb_contactform_submit_' . $et_pb_contact_form_num] ) && empty( $_POST['et_pb_contactform_validate_' . $et_pb_contact_form_num] ) ) { + if ( '' !== $current_form_fields ) { + $fields_data_json = str_replace( '\\', '' , $current_form_fields ); + $fields_data_array = json_decode( $fields_data_json, true ); + + // check whether captcha field is not empty + if ( 'on' === $captcha && ( ! isset( $_POST['et_pb_contact_captcha_' . $et_pb_contact_form_num] ) || empty( $_POST['et_pb_contact_captcha_' . $et_pb_contact_form_num] ) ) ) { + $et_error_message .= sprintf( '

%1$s

', esc_html__( 'Make sure you entered the captcha.', 'et_builder' ) ); + $et_contact_error = true; + } + + // check all fields on current form and generate error message if needed + if ( ! empty( $fields_data_array ) ) { + foreach( $fields_data_array as $index => $value ) { + // check all the required fields, generate error message if required field is empty + if ( 'required' === $value['required_mark'] && empty( $_POST[ $value['field_id'] ] ) ) { + $et_error_message .= sprintf( '

%1$s

', esc_html__( 'Make sure you fill in all required fields.', 'et_builder' ) ); + $et_contact_error = true; + continue; + } + + // additional check for email field + if ( 'email' === $value['field_type'] && ! empty( $_POST[ $value['field_id'] ] ) ) { + $contact_email = sanitize_email( $_POST[ $value['field_id'] ] ); + if ( ! is_email( $contact_email ) ) { + $et_error_message .= sprintf( '

%1$s

', esc_html__( 'Invalid Email.', 'et_builder' ) ); + $et_contact_error = true; + } + } + + // prepare the array of processed field values in convenient format + if ( false === $et_contact_error ) { + $processed_fields_values[ $value['original_id'] ]['value'] = isset( $_POST[ $value['field_id'] ] ) ? $_POST[ $value['field_id'] ] : ''; + $processed_fields_values[ $value['original_id'] ]['label'] = $value['field_label']; + } + } + } + } else { + $et_error_message .= sprintf( '

%1$s

', esc_html__( 'Make sure you fill in all required fields.', 'et_builder' ) ); + $et_contact_error = true; + } + } else { + if ( false === $nonce_result && isset( $_POST['et_pb_contactform_submit_' . $et_pb_contact_form_num] ) && empty( $_POST['et_pb_contactform_validate_' . $et_pb_contact_form_num] ) ) { + $et_error_message .= sprintf( '

%1$s

', esc_html__( 'Please refresh the page and try again.', 'et_builder' ) ); + } + $et_contact_error = true; + } + + // generate digits for captcha + $et_pb_first_digit = rand( 1, 15 ); + $et_pb_second_digit = rand( 1, 15 ); + + if ( ! $et_contact_error && $nonce_result ) { + $et_email_to = '' !== $email + ? $email + : get_site_option( 'admin_email' ); + + $et_site_name = get_option( 'blogname' ); + + $contact_name = isset( $processed_fields_values['name'] ) ? stripslashes( sanitize_text_field( $processed_fields_values['name']['value'] ) ) : ''; + + + // use default message pattern if custom pattern is not defined + $message_pattern = isset( $processed_fields_values['message']['value'] ) ? $processed_fields_values['message']['value'] : ''; + + // Add all custom fields into the message body by default + foreach ( $processed_fields_values as $key => $value ) { + if ( ! in_array( $key, array( 'message', 'name', 'email','descricao','descrição','titulo','tags' ) ) ) { + $message_pattern .= "\r\n"; + $message_pattern .= sprintf( + '%1$s: %2$s', + '' !== $value['label'] ? $value['label'] : $key, + $value['value'] + ); + } + } + + $my_post = array( + 'post_title' => $processed_fields_values['titulo']['value'], + 'post_content' => $processed_fields_values['descricao']['value'], + 'post_type' => 'pauta', + 'tags_input' => $processed_fields_values['tags']['value'], + 'delibera_flow' => array("discussao", "emvotacao", 'comresolucao'), //TODO option + 'redirect' => false + ); + if(!empty( $_POST['et_pb_categories_' . $et_pb_contact_form_num] )) + { + $my_post['tema'] = array( $_POST['et_pb_categories_' . $et_pb_contact_form_num] ); + } + + $post_id = deliberaCreateTopic( $my_post ); + + $_SESSION['last_id'] = $post_id; + + if($redirect_url == "pauta") + { + $redirect_url = esc_url( get_permalink($post_id) ); + } + + $redirect_url = esc_url( get_permalink($post_id) ); + + $et_error_message = sprintf( '

%1$s

', 'Obrigado por participar, você pode ver sua proposta aqui.' ); + + } + + $form = ''; + + $et_pb_captcha = sprintf( ' +
+

+ %1$s = +

+
', + sprintf( '%1$s + %2$s', esc_html( $et_pb_first_digit ), esc_html( $et_pb_second_digit ) ), + esc_attr( $et_pb_contact_form_num ), + esc_attr( $et_pb_first_digit ), + esc_attr( $et_pb_second_digit ) + ); + + if ( '' === trim( $content ) ) { + $content = do_shortcode( $this->predefined_child_modules() ); + } + + if ( $et_contact_error ) { + $form = sprintf( ' +
+
+ %8$s + + +
+ %2$s + + +
+ %4$s + +
', + esc_url( get_permalink( get_the_ID() ) ), + ( 'on' === $captcha ? $et_pb_captcha : '' ), + esc_html__( 'Submit', 'et_builder' ), + wp_nonce_field( 'et-pb-contact-form-submit', '_wpnonce-et-pb-contact-form-submitted', true, false ), + '' !== $custom_icon && 'on' === $button_custom ? sprintf( + ' data-icon="%1$s"', + esc_attr( et_pb_process_font_icon( $custom_icon ) ) + ) : '', + '' !== $custom_icon && 'on' === $button_custom ? ' et_pb_custom_button_icon' : '', + esc_attr( $et_pb_contact_form_num ), + $content + ); + } + + $output = sprintf( ' +
+ %1$s +
%2$s
+ %3$s +
+ ', + ( '' !== $title ? sprintf( '

%1$s

', esc_html( $title ) ) : '' ), + '' !== $et_error_message ? $et_error_message : '', + $form, + ( '' !== $module_id + ? esc_attr( $module_id ) + : esc_attr( 'et_pb_insert_pauta_' . $et_pb_contact_form_num ) + ), + ( '' !== $module_class ? sprintf( ' %1$s', esc_attr( $module_class ) ) : '' ), + esc_attr( $et_pb_contact_form_num ), + 'on' === $use_redirect && '' !== $redirect_url ? sprintf( ' data-redirect_url="%1$s"', esc_attr( $redirect_url ) ) : '' + ); + + return $output; + } + + function javascriptFiles() + { + if (!is_pauta()) + { + wp_enqueue_script('ET_Builder_Module_Formulario', plugins_url("frontend/js", __FILE__).'/ET_Builder_Module_Formulario.js', array('jquery')); + + $data = array( + 'ajax_url' => admin_url('admin-ajax.php'), + 'url' => wp_login_url( get_permalink() ) + ); + wp_localize_script('ET_Builder_Module_Formulario', 'ET_Builder_Module_Formulario', $data); + } + } + +} +new ET_Builder_Module_Formulario; + +class ET_Builder_Module_Formulario_item extends ET_Builder_Module { + function init() { + $this->name = esc_html__( 'Field', 'et_builder' ); + $this->slug = 'et_pb_contact_field_delibera'; + $this->type = 'child'; + $this->child_title_var = 'field_id'; + + $this->whitelisted_fields = array( + 'field_title', + 'field_type', + 'field_id', + 'required_mark', + 'fullwidth_field', + 'input_border_radius', + 'field_background_color', + ); + + $this->advanced_setting_title_text = esc_html__( 'New Field', 'et_builder' ); + $this->settings_text = esc_html__( 'Field Settings', 'et_builder' ); + $this->main_css_element = '%%order_class%%.et_pb_contact_field .input'; + $this->advanced_options = array( + 'fonts' => array( + 'form_field' => array( + 'label' => esc_html__( 'Field', 'et_builder' ), + 'css' => array( + 'main' => "{$this->main_css_element}", + ), + ), + ), + 'border' => array( + 'css' => array( + 'main' => "{$this->main_css_element}", + ), + 'settings' => array( + 'color' => 'alpha', + ), + ), + ); + } + + function get_fields() { + $fields = array( + 'field_id' => array( + 'label' => esc_html__( 'Field ID', 'et_builder' ), + 'type' => 'text', + 'description' => esc_html__( 'Define the unique ID of this field. You should use only English characters without special characters and spaces.', 'et_builder' ), + ), + 'field_title' => array( + 'label' => esc_html__( 'Title', 'et_builder' ), + 'type' => 'text', + 'description' => esc_html__( 'Here you can define the content that will be placed within the current tab.', 'et_builder' ), + ), + 'field_type' => array( + 'label' => esc_html__( 'Type', 'et_builder' ), + 'type' => 'select', + 'option_category' => 'basic_option', + 'options' => array( + 'input' => esc_html__( 'Input Field', 'et_builder' ), + 'email' => esc_html__( 'Email Field', 'et_builder' ), + 'text' => esc_html__( 'Textarea', 'et_builder' ), + ), + 'description' => esc_html__( 'Choose the type of field', 'et_builder' ), + ), + 'required_mark' => array( + 'label' => esc_html__( 'Required Field', 'et_builder' ), + 'type' => 'yes_no_button', + 'option_category' => 'configuration', + 'options' => array( + 'on' => esc_html__( 'Yes', 'et_builder' ), + 'off' => esc_html__( 'No', 'et_builder' ), + ), + 'description' => esc_html__( 'Define whether the field should be required or optional', 'et_builder' ), + ), + 'fullwidth_field' => array( + 'label' => esc_html__( 'Make Fullwidth', 'et_builder' ), + 'type' => 'yes_no_button', + 'option_category' => 'layout', + 'options' => array( + 'on' => esc_html__( 'Yes', 'et_builder' ), + 'off' => esc_html__( 'No', 'et_builder' ), + ), + 'description' => esc_html__( 'If enabled, the field will take 100% of the width of the content area, otherwise it will take 50%', 'et_builder' ), + ), + 'field_background_color' => array( + 'label' => esc_html__( 'Background Color', 'et_builder' ), + 'type' => 'color-alpha', + 'custom_color' => true, + 'tab_slug' => 'advanced', + ), + 'input_border_radius' => array( + 'label' => esc_html__( 'Border Radius', 'et_builder' ), + 'type' => 'range', + 'default' => '0', + 'range_settings' => array( + 'min' => '0', + 'max' => '100', + 'step' => '1', + ), + 'option_category' => 'layout', + 'tab_slug' => 'advanced', + ), + ); + return $fields; + } + + function shortcode_callback( $atts, $content = null, $function_name ) { + $field_title = $this->shortcode_atts['field_title']; + $field_type = $this->shortcode_atts['field_type']; + $field_id = $this->shortcode_atts['field_id']; + $required_mark = $this->shortcode_atts['required_mark']; + $fullwidth_field = $this->shortcode_atts['fullwidth_field']; + $field_background_color = $this->shortcode_atts['field_background_color']; + $input_border_radius = $this->shortcode_atts['input_border_radius']; + + global $et_pb_contact_form_num; + + // do not output the fields with empty ID + if ( '' === $field_id ) { + return; + } + + $field_id = strtolower( $field_id ); + + $current_module_num = '' === $et_pb_contact_form_num ? 0 : intval( $et_pb_contact_form_num ) + 1; + + $module_class = ET_Builder_Element::add_module_order_class( '', $function_name ); + + $this->half_width_counter = ! isset( $this->half_width_counter ) ? 0 : $this->half_width_counter; + + // count fields to add the et_pb_contact_field_last properly + if ( 'off' === $fullwidth_field ) { + $this->half_width_counter++; + } else { + $this->half_width_counter = 0; + } + + $input_field = ''; + + if ( '' !== $field_background_color ) { + ET_Builder_Element::set_style( $function_name, array( + 'selector' => '%%order_class%% .input', + 'declaration' => sprintf( + 'background-color: %1$s;', + esc_html( $field_background_color ) + ), + ) ); + } + + if ( ! in_array( $input_border_radius, array( '', '0' ) ) ) { + ET_Builder_Element::set_style( $function_name, array( + 'selector' => '%%order_class%% .input', + 'declaration' => sprintf( + '-moz-border-radius: %1$s; -webkit-border-radius: %1$s; border-radius: %1$s;', + esc_html( et_builder_process_range_value( $input_border_radius ) ) + ), + ) ); + } + + switch( $field_type ) { + case 'text': + $input_field = sprintf( + '', + ( isset( $_POST['et_pb_contact_' . $field_id . '_' . $current_module_num] ) ? esc_html( sanitize_text_field( $_POST['et_pb_contact_' . $field_id . '_' . $current_module_num] ) ) : esc_html( $field_title ) ), + esc_attr( $current_module_num ), + esc_attr( $field_id ), + esc_attr( $field_type ), + 'off' === $required_mark ? 'not_required' : 'required' + ); + break; + case 'input' : + case 'email' : + $input_field = sprintf( + '', + ( isset( $_POST['et_pb_contact_' . $field_id . '_' . $current_module_num] ) ? esc_attr( sanitize_text_field( $_POST['et_pb_contact_' . $field_id . '_' . $current_module_num] ) ) : esc_attr( $field_title ) ), + esc_attr( $current_module_num ), + esc_attr( $field_id ), + esc_attr( $field_type ), + 'off' === $required_mark ? 'not_required' : 'required' + ); + break; + } + + $output = sprintf( + '

+ + %4$s +

', + esc_html( $field_title ), + esc_attr( $current_module_num ), + esc_attr( $field_id ), + $input_field, + esc_attr( $module_class ), + 'off' === $fullwidth_field ? ' et_pb_contact_field_half' : '', + 0 === $this->half_width_counter % 2 ? ' et_pb_contact_field_last' : '' + ); + + return $output; + } +} +new ET_Builder_Module_Formulario_item; \ No newline at end of file diff --git a/includes/wp-divi/ET_Builder_Module_Formulario/frontend/js/ET_Builder_Module_Formulario.js b/includes/wp-divi/ET_Builder_Module_Formulario/frontend/js/ET_Builder_Module_Formulario.js new file mode 100644 index 0000000..04c4c1b --- /dev/null +++ b/includes/wp-divi/ET_Builder_Module_Formulario/frontend/js/ET_Builder_Module_Formulario.js @@ -0,0 +1,27 @@ +/** + * + */ + +function divi_child_teste() +{ + var ajaxurl = ET_Builder_Module_Formulario.ajax_url; + + var $that = jQuery(this); + var data = { + 'action': 'check_user_logged_in' + }; + + jQuery.post(ajaxurl, data,function(response){ // aja + if(response == '0') { + alert('Antes de interagir você deve se cadastrar'); + if(typeof ajax_login_toggle_panel == 'function') + { + ajax_login_toggle_panel(); + } + else + { + window.location = ET_Builder_Module_Formulario.url; + } + } + }); +} \ No newline at end of file diff --git a/includes/wp-divi/modules.php b/includes/wp-divi/modules.php new file mode 100644 index 0000000..955c1a5 --- /dev/null +++ b/includes/wp-divi/modules.php @@ -0,0 +1,17 @@ + true, + 'term_name' => 'tema', + 'post_type'=>'pauta' + ) ); + + $args = wp_parse_args( $args, $defaults ); + + $output = "\t" . "<% var et_pb_include_categories_temp = typeof et_pb_include_categories !== 'undefined' ? et_pb_include_categories.split( ',' ) : []; %>" . "\n"; + + if ( $args['use_terms'] ) { + $cats_array = get_terms( $args['term_name'], array( 'hide_empty' => false) ); + } else { + $cats_array = get_categories( apply_filters( 'et_builder_get_categories_args', 'hide_empty=0' ) ); + //$cats_array = get_categories(); + } + + if ( empty( $cats_array ) ) { + $output = '

' . esc_html__( "You currently don't have any projects assigned to a category.", 'et_builder' ) . '

'; + } + + foreach ( $cats_array as $category ) { + $contains = sprintf( + '<%%= _.contains( et_pb_include_categories_temp, "%1$s" ) ? checked="checked" : "" %%>', + esc_html( $category->term_id ) + ); + + $output .= sprintf( + '%4$s
', + esc_attr( $category->term_id ), + esc_html( $category->name ), + $contains, + "\n\t\t\t\t\t" + ); + } + + $output = '
' . $output . '
'; + + return $output; + + //return apply_filters( 'et_builder_include_categories_option_html', $output ); +} +endif; + +if ( ! function_exists( 'et_builder_include_categories_delibera_option' ) ) : +function et_builder_include_categories_delibera_option( $args = array() ) { + + $defaults = apply_filters( 'et_builder_include_categories_delibera_defaults', array ( + 'use_terms' => true, + 'term_name' => 'tema', + 'post_type'=>'pauta' + ) ); + + $args = wp_parse_args( $args, $defaults ); + + $output = "\t" . "<% var et_pb_include_categories_temp = typeof et_pb_include_categories !== 'undefined' ? et_pb_include_categories.split( ',' ) : []; %>" . "\n"; + + if ( $args['use_terms'] ) { + $cats_array = get_terms( $args['term_name'], array( 'hide_empty' => false) ); + } else { + $cats_array = get_categories( apply_filters( 'et_builder_get_categories_args', 'hide_empty=0' ) ); + //$cats_array = get_categories(); + } + + if ( empty( $cats_array ) ) { + $output = '

' . esc_html__( "You currently don't have any projects assigned to a category.", 'et_builder' ) . '

'; + } + + foreach ( $cats_array as $category ) { + $contains = sprintf( + '<%%= _.contains( et_pb_include_categories_temp, "%1$s" ) ? checked="checked" : "" %%>', + esc_html( $category->term_id ) + ); + + $output .= sprintf( + '%4$s
', + esc_attr( $category->term_id ), + esc_html( $category->name ), + $contains, + "\n\t\t\t\t\t" + ); + } + + $output = '
' . $output . '
'; + + return $output; + + //return apply_filters( 'et_builder_include_categories_option_html', $output ); +} +endif; + +if(! function_exists('et_builder_pauta_delibera_option')) +{ + function et_builder_pauta_delibera_option($args = array()) + { + $defaults = apply_filters( + 'et_builder_include_categories_delibera_defaults', + array( + 'post_type' => 'pauta' + ) + ); + + $args = wp_parse_args($args, $defaults); + + $output = "\t" . "<% var et_pb_pautas_temp = typeof et_pb_pautas !== 'undefined' ? et_pb_pautas : ''; %>" . "\n"; + + $pautas = get_posts(array( + 'post_type' => $args['post_type'], + 'posts_per_page' => -1, + 'orderby' => 'date', + 'order' => 'DESC', + 'post_status' => 'publish', + )); + + foreach($pautas as $pauta) + { + $contains = sprintf( + '<%%= _.contains( et_pb_pautas_temp, "%1$s" ) ? checked="checked" : "" %%>', + esc_html($category->term_id)); + + $output .= sprintf( + '%4$s
', + esc_attr($category->term_id), esc_html($category->name), + $contains, "\n\t\t\t\t\t"); + } + + $output = '
' . $output . '
'; + + return $output; + + // return apply_filters( 'et_builder_include_categories_option_html', + // $output ); + } +} \ No newline at end of file diff --git a/js/delibera_concordar.js b/js/delibera_concordar.js index 6ab4cc2..335ebd0 100644 --- a/js/delibera_concordar.js +++ b/js/delibera_concordar.js @@ -1,40 +1,56 @@ jQuery(document).ready(function() { - - jQuery(".delibera_like").click(function() { - var container = jQuery(this); - - jQuery.post( - delibera.ajax_url, - { - action : "delibera_curtir", - like_id : jQuery(this).children('input[name="object_id"]').val(), - type : jQuery(this).children('input[name="type"]').val(), - }, - function(response) { - jQuery(container).parent().children(".delibera_unlike").remove(); - jQuery(container).parent().children('.delibera-like-count').text(response); - jQuery(container).parent().children('.delibera-like-count').show(); - jQuery(container).remove(); - } - ); - }); - - jQuery(".delibera_unlike").click(function() { - var container = jQuery(this); - - jQuery.post( - delibera.ajax_url, - { - action : "delibera_discordar", - like_id : jQuery(this).children('input[name="object_id"]').val(), - type : jQuery(this).children('input[name="type"]').val(), - }, - function(response) { - jQuery(container).parent().children(".delibera_like").remove(); - jQuery(container).parent().children('.delibera-unlike-count').text(response); - jQuery(container).parent().children('.delibera-unlike-count').show(); - jQuery(container).remove(); - } - ); - }); + + jQuery(".delibera-like").click(function() { + var container = jQuery(this); + if(jQuery(this).children('input[name="object_id"]').val() > 0) + { + jQuery.post( + delibera.ajax_url, + { + action : "delibera_curtir", + like_id : jQuery(this).children('input[name="object_id"]').val(), + type : jQuery(this).children('input[name="type"]').val(), + }, + function(response) { + container.find('.delibera-icon-thumbs-up').toggleClass('active'); + jQuery(container).children('.delibera-like-count').text(response); + if(parseInt(jQuery(container).children('.delibera-like-count').text()) > 0) + { + jQuery(container).children('.delibera-like-count').show(); + } + else + { + jQuery(container).children('.delibera-like-count').hide(); + } + } + ); + } + }); + + jQuery(".delibera-unlike").click(function() { + var container = jQuery(this); + if(jQuery(this).children('input[name="object_id"]').val() > 0) + { + jQuery.post( + delibera.ajax_url, + { + action : "delibera_discordar", + like_id : jQuery(this).children('input[name="object_id"]').val(), + type : jQuery(this).children('input[name="type"]').val(), + }, + function(response) { + container.find('.delibera-icon-thumbs-down').toggleClass('active') + jQuery(container).children('.delibera-unlike-count').text(response); + if(parseInt(jQuery(container).children('.delibera-unlike-count').text(), 10) > 0) + { + jQuery(container).children('.delibera-unlike-count').show(); + } + else + { + jQuery(container).children('.delibera-unlike-count').hide(); + } + } + ); + } + }); }); diff --git a/js/scripts.js b/js/scripts.js index 3a8b316..656ab21 100644 --- a/js/scripts.js +++ b/js/scripts.js @@ -1,18 +1,11 @@ jQuery(document).ready(function() { - jQuery('.label-voto').expander({ - slicePoint: 70, - expandText: '[leia o encaminhamento inteiro]', - expandPrefix: '... ', - userCollapseText: '[fechar visão completa]' - }); - if (window.location.href.indexOf('#comment') > 0 && document.referrer == window.location.href.substring(0,window.location.href.indexOf('#'))) { jQuery("#mensagem-confirma-voto").show(); jQuery("#mensagem-confirma-voto").fadeOut(5000); } - + //Abrir hide de comentário se tiver no link var hash = location.hash.slice(1); if(hash != null && hash != '') @@ -27,6 +20,8 @@ jQuery(document).ready(function() jQuery(window).resize(function(){ delibera_setpdf_size("#pauta-pdf-content"); }); + if (typeof Socialite != 'undefined') + Socialite.load(); }); function delibera_setpdf_size(element) { @@ -37,12 +32,21 @@ function delibera_showhide(comment) { // Hide the "view" div. jQuery('#showhide-comment-part-text-'+comment).slideToggle(400); jQuery('#showhide_comment'+comment).slideToggle(400); - + return false; } -function delibera_edit_comment_show(comment) +function delibera_edit_comment_show(button, comment) { jQuery('#delibera-comment-text-'+comment).toggle(); jQuery('#delibera-edit-comment-'+comment).toggle(); + jQuery('#submit-edit-comment-button-'+comment).toggle(); + if(jQuery(button).html() == '') + { + jQuery(button).html(''); // TODO translate + } + else + { + jQuery(button).html(''); // TODO translate + } } diff --git a/js/socialite.min.js b/js/socialite.min.js new file mode 100755 index 0000000..f682f92 --- /dev/null +++ b/js/socialite.min.js @@ -0,0 +1,7 @@ +/*! + * Socialite v2.0 + * http://socialitejs.com + * Copyright (c) 2011 David Bushell + * Dual-licensed under the BSD or MIT licenses: http://socialitejs.com/license.txt + */ +window.Socialite=(function(f,g,d){var e=0,a=[],i={},h={},b=/^($|loaded|complete)/,j=f.encodeURIComponent;var c={settings:{},trim:function(k){return k.trim?k.trim():k.replace(/^\s+|\s+$/g,"")},hasClass:function(k,l){return(" "+k.className+" ").indexOf(" "+l+" ")!==-1},addClass:function(k,l){if(!c.hasClass(k,l)){k.className=(k.className==="")?l:k.className+" "+l}},removeClass:function(k,l){k.className=c.trim(" "+k.className+" ".replace(" "+l+" "," "))},extendObject:function(o,n,k){for(var m in n){var l=o[m]!==d;if(l&&typeof n[m]==="object"){c.extendObject(o[m],n[m],k)}else{if(k||!l){o[m]=n[m]}}}},getElements:function(l,p){var k=0,o=[],n=!!l.getElementsByClassName,m=n?l.getElementsByClassName(p):l.getElementsByTagName("*");for(;k\n" +"Language-Team: TGMPA\n" +"Language: en_US\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.7.5\n" +"X-Poedit-Basepath: ..\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;" +"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;" +"_nx_noop:3c,1,2;__ngettext_noop:1,2\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Poedit-SearchPath-0: .\n" +"X-Poedit-SearchPathExcluded-0: *.js\n" +"X-Poedit-SearchPathExcluded-1: example.php\n" + +#: class-tgm-plugin-activation.php:303 +msgid "Install Required Plugins" +msgstr "" + +#: class-tgm-plugin-activation.php:304 +msgid "Install Plugins" +msgstr "" + +#: class-tgm-plugin-activation.php:305 +#, php-format +msgid "Installing Plugin: %s" +msgstr "" + +#: class-tgm-plugin-activation.php:306 +msgid "Something went wrong with the plugin API." +msgstr "" + +#: class-tgm-plugin-activation.php:308 +#, php-format +msgid "This theme requires the following plugin: %1$s." +msgid_plural "This theme requires the following plugins: %1$s." +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:313 +#, php-format +msgid "This theme recommends the following plugin: %1$s." +msgid_plural "This theme recommends the following plugins: %1$s." +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:318 +#, php-format +msgid "" +"Sorry, but you do not have the correct permissions to install the %1$s " +"plugin." +msgid_plural "" +"Sorry, but you do not have the correct permissions to install the %1$s " +"plugins." +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:323 +#, php-format +msgid "" +"The following plugin needs to be updated to its latest version to ensure " +"maximum compatibility with this theme: %1$s." +msgid_plural "" +"The following plugins need to be updated to their latest version to ensure " +"maximum compatibility with this theme: %1$s." +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:328 +#, php-format +msgid "There is an update available for: %1$s." +msgid_plural "There are updates available for the following plugins: %1$s." +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:333 +#, php-format +msgid "" +"Sorry, but you do not have the correct permissions to update the %1$s plugin." +msgid_plural "" +"Sorry, but you do not have the correct permissions to update the %1$s " +"plugins." +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:338 +#, php-format +msgid "The following required plugin is currently inactive: %1$s." +msgid_plural "The following required plugins are currently inactive: %1$s." +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:343 +#, php-format +msgid "The following recommended plugin is currently inactive: %1$s." +msgid_plural "The following recommended plugins are currently inactive: %1$s." +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:348 +#, php-format +msgid "" +"Sorry, but you do not have the correct permissions to activate the %1$s " +"plugin." +msgid_plural "" +"Sorry, but you do not have the correct permissions to activate the %1$s " +"plugins." +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:353 +msgid "Begin installing plugin" +msgid_plural "Begin installing plugins" +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:358 +msgid "Begin updating plugin" +msgid_plural "Begin updating plugins" +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:363 +msgid "Begin activating plugin" +msgid_plural "Begin activating plugins" +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:368 +msgid "Return to Required Plugins Installer" +msgstr "" + +#: class-tgm-plugin-activation.php:369 +msgid "Return to the dashboard" +msgstr "" + +#: class-tgm-plugin-activation.php:370 class-tgm-plugin-activation.php:3016 +msgid "Plugin activated successfully." +msgstr "" + +#: class-tgm-plugin-activation.php:371 class-tgm-plugin-activation.php:2837 +msgid "The following plugin was activated successfully:" +msgid_plural "The following plugins were activated successfully:" +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:372 +#, php-format +msgid "No action taken. Plugin %1$s was already active." +msgstr "" + +#: class-tgm-plugin-activation.php:373 +#, php-format +msgid "" +"Plugin not activated. A higher version of %s is needed for this theme. " +"Please update the plugin." +msgstr "" + +#: class-tgm-plugin-activation.php:374 +#, php-format +msgid "All plugins installed and activated successfully. %1$s" +msgstr "" + +#: class-tgm-plugin-activation.php:375 +msgid "Dismiss this notice" +msgstr "" + +#: class-tgm-plugin-activation.php:376 +msgid "Please contact the administrator of this site for help." +msgstr "" + +#: class-tgm-plugin-activation.php:494 +msgid "This plugin needs to be updated to be compatible with your theme." +msgstr "" + +#: class-tgm-plugin-activation.php:495 +msgid "Update Required" +msgstr "" + +#: class-tgm-plugin-activation.php:612 +msgid "Set the parent_slug config variable instead." +msgstr "" + +#: class-tgm-plugin-activation.php:811 class-tgm-plugin-activation.php:3434 +msgid "Return to the Dashboard" +msgstr "" + +#: class-tgm-plugin-activation.php:926 +msgid "" +"The remote plugin package does not contain a folder with the desired slug " +"and renaming did not work." +msgstr "" + +#: class-tgm-plugin-activation.php:926 class-tgm-plugin-activation.php:930 +msgid "" +"Please contact the plugin provider and ask them to package their plugin " +"according to the WordPress guidelines." +msgstr "" + +#: class-tgm-plugin-activation.php:930 +msgid "" +"The remote plugin package consists of more than one file, but the files are " +"not packaged in a folder." +msgstr "" + +#: class-tgm-plugin-activation.php:1115 class-tgm-plugin-activation.php:2833 +msgctxt "plugin A *and* plugin B" +msgid "and" +msgstr "" + +#: class-tgm-plugin-activation.php:1901 +#, php-format +msgctxt "%s = version number" +msgid "TGMPA v%s" +msgstr "" + +#: class-tgm-plugin-activation.php:2182 +msgid "Required" +msgstr "" + +#: class-tgm-plugin-activation.php:2185 +msgid "Recommended" +msgstr "" + +#: class-tgm-plugin-activation.php:2202 +msgid "WordPress Repository" +msgstr "" + +#: class-tgm-plugin-activation.php:2206 +msgid "External Source" +msgstr "" + +#: class-tgm-plugin-activation.php:2210 +msgid "Pre-Packaged" +msgstr "" + +#: class-tgm-plugin-activation.php:2229 +msgid "Not Installed" +msgstr "" + +#: class-tgm-plugin-activation.php:2233 +msgid "Installed But Not Activated" +msgstr "" + +#: class-tgm-plugin-activation.php:2235 +msgid "Active" +msgstr "" + +#: class-tgm-plugin-activation.php:2241 +msgid "Required Update not Available" +msgstr "" + +#: class-tgm-plugin-activation.php:2244 +msgid "Requires Update" +msgstr "" + +#: class-tgm-plugin-activation.php:2247 +msgid "Update recommended" +msgstr "" + +#: class-tgm-plugin-activation.php:2255 +#, php-format +msgctxt "%1$s = install status, %2$s = update status" +msgid "%1$s, %2$s" +msgstr "" + +#: class-tgm-plugin-activation.php:2304 +#, php-format +msgctxt "plugins" +msgid "All (%s)" +msgid_plural "All (%s)" +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:2308 +#, php-format +msgid "To Install (%s)" +msgid_plural "To Install (%s)" +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:2312 +#, php-format +msgid "Update Available (%s)" +msgid_plural "Update Available (%s)" +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:2316 +#, php-format +msgid "To Activate (%s)" +msgid_plural "To Activate (%s)" +msgstr[0] "" +msgstr[1] "" + +#: class-tgm-plugin-activation.php:2409 +msgctxt "as in: \"version nr unknown\"" +msgid "unknown" +msgstr "" + +#: class-tgm-plugin-activation.php:2417 +msgid "Installed version:" +msgstr "" + +#: class-tgm-plugin-activation.php:2425 +msgid "Minimum required version:" +msgstr "" + +#: class-tgm-plugin-activation.php:2437 +msgid "Available version:" +msgstr "" + +#: class-tgm-plugin-activation.php:2461 +#, php-format +msgid "" +"No plugins to install, update or activate. Return to the " +"Dashboard" +msgstr "" + +#: class-tgm-plugin-activation.php:2477 +msgid "Plugin" +msgstr "" + +#: class-tgm-plugin-activation.php:2478 +msgid "Source" +msgstr "" + +#: class-tgm-plugin-activation.php:2479 +msgid "Type" +msgstr "" + +#: class-tgm-plugin-activation.php:2483 +msgid "Version" +msgstr "" + +#: class-tgm-plugin-activation.php:2484 +msgid "Status" +msgstr "" + +#: class-tgm-plugin-activation.php:2508 +#, php-format +msgctxt "%2$s = plugin name in screen reader markup" +msgid "Install %2$s" +msgstr "" + +#: class-tgm-plugin-activation.php:2514 +#, php-format +msgctxt "%2$s = plugin name in screen reader markup" +msgid "Update %2$s" +msgstr "" + +#: class-tgm-plugin-activation.php:2520 +#, php-format +msgctxt "%2$s = plugin name in screen reader markup" +msgid "Activate %2$s" +msgstr "" + +#: class-tgm-plugin-activation.php:2591 +msgid "Upgrade message from the plugin author:" +msgstr "" + +#: class-tgm-plugin-activation.php:2624 +msgid "Install" +msgstr "" + +#: class-tgm-plugin-activation.php:2630 +msgid "Update" +msgstr "" + +#: class-tgm-plugin-activation.php:2633 +msgid "Activate" +msgstr "" + +#: class-tgm-plugin-activation.php:2694 +msgid "No plugins are available to be installed at this time." +msgstr "" + +#: class-tgm-plugin-activation.php:2696 +msgid "No plugins are available to be updated at this time." +msgstr "" + +#: class-tgm-plugin-activation.php:2819 +msgid "No plugins are available to be activated at this time." +msgstr "" + +#: class-tgm-plugin-activation.php:3015 +msgid "Plugin activation failed." +msgstr "" + +#: class-tgm-plugin-activation.php:3354 +#, php-format +msgid "Updating Plugin %1$s (%2$d/%3$d)" +msgstr "" + +#: class-tgm-plugin-activation.php:3358 +#, php-format +msgid "An error occurred while installing %1$s: %2$s." +msgstr "" + +#: class-tgm-plugin-activation.php:3359 +#, php-format +msgid "The installation of %1$s failed." +msgstr "" + +#: class-tgm-plugin-activation.php:3363 +msgid "" +"The installation and activation process is starting. This process may take a " +"while on some hosts, so please be patient." +msgstr "" + +#: class-tgm-plugin-activation.php:3364 +#, php-format +msgid "%1$s installed and activated successfully." +msgstr "" + +#: class-tgm-plugin-activation.php:3364 class-tgm-plugin-activation.php:3371 +msgid "Show Details" +msgstr "" + +#: class-tgm-plugin-activation.php:3364 class-tgm-plugin-activation.php:3371 +msgid "Hide Details" +msgstr "" + +#: class-tgm-plugin-activation.php:3365 +msgid "All installations and activations have been completed." +msgstr "" + +#: class-tgm-plugin-activation.php:3366 +#, php-format +msgid "Installing and Activating Plugin %1$s (%2$d/%3$d)" +msgstr "" + +#: class-tgm-plugin-activation.php:3370 +msgid "" +"The installation process is starting. This process may take a while on some " +"hosts, so please be patient." +msgstr "" + +#: class-tgm-plugin-activation.php:3371 +#, php-format +msgid "%1$s installed successfully." +msgstr "" + +#: class-tgm-plugin-activation.php:3372 +msgid "All installations have been completed." +msgstr "" + +#: class-tgm-plugin-activation.php:3373 +#, php-format +msgid "Installing Plugin %1$s (%2$d/%3$d)" +msgstr "" diff --git a/mailer/delibera_mailer.php b/mailer/delibera_mailer.php index aacb31b..1068c52 100644 --- a/mailer/delibera_mailer.php +++ b/mailer/delibera_mailer.php @@ -284,7 +284,7 @@ function delibera_mailer_new_comment($comment_post_ID, $comment, $user, $deliber if ( !comments_open($comment_post_ID) ) { do_action('comment_closed', $comment_post_ID); - $erros[] = __('Sorry, comments are closed for this item.'); + $errors[] = __('Sorry, comments are closed for this item.'); } elseif ( 'trash' == $status ) { do_action('comment_on_trash', $comment_post_ID); exit; @@ -314,7 +314,7 @@ function delibera_mailer_new_comment($comment_post_ID, $comment, $user, $deliber $comment_type = ''; if ( '' == $comment_content ) - $erros[] = ( __('ERROR: please type a comment.') ); + $errors[] = ( __('ERROR: please type a comment.') ); $comment_parent = isset($comment_parent) ? absint($comment_parent) : 0; diff --git a/modules/discussion/discussion.php b/modules/discussion/discussion.php new file mode 100644 index 0000000..547868d --- /dev/null +++ b/modules/discussion/discussion.php @@ -0,0 +1,281 @@ + method + * @var array + */ + protected $shorcodes = array('delibera_lista_de_pautas' => 'replacePautas' ); + + /** + * Config days to make new deadline + * @var array + */ + protected $days = array('dias_discussao'); + + /** + * Display priority + * @var int + */ + public $priority = 2; + + /** + * Register Tax for the module + */ + public function registerTax() + { + if(term_exists('discussao', 'situacao', null) == false) + { + delibera_insert_term('Pauta em discussão', 'situacao', array( + 'description'=> 'Pauta em Discussão', + 'slug' => 'discussao', + ), + array( + 'qtrans_term_pt' => 'Pauta em discussão', + 'qtrans_term_en' => 'Agenda en discusión', + 'qtrans_term_es' => 'Topic under discussion', + ) + ); + } + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::initModule() + */ + public function initModule($post_id) + { + wp_set_object_terms($post_id, 'discussao', 'situacao', false); + $this->newDeadline($post_id); + } + + /** + * Append configurations + * @param array $opts + */ + public function getMainConfig($opts) + { + $opts['pauta_suporta_encaminhamento'] = 'S'; + $opts['dias_discussao'] = '5'; + return $opts; + } + + /** + * Array to show on config page + * @param array $rows + */ + public function configPageRows($rows, $opt) + { + $rows[] = array( + "id" => "dias_discussao", + "label" => __('Dias para discussão da pauta:', 'delibera'), + "content" => '' + ); + $rows[] = array( + "id" => "pauta_suporta_encaminhamento", + "label" => __('Pautas suportam sugestão de encaminhamento?', 'delibera'), + "content" => '', + ); + return $rows; + } + + /** + * Label to apply to button + * @param unknown $situation + */ + public function situationButtonText($situation) + { + if($situation == 'discussao') + { + return __('Discutir', 'delibera'); + } + + return $situation; + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::generateDeadline() + */ + public function generateDeadline($options_plugin_delibera) + { + $dias_discussao = intval(htmlentities($options_plugin_delibera['dias_discussao'])); + + $prazo_discussao_sugerido = strtotime("+$dias_discussao days", delibera_tratar_data(\Delibera\Flow::getLastDeadline('discussao'))); + return date('d/m/Y', $prazo_discussao_sugerido); + } + + /** + * + * Post Meta Fields display + * + * @param \WP_Post $post + * @param array $custom post custom fields + * @param array $options_plugin_delibera Delibera options array + * @param WP_Term $situacao + * @param bool $disable_edicao + * + */ + public function topicMeta($post, $custom, $options_plugin_delibera, $situacao, $disable_edicao) + { + $prazo_discussao = $this->generateDeadline($options_plugin_delibera); + + if(!($post->post_status == 'draft' || + $post->post_status == 'auto-draft' || + $post->post_status == 'pending')) + { + $prazo_discussao = array_key_exists("prazo_discussao", $custom) ? $custom["prazo_discussao"][0] : $prazo_discussao; + } + + ?> +

+ + name="prazo_discussao" class="prazo_discussao widefat hasdatepicker" value=""/> +

+ $value) // Buscar dados + { + if(get_post_meta($postID, $key, true)) // Se já existe + { + update_post_meta($postID, $key, $value); // Atualiza + } + else + { + add_post_meta($postID, $key, $value, true); // Senão, cria + } + } + + } + + function checkPostData($errors, $opt, $autosave) + { + $value = $_POST['prazo_discussao']; + $valida = delibera_tratar_data($value); + if(!$autosave && (empty($value) || $valida === false || $valida < 1) ) + { + $errors[] = __("É necessário definir corretamente o prazo de discussão", "delibera"); + } + return $errors; + } + + public function replacePautas($matches) + { + $temp = explode(',', $matches[1]); // configurações da shorttag + $count = count($temp); + + $param = array(); // TODO Tratar Parametros + + $html = self::getPautas($param); + $wp_posts = $html; + global $post; + $old = $post; + echo '
'; + foreach ( $wp_posts as $wp_post ) + { + $post = $wp_post; + include 'delibera_loop_pauta.php'; + } + echo '
'; + $post = $old; + + return ''; // Retornar código da representação + + } + + public function savePostMetas($events_meta, $opt, $post_id = false) + { + if(array_key_exists('prazo_discussao', $_POST)) + { + $events_meta['prazo_discussao'] = sanitize_text_field($_POST['prazo_discussao']); + } + + return $events_meta; + } + + public function createPautaAtFront($opt) + { + $data_externa = trim($opt['data_fixa_nova_pauta_externa']); + if ( !empty($data_externa) && strlen($data_externa) == 10) { + $prazo_discussao = \DateTime::createFromFormat('d/m/Y', $data_externa); + $_POST['prazo_discussao'] = $prazo_discussao->format('d/m/Y'); + } else { + $_POST['prazo_discussao'] = $this->generateDeadline($opt); + } + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::deadline() + */ + public static function deadline($args) + { + $post_id = $args['post_ID']; + $situacao = delibera_get_situacao($post_id); + if($situacao->slug == 'discussao') + { + if(count(delibera_get_comments_encaminhamentos($post_id)) > 0) + { + \Delibera\Flow::next($post_id); + + if(has_action('delibera_discussao_concluida')) + { + do_action('delibera_discussao_concluida', $post_id); + } + } + else + { + $current = \Delibera\Flow::getCurrentModule($post_id); + $current->newDeadline($post_id, false); + } + } + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::getCommentListLabel() + */ + public function getCommentListLabel() + { + return __('Discussão sobre a Pauta', 'delibera'); + } + +} +$DeliberaDiscussion = new \Delibera\Modules\Discussion(); + + diff --git a/modules/modulebase.php b/modules/modulebase.php new file mode 100644 index 0000000..9f1ad26 --- /dev/null +++ b/modules/modulebase.php @@ -0,0 +1,285 @@ + method + */ + protected $shortcodes = array(); + + /** + * Config days to make new deadline + * @var array + */ + protected $days = array(); + + /** + * Display priority + * @var int + */ + public $priority = 0; + + public function __construct() + { + add_filter('delibera_register_flow_module', array($this, 'registerFlowModule'), $this->priority); + add_action('delibera_situacao_register', array($this, 'registerTax')); + add_filter('delibera_get_config', array($this, 'getMainConfig')); + //add_filter('delivera_config_page_rows', array($this, 'configPageRows'), 10, 2); + add_filter('delibera_situation_button_text', array($this, 'situationButtonText')); + //add_action('delibera_topic_meta', array($this, 'topicMeta'), 10, 5); + add_action('delibera_publish_pauta', array($this, 'publishPauta'), 10, 2); + //add_filter('delibera_check_post_data', array($this, 'checkPostData'), 10, 3); + //add_filter('delibera_save_post_metas', array($this, 'savePostMetas'), 10, 2); + add_action('delibera_create_pauta_frontend', array($this, 'createPautaAtFront')); + + foreach ($this->shortcodes as $name => $function) + { + add_shortcode( $name, array( $this, $function )); + } + } + + /** + * Register situacao objects for flow treat + * @param array $modules + */ + public function registerFlowModule($modules) + { + foreach ($this->flows as $situacao) + { + $modules[$situacao] = $this; + } + return $modules; + } + + /** + * Register Tax for the module + */ + abstract public function registerTax(); + + /** + * Initial situation on module begins + * @param int $post_id + */ + abstract public function initModule($post_id); + + /** + * Append configurations + * @param array $opts + */ + abstract public function getMainConfig($opts); + + /** + * Array to show on config page + * @param array $rows + */ + abstract public function configPageRows($rows, $opt); + + /** + * Label to apply to button + * @param unknown $situation + */ + abstract public function situationButtonText($situation); + + /** + * + * Post Meta Fields display + * + * @param \WP_Post $post + * @param array $custom post custom fields + * @param array $options_plugin_delibera Delibera options array + * @param WP_Term $situacao + * @param bool $disable_edicao + * + */ + abstract public function topicMeta($post, $custom, $options_plugin_delibera, $situacao, $disable_edicao); + + /** + * When the topic is published + * @param int $postID + * @param array $opt delibera configs + */ + abstract public function publishPauta($postID, $opt); + + /** + * Validate topic required data + * @param array $errors erros report array + * @param array $opt Delibera configs + * @param bool $autosave is autosave? + * @return array erros report array append if needed + */ + abstract public function checkPostData($errors, $opt, $autosave); + + /** + * Save topic metadata + * @param array $events_meta + * @param array $opt Delibera configs + * + * @return array events_meta to be save on the topic + */ + abstract public function savePostMetas($events_meta, $opt, $post_id = false); + + /** + * Treat postback of frotend topic + * @param array $opt Delibera configs + */ + abstract public function createPautaAtFront($opt); + + /** + * Generate deadline date + * @param array $options_plugin_delibera Delibera configs + */ + abstract public function generateDeadline($options_plugin_delibera); + + /** + * Return this module deadline for the current post + * @param int $post_id + * @return mixed|string deadline date + */ + public function getDeadline($post_id = false) + { + if( empty($this->prazo_meta) ) return -1; // Do not have prazo + + if($post_id == false) + { + $post_id = get_the_ID(); + } + if(is_array($this->prazo_meta)) + { + $situacao = delibera_get_situacao($post_id); + $situacao = $situacao->slug; + + return !empty($situacao) && array_key_exists($situacao, $this->prazo_meta) ? get_post_meta($post_id, $this->prazo_meta[$situacao], true) : $this->generateDeadline(delibera_get_config()); + } + $deadline = get_post_meta($post_id, $this->prazo_meta, true); + + if(empty($deadline)) + { + return $this->generateDeadline(delibera_get_config()); + } + + return $deadline; + } + + /** + * + * Retorn topic at module situation + * @param array $filtro + */ + public static function getPautas($filtro = array()) + { + return delibera_get_pautas_em($filtro, $this->situacao); + } + + /** + * Trigger module deadline event + * @param array $args in form: array('post_id' => $post_id, 'prazo' => $prazo) + */ + abstract public static function deadline($args); + + /** + * Create new deadline events calendar + * @param int $post_id + * @param int $appendDays number of day to append or false to get config option default + */ + public function newDeadline($post_id, $appendDays = 0) + { + if(get_post_status($post_id) == 'publish') + { + if($appendDays == false) + { + $opts = delibera_get_config(); + $appendDays = $opts['dias_novo_prazo']; + } + $prazos = $this->prazo_meta; + if(is_string($this->prazo_meta)) + { + $prazos = array($this->prazo_meta); + } + foreach ($prazos as $prazo) + { + $prazo_date = get_post_meta($post_id, $prazo, true); + if( ! empty($prazo_date) ) + { + if($appendDays > 0) + { + $dateTime = \DateTime::createFromFormat('d/m/Y', $prazo_date); + $dateTime->add(new \DateInterval('P'.$appendDays.'D')); + $prazo_date = $dateTime->format('d/m/Y'); + update_post_meta($post_id, $prazo, $prazo_date); + } + + \Delibera\Cron::del($post_id, array(get_class($this), 'deadline')); + \Delibera\Cron::del($post_id, 'delibera_notificar_fim_prazo'); + + $cron = get_option('delibera-cron'); + + \Delibera\Cron::add( + delibera_tratar_data($prazo_date), + array(get_class($this), 'deadline'), + array( + 'post_ID' => $post_id, + 'prazo' => $prazo_date + ) + ); + \Delibera\Cron::add( + strtotime("-1 day", delibera_tratar_data($prazo_date)), + 'delibera_notificar_fim_prazo', + array( + 'post_ID' => $post_id, + $prazo => $prazo_date + ) + ); + } + else + { + /*$msn = "empty date on $post_id: ".print_r($this, true)."Dates: ".print_r($prazos, true); + throw new \Exception($msn);*/ + // empty date! Meaning: no activated deadline, then do nothing + } + } + } + } + + public function getDeadlineDays() + { + $days = 0; + $opt = delibera_get_config(); + foreach ($this->days as $day) + { + if(array_key_exists($day, $opt)) + { + $days += $opt[$day]; + } + } + return $days; + } + + /** + * Return comment list Title + */ + abstract public function getCommentListLabel(); + +} \ No newline at end of file diff --git a/modules/rapporteur/rapporteur.php b/modules/rapporteur/rapporteur.php new file mode 100644 index 0000000..9bc16ad --- /dev/null +++ b/modules/rapporteur/rapporteur.php @@ -0,0 +1,314 @@ + deadline_a + */ + protected $prazo_meta = array('relatoria' => 'prazo_relatoria', 'eleicao_relator' => 'prazo_eleicao_relator'); + + /** + * Config days to make new deadline + * @var array + */ + protected $days = array('dias_relatoria', 'dias_votacao_relator'); + + /** + * Display priority + * @var int + */ + public $priority = 3; + + /** + * Register Tax for the module + */ + public function registerTax() + { + /*if(term_exists('eleicao_redator', 'situacao', null) == false) // TODO create election + { + delibera_insert_term('Regime de Votação de Relator', 'situacao', array( + 'description'=> 'Pauta em Eleição de Relator', + 'slug' => 'eleicao_redator', + ), + array( + 'qtrans_term_pt' => 'Regime de Votação de Relator', + 'qtrans_term_en' => 'Election of Rapporteur', + 'qtrans_term_es' => 'Elección del Relator', + ) + ); + }*/ + + if(term_exists('relatoria', 'situacao', null) == false) + { + delibera_insert_term('Relatoria', 'situacao', array( + 'description'=> 'Pauta com encaminhamentos em Relatoria', + 'slug' => 'relatoria', + ), + array( + 'qtrans_term_pt' => 'Relatoria', + 'qtrans_term_en' => 'Rapporteur', + 'qtrans_term_es' => 'Relator', + ) + ); + } + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::initModule() + */ + public function initModule($post_id) + { + $opts = delibera_get_config(); + if($opts['eleicao_relator'] == 'S') + { + wp_set_object_terms($post_id, 'eleicao_redator', 'situacao', false); //Mudar situação para Votação + } + else + { + wp_set_object_terms($post_id, 'relatoria', 'situacao', false); //Mudar situação para Votação + } + $this->newDeadline($post_id); + } + + /** + * Append configurations + * @param array $opts + */ + public function getMainConfig($opts) + { + $opts['dias_relatoria'] = '2'; + $opts['eleicao_relator'] = 'N'; + $opts['dias_votacao_relator'] = '2'; + return $opts; + } + + /** + * Array to show on config page + * @param array $rows + */ + public function configPageRows($rows, $opt) + { + $rows[] = array( + "id" => "dias_relatoria", + "label" => __('Prazo para relatoria:', 'delibera'), + "content" => '' + ); + /*$rows[] = array( + "id" => "eleicao_relator", + "label" => __('Necessário eleição de relator?', 'delibera'), + "content" => '' + ); + $rows[] = array( + "id" => "dias_votacao_relator", + "label" => __('Prazo para eleição de relator:', 'delibera'), + "content" => '' + );*/ + return $rows; + } + + /** + * Label to apply to button + * @param unknown $situation + */ + public function situationButtonText($situation) + { + if($situation == 'relatoria') + { + return __('Relatar', 'delibera'); + } + + return $situation; + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::generateDeadline() + */ + public function generateDeadline($options_plugin_delibera) + { + $dias_relatoria = intval(htmlentities($options_plugin_delibera['dias_relatoria'])); + $dias_votacao_relator = intval(htmlentities($options_plugin_delibera['dias_votacao_relator'])); + + //$dias_relatoria += $dias_discussao; // TODO issue #50 + if($options_plugin_delibera['eleicao_relator'] == "S") // Adiciona prazo de vatacao relator se for necessário + { + $dias_relatoria += $dias_votacao_relator; + } + + $prazo_eleicao_relator_sugerido = strtotime("+$dias_votacao_relator days", delibera_tratar_data(\Delibera\Flow::getLastDeadline('relatoria'))); + $prazo_relatoria_sugerido = strtotime("+$dias_relatoria days", delibera_tratar_data(\Delibera\Flow::getLastDeadline('relatoria'))); + + $prazo_eleicao_relator = date('d/m/Y', $prazo_eleicao_relator_sugerido); + + return date('d/m/Y', $prazo_relatoria_sugerido); + + } + + /** + * + * Post Meta Fields display + * + * @param \WP_Post $post + * @param array $custom post custom fields + * @param array $options_plugin_delibera Delibera options array + * @param WP_Term $situacao + * @param bool $disable_edicao + * + */ + public function topicMeta($post, $custom, $options_plugin_delibera, $situacao, $disable_edicao) + { + $dias_votacao_relator = intval(htmlentities($options_plugin_delibera['dias_votacao_relator'])); + + $prazo_eleicao_relator_sugerido = strtotime("+$dias_votacao_relator days", delibera_tratar_data(\Delibera\Flow::getLastDeadline('relatoria', $post->ID))); + + $prazo_eleicao_relator = date('d/m/Y', $prazo_eleicao_relator_sugerido); + + $prazo_relatoria = $this->generateDeadline($options_plugin_delibera); + + if(!($post->post_status == 'draft' || + $post->post_status == 'auto-draft' || + $post->post_status == 'pending')) + { + $prazo_eleicao_relator = array_key_exists("prazo_eleicao_relator", $custom) ? $custom["prazo_eleicao_relator"][0] : $prazo_eleicao_relator; + $prazo_relatoria = array_key_exists("prazo_relatoria", $custom) ? $custom["prazo_relatoria"][0] : $prazo_relatoria; + } + + if($options_plugin_delibera['eleicao_relator'] == "S") + { //TODO remove display none when have election + ?> +

+ + name="prazo_eleicao_relator" class="prazo_eleicao_relator widefat hasdatepicker" value=""/> +

+ +

+ + name="prazo_relatoria" class="prazo_relatoria widefat hasdatepicker" value=""/> +

+ generateDeadline($opt); + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::deadline() + */ + public static function deadline($args) + { + $situacao = delibera_get_situacao($args['post_ID']); + $post_id = $args['post_ID']; + if($situacao->slug == 'relatoria') + { + if(count(delibera_get_comments_encaminhamentos($post_id)) > 0) + { + //wp_set_object_terms($post_id, 'emvotacao', 'situacao', false); //Mudar situação para Votação + \Delibera\Flow::next($post_id); + + //delibera_notificar_situacao($post_id); + + if(has_action('delibera_relatoria_concluida')) + { + do_action('delibera_relatoria_concluida', $post_id); + } + } + else + { + $rapporteur = \Delibera\Flow::getCurrentModule($post_id); + $rapporteur->newDeadline($post_id, false); + } + } + elseif($situacao->slug == 'eleicao_relator') + { + //TODO eleicao relator deadline + wp_set_object_terms($post_id, 'relatoria', 'situacao', false); + $this->newDeadline($post_id); + } + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::getCommentListLabel() + */ + public function getCommentListLabel() + { + return __('Relatoria da Pauta', 'delibera'); + } + +} +$DeliberaRapporteur = new \Delibera\Modules\Rapporteur(); + + diff --git a/modules/result/result.php b/modules/result/result.php new file mode 100644 index 0000000..59d0a07 --- /dev/null +++ b/modules/result/result.php @@ -0,0 +1,233 @@ + method + */ + protected $shortcodes = array('delibera_lista_de_resolucoes' => 'replaceResolucoes' ); + + /** + * Display priority + * @var int + */ + public $priority = 5; + + /** + * Register Tax for the module + */ + public function registerTax() + { + if(term_exists('comresolucao', 'situacao', null) == false) + { + delibera_insert_term('Resolução', 'situacao', array( + 'description'=> 'Pauta com resoluções aprovadas', + 'slug' => 'comresolucao', + ), + array( + 'qtrans_term_pt' => 'Resolução', + 'qtrans_term_en' => 'Resolution', + 'qtrans_term_es' => 'Resolución', + ) + ); + } + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::initModule() + */ + public function initModule($post_id) + { + wp_set_object_terms($post_id, 'comresolucao', 'situacao', false); + } + + /** + * Append configurations + * @param array $opts + */ + public function getMainConfig($opts) + { + return $opts; + } + + /** + * Array to show on config page + * @param array $rows + */ + public function configPageRows($rows, $opt) + { + return $rows; + } + + /** + * Label to apply to button + * @param unknown $situation + */ + public function situationButtonText($situation) + { + if($situation == 'comresolucao') + { + return '';//__('', 'delibera'); + } + + return $situation; + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::generateDeadline() + */ + public function generateDeadline($options_plugin_delibera) + { + //No deadline + return false; + } + + /** + * + * Post Meta Fields display + * + * @param \WP_Post $post + * @param array $custom post custom fields + * @param array $options_plugin_delibera Delibera options array + * @param WP_Term $situacao + * @param bool $disable_edicao + * + */ + public function topicMeta($post, $custom, $options_plugin_delibera, $situacao, $disable_edicao) + { + + } + + /** + * When the topic is published + * @param int $postID + * @param array $opt delibera configs + * @param bool $alterar has been altered + */ + public function publishPauta($postID, $opt) + { + + } + + /** + * Validate topic required data + * @param array $errors erros report array + * @param array $opt Delibera configs + * @param bool $autosave is autosave? + * @return array erros report array append if needed + */ + public function checkPostData($errors, $opt, $autosave) + { + + return $errors; + } + + /** + * + * Retorna pautas já resolvidas + * @param array $filtro + */ + public static function getResolucoes($filtro = array()) + { + return self::getPautas($filtro); + } + + /** + * Shortcut for list of Results + * @param array $matches regext results + * @return string + */ + public function replaceResolucoes($matches) + { + $temp = explode(',', $matches[1]); // configurações da shorttag + $count = count($temp); + + $param = array(); // TODO Tratar Parametros + + $html = $this->getResolucoes($param); + $wp_posts = $html; + global $post; + $old = $post; + echo '
'; + foreach ( $wp_posts as $wp_post ) + { + $post = $wp_post; + include 'delibera_loop_pauta.php'; + } + echo '
'; + $post = $old; + + return ''; // Retornar código da representação + } + + /** + * Save topic metadata + * @param array $events_meta + * @param array $opt Delibera configs + * + * @return array events_meta to be save on the topic + */ + public function savePostMetas($events_meta, $opt, $post_id = false) + { + return $events_meta; + } + + /** + * Treat postback of frotend topic + * @param array $opt Delibera configs + */ + public function createPautaAtFront($opt) + { + + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::deadline() + */ + public static function deadline($args) + { + $post_id = $args['post_ID']; + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::getCommentListLabel() + */ + public function getCommentListLabel() + { + return __('Resolução da Pauta', 'delibera'); + } + +} +$DeliberaResult = new \Delibera\Modules\Result(); + + diff --git a/modules/validation/validation.php b/modules/validation/validation.php new file mode 100644 index 0000000..404d6a9 --- /dev/null +++ b/modules/validation/validation.php @@ -0,0 +1,350 @@ + method + */ + protected $shortcodes = array('delibera_lista_de_propostas' => 'replacePropostas' ); + + /** + * Display priority + * @var int + */ + public $priority = 1; + + public function __construct() + { + add_action('delibera_pauta_recusada', array('\Delibera\Cron', 'del')); + parent::__construct(); + } + + /** + * Register Tax for the module + */ + public function registerTax() + { + if(term_exists('validacao', 'situacao', null) == false) + { + delibera_insert_term('Proposta de Pauta', 'situacao', + array( + 'description'=> 'Pauta em Validação', + 'slug' => 'validacao', + ), + array( + 'qtrans_term_pt' => 'Proposta de Pauta', + 'qtrans_term_en' => 'Proposed Topic', + 'qtrans_term_es' => 'Agenda Propuesta', + ) + ); + } + if(term_exists('naovalidada', 'situacao', null) == false) + { + delibera_insert_term('Pauta Recusada', 'situacao', + array( + 'description'=> 'Pauta não Validação', + 'slug' => 'naovalidada', + ), + array( + 'qtrans_term_pt' => 'Pauta Recusada', + 'qtrans_term_en' => 'Rejected Topic', + 'qtrans_term_es' => 'Agenda Rechazada', + ) + ); + } + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::initModule() + */ + public function initModule($post_id) + { + wp_set_object_terms($post_id, 'validacao', 'situacao', false); + $this->newDeadline($post_id); + } + + /** + * Append configurations + * @param array $opts + */ + public function getMainConfig($opts) + { + $opts['minimo_validacao'] = '10'; + $opts['dias_validacao'] = '5'; + return $opts; + } + + /** + * Array to show on config page + * @param array $rows + */ + public function configPageRows($rows, $opt) + { + $rows[] = array( + "id" => "minimo_validacao", + "label" => __('Mínimo de validações para uma pauta:', 'delibera'), + "content" => '' + ); + + $rows[] = array( + "id" => "dias_validacao", + "label" => __('Dias para validação da pauta:', 'delibera'), + "content" => '' + ); + return $rows; + } + + /** + * Label to apply to button + * @param unknown $situation + */ + public function situationButtonText($situation) + { + if($situation == 'validacao') + { + return __('Votar', 'delibera'); + } + + return $situation; + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::generateDeadline() + */ + public function generateDeadline($options_plugin_delibera) + { + $dias_validacao = intval(htmlentities($options_plugin_delibera['dias_validacao'])); + + $prazo_validacao_sugerido = strtotime("+$dias_validacao days", delibera_tratar_data(\Delibera\Flow::getLastDeadline('valicacao'))); + + return date('d/m/Y', $prazo_validacao_sugerido); + } + + /** + * + * Post Meta Fields display + * + * @param \WP_Post $post + * @param array $custom post custom fields + * @param array $options_plugin_delibera Delibera options array + * @param WP_Term $situacao + * @param bool $disable_edicao + * + */ + public function topicMeta($post, $custom, $options_plugin_delibera, $situacao, $disable_edicao) + { + $validacoes = array_key_exists("numero_validacoes", $custom) ? $custom["numero_validacoes"][0] : 0; + + $min_validacoes = array_key_exists("min_validacoes", $custom) ? $custom["min_validacoes"][0] : htmlentities($options_plugin_delibera['minimo_validacao']); + + $prazo_validacao = $this->generateDeadline($options_plugin_delibera); + + if(!($post->post_status == 'draft' || + $post->post_status == 'auto-draft' || + $post->post_status == 'pending')) + { + $prazo_validacao = array_key_exists("prazo_validacao", $custom) ? $custom["prazo_validacao"][0] : $prazo_validacao; + } + + ?> +

+ + name="min_validacoes" class="min_validacoes widefat" value=""/> +

+

+ + name="prazo_validacao" class="prazo_validacao widefat hasdatepicker" value=""/> +

+ $value) // Buscar dados + { + if(get_post_meta($postID, $key, true)) // Se já existe + { + update_post_meta($postID, $key, $value); // Atualiza + } + else + { + add_post_meta($postID, $key, $value, true); // Senão, cria + } + } + + } + + /** + * Validate topic required data + * @param array $errors erros report array + * @param array $opt Delibera configs + * @param bool $autosave is autosave? + * @return array erros report array append if needed + */ + public function checkPostData($errors, $opt, $autosave) + { + $value = $_POST['prazo_validacao']; + $valida = delibera_tratar_data($value); + if(!$autosave && (empty($value) || $valida === false || $valida < 1) ) + { + $errors[] = __("É necessário definir corretamente o prazo de validação", "delibera"); + } + + $value = (int)$_POST['min_validacoes']; + $valida = is_int($value) && $value > 0; + if(!$autosave && ($valida === false)) + { + $errors[] = __("É necessário definir corretamente o número mínimo de validações", "delibera"); + } + return $errors; + } + + /** + * + * Retorna pautas em Validação + * @param array $filtro + */ + public static function getPropostas($filtro = array()) + { + return self::getPautas($filtro); + } + + public function replacePropostas($matches) + { + global $wp_posts; + $temp = explode(',', $matches[1]); // configurações da shorttag + $count = count($temp); + + $param = array(); // TODO Tratar Parametros + + $html = DeliberaValidation::getPropostas($param); + + $wp_posts = $html; + global $post; + $old = $post; + echo '
'; + foreach ( $wp_posts as $wp_post ) + { + $post = $wp_post; + include 'delibera_loop_pauta.php'; + } + echo '
'; + $post = $old; + + return ''; // Retornar código da representação + } + + /** + * Save topic metadata + * @param array $events_meta + * @param array $opt Delibera configs + * + * @return array events_meta to be save on the topic + */ + public function savePostMetas($events_meta, $opt, $post_id = false) + { + if( // Se tem validação, tem que ter o prazo + (array_key_exists('prazo_validacao', $_POST) && array_key_exists('min_validacoes', $_POST) ) + ) + { + $events_meta['prazo_validacao'] = sanitize_text_field($_POST['prazo_validacao']); + $events_meta['min_validacoes'] = sanitize_text_field($_POST['min_validacoes']); + } + + return $events_meta; + } + + /** + * Treat postback of frotend topic + * @param array $opt Delibera configs + */ + public function createPautaAtFront($opt) + { + $_POST['prazo_validacao'] = $this->generateDeadline($opt); + $_POST['min_validacoes'] = $opt['minimo_validacao']; + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::deadline() + */ + public static function deadline($args) + { + $situacao = delibera_get_situacao($args['post_ID']); + if($situacao->slug == 'validacao') + { + self::marcarNaovalidada($args['post_ID']); + } + } + + /** + * No min validation recived + * @param int $postID + */ + public function marcarNaovalidada($postID) + { + wp_set_object_terms($postID, 'naovalidada', 'situacao', false); + if(has_action('delibera_pauta_recusada')) + { + do_action('delibera_pauta_recusada', $postID); + } + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::getCommentListLabel() + */ + public function getCommentListLabel() + { + return __('Validação da Pauta', 'delibera'); + } + +} +$DeliberaValidation = new \Delibera\Modules\Validation(); + + diff --git a/modules/vote/assets/js/admin-vote.js b/modules/vote/assets/js/admin-vote.js new file mode 100644 index 0000000..32dc878 --- /dev/null +++ b/modules/vote/assets/js/admin-vote.js @@ -0,0 +1,49 @@ +function delibera_add_comment_input(element) +{ + var panel = jQuery(element).parent(); + panel.find('.delibera_comment_add_current').append(jQuery('

')); + panel.find('.delibera_comment_input_list').val(''); + panel.find('.delibera_comment_input_list').focus(); +} + +function delibera_check_discussion() +{ + var boxes = jQuery('#delibera-flow-column2').find('.dragbox'); + for (var i = 0; i < boxes.length; i++) + { + if(jQuery(boxes[i]).hasClass("emvotacao")) + { + jQuery('.delibera_comment_list_panel').show(); + return false; + } + if(jQuery(boxes[i]).hasClass("discussao")) + { + jQuery('.delibera_comment_list_panel').hide(); + return true; + } + } + return true; +} + +jQuery(document).ready(function() { + jQuery('.delibera_comment_input_bt_remove').live('click', function() { + var sel = confirm('Do you want to delete this vote option?'); + if (sel) { + jQuery(this).parents('p').remove(); + } + return false; + }); + jQuery('#delibera-flow-column2').on('deliberaUpdateFlow', function(event, data) + { + delibera_check_discussion(); + }); + delibera_check_discussion(); + + jQuery('.delibera-voto-modal-close').click(function (){ + jQuery(this).parent().parent().hide(); + }); + jQuery('.label-voto').click(function () { + var id = jQuery(this).attr('id').replace('delibera-voto-option-', ''); + jQuery('#delibera-voto-option-' + id).show(); + }); +}); \ No newline at end of file diff --git a/modules/vote/assets/js/vote.js b/modules/vote/assets/js/vote.js new file mode 100644 index 0000000..4c48547 --- /dev/null +++ b/modules/vote/assets/js/vote.js @@ -0,0 +1,9 @@ +jQuery(document).ready(function() { + jQuery('.delibera-voto-modal-close').click(function (){ + jQuery(this).parent().parent().hide(); + }); + jQuery('.delibera-voto-bt-read').click(function () { + var id = jQuery(this).attr('id').replace('delibera-voto-bt-read-', ''); + jQuery('#delibera-voto-modal-' + id).show(); + }); +}); \ No newline at end of file diff --git a/modules/vote/vote.php b/modules/vote/vote.php new file mode 100644 index 0000000..2108c21 --- /dev/null +++ b/modules/vote/vote.php @@ -0,0 +1,496 @@ + 'Pauta com encaminhamentos em Votacao', + 'slug' => 'emvotacao', + ), + array( + 'qtrans_term_pt' => 'Regime de Votação', + 'qtrans_term_en' => 'Voting', + 'qtrans_term_es' => 'Sistema de Votación', + ) + ); + } + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::initModule() + */ + public function initModule($post_id) + { + wp_set_object_terms($post_id, 'emvotacao', 'situacao', false); + $this->newDeadline($post_id); + } + + /** + * Append configurations + * @param array $opts + */ + public function getMainConfig($opts) + { + $opts['dias_votacao'] = '5'; + $opts['tipo_votacao'] = 'checkbox'; + return $opts; + } + + /** + * Array to show on config page + * @param array $rows + */ + public function configPageRows($rows, $opt) + { + $rows[] = array( + "id" => "dias_votacao", + "label" => __('Dias para votação de encaminhamentos:', 'delibera'), + "content" => '' + ); + $id = 'tipo_votacao'; + $value = htmlspecialchars_decode($opt[$id]); + $rows[] = array( + "id" => $id, + "label" => __('Tipo da votação:', 'delibera'), + //"content" => '' + "content" => ' + + ' + ); + return $rows; + } + + /** + * Label to apply to button + * @param unknown $situation + */ + public function situationButtonText($situation) + { + if($situation == 'emvotacao') + { + return __('Votar', 'delibera'); + } + + return $situation; + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::generateDeadline() + */ + public function generateDeadline($options_plugin_delibera) + { + $dias_votacao = intval(htmlentities($options_plugin_delibera['dias_votacao'])); + + $prazo_votacao_sugerido = strtotime("+$dias_votacao days", delibera_tratar_data(\Delibera\Flow::getLastDeadline('emvotacao'))); + + return date('d/m/Y', $prazo_votacao_sugerido); + } + + /** + * + * Post Meta Fields display + * + * @param \WP_Post $post + * @param array $custom post custom fields + * @param array $options_plugin_delibera Delibera options array + * @param WP_Term $situacao + * @param bool $disable_edicao + * + */ + public function topicMeta($post, $custom, $options_plugin_delibera, $situacao, $disable_edicao) + { + /*global $DeliberaFlow; + $flow = $DeliberaFlow->get($post->ID); + $discussao = array_search('discussao', $haystack)*/ + + $prazo_votacao = $this->generateDeadline($options_plugin_delibera); + $tipo_votacao = $options_plugin_delibera['tipo_votacao']; + + if(!($post->post_status == 'draft' || + $post->post_status == 'auto-draft' || + $post->post_status == 'pending')) + { + + $prazo_votacao = array_key_exists("prazo_votacao", $custom) ? $custom["prazo_votacao"][0] : $prazo_votacao; + $tipo_votacao = array_key_exists("tipo_votacao", $custom) ? $custom["tipo_votacao"][0] : $tipo_votacao; + } + + ?> +

+ + name="prazo_votacao" class="prazo_votacao widefat hasdatepicker" value=""/> +

+

+ + +

+ + + + id; + if(strpos($screenid, 'page_delibera') !== false || $screenid == 'pauta' ) + { + wp_enqueue_script('delibera-module-vote-admin',WP_PLUGIN_URL.'/delibera/modules/vote/assets/js/admin-vote.js', array('jquery')); + } + } + + public function js() + { + wp_enqueue_script('delibera-module-vote',WP_PLUGIN_URL.'/delibera/modules/vote/assets/js/vote.js', array('jquery')); + } + + public function publishPauta($postID, $opt) + { + $events_meta = array(); + $events_meta['delibera_numero_comments_votos'] = 0; + + foreach ($events_meta as $key => $value) // Buscar dados + { + if(get_post_meta($postID, $key, true)) // Se já existe + { + update_post_meta($postID, $key, $value); // Atualiza + } + else + { + add_post_meta($postID, $key, $value, true); // Senão, cria + } + } + + } + + function checkPostData($errors, $opt, $autosave) + { + $value = $_POST['prazo_votacao']; + $valida = delibera_tratar_data($value); + if(!$autosave && (empty($value) || $valida === false || $valida < 1) ) + { + $errors[] = __("É necessário definir corretamente o prazo para votação", "delibera"); + } + return $errors; + } + + /** + * + * Retorna pautas em Validação + * @param array $filtro + */ + public static function getEmvotacao($filtro = array()) + { + return self::getPautas($filtro); + } + + public function savePostMetas($events_meta, $opt, $post_id = false) + { + if(array_key_exists('prazo_votacao', $_POST)) + { + $events_meta['prazo_votacao'] = sanitize_text_field($_POST['prazo_votacao']); + } + if(array_key_exists('tipo_votacao', $_POST)) + { + $events_meta['tipo_votacao'] = sanitize_text_field($_POST['tipo_votacao']); + } + + global $post, $current_user; + if(!is_object($post)) + { + if($post_id) + { + $post = get_post($post_id); + } + elseif(array_key_exists('post_id', $_POST )) + { + $post = get_post($_POST['post_id']); + } + } + + if(array_key_exists('delibera_comment_add_list', $_POST) ) + { + if(is_array($_POST['delibera_comment_add_list'])) + { + get_currentuserinfo(); + + $all_saved_vote_options = delibera_get_comments_encaminhamentos($post->ID); + if(!is_array($all_saved_vote_options)) $all_saved_vote_options = array(); + $all_saved_vote_options = array_object_value_recursive('comment_ID', $all_saved_vote_options); + + foreach ($_POST['delibera_comment_add_list'] as $vote_option) + { + $vote_option = explode(',', $vote_option, 2); + if(count($vote_option) == 1) $vote_option = array('', $vote_option[0]); + if($vote_option[0] == '') + { + $commentdata = array( + 'comment_post_ID' => (int) $post->ID, + 'comment_author' => $current_user->dispay_name, + 'comment_author_email' => $current_user->user_mail, + 'comment_author_url' => '', + 'comment_content' => wp_kses_data( (string) $vote_option[1]), + 'comment_type' => '', + 'comment_parent' => 0, + 'user_id' => (int) $current_user->ID, + 'comment_author_IP' => preg_replace( '/[^0-9a-fA-F:., ]/', '',$_SERVER['REMOTE_ADDR'] ), + 'comment_agent' => isset( $_SERVER['HTTP_USER_AGENT'] ) ? substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 ) : '', + 'comment_date' => current_time('mysql'), + 'comment_date_gmt' => current_time('mysql', 1), + 'comment_approved' => 1 + ); + $commentdata = wp_filter_comment($commentdata); + + + //Insert new comment and get the comment ID + $comment_id = wp_insert_comment($commentdata) ; + if($comment_id) + { + add_comment_meta($comment_id, 'delibera_comment_tipo', 'encaminhamento', true); + $nencaminhamentos = get_post_meta($comment_id, 'delibera_numero_comments_encaminhamentos', true); + $nencaminhamentos++; + update_post_meta($comment_id, 'delibera_numero_comments_encaminhamentos', $nencaminhamentos); + } + } + else + { + $comment_tmp_id = substr($vote_option[0], strlen('vote-comment-id-')); + $comment = get_comment($comment_tmp_id, ARRAY_A); + if(is_array($comment)) + { + $comment['comment_content'] = wp_kses_data( (string) $vote_option[1]); + wp_update_comment($comment); + $all_saved_vote_options = array_diff($all_saved_vote_options, array($comment_tmp_id)); + } + else + { + //TODO parse comment error + } + } + } + foreach ($all_saved_vote_options as $comment_delete_id) + { + wp_delete_comment($comment_delete_id); + } + + } + } + return $events_meta; + } + + public function createPautaAtFront($opt) + { + $data_externa = trim($opt['data_fixa_nova_pauta_externa']); + if ( !empty($data_externa) && strlen($data_externa) == 10) { + $prazo_votacao = \DateTime::createFromFormat('d/m/Y', $data_externa); + $_POST['prazo_votacao'] = $prazo_votacao->format('d/m/Y'); + } else { + $_POST['prazo_votacao'] = $this->generateDeadline($opt); + } + } + + /** + * + * Faz a apuração dos votos e toma as devidas ações: + * Empate: Mais prazo; + * Vencedor: Marco com resolucao e marca o encaminhamento. + * @param interger $postID + * @param array $votos + */ + function computaVotos($postID, $votos = null) + { + if(is_null($votos)) // Ocorre no fim do prazo de votação + { + $votos = delibera_get_comments_votacoes($postID); + } + $encaminhamentos = delibera_get_comments_encaminhamentos($postID); + $encaminhamentos_votos = array(); + foreach ($encaminhamentos as $encaminhamento) + { + $encaminhamentos_votos[$encaminhamento->comment_ID] = 0; + } + + foreach ($votos as $voto_comment) + { + $voto = get_comment_meta($voto_comment->comment_ID, 'delibera_votos', true); + foreach ($voto as $voto_para) + { + if (array_key_exists($voto_para, $encaminhamentos_votos)) + { + $encaminhamentos_votos[$voto_para]++; + } else { + $encaminhamentos_votos[$voto_para] = 1; + } + } + } + $maisvotado = array(-1, -1); + $iguais = array(); + + foreach ($encaminhamentos_votos as $encaminhamentos_voto_key => $encaminhamentos_voto_valor) + { + if($encaminhamentos_voto_valor > $maisvotado[1]) + { + $maisvotado[0] = $encaminhamentos_voto_key; + $maisvotado[1] = $encaminhamentos_voto_valor; + $iguais = array(); + } + elseif($encaminhamentos_voto_valor == $maisvotado[1]) + { + $iguais[] = $encaminhamentos_voto_key; + } + delete_comment_meta($encaminhamentos_voto_key, 'delibera_comment_numero_votos'); + add_comment_meta($encaminhamentos_voto_key, 'delibera_comment_numero_votos', $encaminhamentos_voto_valor, true); + } + + // nao finaliza a votacao caso haja um empate, exceto quando o administrador clicar no botão "Forçar fim do prazo" + if(count($iguais) > 0 && !(isset($_REQUEST['action']) && $_REQUEST['action'] == 'delibera_forca_fim_prazo_action')) // Empato + { + $this->newDeadline($postID, false); + } + else + { + //wp_set_object_terms($postID, 'comresolucao', 'situacao', false); + \Delibera\Flow::next($postID); + + update_comment_meta($maisvotado[0], 'delibera_comment_tipo', 'resolucao'); + add_post_meta($postID, 'data_resolucao', date('d/m/Y H:i:s'), true); + ////delibera_notificar_situacao($postID); + if(has_action('votacao_concluida')) + { + do_action('votacao_concluida', $post); + } + } + } + + /** + * + * Verifica se o número de votos é igual ao número de representantes para deflagar fim da votação + * @param integer $postID + */ + public function validaVotos($postID) + { + global $wp_roles,$wpdb; + $users_count = 0; + foreach ($wp_roles->roles as $nome => $role) + { + if(is_array($role['capabilities']) && array_key_exists('votar', $role['capabilities']) && $role['capabilities']['votar'] == 1 ? "SSSSSim" : "NNNnnnnnnnao") + { + $result = $wpdb->get_results("SELECT count(*) as n FROM $wpdb->usermeta WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%$nome%' "); + $users_count += $result[0]->n; + } + } + + $votos = delibera_get_comments_votacoes($postID); + + $votos_count = count($votos); + + if($votos_count >= $users_count) + { + $this->computaVotos($postID, $votos); + } + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::deadline() + */ + public static function deadline($args) + { + $post_id = $args['post_ID']; + $current = \Delibera\Flow::getCurrentModule($post_id); + $current->computaVotos($post_id); + } + + public function unfilterDuplicate($tipos) + { + $tipos[] = 'voto'; + return $tipos; + } + + /** + * + * {@inheritDoc} + * @see \Delibera\Modules\ModuleBase::getCommentListLabel() + */ + public function getCommentListLabel() + { + return __('Votação da Pauta', 'delibera'); + } + +} +$DeliberaVote = new \Delibera\Modules\Vote(); + + diff --git a/themes/atenas/archive-pauta.php b/themes/atenas/archive-pauta.php index bf7c240..f8a2f08 100644 --- a/themes/atenas/archive-pauta.php +++ b/themes/atenas/archive-pauta.php @@ -1,45 +1,46 @@
-
+
'pauta')); - - + + ?> - - + +
archiveLoop(); + ?> - - + + - +
- - + +
diff --git a/themes/atenas/loop-pauta.php b/themes/atenas/content-pauta.php similarity index 95% rename from themes/atenas/loop-pauta.php rename to themes/atenas/content-pauta.php index c79ae0f..d5ffb30 100644 --- a/themes/atenas/loop-pauta.php +++ b/themes/atenas/content-pauta.php @@ -45,10 +45,10 @@
ID ) == -1 ) + if ( \Delibera\Flow::getDeadlineDays( $post->ID ) == -1 ) _e( 'Prazo encerrado', 'delibera' ); else - printf( _n( 'Encerra em um dia', 'Encerra em %1$s dias', delibera_get_prazo( $post->ID ), 'delibera' ), number_format_i18n( delibera_get_prazo( $post->ID ) ) ); + printf( _n( 'Encerra em um dia', 'Encerra em %1$s dias', \Delibera\Flow::getDeadlineDays( $post->ID ), 'delibera' ), number_format_i18n( \Delibera\Flow::getDeadlineDays( $post->ID ) ) ); ?>
diff --git a/themes/atenas/delibera-loop-archive.php b/themes/atenas/delibera-loop-archive.php index 0666c0d..4b0b139 100644 --- a/themes/atenas/delibera-loop-archive.php +++ b/themes/atenas/delibera-loop-archive.php @@ -35,10 +35,10 @@ ID ) == -1 ) + if ( \Delibera\Flow::getDeadlineDays( $post->ID ) == -1 ) _e( 'Prazo encerrado', 'delibera' ); else - printf( _n( 'Encerra em um dia', 'Encerra em %1$s dias', delibera_get_prazo( $post->ID ), 'delibera' ), number_format_i18n( delibera_get_prazo( $post->ID ) ) ); + printf( _n( 'Encerra em um dia', 'Encerra em %1$s dias', \Delibera\Flow::getDeadlineDays( $post->ID ), 'delibera' ), number_format_i18n( \Delibera\Flow::getDeadlineDays( $post->ID ) ) ); ?> diff --git a/themes/atenas/delibera_style.css b/themes/atenas/delibera_style.css index f1b9869..d4659d7 100644 --- a/themes/atenas/delibera_style.css +++ b/themes/atenas/delibera_style.css @@ -5,13 +5,8 @@ /* Header - archive ================================================================================*/ -#content{ - float: none; -} - .home p.delibera-boasvindas { padding-left:20px; - float: left; color: #fff7e4; font-size: 22px; font-weight: bold; @@ -25,7 +20,6 @@ p.delibera-boasvindas { color:#5d5a5d; - float: left; font-size: 22px; font-weight: bold; width: 500px; @@ -39,7 +33,6 @@ p.delibera-login { } .single p.delibera-login { - float:left; font-size:12px; width: 70%; } @@ -49,7 +42,6 @@ p.delibera-participacao a{ padding-top:15px; padding-bottom:15px; display: block; - float: right; width: 225px; text-align:center; color:white; @@ -72,7 +64,6 @@ p.delibera-participacao a{ #filtro { background:#e7f1ee; padding:15px; - float: right; margin-top: 0; width: 220px; } @@ -104,7 +95,6 @@ p.delibera-participacao a{ margin-top: 2px; opacity:0.7; cursor:pointer; - float:left; } .delibera-filtros-mostrar:hover { @@ -121,16 +111,12 @@ p.delibera-participacao a{ margin-top: 2px; cursor:pointer; opacity:0.7; - float:left; } .delibera-filtros-esconder:hover { opacity: 1.0; } -.form-filtro-ultimos-chebox-span { - float: left; -} .form-filtro-ultimos-chebox-label-todos { color: #434343; @@ -143,7 +129,6 @@ p.delibera-participacao a{ #filtro { background:#e7f1ee; padding:15px; - float: right; margin-top: 0; width: 220px; } @@ -203,7 +188,7 @@ p.delibera-participacao a{ padding: 10px 35px; margin:0 10px 0 10px; border-radius: 10px; - width: 790px; + width: 100%; } .archive .form-filtro-ultimos-div { @@ -242,7 +227,6 @@ p.delibera-participacao a{ ================================================================================*/ .post-type-archive-pauta .hentry { - float: left; margin: 10px; width: 400px; border: 3px solid #c4c2c2; @@ -292,6 +276,7 @@ body.post-type-archive-pauta .entry-meta { line-height: 1.9em; padding:0 10px; margin-top: 40px; + } .post-type-archive-pauta .hentry .entry-content { @@ -303,14 +288,12 @@ body.post-type-archive-pauta .entry-meta { text-transform: uppercase; text-align: left; color: #CD334E; - float: left; width: 100%; } span.archive-situacao { display:block; font-size:11px; - float:right; text-transform:uppercase; color:#CD334E; } @@ -345,14 +328,12 @@ body.post-type-archive-pauta .entry-utility { } .single-pauta #leader img { - float: left; margin-right: 20px; border: 3px solid #ebebeb; } .single-pauta #leader h1.entry-title { clear: none; - float: left; font-family: 'LucidaSansDemiboldRoman', arial, sans-serif; line-height:27px; margin-right: 20px; @@ -431,9 +412,7 @@ span.delibera_seguir_text:hover { } .single-pauta .hentry { - float: left; background: #fff; - width: 940px; border-radius: 15px; } @@ -441,10 +420,10 @@ span.delibera_seguir_text:hover { border-left: 1px solid #EEE; border-right: 1px solid #EEE; color: #4F4F4F; - float: left; line-height: 1.9em; padding: 20px 30px; - width: 940px; + width: 100%; + margin: 0px } .single-pauta .entry-utility { @@ -456,8 +435,7 @@ span.delibera_seguir_text:hover { padding-bottom:5px; padding: 0 15px; padding-top:1px; - width:940px; - float:left; + width:100%; border:none; } @@ -466,7 +444,6 @@ span.delibera_seguir_text:hover { } .single .pauta .entry-share { - float:left; clear:both; margin: 10px; margin-left: 12px; @@ -475,7 +452,6 @@ span.delibera_seguir_text:hover { .single-pauta .entry-respond a.comment-reply-link { background-position:right 3px; - float: right; text-align: right; padding-right: 22px; padding-top: 0 !important; @@ -487,7 +463,6 @@ span.delibera_seguir_text:hover { .comentario_coluna2 { background: url('images/icone-grafico.png') center right no-repeat ; width: 170px !important; - float: right !important; margin-right: 4px; padding-right: 22px; text-align: right; @@ -527,7 +502,6 @@ span.delibera_seguir_text:hover { .single .delibera-comment-text, .author .delibera-comment-text { color:#4f4f4f; - float:left; width:600px; margin-left:30px; } @@ -536,7 +510,6 @@ span.delibera_seguir_text:hover { color:#4f4f4f; margin:5px 0; display: block; - float: left; margin: 0; } } @@ -577,7 +550,6 @@ a.comment-reply-link:hover{ clear:right; color:#4F4F4F !important; font-family: 'LucidaSansDemiboldRoman', arial, helvetica; - float: right; font-size:10px; margin-top:5px; margin-right: 4px;; @@ -602,7 +574,6 @@ a.comment-reply-link:hover{ } span.delibera_unlike_text { - float:right; background:url('images/discordo.png') right center no-repeat ; font-weight: bold; } @@ -623,7 +594,6 @@ span.delibera_like_text { span.delibera-unlike-count,.delibera_like span.delibera_like_reposta { display:block; - float:right; clear:both; } @@ -686,7 +656,6 @@ span.delibera-unlike-count, .delibera_unlike span.delibera_unlike_reposta { color:#464646; font-family: 'Candal', arial, helvetica; margin:10px 0 0 20px; - float: left; } #painel_validacao{ @@ -698,7 +667,6 @@ span.delibera-unlike-count, .delibera_unlike span.delibera_unlike_reposta { } .single-pauta p.comment-form-comment label { - float:left; font-size:12px; margin:20px 5px; text-transform:uppercase; @@ -716,7 +684,6 @@ span.delibera-unlike-count, .delibera_unlike span.delibera_unlike_reposta { .single-post #respond { background:#eee; - float:left; padding:15px; width:612px; } @@ -767,7 +734,6 @@ span.delibera-unlike-count, .delibera_unlike span.delibera_unlike_reposta { #delibera-comments .children { display: block; - float: left; position: relative; } @@ -778,7 +744,6 @@ span.delibera-unlike-count, .delibera_unlike span.delibera_unlike_reposta { #delibera-comments .delibera-comment-text { width: 67%; display: block; - float: left; position: relative; } @@ -786,13 +751,11 @@ span.delibera-unlike-count, .delibera_unlike span.delibera_unlike_reposta { #delibera-comments .delibera-comment-botoes { width: 27%; display: block; - float: left; position: relative; } #delibera-comments .delibera-comment-author.vcard { display: block; - float: left; position: relative; } @@ -831,7 +794,6 @@ span.delibera-unlike-count, .delibera_unlike span.delibera_unlike_reposta { } #delibera #tabs { - float: left; width: 650px; background: white; border-bottom-right-radius: 50px; @@ -845,7 +807,6 @@ ul.tab-navigation { } ul.tab-navigation li { - float: left; position: relative; top: 1px; white-space: nowrap; @@ -856,7 +817,6 @@ ul.tab-navigation li a { background: #666; color: #fff; display: block; - float: left; margin-right: 5px; padding: 5px 25px; } @@ -920,12 +880,9 @@ ul.tab-navigation li a:hover { .post-type-archive-pauta #content, .single-pauta #content { -moz-border-radius: 20px; -webkit-border-radius: 20px; - width: 940px; - margin: 0 auto; } .single .hentry img.alignnone { - float:left; margin-right: 20px; background:#fff; } @@ -961,7 +918,6 @@ ul.tab-navigation li a:hover { li.comment .vcard img{ border:2px solid #fff; - float:left; height:40px; margin: 0 20px 10px 10px; width:40px; @@ -971,7 +927,6 @@ li.comment .vcard img{ cite.fn a{ display:block; - float:left; font-style:normal; font-family: 'LucidaSansDemiboldRoman', arial, helvetica; margin-left: 60px; @@ -995,11 +950,6 @@ label.encaminhamento-label { padding-top: 5px; text-align: right; text-transform: uppercase; - float: right; -} - -.single a.comment-reply-link { - float:right; } .single li.depth-1 .delibera-comment-body { @@ -1026,17 +976,14 @@ li.comment ul.children li.depth-3 .delibera-like { } #respond p.logged-in-as { - float:right; text-align:right; } .single-pauta p.logged-in-as { - float:left; } .single-pauta li.comment .reply { clear: right; - float: right; height: 20px; margin-right: 2px; width: 190px; @@ -1045,13 +992,11 @@ li.comment ul.children li.depth-3 .delibera-like { input.baseadoem-checkbox { margin-left: 8px; cursor:pointer; - float:right; } .baseadoem-checkbox-div { margin: 10px 0; display: block; - float: right; } .baseadoem-checkbox-div:hover { @@ -1062,7 +1007,6 @@ input.baseadoem-checkbox { clear: right; color:#4f4f4f; display:block; - float:right; font-family: 'LucidaSansDemiboldRoman', arial, helvetica; font-size:10px; opacity:0.7; @@ -1074,7 +1018,6 @@ input.baseadoem-checkbox { } input#baseadoem-checkbox-9 { - float:right; } .single-pauta ol.commentlist { @@ -1083,11 +1026,9 @@ input#baseadoem-checkbox-9 { .single-pauta .delibera_before_fields { width: 578px; - float: left; } .home p.delibera-pagina-discussoes { - float: right; margin-top: 55px; margin-right: 5px; } @@ -1096,7 +1037,6 @@ p.delibera-pagina-discussoes a { /* border-bottom:2px solid #034ea1; color:#666;*/ margin-top: 20px; - float: right; text-align:right; text-transform:uppercase; margin-right: 30px; @@ -1152,7 +1092,6 @@ a#cancel-comment-reply-link { ================================================================================*/ p.nocomments { - float:left; text-align:center; font-size:16px; padding-top:20px; @@ -1212,10 +1151,6 @@ body.author #content { color: #F8A600; } -#delibera .author-avatar, .author .author-avatar { - float: left; -} - #delibera #ultimos-comentarios .author-avatar img, .author #ultimos-comentarios .author-avatar img { border: 3px solid #5BB762; margin-right: 35px; @@ -1230,7 +1165,6 @@ body.author #content { #delibera #membros a.membro-thumbnail { border: 3px solid #5BB762; display: block; - float:left; height: 60px; margin-right: 35px; width: 60px; @@ -1252,7 +1186,6 @@ body.author #content { #delibera #membros .membro-social a { display: block; - float: right; height: 16px; margin: 0 5px; width: 16px; @@ -1266,10 +1199,6 @@ body.author #content { background: url('images/icone-facebook.png'); } -form.delibera-edit-comment-form { - float:left; -} - form.delibera-edit-comment-form textarea { padding:5px; font-family: 'LucidaSansRegular',arial, helvetica, sans-serif; @@ -1349,7 +1278,6 @@ input .delibera-encaminha-label { border:1px solid #ccc; color:#fff; font-size:11px; - float:right; margin-top:90px; padding:10px; width:300px; @@ -1379,7 +1307,6 @@ input .delibera-encaminha-label { ================================================================================*/ .single .pauta .entry-share { - float:left; clear:both; margin: 10px; margin-left: 12px; @@ -1389,7 +1316,6 @@ input .delibera-encaminha-label { padding: 0; } .single .entry-share { - float:left; clear:both; margin: 10px; margin-left: 12px; @@ -1398,14 +1324,12 @@ input .delibera-encaminha-label { .single .share-twitter, .single .share-facebook, .single .share-this { width: 128px; - float:left; } .single-pauta .share-twitter, .single-pauta .share-facebook, .single-pauta .share-this { width: 100px; - float:left; } @@ -1427,7 +1351,6 @@ input .delibera-encaminha-label { .single-pauta .entry-respond a.comment-reply-link { background-position:right 3px; - float: right; text-align: right; padding-right: 22px; padding-top: 0 !important; @@ -1464,19 +1387,6 @@ h3#delibera-comments-title { height: 16px; background: url(images/icone-excluir.png); cursor: pointer; - float:right; -} - -.painel-baseouseem-item { - float:left; -} - -.painel-baseouseem-link { - float:left; -} - -.painel-baseouseem-label { - float:left; } #coluna-pagina { @@ -1573,7 +1483,6 @@ h1.author { } #author-avatar { - float: left; width: 225px; } @@ -1582,7 +1491,6 @@ h1.author { } #author-data{ - float: left; padding-left:25px; width: 675px; } @@ -1591,7 +1499,6 @@ h1.author { background:url('images/icone-user.png') left 5px no-repeat; padding-left:22px !important; padding-top:3px; - float: left; font-size:11px; margin-left:10px; text-transform:uppercase; @@ -1614,7 +1521,6 @@ h1.author { background:url('images/link.png') left 5px no-repeat; padding-left:22px !important; padding-top:3px; - float: left; font-size:11px; margin-left:10px; text-transform:uppercase; @@ -1628,7 +1534,6 @@ h1.author { #author-edit a { display:block; - float:right; } #entry-author-info { @@ -1652,3 +1557,39 @@ h1.author { font-weight: bold; } + + +/* + Responsivo + ================================================================================*/ +@media screen and (max-width: 910px) { + .site {padding: 20px;} +} + +.cf:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; } +* html .cf { zoom: 1; } +*:first-child+html .cf { zoom: 1; } + +body { font-family: 'Helvetica Neue', Arial, sans-serif; padding: 1.25em; font-size: 100%; line-height: 1; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } + +h1 { font-size: 2.5em; line-height: 1.333em; margin: 0 0 0.5em 0; } +h2 { font-size: 1.25em; line-height: 1.333em; margin: 0.5em 0; } + +.text p, .text li { font-size: 1em; line-height: 1.5em; margin: 0 0 0.5em 0; } +.text li { margin: 0 0 0.25em 0; } + +.vhidden { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; } + +/* + * Socialite Look-a-like defaults + */ + +.social-buttons { display: block; list-style: none; padding: 0; margin: 20px; } +.social-buttons > li { display: block; margin: 0; padding: 10px; float: left; } +.social-buttons .socialite { display: block; position: relative; background: url('images/social-sprite.png') 0 0 no-repeat; } +.social-buttons .socialite-loaded { background: none !important; } + +.social-buttons .twitter-share { width: 55px; height: 65px; background-position: 0 0; } +.social-buttons .googleplus-one { width: 50px; height: 65px; background-position: -75px 0; } +.social-buttons .facebook-like { width: 50px; height: 65px; background-position: -145px 0; } +.social-buttons .linkedin-share { width: 60px; height: 65px; background-position: -215px 0; } \ No newline at end of file diff --git a/themes/atenas/single-pauta.php b/themes/atenas/single-pauta.php index c5d33fa..8e37e34 100644 --- a/themes/atenas/single-pauta.php +++ b/themes/atenas/single-pauta.php @@ -1,17 +1,25 @@
-
- +
+ themeFilePath('content-pauta.php'), true); + } + ?>
diff --git a/themes/creta/archive-pauta.php b/themes/creta/archive-pauta.php index 4197993..ff20ce0 100644 --- a/themes/creta/archive-pauta.php +++ b/themes/creta/archive-pauta.php @@ -49,8 +49,9 @@
- archiveLoop(); global $wp_query; $big = 99999999; // need an unlikely integer diff --git a/themes/creta/loop-pauta.php b/themes/creta/content-pauta.php similarity index 83% rename from themes/creta/loop-pauta.php rename to themes/creta/content-pauta.php index 52d1e3b..a395194 100644 --- a/themes/creta/loop-pauta.php +++ b/themes/creta/content-pauta.php @@ -2,10 +2,10 @@ while (have_posts()) : the_post(); $temas = wp_get_post_terms($post->ID, 'tema'); - + $user_id = get_current_user_id(); $situacao = delibera_get_situacao($post->ID); - + $seguir = false; if (!delibera_ja_seguiu($post->ID, $user_id) && $situacao->slug != 'relatoria') { $seguir = true; @@ -16,20 +16,18 @@
ID)->name; ?> - ID) == -1) { + ID) == -1) { echo 'Prazo encerrado'; } else { - printf(_n('Encerra em um dia', 'Encerra em %1$s dias', delibera_get_prazo($post->ID), 'delibera'), number_format_i18n(delibera_get_prazo($post->ID))); + printf(_n('Encerra em um dia', 'Encerra em %1$s dias', \Delibera\Flow::getDeadlineDays($post->ID), 'delibera'), number_format_i18n(\Delibera\Flow::getDeadlineDays($post->ID))); } ?>

Discussão criada por em

-
- Facebook - Twitter - Google+ +
+
Imprimir
- +
    @@ -52,7 +50,7 @@
- +
diff --git a/themes/creta/delibera-loop-archive.php b/themes/creta/delibera-loop-archive.php index 5195085..787a62c 100644 --- a/themes/creta/delibera-loop-archive.php +++ b/themes/creta/delibera-loop-archive.php @@ -11,10 +11,10 @@
name; ?>
- ID) == -1) { + ID) == -1) { echo 'Prazo encerrado'; } else { - printf(_n('Encerra em um dia', 'Encerra em %1$s dias', delibera_get_prazo($post->ID), 'delibera'), number_format_i18n(delibera_get_prazo($post->ID))); + printf(_n('Encerra em um dia', 'Encerra em %1$s dias', \Delibera\Flow::getDeadlineDays($post->ID), 'delibera'), number_format_i18n(\Delibera\Flow::getDeadlineDays($post->ID))); } ?>
diff --git a/themes/creta/delibera_comments_template.php b/themes/creta/delibera_comments_template.php index 6705fb5..a6d2e9b 100644 --- a/themes/creta/delibera_comments_template.php +++ b/themes/creta/delibera_comments_template.php @@ -32,10 +32,10 @@ function start_el(&$output, $comment, $depth = 0, $args = array(), $current_obje } $GLOBALS['comment'] = $comment; - + $tipo = get_comment_meta($comment->comment_ID, "delibera_comment_tipo", true); $situacao = delibera_get_situacao($comment->comment_post_ID); - + extract($args, EXTR_SKIP); if ('div' == $args['style']) { @@ -45,16 +45,16 @@ function start_el(&$output, $comment, $depth = 0, $args = array(), $current_obje $tag = 'li'; $add_below = 'div-comment'; } - + $classes = array(); - + if (!empty($args['has_children'])) { $classes[] = 'parent'; } - + if ($tipo == 'encaminhamento' || $tipo == 'resolucao' || $tipo == 'encaminhamento_selecionado') { $classes[] = 'encaminhamento'; - + if (in_array($situacao->slug, array('comresolucao', 'emvotacao'))) { $classes[] = 'encaminhamentos-selecionados'; } @@ -88,18 +88,19 @@ function start_el(&$output, $comment, $depth = 0, $args = array(), $current_obje + comment_ID), comment_text()); ?>
@@ -125,7 +126,7 @@ function start_el(&$output, $comment, $depth = 0, $args = array(), $current_obje
slug != 'validacao' && is_user_logged_in()) { + if ($situacao->slug != 'validacao' && is_user_logged_in()) { $args['reply_text'] = __("Responder", 'delibera'); ?> $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?> @@ -150,11 +151,11 @@ function start_el(&$output, $comment, $depth = 0, $args = array(), $current_obje $elements = explode(',', $baseouseem); $result = ''; $count = count($elements); - + foreach ($elements as $key => $element) { $reference_comment = get_comment($element); $result .= "{$reference_comment->comment_author}"; - + if ($key + 1 < $count) { $result .= ', '; } @@ -162,10 +163,10 @@ function start_el(&$output, $comment, $depth = 0, $args = array(), $current_obje echo '
'.__('Proposta baseada em:', 'delibera') . ' ' . $result . '
'; } } - + if (($tipo == "encaminhamento" || $tipo == 'encaminhamento_selecionado') && current_user_can('relatoria') && $situacao->slug == "relatoria") { $selecionados = delibera_get_comments_encaminhamentos_selecionados_ids($comment->comment_post_ID); - + if (!$selecionados) { $selecionados = array(); } @@ -181,26 +182,26 @@ function start_el(&$output, $comment, $depth = 0, $args = array(), $current_obje

- comment_ID, 'delibera_numero_curtir', true); $ndiscordou = get_comment_meta($comment->comment_ID, 'delibera_numero_discordar', true); - + if (is_user_logged_in() || $ncurtiu || $ndiscordou) : ?>
comment_ID, 'comment'); $discordar = delibera_gerar_discordar($comment->comment_ID, 'comment'); - + if ($curtir) { echo $curtir; } - + if ($discordar) { echo $discordar; - } + } ?>
diff --git a/themes/creta/delibera_style.css b/themes/creta/delibera_style.css index 40ae6ec..84a8cb6 100644 --- a/themes/creta/delibera_style.css +++ b/themes/creta/delibera_style.css @@ -28,6 +28,7 @@ div, h1, h2, h3, h4, h5, p { margin-bottom:9px; } #delibera .filters li { padding:3px 0; + list-style-type: none; } #delibera .filters ul.dates li { @@ -237,7 +238,7 @@ div, h1, h2, h3, h4, h5, p { margin-bottom:9px; } } #delibera #comments article header .alignleft { - width:80%; + width:50%; } #delibera #comments article header .alignright { @@ -603,4 +604,43 @@ div.error { div.error p { margin: 0.5em 0; padding: 2px; -} \ No newline at end of file +} + +/* + Responsivo + ================================================================================*/ +@media screen and (max-width: 910px) { + .site-content {padding: 20px;} + .filters.widget-area {width: 100%;} + #delibera .site-content {width: 100%;} +} + + + +.cf:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; } +* html .cf { zoom: 1; } +*:first-child+html .cf { zoom: 1; } + +body { font-family: 'Helvetica Neue', Arial, sans-serif; padding: 1.25em; font-size: 100%; line-height: 1; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } + +h1 { font-size: 2.5em; line-height: 1.333em; margin: 0 0 0.5em 0; } +h2 { font-size: 1.25em; line-height: 1.333em; margin: 0.5em 0; } + +.text p, .text li { font-size: 1em; line-height: 1.5em; margin: 0 0 0.5em 0; } +.text li { margin: 0 0 0.25em 0; } + +.vhidden { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; } + +/* + * Socialite Look-a-like defaults + */ + +.social-buttons { display: block; list-style: none; padding: 0; margin: 20px; } +.social-buttons > li { display: block; margin: 0; float: left; } +.social-buttons .socialite { display: block; position: relative; background: url('images/social-sprite.png') 0 0 no-repeat; } +.social-buttons .socialite-loaded { background: none !important; } + +.social-buttons .twitter-share, +.social-buttons .googleplus-one, +.social-buttons .facebook-like, +.social-buttons .linkedin-share { text-align: center; width: 70px; height: 25px; } \ No newline at end of file diff --git a/themes/creta/functions.php b/themes/creta/functions.php index a45fbf4..fa865ea 100644 --- a/themes/creta/functions.php +++ b/themes/creta/functions.php @@ -2,23 +2,23 @@ function get_delibera_header() { global $wp; - + $opt = delibera_get_config(); - + $current_url = add_query_arg($wp->query_string, '', home_url($wp->request)); - + ?> - +

- +

faça o logout.', 'delibera'), $current_user->display_name, @@ -27,15 +27,15 @@ function get_delibera_header() { } else if (is_user_logged_in() && !delibera_current_user_can_participate()) { global $current_user; get_currentuserinfo(); - + printf( __('Você está logado como %1$s mas seu usuário não tem permissão para participar desta pauta. Caso deseje entrar com outra conta, faça o logout.', 'delibera'), $current_user->display_name, wp_logout_url(home_url('/')) ); - } else { + } else { printf( - __('Para participar, você precisa fazer o login ou registrar-se no site.', 'delibera'), + __('Para participar, você precisa fazer o login ou registrar-se no site.', 'delibera'), wp_login_url($current_url), site_url('wp-login.php?action=register', 'login')."&lang=" ); @@ -44,7 +44,15 @@ function get_delibera_header() {

- + +
@@ -54,10 +62,10 @@ function get_delibera_header() { /** * Formulário do comentário que é usado para * aprovar, discutir e votar nas pautas. - * - * Manipula com array usado pelo Wordpress para + * + * Manipula com array usado pelo Wordpress para * compor o formulário de comentário. - * + * * @param array $defaults * @return array */ @@ -65,10 +73,10 @@ function delibera_comment_form($defaults) { global $post, $delibera_comments_padrao, $user_identity, $comment_footer; $comment_footer = ""; - + if ($delibera_comments_padrao === true) { $defaults['fields'] = $defaults['must_log_in']; - + if (!is_user_logged_in()) { $defaults['comment_field'] = ""; $defaults['logged_in_as'] = ''; @@ -77,17 +85,17 @@ function delibera_comment_form($defaults) $defaults['id_submit'] = "botao-oculto"; $defaults['comment_notes_before'] = ' '; } - + return $defaults; } - + if (get_post_type($post) == "pauta") { $current_user = wp_get_current_user(); $defaults['id_form'] = 'delibera_commentform'; $defaults['comment_field'] = '
'.$defaults['comment_field']; $situacao = delibera_get_situacao($post->ID); - - switch ($situacao->slug) { + + switch ($situacao->slug) { case 'validacao': $user_comments = delibera_get_comments($post->ID, 'validacao', array('user_id' => $current_user->ID)); $temvalidacao = false; @@ -109,7 +117,7 @@ function delibera_comment_form($defaults) '; } else { $defaults['title_reply'] = __('Você quer ver essa pauta posta em discussão?','delibera'); - $defaults['must_log_in'] = sprintf(__('Você precisar estar logado e ter permissão para votar.','delibera'), wp_login_url(apply_filters('the_permalink', get_permalink($post->ID)))); + $defaults['must_log_in'] = sprintf(__('Você precisar estar logado e ter permissão para votar.','delibera'), wp_login_url(apply_filters('the_permalink', get_permalink($post->ID)))); if (delibera_current_user_can_participate()) { $form = '
@@ -138,13 +146,13 @@ function delibera_comment_form($defaults) $defaults['comment_notes_after'] = ""; $defaults['logged_in_as'] = ""; $defaults['comment_field'] = '' . $defaults['comment_field']; - + if($situacao->slug == 'relatoria') { $defaults['comment_field'] = '

' . $defaults['comment_field']; } - + if (delibera_current_user_can_participate()) { $replace = ''; @@ -166,7 +174,7 @@ function delibera_comment_form($defaults) $defaults['label_submit'] = ""; $defaults['id_submit'] = "botao-oculto"; } - + if (has_filter('delibera_discussao_comment_form')) { $defaults = apply_filters('delibera_discussao_comment_form', $defaults, $situacao->slug); } @@ -181,16 +189,16 @@ function delibera_comment_form($defaults) $defaults['logged_in_as'] = ''; $defaults['comment_field'] = '' . $defaults['comment_field']; $defaults['id_submit'] = "botao-oculto"; - + if ($situacao->slug == 'relatoria') { $defaults['comment_field'] = '' . '' . $defaults['comment_field']; } - + $replace = ''; $defaults['comment_field'] = preg_replace("/
+
', + esc_html__( 'Upgrade message from the plugin author:', 'tgmpa' ), + ' ', wp_kses_data( $item['upgrade_notice'] ), ' +
+