function parseData() { $this->originalData = $this->data; if ($this->data === '') { $this->data = array(); } elseif (($this->data = json_decode($this->data, true)) === null) { $this->throwJSONError(false, 'Failed to parse ' . gb_relpath(gb::$site_dir, $this->file)); } }
static function repair_repo_setup() { git::exec('config receive.denyCurrentBranch ignore'); git::exec('config core.sharedRepository 1'); static $hooks = array('post-commit' => '', 'post-update' => 'git --work-tree=.. checkout -f', 'post-checkout' => '', 'post-merge' => ''); $post_update_relpath = gb_relpath(gb::$site_dir . '/.git/post-update.sh', gb::$dir . '/hooks/post-update.sh'); foreach ($hooks as $name => $extras) { $path = gb::$site_dir . '/.git/hooks/' . $name; $s = is_file($path) ? file_get_contents($path) : '#!/bin/sh'; if ($s === '#!/bin/sh' || strpos($s, '/gitblog/hooks/post-update.sh') === false) { $s .= "\n# This was added by gitblog:\n" . 'cd $(dirname "$0")/..' . "\n" . ($extras ? rtrim($extras) . "\n" : '') . ". {$post_update_relpath}\n"; file_put_contents($path, $s, LOCK_EX); @chmod($path, 0774); gb::log('updated hook %s', $path); } } }
static function init($add_sample_content = true, $shared = 'true', $theme = 'default', $mkdirmode = 0775) { # sanity check $themedir = gb::$dir . '/themes/' . $theme; if (!is_dir($themedir)) { throw new InvalidArgumentException('no theme named ' . $theme . ' (' . $themedir . 'not found or not a directory)'); } # git init git::init(null, null, $shared); # Create empty standard directories mkdir(gb::$site_dir . '/content/posts', $mkdirmode, true); chmod(gb::$site_dir . '/content', $mkdirmode); chmod(gb::$site_dir . '/content/posts', $mkdirmode); mkdir(gb::$site_dir . '/content/pages', $mkdirmode); chmod(gb::$site_dir . '/content/pages', $mkdirmode); mkdir(gb::$site_dir . '/data', $mkdirmode); chmod(gb::$site_dir . '/data', $mkdirmode); # Create hooks and set basic config gb_maint::repair_repo_setup(); # Copy default data sets $data_skeleton_dir = gb::$dir . '/skeleton/data'; foreach (scandir($data_skeleton_dir) as $name) { if ($name[0] !== '.') { $path = $data_skeleton_dir . '/' . $name; if (is_file($path)) { copy($path, gb::$site_dir . '/data/' . $name); chmod(gb::$site_dir . '/data/' . $name, 0664); } } } # Copy .gitignore copy(gb::$dir . '/skeleton/gitignore', gb::$site_dir . '/.gitignore'); chmod(gb::$site_dir . '/.gitignore', 0664); git::add('.gitignore'); # Copy theme $lnname = gb::$site_dir . '/index.php'; $lntarget = gb_relpath($lnname, $themedir . '/index.php'); symlink($lntarget, $lnname) or exit($lntarget); git::add('index.php'); # Add gb-config.php (might been added already, might be missing and/or # might be ignored by custom .gitignore -- doesn't really matter) git::add('gb-config.php', false); # Add sample content if ($add_sample_content) { # Copy example "about" page copy(gb::$dir . '/skeleton/content/pages/about.html', gb::$site_dir . '/content/pages/about.html'); chmod(gb::$site_dir . '/content/pages/about.html', 0664); git::add('content/pages/about.html'); # Copy example "about/intro" snippet mkdir(gb::$site_dir . '/content/pages/about', $mkdirmode); chmod(gb::$site_dir . '/content/pages/about', $mkdirmode); copy(gb::$dir . '/skeleton/content/pages/about/intro.html', gb::$site_dir . '/content/pages/about/intro.html'); chmod(gb::$site_dir . '/content/pages/about/intro.html', 0664); git::add('content/pages/about/intro.html'); # Copy example "hello world" post $s = file_get_contents(gb::$dir . '/skeleton/content/posts/0000-00-00-hello-world.html'); $s = preg_replace('/published:.+/', 'published: ' . date('H:i:s O'), $s); $name = 'content/posts/' . gmdate('Y/m-d') . '-hello-world.html'; $path = gb::$site_dir . '/' . $name; @mkdir(dirname($path), 0775, true); chmod(dirname($path), 0775); $s = str_replace('0000/00-00-hello-world.html', basename(dirname($name)) . '/' . basename($name), $s); file_put_contents($path, $s); chmod($path, 0664); git::add($name); } return true; }
public static function formatFrame($ti, $html = null, $context_lines = 2) { if ($html === null) { $html = ini_get('html_errors') ? true : false; } $context = false; if ($context_lines && isset($ti['file']) && isset($ti['line']) && $ti['file'] && $ti['line']) { $context = self::formatSourceLines($ti['file'], $ti['line'], $html, $context_lines); } $args = '()'; if (isset($ti['args'])) { $argsCnt = count($ti['args']); if ($argsCnt > 0) { $args = '(' . $argsCnt . ')'; } } $str = $html ? '<span class="function">' : ''; $str .= (isset($ti['type']) ? $ti['class'] . $ti['type'] : '::') . $ti['function'] . $args; if ($html) { $str .= '</span>'; } $str .= ' called in '; $str .= $html ? '<span class="location">' : ''; $str .= isset($ti['file']) && $ti['file'] ? h(gb_relpath(gb::$site_dir, $ti['file'])) : '?'; $str .= isset($ti['line']) && $ti['line'] ? ':' . $ti['line'] : ''; $str .= $html ? '</span>' : ''; if ($context) { $str .= $html ? '<pre class="context">' . $context . '</pre>' : "\n\n" . $context . "\n\n"; } return $str; }