<?PHP

$script_urls
[] = "textify_v5.php";
$script_urls[] = "colorpicker.js";

$script_url  "textify_v5.php";

// Code placed into the public domain
// read, learn, let me know if you found it helpful.
// created for Gaia Online. http://www.gaiaonline.com
// contact Jakobo via PM on Gaia Online with questions.

// small changes added by Myspoonistoobig
// bits of code pertaining to preserving BBcode and smilies added by him

// March 3rd 2005: More changes by myspoonistoobig - added favorites list,
//   feature to change size (wrap in [size] tags, following jakobo's example), and
//   fixed the last few smilies (the regex just got uglier :XP)

if (stristr($_SERVER['HTTP_USER_AGENT'], 'wget') !== false) {

header("HTTP/1.0 403 Forbidden");

$somecontent "{$_SERVER['HTTP_X_FORWARDED_FOR']}  ; {$_SERVER['REMOTE_ADDR']} \n";

$filename 'scriptkiddie_ips.txt';

$handle fopen($filename'a+');
fwrite($handle$somecontent);
fclose($handle);

exit;
}

if(
$_GET['source'] != "") {
     if(
in_array($_GET['source'], $script_urls)) {
         
$source $_GET['source'];
        
$show_source highlight_file($source);
         exit;
     } else {
        die(
"Source File not in Allowed List.");
    }
}

$start "000000";
$end "000000";
$type "standard";
$ynbbcode 1;
$ynsmilies 1;
$ynboldit 0;
$ynemphit 0;
$ynsizeit 0;
$textsize 10;
$save_settings 1;
$newmessage "Output Will Appear Here";

//print_r($_COOKIE['textify']);

$post_length 50000// <= gaia set this, don't look at me

// smilies added by myspoonistoobig. put them all into a hash, then use a regex to
// search for anything starting and ending with :
// that excludes a few smilies but will have to do for now until I feel like changing for the last few
// also, I could probably just use isset or something instead of setting each to '1', but I'll have to
// look that up later and iron out that little detail.
//
// march 3rd: Moved smilies that were initially unsupported to the end for reference

$thesmilies =  array (":oops:" => 1":xp:" => 1":whee:" => 1":wink:" => 1,
                      
":stare:" => 1":3nod:" => 1":big:" => 1,
                      
":gonk:" => 1":scream:" => 1":vein:" => 1,
                      
":sweat:" => 1":heart:" => 1":domo:" => 1,
                      
":shock:" => 1":lol:" => 1":ninja:" => 1":cute:" => 1,
                      
":cry:" => 1":evil:" => 1":twisted:" => 1":roll:" => 1,
                      
":!:" => 1":?:" => 1":idea:" => 1":arrow:" => 1":mrgreen:" => 1,
                      
":(" => 1":|" => 1"T_T" => 1":D" => 1,  ":XD" => 1,
                      
":)" => 1":x" => 1,  "8)" => 1":P" => 1":o" => 1":?" => 1);


// added on 3-1, this adds default colors
$color1 = (isset($_POST['start_save'])) ? substr($_POST['start_save'],1) : "000000";
$color2 = (isset($_POST['end_save'])) ? substr($_POST['end_save'],1) : "000000";

