Completed
Push — master ( a4d8e0...f29afe )
by Nicolaas
02:13
created

code/TypographyTestPage_Controller.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Add a page to your site that allows you to view all the html that can be used in the typography section - if applied correctly.
5
 * TO DO: add a testing sheet with a list of checks to be made (e.g. italics, bold, paragraphy) - done YES / NO, a date and a person who checked it (member).
6
 */
7
8
class TypographyTestPage_Controller extends Page_Controller
9
{
10
11
    /**
12
     * @var string
13
     */
14
    private static $include_first_heading_in_test_copy = false;
15
16
    /**
17
     * @var string
18
     */
19
    private static $css_folder = '';
20
21
    /**
22
     * use this to set up alternative form
23
     * formats
24
     * @var string
25
     */
26
    private static $form_class_name = "Form";
27
28
    public static function get_css_folder()
29
    {
30
        if (Config::inst()->get("TypographyTestPage_Controller", "css_folder")) {
31
            $folder = Config::inst()->get("TypographyTestPage_Controller", "css_folder");
32
        } else {
33
            $folder = "themes/".SSViewer::current_theme()."/css/";
0 ignored issues
show
Deprecated Code introduced by
The method SSViewer::current_theme() has been deprecated with message: 4.0 Use the "SSViewer.theme" config setting instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
34
        }
35
        $fullFolder = Director::baseFolder().'/'.$folder;
36
        if (!file_exists($fullFolder)) {
37
            @mkdir($fullFolder);
38
            //user_error("could not find the default CSS folder $fullFolder");
39
            $folder = '';
40
        }
41
        return $folder;
42
    }
43
44
    private static $allowed_actions = array(
45
        "colours" => "ADMIN",
46
        "replacecolours" => "ADMIN"
47
    );
48
49
    public function init()
50
    {
51
        parent::init();
52
        Page_Controller::init();
53
    }
54
55
    public function index()
56
    {
57
        $this->Content = $this->typographyhtml();
58
        $this->Title = 'Typography Test Page';
59
        return $this->renderWith('Page');
60
    }
61
62
    public function ShowFirstHeading()
63
    {
64
        return Config::inst()->get("TypographyTestPage_Controller", "include_first_heading_in_test_copy");
65
    }
66
67
    public function colours()
68
    {
69
        $baseFolder = Director::baseFolder();
70
        require($baseFolder.'/typography/thirdparty/colourchart/csscolorchart.php');
71
        $cssPath = array($baseFolder.'/themes/', $baseFolder.$this->project()."css/");
72
        echo '<h1>CSS colors found in: ' .
73
            (is_array($cssPath)?implode($cssPath, ', '):$cssPath) . '</h1>';
74
        $themes = new CssColorChart();
75
        $colourList = $themes->listColors($cssPath);
76
        $html = DBField::create_field("HTMLText", $colourList);
77
        echo $html;
78
    }
79
80
    public function Form()
81
    {
82
        return TypographyTestForm::create($this, 'TestForm');
83
    }
84
85
    public function TestForm($data)
86
    {
87
        $this->redirectBack();
88
    }
89
90
    protected function typographyhtml()
91
    {
92
        return $this->renderWith('TypographySample');
93
    }
94
95
    public function RandomLinkExternal()
96
    {
97
        return "http://www.google.com/?q=".rand(0, 100000);
98
    }
99
100
    public function RandomLinkInternal()
101
    {
102
        return "/?q=".rand(0, 100000);
103
    }
104
105
    public function SiteColours()
106
    {
107
        if ($folder = TypographyTestPage_Controller::get_css_folder()) {
108
            Requirements::themedCSS("CssColorChart", "typography");
109
            //Requirements::javascript("typography/javascript/CssColorChart.js");
110
            $cssColorChart = new CssColorChart();
111
            return $cssColorChart->listColors(Director::baseFolder()."/".$folder);
112
        }
113
    }
114
115
    public function replacecolours()
116
    {
117
        if ($folder = Config::inst()->get("TypographyTestPage_Controller", "css_folder")) {
118
            require_once(Director::baseFolder()."/typography/thirdparty/csscolorchart.php");
119
            $cssColorChart = new CssColorChart();
120
            return $cssColorChart->replaceColours(Director::baseFolder()."/".Config::inst()->get("TypographyTestPage_Controller", "css_folder"));
121
        }
122
        return "no folder specified, use TypographyTestPage_Controller::set_css_folder()";
123
    }
124
}
125