Sarkari Naukri and Naukri

Friday, 5 April 2013

user load drupal 6

 
 
* Using node_load with a node ID parameter */
$node = node_load(25);
/* Then using user_load with the user ID */
$user = user_load(array('uid' => $node->uid));

Thursday, 4 April 2013

Create custom block drupal 7

Some easy steps to create block through module :
Step 1 :
Create a folder (give a folder name e.g., mymodule) in the modules directory of your Drupal site.  The name which you are giving as a folder name will become your module name. To create a module there must have two files inside the module folder named as:
( a) mymodule.info (b) mymodule.module
mymodule.info file contains the general information of the module you created and mymodule.module file contains the main coding which creates the block.
# We are considering the module name as customblock and hence filenames are customblock.info and customblock.module
Step 2 :
Copy the code given below and paste it inside the customblock.info file.
; $Id: customblock.info,v 1.4 2009/02/18 22:02:46 dries Exp $
name = Custom Block
description = Creating Custom Block to demonstrate the block creation through module.
package = Diadem
version = VERSION
; Information added by drupal.org packaging script on 2008-10-08
version = “5.11″
project = “drupal”
datestamp = “1223496909″
This is the general information about the module and description field reflect the purpose of creating the module . Give the correct version which you are using for your drupal site. You need to change this information as per your requirement.
Step 3 :
Always remember that all the function name should start with the module name, e.g.  modulename_node_info(), modulename_perm(), etc. Copy the code given below and paste it inside the customblock.module file. You will observe that there has no php end tag at the end of the file. It is recommended in drupal that we donot need to end the php tag in the module pages.
<?php
/**
* Implementation of hook_node_info().
*/
function customblock_node_info() {
return array(
‘customblock’ => array(
‘name’ => t(‘Custom Block’),
‘module’ => ‘customblock’,
‘description’ => t(‘How to create a custom Block.’),
)
);
}
/**
* Access Permission of this module by hook_perm();
*/
function customblock_perm() {
return array(‘access customblock content’);
}
/**
* Implementation of hook_block().
*/
function customblock_block($op=’list’, $delta=0) {
// listing of blocks, such as on the admin/block page
if ($op == “list”) {
$block[0]["info"] = t(‘Custom Block’);
return $block;
}
else if($op == ‘view’)
{
$block_content=”;
$block_content.=’<div style=”border:1px solid #D6D6D6; background-color:#F2F2F2; padding: 5px;”>’;
$block_content.=’<div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. Why do we use it? <br />
<a href=”http://drupal.org/” target=”_blank”>Click Here</a> – Drupal.Org
</div>’;
$block_content.=’</div>’;
$block['subject'] = ‘Custom Block’;
$block['content'] = $block_content;
return $block;
}
}

How do you uninstall modules in drupal

For both Drupal 6.x and Drupal 7.x, there are just three major steps to removing a contributed module from a Drupal site:
  1. Disable the module
  2. Uninstall the module
  3. Delete the module code

How do you install modules in drupal

For both Drupal 6.x and Drupal 7.x, there are just four major steps to adding a contributed module to a Drupal site:
  1. Upload the module code
  2. Enable the module
  3. Set permissions for the module
  4. Configure the module

contributed modules drupal

Contributed modules live on Drupal.org, specifically, at http://drupal.org/project/modules. You can search the module list and filter it by category, Drupal version, and status. You can also sort based on most installed, title, author, last release date, etc.

what is modules in drupal ?

Drupal is designed to be modular. Instead of always having every possible tool or feature in every site's code, you can just have those you're actually going to use.

Drupal core —what you get when you install Drupal— is like a very basic box of Lego™: a platform and some basic bricks (modules) to get you started. You can do a lot with just those basics, but usually you'll want more.

That's where contributed modules come in. Contributed modules are packages of code that extend or enhance Drupal core to add additional (or alternate) functionality and features. These modules have been "contributed" back to the Drupal community by their authors.

Types of module drupal


A Drupal site can have three kinds of modules (the 3 Cs): 
 
Core modules that ship with Drupal and are approved by the core developers and the community. 
 
Contributed modules written by the Drupal community and shared under the same GNU Public License (GPL) as Drupal. 
 
