]> git.bts.cx Git - cx.git/blob - cx/lib/site.php
Custom markdown for inserting images
[cx.git] / cx / lib / site.php
1 <?php
2
3 cx_require('lib', 'db.php');
4 cx_require('lib', 'setup.php');
5
6 function _cx_default_site_details(...$args) {
7 $sql = 'SELECT '. join(',', $args) .'
8 FROM sites
9 LIMIT 1;';
10
11 foreach (cx_db_query($sql) as $site) {
12 return $site;
13 }
14 }
15
16 function cx_sites_add_site($url, $title, $byline, $copyright) {
17 $sql = 'INSERT INTO sites (
18 site_url,
19 site_title,
20 site_byline,
21 site_copyright
22 )
23 VALUES (?, ?, ?, ?);';
24 $site_id = cx_db_exec($sql, $url, $title, $byline, $copyright);
25 return $site_id;
26 }
27
28 function cx_sites_site_add_user($site_id, $user_id, $owner = false) {
29 $sql = 'INSERT INTO site_authorship (
30 site_authorship_site_id,
31 site_authorship_user_id,
32 site_authorship_owner
33 )
34 VALUES (?, ?, ?);';
35 cx_db_exec($sql, $site_id, $user_id, $owner);
36 }
37
38 function cx_site_name() {
39 $details = _cx_default_site_details('site_title');
40 return $details['site_title'];
41 }
42
43 function cx_site_byline() {
44 $details = _cx_default_site_details('site_byline');
45 return $details['site_byline'];
46 }
47
48 function cx_site_author() {
49 $details = _cx_default_site_details('site_copyright');
50 return $details['site_copyright'];
51 }
52
53 function cx_site_url() {
54 $details = _cx_default_site_details('site_url');
55 return $details['site_url'];
56 }
57
58 cx_setup_register(1, function() {
59 cx_db_exec('CREATE TABLE sites (
60 site_id INTEGER PRIMARY KEY,
61 site_url STRING,
62 site_title STRING,
63 site_byline STRING,
64 site_copyright STRING
65 );');
66
67 cx_db_exec('CREATE TABLE site_metadata (
68 site_metadata_site_id INTEGER,
69 site_metadata_key STRING,
70 site_metadata_value STRING,
71
72 PRIMARY KEY (site_metadata_site_id, site_metadata_key),
73 FOREIGN KEY (site_metadata_site_id) REFERENCES sites(site_id)
74 );');
75
76 cx_db_exec('CREATE TABLE site_authorship (
77 site_authorship_id INTEGER PRIMARY KEY,
78 site_authorship_site_id INTEGER,
79 site_authorship_user_id INTEGER,
80 site_authorship_owner BOOLEAN,
81
82 FOREIGN KEY(site_authorship_site_id) REFERENCES sites(site_id),
83 FOREIGN KEY(site_authorship_user_id) REFERENCES users(user_id)
84 );');
85 });