forked from ethymos/delibera
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdelibera_comments_edit.php
185 lines (160 loc) · 6.27 KB
/
delibera_comments_edit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
function delibera_get_edit_comment_link( $comment_id = 0 )
{
$comment = &get_comment( $comment_id );
$userid = get_current_user_id();
if($userid != $comment->user_id)
return;
$location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID;
return apply_filters( 'get_edit_comment_link', $location );
}
function delibera_edit_comment_link( $link = null, $before = '', $after = '' )
{
global $comment;
$userid = get_current_user_id();
if($userid != $comment->user_id)
return;
if ( null === $link )
$link = __('Editar', delibera);
$html = '<div class="delibera-edit-comment-button"><span class="delibera-edit-comment-button" onclick="';
$html .= 'delibera_edit_comment_show(this, \''.$comment->comment_ID.'\');';
$html .= '" >'.$link.'</span></div>';
echo $html;
}
function delibera_get_comment_to_edit( $id ) {
if ( !$comment = get_comment($id) )
return false;
$comment->comment_ID = (int) $comment->comment_ID;
$comment->comment_post_ID = (int) $comment->comment_post_ID;
$comment->comment_content = format_to_edit( $comment->comment_content );
$comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content);
$comment->comment_author = format_to_edit( $comment->comment_author );
$comment->comment_author_email = format_to_edit( $comment->comment_author_email );
$comment->comment_author_url = format_to_edit( $comment->comment_author_url );
$comment->comment_author_url = esc_url($comment->comment_author_url);
return $comment;
}
function delibera_update_comment($comment_id, $user_id, $text, $proposta)
{
$arrcomment = array(
'comment_ID' => intval($comment_id),
'comment_content' => $text,
'comment_date' => date("Y-m-d H:i:s")
);
wp_update_comment($arrcomment);
$comment = get_comment($comment_id);
$proposta_antes = get_comment_meta($comment_id, 'delibera_comment_tipo', true);
if($proposta != $proposta_antes)
{
if($proposta == 'encaminhamento')
{
update_comment_meta($comment_id, 'delibera_comment_tipo', 'encaminhamento');
$nencaminhamentos = get_post_meta($comment->comment_post_ID, 'delibera_numero_comments_encaminhamentos', true);
$nencaminhamentos++;
update_post_meta($comment->comment_post_ID, 'delibera_numero_comments_encaminhamentos', $nencaminhamentos);
$ndiscussoes = get_post_meta($comment->comment_post_ID, 'delibera_numero_comments_discussoes', true);
$ndiscussoes--;
update_post_meta($comment->comment_post_ID, 'delibera_numero_comments_discussoes', $ndiscussoes);
}
else
{
update_comment_meta($comment_id, 'delibera_comment_tipo', 'discussao');
$ndiscussoes = get_post_meta($comment->comment_post_ID, 'delibera_numero_comments_discussoes', true);
$ndiscussoes++;
update_post_meta($comment->comment_post_ID, 'delibera_numero_comments_discussoes', $ndiscussoes);
$nencaminhamentos = get_post_meta($comment->comment_post_ID, 'delibera_numero_comments_encaminhamentos', true);
$nencaminhamentos--;
update_post_meta($comment->comment_post_ID, 'delibera_numero_comments_encaminhamentos', $nencaminhamentos);
}
}
return $text;
}
function delibera_update_comment_callback()
{
if(
array_key_exists('comment_ID', $_POST) &&
array_key_exists('user_id', $_POST) &&
array_key_exists('text', $_POST) &&
array_key_exists('proposta', $_POST)
)
{
if(check_ajax_referer( "comment-edit-delibera-{$_POST['comment_ID']}-{$_POST['user_id']}", 'security' ))
{
echo delibera_update_comment($_POST['comment_ID'], $_POST['user_id'], $_POST['text'], $_POST['proposta']);
}
}
die();
}
add_action('wp_ajax_delibera_update_comment', 'delibera_update_comment_callback');
add_action('wp_ajax_nopriv_delibera_update_comment', 'delibera_update_comment_callback');
function delibera_comment_edit_form()
{
global $comment;
$comment = delibera_get_comment_to_edit($comment->comment_ID);
require_once(WP_CONTENT_DIR.'/../wp-admin/includes/template.php');
include(__DIR__.'/delibera-edit-form-comment.php');
}
function delibera_delete_comment_link( $link = null, $before = '', $after = '' )
{
global $comment;
$userid = get_current_user_id();
if($userid != $comment->user_id)
return;
if ( null === $link )
$link = __('Deletar', delibera);
$html = '<div id="delibera-delete-comment-button-'.$comment->comment_ID.'" class="delibera-delete-comment-button"><span class="delibera-delete-comment-button" >'.$link.'</span></div>';
echo $html;
}
function delibera_delete_comment($comment_id, $user_id, $proposta)
{
$comment = get_comment($comment_id);
if($proposta == 'encaminhamento')
{
$nencaminhamentos = get_post_meta($comment->comment_post_ID, 'delibera_numero_comments_encaminhamentos', true);
$nencaminhamentos--;
update_post_meta($comment->comment_post_ID, 'delibera_numero_comments_encaminhamentos', $nencaminhamentos);
}
else
{
$ndiscussoes = get_post_meta($comment->comment_post_ID, 'delibera_numero_comments_discussoes', true);
$ndiscussoes--;
update_post_meta($comment->comment_post_ID, 'delibera_numero_comments_discussoes', $ndiscussoes);
}
return wp_delete_comment($comment_id);
}
function delibera_delete_comment_callback()
{
if(
array_key_exists('comment_ID', $_POST) &&
array_key_exists('user_id', $_POST) &&
array_key_exists('proposta', $_POST)
)
{
if(check_ajax_referer( "comment-delete-delibera-{$_POST['comment_ID']}-{$_POST['user_id']}", 'security' ))
{
echo delibera_delete_comment($_POST['comment_ID'], $_POST['user_id'], $_POST['proposta']);
}
}
die();
}
add_action('wp_ajax_delibera_delete_comment', 'delibera_delete_comment_callback');
add_action('wp_ajax_nopriv_delibera_delete_comment', 'delibera_delete_comment_callback');
/*
* Comment Meta Debug
*
function delibera_comment_add_meta_box()
{
add_meta_box( 'delibera-comment-meta', __( 'Comment Title' ), 'delibera_comment_meta_box_cb', 'comment', 'normal', 'high' );
}
add_action( 'add_meta_boxes_comment', 'delibera_comment_add_meta_box' );
function delibera_comment_meta_box_cb( $comment )
{
$title = get_comment_meta( $comment->comment_ID, 'delibera_votos', true );
//wp_nonce_field( 'delibera_comment_update', 'delibera_comment_update', false );
?>
<p>
<label for="delibera_comment_title"><?php _e( 'Comment Title' ); ?></label>;
<input type="text" name="delibera_comment_title" value="<?php echo esc_attr( print_r($title, true) ); ?>" class="widefat" />
</p>
<?php
}*/