Custom modules created by the developer of the website.

L() used in drupal


formats an internal or external URL link as an HTML anchor tag. 
 
This function correctly handles aliased paths and adds an 'active' class attribute to links that point to the current page (for theming), so all internal links output by modules should be generated by this function if possible. 
 
l($text, $path, array $options = array()) .

t function in drupal


Translates a string to the current language or to a given language. 
 
The t() function serves two purposes. First, at run-time it translates user-visible text into the appropriate language. Second, various mechanisms that figure out what text needs to be translated work off t() -- the text inside t() calls is added to the database of strings to be translated.

What is hook in drupal ?


Allow modules to interact with the Drupal core. 
Drupal’s module system is based on the concept of “hooks”. A hook is a PHP function that is named foo_bar(), where “foo” is the name of the module (whose filename is thus foo.module) and “bar” is the name of the hook. Each hook has a defined set of parameters and a specified result type.

Properties of .info file drupal

name (Required) .
description (Required) .
core (Required) .
style sheets (Optional) .
scripts (Optional) .
files (Optional) .
dependencies (Optional) .
package (Optional) .
php (Optional) .
configure (Optional) .
required (Optional) .
hidden (Optional) .

.info files drupal


Drupal uses .info files to store metadata about themes and modules.
The following is a sample .info file:
name = Really Neat Widget
description = Provides a really neat widget for your site's sidebar.
core = 7.x
package = Views
dependencies[] = views
dependencies[] = panels
files[] = example.test
configure = admin/config/content/example

What is a Drupal Theme?


Drupal Themes are what determines the look and feel of Drupal sites. You can select a theme contributed by the community and customize it to suit your needs. You can also create your own themes. Themes are often created to suit a specific purpose or tye of site.
There are themes for News sites, corporate sites, Blogs, commerce sites and any more. 
 
Drupal Core includes a variety of Core Themes to suit many types of sites and styles. Some themes are designed to be highly customizable, there are also modules such as the Drupal Color Manager allow site admins to easily customize the look and feel of themes.

What are Drupal Contrib Modules .

One of the great things about Drupal is the vast collection of ad-ons called ‘Contrib Modules’. These modules are developed, contributed, and supported by the Drupal open source community. Currently, there are over 10,500 Contrib Modules available for free download. 
 
 When selecting a module, you can see info about it such as number of downloads, open bugs, when it was last updated, and developer comments and answers. Modules offer a vast array of features including the following categories: 
 
Administration
Community
Content access control
E-Commerce
Evaluation/ Rating
Event
File Management
Games & Amusement
Location
Mail
Media
Multilingual
Multisite
Paging
Search
Security
Spam Prevention
Statistics
Third Party Integration
User Access and Authentication
User Management
Utilities
 

What is Drupal Core?


Drupal Core is a bundle of official releases of modules and themes intended to provide a foundation for deploying Drupal based websites. 
 
 Drupal Core includes common features and is easily extended with added modules and themes. 
 
Components include:
Account registration and maintenance
Menu Management
Page layout customization
Site administration
Access statistics and logging
Basic search • Blogs, books, comments, forums, and polls
Caching and feature throttling for improved performance
Descriptive URLs
Multi-level menu system
Multi-site support (single source base)
Multi-user content creation and editing
OpenID support
RSS feed and feed aggregator
Security and new release update notification
User profiles
Various access control restrictions (user roles, IP addresses, email)
Workflow tools (triggers and actions)
 

What Technology does Drupal use?


Drupal is an open source platform built on PHP. Drupal has very basic server requirements common to most hosting providers; a web server that can run PHP (including Appache, IIS & ngix). MySQL is commonly used for a database.

What is Drupals Origin?



While attending the University of Antwerp, Dries Buytaert tinkered with an online messaging board to keep in touch with his friends. 
 
 The name ’Drupel’ is derived from the Dutch word “drupel” which means “drop”. In 2001 Drupal became an open source project.

What are Drupal Nodes?


 
Drupal sites are comprised of sets of content and functionality called ‘nodes’. All content on a Drupal site, be it a blog post, article, static page, poll or forum topic is stored as and has common attributes of ‘nodes’. 
 
