/**
  * Render the widget frontend output.
  *
  * @param array $args The sidebar arguments.
  * @param array $instance The widget instance parameters.
  * @return void
  * @author Paul Hughes
  * @since 3.0.2
  */
 public function widget($args, $instance)
 {
     // Do not show widget on the main forum page.
     if (Muut_Post_Utility::getForumPageId() == get_the_ID() && !apply_filters('muut_force_online_widget_display', false) || apply_filters('muut_hide_online_widget_display', false)) {
         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'] : '';
     $num_online_html = '';
     if ($instance['show_number_online'] && !empty($title)) {
         $num_online_html = '<span class="num-logged-in"></span>';
     }
     // Render widget.
     echo $args['before_widget'];
     echo $args['before_title'] . $title . $num_online_html . $args['after_title'];
     include muut()->getPluginPath() . 'views/widgets/widget-online-users.php';
     echo $args['after_widget'];
 }
 /**
  * Render the widget frontend output.
  *
  * @param array $args The sidebar arguments.
  * @param array $instance The widget instance parameters.
  * @return void
  * @author Paul Hughes
  * @since 3.0.2
  */
 public function widget($args, $instance)
 {
     if (Muut_Post_Utility::getForumPageId() == get_the_ID() && !apply_filters('muut_force_my_feed_widget_display', false) || apply_filters('muut_hide_my_feed_widget_display', false)) {
         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();
     if (isset($instance['disable_uploads'])) {
         $embed_args['allow-uploads'] = !$instance['disable_uploads'] ? 'true' : 'false';
     }
     $embed_args['title'] = isset($instance['title']) ? $instance['title'] : '';
     // Render widget.
     echo $args['before_widget'];
     echo $args['before_title'] . $embed_args['title'] . $args['after_title'];
     $path = 'feed';
     echo '<div id="muut-widget-my-feed-wrapper" class="muut_widget_wrapper muut_widget_my_feed_wrapper">';
     Muut_Channel_Utility::getChannelEmbedMarkup($path, $embed_args, true);
     echo '<div id="muut-widget-my-feed-login"><a href="#" class="muut_login">' . __('Login', 'muut') . '</a></div>';
     echo '</div>';
     echo $args['after_widget'];
 }
/**
 * Get embed anchor for page.
 *
 * @param int $page_id The ID of the page we are getting the anchor for.
 * @param bool $echo Whether to echo the anchor or not.
 * @return void|string The anchor markup or void, we $echo is set to true (and we echo the markup).
 * @author Paul Hughes
 * @since 3.0
 */
function muut_page_embed($page_id = null, $echo = true)
{
    if (is_null($page_id)) {
        $page_id = get_the_ID();
    }
    return Muut_Post_Utility::forumPageEmbedMarkup($page_id, $echo);
}
 /**
  *  Gets the proper Muut template, if necessary.
  *
  * @param string $template The current template being requested.
  * @return string The revised template path to load.
  * @author Paul Hughes
  * @since 3.0
  */
 public function getProperTemplate($template)
 {
     if (is_page() && Muut_Post_Utility::isMuutPost(get_the_ID())) {
         //TODO: Allow for other forum templates to get loaded (not just the one).
         if (Muut_Post_Utility::getForumPageId() == get_the_ID() && apply_filters('muut_use_packaged_forum_template', true)) {
             $template = 'forum-page.php';
             $located = $this->locateTemplate($template);
             $template = $located != '' ? $located : $template;
         }
     }
     return $template;
 }
 /**
  * Filters the commenting embed anchor to render the index content rather than the commenting anchor.
  *
  * @param string $content The current embed content (anchor).
  * @param int $post_id The post for which we are filtering the embed.
  * @return string The filtered content.
  * @author Paul Hughes
  * @since 3.0.1
  */
 public function filterCommentsOverrideIndexContent($content, $post_id, $type)
 {
     if ($this->isUsingEscapedFragments()) {
         $post_commenting_options = Muut_Post_Utility::getPostOption($post_id, 'commenting_settings');
         if (isset($post_commenting_options['type']) && $post_commenting_options['type'] == 'threaded') {
             $this->context = 'threaded-commenting';
         } else {
             $this->context = 'flat-commenting';
         }
         if ($_GET['_escaped_fragment_']) {
             $remote_path = $_GET['_escaped_fragment_'];
         } else {
             $remote_path = Muut_Comment_Overrides::instance()->getCommentsPath($post_id);
         }
         $content = $this->getIndexContentForPath($remote_path);
     }
     return $content;
 }
 /**
  * Get a row markup for given row data.
  *
  * @param int $post_id The ID of the post we are fetching the row data for.
  * @param mixed $timestamp The timestamp we are saying was the time for the post, or the template placeholder.
  * @param mixed $user_obj The user object in the format from the webhook.
  * @return string The Markup.
  * @author Paul Hughes
  * @since 3.0.2
  */
 public function getRowMarkup($post_id, $timestamp, $user_obj)
 {
     if (is_numeric($timestamp)) {
         $time_since = time() - $timestamp;
         if ($time_since < 60) {
             $list_time = _x('just now', 'comment-just-posted', 'muut');
         } elseif ($time_since < 60 * 60) {
             $list_time = floor($time_since / 60) . _x('m', 'abbreviation-for-minutes', 'muut');
         } elseif ($time_since < 60 * 60 * 24) {
             $list_time = floor($time_since / (60 * 60)) . _x('h', 'abbreviation-for-hours', 'muut');
         } elseif ($time_since < 60 * 60 * 24 * 7) {
             $list_time = floor($time_since / (60 * 60 * 24)) . _x('d', 'abbreviation-for-days', 'muut');
         } else {
             $list_time = floor($time_since / (60 * 60 * 24 * 7)) . _x('w', 'abbreviation-for-weeks', 'muut');
         }
     } else {
         $list_time = '%LISTTIME%';
     }
     if (is_numeric($post_id)) {
         $permalink = get_permalink($post_id);
         $title = get_the_title($post_id);
     } else {
         $permalink = '%POST_PERMALINK%';
         $title = '%POST_TITLE%';
     }
     $user_link_path = Muut_Post_Utility::getForumPageId() && Muut_Post_Utility::getForumPageId() != get_the_ID() ? get_permalink(Muut_Post_Utility::getForumPageId()) . '#!/' . $user_obj->path . '"' : false;
     $html = '<li class="muut_recentcomments" data-post-id="' . $post_id . '" data-timestamp="' . $timestamp . '" data-username="******">';
     $html .= apply_filters('muut_latest_comments_show_avatar', true) ? muut_get_user_facelink_avatar($user_obj->path, $user_obj->displayname, false, $user_link_path, $user_obj->img, false) : '';
     $html .= '<span class="recent-comments-post-title"><a href="' . $permalink . '">' . $title . '</a></span>';
     $html .= '<div class="muut-post-time-since">' . $list_time . '</div>';
     $html .= '</li>';
     return $html;
 }
 /**
  * Gets the channel page's remote path.
  *
  * @param int $page_id The page ID that we are getting the remote channel path for.
  * @param bool $no_suffix Whether to include ':comments' for unthreaded.
  * @return string|false Returns the path if one is found for the forum page or false if not.
  * @author Paul Hughes
  * @since 3.0
  */
 public static function getChannelRemotePathForPage($page_id, $no_suffix = false)
 {
     if (!is_numeric($page_id)) {
         return false;
     }
     $page_channel_options = Muut_Post_Utility::getPostOption($page_id, 'channel_settings');
     $path = isset($page_channel_options['channel_path']) ? $page_channel_options['channel_path'] : '';
     return $path;
 }
 /**
  * Displays the dismissible admin notice regarding the latest update.
  *
  * @return void
  * @author Paul Hughes
  * @since 3.0.3
  */
 public function maybeShowUpdateNotice()
 {
     $dismissed_notices = muut()->getOption('dismissed_notices', array());
     if (!isset($dismissed_notices['update_notice']) || !$dismissed_notices['update_notice']) {
         $forum_page_id = Muut_Post_Utility::getForumPageId();
         if ($forum_page_id) {
             echo '<div class="updated muut_admin_notice" id="muut_update_notice">';
             wp_nonce_field('muut_dismiss_notice', 'dismiss_nonce');
             echo '<span class="dismiss_notice_button"><a href="#" class="dismiss_notice">X</a></span>';
             echo '<p>' . sprintf(__('The %sMuut Plugin%s update to version 3.0.3 revised the default Forum Template (just a little!). You might want to head over to your %sForum Page%s and make sure it all looks as you expect! Check the post on our %sWordPress support forum%s about the latest release for details or help.', 'muut'), '<b>', '</b>', '<a href="' . get_permalink($forum_page_id) . '">', '</a>', '<a target="_blank" href="https://muut.com/forum/#!/wordpress">', '</a>') . '</p>';
             echo '<p>' . __('Happy Muuting! :-)') . '</p>';
             echo '</div>';
         } else {
             $dismissed_notices['update_notice'] = true;
             muut()->setOption('dismissed_notices', $dismissed_notices);
         }
     }
 }
<?php

/**
 * The post/page editor tab for channel preferences.
 *
 * @package   Muut
 * @copyright 2014 Muut Inc
 */
global $post;
$tab;
$meta_name = $tab['meta_name'];
$channel_settings = Muut_Post_Utility::getPostOption($post->ID, 'channel_settings');
$channel_defaults = muut()->getOption('channel_defaults');
$hide_online = isset($channel_settings['hide_online']) ? $channel_settings['hide_online'] : $channel_defaults['hide_online'];
$disable_uploads = isset($channel_settings['disable_uploads']) ? $channel_settings['disable_uploads'] : $channel_defaults['disable_uploads'];
$channel_path = isset($channel_settings['channel_path']) ? '/' . $channel_settings['channel_path'] : '';
?>
<p>
	<span class="checkbox_row"><input type="checkbox" name="<?php 
echo $tab['meta_name'];
?>
[enabled-tab]" class="muut_enable_<?php 
echo $tab['name'];
?>
" id="muut_enable_tab-<?php 
echo $tab['name'];
?>
" <?php 
checked($active_tab, $tab['name']);
?>
 value="1" /><label for="muut_enable_tab-<?php 
 /**
  * Gets the type of commenting enabled on a given commenting post (threaded or flat).
  *
  * @param int $post_id The commenting post id.
  * @return null|string The commenting type that is enabled or null if failed.
  * @author Paul Hughes
  * @since 3.0.2.1
  */
 public function getCommentingPostCommentType($post_id)
 {
     $post_commenting_options = Muut_Post_Utility::getPostOption($post_id, 'commenting_settings');
     if (isset($post_commenting_options['type'])) {
         return $post_commenting_options['type'];
     }
 }
$commenting_defaults = muut()->getOption('commenting_defaults');
$type = isset($comments_settings['type']) ? $comments_settings['type'] : $commenting_defaults['type'];
$disable_uploads = isset($comments_settings['disable_uploads']) ? $comments_settings['disable_uploads'] : $commenting_defaults['disable_uploads'];
?>
<p>
	<span class="checkbox_row"><input type="checkbox" name="<?php 
echo $tab['meta_name'];
?>
[enabled-tab]" class="muut_enable_<?php 
echo $tab['name'];
?>
" id="muut_enable_tab-<?php 
echo $tab['name'];
?>
" <?php 
checked(true, Muut_Post_Utility::isMuutCommentingPost($post->ID));
?>
 value="1" /><label for="muut_enable_tab-<?php 
echo $tab['name'];
?>
"><?php 
echo $tab['enable_text'];
?>
</label></span>
</p>
<div class="enabled_tab_wrapper">
	<p>
		<span class="muut_metabox_radio"><input type="radio" name="<?php 
echo $meta_name;
?>
[type]" id="muut_comments_type_flat" value="flat" <?php 
 /**
  * Static function for checking if (and what is) the post ID that a given muut path is commenting on.
  *
  * @param string $path The path we are comparing/checking for.
  * @return int|false The post ID, if it is a comment on a given post or false, if not found.
  */
 public static function getPostIdRepliedTo($path)
 {
     // Used to allow the adding of other "allowed" comments base domains if it has changed or whatnot.
     $comments_base_domains = apply_filters('muut_webhooks_allowed_comments_base_domains', array(muut()->getOption('comments_base_domain')));
     $matches = array();
     // Check if the comment path is in the Muut post comment path format.
     foreach ($comments_base_domains as $base_domain) {
         preg_match_all('/^\\/' . addslashes(muut()->getForumName()) . '\\/' . addslashes($base_domain) . '\\/([0-9]+)(?:\\/|\\#)?.*$/', $path, $matches);
         // If there is a match, return it and exit this loop and function.
         if (!empty($matches) && isset($matches[1][0]) && is_numeric($matches[1][0]) && Muut_Post_Utility::isMuutCommentingPost($matches[1][0])) {
             return $matches[1][0];
         }
     }
 }
 * The post/page editor tab for forum preferences.
 *
 * @package   Muut
 * @copyright 2014 Muut Inc
 */
global $post;
$tab;
$meta_name = $tab['meta_name'];
$forum_settings = Muut_Post_Utility::getPostOption($post->ID, 'forum_settings');
$forum_defaults = muut()->getOption('forum_defaults');
$forum_update_default = muut()->getOption('show_comments_in_forum_default');
$forum_defaults['show_comments_in_forum'] = $forum_update_default ? $forum_update_default : $forum_defaults['show_comments_in_forum'];
$hide_online = isset($forum_settings['hide_online']) ? $forum_settings['hide_online'] : $forum_defaults['hide_online'];
$disable_uploads = isset($forum_settings['disable_uploads']) ? $forum_settings['disable_uploads'] : $forum_defaults['disable_uploads'];
$forum_show_comments = isset($forum_settings['show_comments_in_forum']) ? $forum_settings['show_comments_in_forum'] : $forum_defaults['show_comments_in_forum'];
$forum_page_id = Muut_Post_Utility::getForumPageId();
if (!$forum_page_id || $forum_page_id == $post->ID) {
    ?>
	<p>
		<span class="checkbox_row"><input type="checkbox" name="<?php 
    echo $tab['meta_name'];
    ?>
[enabled-tab]" class="muut_enable_<?php 
    echo $tab['name'];
    ?>
" id="muut_enable_tab-<?php 
    echo $tab['name'];
    ?>
" <?php 
    checked($active_tab, $tab['name']);
    ?>
<?php

/**
 * The markup for the Muut page editor metabox.
 *
 * @package   Muut
 * @copyright 2014 Muut Inc
 */
global $post;
$is_forum = Muut_Post_Utility::isMuutPost($post->ID);
$forum_show_class = '';
if ($is_forum != '1') {
    $forum_show_class = 'hidden';
}
$remote_path = '/' . rawurldecode(Muut_Post_Utility::getChannelRemotePathForPage(get_the_ID(), true));
$tabs = Muut_Admin_Post_Editor::instance()->getMetaBoxTabsForCurrentPostType();
$tab_names = array();
foreach ($tabs as $tab) {
    $tab_names[] = $tab['name'];
}
$last_active_tab = get_post_meta(get_the_ID(), 'muut_last_active_tab', true);
$post_type_object = get_post_type_object(get_post_type());
?>
<div id="muut_metabox_tabs">
	<div class="wp-tab-bar">
		<ul id="muut_metabox_tabs_list" class="category-tabs">
			<?php 
$first_tab = true;
$active_tab = $last_active_tab;
foreach ($tabs as $slug => $tab) {
    $class = '';
 /**
  * Enabled callback for the commenting tab.
  *
  * @return bool True if it should be enabled, False if not.
  * @author Paul Hughes
  * @since 3.0
  */
 public function isCommentingTabEnabled()
 {
     if (!isset($this->metaboxTabs['commenting']['enabled'])) {
         global $post;
         $last_active_tab = get_post_meta($post->ID, 'muut_last_active_tab', true);
         if ($last_active_tab == $this->metaboxTabs['commenting']['name'] || Muut_Post_Utility::isMuutCommentingPost($post->ID)) {
             $this->metaboxTabs['commenting']['enabled'] = true;
         } else {
             $this->metaboxTabs['commenting']['enabled'] = false;
         }
     }
     return $this->metaboxTabs['commenting']['enabled'];
 }
 /**
  * Process the widget arguments to save the customization for that instance.
  *
  * @param array $new_instance The changed/new arguments.
  * @param array $old_instance The previous/old arguments.
  * @return void
  * @author Paul Hughes
  * @since 3.0.2
  */
 public function update($new_instance, $old_instance)
 {
     $instance = array();
     $instance['title'] = !empty($new_instance['title']) ? strip_tags($new_instance['title']) : '';
     $instance['disable_uploads'] = !empty($new_instance['disable_uploads']) ? $new_instance['disable_uploads'] : '0';
     // Make sure that the path is saved as SOMETHING.
     $default_path = isset($old_instance['muut_path']) ? $old_instance['muut_path'] : '';
     $default_path = empty($default_path) ? sanitize_title($instance['title']) : $default_path;
     $default_path = empty($default_path) ? sanitize_title($this->get_field_id('muut_path')) : $default_path;
     $default_path = !isset($old_instance['muut_path']) ? '' : $default_path;
     $instance['muut_path'] = !empty($new_instance['muut_path']) ? Muut_Post_Utility::sanitizeMuutPath($new_instance['muut_path']) : $default_path;
     return $instance;
 }