/**
 * Ajouter le markup html pour une navbar responsive
 * [<div class="navbar navbar-inverse navbar-responsive" id="nav">
 * (#INCLURE{fond=inclure/nav,env}|navbar_responsive)
 * </div>]
 *
 * @param string $nav
 * @param string $class_collapse nom de la class à plier/déplier
 * @return string
 */
function navbar_responsive($nav, $class_collapse = 'nav-collapse-main')
{
    if (strpos($nav, 'nav-collapse') !== false) {
        return $nav;
    }
    $respnav = '';
    $uls = extraire_balises($nav, "ul");
    $n = 1;
    while ($ul = array_shift($uls) and strpos(extraire_attribut($ul, "class"), "nav") === false) {
        $n++;
    }
    if ($ul) {
        $respnav = $nav;
        $p = strpos($respnav, $ul);
        $respnav = substr_replace($respnav, '<a class="btn btn-navbar" data-toggle="collapse" data-target=".' . $class_collapse . '">' . '<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></a>' . "\n" . '<div class="nav-collapse ' . $class_collapse . ' collapse">', $p, 0);
        $l = strlen($respnav);
        $p = $l - 1;
        while ($n--) {
            $p = strrpos($respnav, "</ul>", $p - $l);
        }
        if ($p) {
            $respnav = substr_replace($respnav, '</div>', $p + 5, 0);
        } else {
            $respnav = $nav;
        }
    }
    return $respnav;
}
Example #2
0
function importer_links($page)
{
    $ps = explode('<li id="item-', $page);
    array_shift($ps);
    // le premier ne nous interesse pas
    $links = array();
    foreach ($ps as $p) {
        $link = array();
        if (preg_match(',<div class="date">([^<]*)<,Uims', $p, $m)) {
            $link['date'] = $m[1];
            $link['date'] = date('Y-m-d', strtotime($link['date']));
        }
        $h4 = extraire_balise($p, 'h4');
        $a = extraire_balise($h4, 'a');
        $link['url'] = extraire_attribut($a, 'href');
        $link['title'] = trim(strip_tags($a));
        $p = explode('<ul class="tag-chain">', $p);
        $notes = reset($p);
        $p = end($p);
        if (preg_match(',<div class="notes">(.*)</div>,Uims', $notes, $m)) {
            #var_dump($m[1]);
            $link['descriptif'] = nettoyer_notes($m[1]);
            #var_dump($link['descriptif']);
        }
        $p = explode("</ul>", $p);
        $p = reset($p);
        $tags = extraire_balises($p, 'a');
        foreach ($tags as $tag) {
            $link['tags'][] = trim(strip_tags($tag));
        }
        $links[] = $link;
    }
    return $links;
}
Example #3
0
	function info_maj_spip(){
		if (!autoriser('webmestre')) return "";
		// derniere version de SPIP
		$maj = $GLOBALS['meta']['info_maj_spip'];
		if (!$maj) return "";
		$maj = explode('|',$maj);
		// c'est une ancienne notif, on a fait la maj depuis !
		if ($GLOBALS['spip_version_branche']!==array_shift($maj)) {
			// compat_maj_spip(true);
			return "";
		}
		// derniere version de SPIP 2.?.?
		$maj = implode('|',$maj);
		if (strncmp($maj,"<a",2)==0) $maj = extraire_attribut ($maj, 'title');
		$lien = "http://www.spip.net/".$GLOBALS['spip_lang']."_download";
		$maj = _T('couteau:maj_rev_ok',array('revision'=>$maj, 'url'=>$lien, 'zip'=>''));
		// derniere version de SPIP 2.0.?
		include_spip('lib/maj_auto/distant_mise_a_jour');
		if(function_exists('info_maj_cache')) {
			list(,,$rev) = preg_split('/\D+/', $GLOBALS['spip_version_branche']);
			$nom = _DIR_CACHE_XML . _VERSIONS_LISTE;
			$page = info_maj_cache($nom, 'spip', !file_exists($nom) ? '' : file_get_contents($nom));
			preg_match_all(',/SPIP\D+2\D+0(\D+(\d+))?.*?[.]zip",i', $page, $m,  PREG_SET_ORDER);
			$page=0;
			foreach ($m as $v) if ($v[2]>$rev && $v[2]>$page) $page = $v[2];
			if($page) {
				$lien = "http://files.spip.org/spip/archives/SPIP-v2-0-$page.zip"; // 'http://files.spip.org/spip/archives/#SPIP-v2-0-'.$page;
				$maj = _T('couteau:maj_rev_ok',array('revision'=>'2.0.'.$page, 'url'=>$lien, 'zip'=>'')) . '<br/>' . $maj;
			}
		}
		// liens morts
		return preg_replace(',\[([^[]+)->\],', '$1', $maj);
	}
Example #4
0
function tw_traiter_autoliens($r)
{
    if (count($r) < 2) {
        return reset($r);
    }
    list($tout, $l) = $r;
    if (!$l) {
        return $tout;
    }
    // reperer le protocole
    if (preg_match(',^(https?):/*,S', $l, $m)) {
        $l = substr($l, strlen($m[0]));
        $protocol = $m[1];
    } else {
        $protocol = 'http';
    }
    // valider le nom de domaine
    if (!preg_match(_EXTRAIRE_DOMAINE, $l)) {
        return $tout;
    }
    // les ponctuations a la fin d'une URL n'en font certainement pas partie
    // en particulier le "|" quand elles sont dans un tableau a la SPIP
    preg_match('/^(.*?)([,.;?|]?)$/', $l, $k);
    $url = $protocol . '://' . $k[1];
    $lien = charger_fonction('lien', 'inc');
    // deux fois <html> car inc_lien echappe un coup et restaure ensuite
    // => un perd 1 <html>
    $r = $lien($url, "<html><html>{$url}</html></html>", '', '', '', 'nofollow') . $k[2];
    // ajouter la class auto
    $r = inserer_attribut($r, 'class', trim(extraire_attribut($r, 'class') . ' auto'));
    // si l'original ne contenait pas le 'http:' on le supprime du clic
    return $m ? $r : str_replace('>http://', '>', $r);
}
Example #5
0
File: acte.php Project: nursit/bank
/**
 * signer le contexte du formulaire
 * s'applique sur le html pour permettre sa personalisation
 *
 * @param string $texte
 * @param array $config
 * @return string
 */
