tolerant php strtotime

If you want to enlarge strtotime php function to be tolerant about funny date (especially in mail header), here is a little function :

function strtotime_tolerant($time)
{
$datetime_header = strtotime($time) ;
if ($datetime_header === false)
{
if (preg_match(‘/(Wen, .*)/’, $time))
{
$time = (preg_replace(‘/(Wen,) (.*)/’, ‘Wed, ${2}’, $time));
}
if (preg_match(‘/(Sut, .*)/’, $time))
{
$time = (preg_replace(‘/(Sut,) (.*)/’, ‘Sat, ${2}’, $time));
}
if (preg_match(‘/(Tues, .*)/’, $time))
{
$time = (preg_replace(‘/(Tues,) (.*)/’, ‘Tue, ${2}’, $time));
}
if (preg_match(‘/(.* \d\d:\d\d:\d\d) (.\d{4})/’, $time, $matches))
{
$time = $matches[1].’ ‘.$matches[2];
}

if (preg_match(‘/(.* \d\d:\d\d:\d\d) (\d{4})/’, $time))
{
$preg_time = (preg_replace(‘/(.* \d\d:\d\d:\d\d) (\d{4})/’, ‘${1} +${2}’, $time));
}
if (preg_match(‘/(.* \d\d:\d\d:\d\d) (UT)$/’, $time))
{
$preg_time = (preg_replace(‘/(.* \d\d:\d\d:\d\d) (UT)$/’, ‘${1} ${2}C’, $time));
}
if (preg_match(‘/(.* \d\d:\d\d:\d\d) (CEDT)$/’, $time))
{
$preg_time = (preg_replace(‘/(.* \d\d:\d\d:\d\d) (CEDT)$/’, ‘${1} +0200’, $time));
}
if (preg_match(‘/(.* \d\d:\d\d:\d\d) (.0060)/’, $time))
{
$preg_time = (preg_replace(‘/(.* \d\d:\d\d:\d\d) (.0060)/’, ‘${1} +0100’, $time));
}

if(isset($preg_time))
{
$time = $preg_time;
}
}

return strtotime($time);
}

blink css property in IE

IE doesn’t support blinking property :

text-decoration: blink;

You can achieve this effect with (compatible FX and IE) :

.blinking_zone
{
visibility: expression((Math.floor(new Date().getTime()/500)%2)?”visible”:”hidden”);
text-decoration: blink;
}

Reset default theme in drupal without admin / with mysql

You will find usefull information about this in this article: http://drupal.org/node/200774

Situation:
Either you have installed or modified a theme that just breaks everything, or you’ve deleted the current theme without disabling it first.

As you’ve now learned, you should have switched out of the theme via administration before destroying it, because you are left with nothing or almost nothing as a UI to work with now.

But we can probably recover.

If you see some content but no navigation blocks
We can fix up the themes by going directly to the required pages.

  1. You’ll have to be logged on, so enter http://example.com/?q=user in the browser. Logon as normal. (use your own Drupal path of course)
  2. Enter http://example.com/?q=admin/build/themes (D5) or http://example.com/?q=admin/themes (D4) to see a version of the themes page. Select a valid theme (eg BlueMarine) and things should be in a state where you can continue.

If you see no content at all, maybe garbage or a totally blank screen or the above doesn’t work…
We need to do surgery on the database.
It’s easier if you choose a theme name that you know used to work, eg ‘garland’ or ‘bluemarine’ for D4.

Either on the commandline, or via an administration interface (eg PHPMyAdmin) enter the following query

UPDATE system SET status=1 WHERE name = 'garland';

Then either:

UPDATE variable SET value='s:7:"garland"' WHERE name = 'theme_default';
TRUNCATE cache;

Note that ‘s:7’ refers to the length of the following string. Modify as needed. This is database surgery, tricky stuff.
OR
If you are using per-user themes, and you’ve just messed it up for yourself as admin, try

UPDATE users SET theme='garland' WHERE uid = '1';

Be careful, as getting either of those lines wrong can mess things up just as badly.

If you see some of the theme, but no navigation blocks, you may be able to proceed as in the first case, described above.

