/** * Return record coverage data from the NeatlineFeatures plugin. * * @param $record NeatlineRecord The record to get the feature for. * @return string|null */ function nl_getNeatlineFeaturesWkt($record) { // Halt if Features is not present. if (!plugin_is_active('NeatlineFeatures')) { return; } $db = get_db(); // Get raw coverage. $result = $db->fetchOne("SELECT geo FROM `{$db->prefix}neatline_features`\n WHERE is_map=1 AND item_id=?;", $record->item_id); if ($result) { // If KML, convert to WKT. if (strpos($result, '<kml') !== false) { $result = nl_extractWkt(trim($result)); } else { $result = 'GEOMETRYCOLLECTION(' . implode(',', explode('|', $result)) . ')'; } } return $result; }
/** * Import coverage from Neatline Features, if it's installed, and set the * `is_coverage` flag. */ public function compileCoverage() { // Get parent item. $item = $this->getItem(); // Only try to import coverage values if (a) a parent item is defined // and (b) the local coverage value is currently empty (this prevents // modified coverages from being overwritten on save). if ($item && !$this->coverage) { if (plugin_is_active('NeatlineFeatures')) { // Try to import a value from Neatline Features. $wkt = nl_getNeatlineFeaturesWkt($this); if (is_string($wkt)) { $this->coverage = $wkt; } } if (!$this->coverage) { // If a coverage wasn't gethered from Features (either because // it isn't installed, or there isn't a Features-managed value // for the item), just look for a vanilla DC "Coverage" value. try { $coverage = metadata($item, array('Dublin Core', 'Coverage')); $this->coverage = nl_extractWkt($coverage); } catch (Exception $e) { } } } // Track whether the record has a coverage. $this->is_coverage = $this->coverage ? 1 : 0; }