All posts by admin

Install & Add New Site Into Your Nginx-based Ubuntu (14.04) Server

step-1

Install Nginx

sudo apt-get update
sudo apt-get install nginx

Step-2

Check Nginx Status

sudo service nginx status

If you get message from your terminal that “nginx is not running” then start it by the following commend line.

sudo service nginx start

If start successfully then you will get this message from your terminal “Starting nginx: nginx.”

Step-3

Configure Server

Open up the virtual host file you need to make some change within.

sudo nano /etc/nginx/sites-available/default

We need to make a couple of changes in these few lines:

server {                               
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /usr/share/nginx/www;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {

                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.php;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }

        location = /50x.html {
                root /usr/share/nginx/www;
        }

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        location ~ /\.ht {
                deny all;
        }
}

Restart nginx and make the changes visible.

sudo service nginx restart

Step-4

Goto your browser in address bar type “localhost” and hit enter. If you get welcome message then nginx will work successfully.

Step-5

Install phpmyadmin

sudo apt-get install phpmyadmin

we simply need to copy the phpmyadmin into a new custom directory’

sudo ln -s /usr/share/phpmyadmin /usr/share/nginx/www
sudo php5enmod mcrypt

Restart php5-fpm and make the changes visible.

sudo service php5-fpm restart

Step-6

Goto your browser in address bar type “localhost/phpmyadmin” and hit enter. If you get phpmysql interface then phpmysql will work successfully.

Step-7

Site Create

We need to create a new file called index.html within the directory.
Here “your-pc-name” replace with your pc name.

mkdir -p /home/your-pc-name/www/example.com/public_html
sudo nano /home/your-pc-name/www/example.com/public_html/index.html

We can add some text to the file so we will have something to look at when the the site redirects to the virtual host.

<html>
  <head>
    <title>www.example.com</title>
  </head>
  <body>
    <h1>Success: You Have Set Up a Virtual Host</h1>
  </body>
</html>

we simply need to copy the default file text into a new custom example.com file:

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com

Open up the virtual example.com file you need to make some change within.

sudo nano /etc/nginx/sites-available/example.com

We need to make a couple of changes in these few lines:

server {
	listen 80; ## listen for ipv4; this line is default and implied

	#here <strong>"your-pc-name"</strong> replace with your pc name
	root /home/your-pc-name/www/example.com/public_html;

	index index.php index.html index.htm;

	# Make site accessible from http://localhost/
	server_name example.com;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to index.html
		try_files $uri $uri/ /index.php;
		# Uncomment to enable naxsi on this location

		# include /etc/nginx/naxsi.rules
	}

	location /doc/ {
		alias /usr/share/doc/;
		autoindex on;
		allow 127.0.0.1;
		deny all;
	}

	location = /50x.html {
		root /usr/share/nginx/www;
	}

	location ~ \.php$ {
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		fastcgi_index index.php;
		include fastcgi_params;
	}

	location ~ /\.ht {
		deny all;
	}
}

we simply need to copy the example.com text from sites-abailable directory to sites-enabled directory

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com

open up your hosts file.

sudo nano /etc/hosts

You can add the local hosts details to this file, as seen in the example below. As long as that line is there, directing your browser toward, say, example.com will give you all the virtual host details for the corresponding IP address.

127.0.0.1 localhost
127.0.0.1 example.com

Restart nginx and make the changes visible.

sudo service nginx restart

Now go to your browser address bar and type example.com and hit enter. You will get your index.html file interface.

Ribbon Css

<div class="ribbon-wrap">
    <div class="ribbon">
        Ribbon Text
    </div>
