1 | <?php |
---|
2 | |
---|
3 | // Secteur wiki |
---|
4 | define('SECTEUR_WIKI', 607); |
---|
5 | |
---|
6 | /** |
---|
7 | * Critere {tout_voir} permet de deverouiller l'acces restreint sur une boucle |
---|
8 | * |
---|
9 | * @param unknown_type $idb |
---|
10 | * @param unknown_type $boucles |
---|
11 | * @param unknown_type $crit |
---|
12 | */ |
---|
13 | if (!function_exists('critere_tout_voir_dist')){ |
---|
14 | function critere_tout_voir_dist($idb, &$boucles, $crit) { |
---|
15 | $boucle = &$boucles[$idb]; |
---|
16 | $boucle->modificateur['tout_voir'] = true; |
---|
17 | } |
---|
18 | } |
---|
19 | |
---|
20 | // true quand on vient du wiki |
---|
21 | // true dans l'espace prive |
---|
22 | // true dans les crayons |
---|
23 | // false dans les autres pages (publiques hors wiki) |
---|
24 | function boucle_exclure_secteur() { |
---|
25 | return |
---|
26 | ( |
---|
27 | _DIR_RESTREINT=='' |
---|
28 | OR _request('action') |
---|
29 | OR (defined('RUBRIQUE_WIKI_OK') AND RUBRIQUE_WIKI_OK) |
---|
30 | ) |
---|
31 | ? '0' |
---|
32 | : SECTEUR_WIKI |
---|
33 | ; |
---|
34 | } |
---|
35 | |
---|
36 | // |
---|
37 | // <BOUCLE(ARTICLES)> sans le wiki (secteur 607) |
---|
38 | // |
---|
39 | function boucle_ARTICLES($id_boucle, &$boucles) { |
---|
40 | $boucle = &$boucles[$id_boucle]; |
---|
41 | $id_table = $boucle->id_table; |
---|
42 | |
---|
43 | if (!$boucle->modificateur['tout_voir']) |
---|
44 | $boucle->where[] = array("'!='", "'$id_table.id_secteur'", 'sql_quote(boucle_exclure_secteur())'); |
---|
45 | |
---|
46 | return boucle_ARTICLES_dist($id_boucle, $boucles); |
---|
47 | } |
---|
48 | |
---|
49 | // |
---|
50 | // <BOUCLE(RUBRIQUES)> sans le wiki (secteur 607) |
---|
51 | // |
---|
52 | function boucle_RUBRIQUES($id_boucle, &$boucles) { |
---|
53 | $boucle = &$boucles[$id_boucle]; |
---|
54 | $id_table = $boucle->id_table; |
---|
55 | |
---|
56 | if (!$boucle->modificateur['tout_voir']) |
---|
57 | $boucle->where[] = array("'!='", "'$id_table.id_secteur'", 'sql_quote(boucle_exclure_secteur())'); |
---|
58 | |
---|
59 | return boucle_RUBRIQUES_dist($id_boucle, $boucles); |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | function date_rfc822($date_heure) { |
---|
64 | list($annee, $mois, $jour) = recup_date($date_heure); |
---|
65 | list($heures, $minutes, $secondes) = recup_heure($date_heure); |
---|
66 | $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
---|
67 | return gmdate("D, d M Y H:i:s +0100", $time); |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | function dec2hex($v) { |
---|
73 | return substr('00'.dechex($v), -2); |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | function age_style($date) { |
---|
78 | |
---|
79 | // $decal en secondes |
---|
80 | $decal = date("U") - date("U", strtotime($date)); |
---|
81 | |
---|
82 | // 3 jours = vieux |
---|
83 | $decal = min(1.0, sqrt($decal/(3*24*3600))); |
---|
84 | |
---|
85 | // Quand $decal = 0, c'est tout neuf : couleur vive |
---|
86 | // Quand $decal = 1, c'est vieux : bleu pale |
---|
87 | $red = ceil(128+127*(1-$decal)); |
---|
88 | $blue = ceil(130+60*$decal); |
---|
89 | $green = ceil(200+55*(1-$decal)); |
---|
90 | |
---|
91 | $couleur = dec2hex($red).dec2hex($green).dec2hex($blue); |
---|
92 | |
---|
93 | return 'background-color: #'.$couleur.';'; |
---|
94 | } |
---|
95 | |
---|
96 | if (!function_exists('generer_url_site')){ |
---|
97 | function generer_url_site($id){ |
---|
98 | return generer_url_entite($id,'site'); |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | function compter_visiteurs(){ |
---|
103 | return count(preg_files(_DIR_TMP.'visites/','.')); |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | function ohloh_widgetize($bio,$id_auteur,$email){ |
---|
108 | if (!$email OR !$id_auteur=intval($id_auteur)) return $bio; |
---|
109 | if (strpos($bio,"www.ohloh.net")!==FALSE) return $bio; |
---|
110 | $hash = md5($email); |
---|
111 | include_spip('inc/distant'); |
---|
112 | $oh = recuperer_page("http://www.ohloh.net/accounts/$hash/widgets"); |
---|
113 | if (!$oh |
---|
114 | OR count($widgets = extraire_balises($oh,'textarea'))<5) |
---|
115 | $widget = "Pas de compte sur www.ohloh.net"; |
---|
116 | else { |
---|
117 | $widget = preg_replace(',^<textarea[^>]*>,i','',$widgets[4]); |
---|
118 | $widget = preg_replace(',</textarea>$,i','',$widget); |
---|
119 | $widget = html_entity_decode($widget); |
---|
120 | } |
---|
121 | |
---|
122 | $bio .= $widget; |
---|
123 | // mettons a jour sauvagement ! |
---|
124 | include_spip('abstract_sql'); |
---|
125 | $bio_sql = sql_getfetsel('bio','spip_auteurs','id_auteur='.intval($id_auteur)); |
---|
126 | sql_updateq('spip_auteurs',array('bio'=>$bio_sql."\n".$widget),'id_auteur='.intval($id_auteur)); |
---|
127 | return $bio; |
---|
128 | } |
---|
129 | /* |
---|
130 | function critere_compteur($idb, &$boucles, $crit){ |
---|
131 | $boucle = &$boucles[$idb]; |
---|
132 | |
---|
133 | $params = $crit->param; |
---|
134 | $table = array_shift($params); |
---|
135 | $table = $table[0]->texte; |
---|
136 | if(preg_match(',^(\w+)([<>=])([0-9]+)$,',$table,$r)){ |
---|
137 | $table=$r[1]; |
---|
138 | $op=$r[2]; |
---|
139 | $op_val=$r[3]; |
---|
140 | } |
---|
141 | $type = objet_type($table); |
---|
142 | $type_id = id_table_objet($type); |
---|
143 | $table_sql = table_objet_sql($type); |
---|
144 | |
---|
145 | $trouver_table = charger_fonction('trouver_table','base'); |
---|
146 | $arrivee = array($table, $trouver_table($table, $boucle->sql_serveur)); |
---|
147 | $depart = array($boucle->id_table,$trouver_table($boucle->id_table, $boucle->sql_serveur)); |
---|
148 | |
---|
149 | if ($compt = calculer_jointure($boucle,$depart,$arrivee)){ |
---|
150 | |
---|
151 | $boucle->select[]= "COUNT($compt.$type_id) AS compteur_$table"; |
---|
152 | if ($op) |
---|
153 | $boucle->having[]= array("'".$op."'", "'compteur_".$table."'",$op_val); |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | function balise_COMPTEUR_dist($p) { |
---|
158 | $p->code = ''; |
---|
159 | if (isset($p->param[0][1][0]) |
---|
160 | AND $champ = ($p->param[0][1][0]->texte)) |
---|
161 | return rindex_pile($p, "compteur_$champ", 'compteur'); |
---|
162 | return $p; |
---|
163 | } |
---|
164 | */ |
---|
165 | |
---|
166 | function sc_versions_compatibles($id,$type){ |
---|
167 | $compatibles = array(); |
---|
168 | |
---|
169 | static $versions = array( |
---|
170 | 190=>'SPIP 1.9.0', |
---|
171 | 191=>'SPIP 1.9.1', |
---|
172 | 192=>'SPIP 1.9.2', |
---|
173 | 200=>'SPIP 2.0.0', |
---|
174 | ); |
---|
175 | static $versions_min_inc=array( |
---|
176 | 12=>array(190,191,192,200), // toutes versions de spip... |
---|
177 | 100=>array(190,191,192), // 1.9 toutes versions sans plus de precision... |
---|
178 | 258=>array(190), // 1.9.0 |
---|
179 | 119=>array(191), // 1.9.1 |
---|
180 | 120=>array(192), // 1.9.2 |
---|
181 | 261=>array(200), // 2.0.0 |
---|
182 | ); |
---|
183 | static $versions_max_excl = array( |
---|
184 | 260 => array(190,191,192,200), |
---|
185 | 259 => array(200), |
---|
186 | ); |
---|
187 | |
---|
188 | include_spip('base/abstract_sql'); |
---|
189 | $id_objet = id_table_objet($type); |
---|
190 | $mot_min = array_map('reset',sql_allfetsel('id_mot',"spip_mots_".$type.'s',"$id_objet=".intval($id) . " AND " . sql_in('id_mot',array_keys($versions_min_inc)))); |
---|
191 | foreach($mot_min as $mot) |
---|
192 | if (isset($versions_min_inc[$mot])) |
---|
193 | $compatibles = array_merge($compatibles,$versions_min_inc[$mot]); |
---|
194 | if (!count($compatibles)) |
---|
195 | return ""; |
---|
196 | $compatibles = array_unique($compatibles); |
---|
197 | |
---|
198 | $mot_max = array_map('reset',sql_allfetsel('id_mot',"spip_mots_".$type.'s',"$id_objet=".intval($id) . " AND " . sql_in('id_mot',array_keys($versions_max_excl)))); |
---|
199 | foreach($mot_max as $mot) |
---|
200 | if (isset($versions_max_excl[$mot])) |
---|
201 | $compatibles = array_diff($compatibles,$versions_max_excl[$mot]); |
---|
202 | if (!count($compatibles)) |
---|
203 | return ""; |
---|
204 | |
---|
205 | $res = ""; |
---|
206 | foreach ($compatibles as $v) |
---|
207 | $res .= "<li>".$versions[$v]."</li>"; |
---|
208 | return $res; |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | function filtre_date_dist($time,$format){return date($format,$time);} |
---|
213 | |
---|
214 | // Retire les liens en syntaxe Trac: [URL titre] ---> titre |
---|
215 | |
---|
216 | function tracbrut($texte) |
---|
217 | { |
---|
218 | if (preg_match_all('/[[][^ ]* *([^]]*)]/', $texte, $m, PREG_SET_ORDER)) |
---|
219 | foreach($m as $r) |
---|
220 | $texte = str_replace($r[0], $r[1], $texte); |
---|
221 | return $texte ? $texte : 'Log'; |
---|
222 | } |
---|
223 | ?> |
---|