<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| 亚洲AV日韩精品久久久久久| 亚洲国产精品一区二区久| 亚洲精品V天堂中文字幕| 特级做a爰片毛片免费看| 大地影院MV在线观看视频免费| 99久久99久久精品免费观看| 免费看美女裸露无档网站| 日本免费电影一区| 在线亚洲精品福利网址导航| 亚洲最大的成网4438| 亚洲午夜无码久久| 国产大片免费天天看| 精品国产污污免费网站aⅴ| 免费看美女让人桶尿口| 亚洲情侣偷拍精品| 亚洲成a人片7777| 免费人成视频在线观看免费| 国产精品免费无遮挡无码永久视频 | 国产精品无码亚洲精品2021 | 99久久免费中文字幕精品| 国产香蕉九九久久精品免费| 免费在线观看中文字幕| 亚洲精品福利视频| 久久水蜜桃亚洲AV无码精品| a毛看片免费观看视频| 男人的好看免费观看在线视频| 亚洲成av人片不卡无码久久| 久久久久亚洲AV无码专区首| 亚洲精品无码不卡在线播放| 99视频免费在线观看| 国产精品视频免费一区二区| 国产成人综合亚洲AV第一页| 久久精品国产亚洲αv忘忧草| selaoban在线视频免费精品| 免费看国产成年无码AV片| 亚洲精品无码永久中文字幕| 亚洲人成网站999久久久综合|