public function getVisibilityOptions()
 {
     $options = array('public' => __('Public', 'connections'), 'private' => __('Private', 'connections'), 'unlisted' => __('Unlisted', 'connections'));
     foreach ($options as $key => $option) {
         if (!cnValidate::userPermitted($key)) {
             unset($options[$key]);
         }
     }
     return $options;
 }
 /**
  * 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) : '';
 }