Pages

Sunday, August 18, 2013

PHP-Convert a timestamp into facebook post time representation i.e years ago,months ago,weeks ago,days ago,hours ago,minutes ago,seconds ago format

This code is helpful for converting a timestamp field to a time stated as

years ago if it is more than an year ago
months ago if it is more than a month ago
week ago
days ago
hours ago
seconds ago

For example a post made yesterday will be shown as " 1 day ago"

Here goes the code
 <?php  
 $today = time();    
                 $createdday= strtotime($post['created']); //mysql timestamp of when post was created  
                 $datediff = abs($today - $createdday);  
                 $difftext="";  
                 $years = floor($datediff / (365*60*60*24));  
                 $months = floor(($datediff - $years * 365*60*60*24) / (30*60*60*24));  
                 $days = floor(($datediff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));  
                 $hours= floor($datediff/3600);  
                 $minutes= floor($datediff/60);  
                 $seconds= floor($datediff);  
                 //year checker  
                 if($difftext=="")  
                 {  
                   if($years>1)  
                    $difftext=$years." years ago";  
                   elseif($years==1)  
                    $difftext=$years." year ago";  
                 }  
                 //month checker  
                 if($difftext=="")  
                 {  
                    if($months>1)  
                    $difftext=$months." months ago";  
                    elseif($months==1)  
                    $difftext=$months." month ago";  
                 }  
                 //month checker  
                 if($difftext=="")  
                 {  
                    if($days>1)  
                    $difftext=$days." days ago";  
                    elseif($days==1)  
                    $difftext=$days." day ago";  
                 }  
                 //hour checker  
                 if($difftext=="")  
                 {  
                    if($hours>1)  
                    $difftext=$hours." hours ago";  
                    elseif($hours==1)  
                    $difftext=$hours." hour ago";  
                 }  
                 //minutes checker  
                 if($difftext=="")  
                 {  
                    if($minutes>1)  
                    $difftext=$minutes." minutes ago";  
                    elseif($minutes==1)  
                    $difftext=$minutes." minute ago";  
                 }  
                 //seconds checker  
                 if($difftext=="")  
                 {  
                    if($seconds>1)  
                    $difftext=$seconds." seconds ago";  
                    elseif($seconds==1)  
                    $difftext=$seconds." second ago";  
                 }  
                 echo " | ".$difftext;  
 ?>  

MYSQL-Find a word from comma separated list(in string)

I have a table as follows

id name status
1  test1  option1,option2
2  test2  option,option1
3  test3  option2,option3
4  test4  option3,option4
5  test5  option1,option3

"SELECT * FROM TABLE WHERE FIND_IN_SET('option',status-name of column/attribute)">0

simple query to check whether a string is present in comma separated values entered as string under a column or attribute

Cakephp-Refresh Auth Session information after a database change of current user

In order to update current user logged in Auth Session after a database change in his information in Users Table use the following command

$userid=$this->Auth->user('id');

$this->Session->write('Auth',$this->User->read(null,$userid));

That's it and your auth session is updated..

This is usually done once a user updates his information....

Authroize .Net-Error:E00044 [text]=>Customer Information Manager is not Enabled

This error I faced using Authorize .Net CIM.My only mistake was I signed up with an account with credit card present in Authorize .net developers

Sign up with an account with "Card Not Present option" and it will give you a different admin panel where you can enable disable CIM.


cakephp-Ascending Order in Pagination

Recently I faced an issue while implementing an "Order By" command in cakephp pagination it was not taking the regular cakephp syntax

So I performed the same as follows

$this->Paginate=array('limit'=>10,'order'=>array('Model.field1'=>'asc'));

remember I used regular order i.e.

$this->Paginate=array('limit'=>10,'order'=>array('Model.field1 ASC'));

but this did not work

Amazon Cloud-AMI Machines-Setup PHP and mysql on Amazon Cloud

In my case I needed to install -mcrypt library to decrypt passwords

I used

yum install php libmcrypt libmcrypt-devel php-mcrypt php-mbstring

The best complete tutorial I got was here

http://calebogden.com/wordpress-on-linux-in-the-amazon-cloud-with-mac/

Best FLV conversion parameters from ffmpeg

Recently while developing one of my projects We were using Hit and Try to get best output from ffmpeg to convert to a flv.

when one of my co-developers finally came out with following command

exec ("/usr/bin/ffmpeg -qscale 4 -i" old_video_loc new_video_loc);

Thanks Hitesh for efforts

Install FFmpeg and ffmpeg-php on CentOS

1. Create and open a new file called /etc/yum.repos.d/dag.repo.

vi /etc/yum.repos.d/dag.repo“.

2. Add the following text to the file:
[dag]
name=DAG RPM Repository
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1 
Finally, save and close the file.

3. In order to successfully use the DAG repository with tools such as yum, you need to add DAG’s GPG key.

Failure to do so will result in an error like the following: warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 6b8d79e6 Public key for faac.x86_64.1.26-1.el5.rf.rpm is not installed 

4. In order to add the GPG key for DAG, run the following:
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

5. Now that DAG is setup, it’s a good idea to update all your packages.

yum update

6. Search for ffmpeg package

yum search ffmpeg

7. Install package with depencdecy packages

yum install ffmpeg ffmpeg-devel ffmpeg-libpostproc

8. There are four things that are required to successfully install and run ffmpeg-php; they are:
  • ffmpeg-0.4.9_pre1 or higher
  • php-4.3.0 or higher
  • gd-2.0 or higher
  • php-devel
PHP and FFmpeg should be good to go since at the time of this writing, DAG has PHP version 5.1.6 and FFmpeg version 0.4.9. GD and php-devel can be easily installed by running the following yum command:
yum install php-gd php-devel
 
Installing ffmpeg-php

Now we are ready to install ffmpeg-php.
This can be done in six easy steps:

1. Download the latest ffmpeg-php release
2. Extract the archive: tar -xjf ffmpeg-php-X.x.x.tbz2
3. cd ffmpeg-php-X.x.x/
4. phpize
5 ./configure & & make
6 sudo make install