Friday, July 29, 2011

Add Separate CSS for IE - Drupal 6

There are THREE ways by which we can include css for IE with respective to the versions of IE.

1)From active Themes .info file.
2)From active Themes template file (page.tpl.php).

1)From active Themes .info file. (Eg: Zen theme)

 In Themes .info file, there is a section adds CSS files to your theme, there we can include our custom css file for different IE versions.

Code:

; Set the conditional stylesheets that are processed by IE.

;For all versions of IE browser
conditional-stylesheets[if IE][all][]  = css/ie.css

;For  lte (less than or equal to) IE 7 browser - applies to all versions less than or equal to IE 7 (IE7, IE6, IE5 ,.....)
conditional-stylesheets[if lt IE 7][all][] = css/ie.css

;For  lt (less than) IE 7 browser - applies to all versions less than IE 7 (IE6, IE5 ,.....)
conditional-stylesheets[if lte IE 7][all][] = css/ie.css

;For  gte (greater than or equal to) IE 7 browser - applies to all versions greater than IE 7 (IE7, IE8 , IE9,.....)
conditional-stylesheets[if gte IE 7][all][] = css/ie.css


;For  gt (greater than) IE 7 browser - applies to all versions greater than IE 7 (IE8 , IE9,.....)
conditional-stylesheets[if gt IE 7][all][] = css/ie.css 

 ;For only IE 7 browser - applies to only IE 7
conditional-stylesheets[if IE 7][all][] = css/ie7.css 

For More Information -  Click Here


2)From active Theme template file (page.tpl.php).

 Code to be included in <head> </head> tag.

