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/mokup code

From OmegaWiki
Jump to: navigation, search

<?php

include_once("../../../wau_lib/functions_3.php"); include_once("functions.php");

require_once 'HTML/QuickForm.php';



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">

       <head>
               <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


               <link rel="stylesheet" type="text/css" media="screen, projection" href="../ow/styles.css" />
               <link rel="stylesheet" type="text/css" media="screen, projection" href="http://www.omegawiki.org/extensions/Wikidata/OmegaWiki/tables.css" />
               <link rel="shortcut icon" href="http://www.omegawiki.org/favicon.ico" />
               <title>OmegaWiki gateway</title>
               <style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "http://www.omegawiki.org/skins/monobook/main.css?55"; /*]]>*/</style>
               <link rel="stylesheet" type="text/css" media="print" href="http://www.omegawiki.org/skins/common/commonPrint.css?55" />
               <link rel="stylesheet" type="text/css" media="handheld" href="http://www.omegawiki.org/skins/monobook/handheld.css?55" />

</head> <body>

<?php


if($_REQUEST['debug'] == 1){

       print_r($_REQUEST);

}


if($_REQUEST['mode'] == 'trainer' && !$_REQUEST['trainer_step']){

       $_REQUEST['trainer_step'] = '0';

}

if(!$_REQUEST['sections']){

       $sections[] = 'syntrans';
       $sections[] = 'def';

}else{

       $sections = explode('|', $_REQUEST['sections']);

}




display_account_seetings($GLOBALS['params']); display_form();


if(!$wdlanguages){

       //echo "Set languages that you can understand";

}

function build_api_query_url(){

$ow_api_url = 'http://141.13.22.237/wikidata/api.php?action=wikidata';

if(

       ($_REQUEST['expression'])
       OR (($_REQUEST['trainer_step'] == '0') AND ($_REQUEST['wdcollection']))
       OR ($_REQUEST['definedmeaning'])

){

       $ow_api_url = $ow_api_url."&wdsections=def|syntrans";


       if($_REQUEST['definedmeaning']){
               $ow_api_url = wau_lib::build_get_uri_2('wdtype', 'definedmeaning', $ow_api_url);
               $ow_api_url = wau_lib::build_get_uri_2('wddmid', $_REQUEST['definedmeaning'], $ow_api_url);
       }elseif($_REQUEST['trainer_step'] == '0' AND (!($_REQUEST['expression']))){
               $ow_api_url = wau_lib::build_get_uri_2('wdtype', 'randomdm', $ow_api_url);
               $ow_api_url = wau_lib::build_get_uri_2('wdcollection', $_REQUEST['wdcollection'], $ow_api_url);
               $ow_api_url = wau_lib::build_get_uri_2('wdexplanguage', $_REQUEST['wdexplanguage'], $ow_api_url);
       }else{
               $ow_api_url = wau_lib::build_get_uri_2('wdtype', 'expression', $ow_api_url);
               $ow_api_url = wau_lib::build_get_uri_2('wdexpression', $_REQUEST['expression'], $ow_api_url);
               $ow_api_url = wau_lib::build_get_uri_2('wdexplanguage', $_REQUEST['wdexplanguage'], $ow_api_url);
       }


       //3320
       //dog http://141.13.222.103/wau/wau_0_5/ow/retrieve_neu.php?definedmeaning=966
       //http://kantoor.edia.nl/wikidata/api.php?action=wikidata&wdexpression=casa&wdexplanguage=ita&wdsections=def%7Csyntrans%7Cdef%7Caltdef%7Csyntrans%7Csyntransann%7Cann%7Cclassatt%7Cclassmem%7Ccolmem%7Crel&wdlanguages=nld%7Ceng%7Cfra


       $wdlanguages_ser = get_wdlanguages('ser');


       $ow_api_url = wau_lib::build_get_uri_2('wdlanguages', $wdlanguages_ser, $ow_api_url);


}

if($_REQUEST['debug'] == 1){

       echo '
'.$ow_api_url."
";

} return $ow_api_url; }


$ow_api_url = build_api_query_url(); $content = mediawiki_lib::get_ow_content_1($ow_api_url); $xml = new SimpleXMLElement($content);

echo '
    '; foreach($xml->body->{'defined-meaning'} as $defined_meaning){ sub_dm($sections, $xml, $defined_meaning, $wdlanguages); } echo '
';

