1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Renvoyer la balise <link> pour URL CANONIQUES |
---|
5 | * @return string $flux |
---|
6 | */ |
---|
7 | function generer_urls_canoniques(){ |
---|
8 | include_spip('balise/url_'); |
---|
9 | |
---|
10 | if (count($GLOBALS['contexte']) == 0) { |
---|
11 | $type_object = 'sommaire'; |
---|
12 | } elseif (isSet($GLOBALS['contexte']['id_article'])) { |
---|
13 | $id_object = $GLOBALS['contexte']['id_article']; |
---|
14 | $type_object = 'article'; |
---|
15 | } elseif (isSet($GLOBALS['contexte']['id_rubrique'])) { |
---|
16 | $id_object = $GLOBALS['contexte']['id_rubrique']; |
---|
17 | $type_object = 'rubrique'; |
---|
18 | } |
---|
19 | |
---|
20 | switch ($type_object) { |
---|
21 | case 'sommaire': |
---|
22 | $flux .= '<link rel="canonical" href="'. url_de_base() .'" />'; |
---|
23 | break; |
---|
24 | default: |
---|
25 | $flux .= '<link rel="canonical" href="'. url_de_base() . generer_url_entite($id_object, $type_object) .'" />'; |
---|
26 | break; |
---|
27 | } |
---|
28 | |
---|
29 | return $flux; |
---|
30 | } |
---|
31 | |
---|
32 | /** |
---|
33 | * Renvoyer la balise SCRIPT de Google Analytics |
---|
34 | * @return string $flux |
---|
35 | */ |
---|
36 | function generer_google_analytics(){ |
---|
37 | /* CONFIG */ |
---|
38 | $config = unserialize($GLOBALS['meta']['seo']); |
---|
39 | |
---|
40 | /* GOOGLE ANALYTICS */ |
---|
41 | if($config['analytics']['id']){ |
---|
42 | // Nouvelle balise : http://www.google.com/support/analytics/bin/answer.py?hl=fr_FR&answer=174090&utm_id=ad |
---|
43 | $flux .= "<script type=\"text/javascript\"> |
---|
44 | var _gaq = _gaq || []; |
---|
45 | _gaq.push(['_setAccount', '".$config['analytics']['id']."']); |
---|
46 | _gaq.push(['_trackPageview']); |
---|
47 | (function() { |
---|
48 | var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; |
---|
49 | ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
---|
50 | var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); |
---|
51 | })(); |
---|
52 | </script> |
---|
53 | "; |
---|
54 | } |
---|
55 | |
---|
56 | return $flux; |
---|
57 | } |
---|
58 | |
---|
59 | /** |
---|
60 | * Renvoyer les META Classiques |
---|
61 | * - Meta Titre / Description / etc. |
---|
62 | * @return string $flux |
---|
63 | */ |
---|
64 | function generer_meta_tags(){ |
---|
65 | include_spip('inc/abstract_sql'); |
---|
66 | |
---|
67 | /* CONFIG */ |
---|
68 | $config = unserialize($GLOBALS['meta']['seo']); |
---|
69 | |
---|
70 | if (isSet($GLOBALS['contexte']['id_article'])) { |
---|
71 | $id_object = $GLOBALS['contexte']['id_article']; |
---|
72 | $type_object = 'article'; |
---|
73 | } elseif (isSet($GLOBALS['contexte']['id_rubrique'])) { |
---|
74 | $id_object = $GLOBALS['contexte']['id_rubrique']; |
---|
75 | $type_object = 'rubrique'; |
---|
76 | } else{ |
---|
77 | $type_object = 'sommaire'; |
---|
78 | } |
---|
79 | |
---|
80 | /* META TAGS */ |
---|
81 | |
---|
82 | // If the meta tags configuration is activate |
---|
83 | $meta_tags = array(); |
---|
84 | |
---|
85 | switch ($type_object) { |
---|
86 | case 'sommaire': |
---|
87 | $meta_tags = $config['meta_tags']['tag']; |
---|
88 | break; |
---|
89 | default: |
---|
90 | $title = couper(sql_getfetsel("titre", "spip_".$type_object."s", "id_$type_object = $id_object"),64); |
---|
91 | $requete = sql_allfetsel("descriptif,texte", "spip_".$type_object."s", "id_$type_object = $id_object"); |
---|
92 | if($requete) $description = couper(implode(" ",$requete[0]),150,''); |
---|
93 | // Get the value set by default |
---|
94 | foreach ($config['meta_tags']['default'] as $name => $option) { |
---|
95 | if ($option == 'sommaire') { |
---|
96 | $meta_tags[$name] = $config['meta_tags']['tag'][$name]; |
---|
97 | } elseif ($option == 'page') { |
---|
98 | if ($name == 'title') $meta_tags['title'] = $title; |
---|
99 | if ($name == 'description') $meta_tags['description'] = $description; |
---|
100 | } elseif ($option == 'page_sommaire') { |
---|
101 | if ($name == 'title') $meta_tags['title'] = $title . (($title!='')?' - ':'') . $config['meta_tags']['tag'][$name]; |
---|
102 | if ($name == 'description') $meta_tags['description'] = $description . (($description!='')?' - ':'') . $config['meta_tags']['tag'][$name]; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | // If the meta tags rubrique and articles editing is activate (should overwrite other setting) |
---|
107 | if ($config['meta_tags']['activate_editing'] == 'yes' && ($type_object == 'article' || $type_object == 'rubrique')) { |
---|
108 | $result = sql_select("*", "spip_seo", "id_object = $id_object AND type_object = '$type_object'"); |
---|
109 | while($r = sql_fetch($result)){ |
---|
110 | if ($r['meta_content'] != '') |
---|
111 | $meta_tags[$r['meta_name']] = $r['meta_content']; |
---|
112 | } |
---|
113 | } |
---|
114 | break; |
---|
115 | } |
---|
116 | |
---|
117 | // Print the result on the page |
---|
118 | foreach ($meta_tags as $name => $content) { |
---|
119 | if ($content != '') |
---|
120 | if ($name=='title') |
---|
121 | $flux .= '<title>'. htmlspecialchars(supprimer_numero(textebrut(propre($content)))) .'</title>'."\n"; |
---|
122 | else |
---|
123 | $flux .= '<meta name="'. $name .'" content="'. htmlspecialchars(textebrut(propre($content))) .'" />'."\n"; |
---|
124 | } |
---|
125 | |
---|
126 | return $flux; |
---|
127 | } |
---|
128 | |
---|
129 | /** |
---|
130 | * Renvoyer une META toute seule (hors balise) |
---|
131 | * @return string $retour |
---|
132 | */ |
---|
133 | function generer_meta_brute($nom){ |
---|
134 | $config = unserialize($GLOBALS['meta']['seo']); |
---|
135 | $nom = strtolower($nom); |
---|
136 | |
---|
137 | if($config['meta_tags']['tag'][$nom]){ |
---|
138 | return $config['meta_tags']['tag'][$nom]; |
---|
139 | } |
---|
140 | |
---|
141 | return false; |
---|
142 | } |
---|
143 | |
---|
144 | /** |
---|
145 | * Renvoyer la META GOOGLE WEBMASTER TOOLS |
---|
146 | * @return string $flux |
---|
147 | */ |
---|
148 | function generer_webmaster_tools(){ |
---|
149 | /* CONFIG */ |
---|
150 | $config = unserialize($GLOBALS['meta']['seo']); |
---|
151 | |
---|
152 | if($config['webmaster_tools']['id']){ |
---|
153 | $flux .= '<meta name="google-site-verification" content="'. $config['webmaster_tools']['id'] .'"/>'; |
---|
154 | } |
---|
155 | |
---|
156 | return $flux; |
---|
157 | } |
---|
158 | |
---|
159 | /** |
---|
160 | * Renvoyer la META ALEXA |
---|
161 | * @return string $flux |
---|
162 | */ |
---|
163 | function generer_alexa(){ |
---|
164 | /* CONFIG */ |
---|
165 | $config = unserialize($GLOBALS['meta']['seo']); |
---|
166 | |
---|
167 | if($config['alexa']['id']){ |
---|
168 | $flux .= '<meta name="alexaVerifyID" content="'. $config['alexa']['id'] .'"/>'; |
---|
169 | } |
---|
170 | |
---|
171 | return $flux; |
---|
172 | } |
---|