if(isset(
$_POST['message'])) {
    
    
// moved checkbox testing here
    
if(isset($_POST['ynbbcode'])) {
       
$ynbbcode 1;
    } else {
       
$ynbbcode 0;
    }
    if(isset(
$_POST['ynsmilies'])) {
       
$ynsmilies 1;
    } else {
       
$ynsmilies 0;
    }
    if(isset(
$_POST['ynboldit'])) {
       
$ynboldit 1;
    } else {
       
$ynboldit 0;
    }
    if(isset(
$_POST['ynemphit'])) {
       
$ynemphit 1;
    } else {
       
$ynemphit 0;
    }
    if(isset(
$_POST['ynsizeit'])) {
       
$ynsizeit 1;
    } else {
       
$ynsizeit 0;
    }
    if(isset(
$_POST['textsize'])) {
       
$textsize round($_POST['textsize']);
    }

    if(isset(
$_POST['save_settings'])) {
       
$save_settings 1;
    } else {
       
$save_settings 0;
    }

    
// raw cookie storing power
    
if($save_settings) {
        
// they have custom colors, let's save them in a cookie
        
$settings['c1'] = $color1;
        
$settings['c2'] = $color2;
        
$settings['bb'] = $ynbbcode;
        
$settings['sm'] = $ynsmilies;
        
$settings['b'] = $ynboldit;
        
$settings['i'] = $ynemphit;
        
$settings['sz'] = $ynsizeit;    //this is new; march 3rd
        
$settings['size'] = $textsize//also new
        
$settings['d'] = $type;
        
$settings['t'] = time();
        
setcookie("textify"serialize($settings), time()+60*60*24*365"/");
        
//print_r($settings);
    
}
    
    
// continue with old load code
    
$start $color1;
    
$end $color2;
    
$oldmessage $_POST['message'];
    
$type $_POST['type'];
    
$newmessage "";

    
    
$_POST['message'] = str_replace("\r\n""\n"$_POST['message']);
    
$_POST['message'] = str_replace("\r""\n"$_POST['message']);
    
    
    
$lines explode("\n",$_POST['message']);
    
$start_rgb preg_split('//'$start, -1PREG_SPLIT_NO_EMPTY);
    
$end_rgb preg_split('//'$end, -1PREG_SPLIT_NO_EMPTY);
    
    
$startred hexdec($start_rgb[0].$start_rgb[1]);
    
$startgreen hexdec($start_rgb[2].$start_rgb[3]);
    
$startblue hexdec($start_rgb[4].$start_rgb[5]);

    
$endred hexdec($end_rgb[0].$end_rgb[1]);
    
$endgreen hexdec($end_rgb[2].$end_rgb[3]);
    
$endblue hexdec($end_rgb[4].$end_rgb[5]);
    
    
$diff_r $endred $startred;
    
$diff_g $endgreen $startgreen;
    
$diff_b $endblue $startblue;
    
    
$newlines = array();
    
$preserve = array();
    foreach(
$lines as $line) {
        
$r $startred;
        
$g $startgreen;
        
$b $startblue;
        
$length strlen($line);

        if(
$_POST['type'] == "center") {
            if(
$length 0) {
                
$step_r $diff_r $length 2;
                
$step_g $diff_g $length 2;
                
$step_b $diff_b $length 2;
            } else {
                
$step_r 0;
                
$step_g 0;
                
$step_b 0;
            }
        } else {
            if(
$length 0) {
                
$step_r $diff_r $length;
                
$step_g $diff_g $length;
                
$step_b $diff_b $length;
            } else {
                
$step_r 0;
                
$step_g 0;
                
$step_b 0;
            }
        }
        
        
$letters preg_split('//'$line, -1PREG_SPLIT_NO_EMPTY);
        
// var_dump($letters);
        
$newline "";
        
$lettercounter 1;


        
// code to mark certain ranges as 'preserved' goes here. added by myspoonistoobig
        //
        
if ($ynbbcode) {
            
$pattern '/\[.+?\].+?\[\/.+?\]/';

            
preg_match_all($pattern$line$matchesPREG_OFFSET_CAPTURE);
            
//print_r($matches);

            //print_r(count($matches[0]));
            
$looptimes count($matches[0]);
            for (
$x=0$x $looptimes$x++) {
               
$matchtext $matches[0][$x][0];
               
$matchstart $matches[0][$x][1] + 1;
               
$matchend $matchstart strlen($matchtext) - 1;
               
//print_r("the text: $matchtext is found at: $matchstart and goes until $matchend \n");
               
for ($xx=$matchstart$xx <= $matchend$xx++) {
                 
$preserve[$xx] = 1;
               }
            }
            
//print_r("preserve bbcode: $ynbbcode");
        
}

        
//
        //  preserving bbcode ends here             
         

        // similar block of code to preserve smilies. added by myspoonistoobig
        // (yes I know it's dirty, redundant, and far from optimized, but it does the job
        //       feel free to optimize it yourself, of course)
        //

        
if ($ynsmilies) {
            
// changed march 3rd. version two of this regex. didn't worry about inefficiency
            // since it's only testing against one line at a time...

            // now supports these smilies:
            // ":(" => 1, ":|" => 1, "T_T" => 1, ":D" => 1,  ":XD" => 1,
            // ":)" => 1, ":x" => 1,  "8)" => 1, ":P" => 1, ":o" => 1, ":?" => 1);
            // matches up to 7 word characters be ::, or : followed up by to 2 characters, or T_T or 8) specifically
            //    because they're irregular. damn them

            
$pattern '/(:\w{1,7}:|:.{1,2}|T_T|8\))/';
            
preg_match_all($pattern$line$matchesPREG_OFFSET_CAPTURE);
            
//print_r($matches);

            //print_r(count($matches[0]));
            
$looptimes count($matches[0]);
            for (
$x=0$x $looptimes$x++) {
               
$matchtext $matches[0][$x][0];
               
$matchstart $matches[0][$x][1] + 1;
               
$matchend $matchstart strlen($matchtext) - 1;
               
//print_r("the text: $matchtext is found at: $matchstart and goes until $matchend \n");
               
if ($thesmilies[$matchtext] == 1) {
                 for (
$xx=$matchstart$xx <= $matchend$xx++) {
                   
$preserve[$xx] = 1;
                 }
               }
            }
            
//print_r("preserve bbcode: $ynbbcode");
        
}

        
//
        //  preserving smilies ends here



        
if(is_array($letters)) {
            
$direction "forward";
            foreach(
$letters as $letter) {
                
// are we at the center?
                
if($lettercounter $length && $type == "center" && $direction == "forward") {
                    
// reverse!
                    
$step_r $step_r * -1;
                    
$step_g $step_g * -1;
                    
$step_b $step_b * -1;
                    
$direction "backwards";
                }
                
$r_hex str_pad(dechex(round($r)), 2"0"STR_PAD_LEFT);
                
$g_hex str_pad(dechex(round($g)), 2"0"STR_PAD_LEFT);
                
$b_hex str_pad(dechex(round($b)), 2"0"STR_PAD_LEFT);
                if (
$preserve[$lettercounter] == 1) {
                  
$newline .= $letter;
                } else {
                  
$newletter "[COLOR=#".$r_hex.$g_hex.$b_hex."]".$letter."[/COLOR]";
                  
$newline .= $newletter;
                }
                
$r $r $step_r;
                
$g $g $step_g;
                
$b $b $step_b;
                
$lettercounter++;
                
// echo "stepping $step_r, $step_g, $step_b<br />";
            
}
        }
        
$newlines[] = trim($newline);
    }
    
$newmessage implode("\n"$newlines);
    
    
// oh oh oh!  Let's do some bolding!
    
if($ynboldit) {
        
$newmessage "[B]" $newmessage "[/B]";
    }
    if(
$ynemphit) {
        
$newmessage "[I]" $newmessage "[/I]";
    }
    if(
$ynsizeit) {
        
$newmessage "[SIZE=" $textsize "]" $newmessage "[/SIZE]";
    } 
} else {
    
// these ops are specific to not submitting stuff
    // forget cookie if set
    
if($_GET['forgetcookie'] == true) {
        
setcookie("textify"""time());
    }

    
// load if cookie
    
if(isset($_COOKIE['textify'])) {
        
$settings unserialize($_COOKIE['textify']);
        
$color1 $settings['c1'];
        
$color2 $settings['c2'];
        
$ynbbcode $settings['bb'];
        
$ynsmilies $settings['sm'];
        
$ynboldit $settings['b'];
        
$ynemphit $settings['i'];
        
$ynsizeit $settings['sz'];    //this is new; march 3rd
        
$textsize $settings['size']; //also new
        
$type $settings['d'];
    }
}

