public function index() { /* UserCake (Via CupCake) Version: 2.0.2 http://usercake.com */ global $baseURL; require_once "{$baseURL}/application/third_party/user_cake/models/config.php"; if (!securePage($_SERVER['PHP_SELF'])) { die; } $pages = getPageFiles(); //Retrieve list of pages in root usercake folder $dbpages = fetchAllPages(); //Retrieve list of pages in pages table $creations = array(); $deletions = array(); //Check if any pages exist which are not in DB foreach ($pages as $page) { if (!isset($dbpages[str_replace(".php", "", $page)])) { $creations[] = str_replace(".php", "", $page); } } //Enter new pages in DB if found if (count($creations) > 0) { createPages($creations); } if (count($dbpages) > 0) { //Check if DB contains pages that don't exist foreach ($dbpages as $page) { if (!isset($pages[$page['page'] . '.php'])) { $deletions[] = $page['id']; } } } //Delete pages from DB if not found if (count($deletions) > 0) { deletePages($deletions); } //Update DB pages $dbpages = fetchAllPages(); require_once "{$baseURL}/application/third_party/user_cake/models/header.php"; echo "\r\n<body>\r\n<div id='wrapper'>\r\n<div id='top'><div id='logo'></div></div>\r\n<div id='content'>\r\n<h1>UserCake (Via CupCake)</h1>\r\n<h2>Admin Pages</h2>\r\n<div id='left-nav'>"; include "{$baseURL}/application/third_party/user_cake/left-nav.php"; echo "\r\n</div>\r\n<div id='main'>\r\n<form name='adminPages' action='" . $_SERVER['PHP_SELF'] . "' method='post'>\r\n<table class='admin'>\r\n<tr><th>Delete</th><th>Id</th><th>Page</th><th>Access</th></tr>"; //Display list of pages foreach ($dbpages as $page) { echo "\r\n\t<tr>\r\n\t<td><input type='checkbox' name='delete[" . $page['id'] . "]' id='delete[" . $page['id'] . "]' value='" . $page['id'] . "'></td>\r\n\t<td>\r\n\t" . $page['id'] . "\r\n\t</td>\r\n\t<td>\r\n\t<a href ='" . str_replace('index.php/', '', site_url('admin_page')) . "?id=" . $page['id'] . "'>" . $page['page'] . "</a>\r\n\t</td>\r\n\t<td>"; //Show public/private setting of page if ($page['private'] == 0) { echo "Public"; } else { echo "Private"; } echo "\r\n\t</td>\r\n\t</tr>"; } echo "\r\n</table>\r\n<input type = 'submit' value = 'Submit'/>\r\n</form>\r\n</div>\r\n<div id='bottom'></div>\r\n</div>\r\n<div id = 'createNewPage'>\r\n<a href ='" . str_replace('index.php/', '', site_url('new_page')) . "'>Add Page</a>\r\n</div>\r\n</body>\r\n</html>"; }
<?php /* UserCake Version: 2.0.2 http://usercake.com */ require_once "models/config.php"; if (!securePage($_SERVER['PHP_SELF'])) { die; } $pages = getPageFiles(); //Retrieve list of pages in root usercake folder $dbpages = fetchAllPages(); //Retrieve list of pages in pages table $creations = array(); $deletions = array(); //Check if any pages exist which are not in DB foreach ($pages as $page) { if (!isset($dbpages[$page])) { $creations[] = $page; } } //Enter new pages in DB if found if (count($creations) > 0) { createPages($creations); } if (count($dbpages) > 0) { //Check if DB contains pages that don't exist foreach ($dbpages as $page) { if (!isset($pages[$page['page']])) { $deletions[] = $page['id'];
/** * Loads all site pages, adds new pages found, deletes pages not found * @return array $allPages containing all pages and associated permissions for those pages */ function loadSitePages() { // This block automatically checks this action against the permissions database before running. if (!checkActionPermissionSelf(__FUNCTION__, func_get_args())) { addAlert("danger", "Sorry, you do not have permission to access this resource."); return false; } global $page_include_paths; try { // Retrieve files in all included directories $pages = array(); foreach ($page_include_paths as $path) { $pages = array_merge($pages, getPageFiles($path)); } $dbpages = fetchAllPages(); //Retrieve list of pages in pages table $creations = array(); $deletions = array(); $originals = array(); //Check if any pages exist which are not in DB foreach ($pages as $page) { if (!isset($dbpages[$page])) { $creations[] = $page; } } //Enter new pages in DB if found if (count($creations) > 0) { createPages($creations); } // Find pages in table which no longer exist if (count($dbpages) > 0) { //Check if DB contains pages that don't exist foreach ($dbpages as $page) { if (!isset($pages[$page['page']])) { $deletions[] = $page['id']; } else { $originals[] = $page['id']; } } } $allPages = fetchAllPages(); // Merge the newly created pages, plus the pages slated for deletion, load their permissions, and set a flag (C)reated, (U)pdated, (D)eleted foreach ($allPages as $page) { $id = $page['id']; $name = $page['page']; if (in_array($name, $creations)) { $allPages[$name]['status'] = 'C'; } else { if (in_array($id, $deletions)) { $allPages[$name]['status'] = 'D'; } else { $allPages[$name]['status'] = 'U'; } } $pageGroups = fetchPageGroups($id); if ($pageGroups) { $allPages[$name]['permissions'] = $pageGroups; } else { $allPages[$name]['permissions'] = array(); } } //Delete pages from DB if (count($deletions) > 0) { deletePages($deletions); } return $allPages; } catch (PDOException $e) { addAlert("danger", "Oops, looks like our database encountered an error."); error_log("Error in " . $e->getFile() . " on line " . $e->getLine() . ": " . $e->getMessage()); } catch (ErrorException $e) { addAlert("danger", "Oops, looks like our server might have goofed. If you're an admin, please check the PHP error logs."); } }