1
+ <?php defined ('SYSPATH ' ) or die ('No direct script access. ' );
2
+
3
+ class Controller_Kodoc extends Controller_Template {
4
+
5
+ /**
6
+ * @var object Kodoc instance
7
+ */
8
+ public $ kodoc ;
9
+
10
+ public $ template = 'kodoc/template ' ;
11
+
12
+ public function before ()
13
+ {
14
+ if ($ this ->request ->action === 'media ' )
15
+ {
16
+ // Do not template media files
17
+ $ this ->auto_render = FALSE ;
18
+ }
19
+
20
+ return parent ::before ();
21
+ }
22
+
23
+ public function action_guide ($ lang = NULL , $ page = NULL )
24
+ {
25
+ // Create a new guide instance
26
+ $ this ->kodoc = Kodoc_Guide::factory ($ lang );
27
+
28
+ // Load the requested page content
29
+ $ this ->template ->content = $ this ->kodoc ->page ($ page );
30
+
31
+ // Set the page title
32
+ $ this ->template ->title = $ this ->kodoc ->page_title ($ page );
33
+ }
34
+
35
+ public function action_api ()
36
+ {
37
+ throw new Kohana_Exception ('API is not implemented yet ' );
38
+ }
39
+
40
+ public function action_media ($ file )
41
+ {
42
+ // Find the file extension
43
+ $ ext = pathinfo ($ file , PATHINFO_EXTENSION );
44
+
45
+ // Remove the extension from the filename
46
+ $ file = substr ($ file , 0 , -(strlen ($ ext ) + 1 ));
47
+
48
+ if ($ file = Kohana::find_file ('media ' , $ file , $ ext ))
49
+ {
50
+ // Send the file content as the response
51
+ $ this ->request ->response = file_get_contents ($ file );
52
+ }
53
+ else
54
+ {
55
+ // Return a 404 status
56
+ $ this ->request ->status = 404 ;
57
+ }
58
+
59
+ // Set the content type for this extension
60
+ $ this ->request ->headers ['Content-Type ' ] = File::mime_by_ext ($ ext );
61
+ }
62
+
63
+ public function after ()
64
+ {
65
+ if ($ this ->auto_render )
66
+ {
67
+ // Attach the menu to the template
68
+ $ this ->template ->menu = $ this ->kodoc ->page ('menu ' );
69
+
70
+ // Get the media route
71
+ $ media = Route::get ('kodoc_media ' );
72
+
73
+ echo $ e ;
74
+
75
+ // Add styles
76
+ $ this ->template ->styles = array (
77
+ $ media ->uri (array ('file ' => 'css/print.css ' )) => 'print ' ,
78
+ $ media ->uri (array ('file ' => 'css/screen.css ' )) => 'screen ' ,
79
+ $ media ->uri (array ('file ' => 'css/kodoc.css ' )) => 'screen ' ,
80
+ );
81
+ }
82
+
83
+ return parent ::after ();
84
+ }
85
+
86
+ } // End Kodoc
0 commit comments