3
* $RCSfile: create-module.php,v $
5
* Gallery - a web based photo album viewer and editor
6
* Copyright (C) 2000-2006 Bharat Mediratta
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or (at
11
* your option) any later version.
13
* This program is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
22
ini_set('error_reporting', 2047);
23
if (!empty($_SERVER['SERVER_NAME'])) {
24
print "You must run this from the command line\n";
28
if (!file_exists('modules')) {
29
print "You must run this from the gallery2 directory\n";
35
if (function_exists('posix_getlogin')) {
36
$author = posix_getlogin();
37
$tmp = posix_getpwnam($author);
38
if (!empty($tmp['gecos'])) {
39
$authorFullName = $tmp['gecos'];
43
require_once(dirname(__FILE__) . '/../../../lib/smarty/Smarty.class.php');
44
if (!empty($_ENV['TMP'])) {
45
$tmpdir = $_ENV['TMP'];
49
$tmpdir .= "/g2_" . rand(1, 30000);
50
if (file_exists($tmpdir)) {
51
print "Tmp dir already exists: $tmpdir\n";
55
if (!mkdir($tmpdir)) {
56
print "Unable to make tmp dir: $tmpdir\n";
60
$smarty = new Smarty();
61
$smarty->compile_dir = $tmpdir;
62
$smarty->error_reporting = error_reporting();
63
$smarty->debugging = true;
64
$smarty->use_sub_dirs = false;
65
$smarty->template_dir = dirname(__FILE__);
68
* Gather any info we need from the user
70
if (!empty($author)) {
71
$defaultModuleName = 'Hello ' . ucfirst($author);
73
$defaultModuleName = 'Hello World';
76
while (empty($moduleName)) {
77
$moduleName = ask('What is the name of your module?', $defaultModuleName);
80
while (empty($moduleId)) {
81
$moduleId = ask('What is the id of your module?',
82
strtolower(preg_replace('/ /', '', $moduleName)));
84
$moduleId = preg_replace('/\W/', '', $moduleId);
85
$ucModuleId = ucfirst($moduleId);
87
$smarty->assign('moduleId', $moduleId);
88
$smarty->assign('ucModuleId', $ucModuleId);
89
$smarty->assign('moduleName', $moduleName);
90
$smarty->assign('author', $author);
91
$smarty->assign('authorFullName', $authorFullName);
92
$smarty->assign('viewName', 'MyPage');
93
$smarty->assign('mapName', "${ucModuleId}Map");
96
* Start building things!
99
/* Make the module directory */
100
$modulePath = 'modules/' . $moduleId;
101
if (file_exists($modulePath)) {
102
error("$modulePath already exists!");
104
mkdir($modulePath) || error("Can't mkdir($modulePath)");
107
/* Create module.inc */
108
$fd = safe_fopen("$modulePath/module.inc");
109
fwrite($fd, $smarty->fetch(dirname(__FILE__) . '/module.inc.tpl'));
112
/* Create our sample view and template */
113
$fd = safe_fopen("$modulePath/MyPage.inc");
114
fwrite($fd, $smarty->fetch(dirname(__FILE__) . '/MyPage.inc.tpl'));
117
mkdir("$modulePath/templates");
118
$fd = safe_fopen("$modulePath/templates/MyPage.tpl");
119
fwrite($fd, $smarty->fetch(dirname(__FILE__) . '/MyPage.tpl.tpl'));
125
mkdir($modulePath . '/classes');
126
mkdir($modulePath . '/classes/GalleryStorage');
128
$smarty->assign('makefileType', 'classes');
129
$fd = safe_fopen("$modulePath/classes/GNUmakefile");
130
fwrite($fd, $smarty->fetch(dirname(__FILE__) . '/GNUmakefile.tpl'));
133
$smarty->assign('makefileType', 'GalleryStorage');
134
$fd = safe_fopen("$modulePath/classes/GalleryStorage/GNUmakefile");
135
fwrite($fd, $smarty->fetch(dirname(__FILE__) . '/GNUmakefile.tpl'));
138
$fd = safe_fopen("$modulePath/classes/Maps.xml");
139
fwrite($fd, $smarty->fetch(dirname(__FILE__) . '/map.tpl'));
142
$fd = safe_fopen("$modulePath/classes/MyPageHelper.class");
143
fwrite($fd, $smarty->fetch(dirname(__FILE__) . '/MyPageHelper.class.tpl'));
146
print "* * * * * * * * * * * * * * * * * * * * * * * * * *\n";
147
print "Your module is ready! You must build it by doing: \n";
149
print " cd modules/$moduleId/classes \n";
150
print " make && make clean\n";
152
print "Then you can go to the Site Admin -> Modules \n";
153
print "page and install and activate your module!\n";
154
print "* * * * * * * * * * * * * * * * * * * * * * * * * *\n";
156
function ask($prompt, $default='') {
158
if (!empty($default)) {
162
$line = trim(fgets(STDIN));
169
function error($message) {
170
fwrite(STDERR, "$message\n");
171
fwrite(STDERR, "*** Exiting!\n");
178
if (file_exists($tmpdir)) {
179
system("rm -rf $tmpdir");
183
function safe_fopen($path) {
184
($fd = fopen($path, 'wb')) || error("Can't write to $path");
b'\\ No newline at end of file'