. */ use Zend_Session; /** * Class ClippingsCartModule */ class ClippingsCartModule extends Module implements ModuleMenuInterface, ModuleSidebarInterface { /** {@inheritdoc} */ public function getTitle() { return /* I18N: Name of a module */ I18N::translate('Clippings cart'); } /** {@inheritdoc} */ public function getDescription() { return /* I18N: Description of the “Clippings cart” module */ I18N::translate('Select records from your family tree and save them as a GEDCOM file.'); } /** {@inheritdoc} */ public function defaultAccessLevel() { return Auth::PRIV_USER; } /** {@inheritdoc} */ public function modAction($mod_action) { switch ($mod_action) { case 'ajax': $html = $this->getSidebarAjaxContent(); Zend_Session::writeClose(); header('Content-Type: text/html; charset=UTF-8'); echo $html; break; case 'index': global $controller, $WT_SESSION, $WT_TREE; $MAX_PEDIGREE_GENERATIONS = $WT_TREE->getPreference('MAX_PEDIGREE_GENERATIONS'); $clip_ctrl = new ClippingsCart; $controller = new PageController; $controller ->setPageTitle($this->getTitle()) ->PageHeader() ->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL) ->addInlineJavascript('autocomplete();'); echo ''; if (!$WT_SESSION->cart[WT_GED_ID]) { echo '

', I18N::translate('Family tree clippings cart'), '

'; } if ($clip_ctrl->action == 'add') { $person = GedcomRecord::getInstance($clip_ctrl->id); echo '

' . $person->getFullName(), '

'; if ($clip_ctrl->type === 'FAM') { ?>
type === 'INDI') { ?>

     

     

     
type === 'SOUR') { ?>
cart[WT_GED_ID]) { if ($clip_ctrl->action != 'add') { 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.
'); ?>
action != 'download' && $clip_ctrl->action != 'add') { ?>





getPreference('GEDCOM_MEDIA_PATH')); ?>


cart[WT_GED_ID]) as $xref) { $record = GedcomRecord::getInstance($xref); if ($record) { switch ($record::RECORD_TYPE) { case 'INDI': $icon = 'icon-indis'; break; case 'FAM': $icon = 'icon-sfamily'; break; case 'SOUR': $icon = 'icon-source'; break; case 'REPO': $icon = 'icon-repository'; break; case 'NOTE': $icon = 'icon-note'; break; case 'OBJE': $icon = 'icon-media'; break; default: $icon = 'icon-clippings'; break; } ?>
getHtmlUrl(), '">', $record->getFullName(), ''; ?>
getTitle(), 'module.php?mod=clippings&mod_action=index&ged=' . $WT_TREE->getNameUrl(), 'menu-clippings'); if (isset($controller->record)) { $submenu = new Menu($this->getTitle(), 'module.php?mod=clippings&mod_action=index&ged=' . $WT_TREE->getNameUrl(), 'menu-clippingscart'); $menu->addSubmenu($submenu); } if (!empty($controller->record) && $controller->record->canShow()) { $submenu = new Menu(I18N::translate('Add to clippings cart'), 'module.php?mod=clippings&mod_action=index&action=add&id=' . $controller->record->getXref(), 'menu-clippingsadd'); $menu->addSubmenu($submenu); } return $menu; } /** {@inheritdoc} */ public function defaultSidebarOrder() { return 60; } /** {@inheritdoc} */ public function hasSidebarContent() { if (Auth::isSearchEngine()) { return false; } else { // Creating a controller has the side effect of initialising the cart new ClippingsCart; return true; } } /** {@inheritdoc} */ public function getSidebarContent() { global $controller; $controller->addInlineJavascript(' jQuery("#sb_clippings_content").on("click", ".add_cart, .remove_cart", function() { jQuery("#sb_clippings_content").load(this.href); return false; }); '); return '
' . $this->getCartList() . '
'; } /** {@inheritdoc} */ public function getSidebarAjaxContent() { global $WT_SESSION; $clip_ctrl = new ClippingsCart; $add = Filter::get('add', WT_REGEX_XREF); $add1 = Filter::get('add1', WT_REGEX_XREF); $remove = Filter::get('remove', WT_REGEX_XREF); $others = Filter::get('others'); $clip_ctrl->level1 = Filter::getInteger('level1'); $clip_ctrl->level2 = Filter::getInteger('level2'); $clip_ctrl->level3 = Filter::getInteger('level3'); if ($add) { $record = GedcomRecord::getInstance($add); if ($record) { $clip_ctrl->id = $record->getXref(); $clip_ctrl->type = $record::RECORD_TYPE; $clip_ctrl->addClipping($record); } } elseif ($add1) { $record = Individual::getInstance($add1); if ($record) { $clip_ctrl->id = $record->getXref(); $clip_ctrl->type = $record::RECORD_TYPE; if ($others == 'parents') { foreach ($record->getChildFamilies() as $family) { $clip_ctrl->addClipping($family); $clip_ctrl->addFamilyMembers($family); } } elseif ($others == 'ancestors') { $clip_ctrl->addAncestorsToCart($record, $clip_ctrl->level1); } elseif ($others == 'ancestorsfamilies') { $clip_ctrl->addAncestorsToCartFamilies($record, $clip_ctrl->level2); } elseif ($others == 'members') { foreach ($record->getSpouseFamilies() as $family) { $clip_ctrl->addClipping($family); $clip_ctrl->addFamilyMembers($family); } } elseif ($others == 'descendants') { foreach ($record->getSpouseFamilies() as $family) { $clip_ctrl->addClipping($family); $clip_ctrl->addFamilyDescendancy($family, $clip_ctrl->level3); } } } } elseif ($remove) { unset ($WT_SESSION->cart[WT_GED_ID][$remove]); } elseif (isset($_REQUEST['empty'])) { $WT_SESSION->cart[WT_GED_ID] = array(); } elseif (isset($_REQUEST['download'])) { return $this->downloadForm($clip_ctrl); } return $this->getCartList(); } /** * A list for the side bar. * * @return string */ public function getCartList() { global $WT_SESSION; // Keep track of the INDI from the parent page, otherwise it will // get lost after ajax updates $pid = Filter::get('pid', WT_REGEX_XREF); if (!$WT_SESSION->cart[WT_GED_ID]) { $out = I18N::translate('Your clippings cart is empty.'); } else { $out = ''; } if ($WT_SESSION->cart[WT_GED_ID]) { $out .= '
' . I18N::translate('Empty the clippings cart') . '' . '
' . '' . I18N::translate('Download') . ''; } $record = Individual::getInstance($pid); if ($record && !array_key_exists($record->getXref(), $WT_SESSION->cart[WT_GED_ID])) { $out .= '
' . I18N::translate('Add %s to the clippings cart', $record->getFullName()) . ''; } return $out; } /** * @param Individual $person * * @return string */ public function askAddOptions(Individual $person) { $MAX_PEDIGREE_GENERATIONS = $person->getTree()->getPreference('MAX_PEDIGREE_GENERATIONS'); $out = '

' . $person->getFullName() . '

'; $out .= ''; if ($person instanceof Family) { $out .= '
' . I18N::translate('Which other links from this family would you like to add?') . '
'. I18N::translate('Add just this family record.') . '
'. I18N::translate('Add parents’ records together with this family record.') . '
'. I18N::translate('Add parents’ and children’s records together with this family record.') . '
'. I18N::translate('Add parents’ and all descendants’ records together with this family record.') . '
'; } elseif ($person instanceof Individual) { $out .= '
' . I18N::translate('Which links from this individual would you also like to add?') . '
'; } else if ($person instanceof Source) { $out .= '
' . I18N::translate('Which records linked to this source should be added?') . '
'. I18N::translate('Add just this source.') . '
'. I18N::translate('Add this source and families/individuals linked to it.') . '
'; } else { return $this->getSidebarContent(); } return $out; } /** * @param ClippingsCart $clip_ctrl * * @return string */ public function downloadForm(ClippingsCart $clip_ctrl) { global $WT_TREE; $pid = Filter::get('pid', WT_REGEX_XREF); $out = ''; $out .= '
'; if (Auth::isManager($WT_TREE)) { $out .= '' . ''; } elseif (Auth::isMember($WT_TREE)) { $out .= '' . ''; } $out .= '

'. I18N::translate('Download') . '

'. I18N::translate('Zip file(s)') . '
'. I18N::translate('Include media (automatically zips files)') . help_link('include_media') . '
' . I18N::translate('Apply privacy settings') . help_link('apply_privacy') . '' . ' ' . I18N::translate('None') . '
' . ' ' . I18N::translate('Manager') . '
' . ' ' . I18N::translate('Member') . '
' . ' ' . I18N::translate('Visitor') . '
' . I18N::translate('Apply privacy settings') . help_link('apply_privacy') . '' . ' ' . I18N::translate('Member') . '
' . ' ' . I18N::translate('Visitor') . '
'. I18N::translate('Convert from UTF-8 to ISO-8859-1') . help_link('utf8_ansi') . '
'. I18N::translate('Add the GEDCOM media path to filenames') . help_link('GEDCOM_MEDIA_PATH') . ' ' . Filter::escapeHtml($WT_TREE->getPreference('GEDCOM_MEDIA_PATH')) . '
'; return $out; } }