phpXperts seminar – 2011

phpXperts is the biggest PHP group from Bangladesh. It was started by Hasin Hayder as a yahoo group and is a great place for newbies to ask question and to solve their problems. Now the most part of the activity of this group is based on the facebook group for phpXperts .

The annual seminar of this group was arranged this year for the 5th time. Here is the official page of the seminar 2011. You can find the topic list and along with their speakers there.

The seminar was a blast. Too many great speakers with great topics and huge number of audience was the life of the seminar. All the speakers and the listeners enjoyed this event very much.

There is a special portion of the seminar this year and it’s called 6 minutes of fame. It was a chance for new comer speakers to speak for this first time and I was a part of this great opportunity to speak in front of the audience. So I had only 6 minutes to talk on something and I choose a topic from my favorite WordPress. The topic title was “WordPress themes & Plugins development – Best Practices”. As the time was very short, I wanted to cover some of the important features that a WordPress developer should take care of. Here is the slide -

Things to do after installing Ubuntu 11.10 Oneiric Ocelot

The new Ubuntu is here 2 days ago. I was using Natty Narwhal (11.04) and didn’t take any risk to use Gnome 3 there. But I couldn’t resist myself to switch to Gnome 3 this time. Here is some things I did after installing 11.10 -

[Note: If you are in Bangladesh, change the default mirror to Main Server or Server for United States, it'll save a lot of troubles]

1. Update your repository first

sudo apt-get update

2. Install resticted extras package for audio/video codec support and Vlc

sudo apt-get install ubuntu-restricted-extras vlc

3. Surely you want switch to Gnome 3, aren’t you?

sudo apt-get install gnome-shell

4. Install Gnome shell Tweak tool

sudo apt-get install gnome-tweak-tool

Gnome tweak Tool Read the rest of this entry »

Galaxy Mini S5570 downgrading Gingerbread 2.3.4 to Froyo 2.1

After I saw the latest release Gingerbread 2.3.4 in samfirmwire.com about a month ago, I decided to upgrade my Galaxy Mini from Froyo (2.1). I upgraded without any hassle. The experience was quite good. The phone was more faster and also the touch response was really good. I was happy with that :D

But, as Bangla is my native language and I use it a lot in my online activity including twitter, facebook, forum, etc – it was a must have support for my phone and I had that in my default ROM (S5570DDKC1). Although I had root my phone and install a new font. What problem I faced that, the gingerbread build of the ROM hadn’t support for complex script rendering. Although it was an Asian build, but it was lacking of complex script rendering support. So I couldn’t see Bangla clearly on the Gingerbread. Replacing the DroidSansFallback.ttf font was showing the characters, but rendering was faulty. So I decided to downgrade my Android OS to the Froyo stock ROM. I tried two Gingerbread ROM that time, one is S5570ZSKPB – China build and other one was S5570XXKPK – Russian build.
Read the rest of this entry »

Simple pagination system in your WordPress plugins

May be you are developing a plugin or a theme and it has something to do with handing some pagination of your custom tables data. Here’s how we can simply manage it, I am not going to build all the admin panel stuffs, but just showing you the process.

Step 1:

Lets get the page number from the url query string. If we don’t find anything, we’ll set the page number to 1.

$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;

Step 2:

Now we need to set per page entry limit and the page offset. We will use the limit and offset to get data from our MySQL query. If you are confused about the offset, may be you’ve seen it on PHPMyAdmin like this: "SELECT * FROM `table_name` LIMIT 0, 10". Here, we are getting the first 10 entries from our database. If we want get the next 10 entries, our limit will be "LIMIT 10, 10". So the first digit for the limit is the offset. It tells us from where we’ll get our next entries.

$limit = 10;
$offset = ( $pagenum - 1 ) * $limit;

So, by this two lines we are setting the limit and our offset dynamically. Read the rest of this entry »

Tags:

Add your custom columns to WordPress admin panel tables

What? What did you said on the title? Well, I am not sure this is an appropriate title. But I am going to explain it to you.

Lets say, you are making a theme or a WordPress plugin and you want to show something in the admin panel like this:Custom Post Column

We will see how can you add those columns to the admin panel tables and manipulate data on the table rows. Well, this is very easy to do, because WP has a really nice API to work with.

Now we will add those two columns to our admin panel’s post listing table. Here is the code:

<?php
function test_modify_post_table( $column ) {
    $column['test_budget'] = 'Budget';
    $column['test_expires'] = 'Expires';

    return $column;
}
add_filter( 'manage_posts_columns', 'test_modify_post_table' );

Read the rest of this entry »

Tags:

Working with IDE One API

I am very lazy to write any post. To be frank, I don’t find anything to write :roll:

Today I found something to write about. It’s nothing, but some bunch of codes. I’ll describe them, they are self explanatory. The idea is to write code and compile them On-The-Cloud. It’s actually using “IDE One” api to compile any programming source code, and give the result back. It’s useful in the devices where you can’t use any compiler, like mobile phones. There are already many applications for mobile that works the same way. Today I just wrote it in PHP. It uses SOAP protocol to communicate to the server. Enough talks :P

<?php

$user = 'tareq'; //--> API username
$pass = '********'; //--> API password

$lang = 1; //--> Source Language Code; Here is 1 => C++

$code = '#include<stdio.h>
int main() {
	printf("hello");
	return 0;
}
'; //--> Source Code

$input = '';
$run = true;
$private = false;

//create new SoapClient
$client = new SoapClient( "http://ideone.com/api/1/service.wsdl" );

//create new submission
$result = $client->createSubmission( $user, $pass, $code, $lang, $input, $run, $private );

//if submission is OK, get the status
if ( $result['error'] == 'OK' ) {

    $status = $client->getSubmissionStatus( $user, $pass, $result['link'] );

    if ( $status['error'] == 'OK' ) {

        //check if the status is 0, otherwise getSubmissionStatus again
        while ( $status['status'] != 0 ) {
            sleep( 3 ); //sleep 3 seconds
            $status = $client->getSubmissionStatus( $user, $pass, $result['link'] );
        }

        //finally get the submission results
        $details = $client->getSubmissionDetails( $user, $pass, $result['link'], true, true, true, true, true );
        if ( $details['error'] == 'OK' ) {
            var_dump( $details );
        } else {
            //we got some error
            var_dump( $details );
        }
    } else {
        //we got some error
        var_dump( $status );
    }
} else {
    //we got some error
    var_dump( $result );
}

Here is a working demo. It might be buggy, may be you could help me to find those bugs :)

