/**
  * Initialise Livefyre auth
  */
 public static function init_auth()
 {
     if (self::$auth_initiated) {
         return false;
     }
     self::$auth_initiated = true;
     LFAPPS_View::render_partial('script_auth');
 }
 public static function init_sidenotes_script()
 {
     if (!self::display_sidenotes()) {
         return false;
     }
     Livefyre_Apps::init_auth();
     LFAPPS_View::render_partial('script', array(), 'sidenotes');
 }
 /**
  * Run LiveChat page
  */
 public static function menu_chat()
 {
     if (isset($_GET['allow_comments_id'])) {
         $allow_id = sanitize_text_field($_GET['allow_comments_id']);
         if ($allow_id == 'all_posts') {
             self::update_posts_nc(false);
         } else {
             if ($allow_id == 'all_pages') {
                 self::update_posts_nc(false);
             } else {
                 self::update_posts_nc($allow_id, false);
             }
         }
     }
     LFAPPS_View::render('general', array(), 'chat');
 }
 /**
  * Run Livefyre Comments page
  */
 public static function menu_comments()
 {
     //hide import message call
     if (isset($_GET['hide_import_message'])) {
         update_option('livefyre_apps-livefyre_import_status', 'complete');
         wp_redirect(Livefyre_Apps_Admin::get_page_url('livefyre_apps_comments'));
         exit;
     }
     //check for import status updates
     if (isset($_GET['status'])) {
         update_option('livefyre_apps-' . 'livefyre_import_status', sanitize_text_field($_GET['status']));
         if (isset($_GET['message'])) {
             update_option('livefyre_apps-' . 'livefyre_import_message', urldecode(sanitize_text_field($_GET['message'])));
         }
     }
     if (isset($_GET['allow_comments_id'])) {
         $allow_id = sanitize_text_field($_GET['allow_comments_id']);
         if ($allow_id == 'all_posts') {
             self::update_posts_nc(false);
         } else {
             if ($allow_id == 'all_pages') {
                 self::update_posts_nc(false);
             } else {
                 self::update_posts_nc($allow_id, false);
             }
         }
     }
     //process settings form
     if (isset($_POST['livefyre_comments_general']) && check_admin_referer('form-livefyre_comments_general')) {
         $excludes = array('_builtin' => false);
         $post_types = get_post_types($args = $excludes);
         $post_types = array_merge(array('post' => 'post', 'page' => 'page'), $post_types);
         foreach ($post_types as $post_type) {
             $post_type_name = 'livefyre_display_' . $post_type;
             if (isset($_POST[$post_type_name])) {
                 update_option('livefyre_apps-' . $post_type_name, true);
             } else {
                 update_option('livefyre_apps-' . $post_type_name, false);
             }
         }
         Livefyre_Apps::$form_saved = true;
     }
     LFAPPS_View::render('general', array(), 'comments');
 }
 public static function init_shortcode($atts = array())
 {
     if (!self::show_blog()) {
         return;
     }
     if (isset($atts['article_id'])) {
         $articleId = $atts['article_id'];
         $title = isset($pagename) ? $pagename : 'Comments (ID: ' . $atts['article_id'];
         global $wp;
         $url = add_query_arg($_SERVER['QUERY_STRING'], '', home_url($wp->request));
         $tags = array();
     } else {
         global $post;
         if (get_the_ID() !== false) {
             $articleId = apply_filters('livefyre_article_id', get_the_ID());
             $title = apply_filters('livefyre_collection_title', get_the_title(get_the_ID()));
             $url = apply_filters('livefyre_collection_url', get_permalink(get_the_ID()));
             $tags = array();
             $posttags = get_the_tags($post->ID);
             if ($posttags) {
                 foreach ($posttags as $tag) {
                     array_push($tags, $tag->name);
                 }
             }
         } else {
             return;
         }
     }
     Livefyre_Apps::init_auth();
     $network = get_option('livefyre_apps-livefyre_domain_name', 'livefyre.com');
     $network = $network == '' ? 'livefyre.com' : $network;
     $siteId = get_option('livefyre_apps-livefyre_site_id');
     $siteKey = get_option('livefyre_apps-livefyre_site_key');
     $network_key = get_option('livefyre_apps-livefyre_domain_key', '');
     $network = Livefyre::getNetwork($network, strlen($network_key) > 0 ? $network_key : null);
     $site = $network->getSite($siteId, $siteKey);
     $collectionMetaToken = $site->buildCollectionMetaToken($title, $articleId, $url, array("tags" => $tags, "type" => "liveblog"));
     $checksum = $site->buildChecksum($title, $url, $tags, 'liveblog');
     $strings = apply_filters('livefyre_custom_blog_strings', null);
     $livefyre_element = 'livefyre-blog-' . $articleId;
     return LFAPPS_View::render_partial('script', compact('siteId', 'siteKey', 'network', 'articleId', 'collectionMetaToken', 'checksum', 'strings', 'livefyre_element'), 'blog', true);
 }
 /**
  * Run Livefyre Apps General page
  */
 public static function menu_general()
 {
     $conflicting_plugins = Livefyre_Apps::get_conflict_plugins();
     if (count($conflicting_plugins) > 0) {
         self::menu_plugin_conflict();
         return;
     }
     //process data returned from livefyre.com community sign up
     if (self::verified_blog()) {
         update_option('livefyre_apps-livefyre_domain_name', 'livefyre.com');
         update_option('livefyre_apps-livefyre_site_id', sanitize_text_field($_GET["site_id"]));
         update_option('livefyre_apps-livefyre_site_key', sanitize_text_field($_GET["secretkey"]));
     }
     LFAPPS_View::render('general');
 }
 target="_blank">Livefyre Admin</a>
                        <br/>
                        <a href="http://support.livefyre.com" target="_blank">Livefyre Support</a>
                    </div>
                </div>
            </div>
        </div>        
    </div>
