/** * Constructor. * * @param string $url De url om te parsen */ public function __construct($url) { $info = parse_url($url); if ($info === false) { throw new Exception('Invalid url: "' . $url . '"'); } if (isset($info['query'])) { parse_str($info['query'], $info['query']); // Zet de query om naar een array } if (isset($info['path'])) { $info['path'] = rawurldecode($info['path']); // "%20" omzetten naar " " e.d. } \Sledgehammer\set_object_vars($this, $info); }
/** * Open or create the post and patch the properties and meta data. * * @param array $properties * @param array $meta * @param string $guidPrefix Example: WP_HOME.'/?p=' for posts and WP_HOME.'/?page_id=' for pages. */ public static function post($properties, $meta, $guidPrefix) { $repo = Repository::instance(); $conditions = ['AND', 'type' => $properties['type'], 'slug' => $properties['slug']]; $post = $repo->onePost($conditions, true); if ($post === null) { $post = $repo->createPost($properties); } else { \Sledgehammer\set_object_vars($post, $properties); } $post->setMeta($meta); $repo->savePost($post); if (!$post->guid && $guidPrefix !== false) { $post->guid = $guidPrefix . $post->id; $repo->savePost($post, ['ignore_relations' => true]); } return $post; }