Пример #1
0
 function _sEMailLink($sE)
 {
     if ($this->bHideEMailAddresses) {
         return WYLongTextElement::_sFormatEMailLinks($sE);
     } else {
         return "<a href='mailto:{$sE}'>" . webyep_sHTMLEntities($sE) . "</a>";
     }
 }
Пример #2
0
 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" ? "<br>" : "<br />";
     $aOutLines = array();
     $sASCIIBullets = chr(149) . chr(183) . "+";
     if ($sContent) {
         $sContent = str_replace("\r\n", "\n", $sContent);
         $sContent = str_replace("\r", "\n", $sContent);
         $aInLines = explode("\n", $sContent);
     } else {
         $aInLines = array();
     }
     $sOutLine = "";
     $bInLI = false;
     $bInTable = false;
     $bNL = true;
     $sListType = "";
     $iListLevel = 0;
     $iNumLines = count($aInLines);
     $iLine = 0;
     $sTarget = "";
     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 .= "</li>\n";
                     while ($iNewListLevel != $iListLevel) {
                         $sOutLine .= "</{$sListType}>\n";
                         $sOutLine .= "</li>\n";
                         $iListLevel--;
                     }
                 } else {
                     $sOutLine .= "</li>\n";
                 }
             }
             $iListLevel = $iNewListLevel;
             $sOutLine .= "<li>";
             $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("/<FETT ([^>]*)>/", "<strong>\\1</strong>", $sLine);
         $sLine = preg_replace("/<BOLD ([^>]*)>/", "<strong>\\1</strong>", $sLine);
         $sLine = preg_replace("/<([^>a-z:# ]*) ([^>]*)>/", "<span class='\\1'>\\2</span>", $sLine);
         if ($webyep_bOpenFullURLsInNewWindow) {
             $sTarget = " target='_blank'";
         } else {
             $sTarget = "";
         }
         $sLine = preg_replace("|<LINK: *http(s?)://([^ ]*) ([^>]*)>|", "<a href='HtTp\\1://\\2'{$sTarget}>\\3</a>", $sLine);
         $sLine = preg_replace("|<LINK: *HTTP(S?)://([^ ]*) ([^>]*)>|", "<a href='HtTp\\1://\\2'{$sTarget}>\\3</a>", $sLine);
         $sLine = preg_replace("|<LINK: *([^ ]*) ([^>]*)>|", "<a href='\\1'>\\2</a>", $sLine);
         $sLine = preg_replace("{((HTTP)|(http))://([-a-zA-Z0-9_/.~%#?=&;]+[-a-zA-Z0-9_/~%#?=&;])}", "<a href='HtTp://\\4'{$sTarget}>http://@@\\4</a>", $sLine);
         while (preg_match("|(.*)http://@@([-a-zA-Z0-9_/.~%]+)(.*)|", $sLine, $aReg)) {
             $sLine = $aReg[1] . "http://" . str_replace("/", "/&shy;", $aReg[2]) . $aReg[3];
         }
         $sLine = preg_replace("{((HTTPS)|(https))://([-a-zA-Z0-9_/.~%#?=&;]+[-a-zA-Z0-9_/~%#?=&;])}", "<a href='HtTpS://\\4'{$sTarget}>https://@@\\4</a>", $sLine);
         while (preg_match("|(.*)https://@@([-a-zA-Z0-9_/.~%]+)(.*)|", $sLine, $aReg)) {
             $sLine = $aReg[1] . "https://" . str_replace("/", "/&shy;", $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_])|', "<a href='mailto:\\1'>\\1</a>", $sLine);
         }
         if (preg_match('|^-+$|', $sLine)) {
             $sLine = "<hr style='height:1px; border-right-style:none; border-left-style:none; border-bottom-style:none;'" . ($sHTMLStandard != "HTML" ? " /" : "") . ">\n";
             $bNL = false;
         }
         $sOutLine .= $sLine;
         if ($iListLevel > 0 && (trim($sLine) == "" || !preg_match("|[^ \t*{$sASCIIBullets}]+|", $sLine))) {
             // end of bullet list
             while ($iListLevel > 0) {
                 $sOutLine .= "</li>\n";
                 $sOutLine .= "</{$sListType}>\n";
                 $iListLevel--;
                 $bInLI = false;
             }
             $bNL = false;
             $bInLI = false;
         }
         if ($iListLevel == 0 && preg_match('/([^\\\\]\\|)|(^\\|)/', $sOutLine)) {
             $aCells = WYLongTextElement::_aSplitTableCells($sOutLine);
             $sOutLine = "<tr>\n";
             foreach ($aCells as $sCell) {
                 $sCell = trim($sCell);
                 if ($sCell == "") {
                     $sCell = "&nbsp;";
                 }
                 $sOutLine .= "   <td>{$sCell}</td>\n";
             }
             $sOutLine .= "</tr>\n";
             if (!$bInTable) {
                 $sOutLine = "<table border='0' cellpadding='0' cellspacing='0'>\n" . $sOutLine;
                 $bInTable = true;
             }
             $bNL = false;
         } else {
             if ($bInTable && !preg_match('/([^\\\\]\\|)|(^\\|)/', $sOutLine)) {
                 $sOutLine = "</table>{$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[] = "</li>\n";
     if ($bInLI) {
         $aOutLines[] = "\n";
     }
     while ($iListLevel) {
         $aOutLines[] .= "</{$sListType}>\n";
         $iListLevel--;
     }
     if ($bInTable) {
         $aOutLines[] = "</table>\n";
     }
     $sContent = join("", $aOutLines);
     $sContent = str_replace("{$sBR}\n.{$sBR}", $sHTMLStandard == "HTML" ? "<br clear='all'>" : "<br clear='all' />", $sContent);
     $sContent = str_replace("{$sBR}\n<table>", "\n<table>", $sContent);
     $sContent = str_replace("HtTpS", "https", $sContent);
     $sContent = str_replace("HtTp", "http", $sContent);
     return $sContent;
 }