public function action_view() { // We only get here when authorization has been executed // Correct page has been loaded in the before() function $pagename = Wi3::inst()->routing->args[0]; $this->prepareForViewing($pagename); // Render page $renderedInAdminArea = false; $this->request->response = Wi3_Renderer::renderPage($pagename, $renderedInAdminArea); // Page caching will be handled via an Event. See bootstrap.php and the Caching plugin }
public function action_content_edit($pageOrPagename = "") { // Load correct page. if (empty($pageOrPagename)) { // Pagename is the first argument from the URL $pageOrPagename = Wi3::inst()->routing->args[0]; } $renderedInAdminArea = true; $this->template = Wi3_Renderer::renderPage($pageOrPagename, $renderedInAdminArea); // Page caching will be handled via an Event. See bootstrap.php and the Caching module }
public function action_edit() { $fieldid = $_POST["fieldid"]; $field = Wi3::inst()->model->factory("site_field")->set("id", $fieldid)->load(); // check for 'callback' if (method_exists($this, "edit")) { $this->edit($field); } $dataobject = $this->fielddata($field); // If data does not exist, create it if (!$dataobject->loaded()) { $dataobject->create(); } // Check if every part of the model is present in the data, and if not: create it $this->ensureModelExists($dataobject); // Update data field with data foreach ($_POST as $index => $value) { $dataobject->{$index} = $value; } $dataobject->update(); // Remove cache of all pages, since we do not know how this change affects other pages Wi3::inst()->cache->removeAll(); // Let the Front-End rerender the affected field // We however do not want *just* the rendered field with its own content (return e.g. a <cms> element), // we want to have the field as it would appear on the page (e.g. with expanded <cms> elements into <div field...> elements) // including all mutations that any plugin or top-level element might do // Thus we first render the complete page, and then extract the field from there $pageid = $_POST["pageid"]; // TODO: do not render if user does not have proper rights // Render page, and check if our field is within it $page = $field = Wi3::inst()->model->factory("site_page")->set("id", $pageid)->load(); $renderedInAdminArea = true; $pageHtml = Wi3_Renderer::renderPage($page, $renderedInAdminArea); // Now get the proper part of the page if (strpos($pageHtml, $fieldid) > 0) { // The field probably exists. Search for it using phpQuery $document = phpQuery::newDocument($pageHtml); // Give PHPQuery a context to work with $fieldHtml = pq("[type=field][fieldid=" . $fieldid . "]")->html(); } else { $fieldHtml = "Field does not exist on the page."; } echo json_encode(array("scriptsbefore" => array("0" => "wi3.pagefillers.default.edittoolbar.renderFieldHtml('" . $fieldid . "', '" . base64_encode($fieldHtml) . "');"))); }