Notes On Drupal ~
===================================================================
Reference Links ~
===================================================================
Drupal Documentation: http://drupal.org/getting-started/before/overview
Email Config with PHP to use gmail for outbound e-mails:
http://www.okadadesign.no/blog/web-development/sending-email-from-localhost-using-msmtp-with-gmail/
Drupal Modules: http://drupal.org/project/Modules
Jquery UI : http://jqueryui.com/demos
Drupal Videos by bestrank :
http://www.youtube.com/watch?v=CH23k4dYd5A&feature=channel (Drupal 6 Intro)
http://www.youtube.com/watch?v=_0wMHzanYX4 (Ubercart Intro)
http://www.youtube.com/watch?v=Cbgo5C8zQT8&feature=relmfu (Drupal 6.x Theme)
Drupal Videos by GraffitiPROD :
Drupal for Beginners: How to create buttons for your menu bar
http://www.youtube.com/watch?v=Muulpt-2Ob8&feature=channel
Drupal for Beginners: Intro + how to use blocks:
http://www.youtube.com/watch?v=TYHVHsMeCpo&feature=channel
Drupal Distributions:
http://drupal.org/project/distributions
===================================================================
Drupal Concepts ~
Drupal Installation ~
Features Overview ~
E-mail Configuration ~
How to Backup & Restore drupal configuration ~
How to prepare to generate clean URLs ~
Ubercart Intro ~
Fckeditor Install ~
Drupal Javascript Settings ~
Drupal Database Access ~
Drupal Debugging ~
Drupal Node Vs Page ~
What are the differences between Node and Page ? ~
What is really node ? ~
Drupal Important Modules ~
Drupal WebForm Module ~
Drupal Data Module ~
Drupal Theme, Block Internals ~
Drupal Role check ~
Drupal Sessions ~
Anonymous Sessions Performance ~
Drupal Theming ~
Add Custom Regions ~
Add Custom Blocks ~
Hiding Login ~
Create Primary Links ~
How to create a new Page ? ~
What is Drupal Views ? ~
Drupal Distributions ~
===================================================================
Drupal Concepts ~
===================================================================
People often think of a website as a collection of static pages, with some
functions (like a blog, or a news engine) thrown in to round it out. When they
go to manage their site, they are thinking in terms of a tree-like hierarchy
of pages that they will go in and edit.
Drupal, on the other hand, treats most content types as variations on the same
concept: a node (more on this in a moment). Static pages, blog posts, and news
items (some possible node types) are all stored in the same way, and the
site's navigation structure is designed separately by editing menus, views
(lists of content), and blocks (side content which often have links to
different site sections).
Drupal is designed from the ground up so site builders can delegate content
creation, and even site administration, to users. All you have to do is define
who gets to do what on your site (through user permissions), and then you can
start collaborating.
Theme-Templates
Permissions
Blocks and Menus
Modules
Nodes (page data, etc)
1. |Nodes|
At the base of the system is the collection of nodes the data pool. Before
anything can be displayed on the site, it must be input as data.
2. |Modules|
The next layer up is where modules live. Modules are functional plugins.
Modules allow you to customize the data items (fields) on your node types;
set up e-commerce; programmatically sorting and display of content
(custom output controlled by filters you define); and more.
3. |Blocks-and-Menus|
Blocks often provide the output from a module or can be created to display
whatever you want, and then can be placed in various spots in your template
(theme) layout. Blocks can be configured to output in various ways,
as well as only showing on certain defined pages, or only for certain defined users.
4. |user-permissions|
Permissions are defined for various roles.
5. |Theme-Templates|
On the top layer is the site theme (the "skin"). This is made up
predominantly of XHTML and CSS, with some PHP variables intermixed, so
Drupal-generated content can go in the appropriate spots. Also included with
each theme is a set of functions that can be used to override standard
functions in the modules in order to provide complete control over how the
modules generate their markup at output time. Templates can also be assigned
on-the-fly based on user permissions.
===================================================================
Drupal Installation ~
===================================================================
See http://drupal.org/documentation/install/developers
The /var/www/drupal/6/ has been configured:
- Created drupal6 database in MySQL.
- Updated sites/default/settings.php file :
- MySQL url specified
- Following is the default contents, but worth noting:
ini_set('session.use_only_cookies', 1);
ini_set('session.use_trans_sid', 0);
ini_set('url_rewriter.tags', '');
- (cd sites/default; cp default.settings.php settings.php)
- chmod 666 settings.php ; so that web server can update it.
- mysqladmin -u root -p create drupal6
- Create new mysql user, if needed.
Invoke installation script as follows :
- http://localhost/drupal/install.php
- Enabled write perm on sites/default sites/default/files dir.
- Prompts for drupal admin user name/password: thava/1drupal
thava/nithya
- Now it has created 47 tables in drupal6 database. It is all set now.
- http://localhost/drupal/ is my site and it is all ready now!
- It has following Links :
My account - http://localhost/drupal/?q=user/1
Create content - http://localhost/drupal/?q=node/add
Administer - http://localhost/drupal/?q=admin
Log out - http://localhost/drupal/?q=logout
Note: To enable PHP code in your pages, version 6, you should do:
Enable the PHP Filter core module. ^
In drupal 5: Admin > Site Config > Input Formats: add PHP Input type.
Automating the above steps:
cd /tmp/tmp
wget http://drupal.org/files/projects/drupal-x.x.tar.gz
tar -zxvf drupal-x.x.tar.gz
mv drupal-x.x /var/www
drush site-install standard
--db-url=mysql://[db_user]:[db_pass]@localhost/[db_name]
--site-name=Example
--account-name=admin (or thava or whatever) --account-pass=password
It will create the database if the db_user above has the privileges to.
Installing Distributions:
- Install Corp, commons distributions (developed by Acquia)
- mysqladmin create corp (create a new db)
- Just invoke install.php (give connection username/pwd to create tables)
- Admin username/password is not set after install complete. You should do:
./scripts/password-hash.sh nithya (new password)
(hash value)
echo "update users set pass='hash-val' name='thava' where uid=1;" | mysql
- drush upwd username --password="new_password" (not tested)
===================================================================
Features Overview ~
===================================================================
Create Content ~
===================================================================
Page ~
A page, that rarely changes, By default, a page entry does
not allow visitor comments and is not featured on the site's
initial home page.
Story ~
A story, similar in form to a page, is ideal for creating and displaying
content that informs or engages website visitors. Press releases, site
announcements, and informal blog-like entries may all be created with a story
entry. By default, a story entry is automatically featured on the site's
initial home page, and provides the ability to post comments.
Administer By Task ~
===================================================================
You have following options to administer:
Content management ~
Comments ~
List and edit site comments and the comment moderation queue.
Content ~
View, edit, and delete your site's content.
Content types ~
Manage posts by content type, including default status, front page promotion, etc.
Post settings ~
Control posting behavior, such as teaser length, requiring previews before
posting, and the number of posts on the front page.
RSS publishing ~
Configure the number of items per feed and whether feeds should be
titles/teasers/full-text.
Taxonomy ~
Manage tagging, categorization, and classification of your content.
User management ~
===================================================================
Manage your site's users, groups and access to site features.
Access rules ~
List and create rules to disallow usernames, e-mail addresses, and IP addresses.
Permissions ~
Determine access to features by selecting permissions for roles.
Roles ~
List, edit, or add user roles.
User settings ~
Configure default behavior of users, including registration requirements,
e-mails, and user pictures.
Users ~
List, add, and edit users.
Reports ~
===================================================================
View reports from system logs and other status information.
Recent log entries ~
View events that have recently been logged.
Top 'access denied' errors ~
View 'access denied' errors (403s).
Top 'page not found' errors ~
View 'page not found' errors (404s).
Available updates ~
Get a status report about available updates for your installed modules and themes.
Status report ~
Get a status report about your site's operation and any detected problems.
Site building ~
===================================================================
Control how your site looks and feels.
Blocks ~
Configure what block content appears in your site's sidebars and other regions.
Menus ~
Control your site's navigation menu, primary links and secondary links,
as well as rename and reorganize menu items.
Modules ~
Enable or disable add-on modules for your site.
Themes ~
Change which theme your site uses or allows users to set.
Site configuration ~
===================================================================
Adjust basic site configuration options.
Actions ~
Manage the actions defined for your site.
Administration theme ~
Settings for how your administrative pages should look.
Clean URLs ~
Enable or disable clean URLs for your site.
Date and time ~
Settings for how Drupal displays date and time, as well as the system's
default timezone.
Error reporting ~
Control how Drupal deals with errors including 403/404 errors as well
as PHP error reporting.
File system ~
Tell Drupal where to store uploaded files and how they are accessed.
Image toolkit ~
Choose which image toolkit to use if you have installed optional toolkits.
Input formats ~
Configure how content input by users is filtered, including allowed HTML
tags. Also allows enabling of module-provided filters.
Logging and alerts ~
Settings for logging and alerts modules. Various modules can route Drupal's
system events to different destination, such as syslog, database, email, ...etc.
Performance ~
Enable or disable page caching for anonymous users and set CSS and JS
bandwidth optimization options.
Site information ~
Change basic site information, such as the site name, slogan, e-mail address,
mission, front page and more.
Site maintenance ~
Take the site off-line for maintenance or bring it back online.
===================================================================
Administer By Module ~
===================================================================
You have following modules :
Block: Controls the boxes that are displayed around the main content.
Configure permissions; Blocks; Get help
Database logging: Logs and records system events to the database.
Database logging; Recent log entries; Top 'access denied' errors;
Top 'page not found' errors; Get help
Menu: Allows administrators to customize the site navigation menu.
Configure permissions; Menus; Get help
System: Handles general site configuration for administrators.
Configure permissions; Actions; Administration theme; Clean URLs;
Date and time; Error reporting; File system; Image toolkit;
Logging and alerts; Modules; Performance; RSS publishing;
Site information; Site maintenance; Status report; Themes;
Get help;
Update status: Checks the status of available updates for Drupal
and your installed modules and themes.
Available updates; Get help;
Comment: Allows users to comment on and discuss published content.
Configure permissions; Comments; Get help;
Filter: Handles the filtering of content in preparation for display.
Configure permissions; Input formats; Get help
Node: Allows content to be submitted to the site and displayed on pages.
Configure permissions; Content types; Content; Post settings; Get help
Taxonomy: Enables the categorization of content.
Configure permissions; Taxonomy; Get help
User: Manages the user registration and login system.
Configure permissions; Access rules; Permissions; Roles
User settings; Users; Get help
===================================================================
E-mail Configuration ~
===================================================================
See http://www.okadadesign.no/blog/web-development/sending-email-from-localhost-using-msmtp-with-gmail/
Install msmtp and ca-certificates for use with SSL:
sudo apt-get install msmtp ca-certificates
sudo gedit /etc/msmtprc
Add the followings to this file.
defaults
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
account default
host smtp.gmail.com
port 587
auth on
user username(at)gmail.com
password mypass
from username(at)gmail.com
logfile /var/log/msmtp.log
Change username(at) with your username and mypass with your password for gmail.
sudo chmod 0644 /etc/msmtprc
Open php.ini to edit
sudo gedit /etc/php5/apache2/php.ini
Uncomment sendmail_path and add this.
# -t option makes To: etc headers to be recognized.
sendmail_path = '/usr/bin/msmtp -t'
Restart apache
sudo service apache2 restart
Testing
Then test with the following code.
Method 1
Create /var/www/mail.htm
And /var/www/sendmail.php
Change youremail(at)gmail.com to whatever you like. Then go to http://localhost/mail.htm to fill up the form.
Method 2
Create /var/www/mail1.php and add this.
Change youremail(at)gmail.com to your email for receiving this email. And visit http://localhost/mail1.php to send email.
===================================================================
===================================================================
How to Backup & Restore drupal configuration ~
===================================================================
Features.module is an extremely powerful tool for managing Drupal
configuration changes.
Content Types, CCK settings, Views, Drupal Variables, Contexts, Imagecache
presets, Menus, Taxonomies, and Permissions can all be rolled into a feature,
which can be checked into version control. From there, deploying a new site,
or pushing changes to an existing one, is easily managed with the Features UI
or Drush.
Make sure you install Strongarm.module for exporting drupal config that gets
stored in your Variables table. You can also static content/nodes (ie: about
us, faqs, etc) into Features by installing uuid_features.module.
Hands down, this is the best way to work with other developers on the same
site, and to move your site from Development to Testing to Staging and
Production.
===================================================================
How to prepare to generate clean URLs ~
===================================================================
Change /etc/apache2/apache2.conf and put this:
AllowOverride All
AccessFileName .htaccess
This allows the local .htaccess in /drupal directory
Edit the /var/www/drupal/.htaccess file to include (uncomment) following line:
RewriteBase /drupal
===================================================================
Ubercart Intro ~
===================================================================
* Products (nodes)
* Taxonomy (classification; can have multiple: e.g. catalog, new/used,etc )
* lightbox (image popup)
* Product classes (hierarchical classification? pants/shirts; size:med,etc)
* shipping
* payment options : paypal, etc. (you can create one if needed).
* Order tracking: (order history, invoice view etc)
* coupons and volume discounts
* taxes
* stock settings (optional. For reminder email as stock falls low)
* roles (can assign different roles like platinum, priority customers)
===================================================================
Fckeditor Install ~
===================================================================
Installing this is bit different from other modules since
multiple steps required.
A WYSIWYG makes life a lot easier for anyone wanting to create large articles
in drupal. In this tutorial i'll show you how to install FCK Editor on drupal
6.
Requirement:
Drupal 6
FCKeditor drupal Module http://drupal.org/project/fckeditor
FCKeditor Code http://www.fckeditor.net/download
Step1 Install FCKeditor
Go to http://drupal.org/project/fckeditor and download the module and place it
in sites/all/modules. Download the FCKeditor and unzip the content into
sites/all/modules/fckeditor/fckeditor.
Once everything has be copied over, go to Administer >> Site Building >>
Modules and enable the module.
===================================================================
===================================================================
Drupal Javascript Settings ~
===================================================================
Drupal.settings is a way in Drupal that lets you pass variables from php to
javascript. In other words, somewhere in .module or .inc file of the above
module, a settings array is defined. That array contains several variables
defined for future use.
Theses variables can now be accessed on any page, through "Drupal.settings"
namespace by calling drupal_add_js(array(), setting); in that .module or .inc
file. Because of the above code, all variables are now added in
Drupal.settings array, which can be later accessed from your javascript file.
So when you write your javascript, you write like this youmodulename.setting =
somefunction(){ This is where you can access all variables that you earlier
defined in your .module or .inc file. Drupal takes care of the rest };
The use case of why we should this method is because, you can defined all your
php logic and data handling on your server. And perhaps through AJAX or normal
javascript you can access those data and act upon an event.
===================================================================
Drupal Database Access ~
===================================================================
$uid));
// Result is returned as a iterable object that returns a stdClass object on each iteration
foreach ($result as $record) {
// Perform operations on $record->title, etc. here.
// in this example the available data would be mapped to object properties:
// $record->nid, $record->title, $record->created
}
// Same example in Drupal 6
$uid = 1;
$result = db_query("SELECT n.nid, n.title, n.created
FROM {node} n WHERE n.uid = %d", $uid);
while ($record = db_fetch_object($result)) {
// Perform operations on $record->title, etc. here.
}
// NOTE: db_fetch_object and db_fetch_array have been removed from D7!
?>
===================================================================
Drupal Debugging ~
===================================================================
The entry point for drupal is index.php;
This is because following line in .htaccess does this:
ErrorDocument 404 /index.php
Most of the built-in urls in drupal page is designed to be
caught by index.php; Examples:
Admin: http://localhost/drupal/admin
Logout: http://localhost/drupal/logout
Donate: http://localhost/drupal/donate
Product Listing: http://localhost/drupal/catalog/4
Simple Page: http://localhost/drupal/node/2 (no raw .php input)
PHP Page: http://localhost/drupal/progs (you cut&paste php code)
The drupal/ dir contains only following .php files :
cron.php index.php install.php update.php xmlrpc.php
Any URL of form: http://localhost/drupal/pagename
is designed to execute index.php which in turn reads the page contents
from the database and executes it for you.
See this code:
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$return = menu_execute_active_handler();
print theme('page', $return);
drupal_page_footer();
===================================================================
Drupal Debug Session Walk Through:
/drupal/modules/node/node.module.node_page_default :
/drupal/modules/node/node.module at line 1773
/drupal/includes/menu.inc.call_user_func_array : lineno 0()
/drupal/includes/menu.inc.menu_execute_active_handler : lineno 350()
/drupal/index.php.{main} : lineno 17()
function node_page_default(){ /* Load first default Page */
SELECT nodes which are promoted to first page;
For each of that node: node_view(node_load($node->nid))
{
node_load(){
$fields = drupal_schema_fields_sql('node', 'n');
if ($extra = node_invoke($node, 'load')) {/* Node spec cb ? */}
Note: The node is a 'path node';
For each module which implements nodeapi : /* i.e. hook_nodeapi() */
node_invoke_nodeapi($node, 'load') {node spec api?}
/* Nodes implementing nodeapi: webform, comment,
devel_node_access (for debug), menu, path, search, taxonomy,
trigger, Content, Contact_webform, uc_quote, uc_attribute,
uc_cart, uc_catalog, uc_roles, uc_webform,
field_group, etc */
taxonomy module sets $output['taxonomy'] = node category;
}
$node = node_build_content((object)$node, $teaser=false, $page=false);
{
/* If there is view hook, call it */
node_prepare() => check_markup() {
/* runs all enabled filters.
e.g. php_filter() from php.module replaces the content
after php evaluating them as script.
*/
}
/* Node specific nodeapi for 'view' operation ? */
node_invoke_nodeapi($node, 'view', ...)
{
/* It is mostly ignored by most nodes. */
}
}
/* If current node is a type which can be referred by link,
* then set it's link attribute appropriately.
*/
$node->links = module_invoke_all('link', 'node', $node, $teaser);
/* If there is link hook, call it. Modules implementing link hook:
webform, comment, node, taxonomy,
$content = drupal_render($node->content)
{
$content = theme() /* defined in includes/theme.inc */
{
First: themes/engines/phptemplate/phptemplate.engine
init_theme() {
adds stylesheets;
theme engine init: i.e. phptemplate_init():
include ./phptemplate.php if exists;
contains mainly helper functions for later use;
}
drupal_final_markup($content) { header must have utf-8 }
}
}
}
If no default node available, display default message for node.;
}
function drupal_page_footer() { module_invoke_all('exit'); }
/* mods implementing exit: uc_credit_exit, uc* */
sess_write();
===================================================================
Drupal Node Vs Page ~
===================================================================
In the themes directory there are files called page.tpl, node.tpl,
block.tpl, box.tpl, comments.tpl, etc.
What are the differences between Node and Page ? ~
Drupal uses page.tpl.php as a template for an entire web page,
including logos, headers,
menus, sidebars, footers, etc. It (sometimes) uses node.tpl.php as a template
for the "main content" of the page, which is typically inserted into
page.tpl.php as . When you have many nodes on a single
web page (as on the front page of drupal.org), Drupal uses node.tpl.php as a
template for each node, inserting the whole lot of them into page.tpl.php.
What is really node ? ~
In Drupal, each item of content is called a node; Each node belongs to a
single content type; Content type defines various default settings for
nodes of that type, such as whether the node is published automatically
and whether comments are permitted.
For example, default content types in Drupal 6 are Page and Story.
The only difference between them is that by default comments are allowed
for one type and not for other type, etc. (which again you can configure).
Installing additional modules may create additional content types, such as:
Donation, Product, Web Form, etc.
Note: Don't confuse between 'a node of type Page' and Real Full Page
as used in page.tpl template; Any user created content type is really
a node.
===================================================================
Drupal Important Modules ~
===================================================================
Drupal core optional modules:
Site Building->Modules->
Core-Optional Modules:
PATH - Enable path aliases. e.g. register for register.php page.
PHP Filter - Enable php code input type for page.
Site Configuration -> Input Formats -> Enable php code for
specific roles. e.g. any authenticated user.
Site Configuration -> Clean URLs -> Enable (uses more clean urls)
===================================================================
Drupal WebForm Module ~
===================================================================
After you install WebForm module, you get new node type called 'WebForm';
Think of Webform as a solution when you want your end-users (often anonymous)
to be able to submit data that you want emailed to a few email addresses or
saved to a CSV file.
Webform typically is used when performing data collection that is a one-way
communication, that is, many users submitting values to a very small set of
administrators. Webform is not a front end for letting users create custom
nodes. Webform submissions are not nodes. This means that you can't use Views
with submissions, setup custom access permissions to submissions, or do just
about anything with them outside of what Webform provides for you.
For complex form creation, See Drupal *Form-API*
Using Form API, Drupal adds, by default, a security token to each form that
will protect against cross-site forgery;
===================================================================
Drupal Data Module ~
===================================================================
See http://drupal.org/project/data
Data module provides Views integration for displaying table data and Drupal
search integration for searching table content.
The Data module provides an API for dynamically allocating tables for
single-row records, etc :
// Get a table.
$table = data_get_table('my_table');
// If this table is not available create a table.
if (!$table) $table = data_create_table('my_table', $schema).
// Save some data to it.
$table->handler()->save($data);
// Add a field to it.
$table->addField('newfield', $spec);
// Add an index to it.
$table->addIndex('newfield');
// Remove all data from the table.
$table->handler()->truncate();
// Destroy the table.
$table->drop();
===================================================================
Drupal Theme, Block Internals ~
===================================================================
Drupal block is defined by any module. You can put a block in any
region defined by a theme. A theme can define regions such as:
Left Sidebar, Right Sidebar, Header, Content, Footer, etc.
Some themes can define more regions and some may define only few.
A region is defined as described in template.php, page.tpl.php
files. The contents of the region is defined by framework and
html code supplied in $region_name variable.
One or multiple blocks can live in region. The code to produce
block contents live in modules.
To add regions for Drupal 6.x
ADD the following code to you themename.info file:
regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer
regions[newregion] = New Region
(Drupal 6 also defines all above regions except newregion by default.
Drupal 7 defines sidebar_first, sidebar_second instead of left, right).
The clear cache on themes, visit "Administer > Site building > Themes".
Then, in your page.tpl.php file, do following:
A theme offers good configurability from drupal Admin interface and
also by directly changing certain template files for finer config.
Field module (Content Construction Kit in Drupal 6):
Primarily used to create new content types, but
it also provides the ability to change the labels and the ordering of fields
in those content types.
A sub-theme is one with your theme.info file which contains a line in it
to point to the parent theme. e.g. base theme = garland
template.php contains any overriding theme functions.
Drupal 6 features specified in .info file:
You can disable certain components using features:
features[] = logo
features[] = name
features[] = slogan
features[] = mission
features[] = node_user_picture
features[] = comment_user_picture
features[] = search
features[] = favicon
; These last two disabled by redefining the
; above defaults with only the needed features.
; features[] = primary_links
; features[] = secondary_links
drupal_set_content('header', 'Welcome!') would assign the text 'Welcome!' to
the header region.
The region variables such as $left, $right, etc is defined and accessible
inside page.tpl.php; however it is not available from block,view templates.
To configure sitename, etc go to Admin=>Site Building=>Themes
Sub-themes do not inherit custom regions from a parent theme.
You should copy the region declarations from the parent
theme's .info file.
Interesting Drupal Template Variables:
$breadcrumb: HTML for displaying the breadcrumbs at the top of the page.
$closure: Needs to be displayed at the bottom of the page,
for any dynamic javascript that needs to be called once the
page has already been displayed.
$content The HTML content
$help Dynamic help text, mostly for admin pages.
$is_front True if the front page is currently being displayed.
$layout This setting allows you to style different types of layout
('none', 'left', 'right' or 'both') differently, depending on
how many sidebars are enabled.
$messages HTML for status and error messages, to be displayed at top.
$node Available in page.tpl.php
$primary_links (array)
$sidebar_left
$sidebar_right
$styles Required for stylesheet switching to work.
This prints out the style tags required.
$tabs HTML for displaying tabs at the top of the page.
See theme snippets: http://drupal.org/node/45471
===================================================================
Block.tpl.php
===================================================================
http://drupal.org/node/11813
Lays out content for blocks (left and/or right side of page).
This template is optional, and can be overridden.
Available variables: The $block object includes:
$block->module
$block->delta The number of the block for a particular module.
$block->subject The block title.
$block->content The html content for the block.
$block->status Status of block (0 or 1).
$block->region Region name, e.g. left, right, etc.
$block->throttle: Throttle setting.
Template files are searched in the following order:
block-[module]-[delta].tpl.php
block-[module].tpl.php
block-[region].tpl.php
block.tpl.php
===================================================================
Box.tpl.php
===================================================================
Prints a simple html box around a page element.
Available variables
$title
$content
$region Region. main, left or right.
Default template:
===================================================================
Node.tpl.php
===================================================================
This template controls the display of a node, and a node summary.
Available variables
$content Node content, teaser if it is a summary.
$date
$id The sequential ID of the node being displayed in a list.
$is_front True if the front page is currently being displayed.
$links Node links.
$name Formatted name of author.
$node (object) The node object.
Tip:
$node_url Link to node.
$page True if the node is being displayed by itself as a page.
$picture HTML for user picture, if enabled.
$sticky True if the node is sticky.
$taxonomy (array) array of HTML links for taxonomy terms.
$teaser Boolean to indicate whether to return the teaser
rather than the full node text.
$terms HTML for taxonomy terms.
$title Title of node.
$zebra Alternates between odd/even in a list.
===================================================================
node-page.tpl.php
===================================================================
Themes only Page type nodes. Note that this is different from
page.tpl.php which controls the layout of the entire page including
header, sidebars and so on.
When using phptemplate node-[type].tpl.php suggestions, there must
also be an original node.tpl.php template present in your theme
directory or the template suggestion is ignored.
===================================================================
Drupal Role check ~
===================================================================
Example 1:
function user_has_role($role, $user = NULL) {
if ($user == NULL) {
global $user;
}
if (is_array($user->roles) && in_array($role, array_values($user->roles))) {
return TRUE;
}
return FALSE;
}
Example 2:
===================================================================
Drupal Sessions ~
===================================================================
See hook_user in drupal 6.
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
if(isset($_SESSION['region'])){
print '1';
}else{
print '0';
}
See includes/session.inc :
function sess_read($key) {
....
if (!isset($_COOKIE[session_name()])) {
$user = drupal_anonymous_user();
return '';
}
$user = db_fetch_object(db_query("SELECT u.*, s.* FROM {users} u INNER JOIN ".
. " {sessions} s ON u.uid = s.uid WHERE s.sid = '%s'", $key));
// We found the client's session record and they are an authenticated,
// active user.
if ($user && $user->uid > 0 && $user->status == 1) {
// This is done to unserialize the data member of $user
$user = drupal_unpack($user);
....
return $user->session;
}
===================================================================
Anonymous Sessions Performance ~
===================================================================
See http://2bits.com/articles/reducing-server-load-eliminating-anonymous-sessions-drupal-6x.html
Examples of creating a new session:
INSERT INTO sessions (sid, uid, cache, hostname, session, timestamp) VALUES
('744e888350d5c759f067d58380f6874e', 0, 0, '10.1.1.1', '', 1243567441)
And examples for updating a session:
UPDATE sessions SET uid = 0, cache = 0, hostname = '10.1.1.2', session = '',
timestamp = 1243567406 WHERE sid = '74db42a7f35d1d54fc6b274ce840736e'
UPDATE sessions SET uid = 0, cache = 0, hostname = '10.1.1.3', session = '',
timestamp = 1243567429 WHERE sid = 'cf9c94337f2cabc4e7aec5afcfbf44d2'
Note the uid = 0 in all the above cases.
Because such operations are performed way to frequently on a busy site, there
can be contention on the sessions table, even after converting that table to
InnoDB.
Drupal 7.x now has in core the ability to support disabling of anonymous user
sessions. This is good news for sure, but it does not exist on Drupal 6.x, so
not immediately usable for live sites. Even though a port to 6.x is maintained
by Four Kitchens, the the patch involved is too large and somewhat invasive.
That makes it require constant updating as new point releases come out.
Some when Marco Carbone in a recent article, described a simpler approach of
how to get rid of cookies for anonymous users, a light bulb lit up.
Now there is a module to implement this:
No anonymous user sessionsa http://drupal.org/project/no_anon
===================================================================
Drupal Theming ~
===================================================================
See http://websule.com/tutorials/drupal-themeing/drupal-themeing-basics
The general steps for creating a new Drupal theme include the following:
1. Create or modify an HTML file for the site.
2. Create or modify a CSS file for the site.
3. Create an .info file to describe your new theme to Drupal.
4. Standardize the file names according to what Drupal expects.
5. Insert available variables into your template.
6. Create additional files for individual node types, blocks, and so on.
To create a new theme 'Grayscale' do following :
1. Create Grayscale subdir in sites/all/themes dir.
Create grayscale.info file:
name = Grayscale
core = 7.x
engine = phptemplate
stylesheets[all][] = css/style.css # style for all types
We can also say: stylesheets[print][] = css/print.css # style for print page.
Use firebug to see the css style of the main page.
The structure is somewhat like this: