<?php
/*
Copyright (C) 2008 by oscim   Project lossim  [ 15.09.2009, 09:17:59] @oscim
// kate: replace-trailing-space-save true; space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; word-wrap-marker-color #41C2A4
ENCODE UTF-8
*/
/**
  Gestion de l'affichage des artciles et de leurs options

  @package lossim <web http://www.lossim.org>
  @author oscim <mail dom@oscim.fr > <web http://www.oscim.fr>
  @class nav_posts

  NOTE:

  function draw_ (print)

*/
class aff_articles extends constructeur {
  var $files;
  var $content;
  var $type ;
  var $r;
  var $description;
  var $tag;
  var $article;

  /**
    Nbr ligne lue
  */
  var $cpt_nb_ligne;

  var $lechemin;


  function aff_articles(){
    global $cstr;
    $this->files=$cstr->_call('db_posts','the_post'); //$cstr->db_posts->the_post();
    $this->init_article();
  }

  /**
    Ouverture et recuperetaion contenu du fichier
    @p string chemin et nom complet
  */
  /*private*/ function init_article(){
     global $cstr;
    $cpt=0;

    /**
      Mode New post
    */
    if (!is_array($this->files) || !isset($this->files['chemin'])) {
      $this->article='';
      $this->description="";
      $this->tag="";
      return '';
    }
    $this->r =$this->files ;
    if (!file_exists($this->files['chemin'].$this->files['nom_complet'])) return false;
    if($fp=fopen($this->files['chemin'].$this->files['nom_complet'], "r")) {
    while(!feof($fp)){
      $zone=fgets($fp,4096);
      if(strlen(trim($zone))){
        $cpt++;

        if(ereg("^<(!--|\?|new|\/new).*","$zone")) $zone="";
        if(ereg("^.*(<html).*","$zone")){
          $this->title= str_replace("\">","",eregi_replace("<htmltitre contenu=\"","","$zone"));
          if (eregi("htmlcontenu name=\"description\" content",$zone))$this->description=eregi_replace("\".*","",substr($zone,41));
          if (eregi("htmlcontenu name=\"tag\" content",$zone))$this->tag = eregi_replace("\".*","",substr($zone,33));
          $zone="";
        }
      }
      $this->article .=$zone;
    }
    $this->cpt_nb_ligne = $cpt;
    fclose($fp);
    } else die(_('impossible ouvrir le fichier'));
  }

  /**
    Retour du contenu du post
  */
  /*public*/ function the_tab_content(){
    return array(
        'description'=>$this->description,
        'tag'=>$this->tag,
        'content'=>$this->article
                );
  }


  /**
    Nettoyage des chaine string
    @param
      @a string chaine a nettoyé
      @a boolean true pour protect / false pour nettoyaeg strict
  */
  /*static*/ function clean_for_name_files ($content,$reduit=false){
    if(!$reduit)$content = strtolower($content);
    $content = stripslashes($content);
    $content = str_replace(array(";","€","\"","'","^"," - ","\\","/",".","é","è","ê","à","â","ù","û","ô","ë"), array( "","","","","+", "-","-","-","-","e", "e", "e", "a", "a","u","u","o","e"), $content);
    if(!$reduit)$content = str_replace(array("!","?",":","&"," ",",","|",")","("),array( "","","","-","_","_","","-","-"), $content);
    return $content;
  }


  /**
    Nettoyage des chaine string (content)
  @param
    @a string chaine a nettoyé
    @a boolean true pour protect / false pour nettoyaeg strict
  */
  /*static*/ function clean_content ($content,$reduit=false){
    $content = eregi_replace(array("(&euro;)", "&amp;"),array("€", "&"), stripslashes($content));
    return $content;
  }


  /**
    Gestion des date de l'article, publication, retrait, durée
  */
  /*private*/ function afftype($d_publi,$d_retrait){
    if(!function_exists('t_date')){
    function t_date($d){
      $d=trim($d);
      if (!ereg('-',$d)) return $s= substr($d,4,2)."-".substr($d,6,2)."-".substr($d,0,4);
      else return $d;
    }
    }
    return '<span class="label b">'.DATE_PUBLICATION.'</span><br />'.php_f_textField("date_publi",'','',t_date($d_publi),'', ' class="input_100p" onfocus="showCalendarControl(this);" '  )
        .'<span class="label b">'.DATE_RETRAIT.'</span><br />'.php_f_textField("date_retrait",'','',t_date($d_retrait),'', ' class="input_100p" onfocus="showCalendarControl(this);"  '  )
        .'<a href="#no_block" onclick="{document.getElementById(\'date_retrait\').value=\'--\';document.getElementById(\'date_publi\').value=\'--\';}">Reset date</a>';

  }


  /**
    Affichage type articles
  @param
    @a string/boolean $actif true/false ou P/I ou true/false
    @a string  $params
  @return string
  */
  /*private*/ function affactif($actif,$params=''){
    $arryData=array('P'=>ARTICLE_ACTIF_P, 'I'=>ARTICLE_ACTIF_I );
    $etat=( (is_bool($actif) && $actif) || (is_string($actif) && strtoupper($actif)=='P' || strtoupper($actif)=='TRUE')) ? 'P': 'I';
    return '<hr /><span class="label b">'.ETAT_PAGE.'</span><br />'.input_select('etat_page',$arryData,$etat,$params);
  }


  /**
    Affichage rubriques artricles
    @param
      @a string $letitre ajouter ou modifier du champs html
      @a boolean clean
  */
  function afftitre($letitre,$clean=false){
    if(!$clean) {
      if (!empty($letitre))  $this->titre =$letitre ;
      elseif (isset($this->files['lang']) && isset($this->files['title_'.$this->files['lang']])) $this->titre=$this->files['title_'.$this->files['lang']];
      elseif ( isset($this->files['title_'.LANG_POST])) $this->titre=$this->files['title_'.LANG_POST];
      else $this->titre='';
    }
    else $this->titre = $letitre;
    return '<span class="label b">'.TITRE_DE_PAGE.'</span><br />'.php_f_textField("titre_page",'','',ltrim(rtrim($this->titre)) ,'', ' class="input_100p" ' . Toolip(TITRE_DE_PAGE_DETAIL) );
  }

  /**
  */
  function affchemin($lechemin){
    /*if (!empty($lechemin)) $this->lechemin = $lechemin;
    else*/ $this->lechemin = $this->files['rub'].$this->files['nom_ss_ext'];
    return '<span class="label b">'.CHEMIN_DE_PAGE.'</span><br />'.php_f_textField("chemin_page",'','',$this->lechemin ,'', ' class="input_100p" ' . Toolip(CHEMIN_DE_PAGE_DETAIL) );
  }


  /**
    Affichage description artricles
  */
  function affdesciption($ladesri){
    if (!empty($ladesri))$this->description =$this->clean_for_name_files($ladesri,true);
     return '<span class="label b">'.DESCRIPTION_PAGE.'</span><br />'.php_f_textField("desc_page",'','',$this->description ,'', ' class="input_100p" ' . Toolip(DESCRIPTION_PAGE_DETAIL) );
  }


  /**
    Affichage tags artricles
  */
  function afftag($letag){
    if (!empty($letag)) $this->tag = $this->clean_for_name_files($letag,true);
    return '<span class="label b">'.TAG_PAGE.'</span><br />'.php_f_textField("tag_page",'','',$this->tag ,'', ' class="input_100p" ' . Toolip(TAG_PAGE_DETAIL) );
  }

  /** Affichage artricle */
  function affarticle($content,$mode){
    if (empty($mode)) $mode=_USER_PERSO__PREF_MOD_EDIT;

    if ((empty($this->cpt_nb_ligne))OR($this->cpt_nb_ligne<10)) $this->cpt_nb_ligne=10;
    else $this->cpt_nb_ligne= $this->cpt_nb_ligne*0.6;

    if($mode =='bbcode') {
            include("ext/bbcode/bouton_edition.php");
            $add_html="onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);'";
    } else $add_html="";

    if(!empty($content)) $this->article =$this->clean_content($content,'');
    else if (!isset($this->article))$this->article='';

    $tag= "<textarea id='%1\$s' name='%1\$s' rows='".$this->cpt_nb_ligne."' class='bb_area' tabindex='3' class='post' ".$add_html.">%2\$s </textarea>\n";

    printf($tag,"message",$this->article );
    return $this->article;
  }


  /**
    Menu de nav entre post fonction lang
  */
  /*private*/ function nav_draw_lang($id='afflang',$params=''){
    global $cstr;
    $cstr->_call('table_block','force_data_parameters',' class="'.$id.' lang post" '.$params);
    $cstr->_call('table_block','force_separator',array('separator'=>array('ul','li','span')) );
    $lg=$cstr->the_var('lg');
    if (count($lg)>0){
      while($r=each($lg)){
        $select= ($this->files['lang']==$r['key']) ? ' select ' : '';
        if (file_exists(ADD_PATH_ADMIN.REP_DATA.$r['key'].'/'.$this->files['rub'].$this->files['nom_complet']))
          $array[]['text']=tep_links('', _FILENAME_MODIFIER_UN_FICHIER.'?file='.ADD_PATH_ADMIN.REP_DATA.$r['key'].'/'.$this->files['rub'].$this->files['nom_complet'].'&amp;action=edit',BT_EDITER,"<img src=\"".URL_DU_SITE.REP_LIB_PARTAGE.REP_IMG.$r['key'].".gif\" />", false,'', '',' class="'.$select.'" ',5);
        else
          $array[]['text']= tep_links('', _FILENAME_MODIFIER_UN_FICHIER.'?file_rep='.ADD_PATH_ADMIN.REP_DATA.$r['key'].'/'.$this->files['rub'].'&file='.$this->files['nom_complet'],SUBMIT_AJOUTER,"<img src=\"".URL_DU_SITE.REP_LIB_PARTAGE.REP_IMG.$r['key'].".gif\" />", false,'', '',' class="'.$select.'" ',5)."";
      }
      return '<hr /><span class="label b">'.AFFLANG.'</span><br />'.$cstr->_call('table_block','table_block',$array);
    }
    else return '';
  }

