array('label' => t('Mugshot')),
);
return $fields;
}
/** Implementation of hook_field_settings **/
function mugshot_cck_field_settings($op, $field) {
switch ($op) {
case 'database columns':
$columns = array(
'mid' => array('type' => 'int', 'not null' => TRUE, 'default' => '0'),
);
return $columns;
}
}
/** Implementation of hook_field **/
function mugshot_cck_field($op, &$node, $field, &$items, $teaser, $page) {
switch ($op) {
case 'validate':
// Check for existence of the most recent mugshot, deny if it doesn't exist
if (!mugshot_cck_recent_mugshot($_SESSION['mugshot_recent_timestamp'])) {
form_set_error('mugshot', t('You did not capture an image using the Flash browser.'));
}
break;
case 'submit':
$timestamp = $_SESSION['mugshot_recent_timestamp'];
unset($_SESSION['mugshot_recent_timestamp']);
// Save mugshut ID as part of the node
$mugshot = mugshot_cck_recent_mugshot($timestamp);
$items[0]['mid'] = $mugshot->mid;
// Update status of mugshot
db_query("UPDATE {mugshot} SET preview = 0 WHERE timestamp = %d", $timestamp);
// Delete old mugshut images
$result = db_query("SELECT mid, path, path_full FROM {mugshot} WHERE preview = 1 AND sid = '%s'", session_id());
$count = 0;
while ($mugshot_elem = db_fetch_object($result)) {
if (file_exists($mugshot_elem->path)) {
file_delete($mugshot_elem->path);
}
if (file_exists($mugshot_elem->path_full)) {
file_delete($mugshot_elem->path_full);
}
$count++;
db_query('DELETE FROM {mugshot} WHERE mid = %d', $mugshot_elem->mid);
}
break;
case 'insert':
case 'update':
break;
case 'load':
$field_name = $field['field_name'];
$items[0] = mugshot_cck_mugshot($items[0]['mid']);
$return = array();
$return[$field_name] = $items;
return $return;
break;
}
}
/** Implementation of hook_field_formatter_info **/
function mugshot_cck_field_formatter_info() {
return array(
'default' => array(
'label' => t('Default Image'),
'field types' => array('mugshot_cck'),
),
);
}
/** Implementation of hook_field_formatter **/
function mugshot_cck_field_formatter($field, $item, $formatter, $node) {
switch ($formatter) {
case 'default':
$mugshot = mugshot_cck_mugshot($item['mid']);
return theme('mugshot_cck', $mugshot);
}
}
/** Widgets **/
/** Implementation of hook_widget_info **/
function mugshot_cck_widget_info() {
return array(
'mugshot_cck_flash' => array(
'label' => t('Mugshot Flash'),
'field types' => array('mugshot_cck',),
),
);
}
function mugshot_cck_widget_settings($op, $widget) {
switch ($op) {
case 'form':
$form = array();
if ($widget['type'] == 'mugshot_cck_flash') {
$form['mugshot_flash_resolution'] = array(
'#type' => 'select',
'#title' => t('Flash module size'),
'#default_value' => $widget['mugshot_flash_resolution'],
'#options' => array(
'320x240' => '320x240',
'512x384' => '512x384',
'640x480' => '640x480',
),
'#description' => t("Flash module size"),
'#required' => TRUE
);
$form['mugshot_flash_jpeg_quality'] = array(
'#type' => 'select',
'#title' => t('Flash JPEG quality'),
'#default_value' => $widget['mugshot_flash_jpeg_quality'],
'#options' => array(
'10' => t('Ugly'),
'25' => t('Low'),
'50' => t('Average'),
'75' => t('Normal'),
'100' => t('Best'),
),
'#description' => t("Flash JPEG quality"),
'#required' => TRUE
);
$form['mugshot_flash_sound'] = array(
'#type' => 'checkbox',
'#title' => t("Activate the trigger sound's"),
'#default_value' => $widget['mugshot_flash_sound'],
'#description' => t("Activate the trigger sound's"),
'#return_value' => 1,
'#required' => FALSE
);
$form['mugshot_flash_gooeffect'] = array(
'#type' => 'checkbox',
'#title' => t("Activate Goo effect"),
'#default_value' => $widget['mugshot_flash_gooeffect'],
'#description' => t("Activate Goo effect"),
'#return_value' => 1,
'#required' => FALSE
);
}
return $form;
case 'validate':
break;
case 'save':
return array('mugshot_flash_resolution', 'mugshot_flash_jpeg_quality', 'mugshot_flash_sound', 'mugshot_flash_gooeffect');
break;
}
}
/** Implementation of hook_widget **/
function mugshot_cck_widget($op, &$node, $field, &$node_field) {
switch ($op) {
case 'form':
$form = array();
$form[$field['field_name']] = array('#tree' => TRUE);
$form[$field['field_name']]['mugshot'] = array(
'#type' => 'item',
'#value' => mugshot_cck_display($field),
);
return $form;
default:
break;
}
}
/** Grabs recent mugshot for this session and timestamp **/
function mugshot_cck_recent_mugshot($timestamp) {
return db_fetch_object(db_query("SELECT * FROM {mugshot} WHERE sid = '%s' AND timestamp = %d", session_id(), $timestamp));
}
function theme_mugshot_cck($mugshot, $thumb = false) {
global $user;
if (file_exists($mugshot['path_full'])) {
//$content = 'hdf';
$info = image_get_info($mugshot['path_full']);
$content .= '';
}
return $content;
}
/** Loads given mugshot from the database, couldn't find this function in mugshot.module, strange... **/
function mugshot_cck_mugshot($mid) {
return db_fetch_array(db_query("SELECT * FROM {mugshot} WHERE mid = %d", $mid));
}
function mugshot_cck_display($field) {
global $user;
if (!file_check_directory(file_create_path(mugshot_storage_directory()), FILE_CREATE_DIRECTORY)) {
drupal_set_message('The mugshot directory does not exist, or is not writable.', 'error');
}
drupal_add_js(drupal_get_path('module', 'mugshot') .'/swfobject.js');
drupal_add_js(drupal_get_path('module', 'mugshot') .'/mugshot.js');
drupal_add_css(drupal_get_path('module', 'mugshot') .'/mugshot.css');
if ($user->uid!=0) {
$username = $user->name;
}
$mugshot_flash_sound = $field['widget']['mugshot_flash_sound'] ? "true" : "false";
$mugshot_flash_gooeffect = $field['widget']['mugshot_flash_gooeffect'] ? "true" : "false";
$mugshot_flash_jpeg_quality = $field['widget']['mugshot_flash_jpeg_quality'];
list($flash_width, $flash_height) = explode('x', $field['widget']['mugshot_flash_resolution']);
$output .= "
"; $output .= t('Guide : '); if ($mugshot_flash_gooeffect=='true') { $output .= t('You can distort your mugshot with the Goo effect by clicking and moving the mouse on the screen. '); $output .= t('Click on the \'reset\' button to cancel the Goo effect. '); } $output .= t('Click on the \'capture\' button to make a preview. The last preview will be submitted when you click the submit button below. '); $output .= "
"; $url_add = url('mugshot/shot/cck_callback', NULL, NULL, TRUE); $preview_param = 'true'; $url = url('', NULL, NULL, TRUE).drupal_get_path('module', 'mugshot').'/mugshot2.swf?build=3'; $js_callback = 'mugshotTake'; $_SESSION['mugshot_token'] = md5(rand()); $flashvars = '&post_url='.urlencode($url_add).'&sound='.urlencode($mugshot_flash_sound).'&preview='.urlencode($preview_param).'&username='.urlencode($username).'&goo_enable='.urlencode($mugshot_flash_gooeffect).'&jpeg_quality='.urlencode($mugshot_flash_jpeg_quality).'&js_callback='.urlencode($js_callback); $output .= "