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

Source for file Tagger.php

Documentation is available at Tagger.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. /**
  27.  * Raccolta di funzioni per l'input semplificato di codice XML.
  28.  *
  29.  * @package  MCMS
  30.  * @version  2
  31.  * @author   Silvio Moioli <silvio at moioli dot net>
  32.  */
  33.  
  34. function tag($tag$string ""$attributes array()){
  35.     $attributesString="";
  36.     if (empty($attributes== false){
  37.         $attributesString=" ";
  38.         foreach ($attributes as $key => $value){
  39.             $attributesString.=$key."=\"".$value."\" ";
  40.         }
  41.     }
  42.     $result="";
  43.     if ($string == ""){
  44.         $result "<".$tag.$attributesString." />";
  45.     }
  46.     else{
  47.         $result "<".$tag.$attributesString.">".$string."</".$tag.">";
  48.     }
  49.     return $result;
  50. }
  51.  
  52. function b($string){
  53.     return tag("strong",$string,array());
  54. }
  55.  
  56. function p($string){
  57.     return tag("p",$string,array());
  58. }
  59.  
  60. function h1($string$id ''){
  61.     $attributes array();
  62.     if ($id != ''){
  63.         $attributes['id']=$id;
  64.     }
  65.     return tag("h1",$string,$attributes);
  66. }
  67. function h2($string$id ''){
  68.     $attributes array();
  69.     if ($id != ''){
  70.         $attributes['id']=$id;
  71.     }
  72.     return tag("h2",$string,$attributes);
  73. }
  74. function h3($string$id ''){
  75.     $attributes array();
  76.     if ($id != ''){
  77.         $attributes['id']=$id;
  78.     }
  79.     return tag("h3",$string,$attributes);
  80. }
  81.  
  82. function ul($string){
  83.     if ($string!=""){
  84.         return tag("ul",$string,array());
  85.     }
  86.     else{
  87.         return "";
  88.     }
  89. }
  90. function ol($string){
  91.     if ($string!=""){
  92.         return tag("ol",$string,array());
  93.     }
  94.     else{
  95.         return "";
  96.     }
  97. }
  98. function li($string){
  99.     return tag("li",$string,array());
  100. }
  101. function unorderedList($elements){
  102.     $elementsString="";
  103.     foreach ($elements as $i){
  104.         $elementsString.=li($i);
  105.     }
  106.     return ul($elementsString);
  107. }
  108.  
  109. function a($where,$anchor){
  110.     return tag("a",$anchor,array("href" => $where));
  111. }
  112.  
  113. function form($action$method$string){
  114.     $attribs array();
  115.     $attribs["action"]=$action;
  116.     $attribs["method"]=$method;
  117.     return tag("form"$string$attribs);
  118. }
  119.  
  120. function input($type$name$value=""){
  121.     $attribs array();
  122.     $attribs["type"]=$type;
  123.     $attribs["name"]=$name;
  124.     $attribs["value"]=$value;
  125.     return tag("input","",$attribs);
  126. }
  127.  
  128. function submit($label "Invia"){
  129.     return tag("input","",array("type" => "submit""value" => $label));
  130. }
  131.  
  132. function br(){
  133.     return tag("br","","");
  134. }
  135.  
  136. function checkbox($name$checked){
  137.     $attribs array();
  138.     $attribs["type"]="checkbox";
  139.     $attribs["name"]=$name;
  140.     if ($checked == true){
  141.         $attribs["checked"]="checked";
  142.     }
  143.     return tag("input","",$attribs);
  144. }
  145.  
  146. function option($value$selected$string){
  147.     $attribs array();
  148.     $attribs["value"]=$value;
  149.     if ($selected == true){
  150.         $attribs["selected"]="selected";
  151.     }
  152.     return tag("option"$string$attribs);
  153. }
  154.  
  155. function select($name$string){
  156.     $attribs array();
  157.     $attribs["name"]=$name;
  158.     return tag("select"$string$attribs);
  159. }
  160.  
  161. /**
  162. * Aggiunge ai contenuti della pagina un componente per l'editing dell'HTML.
  163. * Puņ essere FCKEditor o, se richiesto, una semplice input HTML.
  164. *
  165. @param $contentsValue string i contenuti della pagina
  166. */
  167. function HTMLEditor($contentsValue$javascript)
  168. {
  169.     $htmlContents htmlspecialchars($contentsValueENT_QUOTES);
  170.     $result "";
  171.     
  172.     if ($javascript == true){
  173.         //FCKEditor
  174.         $oFCKeditor new FCKeditor('contents';
  175.         $oFCKeditor->BasePath "/admin/include/fckeditor/";
  176.         if ($oFCKeditor->IsCompatible()== false){
  177.             $result .= b("Il tuo browser non &egrave; supportato da FCKEditor.");
  178.         }
  179.         else{
  180.             $oFCKeditor->Value $contentsValue;
  181.             $oFCKeditor->Height '500' ;
  182.             $result .= $oFCKeditor->CreateHtml(;
  183.             $result .= '<p><a href="'.$_SERVER['PHP_SELF'].'?javascript=off&amp;';
  184.  
  185.             //Ricopia le variabili GET se presenti
  186.             if (isset($_GET)){
  187.                 foreach ($_GET as $key => $value{
  188.                     if ($key != "javascript"){
  189.                         $result .= "$key=$value&amp;";
  190.                     }
  191.                 }
  192.             }
  193.         }
  194.         $result .= '">Versione senza javascript</a></p>';
  195.     }
  196.     else{
  197.         //Piccolo hack per l'input dell'HTML direttamente
  198.         $result .= '<p><textarea cols="80" rows="100"
  199.             name="contents">'.htmlspecialchars($contentsValue,
  200.             ENT_QUOTES).'</textarea></p>';
  201.  
  202.         $result .= '<p><a href="'.$_SERVER['PHP_SELF'].'?javascript=on&amp;';
  203.         //Ricopia le variabili GET se presenti
  204.         if (isset($_GET)){
  205.             foreach ($_GET as $key => $value{
  206.                 if ($key != "javascript"){
  207.                     $result .= "$key=$value&amp;";
  208.                 }
  209.             }
  210.         }
  211.         $result .= '">Versione con javascript</a></p>';
  212.     }
  213.     
  214.     return $result;
  215. }
  216.     
  217. /**
  218. * Ritorna una stringa XHTML con la "firma"
  219. * dell'autore. Se non &egrave; specificato l'autore,
  220. * si tenter&agrave; di recuperarlo dall'autore corrente.
  221. *
  222. @param $author Author l'autore di cui si cerca la firma
  223. */
  224. function getAuthorSignature($author)
  225. {   
  226.     $result "";
  227.     $name $author->getName();
  228.     $nick $author->getNick();
  229.     $surname $author->getSurname();
  230.     $email $author->getEmail();
  231.     if ($name != null && $name != ""){
  232.         $result .= $name;
  233.     }
  234.     if ($surname != null && $surname != ""){
  235.         $result .= " ".$surname;
  236.     }
  237.     if ($email != null && $email  != ""){
  238.         $email str_replace("@"" at "$email);
  239.         $email str_replace("."" punto "$email);
  240.  
  241.         $result .= " (";
  242.         if ($nick != null && $nick != ""){
  243.             $result .= "<em>&quot;".$nick."&quot;</em>, ";
  244.         }
  245.         
  246.         $result .= $email.")";
  247.     }
  248.     
  249.     return $result;
  250. }
  251. ?>

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