/** * Outputs entry data JSON encoded in HTML data attribute. * This is an action called by the `cn_action_entry_after` hook. * * @access public * @since 0.8 * * @param array $atts Shortcode $atts passed by the `cn_action_entry_after` action hook. * @param cnEntry $entry An instance the the cnEntry object. * * @return string */ public static function JSON($atts, $entry) { $defaults = array('tag' => 'div', 'before' => '', 'after' => '', 'return' => FALSE, 'show_addresses' => TRUE, 'show_phone_numbers' => TRUE, 'show_email' => TRUE, 'show_im' => TRUE, 'show_social_media' => TRUE, 'show_links' => TRUE, 'show_dates' => TRUE, 'show_bio' => TRUE, 'show_notes' => TRUE); $atts = wp_parse_args($atts, $defaults); $data = array('type' => $entry->getEntryType(), 'id' => $entry->getId(), 'ruid' => $entry->getRuid(), 'slug' => $entry->getSlug(), 'name' => array('full' => $entry->getName($atts), 'prefix' => $entry->getHonorificPrefix(), 'first' => $entry->getFirstName(), 'middle' => $entry->getMiddleName(), 'last' => $entry->getLastName(), 'suffix' => $entry->getHonorificSuffix()), 'title' => $entry->getTitle(), 'organization' => $entry->getOrganization(), 'department' => $entry->getDepartment(), 'contact_name' => array('full' => $entry->getContactName(), 'first' => $entry->getContactFirstName(), 'last' => $entry->getContactLastName()), 'family_name' => $entry->getFamilyName(), 'family_members' => $entry->getFamilyMembers(), 'categories' => $entry->getCategory(), 'meta' => $entry->getMeta($atts)); if ($atts['show_addresses']) { $data['addresses'] = $entry->getAddresses($atts); } if ($atts['show_phone_numbers']) { $data['phone_numbers'] = $entry->getPhoneNumbers($atts); } if ($atts['show_email']) { $data['email_addresses'] = $entry->getEmailAddresses($atts); } if ($atts['show_im']) { $data['im'] = $entry->getIm($atts); } if ($atts['show_social_media']) { $data['social_media'] = $entry->getSocialMedia($atts); } if ($atts['show_links']) { $data['links'] = $entry->getLinks($atts); } if ($atts['show_dates']) { $data['dates'] = $entry->getDates($atts); } if ($atts['show_bio']) { $data['bio'] = $entry->getBio(); } if ($atts['show_notes']) { $data['notes'] = $entry->getNotes(); } $out = sprintf('<%1$s class="cn-entry-data-json" data-entry-data-json=\'%2$s\'></%1$s>', $atts['tag'], htmlspecialchars(json_encode($data), ENT_QUOTES, 'UTF-8')); $out = (empty($atts['before']) ? '' : $atts['before']) . $out . (empty($atts['after']) ? '' : $atts['after']) . PHP_EOL; return self::echoOrReturn($atts['return'], $out); }
/** * Prepare a single entry output for response. * * @param cnEntry $entry Post object. * @param WP_REST_Request $request Request object. * * @return WP_REST_Response $data */ public function prepare_item_for_response($entry, $request) { $data = array(); //$entry->directoryHome( // array( // 'page_id' => $homeID, // 'force_home' => $forceHome, // ) //); $data['id'] = $entry->getId(); $data['type'] = $entry->getEntryType(); $data['slug'] = $entry->getSlug(); $data['name'] = array('raw' => $entry->getName(array(), 'raw'), 'rendered' => $entry->getName()); $data['honorific_prefix'] = array('raw' => $entry->getHonorificPrefix('raw'), 'rendered' => $entry->getHonorificPrefix()); $data['given_name'] = array('raw' => $entry->getFirstName('raw'), 'rendered' => $entry->getFirstName()); $data['additional_name'] = array('raw' => $entry->getMiddleName('raw'), 'rendered' => $entry->getMiddleName()); $data['family_name'] = array('raw' => $entry->getLastName('raw'), 'rendered' => $entry->getLastName()); $data['honorific_suffix'] = array('raw' => $entry->getHonorificSuffix('raw'), 'rendered' => $entry->getHonorificSuffix()); $data['job_title'] = array('raw' => $entry->getTitle('raw'), 'rendered' => $entry->getTitle()); $data['org'] = array('organization_name' => array('raw' => $entry->getDepartment('raw'), 'rendered' => $entry->getDepartment()), 'organization_unit' => array('raw' => $entry->getOrganization('raw'), 'rendered' => $entry->getOrganization())); $data['contact'] = array('given_name' => array('raw' => $entry->getContactFirstName('raw'), 'rendered' => $entry->getContactFirstName()), 'family_name' => array('raw' => $entry->getContactLastName('raw'), 'rendered' => $entry->getContactLastName())); $data = $this->prepare_address_for_response($entry, $request, $data); // Wrap the data in a response object. $response = rest_ensure_response($data); return $response; }