function ogone_form_sha_in($texte, $config = null)
{
    // ne rien faire si pas de config
    if (!$config) {
        return $texte;
    }
    $forms = extraire_balises($texte, "form");
    foreach ($forms as $form) {
        $form_s = $form;
        $input = extraire_balises($form, "input");
        $args = array();
        foreach ($input as $i) {
            if (extraire_attribut($i, 'type') == 'hidden') {
                $name = extraire_attribut($i, 'name');
                $value = extraire_attribut($i, 'value');
                // si jamais on applique 2 fois, supprimer la signature precedement calculee
                if ($name == "SHASign") {
                    $form_s = str_replace($i, "", $form_s);
                } else {
                    $args[$name] = $value;
                }
            }
        }
        $s = ogone_sha_in($args, $config);
        $form_s = str_replace(end($input), end($input) . "<input type='hidden' name='SHASign' value='{$s}' />", $form_s);
        $texte = str_replace($form, $form_s, $texte);
    }
    return $texte;
}
Example #6
0
function couleurs_creer_icone_barre($texte, $color) {
	static $icones_barre;
	rep_icones_barre($icones_barre);
	$img = image_typo($texte, 'couleur='.$color, 'taille=12', 'police=dustismo_bold.ttf');
	$nom = basename($src = extraire_attribut($img, 'src'));
	@copy($src, $icones_barre.$nom);
	return $nom;
}
function BOUCLE_documenthtml_b8a8020987dd01f8087ad24f961857eb(&$Cache, &$Pile, &$doublons, &$Numrows, $SP)
{
    static $command = array();
    static $connect;
    $command['connect'] = $connect = '';
    $in = array();
    if (!is_array($a = @$Pile[0]['mode'])) {
        $in[] = $a;
    } else {
        $in = array_merge($in, $a);
    }
    if (!isset($command['table'])) {
        $command['table'] = 'documents';
        $command['id'] = '_document';
        $command['from'] = array('documents' => 'spip_documents', 'L1' => 'spip_types_documents');
        $command['type'] = array();
        $command['groupby'] = array();
        $command['select'] = array("documents.id_document", "L1.titre AS type_document", "documents.taille", "documents.mode", "documents.largeur", "documents.hauteur", "documents.titre", "L1.mime_type");
        $command['orderby'] = array();
        $command['join'] = array('L1' => array('documents', 'extension'));
        $command['limit'] = '';
        $command['having'] = array();
    }
    $command['where'] = array(array('(documents.taille > 0 OR documents.distant=\'oui\')'), array('=', 'documents.id_document', sql_quote(@$Pile[0]['id_document'], '', 'bigint(21) NOT NULL AUTO_INCREMENT')), !(is_array(@$Pile[0]['mode']) ? count(@$Pile[0]['mode']) : strlen(@$Pile[0]['mode'])) ? '' : (is_array(@$Pile[0]['mode']) ? sql_in('documents.mode', sql_quote($in)) : array('=', 'documents.mode', sql_quote(@$Pile[0]['mode'], '', 'varchar(10) NOT NULL DEFAULT \'document\''))));
    if (defined("_BOUCLE_PROFILER")) {
        $timer = time() + microtime();
    }
    $t0 = "";
    // REQUETE
    $iter = IterFactory::create("SQL", $command, array('plugins-dist/medias/modeles/img.html', 'html_b8a8020987dd01f8087ad24f961857eb', '_document', 1, $GLOBALS['spip_lang']));
    if (!$iter->err()) {
        $SP++;
        // RESULTATS
        while ($Pile[$SP] = $iter->fetch()) {
            $t0 .= '

' . vide($Pile['vars'][$_zzz = (string) 'image'] = interdire_scripts(($a = match(entites_html(sinon(table_valeur(@$Pile[0], (string) 'mode_force', null), interdire_scripts($Pile[$SP]['mode'])), true), 'image|vignette') or is_string($a) and strlen($a)) ? $a : interdire_scripts(entites_html(table_valeur(@$Pile[0], (string) 'embed', null), true)) ? ' ' : '')) . (($t1 = strval(table_valeur($Pile["vars"], (string) 'image', null))) !== '' ? $t1 . ('
<span class=\'spip_document_' . $Pile[$SP]['id_document'] . ' spip_documents' . (($t2 = strval(interdire_scripts(entites_html(table_valeur(@$Pile[0], (string) 'align', null), true)))) !== '' ? ' spip_documents_' . $t2 : '') . (($t2 = strval(interdire_scripts(entites_html(table_valeur(@$Pile[0], (string) 'class', null), true)))) !== '' ? ' ' . $t2 : '') . ' spip_lien_ok\'' . (($t2 = strval(interdire_scripts(match(entites_html(table_valeur(@$Pile[0], (string) 'align', null), true), 'left|right')))) !== '' ? '
 style=\'float:' . $t2 . ';\'' : '') . '>
' . (($t2 = strval(interdire_scripts(entites_html(table_valeur(@$Pile[0], (string) 'lien', null), true)))) !== '' ? '<a href="' . $t2 . ('"' . (($t3 = strval(interdire_scripts(entites_html(table_valeur(@$Pile[0], (string) 'lien_class', null), true)))) !== '' ? ' class="' . $t3 . '"' : '') . '>') : '') . '<img src=\'' . vider_url(urlencode_1738(generer_url_entite($Pile[$SP]['id_document'], 'document', '', '', true))) . '\'' . (($t2 = strval(interdire_scripts($Pile[$SP]['largeur']))) !== '' ? ' width="' . $t2 . '"' : '') . (($t2 = strval(interdire_scripts($Pile[$SP]['hauteur']))) !== '' ? ' height="' . $t2 . '"' : '') . ' alt="' . interdire_scripts(texte_backend(typo(supprimer_numero($Pile[$SP]['titre']), "TYPO", $connect, $Pile[0]))) . '"' . (($t2 = strval(interdire_scripts(texte_backend(typo(supprimer_numero($Pile[$SP]['titre']), "TYPO", $connect, $Pile[0]))))) !== '' ? ' title="' . $t2 . '"' : '') . ' />' . interdire_scripts(entites_html(table_valeur(@$Pile[0], (string) 'lien', null), true) ? '</a>' : '') . '</span>
') : '') . (!table_valeur($Pile["vars"], (string) 'image', null) ? ' ' . ('
	' . vide($Pile['vars'][$_zzz = (string) 'fichier'] = extraire_attribut(quete_logo_document(quete_document($Pile[$SP]['id_document'], ''), '', '', '', 0, 0, ''), 'src')) . '
	' . vide($Pile['vars'][$_zzz = (string) 'width'] = extraire_attribut(quete_logo_document(quete_document($Pile[$SP]['id_document'], ''), '', '', '', 0, 0, ''), 'width')) . '
	' . vide($Pile['vars'][$_zzz = (string) 'height'] = extraire_attribut(quete_logo_document(quete_document($Pile[$SP]['id_document'], ''), '', '', '', 0, 0, ''), 'height')) . '
<span class=\'spip_document_' . $Pile[$SP]['id_document'] . ' spip_documents' . (($t2 = strval(interdire_scripts(entites_html(table_valeur(@$Pile[0], (string) 'align', null), true)))) !== '' ? ' spip_documents_' . $t2 : '') . (($t2 = strval(interdire_scripts(entites_html(table_valeur(@$Pile[0], (string) 'class', null), true)))) !== '' ? ' ' . $t2 : '') . ' spip_lien_ok\'' . (($t2 = strval(interdire_scripts(match(entites_html(table_valeur(@$Pile[0], (string) 'align', null), true), 'left|right')))) !== '' ? '
 style=\'float:' . $t2 . (';' . (($t3 = strval(table_valeur($Pile["vars"], (string) 'width', null))) !== '' ? ' width:' . $t3 . 'px;' : '') . '\'') : '') . '><a href="' . interdire_scripts(($a = entites_html(table_valeur(@$Pile[0], (string) 'lien', null), true) or is_string($a) and strlen($a)) ? $a : vider_url(urlencode_1738(generer_url_entite($Pile[$SP]['id_document'], 'document', '', '', true)))) . '"' . (($t2 = strval(interdire_scripts(entites_html(table_valeur(@$Pile[0], (string) 'lien', null), true) ? '' : 'type="' . interdire_scripts($Pile[$SP]['mime_type']) . '"'))) !== '' ? '
 ' . $t2 : '') . (($t2 = strval(interdire_scripts(texte_backend(typo(supprimer_numero($Pile[$SP]['titre']), "TYPO", $connect, $Pile[0]))))) !== '' ? ' title="' . $t2 . '"' : '') . '><img src=\'' . table_valeur($Pile["vars"], (string) 'fichier', null) . '\' width=\'' . table_valeur($Pile["vars"], (string) 'width', null) . '\' height=\'' . table_valeur($Pile["vars"], (string) 'height', null) . '\' alt=\'' . interdire_scripts(attribut_html(strlen(typo(supprimer_numero($Pile[$SP]['titre']), "TYPO", $connect, $Pile[0])) ? interdire_scripts(typo(supprimer_numero($Pile[$SP]['titre']), "TYPO", $connect, $Pile[0])) . ' {' . interdire_scripts($Pile[$SP]['type_document']) . '}' : interdire_scripts($Pile[$SP]['type_document']))) . '\' /></a></span>
') : '');
        }
        $iter->free();
    }
    if (defined("_BOUCLE_PROFILER") and 1000 * ($timer = time() + microtime() - $timer) > _BOUCLE_PROFILER) {
        spip_log(intval(1000 * $timer) . "ms BOUCLE_document @ plugins-dist/medias/modeles/img.html", "profiler" . _LOG_AVERTISSEMENT);
    }
    return $t0;
}
Example #8
0
/**
 * Tourner un document
 *
 * http://code.spip.net/@action_tourner_post
 *
 * @param int $id_document
 * @param int $angle
 *   angle de rotation en degre>0
 * @return
 */
function action_tourner_post($id_document, $angle)
{
    $row = sql_fetsel("fichier,extension", "spip_documents", "id_document=" . intval($id_document));
    if (!$row) {
        return;
    }
    include_spip('inc/charsets');
    # pour le nom de fichier
    include_spip('inc/documents');
    // Fichier destination : on essaie toujours de repartir de l'original
    $var_rot = $angle;
    $effacer = false;
    include_spip('inc/distant');
    # pour copie_locale
    $src = _DIR_RACINE . copie_locale(get_spip_doc($row['fichier']));
    if (preg_match(',^(.*)-r(90|180|270)\\.([^.]+)$,', $src, $match)) {
        $effacer = $src;
        $src = $match[1] . '.' . $match[3];
        $var_rot += intval($match[2]);
    }
    $var_rot = (360 + $var_rot) % 360;
    // 0, 90, 180 ou 270
    if ($var_rot > 0) {
        $dest = preg_replace(',\\.[^.]+$,', '-r' . $var_rot . '$0', $src);
        spip_log("rotation {$var_rot} {$src} : {$dest}");
        include_spip('inc/filtres');
        include_spip('public/parametrer');
        // charger les fichiers fonctions #bugfix spip 2.1.0
        $res = filtrer('image_rotation', $src, $var_rot);
        $res = filtrer('image_format', $res, $row['extension']);
        list($hauteur, $largeur) = taille_image($res);
        $res = extraire_attribut($res, 'src');
        include_spip('inc/getdocument');
        deplacer_fichier_upload($res, $dest);
    } else {
        $dest = $src;
        $size_image = @getimagesize($dest);
        $largeur = $size_image[0];
        $hauteur = $size_image[1];
    }
    // succes !
    if ($largeur > 0 and $hauteur > 0) {
        $set = array('fichier' => set_spip_doc($dest), 'largeur' => $largeur, 'hauteur' => $hauteur, 'distant' => 'non');
        if ($taille = @filesize($dest)) {
            $set['taille'] = $taille;
        }
        sql_updateq('spip_documents', $set, "id_document=" . intval($id_document));
        if ($effacer) {
            spip_log("rotation : j'efface {$effacer}");
            spip_unlink($effacer);
        }
        // pipeline pour les plugins
        pipeline('post_edition', array('args' => array('table' => 'spip_documents', 'table_objet' => 'documents', 'spip_table_objet' => 'spip_documents', 'type' => 'document', 'id_objet' => $id_document, 'champs' => array('rotation' => $angle, 'orientation' => $var_rot, 'fichier' => $row['fichier']), 'action' => 'tourner'), 'data' => $set));
    }
}
Example #9
0
function sommaire_nettoyer_titre($t) {
	// pas de notes
	$brut = preg_replace(',\[<a href=["\']#nb.*?</a>\],','', echappe_retour($t,'CS'));
	// pas de glossaire
	if(function_exists('cs_retire_glossaire')) $brut = cs_retire_glossaire($brut);
	// texte brut
	$brut2 = trim(preg_replace(',[\n\r]+,',' ',textebrut($brut)));
	// cas des intertitres en image_typo
	if(!strlen($brut2)) $brut2 = trim(extraire_attribut($brut, 'alt'));
	return $brut2;
}
function mediabox_config($public = null) {
	include_spip("inc/filtres");
	include_spip("inc/config");
	$config = lire_config('mediabox', array());

	$config = array_merge(array(
		'active' => 'oui',
		'traiter_toutes_images' => 'oui',
		'selecteur_galerie' => '#documents_portfolio a[type=\'image/jpeg\'],#documents_portfolio a[type=\'image/png\'],#documents_portfolio a[type=\'image/gif\']',
		'selecteur_commun' => '.mediabox',
		'splash_url' => '',
		'splash_width' => '600px',
		'splash_height' => '90%',
		'skin' => 'black-striped',
		'transition' => 'elastic',
		'speed' => '200',
		'maxWidth' => '90%',
		'maxHeight' => '90%',
		'minWidth' => '400px',
		'minHeight' => '',
		'slideshow_speed' => '2500',
		'opacite' => '0.9',
	), $config);

	if ((is_null($public) and test_espace_prive()) or $public === false) {
		$config = array_merge($config, array(
			'active' => 'oui',
			'selecteur_galerie' => '#portfolios a[type^=\'image/\']',
			'selecteur_commun' => '.mediabox, .iconifier a[href$=jpg],.iconifier a[href$=png],.iconifier a[href$=gif]',
			'splash_url' => '',
			'skin' => 'white-shadow',
			'maxWidth' => '90%',
			'maxHeight' => '95%',
			'minWidth' => '600px',
			'minHeight' => '300px',
			'opacite' => '0.9',
		));
	}

	// Gerer aussi les liens internes de SPIP
	if (!test_espace_prive() and $config['splash_url']) {
		include_spip("inc/filtres_ecrire");
		$config['splash_url'] = url_absolue(extraire_attribut(lien_article_virtuel($config['splash_url']), 'href'));
	}

	// charger la config du theme uniquement dans le public
	if (!test_espace_prive() and include_spip("colorbox/" . $config['skin'] . "/mediabox_config_theme")) {
		$config_theme = mediabox_config_theme();
		$config = array_merge($config, $config_theme);
	}

	return $config;
}
Example #11
0
function inc_safehtml_dist($t) {
	static $process, $test;

	if (!$test) {
		$process = false;
		if ($f = find_in_path('lib/safehtml/classes')) {
			define('XML_HTMLSAX3', $f.'/');
			require_once XML_HTMLSAX3.'safehtml.php';
			$process = new safehtml();
			$process->deleteTags[] = 'param'; // sinon bug Firefox
		}
		if ($process)
			$test = 1; # ok
		else
			$test = -1; # se rabattre sur une fonction de securite basique
	}

	if ($test > 0) {
		# autoriser des trucs
		# ex: l'embed de youtube
		if (
		false !== strpos($t, 'iframe')) {
			foreach (extraire_balises($t, 'iframe') as $iframe) {
				if (preg_match(',^http://(www\.)?(youtube\.com|(player\.)?vimeo\.com)/.*,', extraire_attribut($iframe, 'src'))) {
					$re = '___IFRAME___'.md5($iframe);
					$ok[$re] = $iframe;
					$t = str_replace($iframe, $re, $t);
				}
			}
		}

		# reset ($process->clear() ne vide que _xhtml...),
		# on doit pouvoir programmer ca plus propremement
		$process->_counter = array();
		$process->_stack = array();
		$process->_dcCounter = array();
		$process->_dcStack = array();
		$process->_listScope = 0;
		$process->_liStack = array();
#		$process->parse(''); # cas particulier ?
		$process->clear();
		$t = $process->parse($t);

		# reinserer les trucs autorises
		if ($ok)
		foreach ($ok as $re => $v)
			$t = str_replace($re, $v, $t);
	}
	else
		$t = entites_html($t); // tres laid, en cas d'erreur

	return $t;
}
function skeleditor_extraire_css($texte){
	$url_base = url_de_base();
	$url_page = substr(generer_url_public('A'), 0, -1);
	$dir = preg_quote($url_page,',').'|'.preg_quote(preg_replace(",^$url_base,",_DIR_RACINE,$url_page),',');

	$css = array();
	// trouver toutes les css pour les afficher dans le bouton
	// repris du compresseur
	foreach (extraire_balises($texte, 'link') as $s) {
		if (extraire_attribut($s, 'rel') === 'stylesheet'
		AND (!($type = extraire_attribut($s, 'type'))
			OR $type == 'text/css')
		AND !strlen(strip_tags($s))
		AND $src = preg_replace(",^$url_base,",_DIR_RACINE,extraire_attribut($s, 'href'))
		AND (
			// regarder si c'est du format spip.php?page=xxx
			preg_match(',^('.$dir.')(.*)$,', $src, $r)
			OR (
				// ou si c'est un fichier
				// enlever un timestamp eventuel derriere un nom de fichier statique
				$src2 = preg_replace(",[.]css[?].+$,",'.css',$src)
				// verifier qu'il n'y a pas de ../ ni / au debut (securite)
				AND !preg_match(',(^/|\.\.),', substr($src2,strlen(_DIR_RACINE)))
				// et si il est lisible
				AND @is_readable($src2)
			)
		)) {
			if ($r)
				$css[$s] = explode('&',
					str_replace('&amp;', '&', $r[2]), 2);
			else{
				$file = preg_replace(",[?]\d+$,","",$src);
				if (strncmp($file,_DIR_VAR,strlen(_DIR_VAR))==0){
					lire_fichier($file,$c);
					if (preg_match(",^\/\*\s*(#@.*)\s*\*\/,Uims",$c,$m)){
						$inc = explode("#@",$m[1]);
						$inc = array_map('trim',$inc);
						$inc = array_filter($inc);
						foreach($inc as $i){
							if (!in_array($i,$css))
								$css["$s:$i"] = $i;
						}
					}
				}
				else
					$css[$s] = $file;
			}
		}
	}
	return $css;
}
Example #13
0
/**
 * signer le contexte du formulaire
 * s'applique sur le html pour permettre sa personalisation
 * 
 * @param string $texte
 */
function ogone_form_sha_in($texte)
{
    $form = extraire_balise($texte, "form");
    $input = extraire_balises($form, "input");
    $args = array();
    foreach ($input as $i) {
        if (extraire_attribut($i, 'type') == 'hidden') {
            $name = extraire_attribut($i, 'name');
            $value = extraire_attribut($i, 'value');
            $args[$name] = $value;
        }
    }
    $s = ogone_sha_in($args);
    $texte = str_replace(end($input), end($input) . "<input type='hidden' name='SHASign' value='{$s}' />", $texte);
    return $texte;
}
Example #14
0
function image_select($img,$width_min=0, $height_min=0, $width_max=10000, $height_max=1000){
	if (!$img) return $img;
	list ($h,$l) = taille_image($img);
	$select = true;
	if ($l<$width_min OR $l>$width_max OR $h<$height_min OR $h>$height_max)
		$select = false;

	$class = extraire_attribut($img,'class');
	$p = strpos($class,'no_image_filtrer');
	if (($select==false) AND ($p===FALSE)){
		$class .= " no_image_filtrer";
		$img = inserer_attribut($img,'class',$class);
	}
	if (($select==true) AND ($p!==FALSE)){
		$class = preg_replace(",\s*no_image_filtrer,","",$class);
		$img = inserer_attribut($img,'class',$class);
	}
	return $img;
}
function filtre_photoswipe_preparer($texte)
{
    foreach (extraire_balises($texte, 'img') as $img) {
        if ($src = extraire_attribut($img, 'src') and !extraire_attribut($img, 'data-photo')) {
            $l = largeur($img);
            $h = hauteur($img);
            if ($l > 500 or $h > 300) {
                // pour echapper à la ligne de filtres_images_lib_mini qui remplace tout:
                // `$tag = str_replace($src,$surcharge['src'],$tag);`
                $photo_src = str_replace('.', '__.__', $src);
                $img2 = inserer_attribut($img, 'data-photo', $photo_src);
                $img2 = inserer_attribut($img2, 'data-photo-w', $l);
                $img2 = inserer_attribut($img2, 'data-photo-h', $h);
                $texte = str_replace($img, $img2, $texte);
            }
        }
    }
    return $texte;
}
Example #16
0
function remplace_points_de_suite($texte, $id, $racc) {
	if (strpos($texte, _INTRODUCTION_CODE) === false) return $texte;
	// precaution sur le tout paragrapher de SPIP >= 2.0 !
	$mem = $GLOBALS['toujours_paragrapher'];  
	$GLOBALS['toujours_paragrapher'] = false;  
	// des points de suite bien propres
	@define('_INTRODUCTION_SUITE', '&nbsp;(...)');
	$intro_suite = propre(_INTRODUCTION_SUITE);
	// si les points de suite sont cliquables
	if ($id && _INTRODUCTION_LIEN == 1) {
		$url = (defined('_SPIP19300') && test_espace_prive())
			?generer_url_entite_absolue($id, $racc, '', '', true):"$racc$id";
		if (substr($intro_suite, 0, 6) == '<br />') 
			$intro_suite = propre("<br />[".substr($intro_suite, 6)."->$url]");
			else $intro_suite = propre("&nbsp;[{$intro_suite}->$url]");
		$intro_suite = inserer_attribut($intro_suite, 'class', extraire_attribut($intro_suite,'class') . ' pts_suite');
	}
	$GLOBALS['toujours_paragrapher'] = $mem; 
	return str_replace(_INTRODUCTION_CODE, $intro_suite, $texte);
}
function bookmarks_extract_links($contenu)
{
    $out = array();
    $contenu = str_ireplace("<DT>", "<dt>", $contenu);
    $contenu = explode("<dt>", $contenu);
    $h3 = array_shift($contenu);
    $h3 = extraire_balise($h3, "h3");
    $out['titre'] = strip_tags($h3);
    foreach ($contenu as $item) {
        $link = array();
        if ($a = extraire_balise($item, 'a')) {
            $link['url'] = extraire_attribut($a, 'href');
            $link['titre'] = strip_tags($a);
            $link['date'] = extraire_attribut($a, "add_date");
            $link['descriptif'] = "";
            if ($p = stripos($item, "<dd>")) {
                $link['descriptif'] = textebrut(substr($item, $p));
            }
            $out['links'][] = $link;
        }
    }
    return $out;
}
Example #18
0
function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000)
{
    if (!$img) {
        return $img;
    }
    list($h, $l) = taille_image($img);
    $select = true;
    if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) {
        $select = false;
    }
    $class = extraire_attribut($img, 'class');
    $p = strpos($class, 'filtre_inactif');
    if ($select == false and $p === FALSE) {
        $class .= " filtre_inactif";
        $img = inserer_attribut($img, 'class', $class);
    }
    if ($select == true and $p !== FALSE) {
        // no_image_filtrer : historique, a virer
        $class = preg_replace(",\\s*(filtre_inactif|no_image_filtrer),", "", $class);
        $img = inserer_attribut($img, 'class', $class);
    }
    return $img;
}
Example #19
0
function podcast_post_syndication($flux)
{
    include_spip("inc/filtres");
    $enclosures = extraire_balises($flux["data"]["enclosures"], "a");
    $date = date("Y-m-d h:i:s", $flux["data"]["date"]);
    if (!$date) {
        $date = date("Y-m-d h:i:s");
    }
    if (is_array($enclosures) and sizeof($enclosures) > 0) {
        foreach ($enclosures as $link) {
            if (extraire_attribut($link, 'type') == "audio/mpeg" or extraire_attribut($link, 'type') == "audio/mp3") {
                $liens[] = extraire_attribut($link, 'href');
            }
        }
    }
    if (is_array($liens) and sizeof($liens) > 0) {
        inserer_document_syndic_article($liens, $flux['args']['id_objet'], $date, $flux["data"]["titre"]);
    } else {
        include_spip("inc/utils");
        // lancer une tache cron de scan
        $id_job = job_queue_add('radiobot_scan', "Scan de " . $flux['args']['id_objet'] . " : " . $flux["data"]["titre"], $arguments = array($flux['args']['id_objet'], $flux["data"]["titre"], $flux['data']['url'], $date), 'podcast_pipelines', $no_duplicate = FALSE, strtotime("+10 seconds"), $priority = 0);
    }
    return $flux;
}
Example #20
0
/**
 * Analyser une URL de site distant, qui peut être une syndication.
 *
 * @param string $url
 *     URL du site à analyser
 * @return array|bool
 *     - array : informations du site
 *     - false : site impossible à récupérer
 **/
