| 1 |
<?php |
<?php |
| 2 |
// $Id: audio_images.module,v 1.20 2007/08/21 23:12:53 drewish Exp $ |
// $Id: audio_images.module,v 1.21 2007/08/21 23:17:58 drewish Exp $ |
| 3 |
|
|
| 4 |
include_once drupal_get_path('module', 'audio') .'/audio_image.inc'; |
include_once drupal_get_path('module', 'audio') .'/audio_image.inc'; |
| 5 |
|
|
| 6 |
/** |
/** |
| 7 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 8 |
*/ |
*/ |
| 9 |
function audio_images_menu($may_cache) { |
function audio_images_menu() { |
| 10 |
$items = array(); |
$items = array(); |
| 11 |
if ($may_cache) { |
$items['admin/settings/audio/images'] = array( |
| 12 |
$items[] = array('path' => 'admin/settings/audio/images', |
'title' => 'Images', |
| 13 |
'title' => t('Images'), |
'page callback' => 'drupal_get_form', |
| 14 |
'callback' => 'drupal_get_form', |
'page arguments' => array('audio_images_admin_settings'), |
| 15 |
'callback arguments' => array('audio_images_admin_settings'), |
'access arguments' => array('administer site configuration'), |
| 16 |
'access' => user_access('administer site configuration'), |
'type' => MENU_LOCAL_TASK, |
| 17 |
'type' => MENU_LOCAL_TASK |
); |
|
); |
|
|
} |
|
| 18 |
return $items; |
return $items; |
| 19 |
} |
} |
| 20 |
|
|
| 21 |
/** |
/** |
| 22 |
|
* Implementation of hook_theme |
| 23 |
|
*/ |
| 24 |
|
function audio_images_theme() { |
| 25 |
|
return array( |
| 26 |
|
'audio_images_form' => array( |
| 27 |
|
'arguments' => array('form'), |
| 28 |
|
), |
| 29 |
|
); |
| 30 |
|
} |
| 31 |
|
|
| 32 |
|
/** |
| 33 |
* Implementation of hook_file_download(). |
* Implementation of hook_file_download(). |
| 34 |
*/ |
*/ |
| 35 |
function audio_images_file_download($filename) { |
function audio_images_file_download($filename) { |
| 57 |
* |
* |
| 58 |
* Here we add our image fields to the audio node form. |
* Here we add our image fields to the audio node form. |
| 59 |
*/ |
*/ |
| 60 |
function audio_images_form_alter($form_id, &$form) { |
function audio_images_form_alter(&$form, &$form_state, $form_id) { |
| 61 |
// We only alter audio node edit forms. |
// We only alter audio node edit forms. |
| 62 |
if ($form_id == 'audio_node_form') { |
if ($form_id == 'audio_node_form') { |
| 63 |
$node = $form['#node']; |
$node = $form['#node']; |
| 64 |
|
|
| 65 |
$form['audio_images'] = array( |
$form['audio_images'] = array( |
| 66 |
'#type' => 'fieldset', '#title' => t('Audio Images'), |
'#type' => 'fieldset', '#title' => t('Audio Images'), |
| 67 |
'#collapsible'=> TRUE, |
'#collapsible' => TRUE, |
| 68 |
'#description' => t('Cover art or other images.'), |
'#description' => t('Cover art or other images.'), |
| 69 |
'#weight' => 0, |
'#weight' => 0, |
| 70 |
'#tree' => TRUE, |
'#tree' => TRUE, |
| 135 |
|
|
| 136 |
case 'prepare': |
case 'prepare': |
| 137 |
// Clean out the session the first time the form is viewed. |
// Clean out the session the first time the form is viewed. |
| 138 |
if(count($_POST) == 0) { |
if (count($_POST) == 0) { |
| 139 |
$_SESSION['audio_images'] = $node->audio_images; |
$_SESSION['audio_images'] = $node->audio_images; |
| 140 |
} |
} |
| 141 |
else if (!empty($_SESSION['audio_images'])) { |
else if (!empty($_SESSION['audio_images'])) { |
| 269 |
/** |
/** |
| 270 |
* Save an image to the audio_image table and copies it to the audio/images |
* Save an image to the audio_image table and copies it to the audio/images |
| 271 |
* directory. |
* directory. |
| 272 |
* |
* |
| 273 |
* The caller needs to delete original image file if it was a temporary. |
* The caller needs to delete original image file if it was a temporary. |
| 274 |
*/ |
*/ |
| 275 |
function _audio_images_save_copy(&$node, $image) { |
function _audio_images_save_copy(&$node, $image) { |
| 276 |
$newpath = _audio_image_filename($node->vid, $image['filemime'], $image['pictype'], FALSE); |
$newpath = _audio_image_filename($node->vid, $image['filemime'], $image['pictype'], FALSE); |
| 277 |
if (file_copy($image['filepath'], $newpath, FILE_EXISTS_REPLACE)) { |
if (file_copy($image['filepath'], $newpath, FILE_EXISTS_REPLACE)) { |
| 278 |
$pid = db_next_id('{audio_image}_pid'); |
db_query("INSERT INTO {audio_image} (nid, vid, pictype, filemime, width, height, filepath, filesize) |
| 279 |
db_query("INSERT INTO {audio_image} (pid, nid, vid, pictype, filemime, width, height, filepath, filesize) |
VALUES (%d, %d, %d, '%s', %d, %d, '%s', %d)", |
| 280 |
VALUES (%d, %d, %d, %d, '%s', %d, %d, '%s', %d)", |
$node->nid, $node->vid, $image['pictype'], $image['filemime'], |
|
$pid, $node->nid, $node->vid, $image['pictype'], $image['filemime'], |
|
| 281 |
$image['width'], $image['height'], $newpath, filesize($newpath)); |
$image['width'], $image['height'], $newpath, filesize($newpath)); |
| 282 |
|
|
| 283 |
$image['filepath'] = $newpath; |
$image['filepath'] = $newpath; |
| 284 |
$image['pid'] = $pid; |
$image['pid'] = db_last_insert_id(); |
| 285 |
$node->audio_images[$pid] = $image; |
$node->audio_images[$image['pid']] = $image; |
| 286 |
} |
} |
| 287 |
} |
} |
| 288 |
|
|
| 337 |
|
|
| 338 |
/** |
/** |
| 339 |
* Returns the array of the default image type. |
* Returns the array of the default image type. |
| 340 |
* |
* |
| 341 |
* If no default image is found, returns a random image array. |
* If no default image is found, returns a random image array. |
| 342 |
*/ |
*/ |
| 343 |
function audio_images_get($audio_images, $pictype = NULL) { |
function audio_images_get($audio_images, $pictype = NULL) { |
| 376 |
$alt = audio_image_type_dirty_array($image['pictype']); |
$alt = audio_image_type_dirty_array($image['pictype']); |
| 377 |
|
|
| 378 |
list($width, $height) = @getimagesize($image['filepath']); |
list($width, $height) = @getimagesize($image['filepath']); |
| 379 |
$attributes = array('width' => $width, 'height'=> $height); |
$attributes = array('width' => $width, 'height' => $height); |
| 380 |
|
|
| 381 |
return theme('image', $url, $alt, '', $attributes, FALSE); |
return theme('image', $url, $alt, '', $attributes, FALSE); |
| 382 |
} |
} |