Paypal express checkout library for CodeIgniter

Hello all,

Just finished a customized version of express checkout for CodeIgniter framework based on NVP API. You can download it from -

Click to Download

thanks,

faisal ahmed

Posted in codeigniter, php | Tagged , , , , , | 2 Comments

PHP: Printing PDF using windows command

Hi,

Recently while I was developing an invoicing system for a local client I came across a problem where I had to send print command directly to the printer from my locally hosted web application.

While it was fairly easy to execute the command to open Adobe Acrobat Reader and show the print dialog from the command prompt using the following command -

1
acrord32.exe /p "c:\location\to\pdf\file.pdf"

But when put inside a php script it was not executing and showing the print dialog even after providing full path to acrord32.exe

So, the next best alternative was to use FoxIt PDF reader. I downloaded a portable version of FoxIt as it will also allow me to transfer the package easily to another computer at a future date.

Once installed I executed the following code on the print.php script -

1
echo system("D:\coral\FoxitReaderPortable\FoxitReaderPortable.exe /p D:\coral\UniServer\www\invoice-master\invoices\invoice-1.pdf");

This printed the requested PDF file effortlessly on the systems default printer. If you want to mention custom printer name (Ex: CANON) then execute the following code in the print.php -

1
echo system("D:\coral\FoxitReaderPortable\FoxitReaderPortable.exe /t D:\coral\UniServer\www\invoice-master\invoices\invoice-1.pdf CANON");

Hope it helps you avoid the issues I faced.

thanks,

faisal ahmed

Posted in Uncategorized | 1 Comment

Installing Tomcat6 on linux

hi,

To install Tomcat6 on linux you can do it in the following manner -

1
sudo apt-get install sun-java6-jdk
1
sudo apt-get install tomcat6
1
apt-get install tomcat6-docs tomcat6-examples tomcat6-admin

Tomcat Management:

1
2
3
/etc/init.d/tomcat6 start
/etc/init.d/tomcat6 stop
/etc/init.d/tomcat6 restart

reference: link

thanks,

faisal ahmed

Posted in Uncategorized | Tagged , , , , , | Leave a comment

Typing Bangla on linux

To use unijoy keyboard layout on linux you need to have iBus and the unijoy keyboard layout installed and the following is the way to get the job done –

1
2
3
4
sudo apt-get install ibus
sudo apt-get install ibus-m17n m17n-db m17n-contrib ibus-gtk
sudo dpkg -L m17n-db|grep bn
sudo dpkg -L m17n-contrib|grep bn
Posted in bangla | Tagged , , | 1 Comment

Stress testing and profiling tools for web application

Hi there,

Recently I came across some cool new tools along with some of my old favorites and thought this calls for a quick post -

Front End Profiling Tool:

FireBug: Firebug is pretty handy to find out how long it is taking your website to load and render as well as how many header calls are made to fetch external java-script and css files. It also packs lots of useful tools and a must have for any serious web application developer.

YSlow:YSlow sort of gives your an easy to understand report on your web pages flaws and how to overcome them.

Web Server Stress Testing Tool:

Siege: Siege is a command line tool that you can install and simulate concurrent hits to any particular URL.

Example:

1
siege -c 10 -r 10 http://www.mydomain.com/

Above code pings the URL concurrently with 10 connections repeating 10 times making 100 hits to the URL.

MySQL database Profiling Tool:

Jet Profiler:Jet profiler Shows the real time activity of the connected mysql database once its hooked up. It is pretty useful when used together with the siege tool and see how concurrent hits affect the database.

Naturally these are not all that is out there so any new inputs from the readers will be most welcomed

Posted in web-development | Tagged , , | Leave a comment

google +1 button onClick event

Hello there,

I was recently working with google +1 feature and came about this trick to trace if someone clicked the button or not.

1
2
3
4
5
6
7
8
9
10
11
12
13
<html>
<head>
  <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
  <script type="text/javascript">
   function testme(){
      alert(‘test’);
   }
  </script>
</head>
<body>
    <g:plusone callback="testme" href="http://www.faisalbd.com/"></g:plusone>
</body>
</html>
Posted in google+ | Tagged | Leave a comment

Codeigniter: Helper for template library dynamic view partial loading

Hello everyone,

I have recently been in quick-fire blogging mode. After playing with the superb template library developed by Phil Sturgeon.

The following template helper is the outcome of tweaking that makes life easier while setting up view partials and calling them inside the layout dynamically. The helper also has an add-on use which gives user the option to use region specific partial loading.

