Subversion Repositories Applications.papyrus

Rev

Rev 898 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
545 ddelon 1
<?php
581 ddelon 2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
545 ddelon 3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This file is part of Integrateur Wikini.                                                             |
9
// |                                                                                                      |
10
// | Foobar is free software; you can redistribute it and/or modify                                       |
11
// | it under the terms of the GNU General Public License as published by                                 |
12
// | the Free Software Foundation; either version 2 of the License, or                                    |
13
// | (at your option) any later version.                                                                  |
14
// |                                                                                                      |
15
// | Foobar is distributed in the hope that it will be useful,                                            |
16
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
17
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
18
// | GNU General Public License for more details.                                                         |
19
// |                                                                                                      |
20
// | You should have received a copy of the GNU General Public License                                    |
21
// | along with Foobar; if not, write to the Free Software                                                |
22
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
23
// +------------------------------------------------------------------------------------------------------+
920 ddelon 24
// CVS : $Id: iw_integrateur.fonct.php,v 1.18 2006-08-29 20:01:33 ddelon Exp $
545 ddelon 25
/**
26
* Fonctions de l'integrateur de page Wikini
27
*
28
* Application permettant d'intégrer des pages wikini dans Papyrus.
29
*
30
*@package IntegrateurWikini
31
//Auteur original :
32
*@author        David Delon <david.delon@clapas.net>
33
//Autres auteurs :
34
*@author        Aucun
35
*@copyright     Tela-Botanica 2000-2004
920 ddelon 36
*@version       $Revision: 1.18 $ $Date: 2006-08-29 20:01:33 $
545 ddelon 37
*
38
// +------------------------------------------------------------------------------------------------------+
39
// |                                            ENTETE du PROGRAMME                                       |
40
// +------------------------------------------------------------------------------------------------------+
41
 
42
 
43
 
44
 
45
/** Inclusion de la classe PEAR de gestion des URL. */
46
 
47
$GLOBALS['_PAPYRUS_']['erreur']->setActive(0);
48
 
832 florian 49
require_once PAP_CHEMIN_API_PEAR.'Net/URL.php';
545 ddelon 50
 
51
// TODO : un seul fichier de configuration ?
52
/** Inclusion du fichier de configuration de cette application.*/
860 ddelon 53
require_once 'client/integrateur_wikini/configuration/adwi_configuration.inc.php';
545 ddelon 54
 
55
require_once ADWI_CHEMIN_BIBLIOTHEQUE.'adwi_wikini.fonct.php';
56
 
57
/** Inclusion du fichier de configuration général de IntegrateurWikini.*/
58
require_once 'client'.GEN_SEP.'integrateur_wikini'.GEN_SEP.'configuration'.GEN_SEP.'iw_config.inc.php';
59
 
60
/** Inclusion du fichier permettant d'encoder du texte mais pas les balises XHTML.*/
61
require_once IW_CHEMIN_BIBLIO.'iw_encodage.fonct.php';
62
/** Inclusion du fichier permettant d'inclure les données dans du XHTML.*/
63
require_once IW_CHEMIN_BIBLIO.'iw_affichage_xhtml.fonct.php';
64
 
65
global $wikini_config_defaut;
66
global $wiki;
67
global $wiki_p;
68
 
69
// $_REQUEST['wiki'] est obligatoire, car wakka.php envoie un redirect si non detecté, avec perte de tout l'environnement !
70
 
71
if ( ! isset( $_REQUEST['wiki'] ) ) {
72
	    $_REQUEST['wiki'] = $wikini_config_defaut['root_page'];
73
}
74
 
75
$server=$_SERVER['PHP_SELF'];
76
$_SERVER['PHP_SELF']="wakka.php";
77
 
78
// Utilise le wakkaconfig de la racine ...
79
// TODO : un wiki par défaut pour chaque papyrus à l'installation de Papyrus
80
// TODO : verifier bon dimensionnement des champs et clef de la table papyrus_wiki
81
// TODO : creation des tables par defaut à l'installation d'un wikini
82
// TODO : Fusion des fichiers de configuration ?
83
 
898 alexandre_ 84
//echo IW_CHEMIN_WIKINI_COURANT.'wakka.php';
85
if (!file_exists(IW_CHEMIN_WIKINI_COURANT.'wakka.php')) {
86
	if (GEN_DEBOGAGE) {
87
            $GLOBALS['_GEN_commun']['debogage_info'] .=
88
                'ERREUR Papyrus : le fichier '.IW_CHEMIN_WIKINI_COURANT.'wakka.php n\'existe pas.<br />'.
89
                'Identifiant : '. $id_fichier .'<br />'.
90
                'Ligne n° : '. __LINE__ .'<br />'.
91
                'Fichier : '. __FILE__;
92
    }
93
    return  ;
94
}
545 ddelon 95
ob_start();
96
include_once IW_CHEMIN_WIKINI_COURANT.'wakka.php';
556 ddelon 97
include_once(IW_CHEMIN_WIKINI_COURANT."/formatters/tableaux.php");
98
include_once(IW_CHEMIN_WIKINI_COURANT."/actions/attach.class.php");
545 ddelon 99
 
100
ob_end_clean();
101
$_SERVER['PHP_SELF']=$server;
102
 
103
 
104
// On surcharge la classe Wiki pour en faire ce qu'on en veut
105
Class Wiki_Papyrus extends Wiki {
581 ddelon 106
 
107
 
545 ddelon 108
	function Header() {
581 ddelon 109
 
545 ddelon 110
		return;
581 ddelon 111
	}
112
 
545 ddelon 113
 	function Footer() {
580 ddelon 114
 		echo  "<div class=\"footer\">";
115
		echo  $this->HasAccess("write") ? "<a href=\"".$this->href("edit")."\" title=\"Cliquez pour modifier cette page.\">Modifier cette page</a> ::\n" : "";
116
		echo  $this->GetPageTime() ? "<a href=\"".$this->href("revisions")."\" title=\"Cliquez pour voir les derni&egrave;res modifications sur cette page.\">".$this->GetPageTime()."</a> ::\n" : "";
117
		// 	if this page exists
118
		if ($this->page)
119
		{
120
		// if owner is current user
121
			if ($this->UserIsOwner())
122
			{
581 ddelon 123
				echo
580 ddelon 124
				"Propri&eacute;taire&nbsp;: vous :: \n",
125
				"<a href=\"",$this->href("acls")."\" title=\"Cliquez pour modifer les permissions de cette page.\">&Eacute;diter permissions</a> :: \n",
126
				"<a href=\"",$this->href("deletepage")."\">Supprimer</a> :: \n";
127
			}
128
			else
129
			{
130
				if ($owner = $this->GetPageOwner())
131
				{
132
					echo "Propri&eacute;taire : ",$this->Format($owner);
133
				}
134
				else
135
				{
136
					echo "Pas de propri&eacute;taire ";
137
					echo ($this->GetUser() ? "(<a href=\"".$this->href("claim")."\">Appropriation</a>)" : "");
138
				}
139
				echo " :: \n";
140
			}
141
		}
142
		echo "Vous &ecirc;tes ";
143
		echo $this->Format($this->GetUserName());
144
		echo "</div>";
581 ddelon 145
 
545 ddelon 146
 	}
581 ddelon 147
 
545 ddelon 148
	function FormOpen($method = "", $tag = "", $formMethod = "post") {
581 ddelon 149
 
150
	// Le diff ne fonctionne pas avec la methode get dans papyrus. On surcharge avec du post.
151
 
545 ddelon 152
		if (($method=="diff") && $formMethod=="get") {
581 ddelon 153
			$formMethod="post";
545 ddelon 154
		}
581 ddelon 155
 
545 ddelon 156
		if ($method=="edit") {
157
            $result = "<form id=\"ACEditor\" name=\"ACEditor\" action=\"".$this->href($method, $tag)."\" method=\"".$formMethod."\">\n";
158
            return $result;
159
		}
581 ddelon 160
 
545 ddelon 161
		return parent::FormOpen($method,$tag, $formMethod);
581 ddelon 162
 
545 ddelon 163
	}
164
	// Detournement des handlers : comme ca on peut faire ce que l'on veut ....
165
	function Method($method) {
581 ddelon 166
 
690 ddelon 167
		if ($method=="xml") {
168
			header("Content-type: text/xml");
169
			if ($pages = $this->LoadRecentlyChanged(50)) {
170
 
171
				$link=ereg_replace('&','&amp;',$this->Href());
172
			    $output = "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n";
173
			    $output .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">' . "\n";
174
			    $output .= "<channel>\n";
175
			    $output .= "<title> Derniers changements sur ". $this->config["wakka_name"]  . "</title>\n";
176
			    $output .= "<link>" .  $link . "</link>\n";
177
			    $output .= "<description> Derniers changements sur " . $this->config["wakka_name"] . " </description>\n";
178
			    $output .= "<language>fr</language>\n";
179
			    $output .= '<generator>WikiNi ' . WIKINI_VERSION . "</generator>\n";
180
			    foreach ($pages as $i => $page)
181
			    {
182
			        $output .= "<item>\n";
183
			        $output .= "<title>" . $page["tag"] . "</title>\n";
184
			        $output .= '<dc:creator>' . $page["user"] . "</dc:creator>\n";
185
			        $output .= '<pubDate>' . date("r", strtotime($page['time'])) . "</pubDate>\n";
186
			        $output .= "<description> Modification de " . $page["tag"] . " --- par " .$page["user"] /* . " le " . $day ." - ". $hh .":". $mm */ . "</description>\n";
187
			        $link=ereg_replace('&','&amp;',$this->Href("",$page["tag"]));
188
			        $output .= "<link>" . $link . "&amp;time=" . rawurlencode($page["time"]) . "</link>\n";
189
			        $output .= "</item>\n";
190
			    }
191
			    $output .= "</channel>\n";
192
			    $output .= "</rss>\n";
193
			    echo $output ;
194
 
195
			}
196
			exit;
197
			return;
198
		}
199
 
545 ddelon 200
		if ($method=="edit") {
920 ddelon 201
 
202
			if ($this->HasAccess("write") && $this->HasAccess("read")) {
203
 
204
				$result='';
205
 
206
				if ($_POST) {
207
					if ($_POST["submit"] == "Sauver")	{
208
					// check for overwriting
209
						if ($this->page) {
210
							if ($this->page["id"] != $_POST["previous"]) {
211
								$error = "ALERTE : ".
212
								"Cette page a &eacute;t&eacute; modifi&eacute;e par quelqu'un d'autre pendant que vous l'&eacute;ditiez.<br />\n".
213
								"Veuillez copier vos changements et r&eacute;&eacute;diter cette page.\n";
214
							}
545 ddelon 215
						}
920 ddelon 216
						// store
217
						if (!$error) {
218
							$body = str_replace("\r", "", $_POST["body"]);
219
							// test si la nouvelle page est differente de la précédente
220
							if(rtrim($body)==rtrim($this->page["body"])) {
221
								$this->SetMessage("Cette page n\'a pas &eacute;t&eacute; enregistr&eacute;e car elle n\'a subi aucune modification.");
222
								$this->Redirect($this->href());
223
							}
224
 
225
							// add page (revisions)
226
							$this->SavePage($this->tag, $body);
227
 
228
							// now we render it internally so we can write the updated link table.
229
							$this->ClearLinkTable();
230
							$this->StartLinkTracking();
231
							$dummy = $this->Header();
232
							$dummy .= $this->Format($body);
233
							$dummy .= $this->Footer();
234
							$this->StopLinkTracking();
235
							$this->WriteLinkTable();
236
							$this->ClearLinkTable();
237
 
238
							// forward
545 ddelon 239
							$this->Redirect($this->href());
240
						}
241
					}
242
				}
920 ddelon 243
 
244
				// fetch fields
245
				if (!$previous = $_POST["previous"]) $previous = $this->page["id"];
246
				if (!$body = $_POST["body"]) $body = $this->page["body"];
247
 
248
				// preview?
249
				if ($_POST["submit"] == "Aperçu")
250
				{
251
					$result .=
252
						"<div class=\"prev_alert\"><strong>Aper&ccedil;u</strong></div>\n".
253
						$this->Format($body)."\n\n".
254
						$this->FormOpen("edit").
255
						"<input type=\"hidden\" name=\"previous\" value=\"".$previous."\" />\n".
256
						"<input type=\"hidden\" name=\"body\" value=\"".htmlentities($body)."\" />\n".
257
						"<br />\n".
258
						"<input name=\"submit\" type=\"submit\" value=\"Sauver\" accesskey=\"s\" />\n".
259
						"<input name=\"submit\" type=\"submit\" value=\"R&eacute;&eacute;diter \" accesskey=\"p\" />\n".
260
						"<input type=\"button\" value=\"Annulation\" onclick=\"document.location='".$this->href("")."';\" />\n".
261
						$this->FormClose()."\n";
262
					return $result;
263
				}
264
				else
265
				{
266
					$ACbuttonsBar='';
267
				    require_once(IW_CHEMIN_BIBLIO_ACEDITOR."ACeditor.buttonsBar.php");
268
 
269
					$result .=
545 ddelon 270
					$this->FormOpen("edit").
920 ddelon 271
					"<input type=\"hidden\" name=\"previous\" value=\"".$previous."\" />\n".$ACbuttonsBar.
272
					"<textarea onkeydown=\"fKeyDown()\" name=\"body\" cols=\"60\" rows=\"40\" wrap=\"soft\" class=\"edit\">\n".
273
					htmlspecialchars($body).
274
					"\n</textarea><br />\n".'<div class="boutons_wiki">'.
275
					($this->config["preview_before_save"] ? "" : "<input name=\"submit\" type=\"submit\" value=\"Sauver\" accesskey=\"s\" />\n").
276
					"<input name=\"submit\" type=\"submit\" value=\"Aper&ccedil;u\" accesskey=\"p\" />\n".
277
					"<input type=\"button\" value=\"Annulation\" onclick=\"document.location='".$this->href("")."';\" /></div>\n".
278
					$this->FormClose();
279
 
280
					return $result;
281
				}
282
 
545 ddelon 283
			}
920 ddelon 284
			else {
285
				echo "<i>Vous n'avez pas acc&egrave;s en &eacute;criture &agrave; cette page !</i>\n";
286
 
545 ddelon 287
			}
288
		}
289
		else {
290
			return parent::Method($method);
291
		}
292
	}
581 ddelon 293
 
294
 
295
	// Surcharge Format a cause probleme de chemin.
296
 
545 ddelon 297
	function Format($text, $formatter = "wakka") {
581 ddelon 298
		return $this->IncludeBuffered(IW_CHEMIN_WIKINI_COURANT_FORMATTER.$formatter.".php", "<i>Impossible de trouver le formateur \"$formatter\"</i>", compact("text"));
545 ddelon 299
	}
581 ddelon 300
 
301
 
302
	// Identification
303
 
584 ddelon 304
	function SetUser($user, $remember) {
305
			// Appel à partir de Papyrus
920 ddelon 306
				if ($user=='initwiki') {
584 ddelon 307
					$remember=1;
596 ddelon 308
					$wiki_prenom=$this->versChatMot($GLOBALS['_GEN_commun']['pear_auth']->getAuthData($GLOBALS['_GEN_commun']['info_auth_bdd']->chp_personne_prenom));
309
					$wiki_nom=$this->versChatMot($GLOBALS['_GEN_commun']['pear_auth']->getAuthData($GLOBALS['_GEN_commun']['info_auth_bdd']->chp_personne_nom));
920 ddelon 310
					$_SESSION["user"]=array("name"=>$wiki_prenom.$wiki_nom,"password"=>"wikini","changescount"=> 100);
584 ddelon 311
					$this->SetPersistentCookie("name", $user["name"], $remember);
312
					$this->SetPersistentCookie("password", $user["password"], $remember);
313
					$this->SetPersistentCookie("remember", $remember, $remember);
314
				}
315
				else {
316
					parent::Setuser($user,$remember);
317
				}
318
 
580 ddelon 319
	}
581 ddelon 320
 
677 ddelon 321
	function LoadUser($name, $password = 0) {
322
		 return true;
323
	}
324
 
596 ddelon 325
	function LogoutUser() {
326
		$_SESSION["user"]="";
327
		$this->DeleteCookie("remember");
328
		parent::LogoutUser();
329
	}
677 ddelon 330
 
331
 
581 ddelon 332
 
596 ddelon 333
	function versChatMot($entree) {
334
		$sortie = strtolower(trim(strtr($entree, "àâéêèëîïôöùûüç-", "aaeeeeiioouuuc ")));
335
		$sortie = ucwords($sortie);
336
		$sortie = str_replace(" ", "",$sortie);
337
		return $sortie;
338
	}
339
 
545 ddelon 340
}
341
 
581 ddelon 342
 
343
 
545 ddelon 344
// Appel du fichier de traduction des textes de l'application Integrateur Wikini
345
if (file_exists(IW_CHEMIN_LANGUES.'iw_langue_'.IW_I18N.'.inc.php')) {
346
    /** Inclusion du fichier de traduction de l'application Integrateur Wikini. */
347
    include_once IW_CHEMIN_LANGUES.'iw_langue_'.IW_I18N.'.inc.php';
348
} else {
349
    /** Inclusion du fichier de traduction fr par défaut. */
350
    include_once IW_CHEMIN_LANGUES.'iw_langue_fr.inc.php';
351
}
352
 
353
$GLOBALS['_PAPYRUS_']['erreur']->setActive(1);
354
/**
581 ddelon 355
 *
545 ddelon 356
 * Fonction afficherPageMenuWikini()
581 ddelon 357
 *
545 ddelon 358
 * Renvoie le contenu de la page Menu de Wikini
359
 *
360
 * @return string
361
 * @access public
362
 */
581 ddelon 363
 
545 ddelon 364
function afficherPageMenuWikini()
365
{
581 ddelon 366
 
545 ddelon 367
	$GLOBALS['_PAPYRUS_']['erreur']->setActive(0);
368
 
369
	global $wiki;
370
	global $wikini_config_defaut;
371
	$sortie='';
372
    $wakkaConfig = $GLOBALS['wikini_config_defaut'];
898 alexandre_ 373
    if (!class_exists('Wiki_Papyrus')) return ;
545 ddelon 374
    $wiki  = new Wiki_Papyrus($wakkaConfig);
375
 
376
    // Suppression des slash.
377
    $_REQUEST['wiki'] = preg_replace("/^\//", '',  $_REQUEST['wiki']);
378
 
379
    // split into page/method
832 florian 380
    $matches='';
545 ddelon 381
    if ( preg_match( "#^(.+?)/(.*)$#",  $_REQUEST['wiki'], $matches ) ) {
382
        list(, $page, $method) = $matches;
383
    } else if ( preg_match( "#^(.*)$#",  $_REQUEST['wiki'], $matches ) ) {
384
        list(, $page) = $matches;
385
    }
386
 
387
    $server=$_SERVER['PHP_SELF'];
388
	$_SERVER['PHP_SELF']="wakka.php";
581 ddelon 389
 
545 ddelon 390
    $contenu=$wiki->LoadPage("PageMenu");
581 ddelon 391
 
585 ddelon 392
    $sortie.="<div id=\"menu_wikini\">";
581 ddelon 393
	$sortie.=$wiki->Format($contenu['body']);
585 ddelon 394
	$sortie.="</div>";
545 ddelon 395
 
396
	$_SERVER['PHP_SELF']=$server;
581 ddelon 397
 
545 ddelon 398
	$GLOBALS['_PAPYRUS_']['erreur']->setActive(1);
581 ddelon 399
 
545 ddelon 400
	return $sortie;
581 ddelon 401
 
402
}
403
 
404
 
545 ddelon 405
// +------------------------------------------------------------------------------------------------------+
406
// |                                            CORPS du PROGRAMME                                        |
407
// +------------------------------------------------------------------------------------------------------+
408
/** Fonction afficherPageWikini() - Fonction appelé par le gestionnaire Papyrus.
409
*
410
* Elle retourne le contenu de l'application.
411
*
412
* @return  string  du code XHTML correspondant au contenu renvoyé par l'application.
413
*/
414
function afficherPageWikini()
415
{
920 ddelon 416
 
545 ddelon 417
 
418
	$GLOBALS['_PAPYRUS_']['erreur']->setActive(0);
581 ddelon 419
 
545 ddelon 420
	// Ajout d'une feuille de style externe
421
	GEN_stockerStyleExterne ('wikini', 'client/integrateur_wikini/presentations/styles/wikini.css') ;
581 ddelon 422
 
545 ddelon 423
	global $wiki;
424
	global $wikini_config_defaut;
425
	$sortie='';
426
    $wakkaConfig = $GLOBALS['wikini_config_defaut'];
898 alexandre_ 427
    if (!class_exists ('Wiki_Papyrus')) return ;
545 ddelon 428
    $wiki  = new Wiki_Papyrus($wakkaConfig);
429
 
581 ddelon 430
	if  ($GLOBALS['_GEN_commun']['pear_auth']->checkAuth()) {
431
		if (!isset($_SESSION["user"]) || ($_SESSION["user"]=="")) {
920 ddelon 432
			$wiki->SetUser('initwiki');
580 ddelon 433
		}
434
	}
435
	else {
436
		$wiki->LogoutUser();
437
	}
581 ddelon 438
 
545 ddelon 439
	// Gestion de la variable de session "linktracking"
440
    if ( ! isset( $_SESSION['linktracking'] ) ) {
441
        $_SESSION['linktracking'] = 1;
442
    }
443
 
444
    // Suppression des slash.
445
    $_REQUEST['wiki'] = preg_replace("/^\//", '',  $_REQUEST['wiki']);
446
 
447
    // split into page/method
832 florian 448
    $matches='';
545 ddelon 449
    if ( preg_match( "#^(.+?)/(.*)$#",  $_REQUEST['wiki'], $matches ) ) {
450
        list(, $page, $method) = $matches;
451
    } else if ( preg_match( "#^(.*)$#",  $_REQUEST['wiki'], $matches ) ) {
452
        list(, $page) = $matches;
453
    }
581 ddelon 454
 
545 ddelon 455
    // Vérification de la méthode d'affichage employée!
456
    if ( ! isset( $method ) ) {
457
        $method = '';
458
    }
581 ddelon 459
 
545 ddelon 460
    //Récupération du contenu de la page Wikini
581 ddelon 461
 
545 ddelon 462
    ob_start();
581 ddelon 463
 
545 ddelon 464
    $server=$_SERVER['PHP_SELF'];
465
	$_SERVER['PHP_SELF']="wakka.php";
581 ddelon 466
 
545 ddelon 467
	$wiki->Run($page, $method);
581 ddelon 468
 
545 ddelon 469
    $_SERVER['PHP_SELF']=$server;
581 ddelon 470
 
545 ddelon 471
    $sortie.= ob_get_contents();
472
    ob_end_clean();
473
 
474
	$GLOBALS['_PAPYRUS_']['erreur']->setActive(1);
475
 
676 ddelon 476
	if ($method!="edit") {
477
		return remplacerEntiteHTLM("<script type=\"text/javascript\" src=\"".IW_CHEMIN_BIBLIO_ACEDITOR."ACeditor.js\"></script><div id=\"wikini_page\"  ondblclick=\"document.location='".$wiki->href("edit")."';"."\">"."\n".$sortie.'</div>'."\n");
478
	}
479
	else {
480
		return remplacerEntiteHTLM("<script type=\"text/javascript\" src=\"".IW_CHEMIN_BIBLIO_ACEDITOR."ACeditor.js\"></script><div id=\"wikini_page\">"."\n".$sortie.'</div>'."\n");
481
	}
690 ddelon 482
 
483
 
545 ddelon 484
}
485
 
486
?>