As an anonymous user, you can only add new data. If you would like to also modify existing data, please create an account and indicate your languages on your user page.

User:MartinMai/vocabulary viewer/mockup/functions.php

From OmegaWiki
Jump to: navigation, search

<?php

/*


omegawiki_lib::list_translations

  • /

class omegawiki_lib{

function filter_dm_id($content, $url_input='1'){


$pattern = '(.*DefinedMeaning)(\:\([0-9]{1,}\))(.*)';


preg_match("%$pattern%Uu", $content, $matches); //print_r($matches); return $matches[2];

}


function filter_definition($content, $def_lang){

$pattern = '(<td\sclass="language\scolumn-even">'.$def_lang.'</td><td class="text column-odd">)([^<]*)(</td><td class="user column-even"><a href="[^"]*" title="[^"]*">)([^<]*)(</a></td><td class="timestamp column-odd">)([^<]*)(</td><td class="user column-even">.*</td><td class="timestamp column-odd">.*</td>)';

$pattern = '(.*)(<tr id="defined-meaning-\d*[^"]*" ><td class="language column-even">'.$def_lang.'</td><td class="text column-odd">)([^<]*</td></tr>)(.*)';

$pattern = str_replace(" ","\s",$pattern); //$pattern = str_replace("\"","\\\"",$pattern); //$pattern = str_replace("=","\=",$pattern);


preg_match_all("%$pattern%Uu", $content, $matches); //print_r($pattern); return $matches; }


function filter_translations($content, $trans_lang){

//$pattern = '(.*)(<tr id="[^"]*" ><td class="language column-even">'.$trans_lang.'</td><td class="spelling column-odd"><a href="[^"]*">)([^<]*)(</a>)(.*)';

$pattern = '(.*)(<tr id="[^"]*" ><td class="language column-even">'.$trans_lang.'</td><td class="spelling column-odd"><a href="[^"]*">)([^<]*)(</a></td>.*<input type="checkbox" )(checked="checked"|.*)(disabled="disabled"/>)(.*)';

preg_match_all("%$pattern%Uu", $content, $matches); //print_r($pattern); return $matches; }

function list_translations($content, $trans_lang, $control_name='trans_lang',$fallback='0'){


$form_trans_lang = ' <select name="'.$control_name.'" onchange="document.form.submit()"> <option value="Italian">Italian</option> <option value="Neapolitan">Neapolitan</option> <option value="Dutch">Dutch</option> <option value="English">English</option> <option value="French">French</option> <option value="German">German</option> </select> ';

$form_trans_lang = str_replace('value="'.$trans_lang.'">','value="'.$trans_lang.'" selected>', $form_trans_lang);

$matches = omegawiki_lib::filter_translations($content, $trans_lang);

if($fallback == 1){ foreach($GLOBALS['trans_lang_fallbacks'] as $trans_lang_fallback){ if ($matches[3][0]){ break; }else{ $matches = omegawiki_lib::filter_translations($content, $trans_lang_fallback); $fallback_msg = "
(not available in $trans_lang, fallback to $trans_lang_fallback)"; } } } //print_r($matches);

$string = "

Translation:

".$form_trans_lang.$fallback_msg; $string .= '
    '; foreach ($matches[3] as $match){ $string .= '
  • '.$match; if (current($matches['5']) != 'checked="checked" '){ $string .= " (not identical in language to Definition)"; } $string .= "
  • ";

    next($matches['5']); }

    $string .= '
';

return $string; }







}

?>