/*For all IE browsers version less than or equal to IE7*/
<!--[if lte IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For all IE browsers version less than  IE7*/
<!--[if lt IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For all IE browsers version greater than or equal to IE7*/
<!--[if gte IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For all IE browsers version greater than IE7*/
<!--[if gt IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For only IE 7 browser - applies to only IE 7*/
<!--[if IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->


/*For all IE browser - applies to all IE versions*/
<!--[if IE]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->



Tuesday, July 26, 2011

how to covert OFC(drupal API "ofc_api") SWF OBJECT TO IMAGE

step1 : sites/all/modules/ofc_api/php-ofc-library/ofc_upload_image.php

Add following  code:
// default path for the image to be stored //
- $default_path = '../tmp-upload-images/';
+if( ! $_GET['defaultPath'] ) {
+    $default_path = '../tmp-upload-images/';
+} else {
 +   $default_path = $_GET['defaultPath'];
+}

step2 : display  chart area


/*************** display chart using area  start*************/
    
    $chart = new open_flash_chart();
    
    $title = new title( 'Future & Option Chart' );
    $title->set_style( "{font-size: 20px; color: #A2ACBA; text-align: center;}" );
    $chart->set_title( $title );
    
    $area = new area();
    $area->set_colour( '#5B56B6' );
    $area->set_values( $call_buy );
    $area->set_key( 'Call_Buy', 13 );
    $area->on_show(new line_on_show($animation[0], $cascade[0], $delay[0]));
    $chart->add_element( $area );
    
    $call_write = new area();
    $call_write->set_colour( '#800517' );
    $call_write->set_values( $CallWrite );
    $call_write->set_key( 'Call_Write', 13 );
    $call_write->on_show(new line_on_show($animation[1], $cascade[1], $delay[1]));
    $chart->add_element( $call_write );
    
    $put_buy = new area();
    $put_buy->set_colour( '#00FFFF' );
    $put_buy->set_values( $putbuy );
    $put_buy->set_key( 'Put_Buy', 13 );
    $put_buy->on_show(new line_on_show($animation[2], $cascade[2], $delay[2]));
    $chart->add_element( $put_buy );
    
    $put_write = new area();
    $put_write->set_colour( '#52D017' );
    $put_write->set_values( $putwrite );
    $put_write->set_key( 'Put_Write', 13 );
    $put_write->on_show(new line_on_show($animation[3], $cascade[3], $delay[3]));
    $chart->add_element( $put_write );
    
    $future_buy = new area();
    $future_buy->set_colour( '#8D38C9' );
    $future_buy->set_values( $futureBuy );
    $future_buy->set_key( 'Future_Buy', 13 );
    $future_buy->on_show(new line_on_show($animation[4], $cascade[4], $delay[4]));
    $chart->add_element( $future_buy );
    
    $future_sell = new area();
    $future_sell->set_colour( '#F778A1' );
    $future_sell->set_values( $futureSell );
    $future_sell->set_key( 'Future_sell', 13 );
    $future_sell->on_show(new line_on_show($animation[5], $cascade[5], $delay[5]));
    $chart->add_element( $future_sell );

    // $average = new area();
    // $average->set_colour( '#0E440E' );
    // $average->set_values( $avg );
    // $average->set_key( 'Resultant Profit', 13 );
    // $average->on_show(new line_on_show($animation[6], $cascade[6], $delay[6]));
    // $chart->add_element( $average );
    
    $line_1_default_dot = new solid_dot();
    $line_1_default_dot->size(2)->halo_size(2)->colour('#0E440E');
    $average = new line();
    $average->set_default_dot_style($line_1_default_dot);
    $average->set_values( $avg  );
    $average->set_width( 1 );
    $average->set_key( 'Resultant Profit', 13 );
    $average->set_colour( '#0E440E' );
    $average->on_show(new line_on_show($animation[6], $cascade[6], $delay[6]));
    $chart->add_element( $average );

    $x_labels = new x_axis_labels();
    $x_labels->set_steps( 1 );
    $x_labels->set_vertical();
    $x_labels->set_colour( '#A2ACBA' );
    $x_labels->set_labels( $current_market );
    
    $x = new x_axis();
    $x->set_colour( '#A2ACBA' );
    $x->set_grid_colour( '#D7E4A3' );
    $x->set_offset( false );
    $x->set_steps(1);
    // Add the X Axis Labels to the X Axis
    $x->set_labels( $x_labels );
    
    $chart->set_x_axis( $x );
    
    $x_legend = new x_legend( $min . ' to ' . $max );
    $x_legend->set_style( '{font-size: 20px; color: #778877}' );
    $chart->set_x_legend( $x_legend );
    
    //
    // remove this when the Y Axis is smarter
    //
    $y = new y_axis();
    $y->set_range( $ymin, $ymax, $y_diff );
    $chart->add_y_axis( $y );
        
    
  step3: here jquery call to get unique id of swf
 
    /************** display chart using area end ***************/

    $displayChart = array();
    
    $displayChart['resultant'] = $resulant_lossprofit;


    $chartId = ofc_api_unique_id();
    $displayChart['chart_id'] = $chartId ;
    $displayChart['chart'] = fno_chart_api_render($chart, 800, 400, array(), $chartId);
    //here unique chart id set
    drupal_add_js("var open_chart_id = '{$chartId}'", 'inline');

    //on particular button click function this image stored in default path
  $js6 = "jQuery(document).ready(function(){
        jQuery('#chart-pdf1').bind('click', function(){         
         var url = 'http://192.168.2.74/stock_adv/sites/all/modules/ofc_api/php-ofc-library/ofc_upload_image.php';   //call ofc_upload_image.php
            url += '?name={$chartId}.png';    //append image name                               
            url += '&defaultPath=' + '/home/ajay/public_html/stock_adv/sites/default/files/';     //default path where image stored
         swfobject.getObjectById(open_chart_id).post_image(url,true, false );   //ofc method to get image stored in default path
 });     
                  });";
  drupal_add_js($js6, 'inline');

    return $displayChart;
}

 step 4: there chart api render function call to display swf object

function fno_chart_api_render($chart = 'ofc_api_sample', $width = 800, $height = 400, $params = array(), $id=false ) {
  $swf = url(drupal_get_path('module', 'ofc_api') . '/open-flash-chart.swf');
  if ( !$id ) {
      $id = ofc_api_unique_id();
  }
  // Call hook_ofc_api_data() to get all function names that will return chart data
  $charts = module_invoke_all('ofc_api_data');
  
  // $chart contains a function name
  if (in_array($chart, $charts, true) && function_exists($chart)) {
    $method = 'data-file';
    $source = url('ofc_api/data/' . $chart);
  }
  // $chart is a chart object
  elseif (is_object($chart) && isset($chart->elements)) {
    $method = 'get-data';
    $source = $id;
    $json = drupal_to_js(json_encode($chart));
  }
  // $chart contains the JSON string
  elseif (is_string($chart) && is_object(json_decode($chart))) {
    $method = 'get-data';
    $source = $id;
    $json = drupal_to_js($chart);
  }
  // $chart is in unknown format
  else {
    $method = 'data-file';
    $source = url('ofc_api/data/not-found');
  }
  
  $data = array(
    '@swf' => $swf,
    '@id' => $id,
    '@width' => check_plain($width),
    '@height' => check_plain($height),
    '@method' => $method,
    '@source' => $source,
    '@json' => $json,
  );
  
  return ofc_api_render_html($data, $params);
}

Adding PHP Code in Views - Drupal 6

Thanks to Views Custom Field module which allowed us to write custom php code in Views field.

Comes with three different fields
1) Markup
Field that allows usage of custom text and the input filter system.
2) PHP code
Field that allows usage of custom PHP code (with access to view's database result)
 $data: contains the retrieved record from the database (e.g. $data->nid).
 we can access the fields build in the database query , To know the fields see the build query shown in views preview or add a custom PHP field with <?php print_r($data); ?> will show the available database field, which can be used in our code.
 3) Rownumber
Field containing rownumber (respects pagers).
 Note:
Include <?php ?> delimiters when using PHP code. Available variables:
$static: can be used to store reusable data per row.

Now i am going to show you how Replacement Patterns can be used in Views Custom field.

For example:

<?php

$static = $this->view->display_handler->get_handlers('field');
if (!empty($static['drupal_id']->last_render)) {
echo "success";
}

?>
here drupal_id is the Replacement Pattern
[drupal_id] == Drupal ID

Alter Menu Title in drupal 6 using hooks

we can alter Menu Title in drupal 6 using hooks using phptemplate_menu_item_link($item) function in template.php file

for Eg:


function phptemplate_menu_item_link($item) {

    if( strpos($item['title'], 'Administer') === 0) {

         $item['title']='Administer Kapil';
           return l($item['title'], $item['link_path'], !empty($item['description']) ? array('title' => $item['description']) : array(), NULL, NULL, FALSE, FALSE);
    }
  
     return l($item['title'], $item['link_path'], !empty($item['description']) ? array('title' => $item['description']) : array());
}


This function will change "Administer" menu title in Navigation menu to 'Administer Kapil'. 

and we can also use html tags in Menu title if we set 7th parameter in return statement to TRUE...