]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - common.php
read-only stuff
[quix0rs-gnu-social.git] / common.php
1 <?php
2
3 # global configuration object
4
5 // default configuration, overwritten in config.php
6
7 $config =
8   array('site' => 
9                 array('name' => 'Just another µB'),
10                 'dsn' =>
11                 array('phptype' => 'mysql',
12                           'username' => 'stoica',
13                           'password' => 'apasswd',
14                           'hostspec' => 'localhost',
15                           'database' => 'thedb')
16                 'dboptions' =>
17                 array('debug' => 2,
18                           'portability' => DB_PORTABILITY_ALL));
19
20 require_once(INSTALLDIR . '/config.php');
21 require_once('DB.php');
22
23 function common_database() {
24         global $config;
25         $db =& DB::connect($config['dsn'], $config['dboptions']);
26         if (PEAR::isError($db)) {
27                 common_server_error($db->getMessage());
28         } else {
29                 return $db;
30         }
31 }
32
33 function common_read_database() {
34         // XXX: read from slave server
35         return common_database();
36 }
37
38 function common_server_error($msg) {
39         header('Status: 500 Server Error');
40         header('Content-type: text/plain');
41
42         print $msg;
43         exit();
44 }
45
46 function common_user_error($msg) {
47         common_show_header('Error');
48         common_element('div', array('class' => 'error'), $msg);
49         common_show_footer();
50 }
51
52 function common_element_start($tag, $attrs=NULL) {
53         print "<$tag";
54         if (is_array($attrs)) {
55                 foreach ($attrs as $name => $value) {
56                         print " $name='$value'";
57                 }
58         } else if (is_string($attrs)) {
59                 print " class='$attrs'";
60         }
61         print '>';
62 }
63
64 function common_element_end($tag) {
65         print "</$tag>";
66 }
67
68 function common_element($tag, $attrs=NULL, $content=NULL) {
69     common_element_start($tag, $attrs);
70         if ($content) print $content;
71         common_element_end($tag);
72 }
73
74 function common_show_header($pagetitle) {
75         global $config;
76         common_element_start('html');
77         common_element_start('head');
78         common_element('title', NULL, $pagetitle . " - " . $config['site']['name']);
79         common_element_end('head');
80         common_element_start('body');
81 }
82
83 function common_show_footer() {
84         common_element_end('body');
85         common_element_end('html');
86 }
87
88 // TODO: set up gettext
89
90 function _t($str) { $str }