</div>

<?php 
add_thickbox();
?>

<?php 
if (!get_option('livefyre_apps-initial_modal_shown', false)) {
    ?>
<script>
    jQuery(document).ready(function(){
        tb_show("","#TB_inline?inlineId=lfapps-initial-modal&width=680&height=310");
    });
</script>
<?php 
}
?>
<div id='lfapps-initial-modal' style='display:none'>
    <?php 
LFAPPS_View::render_partial('initial_modal');
?>
</div>
<?php

$import_status = get_option('livefyre_apps-livefyre_import_status');
if ($import_status !== 'complete') {
    ?>
    <?php 
    LFAPPS_View::render_partial('import_script', array(), 'comments');
    ?>
    <div class="postbox-container postbox-large">
        <div id="normal-sortables" class="meta-box-sortables ui-sortable">
            <div id="referrers" class="postbox livefyre-import-postbox">
                <div class="handlediv" title="Click to toggle"><br></div>
                <h3 class="hndle"><span><?php 
    esc_html_e('Livefyre Import Status', 'lfapps-comments');
    ?>
</span></h3>
                <div class='inside'>
                <?php 
    if ($import_status === 'error') {
        ?>
                    <h4><?php 
        esc_html_e('Status:', 'lfapps-comments');
        ?>
 <span><?php 
        esc_html_e('Failed', 'lfapps-comments');
        ?>
 </span></h4>

                    <?php 
        echo "<p>Message: " . esc_html(get_option('livefyre_apps-livefyre_import_message', '')) . "</p>";
        ?>
 /**
  * Run Livefyre Comments page
  */
 public static function menu_sidenotes()
 {
     LFAPPS_View::render('general', array(), 'sidenotes');
 }
 /**
  * Run LiveBlog page
  */
 public static function menu_blog()
 {
     LFAPPS_View::render('general', array(), 'blog');
 }