Nodes are very flexible in that they can accommodate all types and configurations of content and allow for site builders to create customized content types.

What is Drupal Used for?


It is particularly well suited to e-Learning systems, Community/social networking sites, and news publishing, where its powerful authoring and publishing features allow administrators to create, revise, and deploy content in a rapid and organized manner. User management, site reporting and statistics, ad management, community management, and other administrative functions utilize an intuitive and robust back-end user interface.

Other common deployments are:
Community Portal sites
Business Community Sites
Aficionado sites
Intranet
Corporate websites
E-commerce sites
Resource Directories
International Sites
Multimedia

About Drupal


 
Drupal is a free community supported framework for creating, organizing, presenting and managing a website. It powers millions of websites and applications from all over the world. 
 
Drupal makes it easy for contributors to publish to websites and easy for developers to deploy new sites as well as add features to existing ones. Most commonly referred to as a content management system, or CMS, Drupal has much more to offer. 
 
 Drupal installations include a set of modules called Core Components, which provide features such as user management, menu systems, and user contributed content. The Drupal open source community (one of the largest in the world) contributes and supports thousands of free flexible and robust modules and themes, which can be easily integrated into websites to offer powerful features such as multimedia, calendars, rating systems, and other social media tools.

which type of website make in drupal

Drupal you can create pretty much any kind of site:-

1. File storage site.

2. Social network.

3. Twitter Clone.

4. News portal.

5. Blog network.

6. Video-sharing site.

7. Image-sharing site.

8. Digg-like news site

 

which cms is better for website?.

Some popular cms

 Drupal
Joomla
Wordpress 

I personally think Wordpress is the easiest of the bunch to get up and running.

If you are a seasoned web developer, WordPress is the fastest to get up and running, and with the amount of plugins and specialized themes available, you can probably get it to where you want in a very short amount of time (weeks instead of months).

WordPress used to be extremely blog-centric instead of a full featured CMS, but now with custom post types you can make it whatever you want. It's has a very pluggable interface so plugins are simply uploaded and turned on. And the community that builds them are in the thousands. WordPress also has huge community support. Anything you need can be answered by them.

The above here gives WordPress the edge for gettings websites up and running with ease and speed.

Drupal is a much harder to setup CMS. Recent versions have helped this but it's still a very different kind of CMS. The terminology is tricky to grasp, and immediate understanding is confusing for new users. Drupal is a very powerful CMS and I have only worked with it a little to build a basic site but enough to feel is this worth my time.

With any CMS, time and patience they can all do everything you want given your programming experience, but the initial setup to get something going I'd have to give it to WordPress. 

difference between drupal and joomla

1.Drupal is much more flexible when it comes to the development and setting up the theme and layout of the website. Joomla! is known to be surrounded by the paradigms set by itself, and offers less scope to be flexible.

2. Joomla! is easy and fast to operate and implement. On the other hand, Drupal is quite a tough nut and have always been the choice of comprehensive businesses and enterprises.

3. If we put it in a precise manner then, Joomla! offers a nice, professional looking website with a slow, categorised, and limited options, while its actually vice versa with Drupal.

4.Backend admin functionality with the Drupal is not that good, while Joomla! is comparatively better.

5.The Drupal codes are more professional and skilled and of a quality, while it lacks in the case of Joomla!.

6.With Drupal, you are able to use the same log-in-details for every different site.

7.SEO has always and will always remain the key concern of these open source software. Therefore, this point should be of utmost importance that Drupal has SEO friendly URLs, while with Joomla!, one needs a commercial component.

8.While Joomla! makes use of the plug-ins for the additional functionality, but Drupal uses modules. So drupal module development become more popular.

Both are Open Source Content Management System.There are some differences between them.These are as follows...
* Drupal is more flexible than Joomla.
* Drupal is better for extensibility and for larger sites while Joomla is easier for Non-Geeks.
*Some of the features offered by Drupal are as follow...
Metadata Functionalities
Discussion capabilities
user administration
Publishing workflow
news aggregiation
XML publishing for content sharing

On the other hand Joomla is used form simple to complex corporate applications and it is easy to install, reliable and easy to manage.


Though they may seem quite similar at first glance the deeper you look the more differences you will find.

