/** * Creates or updates an array of custom setting<br/> * Required permissions:<br/> * <ul> * <li>IS_AUTH</li> * <li>MANAGE_SETTINGS</li> * </ul> * @param array $values An array of objects containing a name and a value string * @return array An array of custom settings * @throws \Exception */ public function setSettings($values) { if (!$this->IS_AUTH) { throw $this->throwException(AuthenticationException::NO_USER_AUTH); } if (!$this->MANAGE_SETTINGS) { throw $this->throwException(3002); } foreach ($values as $val) { $oval = (object) $val; $this->setSetting($oval->name, $oval->value); unset($oval); } $cache = new Cache(); $cache->flushCache(); return $this->getSettings(); }
/** * Moves an existing page in the tree<br/> * Required permissions:<br/> * <ul> * <li>IS_AUTH</li> * </ul> * @param int $treeId The id of the page to move * @param int $oldParentId The id of the current parent * @param int $newParentId The id of the new parent * @param int $oldIndex The old index * @param int $newIndex The new index * @return array The children of the new parent * @throws \Exception */ public function movePage($treeId, $oldParentId, $newParentId, $oldIndex, $newIndex) { if (!$this->IS_AUTH) { throw $this->throwException(AuthenticationException::NO_USER_AUTH); } if (!is_numeric($treeId) || !is_numeric($oldParentId) || !is_numeric($newParentId) || !is_numeric($oldIndex) || !is_numeric($newIndex)) { throw $this->throwException(ParameterException::INTEGER_EXCEPTION); } // Check if the number of children doesn't exceed the maximum if ((int) $oldParentId != (int) $newParentId) { $sql = 'SELECT `maxchildren`, (SELECT COUNT(nct.`treeId`) ' . 'FROM `tree` nct ' . 'WHERE nct.parentId=' . $newParentId . ') ' . 'AS numchildren ' . 'FROM `itemtypes` ' . 'WHERE `itemId`=(SELECT `itemType` ' . 'FROM `page` p ' . 'WHERE p.`pageId`=(SELECT t.`pageId` ' . 'FROM `tree` t ' . 'WHERE `treeId`=' . $newParentId . '))'; $ncResult = $this->_conn->getRow($sql); if ((double) $ncResult->numchildren >= (double) $ncResult->maxchildren && (double) $ncResult->maxchildren > -1) { throw $this->throwException(6001, array($ncResult->maxchildren)); } } $retObj = new \stdClass(); $cache = new Cache(); // Check if the page exists in the new parent, //only if the newparent is actually another parent if ((int) $oldParentId != (int) $newParentId) { $sql = 'SELECT pageId FROM tree WHERE treeId = ' . $treeId; $page = $this->_conn->getRow($sql); if ($this->_checkForPageExistance($page->pageId, $newParentId)) { $retObj->oldParent = $this->getChildren($oldParentId); $retObj->newParent = $this->getChildren($newParentId); $cache->flushCache(); return $retObj; } } $this->_cleanIndexes($oldParentId); $this->_cleanIndexes($newParentId); $this->_updateIndexes($oldIndex, -1, $oldParentId); $this->_updateIndexes($newIndex, 1, $newParentId); $sql = 'UPDATE tree ' . 'SET `parentId`=' . $newParentId . ', ' . '`index`=' . $newIndex . ' ' . 'WHERE `treeId`=' . $treeId; $this->_conn->updateRow($sql); $cache->flushCache(); $this->generateSitemap(); $retObj->oldParent = $this->getChildren($oldParentId); $retObj->newParent = $this->getChildren($newParentId); return $retObj; }
/** * Updates a page * @param OPage page The page to update * @return OPage The updated page */ private function _updatePage($page) { $ap = $page->alwayspublished ? 1 : 0; $sn = $page->showinnavigation ? 1 : 0; $cachebleChanged = $this->_cachebleChanged($page); $page->label = Connection::getInstance()->escape_string($this->generateLabel($page->label, $page->pageId)); $page->modifiedby = isset($_SESSION['administratorId']) ? $_SESSION['administratorId'] : 0; BrightUtils::forceInt($page, array('publicationdate', 'expirationdate', 'itemType', 'pageId')); $sql = "UPDATE page \n\t\t\t\tSET label='{$page->label}',\n\t\t\t\titemType='{$page->itemType}', \n\t\t\t\tpublicationdate=FROM_UNIXTIME({$page->publicationdate}),\n\t\t\t\texpirationdate=FROM_UNIXTIME({$page->expirationdate}), \n\t\t\t\talwayspublished={$ap},\n\t\t\t\tshowinnavigation={$sn},\n\t\t\t\tmodificationdate=NOW(),\n\t\t\t\tmodifiedby={$page->modifiedby}\n\t\t\t\tWHERE pageId={$page->pageId}"; $this->conn->updateRow($sql); $this->setContent($page); if ($cachebleChanged) { // Flush cache $cache = new Cache(); $cache->flushCache(); $tree = new Tree(); $tree->generateSitemap(); } return $this->getPageById($page->pageId, true); }
/** * Inserts content into the database * @param OPage $page * @param string $table * @return int * @throws ParameterException */ protected function setContent($page, $table = 'content') { $pid = 'pageId'; switch ($table) { case 'content': $pid = 'pageId'; break; case 'userfields': $pid = 'userId'; break; case 'calendarcontent': $pid = 'calendarId'; break; } $id = (int) $page->{$pid}; $table = Connection::getInstance()->escape_string($table); $b = new Backup(); $b->setBackup($page, $table); if (!isset($page->content) || $page->content == null) { throw new ParameterException(ParameterException::OBJECT_EXCEPTION); } $sql = "UPDATE `{$table}` SET `deleted`=1 WHERE `{$pid}`={$id}"; $this->conn->updateRow($sql); $it = new Template(); $def = $it->getTemplateDefinition($page->itemType, true); $def->title = new \stdClass(); $def->title->contenttype = 'string'; $def->title->searchable = 1; $sql = "INSERT INTO `{$table}` (`{$pid}`, `lang`, `field`, `value`,`index`,`searchable`) VALUES "; $sqla = array(); foreach ($page->content as $field => $langs) { $searchable = 0; if ($field == 'title') { $searchable = 1; if ($table == 'content' && $this->_titleChanged($langs, $page->{$pid})) { $cache = new Cache(); $cache->flushCache(); } } else { $searchable = isset($def->{$field}) && $def->{$field}->searchable ? 1 : 0; } foreach ($langs as $lang => $val) { // 20130725 Fix for unknown fields $contenttype = isset($def->{$field}) && isset($def->{$field}->contenttype) ? $def->{$field}->contenttype : 'string'; switch ($contenttype) { case 'array': $index = 0; if (!is_array($val)) { $val = array($val); } foreach ($val as $listval) { $lang = BrightUtils::escapeSingle($lang); $field = BrightUtils::escapeSingle($field); if (!is_string($listval)) { //throw $this -> throwException(Exceptions::INCORRECT_PARAM_STRING, '$listval: ' . print_r($listval, true)); $listval = json_encode($listval); } $listval = BrightUtils::escapeHtml($listval); $sqlid = $page->{$pid}; $sqla[] = "({$sqlid},\n\t\t\t\t\t\t\t\t\t\t'{$lang}',\n\t\t\t\t\t\t\t\t\t\t'{$field}',\n\t\t\t\t\t\t\t\t\t\t'{$listval}', {$index}, {$searchable}) "; $index++; } break; default: $lang = BrightUtils::escapeSingle($lang); $field = BrightUtils::escapeSingle($field); if ($val !== null && $val !== false && !is_scalar($val)) { $val = json_encode($val); if ($val == '{}') { $val = ''; } //throw $this -> throwException(Exceptions::INCORRECT_PARAM_STRING, 'val: ' . print_r($val, true)); } $val = BrightUtils::escapeHtml($val); if ($val != '') { $sqlid = $page->{$pid}; $sqla[] = "({$sqlid},\n\t\t\t\t\t\t\t\t\t\t'{$lang}',\n\t\t\t\t\t\t\t\t\t\t'{$field}',\n\t\t\t\t\t\t\t\t\t\t'{$val}', 0, {$searchable}) "; } } } } if (count($sqla) > 0) { $sql .= implode(", \r\n", $sqla); $sql .= " ON DUPLICATE KEY UPDATE `value`=VALUES(`value`), `deleted`=0"; $result = $this->conn->insertRow($sql); } else { // Delete old content? uncomment line // $result = 1; } if ($result !== false && $result > 0) { // All is well, clean up old data $sql = "DELETE FROM `{$table}` WHERE `deleted`= 1 AND `{$pid}`={$id}"; $this->conn->deleteRow($sql); } return $result; }