Show wysiwyg_texy.php syntax highlighted
<?php
class WYSIWYG {
const NAME = "texy";
const DEFAULT_TOOLBAR = "Default";
const BASIC_TOOLBAR = "Basic";
private static $instance = false;
/**
* Creates an instance of WYSIWYG textarea editor.
*
* @param string $instance This is the only required parameter.Each window(textarea) must have different instance name.
* @param string $width The width of editor's window (default is 100%).
* @param string $height The height of editor's window (default is 200).
* @param string $value Initial text,which will be displayed in editor.
* @param string $toolbar Toolbar style (only for some types of editors). Default style is "Default".
* @return string This method returns a HTML code which will include wysiwyg editor in current place. (You have to print this code in you document to load this editor)
*/
public static function Show($instance, $value = "", $toolbar = self :: BASIC_TOOLBAR) {
global $XCS, $ECP, $Config;
$toolbar = self :: BASIC_TOOLBAR;
$retval = '';
$value = stripslashes($value);
if ($toolbar == self :: DEFAULT_TOOLBAR) {
// ADMINISTRATION
$retval .= '<textarea name="' . $instance . '" id="' . $instance . '">';
$retval .= $value;
$retval .= '</textarea>';
$retval .= '<br /><a href="http://www.texy.info/" target="_blank"><img src="' . $Config->getMaster() . '/ext/texy/support-us/texy-88x31-white.gif" alt="Text to HTML converter and formatter" /></a>';
$retval .= '<input type="button" value="' . $ECP->localeString("other", "add_picture") . '" onClick="openWindow(\'openWindow.php?module=gallery&file=admin&elementid=' . $instance . '&op=insert_image\',\'picture\',\'400\',\'600\');" target="picture" />';
$retval .= '<input type="button" value="' . $ECP->localeString("other", "add_link") . '" onClick="openWindow(\'openWindow.php?module=downloads&file=admin&elementid=' . $instance . '&op=insert_link\',\'link\',\'400\',\'600\');" target="link" />';
$retval .= '<br />';
if (!empty ($value)) {
$texy = new xcsTexy();
$html = $texy->process($value);
$retval .= '<h3>' . $ECP->localeString("other", "preview") . '</h3>';
$retval .= '<div class="xcs_wysiwyg_preview">';
$retval .= $html;
$retval .= '</div>';
$retval .= '<br />';
}
} else {
// PUBLIC
//$retval .= '<div style="width:100%;text-align:right"><a href="http://www.texy.info/" target="_blank"><img src="' . $Config->getMaster() . '/ext/texy/support-us/texy-88x31-white.gif" alt="Text to HTML converter and formatter" /></a></div>';
$retval .= '<div style="text-align:center"><textarea name="' . $instance . '" id="' . $instance . '" style="text-align:left;width:465px;overflow:visible" onkeypress="if (event.which==13) {self=this; setTimeout(\'net.elitemedia.TextArea.RecalculateHeight(self)\',300); }">';
$retval .= $value;
$retval .= '</textarea></div>';
$retval .= '<br />';
}
return $retval;
}
public static function ParseEnd($text) {
$text = str_replace("<br />", '<br style="clear: both;" />', $text);
$text = str_replace("**", '', $text);
$text = str_replace("<table>", '<table class="document_table">', $text);
$text = str_replace("<td colspan=", '<td class="document_table" colspan=', $text);
$text = str_replace("<td>", '<td class="document_table">', $text);
return $text . '<hr class="cleaner" />';
}
public static function insertImagesFromTexy($text, $imagesPath) {
global $XCS;
$texy = new xcsTexy();
$array = explode("[*gallery ", $text);
$output = "";
foreach ($array as $block) {
$code = explode(" *]", $block);
if (sizeof($code) == 2) {
$image = explode("@", $code[0]);
if (sizeof($image) == 5 && $image[sizeof($image) - 1] == "upload") {
// UPLOAD
$name = $image[0];
$pos = $image[1];
$dir = explode("/", $name);
$original_file = $dir[sizeof($dir) - 1];
$output .= $texy->xcsParseImage($original_file, $imagesPath . $original_file, 0, "original", $pos, $image[2], $image[3]);
}
}
$output .= $code[sizeof($code) - 1];
}
return $output;
}
public static function ParseStart($text) {
global $XCS;
$texy = new xcsTexy();
$text = str_replace("<p>", "\r\n\r\n", $text);
$text = str_replace("</p>", "", $text);
//$text = str_replace(" *", " *", $text);
$text = str_replace(" **", " **", $text);
$text = str_replace(" ***", " ***", $text);
$text = str_replace("<br>", "<br />", $text);
// image from gallery
$array = explode("[*gallery ", $text);
$output = "";
foreach ($array as $block) {
$code = explode(" *]", $block);
if (sizeof($code) == 2) {
$image = explode("@", $code[0]);
// DISPLAY
$output .= $texy->xcsParseImage($image[0], $image[2], $image[1], $image[3], $image[4]);
}
$output .= $code[sizeof($code) - 1];
}
// link from downloads
if (sizeof($array)) {
$text = $output;
}
$array = explode("[*file ", $text);
if (sizeof($array)) {
$output = "";
}
foreach ($array as $block) {
$code = explode(" *]", $block);
if (sizeof($code) == 2) {
$link = explode("@", $code[0]);
$output .= "<a href=\"get.php?id=" . $link[1] . "\">" . $link[0] . "</a>";
}
$output .= $code[sizeof($code) - 1];
}
return $output;
}
public static function Process($text) {
if (self :: $instance === false) {
self :: $instance = new xcsTexy();
}
return self :: $instance->process($text);
}
}
?>
See more files for this project here