Valider 9de35dd8 rédigé par esj's avatar esj
Parcourir les fichiers

La rotation des images passe en AJAX. Ce dépot implémente la tâche #487 de la...

La rotation des images passe en AJAX. Ce dépot implémente la tâche #487 de la meme façon que le dépot [6962] implémentait la tâche [486], sans inconvénients graphiques cette fois car c'est en fait plus facile (d'ailleurs la requete est en GET).

Au passage, nettoyage du script ajax_page car sa générité grandissante lui impose d'éviter les calculs inutiles. Il devrait s'améliorer encore.
parent ec2218a3
Chargement en cours
Chargement en cours
Chargement en cours
Chargement en cours
+30 −15
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
@@ -17,16 +17,26 @@ include_spip('base/abstract_sql');

function action_tourner_dist() {
	
	global $var_rot, $convert_command, $redirect;
	global $action, $arg, $hash, $id_auteur;
	global $convert_command;

	include_spip('inc/actions');

	$arg = $_REQUEST['arg'];
	$hash = $_REQUEST['hash'];
	$action = $_REQUEST['action'];
	$redirect = $_REQUEST['redirect'];
	$id_auteur = $_REQUEST['id_auteur'];

	if (!verifier_action_auteur("$action-$arg", $hash, $id_auteur)) {
		include_spip('inc/minipres');
		minipres(_T('info_acces_interdit'));
	}
	$var_rot = intval($var_rot);
	$arg = intval($arg);

	if (!preg_match(",^\W*(\d+)\\W+(\d+)$,", $arg, $r)) {
		 spip_log("action_tourner_dist $arg pas compris");
	} else {
	$var_rot = $r[2];
	$arg = $r[1];
	$result = spip_query("SELECT id_vignette, fichier FROM spip_documents WHERE id_document=$arg");

	if ($row = spip_fetch_array($result)) {
@@ -69,10 +79,8 @@ function action_tourner_dist() {
*/

		spip_query("UPDATE spip_documents SET largeur=$largeur, hauteur=$hauteur WHERE id_document=$arg");

	  }
	redirige_par_entete(rawurldecode($redirect));

	}
}


@@ -81,27 +89,34 @@ function action_tourner_dist() {
// Faire tourner une image
//
function gdRotate ($imagePath,$rtt){
	$src_img = '';
	if(preg_match("/\.(png|gif|jpe?g|bmp)$/i", $imagePath, $regs)) {
		switch($regs[1]) {
			case 'png':
			  if (function_exists('ImageCreateFromPNG')) {
				$src_img=ImageCreateFromPNG($imagePath);
				$save = 'imagepng';
			  }
			  break;
			case 'gif':
			  if (function_exists('ImageCreateFromGIF')) {
				$src_img=ImageCreateFromGIF($imagePath);
				$save = 'imagegif';
			  }
			  break;
			case 'jpeg':
			case 'jpg':
			  if (function_exists('ImageCreateFromJPEG')) {
				$src_img=ImageCreateFromJPEG($imagePath);
				$save = 'Imagejpeg';
			  }
			  break;
			case 'bmp':
				$src_img=ImageCreateFromWBMP($imagePath);
			  if (function_exists('ImageCreateFromWBMP')) {
				$src_img=@ImageCreateFromWBMP($imagePath);
				$save = 'imagewbmp';
			  }
			  break;
			default:
				return false;
		}
	}

+60 −24
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
@@ -16,10 +16,7 @@ if (!defined("_ECRIRE_INC_VERSION")) return;

function exec_ajax_page_dist()
{
	global $flag_ob, $fonction, $id, $exclus, $col, $id_ajax_fonc, $type, $rac;
	$id = intval($id);
	$exclus = intval($exclus);
	$col = intval($col);
	global $flag_ob, $fonction;

	$var_nom = 'ajax_page_' . $fonction;
	if (!function_exists($var_nom))
@@ -32,7 +29,7 @@ function exec_ajax_page_dist()
// Curieux: le content-type bloque MSIE!
//		@header('Content-type: text/html; charset=$charset');
		echo "<"."?xml version='1.0' encoding='$charset'?".">\n";
		$var_nom($id, $exclus, $col, $id_ajax_fonc, $type, $rac);
		$var_nom();

		if ($flag_ob) {
			$a = ob_get_contents();
@@ -45,9 +42,14 @@ function exec_ajax_page_dist()

# Une fonction stockee en base de donnees ?

function ajax_page_sql($id, $exclus, $col, $id_ajax_fonc, $type, $rac)
function ajax_page_sql()
{
	global $connect_id_auteur;
	global $id, $exclus, $col, $id_ajax_fonc, $type, $rac;
	$id = intval($id);
	$exclus = intval($exclus);
	$col = intval($col);

	$res = spip_query("SELECT variables FROM spip_ajax_fonc	WHERE id_ajax_fonc =" . spip_abstract_quote($id_ajax_fonc) . " AND id_auteur=$connect_id_auteur");
	if ($row = spip_fetch_array($res)) {
		
@@ -72,11 +74,10 @@ function ajax_page_sql($id, $exclus, $col, $id_ajax_fonc, $type, $rac)
			include_spip('inc/mots');
			afficher_groupe_mots ($id_groupe);
		}
		
	}
}

function ajax_page_test($id, $exclus, $col, $id_ajax_fonc, $type, $rac)
function ajax_page_test()
{
	# tester si ca fonctionne pour ce brouteur
	// (si on arrive la c'est que c'est bon, donc poser le cookie)
@@ -85,8 +86,11 @@ function ajax_page_test($id, $exclus, $col, $id_ajax_fonc, $type, $rac)
}

# Un moteur de recherche ?
function ajax_page_recherche($id, $exclus, $col, $id_ajax_fonc, $type, $rac)
function ajax_page_recherche()
{
	global $id, $exclus, $type, $rac;
	$id = intval($id);
	$exclus = intval($exclus);

		include_spip('inc/texte');
		$where = split("[[:space:]]+", $type);
@@ -173,8 +177,12 @@ function ajax_page_recherche($id, $exclus, $col, $id_ajax_fonc, $type, $rac)

# afficher un mini-navigateur de rubriques

function ajax_page_aff_rubrique($id, $exclus, $col, $id_ajax_fonc, $type, $rac)
function ajax_page_aff_rubrique()
{
	global $id, $exclus, $rac;
	$id = intval($id);
	$exclus = intval($exclus);

	include_spip('inc/texte');
	include_spip('inc/mini_nav');
	echo mini_nav ($id, "choix_parent", "this.form.id_rubrique.value=::sel::;this.form.titreparent.value='::sel2::';findObj('selection_rubrique').style.display='none';", $exclus, $rac);
@@ -183,8 +191,13 @@ function ajax_page_aff_rubrique($id, $exclus, $col, $id_ajax_fonc, $type, $rac)

# afficher les sous-rubriques d'une rubrique (composant du mini-navigateur)

function ajax_page_aff_rub($id, $exclus, $col, $id_ajax_fonc, $type, $rac)
function ajax_page_aff_rub()
{
	global $id, $exclus, $col, $rac;
	$id = intval($id);
	$exclus = intval($exclus);
	$col = intval($col);

	include_spip('inc/texte');
	include_spip('inc/mini_nav');
	echo mini_afficher_rubrique ($id, 
@@ -194,8 +207,11 @@ function ajax_page_aff_rub($id, $exclus, $col, $id_ajax_fonc, $type, $rac)

# petit moteur de recherche sur les rubriques

function ajax_page_aff_nav_recherche($id, $exclus, $col, $id_ajax_fonc, $type, $rac)
function ajax_page_aff_nav_recherche()
{
	global $id;
	$id = intval($id);

	include_spip('inc/texte');
	include_spip('inc/mini_nav');
	echo mini_nav ($id, "aff_nav_recherche", 
@@ -205,9 +221,14 @@ function ajax_page_aff_nav_recherche($id, $exclus, $col, $id_ajax_fonc, $type, $

# Affiche les infos d'une rubrique selectionnee dans le mini navigateur

function ajax_page_aff_info($id, $exclus, $col, $id_ajax_fonc, $type, $rac)
function ajax_page_aff_info()
{
	global $couleur_foncee,$spip_display,$spip_lang_right ;
	global $id, $exclus, $col, $type, $rac;
	$id = intval($id);
	$exclus = intval($exclus);
	$col = intval($col);

		include_spip('inc/texte');
		if ($type == "rubrique") {
			$res = spip_query("SELECT titre, descriptif FROM spip_rubriques WHERE id_rubrique = $id");
@@ -257,14 +278,29 @@ function ajax_page_aff_info($id, $exclus, $col, $id_ajax_fonc, $type, $rac)


		echo "</div>";
}

function ajax_page_documenter()
{
	global $id_document, $script, $id, $type, $ancre;
	$id = intval($id);
	$id_document = intval($id_document);

	include_spip('inc/documents');
	include_spip('inc/presentation');

	echo formulaire_documenter($id_document, array(), $script, $type, $id, $ancre);
}

function ajax_page_document($id, $bof, $id_document, $script, $type, $ancre)
function ajax_page_tourner()
{
	global $id_document, $script, $id, $type, $ancre;
	$id = intval($id);
	$id_document = intval($id_document);

	include_spip('inc/documents');
	include_spip('inc/presentation');

	echo formulaire_document($id_document, array(), $script, $type, $id, $ancre);
	echo formulaire_tourner($id_document, array(), $script, 'ajax', $type);
}
?>
+16 −10
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
@@ -176,25 +176,31 @@ function ajahReady(xhr, f) {
        }
}

// Si Ajax est disponible, cette fonction envoie le formulaire avec lui.
// Elle renvoie False pour empecher l'envoi du formulaire en mode normal.
// Si Ajax est disponible, cette fonction envoie la requete en Ajax.
// Si le premier argument n'est pas une url, ce doit etre un formulaire.
// Le deuxieme argument doit etre l'ID du noeud a affecter avec la reponse.
// En cas de formulaire, la fonction retourne False pour empecher son envoi
// Le cas True ne devrait pas se produire car le cookie spip_accepte_ajax
// a du anticiper la situation.
// Toutefois il y toujours un coup de retard dans la pose d'un cookie:
// eviter de se loger avec redirection vers un telle page

function AjaxSqueeze(form, div)
function AjaxSqueeze(trig, id)
{
	var i;
	var i, s;
	var u = '';
	var s = form.getAttribute('action');
	// pere du formulaire (le donner direct serait mieux)
	var noeud = document.getElementById(div);
	
	// pere du demandeur dans le DOM (le donner direct serait mieux)
	var noeud = document.getElementById(id);
	if (!noeud) return true;

	for (i=0;i < form.elements.length;i++) {
		n = form.elements[i].name;
		if (n)  u += n+"="+escape(form.elements[i].value) + '&';
	if (typeof(trig) == 'string')
	  return ajah('GET', trig, null, function(r) { noeud.innerHTML = r;});

	s = trig.getAttribute('action');
	for (i=0;i < trig.elements.length;i++) {
		n = trig.elements[i].name;
		if (n)  u += n+"="+escape(trig.elements[i].value) + '&';
	}

	return !ajah('POST', // ou 'GET'
+126 −105
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
@@ -698,59 +698,71 @@ function afficher_portfolio(
	$case = 0;

	foreach ($documents as $document) {
		$id_article = $document["id_$type"]; 		# numero de l'article ou de la rubrique
		$id_document = $document['id_document'];
		$id_vignette = $document['id_vignette'];
		$titre = $document['titre'];
		$descriptif = $document['descriptif'];
		if (!isset($document['url']))
			$url = generer_url_document($id_document);
		else
			$url = $document['url'];
		$fichier = $document['fichier'];
		$largeur = $document['largeur'];
		$hauteur = $document['hauteur'];
		$taille = $document['taille'];
		$date = $document['date'];
		$mode = $document['mode'];

		# script pour l'action des formulaires
		if (isset($document['script']))
			$script = $document['script']; 
		else if ($type == "rubrique") {
		elseif ($type == "rubrique")
			$script = 'naviguer';
		  $script = 'articles';
		}
		else	$script = $GLOBALS['exec'];

		$style = "";
		if (!$case)
			echo "<tr style='border-top: 1px solid black;'>";
		else if ($case == $bord_droit)
			$style .= " border-$spip_lang_right: 1px solid $couleur;";
		echo "\n<td  style='width:33%; text-align: $spip_lang_left; border-$spip_lang_left: 1px solid $couleur; border-bottom: 1px solid $couleur; $style' valign='top'>";

		echo formulaire_tourner($id_document, $document, $script, $flag_modif, $type);

		if ($case == 0) {
			echo "<tr style='border-top: 1px solid black;'>";
		}
		if ($flag_modif) 
			echo formulaire_documenter($id_document, $document, $script, $type, $document["id_$type"], $album);

		$style = "border-$spip_lang_left: 1px solid $couleur; border-bottom: 1px solid $couleur;";
		if ($case == $bord_droit) $style .= " border-$spip_lang_right: 1px solid $couleur;";
		echo "\n<td  style='width:33%; text-align: $spip_lang_left; $style' valign='top'>";
		if (isset($document['info']))
			echo "<div class='verdana1'>".$document['info']."</div>";
		echo "</td>\n";
		$case++;
				
		$res = '';
		// Signaler les documents distants par une icone de trombone
		if ($document['distant'] == 'oui') {
			$res .= "\n<img src='"._DIR_IMG_PACK.'attachment.gif'."'\n\t style='float: $spip_lang_right;'\n\talt=\"".entites_html($document['fichier'])."\"\n\ttitle=\"" .
entites_html($document['fichier'])."\" />\n";
		if ($case > $bord_droit) {
			  $case = 0;
			  echo "</tr>\n";
		}
			
		// bloc vignette + rotation
		$res .= "<div style='text-align:center;'><b>" . 
		  typo($titre ? $titre : _T('info_sans_titre_2')) .
		  '</b><br />';
		document_vu($id_document);
	}
	// fermer la derniere ligne
	if ($case) {
		echo "<td style='border-$spip_lang_left: 1px solid $couleur;'>&nbsp;</td>";
		echo "</tr>";
	}
}

		if ($flag_modif)
			$res .= afficher_rotateurs($album, $document, $type, $id_article, $id_document, $id_vignette);

		//
		// Recuperer la vignette et afficher le doc
		//
function formulaire_tourner($id_document, $document, $script, $flag_modif, $type)
{
	global $spip_lang_right;

	if (!$document) {
	  	// retour d'Ajax
		$document = spip_fetch_array(spip_query("SELECT * FROM spip_documents WHERE id_document = " . intval($id_document)));
	}

	$id = $document["id_$type"];
	$titre = $document['titre'];
	$id_vignette = $document['id_vignette'];
	$fichier = entites_html($document['fichier']);

	if (isset($document['url']))
		$url = $document['url'];
	else {
		charger_generer_url();
		$url = generer_url_document($id_document);
	}

	if ($flag_modif)
		$res .= boutons_rotateurs($document, $type, $id, $id_document,$script,  $id_vignette);
	else $res = '';
	// Indiquer les documents manquants avec un panneau de warning

	if ($document['distant'] != 'oui'
@@ -766,34 +778,26 @@ entites_html($document['fichier'])."\" />\n";
	$res .= "<div class='verdana1' style='text-align: center;'>";
	$res .= " <font size='1' face='arial,helvetica,sans-serif' color='333333'>&lt;doc$id_document&gt;</font>";
	$res .= "</div>";
		$res .= "</div>"; // fin du bloc vignette + rotation

		echo $res;
	if ($flag_modif === 'ajax') return $res;

		if ($flag_modif) 
		      echo formulaire_document($id_document, $document, $script, $type, $id_article, $album);
	$boite = '';

		if (isset($document['info']))
			echo "<div class='verdana1'>".$document['info']."</div>";
		echo "</td>\n";
		$case++;
	// Signaler les documents distants par une icone de trombone
	if ($document['distant'] == 'oui')
		$boite .= "\n<img src='"._DIR_IMG_PACK.'attachment.gif'."'\n\t style='float: $spip_lang_right;'\n\talt=\"$fichier\"\n\ttitle=\"$fichier\" />\n";
	$boite .= "<div style='text-align:center;'><b>" . 
		  typo($titre ? $titre : _T('info_sans_titre_2')) .
		  "</b><div id='tourner-$id_document'>" .
		$res .
		'</div></div>';

		if ($case > $bord_droit) {
			  $case = 0;
			  echo "</tr>\n";
		}
	return $boite;

		document_vu($id_document);
	}
	// fermer la derniere ligne
	if ($case > 0) {
			echo "<td style='border-$spip_lang_left: 1px solid $couleur;'>&nbsp;</td>";
			echo "</tr>";
	}
}

}

function  afficher_rotateurs($album, $document, $type, $id_article, $id_document, $id_vignette) {
function boutons_rotateurs($document, $type, $id, $id_document, $script, $id_vignette) {
	global $spip_lang_right;
	static $ftype = array(1 => 'jpg', 2 => 'png', 3 => 'gif');

@@ -814,30 +818,26 @@ function afficher_rotateurs($album, $document, $type, $id_article, $id_document

	  return "\n<div class='verdana1' style='float: $spip_lang_right; text-align: $spip_lang_right;'>" .

		  // tourner a gauche
		http_href_img(bouton_tourner_document($id_article, $id_document, $album, -90, $type), 'tourner-gauche.gif', "", _T('image_tourner_gauche'), '', 'bouton_rotation') . "<br />" .
		bouton_tourner_document($id, $id_document, $script, -90, $type, 'tourner-gauche.gif', _T('image_tourner_gauche')) .

		// tourner a droite
	 	http_href_img(bouton_tourner_document($id_article, $id_document, $album, 90, $type), 'tourner-droite.gif', "",  _T('image_tourner_droite'), '', 'bouton_rotation') . "<br />" .
		bouton_tourner_document($id, $id_document, $script,  90, $type, 'tourner-droite.gif', _T('image_tourner_droite')) .

		// tourner 180
		http_href_img(bouton_tourner_document($id_article, $id_document, $album, 180, $type), 'tourner-180.gif', "", _T('image_tourner_180'), '', 'bouton_rotation') . "</div>\n";
		bouton_tourner_document($id, $id_document, $script, 180, $type, 'tourner-180.gif', _T('image_tourner_180')) .
		"</div>\n";
	}
	return '';
}


function bouton_tourner_document($id_article, $id, $album, $rot, $type)
function bouton_tourner_document($id, $id_document, $script, $rot, $type, $img, $title)
{
	return redirige_action_auteur('tourner', $id, $GLOBALS['exec'], "id_$type=$id_article&show_docs=$id#$album") .
		"&amp;var_rot=$rot";
}

function bouton_supprime_document_et_vignette($id_article, $type, $id_v, $album, $id_document=0)
{
	return redirige_action_auteur('supprimer', "document-$id_v", $GLOBALS['exec'], "id_$type=$id_article#$album");


  return ajax_action_auteur("tourner",
			    "$id_document-$rot",
			    array(http_img_pack($img, $title, ''),
				  'bouton_rotation'),
			    $sript,
"&id_document=$id_document&id=$id&type=$type",
"&show_docs=$id_document&id_$type=$id#tourner-$id_document") .
    "<br />";
}

function afficher_documents_non_inclus($id_article, $type = "article", $flag_modif) {
@@ -1089,7 +1089,7 @@ function afficher_case_document($id_document, $id, $type, $deplier = false) {
			  "</font></div>";
		}

		echo formulaire_document($id_document, $document, '', $type, $id, "document$id_document");
		echo formulaire_documenter($id_document, $document, '', $type, $id, "document$id_document");

		fin_cadre_enfonce();
		}
@@ -1136,7 +1136,7 @@ function afficher_case_document($id_document, $id, $type, $deplier = false) {
		if (ereg(",$id_document,", $doublons))
			echo $raccourci_doc;

		echo formulaire_document($id_document, $document,'', $type, $id, "document$id_document");
		echo formulaire_documenter($id_document, $document,'', $type, $id, "document$id_document");
		
		fin_cadre_relief();
	}
@@ -1153,7 +1153,7 @@ function teste_doc_deplie($id_document) {
}


function date_formulaire_document($date, $id_document) {
function date_formulaire_documenter($date, $id_document) {

	if (ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})", $date, $regs)){
		$mois = $regs[2];
@@ -1172,7 +1172,7 @@ function date_formulaire_document($date, $id_document) {
// En mode Ajax pour eviter de recharger toute la page ou il se trouve
// (surtout si c'est un portfolio)

 function formulaire_document($id_document, $document, $script='', $type, $id, $ancre)
 function formulaire_documenter($id_document, $document, $script, $type, $id, $ancre)
{
	if ($document) {
		// premier appel
@@ -1229,7 +1229,7 @@ function date_formulaire_document($date, $id_document) {
	  "<input type='text' name='titre_document' class='formo' value=\"".entites_html($titre).
	  "\" size='40'	onFocus=\"changeVisible(true, 'valider_doc$id_document', 'block', 'block');\"><br />\n" .
	  '<br />' . 
	  date_formulaire_document($date, $id_document) .
	  date_formulaire_documenter($date, $id_document) .
	  "<br /><b>".
	  _T('info_description_2').
	  "</b><br />\n" .
@@ -1246,22 +1246,10 @@ function date_formulaire_document($date, $id_document) {
	  "' type='submit' />" .
	  "</div>\n";

	$bloc = "document_$id_document";
	$bloc = "documenter-$id_document";

	$corps = ajax_action_auteur("documenter", $id_document, $corps, $script, "&id_document=$id_document&id=$id&type=$type&ancre=$ancre","show_docs=$id_document&id_$type=$id#$ancre");

	if ($_COOKIE['spip_accepte_ajax'] == 1 )
		$corps = redirige_action_auteur("documenter", 
				$id_document,
				'ajax_page',
				"fonction=document&col=$id_document&id=$id&type=$type&id_ajax_fonc=$script&rac=$ancre",
				$corps,
				"\nmethod='post' onsubmit='return AjaxSqueeze(this, \"$bloc\")'");
	else
		$corps = redirige_action_auteur("documenter", 
				$id_document,
				$script,
				"show_docs=$id_document&id_$type=$id#$ancre",
				$corps,
				"\nmethod='post'");
	$corps .= 
	  $vignette .
	  icone_horizontale(_T('icone_supprimer_document'), redirige_action_auteur('supprimer', "document-$id_document", $script, "id_$type=$id#$ancre"), $supp,  "supprimer.gif", false);
@@ -1275,4 +1263,37 @@ function date_formulaire_document($date, $id_document) {
	  '</div>' .
	   fin_block());
}

// Retourne un formulaire d'execution de $action sur $id,
// revenant a l'envoyeur $script d'arguments $args.
// Utilise Ajax si dispo, en ecrivant le resultat dans le innerHTML du noeud
// d'attribut  id = $action-$id (AjaxSqueeze dans layer.js)

function ajax_action_auteur($action, $id, $corps, $script, $args_ajax, $args)
{
	if ($_COOKIE['spip_accepte_ajax'] != 1 ) 
		return redirige_action_auteur($action, 
				$id,
				$script,
				$args,
				$corps,
				"\nmethod='post'");

	$pere = '"' . "$action-" . intval($id) . '"';

	if (is_string($corps))
		return redirige_action_auteur($action,
				$id,
				'ajax_page',
				"fonction=$action&script=$script$args_ajax",
				$corps,
				"\nmethod='post' onsubmit='return AjaxSqueeze(this, $pere)'");
	list($clic, $class) = $corps;
	$href = redirige_action_auteur($action,
				$id,
				'ajax_page',
				"fonction=$action&script=$script$args_ajax");
	return "<div class='$class' onclick='AjaxSqueeze(\"$href\",$pere)'>$clic</div>";
			
}
?>