/**
  * Create excerpt from the supplied text. Default is the description.
  *
  * Filters:
  *   cn_cat_excerpt_length => change the default excerpt length of 55 words.
  *   cn_cat_excerpt_more  => change the default more string of …
  *   cn_trim_cat_excerpt  => change returned string
  *
  * @access public
  * @since  0.7.8
  *
  * @param  array  $atts [optional]
  * @param  string $text [optional]
  *
  * @return string
  */
 public function getExcerpt($atts = array(), $text = '')
 {
     $defaults = array('length' => apply_filters('cn_cat_excerpt_length', 55), 'more' => apply_filters('cn_cat_excerpt_more', '…'));
     $atts = $this->validate->attributesArray($defaults, $atts);
     $text = cnString::excerpt(empty($text) ? $this->getDescription() : $text, $atts);
     return apply_filters('cn_trim_cat_excerpt', $text);
 }
Пример #2
0
 public static function sanitizeImageSettings($settings)
 {
     $validate = new cnValidate();
     $defaults = array('quality' => 80, 'height' => 150, 'width' => 225, 'ratio' => 'crop');
     // Use this instead of wp_parse_args since it doesn't drop invalid atts. NOTE: could use shortcode_atts() instead, I suppose.
     $settings = $validate->attributesArray($defaults, $settings);
     // Ensure positive int values
     $settings['quality'] = absint($settings['quality']);
     $settings['height'] = absint($settings['height']);
     $settings['width'] = absint($settings['width']);
     // If the values is empty, set a default.
     $settings['quality'] = empty($settings['quality']) ? 80 : $settings['quality'];
     $settings['height'] = empty($settings['height']) ? 150 : $settings['height'];
     $settings['width'] = empty($settings['width']) ? 225 : $settings['width'];
     // The valid ratio options
     $ratio = array('crop', 'fill', 'fit', 'none');
     // Make sure the value is one of the permitted options and if it is not, set it to the 'crop' value.
     $settings['ratio'] = in_array($settings['ratio'], $ratio) ? $settings['ratio'] : 'crop';
     return $settings;
 }
Пример #3
0
    /**
     * Returns as an array of objects containing the dates per the defined options.
     *
     * $atts['id'] (int) Retrieve the dates of the specified entry by entry id.
     * $atts['preferred'] (bool) Retrieve the preferred date; id must be supplied.
     * $atts['type'] (array) || (string) Retrieve specific date types, id must be supplied.
     *
     * @param array   $suppliedAttr Accepted values as noted above.
     * @param bool    $returnIDs    Query just the entry IDs or not. If set to FALSE, only the entry IDs would be returned as an array. If set TRUE, the date data will be returned.
     * @return array
     */
    public function dates($suppliedAttr, $returnData = TRUE)
    {
        /** @var wpdb $wpdb */
        global $wpdb, $connections, $current_user;
        get_currentuserinfo();
        $validate = new cnValidate();
        $where[] = 'WHERE 1=1';
        /*
         * // START -- Set the default attributes array. \\
         */
        $defaultAttr['id'] = NULL;
        $defaultAttr['preferred'] = NULL;
        $defaultAttr['type'] = NULL;
        $atts = $validate->attributesArray($defaultAttr, $suppliedAttr);
        /*
         * // END -- Set the default attributes array if not supplied. \\
         */
        extract($atts);
        if (!empty($id)) {
            $where[] = $wpdb->prepare('AND `entry_id` = "%d"', $id);
            if (!empty($preferred)) {
                $where[] = $wpdb->prepare('AND `preferred` = %d', (bool) $preferred);
            }
            if (!empty($type)) {
                if (!is_array($type)) {
                    $type = explode(',', trim($type));
                }
                $where[] = stripslashes($wpdb->prepare('AND `type` IN (\'%s\')', implode("', '", (array) $type)));
            }
        }
        // Set query string for visibility based on user permissions if logged in.
        if (is_user_logged_in()) {
            if (!isset($atts['visibility']) || empty($atts['visibility'])) {
                if (current_user_can('connections_view_public')) {
                    $visibility[] = 'public';
                }
                if (current_user_can('connections_view_private')) {
                    $visibility[] = 'private';
                }
                if (current_user_can('connections_view_unlisted') && is_admin()) {
                    $visibility[] = 'unlisted';
                }
            } else {
                $visibility[] = $atts['visibility'];
            }
        } else {
            if ($connections->options->getAllowPublic()) {
                $visibility[] = 'public';
            }
            if ($atts['allow_public_override'] == TRUE && $connections->options->getAllowPublicOverride()) {
                $visibility[] = 'public';
            }
            if ($atts['private_override'] == TRUE && $connections->options->getAllowPrivateOverride()) {
                $visibility[] = 'private';
            }
        }
        if (!empty($visibility)) {
            $where[] = 'AND `visibility` IN (\'' . implode("', '", (array) $visibility) . '\')';
        }
        if ($returnData) {
            $sql = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT ' . CN_ENTRY_DATE_TABLE . '.*

					FROM ' . CN_ENTRY_DATE_TABLE . ' ' . ' ' . implode(' ', $where) . ' ' . 'ORDER BY `order`';
            //print_r($sql);
            $results = $wpdb->get_results($sql);
        } else {
            $sql = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT ' . CN_ENTRY_DATE_TABLE . '.entry_id

					FROM ' . CN_ENTRY_DATE_TABLE . ' ' . ' ' . implode(' ', $where);
            //print_r($sql);
            $results = $wpdb->get_col($sql);
        }
        if (empty($results)) {
            return array();
        }
        //print_r($results);
        return $results;
    }
Пример #4
0
    /**
     * @return array
     */
    public function entries($suppliedAttr = array())
    {
        global $wpdb, $connections;
        $validate = new cnValidate();
        $join = array();
        $where[] = 'WHERE 1=1';
        $permittedEntryTypes = array('individual', 'organization', 'family', 'connection_group');
        /*
         * // START -- Set the default attributes array. \\
         */
        $defaultAttr['list_type'] = NULL;
        $defaultAttr['id'] = NULL;
        $defaultAttr['category'] = NULL;
        $defaultAttr['exclude_category'] = NULL;
        $defaultAttr['category_name'] = NULL;
        $defaultAttr['wp_current_category'] = FALSE;
        $defaultAttr['visibility'] = NULL;
        $defaultAttr['allow_public_override'] = FALSE;
        $defaultAttr['private_override'] = FALSE;
        $defaultAttr['limit'] = NULL;
        $defaultAttr['offset'] = NULL;
        $defaultAttr['order_by'] = NULL;
        $atts = $validate->attributesArray($defaultAttr, $suppliedAttr);
        /*
         * // END -- Set the default attributes array if not supplied. \\
         */
        /*
         * If in a post get the category names assigned to the post.
         */
        if ($atts['wp_current_category'] && !is_page()) {
            // Get the current post categories.
            $wpCategories = get_the_category();
            // Build an array of the post categories.
            foreach ($wpCategories as $wpCategory) {
                $wpCategoryNames[] = $wpCategory->cat_name;
            }
        }
        /*
         * Build and array of the supplied category names and their children.
         */
        if (!empty($atts['category_name'])) {
            // If value is a string convert to an array.
            if (!is_array($atts['category_name'])) {
                $atts['category_name'] = explode(',', $atts['category_name']);
            }
            foreach ($atts['category_name'] as $categoryName) {
                // Add the parent category to the array and remove any whitespace from the begining/end of the name in case the user added it when using the shortcode.
                $categoryNames[] = trim($categoryName);
                // Retrieve the children categories
                $results = $this->categoryChildren('name', $categoryName);
                foreach ((array) $results as $term) {
                    $categoryNames[] = $term->name;
                }
            }
        }
        /*
         * Create the string to be used to query entries based on category names. This will merge the
         * category names from the current post categories and the supplied category names and their
         * respective children categories.
         */
        $catNameString = implode("', '", array_merge((array) $wpCategoryNames, (array) $categoryNames));
        unset($wpCategoryNames);
        unset($categoryNames);
        /*
         * Build an array of all the categories and their children based on the supplied category IDs.
         */
        if (!empty($atts['category'])) {
            // If value is a string, string the white space and covert to an array.
            if (!is_array($atts['category'])) {
                $atts['category'] = str_replace(' ', '', $atts['category']);
                $atts['category'] = explode(',', $atts['category']);
            }
            foreach ($atts['category'] as $categoryID) {
                // Add the parent category ID to the array.
                $categoryIDs[] = $categoryID;
                // Retrieve the children categories
                $results = $this->categoryChildren('term_id', $categoryID);
                foreach ((array) $results as $term) {
                    $categoryIDs[] = $term->term_id;
                }
            }
            /*
             * Exclude the specified categories by ID.
             */
            if (!empty($atts['exclude_category'])) {
                // If value is a string, string the white space and covert to an array.
                if (!is_array($atts['exclude_category'])) {
                    $atts['exclude_category'] = str_replace(' ', '', $atts['exclude_category']);
                    $atts['exclude_category'] = explode(',', $atts['exclude_category']);
                }
                $categoryIDs = array_diff($categoryIDs, $atts['exclude_category']);
            }
            /*
             * Create the string to be used to query entries based on category IDs.
             */
            $catIDString = implode("', '", $categoryIDs);
            unset($categoryIDs);
        }
        if (!empty($catIDString) || !empty($catNameString)) {
            // Set the query string to INNER JOIN the term relationship and taxonomy tables.
            $join[] = 'INNER JOIN ' . CN_TERM_RELATIONSHIP_TABLE . ' ON ( ' . CN_ENTRY_TABLE . '.id = ' . CN_TERM_RELATIONSHIP_TABLE . '.entry_id )';
            $join[] = 'INNER JOIN ' . CN_TERM_TAXONOMY_TABLE . ' ON ( ' . CN_TERM_RELATIONSHIP_TABLE . '.term_taxonomy_id = ' . CN_TERM_TAXONOMY_TABLE . '.term_taxonomy_id )';
            $join[] = 'INNER JOIN ' . CN_TERMS_TABLE . ' ON ( ' . CN_TERMS_TABLE . '.term_id = ' . CN_TERM_TAXONOMY_TABLE . '.term_id )';
            // Set the query string to return entries within the category taxonomy.
            $where[] = 'AND ' . CN_TERM_TAXONOMY_TABLE . '.taxonomy = \'category\'';
            if (!empty($catIDString)) {
                $where[] = 'AND ' . CN_TERM_TAXONOMY_TABLE . '.term_id IN (\'' . $catIDString . '\')';
            }
            if (!empty($catNameString)) {
                $where[] = 'AND ' . CN_TERMS_TABLE . '.name IN (\'' . $catNameString . '\')';
            }
        }
        // Convert the supplied IDs $atts['id'] to an array.
        if (!is_array($atts['id']) && !empty($atts['id'])) {
            // Trim the space characters if present.
            $atts['id'] = str_replace(' ', '', $atts['id']);
            // Convert to array.
            $atts['id'] = explode(',', $atts['id']);
        }
        // Set query string to return specific entries.
        if (!empty($atts['id'])) {
            $where[] = 'AND `id` IN (\'' . implode("', '", (array) $atts['id']) . '\')';
        }
        // Convert the supplied entry types $atts['list_type'] to an array.
        if (!is_array($atts['list_type']) && !empty($atts['list_type'])) {
            // Trim the space characters if present.
            $atts['list_type'] = str_replace(' ', '', $atts['list_type']);
            // Convert to array.
            $atts['list_type'] = explode(',', $atts['list_type']);
        }
        // Set query string for entry type.
        if (!empty($atts['list_type']) && (bool) array_intersect($atts['list_type'], $permittedEntryTypes)) {
            // Capatibility code to make sure any ocurrences of the deprecated entry type connections_group is changed to entry type family
            $atts['list_type'] = str_replace('connection_group', 'family', $atts['list_type']);
            $where[] = 'AND `entry_type` IN (\'' . implode("', '", (array) $atts['list_type']) . '\')';
        }
        // Set query string for visibility based on user permissions if logged in.
        if (is_user_logged_in()) {
            if (!$atts['visibility']) {
                if (current_user_can('connections_view_public')) {
                    $visibility[] = 'public';
                }
                if (current_user_can('connections_view_private')) {
                    $visibility[] = 'private';
                }
                if (current_user_can('connections_view_unlisted') && is_admin()) {
                    $visibility[] = 'unlisted';
                }
            } else {
                $visibility[] = $atts['visibility'];
            }
        } else {
            if ($connections->options->getAllowPublic()) {
                $visibility[] = 'public';
            }
            if ($atts['allow_public_override'] == TRUE && $connections->options->getAllowPublicOverride()) {
                $visibility[] = 'public';
            }
            if ($atts['private_override'] == TRUE && $connections->options->getAllowPrivateOverride()) {
                $visibility[] = 'private';
            }
        }
        $where[] = 'AND `visibility` IN (\'' . implode("', '", (array) $visibility) . '\')';
        empty($atts['limit']) ? $limit = NULL : ($limit = ' LIMIT ' . $atts['limit'] . ' ');
        empty($atts['offset']) ? $offset = NULL : ($offset = ' OFFSET ' . $atts['offset'] . ' ');
        $sql = 'SELECT DISTINCT ' . CN_ENTRY_TABLE . '.*,
				
				CASE `entry_type`
				  WHEN \'individual\' THEN `last_name`
				  WHEN \'organization\' THEN `organization`
				  WHEN \'connection_group\' THEN `family_name`
				  WHEN \'family\' THEN `family_name`
				END AS `sort_column`
				 
				FROM ' . CN_ENTRY_TABLE . ' ' . implode(' ', $join) . ' ' . implode(' ', $where) . ' ' . 'ORDER BY `sort_column`, `last_name`, `first_name`  ' . $limit . $offset;
        $results = $wpdb->get_results($sql);
        $connections->lastQuery = $wpdb->last_query;
        $connections->lastQueryError = $wpdb->last_error;
        $connections->lastInsertID = $wpdb->insert_id;
        $connections->resultCount = $wpdb->num_rows;
        $connections->recordCount = $this->recordCount($atts['allow_public_override'], $atts['private_override']);
        return $this->orderBy($results, $atts['order_by'], $atts['id']);
    }
Пример #5
0
 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) : '';
 }
Пример #7
0
 /**
  * function updateKeyword
  *
  * @instance_id        id of the instance
  * @orig_keyword       original keyword
  * @item               edited value
  * @type               type of the item
  *
  */
 public static function updateKeyword($instance_id, $orig_keyword, $item, $type)
 {
     $instance = self::getInstance($instance_id);
     if ($instance && trim($item)) {
         // validate users
         if (in_array($type, array('twitter_name', 'facebook_name'))) {
             if (!($item = cnValidate::socialUser($item, $type))) {
                 return -1;
             }
         }
         // twitter and facebook
         if (in_array($type, array('twitter_name', 'facebook_name'))) {
             self::updateUser($instance_id, $orig_keyword, $type, $item);
         } else {
             $row = self::filterKeyword($item, array(), self::$searchType[$type]);
             $delete = self::filterKeyword($orig_keyword, array(), self::$searchType[$type]);
             $update = array('$unset' => $delete, '$set' => $row);
             // save data
             self::saveInstance($update, $instance_id);
         }
     }
     return $item;
 }