/** * Save page to database. * @param readPost Read values from post (default true). * @return ErrorLog object if there were errors. */ function savePage($readPost = true) { // Create ErrorLog object $errorLog = new ErrorLog(); // Check if user has edit permission if ($this->hasEditPermission()) { global $dbi, $log, $login, $revision; global $lEditPage; // Save old text for revision $oldText = ""; // Get values if ($readPost) { // Check submitter checkSubmitter(); // Get values $this->disableComments = getPostValue("disableComments"); $this->link = getPostValue("link"); $this->navbarTitle = getPostValue("navbarTitle"); $this->parent = new Page(getPostValue("parentId")); $this->separator = getPostValue("separator"); $this->showComments = getPostValue("showComments"); $this->showInMenu = getPostValue("showInMenu"); $this->showLastModified = getPostValue("showLastModified"); $oldText = $this->text; $this->text = parseHtml(getPostValue("text"), 4); $this->text = parseThumbnailImages($this->text); $this->title = getPostValue("title"); $lastUpdated = getPostValue("lastUpdated"); } else { $this->parent = new Page(0); } // Validate data if (empty($this->title)) { $errorLog->addError("title", $lEditPage["TitleMissing"]); } if (!empty($lastUpdated)) { if ($lastUpdated != $this->getLastUpdated()) { $errorLog->addError("pageModified", $lEditPage["PageModified"]); } } // If no errors save page if (!$errorLog->hasErrors()) { $exists = false; if (!empty($this->id)) { $result = $dbi->query("SELECT id FROM " . pageTableName . " WHERE id=" . $dbi->quote($this->id)); if ($result->rows()) { $exists = true; } } if ($exists) { // Update page in database $dbi->query("UPDATE " . pageTableName . " SET parentId=" . $dbi->quote($this->parent->id) . ",title=" . $dbi->quote($this->title) . ",text=" . $dbi->quote($this->text) . ",link=" . $dbi->quote($this->link) . ",navbarTitle=" . $dbi->quote($this->navbarTitle) . ",showInMenu=" . $dbi->quote($this->showInMenu) . ",showLastModified=" . $dbi->quote($this->showLastModified) . ",showComments=" . $dbi->quote($this->showComments) . ",disableComments=" . $dbi->quote($this->disableComments) . ",`separator`=" . $dbi->quote($this->separator) . " WHERE id=" . $dbi->quote($this->id)); } else { // Get position $result = $dbi->query("SELECT MAX(position) FROM " . pageTableName); if ($result->rows()) { list($position) = $result->fetchrow_array(); $position++; } else { $position = 0; } // Insert page into database $dbi->query("INSERT INTO " . pageTableName . "(" . (!empty($this->id) ? "id," : "") . "parentId,title,link,text,navbarTitle,showInMenu,showLastModified,showComments,disableComments,position,`separator`) VALUES(" . (!empty($this->id) ? $dbi->quote($this->id) . "," : "") . $dbi->quote($this->parent->id) . "," . $dbi->quote($this->title) . "," . $dbi->quote($this->link) . "," . $dbi->quote($this->text) . "," . $dbi->quote($this->navbarTitle) . "," . $dbi->quote($this->showInMenu) . "," . $dbi->quote($this->showLastModified) . "," . $dbi->quote($this->showComments) . "," . $dbi->quote($this->disableComments) . "," . ($position + 1) . "," . $dbi->quote($this->separator) . ")"); // Get new page id $this->id = $dbi->getInsertId(); // Set permissions for reading the page $login->setModuleContentPermissions(pageContentTypeId, $this->id, "Visitors", 0, 0, 1, 0, 0, 0, 0, 1); $login->setModuleContentPermissions(pageContentTypeId, $this->id, "Users", 0, 0, 1, 0, 0, 0, 0, 1); // Free result set $result->finish(); } // Log transaction $log->logTransaction(pageContentTypeId, $this->id); // Save page revision $revision->saveTextRevision(pageModuleId, pageContentTypeId, $this->id, $oldText, $this->text); // Delete cache $this->deleteCache(); } // Return errors if any return $errorLog; } }
/** * Save blog post. * @param $readPost Read values from post. * @return ErrorLog object if there were errors. */ function savePost($readPost = true) { global $category, $dbi, $log, $login; // Check if data is submitted from the form if ($readPost) { checkSubmitter(); } // Create ErrorLog object $errorLog = new ErrorLog(); // Get blog id and create blog object $this->blog = new Blog(getValue("blogId")); // Check if blog exists if (!empty($this->blog->id)) { if ($this->hasEditPermission()) { // Include language include scriptPath . "/" . folderBlog . "/include/language/" . $this->blog->language . "/general.php"; // Save if post was draft before $draftBefore = $this->draft; // Save blog post values if ($readPost) { $this->categories = explode(",", getPostValue("categories")); $this->disableComments = getPostValue("disableComments"); $this->draft = getPostValue("draft"); $this->showComments = getPostValue("showComments"); $this->subject = parseHtml(getPostValue("subject"), 1); $this->summary = parseThumbnailImages(parseHtml(getPostValue("summary"), 4)); $this->text = parseThumbnailImages(parseHtml(getPostValue("text"), 4)); $userId = getPostValue("userId"); // Get publication time $day = getPostValue("day"); $month = getPostValue("month"); $year = getPostValue("year"); $hour = getPostValue("hour"); $minute = getPostValue("minute"); // Process input if (!empty($day) && !empty($month) && !empty($year)) { $this->posted = mktime($hour, $minute, 0, $month, $day, $year); } if (!empty($userId)) { $this->user = new User($userId); } } // Validate post data if (empty($this->posted)) { $this->posted = mktime(); } if (empty($userId)) { $this->user = new User($login->id); } if (empty($this->subject)) { $errorLog->addError("subject", $lBlogEditPost["MissingSubject"]); } // Check if post has been modified $lastUpdated = getValue("lastUpdated"); if ($lastUpdated != $this->getLastUpdated()) { $errorLog->addError("postModified", $lBlogEditPost["PostModified"]); } // Prepare values for notification $subject = "[" . $this->blog->title . "] " . $this->subject; $message = "<p>" . $lBlogEditPost["NotifyInsert"] . " '" . $this->blog->title . "'.</p>" . "<p><b>" . $lBlogEditPost["Name"] . "</b></p><p>" . $login->name . "</p>" . "<p><b>" . $lBlogEditPost["Subject"] . "</b></p><p>" . $this->subject . "</p>" . "<p><b>" . $lBlogEditPost["Summary"] . "</b></p>" . parseString(!empty($this->summary) ? $this->summary : (!empty($this->text) ? $this->text : "")) . "<p>--<br />" . $lBlogEditPost["ReadPost"] . ": " . $this->getPostLink() . "<br />" . $lBlogEditPost["VisitBlog"] . ": " . $this->blog->getBlogLink() . "</p>"; $sender = $login->name; // If no errors proceed, otherwise return errors if (!$errorLog->hasErrors()) { if (empty($this->id)) { // Insert into database $dbi->query("INSERT INTO " . blogPostTableName . "(blogId,userId,subject,summary,text,posted,lastUpdated,showComments,disableComments,draft) VALUES(" . $dbi->quote($this->blog->id) . "," . $dbi->quote($this->user->id) . "," . $dbi->quote($this->subject) . "," . $dbi->quote($this->summary) . "," . $dbi->quote($this->text) . ",FROM_UNIXTIME(" . $dbi->quote($this->posted) . "),NOW()," . $dbi->quote($this->showComments) . "," . $dbi->quote($this->disableComments) . "," . $dbi->quote($this->draft) . ")"); // Get new post id $this->id = $dbi->getInsertId(); // Notify subscribers about the new post if (!$this->draft) { $this->notifySubscribers($sender, $subject, $message); } } else { // Update values in database $dbi->query("UPDATE " . blogPostTableName . " SET blogId=" . $dbi->quote($this->blog->id) . ",userId=" . $dbi->quote($this->user->id) . ",subject=" . $dbi->quote($this->subject) . ",summary=" . $dbi->quote($this->summary) . ",text=" . $dbi->quote($this->text) . ",posted=FROM_UNIXTIME(" . $dbi->quote($this->posted) . "),lastUpdated=lastUpdated,showComments=" . $dbi->quote($this->showComments) . ",disableComments=" . $dbi->quote($this->disableComments) . ",draft=" . $dbi->quote($this->draft) . " WHERE id=" . $dbi->quote($this->id)); // Notify subscribers if the post was a draft previously if (!$this->draft && $draftBefore) { $this->notifySubscribers($sender, $subject, $message); } } // Associate categories with this post $category->addCategoryReferences(blogModuleId, blogPostContentId, $this->id, $this->categories); // Log transaction $log->logTransaction(blogPostContentId, $this->id); // Delete cached files if (!empty($this->blog)) { $this->blog->deleteCache(); } } } } return $errorLog; }