calendar-icon

Here is a php function which returns from and to date as an array for a range:

<?php

function get_rangeof_dates($time_frame = ‘all_time’)

{

$from_date = ;

$to_date = ;

switch($time_frame)

{

case ‘all_time’:        $from_date = ’1170-01-01 00:00:00′;

$to_date = ’2250-12-31 23:59:59′;

break;

case ‘today’:

$from_date = date(‘Y-m-d 00:00:00′);

$to_date = date(‘Y-m-d 23:59:59′);

break;

case ‘yesterday’:

$from_date = date(‘Y-m-d 00:00:00′, time()- 24* 60 * 60 );

$to_date = date(‘Y-m-d 23:59:59′, time()- 24* 60 * 60 );

break;

case ‘this_week’:

$from_date = date(‘Y-m-d 00:00:00′, time() – (date(‘w’, time()) * 60 * 60 * 24));

$to_date = date(‘Y-m-d 23:59:59′, time() + ((6 – date(‘w’, time())) * 60* 60 * 24 ));

break;

case ‘last_week’:

$from_date = date(‘Y-m-d 00:00:00′, time() – (date(‘w’, time()) * 60 * 60 * 24) – 7 * 24 * 60 * 60);

$to_date = date(‘Y-m-d 23:59:59′, time() + (( 6 – date(‘w’, time()) ) * 60* 60 * 24 ) – 7 * 24* 60* 60);

break;

case ‘last_7_days’:     $additonal_query = “created_at > ‘”.date(‘Y-m-d’, time()- 7 * 24* 60 * 60 ).“‘”;

$from_date = date(‘Y-m-d 00:00:00′, time()- 7 * 24* 60 * 60 );

$to_date = date(‘Y-m-d 23:59:59′);

break;

case ‘this_month’:

$from_date = date(‘Y-m-d 00:00:00′, mktime( 0, 0, 0, date(“m”)  , 1 , date(“Y”) ) );

$to_date = date(‘Y-m-d 23:59:59′);

break;

case ‘last_month’:

$from_date = date(“Y-m-01 00:00:00″, strtotime(“-1 month”, strtotime(date(“Y-m-d”))));

$to_date = date(“Y-m-d 23:59:59″, strtotime(“-1 day”, strtotime(date(“Y-m-01″))));

break;

case ‘last_30_days’:

$from_date = date(‘Y-m-d 00:00:00′, time()- 30 * 24* 60 * 60 );

$to_date = date(‘Y-m-d 23:59:59′);

break;

case ‘this_quarter’:

$month = date(‘m’);

$year = date(‘Y’);

if($month == 1 || $month == 2 || $month == 3 )

{

$from_date = $year.‘-01-01′;

$to_date = $year.‘-03-31′;

}

elseif($month == 4 || $month == 5|| $month == 6 )

{

$from_date = $year.‘-04-01′;

$to_date = $year.‘-06-30′;

}

elseif($month == 7 || $month == 8|| $month == 9 )

{

$from_date = $year.‘-07-01′;

$to_date = $year.‘-09-30′;

}

else

{

$from_date = $year.‘-10-01′;

$to_date = $year.‘-12-31′;

}

break;

case ‘last_quarter’:

$month = date(‘m’);

$year = date(‘Y’);

if($month == 1 || $month == 2 || $month == 3 )

{

$from_date = ($year -1).‘-10-01′;

$to_date = ($year-1).‘-12-31′;

}

elseif($month == 4 || $month == 5|| $month == 6 )

{

$from_date = $year.‘-01-01′;

$to_date = $year.‘-03-31′;

}

elseif($month == 7 || $month == 8|| $month == 9 )

{

$from_date = $year.‘-04-01′;

$to_date = $year.‘-06-30′;

}

else

{

$from_date = $year.‘-07-01′;

$to_date = $year.‘-09-30′;

}

break;

case ‘this_year’:

$from_date = date(‘Y-01-01 00:00:00′);

$to_date = date(‘Y-12-31 23:59:59′);

break;

case ‘last_year’:

$from_date = date(‘Y-01-01 00:00:00′, mktime( 0, 0, 0, 01 , 01 , date(“Y”) – 1 ));

$to_date = date(‘Y-12-31 23:59:59′, mktime( 0, 0, 0, 12 , 31 , date(“Y”) – 1 ) );

break;

}

return array($from_date, $to_date);

}

