Skip to content
5 changes: 3 additions & 2 deletions disqus/disqus.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function dsq_sync_comments($comments) {

// and follow up using legacy Disqus agent
if (!$commentdata) {
$commentdata = $wpdb->get_row($wpdb->prepare( "SELECT comment_ID, comment_parent FROM $wpdb->comments WHERE comment_agent = 'Disqus/1.0:{$comment->id}' LIMIT 1"), ARRAY_A);
$commentdata = $wpdb->get_row($wpdb->prepare( "SELECT comment_ID, comment_parent FROM $wpdb->comments WHERE comment_agent = 'Disqus/1.0:%d' LIMIT 1", $comment->id), ARRAY_A);
}
if (!$commentdata) {
// Comment doesnt exist yet, lets insert it
Expand All @@ -301,6 +301,7 @@ function dsq_sync_comments($comments) {
'comment_approved' => $approved,
'comment_agent' => 'Disqus/1.1('.DISQUS_VERSION.'):'.intval($comment->id),
'comment_type' => '',
'comment_parent' => 0
);
if ($comment->is_anonymous) {
$commentdata['comment_author'] = $comment->anonymous_author->name;
Expand Down Expand Up @@ -336,7 +337,7 @@ function dsq_sync_comments($comments) {

$commentdata['comment_ID'] = wp_insert_comment($commentdata);
if (DISQUS_DEBUG) {
echo "inserted {$comment->id}: id is {$commentdata[comment_ID]}\n";
echo "inserted {$comment->id}: id is {$commentdata['comment_ID']}\n";
}
}
if (!$commentdata['comment_parent'] && $comment->parent_post) {
Expand Down
2 changes: 1 addition & 1 deletion disqus/lib/wp-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function import_wordpress_comments(&$wxr, $timestamp, $eof=true) {
)
)
);
if ($response->errors) {
if (is_wp_error($response)) {
// hack
$this->api->last_error = $response->errors;
return -1;
Expand Down
59 changes: 34 additions & 25 deletions disqus/lib/wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,39 @@ function print_line() {
print("{$result}\n");
}

if (!empty($argc)) {
for ($x=0; $x < $argc; $x++){
$param = $argv[$x];
if (strpos($param, '--host=') === 0) {
$param_host = substr($param, strpos($param, '=') + 1);
}
if (strpos($param, '--uri=') === 0) {
$param_uri = substr($param, strpos($param, '=') + 1);
}
}
}

define('DOING_AJAX', true);
define('WP_USE_THEMES', false);
if (isset($_ENV['WORDPRESS_PATH'])) {
define('ABSPATH', $_ENV['WORDPRESS_PATH']);
} else {
if (substr($_SERVER['SCRIPT_FILENAME'], 0, 1) != '/') {
$script_path = $_SERVER['PWD'] . $_SERVER['SCRIPT_FILENAME'];
} else {
$script_path = $_SERVER['SCRIPT_FILENAME'];
}
$tree = '';
$paths = array();
$chunks = explode('/', dirname($script_path));
foreach ($chunks as $chunk) {
if (!$chunk) continue;
$tree = $tree.'/'.$chunk;
array_push($paths, $tree);
}
$paths = array_reverse($paths);
$path = str_replace('\\', '/', dirname(__FILE__));
$parts = explode('/', $path);

foreach ($paths as $path) {
if (is_file($path.'/wp-config.php')) {
define('ABSPATH', $path . '/');
break;
}
if (count($parts) > 4 && is_file($tmp_path = implode('/', array_slice($parts, 0, -4)) . '/wp-config.php')) {
// Logical try for default plugin install, 4 levels up. (wp-content/plugins/disqus-comment-system/lib)
define('ABSPATH', dirname($tmp_path) . '/');
} else {
// Iterate upwards until finding any wp-config.php file.
// Not the best security here, as we could end up running an injected wp-config.php script with the shell user privs.
do {
$tmp_path = implode('/', $parts) . '/wp-config.php';
if(@is_file($tmp_path)) {
define('ABSPATH', dirname($tmp_path) . '/');
break;
}
} while (null !== array_pop($parts));
}
}

Expand All @@ -53,13 +61,14 @@ function print_line() {
}

$_SERVER = array(
"HTTP_HOST" => "disqus.com",
"SCRIPT_NAME" => "",
"PHP_SELF" => __FILE__,
"SERVER_NAME" => "localhost",
"REQUEST_URI" => "/",
"REQUEST_METHOD" => "GET"
'HTTP_HOST' => empty($param_host) ? 'disqus.com' : $param_host,
'SERVER_NAME' => empty($param_host) ? 'localhost' : $param_host,
'REQUEST_URI' => empty($param_uri) ? '/' : $param_uri,
'REQUEST_METHOD' => 'GET',
'SCRIPT_NAME' => '',
'PHP_SELF' => __FILE__
);

require_once(ABSPATH . 'wp-config.php');

// swap out the object cache due to memory constraints
Expand Down
10 changes: 8 additions & 2 deletions disqus/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ function wp_nonce_field() {}

// Handle advanced options.
if ( isset($_POST['disqus_forum_url']) && isset($_POST['disqus_replace']) ) {
update_option('disqus_partner_key', trim(stripslashes($_POST['disqus_partner_key'])));
if (!empty($_POST['disqus_partner_key'])) {
update_option('disqus_partner_key', trim(stripslashes($_POST['disqus_partner_key'])));
}
update_option('disqus_replace', $_POST['disqus_replace']);
update_option('disqus_cc_fix', isset($_POST['disqus_cc_fix']));
update_option('disqus_manual_sync', isset($_POST['disqus_manual_sync']));
Expand Down Expand Up @@ -533,9 +535,13 @@ function wp_nonce_field() {}
<h3><?php echo dsq_i('Debug Information'); ?></h3>
<p><?php echo dsq_i('Having problems with the plugin? Check out our <a href="%s" onclick="window.open(this.href); return false">WordPress Troubleshooting</a> documentation. You can also <a href="%s">drop us a line</a> including the following details and we\'ll do what we can.', 'http://docs.disqus.com/help/87/', 'mailto:[email protected]'); ?></p>
<textarea style="width:90%; height:200px;">URL: <?php echo get_option('siteurl'); ?>

PHP Version: <?php echo phpversion(); ?>

Version: <?php echo $wp_version; ?>
Active Theme: <?php $theme = get_theme(get_current_theme()); echo $theme['Name'].' '.$theme['Version']; ?>

Active Theme: <?php $theme = function_exists('wp_get_theme') ? wp_get_theme() : get_theme(get_current_theme()); echo $theme['Name'].' '.$theme['Version']; ?>

URLOpen Method: <?php echo dsq_url_method(); ?>

Plugin Version: <?php echo DISQUS_VERSION; ?>
Expand Down
5 changes: 3 additions & 2 deletions disqus/scripts/export-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Incrementally (in chunks of EXPORT_CHUNK_SIZE) exports all comments to DISQUS.
*
* ``php export-comments.php``
* ``php export-comments.php [--host=hostname.com] [--uri=/]``
*/

require_once(dirname(__FILE__) . '/../lib/wp-cli.php');
Expand Down Expand Up @@ -71,6 +71,7 @@

// we need to send empty files to ensure EOF happens
while (($at === 0 && $post_id == $max_post_id) || $at < $total_comments) {
$time = abs(microtime() - $start);
if ($post_id == $max_post_id && ($at + EXPORT_CHUNK_SIZE) >= $total_comments) {
$eof = 1;
}
Expand Down Expand Up @@ -103,4 +104,4 @@
print_line('Status available at http://import.disqus.com/group/%d/', $group_id);
}
print_line('---------------------------------------------------------');
?>
?>
5 changes: 3 additions & 2 deletions disqus/scripts/import-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Incrementally downloads all comments from DISQUS.
*
* ``php import-comments.php``
* ``php import-comments.php [--host=hostname.com] [--uri=/]``
*/

require_once(dirname(__FILE__) . '/../lib/wp-cli.php');
Expand Down Expand Up @@ -60,4 +60,5 @@
print_line('---------------------------------------------------------');
print_line('Done (took %.2fs)! %d comments imported from DISQUS', $total_time, $total);
print_line('---------------------------------------------------------');
?>

?>