includes/wikiengine/render_xhtml.php
changeset 1227 bdac73ed481e
parent 1217 feeb49aa6270
child 1329 61d87ee12e80
equal deleted inserted replaced
1226:de56132c008d 1227:bdac73ed481e
    11  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    11  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    12  */
    12  */
    13 
    13 
    14 class Carpenter_Render_Xhtml
    14 class Carpenter_Render_Xhtml
    15 {
    15 {
    16   public $rules = array(
    16 	public $rules = array(
    17     'lang'   => '',
    17 		'lang'   => '',
    18     'templates' => '',
    18 		'templates' => '',
    19     'bold'   => '<strong>\\1</strong>',
    19 		'bold'   => '<strong>\\1</strong>',
    20     'italic' => '<em>\\1</em>',
    20 		'italic' => '<em>\\1</em>',
    21     'underline' => '<span style="text-decoration: underline;">\\1</span>',
    21 		'underline' => '<span style="text-decoration: underline;">\\1</span>',
    22     'externalwithtext' => '<a href="\\1" onclick="window.open(this.href); return false;">\\2</a>',
    22 		'externalwithtext' => '<a href="\\1" onclick="window.open(this.href); return false;">\\2</a>',
    23     'externalnotext' => '<a href="\\1" onclick="window.open(this.href); return false;">\\1</a>',
    23 		'externalnotext' => '<a href="\\1" onclick="window.open(this.href); return false;">\\1</a>',
    24     'hr' => '<hr />'
    24 		'hr' => '<hr />'
    25   );
    25 	);
    26   
    26 	
    27   public function heading($text, $pieces)
    27 	public function heading($text, $pieces)
    28   {
    28 	{
    29     foreach ( $pieces as $i => $piece )
    29 		foreach ( $pieces as $i => $piece )
    30     {
    30 		{
    31       $tocid = sanitize_page_id(trim($piece['text']));
    31 			$tocid = sanitize_page_id(trim($piece['text']));
    32       // (bad) workaround for links in headings
    32 			// (bad) workaround for links in headings
    33       $tocid = str_replace(array('[', ']'), '', $tocid);
    33 			$tocid = str_replace(array('[', ']'), '', $tocid);
    34       $tag = '<h' . $piece['level'] . ' id="head:' . $tocid . '">';
    34 			$tag = '<h' . $piece['level'] . ' id="head:' . $tocid . '">';
    35       $tag .= trim($piece['text']);
    35 			$tag .= trim($piece['text']);
    36       $tag .= '</h' . $piece['level'] . '>';
    36 			$tag .= '</h' . $piece['level'] . '>';
    37       
    37 			
    38       $text = str_replace(Carpenter::generate_token($i), $tag, $text);
    38 			$text = str_replace(Carpenter::generate_token($i), $tag, $text);
    39     }
    39 		}
    40     
    40 		
    41     return $text;
    41 		return $text;
    42   }
    42 	}
    43   
    43 	
    44   public function multilist($text, $pieces)
    44 	public function multilist($text, $pieces)
    45   {
    45 	{
    46     foreach ( $pieces as $i => $piece )
    46 		foreach ( $pieces as $i => $piece )
    47     {
    47 		{
    48       switch($piece['type'])
    48 			switch($piece['type'])
    49       {
    49 			{
    50         case 'unordered':
    50 				case 'unordered':
    51         default:
    51 				default:
    52           $btag = 'ul';
    52 					$btag = 'ul';
    53           $itag = 'li';
    53 					$itag = 'li';
    54           break;
    54 					break;
    55         case 'ordered':
    55 				case 'ordered':
    56           $btag = 'ol';
    56 					$btag = 'ol';
    57           $itag = 'li';
    57 					$itag = 'li';
    58           break;
    58 					break;
    59         case 'indent':
    59 				case 'indent':
    60           $btag = 'dl';
    60 					$btag = 'dl';
    61           $itag = 'dd';
    61 					$itag = 'dd';
    62           break;
    62 					break;
    63       }
    63 			}
    64       $list = "<_paragraph_bypass><$btag>\n";
    64 			$list = "<_paragraph_bypass><$btag>\n";
    65       $spacing = '';
    65 			$spacing = '';
    66       $depth = 1;
    66 			$depth = 1;
    67       foreach ( $piece['items'] as $j => $item )
    67 			foreach ( $piece['items'] as $j => $item )
    68       {
    68 			{
    69         // most of this just goes into pretty formatting.
    69 				// most of this just goes into pretty formatting.
    70         // everything else goes into meeting the PITA requirement that if you're going
    70 				// everything else goes into meeting the PITA requirement that if you're going
    71         // another level deep, HTML requires the next level to be INSIDE of the <dd>/<li> tag.
    71 				// another level deep, HTML requires the next level to be INSIDE of the <dd>/<li> tag.
    72         $itemdepth = $item['depth'];
    72 				$itemdepth = $item['depth'];
    73         if ( $itemdepth > $depth )
    73 				if ( $itemdepth > $depth )
    74         {
    74 				{
    75           while ( $depth < $itemdepth )
    75 					while ( $depth < $itemdepth )
    76           {
    76 					{
    77             $spacing .= '    ';
    77 						$spacing .= '    ';
    78             $list .= "{$spacing}<$btag>\n";
    78 						$list .= "{$spacing}<$btag>\n";
    79             $depth++;
    79 						$depth++;
    80           }
    80 					}
    81         }
    81 				}
    82         else if ( $itemdepth < $depth )
    82 				else if ( $itemdepth < $depth )
    83         {
    83 				{
    84           while ( $depth > $itemdepth )
    84 					while ( $depth > $itemdepth )
    85           {
    85 					{
    86             $list .= "{$spacing}</$btag>\n";
    86 						$list .= "{$spacing}</$btag>\n";
    87             $spacing = substr($spacing, 4);
    87 						$spacing = substr($spacing, 4);
    88             $list .= "{$spacing}</$itag>\n";
    88 						$list .= "{$spacing}</$itag>\n";
    89             $spacing = substr($spacing, 4);
    89 						$spacing = substr($spacing, 4);
    90             $depth--;
    90 						$depth--;
    91           }
    91 					}
    92         }
    92 				}
    93         $list .= "{$spacing}    <$itag>" . nl2br($item['text']);
    93 				$list .= "{$spacing}    <$itag>" . nl2br($item['text']);
    94         if ( ( isset($piece['items'][ ++$j ]) && $piece['items'][ $j ]['depth'] <= $itemdepth ) || !isset($piece['items'][ $j ]) ) 
    94 				if ( ( isset($piece['items'][ ++$j ]) && $piece['items'][ $j ]['depth'] <= $itemdepth ) || !isset($piece['items'][ $j ]) ) 
    95         {
    95 				{
    96           $list .= "</$itag>\n";
    96 					$list .= "</$itag>\n";
    97         }
    97 				}
    98         else
    98 				else
    99         {
    99 				{
   100           $list .= "\n";
   100 					$list .= "\n";
   101           $spacing .= "    ";
   101 					$spacing .= "    ";
   102         }
   102 				}
   103       }
   103 			}
   104       while ( $depth > 1 )
   104 			while ( $depth > 1 )
   105       {
   105 			{
   106         $list .= "{$spacing}</$btag>\n";
   106 				$list .= "{$spacing}</$btag>\n";
   107         $spacing = substr($spacing, 4);
   107 				$spacing = substr($spacing, 4);
   108         $list .= "{$spacing}</$itag>\n";
   108 				$list .= "{$spacing}</$itag>\n";
   109         $spacing = substr($spacing, 4);
   109 				$spacing = substr($spacing, 4);
   110         $depth--;
   110 				$depth--;
   111       }
   111 			}
   112       $list .= "</$btag></_paragraph_bypass>\n";
   112 			$list .= "</$btag></_paragraph_bypass>\n";
   113       $text = str_replace(Carpenter::generate_token($i), $list, $text);
   113 			$text = str_replace(Carpenter::generate_token($i), $list, $text);
   114     }
   114 		}
   115     return $text;
   115 		return $text;
   116   }
   116 	}
   117   
   117 	
   118   public function blockquote($text)
   118 	public function blockquote($text)
   119   {
   119 	{
   120     return $text;
   120 		return $text;
   121   }
   121 	}
   122   
   122 	
   123   public function blockquotepost($text, $rand_id)
   123 	public function blockquotepost($text, $rand_id)
   124   {
   124 	{
   125     $text = strtr($text, array(
   125 		$text = strtr($text, array(
   126         "<p>{blockquote:$rand_id}<br />"  => '<blockquote>',
   126 				"<p>{blockquote:$rand_id}<br />"  => '<blockquote>',
   127         "<br />\n{/blockquote:$rand_id}</p>" => '</blockquote>',
   127 				"<br />\n{/blockquote:$rand_id}</p>" => '</blockquote>',
   128         "{blockquote:$rand_id}"  => '<blockquote>',
   128 				"{blockquote:$rand_id}"  => '<blockquote>',
   129         "{/blockquote:$rand_id}" => '</blockquote>'
   129 				"{/blockquote:$rand_id}" => '</blockquote>'
   130       ));
   130 			));
   131     $text = strtr($text, array(
   131 		$text = strtr($text, array(
   132         "<blockquote><br />" => '<blockquote>',
   132 				"<blockquote><br />" => '<blockquote>',
   133         "</blockquote><br />" => '</blockquote>'
   133 				"</blockquote><br />" => '</blockquote>'
   134       ));
   134 			));
   135     return $text;
   135 		return $text;
   136   }
   136 	}
   137   
   137 	
   138   public function paragraph($text, $pieces)
   138 	public function paragraph($text, $pieces)
   139   {
   139 	{
   140     foreach ( $pieces as $i => $piece )
   140 		foreach ( $pieces as $i => $piece )
   141     {
   141 		{
   142       $text = str_replace(Carpenter::generate_token($i), '<p>' . nl2br($piece) . '</p>', $text);
   142 			$text = str_replace(Carpenter::generate_token($i), '<p>' . nl2br($piece) . '</p>', $text);
   143     }
   143 		}
   144     
   144 		
   145     return $text;
   145 		return $text;
   146   }
   146 	}
   147   
   147 	
   148   public function mailtonotext($pieces)
   148 	public function mailtonotext($pieces)
   149   {
   149 	{
   150     $pieces[2] = $pieces[1];
   150 		$pieces[2] = $pieces[1];
   151     return $this->mailtowithtext($pieces);
   151 		return $this->mailtowithtext($pieces);
   152   }
   152 	}
   153   
   153 	
   154   public function mailtowithtext($pieces)
   154 	public function mailtowithtext($pieces)
   155   {
   155 	{
   156     global $email;
   156 		global $email;
   157     return $email->encryptEmail($pieces[1], '', '', $pieces[2]);
   157 		return $email->encryptEmail($pieces[1], '', '', $pieces[2]);
   158   }
   158 	}
   159   
   159 	
   160   public function code($match)
   160 	public function code($match)
   161   {
   161 	{
   162     return '<pre class="wikitext-code"><final>' . htmlspecialchars($match[1]) . '</final></pre>';
   162 		return '<pre class="wikitext-code"><final>' . htmlspecialchars($match[1]) . '</final></pre>';
   163   }
   163 	}
   164 }
   164 }
   165 
   165 
   166 // Alias internal link parsing to RenderMan's method
   166 // Alias internal link parsing to RenderMan's method
   167 function parser_mediawiki_xhtml_internallink($text)
   167 function parser_mediawiki_xhtml_internallink($text)
   168 {
   168 {
   169   return RenderMan::parse_internal_links($text);
   169 	return RenderMan::parse_internal_links($text);
   170 }
   170 }
   171 
   171