Drug preguntas

Some advices to setup a flexible WordPress site

PHP No Comments »

I love WordPress for the simple reason that I never had to open Netbeans in a year. I just ran PHPmyadmin one time, and my FTP client another time. It was due to two themes that were displaying blank pages once I edited their footers. This issue was everywhere, admin pages included. These themes were telling me that they were under CC licence and I had no right to edit their footers. Without a doubt the images are under the CC licence, but WordPress being under GPL licence, I’m dubitative about the PHP/HTML/CSS  theme files CC licence. Anyway if ever your install a theme, and some of your plugins (Google analytics for example) add some code to the footer, it could entirely break your site. If it happens to you there is some information on this page to reset the default theme.

To come back to the WordPress superbness, I would say it is:

  • the easiest upgrade/update process ever (themes and plugins included)
  • plugin search functionality and plugin installation from the administration pages
  • lots and lots of plugins, most of them working on every updated WordPress
  • Possibility of configuration much deeper than my first look suggested
  • Thousands of beautiful free themes

There is something I learned about themes. Less they have functionalities, more you will like them. Few month ago I started to buy some very cool themes on Themeforest. They are all Flashy and JQuery with great PSD files. They also come with a considerable amount of coding by the author. The problem is that if ever you want to switch to another theme, you could lose widgets/menus/functionalities/… I found out that all the functionalities these themes offer can be found in some free plugins. Except if you want to do a business site, I suggest you to only install themes that don’t provide any special ‘stuff’. A theme should be only about the look. If you are like me you want to change the theme times to times, don’t be depending from a theme.

I’m now going to list the essential plugins I found and use for my Wordpres blog, maybe some of them will interest you.

Akismet: the pre-installed anti-spam plugin is easy to set up and effective.

Contact Form 7: a simple contact form. Just insert a special [shortcode] in a page.

Incarnate for WordPress: because the WordPress avatar system is quite restrictive to one service (Gravatar), this plugin lets people search and choose their own avatar image from profile images of famous community. And that, without being registered.

Polaroid Gallery: Wordpress comes with a gallery attached to each post. You can install many plugin to display it in a better way. This plugin is the one I use on my blog. All my comic reviews use it.

Quick cache: a cache system that works pretty well, once installed my blog got a massive boost.

Sketch Bookmarks: it’s the massive “SHARE->” at the bottom of my post.

TS Custom Widgets: probably the best plugin. It lets you setup where you want your widgets being displayed (by categories, posts, pages, front page…). With it you can design quite complex site, you are just limited by your imagination.

WP-PostRatings: people can vote for a post.

WP-Stats-Dashboard: display nice statistics on the dashboard. Even though Google Analytic service got the best statistics, I do prefer to check my stats from WordPress with it.


Now you’re ready to blog stuff like that…

How to quickly edit a file with a Netbeans macro

PHP No Comments »

I just discovered Netbeans macro functionality. I had a huge file to edit. On every lines, I had to add a string on the 20th position. Instead of creating a little program (it would have take me 15 minutes or more), in Netbeans I selected Menu > Edit > Start Macro Recording:
1- I clicked with the mouse on the position where I wanted to add my string.
2- I added my string.
3- With the keyboard, I moved my cursor on the next position in order to enter the next string.
4- I selected Menu > Edit > Stop Macro Recording and assigned the macro to a shortcut key.
5- I pressed the shortcut key as long as my steps needed to be executed. 6 seconds later my huge file was totaly edited.

You can do a lot more stuff with Netbeans macro, fantastic IDE. A shame that it doesn’t have git and it is sometimes annoying with CVS patches, it would be the perfect IDE. Oh but Nebeans 6.9 should have Git ! What to ask more ?

Create a PHP array containing the code of the ISO 3166-2 country subdivisions

Apple, PHP No Comments »

It’s not that easy to find a ISO 3166-2 country region code file. After some Google searches, I ended up on a Debian page with the ISO codes. The thing requires Git. As I will install it soon or later on my Mac OSX, I decided it was the good moment and I installed Git with an installer. I’m not that much a command line guy :)

