OSDN Git Service

now rewriting
[pukiwiki/pukiwiki_devel.git] / bin / pkwk14.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: pkwk14.php,v 1.6 2009/01/13 15:06:18 henoheno Exp $
4 // Copyright (C) 2009 PukiWiki Developers Team
5 // License: GPL v2 or (at your option) any later version
6 //
7 // PukiWiki administration script for CLI environment
8
9
10 # Name and Usage --------------------------------------------
11 define('PKWK_CLI_NAME', $argv[0]);
12 //define('PKWK_CLI_PATH', rtrim(getcwd(), '/\\'));
13
14 function usage()
15 {
16         warn('Usage: PKWK_ROOT=path/to/pukiwiki php ' . PKWK_CLI_NAME);
17         exit(1);
18 }
19
20 # Safety ----------------------------------------------------
21 if (php_sapi_name() != 'cli') {
22         echo 'pkwk: Error: Seems not CLI';
23         exit;
24 }
25
26 # Error reporting -------------------------------------------
27
28 //error_reporting(0); // Nothing
29 //error_reporting(E_ERROR | E_PARSE); // Avoid E_WARNING, E_NOTICE, etc
30 error_reporting(E_ALL); // Debug purpose
31
32 # Common functions ------------------------------------------
33 function warn($string = ''){ fwrite(STDERR, $string . "\n"); }
34 function err( $string = ''){ warn($string); exit(1);  }
35
36 function load_once($filepath)
37 {
38         if (strpos($filepath, ':') !== FALSE) {
39                 err('load: Error: URL-like string');
40         }
41
42         require_once($filepath);
43 }
44
45
46 # Environment variables -------------------------------------
47
48 $env_default => array(
49         // ENVIRONMENT     => DEFAULT
50         'PKWK_ROOT'        => '.',
51         'PKWK_LIB_DIR',    => 'lib',
52         'PKWK_PLUGIN_DIR', => 'plugin',
53         'PKWK_SKIN_DIR',   => 'skin',
54         'PKWK_IMAGE_DIR',  => 'image',
55         'PKWK_DATA_HOME'   => '.',
56 );
57
58 foreach(array_keys($env_default as $key) {
59         if (isset($_ENV[$key])) {
60                 $env_default[$key] = rtrim($_ENV[$key], '/\\') . '/';
61         }
62 }
63
64
65 //              if (! file_exists($dirs[$key])) {
66 //                      err('Error: [' . $key . ] No such directory: ' . $dirs[$key]);
67 //              }
68
69
70 # Load libraries --------------------------------------------
71
72 define('LIB_DIR', $env['PKWK_ROOT'] . '/' . $env['PKWK_LIB_DIR'] . '/');
73 if (! file_exists(LIB_DIR)) {
74         err('Error: LIB_DIR not found: ' . LIB_DIR);
75 }
76
77 load_once(LIB_DIR . 'func.php');
78 load_once(LIB_DIR . 'file.php');
79 load_once(LIB_DIR . 'html.php');
80 load_once(LIB_DIR . 'backup.php');
81
82 load_once(LIB_DIR . 'convert_html.php');
83 load_once(LIB_DIR . 'make_link.php');
84 load_once(LIB_DIR . 'diff.php');
85 load_once(LIB_DIR . 'config.php');
86 load_once(LIB_DIR . 'link.php');
87 load_once(LIB_DIR . 'auth.php');
88 load_once(LIB_DIR . 'proxy.php');
89 if (! extension_loaded('mbstring')) {
90         load_once(LIB_DIR . 'mbstring.php');
91 }
92
93 load_once(LIB_DIR . 'mail.php');
94 load_once(LIB_DIR . 'spam.php');
95
96
97 # Default variables 2 ---------------------------------------
98
99 define('DATA_HOME', './');
100 // Where to
101 //   * pukiwiki.ini.php
102 //   * xxx_DIR
103
104 if (! defined('LANG'))    define('LANG',    'ja');
105 if (! defined('UI_LANG')) define('UI_LANG', LANG);
106
107 if (! defined('DATA_DIR'))    define('DATA_DIR',      DATA_HOME . 'wiki/'     );
108 if (! defined('DIFF_DIR'))    define('DIFF_DIR',      DATA_HOME . 'diff/'     );
109 if (! defined('BACKUP_DIR'))  define('BACKUP_DIR',    DATA_HOME . 'backup/'   );
110 if (! defined('CACHE_DIR'))   define('CACHE_DIR',     DATA_HOME . 'cache/'    );
111 if (! defined('UPLOAD_DIR'))  define('UPLOAD_DIR',    DATA_HOME . 'attach/'   );
112 if (! defined('COUNTER_DIR')) define('COUNTER_DIR',   DATA_HOME . 'counter/'  );
113 if (! defined('PLUGIN_DIR'))  define('PLUGIN_DIR',    DATA_HOME . 'plugin/'   );
114
115 if (! defined('SKIN_DIR')) define('SKIN_DIR', 'skin/');
116 if (! defined('IMAGE_DIR')) define('IMAGE_DIR', 'image/');
117
118 switch (LANG) {
119 case 'ja':
120         if (! defined('ZONE'))     define('ZONE', 'JST');
121         if (! defined('ZONETIME')) define('ZONETIME', 9 * 3600); // JST = GMT + 9
122         break;
123 default  :
124         if (! defined('ZONE'))     define('ZONE', 'GMT');
125         if (! defined('ZONETIME')) define('ZONETIME', 0);
126         break;
127 }
128
129 //$script = 'http://localhost.example.org/';
130
131 # Load libraries --------------------------------------------
132 // init.php now fails
133
134 // Load *.ini.php files and init PukiWiki
135 //require(LIB_DIR . 'init.php');
136
137
138 # Start -----------------------------------------------------
139
140 usage();
141
142 ?>