Controller:

welcome.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$partial_list[]['region'] = 'left';
$partial_list[]['name'] = 'category';
$partial_list[]['view'] = 'partial_category';
$partial_list[]['region'] = 'right';
$partial_list[]['name'] = 'login_box';
$partial_list[]['view'] = 'partial_login';

/* following functionautomatically sets the partials
* based on the above array and also passes $partial_list
* variable to the view.
*/

/*
* make sure the pareser helper is loaded before
* calling this function
*/

setup_partials($partial_list);

$this->template->set_layout('home_layout');
$this->template->build('home_view');

Layout:
home_view.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<html>
<head>
	<title><?php echo $template['title'];?></title>
</head>
<body>
	<div class="left">
		/* Will show only partials with region set as left */
		<?php show_partials('list', 'left', $partial_list, $template); ?>
	</div>
	<div class="mid"><?php echo $template['body'];?></div>
	<div class="right">
		/* Will show only partials with region set as right */
		<?php show_partials('list', 'right', $partial_list, $template);?>
	</div>
</body>
</html>

Detail about the usage can be found in the actual helper file, also feel free to comment here and I will try my best to help out.

Posted in codeigniter | Tagged , , | Leave a comment

Google translate helper for codeigniter

Hello everyone,

I am back with a tiny contribution. Today I have created a nifty helper for codeigniter which uses the google translate api (v2).

In order to use the function you will require a google translation api key which you can get for free the google api console (https://code.google.com/apis/console).

After you have your key it has to be passed to the function along-with the text to be translated, the language from which it is being translated from and to the language it is translated to. The function returns the translated text which can be used to do further processing or can be also be echoed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
 
/* Develeoped by: faisal ahmed <thephpx(at)gmail.com–>*/
 
function google_translate($api_key, $text, $from_lang, $to_lang){
    $link  = 'https://www.googleapis.com/language/translate/v2?';
    $link .= 'key='.$api_key.'&source='.$from_lang.'&target=';
    $link .= $to_lang.'&q='.$text;

    $response = file_get_contents($link);
    $array = json_decode($response);
    return $array->data->translations[0]->translatedText;
}
 
?>
Posted in codeigniter | Tagged , , | 4 Comments

codeigniter: facebook social plugin – like button helper

Hello everybody,

I have just created a short helper to create facebook like button dynamically for any content, by just giving-in the URL of the page. Hope this one also helps you like my other helpers

Helper function:

1
2
3
4
5
6
7
8
9
10
11
if(!function_exists('facebook_like')){
 function facebook_like($url){
   $formlink  = '<iframe src="http://www.facebook.com/plugins/like.php?href=';
   $formlink .= urlencode($url);
   $formlink .= ';layout=button_count&show_faces=true&width=450&';
   $formlink .= 'action=like&colorscheme=light&height=21" scrolling="no"';
   $formlink .= 'frameborder="0" style="border:none; overflow:hidden;';
   $formlink .= 'width:450px;height:21px;" allowTransparency="true"></iframe>';               
   return $formlink;
  }
 }

Usage:

1
2
3
4
<?php
$url = current_url();
echo facebook_like($url);
?>

Note:
As you can see the function requires you to use the codeigniter’s native URI helper.

Posted in codeigniter | Tagged , , , , | 2 Comments

Codeigniter: Helper – absolute path helper

Recently I decided to give some more time to my blog and write some short but interesting posts. I will be writing some posts about custom helper functions that I have written which helps me in application development.

First on the list is a absolute path helper which creates an absolute path, relative to the base of the application. I call this function base_path(‘relative/url’);

1
2
3
4
5
if(!function_exists(‘base_path')){
    function base_path($relative_path_location){
        return base_url().$relative_path_location;
    }
}

The above is the code which will go into your helper file. The function formulates an absolute url from the given relative path based on base path of the application directory. It uses the existing base_url() helper function in codeigniter. So, you have make sure the URL helper is already loaded.

Example:

Suppose you want to tag an image which is located at “application-root/images/picture.jpg” to give its absolute URL in the img tag you can type as follows in your template/view file.

1
<img src="<?php echo base_path(‘images/picture.jpg’);?>" alt="picture"/>

If you application is hosted at domain.com then it will give http://www.domain.com/images/picture.jpg as the returned path where http://www.domain.com/ is the base_url();

thanks,

thephpx

Posted in Uncategorized | Leave a comment