-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisqus.php
163 lines (136 loc) · 5.21 KB
/
disqus.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/*
Plugin Name: Disqus
Description: Provides Discus comments support on pages
Version: 0.2
Author: Rob Antonishen
Author URI: http://ffaat.poweredbyclear.com/
*/
# get correct id for plugin
$thisfile=basename(__FILE__, ".php");
# register plugin
register_plugin(
$thisfile,
'Disqus Comments',
'0.2',
'Rob Antonishen',
'http://ffaat.poweredbyclear.com',
'Provides Disqus Commenting',
'plugins',
'disqus_config'
);
# activate filter
add_action('plugins-sidebar','createSideMenu',array($thisfile,'Disqus'));
add_filter('content','disqus_display');
# global vars
$disqus_conf = disqus_loadconf();
/* frontend contant replacement */
function disqus_display($contents) {
$tmp_content = $contents;
$location = stripos($tmp_content,"(% disqus %)");
if ($location !== FALSE)
{
$tmp_content = str_replace("(% disqus %)","",$tmp_content);
$start_content = substr($tmp_content, 0 ,$location);
$end_content = substr($tmp_content, $location, strlen($tmp_content)-$location );
$tmp_content = $start_content . return_disqus() . $end_content;
}
// build page
return $tmp_content;
}
/* echo the disqus page code for use in templates */
function get_disqus() {
echo return_disqus();
}
/* returns the disqus page code */
function return_disqus() {
global $disqus_conf;
$new_content = '<div id="disqus_thread"></div>';
$new_content .= '<script type="text/javascript">';
$new_content .= "var disqus_shortname = '" . $disqus_conf['shortname'] . "';";
$new_content .= "var disqus_developer = '" . $disqus_conf['developer'] . "';";
$new_content .= "var disqus_identifier = '" . return_page_slug() . "';";
$new_content .= "var disqus_url = '" . get_page_url(True) . "';";
$new_content .= "var disqus_title = '" . return_page_title() . "';";
$new_content .= <<<INLINECODE
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
INLINECODE;
return $new_content;
}
/* backend management page */
function disqus_config() {
global $disqus_conf;
/* Save Settings */
if (isset($_POST['submit_settings']))
{
if (isset($_POST['developer']))
{
$disqus_conf['developer'] = 1;
}
else
{
$disqus_conf['developer'] = 0;
}
if (isset($_POST['shortname']))
$disqus_conf['shortname'] = $_POST['shortname'];
disqus_saveconf();
echo '<div style="display: block;" class="updated">Updated settings.</div>';
}
echo "<label>Disqus Configuration</label><br/><br/>";
echo '<form name="disqus_settings" action="load.php?id=disqus" method="post">';
echo '<p>Your forum\'s shortname, which is the unique identifier for your website as registered on Disqus:<br />';
echo '<input name="shortname" type="text" size="90" value="'.$disqus_conf['shortname'] .'"></p>';
echo '<input name="developer" type="checkbox" value="Y"';
if ($disqus_conf['developer'] == 1) echo ' checked';
echo '> Developer Mode: testing the system on an inaccessible website, e.g. secured staging server or a local environment.<br /><br />';
echo "<input name='submit_settings' class='submit' type='submit' value='Save Settings'>\n";
echo '</form>';
echo '<p /><p><i>Enable comments on a single page by adding the tag <b>(% disqus %)</b> in that page.<br />';
echo 'Alternately insert <b><?php get_disqus(); ?></b> in your page template to have comments for all pages.</i></p>';
}
/* get config settings from file */
function disqus_loadconf()
{
$vals=array();
$configfile=GSDATAOTHERPATH."disqus.xml";
if (!file_exists($configfile))
{
//default settings
$xmlstr = "<?xml version='1.0'?><disqussettings><developer>0</developer><shortname></shortname></disqussettings>";
$fp = fopen($configfile, 'w') or exit('Unable to save ' . $configfile . ', check GetSimple privileges.');
// save the contents of output buffer to the file
fwrite($fp, $xmlstr);
// close the file
fclose($fp);
}
$fp = @fopen($configfile,"r");
$xmlvals = getXML($configfile);
fclose($fp);
$node = $xmlvals->children();
$vals['developer'] = (int)$node->developer;
$vals['shortname'] = (string)$node->shortname;
return($vals);
}
/* save config settings to file*/
function disqus_saveconf()
{
global $disqus_conf;
$configfile=GSDATAOTHERPATH."disqus.xml";
$xmlstr = '<?xml version=\'1.0\'?><disqussettings>';
$xmlstr .= "<developer>" . $disqus_conf['developer'] . "</developer>";
$xmlstr .= "<shortname>" . $disqus_conf['shortname'] . "</shortname>";
$xmlstr .= "</disqussettings>";
$fp = fopen($configfile, 'w') or exit('Unable to save ' . $configfile . ', check GetSimple privileges.');
// save the contents of output buffer to the file
fwrite($fp, $xmlstr);
// close the file
fclose($fp);
}
?>