/**
 * Cherche le logo d'un élément d'objet
 *
 * @global formats_logos Extensions possibles des logos
 * @uses type_du_logo()
 *
 * @param int $id
 *     Identifiant de l'objet
 * @param string $_id_objet
 *     Nom de la clé primaire de l'objet
 * @param string $mode
 *     Mode de survol du logo désiré (on ou off)
 * @return array
 *     - Liste (chemin complet du fichier, répertoire de logos, nom du logo, extension du logo, date de modification)
 *     - array vide aucun logo trouvé.
 **/
function inc_chercher_logo_dist($id, $_id_objet, $mode = 'on')
{
    # attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval()
    $type = type_du_logo($_id_objet);
    $nom = $type . $mode . intval($id);
    foreach ($GLOBALS['formats_logos'] as $format) {
        if (@file_exists($d = _DIR_LOGOS . $nom . '.' . $format)) {
            return array($d, _DIR_LOGOS, $nom, $format, @filemtime($d));
        }
    }
    # coherence de type pour servir comme filtre (formulaire_login)
    return array();
}
  function inc_chercher_logo($id, $_id_objet, $mode = 'on') {
    include_spip('inc/chercher_logo');
    global $formats_logos;
    # attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval()

    $type = type_du_logo($_id_objet);

    $objet = str_replace('id_', '', $_id_objet);
    $tables = lister_tables_objets_sql();
    $table = 'spip_' . $objet . 's';

    foreach ($formats_logos as $format) {
      $nom = $type . $mode . intval($id);
      if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) {
        return array(
          $d,
          _DIR_LOGOS,
          $nom,
          $format,
          @filemtime($d)
        );
      }
      //si pas de logo on cherche si l'article d'origine en a un
      elseif ($tables[$table]['field']['id_trad'] AND $id_trad = sql_getfetsel('id_trad', $table, $_id_objet . '=' . intval($id)) AND _request('exec') != $objet) {
        $nom = $type . $mode . intval($id_trad);
        if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) {
          return array(
            $d,
            _DIR_LOGOS,
            $nom,
            $format,
            @filemtime($d)
          );
        };
      }
    }
    # coherence de type pour servir comme filtre (formulaire_login)
    return array();
  }
Example #3
0
function lister_objets_avec_logos($type)
{
    global $formats_logos;
    $logos = array();
    $chercher_logo = charger_fonction('chercher_logo', 'inc');
    $type = '/' . type_du_logo($type) . "on(\\d+)\\.(" . join('|', $formats_logos) . ")\$/";
    if ($d = @opendir(_DIR_LOGOS)) {
        while ($f = readdir($d)) {
            if (preg_match($type, $f, $r)) {
                $logos[] = $r[1];
            }
        }
    }
    @closedir($d);
    return join(',', $logos);
}
Example #4
0
function import_inserer_translate($values, $table, $desc, $request, $atts) {
	global $trans;
	$p = $desc['key']["PRIMARY KEY"];
	$v = $values[$p];
	if (!isset($trans[$p]) OR !isset($trans[$p][$v]) OR $trans[$p][$v][2]){
		sql_replace($table, $values);
		$on = isset($atts['on']) ? ($atts['on']) : '';
		$off = isset($atts['off']) ? ($atts['off']) : '';
		if ($on OR $off) {
			$t = type_du_logo($p);		  
			$url = $request['url_site'];
			if (!$url) $url = $atts['adresse_site'];
			if (substr($url,-1) !='/') $url .='/';
			$url .= $atts['dir_logos'];
			$new = $trans[$p][$v][0];
			if ($on) {
			  if ($logo = recuperer_page($url . $t . "on$v." . $on))
			    ecrire_fichier(_DIR_LOGOS. $t . "on$new." . $on, $logo);
			}
			if ($off) {
			  if ($logo = recuperer_page($url . $t . "off$v." . $off))
			    ecrire_fichier(_DIR_LOGOS. $t . "off$new." . $off, $logo);
			}
		}
	}
}
Example #5
0
/**
 * Traitement de l'upload d'un logo
 *
 * Il est affecte au site si la balise n'est pas dans une boucle,
 * sinon a l'objet concerne par la boucle ou indiquee par les parametres d'appel
 *
 * @param string $objet
 * @param integer $id_objet
 * @param string $retour
 * @return Array
 */
