Posted by: ferdous on: February 22, 2009
[ from now onwards I will write blog at: http://dynamicguy.com ]
Posted by: ferdous on: February 18, 2009
I wrote a class on HTML to PCL and Post Script conversion and submitted that to phpclasses. That class has been nominated for innovation award. Please vote for me.
Here you go: http://www.phpclasses.org/vote.html
Posted by: ferdous on: December 30, 2008
Recently I made a news bot named news@bot.im AKA newsbot24@yahoo.com with the help of a wrapper class wrote by Hasin Hayder. This cool API has been provided by imified recently to make your application IM enable easily . You may test my bot by sending any instant message to newsbot24@yahoo.com or sending a message from your GTalk. It will grab one of the latest 25 top news from www.news.google.com or www.bdnews24.com RSS feed. I have set caching time as 1200 so that it can be easily work with very less bandwidth. I used lastRSS class to grab the RSS feed as I am having some freight to use Google feed parser with JSON
You can make one just for FREE from www.bot.im All you need is to DOWNLOAD the wrapper class to do it quick. Alternatively you may read the quick and dirty documentation from HERE.
Now lemme reveal the source code I used for my news bot :p
<?php
// include lastRSS
include "lastRSS.php";
include "class.imified.php";
// Set cache dir and cache time limit (1200 seconds)
// (don't forget to chmod cahce dir to 777 to allow writing)
$rss->cache_dir = './temp';
$rss->cache_time = 1200;
$rss->cp = 'UTF-8';
$rss->date_format = 'l';
//initiating bot...
//@param pass your imified user credentials
$im = new ImifiedHelper("YOUR-API-KEY-GIVEN-FROM-IMIFIED","DEVELOPERS-NAME","PASSWORD");
if(!isset($_REQUEST['msg']))
{
echo "This is a newsbot. You may add it as news@bot.im or newsbot24@yahoo.com";
die();
}
//callback
$im->setCallback("callback");
function callback($message, $step, $network, $userKey)
{
global $im;
$message = strtolower($message);
if("inews" == $message){
// Create lastRSS object
$rss = new lastRSS;
// Try to load and parse RSS file of Slashdot.org
$rssurl = 'http://news.google.com/?output=rss';
$rs = $rss->get($rssurl);
if ($rs) {
$i = rand(0,25);
echo $title = strip_tags(htmlspecialchars_decode($rs['items'][$i]['title']."
"))."
";
echo $description = strip_tags(htmlspecialchars_decode($rs['items'][$i]['description']))."
";
}
else {
echo "Error: It's not possible to get $rssurl...";
}
$im->resetStep();
}
elseif("bdnews" == $message){
// Create lastRSS object
$rss = new lastRSS;
$rssurl = 'http://rss.bdnews24.com/rss/english/home/rss.xml';
$rs = $rss->get($rssurl);
if ($rs) {
$i = rand(0,25);
echo $title = strip_tags(htmlspecialchars_decode($rs['items'][$i]['title']))."
";
echo $description = strip_tags(htmlspecialchars_decode($rs['items'][$i]['description']))."
";
}
else {
echo "Oops! Looks like Server is Busy! to get ".$rssurl." Give it a try with inews";
}
}
else{
echo "Please type help to see available commands";
$im->resetStep();
}
}
?>
Thanks to hasin bro for your cool wrapper class
Posted by: ferdous on: December 25, 2008
At first I would like to thank www.docs.php.net for their clear and cool documentation. Recently I’ve gone through the differences in between php4 and php5. I’ve found some interesting things by studying this topic. I think you all should have a look if you want to be a good developer. If you want a better performance and more features in your application easily then this post is appropriate for you. Happy Christmas!!
Type Hinting
PHP 5 introduces Type Hinting. Functions are now able to force parameters to be objects (by specifying the name of the class in the function prototype) or arrays (since PHP 5.1). However, if NULL is used as the default parameter value, it will be allowed as an argument for any later call.
New Object Model
In PHP 5 there is a new Object Model. PHP’s handling of objects has been completely rewritten, allowing for better performance and more features. In previous versions of PHP, objects were handled like primitive types (for instance integers and strings). The drawback of this method was that semantically the whole object was copied when a variable was assigned, or passed as a parameter to a method. In the new approach, objects are referenced by handle, and not by value (one can think of a handle as an object’s identifier).
Many PHP programmers aren’t even aware of the copying quirks of the old object model and, therefore, the majority of PHP applications will work out of the box, or with very few modifications.
List of new Keywords
These words have special meaning in PHP. Some of them represent things which look like functions, some look like constants, and so on–but they’re not, really: they are language constructs. You cannot use any of the following words as constants, class names, function or method names. Using them as variable names is generally OK, but could lead to confusion.You will find detailed documentation on these new keywords by clicking on it.
abstract catch clone final implements interface instanceof namespace private protected public throw try
Backward Incompatible Changes
Although most existing PHP 4 code should work without changes, you should pay attention to the following backward incompatible changes:
Posted by: ferdous on: December 17, 2008
This wrapper class is a gift for my blog readers. I think the class is self descriptive. This is why I ain’t write how to use it bla bla bla…You can make pcl and ps files from html with this class. I have submitted this class at phpclasses too. You may have a look by clicking HERE. It runs both on Windows and *Nix envioronment.
html2pcl class starts here:
<?php
/* Description of wrapper class Html2pcl
* This class is used to produce .PCL and .PS file from HTML file
* @Author : Nurul Ferdous
* Version : 1.0.0
* Date : 16 Dec 2008
* License : Freeware
* Dependancy-1: html2ps package, you may get it from here: http://user.it.uu.se/~jan/html2ps.html
* you may install it from terminal by typing "sudo apt-get install html2ps" withpcl quote in kubuntu (in my case)
* html2ps uses perl
* Dependancy-2: Ghostscript, you may get it from here: http://pages.cs.wisc.edu/~ghost/
* Download it and run "make" command from terminal. you have to download and run exe installer if you use Windows
* The ps_output directory is used to store .ps files which are used to generate smaller sized pcl file
* keep in your mind that you should have write permission in "pcl_output" directory
*/
class Html2pcl {
public $device = 'laserjet'; //alternatively you may use 'epson' etc as printers
public $paperSize = 'a4'; //alternative you may use 'letter' etc as papersize
function __construct(){
//checking whether the directory named "out" already exists or not
if(!file_exists("pcl_output")){
mkdir("./pcl_output", 0755);
}
//checking whether the directory named "ps_output" already exists or not
if(!file_exists("ps_output")){
mkdir("./ps_output", 0755);
}
}
function __destruct(){
//Clearing file status cache
clearstatcache();
}
function isWinServer()
{
return !(strpos(strtoupper($_SERVER['SERVER_SOFTWARE']), 'WIN32') === false);
}
//please don't use $htmlFileName without "http://" rather use like this "http://www.google.com"
//please use $pclFileName without the extension like "google"
function makePCL($htmlFileName, $pclFileName){
$file = './pcl_output/'.$pclFileName.'.pcl';
if($this->isWinServer()){
//checking whether the file name given as parameter is already exists or not
if(!file_exists($file)){
exec("perl html2ps $htmlFileName > ./ps_output/".$pclFileName.".ps");
exec("gs -sDEVICE={$this->device} -sPAPERSIZE={$this->paperSize} -sOutputFile=./pcl_output/$pclFileName.pcl -dNOPAUSE -q ./ps_output/$pclFileName.ps -c quit");
}
}
else{
if(!file_exists($file)){
exec("html2ps $htmlFileName > ./ps_output/".$pclFileName.".ps");
exec("gs -sDEVICE={$this->device} -sPAPERSIZE={$this->paperSize} -sOutputFile=./pcl_output/$pclFileName.pcl -dNOPAUSE -q ./ps_output/$pclFileName.ps -c quit");
}
}
}
}
?>
Example usage starts here:
<?php
/*
* Usage of html2pcl class
*/
require_once('class.html2pcl.php');
$obj = new Html2pcl;
//please don't use $htmlFileName without "http://www." rather use like this "http://www.google.com"
//please use $pclFileName without the extension like "google"
$obj->makePCL("http://www.google.com", "google");
?>
Recent Comments