3 if (!defined("_ECRIRE_INC_VERSION")) return;
5 include_spip('inc/texte');
8 * Renvoyer la balise <link> pour URL CANONIQUES
11 function generer_urls_canoniques(){
12 include_spip('balise/url_');
14 if (count($GLOBALS['contexte'])==0){
16 } elseif (isset($GLOBALS['contexte']['id_article'])) {
17 $id_objet = $GLOBALS['contexte']['id_article'];
19 } elseif (isset($GLOBALS['contexte']['id_rubrique'])) {
20 $id_objet = $GLOBALS['contexte']['id_rubrique'];
26 $flux .= '<link rel="canonical" href="' . url_de_base() . '" />';
29 $flux .= '<link rel="canonical" href="' . url_de_base() . generer_url_entite($id_objet, $objet) . '" />';
37 * Renvoyer la balise SCRIPT de Google Analytics
38 * @return string $flux
40 function generer_google_analytics(){
42 $config = unserialize($GLOBALS['meta']['seo']);
44 /* GOOGLE ANALYTICS */
45 if ($config['analytics']['id']){
46 // Nouvelle balise : http://www.google.com/support/analytics/bin/answer.py?hl=fr_FR&answer=174090&utm_id=ad
47 $flux .= "<script type=\"text/javascript\">
48 var _gaq = _gaq || [];
49 _gaq.push(['_setAccount', '" . $config['analytics']['id'] . "']);
50 _gaq.push(['_trackPageview']);
52 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
53 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
54 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
64 * Renvoyer les META Classiques
65 * - Meta Titre / Description / etc.
66 * @return string $flux
68 function calculer_meta_tags(){
70 include_spip('inc/texte');
73 $config = unserialize($GLOBALS['meta']['seo']);
75 if (isset($GLOBALS['contexte']['id_article'])){
76 $id_objet = $GLOBALS['contexte']['id_article'];
78 } elseif (isset($GLOBALS['contexte']['id_rubrique'])) {
79 $id_objet = $GLOBALS['contexte']['id_rubrique'];
87 // If the meta tags configuration is activate
92 $meta_tags = $config['meta_tags']['tag'];
95 $table = table_objet_sql($objet);
96 $id_table_objet = id_table_objet($objet);
97 $title = couper(sql_getfetsel("titre", $table, "$id_table_objet = " . intval($id_objet)), 64);
98 $requete = sql_allfetsel("descriptif,texte", $table, "$id_table_objet = " . intval($id_objet));
99 if ($requete) $description = couper(implode(" ", $requete[0]), 150, '');
100 // Get the value set by default
101 foreach ($config['meta_tags']['default'] as $name => $option){
102 if ($option=='sommaire'){
103 $meta_tags[$name] = $config['meta_tags']['tag'][$name];
104 } elseif ($option=='page') {
105 if ($name=='title') $meta_tags['title'] = $title;
106 if ($name=='description') $meta_tags['description'] = $description;
107 } elseif ($option=='page_sommaire') {
108 if ($name=='title') $meta_tags['title'] = $title . (($title!='') ?
' - ' : '') . $config['meta_tags']['tag'][$name];
109 if ($name=='description') $meta_tags['description'] = $description . (($description!='') ?
' - ' : '') . $config['meta_tags']['tag'][$name];
113 // If the meta tags rubrique and articles editing is activate (should overwrite other setting)
114 if ($config['meta_tags']['activate_editing']=='yes' && ($objet=='article' ||
$objet=='rubrique')){
115 $result = sql_select("*", "spip_seo", "id_objet = " . intval($id_objet) . " AND objet = " . sql_quote($objet));
116 while ($r = sql_fetch($result)){
117 if ($r['meta_content']!='')
118 $meta_tags[$r['meta_name']] = $r['meta_content'];
127 function generer_meta_tags($meta_tags = null){
129 //Set meta list if not provided
130 if (!is_array($meta_tags))
131 $meta_tags = calculer_meta_tags();
133 // Print the result on the page
134 foreach ($meta_tags as $name => $content){
137 $flux .= '<title>' . trim(htmlspecialchars(supprimer_numero(textebrut(propre($content))))) . '</title>' . "\n";
139 $flux .= '<meta name="' . $name . '" content="' . trim(htmlspecialchars(textebrut(propre($content)))) . '" />' . "\n";
146 * Renvoyer une META toute seule (hors balise)
148 * @return string|bool
150 function generer_meta_brute($nom){
151 $config = unserialize($GLOBALS['meta']['seo']);
152 $nom = strtolower($nom);
154 if ($config['meta_tags']['tag'][$nom]){
155 return $config['meta_tags']['tag'][$nom];
162 * Renvoyer la META GOOGLE WEBMASTER TOOLS
163 * @return string $flux
165 function generer_webmaster_tools(){
167 $config = unserialize($GLOBALS['meta']['seo']);
169 if ($config['webmaster_tools']['id'])
170 return '<meta name="google-site-verification" content="' . $config['webmaster_tools']['id'] . '" />
176 * Renvoyer la META BING TOOLS
177 * @return string $flux
179 function generer_bing(){
181 $config = unserialize($GLOBALS['meta']['seo']);
183 if ($config['bing']['id'])
184 return '<meta name="msvalidate.01" content="' . $config['bing']['id'] . '" />
189 * Renvoyer la META ALEXA
190 * @return string $flux
192 function generer_alexa(){
194 $config = unserialize($GLOBALS['meta']['seo']);
196 if ($config['alexa']['id'])
197 return '<meta name="alexaVerifyID" content="' . $config['alexa']['id'] . '"/>';
202 * Renvoyer la balise <link> pour URL CANONIQUES
204 function balise_SEO_URL($p){
205 $p->code
= "calculer_balise_SEO_URL()";
209 function calculer_balise_SEO_URL(){
210 $flux = generer_urls_canoniques();
216 * Renvoyer la balise SCRIPT de Google Analytics
218 function balise_SEO_GA($p){
219 $p->code
= "calculer_balise_SEO_GA()";
223 function calculer_balise_SEO_GA(){
224 $flux = generer_google_analytics();
230 * Renvoyer les META Classiques
231 * - Meta Titre / Description / etc.
233 function balise_SEO_META_TAGS($p){
234 $p->code
= "calculer_balise_SEO_META_TAGS()";
238 function calculer_balise_SEO_META_TAGS(){
239 $flux = generer_meta_tags();
244 * #SEO_META_BRUTE{nom_de_la_meta}
245 * Renvoyer la valeur de la meta appelée (sans balise)
247 function balise_SEO_META_BRUTE($p){
248 $_nom = str_replace("'", "", interprete_argument_balise(1, $p));
249 $p->code
= "calculer_balise_META_BRUTE($_nom)";
250 $p->interdire_scripts
= false;
254 function calculer_balise_META_BRUTE($_nom){
255 $metas = calculer_meta_tags();
256 $meta = $metas[$_nom];
264 * Renvoyer la META GOOGLE WEBMASTER TOOLS
266 function balise_SEO_GWT($p){
267 $p->code
= "calculer_balise_SEO_GWT()";
271 function calculer_balise_SEO_GWT(){
272 $flux = generer_webmaster_tools();