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

How to hide image to the visitor right click

Well, I found this hack in http://coollogo.net/cool_logo_70/ a good resource for social icon.

Given you want to show image.jpg, just put a transparent image in a div tag with the background-image: url('image.jpg') this way:

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

Defer javascript execution using data

Due to page performance you should load javascript at the end of page (see http://developer.yahoo.com/performance/rules.html), at least all javascript you can defer to load. There are script that have to load at the very begin of page. But are you sure there is no option?

Well, actually this is a critical reflection on my own script. When I wrote imagedata drupal example module I replaced to {'imagedata ...} a direct call to jquery plugin.

There are a lot of situation where javascript function is called

Simplepie and CodeIgniter

yes, found: http://www.haughin.com/code/simplepie/
and tried with php 5.3 installation ... simply do not work

I recalled there was a problem in simplepie for assign new by reference, just downloaded newer code from http://simplepie.org/ ... still same problem.

So

sed 's/=&\ new/=\ new/' simplepie.inc > Simplepie.php

adding if ( ! defined('BASEPATH')) exit('No direct script access allowed'); to first line, removing ?> from last line, make things work.

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” />
Syndicate content