<commit_before><?php
/**
 * Layout Class
 *
 * @author Anakeen 2000 
 * @version $Id: Class.Layout.php,v 1.22 2005/01/18 08:45:13 eric Exp $
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @package WHAT
 * @subpackage CORE
 */
 /**
 */

// 
// PHP Layout Class
//   this class is designed to perform the final page layout of
//   an application.
//   this class uses a template with three dynamic zones header,toc and main 
//   doc.
//   
// 
// Layout Class can manage three kind of datas :
//  
// 1) Simple tags :
//    those tags are enclosed into brackets [] and can be replaced with any
//    dynamic data given with the Set method.
//    e.g : [MYDATA]  => $this->Set("MYDATA","this is my text");
//
// 2) Block of Data :
//    those tags are used to manage repeated set of data (as table for instance)
//    You can assign a table of data to a specific block.
//    e.g : $table = array ( "0" => array ( "name" => "John",
//                                          "surname" => "Smith"),
//                           "1" => array ( "name" => "Robert",
//                                          "surname" => "Martin"));
//
//    the block : [BLOCK IDENTITY]
//                <tr><td align="left">[NAME]</td>
//                    <td align="right">[SURNAME]</td>
//                </tr>
//                [ENDBLOCK IDENTITY]
//
//   the code :   $lay = new Layout ("file containing the block");
//                $lay->SetBlockCorresp("IDENTITY","NAME","name");
//                $lay->SetBlockCorresp("IDENTITY","SURNAME","surname");
//                $lay->SetBlockData("IDENTITY",$table);
//   
//                $out = $lay->gen();
//
//      $out  :   <tr><td align="left">John</td>
//                    <td align="right">Smith</td>
//                </tr>
//                <tr><td align="left">Robert</td>
//                    <td align="right">Martin</td>
//                </tr>
//
// 3) Call a specific script (need Core App Environment to work)
//   tag syntax : [ZONE zonename]
//
//     the zone name is linked to a specific application/function
//
//          eg :  [ZONE CORE:APPLIST]
//        
//         then the APPLIST function in the CORE Application is called
//           this function can then use another layout etc......
//
//
// Copyright (c) 1999 <NAME>.
//               <NAME>
//
//  $Id: Class.Layout.php,v 1.22 2005/01/18 08:45:13 eric Exp $

$CLASS_LAYOUT_PHP="";
include_once('Class.Log.php');  
include_once('Class.Action.php');  
include_once('Class.Application.php');


class Layout {

//############################################
//# Private var
//#

var $strip='Y';

//########################################################################
//# Public methods
//#  
//#



/**
   * construct layout for view card containt
   *
   * @param string $caneva file of the template
   * @param Action $action current action
   * @param string $template default template
   */
 function Layout($caneva="",$action="",$template="[OUT]") {
   $this->LOG = new Log("","Layout");     
   $this->template = $template;
   $this->action=$action;
   $this->generation="";
   $file = $caneva;
   $this->file="";
   if (file_exists($file)) {
     if (filesize($file) > 0) {
       $fd = fopen($file,"r");
       if ($fd) {
	 $this->file=$file;
	 $this->template = fread($fd,filesize($file));
       }
     } else {
       $this->template = "";
     } 
   }
 }


 function SetBlockCorresp($p_nom_block,$p_nom_modele,$p_nom=NULL) {
   $this->corresp["$p_nom_block"]["[$p_nom_modele]"]=($p_nom==NULL?$p_nom_modele:"$p_nom");
  }

  function SetBlockData($p_nom_block,$data=NULL) {
   $this->data["$p_nom_block"]=$data;
   // affect the corresp block if not
   if (is_array($data))  {
     reset($data);
     $elem = pos($data);
     if ( isset($elem) && is_array($elem)) {
       reset($elem);
       while (list($k,$v)=each($elem)) {
         if (!isset($this->corresp["$p_nom_block"]["[$k]"])) {
           $this->SetBlockCorresp($p_nom_block,$k);
         }
       }
     }
   }
  }

