';
if(isset($userAverage) && $userAverage != '' && count($userCriteria) >=2) {
$userAverages = $userAverage * 10;
$userstartitle = $userAverage / 2;
$text .= '
';
};
for($i = 0; $i < count($userCriteria); $i++) {
$value_criteria = $userCriteria[$i]['value'] * 10;
$text .= '
'.$userCriteria[$i]['name'].''.$value_criteria.'
';
};
$text .= '
';
///
$textsec = '';
if(isset($pros_review) && $pros_review != '') {
$pros_reviews = explode(PHP_EOL, $pros_review);
$proscomment = '';
foreach ($pros_reviews as $pros) {
$proscomment .='';
}
$textsec .= '
'.__('+ PROS:', 'rehub-theme').' '.$proscomment.'
';
};
if(isset($cons_review) && $cons_review != '') {
$cons_reviews = explode(PHP_EOL, $cons_review);
$conscomment = '';
foreach ($cons_reviews as $cons) {
$conscomment .='';
}
$textsec .= '
'.__('- CONS:', 'rehub-theme').' '.$conscomment.'
';
};
$textsec .= getCommentLike_re('');
$textsec .= '
';
};
echo ''.$text;
echo ''; comment_text(); echo '
';
echo ''.$textsec;
}
}
// ADD THE COMMENTS META FIELDS TO THE COMMENTS ADMIN PAGE
function rehub_comment_columns( $columns )
{
$columns['my_custom_column'] = esc_html__( 'User review', 'rehub-theme' );
return $columns;
}
add_filter( 'manage_edit-comments_columns', 'rehub_comment_columns' );
function myplugin_comment_column( $column, $comment_ID )
{
if ( 'my_custom_column' == $column ) {
$comment_meta = get_comment_meta($comment_ID);
$userCriteria = get_comment_meta($comment_ID, 'user_criteria', true);
$pros_review = get_comment_meta($comment_ID, 'pros_review', true);
$cons_review = get_comment_meta($comment_ID, 'cons_review', true);
if(isset($pros_review) && $pros_review != '') {
echo ''.__('+ PROS:', 'rehub-theme').' '.$pros_review.'
';
};
if(isset($cons_review) && $cons_review != '') {
echo ''.__('- CONS:', 'rehub-theme').' '.$cons_review.'
';
};
if(is_array($userCriteria) && !empty($userCriteria)) {
for($i = 0; $i < count($userCriteria); $i++) {
echo ''.$userCriteria[$i]['name'].':
'.$userCriteria[$i]['value'].'';
};
};
echo '
';
}
}
add_filter( 'manage_comments_custom_column', 'myplugin_comment_column', 10, 2 );
/* Save Admin Review Comment fields */
function rehub_admin_update_comment( $data, $comment ) {
$comment_id = $data['comment_ID'];
// Remove curent Post rating if it was approved before
if( $comment['comment_approved'] ) {
remove_comment_rates( $comment_id );
}
// Update Review meta
if( isset( $data['pros_review'] ) ) {
update_comment_meta( $comment_id, 'pros_review', sanitize_textarea_field( $data['pros_review'] ) );
}
if( isset( $data['cons_review'] ) ) {
update_comment_meta( $comment_id, 'cons_review', sanitize_textarea_field( $data['cons_review'] ) );
}
if( isset( $data['user_criteria'] ) ) {
update_comment_meta( $comment_id, 'user_criteria', (array) $data['user_criteria'] );
}
if( isset( $data['removerating'] ) ) {
remove_comment_rates($comment_id);
rehub_rewrite_user_review($comment_id);
delete_comment_meta( $comment_id, 'user_criteria');
delete_comment_meta( $comment_id, 'cons_review' );
delete_comment_meta( $comment_id, 'pros_review' );
}else{
// Run update Post rating
if( $data['comment_approved'] ) {
rh_update_post_rating( $comment_id );
}
}
// Return regular value after updating
return $data;
}
add_filter( 'wp_update_comment_data', 'rehub_admin_update_comment', 10, 2 );
/* Render meta box with Review fields */
if( !function_exists('rh_review_inner_custom_box') ) {
function rh_review_inner_custom_box( $comment ) {
if ( !isset( $comment->comment_ID ) ) return;
if ( !isset( $comment->comment_post_ID ) ) return;
$reviewScore = get_post_meta( $comment->comment_post_ID, 'rehub_review_overall_score', true );
if ($reviewScore && (int)$reviewScore > 0) {
$userCriteria = get_comment_meta( $comment->comment_ID, 'user_criteria', true );
$pros_review = get_comment_meta( $comment->comment_ID, 'pros_review', true );
$cons_review = get_comment_meta( $comment->comment_ID, 'cons_review', true );
$prosconsRow = $criteriaRow = '';
if( !empty($pros_review) || !empty($cons_review) ) {
$prosconsRow .= '
|
|
';
}
if( is_array($userCriteria) && !empty($userCriteria) ) {
$criteriaRow = '
';
for( $i = 0; $i < count($userCriteria); $i++ ) {
$criteriaRow .= ' ';
$criteriaRow .= '';
$criteriaRow .= ' | ';
$criteriaRow .= (is_int(($i+1)/4)) ? '
' : '';
}
$criteriaRow .= '
';
}
if(!empty($userCriteria) || !empty($pros_review) || !empty($cons_review)){
echo '
';
}
}
}
}
/* Update Total score of the Post and the Comment */
if( !function_exists('rh_update_post_rating') ) {
function rh_update_post_rating( $comment_id ) {
$comment = get_comment( $comment_id );
$comment_id = $comment->comment_ID;
$comment_post_id = $comment->comment_post_ID;
$postUserRaitingsArray = get_post_meta($comment_post_id, 'post_user_raitings', false);
$postUserRaitings = $postUserRaitingsArray[0];
$commentRaitingsArray = get_comment_meta($comment_id, 'user_criteria', false);
$commentRaitings = $commentRaitingsArray[0];
$postData = array();
$postCriteriaAverage = $commentTotal = 0;
if( isset($commentRaitings) && count($commentRaitings) > 0 ) {
for($i = 0; $i < count($commentRaitings); $i++) {
$postData['criteria'][$i]['name'] = $commentRaitings[$i]['name'];
if(isset($postUserRaitings['criteria'][$i])) {
$count = (int) $postUserRaitings['criteria'][$i]['count'] + 1;
$total = (float) $commentRaitings[$i]['value'] + (float) $postUserRaitings['criteria'][$i]['value'];
$postData['criteria'][$i]['count'] = $count;
$postData['criteria'][$i]['value'] = $total;
$postData['criteria'][$i]['average'] = bcdiv($total, $count, 1);
}
else {
$postData['criteria'][$i]['count'] = 1;
$postData['criteria'][$i]['value'] = (float) $commentRaitings[$i]['value'];
$postData['criteria'][$i]['average'] = (float) $commentRaitings[$i]['value'];
};
$postCriteriaAverage += (float)$postData['criteria'][$i]['average'];
$commentTotal += (float)$commentRaitings[$i]['value'];
};
$postAverage = bcdiv($postCriteriaAverage, count($commentRaitings), 1);
$commentAverage = bcdiv($commentTotal, count($commentRaitings), 1);
update_post_meta($comment_post_id, 'post_user_raitings', $postData);
update_post_meta($comment_post_id, 'post_user_average', $postAverage);
update_comment_meta($comment_id, 'user_average', $commentAverage);
update_comment_meta($comment_id, 'counted', 1);
if(rehub_option('type_total_score')=='average'){
$editorrate = get_post_meta($comment_post_id, 'rehub_review_editor_score', true);
if($editorrate){
$overallupdate = ($editorrate + $postAverage) / 2;
update_post_meta($comment_post_id, 'rehub_review_overall_score', $overallupdate);
}
}
elseif(rehub_option('type_total_score')=='user'){
update_post_meta($comment_post_id, 'rehub_review_overall_score', $postAverage);
}
}
}
}
?>