Category Archives: Drupal

How to enable or allow htaccess file on apache server

Here we will learn How to enable or allow htaccess file on apache server to override your default server configurations. But before that we will quickly see what is htaccess file.

What is htaccess file?

How to enable or allow htaccess file on apache server

htaccess is a hypertext access file using which web master can override the Apache server default configurations as per their requirement.

Such modifications of default configurations are applicable on directory in which .htaccess file is resides and on all the succeeding directories.

But before you start writing any code in .htaccess file you have to confirm whether this file has permission to override the default configuration or not.

Read more

How to make placeholder work in IE browser

As we all know that HTML 5 placeholder attribute is not working in IE less than 10 version. If you have input elements in your DOM with placeholder attribute and access the page in IE browser less than 10 version then you will get an error message that placeholder is not defined. To resolve this issue you have to use javascript or jQuery. I have attached a sample code file please download and check it out in different browser. Sample Code

How to create a order In Drupal programmatically

Today I got one strange requirement from my client and that is he has a Drupal website which is combined with NetSuite(NS), and he wants that if he create any order at NS end then this order will be create at Drupal end using web-services. So now the first question  “How to create a order In Drupal programmatically”.

Following are the steps:

Step1: Create an new order with the help of below code:

// Create the new order in checkout status.
$order = commerce_order_new($uid, 'pending');

Step2: Load products which you want to add in your news order with the help of below code:

$product = commerce_product_load($product_id);
$line_item = commerce_product_line_item_new($product, 1, $order->order_id, array());
commerce_line_item_save($line_item);

Note: You can do the same for multiple products in a single order.

Step3: Wrap up the order with the help of below code:

$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper->commerce_line_items[] = $line_item;

Step4: Save the order to database:

commerce_order_save($order);

Step5: Done :)

Code together:

$uid = 'USER_ID';
$product_id = 'PRODUCT_ID';

$order = commerce_order_new($uid, ‘pending’);

$product = commerce_product_load($product_id);
$line_item = commerce_product_line_item_new($product, 1, $order->order_id, array());
commerce_line_item_save($line_item);

$order_wrapper = entity_metadata_wrapper(‘commerce_order’, $order);
$order_wrapper->commerce_line_items[] = $line_item;

commerce_order_save($order);

Summery:

Create one link using hook_menu() and call a custom ‘page callback’ function and add the above code in this custome function and execute the newly created link in browser.

How to access Drupal functions and sesions in a stand alone PHP script

If you want to access Drupal functions and sessions in your stand alone PHP scripts which is present any where in your project directory then how you will do this?

Let say you are going to create one websevices in drupal thats mean you have to create one PHP stand alone file then how you will access the Drupal functions?

First of all I am clearing this that this solution is for Drupal 7, not sure this will work in Drupal 6 or not, as I have not tested this in Drupal 6 environment.

Below are the code you have to write in you PHP stand alone file.

$path = getcwd();
$pos = strpos($path, 'sites');
$path = substr($path, 0, $pos);
$path = explode('\\', $path);

$length = sizeof($path);
unset($path[$length - 1]);
$path = implode('/', $path);

// Get the base path
define('DRUPAL_ROOT', $path);

//Include the bootstrap file for using the DRUPLA function in our file
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

Now you can access any function of Drupal 7 in this stand alone PHP file :)

How to modify Active Directory passwords through PHP

The secret is keep in Active Directory on a user object within the unicodePwd attribute. This attribute is written under some restricted conditions, however it can’t be accessible, but the value of this attribute can be modify or alter.
In order to alter this attribute, you must have a 128-bit Secure Socket Layer (SSL) connection to the server. For this connection to be possible, the server must possess a server certificate for a 128-bit RSA connection, the client must trust the certificate authority (CA) that generated the server certificate, and both client and server must be capable of 128-bit encryption.

