示例#1
0
function compare_facts_date($arec, $brec)
{
    if (is_array($arec)) {
        $arec = $arec[1];
    }
    if (is_array($brec)) {
        $brec = $brec[1];
    }
    // If either fact is undated, the facts sort equally.
    if (!preg_match("/2 _?DATE (.*)/", $arec, $amatch) || !preg_match("/2 _?DATE (.*)/", $brec, $bmatch)) {
        if (preg_match('/2 _SORT (\\d+)/', $arec, $match1) && preg_match('/2 _SORT (\\d+)/', $brec, $match2)) {
            return $match1[1] - $match2[1];
        }
        return 0;
    }
    $adate = new GedcomDate($amatch[1]);
    $bdate = new GedcomDate($bmatch[1]);
    // If either date can't be parsed, don't sort.
    if (!$adate->isOK() || !$bdate->isOK()) {
        if (preg_match('/2 _SORT (\\d+)/', $arec, $match1) && preg_match('/2 _SORT (\\d+)/', $brec, $match2)) {
            return $match1[1] - $match2[1];
        }
        return 0;
    }
    // Remember that dates can be ranges and overlapping ranges sort equally.
    $amin = $adate->MinJD();
    $bmin = $bdate->MinJD();
    $amax = $adate->MaxJD();
    $bmax = $bdate->MaxJD();
    // BEF/AFT XXX sort as the day before/after XXX
    if ($adate->qual1 == 'BEF') {
        $amin = $amin - 1;
        $amax = $amin;
    } else {
        if ($adate->qual1 == 'AFT') {
            $amax = $amax + 1;
            $amin = $amax;
        }
    }
    if ($bdate->qual1 == 'BEF') {
        $bmin = $bmin - 1;
        $bmax = $bmin;
    } else {
        if ($bdate->qual1 == 'AFT') {
            $bmax = $bmax + 1;
            $bmin = $bmax;
        }
    }
    if ($amax < $bmin) {
        return -1;
    } else {
        if ($amin > $bmax) {
            return 1;
        } else {
            //-- ranged date... take the type of fact sorting into account
            $factWeight = 0;
            if (preg_match('/2 _SORT (\\d+)/', $arec, $match1) && preg_match('/2 _SORT (\\d+)/', $brec, $match2)) {
                $factWeight = $match1[1] - $match2[1];
            }
            //-- fact is prefered to come before, so compare using the minimum ranges
            if ($factWeight < 0 && $amin != $bmin) {
                return $amin - $bmin;
            } else {
                if ($factWeight > 0 && $bmax != $amax) {
                    //-- fact is prefered to come after, so compare using the max of the ranges
                    return $bmax - $amax;
                } else {
                    //-- facts are the same or the ranges don't give enough info, so use the average of the range
                    $aavg = ($amin + $amax) / 2;
                    $bavg = ($bmin + $bmax) / 2;
                    if ($aavg < $bavg) {
                        return -1;
                    } else {
                        if ($aavg > $bavg) {
                            return 1;
                        } else {
                            return $factWeight;
                        }
                    }
                }
            }
            return 0;
        }
    }
}
示例#2
0
         if (!move_uploaded_file($_FILES['thumbnail']['tmp_name'], $MEDIA_DIRECTORY . "thumbs/" . $_FILES['thumbnail']['name'])) {
             $error .= "\nERROR 19: " . $pgv_lang["upload_error"] . " " . file_upload_error_text($_FILES['thumbnail']['error']);
         }
     }
     if (!empty($error)) {
         addDebugLog($action . " {$error}");
         print $error . "\n";
     } else {
         addDebugLog($action . " SUCCESS");
         print "SUCCESS\n";
     }
     exit;
 case 'getchanges':
     $lastdate = new GedcomDate(safe_REQUEST($_REQUEST, 'date', '\\d\\d \\w\\w\\w \\d\\d\\d\\d'));
     if ($lastdate->isOK()) {
         if ($lastdate->MinJD() < server_jd() - 180) {
             addDebugLog($action . " ERROR 24: You cannot retrieve updates for more than 180 days.");
             print "ERROR 24: You cannot retrieve updates for more than 180 days.\n";
         } else {
             print "SUCCESS\n";
             foreach (get_recent_changes($lastdate->MinJD()) as $xref) {
                 echo "{$xref}\n";
             }
         }
     } else {
         addDebugLog($action . " ERROR 23: Invalid date parameter.  Please use a valid date in the GEDCOM format DD MMM YYYY.");
         print "ERROR 23: Invalid date parameter.  Please use a valid date in the GEDCOM format DD MMM YYYY.\n";
     }
     exit;
 default:
     addDebugLog($action . " ERROR 2: Unable to process request.  Unknown action.");
示例#3
0
        for ($jd = $cal_date->minJD; $jd <= $cal_date->maxJD; ++$jd) {
            foreach (apply_filter(get_anniversary_events($jd, $events), $filterof, $filtersx) as $event) {
                $tmp = $event['date']->MinDate();
                if ($tmp->d >= 1 && $tmp->d <= $tmp->DaysInMonth()) {
                    $d = $jd - $cal_date->minJD + 1;
                } else {
                    $d = 0;
                }
                $found_facts[$d][] = $event;
            }
        }
        break;
    case 'year':
        $cal_date->m = 0;
        $cal_date->SetJDfromYMD();
        $found_facts = apply_filter(get_calendar_events($ged_date->MinJD(), $ged_date->MaxJD(), $events), $filterof, $filtersx);
        // Eliminate duplictes (e.g. BET JUL 1900 AND SEP 1900 will appear twice in 1900)
        foreach ($found_facts as $key => $value) {
            $found_facts[$key] = serialize($found_facts[$key]);
        }
        $found_facts = array_unique($found_facts);
        foreach ($found_facts as $key => $value) {
            $found_facts[$key] = unserialize($found_facts[$key]);
        }
        break;
}
// Group the facts by family/individual
switch ($action) {
    case 'year':
    case 'today':
        $indis = array();