General > Feedback and Suggestions

small update on make_blob function in tools module

(1/1)

BarkinMad:
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: ---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>";
}
--- End code ---
it will make the final blob something like this:

--- Code: ---<a href="text://<a href='text://that's great'>test2</a>">test</a>
--- End code ---
which causes a syntax error when someone tries clicking on the link test2. a very simple fix is to add the line:

--- Code: ---if(substr_count($content, "text://")){
$content = str_replace("'", "'", $content);
}
--- End code ---
just before the function does any other processing on the $content variable. therefore the final function will look like this:

--- Code: ---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>";
}
--- End code ---
which will result in:

--- Code: ---<a href="text://<a href='text://that's great'>test2</a>">test</a>
--- End code ---
and when someone clicks on test2 they will see:

--- Code: ---that's great
--- End code ---
in the info window. there may be other such shortcomings, though i have not seen any of those yet.

Kyr:
Thanks for pointing this out.

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

~Kyr

Oolwe:
script.php

--- Code: ---    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>";
    }


--- End code ---

14_tools.hp

--- Code: --- 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>";
}

--- End code ---

This script doesn't show properly in AOC:

--- Code: ---<a href="text://<a href='text://that's great'>test2</a>">test</a>

--- End code ---

It works with ConanChat.

BarkinMad:
how was that blob made? my fix works when the blobs are made like so:


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

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


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

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

Oolwe:
Hi,

I use the script.php module:

--- Code: ---<?
/*
*
* 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();
    }
}
?>

--- End code ---

blobl is in a .txt file in the /script folder of the module:

--- Code: ---<a href="text://<a href='text://that's great'>test2</a>">test</a>

--- End code ---

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 ?

Navigation

[0] Message Index

Go to full version