root/tags/1.1.0/setup.php

Revision 1688, 10.8 KB (checked in by driehle, 11 months ago)

Converted all files to UTF-8 and added accept-charset="UTF-8" to most forms.

Line 
1<?php
2/* -- setup.php for Jlog
3   -- Please delete this file if you have done the setup
4*/
5
6 // derzeit gibt es noch etliche E_NOTICE-Meldungen in JLog, deshalb:
7 error_reporting(E_ALL ^ E_NOTICE);
8 header("Content-Type: text/html; charset=UTF-8");
9
10
11 define("JLOG_NEW_VERSION", '1.1.0');
12 define("JLOG_SETUP", true);
13 define("JLOG_ADMIN", false);
14 $basepath = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
15
16 // defining to avoid notifications
17 define("JLOG_WEBSITE", $_SERVER["HTTP_HOST"]);
18 define("JLOG_PATH", dirname("http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]));
19
20 // read prefered language from browser
21 $dir = opendir('.'.DIRECTORY_SEPARATOR.'lang');
22 $languages = array();
23 while(($file = readdir($dir)) !== false) {
24  if($file == '.' OR $file == '..') continue;
25  if(!preg_match('/lang\.([a-zA-z0-9]+)\.inc\.php/', $file, $matches)) continue;
26  $languages[] = $matches[1];
27 }
28 $lang = getlang($languages, 'de');
29 define('JLOG_LANGUAGE', $lang);
30 
31 // load required scripts and libraries
32 require('.'.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.'lang.'.$lang.'.inc.php');
33 require('.'.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.'lang-admin.'.$lang.'.inc.php');
34 require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'database.class.php');
35 require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'general.func.php'); 
36 require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'settings.class.php');
37 require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'url_syntax.php');
38 require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'version.inc.php');
39 
40 define("JLOG_NEW_VERSION", JLOG_SOFTWARE_VERSION);
41 define("JLOG_PHPV", JLOG_SOFTWARE_PHPV);
42 define("JLOG_MYSQLV", JLOG_SOFTWARE_MYSQLV);
43 
44 $errors = array();
45 
46 $l['admin']['submit'] = $l['admin']['s_install'];
47 $setup = new Settings($l);
48
49 if($_POST) {
50  $setup->get_userdata(strip($_POST));
51
52  // validate user entry
53  if(count($errors = $setup->validate()) == 0) {
54   define("JLOG_BASEPATH", $setup->put_data('basepath'));
55   if(is_writable(JLOG_BASEPATH.'personal'.DIRECTORY_SEPARATOR)) {
56     $c .= "<ul>\n";
57     
58     // build some MySQL tables
59     if(count($errors = create_mysql_tables($setup->put_data(false))) == 0) {
60      $c .= "<li>".$l['admin']['s_tables_ok']."</li>\n";
61
62      // create and chmod on some directories and files
63      if(count($errors = do_personal()) == 0) {
64       $c .= "<li>".$l['admin']['s_personal_ok']."</li>\n";
65
66       // build settings.inc.php
67       if(count($errors = $setup->do_settings()) == 0) $c .= "<li>".$l['admin']['master_ok']."</li>\n";
68      }
69      $c .= "</ul>";
70     }
71   }
72   else {
73    $errors[] = $l['admin']['s_personal_not_wrtbl'];
74   }
75  }
76  if(count($errors) > 0) {
77   $c .= error_output($errors);
78   $c .= $setup->form_output();
79  }
80  else $c .= "<h2>".$l['admin']['s_ready_head']."</h2>"."<p style='text-align: left;'>".$l['admin']['s_ready']."</p>";
81 }
82 else {
83  // validate PHP and MySQL versions
84  if(!version_compare(phpversion(), JLOG_PHPV, ">=") == 1) $errors[] = $l['admin']['s_phpv_tolow'];
85  if(!is_writable($basepath.'personal'.DIRECTORY_SEPARATOR)) $errors[] = $l['admin']['s_personal_not_wrtbl'];
86  if(!is_writable($basepath.'img'.DIRECTORY_SEPARATOR)) $errors[] = $l['admin']['s_img_not_wrtbl'];
87
88  if(empty($errors)) {
89   // output form
90   $setup->get_sugestiondata();
91   $c .= $setup->form_output();
92  }
93  else $c .= error_output($errors);
94 }
95 
96 echo do_htmlpage($c);
97 
98
99
100
101
102#### some needed functions for the setup ####
103
104 function create_mysql_tables($data) {
105  # returns false if all tables were created, if not returns the $errors array
106
107  $sql['content'] = '
108    CREATE TABLE `'.$data['jlog_db_prefix'].'content` (
109      id int(11) auto_increment,
110      url varchar(200),
111      topic varchar(255),
112      date datetime,
113      teaser mediumtext,
114      teaserpic varchar(10),
115      teaserpiconblog tinyint(1),
116      keywords varchar(255),
117      content longtext,
118      comments tinyint(1) default \'1\',
119      allowpingback tinyint(1) default \'1\',
120      section varchar(10) default \'weblog\',
121      UNIQUE KEY id (id),
122      FULLTEXT KEY content_index (content, topic, teaser, keywords)
123    ) TYPE=MyISAM CHARACTER SET utf8;';
124
125  $sql['comments'] = '
126   CREATE TABLE `'.$data["jlog_db_prefix"].'comments` (
127     id int(11) auto_increment,
128     sid varchar(35),
129     name varchar(255),
130     city varchar(255),
131     email varchar(255),
132     homepage varchar(255),
133     content mediumtext,
134     date datetime,
135     reference int(11),
136     mail_by_comment tinyint(1),
137     type varchar(30) default \'\',
138     PRIMARY KEY (id),
139     UNIQUE KEY sid (sid),
140     FULLTEXT KEY comments_index ( name, city, email, homepage, content )
141   ) TYPE=MyISAM CHARACTER SET utf8;';
142   
143  $sql['categories'] = '
144   CREATE TABLE `'.$data["jlog_db_prefix"].'categories` (
145     id tinyint(4) auto_increment,
146     name tinytext,
147     url varchar(100),
148     description text,
149     UNIQUE KEY id (id),
150     UNIQUE KEY url (url)
151   ) TYPE=MyISAM CHARACTER SET utf8;';
152   
153  $sql['catassign'] = '
154   CREATE TABLE `'.$data["jlog_db_prefix"].'catassign` (
155     content_id int(11),
156     cat_id tinyint(4)
157   ) TYPE=MyISAM CHARACTER SET utf8;';
158
159  $sql['attributes'] = '
160   CREATE TABLE `'.$data["jlog_db_prefix"].'attributes` (
161     id int(10) unsigned NOT NULL auto_increment,
162     entry_id int(10) unsigned NOT NULL default \'0\',
163     name varchar(120) NOT NULL default \'\',
164     value varchar(250) NOT NULL default \'\',
165     PRIMARY KEY (id),
166     KEY entry_id (entry_id)
167   ) TYPE=MyISAM CHARACTER SET utf8;';
168
169    global $l;
170
171    if(!@mysql_connect($data['jlog_db_url'], $data['jlog_db_user'], $data['jlog_db_pwd'])) $errors[] = "Falsche Zugangsdaten | ".mysql_error();
172    elseif(!@mysql_select_db($data['jlog_db'])) $errors[] = "Datenbank ".$data['jlog_db']." extistiert nicht".mysql_error();
173    elseif(!version_compare(mysql_get_server_info(), JLOG_MYSQLV, ">=") == 1) $errors[] = $l['admin']['s_mysqlv_tolow'];
174    else {
175                 new Query("SET NAMES utf8");
176     $create['content'] = new Query($sql['content']);
177     if($create['content']->error()) $errors[] = "MySQL <pre>".$create['content']->getError()."</pre>";
178     $create['comments'] = new Query($sql['comments']);
179     if($create['comments']->error()) $errors[] = "MySQL <pre>".$create['comments']->getError()."</pre>";   
180     $create['categories'] = new Query($sql['categories']);
181     if($create['categories']->error()) $errors[] = "MySQL <pre>".$create['categories']->getError()."</pre>";
182     $create['catassign'] = new Query($sql['catassign']);
183     if($create['catassign']->error()) $errors[] = "MySQL <pre>".$create['catassign']->getError()."</pre>";
184     $create['attributes'] = new Query($sql['attributes']);
185     if($create['attributes']->error()) $errors[] = "MySQL <pre>".$create['attributes']->getError()."</pre>";
186  }
187   
188   return $errors;
189 }
190 
191 function do_personal() {
192  # returns true if all files and dirs could be generated
193  # if not returns the $errors array
194
195  global $l;
196
197  // make some dirs
198  $oldmask = umask(0);
199
200  // make some files
201  if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."settings.inc.php", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/settings.inc.php";
202  if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss.xml", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/rss.xml";
203  if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss-full.xml", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/rss-full.xml";
204  if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."subcurrent.inc", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/subcurrent.inc";
205
206  // chmod 777 so that the user have the ability to delete/write to this files
207  if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."settings.inc.php", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/settings.inc.php";
208  if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss.xml", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/rss.xml";
209  if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss-full.xml", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/rss-full.xml";
210  if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."subcurrent.inc", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/subcurrent.inc";
211
212  umask($oldmask);
213
214  return $errors;
215 }
216
217 function do_htmlpage($content) {
218
219  return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
220        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
221<html xmlns="http://www.w3.org/1999/xhtml">
222  <title>SETUP Jlog ' . JLOG_NEW_VERSION . '</title>
223  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
224  <link rel="stylesheet" href="scripts/css/admin.css" type="text/css" />
225  <style type="text/css">
226   body {
227    background: #F3F3F3;
228    color: black;
229    font-family: verdana, sans-serif;
230    font-size: 100.01%;
231   }
232   #container {
233    font-size: 0.9em;
234    background: white;
235    padding: 20px;
236    margin: 1em auto;
237    border: 1px solid #aaa;
238    width: 600px;
239   }
240   h1 {
241    font-family: georgia, "Times New Roman", Times, sans-serif;
242    font-size: 80px;
243    margin: 0 0 0 30px;
244   }
245   #logo { float: right; }
246   h2 { margin: 1.5em 0 0.3em 0; font-weight: normal; clear: right; }
247   .ok { color: green; }
248   .notok, .error { color: red; }
249   table { border-spacing: 0.5em; }
250   fieldset { padding: 1em; border: 1px solid #ccc; clear: both; margin-top: 1em; }
251   legend { font-weight: bold; padding: 0 1em; }
252   .button { font-size: 3em; }
253   p { text-align: center; }
254   fieldset p { text-align: left; }
255   a img { border: none; }
256  </style>
257 </head>
258 <body>
259  <div id="container">
260   <h1><a href="http://jeenaparadies.net/projects/jlog/" title="Jlog v'.JLOG_NEW_VERSION.'"><img id="logo" src="http://jeenaparadies.net/img/jlog-logo.png" style="width: 210px; height: 120px;" alt="Jlog" /></a> SETUP</h1>
261    '.$content.'
262  </div>
263 </body>
264</html>';
265 }
266 
267  function getlang ($allowed, $default) {
268    $string = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
269    if (empty($string)) {
270      return $default;
271    }
272   
273    $accepted_languages = preg_split('/,\s*/', $string);
274   
275    $cur_l = $default;
276    $cur_q = 0;
277   
278    foreach ($accepted_languages as $accepted_language) {
279      $res = preg_match ('/^([a-z]{1,8}(?:-[a-z]{1,8})*)'.
280                        '(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i', $accepted_language, $matches);
281     
282      if (!$res) {
283        continue;
284      }
285     
286      $lang_code = explode ('-', $matches[1]);
287     
288      if (isset($matches[2])) {
289        $lang_quality = (float)$matches[2];
290      } else {
291        $lang_quality = 1.0;
292      }
293     
294      while (count ($lang_code)) {
295        if (in_array (strtolower (join ('-', $lang_code)), $allowed)) {
296          if ($lang_quality > $cur_q) {
297            $cur_l = strtolower (join ('-', $lang_code));
298            $cur_q = $lang_quality;
299            break;
300          }
301        }
302        array_pop ($lang_code);
303      }
304    }
305   
306    return $cur_l;
307  }
308
309?>
Note: See TracBrowser for help on using the browser.