/** * Composer le code d'inclusion PHP * * @param string $fichier * @param Object $p * @return string */ function sandbox_composer_inclure_php($fichier, &$p) { $compil = texte_script(memoriser_contexte_compil($p)); // si inexistant, on essaiera a l'execution if ($path = find_in_path($fichier)) { $path = "\"{$path}\""; } else { $path = "find_in_path(\"{$fichier}\")"; } return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil); }
function formulaires_configurer_identite_traiter_dist() { include_spip('inc/config'); set_request('adresse_site', appliquer_adresse_site(_request('adresse_site'))); include_spip('inc/meta'); foreach (array('nom_site', 'slogan_site', 'descriptif_site', 'email_webmaster') as $k) { ecrire_meta($k, _request($k)); } include_spip('inc/texte_mini'); $reload = texte_script(couper(_request('nom_site'), 35)); $reload = "<script type='text/javascript'>if (window.jQuery) jQuery('#bando_identite .nom_site_spip .nom').html('{$reload}');</script>"; return array('message_ok' => _T('config_info_enregistree') . $reload, 'editable' => true); }
function socialtags_choix() { include_spip('socialtags_fonctions'); global $couleur_fonce; $cfg = is_array($cfg = lire_config('socialtags/tags')) ? $cfg : array(); $retour = array(); foreach (socialtags_liste() as $service) { $t = $service['titre']; $u = $service['url']; $a = $service['lesauteurs']; $d = isset($service['descriptif']) ? $service['descriptif'] : ''; $category = count($service['tags']) ? textebrut(reset($service['tags'])) : '99'; $image = 'data:image/png;base64,' . base64_encode(file_get_contents(find_in_path('images/' . $a . '.png'))); //$image = find_in_path('images/'.$a.'.png'); $checked = in_array($a, $cfg) ? ' checked="checked"' : ''; $retour[$category] .= "<div class='choix'>\n\t\t\t\t<input type='checkbox' id='choix_{$a}' name='tags[]' value='{$a}'{$checked} />\n\t\t\t\t<label for='choix_{$a}'>\n\t\t\t\t\t<img src=\"{$image}\" title=\"" . texte_script($t) . "\" alt=\"\" style=\"max-width:16px; height:auto;\" />\n\t\t\t\t\t" . ($checked ? "<strong>{$t}</strong>" : $t) . ($d ? " <span style='color:{$couleur_fonce};font-size:90%'>{$d}</span>" : "") . "\n\t\t\t\t</label>\n\t\t\t</div>"; } ksort($retour); return implode("<hr />", $retour); }
/** * Construitre l'email personalise de notification d'un forum * * @param array $t * @param string $email * @param array $contexte * @return string */ function inc_email_notification_forum_dist($t, $email, $contexte = array()) { static $contextes_store = array(); if (!isset($contextes_store[$t['id_forum']])) { $url = ''; $id_forum = $t['id_forum']; if ($t['statut'] == 'prive') { if ($t['id_objet']) { $url = generer_url_entite($t['id_objet'], $t['objet'], '', 'forum' . $id_forum, false); } } else { if ($t['statut'] == 'privrac') { $url = generer_url_ecrire('forum') . '#forum' . $id_forum; } else { if ($t['statut'] == 'privadm') { $url = generer_url_ecrire('forum', 'quoi=admin') . '#forum' . $id_forum; } else { if ($t['statut'] == 'publie') { $url = generer_url_entite($id_forum, 'forum'); } else { $url = generer_url_ecrire('controler_forum', "debut_id_forum=" . $id_forum); } } } } if (!$url) { spip_log("forum {$id_forum} sans referent", 'notifications'); $url = './'; } if ($t['id_objet']) { include_spip('inc/filtres'); $t['titre_source'] = generer_info_entite($t['id_objet'], $t['objet'], 'titre'); } $t['url'] = $url; // detecter les url des liens du forum // pour la moderation (permet de reperer les SPAMS avec des liens caches) // il faut appliquer le traitement de raccourci car sinon on rate des liens sous forme [->..] utilises par les spammeurs ! include_spip("public/interfaces"); $table_objet = "forum"; $links = array(); foreach ($t as $champ => $v) { $champ = strtoupper($champ); $traitement = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : null; if (is_array($traitement) and (isset($traitement[$table_objet]) or isset($traitement[0]))) { $traitement = $traitement[isset($traitement[$table_objet]) ? $table_objet : 0]; $traitement = str_replace('%s', "'" . texte_script($v) . "'", $traitement); eval("\$v = {$traitement};"); } $links = $links + extraire_balises($v, 'a'); } $links = extraire_attribut($links, 'href'); $links = implode("\n", $links); $t['liens'] = $links; $contextes_store[$t['id_forum']] = $t; } $fond = "notifications/forum_poste"; if (isset($contexte['fond'])) { $fond = $contexte['fond']; unset($contexte['fond']); } $t = array_merge($contextes_store[$t['id_forum']], $contexte); // Rechercher eventuellement la langue du destinataire if (null !== ($l = sql_getfetsel('lang', 'spip_auteurs', "email=" . sql_quote($email)))) { $l = lang_select($l); } $parauteur = strlen($t['auteur']) <= 2 ? '' : " " . _T('forum_par_auteur', array('auteur' => $t['auteur'])) . ($t['email_auteur'] ? ' <' . $t['email_auteur'] . '>' : ''); $titre = textebrut(typo($t['titre_source'])); if ($titre) { $forum_poste_par = _T($t['objet'] == 'article' ? 'forum:forum_poste_par' : 'forum:forum_poste_par_generique', array('parauteur' => $parauteur, 'titre' => $titre, 'objet' => $t['objet'])); } else { $forum_poste_par = _T('forum:forum_poste_par_court', array('parauteur' => $parauteur)); } $t['par_auteur'] = $forum_poste_par; $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email $corps = recuperer_fond($fond, $t); if ($l) { lang_select(); } return $corps; }
function argumenter_squelette($v) { if (!is_array($v)) { return "'" . texte_script($v) . "'"; } else { $out = array(); foreach ($v as $k => $val) { $out[] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); } return 'array(' . join(", ", $out) . ')'; } }
/** * si le champ virtuel est non vide c'est une redirection. * avec un eventuel raccourci Spip * si le raccourci a un titre il sera pris comme corps du 302 * * http://code.spip.net/@tester_redirection * * @param string $fond * @param array $contexte * @param string $connect * @return array|bool */ function tester_redirection($fond, $contexte, $connect) { if ($fond == 'article' and $id_article = intval($contexte['id_article'])) { include_spip('public/quete'); // pour quete_virtuel et ses dependances $m = quete_virtuel($id_article, $connect); if (strlen($m)) { include_spip('inc/texte'); // les navigateurs pataugent si l'URL est vide if ($url = virtuel_redirige($m, true)) { // passer en url absolue car cette redirection pourra // etre utilisee dans un contexte d'url qui change // y compris url arbo $status = 302; if (defined('_STATUS_REDIRECTION_VIRTUEL')) { $status = _STATUS_REDIRECTION_VIRTUEL; } if (!preg_match(',^\\w+:,', $url)) { include_spip('inc/filtres_mini'); $url = url_absolue($url); } $url = str_replace('&', '&', $url); return array('texte' => "<" . "?php include_spip('inc/headers');redirige_par_entete('" . texte_script($url) . "','',{$status});" . "?" . ">", 'process_ins' => 'php', 'status' => $status); } } } return false; }
/** * Compile une inclusion <INCLURE> ou #INCLURE * * @param Inclure $p * Description de l'inclusion (AST au niveau de l'inclure) * @param array $boucles * AST du squelette * @param string $id_boucle * Identifiant de la boucle contenant l'inclure * @return string * Code PHP appelant l'inclusion **/ function calculer_inclure($p, &$boucles, $id_boucle) { $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); if (is_string($p->texte)) { $fichier = $p->texte; $code = "\"{$fichier}\""; } else { $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { $fichier = $r[1]; } else { $fichier = ''; } } if (!$code or $code === '""') { $erreur_p_i_i = array('zbug_parametres_inclus_incorrects', array('param' => $code)); erreur_squelette($erreur_p_i_i, $p); return false; } $compil = texte_script(memoriser_contexte_compil($p)); if (is_array($_contexte)) { // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) if ($env = isset($_contexte['env']) || isset($_contexte['self'])) { unset($_contexte['env']); } // noter les doublons dans l'appel a public.php if (isset($_contexte['doublons'])) { $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; } if ($ajax = isset($_contexte['ajax'])) { $ajax = preg_replace(",=>(.*)\$,ims", '=> ($v=(\\1))?$v:true', $_contexte['ajax']); unset($_contexte['ajax']); } $_contexte = join(",\n\t", $_contexte); } else { return false; } // j'aurais voulu toucher le fond ... $contexte = 'array(' . $_contexte . ')'; if ($env) { $contexte = "array_merge('.var_export(\$Pile[0],1).',{$contexte})"; } // s'il y a une extension .php, ce n'est pas un squelette if (preg_match('/^.+[.]php$/s', $fichier)) { $code = sandbox_composer_inclure_php($fichier, $p, $contexte); } else { $_options[] = "\"compil\"=>array({$compil})"; if ($ajax) { $_options[] = $ajax; } $code = " ' . argumenter_squelette({$code}) . '"; $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), "_request(\"connect\")") . ';'; } return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; }
/** * Appliquer a un champ SQL le traitement qui est configure pour la balise homonyme dans les squelettes * * @param string $texte * @param string $champ * @param string $table_objet * @param array $env * @param string $connect * @return string */ function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') { if (!$champ) { return $texte; } $champ = strtoupper($champ); $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; if (!$traitements or !is_array($traitements)) { return $texte; } $traitement = ''; if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg $table_objet = table_objet($table_objet); if (isset($traitements[$table_objet])) { $traitement = $traitements[$table_objet]; } } if (!$traitement and isset($traitements[0])) { $traitement = $traitements[0]; } // (sinon prendre le premier de la liste par defaut ?) if (!$traitement) { return $texte; } $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); // Fournir $connect et $Pile[0] au traitement si besoin $Pile = array(0 => $env); eval("\$texte = {$traitement};"); return $texte; }
function calculer_inclure($p, &$boucles, $id_boucle){ $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); if (is_string($p->texte)){ $fichier = $p->texte; $code = "\"$fichier\""; } else { $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); if ($code AND preg_match("/^'([^']*)'/s", $code, $r)) $fichier = $r[1]; else $fichier = ''; } if (!$code OR $code==='""'){ $erreur_p_i_i = array('zbug_parametres_inclus_incorrects', array('param' => $code)); erreur_squelette($erreur_p_i_i, $p); return false; } $compil = texte_script(memoriser_contexte_compil($p)); if (is_array($_contexte)){ // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) if ($env = (isset($_contexte['env']) || isset($_contexte['self']))){ unset($_contexte['env']); } // noter les doublons dans l'appel a public.php if (isset($_contexte['doublons'])){ $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; } if ($ajax = isset($_contexte['ajax'])) unset($_contexte['ajax']); $_contexte = join(",\n\t", $_contexte); } else return false; // j'aurais voulu toucher le fond ... $contexte = 'array(' . $_contexte . ')'; if ($env){ $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; } // s'il y a une extension .php, ce n'est pas un squelette if (preg_match('/^.+[.]php$/s', $fichier)){ // si inexistant, on essaiera a l'execution if ($path = find_in_path($fichier)) $path = "\"$path\""; else $path = "find_in_path(\"$fichier\")"; $code = sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil); } else { $_options[] = "\"compil\"=>array($compil)"; if ($ajax) $_options[] = "\"ajax\"=>true"; $code = " ' . argumenter_squelette($code) . '"; $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), "_request(\"connect\")") . ';'; } return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; }
/** * Ajoute Chosen aux css chargées dans le public * * @param string $texte Contenu du head HTML concernant les CSS * @return string Contenu du head HTML concernant les CSS **/ function chosen_insert_head($flux) { include_spip('inc/config'); $config = lire_config('chosen',array()); if (isset($config['active']) and $config['active']=='oui') { $flux .= '<script type="text/javascript">/* <![CDATA[ */ var selecteur_chosen = "' . trim(isset($config['selecteur_commun']) ? $config['selecteur_commun'] : '') . '"; var langue_chosen = { placeholder_text_single : "'.texte_script(_T('chosen:lang_select_an_option')).'", placeholder_text_multiple : "'.texte_script(_T('chosen:lang_select_some_option')).'", no_results_text : "'.texte_script(_T('chosen:lang_no_result')).'" }; var chosen_create_option = { create_option: function(term) { this.select_append_option( {value: "chosen_" + term, text: term} ); }, persistent_create_option: true, skip_no_results: true, create_option_text: "'.texte_script(_T('chosen:lang_create_option')).'" }; /* ]]> */</script>'."\n"; } return $flux; }
function agenda_memo($date=0 , $descriptif='', $titre='', $url='', $cal='') { static $agenda = array(); if (!$date) return $agenda; $idate = date_ical($date); $cal = trim($cal); // func_get_args (filtre alterner) rajoute \n !!!! $agenda[$cal][(date_anneemoisjour($date))][] = array( 'CATEGORIES' => $cal, 'DTSTART' => $idate, 'DTEND' => $idate, 'DESCRIPTION' => texte_script($descriptif), 'SUMMARY' => texte_script($titre), 'URL' => $url); // toujours retourner vide pour qu'il ne se passe rien return ""; }
/** * si le champ virtuel est non vide c'est une redirection. * avec un eventuel raccourci Spip * si le raccourci a un titre il sera pris comme corps du 302 * * http://doc.spip.org/@tester_redirection * * @param string $fond * @param array $contexte * @param string $connect * @return array|bool */ function tester_redirection($fond, $contexte, $connect) { if ($fond == 'article' and $id_article = intval($contexte['id_article'])) { include_spip('public/quete'); // pour quete_virtuel et ses dependances $m = quete_virtuel($id_article, $connect); if (strlen($m)) { include_spip('inc/texte'); // les navigateurs pataugent si l'URL est vide if ($url = virtuel_redirige($m, true)) { // passer en url absolue car cette redirection pourra // etre utilisee dans un contexte d'url qui change // y compris url arbo if (!preg_match(',^\\w+:,', $url)) { include_spip('inc/filtres_mini'); $url = url_absolue($url); } $url = str_replace('&', '&', $url); return array('texte' => "<" . "?php header('Location: " . texte_script($url) . "'); echo '" . addslashes($url) . "'.\"\n\"?" . ">", 'process_ins' => 'php'); } } } return false; }
/** * Appliquer a un champ SQL le traitement qui est configure pour la balise homonyme dans les squelettes * * @param string $texte * @param string $champ * @param string $table_sql * @param array $env * @param string $connect * @return string */ function appliquer_traitement_champ($texte, $champ, $table_sql = '', $env = array(), $connect = '') { if (!$champ) { return $texte; } $champ = strtoupper($champ); $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; if (!$traitements) { return $texte; } $traitement = ''; if (isset($traitements[$table_sql])) { $traitement = $traitements[$table_sql]; } elseif (isset($traitements[0])) { $traitement = $traitements[0]; } if (!$traitement) { return $texte; } $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); // Fournir $connect et $Pile[0] au traitement si besoin $Pile = array(0 => $env); eval("\$texte = {$traitement};"); return $texte; }
function exec_agenda_inscriptions_dist() { $id_evenement = intval(_request('id_evenement')); $evenement = sql_fetsel(array('titre','date_debut'), 'spip_evenements', array("id_evenement=$id_evenement","inscription=1")); // recupere les infos de l'evenement $format = _request('format'); if ($GLOBALS['auteur_session']['statut'] != '0minirezo') { include_spip('inc/minipres'); echo minipres(_T('info_acces_refuse')); } elseif ($evenement === false) { include_spip('inc/minipres'); echo minipres(_T('agenda:aucun_evenement')); } else { $retirer_auteur = intval(_request('retirer_auteur')); if ($retirer_auteur) { sql_delete('spip_evenements_participants', "id_auteur=$retirer_auteur AND id_evenement=$id_evenement"); } if ($format == 'csv') { if (_request('mode') == 'inline') { // passer &mode=inline pour voir le fichier au lieu de le télécharger header("Content-type: text/plain; charset=".$GLOBALS['meta']['charset']); } else { header('Content-Disposition: attachment; filename="'._T('agenda:liste_inscrits').' - '.addslashes($evenement['titre']).'.csv"'); // nom du fichier = Inscriptons #TITRE au #AUJOURDHUI if ($GLOBALS['meta']['charset']) header("Content-type: text/csv; charset=".$GLOBALS['meta']['charset']); else header("Content-type: text/csv"); } // liste des champs à inclure dans le CSV $champs = array( 'nom' => 'Nom', 'login' => 'Identifiant', 'email' => 'Email', 'date' => 'Date d\'inscription', 'reponse' => 'Réponse', ); $res = sql_allfetsel(array_keys($champs), 'spip_evenements_participants INNER JOIN spip_auteurs USING (id_auteur)', array("id_evenement=$id_evenement", "reponse = 'oui' OR reponse = '?'"), "date ASC"); $csv = ''; // ligne d'en-tete foreach($champs as $champ => $legende) { $csv .= '"'.str_replace('"','""', $legende).'",'; } $csv = substr($csv, 0, -1); // on supprime la derniere virgule foreach($res as $row) { $csv .= "\r\n"; foreach($champs as $champ => $legende) { if (isset($row[$champ])) { if ($champ == 'date') $row[$champ] = affdate($row[$champ], 'd/m/Y H:i:s'); $csv .= '"'.str_replace('"','""', $row[$champ]).'"'; } $csv .= ','; } $csv = substr($csv, 0, -1); // on supprime la derniere virgule } echo $csv; } else { $inscrits = sql_allfetsel(array('nom', 'reponse', 'id_auteur', 'date'), 'spip_evenements_participants INNER JOIN spip_auteurs USING (id_auteur)', array("id_evenement=$id_evenement"), "date ASC"); pipeline('exec_init',array('args'=>array('exec'=>'agenda_inscriptions', 'id_evenement'=>$id_evenement),'data'=>'')); $titre = $evenement['titre'].' ('.affdate($evenement['date_debut']).') - '._T('agenda:liste_inscrits'); $commencer_page = charger_fonction('commencer_page', 'inc'); echo $commencer_page($titre, "auteurs","redacteurs"); echo pipeline('affiche_milieu',array('args'=>array('exec'=>'agenda_inscriptions', 'id_evenement'=>$id_evenement),'data'=>'')); echo debut_gauche('', true); echo pipeline('affiche_gauche',array('args'=>array('exec'=>'agenda_inscriptions', 'id_evenement'=>$id_evenement),'data'=>'')); echo bloc_des_raccourcis( icone_horizontale (_T('agenda:telecharger').' (CSV)', generer_url_ecrire("agenda_inscriptions", "id_evenement=$id_evenement&format=csv"), "synchro-24.gif", "", false) ); echo creer_colonne_droite('', true); echo pipeline('affiche_droite',array('args'=>array('exec'=>'agenda_inscriptions', 'id_evenement'=>$id_evenement),'data'=>'')); echo debut_droite('', true), gros_titre($titre,'',false); echo debut_cadre('liste','auteur-24.gif','','','inscriptions'); echo "\n<br /><table class='arial2' cellpadding='2' cellspacing='0' style='width: 100%; border: 0px;'>\n"; echo "<tr class='titrem'><th style='width: 20px;'></th><th style='width: 20px;'></th><th>Nom</th><th>Date</th><th>Réponse</th><th></th></tr>"; $formater_auteur = charger_fonction('formater_auteur', 'inc'); foreach ($inscrits as $row) { list($s, $mail, $nom, $w, $p) = $formater_auteur($row['id_auteur']); echo "\n<tr class='tr_liste'>" . "\n<td>" . $s . "</td><td>" . $mail . "</td>" . "\n<td class='verdana1'>" . '<a href="'.generer_url_ecrire("auteur_infos","id_auteur=".$row['id_auteur']).'">' . $nom . '</a>' ."</td>" . "\n<td class='arial1'>" . affdate($row['date']).' '.affdate($row['date'], 'H:i') ."</td>" ."\n<td class='arial1'>" . $row['reponse'] . "</td><td class='arial1'>" . '<a class="arial1 editer_auteurs" href="'.generer_url_ecrire("agenda_inscriptions","id_evenement=$id_evenement&retirer_auteur=".$row['id_auteur']).'" onclick="return (confirm(\''.texte_script(_T('agenda:confirm_suppression_inscription')).'\'));">'._T('agenda:lien_desinscrire')." ". http_img_pack('croix-rouge.gif', "X", " class='puce' style='vertical-align: bottom;'").'</a>' . "</td></tr>\n"; } echo "</table>\n<br />"; echo fin_cadre(); echo fin_gauche(), fin_page(); } } }
function compose_filtres(&$p, $code) { $image_miette = false; foreach($p->param as $filtre) { $fonc = array_shift($filtre); if (!$fonc) continue; // normalement qu'au premier tour. $is_filtre_image = ((substr($fonc,0,6)=='image_') AND $fonc!='image_graver'); if ($image_miette AND !$is_filtre_image){ // il faut graver maintenant car apres le filtre en cours // on est pas sur d'avoir encore le nom du fichier dans le pipe $code = "filtrer('image_graver', $code)"; $image_miette = false; } // recuperer les arguments du filtre, // a separer par "," ou ":" dans le cas du filtre "?{a,b}" if ($fonc !== '?') { $sep = ','; } else {$sep = ':'; // |?{a,b} *doit* avoir exactement 2 arguments ; on les force if (count($filtre) != 2) $filtre = array(isset($filtre[0])?$filtre[0]:"", isset($filtre[1])?$filtre[1]:""); } $arglist = compose_filtres_args($p, $filtre, $sep); $logique = filtre_logique($fonc, $code, substr($arglist,1)); if ($logique) $code = $logique; else { if (isset($GLOBALS['spip_matrice'][$fonc])) { $code = "filtrer('$fonc',$code$arglist)"; if ($is_filtre_image) $image_miette = true; } // le filtre est defini sous forme de fonction ou de methode // par ex. dans inc_texte, inc_filtres ou mes_fonctions elseif ($f = chercher_filtre($fonc)) { $code = "$f($code$arglist)"; } // le filtre n'existe pas, // on le notifie else erreur_squelette(array('zbug_erreur_filtre', array('filtre'=> texte_script($fonc))), $p); } } // ramasser les images intermediaires inutiles et graver l'image finale if ($image_miette) $code = "filtrer('image_graver',$code)"; return $code; }
/** * Donner n'importe quelle information sur un objet de maniere generique. * * La fonction va gerer en interne deux cas particuliers les plus utilises : * l'URL et le titre (qui n'est pas forcemment le champ SQL "titre"). * * On peut ensuite personnaliser les autres infos en creant une fonction * generer_<nom_info>_entite($id_objet, $type_objet, $ligne). * $ligne correspond a la ligne SQL de tous les champs de l'objet, les fonctions * de personnalisation n'ont donc pas a refaire de requete. * * @param int $id_objet * @param string $type_objet * @param string $info * @param string $etoile * @return string */ function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") { global $table_des_traitements; static $trouver_table = null; static $objets; // On verifie qu'on a tout ce qu'il faut $id_objet = intval($id_objet); if (!($id_objet and $type_objet and $info)) { return ''; } // si on a deja note que l'objet n'existe pas, ne pas aller plus loin if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { return ''; } // Si on demande l'url, on retourne direct la fonction if ($info == 'url') { return generer_url_entite($id_objet, $type_objet); } // Sinon on va tout chercher dans la table et on garde en memoire $demande_titre = $info == 'titre'; // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore if (!isset($objets[$type_objet][$id_objet]) or $demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) { if (!$trouver_table) { $trouver_table = charger_fonction('trouver_table', 'base'); } $desc = $trouver_table(table_objet_sql($type_objet)); if (!$desc) { return $objets[$type_objet] = false; } // Si on demande le titre, on le gere en interne $champ_titre = ""; if ($demande_titre) { // si pas de titre declare mais champ titre, il sera peuple par le select * $champ_titre = !empty($desc['titre']) ? ', ' . $desc['titre'] : ''; } include_spip('base/abstract_sql'); include_spip('base/connect_sql'); $objets[$type_objet][$id_objet] = sql_fetsel('*' . $champ_titre, $desc['table_sql'], id_table_objet($type_objet) . ' = ' . intval($id_objet)); } // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee if ($generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)) { $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]); } else { if ($generer = charger_fonction("generer_{$info}_entite", '', true)) { $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]); } else { $info_generee = isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : ''; } } // On va ensuite chercher les traitements automatiques a faire $champ = strtoupper($info); $traitement = isset($table_des_traitements[$champ]) ? $table_des_traitements[$champ] : false; $table_sql = table_objet_sql($type_objet); if (!$etoile and is_array($traitement) and (isset($traitement[$table_sql]) or isset($traitement[0]))) { $traitement = $traitement[isset($traitement[$table_sql]) ? $table_sql : 0]; $traitement = str_replace('%s', "'" . texte_script($info_generee) . "'", $traitement); // FIXME: $connect et $Pile[0] font souvent partie des traitements. // on les definit pour eviter des notices, mais ce fonctionnement est a ameliorer ! $connect = ""; $Pile = array(0 => array('id_objet' => $id_objet, 'objet' => $type_objet)); eval("\$info_generee = {$traitement};"); } return $info_generee; }
function GenerateText() { global $texte, $chapo, $ps, $notes ; $this->SetFont('helvetica'); if ($chapo) { // Chapeau $this->SetFont('times','B',13); $this->WriteHTML($chapo,5); $this->Ln(12); } //Texte - justifie $this->SetFont('helvetica','',10); $this->WriteHTML($texte,5); $this->Ln(12); if ($ps) { //ps $this->SetFont('','I',8); $this->WriteHTML(texte_script(pdf_first_clean(_T('articlepdf:post_scriptum'))),4); $this->WriteHTML($ps,4); $this->Ln(8); } if ($notes) { //notes $this->SetFont('','',8); $this->WriteHTML($notes,3); $this->Ln(); } }