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