/[drupal]/contributions/modules/node_images/node_images.module
ViewVC logotype

Diff of /contributions/modules/node_images/node_images.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.11.2.10, Mon Sep 15 11:56:24 2008 UTC revision 1.11.2.11, Tue Sep 16 21:12:45 2008 UTC
# Line 1  Line 1 
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
# Line 69  function node_images_menu() { Line 69  function node_images_menu() {
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(
# Line 127  function node_images_form_alter(&$form, Line 127  function node_images_form_alter(&$form,
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',
# Line 323  function node_images_file_download($file Line 323  function node_images_file_download($file
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)) {
# Line 361  function _node_images_attach_list($node) Line 362  function _node_images_attach_list($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;
# Line 412  function _node_images_file_upload($form, Line 413  function _node_images_file_upload($form,
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    
# Line 521  function _node_images_js() { Line 519  function _node_images_js() {
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'])) {
# Line 559  function _node_images_js() { Line 562  function _node_images_js() {
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      }      }
# Line 770  function _node_images_access($op, $node, Line 772  function _node_images_access($op, $node,
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;
# Line 832  function _node_images_get_directory($dir Line 834  function _node_images_get_directory($dir
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'));

Legend:
Removed from v.1.11.2.10  
changed lines
  Added in v.1.11.2.11

  ViewVC Help
Powered by ViewVC 1.1.2