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 22
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	File: qa-include/qa-page-admin-pages.php
	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
23 24 25 26
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
	header('Location: ../');
	exit;
}
Scott committed
27

Scott committed
28 29 30
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
31 32 33 34


//	Get current list of pages and determine the state of this admin page

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

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

Scott committed
44 45 46
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
47

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


//	Check admin privileges (do late to allow one DB query)

Scott committed
54 55
if (!qa_admin_check_privileges($qa_content))
	return $qa_content;
Scott committed
56 57 58 59


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

Scott committed
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
$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
97 98 99 100


//	Process saving an old or new page

Scott committed
101
$securityexpired = false;
Scott committed
102

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

Scott committed
106 107 108 109 110
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
111

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

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

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

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

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

Scott committed
131 132 133 134 135 136 137 138
		} 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
139

Scott committed
140
			$errors = array();
Scott committed
141 142 143

			//	Verify the name (navigation link) is legitimate

Scott committed
144 145 146 147
			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
148

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

Scott committed
152 153 154 155
				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
156

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

Scott committed
160 161
				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
162 163 164

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

Scott committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178
				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
179 180
							break;
					}
Scott committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203

					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
204
				}
Scott committed
205
			}
Scott committed
206 207 208

			//	Perform appropriate database action

Scott committed
209 210 211 212 213 214 215
			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
216

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

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

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

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

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

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

Scott committed
240
				$reloadpages = true;
Scott committed
241

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

Scott committed
247 248 249 250 251 252
			} 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
253

Scott committed
254 255 256 257 258
						$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
259 260
					}

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

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

			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
275 276
		}
	}
Scott committed
277
}
Scott committed
278 279 280 281


//	Prepare content for theme

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

Scott committed
284 285
$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
286

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

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

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

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

Scott committed
305 306 307 308 309 310
		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
311

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

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

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

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 350
		if ((!isset($editpage['pageid'])) || $nav != @$editpage['nav']) {
			$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
351 352
			),

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

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

Scott committed
371 372 373 374 375 376
			'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
377 378
			),

Scott committed
379 380 381 382 383 384
			'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
385 386
			),

Scott committed
387 388 389 390 391 392 393
			'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
394

Scott committed
395 396 397 398 399 400 401
			'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
402

Scott committed
403 404 405 406 407 408 409 410 411
			'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
412

Scott committed
413 414 415 416
		'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
417

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

Scott committed
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
			'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
441 442

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

Scott committed
447 448 449 450 451 452 453 454
	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
455

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

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

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

Scott committed
466
} else {
Scott committed
467

Scott committed
468 469 470 471 472 473
	//	List of standard navigation links

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

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

Scott committed
475 476 477 478 479 480
		'fields' => array(),

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

Scott committed
483 484 485
			'addpage' => array(
				'tags' => 'name="doaddpage"',
				'label' => qa_lang_html('admin/add_page_button'),
Scott committed
486 487
			),

Scott committed
488 489 490 491 492
			'addlink' => array(
				'tags' => 'name="doaddlink"',
				'label' => qa_lang_html('admin/add_link_button'),
			),
		),
Scott committed
493

Scott committed
494 495 496 497
		'hidden' => array(
			'code' => qa_get_form_security_code('admin/pages'),
		),
	);
Scott committed
498

Scott committed
499 500 501 502 503 504 505 506 507 508 509 510
	$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
511
		);
Scott committed
512 513 514 515 516
	}

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

	//	List of suggested plugin pages

Scott committed
520
	$listhtml = '';
Scott committed
521

Scott committed
522
	$pagemodules = qa_load_modules_with('page', 'suggest_requests');
Scott committed
523

Scott committed
524 525
	foreach ($pagemodules as $tryname => $trypage) {
		$suggestrequests = $trypage->suggest_requests();
Scott committed
526

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

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

Scott committed
532 533 534 535
			$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
536

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

Scott committed
540
			$listhtml .= '</li>';
Scott committed
541
		}
Scott committed
542
	}
Scott committed
543

Scott committed
544 545 546 547 548 549 550
	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
551 552 553

	//	List of custom pages or links

Scott committed
554
	$listhtml = '';
Scott committed
555

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

Scott committed
559 560 561 562
		$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
563

Scott committed
564
		$listhtml .= '</li>';
Scott committed
565 566
	}

Scott committed
567 568 569 570 571 572
	$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
573

Scott committed
574
$qa_content['navigation']['sub'] = qa_admin_sub_navigation();
Scott committed
575 576


Scott committed
577
return $qa_content;