热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

drupal7节点操作module-PHP源码

drupal7节点操作module

1. [PHP]代码

 'Example node',
    'description' => 'Example of Drupal node',
    'page callback' => 'examplenode_overview',
    'access arguments' => array('access content'),
  );


  return $items;
}

function examplenode_overview() {

//	global $user;
//	$newNode = new stdclass();
//	$newNode->type = 'page';
//	$newNode->uid = $user->uid;
//	$newNode->title = 'New Node';
//	node_save($newNode);

  return 'Example node ';
}

/**
* Implements hook_node_info() to provide our job_post type.
*/
function examplenode_node_info() {
  return array(
    'job_post' => array(
      'name' => t('Job Post'),
      'base' => 'examplenode',
      'description' => t('Use this content type to post a job.'),
      'has_title' => TRUE,
      'title_label' => t('Job Title'),
      'help' => t('Enter the job title, job description, and the name of the company that posted the job'),
    ),
  );
}

/**
* Implements hook_menu_alter().
*/
function examplenode_menu_alter(&$callbacks) {
//  if (!user_access('administer nodes')) {
//    $callbacks['node/add/job_post']['access callback'] = FALSE;
//    // Must unset access arguments or Drupal will use user_access()
//    // as a default access callback.
//    unset($callbacks['node/add/job_post']['access arguments']);
//  }
}

/**
* Implements hook_permission().
*/
function examplenode_permission() {
  return array(
    'create job post' => array(
      'title' => t('Create a job post'),
      'description' => t('Create a job post'),
    ),
    'edit own job post' => array(
      'title' => t('Edit own job post'),
      'description' => t('Edit your own job posting'),
    ),
    'edit any job post' => array(
      'title' => t('Edit any job post'),
      'description' => t('Edit any job posting'),
    ),
    'delete own job post' => array(
      'title' => t('Delete own job post'),
      'description' => t('Delete own job posting'),
    ),
    'delete any job post' => array(
      'title' => t('Delete any job post'),
      'description' => t('Delete any job posting'),
    ),
  );
}

/**
* Implements hook_node_access().
*/
function examplenode_access($op, $node, $account) {
  $is_author = $account->uid == $node->uid;
  switch ($op) {
    case 'create':
      // Allow if user's role has 'create joke' permission.
      if (user_access('create job post', $account)) {
        return NODE_ACCESS_ALLOW;
      }
    case 'update':
      // Allow if user's role has 'edit own joke' permission and user is
      // the author; or if the user's role has 'edit any joke' permission.
      if (user_access('edit own job post', $account) && $is_author || user_access('edit any job post', $account)) {
        return NODE_ACCESS_ALLOW;
      }
    case 'delete':
      // Allow if user's role has 'delete own joke' permission and user is
      // the author; or if the user's role has 'delete any joke' permission.
      if (user_access('delete own job post', $account) && $is_author || user_access('delete any job post', $account)) {
        return NODE_ACCESS_ALLOW;
      }
  }
}

/**
* Implement hook_form() with the standard default form.
*/
function examplenode_form($node, $form_state) {

  return node_content_form($node, $form_state);
}

/**
* Implements hook_validate().
*/
function examplenode_validate($node) {
  // Enforce a minimum character count of 2 on company names.
  if (isset($node->job_post_company) && strlen($node->job_post_company[&#39;und&#39;][0][&#39;value&#39;]) <2) {
    form_set_error(&#39;job_post_company&#39;, t(&#39;The company name is too short. It must be atleast 2characters.&#39;),$limit_validation_errors = NULL);
  }
}

/**
* Implements hook_insert().
*/
function examplenode_insert($node) {
  // log details of the job posting to watchdog
  watchdog(&#39;job post&#39;, &#39;A new job post titled: &#39;.$node->title.&#39; for company: &#39;.$node->job_post_company[&#39;und&#39;][0][&#39;value&#39;].&#39; was added by UID: &#39;.$node->uid, $variables = array(),WATCHDOG_NOTICE, $link = &#39;node/&#39;.$node->nid);
}

/**
* Implements hook_update().
*/
function examplenode_update($node) {
  // log details of the job posting to watchdog
  watchdog(&#39;job post&#39;, &#39;A job post titled: &#39;.$node->title.&#39; for company: &#39;.$node->job_post_company[&#39;und&#39;][0][&#39;value&#39;].&#39; was updated by UID: &#39;.$node->uid, $variables = array(),WATCHDOG_NOTICE, $link = &#39;node/&#39;.$node->nid);
}

/**
* Implements hook_delete().
*/
function examplenode_delete($node) {
  // log details of the job posting to watchdog
  watchdog(&#39;job post&#39;, &#39;A job post titled: &#39;.$node->title.&#39; for company: &#39;.$node->job_post_company[&#39;und&#39;][0][&#39;value&#39;].&#39; was deleted by UID: &#39;.$node->uid, $variables = array(),WATCHDOG_NOTICE, $link = &#39;node/&#39;.$node->nid);
}

/**
* Implements hook_load().
*/
function examplenode_load($nodes) {
  // Add a new element to the node at load time for storing the
  // job posting sponsor information
  foreach ($nodes as $node) {
    $node->spOnsor= "ACME Career Services, Your Source for Drupal Jobs";
  }
  return $node;
}

/**
* Implement hook_view().
*/
function examplenode_view($node, $view_mode) {
  // Add and theme the sponsor so it appears when the job post is displayed
  if ($view_mode == &#39;full&#39;) {
    $node->content[&#39;sponsor&#39;] = array(
      &#39;#markup&#39; => theme(&#39;sponsor&#39;, array(&#39;sponsor&#39; => $node->sponsor, &#39;sponsor_id&#39; => $node->nid)),
      &#39;#weight&#39; => 100,
    );
  }
  return $node;
}

/**
* Implements hook_theme().
*/
function examplenode_theme() {
  // define the variables and template associated with the sponsor field
  // The sponsor will contain the name of the sponsor and the sponsor_id
  // will be used to create a unique CSS ID
  return array(
    &#39;sponsor&#39; => array(
      &#39;variables&#39; => array(&#39;sponsor&#39; => NULL, &#39;sponsor_id&#39; => NULL),
      &#39;template&#39; => &#39;sponsor&#39;,
    ),
  );
}


function examplenode_node_access_records($node) {
	// role id = 5, allow access job post
	// must include strict limit
  if ($node->type == &#39;job_post&#39;) {
    $grants = array();
    $grants[] = array(
      &#39;realm&#39; => &#39;example&#39;,
      &#39;gid&#39; => 5,
      &#39;grant_view&#39; => 1,
      &#39;grant_update&#39; => 0,
      &#39;grant_delete&#39; => 0,
      &#39;priority&#39; => 0,
    );

    return $grants;
  }
}

function examplenode_node_grants($account, $op) {
	if($op == &#39;view&#39;) {
		$roles = $account->roles;
		foreach($roles AS $key => $value ){
			$rid[] = $key;
		}
	  $grants[&#39;example&#39;] = $rid;
	  return $grants;
	}
}

推荐阅读
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文讲述了作者通过点火测试男友的性格和承受能力,以考验婚姻问题。作者故意不安慰男友并再次点火,观察他的反应。这个行为是善意的玩人,旨在了解男友的性格和避免婚姻问题。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • Voicewo在线语音识别转换jQuery插件的特点和示例
    本文介绍了一款名为Voicewo的在线语音识别转换jQuery插件,该插件具有快速、架构、风格、扩展和兼容等特点,适合在互联网应用中使用。同时还提供了一个快速示例供开发人员参考。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
author-avatar
雨润风华_684
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有