Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipsesrl committed Sep 25, 2019
1 parent cdc96a9 commit fbf2ac6
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions assets/css/ajax-loading.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions includes/Core/Udesly.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
59 changes: 59 additions & 0 deletions includes/Dashboard/Views/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static function show()
self::search_tab();
self::email_tab();
self::tools_tab();
self::comments_tab();
self::js_tab();
?>
</Tabs>
Expand All @@ -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'),
Expand All @@ -60,6 +62,8 @@ public static function show()

}



private static function blog_tab()
{

Expand Down Expand Up @@ -390,6 +394,50 @@ private static function tools_tab()

}

private static function comments_tab()
{
?>
<Tab name="<?php _e('Comments', UDESLY_TEXT_DOMAIN); ?>" icon="fas fa-comments">
<Expansion-Panel open="true">
<template v-slot:header>
<h3><?php _e("Comments Texts", UDESLY_TEXT_DOMAIN); ?></h3>
</template>
<Material-Input name="comments.reply_text" required minlength="3" type="text">

<?php _e('Reply:', UDESLY_TEXT_DOMAIN); ?>

</Material-Input>
<Material-Input name="comments.reply_to_text" required minlength="3" type="text">

<?php _e('Reply to:', UDESLY_TEXT_DOMAIN); ?>

</Material-Input>
<Material-Input name="comments.login_text" required minlength="3" type="text">

<?php _e('Login:', UDESLY_TEXT_DOMAIN); ?>

</Material-Input>
<Material-Input name="comments.label_submit" required minlength="3" type="text">

<?php _e('Submit:', UDESLY_TEXT_DOMAIN); ?>

</Material-Input>
<Material-Input name="comments.title_reply" required minlength="3" type="text">

<?php _e('Reply Title:', UDESLY_TEXT_DOMAIN); ?>

</Material-Input>
<Material-Input name="comments.title_reply_to" required minlength="3" type="text">

<?php _e('Reply To Title:', UDESLY_TEXT_DOMAIN); ?>

</Material-Input>
</Expansion-Panel>
</Tab>
<?php

}

private static function email_tab()
{
?>
Expand Down Expand Up @@ -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,
Expand Down
204 changes: 204 additions & 0 deletions includes/misc/comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
<?php

/**
* Gets next comments page link
*
* @param int $max_page
* @return bool|string
*/
function udesly_get_next_comments_link($max_page = 0)
{
global $wp_query;

if (!is_singular()) {
return false;
}

$page = get_query_var('cpage');

if (!$page) {
$page = 1;
}

$nextpage = intval($page) + 1;

if (empty($max_page)) {
$max_page = $wp_query->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(
'<a rel="nofollow" class="comment-reply-login ' . $classLink . '" href="%s">%s</a>',
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(
"<a rel='nofollow' class='comment-reply-link $classLink' href='%s' %s aria-label='%s'>%s</a>",
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" => '<p class="comment-form-comment"><label for="comment" class="${labelClass}">' . _x( 'Comment', 'noun' ) .
'</label><textarea id="comment" name="comment" class="'. $textAreaClass . '" cols="45" rows="8" aria-required="true">' .
'</textarea></p>',
"fields" => array(
'author' =>
'<p class="comment-form-author"><label for="author" class="${labelClass}">' . __( 'Name' ) .
( $req ? '<span class="required">*</span>' : '' ) . '</label>' .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
'" class=" '. $inputClass . '" /></p>',
'email' =>
'<p class="comment-form-email"><label for="email" class="${labelClass}">' . __( 'Email' ) .
( $req ? '<span class="required">*</span>' : '' ) . '</label>' .
'<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) .
'" class=" '. $inputClass . '" /></p>',
'url' =>
'<p class="comment-form-url"><label for="url" class="${labelClass}">' . __( 'Website' ) . '</label>' .
'<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
'" class=" '. $inputClass . '" /></p>',
),
));
}
4 changes: 2 additions & 2 deletions udesly-adapter-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand All @@ -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/');
Expand Down

0 comments on commit fbf2ac6

Please sign in to comment.