Esempio n. 1
0
 /**
  * Create a new database.
  * @param \stdClass $options
  * @param bool $force
  * @return IDatabase
  * @throws ServiceException
  */
 public static function create(\stdClass $options, $force = false)
 {
     $database = $options->database;
     $connection = clone $options;
     $connection->database = NULL;
     $db = Database::connect($connection);
     $db->create($database, $force);
     return Database::connect($options);
 }
Esempio n. 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']))]];
    }
Esempio n. 3
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']))]];
    }
Esempio n. 4
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());
    }
    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())]];
    }
Esempio n. 6
0
    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']));
    }
Esempio n. 7
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;
    }
Esempio n. 8
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]];
    }
Esempio n. 9
0
 private static function execute_row($sql, array $row, array $variables)
 {
     $params = array_intersect_key($row, array_fill_keys($variables, true));
     if (count($params) != count($variables)) {
         throw new \Exception('missing variables: ' . implode(',', array_values(array_diff($variables, array_keys($row)))));
     }
     $params = self::convert_keys($params);
     Database::execute($sql, $params);
 }