includes/render.php
changeset 35 efae425e9b98
parent 24 9ecc94c4c7f5
child 37 7267c2a67a93
equal deleted inserted replaced
34:80f52593bee9 35:efae425e9b98
   241     }
   241     }
   242     
   242     
   243     if ( !$plaintext )
   243     if ( !$plaintext )
   244     {
   244     {
   245       // Process images
   245       // Process images
   246       
   246       $text = RenderMan::process_image_tags($text);
   247       $j = preg_match_all('#\[\[:'.$paths->nslist['File'].'([\w\s0-9_\(\)!@%\^\+\|\.-]+?)\|([0-9]+)\|([0-9]+)\]\]#is', $text, $matchlist);
       
   248       $matches = Array();
       
   249       $matches['images']  =& $matchlist[1];
       
   250       $matches['widths']  =& $matchlist[2];
       
   251       $matches['heights'] =& $matchlist[3];
       
   252       for($i=0;$i<sizeof($matchlist[1]);$i++)
       
   253       {
       
   254         if(isPage($paths->nslist['File'].$matches['images'][$i])) $text = str_replace('[[:'.$paths->nslist['File'].$matches['images'][$i].'|'.$matches['widths'][$i].'|'.$matches['heights'][$i].']]',
       
   255           '<nowiki><a href="'.makeUrlNS('File', $matches['images'][$i]).'"><img alt="'.$matches['images'][$i].'" style="border: 0" src="'.makeUrlNS('Special', 'DownloadFile/'.$matches['images'][$i], 'preview&amp;width='.$matches['widths'][$i].'&amp;height='.$matches['heights'][$i]).'" /></a></nowiki>',
       
   256           $text);
       
   257       }
       
   258       
       
   259       $j = preg_match_all('#\[\[:'.$paths->nslist['File'].'([\w\s0-9_\(\)!@%\^\+\|\.-]+?)\]\]#is', $text, $matchlist);
       
   260       $matches = Array();
       
   261       $matches['images'] = $matchlist[1];
       
   262       for($i=0;$i<sizeof($matchlist[1]);$i++)
       
   263       {
       
   264         if(isPage($paths->nslist['File'].$matches['images'][$i])) $text = str_replace('[[:'.$paths->nslist['File'].$matches['images'][$i].']]',
       
   265           '<nowiki><a href="'.makeUrlNS('File', $matches['images'][$i]).'"><img alt="'.$matches['images'][$i].'" style="border: 0" src="'.makeUrlNS('Special', 'DownloadFile/'.$matches['images'][$i]).'" /></a></nowiki>',
       
   266           $text);
       
   267       }
       
   268       
       
   269     }
   247     }
   270     
   248     
   271     if($do_params)
   249     if($do_params)
   272     {
   250     {
   273       preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
   251       preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist);
   332       
   310       
   333       $message = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $message);
   311       $message = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $message);
   334       
   312       
   335       //return '<pre>'.htmlspecialchars($message).'</pre>';
   313       //return '<pre>'.htmlspecialchars($message).'</pre>';
   336       
   314       
   337       $j = preg_match_all('#\[\[:'.$paths->nslist['File'].'([\w\s0-9_\(\)!@%\^\+\|\.-]+?)\|([0-9]+)\|([0-9]+)\]\]#is', $message, $matchlist);
   315       $message = RenderMan::process_image_tags($message);
   338       $matches = Array();
       
   339       $matches['images'] = $matchlist[1];
       
   340       $matches['widths'] = $matchlist[2];
       
   341       $matches['heights'] = $matchlist[3];
       
   342       for($i=0;$i<sizeof($matchlist[1]);$i++)
       
   343       {
       
   344         if(isPage($paths->nslist['File'].$matches['images'][$i])) $message = str_replace('[[:'.$paths->nslist['File'].$matches['images'][$i].'|'.$matches['widths'][$i].'|'.$matches['heights'][$i].']]',
       
   345           '<nowiki><a href="'.makeUrlNS('File', $matches['images'][$i]).'"><img alt="'.$matches['images'][$i].'" style="border: 0" src="'.makeUrlNS('Special', 'DownloadFile/'.$matches['images'][$i], 'preview&amp;width='.$matches['widths'][$i].'&amp;height='.$matches['heights'][$i]).'" /></a></nowiki>',
       
   346           $message);
       
   347       }
       
   348       
       
   349       $j = preg_match_all('#\[\[:'.$paths->nslist['File'].'([\w\s0-9_\(\)!@%\^\+\|\.-]+?)\]\]#is', $message, $matchlist);
       
   350       $matches = Array();
       
   351       $matches['images'] = $matchlist[1];
       
   352       for($i=0;$i<sizeof($matchlist[1]);$i++)
       
   353       {
       
   354         if(isPage($paths->nslist['File'].$matches['images'][$i])) $message = str_replace('[[:'.$paths->nslist['File'].$matches['images'][$i].']]',
       
   355           '<nowiki><a href="'.makeUrlNS('File', $matches['images'][$i]).'"><img alt="'.$matches['images'][$i].'" style="border: 0" src="'.makeUrlNS('Special', 'DownloadFile/'.$matches['images'][$i]).'" /></a></nowiki>',
       
   356           $message);
       
   357       }
       
   358     
   316     
   359     }
   317     }
   360     
   318     
   361     if($do_params)
   319     if($do_params)
   362     {
   320     {
   784     $diff = new Diff($str1, $str2);
   742     $diff = new Diff($str1, $str2);
   785     $renderer = new TableDiffFormatter();
   743     $renderer = new TableDiffFormatter();
   786     return '<table class="diff">'.$renderer->format($diff).'</table>';
   744     return '<table class="diff">'.$renderer->format($diff).'</table>';
   787   }
   745   }
   788   
   746   
       
   747   /**
       
   748    * Changes wikitext image tags to HTML.
       
   749    * @param string The wikitext to process
       
   750    * @return string
       
   751    */
       
   752   
       
   753   function process_image_tags($text)
       
   754   {
       
   755     global $db, $session, $paths, $template, $plugins; // Common objects
       
   756     
       
   757     // Wicked huh?
       
   758     $regex = '/\[\[:' . $paths->nslist['File'] . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?)((\|thumb)|(\|([0-9]+)x([0-9]+)))?(\|left|\|right)?(\|(.+))?\]\]/i';
       
   759     
       
   760     preg_match_all($regex, $text, $matches);
       
   761     
       
   762     foreach ( $matches[0] as $i => $match )
       
   763     {
       
   764       
       
   765       $full_tag   =& $matches[0][$i];
       
   766       $filename   =& $matches[1][$i];
       
   767       $scale_type =& $matches[2][$i];
       
   768       $width      =& $matches[5][$i];
       
   769       $height     =& $matches[6][$i];
       
   770       $clear      =& $matches[7][$i];
       
   771       $caption    =& $matches[8][$i];
       
   772       
       
   773       if ( !isPage( $paths->nslist['File'] . $filename ) )
       
   774       {
       
   775         continue;
       
   776       }
       
   777       
       
   778       if ( $scale_type == '|thumb' )
       
   779       {
       
   780         $r_width  = 225;
       
   781         $r_height = 225;
       
   782         
       
   783         $url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true);
       
   784       }
       
   785       else if ( !empty($width) && !empty($height) )
       
   786       {
       
   787         $r_width = $width;
       
   788         $r_height = $height;
       
   789         
       
   790         $url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true);
       
   791       }
       
   792       else
       
   793       {
       
   794         $url = makeUrlNS('Special', 'DownloadFile/' . $filename);
       
   795       }
       
   796       
       
   797       $img_tag = '<img src="' . $url . '" ';
       
   798       
       
   799       if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' )
       
   800       {
       
   801         $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" ';
       
   802       }
       
   803       
       
   804       if ( empty($clear) && $scale_type == '|thumb' )
       
   805       {
       
   806         $clear = 'right';
       
   807       }
       
   808       
       
   809       $img_tag .= 'style="border-width: 0px; background-color: white;" ';
       
   810       
       
   811       $img_tag .= '/>';
       
   812       
       
   813       $complete_tag = '';
       
   814       
       
   815       if ( !empty($scale_type) )
       
   816       {
       
   817         $complete_tag .= '<div class="thumbnail" ';
       
   818         $clear_text = '';
       
   819         if ( !empty($clear) )
       
   820         {
       
   821           $side = ( $clear == '|left' ) ? 'left' : 'right';
       
   822           $opposite = ( $clear == '|left' ) ? 'right' : 'left';
       
   823           $clear_text .= "clear: $side; float: $side; margin-$opposite: 20px;";
       
   824           $complete_tag .= 'style="' . $clear_text . '" ';
       
   825         }
       
   826         $complete_tag .= '>';
       
   827         
       
   828         $complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
       
   829         $complete_tag .= $img_tag;
       
   830         $complete_tag .= '</a>';
       
   831         
       
   832         $mag_button = '<a href="' . makeUrlNS('File', $filename) . '" style="display: block; float: right; clear: right; margin: 0 0 10px 10px;"><img alt="[ + ]" src="' . scriptPath . '/images/thumbnail.png" style="border-width: 0px;" /></a>';
       
   833       
       
   834         if ( !empty($caption) )
       
   835         {
       
   836           $cap = substr($caption, 1);
       
   837           $complete_tag .= $mag_button . $cap;
       
   838         }
       
   839         
       
   840         $complete_tag .= '</div>';
       
   841       }
       
   842       else
       
   843       {
       
   844         $complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">';
       
   845         $complete_tag .= $img_tag;
       
   846         $complete_tag .= '</a>';
       
   847       }
       
   848       
       
   849       $complete_tag = "<nowiki>$complete_tag</nowiki>\n\n";
       
   850       
       
   851       $pos = strpos($text, $full_tag) - 3;
       
   852       
       
   853       while(true)
       
   854       {
       
   855         $check1 = substr($text, $pos, 3);
       
   856         $check2 = substr($text, $pos, 1);
       
   857         if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" )
       
   858         {
       
   859           // die('found at pos '.$pos);
       
   860           break;
       
   861         }
       
   862         $pos--;
       
   863       }
       
   864       
       
   865       $text = substr($text, 0, $pos) . $complete_tag . substr($text, $pos + 1);
       
   866       
       
   867       $text = str_replace($full_tag, '', $text);
       
   868       
       
   869       unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height);
       
   870       
       
   871     }
       
   872     
       
   873     return $text;
       
   874   }
       
   875   
   789 }
   876 }
   790  
   877  
   791 ?>
   878 ?>