sText(); } // ---------------------------------------------- class WYLongTextElement extends WYElement { // instance variables var $bHideEMailAddress; function webyep_longText($sFieldName, $bGlobal, $deprecated1 = "", $bHide = false) { global $goApp; $o =& new WYLongTextElement($sFieldName, $bGlobal, $bHide); $s = $o->sDisplay(); if ($goApp->bEditMode) { echo $o->sEditButtonHTML("edit-button-long-text.gif"); if (!$s) $s = $o->sName; } echo $s; } function WYLongTextElement($sN, $bG, $bHide) { global $goApp; parent::WYElement($sN, $bG); $this->sEditorPageName = $goApp->bIsiPhone ? "long-text-iphone.php":"long-text.php"; $this->iEditorWidth = 520; $this->iEditorHeight = 450; $this->sEditButtonCSSClass = "WebYepLongTextEditButton"; $this->bHideEMailAddress = $bHide; $this->setVersion(WY_LONGTEXT_VERSION); if (!isset($this->dContent[WY_DK_CONTENT])) $this->dContent[WY_DK_CONTENT] = ""; } function sFieldNameForFile() { $s = parent::sFieldNameForFile(); $s = "lt-" . $s; return $s; } function sText() { return $this->dContent[WY_DK_CONTENT]; } function setText($s) { $this->dContent[WY_DK_CONTENT] = $s; } function _sFormatEMailLinks($sLine) // also used by guestbook! { return preg_replace("/([-a-zA-Z0-9_.]+)@([-a-zA-Z0-9_.]+[-a-zA-Z0-9_])/", "", $sLine); } function _aSplitTableCells($sLine) { $i = 0; $iLastStart = 0; $iL = strlen($sLine); $aCells = array(); while ($i < $iL) { if ($sLine[$i] == '|' && ($i == 0 || $sLine[$i-1] != '\\')) { $iLen = $i - $iLastStart; if ($iLen > 0) $aCells[] = substr($sLine, $iLastStart, $iLen); else $aCells[] = ""; $iLastStart = $i + 1; } $i++; } $iLen = $i - $iLastStart; if ($iLen > 0) $aCells[] = substr($sLine, $iLastStart, $iLen); return $aCells; } function _sFormatContent($sContent, $bHideEMailAddress) // also used by guestbook as class method - do not use $this->! { global $goApp, $webyep_sCharset, $webyep_bOpenFullURLsInNewWindow; $sHTMLStandard = $goApp->sHTMLStandard(); $sBR = $sHTMLStandard == "HTML" ? "
":"
"; $aOutLines = array(); $sASCIIBullets = chr(149) . chr(183) . "+"; if ($sContent) { $sContent = str_replace("\r\n", "\n", $sContent); $sContent = str_replace("\r", "\n", $sContent); $aInLines = split("\n", $sContent); } else $aInLines = array(); $sOutLine = ""; $bInLI = false; $bInTable = false; $bNL = true; $sListType = ""; $iListLevel = 0; $iNumLines = count($aInLines); $iLine = 0; foreach ($aInLines as $sLine) { $bNL = true; $sOutLine = ""; if (preg_match("/^([*$sASCIIBullets]+)[ \t]+/", $sLine, $aReg) && strpos($sLine, "|") == false) { // bullet list item if (substr($aReg[1], 0, 1) == "+") $sListType = "ol"; else $sListType = "ul"; $iNewListLevel = strlen($aReg[1]); $sLine = preg_replace("/^[*$sASCIIBullets]+[ \t]+/", "", $sLine); if ($iNewListLevel > $iListLevel) { $sOutLine .= "\n" . "<$sListType>\n"; } else if ($iNewListLevel < $iListLevel) { $sOutLine .= "\n"; while ($iNewListLevel != $iListLevel) { $sOutLine .= "\n"; $sOutLine .= "\n"; $iListLevel--; } } else $sOutLine .= "\n"; $iListLevel = $iNewListLevel; $sOutLine .= "
  • "; $bInLI = true; $bNL = false; } else if (trim($sLine) != "" && $iListLevel > 0) { // continued bullet list item $sLine = ltrim($sLine); // strip indention $sOutLine .= "\n$sBR "; $bNL = false; } $sLine = webyep_sHTMLEntities($sLine, false); $sLine = preg_replace("/]*)>/", "\\1", $sLine); $sLine = preg_replace("/]*)>/", "\\1", $sLine); $sLine = preg_replace("/<([^>a-z:# ]*) ([^>]*)>/", "\\2", $sLine); if ($webyep_bOpenFullURLsInNewWindow) { $sLine = preg_replace("|]*)>|", "\\3", $sLine); $sLine = preg_replace("|]*)>|", "\\3", $sLine); } else { $sLine = preg_replace("|]*)>|", "\\3", $sLine); $sLine = preg_replace("|]*)>|", "\\3", $sLine); } $sLine = preg_replace("|]*)>|", "\\2", $sLine); $sLine = preg_replace("{((HTTP)|(http))://([-a-zA-Z0-9_/.~%#?=&;]+[-a-zA-Z0-9_/~%#?=&;])}", "http://@@\\4", $sLine); while (preg_match("|(.*)http://@@([-a-zA-Z0-9_/.~%]+)(.*)|", $sLine, $aReg)) { $sLine = $aReg[1] . "http://" . str_replace("/", "/­", $aReg[2]) . $aReg[3]; } $sLine = preg_replace("{((HTTPS)|(https))://([-a-zA-Z0-9_/.~%#?=&;]+[-a-zA-Z0-9_/~%#?=&;])}", "https://@@\\4", $sLine); while (preg_match("|(.*)https://@@([-a-zA-Z0-9_/.~%]+)(.*)|", $sLine, $aReg)) { $sLine = $aReg[1] . "https://" . str_replace("/", "/­", $aReg[2]) . $aReg[3]; } if ($bHideEMailAddress) { if (preg_match("|[-a-zA-Z0-9_.]+@[-a-zA-Z0-9_.]+|", $sLine)) { $sLine = WYLongTextElement::_sFormatEMailLinks($sLine); } } else { $sLine = preg_replace('|([-a-zA-Z0-9_.]+@[-a-zA-Z0-9_.]+[-a-zA-Z0-9_])|', "\\1", $sLine); } if (preg_match('|^-+$|', $sLine)) { $sLine = "
    \n"; $bNL = false; } $sOutLine .= $sLine; if ($iListLevel > 0 && (trim($sLine) == "" || !preg_match("|[^ \t*$sASCIIBullets]+|", $sLine))) { // end of bullet list while ($iListLevel > 0) { $sOutLine .= "
  • \n"; $sOutLine .= "\n"; $iListLevel--; $bInLI = false; } $bNL = false; $bInLI = false; } if ($iListLevel == 0 && preg_match('/([^\\\\]\|)|(^\|)/', $sOutLine)) { // $aCells = split('([^\\\\]\|)|(^\|)', $sOutLine); $aCells = WYLongTextElement::_aSplitTableCells($sOutLine); $sOutLine = "\n"; foreach ($aCells as $sCell) { $sCell = trim($sCell); if ($sCell == "") $sCell = " "; $sOutLine .= " $sCell\n"; } $sOutLine .= "\n"; if (!$bInTable) { $sOutLine = "\n" . $sOutLine; $bInTable = true; } $bNL = false; } else if ($bInTable && !preg_match('/([^\\\\]\|)|(^\|)/', $sOutLine)) { $sOutLine = "
    $sOutLine\n"; $bInTable = false; $bNL = false; } $sOutLine = preg_replace('/\\\\\|/', '|', $sOutLine); $iLine++; if ($iLine >= $iNumLines) $bNL = false; $aOutLines[] = $sOutLine . ($bNL ? "$sBR\n":""); } // close everything left open: //if ($bInLI) $aOutLines[] = "\n"; if ($bInLI) $aOutLines[] = "\n"; while ($iListLevel) { $aOutLines[] .= "\n"; $iListLevel--; } if ($bInTable) $aOutLines[] = "\n"; $sContent = join("", $aOutLines); $sContent = str_replace("$sBR\n.$sBR", $sHTMLStandard == "HTML" ? "
    ":"
    ", $sContent); $sContent = str_replace("$sBR\n", "\n
    ", $sContent); $sContent = str_replace("HtTpS", "https", $sContent); $sContent = str_replace("HtTp", "http", $sContent); return $sContent; } function sDisplay() { $sContent = ""; $aInLines = array(); $aReg = array(); $sLine = ""; $iLastLineWasBL = 0; $sHTMLBullet = "•"; $sContent = $this->sText(); $sContent = $this->_sFormatContent($sContent, $this->bHideEMailAddress); return $sContent; } } ?>