/** * Returns whether or not their is image editor support. * * @todo Nonfunctional method needs completed. * * @access public * @since 8.1 * @static * * @return bool|void */ public static function checkEditorSupport() { if (!is_admin()) { return; } $atts = array('mime_type' => 'image/jpeg'); if (wp_image_editor_supports($atts) !== TRUE) { cnMessage::create('error', 'image_edit_support_failed'); } return TRUE; }
/** * Callback for the cn_delete_log hook which processes the delete action and then redirects back to the current admin page. * * @access private * @since 8.3 * @static * * @uses current_user_can() * @uses check_admin_referer() * @uses cnLog::delete() * @uses cnMessage::set() * @uses add_query_arg() * @uses wp_get_referer() * @uses wp_safe_redirect() */ public static function deleteLog() { if (current_user_can('install_plugins')) { $id = 0; if (isset($_GET['id']) && !empty($_GET['id'])) { $id = absint($_GET['id']); } check_admin_referer('log_delete_' . $id); cnLog::delete($id); cnMessage::set('success', 'log_delete'); $url = add_query_arg(array('type' => isset($_GET['type']) && !empty($_GET['type']) && '-1' !== $_GET['type'] ? $_GET['type'] : FALSE), wp_get_referer()); wp_safe_redirect($url); exit; } }
/** * Store a success code. * This is a deprecated helper function left in place until all instances of it are removed from the code base. * * @access public * @since unknown * @deprecated 0.7.5 * * @param $code string * * @return void */ public function setSuccessMessage($code) { cnMessage::set('success', $code); }
/** * Deletes the category from the database via the cnTerm class. * * @return bool The success or error message. */ public function delete() { $default = get_option('cn_default_category'); if ($this->id == $default) { cnMessage::set('error', 'category_delete_default'); return FALSE; } $result = cnTerm::delete($this->id, 'category'); if (is_wp_error($result)) { cnMessage::set('error', $result->get_error_message()); return FALSE; } else { cnMessage::set('success', 'category_deleted'); return TRUE; } }
/** * Display the database upgrade notice. This will only be shown on non-Connections pages. * * @access private * @since 0.7.5 * @uses get_current_screen() * @return (void) */ public static function displayDBUpgradeNotice() { // Grab an instance of the Connections object. $instance = Connections_Directory(); $screen = get_current_screen(); if (!in_array($screen->id, (array) $instance->pageHook)) { cnMessage::create('notice', 'db_update_required'); } }
/** * Setup the current user ID. * * @access private * @since 0.7.5 * @uses wp_get_current_user() * @return int */ private static function setUserID() { if (!isset(self::$id)) { // Setup the current user object $current_user = wp_get_current_user(); self::$id = $current_user->ID; } return self::$id; }
/** * Echo or return the image/logo if associated in a HTML hCard compliant string. * * Accepted option for the $atts property are: * image (string) Select the image to display. Valid values are photo || logo * preset (string) Select one of the predefined image sizes Must be used in conjunction with the 'image' option. Valid values are thumbnail || entry || profile * fallback (array) Object to be shown when there is no image or logo. * type (string) Fallback type. Valid values are; none || default || block * string (string) The string used with the block fallback * height (int) Block height. [Required if a image custom size was set.] * width (int) Block width. * height (int) Override the values saved in the settings. [Required if providing custom size.] * width (int) Override the values saved in the settings. * zc (int) Crop format * 0 Resize to Fit specified dimensions (no cropping) * 1 Crop and resize to best fit the dimensions (default behaviour) * 2 Resize proportionally to fit entire image into specified dimensions, and add borders if required * 3 Resize proportionally adjusting size of scaled image so there are no borders gaps * before (string) HTML to output before the image * after (string) HTML to after before the image * style (array) Customize an inline stlye tag for the image or the placeholder block. Array format key == attribute; value == value. * return (bool) Return or echo the string. Default is to echo. * * NOTE: If only the height or width was set for a custom image size, the opposite image dimension must be set for * the fallback block. This does not apply if the fallback is the default image. * * Filters: * cn_output_default_atts_image => (array) Register the methods default attributes. * cn_output_image => (string) The output string, (array) The $atts. * * @todo Enable support for a default image to be set. * * @access public * @since unknown * @version 1.0 * @param array $atts [optional] * @return string */ public function getImage($atts = array()) { $displayImage = FALSE; $cropModes = array(0 => 'none', 1 => 'crop', 2 => 'fill', 3 => 'fit'); $targetOptions = array('new' => '_blank', 'same' => '_self'); $tag = array(); $srcset = array(); $anchorStart = ''; $out = ''; /* * // START -- Set the default attributes array. \\ */ $defaults = array('image' => 'photo', 'preset' => 'entry', 'fallback' => array('type' => 'none', 'string' => '', 'height' => 0, 'width' => 0), 'width' => 0, 'height' => 0, 'zc' => 1, 'quality' => 80, 'before' => '', 'after' => '', 'sizes' => array('100vw'), 'style' => array(), 'action' => 'display', 'return' => FALSE); $defaults = apply_filters('cn_output_default_atts_image', $defaults); $atts = cnSanitize::args($atts, $defaults); if (isset($atts['fallback']) && is_array($atts['fallback'])) { $atts['fallback'] = cnSanitize::args($atts['fallback'], $defaults['fallback']); } /* * // END -- Set the default attributes array if not supplied. \\ */ /* * The $atts key that are not image tag attributes. */ $nonAtts = array('action', 'image', 'preset', 'fallback', 'image_size', 'zc', 'quality', 'before', 'after', 'style', 'return'); $customSize = !empty($atts['height']) || !empty($atts['width']) ? TRUE : FALSE; switch ($atts['image']) { case 'photo': if ($this->getImageLinked() && ($this->getImageDisplay() || 'edit' == $atts['action'])) { $displayImage = TRUE; $atts['class'] = 'cn-image photo'; $atts['alt'] = sprintf(__('Photo of %s', 'connections'), $this->getName()); $atts['title'] = sprintf(__('Photo of %s', 'connections'), $this->getName()); $atts['alt'] = apply_filters('cn_photo_alt', $atts['alt'], $this); $atts['title'] = apply_filters('cn_photo_title', $atts['title'], $this); if ($customSize) { $image = $this->getImageMeta(array('type' => 'photo', 'size' => 'custom', 'crop_mode' => $atts['zc'], 'width' => $atts['width'], 'height' => $atts['height'], 'quality' => $atts['quality'])); if (is_wp_error($image)) { if (is_admin()) { cnMessage::render('error', implode('<br />', $image->get_error_messages())); } $displayImage = FALSE; } else { // Since this is a custom size of an image we can not know which crop mode to use. // Set the crop mode the the value set in $atts['zc']. $cropMode = $atts['zc']; // Add the image to the scrset. $srcset['image_custom'] = array('src' => $image['url'], 'width' => '1x'); $atts['width'] = $image['width']; $atts['height'] = $image['height']; } } else { $preset = array('thumbnail' => 'thumbnail', 'medium' => 'entry', 'large' => 'profile'); if ($size = array_search($atts['preset'], $preset)) { $image = $this->getImageMeta(array('type' => 'photo', 'size' => $size)); if (is_wp_error($image)) { if (is_admin()) { cnMessage::render('error', implode('<br />', $image->get_error_messages())); } $displayImage = FALSE; } else { // Set the crop mode to the value saved in the settings. $cropMode = ($key = array_search(cnSettingsAPI::get('connections', "image_{$size}", 'ratio'), $cropModes)) || $key === 0 ? $key : 2; // Add the image to the scrset. $srcset['image_' . $size] = array('src' => $image['url'], 'width' => '1x'); $atts['width'] = $image['width']; $atts['height'] = $image['height']; } } else { $displayImage = FALSE; $atts['fallback']['type'] = 'block'; $atts['fallback']['string'] = sprintf(__('Photo present %s is not valid.', 'connections'), $size); } } } /* * Create the link for the image if one was assigned. */ $links = $this->getLinks(array('image' => TRUE)); if (!empty($links)) { $link = $links[0]; $target = array_key_exists($link->target, $targetOptions) ? $targetOptions[$link->target] : '_self'; $anchorStart = sprintf('<a href="%1$s"%2$s%3$s>', esc_url($link->url), empty($target) ? '' : ' target="' . $target . '"', empty($link->followString) ? '' : ' rel="' . $link->followString . '"'); } break; case 'logo': if ($this->getLogoLinked() && ($this->getLogoDisplay() || 'edit' == $atts['action'])) { $displayImage = TRUE; $atts['class'] = 'cn-image logo'; $atts['alt'] = sprintf(__('Logo for %s', 'connections'), $this->getName()); $atts['title'] = sprintf(__('Logo for %s', 'connections'), $this->getName()); $cropMode = ($key = array_search(cnSettingsAPI::get('connections', 'image_logo', 'ratio'), $cropModes)) || $key === 0 ? $key : 2; $atts['alt'] = apply_filters('cn_logo_alt', $atts['alt'], $this); $atts['title'] = apply_filters('cn_logo_title', $atts['title'], $this); if ($customSize) { $image = $this->getImageMeta(array('type' => 'logo', 'size' => 'custom', 'crop_mode' => $atts['zc'], 'width' => $atts['width'], 'height' => $atts['height'], 'quality' => $atts['quality'])); if (is_wp_error($image)) { if (is_admin()) { cnMessage::render('error', implode('<br />', $image->get_error_messages())); } $displayImage = FALSE; } else { // Add the image to the scrset. $srcset['logo_custom'] = array('src' => esc_url($image['url']), 'width' => '1x'); $atts['width'] = $image['width']; $atts['height'] = $image['height']; } } else { $image = $this->getImageMeta(array('type' => 'logo', 'size' => 'scaled')); if (is_wp_error($image)) { if (is_admin()) { cnMessage::render('error', implode('<br />', $image->get_error_messages())); } $displayImage = FALSE; } else { // Add the image to the scrset. $srcset['logo'] = array('src' => esc_url($image['url']), 'width' => '1x'); $atts['width'] = $image['width']; $atts['height'] = $image['height']; } } } /* * Create the link for the image if one was assigned. */ $links = $this->getLinks(array('logo' => TRUE)); if (!empty($links)) { $link = $links[0]; $target = array_key_exists($link->target, $targetOptions) ? $targetOptions[$link->target] : '_self'; $anchorStart = sprintf('<a href="%1$s"%2$s%3$s>', esc_url($link->url), empty($target) ? '' : ' target="' . $target . '"', empty($link->followString) ? '' : ' rel="' . $link->followString . '"'); } break; } if ($displayImage) { // Allow extension to filter the img class. $atts['class'] = apply_filters('cn_image_class', $atts['class']); // Add the 2x (retina) image to the srcset. /*$srcset['2x'] = array( 'src' => add_query_arg( array( CN_IMAGE_ENDPOINT => $wp_rewrite->using_permalinks() ? FALSE : TRUE, 'src' => $this->getOriginalImageURL( $atts['image'] ), 'cn-entry-slug' => $this->getSlug(), 'w' => $image['width'] * 2, 'h' => $atts['height'] * 2, 'zc' => $cropMode, ), ( $wp_rewrite->using_permalinks() ? home_url( CN_IMAGE_ENDPOINT ) : home_url() ) ), 'width' => '2x' );*/ // Allow extensions to add/remove images to the srcset. $srcset = apply_filters('cn_image_srcset', $srcset); foreach ($srcset as $src) { $atts['srcset'][] = implode(' ', $src); } $atts['srcset'] = implode(', ', $atts['srcset']); // Allow extensions to add/remove sizes media queries. $atts['sizes'] = apply_filters('cn_image_sizes', $atts['sizes']); $atts['sizes'] = implode(', ', $atts['sizes']); // Remove any values in the $atts array that not not img attributes and add those that are to the $tag array. foreach ($atts as $attr => $value) { if (!empty($value) && !in_array($attr, $nonAtts)) { $tag[] = "{$attr}=\"{$value}\""; } } // All extensions to apply/remove inline styles. $atts['style'] = apply_filters('cn_image_styles', $atts['style']); if (is_array($atts['style']) && !empty($atts['style'])) { array_walk($atts['style'], create_function('&$i, $property', '$i = "$property: $i";')); } // The inner <span> is required for responsive image support. This markup also makes it IE8 compatible. $out = sprintf('<span class="cn-image-style"><span style="display: block; max-width: 100%%; width: %2$spx">%3$s<img %4$s%1$s/>%5$s</span></span>', empty($atts['style']) ? '' : ' style="' . implode('; ', $atts['style']) . ';"', absint($image['width']), empty($anchorStart) ? '' : $anchorStart, implode(' ', $tag), empty($anchorStart) ? '' : '</a>'); } else { if ($customSize) { /* * Set the size to the supplied custom. The fallback custom size would take priority if it has been supplied. */ $atts['style']['width'] = empty($atts['fallback']['width']) ? $atts['width'] . 'px' : $atts['fallback']['width'] . 'px'; $atts['style']['height'] = empty($atts['fallback']['height']) ? $atts['height'] . 'px' : $atts['fallback']['height'] . 'px'; } else { /* * If a custom size was not set, use the dimensions saved in the settings. */ switch ($atts['image']) { case 'photo': switch ($atts['preset']) { case 'entry': $atts['style']['width'] = cnSettingsAPI::get('connections', 'image_medium', 'width') . 'px'; $atts['style']['height'] = cnSettingsAPI::get('connections', 'image_medium', 'height') . 'px'; break; case 'profile': $atts['style']['width'] = cnSettingsAPI::get('connections', 'image_large', 'width') . 'px'; $atts['style']['height'] = cnSettingsAPI::get('connections', 'image_large', 'height') . 'px'; break; case 'thumbnail': $atts['style']['width'] = cnSettingsAPI::get('connections', 'image_thumbnail', 'width') . 'px'; $atts['style']['height'] = cnSettingsAPI::get('connections', 'image_thumbnail', 'height') . 'px'; break; default: $atts['style']['width'] = cnSettingsAPI::get('connections', 'image_medium', 'width') . 'px'; $atts['style']['height'] = cnSettingsAPI::get('connections', 'image_medium', 'height') . 'px'; break; } break; case 'logo': $atts['style']['width'] = cnSettingsAPI::get('connections', 'image_logo', 'width') . 'px'; $atts['style']['height'] = cnSettingsAPI::get('connections', 'image_logo', 'height') . 'px'; break; } } switch ($atts['fallback']['type']) { case 'block': $atts['style']['display'] = 'inline-block'; if (is_array($atts['style']) && !empty($atts['style'])) { array_walk($atts['style'], create_function('&$i, $property', '$i = "$property: $i";')); } $string = empty($atts['fallback']['string']) ? '' : '<span>' . $atts['fallback']['string'] . '</span>'; $out = sprintf('<span class="cn-image-style" style="display: inline-block;"><span class="cn-image-%1$s cn-image-none"%2$s>%3$s</span></span>', esc_attr($atts['image']), empty($atts['style']) ? '' : ' style="' . implode('; ', $atts['style']) . ';"', $string); break; case 'default': /* * @TODO Enable support for a default image to be set. * NOTE: Use switch for image type to allow a default image for both the image and logo. */ break; } } $out = apply_filters('cn_output_image', $out, $atts, $this); $out = $atts['before'] . $out . $atts['after'] . PHP_EOL; return $this->echoOrReturn($atts['return'], $out); }
/** * Add / Edit / Copy an entry. * * @access private * @since 0.7.8 * * @uses absint() * * @param string $action Valid options are: add | update * @param array $data [optional] The data to be used when adding / editing / duplicating an entry. * @param int $id [optional] If editing/duplicating an entry, the entry ID. * * @return bool */ private static function process($action, $data = array(), $id = 0) { global $connections; /** @var cnEntry $entry */ $entry = new cnEntry(); // If copying/editing an entry, the entry data is loaded into the class // properties and then properties are overwritten by the data as needed. if (!empty($id)) { $entry->set(absint($id)); } if (isset($data['entry_type'])) { $entry->setEntryType($data['entry_type']); } if (isset($data['family_name'])) { $entry->setFamilyName($data['family_name']); } isset($data['family_member']) ? $entry->setFamilyMembers($data['family_member']) : $entry->setFamilyMembers(array()); if (isset($data['honorific_prefix'])) { $entry->setHonorificPrefix($data['honorific_prefix']); } if (isset($data['first_name'])) { $entry->setFirstName($data['first_name']); } if (isset($data['middle_name'])) { $entry->setMiddleName($data['middle_name']); } if (isset($data['last_name'])) { $entry->setLastName($data['last_name']); } if (isset($data['honorific_suffix'])) { $entry->setHonorificSuffix($data['honorific_suffix']); } if (isset($data['title'])) { $entry->setTitle($data['title']); } if (isset($data['organization'])) { $entry->setOrganization($data['organization']); } if (isset($data['department'])) { $entry->setDepartment($data['department']); } if (isset($data['contact_first_name'])) { $entry->setContactFirstName($data['contact_first_name']); } if (isset($data['contact_last_name'])) { $entry->setContactLastName($data['contact_last_name']); } isset($data['address']) ? $entry->setAddresses($data['address']) : $entry->setAddresses(array()); isset($data['phone']) ? $entry->setPhoneNumbers($data['phone']) : $entry->setPhoneNumbers(array()); isset($data['email']) ? $entry->setEmailAddresses($data['email']) : $entry->setEmailAddresses(array()); isset($data['im']) ? $entry->setIm($data['im']) : $entry->setIm(array()); isset($data['social']) ? $entry->setSocialMedia($data['social']) : $entry->setSocialMedia(array()); //( isset($data['website']) ) ? $entry->setWebsites($data['website']) : $entry->setWebsites( array() ); isset($data['link']) ? $entry->setLinks($data['link']) : $entry->setLinks(array()); isset($data['date']) ? $entry->setDates($data['date']) : $entry->setDates(array()); if (isset($data['birthday_day']) && isset($data['birthday_month'])) { $entry->setBirthday($data['birthday_day'], $data['birthday_month']); } if (isset($data['anniversary_day']) && isset($data['anniversary_month'])) { $entry->setAnniversary($data['anniversary_day'], $data['anniversary_month']); } if (isset($data['bio'])) { $entry->setBio($data['bio']); } if (isset($data['notes'])) { $entry->setNotes($data['notes']); } if (isset($data['visibility'])) { $entry->setVisibility($data['visibility']); } isset($data['user']) ? $entry->setUser($data['user']) : $entry->setUser(0); switch ($action) { case 'add': // If the entry is being copied, the source slug needs copied because it is required // in order to copy the source entry images to the new entry. if (!empty($id)) { $sourceEntrySlug = rawurldecode($entry->getSlug()); $entry->setSlug($entry->getName(array('format' => '%first%-%last%'))); // If a new entry is being added, set the unique slug. } else { $entry->setSlug($entry->getName(array('format' => '%first%-%last%'))); } break; case 'update': // If an entry is being edited, set the new slug, if a new slug was provided. if (isset($data['slug']) && $data['slug'] != $entry->getSlug()) { $entry->setSlug($data['slug']); } break; } $slug = rawurldecode($entry->getSlug()); // Run any registered filters before processing, passing the $entry object. // ? Should the logo, photo and category data be passed too? $entry = apply_filters('cn_pre_process_' . $action . '-entry', $entry, isset($data['entry_category']) ? $data['entry_category'] : array()); /* * Process the logo upload --> START <-- */ if (isset($_FILES['original_logo']) && $_FILES['original_logo']['error'] != 4) { // If an entry is being updated and a new logo is uploaded, the old logo needs to be deleted. // Delete the entry logo. self::deleteImages($entry->getLogoName(), $slug); // Delete logo the legacy logo, pre 8.1. self::deleteLegacyLogo($entry); // Process the newly uploaded image. $result = self::processLogo($slug); // If there were no errors processing the logo, set the values. if ($result) { $entry->setLogoLinked(TRUE); $entry->setLogoDisplay(TRUE); $entry->setLogoName($result['name']); $entry->setOriginalLogoMeta($result); } else { $entry->setLogoLinked(FALSE); $entry->setLogoDisplay(FALSE); } } // Don't do this if an entry is being updated. if ($action !== 'update') { // If an entry is being copied and there is a logo, the logo will be duplicated for the new entry. // That way if an entry is deleted, only the entry specific logo will be deleted. if ($entry->getLogoName() != NULL && (isset($sourceEntrySlug) && !empty($sourceEntrySlug))) { self::copyImages($entry->getLogoName(), $sourceEntrySlug, $slug); } } /* * If copying an entry, the logo visibility property is set based on the user's choice. * NOTE: This must come after the logo processing. */ if (isset($data['logoOptions'])) { switch ($data['logoOptions']) { case 'remove': $entry->setLogoDisplay(FALSE); $entry->setLogoLinked(FALSE); // Delete the entry image and its variations. self::deleteImages($entry->getLogoName(), $slug); // Delete logo the legacy logo, pre 8.1. self::deleteLegacyLogo($entry); $entry->setLogoName(NULL); break; case 'hidden': $entry->setLogoDisplay(FALSE); break; case 'show': $entry->setLogoDisplay(TRUE); break; default: $entry->setLogoDisplay(FALSE); break; } } /* * Process the logo upload --> END <-- */ /* * Process the image upload. --> START <-- */ if (isset($_FILES['original_image']) && $_FILES['original_image']['error'] != 4) { // Delete the entry image and its variations. self::deleteImages($entry->getImageNameOriginal(), $slug); // Delete any legacy images, pre 8.1, that may exist. self::deleteLegacyImages($entry); // Process the newly uploaded image. $result = self::processImage($slug); // If there were no errors processing the image, set the values. if ($result) { $entry->setImageLinked(TRUE); $entry->setImageDisplay(TRUE); $entry->setImageNameOriginal($result['image_names']['original']); $entry->setOriginalImageMeta($result['image']['original']['meta']); } else { $entry->setImageLinked(FALSE); $entry->setImageDisplay(FALSE); } } // Don't do this if an entry is being updated. if ($action !== 'update') { // If an entry is being copied and there is an image, the image will be duplicated for the new entry. // That way if an entry is deleted, only the entry specific images will be deleted. if ($entry->getImageNameOriginal() != NULL && (isset($sourceEntrySlug) && !empty($sourceEntrySlug))) { self::copyImages($entry->getImageNameOriginal(), $sourceEntrySlug, $slug); } } // If copying an entry, the image visibility property is set based on the user's choice. // NOTE: This must come after the image processing. if (isset($data['imgOptions'])) { switch ($data['imgOptions']) { case 'remove': $entry->setImageDisplay(FALSE); $entry->setImageLinked(FALSE); // Delete the entry image and its variations. self::deleteImages($entry->getImageNameOriginal(), $slug); // Delete any legacy images, pre 8.1, that may exist. self::deleteLegacyImages($entry); $entry->setImageNameOriginal(NULL); break; case 'hidden': $entry->setImageDisplay(FALSE); break; case 'show': $entry->setImageDisplay(TRUE); break; default: $entry->setImageDisplay(FALSE); break; } } /* * Process the image upload. --> END <-- */ switch ($action) { case 'add': // Set moderation status per role capability assigned to the current user. if (current_user_can('connections_add_entry')) { $entry->setStatus('approved'); $messageID = 'entry_added'; } elseif (current_user_can('connections_add_entry_moderated')) { $entry->setStatus('pending'); $messageID = 'entry_added_moderated'; } else { $entry->setStatus('pending'); $messageID = 'entry_added_moderated'; } // Save the entry to the database. On fail store error message. if ($entry->save() == FALSE) { cnMessage::set('error', 'entry_added_failed'); return FALSE; } else { cnMessage::set('success', $messageID); $entryID = (int) $connections->lastInsertID; $entry->setID($entryID); } break; case 'update': // Set moderation status per role capability assigned to the current user. if (current_user_can('connections_edit_entry')) { if ($entry->getStatus() == 'pending' && current_user_can('connections_add_entry_moderated')) { $entry->setStatus('pending'); $messageID = 'entry_updated_moderated'; } elseif ($entry->getStatus() == 'approved' && current_user_can('connections_add_entry_moderated')) { $entry->setStatus('approved'); $messageID = 'entry_updated'; } elseif ($entry->getStatus() == 'pending' && current_user_can('connections_add_entry')) { $entry->setStatus('approved'); $messageID = 'entry_updated'; } elseif ($entry->getStatus() == 'approved' && current_user_can('connections_add_entry')) { $entry->setStatus('approved'); $messageID = 'entry_updated'; } else { // $entry->setStatus( 'pending' ); // $messageID = 'entry_updated_moderated'; $messageID = 'entry_updated'; } } elseif (current_user_can('connections_edit_entry_moderated')) { $entry->setStatus('pending'); $messageID = 'entry_updated_moderated'; } else { $entry->setStatus('pending'); $messageID = 'entry_updated_moderated'; } // Update the entry to the database. On fail store error message. if ($entry->update() == FALSE) { cnMessage::set('error', 'entry_updated_failed'); return FALSE; } else { cnMessage::set('success', $messageID); $entryID = (int) $entry->getId(); } break; } do_action('cn_process_taxonomy-category', $action, $entryID); do_action('cn_process_meta-entry', $action, $entryID); // Refresh the cnEntry object with any updated taxonomy or meta data // that may have been added/updated via actions. $entry->set($entryID); // Run any registered post process actions. do_action("cn_post_process_{$action}-entry", $entry); return $entryID; }
/** * Deletes the category from the database via the cnTerm class. * * @return bool The success or error message. */ public function delete() { // @todo Add option for user to set the default category, which should not be able to be deleted. //$defaults['default'] = get_option( 'cn_default_category' ); // Temporarily hard code the default category to the Uncategorized category // and ensure it can not be deleted. This should be removed when the default // category can be set by the user. $default_category = cnTerm::getBy('slug', 'uncategorized', 'category'); $defaults['default'] = $default_category->term_id; // Do not change the default category. // This should be able to be removed after the user configurable default category is implemented. if ($this->id == $default_category->term_id) { cnMessage::set('error', 'category_delete_uncategorized'); return FALSE; } $result = cnTerm::delete($this->id, 'category'); if (is_wp_error($result)) { cnMessage::set('error', $result->get_error_message()); return FALSE; } else { cnMessage::set('success', 'category_deleted'); return TRUE; } }
/** * Caches the dates for use and preps for saving and updating. * * Valid values as follows. * * $date['id'] (int) Stores the date ID if it was retrieved from the db. * $date['preferred'] (bool) If the date is the preferred date or not. * $date['type'] (string) Stores the date type. * $date['date'] (string) Stores date. * $date['visibility'] (string) Stores the date visibility. * * @TODO Consider using strtotime on $date['date'] to help ensure date_create() does not return FALSE. * * @access public * @since 0.7.3 * @version 1.0 * @param array $dates * @return void */ public function setDates($dates) { $userPreferred = NULL; /* * These will be used to store the first anniversary and birthday entered by the user. */ $anniversary = array(); $birthday = array(); $validFields = array('id' => NULL, 'preferred' => NULL, 'type' => NULL, 'date' => NULL, 'visibility' => NULL); if (!empty($dates)) { $order = 0; $preferred = ''; if (isset($dates['preferred'])) { $preferred = $dates['preferred']; unset($dates['preferred']); } foreach ($dates as $key => $date) { // First validate the supplied data. $date = cnSanitize::args($date, $validFields); // If the date is empty, no need to store it. if (empty($date['date'])) { unset($dates[$key]); continue; } // Store the order attribute as supplied in the date array. $dates[$key]['order'] = $order; isset($preferred) && $preferred == $key ? $dates[$key]['preferred'] = TRUE : ($dates[$key]['preferred'] = FALSE); /* * If the user set a preferred date, save the $key value. * This is going to be needed because if a date that the user * does not have permission to edit is set to preferred, that date * will have preference. */ if ($dates[$key]['preferred']) { $userPreferred = $key; } /* * Format the supplied date correctly for the table column: YYYY-MM-DD * @TODO Consider using strtotime on $date['date'] to help ensure date_create() does not return FALSE. */ $currentDate = date_create($date['date']); /* * Make sure the date object created correctly. */ if (FALSE === $currentDate) { continue; } $dates[$key]['date'] = date_format($currentDate, 'Y-m-d'); /* * Check to see if the date is an anniversary or birthday and store them. * These will then be sent and saved using the legacy methods for backward compatibility * with version 0.7.2.6 and older. */ switch ($date['type']) { case 'anniversary': if (empty($anniversary)) { $anniversary['month'] = date_format($currentDate, 'm'); $anniversary['day'] = date_format($currentDate, 'd'); $this->setAnniversary($anniversary['day'], $anniversary['month']); } break; case 'birthday': if (empty($birthday)) { $birthday['month'] = date_format($currentDate, 'm'); $birthday['day'] = date_format($currentDate, 'd'); $this->setBirthday($birthday['day'], $birthday['month']); } break; } $order++; } } /* * If no anniversary or birthday date types were set, ensure the dates stored are emptied * for backward compatibility with version 0.7.2.6 and older. */ if (empty($anniversary)) { $this->anniversary = ''; } if (empty($birthday)) { $this->birthday = ''; } /* * Before storing the data, add back into the array from the cache the dates * the user may not have had permission to edit so the cache stays current. */ $cached = unserialize($this->dates); if (!empty($cached)) { foreach ($cached as $date) { /* * // START -- Compatibility for previous versions. */ if (!isset($date['visibility']) || empty($date['visibility'])) { $date['visibility'] = 'public'; } /* * // END -- Compatibility for previous versions. */ /** This filter is documented in ../includes/entry/class.entry-data.php */ $date = apply_filters('cn_date-pre_setup', $date); if (!$this->validate->userPermitted($date['visibility'])) { //$dates[] = $date; // If the date is preferred, it takes precedence, so the user's choice is overridden. if (!empty($preferred) && $date['preferred']) { $dates[$userPreferred]['preferred'] = FALSE; // Throw the user a message so they know why their choice was overridden. cnMessage::set('error', 'entry_preferred_overridden_date'); } } } } $this->dates = !empty($dates) ? serialize($dates) : ''; }
/** * Reset any messages stored in the user's meta. * This is a deprecated helper function left in place until all instances of it are removed from the code base. * * @access public * @since unknown * @deprecated 0.7.6 * @return (void) */ public function resetMessages() { cnMessage::reset(); }
/** * Update the role settings. * * @access private * @since 0.7.5 * @uses current_user_can() * @uses check_admin_referer() * @uses wp_redirect() * @uses get_admin_url() * @uses get_current_blog_id() * @return void */ public static function updateRoleCapabilities() { /** @var $wp_roles WP_Roles */ global $wp_roles; $form = new cnFormObjects(); /* * Check whether user can edit roles */ if (current_user_can('connections_change_roles')) { check_admin_referer($form->getNonce('update_role_settings'), '_cn_wpnonce'); if (isset($_POST['roles'])) { // Cycle thru each role available because checkboxes do not report a value when not checked. foreach ($wp_roles->get_names() as $role => $name) { if (!isset($_POST['roles'][$role])) { continue; } foreach ($_POST['roles'][$role]['capabilities'] as $capability => $grant) { // the admininistrator should always have all capabilities if ($role == 'administrator') { continue; } if ($grant == 'true') { cnRole::add($role, $capability); } else { cnRole::remove($role, $capability); } } } } if (isset($_POST['reset'])) { cnRole::reset($_POST['reset']); } if (isset($_POST['reset_all'])) { cnRole::reset(); } cnMessage::set('success', 'role_settings_updated'); wp_redirect(get_admin_url(get_current_blog_id(), 'admin.php?page=connections_roles')); exit; } else { cnMessage::set('error', 'capability_roles'); } }
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 -->'; }