Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Friday, February 22, 2013

Listing current user uploaded brightcove videos in drupal

If you want to list current user uploaded video in drupal, use below code.
Drupal brightcove module provides an option to store the Drupal username of the user who uploaded a video. You need to create this field(custom field) in brightcove before using this feature. Click here to understand how to create cutsom field in BC Studio.


Goto drupal brightcove configuration page and add this field name in "Brightcove Drupal User Custom Field" field. Brightcove module automatically update drupal username in brightcove while uploading new video into video cloud. The below function will fetch all the videos which uploaded by the user.


function video_list(){
  global $user;
 
  // Define our parameters
  $params = array();
  $user_field = variable_get('brightcove_user_field', '');
  // Set our search terms
  $terms = array(
    'all' => $user_field .':'. $user->name
  );
  
  // Make our API call 
  $videos = $bc->search('video', $terms, $params);
  // $videos contains all video which uploaded by the current user
  //write your code for display the result
}

Wednesday, January 30, 2013

How to use brightcove video Search in drupal


Brightcove video cloud, a cloud based video hosting and publishing solution. Drupal is one of the most commonly used open source CMS.

To integrates brightcove video cloud into drupal, drupal community provides one module called Brightcove module. . Using this module you can add Brightcove video to your content and access the information from the Video Cloud in your site.
 In brightcove module they are using Brightcove Media API and this APi provides various methods to retrieve properties from brightcove video cloud. But this module is mainly focusing on find method. So here I am trying to explain how to use search method in drupal. Search method is also a simple function to retrieve properties and information from Brightcove.

To call search method we need to pass three arguments - method, terms and params.Using this method we can search custom fields from brightcove. Here I'm explaining how to search custom fields value from brightcove using search method.

Below code shows how to search for a video with "jobs" in the title AND tags.
 
// Define our parameters
$params = array(
    'video_fields' => 'id,name,shortDescription'
);

// Set our search terms
$terms = array(
    'all' => 'display_name:jobs,tag:jobs'
);
  
 // Make our API call 
$videos = $bc->search('video', $terms, $params);

 Below code will explain how to search video with custom fields. 
custom field name is drupal_user and this field is used for storing uploaded user name(Drupal Username) in brightcove.


// Define our parameters
$params = array(
    'video_fields' => 'id,name,shortDescription'
);

// Set our search terms
$terms = array(
    'all' => 'drupal_user:jobs'
);
  
 // Make our API call 
$videos = $bc->search('video', $terms, $params);



Friday, October 5, 2012

How to create Virtual Hosts in Ubuntu

Virtual Hosting is a method for hosting multiple sites/domains in a single server. It helps to reduce the cost and can share the memory and processor cycle. In local host also we can create Virtual host and we can call original domain name(production/live domain) from our development environment(localhost). Here I am providing the steps for creating Virtual host in Linux/Ubuntu workstation.


i.  Assume your code resides at /var/www/yoursite

ii.  You can access your site using http://localhost/yoursite.

iii.  Edit vhosts file in sites-enabled. sudo gedit /etc/apache2/sites-enabled/vhosts.conf.

iv. Add below code in vhosts file

<VirtualHost *:80>
ServerName local.yoursite.com
ServerAlias www.local.yoursite.com
DocumentRoot /var/www/yoursite
</VirtualHost>
v. Open the file /etc/hosts in your editor.
vi. Add below lines of code.
127.0.0.1   local.yoursite.com
vii. Restart your apache server.
sudo /etc/init.d/apache2 restart
viii. Access http://local.yoursite.com to view your site in direct domain.
 

Saturday, September 1, 2012

How to convert milliseconds to date format in PHP

Normally date field is stored in database as timestamps format, the number of seconds since 00:00:00 UTC on January 1, 1970. Some times the date represented as the number of milliseconds.

There is no default function available in PHP to convert this milliseconds representation to human readable format. In PHP date function is used for converting timestamp format to local date/time format.

This following PHP function will convert milliseconds format to local date format

$milliseconds =  1340562600000;
$timestamp = $milliseconds/1000;
echo date("d-m-Y", $timestamp);

output = 25-06-2012