function display_form(){

////////////////////////////////////////// // Instantiate the HTML_QuickForm object $form = new HTML_QuickForm('firstForm', 'get');


     $languages_suggs = array("eng"=>"eng",
                          "deu"=>"deu", 
                          "fra"=>"fra",                           
                          "ita"=>"ita",
                          "nld"=>"nld"
                          );
       $collections = array(
               '376317' => 'One laptop per child basic vocabulary',
               '376322' => 'Destinazione Italia');    

// Set defaults for the form elements $form->setDefaults(array(

   'name' => 'From'

));

// Add some elements to the form $form->addElement('header', null, ); $form->addElement('hidden', 'ow', '1'); $form->addElement('select', 'mode', 'voc browser mode:', array('browser' => 'lookup dictionary', 'trainer' => 'vocabulary training')); if($_REQUEST['mode'] == 'trainer'){

       $form->addElement('select', 'wdcollection', 'Collection to choose vocabulary from:', $collections);
       $form->addElement('select', 'wdlanguages_1', 'target language you want to train:', $languages_suggs);

}else{

       $form->addElement('select', 'wdlanguages_1', 'first output language:', $languages_suggs);

} if($_REQUEST['settings'] == 1){

       $form->addElement('text', 'wdlanguages_2', 'second output language:', array('value' => ,'size' => 6, 'maxlength' => 6));
       $form->addElement('text', 'wdlanguages_3', 'third output language:', array('size' => 6, 'maxlength' => 6));
       $form->addElement('text', 'wdlanguages_4', 'fourth output language:', array('size' => 6, 'maxlength' => 6));
       $link = wau_lib::build_get_uri_2('settings', '0', );
       echo '<a href="'.$link.'">hide settings and languages</a>';

}elseif($_REQUEST['mode'] == 'trainer' && ($_REQUEST['trainer_step'] == 0)){

       $form->addElement('text', 'wdlanguages_2', 'first language you can understand:', array('size' => 6, 'maxlength' => 6));
       $form->addElement('text', 'wdlanguages_3', 'second language you can understand:', array('size' => 6, 'maxlength' => 6));
       $form->addElement('text', 'wdlanguages_4', 'third language you can understand:', array('size' => 6, 'maxlength' => 6));

}else{

       $form->addElement('hidden', 'wdlanguages_2', , array('size' => 6, 'maxlength' => 6));
       $form->addElement('hidden', 'wdlanguages_3', , array('size' => 6, 'maxlength' => 6));
       $form->addElement('hidden', 'wdlanguages_4', , array('size' => 6, 'maxlength' => 6));
       $link = wau_lib::build_get_uri_2('settings', '1', );
       echo '<a href="'.$link.'">edit settings and languages</a>';

}


if($_REQUEST['definedmeaning']){

       $expression_group[] = &HTML_QuickForm::createElement('text', 'expression', 'search expression:', array('value' =>  ,'size' => 20, 'maxlength' => 256));
       $form->updateElementAttr('expression',array('value' => ));
       $expression_group[] = &HTML_QuickForm::createElement('text', 'wdexplanguage', 'source language of an expression 
(leave blank to search all languages)', array('size' => 20, 'maxlength' => 256));

}else{

       $expression_group[] = &HTML_QuickForm::createElement('text', 'expression', 'search expression:', array('size' => 20, 'maxlength' => 256));
       $expression_group[] = &HTML_QuickForm::createElement('text', 'wdexplanguage', 'source language of an expression 
(leave blank to search all languages)', array('size' => 4, 'maxlength' => 256));

}


$form->addGroup($expression_group, 'Expression', 'Search Expression:', '  only in this language:', 0);

       if($_REQUEST['settings'] == 1){
               $form->addElement('text', 'definedmeaning', 'definedmeaning (word-id):', array('value' => , 'size' => 15));
       }else{
       }


$form->addElement('submit', null, 'set / update');

// Define filters and validation rules

// Try to validate a form

// Output the form $form->display(); // ////////////////////////////////////////// } function display_account_seetings($params){

if($GLOBALS['userdata_type'] == 'wau'){

if ($GLOBALS['a']->checkAuth()) {

echo '
logged in as '.$GLOBALS['a']->getUsername().' | ';
       $link = wau_lib::build_get_uri_2('logout', '1');
       echo '<a href="'.$link.'">logout<a> | '; 


}else{

       $link = wau_lib::build_get_uri_2(,, '../tn/login_1.php');
       $link = wau_lib::build_get_uri_2('goto', $params['goto'], $link);
       $link = wau_lib::build_get_uri_2('modulname_neu', $params['modulname_neu'],$link);
       //$link = wau_lib::build_get_uri_2('do_auth', '1',$link);



       echo '<a href="'.$link.'">login / create account<a> | '; 

}





       if($_REQUEST['get_ow_trainer_overview']){
               $arr = get_ow_trainer_overview($params);
echo "

training overview

"; echo "
    "; foreach($params['status_values'] as $value){ echo "
  • "; echo $params['status_messages'][$value].": ".current($arr); next($arr); echo "
  • ";
                   }
    
    echo "
";
       }else{
               $link = wau_lib::build_get_uri_2('get_ow_trainer_overview', '1', );
               echo '<a href="'.$link.'">training  overview<a> | '; 
       }

} }

