data() статический публичный Метод

static public data ( $name, $default = null )
Пример #1
0
 static function init($context)
 {
     if ($context !== 'rebuild') {
         return false;
     }
     self::$conf = gb::data('plugins/' . gb_filenoext(basename(__FILE__)), array('classname' => 'codeblock', 'tabsize' => 2, 'pygmentize' => 'pygmentize'));
     gb_cfilter::add('body.html', array(__CLASS__, 'filter'), 0);
     return true;
 }
Пример #2
0
 static function init($context)
 {
     self::$conf = gb::data('plugins/' . gb_filenoext(basename(__FILE__)), array('url' => ''));
     if (!self::$conf['url']) {
         gb::log(LOG_WARNING, 'missing "url" in configuration');
         return false;
     }
     gb::observe('will-handle-request', array(__CLASS__, 'will_handle_req'));
     return true;
 }
Пример #3
0
 static function init($context)
 {
     self::$conf = gb::data('plugins/google-analytics', array('property_id' => ''));
     if (!self::$conf['property_id']) {
         gb::log(LOG_WARNING, 'missing property_id in google-analytics configuration');
     } else {
         gb::observe('on-html-footer', array(__CLASS__, 'echo_tracking_code'));
         return true;
     }
     return false;
 }
Пример #4
0
 static function recipient($comment)
 {
     $recipient = self::$data['recipient'];
     if (is_array($recipient) || strpos($recipient, '@') !== false) {
         $recipient = GBMail::normalizeRecipient($recipient);
     } else {
         $recipient = GBMail::normalizeRecipient($comment->post->author);
     }
     if (!$recipient[0]) {
         $recipient = GBMail::normalizeRecipient(gb::data('email')->get('admin'));
     }
     return $recipient;
 }
Пример #5
0
 static function init($context)
 {
     $default_conf = array('api_key' => '', 'delete_spam' => true);
     self::$conf = gb::data('plugins/' . gb_filenoext(basename(__FILE__)), $default_conf);
     if (!self::$key) {
         self::$key = self::$conf['api_key'];
     }
     if (!self::$key) {
         gb::log(LOG_WARNING, 'akismet not loaded since "api_key" is not set in %s', self::$conf->file);
         return false;
     }
     if ($context === 'admin') {
         gb_cfilter::add('pre-comment', array(__CLASS__, 'check_comment'));
         return true;
     }
     return false;
 }
Пример #6
0
<?php

require dirname(__FILE__) . '/../gitblog.php';
$integrity = gb::verify_integrity();
if (strpos($_SERVER['SCRIPT_NAME'], '/admin/setup.php') === false) {
    if ($integrity === 2) {
        header('Location: ' . gb_admin::$url . 'setup.php');
        exit(0);
    } else {
        gb::verify_config();
    }
}
$admin_conf = gb::data('admin');
Пример #7
0
<?php

