/[drupal]/contributions/modules/node_images/node_images.pages.inc
ViewVC logotype

Diff of /contributions/modules/node_images/node_images.pages.inc

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

revision 1.1.2.5, Mon Nov 3 13:41:25 2008 UTC revision 1.1.2.6, Fri Jan 30 13:21:02 2009 UTC
# Line 49  function _node_images_edit_page(&$form_s Line 49  function _node_images_edit_page(&$form_s
49  function _node_images_edit_form(&$form_state, $node) {  function _node_images_edit_form(&$form_state, $node) {
50    global $user;    global $user;
51    $node_images = node_images_load($node);    $node_images = node_images_load($node);
52      $is_translation_source = _node_images_is_translation_source($node);
53    
54    $form = array(    $form = array(
55      '#cache' => TRUE,      '#cache' => TRUE,
56    );    );
57    
58    if (_node_images_access('create', $node)) {    if (_node_images_access('create', $node) && $is_translation_source) {
59      $form['new'] = array(      $form['new'] = array(
60        '#type' => 'fieldset',        '#type' => 'fieldset',
61        '#title' => t('Upload a new image'),        '#title' => t('Upload a new image'),
# Line 115  function _node_images_edit_form(&$form_s Line 116  function _node_images_edit_form(&$form_s
116      // set an appropriate value for delta in weight selectbox      // set an appropriate value for delta in weight selectbox
117      $delta = db_result(db_query('SELECT MAX(ABS(weight)) FROM {node_images} WHERE nid=%d', $node->nid));      $delta = db_result(db_query('SELECT MAX(ABS(weight)) FROM {node_images} WHERE nid=%d', $node->nid));
118      $delta += count($node_images);      $delta += count($node_images);
   
119      $authors = array();      $authors = array();
120      $submit = FALSE;      $submit = FALSE;
121        $form['node_images']['is_translation_source'] = array('#type' => 'value', '#value' => $is_translation_source);
122    
123      foreach ($node_images as $key => $file) {      foreach ($node_images as $key => $file) {
124        $file = (object)$file;        $file = (object)$file;
125        $update_access = _node_images_access('update', $node, $file);        $update_access = _node_images_access('update', $node, $file);
# Line 128  function _node_images_edit_form(&$form_s Line 129  function _node_images_edit_form(&$form_s
129        if (!isset($authors[$file->uid])) {        if (!isset($authors[$file->uid])) {
130          $authors[$file->uid] = user_load(array('uid' => $file->uid));          $authors[$file->uid] = user_load(array('uid' => $file->uid));
131        }        }
       $author = $authors[$file->uid];  
   
132        $url = file_create_url($file->filepath);        $url = file_create_url($file->filepath);
133        $thumb = file_create_url($file->thumbpath);        $thumb = file_create_url($file->thumbpath);
       $description = file_create_url($file->filepath);  
       $description = "<small>". check_plain($description) ."</small>";  
134        $row = array();        $row = array();
135        $row['id'] = array('#type' => 'value',  '#value' => $file->id);        $row['id'] = array('#type' => 'value',  '#value' => $file->id);
       $row['delete'] = array('#type' => 'checkbox', '#attributes' => ($delete_access ? array() : array('disabled' => 'true')));  
       $row['list'] = array('#type' => 'checkbox', '#default_value' => $file->list, '#attributes' => ($update_access ? array() : array('disabled' => 'true')));  
136        $row['thumbnail'] = array('#value' => '<img src="'.$thumb.'" alt="" />');        $row['thumbnail'] = array('#value' => '<img src="'.$thumb.'" alt="" />');
137        $row['description'] = ($update_access ?  
138          array('#type' => 'textfield', '#default_value' => $file->description, '#maxlength' => 255, '#size' => 40) :        if ($is_translation_source) {
139          array('#value' => $file->description)          $row['delete'] = array('#type' => 'checkbox', '#attributes' => ($delete_access ? array() : array('disabled' => 'true')));
140        );          $row['list'] = array('#type' => 'checkbox', '#default_value' => $file->list,
141              '#attributes' => ($update_access && $is_translation_source ? array() : array('disabled' => 'true')));
142            _node_images_translate($file);
143            $element = array('#type' => 'textfield', '#default_value' => $file->description, '#maxlength' => 255, '#size' => 40);
144          }
145          else {
146            _node_images_translate($file);
147            $element = array('#value' => $file->description);
148          }
149          $row['description'] = $element;
150    
151          $author = $authors[$file->uid];
152        $row['author'] = array('#value' => theme('username', $author));        $row['author'] = array('#value' => theme('username', $author));
153    
154        $row['filepath'] = array('#value' => l($file->filepath, file_create_url($file->filepath), array('attributes' => array('target' => '_blank'))));        $row['filepath'] = array('#value' => l($file->filepath, file_create_url($file->filepath), array('attributes' => array('target' => '_blank'))));
155        $row['filesize'] = array('#value' => format_size($file->filesize));        $row['filesize'] = array('#value' => format_size($file->filesize));
156        $row['date'] = array('#value' => format_date($file->timestamp));        $row['date'] = array('#value' => format_date($file->timestamp));
# Line 151  function _node_images_edit_form(&$form_s Line 158  function _node_images_edit_form(&$form_s
158        $form['node_images']['images'][$key] = $row;        $form['node_images']['images'][$key] = $row;
159      }      }
160    
161      if ($submit) {      if ($submit && $is_translation_source) {
162        $form['node_images']['submit'] = array('#type' => 'submit', '#value' => t('Save changes'), '#submit' => array('_node_images_form_submit'));        $form['node_images']['submit'] = array('#type' => 'submit', '#value' => t('Save changes'), '#submit' => array('_node_images_form_submit'));
163      }      }
164    }    }
# Line 168  function _node_images_edit_form(&$form_s Line 175  function _node_images_edit_form(&$form_s
175   *   An associative array containing the current state of the form.   *   An associative array containing the current state of the form.
176   */   */
177  function _node_images_form_submit($form, &$form_state) {  function _node_images_form_submit($form, &$form_state) {
178    global $user;    global $user, $language;
179    
180    $node = node_load($form_state['values']['nid']);    $node = node_load($form_state['values']['nid']);
181    if (!isset($node->nid)) return drupal_set_message(t('Unable to load node.'), 'error');    if (!isset($node->nid)) return drupal_set_message(t('Unable to load node.'), 'error');
182    
183      // Get languages
184      $current_language = $language->language;
185      $default_language = language_default('language');
186    
187    foreach($form_state['values']['node_images']['images'] as $id => $values) {    foreach($form_state['values']['node_images']['images'] as $id => $values) {
188      $file = db_fetch_object(db_query('SELECT filepath, thumbpath, uid, nid FROM {node_images} WHERE id=%d AND nid=%d',      $file = db_fetch_object(db_query('SELECT id, filepath, thumbpath, uid, nid FROM {node_images} WHERE id=%d AND nid=%d',
189        $id, $node->nid));        $id, $node->nid));
190      if ($values['delete']) {      if ($values['delete']) {
191        // check delete access for the current image        // check delete access for the current image
# Line 185  function _node_images_form_submit($form, Line 196  function _node_images_form_submit($form,
196        file_delete($file->filepath);        file_delete($file->filepath);
197        file_delete($file->thumbpath);        file_delete($file->thumbpath);
198        db_query('DELETE FROM {node_images} WHERE id=%d AND nid=%d', $id, $node->nid);        db_query('DELETE FROM {node_images} WHERE id=%d AND nid=%d', $id, $node->nid);
199          module_invoke('i18nstrings', 'remove_string', _node_images_build_i18nstrings_context($file));
200      }      }
201      else {      else {
202        // check update access for the current image        // check update access for the current image
# Line 194  function _node_images_form_submit($form, Line 206  function _node_images_form_submit($form,
206        $update = array('id', 'nid');        $update = array('id', 'nid');
207        $object = (object)$values;        $object = (object)$values;
208        $object->nid = $node->nid;        $object->nid = $node->nid;
209          _node_images_translate($object, TRUE);
210        drupal_write_record('node_images', $object, $update);        drupal_write_record('node_images', $object, $update);
211      }      }
212    }    }
# Line 206  function _node_images_form_submit($form, Line 219  function _node_images_form_submit($form,
219   * @ingroup themeable   * @ingroup themeable
220   */   */
221  function theme_node_images_form_upload(&$form) {  function theme_node_images_form_upload(&$form) {
222    $output = '<div style="float:left; margin-right:20px;">';    $output = '';
223    $output .= drupal_render($form['description']);    foreach (array('description', 'weight') as $key) {
224    $output .= '</div>';      $output .= '<div style="float:left; margin-right:20px;">';
225    $output .= '<div style="float:left; margin-right:20px;">';      $output .= drupal_render($form[$key]);
226    $output .= drupal_render($form['weight']);      $output .= '</div>';
227    $output .= '</div>';    }
228    $output .= '<div style="float:left;">';    $output .= '<div style="float:left;">';
229    $output .= drupal_render($form['list']);    $output .= drupal_render($form['list']);
230    $output .= '</div>';    $output .= '</div>';
231    
232    $output .= '<div style="clear:both;">';    $output .= '<div style="clear:both;"></div>';
233    $output .= drupal_render($form);    $output .= drupal_render($form);
234    return $output;    return $output;
235  }  }
# Line 227  function theme_node_images_form_upload(& Line 240  function theme_node_images_form_upload(&
240   * @ingroup themeable   * @ingroup themeable
241   */   */
242  function theme_node_images_form_list(&$form) {  function theme_node_images_form_list(&$form) {
243    $header = array('', t('Delete'), t('List'), t('Thumbnail'), t('Description and info'), t('Weight'), t('Size'));    $is_translation_source = $form['is_translation_source']['#value'];
244    
245      $header = array();
246      if ($is_translation_source) {
247        $header = array('', t('Delete'), t('List'));
248      }
249      $header =  array_merge($header, array(t('Thumbnail'), t('Description and info'), t('Weight'), t('Size')));
250    drupal_add_tabledrag('node_images_list', 'order', 'sibling', 'node_images-weight');    drupal_add_tabledrag('node_images_list', 'order', 'sibling', 'node_images-weight');
251    
252    foreach (element_children($form['images']) as $key) {    foreach (element_children($form['images']) as $key) {
# Line 240  function theme_node_images_form_list(&$f Line 259  function theme_node_images_form_list(&$f
259      $info .= '<div class="node_images_info">'.t('Uploaded on: %date', array('%date' => drupal_render($form['images'][$key]['date']))).'</div>';      $info .= '<div class="node_images_info">'.t('Uploaded on: %date', array('%date' => drupal_render($form['images'][$key]['date']))).'</div>';
260      $info .= '<div class="node_images_info">'.t('Path: !path', array('!path' => drupal_render($form['images'][$key]['filepath']))).'</div>';      $info .= '<div class="node_images_info">'.t('Path: !path', array('!path' => drupal_render($form['images'][$key]['filepath']))).'</div>';
261    
262      $row = array('');      $row = array();
263      $row[] = drupal_render($form['images'][$key]['delete']);      if ($is_translation_source) {
264      $row[] = drupal_render($form['images'][$key]['list']);        $row[] = '';
265          $row[] = drupal_render($form['images'][$key]['delete']);
266          $row[] = drupal_render($form['images'][$key]['list']);
267        }
268      $row[] = drupal_render($form['images'][$key]['thumbnail']);      $row[] = drupal_render($form['images'][$key]['thumbnail']);
269      $row[] = array('data' => drupal_render($form['images'][$key]['description']).$info, 'width' => '100%');      $row[] = array('data' => drupal_render($form['images'][$key]['description']).$info, 'width' => '100%');
270      $row[] = drupal_render($form['images'][$key]['weight']);      $row[] = drupal_render($form['images'][$key]['weight']);
271      $row[] = array('data' => drupal_render($form['images'][$key]['filesize']), 'class' => 'nowrap');      $row[] = array('data' => drupal_render($form['images'][$key]['filesize']), 'class' => 'nowrap');
272      $rows[] = array('data' => $row, 'class' => 'draggable');      if ($is_translation_source) {
273          $rows[] = array('data' => $row, 'class' => 'draggable');
274        }
275        else {
276          $rows[] = $row;
277        }
278    }    }
279    
280    $output = '&nbsp;';    $output = '&nbsp;';
281    if (!empty($rows)) $output .= theme('table', $header, $rows, array('id' => 'node_images_list'));    if (!empty($rows)) $output .= theme('table', $header, $rows, array('id' => 'node_images_list'));
282      $output .= drupal_render($form['translation_warning']);
283    $output .= drupal_render($form);    $output .= drupal_render($form);
284    return $output;    return $output;
285  }  }
# Line 275  function _node_images_gallery($node) { Line 303  function _node_images_gallery($node) {
303    
304    $i = 1;    $i = 1;
305    $thumbs = array();    $thumbs = array();
306    foreach ($node->node_images as $id=>$image) {    foreach ($node->node_images as $id => $image) {
307        // i18n support for description
308        if (module_exists('i18nstrings')) {
309          // translate description
310          to('node_images:node_image:'.$image->id.':description', $image, array('description'));
311        }
312    
313      $thumb_path = file_create_url($image->thumbpath);      $thumb_path = file_create_url($image->thumbpath);
314      $thumbs[$i] = array(      $thumbs[$i] = array(
315        'src' => $thumb_path,        'src' => $thumb_path,
# Line 351  function theme_node_images_gallery($elem Line 385  function theme_node_images_gallery($elem
385  function theme_node_images_gallery_thumbs($thumbs, $cols = 2) {  function theme_node_images_gallery_thumbs($thumbs, $cols = 2) {
386    $output = '';    $output = '';
387    foreach($thumbs as $id => $thumb) {    foreach($thumbs as $id => $thumb) {
388        $url = url($_GET['q'], array('query' => 'page='.$id, 'absolute' => TRUE));
389      $description = '<div class="thumb-description">'.truncate_utf8($thumb['title'], 40, FALSE, TRUE).'</div>';      $description = '<div class="thumb-description">'.truncate_utf8($thumb['title'], 40, FALSE, TRUE).'</div>';
390      $output .= '<div class="thumb">'.l('<img src="'.$thumb['src'].'" class="slideshow-thumb" id="thumb-'.$id.'" />', $_GET['q'],      $output .= '<div class="thumb">'.l('<img src="'.$thumb['src'].'" class="slideshow-thumb" id="thumb-'.$id.'" />', $url, array('attributes' => array('title' => $thumb['title']), 'html' => TRUE)).$description.'</div>';
       array('title' => $thumb['title'], 'rel' => 'nofollow', 'html' => TRUE), 'page='.$id, NULL, FALSE, TRUE).$description.'</div>';  
391    }    }
392    return $output;    return $output;
393  }  }

Legend:
Removed from v.1.1.2.5  
changed lines
  Added in v.1.1.2.6

  ViewVC Help
Powered by ViewVC 1.1.2