本文整理汇总了PHP中Fisharebest\Webtrees\Tree::getNewXref方法的典型用法代码示例。如果您正苦于以下问题:PHP Tree::getNewXref方法的具体用法?PHP Tree::getNewXref怎么用?PHP Tree::getNewXref使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fisharebest\Webtrees\Tree
的用法示例。
在下文中一共展示了Tree::getNewXref方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createMediaObject
/**
* Create a new media object, from inline media data.
*
* @param int $level
* @param string $gedrec
* @param Tree $tree
*
* @return string
*/
public static function createMediaObject($level, $gedrec, Tree $tree)
{
if (preg_match('/\\n\\d FILE (.+)/', $gedrec, $file_match)) {
$file = $file_match[1];
} else {
$file = '';
}
if (preg_match('/\\n\\d TITL (.+)/', $gedrec, $file_match)) {
$titl = $file_match[1];
} else {
$titl = '';
}
// Have we already created a media object with the same title/filename?
$xref = Database::prepare("SELECT m_id FROM `##media` WHERE m_filename = ? AND m_titl = ? AND m_file = ?")->execute(array($file, $titl, $tree->getTreeId()))->fetchOne();
if (!$xref) {
$xref = $tree->getNewXref('OBJE');
// renumber the lines
$gedrec = preg_replace_callback('/\\n(\\d+)/', function ($m) use($level) {
return "\n" . ($m[1] - $level);
}, $gedrec);
// convert to an object
$gedrec = str_replace("\n0 OBJE\n", '0 @' . $xref . "@ OBJE\n", $gedrec);
// Fix Legacy GEDCOMS
$gedrec = preg_replace('/\\n1 FORM (.+)\\n1 FILE (.+)\\n1 TITL (.+)/', "\n1 FILE \$2\n2 FORM \$1\n2 TITL \$3", $gedrec);
// Fix FTB GEDCOMS
$gedrec = preg_replace('/\\n1 FORM (.+)\\n1 TITL (.+)\\n1 FILE (.+)/', "\n1 FILE \$3\n2 FORM \$1\n2 TITL \$2", $gedrec);
// Create new record
$record = new Media($xref, $gedrec, null, $tree);
Database::prepare("INSERT INTO `##media` (m_id, m_ext, m_type, m_titl, m_filename, m_file, m_gedcom) VALUES (?, ?, ?, ?, ?, ?, ?)")->execute(array($xref, $record->extension(), $record->getMediaType(), $record->getTitle(), $record->getFilename(), $tree->getTreeId(), $gedrec));
}
return "\n" . $level . ' OBJE @' . $xref . '@';
}