/** * Load the JSON-LD at the specified path (the path is appended to the *base_uri*). If the path is empty or null * it is loaded from the query variables (via WordPress). * * @since 3.0.0 * * @uses wl_configuration_get_redlink_dataset_uri() to get the default dataset URI. * @uses wl_jsonld_load_remote() to load a remote JSON-LD file. * * @param string $path The entity path. */ function load($path = null) { // If the path is empty, load the resource from the query string variable. if (empty($path)) { $path = get_query_var(WL_ENTITY_VIEW_ENTITY_ID_QUERY_VAR); } // If a base URI has been set, append the path, otherwise use the path. $this->url = !empty($this->base_uri) ? $this->base_uri . ('/' !== substr($this->base_uri, -1, 1) ? '/' : '') . $path : $path; $this->graph = wl_jsonld_load_remote($this->url . $this->suffix); $this->json_path = new JSONPath($this->graph); }
/** * @param array $collection * * @return array */ public function filter($collection) { $return = []; foreach ($collection as $item) { foreach ($item as $key => $value) { if ($this->value === $key) { if ('.jpg' === strtolower(substr($value, -4)) || '.gif' === strtolower(substr($value, -4))) { continue; } $return[] = array(wl_jsonld_load_remote($value . '.json')); } } } return $return; }
/** * Get a property value using the specified name, language and graph. The property name can be a concatenated tree of * keys, e.g. schema:location>schema:latitude. * * @param object $graph The graph. * @param string $name The property tree. * @param null|string $language If provided, a two-characters language code. * @param string $suffix The suffix for remote requests (empty if not provided). * @return null|string The value or null if not found. */ function wl_jsonld_get_property($graph, $name, $language = null, $suffix = '', $index = 0) { $keys = explode('>', html_entity_decode($name)); $value = null; foreach ($keys as $key) { if (null !== $value) { $graph = wl_jsonld_load_remote($value . $suffix); } $key_exp = wl_prefixes_expand($key); $value = wl_jsonld_get_property_value($graph, $key_exp, $language, $index); } return $value; }