Skip to content
Commits on Source (532)
......@@ -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
......@@ -44,8 +42,8 @@ ErrorDocument 500 /error.php
<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:
# 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':
......
Drupal 4.3.0, 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 selective database table prefixing.
- performance improvements:
- performance:
* optimized many SQL queries for speed by converting left joins to inner joins.
- comment module:
* rewrote the comment housekeeping code to be much more efficient and scalable.
......@@ -17,7 +82,7 @@ Drupal 4.3.0, xxxx-xx-xx (to be released)
* improved the forum views and the themability thereof.
- book module:
* improved integration of non-book nodes in the book outline.
- usability improvements:
- 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.
......@@ -38,7 +103,7 @@ Drupal 4.2.0, 2003-08-01
* 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.
......@@ -89,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.
......@@ -106,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.
......
......@@ -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.
......@@ -160,16 +159,16 @@ access rights.
Use your administration panel to enable and configure services. For
example, set some general settings for your site with "Administration -
site configuration". Enable modules via "Administration - site
configuration - modules". User permissions can be set with
"Administration - user management - user permissions".
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 drupal.org.
available at http://drupal.org/.
CUSTOMIZING YOUR THEME(S)
-------------------------
......@@ -186,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,20 +28,8 @@ 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
......@@ -52,17 +40,13 @@ 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>
S: fixes/patches
M: Hilko Bengen <bengen@debian.org>
S: maintained
THE REST:
M: Dries <dries@drupal.org>
<?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);
}
......@@ -17,5 +18,5 @@
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) IDENTITY 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) 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].[url_alias] (
[pid] numeric (10, 0) NOT NULL,
[dst] [varchar] (128) NOT NULL,
[src] [varchar] (128) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[url_alias] WITH NOCHECK ADD
CONSTRAINT [DF_[url_alias_pid] DEFAULT (0) FOR [pid],
CONSTRAINT [DF_url_alias_dst] DEFAULT ('') FOR [dst],
CONSTRAINT [DF_url_alias_src] DEFAULT ('') FOR [src]
GO
CREATE INDEX [url_alias_src_idx] ON [dbo].[url_alias]([src]) ON [PRIMARY]
CREATE INDEX url_alias_dst_idx ON url_alias(dst);
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].[node_counter] (
[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] [numeric](10, 0) NULL ,
[name] [varchar] (60) NOT NULL ,
[pass] [varchar] (32) NOT NULL ,
[mail] [varchar] (64) 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].[users_uid_seq] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[vapor] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[variable] (
[name] [varchar] (48) 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],
CONSTRAINT [DF_users_status] DEFAULT (0) FOR [status],
CONSTRAINT [DF_users_timestamp] DEFAULT (0) FOR [timestamp],
CONSTRAINT [DF_users_rid] DEFAULT (0) FOR [rid],
CONSTRAINT [DF_users_pass] DEFAULT ('') FOR [pass],
CONSTRAINT [DF_users_homepage] DEFAULT ('') FOR [homepage],
CONSTRAINT [DF_users_theme] DEFAULT ('') FOR [theme],
CONSTRAINT [DF_users_signature] DEFAULT ('') FOR [signature],
CONSTRAINT [DF_users_language] DEFAULT ('') FOR [language]
GO
CREATE INDEX [IX_sid] ON [dbo].[sessions]([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 [sessions_sid_idx] ON [dbo].[sessions]([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:"2003-10-27";');
INSERT INTO variable(name,value) VALUES('theme_default','s:6:"marvin";');
INSERT INTO users(uid,name,mail,rid) VALUES(0,'','','1');
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
......@@ -53,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;
--
......@@ -65,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;
......@@ -78,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),
......@@ -104,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;
......@@ -120,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;
......@@ -140,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;
......@@ -155,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'
--
......@@ -171,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;
--
......@@ -197,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)
......@@ -272,12 +285,11 @@ 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 node_type (type(4)),
......@@ -297,8 +309,7 @@ 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;
--
......@@ -320,7 +331,7 @@ CREATE TABLE url_alias (
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;
......@@ -332,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;
......@@ -376,7 +387,7 @@ CREATE TABLE search_index (
) TYPE=MyISAM;
--
-- Table structure for table 'sessesions'
-- Table structure for table 'sessions'
--
......@@ -385,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)
......@@ -401,25 +412,6 @@ CREATE TABLE sequences (
PRIMARY KEY (name)
) TYPE=MyISAM;
--
-- Table structure for table 'site'
--
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 'node_counter'
--
......@@ -445,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;
......@@ -456,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)
......@@ -525,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),
......@@ -538,7 +532,7 @@ CREATE TABLE users (
CREATE TABLE variable (
name varchar(48) NOT NULL default '',
value text NOT NULL,
value longtext NOT NULL,
PRIMARY KEY (name)
) TYPE=MyISAM;
......@@ -549,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;
......@@ -567,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 '',
......@@ -579,19 +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');
REPLACE variable SET name='update_start', value='s:10:"2003-10-27;"';
REPLACE variable SET name='theme_default', value='s:6:"marvin";';
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:"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';
......
......@@ -51,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'
);
--
......@@ -105,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)
);
......@@ -121,7 +123,6 @@ 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) default '',
......@@ -153,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'
--
......@@ -169,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)
);
......@@ -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',
......@@ -412,26 +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 system
--
......@@ -442,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
--
......@@ -580,20 +572,26 @@ 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:"2003-10-27";');
INSERT INTO variable(name,value) VALUES('theme_default','s:6:"marvin";');
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 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');
......
<?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;
}
/* @} */
/**
* Build the alias/path array
* @name Page messages
* @ingroup common
*
* Functions to get and set the message of the current page.
* @{
*/
function drupal_get_path_map($action = "") {
static $cache;
static $map;
if ($action == "rebuild") {
$map = NULL;
$cache = 0;
}
if (!$cache) {
$result = db_query("SELECT * FROM {url_alias}");
while ($data = db_fetch_object($result)) {
$map[$data->dst] = $data->src;
}
function drupal_set_message($message = NULL, $type = "status") {
static $stored_message = array();
$cache = 1;
if (isset($message)) {
$stored_message[] = array($message, $type);
}
return $map;
return $stored_message;
}
function drupal_rebuild_path_map() {
drupal_get_path_map("rebuild");
function drupal_get_messages() {
return drupal_set_message();
}
/* @} */
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 breadcrumbs
* @ingroup common
*
* Functions to get and set the breadcrumb trail of the current page.
* @{
*/
if ($errno & E_ALL ^ E_NOTICE) {
watchdog("error", $types[$errno] .": $message in $filename on line $line.");
print "<pre>$entry</pre>";
/**
* @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 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_breadcrumb() {
$breadcrumb = drupal_set_breadcrumb();
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");
}
if (!isset($breadcrumb)) {
$breadcrumb = menu_get_active_breadcrumb();
array_pop($breadcrumb);
}
}
function _fix_gpc_magic_array(&$items) {
foreach ($items as $k => $i) {
if (is_array($i)) _fix_gpc_magic_array($items[$k]);
else $items[$k] = stripslashes($i);
}
return $breadcrumb;
}
/* @} */
function fix_gpc_magic() {
static $fixed = false;
if ($fixed) return;
if (ini_get("magic_quotes_gpc") == 0) return;
/**
* @name HTML head contents
* @ingroup common
*
* Set and get output that should be in the \<head\> tag.
* @{
*/
_fix_gpc_magic_array($_GET);
_fix_gpc_magic_array($_POST);
_fix_gpc_magic_array($_COOKIE);
function drupal_set_html_head($data = NULL) {
static $stored_head;
$fixed = true;
if (!is_null($data)) {
$stored_head .= "$data\n";
}
return $stored_head;
}
function arg($index) {
static $arguments;
function drupal_get_html_head() {
global $base_url;
if (empty($arguments)) {
$arguments = explode("/", $_GET["q"]);
}
$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 $arguments[$index];
return $output . drupal_set_html_head();
}
/* @} */
function array2object($node) {
/**
* @name URL path alias
* @ingroup common
*
* Functions to handle path aliases.
*/
function drupal_get_path_map($action = "") {
static $map = NULL;
if (is_array($node)) {
foreach ($node as $key => $value) {
$object->$key = $value;
}
}
else {
$object = $node;
if ($action == "rebuild") {
$map = NULL;
}
return $object;
}
function object2array($node) {
if (is_object($node)) {
foreach ($node as $key => $value) {
$array[$key] = $value;
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;
}
}
else {
$array = $node;
}
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);
}
else {
$output .= " <b><u><a href=\"". $item["link"] ."\">". $item["title"] ."</a></u></b><br />";
$output .= " <small>" . t($type) . ($item["user"] ? " - ". $item["user"] : "") ."". ($item["date"] ? " - ". format_date($item["date"], "small") : "") ."</small>";
$output .= "<br /><br />";
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;
}
return $output;
}
/**
* Render a generic search form.
* @name Conversion
* @ingroup common
*
* "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).
* 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\" class=\"form-text\" size=\"50\" value=\"". check_form($keys) ."\" name=\"keys\" />";
$output .= " <input type=\"submit\" class=\"form-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", $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:
*/
function referer_save() {
if (!strstr(referer_uri(), request_uri())) {
$_SESSION["referer"] = referer_uri();
}
}
/**
* @name Validation
* @ingroup common
*
* Functions to validate user input.
* @{
*/
/*
** Restores the referer from a persistent variable:
*/
/**
* 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}';
function referer_load() {
if (isset($_SESSION["referer"])) {
return $_SESSION["referer"];
}
else {
return 0;
}
return preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail);
}
/**
* 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) || 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;
}
}
......@@ -553,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);
......@@ -565,144 +599,138 @@ 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);
// 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);
/*
** Absolute URLs:
*/
// rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
$text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/?q=\\1/view/\\2/\\4", $text);
/**
* 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("$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);
if (!$action) {
$action = url("search");
}
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);
$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";
/*
** Absolute URLs:
*/
if ($options) {
$output .= "<br />";
$output .= t("Restrict search to") .": ";
// 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);
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);
}
}
}
// 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);
}
$form .= "<br />";
return $text;
return form($output, "post", $action);
}
function check_output($text) {
if (isset($text)) {
// filter content on output:
$text = filter($text);
/*
* Collect the search results:
*/
function search_data($keys = NULL) {
$edit = $_POST["edit"];
// get the line breaks right:
if (strip_tags($text, "<a><i><b><u><tt><code><cite><strong><img>") == $text) {
$text = nl2br($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);
}
}
}
}
}
else {
$text = message_na();
}
return $text;
return $output;
}
/**
* 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";
return search_form($action, $keys, $options) . "<br />". search_data($keys);
}
/* @} */
function check_form($text) {
return drupal_specialchars($text, ENT_QUOTES);
}
function check_file($filename) {
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";
......@@ -719,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";
......@@ -733,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) {
......@@ -762,99 +796,102 @@ 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) {
db_query("UPDATE {cache} SET data = '%s', created = %d, expire = %d WHERE cid = '%s'", $data, time(), $expire, $cid);
if (!db_affected_rows()) {
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":
$format = variable_get("date_format_short", "m/d/Y - H:i");
case 'small':
$format = variable_get('date_format_short', 'm/d/Y - H:i');
break;
case "large":
$format = variable_get("date_format_long", "l, F j, Y - H:i");
case 'large':
$format = variable_get('date_format_long', 'l, F j, Y - H:i');
break;
case "custom":
case 'custom':
// No change to format
break;
case "medium":
case 'medium':
default:
$format = variable_get("date_format_medium", "D, m/d/Y - H:i");
$format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
}
for ($i = strlen($format); $i >= 0; $c = $format[--$i]) {
if (strstr("DFlMSw", $c)) {
$date = t(date($c, $timestamp)) . $date;
$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 (strstr("AaBdgGhHiIjLmnOrstTUWYyZz", $c)) {
$date = date($c, $timestamp) . $date;
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.$date;
$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) {
......@@ -864,13 +901,13 @@ function format_name($object) {
*/
if (strlen($object->name) > 20) {
$name = substr($object->name, 0, 15) ."...";
$name = truncate_utf8($object->name, 15) ."...";
}
else {
$name = $object->name;
}
if (arg(0) == "admin") {
if (arg(0) == "admin" and user_access("administer users")) {
$output = l($name, "admin/user/edit/$object->uid", array("title" => t("Administer user profile.")));
}
else {
......@@ -893,105 +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_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 = 0, $extra = 0) {
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", ""))) : "";
}
/**
* Given an old url, return the alias.
*/
function drupal_get_path_alias($path) {
$map = drupal_get_path_map();
if ($map) {
return array_search($path, $map);
}
}
/**
* Given an alias, return the default url.
*/
function drupal_get_normal_path($path) {
$map = drupal_get_path_map();
return $map[$path];
}
function url($url = NULL, $query = NULL) {
function url($url = NULL, $query = NULL, $fragment = NULL, $absolute = NULL) {
global $base_url;
static $script;
......@@ -1009,60 +1042,75 @@ function url($url = NULL, $query = NULL) {
$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];
}
......@@ -1091,121 +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()) {
// 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;
$none_match = isset($_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");
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"])) {
if ($path = drupal_get_normal_path(trim($_GET["q"], "/"))) {
$_GET["q"] = $path;
}
$_GET["q"] = drupal_get_normal_path(trim($_GET["q"], "/"));
}
else {
if ($path = drupal_get_normal_path(variable_get("site_frontpage", "node"))) {
$_GET["q"] = $path;
}
else {
$_GET["q"] = variable_get("site_frontpage", "node");
}
$_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
......
......@@ -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();
......@@ -142,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) {
......@@ -146,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 = 0) {
function menu($path, $title, $callback = NULL, $weight = 0, $hidden = MENU_SHOW) {
global $_list;
// add the menu to the flat list of menu items:
......@@ -12,7 +33,7 @@ function menu($path, $title, $callback = NULL, $weight = 0, $hidden = 0) {
}
/**
* Returns an array with the menu items that lead to the specied path.
* Returns an array with the menu items that lead to the specified path.
*/
function menu_get_trail($path) {
global $_list;
......@@ -32,25 +53,40 @@ function menu_get_trail($path) {
/**
* 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 $path;
static $stored_path;
if (empty($path)) {
$path = $_GET["q"];
if (is_null($stored_path) || !empty($path)) {
if (empty($path)) {
$path = $_GET["q"];
}
else {
$_GET['q'] = $path;
}
while ($path && !$_list[$path]) {
$path = substr($path, 0, strrpos($path, "/"));
}
$stored_path = $path;
}
return $path;
return $stored_path;
}
/**
* Returns the title of the active menu item.
*/
* Returns the title of the active menu item.
*/
function menu_get_active_title() {
global $_list;
......@@ -60,19 +96,22 @@ function menu_get_active_title() {
}
/**
* Returns the help associated with the active menu item.
*/
* Returns the help associated with the active menu item.
*/
function menu_get_active_help() {
$path = $_GET["q"];
$output = "";
$return = module_invoke_all("help", $path);
foreach ($return as $item) {
if (!empty($item)) {
$output .= $item ."\n";
if (menu_active_handler_exists()) {
$path = $_GET["q"];
$output = "";
$return = module_invoke_all("help", $path);
foreach ($return as $item) {
if (!empty($item)) {
$output .= $item ."\n";
}
}
return $output;
}
return $output;
}
/**
......@@ -101,15 +140,23 @@ function menu_execute_active_handler() {
if ($_list[$path]["callback"]) {
$arg = substr($_GET["q"], strlen($path) + 1);
if (empty($arg)) {
return call_user_func($_list[$path]["callback"]);
if (isset($arg)) {
return call_user_func_array($_list[$path]["callback"], explode("/", $arg));
}
else {
return call_user_func_array($_list[$path]["callback"], explode("/", $arg));
return call_user_func($_list[$path]["callback"]);
}
}
}
function menu_active_handler_exists() {
global $_list;
$path = menu_get_active_item();
return function_exists($_list[$path]["callback"]);
}
/**
* Returns true when the path is in the active trail.
*/
......@@ -123,19 +170,36 @@ function menu_in_active_trail($path) {
return in_array($path, $trail);
}
/**
* 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;
}
/**
* Returns a rendered menu tree.
*/
function menu_tree($parent = "") {
function menu_tree($parent = "", $hidden = 0) {
global $_list;
static $trail;
$output = "";
if (empty($trail)) {
$trail = menu_get_trail($_GET["q"]);
}
if ($_list[$parent]["children"]) {
$output = "";
if (isset($_list[$parent]) && $_list[$parent]["children"]) {
usort($_list[$parent]["children"], "_menu_sort");
foreach ($_list[$parent]["children"] as $item) {
......@@ -144,8 +208,11 @@ function menu_tree($parent = "") {
** nor children. The latter check avoids that useless links are being
** rendered.
*/
if ($_list[$item]["hidden"] == 0 && ($_list[$item]["callback"] || $_list[$item]["children"])) {
$style = ($_list[$item]["children"] ? (menu_in_active_trail($item) ? "expanded" : "collapsed") : "leaf");
$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 .= _render_item($item);
if (menu_in_active_trail($item)) {
......@@ -153,9 +220,12 @@ function menu_tree($parent = "") {
}
$output .= "</li>\n";
}
else if ($_list[$item]["hidden"] == MENU_HIDE && $_list[$item]["children"]) {
$output .= menu_tree($item, 1);
}
}
if ($output != '') {
if ($output != '' && $hidden != MENU_HIDE) {
$output = "\n<ul>\n$output\n</ul>\n";
}
}
......@@ -209,11 +279,7 @@ function _menu_sort($a, $b) {
function _render_item($path) {
global $_list;
if ($path == $_GET["q"]) {
$css = " class=\"active\"";
}
return "<a href=\"". url($path) ."\"$css>". $_list[$path]["title"] ."</a>";
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;
}
......
<?php
// $Id$
/* ***************************************************
* external functions (API)
* ***************************************************/
/**
* @defgroup pager Pager interface
* @{
*
* Pager external functions (API).
*/
/**
* Use this function in your module or theme to display a pager.
* Use this function when doing select queries you wish to be able to page. The
* pager uses LIMIT-based queries to fetch only the records required to render a
* certain page. However, it has to learn the total number of records returned
* by the query to (among others) compute the number of pages (= number of all
* records / number of records per page). This is done by inserting "COUNT(*)"
* in the original query, ie. by rewriting the original query, say "SELECT nid,
* type FROM node WHERE status = '1' ORDER BY static DESC, created DESC" to read
* "SELECT COUNT(*) FROM node WHERE status = '1' ORDER BY static DESC, created
* DESC". Rewriting the query is accomplished using a regular expression.
*
* Unfortunately, the rewrite rule does not always work as intended for queries
* that (already) have a "COUNT(*)" or a "GROUP BY" clause, and possibly for
* other complex queries. In those cases, you can optionally pass a query that
* will be used to count the records.
*
* For example, if you want to page this query: "SELECT COUNT(*), TYPE FROM node
* GROUP BY TYPE", pager_query() would invoke the wrong query, being: "SELECT
* COUNT(*) FROM node GROUP BY TYPE". So instead, you should pass "SELECT
* COUNT(DISTINCT(TYPE)) FROM node" as the optional $count_query parameter.
*
* @param array $tags defines your buttons; text or img.
* @param int $limit how many nodes are displayed per page
* @param int $element support for multiple pagers per page (specify which this is)
* @param string $type allows for distinction between pagers on main page and admin page, etc.
* Supported types are "default", "admin" and "simple".
* @param $query the SQL query that needs paging
* @param $limit the number of rows per page
* @param $element optional attribute to distringuish between multiple pagers
* on one page
* @param $count_query an optional SQL query used to count records when
* rewriting the query would fail
*
* @return string html of pager
* @return SQL query result
*/
function pager_display($tags = "", $limit = 10, $element = 0, $type = "default", $attributes = array()) {
return theme("pager_display_". $type, $tags, $limit, $element, $attributes);
function pager_query($query, $limit = 10, $element = 0, $count_query = "") {
global $pager_from_array, $pager_total;
$from = $_GET["from"];
// count the total number of records in this query:
if ($count_query == "") {
$pager_total[$element] = db_result(db_query(preg_replace(array("/SELECT.*FROM/i", "/ORDER BY .*/"), array("SELECT COUNT(*) FROM", ""), $query)));
}
else {
$pager_total[$element] = db_result(db_query($count_query));
}
// convert comma separated $from to an array, used by other functions:
$pager_from_array = explode(",", $from);
return db_query_range($query, (int)$pager_from_array[$element], (int)$limit);
}
/** @} End of defgroup pager_api */
/**
* DEFAULT PAGER:
* When writing themes, you can rewrite this pager function in your
* theme. This is the most common pager type, and thus the main one
* to re-write in your theme.
*
* @see pager_display
* @addtogroup themeable
* @{
*/
/**
* When writing themes, you can rewrite this pager function in your theme.
* You need to call theme("pager", ...) to get a pager.
*/
function pager_display_default($tags = "", $limit = 10, $element = 0, $attributes = array()) {
function theme_pager($tags = "", $limit = 10, $element = 0, $attributes = array()) {
global $pager_total;
if ($pager_total[$element] > $limit) {
$output .= "<div id=\"pager\" class=\"container-inline\">";
......@@ -42,58 +82,31 @@ function pager_display_default($tags = "", $limit = 10, $element = 0, $attribute
return $output;
}
}
/** @} End of addtogroup themeable */
/**
* SIMPLE PAGER:
* When writing themes, you can rewrite this pager function in your
* theme. Keep in mind that the pager it defines is intended to have
* a "simple" look, possibly located in a table or block.
*
* @see pager_display
*/
function pager_display_simple($tags = "", $limit = 10, $element = 0, $attributes = array()) {
/*
** It's left as an exercise to theme writers to create an alternative
** pager for pager_display_simple(). if your theme does not offer a
** replacement, the theme.inc pager_display_default() is used.
*/
return pager_display_default($tags, $limit, $element, $attributes);
}
/**
* ADMIN PAGER:
* When writing themes, you can rewrite this pager function in your
* theme. Most themes will probably NOT re-write this function, as
* admin pages are not normally themed.
*
* @see pager_display
* @name Pager pieces
* Use these pieces to construct your own custom pagers in your theme. Note
* that you should NOT modify this file to customize your pager.
* @{
*/
function pager_display_admin($tags = "", $limit = 10, $element = 0, $attributes = array()) {
/*
** It's left as an exercise to theme writers to create an alternative
** pager for pager_display_admin(). if your theme does not offer a
** replacement, the pager.inc pager_display_default() is used.
*/
return pager_display_default($tags, $limit, $element, $attributes);
}
/* *******************************************************************
* PAGER PIECES:
* Use these pieces to construct your own custom pagers (i.e. in
* themes). Note that you should NOT modify this file to customize
* your pager)
* *******************************************************************/
/**
* displays a "first-page" link
*
* @see pager_previous
* @param $text defines the name (or image) of the link
* @param $limit how many nodes are displayed per page
* @param $element distinguish between multiple pagers on one page
* @param $attributes extra html attributes for \<a href> (eg. title,
* onMouseOver, etc.)
*
* @return string html of this pager piece
*/
function pager_first($text, $limit, $element = 0, $attributes = array()) {
global $pager_from_array;
if ($pager_from_array[$element]) {
return "<a href=\"". pager_link(pager_load_array(0, $element, $pager_from_array), $attributes) ."\">$text</a>";
return "<a href=\"". pager_link(pager_load_array(0, $element, $pager_from_array), $element, $attributes) ."\">$text</a>";
}
else {
// we are already at the first page, return nothing
......@@ -104,12 +117,14 @@ function pager_first($text, $limit, $element = 0, $attributes = array()) {
/**
* displays a "previous-page" link
*
* @param string $text defines the name (or image) of the link
* @param int $limit how many nodes are displayed per page
* @param int $element distinguish between multiple pagers on one page
* @param int $n how many pages we move back (defaults to 1)
* @param $text defines the name (or image) of the link
* @param $limit how many nodes are displayed per page
* @param $element distinguish between multiple pagers on one page
* @param $n how many pages we move back (defaults to 1)
* @param $attributes extra html attributes for \<a href> (eg. title,
* onMouseOver, etc.)
*
* @return string html of this pager piece
* @return string html of this pager piece
*/
function pager_previous($text, $limit, $element = 0, $n = 1, $attributes = array()) {
global $pager_from_array;
......@@ -117,19 +132,26 @@ function pager_previous($text, $limit, $element = 0, $n = 1, $attributes = array
if ($from_new[$element] < 1) {
return pager_first($text, $limit, $element, $attributes);
}
return "<a href=\"". pager_link($from_new, $attributes) ."\">$text</a>";
return "<a href=\"". pager_link($from_new, $element, $attributes) ."\">$text</a>";
}
/**
* displays a "next-page" link
*
* @see pager_previous
* @param $text defines the name (or image) of the link
* @param $limit how many nodes are displayed per page
* @param $element distinguish between multiple pagers on one page
* @param $n how many pages we move back (defaults to 1)
* @param $attributes extra html attributes for \<a href> (eg. title,
* onMouseOver, etc.)
*
* @return string html of this pager piece
*/
function pager_next($text, $limit, $element = 0, $n = 1, $attributes = array()) {
global $pager_from_array, $pager_total;
$from_new = pager_load_array(((int)$pager_from_array[$element] + ((int)$limit * (int)$n)), $element, $pager_from_array);
if ($from_new[$element] < $pager_total[$element]) {
return "<a href=\"". pager_link($from_new, $attributes) ."\">$text</a>";
return "<a href=\"". pager_link($from_new, $element, $attributes) ."\">$text</a>";
}
return " ";
}
......@@ -137,17 +159,23 @@ function pager_next($text, $limit, $element = 0, $n = 1, $attributes = array())
/**
* displays a "last-page" link
*
* @see pager_previous
* @param $text defines the name (or image) of the link
* @param $limit how many nodes are displayed per page
* @param $element distinguish between multiple pagers on one page
* @param $attributes extra html attributes for \<a href> (eg. title,
* onMouseOver, etc.)
*
* @return string html of this pager piece
*/
function pager_last($text, $limit, $element = 0, $attributes = array()) {
global $pager_from_array, $pager_total;
$from_new = pager_load_array(($pager_total[$element] - $limit), $element, $pager_from_array);
$from_new = pager_load_array(($pager_total[$element] - ($pager_total[$element] % $limit)), $element, $pager_from_array);
if ($from_new[$element] < ($pager_from_array[$element] + $limit)) {
return pager_next($text, $limit, $element, 1, $attributes);
}
if (($from_new[$element] > $pager_from_array[$element]) && ($from_new[$element] > 0) && $from_new[$element] < $pager_total[$element]) {
return "<a href=\"". pager_link($from_new, $attributes) ."\">$text</a>";
return "<a href=\"". pager_link($from_new, $element, $attributes) ."\">$text</a>";
}
return " ";
}
......@@ -155,8 +183,11 @@ function pager_last($text, $limit, $element = 0, $attributes = array()) {
/**
* displays "%d through %d of $d" type detail about the cur page
*
* @param string $format allows you to reword the format string
* @see pager_previous
* @param $limit how many nodes are displayed per page
* @param $element distinguish between multiple pagers on one page
* @param $format allows you to reword the format string
*
* @return string html of this pager piece
*/
function pager_detail($limit, $element = 0, $format = "%d through %d of %d.") {
global $pager_from_array, $pager_total;
......@@ -171,9 +202,14 @@ function pager_detail($limit, $element = 0, $format = "%d through %d of %d.") {
/**
* displays a list of nearby pages with additional nodes
*
* @param int $quantity defines the length of the page list
* @param string $text optional text to display before the page list
* @see pager_previous
* @param $limit how many nodes are displayed per page
* @param $element distinguish between multiple pagers on one page
* @param $quantity defines the length of the page list
* @param $text optional text to display before the page list
* @param $attributes extra html attributes for \<a href> (eg. title,
* onMouseOver, etc.)
*
* @return string html of this pager piece
*/
function pager_list($limit, $element = 0, $quantity = 5, $text = "", $attributes = array()) {
global $pager_from_array, $pager_total;
......@@ -229,7 +265,7 @@ function pager_list($limit, $element = 0, $quantity = 5, $text = "", $attributes
$output .= pager_previous($i, $limit, $element, ($pager_current - $i), $attributes) ." ";
}
if ($i == $pager_current) {
$output .= "<b>$i</b> ";
$output .= "<strong>$i</strong> ";
}
if ($i > $pager_current) {
$output .= pager_next($i, $limit, $element, ($i - $pager_current), $attributes) ." ";
......@@ -243,76 +279,22 @@ function pager_list($limit, $element = 0, $quantity = 5, $text = "", $attributes
return $output;
}
/* @} End of member group pager pieces */
/* ********************************************************************
* QUERIES - call this instead of db_query() if you want your query to
* support a pager.
* ********************************************************************/
/**
* Use this function when doing select queries you wish to be able to page.
* The pager uses LIMIT-based queries to fetch only the records required
* to render a certain page. However, it has to learn the total number
* of records returned by the query to (among others) compute the number
* of pages (= number of all records / number of records per page). This
* is done by inserting "COUNT(*)" in the original query, ie. by rewriting
* the original query, say "SELECT nid, type FROM node WHERE status = '1'
* ORDER BY static DESC, created DESC" to read "SELECT COUNT(*) FROM node
* WHERE status = '1' ORDER BY static DESC, created DESC". Rewriting the
* query is accomplished using a regular expression.
*
* Unfortunately, the rewrite rule does not always work as intended for
* queries that (already) have a "COUNT(*)" or a "GROUP BY" clause, and
* possibly for other complex queries. In those cases, you can optionally
* pass a query that will be used to count the records.
*
* For example, if you want to page this query: "SELECT COUNT(*), TYPE FROM
* node GROUP BY TYPE", pager_query() would invoke the wrong query, being:
* "SELECT COUNT(*) FROM node GROUP BY TYPE". So instead, you should pass
* "SELECT COUNT(DISTINCT(TYPE)) FROM node" as the optional $count_query
* parameter.
*
* @param string $query the SQL query that needs paging
* @param int $limit the number of rows per page
* @param int $element optional attribute to distringuish between multiple pagers on one page
* @param string $count_query an optional SQL query used to count records when rewriting the query would fail
*
* @return resource SQL query result
*/
function pager_query($query, $limit = 10, $element = 0, $count_query = "") {
global $pager_from_array, $pager_total;
$from = $_GET["from"];
// count the total number of records in this query:
if ($count_query == "") {
$pager_total[$element] = db_result(db_query(preg_replace(array("/SELECT.*FROM/i", "/ORDER BY .*/"), array("SELECT COUNT(*) FROM", ""), $query)));
}
else {
$pager_total[$element] = db_result(db_query($count_query));
}
// convert comma separated $from to an array, used by other functions:
$pager_from_array = explode(",", $from);
return db_query_range($query, (int)$pager_from_array[$element], (int)$limit);
}
function pager_link($from_new, $attributes = array()) {
function pager_link($from_new, $element, $attributes = array()) {
$q = $_GET["q"];
$from = $_GET["from"];
foreach($attributes as $key => $value) {
$query[] = "$key=$value";
}
$from_new = pager_load_array($from_new[$element], $element, explode("," ,$from));
if (count($attributes)) {
$url = url($q, "from=". $from_new[0] ."&amp;". implode("&amp;", $query));
$url = url($q, "from=". implode($from_new, ",") ."&amp;". implode("&amp;", $query));
}
else {
$url = url($q, "from=". $from_new[0]);
$url = url($q, "from=". implode($from_new, ","));
}
return $url;
......