Monday, July 16, 2012

Find factorial using PHP

Function to find the factorial of the given value



function factorial($val){
  if($val == 1){
    return 1;
  }
  else {
     return $val*factorial($val-1);
   }
}



Friday, July 13, 2012

Redirect all users to access the site with 'www' prefix using htaccess file

We can redirect the site url to "www" prefix, whether the user is accessing the site without "www" prefix by adding rewrite url in .htaccess file in root folder.

add following lines in .htaccess file to add www prefix.

 RewriteEngine on

 RewriteCond %{HTTP_HOST} ^yoursitename\.com$ [NC]

 RewriteRule ^(.*)$ http://www.yoursitename.com/$1 [L,R=301] 


Similarly we can remove "www" prefix from the url and redirect to without "www" by adding following lines in .htaccess file


 RewriteEngine on

 RewriteCond %{HTTP_HOST} ^www\.yoursitename\.com$ [NC]
 RewriteRule ^(.*)$ http://yoursitename
.com/$1 [L,R=301] 


Saturday, October 15, 2011

Top 20 Wordpress plugins and their Drupal equivalent

Wordpress is a popular blogging platform like google blogger. It provides more flexibility than blogger. If you want setup a good looking blog site quickly without knowing more technical stuff, then Wordpress should be the most likely choice for you . It provides a lot of plugins that just enable to activate more user friendly functionalities.

Wordpress is a Content Management System(CMS) build around PHP and MySQL. Like Wordpress, Drupal is also a CMS build around PHP and MySQL with almost all the strengths of Wordpress. But Drupal is more developer centric and customizable and robust when compared to Wordpress and it useful for developing Medium and large Websites, other than just a blog site. 

Due to the huge fanbase and ease of programming, Wordpress has numerous plugins at its disposal. There are Drupal equivalents for most of these. Here is our take on a few popular Wordpress plugins and their equivalent Drupal modules.


1. Akismet - It is a Wordpress plugin that check your comments against the Akismet web service to see if they look like spam or not and lets you review the spam it catches under your blog's "Comments" admin screen.

 Mollom is the Drupal equivalent of Akismet and is a popular spam prevention service module. Drupal version of Akismet module also available

