/**
 * Ensure WPSEO header items are not added to internal Connections pages.
 * @todo Should add Connections related header items to mimic WPSEO.
 *
 * @access private
 * @since  8.1.1
 * @return void
 */
function cn_remove_wpseo_head()
{
    if (cnQuery::getVar('cn-entry-slug') || cnQuery::getVar('cn-cat-slug') || cnQuery::getVar('cn-cat')) {
        if (isset($GLOBALS['wpseo_front'])) {
            remove_action('wp_head', array($GLOBALS['wpseo_front'], 'head'), 1);
        }
    }
}
 /**
  * Initiate the template options using the option values.
  *
  * @access private
  * @since  3.0
  *
  * @param  array $atts The shortcode $atts array.
  *
  * @return array
  */
 public static function initOptions($atts)
 {
     if (cnQuery::getVar('cn-entry-slug')) {
         /**
          * @var cnOutput $entry
          * @var array $option
          */
         $options = cnSettingsAPI::get('connections_template', self::SLUG, 'single');
     } else {
         /**
          * @var cnOutput $entry
          * @var array $option
          */
         $options = cnSettingsAPI::get('connections_template', self::SLUG, 'card');
         $style = array('background-color' => '#FFF', 'border' => $options['border_width'] . 'px solid ' . $options['border_color'], 'border-radius' => $options['border_radius'] . 'px', 'color' => '#000', 'margin' => '8px 0', 'padding' => '10px', 'position' => 'relative');
         if (is_array($style)) {
             $atts = wp_parse_args($style, $atts);
         }
     }
     if (is_array($options)) {
         $atts = wp_parse_args($options, $atts);
     }
     return $atts;
 }
 /**
  * Returns the current category being viewed.
  *
  * @access public
  * @since  8.5.18
  * @static
  *
  * @return false|cnTerm_Object
  */
 public static function getCurrent()
 {
     $current = FALSE;
     if (cnQuery::getVar('cn-cat-slug')) {
         $slug = explode('/', cnQuery::getVar('cn-cat-slug'));
         // If the category slug is a descendant, use the last slug from the URL for the query.
         $current = end($slug);
     } elseif ($catIDs = cnQuery::getVar('cn-cat')) {
         if (is_array($catIDs)) {
             // If value is a string, strip the white space and covert to an array.
             $catIDs = wp_parse_id_list($catIDs);
             // Use the first element
             $current = reset($catIDs);
         } else {
             $current = $catIDs;
         }
     }
     if (!empty($current)) {
         if (ctype_digit((string) $current)) {
             $field = 'id';
         } else {
             $field = 'slug';
         }
         $current = cnTerm::getBy($field, $current, 'category');
         // cnTerm::getBy() can return NULL || an instance of WP_Error, so, lets check for that.
         if (!is_a($current, 'cnTerm_Object')) {
             $current = FALSE;
         }
     }
     return $current;
 }
 /**
  * Add the the current Connections category description or entry bio excerpt as the page meta description.
  *
  * @access private
  * @since  0.7.8
  * @static
  *
  * @uses   cnQuery::getVar()
  * @uses   esc_attr()
  * @uses   strip_shortcodes()
  */
 public static function metaDesc()
 {
     // Whether or not to filter the page title with the current directory location.
     if (!cnSettingsAPI::get('connections', 'seo_meta', 'page_desc')) {
         return;
     }
     $description = '';
     if (cnQuery::getVar('cn-cat-slug')) {
         // If the category slug is a descendant, use the last slug from the URL for the query.
         $categorySlug = explode('/', cnQuery::getVar('cn-cat-slug'));
         if (isset($categorySlug[count($categorySlug) - 1])) {
             $categorySlug = $categorySlug[count($categorySlug) - 1];
         }
         $term = cnTerm::getBy('slug', $categorySlug, 'category');
         $category = new cnCategory($term);
         $description = $category->getExcerpt(array('length' => 160));
     }
     if (cnQuery::getVar('cn-cat')) {
         if (is_array(cnQuery::getVar('cn-cat'))) {
             return;
         }
         $categoryID = cnQuery::getVar('cn-cat');
         $term = cnTerm::getBy('id', $categoryID, 'category');
         $category = new cnCategory($term);
         $description = $category->getExcerpt(array('length' => 160));
     }
     if (cnQuery::getVar('cn-entry-slug')) {
         // Grab an instance of the Connections object.
         $instance = Connections_Directory();
         $result = $instance->retrieve->entries(array('slug' => urldecode(cnQuery::getVar('cn-entry-slug'))));
         // Make sure an entry is returned and then echo the meta desc.
         if (!empty($result)) {
             $entry = new cnEntry($result[0]);
             $description = $entry->getExcerpt(array('length' => 160));
         }
     }
     if (0 == strlen($description)) {
         return;
     }
     echo '<meta name="description" content="' . esc_attr(trim(strip_shortcodes(strip_tags(stripslashes($description))))) . '"/>' . "\n";
 }
 /**
  * The private recursive function to build the category link item.
  *
  * Accepted option for the $atts property are:
  * 	type (string)
  * 	show_empty (bool) Whether or not to display empty categories.
  * 	show_count (bool) Whether or not to display the category count.
  *
  * @param object $category A category object.
  * @param int $level The current category level.
  * @param int $depth The depth limit.
  * @param array $slug An array of the category slugs to be used to build the permalink.
  * @param array $atts
  * @return string
  */
 private static function categoryLinkDescendant($category, $level, $depth, $slug, $atts)
 {
     /**
      * @var WP_Rewrite $wp_rewrite
      * @var connectionsLoad $connections
      */
     global $wp_rewrite;
     $out = '';
     $defaults = array('show_empty' => TRUE, 'show_count' => TRUE, 'exclude' => array(), 'force_home' => FALSE, 'home_id' => cnSettingsAPI::get('connections', 'connections_home_page', 'page_id'));
     $atts = wp_parse_args($atts, $defaults);
     // Do not show the excluded category as options.
     if (!empty($atts['exclude']) && in_array($category->term_id, $atts['exclude'])) {
         return $out;
     }
     if ($atts['show_empty'] || !empty($category->count) || !empty($category->children)) {
         $count = $atts['show_count'] ? ' (' . $category->count . ')' : '';
         /*
          * Determine of pretty permalink is enabled.
          * If it is, add the category slug to the array which will be imploded to be used to build the URL.
          * If it is not, set the $slug to the category term ID.
          */
         if ($wp_rewrite->using_permalinks()) {
             $slug[] = $category->slug;
         } else {
             $slug = array($category->slug);
         }
         /*
          * Get tge current category from the URL / query string.
          */
         if (cnQuery::getVar('cn-cat-slug')) {
             // Category slug
             $queryCategorySlug = cnQuery::getVar('cn-cat-slug');
             if (!empty($queryCategorySlug)) {
                 // If the category slug is a descendant, use the last slug from the URL for the query.
                 $queryCategorySlug = explode('/', $queryCategorySlug);
                 if (isset($queryCategorySlug[count($queryCategorySlug) - 1])) {
                     $currentCategory = $queryCategorySlug[count($queryCategorySlug) - 1];
                 }
             }
         } elseif (cnQuery::getVar('cn-cat')) {
             $currentCategory = cnQuery::getVar('cn-cat');
         } else {
             $currentCategory = '';
         }
         $out .= '<li class="cat-item cat-item-' . $category->term_id . ($currentCategory == $category->slug || $currentCategory == $category->term_id ? ' current-cat' : '') . ' cn-cat-parent">';
         // Create the permalink anchor.
         $out .= cnURL::permalink(array('type' => 'category', 'slug' => implode('/', $slug), 'title' => $category->name, 'text' => $category->name . $count, 'home_id' => $atts['home_id'], 'force_home' => $atts['force_home'], 'return' => TRUE));
         /*
          * Only show the descendants based on the following criteria:
          * 	- There are descendant categories.
          * 	- The descendant depth is < than the current $level
          *
          * When descendant depth is set to 0, show all descendants.
          * When descendant depth is set to < $level, call the recursive function.
          */
         if (!empty($category->children) && ($depth <= 0 ? -1 : $level) < $depth) {
             $out .= '<ul class="children cn-cat-children">';
             foreach ($category->children as $child) {
                 $out .= self::categoryLinkDescendant($child, $level + 1, $depth, $slug, $atts);
             }
             $out .= '</ul>';
         }
         $out .= '</li>';
     }
     return $out;
 }
    /**
     * Render the note informing the user that the category select drop down is for customization/display purposes only,
     * that is non-functional.
     *
     * @access private
     * @since  8.4
     *
     * @uses   cnTemplate_Customizer::supports()
     */
    public function categoryMessage()
    {
        if ($this->supports('category-select') && !cnQuery::getVar('cn-entry-slug')) {
            ?>

			<div id="cn-customizer-messages">
				<ul id="cn-customizer-message-list">
					<li class="cn-customizer-message"><?php 
            _e('<strong>NOTE:</strong> Category select is for customization purposes only. It will not filter the results.', 'connections');
            ?>
</li>
				</ul>
			</div>

			<?php 
        }
    }
 /**
  * Retrieve all connected logs.
  *
  * Used for retrieving logs related to particular items, such as a specific error.
  *
  * @access private
  * @since  8.2.10
  * @static
  *
  * @uses   wp_parse_args()
  * @uses   get_posts()
  * @uses   cnQuery::getVar()
  * @uses   cnLog::valid()
  *
  * @param array $atts
  *
  * @return array|false An indexed array of logs or false if none were found.
  */
 public static function getConnected($atts = array())
 {
     $defaults = array('post_parent' => 0, 'post_type' => self::POST_TYPE, 'posts_per_page' => 20, 'post_status' => 'publish', 'paged' => cnQuery::getVar('paged'), 'type' => FALSE);
     $query = wp_parse_args($atts, $defaults);
     if ($query['type']) {
         if (is_array($query['type'])) {
             $types = array();
             foreach ($query['type'] as $type) {
                 if (self::valid($type)) {
                     $types[] = $type;
                 }
             }
         } else {
             $types = '';
             if (self::valid($query['type'])) {
                 $types = $query['type'];
             }
         }
         if (!empty($types)) {
             $query['tax_query'] = array(array('taxonomy' => self::TAXONOMY, 'field' => 'slug', 'terms' => $types));
         }
     }
     $logs = get_posts($query);
     if ($logs) {
         return $logs;
     }
     // No logs found.
     return FALSE;
 }
 /**
  * An indexed array of file names to be searched for.
  *
  * The file names is an index array of file names where the
  * highest priority is first and the lowest priority is last.
  *
  * @access public
  * @since  0.8
  * @static
  * @uses   apply_filters()
  * @uses   cnQuery::getVar()
  * @param  string $base The base file name. Typically `card` for a template file and the template slug for CSS and JS files.
  * @param  string $name The template part name; such as `single` or `category`.
  * @param  string $slug The template part slug; such as an entry slug or category slug.
  * @param  string $ext  [optional] The template file name extension. Defaults to `php`.
  *
  * @return array        An indexed array of file names to search for.
  */
 public static function fileNames($base, $name = NULL, $slug = NULL, $ext = 'php')
 {
     $files = array();
     if (cnQuery::getVar('cn-cat')) {
         $categoryID = cnQuery::getVar('cn-cat');
         // Since the `cn-cat` query var can be an array, we'll only add the category slug
         // template name when querying a single category.
         if (!is_array($categoryID)) {
             $term = cnTerm::getBy('id', $categoryID, 'category');
             $files[] = self::fileName($base, 'category', $term->slug, $ext);
         }
         $files[] = self::fileName($base, 'category', NULL, $ext);
         // var_dump( $files );
     }
     if (cnQuery::getVar('cn-cat-slug')) {
         $files[] = self::fileName($base, 'category', cnQuery::getVar('cn-cat-slug'), $ext);
         $files[] = self::fileName($base, 'category', NULL, $ext);
         // var_dump( $files );
     }
     if (cnQuery::getVar('cn-country')) {
         $country = self::queryVarSlug(cnQuery::getVar('cn-country'));
         $files[] = self::fileName($base, 'country', $country, $ext);
         $files[] = self::fileName($base, 'country', NULL, $ext);
         // var_dump( $files );
     }
     if (cnQuery::getVar('cn-region')) {
         $region = self::queryVarSlug(cnQuery::getVar('cn-region'));
         $files[] = self::fileName($base, 'region', $region, $ext);
         $files[] = self::fileName($base, 'region', NULL, $ext);
         // var_dump( $files );
     }
     if (cnQuery::getVar('cn-postal-code')) {
         $zipcode = self::queryVarSlug(cnQuery::getVar('cn-postal-code'));
         $files[] = self::fileName($base, 'postal-code', $zipcode, $ext);
         $files[] = self::fileName($base, 'postal-code', NULL, $ext);
         // var_dump( $files );
     }
     if (cnQuery::getVar('cn-locality')) {
         $locality = self::queryVarSlug(cnQuery::getVar('cn-locality'));
         $files[] = self::fileName($base, 'locality', $locality, $ext);
         $files[] = self::fileName($base, 'locality', NULL, $ext);
         // var_dump( $files );
     }
     if (cnQuery::getVar('cn-organization')) {
         $organization = self::queryVarSlug(cnQuery::getVar('cn-organization'));
         $files[] = self::fileName($base, 'organization', $organization, $ext);
         $files[] = self::fileName($base, 'organization', NULL, $ext);
         // var_dump( $files );
     }
     if (cnQuery::getVar('cn-department')) {
         $department = self::queryVarSlug(cnQuery::getVar('cn-department'));
         $files[] = self::fileName($base, 'department', $department, $ext);
         $files[] = self::fileName($base, 'department', NULL, $ext);
         // var_dump( $files );
     }
     if (cnQuery::getVar('cn-entry-slug')) {
         $files[] = self::fileName($base, NULL, cnQuery::getVar('cn-entry-slug'), $ext);
         $files[] = self::fileName($base, 'single', NULL, $ext);
         // var_dump( $files );
     }
     // If `$name` was supplied, add it to the files to search for.
     if (!is_null($name)) {
         $files[] = self::fileName($base, $name, NULL, $ext);
     }
     // Add the base as the least priority, since it is required.
     $files[] = self::fileName($base, NULL, NULL, $ext);
     /**
      * Allow template choices to be filtered.
      *
      * The resulting array should be in the order of most specific first, least specific last.
      * e.g. 0 => card-single.php, 1 => card.php
      */
     $files = apply_filters('cn_locate_file_names', $files, $base, $name, $slug, $ext);
     // var_dump( $files );
     // Sort the files based on priority
     ksort($files, SORT_NUMERIC);
     // var_dump( $files );
     return array_filter($files);
 }
 /**
  * Render an unordered list of categories.
  *
  * This is the Connections equivalent of @see wp_list_categories() in WordPress core ../wp-includes/category-template.php
  *
  * @access public
  * @since  8.1.6
  * @static
  *
  * @uses   wp_parse_args()
  * @uses   cnTerm::getTaxonomyTerms()
  * @uses   cnURL::permalink()
  * @uses   Walker::walk()
  *
  * @param array $atts {
  *     Optional. An array of arguments.
  *     NOTE: Additionally, all valid options as supported in @see cnTerm::getTaxonomyTerms().
  *
  * @type string $show_option_all  A non-blank value causes the display of a link to the directory home page.
  *                                Default: ''. The default is not to display a link.
  *                                Accepts: Any valid string.
  * @type string $show_option_none Set the text to show when no categories are listed.
  *                                Default: 'No Categories'
  *                                Accepts: Any valid string.
  * @type bool   $show_count       Whether or not to display the category count.
  *                                Default: FALSE
  * @type int    $depth            Controls how many levels in the hierarchy of categories are to be included in the list.
  *                                Default: 0
  *                                Accepts: 0  - All categories and child categories.
  *                                         -1 - All Categories displayed  flat, not showing the parent/child relationships.
  *                                         1  - Show only top level/root parent categories.
  *                                         n  - Value of n (int) specifies the depth (or level) to descend in displaying the categories.
  * @type string $taxonomy         The taxonomy tree to display.
  *                                Default: 'category'
  *                                Accepts: Any registered taxonomy.
  * @type bool   $return           Whether or not to return or echo the resulting HTML.
  *                                Default: FALSE
  * }
  *
  * @return string
  */
 public static function render($atts = array())
 {
     $out = '';
     $defaults = array('show_option_all' => '', 'show_option_none' => __('No categories', 'connections'), 'orderby' => 'name', 'order' => 'ASC', 'show_count' => FALSE, 'hide_empty' => FALSE, 'child_of' => 0, 'exclude' => array(), 'hierarchical' => TRUE, 'depth' => 0, 'parent_id' => array(), 'taxonomy' => 'category', 'force_home' => FALSE, 'home_id' => cnSettingsAPI::get('connections', 'connections_home_page', 'page_id'), 'return' => FALSE);
     $atts = wp_parse_args($atts, $defaults);
     $atts['parent_id'] = wp_parse_id_list($atts['parent_id']);
     $walker = new self();
     if (empty($atts['parent_id'])) {
         $terms = cnTerm::getTaxonomyTerms($atts['taxonomy'], array_merge($atts, array('name' => '')));
     } else {
         $terms = cnTerm::getTaxonomyTerms($atts['taxonomy'], array_merge($atts, array('include' => $atts['parent_id'], 'child_of' => 0, 'name' => '')));
         // If any of the `parent_id` is not a root parent (where $term->parent = 0) set it parent ID to `0`
         // so the term tree will be properly constructed.
         foreach ($terms as $term) {
             if (0 !== $term->parent) {
                 $term->parent = 0;
             }
         }
         foreach ($atts['parent_id'] as $termID) {
             $children = cnTerm::getTaxonomyTerms($atts['taxonomy'], array_merge($atts, array('child_of' => $termID, 'name' => '')));
             if (!is_wp_error($children)) {
                 $terms = array_merge($terms, $children);
             }
         }
     }
     /**
      * Allows extensions to add/remove class names to the term tree list.
      *
      * @since 8.5.18
      *
      * @param array $class The array of class names.
      * @param array $terms The array of terms.
      * @param array $atts  The method attributes.
      */
     $class = apply_filters('cn_term_list_class', array('cn-cat-tree'), $terms, $atts);
     $class = cnSanitize::htmlClass($class);
     $out .= '<ul class="' . cnFunction::escAttributeDeep($class) . '">' . PHP_EOL;
     if (empty($terms)) {
         $out .= '<li class="cat-item-none">' . $atts['show_option_none'] . '</li>';
     } else {
         if (cnQuery::getVar('cn-cat-slug')) {
             $slug = explode('/', cnQuery::getVar('cn-cat-slug'));
             // If the category slug is a descendant, use the last slug from the URL for the query.
             $atts['current_category'] = end($slug);
         } elseif ($catIDs = cnQuery::getVar('cn-cat')) {
             if (is_array($catIDs)) {
                 // If value is a string, strip the white space and covert to an array.
                 $catIDs = wp_parse_id_list($catIDs);
                 // Use the first element
                 $atts['current_category'] = reset($catIDs);
             } else {
                 $atts['current_category'] = $catIDs;
             }
         } else {
             $atts['current_category'] = 0;
         }
         if (!empty($atts['show_option_all'])) {
             $out .= '<li class="cat-item-all"><a href="' . cnURL::permalink(array('type' => 'home', 'data' => 'url', 'return' => TRUE)) . '">' . $atts['show_option_all'] . '</a></li>';
         }
         $out .= $walker->walk($terms, $atts['depth'], $atts);
     }
     $out .= '</ul>' . PHP_EOL;
     if ($atts['return']) {
         return $out;
     }
     echo $out;
 }
 /**
  * Checks the requested URL for Connections' query vars and if found rewrites the URL
  * and passes the new URL back to finish being processed by the redirect_canonical() function.
  *
  * Hooks into the redirect_canonical filter.
  *
  * @access private
  * @since 0.7.3.2
  * @uses cnQuery::getVar()
  * @uses remove_query_arg()
  * @uses user_trailingslashit()
  * @param string  $redirectURL
  * @param string  $requestedURL
  * @return string
  */
 public function canonicalRedirectFilter($redirectURL, $requestedURL)
 {
     $originalURL = $redirectURL;
     $parsedURL = @parse_url($requestedURL);
     $redirectURL = explode('?', $redirectURL);
     $redirectURL = $redirectURL[0];
     // Ensure array index is set, prevent PHP error notice.
     if (!isset($parsedURL['query'])) {
         $parsedURL['query'] = '';
     }
     // If paged, append pagination
     if (cnQuery::getVar('cn-pg')) {
         $page = (int) cnQuery::getVar('cn-pg');
         $parsedURL['query'] = remove_query_arg('cn-pg', $parsedURL['query']);
         if ($page > 1 && !stripos($redirectURL, "pg/{$page}")) {
             $redirectURL .= user_trailingslashit("pg/{$page}", 'page');
         }
         // var_dump( $redirectURL );
         // exit();
     }
     // Add back on to the URL any remaining query string values.
     $parsedURL['query'] = preg_replace('#^\\??&*?#', '', $parsedURL['query']);
     if ($redirectURL && !empty($parsedURL['query'])) {
         parse_str($parsedURL['query'], $_parsed_query);
         $_parsed_query = array_map('rawurlencode', $_parsed_query);
         $redirectURL = add_query_arg($_parsed_query, $redirectURL);
     }
     return $redirectURL;
 }
 /**
  * Add the entry actions to the admin bar
  *
  * @access private
  * @static
  * @since  8.2
  * @uses   cnURL::permalink()
  * @uses   current_user_can()
  * @param  $admin_bar object
  *
  * @return void
  */
 public static function adminBarMenuItems($admin_bar)
 {
     if (cnQuery::getVar('cn-entry-slug')) {
         // Grab an instance of the Connections object.
         $instance = Connections_Directory();
         $entry = $instance->retrieve->entries(array('slug' => rawurldecode(cnQuery::getVar('cn-entry-slug')), 'status' => 'approved,pending'));
         // Make sure an entry is returned and if not, return $title unaltered.
         if (empty($entry)) {
             return;
         }
         // preg_match( '/href="(.*?)"/', cnURL::permalink( array( 'slug' => $entry->slug, 'return' => TRUE ) ), $matches );
         // $permalink = $matches[1];
         if (current_user_can('connections_manage') && current_user_can('connections_view_menu') && (current_user_can('connections_edit_entry_moderated') || current_user_can('connections_edit_entry'))) {
             $admin_bar->add_node(array('parent' => FALSE, 'id' => 'cn-edit-entry', 'title' => __('Edit Entry', 'connections'), 'href' => admin_url(wp_nonce_url('admin.php?page=connections_manage&cn-action=edit_entry&id=' . $entry[0]->id, 'entry_edit_' . $entry[0]->id)), 'meta' => array('title' => __('Edit Entry', 'connections'))));
         }
     }
 }
 /**
  * Parses a TimThumb compatible URL via the CN_IMAGE_ENDPOINT root rewrite endpoint
  * and stream the image to the browser with the correct headers for the image type being served.
  *
  * Streams an image resource to the browser or a error message.
  *
  * @access private
  * @since  8.1
  * @static
  *
  * @uses   cnQuery::getVar()
  * @uses   path_is_absolute()
  * @uses   cnColor::rgb2hex2rgb()
  * @uses   self::get()
  * @uses   is_wp_error()
  */
 public static function query()
 {
     /** @var wpdb $wpdb */
     global $wpdb;
     if (cnQuery::getVar(CN_IMAGE_ENDPOINT)) {
         if (path_is_absolute(cnQuery::getVar('src'))) {
             header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
             echo '<h1>ERROR/s:</h1><ul><li>Source is file path. Source must be a local file URL.</li></ul>';
             exit;
         }
         $atts = array();
         if (cnQuery::getVar('cn-entry-slug')) {
             $sql = $wpdb->prepare('SELECT slug FROM ' . CN_ENTRY_TABLE . ' WHERE slug=%s', cnQuery::getVar('cn-entry-slug'));
             $result = $wpdb->get_var($sql);
             if (is_null($result)) {
                 header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
                 echo '<h1>ERROR/s:</h1><ul><li>Cheating?</li></ul>';
                 exit;
             } else {
                 $atts['sub_dir'] = $result;
             }
         }
         if (cnQuery::getVar('w')) {
             $atts['width'] = cnQuery::getVar('w');
         }
         if (cnQuery::getVar('h')) {
             $atts['height'] = cnQuery::getVar('h');
         }
         if (cnQuery::getVar('zc') || cnQuery::getVar('zc') === '0') {
             $atts['crop_mode'] = cnQuery::getVar('zc');
         }
         if (cnQuery::getVar('a')) {
             $atts['crop_focus'] = array('center', 'center');
             if (strpos(cnQuery::getVar('a'), 't') !== FALSE) {
                 $atts['crop_focus'][1] = 'top';
             }
             if (strpos(cnQuery::getVar('a'), 'r') !== FALSE) {
                 $atts['crop_focus'][0] = 'right';
             }
             if (strpos(cnQuery::getVar('a'), 'b') !== FALSE) {
                 $atts['crop_focus'][1] = 'bottom';
             }
             if (strpos(cnQuery::getVar('a'), 'l') !== FALSE) {
                 $atts['crop_focus'][0] = 'left';
             }
             $atts['crop_focus'] = implode(',', $atts['crop_focus']);
         }
         if (cnQuery::getVar('f')) {
             $filters = explode('|', cnQuery::getVar('f'));
             foreach ($filters as $filter) {
                 $param = explode(',', $filter);
                 for ($i = 0; $i < 4; $i++) {
                     if (!isset($param[$i])) {
                         $param[$i] = NULL;
                     } else {
                         $param[$i] = $param[$i];
                     }
                 }
                 switch ($param[0]) {
                     case '1':
                         $atts['negate'] = TRUE;
                         break;
                     case '2':
                         $atts['grayscale'] = TRUE;
                         break;
                     case '3':
                         $atts['brightness'] = $param[1];
                         break;
                     case '4':
                         $atts['contrast'] = $param[1];
                         break;
                     case '5':
                         $atts['colorize'] = cnColor::rgb2hex2rgb($param[1] . ',' . $param[2] . ',' . $param[3]);
                         break;
                     case '6':
                         $atts['detect_edges'] = TRUE;
                         break;
                     case '7':
                         $atts['emboss'] = TRUE;
                         break;
                     case '8':
                         $atts['gaussian_blur'] = TRUE;
                         break;
                     case '9':
                         $atts['blur'] = TRUE;
                         break;
                     case '10':
                         $atts['sketchy'] = TRUE;
                         break;
                     case '11':
                         $atts['smooth'] = $param[1];
                 }
             }
         }
         if (cnQuery::getVar('s') && cnQuery::getVar('s') === '1') {
             $atts['sharpen'] = TRUE;
         }
         if (cnQuery::getVar('o')) {
             $atts['opacity'] = cnQuery::getVar('o');
         }
         if (cnQuery::getVar('q')) {
             $atts['quality'] = cnQuery::getVar('q');
         }
         if (cnQuery::getVar('cc')) {
             $atts['canvas_color'] = cnQuery::getVar('cc');
         }
         // This needs to be set after the `cc` query var because it should override any value set using the `cc` query var, just like TimThumb.
         if (cnQuery::getVar('ct') && cnQuery::getVar('ct') === '1') {
             $atts['canvas_color'] = 'transparent';
         }
         // Process the image.
         $image = self::get(cnQuery::getVar('src'), $atts, 'editor');
         // If there been an error
         if (is_wp_error($image)) {
             $errors = implode('</li><li>', $image->get_error_messages());
             // Display the error messages.
             header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
             echo '<h1>ERROR/s:</h1><ul><li>' . wp_kses_post($errors) . '</li></ul>';
             exit;
         }
         // Ensure a stream quality is set otherwise we get a block mess as an image when serving a cached image.
         $quality = cnQuery::getVar('q') ? cnQuery::getVar('q') : 90;
         // Ensure valid value for $quality. If invalid valid is supplied reset to the default of 90, matching WP core.
         if (filter_var((int) $quality, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 100))) === FALSE) {
             $quality = 90;
         }
         $image->set_quality($quality);
         $image->stream();
         exit;
     }
 }
 /**
  * Set up the query to only return the entries based on status.
  *
  * @access private
  * @since  0.7.4
  * @static
  *
  * @param array $where
  * @param array $atts
  *
  * @return array
  */
 public static function setQueryStatus($where, $atts = array())
 {
     $valid = array('approved', 'pending');
     $permitted = array('approved');
     $defaults = array('status' => array('approved'));
     $atts = cnSanitize::args($atts, $defaults);
     // Convert the supplied entry statuses $atts['status'] to an array.
     $status = cnFunction::parseStringList($atts['status'], ',');
     if (is_user_logged_in()) {
         // If 'all' was supplied, set the array to all the permitted entry status types.
         if (in_array('all', $status)) {
             $status = $valid;
         }
         // If the current user can edit entries, then they should have permission to view both approved and pending.
         if (current_user_can('connections_edit_entry') || current_user_can('connections_edit_entry_moderated')) {
             $permitted = array('approved', 'pending');
         }
     } else {
         // A non-logged in user should only have permission to view approved entries.
         $status = array('approved');
     }
     $status = array_intersect($permitted, $status);
     // Permit only the supported statuses to be queried.
     $status = array_intersect($status, $valid);
     $where[] = cnQuery::where(array('field' => 'status', 'value' => $status));
     return $where;
 }
 public static function download()
 {
     // Grab an instance of the Connections object.
     $instance = Connections_Directory();
     $process = cnQuery::getVar('cn-process');
     $token = cnQuery::getVar('cn-token');
     $id = absint(cnQuery::getVar('cn-id'));
     if ('vcard' === $process) {
         $slug = cnQuery::getVar('cn-entry-slug');
         //var_dump($slug);
         /*
          * If the token and id values were set, the link was likely from the admin.
          * Check for those values and validate the token. The primary reason for this
          * to be able to download vCards of entries that are set to "Unlisted".
          */
         if (!empty($id) && !empty($token)) {
             if (!wp_verify_nonce($token, 'download_vcard_' . $id)) {
                 wp_die('Invalid vCard Token');
             }
             $entry = $instance->retrieve->entry($id);
             // Die if no entry was found.
             if (empty($entry)) {
                 wp_die(__('vCard not available for download.', 'connections'));
             }
             $vCard = new cnvCard($entry);
             //var_dump($vCard);die;
         } else {
             $entry = $instance->retrieve->entries(array('slug' => $slug));
             //var_dump($entry);die;
             // Die if no entry was found.
             if (empty($entry)) {
                 wp_die(__('vCard not available for download.', 'connections'));
             }
             $vCard = new cnvCard($entry[0]);
             //var_dump($vCard);die;
         }
         $filename = sanitize_file_name($vCard->getName());
         //var_dump($filename);
         $data = $vCard->getvCard();
         //var_dump($data);die;
         header('Content-Description: File Transfer');
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename=' . $filename . '.vcf');
         header('Content-Length: ' . strlen($data));
         header('Pragma: public');
         header("Pragma: no-cache");
         //header( "Expires: 0" );
         header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
         header('Cache-Control: private');
         // header( 'Connection: close' );
         //ob_clean();
         flush();
         echo $data;
         exit;
     }
 }
 /**
  * Run the actions registered to custom content blocks.
  *
  * Render any custom content blocks registered to the `cn_entry_output_content-{id}` action hook.
  *
  * This will also run any actions registered for a custom metaboxes and its fields.
  * The actions should hook into `cn_output_meta_field-{key}` to be rendered.
  *
  * Accepted option for the $atts property are:
  * 	id (string) The custom block ID to render.
  * 	order (mixed) array | string  An indexed array of custom content block IDs that should be rendered in the order in the array.
  * 		If a string is provided, it should be a comma delimited string containing the content block IDs. It will be converted to an array.
  * 	exclude (array) An indexed array of custom content block IDs that should be excluded from being rendered.
  * 	include (array) An indexed array of custom content block IDs that should be rendered.
  * 		NOTE: Custom content block IDs in `exclude` outweigh custom content block IDs in include. Meaning if the
  * 		same custom content block ID exists in both, the custom content block will be excluded.
  *
  * @access public
  * @since 0.8
  * @uses do_action()
  * @uses wp_parse_args()
  * @uses apply_filters()
  * @uses has_action()
  * @param  mixed  $atts array | string [optional] The custom content block(s) to render.
  * @param  array  $shortcode_atts [optional] If this is used within the shortcode template loop, the shortcode atts
  * 		should be passed so the shortcode atts can be passed by do_action() to allow access to the action callback.
  * @param  cnTemplate|null $template [optional] If this is used within the shortcode template loop, the template object
  * 		should be passed so the template object can be passed by do_action() to allow access to the action callback.
  *
  * @return string The HTML output of the custom content blocks.
  */
 public function getContentBlock($atts = array(), $shortcode_atts = array(), $template = NULL)
 {
     $blockContainerContent = '';
     if (cnQuery::getVar('cn-entry-slug')) {
         $settings = cnSettingsAPI::get('connections', 'connections_display_single', 'content_block');
     } else {
         $settings = cnSettingsAPI::get('connections', 'connections_display_list', 'content_block');
     }
     $order = isset($settings['order']) ? $settings['order'] : array();
     $include = isset($settings['active']) ? $settings['active'] : array();
     $exclude = empty($include) ? $order : array();
     $titles = array();
     $defaults = array('id' => '', 'order' => is_string($atts) && !empty($atts) ? $atts : $order, 'exclude' => is_string($atts) && !empty($atts) ? '' : $exclude, 'include' => is_string($atts) && !empty($atts) ? '' : $include, 'layout' => 'list', 'container_tag' => 'div', 'block_tag' => 'div', 'header_tag' => 'h3', 'before' => '', 'after' => '', 'return' => FALSE);
     $atts = wp_parse_args(apply_filters('cn_output_content_block_atts', $atts), $defaults);
     if (!empty($atts['id'])) {
         $blocks = array($atts['id']);
     } elseif (!empty($atts['order'])) {
         $blocks = cnFunction::parseStringList($atts['order'], ',');
     }
     // Nothing to render, exit.
     if (empty($blocks)) {
         return '';
     }
     // Cleanup user input. Trim whitespace and convert to lowercase.
     $blocks = array_map('strtolower', array_map('trim', $blocks));
     // Output the registered action in the order supplied by the user.
     foreach ($blocks as $key) {
         isset($blockNumber) ? $blockNumber++ : ($blockNumber = 1);
         // Exclude/Include the metaboxes that have been requested to exclude/include.
         if (!empty($atts['exclude'])) {
             if (in_array($key, $atts['exclude'])) {
                 continue;
             }
         } else {
             if (!empty($atts['include'])) {
                 if (!in_array($key, $atts['include'])) {
                     continue;
                 }
             }
         }
         ob_start();
         // If the hook has a registered meta data output callback registered, lets run it.
         if (has_action('cn_output_meta_field-' . $key)) {
             // Grab the meta.
             $results = $this->getMeta(array('key' => $key, 'single' => TRUE));
             if (!empty($results)) {
                 do_action("cn_output_meta_field-{$key}", $key, $results, $this, $shortcode_atts, $template);
             }
         }
         // Render the "Custom Fields" meta block content.
         if ('meta' == $key) {
             $this->getMetaBlock(array(), $shortcode_atts, $template);
         }
         $hook = "cn_entry_output_content-{$key}";
         if (has_action($hook)) {
             do_action($hook, $this, $shortcode_atts, $template);
         }
         $blockContent = ob_get_clean();
         if (empty($blockContent)) {
             continue;
         }
         $blockID = $this->getSlug() . '-' . $blockNumber;
         // Store the title in an array that can be accessed/passed from outside the content block loop.
         // And if there is no title for some reason, create one from the key.
         if ($name = cnOptions::getContentBlocks($key)) {
             $titles[$blockID] = $name;
         } elseif ($name = cnOptions::getContentBlocks($key, 'single')) {
             $titles[$blockID] = $name;
         } else {
             $titles[$blockID] = ucwords(str_replace(array('-', '_'), ' ', $key));
         }
         //$titles[ $blockID ] = cnOptions::getContentBlocks( $key ) ? cnOptions::getContentBlocks( $key ) : ucwords( str_replace( array( '-', '_' ), ' ', $key ) );
         $blockContainerContent .= apply_filters('cn_entry_output_content_block', sprintf('<%2$s class="cn-entry-content-block cn-entry-content-block-%3$s" id="cn-entry-content-block-%4$s">%1$s%5$s</%2$s>' . PHP_EOL, sprintf('<%1$s>%2$s</%1$s>', $atts['header_tag'], $titles[$blockID]), $atts['block_tag'], $key, $blockID, $blockContent), $this, $key, $blockID, $titles[$blockID], $blockContent, $atts, $shortcode_atts);
     }
     if (empty($blockContainerContent)) {
         return '';
     }
     $out = apply_filters('cn_entry_output_content_block_container', sprintf('<%1$s class="cn-entry-content-block-%2$s">%3$s</%1$s>' . PHP_EOL, $atts['container_tag'], $atts['layout'], $blockContainerContent), $this, $blockContainerContent, $titles, $atts, $shortcode_atts);
     $out = $atts['before'] . $out . $atts['after'] . PHP_EOL;
     return $this->echoOrReturn($atts['return'], $out);
 }
 /**
  * Display results based on query var `cn-view`.
  *
  * @access public
  * @since  0.7.3
  * @static
  *
  * @uses   cnQuery::getVar()
  *
  * @param array  $atts
  * @param string $content [optional]
  * @param string $tag
  *
  * @return string
  */
 public static function view($atts, $content = '', $tag = 'connections')
 {
     // Grab an instance of the Connections object.
     $instance = Connections_Directory();
     /*$getAllowPublic = $instance->options->getAllowPublic();
     		var_dump($getAllowPublic);
     		$getAllowPublicOverride = $instance->options->getAllowPublicOverride();
     		var_dump($getAllowPublicOverride);
     		$getAllowPrivateOverride = $instance->options->getAllowPrivateOverride();
     		var_dump($getAllowPrivateOverride);*/
     /*
      * Only show this message under the following condition:
      * - ( The user is not logged in AND the 'Login Required' is checked ) AND ( neither of the shortcode visibility overrides are enabled ).
      */
     if (!is_user_logged_in() && !$instance->options->getAllowPublic() && !($instance->options->getAllowPublicOverride() || $instance->options->getAllowPrivateOverride())) {
         $message = $instance->settings->get('connections', 'connections_login', 'message');
         // Format and texturize the message.
         $message = wptexturize(wpautop($message));
         // Make any links and such clickable.
         $message = make_clickable($message);
         // Apply the shortcodes.
         $message = do_shortcode($message);
         return $message;
     }
     $view = cnQuery::getVar('cn-view');
     switch ($view) {
         case 'submit':
             if (has_action('cn_submit_entry_form')) {
                 ob_start();
                 /**
                  * @todo There s/b capability checks just like when editing an entry so users can only submit when they have the permissions.
                  */
                 do_action('cn_submit_entry_form', $atts, $content, $tag);
                 return ob_get_clean();
             } else {
                 return '<p>' . __('Future home of front end submissions.', 'connections') . '</p>';
             }
             break;
         case 'landing':
             return '<p>' . __('Future home of the landing pages, such a list of categories.', 'connections') . '</p>';
             break;
         case 'search':
             if (has_action('cn_submit_search_form')) {
                 ob_start();
                 do_action('cn_submit_search_form', $atts, $content, $tag);
                 return ob_get_clean();
             } else {
                 return '<p>' . __('Future home of the search page.', 'connections') . '</p>';
             }
             break;
         case 'results':
             if (has_action('cn_submit_search_results')) {
                 ob_start();
                 do_action('cn_submit_search_results', $atts, $content, $tag);
                 return ob_get_clean();
             } else {
                 return '<p>' . __('Future home of the search results landing page.', 'connections') . '</p>';
             }
             break;
             // Show the standard result list.
         // Show the standard result list.
         case 'card':
             return cnShortcode_Connections::shortcode($atts, $content);
             break;
             // Show the "View All" result list using the "Names" template.
         // Show the "View All" result list using the "Names" template.
         case 'all':
             // Disable the output of the repeat character index.
             $atts['repeat_alphaindex'] = FALSE;
             // Force the use of the Names template.
             $atts['template'] = 'names';
             return cnShortcode_Connections::shortcode($atts, $content);
             break;
             // Show the entry detail using a template based on the entry type.
         // Show the entry detail using a template based on the entry type.
         case 'detail':
             switch (cnQuery::getVar('cn-process')) {
                 case 'edit':
                     if (has_action('cn_edit_entry_form')) {
                         // Check to see if the entry has been linked to a user ID.
                         $entryID = get_user_meta(get_current_user_id(), 'connections_entry_id', TRUE);
                         // var_dump( $entryID );
                         $results = $instance->retrieve->entries(array('status' => 'approved,pending'));
                         // var_dump( $results );
                         /*
                          * The `cn_edit_entry_form` action should only be executed if the user is
                          * logged in and they have the `connections_manage` capability and either the
                          * `connections_edit_entry` or `connections_edit_entry_moderated` capability.
                          */
                         if (is_user_logged_in() && (current_user_can('connections_manage') || (int) $entryID == (int) $results[0]->id) && (current_user_can('connections_edit_entry') || current_user_can('connections_edit_entry_moderated'))) {
                             ob_start();
                             if (!current_user_can('connections_edit_entry') && $results[0]->status == 'pending') {
                                 echo '<p>' . __('Your entry submission is currently under review, however, you can continue to make edits to your entry submission while your submission is under review.', 'connections') . '</p>';
                             }
                             do_action('cn_edit_entry_form', $atts, $content, $tag);
                             return ob_get_clean();
                         } else {
                             return __('You are not authorized to edit entries. Please contact the admin if you received this message in error.', 'connections');
                         }
                     }
                     break;
                 default:
                     // Ensure an array is passed the the cnRetrieve::entries method.
                     if (!is_array($atts)) {
                         $atts = (array) $atts;
                     }
                     $results = $instance->retrieve->entries($atts);
                     //var_dump($results);
                     $atts['list_type'] = $instance->settings->get('connections', 'connections_display_single', 'template') ? $results[0]->entry_type : NULL;
                     // Disable the output of the following because they do no make sense to display for a single entry.
                     $atts['show_alphaindex'] = FALSE;
                     $atts['repeat_alphaindex'] = FALSE;
                     $atts['show_alphahead'] = FALSE;
                     return cnShortcode_Connections::shortcode($atts, $content);
                     break;
             }
             break;
             // Show the standard result list.
         // Show the standard result list.
         default:
             //return cnShortcode_Connections::shortcode( $atts, $content );
             if (has_action("cn_view_{$view}")) {
                 ob_start();
                 do_action("cn_view_{$view}", $atts, $content, $tag);
                 return ob_get_clean();
             }
             break;
     }
     return cnShortcode_Connections::shortcode($atts, $content);
 }