/** * 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); }
/** * Callback to render the 'family' entry type part of the 'Name' metabox. * Called from self::name() * * @access private * @since 0.8 * * @param cnEntry $entry An instance of the cnEntry object. * @param array $atts The metabox attributes array set in self::register(). Passed from self::name(). * * @return void */ public static function family($entry, $atts) { // Grab an instance of the Connections object. $instance = Connections_Directory(); $html = ''; $id = $entry->getId(); $ckey = $entry->getId() ? 'relative_select_entry_' . $id : 'relative_select_user_' . $instance->currentUser->getID(); if (FALSE !== ($cache = cnCache::get($ckey, 'transient'))) { echo $cache; return; } // Retrieve all the entries of the "individual" entry type that the user is permitted to view and is approved. $individuals = cnRetrieve::individuals(); // Get the core entry relations. $options = $instance->options->getDefaultFamilyRelationValues(); $html .= '<div class="cn-metabox" id="cn-metabox-section-family">'; // --> Start template for Family <-- \\ $html .= '<textarea id="cn-relation-template" style="display: none">'; $html .= cnHTML::select(array('class' => 'family-member-name', 'id' => 'family_member[::FIELD::][entry_id]', 'default' => __('Select Entry', 'connections'), 'options' => $individuals, 'enhanced' => TRUE, 'return' => TRUE)); $html .= cnHTML::select(array('class' => 'family-member-relation', 'id' => 'family_member[::FIELD::][relation]', 'default' => __('Select Relation', 'connections'), 'options' => $options, 'enhanced' => TRUE, 'return' => TRUE)); $html .= '</textarea>'; // --> End template for Family <-- \\ $html .= '<label for="family_name">' . __('Family Name', 'connections') . ':</label>'; $html .= '<input type="text" name="family_name" value="' . $entry->getFamilyName() . '" />'; $html .= '<ul id="cn-relations">'; if ($relations = $entry->getFamilyMembers()) { foreach ($relations as $relationData) { $token = str_replace('-', '', cnUtility::getUUID()); if (array_key_exists($relationData['entry_id'], $individuals)) { $html .= '<li id="relation-row-' . $token . '" class="cn-relation"><i class="fa fa-sort"></i> '; $html .= cnHTML::select(array('class' => 'family-member-name', 'id' => 'family_member[' . $token . '][entry_id]', 'default' => __('Select Entry', 'connections'), 'options' => $individuals, 'enhanced' => TRUE, 'return' => TRUE), $relationData['entry_id']); $html .= cnHTML::select(array('class' => 'family-member-relation', 'id' => 'family_member[' . $token . '][relation]', 'default' => __('Select Relation', 'connections'), 'options' => $options, 'enhanced' => TRUE, 'return' => TRUE), $relationData['relation']); $html .= '<a href="#" class="cn-remove cn-button button cn-button-warning" data-type="relation" data-token="' . $token . '">' . __('Remove', 'connections') . '</a>'; $html .= '</li>'; } } } $html .= '</ul>'; $html .= '<p class="add"><a id="add-relation" class="button">' . __('Add Relation', 'connections') . '</a></p>'; $html .= '</div>'; cnCache::set($ckey, $html, YEAR_IN_SECONDS, 'transient'); echo $html; }