/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendPagesModel::exists($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // init var $success = false; // cannot have children if (BackendPagesModel::getFirstChildId($this->id) !== false) { $this->redirect(BackendModel::createURLForAction('edit') . '&error=non-existing'); } $revisionId = $this->getParameter('revision_id', 'int'); if ($revisionId == 0) { $revisionId = null; } // get page (we need the title) $page = BackendPagesModel::get($this->id, $revisionId); // valid page? if (!empty($page)) { // delete the page $success = BackendPagesModel::delete($this->id, null, $revisionId); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id)); // delete search indexes BackendSearchModel::removeIndex($this->getModule(), $this->id); // build cache BackendPagesModel::buildCache(BL::getWorkingLanguage()); } // page is deleted, so redirect to the overview if ($success) { $this->redirect(BackendModel::createURLForAction('index') . '&id=' . $page['parent_id'] . '&report=deleted&var=' . urlencode($page['title'])); } else { $this->redirect(BackendModel::createURLForAction('edit') . '&error=non-existing'); } } else { $this->redirect(BackendModel::createURLForAction('edit') . '&error=non-existing'); } }
/** * Parse */ protected function parse() { parent::parse(); // set $this->record['url'] = $this->meta->getURL(); if ($this->id == 1) { $this->record['url'] = ''; } // parse some variables $this->tpl->assign('item', $this->record); $this->tpl->assign('isGod', $this->isGod); $this->tpl->assign('templates', $this->templates); $this->tpl->assign('positions', $this->positions); $this->tpl->assign('extrasData', json_encode(BackendExtensionsModel::getExtrasData())); $this->tpl->assign('extrasById', json_encode(BackendExtensionsModel::getExtras())); $this->tpl->assign('prefixURL', rtrim(BackendPagesModel::getFullURL($this->record['parent_id']), '/')); $this->tpl->assign('formErrors', (string) $this->frm->getErrors()); // init var $showDelete = true; // has children? if (BackendPagesModel::getFirstChildId($this->record['id']) !== false) { $showDelete = false; } if (!$this->record['delete_allowed']) { $showDelete = false; } // allowed? if (!BackendAuthentication::isAllowedAction('delete', $this->getModule())) { $showDelete = false; } // show delete button $this->tpl->assign('showPagesDelete', $showDelete); // assign template $this->tpl->assignArray($this->templates[$this->record['template_id']], 'template'); // parse datagrids $this->tpl->assign('revisions', $this->dgRevisions->getNumResults() != 0 ? $this->dgRevisions->getContent() : false); $this->tpl->assign('drafts', $this->dgDrafts->getNumResults() != 0 ? $this->dgDrafts->getContent() : false); // parse the tree $this->tpl->assign('tree', BackendPagesModel::getTreeHTML()); }