Debugging Zend Framework using firebug

You can use firebug to debug your Zend Framework application. May be you are using print_r(), var_dump() or Zend_Debug::dump($var), they prints the information in your application. But, with the help of FirePHP add-on for Firebug, we will be able to dump our variable on firebug console :D

First install the FirePHP add-on for your Firebug. Then you can use the following snippet anywhere to dump your variables to firebug console -

$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log( $writer );
$logger->log('My Sample Log', Zend_Log::DEBUG);

The second parameter of the Zend Logger is a constant. You can use 0-7 (zero to seven) as a parameter. Here is the details – Read the rest of this entry »

Get the executed query in Zend Framework

It seems very difficult when you are working with Zend Framework and you are getting some error for some SQL query. It’s hard to debug this issue for you sometimes. Then you may need to know what was the query executed by Zend_Db_Table_Abstract that was generating the precious(!) error?. Well, that’s simple like the snipped below.

May be you have a Profile Model that extends Zend_Db_Table_Abstract and you have a getUserByName function.

class Application_Model_Profile extends Zend_Db_Table_Abstract {
	protected $_name = 'users';

	function getUserByName( $user_name ) {
        $row = $this->fetchRow("username = '$user_name'");

        if (!$row) {
            return false;
        }

        return $row->toArray();
    }
}

We will write our function to debug the query like this:

class Application_Model_Profile extends Zend_Db_Table_Abstract {
	protected $_name = 'users';

	function getUserByName( $user_name ) {
        $this->_db->getProfiler()->setEnabled(true); //start the profiler
        $row = $this->fetchRow("username = '$user_name'");
        $query = $this->_db->getProfiler()->getLastQueryProfile()->getQuery(); //get the last executed query
        var_dump( $query ); //show the query
        $this->_db->getProfiler()->setEnabled(false); //disable the profiler

        if (!$row) {
            return false;
        }

        return $row->toArray();
    }
}

What we did?

  1. We enabled the profiler before executing the query
  2. Then we executed our query
  3. Stored our raw query in a variable and print it
  4. Finally disabled the profiler

That might help you to debug the SQL :D

Create your own phone synchronisation server

I use Siemens CX70 mobile phone since 2005 and still I’m using it and it’s my only phone. Anyway, it’s not funny :P

My phone’s display is going to die soon, the process already started :cry: . I love this phone for it’s customisable features. If somehow it dies or it’s stolen then I’m so dead. My 5/6 years all contact will be gone. So the best process is to sync it somewhere, so all the contacts remains and I can use those contacts to other phone. I started to dig today about this issue.

My OS is ubuntu and I was not able to pull those contacts from mobile to my laptop. I can’t send the contact’s via bluetooth, because it has only infra-red. So I was looking for some sync service and I found one. After 1 hour of effort I was able to sync my contacts with the memotoo. But after syncing my contacts it says I reached the limit and I need an account upgrade :mad:

May be there are some other cool services to sync free and I don’t know about them. If you know some, please let me know. But I decided to setup a service on my server only for me :D and I found mooha. After looking into it, I found very easy to set it up.

The process is very easy, download the script from google code. There is sql file for database table creation. Create a database on your server and import the sql file. Now give the database credentials on the config.php file and you are done :D

The default username and password is mooha. You can change it and/or add as many user as you want.

It’s time to setup my phone’s remote synchronisation tool. I gave my mooha server address like http://example.com/mooha/index.php and my username/password and contact path it synced successfully :cool:

Bought Amazon Kindle for E-Book reading

I was looking for a e-book reader device for my reading purpose, because I am not comfortable reading in the laptop screen. I went to know about Amazon Kindle device and I was looking for buying it. It’s an awesome device for e-book reading experience. But from Bangladesh it’s very hard to buy online. Paypal is not available and international transaction is also not available in our country. If I somehow manage to buy it, there is no way to bring the device to our country.

The only solution was to buy it online, then ship it to any country that supports shipping by amazon.com and someone is there whom I know. Then bring the device by any of those guy’s. Bring it by postal service is not secure in Bangladesh and if somehow it reaches to Bangladesh, the customs department will do extra charge to release it. It’s so much pain :( Read the rest of this entry »