Node import and domain access

If you are using Node import 1.x-rc4 or below with Domain Access, you can get this error on each row to be imported:

An illegal choice has been detected. Please contact the site administrator.

This error in this case is presented when Domain Access try to import a node without assigning it to a domain. Node import 1.x-rc4 and below  lacks Domain Access support on 1.x-rc4.

Domain Access support will be available on Node import by 1.0 RC5 version, you have to dowload the -dev version to have it now.

After that, the error should disappear. For more information, read the first lines of node_import/node_import.inc , where this error is explained.

Theme a multiple CCK field with a table

Sometimes CCK contrib modules cannot do exactly what you want. It’s time to build your custom CCK field!

Official documentation on CCK fields creation for Drupal 6 is incomplete and some passages are obscure. If there is a good howto you have to read before do any CCK customization, this is Creating Custom CCK Fields. This howto supposes you’ve read and understand it before continue. If you want to create a custom field, you can read the complete Creating a Compound field. A custom multiple compound field (with more than one field for element, e.g. an image and its description).

Read these howto well, you’ll spare time later

Well, you have followed the howto, you have your own compound field but now you have a problem. You want to display compound field data as cells in a table, and each field as row.

On following example, we have a name list made with a multiple compound field with “firstname” and “lastname” columns.

KarenS tell you that you’ve to use CONTENT_HANDLE_MODULE instead of CONTENT_HANDLE_CORE on hook_formatter_info() .

// The machine name of the formatter.
function my_funny_module_field_formatter_info() {
  return array(
    'default' => array(
      'label' => t('Default'),
      // An array of the field types this formatter
      // can be used on.
      'field types' => array('examplefield'),
      // CONTENT_HANDLE_CORE:   CCK will pass the formatter
      // a single value.
      // CONTENT_HANDLE_MODULE: CCK will pass the formatter
      // an array of all the values. None of CCK's core
      // formatters use multiple values, that is an option
      // available to other modules that want it.
      'multiple values' => CONTENT_HANDLE_MODULE,
    ),
  );
}

/** Set the formatter **/
function my_funny_module_theme() {
  return array(
    'my_funny_module_formatter_default' => array(
      'arguments' => array('element' => NULL),
      'function' => 'funny_display_table',
    ),
  );
}

/** Here you format your table data as array **/
function my_funny_module_formatter_default($element) {
  $data = array(
      $element['#item']['firstname'],
      $element['#item']['lastname'],
  );
  return $data;
}

/** This function will display a table even where data array is empty:
 ** You have to put an additional control statement to avoid this.
 ** $element will have $data from formatter_default() above
 **/
function my_funny_module_display_table($element) {
  $header = array(
    t('First name'),
    t('Last name'),
  );
  $i = 0;
  while (!$end) {
    /** Any row will contains **/
    if(array_key_exists($i, $element)) {
      $rows[] = array(
        'firstname' => $element[$i]['#item']['firstname'],
        'lastname' =>$element[$i]['#item']['lastname'],
      );
      $i++;
    }
    else {
      $end = TRUE;
    }
  }
  /** Theme a table with data from element and header **/
  return theme('table', $header, $rows);
}

Note: to format a table you have to change only “multiple values” on my_funny_module_field_formatter_info(): you can leave my_funny_module_widget_info() as is.

See also:

Add CSS style for a block into the same block

This simple code can be pasted into a PHP filtered block (or into a block declared by a module) to set some style from a block into the block container itself.

<?php
echo 'My block content';
/** Put styles inline on html head**/
drupal_set_html_head('<style type="text/css">
#my-block-id {
  /* my style*/
}
</style>
');
?>

This code is placed on html head, applied only to the pages where block appears, without touching css optimization. If you want to include an external CSS file instead, use drupal_add_css instead: in any case you can exclude this file for aggregation, setting $preprocess attribute to FALSE.

If block appears in very few pages, and it can change quickly (e.g. a banner with custom styles on home page), using drupal_set_html_head could be the best way, even according to Yahoo Performance Best Practices. In other cases, use drupal_add_css.

See also:

Cron cannot run on Drupal: the drupal_goto() case

Sometimes you want to redirect a page to another on drupal. You can do this using a simple function called drupal_goto().

On few sites I’ve enabled the PHP filter module and then created a new page with PHP code input format with drupal_goto(‘node/2′) to redirect the current page to a specified node. Bad idea.

I’ve noticed that, after this change, cron.php operations failed, if you have Search module enabled. On cron new contents are indexed by the Search module: when it got my PHP page, it tries to index it but suddenly is redirected to another. You can also found an error like “Maximum function nesting level of ‘100′ reached” on php error log, symptom of an indexing blocked by pages with drupal_goto inside.

Solution:

  1. Comment all drupal_goto() instruction in your site within pages.
  2. Use an alternative method to redirect from a node to another.
  3. Run cron from Status Report page: you can adjust indexed content per cron on Search configuration page (admin/settings/search on 6.x)

