Example #1
0
/**
 * 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;
    }
}
Example #2
0
 public function getBlock($block_id, $template = true, $cfg = null)
 {
     global $ctype, $SURNAME_LIST_STYLE;
     require_once WT_ROOT . 'includes/functions/functions_print_lists.php';
     $COMMON_NAMES_REMOVE = get_gedcom_setting(WT_GED_ID, 'COMMON_NAMES_REMOVE');
     $COMMON_NAMES_THRESHOLD = get_gedcom_setting(WT_GED_ID, 'COMMON_NAMES_THRESHOLD');
     $num = get_block_setting($block_id, 'num', 10);
     $infoStyle = get_block_setting($block_id, 'infoStyle', 'table');
     $block = get_block_setting($block_id, 'block', false);
     if ($cfg) {
         foreach (array('num', 'infoStyle', 'block') as $name) {
             if (array_key_exists($name, $cfg)) {
                 ${$name} = $cfg[$name];
             }
         }
     }
     // This next function is a bit out of date, and doesn't cope well with surname variants
     $top_surnames = get_top_surnames(WT_GED_ID, $COMMON_NAMES_THRESHOLD, $num);
     // Remove names found in the "Remove Names" list
     if ($COMMON_NAMES_REMOVE) {
         foreach (preg_split("/[,; ]+/", $COMMON_NAMES_REMOVE) as $delname) {
             unset($top_surnames[$delname]);
             unset($top_surnames[WT_I18N::strtoupper($delname)]);
         }
     }
     $all_surnames = array();
     $i = 0;
     foreach (array_keys($top_surnames) as $top_surname) {
         $all_surnames = array_merge($all_surnames, WT_Query_Name::surnames($top_surname, '', false, false, WT_GED_ID));
         if (++$i == $num) {
             break;
         }
     }
     if ($i < $num) {
         $num = $i;
     }
     $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 = '';
     }
     if ($num == 1) {
         // I18N: i.e. most popular surname.
         $title .= WT_I18N::translate('Top surname');
     } else {
         // I18N: Title for a list of the most common surnames, %s is a number.  Note that a separate translation exists when %s is 1
         $title .= WT_I18N::plural('Top %s surname', 'Top %s surnames', $num, WT_I18N::number($num));
     }
     switch ($infoStyle) {
         case 'tagcloud':
             uksort($all_surnames, array('WT_I18N', 'strcasecmp'));
             $content = format_surname_tagcloud($all_surnames, 'indilist.php', true);
             break;
         case 'list':
             uasort($all_surnames, array('top10_surnames_WT_Module', 'top_surname_sort'));
             $content = format_surname_list($all_surnames, '1', true, 'indilist.php');
             break;
         case 'array':
             uasort($all_surnames, array('top10_surnames_WT_Module', 'top_surname_sort'));
             $content = format_surname_list($all_surnames, '2', true, 'indilist.php');
             break;
         case 'table':
         default:
             uasort($all_surnames, array('top10_surnames_WT_Module', 'top_surname_sort'));
             $content = format_surname_table($all_surnames, 'indilist.php');
             break;
     }
     if ($template) {
         if ($block) {
             require WT_THEME_DIR . 'templates/block_small_temp.php';
         } else {
             require WT_THEME_DIR . 'templates/block_main_temp.php';
         }
     } else {
         return $content;
     }
 }
function print_block_name_top10($block = true, $config = "", $side, $index)
{
    global $pgv_lang, $COMMON_NAMES_ADD, $COMMON_NAMES_REMOVE, $COMMON_NAMES_THRESHOLD, $PGV_BLOCKS, $ctype, $PGV_IMAGES, $PGV_IMAGE_DIR, $SURNAME_LIST_STYLE;
    if (empty($config)) {
        $config = $PGV_BLOCKS["print_block_name_top10"]["config"];
    }
    // This next function is a bit out of date, and doesn't cope well with surname variants
    $top_surnames = get_top_surnames(PGV_GED_ID, 1, $config["num"]);
    $all_surnames = array();
    foreach (array_keys($top_surnames) as $top_surname) {
        $all_surnames = array_merge($all_surnames, get_indilist_surns($top_surname, '', false, false, PGV_GED_ID));
    }
    // Insert from the "Add Names" list if not already in there
    if ($COMMON_NAMES_ADD) {
        foreach (preg_split('/[,; ]+/', $COMMON_NAMES_ADD) as $addname) {
            $ADDNAME = UTF8_strtoupper($addname);
            if (isset($all_surnames[$ADDNAME])) {
                $SURNAME = $ADDNAME;
                foreach (array_keys($all_surnames[$ADDNAME]) as $surname) {
                    if ($SURNAME != $surname && $SURNAME == UTF8_strtoupper($surname)) {
                        $all_surnames[$ADDNAME][$SURNAME] = $all_surnames[$ADDNAME][$surname];
                        unset($all_surnames[$ADDNAME][$surname]);
                    }
                }
                if (isset($all_surnames[$ADDNAME][$SURNAME])) {
                    $n = count($all_surnames[$ADDNAME][$SURNAME]);
                    $all_surnames[$ADDNAME][$SURNAME] = array_fill(0, max($n, $COMMON_NAMES_THRESHOLD), true);
                } else {
                    $all_surnames[$ADDNAME][$SURNAME] = array_fill(0, $COMMON_NAMES_THRESHOLD, true);
                }
            } else {
                $all_surnames[$ADDNAME][$ADDNAME] = array_fill(0, $COMMON_NAMES_THRESHOLD, true);
            }
        }
    }
    // Remove names found in the "Remove Names" list
    if ($COMMON_NAMES_REMOVE) {
        foreach (preg_split("/[,; ]+/", $COMMON_NAMES_REMOVE) as $delname) {
            unset($all_surnames[UTF8_strtoupper($delname)]);
        }
    }
    $id = "top10surnames";
    $title = print_help_link("index_common_names_help", "qm", "", false, true);
    if ($PGV_BLOCKS["print_block_name_top10"]["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=600,height=350,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 .= str_replace("10", $config["num"], $pgv_lang["block_top10_title"]);
    switch ($SURNAME_LIST_STYLE) {
        case 'style3':
            uksort($all_surnames, 'stringsort');
            $content = format_surname_tagcloud($all_surnames, 'indilist', true);
            break;
        case 'style2':
        default:
            uasort($all_surnames, "top_surname_sort");
            $content = format_surname_table($all_surnames, 'indilist');
            break;
    }
    global $THEME_DIR;
    if ($block) {
        require $THEME_DIR . 'templates/block_small_temp.php';
    } else {
        require $THEME_DIR . 'templates/block_main_temp.php';
    }
}
Example #4
0
 function getCommonSurname()
 {
     $surnames = array_keys(get_top_surnames($this->_ged_id, 1, 1));
     return array_shift($surnames);
 }
Example #5
0
 function getCommonSurname($show_tot = false)
 {
     if ($show_tot) {
         return get_top_surnames(0);
     } else {
         foreach (array_keys(get_top_surnames(0)) as $surname) {
             return $surname;
         }
     }
 }