  function GetBlockData($p_nom_block) {
    if (isset($this->data["$p_nom_block"])) return $this->data["$p_nom_block"];
    return false;
  }
  function SetBlock($name,$block) {
    if ($this->strip=='Y') {
      //      $block = StripSlashes($block);
      $block = str_replace("\\\"","\"",$block);
    }
    $out = "";
  
    if (isset ($this->data) && isset ($this->data["$name"]) && is_array($this->data["$name"])) {
      foreach($this->data["$name"] as $k=>$v) {
        $loc=$block;
        foreach ($this->corresp["$name"] as $k2=>$v2) {
	     $loc = str_replace( $k2, $v[$v2], $loc);
           
	}
	$this->rif=&$v;
	$this->ParseIf($loc);
        $out .= $loc;
      }
    }
    $this->ParseBlock($out);
    return ($out);
  } 

  function ParseBlock(&$out) {
    $out = preg_replace(
       "/(?m)\[BLOCK\s*([^\]]*)\](.*?)\[ENDBLOCK\s*\\1\]/se", 
       "\$this->SetBlock('\\1','\\2')",
       $out);
  }

  function TestIf($name,$block,$not=false) {    
    $out = "";     

    if ($this->rif[$name] xor $not)  {
      if ($this->strip=='Y') {
	$block = str_replace("\\\"","\"",$block);
      }
      $out=$block;      
      $this->ParseBlock($out);
    }
    return ($out);
  } 
  function ParseIf(&$out) {
    $out = preg_replace(
       "/(?m)\[IF(NOT)?\s*([^\]]*)\](.*?)\[ENDIF\s*\\2\]/se", 
       "\$this->TestIf('\\2','\\3','\\1')",
       $out);
  }

  function ParseZone(&$out) {
    $out = preg_replace(
       "/\[ZONE\s*([^:]*):([^\]]*)\]/e",
       "\$this->execute('\\1','\\2')",
       $out);
  }

