Subversion Repositories Applications.papyrus

Rev

Rev 841 | Go to most recent revision | Details | Compare with Previous | 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'];
842 ddelon 25
        $titre = $options['titre'];
841 ddelon 26
        $bdd =& $GLOBALS['_GEN_commun']['pear_db'];
27
 
28
        $id_langue = $GLOBALS['_GEN_commun']['i18n']; //identifiant de la langue choisie
29
 
30
		if (isset($id_langue) && ($id_langue!='')) {
31
			$langue_url=$id_langue;
32
		} else {
33
			$langue_url=GEN_I18N_ID_DEFAUT;
34
		}
35
 
36
 
37
		$une_url =& new Pap_URL('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
38
 
842 ddelon 39
 
841 ddelon 40
		$nom='';
41
 
42
        if ($niveau=="site") {
43
 
44
        	  $requete =  'SELECT distinct * '.
45
                'FROM gen_site ';
46
                if (is_numeric($identifiant)) {
47
         	     	$requete .= 'WHERE gs_code_num = '.$identifiant.' ';
48
            	  	$une_url->addQueryString(GEN_URL_CLE_SITE, $identifiant);
49
                }
50
 
51
    		  $resultat = $bdd->query($requete);
52
    		 (DB::isError($resultat)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '';
53
 
54
    		  $aso_site = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
55
    		  $resultat->free();
56
 
57
 
58
                $requete_traduction =   'SELECT * '.
59
			                        'FROM  gen_site_relation, gen_site '.
60
		    	                    'WHERE gs_id_site =  gsr_id_site_02  ' .
61
		        	                'AND   '.$identifiant.'  = gs_code_num    '.
62
		            	            'AND  gsr_id_valeur = 1 '.// 1 = "avoir traduction"
63
		                	        'AND gs_ce_i18n  = "'.$langue_url.'" ';
64
 
65
			        $resultat_traduction = $bdd->query($requete_traduction);
66
					        (DB::isError($resultat_traduction))             ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_traduction->getMessage(), $requete_traduction))
67
				    	            : '';
68
 
69
 
70
	            if ( $resultat_traduction->numRows() > 0 ) {
71
	            	$aso_site=$resultat_traduction->fetchRow(DB_FETCHMODE_ASSOC);
72
	            }
73
 
842 ddelon 74
    		 if ($titre=='') {
75
		      	if (!empty($aso_site['gs_nom'])) {
76
		        	  $titre = $aso_site['gs_nom'];
77
		      	} else {
78
		        	  $titre = $aso_site['gs_titre'];
79
    	      	}
80
    		 }
841 ddelon 81
 
82
        }
83
 
84
        // Menu
85
 
86
        else {
87
 
88
        	  $requete =  'SELECT distinct * '.
89
                'FROM gen_menu ';
90
                if (is_numeric($identifiant)) {
91
              		$requete .= 'WHERE gm_code_num = '.$identifiant.' ';
92
	              	$une_url->addQueryString(GEN_URL_CLE_MENU, $identifiant);
93
                }
94
 
95
				  $resultat = $bdd->query($requete);
96
				 (DB::isError($resultat)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '';
97
 
98
				  $aso_menu = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
99
				  $resultat->free();
100
 
101
 
102
                $requete_traduction =   'SELECT * '.
103
			                        'FROM  gen_menu_relation, gen_menu '.
104
		    	                    'WHERE '.$identifiant.' = gm_code_num  ' .
105
		        	                'AND  gmr_id_menu_02  = gm_id_menu   '.
106
		            	            'AND  gmr_id_valeur  = 2 '.// 2 = "avoir traduction"
107
		                	        'AND gm_ce_i18n = "'.$langue_url.'" ';
108
 
109
 
110
				$resultat_traduction = $bdd->query($requete_traduction);
111
					        (DB::isError($resultat_traduction))             ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_traduction->getMessage(), $requete_traduction))
112
				    	            : '';
113
 
114
				if ($resultat_traduction->numRows() > 0) {
115
					$aso_menu=$resultat_traduction->fetchRow(DB_FETCHMODE_ASSOC);
116
				}
117
 
842 ddelon 118
            	if ($titre=='') {
119
	     	 		if (!empty($aso_menu['gm_nom'])) {
120
			        $titre = $aso_menu['gm_nom'];
121
		     		}
122
				     elseif (!empty($menu_valeur['gm_titre'])) {
123
				        $titre = $aso_menu['gm_titre'];
124
				     }
125
            	}
841 ddelon 126
 
127
        }
128
 
129
 
130
    	if ($langue_url != GEN_I18N_ID_DEFAUT) {
131
    		$une_url->addQueryString(GEN_URL_CLE_I18N, $langue_url);
132
    	}
133
 
134
 
135
 
136
        // Construction du lien
137
        $sortie  = '<a href="'.$une_url->getURL().'">'.htmlentities($titre).'</a>';
138
 
139
        return $sortie;
140
    }
141
 
142
}
143
?>