You are here

function itweak_upload_nodeapi in iTweak Upload 6.2

Implementation of hook_nodeapi().

File

./itweak_upload.module, line 1055
iTweakUpload - Tweak attachments display and file upload forms.

Code

function itweak_upload_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'alter':
      if (isset($node->itu_files)) {

        // Restore files from private property, so other modules can have access to the list
        $node->files = $node->itu_files;
        unset($node->itu_files);
      }
      break;
    case 'view':
      $files_display = $teaser ? variable_get('itweak_upload_teaser_display_' . $node->type, 0) : variable_get('itweak_upload_node_display_' . $node->type, 1);
      if ($files_display && !empty($node->files) && user_access('view uploaded files')) {
        $group = $node->nid;
        $setting_name = $teaser ? 'teaser' : 'node';
        $teaser_images_max = variable_get('itweak_upload_teaser_images_' . $node->type, 0);
        if ($teaser_images_max === '') {
          $teaser_images_max = -1;
        }
        $cnt_other = _itweak_upload_preprocess_files($node->files, $thumbnails, $files_display, $setting_name, $node->type, $group);

        // Add regular attachment list
        if ($cnt_other) {
          if ($files_display != 4) {
            $node->content['files'] = array(
              '#value' => theme('itweak_upload_upload_attachments', $node->files),
              '#weight' => 50,
            );
          }
        }
        else {
          unset($node->content['files']);
        }

        // Preserve files in private property (this prevents upload.module from showing the files)
        $node->itu_files = $node->files;

        // Clear files list so other modules will not try to display it
        $node->files = array();
        if (count($thumbnails)) {
          $options = array(
            'gallery_type' => _itweak_upload_get_setting('gallery_type', $setting_name, $node->type, _itweak_upload_gallery_type_default()),
          );
          if ($teaser) {
            $node->content['itweak_upload'] = array(
              '#value' => theme('itweak_upload_images_teaser', $thumbnails, $teaser_images_max, $options),
              '#weight' => 49,
            );
          }
          else {
            $node->content['itweak_upload'] = array(
              '#value' => theme('itweak_upload_images_body', $thumbnails, -1, $options),
              '#weight' => 49,
            );
          }
        }
      }
      if ($files_display && !empty($node->files) && !user_access('view uploaded files')) {
        $node->content['itweak_upload'] = array(
          '#value' => theme('view_uploaded_files_forbidden', $node),
          '#weight' => 49,
        );
      }
      break;
    case 'delete':
      _itweak_upload_delete($node);
      break;
  }
}