Drupal 表单,Form

http://api.drupal.org/api/drupal/includes%21form.inc/group/form_api/7

http://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7

Form最基本的函数是drual_get_form, 一切都是这里开始的

drupal_get_form();

这里要特别记录一下一个属性:states中invisible
他的作用就是判断这个此表单在什么时候隐藏:
以下案例就是当name为demos_select选择时。当值为none时,此表单为隐藏状态

$form['demos'] = array(
  '#type' => 'checkboxes',
  '#title' => t('demos from:'),
  '#options' => array('1'),
  '#states' => array(
    // Hide the modes when the content type value is .
    'invisible' => array(
     'select[name="demos_select"]' => array('value' => 'none'),
    ),
  ),
);

如果想要把此表单当成是variable保存到variable表。可以直接使用下面最简单的方法

return system_settings_form($form);

Drupal node_type

node_type_get_names() #获取node type names,只有name,返回一个数组
node_type_get_types() #获取所有的node type 每个type是一个对象
_node_types_build()     #返回两个对象 names和types. 内容相当于上面两个数组

Sublime 安装与配置

GIT插件安装:
https://github.com/kemayo/sublime-text-2-git/wiki

 

Drupal 插件安装:
https://github.com/robballou/drupal-sublimetext

 

package_control安装:
http://wbond.net/sublime_packages/package_control
https://github.com/wbond/sublime_package_control
http://wbond.net/sublime_packages/package_control/installation

 

快捷键操作:
http://docs.sublimetext.info/en/latest/reference/keyboard_shortcuts_win.html
CTRL+G 行跳转
ctrl+shift+p 调用命令
ctrl + ; 文件搜索
ctrl+D
ctrl+U 返回
ctrl+X 删除一行

 

sublime 配置:

https://github.com/andres-torres-marroquin/my-sublime-config

 

语言错误检测工具:

https://github.com/SublimeLinter/SublimeLinter

 

Indent Guides缩进提示插件

Drupal taxonomy 函数指南

http://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/7

常用函数:

taxonomy_get_tree('vid','tid');  #如果tid不存在是获取整个vid的全部term.如果tid存在就只获取指定tid下面的全部term
taxonomy_get_term_by_name('term_name') #用name获取指定term的信息
taxonomy_term_load('tid')                   #用tid获取指定term信息
taxonomy_get_children('tid')                 #获取当前分类下面的所有子trem,不包括自己
taxonomy_get_vocabularies();               #获取所有的分类

Hook_menu_local_tasks_alter

过滤你的tab,当你是node并且你没有field_product_wine字段,而且你的tab的path为node/%/product 就删除这个tab

http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu_local_tasks_alter/7

http://drupalcontrib.org/api/drupal/drupal%21modules%21system%21system.api.php/function/hook_menu_local_tasks_alter/7

/**
 * Implements Hook_menu_local_tasks_alter
 */
function m1nt_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  if($root_path == 'node/%') {
      $node = array_shift($router_item['page_arguments']);
      if(!isset($node->field_product_wine) && isset($data['tabs'][0]['output'])) {
          foreach($data['tabs'][0]['output'] as $key=>$tab) {
              if(isset($tab['#link']['path']) && $tab['#link']['path'] == 'node/%/product') {
                  unset($data['tabs'][0]['output'][$key]);
              }
          }
      }
  }
}
/**
 * 设置指定的tab到page.
 * Implements hook_menu_local_tasks_alter()
 */
function myuser_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  $user_show_tab = array(
    'user/%/view' => t('My Account'),
    'user/%/addressbook' => t('Address Book'),
    'user/%/edit' => t('Change Password'),
    'user/%/points' => t('My Points'),
    'user/%/orders' => t('My Orders'),
  );

  if (isset($user_show_tab[$router_item['path']])) {
    $count = 0;
    global $user;
    $data['tabs'][0]['output'] = array();
    foreach ($user_tab as $path => $title) {
      $path = str_replace('%', $user->uid, $path);
      $item = menu_get_item($path);
      //$data['tabs'][0]['output'] = array();
      if ($item) {
        $item['title'] = $title;
        $item['localized_options'] = array();
        $data['tabs'][0]['output'][$count]['#theme'] = 'menu_local_task';
        $data['tabs'][0]['output'][$count]['#link'] = $item;
        $count++;
      }
    }
    $data['tabs'][0]['count'] = $count;
  }
}