</div>
.ribbon-wrap {
    background: #809E9B;
    height: 180px;
    margin: auto;
    overflow: hidden;
    position: relative;
    top: 0;
    width: 251px;
}
.ribbon-wrap .ribbon {
    background-color: #ABD065;
    background-image: linear-gradient(to bottom, #BFDC7A, #8EBF45);
    background-repeat: repeat-x;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
    color: #4B4B4B;
    font-size: 12px;
    font-weight: bold;
    left: -69px;
    padding: 4px 0;
    position: relative;
    text-align: center;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
    top: 57px;
    transform: rotate(-47deg);
    width: 251px;
}

 

Paypal Payment Gateway For WordPress

Paypal payment gateway processing steps are

  1. Send data form your website to paypal
  2. Paypal process your data and return payment information
  3. Send again payment information to paypal for IPN validation
  4. Paypal again return IPN validated status, if status true then insert payment informationin in your database

Step1: Send data form your website to paypal

Sending data arguments are
$paypal_args = array(
    'cmd' => '_xclick',
    'amount' => 50,
    'business' => 'your paypal email. User will be payment this account',
    'item_name' => 'test',
    'item_number' => 20,
    'email' => 'payer email. who is send money to your business account',
    'no_shipping' => '1',
    'no_note' => '1',
    'currency_code' => 'USD',
    'charset' => 'UTF-8',
    'custom' => json_encode( array( 'user_id' => 1, 'product_id' => 20 ) ),
    'rm' => '2',
    'return' => 'www.example.com/paypal.php',
    'notify_url' => 'www.example.com/success_message',
    'cbt' => sprintf( __( 'Click here to complete the payment on %s', 'wpuf' ), get_bloginfo( 'name' ) )
);

//paypal url
if( sandbox ) {
    $paypal_url = 'https://www.sandbox.paypal.com/webscr/';
} else {
    $paypal_url = 'https://www.paypal.com/webscr/';
}

$paypal_url = $paypal_url . '?' . http_build_query( $paypal_args );

wp_redirect( $paypal_url );<br>exit;

 

Step2: Paypal process your data and return payment information
Step3: Send again payment information to paypal for IPN validation

www.example.com/paypal.php

 // Get recieved values from post data
$ipn_data = (array) stripslashes_deep( $_POST );
$ipn_data['cmd'] = '_notify-validate';

// Send back post vars to paypal
$params = array(
    'body' => $ipn_data,
    'sslverify' => false,
    'timeout' => 30,
    'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
);

//paypal url
if( sandbox ) {
    $paypal_url = 'https://www.sandbox.paypal.com/webscr/';
} else {
    $paypal_url = 'https://www.paypal.com/webscr/';
}

$response = wp_remote_post( $paypal_url, $params );

//Step4: Paypal again return IPN validated status, if status true then //insert payment informationin in your database

if ( !is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && (strcmp( $response['body'], "VERIFIED" ) == 0) ) {
    return true;
} else {
    return false;
}

 

 

Paypal Payment Gateway

Paypal payment gateway processing steps are

  1. Send data form your website to paypal
  2. Paypal process your data and return payment information
  3. Send again payment information to paypal for IPN validation
  4. Paypal again return IPN validated status, if status true then insert payment informationin in your database

Step1: Send data form your website to paypal

Sending data arguments are
$paypal_args = array(
    'cmd' => '_xclick',
    'amount' => 50,
    'business' => 'your paypal email. User will be payment this account',
    'item_name' => 'test',
    'item_number' => 20,
    'email' => 'payer email. who is send money to your business account',
    'no_shipping' => '1',
    'no_note' => '1',
    'currency_code' => 'USD',
    'charset' => 'UTF-8',
    'custom' => json_encode( array( 'user_id' => 1, 'product_id' => 20 ) ),
    'rm' => '2',
    'return' => 'www.example.com/paypal.php',
    'notify_url' => 'www.example.com/success_message',
    'cbt' => 'your blog name'
);

//paypal url
if( sandbox ) {
    $paypal_url = 'https://www.sandbox.paypal.com/webscr/';
} else {
    $paypal_url = 'https://www.paypal.com/webscr/';
}

$paypal_url = $paypal_url . '?' . http_build_query( $paypal_args );

header( "location:$paypal_url" );
 Step2: Paypal process your data and return payment information
Step3: Send again payment information to paypal for IPN validation

www.example.com/paypal.php

// Get recieved values from paypal post data
foreach( $_POST as $key => $value ) { 
   $params[$key] = stripslashes( $value ); 
}
$params = http_build_query( $params, null, '&' );

//paypal url
if( sandbox ) {
    $paypal_url = 'https://www.sandbox.paypal.com/webscr/';
} else {
    $paypal_url = 'https://www.paypal.com/webscr/';
}

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $paypal_url);
curl_setopt($ch,CURLOPT_POST, count($params));
curl_setopt($ch,CURLOPT_POSTFIELDS, $params);

//execute post
$response = curl_exec($ch);

//close connection
curl_close($ch);

//Step4: Paypal again return IPN validated status, if status true then insert payment informationin in your database

if ( $response == 'ok' && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && (strcmp( $response['body'], "VERIFIED" ) == 0) ) {
    echo 'Payment successfully you may insert payment information in your database';
} else {
    echo 'Error';
}

 Remember, IPN validation in your localhost always return false. You have to test IPN validation in your server site.

WordPress File Upload Process

This function has created for wordpress file uploading . You can easily upload your file with the help of this function.