Then I retrieved the git repository of the Debian page:

git clone git://git.debian.org/git/iso-codes/iso-codes.git

After 10 minutes, I got all the stuff, and found a file of 300Ko (iso-codes/iso_3166_2/iso_3166_2.xml). Note that they also have different translation for it, they did a good job at Debian.

Finally I just needed a little PHP script. I quickly found one about the country codes and modified it to support regions:

<?php
$filecontent = file_get_contents('iso_3166_2.xml');
$xml = new SimpleXMLElement($filecontent);

$out = "<?php
$regions = array();
";

foreach ($xml->iso_3166_country as $country)
{
    foreach ($country->iso_3166_subset as $regions) {
       foreach ($regions->iso_3166_2_entry as $region) { 
          $out .= "\$regions['".$country->attributes()->code."']['".$region->attributes()->code."']='"
                  .addslashes($region->attributes()->name)."';";
       }
   }
}

file_put_contents('isoregionnames.php', $out);

How to parse the phpdoc

PHP No Comments »

your goal: you created some new annotations into the phphdoc and you’d like to retrieve these information. So you are looking for a PHPdoc parser.
Get the Zend Framework. Note that the Zend Server component should probably be enough. Here some code to use it:

/// load the Zend Framework – You’ll probably need to change these two lines
require_once “Zend/Loader.php”;
Zend_Loader::registerAutoload();

/// I load my personal library class
require_once(library.php);

/// The magic Reflection class is going to do the work for you – Here I load my personal class named “library”
$reflection = Zend_Server_Reflection::reflectClass(“library”);

/// We’re going to retrieve the docblocks of the library class functions
foreach($reflection->getMethods() as $method){
$docBlock = $method->getDocComment(); //here we retrieve the docblock of a class function
/// then I’m parsing the docblock, modify the regular expression in order to retrieve your own phpdoc annotation
preg_match_all(‘/\s*\*\s*@(subparam|subreturn)\s+(\w+)\s+(\$\w+(?::\w+|->\w+)+)((?:\s+(?:optional|required|multiple))*)/’, $docBlock, $matches);

/// test display to see what we get
echo “<pre>”;
var_dump($method->getName());
var_dump($matches);
echo “</pre>”;
}

Netbeans, the IDE for PHP

PHP No Comments »

Ok make it clear, I love Netbeans. It’s all in the box with a ultra easy installation and a transparent update system. It does what you expect from a commercial IDE, and it’s free. So if you do program in PHP, I invite you to try it.

My first Netbeans, the version 3

I started with Netbeans 3 for the i18n Java function.

Really short Zend XML-RPC client/server

Moodle, PHP No Comments »

A really short XMLRPC client/server using Zend framework. I let you change your include/require. The require lines used here work for Moodle.

Server.php

[php]///require-include TODO: change these lines for your project
require_once(dirname(__FILE__) . ‘/../../config.php’);
include ‘Zend/Loader.php’;
Zend_Loader::registerAutoload();

///the server
$server = new Zend_XmlRpc_Server();
$server->setClass(‘xmlrpc_authentication’, ‘authentication’); //second parameter is the spacename for xmlrpc
echo $server->handle(); //don’t forget echo

class xmlrpc_authentication {

/**
* following the ‘struct’ is the important doctype, but
* you can still use the | notation if you need to define another type
* @param array|struct $params
* @return integer
*/
function get_token($params) {
if ($params['username'] == ‘wsuser’ &amp;&amp; $params['password'] == ‘wspassword’) {
return 465465465468468464;
} else {
return 0;
}
}
}
[/php]

Client.php

[php]
///require-include TODO: change these lines for your project
require_once(‘../../../config.php’);
include ‘Zend/Loader.php’;
Zend_Loader::registerAutoload();