drupal 创建文章编辑器与代码高亮和图片上传

首先代码高亮模块:syntaxhighlighter

$drush dl syntaxhighlighter

下载syntaxhighlighter 插件
移到sites/all/libraries.而不是sites/all/modules/libraries. 我被这个问题搞得头晕眼花.
最后你的目录结构应该是这样的:
sites/all/libraries/syntaxhighlighter_3.0.83

下载wysiwyg模块

$drush dl wysiwyg
$drush en wysiwyg -y
$drush dl imce && drush en imce -y
$drush dl imce_wysiwyg && drush en imce_wysiwyg -y

下载ckeditor非Drupal版,而且目录只支持3.x版本. 解压到sites/all/libraries

然后设置:
admin/config/content/syntaxhighlighter 设置你要高亮的语言
admin/config/content/wysiwyg 把Full HTML选择成你的编辑器保存后再编辑
展开: SHOWBUTTONS AND PLUGINS 选择你要用的工具。但是至少你要选择Insert syntaxhighlighter tag

VPN更新密码脚本


#!/bin/bash                                                                                                                                                  
printf '' > '/var/www/ssh110.com/data/vpnuser'
printf '' > '/etc/ppp/chap-secrets'
users=('vpn01' 'vpn02' 'vpn03' 'vpn04' 'vpn05' 'vpn06' 'vpn07' 'vpn08' 'vpn09' 'vpn10' 'vpn11' 'vpn12' 'vpn13' 'vpn14' 'vpn15' 'vpn16' 'vpn17' 'vpn18' 'vpn19' 'vpn20')
echo zhouitpro pptpd zhouitpro123 '*' >> '/etc/ppp/chap-secrets'
echo cm pptpd 602000 '*' >> '/etc/ppp/chap-secrets'
echo qcc pptpd qcc123456 '*' >> '/etc/ppp/chap-secrets'
for u in ${users[@]}; do
    pawd=''
    a=('0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'a' 'b' 'c' 'z' 'A' 'B' 'Z')
    for i in {1..10}
    do
        pawd=$pawd${a[$RANDOM % ${#a[*]}]}
    done
    echo $u : $pawd >> '/var/www/ssh110.com/data/vpnuser'
    echo $u 'pptpd' $pawd '*' >> '/etc/ppp/chap-secrets'
done;


SSH更新用户密码 脚本


#!/bin/bash
printf '' > '/var/www/ssh110.com/data/userpasswd'
users=('ssh01' 'ssh02' 'ssh03' 'ssh04' 'ssh05' 'ssh06' 'ssh07' 'ssh08' 'ssh09' 'ssh10' 'ssh11' 'ssh12' 'ssh13' 'ssh14' 'ssh15' 'ssh16' 'ssh17' 'ssh18' 'ssh19' 'ssh20')
for u in ${users[@]}; do
    pawd=''
    a=('0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'a' 'b' 'c' 'z' 'A' 'B' 'Z')
    for i in {1..10}
    do
        pawd=$pawd${a[$RANDOM % ${#a[*]}]}
    done
    echo $u : $pawd >> '/var/www/ssh110.com/data/userpasswd'
    echo $u:$pawd | chpasswd
done;


Drupal Database API

查询的API:

http://api.drupal.org/api/drupal/includes!database!select.inc/class/SelectQuery/7

 
DB类:
http://api.drupal.org/api/drupal/includes!database!database.inc/group/database/7
 

Develop Database API:

http://drupal.org/developing/api/database

 
Schema:
http://drupal.org/node/146843

http://drupal.org/node/150223
Data Type: http://drupal.org/node/159605

API: http://api.drupal.org/api/drupal/includes%21database%21schema.inc/group/schemaapi/7

常用函数:

drupal_write_record('tablename','filed_array', $primary_keys) //添加数据, $primary_keys如果是空表示是添加数据,如果有字段。按字段条件更新数据
drupal_get_schema($table);    //根据表名获取这个表里面的所有字段