linea21-modules
[ class tree: linea21-modules ] [ index: linea21-modules ] [ all elements ]

Source for file class.news.php

Documentation is available at class.news.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage news
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  *  News Management
  10.  */
  11.  
  12. class news {
  13.   /* @param
  14.    * */
  15.   var $TDB_NEWS = T_NEWS; // nom de la table.
  16.   var $NB_TEMPLATE = 3; // nombre de templates associés a la classe
  17.   var $URI_INPUT = "news/input/"; // dossier racine de stockage des photos
  18.   var $URI_OUTPUT = "news/output/"; // dossier racine de diffusion des archives
  19.   var $UPLOAD_MAX_MO = UPLOAD_MAX_MO; // taille maximale d'upload des photos en octets
  20.   var $MAX_PHOTO_MAX_WIDTH = MAX_PHOTO_MAX_WIDTH;
  21.   var $MAX_PHOTO_MIN_WIDTH = MAX_PHOTO_MIN_WIDTH;
  22.   var $ID;
  23.   var $TITLE;
  24.   var $HEADER;
  25.   var $BODY;
  26.   var $THEME;
  27.   var $SCALE;
  28.   var $LEVEL;
  29.   var $TEMPLATE;
  30.   var $PHOTO_URI;
  31.   var $RANGE;
  32.   var $POSTED_BY;
  33.   var $POST_DATE;
  34.   var $PUBLISHED_DATE;
  35.   var $PEREMPT_DATE;
  36.   var $IS_NATIONAL;
  37.   var $STATUT;
  38.  
  39.   /**
  40.    * news::_getDate()
  41.    * date courante et ajout
  42.    *
  43.    * @access private
  44.    * @param int $m chiffre des mois
  45.    * @param int $d chiffre des jours
  46.    * @param int $y chiffre des années
  47.    * @return string $format_date
  48.    * @return 
  49.    */
  50.   function _getDate($m = 0, $d = 0, $y = 0)
  51.   {
  52.     $format_date = mktime(date("H"), date("i"), date("s"), date("m") + $m, date("d") , date("Y"), -1);
  53.     $format_date = strftime('%Y-%m-%d %H:%M:%S', $format_date);
  54.  
  55.     return $format_date;
  56.   }
  57.  
  58.   /**
  59.    * news::GetTemplateName()
  60.    * Obtention de la dénomination du template
  61.    *
  62.    * @param integer $num 
  63.    * @return string $return
  64.    */
  65.   function GetTemplateName($num)
  66.   {
  67.     if ($num == 1) $return = _t('news','template_1');
  68.     if ($num == 2) $return = _t('news','template_2');
  69.     if ($num == 3) $return = _t('news','template_3');
  70.     if ($num == 4) $return = _t('news','template_4');
  71.  
  72.     return $return;
  73.   }
  74.  
  75.   /**
  76.    * news::CheckDataIntegrity()
  77.    * Vérification intégrité des données
  78.    *
  79.    * @access public
  80.    * @param array $table : contient les composants Nécessaires d'une news
  81.    * @return boolean true
  82.    *  si verifié, sinon string 'message d'erreur'
  83.    */
  84.  
  85.   function CheckDataIntegrity($table)
  86.   {
  87.     if (strlen($table[0]) < 3) return _t('news','no_title');
  88.     if (strlen($table[1]) < 3) return _t('news','no_header');
  89.     if (strlen($table[2]) < 3) return _t('news','no_body');
  90.     if ($table[3] <= 0 || !is_numeric($table[3])) return _t('news','no_theme');
  91.     if ($table[4] <= 0 || !is_numeric($table[4])) return _t('news','no_scale');
  92.     if ($table[6] <= 0 || !is_numeric($table[6])) return _t('news','no_template');
  93.  
  94.     return true;
  95.   }
  96.  
  97.   /**
  98.    * news::AddNews()
  99.    * Ajout d'une news
  100.    *
  101.    * @access public
  102.    * @param array $table_news : contient les composants d'une news
  103.    * @param object $sql_object 
  104.    * @return integer $last_id
  105.    */
  106.   function AddNews($table_news, $sql_object)
  107.   {
  108.     $table_news=$sql_object->DBescape($table_news);
  109.  
  110.     if ($table_news[0] != '') {
  111.       $this->TITLE = strip_input(trim($table_news[0]), true);
  112.     }
  113.     if ($table_news[1] != '') {
  114.       $this->HEADER = strip_input(trim($table_news[1]), true);
  115.     }
  116.     if ($table_news[2] != '') {
  117.       $this->BODY = strip_input(trim($table_news[2]), true);
  118.     }
  119.     if (is_numeric($table_news[3])) {
  120.       $this->THEME = $table_news[3];
  121.     }
  122.     if (is_numeric($table_news[4])) {
  123.       $this->SCALE = $table_news[4];
  124.     }
  125.     if (is_numeric($table_news[5])) {
  126.       if($table_news[5] == -1) $table_news[5]=0;
  127.       $this->LEVEL = $table_news[5];
  128.     }
  129.     if (is_numeric($table_news[6])) {
  130.       $this->TEMPLATE = $table_news[6];
  131.     }
  132.     if ($table_news[7] != '') {
  133.       $this->PHOTO_URI = $table_news[7];
  134.     }
  135.     if (is_numeric($table_news[8])) {
  136.       $this->RANGE = $table_news[8];
  137.     }
  138.     if (is_numeric($table_news[9])) {
  139.       $this->POSTED_BY = $table_news[9];
  140.     }
  141.     if ($table_news[11] != '') {
  142.       $this->IS_NATIONAL = strtoupper($table_news[11]);
  143.     }
  144.     if ($table_news[12] != '') {
  145.       $this->STATUT = strtoupper($table_news[12]);
  146.     }
  147.     if ($this->STATUT == 'P') {
  148.       $this->PUBLISHED_DATE = $this->_getDate();
  149.       if ($table_news[10] != '') {
  150.         $this->PEREMPT_DATE = $table_news[10];
  151.       } else {
  152.         $this->PEREMPT_DATE = '0001-01-01';
  153.       }
  154.     } else {
  155.       $this->PUBLISHED_DATE = '0001-01-01';
  156.       $this->PEREMPT_DATE = '0001-01-01';
  157.     }
  158.     $requete = "INSERT INTO " . $this->TDB_NEWS . " (news_title, news_header, news_body, news_theme, news_scale, " . "news_level, news_template, news_photo_uri, news_range, news_posted_by, news_published_date, " . "news_perempt_date, news_is_national, news_statut, news_date_crea) " . "VALUES('" . $this->TITLE . "', '" . $this->HEADER . "', '" . $this->BODY . "', " . $this->THEME . ", " . $this->SCALE . ", " . $this->LEVEL . ", " . $this->TEMPLATE . ", '" . $this->PHOTO_URI . "', " . $this->RANGE . ", " . $this->POSTED_BY . ", '" . $this->PUBLISHED_DATE . "' , '" . $this->PEREMPT_DATE . "', '" . $this->IS_NATIONAL . "', '" . $this->STATUT . "', now());";
  159.     
  160.     $last_id = $sql_object->DBInsert ($requete, 1);
  161.     return $last_id;
  162.   }
  163.  
  164.   /**
  165.    * news::DeleteNews()
  166.    * suppression d'une news
  167.    *
  168.    * @access public
  169.    * @param int $ID : identifiant de la news
  170.    * @param object $sql_object 
  171.    * @return bool $result
  172.    */
  173.  
  174.   function DeleteNews($ID, $sql_object)
  175.   {
  176.     $this->ID = $ID;
  177.     $requete = "UPDATE  " . $this->TDB_NEWS . " set news_statut='E', news_last_modify=NOW() WHERE news_id='" . $this->ID . "';";
  178.     $result = $sql_object->DBQuery($requete);
  179.     return $result;
  180.   }
  181.  
  182.   /**
  183.    * news::ModifyNews()
  184.    * modification d'une news
  185.    *
  186.    * @access public
  187.    * @param integer $ID : identifiant de la news
  188.    * @param object $sql_object 
  189.    * @param array $table_news : contient les composants d'une news
  190.    * @return boolean $result
  191.    */
  192.   function ModifyNews($ID, $table_news, $sql_object)
  193.   {
  194.     $table_news=$sql_object->DBescape($table_news);
  195.     if (is_numeric($ID)) {
  196.       $this->ID = $ID;
  197.     }
  198.     if ($table_news[0] != '') {
  199.       $this->TITLE = strip_input(trim($table_news[0]), true);
  200.     }
  201.     if ($table_news[1] != '') {
  202.       $this->HEADER = strip_input(trim($table_news[1]), true);
  203.     }
  204.     if ($table_news[2] != '') {
  205.       $this->BODY = strip_input(trim($table_news[2]), true);
  206.     }
  207.     if (is_numeric($table_news[3])) {
  208.       $this->THEME = $table_news[3];
  209.     }
  210.     if (is_numeric($table_news[4])) {
  211.       $this->SCALE = $table_news[4];
  212.     }
  213.     if (is_numeric($table_news[5])) {
  214.       if($table_news[5] == -1) $table_news[5]=0;
  215.       $this->LEVEL = $table_news[5];
  216.     }
  217.     if (is_numeric($table_news[6])) {
  218.       $this->TEMPLATE = $table_news[6];
  219.     }
  220.     if ($table_news[7] != '') {
  221.       $this->PHOTO_URI = $table_news[7];
  222.     }
  223.     if ($table_news[8] != '') {
  224.       $this->STATUT = $table_news[8];
  225.     }
  226.  
  227.     $mask = $this->_HavePublishedDate($table_news[9]);
  228.  
  229.     $requete = "UPDATE  " . $this->TDB_NEWS . " set news_title='" . $this->TITLE . "', news_header='" . $this->HEADER . "', news_body='" . $this->BODY . "' , news_theme='" . $this->THEME . "', news_scale='" . $this->SCALE . "', news_level='" . $this->LEVEL . "', news_template='" . $this->TEMPLATE . "', news_photo_uri='" . $this->PHOTO_URI . "', news_statut='" . $this->STATUT . "', news_last_modify=NOW() " . $mask . " WHERE news_id='" . $this->ID . "';";
  230.     $result = $sql_object->DBQuery($requete);
  231.     return $result;
  232.   }
  233.  
  234.   /**
  235.    * news::_HavePublishedDate()
  236.    * Détermine la date de publication a inserer dans la bdd
  237.    *
  238.    * @access private
  239.    * @param string $current_status : statut actuel de l'actualité
  240.    * @return string $sql_mask
  241.    */
  242.   function _HavePublishedDate($current_status)
  243.   {
  244.     switch ($this->STATUT) {
  245.       case 'P':
  246.         if ($current_status == 'D') $sql_mask = ", news_published_date= NOW()";
  247.         else $sql_mask = '';
  248.         break;
  249.       case 'D':
  250.         $sql_mask = ", news_published_date= '0001-01-01'";
  251.         break;
  252.       default:
  253.         $sql_mask = '';
  254.     }
  255.     return $sql_mask;
  256.   }
  257. }
  258.  
  259. ?>

Documentation generated on Fri, 16 Oct 2009 09:29:28 +0200 by phpDocumentor 1.4.1