Daniele Cruciani
Programmatore Developer PHP/MySQL Freelance
mobile: +39 3489215204

icq skype msn linkedin fb t ff youtube picasa google
seconds to the end of World
End of World 21 December, 2012 11:11:00
Hire me before that day! | don't bother

Blogs

Come nascondere le immagini al right click context menu del visitatore

Ho trovato questo hack in http://coollogo.net/cool_logo_70/ una buona risorsa per le social icon.

Poniamo che deve essere mostrata image.jpg, allora basta mettere una immagine trasparente in una div con background-image: url('image.jpg'), in questa maniera (mostrando linkedin.png):

Why not to use remove link

This is my experience: I have to rewrite administration page where
there is remove button (in a form) with only javascript confirm.

I thought: "no one had problem with no limitation in the past, why they
should now? I'll use a link with javascript confirm.

It happened I have a dashboard page where is listed the last entries
and links for update and delete its. It happened that few day later 20
entries was deleted and I was looking for what caused the problem for
one day.

I supposed no one would be so silly to click on delete for 20 times

Google Chrome no-cache and Login throw oauth services

I found this very annoying, it seem chrome optimization make it not works things like "login via facebook" or "login via twitter" button with this browser and make it wait forever.

I implemented oauth support for http://www.cellularmagazine.it/recensioni/inserisci.php and had a similar problem: Expires setted to access plus 10 minute (via .htaccess , this happen to set Cache-Control header too) and google do not reload the actual page but use the one in cache. I would suggest to remove Expires header or set it to past data, but I found out adding

php goodies: filter

Filter is in php by default from 5.2.0 and is a usefull library for web developer, so it is the time to make use of it.

It was created for validation and sanitization of foreign input, that is GET, POST, COOKIE, or anything that you can't trust on.


With php filter one can tests if a variable is present in the current request:

if(filter_has_var(INPUT_POST,'login')) {
  //manage login
}

wwwsqldesigner short review

Install

Download from http://code.google.com/p/wwwsqldesigner/
Very easy installation: you need a webserver running, unpack
wwwsqldesigner it in a folder, setup your virtual host (I use
personal domain for my pc), all done!

Use

There is a small tool bar to the right, very simple and intuitive to
use, it is grouped in 4 areas:

  1. Save/load
  2. Table actions (Add,Edit,Keys,Remove,Align,Clear)
  3. Field actions (Add,Edit,Up/Down,foreign key management, remove field)
  4. Option & Documentation

Differire l'esecuzione di javascript usando i dati

Dal punto di vista delle performance si dovrebbero caricare i javascript alla fine della pagina (vedere http://developer.yahoo.com/performance/rules.html), almeno tutti i javascript di cui si può differire il caricamento. Ci sono script che devono essere caricati all'inizio della pagina... Ma siamo sicuri che non c'è altra possibilità?

Beh, in realtà questa è una autocritica su di un mio script. Nel codice di imagedata drupal example module rimpiazzo {imagedata ...} con una chiamanta alla funzione del plugin jQuery.

jquery Form Hint plugin (mine)

This is my view of form hint plugin: show a div over with the title content inside, instead of replace text in input elements and match it with placeholder
simply run $(selector).formHint() on all form element and title is used as hint


See also http://code.google.com/p/jquery-watermark/

shuffle db table order

simple code to shuffle a table ... with php shuffle:

$result = $mysql->query("SELECT id FROM $table ORDER BY id");
$rows = $result->num_rows;
$order = shuffle(range(1,$rows));
while($row=$result->fetch_row()) {
  $num=array_shift($order);
  $mysql->query("UPDATE $table SET rand_sort=$num WHERE id=".$row[0]);
}

added:
with MySQL RAND():

$result = $mysql->query("SELECT id FROM $table ORDER BY RAND()");
for($i=1;$row=$result->fetch_row();$i++) {
  $mysql->query("UPDATE $table SET rand_sort=$i WHERE id=".$row[0]);
}

Ajax frontend for my backoffice in jQuery and PHP

This is my way to organize php for a simple jQuery frontend ajax based:

1.in a administration page include the php that generate html for each box
2.for each box setup behavior in Javascript
3.let each php manage POST request (for change/update) and GET request for show content


So in admin.php we could have something like that

<img src=”button.png” id=”btn_change” />

Fix SEO problem in drupal (give 301 to node/xx request)

this was a problem with www.tecnomagazine.it :

http://www.tecnomagazine.it/recensioni/casio-exilim_ex-z60/442

could be accessed from /node/442

Solution is to redirect all /node/[0-9]* url to the aliased one
... and is very simple in code:

includes/path.inc :

function drupal_init_path() {
  if (!empty($_GET['q'])) {
    // add this conditional
    if(preg_match('/node\/[0-9]*$/',$_GET['q'])) {
      include "includes/common.inc";
      $newq = trim(url($_GET['q']),'/');
      if($newq!=$_GET['q']) {
Syndicate content