예제 #1
0
    public static function load()
    {
        $res = Database::query('
			SELECT time, title text, slug FROM objects
			WHERE type = :type
			ORDER BY time DESC
			LIMIT :count
		', ['type' => 'post', 'count' => 8]);
        return ['SidebarSectionRecent' => ['list' => iterator_to_array($res->rows(['time' => 'strtotime']))]];
    }
예제 #2
0
    public static function load()
    {
        $res = Database::query('
			SELECT strftime(\'%Y-%m\',time) month, COUNT(*) count FROM objects
			WHERE type = :type
			GROUP BY month
			ORDER BY time DESC
		', ['type' => 'post']);
        return ['SidebarSectionArchives' => ['list' => iterator_to_array($res->rows(['month' => 'strtotime']))]];
    }
예제 #3
0
    public static function load($current, array $context = NULL)
    {
        $res = Database::query('
			SELECT t.name, t.slug FROM term_relationships r
			INNER JOIN term_taxonomy x ON r.taxonomy = x.id
			INNER JOIN terms t ON x.term = t.id
			WHERE x.taxonomy = :taxonomy
			AND r.object = :post
		', ['taxonomy' => 'category', 'post' => $context['id']]);
        return iterator_to_array($res->rows());
    }
예제 #4
0
    public static function load()
    {
        $res = Database::query('
			SELECT t.name text, t.slug, COUNT(r.object) count FROM terms t
			INNER JOIN term_taxonomy x ON t.id = x.term
			INNER JOIN term_relationships r ON r.taxonomy = x.id
			WHERE x.taxonomy = :taxonomy
			GROUP BY r.taxonomy
			ORDER BY t.name ASC
		', ['taxonomy' => 'category']);
        return ['SidebarSectionCategories' => ['list' => iterator_to_array($res->rows())]];
    }
예제 #5
0
파일: Posts.php 프로젝트: jdauie/bramble
    public static function category($slug)
    {
        $res = Database::query('
			SELECT p.id, p.time, p.title, p.slug, p.content, u.display FROM objects p
			INNER JOIN users u ON p.author = u.id
			INNER JOIN term_relationships r ON p.id = r.object
			INNER JOIN term_taxonomy x ON r.taxonomy = x.id
			INNER JOIN terms t ON x.term = t.id
			WHERE p.type = :type
			AND x.taxonomy = :taxonomy
			AND t.slug = :slug
			ORDER BY p.time DESC
		', ['type' => 'post', 'taxonomy' => 'category', 'slug' => $slug]);
        return iterator_to_array($res->rows(['time' => 'strtotime']));
    }
예제 #6
0
    public function action__content()
    {
        // load posts/pages
        // parse and create thumbnails
        // in the future, I could alert about unused images/refs, dead links, etc.
        $images = [];
        $subvert_options = ['image_callback' => function (&$attributes) use(&$images) {
            $src = $attributes['src'];
            if (!isset($images[$src])) {
                $images[$src] = [];
            }
            $width = isset($attributes['width']) && ctype_digit($attributes['width']) ? (int) $attributes['width'] : 0;
            $height = isset($attributes['height']) && ctype_digit($attributes['height']) ? (int) $attributes['height'] : 0;
            $key = sprintf('%sx%s', $width, $height);
            if (!isset($images[$src][$key])) {
                $images[$src][$key] = ['width' => $width, 'height' => $height];
            }
        }, 'link_callback' => function (&$attributes) {
        }];
        $res = Database::query('
			SELECT Content FROM Objects
			WHERE Type IN (:types)
		', ['types' => ['post', 'page']]);
        foreach ($res->column() as $content) {
            Subvert::Parse($content, $subvert_options);
        }
        Log::time('load+subvert');
        ksort($images, SORT_NATURAL);
        foreach ($images as $image_path => $versions) {
            foreach ($versions as $version => $dimensions) {
                if ($version !== '0x0') {
                    $parts = pathinfo($image_path);
                    $thumbnail_path = sprintf('%s/%s-%s.%s', $parts['dirname'], $parts['filename'], $version, $parts['extension']);
                    Log::debug("[resize] {$thumbnail_path}]");
                    $src = BRAMBLE_DIR . $image_path;
                    $dst = BRAMBLE_DIR . $thumbnail_path;
                    if (file_exists($src)) {
                        $image = GdImage::load($src);
                        $image->resize($dimensions['width'], $dimensions['height'])->save($dst)->dispose();
                        $image->dispose();
                    }
                }
            }
        }
        Log::time('thumbnails');
        return NULL;
    }
예제 #7
0
    public static function load()
    {
        $res = Database::query('
			SELECT title text, slug, menu_order FROM objects
			WHERE type = :type
			AND menu_order != 0
			ORDER BY menu_order ASC
		', ['type' => 'page']);
        $nav = [];
        $global = [];
        foreach ($res->rows_by_key('menu_order', true) as $order => $row) {
            if ($order < 0) {
                $global[] = $row;
            } else {
                $nav[] = $row;
            }
        }
        return ['Navigation' => ['nav-list' => $nav, 'nav-list-global' => $global]];
    }
예제 #8
0
파일: Builder.php 프로젝트: jdauie/bramble
 private static function create($init)
 {
     // todo: remove this!
     $path = 'c:/tmp/db/bramble.sqlite3';
     if (file_exists($path)) {
         unlink($path);
     }
     $tables = self::tables();
     Log::time('load');
     foreach ($tables as $table) {
         Database::execute((string) $table);
         Log::debug("[database] CREATE TABLE {$table->name()}");
     }
     Log::time('create');
     $saved = [];
     foreach ($init as $action) {
         $sql = $action['sql'];
         $fill = isset($action['fill']) ? $action['fill'] : [];
         $load = isset($action['load']) ? $action['load'] : [];
         $expand = isset($action['expand']) ? explode('/', $action['expand'], 2) : NULL;
         $variables = self::sql_vars($sql);
         if (isset($action['data'])) {
             $rows = $action['data'];
             if (is_string($rows)) {
                 // load saved by name
                 $rows = $saved[$rows];
             } else {
                 $map = isset($action['map']) ? $action['map'] : $variables;
                 // create associative arrays for data
                 $rows = array_map(function ($a) use($map) {
                     return array_combine($map, $a);
                 }, $rows);
             }
             foreach ($rows as $row) {
                 foreach ($fill as $variable => $method) {
                     /** @var callable $method */
                     $method = [self::class, "_{$method}"];
                     $row[$variable] = $method($row);
                 }
                 foreach ($load as $variable => $query) {
                     $params2 = self::convert_keys(array_intersect_key($row, array_fill_keys(self::sql_vars($query), true)));
                     $res = Database::query($query, $params2);
                     $row[$variable] = $res->single_value();
                 }
                 if ($expand) {
                     foreach ($row[$expand[0]] as $expanded) {
                         $row[$expand[1]] = $expanded;
                         self::execute_row($sql, $row, $variables);
                     }
                 } else {
                     self::execute_row($sql, $row, $variables);
                 }
             }
             if (isset($action['save'])) {
                 $saved[$action['save']] = $rows;
             }
         } else {
             Database::execute($sql);
         }
     }
     Log::time('fill');
 }