コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 /**
  * The core method that processes the content according to the
  * entry part that the shortcode should add to the content.
  *
  * @access private
  * @since 0.8
  * @param  array  $atts    The shortcode attributes array.
  * @param  string $content The content captured between an open/close shortcode.
  * @param  string $tag     The shortcode tag.
  *
  * @return string          The processed content.
  */
 public function shortcode($atts, $content = '', $tag = 'cn_entry')
 {
     // Bail if self::$entry is not set because an instance of the cnEntry object is required.
     if (is_null($this->entry)) {
         return '';
     }
     $defaults = array('part' => '');
     // Normally we'd use shortcode_atts, but that strips keys from $atts that do not exist in $defaults.
     // Since $atts can contain various option for the different callback methods, we'll use wp_parse_args()
     // which leaves keys that do not exist in $atts.
     $atts = wp_parse_args($atts, $defaults);
     // All the core methods in the cnEntry_HTML class echo by default, make sure to return instead.
     $atts['return'] = TRUE;
     switch ($atts['part']) {
         case 'name':
             $out = $this->entry->getName($atts);
             break;
         case 'title':
             $out = $this->entry->getTitle();
             break;
         case 'organization':
             $out = $this->entry->getOrganization();
             break;
         case 'department':
             $out = $this->entry->getDepartment();
             break;
         case 'contact':
             $out = $this->entry->getContactName($atts);
             break;
         case 'family_relationships':
             $out = $this->entry->getFamilyMembers();
             break;
         case 'addresses':
             add_shortcode('cn_address', array($this, 'address'));
             $out = has_shortcode($content, 'cn_address') ? do_shortcode($content) : '';
             remove_shortcode('cn_address');
             break;
         case 'phone_numbers':
             add_shortcode('cn_phone', array($this, 'phone'));
             $out = has_shortcode($content, 'cn_phone') ? do_shortcode($content) : '';
             remove_shortcode('cn_phone');
             break;
         case 'email':
             add_shortcode('cn_email', array($this, 'email'));
             $out = has_shortcode($content, 'cn_email') ? do_shortcode($content) : '';
             remove_shortcode('cn_email');
             break;
         case 'im':
             add_shortcode('cn_im', array($this, 'im'));
             $out = has_shortcode($content, 'cn_im') ? do_shortcode($content) : '';
             remove_shortcode('cn_im');
             break;
         case 'social_networks':
             add_shortcode('cn_social_network', array($this, 'socialNetwork'));
             $out = has_shortcode($content, 'cn_social_network') ? do_shortcode($content) : '';
             remove_shortcode('cn_social_network');
             break;
         case 'links':
             add_shortcode('cn_link', array($this, 'link'));
             $out = has_shortcode($content, 'cn_link') ? do_shortcode($content) : '';
             remove_shortcode('cn_link');
             break;
         case 'dates':
             add_shortcode('cn_date', array($this, 'date'));
             $out = has_shortcode($content, 'cn_date') ? do_shortcode($content) : '';
             remove_shortcode('cn_date');
             break;
         case 'bio':
             $out = $this->entry->getBio();
             break;
         case 'notes':
             $out = $this->entry->getNotes();
             break;
         default:
             // Custom shortcodes can be applied to the content using this filter.
             $out = apply_filters('cn_entry_part-' . $atts['part'], $content, $atts, $this->entry);
             break;
     }
     return $out;
 }