$client = new Zend_XmlRpc_Client(‘http://your_project_url/server.php’);
//Note: arguments (here it’s an associative array) are into an array
echo ‘token (call) is : ‘ . $client->call(‘authentication.get_token’, array(array(‘username’ == ‘wsuser’, ‘password’ ==’wspassword’)));
[/php]

Ubuntu, XP and Vista

Moodle, PHP No Comments »

For the last 6 months I’ve switched from Vista to Ubuntu. In this beginning of 2009, here is my opinion about the different operating systems that I used at Moodle HQ for developping PHP web applications.

Windows Vista: when I first arrived at Moodle HQ I asked for Vista. I hadn’t used it before. First it’s been really cool. I like the UAC, make me feel more secure. But WAMP server started to crash really often, and due to some bad memory I had a lot of blue screens.  I switched to Ubuntu. I don’t use Vista anymore. The automatic update system is just the worst I know. Every few time I boot on Vista, it blocks me to work during minutes. The same thing happens when I turn off the computer. I don’t feel to be blocked by XP when it updates. And Ubuntu is even smoother than XP.

Ubuntu 64: I had to deactivate the crappy file indexation system and set apache in order to run a unique server instance at the same time. Once these two things done, all worked fine. Excepted that 2Go of RAM wasn’t enough to runs Firefox + Netbeans + 1 virtual machine. In order to run these three softwares I would advice at least 4Go, and 6Go to be comfortable. For running that much memory on your computer, you need the 64bits Ubuntu version and a Dual/Quad core processor.
In Ubuntu, I love the update system,  I feel more secure about virus and other malwares, and the apache server never crashes.

Ubuntu screenshot with XP running on VirtualBox

Windows XP: I installed it in a virtual machine. It runs on Virtualbox. VirtualBox is free and really give its carrot to VmWare. Windows XP with VirtualBox starts/stops way quicker than on a normal install. I gave 1G of RAM to the virtual machine. I installed Multiple IE so I can test every IE versions (5.5, 6 and 7).
I find XP very cool to run Flex Builder 3 and all Adobe softwares. Windows XP is also the system I installed years ago on my personal notebook. On this old computer, Chrome on XP runs faster than Firefox on Ubuntu 8.10.

I think that Ubuntu + XP on virtualbox is an excellent choice for PHP developers.

How to create a Flex client for a Zend_amf server

Flex, PHP No Comments »

Here are some steps to help to set up a basic working Flex client / Zend_amf server.

You can find the Zend_amf library and some explanation on Wade Arnold blog

First create the server.php
include “Zend/Loader.php“; //this will probably need to be different for you (see here)

Zend_Loader::registerAutoload();
$server = new Zend_Amf_Server();
$server->addFunction(‘hello’);
$response = $server->handle();
echo $response;
function hello($name, $greeting = ‘The server say Hi to’)
{
return $greeting . ‘, ‘ . $name;
}

Then into Flex Builder create a new project. Into the Project Properties > Flex Compiler, add the argument
-services “C:your_project_locationsrcservices-config.xml”

Create this “services-config.xml” under /src
<?xml version=”1.0″ encoding=”UTF-8″?>
<services-config>
<services>
<service id=”zend-service”
class=”flex.messaging.services.RemotingService”
messageTypes=”flex.messaging.messages.RemotingMessage”>
<destination id=”zend”>
<channels>
<channel ref=”zend-endpoint”/>
</channels>
<properties>
<source>*</source>
</properties>
</destination>
</service>
</services>
<channels>
<channel-definition id=”zend-endpoint”
class=”mx.messaging.channels.AMFChannel”>
<endpoint uri=”http://your_amf_server_url/server.php
class=”flex.messaging.endpoints.AMFEndpoint”/>
</channel-definition>
</channels>
</services-config>

Finally in your main.mxml
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute”>

<mx:RemoteObject id=”myservice”
showBusyCursor=”true”
source=”your_flex_client_project_name
destination=”zend”
result=”Alert.show(event.result.toString())”>
</mx:RemoteObject>

<mx:Script>
<![CDATA[
import mx.controls.Alert;
]]>
</mx:Script>
<mx:Button label=”Call service” click=”myservice.hello(‘Yourself‘)”/>

</mx:Application>

Theme by NattyWP