forked from f446843/banshee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_layout
executable file
·142 lines (109 loc) · 2.85 KB
/
new_layout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/php
<?php
chdir(dirname($argv[0]));
require("libraries/banshee.php");
require("libraries/security.php");
/* Show help and exit
*/
function help_exit() {
printf("Usage: %s <layout name>\n", $GLOBALS["argv"][0]);
exit;
}
/* Copy file, but don't overwrite
*/
function safe_copy($source, $dest) {
if (file_exists($source) == false) {
return false;
} else if (file_exists($dest)) {
printf("Warning, destination file already exists: %s\n", $dest);
return false;
}
copy($source, $dest);
return true;
}
/* Set layout name inside file
*/
function set_layout_name($name) {
$filename = "views/banshee/layout_".$name.".xslt";
if (($file = file($filename)) === false) {
return false;
}
foreach ($file as $i => $line) {
$file[$i] = str_replace("layout_XXX", "layout_".$name, $line);
}
if (($fp = fopen($filename, "w")) == false) {
return false;
}
fputs($fp, implode("", $file));
fclose($fp);
return true;
}
/* Add layout to website
*/
function add_layout_to_website($name) {
$filename = "views/banshee/main.xslt";
if (($file = file($filename)) === false) {
return false;
}
if (($fp = fopen($filename, "w")) == false) {
return false;
}
$include = false;
foreach ($file as $i => $line) {
$text = chop($line);
if (substr($text, 0, 12) == "<xsl:include") {
$include = true;
} else if (($text == "") && $include) {
fputs($fp, "<xsl:include href=\"layout_".$name.".xslt\" />\n");
$include = false;
} else if ($text == "</xsl:template>") {
fputs($fp, "<xsl:apply-templates select=\"layout_".$name."\" />\n");
}
fputs($fp, $line);
}
fclose($fp);
return true;
}
/* Activate new layout
*/
function activate_layout($name) {
$filename = "settings/website.conf";
if (($file = file($filename)) === false) {
return false;
}
foreach ($file as $i => $line) {
if (substr($line, 0, 11) == "LAYOUT_SITE") {
$file[$i] = "LAYOUT_SITE = ".$name."\n";
}
}
if (($fp = fopen($filename, "w")) == false) {
return false;
}
fputs($fp, implode("", $file));
fclose($fp);
}
/* Start
*/
error_reporting(E_ALL & ~E_NOTICE);
if (count($argv) < 2) {
help_exit();
}
if (is_dir("settings") == false) {
exit("Not inside a Banshee website directory.\n");
}
$name = $argv[1];
$layout_characters = VALIDATE_NONCAPITALS.VALIDATE_NUMBERS."/_";
if (valid_input($name, $layout_characters) == false) {
exit("Invalid module name.\n");
}
printf("Creating new layout.\n");
safe_copy("templates/layout_XXX.xslt", "views/banshee/layout_".$name.".xslt");
safe_copy("templates/layout_XXX.css", "public/css/banshee/layout_".$name.".css");
printf("Setting layout name.\n");
set_layout_name($name);
printf("Adding layout to website.\n");
add_layout_to_website($name);
printf("Activating new layout.\n");
activate_layout($name);
print "Done.\n";
?>