home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (ping.module)

This example Drupal source code file (ping.module) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

and, array, cron, cron_last, function, href, if, module, name, output, php, ping, url, where

The ping.module Drupal example source code

<?php
// $Id: ping.module,v 1.52.2.1 2009/11/06 07:46:22 goba Exp $

/**
 * @file
 * Alerts other sites that your site has been updated.
 */

/**
 * Implementation of hook_help().
 */
function ping_help($path, $arg) {
  switch ($path) {
    case 'admin/help#ping':
      $output = '<p>'. t('The ping module is useful for notifying interested sites that your site has changed. It automatically sends notifications, or "pings", to the <a href="@external-http-pingomatic-com">pingomatic</a> service about new or updated content. In turn, <a href="@external-http-pingomatic-com">pingomatic</a> notifies other popular services, including weblogs.com, Technorati, blo.gs, BlogRolling, Feedster.com, and Moreover.', array('@external-http-pingomatic-com' => 'http://pingomatic.com/')) .'</p>';
      $output .= '<p>'. t('The ping module requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))) .'</p>';
      $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@ping">Ping module</a>.', array('@ping' => 'http://drupal.org/handbook/modules/ping/')) .'</p>';
      return $output;
  }
}

/**
 * Implementation of hook_cron().
 *
 * Fire off notifications of updates to remote sites.
 */
function ping_cron() {
  global $base_url;

  if (variable_get('site_name', 0)) {
    $cron_last = variable_get('cron_last', time());
    // Query changed first since usually changed >= created.
    if (db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1 AND changed > %d', $cron_last)) || db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1 AND created > %d', $cron_last))) {
      _ping_notify(variable_get('site_name', ''), $base_url);
    }
  }
}

/**
 * Call hook_ping() in all modules to notify remote sites that there is
 * new content at this one.
 */
function _ping_notify($name, $url) {
  module_invoke_all('ping', $name, $url);
}

/**
 * Implementation of hook_ping().
 *
 * Notifies pingomatic.com, blo.gs, and technorati.com of changes at this site.
 */
function ping_ping($name = '', $url = '') {

  $result = xmlrpc('http://rpc.pingomatic.com', 'weblogUpdates.ping', $name, $url);

  if ($result === FALSE) {
    watchdog('directory ping', 'Failed to notify pingomatic.com (site).', array(), WATCHDOG_WARNING);
  }
}


Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal ping.module source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.