Topic: Problems with getting modification to work as an extension

I have here an extension what was made in pre-rc1 time, it worked with the svn version back then. But for now the extension doesn't work with rc1 nor rc2.

What it has to do, is that to read ip's from every post with syntax

ip: [b]xxx.xxx.xxx.xxx.xxx[/b]

and list them as a table or raw in extern.php

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE extension SYSTEM "ext-1.0.dtd">

<!--
***********************************************************************

    Copyright (C) 2008  PunBB

    PunBB is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License,
    or (at your option) any later version.

    PunBB is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
    MA  02111-1307  USA

***********************************************************************
-->

<extension engine="1.0">
    <id>codee_servers</id>
    <title>CoD.EE server output</title>
    <version>0.1</version>
    <description>Add methods into extern to output server ip's inserted into first posts of toppics in certain subforums.</description>
    <author>Is not that important</author>

    <minversion>1.3dev</minversion>
    <maxtestedon>1.3dev</maxtestedon>

    <hooks>
        <hook id="ex_start"><![CDATA[
    // yo    
    function output_raw($servers) {

    global $forum_config;

    echo "<table><tr><th>M2ng</th><th>Nimi</th><th>ip:port</th></tr>\n";
    foreach ($servers as $server)
    {
        preg_match_all("(ip: \[b\]([^\[]*))", $server['info'], $iped); //"(([^[\];])])"
        foreach($iped[1] as $ip){            
            if ($forum_config['o_censoring'] == '1')
                $server['name'] = censor_words($server['name']);
            echo '<tr><td>' . $server['game'] . "\t </td><td> " .$server['name'] ."\t </td><td> " . $ip . "</td></tr>\n";
        }
    }
    echo "</table>\n";
}
function output_servers_html($servers) {

    global $forum_config;

    echo "<table><tr><th>M2ng</th><th>Nimi</th><th>ip:port</th></tr>\n";
    foreach ($servers as $server)
    {
        preg_match_all("(ip: \[b\]([^\[]*))", $server['info'], $iped); //"(([^[\];])])"
        foreach($iped[1] as $ip){            
            if ($forum_config['o_censoring'] == '1')
                $server['name'] = censor_words($server['name']);
            echo '<tr><td>' . $server['game'] . "\t </td><td> " .$server['name'] ."\t </td><td> " . $ip . "</td></tr>\n";
        }
    }
    echo "</table>\n";
}
function output_servers_raw($servers) {

    global $forum_config;

    foreach ($servers as $server)
    {
        preg_match_all("(ip: \[b\]([^\[]*))", $server['info'], $iped); //"(([^[\];])])"
        foreach($iped[1] as $ip){            
            if ($forum_config['o_censoring'] == '1')
                $server['name'] = censor_words($server['name']);
            echo $server['game'].';'.$ip."\n";
        }
    }
}
]]></hook>
        <hook id="ex_new_action"><![CDATA[
//
// server list from toppics
//
else if ($_GET['action'] == 'servers') {

    $type = 'html';
    if (isset($_GET['type']) && is_scalar($_GET['type']))
    {
        if (strtolower($_GET['type']) == 'raw')
            $type = 'raw';
    }
    
    $forum_sql = '';

    // Was any specific forum ID's supplied?
    if (isset($_GET['fid']) && $_GET['fid'] != '')
    {
        $fids = explode(',', trim($_GET['fid']));
        $fids = array_map('intval', $fids);
        
        if (!empty($fids))
            $forum_sql = ' AND t.forum_id IN('.implode(',', $fids).')';
    }

    // Teemade nimed ja pealkirjad ja id'd
    $result = $forum_db->query('
        SELECT t.subject as name,  p.message as info, t.forum_id as game FROM '.$forum_db->prefix.'topics AS t 
        INNER JOIN '.$forum_db->prefix.'posts AS p ON p.topic_id=t.id  
        WHERE p.id = (SELECT id as a FROM '.$forum_db->prefix.'posts WHERE topic_id=t.id ORDER BY a ASC LIMIT 1)
        '.$forum_sql.' ORDER BY game, name DESC') or error('Serverite nimekirja ei saanud, sest '.print_r($forum_db->error(),1), __FILE__, __LINE__, $forum_db->error());

    if (!$forum_db->num_rows($result))
        exit($lang_common['Bad request']);
    while ($servers[] = $forum_db->fetch_assoc($result));

    $output_func = 'output_servers_'.$type;
    $output_func($servers);
    return;
}

]]></hook>
</hooks>
</extension>

And i have tried to put the code next to hooks, then it worked fine hmm

Re: Problems with getting modification to work as an extension

Looks OK (though your SQL is very strange).
What SVN revision do you use?

(BTW, there is no RC2 yet)

Carpe diem

3 (edited by ingram 2008-11-02 07:38)

Re: Problems with getting modification to work as an extension

I met the author if this extension and he helped me with some small changes. like removing else from else if and changing return; to exit;