defaultsFieldsNames = [ wpdFormConst::WPDISCUZ_FORMS_NAME_FIELD, wpdFormConst::WPDISCUZ_FORMS_EMAIL_FIELD, wpdFormConst::WPDISCUZ_FORMS_WEBSITE_FIELD, wpdFormConst::WPDISCUZ_FORMS_CAPTCHA_FIELD, wpdFormConst::WPDISCUZ_FORMS_SUBMIT_FIELD]; $this->wpdOptions = $options; $this->setFormID($formID); $this->row = new Row(); $this->captchaFied = Captcha::getInstance(); } public function initFormMeta() { if ((int) $this->formID) { if (!$this->generalOptions) { $goptions = get_post_meta($this->formID, wpdFormConst::WPDISCUZ_META_FORMS_GENERAL_OPTIONS, true); $this->generalOptions = $goptions ? $goptions : []; } if (!$this->formeStructure) { $this->formeStructure = get_post_meta($this->formID, wpdFormConst::WPDISCUZ_META_FORMS_STRUCTURE, true); } } if (!$this->formPostTypes) { $this->formPostTypes = isset($this->generalOptions[wpdFormConst::WPDISCUZ_META_FORMS_POSTE_TYPES]) ? $this->generalOptions[wpdFormConst::WPDISCUZ_META_FORMS_POSTE_TYPES] : []; } } public function initFormFields() { if (!$this->formFields) { $this->formCustomFields = []; $this->formFields = get_post_meta($this->formID, wpdFormConst::WPDISCUZ_META_FORMS_FIELDS, true); if (is_array($this->formFields)) { foreach ($this->formFields as $key => $field) { if (is_callable($field["type"] . "::getInstance") && !in_array($key, $this->defaultsFieldsNames)) { if (!empty($field["icon"])) { $this->hasIcon = true; } $this->formCustomFields[$key] = $field; if ($field["type"] === "wpdFormAttr\Field\RatingField") { $this->ratingsFieldsKey[] = $key; } } } } if (count($this->ratingsFieldsKey)) { $this->ratingsExists = true; } } } public function getFormCustomFields() { return $this->formCustomFields; } public function setFormID($formID) { if ($formID == 0) { $this->formID = $formID; return; } $form = get_post($formID); if ($form && $form->post_type === wpdFormConst::WPDISCUZ_FORMS_CONTENT_TYPE) { $this->formID = $formID; do_action("wpdiscuz_form_init", $this); } else { $postRel = $this->wpdOptions->formPostRel; $contentRel = $this->wpdOptions->formContentTypeRel; foreach ($postRel as $pid => $fid) { if ($formID == $fid) { unset($postRel[$pid]); } } foreach ($contentRel as $postType => $postTypeData) { foreach ($postTypeData as $lang => $fid) { if ($formID == $fid) { unset($contentRel[$postType][$lang]); } } } update_option(wpdFormConst::WPDISCUZ_FORMS_CONTENT_TYPE_REL, $contentRel); update_option(wpdFormConst::WPDISCUZ_FORMS_POST_REL, $postRel); $this->formID = 0; } } public function getFormID() { return $this->formID; } public function getGeneralOptions() { return $this->generalOptions; } public function getHeaderTextSingle() { $this->initFormMeta(); if (!isset($this->generalOptions["header_text_single"])) { $this->generalOptions["header_text_single"] = esc_html__("Comment", "wpdiscuz"); } return $this->generalOptions["header_text_single"]; } public function getHeaderTextPlural() { $this->initFormMeta(); if (empty($this->generalOptions["header_text_plural"])) { $this->generalOptions["header_text_plural"] = esc_html__("Comments", "wpdiscuz"); } return $this->generalOptions["header_text_plural"]; } public function getTheme() { $this->initFormMeta(); if (empty($this->generalOptions["theme"])) { $this->generalOptions["theme"] = $this->getDefaultTheme(); } else { if (!is_dir($this->generalOptions["theme"])) { $themeName = wp_basename($this->generalOptions["theme"]); if (strpos($this->generalOptions["theme"], "plugins") === false) { $uplDir = wp_upload_dir(); $themesDir = str_replace("\\", "/", $uplDir["basedir"]) . wpdFormConst::THEMES_DIR; if (is_dir($themesDir . $themeName)) { $this->generalOptions["theme"] = $themesDir . $themeName; } else { $this->generalOptions["theme"] = $this->getDefaultTheme(); } } else { $themeDir = str_replace("\\", "/", WPDISCUZ_DIR_PATH) . "/themes/" . $themeName; if (is_dir($themeDir)) { $this->generalOptions["theme"] = $themeDir; } else { $this->generalOptions["theme"] = $this->getDefaultTheme(); } } } } return $this->generalOptions["theme"]; } public function getLayout() { $this->initFormMeta(); if (empty($this->generalOptions["layout"])) { $this->generalOptions["layout"] = 1; } return $this->generalOptions["layout"]; } public function getEnableRateOnPost() { $this->initFormMeta(); if (!array_key_exists("enable_post_rating", $this->generalOptions)) { $this->generalOptions["enable_post_rating"] = 1; } return (int) $this->generalOptions["enable_post_rating"]; } public function getPostRatingTitle() { $this->initFormMeta(); if (!isset($this->generalOptions["post_rating_title"])) { $this->generalOptions["post_rating_title"] = esc_html__("Article Rating", "wpdiscuz"); } return $this->generalOptions["post_rating_title"]; } public function getRatingsExists() { $this->initFormMeta(); $this->initFormFields(); return $this->ratingsExists; } public function getUserCanRateOnPost() { $this->initFormMeta(); if (!isset($this->generalOptions["allow_guests_rate_on_post"])) { $this->generalOptions["allow_guests_rate_on_post"] = 1; } return $this->generalOptions["allow_guests_rate_on_post"]; } public function getCaptchaFied() { return $this->captchaFied; } public function isShowSubscriptionBar() { return $this->generalOptions["show_subscription_bar"]; } public function isShowSubscriptionBarAgreement() { $this->initFormMeta(); return isset($this->generalOptions["show_subscription_agreement"]) ? $this->generalOptions["show_subscription_agreement"] : 0; } public function subscriptionBarAgreementLabel() { return isset($this->generalOptions["subscription_agreement_label"]) ? $this->generalOptions["subscription_agreement_label"] : esc_html__("I allow to use my email address and send notification about new comments and replies (you can unsubscribe at any time).", "wpdiscuz"); } public function getCustomCSS() { return get_post_meta($this->formID, wpdFormConst::WPDISCUZ_META_FORMS_CSS, true); } public function getFormPostTypes() { return $this->formPostTypes; } public function getFormFields() { return $this->formFields; } public function theFormListData($column, $formID) { $this->setFormID($formID); $this->generalOptions = get_post_meta($this->formID, wpdFormConst::WPDISCUZ_META_FORMS_GENERAL_OPTIONS, true); if ($column === "form_post_types") { $postTypes = isset($this->generalOptions[wpdFormConst::WPDISCUZ_META_FORMS_POSTE_TYPES]) ? $this->generalOptions[wpdFormConst::WPDISCUZ_META_FORMS_POSTE_TYPES] : ""; echo $postTypes ? htmlentities(implode(", ", $this->generalOptions[wpdFormConst::WPDISCUZ_META_FORMS_POSTE_TYPES])) : ""; } else if ($column === "form_post_ids") { echo isset($this->generalOptions["postid"]) ? htmlentities($this->generalOptions["postid"]) : ""; } else if ($column === "form_lang") { echo isset($this->generalOptions["lang"]) ? htmlentities($this->generalOptions["lang"]) : ""; } } public function saveFormData($formID) { $this->setFormID($formID); $this->initFormMeta(); if (isset($_REQUEST[wpdFormConst::WPDISCUZ_META_FORMS_GENERAL_OPTIONS])) { $generalOptions = $this->validateGeneralOptions($_REQUEST[wpdFormConst::WPDISCUZ_META_FORMS_GENERAL_OPTIONS]); $this->saveFormContentTypeRel($generalOptions[wpdFormConst::WPDISCUZ_META_FORMS_POSTE_TYPES], $generalOptions["lang"]); $this->saveFormPostRel($generalOptions["postidsArray"]); update_post_meta($this->formID, wpdFormConst::WPDISCUZ_META_FORMS_GENERAL_OPTIONS, $generalOptions); } if (isset($_REQUEST[wpdFormConst::WPDISCUZ_META_FORMS_STRUCTURE])) { $formeStructure = $this->validateFormStructure($_REQUEST[wpdFormConst::WPDISCUZ_META_FORMS_STRUCTURE]); update_post_meta($this->formID, wpdFormConst::WPDISCUZ_META_FORMS_STRUCTURE, $formeStructure); update_post_meta($this->formID, wpdFormConst::WPDISCUZ_META_FORMS_FIELDS, $this->formFields); } } public function saveCommentMeta($commentID) { $comment = get_comment($commentID); $commentApproved = $comment->comment_approved; do_action("wpdiscuz_before_save_commentmeta", $comment, $this->fieldsBeforeSave); foreach ($this->fieldsBeforeSave as $mettaKey => $data) { if ($this->ratingsExists && $this->formCustomFields[$mettaKey]["type"] === "wpdFormAttr\Field\RatingField") { $oldCommentRating = get_comment_meta($commentID, $mettaKey, true); $postID = $comment->comment_post_ID; if (!(class_exists("WooCommerce") && get_post_type($postID) === "product") && $oldCommentRating && $commentApproved === "1") { $postRatingMeta = get_post_meta($postID, wpdFormConst::WPDISCUZ_RATING_COUNT, true); $postRatingMeta = is_array($postRatingMeta) ? $postRatingMeta : []; $oldCommentRatingCount = $postRatingMeta[$mettaKey][$oldCommentRating] - 1; if ($oldCommentRatingCount > 0) { $postRatingMeta[$mettaKey][$oldCommentRating] = $oldCommentRatingCount; } else { unset($postRatingMeta[$mettaKey][$oldCommentRating]); } update_post_meta($postID, wpdFormConst::WPDISCUZ_RATING_COUNT, $postRatingMeta); $this->updateSeparateRatingMeta($postRatingMeta, $postID); } $this->ratings[] = ["metakey" => $mettaKey, "value" => $data]; } update_comment_meta($commentID, $mettaKey, $data); } if ($this->ratingsExists && $this->ratings) { $ratingSum = 0; foreach ($this->ratings as $k => $rating) { $ratingSum += (int) $rating["value"]; } $gRating = round($ratingSum / count($this->ratings)); update_comment_meta($commentID, "rating", $gRating); if ($commentApproved === "1") { $this->savePostRatingMeta($comment, $gRating); } } } private function savePostRatingMeta($comment, $rating) { $postID = $comment->comment_post_ID; if (class_exists("WooCommerce") && get_post_type($postID) === "product") { $ratingCount = get_post_meta($postID, "_wc_rating_count", true); $ratingCount = is_string($ratingCount) ? [] : $ratingCount; $oldRatingMeta = get_comment_meta($comment->comment_ID, "rating", true); $oldRating = $oldRatingMeta ? $oldRatingMeta : 0; if (isset($ratingCount[$oldRating])) { $oldRatingCount = $ratingCount[$oldRating] - 1; if ($oldRatingCount > 0) { $ratingCount[$oldRating] = $oldRatingCount; } else { unset($ratingCount[$oldRating]); } } if (isset($ratingCount[$rating])) { $ratingCount[$rating] = $ratingCount[$rating] + 1; } else if ($rating) { $ratingCount[$rating] = 1; } $allRatingSum = 0; $allCount = 0; foreach ($ratingCount as $star => $count) { $allRatingSum += $star * $count; $allCount += $count; } if ($allCount) { $averageRating = round($allRatingSum / $allCount, 2); update_post_meta($postID, "_wc_average_rating", $averageRating); update_post_meta($postID, "_wc_rating_count", $ratingCount); } } else { $wpdiscuzRatingCountMeta = get_post_meta($postID, wpdFormConst::WPDISCUZ_RATING_COUNT, true); $wpdiscuzRatingCount = $wpdiscuzRatingCountMeta && is_array($wpdiscuzRatingCountMeta) ? $wpdiscuzRatingCountMeta : []; $wpdiscuzRatingCount = $this->cleanUnusedData($wpdiscuzRatingCount, $this->ratings); foreach ($this->ratings as $key => $value) { if (isset($wpdiscuzRatingCount[$value["metakey"]][$value["value"]])) { $wpdiscuzRatingCount[$value["metakey"]][$value["value"]] = $wpdiscuzRatingCount[$value["metakey"]][$value["value"]] + 1; } else if ($value["value"]) { $wpdiscuzRatingCount[$value["metakey"]][$value["value"]] = 1; } } update_post_meta($postID, wpdFormConst::WPDISCUZ_RATING_COUNT, $wpdiscuzRatingCount); $this->updateSeparateRatingMeta($wpdiscuzRatingCount, $postID); } } private function cleanUnusedData($ratingMeta, $ratings) { $ratingMetaKeys = array_keys($ratingMeta); foreach ($ratingMetaKeys as $key => $ratingMetaKey) { $exists = false; foreach ($ratings as $k => $rating) { if ($rating["metakey"] === $ratingMetaKey) { $exists = true; break; } } if (!$exists) { unset($ratingMeta[$ratingMetaKey]); } } return $ratingMeta; } public function displayRatingMeta($content) { global $post; if (!(class_exists("WooCommerce") && get_post_type($post) === "product")) { $this->initFormFields(); if (in_array("before", $this->wpdOptions->rating["displayRatingOnPost"])) { if ($this->ratingsExists) { $content = $this->getRatingMetaHtml() . $content; } else if ($this->getEnableRateOnPost()) { $content = $this->getPostRatingHtml() . $content; } } if (in_array("after", $this->wpdOptions->rating["displayRatingOnPost"])) { if ($this->ratingsExists) { $content .= $this->getRatingMetaHtml(); } else if ($this->getEnableRateOnPost()) { $content .= $this->getPostRatingHtml(); } } } return $content; } public function displayRatingMetaBeforeCommentForm() { global $post; $content = ""; if (!(class_exists("WooCommerce") && get_post_type($post) === "product")) { if (in_array("before_comment_form", $this->wpdOptions->rating["displayRatingOnPost"])) { if ($this->ratingsExists) { $content = $this->getRatingMetaHtml(); } else if ($this->getEnableRateOnPost()) { $content = $this->getPostRatingHtml(); } } } echo $content; } public function getPostRatingHtml($can_rate = true) { $html = ""; $wpdiscuz = wpDiscuz(); if ($wpdiscuz->isWpdiscuzLoaded && $this->getEnableRateOnPost() && (($this->wpdOptions->rating["ratingCssOnNoneSingular"] && !is_singular()) || is_singular())) { global $post; $currentUserId = get_current_user_id(); $class = ""; if ($can_rate && is_singular()) { if (!empty($currentUserId)) { $class = wpDiscuz()->dbManager->isUserRated($currentUserId, "", $post->ID) ? "" : " class='wpd-not-rated'"; } else if ($this->getUserCanRateOnPost()) { $class = wpDiscuz()->dbManager->isUserRated(0, md5(wpDiscuz()->helper->getRealIPAddr()), $post->ID) ? "" : " class='wpd-not-rated'"; } } $rating = (float) get_post_meta($post->ID, wpdFormConst::POSTMETA_POST_RATING, true); $count = (int) get_post_meta($post->ID, wpdFormConst::POSTMETA_POST_RATING_COUNT, true); $prefix = (int) $rating; $suffix = $rating - $prefix; $fullStarSVG = apply_filters("wpdiscuz_full_star_svg", "", "post", "fas fa-star"); $halfStarSVG = apply_filters("wpdiscuz_half_star_svg", "", "post", "fas fa-star"); $html .= "
" . esc_html($rating) . " " . esc_html($count) . " " . ((int) $count === 1 ? esc_html($this->wpdOptions->getPhrase("wc_vote_phrase")) : esc_html($this->wpdOptions->getPhrase("wc_votes_phrase"))) . ""; $html .= "
" . esc_html($this->getPostRatingTitle()) . "
"; if ($prefix) { for ($i = 1; $i < 6; $i++) { if ($i <= $prefix) { $html .= str_replace("wpd-star", "wpd-star wpd-active", $fullStarSVG); } else if ($suffix && $i - $prefix === 1) { $html .= $halfStarSVG; } else { $html .= $fullStarSVG; } } } else if ($suffix) { $html .= $halfStarSVG . str_repeat($fullStarSVG, 4); } else { $html .= str_repeat($fullStarSVG, 5); } $html .= "
"; if ($class) { $html .= "
" . str_repeat($fullStarSVG, 5) . "
"; } $html .= "
"; if ($this->wpdOptions->rating["enablePostRatingSchema"] && $count) { $html .= apply_filters("wpdiscuz_rating_schema", "
", "post", $post->ID); } } return $html; } public function getRatingMetaHtml($atts = []) { $html = ""; $atts = shortcode_atts([ "metakey" => "all", "show-label" => true, "show-lable" => true, "show-average" => true, "itemprop" => !!$this->wpdOptions->rating["enablePostRatingSchema"], "post_id" => null, "postid" => null, ], $atts); if (!$atts["postid"]) { if ($atts["post_id"]) { $post = get_post($atts["post_id"]); unset($atts["post_id"]); } else { global $post; } if (!empty($post->ID)) { $atts["postid"] = $post->ID; $this->resetData(); $wpdiscuz = wpDiscuz(); $form = $wpdiscuz->wpdiscuzForm->getForm($post->ID); if (is_rtl()) { wp_enqueue_style("wpdiscuz-ratings-rtl"); } else { wp_enqueue_style("wpdiscuz-ratings"); } $html = $form->getRatingMetaHtml($atts); $form->resetData(); global $post; $form = $wpdiscuz->wpdiscuzForm->getForm($post->ID); return $html; } } else { $post = get_post($atts["postid"]); $this->initFormFields(); if ($this->ratingsExists && (($this->wpdOptions->rating["ratingCssOnNoneSingular"] && !is_singular()) || is_singular())) { $ratingList = []; foreach (array_unique($this->ratingsFieldsKey) as $key => $field) { $avg = floatval(get_post_meta($post->ID, wpdFormConst::WPDISCUZ_RATING_SEPARATE_AVG . $field, true)); $c = intval(get_post_meta($post->ID, wpdFormConst::WPDISCUZ_RATING_SEPARATE_COUNT . $field, true)); $ratingList[$field]["average"] = $avg ? $avg : 0; $ratingList[$field]["count"] = $c ? $c : 0; } if ($ratingList) { $atts["show-label"] = filter_var($atts['show-label'], FILTER_VALIDATE_BOOLEAN); if (!filter_var($atts['show-lable'], FILTER_VALIDATE_BOOLEAN)) { $atts["show-label"] = false; } $html .= "
"; if (!isset($atts["metakey"]) || $atts["metakey"] === "" || $atts["metakey"] === "all") { foreach ($ratingList as $key => $value) { $html .= $this->getSingleRatingHtml($key, $value, $atts); } if ($atts["itemprop"]) { $html .= $this->getRatingSchema($atts["metakey"], $ratingList, $atts["postid"]); } } else { $html .= $this->getSingleRatingHtml($atts["metakey"], $ratingList[$atts["metakey"]], $atts); if ($atts["itemprop"] && $ratingList[$atts["metakey"]]["count"]) { $html .= $this->getRatingSchema($atts["metakey"], $ratingList, $atts["postid"]); } } $html .= "
"; } } } return $html; } private function getSingleRatingHtml($metakey, $ratingData, $args) { global $post; $html = ""; if (key_exists($metakey, $this->formCustomFields)) { $title = !empty($this->formCustomFields[$metakey]["nameForTotal"]) ? $this->formCustomFields[$metakey]["nameForTotal"] : $this->formCustomFields[$metakey]["name"]; $icon = $this->formCustomFields[$metakey]['icon']; $icon = strpos(trim($icon), ' ') ? $icon : 'fas ' . $icon; $fullStarSVG = apply_filters("wpdiscuz_full_star_svg", "", "custom_field", $icon); $halfStarSVG = apply_filters("wpdiscuz_half_star_svg", "", "custom_field", $icon); $html = "
" . esc_html($ratingData["average"]) . " " . esc_html($ratingData["count"]) . " " . ((int) $ratingData["count"] === 1 ? esc_html($this->wpdOptions->getPhrase("wc_vote_phrase")) : esc_html($this->wpdOptions->getPhrase("wc_votes_phrase"))) . ""; $html .= "
"; if ($args["show-label"]) { $html .= "
" . esc_html($title) . "
"; } $html .= "
"; $prefix = (int) $ratingData['average']; $suffix = $ratingData['average'] - $prefix; if ($prefix) { for ($i = 1; $i < 6; $i++) { if ($i <= $prefix) { $html .= str_replace("wpd-star", "wpd-star wpd-active", $fullStarSVG); } else if ($suffix && $i - $prefix === 1) { $html .= $halfStarSVG; } else { $html .= $fullStarSVG; } } } else if ($suffix) { $html .= $halfStarSVG . str_repeat($fullStarSVG, 4); } else { $html .= str_repeat($fullStarSVG, 5); } $html .= "
"; } return $html; } private function getRatingSchema($key, $ratingList, $postId) { $average = 0; $count = 0; if ($key === "" || $key === "all") { foreach ($ratingList as $k => $value) { if (isset($this->formCustomFields[$k]) && $ratingList[$k]["count"]) { $average += $ratingList[$k]["average"]; $count++; } } if ($count) { $average = round($average / $count, 1); } } else if (isset($this->formCustomFields[$key]) && $ratingList[$key]["count"]) { $average = $ratingList[$key]["average"]; $count = $ratingList[$key]["count"]; } $schema = ""; if ($average) { $schema = apply_filters("wpdiscuz_rating_schema", "
", $key, $postId); } return $schema; } private function validateGeneralOptions($options) { $validData = [ "lang" => get_user_locale(), "roles_cannot_see_comments" => [], "guest_can_see_comments" => 1, "roles_cannot_comment" => [], "guest_can_comment" => 1, "show_subscription_bar" => 1, "header_text_single" => "", "header_text_plural" => "", wpdFormConst::WPDISCUZ_META_FORMS_POSTE_TYPES => [], "postid" => "", "postidsArray" => [], "show_subscription_agreement" => 0, "subscription_agreement_label" => esc_html__("I allow to use my email address and send notification about new comments and replies (you can unsubscribe at any time).", "wpdiscuz"), "theme" => $this->getDefaultTheme(), "layout" => 1, "enable_post_rating" => 1, "post_rating_title" => esc_html__("Article Rating", "wpdiscuz"), "allow_guests_rate_on_post" => 1, ]; if (isset($options["roles_cannot_see_comments"])) { $validData["roles_cannot_see_comments"] = array_map("trim", $options["roles_cannot_see_comments"]); } if (isset($options["guest_can_see_comments"])) { $validData["guest_can_see_comments"] = intval($options["guest_can_see_comments"]); } if (isset($options["roles_cannot_comment"])) { $validData["roles_cannot_comment"] = array_map("trim", $options["roles_cannot_comment"]); } if (isset($options["guest_can_comment"])) { $validData["guest_can_comment"] = intval($options["guest_can_comment"]); } if (isset($options["header_text_single"])) { $validData["header_text_single"] = $options["header_text_single"]; } if (isset($options["header_text_plural"])) { $validData["header_text_plural"] = $options["header_text_plural"]; } if (isset($options["lang"])) { $validData["lang"] = $options["lang"]; } if (isset($options["show_subscription_bar"])) { $validData["show_subscription_bar"] = intval($options["show_subscription_bar"]); } if (isset($options["show_subscription_agreement"])) { $validData["show_subscription_agreement"] = intval($options["show_subscription_agreement"]); } if (isset($options["subscription_agreement_label"]) && trim($options["subscription_agreement_label"])) { $validData["subscription_agreement_label"] = $options["subscription_agreement_label"]; } $themes = $this->getThemes(); if (isset($options["theme"]) && isset($themes[$options["theme"]])) { $validData["theme"] = $options["theme"]; } $layouts = $this->getLayouts($validData["theme"]); if (isset($options["layout"]) && ($layout = intval($options["layout"])) && in_array($layout, $layouts)) { $validData["layout"] = $layout; } else if (!empty($layouts[0])) { $validData["layout"] = $layouts[0]; } if (array_key_exists("enable_post_rating", $options)) { $validData["enable_post_rating"] = intval($options["enable_post_rating"]); } if (!empty($options["post_rating_title"])) { $validData["post_rating_title"] = $options["post_rating_title"]; } if (isset($options["allow_guests_rate_on_post"])) { $validData["allow_guests_rate_on_post"] = intval($options["allow_guests_rate_on_post"]); } if (isset($options[wpdFormConst::WPDISCUZ_META_FORMS_POSTE_TYPES])) { $validData[wpdFormConst::WPDISCUZ_META_FORMS_POSTE_TYPES] = $options[wpdFormConst::WPDISCUZ_META_FORMS_POSTE_TYPES]; } if (isset($options["postid"])) { $postIds = trim(strip_tags($options["postid"])); if ($postIds) { $postIdsArray = []; $postIdsExplode = explode(",", $postIds); foreach ($postIdsExplode as $k => $postId) { $postId = intval($postId); if ($postId) { $postIdsArray[] = $postId; } } $postIdsArray = array_unique($postIdsArray); sort($postIdsArray); $validData["postidsArray"] = $postIdsArray; $postIds = implode(", ", $postIdsArray); } $validData["postid"] = $postIds; } return $validData; } private function validateFormStructure($formStructure) { $this->formFields = []; foreach ($formStructure as $rowID => $rowData) { $sanitizeData = $this->row->sanitizeRowData($rowData, $this->formFields); if ($sanitizeData) { $formStructure[$rowID] = $sanitizeData; } else { unset($formStructure[$rowID]); } } return $formStructure; } public function validateFields($currentUser) { $allowedFieldsType = $this->row->allowedFieldsType(); foreach ($this->formCustomFields as $fieldName => $fieldArgs) { $fieldType = $fieldArgs["type"]; if (!in_array($fieldType, $allowedFieldsType, true)) { continue; } $field = call_user_func($fieldType . "::getInstance"); if (isset($fieldArgs["no_insert_meta"])) { $field->validateFieldData($fieldName, $fieldArgs, $this->wpdOptions, $currentUser); } else { $this->fieldsBeforeSave[$fieldName] = $field->validateFieldData($fieldName, $fieldArgs, $this->wpdOptions, $currentUser); } } } public function validateDefaultCaptcha($currentUser) { $args = $this->formFields[wpdFormConst::WPDISCUZ_FORMS_CAPTCHA_FIELD]; $this->captchaFied->validateFieldData(wpdFormConst::WPDISCUZ_FORMS_CAPTCHA_FIELD, $args, $this->wpdOptions, $currentUser); } public function validateSubscribtionCaptcha($addSubscription) { if (!is_user_logged_in() && $this->wpdOptions->recaptcha["isShowOnSubscribeForm"]) { $addSubscription = $this->captchaFied->reCaptchaValidate($this->wpdOptions); } return $addSubscription; } public function validateDefaultEmail($currentUser, &$isAnonymous) { $emailField = Field\DefaultField\Email::getInstance(); $args = $this->formFields[wpdFormConst::WPDISCUZ_FORMS_EMAIL_FIELD]; $email = $emailField->validateFieldData(wpdFormConst::WPDISCUZ_FORMS_EMAIL_FIELD, $args, $this->wpdOptions, $currentUser); $isAnonymous = $emailField->isAnonymous(); return $email; } public function validateDefaultName($currentUser) { $nameField = Field\DefaultField\Name::getInstance(); $args = $this->formFields[wpdFormConst::WPDISCUZ_FORMS_NAME_FIELD]; return $nameField->validateFieldData(wpdFormConst::WPDISCUZ_FORMS_NAME_FIELD, $args, $this->wpdOptions, $currentUser); } public function validateDefaultWebsite($currentUser) { $webSiteField = Field\DefaultField\Website::getInstance(); $args = $this->formFields[wpdFormConst::WPDISCUZ_FORMS_WEBSITE_FIELD]; return $webSiteField->validateFieldData(wpdFormConst::WPDISCUZ_FORMS_WEBSITE_FIELD, $args, $this->wpdOptions, $currentUser); } public function renderFrontCommentMetaHtml($commentID, &$output) { $htmlExists = false; if ($this->formCustomFields) { $meta = get_comment_meta($commentID); $top = $this->_renderFrontCommentMetaHtml($meta, $this->formCustomFields, "top"); $bottom = $this->_renderFrontCommentMetaHtml($meta, $this->formCustomFields, "bottom"); if ($top || $bottom) { $htmlExists = true; } $top = ($top) ? "
" . $top . "
" : ""; $bottom = ($bottom) ? "
" . $bottom . "
" : ""; $output = $top . $output . $bottom; } return $htmlExists; } private function _renderFrontCommentMetaHtml($meta, $formCustomFields, $loc) { $html = ""; $allowedFieldsType = $this->row->allowedFieldsType(); foreach ($formCustomFields as $key => $value) { if (isset($value["loc"]) && $value["loc"] == $loc) { $fieldType = $value["type"]; $metaValuen = isset($meta[$key][0]) ? maybe_unserialize($meta[$key][0]) : ""; if (in_array($fieldType, $allowedFieldsType, true) && is_callable($fieldType . "::getInstance") && $metaValuen) { $field = call_user_func($fieldType . "::getInstance"); $html .= $field->drawContent($metaValuen, $value); } } } return $html; } public function renderFrontForm($isMain, $uniqueId, $commentsCount, $currentUser, $postID) { $message = ""; ?>
" >
isUserCanComment($currentUser, $message)) { ?>
" method="post" enctype="multipart/form-data" data-uploading="false">
wpdOptions->form["richEditor"] === "desktop") ? "" : "wpd-txt"; ?>"> wpdOptions->thread_layouts["showAvatars"] && $this->wpdOptions->wp["showAvatars"]) { ?> ID ? $currentUser->display_name : "guest"; $authorEmail = $currentUser->ID ? $currentUser->user_email : "unknown@example.com"; ?>
ID, 56, "", $authorName, ["wpdiscuz_current_user" => $currentUser, "wpdiscuz_gravatar_user_email" => $authorEmail]); ?>
renderTextEditor($uniqueId, $commentsCount); ?>
wpdOptions->form["commentFormView"] === "collapsed" ? "style='display:none;'" : ""; ?>>
formeStructure as $k => $row) { $this->row->renderFrontFormRow($row, $this->wpdOptions, $currentUser, $uniqueId, $isMain); } ?>
wpdOptions->isGoodbyeCaptchaActive) { echo $this->wpdOptions->goodbyeCaptchaTocken; } ?>
wpdOptions->form["richEditor"] === "both" || (!wp_is_mobile() && $this->wpdOptions->form["richEditor"] === "desktop")) { ?> wpdOptions->getPhrase("wc_comment_join_text", ["unique_id" => $uniqueId]); } else { $textarea_placeholder = $this->wpdOptions->getPhrase("wc_be_the_first_text", ["unique_id" => $uniqueId]); } if (strrchr($uniqueId, "_") === "_0") { $commentTextMinLength = intval($this->wpdOptions->content["commentTextMinLength"]); $commentTextMaxLength = intval($this->wpdOptions->content["commentTextMaxLength"]); } else { $commentTextMinLength = intval($this->wpdOptions->content["replyTextMinLength"]); $commentTextMaxLength = intval($this->wpdOptions->content["replyTextMaxLength"]); } $commentTextLengthRange = ($commentTextMinLength && $commentTextMaxLength) ? 'pattern=".{' . $commentTextMinLength . ',' . $commentTextMaxLength . '}"' : ''; $textareaMaxLength = $commentTextMaxLength ? "maxlength=$commentTextMaxLength" : ''; ?>
wpdOptions->form["boldButton"]) { $editorButtons[] = ["class" => "ql-bold", "value" => "", "name" => "", "title" => __("Bold", "wpdiscuz"), "svg" => ""]; } if ($this->wpdOptions->form["italicButton"]) { $editorButtons[] = ["class" => "ql-italic", "value" => "", "name" => "", "title" => __("Italic", "wpdiscuz"), "svg" => ""]; } if ($this->wpdOptions->form["underlineButton"]) { $editorButtons[] = ["class" => "ql-underline", "value" => "", "name" => "", "title" => __("Underline", "wpdiscuz"), "svg" => ""]; } if ($this->wpdOptions->form["strikeButton"]) { $editorButtons[] = ["class" => "ql-strike", "value" => "", "name" => "", "title" => __("Strike", "wpdiscuz"), "svg" => ""]; } if ($this->wpdOptions->form["olButton"]) { $editorButtons[] = ["class" => "ql-list", "value" => "ordered", "name" => "", "title" => __("Ordered List", "wpdiscuz"), "svg" => ""]; } if ($this->wpdOptions->form["ulButton"]) { $editorButtons[] = ["class" => "ql-list", "value" => "bullet", "name" => "", "title" => __("Unordered List", "wpdiscuz"), "svg" => ""]; } if ($this->wpdOptions->form["blockquoteButton"]) { $editorButtons[] = ["class" => "ql-blockquote", "value" => "", "name" => "", "title" => __("Blockquote", "wpdiscuz"), "svg" => ""]; } if ($this->wpdOptions->form["codeblockButton"]) { $editorButtons[] = ["class" => "ql-code-block", "value" => "", "name" => "", "title" => __("Code Block", "wpdiscuz"), "svg" => ""]; } if ($this->wpdOptions->form["linkButton"]) { $editorButtons[] = ["class" => "ql-link", "value" => "", "name" => "", "title" => __("Link", "wpdiscuz"), "svg" => ""]; } if ($this->wpdOptions->form["sourcecodeButton"]) { $editorButtons[] = ["class" => "ql-sourcecode", "value" => "", "name" => "sourcecode", "title" => __("Source Code", "wpdiscuz"), "svg" => "{}"]; } if ($this->wpdOptions->form["spoilerButton"]) { $editorButtons[] = ["class" => "ql-spoiler", "value" => "", "name" => "spoiler", "title" => __("Spoiler", "wpdiscuz"), "svg" => "[+]"]; } $editorButtons = apply_filters("wpdiscuz_editor_buttons", $editorButtons, $uniqueId); $editorButtonsHtml = apply_filters("wpdiscuz_editor_buttons_html", "", $uniqueId); ?>
> $editorButton) { $value = $editorButton["value"] ? "value='" . esc_attr($editorButton["value"]) . "'" : ""; $dataName = $editorButton["name"] ? "data-wpde_button_name='" . esc_attr($editorButton["name"]) . "'" : ""; ?>
comment_ID . "_" . $comment->comment_parent; $html = "
"; $html .= "
"; $content = str_replace(["", ""], ["`", "`"], ($this->wpdOptions->form["richEditor"] === "both" || (!wp_is_mobile() && $this->wpdOptions->form["richEditor"] === "desktop") ? str_replace(["

\n", "
\n"], ["


", "
"], wpautop($comment->comment_content)) : $comment->comment_content)); ob_start(); $this->renderTextEditor("edit_" . $uniqueId, 1); $html .= ob_get_clean(); $html .= "
"; if ($this->formCustomFields) { $html .= ""; $allowedFieldsType = $this->row->allowedFieldsType(); foreach ($this->formCustomFields as $key => $data) { $fieldType = $data["type"]; if (in_array($fieldType, $allowedFieldsType, true)) { $field = call_user_func($fieldType . "::getInstance"); $value = get_comment_meta($comment->comment_ID, $key, true); $html .= $field->editCommentHtml($key, $value, $data, $comment); } } $html .= "
"; } $html .= ""; $html .= "
"; ob_start(); do_action("comment_form", $comment->comment_post_ID); $html .= ob_get_clean(); $html .= "
"; return wp_send_json_success(['html' => $html, 'content' => $content]); } public function renderEditAdminCommentForm($comment) { if ($this->formCustomFields) { ?>
row->allowedFieldsType(); foreach ($this->formCustomFields as $key => $data) { $fieldType = $data["type"]; if (in_array($fieldType, $allowedFieldsType, true)) { $field = call_user_func($fieldType . "::getInstance"); $value = get_comment_meta($comment->comment_ID, $key, true); echo $field->editCommentHtml($key, $value, $data, $comment); } } ?>
comment_parent); ?>">
initFormMeta(); $blogRoles = get_editable_roles(); ?>
getThemes()) { $theme = !empty($this->generalOptions["theme"]) && isset($themes[$this->generalOptions["theme"]]) ? $this->generalOptions["theme"] : $this->getDefaultTheme(); if (count($themes) > 1) { ?> getLayouts($theme)) && count($layouts) > 1) { ?>
generalOptions["lang"]) ? $this->generalOptions["lang"] : get_user_locale(); ?> " target="_blank">
generalOptions["roles_cannot_comment"]) ? $this->generalOptions["roles_cannot_comment"] : []; foreach ($blogRoles as $role => $info) { if ($role !== "administrator") { ?>
value="" name="[roles_cannot_comment][]" id="wpd-" style="margin:0px; vertical-align: middle;"/>
" target="_blank">
generalOptions["guest_can_comment"]) ? $this->generalOptions["guest_can_comment"] : 1; ?> type="radio" name="[guest_can_comment]" value="1" id="wpd_cf_guest_yes">   type="radio" name="[guest_can_comment]" value="0" id="wpd_cf_guest_no"> " target="_blank">

generalOptions["roles_cannot_see_comments"]) ? $this->generalOptions["roles_cannot_see_comments"] : []; foreach ($blogRoles as $role => $info) { if ($role !== "administrator") { ?>
value="" name="[roles_cannot_see_comments][]" id="wpd-cannot-see-comments-" style="margin:0px; vertical-align: middle;"/>

generalOptions["guest_can_see_comments"]) ? $this->generalOptions["guest_can_see_comments"] : 1; ?> type="radio" name="[guest_can_see_comments]" value="1" id="wpd_csc_guest_yes">   type="radio" name="[guest_can_see_comments]" value="0" id="wpd_csc_guest_no">
generalOptions["show_subscription_bar"]) ? $this->generalOptions["show_subscription_bar"] : 1; ?> type="radio" name="[show_subscription_bar]" value="1" id="wpd_cf_sbbar_yes">   type="radio" name="[show_subscription_bar]" value="0" id="wpd_cf_sbbar_no"> " target="_blank">
generalOptions["show_subscription_agreement"]) ? $this->generalOptions["show_subscription_agreement"] : 0; ?> type="radio" name="[show_subscription_agreement]" value="1" id="wpd_cf_sbbar_agreement_yes">   type="radio" name="[show_subscription_agreement]" value="0" id="wpd_cf_sbbar_agreement_no"> " target="_blank">
generalOptions["subscription_agreement_label"]) && $this->generalOptions["subscription_agreement_label"] ? $this->generalOptions["subscription_agreement_label"] : esc_html__("I allow to use my email address and send notification about new comments and replies (you can unsubscribe at any time).", "wpdiscuz"); ?>
" value="generalOptions["header_text_single"]) ? htmlentities($this->generalOptions["header_text_single"], ENT_QUOTES) : esc_html__("Comment", "wpdiscuz"); ?>" style="width:80%;">
" target="_blank">
" value="generalOptions["header_text_plural"]) ? htmlentities($this->generalOptions["header_text_plural"], ENT_QUOTES) : esc_html__("Comments", "wpdiscuz"); ?>" style="width:80%;">
" target="_blank">
formPostTypes = $this->formPostTypes ? $this->formPostTypes : []; $registeredPostTypes = get_post_types(["public" => true]); $formContentTypeRel = $this->wpdOptions->formContentTypeRel; $hasForm = false; $formRelExistsInfo = "

