From fbf2ac666b010838e995d933f076ad8a1a82af61 Mon Sep 17 00:00:00 2001 From: Eclipse Srl Date: Wed, 25 Sep 2019 15:34:27 +0200 Subject: [PATCH] added comments --- README.txt | 5 +- assets/css/ajax-loading.css | 8 + includes/Core/Udesly.php | 1 + includes/Dashboard/Views/Settings.php | 59 ++++++++ includes/misc/comments.php | 204 ++++++++++++++++++++++++++ udesly-adapter-plugin.php | 4 +- 6 files changed, 278 insertions(+), 3 deletions(-) create mode 100644 includes/misc/comments.php diff --git a/README.txt b/README.txt index 4fe74e8..aee79b4 100644 --- a/README.txt +++ b/README.txt @@ -4,7 +4,7 @@ Donate link: https://www.udesly.com/ Tags: webflow to wordpress, editor, page builder, layout design, udesly, webflow Requires at least: 5.0 Tested up to: 5.2.3 -Stable tag: 2.0.0.28 +Stable tag: 2.0.0.29 License: GPLv3 or later License URI: https://www.udesly.com/terms-conditions-of-use/#udesly-wordpress-plugin Requires PHP: 5.6.0 @@ -80,6 +80,9 @@ That's all! Absolutely! You can use the Udesly Adapter to create more than one website. == Changelog == += 2.0.0.29 = +* Added comments settings and functions + = 2.0.0.28 = * Added general archive title option diff --git a/assets/css/ajax-loading.css b/assets/css/ajax-loading.css index 8fc2083..b54b5b8 100644 --- a/assets/css/ajax-loading.css +++ b/assets/css/ajax-loading.css @@ -29,4 +29,12 @@ .woocommerce-MyAccount-content p a, .woocommerce p a { display: inline; +} + +p.logged-in-as a { + display: inline-block; +} + +ul ul.children { + list-style-type: inherit; } \ No newline at end of file diff --git a/includes/Core/Udesly.php b/includes/Core/Udesly.php index 56271fd..9a269bf 100644 --- a/includes/Core/Udesly.php +++ b/includes/Core/Udesly.php @@ -80,6 +80,7 @@ public function include_dependencies() require_once UDESLY_ADAPTER_PLUGIN_MISC_PATH . 'terms-query.php'; require_once UDESLY_ADAPTER_PLUGIN_MISC_PATH . 'rules.php'; require_once UDESLY_ADAPTER_PLUGIN_MISC_PATH . 'social.php'; + require_once UDESLY_ADAPTER_PLUGIN_MISC_PATH . 'comments.php'; //Pagination function integration require_once UDESLY_ADAPTER_PLUGIN_MISC_PATH . 'pagination.php'; diff --git a/includes/Dashboard/Views/Settings.php b/includes/Dashboard/Views/Settings.php index a112723..f4f64c4 100644 --- a/includes/Dashboard/Views/Settings.php +++ b/includes/Dashboard/Views/Settings.php @@ -33,6 +33,7 @@ public static function show() self::search_tab(); self::email_tab(); self::tools_tab(); + self::comments_tab(); self::js_tab(); ?> @@ -46,6 +47,7 @@ public static function show() "wc" => self::get_wc_settings(), "search" => self::get_search_settings(), "email" => self::get_email_settings(), + "comments" => self::get_comments_settings(), "js" => self::get_js_settings(), ), "ajaxurl" => admin_url('admin-ajax.php'), @@ -60,6 +62,8 @@ public static function show() } + + private static function blog_tab() { @@ -390,6 +394,50 @@ private static function tools_tab() } + private static function comments_tab() + { + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -491,6 +539,17 @@ public static function get_search_settings() { )); } + public static function get_comments_settings() { + return self::get_settings("comments", array( + "reply_text" => "Reply", + "reply_to_text" => 'Reply to %s', + "login_text" => 'Log in to Reply', + "label_submit" => 'Post Comment', + 'title_reply' => "Leave a Reply", + "title_reply_to" => "Write a reply to %s" + )); + } + public static function get_js_settings() { return self::get_settings("js", array( "break_cache_forms" => false, diff --git a/includes/misc/comments.php b/includes/misc/comments.php new file mode 100644 index 0000000..fa70a3f --- /dev/null +++ b/includes/misc/comments.php @@ -0,0 +1,204 @@ +max_num_comment_pages; + } + + if (empty($max_page)) { + $max_page = get_comment_pages_count(); + } + + if ($nextpage > $max_page) { + return false; + } + return esc_url(get_comments_pagenum_link($nextpage, $max_page)); +} + +/** + * Gets previous comments page link + * @param int $max_page + * @return bool|string + */ +function udesly_get_previous_comments_link($max_page = 0) +{ + if (!is_singular()) { + return false; + } + + $page = get_query_var('cpage'); + + if (intval($page) <= 1) { + return false; + } + + $prevpage = intval($page) - 1; + return esc_url(esc_url(get_comments_pagenum_link($prevpage))); +} + +/** + * Lists comments with correct args + * @param $randomId + */ +function udesly_list_comments($randomId) +{ + wp_list_comments(array( + 'callback' => "udesly_comment_callback_$randomId", + 'end-callback' => "udesly_end_comment_callback_$randomId", + 'style' => 'ul', + 'type' => 'comment' + )); +} + +/** + * Gets reply comment + * + * @param string $classLink + * @param array $args + * @param null $comment + * @param null $post + * @return mixed|string|void + */ +function udesly_get_comment_reply_link($classLink = '', $args = array(), $comment = null, $post = null) +{ + + $settings = \Udesly\Dashboard\Views\Settings::get_comments_settings(); + + global $comment_args, $comment_depth; + $defaults = array( + 'add_below' => 'comment', + 'respond_id' => 'respond', + 'reply_text' => __($settings['reply_text']), + 'reply_to_text' => __($settings['reply_to_text']), + 'login_text' => __($settings['login_text']), + 'max_depth' => $comment_args['max_depth'], + 'depth' => $comment_depth, + 'before' => '', + 'after' => '', + ); + + $args = wp_parse_args($args, $defaults); + + if (0 == $args['depth'] || $args['max_depth'] <= $args['depth']) { + return ''; + } + + $comment = get_comment($comment); + + if (empty($post)) { + $post = $comment->comment_post_ID; + } + + $post = get_post($post); + + if (!comments_open($post->ID)) { + return ''; + } + + $args = apply_filters('comment_reply_link_args', $args, $comment, $post); + + if (get_option('comment_registration') && !is_user_logged_in()) { + $link = sprintf( + '%s', + esc_url(wp_login_url(get_permalink())), + $args['login_text'] + ); + } else { + $data_attributes = array( + 'commentid' => $comment->comment_ID, + 'postid' => $post->ID, + 'belowelement' => $args['add_below'] . '-' . $comment->comment_ID, + 'respondelement' => $args['respond_id'], + ); + + $data_attribute_string = ''; + + foreach ($data_attributes as $name => $value) { + $data_attribute_string .= " data-${name}=\"" . esc_attr($value) . '"'; + } + + $data_attribute_string = trim($data_attribute_string); + + $link = sprintf( + "%s", + esc_url( + add_query_arg( + array( + 'replytocom' => $comment->comment_ID, + 'unapproved' => false, + 'moderation-hash' => false, + ) + ) + ) . '#' . $args['respond_id'], + $data_attribute_string, + esc_attr(sprintf($args['reply_to_text'], $comment->comment_author)), + $args['reply_text'] + ); + } + + + return apply_filters('comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post); +} + + +/** + * Outputs the form class + * + * @param $formClass + * @param $submitClass + * @param $textAreaClass + * @param $inputClass + */ +function udesly_comments_form($formClass, $submitClass, $textAreaClass, $inputClass) { + + $settings = \Udesly\Dashboard\Views\Settings::get_comments_settings(); + + global $commenter, $req; + comment_form(array( + "class_form" => $formClass, + "label_submit" => $settings['label_submit'], + "title_reply" => $settings['title_reply'], + "title_reply_to" => $settings['title_reply_to'], + "class_submit" => $submitClass, + "comment_field" => '

