1
#!/bin/bash
2
3
function bok_showHelp(){
4
  cat <<EOF
5
USAGE: belokan.sh APPNAME
6
7
This will create a new 'APPNAME' directory containing a standard directory
8
tree for a Belokan project.
9
EOF
10
}
11
12
function bok_new(){
13
  bok_appName=$1
14
  mkdir $bok_appName;
15
  cd $bok_appName;
16
  mkdir cache controllers langs lib logs models var
17
  mkdir -p public/{js,img,css,files} views/_{layouts/default,plugins}
18
  touch config.php public/index.php controllers/{Home,HttpErrors}.php 
19
  touch views/_layouts/default/{before,after}.phtml
20
  mkdir views/{home,httperrors}
21
  touch views/home/default.phtml views/httperrors/e404.phtml
22
  cat >config.php <<EOF
23
<?php
24
25
\$${bok_appName}Dir = dirname(__FILE__);
26
27
return array (
28
  'dir' => array (
29
    'models'      => \$${bok_appName}Dir.'/models/',
30
    'views'       => \$${bok_appName}Dir.'/views/',
31
    'controllers' => \$${bok_appName}Dir.'/controllers/',
32
    'public'      => \$${bok_appName}Dir.'/public/',
33
    'lib'         => \$${bok_appName}Dir.'/lib/',
34
    'logs'        => \$${bok_appName}Dir.'/logs/', // should be writable by www-data
35
    'cache'       => \$${bok_appName}Dir.'/cache/',
36
    'var'         => \$${bok_appName}Dir.'/var/'
37
  ),
38
  
39
  'db' => array (
40
    'host'       => '',
41
    'user'       => '',
42
    'pass'       => '',
43
    'base'       => '',
44
    'persistent' => false // true to make persistent connections
45
  ),
46
47
  'intl' => array (
48
    'enabled' => false, // true to enable internationalisation
49
    'lang'    => 'en', // change this before view rendering to set the language
50
    'default' => 'en' // default language if 'lang' is unavailabe
51
  ),
52
  
53
  'log' => array (
54
    'autosave' => true, // false to disable autosaving logs
55
    'belokan'  => true
56
  )
57
);
58
EOF
59
  cat >public/index.php <<EOF
60
<?php
61
62
// this suppose you have Belokan somewhere in your include_path.
63
require_once 'Belokan/Belokan.php';
64
65
\$${bok_appName} = new Belokan(realpath('../config.php'));
66
\$${bok_appName}->run();
67
EOF
68
  cat >controllers/Home.php <<EOF
69
<?php
70
71
class HomeController extends Belokan_Controller {
72
73
  public function defaultAction ()
74
  {
75
    \$this->_view->title = '${bok_appName}';
76
    \$this->_view->message = 'Hello, World!';
77
  }
78
79
}
80
EOF
81
  cat >controllers/HttpErrors.php <<EOF
82
<?php
83
84
class HttpErrorsController extends Belokan_Controller {
85
86
  public function e404 ()
87
  {
88
    header('HTTP/1.1 404 Not Found');
89
    \$this->_view->title = 'Error: 404 Not Found';
90
  }
91
92
}
93
EOF
94
  cat >views/_layouts/default/before.phtml <<EOF
95
<!DOCTYPE html>
96
<html dir="ltr" xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
97
  <head>
98
    <title><?php echo \$this->title; ?></title>
99
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
100
  </head>
101
  <body>
102
    <h1><?php echo \$this->title; ?></h1>
103
    <div id="main">
104
EOF
105
  cat >views/_layouts/default/after.phtml <<EOF
106
    </div>
107
  </body>
108
</html>
109
EOF
110
  cat >views/home/default.phtml <<EOF
111
<p><?php echo \$this->message; ?></p>
112
EOF
113
  cat >views/httperrors/e404.phtml <<EOF
114
<p>Sorry, this page does not exists!</p>
115
<p>You could go to the <a href="/">home page</a> or contact us if you believe this is a problem.</p>
116
EOF
117
}
118
119
# main:
120
121
case "$1" in
122
  --help|-h) bok_showHelp ;;
123
  *) bok_new "$1" ;;
124
esac
125
126
exit 0;