Subversion Repositories Applications.papyrus

Rev

Rev 860 | 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
// +------------------------------------------------------------------------------------------------------+
898 alexandre_ 24
// CVS : $Id: iw_integrateur.fonct.php,v 1.17 2006-07-04 09:40:49 alexandre_tb 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
898 alexandre_ 36
*@version       $Revision: 1.17 $ $Date: 2006-07-04 09:40:49 $
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") {
581 ddelon 201
 
545 ddelon 202
			$result='';
581 ddelon 203
 
545 ddelon 204
			if ($_POST) {
205
				if ($_POST["submit"] == "Sauver")	{
206
				// check for overwriting
207
					if ($this->page) {
208
						if ($this->page["id"] != $_POST["previous"]) {
209
							$error = "ALERTE : ".
210
							"Cette page a &eacute;t&eacute; modifi&eacute;e par quelqu'un d'autre pendant que vous l'&eacute;ditiez.<br />\n".
211
							"Veuillez copier vos changements et r&eacute;&eacute;diter cette page.\n";
212
						}
213
					}
214
					// store
215
					if (!$error) {
216
						$body = str_replace("\r", "", $_POST["body"]);
217
						// test si la nouvelle page est differente de la précédente
218
						if(rtrim($body)==rtrim($this->page["body"])) {
219
							$this->SetMessage("Cette page n\'a pas &eacute;t&eacute; enregistr&eacute;e car elle n\'a subi aucune modification.");
220
							$this->Redirect($this->href());
221
						}
581 ddelon 222
 
545 ddelon 223
						// add page (revisions)
224
						$this->SavePage($this->tag, $body);
581 ddelon 225
 
545 ddelon 226
						// now we render it internally so we can write the updated link table.
227
						$this->ClearLinkTable();
228
						$this->StartLinkTracking();
229
						$dummy = $this->Header();
230
						$dummy .= $this->Format($body);
231
						$dummy .= $this->Footer();
232
						$this->StopLinkTracking();
233
						$this->WriteLinkTable();
234
						$this->ClearLinkTable();
581 ddelon 235
 
545 ddelon 236
						// forward
237
						$this->Redirect($this->href());
238
					}
239
				}
240
			}
241
 
242
			// fetch fields
243
			if (!$previous = $_POST["previous"]) $previous = $this->page["id"];
244
			if (!$body = $_POST["body"]) $body = $this->page["body"];
581 ddelon 245
 
545 ddelon 246
			// preview?
247
			if ($_POST["submit"] == "Aperçu")
248
			{
249
				$result .=
250
					"<div class=\"prev_alert\"><strong>Aper&ccedil;u</strong></div>\n".
251
					$this->Format($body)."\n\n".
252
					$this->FormOpen("edit").
253
					"<input type=\"hidden\" name=\"previous\" value=\"".$previous."\" />\n".
254
					"<input type=\"hidden\" name=\"body\" value=\"".htmlentities($body)."\" />\n".
255
					"<br />\n".
256
					"<input name=\"submit\" type=\"submit\" value=\"Sauver\" accesskey=\"s\" />\n".
257
					"<input name=\"submit\" type=\"submit\" value=\"R&eacute;&eacute;diter \" accesskey=\"p\" />\n".
258
					"<input type=\"button\" value=\"Annulation\" onclick=\"document.location='".$this->href("")."';\" />\n".
259
					$this->FormClose()."\n";
260
				return $result;
261
			}
262
			else
263
			{
832 florian 264
				$ACbuttonsBar='';
545 ddelon 265
			    require_once(IW_CHEMIN_BIBLIO_ACEDITOR."ACeditor.buttonsBar.php");
581 ddelon 266
 
545 ddelon 267
				$result .=
268
				$this->FormOpen("edit").
269
				"<input type=\"hidden\" name=\"previous\" value=\"".$previous."\" />\n".$ACbuttonsBar.
270
				"<textarea onkeydown=\"fKeyDown()\" name=\"body\" cols=\"60\" rows=\"40\" wrap=\"soft\" class=\"edit\">\n".
271
				htmlspecialchars($body).
658 florian 272
				"\n</textarea><br />\n".'<div class="boutons_wiki">'.
545 ddelon 273
				($this->config["preview_before_save"] ? "" : "<input name=\"submit\" type=\"submit\" value=\"Sauver\" accesskey=\"s\" />\n").
274
				"<input name=\"submit\" type=\"submit\" value=\"Aper&ccedil;u\" accesskey=\"p\" />\n".
658 florian 275
				"<input type=\"button\" value=\"Annulation\" onclick=\"document.location='".$this->href("")."';\" /></div>\n".
545 ddelon 276
				$this->FormClose();
581 ddelon 277
 
545 ddelon 278
				return $result;
279
			}
581 ddelon 280
 
545 ddelon 281
		}
282
		else {
283
			return parent::Method($method);
284
		}
285
	}
581 ddelon 286
 
287
 
288
	// Surcharge Format a cause probleme de chemin.
289
 
545 ddelon 290
	function Format($text, $formatter = "wakka") {
581 ddelon 291
		return $this->IncludeBuffered(IW_CHEMIN_WIKINI_COURANT_FORMATTER.$formatter.".php", "<i>Impossible de trouver le formateur \"$formatter\"</i>", compact("text"));
545 ddelon 292
	}
581 ddelon 293
 
294
 
295
	// Identification
296
 
584 ddelon 297
	function SetUser($user, $remember) {
298
			// Appel à partir de Papyrus
299
				if ($user=='') {
300
					$remember=1;
596 ddelon 301
					$wiki_prenom=$this->versChatMot($GLOBALS['_GEN_commun']['pear_auth']->getAuthData($GLOBALS['_GEN_commun']['info_auth_bdd']->chp_personne_prenom));
302
					$wiki_nom=$this->versChatMot($GLOBALS['_GEN_commun']['pear_auth']->getAuthData($GLOBALS['_GEN_commun']['info_auth_bdd']->chp_personne_nom));
303
 
586 ddelon 304
					$_SESSION["user"]["name"] = $wiki_prenom.$wiki_nom;
584 ddelon 305
					$_SESSION["user"]["password"] = "wikini";
306
					$_SESSION["user"]["changescount"] = 100;
307
					$this->SetPersistentCookie("name", $user["name"], $remember);
308
					$this->SetPersistentCookie("password", $user["password"], $remember);
309
					$this->SetPersistentCookie("remember", $remember, $remember);
310
				}
311
				else {
312
					parent::Setuser($user,$remember);
313
				}
314
 
580 ddelon 315
	}
581 ddelon 316
 
677 ddelon 317
	function LoadUser($name, $password = 0) {
318
		 return true;
319
	}
320
 
596 ddelon 321
	function LogoutUser() {
322
		$_SESSION["user"]="";
323
		$this->DeleteCookie("remember");
324
		parent::LogoutUser();
325
	}
677 ddelon 326
 
327
 
581 ddelon 328
 
596 ddelon 329
	function versChatMot($entree) {
330
		$sortie = strtolower(trim(strtr($entree, "àâéêèëîïôöùûüç-", "aaeeeeiioouuuc ")));
331
		$sortie = ucwords($sortie);
332
		$sortie = str_replace(" ", "",$sortie);
333
		return $sortie;
334
	}
335
 
545 ddelon 336
}
337
 
581 ddelon 338
 
339
 
545 ddelon 340
// Appel du fichier de traduction des textes de l'application Integrateur Wikini
341
if (file_exists(IW_CHEMIN_LANGUES.'iw_langue_'.IW_I18N.'.inc.php')) {
342
    /** Inclusion du fichier de traduction de l'application Integrateur Wikini. */
343
    include_once IW_CHEMIN_LANGUES.'iw_langue_'.IW_I18N.'.inc.php';
344
} else {
345
    /** Inclusion du fichier de traduction fr par défaut. */
346
    include_once IW_CHEMIN_LANGUES.'iw_langue_fr.inc.php';
347
}
348
 
349
$GLOBALS['_PAPYRUS_']['erreur']->setActive(1);
350
/**
581 ddelon 351
 *
545 ddelon 352
 * Fonction afficherPageMenuWikini()
581 ddelon 353
 *
545 ddelon 354
 * Renvoie le contenu de la page Menu de Wikini
355
 *
356
 * @return string
357
 * @access public
358
 */
581 ddelon 359
 
545 ddelon 360
function afficherPageMenuWikini()
361
{
581 ddelon 362
 
545 ddelon 363
	$GLOBALS['_PAPYRUS_']['erreur']->setActive(0);
364
 
365
	global $wiki;
366
	global $wikini_config_defaut;
367
	$sortie='';
368
    $wakkaConfig = $GLOBALS['wikini_config_defaut'];
898 alexandre_ 369
    if (!class_exists('Wiki_Papyrus')) return ;
545 ddelon 370
    $wiki  = new Wiki_Papyrus($wakkaConfig);
371
 
372
    // Suppression des slash.
373
    $_REQUEST['wiki'] = preg_replace("/^\//", '',  $_REQUEST['wiki']);
374
 
375
    // split into page/method
832 florian 376
    $matches='';
545 ddelon 377
    if ( preg_match( "#^(.+?)/(.*)$#",  $_REQUEST['wiki'], $matches ) ) {
378
        list(, $page, $method) = $matches;
379
    } else if ( preg_match( "#^(.*)$#",  $_REQUEST['wiki'], $matches ) ) {
380
        list(, $page) = $matches;
381
    }
382
 
383
    $server=$_SERVER['PHP_SELF'];
384
	$_SERVER['PHP_SELF']="wakka.php";
581 ddelon 385
 
545 ddelon 386
    $contenu=$wiki->LoadPage("PageMenu");
581 ddelon 387
 
585 ddelon 388
    $sortie.="<div id=\"menu_wikini\">";
581 ddelon 389
	$sortie.=$wiki->Format($contenu['body']);
585 ddelon 390
	$sortie.="</div>";
545 ddelon 391
 
392
	$_SERVER['PHP_SELF']=$server;
581 ddelon 393
 
545 ddelon 394
	$GLOBALS['_PAPYRUS_']['erreur']->setActive(1);
581 ddelon 395
 
545 ddelon 396
	return $sortie;
581 ddelon 397
 
398
}
399
 
400
 
545 ddelon 401
// +------------------------------------------------------------------------------------------------------+
402
// |                                            CORPS du PROGRAMME                                        |
403
// +------------------------------------------------------------------------------------------------------+
404
/** Fonction afficherPageWikini() - Fonction appelé par le gestionnaire Papyrus.
405
*
406
* Elle retourne le contenu de l'application.
407
*
408
* @return  string  du code XHTML correspondant au contenu renvoyé par l'application.
409
*/
410
function afficherPageWikini()
411
{
412
 
413
	$GLOBALS['_PAPYRUS_']['erreur']->setActive(0);
581 ddelon 414
 
545 ddelon 415
	// Ajout d'une feuille de style externe
416
	GEN_stockerStyleExterne ('wikini', 'client/integrateur_wikini/presentations/styles/wikini.css') ;
581 ddelon 417
 
545 ddelon 418
	global $wiki;
419
	global $wikini_config_defaut;
420
	$sortie='';
421
    $wakkaConfig = $GLOBALS['wikini_config_defaut'];
898 alexandre_ 422
    if (!class_exists ('Wiki_Papyrus')) return ;
545 ddelon 423
    $wiki  = new Wiki_Papyrus($wakkaConfig);
424
 
581 ddelon 425
	if  ($GLOBALS['_GEN_commun']['pear_auth']->checkAuth()) {
426
		if (!isset($_SESSION["user"]) || ($_SESSION["user"]=="")) {
580 ddelon 427
			$wiki->SetUser('');
428
		}
429
	}
430
	else {
431
		$wiki->LogoutUser();
432
	}
581 ddelon 433
 
545 ddelon 434
	// Gestion de la variable de session "linktracking"
435
    if ( ! isset( $_SESSION['linktracking'] ) ) {
436
        $_SESSION['linktracking'] = 1;
437
    }
438
 
439
    // Suppression des slash.
440
    $_REQUEST['wiki'] = preg_replace("/^\//", '',  $_REQUEST['wiki']);
441
 
442
    // split into page/method
832 florian 443
    $matches='';
545 ddelon 444
    if ( preg_match( "#^(.+?)/(.*)$#",  $_REQUEST['wiki'], $matches ) ) {
445
        list(, $page, $method) = $matches;
446
    } else if ( preg_match( "#^(.*)$#",  $_REQUEST['wiki'], $matches ) ) {
447
        list(, $page) = $matches;
448
    }
581 ddelon 449
 
545 ddelon 450
    // Vérification de la méthode d'affichage employée!
451
    if ( ! isset( $method ) ) {
452
        $method = '';
453
    }
581 ddelon 454
 
545 ddelon 455
    //Récupération du contenu de la page Wikini
581 ddelon 456
 
545 ddelon 457
    ob_start();
581 ddelon 458
 
545 ddelon 459
    $server=$_SERVER['PHP_SELF'];
460
	$_SERVER['PHP_SELF']="wakka.php";
581 ddelon 461
 
545 ddelon 462
	$wiki->Run($page, $method);
581 ddelon 463
 
545 ddelon 464
    $_SERVER['PHP_SELF']=$server;
581 ddelon 465
 
545 ddelon 466
    $sortie.= ob_get_contents();
467
    ob_end_clean();
468
 
469
	$GLOBALS['_PAPYRUS_']['erreur']->setActive(1);
470
 
676 ddelon 471
	if ($method!="edit") {
472
		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");
473
	}
474
	else {
475
		return remplacerEntiteHTLM("<script type=\"text/javascript\" src=\"".IW_CHEMIN_BIBLIO_ACEDITOR."ACeditor.js\"></script><div id=\"wikini_page\">"."\n".$sortie.'</div>'."\n");
476
	}
690 ddelon 477
 
478
 
545 ddelon 479
}
480
 
481
?>