You are here

function upload_menu in Drupal 5

Same name and namespace in other branches
  1. 4 modules/upload.module \upload_menu()
  2. 6 modules/upload/upload.module \upload_menu()

Implementation of hook_menu().

File

modules/upload/upload.module, line 61
File-handling and attaching files to nodes.

Code

function upload_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'upload/js',
      'callback' => 'upload_js',
      'access' => user_access('upload files'),
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/settings/uploads',
      'title' => t('File uploads'),
      'description' => t('Control how files may be attached to content.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'upload_admin_settings',
      ),
      'access' => user_access('administer site configuration'),
      'type' => MENU_NORMAL_ITEM,
    );
  }
  else {

    // Add handlers for previewing new uploads.
    if (isset($_SESSION['file_previews'])) {
      foreach ($_SESSION['file_previews'] as $fid => $file) {
        $filename = file_create_filename($file->filename, file_create_path());
        if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE) {

          // strip file_directory_path() from filename. @see file_create_url
          if (strpos($filename, file_directory_path()) !== FALSE) {
            $filename = trim(substr($filename, strlen(file_directory_path())), '\\/');
          }
          $filename = 'system/files/' . $filename;
        }
        $items[] = array(
          'path' => $filename,
          'title' => t('File download'),
          'callback' => 'upload_download',
          'access' => user_access('view uploaded files'),
          'type' => MENU_CALLBACK,
        );
        $_SESSION['file_previews'][$fid]->_filename = $filename;
      }
    }
  }
  return $items;
}