Skip to content
Snippets Groups Projects
Commit ca0151ba authored by The Great Git Migration's avatar The Great Git Migration
Browse files

This commit was manufactured as part of Drupal's Great Git Migration to

create tag 'DRUPAL-4-7-0-BETA-3'.

Sprout from master 2006-01-09 19:18:46 UTC Dries Buytaert <dries@buytaert.net> '- Patch #36716 by m3vrick: made deleting user accounts work.'
Delete:
    modules/aggregator/aggregator.module
    modules/archive/archive.module
    modules/block/block.module
    modules/blog/blog.module
    modules/blogapi/blogapi.module
    modules/book/book.module
    modules/comment/comment.module
    modules/contact/contact.module
    modules/drupal/drupal.module
    modules/filter/filter.module
    modules/forum/forum.module
    modules/help/help.module
    modules/legacy/legacy.module
    modules/locale/locale.module
    modules/menu/menu.module
    modules/node/node.module
    modules/page/page.module
    modules/path/path.module
    modules/ping/ping.module
    modules/poll/poll.module
    modules/profile/profile.module
    modules/search/search.module
    modules/statistics/statistics.module
    modules/story/story.module
    modules/system/system.module
    modules/taxonomy/taxonomy.module
    modules/throttle/throttle.module
    modules/tracker/tracker.module
    modules/upload/upload.module
    modules/user/user.module
    modules/watchdog/watchdog.module
