event() 정적인 공개 메소드

Dispatch an event, optionally with arguments.
static public event ( )
예제 #1
0
    $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);
        } else {
            header('HTTP/1.1 404 Not Found');
        }
        exit('no such comment ' . $input['comment']);
    }
    gb::log(LOG_NOTICE, 'removed comment %s by %s from post %s', $input['comment'], $removed_comment->name, $post->cachename());
    gb::event('did-remove-comment', $removed_comment);
    # done OK
    if ($referrer) {
        $referrer->fragment = 'comments';
        header('HTTP/1.1 303 See Other');
        header('Location: ' . $referrer);
    } else {
        exit2("removed comment: {$removed_comment->id}\n", '200 OK');
    }
} catch (Exception $e) {
    gb::log(LOG_ERR, 'failed to remove comment %s from %s', $input['comment'], $post->cachename());
    header('HTTP/1.1 500 Internal Server Error');
    echo '$input => ';
    var_export($input);
    echo "\n";
    gb_flush();
예제 #2
0
            if (!$comment->approved) {
                $referrer->fragment = 'comments';
                $referrer['comment-status'] = 'pending';
            } else {
                unset($referrer['comment-status']);
            }
            header('HTTP/1.1 303 See Other');
            header('Location: ' . $referrer);
            exit(0);
        } else {
            exit2("new comment: {$comment->id}\n", '200 OK');
        }
    } catch (Exception $e) {
        if ($e instanceof GitError && strpos($e->getMessage(), 'nothing to commit') !== false) {
            gb::log('skipped duplicate comment from ' . var_export($comment->email, 1) . ' (nothing to commit)');
            gb::event('was-duplicate-comment', $comment);
            header('HTTP/1.1 304 Not Modified');
            header('Location: ' . $input['gb-referrer'] . '#skipped-duplicate-reply');
            exit(0);
        }
        gb::log(LOG_ERR, 'failed to add comment ' . var_export($comment->body, 1) . ' from ' . var_export($comment->name, 1) . ' <' . var_export($comment->email, 1) . '>' . ' to ' . $post->cachename());
        header('HTTP/1.1 500 Internal Server Error');
        echo '$input => ';
        var_export($input);
        echo "\n";
        gb_flush();
        throw $e;
    }
} else {
    # rejected by filter(s)
    if ($referrer) {
예제 #3
0
파일: authorize.php 프로젝트: rsms/gitblog
<?php

require '../_base.php';
gb::verify();
$authed = gb::authenticate(false);
if ($authed) {
    gb::log('client authorized: ' . $authed);
    gb_author_cookie::set($authed->email, $authed->name, gb::$site_url);
    gb::event('client-authorized', $authed);
    $url = isset($_REQUEST['referrer']) && $_REQUEST['referrer'] ? $_REQUEST['referrer'] : gb_admin::$url;
    header('HTTP/1.1 303 See Other');
    header('Location: ' . $url);
    exit('<html><body>See Other <a href="' . $url . '"></a></body></html>');
}
if (isset($_POST['chap-username'])) {
    if ($authed === CHAP::BAD_USER) {
        gb::$errors[] = 'No such user';
    } elseif ($authed === CHAP::BAD_RESPONSE) {
        gb::$errors[] = 'Bad password';
    } else {
        gb::$errors[] = 'Unknown error';
    }
}
$auth = gb::authenticator();
include '../_header.php';
?>
<script type="text/javascript" src="<?php 
echo gb_admin::$url;
?>
res/sha1-min.js"></script>
<script type="text/javascript">
예제 #4
0
파일: gitblog.php 프로젝트: rsms/gitblog
 /**
  * Return a, possibly cloned, version of this post which contains a minimal
  * set of information. Primarily used for paged posts pages.
  */
 function condensedVersion()
 {
     $c = clone $this;
     # excerpt member turns into a boolean "is ->body an excerpt?"
     if ($c->excerpt) {
         $c->body = $c->excerpt;
         $c->excerpt = true;
     } else {
         $c->excerpt = false;
     }
     # comments member turns into an integer "number of comments"
     $c->comments = $c->comments ? $c->comments->countApproved() : 0;
     gb::event('did-create-condensed-object', $this, $c);
     return $c;
 }
예제 #5
0
파일: akismet.php 프로젝트: rsms/gitblog
 static function check_comment($comment)
 {
     # null?
     if (!$comment) {
         return $comment;
     }
     # already approved?
     if ($comment->approved) {
         gb::log(LOG_INFO, 'skipping check since comment is already approved');
         return $comment;
     }
     $params = array('blog' => gb::$site_url, 'user_ip' => $comment->ipAddress, 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER'], 'blog_charset' => 'utf-8', 'comment_type' => $comment->type === GBComment::TYPE_COMMENT ? 'comment' : 'pingback', 'comment_author' => $comment->name, 'comment_author_email' => $comment->email, 'comment_content' => $comment->body());
     if ($comment->uri) {
         $params['comment_author_url'] = $comment->uri;
     }
     # add HTTP_* server vars (request headers)
     static $ignore = array('HTTP_COOKIE');
     foreach ($_SERVER as $key => $value) {
         if (strpos($key, 'HTTP_') === 0 && !in_array($key, $ignore) && is_string($value)) {
             $params[$key] = $value;
         }
     }
     # POST
     gb::log('checking comment');
     $reqbody = http_build_query($params);
     $response = self::http_post($reqbody, '/1.1/comment-check', self::$key . '.' . self::$host);
     # parse response
     if ($response[1] === 'true') {
         gb::log('comment classed as spam');
         self::$conf['spam_count'] = intval(self::$conf['spam_count']) + 1;
         $comment->spam = true;
         gb::event('did-spam-comment', $comment);
         if (self::$conf['delete_spam']) {
             $comment = null;
         }
     } elseif ($response[1] === 'false') {
         gb::log('comment classed as ham');
         $comment->spam = false;
         gb::event('did-ham-comment', $comment);
     } else {
         gb::log(LOG_WARNING, 'unexpected response from /1.1/comment-check: ' . $response[1]);
     }
     # forward
     return $comment;
 }