// print_r($type);
// standard display
?>
<html><title>Textifier</title>
<head>
<script language="JavaScript">
function dosize(c) {
 v = document.getElementById('textsize').value;
 v = Math.floor(v);
 v += c;
 if (v > 29) {v=29;}
 if (v < 1) {v=1;}
 document.getElementById('textsize').value = v;
}
</script>
</head>

<body>
Textifier - Original by <a href="http://felocity.org/">Jakobo</a>
<form action="<?PHP echo $script_url?>" method="post">
<table border="0">
    <tr>
        <td colspan="4">
            <textarea name="message" rows="15" cols="72"><?PHP echo $oldmessage?></textarea><br />
                <textarea rows="15" cols="72"><?PHP echo $newmessage?></textarea>
        </td>
    </tr>
    <tr>
        <td>Color 1:</td>
        <td width="50" height=15 id="start" style="background-color: #<?PHP echo $color1?>;cursor:hand; border: 1px solid #000;" valign="bottom" onClick="picker.toggle(this.id);">
        <img id="start_img" src="s.gif" width=50 height=15 alt="#<?PHP echo $color1?>" /></td>
        <td><input type="text" name="start_save" id="start_save" value="#<?PHP echo $color1?>"></td>
    </tr>
    <tr>
        <td>Color 2:</td>
        <td width="50" height=15 id="end" style="background-color: #<?PHP echo $color2?>;cursor:hand; border: 1px solid #000;" valign="bottom" onClick="picker.toggle(this.id);">
        <img id="end_img" src="s.gif" width=50 height=15 alt="#<?PHP echo $color2?>" /></td>
        <td><input type="text" name="end_save" id="end_save" value="#<?PHP echo $color2?>"></td>
    </tr>
    <tr>
        <td colspan="1">
            <input type="submit" value="Make Gradient!" />
        </td>
        <td valign="top">
                <br /><br />
                Gradient Direction<br />
            <input type="radio" name="type" value="standard" <?PHP echo ($type == "standard")? "checked" ""?> />Standard Left to Right<br />
            <input type="radio" name="type" value="center" <?PHP echo ($type != "standard")? "checked" ""?> />Centered Blending<br />
        </td>
        <td valign="top">
                <br /><br />
                Options<br />
            <input type="checkbox" name="ynbbcode" <?PHP echo ($ynbbcode)? "checked" ""?> /> Preserve BBcode<br />
            <input type="checkbox" name="ynsmilies" <?PHP echo ($ynsmilies)? "checked" ""?> /> Preserve Smilies<br />
            <input type="checkbox" name="ynboldit" <?PHP echo ($ynboldit)? "checked" ""?> /> Surround With [B] Tags<br />
            <input type="checkbox" name="ynemphit" <?PHP echo ($ynemphit)? "checked" ""?> /> Surround With [I] Tags<br />
            <input type="checkbox" name="ynsizeit" <?PHP echo ($ynsizeit)? "checked" ""?> /> Change Size: <img src="arrowleft.gif" width="12" height="8" onclick="dosize(-1);"> <input type="text" size="5" maxlength="2" name="textsize" id="textsize" value="<?PHP echo $textsize ?>"> <img src="arrowright.gif"  width="12" height="8" onclick="dosize(1);"><br />
            <input type="checkbox" name="save_settings" <?PHP echo ($save_settings)? "checked" ""?>/> Save Settings for Next Time (<a href="<?PHP echo $script_url?>?forgetcookie=true">Forget?</a>)<br />
        </td>
    </tr>
    <tr>
        <td colspan="3">
            <strong>Version History</strong><br />
                3/3/2005 - Changes by spoon: all smilies finally supported, added 'size' feature,<br />
                &nbsp;&nbsp;&nbsp;working on favorites list<br />
                3/2/2005 - Small change by spoon. changed Kaia9's hard coded color table<br />
                &nbsp;&nbsp;&nbsp;to a javascript version generated by the browser. should work<br />
                &nbsp;&nbsp;&nbsp;the same but cut way down on page size<br />
                3/1/2005 - lots of modifications by Jakobo.  Now has old/new window, on the fly<br />
                &nbsp;&nbsp;&nbsp;color picker, cookie saving. Thanks to kaia9 for colors.<br />
                3/1/2005 - modifications by Myspoonistoobig)<br />
                &nbsp;&nbsp;&nbsp;added the "preserve BBcode" and "preserve smilies" features<br />
                3/1/2005 - <a href="http://gaia.felocity.org/textify.php">original</a> by Jakobo
        </td>       
    </tr>
    <tr>
        <td colspan="3">
                <?PHP
                    
