Sending Push Notification in Drupal with your plugin

It is difficult to implement even simple features in Drupal. Luckily Drupal is one of the CMS which have the largest number of plugins (modules). For implementing push notification feature, there are some good plugins available. We are selecting one plugin from the module gallery and will try to implement the push notification feature for our custom developed module.

Drupal’s “Push Notifications” Module

The module “Push Notifications” will help us to do the push notifications and device registrations for us. You can find and download the module at Drupal website. The module supports:

  1. Apple Push Notification Service (APNS)
  2. Google Cloud Messaging (GCM) and
  3. Cloud 2 Device Messaging (C2DM).

 How to Implement Push Notification Module?

Login to your admin panel and install your module. Follow the steps given below:

  1. Login to your admin panel.
  2. Go to your admin page:
  3. In the field “Install from a URL”, use the following URL: (you can find the latest version from the module page).
  4. Click on “Install” button.
  5. If everything works fine, you will get a message like “Installation was completed successfully.”
  6. Click on the “Enable newly added modules” link to go to the modules listing page.
  7. Go down to the page to see the “Push Notifications” plugins under “Others” category.
  8. Check the enabled column and save the configurations. Your push notification module is enabled now.
  9. Add the certificates and key in the page: Configuration > Web Serivces > Push Notifications > Configuration. For APNS certificate, click on “Generate new certificate string” button, rename your certificates to the displayed names and upload to the sites/all/modules/push_notifications/certificates folder.
  10. After saving your settings, you can test messages to the registered devices from “Send Push” tab.

Configure your module to add the dependency

Since your module is going to use push_notifications module, you have to add dependency for the module. The push_notifications module itself is dependent to the  services, so your module is dependent to both services and push_notifications. After adding dependency, your module info file will look like:

Send Push Notifications from your custom module

Now you can use the push_notifications module to send messages from your custom module. The below example will send a message to the node user when someone comments on the node.

There are many other useful functions in the push_notifications module. You can find more details about the module in our article: Drupal Push Notifications Module’s Functions List (API Manuel).

Drupal Push Notifications Module’s Functions List (API Manuel)

The goal of this article is to give developers’ awareness about the functions included in the push notification module that can be used for your Drupal module development. There are around 20 functions available in the push notification module from which I am selecting 6 functions that can be used for your module to send notifications to APNS and GCM/C2DN services:


This function is the most valuable, which can be used to send push notification messages to selected users. The function sends messages to both Android and iPhone devices. There are two parameters for this message: the first parameter accepts the user IDs as an array; the second parameter accepts the message.

Usage in your module:


This function will get all registered tokens either for Android or iPhone devices. The function accepts three parameters: the device type id, a particular language based registered tokens, the return format – as raw token value array or as token object.

Note: The default type ids’ are: 0 – Apple; 1 – Android.

You have to use only the first parameter if you are not using any specific languages for your applications. Usage:


This function will help you to get all devices registered under a particular user. The function accepts User ID and returns the device tokens for both Apple and Android devices.

Usage in your module:


The function will send messages to the tokens given through the Apple Push Notification Service. The function accepts two parameters: Array of IOS tokens; The payload array to send message.

Make sure that you pass your payload in the correct array format. A valid format of the payload with custom data is given below:


This function will send a message to the Android devices through the Google Cloud Messaging service by accepting Android device tokens. The parameters are same as the previous method. The payload format is slightly different from the APNS function.

A valid payload format is:


The application of this function is same as the previous function. The only difference is that this function will use the Android Cloud to Device Messaging service instead of GCM. The two parameters and its formats are the same like the previous function.

Note: For implementing push notification in your custom module, please read the article: Sending Push Notification from your Drupal Module.

How to make your Linux Apache run under a particular user

It is common to see errors like: “permission denied”, that you can see in your applications after uploading the code to your Linux server. You can simply change many of these errors by providing the proper permissions to apache running on your server.

To change the apache running user, execute the below command and open the file with vim:

Look through the file contents and modify the lines which resembles like:

Replace the “www-data” in the first line to your username and for second line, replace with your user’s group name.

Save the file with VIM commands. For more details about VIM commands, please click here.

Restart the server by executing the following command:

Now, you can see that your application will run without permission errors.

Note: The whole article is written by assuming that you uploaded all your files to a user owned folder.

Sending email from your Codeigniter application with Gmail SMTP

With the Codeigniter’s default email library, we can send email through our Gmail account. This will help us to avoid spam mails, generating from the Codeigniter application.

1. Create GMAIL Configuration for the email configuration

You only have to take care of your email configuration to implement email sending properly for your application. Open your  application/config/config.php file and add the following lines of code at the end of your config file:

2. Create a function to send email from your Codeigniter application

You can create this function as a helper or library according to the usage. I am here, creating the function as a private method in the controller, assuming only one controller will share this email function. The method code is as follows:

3. Call the function and use HTML template for the email

We created the configuration to send HTML emails. So you have to create a view file that holds the complete HTML for the email template. You can create PHP variables in the file and pass dynamic values from the controller. Create a sample email template as below:

Save the file at:  application/views/email.php. In your controller page function, use the following code to initialize the email body and send the email:

Make sure that your computer is open to the port 465. Hopefully you will receive an email from your gmail account. There is chance that the email generating from your application can be considered as insecure, and the gmail will block your access. Login to your gmail account and turn on the less secure app configuration to allow insecure applications to access gmail SMTP.

How to create a new branch in the GIT file repository

It is a common practice that you have to create a new branch for developing the new sprint (agile based development) or a new development phase. With GIT repository, it is very easy to create and work with new branch as you go.

Note: For windows developers, use CygWin for the command console. This will help you to create a virtual Linux like environment in windows system. Continue reading How to create a new branch in the GIT file repository

Install FTP for your Dedicated or Cloud Ubuntu Server

There are many ways to install FTP for Linux server, but there is a preferred way to install FTP on Ubuntu servers.

About FTP

FTP works on a client/server model which transfers file’s data in between as File Transfer Protocol (FTP). The server component in Linux is called an FTP daemon. The FTP helps us to transfer files from the client system to the server. The FTP also can be secured like HTTPS, which will transfer files through the network in a more secure way.

Access to an FTP server can be in two ways: Anonymous and Authenticated. In the Anonymous mode, clients can access the FTP server by using the default user account called “anonymous”. In the Authenticated mode a user must have an account and a password. Continue reading Install FTP for your Dedicated or Cloud Ubuntu Server

MySQL Delete Statement – Confusing Syntax Error when writes in one line

While writing mysql statements in your procedure, you may notice that the workbench will give you a syntax error warning when you states an error free delete statement as below:

The solution is simple, you have to split your statement in two lines. I was not able to find any document which specifies this scenario, but on every document, the delete statements are split into two lines. So the previous statement can be inserted to your procedure as:

Hope you enjoyed this tip. Please give you feedback as comments below.

Assign Variable Value from SELECT query for MySQL Procedure

You may be familiar with MySQL, and this article could be a known factor for you.  But many times, we miss the basics and ends up in approaching complex ways for simple things. This article is about a simple fact that we can miss while implementing a mysql procedure.

How to assign a variable?

In mysql we assign variable with the simple set  statement. Declaration of variable must be preceded before assigning the value (not necessary). A simple set statement is as follows:

 Assign SELECT query value to a variable

We can assign a variable in two ways. The first way is to use the set statement.

The same result can be achieved without the declaration.

You can do the same with SELECT... INTO  statement.


Basic Codeigniter Active Record Knowledge

Following information will give you an idea about how you can use the codeigniter active record class in your models.

You have to initialize your database in your model constructor with

Select Data

You can make a simple select query like:  SELECT * FROM table_name  with the following:

A select query with where condition:

For selecting a single row from a table with the codeigniter active record class:


Looping Data

The result()  method gives you the result as an array of objects. You can parse through the array as normal. Following are the usual two scenarios for the looping:

Insert, Update and Delete with Codeigniter Active Records

Use insert()  method for SQL insertion operation.

Update operation is same like insertion. The update()  method has a third parameter as where condition with which the updating rows will be selected.

Delete method delete()  is also same as the previous two methods. Here, the second parameter is the where clause which used to select the deleting rows.

For more details, please read through the official codeigniter user guide.