/** Handle object */ function onObject($name, $id) { if (substr($name, 0, 14) !== 'content/posts/') { return false; } GBPost::parsePathspec($name, $date, $slug, $fnext); # date missing means malformed pathname if ($date === false) { throw new UnexpectedValueException('malformed post "' . $name . '" missing date prefix -- skipping'); return false; } # handle missing slug. content/posts/2009-01-22 => post if (!$slug) { $slug = 'post'; } # comment or post? if ($fnext === 'comments') { $obj = $this->_onComment($name, $id, GBPost::mkCachename($date, $slug)); } else { $obj = $this->_onObject(GBPost::findByDateAndSlug($date, $slug), 'GBPost', $name, $id, $slug); if (!$obj) { return false; } self::$posts[] = $obj; } if ($obj->published === null) { $obj->published = $date; } return true; }
function buildHeaderFields() { $header = parent::buildHeaderFields(); $header['wp-id'] = $this->wpid; if ($this->wpparent) { $header['wp-parent'] = $this->wpparent; } return $header; }
function _add_posts_from_status($st, $prefixmatch, $stage, $stageflag) { global $muxed_posts; if (isset($st[$stage])) { foreach ($st[$stage] as $name => $t) { if (substr($name, 0, strlen($prefixmatch)) !== $prefixmatch) { continue; } $status = is_array($t) ? $t['status'] : ''; $post = GBPost::findByName($name, $status === 'deleted' ? null : 'work', false); if ($post) { if (!isset($muxed_posts[$post->name])) { $muxed_posts[$post->name] = array(); } $muxed_posts[$post->name][] = array($post, $stageflag . _mkflags($post, $status)); } } } }
if (!$post->published) { $post->published = $post->modified; } $post->name = $post->recommendedName(); } else { gb::log('already exists (OK)'); } # was the state actually modified? if ($modified_state) { gb::log('write %s', r($modified_state)); # write to work area gb_admin::write_content($post); } # if the post was created, reload it to find appropriate values if ($created) { $post = GBPost::findByName($post->name, 'work'); $modified_state = array(); foreach ($state_fields as $k => $discard) { if ($k === 'body') { $modified_state[$k] = $post->rawBody(); } else { $v = $post->{$k}; if ($v instanceof GBDateTime) { $v = strval($v); } $modified_state[$k] = $v; } } } # commit? if ($input['commit']) {
$q['version'] = 'work'; } # load existing post if ($q['name']) { if (!($post = GBPost::findByName($q['name'], $q['version']))) { gb::$errors[] = 'No post could be found at path ' . r($q['name']); } } elseif ($q['uri']) { $q['uri'] = ltrim($q['uri'], '/'); if (!($post = GBPost::find($q['uri'], $q['version']))) { gb::$errors[] = 'No post could be found for URI ' . r($q['uri']); } } # no post found or new post if (!$post) { $post = new GBPost(); $post->published = new GBDateTime(); $post->author = gb::$authorized; $post->mimeType = $admin_conf->get('composing/default_mime_type', 'text/html'); } include '../_header.php'; ?> <script type="text/javascript" charset="utf-8">//<![CDATA[ var post = { savedState: {}, currentState: {}, isModified: false, checkStateTimer: null, checkStateInterval: 10000,
} else { # page if ($preview_pathspec !== null) { $post = GBPage::findByName($preview_pathspec, $version); } else { $post = GBPage::find(urldecode($gb_request_uri), $version); } if ($post === false) { gb::$is_404 = true; } else { gb::$title[] = $post->title; } gb::$is_page = true; } # post 404? if (isset($post) && $post && gb::$is_preview === false && ($post->draft === true || $post->published->time > time())) { gb::$is_404 = true; } } else { # posts $postspage = GBPost::pageByPageno(isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 0); gb::$is_posts = true; gb::$is_404 = $postspage === false; } # unset temporary variables (not polluting global namespace) unset($preview_pathspec); unset($strptime); unset($version); gb::event('will-handle-request'); # from here on, the caller will have to do the rest }