function analyser_site($url)
{
    include_spip('inc/filtres');
    include_spip('inc/distant');
    // Accepter les URLs au format feed:// ou qui ont oublie le http://
    $url = preg_replace(',^feed://,i', 'http://', $url);
    if (!preg_match(',^[a-z]+://,i', $url)) {
        $url = 'http://' . $url;
    }
    $texte = recuperer_page($url, true);
    if (!$texte) {
        return false;
    }
    include_spip('inc/syndic');
    cdata_echappe($texte, $echappe_cdata);
    if (preg_match(',<(channel|feed)([\\:[:space:]][^>]*)?' . '>(.*)</\\1>,ims', $texte, $regs)) {
        $result['syndication'] = 'oui';
        $result['url_syndic'] = $url;
        $channel = $regs[3];
        // Pour recuperer l'entete, on supprime tous les items
        $b = array_merge(extraire_balises($channel, 'item'), extraire_balises($channel, 'entry'));
        $header = str_replace($b, array(), $channel);
        if ($t = extraire_balise($header, 'title')) {
            cdata_echappe_retour($t, $echappe_cdata);
            $result['nom_site'] = filtrer_entites(supprimer_tags($t));
        }
        if ($t = extraire_balises($header, 'link')) {
            cdata_echappe_retour($t, $echappe_cdata);
            foreach ($t as $link) {
                $u = supprimer_tags(filtrer_entites($link));
                if (!strlen($u)) {
                    $u = extraire_attribut($link, 'href');
                }
                if (strlen($u)) {
                    // on installe l'url comme url du site
                    // si c'est non vide, en donnant la priorite a rel=alternate
                    if (preg_match(',\\balternate\\b,', extraire_attribut($link, 'rel')) or !isset($result['url_site'])) {
                        $result['url_site'] = filtrer_entites($u);
                    }
                }
            }
        }
        $result['url_site'] = url_absolue($result['url_site'], $url);
        if ($a = extraire_balise($header, 'description') or $a = extraire_balise($header, 'tagline')) {
            cdata_echappe_retour($a, $echappe_cdata);
            $result['descriptif'] = filtrer_entites(supprimer_tags($a));
        }
        if (preg_match(',<image.*<url.*>(.*)</url>.*</image>,Uims', $header, $r) and preg_match(',(https?://.*/.*(gif|png|jpg)),ims', $r[1], $r) and $image = recuperer_infos_distantes($r[1])) {
            if (in_array($image['extension'], array('gif', 'jpg', 'png'))) {
                $result['format_logo'] = $image['extension'];
                $result['logo'] = $r[1];
            } else {
                if ($image['fichier']) {
                    spip_unlink($image['fichier']);
                }
            }
        }
    } else {
        $result['syndication'] = 'non';
        $result['url_site'] = $url;
        if (preg_match(',<head>(.*(description|title).*)</head>,Uims', $texte, $regs)) {
            $head = filtrer_entites($regs[1]);
        } else {
            $head = $texte;
        }
        if (preg_match(',<title[^>]*>(.*),ims', $head, $regs)) {
            $titre = trim($regs[1]);
            if (!strlen($titre)) {
                $titre = substr($head, strpos($head, $regs[0]));
            }
            $result['nom_site'] = filtrer_entites(supprimer_tags(preg_replace(',</title>.*$,ims', '', $titre)));
        }
        if ($a = array_merge(extraire_balises($head, 'meta'), extraire_balises($head, 'http-equiv'))) {
            foreach ($a as $meta) {
                if (extraire_attribut($meta, 'name') == 'description') {
                    $desc = trim(extraire_attribut($meta, 'content'));
                    if (!strlen($desc)) {
                        $desc = trim(extraire_attribut($meta, 'value'));
                    }
                    $result['descriptif'] = $desc;
                }
            }
        }
        // Cherchons quand meme un backend
        include_spip('inc/distant');
        include_spip('inc/feedfinder');
        $feeds = get_feed_from_url($url, $texte);
        // si on a a trouve un (ou plusieurs) on le note avec select:
        // ce qui constitue un signal pour exec=sites qui proposera de choisir
        // si on syndique, et quelle url.
        if (count($feeds) >= 1) {
            spip_log("feedfinder.php :\n" . join("\n", $feeds));
            $result['url_syndic'] = "select: " . join(' ', $feeds);
        }
    }
    cdata_echappe_retour($result, $echappe_cdata);
    return $result;
}
/**
 * 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;
}
Example #22
0
function tw_expanser_un_lien($reg, $quoi = 'echappe')
{
    static $pile = array();
    static $inserts;
    static $sources;
    static $regs;
    static $k = 0;
    static $lien;
    static $connect = '';
    switch ($quoi) {
        case 'init':
            if (!$lien) {
                $lien = charger_fonction('lien', 'inc');
            }
            array_push($pile, array($inserts, $sources, $regs, $connect, $k));
            $inserts = $sources = $regs = array();
            $connect = $reg;
            // stocker le $connect pour les appels a inc_lien_dist
            $k = 0;
            return;
            break;
        case 'echappe':
            $inserts[$k] = '@@SPIP_ECHAPPE_LIEN_' . $k . '@@';
            $sources[$k] = $reg[0];
            #$titre=$reg[1];
            list($titre, $bulle, $hlang) = tw_traiter_raccourci_lien_atts($reg[1]);
            $r = end($reg);
            // la mise en lien automatique est passee par la a tort !
            // corrigeons pour eviter d'avoir un <a...> dans un href...
            if (strncmp($r, '<a', 2) == 0) {
                $href = extraire_attribut($r, 'href');
                // remplacons dans la source qui peut etre reinjectee dans les arguments
                // d'un modele
                $sources[$k] = str_replace($r, $href, $sources[$k]);
                // et prenons le href comme la vraie url a linker
                $r = $href;
            }
            $regs[$k] = $lien($r, $titre, '', $bulle, $hlang, '', $connect);
            return $inserts[$k++];
            break;
        case 'reinsert':
            if (count($inserts)) {
                $reg = str_replace($inserts, $regs, $reg);
            }
            list($inserts, $sources, $regs, $connect, $k) = array_pop($pile);
            return $reg;
            break;
        case 'sources':
            return array($inserts, $sources);
            break;
    }
}
Example #23
0
function traiter_modeles($texte, $doublons=false, $echap='', $connect='', $liens = null) {
	// preserver la compatibilite : true = recherche des documents
	if ($doublons===true)
		$doublons = array('documents'=>array('doc','emb','img'));
	// detecter les modeles (rapide)
	if (strpos($texte,"<")!==false AND
	  preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)) {
		include_spip('public/assembler');
		foreach ($matches as $match) {
			// Recuperer l'appel complet (y compris un eventuel lien)

			$a = strpos($texte,$match[0]);
			preg_match(_RACCOURCI_MODELE_DEBUT,
			substr($texte, $a), $regs);
			$regs[]=""; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
			list(,$mod, $type, $id, $params, $fin) = $regs;
			if ($fin AND
			preg_match('/<a\s[^<>]*>\s*$/i',
					substr($texte, 0, $a), $r)) {
				$lien = array(
					'href' => extraire_attribut($r[0],'href'),
					'class' => extraire_attribut($r[0],'class'),
					'mime' => extraire_attribut($r[0],'type')
				);
				$n = strlen($r[0]);
				$a -= $n;
				$cherche = $n + strlen($regs[0]);
			} else {
				$lien = false;
				$cherche = strlen($mod);
			}

			// calculer le modele
			# hack articles_edit, breves_edit, indexation
			if ($doublons)
				$texte .= preg_replace(',[|][^|=]*,s',' ',$params);
			# version normale
			else {
				// si un tableau de liens a ete passe, reinjecter le contenu d'origine
				// dans les parametres, plutot que les liens echappes
				if (!is_null($liens))
					$params = str_replace($liens[0], $liens[1], $params);
			  $modele = inclure_modele($type, $id, $params, $lien, $connect);
				// en cas d'echec, 
				// si l'objet demande a une url, 
				// creer un petit encadre vers elle
				if ($modele === false) {
					if (!$lien)
						$lien = traiter_lien_implicite("$type$id", '', 'tout', $connect);
					if ($lien)
						$modele = '<a href="'
						  .$lien['url']
						  .'" class="spip_modele'
						  . '">'
						  .sinon($lien['titre'], _T('ecrire:info_sans_titre'))
						  ."</a>";
					else {
						$modele = "";
						if (test_espace_prive()) {
							$modele = entites_html(substr($texte,$a,$cherche));
							if (!is_null($liens))
								$modele = "<pre>".str_replace($liens[0], $liens[1], $modele)."</pre>";
						}
					}
				}
				// le remplacer dans le texte
				if ($modele !== false) {
					$modele = protege_js_modeles($modele);
					$rempl = code_echappement($modele, $echap);
					$texte = substr($texte, 0, $a)
						. $rempl
						. substr($texte, $a+$cherche);
				}
			}

			// hack pour tout l'espace prive
			if (((!_DIR_RESTREINT) OR ($doublons)) AND ($id)){
				foreach($doublons?$doublons:array('documents'=>array('doc','emb','img')) as $quoi=>$modeles)
					if (in_array($type,$modeles))
						$GLOBALS["doublons_{$quoi}_inclus"][] = $id;
			}
		}
	}

	return $texte;
}
Example #24
0
function smileys_creer_icone_barre($file) {
	static $icones_barre;
	rep_icones_barre($icones_barre);
	$file = filtrer('image_recadre', $file, 16, 16, 'topleft');
	$nom = basename($src = extraire_attribut($file, 'src'));
	@copy($src, $icones_barre.$nom);
	return $nom;
}
Example #25
0
/**
 * fonction sans finesse mais efficace
 * on parcourt ligne par ligne a la recherche de balise <a> ou <link>
 * si dans le corps de celle-ci on trouve les mots rss, xml, atom ou rdf
 * alors on recupere la valeur href='<url>', on adapte celle-ci si elle
 * est relative et on verifie que c'est bien un feed si oui on l'ajoute
 * au tableau des feed si on ne trouve rien ou si aucun feed est trouve on retourne 
 * un tableau vide
 * 
 * @param string $url
 * 		L'URL à analyser
 * @param $buffer
 * @return array $feed_list
 * 		Le tableau des feed trouvés dans la page
 */
