Exemplo n.º 1
0
 /** 
  * Save category in database. 
  * @return ErrorLog containing errors if any. 
  */
 function saveCategory()
 {
     // Initialize ErrorLog object
     $errors = new ErrorLog();
     // Check if user has edit permission
     if ($this->hasEditPermission()) {
         global $dbi, $log;
         global $lCategoryEdit;
         // Check if data is submitted from the form
         checkSubmitter(scriptUrl);
         // Save values
         $this->title = getValue("title");
         $this->description = getValue("description");
         // Validate data
         if (empty($this->title)) {
             $errors->addError("title", $lCategoryEdit["MissingTitle"]);
         } else {
             if (empty($this->id)) {
                 $category = new Category("", $this->title);
                 if (!empty($category->id)) {
                     $errors->addError("title", $lCategoryEdit["CategoryExists"]);
                 }
             }
         }
         if (!$errors->hasErrors()) {
             if (!empty($this->id)) {
                 // Update category in database
                 $dbi->query("UPDATE " . categoryTableName . " SET title=" . $dbi->quote($this->title) . ",description=" . $dbi->quote($this->description) . " WHERE (id=" . $dbi->quote($this->id) . ")");
             } else {
                 // Insert category into database
                 $dbi->query("INSERT INTO " . categoryTableName . "(title,description) VALUES(" . $dbi->quote($this->title) . "," . $dbi->quote($this->description) . ")");
                 // Get insert id
                 $this->id = $dbi->getInsertId();
             }
             // Log transaction
             $log->logTransaction(categoryContentTypeId, $this->id);
         }
     }
     return $errors;
 }
Exemplo n.º 2
0
 /** 
  * Save blog in database. 
  * @param	$readPost	Read values from post.
  * @return ErrorLog if there were errors.
  */
 function saveBlog($readPost = true)
 {
     // Create ErrorLog object
     $errorLog = new ErrorLog();
     if ($this->hasAdministerPermission()) {
         global $dbi, $log, $login, $module;
         // Check if data is submitted from the form
         checkSubmitter();
         // Include language
         include scriptPath . "/include/language/" . pageLanguage . "/general.php";
         include scriptPath . "/" . folderBlog . "/include/language/" . $this->language . "/general.php";
         // Save values from post
         if ($readPost) {
             $this->category = parseHtml(getPostValue("category"), 0);
             $this->description = parseHtml(getPostValue("description"), 1);
             $this->language = getPostValue("language");
             $this->postLimit = getPostValue("postLimit");
             $this->showRSSLink = getPostValue("showRSSLink");
             $this->showRSSCommentsLink = getPostValue("showRSSCommentsLink");
             $this->subscribers = parseHtml(getPostValue("subscribers"), 0);
             $this->title = parseHtml(getPostValue("title"), 0);
         }
         // Validate data
         if (empty($this->language)) {
             $this->language = pageDefaultLanguage;
         }
         if (empty($this->title)) {
             $errorLog->addError("title", $lBlogEdit["MissingTitle"]);
         } else {
             if (empty($this->id)) {
                 $blog = new Blog("", $this->title);
                 if (!empty($blog->id)) {
                     $errorLog->addError("title", $lBlogEdit["BlogExists"]);
                 }
             }
         }
         // If there were no errors update database
         if (!$errorLog->hasErrors()) {
             if (empty($this->id)) {
                 // Get max position
                 $result = $dbi->query("SELECT MAX(position) FROM " . blogTableName);
                 if ($result->rows()) {
                     list($position) = $result->fetchrow_array();
                     $position++;
                 } else {
                     $position = 0;
                 }
                 // Insert blog into database
                 $dbi->query("INSERT INTO " . blogTableName . "(title,category,description,subscribers,language,postLimit,showRSSLink,showRSSCommentsLink,position) VALUES(" . $dbi->quote($this->title) . "," . $dbi->quote($this->category) . "," . $dbi->quote($this->description) . "," . $dbi->quote($this->subscribers) . "," . $dbi->quote($this->language) . "," . $dbi->quote($this->postLimit) . "," . $dbi->quote($this->showRSSLink) . "," . $dbi->quote($this->showRSSCommentsLink) . "," . $dbi->quote($position) . ")");
                 // Get new blog id
                 $this->id = $dbi->getInsertId();
                 // Set default permissions
                 $login->setModuleContentPermissions(blogContentId, $this->id, "Visitors", 0, 0, 1, 0, 0, 0, 0, 1);
                 $login->setModuleContentPermissions(blogContentId, $this->id, "Users", 0, 0, 1, 0, 0, 0, 0, 1);
             } else {
                 // Update blog in database
                 $dbi->query("UPDATE " . blogTableName . " SET title=" . $dbi->quote($this->title) . ",category=" . $dbi->quote($this->category) . ",description=" . $dbi->quote($this->description) . ",subscribers=" . $dbi->quote($this->subscribers) . ",language=" . $dbi->quote($this->language) . ",postLimit=" . $dbi->quote($this->postLimit) . ",showRSSLink=" . $dbi->quote($this->showRSSLink) . ",showRSSCommentsLink=" . $dbi->quote($this->showRSSCommentsLink) . " WHERE id=" . $dbi->quote($this->id));
             }
             // Upload index picture
             if (!empty($_FILES["img_0"])) {
                 uploadFile($_FILES["img_0"], "blog_" . $this->id, array("image/jpeg", "image/pjpeg", "image/gif"), 0, 50, 50);
             }
             // Log transaction
             $log->logTransaction(blogContentId, $this->id);
         } else {
             if (!empty($_FILES["img_0"]["tmp_name"])) {
                 $errorLog->addError("upload", $lErrors["ReUploadImages"]);
             }
         }
     }
     return $errorLog;
 }
