registerEvent('onPrepareContent', 'botJoomfishAlternative'); function botJoomfishAlternative( &$row, &$params, $page=0 ) { // simple performance check to determine whether bot should process further if ( strpos( $row->text, 'jfalternative' ) === false ) { return true; } // define the regular expression for the bot $regex = "#{jfalternative}(.*?){/jfalternative}#s"; preg_match($regex, $row->text, $matches); if (count($matches)!=2) return true; list($id,$table,$defaultText) = explode("|",$matches[1]); // only support tables at this time. if ($table!="content"){ $row->text = preg_replace( $regex, '', $row->text ); return true; } $db = JFactory::getDBO(); $sql = "SELECT DISTINCT jfl.shortcode, jfl.iso, jfl.name, jfl.image FROM #__jf_content AS jfc, #__languages AS jfl " ."\n WHERE reference_id=$id AND reference_table='".$table."'" ."\n AND jfc.language_id=jfl.id AND jfc.published=1"; $db->setQuery($sql); $alts = $db->loadObjectList(); if (is_array($alts) && count($alts)>0){ $alttext = "
"; $alttext .= JText::_('NO TRANSLATION ALTERNATIVE'); foreach ($alts as $lang) { $lang->shortcode = ($lang->shortcode == '') ? $lang->iso : $lang->shortcode; global $Itemid; $alttext .=" "; if ($params->get("falt_showAS","flag")=="flag"){ if( isset($lang->image) && $lang->image!="" ) { $langImg = '/images/' .$lang->image; } else { $langImg = '/components/com_joomfish/images/flags/' .$lang->shortcode .".gif"; } $langImg ='' .$lang->name. ''; $alttext .=$langImg." "; } else { $alttext .=$lang->name.""; } } $alttext .= "
"; $row->text = preg_replace( $regex, $alttext, $row->text ); } else { global $_JOOMFISH_MANAGER; $alttext = "
"; $alttext .= JText::_('NO TRANSLATION AVAILABLE'); $alttext .= "
"; $row->text = preg_replace( $regex, $alttext, $row->text ); } return true; } ?>