function get_feed_from_url($url, $buffer = false)
{
    global $verif_complete;
    //j'ai prevenu ce sera pas fin
    if (!preg_match("/^http:\\/\\/.*/", $url)) {
        $url = "http://www." . $url;
    }
    if (!$buffer) {
        $buffer = @file_get_contents($url);
    }
    include_spip("inc/filtres");
    $feed_list = array();
    //extraction des <link>
    if ($links = extraire_balises($buffer, "link")) {
        //y a t-y rss atom rdf ou xml dans ces balises
        foreach ($links as $link) {
            if ((strpos($link, "rss") || strpos($link, "rdf") || strpos($link, "atom") || strpos($link, "xml")) && (!strpos($link, 'opensearch') && !strpos($link, 'oembed'))) {
                //voila un candidat on va extraire sa partie href et la placer dans notre tableau
                if ($href = extraire_attribut($link, "href")) {
                    //on aura pris soin de verifier si ce lien est relatif d'en faire un absolu
                    $href = suivre_lien($url, $href);
                    if (!$verif_complete or is_feed($href)) {
                        $feed_list[] = $href;
                    }
                }
            }
        }
    }
    //extraction des <a>
    if ($links = extraire_balises($buffer, "a")) {
        //y a t-y rss atom rdf ou xml dans ces balises
        foreach ($links as $link) {
            if ((strpos($link, "rss") || strpos($link, "rdf") || strpos($link, "atom") || strpos($link, "xml")) && (!strpos($link, 'opensearch') && !strpos($link, 'oembed'))) {
                //voila un candidat on va extraire sa partie href et la placer dans notre tableau
                if ($href = extraire_attribut($link, "href")) {
                    //on aura pris soin de verifier si ce lien est relatif d'en faire un absolu
                    $href = suivre_lien($url, $href);
                    if (!$verif_complete or is_feed($href)) {
                        $feed_list[] = $href;
                    }
                }
            }
        }
    }
    // si c'est un site SPIP, tentons l'url connue
    if (!count($feed_list) and (strpos($url, "spip") or stripos($buffer, "spip"))) {
        $href = suivre_lien($url, "spip.php?page=backend");
        if (is_feed($href)) {
            $feed_list[] = $href;
        }
    }
    return $feed_list;
}
/**
 * Réduit une image
 *
 * @uses extraire_attribut()
 * @uses inserer_attribut()
 * @uses _image_valeurs_trans()
 * @uses _image_ratio()
 * @uses _image_tag_changer_taille()
 * @uses _image_ecrire_tag()
 * @uses _image_creer_vignette()
 *
 * @param array $fonction
 *     Un tableau à 2 éléments :
 *     1) string : indique le nom du filtre de traitement demandé (par exemple : `image_reduire`) ;
 *     2) array : tableau reprenant la valeur de `$img` et chacun des arguments passés au filtre utilisé.
 * @param string $img
 *     Chemin de l'image ou texte contenant une balise img
 * @param int $taille
 *     Largeur désirée
 * @param int $taille_y
 *     Hauteur désirée
 * @param bool $force
 * @param bool $cherche_image
 *     Inutilisé
 * @param string $process
 *     Librairie graphique à utiliser (gd1, gd2, netpbm, convert, imagick).
 *     AUTO utilise la librairie sélectionnée dans la configuration.
 * @return string
 *     Code HTML de la balise img produite
 **/
