]>
git.bts.cx Git - cx.git/blob - cx/lib/site.php
3 cx_require('lib', 'db.php');
4 cx_require('lib', 'setup.php');
6 function _cx_default_site_details(...$args) {
7 $sql = 'SELECT '. join(',', $args) .'
11 foreach (cx_db_query($sql) as $site) {
16 function cx_sites_add_site($url, $title, $byline, $copyright) {
17 $sql = 'INSERT INTO sites (
23 VALUES (?, ?, ?, ?);';
24 $site_id = cx_db_exec($sql, $url, $title, $byline, $copyright);
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,
35 cx_db_exec($sql, $site_id, $user_id, $owner);
38 function cx_site_name() {
39 $details = _cx_default_site_details('site_title');
40 return $details['site_title'];
43 function cx_site_byline() {
44 $details = _cx_default_site_details('site_byline');
45 return $details['site_byline'];
48 function cx_site_author() {
49 $details = _cx_default_site_details('site_copyright');
50 return $details['site_copyright'];
53 function cx_site_url() {
54 $details = _cx_default_site_details('site_url');
55 return $details['site_url'];
58 cx_setup_register(1, function() {
59 cx_db_exec('CREATE TABLE sites (
60 site_id INTEGER PRIMARY KEY,
67 cx_db_exec('CREATE TABLE site_metadata (
68 site_metadata_site_id INTEGER,
69 site_metadata_key STRING,
70 site_metadata_value STRING,
72 PRIMARY KEY (site_metadata_site_id, site_metadata_key),
73 FOREIGN KEY (site_metadata_site_id) REFERENCES sites(site_id)
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,
82 FOREIGN KEY(site_authorship_site_id) REFERENCES sites(site_id),
83 FOREIGN KEY(site_authorship_user_id) REFERENCES users(user_id)