示例#1
0
 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
     $action = WT_Filter::get('action');
     switch ($action) {
         case 'deletefav':
             $favorite_id = WT_Filter::getInteger('favorite_id');
             if ($favorite_id) {
                 self::deleteFavorite($favorite_id);
             }
             break;
         case 'addfav':
             $gid = WT_Filter::get('gid', WT_REGEX_XREF);
             $favnote = WT_Filter::get('favnote');
             $url = WT_Filter::getUrl('url');
             $favtitle = WT_Filter::get('favtitle');
             if ($gid) {
                 $record = WT_GedcomRecord::getInstance($gid);
                 if ($record && $record->canShow()) {
                     self::addFavorite(array('user_id' => $ctype == 'user' ? WT_USER_ID : null, 'gedcom_id' => WT_GED_ID, 'gid' => $record->getXref(), 'type' => $record::RECORD_TYPE, 'url' => null, 'note' => $favnote, 'title' => $favtitle));
                 }
             } elseif ($url) {
                 self::addFavorite(array('user_id' => $ctype == 'user' ? WT_USER_ID : null, 'gedcom_id' => WT_GED_ID, 'gid' => null, 'type' => 'URL', 'url' => $url, 'note' => $favnote, 'title' => $favtitle ? $favtitle : $url));
             }
             break;
     }
     $block = get_block_setting($block_id, 'block', false);
     if ($cfg) {
         foreach (array('block') as $name) {
             if (array_key_exists($name, $cfg)) {
                 ${$name} = $cfg[$name];
             }
         }
     }
     // Override GEDCOM configuration temporarily
     if (isset($show_full)) {
         $saveShowFull = $show_full;
     }
     $savePedigreeFullDetails = $PEDIGREE_FULL_DETAILS;
     $show_full = 1;
     $PEDIGREE_FULL_DETAILS = 1;
     $userfavs = $this->getFavorites($ctype == 'user' ? WT_USER_ID : WT_GED_ID);
     if (!is_array($userfavs)) {
         $userfavs = array();
     }
     $id = $this->getName() . $block_id;
     $class = $this->getName() . '_block';
     $title = $this->getTitle();
     if (WT_USER_ID) {
         $controller->addExternalJavascript(WT_STATIC_URL . 'js/autocomplete.js')->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 . '&amp;action=deletefav&amp;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']);
                 if ($record && $record->canShow()) {
                     if ($record instanceof WT_Individual) {
                         $content .= '<div id="box' . $favorite["gid"] . '.0" class="person_box action_header';
                         switch ($record->getsex()) {
                             case 'M':
                                 break;
                             case 'F':
                                 $content .= 'F';
                                 break;
                             case 'U':
                                 $content .= 'NN';
                                 break;
                         }
                         $content .= '">';
                         if ($ctype == "user" || WT_USER_GEDCOM_ADMIN) {
                             $content .= $removeFavourite;
                         }
                         ob_start();
                         print_pedigree_person($record, $style, 1, $key);
                         $content .= ob_get_clean();
                         $content .= $favorite['note'];
                         $content .= '</div>';
                     } else {
                         $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 .= '</div>';
                     }
                 }
             }
         }
     }
     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 .= '</div>';
         $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 .= '<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 .= '</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 .= '<textarea name="favnote" rows="6" cols="50"></textarea>';
         $content .= '</div>';
         $content .= '<input type="submit" value="' . WT_I18N::translate('Add') . '">';
         $content .= '</form></div>';
     }
     if ($template) {
         if ($block) {
             require WT_THEME_DIR . 'templates/block_small_temp.php';
         } else {
             require WT_THEME_DIR . 'templates/block_main_temp.php';
         }
     } else {
         return $content;
     }
     // Restore GEDCOM configuration
     unset($show_full);
     if (isset($saveShowFull)) {
         $show_full = $saveShowFull;
     }
     $PEDIGREE_FULL_DETAILS = $savePedigreeFullDetails;
 }
示例#2
0
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
use WT\Auth;
use WT\Log;
use WT\User;
define('WT_SCRIPT_NAME', 'message.php');
require './includes/session.php';
// Some variables are initialised from GET (so we can set initial values in URLs),
// but are submitted in POST so we can have long body text.
$subject = WT_Filter::post('subject', null, WT_Filter::get('subject'));
$body = WT_Filter::post('body');
$from_name = WT_Filter::post('from_name');
$from_email = WT_Filter::post('from_email');
$action = WT_Filter::post('action', 'compose|send', 'compose');
$to = WT_Filter::post('to', null, WT_Filter::get('to'));
$method = WT_Filter::post('method', 'messaging|messaging2|messaging3|mailto|none', WT_Filter::get('method', 'messaging|messaging2|messaging3|mailto|none', 'messaging2'));
$url = WT_Filter::postUrl('url', WT_Filter::getUrl('url'));
$controller = new WT_Controller_Simple();
$controller->setPageTitle(WT_I18N::translate('webtrees message'));
$to_user = User::findByIdentifier($to);
// Only admins can send broadcast messages
if ((!$to_user || $to == 'all' || $to == 'last_6mo' || $to == 'never_logged') && !Auth::isAdmin()) {
    // TODO, what if we have a user called "all" or "last_6mo" or "never_logged" ???
    WT_FlashMessages::addMessage(WT_I18N::translate('Message was not sent'));
    $controller->pageHeader();
    $controller->addInlineJavascript('window.opener.location.reload(); window.close();');
    exit;
}
$errors = '';
// Is this message from a member or a visitor?
if (WT_USER_ID) {
    $from = WT_USER_NAME;