1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class FontResizer extends Extension |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
protected static $font_size_change = 0.1; |
6
|
|
|
public static function set_font_size_change($v) |
7
|
|
|
{ |
8
|
|
|
self::$font_size_change = floatval($v); |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
protected static $max_font_size = 1.7; |
12
|
|
|
public static function set_max_font_size($v) |
13
|
|
|
{ |
14
|
|
|
self::$max_font_size = floatval($v); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
protected static $min_font_size = 0.7; |
18
|
|
|
public static function set_min_font_size($v) |
19
|
|
|
{ |
20
|
|
|
self::$min_font_size = floatval($v); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public static $allowed_actions = array("increasefontsize", "decreasefontsize", "resetfontsize"); |
24
|
|
|
|
25
|
|
|
// *** TEMPLATE FUNCTIONS |
26
|
|
|
|
27
|
|
|
public function CurrentFontSizeInPercentages($currentSize = 0) |
28
|
|
|
{ |
29
|
|
|
Requirements::themedCSS("fontresizer"); |
30
|
|
|
Requirements::javascript("fontresizer/javascript/fontresizer.js"); |
31
|
|
|
Requirements::customScript("fontresizer.setMin(".(self::$min_font_size*100).");fontresizer.setMax(".(self::$max_font_size*100).");"); |
|
|
|
|
32
|
|
|
if (!$currentSize) { |
33
|
|
|
$currentSize = $this->currentFontSize(); |
34
|
|
|
} |
35
|
|
|
return $currentSize * 100; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function HasAlteredFont() |
39
|
|
|
{ |
40
|
|
|
if ($this->currentFontSize() != 1) { |
|
|
|
|
41
|
|
|
return true; |
42
|
|
|
} |
43
|
|
|
return false; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
// *** ACTIONS |
48
|
|
|
|
49
|
|
|
public function increasefontsize() |
50
|
|
|
{ |
51
|
|
|
return $this->fontAction(1 * self::$font_size_change); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function decreasefontsize() |
55
|
|
|
{ |
56
|
|
|
return $this->fontAction(-1 * self::$font_size_change); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function resetfontsize() |
60
|
|
|
{ |
61
|
|
|
Session::clear("fontsize"); |
62
|
|
|
return $this->fontAction(0); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
// *** INTERNAL FUNCTIONS |
67
|
|
|
|
68
|
|
|
protected function fontAction($change) |
69
|
|
|
{ |
70
|
|
|
$currentSize = $this->currentFontSize(); |
71
|
|
|
$currentSize = floatval($currentSize) + $change; |
72
|
|
|
Session::set("fontsize", $currentSize); |
73
|
|
|
if (Director::is_ajax()) { |
74
|
|
|
return $this->CurrentFontSizeInPercentages($currentSize); |
75
|
|
|
} else { |
76
|
|
|
Director::redirectBack(); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
return array(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
protected function currentFontSize() |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
$currentSize = Session::get("fontsize"); |
85
|
|
|
if (!$currentSize) { |
86
|
|
|
$currentSize = 1; |
87
|
|
|
} |
88
|
|
|
if ($currentSize < self::$min_font_size) { |
89
|
|
|
$currentSize = self::$min_font_size; |
90
|
|
|
} |
91
|
|
|
if ($currentSize > self::$max_font_size) { |
92
|
|
|
$currentSize = self::$max_font_size; |
93
|
|
|
} |
94
|
|
|
//make percentage |
95
|
|
|
return $currentSize; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.