admin-pages.php 17.7 KB
Newer Older
Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	Description: Controller for admin page for editing custom pages and external links


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

Scott committed
22
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
23
	header('Location: ../../../');
Scott committed
24 25
	exit;
}
Scott committed
26

Scott committed
27 28 29
require_once QA_INCLUDE_DIR . 'app/admin.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
Scott committed
30 31


Scott committed
32
// Get current list of pages and determine the state of this admin page
Scott committed
33

Scott committed
34 35 36
$pageid = qa_post_text('edit');
if (!isset($pageid))
	$pageid = qa_get('edit');
Scott committed
37

Scott committed
38 39 40 41
list($pages, $editpage) = qa_db_select_with_pending(
	qa_db_pages_selectspec(),
	isset($pageid) ? qa_db_page_full_selectspec($pageid, true) : null
);
Scott committed
42

Scott committed
43 44 45
if ((qa_clicked('doaddpage') || qa_clicked('doaddlink') || qa_get('doaddlink') || qa_clicked('dosavepage')) && !isset($editpage)) {
	$editpage = array('title' => qa_get('text'), 'tags' => qa_get('url'), 'nav' => qa_get('nav'), 'position' => 1);
	$isexternal = qa_clicked('doaddlink') || qa_get('doaddlink') || qa_post_text('external');
Scott committed
46

Scott committed
47 48
} elseif (isset($editpage))
	$isexternal = $editpage['flags'] & QA_PAGE_FLAGS_EXTERNAL;
Scott committed
49 50


Scott committed
51
// Check admin privileges (do late to allow one DB query)
Scott committed
52

Scott committed
53 54
if (!qa_admin_check_privileges($qa_content))
	return $qa_content;
Scott committed
55 56


Scott committed
57
// Define an array of navigation settings we can change, option name => language key
Scott committed
58

Scott committed
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
$hascustomhome = qa_has_custom_home();

$navoptions = array(
	'nav_home' => 'main/nav_home',
	'nav_activity' => 'main/nav_activity',
	$hascustomhome ? 'nav_qa_not_home' : 'nav_qa_is_home' => $hascustomhome ? 'main/nav_qa' : 'admin/nav_qa_is_home',
	'nav_questions' => 'main/nav_qs',
	'nav_hot' => 'main/nav_hot',
	'nav_unanswered' => 'main/nav_unanswered',
	'nav_tags' => 'main/nav_tags',
	'nav_categories' => 'main/nav_categories',
	'nav_users' => 'main/nav_users',
	'nav_ask' => 'main/nav_ask',
);

$navpaths = array(
	'nav_home' => '',
	'nav_activity' => 'activity',
	'nav_qa_not_home' => 'qa',
	'nav_qa_is_home' => '',
	'nav_questions' => 'questions',
	'nav_hot' => 'hot',
	'nav_unanswered' => 'unanswered',
	'nav_tags' => 'tags',
	'nav_categories' => 'categories',
	'nav_users' => 'users',
	'nav_ask' => 'ask',
);

if (!qa_opt('show_custom_home'))
	unset($navoptions['nav_home']);

if (!qa_using_categories())
	unset($navoptions['nav_categories']);

if (!qa_using_tags())
	unset($navoptions['nav_tags']);
Scott committed
96 97


Scott committed
98
// Process saving an old or new page
Scott committed
99

Scott committed
100
$securityexpired = false;
Scott committed
101

Scott committed
102 103
if (qa_clicked('docancel'))
	$editpage = null;
Scott committed
104

