예제 #1
0
파일: jointure.php 프로젝트: genma/spip_ynh
/**
 * Afficher le diff d'un champ texte generique
 * @param string $champ
 * @param string $old
 * @param string $new
 * @param string $format
 *   apercu, diff ou complet
 * @return string
 */
function afficher_diff_jointure_dist($champ, $old, $new, $format = 'diff')
{
    $join = substr($champ, 9);
    $objet = objet_type($join);
    $old = explode(',', $old);
    $new = explode(',', $new);
    $liste = array();
    // les communs
    $intersection = array_intersect($new, $old);
    foreach ($intersection as $id) {
        if ($id = intval(trim($id))) {
            $liste[$id] = "<a href='" . generer_url_entite($id, $objet) . "' title='" . _T(objet_info($objet, 'texte_objet')) . " {$id}'>" . generer_info_entite($id, $objet, 'titre') . "</a>";
        }
    }
    // les supprimes
    $old = array_diff($old, $intersection);
    foreach ($old as $id) {
        if ($id = intval(trim($id))) {
            $liste[$id] = "<span class='diff-supprime'>" . "<a href='" . generer_url_entite($id, $objet) . "' title='" . _T(objet_info($objet, 'texte_objet')) . " {$id}'>" . generer_info_entite($id, $objet, 'titre') . "</a>" . "</span>";
        }
    }
    // les ajoutes
    $new = array_diff($new, $intersection);
    foreach ($new as $id) {
        if ($id = intval(trim($id))) {
            $liste[$id] = "<span class='diff-ajoute'>" . "<a href='" . generer_url_entite($id, $objet) . "' title='" . _T(objet_info($objet, 'texte_objet')) . " {$id}'>" . generer_info_entite($id, $objet, 'titre') . "</a>" . "</span>";
        }
    }
    ksort($liste);
    $liste = implode(', ', $liste);
    return $liste;
}
예제 #2
0
/**
 * Afficher le diff d'un id_rubrique
 * on affiche en fait le deplacement si id_rubrique a change
 * le nom de la rubrique sinon
 *
 * @param string $champ
 * @param string $old
 * @param string $new
 * @param string $format
 * @return string
 */
function afficher_diff_id_rubrique_dist($champ, $old, $new, $format = 'diff')
{
    // ne pas se compliquer la vie !
    if ($old == $new) {
        $out = _T('info_dans_rubrique') . " <b>&#171;&nbsp;" . generer_info_entite($new, 'rubrique', 'titre') . "&nbsp;&#187;</b>";
    } else {
        $out = _T('revisions:version_deplace_rubrique', array('from' => generer_info_entite($old, 'rubrique', 'titre'), 'to' => generer_info_entite($new, 'rubrique', 'titre')));
    }
    return $out;
}
/**
 * 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;
}
/**
 * Affiche les enfants d'une sous rubrique dans un bloc dépliable
 * (Utilisé dans les pages du privé)
 *
 * @param int $collection2
 *  L'identifiant numérique de la rubrique parente
 * @return string
 *  Le contenu du bloc dépliable
 */
