<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2004 by Philippe Brunier   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {include ("mainfile.php");}
include ("functions.php");

function MNSremoveHack($Xstring) {
   global $op, $userdata, $page, $tiny_mce;

   static $blog_editor;
   if ($tiny_mce) {
      if (!$blog_editor)
         $blog_editor=aff_editeur("tiny_mce","begin").aff_editeur("story","false").aff_editeur("tiny_mce","end");
   } else {
      if (!$blog_editor)
         $blog_editor=aff_editeur("custom", "story&minisite=true&membre=$userdata[1]");
   }

   $npds_forbidden_words=array(
   "'from:'i"=>"!from:!",
   "'subject:'i"=>"!subject:!",
   "'bcc:'i"=>"!bcc:!",
   "'mime-version:'i"=>"!mime-version:!",
   "'base64'i"=>"base_64",
   "'content-type:'i"=>"!content-type:!",
   "'content-transfer-encoding:'i"=>"!content-transfer-encoding:!",
   "'content-disposition:'i"=>"!content-disposition:!",
   "'content-location:'i"=>"!content-location:!",
   "'include'i"=>"!include!",
   "'<script'i"=>"&lt;script",
   "'</script'i"=>"&lt;/script",
   "'<object'i"=>"&lt;object",
   "'javascript'i"=>"!javascript!",
   "'embed'i"=>"!embed!",
   "'iframe'i"=>"!iframe!",
   "'refresh'i"=>"!refresh!",
   "'onload'i"=>"!onload!",
   "'onstart'i"=>"!onstart!",
   "'onerror'i"=>"!onerror!",
   "'onkey'i"=>"!onkey!",
   "'onmouse'i"=>"!onmouse!",
   "'document\.cookie'i"=>"!document.cookie!",
   "'jscript'i"=>"!jscript!",
   "'vbscript'i"=>"!vbscript!",
   "'pearlscript'i"=>"!pearlscript!",
   "'&#8216;'i"=>chr(39),
   "'&#8217;'i"=>chr(39),
   "'&#8220;'i"=>chr(34),
   "'&#8221;'i"=>chr(34),
   "'&#'i"=>"&_#",
   "'.htaccess'i"=>"",
   "'!blog_editeur!'i"=>$blog_editor,
   "'!l_gestionOK!'i"=>"<a href=\"modules.php?ModPath=upload&amp;ModStart=include_minisite/upload_minisite2&amp;apli=minisite\" target=\"_blank\" class=\"BLOG_LIEN\">MiniSite</a>",
   "'!l_blog_ajouterOK!'i"=>"<a href=\"minisite.php?op=$op&amp;page=$page&amp;action=A\" class=\"BLOG_LIEN\">".translate("Add articles")."</a>",
   "'\<\?php'i"=>"&lt;?php",
   "'\<\?'i"=>"&lt;?",
   "'\?\>'i"=>"?&gt;",
   "'\<\%'i"=>"&lt;%",
   "'\%\>'i"=>"%&gt;");
   $Xstring=preg_replace(array_keys($npds_forbidden_words),array_values($npds_forbidden_words), $Xstring);
   return($Xstring);
}