Scott committed
105 106 107 108 109
elseif (qa_clicked('dosaveoptions') || qa_clicked('doaddpage') || qa_clicked('doaddlink')) {
	if (!qa_check_form_security_code('admin/pages', qa_post_text('code')))
		$securityexpired = true;
	else foreach ($navoptions as $optionname => $langkey)
		qa_set_option($optionname, (int)qa_post_text('option_' . $optionname));
Scott committed
110

Scott committed
111 112 113
} elseif (qa_clicked('dosavepage')) {
	require_once QA_INCLUDE_DIR . 'db/admin.php';
	require_once QA_INCLUDE_DIR . 'util/string.php';
Scott committed
114

Scott committed
115 116 117 118
	if (!qa_check_form_security_code('admin/pages', qa_post_text('code')))
		$securityexpired = true;
	else {
		$reloadpages = false;
Scott committed
119

Scott committed
120 121
		if (qa_post_text('dodelete')) {
			qa_db_page_delete($editpage['pageid']);
Scott committed
122

Scott committed
123 124 125
			$searchmodules = qa_load_modules_with('search', 'unindex_page');
			foreach ($searchmodules as $searchmodule)
				$searchmodule->unindex_page($editpage['pageid']);
Scott committed
126

Scott committed
127 128
			$editpage = null;
			$reloadpages = true;
Scott committed
129

Scott committed
130 131 132 133 134 135 136 137
		} else {
			$inname = qa_post_text('name');
			$inposition = qa_post_text('position');
			$inpermit = (int)qa_post_text('permit');
			$inurl = qa_post_text('url');
			$innewwindow = qa_post_text('newwindow');
			$inheading = qa_post_text('heading');
			$incontent = qa_post_text('content');
Scott committed
138

Scott committed
139
			$errors = array();
Scott committed
140

Scott committed
141
			// Verify the name (navigation link) is legitimate
Scott committed
142

Scott committed
143 144 145 146
			if (empty($inname))
				$errors['name'] = qa_lang('main/field_required');
			elseif (qa_strlen($inname) > QA_DB_MAX_CAT_PAGE_TITLE_LENGTH)
				$errors['name'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TITLE_LENGTH);
Scott committed
147

Scott committed
148
			if ($isexternal) {
Scott committed
149
				// Verify the url is legitimate (vaguely)
Scott committed
150

Scott committed
151 152 153 154
				if (empty($inurl))
					$errors['url'] = qa_lang('main/field_required');
				elseif (qa_strlen($inurl) > QA_DB_MAX_CAT_PAGE_TAGS_LENGTH)
					$errors['url'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH);
Scott committed
155

Scott committed
156
			} else {
Scott committed
157
				// Verify the heading is legitimate
Scott committed
158

Scott committed
159 160
				if (qa_strlen($inheading) > QA_DB_MAX_TITLE_LENGTH)
					$errors['heading'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_TITLE_LENGTH);
Scott committed
161

Scott committed
162
				// Verify the slug is legitimate (and try some defaults if we're creating a new page, and it's not)
Scott committed
163

Scott committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177
				for ($attempt = 0; $attempt < 100; $attempt++) {
					switch ($attempt) {
						case 0:
							$inslug = qa_post_text('slug');
							if (!isset($inslug))
								$inslug = implode('-', qa_string_to_words($inname));
							break;

						case 1:
							$inslug = qa_lang_sub('admin/page_default_slug', $inslug);
							break;

						default:
							$inslug = qa_lang_sub('admin/page_default_slug', $attempt - 1);
Scott committed
178 179
							break;
					}
Scott committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202

					list($matchcategoryid, $matchpage) = qa_db_select_with_pending(
						qa_db_slugs_to_category_id_selectspec($inslug),
						qa_db_page_full_selectspec($inslug, false)
					);

					if (empty($inslug))
						$errors['slug'] = qa_lang('main/field_required');
					elseif (qa_strlen($inslug) > QA_DB_MAX_CAT_PAGE_TAGS_LENGTH)
						$errors['slug'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH);
					elseif (preg_match('/[\\+\\/]/', $inslug))
						$errors['slug'] = qa_lang_sub('admin/slug_bad_chars', '+ /');
					elseif (qa_admin_is_slug_reserved($inslug))
						$errors['slug'] = qa_lang('admin/slug_reserved');
					elseif (isset($matchpage) && ($matchpage['pageid'] != @$editpage['pageid']))
						$errors['slug'] = qa_lang('admin/page_already_used');
					elseif (isset($matchcategoryid))
						$errors['slug'] = qa_lang('admin/category_already_used');
					else
						unset($errors['slug']);

					if (isset($editpage['pageid']) || !isset($errors['slug'])) // don't try other options if editing existing page
						break;
Scott committed
203
				}
Scott committed
204
			}
Scott committed
205

Scott committed
206
			// Perform appropriate database action
Scott committed
207

Scott committed
208 209 210 211 212 213 214
			if (isset($editpage['pageid'])) { // changing existing page
				if ($isexternal) {
					qa_db_page_set_fields($editpage['pageid'],
						isset($errors['name']) ? $editpage['title'] : $inname,
						QA_PAGE_FLAGS_EXTERNAL | ($innewwindow ? QA_PAGE_FLAGS_NEW_WINDOW : 0),
						isset($errors['url']) ? $editpage['tags'] : $inurl,
						null, null, $inpermit);
Scott committed
215

Scott committed
216 217 218 219
				} else {
					$setheading = isset($errors['heading']) ? $editpage['heading'] : $inheading;
					$setslug = isset($errors['slug']) ? $editpage['tags'] : $inslug;
					$setcontent = isset($errors['content']) ? $editpage['content'] : $incontent;
Scott committed
220

Scott committed
221 222 223 224
					qa_db_page_set_fields($editpage['pageid'],
						isset($errors['name']) ? $editpage['title'] : $inname,
						0,
						$setslug, $setheading, $setcontent, $inpermit);
Scott committed
225

Scott committed
226 227 228
					$searchmodules = qa_load_modules_with('search', 'unindex_page');
					foreach ($searchmodules as $searchmodule)
						$searchmodule->unindex_page($editpage['pageid']);
Scott committed
229

Scott committed
230
					$indextext = qa_viewer_text($setcontent, 'html');
Scott committed
231

Scott committed
232 233 234 235
					$searchmodules = qa_load_modules_with('search', 'index_page');
					foreach ($searchmodules as $searchmodule)
						$searchmodule->index_page($editpage['pageid'], $setslug, $setheading, $setcontent, 'html', $indextext);
				}
Scott committed
236

Scott committed
237
				qa_db_page_move($editpage['pageid'], substr($inposition, 0, 1), substr($inposition, 1));
Scott committed
238

Scott committed
239
				$reloadpages = true;
Scott committed
240

Scott committed
241 242 243 244
				if (empty($errors))
					$editpage = null;
				else
					$editpage = @$pages[$editpage['pageid']];
Scott committed
245

Scott committed
246 247 248 249 250 251
			} else { // creating a new one
				if (empty($errors)) {
					if ($isexternal) {
						$pageid = qa_db_page_create($inname, QA_PAGE_FLAGS_EXTERNAL | ($innewwindow ? QA_PAGE_FLAGS_NEW_WINDOW : 0), $inurl, null, null, $inpermit);
					} else {
						$pageid = qa_db_page_create($inname, 0, $inslug, $inheading, $incontent, $inpermit);
Scott committed
252

Scott committed
253 254 255 256 257
						$indextext = qa_viewer_text($incontent, 'html');

						$searchmodules = qa_load_modules_with('search', 'index_page');
						foreach ($searchmodules as $searchmodule)
							$searchmodule->index_page($pageid, $inslug, $inheading, $incontent, 'html', $indextext);
Scott committed
258 259
					}

Scott committed
260
					qa_db_page_move($pageid, substr($inposition, 0, 1), substr($inposition, 1));
Scott committed
261

Scott committed
262 263 264
					$editpage = null;
					$reloadpages = true;
				}
Scott committed
265
			}
Scott committed
266 267 268 269 270 271 272 273

			if (qa_clicked('dosaveview') && empty($errors) && !$isexternal)
				qa_redirect($inslug);
		}

		if ($reloadpages) {
			qa_db_flush_pending_result('navpages');
			$pages = qa_db_select_with_pending(qa_db_pages_selectspec());
Scott committed
274 275
		}
	}
Scott committed
276
}
Scott committed
277 278


