Presentation is loading. Please wait.

Presentation is loading. Please wait.

SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,

Similar presentations


Presentation on theme: "SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,"— Presentation transcript:

1 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25, 2007 Professor Paul Resnick (with help from Michael Hess, as usual)

2 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Today’s Learning Objectives n At the end of this week, students should be able to: –Debug minor installation and upgrade problems –Explain the major differences between Drupal 4.7 and 5.0 –Explore the code behind a contributed module –Create small custom modules

3 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal 4.7 Installation n If you don’t have an auto-installer (e.g., fantastico)… n Download and extract the tar.gz file –Place in a web-accessible folder on your server E.g., htdocs n Edit sites/default/settings.php file –Directions in the comments in this file –location of your database –$base_url path n Import the database –Get directions from your ISP –E.g., mysql dbname –u dbuser –ppassword < drupaldb_file

4 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal 5.0 Installation n If you don’t have an auto-installer (e.g., fantastico)… n Download and extract the tar.gz file –Place in a web-accessible folder on your server E.g., htdocs n Change perms on /sites/default/settings.php to 666 –Owner, group, and other all read/write privileges n Access your Drupal install via web and follow the directions

5 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Upgrading 4.7 to 5 n See Lullabot screencastscreencast n Note: you can’t do this on cms.si.umich –We have a multi-site installation

6 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal Security n If you’re the site maintainer… –Join the security mailing list Login to drupal.org My account >> my newsletters –When you get a security alert for a module you’re using Upgrade as soon as you can –When you get a security alert for Drupal core Follow the suggested action ASAP n Do NOT install modules not found on Drupal.org –No security alerting system

7 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal 5.0 Preview n Key changes –Installation is easier –Administration interface changes –Themes New: Garland Some color changes without changing code –CCK is part of core –Installation Profiles n See Lullabot screencastscreencast

8 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Some PHP Basics n Semi-colon at end of statements n { } enclose collection of statements n Variables n If-statements n Functions n Arrays n For loops

9 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu PHP Variables n Variables begin with $ n Set using = $x = 23; n Local unless you specify global global $user;

10 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu PHP If/Else and Switch/Case if ($op == "list") { stm1; stm2; … } else { } switch ($section) { case “a”: stmt; break; case “b”: stmt; }

11 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu PHP Function Definition function onthisdate_help($section='') { $output = ''; switch ($section) { case "admin/modules#description": $output = t("Displays links to nodes created on this date"); break; } return $output; } // function onthisdate_help

12 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu PHP Arrays n Example: an array whose first/only item is an array $items = array(); $items[] = array('path' => 'onthisdate', 'title' => t('on this date'), 'callback' => 'onthisdate_all', 'access' => user_access('access content'), 'type' => MENU_CALLBACK);

13 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu PHP Foreach Loops

14 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Extensibility Concepts: Defining Add- ons n Adding new names –Only problem is name collisions Variables in programs– local and global XML markup tags– XML Namespaces n Defining meaning of named items –Set variable values –Define functions

15 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Extensibility Concepts: Integrating Add-ons n Hooks/callbacks –Base calls the add-on n Function libraries –Add-on calls the base

16 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu What Programmers Need to Know About Callbacks n How to register the callback so it will be invoked n When the callback will be invoked n Parameters passed and returned

17 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal Callbacks (Hooks) n Registering a hook –Define a function with the right name _hookname –No separate registration process; will automatically be invoked n When hook will be invoked –Check documentation; look at source code n Parameters passed and returned –api.drupal.org

18 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal Naming Conventions n One big namespace n Don’t define a module that has same name as any other module n All functions in module begin with prefix – _ For functions that may be invoked from other files –_ _ For private functions

19 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu What Programmers Need to Know About Library Functions n Parameters passed and returned –See api.drupal.org n Any side effects of the function –E.g., saving a node in the database

20 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Some Useful Hooks n Documentation Documentation n hook_access n hook_block n hook_cron n hook_menu n hook_settings (4.7; use hook_menu in 5.0) n hook_nodeapi

21 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Cron.php n When cron.php is executed –Executes the cron hooks for all contributed modules n Set up a UNIX cron job to cause cron.php to be executed periodically –Done for you on cms.si Once per hour n Poormanscron module if you can’t run a cron job on your installation –Checks on each user access whether it’s time to run cron.php

22 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Some Useful Drupal library functions n Documentation at http://api.drupal.org/ n Theme related –l(), t() n Node functions Node functions –node_load(), node_save() n Database functions Database functions –Db_query() et al n Forms API Forms API n Access control –User_access()

23 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal Licensing n Drupal Core is Distributed under GPL –You can modify and redistribute it –You can’t prevent others from doing so –You don’t have to distribute your modifications n If you distribute modifications, must be under GPL –Wiggle room about whether a consultant who gives the module only to a client who paid for its production is distributing it Consult an attorney

24 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Module Development n Tutorial OnThisDate –http://drupal.org/node/22801http://drupal.org/node/22801 n A Sign-me-up custom feature for AARecon

25 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Devel Module n Menu block –Clear the cache –View variable values n PHP block to execute some code n Display SQL queries used in building a page n Object structure display for current node

26 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu OnThisDate Tutorial n http://drupal.org/node/22801 http://drupal.org/node/22801 n Final version of 4.7 code (rename it to OnThisDate.module) Final version of 4.7 code

27 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Making module information visible n hook_help

28 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Permission Actions n hook_perm

29 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Create Block(s) in a Module n hook_block –List op –View op

30 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Create Module Settings n hook_settings –Add a new variable that can be set through administer >> settings >> this_module

31 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Create a Page n Define a function that outputs a page n Give it a URL path and/or add it to a menu

32 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu SignMeUp Custom Module n Adds a link to sign up as the closer n For production we’ll do better –A custom field type using CCK’s API Copy and edit userreference –Button in each of the fields where user can sign up Access controls; don’t allow double sign-up, etc. –Display sign-ups with photos

33 SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Exercises n Which hook would you use? n Write or modify a module


Download ppt "SCHOOL OF INFORMATION UNIVERSITY OF MICHIGAN si.umich.edu Drupal: Configuration and Customization Week 4: Installation, Module Development January 25,"

Similar presentations


Ads by Google