Skip to content
Commits on Source (756)
......@@ -12,18 +12,16 @@
Options -Indexes
Options FollowSymLinks
# Customized server error messages:
ErrorDocument 404 /index.php
# Set the default handler to index.php:
DirectoryIndex index.php
# Customized server error messages:
ErrorDocument 400 /error.php
ErrorDocument 402 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
# Overload PHP variables:
<IfModule mod_php4.c>
# If you are using Apache 2, you have to use <IfModule sapi_apache2.c>
# instead of <IfModule mod_php4.c>.
php_value register_globals 0
php_value track_vars 1
php_value short_open_tag 1
......@@ -32,17 +30,22 @@ ErrorDocument 500 /error.php
php_value magic_quotes_sybase 0
php_value arg_separator.output "&amp;"
php_value session.cache_expire 200000
php_value session.gc_maxlifetime 200000
php_value session.cookie_lifetime 2000000
php_value session.auto_start 0
php_value session.save_handler user
php_value session.cache_limiter none
php_value allow_call_time_pass_reference Off
php_value allow_call_time_pass_reference On
</IfModule>
# Various rewrite rules
<IfModule mod_rewrite.c>
RewriteEngine on
# Modify the RewriteBase if you are using Drupal in a subdirectory and the
# rewrite rules are not working properly:
#RewriteBase /drupal
# Rewrite old-style URLS of the form 'node.php?id=x':
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
......
Drupal x.x.x, xxxx-xx-xx (to be released)
Drupal 4.4.2, 2004-07-04
------------------------
- fixed bugs: no critical bugs were identified.
Drupal 4.4.1, 2004-05-01
------------------------
- fixed bugs: no critical bugs were identified.
Drupal 4.4.0, 2004-04-01
------------------------
- added support for the MetaWeblog API and MovableType extensions.
- added a file API: enables better document management.
- improved the watchdog and search module to log search keys.
- news aggregator:
* added support for conditional GET.
* added OPML feed subscription list.
* added support for <image>, <pubDate>, <dc:date>, <dcterms:created>, <dcterms:issued> and <dcterms:modified>.
- comment module:
* made it possible to disable the "comment viewing controls".
- performance:
* improved module loading when serving cached pages.
* made it possible to automatically disable modules when under heavy load.
* made it possible to automatically disable blocks when under heavy load.
* improved performance and memory footprint of the locale module.
- theme system:
* made all theme functions start with 'theme_'.
* made all theme functions return their output.
* migrated away from using the BaseTheme class.
* added many new theme functions and refactored existing theme functions.
* added avatar support to 'Xtemplate'.
* replaced theme 'UnConeD' by 'Chameleon'.
* replaced theme 'Marvin' by 'Pushbutton'.
- usability:
* added breadcrumb navigation to all pages.
* made it possible to add context-sensitive help to all pages.
* replaced drop-down menus by radio buttons where appropriate.
* removed the 'magic_quotes_gpc = 0' requirement.
* added a 'book navigation' block.
- accessibility:
* made themes degrade gracefully in absence of CSS.
* grouped form elements using '<fieldset>' and '<legend>' tags.
* added '<label>' tags to form elements.
- refactored 404 (file not found) handling to support custom 404 pages.
- documentation:
* added PHPDoc/Doxygen comments.
- improved the filter system to prevent conflicts between filters:
* made it possible to change the order in which filters are applied.
Drupal 4.3.2, 2004-01-01
------------------------
- fixed bugs: no critical bugs were identified.
Drupal 4.3.1, 2003-12-01
------------------------
- fixed bugs: no critical bugs were identified.
Drupal 4.3.0, 2003-11-01
------------------------
- added support for configurable URLs.
- added support for sortable table columns.
- database backend:
* added support for database table prefxing.
- performance improvements:
* optimized SQL queries.
* added support for selective database table prefixing.
- performance:
* optimized many SQL queries for speed by converting left joins to inner joins.
- comment module:
* changed the comment module to use the standard pager and rewrote the
comment housekeeping code to be much more efficient.
* rewrote the comment housekeeping code to be much more efficient and scalable.
* changed the comment module to use the standard pager.
- user module:
* added support for multiple sessions per user.
* added support for anonymous user sessions.
- forum module:
* improved the forum views and the themability thereof.
- usability improvements:
- book module:
* improved integration of non-book nodes in the book outline.
- usability:
* added support for "mass node operations" to ease repetitive tasks.
* added support for breadcrumb navigation to several modules' user pages.
* integrated the administration pages with the normal user pages.
Drupal 4.2.0, 2003-08-01
------------------------
......@@ -29,17 +99,17 @@ Drupal 4.2.0, 2003-08-01
* improved the look and feel.
* added context-sensitive help.
- database backend:
* fixed numereous SQL queries to make Drupal ANSI compliant.
* fixed numerous SQL queries to make Drupal ANSI compliant.
* added MSSQL database scheme.
- search module:
* changed the search module to use implicit AND'ing instead of implicit OR'ing.
- node system improvements:
- node system:
* replaced the "post content" permission by more fine-grained permissions.
* improved content submission:
+ improved teasers: teasers are now optional, teaser length can be configured, teaser and body are edited in a single textarea, users will no longer be bothered with teasers when the post is too short for one.
+ added the ability to preview both the short and the full version of your posts.
* extended the node API which allows for better integration.
* added default node settings to control the behaviour for promotion, moderation and other options.
* added default node settings to control the behavior for promotion, moderation and other options.
- themes:
* replaced theme "Goofy" by "Xtemplate", a template driven theme.
- removed the 'register_globals = on' requirement.
......@@ -84,7 +154,7 @@ Drupal 4.0.0, 2002-06-15
* speeds up pages for anonymous users and reduces system load.
- added support for external SMTP libraries.
- added an archive extension to the calendar.
- added blogger API support.
- added support for the Blogger API.
- themes:
* cleaned up the theme system.
* moved themes that are not maintained to contributions CVS repository.
......@@ -101,7 +171,7 @@ Drupal 4.0.0, 2002-06-15
* blocks can now be enabled and/or be set by the user.
* blocks can be set to only show up on some pages.
* merged box module with block module.
- node system improvements:
- node system:
* fixed node retrieval based on titles.
* blogs can be updated.
* teasers (abstracts) on all node types.
......@@ -145,9 +215,9 @@ Drupal 3.0.0, 2001-09-15
- rewrote headline code and renamed it to import.module and export.module:
* added various improvements, including a better parser, bundles and better control over individual feeds.
- rewrote section code and renamed it to meta.module:
* supports unlimeted amount of nested topics. Topics can be nested to create a multi-level hierarchy.
* supports unlimited amount of nested topics. Topics can be nested to create a multi-level hierarchy.
- rewrote configuration file resolving:
* Drupal tries to locate a configuration file that matches your domainname or uses conf.php if the former failed. Note also that the configuration files got renamed from .conf to .php for security's sake on mal-configured Drupal sites.
* Drupal tries to locate a configuration file that matches your domain name or uses conf.php if the former failed. Note also that the configuration files got renamed from .conf to .php for security's sake on mal-configured Drupal sites.
- added caching support which makes Drupal extremely scalable.
- added access.module:
* allows you to setup 'roles' (groups) and to bind a set of permissions to each group.
......
......@@ -15,7 +15,6 @@ SERVER CONFIGURATION
Your PHP must have the following settings:
magic_quotes_gpc 0
session.save_handler user
In addition, we recommend the following settings:
......@@ -111,9 +110,9 @@ INSTALLATION
Drupal allows for multiple virtual host installations; to configure
a virtual server host, you can create the configuration file
includes/www.yourserver.com.php
includes/www.example.com.php
where www.yourserver.com is your website's URL.
where www.example.com is your website's URL.
Before you can run Drupal, you must set the database URL and the
base URL to the web site. Open the configuration file and edit the
......@@ -123,7 +122,7 @@ INSTALLATION
Set $base_url to match the address to your web site:
$base_url = "http://localhost";
$base_url = "http://www.example.com";
NOTE: for more information about multiple virtual hosts or the
configuration settings, consult the Drupal handbook at drupal.org.
......@@ -154,12 +153,22 @@ INSTALLATION
DRUPAL ADMINISTRATION
---------------------
Your Drupal website defaults to a very basic configuration with only
a few active modules, one theme, and no user access rights.
Upon a new installation, your Drupal website defaults to a very basic
configuration with only a few active modules, one theme, and no user
access rights.
Standard services can be selected and configured through the
administration panel; additional community-contributed modules and
themes are available from drupal.org.
Use your administration panel to enable and configure services. For
example, set some general settings for your site with "Administration -
configuration". Enable modules via "Administration - configuration -
modules". User permissions can be set with "Administration - accounts
- permissions".
For more information on configuration options, read through the
instructions which accompany the different configuration settings and
consult the various help pages available in the administration panel.
Note that additional community-contributed modules and themes are
available at http://drupal.org/.
CUSTOMIZING YOUR THEME(S)
-------------------------
......@@ -176,6 +185,21 @@ Most themes also contain stylesheets or PHP configuration files to
tune the colors and layouts; check the themes/ directory for README
files describing each alternate theme.
UPGRADING
---------
1. Backup your database and Drupal directory - especially your
configuration file (www.example.com.conf or includes/conf.php).
2. Log on as the user with user ID 1.
3. Overwrite all the old Drupal files with the new Drupal files.
4. Modify the new configuration file to make sure it has the
correct information.
5. Run update.php by visiting http://www.example.com/update.php.
MORE INFORMATION
----------------
......
......@@ -16,8 +16,8 @@ LEGEND
--------------------------------------------------------------------------------
BLOCK SYSTEM
M: Kjartan Mannes <kjartan@drupal.org>
BLOG API
M:James Walker <walkah@walkah.net>
S: maintained
CODING STYLE CHECKER
......@@ -28,40 +28,24 @@ DISTRIBUTED AUTHENTICATION MODULES
M: Moshe Weitzman <weitzman@tejasa.com>
S: maintained
FORUM MODULE
M: Marco Molinari <marco@porciletto.org>
S: maintained
POLL MODULE
M: Alastair Maw <me@almaw.com>
S: maintained
LANGUAGE
M: Alastair Maw <me@almaw.com>
S: maintained
MSSQL PORT
M: Moshe Weitzman <weitzman@tejasa.com>
LOCALE MODULE
M: Gabor Hojtsy <goba@php.net>
S: maintained
POSTGRES PORT
M: James Arthur <j_a_arthur@yahoo.com>
M: Adrian Rossouw <adrian@obsidian.co.za>
S: maintained
STATISTICS MODULE
M: Jeremy Andrews <jeremy@kerneltrap.com>
S: maintained
TAXONOMY SYSTEM
M: Marco Molinari <marco@porciletto.org>
S: maintained
USER SYSTEM
M: Moshe Weitzman <weitzman@tejasa.com>
S: maintained
DEBIAN PACKAGE
M: Hugo Espuny <hec@debian.org>
M: Hilko Bengen <bengen@debian.org>
S: maintained
THE REST:
......
<?php
// $Id$
include_once "includes/bootstrap.inc";
include_once "includes/common.inc";
/*
** If not in 'safe mode', increase the maximum execution time:
*/
if (!get_cfg_var("safe_mode")) {
if (!ini_get("safe_mode")) {
set_time_limit(240);
}
......@@ -15,9 +16,7 @@
** Iterate through the modules calling their cron handlers (if any):
*/
foreach (module_list() as $module) {
module_invoke($module, "cron");
}
module_invoke_all("cron");
watchdog("message", "cron run completed");
watchdog("regular", "cron run completed");
?>
---
--- Table definitions
---
CREATE TABLE [dbo].[access] (
[aid] [smallint] NULL ,
[mask] [varchar] (255) NOT NULL ,
[type] [varchar] (255) NOT NULL ,
[status] [smallint] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[accesslog] (
[nid] [numeric](11, 0) NULL ,
[url] [varchar] (255) NULL ,
[hostname] [varchar] (128) NULL ,
[uid] [numeric](10, 0) NULL ,
[timestamp] [numeric](11, 0) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[authmap] (
[aid] [numeric](10, 0) NULL ,
[uid] [int] NOT NULL ,
[authname] [varchar] (128) NOT NULL ,
[module] [varchar] (128) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[blocks] (
[module] [varchar] (64) NOT NULL ,
[delta] [varchar] (32) NOT NULL ,
[status] [smallint] NOT NULL ,
[weight] [smallint] NOT NULL ,
[region] [smallint] NOT NULL ,
[path] [varchar] (255) NOT NULL ,
[custom] [smallint] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[book] (
[nid] [numeric](4, 0) NOT NULL ,
[parent] [int] NOT NULL ,
[weight] [smallint] NOT NULL ,
[format] [smallint] NULL ,
[log] [text] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[boxes] (
[bid] [smallint] NULL ,
[title] [varchar] (64) NOT NULL ,
[body] [text] NULL ,
[info] [varchar] (128) NOT NULL ,
[type] [smallint] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[bundle] (
[bid] [int] NULL ,
[title] [varchar] (255) NOT NULL ,
[attributes] [varchar] (255) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[cache] (
[cid] [varchar] (255) NOT NULL ,
[data] [text] NULL ,
[expire] [int] NOT NULL ,
[created] [int] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[comments] (
[cid] [int] NULL ,
[pid] [int] NOT NULL ,
[nid] [int] NOT NULL ,
[uid] [int] NOT NULL ,
[subject] [varchar] (64) NOT NULL ,
[comment] [varchar] (8000) NOT NULL ,
[hostname] [varchar] (128) NOT NULL ,
[timestamp] [int] NOT NULL ,
[link] [varchar] (16) NULL ,
[score] [int] NOT NULL ,
[status] [tinyint] NOT NULL ,
[thread] [varchar] (255) NOT NULL ,
[users] [varchar] (8000) NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[directory] (
[link] [varchar] (255) NOT NULL ,
[name] [varchar] (128) NOT NULL ,
[mail] [varchar] (128) NOT NULL ,
[slogan] [text] NOT NULL ,
[mission] [text] NOT NULL ,
[timestamp] [int] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[feed] (
[fid] [int] NULL ,
[title] [varchar] (255) NOT NULL ,
[url] [varchar] (255) NOT NULL ,
[refresh] [int] NOT NULL ,
[timestamp] [int] NULL ,
[attributes] [varchar] (255) NULL ,
[link] [varchar] (255) NULL ,
[description] [varchar] (8000) NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[forum] (
[nid] [numeric](10, 0) NOT NULL ,
[tid] [numeric](10, 0) NOT NULL ,
[icon] [varchar] (255) NOT NULL ,
[shadow] [numeric](10, 0) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[history] (
[uid] [int] NOT NULL ,
[nid] [int] NOT NULL ,
[timestamp] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[item] (
[iid] [int] NULL ,
[fid] [int] NOT NULL ,
[title] [varchar] (255) NOT NULL ,
[link] [varchar] (255) NOT NULL ,
[author] [varchar] (255) NOT NULL ,
[description] [text] NOT NULL ,
[timestamp] [int] NULL ,
[attributes] [varchar] (255) NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[locales] (
[lid] [int] NULL ,
[location] [varchar] (128) NOT NULL ,
[string] [nvarchar] (4000) NOT NULL ,
[da] [text] NULL ,
[fi] [text] NULL ,
[fr] [text] NULL ,
[en] [text] NULL ,
[es] [text] NULL ,
[nl] [text] NULL ,
[no] [text] NULL ,
[sw] [text] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[menu] (
[name] [varchar] (255) NOT NULL ,
[link] [varchar] (255) NOT NULL ,
[help] [text] NULL ,
[title] [varchar] (255) NOT NULL ,
[parent] [varchar] (255) NOT NULL ,
[weight] [smallint] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[moderation_filters] (
[fid] [numeric](10, 0) NULL ,
[filter] [varchar] (255) NOT NULL ,
[minimum] [smallint] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[moderation_roles] (
[rid] [numeric](4, 0) NOT NULL ,
[mid] [numeric](4, 0) NOT NULL ,
[value] [smallint] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[moderation_votes] (
[mid] [numeric](10, 0) NULL ,
[vote] [varchar] (255) NULL ,
[weight] [smallint] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[node] (
[nid] [numeric](10, 0) NULL ,
[type] [varchar] (16) NOT NULL ,
[title] [varchar] (128) NOT NULL ,
[path] [varchar] (250) NULL ,
[score] [int] NOT NULL ,
[votes] [int] NOT NULL ,
[uid] [int] NOT NULL ,
[status] [int] NOT NULL ,
[created] [int] NOT NULL ,
[comment] [int] NOT NULL ,
[promote] [int] NOT NULL ,
[moderate] [int] NOT NULL ,
[users] [text] NULL ,
[attributes] [varchar] (255) NULL ,
[teaser] [text] NOT NULL ,
[body] [text] NOT NULL ,
[changed] [int] NOT NULL ,
[revisions] [text] NULL ,
[static] [int] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[page] (
[nid] [numeric](10, 0) NOT NULL ,
[link] [varchar] (128) NOT NULL ,
[format] [smallint] NOT NULL ,
[description] [varchar] (128) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[permission] (
[rid] [numeric](4, 0) NOT NULL ,
[perm] [text] NULL ,
[tid] [numeric](4, 0) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[poll] (
[nid] [numeric](4, 0) NOT NULL ,
[runtime] [int] NOT NULL ,
[voters] [text] NOT NULL ,
[active] [numeric](4, 0) NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[poll_choices] (
[chid] [numeric](10, 0) NULL ,
[nid] [numeric](10, 0) NOT NULL ,
[chtext] [varchar] (128) NOT NULL ,
[chvotes] [int] NOT NULL ,
[chorder] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[role] (
[rid] [numeric](10, 0) IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (32) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[search_index] (
[word] [varchar] (50) NOT NULL ,
[lno] [numeric](10, 0) NOT NULL ,
[type] [varchar] (16) NULL ,
[count] [numeric](10, 0) NULL
) ON [PRIMARY]
GO
CREATE TABLE sessions (
[sid] [varchar] (32) NOT NULL,
[uid] [int] NOT NULL,
[hostname] [varchar] (128) NOT NULL,
[timestamp] [integer] NOT NULL,
[session] [text],
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[sequences] (
[name] [varchar] (255) NOT NULL ,
[id] [numeric](10, 0) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[site] (
[sid] [numeric](10, 0) NULL ,
[name] [varchar] (128) NOT NULL ,
[link] [varchar] (255) NOT NULL ,
[size] [text] NOT NULL ,
[changed] [int] NOT NULL ,
[checked] [int] NOT NULL ,
[feed] [varchar] (255) NOT NULL ,
[refresh] [int] NOT NULL ,
[threshold] [int] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[statistics] (
[nid] [int] NOT NULL ,
[totalcount] [numeric](20, 0) NOT NULL ,
[daycount] [numeric](4, 0) NOT NULL ,
[timestamp] [numeric](4, 0) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[system] (
[filename] [varchar] (255) NOT NULL ,
[name] [varchar] (255) NOT NULL ,
[type] [varchar] (255) NOT NULL ,
[description] [varchar] (255) NOT NULL ,
[status] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[term_data] (
[tid] [numeric](10, 0) NOT NULL ,
[vid] [numeric](10, 0) NOT NULL ,
[name] [varchar] (255) NOT NULL ,
[description] [text] NULL ,
[weight] [smallint] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[term_hierarchy] (
[tid] [numeric](4, 0) NOT NULL ,
[parent] [numeric](4, 0) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[term_node] (
[nid] [numeric](4, 0) NOT NULL ,
[tid] [numeric](4, 0) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[term_relation] (
[tid1] [numeric](4, 0) NOT NULL ,
[tid2] [numeric](4, 0) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[term_synonym] (
[tid] [numeric](10, 0) NOT NULL ,
[name] [varchar] (255) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[users] (
[uid] [bigint] IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (60) NOT NULL ,
[pass] [varchar] (32) NOT NULL ,
[mail] [varchar] (64) NULL ,
[homepage] [varchar] (128) NULL ,
[mode] [smallint] NOT NULL ,
[sort] [smallint] NULL ,
[threshold] [smallint] NULL ,
[theme] [varchar] (255) NULL ,
[signature] [varchar] (255) NULL ,
[timestamp] [float] NOT NULL ,
[status] [smallint] NOT NULL ,
[timezone] [varchar] (8) NULL ,
[language] [char] (2) NULL ,
[init] [varchar] (128) NULL ,
[data] [varchar] (8000) NULL ,
[rid] [int] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[variable] (
[name] [varchar] (32) NOT NULL ,
[value] [varchar] (8000) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[vocabulary] (
[vid] [numeric](10, 0) NULL ,
[name] [varchar] (255) NOT NULL ,
[description] [text] NULL ,
[relations] [tinyint] NOT NULL ,
[hierarchy] [tinyint] NOT NULL ,
[multiple] [tinyint] NOT NULL ,
[required] [tinyint] NOT NULL ,
[nodes] [text] NULL ,
[weight] [smallint] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[watchdog] (
[wid] [int] IDENTITY (1, 1) NOT NULL ,
[uid] [int] NOT NULL ,
[type] [varchar] (16) NOT NULL ,
[message] [text] NOT NULL ,
[link] [varchar] (255) NOT NULL ,
[location] [varchar] (128) NOT NULL ,
[hostname] [varchar] (128) NOT NULL ,
[timestamp] [int] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[role] WITH NOCHECK ADD
CONSTRAINT [PK_role] PRIMARY KEY CLUSTERED
(
[rid]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[watchdog] WITH NOCHECK ADD
PRIMARY KEY CLUSTERED
(
[wid]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[cache] WITH NOCHECK ADD
CONSTRAINT [DF_cache_created] DEFAULT (0) FOR [created]
GO
CREATE INDEX [forum_tid_idx] ON [dbo].[forum]([tid]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[node] WITH NOCHECK ADD
CONSTRAINT [DF_node_score] DEFAULT (0) FOR [score],
CONSTRAINT [DF_node_votes] DEFAULT (0) FOR [votes],
CONSTRAINT [DF_node_uid] DEFAULT (0) FOR [uid],
CONSTRAINT [DF_node_status] DEFAULT (1) FOR [status],
CONSTRAINT [DF_node_created] DEFAULT (0) FOR [created],
CONSTRAINT [DF_node_comment] DEFAULT (2) FOR [comment],
CONSTRAINT [DF_node_promote] DEFAULT (0) FOR [promote],
CONSTRAINT [DF_node_moderate] DEFAULT (0) FOR [moderate],
CONSTRAINT [DF_node_changed] DEFAULT (0) FOR [changed],
CONSTRAINT [DF_node_static] DEFAULT (0) FOR [static]
GO
CREATE INDEX [IX_role] ON [dbo].[role]([rid]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[term_data] WITH NOCHECK ADD
CONSTRAINT [DF_term_data_vid] DEFAULT (0) FOR [vid]
GO
ALTER TABLE [dbo].[users] WITH NOCHECK ADD
CONSTRAINT [DF_users_mode] DEFAULT (0) FOR [mode],
CONSTRAINT [DF_users_sort] DEFAULT (0) FOR [sort],
CONSTRAINT [DF_users_threshold] DEFAULT (0) FOR [threshold]
GO
CREATE INDEX [IX_sid] ON [dbo].[users]([sid]) ON [PRIMARY]
GO
CREATE INDEX [IX_users] ON [dbo].[users]([uid]) ON [PRIMARY]
GO
CREATE INDEX [IX_timestamp] ON [dbo].[users]([timestamp]) ON [PRIMARY]
GO
CREATE INDEX [users_sid_idx] ON [dbo].[users]([sid]) ON [PRIMARY]
GO
CREATE INDEX [users_timestamp_idx] ON [dbo].[users]([timestamp]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[watchdog] WITH NOCHECK ADD
CONSTRAINT [DF__watchdog__uid__41EDCAC5] DEFAULT ('0') FOR [uid],
CONSTRAINT [DF__watchdog__type__42E1EEFE] DEFAULT ('') FOR [type],
CONSTRAINT [DF__watchdog__messag__43D61337] DEFAULT ('') FOR [message],
CONSTRAINT [DF__watchdog__link__44CA3770] DEFAULT ('') FOR [link],
CONSTRAINT [DF__watchdog__locati__45BE5BA9] DEFAULT ('') FOR [location],
CONSTRAINT [DF__watchdog__hostna__46B27FE2] DEFAULT ('') FOR [hostname],
CONSTRAINT [DF__watchdog__timest__47A6A41B] DEFAULT ('0') FOR [timestamp]
GO
--
-- Insert some default values
--
INSERT INTO system VALUES ('modules/admin.module','admin','module','',1);
INSERT INTO system VALUES ('modules/block.module','block','module','',1);
INSERT INTO system VALUES ('modules/comment.module','comment','module','',1);
INSERT INTO system VALUES ('modules/help.module','help','module','',1);
INSERT INTO system VALUES ('modules/node.module','node','module','',1);
INSERT INTO system VALUES ('modules/page.module','page','module','',1);
INSERT INTO system VALUES ('modules/story.module','story','module','',1);
INSERT INTO system VALUES ('modules/taxonomy.module','taxonomy','module','',1);
INSERT INTO system VALUES ('themes/marvin/marvin.theme','marvin','theme','Internet explorer, Netscape, Opera',1);
INSERT INTO variable(name,value) VALUES('update_start', 's:10:"2002-05-15";');
INSERT INTO variable(name,value) VALUES('theme_default','s:6:"marvin";');
INSERT INTO blocks(module,delta,status,custom,region,weight,path) VALUES('user', 0, 1, 0, 1, 0, '');
INSERT INTO blocks(module,delta,status,custom,region,weight,path) VALUES('user', 1, 1, 0, 1, 0, '');
---
--- Functions. Functions first available in SQL Server 2000. GREATEST() used by forum.module, tracker.module at the moment.
---
GO
CREATE FUNCTION GREATEST (@a int, @b int)
RETURNS int AS
BEGIN
IF (@a > @b)
BEGIN
RETURN @a;
END
RETURN @b;
END
......@@ -25,7 +25,8 @@ CREATE TABLE accesslog (
url varchar(255) default NULL,
hostname varchar(128) default NULL,
uid int(10) unsigned default '0',
timestamp int(11) unsigned NOT NULL default '0'
timestamp int(11) unsigned NOT NULL default '0',
KEY accesslog_timestamp (timestamp)
) TYPE=MyISAM;
--
......@@ -52,7 +53,8 @@ CREATE TABLE blocks (
weight tinyint(1) DEFAULT '0' NOT NULL,
region tinyint(1) DEFAULT '0' NOT NULL,
path varchar(255) DEFAULT '' NOT NULL,
custom tinyint(2) DEFAULT '0' NOT NULL
custom tinyint(2) DEFAULT '0' NOT NULL,
throttle tinyint(1) DEFAULT '0' NOT NULL
) TYPE=MyISAM;
--
......@@ -64,9 +66,8 @@ CREATE TABLE book (
parent int(10) NOT NULL default '0',
weight tinyint(3) NOT NULL default '0',
format tinyint(2) default '0',
log text,
log longtext,
PRIMARY KEY (nid),
KEY nid (nid),
KEY parent (parent)
) TYPE=MyISAM;
......@@ -77,7 +78,7 @@ CREATE TABLE book (
CREATE TABLE boxes (
bid tinyint(4) NOT NULL auto_increment,
title varchar(64) NOT NULL default '',
body text,
body longtext,
info varchar(128) NOT NULL default '',
type tinyint(2) NOT NULL default '0',
PRIMARY KEY (bid),
......@@ -103,9 +104,10 @@ CREATE TABLE bundle (
CREATE TABLE cache (
cid varchar(255) NOT NULL default '',
data mediumtext,
data longtext,
expire int(11) NOT NULL default '0',
created int(11) NOT NULL default '0',
headers text,
PRIMARY KEY (cid)
) TYPE=MyISAM;
......@@ -119,14 +121,13 @@ CREATE TABLE comments (
nid int(10) NOT NULL default '0',
uid int(10) NOT NULL default '0',
subject varchar(64) NOT NULL default '',
comment text NOT NULL,
comment longtext NOT NULL,
hostname varchar(128) NOT NULL default '',
timestamp int(11) NOT NULL default '0',
link varchar(16) NOT NULL default '',
score mediumint(9) NOT NULL default '0',
status tinyint(3) unsigned NOT NULL default '0',
thread varchar(255) NOT NULL,
users mediumtext,
users longtext,
PRIMARY KEY (cid),
KEY lid (nid)
) TYPE=MyISAM;
......@@ -139,8 +140,8 @@ CREATE TABLE directory (
link varchar(255) NOT NULL default '',
name varchar(128) NOT NULL default '',
mail varchar(128) NOT NULL default '',
slogan text NOT NULL,
mission text NOT NULL,
slogan longtext NOT NULL,
mission longtext NOT NULL,
timestamp int(11) NOT NULL default '0',
PRIMARY KEY (link)
) TYPE=MyISAM;
......@@ -154,15 +155,28 @@ CREATE TABLE feed (
title varchar(255) NOT NULL default '',
url varchar(255) NOT NULL default '',
refresh int(10) NOT NULL default '0',
timestamp int(10) NOT NULL default '0',
checked int(10) NOT NULL default '0',
attributes varchar(255) NOT NULL default '',
link varchar(255) NOT NULL default '',
description text NOT NULL,
description longtext NOT NULL,
image longtext NOT NULL default '',
etag varchar(255) NOT NULL default '',
modified int(10) NOT NULL default '0',
PRIMARY KEY (fid),
UNIQUE KEY link (url),
UNIQUE KEY title (title)
) TYPE=MyISAM;
--
-- Table structure for table 'filters'
--
CREATE TABLE filters (
module varchar(64) NOT NULL default '',
weight tinyint(2) DEFAULT '0' NOT NULL,
KEY weight (weight)
) TYPE=MyISAM;
--
-- Table structure for table 'forum'
--
......@@ -170,9 +184,9 @@ CREATE TABLE feed (
CREATE TABLE forum (
nid int(10) unsigned NOT NULL default '0',
tid int(10) unsigned NOT NULL default '0',
icon varchar(255) NOT NULL default '',
shadow int(10) unsigned NOT NULL default '0',
PRIMARY KEY (nid)
PRIMARY KEY (nid),
KEY tid (tid)
) TYPE=MyISAM;
--
......@@ -196,7 +210,7 @@ CREATE TABLE item (
title varchar(255) NOT NULL default '',
link varchar(255) NOT NULL default '',
author varchar(255) NOT NULL default '',
description text NOT NULL,
description longtext NOT NULL,
timestamp int(11) default NULL,
attributes varchar(255) NOT NULL default '',
PRIMARY KEY (iid)
......@@ -263,7 +277,6 @@ CREATE TABLE node (
nid int(10) unsigned NOT NULL auto_increment,
type varchar(16) NOT NULL default '',
title varchar(128) NOT NULL default '',
path varchar(250) NULL default '',
score int(11) NOT NULL default '0',
votes int(11) NOT NULL default '0',
uid int(10) NOT NULL default '0',
......@@ -272,19 +285,19 @@ CREATE TABLE node (
comment int(2) NOT NULL default '0',
promote int(2) NOT NULL default '0',
moderate int(2) NOT NULL default '0',
users text NOT NULL,
attributes varchar(255) NOT NULL default '',
teaser text NOT NULL,
body mediumtext NOT NULL,
users longtext NOT NULL,
teaser longtext NOT NULL,
body longtext NOT NULL,
changed int(11) NOT NULL default '0',
revisions text NOT NULL,
revisions longtext NOT NULL,
static int(2) NOT NULL default '0',
PRIMARY KEY (nid),
KEY type (type),
KEY title (title,type),
KEY promote (promote),
KEY node_type (type(4)),
KEY node_title_type (title,type(4)),
KEY status (status),
KEY uid (uid)
KEY uid (uid),
KEY node_moderate (moderate),
KEY node_promote_status (promote, status)
) TYPE=MyISAM;
--
......@@ -296,8 +309,20 @@ CREATE TABLE page (
link varchar(128) NOT NULL default '',
format tinyint(2) NOT NULL default '0',
description varchar(128) NOT NULL default '',
PRIMARY KEY (nid),
KEY nid (nid)
PRIMARY KEY (nid)
) TYPE=MyISAM;
--
-- Table structure for table 'url_alias'
--
CREATE TABLE url_alias (
pid int(10) unsigned NOT NULL auto_increment,
src varchar(128) NOT NULL default '',
dst varchar(128) NOT NULL default '',
PRIMARY KEY (pid),
UNIQUE KEY dst (dst),
UNIQUE KEY src (src)
) TYPE=MyISAM;
--
......@@ -306,7 +331,7 @@ CREATE TABLE page (
CREATE TABLE permission (
rid int(10) unsigned NOT NULL default '0',
perm text,
perm longtext,
tid int(10) unsigned NOT NULL default '0',
KEY rid (rid)
) TYPE=MyISAM;
......@@ -318,7 +343,7 @@ CREATE TABLE permission (
CREATE TABLE poll (
nid int(10) unsigned NOT NULL default '0',
runtime int(10) NOT NULL default '0',
voters text NOT NULL,
voters longtext NOT NULL,
active int(2) unsigned NOT NULL default '0',
PRIMARY KEY (nid)
) TYPE=MyISAM;
......@@ -362,7 +387,7 @@ CREATE TABLE search_index (
) TYPE=MyISAM;
--
-- Table structure for table 'sessesions'
-- Table structure for table 'sessions'
--
......@@ -371,7 +396,7 @@ CREATE TABLE sessions (
sid varchar(32) NOT NULL default '',
hostname varchar(128) NOT NULL default '',
timestamp int(11) NOT NULL default '0',
session text,
session longtext,
KEY uid (uid),
KEY sid (sid(4)),
KEY timestamp (timestamp)
......@@ -388,29 +413,10 @@ CREATE TABLE sequences (
) TYPE=MyISAM;
--
-- Table structure for table 'site'
-- Table structure for table 'node_counter'
--
CREATE TABLE site (
sid int(10) unsigned NOT NULL auto_increment,
name varchar(128) NOT NULL default '',
link varchar(255) NOT NULL default '',
size text NOT NULL,
changed int(11) NOT NULL default '0',
checked int(11) NOT NULL default '0',
feed varchar(255) NOT NULL default '',
refresh int(11) NOT NULL default '0',
threshold int(11) NOT NULL default '0',
PRIMARY KEY (sid),
UNIQUE KEY url (link),
UNIQUE KEY title (name)
) TYPE=MyISAM;
--
-- Table structure for table 'statistics'
--
CREATE TABLE statistics (
CREATE TABLE node_counter (
nid int(11) NOT NULL default '0',
totalcount bigint(20) unsigned NOT NULL default '0',
daycount mediumint(8) unsigned NOT NULL default '0',
......@@ -431,6 +437,8 @@ CREATE TABLE system (
type varchar(255) NOT NULL default '',
description varchar(255) NOT NULL default '',
status int(2) NOT NULL default '0',
throttle tinyint(1) DEFAULT '0' NOT NULL,
bootstrap int(2) NOT NULL default '0',
PRIMARY KEY (filename)
) TYPE=MyISAM;
......@@ -442,7 +450,7 @@ CREATE TABLE term_data (
tid int(10) unsigned NOT NULL auto_increment,
vid int(10) unsigned NOT NULL default '0',
name varchar(255) NOT NULL default '',
description text,
description longtext,
weight tinyint(4) NOT NULL default '0',
PRIMARY KEY (tid),
KEY vid (vid)
......@@ -497,11 +505,10 @@ CREATE TABLE term_synonym (
--
CREATE TABLE users (
uid int(10) unsigned NOT NULL auto_increment,
uid int(10) unsigned NOT NULL default '0',
name varchar(60) NOT NULL default '',
pass varchar(32) NOT NULL default '',
mail varchar(64) default '',
homepage varchar(128) NOT NULL default '',
mode tinyint(1) NOT NULL default '0',
sort tinyint(1) default '0',
threshold tinyint(1) default '0',
......@@ -512,7 +519,7 @@ CREATE TABLE users (
timezone varchar(8) default NULL,
language char(2) NOT NULL default '',
init varchar(64) default '',
data text,
data longtext,
rid int(10) unsigned NOT NULL default '0',
PRIMARY KEY (uid),
UNIQUE KEY name (name),
......@@ -524,8 +531,8 @@ CREATE TABLE users (
--
CREATE TABLE variable (
name varchar(32) NOT NULL default '',
value text NOT NULL,
name varchar(48) NOT NULL default '',
value longtext NOT NULL,
PRIMARY KEY (name)
) TYPE=MyISAM;
......@@ -536,12 +543,12 @@ CREATE TABLE variable (
CREATE TABLE vocabulary (
vid int(10) unsigned NOT NULL auto_increment,
name varchar(255) NOT NULL default '',
description text,
description longtext,
relations tinyint(3) unsigned NOT NULL default '0',
hierarchy tinyint(3) unsigned NOT NULL default '0',
multiple tinyint(3) unsigned NOT NULL default '0',
required tinyint(3) unsigned NOT NULL default '0',
nodes text,
nodes longtext,
weight tinyint(4) NOT NULL default '0',
PRIMARY KEY (vid)
) TYPE=MyISAM;
......@@ -554,7 +561,7 @@ CREATE TABLE watchdog (
wid int(5) NOT NULL auto_increment,
uid int(10) NOT NULL default '0',
type varchar(16) NOT NULL default '',
message text NOT NULL,
message longtext NOT NULL,
link varchar(255) NOT NULL default '',
location varchar(128) NOT NULL default '',
hostname varchar(128) NOT NULL default '',
......@@ -566,18 +573,25 @@ CREATE TABLE watchdog (
-- Insert some default values
--
INSERT INTO system VALUES ('modules/admin.module','admin','module','',1);
INSERT INTO system VALUES ('modules/block.module','block','module','',1);
INSERT INTO system VALUES ('modules/comment.module','comment','module','',1);
INSERT INTO system VALUES ('modules/help.module','help','module','',1);
INSERT INTO system VALUES ('modules/node.module','node','module','',1);
INSERT INTO system VALUES ('modules/page.module','page','module','',1);
INSERT INTO system VALUES ('modules/story.module','story','module','',1);
INSERT INTO system VALUES ('modules/taxonomy.module','taxonomy','module','',1);
INSERT INTO system VALUES ('themes/marvin/marvin.theme','marvin','theme','Internet explorer, Netscape, Opera',1);
INSERT INTO system VALUES ('modules/admin.module','admin','module','',1,0,0);
INSERT INTO system VALUES ('modules/block.module','block','module','',1,0,0);
INSERT INTO system VALUES ('modules/comment.module','comment','module','',1,0,0);
INSERT INTO system VALUES ('modules/help.module','help','module','',1,0,0);
INSERT INTO system VALUES ('modules/node.module','node','module','',1,0,0);
INSERT INTO system VALUES ('modules/page.module','page','module','',1,0,0);
INSERT INTO system VALUES ('modules/story.module','story','module','',1,0,0);
INSERT INTO system VALUES ('modules/taxonomy.module','taxonomy','module','',1,0,0);
INSERT INTO system VALUES ('themes/xtemplate/xtemplate.theme','xtemplate','theme','Internet explorer, Netscape, Opera',1,0,0);
INSERT INTO users (uid, name, mail, rid) VALUES ('0', '', '', '1');
INSERT INTO role (rid, name) VALUES (1, 'anonymous user');
INSERT INTO permission VALUES (1,'access content',0);
INSERT INTO role (rid, name) VALUES (2, 'authenticated user');
INSERT INTO permission VALUES (2,'access comments, access content, post comments, post comments without approval',0);
REPLACE variable SET name='update_start', value='s:10:"2003-04-19;"';
REPLACE variable SET name='theme_default', value='s:6:"marvin";';
REPLACE variable SET name='update_start', value='s:10:"2004-02-21;"';
REPLACE variable SET name='theme_default', value='s:9:"xtemplate";';
REPLACE blocks SET module = 'user', delta = '0', status = '1';
REPLACE blocks SET module = 'user', delta = '1', status = '1';
......
......@@ -25,6 +25,7 @@ CREATE TABLE accesslog (
uid integer default '0',
timestamp integer NOT NULL default '0'
);
CREATE INDEX accesslog_timestamp_idx ON accesslog (timestamp);
--
-- Table structure for authmap
......@@ -50,7 +51,8 @@ CREATE TABLE blocks (
weight smallint NOT NULL default '0',
region smallint NOT NULL default '0',
path varchar(255) NOT NULL default '',
custom smallint NOT NULL default '0'
custom smallint NOT NULL default '0',
throttle smallint NOT NULL default '0'
);
--
......@@ -104,6 +106,7 @@ CREATE TABLE cache (
data text default '',
expire integer NOT NULL default '0',
created integer NOT NULL default '0',
headers text default '',
PRIMARY KEY (cid)
);
......@@ -120,10 +123,9 @@ CREATE TABLE comments (
comment text NOT NULL default '',
hostname varchar(128) NOT NULL default '',
timestamp integer NOT NULL default '0',
link varchar(16) NOT NULL default '',
score integer NOT NULL default '0',
status smallint NOT NULL default '0',
thread varchar(255) NOT NULL,
thread varchar(255) default '',
users text default '',
PRIMARY KEY (cid)
);
......@@ -152,15 +154,28 @@ CREATE TABLE feed (
title varchar(255) NOT NULL default '',
url varchar(255) NOT NULL default '',
refresh integer NOT NULL default '0',
timestamp integer NOT NULL default '0',
checked integer NOT NULL default '0',
attributes varchar(255) NOT NULL default '',
link varchar(255) NOT NULL default '',
description text NOT NULL default '',
image text NOT NULL default '',
etag varchar(255) NOT NULL default '',
modified integer NOT NULL default '0',
PRIMARY KEY (fid),
UNIQUE (title),
UNIQUE (url)
);
--
-- Table structure for table 'filters'
--
CREATE TABLE filters (
module varchar(64) NOT NULL default '',
weight smallint DEFAULT '0' NOT NULL,
PRIMARY KEY (weight)
);
--
-- Table structure for table 'forum'
--
......@@ -168,7 +183,6 @@ CREATE TABLE feed (
CREATE TABLE forum (
nid integer NOT NULL default '0',
tid integer NOT NULL default '0',
icon varchar(255) NOT NULL default '',
shadow integer NOT NULL default '0',
PRIMARY KEY (nid)
);
......@@ -262,7 +276,6 @@ CREATE TABLE node (
nid SERIAL,
type varchar(16) NOT NULL default '',
title varchar(128) NOT NULL default '',
path varchar(250) NULL default '',
score integer NOT NULL default '0',
votes integer NOT NULL default '0',
uid integer NOT NULL default '0',
......@@ -272,7 +285,6 @@ CREATE TABLE node (
promote integer NOT NULL default '0',
moderate integer NOT NULL default '0',
users text NOT NULL default '',
attributes varchar(255) NOT NULL default '',
teaser text NOT NULL default '',
body text NOT NULL default '',
changed integer NOT NULL default '0',
......@@ -282,9 +294,25 @@ CREATE TABLE node (
);
CREATE INDEX node_type_idx ON node(type);
CREATE INDEX node_title_idx ON node(title,type);
CREATE INDEX node_promote_idx ON node(promote);
CREATE INDEX node_status_idx ON node(status);
CREATE INDEX node_uid_idx ON node(uid);
CREATE INDEX node_moderate_idx ON node (moderate);
CREATE INDEX node_promote_status_idx ON node (promote, status);
--
-- Table structure for table 'node_counter'
--
CREATE TABLE node_counter (
nid integer NOT NULL default '0',
totalcount integer NOT NULL default '0',
daycount integer NOT NULL default '0',
timestamp integer NOT NULL default '0',
PRIMARY KEY (nid)
);
CREATE INDEX node_counter_totalcount_idx ON node_counter(totalcount);
CREATE INDEX node_counter_daycount_idx ON node_counter(daycount);
CREATE INDEX node_counter_timestamp_idx ON node_counter(timestamp);
--
-- Table structure for page
......@@ -299,6 +327,18 @@ CREATE TABLE page (
);
CREATE INDEX page_nid_idx ON page(nid);
--
-- Table structure for table 'url_alias'
--
CREATE TABLE url_alias (
pid serial,
dst varchar(128) NOT NULL default '',
src varchar(128) NOT NULL default '',
PRIMARY KEY (pid)
);
CREATE INDEX url_alias_src_idx ON url_alias(src);
CREATE INDEX url_alias_dst_idx ON url_alias(dst);
--
-- Table structure for permission
--
......@@ -384,40 +424,6 @@ CREATE TABLE sessions (
-- PRIMARY KEY (name)
-- );
--
-- Table structure for site
--
CREATE TABLE site (
sid SERIAL,
name varchar(128) NOT NULL default '',
link varchar(255) NOT NULL default '',
size text NOT NULL default '',
changed integer NOT NULL default '0',
checked integer NOT NULL default '0',
feed varchar(255) NOT NULL default '',
refresh integer NOT NULL default '0',
threshold integer NOT NULL default '0',
PRIMARY KEY (sid),
UNIQUE (name),
UNIQUE (link)
);
--
-- Table structure for table 'statistics'
--
CREATE TABLE statistics (
nid integer NOT NULL default '0',
totalcount integer NOT NULL default '0',
daycount integer NOT NULL default '0',
timestamp integer NOT NULL default '0',
PRIMARY KEY (nid)
);
CREATE INDEX statistics_totalcount_idx ON statistics(totalcount);
CREATE INDEX statistics_daycount_idx ON statistics(daycount);
CREATE INDEX statistics_timestamp_idx ON statistics(timestamp);
--
-- Table structure for system
--
......@@ -428,11 +434,11 @@ CREATE TABLE system (
type varchar(255) NOT NULL default '',
description varchar(255) NOT NULL default '',
status integer NOT NULL default '0',
throttle smallint NOT NULL default '0',
bootstrap integer NOT NULL default '0',
PRIMARY KEY (filename)
);
--
-- Table structure for term_data
--
......@@ -496,11 +502,10 @@ CREATE INDEX term_synonym_name_idx ON term_synonym(name);
--
CREATE TABLE users (
uid SERIAL,
uid integer NOT NULL default '0',
name varchar(60) NOT NULL default '',
pass varchar(32) NOT NULL default '',
mail varchar(64) default '',
homepage varchar(128) NOT NULL default '',
mode smallint NOT NULL default '0',
sort smallint default '0',
threshold smallint default '0',
......@@ -518,12 +523,14 @@ CREATE TABLE users (
);
CREATE INDEX users_timestamp_idx ON users(timestamp);
CREATE SEQUENCE users_uid_seq INCREMENT 1 START 1;
--
-- Table structure for variable
--
CREATE TABLE variable (
name varchar(32) NOT NULL default '',
name varchar(48) NOT NULL default '',
value text NOT NULL default '',
PRIMARY KEY (name)
);
......@@ -565,18 +572,25 @@ CREATE TABLE watchdog (
-- Insert some default values
--
INSERT INTO system VALUES ('modules/admin.module','admin','module','',1);
INSERT INTO system VALUES ('modules/block.module','block','module','',1);
INSERT INTO system VALUES ('modules/comment.module','comment','module','',1);
INSERT INTO system VALUES ('modules/help.module','help','module','',1);
INSERT INTO system VALUES ('modules/node.module','node','module','',1);
INSERT INTO system VALUES ('modules/page.module','page','module','',1);
INSERT INTO system VALUES ('modules/story.module','story','module','',1);
INSERT INTO system VALUES ('modules/taxonomy.module','taxonomy','module','',1);
INSERT INTO system VALUES ('themes/marvin/marvin.theme','marvin','theme','Internet explorer, Netscape, Opera',1);
INSERT INTO system VALUES ('modules/admin.module','admin','module','',1,0,0);
INSERT INTO system VALUES ('modules/block.module','block','module','',1,0,0);
INSERT INTO system VALUES ('modules/comment.module','comment','module','',1,0,0);
INSERT INTO system VALUES ('modules/help.module','help','module','',1,0,0);
INSERT INTO system VALUES ('modules/node.module','node','module','',1,0,0);
INSERT INTO system VALUES ('modules/page.module','page','module','',1,0,0);
INSERT INTO system VALUES ('modules/story.module','story','module','',1,0,0);
INSERT INTO system VALUES ('modules/taxonomy.module','taxonomy','module','',1,0,0);
INSERT INTO system VALUES ('themes/xtemplate/xtemplate.theme','xtemplate','theme','Internet explorer, Netscape, Opera',1,0,0);
INSERT INTO variable(name,value) VALUES('update_start', 's:10:"2004-02-21";');
INSERT INTO variable(name,value) VALUES('theme_default','s:9:"xtemplate";');
INSERT INTO users(uid,name,mail,rid) VALUES(0,'','', '1');
INSERT INTO role (rid, name) VALUES (1, 'anonymous user');
INSERT INTO permission VALUES (1,'access content',0);
INSERT INTO variable(name,value) VALUES('update_start', 's:10:"2003-04-19";');
INSERT INTO variable(name,value) VALUES('theme_default','s:6:"marvin";');
INSERT INTO role (rid, name) VALUES (2, 'authenticated user');
INSERT INTO permission VALUES (2,'access comments, access content, post comments, post comments without approval',0);
INSERT INTO blocks(module,delta,status) VALUES('user', '0', '1');
INSERT INTO blocks(module,delta,status) VALUES('user', '1', '1');
......@@ -594,3 +608,8 @@ BEGIN
END;
' LANGUAGE 'plpgsql';
CREATE FUNCTION "rand"() RETURNS float AS '
BEGIN
RETURN random();
END;
' LANGUAGE 'plpgsql';
<?php
/* $Id$ */
// Define the various updates in an array("date : comment" => "function");
$sql_updates = array(
"2002-06-22: first update since Drupal 4.0.0 release" => "update_32",
"2002-07-07" => "update_33",
"2002-07-31" => "update_34",
"2002-08-10" => "update_35",
"2002-08-16" => "update_36",
"2002-08-19" => "update_37",
"2002-08-26" => "update_38",
"2002-09-15" => "update_39",
"2002-09-17" => "update_40",
"2002-10-13" => "update_41",
"2002-10-17" => "update_42",
"2002-10-26" => "update_43",
"2002-11-08" => "update_44",
"2002-11-20" => "update_45",
"2002-12-10: first update since Drupal 4.1.0 release" => "update_46",
"2002-12-29" => "update_47",
"2003-01-03" => "update_48",
"2003-01-05" => "update_49",
"2003-01-15" => "update_50",
"2003-04-19" => "update_51",
"2003-04-20" => "update_52",
"2003-05-18" => "update_53",
"2003-05-24" => "update_54",
"2003-05-31" => "update_55",
"2003-06-04" => "update_56",
"2003-06-08" => "update_57",
"2003-06-08: first update since Drupal 4.2.0 release" => "update_58",
"2003-08-05" => "update_59",
"2003-08-15" => "update_60",
"2003-08-20" => "update_61",
"2003-08-27" => "update_62",
"2003-09-09" => "update_63",
"2003-09-10" => "update_64",
"2003-09-29" => "update_65",
"2003-09-30" => "update_66",
"2003-10-11" => "update_67",
"2003-10-20" => "update_68",
"2003-10-22" => "update_69",
"2003-10-27" => "update_70",
"2003-11-17: first update since Drupal 4.3.0 release" => "update_71",
"2003-11-27" => "update_72",
"2003-12-03" => "update_73",
"2003-12-06" => "update_74",
"2004-01-06" => "update_75",
"2004-01-11" => "update_76",
"2004-01-13" => "update_77",
"2004-02-03" => "update_78",
"2004-02-21" => "update_79"
);
function update_32() {
$ret = array();
$ret[] = update_sql("ALTER TABLE users ADD index (sid(4))");
$ret[] = update_sql("ALTER TABLE users ADD index (timestamp)");
$ret[] = update_sql("ALTER TABLE users ADD UNIQUE KEY name (name)");
return $ret;
}
function update_33() {
$ret = array();
$result = db_query("SELECT * FROM variable WHERE value NOT LIKE 's:%;'");
// NOTE: the "WHERE"-part of the query above avoids variables to get serialized twice.
while ($variable = db_fetch_object($result)) {
variable_set($variable->name, $variable->value);
}
return $ret;
}
function update_34() {
$ret = array();
$ret[] = update_sql("ALTER TABLE feed MODIFY refresh int(10) NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE feed MODIFY timestamp int (10) NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE users CHANGE session session TEXT");
return $ret;
}
function update_35() {
$ret = array();
$ret[] = update_sql("ALTER TABLE poll_choices ADD INDEX (nid)");
return $ret;
}
function update_36() {
$ret = array();
$ret[] = update_sql("ALTER TABLE rating CHANGE old previous int(6) NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE rating CHANGE new current int(6) NOT NULL default '0'");
return $ret;
}
function update_37() {
$ret = array();
$ret[] = update_sql("DROP TABLE IF EXISTS sequences");
$ret[] = update_sql("CREATE TABLE sequences (
name VARCHAR(255) NOT NULL PRIMARY KEY,
id INT UNSIGNED NOT NULL
) TYPE=MyISAM");
if ($max = db_result(db_query("SELECT MAX(nid) FROM node"))) {
$ret[] = update_sql("REPLACE INTO sequences VALUES ('node', $max)");
}
if ($max = db_result(db_query("SELECT MAX(cid) FROM comments"))) {
$ret[] = update_sql("REPLACE INTO sequences VALUES ('comments', $max)");
}
// NOTE: move the comments bit down as soon as we switched to use the new comment module!
if ($max = db_result(db_query("SELECT MAX(tid) FROM term_data"))) {
$ret[] = update_sql("REPLACE INTO sequences VALUES ('term_data', $max)");
}
return $ret;
}
function update_38() {
$ret = array();
$ret[] = update_sql("ALTER TABLE watchdog CHANGE message message text NOT NULL default ''");
return $ret;
}
function update_39() {
$ret = array();
$ret[] = update_sql("DROP TABLE moderate");
$ret[] = update_sql("ALTER TABLE comments ADD score MEDIUMINT NOT NULL");
$ret[] = update_sql("ALTER TABLE comments ADD status TINYINT UNSIGNED NOT NULL");
$ret[] = update_sql("ALTER TABLE comments ADD users MEDIUMTEXT");
$ret[] = update_sql("CREATE TABLE moderation_votes (
mid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
vote VARCHAR(255),
weight TINYINT NOT NULL
)");
$ret[] = update_sql("CREATE TABLE moderation_roles (
rid INT UNSIGNED NOT NULL,
mid INT UNSIGNED NOT NULL,
value TINYINT NOT NULL
)");
$ret[] = update_sql("ALTER TABLE moderation_roles ADD INDEX (rid)");
$ret[] = update_sql("ALTER TABLE moderation_roles ADD INDEX (mid)");
$ret[] = update_sql("CREATE TABLE moderation_filters (
fid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
filter VARCHAR(255) NOT NULL,
minimum SMALLINT NOT NULL
)");
$ret[] = update_sql("DELETE FROM moderation_votes");
$ret[] = update_sql("INSERT INTO moderation_votes VALUES (1, '+1', 0)");
$ret[] = update_sql("INSERT INTO moderation_votes VALUES (2, '-1', 1)");
$ret[] = update_sql("DELETE FROM moderation_roles");
$ret[] = update_sql("INSERT INTO moderation_roles VALUES (2, 1, 1)");
$ret[] = update_sql("INSERT INTO moderation_roles VALUES (2, 2, -1)");
$ret[] = update_sql("CREATE TABLE forum (
nid int unsigned not null primary key,
icon varchar(255) not null,
shadow int unsigned not null
)");
return $ret;
}
function update_40() {
$ret = array();
if ($max = db_result(db_query("SELECT MAX(cid) FROM comments"))) {
$ret[] = update_sql("REPLACE INTO sequences VALUES ('comments', $max)");
}
return $ret;
}
function update_41() {
$ret = array();
$ret[] = update_sql("CREATE TABLE statistics (
nid int(11) NOT NULL,
totalcount bigint UNSIGNED DEFAULT '0' NOT NULL,
daycount mediumint UNSIGNED DEFAULT '0' NOT NULL,
timestamp int(11) UNSIGNED DEFAULT '0' NOT NULL,
PRIMARY KEY (nid),
INDEX (totalcount),
INDEX (daycount),
INDEX (timestamp)
)");
$ret[] = update_sql("CREATE TABLE accesslog (
nid int(11) UNSIGNED DEFAULT '0',
url varchar(255),
hostname varchar(128),
uid int(10) UNSIGNED DEFAULT '0',
timestamp int(11) UNSIGNED NOT NULL
)");
return $ret;
}
function update_42() {
$ret = array();
$ret[] = update_sql("DROP TABLE modules");
$ret[] = update_sql("DROP TABLE layout");
$ret[] = update_sql("DROP TABLE referrer");
return $ret;
}
function update_43() {
$ret = array();
$ret[] = update_sql("ALTER TABLE blocks DROP remove");
$ret[] = update_sql("ALTER TABLE blocks DROP name");
$ret[] = update_sql("UPDATE boxes SET type = 0 WHERE type = 1");
$ret[] = update_sql("UPDATE boxes SET type = 1 WHERE type = 2");
return $ret;
}
function update_44() {
$ret = array();
$ret[] = update_sql("UPDATE system SET filename = CONCAT('modules/', filename) WHERE type = 'module'");
return $ret;
}
function update_45() {
$ret = array();
$ret[] = update_sql("ALTER TABLE page ADD description varchar(128) NOT NULL default ''");
return $ret;
}
function update_46() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("ALTER TABLE cache ADD created integer");
}
else {
$ret[] = update_sql("ALTER TABLE cache ADD created int(11) NOT NULL default '0'");
}
return $ret;
}
function update_47() {
$ret = array();
if ($max = db_result(db_query("SELECT MAX(vid) FROM vocabulary"))) {
$ret[] = update_sql("REPLACE INTO sequences VALUES ('vocabulary', $max)");
}
return $ret;
}
function update_48() {
$ret = array();
$ret[] = update_sql("ALTER TABLE watchdog ADD link varchar(255) DEFAULT '' NULL");
return $ret;
}
function update_49() {
$ret = array();
/*
** Make sure the admin module is added to the system table or the
** admin menus won't show up.
*/
$ret[] = update_sql("DELETE FROM system WHERE name = 'admin';");
$ret[] = update_sql("INSERT INTO system VALUES ('modules/admin.module','admin','module','',1)");
return $ret;
}
function update_50() {
$ret = array();
$ret[] = update_sql("ALTER TABLE forum ADD tid INT UNSIGNED NOT NULL");
$result = db_queryd("SELECT n.nid, t.tid FROM node n, term_node t WHERE n.nid = t.nid AND type = 'forum'");
while ($node = db_fetch_object($result)) {
db_queryd("UPDATE forum SET tid = %d WHERE nid = %d", $node->tid, $node->nid);
}
$ret[] = update_sql("ALTER TABLE forum ADD INDEX (tid)");
return $ret;
}
function update_51() {
$ret = array();
$ret[] = update_sql("ALTER TABLE blocks CHANGE delta delta varchar(32) NOT NULL default '0'");
return $ret;
}
function update_52() {
$ret = array();
$ret[] = update_sql("UPDATE sequences SET name = 'comments_cid' WHERE name = 'comments';");
$ret[] = update_sql("UPDATE sequences SET name = 'node_nid' WHERE name = 'node';");
$ret[] = update_sql("DELETE FROM sequences WHERE name = 'import'");
$ret[] = update_sql("DELETE FROM sequences WHERE name = 'bundle_bid'"); // in case we would run this entry twice
$ret[] = update_sql("DELETE FROM sequences WHERE name = 'feed_fid'"); // in case we would run this entry twice
$bundles = db_result(db_query("SELECT MAX(bid) FROM bundle;"));
$ret[] = update_sql("INSERT INTO sequences (name, id) VALUES ('bundle_bid', '$bundles')");
$feeds = db_result(db_query("SELECT MAX(fid) FROM feed;"));
$ret[] = update_sql("INSERT INTO sequences (name, id) VALUES ('feed_fid', '$feeds')");
$ret[] = update_sql("UPDATE sequences SET name = 'vocabulary_vid' WHERE name = 'vocabulary';");
$ret[] = update_sql("UPDATE sequences SET name = 'term_data_tid' WHERE name = 'term_data'");
return $ret;
}
function update_53() {
$ret = array();
$ret[] = update_sql("CREATE INDEX book_parent ON book(parent);");
return $ret;
}
function update_54() {
$ret = array();
$ret[] = update_sql("ALTER TABLE locales CHANGE string string BLOB DEFAULT '' NOT NULL");
return $ret;
}
function update_55() {
$ret = array();
$ret[] = update_sql("ALTER TABLE site ADD checked INT(11) NOT NULL;");
$ret[] = update_sql("ALTER TABLE site CHANGE timestamp changed INT(11) NOT NULL;");
return $ret;
}
function update_56() {
$ret = array();
$ret[] = update_sql("ALTER TABLE vocabulary CHANGE types nodes TEXT DEFAULT '' NOT NULL");
return $ret;
}
function update_57() {
$ret = array();
$ret[] = update_sql("DELETE FROM variable WHERE name = 'site_charset'");
return $ret;
}
function update_58() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("ALTER TABLE {node} ADD path varchar(250) NULL");
$ret[] = update_sql("ALTER TABLE {node} ALTER COLUMN path SET DEFAULT ''");
}
else {
$ret[] = update_sql("ALTER TABLE {node} ADD path varchar(250) NULL default ''");
}
return $ret;
}
function update_59() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("ALTER TABLE {comments} ADD thread VARCHAR(255)");
$ret[] = update_sql("ALTER TABLE {comments} ALTER COLUMN thread SET NOT NULL");
}
else {
$ret[] = update_sql("ALTER TABLE {comments} ADD thread VARCHAR(255) NOT NULL");
}
$result = db_query("SELECT DISTINCT(nid) FROM {comments} WHERE thread = ''");
while ($node = db_fetch_object($result)) {
$result2 = db_query("SELECT cid, pid FROM {comments} where nid = '%d' ORDER BY timestamp", $node->nid);
$comments = array();
while ($comment = db_fetch_object($result2)) {
$comments[$comment->cid] = $comment;
}
$structure = array();
$structure = _update_thread_structure($comments, 0, -1, $structure);
foreach ($structure as $cid => $thread) {
$new_parts = array();
foreach(explode(".", $thread) as $part) {
if ($part > 9) {
$start = substr($part, 0, strlen($part) - 1);
$end = substr($part, -1, 1);
$new_parts[] = str_repeat("9", $start).$end;
}
else {
$new_parts[] = $part;
}
}
$thread = implode(".", $new_parts);
db_query("UPDATE {comments} SET thread = '%s' WHERE cid = '%d'", $thread."/", $comments[$cid]->cid);
}
}
return $ret;
}
function _update_thread_structure($comments, $pid, $depth, $structure) {
$ret = array();
$depth++;
foreach ($comments as $key => $comment) {
if ($comment->pid == $pid) {
if ($structure[$comment->pid]) {
$structure[$comment->cid] = $structure[$comment->pid]."."._update_next_thread($structure, $structure[$comment->pid]);
}
else {
$structure[$comment->cid] = _update_next_thread($structure, "");
}
$structure = _update_thread_structure($comments, $comment->cid, $depth, $structure);
}
}
return $structure;
return $ret;
}
function update_60() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {forum} DROP icon");
return $ret;
}
function update_61() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("CREATE TABLE {sessions} (
uid integer NOT NULL,
sid varchar(32) NOT NULL default '',
hostname varchar(128) NOT NULL default '',
timestamp integer NOT NULL default '0',
session text,
PRIMARY KEY (sid)
);");
$ret[] = update_sql("ALTER TABLE {users} DROP session;");
$ret[] = update_sql("ALTER TABLE {users} DROP hostname;");
$ret[] = update_sql("ALTER TABLE {users} DROP sid;");
}
else {
$ret[] = update_sql("CREATE TABLE IF NOT EXISTS {sessions} (
uid int(10) unsigned NOT NULL,
sid varchar(32) NOT NULL default '',
hostname varchar(128) NOT NULL default '',
timestamp int(11) NOT NULL default '0',
session text,
KEY uid (uid),
KEY sid (sid(4)),
KEY timestamp (timestamp)
)");
$ret[] = update_sql("ALTER TABLE {users} DROP session;");
$ret[] = update_sql("ALTER TABLE {users} DROP hostname;");
$ret[] = update_sql("ALTER TABLE {users} DROP sid;");
}
return $ret;
}
function update_62() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("CREATE INDEX accesslog_timestamp ON {accesslog} (timestamp)");
$ret[] = update_sql("DROP INDEX node_type_idx");
$ret[] = update_sql("DROP INDEX node_title_idx");
$ret[] = update_sql("DROP INDEX node_promote_idx");
$ret[] = update_sql("CREATE INDEX node_type ON {node} (type)");
$ret[] = update_sql("CREATE INDEX node_title_type ON {node} (title,type)");
$ret[] = update_sql("CREATE INDEX node_moderate ON {node} (moderate)");
$ret[] = update_sql("CREATE INDEX node_path ON {node} (path)");
$ret[] = update_sql("CREATE INDEX node_promote_status ON {node} (promote, status)");
}
else {
$ret[] = update_sql("ALTER TABLE {accesslog} ADD INDEX accesslog_timestamp (timestamp)");
$ret[] = update_sql("ALTER TABLE {node} DROP INDEX type");
$ret[] = update_sql("ALTER TABLE {node} DROP INDEX title");
$ret[] = update_sql("ALTER TABLE {node} DROP INDEX promote");
$ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_type (type(4))");
$ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_title_type (title,type(4))");
$ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_moderate (moderate)");
$ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_path (path(5))");
$ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_promote_status (promote, status)");
}
return $ret;
}
function _update_next_thread($structure, $parent) {
$ret = array();
do {
$val++;
if ($parent) {
$thread = "$parent.$val";
}
else {
$thread = $val;
}
} while (array_search($thread, $structure));
return $val;
return $ret;
}
function update_63() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("INSERT INTO {users} (uid, name, mail, timestamp) VALUES ('0', '', '', '". time() ."')");
}
else {
$ret[] = update_sql("ALTER TABLE {users} CHANGE uid uid int(10) unsigned NOT NULL default '0'");
$ret[] = update_sql("INSERT INTO {users} (uid, name, mail, timestamp) VALUES ('0', '', '', '". time() ."')");
$users = db_result(db_query("SELECT MAX(uid) FROM {users};"));
$ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('users_uid', '$users')");
}
return $ret;
}
function update_64() {
$ret = array();
$ret[] = update_sql("UPDATE {users} SET rid = 1 WHERE uid = 0");
return $ret;
}
function update_65() {
$ret = array();
// PostgreSQL-only update.
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("CREATE FUNCTION \"rand\"() RETURNS float AS '
BEGIN
RETURN random();
END;' LANGUAGE 'plpgsql'");
}
return $ret;
}
function update_66() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("CREATE TABLE {path} (
pid serial,
src varchar(128) NOT NULL default '',
dst varchar(128) NOT NULL default '',
PRIMARY KEY (pid)
)");
$ret[] = update_sql("CREATE INDEX path_src_idx ON {path}(src)");
$ret[] = update_sql("CREATE INDEX path_dst_idx ON {path}(dst)");
$result = db_query("SELECT nid, path FROM {node} WHERE path != ''");
while ($node = db_fetch_object($result)) {
$ret[] = update_sql("INSERT INTO {path} (src, dst) VALUES ('node/view/$node->nid', '". check_query($node->path) ."')");
}
}
else {
$ret[] = update_sql("CREATE TABLE {path} (
pid int(10) unsigned NOT NULL auto_increment,
src varchar(128) NOT NULL default '',
dst varchar(128) NOT NULL default '',
PRIMARY KEY (pid),
UNIQUE KEY src (src),
UNIQUE KEY dst (dst)
)");
// Migrate the existing paths:
$result = db_query("SELECT nid, path FROM {node} WHERE path != ''");
while ($node = db_fetch_object($result)) {
$ret[] = update_sql("INSERT INTO {path} (src, dst) VALUES ('node/view/$node->nid', '". check_query($node->path) ."')");
}
$ret[] = update_sql("ALTER TABLE {node} DROP path");
}
return $ret;
}
function update_67() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
// Taking no action. PostgreSQL is not always capable of dropping columns.
}
else {
$ret[] = update_sql("ALTER TABLE {users} DROP homepage");
}
return $ret;
}
function update_68() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
// Unneccesary. The PostgreSQL port was already using a sequence.
}
else {
$max = db_result(db_query("SELECT MAX(aid) FROM {access};"));
$ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('access_aid', '$max')");
$ret[] = update_sql("ALTER TABLE {access} CHANGE aid aid tinyint(10) NOT NULL ");
}
return $ret;
}
function update_69() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
/* Rename the statistics table to node_counter */
$ret[] = update_sql("ALTER TABLE {statistics} RENAME TO {node_counter}");
$ret[] = update_sql("DROP INDEX {statistics}_totalcount_idx");
$ret[] = update_sql("DROP INDEX {statistics}_daycount_idx");
$ret[] = update_sql("DROP INDEX {statistics}_timestamp_idx");
$ret[] = update_sql("CREATE INDEX {node_counter}_totalcount_idx ON {node_counter}(totalcount)");
$ret[] = update_sql("CREATE INDEX {node_counter}_daycount_idx ON {node_counter}(daycount)");
$ret[] = update_sql("CREATE INDEX {node_counter}_timestamp_idx ON {node_counter}(timestamp)");
/* Rename the path table to url_alias */
$ret[] = update_sql("ALTER TABLE {path} RENAME TO {url_alias}");
$ret[] = update_sql("ALTER TABLE {path}_pid_seq RENAME TO {url_alias}_pid_seq");
}
else {
$ret[] = update_sql("ALTER TABLE {statistics} RENAME TO {node_counter}");
$ret[] = update_sql("ALTER TABLE {path} RENAME TO {url_alias}");
$ret[] = update_sql("UPDATE {sequences} SET name = '{url_alias}_pid' WHERE name = '{path}_pid'");
}
$ret[] = update_sql("UPDATE {users} SET name = '' WHERE uid = 0;");
return $ret;
}
function update_70() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {variable} CHANGE name name varchar(48) NOT NULL");
return $ret;
}
function update_71() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("ALTER TABLE {system} ADD bootstrap integer");
}
else {
$ret[] = update_sql("ALTER TABLE {system} ADD bootstrap int(2)");
}
return $ret;
}
function update_72() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("ALTER TABLE {blocks} ADD throttle smallint");
$ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN throttle SET DEFAULT '0'");
$ret[] = update_sql("UPDATE {blocks} SET throttle = 0");
$ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN throttle SET NOT NULL");
}
else {
$ret[] = update_sql("ALTER TABLE {blocks} ADD throttle tinyint(1) NOT NULL DEFAULT '0'");
}
return $ret;
}
function update_73() {
$ret = array();
/* MySQL only update */
if ($GLOBALS["db_type"] == "mysql") {
$ret[] = update_sql("ALTER TABLE {book} CHANGE log log longtext");
$ret[] = update_sql("ALTER TABLE {boxes} CHANGE body body longtext");
$ret[] = update_sql("ALTER TABLE {cache} CHANGE data data longtext");
$ret[] = update_sql("ALTER TABLE {comments} CHANGE comment comment longtext");
$ret[] = update_sql("ALTER TABLE {comments} CHANGE users users longtext");
$ret[] = update_sql("ALTER TABLE {directory} CHANGE slogan slogan longtext");
$ret[] = update_sql("ALTER TABLE {directory} CHANGE mission mission longtext");
$ret[] = update_sql("ALTER TABLE {feed} CHANGE description description longtext");
$ret[] = update_sql("ALTER TABLE {item} CHANGE description description longtext");
$ret[] = update_sql("ALTER TABLE {node} CHANGE users users longtext");
$ret[] = update_sql("ALTER TABLE {node} CHANGE teaser teaser longtext");
$ret[] = update_sql("ALTER TABLE {node} CHANGE body body longtext");
$ret[] = update_sql("ALTER TABLE {node} CHANGE revisions revisions longtext");
$ret[] = update_sql("ALTER TABLE {permission} CHANGE perm perm longtext");
$ret[] = update_sql("ALTER TABLE {poll} CHANGE voters voters longtext");
$ret[] = update_sql("ALTER TABLE {sessions} CHANGE session session longtext");
$ret[] = update_sql("ALTER TABLE {term_data} CHANGE description description longtext");
$ret[] = update_sql("ALTER TABLE {users} CHANGE data data longtext");
$ret[] = update_sql("ALTER TABLE {variable} CHANGE value value longtext");
$ret[] = update_sql("ALTER TABLE {vocabulary} CHANGE description description longtext");
$ret[] = update_sql("ALTER TABLE {vocabulary} CHANGE nodes nodes longtext");
$ret[] = update_sql("ALTER TABLE {watchdog} CHANGE message message longtext");
}
return $ret;
}
function update_74() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("ALTER TABLE {system} ADD throttle smallint");
$ret[] = update_sql("ALTER TABLE {system} ALTER COLUMN throttle SET DEFAULT '0'");
$ret[] = update_sql("UPDATE {system} SET throttle = 0");
$ret[] = update_sql("ALTER TABLE {system} ALTER COLUMN throttle SET NOT NULL");
}
else {
$ret[] = update_sql("ALTER TABLE {system} ADD throttle tinyint(1) NOT NULL DEFAULT '0'");
}
return $ret;
}
function update_75() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("ALTER TABLE {feed} ADD etag text");
$ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN etag SET DEFAULT ''");
$ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN etag SET NOT NULL");
$ret[] = update_sql("ALTER TABLE {feed} ADD modified integer");
$ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN modified SET DEFAULT '0'");
$ret[] = update_sql("UPDATE {feed} SET modified = 0");
$ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN modified SET NOT NULL");
$ret[] = update_sql("ALTER TABLE {feed} RENAME timestamp TO checked");
$ret[] = update_sql("UPDATE {blocks} SET module = 'aggregator' WHERE module = 'import'");
$ret[] = update_sql("UPDATE {system} SET filename = 'modules/aggregator.module', name = 'aggregator' WHERE filename = 'modules/import.module'");
}
else {
$ret[] = update_sql("ALTER TABLE {feed} ADD etag varchar(255) NOT NULL DEFAULT ''");
$ret[] = update_sql("ALTER TABLE {feed} ADD modified int(10) NOT NULL DEFAULT 0");
$ret[] = update_sql("ALTER TABLE {feed} CHANGE timestamp checked int(10) NOT NULL DEFAULT 0");
$ret[] = update_sql("UPDATE {blocks} SET module = 'aggregator' WHERE module = 'import'");
$ret[] = update_sql("UPDATE {system} SET filename = 'modules/aggregator.module', name = 'aggregator' WHERE filename = 'modules/import.module'");
}
return $ret;
}
function update_76() {
$ret = array();
if ($GLOBALS["db_type"] == "pgsql") {
$ret[] = update_sql("ALTER TABLE {feed} ADD image text");
} else {
$ret[] = update_sql("ALTER TABLE {feed} ADD image longtext");
}
return $ret;
}
function update_77() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {cache} ADD headers text");
return $ret;
}
function update_78() {
$ret = array();
if ($GLOBALS["db_type"] == "mysql") {
$ret[] = update_sql("CREATE TABLE {filters} (
module varchar(64) NOT NULL default '',
weight tinyint(2) DEFAULT '0' NOT NULL,
KEY weight (weight)
)");
}
else {
$ret[] = update_sql("CREATE TABLE {filters} (
module varchar(64) NOT NULL DEFAULT '',
weight smallint NOT NULL DEFAULT 0
);");
$ret[] = update_sql("CREATE INDEX {filters_weight} ON {filters} (weight);");
}
return $ret;
}
function update_79() {
$ret = array();
// Works for both mysql and postgresql
$ret[] = update_sql("ALTER TABLE {node} DROP attributes");
$ret[] = update_sql("ALTER TABLE {comments} DROP link");
return $ret;
}
function update_sql($sql) {
$edit = $_POST["edit"];
$result = db_query($sql);
if ($result) {
return array('1', nl2br(htmlentities($sql)) ." ", "<div style=\"color: green;\">OK</div>\n");
}
else {
return array('0', nl2br(htmlentities($sql)) ." ", "<div style=\"color: red;\">FAILED</div>\n");
}
}
?>
<?php
// $Id$
include_once "includes/common.inc";
$errors = array(
500 => "500 error: internal server error",
404 => "404 error: '". $_SERVER["REDIRECT_URL"] ."' not found",
403 => "403 error: access denied - forbidden",
401 => "401 error: authorization required",
400 => "400 error: bad request"
);
if ($errors[$_SERVER["REDIRECT_STATUS"]]) {
watchdog("httpd", $errors[$_SERVER["REDIRECT_STATUS"]]);
header("HTTP/1.0 ". $errors[$_SERVER["REDIRECT_STATUS"]]);
}
include_once("$base_url/index.php");
?>
<?php
/* $Id$ */
function conf_init() {
/*
** Try finding a matching configuration file by stripping the website's
** URI from left to right. If no configuration file is found, return a
** default value 'conf'.
*/
$uri = $_SERVER["PHP_SELF"];
$file = strtolower(strtr($_SERVER["HTTP_HOST"] . substr($uri, 0, strrpos($uri, "/")), "/:", ".."));
while (strlen($file) > 4) {
if (file_exists("includes/$file.php")) {
return $file;
}
else {
$file = substr($file, strpos($file, ".") + 1);
}
}
return "conf";
}
function variable_init($conf = array()) {
$result = db_query("SELECT * FROM {variable} ");
while ($variable = db_fetch_object($result)) {
if (!isset($conf[$variable->name])) {
$conf[$variable->name] = unserialize($variable->value);
}
}
return $conf;
}
function variable_get($name, $default) {
global $conf;
return isset($conf[$name]) ? $conf[$name] : $default;
}
function variable_set($name, $value) {
global $conf;
db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
$conf[$name] = $value;
}
function variable_del($name) {
global $conf;
db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
unset($conf[$name]);
}
function cache_get($key) {
$cache = db_fetch_object(db_query("SELECT data, created, headers FROM {cache} WHERE cid = '%s'", $key));
return $cache->data ? $cache : 0;
}
function cache_set($cid, $data, $expire = 0, $headers = NULL) {
db_query("UPDATE {cache} SET data = '%s', created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $data, time(), $expire, $headers, $cid);
if (!db_affected_rows()) {
db_query("INSERT INTO {cache} (cid, data, created, expire, headers) VALUES('%s', '%s', %d, %d, '%s')", $cid, $data, time(), $expire, $headers);
}
}
function cache_clear_all($cid = NULL) {
if (empty($cid)) {
db_query("DELETE FROM {cache} WHERE expire <> 0");
}
else {
db_query("DELETE FROM {cache} WHERE cid = '%s'", $cid);
}
}
function page_set_cache() {
global $user;
if (!$user->uid && $_SERVER["REQUEST_METHOD"] == "GET") {
if ($data = ob_get_contents()) {
cache_set(request_uri(), $data, 1, drupal_get_headers());
}
}
}
function page_get_cache() {
global $user;
$cache = NULL;
if (!$user->uid && $_SERVER["REQUEST_METHOD"] == "GET") {
$cache = cache_get(request_uri());
if (empty($cache)) {
ob_start();
}
}
return $cache;
}
function drupal_page_header() {
if (variable_get("dev_timer", 0)) {
timer_start();
}
if (variable_get("cache", 0)) {
if ($cache = page_get_cache()) {
// Set default values:
$date = gmdate("D, d M Y H:i:s", $cache->created) ." GMT";
$etag = '"'. md5($date) .'"';
// Check http headers:
$modified_since = isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) ? $_SERVER["HTTP_IF_MODIFIED_SINCE"] == $date : NULL;
if (!empty($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && ($timestamp = strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"])) != -1) {
$modified_since = $cache->created <= $timestamp;
}
else {
$modified_since = NULL;
}
$none_match = !empty($_SERVER["HTTP_IF_NONE_MATCH"]) ? $_SERVER["HTTP_IF_NONE_MATCH"] == $etag : NULL;
// The type checking here is very important, be careful when changing entries.
if (($modified_since !== NULL || $none_match !== NULL) && $modified_since !== false && $none_match !== false) {
header("HTTP/1.0 304 Not Modified");
exit();
}
// Send appropriate response:
header("Last-Modified: $date");
header("ETag: $etag");
/*
** Send the original request's headers. We send them one after
** another so PHP's header() function can deal with duplicate
** headers.
*/
$headers = explode("\n", $cache->headers);
foreach ($headers as $header) {
header($header);
}
print $cache->data;
/*
** call all init() and exit() hooks without including all modules
** only use those hooks for critical operations
*/
foreach (bootstrap_hooks() as $hook) {
module_invoke_all($hook);
}
exit();
}
}
}
// critical hooks called even when serving a cached page
function bootstrap_hooks() {
return array('init', 'exit');
}
/*
** Unserializes and appends elements from a serialized string
** $obj is the object to which we shall append
** $field is the element whose value is a serialized string
*/
function drupal_unpack($obj, $field = 'data') {
if ($obj->$field && $data = unserialize($obj->$field)) {
foreach ($data as $key => $value) {
if (!isset($obj->$key)) {
$obj->$key = $value;
}
}
}
return $obj;
}
function referer_uri() {
if (isset($_SERVER["HTTP_REFERER"])) {
return check_url($_SERVER["HTTP_REFERER"]);
}
}
function arg($index) {
static $arguments, $q;
if (empty($arguments) || $q != $_GET["q"]) {
$arguments = explode("/", $_GET["q"]);
}
return $arguments[$index];
}
function check_query($text) {
return addslashes($text);
}
function check_url($uri) {
$uri = htmlspecialchars($uri, ENT_QUOTES);
/*
** We replace ( and ) with their entity equivalents to prevent XSS
** attacks.
*/
$uri = strtr($uri, array("(" => "&040;", ")" => "&041;"));
return $uri;
}
function request_uri() {
/*
** Since request_uri() is only available on Apache, we generate
** equivalent using other environment vars.
*/
if (isset($_SERVER["REQUEST_URI"])) {
$uri = $_SERVER["REQUEST_URI"];
}
else {
$uri = $_SERVER["PHP_SELF"] ."?". $_SERVER["argv"][0];
}
return check_url($uri);
}
function timer_start() {
global $timer;
list($usec, $sec) = explode(" ", microtime());
$timer = (float)$usec + (float)$sec;
}
function watchdog($type, $message, $link = NULL) {
global $user;
db_query("INSERT INTO {watchdog} (uid, type, message, link, location, hostname, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $link, request_uri(), $_SERVER['REMOTE_ADDR'], time());
}
unset($conf);
$config = conf_init();
include_once "includes/$config.php";
include_once "includes/database.inc";
include_once "includes/session.inc";
include_once "includes/module.inc";
// initialize configuration variables, using values from conf.php if available:
$conf = variable_init(isset($conf) ? $conf : array());
?>
<?php
// $Id$
/* $Id$ */
function conf_init() {
/**
* @defgroup common Core functions
*/
/*
** Try finding a matching configuration file by stripping the website's
** URI from left to right. If no configuration file is found, return a
** default value 'conf'.
*/
/**
* @name Page title
* @ingroup common
*
* Functions to get and set the title of the current page.
* @{
*/
function drupal_set_title($title = NULL) {
static $stored_title;
$uri = $_SERVER["PHP_SELF"];
if (isset($title)) {
$stored_title = ucfirst($title);
}
return $stored_title;
}
$file = strtolower(strtr($_SERVER["HTTP_HOST"] . substr($uri, 0, strrpos($uri, "/")), "/:", ".."));
function drupal_get_title() {
$title = drupal_set_title();
while (strlen($file) > 4) {
if (file_exists("includes/$file.php")) {
return $file;
}
else {
$file = substr($file, strpos($file, ".") + 1);
}
if (!isset($title)) {
$title = menu_get_active_title();
}
return "conf";
return $title;
}
/* @} */
function error_handler($errno, $message, $filename, $line, $variables) {
$types = array(1 => "error", 2 => "warning", 4 => "parse error", 8 => "notice", 16 => "core error", 32 => "core warning", 64 => "compile error", 128 => "compile warning", 256 => "user error", 512 => "user warning", 1024 => "user notice");
$entry = $types[$errno] .": $message in $filename on line $line.";
/**
* @name Page messages
* @ingroup common
*
* Functions to get and set the message of the current page.
* @{
*/
function drupal_set_message($message = NULL, $type = "status") {
static $stored_message = array();
if ($errno & E_ALL ^ E_NOTICE) {
watchdog("error", $types[$errno] .": $message in $filename on line $line.");
print "<pre>$entry</pre>";
if (isset($message)) {
$stored_message[] = array($message, $type);
}
return $stored_message;
}
function watchdog($type, $message, $link = NULL) {
global $user;
db_query("INSERT INTO {watchdog} (uid, type, message, link, location, hostname, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $link, request_uri(), getenv("REMOTE_ADDR"), time());
function drupal_get_messages() {
return drupal_set_message();
}
/* @} */
function throttle($type, $rate) {
if (!user_access("access administration pages")) {
if ($throttle = db_fetch_object(db_query("SELECT * FROM {watchdog} WHERE type = '$type' AND hostname = '". getenv("REMOTE_ADDR") ."' AND ". time() ." - timestamp < $rate"))) {
watchdog("warning", "throttle: '". getenv("REMOTE_ADDR") ."' exceeded submission rate - $throttle->type");
die(message_throttle());
}
else {
watchdog($type, "throttle");
}
/**
* @name Page breadcrumbs
* @ingroup common
*
* Functions to get and set the breadcrumb trail of the current page.
* @{
*/
/**
* @param $breadcrumb Array of links, starting with "home" and proceeding up
* to but not including the current page.
*/
function drupal_set_breadcrumb($breadcrumb = NULL) {
static $stored_breadcrumb;
if (isset($breadcrumb)) {
$stored_breadcrumb = $breadcrumb;
}
return $stored_breadcrumb;
}
function check_php_setting($name, $value) {
if (ini_get($name) != $value) {
print "<p>Note that the value of PHP's configuration option <code><b>$name</b></code> is incorrect. It should be set to '$value' for Drupal to work properly. Either configure your webserver to support <code>.htaccess</code> files so Drupal's <code>.htaccess</code> file can set it to the proper value, or edit your <code>php.ini</code> file directly. This message will automatically dissapear when the problem has been fixed.</p>";
function drupal_get_breadcrumb() {
$breadcrumb = drupal_set_breadcrumb();
if (!isset($breadcrumb)) {
$breadcrumb = menu_get_active_breadcrumb();
array_pop($breadcrumb);
}
return $breadcrumb;
}
/* @} */
function arg($index) {
/**
* @name HTML head contents
* @ingroup common
*
* Set and get output that should be in the \<head\> tag.
* @{
*/
static $arguments;
function drupal_set_html_head($data = NULL) {
static $stored_head;
if (empty($arguments)) {
$arguments = explode("/", $_GET["q"]);
if (!is_null($data)) {
$stored_head .= "$data\n";
}
return $arguments[$index];
return $stored_head;
}
function array2object($node) {
function drupal_get_html_head() {
global $base_url;
if (is_array($node)) {
foreach ($node as $key => $value) {
$object->$key = $value;
}
}
else {
$object = $node;
}
$output = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
$output .= "<base href=\"$base_url/\" />\n";
$output .= "<style type=\"text/css\" media=\"all\">\n";
$output .= "@import url(misc/drupal.css);\n";
$output .= "</style>\n";
return $object;
return $output . drupal_set_html_head();
}
/* @} */
function object2array($node) {
/**
* @name URL path alias
* @ingroup common
*
* Functions to handle path aliases.
*/
function drupal_get_path_map($action = "") {
static $map = NULL;
if (is_object($node)) {
foreach ($node as $key => $value) {
$array[$key] = $value;
}
if ($action == "rebuild") {
$map = NULL;
}
else {
$array = $node;
if (is_null($map)) {
$map = array(); // make $map non-null in case no aliases are defined
$result = db_query("SELECT * FROM {url_alias}");
while ($data = db_fetch_object($result)) {
$map[$data->dst] = $data->src;
}
}
return $array;
return $map;
}
function referer_uri() {
if (isset($_SERVER["HTTP_REFERER"])) {
$uri = $_SERVER["HTTP_REFERER"];
function drupal_rebuild_path_map() {
drupal_get_path_map("rebuild");
}
return check_url($uri);
/**
* Given an old url, return the alias.
*/
function drupal_get_path_alias($path) {
if (($map = drupal_get_path_map()) && ($newpath = array_search($path, $map))) {
return $newpath;
}
elseif (function_exists("conf_url_rewrite")) {
return conf_url_rewrite($path, 'outgoing');
}
}
function request_uri() {
/*
** Since request_uri() is only available on Apache, we generate
** equivalent using other environment vars.
*/
if (isset($_SERVER["REQUEST_URI"])) {
$uri = $_SERVER["REQUEST_URI"];
/**
* Given an alias, return the default url.
*/
function drupal_get_normal_path($path) {
if (($map = drupal_get_path_map()) && isset($map[$path])) {
return $map[$path];
}
elseif (function_exists("conf_url_rewrite")) {
return conf_url_rewrite($path, 'incoming');
}
else {
$uri = $_SERVER["PHP_SELF"] ."?". $_SERVER["QUERY_STRING"];
return $path;
}
return check_url($uri);
}
/* @} */
function message_access() {
return t("You are not authorized to access this page.");
}
/**
* @name HTTP headers
* @ingroup common
*
* Functions to get and set the HTTP headers of the current page.
* @{
*/
function drupal_set_header($header = NULL) {
static $stored_headers;
function message_na() {
return t("n/a");
if (!is_null($header)) {
header($header);
$stored_headers .= "$header\n";
}
return $stored_headers;
}
function message_throttle() {
return t("You exceeded the maximum submission rate. Please wait a few minutes and try again.");
function drupal_get_headers() {
return drupal_set_header();
}
/* @} */
function locale_init() {
global $languages, $user;
if ($user->uid && $languages[$user->language]) {
return $user->language;
}
else {
return key($languages);
}
}
/**
* @name HTTP handling
* @ingroup common
*
* Functions to properly handle HTTP responses.
* @{
*/
function t($string, $args = 0) {
global $languages;
/**
* HTTP redirects. Makes sure the redirected url is formatted correctly and
* includes the session ID.
*
* @note This function ends the request.
*
* @param $url A Drupal URL
* @param $query Query string component
* @param $fragment Fragment identifier
*/
function drupal_goto($url = NULL, $query = NULL, $fragment = NULL) {
/*
** About the usage of t(). We try to keep strings whole as much as
** possible and are unafraid of HTML markup within translation strings
** if necessary. The suggested syntax for a link embedded within a
** translation string is for example:
**
** $msg = t("You must login below or <a href=\"%url\">create a new
** account</a> before viewing the next page.", array("%url"
** => url("user/register")));
** Translate &amp; to simply & in the absolute URL
*/
$string = ($languages && module_exist("locale") ? locale($string) : $string);
$url = str_replace("&amp;", "&", url($url, $query, $fragment, TRUE));
if (!$args) {
return $string;
/*
** It is advised to use "drupal_goto()" instead of PHP's "header()" as
** "drupal_goto()" will append the user's session ID to the URI when PHP
** is compiled with "--enable-trans-sid".
*/
if (!ini_get("session.use_trans_sid") || !session_id() || strstr($url, session_id())) {
header("Location: $url");
}
else {
return strtr($string, $args);
}
}
$sid = session_name() . "=" . session_id();
function variable_init($conf = array()) {
$result = db_query("SELECT * FROM {variable} ");
while ($variable = db_fetch_object($result)) {
if (!isset($conf[$variable->name])) {
$conf[$variable->name] = unserialize($variable->value);
if (strstr($url, "?") && !strstr($url, $sid)) {
header("Location: $url&". $sid);
}
else {
header("Location: $url?". $sid);
}
}
return $conf;
}
function variable_get($name, $default) {
global $conf;
/*
** The "Location" header sends a REDIRECT status code to the http
** daemon. In some cases this can go wrong, so we make sure none
** of the code /below/ gets executed when we redirect.
*/
return isset($conf[$name]) ? $conf[$name] : $default;
exit();
}
function variable_set($name, $value) {
global $conf;
db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
$conf[$name] = $value;
}
/**
* Generates a 404 error if the request can not be handled.
*/
function drupal_not_found() {
header("HTTP/1.0 404 Not Found");
watchdog("httpd", "404 error: '". check_query($_GET["q"]) ."' not found");
function variable_del($name) {
global $conf;
$path = drupal_get_normal_path(variable_get('site_404', ''));
db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
if ($path) {
menu_set_active_item($path);
}
unset($conf[$name]);
if ($path && menu_active_handler_exists()) {
menu_execute_active_handler();
}
else {
print theme('page', '', t('Page not found'));
}
}
function drupal_specialchars($input, $quotes = ENT_NOQUOTES) {
/*
** Note that we'd like to go 'htmlspecialchars($input, $quotes, "utf-8")'
** like the PHP manual tells us to, but we can't because there's a bug in
** PHP <4.3 that makes it mess up multibyte charsets if we specify the
** charset. Change this later once we make PHP 4.3 a requirement.
*/
return htmlspecialchars($input, $quotes);
}
/**
* Flexible and powerful HTTP client implementation. Allows to GET, POST, PUT
* or any other HTTP requests. Handles redirects.
*
* @param $url A string containing a fully qualified URI.
* @param $headers An array containing a HTTP header => value pair.
* @param $method A string defining the HTTP request to use.
* @param $data A string containing data to include in the request.
* @param $retry An integer representing how many times to retry the request
* in case of a redirect.
* @return An object containing the HTTP request headers, response code,
* headers, data, and redirect status.
*/
function drupal_http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
// Parse the URL, and make sure we can handle the schema
$uri = parse_url($url);
switch ($uri['scheme']) {
case 'http':
$fp = @fsockopen($uri['host'], ($uri['port'] ? $uri['port'] : 80), $errno, $errstr, 15);
break;
case 'https':
// Note: only works for PHP 4.3 compiled with openssl
$fp = @fsockopen("ssl://$uri[host]", ($uri['port'] ? $uri['port'] : 443), $errno, $errstr, 20);
break;
default:
$result->error = "invalid schema $uri[scheme]";
return $result;
}
function table_cell($cell, $header = 0) {
if (is_array($cell)) {
$data = $cell["data"];
foreach ($cell as $key => $value) {
if ($key != "data") {
$attributes .= " $key=\"$value\"";
}
}
// Make sure the socket opened properly
if (!$fp) {
$result->error = trim("$errno $errstr");
return $result;
}
else {
$data = $cell;
// Construct the path to act on
$path = $uri['path'] ? $uri['path'] : '/';
if ($uri['query']) {
$path .= "?$uri[query]";
}
if ($header) {
$output = "<th$attributes>$data</th>";
// Create http request
$defaults = array(
'Host' => "Host: $uri[host]",
'User-Agent' => 'User-Agent: Drupal (+http://www.drupal.org/)',
'Content-Length' => 'Content-Length: '. strlen($data)
);
foreach ($headers as $header => $value) {
$defaults[$header] = "$header: $value";
}
else {
$output = "<td$attributes>$data</td>";
$request = "$method $path HTTP/1.0\r\n";
$request .= implode("\r\n", $defaults);
$request .= "\r\n\r\n";
if ($data) {
$request .= "$data\r\n";
}
$result->request = $request;
return $output;
}
fwrite($fp, $request);
function table($header, $rows) {
// Fetch response.
$response = '';
while (!feof($fp) && $data = fread($fp, 1024)) {
$response .= $data;
}
fclose($fp);
$output = "<table>\n";
// Parse response.
list($headers, $result->data) = explode("\r\n\r\n", $response, 2);
$headers = preg_split("/\r\n|\n|\r/", $headers);
/*
** Emit the table header:
*/
list($protocol, $code, $text) = explode(' ', trim(array_shift($headers)), 3);
$result->headers = array();
if (is_array($header)) {
$output .= " <tr>";
foreach ($header as $cell) {
if (is_array($cell) && $cell["field"]) {
$cell = tablesort($cell, $header);
}
$output .= table_cell($cell, 1);
}
$output .= " </tr>\n";
// Parse headers.
while ($line = trim(array_shift($headers))) {
list($header, $value) = explode(':', $line, 2);
$result->headers[$header] = trim($value);
}
/*
** Emit the table rows:
*/
$responses = array(
100 => 'Continue', 101 => 'Switching Protocols',
200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content',
300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect',
400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed',
500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported'
);
// RFC 2616 states that all unknown HTTP codes must be treated the same as
// the base code in their class:
if (!isset($responses[$code])) {
$code = floor($code / 100) * 100;
}
if (is_array($rows)) {
foreach ($rows as $number => $row) {
if ($number % 2 == 1) {
$output .= " <tr class=\"light\">";
}
else {
$output .= " <tr class=\"dark\">";
switch ($code) {
case 200: // OK
case 304: // Not modified
break;
case 301: // Moved permanently
case 302: // Moved temporarily
case 307: // Moved temporarily
$location = $result->headers['Location'];
if ($retry) {
$result = drupal_http_request($result->headers['Location'], $headers, $method, $data, --$retry);
$result->redirect_code = $result->code;
}
$result->redirect_url = $location;
foreach ($row as $cell) {
$output .= table_cell($cell, 0);
}
$output .= " </tr>\n";
}
break;
default:
$result->error = $text;
}
$output .= "</table>\n";
return $output;
$result->code = $code;
return $result;
}
/* @} */
/**
* Verify the syntax of the given e-mail address. Empty e-mail addresses
* are allowed. See RFC 2822 for details.
*
* @param $mail a email address
*/
function valid_email_address($mail) {
$user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+';
$domain = '(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]\.?)+';
$ipv4 = '[0-9]{1,3}(\.[0-9]{1,3}){3}';
$ipv6 = '[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}';
function error_handler($errno, $message, $filename, $line, $variables) {
$types = array(1 => "error", 2 => "warning", 4 => "parse error", 8 => "notice", 16 => "core error", 32 => "core warning", 64 => "compile error", 128 => "compile warning", 256 => "user error", 512 => "user warning", 1024 => "user notice");
$entry = $types[$errno] .": $message in $filename on line $line.";
if (preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail)) {
return 1;
}
else {
return 0;
if ($errno & E_ALL ^ E_NOTICE) {
watchdog("error", $types[$errno] .": $message in $filename on line $line.");
if (error_reporting()) {
print "<pre>$entry</pre>";
}
}
}
/**
* Verify the syntax of the given URL.
*
* @param $url an URL
*/
function valid_url($url) {
if (preg_match("/^[a-zA-z0-9\/:_\-_\.]+$/", $url)) {
return 1;
function _fix_gpc_magic(&$item, $key) {
if (is_array($item)) {
array_walk($item, '_fix_gpc_magic');
}
else {
return 0;
$item = stripslashes($item);
}
}
/**
* Format a single result entry of a search query:
*
* @param $item a single search result as returned by <module>_search of type
* array("count" => ..., "link" => ..., "title" => ...,
* "user" => ..., "date" => ..., "keywords" => ...)
* @param $type module type of this item
*/
function search_item($item, $type) {
/*
** Modules may implement the "search_item" hook in order to overwrite
** the default function to display search results.
*/
if (module_hook($type, "search_item")) {
$output = module_invoke($type, "search_item", $item);
function fix_gpc_magic() {
static $fixed = false;
if (!$fixed && ini_get("magic_quotes_gpc")) {
array_walk($_GET, '_fix_gpc_magic');
array_walk($_POST, '_fix_gpc_magic');
array_walk($_COOKIE, '_fix_gpc_magic');
array_walk($_REQUEST, '_fix_gpc_magic');
$fixed = true;
}
else {
$output .= " <b><u><a href=\"". $item["link"] ."\">". $item["title"] ."</a></u></b><br />";
$output .= " <small>$type ". ($item["user"] ? " - ". $item["user"] : "") ."". ($item["date"] ? " - ". format_date($item["date"], "small") : "") ."</small>";
$output .= "<br /><br />";
}
return $output;
}
/**
* Render a generic search form.
*
* "Generic" means "universal usable" - that is, usable not only from
* 'site.com/search', but also as a simple seach box (without
* "Restrict search to", help text, etc) from theme's header etc.
* This means: provide options to only conditionally render certain
* parts of this form.
* @name Conversion
* @ingroup common
*
* @param $action Form action. Defaults to 'site.com/search'.
* @param $keys string containing keywords for the search.
* @param $options != 0: Render additional form fields/text
* ("Restrict search to", help text, etc).
* Converts data structures to a different type.
* @{
*/
function search_form($action = NULL, $keys = NULL, $options = NULL) {
if (!$action) {
$action = url("search");
}
$output .= " <br /><input type=\"text\" size=\"50\" value=\"". check_form($keys) ."\" name=\"keys\" />";
$output .= " <input type=\"submit\" value=\"". t("Search") ."\" />\n";
if ($options != 0) {
$output .= "<br />";
$output .= t("Restrict search to") .": ";
foreach (module_list() as $name) {
if (module_hook($name, "search")) {
$output .= " <input type=\"checkbox\" name=\"edit[type][$name]\" ". ($edit["type"][$name] ? " checked=\"checked\"" : "") ." /> ". t($name);
}
function array2object($array) {
if (is_array($array)) {
foreach ($array as $key => $value) {
$object->$key = $value;
}
}
else {
$object = $array;
}
$form .= "<br />";
return form($output, "post", $action);
return $object;
}
/*
* Collect the search results:
*/
function search_data($keys = NULL) {
$edit = $_POST["edit"];
if (isset($keys)) {
foreach (module_list() as $name) {
if (module_hook($name, "search") && (!$edit["type"] || $edit["type"][$name]) && ($result = module_invoke($name, "search", check_query($keys)))) {
if ($name == "node" || $name == "comment") {
$output .= "<p><b>". t("Matching ". $name ."s ranked in order of relevance") .":</b></p>";
}
else {
$output .= "<p><b>". t("Matching ". $name ."s") .":</b></p>";
}
foreach ($result as $entry) {
$output .= search_item($entry, $name);
}
}
function object2array($object) {
if (is_object($object)) {
foreach ($object as $key => $value) {
$array[$key] = $value;
}
}
else {
$array = $object;
}
return $output;
return $array;
}
/* @} */
/**
* Display the search form and the resulting data.
* @name Messages
* @ingroup common
*
* @param $type If set, search only nodes of this type.
* Otherwise, search all types.
* @param $action Form action. Defaults to 'site.com/search'.
* @param $query Query string. Defaults to global $keys.
* @param $options != 0: Render additional form fields/text
* ("Restrict search to", help text, etc).
* Frequently used messages.
* @{
*/
function search_type($type, $action = NULL, $keys = NULL, $options = NULL) {
$_POST["edit"]["type"][$type] = "on";
function message_access() {
return t("You are not authorized to access this page.");
}
return search_form($action, $keys, $options) . "<br />". search_data($keys);
function message_na() {
return t("n/a");
}
/* @} */
function drupal_goto($url) {
function locale_init() {
global $languages, $user;
if ($user->uid && $languages[$user->language]) {
return $user->language;
}
else {
return key($languages);
}
}
/*
** Translate &amp; to simply &
*/
/**
* @ingroup common
*
* Translates strings to the current locale.
*
* When using t(), try to put entire sentences and strings in one t() call.
* This makes it easier for translators. We are unafraid of HTML markup within
* translation strings if necessary. The suggested syntax for a link embedded
* within a translation string is for example:
* @code
* $msg = t("You must login below or \<a href=\"%url\"\>create a new
* account\</a\> before viewing the next page.", array("%url"
* => url("user/register")));
* @endcode
* We suggest the same syntax for links to other sites. This makes it easy to
* change link URLs if needed (which happens often) without requiring updates
* to translations.
*
* @param $string A string containing the english string to translate.
* @param $args Array of values to replace in the string.
* @return Translated string.
*/
function t($string, $args = 0) {
global $languages;
$url = str_replace("&amp;", "&", $url);
$string = ($languages && module_exist("locale") ? locale($string) : $string);
/*
** It is advised to use "drupal_goto()" instead of PHP's "header()" as
** "drupal_goto()" will append the user's session ID to the URI when PHP
** is compiled with "--enable-trans-sid".
*/
if (!ini_get("session.use_trans_sid") || !session_id() || strstr($url, session_id())) {
header("Location: $url");
if (!$args) {
return $string;
}
else {
$sid = session_name() . "=" . session_id();
if (strstr($url, "?") && !strstr($url, $sid)) {
header("Location: $url&". $sid);
}
else {
header("Location: $url?". $sid);
}
return strtr($string, $args);
}
}
function drupal_specialchars($input, $quotes = ENT_NOQUOTES) {
/*
** The "Location" header sends a REDIRECT status code to the http
** daemon. In some cases this can go wrong, so we make sure none
** of the code /below/ gets executed when we redirect.
** Note that we'd like to go 'htmlspecialchars($input, $quotes, "utf-8")'
** like the PHP manual tells us to, but we can't because there's a bug in
** PHP <4.3 that makes it mess up multibyte charsets if we specify the
** charset. Change this later once we make PHP 4.3 a requirement.
*/
exit();
return htmlspecialchars($input, $quotes);
}
/*
** Stores the referer in a persistent variable:
*/
/**
* @name Validation
* @ingroup common
*
* Functions to validate user input.
* @{
*/
function referer_save() {
if (!strstr(referer_uri(), request_uri())) {
$_SESSION["referer"] = referer_uri();
}
}
/**
* Verify the syntax of the given e-mail address. Empty e-mail addresses are
* allowed. See RFC 2822 for details.
*
* @param $mail A string containing an email address.
* @return
*/
function valid_email_address($mail) {
$user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+';
$domain = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+';
$ipv4 = '[0-9]{1,3}(\.[0-9]{1,3}){3}';
$ipv6 = '[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}';
/*
** Restores the referer from a persistent variable:
*/
return preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail);
}
function referer_load() {
if (isset($_SESSION["referer"])) {
return $_SESSION["referer"];
}
else {
return 0;
}
/**
* Verify the syntax of the given URL.
*
* @param $url an URL
*/
function valid_url($url) {
return preg_match("/^[a-zA-z0-9\/:_\-_\.,]+$/", $url);
}
function valid_input_data($data) {
if (is_array($data)) {
if (is_array($data) || is_object($data)) {
/*
** Form data can contain a number of nested arrays.
*/
foreach ($data as $key => $value) {
if (!valid_input_data($value)) {
if (!valid_input_data($key) || !valid_input_data($value)) {
return 0;
}
}
......@@ -511,7 +588,6 @@ function valid_input_data($data) {
// check attributes:
$match += preg_match("/\W(dynsrc|datasrc|data|lowsrc|on[a-z]+)\s*=[^>]+?>/i", $data);
// check tags:
$match += preg_match("/<\s*(applet|script|object|style|embed|form|blink|meta|html|frame|iframe|layer|ilayer|head|frameset|xml)/i", $data);
......@@ -523,154 +599,144 @@ function valid_input_data($data) {
return 1;
}
/* @} */
function check_url($uri) {
$uri = htmlspecialchars($uri, ENT_QUOTES);
/*
** We replace ( and ) with their entity equivalents to prevent XSS
** attacks.
*/
$uri = strtr($uri, array("(" => "&040;", ")" => "&041;"));
return $uri;
}
function check_form($text) {
return drupal_specialchars($text, ENT_QUOTES);
}
function check_query($text) {
return addslashes($text);
}
function filter($text) {
$modules = module_list();
/**
* @defgroup search Search interface
* @{
*/
/**
* Format a single result entry of a search query:
*
* @param $item a single search result as returned by <i>module</i>_search of
* type array("count" => ..., "link" => ..., "title" => ..., "user" => ...,
* "date" => ..., "keywords" => ...)
* @param $type module type of this item
*/
function search_item($item, $type) {
/*
** Make sure the HTML filters that are part of the node module
** are run first.
** Modules may implement the "search_item" hook in order to overwrite
** the default function to display search results.
*/
if (in_array("node", $modules)) {
$text = module_invoke("node", "filter", $text);
if (module_hook($type, "search_item")) {
$output = module_invoke($type, "search_item", $item);
}
foreach ($modules as $name) {
if (module_hook($name, "filter") && $name != "node") {
$text = module_invoke($name, "filter", $text);
}
else {
$output = " <strong><u><a href=\"". $item["link"] ."\">". $item["title"] ."</a></u></strong><br />";
$output .= " <small>" . t($type) . ($item["user"] ? " - ". $item["user"] : "") ."". ($item["date"] ? " - ". format_date($item["date"], "small") : "") ."</small>";
$output .= "<br /><br />";
}
return $text;
return $output;
}
function rewrite_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:
*/
// rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
$text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"?q=\\1/view/\\2/\\4", $text);
/**
* Render a generic search form.
*
* "Generic" means "universal usable" - that is, usable not only from
* 'site.com/search', but also as a simple seach box (without "Restrict search
* to", help text, etc) from theme's header etc. This means: provide options to
* only conditionally render certain parts of this form.
*
* @param $action Form action. Defaults to 'site.com/search'.
* @param $keys string containing keywords for the search.
* @param $options != 0: Render additional form fields/text ("Restrict search
* to", help text, etc).
*/
function search_form($action = NULL, $keys = NULL, $options = NULL) {
$edit = $_POST['edit'];
// rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
$text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4/\\6" , $text);
$text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4", $text);
$text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2", $text);
if (!$action) {
$action = url("search");
}
/*
** Absolute URLs:
*/
$output = " <br /><input type=\"text\" class=\"form-text\" size=\"50\" value=\"". check_form($keys) ."\" name=\"keys\" />";
$output .= " <input type=\"submit\" class=\"form-submit\" value=\"". t("Search") ."\" />\n";
// 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);
if ($options) {
$output .= "<br />";
$output .= t("Restrict search to") .": ";
// rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
$text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4/\\6" , $text);
$text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4", $text);
$text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"$end/?q=\\2", $text);
foreach (module_list() as $name) {
if (module_hook($name, "search")) {
$output .= " <input type=\"checkbox\" name=\"edit[type][$name]\" ". ($edit["type"][$name] ? " checked=\"checked\"" : "") ." /> ". t($name);
}
}
}
else {
/*
** 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);
// rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
$text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4/\\6", $text);
$text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4", $text);
$text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2", $text);
$form .= "<br />";
/*
** Absolute URLs:
*/
return form($output, "post", $action);
}
// 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);
/*
* Collect the search results:
*/
function search_data($keys = NULL) {
$edit = $_POST["edit"];
// rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
$text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4/\\6", $text);
$text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4", $text);
$text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2", $text);
}
if (isset($keys)) {
foreach (module_list() as $name) {
if (module_hook($name, "search") && (!$edit["type"] || $edit["type"][$name])) {
list($title, $results) = module_invoke($name, "search", $keys);
if ($results) {
$output .= "<h2>$title</h2>";
foreach ($results as $entry) {
$output .= search_item($entry, $name);
}
}
}
}
}
return $text;
return $output;
}
function check_output($text) {
if (isset($text)) {
// filter content on output:
$text = filter($text);
/**
* Display the search form and the resulting data.
*
* @param $type If set, search only nodes of this type. Otherwise, search all
* types.
* @param $action Form action. Defaults to 'site.com/search'.
* @param $keys Query string. Defaults to global $keys.
* @param $options != 0: Render additional form fields/text ("Restrict search
* to", help text, etc).
*/
function search_type($type, $action = NULL, $keys = NULL, $options = NULL) {
$_POST["edit"]["type"][$type] = "on";
// get the line breaks right:
if (strip_tags($text, "<a><i><b><u><tt><code><cite><strong><img>") == $text) {
$text = nl2br($text);
}
}
else {
$text = message_na();
}
return search_form($action, $keys, $options) . "<br />". search_data($keys);
}
/* @} */
return $text;
function check_form($text) {
return drupal_specialchars($text, ENT_QUOTES);
}
function check_file($filename) {
if (is_uploaded_file($filename)) {
return 1;
}
else {
return 0;
}
return is_uploaded_file($filename);
}
/**
* @name Formatting
* @ingroup common
*
* Functions to format numbers, strings, dates, etc.
* @{
*/
function format_rss_channel($title, $link, $description, $items, $language = "en", $args = array()) {
// arbitrary elements may be added using the $args associative array
$output .= "<channel>\n";
$output = "<channel>\n";
$output .= " <title>". drupal_specialchars(strip_tags($title)) ."</title>\n";
$output .= " <link>". drupal_specialchars(strip_tags($link)) ."</link>\n";
$output .= " <description>". drupal_specialchars($description) ."</description>\n";
$output .= " <language>". drupal_specialchars(strip_tags($language)) ."</language>\n";
foreach ($args as $key => $value) {
$output .= "<$key>". drupal_specialchars(strip_tags($value)) ."</$key>";
$output .= " <$key>". drupal_specialchars(strip_tags($value)) ."</$key>\n";
}
$output .= $items;
$output .= "</channel>\n";
......@@ -681,7 +747,7 @@ function format_rss_channel($title, $link, $description, $items, $language = "en
function format_rss_item($title, $link, $description, $args = array()) {
// arbitrary elements may be added using the $args associative array
$output .= "<item>\n";
$output = "<item>\n";
$output .= " <title>". drupal_specialchars(strip_tags($title)) ."</title>\n";
$output .= " <link>". drupal_specialchars(strip_tags($link)) ."</link>\n";
$output .= " <description>". drupal_specialchars(check_output($description)) ."</description>\n";
......@@ -695,22 +761,28 @@ function format_rss_item($title, $link, $description, $args = array()) {
/**
* Formats a string with a count of items so that the string is pluralized
* correctly.
* format_plural calls t() by itself, make sure not to pass already localized
* strings to it.
* correctly. format_plural calls t() by itself, make sure not to pass already
* localized strings to it.
*
* @param $count The item count to display.
* @param $singular The string for the singular case. Please make sure it's clear
* this is singular, to ease translation. ("1 new comment" instead of
* "1 new").
* @param $plural The string for the plrual case. Please make sure it's clear
* this is plural, to ease translation. Use %count in places of the
* item count, as in "%count new comments".
* @param $count The item count to display.
* @param $singular The string for the singular case. Please make sure it's
* clear this is singular, to ease translation. ("1 new comment" instead of "1
* new").
* @param $plural The string for the plural case. Please make sure it's clear
* this is plural, to ease translation. Use %count in places of the item
* count, as in "%count new comments".
* @return Translated string
*/
function format_plural($count, $singular, $plural) {
return t($count == 1 ? $singular : $plural, array("%count" => $count));
}
/**
* Generates a string representation for the given byte count.
*
* @param $size The size in bytes
* @return Translated string representation of the size
*/
function format_size($size) {
$suffix = t("bytes");
if ($size > 1024) {
......@@ -724,109 +796,122 @@ function format_size($size) {
return t("%size %suffix", array("%size" => $size, "%suffix" => $suffix));
}
function cache_get($key) {
$cache = db_fetch_object(db_query("SELECT data, created FROM {cache} WHERE cid = '%s'", $key));
return $cache->data ? $cache : 0;
}
function cache_set($cid, $data, $expire = 0) {
if (db_fetch_object(db_query("SELECT cid FROM {cache} WHERE cid = '%s'", $cid))) {
db_query("UPDATE {cache} SET data = '%s', created = %d, expire = %d WHERE cid = '%s'", $data, time(), $expire, $cid);
}
else {
db_query("INSERT INTO {cache} (cid, data, created, expire) VALUES('%s', '%s', %d, %d)", $cid, $data, time(), $expire);
}
}
function cache_clear_all($cid = NULL) {
if (empty($cid)) {
db_query("DELETE FROM {cache} WHERE expire <> 0");
}
else {
db_query("DELETE FROM {cache} WHERE cid = '%s'", $cid);
}
}
function page_set_cache() {
global $user;
if (!$user->uid && $_SERVER["REQUEST_METHOD"] == "GET") {
if ($data = ob_get_contents()) {
cache_set(request_uri(), $data, 1);
}
}
}
function page_get_cache() {
global $user;
$cache = NULL;
if (!$user->uid && $_SERVER["REQUEST_METHOD"] == "GET") {
$cache = cache_get(request_uri());
if (empty($cache)) {
ob_start();
}
}
return $cache;
}
function format_interval($timestamp) {
/**
* Formats a time interval with the requested granularity.
*
* @param $timestamp The length of the interval in seconds
* @param $granularity How much units to consider when generating the string
* @return Translated string representation of the interval
*/
function format_interval($timestamp, $granularity = 2) {
$units = array("1 year|%count years" => 31536000, "1 week|%count weeks" => 604800, "1 day|%count days" => 86400, "1 hour|%count hours" => 3600, "1 min|%count min" => 60, "1 sec|%count sec" => 1);
foreach ($units as $key=>$value) {
foreach ($units as $key => $value) {
$key = explode("|", $key);
if ($timestamp >= $value) {
$output .= ($output ? " " : "") . format_plural(floor($timestamp / $value), $key[0], $key[1]);
$timestamp %= $value;
$granularity--;
}
if ($granularity == 0) {
break;
}
}
return ($output) ? $output : t("0 sec");
}
function format_date($timestamp, $type = "medium", $format = "") {
global $user;
/**
* Formats a date with the given configured format or a custom format string.
* Drupal allows administrators to select formatting strings for 'small',
* 'medium' and 'large' date formats. This function can handle these formats,
* as well as any custom format.
*
* @param $timestamp The exact date to format
* @param $type Could be 'small', 'medium' or 'large' for the preconfigured
* date formats. If 'custom' is specified, the next parameter
* should contain the format string
* @param $format Format string (as required by the PHP date() function).
* Only required if 'custom' date format is requested.
* @param $timezone Timezone offset in seconds in case the user timezone
* should not be used.
* @return Translated date string in the requested format
*/
function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL) {
if ($timezone === NULL) {
global $user;
$timezone = $user->uid ? $user->timezone : variable_get('date_default_timezone', 0);
}
$timestamp += ($user->timezone) ? $user->timezone - date("Z") : 0;
$timestamp += $timezone;
switch ($type) {
case "small":
$date = date(variable_get("date_format_short", "m/d/Y - H:i"), $timestamp);
case 'small':
$format = variable_get('date_format_short', 'm/d/Y - H:i');
break;
case "medium":
$date = date(variable_get("date_format_medium", "D, m/d/Y - H:i"), $timestamp);
case 'large':
$format = variable_get('date_format_long', 'l, F j, Y - H:i');
break;
case "large":
$date = date(variable_get("date_format_long", "l, F j, Y - H:i"), $timestamp);
break;
case "custom":
for ($i = strlen($format); $i >= 0; $c = $format[--$i]) {
if (strstr("DFlMSw", $c)) {
$date = t(date($c, $timestamp)) . $date;
}
else if (strstr("AaBdgGhHiIjLmnOrstTUWYyZz", $c)) {
$date = date($c, $timestamp) . $date;
}
else {
$date = $c.$date;
}
}
case 'custom':
// No change to format
break;
case 'medium':
default:
$date = date(variable_get("date_format_medium", "l, m/d/Y - H:i"), $timestamp);
$format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
}
$max = strlen($format);
for ($i = 0; $i <= $max; $c = $format{$i++}) {
if (strpos('AaDFlM', $c)) {
$date .= t(gmdate($c, $timestamp));
}
else if (strpos('BdgGhHiIjLmnsStTUwWYyz', $c)) {
$date .= gmdate($c, $timestamp);
}
else if ($c == 'r') {
$date .= format_date($timestamp - $timezone, 'custom', 'D, d M Y H:i:s O', $timezone);
}
else if ($c == 'O') {
$date .= sprintf('%s%02d%02d', ($timezone < 0 ? '-' : '+'), abs($timezone / 3600), abs($timezone % 3600) / 60);
}
else if ($c == 'Z') {
$date .= $timezone;
}
else {
$date .= $c;
}
}
return $date;
}
/**
* Formats a username.
*
* @param $object User object
* @return String containing a HTML link to the user's page if the
* passed object suggests that this is a site user. Otherwise
* only the user name is returned.
*/
function format_name($object) {
if ($object->uid && $object->name) {
if (arg(0) == "admin") {
$output = l($object->name, "admin/user/edit/$object->uid", array("title" => t("Administer user profile.")));
/*
** Shorten the name when it is too long or it will break many
** tables.
*/
if (strlen($object->name) > 20) {
$name = truncate_utf8($object->name, 15) ."...";
}
else {
$name = $object->name;
}
if (arg(0) == "admin" and user_access("administer users")) {
$output = l($name, "admin/user/edit/$object->uid", array("title" => t("Administer user profile.")));
}
else {
$output = l($object->name, "user/view/$object->uid", array("title" => t("View user profile.")));
$output = l($name, "user/view/$object->uid", array("title" => t("View user profile.")));
}
}
else if ($object->name) {
......@@ -845,86 +930,101 @@ function format_name($object) {
return $output;
}
/* @} */
function form($form, $method = "post", $action = 0, $options = 0) {
/**
* @defgroup from Form generation
* @{
*/
function form($form, $method = "post", $action = NULL, $attributes = NULL) {
if (!$action) {
$action = request_uri();
}
return "<form action=\"$action\" method=\"$method\"". drupal_attributes($options) .">\n$form\n</form>\n";
return "<form action=\"$action\" method=\"$method\"". drupal_attributes($attributes) .">\n$form\n</form>\n";
}
function form_item($title, $value, $description = NULL, $id = NULL) {
return theme("form_element", $title, $value, $description, $id);
}
function form_group($legend, $group, $description = NULL) {
return "<fieldset>" . ($legend ? "<legend>$legend</legend>" : "") . $group . ($description ? "<div class=\"description\">$description</div>" : "") . "</fieldset>\n";
}
function form_item($title, $value, $description = 0) {
return "<div class=\"form-item\">". ($title ? "<div class=\"title\">$title:</div>" : "") . $value . ($description ? "<div class=\"description\">$description</div>" : "") ."</div>\n";
function form_radio($title, $name, $value = 1, $checked = 0, $description = NULL, $attributes = NULL) {
$element = "<input type=\"radio\" class=\"form-radio\" name=\"edit[$name]\" value=\"$value\"". ($checked ? " checked=\"checked\"" : "") . drupal_attributes($attributes) .' />';
if (!is_null($title)) {
$element = "<label class=\"option\">$element $title</label>";
}
return theme('form_element', NULL, $element, $description);
}
function form_radio($title, $name, $value = 1, $checked = 0, $description = 0, $attributes = 0) {
return form_item(0, "<input type=\"radio\" class=\"form-radio\" name=\"edit[$name]\" value=\"". $value ."\"". ($checked ? " checked=\"checked\"" : "") . drupal_attributes($attributes) ." /> $title", $description);
function form_radios($title, $name, $value, $options, $description = NULL) {
if (count($options) > 0) {
foreach ($options as $key => $choice) {
$choices .= "<label class=\"option\"><input type=\"radio\" class=\"form-radio\" name=\"edit[$name]\" value=\"$key\"". ($key == $value ? " checked=\"checked\"" : "") ." /> $choice</label><br />";
}
return theme('form_element', $title, $choices, $description);
}
}
function form_checkbox($title, $name, $value = 1, $checked = 0, $description = 0, $attributes = 0) {
return form_hidden($name, 0) . form_item(0, "<input type=\"checkbox\" class=\"form-checkbox\" name=\"edit[$name]\" value=\"". $value ."\"". ($checked ? " checked=\"checked\"" : "") . drupal_attributes($attributes) ." /> $title", $description);
function form_checkbox($title, $name, $value = 1, $checked = 0, $description = NULL, $attributes = NULL) {
$element = "<input type=\"checkbox\" class=\"form-checkbox\" name=\"edit[$name]\" id=\"edit-$name\" value=\"". $value ."\"". ($checked ? " checked=\"checked\"" : "") . drupal_attributes($attributes) .' />';
if (!is_null($title)) {
$element = "<label class=\"option\">$element $title</label>";
}
return form_hidden($name, 0) . theme('form_element', NULL, $element, $description);
}
function form_textfield($title, $name, $value, $size, $maxlength, $description = 0, $attributes = 0) {
function form_textfield($title, $name, $value, $size, $maxlength, $description = NULL, $attributes = NULL) {
$size = $size ? " size=\"$size\"" : "";
return form_item($title, "<input type=\"text\" maxlength=\"$maxlength\" class=\"form-text\" name=\"edit[$name]\"$size value=\"". check_form($value) ."\"". drupal_attributes($attributes) ." />", $description);
return theme("form_element", $title, "<input type=\"text\" maxlength=\"$maxlength\" class=\"form-text\" name=\"edit[$name]\" id=\"$name\"$size value=\"". check_form($value) ."\"". drupal_attributes($attributes) ." />", $description, $name);
}
function form_password($title, $name, $value, $size, $maxlength, $description = 0, $attributes = 0) {
function form_password($title, $name, $value, $size, $maxlength, $description = NULL, $attributes = NULL) {
$size = $size ? " size=\"$size\"" : "";
return form_item($title, "<input type=\"password\" class=\"form-password\" maxlength=\"$maxlength\" name=\"edit[$name]\"$size value=\"". check_form($value) ."\"". drupal_attributes($attributes) ." />", $description);
return theme("form_element", $title, "<input type=\"password\" class=\"form-password\" maxlength=\"$maxlength\" name=\"edit[$name]\" id=\"$name\"$size value=\"". check_form($value) ."\"". drupal_attributes($attributes) ." />", $description, $name);
}
function form_textarea($title, $name, $value, $cols, $rows, $description = 0, $attributes = 0) {
function form_textarea($title, $name, $value, $cols, $rows, $description = NULL, $attributes = NULL) {
$cols = $cols ? " cols=\"$cols\"" : "";
module_invoke_all("textarea", $name); // eg. optionally plug in a WYSIWYG editor
return form_item($title, "<textarea wrap=\"virtual\"$cols rows=\"$rows\" name=\"edit[$name]\" id=\"edit[$name]\"". drupal_attributes($attributes) .">". check_form($value) ."</textarea>", $description);
}
function form_select($title, $name, $value, $options, $description = 0, $extra = 0, $multiple = 0) {
if (count($options) > 0) {
foreach ($options as $key=>$choice) {
$select .= "<option value=\"$key\"". (is_array($value) ? (in_array($key, $value) ? " selected=\"selected\"" : "") : ($value == $key ? " selected=\"selected\"" : "")) .">". check_form($choice) ."</option>";
}
return form_item($title, "<select name=\"edit[$name]". ($multiple ? "[]" : "") ."\"". ($multiple ? " multiple " : "") . ($extra ? " $extra" : "") .">$select</select>", $description);
}
return theme("form_element", $title, "<textarea wrap=\"virtual\"$cols rows=\"$rows\" name=\"edit[$name]\" id=\"$name\"". drupal_attributes($attributes) .">". check_form($value) ."</textarea>", $description, $name);
}
function form_radios($title, $name, $value, $options, $description = 0) {
if (count($options) > 0) {
foreach ($options as $key=>$choice) {
$output .= form_radio($choice, $name, $key, ($key == $value));
}
return form_item($title, $output, $description);
function form_select($title, $name, $value, $options, $description = NULL, $extra = 0, $multiple = 0) {
foreach ($options as $key => $choice) {
$select .= "<option value=\"$key\"". (is_array($value) ? (in_array($key, $value) ? " selected=\"selected\"" : "") : ($value == $key ? " selected=\"selected\"" : "")) .">". check_form($choice) ."</option>";
}
return theme("form_element", $title, "<select name=\"edit[$name]". ($multiple ? "[]" : "") ."\"". ($multiple ? " multiple " : "") . ($extra ? " $extra" : "") ." id=\"$name\">$select</select>", $description, $name);
}
function form_file($title, $name, $size, $description = 0) {
return form_item($title, "<input type=\"file\" class=\"form-file\" name=\"edit[$name]\" size=\"$size\" />\n", $description);
function form_file($title, $name, $size, $description = NULL) {
return theme("form_element", $title, "<input type=\"file\" class=\"form-file\" name=\"edit[$name]\" id=\"$name\" size=\"$size\" />\n", $description, $name);
}
function form_hidden($name, $value) {
return "<input type=\"hidden\" name=\"edit[$name]\" value=\"". check_form($value) ."\" />\n";
}
function form_submit($value, $name = "op", $attributes = 0) {
return "<input type=\"submit\" class=\"form-submit\" name=\"$name\" value=\"". check_form($value) ."\" />\n";
function form_button($value, $name = "op", $type = "submit", $attributes = NULL) {
return "<input type=\"$type\" class=\"form-$type\" name=\"$name\" value=\"". check_form($value) ."\" ". drupal_attributes($attributes) ." />\n";
}
function form_weight($title = NULL, $name = "weight", $value = 0, $delta = 10, $description = 0, $extra = 0) {
function form_submit($value, $name = "op", $attributes = NULL) {
return form_button($value, $name, "submit", $attributes);
}
function form_weight($title = NULL, $name = "weight", $value = 0, $delta = 10, $description = NULL, $extra = 0) {
for ($n = (-1 * $delta); $n <= $delta; $n++) {
$weights[$n] = $n;
}
return form_select($title, $name, $value, $weights, $description, $extra);
}
/* @} */
function form_allowed_tags_text() {
return variable_get("allowed_html", "") ? (t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", ""))) : "";
}
function url($url = NULL, $query = NULL) {
function url($url = NULL, $query = NULL, $fragment = NULL, $absolute = NULL) {
global $base_url;
static $script;
......@@ -938,60 +1038,79 @@ function url($url = NULL, $query = NULL) {
$script = (strpos($_SERVER["SERVER_SOFTWARE"], "Apache") === false) ? "index.php" : "";
}
if ($alias = drupal_get_path_alias($url)) {
$url = $alias;
}
if (isset($fragment)) {
$fragment = "#$fragment";
}
$base = ($absolute ? $base_url . '/' : '');
if (variable_get("clean_url", "0") == "0") {
if (isset($url)) {
if (isset($query)) {
return "$base_url/$script?q=$url&amp;$query";
return "$base$script?q=$url&amp;$query$fragment";
}
else {
return "$base_url/$script?q=$url";
return "$base$script?q=$url$fragment";
}
}
else {
if (isset($query)) {
return "$base_url/$script?$query";
return "$base$script?$query$fragment";
}
else {
return "$base_url/";
return "$base$fragment";
}
}
}
else {
if (isset($url)) {
if (isset($query)) {
return "$base_url/$url?$query";
return "$base$url?$query$fragment";
}
else {
return "$base_url/$url";
return "$base$url$fragment";
}
}
else {
if (isset($query)) {
return "$base_url/$script?$query";
return "$base$script?$query$fragment";
}
else {
return "$base_url/";
return "$base$fragment";
}
}
}
}
function drupal_attributes($attributes = 0) {
if (is_array($attributes)) {
function drupal_attributes($attributes = array()) {
if (count($attributes)) {
$t = array();
foreach ($attributes as $key => $value) {
$t[] = "$key=\"$value\"";
}
return " ". implode($t, " ");
}
}
function l($text, $url, $attributes = array(), $query = NULL) {
return "<a href=\"". url($url, $query) ."\"". drupal_attributes($attributes) .">$text</a>";
function l($text, $url, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = NULL) {
if (drupal_get_normal_path($url) == $_GET['q']) {
if (isset($attributes['class'])) {
$attributes['class'] .= ' active';
}
else {
$attributes['class'] = 'active';
}
}
return "<a href=\"". url($url, $query, $fragment, $absolute) ."\"". drupal_attributes($attributes) .">$text</a>";
}
function field_get($string, $name) {
ereg(",?$name=([^,]+)", ", $string", $regs);
ereg(",$name=([^,]+)", ",$string", $regs);
return $regs[1];
}
......@@ -1006,7 +1125,7 @@ function field_set($string, $name, $value) {
function link_page() {
global $custom_links;
if (0 && is_array($custom_links)) {
if (is_array($custom_links)) {
return $custom_links;
}
else {
......@@ -1020,103 +1139,143 @@ function link_node($node, $main = 0) {
return module_invoke_all("link", "node", $node, $main);
}
function timer_start() {
global $timer;
list($usec, $sec) = explode(" ", microtime());
$timer = (float)$usec + (float)$sec;
}
function drupal_page_header() {
if (variable_get("dev_timer", 0)) {
timer_start();
}
function drupal_page_footer() {
if (variable_get("cache", 0)) {
if ($cache = page_get_cache()) {
$date = gmdate("D, d M Y H:i:s", $cache->created) ." GMT";
header("Last-Modified: $date");
header("ETag: \"$date\"");
if (function_exists("getallheaders") && $headers = getallheaders()) {
/*
** Notice that the above is an optional Apache-ism so for the
** time being we don't send 304 headers when "getallheaders()"
** is not supported (eg. on IIS webservers).
*/
if ($headers["If-Modified-Since"] == $date && $headers["If-None-Match"] == "\"$date\"") {
header("HTTP/1.0 304 Not Modified");
exit();
}
}
print $cache->data;
/*
** A hook for modules where modules may take action at the end of a
** request good uses include setting a cache, page logging, etc.
*/
module_invoke_all("exit");
exit();
}
page_set_cache();
}
/*
** Putting the check here avoids SQL query overhead in case we are
** serving cached pages. The downside, however, is that the init
** hooks might use unchecked data.
** A hook for modules where modules may take action at the end of a
** request good uses include setting a cache, page logging, etc.
*/
if (!user_access("bypass input data check")) {
if (!valid_input_data($_REQUEST)) {
die("terminated request because of suspicious input data");
module_invoke_all("exit");
}
/**
* Walks through the provided array and constructs an associative
* array out of it. The keys of the resulting array will be the
* values of the passed array. The values will either be the same
* (if no function was specified), or the results of the function
* given the value.
*
* @param $array An array
* @param $function A name of a function to apply to all values
*/
function drupal_map_assoc($array, $function = NULL) {
if (!isset($function)) {
$result = array();
foreach ($array as $value) {
$result[$value] = $value;
}
return $result;
}
elseif (function_exists($function)) {
$result = array();
foreach($array as $value) {
$result[$value] = $function($value);
}
return $result;
}
}
function drupal_page_footer() {
if (variable_get("cache", 0)) {
page_set_cache();
/**
* Wrapper around xml_parser_create() which extracts the encoding from the XML
* data first and sets the output encoding to UTF-8. This function should be
* used instead of xml_parser_create(), because PHP's XML parser doesn't check
* the input encoding itself.
*
* This is also where unsupported encodings should be converted.
* Callers should take this into account: $data might have been changed after
* the call.
*
* @param $data The XML data which will be parsed later.
*/
function drupal_xml_parser_create(&$data) {
$encoding = 'utf-8';
if (ereg('^<\?xml[^>]+encoding="([^"]+)"', $data, $match)) {
$encoding = $match[1];
}
/*
** A hook for modules where modules may take action at the end of a
** request good uses include setting a cache, page logging, etc.
*/
* Unsupported encodings are converted here into UTF-8.
* Requires iconv, see http://www.php.net/iconv
*/
$php_supported = array('utf-8', 'iso-8859-1', 'us-ascii');
if (!in_array(strtolower($encoding), $php_supported)) {
if (function_exists('iconv')) {
$out = iconv($encoding, 'utf-8', $data);
if ($out !== false) {
$data = $out;
$encoding = 'utf-8';
}
}
}
module_invoke_all("exit");
$xml_parser = xml_parser_create($encoding);
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'utf-8');
return $xml_parser;
}
unset($conf);
$config = conf_init();
/**
* UTF-8-safe string truncation
* If the end position is in the middle of a UTF-8 sequence, it scans backwards
* until the beginning of the byte sequence.
*
* Use this function whenever you want to chop off a string at an unsure
* location. On the other hand, if you're sure that you're splitting on a
* character boundary (e.g. after using strpos or similar), you can safely use
* substr() instead.
*
* @param $string The string to truncate
* @param $len An upper limit on the returned string length.
*/
function truncate_utf8($string, $len) {
$slen = strlen($string);
if ($slen <= $len) {
return $string;
}
if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) {
return substr($string, 0, $len);
}
while (ord($string[--$len]) < 0xC0) {};
return substr($string, 0, $len);
}
include_once "includes/$config.php";
include_once "includes/database.inc";
include_once "includes/module.inc";
include_once "includes/theme.inc";
include_once "includes/pager.inc";
include_once "includes/menu.inc";
include_once "includes/xmlrpc.inc";
include_once "includes/tablesort.inc";
// initialize configuration variables, using values from conf.php if available:
$conf = variable_init(isset($conf) ? $conf : array());
include_once "includes/file.inc";
// set error handler:
set_error_handler("error_handler");
// spit out the correct charset http header
header("Content-Type: text/html; charset=utf-8");
drupal_set_header("Content-Type: text/html; charset=utf-8");
// initialize the _GET["q"] prior to loading the modules and invoking their 'init' hook:
if (!empty($_GET["q"])) {
$_GET["q"] = drupal_get_normal_path(trim($_GET["q"], "/"));
}
else {
$_GET["q"] = drupal_get_normal_path(variable_get("site_frontpage", "node"));
}
// initialize installed modules:
module_init();
if ($_REQUEST && !user_access("bypass input data check")) {
if (!valid_input_data($_REQUEST)) {
die("terminated request because of suspicious input data");
}
}
// initialize localization system:
$locale = locale_init();
// initialize theme:
$theme = theme_init();
$theme = init_theme();
?>
......@@ -14,7 +14,6 @@
# $db_url = "mysql://user:password@hostname/database";
# $db_url = "pgsql://user:password@hostname/database";
# $db_url = "mssql://user:password@hostname/database";
$db_url = "mysql://drupal:drupal@localhost/drupal";
# If $db_prefix is specified all database table names will be
......
......@@ -4,7 +4,18 @@
function db_prefix_tables($sql) {
global $db_prefix;
return strtr($sql, array("{" => $db_prefix, "}" => ""));
if (is_array($db_prefix)) {
$prefix = $db_prefix["default"];
foreach ($db_prefix as $key => $val) {
if ($key !== "default") {
$sql = strtr($sql, array("{". $key. "}" => $val. $key));
}
}
}
else {
$prefix = $db_prefix;
}
return strtr($sql, array("{" => $prefix, "}" => ""));
}
$db_type = substr($db_url, 0, strpos($db_url, "://"));
......@@ -18,4 +29,5 @@ function db_prefix_tables($sql) {
db_connect($db_url);
?>
......@@ -21,6 +21,13 @@ function db_connect($url) {
*/
}
/**
* Runs a query in the database.
*
* @param $query SQL query, followed by a variable number of arguments which
* are substituted into query by sprintf.
* @return a MySQL result or FALSE if the query was not executed correctly.
*/
function db_query($query) {
$args = func_get_args();
......@@ -126,6 +133,7 @@ function db_next_id($name) {
** when needed
*/
$name = db_prefix_tables($name);
db_query("LOCK TABLES {sequences} WRITE");
$id = db_result(db_query("SELECT id FROM {sequences} WHERE name = '%s'", $name)) + 1;
db_query("REPLACE INTO {sequences} VALUES ('%s', %d)", $name, $id);
......@@ -141,9 +149,11 @@ function db_affected_rows() {
/**
* Runs a LIMIT query in the database.
*
* @param mixed $query SQL query, followed by a variable number of arguments which are substituted into query by sprintf, followed by 'from' and 'count' parameters. 'from' is the row to start fetching, 'count' the numbers of rows to fetch.
* @return resource a MySQL result or FALSE if the query was not executed correctly.
* @access public
* @param $query SQL query, followed by a variable number of arguments which
* are substituted into query by sprintf, followed by 'from' and 'count'
* parameters. 'from' is the row to start fetching, 'count' the numbers of
* rows to fetch.
* @return a MySQL result or FALSE if the query was not executed correctly.
*/
function db_query_range($query) {
$args = func_get_args();
......
......@@ -18,9 +18,9 @@ function db_connect($url) {
/**
* Runs a query in the database.
*
* @param $query SQL query
* @param $type module type of this item
* @return sql result resource
* @param $query SQL query, followed by a variable number of arguments which
* are substituted into query by sprintf.
* @return a DB_Result object or a DB_Error
*/
function db_query($query) {
......@@ -127,9 +127,10 @@ function db_error() {
function db_next_id($name) {
global $db_handle;
$name = db_prefix_tables($name);
$result = $db_handle->nextID($name);
if (DB::isError($result)) {
watchdog("error", "database: ". $result->getMessage() ."\nquery: ". htmlspecialchars($query));
watchdog("error", "database: ". $result->getMessage() ."\nsequence table: $name");
}
else {
return $result;
......@@ -145,9 +146,11 @@ function db_affected_rows() {
/**
* Runs a LIMIT query in the database.
*
* @param mixed $query SQL query followed by a variable number of arguments which are substituted into query by sprintf, followed by 'from' and 'count' parameters. 'from' is the row to start fetching, 'count' the numbers of rows to fetch.
* @return mixed a DB_Result object or a DB_Error
* @access public
* @param $query SQL query followed by a variable number of arguments which
* are substituted into query by sprintf, followed by 'from' and 'count'
* parameters. 'from' is the row to start fetching, 'count' the numbers of
* rows to fetch.
* @return a DB_Result object or a DB_Error
*/
function db_query_range($query) {
global $db_handle, $queries;
......
<?php
/* $Id$ */
/**
* @defgroup file File interface
* Common file handling functions.
* @{
*/
define('FILE_DOWNLOADS_PUBLIC', 1);
define('FILE_DOWNLOADS_PRIVATE', 2);
define('FILE_SEPARATOR', PHP_OS == 'WINNT' ? '\\' : '/');
/**
* Create the download path to a file.
*/
function file_create_url($path) {
if (strpos($path, variable_get('file_directory_path', 'files')) !== false) {
$path = trim(substr($path, strlen(variable_get('file_directory_path', 'files'))), '\\/');
}
switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
case FILE_DOWNLOADS_PUBLIC:
global $base_url;
return $base_url .'/'. variable_get('file_directory_path', 'files') .'/'. str_replace('\\', '/', $path);
case FILE_DOWNLOADS_PRIVATE:
return url('system/files', 'file='. $path);
}
}
/**
* Make sure the destination is a complete path, if it is not prepend the
* file system directory.
*/
function file_create_path($dest = 0) {
if (!$dest) {
return variable_get('file_directory_path', 'files');
}
$regex = (PHP_OS == 'WINNT' ? '.?:\\\\' : '/');
if (!file_check_location($dest, variable_get('file_directory_path', 'files')) && !preg_match("|^$regex|", $dest)) {
return variable_get('file_directory_path', 'files') . FILE_SEPARATOR . trim($dest, '\\/');
}
else {
return $dest;
}
}
/**
* Check that directory exists and is writable.
*
* @param $directory Path to extract and verify directory for.
* @return False when directory not found, or true when directory exists.
*/
function file_check_directory(&$directory) {
$directory = rtrim($directory, '/\\');
return is_dir($directory) && is_writable($directory);
}
/**
* Checks path to see if it is a directory, or a dir/file.
*
* @param $path
*/
function file_check_path(&$path) {
// Check if path is a directory.
if (file_check_directory($path)) {
return '';
}
// Check if path is a possible dir/file.
$filename = basename($path);
$path = dirname($path);
if (file_check_directory($path)) {
return $filename;
}
return false;
}
/**
* Check if $source is a valid file upload.
*
* @param $source
*/
function file_check_upload($source) {
if (is_object($source)) {
if (is_file($source->path)) {
return $source;
}
}
elseif ($_FILES["edit"]["name"][$source] && is_uploaded_file($_FILES["edit"]["tmp_name"][$source])) {
$file->name = trim(basename($_FILES["edit"]["name"][$source]), '.');
$file->type = $_FILES["edit"]["type"][$source];
$file->path = $_FILES["edit"]["tmp_name"][$source];
$file->error = $_FILES["edit"]["error"][$source];
$file->size = $_FILES["edit"]["size"][$source];
$file->source = $_FILES["edit"]["size"][$source];
return $file;
}
}
/**
* Check if a file is really located inside $directory. Should be used to make
* sure a file specified is really located within the directory to prevent
* exploits.
*
* @code
* // Returns false:
* file_check_location('/www/example.com/files/../../../etc/passwd', '/www/example.com/files');
* @endcode
*
* @param $source A string set to the file to check.
* @param $directory A string where the file should be located.
* @return 0 for invalid path or the real path of the source.
*/
function file_check_location($source, $directory = 0) {
$source = realpath($source);
$directory = realpath($directory);
if ($directory && strpos($source, $directory) !== 0) {
return 0;
}
return $source;
}
/**
* Saves a file to a new location. This is a powerful function that in many ways
* performs like an advanced version of copy().
* - Checks if $source and $dest are valid and readable/writable.
* - Performs a file copy if $source is not equal to $dest.
* - If file already exists in $dest it will append a number to the end of the
* filename, but before the file extension. It will increment the number until
* it finds a filename that is not already in use.
*
* @param $source A string specifying the file location of the original file.
* This parameter will contain the resulting destination filename in case of
* success.
* @param $dest A string containing the directory $source should be copied to.
* @param $replace A boolean that when true will overwrite any existing files,
* but when false append a _X to the filename.
* @return True for success, false for failure.
*/
function file_copy(&$source, $dest = 0, $replace = 0) {
$dest = file_create_path($dest);
$directory = $dest;
$basename = file_check_path($directory);
// Make sure we at least have a valid directory.
if ($basename === false) {
drupal_set_message(t('file copy failed: no directory configured, or it could not be accessed.'), 'error');
return 0;
}
// Process a file upload object.
if (is_object($source)) {
$file = $source;
$source = $file->path;
if (!$basename) {
$basename = $file->name;
}
}
$source = realpath($source);
if (!file_exists($source)) {
drupal_set_message(t('file copy failed: source file does not exist.'), 'error');
return 0;
}
// If destination file is not specified then use filename of source file.
$basename = $basename ? $basename : basename($source);
$dest = $directory . FILE_SEPARATOR . $basename;
if (file_exists($dest) && !$replace) {
// Destination file already exists and we can't replace is so we try and
// and find a new filename.
$pos = strrpos($basename, '.');
$name = substr($basename, 0, $pos);
if ($pos = strrpos($basename, '.')) {
$name = substr($basename, 0, $pos);
$ext = substr($basename, $pos);
}
else {
$name = $basename;
}
$counter = 0;
do {
$dest = $directory . FILE_SEPARATOR . $name .'_'. $counter++ . $ext;
} while (file_exists($dest));
}
if (!copy($source, $dest)) {
drupal_set_message(t('file copy failed.'), 'error');
return 0;
}
if (is_object($file)) {
$file->name = $basename;
$file->path = $dest;
$source = $file;
}
else {
$source = $dest;
}
return 1; // Everything went ok.
}
function file_move(&$source, $dest = 0, $replace = 0) {
$path = is_object($source) ? $source->path : $source;
if (file_copy($source, $dest, $replace)) {
if (unlink($path)) {
return 1;
}
drupal_set_message(t('removing original file failed.'), 'error');
}
return 0;
}
function file_delete($path) {
if (is_file($path)) {
unlink($path);
}
}
/**
* Saves a file upload to a new location. The source file is validated as a
* proper upload and handled as such.
*
* @param $source A string specifying the name of the upload field to save.
* This parameter will contain the resulting destination filename in case of
* success.
* @param $dest A string containing the directory $source should be copied to,
* will use the temporary directory in case no other value is set.
* @param $replace A boolean, set to true if the destination should be replaced
* when in use, but when false append a _X to the filename.
* @return An object containing file info or 0 in case of error.
*/
function file_save_upload($source, $dest = 0, $replace = 0) {
// Make sure $source exists in $_FILES.
if ($file = file_check_upload($source)) {
if (!$dest) {
$dest = variable_get('file_directory_temp', (PHP_OS == 'WINNT' ? 'c:\\windows\\temp' : '/tmp'));
$temporary = 1;
if (is_file($_SESSION['file_uploads'][$source]->path)) {
// If this file was uploaded by this user before replace the temporary copy.
$replace = 1;
}
}
if (!valid_input_data($file)) {
watchdog('error', t('Possible exploit abuse: invalid data.'));
drupal_set_message(t("file upload failed: invalid data."), 'error');
return 0;
}
// Check for file upload errors.
switch ($file->error) {
case 0: // UPLOAD_ERR_OK
break;
case 1: // UPLOAD_ERR_INI_SIZE
case 2: // UPLOAD_ERR_FORM_SIZE
drupal_set_message(t("file upload failed: file size too big."), 'error');
return 0;
case 3: // UPLOAD_ERR_PARTIAL
case 4: // UPLOAD_ERR_NO_FILE
drupal_set_message(t("file upload failed: incomplete upload."), 'error');
return 0;
default: // Unknown error
drupal_set_message(t("file upload failed: unkown error."), 'error');
return 0;
}
unset($_SESSION['file_uploads'][is_object($source) ? $source->source : $source]);
if (file_move($file, $dest, $replace)) {
if ($temporary) {
$_SESSION['file_uploads'][$source] = $file;
}
return $file;
}
return 0;
}
else {
// In case of previews return previous file object.
if (file_exists($_SESSION['file_uploads'][$source]->path)) {
return $_SESSION['file_uploads'][$source];
}
}
return 0;
}
/**
* Transfer file using http to client. Pipes a file through Drupal to the
* client.
*
* @param $source File to transfer.
* @param $headers An array of http headers to send along with file.
*/
function file_transfer($source, $headers) {
ob_end_clean();
foreach ($headers as $header) {
header($header);
}
$source = file_create_path($source);
// Transfer file in 1024 byte chunks to save memory usage.
$fd = fopen($source, 'rb');
while (!feof($fd)) {
print fgets($fd, 1024);
}
fclose($fd);
exit();
}
/**
* Call modules to find out if a file is accessible for a given user.
*/
function file_download() {
$file = $_GET['file'];
if (file_exists(file_create_path($file))) {
$list = module_list();
foreach ($list as $module) {
$headers = module_invoke($module, 'file_download', $file);
if ($headers === -1) {
print theme('page', message_access());
}
elseif (is_array($headers)) {
file_transfer($file, $headers);
}
}
}
drupal_not_found();
}
/**
* Finds all files that match a given mask in a given directory. Searches
* recursively.
*/
function file_scan_directory($dir, $mask, $nomask = array('.', '..', 'CVS'), $callback = 0) {
$files = array();
if (is_dir($dir) && $handle = opendir($dir)) {
while ($file = readdir($handle)) {
if (!in_array($file, $nomask)) {
if (is_dir("$dir/$file")) {
$files = array_merge($files, file_scan_directory("$dir/$file", $mask, $nomask, $callback));
}
elseif (ereg($mask, $file)) {
$name = basename($file);
$files["$dir/$file"]->filename = "$dir/$file";
$files["$dir/$file"]->name = substr($name, 0, strrpos($name, '.'));
if ($callback) {
$callback("$dir/$file");
}
}
}
}
closedir($handle);
}
return $files;
}
?>
<?php
// $Id$
/* $Id$ */
/**
* @defgroup menu Menu system
* @{
*/
define('MENU_SHOW', 0);
define('MENU_HIDE', 1);
define('MENU_HIDE_NOCHILD', 2);
/** @} */
/**
* Register a menu item with the menu system.
*
* @ingroup menu
* @param $path Location then menu item refers to.
* @param $title The title of the menu item to show in the rendered menu.
* @param $callback The function to call when this is the active menu item.
* @param $weight Heavier menu items sink down the menu.
* @param $hidden
* - MENU_SHOW show the menu (default).
* - MENU_HIDE hide the menu item, but register a callback.
* - MENU_HIDE_NOCHILD hide the menu item when it has no children.
*/
function menu($path, $title, $callback = NULL, $weight = 0, $hidden = MENU_SHOW) {
global $_list;
// add the menu to the flat list of menu items:
$_list[$path] = array("title" => $title, "callback" => $callback, "weight" => $weight, "hidden" => $hidden);
}
function menu($path, $title, $callback = NULL, $help = NULL, $weight = 0, $hidden = 0) {
global $_gmenu;
/**
* Returns an array with the menu items that lead to the specified path.
*/
function menu_get_trail($path) {
global $_list;
if (empty($_gmenu[$path])) {
// add the menu to the flat list of menu items:
$_gmenu[$path] = array("title" => $title, "callback" => $callback, "help" => $help, "weight" => $weight, "hidden" => $hidden, "children" => array());
$trail = array();
// find the best matching parent item:
$parent = substr($path, 0, strrpos($path, "/"));
while ($parent && !$_gmenu[$parent]) {
$parent = substr($parent, 0, strrpos($parent, "/"));
while ($path) {
if ($_list[$path]) {
array_unshift($trail, $path);
}
// check if any items need to be lowered:
if ($parent) {
foreach ($_gmenu[$parent]["children"] as $key => $item) {
if (strstr($item, $path)) {
// remove the item from its parent:
unset($_gmenu[$parent]["children"][$key]);
$path = substr($path, 0, strrpos($path, "/"));
}
// add the item to its new parent:
$_gmenu[$path]["children"][] = $item;
}
}
return $trail;
}
/**
* Returns the path of the active menu item.
* @ingroup menu
*/
function menu_get_active_item() {
return menu_set_active_item();
}
/**
* Sets the path of the active menu item.
* @ingroup menu
*/
function menu_set_active_item($path = NULL) {
global $_list;
static $stored_path;
if (is_null($stored_path) || !empty($path)) {
if (empty($path)) {
$path = $_GET["q"];
}
else {
$_GET['q'] = $path;
}
// add the menu to the best matching parent:
$_gmenu[$parent]["children"][] = $path;
while ($path && !$_list[$path]) {
$path = substr($path, 0, strrpos($path, "/"));
}
$stored_path = $path;
}
return $stored_path;
}
function menu_item($in_path) {
global $_gmenu;
/*
** If you want to theme your links, or if you want to replace them
** by an image, this would be the function to customize.
*/
$trail = menu_trail();
if (end($trail) == $in_path) {
$css = " class=\"current\"";
}
/**
* Returns the title of the active menu item.
*/
function menu_get_active_title() {
global $_list;
return "<a href=\"". url($in_path) ."\"$css>". t($_gmenu[$in_path]["title"]) ."</a>";
if ($path = menu_get_active_item()) {
return ucfirst($_list[$path]["title"]);
}
}
function menu_trail() {
global $_gmenu;
static $trail; // cache
/**
* Returns the help associated with the active menu item.
*/
function menu_get_active_help() {
if (empty($trail)) {
$trail = array();
if (menu_active_handler_exists()) {
$path = $_GET["q"];
$output = "";
while ($path) {
if ($_gmenu[$path]) {
$trail[] = $path;
$return = module_invoke_all("help", $path);
foreach ($return as $item) {
if (!empty($item)) {
$output .= $item ."\n";
}
$path = substr($path, 0, strrpos($path, "/"));
}
return $output;
}
}
$trail = array_reverse($trail);
/**
* Returns an array of rendered menu items in the active breadcrumb trail.
*/
function menu_get_active_breadcrumb() {
$links[] = l(t("Home"), "");
$trail = menu_get_trail($_GET["q"]);
foreach ($trail as $item) {
$links[] = _render_item($item);
}
return $trail;
return $links;
}
function menu_path() {
$trail = menu_trail();
/**
* Execute the handler associated with the active menu item.
*/
function menu_execute_active_handler() {
global $_list;
$links = array();
$path = menu_get_active_item();
foreach ($trail as $item) {
$links[] = menu_item($item);
if ($_list[$path]["callback"]) {
$arg = substr($_GET["q"], strlen($path) + 1);
if (isset($arg)) {
return call_user_func_array($_list[$path]["callback"], explode("/", $arg));
}
else {
return call_user_func($_list[$path]["callback"]);
}
}
}
return implode(" &raquo; ", $links);
function menu_active_handler_exists() {
global $_list;
$path = menu_get_active_item();
return function_exists($_list[$path]["callback"]);
}
function menu_help() {
global $_gmenu;
$path = menu_trail();
if ($path) {
$item = array_pop($path);
$output = $_gmenu[$item]["help"];
/**
* Returns true when the path is in the active trail.
*/
function menu_in_active_trail($path) {
static $trail;
if (empty($trail)) {
$trail = menu_get_trail($_GET["q"]);
}
return @$output;
return in_array($path, $trail);
}
function _menu_sort($a, $b) {
global $_gmenu;
$a = &$_gmenu[$a];
$b = &$_gmenu[$b];
return $a["weight"] < $b["weight"] ? -1 : ($a["weight"] > $b["weight"] ? 1 : ($a["title"] < $b["title"] ? -1 : 1));
/**
* Returns true when the menu has visisble children.
*/
function menu_has_visible_children($item) {
global $_list;
if ($_list[$item]['children']) {
foreach ($_list[$item]['children'] as $child) {
if ($_list[$child]['hidden'] == MENU_SHOW) {
return true;
}
}
}
return false;
}
function menu_tree($parent = "") {
global $_gmenu;
/**
* Returns a rendered menu tree.
*/
function menu_tree($parent = "", $hidden = 0) {
global $_list;
static $trail;
$output = "";
if (empty($trail)) {
$trail = menu_get_trail($_GET["q"]);
}
if ($_gmenu[$parent]["children"]) {
$output = "\n<ul>\n";
usort($_gmenu[$parent]["children"], "_menu_sort");
foreach ($_gmenu[$parent]["children"] as $item) {
if ($_gmenu[$item]["hidden"] == 0) {
$trail = menu_trail($item);
$style = ($_gmenu[$item]["children"] ? (in_array($item, $trail) ? "expanded" : "collapsed") : "leaf");
if (isset($_list[$parent]) && $_list[$parent]["children"]) {
usort($_list[$parent]["children"], "_menu_sort");
foreach ($_list[$parent]["children"] as $item) {
/*
** Don't render the menu when it is hidden, or when it has no call-back
** nor children. The latter check avoids that useless links are being
** rendered.
*/
$visible = menu_has_visible_children($item);
if (($_list[$item]["hidden"] == MENU_SHOW && $_list[$item]["callback"]) ||
($_list[$item]["hidden"] == MENU_SHOW && $visible) ||
($_list[$item]["hidden"] == MENU_HIDE_NOCHILD && $visible)) {
$style = ($visible ? (menu_in_active_trail($item) ? "expanded" : "collapsed") : "leaf");
$output .= "<li class=\"$style\">";
$output .= menu_item($item);
if (in_array($item, $trail)) {
$output .= _render_item($item);
if (menu_in_active_trail($item)) {
$output .= menu_tree($item);
}
$output .= "</li>\n";
}
else if ($_list[$item]["hidden"] == MENU_HIDE && $_list[$item]["children"]) {
$output .= menu_tree($item, 1);
}
}
$output .= "</ul>\n";
}
return $output;
}
function menu_map($parent = "") {
global $_gmenu;
$output = "<ul>";
usort($_gmenu[$parent]["children"], "_menu_sort");
foreach ($_gmenu[$parent]["children"] as $item) {
if ($_gmenu[$item]["hidden"] == 0) {
$output .= "<li>";
$output .= menu_item($item);
$output .= menu_map($item);
$output .= "</li>";
if ($output != '' && $hidden != MENU_HIDE) {
$output = "\n<ul>\n$output\n</ul>\n";
}
}
$output .= "</ul>";
return $output;
}
function menu_execute_action() {
global $_gmenu;
$trail = menu_trail();
$selected_menu = array_pop($trail);
/**
* Query to module to build the menu.
*/
function menu_build($type) {
/*
** Build a sequential list of all menus items.
*/
module_invoke_all("link", $type);
/*
** Tree-ify the sequential list of menu items by adding each
** menu item to the 'children' array of their direct parent.
*/
if ($_gmenu[$selected_menu]["callback"]) {
$arg = substr($_GET["q"], strlen($selected_menu) + 1);
if (empty($arg)) {
return call_user_func($_gmenu[$selected_menu]["callback"]);
global $_list;
foreach ($_list as $path => $data) {
/*
** Find $path's direct parent:
*/
$parent = $path;
do {
$parent = substr($parent, 0, strrpos($parent, "/"));
}
else {
return call_user_func_array($_gmenu[$selected_menu]["callback"], explode("/", $arg));
while ($parent && !$_list[$parent]);
if ($path) {
$_list[$parent]["children"][] = $path;
}
}
}
function menu_build($type) {
function _menu_sort($a, $b) {
global $_list;
// Empty the existing menu tree (if any):
unset($GLOBALS["_gmenu"]);
$a = &$_list[$a];
$b = &$_list[$b];
// Build the menu tree:
module_invoke_all("link", $type);
return $a["weight"] < $b["weight"] ? -1 : ($a["weight"] > $b["weight"] ? 1 : ($a["title"] < $b["title"] ? -1 : 1));
}
function _render_item($path) {
global $_list;
return l($_list[$path]["title"], $path);
}
?>
......@@ -3,10 +3,11 @@
// initialize modules:
function module_init() {
// Note: changing this also requires changing system_admin() @ modules/system.module.
// Note: changing this also requires changing system_listing() @ modules/system.module.
require_once "modules/admin.module";
require_once "modules/user.module";
require_once "modules/filter.module";
require_once "modules/system.module";
require_once "modules/user.module";
require_once "modules/watchdog.module";
module_list();
module_invoke_all("init");
......@@ -40,8 +41,8 @@ function module_invoke_all($hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL
return $return;
}
// return array of module names (includes lazy module loading):
function module_list($refresh = 0) {
// return array of module names (includes lazy module loading if not in bootstrap mode)
function module_list($refresh = 0, $bootstrap = 0) {
static $list;
if ($refresh) {
......@@ -49,17 +50,29 @@ function module_list($refresh = 0) {
}
if (!$list) {
$list = array("admin" => "admin", "system" => "system", "user" => "user", "watchdog" => "watchdog");
$result = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = '1' ORDER BY name");
$list = array("admin" => "admin", "filter" => "filter", "system" => "system", "user" => "user", "watchdog" => "watchdog");
if ($bootstrap) {
$result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1");
}
else {
$result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1");
}
while ($module = db_fetch_object($result)) {
if (file_exists($module->filename)) {
$list[$module->name] = $module->name;
include_once $module->filename;
/*
** Determine the current throttle status and see if module should be
** loaded based on server load. We have to directly access the
** throttle variables as the throttle.module may not be loaded yet.
*/
$throttle = ($module->throttle && variable_get("throttle_level", 0) > 4);
if (!$throttle) {
$list[$module->name] = $module->name;
include_once $module->filename;
}
}
}
natcasesort($list);
asort($list);
}
return $list;
}
......