function sous_enfant_rub($collection2)
{
    $nb = sql_countsel('spip_rubriques', "id_parent={$collection2}");
    $retour = '';
    $pagination = '';
    $debut = 0;
    $limite = 500;
    /**
     * On ne va afficher que 500 résultats max
     * Si > 500 on affiche une pagination
     */
    if ($nb > $limite) {
        $debut = _request('debut_rubrique' . $collection2) ? _request('debut_rubrique' . $collection2) : $debut;
        $pagination = chercher_filtre('pagination');
        $pagination = '<p class="pagination">' . $pagination($nb, '_rubrique' . $collection2, $debut, $limite, true, 'prive') . '</p>';
        $limite = $debut + $limite;
    }
    $result = sql_select("id_rubrique, id_parent, titre, lang", "spip_rubriques", "id_parent={$collection2}", '', '0+titre,titre', "{$debut},{$limite}");
    while ($row = sql_fetch($result)) {
        $id_rubrique2 = $row['id_rubrique'];
        $id_parent2 = $row['id_parent'];
        $titre2 = generer_info_entite($id_rubrique2, 'rubrique', 'titre');
        // pour etre sur de passer par tous les traitements
        if ('' !== ($rang2 = recuperer_numero($row['titre']))) {
            $rang2 = "{$rang2}. ";
        }
        changer_typo($row['lang']);
        $lang_dir = lang_dir($row['lang']);
        if (autoriser('voir', 'rubrique', $id_rubrique2)) {
            $retour .= "\n<li class='item' dir='{$lang_dir}'><a href='" . generer_url_entite($id_rubrique2, 'rubrique') . "'>" . $rang2 . $titre2 . "</a></li>\n";
        }
    }
    $retour = $pagination . $retour . $pagination;
    if (!$retour) {
        return '';
    }
    return debut_block_depliable($debut > 0 ? true : false, "enfants{$collection2}") . "\n<ul class='liste-items sous-sous-rub'>\n" . $retour . "</ul>\n" . fin_block() . "\n\n";
}
예제 #5
0
/**
 * Trouver le titre d'un objet publie
 *
 * @param string $objet
 * @param int $id_objet
 * @param int $id_forum
 * @param bool $publie
 * @return bool|string
 */
function forum_recuperer_titre_dist($objet, $id_objet, $id_forum = 0, $publie = true)
{
    include_spip('inc/filtres');
    $titre = "";
    if ($f = charger_fonction($objet . '_forum_extraire_titre', 'inc', true)) {
        $titre = $f($id_objet);
    } else {
        include_spip('base/objets');
        if ($publie and !objet_test_si_publie($objet, $id_objet)) {
            return false;
        }
        $titre = generer_info_entite($id_objet, $objet, 'titre', '*');
    }
    if ($titre and $id_forum) {
        $titre_m = sql_getfetsel('titre', 'spip_forum', "id_forum = " . intval($id_forum));
        if (!$titre_m) {
            return false;
            // URL fabriquee
        }
        $titre = $titre_m;
    }
    $titre = supprimer_numero($titre);
    $titre = str_replace('~', ' ', extraire_multi($titre));
    return $titre;
}
예제 #6
0
파일: filtres.php 프로젝트: JLuc/SPIP
/**
 * Generer un lien (titre clicable vers url) vers un objet
 * @param int $id_objet
 * @param $objet
 * @param int $longueur
 * @param null|string $connect
 * @return string
 */
function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = NULL)
{
    include_spip('inc/liens');
    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
    // le raccourcis n'est plus valide
    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
    // on essaye avec generer_info_entite ?
    if (!strlen($titre) and !$connect) {
        $titre = generer_info_entite($id_objet, $objet, 'titre');
    }
    if (!strlen($titre)) {
        $titre = _T('info_sans_titre');
    }
    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
    return "<a href='{$url}' class='{$objet}'>" . couper($titre, $longueur) . "</a>";
}
예제 #7
0
function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false)
{
    include_spip('inc/json');
    include_spip('inc/lien');
    // On construit un tableau des objets sélectionnables suivant les paramètres
    $objets = array();
    if ($rubriques_ou_objets and is_array($rubriques_ou_objets)) {
        $objets = $rubriques_ou_objets;
    } else {
        if ($rubriques_ou_objets) {
            $objets[] = 'rubriques';
        }
        if ($articles) {
            $objets[] = 'articles';
        }
    }
    // Si la référence ne correspond à rien, c'est fini
    if (!($match = typer_raccourci($ref))) {
        return json_export(false);
    }
    // Sinon on récupère les infos utiles
    @(list($type, , $id, , , , ) = $match);
    // On regarde si le type trouvé fait partie des objets sélectionnables
    if (!in_array(table_objet($type), $objets)) {
        return json_export(false);
    }
    // Maintenant que tout est bon, on cherche les informations sur cet objet
    include_spip('inc/filtres');
    if (!($titre = generer_info_entite($id, $type, 'titre'))) {
        return json_export(false);
    }
    // On simplifie le texte
    $titre = attribut_html($titre);
    return json_export(array('type' => $type, 'id' => "{$type}|{$id}", 'titre' => $titre));
}