function add() { if ($this->id != 0) { $this->id = null; } if (isset($this->parent) && !is_numeric($this->parent)) { return $this->_error('parent'); } $this->name = Utils_Unicode::lessenAsEncoding(trim($this->name), 127); if (empty($this->name)) { return $this->_error('name'); } $query = DBModel::getInstance(); $query->reset('Categories'); $query->setQualifier('blogid', 'equals', getBlogId()); if (isset($this->parent)) { if (is_null($parentLabel = Category::getLabel($this->parent))) { return $this->_error('parent'); } $query->setQualifier('parent', 'equals', $this->parent); $query->setAttribute('label', Utils_Unicode::lessenAsEncoding($parentLabel . '/' . $this->name, 255), true); } else { $query->setQualifier('parent', null); $query->setAttribute('label', $this->name, true); } $query->setQualifier('name', 'equals', $this->name, true); if (isset($this->priority)) { if (!is_numeric($this->priority)) { return $this->_error('priority'); } $query->setAttribute('priority', $this->priority); } if ($query->doesExist()) { $this->id = $query->getCell('id'); if ($query->update()) { return true; } else { return $this->_error('update'); } } if (!isset($this->id)) { $this->id = $this->getNextCategoryId(); $query->setQualifier('id', 'equals', $this->id); } if (!$query->insert()) { return $this->_error('insert'); } return true; }
} $post = new Post(); if ($post->open('', '*', 'published, id')) { do { $writer->write('<post slogan="' . htmlspecialchars($post->slogan) . '"' . $newlineStyle . '>' . '<id>' . $post->id . '</id>'); if ($post->visibility == 'appointed') { // for backward compatibility $writer->write('<appointed>true</appointed>'); $writer->write('<visibility>private</visibility>'); } else { $writer->write('<appointed>false</appointed>'); $writer->write('<visibility>' . $post->visibility . '</visibility>'); } $writer->write('<starred>' . $post->starred . '</starred>' . '<title>' . htmlspecialchars($post->title) . '</title>' . '<content formatter="' . htmlspecialchars($post->contentformatter) . '" editor="' . htmlspecialchars($post->contenteditor) . '">' . htmlspecialchars(Utils_Unicode::correct($post->content)) . '</content>' . '<location>' . htmlspecialchars($post->location) . '</location>' . (!is_null($post->password) ? '<password>' . htmlspecialchars($post->password) . '</password>' : '') . '<acceptComment>' . $post->acceptcomment . '</acceptComment>' . '<acceptTrackback>' . $post->accepttrackback . '</acceptTrackback>' . '<published>' . $post->published . '</published>' . '<created>' . $post->created . '</created>' . '<modified>' . $post->modified . '</modified>' . '<longitude>' . $post->longitude . '</longitude>' . '<latitude>' . $post->latitude . '</latitude>'); if ($post->category) { $writer->write('<category>' . htmlspecialchars(Category::getLabel($post->category)) . '</category>'); } if ($post->loadTags()) { foreach ($post->tags as $tag) { $writer->write('<tag>' . htmlspecialchars($tag) . '</tag>'); } } $writer->write(CRLF); if ($attachment = $post->getAttachments()) { do { $writer->write('<attachment' . ' mime="' . htmlspecialchars($attachment->mime) . '"' . ' size="' . $attachment->size . '"' . ' width="' . $attachment->width . '"' . ' height="' . $attachment->height . '"' . '>' . '<name>' . htmlspecialchars($attachment->name) . '</name>' . '<label>' . htmlspecialchars($attachment->label) . '</label>' . '<enclosure>' . ($attachment->enclosure ? 1 : 0) . '</enclosure>' . '<attached>' . $attachment->attached . '</attached>' . '<downloads>' . $attachment->downloads . '</downloads>'); if ($includeFileContents && file_exists(__TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/{$attachment->name}")) { $writer->write('<content>'); Base64Stream::encode(__TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/{$attachment->name}", $writer); $writer->write('</content>'); }