diff options
author | Dries Buytaert <dries@buytaert.net> | 2004-05-17 22:00:06 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2004-05-17 22:00:06 +0000 |
commit | e52c0f5d41ad9319c9420bbe3a9dcfa76a90222f (patch) | |
tree | 16bddd048a7a2c0eb271879700cb7c47e2fe68ba /modules | |
parent | ac3c45dd2ac615327678301a5bb43d9c7edc7af8 (diff) | |
download | brdo-e52c0f5d41ad9319c9420bbe3a9dcfa76a90222f.tar.gz brdo-e52c0f5d41ad9319c9420bbe3a9dcfa76a90222f.tar.bz2 |
- Code improvements by JonBob. Thanks.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/admin.module | 7 | ||||
-rw-r--r-- | modules/aggregator.module | 27 | ||||
-rw-r--r-- | modules/aggregator/aggregator.module | 27 | ||||
-rw-r--r-- | modules/archive.module | 2 | ||||
-rw-r--r-- | modules/archive/archive.module | 2 | ||||
-rw-r--r-- | modules/block.module | 13 | ||||
-rw-r--r-- | modules/block/block.module | 13 | ||||
-rw-r--r-- | modules/blog.module | 4 | ||||
-rw-r--r-- | modules/blog/blog.module | 4 | ||||
-rw-r--r-- | modules/book.module | 12 | ||||
-rw-r--r-- | modules/book/book.module | 12 | ||||
-rw-r--r-- | modules/drupal.module | 136 | ||||
-rw-r--r-- | modules/drupal/drupal.module | 136 | ||||
-rw-r--r-- | modules/filter.module | 197 | ||||
-rw-r--r-- | modules/filter/filter.module | 197 | ||||
-rw-r--r-- | modules/forum.module | 2 | ||||
-rw-r--r-- | modules/forum/forum.module | 2 | ||||
-rw-r--r-- | modules/help.module | 56 | ||||
-rw-r--r-- | modules/help/help.module | 56 | ||||
-rw-r--r-- | modules/statistics.module | 8 | ||||
-rw-r--r-- | modules/statistics/statistics.module | 8 |
21 files changed, 497 insertions, 424 deletions
diff --git a/modules/admin.module b/modules/admin.module index 8c9c97e01..276a63a2e 100644 --- a/modules/admin.module +++ b/modules/admin.module @@ -20,15 +20,14 @@ function admin_help($section) { */ function admin_link($type) { if ($type == 'system') { - menu('admin', t('administer'), user_access('access administration pages') ? 'admin_admin' : MENU_DENIED, 9); + menu('admin', t('administer'), user_access('access administration pages') ? 'admin_main_page' : MENU_DENIED, 9); } } /** - * Menu callback. Provides an overview to serve as the main page of the - * administration section. + * Menu callback; provides the main page of the administration section. */ -function admin_admin() { +function admin_main_page() { print theme("page", watchdog_overview("actions")); } diff --git a/modules/aggregator.module b/modules/aggregator.module index 707bf0fee..62e131a78 100644 --- a/modules/aggregator.module +++ b/modules/aggregator.module @@ -68,7 +68,7 @@ function aggregator_help($section) { } /** - * Menu callback. Displays the aggregator-specific information from admin/help. + * Menu callback; displays the aggregator-specific information from admin/help. */ function aggregator_help_page() { print theme('page', aggregator_help('admin/help#aggregator')); @@ -626,7 +626,7 @@ function aggregator_view() { } /** - * Menu callback. Displays the category edit form, or saves changes and + * Menu callback; displays the category edit form, or saves changes and * displays the overview page. */ function aggregator_admin_edit_category($category = 0) { @@ -652,8 +652,9 @@ function aggregator_admin_edit_category($category = 0) { } /** - * Menu callback. Displays the feed edit form, or saves changes and - * displays the overview page. + * Menu callback; displays the feed edit form. + * + * After editing, saves changes and displays the overview page. */ function aggregator_admin_edit_feed($feed = 0) { $edit = $_POST['edit']; @@ -678,7 +679,7 @@ function aggregator_admin_edit_feed($feed = 0) { } /** - * Menu callback. Removes all items from a feed, then displays the overview page. + * Menu callback; removes all items from a feed, then displays the overview page. */ function aggregator_admin_remove_feed($feed) { aggregator_remove(aggregator_get_feed($feed)); @@ -686,7 +687,7 @@ function aggregator_admin_remove_feed($feed) { } /** - * Menu callback. Refreshes a feed, then displays the overview page. + * Menu callback; refreshes a feed, then displays the overview page. */ function aggregator_admin_refresh_feed($feed) { aggregator_refresh(aggregator_get_feed($feed)); @@ -694,21 +695,21 @@ function aggregator_admin_refresh_feed($feed) { } /** - * Menu callback. Displays the aggregator administration page. + * Menu callback; displays the aggregator administration page. */ function aggregator_admin_overview() { print theme('page', aggregator_view()); } /** - * Menu callback. Displays the most recent items gathered from any feed. + * Menu callback; displays the most recent items gathered from any feed. */ function aggregator_page_last() { _aggregator_page_list('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC', arg(1)); } /** - * Menu callback. Displays all the items captured from a particular feed. + * Menu callback; displays all the items captured from a particular feed. */ function aggregator_page_source() { $feed = db_fetch_object(db_query('SELECT * FROM {aggregator_feed} WHERE fid = %d', arg(2))); @@ -718,7 +719,7 @@ function aggregator_page_source() { } /** - * Menu callback. Displays all the items aggregated in a particular category. + * Menu callback; displays all the items aggregated in a particular category. */ function aggregator_page_category() { $category = db_fetch_object(db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = %d', arg(2))); @@ -804,7 +805,7 @@ function _aggregator_page_list($sql, $op, $header = '') { } /** - * Menu callback. Displays all the feeds used by the aggregator. + * Menu callback; displays all the feeds used by the aggregator. */ function aggregator_page_sources() { $result = db_query('SELECT f.fid, f.title, f.description, f.image, MAX(i.timestamp) AS last FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY fid'); @@ -829,7 +830,7 @@ function aggregator_page_sources() { } /** - * Menu callback. Generates an OPML representation of all feeds. + * Menu callback; generates an OPML representation of all feeds. */ function aggregator_page_opml() { $result = db_query('SELECT * FROM {aggregator_feed} ORDER BY title'); @@ -854,7 +855,7 @@ function aggregator_page_opml() { } /** - * Menu callback. Displays all the categories used by the aggregator. + * Menu callback; displays all the categories used by the aggregator. */ function aggregator_page_categories() { $result = db_query('SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY cid'); diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index 707bf0fee..62e131a78 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -68,7 +68,7 @@ function aggregator_help($section) { } /** - * Menu callback. Displays the aggregator-specific information from admin/help. + * Menu callback; displays the aggregator-specific information from admin/help. */ function aggregator_help_page() { print theme('page', aggregator_help('admin/help#aggregator')); @@ -626,7 +626,7 @@ function aggregator_view() { } /** - * Menu callback. Displays the category edit form, or saves changes and + * Menu callback; displays the category edit form, or saves changes and * displays the overview page. */ function aggregator_admin_edit_category($category = 0) { @@ -652,8 +652,9 @@ function aggregator_admin_edit_category($category = 0) { } /** - * Menu callback. Displays the feed edit form, or saves changes and - * displays the overview page. + * Menu callback; displays the feed edit form. + * + * After editing, saves changes and displays the overview page. */ function aggregator_admin_edit_feed($feed = 0) { $edit = $_POST['edit']; @@ -678,7 +679,7 @@ function aggregator_admin_edit_feed($feed = 0) { } /** - * Menu callback. Removes all items from a feed, then displays the overview page. + * Menu callback; removes all items from a feed, then displays the overview page. */ function aggregator_admin_remove_feed($feed) { aggregator_remove(aggregator_get_feed($feed)); @@ -686,7 +687,7 @@ function aggregator_admin_remove_feed($feed) { } /** - * Menu callback. Refreshes a feed, then displays the overview page. + * Menu callback; refreshes a feed, then displays the overview page. */ function aggregator_admin_refresh_feed($feed) { aggregator_refresh(aggregator_get_feed($feed)); @@ -694,21 +695,21 @@ function aggregator_admin_refresh_feed($feed) { } /** - * Menu callback. Displays the aggregator administration page. + * Menu callback; displays the aggregator administration page. */ function aggregator_admin_overview() { print theme('page', aggregator_view()); } /** - * Menu callback. Displays the most recent items gathered from any feed. + * Menu callback; displays the most recent items gathered from any feed. */ function aggregator_page_last() { _aggregator_page_list('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC', arg(1)); } /** - * Menu callback. Displays all the items captured from a particular feed. + * Menu callback; displays all the items captured from a particular feed. */ function aggregator_page_source() { $feed = db_fetch_object(db_query('SELECT * FROM {aggregator_feed} WHERE fid = %d', arg(2))); @@ -718,7 +719,7 @@ function aggregator_page_source() { } /** - * Menu callback. Displays all the items aggregated in a particular category. + * Menu callback; displays all the items aggregated in a particular category. */ function aggregator_page_category() { $category = db_fetch_object(db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = %d', arg(2))); @@ -804,7 +805,7 @@ function _aggregator_page_list($sql, $op, $header = '') { } /** - * Menu callback. Displays all the feeds used by the aggregator. + * Menu callback; displays all the feeds used by the aggregator. */ function aggregator_page_sources() { $result = db_query('SELECT f.fid, f.title, f.description, f.image, MAX(i.timestamp) AS last FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY fid'); @@ -829,7 +830,7 @@ function aggregator_page_sources() { } /** - * Menu callback. Generates an OPML representation of all feeds. + * Menu callback; generates an OPML representation of all feeds. */ function aggregator_page_opml() { $result = db_query('SELECT * FROM {aggregator_feed} ORDER BY title'); @@ -854,7 +855,7 @@ function aggregator_page_opml() { } /** - * Menu callback. Displays all the categories used by the aggregator. + * Menu callback; displays all the categories used by the aggregator. */ function aggregator_page_categories() { $result = db_query('SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY cid'); diff --git a/modules/archive.module b/modules/archive.module index cf0e99157..15825ec25 100644 --- a/modules/archive.module +++ b/modules/archive.module @@ -208,7 +208,7 @@ function archive_link($type) { } /** - * Menu callback. Lists all nodes posted on a given date. + * Menu callback; lists all nodes posted on a given date. */ function archive_page($year = 0, $month = 0, $day = 0) { global $user; diff --git a/modules/archive/archive.module b/modules/archive/archive.module index cf0e99157..15825ec25 100644 --- a/modules/archive/archive.module +++ b/modules/archive/archive.module @@ -208,7 +208,7 @@ function archive_link($type) { } /** - * Menu callback. Lists all nodes posted on a given date. + * Menu callback; lists all nodes posted on a given date. */ function archive_page($year = 0, $month = 0, $day = 0) { global $user; diff --git a/modules/block.module b/modules/block.module index 1921193b6..17137ec89 100644 --- a/modules/block.module +++ b/modules/block.module @@ -48,7 +48,7 @@ function block_help($section) { } /** - * Menu callback. Presents the block-specific information from admin/help. + * Menu callback; presents the block-specific information from admin/help. */ function block_help_page() { print theme('page', block_help('admin/help#block')); @@ -192,7 +192,7 @@ function block_admin_display() { } /** - * Menu callback. Displays the block layout as it will appear when themed. + * Menu callback; displays the block layout as it will appear when themed. */ function block_admin_preview() { $result = db_query('SELECT * FROM {blocks} WHERE status > 0 AND region = 0 ORDER BY weight'); @@ -251,8 +251,9 @@ function block_box_get($bid) { } /** - * Menu callback. Displays the block editing form, or saves changes and - * displays the block overview. + * Menu callback; displays the block editing form. + * + * On edit, saves changes and displays the block overview. */ function block_box_edit($bid = 0) { $edit = $_POST['edit']; @@ -310,7 +311,7 @@ function block_box_save($edit) { } /** - * Menu callback. Deletes a custom box, then displays the overview page. + * Menu callback; deletes a custom box, then displays the overview page. */ function block_box_delete($bid = 0) { if ($bid) { @@ -322,7 +323,7 @@ function block_box_delete($bid = 0) { } /** - * Menu callback. Displays the block overview page. + * Menu callback; displays the block overview page. */ function block_admin() { $edit = $_POST['edit']; diff --git a/modules/block/block.module b/modules/block/block.module index 1921193b6..17137ec89 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -48,7 +48,7 @@ function block_help($section) { } /** - * Menu callback. Presents the block-specific information from admin/help. + * Menu callback; presents the block-specific information from admin/help. */ function block_help_page() { print theme('page', block_help('admin/help#block')); @@ -192,7 +192,7 @@ function block_admin_display() { } /** - * Menu callback. Displays the block layout as it will appear when themed. + * Menu callback; displays the block layout as it will appear when themed. */ function block_admin_preview() { $result = db_query('SELECT * FROM {blocks} WHERE status > 0 AND region = 0 ORDER BY weight'); @@ -251,8 +251,9 @@ function block_box_get($bid) { } /** - * Menu callback. Displays the block editing form, or saves changes and - * displays the block overview. + * Menu callback; displays the block editing form. + * + * On edit, saves changes and displays the block overview. */ function block_box_edit($bid = 0) { $edit = $_POST['edit']; @@ -310,7 +311,7 @@ function block_box_save($edit) { } /** - * Menu callback. Deletes a custom box, then displays the overview page. + * Menu callback; deletes a custom box, then displays the overview page. */ function block_box_delete($bid = 0) { if ($bid) { @@ -322,7 +323,7 @@ function block_box_delete($bid = 0) { } /** - * Menu callback. Displays the block overview page. + * Menu callback; displays the block overview page. */ function block_admin() { $edit = $_POST['edit']; diff --git a/modules/blog.module b/modules/blog.module index 775b1f581..a6737a8d6 100644 --- a/modules/blog.module +++ b/modules/blog.module @@ -80,7 +80,7 @@ function blog_help($section) { } /** - * Menu callback. Displays an RSS feed containing recent blog entries. + * Menu callback; displays an RSS feed containing recent blog entries. */ function blog_feed($uid = 0) { if ($uid) { @@ -123,7 +123,7 @@ function blog_feed_last() { } /** - * Menu callback. Displays a Drupal page containing recent blog entries. + * Menu callback; displays a Drupal page containing recent blog entries. */ function blog_page($uid = 0) { if ($uid) { diff --git a/modules/blog/blog.module b/modules/blog/blog.module index 775b1f581..a6737a8d6 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -80,7 +80,7 @@ function blog_help($section) { } /** - * Menu callback. Displays an RSS feed containing recent blog entries. + * Menu callback; displays an RSS feed containing recent blog entries. */ function blog_feed($uid = 0) { if ($uid) { @@ -123,7 +123,7 @@ function blog_feed_last() { } /** - * Menu callback. Displays a Drupal page containing recent blog entries. + * Menu callback; displays a Drupal page containing recent blog entries. */ function blog_page($uid = 0) { if ($uid) { diff --git a/modules/book.module b/modules/book.module index 7658a9251..f499db81c 100644 --- a/modules/book.module +++ b/modules/book.module @@ -679,7 +679,7 @@ function book_tree($parent = 0, $depth = 3, $unfold = array()) { } /** - * Menu callback. Prints a listing of all books. + * Menu callback; prints a listing of all books. */ function book_render() { @@ -705,7 +705,7 @@ function book_render() { } /** - * Menu callback. Prints a node as a book page, complete with navigation. + * Menu callback; prints a node as a book page, complete with navigation. */ function book_view_page($nid = 0, $cid = 0) { $node = node_load(array('nid' => $nid)); @@ -714,7 +714,7 @@ function book_view_page($nid = 0, $cid = 0) { } /** - * Menu callback. Generates printer-friendly book page will all descendants. + * Menu callback; generates printer-friendly book page will all descendants. */ function book_print($nid = 0, $depth = 1) { global $base_url; @@ -845,7 +845,7 @@ function book_admin_save($nid, $edit = array()) { } /** - * Menu callback. Displays a listing of all orphaned book pages. + * Menu callback; displays a listing of all orphaned book pages. */ function book_admin_orphan() { $result = db_query("SELECT n.nid, n.title, n.status, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid"); @@ -870,9 +870,9 @@ function book_admin_orphan() { } /** - * Menu callback. Displays the book administration page. + * Menu callback; displays the book administration page. */ -function book_admin($nid) { +function book_admin($nid = 0) { $op = $_POST["op"]; $edit = $_POST["edit"]; diff --git a/modules/book/book.module b/modules/book/book.module index 7658a9251..f499db81c 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -679,7 +679,7 @@ function book_tree($parent = 0, $depth = 3, $unfold = array()) { } /** - * Menu callback. Prints a listing of all books. + * Menu callback; prints a listing of all books. */ function book_render() { @@ -705,7 +705,7 @@ function book_render() { } /** - * Menu callback. Prints a node as a book page, complete with navigation. + * Menu callback; prints a node as a book page, complete with navigation. */ function book_view_page($nid = 0, $cid = 0) { $node = node_load(array('nid' => $nid)); @@ -714,7 +714,7 @@ function book_view_page($nid = 0, $cid = 0) { } /** - * Menu callback. Generates printer-friendly book page will all descendants. + * Menu callback; generates printer-friendly book page will all descendants. */ function book_print($nid = 0, $depth = 1) { global $base_url; @@ -845,7 +845,7 @@ function book_admin_save($nid, $edit = array()) { } /** - * Menu callback. Displays a listing of all orphaned book pages. + * Menu callback; displays a listing of all orphaned book pages. */ function book_admin_orphan() { $result = db_query("SELECT n.nid, n.title, n.status, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid"); @@ -870,9 +870,9 @@ function book_admin_orphan() { } /** - * Menu callback. Displays the book administration page. + * Menu callback; displays the book administration page. */ -function book_admin($nid) { +function book_admin($nid = 0) { $op = $_POST["op"]; $edit = $_POST["edit"]; diff --git a/modules/drupal.module b/modules/drupal.module index 084fb96d1..526e9aefa 100644 --- a/modules/drupal.module +++ b/modules/drupal.module @@ -1,8 +1,10 @@ <?php // $Id$ -function drupal_help($section = "admin/help#drupal") { - +/** + * Implementation of hook_help(). + */ +function drupal_help($section) { switch ($section) { case 'admin/help#drupal': return t(" @@ -10,62 +12,59 @@ function drupal_help($section = "admin/help#drupal") { <p>Currently, the main application of this feature is the <a href=\"%drupal-sites\">Drupal sites</a> page. By default, fresh Drupal installations can use <a href=\"%Drupal\">drupal.org</a> as their <em>directory server</em> and report their existence. This reporting occurs via scheduled <a href=\"%xml-rpc\">XML-RPC</a> pings.</p> <p>Drupal administrators should simply enable this feature to get listed on the <a href=\"%drupal-sites\">Drupal sites</a> page. Just set your site's name, e-mail address, slogan and mission statement on the <a href=\"%site-admin\">site administration</a> page. Then make sure that the field called <em>Drupal XML-RPC server</em> on the <a href=\"%drupal-settings\">administer » configuration » modules » drupal</a> page is set to %drupal-xml-rpc, and enable this feature using the dropdown directly below.</p> <p>The listing of your site will occur shortly after your site's next <a href=\"%cron-run\">cron run</a>. Note that cron.php should be called using the domain name which you want to have listed at <a href=\"%Drupal\">drupal.org</a>. For example, don't kick off cron by requesting http://127.0.0.1/cron.php. Instead, use a publicly accessible domain name such as http://www.example.com/cron.php.</p> -<p>Also note that your installation need not use drupal.org as its directory server. For example, this feature is perfectly capable of aggregating pings from all of your departmental drupal installations sites within an enterprise.</p>", array("%drupal-sites" => "http://www.drupal.org/sites", "%Drupal" => "http://www.drupal.org", "%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php", "%xml-rpc" => "http://www.xmlrpc.com/", "%site-admin" => url("admin/system"), "%drupal-settings" => url("admin/system/modules/drupal"), "%cron" => url("admin/system/help#cron"))); - break; +<p>Also note that your installation need not use drupal.org as its directory server. For example, this feature is perfectly capable of aggregating pings from all of your departmental drupal installations sites within an enterprise.</p>", array('%drupal-sites' => 'http://www.drupal.org/sites', '%Drupal' => 'http://www.drupal.org', '%drupal-xml-rpc' => 'http://www.drupal.org/xmlrpc.php', '%xml-rpc' => 'http://www.xmlrpc.com/', '%site-admin' => url('admin/system'), '%drupal-settings' => url('admin/system/modules/drupal'), '%cron' => url('admin/system/help#cron'))); case 'admin/system/modules#description': - return t("Lets users log in using a Drupal ID and can notify a central server about your site."); - break; + return t('Lets users log in using a Drupal ID and can notify a central server about your site.'); case 'admin/system/modules/drupal': - return t("Using this your Drupal site can \"call home\" and add itself to the Drupal directory. If you want it to add itself to a different directory server you can change the <a href=\"%xml-rpc-setting\">Drupal XML-RPC server</a> setting -- but the directory server has to be able to handle Drupal XML. To get all your site information listed go to the <a href=\"%site-admin\">site configuration</a> page and set the site name, the e-mail address, the slogan, and the mission statement.", array("%xml-rpc-setting" => url("admin/system/modules/drupal"), "%site-admin" => url("admin/system"))); - break; + return t("Using this your Drupal site can \"call home\" and add itself to the Drupal directory. If you want it to add itself to a different directory server you can change the <a href=\"%xml-rpc-setting\">Drupal XML-RPC server</a> setting -- but the directory server has to be able to handle Drupal XML. To get all your site information listed go to the <a href=\"%site-admin\">site configuration</a> page and set the site name, the e-mail address, the slogan, and the mission statement.", array('%xml-rpc-setting' => url('admin/system/modules/drupal'), '%site-admin' => url('admin/system'))); case 'user/help#drupal': return t("<p><a href=\"%Drupal\">Drupal</a> is the name of the software which 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 login to any Drupal site using a single <strong>Drupal ID</strong>.</p> -<p>So please feel free to login 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>")); - break; +<p>So please feel free to login 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>')); } - - return $output; } +/** + * Implementation of hook_settings(). + */ function drupal_settings() { // Check if all required fields are present for the Drupal directory - if ((variable_get("site_name", "drupal") == "drupal") || (variable_get("site_name", "drupal") == "")) - $error["drupal_directory"] = theme("error", t("You must set your site's name at the <a href=\"%url\">site configuration</a>.", array("%url" => url("admin/system")))); - else if (variable_get("site_mail", ini_get("sendmail_from")) == "") - $error["drupal_directory"] = theme("error", t("You must set your site's e-mail address at the <a href=\"%url\">site configuration</a>.", array("%url" => url("admin/system")))); - else if (variable_get("site_slogan", "") == "") - $error["drupal_directory"] = theme("error", t("You must set your site's slogan at the <a href=\"%url\">site configuration</a>.", array("%url" => url("admin/system")))); - else if (variable_get("site_mission", "") == "") - $error["drupal_directory"] = theme("error", t("You must set your site's mission at the <a href=\"%url\">site configuration</a>.", array("%url" => url("admin/system")))); - - $output = form_textfield(t("Drupal XML-RPC server"), "drupal_server", variable_get("drupal_server", "http://www.drupal.org/xmlrpc.php"), 55, 128, t("The URL of your root Drupal XML-RPC server.")); - $output .= form_radios(t("Drupal directory"), "drupal_directory", variable_get("drupal_directory", 0), array(t("Disabled"), t("Enabled")), t("If enabled, your Drupal site will make itself known to the Drupal directory at 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 get listed on the <a href=\"%drupal-sites\">Drupal sites</a> page. Requires the cron feature to be enabled.", array("%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php")) . $error["drupal_directory"]); + if ((variable_get('site_name', 'drupal') == 'drupal') || (variable_get('site_name', 'drupal') == '')) + $error['drupal_directory'] = theme('error', t("You must set your site's name at the <a href=\"%url\">site configuration</a>.", array('%url' => url('admin/system')))); + else if (variable_get('site_mail', ini_get('sendmail_from')) == '') + $error['drupal_directory'] = theme('error', t("You must set your site's e-mail address at the <a href=\"%url\">site configuration</a>.", array('%url' => url('admin/system')))); + else if (variable_get('site_slogan', '') == '') + $error['drupal_directory'] = theme('error', t("You must set your site's slogan at the <a href=\"%url\">site configuration</a>.", array('%url' => url('admin/system')))); + else if (variable_get('site_mission', '') == '') + $error['drupal_directory'] = theme('error', t("You must set your site's mission at the <a href=\"%url\">site configuration</a>.", array('%url' => url('admin/system')))); + + $output = form_textfield(t('Drupal XML-RPC server'), 'drupal_server', variable_get('drupal_server', 'http://www.drupal.org/xmlrpc.php'), 55, 128, t('The URL of your root Drupal XML-RPC server.')); + $output .= form_radios(t('Drupal directory'), 'drupal_directory', variable_get('drupal_directory', 0), array(t('Disabled'), t('Enabled')), t("If enabled, your Drupal site will make itself known to the Drupal directory at 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 get listed on the <a href=\"%drupal-sites\">Drupal sites</a> page. Requires the cron feature to be enabled.", array('%drupal-xml-rpc' => 'http://www.drupal.org/xmlrpc.php')) . $error['drupal_directory']); return $output; } +/** + * Implementation of hook_cron(); handles pings to and from the site. + */ function drupal_cron() { - if (time() - variable_get("drupal_cron_last", 0) > 21600) { - variable_set("drupal_cron_last", time()); - - /* - ** If this site acts as a Drupal XML-RPC server, delete the sites that - ** stopped sending "ping" messages. - */ + if (time() - variable_get('drupal_cron_last', 0) > 21600) { + variable_set('drupal_cron_last', time()); + // If this site acts as a Drupal XML-RPC server, delete the sites that + // stopped sending "ping" messages. db_query("DELETE FROM {directory} WHERE timestamp < '". (time() - 259200) ."'"); - /* - ** If this site acts as a Drupal XML-RPC client, send a message to the - ** Drupal XML-RPC server. - */ - - if (variable_get("drupal_directory", 0) && variable_get("drupal_server", 0)) { - drupal_notify(variable_get("drupal_server", "")); + // If this site acts as a Drupal XML-RPC client, send a message to the + // Drupal XML-RPC server. + if (variable_get('drupal_directory', 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_directory_ping($arguments) { /* @@ -91,18 +90,24 @@ function drupal_directory_ping($arguments) { db_query("DELETE FROM {directory} WHERE link = '%s' OR mail = '%s'", $link, $mail); db_query("INSERT INTO {directory} (link, name, mail, slogan, mission, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $link, $name, $mail, $slogan, $mission, time()); - watchdog("regular", "directory: ping from '$name' ($link)"); + watchdog('regular', "directory: ping from \"$name\" ($link)"); - return new xmlrpcresp(new xmlrpcval(1, "int")); + return new xmlrpcresp(new xmlrpcval(1, 'int')); } else { - return new xmlrpcresp(new xmlrpcval(0, "int")); + return new xmlrpcresp(new xmlrpcval(0, 'int')); } } +/** + * Formats a list of all sites indexed in the ddirectory. + * + * This function may be called from a custom page on sites that are + * Drupal directory servers. + */ function drupal_directory_page() { - $result = db_query("SELECT * FROM {directory} ORDER BY name"); + $result = db_query('SELECT * FROM {directory} ORDER BY name'); while ($site = db_fetch_object($result)) { $output .= "<a href=\"$site->link\">$site->name</a> - $site->slogan<div style=\"padding-left: 20px;\">$site->mission</div><br />"; @@ -111,30 +116,39 @@ function drupal_directory_page() { return $output; } +/** + * Implementation of hook_xmlrpc(). + */ function drupal_xmlrpc() { - return array("drupal.site.ping" => array("function" => "drupal_directory_ping"), "drupal.login" => array("function" => "drupal_login")); + return array('drupal.site.ping' => array('function' => 'drupal_directory_ping'), 'drupal.login' => array('function' => 'drupal_login')); } +/** + * Sends a ping to the Drupal directory server. + */ function drupal_notify($server) { global $base_url; $url = parse_url($server); - $client = new xmlrpc_client($url["path"], $url["host"], 80); + $client = new xmlrpc_client($url['path'], $url['host'], 80); - $message = new xmlrpcmsg("drupal.site.ping", array(new xmlrpcval($base_url, "string"), new xmlrpcval(variable_get("site_name", ""), "string"), new xmlrpcval(variable_get("site_mail", ""), "string"), new xmlrpcval(variable_get("site_slogan", ""), "string"), new xmlrpcval(variable_get("site_mission", ""), "string"))); + $message = new xmlrpcmsg('drupal.site.ping', array(new xmlrpcval($base_url, 'string'), new xmlrpcval(variable_get('site_name', ''), 'string'), new xmlrpcval(variable_get('site_mail', ''), 'string'), new xmlrpcval(variable_get('site_slogan', ''), 'string'), new xmlrpcval(variable_get('site_mission', ''), 'string'))); $result = $client->send($message, 5); if (!$result || $result->faultCode()) { - watchdog("error", "failed to notify '". $url["host"] ."' at '". $url["path"] ."': ". $result->faultString()); + watchdog('error', 'failed to notify "'. $url['host'] .'" at "'. $url['path'] .'": '. $result->faultString()); } } +/** + * Implementation of hook_info(). + */ function drupal_info($field = 0) { - $info["name"] = "Drupal"; - $info["protocol"] = "XML-RPC"; + $info['name'] = 'Drupal'; + $info['protocol'] = 'XML-RPC'; if ($field) { return $info[$field]; @@ -144,13 +158,16 @@ function drupal_info($field = 0) { } } +/** + * Implementation of hook_auth(). + */ function drupal_auth($username, $password, $server) { - $message = new xmlrpcmsg("drupal.login", array(new xmlrpcval($username, "string"), new xmlrpcval($password, "string"))); + $message = new xmlrpcmsg('drupal.login', array(new xmlrpcval($username, 'string'), new xmlrpcval($password, 'string'))); // TODO remove hard coded Port 80 // TODO manage server/path such that HTTP_HOST/xml.rpc.php is not assumed - $client = new xmlrpc_client("/xmlrpc.php", $server, 80); + $client = new xmlrpc_client('/xmlrpc.php', $server, 80); $result = $client->send($message, 5); if ($result && !$result->faultCode()) { $value = $result->value(); @@ -165,26 +182,33 @@ function drupal_auth($username, $password, $server) { */ function drupal_link($type) { if ($type == 'system') { - menu('drupal', t('Drupal'), 'drupal_page', 0, MENU_HIDE); + menu('drupal', t('Drupal'), 'drupal_page_help', 0, MENU_HIDE); } } -function drupal_page() { - print theme("page", drupal_help("user/help#drupal"), t("Drupal")); +/** + * Menu callback; print Drupal-authentication-specific information from user/help. + */ +function drupal_page_help() { + print theme('page', drupal_help('user/help#drupal'), t('Drupal')); } +/** + * Callback function from drupal_xmlrpc() for authenticating remote clients. + * + * Remote clients are usually other Drupal instances. + */ function drupal_login($arguments) { - // an XML-RPC method called by external clients (usually other Drupal instances) $argument = $arguments->getparam(0); $username = $argument->scalarval(); $argument = $arguments->getparam(1); $password = $argument->scalarval(); - if ($user = user_load(array(name => "$username", "pass" => $password, "status" => 1))) { - return new xmlrpcresp(new xmlrpcval($user->uid, "int")); + if ($user = user_load(array(name => $username, 'pass' => $password, 'status' => 1))) { + return new xmlrpcresp(new xmlrpcval($user->uid, 'int')); } else { - return new xmlrpcresp(new xmlrpcval(0, "int")); + return new xmlrpcresp(new xmlrpcval(0, 'int')); } } diff --git a/modules/drupal/drupal.module b/modules/drupal/drupal.module index 084fb96d1..526e9aefa 100644 --- a/modules/drupal/drupal.module +++ b/modules/drupal/drupal.module @@ -1,8 +1,10 @@ <?php // $Id$ -function drupal_help($section = "admin/help#drupal") { - +/** + * Implementation of hook_help(). + */ +function drupal_help($section) { switch ($section) { case 'admin/help#drupal': return t(" @@ -10,62 +12,59 @@ function drupal_help($section = "admin/help#drupal") { <p>Currently, the main application of this feature is the <a href=\"%drupal-sites\">Drupal sites</a> page. By default, fresh Drupal installations can use <a href=\"%Drupal\">drupal.org</a> as their <em>directory server</em> and report their existence. This reporting occurs via scheduled <a href=\"%xml-rpc\">XML-RPC</a> pings.</p> <p>Drupal administrators should simply enable this feature to get listed on the <a href=\"%drupal-sites\">Drupal sites</a> page. Just set your site's name, e-mail address, slogan and mission statement on the <a href=\"%site-admin\">site administration</a> page. Then make sure that the field called <em>Drupal XML-RPC server</em> on the <a href=\"%drupal-settings\">administer » configuration » modules » drupal</a> page is set to %drupal-xml-rpc, and enable this feature using the dropdown directly below.</p> <p>The listing of your site will occur shortly after your site's next <a href=\"%cron-run\">cron run</a>. Note that cron.php should be called using the domain name which you want to have listed at <a href=\"%Drupal\">drupal.org</a>. For example, don't kick off cron by requesting http://127.0.0.1/cron.php. Instead, use a publicly accessible domain name such as http://www.example.com/cron.php.</p> -<p>Also note that your installation need not use drupal.org as its directory server. For example, this feature is perfectly capable of aggregating pings from all of your departmental drupal installations sites within an enterprise.</p>", array("%drupal-sites" => "http://www.drupal.org/sites", "%Drupal" => "http://www.drupal.org", "%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php", "%xml-rpc" => "http://www.xmlrpc.com/", "%site-admin" => url("admin/system"), "%drupal-settings" => url("admin/system/modules/drupal"), "%cron" => url("admin/system/help#cron"))); - break; +<p>Also note that your installation need not use drupal.org as its directory server. For example, this feature is perfectly capable of aggregating pings from all of your departmental drupal installations sites within an enterprise.</p>", array('%drupal-sites' => 'http://www.drupal.org/sites', '%Drupal' => 'http://www.drupal.org', '%drupal-xml-rpc' => 'http://www.drupal.org/xmlrpc.php', '%xml-rpc' => 'http://www.xmlrpc.com/', '%site-admin' => url('admin/system'), '%drupal-settings' => url('admin/system/modules/drupal'), '%cron' => url('admin/system/help#cron'))); case 'admin/system/modules#description': - return t("Lets users log in using a Drupal ID and can notify a central server about your site."); - break; + return t('Lets users log in using a Drupal ID and can notify a central server about your site.'); case 'admin/system/modules/drupal': - return t("Using this your Drupal site can \"call home\" and add itself to the Drupal directory. If you want it to add itself to a different directory server you can change the <a href=\"%xml-rpc-setting\">Drupal XML-RPC server</a> setting -- but the directory server has to be able to handle Drupal XML. To get all your site information listed go to the <a href=\"%site-admin\">site configuration</a> page and set the site name, the e-mail address, the slogan, and the mission statement.", array("%xml-rpc-setting" => url("admin/system/modules/drupal"), "%site-admin" => url("admin/system"))); - break; + return t("Using this your Drupal site can \"call home\" and add itself to the Drupal directory. If you want it to add itself to a different directory server you can change the <a href=\"%xml-rpc-setting\">Drupal XML-RPC server</a> setting -- but the directory server has to be able to handle Drupal XML. To get all your site information listed go to the <a href=\"%site-admin\">site configuration</a> page and set the site name, the e-mail address, the slogan, and the mission statement.", array('%xml-rpc-setting' => url('admin/system/modules/drupal'), '%site-admin' => url('admin/system'))); case 'user/help#drupal': return t("<p><a href=\"%Drupal\">Drupal</a> is the name of the software which 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 login to any Drupal site using a single <strong>Drupal ID</strong>.</p> -<p>So please feel free to login 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>")); - break; +<p>So please feel free to login 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>')); } - - return $output; } +/** + * Implementation of hook_settings(). + */ function drupal_settings() { // Check if all required fields are present for the Drupal directory - if ((variable_get("site_name", "drupal") == "drupal") || (variable_get("site_name", "drupal") == "")) - $error["drupal_directory"] = theme("error", t("You must set your site's name at the <a href=\"%url\">site configuration</a>.", array("%url" => url("admin/system")))); - else if (variable_get("site_mail", ini_get("sendmail_from")) == "") - $error["drupal_directory"] = theme("error", t("You must set your site's e-mail address at the <a href=\"%url\">site configuration</a>.", array("%url" => url("admin/system")))); - else if (variable_get("site_slogan", "") == "") - $error["drupal_directory"] = theme("error", t("You must set your site's slogan at the <a href=\"%url\">site configuration</a>.", array("%url" => url("admin/system")))); - else if (variable_get("site_mission", "") == "") - $error["drupal_directory"] = theme("error", t("You must set your site's mission at the <a href=\"%url\">site configuration</a>.", array("%url" => url("admin/system")))); - - $output = form_textfield(t("Drupal XML-RPC server"), "drupal_server", variable_get("drupal_server", "http://www.drupal.org/xmlrpc.php"), 55, 128, t("The URL of your root Drupal XML-RPC server.")); - $output .= form_radios(t("Drupal directory"), "drupal_directory", variable_get("drupal_directory", 0), array(t("Disabled"), t("Enabled")), t("If enabled, your Drupal site will make itself known to the Drupal directory at 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 get listed on the <a href=\"%drupal-sites\">Drupal sites</a> page. Requires the cron feature to be enabled.", array("%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php")) . $error["drupal_directory"]); + if ((variable_get('site_name', 'drupal') == 'drupal') || (variable_get('site_name', 'drupal') == '')) + $error['drupal_directory'] = theme('error', t("You must set your site's name at the <a href=\"%url\">site configuration</a>.", array('%url' => url('admin/system')))); + else if (variable_get('site_mail', ini_get('sendmail_from')) == '') + $error['drupal_directory'] = theme('error', t("You must set your site's e-mail address at the <a href=\"%url\">site configuration</a>.", array('%url' => url('admin/system')))); + else if (variable_get('site_slogan', '') == '') + $error['drupal_directory'] = theme('error', t("You must set your site's slogan at the <a href=\"%url\">site configuration</a>.", array('%url' => url('admin/system')))); + else if (variable_get('site_mission', '') == '') + $error['drupal_directory'] = theme('error', t("You must set your site's mission at the <a href=\"%url\">site configuration</a>.", array('%url' => url('admin/system')))); + + $output = form_textfield(t('Drupal XML-RPC server'), 'drupal_server', variable_get('drupal_server', 'http://www.drupal.org/xmlrpc.php'), 55, 128, t('The URL of your root Drupal XML-RPC server.')); + $output .= form_radios(t('Drupal directory'), 'drupal_directory', variable_get('drupal_directory', 0), array(t('Disabled'), t('Enabled')), t("If enabled, your Drupal site will make itself known to the Drupal directory at 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 get listed on the <a href=\"%drupal-sites\">Drupal sites</a> page. Requires the cron feature to be enabled.", array('%drupal-xml-rpc' => 'http://www.drupal.org/xmlrpc.php')) . $error['drupal_directory']); return $output; } +/** + * Implementation of hook_cron(); handles pings to and from the site. + */ function drupal_cron() { - if (time() - variable_get("drupal_cron_last", 0) > 21600) { - variable_set("drupal_cron_last", time()); - - /* - ** If this site acts as a Drupal XML-RPC server, delete the sites that - ** stopped sending "ping" messages. - */ + if (time() - variable_get('drupal_cron_last', 0) > 21600) { + variable_set('drupal_cron_last', time()); + // If this site acts as a Drupal XML-RPC server, delete the sites that + // stopped sending "ping" messages. db_query("DELETE FROM {directory} WHERE timestamp < '". (time() - 259200) ."'"); - /* - ** If this site acts as a Drupal XML-RPC client, send a message to the - ** Drupal XML-RPC server. - */ - - if (variable_get("drupal_directory", 0) && variable_get("drupal_server", 0)) { - drupal_notify(variable_get("drupal_server", "")); + // If this site acts as a Drupal XML-RPC client, send a message to the + // Drupal XML-RPC server. + if (variable_get('drupal_directory', 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_directory_ping($arguments) { /* @@ -91,18 +90,24 @@ function drupal_directory_ping($arguments) { db_query("DELETE FROM {directory} WHERE link = '%s' OR mail = '%s'", $link, $mail); db_query("INSERT INTO {directory} (link, name, mail, slogan, mission, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $link, $name, $mail, $slogan, $mission, time()); - watchdog("regular", "directory: ping from '$name' ($link)"); + watchdog('regular', "directory: ping from \"$name\" ($link)"); - return new xmlrpcresp(new xmlrpcval(1, "int")); + return new xmlrpcresp(new xmlrpcval(1, 'int')); } else { - return new xmlrpcresp(new xmlrpcval(0, "int")); + return new xmlrpcresp(new xmlrpcval(0, 'int')); } } +/** + * Formats a list of all sites indexed in the ddirectory. + * + * This function may be called from a custom page on sites that are + * Drupal directory servers. + */ function drupal_directory_page() { - $result = db_query("SELECT * FROM {directory} ORDER BY name"); + $result = db_query('SELECT * FROM {directory} ORDER BY name'); while ($site = db_fetch_object($result)) { $output .= "<a href=\"$site->link\">$site->name</a> - $site->slogan<div style=\"padding-left: 20px;\">$site->mission</div><br />"; @@ -111,30 +116,39 @@ function drupal_directory_page() { return $output; } +/** + * Implementation of hook_xmlrpc(). + */ function drupal_xmlrpc() { - return array("drupal.site.ping" => array("function" => "drupal_directory_ping"), "drupal.login" => array("function" => "drupal_login")); + return array('drupal.site.ping' => array('function' => 'drupal_directory_ping'), 'drupal.login' => array('function' => 'drupal_login')); } +/** + * Sends a ping to the Drupal directory server. + */ function drupal_notify($server) { global $base_url; $url = parse_url($server); - $client = new xmlrpc_client($url["path"], $url["host"], 80); + $client = new xmlrpc_client($url['path'], $url['host'], 80); - $message = new xmlrpcmsg("drupal.site.ping", array(new xmlrpcval($base_url, "string"), new xmlrpcval(variable_get("site_name", ""), "string"), new xmlrpcval(variable_get("site_mail", ""), "string"), new xmlrpcval(variable_get("site_slogan", ""), "string"), new xmlrpcval(variable_get("site_mission", ""), "string"))); + $message = new xmlrpcmsg('drupal.site.ping', array(new xmlrpcval($base_url, 'string'), new xmlrpcval(variable_get('site_name', ''), 'string'), new xmlrpcval(variable_get('site_mail', ''), 'string'), new xmlrpcval(variable_get('site_slogan', ''), 'string'), new xmlrpcval(variable_get('site_mission', ''), 'string'))); $result = $client->send($message, 5); if (!$result || $result->faultCode()) { - watchdog("error", "failed to notify '". $url["host"] ."' at '". $url["path"] ."': ". $result->faultString()); + watchdog('error', 'failed to notify "'. $url['host'] .'" at "'. $url['path'] .'": '. $result->faultString()); } } +/** + * Implementation of hook_info(). + */ function drupal_info($field = 0) { - $info["name"] = "Drupal"; - $info["protocol"] = "XML-RPC"; + $info['name'] = 'Drupal'; + $info['protocol'] = 'XML-RPC'; if ($field) { return $info[$field]; @@ -144,13 +158,16 @@ function drupal_info($field = 0) { } } +/** + * Implementation of hook_auth(). + */ function drupal_auth($username, $password, $server) { - $message = new xmlrpcmsg("drupal.login", array(new xmlrpcval($username, "string"), new xmlrpcval($password, "string"))); + $message = new xmlrpcmsg('drupal.login', array(new xmlrpcval($username, 'string'), new xmlrpcval($password, 'string'))); // TODO remove hard coded Port 80 // TODO manage server/path such that HTTP_HOST/xml.rpc.php is not assumed - $client = new xmlrpc_client("/xmlrpc.php", $server, 80); + $client = new xmlrpc_client('/xmlrpc.php', $server, 80); $result = $client->send($message, 5); if ($result && !$result->faultCode()) { $value = $result->value(); @@ -165,26 +182,33 @@ function drupal_auth($username, $password, $server) { */ function drupal_link($type) { if ($type == 'system') { - menu('drupal', t('Drupal'), 'drupal_page', 0, MENU_HIDE); + menu('drupal', t('Drupal'), 'drupal_page_help', 0, MENU_HIDE); } } -function drupal_page() { - print theme("page", drupal_help("user/help#drupal"), t("Drupal")); +/** + * Menu callback; print Drupal-authentication-specific information from user/help. + */ +function drupal_page_help() { + print theme('page', drupal_help('user/help#drupal'), t('Drupal')); } +/** + * Callback function from drupal_xmlrpc() for authenticating remote clients. + * + * Remote clients are usually other Drupal instances. + */ function drupal_login($arguments) { - // an XML-RPC method called by external clients (usually other Drupal instances) $argument = $arguments->getparam(0); $username = $argument->scalarval(); $argument = $arguments->getparam(1); $password = $argument->scalarval(); - if ($user = user_load(array(name => "$username", "pass" => $password, "status" => 1))) { - return new xmlrpcresp(new xmlrpcval($user->uid, "int")); + if ($user = user_load(array(name => $username, 'pass' => $password, 'status' => 1))) { + return new xmlrpcresp(new xmlrpcval($user->uid, 'int')); } else { - return new xmlrpcresp(new xmlrpcval(0, "int")); + return new xmlrpcresp(new xmlrpcval(0, 'int')); } } diff --git a/modules/filter.module b/modules/filter.module index 7d32bb3d1..0221d35e7 100644 --- a/modules/filter.module +++ b/modules/filter.module @@ -8,33 +8,36 @@ define('FILTER_HTML_ESCAPE', 2); define('FILTER_STYLE_ALLOW', 0); define('FILTER_STYLE_STRIP', 1); -function filter_help($section = "admin/help#filter") { +/** + * Implementation of hook_help(). + */ +function filter_help($section) { switch ($section) { case 'admin/system/modules#description': - return t("Framework for handling filtering of content."); + return t('Framework for handling filtering of content.'); case 'admin/system/filters': return t(" <p>Filters fit between the raw text in a node and the HTML output. They allow you to replace text selectively. Uses include automatic conversion of emoticons into graphics and filtering HTML content from users' submissions.</p> -<p>If you notice some filters are causing conflicts in the output, you can <a href=\"%url\">rearrange them</a>.</p>", array("%url" => url("admin/system/filters/order"))); +<p>If you notice some filters are causing conflicts in the output, you can <a href=\"%url\">rearrange them</a>.</p>", array('%url' => url('admin/system/filters/order'))); case 'admin/system/filters/order': return t(" <p>Because of the flexible filtering system, you might encounter a situation where one filter prevents another from doing its job. For example: a word in an URL gets converted into a glossary term, before the URL can be converted in a clickable link. When this happens, you will need to rearrange the order in which filters get executed.</p> <p>Filters are executed from top-to-bottom. You can use the weight column to rearrange them: heavier filters 'sink' to the bottom. Standard HTML filtering is always run first.</p>"); case 'filter#long-tip': case 'filter#short-tip': - switch (variable_get("filter_html", FILTER_HTML_DONOTHING)) { + switch (variable_get('filter_html', FILTER_HTML_DONOTHING)) { case 0: - return t("All HTML tags allowed"); + return t('All HTML tags allowed'); break; case 1: - if ($allowed_html = variable_get("allowed_html", "<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>")) { - return t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html); + if ($allowed_html = variable_get('allowed_html', '<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>')) { + return t('Allowed HTML tags') .': '. htmlspecialchars($allowed_html); } else { - return t("No HTML tags allowed"); + return t('No HTML tags allowed'); } break; case 2: - return t("No HTML tags allowed"); + return t('No HTML tags allowed'); break; } break; @@ -46,18 +49,21 @@ function filter_help($section = "admin/help#filter") { */ function filter_link($type) { if ($type == 'system') { - menu('admin/system/filters', t('filters'), user_access('administer site configuration') ? 'filter_admin' : MENU_DENIED, 5); - menu('admin/system/filters/order', t('ordering'), user_access('administer site configuration') ? 'filter_admin' : MENU_DENIED, 5); + menu('admin/system/filters', t('filters'), user_access('administer site configuration') ? 'filter_admin_settings' : MENU_DENIED, 5); + menu('admin/system/filters/order', t('ordering'), user_access('administer site configuration') ? 'filter_admin_order' : MENU_DENIED, 5); menu('filter/tips', t('compose tips'), 'filter_tips_long', 0, MENU_HIDE); } } +/** + * Menu callback; allows administrators to change the filter ordering. + */ function filter_admin_order() { - $edit = $_POST["edit"]; - $op = $_POST["op"]; - if ($op == t("Save configuration")) { + $edit = $_POST['edit']; + $op = $_POST['op']; + if ($op == t('Save configuration')) { foreach ($edit as $module => $filter) { - db_query("UPDATE {filters} SET weight = %d WHERE module = '%s'", $filter["weight"], $module); + db_query("UPDATE {filters} SET weight = %d WHERE module = '%s'", $filter['weight'], $module); } } @@ -69,53 +75,47 @@ function filter_admin_order() { $rows = array(); // Standard HTML filters are always run first, we add a dummy row to indicate this - $rows[] = array(t("HTML filtering"), array("data" => t("locked"))); + $rows[] = array(t('HTML filtering'), array('data' => t('locked'))); foreach ($filters as $module => $filter) { - $name = module_invoke($module, "filter", "name"); - $rows[] = array($name, array("data" => form_weight(NULL, $module ."][weight", $filter["weight"]))); + $name = module_invoke($module, 'filter', 'name'); + $rows[] = array($name, array('data' => form_weight(NULL, $module .'][weight', $filter['weight']))); } - $form = theme("table", $header, $rows); - $form .= form_submit(t("Save configuration")); + $form = theme('table', $header, $rows); + $form .= form_submit(t('Save configuration')); $output = form($form); - return $output; + print theme('page', $output); } +/** + * Menu callback; displays settings defined by filters. + */ function filter_admin_settings() { system_settings_save(); filter_refresh(); $form = filter_default_settings(); - $form .= implode("\n", module_invoke_all("filter", "settings")); + $form .= implode("\n", module_invoke_all('filter', 'settings')); $output = system_settings_form($form); - return $output; -} - -function filter_admin() { - switch (arg(3)) { - case "order": - $output = filter_admin_order(); - break; - default: - $output = filter_admin_settings(); - break; - } - print theme("page", $output); + print theme('page', $output); } +/** + * Search through all modules for the filters they implement. + */ function filter_refresh() { $modules = module_list(); $filters = filter_list(); // Update list in database - db_query("DELETE FROM {filters}"); + db_query('DELETE FROM {filters}'); foreach ($modules as $module) { - if (module_hook($module, "filter")) { - $weight = $filters[$module]["weight"]; + if (module_hook($module, 'filter')) { + $weight = $filters[$module]['weight']; db_query("INSERT INTO {filters} (module, weight) VALUES ('%s', %d)", $module, $weight); } @@ -124,16 +124,19 @@ function filter_refresh() { filter_list(1); } +/** + * Retrieve a list of all filters from the database. + */ function filter_list($force = 0) { static $filters; if (!is_array($filters) || $force) { $filters = array(); - $result = db_query("SELECT * FROM {filters} ORDER BY weight ASC"); + $result = db_query('SELECT * FROM {filters} ORDER BY weight ASC'); while ($filter = db_fetch_array($result)) { // Fail-safe in case a module was deleted/changed without disabling it - if (module_hook($filter["module"], "filter")) { - $filters[$filter["module"]] = $filter; + if (module_hook($filter['module'], 'filter')) { + $filters[$filter['module']] = $filter; } } } @@ -141,31 +144,31 @@ function filter_list($force = 0) { return $filters; } +/** + * Run all the enabled filters on a piece of text. + */ function check_output($text) { if (isset($text)) { - // Filter content on output: $filters = filter_list(); - // Give filters the chance to escape HTML-like data such as code or formulas - // (from this point on, the input can be treated as HTML) - if (variable_get("filter_html", FILTER_HTML_DONOTHING) != FILTER_HTML_ESCAPE) { + // Give filters the chance to escape HTML-like data such as code or formulas. + // From this point on, the input can be treated as HTML. + if (variable_get('filter_html', FILTER_HTML_DONOTHING) != FILTER_HTML_ESCAPE) { foreach ($filters as $module => $filter) { - $text = module_invoke($module, "filter", "prepare", $text); + $text = module_invoke($module, 'filter', 'prepare', $text); } } - // HTML handling is done before all regular filtering activities + // HTML handling is done before all regular filtering activities. $text = filter_default($text); - // Regular filtering + // Regular filtering. foreach ($filters as $module => $filter) { - $text = module_invoke($module, "filter", "process", $text); + $text = module_invoke($module, 'filter', 'process', $text); } - /* - ** If only inline elements are used and no block level elements, we - ** replace all newlines with HTML line breaks. - */ + // If only inline elements are used and no block level elements, we + // replace all newlines with HTML line breaks. if (strip_tags($text, '<a><br><span><bdo><map><object><img><tt><i><b><u><big><small><em><strong><dfn><code><q><samp><kbd><var><cite><abbr><acronym><sub><sup><input><select><textarea><label><button><ins><del><script>') == $text) { $text = nl2br($text); } @@ -177,17 +180,20 @@ function check_output($text) { return $text; } +/** + * Perform the default filters, preventing malicious HTML from being displayed. + */ function filter_default($text) { - if (variable_get("filter_html", FILTER_HTML_DONOTHING) == FILTER_HTML_STRIP) { + if (variable_get('filter_html', FILTER_HTML_DONOTHING) == FILTER_HTML_STRIP) { // Allow users to enter HTML, but filter it - $text = strip_tags($text, variable_get("allowed_html", "")); - if (variable_get("filter_style", FILTER_STYLE_STRIP)) { - $text = preg_replace("/\Wstyle\s*=[^>]+?>/i", ">", $text); + $text = strip_tags($text, variable_get('allowed_html', '')); + if (variable_get('filter_style', FILTER_STYLE_STRIP)) { + $text = preg_replace('/\Wstyle\s*=[^>]+?>/i', '>', $text); } - $text = preg_replace("/\Won[a-z]+\s*=[^>]+?>/i", ">", $text); + $text = preg_replace('/\Won[a-z]+\s*=[^>]+?>/i', '>', $text); } - if (variable_get("filter_html", FILTER_HTML_DONOTHING) == FILTER_HTML_ESCAPE) { + if (variable_get('filter_html', FILTER_HTML_DONOTHING) == FILTER_HTML_ESCAPE) { // Escape HTML $text = htmlspecialchars($text); } @@ -195,50 +201,55 @@ function filter_default($text) { return trim($text); } +/** + * Settings for the filter system's built-in HTML handling. + */ function filter_default_settings() { - $group = form_radios(t("Filter HTML tags"), "filter_html", variable_get("filter_html", FILTER_HTML_DONOTHING), array(FILTER_HTML_DONOTHING => t("Do not filter"), FILTER_HTML_STRIP => t("Strip tags"), FILTER_HTML_ESCAPE => t("Escape tags")), t("How to deal with HTML and PHP tags in user-contributed content. If set to \"Strip tags\", dangerous tags are removed (see below). If set to \"Escape tags\", all HTML is escaped and presented as it was typed.")); - $group .= form_textfield(t("Allowed HTML tags"), "allowed_html", variable_get("allowed_html", "<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>"), 64, 255, t("If \"Strip tags\" is selected, optionally specify tags which should not be stripped. 'ON*' attributes are always stripped.")); - $group .= form_radios(t("HTML style attributes"), "filter_style", variable_get("filter_style", FILTER_STYLE_STRIP), array(FILTER_STYLE_ALLOW => t("Allowed"), FILTER_STYLE_STRIP => t("Removed")), t("If \"Strip tags\" is selected, you can choose whether 'STYLE' attributes are allowed or removed from input.")); - $output .= form_group(t("HTML filtering"), $group); + $group = form_radios(t('Filter HTML tags'), 'filter_html', variable_get('filter_html', FILTER_HTML_DONOTHING), array(FILTER_HTML_DONOTHING => t('Do not filter'), FILTER_HTML_STRIP => t('Strip tags'), FILTER_HTML_ESCAPE => t('Escape tags')), t('How to deal with HTML and PHP tags in user-contributed content. If set to "Strip tags", dangerous tags are removed (see below). If set to "Escape tags", all HTML is escaped and presented as it was typed.')); + $group .= form_textfield(t('Allowed HTML tags'), 'allowed_html', variable_get('allowed_html', '<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>'), 64, 255, t('If "Strip tags" is selected, optionally specify tags which should not be stripped. "ON*" attributes are always stripped.')); + $group .= form_radios(t('HTML style attributes'), 'filter_style', variable_get('filter_style', FILTER_STYLE_STRIP), array(FILTER_STYLE_ALLOW => t('Allowed'), FILTER_STYLE_STRIP => t('Removed')), t('If "Strip tags" is selected, you can choose whether "STYLE" attributes are allowed or removed from input.')); + $output .= form_group(t('HTML filtering'), $group); return $output; } -function filter_filter($op, $text = "") { +/** + * Implementation of hook_filter(). Handles URL upgrades from Drupal 4.1. + */ +function filter_filter($op, $text = '') { switch ($op) { - case "name": - return t("Legacy filtering"); - case "process": - if (variable_get("rewrite_old_urls", 0)) { + case 'name': + return t('Legacy filtering'); + case 'process': + if (variable_get('rewrite_old_urls', 0)) { $text = filter_old_urls($text); } return $text; - case "settings": - $group = form_radios(t("Rewrite old URLs"), "rewrite_old_urls", variable_get("rewrite_old_urls", 0), array(t("Disabled"), t("Enabled")), t("The introduction of 'clean URLs' in Drupal 4.2.0 breaks internal URLs that date back from Drupal 4.1.0 and before. If enabled, this filter will attempt to rewrite the old style URLs to avoid broken links. If <code>mod_rewrite</code> is available on your system, use the rewrite rules in Drupal's <code>.htaccess</code> file instead as these will also correct external referrers.")); - $output .= form_group(t("Legacy filtering"), $group); + case 'settings': + $group = form_radios(t('Rewrite old URLs'), 'rewrite_old_urls', variable_get('rewrite_old_urls', 0), array(t('Disabled'), t('Enabled')), t('The introduction of "clean URLs" in Drupal 4.2.0 breaks internal URLs that date back from Drupal 4.1.0 and before. If enabled, this filter will attempt to rewrite the old style URLs to avoid broken links. If <code>mod_rewrite</code> is available on your system, use the rewrite rules in Drupal\'s <code>.htaccess</code> file instead as these will also correct external referrers.')); + $output .= form_group(t('Legacy filtering'), $group); return $output; default: return $text; } } +/** + * Rewrite legacy URLs. + * + * This is a *temporary* filter to rewrite old-style URLs to new-style + * URLs (clean URLs). Currently, URLs are being rewritten dynamically + * (ie. "on output"), however when these rewrite rules have been tested + * enough, we will use them to permanently rewrite the links in node + * and comment bodies. + */ function filter_old_urls($text) { global $base_url; $end = substr($base_url, 12); - /* - ** This is a *temporary* filter to rewrite old-style URLs to new-style - ** URLs (clean URLs). Currently, URLs are being rewritten dynamically - ** (ie. "on output"), however when these rewrite rules have been tested - ** enough, we will use them to permanently rewrite the links in node - ** and comment bodies. - */ - - if (variable_get("clean_url", "0") == "0") { - /* - ** Relative URLs: - */ + if (variable_get('clean_url', '0') == '0') { + // Relative URLs: // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"?q=\\1/view/\\2/\\4", $text); @@ -248,9 +259,7 @@ function filter_old_urls($text) { $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4", $text); $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2", $text); - /* - ** Absolute URLs: - */ + // Absolute URLs: // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/?q=\\1/view/\\2/\\4", $text); @@ -261,9 +270,7 @@ function filter_old_urls($text) { $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"$end/?q=\\2", $text); } else { - /* - ** Relative URLs: - */ + // Relative URLs: // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"\\1/view/\\2/\\4", $text); @@ -273,9 +280,7 @@ function filter_old_urls($text) { $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4", $text); $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2", $text); - /* - ** Absolute URLs: - */ + // Absolute URLs: // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/\\1/view/\\2/\\4", $text); @@ -289,6 +294,9 @@ function filter_old_urls($text) { return $text; } +/** + * Fetch full filter help texts defined by modules. + */ function filter_tips_long() { $tiplist = ''; foreach (module_list() as $name) { @@ -297,9 +305,12 @@ function filter_tips_long() { } } $output = "<ul class=\"filter-tips-long\">\n$tiplist\n</ul>\n"; - print theme("page", $output, t('Compose Tips')); + print theme('page', $output, t('Compose Tips')); } +/** + * Fetch abbreviated filter help texts defined by modules. + */ function filter_tips_short() { $tiplist = ''; foreach (module_list() as $name) { diff --git a/modules/filter/filter.module b/modules/filter/filter.module index 7d32bb3d1..0221d35e7 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -8,33 +8,36 @@ define('FILTER_HTML_ESCAPE', 2); define('FILTER_STYLE_ALLOW', 0); define('FILTER_STYLE_STRIP', 1); -function filter_help($section = "admin/help#filter") { +/** + * Implementation of hook_help(). + */ +function filter_help($section) { switch ($section) { case 'admin/system/modules#description': - return t("Framework for handling filtering of content."); + return t('Framework for handling filtering of content.'); case 'admin/system/filters': return t(" <p>Filters fit between the raw text in a node and the HTML output. They allow you to replace text selectively. Uses include automatic conversion of emoticons into graphics and filtering HTML content from users' submissions.</p> -<p>If you notice some filters are causing conflicts in the output, you can <a href=\"%url\">rearrange them</a>.</p>", array("%url" => url("admin/system/filters/order"))); +<p>If you notice some filters are causing conflicts in the output, you can <a href=\"%url\">rearrange them</a>.</p>", array('%url' => url('admin/system/filters/order'))); case 'admin/system/filters/order': return t(" <p>Because of the flexible filtering system, you might encounter a situation where one filter prevents another from doing its job. For example: a word in an URL gets converted into a glossary term, before the URL can be converted in a clickable link. When this happens, you will need to rearrange the order in which filters get executed.</p> <p>Filters are executed from top-to-bottom. You can use the weight column to rearrange them: heavier filters 'sink' to the bottom. Standard HTML filtering is always run first.</p>"); case 'filter#long-tip': case 'filter#short-tip': - switch (variable_get("filter_html", FILTER_HTML_DONOTHING)) { + switch (variable_get('filter_html', FILTER_HTML_DONOTHING)) { case 0: - return t("All HTML tags allowed"); + return t('All HTML tags allowed'); break; case 1: - if ($allowed_html = variable_get("allowed_html", "<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>")) { - return t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html); + if ($allowed_html = variable_get('allowed_html', '<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>')) { + return t('Allowed HTML tags') .': '. htmlspecialchars($allowed_html); } else { - return t("No HTML tags allowed"); + return t('No HTML tags allowed'); } break; case 2: - return t("No HTML tags allowed"); + return t('No HTML tags allowed'); break; } break; @@ -46,18 +49,21 @@ function filter_help($section = "admin/help#filter") { */ function filter_link($type) { if ($type == 'system') { - menu('admin/system/filters', t('filters'), user_access('administer site configuration') ? 'filter_admin' : MENU_DENIED, 5); - menu('admin/system/filters/order', t('ordering'), user_access('administer site configuration') ? 'filter_admin' : MENU_DENIED, 5); + menu('admin/system/filters', t('filters'), user_access('administer site configuration') ? 'filter_admin_settings' : MENU_DENIED, 5); + menu('admin/system/filters/order', t('ordering'), user_access('administer site configuration') ? 'filter_admin_order' : MENU_DENIED, 5); menu('filter/tips', t('compose tips'), 'filter_tips_long', 0, MENU_HIDE); } } +/** + * Menu callback; allows administrators to change the filter ordering. + */ function filter_admin_order() { - $edit = $_POST["edit"]; - $op = $_POST["op"]; - if ($op == t("Save configuration")) { + $edit = $_POST['edit']; + $op = $_POST['op']; + if ($op == t('Save configuration')) { foreach ($edit as $module => $filter) { - db_query("UPDATE {filters} SET weight = %d WHERE module = '%s'", $filter["weight"], $module); + db_query("UPDATE {filters} SET weight = %d WHERE module = '%s'", $filter['weight'], $module); } } @@ -69,53 +75,47 @@ function filter_admin_order() { $rows = array(); // Standard HTML filters are always run first, we add a dummy row to indicate this - $rows[] = array(t("HTML filtering"), array("data" => t("locked"))); + $rows[] = array(t('HTML filtering'), array('data' => t('locked'))); foreach ($filters as $module => $filter) { - $name = module_invoke($module, "filter", "name"); - $rows[] = array($name, array("data" => form_weight(NULL, $module ."][weight", $filter["weight"]))); + $name = module_invoke($module, 'filter', 'name'); + $rows[] = array($name, array('data' => form_weight(NULL, $module .'][weight', $filter['weight']))); } - $form = theme("table", $header, $rows); - $form .= form_submit(t("Save configuration")); + $form = theme('table', $header, $rows); + $form .= form_submit(t('Save configuration')); $output = form($form); - return $output; + print theme('page', $output); } +/** + * Menu callback; displays settings defined by filters. + */ function filter_admin_settings() { system_settings_save(); filter_refresh(); $form = filter_default_settings(); - $form .= implode("\n", module_invoke_all("filter", "settings")); + $form .= implode("\n", module_invoke_all('filter', 'settings')); $output = system_settings_form($form); - return $output; -} - -function filter_admin() { - switch (arg(3)) { - case "order": - $output = filter_admin_order(); - break; - default: - $output = filter_admin_settings(); - break; - } - print theme("page", $output); + print theme('page', $output); } +/** + * Search through all modules for the filters they implement. + */ function filter_refresh() { $modules = module_list(); $filters = filter_list(); // Update list in database - db_query("DELETE FROM {filters}"); + db_query('DELETE FROM {filters}'); foreach ($modules as $module) { - if (module_hook($module, "filter")) { - $weight = $filters[$module]["weight"]; + if (module_hook($module, 'filter')) { + $weight = $filters[$module]['weight']; db_query("INSERT INTO {filters} (module, weight) VALUES ('%s', %d)", $module, $weight); } @@ -124,16 +124,19 @@ function filter_refresh() { filter_list(1); } +/** + * Retrieve a list of all filters from the database. + */ function filter_list($force = 0) { static $filters; if (!is_array($filters) || $force) { $filters = array(); - $result = db_query("SELECT * FROM {filters} ORDER BY weight ASC"); + $result = db_query('SELECT * FROM {filters} ORDER BY weight ASC'); while ($filter = db_fetch_array($result)) { // Fail-safe in case a module was deleted/changed without disabling it - if (module_hook($filter["module"], "filter")) { - $filters[$filter["module"]] = $filter; + if (module_hook($filter['module'], 'filter')) { + $filters[$filter['module']] = $filter; } } } @@ -141,31 +144,31 @@ function filter_list($force = 0) { return $filters; } +/** + * Run all the enabled filters on a piece of text. + */ function check_output($text) { if (isset($text)) { - // Filter content on output: $filters = filter_list(); - // Give filters the chance to escape HTML-like data such as code or formulas - // (from this point on, the input can be treated as HTML) - if (variable_get("filter_html", FILTER_HTML_DONOTHING) != FILTER_HTML_ESCAPE) { + // Give filters the chance to escape HTML-like data such as code or formulas. + // From this point on, the input can be treated as HTML. + if (variable_get('filter_html', FILTER_HTML_DONOTHING) != FILTER_HTML_ESCAPE) { foreach ($filters as $module => $filter) { - $text = module_invoke($module, "filter", "prepare", $text); + $text = module_invoke($module, 'filter', 'prepare', $text); } } - // HTML handling is done before all regular filtering activities + // HTML handling is done before all regular filtering activities. $text = filter_default($text); - // Regular filtering + // Regular filtering. foreach ($filters as $module => $filter) { - $text = module_invoke($module, "filter", "process", $text); + $text = module_invoke($module, 'filter', 'process', $text); } - /* - ** If only inline elements are used and no block level elements, we - ** replace all newlines with HTML line breaks. - */ + // If only inline elements are used and no block level elements, we + // replace all newlines with HTML line breaks. if (strip_tags($text, '<a><br><span><bdo><map><object><img><tt><i><b><u><big><small><em><strong><dfn><code><q><samp><kbd><var><cite><abbr><acronym><sub><sup><input><select><textarea><label><button><ins><del><script>') == $text) { $text = nl2br($text); } @@ -177,17 +180,20 @@ function check_output($text) { return $text; } +/** + * Perform the default filters, preventing malicious HTML from being displayed. + */ function filter_default($text) { - if (variable_get("filter_html", FILTER_HTML_DONOTHING) == FILTER_HTML_STRIP) { + if (variable_get('filter_html', FILTER_HTML_DONOTHING) == FILTER_HTML_STRIP) { // Allow users to enter HTML, but filter it - $text = strip_tags($text, variable_get("allowed_html", "")); - if (variable_get("filter_style", FILTER_STYLE_STRIP)) { - $text = preg_replace("/\Wstyle\s*=[^>]+?>/i", ">", $text); + $text = strip_tags($text, variable_get('allowed_html', '')); + if (variable_get('filter_style', FILTER_STYLE_STRIP)) { + $text = preg_replace('/\Wstyle\s*=[^>]+?>/i', '>', $text); } - $text = preg_replace("/\Won[a-z]+\s*=[^>]+?>/i", ">", $text); + $text = preg_replace('/\Won[a-z]+\s*=[^>]+?>/i', '>', $text); } - if (variable_get("filter_html", FILTER_HTML_DONOTHING) == FILTER_HTML_ESCAPE) { + if (variable_get('filter_html', FILTER_HTML_DONOTHING) == FILTER_HTML_ESCAPE) { // Escape HTML $text = htmlspecialchars($text); } @@ -195,50 +201,55 @@ function filter_default($text) { return trim($text); } +/** + * Settings for the filter system's built-in HTML handling. + */ function filter_default_settings() { - $group = form_radios(t("Filter HTML tags"), "filter_html", variable_get("filter_html", FILTER_HTML_DONOTHING), array(FILTER_HTML_DONOTHING => t("Do not filter"), FILTER_HTML_STRIP => t("Strip tags"), FILTER_HTML_ESCAPE => t("Escape tags")), t("How to deal with HTML and PHP tags in user-contributed content. If set to \"Strip tags\", dangerous tags are removed (see below). If set to \"Escape tags\", all HTML is escaped and presented as it was typed.")); - $group .= form_textfield(t("Allowed HTML tags"), "allowed_html", variable_get("allowed_html", "<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>"), 64, 255, t("If \"Strip tags\" is selected, optionally specify tags which should not be stripped. 'ON*' attributes are always stripped.")); - $group .= form_radios(t("HTML style attributes"), "filter_style", variable_get("filter_style", FILTER_STYLE_STRIP), array(FILTER_STYLE_ALLOW => t("Allowed"), FILTER_STYLE_STRIP => t("Removed")), t("If \"Strip tags\" is selected, you can choose whether 'STYLE' attributes are allowed or removed from input.")); - $output .= form_group(t("HTML filtering"), $group); + $group = form_radios(t('Filter HTML tags'), 'filter_html', variable_get('filter_html', FILTER_HTML_DONOTHING), array(FILTER_HTML_DONOTHING => t('Do not filter'), FILTER_HTML_STRIP => t('Strip tags'), FILTER_HTML_ESCAPE => t('Escape tags')), t('How to deal with HTML and PHP tags in user-contributed content. If set to "Strip tags", dangerous tags are removed (see below). If set to "Escape tags", all HTML is escaped and presented as it was typed.')); + $group .= form_textfield(t('Allowed HTML tags'), 'allowed_html', variable_get('allowed_html', '<a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul>'), 64, 255, t('If "Strip tags" is selected, optionally specify tags which should not be stripped. "ON*" attributes are always stripped.')); + $group .= form_radios(t('HTML style attributes'), 'filter_style', variable_get('filter_style', FILTER_STYLE_STRIP), array(FILTER_STYLE_ALLOW => t('Allowed'), FILTER_STYLE_STRIP => t('Removed')), t('If "Strip tags" is selected, you can choose whether "STYLE" attributes are allowed or removed from input.')); + $output .= form_group(t('HTML filtering'), $group); return $output; } -function filter_filter($op, $text = "") { +/** + * Implementation of hook_filter(). Handles URL upgrades from Drupal 4.1. + */ +function filter_filter($op, $text = '') { switch ($op) { - case "name": - return t("Legacy filtering"); - case "process": - if (variable_get("rewrite_old_urls", 0)) { + case 'name': + return t('Legacy filtering'); + case 'process': + if (variable_get('rewrite_old_urls', 0)) { $text = filter_old_urls($text); } return $text; - case "settings": - $group = form_radios(t("Rewrite old URLs"), "rewrite_old_urls", variable_get("rewrite_old_urls", 0), array(t("Disabled"), t("Enabled")), t("The introduction of 'clean URLs' in Drupal 4.2.0 breaks internal URLs that date back from Drupal 4.1.0 and before. If enabled, this filter will attempt to rewrite the old style URLs to avoid broken links. If <code>mod_rewrite</code> is available on your system, use the rewrite rules in Drupal's <code>.htaccess</code> file instead as these will also correct external referrers.")); - $output .= form_group(t("Legacy filtering"), $group); + case 'settings': + $group = form_radios(t('Rewrite old URLs'), 'rewrite_old_urls', variable_get('rewrite_old_urls', 0), array(t('Disabled'), t('Enabled')), t('The introduction of "clean URLs" in Drupal 4.2.0 breaks internal URLs that date back from Drupal 4.1.0 and before. If enabled, this filter will attempt to rewrite the old style URLs to avoid broken links. If <code>mod_rewrite</code> is available on your system, use the rewrite rules in Drupal\'s <code>.htaccess</code> file instead as these will also correct external referrers.')); + $output .= form_group(t('Legacy filtering'), $group); return $output; default: return $text; } } +/** + * Rewrite legacy URLs. + * + * This is a *temporary* filter to rewrite old-style URLs to new-style + * URLs (clean URLs). Currently, URLs are being rewritten dynamically + * (ie. "on output"), however when these rewrite rules have been tested + * enough, we will use them to permanently rewrite the links in node + * and comment bodies. + */ function filter_old_urls($text) { global $base_url; $end = substr($base_url, 12); - /* - ** This is a *temporary* filter to rewrite old-style URLs to new-style - ** URLs (clean URLs). Currently, URLs are being rewritten dynamically - ** (ie. "on output"), however when these rewrite rules have been tested - ** enough, we will use them to permanently rewrite the links in node - ** and comment bodies. - */ - - if (variable_get("clean_url", "0") == "0") { - /* - ** Relative URLs: - */ + if (variable_get('clean_url', '0') == '0') { + // Relative URLs: // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"?q=\\1/view/\\2/\\4", $text); @@ -248,9 +259,7 @@ function filter_old_urls($text) { $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4", $text); $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2", $text); - /* - ** Absolute URLs: - */ + // Absolute URLs: // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/?q=\\1/view/\\2/\\4", $text); @@ -261,9 +270,7 @@ function filter_old_urls($text) { $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"$end/?q=\\2", $text); } else { - /* - ** Relative URLs: - */ + // Relative URLs: // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"\\1/view/\\2/\\4", $text); @@ -273,9 +280,7 @@ function filter_old_urls($text) { $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4", $text); $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2", $text); - /* - ** Absolute URLs: - */ + // Absolute URLs: // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/\\1/view/\\2/\\4", $text); @@ -289,6 +294,9 @@ function filter_old_urls($text) { return $text; } +/** + * Fetch full filter help texts defined by modules. + */ function filter_tips_long() { $tiplist = ''; foreach (module_list() as $name) { @@ -297,9 +305,12 @@ function filter_tips_long() { } } $output = "<ul class=\"filter-tips-long\">\n$tiplist\n</ul>\n"; - print theme("page", $output, t('Compose Tips')); + print theme('page', $output, t('Compose Tips')); } +/** + * Fetch abbreviated filter help texts defined by modules. + */ function filter_tips_short() { $tiplist = ''; foreach (module_list() as $name) { diff --git a/modules/forum.module b/modules/forum.module index 549f48d7f..972b0ce3f 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -443,7 +443,7 @@ function _forum_new($tid) { } /** - * Menu callback. Prints a forum listing. + * Menu callback; prints a forum listing. */ function forum_page($tid = 0, $display = 'all') { global $sortby, $forum_per_page, $from, $user; diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 549f48d7f..972b0ce3f 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -443,7 +443,7 @@ function _forum_new($tid) { } /** - * Menu callback. Prints a forum listing. + * Menu callback; prints a forum listing. */ function forum_page($tid = 0, $display = 'all') { global $sortby, $forum_per_page, $from, $user; diff --git a/modules/help.module b/modules/help.module index 927b93cdf..a29a58feb 100644 --- a/modules/help.module +++ b/modules/help.module @@ -7,13 +7,15 @@ function help_link($type) { if ($type == 'system') { menu('admin/help/glossary', t('glossary'), user_access('access administration pages') ? 'help_glossary' : MENU_DENIED, 8); - menu('admin/help', t('help'), user_access('access administration pages') ? 'help_help_page' : MENU_DENIED, 9); + menu('admin/help', t('help'), user_access('access administration pages') ? 'help_page' : MENU_DENIED, 9); } } +/** + * Menu callback; prints a page listing a glossary of Drupal terminology. + */ function help_glossary() { - - $output .= t(" + $output = t(" <h3>Glossary</h3><dl> <dt>Block</dt><dd>A small box containing information or content placed in the left-hand or right-hand sidebar of a web page.</dd> <dt>Comment</dt><dd>A note attached to a node. Usually intended to clarify, explain, criticize, or express an opinion on the original material.</dd> @@ -29,41 +31,39 @@ function help_glossary() { <dt>Unpublished</dt><dd>A node that is only viewable by administrators and moderators.</dd> <dt>User</dt><dd>A person who has an account at your Drupal site, and is logged in with that account.</dd> <dt>Visitor</dt><dd>A person who does not have an account at your Drupal site or a person who has an account at your Drupal site but is <u>not</u> logged in with that account. Also termed \"anonymous user\".</dd> - </dl>", array("%taxonomy" => url("admin/taxonomy/help"))); + </dl>", array('%taxonomy' => url('admin/taxonomy/help'))); - print theme("page", $output); + print theme('page', $output); } -function help_help($section = "admin/help#help") { - $output = ""; - +/** + * Implementation of hook_help(). + */ +function help_help($section) { switch ($section) { - - case 'admin/help#help': - foreach (module_list() as $name) { - if ($name == 'help') { - continue; - } - else if (module_hook($name, "help")) { - $temp = module_invoke($name, "help", "admin/help#$name"); - if (!empty($temp)) { - $links[] = l($name, "admin/help#$name"); - $output .= "<h2><a id=\"$name\">". ucfirst($name) ." module</a></h2>"; - $output .= $temp; - } - } - } - $output = "<small>". implode(" · ", $links) ."</small><hr />". $output; - break; case 'admin/system/modules#description': - $output = t("Manages displaying online help."); + $output = t('Manages displaying online help.'); break; } return $output; } -function help_help_page() { - print theme("page", help_help()); +/** + * Menu callback; prints a page listing general help for all modules. + */ +function help_page() { + foreach (module_list() as $name) { + if (module_hook($name, 'help')) { + $temp = module_invoke($name, 'help', "admin/help#$name"); + if (!empty($temp)) { + $links[] = l($name, "admin/help#$name"); + $output .= "<h2><a id=\"$name\">". ucfirst($name) .' module</a></h2>'; + $output .= $temp; + } + } + } + $output = '<small>'. implode(' · ', $links) .'</small><hr />'. $output; + print theme('page', $output); } ?> diff --git a/modules/help/help.module b/modules/help/help.module index 927b93cdf..a29a58feb 100644 --- a/modules/help/help.module +++ b/modules/help/help.module @@ -7,13 +7,15 @@ function help_link($type) { if ($type == 'system') { menu('admin/help/glossary', t('glossary'), user_access('access administration pages') ? 'help_glossary' : MENU_DENIED, 8); - menu('admin/help', t('help'), user_access('access administration pages') ? 'help_help_page' : MENU_DENIED, 9); + menu('admin/help', t('help'), user_access('access administration pages') ? 'help_page' : MENU_DENIED, 9); } } +/** + * Menu callback; prints a page listing a glossary of Drupal terminology. + */ function help_glossary() { - - $output .= t(" + $output = t(" <h3>Glossary</h3><dl> <dt>Block</dt><dd>A small box containing information or content placed in the left-hand or right-hand sidebar of a web page.</dd> <dt>Comment</dt><dd>A note attached to a node. Usually intended to clarify, explain, criticize, or express an opinion on the original material.</dd> @@ -29,41 +31,39 @@ function help_glossary() { <dt>Unpublished</dt><dd>A node that is only viewable by administrators and moderators.</dd> <dt>User</dt><dd>A person who has an account at your Drupal site, and is logged in with that account.</dd> <dt>Visitor</dt><dd>A person who does not have an account at your Drupal site or a person who has an account at your Drupal site but is <u>not</u> logged in with that account. Also termed \"anonymous user\".</dd> - </dl>", array("%taxonomy" => url("admin/taxonomy/help"))); + </dl>", array('%taxonomy' => url('admin/taxonomy/help'))); - print theme("page", $output); + print theme('page', $output); } -function help_help($section = "admin/help#help") { - $output = ""; - +/** + * Implementation of hook_help(). + */ +function help_help($section) { switch ($section) { - - case 'admin/help#help': - foreach (module_list() as $name) { - if ($name == 'help') { - continue; - } - else if (module_hook($name, "help")) { - $temp = module_invoke($name, "help", "admin/help#$name"); - if (!empty($temp)) { - $links[] = l($name, "admin/help#$name"); - $output .= "<h2><a id=\"$name\">". ucfirst($name) ." module</a></h2>"; - $output .= $temp; - } - } - } - $output = "<small>". implode(" · ", $links) ."</small><hr />". $output; - break; case 'admin/system/modules#description': - $output = t("Manages displaying online help."); + $output = t('Manages displaying online help.'); break; } return $output; } -function help_help_page() { - print theme("page", help_help()); +/** + * Menu callback; prints a page listing general help for all modules. + */ +function help_page() { + foreach (module_list() as $name) { + if (module_hook($name, 'help')) { + $temp = module_invoke($name, 'help', "admin/help#$name"); + if (!empty($temp)) { + $links[] = l($name, "admin/help#$name"); + $output .= "<h2><a id=\"$name\">". ucfirst($name) .' module</a></h2>'; + $output .= $temp; + } + } + } + $output = '<small>'. implode(' · ', $links) .'</small><hr />'. $output; + print theme('page', $output); } ?> diff --git a/modules/statistics.module b/modules/statistics.module index be91dd47a..01a61dd72 100644 --- a/modules/statistics.module +++ b/modules/statistics.module @@ -237,7 +237,7 @@ function statistics_admin_accesslog_table($type, $id) { } /** - * Menu callback. Presents the "Top referrers" page. + * Menu callback; presents the "Top referrers" page. * * @param $view * - "internal": Only display internal links. @@ -286,14 +286,14 @@ function statistics_top_refer($view = 'all') { } /** - * Menu callback. Presents the "Most Popular Content" page. + * Menu callback; presents the "Most Popular Content" page. */ function statistics_admin_topnodes() { print theme('page', statistics_admin_topnodes_table()); } /** - * Menu callback. Presents the "Access logs" page. + * Menu callback; presents the "Access logs" page. * * @param $type * - "user": display accesses for a particular user. @@ -469,7 +469,7 @@ function statistics_block($op = 'list', $delta = 0) { } /** - * Menu callback. Presents the "Top Nodes" summary page. + * Menu callback; presents the "Top Nodes" summary page. */ function statistics_page() { $output = ''; diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index be91dd47a..01a61dd72 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -237,7 +237,7 @@ function statistics_admin_accesslog_table($type, $id) { } /** - * Menu callback. Presents the "Top referrers" page. + * Menu callback; presents the "Top referrers" page. * * @param $view * - "internal": Only display internal links. @@ -286,14 +286,14 @@ function statistics_top_refer($view = 'all') { } /** - * Menu callback. Presents the "Most Popular Content" page. + * Menu callback; presents the "Most Popular Content" page. */ function statistics_admin_topnodes() { print theme('page', statistics_admin_topnodes_table()); } /** - * Menu callback. Presents the "Access logs" page. + * Menu callback; presents the "Access logs" page. * * @param $type * - "user": display accesses for a particular user. @@ -469,7 +469,7 @@ function statistics_block($op = 'list', $delta = 0) { } /** - * Menu callback. Presents the "Top Nodes" summary page. + * Menu callback; presents the "Top Nodes" summary page. */ function statistics_page() { $output = ''; |