Skip to:
Content
Pages
Categories
Search
Top
Bottom

Color text in status updates


  • daltontastic
    Participant

    @daltontastic

    I found this code online, and I would like to use it in my BuddyPress installation.

    
        <?php
        function MineToWeb($minetext){
        preg_match_all("/[^§&]*[^§&]|[§&][0-9a-z][^§&]*/", $minetext, $brokenupstrings);
        $returnstring = "";
        foreach ($brokenupstrings as $results){
        $ending = '';
        foreach ($results as $individual){
        $code = preg_split("/[&§][0-9a-z]/", $individual);
        preg_match("/[&§][0-9a-z]/", $individual, $prefix);
        if (isset($prefix[0])){
        $actualcode = substr($prefix[0], 1);
        switch ($actualcode){
        case "1":
        $returnstring = $returnstring.'<FONT COLOR="0000AA">';
        $ending = $ending ."</FONT>";
        break;
        case "2":
        $returnstring = $returnstring.'<FONT COLOR="00AA00">';
        $ending =$ending ."</FONT>";
        break;
        case "3":
        $returnstring = $returnstring.'<FONT COLOR="00AAAA">';
        $ending = $ending ."</FONT>";
        break;
        case "4":
        $returnstring = $returnstring.'<FONT COLOR="AA0000">';
        $ending =$ending ."</FONT>";
        break;
        case "5":
        $returnstring = $returnstring.'<FONT COLOR="AA00AA">';
        $ending =$ending . "</FONT>";
        break;
        case "6":
        $returnstring = $returnstring.'<FONT COLOR="FFAA00">';
        $ending =$ending ."</FONT>";
        break;
        case "7":
        $returnstring = $returnstring.'<FONT COLOR="AAAAAA">';
        $ending = $ending ."</FONT>";
        break;
        case "8":
        $returnstring = $returnstring.'<FONT COLOR="555555">';
        $ending =$ending ."</FONT>";
        break;
        case "9":
        $returnstring = $returnstring.'<FONT COLOR="5555FF">';
        $ending =$ending . "</FONT>";
        break;
        case "a":
        $returnstring = $returnstring.'<FONT COLOR="55FF55">';
        $ending =$ending ."</FONT>";
        break;
        case "b":
        $returnstring = $returnstring.'<FONT COLOR="55FFFF">';
        $ending = $ending ."</FONT>";
        break;
        case "c":
        $returnstring = $returnstring.'<FONT COLOR="FF5555">';
        $ending =$ending ."</FONT>";
        break;
        case "d":
        $returnstring = $returnstring.'<FONT COLOR="FF55FF">';
        $ending =$ending ."</FONT>";
        break;
        case "e":
        $returnstring = $returnstring.'<FONT COLOR="FFFF55">';
        $ending = $ending ."</FONT>";
        break;
        case "f":
        $returnstring = $returnstring.'<FONT COLOR="FFFFFF">';
        $ending =$ending ."</FONT>";
        break;
        case "l":
        if (strlen($individual)>2){
        $returnstring = $returnstring.'<span style="font-weight:bold;">';
        $ending = "</span>".$ending;
        break;
        }
        case "m":
        if (strlen($individual)>2){
        $returnstring = $returnstring.'<strike>';
        $ending = "</strike>".$ending;
        break;
        }
        case "n":
        if (strlen($individual)>2){
        $returnstring = $returnstring.'<span style="text-decoration: underline;">';
        $ending = "</span>".$ending;
        break;
        }
        case "o":
        if (strlen($individual)>2){
        $returnstring = $returnstring.'<i>';
        $ending ="</i>".$ending;
        break;
        }
        case "r":
        $returnstring = $returnstring.$ending;
        $ending = '';
        break;
        }
        if (isset($code[1])){
        $returnstring = $returnstring.$code[1];
        if (isset($ending)&&strlen($individual)>2){
        $returnstring = $returnstring.$ending;
        $ending = '';
        }
        }
        }
        else{
        $returnstring = $returnstring.$individual;
        }
        
        }
        }
        
        return $returnstring;
        }
        ?>

    I run a Minecraft themed social networking site so I thought it would be a cool idea to integrate this function into status updates (Minecraft Wiki).

    In theory people will post:

    §4This is red text and it’ll get saved as is in the database, but it will show in color in activity feeds.

    The thing is that BuddyPress blocks font tags in status updates.

    I’m going to share with you some different techniques I tried:

    I went inside activity/entry.php and inputted the function at the top of the file, and then I replaced

    <?php bp_activity_content_body(); ?>

    With:

    <?php MineToWeb(bp_activity_content_body); ?>

    That was a no go.

    I also tried editing bp-activity/bp-activity-functions.php but there is so many references in the file and I’m not even entirely sure where to look. All I accomplished with editing this file is that it strips the § from the status update before submitting it to the database (which is the complete opposite of what I want), and it doesn’t make it colorful.

    Anybody familiar with BuddyPress? Wanna lend me a hand? Thanks a bunch.

  • You must be logged in to reply to this topic.
Skip to toolbar