Overview
Comment:Base plugins
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4dda85a74d9016114bd258ba70c713b278dce1d5
User & Date: bohwaz on 2014-01-15 18:23:10
Other Links: manifest | tags
Context
2014-01-15
19:23
Bases plugins check-in: da4017b724 user: bohwaz tags: trunk
18:23
Base plugins check-in: 4dda85a74d user: bohwaz tags: trunk
2014-01-08
18:53
menu minimal quand non connecté check-in: e5d1847240 user: bohwaz tags: trunk
Changes

Added src/include/class.plugin.php version [56f29fe6ae].



































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php

namespace Garradin;

class Plugin
{
	protected $id = null;
	protected $config = null;

	public function __construct($id)
	{
		$this->id = null;
	}

	public function getConfig($key = null)
	{
		if (is_null($this->config))
		{
			$db = DB::getInstance();
			$this->config = $db->simpleQuerySingle('SELECT config FROM plugins WHERE id = ?;', false, $this->id);
			$this->config = json_decode($this->config, true);

			if (!is_array($this->config))
			{
				$this->config = [];
			}
		}

		if (array_key_exists($key, $this->config))
		{
			return $this->config[$key];
		}

		return null;
	}

	public function setConfig($key, $value = null)
	{
		$this->getConfig();

		if (is_null($value))
		{
			unset($this->config[$key]);
		}
		else
		{
			$this->config[$key] = $value;
		}

		$db = DB::getInstance();
		$db->simpleUpdate('plugins', 'id = \'' . $this->id . '\'', ['config' => json_encode($this->config)]);

		return true;
	}

	public function getInfos()
	{
		$db = DB::getInstance();
		return $db->simpleStatementFetch('SELECT * FROM plugins WHERE id = ?;', $this->id);
	}

	static public function listInstalled()
	{
		$db = DB::getInstance();
		return $db->simpleStatement('SELECT * FROM plugins ORDER BY nom;');
	}

	static public function fetchOfficialList()
	{
		if (Static_Cache::expired('plugins_list', 3600 * 24))
		{
			$url = parse_url(GARRADIN_PLUGINS_URL);

			$context_options = [
				'ssl' => [
					'verify_peer'   => TRUE,
					'cafile'        => GARRADIN_ROOT . '/include/data/cacert.pem',
					'verify_depth'  => 5,
					'CN_match'      => $url['host'],
				]
			];

			$context = stream_context_create($context_options);
			$result = file_get_contents(GARRADIN_PLUGINS_URL, NULL, $context);
			Static_Cache::store('plugins_list', $result);
		}
		else
		{
			$result = Static_Cache::get('plugins_list');
		}

		$list = json_decode($result, true);
		return $list;
	}

	static public function checkHash($id)
	{
		$list = self::fetchOfficialList();

		if (!array_key_exists($id, $list))
			return null;

		$hash = sha1_file(GARRADIN_PLUGINS_PATH . '/' . $id . '.phar');

		return ($hash == $list[$id]['hash']);
	}

	static public function isOfficial($id)
	{
		$list = self::fetchOfficialList();
		return array_key_exists($id, $list);
	}
}

Modified src/include/data/schema.sql from [e3c3d57b96] to [a14bc60d26].

308
309
310
311
312
313
314
315
316
317
318

319
320
321
322
323

324



325
326
    description TEXT,

    compte TEXT NOT NULL, -- Compte affecté par cette catégorie

    FOREIGN KEY(compte) REFERENCES compta_comptes(id)
);

/*
--
-- générateur de paperasses
--


CREATE TABLE papiers (
    id INTEGER PRIMARY KEY,
    modele INTEGER,


    donnees TEXT



);
*/







<
<
<
<
>
|
<
|
|
|
>
|
>
>
>

<
308
309
310
311
312
313
314




315
316

317
318
319
320
321
322
323
324
325

    description TEXT,

    compte TEXT NOT NULL, -- Compte affecté par cette catégorie

    FOREIGN KEY(compte) REFERENCES compta_comptes(id)
);





CREATE TABLE plugins
(

    id TEXT PRIMARY KEY,
    nom TEXT NOT NULL,
    description TEXT,
    auteur TEXT,
    url TEXT,
    version TEXT NOT NULL,
    menu INTEGER NOT NULL DEFAULT 0,
    config TEXT
);

