cfdisk 分区

cfdis /dev/sdb 分第二个区
第一个分区分完成后必须write
最后退出。

格式化分区

mkfs.ext3 /dev/sdb1  格式化第分区
mkswap  /dev/sdb2    格式化成swap分区

最后编辑 /etc/fstab

修改Drupal 分页显示方式

像这样的显示结果,不过你要翻译文字和写CSS样式。这里只是文字的拼接.
pager

/**
 * Override theme_pager().
 */
function MYTHEME_pager($variables) {
   /**
    * @param $pager_total_items 总条数.
    * @param $pager_total 总页数.
    * @param $pager_limits 每页多少条.
    * @param $pager_page_array 当前多少页.
    */	
   global $pager_page_array, $pager_total, $pager_total_items, $pager_limits;	
   $pager_old = theme_pager($variables);	
   $element = $variables['element'];
   $page_first = t('@pager_total_items Result(s), @pager_limits Item(s) Per Page , Current Page @current_page/@pager_total Page(s)', array(	
   '@pager_total_items' => (int) $pager_total_items[$element],	
   '@pager_limits' => (int) $pager_limits[$element],	
   '@current_page' => (int) $pager_page_array[$element] + 1,	
   '@pager_total' => (int) $pager_total[$element]
   ));
   return "
{$page_first}
{$pager_old}
"; }

/**
 * Override theme_pager().
 */
function MYTHEME_pager($variables) {
  $tags = $variables['tags'];
  $element = $variables['element'];
  $parameters = $variables['parameters'];
  $quantity = $variables['quantity'];
  global $pager_page_array, $pager_total;

  // Calculate various markers within this pager piece:
  // Middle is used to "center" pages around the current page.
  $pager_middle = ceil($quantity / 2);
  // current is the page we are currently paged to
  $pager_current = $pager_page_array[$element] + 1;
  // first is the first page listed by this pager piece (re quantity)
  $pager_first = $pager_current - $pager_middle + 1;
  // last is the last page listed by this pager piece (re quantity)
  $pager_last = $pager_current + $quantity - $pager_middle;
  // max is the maximum page number
  $pager_max = $pager_total[$element];
  // End of marker calculations.

  // Prepare for generation loop.
  $i = $pager_first;
  if ($pager_last > $pager_max) {
    // Adjust "center" if at end of query.
    $i = $i + ($pager_max - $pager_last);
    $pager_last = $pager_max;
  }
  if ($i <= 0) {
    // Adjust "center" if at start of query.
    $pager_last = $pager_last + (1 - $i);
    $i = 1;
  }

  $li_previous = theme('pager_previous', array(
    'text'       => (isset($tags[1]) ? $tags[1] : t('‹')),
    'element'    => $element,
    'interval'   => 1,
    'parameters' => $parameters,
  ));
  $li_next = theme('pager_next', array(
    'text'       => (isset($tags[3]) ? $tags[3] : t('›')),
    'element'    => $element,
    'interval'   => 1,
    'parameters' => $parameters,
  ));

  if ($pager_total[$element] > 1) {
    if ($li_previous) {
      $items[] = array(
        'class' => array('pager-previous'),
        'data'  => $li_previous,
      );
    }

    // When there is more than one page, create the pager list.
    if ($i != $pager_max) {
      if ($i > 1) {
        $items[] = array(
          'class' => array('pager-item'),
          'data'  => theme('pager_first', array(
            'text'       => (isset($tags[0]) ? $tags[0] : 1),
            'element'    => $element,
            'parameters' => $parameters,
          )),
        );
        $items[] = array(
          'class' => array('pager-ellipsis'),
          'data'  => '…',
        );
      }
      // Now generate the actual pager piece.
      for (; $i <= $pager_last && $i <= $pager_max; $i++) {
        if ($i < $pager_current) {
          $items[] = array(
            'class' => array('pager-item'),
            'data'  => theme('pager_previous', array(
              'text'       => $i,
              'element'    => $element,
              'interval'   => ($pager_current - $i),
              'parameters' => $parameters,
            )),
          );
        }
        if ($i == $pager_current) {
          $items[] = array(
            'class' => array('pager-current'),
            'data'  => $i,
          );
        }
        if ($i > $pager_current) {
          $items[] = array(
            'class' => array('pager-item'),
            'data'  => theme('pager_next', array(
              'text'       => $i,
              'element'    => $element,
              'interval'   => ($i - $pager_current),
              'parameters' => $parameters,
            )),
          );
        }
      }
      if ($i < $pager_max) {
        $items[] = array(
          'class' => array('pager-ellipsis'),
          'data'  => '…',
        );

        $items[] = array(
          'class' => array('pager-last'),
          'data'  => theme('pager_last', array(
            'text'       => (isset($tags[4]) ? $tags[4] : $pager_max),
            'element'    => $element,
            'parameters' => $parameters,
          )),
        );
      }
    }

    // End generation.
    if ($li_next) {
      $items[] = array(
        'class' => array('pager-next'),
        'data'  => $li_next,
      );
    }

    return '

' . t('Pages') . '

' . theme('item_list', array( 'items' => $items, 'attributes' => array('class' => array('pager')), )); }; }

Drupal Views 多个分页. top/button

比如现在我需要在页面顶部和底部分别会有一个分页的链接, 采用模板覆盖的方法.
查看更多的模板覆盖规则: https://drupal.org/node/173880

复制views目录下面的模块文件 site/all/modules/views/theme/views-view.tpl 到我自己的模板的templates目录:
site/default/themes/mytheme/templates/views-view.tpl现在的模板文件是针对所有的Views, 我们需要改成只针对某一个Views
比如我的Views名叫products, 显示名为page_1,views机器名字可以根据编辑views时候的url来看,比如我当前页面是:

admin/structure/views/view/products/edit/page_1

那么我的Views ID就是: products, page_1则是当前Views中的display_id. 只针对某个Views 页面的命名应该是

views-view--VIEWS_DI--DISPLAY_ID.tpl.php

所以我们的目录就应该是, 这样就坐覆盖原来的模块。

site/default/themes/mytheme/templates/views-view--products--page_1.tpl.php

如果没有display_ID.则是针对当前这个Views的所有页面和区块模板覆盖.

views-view--VIEWS_DI.tpl.php
site/default/themes/mytheme/templates/views-view--products.tpl.php

最后修改模板文件来满足多个分页, 以下代码就是分页的代码。你接着就可以随意复制贴粘:


    

Drupal 多站点配置

IBM文档: http://www.ibm.com/developerworks/cn/web/wa-multisitedrupal/
查看官方的多站点目录配置: https://drupal.org/node/53705
多站点不显示图片解决方案: https://drupal.org/node/1321066

我们目标是将三个已经存在的网站合并成一个。分别连接三个不同的数据库.只是使用同相同的代码。
1. 先创建三个目录

 sites/host1.com/  //这里没有www., 只是域名
 sites/host2.com/
 sites/host3.com/

再将 /sites/default/settings.php 分别放到刚刚创建的三个目录里面. 而且这一步是必须的。如果系统没有检测到settings.php也就不会执行多网站的安装。就算你在这些目录下面放一个default.settings.php也是不可以的。所以settings.php是必须的

最后的结构就是:

 sites/host1.com/settings.php
 sites/host2.com/settings.php
 sites/host3.com/settings.php

2. 我们以前的网站都是用过的,所以自然就会有files目录。但是我们想将这些files都分开。按照官方的文档是这样的

 sites/host1.com/files
 sites/host2.com/files
 sites/host3.com/files

这样自然没有错。但是我们以前的files目录都是写在数据库里面写死的 sites/default/files, 这个可以查看数据库 -> files表 -> filepath所以我们以前的图片自然就不会显示出来了,如果用.htaccess 来进行重写又会对服务器有很大的压力。如果是.htaccess应该是这样的

RewriteRule ^/sites/default/files/(.*) /sites/%{HTTP_HOST}/files/$1 [L]

后来我们选择了替换数据库的方法。而不使用.htaccess重写.分别要对三个网站的数据库进行操作

#host1 database
update `files` set filepath = replace(filepath,'sites/default/files','sites/host1.com/files');

#host2 database
update `files` set filepath = replace(filepath,'sites/default/files','sites/host2.com/files');

#host3 database
update `files` set filepath = replace(filepath,'sites/default/files','sites/host3.com/files');

最后别忘记设置分别到 /en/admin/config/media/file-system 设置上传文件路径。因为以后我们还会上传新的文件。

sites/host1.com/files

Drupal commerce当用户更新购物车,更新Coupon code

Module: commerce, commerce coupon, commerce order
when update cart, update coupon code
Action:

After adding a product to the cart
After removing a product from the cart
After updating an existing commerce order

Rules code:

{ "rules_coupon_cart_update_basic_coupon" : {
    "LABEL" : "Coupon Cart: Update Basic Coupon",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "Commerce Coupon" ],
    "REQUIRES" : [ "commerce_cart", "rules", "commerce_coupon", "entity" ],
    "ON" : [
      "commerce_cart_product_add",
      "commerce_cart_product_remove",
      "commerce_order_update"
    ],
    "IF" : [
      { "commerce_order_is_cart" : { "commerce_order" : [ "commerce-order" ] } },
      { "entity_has_field" : {
          "entity" : [ "commerce-order" ],
          "field" : "commerce_coupon_order_reference"
        }
      },
      { "OR" : [
          { "data_is" : { "data" : [ "commerce-order:state" ], "value" : "cart" } },
          { "data_is" : { "data" : [ "commerce-order:state" ], "value" : "checkout" } }
        ]
      },
      { "NOT data_is_empty" : { "data" : [ "commerce-order:commerce-coupon-order-reference" ] } }
    ],
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "commerce-order:commerce-coupon-order-reference" ] },
          "ITEM" : { "coupon_list_item" : "Current list item" },
          "DO" : [
            { "commerce_coupon_action_is_valid_coupon" : { "override" : 0 } },
            { "update_cart_update_basic_coupon_price" : {
                "commerce_order" : [ "commerce-order" ],
                "commerce_coupon" : [ "coupon-list-item" ]
              }
            }
          ]
        }
      }
    ]
  }
}

