Index: pingback.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pingback/pingback.admin.inc,v
retrieving revision 1.3
diff -u -p -r1.3 pingback.admin.inc
--- pingback.admin.inc	15 Mar 2008 00:30:32 -0000	1.3
+++ pingback.admin.inc	28 Feb 2009 10:01:07 -0000
@@ -1,6 +1,17 @@
 <?php
 // $Id: pingback.admin.inc,v 1.0.0.1 2007/07/26 23:17:13 dww Exp $
 
+/**
+ * @file
+ * Admin page callbacks for the Pingback module.
+ */
+
+/**
+ * Form builder; Configure the Pingback system.
+ *
+ * @ingroup forms
+ * @see system_settings_form()
+ */
 function pingback_settings_form() {
   $form = array();
   $formats = array();
@@ -17,21 +28,31 @@ function pingback_settings_form() {
   $form['pingback_hide_format_for_anon'] = array(
     '#type' => 'radios',
     '#title' => t('Hide pingback input format for anonymous users'),
-    '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
+    '#options' => array(
+      0 => t('Disabled'),
+      1 => t('Enabled'),
+    ),
     '#default_value' => variable_get('pingback_hide_format_for_anon', 0),
     '#description' => t('Hide the input format chosen from the above option when anonymous users post comments. Enable this, or else people can post comments as pingbacks!'), //to devs: every node update will invalidate the variable cache, so it is not appropriate for sites that has many concurrent node insert / update, e.g. 50 node updates each second.
   );
   $form['pingback_receive'] = array(
     '#type' => 'radios',
     '#title' => t('Receive pingbacks'),
-    '#options' => array(1 => t('Yes'), 0 => t('No')),
+    '#options' => array(
+      1 => t('Yes'),
+      0 => t('No'),
+    ),
     '#default_value' => variable_get('pingback_receive', 1),
     '#description' => t('Receive pingbacks sent from other sites linking to you.'),
   );
   $form['pingback_mode'] = array(
     '#type' => 'radios',
     '#title' => t('Pingback autoping'),
-    '#options' => array('off' => t('Never'), 'submit' => t('When creating and updating nodes'), 'cron' => t('On cron run')),
+    '#options' => array(
+      'off' => t('Never'),
+      'submit' => t('When creating and updating nodes'),
+      'cron' => t('On cron run'),
+    ),
     '#default_value' => variable_get('pingback_mode', 'off'),
     '#description' => t('When to automatically ping linked sites.  Performance of cron mode is still poor if post creation and update traffic is very high.'), //to devs: every node update will invalidate the variable cache, so it is not appropriate for sites that has many concurrent node insert / update, e.g. 50 node updates each second.
   );
@@ -44,7 +65,10 @@ function pingback_settings_form() {
   $form['pingback_notify_successful_pings'] = array(
     '#type' => 'radios',
     '#title' => t('Notify for successful pingbacks'),
-    '#options' => array(1 => t('Yes'), 0 => t('No')),
+    '#options' => array(
+      1 => t('Yes'),
+      0 => t('No'),
+    ),
     '#default_value' => variable_get('pingback_notify_successful_pings', 1),
     '#description' => t('Notify users about successful pingbacks. This option is efective only if pingbacks are sent when creating and updating nodes.'),
   );
@@ -53,7 +77,10 @@ function pingback_settings_form() {
   $form['pingback_moderation'] = array(
     '#type' => 'radios',
     '#title' => t('Pingback moderation'),
-    '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
+    '#options' => array(
+      0 => t('Disabled'),
+      1 => t('Enabled'),
+    ),
     '#default_value' => variable_get('pingback_moderation', 0),
     '#description' => t('If pingback moderation is enabled, incoming pingbacks will not be published automatically.  A user with "administer comments" permission can publish those pingbacks.'), //to devs: every node update will invalidate the variable cache, so it is not appropriate for sites that has many concurrent node insert / update, e.g. 50 node updates each second.
   );
@@ -61,12 +88,14 @@ function pingback_settings_form() {
   return system_settings_form($form);
 }
 
+/**
+ * Validate pingback_settings form submissions.
+ */
 function pingback_settings_form_validate($form, &$form_state) {
   $formats = filter_formats();
   $f = $formats[$form_state['values']['pingback_input_format']];
-  //dpm($f);
   //note: this role-matching is dependent of current implementation of filter.module
   if (strpos($f->roles, ','. DRUPAL_ANONYMOUS_RID .',') === FALSE) {
     form_set_error('pingback_input_format', t('The input format has to be usable by anonymous users.'));
   }
-}
\ No newline at end of file
+}
Index: pingback.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pingback/pingback.install,v
retrieving revision 1.4
diff -u -p -r1.4 pingback.install
--- pingback.install	14 Aug 2008 09:57:33 -0000	1.4
+++ pingback.install	28 Feb 2009 10:01:07 -0000
@@ -2,6 +2,11 @@
 // $Id: pingback.install,v 1.0.0.1 2007/07/26 23:17:13 dww Exp $
 
 /**
+ * @file
+ * Install, update, and uninstall functions for Pingback.
+ */
+
+/**
  * Implementation of hook_schema().
  */
 function pingback_schema() {
@@ -13,21 +18,21 @@ function pingback_schema() {
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
-        'default' => 0
+        'default' => 0,
       ),
       'url' => array(
         'description' => t('URL pingback was sent to.'),
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,
-        'default' => ''
+        'default' => '',
       ),
       'timestamp' => array(
         'description' => t('Time when pingback was sent.'),
         'type' => 'int',
         'unsigned' => FALSE,
         'not null' => TRUE,
-        'default' => 0
+        'default' => 0,
       ),
     ),
     'primary key' => array('nid', 'url'),
@@ -39,7 +44,6 @@ function pingback_schema() {
  * Implementation of hook_install().
  */
 function pingback_install() {
-  // Create my tables.
   drupal_install_schema('pingback');
 }
 
@@ -47,7 +51,6 @@ function pingback_install() {
  * Implementation of hook_uninstall().
  */
 function pingback_uninstall() {
-  // Drop my tables.
   drupal_uninstall_schema('pingback');
 
   // Clear any variables that might be in use
Index: pingback.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pingback/pingback.module,v
retrieving revision 1.5
diff -u -p -r1.5 pingback.module
--- pingback.module	14 Aug 2008 10:12:31 -0000	1.5
+++ pingback.module	28 Feb 2009 10:01:07 -0000
@@ -2,6 +2,11 @@
 // $Id: pingback.module,v 1.0.0.1 2007/07/26 23:17:13 dww Exp $
 
 /**
+ * @file
+ * Main file for the Pingback module, which enables pingbacks for content.
+ */
+
+/**
  * Implementation of hook_perm().
  */
 function pingback_perm() {
@@ -35,7 +40,7 @@ function pingback_form_alter(&$form, &$f
       '#title' => t('Pingbacks'),
       '#options' => array(1 => t('Enabled'), 0 => t('Disabled')),
       '#default_value' => _pingback_valid_for_node_type($type),
-      '#description' => t('Enable pingbacks for this node type.')
+      '#description' => t('Enable pingbacks for this node type.'),
     );
   }
   else if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
@@ -43,7 +48,7 @@ function pingback_form_alter(&$form, &$f
     if (_pingback_valid_for_node_type($node->type)) {
       // if there are any past successful pingbacks from this posting, add them to the node editing page.
       $past_successes_listing = array();
-      $q = db_query("SELECT url FROM {pingback_sent} WHERE nid = %d", $node->nid);
+      $q = db_query('SELECT url FROM {pingback_sent} WHERE nid = %d', $node->nid);
       while ($pb = db_fetch_object($q)) {
         $past_successes_listing[] = $pb->url;
       }
@@ -58,21 +63,18 @@ function pingback_form_alter(&$form, &$f
           '#type' => 'markup',
           '#value' => theme('item_list', $past_successes_listing, t('Successfully pingbacked URLs')),
         );
-        //t('These URLs have been successfuly pinged by this post.')
       }
     }
   }
   //hide pingback input format if desired for anon users
-  else if (
+  elseif (
     $form_id == 'comment_form'
     && (!$user->uid)
     && variable_get('pingback_hide_format_for_anon', 0)
     //&& (isset($GLOBALS['pingback_bypass_format_hiding']) ? !$GLOBALS['pingback_bypass_format_hiding'] : TRUE)
   ) {
-    //dpm($form);
     $alternate_formats = array();
     foreach ($form['comment_filter']['format'] as $k => $v) {
-      //dpm($k);
       if (!element_property($k) && isset($v['#return_value'])) {
         if ($v['#return_value'] == variable_get('pingback_input_format', FILTER_FORMAT_DEFAULT)) {
           unset($form['comment_filter']['format'][$k]);
@@ -107,22 +109,24 @@ function pingback_theme() {
     'pingback' => array(
       'file' => 'pingback.module',
       'function' => 'theme_pingback',
-    )
+    ),
   );
 }
 
 /**
- * Menu callback: lists pingbacks.  TODO: ability to delete them!
+ * Menu callback: lists pingbacks. (TODO)
+ *
+ * TODO: ability to delete them!
+ * TODO: Is pingback_list_pingbacks() a better name?
  */
- //pingback_list_pingbacks() a better name?
 function pingback_list_page() {
-  //$result = db_query("SELECT ");
-  return 'TODO';
+  return '';
 }
 
-
+/**
+ * Implementation of hook_nodeapi().
+ */
 function pingback_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
-  
   if (_pingback_valid_for_node_type($node->type)) {
     switch ($op) {
       case 'insert':
@@ -157,10 +161,8 @@ function pingback_cron() {
   $q = variable_get('pingback_nid_queue', array());
   $limit = variable_get('pingback_check_per_cron', 30);
   $count = 0;
-  //dpr($q);
   while (($nid = array_shift($q)) && ($count++ < $limit)) {
     pingback_send_by_nid($nid, FALSE);
-    //dpr("Sent pingbacks in node $nid");
   }
   variable_set('pingback_nid_queue', $q);
 }
@@ -186,7 +188,6 @@ function pingback_xmlrpc() {
   );
 }
 
-
 /**
  * XML-RPC callback: process pingback.ping() call.
  */
@@ -194,9 +195,9 @@ function pingback_receive($pagelinkedfro
   //return xmlrpc_server_error(0, 'abcdefgh');
   //big thanks to WordPress codebase, specifically file xmlrpc.php, method pingback_ping() for becoming the reference implementation and theft victim ;)
   //note: $pagelinkedto is a URL from our own site, $pagelinkedfrom is a foreign URL
-  
+
   if (!variable_get('pingback_receive', 1)) return xmlrpc_server_error(33, t("The specified target URL cannot be used as a target. It either doesn't exist, or it is not a pingback-enabled resource."));
-  
+
   //don't really understand this part, supposed to unescape ampersand entities?
   $pagelinkedfrom = str_replace('&amp;', '&', $pagelinkedfrom);
   $pagelinkedto   = preg_replace('#&([^amp\;])#is', '&amp;$1', $pagelinkedto);
@@ -207,30 +208,30 @@ function pingback_receive($pagelinkedfro
   if (!$pos1) {
     return new xmlrpc_server_error(0, t('Is there no link to us?'));
   }
-  
+
   // let's find which post is linked to
   $nid = _pingback_url_to_nid($pagelinkedto);
 
-
-  //dpm("(PB) URL='$pagelinkedto' ID='$post_ID' Found='$way'");
-
   $node = $nid ? node_load($nid) : FALSE;
-  //watchdog('debug', '--- ' . $nid . ' --- ' . print_r($node, TRUE));
-  
-  if (!$node || !_pingback_valid_for_node($node)) // node not found
+
+  if (!$node || !_pingback_valid_for_node($node)) { // node not found
     return xmlrpc_server_error(33, t("The specified target URL cannot be used as a target. It either doesn't exist, or it is not a pingback-enabled resource."));
+  }
 
-  if ($nid == _pingback_url_to_nid($pagelinkedfrom))
+  if ($nid == _pingback_url_to_nid($pagelinkedfrom)) {
     return xmlrpc_server_error(0, t('The source URL and the target URL cannot both point to the same resource.'));
-  
-  if (!$node->status)
+  }
+
+  if (!$node->status) {
     return xmlrpc_server_error(33, t("The specified target URL cannot be used as a target. It either doesn't exist, or it is not a pingback-enabled resource."));
+  }
 
   // Let's check that the remote site didn't already pingback this entry
   $result = db_result(db_query("SELECT COUNT(*) FROM {comments} WHERE  nid = %d AND homepage = '%s' AND format = %d", $nid, $pagelinkedfrom, variable_get('pingback_input_format', FILTER_FORMAT_DEFAULT)));
 
-  if ($result > 0) // We already have a Pingback from this URL
-      return xmlrpc_server_error(48, 'The pingback has already been registered.');
+  if ($result > 0) { // We already have a Pingback from this URL
+    return xmlrpc_server_error(48, 'The pingback has already been registered.');
+  }
 
   // very stupid, but gives time to the 'from' server to publish !
   sleep(1);
@@ -239,31 +240,33 @@ function pingback_receive($pagelinkedfro
   $r = drupal_http_request($pagelinkedfrom);
   if ($r->error)
     return xmlrpc_server_error(16, 'The source URL does not exist.');
-  //watchdog('debug', print_r($r, TRUE));
   $linea = $r->data;
 
   // Work around bug in strip_tags():
   $linea = str_replace('<!DOC', '<DOC', $linea);
-  $linea = preg_replace( '/[\s\r\n\t]+/', ' ', $linea ); // normalize spaces
-  $linea = preg_replace( "/ <(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body|br)[^>]*>/", "\n\n", $linea );
+  $linea = preg_replace('/[\s\r\n\t]+/', ' ', $linea); // normalize spaces
+  $linea = preg_replace('/ <(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body|br)[^>]*>/', "\n\n", $linea);
 
   preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle);
   $title = check_plain($matchtitle[1]);
-  if ( empty( $title ) )
-      return xmlrpc_server_error(32, 'We cannot find a title on that page.');
+  if (empty($title)) {
+    return xmlrpc_server_error(32, 'We cannot find a title on that page.');
+  }
 
-  $linea = strip_tags( $linea, '<a>' ); // just keep the tag we need
+  $linea = strip_tags($linea, '<a>'); // just keep the tag we need
 
-  $p = explode( "\n\n", $linea );
+  $p = explode("\n\n", $linea);
 
   $preg_target = preg_quote($pagelinkedto);
 
-  foreach ( $p as $para ) {
-    if ( strpos($para, $pagelinkedto) !== false ) { // it exists, but is it a link?
-      preg_match("|<a[^>]+?". $preg_target ."[^>]*>([^>]+?)</a>|", $para, $context);
+  foreach ($p as $para) {
+    if (strpos($para, $pagelinkedto) !== FALSE) { // it exists, but is it a link?
+      preg_match('|<a[^>]+?'. $preg_target .'[^>]*>([^>]+?)</a>|', $para, $context);
 
       // If the URL isn't in a link context, keep looking
-      if (empty($context)) continue;
+      if (empty($context)) {
+        continue;
+      }
 
       // We're going to use this fake tag to mark the context in a bit
       // the marker is needed in case the link text appears more than once in the paragraph
@@ -271,10 +274,10 @@ function pingback_receive($pagelinkedfro
       $excerpt = preg_replace('|\</?dpcontext\>|', '', $para);
 
       // prevent really long link text
-      if ( strlen($context[1]) > 100 )
-        $context[1] = substr($context[1], 0, 100) .'...';
-      
-      
+      if (drupal_strlen($context[1]) > 100) {
+        $context[1] = drupal_substr($context[1], 0, 100) .'...';
+      }
+
       $marker = '<dpcontext>'. $context[1] .'</dpcontext>';    // set up our marker
       $excerpt = str_replace($context[0], $marker, $excerpt); // swap out the link for our marker
       $excerpt = strip_tags($excerpt, '<dpcontext>');        // strip all tags but our context marker
@@ -282,18 +285,18 @@ function pingback_receive($pagelinkedfro
       $preg_marker = preg_quote($marker);
       $excerpt = preg_replace("|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt);
       $excerpt = strip_tags($excerpt); // YES, again, to remove the marker wrapper
-      
+
       break;
     }
   }
 
-  if (empty($context)) // Link to target not found
-      return xmlrpc_server_error(17, t('The source URL does not contain a link to the target URL, and so cannot be used as a source.'));
-  
+  if (empty($context)) { // Link to target not found
+    return xmlrpc_server_error(17, t('The source URL does not contain a link to the target URL, and so cannot be used as a source.'));
+  }
+
   //??? can someone explain about this?
   $pagelinkedfrom = preg_replace('#&([^amp\;])#is', '&amp;$1', $pagelinkedfrom);
 
-  //$context = '[...] ' . wp_specialchars( $excerpt ) . ' [...]';
   //TODO: a custom filter for $excerpt
   $edit = array(
     'nid' => $nid,
@@ -313,8 +316,6 @@ function pingback_receive($pagelinkedfro
   watchdog('debug', print_r(form_get_errors(), TRUE));
   */
   $message = t('Pingback from @source to @target registered! Keep the web talking! :-)', array('@source' => $pagelinkedfrom, '@target' => $pagelinkedto));
-  //comment.module already logs new comments
-  //watchdog('pingback', $message);
   return $message;
 }
 
@@ -334,7 +335,6 @@ function pingback_discover($target) {
   $server = '';
   //#1: send a HEAD to check for X-Pingback header
   $r = drupal_http_request($target, array(), 'HEAD');
-  //dpm($r);
   if (empty($r->error)) {
     if (is_array($r->headers) && isset($r->headers['X-Pingback'])) {
       $server = $r->headers['X-Pingback'];
@@ -343,19 +343,17 @@ function pingback_discover($target) {
       //#2: search for <link rel="pingback" href="(server)" /> tags
       $get = drupal_http_request($target);
       if (empty($get->error)) {
-        //dpm($get->data);
         //this regexp is the one provided in the spec
         if (preg_match('#<link rel="pingback" href="([^"]+)" ?/?>#', $get->data, $matches)) {
           $server = $matches[1];
         }
-        
       }
     }
   }
   if (!empty($server)) {
     return check_url($server);
   }
-  else return '';
+  return '';
 }
 
 /**
@@ -375,7 +373,6 @@ function pingback_send($nid, $target, $s
     $result = db_result(db_query("SELECT COUNT(*) FROM {pingback_sent} WHERE nid = %d AND url = '%s'", $nid, $target));
     if ($result > 0) {
       watchdog('pingback', 'Pingback already sent for: @nid', array('@nid' => $nid), WATCHDOG_WARNING);
-      //dpm('oops already sent');
       return FALSE;
     }
   }
@@ -386,13 +383,11 @@ function pingback_send($nid, $target, $s
       return FALSE;
     }
   }
-  //dpm($source);
   $retval = FALSE;
 
   //server autodiscovery
   $server = pingback_discover($target);
-  //dpm($server);
-  
+
   if (!empty($server)) {
     if (xmlrpc($server, 'pingback.ping', $source, $target)) {
       if (!$source_is_absolute) {
@@ -415,33 +410,21 @@ function pingback_send($nid, $target, $s
  */
 function pingback_send_by_nid($nid, $message = TRUE) {
   global $base_root;
-  
+
   $node = node_load($nid);
   $prepared = node_prepare($node);
   $urls = _pingback_extract_urls($prepared->body);
-  if (isset($node->pingback_sent)) {
-    //$urls = array_diff(_pingback_extract_urls($prepared->body), $node->pingback_sent);
-  }
   $successful = array();
   foreach ($urls as $url) {
-    //dpm("Sending to " . check_plain($url));
-    if (pingback_send($node->nid, $url)) {
-      //dpm('success!');
-      // watchdog('pingback', 'Pingback successful for: @url', array('@url' => $url));
-      if ($message) $successful[] = "<a href=\"$url\">$url</a>";
-    }
-    else {
-      // watchdog('pingback', 'Pingback failed for: @url', array('@url' => $url), WATCHDOG_WARNING);
+    if (pingback_send($node->nid, $url) && $message) {
+      $successful[] = "<a href=\"$url\">$url</a>";
     }
   }
-  
   if ($message && count($successful)) {
     drupal_set_message(t('!urls pingbacked successfully.', array('!urls' => implode(', ', $successful))));
   }
-  //drupal_set_message("URLs: " . implode(', ', $urls));
 }
 
-
 function pingback_comment_is_pingback($comment) {
   return $comment->format == variable_get('pingback_input_format', FILTER_FORMAT_DEFAULT);
 }
@@ -462,22 +445,22 @@ function _pingback_extract_urls($text) {
   return array_unique($urls[0]);
 }
 
-//maps any absolute url from this drupal site to nid if applicable.
-//can also be used to check whether an absolute path is in the site and points to a node (e.g. node/1)
+/**
+ * Map any absolute url from this Drupal site to nid if applicable.
+ *
+ * Can also be used to check whether an absolute path is in the site and points
+ * to a node (e.g. node/1).
+ */
 function _pingback_url_to_nid($url) {
   //first check if the url is really in our site, as well as getting the non-base-url part
   if (preg_match($a = '#^'. preg_quote($GLOBALS['base_url'], '#') .'/(.+)$#', $url, $matches)) {
-    //dpm($matches[1]);
-    //dpm(drupal_get_normal_path($matches[1]));
     if (!variable_get('clean_url', 0)) {
       // Clean URLs not enabled. Strip '?q=' from URL.
       $matches[1] = str_replace('?q=', '', $matches[1]);
     }
     if (preg_match($b = '#^node/([0-9]+)$#', drupal_get_normal_path($matches[1]), $matches2)) {
       return $matches2[1];
-    } //else dpm($b);
+    }
   }
-  
-  //dpm($a);
   return FALSE;
-}
\ No newline at end of file
+}
