findByName() static public method

static public findByName ( $name, $version = null, $applyBodyFilters = true )
Exemplo n.º 1
0
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));
            }
        }
    }
}
Exemplo n.º 2
0
     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']) {
Exemplo n.º 3
0
gb::authenticate();
gb::$title[] = 'New post';
# array( string name => filterspec , .. )
$fields = array('name' => FILTER_REQUIRE_SCALAR, 'uri' => FILTER_REQUIRE_SCALAR, 'version' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH));
if (($q = filter_input_array(INPUT_GET, $fields)) === null) {
    $q = array_fill_keys(array_keys($fields), null);
}
$post = false;
$body = '';
# default version
if ($q['version'] === null) {
    $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');
}
Exemplo n.º 4
0
     $postspage = GBExposedContent::findByTags($tags, isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 0);
     gb::$is_tags = true;
     gb::$is_404 = $postspage === false;
 } elseif (strpos($gb_request_uri, gb::$feed_prefix) === 0) {
     # feed
     $postspage = GBPost::pageByPageno(0);
     gb::$is_feed = true;
     gb::event('will-handle-request');
     # if we got this far it means no event observers took over this task, so
     # we run the built-in feed (Atom) code:
     require gb::$dir . '/helpers/feed.php';
     exit;
 } elseif (gb::$posts_prefix === '' || ($strptime = strptime($gb_request_uri, gb::$posts_prefix)) !== false) {
     # post
     if ($preview_pathspec !== null) {
         $post = GBPost::findByName($preview_pathspec, $version);
     } else {
         $post = GBPost::find(urldecode($gb_request_uri), $version, $strptime);
     }
     if ($post === false) {
         gb::$is_404 = true;
     } else {
         gb::$title[] = $post->title;
     }
     gb::$is_post = true;
     # empty prefix and 404 -- try page
     if (gb::$is_404 === true && gb::$posts_prefix === '') {
         if ($preview_pathspec !== null) {
             $post = GBPage::findByName($preview_pathspec, $version);
         } else {
             $post = GBPage::find(urldecode($gb_request_uri), $version);