Make WordPress Core

Ticket #14569: comments.php

File comments.php, 5.2 KB (added by realcoolmanbd, 9 years ago)
Line 
1<?php
2if (DISQUS_DEBUG) {
3 echo "<p><strong>Disqus Debug</strong> thread_id: ".get_post_meta($post->ID, 'dsq_thread_id', true)."</p>";
4}
5?>
6
7<div id="disqus_thread">
8 <?php if (!get_option('disqus_disable_ssr') && have_comments()): ?>
9 <div id="dsq-content">
10
11<?php if (get_comment_pages_count() > 1 && get_option('page_comments')): // Are there comments to navigate through? ?>
12 <div class="navigation">
13 <div class="nav-previous">
14 <span class="meta-nav">&larr;</span>&nbsp;
15 <?php previous_comments_link( dsq_i('Older Comments')); ?>
16 </div>
17 <div class="nav-next">
18 <?php next_comments_link(dsq_i('Newer Comments')); ?>
19 &nbsp;<span class="meta-nav">&rarr;</span>
20 </div>
21 </div> <!-- .navigation -->
22<?php endif; // check for comment navigation ?>
23
24 <ul id="dsq-comments">
25 <?php
26 /* Loop through and list the comments. Tell wp_list_comments()
27 * to use dsq_comment() to format the comments.
28 */
29 wp_list_comments(array('callback' => 'dsq_comment'));
30 ?>
31 </ul>
32
33<?php if (get_comment_pages_count() > 1 && get_option('page_comments')): // Are there comments to navigate through? ?>
34 <div class="navigation">
35 <div class="nav-previous">
36 <span class="meta-nav">&larr;</span>
37 &nbsp;<?php previous_comments_link( dsq_i('Older Comments') ); ?>
38 </div>
39 <div class="nav-next">
40 <?php next_comments_link( dsq_i('Newer Comments') ); ?>
41 &nbsp;<span class="meta-nav">&rarr;</span>
42 </div>
43 </div><!-- .navigation -->
44<?php endif; // check for comment navigation ?>
45
46 </div>
47
48 <?php endif; ?>
49</div>
50
51<?php
52
53global $wp_version;
54
55$embed_vars = array(
56 'disqusConfig' => array(
57 'platform' => 'wordpress@'.$wp_version,
58 'language' => apply_filters( 'disqus_language_filter', '' ),
59 ),
60 'disqusIdentifier' => dsq_identifier_for_post( $post ),
61 'disqusShortname' => strtolower( get_option( 'disqus_forum_url' ) ),
62 'disqusTitle' => dsq_title_for_post( $post ),
63 'disqusUrl' => get_permalink(),
64 'options' => array(
65 'manualSync' => get_option('disqus_manual_sync'),
66 ),
67 'postId' => $post->ID,
68);
69
70// Add SSO vars if enabled
71$sso = dsq_sso();
72if ($sso) {
73 global $current_site;
74
75 foreach ($sso as $k=>$v) {
76 $embed_vars['disqusConfig'][$k] = $v;
77 }
78
79 $siteurl = site_url();
80 $sitename = get_bloginfo('name');
81 $embed_vars['disqusConfig']['sso'] = array(
82 'name' => wp_specialchars_decode($sitename, ENT_QUOTES),
83 'button' => get_option('disqus_sso_button'),
84 'url' => $siteurl.'/wp-login.php',
85 'logout' => $siteurl.'/wp-login.php?action=logout',
86 'width' => '800',
87 'height' => '700',
88 );
89}
90
91if ( get_option('dsq_external_js') == '1' ) {
92 wp_register_script( 'dsq_embed_script', plugins_url( '/media/js/disqus.js', __FILE__ ) );
93 wp_localize_script( 'dsq_embed_script', 'embedVars', $embed_vars );
94 wp_enqueue_script( 'dsq_embed_script', plugins_url( '/media/js/disqus.js', __FILE__ ) );
95}
96else {
97
98?>
99<script type="text/javascript">
100var disqus_url = '<?php echo get_permalink(); ?>';
101var disqus_identifier = '<?php echo dsq_identifier_for_post($post); ?>';
102var disqus_container_id = 'disqus_thread';
103var disqus_shortname = '<?php echo strtolower(get_option('disqus_forum_url')); ?>';
104var disqus_title = <?php echo cf_json_encode( dsq_title_for_post($post) ); ?>;
105var disqus_config_custom = window.disqus_config;
106var disqus_config = function () {
107 /*
108 All currently supported events:
109 onReady: fires when everything is ready,
110 onNewComment: fires when a new comment is posted,
111 onIdentify: fires when user is authenticated
112 */
113
114 <?php
115 $sso = dsq_sso();
116 if ($sso) {
117 foreach ($sso as $k=>$v) {
118 echo 'this.page.' . esc_js($k) . ' = \'' . esc_js($v) . '\';';
119 echo "\n";
120 }
121 echo dsq_sso_login();
122 }
123 ?>
124
125 this.language = '<?php echo esc_js( apply_filters('disqus_language_filter', '') ) ?>';
126 <?php if (!get_option('disqus_manual_sync')): ?>
127 this.callbacks.onReady.push(function () {
128
129 // sync comments in the background so we don't block the page
130 var script = document.createElement('script');
131 script.async = true;
132 script.src = '?cf_action=sync_comments&post_id=<?php echo esc_attr( $post->ID ); ?>';
133
134 var firstScript = document.getElementsByTagName('script')[0];
135 firstScript.parentNode.insertBefore(script, firstScript);
136 });
137 <?php endif; ?>
138
139 if (disqus_config_custom) {
140 disqus_config_custom.call(this);
141 }
142};
143
144(function() {
145 var dsq = document.createElement('script'); dsq.type = 'text/javascript';
146 dsq.async = true;
147 dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
148 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
149})();
150</script>
151
152<?php
153
154}
155
156?>