Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
841 ddelon 1
<?php
2
 
3
class Text_Wiki_Render_Xhtml_Lien extends Text_Wiki_Render {
4
 
5
    /**
6
    *
7
    * Renders a token into text matching the requested format.
8
    *
9
    * @access public
10
    *
11
    * @param array $options The "options" portion of the token (second
12
    * element).
13
    *
14
    * @return string The text rendered from the token options.
15
    *
16
    */
17
 
18
    function token($options)
19
    {
20
 
21
    	// Initialisation des variables
22
        $sortie = '';
23
        $niveau = $options['niveau'];
24
        $identifiant = $options['identifiant'];
25
        $bdd =& $GLOBALS['_GEN_commun']['pear_db'];
26
 
27
        $id_langue = $GLOBALS['_GEN_commun']['i18n']; //identifiant de la langue choisie
28
 
29
		if (isset($id_langue) && ($id_langue!='')) {
30
			$langue_url=$id_langue;
31
		} else {
32
			$langue_url=GEN_I18N_ID_DEFAUT;
33
		}
34
 
35
 
36
		$une_url =& new Pap_URL('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
37
 
38
		$titre='';
39
		$nom='';
40
 
41
        if ($niveau=="site") {
42
 
43
        	  $requete =  'SELECT distinct * '.
44
                'FROM gen_site ';
45
                if (is_numeric($identifiant)) {
46
         	     	$requete .= 'WHERE gs_code_num = '.$identifiant.' ';
47
            	  	$une_url->addQueryString(GEN_URL_CLE_SITE, $identifiant);
48
                }
49
 
50
    		  $resultat = $bdd->query($requete);
51
    		 (DB::isError($resultat)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '';
52
 
53
    		  $aso_site = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
54
    		  $resultat->free();
55
 
56
 
57
                $requete_traduction =   'SELECT * '.
58
			                        'FROM  gen_site_relation, gen_site '.
59
		    	                    'WHERE gs_id_site =  gsr_id_site_02  ' .
60
		        	                'AND   '.$identifiant.'  = gs_code_num    '.
61
		            	            'AND  gsr_id_valeur = 1 '.// 1 = "avoir traduction"
62
		                	        'AND gs_ce_i18n  = "'.$langue_url.'" ';
63
 
64
			        $resultat_traduction = $bdd->query($requete_traduction);
65
					        (DB::isError($resultat_traduction))             ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_traduction->getMessage(), $requete_traduction))
66
				    	            : '';
67
 
68
 
69
	            if ( $resultat_traduction->numRows() > 0 ) {
70
	            	$aso_site=$resultat_traduction->fetchRow(DB_FETCHMODE_ASSOC);
71
	            }
72
 
73
 
74
		      if (!empty($aso_site['gs_nom'])) {
75
		          $titre = $aso_site['gs_nom'];
76
		      } else {
77
		          $titre = $aso_site['gs_titre'];
78
    	      }
79
 
80
        }
81
 
82
        // Menu
83
 
84
        else {
85
 
86
        	  $requete =  'SELECT distinct * '.
87
                'FROM gen_menu ';
88
                if (is_numeric($identifiant)) {
89
              		$requete .= 'WHERE gm_code_num = '.$identifiant.' ';
90
	              	$une_url->addQueryString(GEN_URL_CLE_MENU, $identifiant);
91
                }
92
 
93
				  $resultat = $bdd->query($requete);
94
				 (DB::isError($resultat)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '';
95
 
96
				  $aso_menu = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
97
				  $resultat->free();
98
 
99
 
100
                $requete_traduction =   'SELECT * '.
101
			                        'FROM  gen_menu_relation, gen_menu '.
102
		    	                    'WHERE '.$identifiant.' = gm_code_num  ' .
103
		        	                'AND  gmr_id_menu_02  = gm_id_menu   '.
104
		            	            'AND  gmr_id_valeur  = 2 '.// 2 = "avoir traduction"
105
		                	        'AND gm_ce_i18n = "'.$langue_url.'" ';
106
 
107
 
108
				$resultat_traduction = $bdd->query($requete_traduction);
109
					        (DB::isError($resultat_traduction))             ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_traduction->getMessage(), $requete_traduction))
110
				    	            : '';
111
 
112
				if ($resultat_traduction->numRows() > 0) {
113
					$aso_menu=$resultat_traduction->fetchRow(DB_FETCHMODE_ASSOC);
114
				}
115
 
116
 
117
     	 		if (!empty($aso_menu['gm_nom'])) {
118
		        $titre = $aso_menu['gm_nom'];
119
	     		}
120
			     elseif (!empty($menu_valeur['gm_titre'])) {
121
			        $titre = $aso_menu['gm_titre'];
122
			     }
123
 
124
 
125
        }
126
 
127
 
128
    	if ($langue_url != GEN_I18N_ID_DEFAUT) {
129
    		$une_url->addQueryString(GEN_URL_CLE_I18N, $langue_url);
130
    	}
131
 
132
 
133
 
134
        // Construction du lien
135
        $sortie  = '<a href="'.$une_url->getURL().'">'.htmlentities($titre).'</a>';
136
 
137
        return $sortie;
138
    }
139
 
140
}
141
?>