function convert_ressources ($Xcontent) {
   global $op;
   for ($i=0;$i<strlen($Xcontent);$i++) {
      if (strtoupper(substr($Xcontent,$i,4))=="SRC=") {
         if ( (strtoupper(substr($Xcontent,$i+4,3))!="HTT") and (strtoupper(substr($Xcontent,$i+4,4))!="\"HTT") )  {
            $Xcontent=substr_replace($Xcontent,"src=getfile.php?att_id=$op&amp;apli=minisite&amp;att_type=&amp;att_size=&amp;att_name=",$i,4);
         }
         $i=$i+4;
      }
      if (strtoupper(substr($Xcontent,$i,5))=="HREF=") {
         if ( (strtoupper(substr($Xcontent,$i+5,3))!="HTT") and (strtoupper(substr($Xcontent,$i+5,4))!="\"HTT") and (strtoupper(substr($Xcontent,$i+5,6))!="MAILTO") and (strtoupper(substr($Xcontent,$i+5,7))!="\"MAILTO") and (strtoupper(substr($Xcontent,$i+5,7))!="MAILTO:") and (strtoupper(substr($Xcontent,$i+5,8))!="\"MAILTO:") ) {
            $Xcontent=substr_replace($Xcontent,"href=minisite.php?op=$op&amp;page=",$i,5);
         }
         $i=$i+5;
      }
      if (strtoupper(substr($Xcontent,$i,11))=="BACKGROUND=") {
         if ( (strtoupper(substr($Xcontent,$i+11,3))!="HTT") and (strtoupper(substr($Xcontent,$i+11,4))!="\"HTT") )  {
            $Xcontent=substr_replace($Xcontent,"background=getfile.php?att_id=$op&amp;apli=minisite&amp;att_type=&amp;att_size=&amp;att_name=",$i,11);
         }
         $i=$i+11;
      }
   }
   return ($Xcontent);
}

   // Troll Control for security
   $affich=false;
   if (($op!="") and ($op)) {
      if (eregi("(^[0-9a-z_\.-])",$op) and !stristr($op,".*://") and !stristr($op,"..") and !stristr($op,"../") and !stristr($op, "script") and !stristr($op, "cookie") and !stristr($op, "iframe") and  !stristr($op, "applet") and !stristr($op, "object") and !stristr($op, "meta"))  {
         $userdata=get_userdata($op);
         if ($userdata[mns]==true) {
            $affich=true;
         }
         global $user;
         $adminblog=false;
         $userX = base64_decode($user);
         $userdata = explode(":", $userX);
         if ($userdata[1]==$op) {
            $adminblog=true;
         }
      }
   }
   if ($affich) {
      $dir="users_private/$op/mns/";
      if ($page=="") {
         $fic=$dir."index.html";
      } else {
         if (eregi("(^[0-9a-z_\.-])",$page) and !stristr($page,".*://") and !stristr($page,"..") and !stristr($page,"../"))  {
            $page=StripSlashes(str_replace("\"","",$page));
            $fic=$dir.$page;
         } else {
            $fic=$dir."index.html";
         }
      }
      $fic=MNSremoveHack($fic);
      if (file_exists($fic)) {
         $fp=fopen($fic,"r");
         if (filesize($fic)>0)
            $Xcontent=fread($fp,filesize($fic));
         fclose($fp);

         //compteur
         $compteur=$dir."compteur.txt";
         if (!file_exists($compteur)) {
            $fp=fopen($compteur,"w");
            fwrite($fp,"1");
            fclose($fp);
         } else {
            $cpt=file($compteur);
            $cpt=$cpt[0]+1;
            $fp=fopen($compteur,"w");
            fwrite($fp,$cpt);
            fclose($fp);
         }

         // Analyse et convertion des liens et images, blog, header, footer ...
         if (strstr($Xcontent,"!blog_page!")) {
            $perpage=substr($Xcontent,strpos($Xcontent,"!blog_page!",0)+11,2);
         } else {
            $perpage=4;
         }
         if (strstr($Xcontent,"!blog!")) {
            include ("modules/blog/readnews.php");
            settype($startpage,"integer");
            settype($perpage,"integer");
            $content=readnews($dir, $op, $perpage, $startpage, $action, $adminblog, $page);
            if (strstr($content,"!l_new_pages!")) {
               $new_pages=substr($content,strpos($content,"!l_new_pages!")+13);
               $content=substr($content,0,strpos($content,"!l_new_pages!"));
            }
         }
         if (strstr($Xcontent,"!l_header!")) {
            $l_fic=$dir."header.html";
            if (file_exists($l_fic)) {
               $fp=fopen($l_fic,"r");
               if (filesize($l_fic)>0)
                  $Hcontent=convert_ressources(fread($fp,filesize($l_fic)));
               fclose($fp);
            }
         }
         if (strstr($Xcontent,"!l_footer!")) {
            $l_fic=$dir."footer.html";
            if (file_exists($l_fic)) {
               $fp=fopen($l_fic,"r");
               if (filesize($l_fic)>0)
                  $Fcontent=convert_ressources(fread($fp,filesize($l_fic)));
               fclose($fp);
            }
         }
         if (($adminblog) and (strstr($Xcontent,"!l_gestion!"))) {
            $gestion="!l_gestionOK!";
         } else {
            $gestion="";
         }
         if (($adminblog) and (strstr($Xcontent,"!l_blog_ajouter!"))) {
            $blog_ajouter="!l_blog_ajouterOK!";
         } else {
            $blog_ajouter="";
         }
         $Xcontent=convert_ressources($Xcontent);
         // Meta-lang et removehack local
         $MNS_METALANG_words=array(
         "'!l_header!'i"=>"$Hcontent",
         "'!l_footer!'i"=>"$Fcontent",
         "'!blog_page!$perpage'i"=>"",
         "'!l_compteur!'i"=>"$cpt",
         "'!l_gestion!'i"=>"$gestion",
         "'!l_new_pages!'i"=>"$new_pages",
         "'!l_blog_ajouter!'i"=>"$blog_ajouter",
         "'!blog!'i"=>"$content"
         );
         $Xcontent=preg_replace(array_keys($MNS_METALANG_words),array_values($MNS_METALANG_words), $Xcontent);
         $Xcontent=meta_lang(MNSremoveHack($Xcontent));

         // Meta-mot post removeHack (Flash par exemple)
         // flash!fichier,width,height
         while (strstr($Xcontent,"!flash!")) {
            $deb=strpos($Xcontent,"!flash!",0)+7;
            $fin=strpos($Xcontent," ",$deb);
            if ($fin) {
               $s_flash=substr($Xcontent,$deb,$fin-$deb);
            } else {
               $s_flash=substr($Xcontent,$deb);
            }
            $s_flash_tab=explode(",",$s_flash);
            $att_url = "getfile.php?att_id=$op&amp;apli=minisite&amp;att_name=".rawurlencode($s_flash_tab[0]);
            settype($s_flash_tab[1],"integer");
            settype($s_flash_tab[2],"integer");
            $mime_renderers="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4\,0\,2\,0\" width=\"".$s_flash_tab[1]."\" height=\"".$s_flash_tab[2]."\"><param name=\"quality\" value=\"high\"><param name=\"SRC\" value=\"".$att_url."\"><embed src=\"".$att_url."\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"".$s_flash_tab[1]."\" height=\"".$s_flash_tab[2]."\"></embed></object>";
            $Xcontent=str_replace("!flash!$s_flash",$mime_renderers,$Xcontent);
         }
         echo $Xcontent;
      }
   }
   // NPDS copyright ... don't remove !
   echo "<br /><p align=\"center\">
   <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"90%\">
   <tr><td align=\"center\" valign=\"top\" width=\"90%\" colspan=\"17\"><hr noshade></td></tr>
   <tr>
   <td align=\"center\" valign=\"top\" nowrap=\"nowrap\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">$sitename</span></td>
   <td align=\"center\" valign=\"top\" width=\"10%\">&nbsp;</td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">N</span></td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">P</span></td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">D</span></td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">S</span></td>
   <td align=\"center\" valign=\"top\" width=\"10%\">&nbsp;</td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">H</span></td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">U</span></td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">B</span></td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">-</span></td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">B</span></td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">L</span></td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">O</span></td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\">G</span></td>
   <td align=\"center\" valign=\"top\" width=\"10%\">&nbsp;</td>
   <td align=\"center\" valign=\"top\" width=\"5%\"><span style=\"font-family: Verdana; color: #B6B6B6; font-size: 10px;\"><a href=\"http://www.npds.org\">NPDS</a></span></td>
   </tr>
   </table>
   </p>
   </body></html>";
?>