|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
*@author: nicolaas [at] sunnysideup.co.nz |
|
4
|
|
|
*@description 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
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class TemplateOverviewPage_Controller extends Page_Controller |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
12
|
|
|
"showmore" => true, |
|
13
|
|
|
"quicklist" => true, |
|
14
|
|
|
"listofobjectsused" => true |
|
15
|
|
|
); |
|
16
|
|
|
|
|
17
|
|
|
public function init() |
|
18
|
|
|
{ |
|
19
|
|
|
parent::init(); |
|
20
|
|
|
if (!Director::is_cli() && !Director::isDev() && !Permission::check('ADMIN')) { |
|
21
|
|
|
return Security::permissionFailure(); |
|
22
|
|
|
} |
|
23
|
|
|
Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js"); |
|
24
|
|
|
Requirements::javascript('templateoverview/javascript/TemplateOverviewPage.js'); |
|
25
|
|
|
Requirements::css("templateoverview/css/TemplateOverviewPage.css"); |
|
26
|
|
|
if (class_exists("PrettyPhoto")) { |
|
27
|
|
|
if(method_exists('PrettyPhoto','include_code')) { |
|
28
|
|
|
PrettyPhoto::include_code(); |
|
29
|
|
|
} |
|
30
|
|
|
} else { |
|
31
|
|
|
user_error("It is recommended that you install the Sunny Side Up Pretty Photo Module", E_USER_NOTICE); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
function index() |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
return $this->renderWith(['TemplateOverviewPage', 'Page']); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function showmore($request) |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$id = $request->param("ID"); |
|
43
|
|
|
$obj = SiteTree::get()->byID(intval($id)); |
|
44
|
|
|
if ($obj) { |
|
45
|
|
|
$className = $obj->ClassName; |
|
46
|
|
|
$data = $className::get() |
|
47
|
|
|
->filter(array("ClassName" => $obj->ClassName)) |
|
48
|
|
|
->limit(200); |
|
49
|
|
|
$array = array( |
|
50
|
|
|
"Results" => $data |
|
51
|
|
|
); |
|
52
|
|
|
} else { |
|
53
|
|
|
$array = array(); |
|
54
|
|
|
} |
|
55
|
|
|
return $this->customise($array)->renderWith("TemplateOverviewPageShowMoreList"); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
public function ConfigurationDetails() |
|
60
|
|
|
{ |
|
61
|
|
|
$m = Member::currentUser(); |
|
62
|
|
|
if ($m) { |
|
63
|
|
|
if ($m->inGroup("ADMIN")) { |
|
64
|
|
|
$baseFolder = Director::baseFolder(); |
|
65
|
|
|
$myFile = $baseFolder."/".$this->project()."/_config.php"; |
|
66
|
|
|
$fh = fopen($myFile, 'r'); |
|
67
|
|
|
$string = ''; |
|
68
|
|
|
while (!feof($fh)) { |
|
69
|
|
|
$string .= fgets($fh, 1024); |
|
70
|
|
|
} |
|
71
|
|
|
fclose($fh); |
|
72
|
|
|
return $string; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
public function TestTaskLink() |
|
79
|
|
|
{ |
|
80
|
|
|
return "/dev/tasks/CheckAllTemplates/"; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function QuickListLink() |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
return $this->Link("quicklist"); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function ImagesListLink() |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
|
|
return $this->Link("listofobjectsused/Image"); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function quicklist() |
|
94
|
|
|
{ |
|
95
|
|
|
$list = $this->ListOfAllClasses(); |
|
96
|
|
|
foreach ($list as $item) { |
|
97
|
|
|
DB::alteration_message($item->ClassName); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function listofobjectsused($request) |
|
102
|
|
|
{ |
|
103
|
|
|
$classWeAreLookingFor = $request->param("ID"); |
|
104
|
|
|
$classWeAreLookingFor = singleton($classWeAreLookingFor); |
|
105
|
|
|
if ($classWeAreLookingFor instanceof DataObject) { |
|
106
|
|
|
$list = $this->ListOfAllClasses(); |
|
107
|
|
|
foreach ($list as $item) { |
|
108
|
|
|
$config = Config::inst(); |
|
109
|
|
|
$listOfImages = $config->get($item->ClassName, "has_one") |
|
110
|
|
|
+ $config->get($item->ClassName, "has_many") |
|
111
|
|
|
+ $config->get($item->ClassName, "many_many"); |
|
112
|
|
|
foreach ($listOfImages as $fieldName => $potentialImage) { |
|
113
|
|
|
$innerSingleton = singleton($potentialImage); |
|
114
|
|
|
if ($innerSingleton instanceof $classWeAreLookingFor) { |
|
115
|
|
|
DB::alteration_message($item->ClassName.".". $fieldName); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
} else { |
|
120
|
|
|
user_error("Please specify the ID for the model you are looking for - e.g. /listofobjectsused/Image/", E_USER_ERROR); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* returns a list of all SiteTree Classes |
|
126
|
|
|
* @return Array(String) |
|
|
|
|
|
|
127
|
|
|
*/ |
|
128
|
|
|
public function ListOfAllClasses() |
|
|
|
|
|
|
129
|
|
|
{ |
|
130
|
|
|
$templateOverviewPageAPI = Injector::inst()->get('TemplateOverviewPageAPI'); |
|
131
|
|
|
|
|
132
|
|
|
return $templateOverviewPageAPI->ListOfAllClasses(); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
public function TotalCount() |
|
137
|
|
|
{ |
|
138
|
|
|
return count(ClassInfo::subclassesFor("SiteTree"))-1; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
|
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.