/** * Initialize Post object. * @param $id Post identifier. * @param $subject Post subject. */ function init($id = 0, $subject = "") { // Get blogId parameter $blogId = getValue("blogId"); // Create Blog object $this->blog = new Blog(); // Create User object $this->user = new User(); if (!empty($id) || !empty($subject)) { global $dbi; // Get post data $result = $dbi->query("SELECT id,blogId,categoryId,categoryId2,userId,subject,summary,text,UNIX_TIMESTAMP(posted),UNIX_TIMESTAMP(lastUpdated),disableComments,showComments,draft FROM " . blogPostTableName . " WHERE " . (!empty($id) ? "id=" . $dbi->quote($id) : "") . (!empty($subject) ? (!empty($id) ? " OR " : "") . "subject=" . $dbi->quote($subject) : "") . " ORDER BY posted DESC"); if ($result->rows()) { list($this->id, $blogId, $categoryId1, $categoryId2, $userId, $this->subject, $this->summary, $this->text, $this->posted, $this->lastUpdated, $this->disableComments, $this->showComments, $this->draft) = $result->fetchrow_array(); $this->subject = parseString($this->subject); $this->summary = parseString($this->summary); $this->text = parseString($this->text); // Create blog object $this->blog->init($blogId); // Create user object $this->user->init($userId); // Update old categories (<0.5) to new format if (!empty($categoryId1)) { $category = new Category($categoryId1); $category->addCategoryReference(blogModuleId, blogPostContentId, $this->id, $categoryId1, sizeof($this->categories)); $dbi->query("UPDATE " . blogPostTableName . " SET categoryId=0,posted=posted,lastUpdated=lastUpdated WHERE id=" . $dbi->quote($this->id)); } if (!empty($categoryId2)) { $category = new Category($categoryId2); $category->addCategoryReference(blogModuleId, blogPostContentId, $this->id, $categoryId2, sizeof($this->categories)); $dbi->query("UPDATE " . blogPostTableName . " SET categoryId2=0,posted=posted,lastUpdated=lastUpdated WHERE id=" . $dbi->quote($this->id)); } // Get categories for this post $numberOfCategories = 0; $result2 = $dbi->query("SELECT c1.title,c2.categoryId,c2.position FROM " . categoryTableName . " as c1," . categoryContentRefTableName . " as c2 WHERE c1.id=c2.categoryId AND c2.moduleId=" . $dbi->quote(blogModuleId) . " AND c2.moduleContentTypeId=" . $dbi->quote(blogPostContentId) . " AND c2.moduleContentId=" . $dbi->quote($this->id)); if ($result2->rows()) { for ($i = 0; list($categoryTitle, $categoryId, $categoryPosition) = $result2->fetchrow_array(); $i++) { $this->categories[$i][0] = $categoryPosition; $this->categories[$i][1] = stripslashes($categoryTitle); $this->categories[$i][2] = $categoryId; } $numberOfCategories = $result2->rows(); } // Sort by position sort($this->categories); // Convert old <img> tags for summary (CMIS 0.1-0.2) for ($i = 1; $i <= 4; $i++) { // Replace img-tags with html-tags if (file_exists(scriptPath . "/" . folderUploadedFiles . "/blog/img_" . $this->blog->id . "_" . $this->id . "_{$i}.jpg")) { $size = GetImageSize(scriptPath . "/" . folderUploadedFiles . "/blog/img_" . $this->blog->id . "_" . $this->id . "_{$i}.jpg"); $this->summary = preg_replace("/\\<img{$i}\\>(.*?)\\<\\/img{$i}\\>/si", "<img name=\"img{$i}\" src=\"" . scriptUrl . "/" . folderUploadedFiles . "/blog/img_" . $this->blog->id . "_" . $this->id . "_{$i}.jpg\" {$size['3']} border=\"0\" alt=\"\$1\" title=\"\$1\" />", $this->summary); $this->text = preg_replace("/\\<img{$i}\\>(.*?)\\<\\/img{$i}\\>/si", "<img name=\"img{$i}\" src=\"" . scriptUrl . "/" . folderUploadedFiles . "/blog/img_" . $this->blog->id . "_" . $this->id . "_{$i}.jpg\" {$size['3']} border=\"0\" alt=\"\$1\" title=\"\$1\" />", $this->text); } } // Free resultset $result->finish(); $result2->finish(); } } else { if (!empty($blogId)) { global $login; // Create blog object $this->blog->init($blogId); // Set posted to now $this->posted = mktime(); // Set user to this user $this->user->init($login->id); } } }