parse($fileContent); return $opml; } /** * * @param Opml $opml object * @param boolean $freezeDateModified update (or not) the dateModified entry - used for tests only * @return string OPML valid string */ public static function format(Opml $opml, bool $freezeDateModified = false) : string { $owner = ''; if ($opml->ownerName != '') { $owner .= ''.htmlspecialchars($opml->ownerName).''."\n"; } if ($opml->ownerEmail != '') { $owner .= ''.htmlspecialchars($opml->ownerEmail).''."\n"; } if ($opml->ownerId != '') { $owner .= ''.htmlspecialchars($opml->ownerId).''."\n"; } $entries = ''; foreach ($opml->entries as $person) { $entries .= sprintf( "\t" . '', htmlspecialchars($person['name'], ENT_QUOTES), htmlspecialchars($person['website'], ENT_QUOTES), htmlspecialchars($person['feed'], ENT_QUOTES), htmlspecialchars($person['isDown'] ?? '', ENT_QUOTES) ) . "\n"; } $template = << %s %s %s %s http://opml.org/spec2.opml %s XML; return sprintf( $template, htmlspecialchars($opml->getTitle()), $opml->dateCreated, $freezeDateModified ? $opml->dateModified : date_format(date_create('now', new DateTimeZone('UTC')), DateTimeInterface::ATOM), $owner, $entries ); } /** * @param Opml $opml * @param string $file */ public static function save(Opml $opml, string $file) : int|bool { return file_put_contents($file, self::format($opml)); } public static function backup(string $file) : void { copy($file, $file.'.bak'); } }