/** * Print a row for the media tab on the individual page. * * @param Fact $fact * @param int $level */ public static function printMainMedia(Fact $fact, $level) { $factrec = $fact->getGedcom(); $parent = $fact->getParent(); if ($fact->isPendingAddition()) { $styleadd = 'new'; $can_edit = $level == 1 && $fact->canEdit(); } elseif ($fact->isPendingDeletion()) { $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 = Media::getInstance($xref, $fact->getParent()->getTree()); // 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 GedcomTag::getLabel($factname, $parent); } } elseif ($can_edit) { echo '<a onclick="window.open(\'addmedia.php?action=editmedia&pid=', $media->getXref(), '\', \'_blank\', edit_window_specs); return false;" href="#" title="', I18N::translate('Edit'), '">'; echo GedcomTag::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="', I18N::translate('Edit'), '"><span class="link_text">', 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="' . I18N::translate('Copy') . '"><span class="link_text">' . I18N::translate('Copy') . '</span></a></div>'; echo '<div class="deletelink"><a class="deleteicon" onclick="return delete_fact(\'', I18N::translate('Are you sure you want to delete this fact?'), '\', \'', $parent->getXref(), '\', \'', $fact->getFactId(), '\');" href="#" title="', I18N::translate('Delete'), '"><span class="link_text">', I18N::translate('Delete'), '</span></a></div>'; echo '</div>'; } else { echo GedcomTag::getLabel($factname, $parent); } echo '</td>'; echo '<td class="optionbox ', $styleadd, ' wrap">'; if ($media) { echo '<span class="field">'; echo $media->displayImage(); echo '<a href="' . $media->getHtmlUrl() . '">'; echo '<em>'; foreach ($media->getAllNames() as $name) { if ($name['type'] != 'TITL') { echo '<br>'; } echo $name['full']; } echo '</em>'; echo '</a>'; echo '</span>'; echo GedcomTag::getLabelValue('FORM', $media->mimeType()); $imgsize = $media->getImageAttributes('main'); if (!empty($imgsize['WxH'])) { echo GedcomTag::getLabelValue('__IMAGE_SIZE__', $imgsize['WxH']); } if ($media->getFilesizeraw() > 0) { echo GedcomTag::getLabelValue('__FILE_SIZE__', $media->getFilesize()); } $mediatype = $media->getMediaType(); if ($mediatype) { echo GedcomTag::getLabelValue('TYPE', GedcomTag::getFileFormTypeValue($mediatype)); } switch ($media->isPrimary()) { case 'Y': echo GedcomTag::getLabelValue('_PRIM', I18N::translate('yes')); break; case 'N': echo GedcomTag::getLabelValue('_PRIM', I18N::translate('no')); break; } echo FunctionsPrint::printFactNotes($media->getGedcom(), 1); echo self::printFactSources($media->getGedcom(), 1); } else { echo $xref; } echo '</td></tr>'; } } }
/** * Create a chart of media types. * * @param string[] $params * * @return string */ public function chartMedia($params = array()) { $WT_STATS_CHART_COLOR1 = Theme::theme()->parameter('distribution-chart-no-values'); $WT_STATS_CHART_COLOR2 = Theme::theme()->parameter('distribution-chart-high-values'); $WT_STATS_S_CHART_X = Theme::theme()->parameter('stats-small-chart-x'); $WT_STATS_S_CHART_Y = Theme::theme()->parameter('stats-small-chart-y'); if (isset($params[0]) && $params[0] != '') { $size = strtolower($params[0]); } else { $size = $WT_STATS_S_CHART_X . 'x' . $WT_STATS_S_CHART_Y; } if (isset($params[1]) && $params[1] != '') { $color_from = strtolower($params[1]); } else { $color_from = $WT_STATS_CHART_COLOR1; } if (isset($params[2]) && $params[2] != '') { $color_to = strtolower($params[2]); } else { $color_to = $WT_STATS_CHART_COLOR2; } $sizes = explode('x', $size); $tot = $this->totalMediaType('all'); // Beware divide by zero if ($tot == 0) { return I18N::translate('None'); } // Build a table listing only the media types actually present in the GEDCOM $mediaCounts = array(); $mediaTypes = ""; $chart_title = ""; $c = 0; $max = 0; $media = array(); foreach ($this->_media_types as $type) { $count = $this->totalMediaType($type); if ($count > 0) { $media[$type] = $count; if ($count > $max) { $max = $count; } $c += $count; } } $count = $this->totalMediaType('unknown'); if ($count > 0) { $media['unknown'] = $tot - $c; if ($tot - $c > $max) { $max = $count; } } if ($max / $tot > 0.6 && count($media) > 10) { arsort($media); $media = array_slice($media, 0, 10); $c = $tot; foreach ($media as $cm) { $c -= $cm; } if (isset($media['other'])) { $media['other'] += $c; } else { $media['other'] = $c; } } asort($media); foreach ($media as $type => $count) { $mediaCounts[] = round(100 * $count / $tot, 0); $mediaTypes .= GedcomTag::getFileFormTypeValue($type) . ' - ' . I18N::number($count) . '|'; $chart_title .= GedcomTag::getFileFormTypeValue($type) . ' (' . $count . '), '; } $chart_title = substr($chart_title, 0, -2); $chd = $this->arrayToExtendedEncoding($mediaCounts); $chl = substr($mediaTypes, 0, -1); return "<img src=\"https://chart.googleapis.com/chart?cht=p3&chd=e:{$chd}&chs={$size}&chco={$color_from},{$color_to}&chf=bg,s,ffffff00&chl={$chl}\" width=\"{$sizes[0]}\" height=\"{$sizes[1]}\" alt=\"" . $chart_title . "\" title=\"" . $chart_title . "\" />"; }
} else { echo '<p><b><a href="', $mediaobject->getHtmlUrl(), '">'; echo basename($mediaobject->getFilename()); echo '</a></b></p>'; echo GedcomTag::getLabelValue('TITL', $mediaobject->getFullName()); } // Show file details if ($mediaobject->isExternal()) { echo GedcomTag::getLabelValue('URL', $mediaobject->getFilename()); } else { if ($mediaobject->fileExists()) { if (Auth::isEditor($WT_TREE)) { echo GedcomTag::getLabelValue('FILE', $mediaobject->getFilename()); $mediatype = $mediaobject->getMediaType(); if ($mediatype) { echo GedcomTag::getLabelValue('TYPE', GedcomTag::getFileFormTypeValue($mediatype)); } } echo GedcomTag::getLabelValue('FORM', $mediaobject->mimeType()); echo GedcomTag::getLabelValue('__FILE_SIZE__', $mediaobject->getFilesize()); $imgsize = $mediaobject->getImageAttributes(); if ($imgsize['WxH']) { echo GedcomTag::getLabelValue('__IMAGE_SIZE__', $imgsize['WxH']); } } else { echo '<p class="ui-state-error">', I18N::translate('The file ā%sā does not exist.', $mediaobject->getFilename()), '</p>'; } } echo '<br>'; echo '<div>'; echo FunctionsPrintFacts::printFactSources($mediaobject->getGedcom(), 1);