function formulaires_editer_logo_traiter_dist($objet, $id_objet, $retour = '')
{
    $res = array('editable' => ' ');
    // pas dans une boucle ? formulaire pour le logo du site
    // dans ce cas, il faut chercher un 'siteon0.ext'
    if (!$objet) {
        $objet = 'site';
    }
    $objet = objet_type($objet);
    $_id_objet = id_table_objet($objet);
    // supprimer l'ancien logo puis copier le nouveau
    include_spip('inc/chercher_logo');
    include_spip('inc/flock');
    $type = type_du_logo($_id_objet);
    $chercher_logo = charger_fonction('chercher_logo', 'inc');
    // effectuer la suppression si demandee d'un logo
    $on = _request('supprimer_logo_on');
    if ($on or _request('supprimer_logo_off')) {
        $logo = $chercher_logo($id_objet, $_id_objet, $on ? 'on' : 'off');
        if ($logo) {
            spip_unlink($logo[0]);
        }
        $res['message_ok'] = '';
        // pas besoin de message : la validation est visuelle
    } else {
        include_spip('action/iconifier');
        $ajouter_image = charger_fonction('spip_image_ajouter', 'action');
        $sources = formulaire_editer_logo_get_sources();
        foreach ($sources as $etat => $file) {
            if ($file and $file['error'] == 0) {
                $logo = $chercher_logo($id_objet, $_id_objet, $etat);
                if ($logo) {
                    spip_unlink($logo[0]);
                }
                $ajouter_image($type . $etat . $id_objet, " ", $file);
                $res['message_ok'] = '';
                // pas besoin de message : la validation est visuelle
            }
        }
    }
    if ($retour) {
        include_spip('inc/headers');
        $res['redirect'] = parametre_url($retour, 'var_mode', 'calcul');
    }
    return $res;
}
Example #6
0
/**
 * @param string $objet
 * @param int $id_objet
 * @param string $etat
 *   on ou off
 * @param string|array $source
 *   array : sous tableau de $_FILE issu de l'upload
 *   string : fichier source (chemin complet ou chemin relatif a tmp/upload)
 * @return string
 */
