상속: extends GBContent
예제 #1
0
 function writeComments(GBExposedContent $obj)
 {
     if (!$obj->comments) {
         return;
     }
     # sort
     ksort($obj->comments);
     # init comments db
     $cdb = $obj->getCommentsDB();
     $cdb->autocommitToRepo = false;
     $cdb->begin(true);
     try {
         foreach ($obj->comments as $comment) {
             $cdb->append($comment);
         }
     } catch (Exception $e) {
         $cdb->rollback();
         throw $e;
     }
     $cdb->commit();
     git::add($cdb->file);
 }
예제 #2
0
    if (!$input[$field]) {
        $fields_missing[] = $field;
    }
}
if ($fields_missing) {
    exit2('missing parameter(s): ' . implode(', ', $fields_missing));
}
# sanitize $input['object']
$input['object'] = trim(str_replace('..', '', $input['object']), '/');
if (strpos($input['object'], 'content/') !== 0) {
    exit2('malformed parameter "object"');
}
# sanitize $input['comment']
$input['comment'] = preg_replace('/[^0-9\\.]+/', '', $input['comment']);
# look up post/page
$post = GBExposedContent::findByCacheName($input['object'] . gb::$content_cache_fnext);
# verify existing content and that comments are enabled
if (!$post) {
    exit2('no such object ' . $input['object']);
}
# remove from comment db
try {
    $cdb = $post->getCommentsDB();
    $removed_comment = $cdb->remove($input['comment']);
    $referrer = gb::referrer_url();
    # comment not found
    if (!$removed_comment) {
        if ($referrer) {
            $referrer['gb-error'] = 'Comment ' . $input['comment'] . ' not found';
            header('HTTP/1.1 303 See Other');
            header('Location: ' . $referrer);
예제 #3
0
파일: gitblog.php 프로젝트: rsms/gitblog
 static function find($uri_path_or_slug, $version = null, $strptime = null, $applyBodyFilters = true)
 {
     $version = self::parseVersion($version);
     $path = false;
     if (strpos($uri_path_or_slug, 'content/posts/') !== false) {
         $path = $uri_path_or_slug;
         if ($path[0] !== '/') {
             $path = gb::$site_dir . '/' . $path;
         }
     }
     if ($version === 'work') {
         # find path to raw content
         if ((!$path || !is_file($path)) && ($path = self::pathToWork($uri_path_or_slug, $strptime)) === null) {
             return false;
         }
         # parse pathspec, producing date and actual slug needed to look up cached
         try {
             self::parsePathspec(self::pathspecFromAbsPath($path), $date, $slug, $fnext);
         } catch (UnexpectedValueException $e) {
             return null;
         }
         # try to find a cached version
         $post = self::findByDateAndSlug($date, $slug);
         # load work
         return self::loadWork($path, $post, 'GBPost', $version, $slug, $applyBodyFilters);
     } elseif ($version === null) {
         if ($path) {
             self::parsePathspec(self::pathspecFromAbsPath($path), $date, $slug, $fnext);
             return self::findByDateAndSlug($date, $slug);
         }
         $path = self::pathToCached($uri_path_or_slug, $strptime);
         $data = @file_get_contents($path);
         if ($data === false && gb::$posts_fuzzy_lookup === true) {
             # exact match failed -- try fuzzy matching using glob and our knowledge of patterns
             list($prefix, $suffix) = self::cachenameFromURI($uri_path_or_slug, $strptime, true);
             $path = strtr($prefix, array('/' => '{/,*,.}', '-' => '{/,*,.}', '.' => '{/,*,.}')) . '*' . $suffix;
             $path = GBExposedContent::pathToCached('posts', $path . gb::$content_cache_fnext);
             # try any file with the cachename as prefix
             if ($path = gb::glob($path)) {
                 $data = @file_get_contents($path);
                 /*
                 Send premanent redirect if we found a valid article.
                  
                 Discussion: This is where things might go really wrong -- imagine we did find an 
                             article on fuzzy matching but it's _another_ article. Fail. But that
                             case is almost negligible since we only expand the time prefix, not
                             the slug.
                 */
                 global $gb_handle_request;
                 if ($data !== false && isset($gb_handle_request) && $gb_handle_request === true && ($post = unserialize($data)) && headers_sent() === false) {
                     header('HTTP/1.1 301 Moved Permanently');
                     header('Location: ' . $post->url());
                     exit('Moved to <a href="' . h($post->url()) . '">' . h($post->url()) . '</a>');
                 }
             }
         }
         return $data === false ? false : unserialize($data);
     }
     throw new Exception('arbitrary version retrieval not yet implemented');
 }