go to my.module file and difine hook rules_action_info().

/**
 * Implements hook_rules_action_info().
 */
function Mymodule_rules_action_info() {
  $actions['update_cart_update_basic_coupon_price'] = array(
    'label' => t('Update cart Update Basic Coupon price.'),
    'parameter' => array(
      'commerce_order' => array(
        'type' => 'commerce_order',
        'label' => t('Commerce Order'),
      ),
      'commerce_coupon' => array(
        'type' => 'commerce_coupon',
        'label' => t('Commerce Coupon'),
      ),
    ),
    'group' => t('Commerce Coupon'),
  );
}


function remove_a_coupon($order, $coupon) {
  module_load_include('rules.inc', 'commerce_coupon');
  commerce_coupon_action_remove_coupon_from_order($order, $coupon);
}

function update_cart_update_basic_coupon_price($commerce_order, $commerce_coupon) {
  static $is_execute = FALSE;

  if ($is_execute == TRUE)
    return;

  $is_execute = TRUE;

  if (empty($commerce_order->original->commerce_coupon_order_reference))
    return false;

  // remove coupon.
  remove_a_coupon($commerce_order, $commerce_coupon);

  $commerce_order = commerce_order_load($commerce_order->order_id);
  // apply coupon. get coupon applay code form and set coupon code and submit this form.
  $commerce_coupon_entity = (entity_metadata_wrapper('commerce_coupon', $commerce_coupon));
  $commerce_coupon_code = $commerce_coupon_entity->commerce_coupon_code->value();
  include_once drupal_get_path('module', 'commerce_coupon') . '/includes/commerce_coupon.checkout_pane.inc';
  $form_state = array();
  $form = drupal_get_form('commerce_coupon_pane_checkout_form', $form_state);
  $form_state['values']['commerce_coupon']['coupon_code'] = $commerce_coupon_code;
  
  // validate coupon code. this will execute all rules event: Validate basic coupon.
  commerce_coupon_pane_checkout_form_validate($form, $form_state, 'checkout', $commerce_order);
  commerce_coupon_pane_checkout_form_submit($form, $form_state, 'checkout', $commerce_order);
}