function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $cherche_image, $process = 'AUTO')
{
    $image = false;
    if ($process == 'AUTO' and isset($GLOBALS['meta']['image_process'])) {
        $process = $GLOBALS['meta']['image_process'];
    }
    # determiner le format de sortie
    $format_sortie = false;
    // le choix par defaut sera bon
    if ($process == "netpbm") {
        $format_sortie = "jpg";
    } elseif ($process == 'gd1' or $process == 'gd2') {
        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction);
        // on verifie que l'extension choisie est bonne (en principe oui)
        $gd_formats = explode(',', $GLOBALS['meta']["gd_formats"]);
        if (is_array($image) and (!in_array($image['format_dest'], $gd_formats) or $image['format_dest'] == 'gif' and !function_exists('ImageGif'))) {
            if ($image['format_source'] == 'jpg') {
                $formats_sortie = array('jpg', 'png', 'gif');
            } else {
                $formats_sortie = array('png', 'jpg', 'gif');
            }
            // Choisir le format destination
            // - on sauve de preference en JPEG (meilleure compression)
            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
            # pas *ecrire*
            $format_sortie = "";
            foreach ($formats_sortie as $fmt) {
                if (in_array($fmt, $gd_formats)) {
                    if ($fmt != "gif" or function_exists('ImageGif')) {
                        $format_sortie = $fmt;
                    }
                    break;
                }
            }
            $image = false;
        }
    }
    if (!is_array($image)) {
        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction);
    }
    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
        spip_log("image_reduire_src:pas de version locale de {$img}");
        // on peut resizer en mode html si on dispose des elements
        if ($srcw = extraire_attribut($img, 'width') and $srch = extraire_attribut($img, 'height')) {
            list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
            return _image_tag_changer_taille($img, $w, $h);
        }
        // la on n'a pas d'infos sur l'image source... on refile le truc a css
        // sous la forme style='max-width: NNpx;'
        return inserer_attribut($img, 'style', "max-width: {$taille}px; max-height: {$taille_y}px");
    }
    // si l'image est plus petite que la cible retourner une copie cachee de l'image
    if ($image['largeur'] <= $taille && $image['hauteur'] <= $taille_y) {
        if ($image['creer']) {
            @copy($image['fichier'], $image['fichier_dest']);
        }
        return _image_ecrire_tag($image, array('src' => $image['fichier_dest']));
    }
    if ($image['creer'] == false && !$force) {
        return _image_ecrire_tag($image, array('src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']));
    }
    if (in_array($image["format_source"], array('jpg', 'gif', 'png'))) {
        $destWidth = $image['largeur_dest'];
        $destHeight = $image['hauteur_dest'];
        $logo = $image['fichier'];
        $date = $image["date_src"];
        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
        if ($preview && $preview['fichier']) {
            $logo = $preview['fichier'];
            $destWidth = $preview['width'];
            $destHeight = $preview['height'];
            $date = $preview['date'];
        }
        // dans l'espace prive mettre un timestamp sur l'adresse
        // de l'image, de facon a tromper le cache du navigateur
        // quand on fait supprimer/reuploader un logo
        // (pas de filemtime si SAFE MODE)
        $date = test_espace_prive() ? '?' . $date : '';
        return _image_ecrire_tag($image, array('src' => "{$logo}{$date}", 'width' => $destWidth, 'height' => $destHeight));
    } else {
        return $img;
    }
}
Example #27
0
/**
 * Extraire les balises JS à compacter
 * 
 * @param string $flux
 *     Contenu HTML dont on extrait les balises CSS
 * @param string $url_base
 * @return array
 *     Couples (balise => src)
 */