Passwords must meet complexity requirements determines whether password complexity is enforced. If this setting is enabled, user passwords meet the following requirements:

  • The password is at least six characters long.
  • The password contains characters from at least three of the following five categories:
    • English uppercase characters (A – Z)
    • English lowercase characters (a – z)
    • Base 10 digits (0 – 9)
    • Non-alphanumeric (For example: !, $, #, or %)
    • Unicode characters
  • The password does not contain three or more characters from the user’s account name.

PHP code as follows:
function create_ldap_connection() {
$ip = "Ad server IP";
$ldaps_url = "ldaps://$ip";
$port = 636;

$ldap_conn = ldap_connect( $ldaps_url, $port ) or die("Sorry! Could not connect to LDAP server ($ip)");

ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);

$username = "AdminUserName";
$password = "AdminPassword";
$binddn = "CN=Administrator,CN=Users,DC=TestDomain,DC=local";

$result = ldap_bind( $ldap_conn, $binddn, $password ) or die("
Error: Couldn't bind to server using provided credentials!");

if($result) {
return $ldap_conn;
} else {
die("
Error: Couldn't bind to server with supplied credentials!");
}
}

function get_user_dn( $ldap_conn, $user_name ) {
/* Write the below details as per your AD setting */
$basedn = "DC=AD Test,DC=Local";
/* Search the user details in AD server */
$searchResults = ldap_search( $ldap_conn, $basedn, $user_name );
if ( !is_resource( $searchResults ) )
die('Error in search results.');

/* Get the first entry from the searched result */
$entry = ldap_first_entry( $ldap_conn, $searchResults );
return ldap_get_dn( $ldap_conn, $entry );
}

function pwd_encryption( $newPassword ) {
$newPassword = "\"" . $newPassword . "\"";
$len = strlen( $newPassword );
$newPassw = "";
for ( $i = 0; $i < $len; $i++ ){
$newPassw .= "{$newPassword{$i}}\000";
}
$userdata["unicodePwd"] = $newPassw;
return $userdata;
}

$user_name = "(sAMAccountName=UserName of user whose password want to change)";//Dont remove parentheses brackets
$user_password = "New Password";

$ldap_conn = create_ldap_connection();
$userDn = get_user_dn($ldap_conn, $user_name);
$userdata = pwd_encryption($user_password);

$result = ldap_mod_replace($ldap_conn, $userDn , $userdata);
/* Check whether the password updated successfully or not. */
if ( $result )
die("Password changed successfully!");
else
die("Error: Please try again later!");

PHP CMS lists

Following are the PHP CMS list and their brief details.

NameSupported databasesLatest stable releaseLicensesLatest release date
AdaptCMS LiteMySQL2.0.1GPL2011-09-21
ATutorMySQL2.0.3GPL2011-09-14
b2evolutionMySQL4.1.4GPL2012-04-06
BEditaMySQL3.1.5AGPL2012-03-05
BLOG:CMSMySQL4.2.1.gGPL2011-06-06
CivicSpaceMySQL0.8.3GPL2005-05-01
CMS Made SimpleMySQL, PostgreSQL1.10.3GPL2012-01-09
Concrete5MySQL5.5.1MIT2012-01-23
CotontiMySQL0.9.11BSD2012-08-01
DotclearMySQL, PostgreSQL, SQLite2.4.2GPL2012-02-11
DrupalMySQL, Oracle, PostgreSQL, SQLite, Microsoft SQL Server7.14GPL2012-05-02
Elxis CMSMySQL, Oracle, PostgreSQL2009.3GNU/GPL2011-11-23
DynPGMySQL4.5.1GPL2011-12-17
e107MySQL1.0.0GPL v22011-12-28
Exponent CMSMySQL2.0.4GPL2012-01-27
eZ PublishMySQL, PostgreSQL, Oracle, Microsoft SQL Server4.6.0GPL2011-11-22
Frog CMSMySQL, SQLite0.9.5GPL2009-04-26
GeeklogMySQL, PostgreSQL, Microsoft SQL Server1.8.0GPL2011-06-12
HabariMySQL, PostgreSQL, SQLite0.8.0Apache License2011-12-13
ImpressCMSMySQL1.3.1GPL2011-12-27
Joomla!MySQL, MSSQL, PostgreSQL, Oracle, SQLite2.5.6GPL2012-03-15
JumboSQLite1.3.7GPL v32011-09-16
KajonaMySQL, PostgreSQL, SQLite3.4.1LGPL2011-11-08
KnowledgeTree Community EditionMySQL3.7GPL & proprietary2009-12
LyceumMySQL1.0.2GPL2008-06-04
MamboMySQL4.6.5GPL2008-06-01
MediawikiMySQL, PostgreSQL, SQLite1.19.0GPL2012-05-02
MiaCMSMySQL4.6.5GPL2008-09-11
Midgard CMSMySQL8.09.9.2LGPL2010-07-22
MODxMySQL2.2.0-pl2GPL2012-01-04
MoodleMySQL, Postgres, MSSQL, or Oracle2.3.1GPLv3+2012-07-09
Nucleus CMSMySQL3.64GPL2011-03-14
OcportalMySQL7.1.5CPAL2011-09-06
OpusMySQL2.29GPL2008-07-08
papaya CMSMySQL, PostgreSQL, SQLite5.3.10GNU/GPL 22012-02-13
Phire CMSMySQL1.1.2New BSD License2011-07-07
PHP-FusionMySQL7.02.04AGPLv32011-11-10
PHP-NukeMySQL8.1GPL2009-05-22
PHPSlashMySQL0.8.1.1GPL2006-01-15
PhpweblogMySQL0.5.2GPL2001-10-31
phpWebSiteMySQL, PostgreSQL1.6.3LGPL2009-06-17
pimcoreMySQL1.4.5BSD2012-04-16
PivotXMySQL, Flat-file database2.3.0GPL2011-08-15
Pixie (CMS)MySQL1.0.2GPL2009-03-24
PrestashopMySQL1.4.7GPL2012-02-08
ProcessWireMySQL2.2.2GPL2012-01-11
RedaxscriptMySQL1.0GPL2012-08-10
RavenNuke CMSMySQL2.4.0GPL2009-10-12
RenovatioCMSMySQL001.110GPL2011-10-18
SMW+MySQL1.6.0GPL2011-12-02
SerendipityMySQL, PostgreSQL, MySQLi, SQLite1.6.0BSD2011-10-27
SilverStripeMySQL, Microsoft SQL Server, PostgreSQL, SQLite, Oracle2.4.7BSD2012-02-01
SPIPMySQL, PostgreSQL, SQLite2.1.12GPL2011-11-17
Squiz CMS (Squiz)PostgreSQLGPL2011-12-08
Squiz Matrix (Squiz)PostgreSQL, Oracle4.6.3GPL2012-02-06
TangoCMSMySQL2.6.1GNU/GPL 22010-11-29
TextpatternMySQL4.4.1GPL2011-06-18
Tiki Wiki CMS GroupwareMySQL9.0LGPL2012-06-26
Tribiq CMSMySQL6.0.3bGPL2012-02-03
TYPO3MySQL, Oracle, PostgreSQL4.7.1GPL2012-05-22
WolfCMSMySQL, SQLite, PostgreSQL0.7.5GPL v32011-04-12
WordPressMySQL3.4.1GPL2012-06-27
Xpress EngineMySQL, Cubrid, PostgreSQL, SQLite, Firebird, MSSQL1.5.1.2LGPL v22012-01-05
XarayaMySQL, PostgreSQL2.2.0GPL2011-07-09
XOOPSMySQL2.5.5GPL2012-04-17
ZikulaMySQL, PostgreSQL, MSSQL, Oracle1.2.8GPL2011-09-09

How to create new block region in Drupal 7

Then following are the steps demonstrate how to create a 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; ?>

Drupal node indexing

How to index a node at time of its creation/modification in Drupal7?

Drupal would not indexing nodes at the time of its creation/modification.
At the time of executing the cron script drupal indexing all the nodes those are yet not indexed.
That is why if we want to search a node in site(at user end) just after its creation/updation we can’t get this node as the node is not indexed.So our objective is indexing node at the time of its creation/updation(means just after saving it into the database).Drupal provides us a hook(hook_node_insert and hook_node_update) which is execute just after node saved into the database and also provide a function(_node_index_node) which can index a node.
So, we just need to add the following functions in any custom module.
/* Implementing hook_node_insert */
function {module_name}_node_insert($node) {
 //calling the the below function to index the current node.
 _node_index_node($node);
}
/* Implement hook_node_update */
function {module_name}_node_update($node) {
 //calling the the below function to index the current node.
 _node_index_node($node);
}
*NOTE: replace {module_name} by your module name.
After adding the above functions if we create/updation any node it will immediately indexed and you are able to get the created node in your search result at user end.