Scott committed
279
// Prepare content for theme
Scott committed
280

Scott committed
281
$qa_content = qa_content_prepare();
Scott committed
282

Scott committed
283 284
$qa_content['title'] = qa_lang_html('admin/admin_title') . ' - ' . qa_lang_html('admin/pages_title');
$qa_content['error'] = $securityexpired ? qa_lang_html('admin/form_security_expired') : qa_admin_page_error();
Scott committed
285

Scott committed
286 287
if (isset($editpage)) {
	$positionoptions = array();
Scott committed
288

Scott committed
289 290
	if (!$isexternal)
		$positionoptions['_' . max(1, @$editpage['position'])] = qa_lang_html('admin/no_link');
Scott committed
291

Scott committed
292 293 294 295 296 297
	$navlangkey = array(
		'B' => 'admin/before_main_menu',
		'M' => 'admin/after_main_menu',
		'O' => 'admin/opposite_main_menu',
		'F' => 'admin/after_footer',
	);
Scott committed
298

Scott committed
299 300 301 302
	foreach ($navlangkey as $nav => $langkey) {
		$previous = null;
		$passedself = false;
		$maxposition = 0;
Scott committed
303

Scott committed
304 305 306 307 308 309
		foreach ($pages as $key => $page) {
			if ($page['nav'] == $nav) {
				if (isset($previous))
					$positionhtml = qa_lang_html_sub('admin/after_x_tab', qa_html($passedself ? $page['title'] : $previous['title']));
				else
					$positionhtml = qa_lang_html($langkey);
Scott committed
310

Scott committed
311 312
				if ($page['pageid'] == @$editpage['pageid'])
					$passedself = true;
Scott committed
313

Scott committed
314 315
				$maxposition = max($maxposition, $page['position']);
				$positionoptions[$nav . $page['position']] = $positionhtml;
Scott committed
316

Scott committed
317
				$previous = $page;
Scott committed
318 319 320
			}
		}

Scott committed
321
		if (!isset($editpage['pageid']) || $nav != @$editpage['nav']) {
Scott committed
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
			$positionvalue = isset($previous) ? qa_lang_html_sub('admin/after_x_tab', qa_html($previous['title'])) : qa_lang_html($langkey);
			$positionoptions[$nav . (isset($previous) ? (1 + $maxposition) : 1)] = $positionvalue;
		}
	}

	$positionvalue = @$positionoptions[$editpage['nav'] . $editpage['position']];

	$permitoptions = qa_admin_permit_options(QA_PERMIT_ALL, QA_PERMIT_ADMINS, false, false);
	$permitvalue = @$permitoptions[isset($inpermit) ? $inpermit : $editpage['permit']];

	$qa_content['form'] = array(
		'tags' => 'method="post" action="' . qa_path_html(qa_request()) . '"',

		'style' => 'tall',

		'fields' => array(
			'name' => array(
				'tags' => 'name="name" id="name"',
				'label' => qa_lang_html($isexternal ? 'admin/link_name' : 'admin/page_name'),
				'value' => qa_html(isset($inname) ? $inname : @$editpage['title']),
				'error' => qa_html(@$errors['name']),
			),

			'delete' => array(
				'tags' => 'name="dodelete" id="dodelete"',
				'label' => qa_lang_html($isexternal ? 'admin/delete_link' : 'admin/delete_page'),
				'value' => 0,
				'type' => 'checkbox',
Scott committed
350 351
			),

Scott committed
352 353 354 355 356 357 358 359
			'position' => array(
				'id' => 'position_display',
				'tags' => 'name="position"',
				'label' => qa_lang_html('admin/position'),
				'type' => 'select',
				'options' => $positionoptions,
				'value' => $positionvalue,
			),
Scott committed
360

Scott committed
361 362 363 364 365 366 367 368
			'permit' => array(
				'id' => 'permit_display',
				'tags' => 'name="permit"',
				'label' => qa_lang_html('admin/permit_to_view'),
				'type' => 'select',
				'options' => $permitoptions,
				'value' => $permitvalue,
			),
Scott committed
369

Scott committed
370 371 372 373 374 375
			'slug' => array(
				'id' => 'slug_display',
				'tags' => 'name="slug"',
				'label' => qa_lang_html('admin/page_slug'),
				'value' => qa_html(isset($inslug) ? $inslug : @$editpage['tags']),
				'error' => qa_html(@$errors['slug']),
Scott committed
376 377
			),

Scott committed
378 379 380 381 382 383
			'url' => array(
				'id' => 'url_display',
				'tags' => 'name="url"',
				'label' => qa_lang_html('admin/link_url'),
				'value' => qa_html(isset($inurl) ? $inurl : @$editpage['tags']),
				'error' => qa_html(@$errors['url']),
Scott committed
384 385
			),

Scott committed
386 387 388 389 390 391 392
			'newwindow' => array(
				'id' => 'newwindow_display',
				'tags' => 'name="newwindow"',
				'label' => qa_lang_html('admin/link_new_window'),
				'value' => (isset($innewwindow) ? $innewwindow : (@$editpage['flags'] & QA_PAGE_FLAGS_NEW_WINDOW)) ? 1 : 0,
				'type' => 'checkbox',
			),
Scott committed
393

Scott committed
394 395 396 397 398 399 400
			'heading' => array(
				'id' => 'heading_display',
				'tags' => 'name="heading"',
				'label' => qa_lang_html('admin/page_heading'),
				'value' => qa_html(isset($inheading) ? $inheading : @$editpage['heading']),
				'error' => qa_html(@$errors['heading']),
			),
Scott committed
401

Scott committed
402 403 404 405 406 407 408 409 410
			'content' => array(
				'id' => 'content_display',
				'tags' => 'name="content"',
				'label' => qa_lang_html('admin/page_content_html'),
				'value' => qa_html(isset($incontent) ? $incontent : @$editpage['content']),
				'error' => qa_html(@$errors['content']),
				'rows' => 16,
			),
		),
Scott committed
411

Scott committed
412 413 414 415
		'buttons' => array(
			'save' => array(
				'label' => qa_lang_html(isset($editpage['pageid']) ? 'main/save_button' : ($isexternal ? 'admin/add_link_button' : 'admin/add_page_button')),
			),
Scott committed
416

Scott committed
417 418 419 420
			'saveview' => array(
				'tags' => 'name="dosaveview"',
				'label' => qa_lang_html('admin/save_view_button'),
			),
Scott committed
421

Scott committed
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
			'cancel' => array(
				'tags' => 'name="docancel"',
				'label' => qa_lang_html('main/cancel_button'),
			),
		),

		'hidden' => array(
			'dosavepage' => '1', // for IE
			'edit' => @$editpage['pageid'],
			'external' => (int)$isexternal,
			'code' => qa_get_form_security_code('admin/pages'),
		),
	);

	if ($isexternal) {
		unset($qa_content['form']['fields']['slug']);
		unset($qa_content['form']['fields']['heading']);
		unset($qa_content['form']['fields']['content']);
Scott committed
440 441

	} else {
Scott committed
442 443 444
		unset($qa_content['form']['fields']['url']);
		unset($qa_content['form']['fields']['newwindow']);
	}
Scott committed
445

Scott committed
446 447 448 449 450 451 452 453
	if (isset($editpage['pageid'])) {
		qa_set_display_rules($qa_content, array(
			'position_display' => '!dodelete',
			'permit_display' => '!dodelete',
			($isexternal ? 'url_display' : 'slug_display') => '!dodelete',
			($isexternal ? 'newwindow_display' : 'heading_display') => '!dodelete',
			'content_display' => '!dodelete',
		));
Scott committed
454

Scott committed
455 456 457 458
	} else {
		unset($qa_content['form']['fields']['slug']);
		unset($qa_content['form']['fields']['delete']);
	}
Scott committed
459

Scott committed
460 461
	if ($isexternal || !isset($editpage['pageid']))
		unset($qa_content['form']['buttons']['saveview']);
Scott committed
462

Scott committed
463
	$qa_content['focusid'] = 'name';
Scott committed
464

Scott committed
465
} else {
Scott committed
466
	// List of standard navigation links
Scott committed
467 468 469 470
	$qa_content['form'] = array(
		'tags' => 'method="post" action="' . qa_self_html() . '"',

		'style' => 'tall',
Scott committed
471

Scott committed
472 473 474 475 476 477
		'fields' => array(),

		'buttons' => array(
			'save' => array(
				'tags' => 'name="dosaveoptions"',
				'label' => qa_lang_html('main/save_button'),
Scott committed
478 479
			),

Scott committed
480 481 482
			'addpage' => array(
				'tags' => 'name="doaddpage"',
				'label' => qa_lang_html('admin/add_page_button'),
Scott committed
483 484
			),

Scott committed
485 486 487 488 489
			'addlink' => array(
				'tags' => 'name="doaddlink"',
				'label' => qa_lang_html('admin/add_link_button'),
			),
		),
Scott committed
490

Scott committed
491 492 493 494
		'hidden' => array(
			'code' => qa_get_form_security_code('admin/pages'),
		),
	);
Scott committed
495

Scott committed
496 497 498 499 500 501 502 503 504 505 506 507
	$qa_content['form']['fields']['navlinks'] = array(
		'label' => qa_lang_html('admin/nav_links_explanation'),
		'type' => 'static',
		'tight' => true,
	);

	foreach ($navoptions as $optionname => $langkey) {
		$qa_content['form']['fields'][$optionname] = array(
			'label' => '<a href="' . qa_path_html($navpaths[$optionname]) . '">' . qa_lang_html($langkey) . '</a>',
			'tags' => 'name="option_' . $optionname . '"',
			'type' => 'checkbox',
			'value' => qa_opt($optionname),
Scott committed
508
		);
Scott committed
509 510 511 512 513
	}

	$qa_content['form']['fields'][] = array(
		'type' => 'blank'
	);
Scott committed
514

Scott committed
515
	// List of suggested plugin pages
Scott committed
516

Scott committed
517
	$listhtml = '';
Scott committed
518

Scott committed
519
	$pagemodules = qa_load_modules_with('page', 'suggest_requests');
Scott committed
520

Scott committed
521 522
	foreach ($pagemodules as $tryname => $trypage) {
		$suggestrequests = $trypage->suggest_requests();
Scott committed
523

Scott committed
524 525
		foreach ($suggestrequests as $suggestrequest) {
			$listhtml .= '<li><b><a href="' . qa_path_html($suggestrequest['request']) . '">' . qa_html($suggestrequest['title']) . '</a></b>';
Scott committed
526

Scott committed
527
			$listhtml .= qa_lang_html_sub('admin/plugin_module', qa_html($tryname));
Scott committed
528

Scott committed
529 530 531 532
			$listhtml .= strtr(qa_lang_html('admin/add_link_link'), array(
				'^1' => '<a href="' . qa_path_html(qa_request(), array('doaddlink' => 1, 'text' => $suggestrequest['title'], 'url' => $suggestrequest['request'], 'nav' => @$suggestrequest['nav'])) . '">',
				'^2' => '</a>',
			));
Scott committed
533

Scott committed
534 535
			if (method_exists($trypage, 'admin_form'))
				$listhtml .= ' - <a href="' . qa_admin_module_options_path('page', $tryname) . '">' . qa_lang_html('admin/options') . '</a>';
Scott committed
536

Scott committed
537
			$listhtml .= '</li>';
Scott committed
538
		}
Scott committed
539
	}
Scott committed
540

Scott committed
541 542 543 544 545 546 547
	if (strlen($listhtml)) {
		$qa_content['form']['fields']['plugins'] = array(
			'label' => qa_lang_html('admin/plugin_pages_explanation'),
			'type' => 'custom',
			'html' => '<ul style="margin-bottom:0;">' . $listhtml . '</ul>',
		);
	}
Scott committed
548

Scott committed
549
	// List of custom pages or links
Scott committed
550

Scott committed
551
	$listhtml = '';
Scott committed
552

Scott committed
553 554
	foreach ($pages as $page) {
		$listhtml .= '<li><b><a href="' . qa_custom_page_url($page) . '">' . qa_html($page['title']) . '</a></b>';
Scott committed
555

Scott committed
556 557 558 559
		$listhtml .= strtr(qa_lang_html(($page['flags'] & QA_PAGE_FLAGS_EXTERNAL) ? 'admin/edit_link' : 'admin/edit_page'), array(
			'^1' => '<a href="' . qa_path_html('admin/pages', array('edit' => $page['pageid'])) . '">',
			'^2' => '</a>',
		));
Scott committed
560

Scott committed
561
		$listhtml .= '</li>';
Scott committed
562 563
	}

Scott committed
564 565 566 567 568 569
	$qa_content['form']['fields']['pages'] = array(
		'label' => strlen($listhtml) ? qa_lang_html('admin/click_name_edit') : qa_lang_html('admin/pages_explanation'),
		'type' => 'custom',
		'html' => strlen($listhtml) ? '<ul style="margin-bottom:0;">' . $listhtml . '</ul>' : null,
	);
}
Scott committed
570

Scott committed
571
$qa_content['navigation']['sub'] = qa_admin_sub_navigation();
Scott committed
572 573


Scott committed
574
return $qa_content;