function compresseur_extraire_balises_js_dist($flux, $url_base)
{
    $balises = extraire_balises($flux, 'script');
    $files = array();
    foreach ($balises as $s) {
        if (extraire_attribut($s, 'type') === 'text/javascript' and is_null(extraire_attribut($s, 'id')) and $src = extraire_attribut($s, 'src') and !strlen(strip_tags($s))) {
            $files[$s] = $src;
        }
    }
    return $files;
}
Example #28
0
/**
 * Retrouver les champs d'un formulaire en parcourant son squelette
 * et en extrayant les balises input, textarea, select
 *
 * @param string $form
 * @return array
 */
function cvtconf_formulaires_configurer_recense($form)
{
    $valeurs = array('editable' => ' ');
    // sinon cas analyse du squelette
    if ($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') and lire_fichier($f, $contenu)) {
        for ($i = 0; $i < 2; $i++) {
            // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees
            // permet de trouver aussi les name="#GET{truc}"
            if ($i == 1) {
                $contenu = recuperer_fond("formulaires/{$form}", $valeurs);
            }
            $balises = array_merge(extraire_balises($contenu, 'input'), extraire_balises($contenu, 'textarea'), extraire_balises($contenu, 'select'));
            foreach ($balises as $b) {
                if ($n = extraire_attribut($b, 'name') and preg_match(",^([\\w\\-]+)(\\[\\w*\\])?\$,", $n, $r) and !in_array($n, array('formulaire_action', 'formulaire_action_args')) and extraire_attribut($b, 'type') !== 'submit') {
                    $valeurs[$r[1]] = '';
                    // recuperer les valeurs _meta_xx qui peuvent etre fournies
                    // en input hidden dans le squelette
                    if (strncmp($r[1], '_meta_', 6) == 0) {
                        $valeurs[$r[1]] = extraire_attribut($b, 'value');
                    }
                }
            }
        }
    }
    cvtconf_configurer_lire_meta($form, $valeurs);
    return $valeurs;
}
Example #29
0
function tags2dcsubject($tags)
{
    $subjects = '';
    foreach (extraire_balises($tags, 'a') as $e) {
        if (extraire_attribut($e, rel) == 'tag') {
            $subjects .= '<dc:subject>' . texte_backend(textebrut($e)) . '</dc:subject>' . "\n";
        }
    }
    return $subjects;
}
/**
 * Massicoter un logo
 *
 * Traitement automatique sur les balises #LOGO_*
 *
 * @param string $fichier : Le logo
 *
 * @return string : Un logo massicoté
 */