  function ParseKey(&$out) {
    if (isset ($this->rkey)) {
      $out=preg_replace($this->pkey,$this->rkey,$out);<commit_msg>Correct IF, set only if is set<commit_after><?php
/**
 * Layout Class
 *
 * @author Anakeen 2000 
 * @version $Id: Class.Layout.php,v 1.23 2005/01/20 10:34:15 eric Exp $
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @package WHAT
 * @subpackage CORE
 */
 /**
 */

// 
// PHP Layout Class
//   this class is designed to perform the final page layout of
//   an application.
//   this class uses a template with three dynamic zones header,toc and main 
//   doc.
//   
// 
// Layout Class can manage three kind of datas :
//  
// 1) Simple tags :
//    those tags are enclosed into brackets [] and can be replaced with any
//    dynamic data given with the Set method.
//    e.g : [MYDATA]  => $this->Set("MYDATA","this is my text");
//
// 2) Block of Data :
//    those tags are used to manage repeated set of data (as table for instance)
//    You can assign a table of data to a specific block.
//    e.g : $table = array ( "0" => array ( "name" => "John",
//                                          "surname" => "Smith"),
//                           "1" => array ( "name" => "Robert",
//                                          "surname" => "Martin"));
//
//    the block : [BLOCK IDENTITY]
//                <tr><td align="left">[NAME]</td>
//                    <td align="right">[SURNAME]</td>
//                </tr>
//                [ENDBLOCK IDENTITY]
//
//   the code :   $lay = new Layout ("file containing the block");
//                $lay->SetBlockCorresp("IDENTITY","NAME","name");
//                $lay->SetBlockCorresp("IDENTITY","SURNAME","surname");
//                $lay->SetBlockData("IDENTITY",$table);
//   
//                $out = $lay->gen();
//
//      $out  :   <tr><td align="left">John</td>
//                    <td align="right">Smith</td>
//                </tr>
//                <tr><td align="left">Robert</td>
//                    <td align="right">Martin</td>
//                </tr>
//
// 3) Call a specific script (need Core App Environment to work)
//   tag syntax : [ZONE zonename]
//
//     the zone name is linked to a specific application/function
//
//          eg :  [ZONE CORE:APPLIST]
//        
//         then the APPLIST function in the CORE Application is called
//           this function can then use another layout etc......
//
//
// Copyright (c) 1999 <NAME>.
//               <NAME>
//
//  $Id: Class.Layout.php,v 1.23 2005/01/20 10:34:15 eric Exp $

$CLASS_LAYOUT_PHP="";
include_once('Class.Log.php');  
include_once('Class.Action.php');  
include_once('Class.Application.php');


class Layout {

//############################################
//# Private var
//#

var $strip='Y';

//########################################################################
//# Public methods
//#  
//#



/**
   * construct layout for view card containt
   *
   * @param string $caneva file of the template
   * @param Action $action current action
   * @param string $template default template
   */
 function Layout($caneva="",$action="",$template="[OUT]") {
   $this->LOG = new Log("","Layout");     
   $this->template = $template;
   $this->action=$action;
   $this->generation="";
   $file = $caneva;
   $this->file="";
   if (file_exists($file)) {
     if (filesize($file) > 0) {
       $fd = fopen($file,"r");
       if ($fd) {
	 $this->file=$file;
	 $this->template = fread($fd,filesize($file));
       }
     } else {
       $this->template = "";
     } 
   }
 }


 function SetBlockCorresp($p_nom_block,$p_nom_modele,$p_nom=NULL) {
   $this->corresp["$p_nom_block"]["[$p_nom_modele]"]=($p_nom==NULL?$p_nom_modele:"$p_nom");
  }

  function SetBlockData($p_nom_block,$data=NULL) {
   $this->data["$p_nom_block"]=$data;
   // affect the corresp block if not
   if (is_array($data))  {
     reset($data);
     $elem = pos($data);
     if ( isset($elem) && is_array($elem)) {
       reset($elem);
       while (list($k,$v)=each($elem)) {
         if (!isset($this->corresp["$p_nom_block"]["[$k]"])) {
           $this->SetBlockCorresp($p_nom_block,$k);
         }
       }
     }
   }
  }

  function GetBlockData($p_nom_block) {
    if (isset($this->data["$p_nom_block"])) return $this->data["$p_nom_block"];
    return false;
  }
  function SetBlock($name,$block) {
    if ($this->strip=='Y') {
      //      $block = StripSlashes($block);
      $block = str_replace("\\\"","\"",$block);
    }
    $out = "";
  
    if (isset ($this->data) && isset ($this->data["$name"]) && is_array($this->data["$name"])) {
      foreach($this->data["$name"] as $k=>$v) {
        $loc=$block;
        foreach ($this->corresp["$name"] as $k2=>$v2) {
	     $loc = str_replace( $k2, $v[$v2], $loc);
           
	}
	$this->rif=&$v;
	$this->ParseIf($loc);
        $out .= $loc;
      }
    }
    $this->ParseBlock($out);
    return ($out);
  } 

  function ParseBlock(&$out) {
    $out = preg_replace(
       "/(?m)\[BLOCK\s*([^\]]*)\](.*?)\[ENDBLOCK\s*\\1\]/se", 
       "\$this->SetBlock('\\1','\\2')",
       $out);
  }

  function TestIf($name,$block,$not=false) {    
    $out = "";     
    if ( isset($this->rif[$name])) {
     if ($this->rif[$name] xor $not)  {
      if ($this->strip=='Y') {
	$block = str_replace("\\\"","\"",$block);
      }
      $out=$block;      
      $this->ParseBlock($out);
     }
    } else {
      if ($this->strip=='Y') $block = str_replace("\\\"","\"",$block);
      
      if ($not) $out="[IFNOT $name]".$block."[ENDIF $name]";
      else $out="[IF $name]".$block."[ENDIF $name]";
    }
    return ($out);
  } 
  function ParseIf(&$out) {
    $out = preg_replace(
       "/(?m)\[IF(NOT)?\s*([^\]]*)\](.*?)\[ENDIF\s*\\2\]/se", 
       "\$this->TestIf('\\2','\\3','\\1')",
       $out);
  }

  function ParseZone(&$out) {
    $out = preg_replace(
       "/\[ZONE\s*([^:]*):([^\]]*)\]/e",
       "\$this->execute('\\1','\\2')",
       $out);
  }

  function ParseKey(&$out) {
    if (isset ($this->rkey)) {
      $out=preg_replace($this->pkey,$this->rkey,$out);
{'fraction_non_alphanumeric': 0.23248843980133585, 'fraction_numerical': 0.010446994348347319, 'mean_word_length': 2.1831561733442353, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3600675', 'n_tokens_mistral': 4121, 'n_tokens_neox': 3918, 'n_words': 815}