  /**
    Menu de nav options  article
  */
  /*public*/ function c_options($post,$params=''){
    global $cstr;
    $cstr->_call('table_block','force_row_parameters',$params);

    $array[]['text']='<span>'. option_deplie('aff_desciption',AFFDESCIPTION,true).'</span>';
    $array[]['text']='<span>'. option_deplie('afftag',AFFTAG,true).'</span></li>';
    $array[]['text']='<span>'. option_deplie('chemin_page',LE_CHEMIN_PAGE,true) .'</span>';
//     $array[]['text']='<span>'. option_deplie('aff_page_home',LA_PAGE_HOME,true) .'</span>';

    if (test_const('PX_CONFIG_MODULE_PORTFOLIO')) $array[]['text']= '<span>'.option_deplie('aff_portfolio',AFF_PORTFOLIO,true).'</span>';
    if (test_const('PX_CONFIG_MODULE_POSTS_CAL')) $array[]['text']= '<span>'.option_deplie('aff_posts_cal',AFF_POSTS_CAL,true).'</span>';
    /* Specifique bbcode */
    if (select_editeur_d_edition($post['fixe_mod']) =='bbcode'){
      $array[]['text']= '<span><a id="btform_fb" class="btform" href="javascript:bbstyle(-1)">'.FERMER_LES_BALISES.'</a></span>';
      $array[]['text']= '<span><input id="btform_sr" class="btform" type="reset" value="'.SUBMIT_RESET.'"/></span>';
    }

    return $cstr->_call('table_block','table_block',$array);
  }


  /**
    Block Etat general article
  @param
    @a array $post les retoru get /post
    @a array $the_post
    @a string param
  */
  /*public*/ function draw_block_etat( $post,$the_post, $params=''){
    global $cstr;

    $cstr->_call('table_block','force_row_parameters',$params);
    $cstr->_call('table_block','force_separator',array('separator'=>array('div','p','span')) );

    $etat=(isset($post['etat_page']) && !empty($post['etat_page']) )? $post['etat_page'] : @$the_post['etat'];

    $array[]['text']= $this->affactif($etat,' class="input_100p" ');
    $array[]['text']='<hr /><span class="label b">'.RUBRIQUE_DE_PAGE.'</span><br />'.$cstr->_call('db_rubrique','c_cat',$the_post['keyrub'],' class="input_100p" ');
    $array[]['text']= $this->afftype(@$the_post['date_publi'],@$the_post['date_retrait']);
    $array[]['text']= $this->nav_draw_lang('afflang');
    $array[]['text']= '<hr />'.mode_editions (ltrim($post['fixe_mod']));

    print $cstr->_call('table_block','table_block',$array);
  }


  /**
    Block central
  */
  /*public*/ function draw_block_content($post,$the_post,$params=''){
    global $cstr;
    if (!empty($params)) $cstr->_call('table_block','force_row_parameters',$params);
    $cstr->_call('table_block','force_separator',array('separator'=> array('div','p','label')) );

    $array[]= array( 'params'=>' class="form item " ', 'text' => $this->afftitre(@$post['tpage'],false) );
    $array[]['text']= '<span class="label b" >'.LINK_THIS_POSTS .'</span> '.$post['link_public'] ;
    $array[]= array( 'params'=>' id="chemin_page"  class="form item "  style="display:none;" ', 'text' =>  $this->affchemin(@$post['chemin']) );
    $array[]= array( 'params'=>'  id="aff_desciption" class="form item " style="display:none;" ', 'text' => $this-> affdesciption(ltrim(@$post['desc_page'])) );
    $array[]= array( 'params'=>' id="afftag" class="form item " style="display:none;" ', 'text' => $this-> afftag(ltrim(@$post['tag_page'])));
//     $array[]= array( 'params'=>' id="aff_page_home" class="form item " style="display:none;" ', 'text' => $this-> aff_page_home(ltrim($_POST['page_home'])));
// AJOUT PORTFOLIO
/*if (test_const('PX_CONFIG_MODULE_PORTFOLIO')) {
                include(ADD_PATH_ADMIN.CHEM_MODULES.'portfolio/inc/lib/function.widget_article_portfolio.inc');
                widget_article_portfolio($file,$_GET['file']);
              }*/
//  AJOUT POSTS_CAL DATE EVENEMENT, GETSION CALL
/*if (test_const('PX_CONFIG_MODULE_POSTS_CAL')) {
                include(ADD_PATH_ADMIN.CHEM_MODULES.'posts_cal/inc/lib/function.widget_posts_cal.inc');
                widget_posts_cal($_GET['file'],$result_article);
              }*/


    print $cstr->_call('table_block','table_block',$array);
    $this->affarticle(stripcslashes(ltrim(@$post['message'])),@$post['fixe_mod']) ;
    if (isset($_GET['file'])||isset($_GET['file_rep'])) charg_editeur_d_edition(@$post['fixe_mod']) ;
  }



 /*public*/ function debugg(){
   if(test_const('DEBUG')) return $this;
   else die(_('no debugg actif'));
 }

}

?>