/** * Get the single review via ajax * * @param array $reviewOptions * @param array $ratingFormArray * @param int $lastcommentid * @param bool $ajax * * @return array|string */ public static function build_user_rating_review_single($reviewOptions = array(), $ratingFormArray = array(), $lastcommentid, $ajax = false) { global $wpdb; $firstLabel = ''; $post_id = !empty($reviewOptions['post_id']) ? $reviewOptions['post_id'] : get_the_ID(); if (!empty($reviewOptions['form_id'])) { $ratingFormId = $reviewOptions['form_id']; } else { $defaultFormId = get_option('cbratingsystem_defaultratingForm'); $ratingFormId = apply_filters('rating_form_array', $defaultFormId); } if (is_string($reviewOptions['theme']) and !empty($reviewOptions['theme'])) { $theme_key = $reviewOptions['theme']; } else { $theme_key = 'basic'; } $reviews = CBRatingSystemData::get_user_ratings_with_ratingForm_lastID($lastcommentid, true); $output = $mainContent = ''; if (!empty($reviews[0])) { if (!empty($reviews) and is_array($reviews)) { $jsArray = array(); $shownReviews = 0; foreach ($reviews as $reviewKey => $review) { $mainContent .= '<div id="cbrating-' . $ratingFormId . '-review-' . $review->id . '" data-review-id="' . $review->id . '" data-post-id="' . $post_id . '" data-form-id="' . $ratingFormId . '" class="cbratingsinglerevbox reviews_wrapper_' . $theme_key . '_theme review_wrapper review_wrapper_post-' . $post_id . '_form-' . $ratingFormId . ' review_wrapper_post-' . $post_id . '_form-' . $ratingFormId . '_review-' . $review->id . '">'; $mainContent .= ' <div class="cbratingboxinner ' . $reviewOptions['comment_status'] . ' reviews_rating_' . $theme_key . '_theme review_rating review_rating_review-' . $review->id . '">'; if (!empty($review->rating) and is_array($review->rating)) { // User Details part. if ($review->user_id != 0) { $user_url = get_author_posts_url($review->user_id); //$name = get_the_author_meta( 'display_name', $review->user_id ); $name = get_user_meta($review->user_id, 'company_name', true); if (!empty($user_url) && $ratingFormArray['show_user_link_in_review'] == '1') { $name = '<a target="_blank" href="' . $user_url . '">' . $name . '</a>'; } $name = apply_filters('cbrating_edit_review_user_link', $name, $review->user_id); //finally check the settings if ($ratingFormArray['show_user_avatar_in_review'] == '1') { // $gravatar = get_avatar( $review->user_id, 36 ); $gravatar = '<img src="' . WEPN_Helper::supplier_avatar($review->user_id, 'vendor-small-thumb') . '" />'; } else { $gravatar = ''; } $gravatar = apply_filters('cbrating_edit_review_user_avatar', $gravatar, $review->user_id); $user_html = ' <p class="cbrating_user_name">' . (!empty($user_url) ? '<span class="user_gravatar">' . $gravatar . $name . '</span>' : '<span class="user_gravatar">' . $gravatar . $name . '</span>') . '</p>'; if (isset($ratingFormArray['buddypress_active']) && $ratingFormArray['buddypress_active'] == '1') { if (function_exists('bp_is_active')) { $rating_review_filtered_authorlink = apply_filters('cbratingsystem_buddypress_authorlink', array('show_image' => $ratingFormArray['show_user_avatar_in_review'], 'show_link' => $ratingFormArray['show_user_link_in_review'], 'review_user_id' => $review->user_id, 'user_html' => $user_html)); $user_html = $rating_review_filtered_authorlink['user_html']; } } } else { $user_url = ''; $name = !empty($review->user_name) ? $review->user_name : 'Anonymous'; if ($ratingFormArray['show_user_avatar_in_review'] == '1') { $gravatar = get_avatar(0, 36, 'gravatar_default'); } else { $gravatar = ''; } $user_html = ' <p class="cbrating_user_name">' . (!empty($user_url) ? '<span class="user_gravatar">' . $gravatar . $name . '</span>' : '<span class="user_gravatar">' . $gravatar . $name . '</span>') . '</p>'; } $user_html = apply_filters('cbrating_edit_review_user_info', $user_html, $review->user_id, $ratingFormArray, $reviewOptions, $review); $mainContent .= ' <div class="reviews_user_details_' . $theme_key . '_theme review_user_details"> ' . $user_html . ' <span class="user_rate_time"><a title="' . date('l, F d, Y \\a\\t j:ia', $review->created) . '" href="' . get_permalink($post_id) . '#cbrating-' . $ratingFormId . '-review-' . $review->id . '">' . CBRatingSystemFunctions::codeboxr_time_elapsed_string($review->created) . '</a></span> </div> <div class="clear" style="clear:both;"></div> '; // Criteria Display part. $mainContent .= '<div data-form-id="' . $ratingFormId . '" class="all_criteria_warpper_' . $theme_key . '_theme all-criteria-wrapper all-criteria-wrapper-form-' . $ratingFormId . '">'; foreach ($review->rating as $criteriId => $value) { if (is_numeric($criteriId)) { $value = $value / 100 * $review->rating[$criteriId . '_starCount']; $jsArray['review'][$review->id]['ratingForm'] = $ratingFormId; $jsArray['review'][$review->id]['criteria']['review_' . $review->id . '_criteria_' . $criteriId . '_value'] = $value; $jsArray['review'][$review->id]['criteria']['review_' . $review->id . '_criteria_' . $criteriId . '_count'] = $review->rating[$criteriId . '_starCount']; $jsArray['review'][$review->id]['criteria']['review_' . $review->id . '_criteria_' . $criteriId . '_redOnlyHint'] = $review->rating[$criteriId . '_stars'][$value - 1]; $jsArray['review'][$review->id]['criteria']['review_' . $review->id . '_criteria_' . $criteriId . '_hints'] = $review->rating[$criteriId . '_stars']; $imgtitle = ''; $hello = ''; $i = 0; $ratvalue = round($value); for (; $i < $ratvalue; $i++) { $hello .= '<img src="' . plugins_url('/images/star-on.png', __FILE__) . '" alt="' . $i . '" title="' . $imgtitle . '">'; } $whiteimg = $review->rating[$criteriId . '_starCount'] - $ratvalue; for ($j = 0; $j < $whiteimg; $j++) { $hello .= '<img src="' . plugins_url('/images/star-off.png', __FILE__) . '" alt="' . $j . '" title="' . $imgtitle . '">'; } $mainContent .= '<div data-form-id="' . $ratingFormId . '" data-criteria-id="' . $criteriId . '" class="criteria_warpper_' . $theme_key . '_theme criteria-wrapper criteria-id-wrapper-' . $criteriId . ' criteria-id-wrapper-' . $criteriId . '-form-' . $ratingFormId . ' "> <div class="criteria_label_warpper_' . $theme_key . '_theme criteria-label-wrapper"> <span class="criteria-label criteria-label-id-' . $criteriId . '" ><strong>' . __($review->custom_criteria[$criteriId]['label'], 'cbratingsystem') . '</strong></span> </div> <div id="criteria-star-wrapper-' . $review->id . '" data-form-id="' . $ratingFormId . '" data-criteria-id="' . $criteriId . '" class="criteria-star-wrapper criteria-star-wrapper-id-' . $firstLabel . ' criteria-star-wrapper-id-' . $criteriId . '-form-' . $ratingFormId . '"></div> <div class="readonly_criteria_average_label_' . $theme_key . '_theme readonly-criteria-average-label criteria-average-label-form-' . $ratingFormId . '-label-' . $criteriId . '"> <span class="starTitle">' . sanitize_text_field($review->rating[$criteriId . '_stars'][$value - 1]) . '</span> </div> </div>'; } } $mainContent .= '</div><div class="clear" style="clear:both;"></div>'; // Question Display part. $mainContent .= ' <div data-form-id="' . $ratingFormId . '" class="question_wrapper_' . $theme_key . '_theme question-wrapper question-wrapper-form-' . $ratingFormId . '">'; if (!empty($review->question) && is_array($review->question)) { foreach ($review->question as $questionId => $value) { $single_question = $review->custom_question[$questionId]; $type = $single_question['field']['type']; if (is_array($value)) { //$single_question = $review->custom_question[$questionId]; //$type = $single_question['field']['type']; $seperated = isset($fieldArr['seperated']) ? intval($fieldArr['seperated']) : 0; $fieldArr = $single_question['field'][$type]; $valuesText = array(); foreach ($value as $key => $val) { $valuesText[$review->id][$questionId][] = '<strong>' . __(stripcslashes($fieldArr[$key]['text']), 'cbratingsystem') . '</strong>'; } if (!empty($valuesText)) { $mainContent .= ' <div data-form-id="' . $ratingFormId . '" data-q-id="' . $questionId . '" class="question_id_wrapper_' . $theme_key . '_theme question-id-wrapper-' . $questionId . ' question-id-wrapper-' . $questionId . '-form-' . $ratingFormId . ' "> <div class="question_label_wrapper_' . $theme_key . '_theme question-label-wrapper"> <span class="question-label question-label-id-' . $questionId . '" >' . (isset($review->custom_question[$questionId]) ? __(stripslashes($review->custom_question[$questionId]['title']), 'cbratingsystem') : '') . '</span> <span class="question-label-hiphen">' . (isset($review->custom_question[$questionId]) ? ' - ' : '') . '</span> <span class="answer"><strong>' . implode(', ', $valuesText[$review->id][$questionId]) . '</strong></span> </div> </div> '; } } else { /*$type = $review->custom_question['enabled'][$questionId]['field']['type']; $fieldArr = $review->custom_question['enabled'][$questionId]['field'][$type]; $seperated = $fieldArr['seperated'];*/ //$single_question = $review->custom_question[$questionId]; $seperated = isset($single_question['field']['type']['seperated']) ? intval($single_question['field']['type']['seperated']) : 0; //$type = $single_question['field']['type']; if ($seperated == 0) { if ($type == 'text') { $mainContent .= ' <div data-form-id="' . $ratingFormId . '" data-q-id="' . $questionId . '" class="question_id_wrapper_' . $theme_key . '_theme question-id-wrapper-' . $questionId . ' question-id-wrapper-' . $questionId . '-form-' . $ratingFormId . ' "> <div class="question_label_wrapper_' . $theme_key . '_theme question-label-wrapper"> <span class="question-label question-label-id-' . $questionId . '" >' . (isset($review->custom_question[$questionId]) ? __(stripslashes($review->custom_question[$questionId]['title']), 'cbratingsystem') : '') . '</span> <span class="question-label-hiphen">' . (isset($review->custom_question[$questionId]) ? ' - ' : '') . '</span> <span class="answer"><strong>' . $value . '</strong></span> </div> </div>'; } else { $fieldArr = $single_question['field'][$type]; $mainContent .= ' <div data-form-id="' . $ratingFormId . '" data-q-id="' . $questionId . '" class="question_id_wrapper_' . $theme_key . '_theme question-id-wrapper-' . $questionId . ' question-id-wrapper-' . $questionId . '-form-' . $ratingFormId . ' "> <div class="question_label_wrapper_' . $theme_key . '_theme question-label-wrapper"> <span class="question-label question-label-id-' . $questionId . '" >' . (isset($review->custom_question[$questionId]) ? __(stripslashes($review->custom_question[$questionId]['title']), 'cbratingsystem') : '') . '</span> <span class="question-label-hiphen">' . (isset($review->custom_question[$questionId]) ? ' - ' : '') . '</span> <span class="answer"><strong>' . ($value == 1 ? __('Yes', 'cbratingsystem') : __('No', 'cbratingsystem')) . '</strong></span> </div> </div>'; } } } //end of else } //end of foreach } $mainContent .= ' </div> <div class="clear" style="clear:both;"></div>'; // Comment Display part if (!empty($review->comment) and is_string($review->comment)) { $comment = CBRatingSystemFunctions::text_summary_mapper($review->comment); /* if ( is_array( $comment ) && ! empty( $comment['summury'] ) && isset( $comment['rest'] ) ) { $comment_output = ' <p class="comment"> ' . stripslashes( $comment['summury'] ) . ( ! empty( $comment['rest'] ) ? ' <span style="display:none;" class="read_more_paragraph disable_field">' . $comment['rest'] . '</span>' : '' ) . '</p> <a href="#" class="js_read_link read_more"> ...More</a>'; } else { $comment_output = '<p class="comment">' . stripslashes($comment['summury']) . '</p>'; } */ $comment_output = '<p class="comment">' . stripslashes($review->comment) . '</p>'; if ($reviewOptions['comment_status'] != 'approved') { if ($reviewOptions['comment_status'] == 'unverified') { $review_status = 'Your comment is' . $reviewOptions['comment_status'] . '[please check your mail to verify]'; } else { $review_status = $reviewOptions['comment_status']; } $mainContent .= '<div class="review_user_rating_comment_' . $theme_key . '_theme review_user_rating_comment"> <strong>Comment : </strong> ' . $comment_output . ' (' . $review_status . ')' . ' </div> <div class="clear" style="clear:both;"></div> '; } else { $mainContent .= '<div class="review_user_rating_comment_' . $theme_key . '_theme review_user_rating_comment"> <strong>Comment : </strong> ' . $comment_output . ' </div> <div class="clear" style="clear:both;"></div> '; } } } // end if ( ! empty( $review->rating ) and is_array( $review->rating ) ) $mainContent .= '</div>'; $mainContent .= '</div><div class="clear" style="clear:both;"></div>'; $shownReviews++; } // end foreach $output .= $mainContent; } // end if ( ! empty( $reviews ) and is_array( $reviews ) ) $jsSettings = self::front_end_review_js_settings($reviews, $jsArray, $post_id, $ajax); $output .= '<script type="text/javascript">' . $jsSettings . '</script>'; if ($ajax === true) { return array('html' => $mainContent . '<script type="text/javascript">' . $jsSettings . '</script>'); } $output = array($output, $review); return $output; } // end empty( $reviews[0] }