-- --------------------------------------------------------

-- 
-- Table structure for table `channels`
-- 

DROP TABLE IF EXISTS `channels`;
CREATE TABLE `channels` (
  `id` bigint(20) NOT NULL auto_increment,                  -- the primary key
  `channelName` varchar(255) NOT NULL,                     -- the full name of the channel
  `parent` bigint(20) NOT NULL default '0',                -- the primary key of the parent of this channel
  `description` varchar(255) NOT NULL default '',         -- a description of the channel
  `created` double precision NOT NULL default '0.0',    -- the date and time the channel was created
  `keywords` varchar(255) NOT NULL default '',            -- keywords related to the channel
  `public` enum('y','n') NOT NULL default 'y',             -- whether or not the channel is available to all
  `owner` varchar(255) NOT NULL default '',               -- the name of the group that controls access to the channel
  `moderator` varchar(255) NOT NULL default '',           -- the name of the group that moderates publication to the channel
  `provider` varchar(255) NOT NULL default '',            -- the content provider for the channel
  `meta` longtext NOT NULL default '',                     -- additional metadata for the channel
  PRIMARY KEY  (`id`),
  UNIQUE KEY `channelName` (`channelName`),
  FULLTEXT KEY `keywords` (`channelName`,`description`,`keywords`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- ID, channelName, parent, description, owners, created,
-- lastUpdate, keywords, icon, public, defaultView, moderators, source, fields,
-- filter, defaultLimit, defaultGrouping, defaultSort, meta
-- ID, channel name, parent
-- description
-- created
-- keywords
-- public, owner, moderator
-- provider
-- meta
INSERT INTO `channels` VALUES(
1, 'home', 0,
'This is the default channel for the site',
unix_timestamp(),
'home',
'y', 'editors', '',
'Content.PerUser.Arena.ContentProviders,AnArenaParsedContentProvider',
'icon:=/media/icons/channel/home.png|
viewProvider:=View.PerUser.Arena.Views,AnArenaView|
viewParameters:=view=channel/blog|
contentHandler:=Content.PerUser.Arena.PostsWithHighlighting,AnArenaPostWithHighlighting|
onFetchContent:=\n
source = Site.Posts.category\n
sort += ("-sticky", "-published")\n
\n
\n
if "limit" not in Request:\n
    limit = 7\n
\n
if "id" in Request:\n
    filter.append(("{field:id} = {}", Request["id"].value))\n
    Request["view"] = "post/single"\n
\n
else:\n
    filter.append(("FIND_IN_SET({},{field:channels})", Channel.name()))\n
    filter.append(("AND {field:draft} = {}", "n"))\n
\n
if ("title" in Request) and (len(Request["title"].value) > 0):\n
    filter.append(("AND {field:title} = {}", Request["title"].value))\n
    Request["view"] = "post/single"\n');

INSERT INTO `channels` VALUES(
2, 'administration', 0,
'This channel allows members of the administrators group to administer the site',
unix_timestamp(),
'admin,administer,administration',
'n', 'administrators', '',
'Content.PerUser.Arena.Administration,AnArenaAdministrator',
'icon:=/media/icons/channel/admin.png|
viewProvider:=View.PerUser.Arena.Views,AnArenaView');

INSERT INTO `channels` VALUES(
3, 'search', 0,
'Search for posts within the site',
unix_timestamp(),
'search,find',
'y', 'administrators', '',
'Content.PerUser.Arena.ContentProviders,AnArenaParsedContentProvider',
'icon:=/media/icons/channel/search.png|
viewProvider:=View.PerUser.Arena.Views,AnArenaView|
viewParameters:=view=site/search/posts|
contentHandler:=Content.PerUser.Arena.Posts,AnArenaPost|
onFetchContent:=\n
source = Site.Posts.category\n
\n
# Determine which fields to search\n
searchFields = None\n
if "what" in Request:\n
    searchFields = Request["what"].value.lower()\n
\n
# Determine if a full-text search is required
fullText = searchFields in ("tags", "all")\n
\n
if "limit" not in Request:\n
    limit = 25\n
\n
if "title" in Request:\n
    if fullText == False:\n
        filter.append(("{field:title} = {}", Request["title"].value))\n
\n
    else:\n
        if searchFields == "tags": \n
            filter.append(\n
                ("MATCH({field:keywords}) " + \\\n
                     "AGAINST ({} IN BOOLEAN MODE)", Request["title"].value))\n
\n
        else:\n
            filter.append(\n
                 ("MATCH(" + \\\n
                    "{field:title}," + \\\n
                    "{field:description}," + \\\n
                    "{field:keywords}," + \\\n
                    "{field:content}) AGAINST ({} IN BOOLEAN MODE)",\n
                    Request["title"].value)\n
                )\n
\n
        sort.append("-$relevance")\n');

INSERT INTO `channels` VALUES(   
4, '$site/channels/list', 0,
'This channel returns a list of channels on the site, tailored to the current user',
unix_timestamp(),
'',
'y', 'administrators', '',
'Content.PerUser.Arena.ChannelsList,AnArenaChannelsListing',
'viewProvider:=View.PerUser.Arena.Views,AnArenaView|
viewParameters:=view=site/navigation|
onFetchContent:=\n
source = Site.Posts.category\n
fields += ("channels",)\n
\n
filter.append(("{field:draft} = {}", "n"))\n');

INSERT INTO `channels` VALUES(
5, '$site/user/profile', 0,
'This channel lists profile information for a specific user',  
unix_timestamp(),
'profile,user,whois',
'y', 'administrators', '',
'Content.PerUser.Arena.ContentProviders,AnArenaParsedContentProvider',
'viewProvider:=View.PerUser.Arena.Views,AnArenaView|
viewParameters:=view=site/user/profile|
contentHandler:=Content.PerUser.Arena.Posts,AnArenaPost|
displayName:=User Profile|
onFetchContent:=\n
source = Site.Users.category\n
fields += ("id", "userName", "icon", "created", "fullName", "description", \n
    "email", "website", "lastVisit", "postCount", "content")\n
\n
if ("title" in Request) and (len(Request["title"].value) > 0):\n
    filter.append(("{field:userName} = {}", Request["title"].value))\n
\n
else:\n
    filter.append(("{field:userName} = {}", Site.Users.anonymous))\n');

INSERT INTO `channels` VALUES(
6, '$site/user/login', 0,
'This channel allows registered users to authenticate themselves',
unix_timestamp(),
'login',
'y', 'administrators', '',
'Content.PerUser.Arena.UserAuthentication,AUserAuthenticator',
'icon:=/media/icons/user/login.png|
displayName:=Log In|
viewProvider:=View.PerUser.Arena.Views,AnArenaView|
viewParameters:=view=site/user/login');

INSERT INTO `channels` VALUES(
7, '$site/posts/edit', 0,
'This channel allows posts to be created and edited.',
unix_timestamp(),
'',
'y', 'administrators', '',
'Content.PerUser.Arena.PostEditing,AnArenaPostEditor',
'viewProvider:=View.PerUser.Arena.Views,AnArenaView|
viewParameters:=view=post/edit|
displayName:=Edit|
contentHandler:=Content.PerUser.Arena.Posts,AnArenaPost|
onFetchContent:=\n
if "id" in Request:\n
    if Request["id"].value > 0:\n
        source = Site.Posts.category\n
        filter.append(("{field:id} = {}", Request["id"].value))\n
\n
elif "title" in Request:\n
    source = Site.Posts.category\n
    filter.append(("{field:title} = {}", Request["title"].value))\n
    filter.append(("AND {field:author} = {}", User.name()))\n');

INSERT INTO `channels` VALUES(
8, '$site/posts/draft', 0,
'This channel serves as the repository for draft copies of posts.',
unix_timestamp(),
'',
'y', 'administrators', '',
'Content.PerUser.Arena.ContentProviders,AnArenaParsedContentProvider',
'viewProvider:=View.PerUser.Arena.Views,AnArenaView|
contentHandler:=Content.PerUser.Arena.Posts,AnArenaPost|
onFetchContent:=\n
source = Site.Posts.category\n
sort.append("-published")\n
\n
if "id" in Request:\n
    filter.append(("{field:id} = {}", Request["id"].value))\n
\n
else:\n
    filter.append(("{field:channelName} = {} AND", Channel.name()))\n
\n
    if "title" in Request:\n
        filter.append(("{field:title} = {}", Request["title"].value))\n
\n
    else:\n
        filter.append(("{field:author = {}", User.name()))\n');

INSERT INTO `channels` VALUES(
9, '$site/attach', 0,
'This channel is used to manage attachments.',
unix_timestamp(),
'',
'y', 'administrators', '',
'Content.PerUser.Arena.AttachManagement,AnArenaAttachmentManager',
'viewProvider:=View.PerUser.Arena.Views,AnArenaView|
viewParameters:=view=attach/single|
contentHandler:=Content.PerUser.Arena.Attachments,AnArenaAttachment|
icon:=/media/icons/channel/site.attach.png|
displayName:=Attachments|
onFetchContent:=\n
source = Site.Attachments.category\n
\n
# Determine which fields to search\n
searchFields = None\n
if "what" in Request:\n
    searchFields = Request["what"].value.lower()\n
\n
# Determine if a full-text search is required
fullText = searchFields in ("tags", "all")\n
\n
if "limit" not in Request:\n
    limit = 25\n
\n
if "id" in Request:\n
    filter.append(("{field:id} = {}", Request["id"].value))\n
    limit = -1\n
\n
elif "title" in Request:\n
    if fullText == False:\n
        filter.append(("{field:attachmentName} = {}", Request["title"].value))\n
\n
    else:\n        
        if searchFields == "tags":\n
            filter.append(\n
                ("MATCH({field:keywords}) " + \\\n
                    "AGAINST ({} IN BOOLEAN MODE)", Request["title"].value))\n
\n
        else:\n
            filter.append(\n
                ("MATCH(" + \\\n
                    "{field:attachmentName}," + \\\n
                    "{field:description}," + \\\n
                    "{field:keywords}) AGAINST ({} IN BOOLEAN MODE)",\n
                    Request["title"].value)\n
                )\n
\n                
        sort.append("-$relevance")\n');

-- --------------------------------------------------------

-- 
-- Table structure for table `attachments`
-- 

DROP TABLE IF EXISTS `attachments`;
CREATE TABLE `attachments` (
  `id` bigint(20) NOT NULL auto_increment,              -- the primary key
  `attachmentName` varchar(255) NOT NULL default '',    -- the name of the attachment
  `category` varchar(255) NOT NULL default '',          -- the attachment category
  `localPath` varchar(255) NOT NULL default '',         -- the file system path to the attachment
  `clientPath` varchar(255) NOT NULL default '',        -- the path to the attachment as seen by remote clients
  `mimeType` varchar(255) NOT NULL default '',          -- the MIME type of the attachment
  `fileSize` bigint(20) NOT NULL default '0',           -- the size of the attachment, in bytes
  `icon` varchar(255) NOT NULL default '',              -- the path to an icon used to represent the attachment
  `description` varchar(255) NOT NULL default '',       -- a brief description of the attachment
  `keywords` varchar(255) NOT NULL default '',          -- a list of keywords applicable to the attachment
  `author` varchar(255) NOT NULL default '',            -- the name of the original author of the attachment
  `editor` varchar(255) NOT NULL default '',            -- the name of the most recent editor of the attachment
  `reviewer` varchar(255) NOT NULL default '',          -- the name of the moderator that approved the attachment
  `created` double precision NOT NULL default '0.0',    -- the date the attachment was first uploaded
  `published` double precision NOT NULL default '0.0',  -- the date the attachment was last updated
  `ip` varchar(255) NOT NULL default '',                -- the IP address of the user that last modified the post
  `meta` text NOT NULL default '',                      -- additional metadata concerning the attachment
  PRIMARY KEY  (`id`),
  UNIQUE KEY `attachmentName` (`attachmentName`),
  FULLTEXT KEY `keywords` (`attachmentName`, `keywords`, `description`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- INSERT INTO `attachments` VALUES(
-- 1, 'argle', 'archives', 
-- '/media/attachments/archives/argle.tar.gz',
-- 'application/gzip',
-- 1258291, '',
-- 'This is a phony attachment, the sole purpose of which is to test the attachment system.',
-- 'argle,bargle,fooferaw',
-- 'michael', 'michael', '', unix_timestamp(), unix_timestamp(), '127.0.0.1', '');


-- --------------------------------------------------------

-- 
-- Table structure for table `posts`
-- 

DROP TABLE IF EXISTS `posts`;
CREATE TABLE `posts` (
  `id` bigint(20) NOT NULL auto_increment,              -- the primary key
  `title` varchar(255) NOT NULL default '',             -- the title of the post
  `description` varchar(255) NOT NULL default '',       -- a brief description of the post
  `author` varchar(255) NOT NULL default '',            -- the name of the original author of the post
  `editor` varchar(255) NOT NULL default '',            -- the name of the most recent editor of the post
  `reviewer` varchar(255) NOT NULL default '',          -- the name of the moderator that approved the post
  `icon` varchar(255) NOT NULL default '',              -- the path to an icon related to the post
  `keywords` varchar(255) NOT NULL default '',          -- a list of keywords related to the post (aka "tags")
  `created` double precision NOT NULL default '0.0',    -- the date the post was first created
  `published` double precision NOT NULL default '0.0',  -- the date the post was last published (or updated)
  `ip` varchar(255) NOT NULL default '',                -- the IP address of the user that last modified the post
  `draft` enum('y', 'n') NOT NULL default 'n',          -- whether or not the post is a draft
  `sticky` enum('y', 'n') NOT NULL default 'n',         -- whether or not the post is sticky
  `channels` text NOT NULL default '',                  -- the names of the channels to which the post belongs  
  `meta` text NOT NULL default '',                      -- additional metadeta related to the post
  `content` longtext NOT NULL default '',               -- the content of the post
  PRIMARY KEY  (`id`),
  KEY `published` (`published`),
  FULLTEXT KEY `keywords` (`title`,`description`,`keywords`,`channels`,`content`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

-- 
-- Table structure for table `comments`
-- 

DROP TABLE IF EXISTS `comments`;
CREATE TABLE `comments` (
  `id` bigint(20) NOT NULL auto_increment,             -- the primary key
  `pid` bigint(20) NOT NULL default '0',               -- the ID of the post to which the comment belongs
  `parent` bigint(20) NOT NULL default '0',            -- the ID of the comment to which this comment belongs (for threaded comments)
  `grandParent` bigint(20) NOT NULL default '0',       -- the ID of the ultimate parent of this comment (for threaded comments)
  `title` varchar(255) NOT NULL default '',            -- the title of the comment
  `author` varchar(255) NOT NULL default '',           -- the name of the original author of the comment
  `reviewer` varchar(255) NOT NULL default '',         -- the name of the moderator that approved the comment
  `icon` varchar(255) NOT NULL default '',             -- the path to an icon related to the comment
  `created` double precision NOT NULL default '0.0',   -- the date the comment was first created
  `published` double precision NOT NULL default '0.0', -- the date the comment was last published (or updated)
  `ip` varchar(255) NOT NULL default '',               -- the IP address of the user that last modified the comment
  `meta` text NOT NULL default '',                     -- additional metadata related to the comment
  `content` longtext NOT NULL default '',              -- the content of the comment
  PRIMARY KEY  (`id`),
  KEY `pid` (`pid`),
  KEY `published` (`published`),
  FULLTEXT KEY `keywords` (`title`,`content`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

-- 
-- Table structure for table `sessions`
-- 

DROP TABLE IF EXISTS `sessions`;
CREATE TABLE `sessions` (
  `id` char(64) NOT NULL,                               -- the session ID (and primary key)
  `expiration` double precision NOT NULL default '0.0', -- the date and time that the session expires
  `meta` text NOT NULL default '',                      -- session metadata
  PRIMARY KEY (`id`),
  KEY `expiration` (`expiration`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

-- 
-- Table structure for table `subscriptions`
-- 

DROP TABLE IF EXISTS `subscriptions`;
CREATE TABLE `subscriptions` (
  `id` bigint(20) NOT NULL auto_increment,         -- the primary key
  `channelName` varchar(255) NOT NULL default '',  -- the name of the channel to which the subscription applies
  `groupName` varchar(255) NOT NULL default '',    -- the name of the group to which the subscription applies
  `rights` varchar(25) NOT NULL default '',        -- the rights granted by the subscription
  PRIMARY KEY  (`id`),
  KEY `channelName` (`channelName`),
  KEY `groupName` (`groupName`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- Rights:
--   r            Read from and access the channel
--   m            Edit (modify) existing channel content
--   w            Create new channel content
--   y            Reply to channel content
--   d            Delete channel content
--   C            Create new channels within the channel
--   D            Delete channels within the channel
--   M            Modify channels within the channel

INSERT INTO `subscriptions` VALUES (1, '$site/channels/public', 'administrators', 'rmwydCDM');
INSERT INTO `subscriptions` VALUES (2, '$site/channels/private', 'administrators', 'rydCDM');
INSERT INTO `subscriptions` VALUES (3, '$site/channels/public', 'visitors', 'r');
INSERT INTO `subscriptions` VALUES (4, '$site/channels/public', 'site-editors', 'rmyd');
INSERT INTO `subscriptions` VALUES (5, '$site/attach', 'administrators', 'wd');
INSERT INTO `subscriptions` VALUES (6, 'administration', 'administrators', 'rmwyd');
INSERT INTO `subscriptions` VALUES (7, 'search', 'administrators', 'r');
INSERT INTO `subscriptions` VALUES (8, 'search', 'visitors', 'r');
INSERT INTO `subscriptions` VALUES (9, 'search', 'site-editors', 'r');

-- --------------------------------------------------------

-- 
-- Table structure for table `users`
-- 

DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `id` bigint(20) NOT NULL auto_increment,              -- the primary key
  `userName` varchar(255) NOT NULL,                     -- the user name
  `userPassword` varchar(255) NOT NULL,                 -- the encrypted user password
  `icon` varchar(255) NOT NULL default '',              -- the path to an icon related to the user
  `created` double precision NOT NULL default '0.0',    -- the date and time the user was added
  `fullName` varchar(255) NOT NULL default '',          -- the full name of the user
  `description` varchar(255) NOT NULL default '',       -- a brief description of the user (e.g., "Webmaster")
  `email` varchar(255) NOT NULL default '',             -- an e-mail address for the user (needed for moderators)
  `website` varchar(255) NOT NULL default '',           -- the URL of a website related to the user (for profile)
  `enabled` enum('y','n') NOT NULL default 'y',         -- whether or not the user is active
  `lastVisit` double precision NOT NULL default '0.0',  -- the date and time the user last logged in to the site
  `failedLogins` int(10) NOT NULL default '0',          -- the number of failed login attempts
  `challengePrompt` varchar(255) NOT NULL default '',   -- a challenge question used to reset the user's password
  `challengeReply` varchar(255) NOT NULL default '',    -- the encrypted challenge reply
  `postCount` bigint(20) NOT NULL default '0',          -- the number of posts made by the user to the site
  `content` text NOT NULL default '',                   -- the content of the user's profile
  `meta` text NOT NULL default '',                      -- user metadata
  PRIMARY KEY  (`id`),
  UNIQUE KEY `userName` (`userName`),
  FULLTEXT KEY `keywords` (`fullName`,`email`,`description`,`content`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- Default password for administrator: admin+this+site
INSERT INTO `users` VALUES(1, 'administrator', '5ea13df83cd8d0091717c5e7f8ce557102e245f79fd140e48ce2c795841d7dfe', '', unix_timestamp(), 'Administrator', 'This is the account for the site administrator.', '', '', 'y', unix_timestamp(), 0, '', '', 0, '', '');
INSERT INTO `users` VALUES(2, 'visitor', '', '', unix_timestamp(), 'Anonymous', 'This is the account for anonymous site visitors.', '', '', 'y', unix_timestamp(), 0, '', '', 0, '', '');

--
-- Table structure for table `user2group`
--
DROP TABLE IF EXISTS `user2group`;
CREATE TABLE `user2group` (
  `id` bigint(20) NOT NULL auto_increment,  -- the primary key
  `userName` varchar(255) NOT NULL,         -- the user name
  `groupName` varchar(255) NOT NULL,        -- the name of a group to which the user belongs
  PRIMARY KEY (`id`),
  KEY `userName` (`userName`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO `user2group` VALUES(1, 'administrator', 'administrators');
INSERT INTO `user2group` VALUES(2, 'visitor', 'visitors');

-- --------------------------------------------------------

-- 
-- Table structure for table `statistics`
-- 

DROP TABLE IF EXISTS `statistics`;
CREATE TABLE `statistics` (
  `id` bigint(20) NOT NULL auto_increment,
  `category` varchar(255) NOT NULL default '',
  `item` varchar(255) NOT NULL default '',
  `description` varchar(255) NOT NULL default '',
  `value` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`ID`),
  KEY `category` (`category`),
  KEY `item` (`item`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

