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>"; }
public function index() { /* UserCake (Via CupCake) Version: 2.0.2 http://usercake.com */ global $baseURL, $loggedInUser, $errors, $success; require_once "{$baseURL}/application/third_party/user_cake/models/config.php"; if (!securePage($_SERVER['PHP_SELF'])) { die; } //Forms posted if (!empty($_POST)) { $pageName = $_POST['pageName']; $pageNameWithoutExt = str_replace(".php", "", $pageName); $defaultPages = fetchAllPages(); $pageCheck = false; foreach ($defaultPages as $indPage) { if ($indPage['page'] == $pageNameWithoutExt) { $pageCheck = true; } } if (preg_match('/^[A-Za-z][A-Za-z0-9]*(?:_[A-Za-z0-9]+)*$/', $pageNameWithoutExt) && !$pageCheck) { $comment = $_POST['pageComment']; $nameWords = explode("_", $pageNameWithoutExt); $className = ''; if (sizeof($nameWords)) { for ($i = 0; $i < sizeof($nameWords); $i++) { $sep = $i ? "_" : ""; $className .= $sep . ucfirst($nameWords[$i]); } } else { $className = ucfirst($pageNameWithoutExt); } $file = fopen("{$baseURL}/application/controllers/{$pageName}.php", "w"); fwrite($file, '<?php /* This pase was created by ' . $loggedInUser->displayname . ' at "' . date("Y m d H-i-s") . '". */ /* ' . $comment . ' */ class ' . $className . ' extends CI_Controller{ public function __construct(){ parent::__construct(); global $baseURL; $baseURL = getcwd(); // File requires to check logged in user information. require_once("$baseURL/application/third_party/user_cake/models/class.user.php"); // Basic helper and libraries $this->load->helper(); $this->load->library("session"); } public function index(){ global $baseURL; // Require config file require_once("$baseURL/application/third_party/user_cake/models/config.php"); // Write your code after this line // Code ends here // index function $this->load->view("' . $pageName . '"); } } ?>'); fclose($file); $file = fopen("{$baseURL}/application/views/{$pageName}.php", "w"); fwrite($file, '<?php global $baseURL; require_once("$baseURL/application/third_party/user_cake/models/header.php"); ?> <!DOCTYPE html PUBLIC \'-//W3C//DTD XHTML 1.0 Transitional//EN\' \'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\'> <html xmlns=\'http://www.w3.org/1999/xhtml\'> <head> <meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\' /> <title>' . $pageName . '</title> </head> <body> <div id="wrapper"> <div id="top"><div id="logo"></div></div> <div id="content"> <h1>UserCake (Via CupCake)</h1> <h2>Account</h2> <div id="left-nav"> <?php include("$baseURL/application/third_party/user_cake/left-nav.php"); ?> </div> <div id="main"> </div> <div id="bottom"></div> </div> </body> </html>'); fclose($file); $newPage = array(str_replace(".php", "", $pageName)); createPages($newPage); $successes[] = lang("PAGE_CREATED_SUCCESSFULLY", array($baseURL, $pageName)); } else { if ($pageCheck) { $errors[] = lang("USER_CREATED_PAGE_EXIST"); } else { $errors[] = lang("PAGE_VALIDATION_ERROR"); } } } 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 Page</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'>"; echo resultBlock($errors, $successes); echo "\r\n<form name='newPage' action='" . $_SERVER['PHP_SELF'] . "' method='post'>\r\n<input type='hidden' name='process' value='1'>\r\n<table class='admin'>\r\n<tr><td>\r\n<h3>Add New Page</h3>\r\n<div id='regbox'>\r\n<p>\r\n<label>New Page Name:</label>\r\n<input type = 'text' name = 'pageName' id = 'pageName'><br/>\r\n(only underscore '_' is allowed as special character.)<br/>\r\n<label>Write your comment:</label><textarea rows = '5' cols = '30' name = 'pageComment' id = 'pageComment'></textarea><br/>\r\n<div>( This is only for documentation purpose. )</div>"; echo "<input type='submit' value='Create' class='submit'/>\r\n</p>\r\n</form>\r\n</div>\r\n<div id='bottom'></div>\r\n</div>\r\n</body>\r\n</html>"; }
} $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']; } } } //Delete pages from DB if not found if (count($deletions) > 0) { deletePages($deletions); } //Update DB pages $dbpages = fetchAllPages();
/** * 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."); } }
public function item_list() { if ($this->check_admin()) { $action = $this->spArgs("act"); $item_id = $this->spArgs("item_id"); $this->message = $this->spArgs("message"); $ptx_item = spClass('ptx_item'); $ptx_share = spClass('ptx_share'); if ($item_id) { $conditions['item_id'] = $item_id; $this->item = $ptx_item->find($conditions); $this->share = $ptx_share->find($conditions); } if ($action == 'delete' && $this->item) { $ptx_item->update($conditions, array('is_deleted' => 1)); $this->jump(spUrl('admin', 'item_list')); return; } else { if ($action == 'push' && $this->item) { $ptx_item->update($conditions, array('is_show' => 2)); $this->jump(spUrl('admin', 'item_list')); return; } else { if ($action == 'depush' && $this->item) { $ptx_item->update($conditions, array('is_show' => 1)); $this->jump(spUrl('admin', 'item_list')); return; } else { if ($action == 'verify' && $this->item) { $ptx_item->update($conditions, array('is_show' => 1)); $albums = $ptx_share->find_albums_by_item($item_id); $ptx_album = spClass('ptx_album'); foreach ($albums as $album) { $ptx_album->update_album_cover($album['album_id']); } $this->jump(spUrl('admin', 'item_list')); return; } else { if ($action == 'deverify' && $this->item) { $ptx_item->update($conditions, array('is_show' => 0)); $this->jump(spUrl('admin', 'item_list')); return; } else { if ($action == 'edit' && $this->item) { $this->display("/admin/item_edit.php"); return; } else { if ($action == 'edit_save' && $this->item) { $segment = spClass('Segment'); $update_data['intro'] = $this->spArgs('intro'); $segment_str = $segment->segment($update_data['intro']); $update_data['intro_search'] = $segment_str['py']; $update_data['keywords'] = $segment_str['cn']; $update_data['price'] = $this->spArgs("price"); $update_data['title'] = $this->spArgs("title"); $update_data['promotion_url'] = $this->spArgs("promotion_url"); $share_update_data['category_id'] = $this->spArgs("category_id"); $ptx_share->update($conditions, $share_update_data); if ($ptx_item->update($conditions, $update_data)) { $this->jump(spUrl('admin', 'item_list')); } else { $this->jump(spUrl('admin', 'item_list', array('act' => 'edit', 'item_id' => $item['item_id'], 'message' => '修改失败'))); return; } return; } else { if ($action == 'search') { $conditions['orgin_post'] = 1; $page = $this->spArgs("page", 1); if (NULL != $this->spArgs("is_show")) { $conditions['is_show'] = $this->spArgs("is_show"); } if ($category_id = $this->spArgs("category_id")) { $conditions['category_id'] = $category_id; } if ($keyword = $this->spArgs("keyword")) { $segment = spClass('Segment'); $conditions['keyword'] = $segment->convert_to_py($keyword); } $this->items = $ptx_share->search($conditions, $page, 15); $conditions['act'] = 'search'; $this->pages = createPages($ptx_share->spPager()->getPager(), 'admin', 'item_list', $conditions); $this->display("/admin/item_list.php"); } else { $conditions['orgin_post'] = 1; //$conditions['is_deleted'] = 0; $page = $this->spArgs("page", 1); $this->items = $ptx_share->search($conditions, $page, 15); //var_dump($this->shares); //$this->items = $ptx_item->spPager($page, 15)->findAll($conditions,' item_id DESC '); $this->pages = createPages($ptx_share->spPager()->getPager(), 'admin', 'item_list'); $this->display("/admin/item_list.php"); } } } } } } } } } }