Hi,
Using flexinode.module and i18n.module I have managed to create multilingual blocks.
Here's what I've done and I'm looking forward to some comments, as I want to know how useful this workaround might be and what kind of polishing it needs :) I'm not a programmer, so please keep your comments simple and understandable...
It started with my wish to have some kind of news / sidenotes / links in the sidebar of my website. Therefore I needed: title, link, date, content.
First I created a flexinode called "sidenote", which got id 2, so let's say flexinode-type 2. As flexinodes are connected with their nodedata, I already had a title and a date. Therefore I defined two additional flexinode fields: link (which was given id 16) and content (which was given id 18). Now I was able to enter the necessary content just as easy as stories, blogposts, et cetera.
Second I had to create some php for the block. Using php I wanted to take care for both logic and themeing. First time ever... But I got it done, wooohaaa! For explaining the basic idea, I will suffice with quoting my code, as the comment lines will explain the logic. I implemented this code as part of a new block, which has been made visible in the right sidebar. Now all content of type sidenote (type 2) is showed as short stories with a title, link, date and content in the right sidebar and, moreover, in the right language as well! I also added a link at the bottom of the sidebar, which links to an overview page using taxonomy terms (this part needs some polishing definitely...).
The result can be found here:
NOTE
At the bottom of the code there are a lot of comment lines; these are for future use, when I want to show certain sidenotes in certain sections, using sections.module.
As said before: I'm looking forward to some feedback, thanks in advance!
Marc
<?php
// determination of the site's language using i18n.
$site_language = _i18n_get_lang();
// definition of flexinode-type for creating content:
// - 2 = custom defined type for nodes in sidebar (sidenotes).
$flexinode_type = 2;
// defintion of flexinode-type fields providing content:
// - 16 = custom defined field for storing weblink;
// - 18 = custom defined field for storing content.
$flexinode_field_link = 16;
$flexinode_field_body = 18;
// initialization of sidebar's block.
$block_initialized = FALSE;
// query:
// selecting (flexi)node data
// where the flexinode-type is the one for sidenotes
// and the node's language is the site's language
// and the node's status is published
// sorted by date created.
$result_fn = db_query
(" SELECT *
FROM {node} n
, {flexinode_data} fn_d
, {flexinode_field} fn_f
, {flexinode_type} fn_t
WHERE fn_t.ctype_id = '$flexinode_type'
AND fn_t.ctype_id = fn_f.ctype_id
AND fn_f.field_id = fn_d.field_id
AND fn_d.nid = n.nid
AND n.language = '$site_language'
AND n.status = 1
ORDER BY n.created DESC
");
// loop for every row of the query above.
// NOTE: one node will have multiple rows,
// namely one for every flexinode field.
// rows for one node are next to each other,
// because of ordering by date and time created.
// the transition from one node to another
// will be determined by comparing:
// - $previous_node;
// - $current_node.
while ($row = db_fetch_object($result_fn))
{
if ($block_initialized == FALSE)
{
// at the start of the first loop,
// the block needs to be initialized:
// row defines $current_node and $previous_node.
$previous_node = $row->created;
$current_node = $row->created;
$block_initialized = TRUE;
}
else
{
// at the start of other loops,
// row defines $current_node only.
$current_node = $row->created;
}
if ($current_node < $previous_node)
{
// if $current_node and $previous_node are not equal,
// the query has just entered the data of another node,
// so the gathered content needs to be printed
// and $previous_node needs to be updated.
print '<a href="/' . $link . '" target="_blank" title=" link naar ' . $titel . '"> ' . $titel . '</a>' . '<br /><small>' . $datum . ' - ' . $body . '<br /><br /></small>';
$previous_node = $row->created;
}
// gathering content:
// - date
// - title
// - weblink (flexinodes textual data defined by: $flexinode_field_link = 16)
// - content (flexinodes textual data defined by: $flexinode_field_link = 18)
// NOTE: the gathering of content needs more than one loop,
// as every row contains one flexinode field
// which is stored in the textual data.
// so, for gathering the content of one node
// there are as many loops as there are flexinode fields.
$datum = format_date($row->created, $type = 'custom', $format = 'j M Y', $timezone = NULL);
$titel = $row->title;
if ($row->field_id == $flexinode_field_link)
{ $link = $row->textual_data;
}
if ($row->field_id == $flexinode_field_body)
{ $body = $row->textual_data;
}
}
// after finishing the last loop,
// the content of the concerning node needs to be printed as well.
print '<a href="/' . $link . '" target="_blank" title=" link naar ' . $titel . '"> ' . $titel . '</a>' . '<br /><small>' . $datum . ' - ' . $body . '<br /><br /></small>';
// addition of an extra link at the bottom
// to access an overview page in the right language.
// still needs some polishing :D
if ($site_language == "nl")
{ print '<a href="/nl/taxonomy/term/73" target="_top">' . t("all links") . '...</a>';
}
elseif ($site_language == "en-local")
{ print '<a href="/en-local/taxonomy/term/74" target="_top">' . t("all links") . '...</a>';
}
// from here some code that determines the section (using section.module),
// which might be useful when trying to create section dependent block content.
//
// $res = db_query("SELECT path, status, template FROM {sections_data} s");
//
// while ($row = db_fetch_object($res))
// { $path = drupal_get_path_alias($_GET['q']);
// $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1\2'), preg_quote($row->path, '/')) .')$/';
// if($row->status && preg_match($regexp, $path)) {
// $sectie = $row->template;
// }
// }
// print $sectie;
?>
Comments
Oops...
Forgot to mention that -of course- flexinode content is translated using i18n.module, the same way other content is translated.
___________________
discover new oceans
lose sight of the shore
I failed...
I try to use your work. Without success... I'm enable to make the flexinode work.
Well I try with flexiblocks.
--
@+
sKanD
aka Stephane Carpentier
Sorry to hear that...
Hi Stephane!
Sorry to hear that you didn't manage to get it done. Hope you have more success with flexiblocks. In case you want to try again, I'm all yours (may be we can start an e-mailconversation?).
Cheers!
Marc
___________________
discover new oceans
lose sight of the shore