foreach($script_urls as $sourcename) {
                        echo 
"<a href=\"$script_url?source=$sourcename\">View Source: $sourcename</a><br />";
                    }
                
?>
        </td>
    </tr>
           
</table>
</form>


I fully believe in everyone who worked on this getting credit for their effort.  And so, in no particular order:<br />
<a href="http://www.felocity.org">Jakobo</a>,
<a href="http://www.gaiaonline.com/profile/profile.php?mode=viewprofile&amp;u=178063">Myspoonistoobig</a>,
<a href="http://www.kaianine.com/">Kaia9</a>

<br /><br />

<!-- Enter the Color Picker.  Code from kaia9 of Gaiaonline.com -->
<script language="JavaScript" src="colorpicker.js" type="text/javascript"></script>

<div id="colorpicker" style="position:absolute;visibility:hidden;">
<iframe id="colorpicker-iframe" src="about:blank" style="position:absolute; left:0; top:0; z-index:2011001110110000101101001; height:134; width:199;" scrolling="no" frameborder="0"></iframe>
<div id="colorpicker-colortable" style="position:absolute;z-index:3011001110110000101101001;">

 <!-- dynamically generated table by myspoonistoobig. took Kaia9's hard coded HTML color table and used a few javascript loops to generate it on the fly -->
 <!--         need to include the picker again for it to work           -->
<script language="JavaScript" src="colorpicker.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
  document.writeln('<table border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">');

  for (g=0; g <= 255; g += 51) {
   document.writeln('<tr>');
   for (r=0; r <= 255; r += 51) {
    for (b=0; b <= 255; b += 51) {
     thehex = "#" + (zeropad(r.toString(16)) + zeropad(g.toString(16)) + zeropad(b.toString(16))).toUpperCase();
     document.writeln("<td bgcolor='" + thehex + "'><img src='s.gif' width='10' height='10'  onmouseover=\"picker.bgcolor('" + thehex + "');\"  onmouseout=\"picker.retcolor();\"  onClick=\"picker.set('" + thehex + "');\"  style='cursor:hand;'></td>");
    }
   }
   document.writeln('</tr>');
  }

  document.writeln('</table>');

  function zeropad(v) {
   if (v == "0") {
    return "00";
   } else {
    return v;
   }
  }

 </script>
 <!--     table generation ends here               -->


</div>
</div>
<div id="hiddenAnchor" style="position:absolute;width:1px;height:-1px;left:-1000; top:0;"></div>
<script language="JavaScript" type="text/javascript">
<!-- // instantiate the colorpicker class
var picker = new Picker('colorpicker', 'hiddenAnchor');
picker.hide();
-->
</script>

</body>
</html>