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"$mdate("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 $GLOBALS['lang']['news']['template_1'];
  68.     if ($num == 2$return $GLOBALS['lang']['news']['template_2'];
  69.     if ($num == 3$return $GLOBALS['lang']['news']['template_3'];
  70.     if ($num == 4$return $GLOBALS['lang']['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]3return $GLOBALS['lang']['news']['no_title'];
  88.     if (strlen($table[1]3return $GLOBALS['lang']['news']['no_header'];
  89.     if (strlen($table[2]3return $GLOBALS['lang']['news']['no_body'];
  90.     if ($table[3<= || !is_numeric($table[3])) return $GLOBALS['lang']['news']['no_theme'];
  91.     if ($table[4<= || !is_numeric($table[4])) return $GLOBALS['lang']['news']['no_scale'];
  92.     if ($table[5<= || !is_numeric($table[5])) return $GLOBALS['lang']['news']['no_level'];
  93.     if ($table[6<= || !is_numeric($table[6])) return $GLOBALS['lang']['news']['no_template'];
  94.  
  95.     return true;
  96.   }
  97.  
  98.   /**
  99.    * news::AddNews()
  100.    * Ajout d'une news
  101.    *
  102.    * @access public
  103.    * @param array $table_news : contient les composants d'une news
  104.    * @param object $sql_object 
  105.    * @return integer $last_id
  106.    */
  107.   function AddNews($table_news$sql_object)
  108.   {
  109.     $table_news=$sql_object->DBescape($table_news);
  110.  
  111.     if ($table_news[0!= ''{
  112.       $this->TITLE = strip_input(trim($table_news[0])true);
  113.     }
  114.     if ($table_news[1!= ''{
  115.       $this->HEADER = strip_input(trim($table_news[1])true);
  116.     }
  117.     if ($table_news[2!= ''{
  118.       $this->BODY = strip_input(trim($table_news[2])true);
  119.     }
  120.     if (is_numeric($table_news[3])) {
  121.       $this->THEME = $table_news[3];
  122.     }
  123.     if (is_numeric($table_news[4])) {
  124.       $this->SCALE = $table_news[4];
  125.     }
  126.     if (is_numeric($table_news[5])) {
  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 ($requete1);
  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.       $this->LEVEL = $table_news[5];
  215.     }
  216.     if (is_numeric($table_news[6])) {
  217.       $this->TEMPLATE = $table_news[6];
  218.     }
  219.     if ($table_news[7!= ''{
  220.       $this->PHOTO_URI = $table_news[7];
  221.     }
  222.     if ($table_news[8!= ''{
  223.       $this->STATUT = $table_news[8];
  224.     }
  225.  
  226.     $mask $this->_HavePublishedDate($table_news[9]);
  227.  
  228.     $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 . "';";
  229.     $result $sql_object->DBQuery($requete);
  230.     return $result;
  231.   }
  232.  
  233.   /**
  234.    * news::_HavePublishedDate()
  235.    * Détermine la date de publication a inserer dans la bdd
  236.    *
  237.    * @access private
  238.    * @param string $current_status : statut actuel de l'actualité
  239.    * @return string $sql_mask
  240.    */
  241.   function _HavePublishedDate($current_status)
  242.   {
  243.     switch ($this->STATUT{
  244.       case 'P':
  245.         if ($current_status == 'D'$sql_mask ", news_published_date= NOW()";
  246.         else $sql_mask '';
  247.         break;
  248.       case 'D':
  249.         $sql_mask ", news_published_date= '0001-01-01'";
  250.         break;
  251.       default:
  252.         $sql_mask '';
  253.     }
  254.     return $sql_mask;
  255.   }
  256. }
  257.  
  258. ?>

Documentation generated on Sat, 08 Nov 2008 14:51:12 +0100 by phpDocumentor 1.4.1