Просмотр файла vavok-1.5.3/adminpanel/procfiles.php

Размер файла: 9.11Kb
  1. <?php
  2. // (c) vavok.net - Aleksandar Vranešević
  3. // modified: 24.07.2020. 12:17:40
  4. // todo: rewrite whole page
  5.  
  6. require_once"../include/startup.php";
  7. require_once"../include/htmlbbparser.php";
  8.  
  9. if (!$users->is_reg() || (!$users->is_administrator() && !$users->check_permissions('pageedit', 'show'))) { redirect_to("../?isset=ap_noaccess"); }
  10.  
  11. // init page editor
  12. $pageEditor = new Page;
  13.  
  14. $action = isset($_GET['action']) ? check($_GET['action']) : '';
  15.  
  16. if (isset($_GET['file'])) {
  17. $file = check($_GET['file']);
  18.  
  19. // get page id we work with
  20. $page_id = $pageEditor->get_page_id("file='{$file}'");
  21. } elseif (isset($_POST['file'])) {
  22. $file = check($_POST['file']);
  23.  
  24. // get page id we work with
  25. $page_id = $pageEditor->get_page_id("file='{$file}'");
  26. } else {
  27. $file = '';
  28. }
  29.  
  30. $text_files = isset($_POST['text_files']) ? $_POST['text_files'] : ''; // keep data as received so html codes will be ok
  31.  
  32. $config_editfiles = 10;
  33.  
  34. if ($action == "editfile") {
  35. // get edit mode
  36. if (!empty($_SESSION['edmode'])) {
  37. $edmode = check($_SESSION['edmode']);
  38. } else {
  39. $edmode = 'columnist';
  40. $_SESSION['edmode'] = $edmode;
  41. }
  42.  
  43. if (!empty($file) && !empty($text_files)) {
  44. $page_info = $pageEditor->select_page($page_id, 'crtdby, published');
  45.  
  46. if (!$users->check_permissions('pageedit', 'show') && !$users->is_administrator()) { redirect_to("index.php?isset=ap_noaccess"); }
  47.  
  48. if ($page_info['crtdby'] != $user_id && !$users->check_permissions('pageedit', 'edit') && (!$users->check_permissions('pageedit', 'editunpub') || $page_info['published'] != 1) && !$users->is_administrator()) {
  49. header("Location: index.php?isset=ap_noaccess");
  50. exit;
  51. }
  52.  
  53. // bug when magic quotes are on and '\' sign
  54. // if magic quotes are on we don't want ' to become \'
  55. if (get_magic_quotes_gpc()) {
  56. // strip all slashes
  57. $text_files = stripslashes($text_files);
  58. }
  59.  
  60. $text_files = str_replace('{INBOX}', '<?php echo \'<a href="\' . BASEDIR . \'pages/inbox.php">\' . $lang_home[\'inbox\'] . \'</a>\'; ?>', $text_files);
  61. $text_files = str_replace('{INBOXMSGS}', '<?php echo \'(\' . $users->user_mail($user_id) . \')\'; ?>', $text_files);
  62. $text_files = str_replace('{LOGOUT}', '<?php echo \'<a href="\' . BASEDIR . \'pages/input.php?action=exit">Log out</a>\'; ?>', $text_files);
  63.  
  64. $text_files = str_replace('{BASEDIR}', '<?php echo BASEDIR; ?>', $text_files);
  65.  
  66. // update db data
  67. $pageEditor->update($page_id, $text_files);
  68. }
  69.  
  70. header("Location: files.php?action=edit&file=$file&isset=mp_editfiles");
  71. exit;
  72. }
  73.  
  74. // update head tags on all pages
  75. if ($action == 'editmainhead') {
  76. if (!$users->is_administrator(101)) {
  77. redirect_to("../?isset=ap_noaccess");
  78. }
  79.  
  80. // update header data
  81. file_put_contents("../used/headmeta.dat", $text_files);
  82.  
  83. redirect_to("files.php?action=mainmeta&isset=mp_editfiles");
  84. }
  85.  
  86. // update head tags on specific page
  87. if ($action == "editheadtag") {
  88.  
  89. // get default image link
  90. $image = !empty($_POST['image']) ? check($_POST['image']) : '';
  91.  
  92. // update header tags
  93. if (!empty($file)) {
  94.  
  95. // who created page
  96. $page_info = $pageEditor->select_page($page_id, 'crtdby');
  97.  
  98. // check can user see page
  99. if (!$users->check_permissions('pageedit', 'show') && !$users->is_administrator()) { redirect_to("index.php?isset=ap_noaccess"); }
  100.  
  101. // check can user edit page
  102. if (!$users->check_permissions('pageedit', 'edit') && !$users->is_administrator() && $page_info['crtdby'] != $user_id) { redirect_to("index.php?isset=ap_noaccess"); }
  103.  
  104. // update db data
  105. $data = array(
  106. 'headt' => $text_files,
  107. 'default_img' => $image
  108. );
  109. $pageEditor->head_data($page_id, $data);
  110.  
  111. // redirect
  112. redirect_to("files.php?action=headtag&file=$file&isset=mp_editfiles");
  113.  
  114. }
  115. // fields must not be empty
  116. redirect_to("files.php?action=headtag&file=$file&isset=mp_noeditfiles");
  117. }
  118.  
  119. // rename page
  120. if ($action == "renamepg") {
  121. $pg = check($_POST['pg']); // new file name
  122.  
  123. if (!empty($pg) && !empty($file)) {
  124. $page_info = $pageEditor->select_page($page_id, 'crtdby');
  125.  
  126. if (!$users->check_permissions('pageedit', 'show') && !$users->is_administrator()) {
  127. header("Location: index.php?isset=ap_noaccess");
  128. exit;
  129. }
  130. if (!$users->check_permissions('pageedit', 'edit') && !$users->is_administrator() && $page_info['crtdby'] != $user_id) {
  131. header("Location: index.php?isset=ap_noaccess");
  132. exit;
  133. }
  134.  
  135. // rename page
  136. $pageEditor->rename($pg, $page_id);
  137.  
  138. header("Location: files.php?action=edit&file=$pg&isset=mp_editfiles");
  139. exit;
  140. }
  141. header("Location: files.php?action=edit&file=$pg&isset=mp_noedit");
  142. exit;
  143. }
  144.  
  145. if ($action == "addnew") {
  146.  
  147. if (!$users->check_permissions('pageedit', 'insert') && !$users->is_administrator()) { redirect_to("index.php?isset=ap_noaccess"); }
  148.  
  149. $newfile = isset($_POST['newfile']) ? check($_POST['newfile']) : '';
  150. $type = isset($_POST['type']) ? check($_POST['type']) : '';
  151. $page_structure = isset($_POST['page_structure']) ? check($_POST['page_structure']) : '';
  152. $allow_unicode = isset($_POST['allow_unicode']) ? true : false;
  153.  
  154. // page title
  155. $page_title = $newfile;
  156.  
  157. // page name in url
  158. if ($allow_unicode === false) {
  159. // remove unicode chars
  160. $newfile = trans($newfile);
  161. } else {
  162. $newfile = trans_unicode($newfile);
  163. }
  164.  
  165. // if page structure is set
  166. if (!empty($page_structure)) {
  167. $type = $page_structure;
  168. }
  169.  
  170. // page language
  171. if (isset($_POST['lang']) && !empty($_POST['lang'])) {
  172.  
  173. $pagelang = check($_POST['lang']);
  174.  
  175. $pagelang_file = '!.' . $pagelang . '!';
  176.  
  177. } else {
  178.  
  179. $pagelang = '';
  180.  
  181. }
  182.  
  183. if (!empty($newfile)) {
  184. // page filename
  185. $newfiles = $newfile . $pagelang_file . '.php';
  186.  
  187. // check if page exists
  188. $includePageLang = !empty($pagelang) ? " AND lang='{$pagelang}'" : '';
  189.  
  190. if ($pageEditor->page_exists('', "pname='{$newfile}'" . $includePageLang)) {
  191. redirect_to("files.php?action=new&isset=mp_pageexists");
  192. }
  193.  
  194. // full page address
  195. if (!empty($page_structure)) {
  196. // user's custom page structure
  197. $page_url = website_home_address() . '/' . $page_structure . '/' . $newfile . '/';
  198. } elseif ($type == 'post') {
  199. // blog post
  200. $page_url = website_home_address() . '/blog/' . $newfile . '/';
  201. } else {
  202. // page
  203. $page_url = website_home_address() . '/page/' . $newfile . '/';
  204. }
  205.  
  206. // insert db data
  207. $values = array(
  208. 'pname' => $newfile,
  209. 'lang' => $pagelang,
  210. 'created' => time(),
  211. 'lastupd' => time(),
  212. 'lstupdby' => $user_id,
  213. 'file' => $newfiles,
  214. 'crtdby' => $user_id,
  215. 'published' => '1',
  216. 'pubdate' => '0',
  217. 'tname' => $page_title,
  218. 'headt' => '<meta property="og:title" content="' . $page_title . '" />'. "\r\n" . '<meta property="og:url" content="' . $page_url . '" />' . "\r\n" . '<link rel="canonical" href="' . $page_url . '" />',
  219. 'type' => $type
  220. );
  221.  
  222. // insert data
  223. $pageEditor->insert($values);
  224.  
  225. // file successfully created
  226. redirect_to("files.php?action=edit&file=$newfiles&isset=mp_newfiles");
  227.  
  228. } else {
  229. redirect_to("files.php?action=new&isset=mp_noyesfiles");
  230. }
  231.  
  232. }
  233.  
  234. if ($action == "del") {
  235.  
  236. if (!$users->check_permissions('pageedit', 'del') && !$users->is_administrator()) {
  237. redirect_to("index.php?isset=ap_noaccess");
  238. }
  239.  
  240. // delete page
  241. $pageEditor->delete($page_id);
  242. redirect_to("files.php?isset=mp_delfiles");
  243. }
  244.  
  245. // publish page; page will be avaliable for visitors
  246. if ($action == "publish") {
  247. if (!empty($page_id)) {
  248.  
  249. if (!$users->check_permissions('pageedit', 'edit') && !$users->is_administrator()) {
  250. header("Location: index.php?isset=ap_noaccess");
  251. exit;
  252. }
  253.  
  254. // update db data
  255. $pageEditor->visibility($page_id, 2);
  256. }
  257.  
  258. redirect_to("files.php?action=show&file=" . $file . "&isset=mp_editfiles");
  259. }
  260.  
  261. // unpublish page
  262. if ($action == "unpublish") {
  263.  
  264. if (!empty($page_id)) {
  265.  
  266. if (!$users->check_permissions('pageedit', 'edit') && !$users->is_administrator()) {
  267. header("Location: index.php?isset=ap_noaccess");
  268. exit;
  269. }
  270.  
  271. // update db data
  272. $pageEditor->visibility($page_id, 1);
  273. }
  274.  
  275. redirect_to("files.php?action=show&file=" . $file . "&isset=mp_editfiles");
  276. }
  277.  
  278. // update page language
  279. if ($action == 'pagelang') {
  280. if (!$users->is_administrator()) { redirect_to("../?isset=ap_noaccess"); }
  281.  
  282. $pageId = check($_GET['id']);
  283. $lang = check($_POST['lang']);
  284.  
  285. // update database data
  286. $pageEditor->language($pageId, $lang);
  287.  
  288. $pageData = $pageEditor->select_page($pageId);
  289. redirect_to("files.php?action=show&file=" . $pageData['pname'] . "!." . $lang . "!.php&isset=mp_editfiles");
  290.  
  291. }
  292.  
  293. ?>