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