Exemplo n.º 1
0
 /**
  * Get dictionary detail page
  */
 function show_phrase()
 {
     global $_GET;
     $lex_classes = $this->db->get_row_assoc('SELECT * FROM lexical_class', 'lex_class', 'lex_class_name');
     $this->phrase = $this->get_phrase();
     $phrase = $this->phrase;
     $this->kbbi = new kbbi($this->msg, &$this->db);
     // if it's not marked created
     if (!$phrase['created']) {
         $this->kbbi->force_refresh = true;
         $this->kbbi->parse($_GET['phrase']);
         if ($this->kbbi->found) {
             $this->save_kbbi($_GET['phrase']);
         }
         $this->kbbi->force_refresh = false;
         $this->phrase = $this->get_phrase();
         $phrase = $this->phrase;
     }
     // if it's not marked created
     if (!$phrase['kbbi_updated']) {
         $this->kbbi->force_refresh = true;
         $this->kbbi->parse($_GET['phrase']);
         if ($this->kbbi->found) {
             $this->save_kbbi2($_GET['phrase']);
         }
         $this->kbbi->force_refresh = false;
         $this->phrase = $this->get_phrase();
         $phrase = $this->phrase;
     }
     // header
     if ($phrase['pronounciation']) {
         $pronounce = sprintf(' <small>/%s/</small>', $phrase['pronounciation']);
     }
     $ret .= sprintf('<h1>%1$s%2$s</h1>' . LF, $_GET['phrase'], $pronounce);
     // buttons
     if ($this->auth->checkAuth()) {
         $actions = array('new' => array('url' => './?mod=dictionary&action=form'), 'edit' => array('url' => './?mod=dictionary&action=form&phrase=' . $_GET['phrase']), 'delete' => array('url' => './?mod=dictionary&action=delete&phrase=' . $_GET['phrase']), 'get_kbbi' => array('url' => './?mod=dictionary&action=kbbi&phrase=' . $_GET['phrase']));
         $ret .= $this->get_action_buttons($actions, $phrase ? null : array('new', 'get_kbbi'));
     }
     $panel_head = '<div class="panel-heading">' . '<h4 class="panel-title">' . '<a data-toggle="collapse" data-parent="#accordion" ' . 'href="#%s">%s</a></h4>' . '</div>';
     // found?
     if ($phrase) {
         $i = 0;
         // PREPROCESSING
         // definition: get from actual phrase or definition
         if ($phrase['actual_phrase']) {
             $defs = array(array('def_num' => 1, 'def_text' => $phrase['actual_phrase'], 'see' => $phrase['actual_phrase']));
         } else {
             $defs = $phrase['definition'];
         }
         for ($j = 0; $j < count($defs); $j++) {
             if ($defs[$j]['lex_class'] == '') {
                 $defs[$j]['lex_class'] = $phrase['lex_class'];
             }
             $lex_class = $defs[$j]['lex_class'];
             $def_group[$lex_class][] = $defs[$j];
         }
         if ($phrase['info']) {
             $tags = explode(',', $phrase['info']);
         }
         if ($tag_count = count($tags)) {
             for ($j = 0; $j < $tag_count; $j++) {
                 $tags[$j] = trim($tags[$j]);
             }
         }
         if ($phrase['actual_phrase']) {
             $tags[] = 'var';
         }
         // show definition
         $def_count = count($defs);
         if ($def_group) {
             foreach ($def_group as $lex_key => $defs) {
                 $lex_name = $lex_classes[$lex_key] . ' (' . $lex_key . ')';
                 $ret .= sprintf('<h4>%s</h4>', $lex_name) . LF;
                 $ret .= '<ol>' . LF;
                 foreach ($defs as $def) {
                     // discipline
                     // $discipline = ($i == 0) ? $phrase['info'] : '';
                     $discipline = '';
                     if ($def['discipline']) {
                         $discipline .= $discipline ? ', ' : '';
                         $discipline .= $def['discipline'];
                     }
                     $dsc = $discipline ? '<em>(' . $this->get_abbrev($discipline) . ')</em> ' : '';
                     // start
                     $ret .= '<li>';
                     if ($def['see']) {
                         $ret .= sprintf('%3$s%4$s&rarr; <a href="%2$s%1$s">%1$s</a>', $def['see'], './?mod=dictionary&action=view&phrase=', $lex, $dsc);
                     } else {
                         $ret .= sprintf('%4$s%2$s%1$s%3$s', $def['def_text'], $dsc, $def['sample'] ? ': <span class="sample">' . $def['sample'] . '</span>' : '', $lex);
                     }
                     $ret .= '</li>' . LF;
                     $i++;
                 }
                 $ret .= '</ol>' . LF;
             }
         } else {
             $ret .= '<p>' . $this->msg['na'] . '</p>' . LF;
         }
         // labels
         $ret .= '<div style="margin-bottom:20px">';
         if ($phrase['ref_source']) {
             $ret .= sprintf('<span><a href="./?mod=dictionary&src=%2$s&srch=Cari" class="label label-info">%1$s</a></span>', $phrase['ref_source_name'], $phrase['ref_source']) . LF;
         }
         if ($tags) {
             foreach ($tags as $tag) {
                 if (array_key_exists($tag, $this->abbrevs)) {
                     $ret .= sprintf('<span class="label label-info">%1$s</span>', $this->abbrevs[$tag]) . LF;
                 }
             }
         }
         $ret .= '</div>' . LF;
         // additional info
         if ($phrase['root'] || $phrase['etymology'] || $phrase['notes'] || $phrase['reference']) {
             $ret .= '<div class="row" style="margin-bottom:20px;">' . LF;
             if ($phrase['root'] || $phrase['etymology']) {
                 $ret .= '<div class="col-sm-6">' . LF;
                 if ($phrase['root']) {
                     $ret .= '<h4 style="color:#999;">Kata Dasar</h4>' . LF;
                     $ret .= sprintf('<p style="margin-left:20px;">%s</p>' . LF, $this->merge_phrase_list($phrase['root'], 'root_phrase'));
                 }
                 // etymology
                 if ($phrase['etymology']) {
                     $ret .= '<h4 style="color:#999;">Etimologi</h4>' . LF;
                     $ret .= sprintf('<p style="margin-left:20px;">%s</p>', $phrase['etymology']) . LF;
                 }
                 $ret .= '</div>' . LF;
             }
             // reference
             if ($phrase['notes'] || $phrase['reference']) {
                 $ret .= '<div class="col-sm-6">' . LF;
                 // notes
                 if ($phrase['notes']) {
                     $ret .= '<h4 style="color:#999;">Catatan</h4>' . LF;
                     $ret .= sprintf('<p style="margin-left:20px;">%s</p>', $phrase['notes']) . LF;
                 }
                 if ($phrase['reference']) {
                     $ret .= '<h4 style="color:#999;">Tautan</h4>' . LF;
                     $ret .= '<ul>' . LF;
                     foreach ($phrase['reference'] as $reference) {
                         $ret .= sprintf('<li><a href="%2$s">%1$s</a></li>' . LF, $reference['label'] ? $reference['label'] : $reference['url'], $reference['url']);
                     }
                     $ret .= '</ul>' . LF;
                 }
                 $ret .= '</div>' . LF;
             }
             $ret .= '</div>' . LF;
         }
         // misc
         $template = '<dt>%1$s</dt><dd>' . LF . '%2$s</dd>' . LF;
         $ret .= '<div class="panel-group" id="accordion">';
         // relation and derivation
         if ($ret_related = $this->show_relation($phrase, 'related_phrase')) {
             $ret .= $this->show_panel('panelRelated', 'Kata Terkait', $ret_related);
         }
         // peribahasa
         if ($phrase['proverbs']) {
             $ret_proverb .= '<ul>' . LF;
             foreach ($phrase['proverbs'] as $proverb) {
                 $ret_proverb .= sprintf('<li><em>%1$s</em>: %2$s</li>' . LF, $proverb['proverb'], $proverb['meaning']);
             }
             $ret_proverb .= '</ul>' . LF;
             $ret .= $this->show_panel('panelProverb', 'Peribahasa', $ret_proverb);
         }
         // translation
         if ($phrase['translations']) {
             $ret_translation .= '<ul>' . LF;
             foreach ($phrase['translations'] as $translation) {
                 $ret_translation .= sprintf('<li><em>%1$s</em>: %2$s</li>' . LF, $translation['ref_source'], $translation['translation']);
             }
             $ret_translation .= '</ul>' . LF;
             $ret .= $this->show_panel('panelTranslation', 'Terjemahan', $ret_translation);
         }
         // kbbi
         if ($ret_kbbi = $this->show_kbbi()) {
             $ret .= $this->show_panel('panelKBBI', 'KBBI', $ret_kbbi);
         }
         // additional process: update relation
         if ($phrase['relation']['d']) {
             $word = $_GET['phrase'];
             $tmp = '';
             foreach ($phrase['relation']['d'] as $rel) {
                 $pattern = '/\\b' . $word . '\\b/';
                 if (preg_match($pattern, $rel['related_phrase']) && !strpos($rel['related_phrase'], '-')) {
                     $tmp .= $tmp ? ', ' : '';
                     $tmp .= "'" . $rel['related_phrase'] . "'";
                 }
             }
             if ($tmp) {
                 $sql = sprintf('UPDATE relation SET
                     rel_type = \'c\',
                     updater = \'%3$s\',
                     updated = NOW()
                     WHERE root_phrase = \'%1$s\'
                     AND related_phrase IN (%2$s);', $word, $tmp, 'compounder');
                 $this->db->exec($sql);
             }
         }
         // additional process: insert new root
         if ($phrase['root']) {
             $words = "'" . str_replace(' ', "', '", $_GET['phrase']) . "'";
             $sql = sprintf('
                 INSERT INTO relation
                 (root_phrase, related_phrase, rel_type, updater, updated)
                 SELECT phrase, \'%2$s\', \'c\', \'rooter\', NOW()
                 FROM phrase
                 WHERE phrase <> \'%2$s\' AND phrase IN (%1$s) AND phrase NOT IN
                     (SELECT root_phrase FROM relation
                     WHERE related_phrase = \'%2$s\');', $words, $_GET['phrase']);
             $this->db->exec($sql);
         }
     } else {
         $ret .= sprintf('<p style="margin-bottom:20px;">%1$s</p>', sprintf($this->msg['phrase_na'], $_GET['phrase']));
         // derivation and relation
         $this->get_relation(&$phrase, 'related_phrase', true);
         $ret .= $this->show_panel('panelRelated', 'Kata Terkait', $this->show_relation($phrase, 'root_phrase'));
     }
     // glosarium
     $_GET['lang'] = 'id';
     $glossary = new glossary(&$this->db, &$this->auth, $this->msg);
     $glos_in = isset($_GET['p']) ? ' in' : '';
     $glossary->sublist = true;
     if ($ret_glossary = $glossary->show_result()) {
         $glossary_label = sprintf('Glosarium <span class="badge">%s</span>', $glossary->db->pager['rcount']);
         $ret .= $this->show_panel('panelGlossary', $glossary_label, $ret_glossary, $glos_in);
     }
     $ret .= '</div>' . LF;
     // navigation
     if ($phrase) {
         $ret .= '<div style="margin-top:20px; text-align:center;">' . $this->get_prev_next($_GET['phrase']) . '</div>';
     }
     return $ret;
 }
Exemplo n.º 2
0
 /**
  * Alternate display
  */
 function show_phrase2()
 {
     global $_GET;
     $lex_classes = $this->db->get_row_assoc('SELECT * FROM lexical_class', 'lex_class', 'lex_class_name');
     $this->phrase = $this->get_phrase();
     $phrase = $this->phrase;
     $this->kbbi = new kbbi($this->msg, &$this->db);
     // if it's not marked created
     if (!$phrase['created']) {
         $this->kbbi->force_refresh = true;
         $this->kbbi->parse($_GET['phrase']);
         if ($this->kbbi->found) {
             $this->save_kbbi($_GET['phrase']);
         }
         $this->kbbi->force_refresh = false;
         $this->phrase = $this->get_phrase();
         $phrase = $this->phrase;
     }
     // if it's not marked created
     if (!$phrase['kbbi_updated']) {
         $this->kbbi->force_refresh = true;
         $this->kbbi->parse($_GET['phrase']);
         if ($this->kbbi->found) {
             $this->save_kbbi2($_GET['phrase']);
         }
         $this->kbbi->force_refresh = false;
         $this->phrase = $this->get_phrase();
         $phrase = $this->phrase;
     }
     // header
     $ret .= sprintf('<h1>%1$s</h1>' . LF, $_GET['phrase']);
     // kbbi header
     $ret .= '<table width="100%" cellpadding="0" cellspacing="0"><tr valign="top"><td width="60%">' . LF;
     if ($this->auth->checkAuth()) {
         $actions = array('new' => array('url' => './?mod=dictionary&action=form'), 'edit' => array('url' => './?mod=dictionary&action=form&phrase=' . $_GET['phrase']), 'delete' => array('url' => './?mod=dictionary&action=delete&phrase=' . $_GET['phrase']), 'get_kbbi' => array('url' => './?mod=dictionary&action=kbbi&phrase=' . $_GET['phrase']));
         $ret .= $this->get_action_buttons($actions, $phrase ? null : array('new', 'get_kbbi'));
     }
     // found?
     if ($phrase) {
         $i = 0;
         // definition: get from actual phrase or definition
         if ($phrase['actual_phrase']) {
             $defs = array(array('def_num' => 1, 'def_text' => $phrase['actual_phrase'], 'see' => $phrase['actual_phrase']));
         } else {
             $defs = $phrase['definition'];
         }
         $ret .= '<p>';
         $ret .= sprintf('<strong>%1$s</strong> ', $phrase['phrase']);
         if ($phrase['pronounciation']) {
             $ret .= sprintf(' /%2$s/ ', $this->msg['pronounciation'], $phrase['pronounciation']);
         }
         if ($phrase['lex_class_name']) {
             $lex_name = $phrase['lex_class_name'];
             if ($phrase['lex_class_ref']) {
                 $lex_name = sprintf('<a href="./?mod=dictionary&action=view&phrase=%2$s">%1$s</a>', $phrase['lex_class_name'], $phrase['lex_class_ref']);
             }
             $ret .= sprintf(' <em>%2$s</em> ', $this->msg['lex_class'], strtolower($lex_name));
         }
         // show definition
         $def_count = count($defs);
         if ($defs) {
             foreach ($defs as $def) {
                 $discipline = $i == 0 ? $phrase['info'] : '';
                 if ($def_count > 1) {
                     $ret .= '<strong>' . ($i + 1) . '.</strong> ';
                 }
                 if ($def['see']) {
                     $ret .= sprintf('lihat <b><a href="./?mod=dictionary&action=view&phrase=%2$s">%1$s</a></b>', $def['see'], $def['see']);
                 } else {
                     if ($def['discipline']) {
                         $discipline .= $discipline ? ', ' : '';
                         $discipline .= $def['discipline'];
                     }
                     $lex_name = $def['lex_class'];
                     $lex_title = $lex_classes[$def['lex_class']];
                     if ($def['lex_class_ref']) {
                         $lex_name = sprintf('<a href="./?mod=dictionary&action=view&phrase=%2$s" title="%3$s">%1$s</a>', $def['lex_class'], $def['lex_class_ref'], $lex_title);
                     }
                     $ret .= sprintf('%4$s%2$s%1$s%3$s', $def['def_text'], $discipline ? '<em>(' . $this->get_abbrev($discipline) . ')</em> ' : '', $def['sample'] ? ': <em>' . $def['sample'] . '</em> ' : '', $def['lex_class'] ? '<em>' . $lex_name . '</em> ' : '');
                 }
                 if ($def_count > 1) {
                     $ret .= '; ';
                 }
                 $i++;
             }
         } else {
             $ret .= $this->msg['na'];
         }
         $ret .= '</p>' . LF;
         // misc
         $template = '<p><b>%1$s:</b><br />' . LF . '%2$s</p>' . LF;
         $template = '<dl><dt>%1$s:</dt><dd>' . LF . '%2$s</dd></dl>' . LF;
         $template = '<p><em>%1$s:</em> ' . LF . '%2$s</p>' . LF;
         if ($phrase['etymology']) {
             $ret .= sprintf($template, $this->msg['etymology'], $phrase['etymology']);
         }
         if ($phrase['root']) {
             $ret .= sprintf($template, $this->msg['root_phrase'], $this->merge_phrase_list($phrase['root'], 'root_phrase'));
         }
         if ($phrase['roget_class']) {
             $ret .= sprintf($template, $this->msg['roget_class'], $phrase['roget_name']);
         }
         if ($phrase['ref_source']) {
             $ret .= sprintf($template, $this->msg['ref_source'], $phrase['ref_source_name']);
         }
         // reference
         if ($phrase['reference']) {
             $ret .= '<p>' . $this->msg['external_ref'] . ':</p>' . LF;
             $ret .= '<ul>' . LF;
             foreach ($phrase['reference'] as $reference) {
                 $ret .= sprintf('<li><a href="%2$s">%1$s</a></li>' . LF, $reference['label'] ? $reference['label'] : $reference['url'], $reference['url']);
             }
             $ret .= '</ul>' . LF;
         }
         // relation and derivation
         $ret .= $this->show_relation($phrase, 'related_phrase');
         // peribahasa
         if ($phrase['proverbs']) {
             $ret .= sprintf('<h2>%1$s</h2>' . LF, $this->msg['proverb']);
             $ret .= '<ul>' . LF;
             foreach ($phrase['proverbs'] as $proverb) {
                 $ret .= sprintf('<li><em>%1$s</em>: %2$s</li>' . LF, $proverb['proverb'], $proverb['meaning']);
             }
             $ret .= '</ul>' . LF;
         }
         // translation
         if ($phrase['translations']) {
             $ret .= sprintf('<h2>%1$s</h2>' . LF, $this->msg['translation']);
             $ret .= '<ul>' . LF;
             foreach ($phrase['translations'] as $translation) {
                 $ret .= sprintf('<li><em>%1$s</em>: %2$s</li>' . LF, $translation['ref_source'], $translation['translation']);
             }
             $ret .= '</ul>' . LF;
         }
     } else {
         $ret .= sprintf('<p>%1$s</p>', sprintf($this->msg['phrase_na'], $_GET['phrase']));
         // derivation and relation
         $this->get_relation(&$phrase, 'related_phrase', true);
         $ret .= $this->show_relation($phrase, 'root_phrase');
     }
     // glosarium
     $ret .= sprintf('<h2>%1$s</h2>' . LF, $this->msg['glossary']);
     $_GET['lang'] = 'id';
     $glossary = new glossary(&$this->db, &$this->auth, $this->msg);
     $glossary->sublist = true;
     $ret .= $glossary->show_result();
     $ret .= $this->show_kbbi();
     return $ret;
 }