| Conditions | 27 |
| Paths | 434 |
| Total Lines | 409 |
| Code Lines | 183 |
| Lines | 25 |
| Ratio | 6.11 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 61 | public function modAction($mod_action) { |
||
| 62 | switch ($mod_action) { |
||
| 63 | case 'ajax': |
||
| 64 | $html = $this->getSidebarAjaxContent(); |
||
| 65 | header('Content-Type: text/html; charset=UTF-8'); |
||
| 66 | echo $html; |
||
| 67 | break; |
||
| 68 | case 'index': |
||
| 69 | global $controller, $WT_TREE; |
||
|
|
|||
| 70 | |||
| 71 | $MAX_PEDIGREE_GENERATIONS = $WT_TREE->getPreference('MAX_PEDIGREE_GENERATIONS'); |
||
| 72 | |||
| 73 | $clip_ctrl = new ClippingsCartController; |
||
| 74 | $cart = Session::get('cart'); |
||
| 75 | |||
| 76 | $controller = new PageController; |
||
| 77 | $controller |
||
| 78 | ->setPageTitle($this->getTitle()) |
||
| 79 | ->PageHeader() |
||
| 80 | ->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL) |
||
| 81 | ->addInlineJavascript('autocomplete();'); |
||
| 82 | |||
| 83 | echo '<script>'; |
||
| 84 | echo 'function radAncestors(elementid) {var radFamilies=document.getElementById(elementid);radFamilies.checked=true;}'; |
||
| 85 | echo '</script>'; |
||
| 86 | |||
| 87 | if (!$cart[$WT_TREE->getTreeId()]) { |
||
| 88 | echo '<h2>', I18N::translate('Family tree clippings cart'), '</h2>'; |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($clip_ctrl->action == 'add') { |
||
| 92 | $record = GedcomRecord::getInstance($clip_ctrl->id, $WT_TREE); |
||
| 93 | if ($clip_ctrl->type === 'FAM') { ?> |
||
| 94 | <form action="module.php" method="get"> |
||
| 95 | <input type="hidden" name="mod" value="clippings"> |
||
| 96 | <input type="hidden" name="mod_action" value="index"> |
||
| 97 | <input type="hidden" name="id" value="<?php echo $clip_ctrl->id; ?>"> |
||
| 98 | <input type="hidden" name="type" value="<?php echo $clip_ctrl->type; ?>"> |
||
| 99 | <input type="hidden" name="action" value="add1"> |
||
| 100 | <table> |
||
| 101 | <thead> |
||
| 102 | <tr> |
||
| 103 | <td class="topbottombar"> |
||
| 104 | <?php echo I18N::translate('Add to the clippings cart'); ?> |
||
| 105 | </td> |
||
| 106 | </tr> |
||
| 107 | </thead> |
||
| 108 | <tbody> |
||
| 109 | <tr> |
||
| 110 | <td class="optionbox"> |
||
| 111 | <input type="radio" name="others" value="parents"> |
||
| 112 | <?php echo $record->getFullName(); ?> |
||
| 113 | </td> |
||
| 114 | </tr> |
||
| 115 | <tr> |
||
| 116 | <td class="optionbox"> |
||
| 117 | <input type="radio" name="others" value="members" checked> |
||
| 118 | <?php echo /* I18N: %s is a family (husband + wife) */ I18N::translate('%s and their children', $record->getFullName()); ?> |
||
| 119 | </td> |
||
| 120 | </tr> |
||
| 121 | <tr> |
||
| 122 | <td class="optionbox"> |
||
| 123 | <input type="radio" name="others" value="descendants"> |
||
| 124 | <?php echo /* I18N: %s is a family (husband + wife) */ I18N::translate('%s and their descendants', $record->getFullName()); ?> |
||
| 125 | </td> |
||
| 126 | </tr> |
||
| 127 | </tbody> |
||
| 128 | <tfoot> |
||
| 129 | <tr> |
||
| 130 | <td class="topbottombar"><input type="submit" value="<?php echo I18N::translate('continue'); ?>"> |
||
| 131 | </td> |
||
| 132 | </tr> |
||
| 133 | </tfoot> |
||
| 134 | </table> |
||
| 135 | </form> |
||
| 136 | <?php } elseif ($clip_ctrl->type === 'INDI') { ?> |
||
| 137 | <form action="module.php" method="get"> |
||
| 138 | <input type="hidden" name="mod" value="clippings"> |
||
| 139 | <input type="hidden" name="mod_action" value="index"> |
||
| 140 | <input type="hidden" name="id" value="<?php echo $clip_ctrl->id; ?>"> |
||
| 141 | <input type="hidden" name="type" value="<?php echo $clip_ctrl->type; ?>"> |
||
| 142 | <input type="hidden" name="action" value="add1"></td></tr> |
||
| 143 | <table> |
||
| 144 | <thead> |
||
| 145 | <tr> |
||
| 146 | <td class="topbottombar"> |
||
| 147 | <?php echo I18N::translate('Add to the clippings cart'); ?> |
||
| 148 | </td> |
||
| 149 | </tr> |
||
| 150 | </thead> |
||
| 151 | <tbody> |
||
| 152 | <tr> |
||
| 153 | <td class="optionbox"> |
||
| 154 | <label> |
||
| 155 | <input type="radio" name="others" checked value="none"> |
||
| 156 | <?php echo $record->getFullName(); ?> |
||
| 157 | </label> |
||
| 158 | </td> |
||
| 159 | </tr> |
||
| 160 | <tr> |
||
| 161 | <td class="optionbox"> |
||
| 162 | <label> |
||
| 163 | <input type="radio" name="others" value="parents"> |
||
| 164 | <?php |
||
| 165 | View Code Duplication | if ($record->getSex() === 'F') { |
|
| 166 | echo /* I18N: %s is a woman's name */ I18N::translate('%s, her parents and siblings', $record->getFullName()); |
||
| 167 | } else { |
||
| 168 | echo /* I18N: %s is a man's name */ I18N::translate('%s, his parents and siblings', $record->getFullName()); |
||
| 169 | } |
||
| 170 | ?> |
||
| 171 | </label> |
||
| 172 | </td> |
||
| 173 | </tr> |
||
| 174 | <tr> |
||
| 175 | <td class="optionbox"> |
||
| 176 | <label> |
||
| 177 | <input type="radio" name="others" value="members"> |
||
| 178 | <?php |
||
| 179 | View Code Duplication | if ($record->getSex() === 'F') { |
|
| 180 | echo /* I18N: %s is a woman's name */ I18N::translate('%s, her spouses and children', $record->getFullName()); |
||
| 181 | } else { |
||
| 182 | echo /* I18N: %s is a man's name */ I18N::translate('%s, his spouses and children', $record->getFullName()); |
||
| 183 | } |
||
| 184 | ?> |
||
| 185 | </label> |
||
| 186 | </td> |
||
| 187 | </tr> |
||
| 188 | <tr> |
||
| 189 | <td class="optionbox"> |
||
| 190 | <label> |
||
| 191 | <input type="radio" name="others" value="ancestors" id="ancestors"> |
||
| 192 | <?php |
||
| 193 | View Code Duplication | if ($record->getSex() === 'F') { |
|
| 194 | echo /* I18N: %s is a woman's name */ I18N::translate('%s and her ancestors', $record->getFullName()); |
||
| 195 | } else { |
||
| 196 | echo /* I18N: %s is a man's name */ I18N::translate('%s and his ancestors', $record->getFullName()); |
||
| 197 | } |
||
| 198 | ?> |
||
| 199 | </label> |
||
| 200 | <br> |
||
| 201 | <?php echo I18N::translate('Number of generations'); ?> |
||
| 202 | <input type="text" size="5" name="level1" value="<?php echo $MAX_PEDIGREE_GENERATIONS; ?>" onfocus="radAncestors('ancestors');"> |
||
| 203 | </td> |
||
| 204 | </tr> |
||
| 205 | <tr> |
||
| 206 | <td class="optionbox"> |
||
| 207 | <label> |
||
| 208 | <input type="radio" name="others" value="ancestorsfamilies" id="ancestorsfamilies"> |
||
| 209 | <?php |
||
| 210 | View Code Duplication | if ($record->getSex() === 'F') { |
|
| 211 | echo /* I18N: %s is a woman's name */ I18N::translate('%s, her ancestors and their families', $record->getFullName()); |
||
| 212 | } else { |
||
| 213 | echo /* I18N: %s is a man's name */ I18N::translate('%s, his ancestors and their families', $record->getFullName()); |
||
| 214 | } |
||
| 215 | ?> |
||
| 216 | </label> |
||
| 217 | <br > |
||
| 218 | <?php echo I18N::translate('Number of generations'); ?> |
||
| 219 | <input type="text" size="5" name="level2" value="<?php echo $MAX_PEDIGREE_GENERATIONS; ?>" onfocus="radAncestors('ancestorsfamilies');"> |
||
| 220 | </td> |
||
| 221 | </tr> |
||
| 222 | <tr> |
||
| 223 | <td class="optionbox"> |
||
| 224 | <label> |
||
| 225 | <input type="radio" name="others" value="descendants" id="descendants"> |
||
| 226 | <?php |
||
| 227 | View Code Duplication | if ($record->getSex() === 'F') { |
|
| 228 | echo /* I18N: %s is a woman's name */ I18N::translate('%s, her spouses and descendants', $record->getFullName()); |
||
| 229 | } else { |
||
| 230 | echo /* I18N: %s is a man's name */ I18N::translate('%s, his spouses and descendants', $record->getFullName()); |
||
| 231 | } |
||
| 232 | ?> |
||
| 233 | </label> |
||
| 234 | <br > |
||
| 235 | <?php echo I18N::translate('Number of generations'); ?> |
||
| 236 | <input type="text" size="5" name="level3" value="<?php echo $MAX_PEDIGREE_GENERATIONS; ?>" onfocus="radAncestors('descendants');"> |
||
| 237 | </td> |
||
| 238 | </tr> |
||
| 239 | </tbody> |
||
| 240 | <tfoot> |
||
| 241 | <tr> |
||
| 242 | <td class="topbottombar"> |
||
| 243 | <input type="submit" value="<?php echo I18N::translate('continue'); ?>"> |
||
| 244 | </td> |
||
| 245 | </tr> |
||
| 246 | </tfoot> |
||
| 247 | </table> |
||
| 248 | </form> |
||
| 249 | <?php } elseif ($clip_ctrl->type === 'SOUR') { ?> |
||
| 250 | <form action="module.php" method="get"> |
||
| 251 | <input type="hidden" name="mod" value="clippings"> |
||
| 252 | <input type="hidden" name="mod_action" value="index"> |
||
| 253 | <input type="hidden" name="id" value="<?php echo $clip_ctrl->id; ?>"> |
||
| 254 | <input type="hidden" name="type" value="<?php echo $clip_ctrl->type; ?>"> |
||
| 255 | <input type="hidden" name="action" value="add1"></td></tr> |
||
| 256 | <table> |
||
| 257 | <thead> |
||
| 258 | <tr> |
||
| 259 | <td class="topbottombar"> |
||
| 260 | <?php echo I18N::translate('Add to the clippings cart'); ?> |
||
| 261 | </td> |
||
| 262 | </tr> |
||
| 263 | </thead> |
||
| 264 | <tbody> |
||
| 265 | <tr> |
||
| 266 | <td class="optionbox"> |
||
| 267 | <label> |
||
| 268 | <input type="radio" name="others" checked value="none"> |
||
| 269 | <?php echo $record->getFullName(); ?> |
||
| 270 | </label> |
||
| 271 | </td> |
||
| 272 | </tr> |
||
| 273 | <tr> |
||
| 274 | <td class="optionbox"> |
||
| 275 | <label> |
||
| 276 | <input type="radio" name="others" value="linked"> |
||
| 277 | <?php echo /* I18N: %s is the name of a source */ I18N::translate('%s and the individuals that reference it.', $record->getFullName()); ?> |
||
| 278 | </label> |
||
| 279 | </td> |
||
| 280 | </tr> |
||
| 281 | </tbody> |
||
| 282 | <tfoot> |
||
| 283 | <tr> |
||
| 284 | <td class="topbottombar"> |
||
| 285 | <input type="submit" value="<?php echo I18N::translate('continue'); ?>"> |
||
| 286 | </td> |
||
| 287 | </tr> |
||
| 288 | </tfoot> |
||
| 289 | </table> |
||
| 290 | </form> |
||
| 291 | <?php } |
||
| 292 | } |
||
| 293 | |||
| 294 | if (!$cart[$WT_TREE->getTreeId()]) { |
||
| 295 | if ($clip_ctrl->action != 'add') { |
||
| 296 | echo I18N::translate('The clippings cart allows you to take extracts (“clippings”) from this family tree and bundle them up into a single file for downloading and subsequent importing into your own genealogy program. The downloadable file is recorded in GEDCOM format.<br><ul><li>How to take clippings?<br>This is really simple. Whenever you see a clickable name (individual, family, or source) you can go to the Details page of that name. There you will see the <b>Add to clippings cart</b> option. When you click that link you will be offered several options to download.</li><li>How to download?<br>Once you have items in your cart, you can download them just by clicking the “Download” link. Follow the instructions and links.</li></ul>'); |
||
| 297 | ?> |
||
| 298 | <form method="get" name="addin" action="module.php"> |
||
| 299 | <input type="hidden" name="mod" value="clippings"> |
||
| 300 | <input type="hidden" name="mod_action" value="index"> |
||
| 301 | <table> |
||
| 302 | <thead> |
||
| 303 | <tr> |
||
| 304 | <td colspan="2" class="topbottombar"> |
||
| 305 | <?php echo I18N::translate('Add to the clippings cart'); ?> |
||
| 306 | </td> |
||
| 307 | </tr> |
||
| 308 | </thead> |
||
| 309 | <tbody> |
||
| 310 | <tr> |
||
| 311 | <td class="optionbox"> |
||
| 312 | <input type="hidden" name="action" value="add"> |
||
| 313 | <input type="text" data-autocomplete-type="IFSRO" name="id" id="cart_item_id" size="5"> |
||
| 314 | </td> |
||
| 315 | <td class="optionbox"> |
||
| 316 | <?php echo FunctionsPrint::printFindIndividualLink('cart_item_id'); ?> |
||
| 317 | <?php echo FunctionsPrint::printFindFamilyLink('cart_item_id'); ?> |
||
| 318 | <?php echo FunctionsPrint::printFindSourceLink('cart_item_id', ''); ?> |
||
| 319 | <input type="submit" value="<?php echo I18N::translate('Add'); ?>"> |
||
| 320 | </td> |
||
| 321 | </tr> |
||
| 322 | </tbody> |
||
| 323 | </table> |
||
| 324 | </form> |
||
| 325 | <?php |
||
| 326 | } |
||
| 327 | |||
| 328 | // -- end new lines |
||
| 329 | echo I18N::translate('Your clippings cart is empty.'); |
||
| 330 | } else { |
||
| 331 | // Keep track of the INDI from the parent page, otherwise it will |
||
| 332 | // get lost after ajax updates |
||
| 333 | $pid = Filter::get('pid', WT_REGEX_XREF); |
||
| 334 | |||
| 335 | if ($clip_ctrl->action != 'download' && $clip_ctrl->action != 'add') { ?> |
||
| 336 | <table><tr><td class="width33" valign="top" rowspan="3"> |
||
| 337 | <form method="get" action="module.php"> |
||
| 338 | <input type="hidden" name="mod" value="clippings"> |
||
| 339 | <input type="hidden" name="mod_action" value="index"> |
||
| 340 | <input type="hidden" name="action" value="download"> |
||
| 341 | <input type="hidden" name="pid" value="<?php echo $pid; ?>"> |
||
| 342 | <table> |
||
| 343 | <tr><td colspan="2" class="topbottombar"><h2><?php echo I18N::translate('Download'); ?></h2></td></tr> |
||
| 344 | <tr> |
||
| 345 | <td class="descriptionbox width50 wrap"> |
||
| 346 | <?php echo I18N::translate('To reduce the size of the download, you can compress the data into a .ZIP file. You will need to uncompress the .ZIP file before you can use it.'); ?> |
||
| 347 | </td> |
||
| 348 | <td class="optionbox wrap"> |
||
| 349 | <input type="checkbox" name="Zip" value="yes"> |
||
| 350 | <?php echo I18N::translate('Zip file(s)'); ?> |
||
| 351 | </td> |
||
| 352 | </tr> |
||
| 353 | <tr> |
||
| 354 | <td class="descriptionbox width50 wrap"> |
||
| 355 | <?php echo I18N::translate('Include media (automatically zips files)'); ?> |
||
| 356 | </td> |
||
| 357 | <td class="optionbox"><input type="checkbox" name="IncludeMedia" value="yes"></td></tr> |
||
| 358 | |||
| 359 | <?php if (Auth::isManager($WT_TREE)) { ?> |
||
| 360 | <tr><td class="descriptionbox width50 wrap"><?php echo I18N::translate('Apply privacy settings'); ?></td> |
||
| 361 | <td class="optionbox"> |
||
| 362 | <input type="radio" name="privatize_export" value="none" checked> <?php echo I18N::translate('None'); ?><br> |
||
| 363 | <input type="radio" name="privatize_export" value="gedadmin"> <?php echo I18N::translate('Manager'); ?><br> |
||
| 364 | <input type="radio" name="privatize_export" value="user"> <?php echo I18N::translate('Member'); ?><br> |
||
| 365 | <input type="radio" name="privatize_export" value="visitor"> <?php echo I18N::translate('Visitor'); ?> |
||
| 366 | </td></tr> |
||
| 367 | <?php } elseif (Auth::isMember($WT_TREE)) { ?> |
||
| 368 | <tr><td class="descriptionbox width50 wrap"><?php echo I18N::translate('Apply privacy settings'); ?></td> |
||
| 369 | <td class="optionbox"> |
||
| 370 | <input type="radio" name="privatize_export" value="user" checked> <?php echo I18N::translate('Member'); ?><br> |
||
| 371 | <input type="radio" name="privatize_export" value="visitor"> <?php echo I18N::translate('Visitor'); ?> |
||
| 372 | </td></tr> |
||
| 373 | <?php } ?> |
||
| 374 | |||
| 375 | <tr><td class="descriptionbox width50 wrap"><?php echo I18N::translate('Convert from UTF-8 to ISO-8859-1'); ?></td> |
||
| 376 | <td class="optionbox"><input type="checkbox" name="convert" value="yes"></td></tr> |
||
| 377 | |||
| 378 | <tr><td class="descriptionbox width50 wrap"><?php echo I18N::translate('Add the GEDCOM media path to filenames'); ?></td> |
||
| 379 | <td class="optionbox"> |
||
| 380 | <input type="checkbox" name="conv_path" value="<?php echo Filter::escapeHtml($WT_TREE->getPreference('GEDCOM_MEDIA_PATH')); ?>"> |
||
| 381 | <span dir="auto"><?php echo Filter::escapeHtml($WT_TREE->getPreference('GEDCOM_MEDIA_PATH')); ?></span> |
||
| 382 | </td></tr> |
||
| 383 | |||
| 384 | <tr><td class="topbottombar" colspan="2"> |
||
| 385 | <input type="submit" value="<?php echo I18N::translate('Download'); ?>"> |
||
| 386 | </form> |
||
| 387 | </td></tr> |
||
| 388 | </table> |
||
| 389 | </td></tr> |
||
| 390 | </table> |
||
| 391 | <br> |
||
| 392 | |||
| 393 | <form method="get" name="addin" action="module.php"> |
||
| 394 | <input type="hidden" name="mod" value="clippings"> |
||
| 395 | <input type="hidden" name="mod_action" value="index"> |
||
| 396 | <table> |
||
| 397 | <thead> |
||
| 398 | <tr> |
||
| 399 | <td colspan="2" class="topbottombar" style="text-align:center; "> |
||
| 400 | <?php echo I18N::translate('Add to the clippings cart'); ?> |
||
| 401 | </td> |
||
| 402 | </tr> |
||
| 403 | </thead> |
||
| 404 | <tbody> |
||
| 405 | <tr> |
||
| 406 | <td class="optionbox"> |
||
| 407 | <input type="hidden" name="action" value="add"> |
||
| 408 | <input type="text" data-autocomplete-type="IFSRO" name="id" id="cart_item_id" size="8"> |
||
| 409 | </td> |
||
| 410 | <td class="optionbox"> |
||
| 411 | <?php echo FunctionsPrint::printFindIndividualLink('cart_item_id'); ?> |
||
| 412 | <?php echo FunctionsPrint::printFindFamilyLink('cart_item_id'); ?> |
||
| 413 | <?php echo FunctionsPrint::printFindSourceLink('cart_item_id'); ?> |
||
| 414 | <input type="submit" value="<?php echo I18N::translate('Add'); ?>"> |
||
| 415 | </td> |
||
| 416 | </tr> |
||
| 417 | </tbody> |
||
| 418 | </table> |
||
| 419 | </form> |
||
| 420 | |||
| 421 | |||
| 422 | <?php } ?> |
||
| 423 | <br><a href="module.php?mod=clippings&mod_action=index&action=empty"><?php echo I18N::translate('Empty the clippings cart'); ?></a> |
||
| 424 | </td></tr> |
||
| 425 | |||
| 426 | <tr><td class="topbottombar"><h2><?php echo I18N::translate('Family tree clippings cart'); ?></h2></td></tr> |
||
| 427 | |||
| 428 | <tr><td valign="top"> |
||
| 429 | <table id="mycart" class="sortable list_table width100"> |
||
| 430 | <tr> |
||
| 431 | <th class="list_label"><?php echo I18N::translate('Record'); ?></th> |
||
| 432 | <th class="list_label"><?php echo I18N::translate('Remove'); ?></th> |
||
| 433 | </tr> |
||
| 434 | <?php |
||
| 435 | foreach (array_keys($cart[$WT_TREE->getTreeId()]) as $xref) { |
||
| 436 | $record = GedcomRecord::getInstance($xref, $WT_TREE); |
||
| 437 | if ($record) { |
||
| 438 | switch ($record::RECORD_TYPE) { |
||
| 439 | case 'INDI': $icon = 'icon-indis'; break; |
||
| 440 | case 'FAM': $icon = 'icon-sfamily'; break; |
||
| 441 | case 'SOUR': $icon = 'icon-source'; break; |
||
| 442 | case 'REPO': $icon = 'icon-repository'; break; |
||
| 443 | case 'NOTE': $icon = 'icon-note'; break; |
||
| 444 | case 'OBJE': $icon = 'icon-media'; break; |
||
| 445 | default: $icon = 'icon-clippings'; break; |
||
| 446 | } |
||
| 447 | ?> |
||
| 448 | <tr><td class="list_value"> |
||
| 449 | <i class="<?php echo $icon; ?>"></i> |
||
| 450 | <?php |
||
| 451 | echo '<a href="', $record->getHtmlUrl(), '">', $record->getFullName(), '</a>'; |
||
| 452 | ?> |
||
| 453 | </td> |
||
| 454 | <td class="list_value center vmiddle"><a href="module.php?mod=clippings&mod_action=index&action=remove&id=<?php echo $xref; ?>" class="icon-remove" title="<?php echo I18N::translate('Remove'); ?>"></a></td> |
||
| 455 | </tr> |
||
| 456 | <?php |
||
| 457 | } |
||
| 458 | } |
||
| 459 | ?> |
||
| 460 | </table> |
||
| 461 | </td></tr></table> |
||
| 462 | <?php |
||
| 463 | } |
||
| 464 | break; |
||
| 465 | default: |
||
| 466 | http_response_code(404); |
||
| 467 | break; |
||
| 468 | } |
||
| 469 | } |
||
| 470 | |||
| 734 |
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state