Saturday, 10 December 2011

How to create a Static Block in magento

video-tutorial will help you create static block in magento backend.
And call backend static block to frontend .phtml file.

Create main menu in magento

Create navigation menu in magento

Friday, 28 October 2011

Facebook login in drupal

In drupal Facebook connect module used to add Facebook login.

This module also used for twitter login.

This video show the basic integration of Facebook connect module in drupal

 
INSTALLATION

1.  Copy facebook connect module to sites/all/modules folder

2. Create new facebook app in this url https://developers.facebook.com/apps

3. Download php-sdk libraries from  http://github.com/facebook/php-sdk/tarball/v2.1.1

4. Copy this php-sdk to facebook connect module folder
   <fbconnect folder>/facebook-php-sdk/src/facebook.php
5.Enable fbconnect module

6. Enter facebook app key and id in admin/settings/fbconnect page.
 

Tuesday, 25 October 2011

Upload file extension restriction in jquery

Image upload field only accept following extension gif, png, jpg,jpeg.
<form action="" method="post" enctype="multipart/form-data">
Upload Image:<input type="file" name="image" id="image_id"  />
</form>
following code used to limit the upload file extension
<script type="text/javascript">
$(function() {
   $('#image_id').change( function() {
    var ext = $('#image_id').val().split('.').pop().toLowerCase();
    if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) {
      $('#image_id').val("");
        alert('Please Enter the files in the format jpeg,gif,png');
       
    }
   });
});
</script>

Sunday, 23 October 2011

Create node theme for content type in drupal

The node.tpl.php is a default theme for all nodes.
If need to change node theme for specific content type follow following steps

1. If u create node theme for page content type, create node-page.tpl.php in your template folder.
2. Copy node.tpl.php to node-page.tpl.php , Importent do not delete default node.tpl.php file
3. Change the theme display for your needs
4. Use variables node.tpl.php
5. If u create node theme for movie page content type, create node-movie_page.tpl.php file.

For more: Theming node by content type

Saturday, 22 October 2011

How delete own comment in drupal

In Drupal user can not delete own comment
So need Comment Delete module.
  1. Unzip and copy this module in sites/all/modules folder.
  2. Enable comment delete module.
  3. Enable required permission in user permission page

How add facebook like button


1. Create your App in facebook https://developers.facebook.com/apps

2.Copy and paste following code in your site after opening body tag and enter your App id
<script>
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=YOUR APP ID";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
3.Paste following code in which place you need like button
<div class="fb-like" data-href="http://phpand.blogspot.com/" data-send="true" data-width="450" data-show-faces="true" data-font="arial"></div>
4. For more refer https://developers.facebook.com/docs/reference/plugins/like/

Friday, 21 October 2011

How create facebook login

1. Go https://developers.facebook.com/apps and click create new App

2. After create your App, you get App ID/API Key and App Secret code.



3. Enter your website name to include Facebook login


4.Add following code in your login page
<html>
    <head>
      <title>My Facebook Login Page</title>
    </head>
    <body>
      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
            appId      : 'YOUR_APP_ID',
            status     : true, 
            cookie     : true,
            xfbml      : true
          });
        };
        (function(d){
           var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
           js = d.createElement('script'); js.id = id; js.async = true;
           js.src = "//connect.facebook.net/en_US/all.js";
           d.getElementsByTagName('head')[0].appendChild(js);
         }(document));
      </script>
      <div class="fb-login-button" data-perms="email,user_checkins">
        Login with Facebook
      </div>
    </body>
 </html>

5.For more https://developers.facebook.com/docs/guides/web/

Monday, 17 October 2011

How get current username in drupal

Following code used to get current username
<?php
       global $user;
       print_r($user->username);
?>

To get user details
<?php
       global $user;
       print_r($user);
?>

Saturday, 15 October 2011

Create user gallery in drupal

Following module used for create user photo gallery
  1. Views
  2. CCK
  3. Image field
  4. Nodereference_url
  5. Views_attach
  6. CSS_injector

Wednesday, 12 October 2011

Create facebook share URL

Share your article in Facebook following code is used