That didn’t work
It’s hard to guess how badly your system is damaged at this point. Did you delete the phptemplate directory?
Try re-uploading the entire contents of the /themes directory from a clean distribution of the exact same version of Drupal.

FCKEditor + AjaxFileManager

Default file browser embedded with FCKEditor is very light.

I prefer AjaxFileManager, a rich browser / uploader / manager for your files, most intuitive.

But, in order to include it with your FCKEditor installation, you need to tweak some files.

When following directives here, step by step : http://www.phpletter.com/Our-Projects/Fckeditor-Ajax-File-Manager-Project/ , you will have to :

  • put  all the “ajaxfilemanager” directory in “filemanager/browser” directory of fckeditor
  • edit fckconfig.js to get something like that :
    • FCKConfig.LinkBrowser = true ;
      //FCKConfig.LinkBrowserURL = FCKConfig.BasePath + ‘filemanager/browser/default/browser.html?Connector=’ + encodeURIComponent( FCKConfig.BasePath + ‘filemanager/connectors/’ + _FileBrowserLanguage + ‘/connector.’ + _FileBrowserExtension ) ;
      //FCKConfig.LinkBrowserWindowWidth    = FCKConfig.ScreenWidth * 0.7 ;        // 70%
      //FCKConfig.LinkBrowserWindowHeight    = FCKConfig.ScreenHeight * 0.7 ;    // 70%
      FCKConfig.LinkBrowserURL = FCKConfig.BasePath + ‘filemanager/browser/ajaxfilemanager/ajaxfilemanager.php’ ;
      FCKConfig.LinkBrowserWindowWidth    = 782 ;
      FCKConfig.LinkBrowserWindowHeight    = 440 ;FCKConfig.ImageBrowser = true ;
      //FCKConfig.ImageBrowserURL = FCKConfig.BasePath + ‘filemanager/browser/default/browser.html?Type=Image&Connector=’ + encodeURIComponent( FCKConfig.BasePath + ‘filemanager/connectors/’ + _FileBrowserLanguage + ‘/connector.’ + _FileBrowserExtension ) ;
      //FCKConfig.ImageBrowserWindowWidth  = FCKConfig.ScreenWidth * 0.7 ;    // 70% ;
      //FCKConfig.ImageBrowserWindowHeight = FCKConfig.ScreenHeight * 0.7 ;    // 70% ;
      FCKConfig.ImageBrowserURL = FCKConfig.BasePath + ‘filemanager/browser/ajaxfilemanager/ajaxfilemanager.php’ ;
      FCKConfig.ImageBrowserWindowWidth  = 782 ;
      FCKConfig.ImageBrowserWindowHeight = 440 ;

      FCKConfig.FlashBrowser = true ;
      //FCKConfig.FlashBrowserURL = FCKConfig.BasePath + ‘filemanager/browser/default/browser.html?Type=Flash&Connector=’ + encodeURIComponent( FCKConfig.BasePath + ‘filemanager/connectors/’ + _FileBrowserLanguage + ‘/connector.’ + _FileBrowserExtension ) ;
      //FCKConfig.FlashBrowserWindowWidth  = FCKConfig.ScreenWidth * 0.7 ;    //70% ;
      //FCKConfig.FlashBrowserWindowHeight = FCKConfig.ScreenHeight * 0.7 ;    //70% ;
      FCKConfig.FlashBrowserURL = FCKConfig.BasePath + ‘filemanager/browser/ajaxfilemanager/ajaxfilemanager.php’ ;
      FCKConfig.FlashBrowserWindowWidth  = 782 ;
      FCKConfig.FlashBrowserWindowHeight = 440 ;

      //FCKConfig.LinkUpload = true ;
      FCKConfig.LinkUpload = false ;
      FCKConfig.LinkUploadURL = FCKConfig.BasePath + ‘filemanager/connectors/’ + _QuickUploadLanguage + ‘/upload.’ + _QuickUploadExtension ;
      FCKConfig.LinkUploadAllowedExtensions    = “.(7z|aiff|asf|avi|bmp|csv|doc|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xml|zip)$” ;            // empty for all
      FCKConfig.LinkUploadDeniedExtensions    = “” ;    // empty for no one

      //FCKConfig.ImageUpload = true ;
      FCKConfig.ImageUpload = false ;
      FCKConfig.ImageUploadURL = FCKConfig.BasePath + ‘filemanager/connectors/’ + _QuickUploadLanguage + ‘/upload.’ + _QuickUploadExtension + ‘?Type=Image’ ;
      FCKConfig.ImageUploadAllowedExtensions    = “.(jpg|gif|jpeg|png|bmp)$” ;        // empty for all
      FCKConfig.ImageUploadDeniedExtensions    = “” ;                            // empty for no one

      //FCKConfig.FlashUpload = true ;
      FCKConfig.FlashUpload = false ;
      FCKConfig.FlashUploadURL = FCKConfig.BasePath + ‘filemanager/connectors/’ + _QuickUploadLanguage + ‘/upload.’ + _QuickUploadExtension + ‘?Type=Flash’ ;
      FCKConfig.FlashUploadAllowedExtensions    = “.(swf|flv)$” ;        // empty for all
      FCKConfig.FlashUploadDeniedExtensions    = “” ;

  • edit ‘config.base.php’ in ajaxfilemanager/inc directory and change these lines :
    • define(‘CONFIG_SYS_DEFAULT_PATH’, ‘../../../../../../uploads/images/fckeditor/’); //accept relative path only
      define(‘CONFIG_SYS_ROOT_PATH’, ‘../../../../../../uploads/images/fckeditor/’);    //accept relative path only
    • //define(‘CONFIG_EDITOR_NAME’, (CONFIG_QUERY_STRING_ENABLE && !empty($_GET[‘editor’])?secureFileName($_GET[‘editor’]):’stand_alone’));
      define(‘CONFIG_EDITOR_NAME’, (CONFIG_QUERY_STRING_ENABLE && !empty($_GET[‘editor’])?secureFileName($_GET[‘editor’]):’fckeditor’));
  • patch ajaxfilemanager/jscripts/for_fckeditor.js with this new function (comment original ‘selectFile’ function) :
    • function selectFile(absoluteurl)
      {
      //var relative=absoluteurl.split(document.domain);
      var relative = absoluteurl.split(‘/uploads/’);
      var url =  ‘/uploads/’ + relative[1];if (url != ”)
      {
      window.opener.SetUrl(url) ;
      window.close() ;
      }else
      {
      alert(noFileSelected);
      }
      }