?>


Tags: , , , , , , , , , , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

facebook_f

This is a quick note for myself to remember some tricks while we develop a Facebook application.

If you are a beginner in Facebook application development, go here first.

If  you an expert in Facebook development, go here. :)

The steps in creating a facebook app.
1) Register an application in facebook
2) Add Canvas URL
3) Add Canvas Callback url
4) Test the canvas is working or not
To execute FBML inside your code (for iframe), you must add FBConnect URL
You need to set xd_receiver.htm in your webroot folder
Download facebook php api
If you are using iframe, remember to use facebook-canvas url for links and forms , not your local url.
If you are using canvas mode, you cannot use body tag in your html. You dont need to keep the basic html layout
like head, title, body etc
An example page in the canvas_callback looks like this:

The steps in creating a facebook app.

1) Register an application in facebook

2) Add Canvas URL

3) Add Canvas Callback url

4) Test the canvas is working or not

To execute FBML inside your code (for iframe), you must add FBConnect URL

You need to set xd_receiver.htm in your webroot folder

Download facebook php api

If you are using iframe, remember to use facebook-canvas url for links and forms , not your local url.

If you are using canvas mode, you cannot use body tag in your html. You dont need to keep the basic html layout

like head, title, body etc

An example page in the canvas_callback looks like this:

<?php

require_once(‘facebook.php’);

//ini_set (‘display_errors’, 1);

$appapikey = ’0d7c64e9a387eXXXXXXXXXXXXXXXXXXX’;

$appsecret = ’9fc9eef6dXXXXXXXXXXXXXXXXXXXXXXX’;

$facebook = new Facebook($appapikey, $appsecret);

?>


Sometimes , in IE and Safari, infinite redirect loop will happen. It is due to session problem

add the below code to solve this!

<?php

$prefix = ($_REQUEST['fb_sig_user']) ? ‘fb_sig’ : $appapikey;

if( isset($_REQUEST[$prefix.'_session_key']) ){

session_name( $_REQUEST[$prefix.'_session_key'] );

session_start();

$_SESSION['fb_user']        = $_REQUEST[$prefix.'_user'];

$_SESSION['fb_session_key'] = $_REQUEST[$prefix.'_session_key'];

$_SESSION['fb_expires']     = $_REQUEST[$prefix.'_expires'];

$_SESSION['fb_in_canvas']   = $_REQUEST[$prefix.'_in_canvas'];

$_SESSION['fb_time']        = $_REQUEST[$prefix.'_time'];

$_SESSION['fb_profile_update_time'] = $_REQUEST[$prefix.'_profile_update_time'];

$_SESSION['fb_api_key']     = $_REQUEST[$prefix.'_api_key'];

} else {

// Just so there *is* a session for times when there is no fb session

session_start();

}

?>

If you use iframe, remember to use this funcion as well


<?php

$facebook->require_frame();

?>

Also use the following function if you need authentication

$user_id = $facebook->require_login();

Don’t forget to add this in html tag (for iframe users)

<html xmlns=“http://www.w3.org/1999/xhtml” xmlns:fb=“http://www.facebook.com/2008/fbml”>

For facebook client side api (Javascript), include this line

<script type=“text/javascript” src=http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php></script>

For example, if you need to open a add to bookmark dialog on button click, use:

onclick=”FB.Connect.showBookmarkDialog();”

Add this line very bottom of the page, to avoid javascript error in some browsers (IE6 or 7 not sure)

<div id=“FB_HiddenIFrameContainer” style=“display:none; position:absolute; left:-100px; top:-100px; width:0px; height: 0px;”></div>

Sometimes, your application inside iframe shows scroll bar. It is due to dynamically increasing height or width of the content

use the below script at the bottom of the page.

<script type=“text/javascript”>

