Example #1
0
 function export_items($table, $primary_key, $ref_key, $primary_key_value)
 {
     global $serendipity;
     $result = serendipity_db_Query("SELECT * FROM {$serendipity['dbPrefix']}{$table} WHERE {$ref_key} = {$primary_key_value}", false, 'assoc');
     foreach ($result as $row) {
         $row[$ref_key] = '@last';
         if ($primary_key !== null) {
             unset($row[$primary_key]);
         }
         foreach ($row as $key => $val) {
             if ($val != '@last') {
                 $row[$key] = "'" . serendipity_db_escape_string($val) . "'";
             }
         }
         echo "INSERT INTO {$serendipity['dbPrefix']}{$table} (" . implode(', ', array_keys($row)) . ") VALUES (" . implode(', ', $row) . ");\n";
     }
 }
    function event_hook($event, &$bag, &$eventData, $addData = null)
    {
        global $serendipity;
        $hooks =& $bag->get('event_hooks');
        $this->debug = serendipity_db_bool($this->get_config('debug'));
        if (isset($hooks[$event])) {
            switch ($event) {
                case 'backend_sidebar_entries':
                    if ($serendipity['serendipityUserlevel'] >= USERLEVEL_CHIEF) {
                        if ($serendipity['version'][0] == '1') {
                            ?>
                        <li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks"><a href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=aggregator"><?php 
                            echo PLUGIN_AGGREGATOR_TITLE;
                            ?>
</a></li>
<?php 
                        } else {
                            ?>
                        <li><a href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=aggregator"><?php 
                            echo PLUGIN_AGGREGATOR_TITLE;
                            ?>
</a></li>
<?php 
                        }
                    }
                    break;
                case 'backend_sidebar_entries_event_display_aggregator':
                    $this->showFeeds();
                    break;
                case 'cronjob':
                    if ($this->get_config('cronjob') == $eventData) {
                        serendipity_event_cronjob::log('Aggregator', 'plugin');
                        $this->fetchFeeds();
                        # Fetch first, expire later (some feeds offer old stuff)
                        $this->expireFeeds();
                    }
                    return true;
                    break;
                case 'aggregator_feedlist':
                    $this->parseShowFeed($eventData);
                    return true;
                    break;
                case 'external_plugin':
                    if ($eventData == 'opmlfeeds.xml') {
                        header('Content-Type: text/xml; charset=utf-8');
                        echo '<?xml version="1.0" encoding="utf-8" ?>' . "\n";
                        $modified = gmdate('D, d M Y H:i:s \\G\\M\\T', serendipity_serverOffsetHour(time(), true));
                        print <<<EOF
<opml version="1.0">
<head>
    <title>{$serendipity['blogTitle']}</title>
    <dateModified>{$modified}</dateModified>
    <ownerName>Serendipity - http://www.s9y.org/</ownerName>
</head>
<body>
EOF;
                        $feeds = serendipity_db_Query("\n                                    SELECT c.categoryid,\n                                           f.feedname,\n                                           f.feedurl,\n                                           f.htmlurl\n                                     FROM {$serendipity['dbPrefix']}category AS c\n                                LEFT JOIN {$serendipity['dbPrefix']}aggregator_feedcat AS fc\n                                       ON fc.categoryid = c.categoryid\n                                LEFT JOIN {$serendipity['dbPrefix']}aggregator_feeds AS f\n                                       ON fc.feedid = f.feedid", false, 'assoc');
                        $xml = array();
                        if (is_array($feeds)) {
                            foreach ($feeds as $feed) {
                                $xml[$feed['categoryid']][] = $feed;
                            }
                        }
                        if (is_array($cats = serendipity_fetchCategories())) {
                            $cats = $this->showRecursive($cats, $xml, 'categoryid', 'parentid', VIEWMODE_THREADED);
                        }
                        print "</body>\n</opml>";
                        return;
                    }
                    if ($eventData != 'aggregator') {
                        return;
                    }
                    $this->fetchFeeds();
                    # Fetch first, expire later (some feeds offer old stuff)
                    $this->expireFeeds();
                    break;
            }
        }
        return true;
    }
 function djo_zwischenspeicherung()
 {
     global $serendipity;
     if (is_array($this->djo_vernetzung_in_cache_schreiben)) {
         foreach ($this->djo_vernetzung_in_cache_schreiben as $vernetzung) {
             $schluessel = md5($vernetzung[0]);
             if ($vernetzung[0] == $vernetzung[1]) {
                 $text = "<!-- idem -->";
             } else {
                 $text = $vernetzung[1];
             }
             serendipity_db_Query("DELETE FROM {$serendipity['dbPrefix']}dejure WHERE ckey = '" . $schluessel . "'");
             serendipity_db_Query("INSERT INTO {$serendipity['dbPrefix']}dejure (ckey, cache, last_update) VALUES ('" . $schluessel . "', '" . serendipity_db_escape_string($text) . "', " . time() . ")");
         }
     }
 }
    function event_hook($event, &$bag, &$eventData, $addData = null)
    {
        global $serendipity;
        static $phpbb_mirror = null;
        if ($phpbb_mirror == null) {
            $phpbb_mirror = $this->get_config('phpbb_mirror');
            if ((int) $phpbb_mirror === 4) {
                $phpbb_mirror = 4;
            } elseif ((int) $phpbb_mirror === 3) {
                $phpbb_mirror = 3;
            } elseif ((int) $phpbb_mirror === 2) {
                $phpbb_mirror = 2;
            } elseif (serendipity_db_bool($phpbb_mirror)) {
                $phpbb_mirror = 2;
            } else {
                $phpbb_mirror = false;
            }
        }
        $hooks =& $bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch ($event) {
                case 'entries_header':
                    $this->show();
                    return true;
                    break;
                case 'entry_display':
                    if ($serendipity['GET']['subpage'] == $this->get_config('pageurl')) {
                        if (is_array($eventData)) {
                            $eventData['clean_page'] = true;
                        } else {
                            $eventData = array('clean_page' => true);
                        }
                    }
                    return true;
                    break;
                case 'backend_sidebar_entries':
                    $this->setupDB();
                    if ($serendipity['serendipityUserlevel'] < USERLEVEL_ADMIN) {
                        break;
                    } else {
                        ?>
                    <li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks"><a href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=forum"><?php 
                        echo PLUGIN_FORUM_TITLE;
                        ?>
</a></li>
                    <?php 
                    }
                    break;
                case 'backend_sidebar_entries_event_display_forum':
                    if ($serendipity['serendipityUserlevel'] < USERLEVEL_ADMIN) {
                        break;
                    } else {
                        $this->forumAdmin();
                    }
                    break;
                case 'external_plugin':
                    if (isset($eventData['setthreadcookie']) && intval($eventData['setthreadcookie']) >= 1) {
                        $threadid = intval($eventData['setthreadcookie']);
                        if (is_array($_COOKIE) && trim($_COOKIE['s9yread']) != "") {
                            $READARRAY = unserialize(stripslashes(trim($_COOKIE['s9yread'])));
                        } else {
                            $READARRAY = array();
                        }
                        $READARRAY[$threadid] = time();
                        $READCOOKIE = addslashes(trim(serialize($READARRAY)));
                        setcookie("s9yread", "{$READCOOKIE}", time() + 31536000, "/");
                    }
                    $theUri = (string) str_replace('&amp;', '&', $eventData);
                    $uri_parts = explode('?', $theUri);
                    // Try to get reguest parameters from eventData name
                    if (!empty($uri_parts[1])) {
                        $reqs = explode('&', $uri_parts[1]);
                        foreach ($reqs as $id => $req) {
                            $val = explode('=', $req);
                            if (empty($_REQUEST[$val[0]])) {
                                $_REQUEST[$val[0]] = $val[1];
                            }
                        }
                    }
                    $parts = explode('_', $uri_parts[0]);
                    if (!empty($parts[1])) {
                        $param = (int) $parts[1];
                    } else {
                        $param = null;
                    }
                    switch ($parts[0]) {
                        case 'forumdl':
                            $fileid = intval($parts[1]);
                            serendipity_db_query("UPDATE {$serendipity['dbPrefix']}dma_forum_uploads SET dlcount = dlcount+1 WHERE uploadid = " . $fileid);
                            $sql = "SELECT * FROM {$serendipity['dbPrefix']}dma_forum_uploads WHERE uploadid = " . $fileid;
                            $file = serendipity_db_query($sql);
                            $mime = DMA_forum_getMime(basename($file[0]['realfilename']), $this->DMA_forum_getRelPath());
                            $contenttype = $mime['TYPE'];
                            $filename = basename($file[0]['realfilename']);
                            $path = $this->get_config('uploaddir');
                            $sysname = basename($file[0]['sysfilename']);
                            $filesize = $file[0]['filesize'];
                            if (function_exists("getallheaders")) {
                                $headers = getallheaders();
                            }
                            if (substr($headers["Range"], 0, 6) == "bytes=") {
                                header("HTTP/1.1 206 Partial Content");
                                header("Content-Type: {$contenttype}");
                                header("Content-Disposition: attachment; filename=" . $filename);
                                header("Accept-Ranges: bytes");
                                header("Connection: close");
                                $bytes = explode("=", $headers["Range"]);
                                $bytes = $bytes[1];
                                if (preg_match("@^-([0-9]+)@", $bytes, $bytes_len)) {
                                    $bytes_len = $bytes_len[1];
                                    $bytes_start = $filesize - $bytes_len;
                                    $bytes_end = $filesize - 1;
                                    header("Content-Length: " . $bytes_len);
                                } elseif (preg_match("@([0-9]+)-\$@", $bytes, $bytes_start)) {
                                    $bytes_start = $bytes_start[1];
                                    $bytes_end = $filesize - 1;
                                    $bytes_len = $filesize - $bytes_start;
                                    header("Content-Length: {$bytes_len}");
                                } elseif (preg_match("@^([0-9]+)-([0-9]+)\$@", $bytes, $bytes_pos)) {
                                    $bytes_start = $bytes_pos[0];
                                    $bytes_end = $bytes_pos[1];
                                    if ($bytes_start < 0 || $bytes_start > $filesize - 1) {
                                        $bytes_start = 0;
                                    }
                                    if ($bytes_end < $bytes_start || $bytes_end > $filesize - 1) {
                                        $bytes_end = $filesize - 1;
                                    }
                                    $bytes_len = $bytes_end - $bytes_start + 1;
                                    header("Content-Length: {$bytes_len}");
                                } else {
                                    $bytes_start = 0;
                                    $bytes_end = $filesize - 1;
                                    $bytes_len = $bytes_end - $bytes_start + 1;
                                    header("Content-Length: {$bytes_len}");
                                }
                                header("Content-Range: bytes {$bytes_start}-{$bytes_end}/" . $filesize);
                                $fp = fopen($path . "/" . $sysname, "rb");
                                fseek($fp, $bytes_start);
                                $contents = fread($fp, $bytes_len);
                                fclose($fp);
                                echo $contents;
                            } else {
                                $fp = fopen($path . "/" . $sysname, "rb");
                                $contents = fread($fp, $filesize);
                                fclose($fp);
                                header("Content-Type: {$contenttype}");
                                header("Content-Disposition: attachment; filename=" . $filename);
                                header("Accept-Ranges: bytes");
                                header("Content-Length: " . strlen($contents));
                                header("Connection: close");
                                echo $contents;
                            }
                            break;
                    }
                    return true;
                    break;
                case 'backend_save':
                case 'backend_publish':
                    if (!$phpbb_mirror) {
                        #$this->logMSG('Forum mirroring is disabled');
                        return false;
                    }
                    $con = mysql_connect($this->get_config('phpbb_db_host'), $this->get_config('phpbb_db_user'), $this->get_config('phpbb_db_pw'));
                    if (!$con) {
                        $this->logMSG('Could not connect to database');
                        return false;
                    }
                    if (!mysql_select_db($this->get_config('phpbb_db_name'), $con)) {
                        $this->logMSG('Could not select database');
                        return false;
                    }
                    if (mysql_error() != '') {
                        $this->logMSG(mysql_error(), true);
                        return false;
                    }
                    mysql_query("SET NAMES " . SQL_CHARSET);
                    $prefix = $this->get_config('phpbb_db_prefix');
                    $fid = (int) $this->get_config('phpbb_forum');
                    $topic_poster = (int) $this->get_config('phpbb_poster');
                    if ($phpbb_mirror == 4) {
                        $tp = mysql_query("SELECT realName AS username FROM {$prefix}members WHERE ID_MEMBER = {$topic_poster}");
                    } else {
                        $tp = mysql_query("SELECT username FROM {$prefix}users WHERE user_id = {$topic_poster}");
                    }
                    if (mysql_num_rows($tp) > 0) {
                        $topic_poster_data = mysql_fetch_array($tp, MYSQL_ASSOC);
                    }
                    if ($event == 'backend_save') {
                        $r = serendipity_db_query("SELECT value, property\n                                                     FROM {$serendipity['dbPrefix']}entryproperties\n                                                    WHERE entryid = " . (int) $eventData['id'] . "\n                                                      AND (property = 'phpbb_topic' OR property = 'phpbb_post')", false, 'assoc', false, 'property');
                        if (empty($r['phpbb_post']['value']) || empty($r['phpbb_topic']['value'])) {
                            #$this->logMSG('Could not get phpbb reference for entry ' . $eventData['id']);
                            return false;
                        }
                        if ($phpbb_mirror == 4) {
                        } else {
                            mysql_query("UPDATE {$prefix}topics\n                                            SET topic_title = '" . serendipity_db_escape_string($eventData['title']) . "'\n                                          WHERE topic_id = " . (int) $r['phpbb_topic']['value'], $con);
                        }
                        $this->logMSG(mysql_error(), true);
                        if ($phpbb_mirror == 4) {
                            mysql_query("UPDATE {$prefix}messages\n                                            SET subject = '" . serendipity_db_escape_string($eventData['title']) . "',\n                                                body    = '" . serendipity_db_escape_string($eventData['body'] . $eventData['extended']) . "',\n                                                modifiedTime = '" . time() . "',\n                                                posterTime = '" . time() . "'\n                                          WHERE ID_MSG = " . (int) $r['phpbb_post']['value'], $con);
                        } elseif ($phpbb_mirror == 3) {
                            mysql_query("UPDATE {$prefix}posts\n                                            SET post_subject = '" . serendipity_db_escape_string($eventData['title']) . "',\n                                                post_text    = '" . serendipity_db_escape_string($eventData['body'] . $eventData['extended']) . "',\n                                                topic_last_post_time = '" . time() . "'\n                                          WHERE post_id = " . (int) $r['phpbb_post']['value'], $con);
                        } else {
                            mysql_query("UPDATE {$prefix}posts_text\n                                            SET post_subject = '" . serendipity_db_escape_string($eventData['title']) . "',\n                                                post_text    = '" . serendipity_db_escape_string($eventData['body'] . $eventData['extended']) . "'\n                                          WHERE post_id = " . (int) $r['phpbb_post']['value'], $con);
                        }
                        $this->logMSG(mysql_error(), true);
                        return true;
                    }
                    if ($phpbb_mirror == 4) {
                        mysql_query("INSERT INTO {$prefix}topics (ID_BOARD, ID_FIRST_MSG, ID_LAST_MSG, ID_MEMBER_STARTED, ID_MEMBER_UPDATED)\n                                          VALUES ({$fid}, {$topic_poster}, {$topic_poster}, {$topic_poster}, {$topic_poster})", $con);
                    } elseif ($phpbb_mirror == 3) {
                        mysql_query("INSERT INTO {$prefix}topics (forum_id, topic_title, topic_poster, topic_time, topic_first_post_id, topic_last_post_id, topic_first_poster_name, topic_last_post_time, topic_last_poster_id)\n                                          VALUES ({$fid}, '" . serendipity_db_escape_string($eventData['title']) . "', {$topic_poster}, UNIX_TIMESTAMP(NOW()), {$topic_poster}, {$topic_poster}, '" . serendipity_db_escape_string($topic_poster_data['username']) . "', '" . time() . "', {$topic_poster})", $con);
                    } else {
                        mysql_query("INSERT INTO {$prefix}topics (forum_id, topic_title, topic_poster, topic_time, topic_first_post_id, topic_last_post_id)\n                                          VALUES ({$fid}, '" . serendipity_db_escape_string($eventData['title']) . "', {$topic_poster}, UNIX_TIMESTAMP(NOW()), 0, 0)", $con);
                    }
                    $this->logMSG(mysql_error(), true);
                    $topic_id = mysql_insert_id($con);
                    if ($phpbb_mirror == 4) {
                        mysql_query("INSERT INTO {$prefix}messages (ID_TOPIC, ID_BOARD, posterTime, ID_MEMBER, subject, posterName, posterEmail, posterIP, modifiedTime, body)\n                                          VALUES ({$topic_id}, {$fid}, UNIX_TIMESTAMP(NOW()), {$topic_poster}, '" . serendipity_db_escape_string($eventData['title']) . "', '" . serendipity_db_escape_string($eventData['author']) . "', '" . serendipity_db_escape_string($eventData['email']) . "', '" . $_SERVER['REMOTE_ADDR'] . "', 0, '" . serendipity_db_escape_string($eventData['body'] . $eventData['extended']) . "')", $con);
                        $this->logMSG(mysql_error(), true);
                        $post_id = mysql_insert_id($con);
                    } elseif ($phpbb_mirror == 3) {
                        mysql_query("INSERT INTO {$prefix}posts (topic_id, forum_id, poster_id, post_time, post_username, post_subject, post_text)\n                                          VALUES ({$topic_id}, {$fid}, {$topic_poster}, UNIX_TIMESTAMP(NOW()), '" . serendipity_db_escape_string($eventData['author']) . "', '" . serendipity_db_escape_string($eventData['title']) . "', '" . serendipity_db_escape_string($eventData['body'] . $eventData['extended']) . "')", $con);
                        $this->logMSG(mysql_error(), true);
                        $post_id = mysql_insert_id($con);
                    } else {
                        mysql_query("INSERT INTO {$prefix}posts (topic_id, forum_id, poster_id, post_time, post_username)\n                                          VALUES ({$topic_id}, {$fid}, {$topic_poster}, UNIX_TIMESTAMP(NOW()), '" . serendipity_db_escape_string($eventData['author']) . "')", $con);
                        $this->logMSG(mysql_error(), true);
                        $post_id = mysql_insert_id($con);
                        mysql_query("INSERT INTO {$prefix}posts_text (post_id, post_subject, post_text)\n                                          VALUES ({$post_id}, '" . serendipity_db_escape_string($eventData['title']) . "', '" . serendipity_db_escape_string($eventData['body'] . $eventData['extended']) . "')", $con);
                        $this->logMSG(mysql_error(), true);
                    }
                    if ($phpbb_mirror == 4) {
                        mysql_query("UPDATE {$prefix}topics\n                                        SET ID_FIRST_MSG = {$post_id},\n                                            ID_LAST_MSG  = {$post_id}\n                                      WHERE ID_TOPIC = {$topic_id}", $con);
                    } else {
                        mysql_query("UPDATE {$prefix}topics\n                                        SET topic_first_post_id = {$post_id},\n                                            topic_last_post_id  = {$post_id}\n                                      WHERE topic_id = {$topic_id}", $con);
                    }
                    $this->logMSG(mysql_error(), true);
                    if ($phpbb_mirror == 4) {
                        mysql_query("UPDATE {$prefix}boards\n                                                 SET numPosts    = numPosts + 1,\n                                                     numTopics   = numTopics + 1,\n                                                     ID_LAST_MSG = {$post_id}\n                                               WHERE ID_BOARD = {$fid}", $con);
                    } else {
                        mysql_query("UPDATE {$prefix}forums\n                                                 SET forum_posts        = forum_posts + 1,\n                                                     forum_topics       = forum_topics + 1,\n                                                     forum_last_post_id = {$post_id}\n                                               WHERE forum_id = {$fid}", $con);
                    }
                    $this->logMSG(mysql_error(), true);
                    if ($phpbb_mirror == 4) {
                        $v = mysql_query("SELECT variable, value FROM {$prefix}settings WHERE variable = 'smileys_url'", $con);
                        $this->logMsg(mysql_error(), true);
                        #$this->logMSG('Fetching config values from phpBB Board');
                        while ($row = mysql_fetch_array($v, MYSQL_ASSOC)) {
                            $conf[$row['variable']] = $row['value'];
                            #$this->logMSG('Got config values from phpBB: ' . print_r($row, true));
                        }
                        $url = str_replace('/Smileys', '/index.php?topic=' . $topic_id . '.0', $conf['smileys_url']);
                    } else {
                        #$this->logMSG('Fetching config values from phpBB Board');
                        while ($row = mysql_fetch_array($v, MYSQL_ASSOC)) {
                            $conf[$row['config_name']] = $row['config_value'];
                            #$this->logMSG('Got config values from phpBB: ' . print_r($row, true));
                        }
                        $url = "http://{$conf['server_name']}{$conf['script_path']}/viewtopic.php?p={$post_id}";
                    }
                    serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value)\n                                               VALUES (" . (int) $eventData['id'] . ", 'phpbb_topic', {$topic_id})");
                    serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value)\n                                               VALUES (" . (int) $eventData['id'] . ", 'phpbb_post', {$post_id})");
                    serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value)\n                                               VALUES (" . (int) $eventData['id'] . ", 'phpbb_url', '" . $url . "')");
                    return true;
                case 'frontend_saveComment':
                    if (!$phpbb_mirror) {
                        return true;
                    }
                    if (!$eventData['allow_comments']) {
                        return true;
                    }
                    $r = serendipity_db_query("SELECT value, property\n                                                 FROM {$serendipity['dbPrefix']}entryproperties\n                                                WHERE entryid = " . (int) $eventData['id'] . "\n                                                  AND (property = 'phpbb_topic' OR property = 'phpbb_post' OR property = 'phpbb_url')", false, 'assoc', false, 'property');
                    if (empty($r['phpbb_post']['value']) || empty($r['phpbb_topic']['value'])) {
                        #$this->logMSG('Could not get phpBB properties for storing a comment');
                        return false;
                    }
                    $con = mysql_connect($this->get_config('phpbb_db_host'), $this->get_config('phpbb_db_user'), $this->get_config('phpbb_db_pw'));
                    if (!$con) {
                        $this->logMSG('Could not get phpBB properties for storing a comment: DB credentials');
                        return false;
                    }
                    if (!mysql_select_db($this->get_config('phpbb_db_name'), $con)) {
                        $this->logMSG('Could not get phpBB properties for storing a comment: DB name');
                        return false;
                    }
                    if (mysql_error() != '') {
                        $this->logMSG(mysql_error(), true);
                        return false;
                    }
                    mysql_query("SET NAMES " . SQL_CHARSET);
                    $prefix = $this->get_config('phpbb_db_prefix');
                    $fid = (int) $this->get_config('phpbb_forum');
                    $topic_poster = (int) $this->get_config('phpbb_poster');
                    $topic_id = $r['phpbb_topic']['value'];
                    $phpbb_url = $r['phpbb_url']['value'];
                    if ($phpbb_mirror == 4) {
                        mysql_query("INSERT INTO {$prefix}messages (ID_TOPIC, ID_BOARD, posterTime, ID_MEMBER, subject, posterName, posterEmail, posterIP, modifiedTime, body)\n                                          VALUES ({$topic_id}, {$fid}, UNIX_TIMESTAMP(NOW()), 0, '" . serendipity_db_escape_string($addData['title']) . "', '" . serendipity_db_escape_string($addData['name']) . "', '" . serendipity_db_escape_string($addData['email']) . "', '" . $_SERVER['REMOTE_ADDR'] . "', 0, '" . serendipity_db_escape_string($addData['comment']) . "')", $con);
                        $this->logMSG(mysql_error(), true);
                        $post_id = mysql_insert_id($con);
                    } elseif ($phpbb_mirror == 3) {
                        $q1 = "INSERT INTO {$prefix}posts (topic_id, forum_id, post_time, post_username, poster_id, post_subject, post_text)\n                                          VALUES ({$topic_id}, {$fid}, UNIX_TIMESTAMP(NOW()), '" . strip_tags(serendipity_db_escape_string($addData['name'])) . "', 1, '" . strip_tags(serendipity_db_escape_string($addData['title'])) . "', '" . strip_tags(serendipity_db_escape_string($addData['comment'])) . "')";
                        mysql_query($q1, $con);
                        $this->logMSG(mysql_error(), true);
                        $post_id = mysql_insert_id($con);
                    } else {
                        $q1 = "INSERT INTO {$prefix}posts (topic_id, forum_id, post_time, post_username, poster_id)\n                                          VALUES ({$topic_id}, {$fid}, UNIX_TIMESTAMP(NOW()), '" . strip_tags(serendipity_db_escape_string($addData['name'])) . "', -1)";
                        mysql_query($q1, $con);
                        $this->logMSG(mysql_error(), true);
                        $post_id = mysql_insert_id($con);
                        $q2 = "INSERT INTO {$prefix}posts_text (post_id, post_subject, post_text)\n                                          VALUES ({$post_id}, '" . strip_tags(serendipity_db_escape_string($addData['title'])) . "', '" . strip_tags(serendipity_db_escape_string($addData['comment'])) . "')";
                        mysql_query($q2, $con);
                        $this->logMSG(mysql_error(), true);
                    }
                    if ($phpbb_mirror == 4) {
                        $q3 = "UPDATE {$prefix}topics \n                                  SET numReplies = numReplies + 1, \n                                      ID_MEMBER_UPDATED = 0, \n                                      ID_LAST_MSG = {$post_id} \n                                WHERE ID_TOPIC = {$topic_id}";
                    } elseif ($phpbb_mirror == 3) {
                        $q3 = "UPDATE {$prefix}topics SET topic_replies = topic_replies + 1, topic_replies_real = topic_replies_real + 1, topic_last_poster_id = 1, topic_last_poster_name = '" . strip_tags(serendipity_db_escape_string($addData['name'])) . "', topic_last_post_id = {$post_id} WHERE topic_id = {$topic_id}";
                    } else {
                        $q3 = "UPDATE {$prefix}topics SET topic_replies = topic_replies + 1, topic_last_post_id = {$post_id} WHERE topic_id = {$topic_id}";
                    }
                    mysql_query($q3, $con);
                    $this->logMSG(mysql_error(), true);
                    if ($phpbb_mirror == 4) {
                        $q4 = "UPDATE {$prefix}boards SET numPosts = numPosts + 1, ID_LAST_MSG = {$post_id} WHERE ID_BOARD = {$fid}";
                    } else {
                        $q4 = "UPDATE {$prefix}forums SET forum_posts = forum_posts + 1, forum_last_post_id = {$post_id} WHERE forum_id = {$fid}";
                    }
                    mysql_query($q4, $con);
                    $this->logMSG(mysql_error(), true);
                    $c = serendipity_db_query("SELECT comments FROM {$serendipity['dbPrefix']}entries WHERE id = " . (int) $eventData['id'], true, 'assoc');
                    if ($c['comments'] < 1) {
                        serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}comments (entry_id, title, url, type, status, subscribed)\n                                                   VALUES (" . (int) $eventData['id'] . ", 'phpbb_mirror', '" . serendipity_db_escape_string($phpbb_url) . "', 'NORMAL', 'approved', 'false')");
                    }
                    serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries SET comments = comments + 1 WHERE id = " . (int) $eventData['id']);
                    header('Status: 302 Found');
                    header('Location: ' . $phpbb_url);
                    exit;
                    return true;
                case 'frontend_display:html:per_entry':
                    if (!$phpbb_mirror) {
                        return true;
                    }
                    #$this->logMSG('PHPBB Entry #' . $eventData['id'] . ': ' . print_r($eventData['properties'], true));
                    $eventData['display_dat'] .= $eventData['phpbb_discuss'] = '<a class="phpbb_link" href="' . $eventData['properties']['phpbb_url'] . '">' . FORUM_PLUGIN_PHPBB_DISCUSS . '</a>';
                    break;
                case 'frontend_display':
                    if (!$phpbb_mirror || !is_array($eventData['properties']) || !isset($eventData['comments'])) {
                        return true;
                    }
                    if ($eventData['comments'] < 1) {
                        $con = mysql_connect($this->get_config('phpbb_db_host'), $this->get_config('phpbb_db_user'), $this->get_config('phpbb_db_pw'));
                        if (!$con) {
                            return false;
                        }
                        mysql_select_db($this->get_config('phpbb_db_name'), $con);
                        mysql_query("SET NAMES " . SQL_CHARSET);
                        $prefix = $this->get_config('phpbb_db_prefix');
                        $basepost_id = $eventData['properties']['phpbb_post'];
                        $topic_id = $eventData['properties']['phpbb_topic'];
                        $phpbb_url = $eventData['properties']['phpbb_url'];
                        if ($phpbb_mirror == 4) {
                            $pq = "SELECT count(m.ID_MSG) AS postcount\n                                                       FROM {$prefix}messages AS m\n                                                      WHERE m.ID_TOPIC = {$topic_id}\n                                                        AND m.ID_MSG != {$basepost_id}\n                                                   GROUP BY m.ID_TOPIC\n                                                      LIMIT 1";
                        } else {
                            $pq = "SELECT count(p.post_id) AS postcount\n                                                       FROM {$prefix}posts AS p\n                                                      WHERE p.topic_id = {$topic_id}\n                                                        AND p.post_id != {$basepost_id}\n                                                   GROUP BY p.topic_id\n                                                      LIMIT 1";
                        }
                        $comments = mysql_query($pq, $con);
                        if ($comments) {
                            $crows = mysql_fetch_array($comments, MYSQL_ASSOC);
                            if ($crows['postcount'] > 0) {
                                $eventData['comments'] = $crows['postcount'];
                            }
                        }
                    }
                    return true;
                case 'fetchcomments':
                    if (!$phpbb_mirror || !is_array($eventData)) {
                        return true;
                    }
                    foreach ($eventData as $idx => $comment) {
                        if ($comment['ctitle'] == 'phpbb_mirror') {
                            $entryid = $comment['entryid'];
                            $entry = $comment;
                            unset($eventData[$idx]);
                        }
                    }
                    if (empty($entryid) && isset($addData['id'])) {
                        $entryid = $addData['id'];
                    }
                    if (empty($entryid)) {
                        return false;
                    }
                    $con = mysql_connect($this->get_config('phpbb_db_host'), $this->get_config('phpbb_db_user'), $this->get_config('phpbb_db_pw'));
                    if (!$con) {
                        return false;
                    }
                    mysql_select_db($this->get_config('phpbb_db_name'), $con);
                    if (mysql_error() != '') {
                        $this->logMSG(mysql_error(), true);
                        return false;
                    }
                    mysql_query("SET NAMES " . SQL_CHARSET);
                    $r = serendipity_db_query("SELECT value, property\n                                                 FROM {$serendipity['dbPrefix']}entryproperties\n                                                WHERE entryid = " . (int) $entryid . "\n                                                  AND (property = 'phpbb_topic' OR property = 'phpbb_post' OR property = 'phpbb_url')", false, 'assoc', false, 'property');
                    if (empty($r['phpbb_post']['value']) || empty($r['phpbb_topic']['value'])) {
                        return false;
                    }
                    $prefix = $this->get_config('phpbb_db_prefix');
                    $basepost_id = $r['phpbb_post']['value'];
                    $topic_id = $r['phpbb_topic']['value'];
                    $phpbb_url = $r['phpbb_url']['value'];
                    if ($phpbb_mirror == 4) {
                        $comments = mysql_query("SELECT p.ID_MSG AS id,\n                                                        p.ID_MSG AS commentid,\n                                                        0 AS parent_id,\n                                                        p.posterTime AS timestamp,\n                                                        p.subject AS ctitle,\n                                                        p.body AS body,\n                                                        'NORMAL' as type,\n                                                        0 AS subscribed,\n                                                        \n                                                        IF(m.realName != '', m.realName, p.posterName) AS author\n    \n                                                   FROM {$prefix}messages AS p\n\n                                        LEFT OUTER JOIN {$prefix}members AS m\n                                                     ON m.ID_MEMBER = p.ID_MEMBER\n\n                                                  WHERE p.ID_TOPIC = {$topic_id}\n                                                    AND p.ID_MSG != {$basepost_id}\n                                               ORDER BY p.posterTime ASC", $con);
                        echo mysql_error();
                    } elseif ($phpbb_mirror == 3) {
                        $comments = mysql_query("SELECT p.post_id AS id,\n                                                        p.post_id AS commentid,\n                                                        0 AS parent_id,\n                                                        p.post_time AS timestamp,\n                                                        p.post_subject AS ctitle,\n                                                        p.post_text AS body,\n                                                        'NORMAL' as type,\n                                                        0 AS subscribed,\n                                                        p.post_username AS author\n    \n                                                   FROM {$prefix}posts AS p\n                                                  WHERE p.topic_id = {$topic_id}\n                                                    AND p.post_id != {$basepost_id}\n                                               ORDER BY p.post_time ASC", $con);
                    } else {
                        $comments = mysql_query("SELECT p.post_id AS id,\n                                                        p.post_id AS commentid,\n                                                        0 AS parent_id,\n                                                        p.post_time AS timestamp,\n                                                        pt.post_subject AS ctitle,\n                                                        pt.post_text AS body,\n                                                        'NORMAL' as type,\n                                                        0 AS subscribed,\n                                                        p.post_username AS author\n    \n                                                   FROM {$prefix}posts AS p\n                                                   JOIN {$prefix}posts_text AS pt\n                                                     ON p.post_id = pt.post_id\n                                                  WHERE p.topic_id = {$topic_id}\n                                                    AND p.post_id != {$basepost_id}\n                                               ORDER BY p.post_time ASC", $con);
                    }
                    $this->logMSG(mysql_error(), true);
                    $return = $eventData;
                    if (mysql_num_rows($comments) < 1) {
                        return false;
                    }
                    while ($row = mysql_fetch_array($comments, MYSQL_ASSOC)) {
                        $row['title'] = $entry['title'];
                        $row['entrytimestamp'] = $entry['entrytimestamp'];
                        $row['entryid'] = $row['entry_id'] = $entryid;
                        $row['authorid'] = $entry['authorid'];
                        $return[] = $row;
                    }
                    $eventData = $return;
                    serendipity_db_Query("UPDATE {$serendipity['dbPrefix']}entries SET comments = " . count($eventData) . " WHERE id = " . (int) $entryid);
                    return true;
                case 'css':
                    if (strpos($eventData, '.forum-') !== false) {
                        // class exists in CSS, so a user has customized it and we don't need default
                        return true;
                    }
                    ?>
.forum-filebox {
    font: normal 12px Courier, Courier New, fixed;
    background-color: #fffde0;
    color: #000000;
    border: 1px dashed;
    border-color: #888888;
    margin: 10px auto;
    padding: 5px;
}
<?php 
                    return true;
                    break;
            }
        }
        return true;
    }