/** * Get array of common surnames * * This function returns a simple array of the most common surnames * found in the individuals list. * * @param int $min the number of times a surname must occur before it is added to the array * * @return array */ function get_common_surnames($min) { $COMMON_NAMES_ADD = get_gedcom_setting(WT_GED_ID, 'COMMON_NAMES_ADD'); $COMMON_NAMES_REMOVE = get_gedcom_setting(WT_GED_ID, 'COMMON_NAMES_REMOVE'); $topsurns = get_top_surnames(WT_GED_ID, $min, 0); foreach (explode(',', $COMMON_NAMES_ADD) as $surname) { if ($surname && !array_key_exists($surname, $topsurns)) { $topsurns[$surname] = $min; } } foreach (explode(',', $COMMON_NAMES_REMOVE) as $surname) { unset($topsurns[WT_I18N::strtoupper($surname)]); } //-- check if we found some, else recurse if (empty($topsurns) && $min > 2) { return get_common_surnames($min / 2); } else { uksort($topsurns, array('WT_I18N', 'strcasecmp')); foreach ($topsurns as $key => $value) { $topsurns[$key] = array('name' => $key, 'match' => $value); } return $topsurns; } }
/** * Store GEDCOMS array * * this function will store the <var>$GEDCOMS</var> array in the <var>$INDEX_DIRECTORY</var>/gedcoms.php * file. The gedcoms.php file is included in session.php to create the <var>$GEDCOMS</var> * array with every page request. * @see session.php */ function store_gedcoms() { global $GEDCOMS, $pgv_lang, $INDEX_DIRECTORY, $COMMON_NAMES_THRESHOLD, $GEDCOM, $CONFIGURED; global $IN_STORE_GEDCOMS; if (!$CONFIGURED) { return false; } //-- do not allow recursion into this function if (isset($IN_STORE_GEDCOMS) && $IN_STORE_GEDCOMS == true) { return false; } $IN_STORE_GEDCOMS = true; // $mutex = new Mutex("gedcoms.php"); // $mutex->Wait(); uasort($GEDCOMS, "gedcomsort"); $gedcomtext = "<?php\n//--START GEDCOM CONFIGURATIONS\n"; $gedcomtext .= "\$GEDCOMS = array();\n"; $maxid = 0; foreach ($GEDCOMS as $name => $details) { if (isset($details["id"]) && $details["id"] > $maxid) { $maxid = $details["id"]; } } if ($maxid != 0) { $maxid++; } reset($GEDCOMS); //-- keep a local copy in case another function tries to change $GEDCOMS $geds = $GEDCOMS; foreach ($geds as $indexval => $GED) { $GED["config"] = str_replace($INDEX_DIRECTORY, "\${INDEX_DIRECTORY}", $GED["config"]); if (isset($GED["privacy"])) { $GED["privacy"] = str_replace($INDEX_DIRECTORY, "\${INDEX_DIRECTORY}", $GED["privacy"]); } else { $GED["privacy"] = "privacy.php"; } $GED["path"] = str_replace($INDEX_DIRECTORY, "\${INDEX_DIRECTORY}", $GED["path"]); $GED["title"] = stripslashes($GED["title"]); $GED["title"] = preg_replace("/\"/", "\\\"", $GED["title"]); $gedcomtext .= "\$gedarray = array();\n"; $gedcomtext .= "\$gedarray[\"gedcom\"] = \"" . $GED["gedcom"] . "\";\n"; $gedcomtext .= "\$gedarray[\"config\"] = \"" . $GED["config"] . "\";\n"; $gedcomtext .= "\$gedarray[\"privacy\"] = \"" . $GED["privacy"] . "\";\n"; $gedcomtext .= "\$gedarray[\"title\"] = \"" . $GED["title"] . "\";\n"; $gedcomtext .= "\$gedarray[\"path\"] = \"" . $GED["path"] . "\";\n"; $gedcomtext .= "\$gedarray[\"pgv_ver\"] = \"" . $GED["pgv_ver"] . "\";\n"; if (isset($GED["imported"])) { $gedcomtext .= "\$gedarray[\"imported\"] = " . ($GED["imported"] == false ? 'false' : 'true') . ";\n"; } // TODO: Commonsurnames from an old gedcom are used // TODO: Default GEDCOM is changed to last uploaded GEDCOM // NOTE: Set the GEDCOM ID if (!isset($GED["id"]) && $maxid == 0) { $GED["id"] = 1; } elseif (!isset($GED["id"]) && $maxid > 0) { $GED["id"] = $maxid; } elseif (empty($GED["id"])) { $GED["id"] = $maxid; } $gedcomtext .= "\$gedarray[\"id\"] = \"" . $GED["id"] . "\";\n"; if (empty($GED["commonsurnames"])) { if ($GED["gedcom"] == $GEDCOM) { $GED["commonsurnames"] = ""; $surnames = get_common_surnames($COMMON_NAMES_THRESHOLD); foreach ($surnames as $indexval => $surname) { $GED["commonsurnames"] .= $surname["name"] . ", "; } } else { $GED["commonsurnames"] = ""; } } $geds[$GED["gedcom"]]["commonsurnames"] = $GED["commonsurnames"]; $gedcomtext .= "\$gedarray[\"commonsurnames\"] = \"" . addslashes($GED["commonsurnames"]) . "\";\n"; $gedcomtext .= "\$GEDCOMS[\"" . $GED["gedcom"] . "\"] = \$gedarray;\n"; } $GEDCOMS = $geds; $gedcomtext .= "\n?" . ">"; $fp = @fopen($INDEX_DIRECTORY . "gedcoms.php", "wb"); if (!$fp) { global $whichFile; $whichFile = $INDEX_DIRECTORY . "gedcoms.php"; print "<span class=\"error\">" . print_text("gedcom_config_write_error", 0, 1) . "<br /></span>\n"; } else { fwrite($fp, $gedcomtext); fclose($fp); check_in("store_gedcoms() ->" . getUserName() . "<-", "gedcoms.php", $INDEX_DIRECTORY, true); } // $mutex->Release(); $IN_STORE_GEDCOMS = false; return true; }
function print_gedcom_stats($block = true, $config = '', $side, $index) { global $PGV_BLOCKS, $pgv_lang, $ALLOW_CHANGE_GEDCOM, $ctype, $COMMON_NAMES_THRESHOLD, $PGV_IMAGE_DIR, $PGV_IMAGES, $MULTI_MEDIA; global $top10_block_present; if (empty($config)) { $config = $PGV_BLOCKS['print_gedcom_stats']['config']; } if (!isset($config['stat_indi'])) { $config = $PGV_BLOCKS['print_gedcom_stats']['config']; } if (!isset($config['stat_first_death'])) { $config['stat_first_death'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_first_death']; } if (!isset($config['stat_last_death'])) { $config['stat_last_death'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_last_death']; } if (!isset($config['stat_media'])) { $config['stat_media'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_media']; } if (!isset($config['stat_link'])) { $config['stat_link'] = $PGV_BLOCKS['print_gedcom_stats']['config']['stat_link']; } $id = 'gedcom_stats'; $title = print_help_link('index_stats_help', 'qm', '', false, true); if ($PGV_BLOCKS['print_gedcom_stats']['canconfig']) { if ($ctype == 'gedcom' && PGV_USER_GEDCOM_ADMIN || $ctype == 'user' && PGV_USER_ID) { if ($ctype == 'gedcom') { $name = PGV_GEDCOM; } else { $name = PGV_USER_NAME; } $title .= "<a href=\"javascript: configure block\" onclick=\"window.open('" . encode_url("index_edit.php?name={$name}&ctype={$ctype}&action=configure&side={$side}&index={$index}") . "', '_blank', 'top=50,left=50,width=700,height=400,scrollbars=1,resizable=1'); return false;\">"; $title .= "<img class=\"adminicon\" src=\"{$PGV_IMAGE_DIR}/" . $PGV_IMAGES['admin']['small'] . "\" width=\"15\" height=\"15\" border=\"0\" alt=\"" . $pgv_lang['config_block'] . "\" /></a>"; } } $title .= $pgv_lang['gedcom_stats']; $stats = new stats(PGV_GEDCOM); $content = "<b><a href=\"index.php?ctype=gedcom\">" . PrintReady(strip_tags(get_gedcom_setting(PGV_GED_ID, 'title'))) . "</a></b><br />"; $head = find_other_record('HEAD', PGV_GED_ID); $ct = preg_match('/1 SOUR (.*)/', $head, $match); if ($ct > 0) { $softrec = get_sub_record(1, '1 SOUR', $head); $tt = preg_match('/2 NAME (.*)/', $softrec, $tmatch); if ($tt > 0) { $software = printReady(trim($tmatch[1])); } else { $software = trim($match[1]); } if (!empty($software)) { $text = str_replace(array('#SOFTWARE#', '#CREATED_SOFTWARE#'), $software, $pgv_lang['gedcom_created_using']); $tt = preg_match('/2 VERS (.*)/', $softrec, $tmatch); if ($tt > 0) { $version = printReady(trim($tmatch[1])); } else { $version = ''; } $text = str_replace(array('#VERSION#', '#CREATED_VERSION#'), $version, $text); $content .= $text; } } if (preg_match('/1 DATE (.+)/', $head, $match)) { if (empty($software)) { $content .= str_replace(array('#DATE#', '#CREATED_DATE#'), $stats->gedcomDate(), $pgv_lang['gedcom_created_on']); } else { $content .= str_replace(array('#DATE#', '#CREATED_DATE#'), $stats->gedcomDate(), $pgv_lang['gedcom_created_on2']); } } $content .= '<br /><table><tr><td valign="top" class="width20"><table cellspacing="1" cellpadding="0">'; if ($config['stat_indi'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_individuals'] . '</td><td class="facts_value"><div dir="rtl"><a href="' . encode_url("indilist.php?surname_sublist=no&ged=" . PGV_GEDCOM) . '">' . $stats->totalIndividuals() . '</a></div></td></tr>'; $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_males'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalSexMales() . '<br />' . $stats->totalSexMalesPercentage() . '%</div></td></tr>'; $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_females'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalSexFemales() . '<br />' . $stats->totalSexFemalesPercentage() . '%</div></td></tr>'; } if ($config['stat_surname'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_surnames'] . '</td><td class="facts_value"><div dir="rtl"><a href="' . encode_url("indilist.php?show_all=yes&surname_sublist=yes&ged=" . PGV_GEDCOM) . '">' . $stats->totalSurnames() . '</a></div></td></tr>'; } if ($config['stat_fam'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_families'] . '</td><td class="facts_value"><div dir="rtl"><a href="famlist.php">' . $stats->totalFamilies() . '</a></div></td></tr>'; } if ($config['stat_sour'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_sources'] . '</td><td class="facts_value"><div dir="rtl"><a href="sourcelist.php">' . $stats->totalSources() . '</a></div></td></tr>'; } if ($config['stat_media'] == 'yes' && $MULTI_MEDIA == true) { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_media'] . '</td><td class="facts_value"><div dir="rtl"><a href="medialist.php">' . $stats->totalMedia() . '</a></div></td></tr>'; } if ($config['stat_other'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_other'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalOtherRecords() . '</div></td></tr>'; } if ($config['stat_events'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_events'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->totalEvents() . '</div></td></tr>'; } if ($config['stat_users'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_users'] . '</td><td class="facts_value"><div dir="rtl">'; if (PGV_USER_GEDCOM_ADMIN) { $content .= '<a href="useradmin.php">' . $stats->totalUsers() . '</a>'; } else { $content .= $stats->totalUsers(); } $content .= '</div> </td> </tr>'; } if (!$block) { $content .= '</table></td><td><br /></td><td valign="top"><table cellspacing="1" cellpadding="1" border="0">'; } if ($config['stat_first_birth'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_earliest_birth'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->firstBirthYear() . '</div></td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->firstBirth() . '</td>'; } $content .= '</tr>'; } if ($config['stat_last_birth'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_latest_birth'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->lastBirthYear() . '</div></td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->lastBirth() . '</td>'; } $content .= '</tr>'; } if ($config['stat_first_death'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_earliest_death'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->firstDeathYear() . '</div></td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->firstDeath() . '</td>'; } $content .= '</tr>'; } if ($config['stat_last_death'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_latest_death'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->lastDeathYear() . '</div> </td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->lastDeath() . '</td>'; } $content .= '</tr>'; } if ($config['stat_long_life'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_longest_life'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->LongestLifeAge() . '</div></td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->LongestLife() . '</td>'; } $content .= '</tr>'; } if ($config['stat_avg_life'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_avg_age_at_death'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->averageLifespan() . '</div></td>'; if (!$block) { $content .= '<td class="facts_value">' . $pgv_lang['stat_males'] . ': ' . $stats->averageLifespanMale(); $content .= ' ' . $pgv_lang['stat_females'] . ': ' . $stats->averageLifespanFemale() . '</td>'; } $content .= '</tr>'; } if ($config['stat_most_chil'] == 'yes' && !$block) { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_most_children'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->largestFamilySize() . '</div></td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->largestFamily() . '</td>'; } $content .= '</tr>'; } if ($config['stat_avg_chil'] == 'yes') { $content .= '<tr><td class="facts_label">' . $pgv_lang['stat_average_children'] . '</td><td class="facts_value"><div dir="rtl">' . $stats->averageChildren() . '</div></td>'; if (!$block) { $content .= '<td class="facts_value"> </td>'; } $content .= '</tr>'; } $content .= '</table></td></tr></table>'; if ($config['stat_link'] == 'yes') { $content .= '<a href="statistics.php"><b>' . $pgv_lang['stat_link'] . '</b></a><br />'; } // NOTE: Print the most common surnames if ($config['show_common_surnames'] == 'yes') { $surnames = get_common_surnames($COMMON_NAMES_THRESHOLD); if (count($surnames) > 0) { $content .= '<br />'; $content .= print_help_link('index_common_names_help', 'qm', '', false, true); $content .= '<b>' . $pgv_lang['common_surnames'] . '</b><br />'; $i = 0; foreach ($surnames as $indexval => $surname) { if (stristr($surname['name'], '@N.N') === false) { if ($i > 0) { $content .= ', '; } $content .= '<a href="' . encode_url("indilist.php?ged=" . PGV_GEDCOM . "&surname=" . $surname['name']) . '">' . PrintReady($surname['name']) . '</a>'; $i++; } } } } global $THEME_DIR; if ($block) { require $THEME_DIR . 'templates/block_small_temp.php'; } else { require $THEME_DIR . 'templates/block_main_temp.php'; } }
public function getBlock($block_id, $template = true, $cfg = null) { global $ctype, $top10_block_present; $show_last_update = get_block_setting($block_id, 'show_last_update', true); $show_common_surnames = get_block_setting($block_id, 'show_common_surnames', true); $stat_indi = get_block_setting($block_id, 'stat_indi', true); $stat_fam = get_block_setting($block_id, 'stat_fam', true); $stat_sour = get_block_setting($block_id, 'stat_sour', true); $stat_media = get_block_setting($block_id, 'stat_media', true); $stat_repo = get_block_setting($block_id, 'stat_repo', true); $stat_surname = get_block_setting($block_id, 'stat_surname', true); $stat_events = get_block_setting($block_id, 'stat_events', true); $stat_users = get_block_setting($block_id, 'stat_users', true); $stat_first_birth = get_block_setting($block_id, 'stat_first_birth', true); $stat_last_birth = get_block_setting($block_id, 'stat_last_birth', true); $stat_first_death = get_block_setting($block_id, 'stat_first_death', true); $stat_last_death = get_block_setting($block_id, 'stat_last_death', true); $stat_long_life = get_block_setting($block_id, 'stat_long_life', true); $stat_avg_life = get_block_setting($block_id, 'stat_avg_life', true); $stat_most_chil = get_block_setting($block_id, 'stat_most_chil', true); $stat_avg_chil = get_block_setting($block_id, 'stat_avg_chil', true); $stat_link = get_block_setting($block_id, 'stat_link', true); $block = get_block_setting($block_id, 'block', false); if ($cfg) { foreach (array('show_common_surnames', 'stat_indi', 'stat_fam', 'stat_sour', 'stat_media', 'stat_surname', 'stat_events', 'stat_users', 'stat_first_birth', 'stat_last_birth', 'stat_first_death', 'stat_last_death', 'stat_long_life', 'stat_avg_life', 'stat_most_chil', 'stat_avg_chil', 'stat_link', 'block') as $name) { if (array_key_exists($name, $cfg)) { ${$name} = $cfg[$name]; } } } $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(); $stats = new WT_Stats(WT_GEDCOM); $content = '<b>' . WT_TREE_TITLE . '</b><br>'; if ($show_last_update) { $content .= '<div>' . WT_I18N::translate('This family tree was last updated on %s.', strip_tags($stats->gedcomUpdated())) . '</div>'; } $content .= '<table><tr><td class="width20"><table class="facts_table">'; if ($stat_indi) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Individuals') . '</td><td class="facts_value stats_value"><a href="' . "indilist.php?surname_sublist=no&ged=" . WT_GEDURL . '">' . $stats->totalIndividuals() . '</a></td></tr>'; $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Males') . '</td><td class="facts_value stats_value">' . $stats->totalSexMales() . '<br>' . $stats->totalSexMalesPercentage() . '</td></tr>'; $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Females') . '</td><td class="facts_value stats_value">' . $stats->totalSexFemales() . '<br>' . $stats->totalSexFemalesPercentage() . '</td></tr>'; } if ($stat_surname) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Total surnames') . '</td><td class="facts_value stats_value"><a href="indilist.php?show_all=yes&surname_sublist=yes&ged=' . WT_GEDURL . '">' . $stats->totalSurnames() . '</a></td></tr>'; } if ($stat_fam) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Families') . '</td><td class="facts_value stats_value"><a href="famlist.php?ged=' . WT_GEDURL . '">' . $stats->totalFamilies() . '</a></td></tr>'; } if ($stat_sour) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Sources') . '</td><td class="facts_value stats_value"><a href="sourcelist.php?ged=' . WT_GEDURL . '">' . $stats->totalSources() . '</a></td></tr>'; } if ($stat_media) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Media objects') . '</td><td class="facts_value stats_value"><a href="medialist.php?ged=' . WT_GEDURL . '">' . $stats->totalMedia() . '</a></td></tr>'; } if ($stat_repo) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Repositories') . '</td><td class="facts_value stats_value"><a href="repolist.php?ged=' . WT_GEDURL . '">' . $stats->totalRepositories() . '</a></td></tr>'; } if ($stat_events) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Total events') . '</td><td class="facts_value stats_value">' . $stats->totalEvents() . '</td></tr>'; } if ($stat_users) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Total users') . '</td><td class="facts_value stats_value">'; if (WT_USER_GEDCOM_ADMIN) { $content .= '<a href="admin_users.php">' . $stats->totalUsers() . '</a>'; } else { $content .= $stats->totalUsers(); } $content .= '</td></tr>'; } if (!$block) { $content .= '</table></td><td><table class="facts_table">'; } if ($stat_first_birth) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Earliest birth year') . '</td><td class="facts_value stats_value">' . $stats->firstBirthYear() . '</td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->firstBirth() . '</td>'; } $content .= '</tr>'; } if ($stat_last_birth) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Latest birth year') . '</td><td class="facts_value stats_value">' . $stats->lastBirthYear() . '</td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->lastBirth() . '</td>'; } $content .= '</tr>'; } if ($stat_first_death) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Earliest death year') . '</td><td class="facts_value stats_value">' . $stats->firstDeathYear() . '</td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->firstDeath() . '</td>'; } $content .= '</tr>'; } if ($stat_last_death) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Latest death year') . '</td><td class="facts_value stats_value">' . $stats->lastDeathYear() . ' </td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->lastDeath() . '</td>'; } $content .= '</tr>'; } if ($stat_long_life) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Individual who lived the longest') . '</td><td class="facts_value stats_value">' . $stats->LongestLifeAge() . '</td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->LongestLife() . '</td>'; } $content .= '</tr>'; } if ($stat_avg_life) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Average age at death') . '</td><td class="facts_value stats_value">' . $stats->averageLifespan() . '</td>'; if (!$block) { $content .= '<td class="facts_value">' . WT_I18N::translate('Males') . ': ' . $stats->averageLifespanMale(); $content .= ' ' . WT_I18N::translate('Females') . ': ' . $stats->averageLifespanFemale() . '</td>'; } $content .= '</tr>'; } if ($stat_most_chil && !$block) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Family with the most children') . '</td><td class="facts_value stats_value">' . $stats->largestFamilySize() . '</td>'; if (!$block) { $content .= '<td class="facts_value">' . $stats->largestFamily() . '</td>'; } $content .= '</tr>'; } if ($stat_avg_chil) { $content .= '<tr><td class="facts_label">' . WT_I18N::translate('Average number of children per family') . '</td><td class="facts_value stats_value">' . $stats->averageChildren() . '</td>'; if (!$block) { $content .= '<td class="facts_value"> </td>'; } $content .= '</tr>'; } $content .= '</table></td></tr></table>'; if ($stat_link) { $content .= '<a href="statistics.php?ged=' . WT_GEDURL . '"><b>' . WT_I18N::translate('View statistics as graphs') . '</b></a><br>'; } // NOTE: Print the most common surnames if ($show_common_surnames) { $surnames = get_common_surnames(get_gedcom_setting(WT_GED_ID, 'COMMON_NAMES_THRESHOLD')); if (count($surnames) > 0) { $content .= '<p><b>' . WT_I18N::translate('Most common surnames') . '</b></p>'; $content .= '<div class="common_surnames">'; $i = 0; foreach ($surnames as $indexval => $surname) { if (stristr($surname['name'], '@N.N') === false) { if ($i > 0) { $content .= ', '; } $content .= '<a href="' . "indilist.php?ged=" . WT_GEDURL . "&surname=" . rawurlencode($surname['name']) . '">' . $surname['name'] . '</a>'; $i++; } } $content .= '</div>'; } } if ($template) { require WT_THEME_DIR . 'templates/block_main_temp.php'; } else { return $content; } }
function chartCommonSurnames($params = null) { global $WT_STATS_CHART_COLOR1, $WT_STATS_CHART_COLOR2, $WT_STATS_S_CHART_X, $WT_STATS_S_CHART_Y; if ($params === null) { $params = array(); } 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; } if (isset($params[3]) && $params[3] != '') { $threshold = strtolower($params[3]); } else { $threshold = get_gedcom_setting($this->_ged_id, 'COMMON_NAMES_THRESHOLD'); } if (isset($params[4]) && $params[4] != '') { $maxtoshow = strtolower($params[4]); } else { $maxtoshow = 7; } $sizes = explode('x', $size); $tot_indi = $this->_totalIndividuals(); $surnames = get_common_surnames($threshold); if (count($surnames) <= 0) { return ''; } $SURNAME_TRADITION = get_gedcom_setting(WT_GED_ID, 'SURNAME_TRADITION'); uasort($surnames, array('WT_Stats', '_name_total_rsort')); $surnames = array_slice($surnames, 0, $maxtoshow); $all_surnames = array(); foreach (array_keys($surnames) as $n => $surname) { if ($n >= $maxtoshow) { break; } $all_surnames = array_merge($all_surnames, WT_Query_Name::surnames(WT_I18N::strtoupper($surname), '', false, false, WT_GED_ID)); } $tot = 0; foreach ($surnames as $surname) { $tot += $surname['match']; } $chd = ''; $chl = array(); foreach ($all_surnames as $surns) { $count_per = 0; $max_name = 0; foreach ($surns as $spfxsurn => $indis) { $per = count($indis); $count_per += $per; // select most common surname from all variants if ($per > $max_name) { $max_name = $per; $top_name = $spfxsurn; } } switch ($SURNAME_TRADITION) { case 'polish': // most common surname should be in male variant (Kowalski, not Kowalska) $top_name = preg_replace(array('/ska$/', '/cka$/', '/dzka$/', '/żka$/'), array('ski', 'cki', 'dzki', 'żki'), $top_name); } $per = round(100 * $count_per / $tot_indi, 0); $chd .= self::_array_to_extended_encoding($per); //ToDo: RTL names are often printed LTR when also LTR names are present $chl[] = $top_name . ' - ' . WT_I18N::number($count_per); } $per = round(100 * ($tot_indi - $tot) / $tot_indi, 0); $chd .= self::_array_to_extended_encoding($per); $chl[] = WT_I18N::translate('Other') . ' - ' . WT_I18N::number($tot_indi - $tot); $chart_title = implode(WT_I18N::$list_separator, $chl); $chl = implode('|', $chl); 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=' . rawurlencode($chl) . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" alt="' . $chart_title . '" title="' . $chart_title . '" />'; }
function chartCommonSurnames($params = null) { global $pgv_lang, $COMMON_NAMES_THRESHOLD, $PGV_STATS_CHART_COLOR1, $PGV_STATS_CHART_COLOR2, $PGV_STATS_S_CHART_X, $PGV_STATS_S_CHART_Y; if ($params === null) { $params = array(); } if (isset($params[0]) && $params[0] != '') { $size = strtolower($params[0]); } else { $size = $PGV_STATS_S_CHART_X . "x" . $PGV_STATS_S_CHART_Y; } if (isset($params[1]) && $params[1] != '') { $color_from = strtolower($params[1]); } else { $color_from = $PGV_STATS_CHART_COLOR1; } if (isset($params[2]) && $params[2] != '') { $color_to = strtolower($params[2]); } else { $color_to = $PGV_STATS_CHART_COLOR2; } if (isset($params[3]) && $params[3] != '') { $threshold = strtolower($params[3]); } else { $threshold = $COMMON_NAMES_THRESHOLD; } if (isset($params[4]) && $params[4] != '') { $maxtoshow = strtolower($params[4]); } else { $maxtoshow = 7; } $sizes = explode('x', $size); $tot_indi = $this->totalIndividuals(); $surnames = get_common_surnames($threshold); uasort($surnames, array('stats', '_name_total_rsort')); $surnames = array_slice($surnames, 0, $maxtoshow); $all_surnames = array(); foreach (array_keys($surnames) as $n => $surname) { if ($n >= $maxtoshow) { break; } $all_surnames = array_merge($all_surnames, get_indilist_surns(UTF8_strtoupper($surname), '', false, false, PGV_GED_ID)); } if (count($surnames) <= 0) { return ''; } $tot = 0; foreach ($surnames as $indexval => $surname) { $tot += $surname['match']; } $chart_title = ""; $chd = ''; $chl = array(); foreach ($all_surnames as $surn => $surns) { foreach ($surns as $spfxsurn => $indis) { if ($tot == 0) { $per = 0; } else { $per = round(100 * count($indis) / $tot_indi, 0); } $chd .= self::_array_to_extended_encoding($per); $chl[] = $spfxsurn . ' - ' . count($indis); $chart_title .= $spfxsurn . ' [' . count($indis) . '], '; } } $per = round(100 * ($tot_indi - $tot) / $tot_indi, 0); $chd .= self::_array_to_extended_encoding($per); $chl[] = $pgv_lang["other"] . ' - ' . ($tot_indi - $tot); $chart_title .= $pgv_lang["other"] . ' [' . ($tot_indi - $tot) . ']'; $chl = join('|', $chl); return "<img src=\"" . encode_url("http://chart.apis.google.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 . "\" />"; }