function logo_modifier($objet, $id_objet, $etat, $source)
{
    $chercher_logo = charger_fonction('chercher_logo', 'inc');
    $objet = objet_type($objet);
    $primary = id_table_objet($objet);
    include_spip('inc/chercher_logo');
    $type = type_du_logo($primary);
    // nom du logo
    $nom = $type . $etat . $id_objet;
    // supprimer le logo eventueel existant
    logo_supprimer($objet, $id_objet, $etat);
    include_spip('inc/documents');
    $erreur = "";
    if (!$source) {
        spip_log("spip_image_ajouter : source inconnue");
        $erreur = "source inconnue";
        return $erreur;
    }
    $file_tmp = _DIR_LOGOS . $nom . '.tmp';
    $ok = false;
    // fichier dans upload/
    if (is_string($source)) {
        if (file_exists($source)) {
            $ok = @copy($source, $file_tmp);
        } elseif (file_exists($f = determine_upload() . $source)) {
            $ok = @copy($f, $file_tmp);
        }
    } elseif (!($erreur = check_upload_error($source['error'], "", true))) {
        // analyse le type de l'image (on ne fait pas confiance au nom de
        // fichier envoye par le browser : pour les Macs c'est plus sur)
        $ok = deplacer_fichier_upload($source['tmp_name'], $file_tmp);
    }
    if ($erreur) {
        return $erreur;
    }
    if (!$ok or !file_exists($file_tmp)) {
        spip_log($erreur = "probleme de copie pour {$file_tmp} ");
        return $erreur;
    }
    $size = @getimagesize($file_tmp);
    $type = !$size ? '' : ($size[2] > 3 ? '' : $GLOBALS['formats_logos'][$size[2] - 1]);
    if ($type) {
        @rename($file_tmp, $file_tmp . ".{$type}");
        $file_tmp = $file_tmp . ".{$type}";
        $poids = filesize($file_tmp);
        if (defined('_LOGO_MAX_WIDTH') or defined('_LOGO_MAX_HEIGHT')) {
            if (defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH and $size[0] > _LOGO_MAX_WIDTH or defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT and $size[1] > _LOGO_MAX_HEIGHT) {
                $max_width = (defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH) ? _LOGO_MAX_WIDTH : '*';
                $max_height = (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT) ? _LOGO_MAX_HEIGHT : '*';
                // pas la peine d'embeter le redacteur avec ca si on a active le calcul des miniatures
                // on met directement a la taille maxi a la volee
                if (isset($GLOBALS['meta']['creer_preview']) and $GLOBALS['meta']['creer_preview'] == 'oui') {
                    include_spip('inc/filtres');
                    $img = filtrer('image_reduire', $file_tmp, $max_width, $max_height);
                    $img = extraire_attribut($img, 'src');
                    $img = supprimer_timestamp($img);
                    if (@file_exists($img) and $img !== $file_tmp) {
                        spip_unlink($file_tmp);
                        @rename($img, $file_tmp);
                        $size = @getimagesize($file_tmp);
                    }
                }
                // verifier au cas ou image_reduire a echoue
                if (defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH and $size[0] > _LOGO_MAX_WIDTH or defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT and $size[1] > _LOGO_MAX_HEIGHT) {
                    spip_unlink($file_tmp);
                    $erreur = _T('info_logo_max_poids', array('maxi' => _T('info_largeur_vignette', array('largeur_vignette' => $max_width, 'hauteur_vignette' => $max_height)), 'actuel' => _T('info_largeur_vignette', array('largeur_vignette' => $size[0], 'hauteur_vignette' => $size[1]))));
                }
            }
        }
        if (!$erreur and defined('_LOGO_MAX_SIZE') and _LOGO_MAX_SIZE and $poids > _LOGO_MAX_SIZE * 1024) {
            spip_unlink($file_tmp);
            $erreur = _T('info_logo_max_poids', array('maxi' => taille_en_octets(_LOGO_MAX_SIZE * 1024), 'actuel' => taille_en_octets($poids)));
        }
        if (!$erreur) {
            @rename($file_tmp, _DIR_LOGOS . $nom . ".{$type}");
        }
    } else {
        spip_unlink($file_tmp);
        $erreur = _T('info_logo_format_interdit', array('formats' => join(', ', $GLOBALS['formats_logos'])));
    }
    return $erreur;
}
Example #7
0
function logo_revision($id, $file, $type, $ref)
{
    $chercher_logo = charger_fonction('chercher_logo', 'inc');
    $_id_objet = id_table_objet($type);
    // Chargement d'un nouveau logo ?
    if ($file['logo']) {
        define('FILE_UPLOAD', true);
        // message pour crayons_json_export :(
        if (include_spip("action/editer_logo") and function_exists("logo_modifier")) {
            logo_modifier($type, $id, "on", $file['logo']);
        } else {
            // supprimer l'ancien logo
            $on = $chercher_logo($id, $_id_objet, 'on');
            if ($on) {
                @unlink($on[0]);
            }
            // ajouter le nouveau
            include_spip('action/iconifier');
            action_spip_image_ajouter_dist(type_du_logo($_id_objet) . 'on' . $id, false, false);
            // beurk
        }
    } else {
        // Suppression du logo ?
        if ($wid = array_pop($ref) and $_POST['content_' . $wid . '_logo_supprimer'] == 'on') {
            if (include_spip("action/editer_logo") and function_exists("logo_supprimer")) {
                logo_supprimer($type, $id, "on");
            } else {
                if ($on = $chercher_logo($id, $_id_objet, 'on')) {
                    @unlink($on[0]);
                }
            }
        }
    }
    // Reduire le logo ?
    if (is_array($cfg = @unserialize($GLOBALS['meta']['crayons'])) and $max = intval($cfg['reduire_logo'])) {
        $on = $chercher_logo($id, $_id_objet, 'on');
        include_spip('inc/filtres');
        @copy($on[0], $temp = _DIR_VAR . 'tmp' . rand(0, 999) . '.' . $on[3]);
        $img1 = filtrer('image_reduire', $temp, $max);
        $img2 = preg_replace(',[?].*,', '', extraire_attribut($img1, 'src'));
        if (@file_exists($img2) and $img2 != $temp) {
            if (include_spip("action/editer_logo") and function_exists("logo_modifier")) {
                logo_modifier($type, $id, "on", $img2);
            } else {
                @unlink($on[0]);
                $dest = $on[1] . $on[2] . '.' . preg_replace(',^.*\\.(gif|jpg|png)$,', '\\1', $img2);
                @rename($img2, $dest);
            }
        }
        @unlink($temp);
    }
    return true;
}
Example #8
0
function indiquer_logo($titre, $id_objet, $mode, $id, $script, $iframe_script) {

	global $formats_logos;
	$afficher = "";
	$reg = '[.](' . join('|', $formats_logos) . ')$';


/*
	# CODE MORT SI ON DECIDE DE NE PAS LAISSER UPLOADER DES LOGOS PAR FTP

	if ($GLOBALS['flag_upload']
	AND $dir_ftp = determine_upload('logos')
	AND $fichiers = preg_files($dir_ftp, $reg)) {
		foreach ($fichiers as $f) {
			$f = substr($f, strlen($dir_ftp));
			$afficher .= "\n<option value='$f'>$f</option>";
		}
	}
	if (!$afficher) {
		if ($dir_ftp) {
			$afficher = _T('info_installer_images_dossier',
				array('upload' => '<b>' . joli_repertoire($dir_ftp) . '</b>'));
		}
	} else {
		$afficher = "\n<div style='text-align: left'>" .
			_T('info_selectionner_fichier',
				array('upload' => '<b>' . joli_repertoire($dir_ftp) . '</b>')) .
			":</div>" .
			"\n<select name='source' class='forml' size='1'>$afficher\n</select>" .
			"\n<div style='text-align:" .
			$GLOBALS['spip_lang_right'] .
			"'><input name='sousaction2' type='submit' value='".
			_T('bouton_choisir') .
			"'  /></div>";
	}
*/

	$afficher = "\n<label for='image'>" .
		_T('info_telecharger_nouveau_logo') .
		"</label><br />" .
		"\n<input name='image' id='image' type='file' class='forml spip_xx-small' size='15' />" .
		"<div style='text-align: " .  $GLOBALS['spip_lang_right'] . "'>" .
		"\n<input name='sousaction1' type='submit' value='" .
		_T('bouton_telecharger') .
		"'  /></div>" .
		$afficher;

	$type = type_du_logo($id_objet);
	return redirige_action_post('iconifier',
		"$id+$type$mode$id",
		$script,
		"$id_objet=$id",
		$iframe_script.$afficher,
		" enctype='multipart/form-data' class='form_upload_icon'");
}