/** * Adds a comment to an article * * @param comment the UserComment object that we're going to add. * @return Returns true if successful or false if error. Also in case of success, it will modify the UserComment * object passed by reference and include its new id. */ function addComment(&$comment) { $filter = new Textfilter(); $t = new Timestamp(); $timeStamp = $t->getTimestamp(); $query = "INSERT INTO " . $this->getPrefix() . "articles_comments (article_id,topic,text,user_name,user_email,\n\t\t\t\t\t user_url,parent_id,client_ip,status,date,normalized_text,normalized_topic) \n\t\t\t\t\t VALUES (" . $comment->getArticleId() . ",'" . Db::qstr($comment->getTopic()) . "','" . Db::qstr($comment->getText()) . "','" . Db::qstr($comment->getUserName()) . "','" . Db::qstr($comment->getUserEmail()) . "','" . Db::qstr($comment->getUserUrl()) . "'," . $comment->getParentId() . ", '" . $comment->getClientIp() . "', " . $comment->getStatus() . "," . $timeStamp . ",'" . Db::qstr($filter->normalizeText($comment->getText())) . "', '" . Db::qstr($filter->normalizeText($comment->getTopic())) . "');"; $result = $this->Execute($query); if (!$result) { return false; } // retrieve the last id and save it in the object $comment->setId($this->_db->Insert_ID()); return true; }
/** * adds a custom field value to the given article * * @param fieldId * @param fieldValue * @param articleId * @param blogId * @return True if successful or false otherwise */ function addCustomFieldValue($fieldId, $fieldValue, $articleId, $blogId) { $filter = new Textfilter(); $query = "INSERT INTO " . $this->getPrefix() . "custom_fields_values\n\t\t\t (field_id, field_value, normalized_value, blog_id, article_id)\n\t\t\t\t\t VALUES (\n\t\t\t\t\t {$fieldId}, '" . Db::qstr($fieldValue) . "','" . $filter->normalizeText(Db::qstr($fieldValue)) . "',\n\t\t\t\t\t {$blogId}, {$articleId}\n\t\t\t\t\t )"; $result = $this->Execute($query); return $result; }
/** * Adds an album to the database * * @param album A GalleryAlbum object, with all its data filled in * @return Returns true if successful or false otherwise. * @see GAlleryAlbum */ function addAlbum($album) { $tf = new Textfilter(); $query = "INSERT INTO " . $this->getPrefix() . "gallery_albums (\n owner_id, description, name, flags, parent_id, properties, \n show_album, normalized_name, normalized_description, mangled_name )\n VALUES (" . $album->getOwnerId() . ", '" . Db::qstr($album->getDescription()) . "', '" . Db::qstr($album->getName()) . "', 0, " . $album->getParentId() . ", '" . serialize($album->getProperties()) . "', " . $album->getShowAlbum() . " ,'" . Db::qstr($tf->normalizeText($album->getName())) . "','" . Db::qstr($tf->normalizeText($album->getDescription())) . "', '" . $tf->urlize($album->getName()) . "');"; $result = $this->Execute($query); if (!$result) { return false; } // return the id of the last row we inserted, which will be the id of the album $result = $this->_db->Insert_ID(); return $result; }
/** * updates the text of an article * * @param article an Article object * @return true if successful or false otherwise */ function updateArticleText($article) { $filter = new Textfilter(); $query = "UPDATE " . $this->getPrefix() . "articles_text SET \n topic = '" . Db::qstr($article->getTopic()) . "'" . ", text = '" . Db::qstr($article->getText(false)) . "'" . ", normalized_text = '" . $filter->normalizeText(Db::qstr($article->getText(false))) . "'" . ", normalized_topic = '" . $filter->normalizeText(Db::qstr($article->getTopic())) . "'" . " WHERE article_id = " . $article->getId() . ";"; return $this->Execute($query); }
/** * Adds a row related to a resource to the database. You should usually use * GalleryResources::addResource() or GalleryResources::addResourceFromDisk(), which are more * suitable and will do most of the job for you. * * @param ownerId * @param albumId * @param description * @param flags * @param resourceType * @param filePath * @param fileName * @param metadata * @return a valid resource id or false otherwise * @see addResource */ function addResourceToDatabase($ownerId, $albumId, $description, $flags, $resourceType, $filePath, $fileName, $metadata) { // prepare the metadata to be stored in the db $serMetadata = Db::qstr(serialize($metadata)); // get the correct thumbnail format $config =& Config::getConfig(); $thumbnailFormat = $config->getValue("thumbnail_format"); // prepare some other stuff $tf = new Textfilter(); $normalizedDescription = $tf->normalizeText($description); // finally put the query together and execute it $query = "INSERT INTO " . $this->getPrefix() . "gallery_resources(\n\t\t\t\t\t\t owner_id, album_id, description, flags, resource_type,\n\t\t\t\t\t\t file_path, file_name, metadata, thumbnail_format, normalized_description) VALUES (\n\t\t\t\t\t\t {$ownerId}, {$albumId}, '" . Db::qstr($description) . "', {$flags}, {$resourceType},\n\t\t\t\t\t\t '{$filePath}', '{$fileName}', '{$serMetadata}', '{$thumbnailFormat}',\n\t\t\t\t '" . Db::qstr($normalizedDescription) . "');"; $result = $this->Execute($query); // check the return result if (!$result) { return GALLERY_ERROR_ADDING_RESOURCE; } // get the id that was given to the record $resourceId = $this->_db->Insert_ID(); // check if we have two resources with the same filename now // check if there already exists a file with the same name // // if that's the case, then we should rename the one we just // added with some random prefix, to make it different from the // other one... if ($this->isDuplicatedFilename($fileName)) { $query = "UPDATE " . $this->getPrefix() . "gallery_resources\n\t\t\t\t\t\t SET file_name = '{$resourceId}-{$fileName}'\n\t\t\t\t\t\t WHERE id = {$resourceId}"; $this->Execute($query); } return $resourceId; }