コード例 #1
0
ファイル: Tree.php プロジェクト: AlexSnet/webtrees
 /**
  * Export the tree to a GEDCOM file
  *
  * @param resource $stream
  */
 public function exportGedcom($stream)
 {
     $stmt = Database::prepare("SELECT i_gedcom AS gedcom, i_id AS xref, 1 AS n FROM `##individuals` WHERE i_file = :tree_id_1" . " UNION ALL " . "SELECT f_gedcom AS gedcom, f_id AS xref, 2 AS n FROM `##families`    WHERE f_file = :tree_id_2" . " UNION ALL " . "SELECT s_gedcom AS gedcom, s_id AS xref, 3 AS n FROM `##sources`     WHERE s_file = :tree_id_3" . " UNION ALL " . "SELECT o_gedcom AS gedcom, o_id AS xref, 4 AS n FROM `##other`       WHERE o_file = :tree_id_4 AND o_type NOT IN ('HEAD', 'TRLR')" . " UNION ALL " . "SELECT m_gedcom AS gedcom, m_id AS xref, 5 AS n FROM `##media`       WHERE m_file = :tree_id_5" . " ORDER BY n, LENGTH(xref), xref")->execute(array('tree_id_1' => $this->tree_id, 'tree_id_2' => $this->tree_id, 'tree_id_3' => $this->tree_id, 'tree_id_4' => $this->tree_id, 'tree_id_5' => $this->tree_id));
     $buffer = FunctionsExport::reformatRecord(FunctionsExport::gedcomHeader($this));
     while ($row = $stmt->fetch()) {
         $buffer .= FunctionsExport::reformatRecord($row->gedcom);
         if (strlen($buffer) > 65535) {
             fwrite($stream, $buffer);
             $buffer = '';
         }
     }
     fwrite($stream, $buffer . '0 TRLR' . WT_EOL);
     $stmt->closeCursor();
 }
コード例 #2
0
        if ($v_list == 0) {
            echo "Error : " . $archive->errorInfo(true);
        } else {
            header('Content-Type: application/zip');
            header('Content-Disposition: attachment; filename="' . $zip_file . '"');
            header('Content-length: ' . filesize($temp_dir . $zip_file));
            readfile($temp_dir . $zip_file);
            File::delete($temp_dir);
        }
    } else {
        header('Content-Type: text/plain; charset=UTF-8');
        header('Content-Disposition: attachment; filename="' . $download_filename . '"');
        // Stream the GEDCOM file straight to the browser.
        // We could open "php://compress.zlib" to create a .gz file or "php://compress.bzip2" to create a .bz2 file
        $stream = fopen('php://output', 'w');
        FunctionsExport::exportGedcom($WT_TREE, $stream, $exportOptions);
        fclose($stream);
    }
    return;
}
$controller->pageHeader();
?>
<ol class="breadcrumb small">
	<li><a href="admin.php"><?php 
echo I18N::translate('Control panel');
?>
</a></li>
	<li><a href="admin_trees_manage.php"><?php 
