18c2e8227SGreg Roach<?php 28c2e8227SGreg Roachnamespace Fisharebest\Webtrees; 38c2e8227SGreg Roach 48c2e8227SGreg Roach/** 58c2e8227SGreg Roach * webtrees: online genealogy 68c2e8227SGreg Roach * Copyright (C) 2015 webtrees development team 78c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 88c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 98c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 108c2e8227SGreg Roach * (at your option) any later version. 118c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 128c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 138c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 148c2e8227SGreg Roach * GNU General Public License for more details. 158c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 168c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 178c2e8227SGreg Roach */ 188c2e8227SGreg Roach 198c2e8227SGreg Roach/** 208c2e8227SGreg Roach * Class MediaTabModule 218c2e8227SGreg Roach */ 22*e2a378d3SGreg Roachclass MediaTabModule extends AbstractModule implements ModuleTabInterface { 238c2e8227SGreg Roach private $facts; 248c2e8227SGreg Roach 258c2e8227SGreg Roach /** {@inheritdoc} */ 268c2e8227SGreg Roach public function getTitle() { 278c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('Media'); 288c2e8227SGreg Roach } 298c2e8227SGreg Roach 308c2e8227SGreg Roach /** {@inheritdoc} */ 318c2e8227SGreg Roach public function getDescription() { 328c2e8227SGreg Roach return /* I18N: Description of the “Media” module */ I18N::translate('A tab showing the media objects linked to an individual.'); 338c2e8227SGreg Roach } 348c2e8227SGreg Roach 358c2e8227SGreg Roach /** {@inheritdoc} */ 368c2e8227SGreg Roach public function defaultTabOrder() { 378c2e8227SGreg Roach return 50; 388c2e8227SGreg Roach } 398c2e8227SGreg Roach 408c2e8227SGreg Roach /** {@inheritdoc} */ 418c2e8227SGreg Roach public function hasTabContent() { 424b9ff166SGreg Roach global $WT_TREE; 434b9ff166SGreg Roach 444b9ff166SGreg Roach return Auth::isEditor($WT_TREE) || $this->getFactsWithMedia(); 458c2e8227SGreg Roach } 468c2e8227SGreg Roach 478c2e8227SGreg Roach /** {@inheritdoc} */ 488c2e8227SGreg Roach public function isGrayedOut() { 498c2e8227SGreg Roach return !$this->getFactsWithMedia(); 508c2e8227SGreg Roach } 518c2e8227SGreg Roach 528c2e8227SGreg Roach /** {@inheritdoc} */ 538c2e8227SGreg Roach public function getTabContent() { 548c2e8227SGreg Roach global $WT_TREE, $controller; 558c2e8227SGreg Roach 568c2e8227SGreg Roach ob_start(); 578c2e8227SGreg Roach echo '<table class="facts_table">'; 588c2e8227SGreg Roach foreach ($this->getFactsWithMedia() as $fact) { 598c2e8227SGreg Roach if ($fact->getTag() == 'OBJE') { 608c2e8227SGreg Roach print_main_media($fact, 1); 618c2e8227SGreg Roach } else { 628c2e8227SGreg Roach for ($i = 2; $i < 4; ++$i) { 638c2e8227SGreg Roach print_main_media($fact, $i); 648c2e8227SGreg Roach } 658c2e8227SGreg Roach } 668c2e8227SGreg Roach } 678c2e8227SGreg Roach if (!$this->getFactsWithMedia()) { 688c2e8227SGreg Roach echo '<tr><td id="no_tab4" colspan="2" class="facts_value">', I18N::translate('There are no media objects for this individual.'), '</td></tr>'; 698c2e8227SGreg Roach } 708c2e8227SGreg Roach // New media link 714b9ff166SGreg Roach if ($controller->record->canEdit() && $WT_TREE->getPreference('MEDIA_UPLOAD') >= Auth::accessLevel($controller->record->getTree())) { 728c2e8227SGreg Roach ?> 738c2e8227SGreg Roach <tr> 748c2e8227SGreg Roach <td class="facts_label"> 75764a01d9SGreg Roach <?php echo GedcomTag::getLabel('OBJE'); ?> 768c2e8227SGreg Roach </td> 778c2e8227SGreg Roach <td class="facts_value"> 784b9ff166SGreg Roach <a href="#" onclick="window.open('addmedia.php?action=showmediaform&linktoid=<?php echo $controller->record->getXref(); ?>&ged=<?php echo $controller->record->getTree()->getNameUrl(); ?>', '_blank', edit_window_specs); return false;"> 798c2e8227SGreg Roach <?php echo I18N::translate('Add a new media object'); ?> 808c2e8227SGreg Roach </a> 818c2e8227SGreg Roach <?php echo help_link('OBJE'); ?> 828c2e8227SGreg Roach <br> 834b9ff166SGreg Roach <a href="#" onclick="window.open('inverselink.php?linktoid=<?php echo $controller->record->getXref(); ?>&ged=<?php echo $WT_TREE->getNameUrl(); ?>&linkto=person', '_blank', find_window_specs); return false;"> 848c2e8227SGreg Roach <?php echo I18N::translate('Link to an existing media object'); ?> 858c2e8227SGreg Roach </a> 868c2e8227SGreg Roach </td> 878c2e8227SGreg Roach </tr> 888c2e8227SGreg Roach <?php 898c2e8227SGreg Roach } 908c2e8227SGreg Roach ?> 918c2e8227SGreg Roach </table> 928c2e8227SGreg Roach <?php 938c2e8227SGreg Roach return '<div id="' . $this->getName() . '_content">' . ob_get_clean() . '</div>'; 948c2e8227SGreg Roach } 958c2e8227SGreg Roach 968c2e8227SGreg Roach /** 978c2e8227SGreg Roach * Get all the facts for an individual which contain media objects. 988c2e8227SGreg Roach * 998c2e8227SGreg Roach * @return Fact[] 1008c2e8227SGreg Roach */ 1018c2e8227SGreg Roach private function getFactsWithMedia() { 1028c2e8227SGreg Roach global $controller; 1038c2e8227SGreg Roach 1048c2e8227SGreg Roach if ($this->facts === null) { 1058c2e8227SGreg Roach $facts = $controller->record->getFacts(); 1068c2e8227SGreg Roach foreach ($controller->record->getSpouseFamilies() as $family) { 1078c2e8227SGreg Roach if ($family->canShow()) { 1088c2e8227SGreg Roach foreach ($family->getFacts() as $fact) { 1098c2e8227SGreg Roach $facts[] = $fact; 1108c2e8227SGreg Roach } 1118c2e8227SGreg Roach } 1128c2e8227SGreg Roach } 1138c2e8227SGreg Roach $this->facts = array(); 1148c2e8227SGreg Roach foreach ($facts as $fact) { 1158c2e8227SGreg Roach if (preg_match('/(?:^1|\n\d) OBJE @' . WT_REGEX_XREF . '@/', $fact->getGedcom())) { 1168c2e8227SGreg Roach $this->facts[] = $fact; 1178c2e8227SGreg Roach } 1188c2e8227SGreg Roach } 1198c2e8227SGreg Roach sort_facts($this->facts); 1208c2e8227SGreg Roach } 1218c2e8227SGreg Roach 1228c2e8227SGreg Roach return $this->facts; 1238c2e8227SGreg Roach } 1248c2e8227SGreg Roach 1258c2e8227SGreg Roach /** {@inheritdoc} */ 1268c2e8227SGreg Roach public function canLoadAjax() { 1278c2e8227SGreg Roach return !Auth::isSearchEngine(); // Search engines cannot use AJAX 1288c2e8227SGreg Roach } 1298c2e8227SGreg Roach 1308c2e8227SGreg Roach /** {@inheritdoc} */ 1318c2e8227SGreg Roach public function getPreLoadContent() { 1328c2e8227SGreg Roach return ''; 1338c2e8227SGreg Roach } 1348c2e8227SGreg Roach} 135