Modified src/include/init.php from [e2dc445610] to [07cfd5c797].

1
2
3
4
5
6



7
8
9
10
11
12
13
<?php

namespace Garradin;

error_reporting(-1);




/*
 * Version de Garradin
 */

function garradin_version()
{
    if (defined('GARRADIN_VERSION'))






>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

namespace Garradin;

error_reporting(-1);

define('GARRADIN_WEBSITE', 'http://garradin.eu/');
define('GARRADIN_PLUGINS_URL', 'https://garradin.eu/plugins/list.json');

/*
 * Version de Garradin
 */

function garradin_version()
{
    if (defined('GARRADIN_VERSION'))

Modified src/include/lib.static_cache.php from [c7a4e63305] to [2b38bda8cc].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

namespace Garradin;

class Static_Cache
{
	const EXPIRE = 3600; // 1h
	const CLEAN_EXPIRE = 86400; // 1 day
	protected static $cache_dir = null;

	protected static function _getCacheDir()
	{
		if (is_null(self::$cache_dir))
		{
			throw new \RuntimeException('Cache dir not set.');
		}

		return self::$cache_dir;
	}

	protected static function _getCachePath($id)
	{
		$id = 'cache_' . sha1($id);
		return self::_getCacheDir() . '/' . $id;
	}

	public static function setCacheDir($dir)
	{
		if (substr($dir, -1) == '/')
		{
			$dir = substr($dir, 0, -1);
		}

		if (!is_readable($dir) || !is_writable($dir))
		{
			throw new \RuntimeException('Cache dir is not readable or writeable.');
		}

		self::$cache_dir = $dir;
		return true;
	}

	static public function store($id, $content)
	{
		$path = self::_getCachePath($id);
		return (bool) file_put_contents($path, $content);
	}

	static public function expired($id, $expire = self::EXPIRE)








<



<
<
<
<
|
<








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1
2
3
4
5
6
7
8

9
10
11




12

13
14
15
16
17
18
19
20
















21
22
23
24
25
26
27
<?php

namespace Garradin;

class Static_Cache
{
	const EXPIRE = 3600; // 1h
	const CLEAN_EXPIRE = 86400; // 1 day


	protected static function _getCacheDir()
	{




		return GARRADIN_DATA_ROOT . '/cache/static';

	}

	protected static function _getCachePath($id)
	{
		$id = 'cache_' . sha1($id);
		return self::_getCacheDir() . '/' . $id;
	}

















	static public function store($id, $content)
	{
		$path = self::_getCachePath($id);
		return (bool) file_put_contents($path, $content);
	}

	static public function expired($id, $expire = self::EXPIRE)

Modified src/www/admin/compta/graph.php from [9bf2c1c68d] to [1d61f36647].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

if (!in_array(utils::get('g'), array('recettes_depenses', 'banques_caisses')))
{
	throw new UserException('Graphique inconnu.');
}

$graph = utils::get('g');

define('GRAPH_CACHE_DIR', GARRADIN_ROOT . '/cache/static');

if (!file_exists(GRAPH_CACHE_DIR))
{
	mkdir(GRAPH_CACHE_DIR);
}

Static_Cache::setCacheDir(GRAPH_CACHE_DIR);

if (Static_Cache::expired('graph_' . $graph))
{
	$stats = new Compta_Stats;

	require_once GARRADIN_ROOT . '/include/libs/svgplot/lib.svgplot.php';

	$plot = new \SVGPlot(400, 300);












<
<
<
<
<
<
<
<
<







1
2
3
4
5
6
7
8
9
10
11
12









13
14
15
16
17
18
19
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

if (!in_array(utils::get('g'), array('recettes_depenses', 'banques_caisses')))
{
	throw new UserException('Graphique inconnu.');
}

$graph = utils::get('g');










if (Static_Cache::expired('graph_' . $graph))
{
	$stats = new Compta_Stats;

	require_once GARRADIN_ROOT . '/include/libs/svgplot/lib.svgplot.php';

	$plot = new \SVGPlot(400, 300);