/** * Gets a general set of option/setting for a given Muut page. * * @param int $post_id The page ID. * @param string $option_name The option name. * @param mixed $default The default if not found. * @return mixed The option * @author Paul Hughes * @since 3.0.2 */ function muut_get_page_general_option($post_id, $option_name, $default = '') { $return = $default; if (class_exists('Muut_Post_Utility')) { $return = Muut_Post_Utility::getPostOption($post_id, $option_name, $default); } return $return; }
/** * 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; }
/** * Prints the JS necessary on a given frontend page. * * @return void * @author Paul Hughes * @since 3.0 */ public function printCurrentPageJs() { if ($this->needsMuutResources() || !is_admin() && get_post()) { echo '<script type="text/javascript">'; echo 'var muut_object = jQuery();'; echo 'if ( typeof ajaxurl == "undefined" ) { var ajaxurl = "' . admin_url('admin-ajax.php') . '"; }'; echo 'function muutObj() { if( typeof muut_object.path == "undefined" ) { if ( typeof muut() != "undefined" ) { muut_object = muut(); } } return muut_object; }'; if ($this->getOption('subscription_use_signed_setup') && $this->getOption('website_uses_caching')) { echo 'var muut_must_fetch_signed = true;'; echo 'var muut_fetch_signed_nonce = "' . wp_create_nonce('muut_get_signed') . '";'; } echo '</script>'; $page_id = get_the_ID(); $forum_page_id = Muut_Post_Utility::getForumPageId(); if (Muut_Post_Utility::isMuutPost($page_id)) { echo '<script type="text/javascript">'; if (Muut_Post_Utility::getForumPageId() == $page_id) { $forum_settings = Muut_Post_Utility::getPostOption($page_id, 'forum_settings'); echo 'var muut_current_page_permalink = "' . get_permalink($page_id) . '";'; echo 'var muut_comments_base_domain = "' . $this->getOption('comments_base_domain') . '";'; if ($this->getOption('replace_comments')) { echo 'var muut_show_comments_in_nav = ' . $forum_settings['show_comments_in_forum'] . ';'; Muut_Post_Utility::getPostOption($page_id, 'forum_settings'); } } echo '</script>'; } if (Muut_Post_Utility::getForumPageId() != $page_id && (is_active_widget(false, false, 'muut_online_users_widget') || is_active_widget(false, false, 'muut_my_feed_widget') || is_active_widget(false, false, 'muut_channel_embed_widget') || is_active_widget(false, false, 'muut_latest_comments_widget') || is_active_widget(false, false, 'muut_online_users_widget') || is_active_widget(false, false, 'muut_trending_posts_widget'))) { echo '<script type="text/javascript">'; echo 'var muut_widget_conf = { url: "' . $this->getForumIndexUri() . '", path: "/' . $this->getForumName() . '", widget: true };'; echo 'var muut_force_load = true;'; if ($forum_page_id) { echo 'var muut_forum_page_permalink = "' . get_permalink($forum_page_id) . '";'; } echo '</script>'; } // Print the various and proper JS templates for items like Muut user avatars. } }
/** * 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; }
<?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']; } }
<?php /** * The post/page editor tab for commenting. * * @package Muut * @copyright 2014 Muut Inc */ global $post; $tab; $post_type_tabs = Muut_Admin_Post_Editor::instance()->getMetaBoxTabsForCurrentPostType(); unset($post_type_tabs[$tab['slug']]); $post_type_object = get_post_type_object($post->post_type); $post_type_label = $post_type_object->labels->singular_name; $meta_name = $tab['meta_name']; $comments_settings = Muut_Post_Utility::getPostOption($post->ID, 'commenting_settings'); $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
<?php /** * 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']; ?>
/** * Saves the settings on a given tab. * * @param array $tab The tab we are saving. * @param int $post_id The ID of the post we are saving. * @param WP_Post $post The post (or page) object that is being saved. * @return void * @author Paul Hughes * @since 3.0 */ public function saveMuutPostTab($tab, $post_id, $post) { $muut_tabs_to_save = array(); foreach ($this->defaultTabs as $default_tab) { $muut_tabs_to_save[] = $default_tab['name']; } if (!in_array($tab['name'], $muut_tabs_to_save) || !empty($tab['post_types']) && !in_array($post->post_type, (array) $tab['post_types'])) { return; } switch ($tab['name']) { case 'commenting-tab': $tab_options = array(); if (isset($_POST[$tab['meta_name']])) { $tab_options = $_POST[$tab['meta_name']]; } $boolean_values = array('disable_uploads'); foreach ($boolean_values as $boolean_value) { $tab_options[$boolean_value] = isset($tab_options[$boolean_value]) ? $tab_options[$boolean_value] : '0'; } Muut_Post_Utility::setPostOption($post_id, $tab['meta_name'], $tab_options); break; case 'channel-tab': $tab_options = array(); if (isset($_POST[$tab['meta_name']])) { $tab_options = $_POST[$tab['meta_name']]; $tab_current_options = Muut_Post_Utility::getPostOption($post_id, $tab['meta_name']); } $boolean_values = array('hide_online', 'disable_uploads'); foreach ($boolean_values as $boolean_value) { $tab_options[$boolean_value] = isset($tab_options[$boolean_value]) ? $tab_options[$boolean_value] : '0'; } $channel_path = isset($tab_options['channel_path']) ? $tab_options['channel_path'] : ''; if (!isset($tab_options['channel_path']) || $tab_options['channel_path'] == '' || !$tab_options['channel_path']) { // If no path is saved yet, let's generate one and save it. $path = sanitize_title($post->post_name); $ancestors = get_post_ancestors($post); foreach ($ancestors as $ancestor) { if (Muut_Post_Utility::isMuutChannelPage($ancestor) && Muut_Post_Utility::getChannelRemotePathForPage($ancestor, true)) { $path = Muut_Post_Utility::getChannelRemotePathForPage($ancestor, true) . '/' . $path; } } $channel_path = $path; } elseif (isset($tab_options['channel_path']) && $tab_options['channel_path'] != '') { $channel_path = Muut_Post_Utility::sanitizeMuutPath($tab_options['channel_path']); } $tab_options['channel_path'] = $channel_path; Muut_Post_Utility::setPostOption($post_id, $tab['meta_name'], $tab_options); break; case 'forum-tab': $tab_options = array(); if (isset($_POST[$tab['meta_name']])) { $tab_options = $_POST[$tab['meta_name']]; } $boolean_values = array('hide_online', 'disable_uploads', 'show_comments_in_forum'); foreach ($boolean_values as $boolean_value) { $tab_options[$boolean_value] = isset($tab_options[$boolean_value]) ? $tab_options[$boolean_value] : '0'; } // Remove the default setting for showing comments in forum, if it was copied // over from an older version of the plugin. if (muut()->getOption('show_comments_in_forum_default')) { muut()->setOption('show_comments_in_forum_default', null); } Muut_Post_Utility::setPostOption($post_id, $tab['meta_name'], $tab_options); Muut_Post_Utility::setAsForumPage($post_id); break; } }