PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/edit.php

http://github.com/taylorchu/goolog
PHP | 120 lines | 112 code | 8 blank | 0 comment | 29 complexity | 699f1a96f626e1ba8e594223a790b22b MD5 | raw file
  1<?php
  2
  3$out['self'] = 'edit';
  4require 'header.php';
  5
  6if(isGETValidEntry('post', 'post') && isAdmin())
  7{
  8	$postEntry = readEntry('post', $_GET['post']);
  9	$out['subtitle'] = lang('edit post : %s', $postEntry['title']);
 10	if(checkBot() && check('title') && check('content', 1, 2000) &&
 11		isPOST('locked') && ($_POST['locked'] === 'yes' || $_POST['locked'] === 'no') &&
 12		isPOST('category') && ($_POST['category'] === '' || isValidEntry('category', $_POST['category'])))
 13	{
 14		$postEntry['title'] = clean($_POST['title']);
 15		$postEntry['content'] = transNL(clean($_POST['content']));
 16
 17		$postEntry['locked'] = $_POST['locked'] === 'yes';
 18
 19		if($postEntry['category'] !== $_POST['category'])
 20		{
 21			if($postEntry['category'] !== '')
 22			{
 23				$categoryEntry = readEntry('category', $postEntry['category']);
 24				unset($categoryEntry['post'][$_GET['post']]);
 25				saveEntry('category', $postEntry['category'], $categoryEntry);
 26
 27				$postEntry['category'] = '';
 28			}
 29			if($_POST['category'] !== '')
 30			{
 31				$postEntry['category'] = $_POST['category'];
 32
 33				$categoryEntry = readEntry('category', $postEntry['category']);
 34				$categoryEntry['post'][$_GET['post']] = $_GET['post'];
 35				saveEntry('category', $postEntry['category'], $categoryEntry);
 36			}
 37		}
 38		saveEntry('post', $_GET['post'], $postEntry);
 39		$out['content'] .= '<p><a href="view.php/post/' .$_GET['post']. '">? ' .$lang['redirect']. ' : ' .$postEntry['title']. '</a></p>';
 40	}
 41	else
 42	{
 43		$categoryOptions[''] = $lang['uncategorized'];
 44		foreach(listEntry('category') as $category)
 45		{
 46			$categoryEntry = readEntry('category', $category);
 47			$categoryOptions[$category] = $categoryEntry['name'];
 48		}
 49		$out['content'] .= form('edit.php/post/' .$_GET['post'],
 50			text('title', $postEntry['title']).
 51			textarea('content', $postEntry['content']).
 52			select('locked', array('yes' => $lang['yes'], 'no' => $lang['no']), $postEntry['locked']? 'yes' : 'no').
 53			select('category', $categoryOptions, $postEntry['category']).
 54			submit()).
 55		preview('content');
 56	}
 57}
 58else if(isGETValidEntry('reply', 'reply') && (isAdmin() || isAuthor($_GET['reply'])))
 59{
 60	$replyEntry = readEntry('reply', $_GET['reply']);
 61	$out['subtitle'] = lang('edit reply');
 62	if(checkBot() && check('content', 1, 2000))
 63	{
 64		$replyEntry['content'] = transNL(clean($_POST['content']));
 65		saveEntry('reply', $_GET['reply'], $replyEntry);
 66		$postEntry = readEntry('post', $replyEntry['post']);
 67		$out['content'] .= '<p><a href="view.php/post/' .$replyEntry['post']. '/p/' .onPage($_GET['reply'], $postEntry['reply']). '#' .$_GET['reply']. '">? ' .$lang['redirect']. ' : ' .$postEntry['title']. '</a></p>';
 68	}
 69	else
 70	{
 71		$out['content'] .= form('edit.php/reply/' .$_GET['reply'],
 72			textarea('content', $replyEntry['content']).
 73			submit()).
 74		preview('content');
 75	}
 76}
 77else if(isGETValidEntry('link', 'link') && isAdmin())
 78{
 79	$linkEntry = readEntry('link', $_GET['link']);
 80	$out['subtitle'] = lang('edit link : %s', $linkEntry['name']);
 81	if(checkBot() && check('name') && check('url', 1, 80))
 82	{
 83		$linkEntry['name'] = clean($_POST['name']);
 84		$linkEntry['url'] = clean($_POST['url']);
 85		saveEntry('link', $_GET['link'], $linkEntry);
 86		$out['content'] .= '<p><a href="index.php/post">? ' .$lang['redirect']. ' : ' .$lang['post']. '</a></p>';
 87	}
 88	else
 89	{
 90		$out['content'] .= form('edit.php/link/' .$_GET['link'],
 91			text('name', $linkEntry['name']).
 92			text('url', $linkEntry['url']).
 93			submit());
 94	}
 95}
 96else if(isGETValidEntry('category', 'category') && isAdmin())
 97{
 98	$categoryEntry = readEntry('category', $_GET['category']);
 99	$out['subtitle'] = lang('edit category : %s', $categoryEntry['name']);
100	if(checkBot() && check('name'))
101	{
102		$categoryEntry['name'] = clean($_POST['name']);
103		saveEntry('category', $_GET['category'], $categoryEntry);
104		$out['content'] .= '<p><a href="index.php/post">? ' .$lang['redirect']. ' : ' .$lang['post']. '</a></p>';
105	}
106	else
107	{
108		$out['content'] .= form('edit.php/category/' .$_GET['category'],
109			text('name', $categoryEntry['name']).
110			submit());
111	}
112}
113else
114{
115	exit;
116}
117
118require 'footer.php';
119
120?>