diff admin.php @ 0:629389204276

Import initial
author Franck Deroche <webmaster@defr.org>
date Sat, 20 Oct 2007 14:15:10 +0200
parents
children ec0c926a78a6
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/admin.php	Sat Oct 20 14:15:10 2007 +0200
@@ -0,0 +1,283 @@
+<?php
+ if(!is_null($_SERVER['HTTP_ACCEPT']) && stristr($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml'))
+  header('Content-Type: application/xhtml+xml; charset=UTF-8');
+ else
+  header('Content-Type: text/html; charset=UTF-8');
+
+ include("classes.php");
+ $Data=new DataAccess;
+ $Req = new Requete;
+ 
+ $mode = $Req->get('mode');
+ switch($mode) {
+	case 'nvBrouillon':
+	$nvTitre = $Req->get('Titre', 'POST');
+	$nvContenu = $Req->get('Contenu', 'POST');
+	$Data->debugQuery("INSERT INTO Brouillons SET Titre='{$nvTitre}', Contenu='{$nvContenu}'");
+	break;
+	
+	case 'nvTache':
+	$nvThing = $Req->get('Tache');
+	$Data->Query("INSERT INTO ToDo SET Thing='{$nvThing}'");
+	break;
+	
+	case 'nvPost':
+	 $id = $Req->get('id', 'POST');
+	 $versionAc = $Req->get('versionAc', 'POST');
+	 $newVersion = $Req->get('newVersion', 'POST');
+	 $mood = $Req->get('mood', 'POST');
+	 $tbAddress = $Req->get('tb', 'POST');
+	 if($versionAc == 'Version 10' && $newVersion != 'Nouvelle version ?' && !empty($newVersion))
+		$version = $newVersion;
+	 else
+		$version = $versionAc;
+	 $Data->Query("SELECT * FROM Brouillons WHERE id_brouillon={$id}");
+	 $row = $Data->GetRow();
+	 $row['Titre'] = addslashes($row['Titre']);
+	 $row['Contenu'] = addslashes($row['Contenu']);
+	 $datePost = gmdate("Y-m-d H:i:s", time() + 3600);
+	 $Data->Query("
+	  INSERT INTO Mess(Titre, DatePost, num_version, Message, Emot) 
+	  VALUES('{$row['Titre']}', '{$datePost}', '{$version}', '{$row['Contenu']}', '{$mood}')");
+	 $Data->Query("DELETE FROM Brouillons WHERE id_brouillon={$id}");
+	 $Data->Query("SELECT num_mess, Message FROM Mess ORDER BY num_mess DESC LIMIT 0, 1");
+	 $id_row = $Data->GetRow();
+	 // Gestion des tags
+	 $arTags = TextUtils::SplitTags($Req->get('Tags'));
+	 foreach($arTags as $tagAj)
+	 {
+	    $n = $Data->Query("SELECT idTag FROM Tags WHERE Tag='{$tagAj}'");
+	    if($n ==  0)
+	    {
+		// Si le tag n'existe pas, on le crée
+		$Data->Query("INSERT INTO Tags SET Tag='{$tagAj}'");
+		$Data->Query("SELECT idTag FROM Tags WHERE Tag='{$tagAj}'");
+	    }
+	    $row_tag = $Data->GetRow();
+	    $Data->Query
+	    ("
+		INSERT INTO Lien_Tags_Posts 
+		SET idMess={$id_row['num_mess']}, idTag={$row_tag['idTag']}
+	    ");
+	 }
+	 // Génération de trackbacks
+	 if(!empty($tbAddress) && substr($tbAddress, 0, 4)=='http') {
+		$ar_tbAddress = parse_url($tbAddress);
+		if(!array_key_exists('port', $ar_tbAddress)) $ar_tbAddress['port'] = 80;
+		if(!array_key_exists('path', $ar_tbAddress)) $ar_tbAddress['path'] = '/';
+		if(array_key_exists('query', $ar_tbAddress)) $ar_tbAddress['query'] = '?' . $ar_tbAddress['query'];
+		$fp = fsockopen($ar_tbAddress['host'], $ar_tbAddress['port'], $errno, $errstr, 15);
+		if($fp) {
+			$genToSend = "POST {$ar_tbAddress['path']}{$ar_tbAddress['query']} HTTP/1.0\r\n";
+			$genToSend .= "Host: {$ar_tbAddress['host']}\r\n";
+			$genToSend .= "Content-Type: application/x-www-form-urlencoded \n";
+			
+			// Essai de récuperation de l'encodage...Envoie en iso si pas d'indication d'UTF...
+			$argToSend = "__info=1";
+			$toSend = $genToSend . "Content-Length: " . strlen($argToSend) . "\n\n";
+			$toSend .= $argToSend;
+			echo("<pre>$toSend</pre>");
+			fwrite($fp, $toSend);
+			while(!feof($fp))
+				$result .= fgets($fp, 128);
+			fclose($fp);
+			if(!preg_match('/<encoding>(UTF-8|utf-8)<\/encoding>/msU',$result)) {
+				$row['Titre'] = utf8_decode($row['Titre']);
+				$row['Message'] = utf8_decode($row['Message']);
+			}
+			
+			$fp = fsockopen($ar_tbAddress['host'], 80, $errno, $errstr, 15);
+			$argToSend = "title=" . htmlentities(urlencode($row['Titre'])) . "&blog_name=Dual+Blog";
+			$argToSend .= "&url=http://defr.org/blog/posts/{$row['num_mess']}&excerpt=" 
+								. htmlentities(urlencode(substr(strip_tags($row['Message']), 0, 255) . "..."));
+
+			$toSend = $genToSend . "Content-Length: " . strlen($argToSend) . "\n\n";
+			$toSend .= $argToSend;
+			echo("<pre><![CDATA[$toSend]]></pre>");
+			echo("<![CDATA[");
+			fwrite($fp, $toSend);
+			while (!feof($fp)) {
+				echo fgets($fp, 128);
+			}
+			echo("]]>");
+			fclose($fp);
+		}
+	}
+	 break;
+ }
+?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+
+<html xmlns='http://www.w3.org/1999/xhtml'>
+<head>
+ <title>Administration : Conception &amp; Design</title>
+ <link rel='StyleSheet' type='Text/CSS' href='css/admin.css' />
+ <script type='text/javascript' src='admin.js'>/* Die IE, diiie */</script> 
+</head>
+
+<body>
+ <h3>Administration de Dual Blog</h3>
+<ul id='Menu'>
+ <li><div id='Brouillons'>Brouillons</div></li>
+ <li><div id='Posts'>Posts publiés</div></li>
+ <li><div id='Designs'>Designs</div></li>
+ <li><div id='ToDo'>To-Do</div></li>
+</ul>
+<div id='GestPosts'>
+<ul>
+<?php
+ $Data->Connect();
+ $Data->Query("SELECT * FROM Mess ORDER BY num_version, num_mess DESC LIMIT 0, 10");
+ $versionAc="";
+ $i=0;
+ $ar_Version = array();
+ while(0!==($val=$Data->GetRow())) {
+  if($val['num_version']!=$versionAc) {
+	if($i!=0) echo("</ul>\n</li>");
+	echo("  <li>{$val['num_version']} :\n    <ul>");
+	$versionAc=$val['num_version'];
+	$ar_Version[] = $versionAc;
+	$i++;
+  }
+  $Titre=$Data->utf8_ensure($val['Titre']);
+  echo("
+  \t  <li>{$Titre}<span class='Admin'><a href='#id={$val['num_mess']}'>Editer</a>  --  <a href='#id={$val['num_mess']}'>Supprimer</a>  --  <a href='?id={$val['num_mess']}'>Gérer les commentaires</a></span></li>");
+ }
+ echo("\n    </ul>\n  </li>\n");
+?>
+</ul>
+</div>
+
+<div id='GestDesigns'>
+<ul>
+ <li class='Add'><a href='#'>Ajouter un nouveau design au weblog</a></li>
+ <li>Modifier les designs déja existants</li>
+</ul>
+</div>
+
+<div id='GestBrouillons'>
+ <ul>
+  <li class='Add'><a href='#'>Ajouter un nouveau brouillon</a>
+  <form method='post' action='admin.php'>
+   <div>
+   <input type='hidden' name='mode' value='nvBrouillon' />
+   <input type='text' name='Titre' value='Titre' />
+   <textarea name='Contenu' rows='10' cols='30'></textarea>
+   <input type='submit' value='Valider ce brouillon' />
+   </div>
+  </form>
+  </li>
+<?
+   $Data->Query("SELECT * FROM Brouillons ORDER BY id_brouillon DESC");
+   while(0!==($val=$Data->GetRow())) {
+	echo("
+   <li>{$val['Titre']}  <span class='Admin'><a href='#id={$val['id_brouillon']}'>Editer</a>  --  <a href='#id={$val['id_brouillon']}'>Publier</a>  --  <a href='?id={$val['id_brouillon']}'>Supprimer</a></span></li>");
+   }
+?>
+  </ul>
+</div>
+
+<div id='GestToDo'>
+<ul>
+ <li class='Add'><a href='#'>Ajouter une nouvelle tâche</a>
+ <form method='post' action='admin.php'>
+  <div>
+  <input type='hidden' name='mode' value='nvTache' />
+  <input type='text' name='Tache' />
+  <input type='submit' value='Ajouter cette tâche' />
+  </div>
+ </form></li>
+ <?php
+  $Data->Query("SELECT * FROM ToDo ORDER By num_thing DESC");
+  while(0!==($val=$Data->GetRow())) {
+    echo("
+  <li>{$val['Thing']} <span class='Admin'><a href='#'>Fait</a>  --  <a href='#'>Editer</a>  --  <a href='#'>Supprimer</a></span></li>");
+  }
+  $Data->Close();
+?>
+</ul>
+</div>
+
+<form method='post' action='#' id='editPost'>
+ <div>
+   <input type='hidden' name='mode' value='editBrouillon' />
+   <p><input type='text' name='Titre' value='Titre' /></p>
+   <p><textarea name='Contenu' rows='10' cols='30'></textarea></p>
+   <p><select name='mood' id='mood'>
+<?php
+		$handle = opendir('mood');
+		while($file = readdir($handle))
+		{
+		    if(strlen($file) > 3 && substr($file, -3) == 'png')
+		    {
+			  $short = substr($file, 0, -4);
+			  echo("\t\t<option value='$short'><img src='mood/25/$file' alt='' />" . $short . "</option>\n");
+		    }
+		}
+		closedir($handle);
+?>
+   </select></p>
+   <p><input type='text' name='Tags' value='Tags' /></p>
+   <input type='button' name='Save' value='Sauver la modification' /> 
+ </div>
+</form>
+
+<form method='post' action='admin.php' id='whichVersion'>
+ <div>
+ <!--a onclick='javascript:hidePubForm()'>Hide</a-->
+ <input type='hidden' name='mode' value='nvPost' />
+ <input type='hidden' name='id' />
+ <fieldset>
+	<legend>Catégorie du post</legend>
+	<label for='vAc'>Pour poster le post dans une catégorie déja existante, veuillez la choisir dans la liste ci-dessous :<br /></label>
+	<select name='versionAc' id='vAc'>
+	  <option>Version 10</option>
+	  <option>DeFr.org news</option>
+	</select>
+	<label for='nvCat'><br />Pour poster le post dans une catégorie n'existant pas encore, veuillez
+	entrer son nom : <br /></label>
+	<input type='text' name='newVersion' id='nvCat' value='Nouvelle version ?' />
+ </fieldset>
+ <fieldset>
+	  <legend>Tags</legend>
+	  <label for='Tags'>Histoire d'organiser les posts, et de pouvoir filtrer par centres d'interet, veuillez
+	  préciser les <em>tags</em> à attribuer à ce post :<br /></label>
+	  <input type='text' name='Tags' id='Tags' />
+ </fieldset>
+ <fieldset>
+	  <legend>Mood / Emots</legend>
+	  <label for='mood'>Pour assurer un minimum d'attrait aux posts, et leur attribuer un aspect graphique
+	  sympathique, veuillez selectionner une emoticone pour le post, dans la liste suivante :<br /></label>
+	  <select name='mood' id='mood'>
+<?php
+		$handle = opendir('mood');
+		while($file = readdir($handle))
+		{
+		    if(strlen($file) > 3 && substr($file, -3) == 'png')
+		    {
+			  $short = substr($file, 0, -4);
+			  echo("\t\t\t<option value='$short'><img src='mood/25/$file' alt='' />" . $short . "</option>\n");
+		    }
+		}
+		closedir($handle);
+?>
+	  </select>
+ </fieldset>
+ <fieldset>
+	<legend>Trackback</legend>
+	<label for='tb'>Pour effectuer un trackback vers un autre post, rentrer son URL :<br /></label>
+	<input type='text' name='tb' id='tb' value='TrackBack ?' />
+ </fieldset>
+ <fieldset>
+	<legend>Publication</legend>
+	<label id='pubComment' for='pubButton' />
+	<input type='submit' name="pubButton" id="pubButton" value='Publier' />
+ </fieldset>
+</div>
+</form>
+
+<div id='Infos'>
+Administration de Dual Blog - Par DeFr - Icones &copy; David Lanham - The IconFactory -
+Valide <a href="http://validator.w3.org/check?uri=referer">XHTML 1.1</a> et <a href='http://jigsaw.w3.org/css-validator/check/referer'>CSS 3</a>
+</div>
+</body>
+</html>