@@ -84,22 +84,7 @@ public function __construct($template, $image)
84
84
*/
85
85
public function get ($ object )
86
86
{
87
- $ include = null ;
88
- if (stream_resolve_include_path ('templates ' . DIRECTORY_SEPARATOR . $ this ->template . DIRECTORY_SEPARATOR . $ this ->template . '.phtml ' )) {
89
- $ include =
90
- 'templates ' . DIRECTORY_SEPARATOR . $ this ->template . DIRECTORY_SEPARATOR . $ this ->template . '.phtml ' ;
91
- }
92
- if (stream_resolve_include_path ($ this ->template . DIRECTORY_SEPARATOR . $ this ->template . '.phtml ' )) {
93
- $ include = $ this ->template . DIRECTORY_SEPARATOR . $ this ->template . '.phtml ' ;
94
- }
95
-
96
- if (stream_resolve_include_path ($ this ->template . '.phtml ' )) {
97
- $ include = $ this ->template . '.phtml ' ;
98
- }
99
-
100
- if (stream_resolve_include_path ('PHPDraft/Out/HTML/ ' . $ this ->template . '.phtml ' )) {
101
- $ include = 'PHPDraft/Out/HTML/ ' . $ this ->template . '.phtml ' ;
102
- }
87
+ $ include = $ this ->find_include_file ($ this ->template );
103
88
if ($ include === null ) {
104
89
file_put_contents ('php://stderr ' , "Couldn't find template ' $ this ->template ' \n" );
105
90
exit (1 );
@@ -143,6 +128,46 @@ public function get($object)
143
128
require_once $ include ;
144
129
}
145
130
131
+ /**
132
+ * Get the path to a file to include
133
+ *
134
+ * @param string $template The name of the template to include
135
+ * @param string $extension Extension of the file to include
136
+ *
137
+ * @return null|string File path or null if not found
138
+ */
139
+ function find_include_file ($ template , $ extension = 'phtml ' )
140
+ {
141
+ $ include = null ;
142
+ $ fextension = '. ' .$ extension ;
143
+ if (stream_resolve_include_path ('templates ' . DIRECTORY_SEPARATOR . $ template . DIRECTORY_SEPARATOR . $ template . $ fextension )) {
144
+ $ include = 'templates ' . DIRECTORY_SEPARATOR . $ template . DIRECTORY_SEPARATOR . $ template . $ fextension ;
145
+ return $ include ;
146
+ }
147
+ if (stream_resolve_include_path ('templates ' . DIRECTORY_SEPARATOR . $ template . $ fextension )) {
148
+ $ include = 'templates ' . DIRECTORY_SEPARATOR . $ template . $ fextension ;
149
+ return $ include ;
150
+ }
151
+ if (stream_resolve_include_path ($ template . DIRECTORY_SEPARATOR . $ template . $ fextension )) {
152
+ $ include = $ template . DIRECTORY_SEPARATOR . $ template . $ fextension ;
153
+ return $ include ;
154
+ }
155
+
156
+ if (stream_resolve_include_path ($ template . $ fextension )) {
157
+ $ include = $ template . $ fextension ;
158
+ return $ include ;
159
+ }
160
+
161
+ if (stream_resolve_include_path ('PHPDraft/Out/HTML/ ' . $ template . $ fextension )) {
162
+ $ include = 'PHPDraft/Out/HTML/ ' . $ template . $ fextension ;
163
+ return $ include ;
164
+ }
165
+
166
+ if ($ include === null && $ extension === 'phtml ' ) {
167
+ return $ this ->find_include_file ('default ' , $ extension );
168
+ }
169
+ }
170
+
146
171
/**
147
172
* Get an icon for a specific HTTP Method
148
173
*
0 commit comments