<a href="http://www.facebook.com/sharer.php?u=<url to share>
&t=<title of content>" target="_blank"> link or image</a>
  • url to share – what URL  you want to share to Facebook
  • title of content – the title of what you are sharing
<a name="fb_share" type="button" 
   share_url="YOUR_URL">Compartir en Facebook</a> 
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" 
        type="text/javascript">
</script> 
For more http://developers.facebook.com/docs/share/

Tuesday, 11 October 2011

find odd or even number in php

If number divided by 2 and remainder is zero , that number is even number.
8 is divided by 2 and reminder is zero , this is even number
8/2 = 4
4/2 = 2
2/2 = 0 (remainder)

5 is odd number

5/2     = 2.5
2.5 /2 = 1.25 (remainder)


if remainder = 0 , that number is even number

In php % (Modulus result is Remainder of $a divided by $b ) operator used to find remainder value

<?php

if (($i % 2) == 0 ) {
  echo "$i is even";
} else {
  echo "$i is odd";
}

?>
Another method to find odd or even number in php, by using Logical AND operator
<?php

function is_odd($num)
{
  return( $num & 1 );
}

if (is_odd(8)) {
    echo "8 is odd";
} else {
    echo "8 is even";
}

Output: 8 is even 

?>
Number 8 binary value is 1 0 0 0
number 1 binary value is  0 0 0 1
AND                              ---------
                                    0 0 0 0

return false so output is 8 is even 

Thursday, 6 October 2011

Print array values in php


To print array values following method are used. For your need use correct method

This code will display the text "apple"

$fruit[0] = "apple";
$fruit[1] = "banana";
$fruit[2] = "orange";
echo $fruit[0]; 


This display all elements in the array. but u need to count a array

for ($i=0;$i<=2;$i++){
    echo $fruit[$i]; 
}

Using count array

$count = count($fruit);
for ($i=0;$i<=$count;$i++){
    echo $fruit[$i];
}

This is a best way to display all the element in the array

foreach ($fruit as $value){
    echo $value;   
}

Difference between get and post method


Get and Post Method used for pass data to data processing page, and are used for form data handling.

