Pages: 4/34 First page Previous page 1 2 3 4 5 6 7 8 9 10 Next page Final page [ View by Articles | List ]
drupal7用户头像上传的代码,可以作为上传图片或者附件,使用文件字段的参考。

function user_account_form(&$form, &$form_state) {
  global $user;

$form['picture']['picture_upload'] = array(
    '#type' => 'file',
    '#title' => t('Upload picture'),
    '#size' => 48,
    '#description' => t('Your virtual face or picture. Pictures larger than @dimensions pixels will be scaled down.', array('@dimensions' => variable_get('user_picture_dimensions', '85x85'))) . ' ' . filter_xss_admin(variable_get('user_picture_guidelines', '')),
  );
  $form['#validate'][] = 'user_validate_picture';
   return $form;
}

function user_validate_picture(&$form, &$form_state) {
  // If required, validate the uploaded picture.
  $validators = array(
    'file_validate_is_image' => array(),
    'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')),
    'file_validate_size' => array(variable_get('user_picture_file_size', '30') * 1024),
  );

  // Save the file as a temporary file.
  $file = file_save_upload('picture_upload', $validators);
  if ($file === FALSE) {
    form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist or is not writable.", array('%directory' => variable_get('user_picture_path', 'pictures'))));
  }
  elseif ($file !== NULL) {
    $form_state['values']['picture_upload'] = $file;
  }
}


和file文件相关的api:
http://api.drupal.org/api/drupal/includes%21file.inc/group/file/7
Tags:

获取菜单 不指定

drupal水滴 , 2012/09/29 07:06 , drupal建站 » drupal7教程 , Comments(0) , Reads(2264)
menu.module   menu_get_menus($all = TRUE)

如果为真返回包含系统菜单在内的所有菜单,否则返回客户定义菜单


function menu_get_menus($all = TRUE) {
  if ($custom_menus = menu_load_all()) {
    if (!$all) {
      $custom_menus = array_diff_key($custom_menus, menu_list_system_menus());
    }
    foreach ($custom_menus as $menu_name => $menu) {
      $custom_menus[$menu_name] = t($menu['title']);
    }
    asort($custom_menus);
  }
  return $custom_menus;
}


http://api.drupal.org/api/drupal/modules!menu!menu.module/function/menu_get_menus/7
Tags:

系统菜单区块 不指定

drupal水滴 , 2012/09/29 07:04 , drupal建站 » drupal7教程 , Comments(0) , Reads(2169)
system.module   system_block_view($delta = '')

系统菜单区块


function system_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'main':
      $block['subject'] = NULL;
      $block['content'] = drupal_set_page_content();
      return $block;
    case 'powered-by':
      $block['subject'] = NULL;
      $block['content'] = theme('system_powered_by');
      return $block;
    case 'help':
      $block['subject'] = NULL;
      $block['content'] = menu_get_active_help();
      return $block;
    default:
      // All system menu blocks.
      $system_menus = menu_list_system_menus(); //--系统区块
      if (isset($system_menus[$delta])) {
        $block['subject'] = t($system_menus[$delta]);
        $block['content'] = menu_tree($delta);
        return $block;
      }
      break;
  }
}
Tags:
控制私有文件的下载和指定http headers


function hook_file_download($uri) {
  // Check if the file is controlled by the current module.
  if (!file_prepare_directory($uri)) {
    $uri = FALSE;
  }
  if (strpos(file_uri_target($uri), variable_get('user_picture_path', 'pictures') . '/picture-') === 0) {
    if (!user_access('access user profiles')) {
      // Access to the file is denied.
      return -1;
    }
    else {
      $info = image_get_info($uri);
      return array('Content-Type' => $info['mime_type']);
    }
  }
}


http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_file_download/7
Tags:
drupal附件显示表格theme
位置:file.field.inc


/**
* Returns HTML for a file attachments table.
*
* @param $variables
*   An associative array containing:
*   - items: An array of file attachments.
*
* @ingroup themeable
*/
function theme_file_formatter_table($variables) {
  $header = array(t('Attachment'), t('Size'));
  $rows = array();
  foreach ($variables['items'] as $delta => $item) {
    $rows[] = array(
      theme('file_link', array('file' => (object) $item)),
      format_size($item['filesize']),
    );
  }

  return empty($rows) ? '' : theme('table', array('header' => $header, 'rows' => $rows));
}
Tags:
Pages: 4/34 First page Previous page 1 2 3 4 5 6 7 8 9 10 Next page Final page [ View by Articles | List ]