window.onload = function() {

FB_RequireFeatures(["XFBML", "Connect"], function() {

FB.init(“0d7c64e9a387XXXXXXXXXXXX”, ‘xd_receiver.htm’);

FB.CanvasClient.startTimerToSizeToContent();

FB.CanvasClient.syncUrl();

});

};

</script>

Look  inside the facebook api php file to know more about the functions. For example to get friends info

<?php

$friends = $facebook->api_client->friends_get(,$user_id);

$friends_info = $facebook->api_client->users_getInfo(implode(‘,’, $friends), ‘first_name,last_name,pic_square ‘ );

?>


For ajax call inside your iframe, to avoid redirect loop, pass the full server query url along with your file.

<?=$_SERVER['QUERY_STRING']?>

eg:

$(‘#browse_ajax’).load(‘<?=$root_path?>browse_ajax.php?<?=$_SERVER['QUERY_STRING']?>’);

When you pass Query string, remember to replace your parameters passing via get method. Otherwise

you cannot pass yourown custom values

<?php

function get_query_string()

{

$serverQuery = $_SERVER['QUERY_STRING'];

$serverQuery=  str_replace(‘page=’, ‘page_=’, $serverQuery);

$serverQuery = str_replace(‘fan=’, ‘fan_=’, $serverQuery);

$serverQuery = str_replace(‘uid=’, ‘uid_=’, $serverQuery);

return $serverQuery;

}

?>

<?php

Use the below function for publish to wall option:

function publishWall()

{

var message = ‘type your message here’;

var attachment = { ‘name’: ‘your text here’, ‘href’: ‘http://urlhere.com/’, ‘description’: ‘Your message here’, ‘media’: [{ 'type': 'image', 'src': 'urlhere.com', 'href': 'urlhere.com'}] };

var action_links = [{'text':'More like this', 'href':'urlhere.com'}];

FB.Connect.streamPublish(message, attachment, action_links);

}

?>

Tags: , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

jquery-logo

Recently I created a sliding menu for a project using jQuery and ScrollTo functions.

See demo: Slider  Menu

We can use the jQuery function $(“.menubar”).scrollTo(id_of_element) to scroll any scrollable area to a particular location.

The idea behind every smooth sliding is using scroll function with overflow:hidden mode.

You can download the source code from : http://www.sajithmr.me/downloads/slider/slider.zip

Here div menu-bar is the scrollable div with overflow:hidden mode contains set of menu and a duplicate as a  buffer

At the bottom of the code, you can see a filler div, this is for filling the menu one by one to the right side menu-bar to make the sliding very smooth

The function setMotion(this) calls  the scroll function and it moves till the called DOM object’s id reaches

If you use an ajax call after the motion to load the content at the bottom, you can make this sliding menu for proper navigation purpose.

Thanks

Sajith

Tags: , , , , , , ,

· · · ◊ ◊ ◊ · · ·

Jmail++ LogoI am writing this topic in sajithmr.com, because i am getting a lot of queries regarding this project from the place I submitted , ProjectGuidance.com , 3 years back. It was a new Webmail Service Idea Developed in JSP . Here is the link. http://www.projectguidance.com/guidance/details/id/36676649 .

There are more than 400 replies and most of its content is “please send me the project report to my email address”.

jMail++ is a webmail written in JSP. You can create new Account here like yahoo, gmail etc…The Session is handled by Single page Auto Invalidate Method..That will increase Your Mail Security. A simple 4 entry Registration process is required.. And your Password will be handle using RSA Encryption method…There is a Fast Search Mechanism included with Google APIs. The Very Important and Unique Feature is You can Check Your Rediff, Hotmail , Gmail account from this Webmail without login into the respective sites. It means this Webpage act as an Email Client Also (Like OutLook Express). The Protocols (SMTP,POP3) all are implement from Scrach without any API’s…Its is a Pure JSP Project.

This was the post on ProjectGuidance.com

Here i included the full project report as zip file.

Jmail-Project-Report.zip

OpenID Integration PHP

See screen short of this project:

Jmail Screen Shot 1
(Screenshot 1)

Jmail Screen Shot 2
(Screen shot 2)

Tags: , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

PHP post without curl

04 Apr 2008

You can simulate the post method using php without the help of curl library.
download full source code:
OpenID Integration PHP

See the code below:

function do_post_request($url, $data, $optional_headers = null) {

$params = array('http' =>; array('method' =>; 'POST',

'content' =>; $data

));

if ($optional_headers !== null) {

$params['http']['header'] = $optional_headers;

}

$ctx = stream_context_create($params);

$fp = @fopen($url, 'rb', false, $ctx);

if (!$fp) {

throw new Exception("Problem with $url, $php_errormsg");

}

$response = @stream_get_contents($fp);

if ($response === false) {

throw new Exception("Problem reading data from $url, $php_errormsg");

}

return $response;

}

?>

Download the full source code from post_without_curl.zip

Tags: , , , ,

· · · ◊ ◊ ◊ · · ·

OpenID PHP Integration

I think you know the use of OpenID. Else go here and learn

http://en.wikipedia.org/wiki/OpenID
http://openid.net/what/
http://openiddirectory.com/

In a nutshell, the OpenID technology makes life simpler by having only one username and password to remember – yahoo OpenID tour

Here the php source code for integrating your site with OpenID. If you have a website which has user login / signup options , you can also add openID authentication so that user can login into your site with there OpenID

php-openid-2.0.zip

OpenID Integration PHP

(tested in windows. read the README file before installing. set $store_path = “/tmp” to a directory according to OS)

Visit this url: http://openidenabled.com/ for other languages (phython, ruby etc)

Tags: , , , ,

· · · ◊ ◊ ◊ · · ·

ffmpeg sample code

12 Jun 2007

ffmpeg

Install ffmpeg library in your server first.

Place a video file of any type on current directory (or anywhere), here it is clock.avi .

Click more for source code:

extension_loaded('ffmpeg') or die('Error in loading ffmpeg');

$ffmpegInstance = new ffmpeg_movie('clock.avi');
echo "getDuration: " . $ffmpegInstance->getDuration() .
"getFrameCount: " . $ffmpegInstance->getFrameCount() .
"getFrameRate: " . $ffmpegInstance->getFrameRate() .
"getFilename: " . $ffmpegInstance->getFilename() .
"getComment: " . $ffmpegInstance->getComment() .
"getTitle: " . $ffmpegInstance->getTitle() .
"getAuthor: " . $ffmpegInstance->getAuthor() .
"getCopyright: " . $ffmpegInstance->getCopyright() .
"getArtist: " . $ffmpegInstance->getArtist() .
"getGenre: " . $ffmpegInstance->getGenre() .
"getTrackNumber: " . $ffmpegInstance->getTrackNumber() .
"getYear: " . $ffmpegInstance->getYear() .
"getFrameHeight: " . $ffmpegInstance->getFrameHeight() .
"getFrameWidth: " . $ffmpegInstance->getFrameWidth() .
"getPixelFormat: " . $ffmpegInstance->getPixelFormat() .
"getBitRate: " . $ffmpegInstance->getBitRate() .
"getVideoBitRate: " . $ffmpegInstance->getVideoBitRate() .
"getAudioBitRate: " . $ffmpegInstance->getAudioBitRate() .
"getAudioSampleRate: " . $ffmpegInstance->getAudioSampleRate() .
"getVideoCodec: " . $ffmpegInstance->getVideoCodec() .
"getAudioCodec: " . $ffmpegInstance->getAudioCodec() .
"getAudioChannels: " . $ffmpegInstance->getAudioChannels() .
"hasAudio: " . $ffmpegInstance->hasAudio();

//___________________________________Code end here_____________________________________

I also can be used for file format conversion

Eg: exec(‘ffmpeg -i ‘.$SourcePath.’ ‘.$Destination);

Here $SourcePath any file of any format , and destionation also another format.

eg: exec(‘ffmpeg -i saji.3gp saji.flv’);

Tags: , , ,

· · · ◊ ◊ ◊ · · ·

وظائف 2011 تحويل العملات برامج برنامج تسريع التحميل برنامج الفلاش برنامج محول الصوتيات عربي hotel 2011 زيادة رواتب العساكر 1431