Drupal 重新应用Coupon code

  $commerce_order = commerce_order_load(1);
  $commerce_coupon = commerce_coupon_load(1);

 // remove 移除一个coupon
 module_load_include('rules.inc', 'commerce_coupon');
 commerce_coupon_action_remove_coupon_from_order($commerce_order, $commerce_coupon);


  // 重新应用.
  // apply coupon.
  $commerce_coupon_entity = (entity_metadata_wrapper('commerce_coupon', $commerce_coupon));
  //  这里主要是获取Coupon code. 当然你可以写死。比如  $commerce_coupon_code = "test1"; ??
  $commerce_coupon_code = $commerce_coupon_entity->commerce_coupon_code->value();

  // start apply
  include_once drupal_get_path('module', 'commerce_coupon_extra') . '/includes/commerce_coupon.checkout_pane.inc';
  $form_state = array();
  $form = drupal_get_form('commerce_coupon_pane_checkout_form', $form_state);
  $form_state['values']['commerce_coupon']['coupon_code'] = $commerce_coupon_code;
  
  // 验证Coupon. 这里会执行rules
  commerce_coupon_pane_checkout_form_validate($form, $form_state, 'checkout', $commerce_order);
  commerce_coupon_pane_checkout_form_submit($form, $form_state, 'checkout', $commerce_order);

Drupal Ajax常用函数

https://api.drupal.org/api/drupal/includes%21ajax.inc/group/ajax_commands/7

比如:

$commands = array();
ajax_command_prepend('.view-content', 'test');
return array('#type' => 'ajax', '#commands' => $commands);

Drupal 获取Node 表单

比如我的内容类型是: square

global $user;

// 创建参数.
$node = (object) array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => 'square', 'language' => LANGUAGE_NONE);
$form_state['build_info']['args'] = array($node);
form_load_include($form_state, 'inc', 'node', 'node.pages');
drupal_build_form('square_node_form', $form_state);


Drupal 模块开发必备函数

1. module_load_all_includes
include 所有模块下面的my.inc文件.

module_load_all_includes('my.inc')

2. module_load_include 获取指定模块下面的一个文件.

module_load_include('admin.inc', 'search_api');

3.module_invoke_all
执行所有的myhook, 并把返回值给$result

$result = module_invoke_all('myhook')