You can add a new block with PHP code inside or (better) create a new module for this simple block (with a simple PHP switch statement as content), displaying it only on specified pages (on the bottom of block configuration). But if you create a PHP block via UI, and you put that block on every page, your site could be loop, so creating a module is the cleanest and secure way (if something go wrong, you can delete your module from the codebase and correct it). You can also find some contrib modules for redirect on drupalmodules.com.

See also:

Fatal error: Maximum function nesting level of ‘100′ reached, aborting!

Character substitution on Jquery

Here an easy way to search and replace each occurrence a group of characters (in this case underscore and minus) with another (in this case a space) on a specified element (in this case each A), using Jquery javascript library.

$("a").each(function() {
   $(this).html($(this).html().replace(/[_-]/g," "));
});

The first argument passed on replace is a regex, if you just pass a single character (like “_” or “-”) only first occurrence for each element.

Real world usage: I use this onto a long page, where a table has long filenames with underscore and minus in place of spaces. This trick allows in my case to show tables nicely, without caring on a mass substitution via server side scripting.

See also:

Video on Flash doesn’t buffer? Maybe a FLV and MP4 issue

I recently tried Flowplayer a Flash video player released under GNU GPL license. It’s great, since it has a plugin allowing pseudostreaming (it allows buffering from any server) with both FLV and MP4 (H.264 / AC3).

Using avidemux to convert my videos, I had no problem to play FLV files: buffering works as expected, I watch video while buffer is filled. But on MP4, I’ve to wait the video is fully buffered (downloaded entirely).

This is not a Flowplayer issue: this exaustive howto explain that FLV and MP4 files should be properly indexed to works with pseudostreaming.

  • For FLV files, you can use Flvtool2, a Ruby gem, available also on apt / synaptic via “apt-get install flvtool2″ (Debian packages, description on rubyforge). Using avidemux, FLV files are ok even if I don’t use Flvtool2, so FLV metadata seems correctly handled by Avidemux. Ready for pseudostreaming!
  • For MP4 files, you have to move MP4 metadata (“moov atom”) from the end of the file to the beginning, since Avidemux seems to put it on the very end of the video file. To do this, I’ve used successfully a tool named mp4box (mp4box on videohelp, author website) using MP4Box-0.4.6-dev_20090519 version (win32 binary). Read also MP4box documentation on GPAC, you can also get it on sourceforge.

MP4Box usage example:

MP4Box.exe -add TEST_src.mp4 -new TEST_dst.mp4
IsoMedia import – track ID 1 – Video (size 848 x 480)
IsoMedia import – track ID 2 – Audio (SR 44100 – 2 channels)
Saving TEST_dst.mp4: 0.500 secs Interleaving

See also:

Flowplayer forum posts on same topic:

Qt-fastart (FFMpeg alternative), another post

Animax in Italia

L’animazione giapponese nella televisione italiana degli ultimi anni si è affacciata con proposte interessanti principalmente per opera di MTV. Una sera alla settimana (il martedì), il canale musicale trasmetteva e continua a trasmettere una fascia dedicata agli anime dedicati ad un pubblico di teenager e giovani adulti, comprendendo negli anni titoli come Cowboy Bebop, Inuyasha, Fullmetal Alchemist, Le situazioni di Lui & Lei, BECK, Full Metal Panic, Death Note, NANA, Kenshin, GTO (elenco completo).

Una volta l’anno, lo stesso canale trasmetteva un assaggio di alcuni titoli distribuiti principalmente da Shin Vision (attualmente fallita), Dynit e Yamato in un evento autunnale chiamato Anime Week (maggiori informazioni su IAC, maggiori info su Wikipedia) che sembrava fungesse da vetrina per i distributori, dato che molti titoli non venivano poi successivamente trasmessi dalla rete ma resi disponibili contestualmente in home video.

Mentre l’ultima anime week risale al 2006, alcuni canali satellitari hanno iniziato a popolare i propri palinsesti di anime, mentre sono sorti canali dedicati (ad es. Cultoon diventato poi Cooltoon), senza contare che alcuni canali satellitari come Cartoon Network hanno incluso anch’essi animazione giapponese (ad es. School Rumble) in una programmazione più variegata.

Il 12 gennaio 2007 Sony, che vanta un canale satellitare chiamato Animax trasmesso in tutto il mondo, decide di aprire una fascia di animazione giapponese nel canale satellitare AXN, che fino a quel momento trattava principalmente telefilm d’azione statunitensi (es. McGuyver).

In questa fascia, che sembrava sarebbe dovuto fungere da test per lo sbarco del canale satellitare dedicato Animax in Italia, viene trasmesso fra gli altri un titolo di alto pregio come PlanetES, accendendo le speranze degli appassionati italiani (articolo su AnimeClick). La fascia viene prima migrata in orari notturni e successivamente soppressa (articolo su Animeclick). L’avvento di Animax in Italia viene quindi rimandato ad una data indefinita.

