gzipCompression = false; } if(!empty($_GET['debug']) && getperms('0')) { $debug = true; // For future use. if(defined("TINYMCE_PARSER_DEBUG_TEXT")) { $text = TINYMCE_PARSER_DEBUG_TEXT; echo "

Original

"; print_a($text); echo "

toHtml

"; } else { $text = <<toHtml($_POST['content']); } if($_POST['mode'] == 'tobbcode') { $html = $this->toBBcode($_POST['content']); } if($debug == true) { print_a($html); echo "
"; echo "

Rendered

"; echo $html; } elseif($this->gzipCompression == true) { header('Content-Encoding: gzip'); $gzipoutput = gzencode($html,6); header('Content-Length: '.strlen($gzipoutput)); echo $gzipoutput; } else { echo $html; } } function toHtml($content) { global $pref, $tp; //XXX faster? // XXX @Cam possible fix - convert to BB first, see news admin AJAX request/response values for reference why $content = stripslashes($content); // $content = e107::getBB()->htmltoBBcode($content); //XXX This breaks inserted images from media-manager. :/ e107::getBB()->setClass($_SESSION['media_category']); if(check_class($pref['post_html'])) // raw HTML within [html] tags. { // $content = $tp->replaceConstants($content,'abs'); if(strstr($content,"[html]") === false) // BC - convert old BB code text to html. { e107::getBB()->clearClass(); //$content = str_replace('\r\n',"
",$content); //$content = nl2br($content, true); $content = $tp->toHtml($content, true, 'WYSIWYG'); } $content = str_replace("{e_BASE}",e_HTTP,$content); // We want {e_BASE} in the final data going to the DB, but not the editor. $srch = array("","","[html]","[/html]"); $content = str_replace($srch,"",$content); $content = e107::getBB()->parseBBCodes($content); // parse the tag so we see the HTML equivalent while editing! if(!empty($content) && E107_DEBUG_LEVEL > 0) { // $content = "-- DEBUG MODE ACTIVE -- \n".$content; // echo htmlentities($content)."\n"; // echo "
".$content."
"; $text = $content; return $text; // exit; } else { $text = $content; } } else // bbcode Mode. { // XXX @Cam this breaks new lines, currently we use \n instead [br] //echo $tp->toHtml(str_replace("\n","",$content), true); $content = str_replace("{e_BASE}",e_HTTP, $content); // We want {e_BASE} in the final data going to the DB, but not the editor. $content = $tp->toHtml($content, true, 'WYSIWYG'); $content = str_replace(e_MEDIA_IMAGE,"{e_MEDIA_IMAGE}",$content); $text = ""; if(!empty($content) && E107_DEBUG_LEVEL > 0) { $text .= ""; //print_r(htmlentities($content))."\n"; //exit; } $text .= $content; } e107::getBB()->clearClass(); return $text; } function toBBcode($content) { // echo $_POST['content']; global $pref, $tp; $content = stripslashes($content); if(check_class($pref['post_html'])) // Plain HTML mode. { $content = trim($content); // $srch = array('src="'.e_HTTP.'thumb.php?','src="/{e_MEDIA_IMAGE}'); // $repl = array('src="{e_BASE}thumb.php?','src="{e_BASE}thumb.php?src=e_MEDIA_IMAGE/'); // $content = str_replace($srch, $repl, $content); // resize the thumbnail to match wysiwyg width/height. // $psrch = '/]*src="{e_BASE}thumb.php\?src=([\S]*)w=([\d]*)&h=([\d]*)"(.*)width="([\d]*)" height="([\d]*)"/i'; // $prepl = 'updateImg($content); $content = $tp->parseBBTags($content,true); // replace html with bbcode equivalent if(strip_tags($content, '') == ' ') // Avoid this: [html]

 

[/html] { exit; } $text = $content ? "[html]".$content."[/html]" : ""; // Add the tags before saving to DB. } else // bbcode Mode. //XXX Disabled at the moment in tinymce/e_meta.php - post_html is required to activate. { // [img width=400]/e107_2.0/thumb.php?src={e_MEDIA_IMAGE}2012-12/e107org_white_stripe.png&w=400&h=0[/img] // $content = str_replace("{e_BASE}","", $content); // We want {e_BASE} in the final data going to the DB, but not the editor. $text = e107::getBB()->htmltoBBcode($content); // not reliable enough yet. } $text = str_replace('[html]

[/html]','',$text); // cleanup. return $text; } /** * Split a thumb.php url into an array which can be parsed back into the thumbUrl method. . * @param $src * @return array */ function thumbUrlDecode($src) { list($url,$qry) = explode("?",$src); $ret = array(); if(strstr($url,"thumb.php") && !empty($qry)) // Regular { parse_str($qry,$val); $ret = $val; } elseif(preg_match('/media\/img\/(a)?([\d]*)x(a)?([\d]*)\/(.*)/',$url,$match)) // SEF { $wKey = $match[1].'w'; $hKey = $match[3].'h'; $ret = array( 'src'=> 'e_MEDIA_IMAGE/'.$match[5], $wKey => $match[2], $hKey => $match[4] ); } elseif(preg_match('/theme\/img\/(a)?([\d]*)x(a)?([\d]*)\/(.*)/', $url, $match)) // Theme-image SEF Urls { $wKey = $match[1].'w'; $hKey = $match[3].'h'; $ret = array( 'src'=> 'e_THEME/'.$match[5], $wKey => $match[2], $hKey => $match[4] ); } elseif(defined('TINYMCE_DEBUG')) { print_a("thumbUrlDecode: No Matches"); } return $ret; } /** * Rebuld tags with modified thumbnail size. * @param $text * @return mixed */ function updateImg($text) { $arr = e107::getParser()->getTags($text,'img'); $srch = array("?","&"); $repl = array("\?","&"); if(defined('TINYMCE_DEBUG')) { print_a($arr); } foreach($arr['img'] as $img) { if(substr($img['src'],0,4) == 'http' || strpos($img['src'], e_IMAGE_ABS.'emotes/')!==false) // dont resize external images or emoticons. { continue; } $regexp = '#(]*src="'.str_replace($srch, $repl, $img['src']).'"[^>]*>)#'; $width = vartrue($img['width']) ? ' width="'.$img['width'].'"' : ''; $height = vartrue($img['height']) ? ' height="'.$img['height'].'"' : ''; $style = vartrue($img['style']) ? ' style="'.$img['style'].'"' : ''; $class = vartrue($img['class']) ? ' class="'.$img['class'].'"' : ''; $alt = vartrue($img['alt']) ? ' alt="'.$img['alt'].'"' : ''; $title = vartrue($img['title']) ? ' title="'.$img['title'].'"' : ''; $srcset = vartrue($img['srcset']) ? 'srcset="'.$img['srcset'].'"' : ''; $qr = $this->thumbUrlDecode($img['src']); if(substr($qr['src'],0,4)!=='http' && empty($qr['w']) && empty($qr['aw'])) { $qr['w'] = $img['width']; $qr['h'] = $img['height']; } $qr['ebase'] = true; $src = e107::getParser()->thumbUrl($qr['src'],$qr); $replacement = ''; $text = preg_replace($regexp, $replacement, $text); } return $text; } } $mce = new e107TinyMceParser(); ?>