<?php
// emojiicon.php
// RJM Programming
// March, 2025

$usuffix='';
$iponl='';
$rma='';
$ask='';

  function massage($inidea) {
   if (isset($_GET['ididea'])) {
     return str_replace("document.body", "document.getElementById('" . str_replace('+',' ',urldecode($_GET['ididea'])) . "')", $inidea);
   }
   return str_replace('(7 == 7)', '(56 == 67)',$inidea);
  }

  function server_remote_addr() {
    global $iponl, $rma;
    $rma = $_SERVER['REMOTE_ADDR'];
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    // you can add different browsers with the same way ..
    if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
            $rma = '000000'.$rma;
    elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
            $rma = '00000'.$rma;
    elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
            $rma = '0000'.$rma;
    elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
            $rma = '000'.$rma;
    elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
            $rma = '00'.$rma; 
    elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
            $rma = '0'.$rma;
    $rma=str_replace(':','_',$rma);
    $iponl=massage(" onload=\" if (window.parent) { if (parent.document.body.outerHTML.split('>')[0].indexOf(' data-ip=') == -1) { if (7 == 7) { parent.document.body.title=('' + parent.document.body.title) + ' +++ _" . $rma . "'; }  parent.document.body.setAttribute('data-ip', '_" . $rma . "');  } } \"");
    return $rma;
  }

  if (isset($_GET['mysvg'])) {
    $usuffix='_' . server_remote_addr();
    file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'emojiicon' . DIRECTORY_SEPARATOR . 'favicon' . $usuffix . '.svg', str_replace('   ',' + ',str_replace('+',' ',$_GET['mysvg'])));
    if ($iponl != '' && file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'emojiicon' . DIRECTORY_SEPARATOR . 'favicon_' . server_remote_addr() . '.svg')) {
      $iponl=massage(" onload=\" if (window.parent) { if (parent.document.body.outerHTML.split('>')[0].indexOf(' data-ip=') == -1) { parent.document.body.setAttribute('data-ip', '_" . $rma . "');  parent.document.body.setAttribute('data-firstip', 'y');  } } \"");
    }
  } else if (isset($_GET['codepoint'])) {
    if (strlen($_GET['codepoint']) > 0) {
     if (isset($_GET['ishex']) || isset($_GET['tohex']) || isset($_GET['hex'])) {
      $usuffix='_' . server_remote_addr();
      file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'emojiicon' . DIRECTORY_SEPARATOR . 'favicon' . $usuffix . '.svg', str_replace('&#x1f1e6;','&#127462;&#127465;','<svg xmlns="http://www.w3.org/2000/svg"><text y="32" font-size="32">&#x' . str_replace(',',';&#x',str_replace(';','',str_replace('&#','',str_replace('+',' ',urldecode($_GET['codepoint']))))) . ';</text></svg>'));
     } else {
      $usuffix='_' . server_remote_addr();
      file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'emojiicon' . DIRECTORY_SEPARATOR . 'favicon' . $usuffix . '.svg', '<svg xmlns="http://www.w3.org/2000/svg"><text y="32" font-size="32">&#' . str_replace(',',';&#',str_replace(';','',str_replace('&#','',str_replace('+',' ',urldecode($_GET['codepoint']))))) . ';</text></svg>');
     }
    } else if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'emojiicon' . DIRECTORY_SEPARATOR . 'favicon_' . server_remote_addr() . '.svg')) {
     $usuffix='_' . server_remote_addr();
    } else {
     file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'emojiicon' . DIRECTORY_SEPARATOR . 'favicon' . $usuffix . '.svg', '<svg xmlns="http://www.w3.org/2000/svg"><text y="32" font-size="32">X</text></svg>');
     if ($iponl != '' && file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'emojiicon' . DIRECTORY_SEPARATOR . 'favicon_' . server_remote_addr() . '.svg')) {
      $iponl=massage(" onload=\" if (window.parent) { if (parent.document.body.outerHTML.split('>')[0].indexOf(' data-ip=') == -1) { parent.document.body.setAttribute('data-ip', '_" . $rma . "');  parent.document.body.setAttribute('data-firstip', 'y');  } } \"");
     }
    }
  } else if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'emojiicon' . DIRECTORY_SEPARATOR . 'favicon_' . server_remote_addr() . '.svg')) {
    $usuffix='_' . server_remote_addr();
  } else {
    file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'emojiicon' . DIRECTORY_SEPARATOR . 'favicon' . $usuffix . '.svg', '<svg xmlns="http://www.w3.org/2000/svg"><text y="32" font-size="32">X</text></svg>');
    if ($iponl != '' && file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'emojiicon' . DIRECTORY_SEPARATOR . 'favicon_' . server_remote_addr() . '.svg')) {
     $iponl=massage(" onload=\" if (window.parent) { if (parent.document.body.outerHTML.split('>')[0].indexOf(' data-ip=') == -1) { parent.document.body.setAttribute('data-ip', '_" . $rma . "');  parent.document.body.setAttribute('data-firstip', 'y');  } } \"");
    }
  }

  if (('' . $_SERVER['QUERY_STRING']) == '') {
     $ask="<br><div id=dform><form target=_self id=myform onsubmit=\"if (('' + document.getElementById('codepoint').value).indexOf('-') != -1 && !viasvg) { return false; } setTimeout(doviasvg,2000); return false;\" method=GET action=./emojiicon.php><input title='Emoji codepoint as web browser tab icon (ie. look up to see after clicking display)' type=number id=codepoint name=codepoint value='-1' min='-1'></input><br><br>
<textarea rows=9 cols=120 id=mysvg><?xml version=\"1.0\" standalone=\"no\"?>
<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" 
\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> 
<svg width=\"100\" height=\"100\" viewbox=\"0 0 100 100\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">
<rect x=\"-50\" y=\"-50\" width=\"100\" height=\"100\" id=\"square\" fill=\"red\" transform=\"translate(50, 50) rotate(45)\"></rect>
</svg></textarea><br>
<br><input onmouseover='viasvg=false;' onmousedown='viasvg=false;' ontouchdown='viasvg=false;' style=background-color:yellow; type=submit value='Display icon as positive codepoint Number above'></input>&nbsp;<input onmousedown='viasvg=true;' onmouseover='viasvg=true;' ontouchdown='viasvg=true;' style=background-color:yellow; type=submit name=svgvia value='Display icon as SVG above'></input></form></div>";
  }
 