require_once '../_base.php';
gb::authenticate();
gb::$title[] = 'Settings';
include '../_header.php';
?>
<script type="text/javascript" charset="utf-8">//<![CDATA[
	var settings = gb.data('admin', <?php 
echo gb::data('admin')->toJSON();
?>
);
	var activeRequestCount = 0;
	var throbber = null;
	
	settings.onRequestStart = function(xhr) { throbber.push(); }
	settings.onRequestComplete = function(xhr, textStatus) { throbber.pop(); console.log(xhr.responseText); }
	settings.onData = function(delta) {
		console.log('settings updated =>', this.data);
	}
	settings.onSet = function(pairs) {
		// don't set stuff we believe is already set
		var p = pairs;
		for (var k in p)
			if (this.get(k) == p[k])
				delete pairs[k];
		
		// check custom "composing/default_mime_type"
		var default_mime_type = pairs["composing/default_mime_type"];
		if (typeof default_mime_type != 'undefined' && !default_mime_type.match(/[a-zA-Z0-9\.-]+/)) {
			$('#custom_default_mime_type').select();
Пример #8
0
    static function _000104($from, $to)
    {
        $datadir = gb::$site_dir . '/data/';
        $added = array();
        # create data/
        if (!file_exists($datadir)) {
            gb::log('creating directory %s', $datadir);
            mkdir($datadir, 0775);
            chmod($datadir, 0775);
        }
        # load old site.json
        gb::log('loading %s', gb::$site_dir . '/site.json');
        gb::$site_state = is_readable(gb::$site_dir . '/site.json') ? json_decode(file_get_contents(gb::$site_dir . '/site.json'), true) : array();
        # move site.json:plugins to data/plugins.json
        $plugins = isset(gb::$site_state['plugins']) ? gb::$site_state['plugins'] : array();
        gb::log('creating data:plugins');
        gb::data('plugins')->storage()->set($plugins);
        unset(gb::$site_state['plugins']);
        # write data/site.json
        gb::log('moving %s -> data:site', gb::$site_dir . '/site.json');
        # gb_maint::sync_site_state() will be called after this method returns
        @unlink(gb::$site_dir . '/site.json');
        # remove /site.json from .gitignore
        if (gb_maint::gitignore_sub('/(?:\\r?\\n)\\/site\\.json([\\t\\s \\r\\n]+|^)/m', '$1')) {
            gb::log('removed "/site.json" from .gitignore');
            $added[] = git::add('.gitignore');
        }
        # load settings.json
        gb::log('loading %s', gb::$site_dir . '/settings.json');
        $settings = is_readable(gb::$site_dir . '/settings.json') ? json_decode(file_get_contents(gb::$site_dir . '/settings.json'), true) : array();
        # move settings.json:* to data/plugins/*
        foreach ($settings as $pluginn => $d) {
            if (!is_array($d)) {
                $d = $d !== null ? array($d) : array();
            }
            if ($d) {
                gb::log('copying %s:%s -> data:plugins/%s', gb::$site_dir . '/settings.json', $pluginn, $pluginn);
                gb::data('plugins/' . $pluginn)->storage()->set($d);
            }
        }
        gb::log('removing old %s', gb::$site_dir . '/settings.json');
        @unlink(gb::$site_dir . '/settings.json');
        # load gb-users.php
        $users = array();
        if (is_readable(gb::$site_dir . '/gb-users.php')) {
            gb::log('loading %s', gb::$site_dir . '/gb-users.php');
            eval('class GBUserAccount {
				static function __set_state($state) {
					return GBUser::__set_state($state);
				}
			}');
            require gb::$site_dir . '/gb-users.php';
            if (isset($db)) {
                $admin = isset($db['_admin']) ? $db['_admin'] : '';
                foreach ($db as $email => $user) {
                    if (is_object($user)) {
                        $user->admin = $email === $admin;
                        $users[$email] = $user;
                        gb::log('transponded user %s', $email);
                    }
                }
            }
        }
        # move gb-users.php to data/users.json
        gb::log('moving %s -> data:users', gb::$site_dir . '/gb-users.php');
        GBUser::storage()->set($users);
        @unlink(gb::$site_dir . '/gb-users.php');
        # commit any modifications
        if ($added) {
            try {
                git::commit('upgrade 0.1.4 modified ' . implode(', ', $added), GBUser::findAdmin()->gitAuthor(), $added);
            } catch (GitError $e) {
                if (strpos($e->getMessage(), 'no changes added to commit') === false) {
                    throw $e;
                }
            }
        }
    }
Пример #9
0
# input params
$method = $_SERVER['REQUEST_METHOD'];
$store_id = isset($_SERVER['PATH_INFO']) ? trim($_SERVER['PATH_INFO'], "\r\n\t/ ") : null;
$jsonp_cb = false;
if (isset($_GET['jsoncallback'])) {
    $jsonp_cb = $_GET['jsoncallback'];
    unset($_GET['jsoncallback']);
    header('Content-Type: text/javascript');
} else {
    header('Content-Type: application/json');
}
# store
if (!$store_id) {
    rsp_err('No store specified in path');
}
$store = gb::data($store_id);
if ($method !== 'POST' && !is_readable($store->file)) {
    rsp_err('No such store "' . $store_id . '"', '404 Not found');
}
try {
    # POST
    if ($method === 'POST') {
        $payload_type = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '';
        $payload_data = '';
        $payload_struct = null;
        if ($payload_type !== 'application/json') {
            rsp_err('Unsupported Media Type. Only accepts "application/json"', '415 Unsupported Media Type');
        }
        # parse json
        $input = fopen('php://input', 'r');
        while ($data = fread($input, 8192)) {
Пример #10
0
 static function mkmailer()
 {
     # setup conf
     $siteurl = new GBURL(gb::$site_url);
     $admin = GBUser::findAdmin();
     $default_name = $admin ? $admin->name : $siteurl->host;
     $default_address = $admin ? $admin->email : 'root@' . $siteurl->host;
     self::$conf = gb::data('email', array('admin' => array($default_name, $default_address), 'from' => array(gb::$site_title, 'noreply@' . $siteurl->host), 'smtp.example-gmail' => array('secure' => 'ssl', 'host' => 'smtp.gmail.com:465', 'username' => $default_address, 'password' => 'secret')));
     # since PHPMailer is one ugly piece of software
     $orig_error_reporting = error_reporting(E_ALL ^ E_NOTICE);
     # setup phpmailer
     $e = new PHPMailer();
     $e->From = '';
     $e->FromName = '';
     $e->PluginDir = gb::$dir . '/lib/PHPMailer/';
     # SMTP
     if (($c = self::$conf['smtp']) !== null) {
         $e->IsSMTP();
         # enable SMTP
         # authenitcation?
         $e->SMTPAuth = isset($c['password']) || isset($c['username']);
         # secure?
         if (isset($c['secure']) && $c['secure']) {
             static $allowed = array('ssl' => 1, 'tls' => 1, '' => 1);
             $c['secure'] = is_string($c['secure']) ? strtolower($c['secure']) : ($c['secure'] ? 'ssl' : '');
             if (!isset($allowed[$c['secure']])) {
                 gb::log(LOG_WARNING, 'malformed configuration: bad value for "secure": %s -- only "ssl" or "tls" is allowed', $c['secure']);
             } else {
                 $e->SMTPSecure = $c['secure'];
             }
         }
         # support for multiple hosts
         if (isset($c['host'])) {
             $e->Host = $c['host'];
         } elseif (isset($c['hosts'])) {
             $e->Host = $c['hosts'];
         }
         if (is_array($e->Host)) {
             $hosts = $e->Host;
             $e->Host = array();
             foreach ($hosts as $host) {
                 if (is_array($host)) {
                     if (!isset($host['name'])) {
                         gb::log(LOG_WARNING, 'malformed configuration: missing "name" for host %s', var_export($host, 1));
                     } else {
                         $v[] = $host['name'] . (isset($host['port']) ? ':' . $host['port'] : '');
                     }
                 } else {
                     $v[] = $host;
                 }
             }
             $e->Host = implode(';', $e->Host);
         }
         # default port
         if (isset($c['port']) && ($port = intval($c['port'])) > 0) {
             $e->Port = $port;
         }
         # username
         if (isset($c['username'])) {
             $e->Username = $c['username'];
         }
         # password
         if (isset($c['password'])) {
             $e->Password = $c['password'];
         }
         # connection timeout
         if (isset($c['timeout']) && ($i = intval($c['timeout'])) > 0) {
             $e->Timeout = $i;
         }
     }
     # gitblog <heart> UTF-8
     $e->CharSet = 'utf-8';
     # Default from
     if ($from = self::$conf['from']) {
         list($e->From, $e->FromName) = self::normalizeRecipient($from);
     }
     # Default sender
     if (($sender = self::$conf['sender']) || ($sender = self::$conf['admin'])) {
         list($e->Sender, $discard) = self::normalizeRecipient($sender);
     }
     # default priority
     if ($priority = self::$conf['priority']) {
         $e->Priority = intval($priority);
     }
     # reset error reporting
     error_reporting($orig_error_reporting);
     return $e;
 }