Exemplo n.º 3
0
 /** 
  * Save settings.
  * @param	$readPost	Read values from post.
  * @return ErrorLog object if there were errors.
  */
 function saveSettings($readPost = true)
 {
     global $dbi, $login;
     global $lSettings;
     // Check if data is submitted from the form
     checkSubmitter();
     // Get values
     if ($readPost) {
         $this->activateWithEmail = getPostValue("activateWithEmail");
         $this->adminMail = getPostValue("adminMail");
         $this->allowUserRegistration = getPostValue("allowUserRegistration");
         $this->cacheSize = getPostValue("cacheSize");
         $this->commentBlacklist = getPostValue("commentBlacklist");
         $this->commentsRequireValidation = getPostValue("commentsRequireValidation");
         $this->defaultPage = getPostValue("defaultPage");
         $this->defaultUploadFolder = getPostValue("defaultUploadFolder");
         $this->description = getPostValue("description");
         $this->enableCaching = getPostValue("enableCaching");
         $this->enableRevisioning = getPostValue("enableRevisioning");
         $this->iconTheme = getPostValue("iconTheme");
         $this->keywords = getPostValue("keywords");
         $this->language = getPostValue("language");
         $this->linkType = getPostValue("linkType");
         $this->maxNoOfLinksInComments = getPostValue("maxNoOfLinksInComments");
         $this->requireValidation = getPostValue("requireValidation");
         $this->showDirectLink = getPostValue("showDirectLink");
         $this->showPrinterLink = getPostValue("showPrinterLink");
         $this->showRecommendLink = getPostValue("showRecommendLink");
         $this->subtheme = getPostValue("subtheme");
         $this->theme = getPostValue("theme");
         $this->themeHeaderUrl = getPostValue("themeHeaderUrl");
         $this->themeWidth = getPostValue("themeWidth");
         $this->title = getPostValue("title");
     }
     // Create ErrorLog object
     $errorLog = new ErrorLog();
     // Validate data
     if (empty($this->title)) {
         $errorLog->addError("title", $lSettings["MissingTitle"]);
     }
     if (empty($this->adminMail)) {
         $errorLog->addError("adminMail", $lSettings["MissingAdminMail"]);
     } else {
         if (!checkEmail($this->adminMail)) {
             $errorLog->addError("adminMail", $lSettings["InvalidAdminMail"]);
         }
     }
     // Update database
     if (!$errorLog->hasErrors()) {
         // Check that row exists
         $result = $dbi->query("SELECT id FROM " . settingsTableName);
         if (!$result->rows()) {
             $dbi->query("INSERT INTO " . settingsTableName . "(title) VALUES(" . $dbi->quote($this->title) . ")");
         }
         // Update settings
         $dbi->query("UPDATE " . settingsTableName . " SET " . "activateWithEmail=" . $dbi->quote($this->activateWithEmail) . "," . "adminMail=" . $dbi->quote($this->adminMail) . "," . "allowUserRegistration=" . $dbi->quote($this->allowUserRegistration) . "," . "cacheSize=" . $dbi->quote($this->cacheSize) . "," . "commentBlacklist=" . $dbi->quote($this->commentBlacklist) . "," . "commentsRequireValidation=" . $dbi->quote($this->commentsRequireValidation) . "," . "defaultPage=" . $dbi->quote($this->defaultPage) . "," . "description=" . $dbi->quote($this->description) . "," . "enableCaching=" . $dbi->quote($this->enableCaching) . "," . "enableRevisioning=" . $dbi->quote($this->enableRevisioning) . "," . "iconTheme=" . $dbi->quote($this->iconTheme) . "," . "keywords=" . $dbi->quote($this->keywords) . "," . "language=" . $dbi->quote($this->language) . "," . "linkType=" . $dbi->quote($this->linkType) . "," . "maxNoOfLinksInComments=" . $dbi->quote($this->maxNoOfLinksInComments) . "," . "requireValidation=" . $dbi->quote($this->requireValidation) . "," . "showDirectLink=" . $dbi->quote($this->showDirectLink) . "," . "showPrinterLink=" . $dbi->quote($this->showPrinterLink) . "," . "showRecommendLink=" . $dbi->quote($this->showRecommendLink) . "," . "subtheme=" . $dbi->quote($this->subtheme) . "," . "theme=" . $dbi->quote($this->theme) . "," . "themeWidth=" . $dbi->quote($this->themeWidth) . "," . "themeHeaderUrl=" . $dbi->quote($this->themeHeaderUrl) . "," . "title=" . $dbi->quote($this->title));
     }
     // Return errors if any
     return $errorLog;
 }
Exemplo n.º 4
0
 /** 
  * 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;
     }
 }
Exemplo n.º 5
0
 /** 
  * 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;
 }