'. t('Uses the Disqus comment system to enhance comments.', array('@disqus' => 'http://disqus.com')) .'
'; $output.= ''. t('The following provides the general configuration options for the Disqus comment web service.', array('@disqus' => 'http://disqus.com')) .'
'; } } /** * Implementation of hook_perm(). */ function disqus_perm() { return array( 'administer disqus', 'view disqus comments', 'display disqus comments on profile', ); } /** * Implementation of hook_menu(). */ function disqus_menu() { $items = array(); $items['admin/settings/disqus'] = array( 'title' => 'Disqus', 'description' => 'Provides configuration options for the Disqus comment system.', 'access arguments' => array('administer disqus'), 'page callback' => 'drupal_get_form', 'page arguments' => array('disqus_admin_settings'), 'file' => 'disqus.admin.inc' ); $items['admin/settings/disqus/general'] = array( 'title' => 'General', 'type' => MENU_DEFAULT_LOCAL_TASK, 'description' => 'Provides general configuration options for the Disqus comment system.', 'weight' => -10, ); return $items; } /** * Implementation of hook_nodeapi(). */ function disqus_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { switch ($op) { case 'load': // See if Disqus is active on this node. $types = variable_get('disqus_nodetypes', array()); if (!empty($types[$node->type])) { // Check which Disqus domain to use. $domain = variable_get('disqus_domain', ''); if (!empty($domain)) { // Save the data to the node object. $node->disqus = array('domain' => $domain); // Build the absolute URL without the alias for the disqus_url flag. $node->disqus['url'] = url("node/$node->nid", array( 'alias' => TRUE, 'absolute' => TRUE, )); // Build the message excerpt. $message = nl2br($node->teaser); $message = str_replace("\r", ' ', $message); $message = str_replace("\n", ' ', $message); $message = strip_tags($message); $node->disqus['message'] = check_plain($message); // Build the title. $node->disqus['title'] = check_plain($node->title); // Provide the identifier. $node->disqus['identifier'] = 'node/' . $node->nid; // The developer flag must always be set when the node is unpublished. if ($node->status == 0) { $node->disqus['developer'] = 1; } elseif ($developer = variable_get('disqus_developer', FALSE)) { $node->disqus['developer'] = intval($developer); } } } break; case 'view': // See if we are to display Disqus in the current context. if (!$a3 && $a4 && isset($node->disqus)) { if (user_access('view disqus comments') && variable_get('disqus_location', 'content_area') == 'content_area') { // Inject the comments into the node content area. $node->content['disqus'] = array( '#value' => theme('disqus_comments', $node->disqus), '#weight' => variable_get('disqus_weight', 50), ); } } break; } } /** * Implementation of hook_user(). */ function disqus_user($op, &$edit, &$account, $category = NULL) { switch ($op) { case 'load': // Only show on the profile if desired. Don't show on the administrator's profile. if (user_access('display disqus comments on profile', $account) && $account->uid != 1) { // Check which Disqus domain to use. $domain = variable_get('disqus_domain', ''); if (!empty($domain)) { // Save the data to the user object. $account->disqus = array('domain' => $domain); } // Build the absolute URL without the alias for the disqus_url flag. $account->disqus['url'] = url("user/$account->uid", array( 'alias' => TRUE, 'absolute' => TRUE, )); // Build the message excerpt. $account->disqus['message'] = check_plain($account->name); // Build the title. $account->disqus['title'] = check_plain($account->name); // Provide the identifier. $account->disqus['identifier'] = 'user/' . $account->uid; // Inject the script. if ($developer = variable_get('disqus_developer', FALSE)) { $account->disqus['developer'] = $developer; } } break; case 'view': if (user_access('view disqus comments') && variable_get('disqus_location', 'content_area') == 'content_area') { if (isset($account->disqus)) { $account->content['disqus'] = array( '#value' => theme('disqus_comments', $account->disqus), '#weight' => variable_get('disqus_weight', 50), ); } } break; } } /** * Implementation of hook_link(). */ function disqus_link($type, $node = NULL, $teaser = FALSE) { $links = array(); // Only show the Disqus links on node teasers. if ($type == 'node' && $teaser == TRUE) { // Make sure the context is correct. $types = variable_get('disqus_nodetypes', array()); $domain = variable_get('disqus_domain', ''); if (!empty($types[$node->type]) && user_access('view disqus comments') && !empty($domain)) { // Construct the path and inject it into the links area. $path = url("node/$node->nid", array( 'alias' => TRUE, 'absolute' => TRUE, )); $links['disqus_comments'] = array( 'title' => theme('disqus_comments_num', $domain, $path, t('Comments')), 'html' => TRUE, ); } } return $links; } /** * Implementation of hook_block(). */ function disqus_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': return array( 'disqus_recent_comments' => array('info' => t('Disqus: Recent Comments'), 'cache' => BLOCK_CACHE_GLOBAL), 'disqus_popular_threads' => array('info' => t('Disqus: Popular Threads'), 'cache' => BLOCK_CACHE_GLOBAL), 'disqus_top_commenters' => array('info' => t('Disqus: Top Commenters'), 'cache' => BLOCK_CACHE_GLOBAL), 'disqus_combination_widget' => array('info' => t('Disqus: Combination Widget'), 'cache' => BLOCK_CACHE_GLOBAL), 'disqus_comments' => array('info' => t('Disqus: Comments'), 'cache' => BLOCK_NO_CACHE), ); case 'configure': $form = array(); $form[$delta .'_items'] = array( '#type' => 'select', '#title' => t('Number of items to show'), '#options' => array(1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), '#default_value' => variable_get($delta .'_items', 5), '#access' => ($delta != 'disqus_comments'), ); $form[$delta .'_showavatars'] = array( '#type' => 'select', '#title' => t('Show avatars'), '#options' => array(FALSE => t('No'), TRUE => t('Yes')), '#default_value' => variable_get($delta .'_showavatars', TRUE), '#access' => ($delta == 'disqus_recent_comments') || ($delta == 'disqus_top_commenters'), ); $form[$delta .'_avatarsize'] = array( '#type' => 'select', '#title' => t('Avatar size'), '#options' => array( 24 => t('X-Small (24px)'), 32 => t('Small (32px)'), 48 => t('Medium (48px)'), 92 => t('Large (92px)'), 128 => t('X-Large (128px)'), ), '#default_value' => variable_get($delta .'_avatarsize', 32), '#access' => $form[$delta .'_showavatars']['#access'], ); # excerpt length starts $form[$delta .'_excerpt'] = array( '#type' => 'textfield', '#title' => t('Excerpt length'), '#default_value' => variable_get($delta .'_excerpt', '200'), '#size' => 5, '#access' => ($delta == 'disqus_recent_comments'), ); # excerpt length ends $form[$delta .'_colortheme'] = array( '#type' => 'select', '#title' => t('Color Theme'), '#options' => array( 'blue' => t('Blue'), 'grey' => t('Grey'), 'green' => t('Green'), 'red' => t('Red'), 'orange' => t('Orange'), ), '#default_value' => variable_get($delta .'_colortheme', 'blue'), '#access' => $delta == 'disqus_combination_widget', ); $form[$delta .'_defaulttabview'] = array( '#type' => 'select', '#title' => t('Default Tab View'), '#options' => array( 'people' => t('People'), 'recent' => t('Recent'), 'popular' => t('Popular'), ), '#default_value' => variable_get($delta .'_defaulttabview', 'people'), '#access' => $delta == 'disqus_combination_widget', ); return $form; case 'save': if ($delta != 'disqus_comments') { variable_set($delta .'_items', $edit[$delta .'_items']); variable_set($delta .'_showavatars', $edit[$delta .'_showavatars']); variable_set($delta .'_avatarsize', $edit[$delta .'_avatarsize']); # excerpt length starts variable_set($delta .'_excerpt', $edit[$delta .'_excerpt']); # excerpt length ends variable_set($delta .'_colortheme', $edit[$delta .'_colortheme']); variable_set($delta .'_defaulttabview', $edit[$delta .'_defaulttabview']); } break; case 'view': $num_items = variable_get($delta .'_items', 5); $avatars = variable_get($delta .'_showavatars', TRUE) ? '&avatar_size='. variable_get($delta .'_avatarsize', 32) : '&hide_avatars=1'; # excerpt length starts $excerpt = variable_get($delta .'_excerpt', '200'); # excerpt length ends $color = variable_get($delta .'_colortheme', 'blue'); $default_tab = variable_get($delta .'_defaulttabview', 'people'); $domain = variable_get('disqus_domain', ''); if (!empty($domain)) { $subject = ''; $content = ''; switch ($delta) { case 'disqus_recent_comments': $content = <<