DragonPrime - LoGD Resource Community
Welcome Guest
  • Good afternoon, Guest.
    Please log in, or register.
  • April 19, 2019, 01:17:47 PM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1]   Go Down
  Print  
Author Topic: appoencode  (Read 2914 times)
0 Members and 1 Guest are viewing this topic.
Eliwood
Member
Codemeister
****
Offline Offline

Posts: 278


View Profile WWW
« on: January 18, 2006, 09:24:38 AM »

Year.. I mean, the original function appoencode() is slower than "my" changed function.

So I save the Tags in an array:

Code:
$appoencode = array(
   '1'=>array(
      'id'=>'1',
      'code'=>'1',
      'color'=>'0000B0',
      'tag'=>'',
      'style'=>'',
      'allowed'=>'1',
   )
// [...]
        ,'b'=>array(
      'id'=>'44',
      'code'=>'b',
      'color'=>'',
      'tag'=>'strong',
      'style'=>'',
      'allowed'=>'0',
   ),
);

And now, my function appoencode is smaller:

Code:
function appoencode($data,$priv=false){
   global $nestedtags,$session,$appoencode;
   /* berarbeitet und verkleinert von Eliwood =D */
   $output = "";
   while( !(($x=strpos($data,"`")) === false) )
    {
        $tag=substr($data,$x+1,1);
        $append=substr($data,0,$x);
        $output.=($priv?$append:HTMLEntities($append));
        $data=substr($data,$x+2);
        if($tag == "0")
      {
        if ($nestedtags['color']) $output.="</span>";
          unset($nestedtags['color']);
      }
      elseif($tag == "`")
      {
        $output.="`";
      }
      else
        {
        if(isset($appoencode[$tag]))
        {
          $tagrow = $appoencode[$tag];
            if($tagrow['color'] == "")
          {
            if($nestedtags[$tagrow['tag']] && strchr($tagrow['tag']," /")==false)
            {
              $output.="</".$tagrow['tag'].">";
              unset($nestedtags[$tagrow['tag']]);
            }
            elseif(strchr($tagrow['tag']," /")==true) $output.="<".$tagrow['tag'].">\n";
            else
            {
              $output.="<".$tagrow['tag']." ".$tagrow['style'].">";
              $nestedtags[$tagrow['tag']] = true;
            }
          }
          else
          {
            if ($nestedtags['color']) $output.="</span>"; else $nestedtags['color']=true;
            $output.="<span style='color: #".$tagrow['color'].";'>";
          }
        }
        else $output.=$tag;
        }
    }
    if ($priv)
        $output.=$data;
     else
        $output.=HTMLEntities($data);
    return $output;
  }

And... I think it is faster, too.

For listening the Tags in e Regexp ( => sanitize & co), I use this function:

Code:
function Get_Allowed_Tags($sanitize="color")
{
  global $appoencode;
  reset($appoencode);
  while(list($key,$val) = each($appoencode))
  {
    switch($sanitize):
      case "color":
        if($val['allowed'] == 1) $list.=$val['code'];
        break;
      case "+":
        if($val['allowed'] == 1 XOR $val['allowed'] == 2) $list.=$val['code'];
        break;
      case "++":
        if($val['allowed'] == 1 || $val['allowed'] == 2 || $val['allowed'] == 3) $list.=$val['code'];
        break;
      endswitch;
  }
  return preg_quote($list);
}
(But it must be changed for support all sanitize-functions...)

EDIT:

Code:
function sanitize($in){
   // $out = preg_replace("/[`][1234567890!@#\$%^&)QqbicnHw]/", "", $in);
   $out = preg_replace("/[`][".get_allowed_tags("++")."]/","",$in);
   return $out;
}

function newline_sanitize($in){
   $out = preg_replace("/`n/", "", $in);
   return $out;
}

function color_sanitize($in){
   $out = preg_replace("/[`][1234567890!@#\$%^&)Qqbi]/", "", $in);
   $out = preg_replace("/[`][".get_allowed_tags("+")."]/", "", $in);
   return $out;
}

function comment_sanitize($in) {
   // to keep the regexp from boinging this, we need to make sure
   // that we're not replacing in with the ` mark.
   // $out=preg_replace("/[`](?=[^1234567890!@#\$%^&)Qq])/", chr(1).chr(1), $in);
   $out=preg_replace("/[`](?=[^".get_allowed_tags("color")."])/", chr(1).chr(1), $in);
   $out = str_replace(chr(1),"`",$out);
   return $out;
}
« Last Edit: January 18, 2006, 10:48:29 AM by Eliwood » Logged

Daenerys LotGD-Remake using PHP7 and a modern, headless approach.
XChrisX
Global Moderator
Mod God
*****
Offline Offline

Posts: 4647

Be aware of the squirrel!


View Profile WWW
« Reply #1 on: January 18, 2006, 10:17:15 AM »

I'm not sure about this, but $db->query() doesn't seem like a php4 function or an lotgd function...

Wink
Logged

Running for more than three years now:
Eliwood
Member
Codemeister
****
Offline Offline

Posts: 278


View Profile WWW
« Reply #2 on: January 18, 2006, 10:21:06 AM »

I'm not sure about this, but $db->query() doesn't seem like a php4 function or an lotgd function...

Wink

Yeahr... n-Word before are 2 " // *, and so, this row is a commentary... Wink
It can be deletet... It isn't relevant.
Logged

Daenerys LotGD-Remake using PHP7 and a modern, headless approach.
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Play LoGD on Dragonprime

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
98 Guests, 1 User
Smirnov
Home Forums News Downloads Login Register Advanced Search