File: pages.php

package info (click to toggle)
diogenes 0.9.20-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,976 kB
  • ctags: 3,271
  • sloc: php: 12,285; sh: 828; perl: 258; makefile: 137; sql: 85
file content (186 lines) | stat: -rw-r--r-- 6,457 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
require_once 'diogenes.common.inc.php';
require_once 'diogenes.admin.inc.php';
require_once 'Barrel.php';
require_once 'Barrel/Page.php';

$page = new DiogenesAdmin;
$bbarrel =& $page->barrel;

// rcs handle
$rcs = $page->getRcs();

// translations
$page->assign('msg_submit',__("Submit"));
$page->assign('msg_reset',__("Reset"));
$page->assign('msg_properties',__("Page properties"));
$page->assign('msg_parent',__("parent page"));
$page->assign('msg_location',__("location"));
$page->assign('msg_title',__("title"));
$page->assign('msg_page_template',__("page template"));
$page->assign('msg_status',__("status"));
$page->assign('msg_access',__("access"));
$page->assign('msg_read_perms',__("read access"));
$page->assign('msg_write_perms',__("write access"));
$page->assign('msg_actions',__("actions"));
$page->assign('msg_add_page', array(__("Add a page"),"?action=edit") );

$page->assign('post', $page->script_self());
$page->assign('table', $bbarrel->table_page);
$page->assign('from', $_REQUEST['from']);
$action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : "";
$target = isset($_REQUEST["target"]) ? $_REQUEST["target"] : "";

if (isset($_REQUEST["dir"])) {
  $dir = $_REQUEST["dir"];
  if (!$action) $action="edit";
} else {
  $dir = 0;
}


/* add or update a page */
switch ($action) {
case "import":

  // if needed, import a file
  if ($globals->word_import && isset($_FILES['wordfile']) && is_uploaded_file($_FILES['wordfile']['tmp_name'])) {
    $userfile = strtolower($_FILES['wordfile']['name']);
    if (!substr($userfile,-4,4) == ".doc") {
      $page->info(__("Document name does not end in .doc"));
    } else {
      $mydir = $bbarrel->spool->spoolPath($dir);
      $page->info(__("Checking in Word file") . " $userfile");
      $rcs->commit($dir, $globals->wordfile,
                          file_get_contents($_FILES['wordfile']['tmp_name']),
                          "Word file update $userfile" );

      $page->info(__("Importing Word file") . " $userfile");
      $rcs->importWordFile($dir, $globals->htmlfile, $_FILES['wordfile']['tmp_name']);
    }
  } else if (isset($_FILES['htmlfile']) && is_uploaded_file($_FILES['htmlfile']['tmp_name'])) {
    $userfile = strtolower($_FILES['htmlfile']['name']);
    if ( (substr($userfile,-4,4) == ".htm") || (substr($userfile,-5,5) == ".html") ) {
      $page->info(__("Importing HTML file") . " $userfile");
      $rcs->commit( $dir, $globals->htmlfile,
                 $rcs->importHtmlString(file_get_contents($_FILES['htmlfile']['tmp_name'])),
                 "html file import of $userfile" );
    } else {
      $page->info(__("Raw file import") . " $userfile");
      $rcs->commit( $dir, $globals->htmlfile,
                 file_get_contents($_FILES['htmlfile']['tmp_name']),
                 "raw file import of $userfile" );
    }
  }
  break;

case "update":
    // page ID
    $props['PID'] = $dir;

    // page location
    if (isset($_REQUEST['pedit_location'])) {
      $homepage = 0;
      $props['location'] = $_REQUEST['pedit_' . 'location'];
    } else {
      $homepage = 1;
      $props['location'] = '';
    }
    
    // other properties
    $kprops = array('parent', 'title', 'perms', 'wperms', 'status', 'template');    
    foreach ($kprops as $key) {
      $props[$key] = $_REQUEST['pedit_' . $key];
    }    
    
    $bpage = new Diogenes_Barrel_Page($bbarrel, $props);
    if ($bpage->toDb($homepage, $page) && $_REQUEST['from'])
    {
      header("Location: {$_REQUEST['from']}");
      exit;
    }
    break;
}

// retrieve all the barrel's page
$bpages = $bbarrel->getPages();


if ($dir) 
{
  $bpage = Diogenes_Barrel_Page::fromDb($bbarrel, $dir);
} else {
  $tparent = empty($_REQUEST['parent']) ? $bbarrel->getPID('') : $_REQUEST['parent']; 
  //$page->info("parent $tparent");
  $bpage = new Diogenes_Barrel_Page($bbarrel, array('parent' => $tparent));
}
 
// "Page" toolbar  
//if (isset($bpage->props['PID'])) {
if ($dir != 0) {
  $page->toolbar(__("Page"), $bpage->make_toolbar($page));
  $page->toolbar(__("File"), $bpage->make_doc_toolbar($rcs));
}
  
// retrieve suitable parents for the current page
if (!$bpage->props['PID'] || strlen($bpage->props['location']))
{
  $parent_all = array();
  foreach($bpages as $pkey => $pval)
  {
    if (!$dir or (($pval->props['PID'] != $dir) and ($pval->props['parent'] != $dir)))
    {
      $parent_all[$pkey] = $pval;
    }
  }

  $parent_opts = array();        
  foreach (array_keys($parent_all) as $pkey)
  {
    $ppage = $parent_all[$pkey];
    if (!$ppage->props['parent']  or isset($parent_all[$ppage->props['parent']]))
    {
      $pageloc = $bbarrel->getLocation($pkey);
      $parent_opts[$pkey] = ( strlen($pageloc) ? "<$pageloc> " : "") . $ppage->props['title'];
    }
  }      
  $page->assign('parent_opts', $parent_opts);    
} 
 
// messages
$gtitle = "";
if ($dir) 
{
  $gtitle = $bbarrel->getLocation($dir);
  if (!$gtitle) $gtitle = __("home");
}
$page->assign('greeting',__("Page manager") . ($gtitle ? " - $gtitle" : "") );

$page->assign('html',__("Import HTML"));
$page->assign('htmlblab',__("You can replace the current page's contents by uploading an HTML file below."));
$page->assign('htmlstrip',__("If the file name ends with .htm or .html, anything outside the &lt;body&gt;&lt;/body&gt; pair will be stripped."));
$page->assign('send',__("Send"));

$page->assign('dir',$dir);
$page->assign('page_obj', $bpage->props);  
$page->assign('status_opts',array(0=>__("visible"), 1=>__("under construction"), 2=>__("disabled"), 3=>__("archived")));
$page->assign('templates',$page->getTemplates());
  
if ($globals->word_import) {

  $page->assign('word',__("Import a Word document"));

  if (file_exists($bbarrel->spool->spoolPath($dir,$globals->wordfile)) )
  {
    $page->assign('wordblab', __("This page's master document is currently a Word document."));
    $page->assign('wordsend', __("You can upload a new version of the Word document below."));
    $page->assign('wordfile', __("You can get the current version of the file here"));
    $page->assign('wordlnk', array($globals->wordfile,$page->urlSite((strlen($bpage->props['location']) ? $bpage->props['location'].'/' : '') . $globals->wordfile)) );
  } else {
    $page->assign('wordblab', __("If you wish, you can set this page's content from a Word document."));
    $page->assign('wordsend', __("To do so, simply upload the Word document below."));
  }
}

$page->display('page-properties.tpl');
?>