diff options
Diffstat (limited to 'modules_v3/gedcom_favorites/module.php')
| -rw-r--r-- | modules_v3/gedcom_favorites/module.php | 134 |
1 files changed, 71 insertions, 63 deletions
diff --git a/modules_v3/gedcom_favorites/module.php b/modules_v3/gedcom_favorites/module.php index a984f6a047..b1193c73bd 100644 --- a/modules_v3/gedcom_favorites/module.php +++ b/modules_v3/gedcom_favorites/module.php @@ -1,6 +1,6 @@ <?php // webtrees: Web based Family History software -// Copyright (C) 2014 webtrees development team. +// Copyright (C) 2015 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2010 John Finlay @@ -21,6 +21,7 @@ use Rhumsaa\Uuid\Uuid; use WT\Auth; +use WT\Theme; /** * Class gedcom_favorites_WT_Module @@ -40,7 +41,7 @@ class gedcom_favorites_WT_Module extends WT_Module implements WT_Module_Block { } /** {@inheritdoc} */ - public function getBlock($block_id, $template=true, $cfg=null) { + public function getBlock($block_id, $template = true, $cfg = null) { global $ctype, $show_full, $PEDIGREE_FULL_DETAILS, $controller; self::updateSchema(); // make sure the favorites table has been created @@ -86,7 +87,8 @@ class gedcom_favorites_WT_Module extends WT_Module implements WT_Module_Block { break; } - $block = get_block_setting($block_id, 'block', false); + $block = get_block_setting($block_id, 'block', '0'); + if ($cfg) { foreach (array('block') as $name) { if (array_key_exists($name, $cfg)) { @@ -96,7 +98,9 @@ class gedcom_favorites_WT_Module extends WT_Module implements WT_Module_Block { } // Override GEDCOM configuration temporarily - if (isset($show_full)) $saveShowFull = $show_full; + if (isset($show_full)) { + $saveShowFull = $show_full; + } $savePedigreeFullDetails = $PEDIGREE_FULL_DETAILS; $show_full = 1; $PEDIGREE_FULL_DETAILS = 1; @@ -106,33 +110,36 @@ class gedcom_favorites_WT_Module extends WT_Module implements WT_Module_Block { $userfavs = array(); } - $id=$this->getName().$block_id; - $class=$this->getName().'_block'; - $title=$this->getTitle(); + $id = $this->getName() . $block_id; + $class = $this->getName() . '_block'; + $title = $this->getTitle(); if (Auth::check()) { $controller - ->addExternalJavascript(WT_STATIC_URL . 'js/autocomplete.js') + ->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL) ->addInlineJavascript('autocomplete();'); } $content = ''; - $style = 2; // 1 means "regular box", 2 means "wide box" if ($userfavs) { foreach ($userfavs as $key=>$favorite) { - if (isset($favorite['id'])) $key=$favorite['id']; - $removeFavourite = '<a class="font9" href="index.php?ctype='.$ctype.'&action=deletefav&favorite_id='.$key.'" onclick="return confirm(\''.WT_I18N::translate('Are you sure you want to remove this item from your list of favorites?').'\');">'.WT_I18N::translate('Remove').'</a> '; - if ($favorite['type']=='URL') { - $content .= '<div id="boxurl'.$key.'.0" class="person_box">'; - if ($ctype=='user' || WT_USER_GEDCOM_ADMIN) $content .= $removeFavourite; - $content .= '<a href="'.$favorite['url'].'"><b>'.$favorite['title'].'</b></a>'; - $content .= '<br>'.$favorite['note']; + if (isset($favorite['id'])) { + $key = $favorite['id']; + } + $removeFavourite = '<a class="font9" href="index.php?ctype=' . $ctype . '&action=deletefav&favorite_id=' . $key . '" onclick="return confirm(\'' . WT_I18N::translate('Are you sure you want to remove this item from your list of favorites?') . '\');">' . WT_I18N::translate('Remove') . '</a> '; + if ($favorite['type'] == 'URL') { + $content .= '<div id="boxurl' . $key . '.0" class="person_box">'; + if ($ctype == 'user' || WT_USER_GEDCOM_ADMIN) { + $content .= $removeFavourite; + } + $content .= '<a href="' . $favorite['url'] . '"><b>' . $favorite['title'] . '</b></a>'; + $content .= '<br>' . $favorite['note']; $content .= '</div>'; } else { - $record=WT_GedcomRecord::getInstance($favorite['gid']); + $record = WT_GedcomRecord::getInstance($favorite['gid']); if ($record && $record->canShow()) { if ($record instanceof WT_Individual) { - $content .= '<div id="box'.$favorite["gid"].'.0" class="person_box action_header'; + $content .= '<div id="box' . $favorite["gid"] . '.0" class="person_box action_header'; switch ($record->getsex()) { case 'M': break; @@ -144,54 +151,54 @@ class gedcom_favorites_WT_Module extends WT_Module implements WT_Module_Block { break; } $content .= '">'; - if ($ctype=="user" || WT_USER_GEDCOM_ADMIN) $content .= $removeFavourite; - ob_start(); - print_pedigree_person($record, $style); - $content .= ob_get_clean(); + if ($ctype == "user" || WT_USER_GEDCOM_ADMIN) { + $content .= $removeFavourite; + } + $content .= Theme::theme()->individualBoxLarge($record); $content .= $favorite['note']; $content .= '</div>'; } else { - $content .= '<div id="box'.$favorite['gid'].'.0" class="person_box">'; - if ($ctype=='user' || WT_USER_GEDCOM_ADMIN) { + $content .= '<div id="box' . $favorite['gid'] . '.0" class="person_box">'; + if ($ctype == 'user' || WT_USER_GEDCOM_ADMIN) { $content .= $removeFavourite; } $content .= $record->format_list('span'); - $content .= '<br>'.$favorite['note']; + $content .= '<br>' . $favorite['note']; $content .= '</div>'; } } } } } - if ($ctype=='user' || WT_USER_GEDCOM_ADMIN) { + if ($ctype == 'user' || WT_USER_GEDCOM_ADMIN) { $uniqueID = Uuid::uuid4(); // This block can theoretically appear multiple times, so use a unique ID. $content .= '<div class="add_fav_head">'; - $content .= '<a href="#" onclick="return expand_layer(\'add_fav'.$uniqueID.'\');">'.WT_I18N::translate('Add a new favorite').'<i id="add_fav'.$uniqueID.'_img" class="icon-plus"></i></a>'; + $content .= '<a href="#" onclick="return expand_layer(\'add_fav' . $uniqueID . '\');">' . WT_I18N::translate('Add a new favorite') . '<i id="add_fav' . $uniqueID . '_img" class="icon-plus"></i></a>'; $content .= '</div>'; - $content .= '<div id="add_fav'.$uniqueID.'" style="display: none;">'; + $content .= '<div id="add_fav' . $uniqueID . '" style="display: none;">'; $content .= '<form name="addfavform" method="get" action="index.php">'; $content .= '<input type="hidden" name="action" value="addfav">'; - $content .= '<input type="hidden" name="ctype" value="'.$ctype.'">'; - $content .= '<input type="hidden" name="ged" value="'.WT_GEDCOM.'">'; + $content .= '<input type="hidden" name="ctype" value="' . $ctype . '">'; + $content .= '<input type="hidden" name="ged" value="' . WT_GEDCOM . '">'; $content .= '<div class="add_fav_ref">'; - $content .= '<input type="radio" name="fav_category" value="record" checked="checked" onclick="jQuery(\'#gid'.$uniqueID.'\').removeAttr(\'disabled\'); jQuery(\'#url, #favtitle\').attr(\'disabled\',\'disabled\').val(\'\');">'; - $content .= '<label for="gid'.$uniqueID.'">'.WT_I18N::translate('Enter an individual, family, or source ID').'</label>'; - $content .= '<input class="pedigree_form" data-autocomplete-type="IFSRO" type="text" name="gid" id="gid'.$uniqueID.'" size="5" value="">'; - $content .= ' '.print_findindi_link('gid'.$uniqueID); - $content .= ' '.print_findfamily_link('gid'.$uniqueID); - $content .= ' '.print_findsource_link('gid'.$uniqueID); - $content .= ' '.print_findrepository_link('gid'.$uniqueID); - $content .= ' '.print_findnote_link('gid'.$uniqueID); - $content .= ' '.print_findmedia_link('gid'.$uniqueID); + $content .= '<input type="radio" name="fav_category" value="record" checked onclick="jQuery(\'#gid' . $uniqueID . '\').removeAttr(\'disabled\'); jQuery(\'#url, #favtitle\').attr(\'disabled\',\'disabled\').val(\'\');">'; + $content .= '<label for="gid' . $uniqueID . '">' . WT_I18N::translate('Enter an individual, family, or source ID') . '</label>'; + $content .= '<input class="pedigree_form" data-autocomplete-type="IFSRO" type="text" name="gid" id="gid' . $uniqueID . '" size="5" value="">'; + $content .= ' ' . print_findindi_link('gid' . $uniqueID); + $content .= ' ' . print_findfamily_link('gid' . $uniqueID); + $content .= ' ' . print_findsource_link('gid' . $uniqueID); + $content .= ' ' . print_findrepository_link('gid' . $uniqueID); + $content .= ' ' . print_findnote_link('gid' . $uniqueID); + $content .= ' ' . print_findmedia_link('gid' . $uniqueID); $content .= '</div>'; $content .= '<div class="add_fav_url">'; - $content .= '<input type="radio" name="fav_category" value="url" onclick="jQuery(\'#url, #favtitle\').removeAttr(\'disabled\'); jQuery(\'#gid'.$uniqueID.'\').attr(\'disabled\',\'disabled\').val(\'\');">'; - $content .= '<input type="text" name="url" id="url" size="20" value="" placeholder="'.WT_Gedcom_Tag::getLabel('URL').'" disabled="disabled"> '; - $content .= '<input type="text" name="favtitle" id="favtitle" size="20" value="" placeholder="'.WT_I18N::translate('Title').'" disabled="disabled">'; - $content .= '<p>'.WT_I18N::translate('Enter an optional note about this favorite').'</p>'; + $content .= '<input type="radio" name="fav_category" value="url" onclick="jQuery(\'#url, #favtitle\').removeAttr(\'disabled\'); jQuery(\'#gid' . $uniqueID . '\').attr(\'disabled\',\'disabled\').val(\'\');">'; + $content .= '<input type="text" name="url" id="url" size="20" value="" placeholder="' . WT_Gedcom_Tag::getLabel('URL') . '" disabled> '; + $content .= '<input type="text" name="favtitle" id="favtitle" size="20" value="" placeholder="' . WT_I18N::translate('Title') . '" disabled>'; + $content .= '<p>' . WT_I18N::translate('Enter an optional note about this favorite') . '</p>'; $content .= '<textarea name="favnote" rows="6" cols="50"></textarea>'; $content .= '</div>'; - $content .= '<input type="submit" value="'.WT_I18N::translate('Add').'">'; + $content .= '<input type="submit" value="' . WT_I18N::translate('Add') . '">'; $content .= '</form></div>'; } @@ -204,10 +211,9 @@ class gedcom_favorites_WT_Module extends WT_Module implements WT_Module_Block { if ($template) { if ($block) { - require WT_THEME_DIR.'templates/block_small_temp.php'; - } else { - require WT_THEME_DIR.'templates/block_main_temp.php'; + $class .= ' small_inner_block'; } + return Theme::theme()->formatBlock($id, $title, $class, $content); } else { return $content; } @@ -231,13 +237,13 @@ class gedcom_favorites_WT_Module extends WT_Module implements WT_Module_Block { /** {@inheritdoc} */ public function configureBlock($block_id) { if (WT_Filter::postBool('save') && WT_Filter::checkCsrf()) { - set_block_setting($block_id, 'block', WT_Filter::postBool('block')); - exit; + set_block_setting($block_id, 'block', WT_Filter::postBool('block')); } - require_once WT_ROOT.'includes/functions/functions_edit.php'; + require_once WT_ROOT . 'includes/functions/functions_edit.php'; + + $block = get_block_setting($block_id, 'block', '0'); - $block=get_block_setting($block_id, 'block', false); echo '<tr><td class="descriptionbox wrap width33">'; echo /* I18N: label for a yes/no option */ WT_I18N::translate('Add a scrollbar when block contents grow'); echo '</td><td class="optionbox">'; @@ -274,19 +280,19 @@ class gedcom_favorites_WT_Module extends WT_Module implements WT_Module_Block { //-- make sure this is not a duplicate entry $sql = "SELECT SQL_NO_CACHE 1 FROM `##favorite` WHERE"; if (!empty($favorite['gid'])) { - $sql.=" xref=?"; - $vars=array($favorite['gid']); + $sql .= " xref=?"; + $vars = array($favorite['gid']); } else { - $sql.=" url=?"; - $vars=array($favorite['url']); + $sql .= " url=?"; + $vars = array($favorite['url']); } - $sql.=" AND gedcom_id=?"; - $vars[]=$favorite['gedcom_id']; + $sql .= " AND gedcom_id=?"; + $vars[] = $favorite['gedcom_id']; if ($favorite['user_id']) { - $sql.=" AND user_id=?"; - $vars[]=$favorite['user_id']; + $sql .= " AND user_id=?"; + $vars[] = $favorite['user_id']; } else { - $sql.=" AND user_id IS NULL"; + $sql .= " AND user_id IS NULL"; } if (WT_DB::prepare($sql)->execute($vars)->fetchOne()) { @@ -311,7 +317,7 @@ class gedcom_favorites_WT_Module extends WT_Module implements WT_Module_Block { return WT_DB::prepare( - "SELECT SQL_CACHE favorite_id AS id, user_id, gedcom_id, xref AS gid, favorite_type AS type, title, note, url". + "SELECT SQL_CACHE favorite_id AS id, user_id, gedcom_id, xref AS gid, favorite_type AS type, title, note, url" . " FROM `##favorite` WHERE gedcom_id=? AND user_id IS NULL") ->execute(array($gedcom_id)) ->fetchAll(PDO::FETCH_ASSOC); @@ -323,10 +329,12 @@ class gedcom_favorites_WT_Module extends WT_Module implements WT_Module_Block { protected static function updateSchema() { // Create tables, if not already present try { - WT_DB::updateSchema(WT_ROOT.WT_MODULES_DIR.'gedcom_favorites/db_schema/', 'FV_SCHEMA_VERSION', 4); + WT_DB::updateSchema(WT_ROOT . WT_MODULES_DIR . 'gedcom_favorites/db_schema/', 'FV_SCHEMA_VERSION', 4); } catch (PDOException $ex) { // The schema update scripts should never fail. If they do, there is no clean recovery. - die($ex); + WT_FlashMessages::addMessage($ex->getMessage(), 'danger'); + header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'site-unavailable.php'); + throw $ex; } } } |
