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
<?php

/**
 * Default page model class
 * Collects required data for the controller
 */
class Page extends SiteTree {

    public static $db = array(
    );

    public static $has_one = array(
    );

    // rewrites the link targets
    public function Link($action = null) {

        // URL locale issues
        $URLLocale = Translatable::get_current_locale();
        if(preg_match('/(^[a-z]{2})_([A-Z]{2})$/', $URLLocale, $matches)) {
            $URLLocale = strtolower($matches[1])."-".strtolower($matches[2]);
        }

        // URL Live/ Stage issues
        $URLStage = Versioned::current_stage();
        if($URLStage == "Stage") $stage = "/?stage=Stage";
        else $stage = "";

        // Homepage rewriting
        if($action == "index") {
            $action = "home";
        }

        // Final link
        if($this->URLSegment == 'home' && !$action) return $URLLocale.$stage;
        else return $URLLocale."/".$this->URLSegment."/".$action.$stage;
     }

}

/**
 * Default page controller class
 * Delivers content and handles actions
 */
class Page_Controller extends ContentController {

    public function init() {
        parent::init();

        // Note: you should use SS template require tags inside your templates
        // instead of putting Requirements calls here.  However these are
        // included so that our older themes still work
        Requirements::themedCSS("layout");
        Requirements::themedCSS("typography");
        Requirements::themedCSS("form");
    }

    public function setLocale($locale) {

        Translatable::set_current_locale($locale);
    }

}

?>