/** * Prepare a single post 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) { //$entry->directoryHome( // array( // 'page_id' => $homeID, // 'force_home' => $forceHome, // ) //); $addresses = $entry->getAddresses(); /** * NOTES: * * - The `coordinates` index array value must not have indexes otherwise it'll be converted to an object * which is invalid geoJSON. * - The `coordinates` must but cast as floats otherwise they'll be converted to strings. * - The `coordinates` must be longitude, latitude order per the geoJSON spec. * * @todo Loop thu each address within an entry so a geoJSON `feature` is added for each address the entry may have. * @todo The entry only needs to be added to $entries if it has at least one address and those address has both a latitude and longitude. * * @link http://connections-pro.com/support/topic/map-view/#post-319981 */ if ((!isset($addresses[0]->latitude) || empty($addresses[0]->latitude)) && (!isset($addresses[0]->longitude) || empty($addresses[0]->longitude))) { //return; } switch ($entry->getEntryType()) { case 'individual': $type = 'Person'; break; case 'organization': $type = 'Organization'; break; case 'family': $type = 'Family'; break; default: $type = NULL; } $data = array('type' => 'Feature', 'geometry' => array('type' => 'Point', 'coordinates' => array((double) $addresses[0]->longitude, (double) $addresses[0]->latitude)), 'properties' => array('id' => $entry->getId(), 'type' => $type, 'slug' => $entry->getSlug(), 'permalink' => $entry->getPermalink(), 'name' => $entry->getName(), 'title' => $entry->getTitle(), 'department' => $entry->getDepartment() ? array('@type' => 'Organization', 'name' => $entry->getDepartment()) : NULL, 'organization' => $entry->getOrganization() ? array('@type' => 'Organization', 'name' => $entry->getOrganization()) : NULL, 'bio' => $entry->getBio(), 'notes' => $entry->getNotes())); // Wrap the data in a response object. $response = rest_ensure_response($data); return $response; }
/** * Process the content adding the entry dates details in place of the shortcode. * * @access private * @since 0.8 * @param array $atts The shortcode attributes array. * @param string $content The content captured between an open/close shortcode tag. * @param string $tag The shortcode tag. * * @return string The processed content. */ public function date($atts, $content = '', $tag = 'cn_date') { $out = ''; $defaults = array('preferred' => FALSE, 'type' => NULL); $atts = shortcode_atts($defaults, $atts, $tag); $search = array('%type%', '%date%'); $dates = $this->entry->getDates($atts); foreach ($dates as $date) { $replace = array('type' => $date->name, 'date' => $date->date); $out .= str_ireplace($search, $replace, $content); } return $out; }
/** * Prepare a single post 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, // ) //); switch ($entry->getEntryType()) { case 'individual': $data['@type'] = 'Person'; $data['honorificPrefix'] = $entry->getHonorificPrefix(); $data['givenName'] = $entry->getFirstName(); $data['additionalName'] = $entry->getMiddleName(); $data['familyName'] = $entry->getLastName(); $data['honorificSuffix'] = $entry->getHonorificSuffix(); break; case 'organization': $data['@type'] = 'Organization'; $data['name'] = $entry->getName(); break; case 'family': /** * Unfortunately there is no "Family" type available. * Use "Person" as the type with the "additionalType" set as "Family". Valid? Unsure. * * NOTES: Perhaps if "Family" is merged in from @link http://historical-data.org/ it can be used. */ $data['@type'] = 'Person'; $data['additionalType'] = 'Family'; $data['name'] = $entry->getName(); break; default: /** @todo add filter for custom entry types */ } /** * NOTES: * * - Social network links should use the sameAs property as an array. */ // Wrap the data in a response object. $response = rest_ensure_response($data); return $response; }
/** * Sort the entries by the user set attributes. * * $object -- syntax is field|SORT_ASC(SORT_DESC)|SORT_REGULAR(SORT_NUMERIC)(SORT_STRING) * * example -- 'state|SORT_ASC|SORT_STRING, last_name|SORT_DESC|SORT_REGULAR * * * Available order_by fields: * id * date_added * date_modified * first_name * last_name * organization * department * city * state * zipcode * country * birthday * anniversary * * Order Flags: * SORT_ACS * SORT_DESC * SPECIFIED** * RANDOM** * * Sort Types: * SORT_REGULAR * SORT_NUMERIC * SORT_STRING * * **NOTE: The SPECIFIED and RANDOM Order Flags can only be used * with the id field. The SPECIFIED flag must be used in conjunction * with $suppliedIDs which can be either a comma delimited sting or * an indexed array of entry IDs. If this is set, other sort fields/flags * are ignored. * * @access private * @since unknown * @deprecated since unknown * * @param array $entries A reference to an array of object $entries * @param string $orderBy * @param mixed array|string|NULL [optional] * * @return array of objects */ private function orderBy(&$entries, $orderBy, $suppliedIDs = NULL) { if (empty($entries) || empty($orderBy)) { return $entries; } $orderFields = array('id', 'date_added', 'date_modified', 'first_name', 'last_name', 'title', 'organization', 'department', 'city', 'state', 'zipcode', 'country', 'birthday', 'anniversary'); $sortFlags = array('SPECIFIED' => 'SPECIFIED', 'RANDOM' => 'RANDOM', 'SORT_ASC' => SORT_ASC, 'SORT_DESC' => SORT_DESC, 'SORT_REGULAR' => SORT_REGULAR, 'SORT_NUMERIC' => SORT_NUMERIC, 'SORT_STRING' => SORT_STRING); $specifiedIDOrder = FALSE; // Build an array of each field to sort by and attributes. $sortFields = explode(',', $orderBy); // For each field the sort order can be defined as well as the sort type foreach ($sortFields as $sortField) { $sortAtts[] = explode('|', $sortField); } /* * Dynamically build the variables that will be used for the array_multisort. * * The field type should be the first item in the array if the user * constructed the shortcode attribute correctly. */ foreach ($sortAtts as $field) { // Trim any spaces the user might have added to the shortcode attribute. $field[0] = strtolower(trim($field[0])); // If a user included a sort field that is invalid/mis-spelled it is skipped since it can not be used. if (!in_array($field[0], $orderFields)) { continue; } // The dynamic variable are being created and populated. foreach ($entries as $key => $row) { $entry = new cnEntry($row); switch ($field[0]) { case 'id': ${$field[0]}[$key] = $entry->getId(); break; case 'date_added': ${$field[0]}[$key] = $entry->getDateAdded('U'); break; case 'date_modified': ${$field[0]}[$key] = $entry->getUnixTimeStamp(); break; case 'first_name': ${$field[0]}[$key] = $entry->getFirstName(); break; case 'last_name': ${$field[0]}[$key] = $entry->getLastName(); break; case 'title': ${$field[0]}[$key] = $entry->getTitle(); break; case 'organization': ${$field[0]}[$key] = $entry->getOrganization(); break; case 'department': ${$field[0]}[$key] = $entry->getDepartment(); break; case $field[0] === 'city' || $field[0] === 'state' || $field[0] === 'zipcode' || $field[0] === 'country': if ($entry->getAddresses()) { $addresses = $entry->getAddresses(); foreach ($addresses as $address) { //${$field[0]}[$key] = $address[$field[0]]; ${$field[0]}[$key] = $address->{$field}[0]; // Only set the data from the first address. break; } } else { ${$field[0]}[$key] = NULL; } break; case 'birthday': ${$field[0]}[$key] = strtotime($entry->getBirthday()); break; case 'anniversary': ${$field[0]}[$key] = strtotime($entry->getAnniversary()); break; } } // The sorting order to be determined by a lowercase copy of the original array. ${$field}[0] = array_map('strtolower', ${$field}[0]); // The arrays to be sorted must be passed by reference or it won't work. $sortParams[] =& ${$field}[0]; // Add the flag and sort type to the sort parameters if they were supplied in the shortcode attribute. foreach ($field as $key => $flag) { // Trim any spaces the user might have added and change the string to uppercase.. $flag = strtoupper(trim($flag)); // If a user included a sort tag that is invalid/mis-spelled it is skipped since it can not be used. if (!array_key_exists($flag, $sortFlags)) { continue; } /* * If the order is specified set the variable to true and continue * because SPECIFIED should not be added to the $sortParams array * as that would be an invalid argument for the array multisort. */ if ($flag === 'SPECIFIED' || $flag === 'RANDOM') { $idOrder = $flag; continue; } // Must be pass as reference or the multisort will fail. $sortParams[] =& $sortFlags[$flag]; unset($flag); } } /* * */ if (isset($id) && isset($idOrder)) { switch ($idOrder) { case 'SPECIFIED': $sortedEntries = array(); /* * Convert the supplied IDs value to an array if it is not. */ if (!is_array($suppliedIDs) && !empty($suppliedIDs)) { // Trim the space characters if present. $suppliedIDs = str_replace(' ', '', $suppliedIDs); // Convert to array. $suppliedIDs = explode(',', $suppliedIDs); } foreach ($suppliedIDs as $entryID) { $sortedEntries[] = $entries[array_search($entryID, $id)]; } $entries = $sortedEntries; return $entries; break; case 'RANDOM': shuffle($entries); return $entries; break; } } /*print_r($sortParams); print_r($first_name); print_r($last_name); print_r($state); print_r($zipcode); print_r($organization); print_r($department); print_r($birthday); print_r($anniversary);*/ // Must be pass as reference or the multisort will fail. $sortParams[] =& $entries; //$sortParams = array(&$state, SORT_ASC, SORT_REGULAR, &$zipcode, SORT_DESC, SORT_STRING, &$entries); call_user_func_array('array_multisort', $sortParams); return $entries; }
/** * Callback to render the "Custom Fields" metabox. * * @access private * @since 0.8 * @param cnEntry $entry An instance of the cnEntry object. * @param array $metabox The metabox attributes array set in self::register(). * @return void */ public static function meta($entry, $metabox) { /** @var wpdb $wpdb */ global $wpdb; $results = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value, meta_id, entry_id\n\t\t\tFROM " . CN_ENTRY_TABLE_META . " WHERE entry_id = %d\n\t\t\tORDER BY meta_key,meta_id", $entry->getId()), ARRAY_A); $metabox = $metabox['args']; $keys = cnMeta::key('entry'); $options = array(); // Toss the meta that is saved as part of a custom field. if (!empty($results)) { foreach ($results as $metaID => $meta) { if (cnMeta::isPrivate($meta['meta_key'])) { unset($results[$metaID]); } } } // Build the meta key select drop down options. if (!empty($keys)) { $options = array_combine(array_map('esc_attr', array_keys($keys)), array_map('esc_html', $keys)); array_walk($options, create_function('&$key', '$key = "<option value=\\"$key\\">$key</option>";')); } array_unshift($options, '<option value="-1">— ' . __('Select', 'connections') . ' —</option>'); $options = implode($options, PHP_EOL); // echo '<input type="hidden" name="wp_meta_box_nonce" value="', wp_create_nonce( basename(__FILE__) ), '" />'; echo '<div class="cn-metabox-section" id="meta-fields">'; ?> <table id="list-table" style="<?php echo empty($results) ? 'display: none;' : 'display: table;'; ?> "> <thead> <tr> <th class="left"><?php _e('Name', 'connections'); ?> </th> <th><?php _e('Value', 'connections'); ?> </th> </tr> </thead> <tbody id="the-list"> <?php if (!empty($results)) { foreach ($results as $metaID => $meta) { // Class added to alternate tr rows for CSS styling. $alternate = !isset($alternate) || $alternate == '' ? 'alternate' : ''; ?> <tr id="meta-<?php echo $meta['meta_id']; ?> " class="<?php echo $alternate; ?> "> <td class="left"> <label class="screen-reader-text" for='meta[<?php echo $meta['meta_id']; ?> ][key]'><?php _e('Key', 'connections'); ?> </label> <input name='meta[<?php echo $meta['meta_id']; ?> ][key]' id='meta[<?php echo $meta['meta_id']; ?> ][key]' type="text" size="20" value="<?php echo esc_textarea($meta['meta_key']); ?> " /> <div class="submit"> <input type="submit" name="deletemeta[<?php echo $meta['meta_id']; ?> ]" id="deletemeta[<?php echo $meta['meta_id']; ?> ]" class="button deletemeta button-small" value="<?php _e('Delete', 'connections'); ?> " /> </div> </td> <td> <label class="screen-reader-text" for='meta[<?php echo $meta['meta_id']; ?> ][value]'><?php _e('Value', 'connections'); ?> </label> <textarea name='meta[<?php echo $meta['meta_id']; ?> ][value]' id='meta[<?php echo $meta['meta_id']; ?> ][value]' rows="2" cols="30"><?php echo esc_textarea(cnFormatting::maybeJSONencode($meta['meta_value'])); ?> </textarea> </td> </tr> <?php } ?> <?php } ?> <!-- This is the row that will be cloned via JS when adding a new Custom Field. --> <tr style="display: none;"> <td class="left"> <label class="screen-reader-text" for='newmeta[0][key]'><?php _e('Key', 'connections'); ?> </label> <input name='newmeta[0][key]' id='newmeta[0][key]' type="text" size="20" value=""/> <div class="submit"> <input type="submit" name="deletemeta[0]" id="deletemeta[0]" class="button deletemeta button-small" value="<?php _e('Delete', 'connections'); ?> " /> <!-- <input type="submit" name="newmeta-0-submit" id="newmeta-0-submit" class="button updatemeta button-small" value="Update" /> --> </div> <!-- <input type="hidden" id="_ajax_nonce" name="_ajax_nonce" value="0db0025bba" /> --> </td> <td> <label class="screen-reader-text" for='newmeta[0][value]'><?php _e('Value', 'connections'); ?> </label> <textarea name='newmeta[0][value]' id='newmeta[0][value]' rows="2" cols="30"></textarea> </td> </tr> </tbody> </table> <p><strong><?php _e('Add New Custom Field:', 'connections'); ?> </strong></p> <table id="newmeta"> <thead> <tr> <th class="left"><label for="metakeyselect"><?php _e('Name', 'connections'); ?> </label></th> <th><label for="metavalue"><?php _e('Value', 'connections'); ?> </label></th> </tr> </thead> <tbody> <tr> <td id="newmetaleft" class="left"> <select id="metakeyselect" name="metakeyselect"> <?php echo $options; ?> </select> <input class="hide-if-js" type=text id="metakeyinput" name="newmeta[99][key]" value=""/> <a href="#postcustomstuff" class="postcustomstuff hide-if-no-js"> <span id="enternew"><?php _e('Enter New', 'connections'); ?> </span> <span id="cancelnew" class="hidden"><?php _e('Cancel', 'connections'); ?> </span></a> </td> <td> <textarea id="metavalue" name="newmeta[99][value]" rows="2" cols="25"></textarea> </td> </tr> </tbody> <tfoot> <td colspan="2"> <div class="submit"> <input type="submit" name="addmeta" id="newmeta-submit" class="button" value="<?php _e('Add Custom Field', 'connections'); ?> " /> </div> <!-- <input type="hidden" id="_ajax_nonce-add-meta" name="_ajax_nonce-add-meta" value="a7f70d2878" /> --> </td> </tfoot> </table> <?php if (isset($metabox['desc']) && !empty($metabox['desc'])) { printf('<p>%1$s</p>', esc_html($metabox['desc'])); } echo '</div>'; }
function connectionsShowViewPage($action = NULL) { // Grab an instance of the Connections object. $instance = Connections_Directory(); $queryVars = array(); echo '<div class="wrap">'; switch ($action) { case 'add_entry': echo '<h2>Connections : ', __('Add Entry', 'connections'), '</h2>'; /* * Check whether current user can add an entry. */ if (current_user_can('connections_add_entry') || current_user_can('connections_add_entry_moderated')) { $form = new cnFormObjects(); $entry = new cnOutput(); $attr = array('id' => 'cn-form', 'method' => 'post', 'enctype' => 'multipart/form-data'); $form->open($attr); $field = array('id' => 'metabox-name', 'title' => __('Name', 'connections'), 'context' => 'normal', 'priority' => 'high', 'callback' => array('cnEntryMetabox', 'name')); cnMetabox_Render::add($instance->pageHook->add, $field); echo '<div id="poststuff">'; echo '<div id="post-body" class="metabox-holder columns-' . (1 == get_current_screen()->get_columns() ? '1' : '2') . '">'; wp_nonce_field('cn-manage-metaboxes'); wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', FALSE); wp_nonce_field('meta-box-order', 'meta-box-order-nonce', FALSE); $form->tokenField('add_entry', FALSE, '_cn_wpnonce', FALSE); do_action('cn_admin_form_add_entry_before', $entry, $form); echo '<div id="postbox-container-1" class="postbox-container">'; echo '<div id="side-sortables" class="meta-box-sortables ui-sortable">'; do_meta_boxes($instance->pageHook->add, 'side', $entry); echo '</div> <!-- #side-sortables -->'; echo '</div> <!-- #postbox-container-1 -->'; echo '<div id="postbox-container-2" class="postbox-container">'; echo '<div id="normal-sortables" class="meta-box-sortables ui-sortable">'; do_meta_boxes($instance->pageHook->add, 'normal', $entry); echo '</div> <!-- #normal-sortables -->'; echo '</div> <!-- #postbox-container-2 -->'; do_action('cn_admin_form_add_entry_after', $entry, $form); echo '</div> <!-- #post-body -->'; echo '<br class="clear">'; echo '</div> <!-- #poststuff -->'; $form->close(); unset($entry); } else { cnMessage::render('error', __('You are not authorized to add entries. Please contact the admin if you received this message in error.', 'connections')); } break; case 'copy_entry': echo '<div class="wrap">'; echo '<h2>Connections : ', __('Copy Entry', 'connections'), '</h2>'; /* * Check whether current user can add an entry. */ if (current_user_can('connections_add_entry') || current_user_can('connections_add_entry_moderated')) { $id = esc_attr($_GET['id']); check_admin_referer('entry_copy_' . $id); $form = new cnFormObjects(); $entry = new cnOutput($instance->retrieve->entry($id)); $attr = array('id' => 'cn-form', 'method' => 'post', 'enctype' => 'multipart/form-data'); $form->open($attr); $field = array('id' => 'metabox-name', 'title' => __('Name', 'connections'), 'context' => 'normal', 'priority' => 'high', 'callback' => array('cnEntryMetabox', 'name')); cnMetabox_Render::add($instance->pageHook->manage, $field); echo '<div id="poststuff">'; echo '<div id="post-body" class="metabox-holder columns-' . (1 == get_current_screen()->get_columns() ? '1' : '2') . '">'; wp_nonce_field('cn-manage-metaboxes'); wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', FALSE); wp_nonce_field('meta-box-order', 'meta-box-order-nonce', FALSE); $form->tokenField('add_entry', FALSE, '_cn_wpnonce', FALSE); do_action('cn_admin_form_copy_entry_before', $entry, $form); echo '<div id="postbox-container-1" class="postbox-container">'; echo '<div id="side-sortables" class="meta-box-sortables ui-sortable">'; do_meta_boxes($instance->pageHook->manage, 'side', $entry); echo '</div> <!-- #side-sortables -->'; echo '</div> <!-- #postbox-container-1 -->'; echo '<div id="postbox-container-2" class="postbox-container">'; echo '<div id="normal-sortables" class="meta-box-sortables ui-sortable">'; do_meta_boxes($instance->pageHook->manage, 'normal', $entry); echo '</div> <!-- #normal-sortables -->'; echo '</div> <!-- #postbox-container-2 -->'; do_action('cn_admin_form_copy_entry_after', $entry, $form); echo '</div> <!-- #post-body -->'; echo '<br class="clear">'; echo '</div> <!-- #poststuff -->'; $form->close(); unset($entry); } else { cnMessage::render('error', __('You are not authorized to add entries. Please contact the admin if you received this message in error.', 'connections')); } break; case 'edit_entry': echo '<h2>Connections : ', __('Edit Entry', 'connections'), '</h2>'; /* * Check whether the current user can edit entries. */ if (current_user_can('connections_edit_entry') || current_user_can('connections_edit_entry_moderated')) { $id = esc_attr($_GET['id']); check_admin_referer('entry_edit_' . $id); $form = new cnFormObjects(); $entry = new cnOutput($instance->retrieve->entry($id)); $attr = array('id' => 'cn-form', 'action' => 'admin.php?connections_process=true&process=manage&action=update&id=' . $id, 'method' => 'post', 'enctype' => 'multipart/form-data'); $form->open($attr); $field = array('id' => 'metabox-name', 'title' => __('Name', 'connections'), 'context' => 'normal', 'priority' => 'high', 'callback' => array('cnEntryMetabox', 'name')); cnMetabox_Render::add($instance->pageHook->manage, $field); echo '<div id="poststuff">'; echo '<div id="post-body" class="metabox-holder columns-' . (1 == get_current_screen()->get_columns() ? '1' : '2') . '">'; wp_nonce_field('cn-manage-metaboxes'); wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', FALSE); wp_nonce_field('meta-box-order', 'meta-box-order-nonce', FALSE); $form->tokenField('update_entry', FALSE, '_cn_wpnonce', FALSE); do_action('cn_admin_form_edit_entry_before', $entry, $form); echo '<div id="postbox-container-1" class="postbox-container">'; echo '<div id="side-sortables" class="meta-box-sortables ui-sortable">'; do_meta_boxes($instance->pageHook->manage, 'side', $entry); echo '</div> <!-- #side-sortables -->'; echo '</div> <!-- #postbox-container-1 -->'; echo '<div id="postbox-container-2" class="postbox-container">'; echo '<div id="normal-sortables" class="meta-box-sortables ui-sortable">'; do_meta_boxes($instance->pageHook->manage, 'normal', $entry); echo '</div> <!-- #normal-sortables -->'; echo '</div> <!-- #postbox-container-2 -->'; do_action('cn_admin_form_edit_entry_after', $entry, $form); echo '</div> <!-- #post-body -->'; echo '<br class="clear">'; echo '</div> <!-- #poststuff -->'; $form->close(); unset($entry); } else { cnMessage::render('error', __('You are not authorized to edit entries. Please contact the admin if you received this message in error.', 'connections')); } break; default: $form = new cnFormObjects(); $page = $instance->currentUser->getFilterPage('manage'); $offset = ($page->current - 1) * $page->limit; echo '<div class="wrap">'; echo get_screen_icon('connections'); echo '<h2>Connections : ', __('Manage', 'connections'), ' <a class="button add-new-h2" href="admin.php?page=connections_add">', __('Add New', 'connections'), '</a></h2>'; /* * Check whether user can view the entry list */ if (current_user_can('connections_manage')) { $retrieveAttr['list_type'] = $instance->currentUser->getFilterEntryType(); $retrieveAttr['category'] = $instance->currentUser->getFilterCategory(); $retrieveAttr['char'] = isset($_GET['cn-char']) && 0 < strlen($_GET['cn-char']) ? $_GET['cn-char'] : ''; $retrieveAttr['visibility'] = $instance->currentUser->getFilterVisibility(); $retrieveAttr['status'] = $instance->currentUser->getFilterStatus(); $retrieveAttr['limit'] = $page->limit; $retrieveAttr['offset'] = $offset; if (isset($_GET['s']) && !empty($_GET['s'])) { $retrieveAttr['search_terms'] = $_GET['s']; } $results = $instance->retrieve->entries($retrieveAttr); // print_r($instance->lastQuery); ?> <?php if (current_user_can('connections_edit_entry')) { ?> <ul class="subsubsub"> <?php $statuses = array('all' => __('All', 'connections'), 'approved' => __('Approved', 'connections'), 'pending' => __('Moderate', 'connections')); foreach ($statuses as $key => $status) { $subsubsub[] = sprintf('<li><a%1$shref="%2$s">%3$s</a> <span class="count">(%4$d)</span></li>', $instance->currentUser->getFilterStatus() == $key ? ' class="current" ' : ' ', esc_url($form->tokenURL(add_query_arg(array('page' => 'connections_manage', 'cn-action' => 'filter', 'status' => $key)), 'filter')), $status, cnRetrieve::recordCount(array('status' => $key))); } echo implode(' | ', $subsubsub); ?> </ul> <?php } ?> <form method="post"> <p class="search-box"> <label class="screen-reader-text" for="post-search-input"><?php _e('Search Entries', 'connections'); ?> :</label> <input type="search" id="entry-search-input" name="s" value="<?php if (isset($_GET['s']) && !empty($_GET['s'])) { echo $_GET['s']; } ?> " /> <input type="submit" name="" id="search-submit" class="button" value="<?php _e('Search Entries', 'connections'); ?> " /> </p> <?php $form->tokenField('cn_manage_actions'); ?> <input type="hidden" name="cn-action" value="manage_actions"/> <div class="tablenav"> <div class="alignleft actions"> <?php cnTemplatePart::walker('term-select', array('name' => 'category', 'show_option_all' => __('Show All Categories', 'connections'), 'hide_empty' => FALSE, 'hierarchical' => TRUE, 'show_count' => FALSE, 'orderby' => 'name', 'selected' => $instance->currentUser->getFilterCategory())); echo $form->buildSelect('entry_type', array('all' => __('Show All Entries', 'connections'), 'individual' => __('Show Individuals', 'connections'), 'organization' => __('Show Organizations', 'connections'), 'family' => __('Show Families', 'connections')), $instance->currentUser->getFilterEntryType()); /* * Builds the visibilty select list base on current user capabilities. */ if (current_user_can('connections_view_public') || $instance->options->getAllowPublic()) { $visibilitySelect['public'] = __('Show Public', 'connections'); } if (current_user_can('connections_view_private')) { $visibilitySelect['private'] = __('Show Private', 'connections'); } if (current_user_can('connections_view_unlisted')) { $visibilitySelect['unlisted'] = __('Show Unlisted', 'connections'); } if (isset($visibilitySelect)) { /* * Add the 'Show All' option and echo the list. */ $showAll['all'] = __('Show All', 'connections'); $visibilitySelect = $showAll + $visibilitySelect; echo $form->buildSelect('visibility_type', $visibilitySelect, $instance->currentUser->getFilterVisibility()); } ?> <input class="button-secondary action" type="submit" name="filter" value="Filter"/> </div> <div class="tablenav-pages"> <?php echo '<span class="displaying-num">' . sprintf(__('Displaying %1$d of %2$d entries.', 'connections'), $instance->resultCount, $instance->resultCountNoLimit) . '</span>'; /* * // START --> Pagination * * Grab the pagination data again incase a filter reset the values * or the user input an invalid number which the retrieve query would have reset. */ $page = $instance->currentUser->getFilterPage('manage'); $pageCount = ceil($instance->resultCountNoLimit / $page->limit); if ($pageCount > 1) { $pageDisabled = array(); $pageFilterURL = array(); $pageValue = array(); $currentPageURL = add_query_arg(array('page' => FALSE, 'cn-action' => 'filter')); $pageValue['first_page'] = 1; $pageValue['previous_page'] = $page->current - 1 >= 1 ? $page->current - 1 : 1; $pageValue['next_page'] = $page->current + 1 <= $pageCount ? $page->current + 1 : $pageCount; $pageValue['last_page'] = $pageCount; $page->current > 1 ? $pageDisabled['first_page'] = '' : ($pageDisabled['first_page'] = ' disabled'); $page->current - 1 >= 1 ? $pageDisabled['previous_page'] = '' : ($pageDisabled['previous_page'] = ' disabled'); $page->current + 1 <= $pageCount ? $pageDisabled['next_page'] = '' : ($pageDisabled['next_page'] = ' disabled'); $page->current < $pageCount ? $pageDisabled['last_page'] = '' : ($pageDisabled['last_page'] = ' disabled'); /* * Genreate the page link token URL. */ $pageFilterURL['first_page'] = esc_url($form->tokenURL(add_query_arg(array('pg' => $pageValue['first_page']), $currentPageURL), 'filter')); $pageFilterURL['previous_page'] = esc_url($form->tokenURL(add_query_arg(array('pg' => $pageValue['previous_page']), $currentPageURL), 'filter')); $pageFilterURL['next_page'] = esc_url($form->tokenURL(add_query_arg(array('pg' => $pageValue['next_page']), $currentPageURL), 'filter')); $pageFilterURL['last_page'] = esc_url($form->tokenURL(add_query_arg(array('pg' => $pageValue['last_page']), $currentPageURL), 'filter')); echo '<span class="page-navigation" id="page-input">'; echo '<a href="' . $pageFilterURL['first_page'] . '" title="' . __('Go to the first page.', 'connections') . '" class="first-page', $pageDisabled['first_page'], '">«</a> '; echo '<a href="' . $pageFilterURL['previous_page'] . '" title="' . __('Go to the previous page.', 'connections') . '" class="prev-page', $pageDisabled['previous_page'], '">‹</a> '; echo '<span class="paging-input"><input type="text" size="2" value="' . $page->current . '" name="pg" title="' . __('Current page', 'connections') . '" class="current-page"> ' . __('of', 'connections') . ' <span class="total-pages">' . $pageCount . '</span></span> '; echo '<a href="' . $pageFilterURL['next_page'] . '" title="' . __('Go to the next page.', 'connections') . '" class="next-page', $pageDisabled['next_page'], '">›</a> '; echo '<a href="' . $pageFilterURL['last_page'] . '" title="' . __('Go to the last page.', 'connections') . '" class="last-page', $pageDisabled['last_page'], '">»</a>'; echo '</span>'; } /* * // END --> Pagination */ ?> </div> </div> <div class="clear"></div> <div class="tablenav"> <?php if (current_user_can('connections_edit_entry') || current_user_can('connections_delete_entry')) { echo '<div class="alignleft actions">'; echo '<select name="action">'; echo '<option value="" SELECTED>', __('Bulk Actions', 'connections'), '</option>'; $bulkActions = array(); if (current_user_can('connections_edit_entry') || current_user_can('connections_edit_entry_moderated')) { $bulkActions['unapprove'] = __('Unapprove', 'connections'); $bulkActions['approve'] = __('Approve', 'connections'); $bulkActions['public'] = __('Set Public', 'connections'); $bulkActions['private'] = __('Set Private', 'connections'); $bulkActions['unlisted'] = __('Set Unlisted', 'connections'); } if (current_user_can('connections_delete_entry')) { $bulkActions['delete'] = __('Delete', 'connections'); } $bulkActions = apply_filters('cn_manage_bulk_actions', $bulkActions); foreach ($bulkActions as $action => $string) { echo '<option value="', $action, '">', $string, '</option>'; } echo '</select>'; echo '<input class="button-secondary action" type="submit" name="bulk_action" value="', __('Apply', 'connections'), '" />'; echo '</div>'; } ?> <div class="tablenav-pages"> <?php /* * Display the character filter control. */ echo '<span class="displaying-num">', __('Filter by character:', 'connections'), '</span>'; cnTemplatePart::index(array('status' => $instance->currentUser->getFilterStatus(), 'tag' => 'span')); cnTemplatePart::currentCharacter(); ?> </div> </div> <div class="clear"></div> <table cellspacing="0" class="widefat connections"> <thead> <tr> <th class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"/></th> <th class="col" style="width:10%;"></th> <th scope="col" colspan="2" style="width:40%;"><?php _e('Name', 'connections'); ?> </th> <th scope="col" style="width:30%;"><?php _e('Categories', 'connections'); ?> </th> <th scope="col" style="width:20%;"><?php _e('Last Modified', 'connections'); ?> </th> </tr> </thead> <tfoot> <tr> <th class="manage-column column-cb check-column" scope="col"><input type="checkbox"/></th> <th class="col" style="width:10%;"></th> <th scope="col" colspan="2" style="width:40%;"><?php _e('Name', 'connections'); ?> </th> <th scope="col" style="width:30%;"><?php _e('Categories', 'connections'); ?> </th> <th scope="col" style="width:20%;"><?php _e('Last Modified', 'connections'); ?> </th> </tr> </tfoot> <tbody> <?php $previousLetter = ''; foreach ($results as $row) { /** * * * @TODO: Use the Output class to show entry details. */ $entry = new cnvCard($row); $vCard =& $entry; $currentLetter = strtoupper(mb_substr($entry->getSortColumn(), 0, 1)); if ($currentLetter != $previousLetter) { $setAnchor = "<a name='{$currentLetter}'></a>"; $previousLetter = $currentLetter; } else { $setAnchor = null; } /* * Generate the edit, copy and delete URLs with nonce tokens. */ $editTokenURL = esc_url($form->tokenURL('admin.php?page=connections_manage&cn-action=edit_entry&id=' . $entry->getId(), 'entry_edit_' . $entry->getId())); $copyTokenURL = esc_url($form->tokenURL('admin.php?page=connections_manage&cn-action=copy_entry&id=' . $entry->getId(), 'entry_copy_' . $entry->getId())); $deleteTokenURL = esc_url($form->tokenURL('admin.php?cn-action=delete_entry&id=' . $entry->getId(), 'entry_delete_' . $entry->getId())); $approvedTokenURL = esc_url($form->tokenURL('admin.php?cn-action=set_status&status=approved&id=' . $entry->getId(), 'entry_status_' . $entry->getId())); $unapproveTokenURL = esc_url($form->tokenURL('admin.php?cn-action=set_status&status=pending&id=' . $entry->getId(), 'entry_status_' . $entry->getId())); switch ($entry->getStatus()) { case 'pending': $statusClass = ' unapproved'; break; case 'approved': $statusClass = ' approved'; break; default: $statusClass = ''; break; } echo '<tr id="row-', $entry->getId(), '" class="parent-row' . $statusClass . '">'; echo "<th class='check-column' scope='row'><input type='checkbox' value='" . $entry->getId() . "' name='id[]'/></th> \n"; echo '<td>'; $entry->getImage(array('image' => 'photo', 'height' => 54, 'width' => 80, 'zc' => 2, 'fallback' => array('type' => 'block', 'string' => __('No Photo Available', 'connections')))); echo '</td>'; echo '<td colspan="2">'; if ($setAnchor) { echo $setAnchor; } echo '<div style="float:right"><a href="#wphead" title="Return to top."><img src="' . CN_URL . 'assets/images/uparrow.gif" /></a></div>'; if (current_user_can('connections_edit_entry') || current_user_can('connections_edit_entry_moderated')) { echo '<a class="row-title" title="Edit ' . $entry->getName(array('format' => '%last%, %first%')) . '" href="' . $editTokenURL . '"> ' . $entry->getName(array('format' => '%last%, %first%')) . '</a><br />'; } else { echo '<strong>' . $entry->getName(array('format' => '%last%, %first%')) . '</strong>'; } echo '<div class="row-actions">'; $rowActions = array(); $rowEditActions = array(); $rowActions[] = '<a class="detailsbutton" id="row-' . $entry->getId() . '" title="' . __('Click to show details.', 'connections') . '" >' . __('Show Details', 'connections') . '</a>'; $rowActions[] = $vCard->download(array('anchorText' => __('vCard', 'connections'), 'return' => TRUE)); $rowActions[] = cnURL::permalink(array('slug' => $entry->getSlug(), 'title' => sprintf(__('View %s', 'connections'), $entry->getName(array('format' => '%first% %last%'))), 'text' => __('View', 'connections'), 'return' => TRUE)); if ($entry->getStatus() == 'approved' && current_user_can('connections_edit_entry')) { $rowEditActions[] = '<a class="action unapprove" href="' . $unapproveTokenURL . '" title="' . __('Unapprove', 'connections') . ' ' . $entry->getFullFirstLastName() . '">' . __('Unapprove', 'connections') . '</a>'; } if ($entry->getStatus() == 'pending' && current_user_can('connections_edit_entry')) { $rowEditActions[] = '<a class="action approve" href="' . $approvedTokenURL . '" title="' . __('Approve', 'connections') . ' ' . $entry->getFullFirstLastName() . '">' . __('Approve', 'connections') . '</a>'; } if (current_user_can('connections_edit_entry') || current_user_can('connections_edit_entry_moderated')) { $rowEditActions[] = '<a class="editbutton" href="' . $editTokenURL . '" title="' . __('Edit', 'connections') . ' ' . $entry->getFullFirstLastName() . '">' . __('Edit', 'connections') . '</a>'; } if (current_user_can('connections_add_entry') || current_user_can('connections_add_entry_moderated')) { $rowEditActions[] = '<a class="copybutton" href="' . $copyTokenURL . '" title="' . __('Copy', 'connections') . ' ' . $entry->getFullFirstLastName() . '">' . __('Copy', 'connections') . '</a>'; } if (current_user_can('connections_delete_entry')) { $rowEditActions[] = '<a class="submitdelete" onclick="return confirm(\'You are about to delete this entry. \\\'Cancel\\\' to stop, \\\'OK\\\' to delete\');" href="' . $deleteTokenURL . '" title="' . __('Delete', 'connections') . ' ' . $entry->getFullFirstLastName() . '">' . __('Delete', 'connections') . '</a>'; } if (!empty($rowEditActions)) { echo implode(' | ', $rowEditActions), '<br/>'; } if (!empty($rowActions)) { echo implode(' | ', $rowActions); } echo '</div>'; echo "</td> \n"; echo "<td > \n"; $categories = $entry->getCategory(); if (!empty($categories)) { $i = 0; foreach ($categories as $category) { /* * Genreate the category link token URL. */ $categoryFilterURL = $form->tokenURL('admin.php?cn-action=filter&category=' . $category->term_id, 'filter'); echo '<a href="' . $categoryFilterURL . '">' . $category->name . '</a>'; $i++; if (count($categories) > $i) { echo ', '; } } unset($i); } echo "</td> \n"; echo '<td >'; echo '<strong>' . __('On', 'connections') . ':</strong> ' . $entry->getFormattedTimeStamp('m/d/Y g:ia') . '<br />'; echo '<strong>' . __('By', 'connections') . ':</strong> ' . $entry->getEditedBy() . '<br />'; echo '<strong>' . __('Visibility', 'connections') . ':</strong> ' . $entry->displayVisibilityType() . '<br />'; $user = $entry->getUser() ? get_userdata($entry->getUser()) : FALSE; /** * NOTE: WP 3.5 introduced get_edit_user_link() * REF: http://codex.wordpress.org/Function_Reference/get_edit_user_link * * @TODO Use get_edit_user_link() to simplify this code when WP hits >= 3.9. */ if ($user) { if (get_current_user_id() == $user->ID) { $editUserLink = get_edit_profile_url($user->ID); } else { $editUserLink = add_query_arg('user_id', $user->ID, self_admin_url('user-edit.php')); } echo '<strong>' . __('Linked to:', 'connections') . '</strong> ' . '<a href="' . esc_url($editUserLink) . '">' . esc_attr($user->display_name) . '</a>'; } echo "</td> \n"; echo "</tr> \n"; echo "<tr class='child-row-" . $entry->getId() . " cn-entry-details' id='contact-" . $entry->getId() . "-detail' style='display:none;'>"; echo '<td colspan="2"> </td>', "\n"; //echo "<td > </td> \n"; echo '<td colspan="2">'; /* * Check if the entry has relations. Count the relations and then cycle thru each relation. * Before the out check that the related entry still exists. If it does and the current user * has edit capabilites the edit link will be displayed. If the user does not have edit capabilities * the only the relation will be shown. After all relations have been output insert a <br> * for spacing [@TODO: NOTE: this should be done with styles]. */ if ($entry->getFamilyMembers()) { $count = count($entry->getFamilyMembers()); $i = 0; foreach ($entry->getFamilyMembers() as $key => $value) { $relation = new cnEntry(); $relation->set($key); $editRelationTokenURL = $form->tokenURL('admin.php?page=connections&action=edit&id=' . $relation->getId(), 'entry_edit_' . $relation->getId()); if ($relation->getId()) { if (current_user_can('connections_edit_entry')) { echo '<strong>' . $instance->options->getFamilyRelation($value) . ':</strong> ' . '<a href="' . $editRelationTokenURL . '" title="' . __('Edit', 'connections') . ' ' . $relation->getFullFirstLastName() . '">' . $relation->getFullFirstLastName() . '</a><br />' . "\n"; } else { echo '<strong>' . $instance->options->getFamilyRelation($value) . ':</strong> ' . $relation->getFullFirstLastName() . '<br />' . "\n"; } } if ($count - 1 == $i) { echo '<br />'; } // Insert a break after all connections are listed. $i++; unset($relation); } unset($i); unset($count); } if ($entry->getContactFirstName() || $entry->getContactLastName()) { echo '<strong>' . __('Contact', 'connections') . ':</strong> ' . $entry->getContactFirstName() . ' ' . $entry->getContactLastName() . '<br />'; } if ($entry->getTitle()) { echo '<strong>' . __('Title', 'connections') . ':</strong> ' . $entry->getTitle() . '<br />'; } if ($entry->getOrganization() && $entry->getEntryType() !== 'organization') { echo '<strong>' . __('Organization', 'connections') . ':</strong> ' . $entry->getOrganization() . '<br />'; } if ($entry->getDepartment()) { echo '<strong>' . __('Department', 'connections') . ':</strong> ' . $entry->getDepartment() . '<br />'; } $addresses = $entry->getAddresses(); //print_r($addresses); if (!empty($addresses)) { foreach ($addresses as $address) { $outCache = array(); echo '<div style="margin: 10px 0;">'; $address->preferred ? $preferred = '*' : ($preferred = ''); if (!empty($address->name)) { echo '<span style="display: block"><strong>', $address->name, $preferred, '</strong></span>'; } if (!empty($address->line_1)) { echo '<span style="display: block">', $address->line_1, '</span>'; } if (!empty($address->line_2)) { echo '<span style="display: block">', $address->line_2, '</span>'; } if (!empty($address->line_3)) { echo '<span style="display: block">', $address->line_3, '</span>'; } if (!empty($address->city)) { $outCache[] = '<span>' . $address->city . '</span>'; } if (!empty($address->state)) { $outCache[] = '<span>' . $address->state . '</span>'; } if (!empty($address->zipcode)) { $outCache[] = '<span>' . $address->zipcode . '</span>'; } if (!empty($outCache)) { echo '<span style="display: block">', implode(' ', $outCache), '</span>'; } if (!empty($address->country)) { echo '<span style="display: block">', $address->country, '</span>'; } if (!empty($address->latitude) && !empty($address->longitude)) { echo '<span style="display: block">', '<strong>', __('Latitude', 'connections'), ':</strong>', ' ', $address->latitude, ' ', '<strong>', __('Longitude', 'connections'), ':</strong>', ' ', $address->longitude, '</span>'; } echo '</div>'; } unset($outCache); } echo '</td>', "\n"; echo '<td>'; $phoneNumbers = $entry->getPhoneNumbers(); if (!empty($phoneNumbers)) { echo '<div class="phone-numbers">'; foreach ($phoneNumbers as $phone) { $phone->preferred ? $preferred = '*' : ($preferred = ''); echo '<span class="phone"><strong>', $phone->name, '</strong>: ', $phone->number, $preferred, '</span>'; } echo '</div>'; } $emailAddresses = $entry->getEmailAddresses(); if (!empty($emailAddresses)) { echo '<div class="email-addresses">'; foreach ($emailAddresses as $email) { $email->preferred ? $preferred = '*' : ($preferred = ''); echo '<span class="email"><strong>', $email->name, ':</strong> <a href="mailto:', $email->address, '">', $email->address, '</a>', $preferred, '</span>'; } echo '</div>'; } $imIDs = $entry->getIm(); if (!empty($imIDs)) { echo '<div class="im-ids">'; foreach ($imIDs as $im) { $im->preferred ? $preferred = '*' : ($preferred = ''); echo '<span class="im"><strong>', $im->name, ':</strong> ', $im->id, $preferred, '</span>'; } echo '</div>'; } $socialNetworks = $entry->getSocialMedia(); if (!empty($socialNetworks)) { echo '<div class="social-networks">'; foreach ($entry->getSocialMedia() as $network) { $network->preferred ? $preferred = '*' : ($preferred = ''); echo '<span class="social-network"><strong>', $network->name, ':</strong> <a target="_blank" href="', $network->url, '">', $network->url . '</a>', $preferred, '</span>'; } echo '</div>'; } $links = $entry->getLinks(); if (!empty($links)) { echo '<div class="links">'; foreach ($links as $link) { $link->preferred ? $preferred = '*' : ($preferred = ''); echo '<span class="link"><strong>', $link->name, ':</strong> <a target="_blank" href="', $link->url, '">', $link->url, '</a>', $preferred, '</span>'; } echo '</div>'; } echo "</td> \n"; echo "<td>"; $entry->getDateBlock(); echo "</td> \n"; echo "</tr> \n"; echo "<tr class='child-row-" . $entry->getId() . " entrynotes' id='contact-" . $entry->getId() . "-detail-notes' style='display:none;'>"; echo "<td colspan='2'> </td> \n"; //echo "<td > </td> \n"; echo "<td colspan='3'>"; echo $entry->getBio() ? '<strong>' . __('Bio', 'connections') . ':</strong> ' . $entry->getBio() . '<br />' : ' '; echo $entry->getNotes() ? '<strong>' . __('Notes', 'connections') . ':</strong> ' . $entry->getNotes() : ' '; echo "</td> \n"; echo '<td> <span style="display: block;"><strong>' . __('Entry ID', 'connections') . ':</strong> ' . $entry->getId() . '</span>' . ' <span style="display: block;"><strong>' . __('Entry Slug', 'connections') . ':</strong> ' . $entry->getSlug() . '</span>' . ' <span style="display: block;"><strong>' . __('Date Added', 'connections') . ':</strong> ' . $entry->getDateAdded('m/d/Y g:ia') . '</span> <span style="display: block;"><strong>' . __('Added By', 'connections') . ':</strong> ' . $entry->getAddedBy() . '</span>'; echo '<span style="display: block;"><strong>' . __('Image Linked', 'connections') . ':</strong> ' . (!$entry->getImageLinked() ? __('No', 'connections') : __('Yes', 'connections')) . '</span>'; echo '<span style="display: block;"><strong>' . __('Display', 'connections') . ':</strong> ' . ($entry->getImageLinked() && $entry->getImageDisplay() ? __('Yes', 'connections') : __('No', 'connections')) . '</span>'; echo "</td> \n"; echo "</tr> \n"; } ?> </tbody> </table> </form> <script type="text/javascript"> /* <![CDATA[ */ (function($){ $(document).ready(function(){ $('#doaction, #doaction2').click(function(){ if ( $('select[name^="action"]').val() == 'delete' ) { var m = 'You are about to delete the selected entry(ies).\n \'Cancel\' to stop, \'OK\' to delete.'; return showNotice.warn(m); } }); }); })(jQuery); /* ]]> */ </script> <?php } else { cnMessage::set('error', 'capability_view_entry_list'); } break; } echo '</div> <!-- .wrap -->'; }
* @author : Phill Pafford * @website: http://llihp.blogspot.com * * @todo : * -Add Link to personal profile in popup for each member displayed, NOT FOR MOBILE VIEWING */ /** @var cnEntry $entry */ if (sizeof($entry->getFamilyMembers()) > 0) { // create the div $member_listing = '<div class="member-entry">'; $mobile_member_listing = '<div class="member-entry">'; // Info Div header $member_listing .= '<div><span class="member-details"><strong>'; $mobile_member_listing .= '<div><span class="member-details"><strong>'; // create family member $member_group = new cnEntry(); // Create the popup container //$member_popup_info = '<div id="popup-group-name"><span>' . $entry->getFamilyName() . '</span></div>'; // Set a counter $counter = 0; foreach ($entry->getFamilyMembers() as $relationData) { // Increment $counter++; // Set family member id $member_group->set($relationData['entry_id']); if ($counter > 1) { $member_list_first_names .= ", " . $member_group->getName(array('format' => '%first%')); } else { $member_list_first_names = $member_group->getName(array('format' => '%first%')); } }
/** * Delete the player. * * @param none * @return void */ public function delete() { $entry = new cnEntry(); $entry->delete($this->getId()); }
/** * 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); }
private function getEntrySelect($name, $selected = NULL) { global $wpdb, $connections; $atts['list_type'] = 'individual'; $atts['category'] = NULL; $atts['visibility'] = NULL; $results = $connections->retrieve->entries($atts); $out = '<select name="' . $name . '">'; $out .= '<option value="">Select Entry</option>'; foreach ($results as $row) { $entry = new cnEntry($row); $out .= '<option value="' . $entry->getId() . '"'; if ($selected == $entry->getId()) { $out .= ' SELECTED'; } $out .= '>' . $entry->getFullLastFirstName() . '</option>'; } $out .= '</select>'; return $out; }
*/ if (sizeof($entry->getConnectionGroup()) > 0) { // Get the plugins dir URL for the site $plugindir = get_bloginfo('wpurl').'/wp-content/plugins'; // create the div $member_listing = '<div class="member-entry">'; $mobile_member_listing = '<div class="member-entry">'; // Info Div header $member_listing .= '<div><span class="member-details"><strong>'; $mobile_member_listing .= '<div><span class="member-details"><strong>'; // create family member $member_group = new cnEntry(); // Create the popup container //$member_popup_info = '<div id="popup-group-name"><span>' . $entry->getFamilyName() . '</span></div>'; // Set a counter $counter = 0; foreach ($entry->getConnectionGroup() as $key_member_group=>$value_member_group) { // Increment $counter++; // Set family member id $member_group->set($key_member_group); if ($counter > 1) {
public static function shortcode($atts, $content = '', $tag = 'cn_thumbr') { // Grab an instance of the Connections object. $instance = Connections_Directory(); $log = array(); $srcset = array(); $permitted = array('attachment', 'featured', 'path', 'url', 'logo', 'photo'); $defaults = array('type' => 'url', 'source' => NULL, 'negate' => FALSE, 'grayscale' => FALSE, 'brightness' => 0, 'colorize' => NULL, 'contrast' => 0, 'detect_edges' => FALSE, 'emboss' => FALSE, 'gaussian_blur' => FALSE, 'blur' => FALSE, 'sketchy' => FALSE, 'sharpen' => FALSE, 'smooth' => NULL, 'opacity' => 100, 'crop_mode' => 1, 'crop_focus' => array(0.5, 0.5), 'crop_only' => FALSE, 'canvas_color' => '#FFFFFF', 'quality' => 90, 'sizes' => '1024|640|320'); $defaults = apply_filters('cn_thumbr_shortcode_atts', $defaults); $atts = shortcode_atts($defaults, $atts, $tag); if (!in_array($atts['type'], $permitted)) { return __('Valid image source type not supplied.', 'connections'); } /* * Convert some of the $atts values in the array to boolean because the Shortcode API passes all values as strings. */ cnFormatting::toBoolean($atts['negate']); cnFormatting::toBoolean($atts['grayscale']); cnFormatting::toBoolean($atts['detect_edges']); cnFormatting::toBoolean($atts['emboss']); cnFormatting::toBoolean($atts['gaussian_blur']); cnFormatting::toBoolean($atts['blur']); cnFormatting::toBoolean($atts['sketchy']); cnFormatting::toBoolean($atts['sharpen']); // cnFormatting::toBoolean( $atts['crop'] ); cnFormatting::toBoolean($atts['crop_only']); $atts['sizes'] = explode('|', $atts['sizes']); array_map('trim', $atts['sizes']); array_map('absint', $atts['sizes']); if (empty($atts['sizes'])) { return __('No image sizes were supplied or supplied values were invalid.', 'connections'); } switch ($atts['type']) { case 'attachment': $source = wp_get_attachment_url(absint($atts['source'])); break; case 'featured': $source = wp_get_attachment_url(get_post_thumbnail_id()); break; case 'path': $source = $atts['source']; break; case 'url': $source = esc_url($atts['source']); break; case 'logo': $result = $instance->retrieve->entry(absint($atts['source'])); $entry = new cnEntry($result); $meta = $entry->getImageMeta(array('type' => 'logo')); if (is_wp_error($meta)) { // Display the error messages. return implode(PHP_EOL, $meta->get_error_messages()); } $source = $meta['url']; break; case 'photo': $result = $instance->retrieve->entry(absint($atts['source'])); $entry = new cnEntry($result); $meta = $entry->getImageMeta(array('type' => 'photo')); if (is_wp_error($meta)) { // Display the error messages. return implode(PHP_EOL, $meta->get_error_messages()); } $source = $meta['url']; break; } // Unset $atts['source'] because passing that $atts to cnImage::get() extracts and overwrite the $source var. unset($atts['source']); foreach ($atts['sizes'] as $width) { $atts['width'] = $width; $image = cnImage::get($source, $atts, 'data'); if (is_wp_error($image)) { // Display the error messages. return implode(PHP_EOL, $image->get_error_messages()); } elseif ($image === FALSE) { return __('An error has occured while creating the thumbnail.', 'connections'); } if (defined('WP_DEBUG') && WP_DEBUG === TRUE) { $log[] = '<pre>' . $image['log'] . '</pre>'; } $srcset[] = $image['url'] . ' ' . $width . 'w'; } $out = sprintf('<img class="cn-image" srcset="%1$s" sizes="100vw"%2$s />', implode(',', $srcset), empty($content) ? '' : ' alt="' . esc_attr($content) . '"'); if (defined('WP_DEBUG') && WP_DEBUG === TRUE) { $out .= implode('', $log); } return $out; }
/** * Add the the current Connections category description or entry bio excerpt as the page meta description. * * @access private * @since 0.7.8 * @static * * @uses get_query_var() * @uses esc_attr() * @uses strip_shortcodes() * * @return string */ public static function metaDesc() { global $connections; // Whether or not to filter the page title with the current directory location. if (!cnSettingsAPI::get('connections', 'connections_seo_meta', 'page_desc')) { return; } if (get_query_var('cn-cat-slug')) { // If the category slug is a descendant, use the last slug from the URL for the query. $categorySlug = explode('/', get_query_var('cn-cat-slug')); if (isset($categorySlug[count($categorySlug) - 1])) { $categorySlug = $categorySlug[count($categorySlug) - 1]; } $term = $connections->term->getTermBy('slug', $categorySlug, 'category'); $category = new cnCategory($term); $description = $category->getExcerpt(array('length' => 160)); } if (get_query_var('cn-cat')) { if (is_array(get_query_var('cn-cat'))) { return; } $categoryID = get_query_var('cn-cat'); $term = $connections->term->getTermBy('id', $categoryID, 'category'); $category = new cnCategory($term); $description = $category->getExcerpt(array('length' => 160)); } if (get_query_var('cn-entry-slug')) { $result = $connections->retrieve->entries(array('slug' => urldecode(get_query_var('cn-entry-slug')))); $entry = new cnEntry($result[0]); $description = $entry->getExcerpt(array('length' => 160)); } if (empty($description)) { return; } echo '<meta name="description" content="' . esc_attr(trim(strip_shortcodes(strip_tags(stripslashes($description))))) . '"/>' . "\n"; }
/** * Echos the family members of the family entry type. */ public function getFamilyMemberBlock() { if ($this->getFamilyMembers()) { global $connections; foreach ($this->getFamilyMembers() as $key => $value) { $relation = new cnEntry(); $relation->set($key); echo '<span><strong>' . $connections->options->getFamilyRelation($value) . ':</strong> ' . $relation->getFullFirstLastName() . '</span><br />' . "\n"; unset($relation); } } }
function processDeleteEntries() { /* * Check whether the current user delete an entry. */ if (current_user_can('connections_delete_entry')) { global $connections; if (empty($_POST['entry'])) return FALSE; if (current_user_can('connections_delete_entry')) { $ids = $_POST['entry']; foreach ($ids as $id) { $entry = new cnEntry( $connections->retrieve->entry($id) ); $id = esc_attr($id); $entry->delete($id); unset($entry); } $connections->setSuccessMessage('form_entry_delete_bulk'); } else { $connections->setErrorMessage('capability_delete'); } } else { $connections->setErrorMessage('capability_delete'); } }
/** * Prepare a single address output for response. * * @param cnEntry $entry Post object. * @param WP_REST_Request $request Request object. * @param array $data * * @return array $data */ private function prepare_address_for_response($entry, $request, $data) { $data['adr'] = array(); $display = $entry->getAddresses(); $raw = $entry->getAddresses(array(), TRUE, FALSE, 'raw'); if (empty($addresses)) { return $data; } foreach ($addresses as $address) { $item = array('street_address' => array('raw' => '', 'rendered' => ''), 'extended_address' => array('raw' => '', 'rendered' => ''), 'street_address_3' => array('raw' => '', 'rendered' => ''), 'street_address_4' => array('raw' => '', 'rendered' => ''), 'locality' => array('raw' => '', 'rendered' => ''), 'region' => array('raw' => '', 'rendered' => ''), 'district' => array('raw' => '', 'rendered' => ''), 'county' => array('raw' => '', 'rendered' => ''), 'postal_code' => array('raw' => '', 'rendered' => ''), 'country_name' => array('raw' => '', 'rendered' => '')); $data['adr'] = $item; } return $data; }
/** * Echos the family members of the family entry type. * * @access public * @since unknown * * @param array $atts { * Optional. * * @type string $container_tag The relationship container tag. Default `ul`. Accepts HTML tag. * @type string $item_tag The relationship row tag. Default `li`. Accepts HTML tag. * @type string $item_format The relationship row HTML markup. * @type string $name_format How the relationship name should be displayed @see cnEntry::getName(). * @type string $separator The string used to separate the relation label from the relation name. Default ':'. * @type string $before HTML to be displayed before the relations container. Default, empty string. * @type string $after HTML to be displayed after the relations container. Default, empty string. * @type string $before_item HTML to be displayed before a relation row. Default, empty string. * @type string $after_item HTML to be displayed after a relation row. Default, empty string. * } * * @return string */ public function getFamilyMemberBlock($atts = array()) { $defaults = array('container_tag' => 'ul', 'item_tag' => 'li', 'item_format' => '<%1$s class="cn-relation"><span class="cn-relation-label">%relation%</span>%separator% <span class="cn-relation-name notranslate">%name%</span></%1$s>', 'name_format' => '', 'separator' => ':', 'before' => '', 'after' => '', 'before_item' => '', 'after_item' => '', 'return' => FALSE); /** * Filter the arguments. * * @since unknown * * @param array $atts An array of arguments. */ $atts = cnSanitize::args(apply_filters('cn_output_family_atts', $atts), $defaults); $html = ''; $search = array('%relation%', '%name%', '%separator%'); if ($this->getFamilyMembers()) { // Grab an instance of the Connections object. $instance = Connections_Directory(); foreach ($this->getFamilyMembers() as $key => $value) { $relation = new cnEntry(); $replace = array(); if ($relation->set($key)) { $replace[] = $instance->options->getFamilyRelation($value); $replace[] = cnURL::permalink(array('type' => 'name', 'slug' => $relation->getSlug(), 'title' => $relation->getName(array('format' => $atts['name_format'])), 'text' => $relation->getName(array('format' => $atts['name_format'])), 'home_id' => $this->directoryHome['page_id'], 'force_home' => $this->directoryHome['force_home'], 'return' => TRUE)); $replace[] = empty($atts['separator']) ? '' : '<span class="cn-separator">' . $atts['separator'] . '</span>'; $row = str_ireplace($search, $replace, empty($atts['item_format']) ? $defaults['item_format'] : $atts['item_format']); $html .= "\t" . sprintf($row, $atts['item_tag']) . PHP_EOL; } } $html = sprintf('<%1$s class="cn-relations">' . PHP_EOL . '%2$s</%1$s>', $atts['container_tag'], $html); $html = $atts['before'] . $html . $atts['after'] . PHP_EOL; } return $this->echoOrReturn($atts['return'], $html); }
function cnRunDBUpgrade() { global $wpdb, $connections; $urlPath = admin_url() . 'admin.php?page=' . $_GET['page']; // Check to ensure that the table exists if ($wpdb->get_var("SHOW TABLES LIKE 'CN_ENTRY_TABLE'") != CN_ENTRY_TABLE) { echo '<h3>Upgrade the database structure...</h3>' . "\n"; $wpdb->show_errors(); $dbVersion = $connections->options->getDBVersion(); if (version_compare($dbVersion, '0.1.0', '<')) { echo '<h4>Upgrade from database version ' . $connections->options->getDBVersion() . ' to database version 0.1.0 ' . ".</h4>\n"; echo '<ul>'; echo '<li>Changing "id" type-length/values to BIGINT(20)' . "</li>\n"; if (!$wpdb->query("ALTER TABLE " . CN_ENTRY_TABLE . " CHANGE id id BIGINT(20) NOT NULL AUTO_INCREMENT")) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "date_added"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'date_added', 'tinytext NOT NULL AFTER ts')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "entry_type"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'entry_type', 'tinytext NOT NULL AFTER date_added')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "honorable_prefix"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'honorable_prefix', 'tinytext NOT NULL AFTER entry_type')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "middle_name"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'middle_name', 'tinytext NOT NULL AFTER first_name')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "honorable_suffix"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'honorable_suffix', 'tinytext NOT NULL AFTER last_name')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "social"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'social', 'longtext NOT NULL AFTER im')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "added_by"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'added_by', 'bigint(20) NOT NULL AFTER options')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "edited_by"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'edited_by', 'bigint(20) NOT NULL AFTER added_by')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "owner"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'owner', 'bigint(20) NOT NULL AFTER edited_by')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "status"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'status', 'varchar(20) NOT NULL AFTER owner')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "contact_first_name"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'contact_first_name', 'tinytext NOT NULL AFTER department')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Adding Column... "contact_last_name"' . "</li>\n"; if (cnAddTableColumn(CN_ENTRY_TABLE, 'contact_last_name', 'tinytext NOT NULL AFTER contact_first_name')) echo '<ul><li>SUCCESS</li></ul>'; echo '</ul>'; echo '<h4>Adding default term relationship.</h4>'; // Add the Uncategorized category to all previous entries. $term = $connections->term->getTermBy('slug', 'uncategorized', 'category'); $entryIDs = $wpdb->get_col( "SELECT id FROM " . CN_ENTRY_TABLE ); $termID[] = $term->term_taxonomy_id; foreach ($entryIDs as $entryID) { $connections->term->setTermRelationships($entryID, $termID, 'category'); } $connections->options->setDBVersion('0.1.0'); } if (version_compare($dbVersion, '0.1.1', '<')) { echo '<h4>Upgrade from database version ' . $connections->options->getDBVersion() . ' to database version 0.1.1 ' . ".</h4>\n"; //echo '<h4>Setting all current entries to the "approved" status.' . "</h4>\n"; /*$results = $connections->retrieve->entries(); foreach ($results as $result) { $entry = new cnEntry($result); $entry->update(); }*/ $connections->options->setDBVersion('0.1.1'); } if (version_compare($dbVersion, '0.1.2', '<')) { echo '<h4>Upgrade from database version ' . $connections->options->getDBVersion() . ' to database version 0.1.2 ' . ".</h4>\n"; //echo '<h4>Setting all current entries `entry_type` column.' . "</h4>\n"; /*$results = $connections->retrieve->entries(); foreach ($results as $result) { $entry = new cnEntry($result); $entry->update(); }*/ $connections->options->setDBVersion('0.1.2'); } if (version_compare($dbVersion, '0.1.3', '<')) { echo '<h4>Upgrade from database version ' . $connections->options->getDBVersion() . ' to database version ' . CN_DB_VERSION . ".</h4>\n"; echo '<ul>'; echo '<li>Changing column name from group_name to family_name...' . "</li>\n"; if (cnAlterTable(CN_ENTRY_TABLE, 'CHANGE COLUMN group_name family_name tinytext NOT NULL')) echo '<ul><li>SUCCESS</li></ul>'; echo '</ul>'; $connections->options->setDBVersion('0.1.3'); } if (version_compare($dbVersion, '0.1.4', '<')) { echo '<h4>Upgrade from database version ' . $connections->options->getDBVersion() . ' to database version ' . CN_DB_VERSION . ".</h4>\n"; echo '<ul>'; echo '<li>Changing column name from honorable_prefix to honorific_prefix...' . "</li>\n"; if (cnAlterTable(CN_ENTRY_TABLE, 'CHANGE COLUMN honorable_prefix honorific_prefix tinytext NOT NULL')) echo '<ul><li>SUCCESS</li></ul>'; echo '<li>Changing column name from honorable_suffix to honorific_suffix...' . "</li>\n"; if (cnAlterTable(CN_ENTRY_TABLE, 'CHANGE COLUMN honorable_suffix honorific_suffix tinytext NOT NULL')) echo '<ul><li>SUCCESS</li></ul>'; echo '</ul>'; $connections->options->setDBVersion('0.1.4'); } echo '<h4>Updating entries to the new database stucture.' . "</h4>\n"; $results = $connections->retrieve->entries(); foreach ($results as $result) { $entry = new cnEntry($result); $entry->update(); } echo '<h4>Upgrade completed.' . "</h4>\n"; echo '<h4><a href="' . $urlPath . '">Continue</a></h4>'; $wpdb->hide_errors(); } }
/** * Retrieve a player. * * @param mixed Player name or ID. * @param bool (Optional) Boolean indicating if the player should be automatically created. When * $Name is numeric (an ID), this argument has no effect. * @return object my5280_Player object */ public function getPlayer($Name, $Create = true) { global $connections; $cnRetrieve = $connections->retrieve; // Handle a numeric name if (is_numeric($Name)) { $entry = $cnRetrieve->entry($Name); if (!$entry) { return null; } } elseif (is_string($Name)) { // Parse the name $parts = explode(',', $Name); $count = count($parts); if ($count == 2) { $firstName = trim($parts[1]); $lastName = trim($parts[0]); } elseif ($count == 1) { $parts = explode(' ', $Name); $count = count($parts); $firstName = $parts[0]; if ($count >= 2) { $lastName = implode(' ', array_slice($parts, 1)); } else { $lastName = null; } } else { $firstName = $Name; $lastName = null; } // Search for the contact $ret = $cnRetrieve->entries(array('first_name' => $firstName, 'last_name' => $lastName)); // Get the matching entry $entry = null; foreach ($ret as $possible) { if (strcasecmp($possible->first_name, $firstName) == 0 && strcasecmp($possible->last_name, $lastName) == 0) { $entry = $possible; break; } } // Create a new entry (if requested) if ($entry === null) { if ($Create) { // Set basic information $entry = new cnEntry(); $entry->setFirstName($firstName); $entry->setLastName($lastName); $entry->setEntryType('individual'); $entry->setVisibility('private'); $entry->setStatus('approved'); } else { return null; } } } else { throw new Exception("Invalid player identifier: {$Name}"); } // Return the my5280_Player object require_once MY5280_PLUGIN_DIR . 'lib/player.php'; return new my5280_Player($entry); }
/** * Add the the current Connections category description or entry bio excerpt as the page meta description. * * @access private * @since 0.7.8 * @static * * @uses cnQuery::getVar() * @uses esc_attr() * @uses strip_shortcodes() */ public static function metaDesc() { // Whether or not to filter the page title with the current directory location. if (!cnSettingsAPI::get('connections', 'seo_meta', 'page_desc')) { return; } $description = ''; if (cnQuery::getVar('cn-cat-slug')) { // If the category slug is a descendant, use the last slug from the URL for the query. $categorySlug = explode('/', cnQuery::getVar('cn-cat-slug')); if (isset($categorySlug[count($categorySlug) - 1])) { $categorySlug = $categorySlug[count($categorySlug) - 1]; } $term = cnTerm::getBy('slug', $categorySlug, 'category'); $category = new cnCategory($term); $description = $category->getExcerpt(array('length' => 160)); } if (cnQuery::getVar('cn-cat')) { if (is_array(cnQuery::getVar('cn-cat'))) { return; } $categoryID = cnQuery::getVar('cn-cat'); $term = cnTerm::getBy('id', $categoryID, 'category'); $category = new cnCategory($term); $description = $category->getExcerpt(array('length' => 160)); } if (cnQuery::getVar('cn-entry-slug')) { // Grab an instance of the Connections object. $instance = Connections_Directory(); $result = $instance->retrieve->entries(array('slug' => urldecode(cnQuery::getVar('cn-entry-slug')))); // Make sure an entry is returned and then echo the meta desc. if (!empty($result)) { $entry = new cnEntry($result[0]); $description = $entry->getExcerpt(array('length' => 160)); } } if (0 == strlen($description)) { return; } echo '<meta name="description" content="' . esc_attr(trim(strip_shortcodes(strip_tags(stripslashes($description))))) . '"/>' . "\n"; }
function connectionsShowViewPage() { global $wpdb, $connections; if (isset($_GET['action'])) { $action = $_GET['action']; } else { $action = NULL; } ?> <div class="wrap"> <div class="icon32" id="icon-connections"><br/></div> <h2>Connections</h2> <?php $connections->displayMessages(); switch ($action) { case 'add_new': /* * Check whether current user can add an entry. */ if (current_user_can('connections_add_entry')) { add_meta_box('metabox-name', 'Name', array(&$form, 'metaboxName'), $connections->pageHook->manage, 'normal', 'high'); $form = new cnFormObjects(); $entry = new cnEntry(); echo '<div id="poststuff" class="metabox-holder has-right-sidebar">'; echo '<h2><a name="new"></a>Add Entry</h2>'; $attr = array('action' => 'admin.php?page=connections&action=add', 'method' => 'post', 'enctype' => 'multipart/form-data'); $form->open($attr); $form->tokenField('add_entry'); wp_nonce_field('howto-metaboxes-general'); wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); echo '<input type="hidden" name="action" value="save_howto_metaboxes_general" />'; echo '<div id="side-info-column" class="inner-sidebar">'; do_meta_boxes($connections->pageHook->manage, 'side', $entry); echo '</div>'; echo '<div id="post-body" class="has-sidebar">'; echo '<div id="post-body-content" class="has-sidebar-content">'; do_meta_boxes($connections->pageHook->manage, 'normal', $entry); echo '</div>'; echo '</div>'; $form->close(); echo '</div>'; ?> <script type="text/javascript"> //<![CDATA[ jQuery(document).ready( function($) { // close postboxes that should be closed $('.if-js-closed').removeClass('if-js-closed').addClass('closed'); // postboxes setup postboxes.add_postbox_toggles('<?php echo $connections->pageHook->manage; ?> '); }); //]]> </script> <?php unset($entry); } else { $connections->setErrorMessage('capability_add'); } break; case 'copy': /* * Check whether current user can add an entry. */ if (current_user_can('connections_add_entry')) { $id = esc_attr($_GET['id']); check_admin_referer('entry_copy_' . $id); add_meta_box('metabox-name', 'Name', array(&$form, 'metaboxName'), $connections->pageHook->manage, 'normal', 'high'); $form = new cnFormObjects(); $entry = new cnEntry($connections->retrieve->entry($id)); echo '<div id="poststuff" class="metabox-holder has-right-sidebar">'; echo '<h2><a name="new"></a>Add Entry</h2>'; $attr = array('action' => 'admin.php?page=connections&action=add&id=' . $id, 'method' => 'post', 'enctype' => 'multipart/form-data'); $form->open($attr); $form->tokenField('add_entry'); wp_nonce_field('howto-metaboxes-general'); wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); echo '<input type="hidden" name="action" value="save_howto_metaboxes_general" />'; echo '<div id="side-info-column" class="inner-sidebar">'; do_meta_boxes($connections->pageHook->manage, 'side', $entry); echo '</div>'; echo '<div id="post-body" class="has-sidebar">'; echo '<div id="post-body-content" class="has-sidebar-content">'; do_meta_boxes($connections->pageHook->manage, 'normal', $entry); echo '</div>'; echo '</div>'; $form->close(); echo '</div>'; ?> <script type="text/javascript"> //<![CDATA[ jQuery(document).ready( function($) { // close postboxes that should be closed $('.if-js-closed').removeClass('if-js-closed').addClass('closed'); // postboxes setup postboxes.add_postbox_toggles('<?php echo $connections->pageHook->manage; ?> '); }); //]]> </script> <?php unset($entry); } else { $connections->setErrorMessage('capability_add'); } break; case 'edit': /* * Check whether the current user can edit entries. */ if (current_user_can('connections_edit_entry')) { $id = esc_attr($_GET['id']); check_admin_referer('entry_edit_' . $id); add_meta_box('metabox-name', 'Name', array(&$form, 'metaboxName'), $connections->pageHook->manage, 'normal', 'high'); $form = new cnFormObjects(); $entry = new cnEntry($connections->retrieve->entry($id)); echo '<div id="poststuff" class="metabox-holder has-right-sidebar">'; echo '<h2><a name="new"></a>Edit Entry</h2>'; $attr = array('action' => 'admin.php?page=connections&action=update&id=' . $id, 'method' => 'post', 'enctype' => 'multipart/form-data'); $form->open($attr); $form->tokenField('update_entry'); wp_nonce_field('howto-metaboxes-general'); wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); echo '<input type="hidden" name="action" value="save_howto_metaboxes_general" />'; echo '<div id="side-info-column" class="inner-sidebar">'; do_meta_boxes($connections->pageHook->manage, 'side', $entry); echo '</div>'; echo '<div id="post-body" class="has-sidebar">'; echo '<div id="post-body-content" class="has-sidebar-content">'; do_meta_boxes($connections->pageHook->manage, 'normal', $entry); echo '</div>'; echo '</div>'; $form->close(); echo '</div>'; ?> <script type="text/javascript"> //<![CDATA[ jQuery(document).ready( function($) { // close postboxes that should be closed $('.if-js-closed').removeClass('if-js-closed').addClass('closed'); // postboxes setup postboxes.add_postbox_toggles('<?php echo $connections->pageHook->manage; ?> '); }); //]]> </script> <?php unset($entry); } else { $connections->setErrorMessage('capability_edit'); } break; default: $form = new cnFormObjects(); $categoryObjects = new cnCategoryObjects(); /* * Check whether user can view the entry list */ if (current_user_can('connections_view_entry_list')) { ?> <?php $retrieveAttr['list_type'] = $connections->currentUser->getFilterEntryType(); $retrieveAttr['category'] = $connections->currentUser->getFilterCategory(); $retrieveAttr['visibility'] = $connections->currentUser->getFilterVisibility(); $results = $connections->retrieve->entries($retrieveAttr); //print_r($connections->lastQuery); ?> <form action="admin.php?page=connections&action=do" method="post"> <?php $form->tokenField('bulk_action'); ?> <div class="tablenav"> <div class="alignleft actions"> <?php echo '<select class="postform" id="category" name="category">'; echo '<option value="-1">Show All Categories</option>'; echo $categoryObjects->buildCategoryRow('option', $connections->retrieve->categories(), $level, $connections->currentUser->getFilterCategory()); echo '</select>'; echo $form->buildSelect('entry_type', array('all' => 'Show All Enties', 'individual' => 'Show Individuals', 'organization' => 'Show Organizations', 'family' => 'Show Families'), $connections->currentUser->getFilterEntryType()); ?> <?php /* * Builds the visibilty select list base on current user capabilities. */ if (current_user_can('connections_view_public') || $connections->options->getAllowPublic()) { $visibilitySelect['public'] = 'Show Public'; } if (current_user_can('connections_view_private')) { $visibilitySelect['private'] = 'Show Private'; } if (current_user_can('connections_view_unlisted')) { $visibilitySelect['unlisted'] = 'Show Unlisted'; } if (isset($visibilitySelect)) { /* * Add the 'Show All' option and echo the list. */ $showAll['all'] = 'Show All'; $visibilitySelect = $showAll + $visibilitySelect; echo $form->buildSelect('visibility_type', $visibilitySelect, $connections->currentUser->getFilterVisibility()); } ?> <input id="doaction" class="button-secondary action" type="submit" name="filter" value="Filter" /> <input type="hidden" name="formId" value="do_action" /> <input type="hidden" name="token" value="<?php echo $form->token("do_action"); ?> " /> </div> </div> <div class="clear"></div> <div class="tablenav"> <?php if (current_user_can('connections_edit_entry') || current_user_can('connections_delete_entry')) { echo '<div class="alignleft actions">'; echo '<select name="action">'; echo '<option value="" SELECTED>Bulk Actions</option>'; $bulkActions = array(); if (current_user_can('connections_edit_entry')) { $bulkActions['public'] = 'Set Public'; $bulkActions['private'] = 'Set Private'; $bulkActions['unlisted'] = 'Set Unlisted'; } if (current_user_can('connections_delete_entry')) { $bulkActions['delete'] = 'Delete'; } $bulkActions = apply_filters('cn_view_bulk_actions', $bulkActions); foreach ($bulkActions as $action => $string) { echo '<option value="', $action, '">', $string, '</option>'; } echo '</select>'; echo '<input id="doaction" class="button-secondary action" type="submit" name="doaction" value="Apply" />'; echo '</div>'; } ?> <div class="tablenav-pages"> <?php echo '<span class="displaying-num">Displaying ', $connections->resultCount, ' of ', $connections->recordCount, ' records.</span>'; /* * Dynamically builds the alpha index based on the available entries. */ $previousLetter = NULL; $setAnchor = NULL; foreach ($results as $row) { $entry = new cnEntry($row); $currentLetter = strtoupper(mb_substr($entry->getSortColumn(), 0, 1)); if ($currentLetter != $previousLetter) { $setAnchor .= '<a href="#' . $currentLetter . '">' . $currentLetter . '</a> '; $previousLetter = $currentLetter; } } echo $setAnchor; ?> </div> </div> <div class="clear"></div> <table cellspacing="0" class="widefat connections"> <thead> <tr> <th class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"/></th> <th class="col" style="width:10%;"></th> <th scope="col" colspan="2" style="width:40%;">Name</th> <th scope="col" style="width:30%;">Categories</th> <th scope="col" style="width:20%;">Last Modified</th> </tr> </thead> <tfoot> <tr> <th class="manage-column column-cb check-column" scope="col"><input type="checkbox"/></th> <th class="col" style="width:10%;"></th> <th scope="col" colspan="2" style="width:40%;">Name</th> <th scope="col" style="width:30%;">Categories</th> <th scope="col" style="width:20%;">Last Modified</th> </tr> </tfoot> <tbody> <?php foreach ($results as $row) { /** * @TODO: Use the Output class to show entry details. */ $entry = new cnvCard($row); $vCard =& $entry; $currentLetter = strtoupper(mb_substr($entry->getSortColumn(), 0, 1)); if ($currentLetter != $previousLetter) { $setAnchor = "<a name='{$currentLetter}'></a>"; $previousLetter = $currentLetter; } else { $setAnchor = null; } /* * Genreate the edit, copy and delete URLs with nonce tokens. */ $editTokenURL = $form->tokenURL('admin.php?page=connections&action=edit&id=' . $entry->getId(), 'entry_edit_' . $entry->getId()); $copyTokenURL = $form->tokenURL('admin.php?page=connections&action=copy&id=' . $entry->getId(), 'entry_copy_' . $entry->getId()); $deleteTokenURL = $form->tokenURL('admin.php?page=connections&action=delete&id=' . $entry->getId(), 'entry_delete_' . $entry->getId()); echo "<tr id='row-" . $entry->getId() . "' class='parent-row'>"; echo "<th class='check-column' scope='row'><input type='checkbox' value='" . $entry->getId() . "' name='entry[]'/></th> \n"; echo '<td>'; echo $entry->getThumbnailImage(array('place_holder' => TRUE)); echo '</td>'; echo '<td colspan="2">'; if ($setAnchor) { echo $setAnchor; } echo '<div style="float:right"><a href="#wphead" title="Return to top."><img src="' . WP_PLUGIN_URL . '/connections/images/uparrow.gif" /></a></div>'; if (current_user_can('connections_edit_entry')) { echo '<a class="row-title" title="Edit ' . $entry->getFullFirstLastName() . '" href="' . $editTokenURL . '"> ' . $entry->getFullLastFirstName() . '</a><br />'; } else { echo '<strong>' . $entry->getFullLastFirstName() . '</strong>'; } echo '<div class="row-actions">'; echo '<a class="detailsbutton" id="row-' . $entry->getId() . '">Show Details</a> | '; echo $vCard->download(array('anchorText' => 'vCard')) . ' | '; if (current_user_can('connections_edit_entry')) { echo '<a class="editbutton" href="' . $editTokenURL . '" title="Edit ' . $entry->getFullFirstLastName() . '">Edit</a> | '; } if (current_user_can('connections_add_entry')) { echo '<a class="copybutton" href="' . $copyTokenURL . '" title="Copy ' . $entry->getFullFirstLastName() . '">Copy</a> | '; } if (current_user_can('connections_delete_entry')) { echo '<a class="submitdelete" onclick="return confirm(\'You are about to delete this entry. \\\'Cancel\\\' to stop, \\\'OK\\\' to delete\');" href="' . $deleteTokenURL . '" title="Delete ' . $entry->getFullFirstLastName() . '">Delete</a>'; } echo '</div>'; echo "</td> \n"; echo "<td > \n"; $categories = $entry->getCategory(); if (!empty($categories)) { $i = 0; foreach ($categories as $category) { /* * Genreate the category link token URL. */ $categoryFilterURL = $form->tokenURL('admin.php?page=connections&action=filter&category_id=' . $category->term_id, 'filter'); echo '<a href="' . $categoryFilterURL . '">' . $category->name . '</a>'; $i++; if (count($categories) > $i) { echo ', '; } } unset($i); } echo "</td> \n"; echo '<td >'; echo '<strong>On:</strong> ' . $entry->getFormattedTimeStamp('m/d/Y g:ia') . '<br />'; echo '<strong>By:</strong> ' . $entry->getEditedBy() . '<br />'; echo '<strong>Visibility:</strong> ' . $entry->displayVisibiltyType(); echo "</td> \n"; echo "</tr> \n"; echo "<tr class='child-row-" . $entry->getId() . " entrydetails' id='contact-" . $entry->getId() . "-detail' style='display:none;'>"; echo "<td colspan='2' > </td> \n"; //echo "<td > </td> \n"; echo "<td colspan='2'>"; /* * Check if the entry has relations. Count the relations and then cycle thru each relation. * Before the out check that the related entry still exists. If it does and the current user * has edit capabilites the edit link will be displayed. If the user does not have edit capabilities * the only the relation will be shown. After all relations have been output insert a <br> * for spacing [@TODO: NOTE: this should be done with styles]. */ if ($entry->getFamilyMembers()) { $count = count($entry->getFamilyMembers()); $i = 0; foreach ($entry->getFamilyMembers() as $key => $value) { $relation = new cnEntry(); $relation->set($key); $editRelationTokenURL = $form->tokenURL('admin.php?page=connections&action=edit&id=' . $relation->getId(), 'entry_edit_' . $relation->getId()); if ($relation->getId()) { if (current_user_can('connections_edit_entry')) { echo '<strong>' . $connections->options->getFamilyRelation($value) . ':</strong> ' . '<a href="' . $editRelationTokenURL . '" title="Edit ' . $relation->getFullFirstLastName() . '">' . $relation->getFullFirstLastName() . '</a><br />' . "\n"; } else { echo '<strong>' . $connections->options->getFamilyRelation($value) . ':</strong> ' . $relation->getFullFirstLastName() . '<br />' . "\n"; } } if ($count - 1 == $i) { echo '<br />'; } // Insert a break after all connections are listed. $i++; unset($relation); } unset($i); unset($count); } if ($entry->getContactFirstName() || $entry->getContactLastName()) { echo '<strong>Contact:</strong> ' . $entry->getContactFirstName() . ' ' . $entry->getContactLastName() . '<br />'; } if ($entry->getTitle()) { echo '<strong>Title:</strong> ' . $entry->getTitle() . '<br />'; } if ($entry->getOrganization() && $entry->getEntryType() !== 'organization') { echo '<strong>Organization:</strong> ' . $entry->getOrganization() . '<br />'; } if ($entry->getDepartment()) { echo '<strong>Department:</strong> ' . $entry->getDepartment() . '<br />'; } if ($entry->getAddresses()) { foreach ($entry->getAddresses() as $address) { echo "<div style='margin-bottom: 10px;'>"; if ($address->name != NULL || $address->type) { echo "<strong>" . $address->name . "</strong><br />"; } //The OR is for compatiblity for 0.2.24 and under if ($address->line_one != NULL) { echo $address->line_one . "<br />"; } if ($address->line_two != NULL) { echo $address->line_two . "<br />"; } if ($address->city != NULL) { echo $address->city . " "; } if ($address->state != NULL) { echo $address->state . " "; } if ($address->zipcode != NULL) { echo $address->zipcode . "<br />"; } if ($address->country != NULL) { echo $address->country; } echo "</div>"; } } echo "</td> \n"; echo "<td>"; if ($entry->getEmailAddresses()) { foreach ($entry->getEmailAddresses() as $emailRow) { if ($emailRow->address != null) { echo "<strong>" . $emailRow->name . ":</strong><br /><a href='mailto:" . $emailRow->address . "'>" . $emailRow->address . "</a><br /><br />"; } } } if ($entry->getIm()) { foreach ($entry->getIm() as $imRow) { if ($imRow->id != "") { echo "<strong>" . $imRow->name . ":</strong><br />" . $imRow->id . "<br /><br />"; } } } if ($entry->getSocialMedia()) { foreach ($entry->getSocialMedia() as $socialNetwork) { if ($socialNetwork->id != "") { echo "<strong>" . $socialNetwork->name . ":</strong><br /><a target='_blank' href='" . $socialNetwork->url . "'>" . $socialNetwork->url . "</a><br /><br />"; } } } if ($entry->getWebsites()) { foreach ($entry->getWebsites() as $website) { if ($website->url != "") { echo "<strong>Website:</strong><br /><a target='_blank' href='" . $website->url . "'>" . $website->url . "</a><br /><br />"; } } } if ($entry->getPhoneNumbers()) { foreach ($entry->getPhoneNumbers() as $phone) { if ($phone->number != "") { echo "<strong>" . $phone->name . "</strong>: " . $phone->number . "<br />"; } } } echo "</td> \n"; echo "<td>"; if ($entry->getBirthday()) { echo "<strong>Birthday:</strong><br />" . $entry->getBirthday() . "<br /><br />"; } if ($entry->getAnniversary()) { echo "<strong>Anniversary:</strong><br />" . $entry->getAnniversary(); } echo "</td> \n"; echo "</tr> \n"; echo "<tr class='child-row-" . $entry->getId() . " entrynotes' id='contact-" . $entry->getId() . "-detail-notes' style='display:none;'>"; echo "<td colspan='2'> </td> \n"; //echo "<td > </td> \n"; echo "<td colspan='3'>"; if ($entry->getBio()) { echo "<strong>Bio:</strong> " . $entry->getBio() . "<br />"; } else { echo " "; } if ($entry->getNotes()) { echo "<strong>Notes:</strong> " . $entry->getNotes(); } else { echo " "; } echo "</td> \n"; echo '<td> <strong>Entry ID:</strong> ' . $entry->getId() . '<br />' . ' <strong>Date Added:</strong> ' . $entry->getDateAdded('m/d/Y g:ia') . '<br /> <strong>Added By:</strong> ' . $entry->getAddedBy() . '<br />'; if (!$entry->getImageLinked()) { echo "<br /><strong>Image Linked:</strong> No"; } else { echo "<br /><strong>Image Linked:</strong> Yes"; } if ($entry->getImageLinked() && $entry->getImageDisplay()) { echo "<br /><strong>Display:</strong> Yes"; } else { echo "<br /><strong>Display:</strong> No"; } echo "</td> \n"; echo "</tr> \n"; } ?> </tbody> </table> </form> <p style="font-size:smaller; text-align:center">This is version <?php echo $connections->options->getVersion(), '-', $connections->options->getDBVersion(); ?> of Connections.</p> <form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="text-align:center"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="5070255"> <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> <script type="text/javascript"> /* <![CDATA[ */ (function($){ $(document).ready(function(){ $('#doaction, #doaction2').click(function(){ if ( $('select[name^="action"]').val() == 'delete' ) { var m = 'You are about to delete the selected entry(ies).\n \'Cancel\' to stop, \'OK\' to delete.'; return showNotice.warn(m); } }); }); })(jQuery); /* ]]> */ </script> <?php } else { $connections->setErrorMessage('capability_view_entry_list'); } break; } ?> </div> <?php }
* @website: http://llihp.blogspot.com * * @todo : * -Add Link to personal profile in popup for each member displayed, NOT FOR MOBILE VIEWING */ if (sizeof($entry->getFamilyMembers()) > 0) { // Get the plugins dir URL for the site $plugindir = get_bloginfo('wpurl') . '/wp-content/plugins'; // create the div $member_listing = '<div class="member-entry">'; $mobile_member_listing = '<div class="member-entry">'; // Info Div header $member_listing .= '<div><span class="member-details"><strong>'; $mobile_member_listing .= '<div><span class="member-details"><strong>'; // create family member $member_group = new cnEntry(); // Create the popup container //$member_popup_info = '<div id="popup-group-name"><span>' . $entry->getFamilyName() . '</span></div>'; // Set a counter $counter = 0; foreach ($entry->getFamilyMembers() as $key_member_group => $value_member_group) { // Increment $counter++; // Set family member id $member_group->set($key_member_group); if ($counter > 1) { $member_list_first_names .= ", " . $member_group->getFirstName(); } else { $member_list_first_names = $member_group->getFirstName(); } }
/** * Delete one or more entries. * * @access private * @since 0.7.8 * * @uses Connections_Directory() * @uses wp_parse_id_list() * @uses cnRetrieve::entry() * @uses cnEntry::delete() * @uses do_action() * * @param mixed $ids array|int The entry IDs to delete. * * @return bool */ public static function delete($ids) { // Grab an instance of the Connections object. $instance = Connections_Directory(); // Make sure $id is not empty. if (empty($ids)) { return FALSE; } // Check for and convert to an array. $ids = wp_parse_id_list($ids); foreach ($ids as $id) { $entry = new cnEntry($instance->retrieve->entry($id)); $entry->delete($id); // Delete any meta data associated with the entry. self::meta('delete', $id); } /** * Action fired after entries are bulk deleted. * * @since 8.2.5 * * @param array $ids An array of entry IDs that were deleted. */ do_action('cn_process_bulk_delete', $ids); return TRUE; }
/** * Function for displaying the widget on the page. * * @access private * @since 1.0 * * @param array $args * @param array $option * * @return string */ public function widget($args, $option) { // Only process and display the widget if displaying a single entry. if (get_query_var('cn-entry-slug')) { // Grab an instance of the Connections object. $instance = Connections_Directory(); // Query the entry. $result = $instance->retrieve->entries(array('slug' => urldecode(get_query_var('cn-entry-slug')))); // Setup the entry object $entry = new cnEntry($result[0]); // Query the entry meta. $metadata = $entry->getMeta(array('key' => 'hobbies', 'single' => TRUE)); // If there is no meta; bail. if (empty($metadata)) { return; } /** * Extract $before_widget, $after_widget, $before_title and $after_title. * * @var $before_widget * @var $after_widget * @var $before_title * @var $after_title */ extract($args); // Setup the default widget options if they were not set when they were added to the sidebar; // ie. the user did not click the "Save" button on the widget. $title = strlen($option['title']) > 0 ? $option['title'] : __('Hobbies', 'connections_hobbies'); // Setup the atts to be passed to the method that displays the data. $atts = array(); echo $before_widget; echo $before_title . $title . $after_title; // Display the income level. Connections_Hobbies::block('hobbies', $metadata, NULL, $atts); echo $after_widget; } }
/** * Save the doubles team. */ public function save(&$Error = null) { // Load existing data $this->load(); // Determine if we are creating or updating if (isset($this->cnData->id)) { // Use the existing entry $entry = new cnEntry($this->cnData); $entry->setEntryType($this->cnData->entry_type); } else { // Initialize the new entry $entry = new cnEntry(); $entry->setFamilyName($this->familyName); $entry->setEntryType('family'); $entry->setVisibility('private'); $entry->setStatus('approved'); // Add the family members $family = array(); foreach ($this->familyMembers as $player) { $id = $player->getId(); if (!$id) { $player->save(); $id = $player->getId(); } $family[] = array('entry_id' => $id, 'relation' => 'partner'); } $entry->setFamilyMembers($family); // Save the entry if ($entry->save() && $this->getId() === null) { global $connections; $this->cnData->id = $connections->lastInsertID; $isNew = true; } else { $isNew = false; } // Update meta data $meta = array(); foreach ($this->cnMeta as $name => $value) { $meta[] = array('key' => $name, 'value' => $value); } if (count($meta)) { cnEntry_Action::meta($isNew ? 'add' : 'update', $this->getId(), $meta); } } return true; }