User Tools

Site Tools


wordpress:disqusrecents

This is an old revision of the document!


Disqus: Recent Comments for Wordpress

Work in progress.

disqusrecents.php
<?php
/*
  Plugin Name: Disqus: Recent Comments
  Plugin URI: http://public.gfsolone.com/wiki/doku.php?id=wordpress:disqusrecents
  Description: Mostra gli ultimi commenti lasciati nel sistema Disqus installato nel vostro Wordpress. Tutti i dettagli sul codice (e aggiornamenti) rilasciati nella <a href="http://public.gfsolone.com/wiki/doku.php?id=wordpress:disqusrecents">pagina dedicata del Wiki</a>. Utilizzo del widget descritto nell'<a href="http://wp.me/pdQ5q-4Jn">articolo sul mio blog</a>!
  Version: 0.4
  Author: Gioxx
  Author URI: http://gioxx.org
  License: CC BY-NC-SA 3.0 IT
 */
 
/*
  Vedi dettaglio licenza di rilascio: http://creativecommons.org/licenses/by-nc-sa/3.0/it/deed.it
  Basato su Codex Wordpress: http://codex.wordpress.org/Widgets_API
  Grazie a: https://gist.github.com/flowcomm/4174893
  2013-2014 Gioxx (dev@gfsolone.com)
  IL CONTENUTO DI QUESTO FILE PHP VIENE FORNITO AS-IS
 
 */
 
class DsqRecents_Widget extends WP_Widget {
 
	/**
	 * Register widget with WordPress.
	 */
	public function __construct() {
		parent::__construct(
	 		'dsqrecents_widget', // Base ID
			'Disqus Recents Widget', // Name
			array( 'description' => __( 'Mostra gli ultimi commenti recuperati dal sistema Disqus (vedi documentazione)', 'text_domain' ), ) // Args
		);
	}
 
	/**
	 * Front-end display of widget.
	 *
	 * @see WP_Widget::widget()
	 *
	 * @param array $args     Widget arguments.
	 * @param array $instance Saved values from database.
	 */
	public function widget( $args, $instance ) {
		extract( $args );
		$title = apply_filters( 'widget_title', $instance['title'] );
		$dsqid = apply_filters( 'widget_dsqid', $instance['dsqid'] );
		$dsqitems = apply_filters( 'widget_dsqid', $instance['dsqitems'] );
 
		echo $before_widget;
		if ( ! empty( $title ) )
			echo $before_title . $title . $after_title;
		// echo __( 'Stringa debug, dovrebbe comparire nel widget', 'text_domain' );
		?>
			<!-- Blocco commenti Disqus -->
			<div id="recentcomments" class="dsq-widget">
				<script type="text/javascript" src="http://<?php echo $dsqid; ?>.disqus.com/recent_comments_widget.js?num_items=<?php echo $dsqitems; ?>&hide_avatars=0&avatar_size=32&excerpt_length=200"></script>
			</div><img src="http://public.gfsolone.com/wiki/lib/tpl/dokuwiki/images/logo.png" style="max-width: 16px; float: left;"><a href="http://public.gfsolone.com/wiki/doku.php?id=wordpress:disqusrecents" style="font-size: x-small; font-variant: small-caps;">Disqus Recent Comments</a>
		<?php
		echo $after_widget;
	}
 
	/**
	 * Sanitize widget form values as they are saved.
	 *
	 * @see WP_Widget::update()
	 *
	 * @param array $new_instance Values just sent to be saved.
	 * @param array $old_instance Previously saved values from database.
	 *
	 * @return array Updated safe values to be saved.
	 */
	public function update( $new_instance, $old_instance ) {
		$instance = array();
		$instance['title'] = strip_tags( $new_instance['title'] );
		$instance['dsqid'] = strip_tags( $new_instance['dsqid'] );
		$instance['dsqitems'] = strip_tags( $new_instance['dsqitems'] );
 
		return $instance;
	}
 
	/**
	 * Back-end widget form.
	 *
	 * @see WP_Widget::form()
	 *
	 * @param array $instance Previously saved values from database.
	 */
	public function form( $instance ) {
		if ( isset( $instance[ 'title' ] ) ) {
			$title = $instance[ 'title' ];
		}
		else {
			$title = __( 'Recent Comments', 'text_domain' );
		}
		if ( isset( $instance[ 'dsqid' ] ) ) {
			$dsqid = $instance[ 'dsqid' ];
		}
		else {
			$dsqid = __( 'gioxx', 'text_domain' );
		}
		if ( isset( $instance[ 'dsqitems' ] ) ) {
			$dsqitems = $instance[ 'dsqitems' ];
		}
		else {
			$dsqitems = __( '5', 'text_domain' );
		}
		?>
		<p>
			<!-- Titolo del widget -->
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
			<!-- ID DISQUS: ID.disqus.com -->
			<label for="<?php echo $this->get_field_id( 'dsqid' ); ?>"><?php _e( 'Disqus ID (ID.disqus.com):' ); ?></label> 
			<input class="widefat" id="<?php echo $this->get_field_id( 'dsqid' ); ?>" name="<?php echo $this->get_field_name( 'dsqid' ); ?>" type="text" value="<?php echo esc_attr( $dsqid ); ?>" />
			<!-- Numero commenti da caricare -->
			<label for="<?php echo $this->get_field_id( 'dsqitems' ); ?>"><?php _e( 'Items to load:' ); ?></label> 
			<input class="widefat" id="<?php echo $this->get_field_id( 'dsqitems' ); ?>" name="<?php echo $this->get_field_name( 'dsqitems' ); ?>" type="text" value="<?php echo esc_attr( $dsqitems ); ?>" />
		<br /><br />
		<a href="http://public.gfsolone.com/wiki/doku.php?id=wordpress:disqusrecents">Help me!</a><br />
		<a href="http://gfsolone.com"><img src="http://gfsolone.com/images/gfsolone.footer.png"></a>
		</p>
		<?php 
	}
 
} // class Widget terminata
 
// Registrazione del widget
add_action( 'widgets_init', create_function( '', 'register_widget( "dsqrecents_widget" );' ) );
?>
wordpress/disqusrecents.1389278014.txt.gz · Last modified: 2014/01/09 15:33 by Giovanni