function get_wdlanguages($output='arr'){

       $wdlanguages = array();
       $wdlanguages[] = $_REQUEST['wdlanguages_1'];
       if($_REQUEST['wdlanguages_2']){
               $wdlanguages[] = $_REQUEST['wdlanguages_2'];
       }
       if($_REQUEST['wdlanguages_3']){
               $wdlanguages[] = $_REQUEST['wdlanguages_3'];
       }
       if($_REQUEST['wdlanguages_4']){
               $wdlanguages[] = $_REQUEST['wdlanguages_4'];
       }
       if($output == 'ser'){
               $wdlanguages = implode('|',$wdlanguages);
       }

return $wdlanguages; }

function sub_dm($sections, $xml, $defined_meaning, $wdlanguages){

echo "
  • "; $link = wau_lib::build_get_uri_2(); $link = wau_lib::build_get_uri_2('definedmeaning', (string) $defined_meaning['defined-meaning-id'], $link); $link_ow = 'http://www.omegawiki.org?title='; $link_ow .= 'DefinedMeaning:('.(string) $defined_meaning['defined-meaning-id'].')'; echo '

    <a href="'.$link.'">dm: '.(string) $defined_meaning['defined-meaning-id'].'</a>

    ';
           echo '<a href="'.$link_ow.'" title="show and edit complete data at omegawiki.org">[edit at omegawiki.org]</a>';
    


           $link = wau_lib::build_get_uri_2('settings', '1', );
           echo  ' [<a href="'.$link.'">set language(s)</a>]';
    
           echo display_wrap(current($sections), $xml, $defined_meaning, $languages);
           next($sections);
    



           if($_REQUEST['trainer_step'] == '0'){
                   echo build_trainer_link(1, $defined_meaning['defined-meaning-id']);
           }
    



    if(!($_REQUEST['trainer_step'] == '0')){

           echo display_wrap(current($sections), $xml, $defined_meaning, $languages);
           next($sections);
    

    }


    if($_REQUEST['trainer_step'] == '1'){

                   echo build_trainer_link(2, $defined_meaning['defined-meaning-id']);
           }
    

    if($_REQUEST['trainer_step'] == '2'){

                   echo build_trainer_link(0, $defined_meaning['defined-meaning-id']);
           }
    

    /*

    echo '
      '; foreach($xml->xpath('//defined-meaning[@defined-meaning-id="'.$defined_meaning['defined-meaning-id'].'"]//synonyms-translations[@indentical-meaning="1"]/expression[@language="'.$wdlanguage.'"]') as $expression){ echo '
    • '.$expression.'
    • ';
                     }
                     foreach($xml->xpath('//defined-meaning[@defined-meaning-id="'.$defined_meaning['defined-meaning-id'].'"]//synonyms-translations[@indentical-meaning="0"]/expression[@language="'.$wdlanguage.'"]') as $expression){
      
      echo '
    • '.$expression.' (not identical)
    • ';
                     }
      
      • /
      echo "";

      }

      function display_wrap($section, $xml, $defined_meaning, $languages){

             if($section == 'def'){
                     $string = display_definition($xml, $defined_meaning, $languages);
             }
             if($section == 'syntrans'){
                     $string =display_expression($wdlanguages, $xml, $defined_meaning, $languages);
             }
      

      return $string; }

      function section_reverse_link(){

             $sections = array_reverse($GLOBALS['sections']);
             $string = implode('|', $sections);
             $link = wau_lib::build_get_uri_2('sections', $string);
      

      if(!$GLOBALS['section_reverse_link']){

             $label = 'change order definition / expression';
      

      }else{

             $label = 'change order definition / expression';
      

      }

             $link = '<a href="'.$link.'">'.$label.'</a>';
             $GLOBALS['section_reverse_link'] = '1';
      

      return $link; }

      function display_definition($xml, $defined_meaning, $languages){ $string = ;

      $wdlanguages = get_wdlanguages(); if($_REQUEST['trainer_step'] == '0' || $_REQUEST['trainer_step'] == '1'){

             $languages = array();
             $languages[] = $wdlanguages[0];
      

      }else{

             $languages = $wdlanguages;
      

      }

      $string .= "

      definitions

      ";
             $string .= section_reverse_link();
      
      $string .= '
        '; $definitions = get_definition($xml, $defined_meaning, $languages); foreach ($definitions['wdlanguage'] as $wdlanguage){ $string .= '
      • '; $string .= $wdlanguage.': '; $string .= current($definitions['translated_text']); $string .= '
      • ';
                       next($definitions['translated_text']);
               }
        
        $string .= '
      ';

      return $string; }


      function display_expression($wdlanguages, $xml, $defined_meaning, $languages){

             $string = ;
             $wdlanguages = get_wdlanguages();
      
      $string .= "

      expressions / translations

      ";
             $string .= section_reverse_link();
      
      $string .= '
        '; if($_REQUEST['trainer_step'] == '0' || $_REQUEST['trainer_step'] == '1'){ $languages = array(); $languages[] = $wdlanguages[0]; }else{ $languages = $wdlanguages; } $expressions = get_expression($xml, $defined_meaning, $languages); foreach ($expressions['wdlanguage'] as $wdlanguage){ if((current($expressions['indentical_meaning'])) == '1'){ $string .= '
      • '; }else{ $string .= '
      • '; } #echo '
      • '; $string .= $wdlanguage.': '; $string .= ''.current($expressions['expression']).''; if((current($expressions['indentical_meaning'])) == '0'){ $string .= " (not identical) "; } $string .= '
      • ';
                       next($expressions['expression']);
                       next($expressions['indentical_meaning']);
               }
        
        $string .= '
      ';

      return $string; }

      function get_definition($xml, $defined_meaning, $wdlanguages){

                     $lang_rows['wdlanguage'] = array();
                     $lang_rows['translated_text'] = array();
      
             foreach($wdlanguages as $wdlanguage){
                     $lang_row = get_definition_sub_1($xml, $defined_meaning, $wdlanguage);
                     $lang_rows['wdlanguage'] = array_merge($lang_rows['wdlanguage'], (array)$lang_row['wdlanguage']);
                     $lang_rows['translated_text'] = array_merge($lang_rows['translated_text'], (array)$lang_row['translated_text']);
             }
             if($lang_rows['wdlanguage'][0] == ){
                     echo "leer";
                     $lang_row = get_definition_sub_1($xml, $defined_meaning, 'eng');
                     $lang_rows['wdlanguage'] = array_merge($lang_rows['wdlanguage'], (array)$lang_row['wdlanguage']);
                     $lang_rows['translated_text'] = array_merge($lang_rows['translated_text'], (array)$lang_row['translated_text']);
      


             }
      

      //print_r($arr); return $lang_rows; }

      function get_definition_sub_1($xml, $defined_meaning, $wdlanguage){

      if($xml->xpath('//defined-meaning[@defined-meaning-id="'.$defined_meaning['defined-meaning-id'].'"]/definition/translated-text-list/translated-text[@language="'.$wdlanguage.'"]')){

             foreach($xml->xpath('//defined-meaning[@defined-meaning-id="'.$defined_meaning['defined-meaning-id'].'"]/definition/translated-text-list/translated-text[@language="'.$wdlanguage.'"]') as $translated_text){
      
                     $arr['wdlanguage'][] = $wdlanguage;
                     $arr['translated_text'][] = (string) $translated_text;
             }
      

      } return $arr;

      }

      function get_expression($xml, $defined_meaning, $wdlanguages){

                     $lang_rows['wdlanguage'] = array();
                     $lang_rows['expression'] = array();
                     $lang_rows['indentical_meaning'] = array();
      
             foreach($wdlanguages as $wdlanguage){
                     $lang_row = get_expression_sub_1($xml, $defined_meaning, $wdlanguage);
                     $lang_rows['wdlanguage']                        = array_merge($lang_rows['wdlanguage'], (array)$lang_row['wdlanguage']);
                     $lang_rows['expression']                        = array_merge($lang_rows['expression'], (array)$lang_row['expression']);
                     $lang_rows['indentical_meaning']        = array_merge($lang_rows['indentical_meaning'], (array)$lang_row['indentical_meaning']);
             }
             if($lang_rows['expression'][0] == ){
                     echo "leer";
                     $lang_row = get_expression_sub_1($xml, $defined_meaning, 'eng');
                     $lang_rows['wdlanguage']                        = array_merge($lang_rows['wdlanguage'], (array)$lang_row['wdlanguage']);
                     $lang_rows['expression']                        = array_merge($lang_rows['expression'], (array)$lang_row['expression']);
                     $lang_rows['indentical_meaning']        = array_merge($lang_rows['indentical_meaning'], (array)$lang_row['indentical_meaning']);
      
             }
      

      //print_r($arr); return $lang_rows; }

      function get_expression_sub_1($xml, $defined_meaning, $wdlanguage){

             $arr = array();
             $arr = get_expression_sub_2($arr, $xml, $defined_meaning, $wdlanguage, '1');
             $arr = get_expression_sub_2($arr, $xml, $defined_meaning, $wdlanguage, '0');
      

      return $arr; }

      function get_expression_sub_2($arr, $xml, $defined_meaning, $wdlanguage, $indentical_meaning){

      $xpath_expr = '//defined-meaning[@defined-meaning-id="'.$defined_meaning['defined-meaning-id'].'"]//synonyms-translations[@indentical-meaning="'.$indentical_meaning.'"]/expression[@language="'.$wdlanguage.'"]'; if($defined_meaning->xpath($xpath_expr)){

             foreach($defined_meaning->xpath($xpath_expr) 
             as $synonyms_translation){
      
                     $arr['wdlanguage'][] = $wdlanguage;
                     $arr['expression'][] = (string) $synonyms_translation;
                     $arr['indentical_meaning'][] = $indentical_meaning;
             }
      

      } return $arr;

      }

      function build_trainer_link($step, $definedmeaning){

             $step = intval($step);
             $link = wau_lib::build_get_uri_2();
             $link = wau_lib::build_get_uri_2('trainer_step', $step, $link);
             $link = wau_lib::build_get_uri_2('definedmeaning', (string) $definedmeaning, $link);
      
             if($step != '0'){
                     $linktext = 'show more';
                     $link_a = '
                     <a href="'.$link.'">
                     '.$linktext.'
                     <img src="/wau/production/bilder/pfeil_u_1.png">
                     <img src="/wau/production/bilder/question_mark_1.png">
                     </a>';
             }
                     $link = wau_lib::build_get_uri_2('trainer_step', '0', $link);
                     $link = wau_lib::build_get_uri_2('definedmeaning', , $link);
                     $linktext = 'continue with next';
                     $link_b = '
                     <a href="'.$link.'">
                     <img src="/wau/production/bilder/pfeil_r_1.gif">
                     '.$linktext.'
                     </a>';
      
      1. $linktext = 'continue with next';


             if($GLOBALS['userdata_type'] == 'wau'){
                     if ($GLOBALS['a']->checkAuth()) {    
      
      $link_a .= "
      ".build_save_staus_link( (string) $definedmeaning);
                     }
             }
      

      return $link_a.$link_b; }

      function build_save_staus_link($definedmeaning){

                             $params = $GLOBALS['params'];
                             $params['dm_id'] =  (string) $definedmeaning;
                             $dm_status = get_ow_trainer_status($params);
      
      $link = '
        '; foreach($GLOBALS['params']['status_values'] as $value){ $link .= build_save_staus_link_sub( $definedmeaning,$dm_status,$value, current($GLOBALS['params']['status_messages'])); next($GLOBALS['params']['status_messages']); } $link .= '
      ';

      return $link; }

      function build_save_staus_link_sub($definedmeaning,$dm_status,$value, $message){

             $link = wau_lib::build_get_uri_2();
             $link = wau_lib::build_get_uri_2('save_ow_trainer_data', '1', $link);
             $link = wau_lib::build_get_uri_2('definedmeaning', (string) $definedmeaning, $link);
             $link = wau_lib::build_get_uri_2('dm_status', $value, $link);
             if($_REQUEST['trainer_step'] == '2'){ //stay on same dm for switching
                     $link = wau_lib::build_get_uri_2('trainer_step', '2', $link);
             }
      
             if($value != $dm_status){
      
      $string .= '
    • <a href="'.$link.'"> '.$message.'</a>'; }else{ $string .= '
    • '.$message.'
    • ';
             }
      

      return $string; }


      ?> </form>

      </body>