22
33namespace BNETDocs \Controllers \Document ;
44
5+ use \BNETDocs \Controllers \Redirect as RedirectController ;
56use \BNETDocs \Libraries \Common ;
67use \BNETDocs \Libraries \Controller ;
78use \BNETDocs \Libraries \Document ;
@@ -25,6 +26,26 @@ public function __construct($document_id) {
2526 }
2627
2728 public function run (Router &$ router ) {
29+ $ model = new DocumentViewModel ();
30+ $ model ->document_id = $ this ->document_id ;
31+ try {
32+ $ model ->document = new Document ($ this ->document_id );
33+ } catch (DocumentNotFoundException $ e ) {
34+ $ model ->document = null ;
35+ }
36+ $ pathArray = $ router ->getRequestPathArray ();
37+ if ($ model ->document && (
38+ !isset ($ pathArray [3 ]) || empty ($ pathArray [3 ]))) {
39+ $ redirect = new RedirectController (
40+ Common::relativeUrlToAbsolute (
41+ "/document/ " . $ model ->document ->getId () . "/ "
42+ . Common::sanitizeForUrl (
43+ $ model ->document ->getTitle (), true
44+ )
45+ ), 302
46+ );
47+ return $ redirect ->run ($ router );
48+ }
2849 switch ($ router ->getRequestPathExtension ()) {
2950 case "htm " : case "html " : case "" :
3051 $ view = new DocumentViewHtmlView ();
@@ -35,13 +56,6 @@ public function run(Router &$router) {
3556 default :
3657 throw new UnspecifiedViewException ();
3758 }
38- $ model = new DocumentViewModel ();
39- $ model ->document_id = $ this ->document_id ;
40- try {
41- $ model ->document = new Document ($ this ->document_id );
42- } catch (DocumentNotFoundException $ e ) {
43- $ model ->document = null ;
44- }
4559 $ model ->user_session = UserSession::load ($ router );
4660 ob_start ();
4761 $ view ->render ($ model );
0 commit comments