function file_upload() {
    $upload = array(
        'name' => $_FILES['file']['name'],
        'type' => $_FILES['file']['type'],
        'tmp_name' => $_FILES['file']['tmp_name'],
        'error' => $_FILES['file']['error'],
        'size' => $_FILES['file']['size']
    );

    header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );

    $attach = handle_upload( $upload );

    if ( $attach['success'] ) {
        echo 'Successfully upload your file';
    } else {
        echo 'Fail to upload your file';
    }
}
function handle_upload( $upload_data ) {

    if ( ! function_exists( 'wp_handle_upload' ) ) {
       require_once( ABSPATH . 'wp-admin/includes/file.php' );
    }

    $uploaded_file = wp_handle_upload( $upload_data, array('test_form' => false) );

    if ( isset( $uploaded_file['file'] ) ) {
        $file_loc = $uploaded_file['file'];
        $file_name = basename( $upload_data['name'] );
        $file_type = wp_check_filetype( $file_name );
        $post_title = preg_replace( '/\.[^.]+$/', '', basename( $file_name ) );

        $attachment = array(
            'post_mime_type' => $file_type['type'],
            'post_title' => $post_title,
            'post_content' => '',
            'post_status' => 'inherit'
        );

        include( ABSPATH . 'wp-admin/includes/image.php' );
        $attach_id = wp_insert_attachment( $attachment, $file_loc );
        $attach_data = wp_generate_attachment_metadata( $attach_id, $file_loc );
        wp_update_attachment_metadata( $attach_id, $attach_data );
        return array('success' => true, 'attach_id' => $attach_id);
    }

    return array('success' => false, 'error' => $uploaded_file['error']);
}

 

WordPress Email Sending Configuration

WordPress email sending configuration for Bcc (Blind carbon copy).  If you want to send Cc (carbon copy) then change the first line as

$type = 'Cc: User <user@example.com>, Another User <anotheruser@example.com>';

Does not use to Bcc or Cc then remove the first line as

$type = 'Bcc: User <user@example.com>, Another User <anotheruser@example.com>';

here if full code

$type = 'Bcc: User <user@example.com>, Another User <anotheruser@example.com>';
$admin_email = get_option( 'admin_email' );
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$reply = 'no-reply@' . preg_replace( '#^www\.#', '', strtolower( $_SERVER['SERVER_NAME'] ) );
$reply_to = "Reply_To: <$reply>";
$content_type = 'Content-Type: text/html';
$charset = 'Charset: UTF-8';
$from = "From: $blogname <$reply>";
$subject = 'test';
$message = 'Hi, how are you?';

$headers = array(
    $type,
    $reply_to,
    $content_type,
    $charset,
    $from
);
wp_mai( $admin_email, $subject, $message, $headers);

 

PHP autoload

PHP Autoload Usage:

Suppose you have a lot of php file in “my-class” directory. Each file contain php class. You want to call those class from other php file which is out of “my-class” directory. In this case the better way to use php autoload.

function autoload( $class ) {
    $directorys = array();

    //assing your php file directory which file containg your class
    $directorys = array(
        dirname(__FILE__) . '/your-class-directory',
    );

    if( ! count( $directorys ) ) {
        return;
    } 

    foreach( $directorys as $directory ) {

        if( ! is_dir( $directory ) ) {
            echo $directory .' Direcotry is not exist';
            continue;
        }

        if ( ! ( $handle = opendir( $directory ) ) ) {
            echo 'Fail to open your directory. Please check your directory permission';
            continue;
        }

        while ( false !== ( $entry = readdir( $handle ) ) ) {

            if ( $entry != "." && $entry != "..") {

                $file = $directory .'/'. $entry;
                $contents = file_get_contents( $file );
                $contents = str_replace( ' ', '', $contents ); 
                $contents = strtolower( $contents );
                $search = 'class'.$class.'{';

                if ( strpos( $contents, $search ) !== false ) {
                    require_once $directory .'/'. $entry;
                }
            }   
        }
        closedir( $handle );  
    }    
}

spl_autoload_register( 'autoload' );

 

Shortcode for drupal mp3 player

Shortcode Installation:

This shortcode Installation is like with all normal drupal modules:
extract the ‘mishu_swf.zip’
modules directory from your website (typically sites/all/modules).
go to modules find swf_tools_mod and active it

Shortcode Featur:

1. Shortcode for display mp3 player
2. mp3 player display inline
3. Customize play and sotp icon
4. Use multiple mp3 player
5. In the case of multiple player when you play one others will be pause automatically

Shortcode Usage:

Use shortcode in your post editor like [mishu_swf file=”sites/default/files/01.mp3″]
your short code name must be mishu_swf.
file is the parametar which is contain the mp3 file location
Download shortcode for drupal mp3 player
Hope you like drupal mp3 shortcode.