author | Dan |
Sat, 19 Dec 2009 16:06:27 -0500 | |
changeset 1190 | fa306d7af9ce |
parent 1081 | 745200a9cc2a |
child 1227 | bdac73ed481e |
permissions | -rw-r--r-- |
346 | 1 |
<?php |
2 |
||
3 |
/* |
|
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
1081
745200a9cc2a
Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
parents:
1013
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Dan Fuhry |
346 | 6 |
* |
7 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
11 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
12 |
*/ |
|
13 |
||
14 |
// Page editing portal |
|
15 |
||
16 |
function page_Admin_PageEditor() |
|
17 |
{ |
|
18 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
19 |
global $lang; |
|
20 |
if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) |
|
21 |
{ |
|
22 |
$login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true); |
|
23 |
echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>'; |
|
24 |
echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>'; |
|
25 |
return; |
|
26 |
} |
|
27 |
||
28 |
echo '<h3>' . $lang->get('acped_heading_main') . '</h3>'; |
|
29 |
$show_select = true; |
|
30 |
||
31 |
if ( isset($_REQUEST['action']) || isset($_REQUEST['source']) ) |
|
32 |
{ |
|
33 |
if ( isset($_REQUEST['action']) ) |
|
34 |
{ |
|
35 |
$act =& $_REQUEST['action']; |
|
36 |
$act = strtolower($act); |
|
37 |
} |
|
38 |
else if ( isset($_REQUEST['source']) && $_REQUEST['source'] == 'ajax' ) |
|
39 |
{ |
|
40 |
$act = 'select'; |
|
41 |
} |
|
42 |
switch ( $act ) |
|
43 |
{ |
|
44 |
case 'save': |
|
45 |
case 'select': |
|
46 |
// First step is to determine the page ID and namespace |
|
47 |
||
48 |
if ( isset($_REQUEST['pid_search']) ) |
|
49 |
{ |
|
50 |
list($page_id, $namespace) = RenderMan::strToPageID($_REQUEST['page_id']); |
|
51 |
$name = $db->escape(dirtify_page_id($page_id)); |
|
52 |
$page_id = $db->escape(sanitize_page_id($page_id)); |
|
53 |
$namespace = $db->escape($namespace); |
|
54 |
$name = strtolower($name); |
|
55 |
$page_id = strtolower($page_id); |
|
56 |
$sql = "SELECT * FROM " . table_prefix . "pages WHERE ( " . ENANO_SQLFUNC_LOWERCASE . "(urlname) LIKE '%$page_id%' OR " . ENANO_SQLFUNC_LOWERCASE . "(name) LIKE '%$name%' ) ORDER BY name ASC;"; |
|
57 |
} |
|
58 |
else |
|
59 |
{ |
|
60 |
// pid_search was not set, assume absolute page ID |
|
61 |
list($page_id, $namespace) = RenderMan::strToPageID($_REQUEST['page_id']); |
|
62 |
$page_id = $db->escape(sanitize_page_id($page_id)); |
|
63 |
$namespace = $db->escape($namespace); |
|
64 |
||
65 |
$sql = "SELECT * FROM " . table_prefix . "pages WHERE urlname = '$page_id' AND namespace = '$namespace';"; |
|
66 |
} |
|
67 |
||
68 |
if ( !($q = $db->sql_query($sql)) ) |
|
69 |
{ |
|
70 |
$db->_die('PageManager selecting dataset for page'); |
|
71 |
} |
|
72 |
||
73 |
if ( $db->numrows() < 1 ) |
|
74 |
{ |
|
75 |
echo '<div class="error-box"> |
|
76 |
' . $lang->get('acped_err_page_not_found') . ' |
|
77 |
</div>'; |
|
78 |
break; |
|
79 |
} |
|
80 |
||
81 |
if ( $db->numrows() > 1 ) |
|
82 |
{ |
|
83 |
// Ambiguous results |
|
84 |
if ( isset($_REQUEST['pid_search']) ) |
|
85 |
{ |
|
86 |
echo '<h3>' . $lang->get('acped_msg_results_ambiguous_title') . '</h3>'; |
|
87 |
echo '<p>' . $lang->get('acped_msg_results_ambiguous_body') . '</p>'; |
|
88 |
echo '<ul>'; |
|
89 |
while ( $row = $db->fetchrow($q) ) |
|
90 |
{ |
|
91 |
echo '<li>'; |
|
92 |
$pathskey = $paths->nslist[$row['namespace']] . $row['urlname']; |
|
93 |
$edit_url = makeUrlNS($row['namespace'], $row['urlname']) . '#do:edit'; |
|
94 |
$view_url = makeUrlNS($row['namespace'], $row['urlname']); |
|
95 |
$page_name = htmlspecialchars(get_page_title_ns( $row['urlname'], $row['namespace'] )); |
|
96 |
$view_link = $lang->get('acped_ambig_btn_viewpage'); |
|
97 |
echo "<a href=\"$edit_url\">$page_name</a> (<a onclick=\"window.open(this.href); return false;\" href=\"$view_url\">$view_link</a>)"; |
|
98 |
echo '</li>'; |
|
99 |
} |
|
100 |
echo '</ul>'; |
|
101 |
$show_select = false; |
|
102 |
break; |
|
103 |
} |
|
104 |
else |
|
105 |
{ |
|
106 |
echo '<p>' . $lang->get('acped_err_ambig_absolute') . '</p>'; |
|
107 |
break; |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
// From this point on we can assume that exactly one matching page was found. |
|
112 |
$dataset = $db->fetchrow(); |
|
113 |
$page_id = $dataset['urlname']; |
|
114 |
$namespace = $dataset['namespace']; |
|
115 |
$url = makeUrlNS($namespace, $page_id, false, true) . '#do:edit'; |
|
116 |
$url = addslashes($url); |
|
117 |
echo '<script type="text/javascript"> |
|
118 |
window.location = \'' . $url . '\'; |
|
119 |
</script>'; |
|
120 |
||
121 |
$show_select = false; |
|
122 |
break; |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
if ( $show_select ) |
|
127 |
{ |
|
128 |
echo '<p>' . $lang->get('acped_hint') . '</p>'; |
|
129 |
||
130 |
// Show the search form |
|
131 |
||
132 |
$form_action = makeUrlNS('Special', 'Administration', "module={$paths->nslist['Admin']}PageEditor", true); |
|
133 |
echo "<form action=\"$form_action\" method=\"post\">"; |
|
134 |
echo $lang->get('acped_lbl_field_search') . ' '; |
|
135 |
echo $template->pagename_field('page_id') . ' '; |
|
136 |
echo '<input type="hidden" name="action" value="select" />'; |
|
137 |
echo '<input type="submit" name="pid_search" value="' . $lang->get('search_btn_search') . '" />'; |
|
138 |
echo "</form>"; |
|
139 |
||
140 |
// Grab all pages from the database and show a list of pages on the site |
|
141 |
||
142 |
echo '<h3>' . $lang->get('acped_heading_select_page_from_list') . '</h3>'; |
|
143 |
echo '<p>' . $lang->get('acped_hint_select_page_from_list') . '</p>'; |
|
144 |
||
145 |
$q = $db->sql_query('SELECT COUNT(name) AS num_pages FROM ' . table_prefix . 'pages;'); |
|
146 |
if ( !$q ) |
|
147 |
$db->_die('PageManager doing initial page count'); |
|
148 |
list($num_pages) = $db->fetchrow_num(); |
|
149 |
$db->free_result(); |
|
150 |
||
151 |
$pg_start = ( isset($_GET['offset']) ) ? intval($_GET['offset']) : 0; |
|
152 |
||
1013
8626bb38410f
Set a few queries to buffered due to intermediate queries during fetching
Dan
parents:
801
diff
changeset
|
153 |
$q = $db->sql_query('SELECT urlname, name, namespace, ' . $num_pages . ' AS num_pages, ' . $pg_start . ' AS offset, \'edit\' AS mode FROM ' . table_prefix . 'pages ORDER BY name ASC;'); |
346 | 154 |
if ( !$q ) |
155 |
$db->_die('PageManager doing main select query for page list'); |
|
156 |
||
157 |
// Paginate results |
|
158 |
$html = paginate( |
|
159 |
$q, |
|
160 |
'{urlname}', |
|
161 |
$num_pages, |
|
162 |
makeUrlNS('Special', 'Administration', "module={$paths->nslist['Admin']}PageEditor&offset=%s", false), |
|
163 |
$pg_start, |
|
164 |
99, |
|
165 |
array('urlname' => 'admin_pagemanager_format_listing'), |
|
166 |
'<div class="tblholder" style="height: 300px; clip: rect(0px, auto, auto, 0px); overflow: auto;"> |
|
167 |
<table border="0" cellspacing="1" cellpadding="4">', |
|
168 |
' </table> |
|
169 |
</div>' |
|
170 |
); |
|
171 |
echo $html; |
|
172 |
} |
|
173 |
||
174 |
} |
|
175 |
||
176 |
?> |