1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Craft; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Export variable. |
7
|
|
|
* |
8
|
|
|
* Acts as a bridge between services and templates. |
9
|
|
|
* |
10
|
|
|
* @author Bob Olde Hampsink <[email protected]> |
11
|
|
|
* @copyright Copyright (c) 2015, Bob Olde Hampsink |
12
|
|
|
* @license MIT |
13
|
|
|
* |
14
|
|
|
* @link http://github.com/boboldehampsink |
15
|
|
|
*/ |
16
|
|
|
class ExportVariable |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Return "groups" (section, groups, etc.). |
20
|
|
|
* |
21
|
|
|
* @param string $elementType |
22
|
|
|
* |
23
|
|
|
* @return array|bool |
24
|
|
|
*/ |
25
|
|
|
public function getGroups($elementType) |
26
|
|
|
{ |
27
|
|
|
// Check if elementtype can be imported |
28
|
|
|
if ($service = craft()->export->getService($elementType)) { |
29
|
|
|
|
30
|
|
|
// Return "groups" (section, groups, etc.) |
|
|
|
|
31
|
|
|
return $service->getGroups(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return false; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get template for service. |
39
|
|
|
* |
40
|
|
|
* @param string $elementType |
41
|
|
|
* |
42
|
|
|
* @return array|bool |
43
|
|
|
*/ |
44
|
|
|
public function getTemplate($elementType) |
45
|
|
|
{ |
46
|
|
|
// Check if elementtype can be imported |
47
|
|
|
if ($service = craft()->export->getService($elementType)) { |
48
|
|
|
|
49
|
|
|
// Return template |
50
|
|
|
return $service->getTemplate(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get fields of elementType. |
58
|
|
|
* |
59
|
|
|
* @param string $elementType |
60
|
|
|
* @param bool $reset |
61
|
|
|
* |
62
|
|
|
* @return array |
63
|
|
|
*/ |
64
|
|
|
public function getFields($elementType, $reset) |
65
|
|
|
{ |
66
|
|
|
// Get export vars |
67
|
|
|
$export = craft()->request->getParam('export'); |
68
|
|
|
|
69
|
|
|
// Unset non-map settings |
70
|
|
|
unset($export['limit'], $export['offset']); |
71
|
|
|
ksort($export); |
72
|
|
|
|
73
|
|
|
// Check if elementtype can be imported |
74
|
|
|
if ($service = craft()->export->getService($elementType)) { |
75
|
|
|
|
76
|
|
|
// Return fields of elementType |
77
|
|
|
return $service->getFields($export, $reset); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return false; |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get path to fieldtype's custom table row template. |
85
|
|
|
* |
86
|
|
|
* @param string $fieldHandle |
87
|
|
|
* |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function customTableRow($fieldHandle) |
91
|
|
|
{ |
92
|
|
|
// Return custom <tr> for template |
93
|
|
|
return craft()->export->getCustomTableRow($fieldHandle); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.