Example #1
0
 public function handle_action_show_redirect(Doku_Event &$event, $param)
 {
     $act = $event->data['preact'];
     if ($act != 'dokutranslate_review') {
         $act = act_clean($act);
     }
     if (($act == 'save' || $act == 'draftdel') && @file_exists(metaFN($event->data['id'], '.translate'))) {
         $event->data['fragment'] = '_par' . getParID();
     }
 }
Example #2
0
 public function render($mode, Doku_Renderer $renderer, $data)
 {
     global $DOKUTRANSLATE_NEST;
     global $ID;
     global $ACT;
     global $TEXT;
     global $REV;
     # No metadata rendering
     if ($mode == 'metadata') {
         return false;
     }
     # Allow exporting the page
     if (substr($ACT, 0, 7) == 'export_') {
         # Ignore plugin-specific markup, just let text through
         if ($data[0] != DOKU_LEXER_UNMATCHED) {
             return true;
         }
         $renderer->cdata($data[1]);
         return true;
         # Not exporting, allow only XHTML
     } else {
         if ($mode != 'xhtml') {
             return false;
         }
     }
     # Load instructions for original text on first call
     if (is_null($this->origIns)) {
         $DOKUTRANSLATE_NEST++;
         $this->origIns = getCleanInstructions(dataPath($ID) . '/orig.txt');
         $this->meta = loadTranslationMeta($ID);
         $this->parCounter = 0;
         $DOKUTRANSLATE_NEST--;
     }
     $parid = getParID();
     $edithere = in_array($ACT, array('edit', 'preview')) && $parid == $this->parCounter;
     switch ($data[0]) {
         # Open the table
         case DOKU_LEXER_ENTER:
             $renderer->doc .= '<table width="100%" class="dokutranslate"><tbody><tr>';
             $cls = parReviewClass($this->meta, $this->parCounter);
             # Start the cell with proper review class
             if (empty($cls)) {
                 $renderer->doc .= '<td width="50%">';
             } else {
                 $renderer->doc .= '<td width="50%" class="' . $cls . '">';
             }
             # Paragraph anchor (yes, empty named anchor is valid)
             $renderer->doc .= "<a name=\"_par{$this->parCounter}\"></a>\n";
             # Insert edit form if we're editing the first paragraph
             if ($edithere) {
                 startEditForm($renderer);
             }
             break;
             # Dump original text and close the row
         # Dump original text and close the row
         case DOKU_LEXER_SPECIAL:
             # Generate edit button
             if ($ACT == 'show') {
                 if (empty($REV)) {
                     $renderer->doc .= parEditButton($this->parCounter);
                 }
                 $renderer->doc .= $this->_renderReviews($ID, $this->meta, $this->parCounter);
                 # Finish erasure if we're editing this paragraph
             } else {
                 if ($edithere) {
                     endEditForm($renderer);
                     $renderer->doc .= $this->_renderReviews($ID, $this->meta, $this->parCounter);
                 }
             }
             $renderer->doc .= "</td>\n";
             if (needsReview($ID, $this->meta, $this->parCounter) || $edithere) {
                 $renderer->doc .= '<td class="reviewme">';
             } else {
                 $renderer->doc .= '<td>';
             }
             # If this condition fails, somebody's been messing
             # with the data
             if (current($this->origIns) !== FALSE) {
                 $renderer->nest(current($this->origIns));
                 next($this->origIns);
             }
             $renderer->doc .= "</td></tr>\n<tr>";
             $this->parCounter++;
             $cls = parReviewClass($this->meta, $this->parCounter);
             # Start the cell with proper review class
             if (empty($cls)) {
                 $renderer->doc .= '<td width="50%">';
             } else {
                 $renderer->doc .= '<td width="50%" class="' . $cls . '">';
             }
             # Paragraph anchor (yes, empty named anchor is valid)
             $renderer->doc .= "<a name=\"_par{$this->parCounter}\"></a>\n";
             # Insert edit form if we're editing this paragraph
             if (in_array($ACT, array('edit', 'preview')) && getParID() == $this->parCounter) {
                 startEditForm($renderer);
             }
             break;
             # Dump the rest of the original text and close the table
         # Dump the rest of the original text and close the table
         case DOKU_LEXER_EXIT:
             # Generate edit button
             if ($ACT == 'show') {
                 if (empty($REV)) {
                     $renderer->doc .= parEditButton($this->parCounter);
                 }
                 $renderer->doc .= $this->_renderReviews($ID, $this->meta, $this->parCounter);
                 # Finish erasure if we're editing the last paragraph
             } else {
                 if (in_array($ACT, array('edit', 'preview'))) {
                     $parid = getParID();
                     if ($parid == $this->parCounter) {
                         endEditForm($renderer);
                         $renderer->doc .= $this->_renderReviews($ID, $this->meta, $this->parCounter);
                         # Invalid paragraph ID, show form here
                     } else {
                         if ($parid > $this->parCounter) {
                             startEditForm($renderer, true);
                         }
                     }
                 }
             }
             $renderer->doc .= "</td>\n";
             if (needsReview($ID, $this->meta, $this->parCounter) || $edithere) {
                 $renderer->doc .= '<td class="reviewme">';
             } else {
                 $renderer->doc .= '<td>';
             }
             # Loop to make sure all remaining text gets dumped
             # (external edit safety)
             while (current($this->origIns) !== FALSE) {
                 $renderer->nest(current($this->origIns));
                 next($this->origIns);
             }
             $renderer->doc .= '</td></tr></tbody></table>';
             break;
             # Just sanitize and dump the text
         # Just sanitize and dump the text
         default:
             $renderer->cdata($data[1]);
             break;
     }
     return true;
 }