/**
  * The singleton method.
  *
  * @return Muut_Webhooks The instance.
  * @author Paul Hughes
  * @since  3.0.2
  */
 public static function instance()
 {
     if (!is_a(self::$instance, __CLASS__)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
/**
 * Check if webhooks are currently activated.
 *
 * @return bool Whether webhooks are active or not.
 * @author Paul Hughes
 * @since 3.0.2
 */
function muut_is_webhooks_active()
{
    return Muut_Webhooks::instance()->isWebhooksActivated();
}
 /**
  * Initializes the Webhooks class.
  *
  * @return void
  * @author Paul Hughes
  * @since 3.0.2
  */
 public function initWebhooks()
 {
     $class = 'Muut_Webhooks';
     if (!in_array($class, $this->alreadyInit)) {
         require_once muut()->getPluginPath() . 'lib/subscriber/webhooks.class.php';
         if (class_exists($class)) {
             Muut_Webhooks::instance();
         }
         $this->alreadyInit[] = $class;
     }
 }
	</p>
<?php 
}
?>
	</form>
	<div id="muut_settings_webhooks_setup_instructions" style="display: none">
		<div class="center_screenshot">
			<h3><?php 
_e('To complete your webhooks setup...', 'muut');
?>
</h3>
			<p><?php 
_e('From your main forum page, open the Muut settings, select the integrations tab, and create a new integration as below using the following URL and secret:', 'muut');
?>
</p>
			<p><input type="text" class="muut_autoselect"  value="<?php 
echo site_url() . '/' . Muut_Webhooks::instance()->getEndpointSlug();
?>
" style="width: 500px;" readonly /><br />
			<input type="text" class="muut_autoselect" value="<?php 
echo $current_values['webhooks_secret'];
?>
" readonly />
			</p>
			<img class="retinaise" style="height: 480px" src="<?php 
echo muut()->getPluginUrl() . '/resources/images/webhooks-instructions.png';
?>
">
		</div>
	</div>
</div>
 /**
  * Updates/checks the latest reply-time on a post if one of its comments is removed (if it was the latest comment, obviously it's no longer the latest).
  *
  * @param $request array The array that was parsed from the request body.
  * @param $event string The event that was sent.
  * @return void
  * @author Paul Hughes
  * @since 3.0.2.1
  */
 public function updatePostLatestReplyTime($request, $event)
 {
     // Only execute for the applicable events.
     $events = array('remove', 'spam', 'unspam');
     if (in_array($event, $events)) {
         $path = $request['path'];
         $split_path = explode('#', $path);
         $split_final = explode('/', $split_path[1]);
         $comment_base = $split_path[0] . '#' . $split_final[0];
         // See if the path is a reply to a given post.
         $post_id = Muut_Webhooks::getPostIdRepliedTo($path);
         if (!$post_id) {
             return;
         }
         $latest_update_timestamp = get_post_time('U', true, $post_id);
         $muut_user = '';
         $has_replies = false;
         // If it is threaded commenting, make sure to check for the top-level times.
         if (Muut_Comment_Overrides::instance()->getCommentingPostCommentType($post_id) == 'threaded') {
             // Check if a WP post exists in the database that would match the path of the "post" request (for threaded commenting).
             $post_query_args = array('post_type' => Muut_Custom_Post_Types::MUUT_THREAD_CPT_NAME, 'post_status' => Muut_Custom_Post_Types::MUUT_PUBLIC_POST_STATUS, 'meta_query' => array(array('key' => 'muut_channel_path', 'value' => $split_path[0])), 'orderby' => 'post_date_gmt', 'order' => 'DESC', 'posts_per_page' => 1);
             $query = new WP_Query($post_query_args);
             $posts = $query->get_posts();
             if (!empty($posts) && is_array($posts)) {
                 $post_update_time = get_post_time('U', true, $posts[0]);
                 if ($post_update_time > $latest_update_timestamp) {
                     $latest_update_timestamp = $post_update_time;
                     $muut_user = get_post_meta($posts[0]->ID, 'muut_user', true);
                     $has_replies = true;
                 }
             }
         }
         // Also check the actual comments.
         $comment_query_args = array('meta_query' => array(array('key' => 'muut_path', 'value' => $comment_base)), 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'number' => 1);
         // Get the comment data.
         $comment_query = new WP_Comment_Query();
         $comments = $comment_query->query($comment_query_args);
         if (!empty($comments) && is_array($comments)) {
             $comment_update_time = strtotime($comments[0]->comment_date_gmt);
             if ($comment_update_time > $latest_update_timestamp) {
                 $latest_update_timestamp = $comment_update_time;
                 $muut_user = get_comment_meta($comments[0]->comment_ID, 'muut_user', true);
             }
             $has_replies = true;
         }
         if (!$has_replies) {
             delete_post_meta($post_id, self::REPLY_UPDATE_TIME_NAME);
             delete_post_meta($post_id, self::REPLY_LAST_USER_DATA_NAME);
         } else {
             // Add/update a meta for the post with the time of the last comment and the user data responsible.
             update_post_meta($post_id, self::REPLY_UPDATE_TIME_NAME, $latest_update_timestamp);
             update_post_meta($post_id, self::REPLY_LAST_USER_DATA_NAME, $muut_user);
         }
         self::refreshCache();
     }
 }