Hope this helps !

Firefox 3.1

Enfin… depuis le temps que j’attends celle-là (quand je vois que y en a qui génère des objets flash pour chaque h1 ou h2 pour avoir une font un peu originale…) :

[style type=”text/css” media=”screen, print”]
@font-face {
font-family: “Bitstream Vera Serif Bold”;
src: url(“http://yourserver.com/VeraSeBd.ttf”);
}

body { font-family: “Bitstream Vera Serif Bold”, serif }

Sans parler de tout le reste : offline caching, xhr cross site allowed, svg filters on html,  and  natively supported…

Un aperçu dans ce PDF.

Vu la merdasse qu’est IE6 à l’heure actuelle et que tout le monde se fait chier à encore supporter, le prochain client aura droit à un supplément financier pour rendre son site internet compatible IE6. Y en a marre de tirer vers le bas tout le web à cause d’un navigateur complétement obsolète et buggué jusqu’à l’os.

SVN Cheat Sheet

An exhaustive SVN cheat sheet found here :

* Create a repository
– use the database backend
svnadmin create ~/svn_repos/Eccos
– use the filesystem backend
svnadmin create –fs-type=fsfs PATH

* Import a revision
svn import -m “Initial import” Eccos file:///home/reichr/svn_repos/Eccos/trunk

* Check out a revision
svn co file:///home/reichr/svn_repos/Eccos/trunk Eccos

* Dump a repository
svnadmin dump /home/reichr/svn_repos/Eccos | gzip -9 > dump.gz
svnadmin dump /home/reichr/svn_repos/Eccos | gzip -9 > `date “+Eccosdump%Y-%m-%d_%H:%M:%S.gz”`

* Load contents of a dump into a repository
gunzip -c dump.gz | svnadmin load /home/reichr/svn_repos/e

* Import from an existing directory, no need to check it out again
It should work, but you could also check it out right into /etc. Something
like this:

$ svnadmin create /var/svnrepos/admin
$ svn mkdir -m “initial setup” file:///var/svnrepos/admin/trunk
c:> svn mkdir -m “initial setup” file:///c:/fhs/svn_repos/trunk
$ cd /etc
$ svn co file:///var/svnrepos/admin/trunk .
$ svn add passwd group
$ svn commit -m “start loading it in”

I tested the ‘svn co’ into ‘.’ just now. Works great.

* svn propset
svn propset svn:keywords “LastChangedDate LastChangedRevision Id Author” weather.txt
svn propset svn:keywords “LastChangedDate LastChangedRevision Id” slides.tex

* Before an update you could use the following to get the log messages of the changes:
svn log -rBASE:HEAD

* Upgrade to a new subversion version
$ mv repos repos.tmp
$ svnadmin create repos
$ svnadmin-old dump repos.tmp | svnadmin load repos
$ # copy over any hook scripts and stuff from repos.tmp to repos

* Upgrade my repositories at work
$ mv Eccos Eccos-old
$ svnadmin create Eccos
$ gunzip -c dumps/Eccosdump2003-11-11_10:08:54.gz | svnadmin load Eccos

* Checkout from a repository over ssh
svn co svn+ssh://felix/home/reichr/svn_repos/XSteveData/trunk data

* Change the path of the repository for a working copy
svn switch –relocate file:///original/path/to/repos file:///new/path

* Put system configuration in a subversion repository
– create the repository /home/reichr/svn_repos/WaldiConfig
svnadmin create WaldiConfig
– Import an empty directory
cd to an empty directory
svn import -m “Initial import” . file:///home/reichr/svn_repos/WaldiConfig/trunk
– Check it out from Waldi (user reichr)
svn co svn+ssh://felix/home/reichr/svn_repos/WaldiConfig/trunk WaldiConfig
– Put files in the repository (as root)
mv /etc/fstab /home/reichr/WaldiConfig/etc
ln -s /home/reichr/WaldiConfig/etc/fstab /etc/fstab

* Network a repository via svn+ssh:
– create the repository on the repository host:
svnadmin create rp1 — this is located at /home/svtest/rp1
– Import data to the repository:
svn import -m”Initial import” svn+ssh://svtest@host/rp1/trunk
– Checkout the project:
svn co svn+ssh://svtest@host/home/svtest/rp1/trunk p1

* Warning:
Putting the repository on a network filesystem my be a bad idea,
because the repository may get corrupted!
It is better to put it on a local filesystem.

* Merge from a branch back to the trunk
SvnMerging

* Generate a patch to undo some local changes and redo them later
> What usually happens to me is that I’ve changed N files in M different
> directories distributed all over the filesystem, and I want to check in
> N-1 of them.

Yeah, I have to do this all the time. But I can eye a potentially
complex command-line pretty well, so if I need to commit all but one
file, I do this:

% svn diff path/to/file_not_committing > /tmp/patch.txt
% svn revert path/to/file_not_committing
% svn ci -m “committing all the stuff i wanted to”
% patch -p0 < /tmp/patch.txt Revert is your friend. Learn it, use it, looooooooooove it. * Revert to a previous version svn co project
svn ci foo.c (commits to r348)

svn merge -r348:347 foo.c
svn ci foo.c (commits 349)

note the ordering of the revision numbers in the merge command. what this
really says is “make a diff between revision 348 and 347, and apply it
immediately to foo.c”

if you are trying to revert a directory tree with moves or deletes in it, and
are getting arcane errors, try the –ignore-ancestry flag.

* Edit the commit/log messages after the commit
Read chapter 7, regarding unversioned properties attached to revisions.
You want to change the svn:log property:
$ svn propedit -r N –revprop svn:log URL

* Svn repository via apache2
– manage the htpasswd file:
http://search.cpan.org/dist/Apache-Htpasswd/Htpasswd.pm
– a sample cgi script to alter users passwords via Apache::Htpasswd:
http://perlmonks.thepen.com/178482.html
– A full featured utility to add/change users via commandline or cgi:
http://stein.cshl.org/~lstein/user_manage/

* Use svn:mime-type for nicer www browsing of a repository
> When browsing your repository, if you click on a filename, you see the
> contents of the file (assuming it’s a text file) formatted as if with a
>

 tag.  So, if the file happens to be an HTML file, you essentially see
> the source HTML code. Which, in most cases, is perfectly correct.
>
> However, there are times when it would be nice to see the _formatted_ HTML
> instead. Is there a way to do this, other than the cumbersome Save Page As
> / Open File process within the browser?

If you set the svn:mime-type property on that file to ‘text/html’ and
commit, your browser should see subsequent revisions of that file as
formatted HTML.

* Versionize symlinks, unix permissions and ownership
svnpropset.pl, svnpropget.pl from Steve Wray
(search on the svn mailing list or in my mail-boxes)

* track svn trunks/branches with all history in arch
– svn-arch-mirror
Category: svn-arch-mirror
Archive: eric@petta-tech.com–2004b-ordinary

Location: http://des.petta-tech.bogomips.org/~eric/MusicPD/eric@petta-tech.com--2004b-ordinary/

How to migrate / convert MSSQL .bak into Mysql / SQL

Here are the steps to follow in order to convert a MsSql (sql server) .BAK into mysql format:

  1. you need windows
  2. download and install Microsoft SQL Server Express
  3. download and install Microsoft SQL Server Management Studio Express
  4. download and install Mysql Migration Toolkit (included in Mysql Gui Tools only in Windows package, no linux version 🙁 )
  5. configure your MSSql server to listen on TCP connexion
  6. load your .bak in SQL Serveur management studio (right clic on database, restose database, from the unit, go to options tab and set a right path for the files listed in the .bak file, launch the recovery)
  7. in Mysql Migration toolkit, follow the wizard, it should be easy

Hercules Deluxe Webcam :compiling drivers for Ubuntu 8.10

Here again we are facing a crappy hardware with homebrewed drivers, not integrated: sunday morning, let’s compile something.
That’s a translated how to from here

Unplug the webcam

lsmod | grep ov

to check if any module is loaded, and remove it

sudo rmmod gspca_ov519sudo rm -r/lib/modules/`uname -r`/kernel/ubuntu/misc/media/ov511

sudo rm /lib/modules/`uname -r`/kernel/drivers/media/video/gspca

So let’s download the drivers’ sources:

wget http://www.rastageeks.org/downloads/ov51x-jpeg/ov51x-jpeg-1.5.9.tar.gztar -zxwf ov51x-jpeg-1.5.9.tar.gz

cd ov51x-jpeg-1.5.9/

sudo apt-get install build-essential linux-headers-`uname -r`

make

sudo make install

sudo modprobe ov51x-jpeg

echo “options ov51x-jpeg forceblock=1” | sudo tee -a /etc/modprobe.d/options

echo “options ov51x-jpeg force_palette=13” | sudo tee -a /etc/modprobe.d/options

tail -f /var/log/syslog | grep “ov51x”

and plug the webcam, something close to this should appears:

kernel: [324189.288878] ov51x_jpeg: USB OV519 video device found
kernel: [324189.656291] ov51x_jpeg: Sensor is an OV7648
kernel: [324189.758541] ov51x_jpeg: Device at usb-0000:00:1d.1-2 registered to minor 1

(control+c to quit)

gstreamer-properties

and the webcam shoud show up

If not, check the rights:

ls -l /dev/video*
crwxrwxrwx+ 1 root video 81, 0 2009-01-14 20:03 /dev/video0
crw-rw—-  1 root video 81, 1 2009-01-18 14:10 /dev/video1

The first one is good, but not the second webcam, only video access, so to correct it: create a simlink at the module initialisation:

sudo gedit /etc/udev/rules.d/80-programs.rules

And add this line:

KERNEL==”video[0-1]”, NAME=”video%k”, SYMLINK+=”%k”, MODE=”0666″

Restart the service

sudo /etc/init.d/udev restart

now check it works fine:

mplayer tv:// -tv driver=v4l:width=640:height=480:device=/dev/video0

Now you end up with a perfectly working webcam, it’s time to check out the new cross plateform opensource webcam instant messaging:a
http://www.qutecom.org/

(And to drop Skype)