', + "fields" => array( + 'author' => + '

' . + '

', + 'email' => + '

' . + '

', + 'url' => + '

' . + '

', + ), + )); +} \ No newline at end of file diff --git a/udesly-adapter-plugin.php b/udesly-adapter-plugin.php index a48cd4d..ba881d7 100644 --- a/udesly-adapter-plugin.php +++ b/udesly-adapter-plugin.php @@ -11,7 +11,7 @@ * Plugin Name: Udesly Adapter * Plugin URI: https://www.udesly.com * Description: This is a support plugin for Udesly (Webflow to WordPress converter) that allows you to enable additional features for your theme. - * Version: 2.0.0.28 + * Version: 2.0.0.29 * Author: Udesly * Author URI: https://www.udesly.com * License: GPL-2.0+ @@ -29,7 +29,7 @@ // Constants defined('UDESLY_ADAPTER_PLUGIN_DIRECTORY_PATH') ?: define('UDESLY_ADAPTER_PLUGIN_DIRECTORY_PATH', plugin_dir_path(__FILE__)); defined('UDESLY_ADAPTER_PLUGIN_DIRECTORY_URL') ?: define('UDESLY_ADAPTER_PLUGIN_DIRECTORY_URL', plugin_dir_url(__FILE__)); -defined('UDESLY_ADAPTER_VERSION') ?: define('UDESLY_ADAPTER_VERSION', "2.0.0.28"); +defined('UDESLY_ADAPTER_VERSION') ?: define('UDESLY_ADAPTER_VERSION', "2.0.0.29"); defined('UDESLY_TEXT_DOMAIN') ?: define('UDESLY_TEXT_DOMAIN', "udesly-adapter-plugin"); defined('UDESLY_ADAPTER_PLUGIN_MISC_PATH') ?: define('UDESLY_ADAPTER_PLUGIN_MISC_PATH', plugin_dir_path(__FILE__) . 'includes/misc/');