<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 431,  comments - 344,  trackbacks - 0
    1.         sites/all/modules下面創建一個annotate文件夾

    2.         創建annotate module的信息文件(annotate.info)

    ; $Id: annotate.info v 1.1.2.3 2007/06/18 23:06:32 dww Exp $

    name = Annotate

    description = Allows users to annotate nodes.

    package = Example

    version = 5.5

    //dependencies = node blog

    project = "annotate"

    datestamp = "1193367002"

    3.         創建annotate module的實際的module功能文件(annotate.module),所以的功能都在此文件中定義.

    <?php

    // $Id$

    /**

    * @file

    * Lets users add private annotations to nodes.

    *

    * Adds a text field when a node is displayed

    * so that authenticated users may make notes.

    */

    4.         這時候到Administer? Site building? Modules中就可以看到剛才添加的annotate模組.但這時候激活它在導航欄里面是看不到annotate設置菜單的.

    5.         實現Hook(鉤子),添加一下代碼,重新激活annotate模組,這樣就可以看到在Administer? Site configuration下多了一個Annotation settings菜單

    /**

    * Implementation of hook_menu().

    */

    function annotate_menu($may_cache) {

        $items = array();

        if ($may_cache) {

                  $items[] = array(

                  'path' => 'admin/settings/annotate',

                  'title' => t('Annotation settings'),

                  'description' => t('Change how annotations behave.'),

                  'callback' => 'drupal_get_form',

                  'callback arguments' => array('annotate_admin_settings'),

                  'access' => user_access('administer site configuration')

                  );

           }

           return $items;

    }

    6.         上面有行'callback' => 'drupal_get_form'代碼,還有一行 'callback arguments' => array('annotate_admin_settings'). 這里當用戶通過http://www.example.com/?q=admin/settings/annotate訪問的時候,將會調用drupal_get_form()函數,并且通過它的form ID annotate_admin_settings來調用annotate_admin_settings()函數.所以我們要自己定義這個方法.

    /**

    * Define the settings form.

    */

    function annotate_admin_settings() {

           $form['annotate_nodetypes'] = array(

                  '#type' => 'checkboxes',

                  '#title' => t('Users may annotate these node types'),

                  '#options' => node_get_types('names'), //返回所有node類型組成的數組

                  '#default_value' => variable_get('annotate_nodetypes', array('story')),

                  '#description' => t('A text field will be available on these node types to make

                  user-specific notes.'),

           );

           $form['array_filter'] = array('#type' => 'hidden');

           return system_settings_form($form);

    }

    7.         實現hook_nodeapi(),Drupalnode做各種各樣的操作的時候對調用此函數.

    /**

    * Implementation of hook_nodeapi().

    */

    function annotate_nodeapi(&$node, $op, $teaser, $page) {

           switch ($op) {

                  case 'view':

                         global $user;

                         // If only the node summary is being displayed, or if the

                         // user is an anonymous user (not logged in), abort.

                         if ($teaser || $user->uid == 0) {

                                break;

                         }

                         $types_to_annotate = variable_get('annotate_nodetypes', array('story'));

                         if (!in_array($node->type, $types_to_annotate)) {

                                break;

                         }

                         // Add our form as a content item.

                         $node->content['annotation_form'] = array(

                                '#value' => drupal_get_form('annotate_entry_form', $node),

                                '#weight' => 10

                         );

           }

    }

    8.         下面我們要定義annotate form,作為頁面現實內容

    /**

    * Define the form for entering an annotation.

    */

    function annotate_entry_form($node) {

           $form['annotate'] = array(

                  '#type' => 'fieldset',

                  '#title' => t('Annotations')

           );

           $form['annotate']['nid'] = array(

                  '#type' => 'value',

                  '#value' => $node->nid

        );

           $form['annotate']['note'] = array(

                  '#type' => 'textarea',

                  '#title' => t('Node'),

                  '#default_value' => $node->annotation,

                  '#description' => t('Make your personal annotations about this content

    here. Only you (and the site administrator) will be able to see them.')

           );

           $form['annotate']['submit'] = array(

                  '#type' => 'submit',

                  '#value' => t('Update')

           );

           return $form;

    }

    9.         到目前為止對于annotate的內容我們還有做處理.從這里開始,我們就要把annotate的數據存儲到數據庫里面,很多module里面都有.install文件,該文件就是創建數據庫表文件.我們要創建一個annotate.install文件

    <?php

    // $Id$

    function annotate_install() {

           drupal_set_message(t('Beginning installation of annotate module.'));

           switch ($GLOBALS['db_type']) {

                  case 'mysql':

                  case 'mysqli':

                         db_query("CREATE TABLE annotations (

                                uid int NOT NULL default 0,

                                nid int NOT NULL default 0,

                                note longtext NOT NULL,

                                timestamp int NOT NULL default 0,

                                PRIMARY KEY (uid, nid)

                                ) /*!40100 DEFAULT CHARACTER SET utf8 */;"

                         );

                         $success = TRUE;

                         break;

                  case 'pgsql':

                         db_query("CREATE TABLE annotations (

                                uid int NOT NULL DEFAULT 0,

                                nid int NOT NULL DEFAULT 0,

                                note text NOT NULL,

                                timestamp int NOT NULL DEFAULT 0,

                                PRIMARY KEY (uid, nid)

                                );"

                         );

                         $success = TRUE;

                         break;

                  default:

                         drupal_set_message(t('Unsupported database.'));

           }

           if ($success) {

                  drupal_set_message(t('The module installed tables successfully.'));

           } else {

                  drupal_set_message(t('The installation of the annotate module was unsuccessful.'),'error');

           }

    }

    10.     這里要到數據庫system表里把annotate給刪了,然后重新激活annotate模組.添加提交事件.

    /*

    * Save the annotation to the database.

    */

    function annotate_entry_form_submit($form_id, $form_values) {

           global $user;

           $nid = $form_values['nid'];

           $note = $form_values['note'];

           db_query("DELETE FROM {annotations} WHERE uid = %d and nid = %d", $user->uid, $nid);

           db_query("INSERT INTO {annotations} (uid, nid, note, timestamp) VALUES (%d, %d, '%s', %d)", $user->uid, $nid, $note, time());

           drupal_set_message(t('Your annotation was saved.'));

    }

    11.     為了實現在現實annotate的時候讀取數據庫里面的數據現實,這里要修改一下前面的hook_nodeapi函數.修改以后的為:

    /**

    * Implementation of hook_nodeapi().

    */

    function annotate_nodeapi(&$node, $op, $teaser, $page) {

           switch ($op) {

                  case 'view':

                         global $user;

                         // If only the node summary is being displayed, or if the

                         // user is an anonymous user (not logged in), abort.

                         if ($teaser || $user->uid == 0) {

                                break;

                         }

                         $types_to_annotate = variable_get('annotate_nodetypes', array('story'));

                         if (!in_array($node->type, $types_to_annotate)) {

                                break;

                         }

                         // Get previously saved note, if any.

                         $result = db_query("SELECT note FROM {annotations} WHERE uid = %d AND nid = %d", $user->uid, $node->nid);

                         $node->annotation = db_result($result);

                         // Add our form as a content item.

                         $node->content['annotation_form'] = array(

                                '#value' => drupal_get_form('annotate_entry_form', $node),

                                '#weight' => 10

                         );

           }

    }

    這樣在重新激活使用一下就可以了!

    posted on 2007-11-29 15:41 周銳 閱讀(325) 評論(0)  編輯  收藏 所屬分類: PHP
    主站蜘蛛池模板: 免费黄网在线观看| 亚洲高清最新av网站| 亚洲AV综合色区无码一二三区| 大胆亚洲人体视频| 俄罗斯极品美女毛片免费播放| a级黄色毛片免费播放视频| 亚洲国产成人手机在线电影bd| 免费a级毛片永久免费| 免费在线观看一级片| 亚洲中文字幕无码爆乳app| MM131亚洲国产美女久久| 亚洲免费在线视频播放| 粉色视频在线观看www免费| 亚洲成人动漫在线| 日本xxwwxxww在线视频免费| A级毛片高清免费视频在线播放| 亚洲欧美第一成人网站7777| 亚洲va久久久噜噜噜久久天堂 | 少妇太爽了在线观看免费视频| 亚洲日本国产综合高清| 国产亚洲av人片在线观看| 欧洲乱码伦视频免费| 久久久精品国产亚洲成人满18免费网站 | 无码人妻久久一区二区三区免费丨| 日日狠狠久久偷偷色综合免费| 亚洲永久中文字幕在线| 亚洲色偷偷综合亚洲AV伊人| 国拍在线精品视频免费观看| 你是我的城池营垒免费看| WWW国产亚洲精品久久麻豆| 久久亚洲AV成人无码电影| 亚洲精品乱码久久久久久不卡| 成视频年人黄网站免费视频| 中文字幕无码免费久久9一区9 | 看亚洲a级一级毛片| 亚洲第一页在线观看| 亚洲精品午夜国产VA久久成人| 蜜臀91精品国产免费观看| 最近中文字幕2019高清免费| 久久久久久久国产免费看 | gogo免费在线观看|