includes/render.php
changeset 37 7267c2a67a93
parent 35 efae425e9b98
child 63 2c57d3018a88
equal deleted inserted replaced
36:425261984266 37:7267c2a67a93
   241     }
   241     }
   242     
   242     
   243     if ( !$plaintext )
   243     if ( !$plaintext )
   244     {
   244     {
   245       // Process images
   245       // Process images
   246       $text = RenderMan::process_image_tags($text);
   246       $text = RenderMan::process_image_tags($text, $taglist);
   247     }
   247     }
   248     
   248     
   249     if($do_params)
   249     if($do_params)
   250     {
   250     {
   251       preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
   251       preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
   268     else
   268     else
   269     {
   269     {
   270       $wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath);
   270       $wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath);
   271       $wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external');
   271       $wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external');
   272       $result = $wiki->transform($text, 'Xhtml');
   272       $result = $wiki->transform($text, 'Xhtml');
       
   273     }
       
   274     
       
   275     if ( !$plaintext )
       
   276     {
       
   277       $result = RenderMan::process_imgtags_stage2($result, $taglist);
   273     }
   278     }
   274     
   279     
   275     // Reinsert <nowiki> sections
   280     // Reinsert <nowiki> sections
   276     for($i=0;$i<$nw;$i++)
   281     for($i=0;$i<$nw;$i++)
   277     {
   282     {
   745   }
   750   }
   746   
   751   
   747   /**
   752   /**
   748    * Changes wikitext image tags to HTML.
   753    * Changes wikitext image tags to HTML.
   749    * @param string The wikitext to process
   754    * @param string The wikitext to process
       
   755    * @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility)
   750    * @return string
   756    * @return string
   751    */
   757    */
   752   
   758   
   753   function process_image_tags($text)
   759   function process_image_tags($text, &$taglist)
   754   {
   760   {
   755     global $db, $session, $paths, $template, $plugins; // Common objects
   761     global $db, $session, $paths, $template, $plugins; // Common objects
       
   762     
       
   763     $s_delim = "\xFF";
       
   764     $f_delim = "\xFF";
       
   765     $taglist = array();
   756     
   766     
   757     // Wicked huh?
   767     // Wicked huh?
   758     $regex = '/\[\[:' . $paths->nslist['File'] . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?)((\|thumb)|(\|([0-9]+)x([0-9]+)))?(\|left|\|right)?(\|(.+))?\]\]/i';
   768     $regex = '/\[\[:' . $paths->nslist['File'] . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?)((\|thumb)|(\|([0-9]+)x([0-9]+)))?(\|left|\|right)?(\|(.+))?\]\]/i';
   759     
   769     
   760     preg_match_all($regex, $text, $matches);
   770     preg_match_all($regex, $text, $matches);
   799       if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' )
   809       if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' )
   800       {
   810       {
   801         $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" ';
   811         $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" ';
   802       }
   812       }
   803       
   813       
   804       if ( empty($clear) && $scale_type == '|thumb' )
       
   805       {
       
   806         $clear = 'right';
       
   807       }
       
   808       
       
   809       $img_tag .= 'style="border-width: 0px; background-color: white;" ';
   814       $img_tag .= 'style="border-width: 0px; background-color: white;" ';
   810       
   815       
   811       $img_tag .= '/>';
   816       $img_tag .= '/>';
   812       
   817       
   813       $complete_tag = '';
   818       $complete_tag = '';
   818         $clear_text = '';
   823         $clear_text = '';
   819         if ( !empty($clear) )
   824         if ( !empty($clear) )
   820         {
   825         {
   821           $side = ( $clear == '|left' ) ? 'left' : 'right';
   826           $side = ( $clear == '|left' ) ? 'left' : 'right';
   822           $opposite = ( $clear == '|left' ) ? 'right' : 'left';
   827           $opposite = ( $clear == '|left' ) ? 'right' : 'left';
   823           $clear_text .= "clear: $side; float: $side; margin-$opposite: 20px;";
   828           $clear_text .= "float: $side; margin-$opposite: 20px;";
   824           $complete_tag .= 'style="' . $clear_text . '" ';
   829           $complete_tag .= 'style="' . $clear_text . '" ';
   825         }
   830         }
   826         $complete_tag .= '>';
   831         $complete_tag .= '>';
   827         
   832         
   828         $complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
   833         $complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
   844         $complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
   849         $complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
   845         $complete_tag .= $img_tag;
   850         $complete_tag .= $img_tag;
   846         $complete_tag .= '</a>';
   851         $complete_tag .= '</a>';
   847       }
   852       }
   848       
   853       
   849       $complete_tag = "<nowiki>$complete_tag</nowiki>\n\n";
   854       $complete_tag .= "\n\n";
   850       
   855       $taglist[$i] = $complete_tag;
   851       $pos = strpos($text, $full_tag) - 3;
   856       
       
   857       $pos = strpos($text, $full_tag);
   852       
   858       
   853       while(true)
   859       while(true)
   854       {
   860       {
   855         $check1 = substr($text, $pos, 3);
   861         $check1 = substr($text, $pos, 3);
   856         $check2 = substr($text, $pos, 1);
   862         $check2 = substr($text, $pos, 1);
   860           break;
   866           break;
   861         }
   867         }
   862         $pos--;
   868         $pos--;
   863       }
   869       }
   864       
   870       
   865       $text = substr($text, 0, $pos) . $complete_tag . substr($text, $pos + 1);
   871       $repl = "{$s_delim}e_img_{$i}{$f_delim}";
       
   872       $text = substr($text, 0, $pos) . $repl . substr($text, $pos);
   866       
   873       
   867       $text = str_replace($full_tag, '', $text);
   874       $text = str_replace($full_tag, '', $text);
   868       
   875       
   869       unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height);
   876       unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height);
   870       
   877       
   871     }
   878     }
   872     
   879     
       
   880     return $text;
       
   881   }
       
   882   
       
   883   /**
       
   884    * Finalizes processing of image tags.
       
   885    * @param string The preprocessed text
       
   886    * @param array The list of image tags created by RenderMan::process_image_tags()
       
   887    */
       
   888    
       
   889   function process_imgtags_stage2($text, $taglist)
       
   890   {
       
   891     $s_delim = "\xFF";
       
   892     $f_delim = "\xFF";
       
   893     foreach ( $taglist as $i => $tag )
       
   894     {
       
   895       $repl = "{$s_delim}e_img_{$i}{$f_delim}";
       
   896       $text = str_replace($repl, $tag, $text);
       
   897     }               
   873     return $text;
   898     return $text;
   874   }
   899   }
   875   
   900   
   876 }
   901 }
   877  
   902