parent afb923a0
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 13922 deletions
This diff is collapsed.
<?php
// $Id$
/**
* @file
* Displays a calendar to navigate old content.
*/
/**
* Implementation of hook_help().
*/
function archive_help($section) {
switch ($section) {
case 'admin/help#archive':
$output = '<p>'. t('The archive page allows content to be viewed by date. It also provides a monthly calendar view that users can use to navigate through content.') .'</p>';
$output .= '<p>'. t('To view the archive by date, select the date in the calendar. Administrators can enable the <em>browse archives</em> block in block administration to allow users to browse by calendar. Clicking on a date in the monthly calendar view shows the content for that date. Users can navigate to different months using arrows beside the month\'s name in the calendar display. The current date will be highlighted in the calendar.') .'</p>';
$output .= t('<p>You can</p>
<ul>
<li>view your <a href="%archive">archive by day</a>.</li>
<li>enable the <em>browse archives</em> block at <a href="%admin-block">administer &gt;&gt; block</a>.</li>
</ul>
', array('%archive' => url('archive'), '%admin-block' => url('admin/block')));
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%archive">Archive page</a>.', array('%archive' => 'http://www.drupal.org/handbook/modules/archive/')) .'</p>';
return $output;
case 'admin/modules#description':
return t('Displays a calendar for navigating older content.');
}
}
/**
* Generates a monthly calendar, for display in the archive block.
*/
function archive_calendar($original = 0) {
global $user;
$edit = $_POST['edit'];
// Extract today's date:
$start_of_today = mktime(0, 0, 0, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone;
$end_of_today = mktime(23, 59, 59, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone;
// Extract the requested date:
if ($edit['year'] && $edit['month'] && $edit['day']) {
$year = $edit['year'];
$month = $edit['month'];
$day = $edit['day'];
$requested = mktime(0, 0, 0, $month, $day, $year) + $user->timezone;
}
else if (arg(0) == 'archive' && arg(3)) {
$year = arg(1);
$month = arg(2);
$day = arg(3);
$requested = mktime(0, 0, 0, $month, $day, $year) + $user->timezone;
}
else {
$year = date('Y', time());
$month = date('n', time());
$day = date('d', time());
$requested = $end_of_today + $user->timezone;
}
$start_of_month = mktime(0, 0, 0, $month, 1, $year);
// Extract first day of the month:
$first = date('w', $start_of_month);
// Extract last day of the month:
$last = date('t', $start_of_month);
$end_of_month = mktime(23, 59, 59, $month, $last, $year);
$cache = cache_get("archive:calendar:$day-$month-$year");
if (!empty($cache)) {
return $cache->data;
}
// Calculate previous and next months dates and check for shorter months (28/30 days)
$prevmonth = mktime(23, 59, 59, $month - 1, 1, $year);
$prev = mktime(23, 59, 59, $month - 1, min(date('t', $prevmonth), $day), $year);
$nextmonth = mktime(23, 59, 59, $month + 1, 1, $year);
$next = mktime(23, 59, 59, $month + 1, min(date('t', $nextmonth), $day), $year);
$sql = 'SELECT n.nid, n.created FROM {node} n WHERE n.status = 1 AND n.created > %d AND n.created < %d ORDER BY n.created';
$sql = db_rewrite_sql($sql);
$result = db_query($sql, $start_of_month, $end_of_month);
$days_with_posts = array();
while ($day_with_post = db_fetch_object($result)) {
$daynum = date('j', $day_with_post->created + $user->timezone);
if (isset($days_with_posts[$daynum])) {
$days_with_posts[$daynum]++;
}
else {
$days_with_posts[$daynum] = 1;
}
}
// Generate calendar header:
$output .= "\n<!-- calendar -->\n";
$output .= '<div class="calendar">';
$output .= '<table summary="'. t('A calendar to browse the archives') .".\">\n";
$output .= ' <caption>'. l('«', 'archive/'. date('Y/m/d', $prev), array('title' => t('Previous month'))) .' '. format_date($requested, 'custom', 'F') . date(' Y', $requested) .' '. ($nextmonth <= time() ? l('»', 'archive/'. date('Y/m/d', $next), array('title' => t('Next month'))) : ' ') ."</caption>\n";
// First day of week (0 => Sunday, 1 => Monday, ...)
$weekstart = variable_get('date_first_day', 0);
// Last day of week
($weekstart - 1 == -1) ? $lastday = 6 : $lastday = $weekstart - 1;
// Generate the days of the week:
$firstcolumn = mktime(0, 0, 0, 3, 20 + $weekstart, 1994);
$output .= " <tr class=\"header-week\">\n";
$days = array(t('Sunday') => t('Su'), t('Monday') => t('Mo'), t('Tuesday') => t('Tu'), t('Wednesday') => t('We'), t('Thursday') => t('Th'), t('Friday') => t('Fr'), t('Saturday') => t('Sa'));
if ($weekstart) {
$days = array_merge(array_slice($days, $weekstart), array_slice($days, 0, $weekstart));
}
foreach ($days as $fullname => $name) {
$output .= ' <th abbr="'. $fullname .'">'. $name . "</th>\n";
}
$output .= "</tr>\n";
// Initialize temporary variables:
$nday = 1;
$sday = $first;
// Loop through all the days of the month:
while ($nday <= $last) {
// Set up blank days for first week of the month (allowing individual blank day styling):
if ($first != $weekstart) {
$blankdays = ($first - $weekstart + 7) % 7;
$output .= " <tr class=\"row-week\">" . str_repeat("<td class=\"day-blank\">&nbsp;</td>\n", $blankdays);
$first = $weekstart;
}
// Start every week on a new line:
if ($sday == $weekstart) {
$output .= " <tr class=\"row-week\">\n";
}
// Print one cell:
$date = mktime(0, 0, 0, $month, $nday, $year) + $user->timezone;
if (isset($days_with_posts[$nday])) {
$daytext = l($nday, "archive/$year/$month/$nday", array("title" => format_plural($days_with_posts[$nday], "1 post", "%count posts")));
$dayclass = 'day-link';
}
else {
$daytext = $nday;
$dayclass = 'day-normal';
}
if ($date == $requested) {
$output .= " <td class=\"day-selected\">$daytext</td>\n";
}
else if ($date == $start_of_today) {
$output .= " <td class=\"day-today\">$daytext</td>\n";
}
else if ($date > $end_of_today) {
$output .= " <td class=\"day-future\">$daytext</td>\n";
}
else {
$output .= " <td class=\"$dayclass\">$daytext</td>\n";
}
// Start every week on a new line:
if ($sday == $lastday) {
$output .= " </tr>\n";
}
// Update temporary variables:
$sday++;
$sday = $sday % 7;
$nday++;
}
// Complete the calendar (allowing individual blank day styling):
if ($sday != $weekstart) {
$end = (7 - $sday + $weekstart) % 7;
$output .= str_repeat("<td class=\"day-blank\">&nbsp;</td>\n", $end) . "</tr>\n";
}
$output .= "</table></div>\n\n";
cache_set("archive:calendar:$day-$month-$year", $output, CACHE_TEMPORARY);
return $output;
}
/**
* Implementation of hook_block().
*
* Generates a calendar for the current month, with links to the archives
* for each day.
*/
function archive_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Calendar to browse archives');
return $blocks;
}
else if ($op == 'view' && user_access('access content')) {
$block['subject'] = t('Browse archives');
$block['content'] = archive_calendar();
return $block;
}
}
/**
* Implementation of hook_menu().
*/
function archive_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'archive', 'title' => t('archives'),
'access' => user_access('access content'),
'callback' => 'archive_page',
'type' => MENU_SUGGESTED_ITEM);
}
return $items;
}
/**
* Menu callback; lists all nodes posted on a given date.
*/
function archive_page($year = 0, $month = 0, $day = 0) {
global $user;
$op = $_POST['op'];
$edit = $_POST['edit'];
if ($op == t('Show')) {
$year = $edit['year'];
$month = $edit['month'];
$day = $edit['day'];
}
$date = mktime(0, 0, 0, $month, $day, $year) - $user->timezone;
$date_end = mktime(0, 0, 0, $month, $day + 1, $year) - $user->timezone;
// Prepare the values of the form fields.
$years = drupal_map_assoc(range(2000, 2010));
$months = array(1 => t('January'), 2 => t('February'), 3 => t('March'), 4 => t('April'), 5 => t('May'), 6 => t('June'), 7 => t('July'), 8 => t('August'), 9 => t('September'), 10 => t('October'), 11 => t('November'), 12 => t('December'));
$days = drupal_map_assoc(range(0, 31));
$form['year'] = array('#type' => 'select', '#default_value' => ($year ? $year : date('Y')), '#options' => $years);
$form['month'] = array('#type' => 'select', '#default_value' => ($month ? $month : date('m')), '#options' => $months);
$form['day'] = array('#type' => 'select', '#default_value' => ($day ? $day : date('d')), '#options' => $days);
$form['show'] = array('#type' => 'submit', '#value' => t('Show'));
$output = drupal_get_form('archive_dates', $form);
if ($year && $month && $day) {
// Fetch nodes for the selected date, if one was specified.
$sql = 'SELECT n.nid, n.created FROM {node} n WHERE n.status = 1 AND n.created > %d AND n.created < %d ORDER BY n.created';
$sql = db_rewrite_sql($sql);
$result = db_query_range($sql, $date, $date_end, 0, 20);
while ($nid = db_fetch_object($result)) {
$output .= node_view(node_load($nid->nid), 1);
}
}
return $output;
}
/**
* Form theme function; displays the archive date navigation form inline.
*/
function theme_archive_dates($form) {
$output = '<div class="container-inline">' . form_render($form) . '</div>';
return $output;
}
This diff is collapsed.
<?php
// $Id$
/**
* @file
* Enables keeping an easily and regularly updated web page or a blog.
*/
/**
* Implementation of hook_node_info().
*/
function blog_node_info() {
return array('blog' => array('name' => t('blog entry'), 'base' => 'blog'));
}
/**
* Implementation of hook_perm().
*/
function blog_perm() {
return array('edit own blog');
}
/**
* Implementation of hook_access().
*/
function blog_access($op, $node) {
global $user;
if ($op == 'create') {
return user_access('edit own blog') && $user->uid;
}
if ($op == 'update' || $op == 'delete') {
if (user_access('edit own blog') && ($user->uid == $node->uid)) {
return TRUE;
}
}
}
/**
* Implementation of hook_user().
*/
function blog_user($type, &$edit, &$user) {
if ($type == 'view' && user_access('edit own blog', $user)) {
$form['blog'] = array(
'#type' => 'item', '#title' => t('Blog'),
'#value' => l(t('view recent blog entries'), "blog/$user->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $user->name))))
);
return array(t('History') => $form);
}
}
/**
* Implementation of hook_help().
*/
function blog_help($section) {
switch ($section) {
case 'admin/help#blog':
$output = '<p>'. t('The blog module allows registered users to maintain an online weblog (commonly known as a blog), often referred to as an online journal or diary. Blogs are made up of individual posts that are time stamped and are typically viewed by date as you would a diary. Blogs often contain links to webpages users have read and/or agree/disagree with.') .'</p>';
$output .= '<p>'. t('The blog module adds a <em>user blogs</em> navigation link to the site, which takes any visitor to a page that displays the most recent blog entries from all the users on the site. The navigation menu has a <em>create a blog entry</em> link (which takes you to a submission form) and a <em>view personal blog</em> link (which displays your blog entries as other people will see them). The blog module also creates a <em>recent blog posts</em> block that can be enabled.') .'</p>';
$output .= '<p>'. t('If a user has the ability to post blogs, then the import module (news aggregator) will display a blog-it link next to each news item in its lists. Clicking on this takes the user to the blog submission form, with the title, a link to the item, and a link to the source into the body text already in the text box, ready for the user to add a comment or explanation. This actively encourages people to add blog entries about things they see and hear elsewhere in the website and from your syndicated partner sites.') .'</p>';
$output .= t('<p>You can</p>
<ul>
<li>read your blog via your user profile at <a href="%user">my account</a>.</li>
<li>post a blog at <a href="%node-add-blog">create content &gt;&gt; personal blog entry</a>.</li>
<li>administer blog at <a href="%admin-node-configure-types-blog">administer &gt;&gt; content &gt;&gt; configure &gt;&gt; content types &gt;&gt; personal blog entry</a>.</li>
<li>administer blog api at <a href="%admin-settings-blogapi">administer &gt;&gt; settings &gt;&gt; blogapi</a>.</li>
<li>enable the "recent blog posts" block at <a href="%admin-block">administer &gt;&gt; blocks</a> to show the 10 most recent blog posts.</li>
</ul>
', array('%user' => url('user'), '%node-add-blog' => url('node/add/blog'), '%admin-node-configure-types-blog' => url('admin/node/configure/types/blog'), '%admin-settings-blogapi' => url('admin/settings/blogapi'), '%admin-block' => url('admin/block')));
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%blog">Blog page</a>.', array('%blog' => 'http://www.drupal.org/handbook/modules/blog/')) .'</p>';
return $output;
case 'admin/modules#description':
return t('Enables keeping an easily and regularly updated web page or a blog.');
case 'node/add#blog':
return t("A blog is a regularly updated journal or diary made up of individual posts shown in reversed chronological order. A blog is tightly coupled to the author so each user will have his 'own' blog.");
}
}
/**
* Displays an RSS feed containing recent blog entries of a given user.
*/
function blog_feed_user($uid = 0) {
global $user;
if ($uid) {
$account = user_load(array('uid' => $uid, 'status' => 1));
}
else {
$account = $user;
}
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, variable_get('feed_default_items', 10));
$channel['title'] = $account->name ."'s blog";
$channel['link'] = url("blog/$uid", NULL, NULL, TRUE);
$channel['description'] = $term->description;
node_feed($result, $channel);
}
/**
* Displays an RSS feed containing recent blog entries of all users.
*/
function blog_feed_last() {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, variable_get('feed_default_items', 10));
$channel['title'] = variable_get('site_name', 'drupal') .' blogs';
$channel['link'] = url('blog', NULL, NULL, TRUE);
$channel['description'] = $term->description;
node_feed($result, $channel);
}
/**
* Menu callback; displays a Drupal page containing recent blog entries.
*/
function blog_page($a = NULL, $b = NULL) {
if (is_numeric($a)) { // $a is a user ID
if ($b == 'feed') {
return blog_feed_user($a);
}
else {
return blog_page_user($a);
}
}
else if ($a == 'feed') {
return blog_feed_last();
}
else {
return blog_page_last();
}
}
/**
* Displays a Drupal page containing recent blog entries of a given user.
*/
function blog_page_user($uid) {
global $user;
$account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
if ($account->uid) {
drupal_set_title($title = t("%name's blog", array('%name' => $account->name)));
if (($account->uid == $user->uid) && user_access('edit own blog')) {
$output = '<li>'. l(t('Post new blog entry.'), "node/add/blog") .'</li>';
}
else if ($account->uid == $user->uid) {
$output = '<li>'. t('You are not allowed to post a new blog entry.') .'</li>';
}
if ($output) {
$output = '<ul>'. $output .'</ul>';
}
else {
$output = '';
}
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid);
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
}
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
$output .= theme('feed_icon', url("blog/$account->uid/feed"));
drupal_add_link(array('rel' => 'alternate',
'type' => 'application/rss+xml',
'title' => t('RSS - %title', array('%title' => $title)),
'href' => url("blog/$account->uid/feed")));
return $output;
}
else {
drupal_not_found();
}
}
/**
* Displays a Drupal page containing recent blog entries of all users.
*/
function blog_page_last() {
global $user;
$output = '';
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10));
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
}
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
$output .= theme('feed_icon', url('blog/feed'));
drupal_add_link(array('rel' => 'alternate',
'type' => 'application/rss+xml',
'title' => t('RSS - blogs'),
'href' => url("blog/feed")));
return $output;
}
/**
* Implementation of hook_validate().
*/
function blog_validate($node) {
node_validate_title($node);
}
/**
* Implementation of hook_form().
*/
function blog_form(&$node) {
global $nid;
$iid = $_GET['iid'];
if (empty($node->body)) {
/*
** If the user clicked a "blog it" link, we load the data from the
** database and quote it in the blog:
*/
if ($nid && $blog = node_load($nid)) {
$node->body = '<em>'. $blog->body .'</em> ['. l($blog->name, "node/$nid") .']';
}
if ($iid && $item = db_fetch_object(db_query('SELECT i.*, f.title as ftitle, f.link as flink FROM {aggregator_item} i, {aggregator_feed} f WHERE i.iid = %d AND i.fid = f.fid', $iid))) {
$node->title = $item->title;
// Note: $item->description has been validated on aggregation.
$node->body = '<a href="'. check_url($item->link) .'">'. check_plain($item->title) .'</a> - <em>'. $item->description .'</em> [<a href="'. check_url($item->flink) .'">'. check_plain($item->ftitle) ."</a>]\n";
}
}
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title);
$form['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
$form['filter'] = filter_form($node->format);
return $form;
}
/**
* Implementation of hook_view().
*/
function blog_view(&$node, $teaser = FALSE, $page = FALSE) {
if ($page) {
// Breadcrumb navigation
$breadcrumb[] = array('path' => 'blog', 'title' => t('blogs'));
$breadcrumb[] = array('path' => 'blog/'. $node->uid, 'title' => t("%name's blog", array('%name' => $node->name)));
$breadcrumb[] = array('path' => 'node/'. $node->nid);
menu_set_location($breadcrumb);
}
$node = node_prepare($node, $teaser);;
}
/**
* Implementation of hook_link().
*/
function blog_link($type, $node = 0, $main = 0) {
$links = array();
if ($type == 'node' && $node->type == 'blog') {
if (arg(0) != 'blog' || arg(1) != $node->uid) {
$links[] = l(t("%username's blog", array('%username' => $node->name)), "blog/$node->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $node->name))));
}
}
return $links;
}
/**
* Implementation of hook_menu().
*/
function blog_menu($may_cache) {
global $user;
$items = array();
if ($may_cache) {
$items[] = array('path' => 'node/add/blog', 'title' => t('blog entry'),
'access' => user_access('edit own blog'));
$items[] = array('path' => 'blog', 'title' => t('blogs'),
'callback' => 'blog_page',
'access' => user_access('access content'),
'type' => MENU_SUGGESTED_ITEM);
$items[] = array('path' => 'blog/'. $user->uid, 'title' => t('my blog'),
'access' => user_access('edit own blog'),
'type' => MENU_DYNAMIC_ITEM);
}
return $items;
}
/**
* Implementation of hook_block().
*
* Displays the most recent 10 blog titles.
*/
function blog_block($op = 'list', $delta = 0) {
global $user;
if ($op == 'list') {
$block[0]['info'] = t('Recent blog posts');
return $block;
}
else if ($op == 'view') {
if (user_access('access content')) {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10);
if (db_num_rows($result)) {
$block['content'] = node_title_list($result);
$block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>';
$block['subject'] = t('Recent blog posts');
return $block;
}
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
// $Id$
/**
* @file
* Enables the use of personal contact forms.
*/
/**
* Implementation of hook_help().
*/
function contact_help($section) {
switch ($section) {
case 'admin/help#contact':
$output = '<p>'. t('The contact module allows other users to contact you by e-mail via your personal contact form. Users can send a subject and message in the contact form. The contact module is important in helping make connections among members of your community.') .'</p>';
$output .= '<p>'. t('Users can administer the contact settings in their account settings. Note that a users e-mail address is not made public and that privileged users such as site administrators are able to contact you even if you choose not to enable this feature. If users activate the personal contact form, then a contact tab will appear in their user profile.') .'</p>';
$output .= t('<p>You can</p>
<ul>
<li>view user <a href="%profile">profiles</a>.</li>
<li>enable the personal contact form in <a href="%admin-user">administer &gt;&gt; user &gt;&gt; edit tab &gt;&gt; account settings tab &gt;&gt; personal contact settings</a>.</li>
</ul>
', array('%profile' => url('profile'), '%admin-user' => url('admin/user')));
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%contact">Contact page</a>.', array('%contact' => 'http://www.drupal.org/handbook/modules/contact/')) .'</p>';
return $output;
case 'admin/modules#description':
return t('Enables the use of both personal and site-wide contact forms.');
case 'admin/contact':
return t('This page lets you setup <a href="%form">your site-wide contact form</a>. To do so, add one or more subjects. You can associate different recipients with each subject to route e-mails to different people. For example, you can route website feedback to the webmaster and direct product information requests to the sales department. On the <a href="%settings">settings page</a> you can customize the information shown above the contact form. This can be useful to provide additional contact information such as your postal address and telephone number.', array('%settings' => url('admin/settings/contact'), '%form' => url('contact', NULL, NULL, TRUE)));
}
}
/**
* Implementation of hook_menu().
*/
function contact_menu($may_cache) {
global $user;
$items = array();
if ($may_cache) {
$items[] = array('path' => 'contact', 'title' => t('contact'),
'callback' => 'contact_mail_page', 'access' => user_access('access content'),
'type' => MENU_SUGGESTED_ITEM);
$items[] = array('path' => 'admin/contact', 'title' => t('contact form'),
'callback' => 'contact_admin', 'access' => user_access('administer site configuration'));
$items[] = array('path' => 'admin/contact/list', 'title' => t('list'),
'callback' => 'contact_admin', 'access' => user_access('administer site configuration'),
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1);
$items[] = array('path' => 'admin/contact/edit', 'title' => t('add category'),
'callback' => 'contact_admin_edit', 'access' => user_access('administer site configuration'),
'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'admin/contact/delete', 'title' => t('delete contact'),
'callback' => 'contact_admin_delete', 'access' => user_access('administer site configuration'),
'type' => MENU_CALLBACK);
}
else {
if (arg(0) == 'user' && is_numeric(arg(1))) {
$items[] = array('path' => "user/". arg(1) ."/contact", 'title' => t('contact'),
'callback' => 'contact_mail_user', 'type' => MENU_LOCAL_TASK, 'weight' => 2);
}
}
return $items;
}
/**
* Implementation of hook_settings().
*/
function contact_settings() {
$form['contact_form_information'] = array(
'#type' => 'textarea', '#title' => t('Additional information'),
'#default_value' => variable_get('contact_form_information', t('You can leave a message using the contact form below.')),
'#description' => t('Information to show on the <a href="%form">contact page</a>. Can be anything from submission guidelines to your postal address or telephone number.', array('%form' => url('contact')))
);
$form['contact_hourly_threshold'] = array(
'#type' => 'select',
'#title' => t('Hourly threshold'),
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50)),
'#default_value' => variable_get('contact_hourly_threshold', 3),
'#description' => t('The maximum number of contact form submissions a user can perform per hour.'),
);
return $form;
}
/**
* Implementation of hook_user().
*
* Provides signature customization for the user's comments.
*/
function contact_user($type, $edit, &$user, $category = NULL) {
if ($type == 'form' && $category == 'account') {
$form['contact'] = array('#type' => 'fieldset', '#title' => t('Contact settings'), '#weight' => 5, '#collapsible' => TRUE);
$form['contact']['contact'] = array('#type' => 'checkbox', '#title' => t('Personal contact form'), '#default_value' => $edit['contact'], '#description' => t('Allow other users to contact you by e-mail via <a href="%url">your personal contact form</a>. Note that your e-mail address is not made public and that privileged users such as site administrators are able to contact you even if you choose not to enable this feature.', array('%url' => url("user/$user->uid/contact"))));
return $form;
}
if ($type == 'validate') {
return array('contact' => $edit['contact']);
}
}
function contact_mail_user() {
global $user;
if ($account = user_load(array('uid' => arg(1), 'status' => 1))) {
if (!$account->contact && !user_access('administer users')) {
$output = t('%name is not accepting e-mails.', array('%name' => $account->name));
}
else if (!$user->uid) {
$output = t('Please <a href="%login">login</a> or <a href="%register">register</a> to send %name a message.', array('%login' => url('user/login'), '%register' => url('user/register'), '%name' => $account->name));
}
else if (!valid_email_address($user->mail)) {
$output = t('You need to provide a valid e-mail address to contact other users. Please edit your <a href="%url">user information</a>.', array('%url' => url("user/$user->uid/edit")));
}
else if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
$output = t("You can't contact more than %number users per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3)));
}
else {
drupal_set_title($account->name);
$form['#token'] = $user->name . $user->mail;
$form['from'] = array('#type' => 'item', '#title' => t('From'), '#value' => $user->name .' &lt;'. $user->mail .'&gt;');
$form['to'] = array('#type' => 'item', '#title' => t('To'), '#value' => $account->name);
$form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 50, '#required' => TRUE);
$form['message'] = array('#type' => 'textarea', '#title' => t('Message'), '#rows' => 15, '#required' => TRUE);
$form['copy'] = array('#type' => 'checkbox', '#title' => t('Send me a copy.'));
$form['submit'] = array('#type' => 'submit', '#value' => t('Send e-mail'));
$output = drupal_get_form('contact_user_mail', $form);
}
return $output;
}
else {
drupal_not_found();
}
}
function contact_user_mail_submit($form_id, $edit) {
global $user;
$account = user_load(array('uid' => arg(1), 'status' => 1));
// Compose the body:
$message[] = "$account->name,";
$message[] = t("%name (%name-url) has sent you a message via your contact form (%form-url) at %site.", array('%name' => $user->name, '%name-url' => url("user/$user->uid", NULL, NULL, TRUE), '%form-url' => url($_GET['q'], NULL, NULL, TRUE), '%site' => variable_get('site_name', 'drupal')));
$message[] = t("If you don't want to receive such e-mails, you can change your settings at %url.", array('%url' => url("user/$account->uid", NULL, NULL, TRUE)));
$message[] = t('Message:');
$message[] = $edit['message'];
// Tidy up the body:
foreach ($message as $key => $value) {
$message[$key] = wordwrap($value);
}
// Prepare all fields:
$to = $account->mail;
$from = $user->mail;
// Format the subject:
$subject = '['. variable_get('site_name', 'drupal') .'] '. $edit['subject'];
// Prepare the body:
$body = implode("\n\n", $message);
// Send the e-mail:
user_mail($to, $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
// Send a copy if requested:
if ($edit['copy']) {
user_mail($from, $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
}
// Log the operation:
flood_register_event('contact');
watchdog('mail', t('%name-from sent %name-to an e-mail.', array('%name-from' => theme('placeholder', $user->name), '%name-to' => theme('placeholder', $account->name))));
// Set a status message:
drupal_set_message(t('The message has been sent.'));
// Jump to the user's profile page:
drupal_goto("user/$account->uid");
}
function contact_admin_edit($cid = NULL) {
if (isset($_POST['edit'])) {
$edit = $_POST['edit'];
if (empty($edit['category'])) {
form_set_error('category', t('You must enter a category.'));
}
if (empty($edit['recipients'])) {
form_set_error('recipients', t('You must enter one or more recipients.'));
}
else {
$recipients = split(',', $edit['recipients']);
foreach($recipients as $recipient) {
if (!valid_email_address(trim($recipient))) {
form_set_error('recipients',t('%recipient is an invalid e-mail address.', array('%recipient' => theme('placeholder', $recipient))));
}
}
}
if (!form_get_errors()) {
db_query("DELETE FROM {contact} WHERE cid = %d", $cid);
db_query("INSERT INTO {contact} (category, recipients, reply, weight, selected) VALUES ('%s', '%s', '%s', %d, %d)", $edit['category'], $edit['recipients'], $edit['reply'], $edit['weight'], $edit['selected']);
drupal_set_message(t('Category %category has been updated.', array('%category' => theme('placeholder', $edit['category']))));
drupal_goto('admin/contact');
}
}
else {
$category = db_fetch_object(db_query("SELECT * FROM {contact} WHERE cid = %d", $cid));
$edit['cid'] = $category->cid;
$edit['category'] = $category->category;
$edit['recipients'] = $category->recipients;
$edit['reply'] = $category->reply;
$edit['weight'] = $category->weight;
$edit['selected'] = $category->selected;
}
$form['category'] = array('#type' => 'textfield', '#title' => t('Category'), '#maxlength' => 255, '#default_value' => $edit['category'], '#description' => t("Example: 'website feedback' or 'product information'."), '#required' => TRUE);
$form['recipients'] = array('#type' => 'textarea', '#title' => t('Recipients'), '#default_value' => $edit['recipients'], '#description' => t("Example: 'webmaster@yoursite.com' or 'sales@yoursite.com'. To specify multiple repecients, separate each e-mail address with a comma."), '#required' => TRUE);
$form['reply'] = array('#type' => 'textarea', '#title' => t('Auto-reply'), '#default_value' => $edit['reply'], '#description' => t("Optional auto-reply. Leave empty if you don't want to send the user an auto-reply message."));
$form['weight'] = array('#type' => 'weight', '#title' => t('Weight'), '#default_value' => $edit['weight'], '#description' => t('When listing categories, those with with light (small) weights get listed before categories with heavier (larger) weights. Categories with equal weights are sorted alphabetically.'));
$form['selected'] = array('#type' => 'select', '#title' => t('Selected'), '#options' => array('0' => t('No'), '1' => t('Yes')), '#default_value' => $edit['selected'], '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'));
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
return drupal_get_form('contact_admin_edit', $form);
}
function contact_admin_delete($cid) {
$info = db_fetch_object(db_query("SELECT cid, category FROM {contact} WHERE cid = %d", $cid));
if ($_POST['op'] != t('Delete')) {
return confirm_form('contact_admin_delete', array(),
t('Are you sure you want to delete %category?', array('%category' => theme('placeholder', $info->category))),
'admin/contact',
t('This action cannot be undone.'),
t('Delete'),
t('Cancel'));
}
else {
db_query("DELETE FROM {contact} WHERE cid = %d", $cid);
drupal_goto('admin/contact');
}
}
function contact_admin() {
$result = db_query('SELECT cid, category, recipients, selected FROM {contact} ORDER BY weight, category');
$rows = array();
while ($category = db_fetch_object($result)) {
$rows[] = array($category->category, $category->recipients, ($category->selected ? t('Yes') : t('No')), l(t('edit'), 'admin/contact/edit/'. $category->cid), l(t('delete'), 'admin/contact/delete/'. $category->cid));
}
$header = array(t('Category'), t('Recipients'), t('Selected'), array('data' => t('Operations'), 'colspan' => 2));
return theme('table', $header, $rows);
}
function contact_mail_page() {
global $user;
if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
$output = t("You can't send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3)));
}
else {
if ($user->uid) {
$edit['name'] = $user->name;
$edit['mail'] = $user->mail;
}
$result = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category');
$categories[] = '--';
while ($category = db_fetch_object($result)) {
$categories[$category->cid] = $category->category;
if ($category->selected) {
$default_category = $category->cid;
}
}
if (count($categories) > 1) {
$form['#token'] = $user->name . $user->mail;
$form['contact_information'] = array('#type' => 'markup', '#value' => variable_get('contact_form_information', t('You can leave us a message using the contact form below.')));
$form['name'] = array('#type' => 'textfield', '#title' => t('Your name'), '#maxlength' => 255, '#default_value' => $edit['name'], '#required' => TRUE);
$form['mail'] = array('#type' => 'textfield', '#title' => t('Your e-mail address'), '#maxlength' => 255, '#default_value' => $edit['mail'], '#required' => TRUE);
$form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 255, '#default_value' => $edit['subject'], '#required' => TRUE);
if (count($categories) > 2) {
$form['cid'] = array('#type' => 'select', '#title' => t('Category'), '#default_value' => $default_category, '#options' => $categories, '#required' => TRUE);
}
$form['message'] = array('#type' => 'textarea', '#title' => t('Message'), '#default_value' => $edit['message'], '#required' => TRUE);
$form['copy'] = array('#type' => 'checkbox', '#title' => t('Send me a copy.'), '#default_value' => $edit['copy']);
$form['submit'] = array('#type' => 'submit', '#value' => t('Send e-mail'));
$output = drupal_get_form('contact_mail_page', $form);
}
else {
$output = t('The contact form has not been configured.');
}
}
return $output;
}
function contact_mail_page_validate($form_id, &$form) {
global $form_values;
if (!$form['cid']) {
// Look if there is only one category
$result = db_query('SELECT cid FROM {contact}');
if (db_num_rows($result) == 1) {
$category = db_fetch_object($result);
$form_values['cid'] = $category->cid;
}
else {
form_set_error('category', t('You must select a valid category.'));
}
if (!valid_email_address($form['mail'])) {
form_set_error('mail', t('You must enter a valid e-mail address.'));
}
}
}
function contact_mail_page_submit($form_id, $edit) {
// Prepare the sender:
$from = $edit['mail'];
// Compose the body:
$message[] = t("%name sent a message using the contact form at %form.", array('%name' => $edit['name'], '%form' => url($_GET['q'], NULL, NULL, TRUE)));
$message[] = $edit['message'];
// Tidy up the body:
foreach ($message as $key => $value) {
$message[$key] = wordwrap($value);
}
// Load the category information:
$contact = db_fetch_object(db_query("SELECT * FROM {contact} WHERE cid = %d", $edit['cid']));
// Format the category:
$subject = '['. $contact->category .'] '. $edit['subject'];
// Prepare the body:
$body = implode("\n\n", $message);
// Send the e-mail to the recipients:
user_mail($contact->recipients, $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
// If the user requests it, send a copy.
if ($edit['copy']) {
user_mail($from, $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
}
// Send an auto-reply if necessary:
if ($contact->reply) {
user_mail($from, $subject, wordwrap($contact->reply), "From: $contact->recipients\nReply-to: $contact->recipients\nX-Mailer: Drupal\nReturn-path: $contact->recipients\nErrors-to: $contact->recipients");
}
// Log the operation:
flood_register_event('contact');
watchdog('mail', t('%name-from sent an e-mail regarding %category.', array('%name-from' => theme('placeholder', $edit['name'] ." <$from>"), '%category' => theme('placeholder', $contact->category))));
// Set a status message:subject
drupal_set_message(t('Your message has been sent.'));
// Jump to contact page:
drupal_goto('contact');
}
<?php
// $Id$
/**
* @file
* Lets users log in using a Drupal ID and can notify a central server about your site.
*/
define(VERSION, '4.7.0');
/**
* Implementation of hook_help().
*/
function drupal_help($section) {
global $base_url;
switch ($section) {
case 'admin/help#drupal':
$output = '<p>'. t('The Drupal module uses the XML-RPC network communication protocol to connect your site with a central server that maintains a directory of client sites.') .'</p>';
$output .= t('<p>Enabling the Drupal module will allow you to:</p>
<ul>
<li>register your site with a server, including (optionally) posting information on your installed modules and themes and summary statistics on your number of posts and users, information that can help rank Drupal modules and themes</li>
<li>enable other sites to register with your site</li>
<li>allow members on all sites using the Drupal module to log in to your site without registering using their distributed identification</li>
<li>allow members to log in to any other site that uses the Drupal module, using a login name that looks much like an email address for your site: <em>username@%base_url</em></li>
</ul>
', array('%base_url' => $base_url));
$output .= '<p>'. t('The Drupal module administration page allows you to set the xml-rpc server page and other related options.') .'</p>';
$output .= t('<p>You can</p>
<ul>
<li>run your cron job at your site\'s <a href="%file-cron">cron page</a></li>
<li>view your <a href="%file-xmlrpc">XML-RPC page</a>.</li>
<li>administer Drupal <a href="%admin-settings-drupal">administer &gt;&gt; settings &gt;&gt; drupal</a>.</li>
</ul>
', array('%file-cron' => 'cron.php', '%file-xmlrpc' => 'xmlrpc.php', '%admin-settings-drupal' => url('admin/settings/drupal')));
$output .= '<p>'. t('If you maintain a directory of sites, you can list them on a page using the <code>drupal_client_page()</code> function. Sample instructions:
<ul>
<li>Enable the page module. Select create content &gt;&gt; page.</li>
<li>For input format, select PHP code.</li>
<li>Give the page a title. For body, put:
<pre>
&lt;?php
print drupal_client_page();
?&gt;
</pre>
<li>Save the page.</li>
</ul>') . '</p>';
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%drupal">Drupal page</a>.', array('%drupal' => 'http://www.drupal.org/handbook/modules/drupal/')) .'</p>';
return $output;
case 'admin/modules#description':
return t('Lets you register your site with a central server and improve ranking of Drupal projects by posting information on your installed modules and themes; also enables users to log in using a Drupal ID.');
case 'admin/settings/drupal':
return t('<p>Using this your site can "call home" to another Drupal server. By calling home to drupal.org and sending a list of your installed modules and themes, you help rank projects on drupal.org and so assist all Drupal administrators to find the best components for meeting their needs. If you want to register with a different server, you can change the Drupal XML-RPC server setting -- but the server has to be able to handle Drupal XML. Some XML-RPC servers may present directories of all registered sites. To get all your site information listed, go to the <a href="%site-settings">settings page</a> and set the site name, the e-mail address, the slogan, and the mission statement.</p>', array('%site-settings' => url('admin/settings')));
case 'user/help#drupal':
return variable_get('drupal_authentication_service', 0) ? t("<p><a href=\"%Drupal\">Drupal</a> is the name of the software that powers %this-site. There are Drupal web sites all over the world, and many of them share their registration databases so that users may freely log in to any Drupal site using a single <strong>Drupal ID</strong>.</p>
<p>So please feel free to log in to your account here at %this-site with a username from another Drupal site. The format of a Drupal ID is similar to an email address: <strong>username</strong>@<em>server</em>. An example of a valid Drupal ID is <strong>mwlily</strong>@<em>www.drupal.org</em>.</p>", array('%Drupal' => 'http://www.drupal.org', '%this-site' => '<em>'. variable_get('site_name', 'this web site') .'</em>')) : NULL;
}
}
/**
* Implementation of hook_settings().
*/
function drupal_settings() {
// Check if all required fields are present
if ((variable_get('site_name', 'drupal') == 'drupal') || (variable_get('site_name', 'drupal') == '')) {
form_set_error('drupal_directory', t('You must set the name of your site on the <a href="%url">administer &raquo; settings</a> page.', array('%url' => url('admin/settings'))));
}
else if (variable_get('site_mail', ini_get('sendmail_from')) == '') {
form_set_error('drupal_directory', t('You must set an e-mail address for your site on the <a href="%url">administer &raquo; settings</a> page.', array('%url' => url('admin/settings'))));
}
else if (variable_get('site_slogan', '') == '') {
form_set_error('drupal_directory', t('You must set your site slogan on the <a href="%url">administer &raquo; settings</a> page.', array('%url' => url('admin/settings'))));
}
else if (variable_get('site_mission', '') == '') {
form_set_error('drupal_directory', t('You must set your site mission on the <a href="%url">administer &raquo; settings</a> page.' , array('%url' => url('admin/settings'))));
}
$options = array('1' => t('Enabled'), '0' => t('Disabled'));
$form['drupal'] = array(
'#type' => 'fieldset',
'#title' => t('Post data to another site'),
'#tree' => FALSE
);
$form['drupal']['drupal_register'] = array(
'#type' => 'radios',
'#title' => t('Register with a Drupal server'),
'#default_value' => variable_get('drupal_register', 0),
'#options' => $options,
'#description' => t("If enabled, your Drupal site will register itself with the specified Drupal XML-RPC server. For this to work properly, you must set your site's name, e-mail address, slogan and mission statement. When the \"Drupal XML-RPC server\" field is set to \"%drupal-xml-rpc\", your web site will register itself with drupal.org. Requires the cron feature to be enabled.", array("%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php", "%drupal-sites" => "http://www.drupal.org/drupal-sites/"))
);
$form['drupal']['drupal_server'] = array(
'#type' => 'textfield',
'#title' => t('Drupal XML-RPC server'),
'#default_value' => variable_get('drupal_server', 'http://www.drupal.org/xmlrpc.php'),
'#description' => t('The URL of the Drupal XML-RPC server you wish to register with.')
);
$form['drupal']['drupal_system'] = array(
'#type' => 'radios',
'#title' => t('Send system information'),
'#default_value' => variable_get('drupal_system', 0),
'#options' => $options,
'#description' => t("If enabled, your site will send information on its installed components (modules, themes, and theme engines). This information can help in compiling statistics on usage of Drupal projects.")
);
$form['drupal']['drupal_statistics'] = array(
'#type' => 'radios',
'#title' => t('Send statistics'),
'#default_value' => variable_get('drupal_statistics', 0),
'#options' => $options,
'#description' => t("If enabled, your site will send summary statistics on the number of registered users and the total number of posts. No private information will be sent. These data help to improve the ranking statistics of Drupal projects.")
);
$form['services'] = array(
'#type' => 'fieldset',
'#title' => t('Receive data from other sites'),
'#tree' => FALSE
);
$form['services']['drupal_client_service'] = array(
'#type' => 'radios',
'#title' => t('Allow other Drupal sites to register'),
'#default_value' => variable_get('drupal_client_service', 0),
'#options' => $options,
'#description' => t('If enabled, your Drupal site will allow other sites to register with your site and send information to this site. This functionality can be used to maintain a list of related sites.')
);
$form['services']['drupal_authentication_service'] = array(
'#type' => 'radios',
'#title' => t('Authentication service'),
'#default_value' => variable_get('drupal_authentication_service', 0),
'#options' => $options,
'#description' => t('If enabled, your Drupal site will accept logins with the user names of other Drupal sites, and likewise provide authentication for users logging into other Drupal sites, based on their user accounts here.')
);
return $form;
}
/**
* Implementation of hook_cron(); handles pings to and from the site.
*/
function drupal_cron() {
if (time() - variable_get('cron_last', 0) > 21600) {
// If this site acts as a Drupal XML-RPC server, delete the sites that
// stopped sending "ping" messages.
if (variable_get('drupal_client_service', 0)) {
$result = db_query("SELECT cid FROM {client} WHERE changed < %d", time() - 259200);
while ($client = db_fetch_object($result)) {
db_query("DELETE FROM {client_system} WHERE cid = %d", $client->cid);
db_query("DELETE FROM {client} WHERE cid = %d", $client->cid);
}
}
// If this site acts as a Drupal XML-RPC client, send a message to the
// Drupal XML-RPC server.
if (variable_get('drupal_register', 0) && variable_get('drupal_server', 0)) {
drupal_notify(variable_get('drupal_server', ''));
}
}
}
/**
* Callback function from drupal_xmlrpc() called when another site pings this one.
*/
function drupal_client_ping($client, $system) {
/*
** Parse our parameters:
*/
foreach (array('link', 'name', 'mail', 'slogan', 'mission') as $key) {
$client[$key] = strip_tags($client[$key]);
}
/*
** Update the data in our database and send back a reply:
*/
if ($client['link'] && $client['name'] && $client['mail'] && $client['slogan'] && $client['mission']) {
$result = db_query(db_rewrite_sql("SELECT cid FROM {client} WHERE link = '%s'"), $client['link']);
if (db_num_rows($result)) {
$record = db_fetch_object($result);
$client['cid'] = $record->cid;
// We have an existing record.
db_query("UPDATE {client} SET link = '%s', name = '%s', mail = '%s', slogan = '%s', mission = '%s', users = %d, nodes = %d, version = '%s', changed = '%s' WHERE cid = %d", $client['uid'], $client['link'], $client['name'], $client['mail'], $client['slogan'], $client['mission'], $client['users'], $client['nodes'], $client['version'], time(), $client['cid']);
}
else {
$client['cid'] = db_next_id('{client}_cid');
db_query("INSERT INTO {client} (cid, link, name, mail, slogan, mission, users, nodes, version, created, changed) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $client['cid'], $client['link'], $client['name'], $client['mail'], $client['slogan'], $client['mission'], $client['users'], $client['nodes'], $client['version'], time(), time());
}
if (is_array($system)) {
db_query("DELETE FROM {client_system} WHERE cid = %d", $client['cid']);
foreach ($system as $item) {
db_query("INSERT INTO {client_system} (cid, name, type) VALUES (%d, '%s', '%s')", $client['cid'], $item['name'], $item['type']);
}
}
watchdog('client ping', t('Ping from %name (%link).', array('%name' => theme('placeholder', $client['name']), '%link' => theme('placeholder', $client['link']))), WATCHDOG_NOTICE, '<a href="'. check_url($client['link']) .'">view</a>');
return TRUE;
}
else {
return 0;
}
}
/**
* Formats a list of all clients.
*
* This function may be called from a custom page on sites that are
* Drupal directory servers.
*/
function drupal_client_page($sort = 'name') {
$result = db_query('SELECT * FROM {client} ORDER BY %s', $sort);
$clients = array();
while ($client = db_fetch_object($result)) {
$clients[] = $client;
}
return theme('client_list', $clients);
}
/**
* Theme a client list.
*/
function theme_client_list($clients) {
// Note: All fields except the mission are treated as plain-text.
// The mission is stripped of any HTML tags to keep the output simple and consistent.
$output = "\n<dl>\n";
foreach ($clients as $client) {
$output .= ' <dt><a href="' . check_url($client->link) . '">' . check_plain($client->name) . '</a> - ' . check_plain($client->slogan) . "</dt>\n";
$output .= ' <dd>' . strip_tags($client->mission) . "</dd>\n";
}
$output .= "</dl>\n";
return $output;
}
/**
* Implementation of hook_xmlrpc().
*/
function drupal_xmlrpc() {
$xmlrpc = array();
if (variable_get('drupal_client_service', 0)) {
$xmlrpc[] = array(
'drupal.client.ping',
'drupal_client_ping',
array('array', 'array', 'array'),
t('Handling ping request')
);
}
if (variable_get('drupal_authentication_service', 0)) {
$xmlrpc[] = array(
'drupal.login',
'drupal_login',
array('int', 'string', 'string'),
t('Logging into a Drupal site')
);
}
return $xmlrpc;
}
/**
* Sends a ping to the Drupal directory server.
*/
function drupal_notify($server) {
global $base_url;
$client = array(
'link' => $base_url,
'name' => variable_get('site_name', ''),
'mail' => variable_get('site_mail', ''),
'slogan' => variable_get('site_slogan', ''),
'mission' => variable_get('site_mission', ''),
'version' => VERSION
);
if (variable_get('drupal_system', 0)) {
$system = array();
$result = db_query("SELECT name, type FROM {system} WHERE status = 1");
while ($item = db_fetch_array($result)) {
$system[] = $item;
}
}
if (variable_get('drupal_statistics', 0)) {
$users = db_fetch_object(db_query("SELECT COUNT(uid) AS count FROM {users}"));
$client['users'] = $users->count;
$nodes = db_fetch_object(db_query("SELECT COUNT(nid) AS count FROM {node}"));
$client['nodes'] = $nodes->count;
}
$result = xmlrpc($server, 'drupal.client.ping', $client, $system);
if ($result === FALSE) {
watchdog('server ping', t('Failed to notify %server; error code: %errno; error message: %error_msg.', array('%server' => theme('placeholder', $server), '%errno' => theme('placeholder', xmlrpc_errno()), '%error_msg' => theme('placeholder', xmlrpc_error_msg()))), WATCHDOG_WARNING);
}
}
/**
* Implementation of hook_info().
*/
function drupal_info($field = 0) {
$info['name'] = 'Drupal';
$info['protocol'] = 'XML-RPC';
if ($field) {
return $info[$field];
}
else {
return $info;
}
}
/**
* Implementation of hook_auth().
*/
function drupal_auth($username, $password, $server) {
if (variable_get('drupal_authentication_service', 0)) {
$result = xmlrpc("http://$server/xmlrpc.php", 'drupal.login', $username, $password);
if ($result === FALSE) {
drupal_set_message(t('Error %code : %message', array('%code' => theme('placeholder', xmlrpc_errno()), '%message' => theme('placeholder', xmlrpc_error_msg()))), 'error');
}
else {
return $result;
}
}
}
/**
* Implementation of hook_menu().
*/
function drupal_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'drupal', 'title' => t('Drupal'),
'callback' => 'drupal_page_help', 'access' => TRUE,
'type' => MENU_SUGGESTED_ITEM
);
}
return $items;
}
/**
* Menu callback; print Drupal-authentication-specific information from user/help.
*/
function drupal_page_help() {
return drupal_help('user/help#drupal');
}
/**
* Callback function from drupal_xmlrpc() for authenticating remote clients.
*
* Remote clients are usually other Drupal instances.
*/
function drupal_login($username, $password) {
if (variable_get('drupal_authentication_service', 0)) {
if ($user = user_load(array('name' => $username, 'pass' => $password, 'status' => 1))) {
return $user->uid;
}
else {
return 0;
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment