ba279a90a375891112069ca39aeacaf8b79f43ab
[diogenes.git] / compose.php
1 <?php
2 require_once 'diogenes.common.inc.php';
3 require_once 'diogenes.admin.inc.php';
4 require_once 'diogenes.text.inc.php';
5 require_once 'Barrel/Page.php';
6 require_once 'Barrel/File.php';
7
8 if (!isset($_REQUEST['dir']) && !isset($_REQUEST['file']))
9 exit;
10
11 // retrieve directory & file info
12 $dir = $_REQUEST["dir"];
13 $file = $_REQUEST["file"];
14 $page = new DiogenesAdmin($dir);
15
16 $bbarrel = $page->barrel;
17 $bpage = Diogenes_Barrel_Page::fromDb($bbarrel, $dir);
18 $bfile = new Diogenes_Barrel_File($bpage, $file);
19
20 // rcs handle
21 $rcs = $page->getRcs();
22
23 // file location & url
24 $mydir = $bbarrel->spool->spoolPath($dir);
25 $myfile = $bbarrel->spool->spoolPath($dir,$file);
26
27 // process requested action
28 $action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : "";
29 switch ($action)
30 {
31 case "update":
32 // update the current file with form contents
33 if (isset($_REQUEST['file_content'])) {
34 $page->info(__("Commiting changes to file") . " $file");
35 $content = trim(stripslashes($_REQUEST['file_content']));
36 $content = str_replace("\n ","\n",$content);
37 $content = phpUnprotect(htmltoXhtml($content));
38 $message = empty($_REQUEST['message']) ? "updated using HTML composer" : stripslashes($_REQUEST['message']);
39 $rcs->commit($dir,$file,$content,$message);
40 }
41
42 break;
43 }
44
45 $rev = array_shift($tmparr = $rcs->logParse($dir,$file));
46
47 // protect PHP code and XHTML tags
48 $rawdoc = file_get_contents($myfile);
49 $protdoc = xhtmlToHtml(phpProtect($rawdoc));
50
51 // smarty assignments
52 $page->assign('post',$page->script_self());
53 $page->assign('dir',$dir);
54 $page->assign('dirloc',$page->urlBarrel($bbarrel->alias,$bbarrel->vhost,$bpage->getLocation()));
55
56 $page->assign('file',$file);
57 $page->assign('file_content',chunk_split(base64_encode($protdoc)));
58 $page->assign('msg_log',__("log message"));
59
60 // build toolbars
61 $page->toolbar(__("Page"), $bpage->make_toolbar($page));
62 $page->toolbar(__("File"), $bfile->make_toolbar(true));
63
64 $auxpage = new DiogenesBarrel("/".$bbarrel->alias."/". $bpage->getLocation());
65
66 switch ($globals->html_editor) {
67 case "ekit":
68 $page->assign('greeting', "Ekit - ". $bpage->getLocation($file)." - {$rev['rev']}");
69 $page->assign('cssfiles', array_pop($auxpage->sheets));
70 $page->display('admin-ekit.tpl');
71 break;
72 case "kafenio": default:
73 $page->assign('greeting', "Kafenio - ". $bpage->getLocation($file)." - {$rev['rev']}");
74 $page->assign('cssfiles', implode(",", $auxpage->sheets));
75 $page->display('admin-kafenio.tpl');
76 break;
77 }
78 ?>