Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1308596
  • 博文数量: 273
  • 博客积分: 5865
  • 博客等级: 准将
  • 技术积分: 3280
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-11 10:01
文章分类

全部博文(273)

文章存档

2015年(33)

2014年(11)

2013年(11)

2012年(136)

2011年(32)

2010年(50)

分类: Android平台

2015-01-04 23:00:17


点击(此处)折叠或打开

  1. <?php
  2. /**
  3.  * Implements hook_help.
  4.  *
  5.  * Displays help and module information.
  6.  *
  7.  * @param path
  8.  * Which path of the site we're using to display help
  9.  * @param arg
  10.  * Array that holds the current path as returned from arg() function
  11.  */


  12. function current_posts_help($path,$arg){
  13.     switch ($path) {
  14.         case 'admin/help#current_posts':
  15.             return '

    ' . t("Display links on today") . '

    '
    ;
  16.         case 'admin/config/adminstration/current_posts':
  17.             return '

    ' . t("testsaaaaaaa") . '

    ';

  18.             #break;
  19.     }
  20. }

  21. /**
  22.  * Implements hook_block_info().
  23.  */

  24. function current_posts_block_info(){
  25.     $blocks['current_posts'] = array(
  26.             'info' => t("current posts"),
  27.             'cache' => DRUPAL_CACHE_PRE_ROLE,
  28.             );
  29.     return $blocks;

  30. }


  31. /**
  32.  * Implements hook_block_view().
  33.  *
  34.  * Prepares the contents of the block.
  35.  */
  36. function current_posts_block_view($delta = '') {
  37.   switch($delta){
  38.     case 'current_posts':
  39.       $block['subject'] = t('Current posts');
  40.       if(user_access('access content')){
  41.         //Use our custom function to retrieve data.
  42.         $result = array(1,2,3,4);
  43.         #$result = current_posts_contents();
  44.         //Array to contain items for the block to render.
  45.         $items = array();
  46.         //Iterate over the resultset and format as links.
  47.         foreach ($result as $node){
  48.           $items[] = array(
  49.             'data' => l($node->title, 'node/' . $node->nid),
  50.           );
  51.         }
  52.       
  53.         if (empty($items)) { //No content in the last week.
  54.           $block['content'] = t('No posts available.');
  55.         }
  56.         else {
  57.           //Pass data through theme function.
  58.           $block['content'] = theme('item_list', array(
  59.             'items' => $items));
  60.         }
  61.       }
  62.   }
  63.   return $block;
  64. }


  65. /**
  66. * Implements hook_menu().
  67. */
  68. function current_posts_menu() {
  69.   $items = array();

  70.   $items['admin/config/content/current_posts'] = array(
  71.     'title' => 'Current posts',
  72.     'description' => 'Configuration for Current posts module',
  73.     'page callback' => 'drupal_get_form',
  74.     'page arguments' => array('current_posts_form'),
  75.     'access arguments' => array('access administration pages'),
  76.     'type' => MENU_NORMAL_ITEM,
  77.   );
  78.  $items['current_posts'] = array(
  79.     'title' => 'Current posts',
  80.     'page callback' => '_current_posts_page',
  81.     'access arguments' => array('access current_posts content'),
  82.     'type' => MENU_NORMAL_ITEM, //Will appear in Navigation menu.
  83.   );
  84.   return $items;
  85. }

  86. /**
  87.  * Page callback: Current posts settings
  88.  *
  89.  * @see current_posts_menu()
  90.  */
  91. function current_posts_form($form, &$form_state) {
  92.   $form['current_posts_max'] = array(
  93.     '#type' => 'textfield',
  94.     '#title' => t('Maximum number of posts'),
  95.     '#default_value' => variable_get('current_posts_max', 3),
  96.     '#size' => 2,
  97.     '#maxlength' => 2,
  98.     '#description' => t('The maximum number of links to display in the block.'),
  99.     '#required' => TRUE,
  100.   );

  101.   return system_settings_form($form);
  102. }

  103. /**
  104. * Implements validation from the Form API.
  105. *
  106. * @param $form
  107. * A structured array containing the elements and properties of the form.
  108. * @param $form_state
  109. * An array that stores information about the form's current state
  110. * during processing.
  111. */
  112. function current_posts_form_validate($form, &$form_state){
  113.   $max_num = $form_state['values']['current_posts_max'];
  114.   if (!ctype_digit($max_num)){
  115.     form_set_error('current_posts_max', t('You must enter a number for the maximum number of posts to display.'));
  116.   }
  117. }




  118. /**
  119. * Implements hook_permission().
  120. */
  121. function current_posts_permission(){
  122.   return array(
  123.     'access current_posts content' => array(
  124.       'title' => t('Access content for the Current posts module'),
  125.     )
  126.   );
  127. }



  128. ?>

阅读(1360) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~