/** * Update a category. * * @access public * @since 0.7.7 * @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 updateCategory() { $form = new cnFormObjects(); /* * Check whether user can edit Settings */ if (current_user_can('connections_edit_categories')) { check_admin_referer($form->getNonce('update_category'), '_cn_wpnonce'); $category = new cnCategory(); $format = new cnFormatting(); $category->setID($format->sanitizeString($_POST['category_id'])); $category->setName($format->sanitizeString($_POST['category_name'])); $category->setParent($format->sanitizeString($_POST['category_parent'])); $category->setSlug($format->sanitizeString($_POST['category_slug'])); $category->setDescription($format->sanitizeString($_POST['category_description'], TRUE)); $category->update(); wp_redirect(get_admin_url(get_current_blog_id(), 'admin.php?page=connections_categories')); exit; } else { cnMessage::set('error', 'capability_categories'); } }
function processUpdateCategory() { $category = new cnCategory(); $format = new cnFormatting(); $category->setID($format->sanitizeString($_POST['category_id'])); $category->setName($format->sanitizeString($_POST['category_name'])); $category->setParent($format->sanitizeString($_POST['category_parent'])); $category->setSlug($format->sanitizeString($_POST['category_slug'])); $category->setDescription($format->sanitizeString($_POST['category_description'])); $category->update(); }
/** * Returns $description. * * @see cnCategory::$description */ public function getDescription() { return $this->format->sanitizeString($this->description, TRUE); }
/** * Returns as an array of objects containing the dates per the defined options for the current entry. * * Accepted options for the $atts property are: * preferred (bool) Retrieve the preferred entry date. * type (array) || (string) Retrieve specific date types. * Permitted Types: * baptism * certification * employment * membership * graduate_high_school * graduate_college * ordination * * Filters: * cn_date_atts => (array) Set the method attributes. * cn_date_cached => (bool) Define if the returned dates should be from the object cache or queried from the db. * cn_date => (object) Individual date as it is processed thru the loop. * cn_dates => (array) All dates before they are returned. * * @access public * @since 0.7.3 * @version 1.0 * @param array $atts Accepted values as noted above. * @param bool $cached Returns the cached date data rather than querying the db. * @param bool $saving Whether or no the data is being saved to the db. * * @return array */ public function getDates($atts = array(), $cached = TRUE, $saving = FALSE) { // Grab an instance of the Connections object. $instance = Connections_Directory(); $results = array(); $atts = apply_filters('cn_date_atts', $atts); $cached = apply_filters('cn_date_cached', $cached); /* * // START -- Set the default attributes array. \\ */ $defaults = array('preferred' => FALSE, 'type' => NULL); $atts = cnSanitize::args($atts, $defaults); $atts['id'] = $this->getId(); /* * // END -- Set the default attributes array if not supplied. \\ */ /* * Load back into the results the data from the legacy fields, anniversary and birthday, * for backward compatibility with versions 0.7.2.6 and older. */ if (!empty($this->anniversary)) { $anniversary = new stdClass(); $anniversary->id = 0; $anniversary->order = 0; $anniversary->preferred = FALSE; $anniversary->type = 'anniversary'; $anniversary->name = __('Anniversary', 'connections'); $anniversary->date = $this->getAnniversary('Y-m-d'); $anniversary->day = $this->getAnniversary('m-d'); $anniversary->visibility = 'public'; $results['anniversary'] = $anniversary; } if (!empty($this->birthday)) { $birthday = new stdClass(); $birthday->id = 0; $birthday->order = 0; $birthday->preferred = FALSE; $birthday->type = 'birthday'; $birthday->name = __('Birthday', 'connections'); $birthday->date = $this->getBirthday('Y-m-d'); $birthday->day = $this->getBirthday('m-d'); $birthday->visibility = 'public'; $results['birthday'] = $birthday; } if ($cached) { if (!empty($this->dates)) { $dates = unserialize($this->dates); if (empty($dates)) { return $results; } /** * @var bool $preferred * @var string $type */ extract($atts); /* * Covert to an array if it was supplied as a comma delimited string */ cnFunction::parseStringList($type); foreach ((array) $dates as $key => $date) { /** * Allow plugins to filter raw data before object is setup. * * @since 8.5.19 * * @param array $date */ $date = apply_filters('cn_date-pre_setup', $date); $row = new stdClass(); isset($date['id']) ? $row->id = (int) $date['id'] : ($row->id = 0); isset($date['order']) ? $row->order = (int) $date['order'] : ($row->order = 0); isset($date['preferred']) ? $row->preferred = (bool) $date['preferred'] : ($row->preferred = FALSE); isset($date['type']) ? $row->type = $this->format->sanitizeString($date['type']) : ($row->type = ''); isset($date['date']) ? $row->date = $this->format->sanitizeString($date['date']) : ($row->date = ''); isset($date['visibility']) ? $row->visibility = $this->format->sanitizeString($date['visibility']) : ($row->visibility = ''); /* * Set the date name based on the type. */ $dateTypes = $instance->options->getDateOptions(); $row->name = $dateTypes[$row->type]; /* * If the date type is anniversary or birthday and the date is equal to the date * saved in the legacy fields, unset the data imported from the legacy field. * This is for compatibility with versions 0.7.2.6 and older. * * NOTE: Only the month and day will be compared because the legacy getAnniversary() and getBirthday() methods * will return the year of the next anniversary or birthday. IE: if that date in the current year has already * passed the year would be the next year. */ if ('anniversary' == $row->type && isset($results['anniversary']) && substr($row->date, 5, 5) == $results['anniversary']->day) { unset($results['anniversary']); } if ('birthday' == $row->type && isset($results['birthday']) && substr($row->date, 5, 5) == $results['birthday']->day) { unset($results['birthday']); } /* * // START -- Do not return dates that do not match the supplied $atts. */ if ($preferred && !$row->preferred) { continue; } if (!empty($type) && !in_array($row->type, $type)) { continue; } /* * // END -- Do not return dates that do not match the supplied $atts. */ /* * // START -- Compatibility for previous versions. */ // Versions prior to 8.1.5 may not have visibility set, so we'll assume it was 'public' since it wasn't the option before. if (!isset($date['visibility']) || empty($date['visibility'])) { $row->visibility = 'public'; } /* * // END -- Compatibility for previous versions. */ // If the user does not have permission to view the address, do not return it. if (!$this->validate->userPermitted($row->visibility) && !$saving) { continue; } $results[] = apply_filters('cn_date', $row); } } } else { // Exit right away and return an emtpy array if the entry ID has not been set otherwise all dates will be returned by the query. if (!isset($this->id) || empty($this->id)) { return array(); } $dates = $instance->retrieve->dates($atts, $saving); if (empty($dates)) { return $results; } foreach ($dates as $date) { /** This filter is documented in ../includes/entry/class.entry-data.php */ $date = apply_filters('cn_date-pre_setup', $date); $date->id = (int) $date->id; $date->order = (int) $date->order; $date->preferred = (bool) $date->preferred; $date->type = $this->format->sanitizeString($date->type); $date->date = $this->format->sanitizeString($date->date); $date->visibility = $this->format->sanitizeString($date->visibility); /* * Set the date name based on the date type. */ $dateTypes = $instance->options->getDateOptions(); $date->name = $dateTypes[$date->type]; /* * If the date type is anniversary or birthday and the date is equal to the date * saved in the legacy fields are the same, unset the data imported from the legacy field. * This is for compatibility with versions 0.7.2.6 and older. */ if ('anniversary' == $date->type && isset($results['anniversary']) && $date->date == $results['anniversary']->date) { unset($results['anniversary']); } if ('birthday' == $date->type && isset($results['birthday']) && $date->date == $results['birthday']->date) { unset($results['birthday']); } /* * If the date type is anniversary or birthday and the date is equal to the date * saved in the legacy fields, unset the data imported from the legacy field. * This is for compatibility with versions 0.7.2.6 and older. * * NOTE: Only the month and day will be compared because the legacy getAnniversary() and getBirthday() methods * will return the year of the next anniversary or birthday. IE: if that date in the current year has already * passed the year would be the next year. */ if ('anniversary' == $date->type && isset($results['anniversary']) && substr($date->date, 5, 5) == $results['anniversary']->day) { unset($results['anniversary']); } if ('birthday' == $date->type && isset($results['birthday']) && substr($date->date, 5, 5) == $results['birthday']->day) { unset($results['birthday']); } $results[] = apply_filters('cn_date', $date); } } return apply_filters('cn_dates', $results); }