/** MakeLink
  * @param string Link
  * @return string
  */
 function MakeLink($Link)
 {
     $antibot = EMAIL_ANTISPAM_TEXT;
     $encodedLink = encodeUri($Link);
     // identify mail-adresses
     if (preg_match("/^[a-z0-9-_\\.]+@[a-z0-9\\[\\]-_\\.]+\\.[a-z]{2,4}\$/i", $Link)) {
         // only a replacement of "dots" and the "at"
         if ($antibot == EMAIL_ANTISPAM_TEXT) {
             $Link = str_replace('.', ' [dot] ', $Link);
             $Link = str_replace('@', ' [at] ', $Link);
         } else {
             if ($antibot == EMAIL_ANTISPAM_ASCII) {
                 $tmpMail = '';
                 $length = strlen($Link);
                 for ($chr = 0; $chr < $length; $chr++) {
                     $tmpMail .= '&#' . ord($Link[$chr]) . ';';
                 }
                 $Link = $tmpMail;
             }
         }
         return "mailto:{$Link}\" class=\"link_email";
     } else {
         if (substr($encodedLink, 0, 6) == 'http:/' || substr($encodedLink, 0, 5) == 'ftp:/' || substr($encodedLink, 0, 7) == 'https:/') {
             return "{$encodedLink}\" class=\"link_extern";
         }
     }
     return TextActions::GetInternUrl($encodedLink);
 }
 function _makeLinks($Text)
 {
     preg_match_all("#\\[\\[(.+?)\\]\\]#s", $Text, $links);
     $link_list = array();
     $linkNr = 1;
     // replace all links with a short uniqe id to replace them later back
     foreach ($links[1] as $link) {
         $link_list[$linkNr] = $link;
         $Text = str_replace("[[{$link}]]", "[[%{$linkNr}%]]", $Text);
         $linkNr++;
     }
     foreach ($link_list as $linkNr => $link) {
         if (preg_match("#^(.+?)\\|(.+?)\$#i", $link, $link2)) {
             $Text = str_replace("[[%{$linkNr}%]]", "<a href=\"" . TextActions::MakeLink($link2[1]) . "\">" . $link2[2] . "</a>", $Text);
         } else {
             $Text = str_replace("[[%{$linkNr}%]]", "<a href=\"" . TextActions::MakeLink($link) . "\">" . $link . "</a>", $Text);
         }
     }
     // convert all **text** to <strong>text</strong> => Bold
     $Text = preg_replace("/\\*\\*(.+?)\\*\\*/s", "<strong>\$1</strong>", $Text);
     // convert all //text// to <em>text</em> => Italic
     $Text = preg_replace("/\\/\\/(.+?)\\/\\//s", "<em>\$1</em>", $Text);
     // convert all __text__ to <u>text</u> => Underline
     $Text = preg_replace("/__(.+?)__/s", "<u>\$1</u>", $Text);
     $Text = nl2br($Text);
     return $Text;
 }
    /**
     * @access public
     * @param integer PageID
     * @param integer Revision 0 = HEAD
     * @return boolean Is true on success
     */
    function LoadPageFromRevision($PageID, $Revision)
    {
        if (!is_numeric($Revision) || !is_numeric($PageID)) {
            return false;
        }
        // It is the HEAD-revision, we won't find it in the history data
        if ($Revision == 0) {
            return $this->LoadPage($PageID);
        }
        $sql = 'SELECT text.text_page_text
					FROM (' . DB_PREFIX . 'pages_history page
					LEFT JOIN ' . DB_PREFIX . 'pages_text_history text ON text.page_id = page.id ) 
					WHERE page.page_id=' . $PageID . '
					ORDER BY  page.page_date ASC
					LIMIT ' . ($Revision - 1) . ',1';
        $pageDataResult = $this->_SqlConnection->SqlQuery($sql);
        if ($pageData = mysql_fetch_object($pageDataResult)) {
            $this->HTML = TextActions::ConvertToPreHtml($pageData->text_page_text);
            $this->Text = $pageData->text_page_text;
            return true;
        }
        return false;
    }
 function Edit($page_id, $title = '', $text = '', $edit_comment = '')
 {
     global $_SERVER, $admin_lang;
     $change = GetPostOrGet('change');
     $count = 1;
     $out = '';
     $page_data = null;
     $got_mysql = false;
     if ($text == '' && $title == '') {
         if (is_numeric($change) && $text == '' && $title == '') {
             $out .= "<strong>Achtung:</strong> Sie bearbeiten nicht die aktuelle Version, wenn Sie speichern wird ihr Text den aktuellen Text &uuml;berschreiben!";
             $sql = "SELECT *\r\n\t\t\t\t\t\tFROM (" . DB_PREFIX . "pages_history page\r\n\t\t\t\t\t\tLEFT JOIN " . DB_PREFIX . "pages_text_history text ON text.page_id = page.id ) \r\n\t\t\t\t\t\tWHERE page.page_id={$page_id}\r\n\t\t\t\t\t\tORDER BY  page.page_date ASC\r\n\t\t\t\t\t\tLIMIT " . ($change - 1) . ",1";
         } else {
             if ($text == '' && $title == '') {
                 $sql = "SELECT *\r\n\t\t\t\t\t\tFROM " . DB_PREFIX . "pages_history\r\n\t\t\t\t\t\tWHERE page_id = {$page_id}\r\n\t\t\t\t\t\tLIMIT 0,1";
                 $count_result = db_result($sql);
                 $count = mysql_num_rows($count_result);
                 $sql = "SELECT struct.page_id, struct.page_title, text.text_page_text, struct.page_edit_comment\r\n\t\t\t\t\t\tFROM ( " . DB_PREFIX . "pages struct\r\n\t\t\t\t\t\tLEFT JOIN " . DB_PREFIX . "pages_text text ON text.page_id = struct.page_id )\r\n\t\t\t\t\t\tWHERE struct.page_id='{$page_id}' AND struct.page_type='text'";
             }
         }
         $page_result = db_result($sql);
         if ($page_data = mysql_fetch_object($page_result)) {
             $got_mysql = true;
         }
     }
     if ($got_mysql || ($text != '' || $title != '')) {
         if ($text != '' || $title != '') {
             $page_title = stripslashes($title);
             $page_text = stripslashes($text);
             $page_edit_comment = stripslashes($edit_comment);
             $show_preview = true;
         } else {
             $page_title = $page_data->page_title;
             $page_text = $page_data->text_page_text;
             $page_edit_comment = $admin_lang['edited'] . '...';
             $show_preview = false;
         }
         $page_text = str_replace('&', '&amp;', $page_text);
         // FIXME: doesn't solve the problem with umlauts
         /*$page_text = str_replace('�', '&auml;', $page_text);
         		$page_text = str_replace('�', '&Auml;', $page_text);
         		$page_text = str_replace('�', '&uuml;', $page_text);
         		$page_text = str_replace('�', '&Uuml;', $page_text);
         		$page_text = str_replace('�', '&ouml;', $page_text);
         		$page_text = str_replace('�', '&Ouml;', $page_text);
         		$page_text = str_replace('�', '&szlig;', $page_text);
         		**/
         $page_text = str_replace('<', '&lt;', $page_text);
         $page_text = str_replace('>', '&gt;', $page_text);
         $out .= "\t\t\t<fieldset><legend>Seite Bearbeiten</legend><form action=\"admin.php\" method=\"post\">\r\n\t\t\t\t<input type=\"hidden\" name=\"page\" value=\"pagestructure\" />\r\n\t\t\t\t<input type=\"hidden\" name=\"action\" value=\"savePage\" />\r\n\t\t\t\t<input type=\"hidden\" name=\"pageID\" value=\"{$page_id}\" />\r\n\t\t\t\t<input type=\"text\" name=\"pageTitle\" value=\"{$page_title}\" /><br />\r\n\t\t\t\t<script type=\"text/javascript\" language=\"JavaScript\" src=\"system/functions.js\"></script>\r\n\t\t\t\t<script type=\"text/javascript\" language=\"javascript\">\r\n\t\t\t\t\twriteButton(\"img/button_fett.png\",\"Formatiert Text fett\",\"**\",\"**\",\"Fetter Text\",\"f\");\r\n\t\t\t\t\twriteButton(\"img/button_kursiv.png\",\"Formatiert Text kursiv\",\"//\",\"//\",\"Kursiver Text\",\"k\");\r\n\t\t\t\t\twriteButton(\"img/button_unterstrichen.png\",\"Unterstreicht den Text\",\"__\",\"__\",\"Unterstrichener Text\",\"u\");\r\n\t\t\t\t\twriteButton(\"img/button_ueberschrift.png\",\"Markiert den Text als &Uuml;berschrift\",\"==== \",\" ====\",\"&Uuml;berschrift\",\"h\");\r\n\t\t\t\t</script><br />\r\n\t\t\t\t<textarea id=\"editor\" class=\"edit\" name=\"pageText\">{$page_text}</textarea>\r\n\t\t\t\t<script type=\"text/javascript\" language=\"javascript\">\r\n\t\t\t\t\tdocument.write('<div style=\"float:right;\">');\r\n\t\t\t\t\tdocument.write('<img onclick=\"resizeBox(-5)\" title=\"Eingabefeld verkleinern\" alt=\"Eingabefeld verkleinern\" class=\"resize\" src=\"img/up.png\" /> ');\r\n\t\t\t\t\tdocument.write('<img onclick=\"resizeBox(5)\" title=\"Eingabefeld vergr&ouml;&szlig;ern\" alt=\"Eingabefeld vergr&ouml;&szlig;ern\" class=\"resize\" src=\"img/down.png\" /><br />');\r\n\t\t\t\t\tdocument.write('</div>');\t\r\n\t\t\t\t</script>\r\n\t\t\t\t{$admin_lang['comment_on_change']}: <input name=\"pageEditComment\" style=\"width:20em;\" value=\"" . ($count == 0 ? $page_data->page_edit_comment : (is_numeric($change) ? sprintf($admin_lang['edited_from_version'], $change) : $page_edit_comment)) . "\" maxlength=\"100\" type=\"text\"/><br />\r\n\t\t\t\t<input type=\"submit\" value=\"Speichern\" class=\"button\" />\r\n\t\t\t\t<input type=\"submit\" value=\"Vorschau\" name=\"pagePreview\" class=\"button\" />\r\n\t\t\t\t<input type=\"submit\" value=\"Abbrechen\" name=\"pageAbort\" class=\"button\"/>\r\n\t\t\t</form></fieldset>\r\n";
         if ($show_preview) {
             $page_text = TextActions::ConvertToPreHTML($page_text);
             $out .= "<fieldset>\r\n\t\t\t\t\t\t<legend>Vorschau</legend>\r\n\t\t\t\t\t\t<iframe class=\"pagepreview\" src=\"index.php?content=" . urlencode($page_text) . "\"></iframe>\r\n\t\t\t\t\t</fieldset>";
         }
     }
     return $out;
 }
 /**
  * @access public
  * @return string
  */
 function _saveArticle()
 {
     $id = GetPostOrGet('article_id');
     $title = GetPostOrGet('article_title');
     $description = GetPostOrGet('article_description');
     $text = GetPostOrGet('article_text');
     if (strlen($description) > 200) {
         $description = substr($description, 0, 200);
     }
     if ($title !== null && $description !== null && $text !== null && is_numeric($id)) {
         $sql = "UPDATE " . DB_PREFIX . "articles SET \n\t\t\t\t\tarticle_title= '{$title}', \n\t\t\t\t\tarticle_description= '{$description}', \n\t\t\t\t\tarticle_text= '{$text}',\n\t\t\t\t\tarticle_html= '" . TextActions::ConvertToPreHTML($text) . "'\n\t\t\t\t\tWHERE article_id={$id}";
         db_result($sql);
     }
 }
 function GetSavePage($PageID)
 {
     if (!is_numeric($PageID)) {
         return false;
     }
     $preview = GetPostOrGet('pagePreview');
     // oh.. somebody called the previewfunction without javascript
     if ($preview != '') {
         return $this->GetEditPage($PageID);
     }
     $pageTitle = stripslashes(GetPostOrGet('pageTitle'));
     $pageText = stripslashes(GetPostOrGet('pageText'));
     $pageComment = stripslashes(GetPostOrGet('pageEditComment'));
     $pageHtml = TextActions::ConvertToPreHTML($pageText);
     $html = addslashes($pageHtml);
     $this->LogPage($PageID, $pageComment);
     $this->UpdatePage($PageID, addslashes($pageText), $html);
     $this->UpdateTitle($PageID, addslashes($pageTitle));
 }
 /** MakeLink
  * @param string Link
  * @return string
  */
 function MakeLink($Link)
 {
     $antibot = EMAIL_ANTISPAM_TEXT;
     $encodedLink = encodeUri($Link);
     // identify mail-adresses
     if (preg_match("/^[a-z0-9-_\\.]+@[a-z0-9\\-_\\.]+\\.[a-z]{2,4}\$/i", $Link)) {
         $Link = TextActions::EmailAntispam($Link, $antibot);
         return "mailto:{$Link}\" class=\"link_email";
     } else {
         if (substr($encodedLink, 0, 6) == 'http:/' || substr($encodedLink, 0, 5) == 'ftp:/' || substr($encodedLink, 0, 7) == 'https:/') {
             return "{$encodedLink}\" class=\"link_extern";
         } else {
             if (substr($encodedLink, 0, 11) == 'download%3A') {
                 return TextActions::GetDownloadUrl(substr($encodedLink, 11));
             }
         }
     }
     return TextActions::GetInternUrl($encodedLink);
 }
 function _generateHtml($Text)
 {
     preg_match_all("#\\[\\[(.+?)\\]\\]#s", $Text, $links);
     $link_list = array();
     $linkNr = 1;
     // replace all links with a short uniqe id to replace them later back
     foreach ($links[1] as $link) {
         $link_list[$linkNr] = $link;
         $Text = str_replace("[[{$link}]]", "[[%{$linkNr}%]]", $Text);
         $linkNr++;
     }
     foreach ($link_list as $linkNr => $link) {
         if (preg_match("#^(.+?)\\|(.+?)\$#i", $link, $link2)) {
             $Text = str_replace("[[%{$linkNr}%]]", "<a href=\"" . TextActions::MakeLink($link2[1]) . "\">" . $link2[2] . "</a>", $Text);
         } else {
             $Text = str_replace("[[%{$linkNr}%]]", "<a href=\"" . TextActions::MakeLink($link) . "\">" . $link . "</a>", $Text);
         }
     }
     $Text = nl2br($Text);
     return $Text;
 }