Add oEmbed support
[phorkie.git] / www / setup.php
1 <?php
2 /**
3  * Check if all is setup correctly
4  */
5 namespace phorkie;
6 header('HTTP/1.0 500 Internal Server Error');
7
8 $reqWritePermissions = false;
9 require_once 'www-header.php';
10
11 if (!$GLOBALS['phorkie']['cfg']['setupcheck']) {
12     header('HTTP/1.0 403 Forbidden');
13     header('Content-type: text/plain');
14     echo "Setup check is disabled\n";
15     exit(1);
16 }
17
18 $messages = SetupCheck::run();
19 $errors = 0;
20 foreach ($messages as $arMessage) {
21     list($type, $message) = $arMessage;
22     $type == 'error' && ++$errors;
23 }
24 if ($errors == 0) {
25     header('HTTP/1.0 200 OK');
26 }
27 header('Content-type: text/html');
28
29 if ($errors == 0) {
30     $messages[] =  array('ok', 'All fine');
31 }
32
33 $out = <<<HTM
34 <?xml version="1.0" encoding="utf-8"?>
35 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
36 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
37  <head>
38   <title>phorkie setup check</title>
39   <link rel="stylesheet" href="css/bootstrap.min.css"/>
40   <link rel="stylesheet" href="css/font-awesome.css"/>
41   <link rel="stylesheet" href="css/phorkie.css"/>
42   <meta name="viewport" content="width=device-width, initial-scale=1"/>
43   <style type="text/css">
44     /**/
45     li:before {
46         text-align: center;
47         display: inline-block;
48         width: 1em;
49         padding: 0 0.5ex;
50         margin-right: 0.5ex;
51     }
52     li.list-group-item-success:before {
53         content: '✔';
54         color: green;
55     }
56     li.list-group-item-danger:before {
57         content: "✘";
58         color: white;
59         background-color: red;
60     }
61     li.list-group-item-info:before {
62         content: "i";
63         font-weight: bold;
64         color: blue;
65     }
66 /**/
67   </style>
68  </head>
69  <body>
70   <div class="container">
71    <div class="row">
72     <div class="span12">
73
74      <div class="page-header">
75       <h1>phorkie setup check</h1>
76      </div>
77      <h3>Check results</h3>
78
79      <ul class="list-group">
80 HTM;
81 $stateMap = array(
82     'ok'    => 'success',
83     'info'  => 'info',
84     'error' => 'danger'
85 );
86 foreach ($messages as $arMessage) {
87     list($type, $message) = $arMessage;
88     $out .= '<li class="list-group-item list-group-item-'
89         . $stateMap[$type] . '">';
90     $out .= htmlspecialchars($message);
91     $out .= '</li>' . "\n";
92 }
93 $out .= <<<HTM
94      </ul>
95 HTM;
96
97 if (array_sum($GLOBALS['phorkie']['cfgfiles']) == 0) {
98     //no config file loaded
99     reset($GLOBALS['phorkie']['cfgfiles']);
100     list($cfgFilePath, ) = each($GLOBALS['phorkie']['cfgfiles']);
101
102     $cfgFilePath = Tools::foldPath($cfgFilePath);
103     $cfgFileTemplate = htmlspecialchars(
104         file_get_contents(__DIR__ . '/../data/config.php.dist')
105     );
106     $cfgFileLines = count(explode("\n", $cfgFileTemplate));
107
108     $out .= <<<HTM
109      <h3 id="configfile">Configuration file</h3>
110      <p>
111       Phorkie did not find a configuration file.
112       Please create one at
113      </p>
114      <pre>$cfgFilePath</pre>
115      <p>
116       from the following template:
117      </p>
118      <textarea style="width:99%; background-color: #F5F5F5" rows="$cfgFileLines">$cfgFileTemplate</textarea>
119      <p>
120       Remove the leading <tt>//</tt> from a line if you want to adjust it.
121      </p>
122 HTM;
123 }
124
125 $out .= <<<HTM
126      <p style="margin-top: 4ex">
127       <a href="./"><i class="icon-arrow-left"></i> back</a> to the index
128      </p>
129     </div>
130    </div>
131   </div>
132
133   <div class="container footer">
134    <a href="//sf.net/p/phorkie/">phorkie</a>,
135    the self-hosted, git-based pastebin software is available under the
136    <a href="http://www.gnu.org/licenses/agpl-3.0.html">
137     <abbr title="GNU Affero General Public License">AGPL</abbr></a>.
138   </div>
139
140  </body>
141 </html>
142 HTM;
143 echo $out;
144 ?>