Commit 224151b7 authored by Thomas's avatar Thomas
Browse files

Add comments to the end of the article

parent 5cb1f0e9
......@@ -56,6 +56,10 @@ if( isset($optionsPreferences['selector']) ){
register_setting( $this->plugin_name.'preferences', $this->plugin_name."preferences[selector]", $optionsPreferences['selector'] );
}
if( isset($optionsPreferences['where']) ){
register_setting( $this->plugin_name.'preferences', $this->plugin_name."preferences[where]", $optionsPreferences['where'] );
}
if( ! isset($_SESSION['mc_step']))
$_SESSION['mc_step'] = 1;
......@@ -74,7 +78,7 @@ if( !empty($currentUser) && !empty($currentUser[0]->mastodon_instance) && strlen
$Mastodon_api->set_token($account['token'], "bearer");
$response = $Mastodon_api->accounts($account['user_id']);
;?>
<div class="card" style="position: relative;">
<div class="card" style="position: relative;" >
<form method="post" name="<?php echo $this->plugin_name.'account';?>" style="position: absolute;right:0;bottom:0;" action="options.php">
<?php settings_fields($this->plugin_name.'account');?>
<input type="hidden" id="<?php echo $this->plugin_name;?>-disconnect" name="<?php echo $this->plugin_name;?>account[disconnect]" value="1" />
......@@ -216,12 +220,24 @@ if ( isset($options['oauth']) ){
<?php settings_fields($this->plugin_name.'preferences');?>
<h2 class="nav-tab-wrapper"><?php _e('Targeted element', $this->plugin_name);?></h2>
<fieldset style="margin-top: 10px;">
<label for="<?php echo $this->plugin_name;?>-selector"><?php _e('Selector', $this->plugin_name);?></label>
<input type="text" id="<?php echo $this->plugin_name;?>-selector"
placeholder="<?php _e('Use a jquery selector', $this->plugin_name);?>"
name="<?php echo $this->plugin_name;?>preferences[selector]"
value="<?php echo isset($optionsPreferences['selector'])?$optionsPreferences['selector']:"#comments";?>" />
<input type="radio"
name="<?php echo $this->plugin_name;?>preferences[where]"
value="custom"
<?php if( $optionsPreferences['where'] != "end_article" ) {echo "checked";}?>>
<label for="<?php echo $this->plugin_name;?>-selector"><?php _e('Selector', $this->plugin_name);?></label>
<input type="text" id="<?php echo $this->plugin_name;?>-selector"
placeholder="<?php _e('Use a jquery selector', $this->plugin_name);?>"
name="<?php echo $this->plugin_name;?>preferences[selector]"
value="<?php echo isset($optionsPreferences['selector'])?$optionsPreferences['selector']:"#comments";?>" />
</input>
<a href="https://api.jquery.com/category/selectors/" target="_blank" title="<?php _e('JQuery selectors', $this->plugin_name);?>" ><?php _e('More about JQuery selectors', $this->plugin_name);?></a>
<br/>
<input type="radio"
name="<?php echo $this->plugin_name;?>preferences[where]"
value="end_article"
<?php if( $optionsPreferences['where'] == "end_article" ) {echo "checked";}?>>
<?php _e('Automatically add comments at the end of the article', $this->plugin_name);?>
</input>
<br/><br/>
<label for="<?php echo $this->plugin_name;?>-peertubecomments"><?php _e('Display peertube comments', $this->plugin_name);?></label>
<input type="checkbox" id="<?php echo $this->plugin_name;?>-peertubecomments"
......
......@@ -181,6 +181,7 @@ class Mastalab_comments {
$this->loader->add_action( 'wp_ajax_mastalab_comments_getcomment_peertube',$plugin_public, 'prefix_ajax_mastalab_comments_getcomment_peertube' );
$this->loader->add_action( 'wp_ajax_nopriv_mastalab_comments_getcomment_peertube',$plugin_public, 'prefix_ajax_mastalab_comments_getcomment_peertube' );
$this->loader->add_action('the_content', $plugin_public, 'mastalab_comments_add_to_footer', 1);
}
......
......@@ -110,12 +110,26 @@ class Mastalab_comments_Public {
'peertube_bg' => $optionsPreferences['peertube_bg'],
'peertube_text' => $optionsPreferences['peertube_text'],
'peertube_link' => $optionsPreferences['peertube_link'],
'mastalab_where' => $optionsPreferences['where'],
'selector' => $optionsPreferences['selector'],
'mastalab_comments_nonce' => wp_create_nonce('mastalab_comments_nonce')
);
wp_localize_script( $this->plugin_name, 'params', $params );
}
public function mastalab_comments_add_to_footer(){
$fullcontent = get_the_content();
if(is_page() || is_single()) {
$optionsPreferences = get_option( $this->plugin_name . 'preferences' );
$where = $optionsPreferences['where'];
if ( $where === "end_article" ) {
$fullcontent = $fullcontent . "<div style='clear: both;'>".__('Comments from Mastodon:', $this->plugin_name)."</div><div id='mastalab_comments_end_article'></div>";
}
}
return $fullcontent;
}
/**
* Get remote comments for Peertube related to its URL
* Values are cached
......
......@@ -40,9 +40,14 @@
'mastalab_comments_nonce': params.mastalab_comments_nonce
},
function(data){
var targeted_element = "#comments";
if( typeof params.selector !== "undefined")
targeted_element = params.selector;
var targeted_element
if( params.mastalab_where === 'end_article')
targeted_element = "#mastalab_comments_end_article";
else {
targeted_element = "#comments";
if (typeof params.selector !== "undefined")
targeted_element = params.selector;
}
if( typeof data.stats === "undefined" || data.comments.length === 0)
return;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment