public function __construct() { $xref = WT_Filter::get('mid', WT_REGEX_XREF); $this->record = WT_Media::getInstance($xref); parent::__construct(); }
if ($media && $media->canShow()) { $sort_obje[] = $media; } } // Add other media objects from the individual and any spouse-families $record_list = array($person); foreach ($person->getSpouseFamilies() as $family) { $record_list[] = $family; } foreach ($record_list as $record) { if ($record->canShow()) { foreach ($record->getFacts() as $fact) { if (!$fact->isOld()) { preg_match_all('/(?:^1|\\n\\d) OBJE @(' . WT_REGEX_XREF . ')@/', $fact->getGedcom(), $matches); foreach ($matches[1] as $match) { $media = WT_Media::getInstance($match); if (!in_array($media, $sort_obje)) { $sort_obje[] = $media; } } } } } } ?> <div id="edit_interface-page"> <h4><?php echo WT_I18N::translate('Click a row, then drag-and-drop to re-order media '); ?> </h4> <form name="reorder_form" method="post" action="edit_interface.php">
/** * add a new tag input field * * called for each fact to be edited on a form. * Fact level=0 means a new empty form : data are POSTed by name * else data are POSTed using arrays : * glevels[] : tag level * islink[] : tag is a link * tag[] : tag name * text[] : tag value * * @param string $tag fact record to edit (eg 2 DATE xxxxx) * @param string $upperlevel optional upper level tag (eg BIRT) * @param string $label An optional label to echo instead of the default * @param string $extra optional text to display after the input field * @param WT_Individual $person For male/female translations * * @return string */ function add_simple_tag($tag, $upperlevel = '', $label = '', $extra = null, WT_Individual $person = null) { global $tags, $emptyfacts, $main_fact, $FILE_FORM_accept, $xref, $bdm, $action; global $QUICK_REQUIRED_FACTS, $QUICK_REQUIRED_FAMFACTS, $PREFER_LEVEL2_SOURCES; $subnamefacts = array("NPFX", "GIVN", "SPFX", "SURN", "NSFX", "_MARNM_SURN"); preg_match('/^(?:(\\d+) (' . WT_REGEX_TAG . ') ?(.*))/', $tag, $match); list(, $level, $fact, $value) = $match; // element name : used to POST data if ($level == 0) { if ($upperlevel) { $element_name = $upperlevel . '_' . $fact; } else { $element_name = $fact; } // ex: OCCU } else { $element_name = "text[]"; } if ($level == 1) { $main_fact = $fact; } // element id : used by javascript functions if ($level == 0) { $element_id = $fact; } else { $element_id = $fact . Uuid::uuid4(); } if ($upperlevel) { $element_id = $upperlevel . '_' . $fact . Uuid::uuid4(); } // field value $islink = substr($value, 0, 1) === '@' && substr($value, 0, 2) != '@#'; if ($islink) { $value = trim(trim(substr($tag, strlen($fact) + 3)), " @\r"); } else { $value = trim(substr($tag, strlen($fact) + 3)); } if ($fact == 'REPO' || $fact == 'SOUR' || $fact == 'OBJE' || $fact == 'FAMC') { $islink = true; } if ($fact == 'SHARED_NOTE_EDIT' || $fact == 'SHARED_NOTE') { $islink = 1; $fact = "NOTE"; } // label echo "<tr id=\"", $element_id, "_tr\" "; if ($fact == "MAP" || ($fact == "LATI" || $fact == "LONG") && $value == '') { echo " style=\"display:none;\""; } echo " >"; if (in_array($fact, $subnamefacts) || $fact == "LATI" || $fact == "LONG") { echo "<td class=\"optionbox wrap width25\">"; } else { echo "<td class=\"descriptionbox wrap width25\">"; } if (WT_DEBUG) { echo $element_name, "<br>"; } // tag name if ($label) { echo $label; } elseif ($upperlevel) { echo WT_Gedcom_Tag::getLabel($upperlevel . ':' . $fact); } else { echo WT_Gedcom_Tag::getLabel($fact); } // help link // If using GEDFact-assistant window if ($action == "addnewnote_assisted") { // Do not print on GEDFact Assistant window } else { // Not all facts have help text. switch ($fact) { case 'FORM': if ($upperlevel != 'OBJE') { echo help_link($fact); } break; case 'NOTE': if ($islink) { echo help_link('edit_add_SHARED_NOTE'); } else { echo help_link($fact); } break; case 'NAME': if ($upperlevel != 'REPO') { echo help_link($fact); } break; case 'ASSO': case '_ASSO': // Some apps (including webtrees) use "2 _ASSO", since "2 ASSO" is not strictly valid GEDCOM if ($level == 1) { echo help_link('ASSO_1'); } else { echo help_link('ASSO_2'); } break; case 'ADDR': case 'AGNC': case 'CAUS': case 'DATE': case 'EMAI': case 'EMAIL': case 'EMAL': case '_EMAIL': case 'FAX': case 'OBJE': case 'PAGE': case 'PEDI': case 'PHON': case 'PLAC': case 'RELA': case 'RESN': case 'ROMN': case 'SEX': case 'SOUR': case 'STAT': case 'SURN': case 'TEMP': case 'TEXT': case 'TIME': case 'URL': case '_HEB': case '_PRIM': echo help_link($fact); break; } } // tag level if ($level > 0) { if ($fact == 'TEXT' && $level > 1) { echo "<input type=\"hidden\" name=\"glevels[]\" value=\"", $level - 1, "\">"; echo "<input type=\"hidden\" name=\"islink[]\" value=\"0\">"; echo "<input type=\"hidden\" name=\"tag[]\" value=\"DATA\">"; //-- leave data text[] value empty because the following TEXT line will //--- cause the DATA to be added echo "<input type=\"hidden\" name=\"text[]\" value=\"\">"; } echo "<input type=\"hidden\" name=\"glevels[]\" value=\"", $level, "\">"; echo "<input type=\"hidden\" name=\"islink[]\" value=\"", $islink, "\">"; echo "<input type=\"hidden\" name=\"tag[]\" value=\"", $fact, "\">"; } echo "</td>"; // value echo "<td class=\"optionbox wrap\">"; if (WT_DEBUG) { echo $tag, "<br>"; } // retrieve linked NOTE if ($fact == "NOTE" && $islink) { $note1 = WT_Note::getInstance($value); if ($note1) { $noterec = $note1->getGedcom(); preg_match("/{$value}/i", $noterec, $notematch); $value = $notematch[0]; } } if (in_array($fact, $emptyfacts) && ($value == '' || $value == 'Y' || $value == 'y')) { echo "<input type=\"hidden\" id=\"", $element_id, "\" name=\"", $element_name, "\" value=\"", $value, "\">"; if ($level <= 1) { echo '<input type="checkbox" '; if ($value) { echo ' checked="checked"'; } echo " onclick=\"if (this.checked) ", $element_id, ".value='Y'; else ", $element_id, ".value='';\">"; echo WT_I18N::translate('yes'); } } else { if ($fact == "TEMP") { echo select_edit_control($element_name, WT_Gedcom_Code_Temp::templeNames(), WT_I18N::translate('No temple - living ordinance'), $value); } else { if ($fact == "ADOP") { echo edit_field_adop($element_name, $value, '', $person); } else { if ($fact == "PEDI") { echo edit_field_pedi($element_name, $value, '', $person); } else { if ($fact == 'STAT') { echo select_edit_control($element_name, WT_Gedcom_Code_Stat::statusNames($upperlevel), '', $value); } else { if ($fact == 'RELA') { echo edit_field_rela($element_name, strtolower($value)); } else { if ($fact == 'QUAY') { echo select_edit_control($element_name, WT_Gedcom_Code_Quay::getValues(), '', $value); } else { if ($fact == '_WT_USER') { echo edit_field_username($element_name, $value); } else { if ($fact == 'RESN') { echo edit_field_resn($element_name, $value); } else { if ($fact == '_PRIM') { echo '<select id="', $element_id, '" name="', $element_name, '" >'; echo '<option value=""></option>'; echo '<option value="Y"'; if ($value == 'Y') { echo ' selected="selected"'; } echo '>', WT_I18N::translate('yes'), '</option>'; echo '<option value="N"'; if ($value == 'N') { echo ' selected="selected"'; } echo '>', WT_I18N::translate('no'), '</option>'; echo '</select>'; } else { if ($fact == 'SEX') { echo '<select id="', $element_id, '" name="', $element_name, '"><option value="M"'; if ($value == 'M') { echo ' selected="selected"'; } echo '>', WT_I18N::translate('Male'), '</option><option value="F"'; if ($value == 'F') { echo ' selected="selected"'; } echo '>', WT_I18N::translate('Female'), '</option><option value="U"'; if ($value == 'U' || empty($value)) { echo ' selected="selected"'; } echo '>', WT_I18N::translate_c('unknown gender', 'Unknown'), '</option></select>'; } else { if ($fact == 'TYPE' && $level == '3') { //-- Build the selector for the Media 'TYPE' Fact echo '<select name="text[]"><option selected="selected" value="" ></option>'; $selectedValue = strtolower($value); if (!array_key_exists($selectedValue, WT_Gedcom_Tag::getFileFormTypes())) { echo '<option selected="selected" value="', WT_Filter::escapeHtml($value), '" >', WT_Filter::escapeHtml($value), '</option>'; } foreach (WT_Gedcom_Tag::getFileFormTypes() as $typeName => $typeValue) { echo '<option value="', $typeName, '"'; if ($selectedValue == $typeName) { echo ' selected="selected"'; } echo '>', $typeValue, '</option>'; } echo '</select>'; } else { if ($fact == 'NAME' && $upperlevel != 'REPO' || $fact == '_MARNM') { // Populated in javascript from sub-tags echo "<input type=\"hidden\" id=\"", $element_id, "\" name=\"", $element_name, "\" onchange=\"updateTextName('", $element_id, "');\" value=\"", WT_Filter::escapeHtml($value), "\" class=\"", $fact, "\">"; echo '<span id="', $element_id, '_display" dir="auto">', WT_Filter::escapeHtml($value), '</span>'; echo ' <a href="#edit_name" onclick="convertHidden(\'', $element_id, '\'); return false;" class="icon-edit_indi" title="' . WT_I18N::translate('Edit name') . '"></a>'; } else { // textarea if ($fact == 'TEXT' || $fact == 'ADDR' || $fact == 'NOTE' && !$islink) { echo "<textarea id=\"", $element_id, "\" name=\"", $element_name, "\" dir=\"auto\">", WT_Filter::escapeHtml($value), "</textarea><br>"; } else { // text // If using GEDFact-assistant window if ($action == "addnewnote_assisted") { echo "<input type=\"text\" id=\"", $element_id, "\" name=\"", $element_name, "\" value=\"", WT_Filter::escapeHtml($value), "\" style=\"width:4.1em;\" dir=\"ltr\""; } else { echo "<input type=\"text\" id=\"", $element_id, "\" name=\"", $element_name, "\" value=\"", WT_Filter::escapeHtml($value), "\" dir=\"ltr\""; } echo " class=\"{$fact}\""; if (in_array($fact, $subnamefacts)) { echo " onblur=\"updatewholename();\" onkeyup=\"updatewholename();\""; } // Extra markup for specific fact types switch ($fact) { case 'DATE': echo " onblur=\"valid_date(this);\" onmouseout=\"valid_date(this);\""; break; case 'GIVN': echo ' autofocus data-autocomplete-type="GIVN"'; break; case 'LATI': echo " onblur=\"valid_lati_long(this, 'N', 'S');\" onmouseout=\"valid_lati_long(this, 'N', 'S');\""; break; case 'LONG': echo " onblur=\"valid_lati_long(this, 'E', 'W');\" onmouseout=\"valid_lati_long(this, 'E', 'W');\""; break; case 'NOTE': // Shared notes. Inline notes are handled elsewhere. echo ' data-autocomplete-type="NOTE"'; break; case 'OBJE': echo ' data-autocomplete-type="OBJE"'; break; case 'PLAC': echo ' data-autocomplete-type="PLAC"'; break; case 'REPO': echo ' data-autocomplete-type="REPO"'; break; case 'SOUR': echo ' data-autocomplete-type="SOUR"'; break; case 'SURN': case '_MARNM_SURN': echo ' data-autocomplete-type="SURN"'; break; } echo '>'; } $tmp_array = array('TYPE', 'TIME', 'NOTE', 'SOUR', 'REPO', 'OBJE', 'ASSO', '_ASSO', 'AGE'); // split PLAC if ($fact == 'PLAC') { echo "<div id=\"", $element_id, "_pop\" style=\"display: inline;\">"; echo print_specialchar_link($element_id), ' ', print_findplace_link($element_id); echo '<span onclick="jQuery(\'tr[id^=', $upperlevel, '_LATI],tr[id^=', $upperlevel, '_LONG],tr[id^=LATI],tr[id^=LONG]\').toggle(\'fast\'); return false;" class="icon-target" title="', WT_Gedcom_Tag::getLabel('LATI'), ' / ', WT_Gedcom_Tag::getLabel('LONG'), '"></span>'; echo '</div>'; if (array_key_exists('places_assistant', WT_Module::getActiveModules())) { places_assistant_WT_Module::setup_place_subfields($element_id); places_assistant_WT_Module::print_place_subfields($element_id); } } elseif (!in_array($fact, $tmp_array)) { echo print_specialchar_link($element_id); } } } } } } } } } } } } } } // MARRiage TYPE : hide text field and show a selection list if ($fact == 'TYPE' && $level == 2 && $tags[0] == 'MARR') { echo '<script>'; echo "document.getElementById('", $element_id, "').style.display='none'"; echo '</script>'; echo "<select id=\"", $element_id, "_sel\" onchange=\"document.getElementById('", $element_id, "').value=this.value;\" >"; foreach (array("Unknown", "Civil", "Religious", "Partners") as $key) { if ($key == "Unknown") { echo "<option value=\"\""; } else { echo "<option value=\"", $key, "\""; } $a = strtolower($key); $b = strtolower($value); if (@strpos($a, $b) !== false || @strpos($b, $a) !== false) { echo ' selected="selected"'; } $tmp = "MARR_" . strtoupper($key); echo ">", WT_Gedcom_Tag::getLabel($tmp), "</option>"; } echo "</select>"; } else { if ($fact == 'TYPE' && $level == 0) { $onchange = 'onchange="document.getElementById(\'' . $element_id . '\').value=this.value;"'; echo edit_field_name_type($element_name, $value, $onchange, $person); echo '<script>'; echo "document.getElementById('", $element_id, "').style.display='none';"; echo '</script>'; } } // popup links switch ($fact) { case 'DATE': echo print_calendar_popup($element_id); // Allow the GEDFact_assistant module to show a census-date selector if (array_key_exists('GEDFact_assistant', WT_Module::getActiveModules())) { echo GEDFact_assistant_WT_Module::censusDateSelector($action, $upperlevel, $element_id); } break; case 'FAMC': case 'FAMS': echo print_findfamily_link($element_id); break; case 'ASSO': case '_ASSO': echo print_findindi_link($element_id, $element_id . '_description'); break; case 'FILE': print_findmedia_link($element_id, "0file"); break; case 'SOUR': echo print_findsource_link($element_id, $element_id . '_description'), ' ', print_addnewsource_link($element_id); //-- checkboxes to apply '1 SOUR' to BIRT/MARR/DEAT as '2 SOUR' if ($level == 1) { echo '<br>'; if ($PREFER_LEVEL2_SOURCES === '0') { $level1_checked = ''; $level2_checked = ''; } else { if ($PREFER_LEVEL2_SOURCES === '1' || $PREFER_LEVEL2_SOURCES === true) { $level1_checked = ''; $level2_checked = ' checked="checked"'; } else { $level1_checked = ' checked="checked"'; $level2_checked = ''; } } if (strpos($bdm, 'B') !== false) { echo ' <input type="checkbox" name="SOUR_INDI" ', $level1_checked, ' value="1">'; echo WT_I18N::translate('Individual'); if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $QUICK_REQUIRED_FACTS, $matches)) { foreach ($matches[1] as $match) { if (!in_array($match, explode('|', WT_EVENTS_DEAT))) { echo ' <input type="checkbox" name="SOUR_', $match, '"', $level2_checked, ' value="1">'; echo WT_Gedcom_Tag::getLabel($match); } } } } if (strpos($bdm, 'D') !== false) { if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $QUICK_REQUIRED_FACTS, $matches)) { foreach ($matches[1] as $match) { if (in_array($match, explode('|', WT_EVENTS_DEAT))) { echo ' <input type="checkbox" name="SOUR_', $match, '"', $level2_checked, ' value="1">'; echo WT_Gedcom_Tag::getLabel($match); } } } } if (strpos($bdm, 'M') !== false) { echo ' <input type="checkbox" name="SOUR_FAM" ', $level1_checked, ' value="1">'; echo WT_I18N::translate('Family'); if (preg_match_all('/(' . WT_REGEX_TAG . ')/', $QUICK_REQUIRED_FAMFACTS, $matches)) { foreach ($matches[1] as $match) { echo ' <input type="checkbox" name="SOUR_', $match, '"', $level2_checked, ' value="1">'; echo WT_Gedcom_Tag::getLabel($match); } } } } break; case 'REPO': echo print_findrepository_link($element_id), ' ', print_addnewrepository_link($element_id); break; case 'NOTE': // Shared Notes Icons ======================================== if ($islink) { // Print regular Shared Note icons --------------------------- echo ' ', print_findnote_link($element_id, $element_id . '_description'), ' ', print_addnewnote_link($element_id); if ($value) { echo ' ', print_editnote_link($value); } // Allow the GEDFact_assistant module to create a formatted shared note. if (array_key_exists('GEDFact_assistant', WT_Module::getActiveModules())) { echo GEDFact_assistant_WT_Module::print_addnewnote_assisted_link($element_id, $xref, $action); } } break; case 'OBJE': echo print_findmedia_link($element_id, '1media'); if (!$value) { echo ' ', print_addnewmedia_link($element_id); $value = 'new'; } break; } echo '<div id="' . $element_id . '_description">'; // current value if ($fact == 'DATE') { $date = new WT_Date($value); echo $date->Display(false); } if ($value && $value != 'new' && $islink) { switch ($fact) { case 'ASSO': case '_ASSO': $tmp = WT_Individual::getInstance($value); if ($tmp) { echo ' ', $tmp->getFullname(); } break; case 'SOUR': $tmp = WT_Source::getInstance($value); if ($tmp) { echo ' ', $tmp->getFullname(); } break; case 'NOTE': $tmp = WT_Note::getInstance($value); if ($tmp) { echo ' ', $tmp->getFullname(); } break; case 'OBJE': $tmp = WT_Media::getInstance($value); if ($tmp) { echo ' ', $tmp->getFullname(); } break; case 'REPO': $tmp = WT_Repository::getInstance($value); if ($tmp) { echo ' ', $tmp->getFullname(); } break; } } // pastable values if ($fact == 'FORM' && $upperlevel == 'OBJE') { print_autopaste_link($element_id, $FILE_FORM_accept); } echo '</div>', $extra, '</td></tr>'; return $element_id; }
private function generate_file($ged_id, $rec_type, $volume) { // Check the cache $timestamp = get_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.timestamp'); if ($timestamp > WT_TIMESTAMP - self::CACHE_LIFE && !WT_USER_ID) { $data = get_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.xml'); } else { $tree = WT_Tree::get($ged_id); $data = '<url><loc>' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'index.php?ctype=gedcom&ged=' . $tree->tree_name_url . '</loc></url>' . PHP_EOL; $records = array(); switch ($rec_type) { case 'i': $rows = WT_DB::prepare("SELECT i_id AS xref, i_file AS gedcom_id, i_gedcom AS gedcom" . " FROM `##individuals`" . " WHERE i_file=?" . " ORDER BY i_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $records[] = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom); } break; case 's': $rows = WT_DB::prepare("SELECT s_id AS xref, s_file AS gedcom_id, s_gedcom AS gedcom" . " FROM `##sources`" . " WHERE s_file=?" . " ORDER BY s_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $records[] = WT_Source::getInstance($row->xref, $row->gedcom_id, $row->gedcom); } break; case 'r': $rows = WT_DB::prepare("SELECT o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom" . " FROM `##other`" . " WHERE o_file=? AND o_type='REPO'" . " ORDER BY o_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $records[] = WT_Repository::getInstance($row->xref, $row->gedcom_id, $row->gedcom); } break; case 'n': $rows = WT_DB::prepare("SELECT o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom" . " FROM `##other`" . " WHERE o_file=? AND o_type='NOTE'" . " ORDER BY o_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $records[] = WT_Note::getInstance($row->xref, $row->gedcom_id, $row->gedcom); } break; case 'm': $rows = WT_DB::prepare("SELECT m_id AS xref, m_file AS gedcom_id, m_gedcom AS gedcom" . " FROM `##media`" . " WHERE m_file=?" . " ORDER BY m_id" . " LIMIT " . self::RECORDS_PER_VOLUME . " OFFSET " . $volume * self::RECORDS_PER_VOLUME)->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $records[] = WT_Media::getInstance($row->xref, $row->gedcom_id, $row->gedcom); } break; } foreach ($records as $record) { if ($record->canShowName()) { $data .= '<url>'; $data .= '<loc>' . WT_SERVER_NAME . WT_SCRIPT_PATH . $record->getHtmlUrl() . '</loc>'; $chan = $record->getFirstFact('CHAN'); if ($chan) { $date = $chan->getDate(); if ($date->isOK()) { $data .= '<lastmod>' . $date->minDate()->Format('%Y-%m-%d') . '</lastmod>'; } } $data .= '</url>' . PHP_EOL; } } $data = '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>' . PHP_EOL . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . PHP_EOL . $data . '</urlset>' . PHP_EOL; // Cache this data - but only for visitors, as we don’t want // visitors to see data created by logged-in users. if (!WT_USER_ID) { set_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.xml', $data); set_module_setting($this->getName(), 'sitemap-' . $ged_id . '-' . $rec_type . '-' . $volume . '.timestamp', WT_TIMESTAMP); } } header('Content-Type: application/xml'); header('Content-Length: ' . strlen($data)); echo $data; }
public function linkedMedia($link) { $rows = WT_DB::prepare("SELECT m_id AS xref, m_file AS gedcom_id, m_gedcom AS gedcom" . " FROM `##media`" . " JOIN `##link` ON (m_file=l_file AND m_id=l_from)" . " WHERE m_file=? AND l_type=? AND l_to=?" . " ORDER BY m_titl COLLATE '" . WT_I18N::$collation . "'")->execute(array($this->gedcom_id, $link, $this->xref))->fetchAll(); $list = array(); foreach ($rows as $row) { $record = WT_Media::getInstance($row->xref, $row->gedcom_id, $row->gedcom); if ($record->canShowName()) { $list[] = $record; } } return $list; }
public function getBlock($block_id, $template = true, $cfg = null) { global $ctype, $foundlist; $filter = get_block_setting($block_id, 'filter', 'all'); $controls = get_block_setting($block_id, 'controls', true); $start = get_block_setting($block_id, 'start', false) || WT_Filter::getBool('start'); $block = get_block_setting($block_id, 'block', true); // We can apply the filters using SQL // Do not use "ORDER BY RAND()" - it is very slow on large tables. Use PHP::array_rand() instead. $all_media = WT_DB::prepare("SELECT m_id FROM `##media`" . " WHERE m_file = ?" . " AND m_ext IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '')" . " AND m_type IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '')")->execute(array(WT_GED_ID, get_block_setting($block_id, 'filter_avi', false) ? 'avi' : NULL, get_block_setting($block_id, 'filter_bmp', true) ? 'bmp' : NULL, get_block_setting($block_id, 'filter_gif', true) ? 'gif' : NULL, get_block_setting($block_id, 'filter_jpeg', true) ? 'jpg' : NULL, get_block_setting($block_id, 'filter_jpeg', true) ? 'jpeg' : NULL, get_block_setting($block_id, 'filter_mp3', false) ? 'mp3' : NULL, get_block_setting($block_id, 'filter_ole', true) ? 'ole' : NULL, get_block_setting($block_id, 'filter_pcx', true) ? 'pcx' : NULL, get_block_setting($block_id, 'filter_pdf', false) ? 'pdf' : NULL, get_block_setting($block_id, 'filter_png', true) ? 'png' : NULL, get_block_setting($block_id, 'filter_tiff', true) ? 'tiff' : NULL, get_block_setting($block_id, 'filter_wav', false) ? 'wav' : NULL, get_block_setting($block_id, 'filter_audio', false) ? 'audio' : NULL, get_block_setting($block_id, 'filter_book', true) ? 'book' : NULL, get_block_setting($block_id, 'filter_card', true) ? 'card' : NULL, get_block_setting($block_id, 'filter_certificate', true) ? 'certificate' : NULL, get_block_setting($block_id, 'filter_coat', true) ? 'coat' : NULL, get_block_setting($block_id, 'filter_document', true) ? 'document' : NULL, get_block_setting($block_id, 'filter_electronic', true) ? 'electronic' : NULL, get_block_setting($block_id, 'filter_fiche', true) ? 'fiche' : NULL, get_block_setting($block_id, 'filter_film', true) ? 'film' : NULL, get_block_setting($block_id, 'filter_magazine', true) ? 'magazine' : NULL, get_block_setting($block_id, 'filter_manuscript', true) ? 'manuscript' : NULL, get_block_setting($block_id, 'filter_map', true) ? 'map' : NULL, get_block_setting($block_id, 'filter_newspaper', true) ? 'newspaper' : NULL, get_block_setting($block_id, 'filter_other', true) ? 'other' : NULL, get_block_setting($block_id, 'filter_painting', true) ? 'painting' : NULL, get_block_setting($block_id, 'filter_photo', true) ? 'photo' : NULL, get_block_setting($block_id, 'filter_tombstone', true) ? 'tombstone' : NULL, get_block_setting($block_id, 'filter_video', false) ? 'video' : NULL))->fetchOneColumn(); // Keep looking through the media until a suitable one is found. $random_media = null; while ($all_media) { $n = array_rand($all_media); $media = WT_Media::getInstance($all_media[$n]); if ($media->canShow() && !$media->isExternal()) { // Check if it is linked to a suitable individual foreach ($media->linkedIndividuals('OBJE') as $indi) { if ($filter == 'all' || $filter == 'indi' && strpos($indi->getGedcom(), "\n1 OBJE @" . $media->getXref() . '@') !== false || $filter == 'event' && strpos($indi->getGedcom(), "\n2 OBJE @" . $media->getXref() . '@') !== false) { // Found one :-) $random_media = $media; break 2; } } } unset($all_media[$n]); } $id = $this->getName() . $block_id; $class = $this->getName() . '_block'; if ($ctype == 'gedcom' && WT_USER_GEDCOM_ADMIN || $ctype == 'user' && WT_USER_ID) { $title = '<i class="icon-admin" title="' . WT_I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>'; } else { $title = ''; } $title .= $this->getTitle(); if ($random_media) { $content = "<div id=\"random_picture_container{$block_id}\">"; if ($controls) { if ($start) { $icon_class = 'icon-media-stop'; } else { $icon_class = 'icon-media-play'; } $content .= '<div dir="ltr" class="center" id="random_picture_controls' . $block_id . '"><br>'; $content .= "<a href=\"#\" onclick=\"togglePlay(); return false;\" id=\"play_stop\" class=\"" . $icon_class . "\" title=\"" . WT_I18N::translate('Play') . "/" . WT_I18N::translate('Stop') . '"></a>'; $content .= '<a href="#" onclick="jQuery(\'#block_' . $block_id . '\').load(\'index.php?ctype=' . $ctype . '&action=ajax&block_id=' . $block_id . '\');return false;" title="' . WT_I18N::translate('Next image') . '" class="icon-media-next"></a>'; $content .= '</div><script> var play = false; function togglePlay() { if (play) { play = false; jQuery("#play_stop").removeClass("icon-media-stop").addClass("icon-media-play"); } else { play = true; playSlideShow(); jQuery("#play_stop").removeClass("icon-media-play").addClass("icon-media-stop"); } } function playSlideShow() { if (play) { window.setTimeout("reload_image()", 6000); } } function reload_image() { if (play) { jQuery("#block_' . $block_id . '").load("index.php?ctype=' . $ctype . '&action=ajax&block_id=' . $block_id . '&start=1"); } } </script>'; } if ($start) { $content .= '<script>togglePlay();</script>'; } $content .= '<div class="center" id="random_picture_content' . $block_id . '">'; $content .= '<table id="random_picture_box"><tr><td'; if ($block) { $content .= ' class="details1"'; } else { $content .= ' class="details2"'; } $content .= ' >'; $content .= $random_media->displayImage(); if ($block) { $content .= '<br>'; } else { $content .= '</td><td class="details2">'; } $content .= '<a href="' . $random_media->getHtmlUrl() . '"><b>' . $random_media->getFullName() . '</b></a><br>'; foreach ($random_media->linkedIndividuals('OBJE') as $individual) { $content .= '<a href="' . $individual->getHtmlUrl() . '">' . WT_I18N::translate('View person') . ' — ' . $individual->getFullname() . '</a><br>'; } foreach ($random_media->linkedFamilies('OBJE') as $family) { $content .= '<a href="' . $family->getHtmlUrl() . '">' . WT_I18N::translate('View family') . ' — ' . $family->getFullname() . '</a><br>'; } foreach ($random_media->linkedSources('OBJE') as $source) { $content .= '<a href="' . $source->getHtmlUrl() . '">' . WT_I18N::translate('View source') . ' — ' . $source->getFullname() . '</a><br>'; } $content .= '<br><div class="indent">'; $content .= print_fact_notes($random_media->getGedcom(), "1", false, true); $content .= '</div>'; $content .= '</td></tr></table>'; $content .= '</div>'; // random_picture_content $content .= '</div>'; // random_picture_container } else { $content = WT_I18N::translate('This family tree has no images to display.'); } if ($template) { require WT_THEME_DIR . 'templates/block_main_temp.php'; } else { return $content; } }
function print_main_media(WT_Fact $fact, $level) { $factrec = $fact->getGedcom(); $parent = $fact->getParent(); if ($fact->isNew()) { $styleadd = 'new'; $can_edit = $level == 1 && $fact->canEdit(); } elseif ($fact->isOld()) { $styleadd = 'old'; $can_edit = false; } else { $styleadd = ''; $can_edit = $level == 1 && $fact->canEdit(); } // -- find source for each fact preg_match_all('/(?:^|\\n)' . $level . ' OBJE @(.*)@/', $factrec, $matches); foreach ($matches[1] as $xref) { $media = WT_Media::getInstance($xref); // Allow access to "1 OBJE @non_existent_source@", so it can be corrected/deleted if (!$media || $media->canShow()) { if ($level > 1) { echo '<tr class="row_obje2">'; } else { echo '<tr>'; } echo '<td class="descriptionbox'; if ($level > 1) { echo ' rela'; } echo ' ', $styleadd, ' width20">'; preg_match("/^\\d (\\w*)/", $factrec, $factname); $factlines = explode("\n", $factrec); // 1 BIRT Y\n2 SOUR ... $factwords = explode(" ", $factlines[0]); // 1 BIRT Y $factname = $factwords[1]; // BIRT if ($factname == 'EVEN' || $factname == 'FACT') { // Add ' EVEN' to provide sensible output for an event with an empty TYPE record $ct = preg_match("/2 TYPE (.*)/", $factrec, $ematch); if ($ct > 0) { $factname = $ematch[1]; echo $factname; } else { echo WT_Gedcom_Tag::getLabel($factname, $parent); } } else { if ($can_edit) { echo '<a onclick="window.open(\'addmedia.php?action=editmedia&pid=', $media->getXref(), '\', \'_blank\', edit_window_specs); return false;" href="#" title="', WT_I18N::translate('Edit'), '">'; echo WT_Gedcom_Tag::getLabel($factname, $parent), '</a>'; echo '<div class="editfacts">'; echo '<div class="editlink"><a class="editicon" onclick="window.open(\'addmedia.php?action=editmedia&pid=', $media->getXref(), '\', \'_blank\', edit_window_specs); return false;" href="#" title="', WT_I18N::translate('Edit'), '"><span class="link_text">', WT_I18N::translate('Edit'), '</span></a></div>'; echo '<div class="copylink"><a class="copyicon" href="#" onclick="jQuery.post(\'action.php\',{action:\'copy-fact\', type:\'\', factgedcom:\'' . rawurlencode($factrec) . '\'},function(){location.reload();})" title="' . WT_I18N::translate('Copy') . '"><span class="link_text">' . WT_I18N::translate('Copy') . '</span></a></div>'; echo '<div class="deletelink"><a class="deleteicon" onclick="return delete_fact(\'', WT_I18N::translate('Are you sure you want to delete this fact?'), '\', \'', $parent->getXref(), '\', \'', $fact->getFactId(), '\');" href="#" title="', WT_I18N::translate('Delete'), '"><span class="link_text">', WT_I18N::translate('Delete'), '</span></a></div>'; echo '</div>'; } else { echo WT_Gedcom_Tag::getLabel($factname, $parent); } } echo '</td>'; echo '<td class="optionbox ', $styleadd, ' wrap">'; if ($media) { echo '<span class="field">'; echo $media->displayImage(); if (empty($SEARCH_SPIDER)) { echo '<a href="' . $media->getHtmlUrl() . '">'; } echo '<em>'; foreach ($media->getAllNames() as $name) { if ($name['type'] != 'TITL') { echo '<br>'; } echo $name['full']; } echo '</em>'; if (empty($SEARCH_SPIDER)) { echo '</a>'; } echo '</span>'; echo WT_Gedcom_Tag::getLabelValue('FORM', $media->mimeType()); $imgsize = $media->getImageAttributes('main'); if (!empty($imgsize['WxH'])) { echo WT_Gedcom_Tag::getLabelValue('__IMAGE_SIZE__', $imgsize['WxH']); } if ($media->getFilesizeraw() > 0) { echo WT_Gedcom_Tag::getLabelValue('__FILE_SIZE__', $media->getFilesize()); } $mediatype = $media->getMediaType(); if ($mediatype) { echo WT_Gedcom_Tag::getLabelValue('TYPE', WT_Gedcom_Tag::getFileFormTypeValue($mediatype)); } switch ($media->isPrimary()) { case 'Y': echo WT_Gedcom_Tag::getLabelValue('_PRIM', WT_I18N::translate('yes')); break; case 'N': echo WT_Gedcom_Tag::getLabelValue('_PRIM', WT_I18N::translate('no')); break; } echo print_fact_notes($media->getGedcom(), 1); echo print_fact_sources($media->getGedcom(), 1); } else { echo $xref; } echo '</td></tr>'; } } }
private function get_media() { global $controller; if ($this->media_list === null) { // Use facts from this individual and all their spouses $facts = $controller->record->getFacts(); foreach ($controller->record->getSpouseFamilies() as $family) { foreach ($family->getFacts() as $fact) { $facts[] = $fact; } } // Use all media from each fact $this->media_list = array(); foreach ($facts as $fact) { if (!$fact->isOld()) { // Don't show pending edits, as the user just sees duplicates preg_match_all('/(?:^1|\\n\\d) OBJE @(' . WT_REGEX_XREF . ')@/', $fact->getGedcom(), $matches); foreach ($matches[1] as $match) { $media = WT_Media::getInstance($match); if ($media && $media->canShow()) { $this->media_list[] = $media; } } } } // If a media object is linked twice, only show it once $this->media_list = array_unique($this->media_list); // Sort these using _WT_OBJE_SORT $wt_obje_sort = array(); foreach ($controller->record->getFacts('_WT_OBJE_SORT') as $fact) { $wt_obje_sort[] = trim($fact->getValue(), '@'); } usort($this->media_list, function ($x, $y) use($wt_obje_sort) { return array_search($x->getXref(), $wt_obje_sort) - array_search($y->getXref(), $wt_obje_sort); }); } return $this->media_list; }
static function getLatestRecord($xref, $type) { switch ($type) { case 'INDI': return WT_Individual::getInstance($xref)->getGedcom(); case 'FAM': return WT_Family::getInstance($xref)->getGedcom(); case 'SOUR': return WT_Source::getInstance($xref)->getGedcom(); case 'REPO': return WT_Repository::getInstance($xref)->getGedcom(); case 'OBJE': return WT_Media::getInstance($xref)->getGedcom(); case 'NOTE': return WT_Note::getInstance($xref)->getGedcom(); default: return WT_GedcomRecord::getInstance($xref)->getGedcom(); } }
/** * Create a new image object from WT_Media Object - WT_Report_PDF * * @param WT_Media $mediaobject * @param mixed $x * @param mixed $y * @param int $w Image width * @param int $h Image height * @param string $align L:left, C:center, R:right or empty to use x/y * @param string $ln T:same line, N:next line * * @return WT_Report_PDF_Image */ function createImageFromObject($mediaobject, $x, $y, $w, $h, $align, $ln) { return new WT_Report_PDF_Image($mediaobject->getServerFilename('thumb'), $x, $y, $w, $h, $align, $ln); }
} } // Fetch all data, regardless of privacy $rows = get_REPO_rows($term); // Filter for privacy foreach ($rows as $row) { $repository = WT_Repository::getInstance($row->xref, $row->gedcom_id, $row->gedcom); if ($repository->canShowName()) { $data[] = array('value' => $repository->getXref(), 'label' => $repository->getFullName()); } } // Fetch all data, regardless of privacy $rows = get_OBJE_rows($term); // Filter for privacy foreach ($rows as $row) { $media = WT_Media::getInstance($row->xref, $row->gedcom_id, $row->gedcom); if ($media->canShowName()) { $data[] = array('value' => $media->getXref(), 'label' => '<img src="' . $media->getHtmlUrlDirect() . '" width="25"> ' . $media->getFullName()); } } // Fetch all data, regardless of privacy $rows = get_FAM_rows($term); // Filter for privacy foreach ($rows as $row) { $family = WT_Family::getInstance($row->xref, $row->gedcom_id, $row->gedcom); if ($family->canShowName()) { $marriage_year = $family->getMarriageYear(); if ($marriage_year) { $data[] = array('value' => $family->getXref(), 'label' => $family->getFullName() . ', <i>' . $marriage_year . '</i>'); } else { $data[] = array('value' => $family->getXref(), 'label' => $family->getFullName());
/** * Edit menu items used in media list * * @param WT_Media $mediaobject * * @return string */ static function getMediaListMenu(WT_Media $mediaobject) { $html = '<div class="lightbox-menu"><ul class="makeMenu lb-menu">'; $menu = new WT_Menu(WT_I18N::translate('Edit details')); $menu->addClass('', '', 'lb-image_edit'); $menu->addOnclick("return window.open('addmedia.php?action=editmedia&pid=" . $mediaobject->getXref() . "', '_blank', edit_window_specs);"); $html .= $menu->getMenuAsList(); $menu = new WT_Menu(WT_I18N::translate('Set link')); $menu->addClass('', '', 'lb-image_link'); $menu->addOnclick("return ilinkitem('" . $mediaobject->getXref() . "','person')"); $submenu = new WT_Menu(WT_I18N::translate('To individual'), '#'); $submenu->addOnclick("return ilinkitem('" . $mediaobject->getXref() . "','person')"); $menu->addSubMenu($submenu); $submenu = new WT_Menu(WT_I18N::translate('To family'), '#'); $submenu->addOnclick("return ilinkitem('" . $mediaobject->getXref() . "','family')"); $menu->addSubMenu($submenu); $submenu = new WT_Menu(WT_I18N::translate('To source'), '#'); $submenu->addOnclick("return ilinkitem('" . $mediaobject->getXref() . "','source')"); $menu->addSubMenu($submenu); $html .= $menu->getMenuAsList(); $menu = new WT_Menu(WT_I18N::translate('View details'), $mediaobject->getHtmlUrl()); $menu->addClass('', '', 'lb-image_view'); $html .= $menu->getMenuAsList(); $html .= '</ul></div>'; return $html; }
/** * Generate a filtered, sourced, privacy-checked list of media objects - for the media list. * * @param string $folder folder to search * @param string $subfolders either "include" or "exclude" * @param string $sort either "file" or "title" * @param string $filter optional search string * * @return WT_Media[] * @throws Exception */ public static function mediaList($folder, $subfolders, $sort, $filter) { // All files in the folder, plus external files $sql = "SELECT m_id AS xref, m_file AS gedcom_id, m_gedcom AS gedcom" . " FROM `##media`" . " WHERE m_file=?"; $args = array(WT_GED_ID); // Only show external files when we are looking at the root folder if ($folder == '') { $sql_external = " OR m_filename LIKE 'http://%' OR m_filename LIKE 'https://%'"; } else { $sql_external = ""; } // Include / exclude subfolders (but always include external) switch ($subfolders) { case 'include': $sql .= " AND (m_filename LIKE CONCAT(?, '%') {$sql_external})"; $args[] = WT_Filter::escapeLike($folder); break; case 'exclude': $sql .= " AND (m_filename LIKE CONCAT(?, '%') AND m_filename NOT LIKE CONCAT(?, '%/%') {$sql_external})"; $args[] = WT_Filter::escapeLike($folder); $args[] = WT_Filter::escapeLike($folder); break; default: throw new Exception('Bad argument (subfolders=' . $subfolders . ') in WT_Query_Media::mediaList()'); } // Apply search terms if ($filter) { $sql .= " AND (SUBSTRING_INDEX(m_filename, '/', -1) LIKE CONCAT('%', ?, '%') OR m_titl LIKE CONCAT('%', ?, '%'))"; $args[] = WT_Filter::escapeLike($filter); $args[] = WT_Filter::escapeLike($filter); } switch ($sort) { case 'file': $sql .= " ORDER BY m_filename"; break; case 'title': $sql .= " ORDER BY m_titl"; break; default: throw new Exception('Bad argument (sort=' . $sort . ') in WT_Query_Media::mediaList()'); } $rows = WT_DB::prepare($sql)->execute($args)->fetchAll(); $list = array(); foreach ($rows as $row) { $media = WT_Media::getInstance($row->xref, $row->gedcom_id, $row->gedcom); if ($media->canShow()) { $list[] = $media; } } return $list; }
$multi_gedcom = !$media->isExternal() && is_media_used_in_other_gedcom($media->getFilename(), WT_GED_ID); if ($multi_gedcom) { WT_FlashMessages::addMessage(WT_I18N::translate('This file is linked to another genealogical database on this server. It cannot be deleted, moved, or renamed until these links have been removed.')); break; } // Cannot rename local to external or vice-versa if (isFileExternal($oldFilename) != isFileExternal($filename)) { WT_FlashMessages::addMessage(WT_I18N::translate('Media file %1$s could not be renamed to %2$s.', '<span class="filename">' . $oldFilename . '</span>', '<span class="filename">' . $newFilename . '</span>')); break; } $messages = false; // Move files on disk (if we can) to reflect the change to the GEDCOM data if (!$media->isExternal()) { $oldServerFile = $media->getServerFilename('main'); $oldServerThumb = $media->getServerFilename('thumb'); $newmedia = new WT_Media("xxx", "0 @xxx@ OBJE\n1 FILE " . $newFilename, null, WT_GED_ID); $newServerFile = $newmedia->getServerFilename('main'); $newServerThumb = $newmedia->getServerFilename('thumb'); // We could be either renaming an existing file, or updating a record (with no valid file) to point to a new file if ($oldServerFile != $newServerFile) { if (!file_exists($newServerFile) || @md5_file($oldServerFile) == md5_file($newServerFile)) { if (@rename($oldServerFile, $newServerFile)) { WT_FlashMessages::addMessage(WT_I18N::translate('Media file %1$s successfully renamed to %2$s.', '<span class="filename">' . $oldFilename . '</span>', '<span class="filename">' . $newFilename . '</span>')); } else { WT_FlashMessages::addMessage(WT_I18N::translate('Media file %1$s could not be renamed to %2$s.', '<span class="filename">' . $oldFilename . '</span>', '<span class="filename">' . $newFilename . '</span>')); } $messages = true; } if (!file_exists($newServerFile)) { WT_FlashMessages::addMessage(WT_I18N::translate('Media file %s does not exist.', '<span class="filename">' . $newFilename . '</span>')); $messages = true;
/** * @param array $attrs an array of key value pairs for the attributes */ function ImageSHandler($attrs) { global $gedrec, $wt_report, $MEDIA_DIRECTORY, $ReportRoot; // mixed Position the top corner of this box on the page. the default is the current position $top = '.'; if (isset($attrs['top'])) { if ($attrs['top'] === "0") { $top = 0; } elseif ($attrs['top'] === '.') { $top = '.'; } elseif (!empty($attrs['top'])) { $top = (int) $attrs['top']; } } // mixed Position the left corner of this box on the page. the default is the current position $left = '.'; if (isset($attrs['left'])) { if ($attrs['left'] === '0') { $left = 0; } elseif ($attrs['left'] === '.') { $left = '.'; } elseif (!empty($attrs['left'])) { $left = (int) $attrs['left']; } } // string Align the image in left, center, right $align = ''; if (!empty($attrs['align'])) { $align = $attrs['align']; } // string Next Line should be T:next to the image, N:next line $ln = 'T'; if (!empty($attrs['ln'])) { $ln = $attrs['ln']; } $width = 0; $height = 0; if (!empty($attrs['width'])) { $width = (int) $attrs['width']; } if (!empty($attrs['height'])) { $height = (int) $attrs['height']; } $file = ''; if (!empty($attrs['file'])) { $file = $attrs['file']; } if ($file == "@FILE") { $match = array(); if (preg_match("/\\d OBJE @(.+)@/", $gedrec, $match)) { $mediaobject = WT_Media::getInstance($match[1], WT_GED_ID); $attributes = $mediaobject->getImageAttributes('thumb'); if (in_array($attributes['ext'], array('GIF', 'JPG', 'PNG', 'SWF', 'PSD', 'BMP', 'TIFF', 'TIFF', 'JPC', 'JP2', 'JPX', 'JB2', 'SWC', 'IFF', 'WBMP', 'XBM')) && $mediaobject->canShow() && $mediaobject->fileExists('thumb')) { if ($width > 0 and $height == 0) { $perc = $width / $attributes['adjW']; $height = round($attributes['adjH'] * $perc); } elseif ($height > 0 && $width == 0) { $perc = $height / $attributes['adjH']; $width = round($attributes['adjW'] * $perc); } else { $width = $attributes['adjW']; $height = $attributes['adjH']; } $image = $ReportRoot->createImageFromObject($mediaobject, $left, $top, $width, $height, $align, $ln); $wt_report->addElement($image); } } } else { if (file_exists($file) && preg_match("/(jpg|jpeg|png|gif)\$/i", $file)) { $size = getimagesize($file); if ($width > 0 and $height == 0) { $perc = $width / $size[0]; $height = round($size[1] * $perc); } elseif ($height > 0 && $width == 0) { $perc = $height / $size[1]; $width = round($size[0] * $perc); } else { $width = $size[0]; $height = $size[1]; } $image = $ReportRoot->createImage($file, $left, $top, $width, $height, $align, $ln); $wt_report->addElement($image); } } }
function create_media_object($level, $gedrec, $ged_id) { static $sql_insert_media = null; static $sql_select_media = null; if (!$sql_insert_media) { $sql_insert_media = WT_DB::prepare("INSERT INTO `##media` (m_id, m_ext, m_type, m_titl, m_filename, m_file, m_gedcom) VALUES (?, ?, ?, ?, ?, ?, ?)"); $sql_select_media = WT_DB::prepare("SELECT m_id FROM `##media` WHERE m_filename=? AND m_titl=? AND m_file=?"); } if (preg_match('/\\n\\d FILE (.+)/', $gedrec, $file_match)) { $file = $file_match[1]; } else { $file = ''; } if (preg_match('/\\n\\d TITL (.+)/', $gedrec, $file_match)) { $titl = $file_match[1]; } else { $titl = $file; } // Have we already created a media object with the same title/filename? $xref = $sql_select_media->execute(array($file, $titl, $ged_id))->fetchOne(); if (!$xref) { $xref = get_new_xref("OBJE", $ged_id); // renumber the lines $gedrec = preg_replace_callback('/\\n(\\d+)/', function ($m) use($level) { return "\n" . ($m[1] - $level); }, $gedrec); // convert to an object $gedrec = str_replace("\n0 OBJE\n", '0 @' . $xref . "@ OBJE\n", $gedrec); // Fix Legacy GEDCOMS $gedrec = preg_replace('/\\n1 FORM (.+)\\n1 FILE (.+)\\n1 TITL (.+)/', "\n1 FILE \$2\n2 FORM \$1\n2 TITL \$3", $gedrec); // Create new record $record = new WT_Media($xref, $gedrec, null, $ged_id); $sql_insert_media->execute(array($xref, $record->extension(), $record->getMediaType(), $record->title, $record->file, $ged_id, $gedrec)); } return "\n" . $level . ' OBJE @' . $xref . '@'; }
// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA use WT\Log; define('WT_SCRIPT_NAME', 'mediafirewall.php'); require './includes/session.php'; Zend_Session::writeClose(); $mid = WT_Filter::get('mid', WT_REGEX_XREF); $thumb = WT_Filter::getBool('thumb'); $media = WT_Media::getInstance($mid); // Send a “Not found” error as an image function send404AndExit() { $error = WT_I18N::translate('The media file was not found in this family tree'); $width = mb_strlen($error) * 6.5 + 50; $height = 60; $im = imagecreatetruecolor($width, $height); /* Create a black image */ $bgc = imagecolorallocate($im, 255, 255, 255); /* set background color */ imagefilledrectangle($im, 2, 2, $width - 4, $height - 4, $bgc); /* create a rectangle, leaving 2 px border */ embedText($im, $error, 100, "255, 0, 0", "", "top", "left"); header('HTTP/1.0 404 Not Found'); header('Status: 404 Not Found');
public function getMedia() { $media = array(); preg_match_all('/\\n2 OBJE @(' . WT_REGEX_XREF . ')@/', $this->getGedcom(), $matches); foreach ($matches[1] as $match) { $obje = WT_Media::getInstance($match, $this->getParent()->getGedcomId()); if ($obje->canShow()) { $media[] = $obje; } } return $media; }
function findHighlightedMedia() { $objectA = null; $objectB = null; $objectC = null; // Iterate over all of the media items for the individual preg_match_all('/\\n(\\d) OBJE @(' . WT_REGEX_XREF . ')@/', $this->getGedcom(), $matches, PREG_SET_ORDER); foreach ($matches as $match) { $media = WT_Media::getInstance($match[2]); if (!$media || !$media->canShow() || $media->isExternal()) { continue; } $level = $match[1]; $prim = $media->isPrimary(); if ($prim == 'N') { continue; } if ($level == 1) { if ($prim == 'Y') { if (empty($objectA)) { $objectA = $media; } } else { if (empty($objectB)) { $objectB = $media; } } } else { if ($prim == 'Y') { if (empty($objectC)) { $objectC = $media; } } } } if ($objectA) { return $objectA; } if ($objectB) { return $objectB; } if ($objectC) { return $objectC; } return null; }
$linked_sour = $controller->record->linkedSources('OBJE'); $linked_repo = $controller->record->linkedRepositories('OBJE'); // Invalid GEDCOM - you cannot link a REPO to an OBJE $linked_note = $controller->record->linkedNotes('OBJE'); // Invalid GEDCOM - you cannot link a NOTE to an OBJE echo '<div id="media-details">'; echo '<h2>', $controller->record->getFullName(), ' ', $controller->record->getAddName(), '</h2>'; echo '<div id="media-tabs">'; echo '<div id="media-edit">'; echo '<table class="facts_table"> <tr> <td align="center" width="150">'; // When we have a pending edit, $controller->record shows the *old* data. // As a temporary kludge, fetch a "normal" version of the record - which includes pending changes // TODO - check both, and use RED/BLUE boxes. $tmp = WT_Media::getInstance($controller->record->getXref()); echo $tmp->displayImage(); if (!$tmp->isExternal()) { if ($tmp->fileExists('main')) { if ($SHOW_MEDIA_DOWNLOAD) { echo '<p><a href="' . $tmp->getHtmlUrlDirect('main', true) . '">' . WT_I18N::translate('Download file') . '</a></p>'; } } else { echo '<p class="ui-state-error">' . WT_I18N::translate('The file “%s” does not exist.', $tmp->getFilename()) . '</p>'; } } echo '</td> <td valign="top"> <table width="100%"> <tr> <td>
function media_object_info(WT_Media $media) { $xref = $media->getXref(); $gedcom = WT_Tree::getNameFromId($media->getGedcomId()); $name = $media->getFullName(); $html = '<b>' . $name . '</b>' . '<div><i>' . WT_Filter::escapeHtml($media->getNote()) . '</i></div>' . '<br>' . '<a href="' . $media->getHtmlUrl() . '">' . WT_I18N::translate('View') . '</a>'; $html .= ' - ' . '<a onclick="window.open(\'addmedia.php?action=editmedia&pid=' . $xref . '&ged=' . WT_Filter::escapeJs($gedcom) . '\', \'_blank\', edit_window_specs)" href="#">' . WT_I18N::Translate('Edit') . '</a>' . ' - ' . '<a onclick="return delete_media(\'' . WT_Filter::escapeJs(WT_I18N::translate('Are you sure you want to delete “%s”?', strip_tags($media->getFullName()))) . '\', \'' . $media->getXref() . '\', \'' . WT_Filter::escapeJs($gedcom) . '\');" href="#">' . WT_I18N::Translate('Delete') . '</a>' . ' - '; if (array_key_exists('GEDFact_assistant', WT_Module::getActiveModules())) { $html .= '<a onclick="return ilinkitem(\'' . $xref . '\', \'manage\', \'' . $gedcom . '\')" href="#">' . WT_I18N::Translate('Manage links') . '</a>'; } else { global $TEXT_DIRECTION; $classSuffix = $TEXT_DIRECTION == 'rtl' ? '_rtl' : ''; $menu = new WT_Menu(); $menu->addLabel(WT_I18N::translate('Set link')); $menu->addClass('', 'submenu'); $submenu = new WT_Menu(WT_I18N::translate('To individual')); $submenu->addClass("submenuitem" . $classSuffix); $submenu->addOnClick("return ilinkitem('{$xref}', 'person', '{$gedcom}')"); $menu->addSubMenu($submenu); $submenu = new WT_Menu(WT_I18N::translate('To family')); $submenu->addClass("submenuitem" . $classSuffix); $submenu->addOnClick("return ilinkitem('{$xref}', 'family', '{$gedcom}')"); $menu->addSubMenu($submenu); $submenu = new WT_Menu(WT_I18N::translate('To source')); $submenu->addClass("submenuitem" . $classSuffix); $submenu->addOnClick("return ilinkitem('{$xref}', 'source', '{$gedcom}')"); $menu->addSubMenu($submenu); $html .= '<div style="display:inline-block;">' . $menu->getMenu() . '</div>'; } $html .= '<br><br>'; $linked = array(); foreach ($media->linkedIndividuals('OBJE') as $link) { $linked[] = '<a href="' . $link->getHtmlUrl() . '">' . $link->getFullName() . '</a>'; } foreach ($media->linkedFamilies('OBJE') as $link) { $linked[] = '<a href="' . $link->getHtmlUrl() . '">' . $link->getFullName() . '</a>'; } foreach ($media->linkedSources('OBJE') as $link) { $linked[] = '<a href="' . $link->getHtmlUrl() . '">' . $link->getFullName() . '</a>'; } foreach ($media->linkedNotes('OBJE') as $link) { // Invalid GEDCOM - you cannot link a NOTE to an OBJE $linked[] = '<a href="' . $link->getHtmlUrl() . '">' . $link->getFullName() . '</a>'; } foreach ($media->linkedRepositories('OBJE') as $link) { // Invalid GEDCOM - you cannot link a REPO to an OBJE $linked[] = '<a href="' . $link->getHtmlUrl() . '">' . $link->getFullName() . '</a>'; } if ($linked) { $html .= '<ul>'; foreach ($linked as $link) { $html .= '<li>' . $link . '</li>'; } $html .= '</ul>'; } else { $html .= '<div class="error">' . WT_I18N::translate('This media object is not linked to any other record.') . '</div>'; } return $html; }
function export_gedcom($gedcom, $gedout, $exportOptions) { global $GEDCOM; // Temporarily switch to the specified GEDCOM $oldGEDCOM = $GEDCOM; $GEDCOM = $gedcom; $ged_id = get_id_from_gedcom($gedcom); switch ($exportOptions['privatize']) { case 'gedadmin': $access_level = WT_PRIV_NONE; break; case 'user': $access_level = WT_PRIV_USER; break; case 'visitor': $access_level = WT_PRIV_PUBLIC; break; case 'none': $access_level = WT_PRIV_HIDE; break; } $head = gedcom_header($gedcom); if ($exportOptions['toANSI'] == 'yes') { $head = str_replace('UTF-8', 'ANSI', $head); $head = utf8_decode($head); } $head = reformat_record_export($head); fwrite($gedout, $head); // Buffer the output. Lots of small fwrite() calls can be very slow when writing large gedcoms. $buffer = ''; // Generate the OBJE/SOUR/REPO/NOTE records first, as their privacy calcualations involve // database queries, and we wish to avoid large gaps between queries due to MySQL connection timeouts. $tmp_gedcom = ''; $rows = WT_DB::prepare("SELECT 'OBJE' AS type, m_id AS xref, m_file AS gedcom_id, m_gedcom AS gedcom" . " FROM `##media` WHERE m_file=? ORDER BY m_id")->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $rec = WT_Media::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level); $rec = convert_media_path($rec, $exportOptions['path']); if ($exportOptions['toANSI'] == 'yes') { $rec = utf8_decode($rec); } $tmp_gedcom .= reformat_record_export($rec); } $rows = WT_DB::prepare("SELECT s_id AS xref, s_file AS gedcom_id, s_gedcom AS gedcom" . " FROM `##sources` WHERE s_file=? ORDER BY s_id")->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $rec = WT_Source::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level); if ($exportOptions['toANSI'] == 'yes') { $rec = utf8_decode($rec); } $tmp_gedcom .= reformat_record_export($rec); } $rows = WT_DB::prepare("SELECT o_type AS type, o_id AS xref, o_file AS gedcom_id, o_gedcom AS gedcom" . " FROM `##other` WHERE o_file=? AND o_type!='HEAD' AND o_type!='TRLR' ORDER BY o_id")->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { switch ($row->type) { case 'NOTE': $record = WT_Note::getInstance($row->xref, $row->gedcom_id, $row->gedcom); break; case 'REPO': $record = WT_Repository::getInstance($row->xref, $row->gedcom_id, $row->gedcom); break; default: $record = WT_GedcomRecord::getInstance($row->xref, $row->gedcom_id, $row->gedcom); break; } $rec = $record->privatizeGedcom($access_level); if ($exportOptions['toANSI'] == 'yes') { $rec = utf8_decode($rec); } $tmp_gedcom .= reformat_record_export($rec); } $rows = WT_DB::prepare("SELECT i_id AS xref, i_file AS gedcom_id, i_gedcom AS gedcom" . " FROM `##individuals` WHERE i_file=? ORDER BY i_id")->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $rec = WT_Individual::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level); if ($exportOptions['toANSI'] == 'yes') { $rec = utf8_decode($rec); } $buffer .= reformat_record_export($rec); if (strlen($buffer) > 65536) { fwrite($gedout, $buffer); $buffer = ''; } } $rows = WT_DB::prepare("SELECT f_id AS xref, f_file AS gedcom_id, f_gedcom AS gedcom" . " FROM `##families` WHERE f_file=? ORDER BY f_id")->execute(array($ged_id))->fetchAll(); foreach ($rows as $row) { $rec = WT_Family::getInstance($row->xref, $row->gedcom_id, $row->gedcom)->privatizeGedcom($access_level); if ($exportOptions['toANSI'] == 'yes') { $rec = utf8_decode($rec); } $buffer .= reformat_record_export($rec); if (strlen($buffer) > 65536) { fwrite($gedout, $buffer); $buffer = ''; } } fwrite($gedout, $buffer); fwrite($gedout, $tmp_gedcom); fwrite($gedout, '0 TRLR' . WT_EOL); $GEDCOM = $oldGEDCOM; }