1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * webtrees: online genealogy |
||
4 | * Copyright (C) 2018 webtrees development team |
||
5 | * This program is free software: you can redistribute it and/or modify |
||
6 | * it under the terms of the GNU General Public License as published by |
||
7 | * the Free Software Foundation, either version 3 of the License, or |
||
8 | * (at your option) any later version. |
||
9 | * This program is distributed in the hope that it will be useful, |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
12 | * GNU General Public License for more details. |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
15 | */ |
||
16 | namespace Fisharebest\Webtrees; |
||
17 | |||
18 | /** |
||
19 | * Defined in session.php |
||
20 | * |
||
21 | * @global Tree $WT_TREE |
||
22 | */ |
||
23 | global $WT_TREE; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
24 | |||
25 | use Fisharebest\Webtrees\Controller\PedigreeController; |
||
26 | use Fisharebest\Webtrees\Functions\FunctionsEdit; |
||
27 | use Fisharebest\Webtrees\Functions\FunctionsPrint; |
||
28 | |||
29 | define('WT_SCRIPT_NAME', 'pedigree.php'); |
||
30 | require './includes/session.php'; |
||
31 | |||
32 | $controller = new PedigreeController; |
||
33 | $controller |
||
34 | ->restrictAccess(Module::isActiveChart($WT_TREE, 'pedigree_chart')) |
||
35 | ->pageHeader() |
||
36 | ->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL) |
||
37 | ->addInlineJavascript(' |
||
38 | (function() { |
||
39 | autocomplete(); |
||
40 | |||
41 | jQuery("#childarrow").on("click", ".menuselect", function(e) { |
||
42 | e.preventDefault(); |
||
43 | jQuery("#childbox").slideToggle("fast"); |
||
44 | }); |
||
45 | |||
46 | jQuery("#pedigree_chart") |
||
47 | .width(' . $controller->chartsize['x'] . ') |
||
48 | .height(' . $controller->chartsize['y'] . '); |
||
49 | |||
50 | // Set variables |
||
51 | var p0, p1, p2, // Holds the ids of the boxes used in the join calculations |
||
52 | canvas = jQuery("#pedigree_canvas"), |
||
53 | ctx = canvas[0].getContext("2d"), |
||
54 | nodes = jQuery(".shadow").length, |
||
55 | gen1Start = Math.ceil(nodes / 2), |
||
56 | boxWidth = jQuery(".person_box_template").first().outerWidth(), |
||
57 | boxHeight = jQuery(".person_box_template").first().outerHeight(), |
||
58 | useOffset = true, |
||
59 | extraOffsetX = Math.floor(boxWidth / 15), // set offsets to be sensible fractions of the box size |
||
60 | extraOffsetY = Math.floor(boxHeight / 10), |
||
61 | addOffset; |
||
62 | |||
63 | // Draw joining lines on the <canvas> |
||
64 | function drawLines(context, x1, y1, x2, y2) { |
||
65 | x1 = Math.floor(x1); |
||
66 | y1 = Math.floor(y1); |
||
67 | x2 = Math.floor(x2); |
||
68 | y2 = Math.floor(y2); |
||
69 | if (' . json_encode($controller->orientation < $controller::OLDEST_AT_TOP) . ') { |
||
70 | context.moveTo(x1, y1); |
||
71 | context.lineTo(x2, y1); |
||
72 | context.lineTo(x2, y2); |
||
73 | context.lineTo(x1, y2); |
||
74 | } else { |
||
75 | context.moveTo(x1, y1); |
||
76 | context.lineTo(x1, y2); |
||
77 | context.lineTo(x2, y2); |
||
78 | context.lineTo(x2, y1); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | //Plot the lines |
||
83 | switch (' . $controller->orientation . ') { |
||
84 | case ' . $controller::PORTRAIT . ': |
||
85 | useOffset = false; |
||
86 | // Drop through |
||
87 | case ' . $controller::LANDSCAPE . ': |
||
88 | for (var i = 2; i < nodes; i+=2) { |
||
89 | p0 = jQuery("#sosa_" + i); |
||
90 | p1 = jQuery("#sosa_" + (i+1)); |
||
91 | // change line y position if within 10% of box top/bottom |
||
92 | addOffset = boxHeight / (p1.position().top - p0.position().top) > 0.9 ? extraOffsetY: 0; |
||
93 | if (' . json_encode(I18N::direction() === "rtl") . ') { |
||
94 | drawLines( |
||
95 | ctx, |
||
96 | p0.position().left + p0.width(), |
||
97 | p0.position().top + (boxHeight / 2) + addOffset, |
||
98 | p0.position().left + p0.width() + extraOffsetX, |
||
99 | p1.position().top + (boxHeight / 2) - addOffset |
||
100 | ); |
||
101 | } else { |
||
102 | drawLines( |
||
103 | ctx, |
||
104 | p0.position().left, |
||
105 | p0.position().top + (boxHeight / 2) + addOffset, |
||
106 | p0.position().left - extraOffsetX, |
||
107 | p1.position().top + (boxHeight / 2) - addOffset |
||
108 | ); |
||
109 | } |
||
110 | } |
||
111 | break; |
||
112 | case ' . $controller::OLDEST_AT_TOP . ': |
||
113 | useOffset = false; |
||
114 | // Drop through |
||
115 | case ' . $controller::OLDEST_AT_BOTTOM . ': |
||
116 | for (var i = 1; i < gen1Start; i++) { |
||
117 | p0 = jQuery("#sosa_" + i); |
||
118 | p1 = jQuery("#sosa_" + (i*2)); |
||
119 | p2 = jQuery("#sosa_" + (i*2+1)); |
||
120 | addOffset = i*2 >= gen1Start ? extraOffsetX : 0; |
||
121 | var templateHeight = p0.children(".person_box_template").outerHeight(), |
||
122 | // bHeight taks account of offset when root person has a menu icon |
||
123 | bHeight = useOffset ? (p0.outerHeight() - templateHeight) + (templateHeight / 2) : templateHeight / 2; |
||
124 | drawLines( |
||
125 | ctx, |
||
126 | p1.position().left + (boxWidth / 2) + addOffset, |
||
127 | p1.position().top + boxHeight, |
||
128 | p2.position().left + (boxWidth / 2) - addOffset, |
||
129 | p0.position().top + bHeight |
||
130 | ); |
||
131 | } |
||
132 | break; |
||
133 | } |
||
134 | |||
135 | // Set line styles & draw them |
||
136 | ctx.strokeStyle = canvas.css("color"); |
||
137 | ctx.lineWidth = ' . Theme::theme()->parameter('line-width') . '; |
||
138 | ctx.shadowColor = ' . json_encode(Theme::theme()->parameter('shadow-color')) . '; |
||
139 | ctx.shadowBlur = ' . Theme::theme()->parameter('shadow-blur') . '; |
||
140 | ctx.shadowOffsetX = ' . Theme::theme()->parameter('shadow-offset-x') . '; |
||
141 | ctx.shadowOffsetY = ' . Theme::theme()->parameter('shadow-offset-y') . '; |
||
142 | ctx.stroke(); |
||
143 | })(); |
||
144 | '); |
||
145 | |||
146 | ?> |
||
147 | <div id="pedigree-page"> |
||
148 | <h2><?php echo $controller->getPageTitle(); ?></h2> |
||
149 | |||
150 | <form name="people" id="people" method="get" action="?"> |
||
151 | <input type="hidden" name="ged" value="<?php echo $WT_TREE->getNameHtml(); ?>"> |
||
152 | <input type="hidden" name="show_full" value="<?php echo $controller->showFull(); ?>"> |
||
153 | <table class="list_table"> |
||
154 | <tbody> |
||
155 | <tr> |
||
156 | <th class="descriptionbox wrap"> |
||
157 | <?php echo I18N::translate('Individual'); ?> |
||
158 | </th> |
||
159 | <th class="descriptionbox wrap"> |
||
160 | <?php echo I18N::translate('Generations'); ?> |
||
161 | </th> |
||
162 | <th class="descriptionbox wrap"> |
||
163 | <?php echo I18N::translate('Layout'); ?> |
||
164 | </th> |
||
165 | <th class="descriptionbox wrap"> |
||
166 | <?php echo I18N::translate('Show details'); ?> |
||
167 | </th> |
||
168 | <th rowspan="2" class="facts_label03"> |
||
169 | <input type="submit" value="<?php echo /* I18N: A button label. */ I18N::translate('view'); ?>"> |
||
170 | </th> |
||
171 | </tr> |
||
172 | <tr> |
||
173 | <td class="optionbox"> |
||
174 | <input class="pedigree_form" data-autocomplete-type="INDI" type="text" id="rootid" name="rootid" |
||
175 | size="3" value="<?php echo $controller->root->getXref(); ?>"> |
||
176 | <?php echo FunctionsPrint::printFindIndividualLink('rootid'); ?> |
||
177 | </td> |
||
178 | <td class="optionbox center"> |
||
179 | <?php echo FunctionsEdit::editFieldInteger('PEDIGREE_GENERATIONS', $controller->generations, 3, $WT_TREE->getPreference('MAX_PEDIGREE_GENERATIONS')); ?> |
||
180 | </td> |
||
181 | <td class="optionbox center"> |
||
182 | <?php echo FunctionsEdit::selectEditControl('orientation', array(0 => I18N::translate('Portrait'), 1 => I18N::translate('Landscape'), 2 => I18N::translate('Oldest at top'), 3 => I18N::translate('Oldest at bottom')), null, $controller->orientation); ?> |
||
183 | </td> |
||
184 | <td class="optionbox center"> |
||
185 | <?php echo FunctionsEdit::twoStateCheckbox('show_full', $controller->showFull()); ?> |
||
186 | </td> |
||
187 | </tr> |
||
188 | </tbody> |
||
189 | </table> |
||
190 | </form> |
||
191 | <?php |
||
192 | if ($controller->error_message) { |
||
193 | echo '<p class="ui-state-error">', $controller->error_message, '</p>'; |
||
194 | |||
195 | return; |
||
196 | } |
||
197 | |||
198 | $posn = I18N::direction() === 'rtl' ? 'right' : 'left'; |
||
199 | $lastgenStart = (int) floor($controller->treesize / 2); |
||
200 | |||
201 | echo '<div id="pedigree_chart" class="layout', $controller->orientation, '">'; |
||
202 | |||
203 | //Output the chart |
||
204 | foreach ($controller->nodes as $i => $node) { |
||
205 | |||
206 | // -- draw the box |
||
207 | printf('<div id="sosa_%s" class="shadow" style="%s:%spx; top:%spx">', $i + 1, $posn, $node["x"], $node["y"]); |
||
208 | |||
209 | if ($controller->orientation === $controller::OLDEST_AT_TOP) { |
||
210 | if ($i >= $lastgenStart) { |
||
211 | echo $controller->gotoPreviousGen($i); |
||
212 | } |
||
213 | } else { |
||
214 | if (!$i) { |
||
215 | echo $controller->getMenu(); |
||
216 | } |
||
217 | } |
||
218 | |||
219 | FunctionsPrint::printPedigreePerson($controller->nodes[$i]['indi'], $controller->showFull()); |
||
220 | |||
221 | if ($controller->orientation === $controller::OLDEST_AT_TOP) { |
||
222 | if (!$i) { |
||
223 | echo $controller->getMenu(); |
||
224 | } |
||
225 | } else { |
||
226 | if ($i >= $lastgenStart) { |
||
227 | echo $controller->gotoPreviousGen($i); |
||
228 | } |
||
229 | } |
||
230 | echo '</div>'; |
||
231 | } |
||
232 | |||
233 | echo '<canvas id="pedigree_canvas" width="' . $controller->chartsize['x'] . '" height="' . $controller->chartsize['y'] . '"><p>No lines between boxes? Unfortunately your browser does not support the HTML5 canvas feature.</p></canvas>'; |
||
234 | echo '</div>'; //close #pedigree_chart |
||
235 | echo '</div>'; //close #pedigree-page |
||
236 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.