]>
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 function cx_site_posts_per_page() {
62 cx_setup_register(1, function() {
63 cx_db_exec('CREATE TABLE sites (
64 site_id INTEGER PRIMARY KEY,
71 cx_db_exec('CREATE TABLE site_metadata (
72 site_metadata_site_id INTEGER,
73 site_metadata_key STRING,
74 site_metadata_value STRING,
76 PRIMARY KEY (site_metadata_site_id, site_metadata_key),
77 FOREIGN KEY (site_metadata_site_id) REFERENCES sites(site_id)
80 cx_db_exec('CREATE TABLE site_authorship (
81 site_authorship_id INTEGER PRIMARY KEY,
82 site_authorship_site_id INTEGER,
83 site_authorship_user_id INTEGER,
84 site_authorship_owner BOOLEAN,
86 FOREIGN KEY(site_authorship_site_id) REFERENCES sites(site_id),
87 FOREIGN KEY(site_authorship_user_id) REFERENCES users(user_id)