Archive | Howto RSS feed for this section

Better performance on autoloading php classes

1 may

PHP Developer

Autoloading classes is quite useful to avoid including a lot of files during the coding. Moreover you will not have to repeat any include call.

The simplest example is this:

function __autload($name) {
require_once 'lib/'.$name.'.class.php';
}
$glab = new GraficLab();

It will include ‘lib/GraficLab.class.php’ file.

The thing is, each time you call class_exists() function, if the class does not exists, it calls __autload() function. If autloading handler is simple, ok, not problem, but if you want a complex autoload engine it will consume a lot of memory.

My purpose is to define a new function like this:

function gl_class_exists($class) {
return in_array($class, get_declared_classes());
}

From now, each time you want to check if a class is declared, use this function. Of  course, you will have to compare the autoloading method with this checking function; in my case is better to use this method.

Waiting your opinion!

Enhanced rounded images with CSS3

4 feb

As you may know border-radius can round images using CSS3. But you can enhance this feature putting that image inside a div, which will has overflow: hidden, a fixed size and border-radius instead of image.

What is the gap? This way you will be able to choose which part of image you want to see and round.

Take a look on next code.

HTML, an image of 300×300 pixels:
<div>
<img src="http://www.jordisalord.com/wp-content/uploads/2012/02/qr-jordisalord-300x300.png" alt="Jordi Salord @ Blog" />
</div>

 

CSS:
<style>
div.img-round {
overflow: hidden;
border-radius: 5px;
box-shadow:-1px 1px 2px #000;
height:280px;
width:280px;
}
div.img-round img {
margin-top:-10px;
margin-left:-10px;
}
</style>

 

The original image:
Jordi Salord's QR Code

The result:

Jordi Salord's QR Code

 

 

That’s all folks!

What do you think about this technique? Is there any other way to do it?

Enjoy this tip, I’ve recently used this technique to round non-editable images.

How to manually configure Plesk Virtual Host httpd.conf

10 ene

As you may know Plesk rewrites every apache configuration file on server. But it let’s you add some virtual host configuration inside each host directory.

You have to create httpd.conf files inside these directories:

  1. Domains
    1. /var/www/vhosts/domain.com/conf/httpd.conf
  2. Subdomains
    1. /var/www/vhosts/domain.com/subdomains/subdomain.com/conf/httpd.conf

 

Then, once you have finished with configuration files, you must say Plesk to reload these configurations:

  1. Per domain
    1. # /usr/local/psa/admin/sbin/websrvmng -u --vhost-name=domain.com
  2. Global
    1. # /usr/local/psa/admin/sbin/websrvmng -a

 

It is really useful to add permissions, rewrites, svn, or anything you want.

Ordenar portada WordPress

6 ene

Para ordenar la portada de un WordPress se debe modificar el archivo index.php del tema.

Y añadir estas tres líneas de código:
global $query_string;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($query_string . '&order=DESC&orderby=modified&paged='.$paged);

En este ejemplo s’está ordenando por fecha de modificación de forma descendiente, en lugar de hacerlo por fecha de publicación.

Se puede aplicar a cualquier zona del blog modificando otros archivos, como por ejemplo category.php.

Más información a: How to sort WordPress posts by modified date