@@ -26,6 +26,12 @@ class TemplateGenerator
2626 */
2727 protected $ template ;
2828
29+ /**
30+ * The image to use as a logo
31+ * @var string
32+ */
33+ protected $ image ;
34+
2935 /**
3036 * The base URl of the API
3137 * @var
@@ -42,10 +48,12 @@ class TemplateGenerator
4248 * TemplateGenerator constructor.
4349 *
4450 * @param string $template name of the template to load
51+ * @param string $image Image to use as Logo
4552 */
46- public function __construct ($ template )
53+ public function __construct ($ template, $ image )
4754 {
4855 $ this ->template = $ template ;
56+ $ this ->image = $ image ;
4957 }
5058
5159 /**
@@ -57,20 +65,34 @@ public function __construct($template)
5765 */
5866 public function get ($ object )
5967 {
68+ $ include = NULL ;
69+ if (stream_resolve_include_path ($ this ->template . DIRECTORY_SEPARATOR . $ this ->template . '.php ' ))
70+ {
71+ $ include = $ this ->template . DIRECTORY_SEPARATOR . $ this ->template . '.php ' ;
72+ }
73+
74+ if (stream_resolve_include_path ($ this ->template . '.php ' ))
75+ {
76+ $ include = $ this ->template . '.php ' ;
77+ }
78+
79+ if (stream_resolve_include_path ('PHPDraft/Out/HTML/ ' . $ this ->template . '.php ' ))
80+ {
81+ $ include = 'PHPDraft/Out/HTML/ ' . $ this ->template . '.php ' ;
82+ }
83+ if ($ include === NULL )
84+ {
85+ file_put_contents ('php://stderr ' , "Couldn't find template ' $ this ->template ' \n" );
86+ exit (1 );
87+ }
88+
6089 //Prepare base data
6190 if (is_array ($ object ->content [0 ]->content ))
6291 {
6392 foreach ($ object ->content [0 ]->attributes ->meta as $ meta )
6493 {
6594 $ this ->base_data [$ meta ->content ->key ->content ] = $ meta ->content ->value ->content ;
6695 }
67-
68- $ this ->base_data ['TITLE ' ] = $ object ->content [0 ]->meta ->title ;
69- }
70-
71- //Parse specific data
72- if (is_array ($ object ->content [0 ]->content ))
73- {
7496 foreach ($ object ->content [0 ]->content as $ value )
7597 {
7698 if ($ value ->element === 'copy ' )
@@ -88,9 +110,11 @@ public function get($object)
88110 $ this ->base_structures = $ cat ->structures ;
89111 }
90112 }
113+
114+ $ this ->base_data ['TITLE ' ] = $ object ->content [0 ]->meta ->title ;
91115 }
92116
93- include_once ' PHPDraft/Out/HTML/ ' . $ this -> template . ' .php ' ;
117+ include_once $ include ;
94118 }
95119
96120 /**
0 commit comments