/** * Serialize an entity post. * * @param array $entity The entity post or the entity post id. * * @return array mixed The entity data array. */ function wl_serialize_entity($entity) { $entity = is_numeric($entity) ? get_post($entity) : $entity; $type = wl_entity_type_taxonomy_get_type($entity->ID); $images = wl_get_image_urls($entity->ID); return array('id' => wl_get_entity_uri($entity->ID), 'label' => $entity->post_title, 'description' => wp_strip_all_tags($entity->post_content), 'sameAs' => wl_schema_get_value($entity->ID, 'sameAs'), 'mainType' => str_replace('wl-', '', $type['css_class']), 'types' => wl_get_entity_rdf_types($entity->ID), 'images' => $images); }
/** * Optimize and convert retrieved content to JSON. * * @used-by wl_shortcode_chord_ajax * * @param $data * @return mixed|string|void */ function wl_shortcode_chord_get_graph($data) { // Refactor the entities array in order to provide entities relevant data (uri, url, label, type, css_class). array_walk($data['entities'], function (&$item) { $post = get_post($item); // Skip non-existing posts. if (is_null($post)) { wl_write_log("wl_shortcode_chord_get_graph : post not found [ post id :: {$item} ]"); return $item; } // Get the entity taxonomy bound to this post (if there's no taxonomy, no stylesheet will be set). $term = wl_entity_type_taxonomy_get_type($item); wl_write_log("wl_shortcode_chord_get_graph [ post id :: {$post->ID} ][ term :: " . var_export($term, true) . " ]"); $entity = array('uri' => wl_get_entity_uri($item), 'url' => get_permalink($item), 'label' => $post->post_title, 'type' => $post->post_type, 'thumbnails' => wl_get_image_urls($post->ID), 'css_class' => isset($term['css_class']) ? $term['css_class'] : ''); $item = $entity; }); // Refactor the relations. array_walk($data['relations'], function (&$item) { $relation = array('s' => wl_get_entity_uri($item[0]), 'o' => wl_get_entity_uri($item[1])); $item = $relation; }); // Return the JSON representation. return $data; }
/** * Get a SPARQL fragment with schema:image predicates. * * @param string $uri The URI subject of the statements. * @param int $post_id The post ID. * * @return string The SPARQL fragment. */ function wl_get_sparql_images($uri, $post_id) { $sparql = ''; // Get the escaped URI. $uri_e = esc_html($uri); // Add SPARQL stmts to write the schema:image. $image_urls = wl_get_image_urls($post_id); foreach ($image_urls as $image_url) { $image_url_esc = wl_sparql_escape_uri($image_url); $sparql .= " <{$uri_e}> schema:image <{$image_url_esc}> . \n"; } return $sparql; }