GET
POST
Get method transfer data through URL 
http://www.phpand.blogspot.com/index.php?fname=phpand&age=20
In post method data transfer will not appear in the browser
Get method have character restriction depends on browser. In old browser URL length is very less. 
Post method is no limit. The post method depends on post_max_size in the php.ini file
Get method data will be visible for every one(displayed in the browser's address bar)
Post data not visible and secure.
Get method data transfer speed is high
Data transfer speed is less.

Phone number validation in php


In phone number validation mostly php regular expression was used.

Example1  91-9874563210
if(ereg("^[0-9]{2}-[0-9]{10}$", $phone_number)) {
      echo "valid phone number";
}
else {
       echo "invalid phone number";
}


Example2  555-655-7516
if(ereg("^[0-9]{3}-[0-9]{3}-[0-9]{4}$", $phone_number)) {
       echo "valid phonenumber";
}
else {
      echo "invalid phonenumber";
}
  

Differencce between strstr and stristr function


strstr and stristr are the same functionalites that used to find the first occurrence of the string.
Difference is strstr is used to find the first occurrence of the string with case sensitive but stristr is used for case-insensitive searches.

Syntex:
strstr($string , $needle string , $before needle);
$before needle :
If TRUE, strstr() returns the part of the haystack before the first occurrence of the needle.

Example :
<?php
    $email  = 'name@example.com';
    $domain = strstr($email, '@');
    echo $domain; // prints @example.com

    $user = strstr($email, '@', true); // As of PHP 5.3.0
    echo $user; // prints name
?>

Wednesday, 5 October 2011

Show page only for owner in elgg

In elgg tool following page pg/friends/user_name only display only owner.

For example logged in user name is john he will access pg/friends/john page and he will not access pg/friends/balaji page.

This done by using following code
if($_SESSION['user']->guid != page_owner()){
       forward($_SERVER['HTTP_REFERER']);
}  

Tuesday, 4 October 2011

Find second max salary in MySQL

To find max second salary without using sub-query
SELECT salary FROM `salary_table` GROUP BY `salary` DESC LIMIT 1 , 1;

By using sub-query, get all second salary records
SELECT max(salary) FROM `salary_table` WHERE salary = (SELECT max(salary)FROM `salary_table`);

Find register actions in elgg

In elgg to find your plugins register action , to use the following code
global $CONFIG;
echo "<pre>";
print_r($CONFIG->actions);

Difference between htmlentities and htmlspecialchar

htmlentities         — Convert all applicable characters to HTML entities.
htmlspecialchars — Convert special characters to HTML entities.

Monday, 3 October 2011

Add captcha in elgg form

If you need to add captcha  in your form, to follow the below steps

Step 1:

In your form add captcha image and text box
$form_body .= elgg_view('input/captcha');

Step 2:

There two method used to check the capcha

Method 1
Open mod/capcha/start.php and
add your action name in $retrunvalue[] array

function captcha_actionlist_hook($hook, $entity_type, $returnvalue, $params)
    {
        if (!is_array($returnvalue))
            $returnvalue = array();
           
        $returnvalue[] = 'register';
        $returnvalue[] = 'user/requestnewpassword';
        $returnvalue[] = 'your action name';
           
        return $returnvalue;
    }

Method 2

In your module form action file call the captcha_verify_action_hook
captcha_verify_action_hook();

Sunday, 2 October 2011

Add syntax highlighter in drupal

<?php 
if(ereg("^[0-9]{2}-[0-9]{10}$", $phone_number)) {
      echo "valid phone number";
}
else {
       echo "invalid phone number";
}
?>

To activate syntax highlighter in your drupal site to follow the below steps

1. Download syntax highlighter module to following link http://drupal.org/project/syntaxhighlighter
    and extract to sites/all/modules directories

2. The module required following Syntax highlighter javascript library
     download and  extract sites/all/libraries directories

3. Now enable Syntax highlighter module

4. Enable the Syntaxhighlighter filter in an input format Site configuration > Input formats > Configure




5. Go to admin/settings/syntaxhighlighter to configure syntaxhighlighter module


6. If u need to highlight code to use following pre tag

<pre class="brush: js; highlight: [1, 5]; html-script: true">
     your javascript and html code here
</pre>

<pre class="brush: php; highlight: [1, 5]; html-script: true">
      your php and html code here
</pre>

 highlight: [1, 5] is used to highlight the code lines 1 and 5


Wednesday, 28 September 2011

In operator in mysql

If you want to select id values of 1,2,3 in same query we use IN operator in MySQL


Table Name : user

Id    LastName
1      Value1 
2      Value2
3      Value3 
4      Value4


SELECT * FROM `user` WHERE `Id` =1;

Id    LastName
1       Value1

It select only one value.

By using IN operator

SELECT * FROM `user` WHERE `Id` IN ('1','2','3');

Id    LastName
1      Value1 
2      Value2
3      Value3

SELECT * FROM `user` WHERE `Id` IN ('1','2','10');

In this query Id 10 is not in the table user

So output like this


Id    LastName
1      Value1 
2      Value2


Tuesday, 27 September 2011

Hide after current date in jquery datepicker


If use date picker for Date of birth, need to hide after current date in date picker.
In jquery date picker maxDate is user to hide the dates after current date.

Assign maxDate to current date.

<script type="text/javascript">
<!--

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()

$(document).ready(function(){
    $('#DOB1').datepick({
    yearRange: '-90:+10',
    dateFormat: 'mm/dd/yyyy',
    maxDate: 'month/day/year',
    altField: '#DOB1_alt',
    showTrigger: '<img src="images/calendar.gif" alt="Popup" class="trigger">',
    onSelect: function(dates) {
        
    var date = dates[0];
    $('#DOB1_alt').val(date);
    }
    });
    });  

//-->
</script></div>

Monday, 26 September 2011

How get elgg base path

In elgg the global config variable is used
following code is used to get elgg base path

<?php
  global $CONFIG;
  echo $CONFIG->path;
?> 

Sunday, 25 September 2011

Remove submitted by admin in drupal

move the following global setting page in admin
Site bulding -> Themes -> Configure -> Global settings
Disable Post information in "Display post information on"

Friday, 16 September 2011

Product image upload problem in magento 1.6


1. Download prototype.js version 1.6.0.3
2. Go to Magento/js/prototype –  here rename prototype.js with old_prototype.js
3. Then copy downloaded prototype.js in Magento/js/prototype
4. In the /app/etc/config.xml file change the initStatements node from:

<initStatements>SET NAMES utf8</initStatements>
to:
<initStatements>SET NAMES utf8; SET FOREIGN_KEY_CHECKS=0; SET UNIQUE_CHECKS=0;</initStatements>

Flush the cache and then you can upload image for products.

Reference: http://blog.magentoconnect.us/image-upload-problemissue-magento-1-6/

Wednesday, 14 September 2011

Remove Riverdashboard "All" tab in elgg

Follow below 2 steps to remove "All" tab in elgg riverdashboard

Setp 1:

Open the nav.php file in riverdashboard plugin
>> elgg-root\mod\riverdashboard\views\default\riverdashboard\nav.php
$allselect = '';
$friendsselect = '';
$mineselect = '';
switch($vars['orient']) {
    case '':
        $allselect = 'class="selected"';
        break;
    case 'friends':
        $friendsselect = 'class="selected"';
        break;
    case 'mine':
        $mineselect = 'class="selected"';
        break;
}

?>

<?php
if (isloggedin()) {
?>
    <div id="elgg_horizontal_tabbed_nav">
        <ul>
            <li <?php echo $allselect; ?> ><a onclick="javascript:$('#river_container').load('<?php echo $vars['url']; ?>mod/riverdashboard/?content=<?php echo $vars['type']; ?>,<?php echo $vars['subtype']; ?>&amp;callback=true'); return false;" href="?display="><?php echo elgg_echo('all'); ?></a></li>
            <li <?php echo $friendsselect; ?> ><a onclick="javascript:$('#river_container').load('<?php echo $vars['url']; ?>mod/riverdashboard/?display=friends&amp;content=<?php echo $vars['type']; ?>,<?php echo $vars['subtype']; ?>&amp;callback=true'); return false;" href="?display=friends"><?php echo elgg_echo('friends'); ?></a></li>
            <li <?php echo $mineselect; ?> ><a onclick="javascript:$('#river_container').load('<?php echo $vars['url']; ?>mod/riverdashboard/?display=mine&amp;content=<?php echo $vars['type']; ?>,<?php echo $vars['subtype']; ?>&amp;callback=true'); return false;" href="?display=mine"><?php echo elgg_echo('mine'); ?></a></li>
        </ul>
    </div>
<?php
}
?>



Remove above lines and paste following lines in nav.php file

$friendsselect = '';
$mineselect = '';
switch($vars['orient']) {
    case '':
         $friendsselect = 'class="selected"';
        break;
    case 'friends':
        $friendsselect = 'class="selected"';
        break;
    case 'mine':
        $mineselect = 'class="selected"';
        break;
}

?>

<?php
if (isloggedin()) {
?>
    <div id="elgg_horizontal_tabbed_nav">
        <ul>
           <li <?php echo $friendsselect; ?> ><a onclick="javascript:$('#river_container').load('<?php echo $vars['url']; ?>mod/riverdashboard/?display=friends&amp;content=<?php echo $vars['type']; ?>,<?php echo $vars['subtype']; ?>&amp;callback=true'); return false;" href="?display=friends"><?php echo elgg_echo('friends'); ?></a></li>
            <li <?php echo $mineselect; ?> ><a onclick="javascript:$('#river_container').load('<?php echo $vars['url']; ?>mod/riverdashboard/?display=mine&amp;content=<?php echo $vars['type']; ?>,<?php echo $vars['subtype']; ?>&amp;callback=true'); return false;" href="?display=mine"><?php echo elgg_echo('mine'); ?></a></li>
        </ul>
    </div>
<?php
}
?>
Step 2:

 Open the index.php file in riverdashboard plugin
switch($orient) {
    case 'mine':
        $subject_guid = get_loggedin_userid();
        $relationship_type = '';
        break;
    case 'friends':
        $subject_guid = get_loggedin_userid();
        $relationship_type = 'friend';
        break;
    default:
        $subject_guid = 0;
        $relationship_type = '';
        break;
}


Remove above lines and paste following lines in riverdashboard index.php file


 switch($orient) {
    case 'mine':
        $subject_guid = get_loggedin_userid();
        $relationship_type = '';
        break;
    case 'friends':
        $subject_guid = get_loggedin_userid();
        $relationship_type = 'friend';
        break;
    default:
        $subject_guid = get_loggedin_userid();;
        $relationship_type = 'friend';
        break;
}

Disable the spotlight section in elgg

In pageshells file >>> elggroot/views/default/pageshells/pageshells.php

Comment the following line

    <?php  echo elgg_view('page_elements/spotlight', $vars); ?>

<?php
if(isloggedin()){
?>
    <!-- spotlight -->
   <?php //echo elgg_view('page_elements/spotlight', $vars); ?>
<?php
}
?>


Note: If you enable new theme edit the above line in themes views/default/pageshells/pageshells.php file

Tuesday, 13 September 2011

Make your social network using ELGG

Elgg is a social network tool made by PHP and Mysql


Tuesday, 6 September 2011

List the admin menu in drupal

The following code use to display all the menu items in drupal

In user.module file

function user_menu() {

$items['admin/user'] = array(
'title' => 'User management',
'description' => "Manage your site's users, groups and access to site features.",
'position' => 'left',
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('access administration pages'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
'weight' => 3,
);

}
In system.admin.inc file

function system_admin_menu_block_page() {
$item = menu_get_item();
if ($content = system_admin_menu_block($item)) {
$output = theme('admin_block_content', $content);
}
else {
$output = t('You do not have any administrative items.');
}
return $output;
}
The same module we display our custom module menus

Sunday, 4 September 2011

Create different page templates depending on the current path in drupal

In drupal default template is page.tpl.php.
Drupal check the available template for following order it use the first available template for the current page.
 
1. http://www.mysite.com/node/22
This URL is encountered drupal will check for available templates in the following order.

page-node-22.tpl.php

page-node.tpl.php

page.tpl.php

2. http://www.mysite.com/node/22/edit 
Similarly

page-node-edit.tpl.php

page-node-22.tpl.php

page-node.tpl.php

page.tpl.php

3.  http://www.mysite.com/calendar


page-calendar.tpl.php

page.tpl.php


If you are using URL alias like  http://www.mysite.com/node/2 is http://www.mysite.com/about
To check alias for node in URL aliases->list


Following order is used to check for templates.

page-node-2.tpl.php

page-node.tpl.php

page.tpl.php
 

Friday, 2 September 2011

Convert HTML template to joomla template

Joomla is one of the best cms.

Joomla Template directory structure:

  • index.php
  • component.php
  • template.css
  • templateDetails.xml
  • template_thumbnail.ext ( .jpg, .png, .gif )
The basic index.php file create from following video

 



Create page.tpl for calendar/* all url in drupal 6

calendar for default  page.tpl

Add following function in template.php.
After create page-calendar.tpl.php file in theme folder.
Clear cache and check it.


<?php
function themeName_preprocess_page(&$vars) {
    if (arg(0) == 'calender'){
            $vars['template_files'][] = 'page-calendar';
    }
} 
?> 

 Calendar display using page-calendar.tpl.php ( without right and left side )

Thursday, 1 September 2011

Creating Slideshow in Drupal

Following modules are used to create image slideshow
1. CCK,
2. Views
3. Views Slideshow
4. ImageCache .

Wednesday, 31 August 2011

Views module in drupal

This views module important module of drupal. It used to create views of all content in drupal.
 The views module introduction video

 


create drupal calendar

Drupal calender module Requires Views and the Date API (packaged with the Date module).






For More to see

Step by Step Setup of Calendar View

Our new blog site

http://blog.innovsystems.com This is our new blog site................

Tuesday, 30 August 2011

How to add meta tag to drupal page?

In drupal 6 Nodewords is used for add meta tag in all pages.