echo "<html>
<head>
<scr" . "ipt type=text/javascript>
   var viasvg=false, prevval='', prevcp='', initdiv='';
   
   function doviasvg() {
    if (viasvg) {  
      document.getElementById('mysvg').name='mysvg'; 
      document.getElementById('myform').submit(); 
      setTimeout(function(){ document.getElementById('dform').innerHTML=initdiv; }, 7000);
    } else if (('' + document.getElementById('codepoint').value).indexOf('-') == -1) {
      document.getElementById('myform').submit();
      setTimeout(function(){ document.getElementById('dform').innerHTML=initdiv; }, 7000);
    }
   }
   
   setTimeout(function(){
   if (window.parent) {
     if (window.parent != window.self) {
        document.getElementById('dform').innerHTML=document.getElementById('dform').innerHTML.replace('_self','_blank'); //document.getElementById('myform').target='_top';
     }
   }
   initdiv=document.getElementById('dform').innerHTML;
   }, 3000);
   
</scr" . "ipt>
<title>Emoji Icon - RJM Programming - March, 2025</title>
<link rel='icon' href='/emojiicon/favicon" . $usuffix . ".svg?rand=" . rand(0,3456789) . "' sizes='any' type='image/svg+xml'>
</head>
<body" . $iponl . ">
<h1>Emoji Icon <a target=_blank href=./emojiicon.php title=Reset>-</a> RJM Programming - March, 2025</h1>" . $ask . "
</body>
</html>";
?>
