Tuesday, March 6, 2012

how to use server time to make local time

If you are working with php and want's to show time as per your time zone but your server is using php timestamp then you can use  combination of  php and javascript to get your code working for you. Its not easy to make php work with javascript but with little trick you can do it.
<script type="text/javascript"> 
function gettime() { 
var months = new Array(13);
  months[0]  = "Jan";
  months[1]  = "Feb";
  months[2]  = "Mar";
  months[3]  = "Apr";
  months[4]  = "May";
  months[5]  = "Jun";
  months[6]  = "Jul";
  months[7]  = "Aug";
  months[8]  = "Sep";
  months[9]  = "Oct";
  months[10] = "Nov";
  months[11] = "Dec";
var now = new Date(time()*1000); 
var currenthour = now.getHours(); 
var currenttime = now.getMinutes(); 
var currentdate = now.getDate(); 
var monthnumber = now.getMonth();
var monthname=months[monthnumber];
var curYear = now.getFullYear();
curYear=curYear.toString().slice(2);
//var offset = now.gettimezoneOffset(); 
//document.write(now);//.toLocaleString()); 
document.getElementById('curr_time<?php echo $i;?>').innerHTML=currentdate+'-'+monthname+'-'+curYear+' '+currenthour+':'+currenttime;
</script> 
<span id="curr_time<?php echo $i;?>"></span>
<?php 
$time_current = "<script>gettime()</script>";echo $time_current; 
$i++; 

Thursday, March 1, 2012

Do scroll of page to about certain pixel using jquery

You can do page scroll using jquery . Suppose on click event you want to do page scroll upto a certain points. For this use 
$('html,body').animate({scrollTop: $('#xyz').offset().top}, 2000);
give the id from which you want to display.
call it inside a function and call this function ocClick event.

Sunday, February 19, 2012

How to add Google Analytics to ajax page in drupal

We know that Google Analytics works with url hit .No of URL hits no of page hits occur,but what about ajax page suppose some part is inside a page and with click of that ajax area create hits for the page with out page refresh.For that solution is

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-800000-5']);
  _gaq.push(['_trackPageview']);

  (function() {alert('1');
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

For doing this in drupal you will have to add this script in HEAD section of ypour theme html.tpl.php  file and call in  onClick event like this <a href="" onClick="_gaq.push(['_trackPageview', '/pp']);">Click it</a>
it adds hits to page called as pp you can give name of any page you like its your custom url which you are giving.

Tuesday, September 20, 2011

Creating new custom node with image field and other in drupal7

This code is useful for making a custom node with fields and it also guides how to add data to your custom fields

function node_photo_create_data()
{
$qry = db_query("select * from tp_photos limit 1");
foreach($qry as $qryString)
{
  $image_valid=db_query("select * from field_data_field_tp_image_id where field_tp_image_id_value=".$qryString->photo_id);
   drupal_set_message(count($image_valid));
  if(count($image_valid)==0)
   {
  $node = (object) array
  (
    'title' => $qryString->photo_title,
    'type' => 'tp_photo',
    'language' => LANGUAGE_NONE, 
   );
 node_object_prepare($node);
 $filepath = drupal_realpath('images/shutterstock_'.$qryString->photo_id.'.jpg');
 $file = (object) array(
     'uri' => $filepath,
    'filemime' => file_get_mimetype($filepath),
    'status' => 1,
  );
  
  // We save the file to the root of the files directory.
  $file = file_copy($file, 'public://tpimages');
  $node->field_tp_image[LANGUAGE_NONE][0] = (array)$file;
  $node->field_tp_image_cityid[LANGUAGE_NONE][0]['value']=$qryString->city_id;
  $node->field_tp_image_copyright[LANGUAGE_NONE][0]['value']=$qryString->photo_copyright;
  $node->field_tp_image_id[LANGUAGE_NONE][0]['value']=$qryString->photo_id;
  $node->field_tp_image_url[LANGUAGE_NONE][0]['value']=$qryString->photo_url;
  $node->field_tp_image_loc[LANGUAGE_NONE][0]['value']=$qryString->photo_location;
  $node->field_tp_image_category[LANGUAGE_NONE][0]['value']=$qryString->photo_category;
  
  $node->field_tp_image_source[LANGUAGE_NONE][0]['value']=$qryString->photo_Source;
  $node->field_tp_image_tags[LANGUAGE_NONE][0]['value']=$qryString->photo_tags;
 
  node_save((object) $node);

      } //for each
}
}

note: create a new content type and name add fields which you want to add it.and then assign its custom name data

Friday, August 12, 2011

Adding Facebook Api to your file

First register your application with http://developers.facebook.com/
here is the useful link http://itprism.com/blog/register-facebook-application
Login to it and give your application url in it
note: your application should be on remote server or webserver then only it will work and register.
After registration it will give you App Id and API Key use these in your file to run your code.
Next job is to to copy https://github.com/facebook/php-sdk/ link files to your server folder
and import those files to your module where you want to use it.
You can use its example.php file and edit it put your website App Id and API Key and give permissions what else things you require from it except default things it is giving like email,link friend's list etc.
After that put those things in the web server.it will work











Tuesday, November 30, 2010

How to pass time while no work in office

Its very often that few days will be there when there will be no work for you at office. so what to do how to pass time. Its very difficult to say. Some pass their time by just learning new things while some like to serf on net new things while some feel to chat or etc. So for new techniques and ideas of passing time just give your comments.