1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Andreas Gohr <andi@splitbrain.org>
5 */
6
7/**
8 * Class helper_plugin_blogtng_sqlite
9 */
10class helper_plugin_blogtng_sqlite extends DokuWiki_Plugin {
11
12    /** @var helper_plugin_sqlite initialized via _getDb() */
13    protected $db = null;
14
15    /**
16     * Simple function to check if the database is ready to use
17     *
18     * @return bool
19     */
20    public function ready() {
21        return (bool) $this->getDB();
22    }
23
24    /**
25     * Returns the instance of helper_plugin_sqlite,
26     * otherwise it creates a new instance of the helper_plugin_sqlite and stores it in this object
27     *
28     * @return false|helper_plugin_sqlite returned the loaded sqlite helper
29     */
30    public function getDB() {
31        if($this->db === null) {
32            $this->db = plugin_load('helper', 'sqlite');
33            if($this->db === null) {
34                msg('The BlogTNG plugin needs the <a href="https://www.dokuwiki.org/plugin:sqlite">sqlite plugin</a>. Please install and enable this plugin.', -1);
35                return false;
36            }
37            if(!$this->db->init('blogtng', dirname(__FILE__) . '/../db/')) {
38                $this->db = null;
39                return false;
40            }
41        }
42        return $this->db;
43    }
44}
45