MCMS
[ class tree: MCMS ] [ index: MCMS ] [ all elements ]

Source for file Event.php

Documentation is available at Event.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | MCMS: a PHP Content Management System for creating accessible sites. |
  5. // | Copyright (C) 2005  Silvio Moioli                                    |
  6. // |                                                                      |
  7. // | This program is free software; you can redistribute it and/or modify |
  8. // | it under the terms of the GNU General Public License as published by |
  9. // | the Free Software Foundation; either version 2 of the License, or    |
  10. // | (at your option) any later version.                                  |
  11. // |                                                                      |
  12. // | This program is distributed in the hope that it will be useful,      |
  13. // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  14. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
  15. // | GNU General Public License for more details.                         |
  16. // |                                                                      |
  17. // | You should have received a copy of the GNU General Public License    |
  18. // | along with this program; if not, write to the Free Software          |
  19. // | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 |
  20. // +----------------------------------------------------------------------+
  21. // | Authors: Silvio Moioli <silvio at moioli dot net> www.moioli.net     |
  22. // +----------------------------------------------------------------------+
  23. //
  24. //$Id:
  25.  
  26. /** Carica la classe base di MCMS per l'interfacciamento al Database */
  27. require_once $_SERVER["DOCUMENT_ROOT"]."/admin/lib/model/Engine.php";
  28.  
  29. /**
  30.  * Evento di MCMS.
  31.  * Un Event modella una possibile richiesta dell'utente con tutti i parametri
  32.  * ad essa associati (POST e GET).
  33.  *
  34.  * @package MCMS
  35.  * @author Silvio Moioli
  36.  * @version 2
  37.  */
  38. class Event extends PEAR
  39. {
  40.     /** @var Engine l'oggetto per la comunicazione al Database */
  41.     var $engine = null;
  42.     /** @var array i parametri di questo evento */
  43.     var $parameters = array();
  44.     
  45.     /**
  46.      * Costruttore standard.
  47.      *
  48.      * @param array $post i parametri POST della richiesta
  49.      * @param array $get i parametri GET della richiesta
  50.      */
  51.     /*abstract*/ function Event($engine$post$get)
  52.     {
  53.         $this->engine=$engine;         
  54.         $httpParams=array_merge($post,$get);
  55.         foreach ($httpParams as $key => $value{
  56.             if ($key == "contents"){
  57.                 $this->parameters[$key$this->formatInputXml($value);
  58.             }
  59.             else{
  60.                 $this->parameters[$key$this->formatInputText($value);
  61.             }
  62.         }
  63.     }
  64.     
  65.     /**
  66.      * Ritorna un parametro generico (se esiste).
  67.      * 
  68.      * @return string il parametro o null
  69.      */
  70.     function getParameter($key){
  71.         if (array_key_exists($key$this->parameters)){
  72.             return $this->parameters[$key];
  73.         }
  74.         else{
  75.             return null;
  76.         }
  77.     }
  78.     
  79.     /**
  80.      * Ritorna tutti i parametri.
  81.      * 
  82.      * @return array i parametri
  83.      */
  84.     function getParameters(){
  85.         return $this->parameters;
  86.     }
  87.     
  88.     /** 
  89.      * Se tra i parametri c'è un ID di autore, ritorna l'oggetto
  90.      * corrispondente.
  91.      *
  92.      * @return l'oggetto Author o null
  93.      */
  94.     function getAuthor(){
  95.         $result null;
  96.         if (array_key_exists("authorID"$this->parameters)){
  97.             $id $this->parameters["authorID"];
  98.             if ($id!= null){
  99.                 $result new Author($id$this->engine);
  100.             }
  101.         }
  102.         return $result;
  103.     }
  104.     
  105.     /** 
  106.      * Se tra i parametri c'è un ID di articolo, ritorna l'oggetto
  107.      * corrispondente.
  108.      *
  109.      * @return l'oggetto Article o null
  110.      */
  111.     function getArticle(){
  112.         $result null;
  113.         if (array_key_exists("articleID"$this->parameters)){
  114.             $id $this->parameters["articleID"];
  115.             if ($id!= null){
  116.                 $result new Article($id$this->engine);
  117.             }
  118.         }
  119.         return $result;
  120.     }
  121.     
  122.     /** 
  123.      * Se tra i parametri c'è un ID di notizia, ritorna l'oggetto
  124.      * corrispondente.
  125.      *
  126.      * @return l'oggetto News o null
  127.      */
  128.     function getNews(){
  129.         $result null;
  130.         if (array_key_exists("newsID"$this->parameters)){
  131.             $id $this->parameters["newsID"];
  132.             if ($id!= null){
  133.                 $result new News($id$this->engine);
  134.             }
  135.         }
  136.         return $result;
  137.     }
  138.     
  139.     /** 
  140.      * Se tra i parametri c'è un ID di sito, ritorna l'oggetto
  141.      * corrispondente.
  142.      *
  143.      * @return l'oggetto Site o null
  144.      */
  145.     function getSite(){
  146.         $result null;
  147.         if (array_key_exists("siteID"$this->parameters)){
  148.             $id $this->parameters["siteID"];
  149.             if ($id!= null){
  150.                 $result new Site($id$this->engine);
  151.             }
  152.         }
  153.         return $result;
  154.     }
  155.  
  156.     /** 
  157.      * Se tra i parametri c'è un ID di sezione, ritorna l'oggetto
  158.      * corrispondente.
  159.      *
  160.      * @return l'oggetto Category o null
  161.      */
  162.     function getCategory(){
  163.         $result null;
  164.         if (array_key_exists("categoryID"$this->parameters)){
  165.             $id $this->parameters["categoryID"];
  166.             if ($id!= null){
  167.                 $result new Category($id$this->engine);
  168.             }
  169.         }
  170.         return $result;
  171.     }
  172.     
  173.     /** 
  174.      * Se tra i parametri ci sono più ID di articolo, ritorna
  175.      * gli oggetti corrispondenti.
  176.      *
  177.      * @return un array di Article
  178.      */
  179.     function getArticles(){
  180.         $result array();
  181.         for ($i=0$i<count($this->parameters)$i++{
  182.             if (array_key_exists("article$i"$this->parameters)){
  183.                 $id $this->parameters["article".$i."ID"];
  184.                 if ($id!= null){
  185.                     $result []new Article($id$this->engine);
  186.                 }
  187.             }
  188.         }
  189.         return $result;
  190.     }
  191.     
  192.     /** 
  193.      * Se tra i parametri ci sono più ID di componente, ritorna
  194.      * gli oggetti corrispondenti.
  195.      *
  196.      * @return un array di Components
  197.      */
  198.     function getComponents(){
  199.         $result array();
  200.         $components $this->engine->getComponents();
  201.         $componentNames array();
  202.         foreach($components as $i){
  203.             $componentName get_class($i);
  204.             require_once $_SERVER["DOCUMENT_ROOT"]."/admin/lib/plugins/$componentName.php";
  205.             if (array_key_exists("component$componentName"$this->parameters&&
  206.                 $this->parameters["component$componentName"== "on"{
  207.                 $result[$i;
  208.             }
  209.         }
  210.         return $result;
  211.     }
  212.      
  213.     //Metodi privati
  214.         /**
  215.      * Formatta (applica il quoting) a stringhe potenzialmente non sicure
  216.      * che devono essere trattate come testo semplice.
  217.      *
  218.      * @param string $string la stringa da preparare
  219.      * @return la stringa formattata
  220.      */
  221.     function formatInputText($string){
  222.         return htmlspecialchars(stripslashes($string)ENT_QUOTES);
  223.     }
  224.  
  225.     /**
  226.      * Formatta (applica il quoting) a stringhe potenzialmente non sicure
  227.      * che devono essere trattate come XML.
  228.      *
  229.      * @param string $string la stringa da preparare
  230.      * @return la stringa formattata
  231.      */
  232.     function formatInputXml($string){
  233.         $result stripslashes($string);
  234.         //Rimuovi il codice JavaScript
  235.         $result preg_replace("@<script[^>]*?>.*?</script>@si"""$result);
  236.         return $result;
  237.     
  238. }

Documentation generated on Wed, 26 Jul 2006 21:44:54 +0200 by phpDocumentor 1.3.0RC6