<?php //define('SHORTINIT', true); require '../../../../../wp-load.php'; $mural_id = $_REQUEST['mural_id']; $msg = $_REQUEST['message']; $current_user = wp_get_current_user(); if (is_numeric($_REQUEST['deletar']) && (int) $_REQUEST['deletar'] > 0) { $comment_to_delete = (int) $_REQUEST['deletar']; $comment = get_comment($comment_to_delete); if (current_user_can('edit_post', $mural_id) || $current_user->ID == $comment->user_id) { wp_delete_comment($comment_to_delete); } } if (strlen($msg) > 0) { // novo comentário $msg = strip_tags($msg); $msg = substr($msg, 0, 1000); if (is_object($current_user)) { $commentdata = array('comment_post_ID' => $mural_id, 'comment_author' => $current_user->display_name, 'comment_author_email' => $current_user->user_email, 'user_ID' => $current_user->ID, 'comment_author_url' => get_author_posts_url($current_user->ID), 'comment_content' => $msg); $comment_id = wp_new_comment($commentdata); // check if the comment is approved $comment = get_comment($comment_id); if ($comment->comment_approved == 0) { _e('Seu comentário está aguardando moderação', 'tnb'); } } } print_mural_comentarios($mural_id, $_REQUEST['per_page'], $_REQUEST['page'], $_REQUEST['profile_owner']);
protected function __output() { $widget_id = uniqid('mural'); $mural_id = self::get_mural_id(); ?> <div id="<?php echo $widget_id; ?> "> <div class="mural-lista-container"> <ul class="mural-lista"> <?php print_mural_comentarios($mural_id, $this->property['num_posts'], 1, $this->user_id); ?> </ul> <div class="loading">Carregando</div> </div> <?php if (is_user_logged_in()) { ?> <form class="mural-form"> <label for="mensagem">Mensagem</label><br /> <input type="hidden" name="profile_owner" value="<?php echo $this->user_id; ?> " /> <textarea name="mensagem"></textarea> <button class="config-button bg-yellow alignright">Enviar</button> </form> <?php } ?> </div> <script> function <?php echo $widget_id; ?> _add_button_events() { var current_page = jQuery('#<?php echo $widget_id; ?> ').find('.current_page').val(); jQuery('#<?php echo $widget_id; ?> ').find('a.widget_mural_anterior').click(function() { <?php echo $widget_id; ?> tnb_load_comments('', parseInt(current_page) - 1, 0); }); jQuery('#<?php echo $widget_id; ?> ').find('a.widget_mural_proximo').click(function() { <?php echo $widget_id; ?> tnb_load_comments('', parseInt(current_page) + 1, 0); }); jQuery('#<?php echo $widget_id; ?> ').find('a.widget_mural_apagar').click(function() { var comment_id = jQuery(this).attr('id').replace('apagar_', ''); <?php echo $widget_id; ?> tnb_load_comments('', current_page, comment_id); }); } <?php echo $widget_id; ?> _add_button_events() function <?php echo $widget_id; ?> tnb_load_comments(msg, page, deletar) { jQuery('#<?php echo $widget_id; ?> ').find('.loading').show() jQuery('#<?php echo $widget_id; ?> ul.mural-lista').load('<?php echo TNB_URL . '/includes/tnb_widgets/_widget_mural_ajax.php'; ?> ', { message: msg, deletar: deletar, mural_id: <?php echo $mural_id; ?> , per_page: <?php echo $this->property['num_posts'] ? $this->property['num_posts'] : 5; ?> , profile_owner: <?php echo $this->user_id; ?> , page: page }, function() { jQuery('#<?php echo $widget_id; ?> ').find('.loading').hide(); jQuery('#<?php echo $widget_id; ?> form.mural-form textarea').val(''); <?php echo $widget_id; ?> _add_button_events(); } ); } jQuery('#<?php echo $widget_id; ?> form.mural-form button').click(function() { if (jQuery('#<?php echo $widget_id; ?> form.mural-form textarea').val() == '') { alert('<?php _e('Escreva uma mensagem', 'tnb'); ?> '); return false; } else { <?php echo $widget_id; ?> tnb_load_comments(jQuery('#<?php echo $widget_id; ?> form.mural-form textarea').val(), 1, 0); return false; } }); </script> <?php }