<commit_before><?php
/**
 * The Muut Latest Comments widget.
 *
 * @package   Muut
 * @copyright 2014 Muut Inc
 */

// Don't load directly
if ( !defined( 'ABSPATH' ) ) {
	die( '-1' );
}

if ( !class_exists( 'Muut_Widget_Latest_Comments' ) ) {
	/**
	 * Muut Latest Comments widget class.
	 *
	 * @package Muut
	 * @author  <NAME>
	 * @since   NEXT_RELEASE
	 */
	class Muut_Widget_Latest_Comments extends WP_Widget {

		const LATEST_COMMENTS_TRANSIENT_NAME = 'muut_latest_comments';

		const REPLY_UPDATE_TIME_NAME = 'muut_last_reply_time';

		const REPLY_LAST_USER_DATA_NAME = 'muut_last_reply_user';

		const LATEST_COMMENTS_JSON_FILE_NAME = 'latest_comments.json';

		/**
		 * @property array The instance array of settings.
		 */
		protected $widget_instance;

		/**
		 * The class constructor.
		 *
		 * @return Muut_Widget_Online_Users
		 * @author <NAME>
		 * @since NEXT_RELEASE
		 */
		function __construct() {
			parent::__construct(
				'muut_latest_comments_widget',
				__( 'Muut Latest Comments', 'muut' ),
				array(
					'description' => __( 'Use this to show the latest posts with Muut comments.', 'muut' ),
				)
			);

			$this->addActions();
			$this->addFilters();
		}

		/**
		 * Adds the actions pertaining to the widget's functionality.
		 *
		 * @return void
		 * @author <NAME>
		 * @since NEXT_RELEASE
		 */
		public function addActions() {
			// Update the transient data when a reply is made.
			add_action( 'muut_webhook_request_reply', array( $this, 'updateWidgetData' ), 100, 2 );
			// The reason we have to worry about this below (post event) is in case it is on threaded commenting.
			add_action( 'muut_webhook_request_post', array( $this, 'updateWidgetData' ), 100, 2 );

			add_action( 'wp_enqueue_scripts', array( $this, 'enqueueWidgetScripts' ), 12 );
			add_action( 'wp_print_scripts', array( $this, 'printWidgetJs' ) );
			add_action( 'init', array( $this, 'maybeRequireMuutResources') );
		}

		/**
		 * Adds the filters pertaining to the widget's functionality.
		 *
		 * @return void
		 * @author <NAME>
		 * @since NEXT_RELEASE
		 */
		public function addFilters() {

		}

		/**
		 * Render the widget frontend output.
		 *
		 * @param array $args The sidebar arguments.
		 * @param array $instance The widget instance parameters.
		 * @return void
		 * @author <NAME>
		 * @since NEXT_RELEASE
		 */
		public function widget( $args, $instance ) {
			// Make sure webhooks are active, or don't bother.
			if ( !muut_is_webhooks_active() ) {
				return;
			}
			// Make sure the Muut resources get loaded (only stuff in the footer will work, as this happens
			// partway through page load).
			add_filter( 'muut_requires_muut_resources', '__return_true' );
			muut()->enqueueFrontendScripts();

			$title = isset( $instance['title'] ) ? $instance['title'] : '';
			$latest_comments_data = array_slice( $this->getLatestCommentsData(), 0, $instance['number_of_comments'] );

			// Render widget.
			echo $args['before_widget'];
			echo '<script type="text/javascript">';
			echo 'var muut_latest_comments_num_posts = "' . $instance['number_of_comments'] . '";';
			echo 'var muut_latest_comments_path = "' . muut()->getOption( 'comments_base_domain') . '";';
			if ( get_the_ID() && Muut_Post_Utility::isMuutCommentingPost( get_the_ID() ) ) {
				echo 'var muut_wp_post_id = ' . get_the_ID() . ';';
				echo 'var muut_wp_post_permalink = "' . get_permalink() . '";';
				echo 'var muut_wp_post_title = "' . get_the_title() . '";';
			}
			echo '</script>';
			echo $args['before_title'] . $title . $args['after_title'];
			include( muut()->getPluginPath() . 'views/widgets/widget-latest-comments.php' );
			echo $args['after_widget'];
		}

		/**<commit_msg>Latest Comments: Only will load once on a given page.<commit_after><?php
/**
 * The Muut Latest Comments widget.
 *
 * @package   Muut
 * @copyright 2014 Muut Inc
 */

// Don't load directly
if ( !defined( 'ABSPATH' ) ) {
	die( '-1' );
}

if ( !class_exists( 'Muut_Widget_Latest_Comments' ) ) {
	/**
	 * Muut Latest Comments widget class.
	 *
	 * @package Muut
	 * @author  <NAME>
	 * @since   NEXT_RELEASE
	 */
	class Muut_Widget_Latest_Comments extends WP_Widget {

		const LATEST_COMMENTS_TRANSIENT_NAME = 'muut_latest_comments';

		const REPLY_UPDATE_TIME_NAME = 'muut_last_reply_time';

		const REPLY_LAST_USER_DATA_NAME = 'muut_last_reply_user';

		const LATEST_COMMENTS_JSON_FILE_NAME = 'latest_comments.json';

		/**
		 * @property array The instance array of settings.
		 */
		protected $widget_instance;

		/**
		 * @static
		 * @property bool Whether the widget has been loaded.
		 */
		protected static $has_loaded = false;

		/**
		 * The class constructor.
		 *
		 * @return Muut_Widget_Online_Users
		 * @author <NAME>
		 * @since NEXT_RELEASE
		 */
		function __construct() {
			parent::__construct(
				'muut_latest_comments_widget',
				__( 'Muut Latest Comments', 'muut' ),
				array(
					'description' => __( 'Use this to show the latest posts with Muut comments.', 'muut' ),
				)
			);

			$this->addActions();
			$this->addFilters();
		}

		/**
		 * Adds the actions pertaining to the widget's functionality.
		 *
		 * @return void
		 * @author <NAME>
		 * @since NEXT_RELEASE
		 */
		public function addActions() {
			// Update the transient data when a reply is made.
			add_action( 'muut_webhook_request_reply', array( $this, 'updateWidgetData' ), 100, 2 );
			// The reason we have to worry about this below (post event) is in case it is on threaded commenting.
			add_action( 'muut_webhook_request_post', array( $this, 'updateWidgetData' ), 100, 2 );

			add_action( 'wp_enqueue_scripts', array( $this, 'enqueueWidgetScripts' ), 12 );
			add_action( 'wp_print_scripts', array( $this, 'printWidgetJs' ) );
			add_action( 'init', array( $this, 'maybeRequireMuutResources') );
		}

		/**
		 * Adds the filters pertaining to the widget's functionality.
		 *
		 * @return void
		 * @author <NAME>
		 * @since NEXT_RELEASE
		 */
		public function addFilters() {

		}

		/**
		 * Render the widget frontend output.
		 *
		 * @param array $args The sidebar arguments.
		 * @param array $instance The widget instance parameters.
		 * @return void
		 * @author <NAME>
		 * @since NEXT_RELEASE
		 */
		public function widget( $args, $instance ) {
			// Make sure webhooks are active, or don't bother.
			if ( !muut_is_webhooks_active() || self::$has_loaded ) {
				return;
			}
			// Make sure the Muut resources get loaded (only stuff in the footer will work, as this happens
			// partway through page load).
			add_filter( 'muut_requires_muut_resources', '__return_true' );
			muut()->enqueueFrontendScripts();

			$title = isset( $instance['title'] ) ? $instance['title'] : '';
			$latest_comments_data = array_slice( $this->getLatestCommentsData(), 0, $instance['number_of_comments'] );

			// Render widget.
			echo $args['before_widget'];
			echo '<script type="text/javascript">';
			echo 'var muut_latest_comments_num_posts = "' . $instance['number_of_comments'] . '";';
			echo 'var muut_latest_comments_path = "' . muut()->getOption( 'comments_base_domain') . '";';
			if ( get_the_ID() && Muut_Post_Utility::isMuutCommentingPost( get_the_ID() ) ) {
				echo 'var muut_wp_post_id = ' . get_the_ID() . ';';
				echo 'var muut_wp_post_permalink = "' . get_permalink() . '";';
				echo 'var muut_wp_post_title = "' . get_the_title() . '";';
			}
			echo '</script>';
			echo $args['before_title'] . $title . $args['after_title'];
			include( muut()->getPluginPath() . 'views/widgets/widget-latest-comments.php' );
			echo $args['after_widget'];

			self::$has_loaded = true;
		}

		/**
{'fraction_non_alphanumeric': 0.13944013668024707, 'fraction_numerical': 0.004205546063871731, 'mean_word_length': 3.5650869826034794, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1551439', 'n_tokens_mistral': 2912, 'n_tokens_neox': 2475, 'n_words': 625}