David Ansermot Web Developer / TYPO3 Integrator

26avr/110

PHP – Generate Luhn checksum (for valid account numbers)

Here's a function to calculate the Luhn checksum of a 15 digits account number (the checksum'll be the 16th digit) :

  1. public function luhnChecksum($accountNumber) {
  2.                
  3.         // Buffer
  4.         $sum = 0;
  5.        
  6.         // Process each digit
  7.         for ($i = 0; $i < 15; $i++) {
  8.                 $digit = $accountNumber{$i};
  9.                
  10.                 // each 2 digits
  11.                 if ($i % 2 == 0) {
  12.                         $double = $digit * 2;
  13.                        
  14.                         // if over 10, sum of the 2 digits
  15.                         if ($double > 10) {
  16.                                 $double = (string)$double;
  17.                                 $sum += ((int)$double{0} + (int)$double{1});
  18.                         } else {
  19.                                 $sum += $digit;
  20.                         }
  21.                 } else {
  22.                         $sum += $digit;
  23.                 }
  24.         }
  25.        
  26.         // Euclidian division
  27.         $rest = $sum % 10;
  28.        
  29.         // luhn key  
  30.         $key = 10 - $rest;
  31.        
  32.         return $key;
  33. }

Article for teaching purposes.
I can not in any way be held liable for its use

18avr/110

TYPO3 – Change files/images upload limit

Today I'll explain how to change the limit for files, images and other medias upload.

To do the trick, you have multiple changes to make.

14avr/110

Javascript – Test if variable is numeric

Here's a simple way to check if a variable is numeric or not in javascript

  1. function isNumeric(input) {
  2.         return (input - 0) == input && input.length > 0;
  3. }

Enjoy

13avr/110

TYPO3 – Get content element from extension code

I've not wrote something from long time, so today I give you a little snippet.
If you have to use in your extension a content element from another page, you can use this function to get it from it's uid :

  1. function loadContentElement($uid) {
  2.  
  3.         $conf = array(
  4.                 'tables' => 'tt_content',
  5.                 'source' => $uid,
  6.                 'dontCheckPid' => 1,
  7.         );
  8.  
  9.         return $this->cObj->RECORDS($conf);
  10. }
23mar/110

Google Maps – Center and fit map to a group of markers

Google LogoToday I'll explain how you can center and auto zoom to the correct value your map to fit a group of markers.
Suppose that we have our map called myMap and a group of markers called markers (^.^')