Mentre il canale si diffonde in Germania, Spagna, Portogallo, Polonia, Repubblica Ceca, Slovacchia, Ungheria, Romania, l’Italia resta al palo.

Per tentare di organizzare il vero ritorno del canale in Italia nella forma in cui è conosciuto negli altri paesi del mondo, nasce prima il sito web animaxinitalia.org e successivamente una causa su Facebook chiamata Animax in Italia, che al 15 marzo 2009 conta 54 aderenti. L’obiettivo è raggiungere un numero di aderenti tale da poter chiedere formalmente alla Sony di riconsiderare lo sbarco del canale tematico in Italia, dimostrando l’interesse attivo degli appassionati italiani verso un canale di animazione giapponese recente.

Iscriviti alla causa Animax in Italia

Iscriviti alla causa Animax in Italia (cliccando sul banner e poi su Join). In caso non l'abbia già fatto, devi prima autorizzare l'applicazione Causes.

P.S. Ringrazio Cesco per aver acconsentito all’uso del logo modificato di Animax per la causa e ovviamente per aver avviato animaxinitalia.org.

Vedi anche:

Howto merge two torrent files

Sometimes you want to download a torrent that you’ve partially downloaded. Many bittorrent client allow partially downloaded files, but what if you’ve downloaded the same torrent twice, with differents parts available?

Use Zeroconf / Local peer

I’ve used two client on the same LAN, ktorrent (on Debian) and utorrent (on Windows XP). I’ve two downloaded files (or folder) from the same .torrent, with different parts downloaded.

  • Enable Zeroconf plugin on ktorrent
  • Check if on utorrent “Enable local peer discovery” is enabled
  • Import existing download #1 on ktorrent
  • On debian system, as root type ifconfig to discover your local IP address, i.e.  inet addr:192.168.0.XX
  • Go to ktorrent preferences and check the used port (e.g. 12345)
  • On utorrent go to Peers tab on #2 download. Right-click > Add peer
  • Type your first machine IP address (e.g. Debian) and the first bittorrent client port (e.g. 12345 on ktorrent),  e.g. 192.168.0.XX:12345 with no protocol prepended.

On both client you’ll notice a new peer, downloading and uploading very fast. Little after, the two downloaded files / folder could be completely merged.

You can now close #2 and continue to download the torrent on a single machine / client from external peers.

Note: I’ve tested this method on the same machine using Virtualbox (Debian as host, XP as guest).

See also:

Howto extract tracks from mkv and avi

This howto requires:

  • mplayer
  • mkvtoolnix
  • your Linux box ;)

Audio from Avi files (es. Xvid + MP3):

mplayer -dumpaudio "mymovie.avi" -dumpfile mymovie_audio_track.mp3

Tracks from Matroska MKV file:

List all tracks:

mkvmerge -i mymovie.mkv

File 'mymovie.mkv': container: Matroska
Track ID 1: video (V_MS/VFW/FOURCC, XVID)
Track ID 2: audio (A_VORBIS)
Track ID 3: audio (A_VORBIS)
Track ID 4: subtitles (S_TEXT/UTF8)
Track ID 5: subtitles (S_TEXT/UTF8)

mkvextract tracks *.mkv 3:mymovie_audio_track.ogg 4:mymovie_subtitle.srt

Creates two files, mymovie_audio_track.ogg (track 3) and mymovie_subtitle.srt (track 4).

Installing Plone on Debian

A little howto to quickly install and try Plone (a GPL’d CMS based on Zope) on your linux box. Well, the installer seems to do the job nicely. :)

Tested on Plone 3.* version, Debian “Lenny”.

  • apt-get install g++
  • Download latest version of Plone (Unified Installer)
  • Execute:
    tar zxvf Plone-YOURVERSION-UnifiedInstaller.tgz
    cd Plone-
    YOURVERSION-UnifiedInstaller
    ./install.sh standalone
    gedit /usr/local/Plone/zinstance/README.txt &
    gedit /usr/local/Plone/zinstance/buildout.cfg &
    /usr/local/Plone/zinstance/bin/plonectl start
    less /usr/local/Plone/zinstance/adminPassword.txt
  • README should be read to follow installation instructions, then you can modify Plone configuration on buildout.cfg, and then you can start Plone. On adminPassword.txt you’ll find your Plone passwords to use for administrative purpouses.

  • Add /usr/local/Plone/zinstance/bin/plonectl start to /etc/rc.local before exit 0 (Red Hat) to run plone at any server restart or create a script on /etc/init.d/ (Debian) like.

Now you can test this CMS based on Python (I’ve tested it 4 years ago, maybe it hardly can replace Drupal but you can give it a try ;-) ).

Next Page »


IE6: Rust in Peace

Blog Stats

  • 101,154 hits
My Bookshelf

Texts double licensed under Creative Commons Attribution - Share Alike license and GNU Free Documentation License. Examples may contain software licensed under GNU General Public License. Images and comments texts aren't necessarily licensed under these terms.