1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148:
<?php
abstract class ContentFormattingUnparser extends AbstractParser
{
public function __construct()
{
parent::__construct();
}
protected function unparse_html($action)
{
if ($action == self::PICK_UP)
{
$mask = '`<!-- START HTML -->' . "\n" . '(.+)' . "\n" . '<!-- END HTML -->`suU';
$content_split = preg_split($mask, str_replace(' ', '&nbsp;', $this->content), -1, PREG_SPLIT_DELIM_CAPTURE);
$content_length = count($content_split);
$id_tag = 0;
if ($content_length > 1)
{
$this->content = '';
for ($i = 0; $i < $content_length; $i++)
{
if ($i % 2 == 0)
{
$this->content .= $content_split[$i];
if ($i < $content_length - 1)
{
$this->content .= '[HTML_UNPARSE_TAG_' . $id_tag++ . ']';
}
}
else
{
$this->array_tags['html_unparse'][] = $content_split[$i];
}
}
$this->array_tags['html_unparse'] = array_map(function($var) {return TextHelper::htmlspecialchars($var, ENT_NOQUOTES);}, $this->array_tags['html_unparse']);
}
return true;
}
else
{
if (!array_key_exists('html_unparse', $this->array_tags))
{
return false;
}
$content_length = count($this->array_tags['html_unparse']);
if ($content_length > 0)
{
for ($i = 0; $i < $content_length; $i++)
{
$this->content = str_replace('[HTML_UNPARSE_TAG_' . $i . ']', '[html]' . $this->array_tags['html_unparse'][$i] . '[/html]', $this->content);
}
$this->array_tags['html_unparse'] = array();
}
return true;
}
}
protected function unparse_code($action)
{
if ($action == self::PICK_UP)
{
$mask = '`\[\[CODE(=[^,\s]+(?:,(?:0|1)(?:,1)?)?)?\]\]' . '(.+)' . '\[\[/CODE\]\]`suU';
$content_split = preg_split($mask, str_replace(' ', '&nbsp;', $this->content), -1, PREG_SPLIT_DELIM_CAPTURE);
$content_length = count($content_split);
$id_tag = 0;
if ($content_length > 1)
{
$this->content = '';
for ($i = 0; $i < $content_length; $i++)
{
if ($i % 3 == 0)
{
$this->content .= $content_split[$i];
if ($i < $content_length - 1)
{
$this->content .= '[CODE_UNPARSE_TAG_' . $id_tag++ . ']';
}
}
elseif ($i % 3 == 2)
{
$this->array_tags['code_unparse'][] = '[code' . $content_split[$i - 1] . ']' . $content_split[$i] . '[/code]';
}
}
}
return true;
}
else
{
if (!array_key_exists('code_unparse', $this->array_tags))
{
return false;
}
$content_length = count($this->array_tags['code_unparse']);
if ($content_length > 0)
{
for ($i = 0; $i < $content_length; $i++)
$this->content = str_replace('[CODE_UNPARSE_TAG_' . $i . ']', $this->array_tags['code_unparse'][$i], $this->content);
$this->array_tags['code_unparse'] = array();
}
return true;
}
}
}
?>