View source
<?php
function disqus_migrate_help($path, $arg) {
switch ($path) {
case 'admin/settings/disqus/export':
return '<p>' . t('When you are ready to perform an export, visit !thispage.', array(
'!thispage' => l('this page', 'admin/content/comment/disqus_export'),
)) . '</p>';
case 'admin/content/comment/disqus_export':
return '<p>' . t('Exporting via the API requires that you have registered your website as an application with Disqus and filled our your ' . 'private and public keys in the !mainsettings. Exporting via XML will just gather all of your websites comments ' . 'and format them for importing manually into Disqus. The recommended method is using the API. Visit the !exportsettings ' . 'to customize how these exports are performed.', array(
'!exportsettings' => l('export settings', 'admin/settings/disqus/export'),
'!mainsettings' => l('main settings', 'admin/settings/disqus'),
)) . '</p>';
}
}
function disqus_migrate_menu() {
$items = array();
$items['admin/settings/disqus/import'] = array(
'title' => 'Import',
'description' => 'Settings for importing comments from Disqus into Drupal.',
'access arguments' => array(
'administer disqus',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'disqus_migrate_admin_import_settings',
),
'file' => 'include/disqus_migrate.import.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/content/comment/disqus_import'] = array(
'title' => 'Disqus Import',
'description' => 'Import comments from Disqus into Drupal.',
'access arguments' => array(
'administer disqus',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'disqus_migrate_admin_import',
),
'file' => 'include/disqus_migrate.import.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/settings/disqus/export'] = array(
'title' => 'Export',
'description' => 'Settings for exporting comments from Drupal into Disqus',
'access arguments' => array(
'administer disqus',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'disqus_migrate_admin_export_settings',
),
'file' => 'include/disqus_migrate.export.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/content/comment/disqus_export'] = array(
'title' => 'Disqus Export',
'description' => 'Export comments from the Drupal to Disqus.',
'access arguments' => array(
'administer disqus',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'disqus_migrate_admin_export',
),
'file' => 'include/disqus_migrate.export.inc',
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function disqus_migrate_cron() {
if (variable_get('disqus_migrate_sync_enabled', 0) == 0) {
return;
}
$last_run = variable_get('disqus_migrate_last_sync', 0);
$interval = variable_get('disqus_migrate_sync_interval', 0);
$time_elapsed = time() - $last_run;
if ($time_elapsed < $interval) {
return;
}
module_load_include('inc', 'disqus_migrate', 'include/disqus_migrate.import');
$last_synced_time = _disqus_migrate_last_synced_time();
_disqus_migrate_import($last_synced_time + 1);
variable_set('disqus_migrate_last_sync', time());
}
function _disqus_migrate_api_request($resource, $parameters = array(), $method = 'GET', $include_forum = TRUE) {
if ($include_forum) {
$parameters['forum'] = variable_get('disqus_domain', '');
}
$data = http_build_query($parameters, '', '&');
$url = 'http://disqus.com/api/3.0/' . $resource . '?' . $data;
$headers = array(
'Content-Type' => 'application/x-www-form-urlencoded',
);
$response = drupal_http_request($url, $headers, $method);
$content = $response->data;
$data = json_decode($content);
return $data;
}
function _disqus_migrate_last_synced_time() {
$last_synced_time = db_result(db_query("SELECT MAX(c.timestamp) FROM {comments} c INNER JOIN {disqus_migrate} dm ON c.cid = dm.cid"));
if (empty($last_synced_time)) {
$last_synced_time = 0;
}
return $last_synced_time;
}
function _disqus_migrate_api_exists() {
if (file_exists('sites/all/libraries/disqusapi/disqusapi.php')) {
return TRUE;
}
return FALSE;
}
function _disqus_migrate_api_load() {
include_once 'sites/all/libraries/disqusapi/disqusapi.php';
}