2. All in one SEO pack - Automatically optimizes your WordPress blog for Search Engines (Search Engine Optimization)


 Drupal has several tested and proven modules available in the Drupal core as well as in the contributed section. The most popular ones are

  1. Path – core module
  2. Pathauto
  3. Path redirect
  4. Search 404
  5. Page title
  6. Nodewords ( A new module Metatagsis on development to replace nodewords. Currently there is a quick solution to use Metatags Quick available for Drupal


3. Bad Behavior - It prevents spammers from ever delivering their junk, and in many cases, from ever reading your Wordpress site in the first place.

 Bad Behavior is available for Drupal and it is a set of PHP scripts which prevents spambots from accessing your site by analyzing their actual HTTP requests and comparing them to profiles from known spambots. It goes far beyond User-Agent and Referer, however.

4. Broken Line Checker - It will check your posts, comments and other content for broken links and missing images, and notify you if any are found.

 Link Checker is the Drupal module to detect broken hypertext links.

5. Contact Form 7 - Wordpress plugin that can manage multiple contact forms, plus you can customize the form and the mail contents flexibly with simple markup. The form supports Ajax-powered submitting, CAPTCHA, Akismet spam filtering and so on.

 Drupal has core module for Simple contact us form. Webform can be used to create any type of custom forms. It supports csv export of the collected information. It is also possible to use captcha with webforms.

6. Google Analytics for Wordpress - WordPress plugin allows you to track your blog easily and with lots of metadata.

The Google Analytics module for Drupal incorporates all the features of the Wordpress plugin for Drupal.

7.  Google XML sitemaps for Worpress - This plugin will generate a special XML sitemap which will help search engines to better index your blog.

Drupal has also a Google XML Sitemap module with the same functionality.

8. GTranslate is a Wordpress plugin that provides an automatic translation service to translate your web page with Google power. With the ability to translate over 58 available languages your site will be available to more than 98% of Internet users.

GTranslate for Drupal does the same thing in Drupal and has been coded by the same author.

9. Lightbox Plus is a Wordpress plugin that permits users to view larger versions of images, simple slide shows, videos and content all in an overlay. It uses the popular colorbox jquery plugin.

Colorbox module for Drupal will provide full integration of the colorbox plugin.

10. MapPress is is the most popular and easiest way to create great-looking Google Maps and driving directions in your Wordpress blog.

In Drupal Gmap is the advanced and complete google map solution in Drupal. If you just want a basic google map embedded in a page, use LocationMap or Simplemap as per your requirements.

11. Newsletter is a Wordpress plug-in that lets you collect subscribers on your blog with a single or double opt-in subscription process. Double opt-in is law compliant and it means the user has to confirm the subscription following simple standard instructions sent to him via email.

Simplenews Drupal module - It can be used to send newsletters. Both anonymous and authenticated users can opt-in to different mailing lists. HTML email can be send by adding the Mime Mail module.

12. NextGEN Gallery Wordpress plugin is a fully integrated Image Gallery plugin for WordPress with a slideshow option. Before I started writing the plugin I studied all the existing image and gallery plugins for WordPress. Some of them are really good and well designed, but the gap I filled was a simple administration system at the back end which can also handle multiple galleries.

There are no equivalent ready made solutions available for Drupal, though there are some modules like Fast Gallery available, it will not stand anywhere near the features provided by the nextgen gallery.

The best way to create a custom image gallery in Drupal is to use the content types, image field and views. You can use modules like DDBlock, Views_Slideshow using views and content types.

13. Redirection is a WordPress plugin to manage 301 redirections and keep track of 404 errors without requiring knowledge of Apache .htaccess files.

Path redirect is the popular alternative in Drupal

14. Simple Tags add some tools for taxonomies like Terms suggestion, Mass Edit Terms, Auto link Terms, Ajax Autocompletion, Click Terms, Auto terms, Advanced manage term
In Drupal: By default Drupal taxonomies support tags with auto-complete option. Other features like tagcloud and manage tags can be done using the
  1. Tagadalic For tagclouds
  2. Taxonomy Manager - Manage taxonomies
  3. Community tags - allow users to tag content and track it.
15. Social Plugins - Wordpress comes with the popular social plugins Addtoany and Addthis.

Both of these plugins provide share icons of the popular social bookmarking websites. Add-to-any allows integration with google analytics and Addthis allows customization of the social icons.

Both Addtoany and Addthis are available as modules for installation in Drupal to enhance your social experience while using Drupal

16. WP e-Commerce is a free WordPress Shopping Cart Plugin that lets customers buy your products, services and digital downloads online.

Ubercart is the popular tool for ecommerce applications in Drupal. It is a superior e-commerce solution available when compared to the wordpress equivalent and has tons of features.

17. WP-DB-Backup is a Wordpress plugin that allows you easily to backup your core WordPress database tables. You may also backup other tables in the same database.

In Drupal the Backup and Migrate module (is the best automated backup solution integrated with Drupal.)

18. WP Security Scan is a Wordpress plugin that scans your WordPress installation for any security vulnerabilities.

 Security review is the Drupal module that offers the same functionality will do the same kind of security check for Drupal.

19. WP-Super Cache is a Wordpress plugin that generates static html files from your dynamic WordPress blog. After a html file is generated your webserver will serve that file instead of processing the comparatively heavier and more expensive WordPress PHP scripts.

Boost is the popular alternative in Drupal for static page caching
20. Yet Another Related Posts Plugin (YARPP) gives you a list of posts and/or pages related to the current entry, introducing the reader to other relevant content on your site. 
Similar Entries is the Drupal equivalent module that can do this same task.

Thursday, June 30, 2011

Regular expression for validating US phone number

US phone number format validation using regular expression.

The common US phone number format is 3digits-3digits-4digits
eg: 222-333-3333
      111-222-1234
The regular expression for validating this format is

function usphone($string) {
   if(preg_match('/^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$/', $string)) {
    return true;
  }
  else{
    return false;
  }
}

Validation using Javascript

function isUSphone(phoneno) {
   var filter = /^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$/;
   if (filter.test(phoneno))
        returntrue;
    else
        return false; 
}

In Jquery

if($("#phone-num").val().match(/^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$/)) {
  //valid phone number
}
else {
  //not a valid number
}

*phone-num -  id of phone number field(input field)

Sunday, February 20, 2011

Installing Apache, MySQL and PHP in Linux-Ubuntu

Apache is the most commonly used web server. It is a free open source web server. PHP is an open source server scripting language. It has a lot of advantages. MySQL is also an open source database used for small and medium data storage. It can also used for large data storage also.

We can install apache, PHP and MySQL in two ways. 1. Download source code from their site and install. 2 the easiest way install it from synaptic package manager. If you use this method apt-get automatically manage all dependencies. So I explain the second method here.

1. Open the Terminal from Applications -> Accessories -> Terminal

2. Install apache2 copy paste command to terminal
sudo apt-get install apache2

3. Install PHP5
sudo apt-get install php5 libapache2-mod-php5

4. Restart apache
sudo /etc/init.d/apache2 restart

Now the PHP was installed. To test it create a php page in /var/www/ - the webroot and run it
Example sudo gedit /var/www/hello.php
write a basic php code in it

to run this script type http://localhost/hello.php in your browser and you can see "Hello World" in it.

5. Install mySQL
sudo apt-get install mysql-client mysql-server mysql-query-browser mysql-admin mysql-navigator php5-mysql php5-gd

6. Restart apache
sudo /etc/init.d/apache2 restart 

7. If you need phpmyadmin follow this step. If you like to use MySQL GUI then skip this step
sudo apt-get install phpmyadmin 

Restart apache
sudo /etc/init.d/apache2 restart 

Add following lines in httpd.conf
# Enable PHPMyAdmin
Include /etc/phpmyadmin/apache.conf

To access httpd.conf copy paste following line to terminal

sudo gedit /etc/apache2/httpd.conf

Restart apache
8. If you need to access your url as http://localhost/~username, enable userdir module in apache2. enable mod_rewrite to allow clean url
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/userdir.load
sudo ln -s ../mods-available/userdir.conf
sudo ln -s ../mods-available/rewrite.load
sudo /etc/init.d/apache2 reload

9. Create folder /home/<username>/public_html -- > this is the folder which we are going to use as the document root for local development. So you will be accessing your local websites as http://localhost/~username/sitename

10. Edit /etc/apache2/mods-available/userdir.conf and change the AllowOverride line to just read AllowOverride All
Now you can use public_html as user document root

Enjoy scripting

Common PHP frameworks

Now a days most of the websites are developed by PHP. The main reason is that, it is open source and free software and most of the web servers support PHP. In PHP based web development companies, they are using frameworks for the site development. Because it provides better stability and security for the sites. Also it provide good coding standards and good templates for the sits.

Here I providing a list of good, commonly used PHP based frameworks

1. Drupal (http://drupal.org)

Drupal is the most commonly used PHP framework. It provides better security and stability for the sites. A good development teams for drupal. They are providing security updates and patches in regular interval and more than 3000 contributed modules and themes are available in drupal.
Drupal strictly following PHP coding standard and its provide extensibility and good support. Drupal is used for blog sites, e-commerce site and medium and large websites.
In developer point of view, easy for extend, developer friendly and easy to understand the code.

2. Wordpress (http://wordpress.org)
Wordpress is commonly used for developing blog sites. It provides a lot of good templates for sites. And most of the common blogging functionalities are included in the package.
Now a days most of the blogging sites are uses wordpress as their back end.

3. joomla (http://www.joomla.org)
joomla is also a php based framework. It is commonly used for organizations and institutions websites. Joomla gives a lot of beautiful templates. It has vibrant volunteer community, that help you to build good web sites.

4. Cake PHP (http://cakephp.org)
Cake PHP is fee open source, rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications.
It Using MVC architecture for the development. So developer need to write a less code.

5. Zend Framework (http://framework.zend.com/)
Zend, the PHP based most featured framework. It's the most old and well-known framework. Zend Framework has hundreds of contributors and users number in the hundreds of thousands.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Maintained by Web Themes