Joomla is more complete as CMS "out if the box" with a good system for organising and outputting articles of content, a pre configured WYSIWYG editor, excellent media manager for files and images and even a strong access control system. This comes at a (for me personally) high price as it forces you to do things the Joomla way, very little flexibility.

Drupal is significantly more flexible, arguablly built to be flexible, at the cost of a longer learning curve and (until you learn your way around) a longer development time. With the addition of just a few third party modules to extend Drupal (look into Views, CCK (part of core in Drupal 7), Panels, Rules and you'll get the idea).

Since we are talking about third party extensions its worth saying Joomla has some excellent third party components that will do just about anything but again the tendency is for them to achieve specific goals rather than providing tools to let you do what you want.

There are also major differences in the coding, Joomla uses MVC (you DON'T need to hack core to work with Joomla) and Drupal uses something I have heard referred to as PAC but cannot remember what it means. Drupal has a very easy to use system of hooks to add functionality to a site.

The topic is much deeper than this to be honest, I'll let others add their perspectives as this is just my experience. For the type of site you're planning I would recommend Drupal.

 

 

what is drupal

Drupal is open source cms and it is free to download it and share it with others. Drupal powers some of the busiest sites on the web, and can be adapted to virtually any visual design. Drupal runs over a million sites.

is open

Drupal was created over ten years ago and released as open-source software under the GNU Public License. That means it’s completely free to download, use, and modify: There are no purchase, license, or maintenance fees.

is design

Drupal site designs come from “themes”, whose visual presentation is described in standard CSS. Drupal.org hosts hundreds of free, fully customizable themes, including several “base themes” to help you launch your own designs.

is social

Drupal is a multi-user system, letting site visitors log in (as “authenticated” users) or browse the site without doing so (as “anonymous” users). You control their access levels, and can also assign “roles” for multiple permission levels.

is secure

Drupal is used by thousands of high profile web sites and is subject to rigorous security testing both by the Drupal community and by security experts around the world. Drupal's core code has been proven to prevent common security vulnerabilities such as those defined by the Open Web Application Security Project (OWASP).

is scalable

Drupal has proven itself repeatedly in the field on sites with over a million pages, and at over 20,000 requests per second. Its core installation handles over 99 percent of use cases, while free optimization tools and a large base of Drupal-trained administrators address the other one percent.



create block region in drupal 6


Open theme_name.info and add regions like


regions[left] = Left sidebar
regions[right] = Right sidebar
region[header] = Header
regions[content] = content
regions[footer] = Footer
regions[top] = Center
regions[center] = Center
regions[custom_regions] = Custom Regions
regions[custom_regions1] = Custom regions1

 add in page.tpl.php file
  1. <div>
  2. Custom region blocks will go here...
  3. <?php print $custom_regions?>
  4. </div>

Create New Block Region in Drupal 7

Step 1:
Open up your theme's .info file and add the following line:
regions[new_region] = New Region

Step 2:
Now go to the your site url/admin/structure/block and select which block you want to show in your newly create region, and save the your choice.


Step 3:
Then you'll need to print out your new region in your page.tpl.php file which goes something like this now:
<?php if ($page['new_region']): ?>
      <div id="new_region"><div>
        <?php print render($page['new_region']); ?>
      </div></div>
    <?php endif; ?>

db_fetch_object not working in drupal 7

<?php// Drupal 7
// Notice the place holders are now done using the same syntax as PDOs (:uid)
// Placeholders also don't need to be quoted anymore.
$uid = 1;$result = db_query('SELECT n.nid, n.title, n.created
FROM {node} n WHERE n.uid = :uid'
, array(':uid' => $uid));// Result is returned as a iterable object that returns a stdClass object on each iterationforeach ($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!


?> 



You can use fetchField() to get a single value. Example:

<?php
$node_title
= db_query('SELECT title FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();?>



Wednesday, 3 April 2013

get path of node id drupal


1.first options

$just_the_aliased_path=drupal_get_path_alias("node/".$THE_NID_HERE);

2.second options
 
and you can use url functions

$nid = 1; // Node ID
 
$url = url('node/' . $nid, $options);

get path of taxonomy term id drupal




<?php// first, get a term object from a term ID

$term = taxonomy_get_term($tid);

// then, use the term object to get the unaliased path

$taxonomy_path = taxonomy_term_path($term);

// finally, lookup the path alias using drupal_lookup_path()

$taxonomy_path_alias = drupal_lookup_path('alias', $taxonomy_path);

?>
For Drupal 7 you can use: taxonomy_term_uri()
<?php

$term
= taxonomy_term_load($tid); // load term object

$term_uri = taxonomy_term_uri($term); // get array with path

$term_title = taxonomy_term_title($term);

$term_path = $term_uri['path'];

$link = l($term_title,$term_path);

?>
or simple soution
url('taxonomy/term/' . $tid);

create custom theme in drupal 7

1. Create custom.info file

- Create a folder custom in your sites/all/themes folder
- Inside it create a file custom.info with these lines:

name = Custom Theme
core = 7.x
engine = phptemplate

2. Enable the theme

- Go to Appearence and click 'Enable and set default' for the Custom Theme.

3. Create page.tpl.php and style.css files

- Create a folder templates in your sites/all/themes/custom folder
- Inside it create a file page.tpl.php
- Now let's create our html document with this design in mind. Add the wrapper and navigation divs in the page.tpl.php:

<div id="wrapper">
  <div id="navigation"><?php if ($main_menu) { print theme('links__system_main_menu',array('links' => $main_menu)); } ?></div>
  <div id="header"><h1>BuyFlowers.com</h1></div>
  <div id="page-wrapper">
    <div id="sidebar"><?php if($page['sidebar_first']) { print render($page['sidebar_first']); } ?></div>
    <div id="content">
      <?php print $messages; ?>
      <h1><?php if($title) { print $title; } ?></h1>
      <div class="tabs"><?php if ($tabs) { print render($tabs); } ?></div>
      <?php print render($page['help']); ?>
      <ul class="action-links"><?php if($action_links) { print render($action_links); } ?></ul>
      <?php print render($page['content']); ?>
    </div>
  </div>
</div>


* { margin:0; padding: 0;} /* Clear all predefined margins and paddings to make it easier to style */
html { overflow-y: scroll;} /* Prevent page-shift to right when little or no content. */
body { font-family: Arial, sans-serif;} /* Change the default font to Arial. Generic sans-serif will be applied if Arial is not available */
a { color: #000; outline: none;} /* Remove dotted outline from links (might want to leave it for better usability). */
p { padding: 1em;}

/*** LAYOUT ***/

/* WRAPPER */
#wrapper { width: 1000px; margin: 0 auto;}
/* Make it 1000px wide and center it */

/* NAVIGATION */
#navigation { width: 1000px; height: 50px; border: 1px solid #ccc; border-top: none; background-color: #eee;  }
/* Define width, height, border and background color */
 #navigation ul { width: 400px;  margin: 0 auto; list-style: none; line-height: 50px;} /* list-style removes the dots, line-height centers the links vertically */
  #navigation ul li{ display: inline;} /* Spread the list elements horizontally */

/* HEADER */
#header { width: 1000px; height: 150px; border: 1px solid #ccc; border-top: none; background-color: #ddd; }
 #header h1 { line-height: 150px; padding: 0 0 0 60px; font-size: 40px;}

/* PAGE-WRAPPER */
#page-wrapper { width: 1000px; border: 1px solid #ccc; border-top: none; overflow: hidden;}

/* SIDEBAR */
#sidebar {  width: 260px; float: right; border-left: 1px solid #ccc;  background-color: #eee; padding: 20px 20px 10000px 20px;  margin-bottom: -10000px; }

/* CONTENT */
#content { margin-right: 300px; padding: 20px;}



 

How to save node in drupal 6

<?php
$orig
= node_load(); // load original$node = $orig;       // copy for mods $node->teaser = 'nah, nah, nah, nah, boo, boo'; // Do some changes node_save($node); // save your changes if ($node->changed != $orig->changed)
{
  
drupal_set_message('Updated');
}
else
{
 
drupal_set_message('Unable to update.');
}
?>
If your node type is saving revisions, you could technically use $node->vid instead of $node->changed in the same manner, however if your node type ISN'T saving revisions, you need to use $node->changed.