echo I18N::translate('Manage family trees');
?>
</a></li>
コード例 #3
0
 /**
  * Create the clippings controller
  */
 public function __construct()
 {
     global $WT_TREE;
     // Our cart is an array of items in the session
     $this->cart = Session::get('cart', array());
     if (!array_key_exists($WT_TREE->getTreeId(), $this->cart)) {
         $this->cart[$WT_TREE->getTreeId()] = array();
     }
     $this->action = Filter::get('action');
     $this->id = Filter::get('id');
     $convert = Filter::get('convert', 'yes|no', 'no');
     $this->Zip = Filter::get('Zip');
     $this->IncludeMedia = Filter::get('IncludeMedia');
     $this->conv_path = Filter::get('conv_path');
     $this->privatize_export = Filter::get('privatize_export', 'none|visitor|user|gedadmin', 'visitor');
     $this->level1 = Filter::getInteger('level1');
     $this->level2 = Filter::getInteger('level2');
     $this->level3 = Filter::getInteger('level3');
     $others = Filter::get('others');
     $this->type = Filter::get('type');
     if (($this->privatize_export === 'none' || $this->privatize_export === 'none') && !Auth::isManager($WT_TREE)) {
         $this->privatize_export = 'visitor';
     }
     if ($this->privatize_export === 'user' && !Auth::isMember($WT_TREE)) {
         $this->privatize_export = 'visitor';
     }
     if ($this->action === 'add') {
         if (empty($this->type) && !empty($this->id)) {
             $obj = GedcomRecord::getInstance($this->id, $WT_TREE);
             if ($obj) {
                 $this->type = $obj::RECORD_TYPE;
             } else {
                 $this->type = '';
                 $this->id = '';
                 $this->action = '';
             }
         } elseif (empty($this->id)) {
             $this->action = '';
         }
         if (!empty($this->id) && $this->type !== 'FAM' && $this->type !== 'INDI' && $this->type !== 'SOUR') {
             $this->action = 'add1';
         }
     }
     if ($this->action === 'add1') {
         $obj = GedcomRecord::getInstance($this->id, $WT_TREE);
         $this->addClipping($obj);
         if ($this->type === 'SOUR') {
             if ($others === 'linked') {
                 foreach ($obj->linkedIndividuals('SOUR') as $indi) {
                     $this->addClipping($indi);
                 }
                 foreach ($obj->linkedFamilies('SOUR') as $fam) {
                     $this->addClipping($fam);
                 }
             }
         }
         if ($this->type === 'FAM') {
             if ($others === 'parents') {
                 $this->addClipping($obj->getHusband());
                 $this->addClipping($obj->getWife());
             } elseif ($others === "members") {
                 $this->addFamilyMembers(Family::getInstance($this->id, $WT_TREE));
             } elseif ($others === "descendants") {
                 $this->addFamilyDescendancy(Family::getInstance($this->id, $WT_TREE));
             }
         } elseif ($this->type === 'INDI') {
             if ($others === 'parents') {
                 foreach (Individual::getInstance($this->id, $WT_TREE)->getChildFamilies() as $family) {
                     $this->addFamilyMembers($family);
                 }
             } elseif ($others === 'ancestors') {
                 $this->addAncestorsToCart(Individual::getInstance($this->id, $WT_TREE), $this->level1);
             } elseif ($others === 'ancestorsfamilies') {
                 $this->addAncestorsToCartFamilies(Individual::getInstance($this->id, $WT_TREE), $this->level2);
             } elseif ($others === 'members') {
                 foreach (Individual::getInstance($this->id, $WT_TREE)->getSpouseFamilies() as $family) {
                     $this->addFamilyMembers($family);
                 }
             } elseif ($others === 'descendants') {
                 foreach (Individual::getInstance($this->id, $WT_TREE)->getSpouseFamilies() as $family) {
                     $this->addClipping($family);
                     $this->addFamilyDescendancy($family, $this->level3);
                 }
             }
             uksort($this->cart[$WT_TREE->getTreeId()], array($this, 'compareClippings'));
         }
     } elseif ($this->action === 'remove') {
         unset($this->cart[$WT_TREE->getTreeId()][$this->id]);
     } elseif ($this->action === 'empty') {
         $this->cart[$WT_TREE->getTreeId()] = array();
     } elseif ($this->action === 'download') {
         $media = array();
         $mediacount = 0;
         $filetext = FunctionsExport::gedcomHeader($WT_TREE);
         // Include SUBM/SUBN records, if they exist
         $subn = Database::prepare("SELECT o_gedcom FROM `##other` WHERE o_type=? AND o_file=?")->execute(array('SUBN', $WT_TREE->getTreeId()))->fetchOne();
         if ($subn) {
             $filetext .= $subn . "\n";
         }
         $subm = Database::prepare("SELECT o_gedcom FROM `##other` WHERE o_type=? AND o_file=?")->execute(array('SUBM', $WT_TREE->getTreeId()))->fetchOne();
         if ($subm) {
             $filetext .= $subm . "\n";
         }
         if ($convert === "yes") {
             $filetext = str_replace("UTF-8", "ANSI", $filetext);
             $filetext = utf8_decode($filetext);
         }
         switch ($this->privatize_export) {
             case 'gedadmin':
                 $access_level = Auth::PRIV_NONE;
                 break;
             case 'user':
                 $access_level = Auth::PRIV_USER;
                 break;
             case 'visitor':
                 $access_level = Auth::PRIV_PRIVATE;
                 break;
             case 'none':
                 $access_level = Auth::PRIV_HIDE;
                 break;
         }
         foreach (array_keys($this->cart[$WT_TREE->getTreeId()]) as $xref) {
             $object = GedcomRecord::getInstance($xref, $WT_TREE);
             // The object may have been deleted since we added it to the cart....
             if ($object) {
                 $record = $object->privatizeGedcom($access_level);
                 // Remove links to objects that aren't in the cart
                 preg_match_all('/\\n1 ' . WT_REGEX_TAG . ' @(' . WT_REGEX_XREF . ')@(\\n[2-9].*)*/', $record, $matches, PREG_SET_ORDER);
                 foreach ($matches as $match) {
                     if (!array_key_exists($match[1], $this->cart[$WT_TREE->getTreeId()])) {
                         $record = str_replace($match[0], '', $record);
                     }
                 }
                 preg_match_all('/\\n2 ' . WT_REGEX_TAG . ' @(' . WT_REGEX_XREF . ')@(\\n[3-9].*)*/', $record, $matches, PREG_SET_ORDER);
                 foreach ($matches as $match) {
                     if (!array_key_exists($match[1], $this->cart[$WT_TREE->getTreeId()])) {
                         $record = str_replace($match[0], '', $record);
                     }
                 }
                 preg_match_all('/\\n3 ' . WT_REGEX_TAG . ' @(' . WT_REGEX_XREF . ')@(\\n[4-9].*)*/', $record, $matches, PREG_SET_ORDER);
                 foreach ($matches as $match) {
                     if (!array_key_exists($match[1], $this->cart[$WT_TREE->getTreeId()])) {
                         $record = str_replace($match[0], '', $record);
                     }
                 }
                 $record = FunctionsExport::convertMediaPath($record, $this->conv_path);
                 $savedRecord = $record;
                 // Save this for the "does this file exist" check
                 if ($convert === 'yes') {
                     $record = utf8_decode($record);
                 }
                 switch ($object::RECORD_TYPE) {
                     case 'INDI':
                         $filetext .= $record . "\n";
                         $filetext .= "1 SOUR @WEBTREES@\n";
                         $filetext .= "2 PAGE " . WT_BASE_URL . $object->getRawUrl() . "\n";
                         break;
                     case 'FAM':
                         $filetext .= $record . "\n";
                         $filetext .= "1 SOUR @WEBTREES@\n";
                         $filetext .= "2 PAGE " . WT_BASE_URL . $object->getRawUrl() . "\n";
                         break;
                     case 'SOUR':
                         $filetext .= $record . "\n";
                         $filetext .= "1 NOTE " . WT_BASE_URL . $object->getRawUrl() . "\n";
                         break;
                     default:
                         // This autoloads the PclZip library, so we can use its constants.
                         new PclZip('');
                         $ft = preg_match_all("/\n\\d FILE (.+)/", $savedRecord, $match, PREG_SET_ORDER);
                         $MEDIA_DIRECTORY = $WT_TREE->getPreference('MEDIA_DIRECTORY');
                         for ($k = 0; $k < $ft; $k++) {
                             // Skip external files and non-existant files
                             if (file_exists(WT_DATA_DIR . $MEDIA_DIRECTORY . $match[$k][1])) {
                                 $media[$mediacount] = array(\PCLZIP_ATT_FILE_NAME => WT_DATA_DIR . $MEDIA_DIRECTORY . $match[$k][1], \PCLZIP_ATT_FILE_NEW_FULL_NAME => $match[$k][1]);
                                 $mediacount++;
                             }
                         }
                         $filetext .= trim($record) . "\n";
                         break;
                 }
             }
         }
         if ($this->IncludeMedia === "yes") {
             $this->media_list = $media;
         } else {
             $this->media_list = array();
         }
         $filetext .= "0 @WEBTREES@ SOUR\n1 TITL " . WT_BASE_URL . "\n";
         if ($user_id = $WT_TREE->getPreference('CONTACT_EMAIL')) {
             $user = User::find($user_id);
             $filetext .= "1 AUTH " . $user->getRealName() . "\n";
         }
         $filetext .= "0 TRLR\n";
         //-- make sure the preferred line endings are used
         $filetext = preg_replace("/[\r\n]+/", WT_EOL, $filetext);
         $this->download_data = $filetext;
         $this->downloadClipping();
     }
     Session::put('cart', $this->cart);
 }