function massicoter_logo($logo, $objet_type = null, $id_objet = null, $role = null, $env = null)
{
    include_spip('inc/filtres');
    if (!$logo) {
        return $logo;
    }
    $src = extraire_attribut($logo, 'src');
    $alt = extraire_attribut($logo, 'alt');
    $classes = extraire_attribut($logo, 'class');
    $onmouseover = extraire_attribut($logo, 'onmouseover');
    $onmouseout = extraire_attribut($logo, 'onmouseout');
    /* S'il n'y a pas d'id_objet, on essaie de le deviner avec le nom du
       fichier, c'est toujours mieux que rien. Sinon on abandonne… */
    if (is_null($id_objet)) {
        $objet = massicot_trouver_objet_logo($src);
        /* Si le plugin roles_documents est activé, l'objet n'est pas forcément
         * devinable via le nom de fichier (notamment avec la balise
         * LOGO_ARTICLE_RUBRIQUE). Dans ce cas on essaie de bidouiller un truc
         * avec l'environnement. */
        if (test_plugin_actif('roles_documents') and $env) {
            if (isset($env['id_article'])) {
                $objet = array('objet' => 'article', 'id_objet' => $env['id_article']);
            } elseif (isset($env['id_rubrique'])) {
                $objet = array('objet' => 'rubrique', 'id_objet' => $env['id_rubrique']);
            }
        }
        if (is_null($objet)) {
            return $logo;
        }
        $objet_type = $objet['objet'];
        $id_objet = $objet['id_objet'];
    }
    $parametres = massicot_get_parametres($objet_type, $id_objet, $role);
    $fichier = massicoter_fichier($src, $parametres);
    if ($onmouseout) {
        $onmouseout = str_replace($src, $fichier, $onmouseout);
    }
    if ($onmouseover) {
        $src_off = preg_replace('/^.*[\']([^\']+)[\']/', '$1', $onmouseover);
        $parametres_off = massicot_get_parametres($objet_type, $id_objet, 'logo_survol');
        $fichier_off = massicoter_fichier($src_off, $parametres_off);
        $onmouseover = str_replace($src_off, $fichier_off, $onmouseover);
    }
    $balise_img = charger_filtre('balise_img');
    $balise = $balise_img($fichier, $alt, $classes);
    $balise = inserer_attribut($balise, 'onmouseover', $onmouseover);
    $balise = inserer_attribut($balise, 'onmouseout', $onmouseout);
    return $balise;
}