You are here

function webfm_nodeapi in Web File Manager 5.2

Same name and namespace in other branches
  1. 5 webfm.module \webfm_nodeapi()

Implementation of hook_nodeapi().

File

./webfm.module, line 399

Code

function webfm_nodeapi(&$node, $op, $teaser) {
  switch ($op) {
    case 'load':
      if (variable_get("wfm_attach_{$node->type}", 1) == 1 && user_access('view webfm attachments')) {
        $output['webfm_files'] = webfm_get_attachments($node->nid);
      }
      return $output;
      break;
    case 'view':

      // Add the attachments list to node body if configured to appear in body
      if (is_array($node->webfm_files) && variable_get('webfm_attach_body', '')) {
        if (count($node->webfm_files) && !$teaser) {
          $node->content['webfm_attachments'] = array(
            '#value' => theme('webfm_attachments', $node->webfm_files),
            '#weight' => 10,
          );
          drupal_add_css(drupal_get_path('module', 'webfm') . '/css/webfm.css');
        }
      }
      break;
    case 'insert':
      if ($_POST['attachlist']) {
        $files = explode(',', $_POST['attachlist']);
        $i = 0;
        foreach ($files as $fid) {
          if ($fid) {

            // weight argument determined by position in csv
            webfm_dbinsert_attach($node->nid, $fid, $i++);
          }
        }
      }
      break;
    case 'update':
      $files = explode(',', $_POST['attachlist']);
      webfm_dbupdate_attach($node->nid, $files);
      break;
  }
}