<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
    Creating a Node Module

    1Creating the .info File

    Let’s also create the joke.info file and add it to the joke folder.

    ; $Id$

    name = Joke

    description = Provides a joke node type with a punchline.

    version = "$Name$"

    2Creating the .install File

    <?php

    function joke_install() {

           switch ($GLOBALS['db_type']) {

                  case 'mysql':

                  case 'mysqli':

                         db_query("CREATE TABLE {joke} (

                                nid int unsigned NOT NULL default '0',

                                vid int unsigned NOT NULL default '0',

                                punchline text NOT NULL,

                                PRIMARY KEY (nid,vid),

                                UNIQUE KEY vid (vid),

                                KEY nid (nid)

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

                         break;

                  case 'pgsql':

                         db_query("CREATE TABLE {joke} (

                                nid int unsigned NOT NULL default '0',

                                vid int unsigned NOT NULL default '0',

                                punchline text NOT NULL,

                                PRIMARY KEY (nid,vid),

                                UNIQUE KEY vid (vid),

                                KEY nid (nid)

                         )");

                  break;

           }

    }

    function joke_uninstall() {

           db_query('DROP TABLE {joke}');

    }

    3Creating the .module File

    <?php

    function joke_perm() {

           return array('create joke', 'edit joke', 'delete joke');

    }

    /**

    * @file

    * Provides a "joke" node type.

    */

    /**

    * Implementation of hook_node_info().

    */

    function joke_node_info() {

           // We return an array since a module can define multiple node types.

           // We're only defining one node type, type 'joke'.

           return array(

                  'joke' => array(

                         'name' => t('Joke'), // Required.

                         'module' => 'joke', // Required.

                         'description' => t('Tell us your favorite joke!'), // Required.

                         'has_title' => TRUE,

                         'title_label' => t('Title'),

                         'has_body' => TRUE,

                         'body_label' => t('Joke'),

                         'min_word_count' => 2,

                         'locked' => TRUE

                  )

           );

    }

    function joke_menu($may_cache) {

           $items = array();

           if ($may_cache) {

                  $items[] = array(

                         'path' => 'node/add/joke',

                         'title' => t('Joke'),

                         'access' => user_access('create joke'),

                  );

           }

           return $items;

    }

    function joke_access($op, $node) {

           global $user;

           if ($op == 'create') {

                  return (user_access('create joke'));

           }

           if ($op == 'update') {

                  return (user_access('edit joke') && ($user->uid == $node->uid));

           }

           if ($op == 'delete') {

                  return (user_access('delete joke') && ($user->uid == $node->uid));

           }

    }

    function joke_form($node) {

           // Get metadata for this node type

           // (we use it for labeling title and body fields).

           // We defined this in joke_node_info().

           $type = node_get_types('type', $node);

           $form['title'] = array(

                  '#type' => 'textfield',

                  '#title' => check_plain($type->title_label),

                  '#required' => TRUE,

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

                  '#weight' => -5

           );

           $form['body_filter']['body'] = array(

                  '#type' => 'textarea',

                  '#title' => check_plain($type->body_label),

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

                  '#rows' => 7,

                  '#required' => TRUE

           );

           $form['body_filter']['filter'] = filter_form($node->format);

           $form['punchline'] = array(

                  '#type' => 'textfield',

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

                  '#required' => TRUE,

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

                  '#weight' => 5

           );

           return $form;

    }

    function joke_validate($node) {

           //Enforce a minimum word length of 3.

           if (isset($node->punchline) && str_word_count($node->punchline) <= 3) {

                  $type = node_get_types('type', $node);

                  form_set_error('punchline', t('The punchline of your @type is too short. You need at least three words.', array('@type'=> $type->name)));

           }

    }

    function joke_insert($node) {

           db_query("INSERT INTO {joke} (nid, vid, punchline) VALUES (%d, %d, '%s')",

           $node->nid, $node->vid, $node->punchline);

    }

    function joke_update($node) {

           if ($node->revision) {

                  joke_insert($node);

           } else {

                  db_query("UPDATE {joke} SET punchline = '%s' WHERE vid = %d", $node->punchline, $node->vid);

           }

    }

    /**

    * Implementation of hook_delete().

    */

    function joke_delete(&$node) {

           // Delete the related information we were saving for this node.

           db_query('DELETE FROM {joke} WHERE nid = %d', $node->nid);

    }

    /**

    * Implementation of hook_load().

    */

    function joke_load($node) {

           drupal_add_js('misc/collapse.js');

           return db_fetch_object(db_query('SELECT punchline FROM {joke} WHERE vid = %d', $node->vid));

    }

    function joke_view($node, $teaser = FALSE, $page = FALSE) {

           if (!$teaser) {

                  // Use Drupal's default node view.

                  $node = node_prepare($node, $teaser);

                  $node->guffaw = str_repeat(t('Ha!'), mt_rand(0, 10));

                  // Now add the punchline.

                  /**

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

                         '#value' => theme('joke_punchline', $node),

                         '#weight' => 2

                  );

                  */

           }

           if ($teaser) {

                  // Use Drupal's default node view.

                  $node = node_prepare($node, $teaser);

           }

           return $node;

    }

    function theme_joke_punchline($node) {

           $output = '<div class="joke-punchline">'.check_plain($node->punchline). '</div><br />';

           $output .= '<div class="joke-guffaw">'.check_plain($node->guffaw). '</div>';

           return $output;

    }

    posted on 2007-12-04 09:28 周銳 閱讀(280) 評論(0)  編輯  收藏 所屬分類: PHP
    主站蜘蛛池模板: 成人免费视频一区| 日韩电影免费在线观看中文字幕| 免费福利网站在线观看| 亚洲黄色在线观看视频| 在线观看免费中文视频| 亚洲精品中文字幕无码AV| 亚洲免费在线观看视频| 亚洲国产日韩在线成人蜜芽| 国产精品爱啪在线线免费观看| 亚洲另类精品xxxx人妖| 免费在线观看的网站| 亚洲高清毛片一区二区| 免费国产高清视频| 一级大黄美女免费播放| 亚洲人成图片小说网站| 亚洲国产精品免费视频| 精品日韩99亚洲的在线发布| 最好免费观看韩国+日本 | 美女视频黄免费亚洲| 亚洲一区二区无码偷拍| 国产成人3p视频免费观看| 香蕉视频在线免费看| 亚洲精品不卡视频| 成人免费视频试看120秒| 色妞www精品视频免费看| 国产成人A人亚洲精品无码| 国产国产人免费视频成69堂| 国产精品亚洲专区无码唯爱网| 亚洲国产精品成人一区| 麻豆精品成人免费国产片| 亚洲xxxx18| 亚洲国产一区二区视频网站| 久久福利青草精品资源站免费| 亚洲日韩乱码久久久久久| 波多野结衣免费视频观看| 免费在线看黄网站| 亚洲另类无码专区首页| 亚洲热线99精品视频| 成年性生交大片免费看| 黄桃AV无码免费一区二区三区| 亚洲冬月枫中文字幕在线看|