" . esc_html__("The red marked post types are already attached to other comment form. If you set this form too, the old forms will not be used for them.", "wpdiscuz") . "

"; foreach ($registeredPostTypes as $typeKey => $typeValue) { if (!post_type_supports($typeKey, "comments")) { continue; } $checked = array_key_exists($typeKey, $this->formPostTypes) ? "checked" : ""; $formRelExistsClass = ""; if (!$checked && !empty($formContentTypeRel[$typeKey][$lang])) { $formRelExistsClass = "wpd-form-rel-exixts"; $hasForm = true; } ?> " target="_blank">

generalOptions["postid"], ENT_QUOTES) : ""; ?>" style="width:80%;"> " target="_blank">
$val) { ?> type="radio" name="[theme]" value="" id="wpd_cf_theme_">  
generalOptions["layout"]) ? $this->generalOptions["layout"] : $layouts[0]; foreach ($layouts as $k => $value) { ?>
" class="wpd-com-layout-" style="height: 85px;"/> "/>

type="radio" name="[layout]" value="" id="wpd_cf_layout_">

" target="_blank">
generalOptions) ? $this->generalOptions["enable_post_rating"] : 1; ?> type="radio" name="[enable_post_rating]" value="1" id="wpd_enable_post_rating_yes">   type="radio" name="[enable_post_rating]" value="0" id="wpd_enable_post_rating_no"> " target="_blank">
" value="generalOptions["post_rating_title"]) ? htmlentities($this->generalOptions["post_rating_title"], ENT_QUOTES) : esc_html__("Article Rating", "wpdiscuz"); ?>" style="width:80%;">
generalOptions["allow_guests_rate_on_post"]) ? $this->generalOptions["allow_guests_rate_on_post"] : 1; ?> type="radio" name="[allow_guests_rate_on_post]" value="1" id="wpd_allow_guests_rate_on_post_yes">   type="radio" name="[allow_guests_rate_on_post]" value="0" id="wpd_allow_guests_rate_on_post_no"> " target="_blank">
formeStructure) { foreach ($this->formeStructure as $id => $rowData) { $this->row->dashboardForm($id, $rowData); } } else { $this->row->dashboardForm("wpd_form_row_wrap_0", $this->defaultFieldsData()); } ?>
initFormMeta(); $this->isUserCanSeeComments = true; if ($currentUser && $currentUser->ID) { if ($post->post_author && $post->post_author != $currentUser->ID && $currentUser->roles && is_array($currentUser->roles)) { $this->generalOptions["roles_cannot_see_comments"] = isset($this->generalOptions["roles_cannot_see_comments"]) ? $this->generalOptions["roles_cannot_see_comments"] : []; foreach ($currentUser->roles as $k => $role) { if (in_array($role, $this->generalOptions["roles_cannot_see_comments"])) { //Filter hook to add extra conditions in user role dependent restriction. $this->isUserCanSeeComments = apply_filters("wpdiscuz_user_role_can_see_comments", false, $role); break; } } } } else { $this->isUserCanSeeComments = $this->generalOptions["guest_can_see_comments"] = isset($this->generalOptions["guest_can_see_comments"]) ? $this->generalOptions["guest_can_see_comments"] : 1; } return $this->isUserCanSeeComments; } public function isUserCanComment($currentUser, $postId = 0, &$message = "") { global $post; if (!$post) { $post = get_post($postId); } $user_can_comment = true; $this->initFormMeta(); if ($currentUser && $currentUser->ID) { if ($post->post_author && $post->post_author != $currentUser->ID && $currentUser->roles && is_array($currentUser->roles)) { $postId = $post && isset($post->ID) ? $post->ID : $postId; $this->generalOptions["roles_cannot_comment"] = isset($this->generalOptions["roles_cannot_comment"]) ? $this->generalOptions["roles_cannot_comment"] : []; $this->generalOptions["roles_cannot_see_comments"] = isset($this->generalOptions["roles_cannot_see_comments"]) ? $this->generalOptions["roles_cannot_see_comments"] : []; foreach ($currentUser->roles as $k => $role) { if (in_array($role, $this->generalOptions["roles_cannot_see_comments"]) || in_array($role, $this->generalOptions["roles_cannot_comment"])) { //Filter hook to add extra conditions in user role dependent restriction. $user_can_comment = apply_filters("wpdiscuz_user_role_can_comment", false, $role); $message = $this->wpdOptions->getPhrase("wc_roles_cannot_comment_message"); break; } } } } else { $this->generalOptions["guest_can_see_comments"] = isset($this->generalOptions["guest_can_see_comments"]) ? $this->generalOptions["guest_can_see_comments"] : 1; $user_can_comment = $this->generalOptions["guest_can_see_comments"] && $this->generalOptions["guest_can_comment"]; } if ($user_can_comment && class_exists("WooCommerce") && get_post_type($postId) === "product") { if (get_option("woocommerce_review_rating_verification_required") === "no" || wc_customer_bought_product("", get_current_user_id(), $postId)) { $user_can_comment = true; } else { $user_can_comment = false; $message = "

" . esc_html__("Only logged in customers who have purchased this product may leave a review.", "woocommerce") . "

"; } } $this->isUserCanComment = $user_can_comment; return $user_can_comment; } public function defaultFieldsData() { return [ "column_type" => "two", "row_order" => 0, "default" => 1, "left" => [ wpdFormConst::WPDISCUZ_FORMS_NAME_FIELD => [ "type" => "wpdFormAttr\Field\DefaultField\Name", "name" => esc_html__("Name", "wpdiscuz"), "desc" => "", "icon" => "fas fa-user", "required" => "1" ], wpdFormConst::WPDISCUZ_FORMS_EMAIL_FIELD => [ "type" => "wpdFormAttr\Field\DefaultField\Email", "name" => esc_html__("Email", "wpdiscuz"), "desc" => "", "icon" => "fas fa-at", "required" => "1" ], wpdFormConst::WPDISCUZ_FORMS_WEBSITE_FIELD => [ "type" => "wpdFormAttr\Field\DefaultField\Website", "name" => esc_html__("Website", "wpdiscuz"), "desc" => "", "icon" => "fas fa-link", "enable" => "1" ], ], "right" => [ wpdFormConst::WPDISCUZ_FORMS_CAPTCHA_FIELD => [ "type" => "wpdFormAttr\Field\DefaultField\Captcha", "name" => "", "desc" => "", "show_for_guests" => "0", "show_for_users" => "0" ], wpdFormConst::WPDISCUZ_FORMS_SUBMIT_FIELD => [ "type" => "wpdFormAttr\Field\DefaultField\Submit", "name" => esc_html__("Post Comment", "wpdiscuz") ], ], ]; } private function saveFormContentTypeRel($data, $lang) { $contentType = get_option(wpdFormConst::WPDISCUZ_FORMS_CONTENT_TYPE_REL, []); foreach ($this->formPostTypes as $k => $formPostType) { if (!in_array($formPostType, $data)) { unset($contentType[$formPostType][$lang]); } } foreach ($data as $type => $lable) { if (isset($contentType[$type][$lang]) && $contentType[$type][$lang]) { $existsFormID = $contentType[$type][$lang]; $generalOptions = get_post_meta($existsFormID, wpdFormConst::WPDISCUZ_META_FORMS_GENERAL_OPTIONS, true); if (!empty($generalOptions)) { unset($generalOptions[wpdFormConst::WPDISCUZ_META_FORMS_POSTE_TYPES][$type]); } update_post_meta($existsFormID, wpdFormConst::WPDISCUZ_META_FORMS_GENERAL_OPTIONS, $generalOptions); } $contentType[$type][$lang] = $this->formID; } update_option(wpdFormConst::WPDISCUZ_FORMS_CONTENT_TYPE_REL, $contentType); } private function saveFormPostRel($data) { $formPostIds = isset($this->generalOptions["postidsArray"]) ? $this->generalOptions["postidsArray"] : []; $ids = get_option(wpdFormConst::WPDISCUZ_FORMS_POST_REL, []); foreach ($formPostIds as $k => $formPostId) { if (!in_array($formPostId, $data)) { unset($ids[$formPostId]); } } foreach ($data as $k1 => $id) { if (isset($ids[$id]) && $ids[$id]) { $existsFormID = $ids[$id]; $generalOptions = get_post_meta($existsFormID, wpdFormConst::WPDISCUZ_META_FORMS_GENERAL_OPTIONS, true); if (!$generalOptions) { $generalOptions = ["postidsArray" => []]; } foreach ($generalOptions["postidsArray"] as $key => $pid) { if ($pid == $id) { unset($generalOptions["postidsArray"][$key]); } } $generalOptions["postid"] = implode(", ", $generalOptions["postidsArray"]); update_post_meta($existsFormID, wpdFormConst::WPDISCUZ_META_FORMS_GENERAL_OPTIONS, $generalOptions); } $ids[$id] = $this->formID; } update_option(wpdFormConst::WPDISCUZ_FORMS_POST_REL, $ids); } public function transferJSData($data) { $this->initFormFields(); $data["is_email_field_required"] = empty($this->formFields[wpdFormConst::WPDISCUZ_FORMS_EMAIL_FIELD]["required"]) ? 0 : $this->formFields[wpdFormConst::WPDISCUZ_FORMS_EMAIL_FIELD]["required"]; return $data; } public function showRecaptcha() { return ($this->wpdOptions->recaptcha["showForGuests"] && !is_user_logged_in()) || ($this->wpdOptions->recaptcha["showForUsers"] && is_user_logged_in()) || ($this->wpdOptions->recaptcha["isShowOnSubscribeForm"] && !is_user_logged_in()); } public function customFieldsExists() { $this->initFormFields(); return $this->formCustomFields ? true : false; } public function resetData() { $this->formID = 0; $this->generalOptions = []; $this->formCustomFields = []; $this->formFields = []; } public function getLayouts($theme = '') { $theme = $theme ? $theme : $this->generalOptions["theme"]; $layouts = []; $path = $theme . "/layouts/"; $scannedLayouts = scandir($path); unset($scannedLayouts[0]); unset($scannedLayouts[1]); foreach ($scannedLayouts as $k => $scannedLayout) { if (is_dir($path . $scannedLayout)) { $layouts[] = $scannedLayout; } } return $layouts; } public function getThemes() { $themes = []; $path = str_replace("\\", "/", WPDISCUZ_DIR_PATH) . "/themes/"; $scannedThemes = scandir($path); if ($scannedThemes && is_array($scannedThemes)) { unset($scannedThemes[0]); unset($scannedThemes[1]); foreach ($scannedThemes as $k => $scannedTheme) { if (is_dir($path . $scannedTheme)) { $theme = wp_get_theme($scannedTheme, $path); if ($theme->exists()) { $themes[$path . $scannedTheme] = [ "name" => $theme->get("Name"), "desc" => $theme->get("Description"), "url" => plugins_url(WPDISCUZ_DIR_NAME . "/themes/$scannedTheme"), ]; } } } } $uplDir = wp_upload_dir(); $themesDir = str_replace("\\", "/", $uplDir["basedir"]) . wpdFormConst::THEMES_DIR; if (is_dir($themesDir)) { $scannedThemes = scandir($themesDir); if ($scannedThemes && is_array($scannedThemes)) { unset($scannedThemes[0]); unset($scannedThemes[1]); foreach ($scannedThemes as $k => $scannedTheme) { if (is_dir($themesDir . $scannedTheme)) { $theme = wp_get_theme($scannedTheme, $themesDir); if ($theme->exists()) { $themes[$themesDir . $scannedTheme] = [ "name" => $theme->get("Name"), "desc" => $theme->get("Description"), "url" => $uplDir["baseurl"] . wpdFormConst::THEMES_DIR . $scannedTheme, ]; } } } } } return $themes; } public function getDefaultTheme() { $path = str_replace("\\", "/", WPDISCUZ_DIR_PATH) . "/themes/"; $scannedThemes = scandir($path); unset($scannedThemes[0]); unset($scannedThemes[1]); foreach ($scannedThemes as $k => $scannedTheme) { if (is_dir($path . $scannedTheme)) { $theme = wp_get_theme($scannedTheme, $path); if ($theme->exists()) { return $path . $scannedTheme; } } } } public function getAllowedFieldsType() { return $this->row->allowedFieldsType(); } public function updateSeparateRatingMeta($ratings, $post_id) { foreach ($ratings as $key => $values) { $avg = 0; $c = 0; foreach ($values as $rating => $count) { $avg += $rating * $count; $c += $count; } update_post_meta($post_id, wpdFormConst::WPDISCUZ_RATING_SEPARATE_AVG . $key, ($c === 0 ? 0 : round($avg / $c, 1))); update_post_meta($post_id, wpdFormConst::WPDISCUZ_RATING_SEPARATE_COUNT . $key, $c); } } }