collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18366
  • stats Total Topics: 2501
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: small update on make_blob function in tools module  (Read 10355 times)

0 Members and 1 Guest are viewing this topic.

Offline BarkinMad

  • BeBot Rookie
  • *
  • Posts: 6
  • Karma: +0/-0
small update on make_blob function in tools module
« on: September 05, 2011, 12:03:59 am »
Hi there, i found a logic error in the make_blob() function of the bot, that is apt to cause syntax errors if not fixed. it is the function's handling of \' chars when you have a blob within a blob. as the function is atm:

Code: [Select]
function make_blob($title, $content)
{
// Using " inside a blob will end the blob.
// Convert opening and closing tags with " to '
// Convert any other " to HTML entities.
$content = str_replace("=\"", "='", $content);
$content = str_replace("\">", "'>", $content);
$content = str_replace("\"", """, $content);

return "<a href=\"text://" . $content . "\">" . $title . "</a>";
}
it will make the final blob something like this:
Code: [Select]
<a href="text://<a href='text://that's great'>test2</a>">test</a>which causes a syntax error when someone tries clicking on the link test2. a very simple fix is to add the line:
Code: [Select]
if(substr_count($content, "text://")){
$content = str_replace("'", "'", $content);
}
just before the function does any other processing on the $content variable. therefore the final function will look like this:
Code: [Select]
function make_blob($title, $content)
{
// Using " inside a blob will end the blob.
// Convert opening and closing tags with " to '
// Convert any other " to HTML entities.

                if(substr_count($content, "text://")){
$content = str_replace("'", "'", $content);
}

$content = str_replace("=\"", "='", $content);
$content = str_replace("\">", "'>", $content);
$content = str_replace("\"", "&quot;", $content);

return "<a href=\"text://" . $content . "\">" . $title . "</a>";
}
which will result in:
Code: [Select]
<a href="text://<a href='text://that's great'>test2</a>">test</a>and when someone clicks on test2 they will see:
Code: [Select]
that's greatin the info window. there may be other such shortcomings, though i have not seen any of those yet.
« Last Edit: September 05, 2011, 02:59:27 am by BarkinMad »

Offline Kyr

  • BeBot Apprentice
  • ***
  • Posts: 177
  • Karma: +0/-0
Re: small update on make_blob function in tools module
« Reply #1 on: September 06, 2011, 11:37:34 pm »
Thanks for pointing this out.

I think a similar change should be made to the make_blob function in the scripts module.

~Kyr

Offline Oolwe

  • BeBot User
  • **
  • Posts: 47
  • Karma: +0/-0
Re: small update on make_blob function in tools module
« Reply #2 on: September 08, 2011, 08:39:38 am »
script.php
Code: [Select]
    function make_blob($title, $content, $specialtag="")
    {
// Using " inside a blob will end the blob.
// Convert opening and closing tags with " to '
// Convert any other " to HTML entities.

// fix ajouté
    if(substr_count($content, "text://")){
$content = str_replace("'", "'", $content);
}
$content = str_replace("=\"", "='", $content);
$content = str_replace("\">", "'>", $content);
$content = str_replace("\"", "&quot;", $content);
if ($specialtag == "")
    return "<a href=\"text://" . $content . "\">" . $title . "</a>";
else
    return "<a " . $specialtag . " href=\"text://" . $content . "\">" . $title . "</a>";
    }


14_tools.hp
Code: [Select]
function make_blob($title, $content)
{
// Using " inside a blob will end the blob.
// Convert opening and closing tags with " to '
// Convert any other " to HTML entities.
        if(substr_count($content, "text://")){
$content = str_replace("'", "'", $content);
}
$content = str_replace("=\"", "='", $content);
$content = str_replace("\">", "'>", $content);
$content = str_replace("\"", "&quot;", $content);

return "<a href=\"text://" . $content . "\">" . $title . "</a>";
}

This script doesn't show properly in AOC:
Code: [Select]
<a href="text://<a href='text://that's great'>test2</a>">test</a>

It works with ConanChat.

Offline BarkinMad

  • BeBot Rookie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: small update on make_blob function in tools module
« Reply #3 on: September 11, 2011, 10:48:18 pm »
how was that blob made? my fix works when the blobs are made like so:

Code: [Select]
$innerblob = $this->bot->core("tools")->make_blob("test2", "that's great");
$outerblob = $this->bot->core("tools")->make_blob("test", $innerblob);

but yes, there WOULD be an issue if the blob was made like so:

Code: [Select]
$innerblob = "<a href='text://that's great'>test2</a>";
$outerblob = $this->bot->core("tools")->make_blob("test", $innerblob);

this is because make_blob by default makes the blobs as <a href="text://yaddayadda">title</a>, then when THAT is passed on to it, it switches =" with =' and "> with '>

yes, my fix is far from perfect, but then, we're trying to automate human reasoning here

Offline Oolwe

  • BeBot User
  • **
  • Posts: 47
  • Karma: +0/-0
Re: small update on make_blob function in tools module
« Reply #4 on: September 13, 2011, 09:06:13 am »
Hi,

I use the script.php module:
Code: [Select]
<?
/*
*
* Display Scripts for APF Sectors.
* Based on Rules_Raid.php by Blondengy
* By Andrew Zbikowski <[email protected]> (AKA Glarawyn, RK1)
* Version 1.0.1
* Converted to script module by Kelmino <[email protected]>
* 03/18/10 - Kyr Updated with some new features
*
* Version 2 script help
* script must start exactly with the text:
* //-- script ver 2 --//
* If it doesn't the script doesn't start with that the module will read it as the old format and that won't work.

* Lines can start with these tags (always 8 characters):
* BEFOREH-
* HLINK---
* AFTERH--
* SPECIAL-
* BODY----
*
* The special tag is for adding text that’s not the href in the a tag
*
* The only thing I need that for so far is:
* style='text-decoration:none'
*
* There can only be one of each type of line. 
* The order of the tags is not significant, but I suggest the body tag always come last.
*
*/

$Scripts = new Scripts($bot);

/*
The Class itself...
*/
class Scripts Extends BaseActiveModule
{
    var $bot;

    /*
    Constructor:
    Hands over a referance to the "Bot" class.
    */
    function __construct (&$bot)
    {
        parent::__construct(&$bot, get_class($this));

        $this -> register_command('all', 'scripts', 'GUEST');
        $this -> register_command('all', 'script', 'GUEST');

        $this -> help['description'] = 'Affiche des scripts.';
        $this -> help['command']['scripts'] = 'Affiche la liste de tous les scripts disponible.';
        $this -> help['command']['script <nom>'] = 'Affiche le script spécifié.';
    }

    /*
        This function handles all the inputs and returns output
        sutible for send_tell, send_pgroup, and send_gc.
    */
    function command_handler($name, $msg, $origin)
    {
        $this->error->reset(); //Reset the error message so we don't trigger the handler by old error messages.

        $com = $this->parse_com($msg, array('com', 'args', 'error'));

        if(empty($com['args']))
            return $this -> make_list();
        else if(empty($com['error']))
            return $this -> make_script($com['args']);

        return "Commande inconnue, voici la liste des scripts: " . $this -> make_list();
    }

    /*
    Makes the list of scripts
    */
    function make_list()
   
    {
        if(false !== ($handle = @fopen("scripts/script.lst", "r")))
        {
            $content = fread($handle, filesize("scripts/script.lst"));
            fclose($handle);
            return "Liste des Scripts :: " . $this -> bot -> core("tools") -> make_blob("<IMG SRC=rdb://791043>Afficher", $content);
        }

        return ":: Aucun Script disponible sur le serveur.";
    }
   
    function make_blob($title, $content, $specialtag="")
    {
// Using " inside a blob will end the blob.
// Convert opening and closing tags with " to '
// Convert any other " to HTML entities.

// fix ajouté posté ici: http://bebot.link/feedback-and-suggestions/small-update-on-make_blob-function-in-tools-module/msg17708/?topicseen#new
    if(substr_count($content, "text://")){
$content = str_replace("'", "'", $content);
}
// fin du fix
$content = str_replace("=\"", "='", $content);
$content = str_replace("\">", "'>", $content);
$content = str_replace("\"", "&quot;", $content);
if ($specialtag == "")
    return "<a href=\"text://" . $content . "\">" . $title . "</a>";
else
    return "<a " . $specialtag . " href=\"text://" . $content . "\">" . $title . "</a>";
    }

    /*
    Make the Script
    */
    function make_script($script)
    {
        if(false !== ($handle = @fopen("scripts/".$script.".txt", "r")))
        {
            $content = fread($handle, filesize("scripts/".$script.".txt"));
            fclose($handle);           
           
            if (substr($content, 0, 22) != "//-- script ver 2 --//") {           
                $beforeh = "Script (".$script."):: ";
                $afterh = "";
                $hlink = "Afficher";
                $specialtag = "";
               
                //$this -> bot -> log('SCRIPTS', 'LOG', "Old script version used.".substr($content, 1, 22));
                $body = $content;
            }
            else
            {
                //$this -> bot -> log('SCRIPTS', 'LOG', "New script version used.");

                $file_parts = preg_split("(\r\n|\n\r|\r|\n)", $content);
               
                for ($i = count($file_parts) - 1; $i >= 0; $i--)
switch (substr($file_parts[$i], 0, 8)) {
    case "BEFOREH-":
$beforeh = substr($file_parts[$i], 8, strlen($file_parts[$i])-8);
                $this -> bot -> log('SCRIPTS', 'LOG', "beforeh = $beforeh");
break;
    case "HLINK---":
$hlink = substr($file_parts[$i], 8, strlen($file_parts[$i])-8);
                $this -> bot -> log('SCRIPTS', 'LOG', "hlink = $hlink");
break;
    case "AFTERH--":
$afterh = substr($file_parts[$i], 8, strlen($file_parts[$i])-8);
                $this -> bot -> log('SCRIPTS', 'LOG', "afterh = $afterh");
break;
    case "BODY----":
$body = substr($file_parts[$i], 8, strlen($file_parts[$i])-8);
                $this -> bot -> log('SCRIPTS', 'LOG', "body = $body");
break;
    case "SPECIAL-":
$specialtag = substr($file_parts[$i], 8, strlen($file_parts[$i])-8);
                $this -> bot -> log('SCRIPTS', 'LOG', "specialtag = $specialtag");
break;
}
            }           
return "" . $beforeh . " :: " . $this -> make_blob($hlink, $body, $specialtag) . " " . $afterh;
        }
        return "Script introuvable! - " . $this -> make_list();
    }
}
?>

blobl is in a .txt file in the /script folder of the module:
Code: [Select]
<a href="text://<a href='text://that's great'>test2</a>">test</a>

Kyr say it probably fix this limitation of script.php module but in fact no :'(

BarkinMad do you think there is a way to fix this pls ?

 

* Recent Posts
Com bot module by bitnykk
[November 25, 2024, 05:36:11 pm ]


0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm ]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am ]

* Who's Online
  • Dot Guests: 219
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal