У меня есть следующая схема, определенная в файле 'doodil.install' как часть настраиваемого модуля, который я пишу. Однако каждый раз, когда я включаю модуль в Drupal, я получаю белый экран смерти. Код для doodil.install показан ниже:
<?php
function doodil_schema() {
$schema['doodil_user'] = array(
'description' => t('The table containing users who have signed up for the chance to register.'),
'fields' => array(
'id' => array(
'description' => t('Primary Key ID'),
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'email_address' => array(
'description' => t('User\'s Email Address'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'first_name' => array(
'description' => t('User\'s First Name'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'last_name' => array(
'description' => t('User\'s Last Name'),
'type' => 'varchar',
'length' => 255,
),
'user_hash' => array(
'description' => t('A unique hash string to ID the User'),
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'active' => array(
'description' => t('Whether the account has been activated'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'successful_invites' => array(
'description' => t('The number of invites responded to'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
)
),
'primary key' => array( 'id' ),
);
// Return the Table Schema
return $schema;
}
Это файл модуля:
<?php
// $Id$
/**
* @file
* A module for encouraging users to sign up to Doodil, the hottest social
* network on the web.
*
* This module encourages users to invite their friends to sign up to Doodil
*/
define('USER_SIGNUP_CONFIRM_EMAIL',
'Hi !firstname,
You\'re just one step away from being able to invite your friends to Doodil - the hottest Social Network on the web! Just click the link below and you\'ll be all set to earn some invite points.
!confirmlink
See you soon!
Team Doodil');
/**
* Implements hook_help().
*/
function doodil_help($path, $arg) {
if ($path == 'admin/help#doodil') {
return t('A module to encourage users to invite their friends to sign up to Doodil.');
}
}
/**
* Implements hook_menu().
*/
function doodil_menu() {
// Create an Array of Menu Items
$items = array();
// Add the Initial "Sign Up" Item
$items['doodil/signup'] = array(
'title' => 'Sign up to Doodil',
'description' => 'Sign up to Doodil and invite your friends',
'page callback' => 'drupal_get_form',
'page arguments' => array('doodil_signup_form'),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
// Add the Sign Up from Invitation Item
$items['doodil/signup/%'] = array(
'title' => 'Sign up to Doodil',
'description' => 'Sign up to Doodil and invite your friends',
'page callback' => 'drupal_get_form',
'page arguments' => array('doodil_signup_form', 1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
// Add the Invitation Page
$items['doodil/invite/%'] = array(
'title' => 'Invite your Friends to Doodil',
'description' => 'Invite your Friends to join Doodil',
'page callback' => 'drupal_get_form',
'page arguments' => array('doodil_invite_form', 1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
// Return the Items Array
return $items;
}
function doodil_signup_form($form, &$form_args, $uhash = null, $fullsize = TRUE) {
// Determine the Size of the Form (Full Size for Page, Small for Block)
if ($fullsize) {
$width = '100';
} else {
$width = '20';
}
// [input text] First Name
$form['first_name'] = array(
'#type' => 'textfield',
'#title' => t('First Name'),
'#size' => $width,
);
// [input text] Last Name
$form['last_name'] = array(
'#type' => 'textfield',
'#title' => t('Last Name'),
'#size' => $width,
);
// [input text] Email Address
$form['email_address'] = array(
'#type' => 'textfield',
'#title' => t('Email Address'),
'#size' => $width,
);
// [input hidden] User Hash
$form['user_hash'] = array(
'#type' => 'hidden',
'#value' => $uhash,
);
// [input submit] Sign Me Up
$form['submit'] = array(
'#type' => 'submit',
'#title' => t('Sign Me Up'),
'#value' => t('Sign Me Up'),
);
return $form;
}
function doodil_signup_form_submit($form, $form_args) {
// Get the Base URL
global $base_url;
// Create a Unique Hash Key
$user_hash = substr(md5($form_args['values']['email_address'].microtime(true)), 0, 15);
// Create a Confirm User Link
$confirm_link = $base_url.'/doodil/confirm_signup/'.$user_hash;
// Insert the User into the Table
drupal_write_record('doodil_user', array(
'email_address' => $form_args['values']['email_address'],
'first_name' => $form_args['values']['first_name'],
'last_name' => $form_args['values']['last_name'],
'user_hash' => $user_hash,
));
// Build an "Account Array"
$account = array(
'first_name' => $form_args['values']['first_name'],
'last_name' => $form_args['values']['last_name'],
'email_address' => $form_args['values']['email_address'],
'confirm_link' => $confirm_link,
);
// Send the Email
drupal_mail(
'doodil',
'signup_confirm',
$account['email_address'],
language_default(),
$account,
variable_get('site_mail', NULL),
TRUE
);
// Do some Stuff here like email user and add to temp users table?
$message = t('A confirmation email has been sent to !email.',
array(
'!email' => $form_args['values']['email_address'],
'!uhash' => $form_args['values']['user_hash'],
));
// Send a Message
drupal_set_message($message);
}
function doodil_invite_form($form, &$form_args, $uhash) {
// Make the Form Element an Array
$form['email_address']['#tree'] = true;
// Loop through and add 10 Fields
for ($i = 1; $i <= 10; $i++) {
$form['email_address'][$i] = array(
'#type' => 'textfield',
'#title' => t('Friend !number\'s Email Address', array('!number' => $i)),
);
}
// [input submit] Sign Me Up
$form['submit'] = array(
'#type' => 'submit',
'#title' => t('Invite Friends'),
'#value' => t('Invite Friends'),
);
// Return the Form
return $form;
}
/**
* Implements hook_block_info().
*/
function doodil_block_info() {
// Create an Array of Blocks
$blocks = array();
// Add the Sign Up Block
$blocks['signup_form'] = array(
'info' => t('Doodil Signup Form.'),
'cache' => DRUPAL_NO_CACHE,
);
// Return the Blocks
return $blocks;
}
/**
* Implements hook_block_view().
*/
function doodil_block_view($block_name = '') {
// Figure out which block to show
switch($block_name) {
case('signup_form'):
$block = array(
'subject' => null,
'content' => drupal_get_form('doodil_signup_form', null, FALSE),
);
break;
}
// Return the Block View
return $block;
}
/**
* Implements hook_mail().
*/
function doodil_mail($key, &$message, $params) {
switch($key) {
case('signup_confirm'):
//$account = (object) $params;
$subject = t('Welcome to Doodil');
$body = USER_SIGNUP_CONFIRM_EMAIL;
$message['to'] = $params['email_address'];
$message['subject'] = $subject;
$message['body'][] = t(USER_SIGNUP_CONFIRM_EMAIL, array(
'!firstname' => $params['first_name'],
'!confirmlink' => $params['confirm_link']
));
break;
}
// Return the Message Array
return $message;
}