Joomla template creation, Joom!Fish language detection.

February 19th, 2007 by ltz

Creating a Joomla template might be rather simple, when involving different languages on the text-level it all seems simple aswell. However when we want 100% of our website to change language when we swith languages, this requires a workaround. The Joom!fish component is very powerful, however you control 95% of the website content from Joom!fish, the rest should be handled some other way. I find it easy to manipulate these parts from ithin the template, creating a few language files containing the rest of the phrases/imagesfiles/meta tags etc that you whish to translate. Some example code below.

Retrieving the current language setting.

Given that the Joom!Fish component is installed, the following code in your template index.php should do the trick.


< ?php
/**
* @author Pierre Norraeus
*
* Return the current language. This variable is controlled by
* the Joom!Fish Joomla component. Having this function should enable
* a potential change in the Joom!Fish functionality.
*
*
*/
function getCurrentLanguage() {

global $mosConfig_lang;

return $mosConfig_lang;

}

/**
* @author Pierre Norraeus
*
* Detect the current language, for now only accept swedish, and if
* not swedish lets make english the default.
*
* @todo extend more languages..
*
*/
if (getCurrentLanguage() == "swedish") {

include_once ('language_texts_se.php');

} else {

include_once ('language_texts_en.php');

}

? >

Example language file.

The variablenames below should of course be according to your coding standard (aswell as the rest of this example..:) ).

< ?php
/*
* @author Pierre Norraeus
* English language file.
*
*/

define(main_userid, 'Username');
define(main_password, 'Password');

? >

HTML examples..

Importing a language-based javascript file..

..script language="JavaScript" type="text/javascript" src="< ?php echo $mosConfig_live_site;?>/templates/Templatename/js/menu_< ?php echo getCurrentLanguage();? >.js”>

Language specific image

...img src="< ?php echo $mosConfig_live_site;? >/templates/templatename/images/buttons/search_< ?php echo getCurrentLanguage();? >.gif” alt=”" /…

The rest should be handled by the Joom!Fish component, very smooth.

Posted in Programming, Comp, Joomla | No Comments »

Simple XML parsing with CLI PHP, character encoding problems

January 7th, 2007 by ltz

When using PHP for creating html documents intended to be read by a web browser there’s the possibility to set character encoding within the html-heading, getting a extra way to handla the character presentation of the content. However when running PHP code through the CLI-PHP software for internal, server-side purposes handling data the character encoding might require a little bit more work. Reading XML-documents using the PHP “xml_parser” and at the same time trusting the character encoding given in the XML-document header as shown below might not be enough in order to make sure you get the correct character encoding.

...xml version="1.0" encoding="iso-8859-1" ...

Be sure to set the encoding within the creation of the XML-parser.


$xml_parser = xml_parser_create();

xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");

Posted in Programming | No Comments »

PHP IMAP mail fetching including attachments..

November 8th, 2006 by ltz

Took me a while to figure out how to search and fetch a single attachment from a POP mailbox, without ending up with 300+ lines of code.. Maybe this one could help someone else..

// Open pop account.
$mailbox = imap_open( $popaddr, $popuser, $poppasswd);

// Search for the message we are looking for..
$result = imap_search($mailbox, $searchsubject, SE_UID);

if ($result) {

storePDFAttachment(imap_fetchbody($mailbox,$result[0],2),$savefilename,$savefilepath);

} else {

exit(“message not found in mailbox yet..”);

}

// Close the connection.
imap_close($mailbox);

function storePDFAttachment( $content , $filename , $localfilepath ) {

$file = fopen($localfilepath.$filename, ‘w’);
fwrite($file, imap_base64($content));

fclose($file);
}


Posted in Programming | No Comments »

Implementing updating stock chart

October 28th, 2006 by ltz

Trying to update a html-page without having a) annoying refreshes of the entire page, b) a third party framework implementation (ie: Java/Flash/etc..). My experience is that a “third party” implementation more or less makes the best solution however there are alternatives. For instance a simple AJAX-based implementation of such a function would be possible. This also does have its drawbacks, but for now we could look at the possibilities.

Attached is one solution involving PHP and a standard OSI-certified AJAX-framework called Agent AJAX. Please note the drawbacks of this solution. If the client/server connection is poor, the transfers in AJAX might create problems for the Client. You can of course overcome this problem by simply thinking your solution through and for instance creating feedback to the user at any transaction that might fail.

Posted in Programming | No Comments »

Pierre Norraeus
Joomla! 1.5 Beta 2 - Red Barchetta