| 1 |
<?php |
<?php |
| 2 |
// $Id: node_images.module,v 1.11.2.9 2008/09/08 09:14:00 stefano73 Exp $ |
// $Id: node_images.module,v 1.11.2.10 2008/09/15 11:56:24 stefano73 Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 69 |
*/ |
*/ |
| 70 |
function node_images_form_alter(&$form, $form_state, $form_id) { |
function node_images_form_alter(&$form, $form_state, $form_id) { |
| 71 |
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) { |
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) { |
| 72 |
$type = $form['#node_type']->type; |
$type = $form['#node_type']->type; |
| 73 |
// radio button in the node's content type configuration page |
// radio button in the node's content type configuration page |
| 74 |
_node_images_check_settings(); |
_node_images_check_settings(); |
| 75 |
$form['node_images'] = array( |
$form['node_images'] = array( |
| 127 |
|
|
| 128 |
if (isset($form['type']) && isset($form['#node'])) { |
if (isset($form['type']) && isset($form['#node'])) { |
| 129 |
$node = $form['#node']; |
$node = $form['#node']; |
| 130 |
if (!$node->nid && $form['type']['#value'] .'_node_form' == $form_id && _node_images_access('create', $node)) { |
if (!isset($node->nid) && $form['type']['#value'] .'_node_form' == $form_id && _node_images_access('create', $node)) { |
| 131 |
// Attachments fieldset |
// Attachments fieldset |
| 132 |
$form['node_images'] = array( |
$form['node_images'] = array( |
| 133 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 323 |
************************************************************/ |
************************************************************/ |
| 324 |
|
|
| 325 |
function _node_images_attach_form($form_state, $node) { |
function _node_images_attach_form($form_state, $node) { |
| 326 |
|
global $user; |
| 327 |
|
|
| 328 |
$form = array( |
$form = array( |
| 329 |
'#cache' => TRUE, |
'#cache' => TRUE, |
| 330 |
); |
); |
|
|
|
| 331 |
$form['node_images'] = _node_images_attach_list($node); |
$form['node_images'] = _node_images_attach_list($node); |
| 332 |
|
|
| 333 |
if (_node_images_access('create', $node)) { |
if (_node_images_access('create', $node)) { |
| 362 |
'#tree' => TRUE, |
'#tree' => TRUE, |
| 363 |
); |
); |
| 364 |
|
|
| 365 |
if (is_array($node->node_images) && !empty($node->node_images)) { |
if (!empty($node->node_images) && is_array($node->node_images)) { |
| 366 |
$delta = max(count($node->node_images), 10); |
$delta = max(count($node->node_images), 10); |
| 367 |
foreach ($node->node_images as $key => $file) { |
foreach ($node->node_images as $key => $file) { |
| 368 |
$file = (object)$file; |
$file = (object)$file; |
| 413 |
// Save new file upload. |
// Save new file upload. |
| 414 |
$dest = ($node ? _node_images_get_directory('', $user, $node) : file_directory_path()); |
$dest = ($node ? _node_images_get_directory('', $user, $node) : file_directory_path()); |
| 415 |
if ($file = file_save_upload($source, $validators, $dest)) { |
if ($file = file_save_upload($source, $validators, $dest)) { |
|
// remove uploaded file from the files table, so it won't be deleted by system_cron() |
|
|
db_query('DELETE FROM {files} WHERE fid = %d', $file->fid); |
|
|
|
|
| 416 |
return $file; |
return $file; |
| 417 |
} |
} |
| 418 |
|
|
| 519 |
|
|
| 520 |
// Load the form from the Form API cache. |
// Load the form from the Form API cache. |
| 521 |
$cache = cache_get('form_'. $_POST['form_build_id'], 'cache_form'); |
$cache = cache_get('form_'. $_POST['form_build_id'], 'cache_form'); |
| 522 |
|
$form = $cache->data; |
| 523 |
|
$form_state = array('values' => $_POST); |
| 524 |
|
|
| 525 |
$node = (object)$_POST; |
$node = (object)$_POST; |
| 526 |
$node->type = $cache->data['#node']->type; |
$type = (isset($cache->data['#node'])? $cache->data['#node']->type : NULL); |
|
$node->uid = $user->uid; |
|
| 527 |
|
|
| 528 |
if ($_POST['form_id'] == $node->type.'_node_form') { |
if ($type && $_POST['form_id'] == $type.'_node_form') { |
| 529 |
// upload from node creation page |
// upload from node creation page |
| 530 |
|
|
| 531 |
|
$node->type = $type; |
| 532 |
|
$node->uid = $user->uid; |
| 533 |
|
|
| 534 |
// Handle new uploads, and merge tmp files into node_images. |
// Handle new uploads, and merge tmp files into node_images. |
| 535 |
node_images_node_form_submit($form, $form_state); |
node_images_node_form_submit($form, $form_state); |
| 536 |
if (!empty($form_state['values']['node_images'])) { |
if (!empty($form_state['values']['node_images'])) { |
| 562 |
// upload from node images page |
// upload from node images page |
| 563 |
if ($node = node_load($nid)) { |
if ($node = node_load($nid)) { |
| 564 |
$form = array(); |
$form = array(); |
|
$form_state = array('values' => $_POST); |
|
| 565 |
$file = _node_images_upload_submit($form, $form_state, $node); |
$file = _node_images_upload_submit($form, $form_state, $node); |
| 566 |
$form = _node_images_edit_form($form_state, $node); |
$form = _node_images_edit_form($form_state, $node); |
| 567 |
} |
} |
| 772 |
return (user_access('add node images to any '. $type .' content') || (user_access('add node images to own '. $type .' content') && ($user->uid == $node->uid))); |
return (user_access('add node images to any '. $type .' content') || (user_access('add node images to own '. $type .' content') && ($user->uid == $node->uid))); |
| 773 |
} |
} |
| 774 |
if ($op == 'update') { |
if ($op == 'update') { |
| 775 |
return (user_access('edit any node image') || (user_access('edit own node images') && ($user->uid == $file->uid))); |
return (user_access('edit any node_image') || (user_access('edit own node images') && ($user->uid == $file->uid))); |
| 776 |
} |
} |
| 777 |
if ($op == 'delete') { |
if ($op == 'delete') { |
| 778 |
return (user_access('delete any node image') || (user_access('delete own node images') && ($user->uid == $file->uid))); |
return (user_access('delete any node_image') || (user_access('delete own node images') && ($user->uid == $file->uid))); |
| 779 |
} |
} |
| 780 |
|
|
| 781 |
return FALSE; |
return FALSE; |
| 834 |
|
|
| 835 |
if (!$u) $u = $user; |
if (!$u) $u = $user; |
| 836 |
$variables = array('%uid' => $u->uid, '%username' => $u->name); |
$variables = array('%uid' => $u->uid, '%username' => $u->name); |
| 837 |
$variables['%nid'] = ($node ? $node->nid : 0); |
$variables['%nid'] = (isset($node->nid) ? $node->nid : 0); |
| 838 |
$variables['%type'] = ($node ? $node->type: 'node'); |
$variables['%type'] = ($node ? $node->type: 'node'); |
| 839 |
$path = file_directory_path().'/'; |
$path = file_directory_path().'/'; |
| 840 |
$path .= ($dir ? trim($dir, '/') : variable_get('node_images_path', 'node_images')); |
$path .= ($dir ? trim($dir, '/') : variable_get('node_images_path', 'node_images')); |