Esempio n. 1
0
 function cache_shortcode($atts, $content)
 {
     extract(shortcode_atts(array('name' => '', 'expire' => '10 min', 'update' => 'false'), $atts));
     if (empty($name)) {
         return;
     }
     // Needs a transient name
     $result = false;
     if (is_array($atts)) {
         $atts = CCS_Content::get_all_atts($atts);
     }
     $update = isset($atts['update']) ? 'true' : $update;
     if ($update != 'true') {
         $result = self::get_transient($name);
         // get cache if update not true
     }
     if (false === $result) {
         $result = do_shortcode($content);
         self::set_transient($name, $result, $expire);
     }
     return $result;
 }
Esempio n. 2
0
 public static function pass_shortcode($atts, $content, $shortcode_name)
 {
     $args = array('field' => '', 'date_format' => '', 'in' => '', 'fields' => '', 'array' => '', 'debug' => '', 'field_loop' => '', 'taxonomy_loop' => '', 'list' => '', 'acf_gallery' => '', 'current' => '', 'orderby' => '', 'order' => '', 'hide_empty' => 'false', 'pre_render' => 'false', 'post_render' => 'true', 'trim' => 'false', 'count' => '9999', 'user_field' => '', 'user_fields' => '', 'global' => '', 'sub' => '', 'random' => '');
     extract(shortcode_atts($args, $atts, true));
     if ($pre_render == 'true') {
         $content = do_local_shortcode('ccs', $content, true);
     }
     if (CCS_Loop::$state['is_loop']) {
         $post_id = do_shortcode('[field id]');
     } else {
         $post_id = get_the_ID();
     }
     // Support nested
     $prefix = '';
     if (substr($shortcode_name, 0, 2) == '--') {
         $prefix = '--';
     } elseif (substr($shortcode_name, 0, 1) == '-') {
         $prefix = '-';
     }
     if (!empty($date_format)) {
         // Date format: allow escape via "//" because "\" disappears in shortcode parameters
         $date_format = str_replace("//", "\\", $date_format);
     }
     /*---------------------------------------------
      *
      * Pass single field to {FIELD}
      *
      */
     if (!empty($global) && empty($field) && $field != '0') {
         $field = 'this';
     }
     if (!empty($array)) {
         $field = $array;
     }
     if (!empty($field) || $field == '0') {
         if ($field == 'gallery') {
             $field = '_custom_gallery';
         }
         // Support CCS gallery field
         // Pass global variable
         if (!empty($global)) {
             $field_value = '';
             if ($global == 'route') {
                 // Parsed URL route
                 $request = CCS_URL::get_route();
                 $requests = CCS_URL::get_routes();
                 if ($field == 'this') {
                     $field_value = $request;
                     // whole thing
                     for ($i = 0; $i < 6; $i++) {
                         $part = '';
                         if (isset($requests[$i])) {
                             $part = $requests[$i];
                         }
                         $tag = '{' . $prefix . 'FIELD_' . ($i + 1) . '}';
                         $content = str_replace($tag, $part, $content);
                     }
                 } else {
                     if (isset($requests[intval($field)])) {
                         $field_value = $requests[intval($field)];
                     }
                 }
             } elseif ($global == 'query') {
                 // Parsed query string
                 $field_value = CCS_URL::get_query();
                 $query_array = CCS_URL::get_queries();
                 foreach ($query_array as $key => $value) {
                     $tag = '{' . $prefix . strtoupper($key) . '}';
                     $content = str_replace($tag, $value, $content);
                 }
                 if (!empty($fields)) {
                     // Remove what was not rendered
                     $fields = CCS_Loop::explode_list($fields);
                     foreach ($fields as $key) {
                         $tag = '{' . $prefix . strtoupper($key) . '}';
                         $content = str_replace($tag, '', $content);
                     }
                     $fields = '';
                 } elseif (!empty($field)) {
                     $tag = '{' . $prefix . 'FIELD' . '}';
                     $value = isset($query_array[$field]) ? $query_array[$field] : '';
                     $content = str_replace($tag, $value, $content);
                 }
             } else {
                 if ($field == 'this' && isset($GLOBALS[$global])) {
                     $field_value = $GLOBALS[$global];
                 } elseif (!empty($sub) && isset($GLOBALS[$global][$field][$sub])) {
                     $field_value = $GLOBALS[$global][$field][$sub];
                 } elseif (isset($GLOBALS[$global][$field])) {
                     $field_value = $GLOBALS[$global][$field];
                 }
             }
             // end global
             // Repeater or flexible content field
         } elseif (class_exists('CCS_To_ACF') && CCS_To_ACF::$state['is_repeater_or_flex_loop']) {
             if ($field == 'index') {
                 $field_value = CCS_To_ACF::$state['repeater_index'];
             } elseif (function_exists('get_sub_field')) {
                 $field_value = get_sub_field($field);
             } else {
                 $field_value = null;
             }
             // Predefined or custom field
         } else {
             $field_value = CCS_Content::get_prepared_field($field, $post_id);
         }
         if (is_array($field_value)) {
             if (!empty($array)) {
                 if ($debug == 'true') {
                     ob_start();
                     echo '<pre><code>';
                     print_r($field_value);
                     echo '</code></pre>';
                     return ob_get_clean();
                 }
                 // array parameter
                 foreach ($field_value as $key => $value) {
                     $content = str_replace('{' . strtoupper($key) . '}', $value, $content);
                 }
             } else {
                 // field parameter
                 foreach ($field_value as $key => $value) {
                     $content = str_replace('{' . $prefix . 'FIELD:' . strtoupper($key) . '}', $value, $content);
                 }
             }
             //$field_value = '(Array)';
             $field_value = implode(",", $field_value);
         } else {
             // Clean extra spaces if it's a list
             $field_value = CCS_Loop::clean_list($field_value);
         }
         if (!empty($date_format)) {
             // Date format for custom field
             if (!empty($in) && $in == 'timestamp' && is_numeric($field_value)) {
                 $field_value = gmdate("Y-m-d H:i:s", $field_value);
             }
             if ($date_format == 'true') {
                 $date_format = get_option('date_format');
             }
             $field_value = mysql2date($date_format, $field_value);
         }
         // Replace it
         $content = str_replace('{' . $prefix . 'FIELD}', $field_value, $content);
         /*---------------------------------------------
          *
          * Pass each item in a list stored in a field
          *
          */
     } elseif (!empty($field_loop)) {
         if ($field_loop == 'gallery' && class_exists('CCS_Gallery_Field')) {
             // Support gallery field
             $field_values = CCS_Gallery_Field::get_image_ids();
         } else {
             $field_values = get_post_meta($post_id, $field_loop, true);
         }
         if (!empty($field_values)) {
             if (!is_array($field_values)) {
                 $field_values = CCS_Loop::explode_list($field_values);
             }
             // Get comma-separated list of values
             $contents = null;
             // Loop for the number of field values
             foreach ($field_values as $field_value) {
                 $contents[] = str_replace('{' . $prefix . 'FIELD}', $field_value, $content);
             }
             $content = implode('', $contents);
         }
         /*---------------------------------------------
          *
          * Pass image IDs from ACF gallery
          *
          */
     } elseif (!empty($acf_gallery)) {
         if (function_exists('get_field') && function_exists('get_sub_field')) {
             $field = $acf_gallery;
             $images = get_field($acf_gallery, $post_id, false);
             if (empty($field_value)) {
                 // Try sub field
                 $images = get_sub_field($acf_gallery, $post_id, false);
             }
             if (!empty($images)) {
                 $ids = array();
                 foreach ($images as $image) {
                     $ids[] = $image['id'];
                 }
                 if (is_array($ids)) {
                     $replace = implode(',', $ids);
                 } else {
                     $replace = $ids;
                 }
                 $content = str_replace('{' . $prefix . 'FIELD}', $replace, $content);
             }
         }
         /*---------------------------------------------
          *
          * Pass each taxonomy term
          *
          */
     } elseif (!empty($taxonomy_loop)) {
         if ($current == 'true') {
             if (empty($orderby) && empty($order)) {
                 // Doesn't accept order/orderby parameters - but it's cached
                 $terms = get_the_terms($post_id, $taxonomy_loop);
             } else {
                 $terms = wp_get_object_terms($post_id, $taxonomy_loop, array('orderby' => empty($orderby) ? 'name' : $orderby, 'order' => empty($order) ? 'ASC' : strtoupper($order)));
             }
         } else {
             // Get all terms: not by post ID
             $terms = get_terms($taxonomy_loop, array('orderby' => empty($orderby) ? 'name' : $orderby, 'order' => empty($order) ? 'ASC' : strtoupper($order), 'hide_empty' => $hide_empty == 'true'));
         }
         $contents = '';
         // Loop through each term
         if (!empty($terms)) {
             $i = 0;
             foreach ($terms as $term) {
                 if ($i++ >= $count) {
                     break;
                 }
                 $slug = $term->slug;
                 $id = $term->term_id;
                 $name = $term->name;
                 $replaced_content = str_replace('{' . $prefix . 'TERM}', $slug, $content);
                 $replaced_content = str_replace('{' . $prefix . 'TERM_ID}', $id, $replaced_content);
                 $replaced_content = str_replace('{' . $prefix . 'TERM_NAME}', $name, $replaced_content);
                 $contents .= $replaced_content;
             }
         }
         $content = $contents;
         /*---------------------------------------------
          *
          * Pass an arbitrary list of items
          *
          */
     } elseif (!empty($list)) {
         $items = CCS_Loop::explode_list($list);
         // Comma-separated list -> array
         // Create range
         $new_items = array();
         foreach ($items as $item) {
             if (strpos($item, '~') !== false) {
                 $pair = CCS_Loop::explode_list($item, '~');
                 $list = range($pair[0], $pair[1]);
                 foreach ($list as $list_item) {
                     $new_items[] = $list_item;
                 }
             } else {
                 $new_items[] = $item;
             }
         }
         $items = $new_items;
         $contents = '';
         foreach ($items as $item) {
             $replaced_content = $content;
             // Multiple items per loop
             if (strpos($item, ':') !== false) {
                 $parts = explode(':', $item);
                 $count = count($parts);
                 for ($i = 0; $i < $count; $i++) {
                     $this_item = trim($parts[$i]);
                     // Index starts at ITEM_1
                     $replaced_content = str_replace('{' . $prefix . 'ITEM_' . ($i + 1) . '}', $this_item, $replaced_content);
                     // Would this be useful?
                     // $replaced_content = str_replace('{Item_'.$i.'}', ucfirst($this_item),
                     //  $replaced_content);
                 }
             } else {
                 $replaced_content = str_replace('{' . $prefix . 'ITEM}', $item, $replaced_content);
                 $replaced_content = str_replace('{' . $prefix . 'Item}', ucfirst($item), $replaced_content);
             }
             $contents .= $replaced_content;
         }
         $content = $contents;
     }
     /*---------------------------------------------
      *
      * Pass user field(s)
      *
      */
     if (!empty($user_field)) {
         $user_field_value = do_shortcode('[user ' . $user_field . ' out="slug"]');
         // Replace it
         $content = str_replace('{' . $prefix . 'USER_FIELD}', $user_field_value, $content);
     }
     if (!empty($user_fields)) {
         $user_fields_array = CCS_Loop::explode_list($user_fields);
         foreach ($user_fields_array as $this_field) {
             $user_field_value = do_shortcode('[user ' . $this_field . ' out="slug"]');
             // Replace {FIELD_NAME}
             $content = str_replace('{' . $prefix . strtoupper($this_field) . '}', $user_field_value, $content);
         }
     }
     if (!empty($random)) {
         $content = str_replace('{' . $prefix . 'RANDOM}', do_shortcode('[random ' . $random . ']'), $content);
     }
     if (!empty($fields)) {
         if (!empty($global)) {
             $fields = CCS_Loop::explode_list($fields);
             foreach ($fields as $this_field) {
                 $tag = '{' . $prefix . strtoupper($this_field) . '}';
                 $value = '';
                 if (isset($GLOBALS[$global][$this_field])) {
                     $value = $GLOBALS[$global][$this_field];
                 }
                 $content = str_replace($tag, $value, $content);
             }
         } else {
             // Replace these fields (+default)
             $content = CCS_Loop::render_field_tags($content, array('fields' => $fields));
         }
     } else {
         $content = CCS_Loop::render_default_field_tags($content);
     }
     if ($post_render == 'true') {
         $content = do_local_shortcode('ccs', $content, true);
     }
     // Trim trailing white space and comma
     if ($trim != 'false') {
         if ($trim == 'true') {
             $trim = null;
         }
         $content = rtrim($content, " \t\n\r\v," . $trim);
     }
     return $content;
 }
Esempio n. 3
0
 function is_shortcode($atts, $content, $tag)
 {
     global $post;
     extract(shortcode_atts(array('user' => '', 'format' => 'false', 'shortcode' => 'true', 'role' => '', 'capable' => '', 'compare' => 'OR', 'device' => ''), $atts));
     $condition = false;
     // Load user info
     // NOTE: Don't change $current_user
     if (self::$state['is_users_loop'] && isset(self::$state['current_user_object'])) {
         $u = self::$state['current_user_object'];
     } else {
         //get_currentuserinfo();
         $current_user = wp_get_current_user();
         $u = $current_user;
     }
     // Get [else] if it exists
     $content_array = explode('[else]', $content);
     $content = $content_array[0];
     if (count($content_array) > 1) {
         $else = $content_array[1];
     } else {
         $else = null;
     }
     if (!empty($user)) {
         $user_array = explode(',', $user);
         foreach ($user_array as $this_user) {
             $this_user = trim($this_user);
             if ($this_user == $u->user_login) {
                 $condition = true;
             } elseif (is_numeric($this_user) && $this_user == $u->ID) {
                 // User ID
                 $condition = true;
             }
         }
     }
     if (!empty($role)) {
         $current_roles = $u->roles;
         // an array of roles
         $condition = false;
         // check each role
         $check_roles = explode(',', $role);
         foreach ($check_roles as $check_role) {
             $check_role = trim($check_role);
             if (in_array($check_role, $current_roles)) {
                 $condition = true;
             } elseif ($compare == 'AND') {
                 $condition = false;
             }
         }
     }
     if (!empty($capable)) {
         $capables = explode(',', $capable);
         foreach ($capables as $capability) {
             $check_capable = trim($capability);
             if (user_can($u, $check_capable)) {
                 $condition = true;
             } elseif ($compare == 'AND') {
                 $condition = false;
             }
         }
     }
     if (is_array($atts)) {
         $atts = CCS_Content::get_all_atts($atts);
     }
     if (isset($atts['admin']) && user_can($u, 'manage_options') || isset($atts['login']) && is_user_logged_in() || isset($atts['logout']) && !is_user_logged_in()) {
         $condition = true;
     }
     if (isset($atts['author'])) {
         // If user is the author of current post
         if (!empty($post)) {
             if ($post->post_author == $u->ID) {
                 $condition = true;
             }
         }
     }
     if (class_exists('CCS_Mobile_Detect')) {
         if (!empty($device)) {
             $condition = strtolower(CCS_Mobile_Detect::$device) == strtolower($device);
         } elseif (isset($atts['mobile'])) {
             $condition = CCS_Mobile_Detect::$is_mobile;
         } elseif (isset($atts['phone'])) {
             $condition = CCS_Mobile_Detect::$device_type == 'phone';
         } elseif (isset($atts['tablet'])) {
             $condition = CCS_Mobile_Detect::$device_type == 'tablet';
         } elseif (isset($atts['computer'])) {
             $condition = CCS_Mobile_Detect::$device_type == 'computer';
         }
     }
     if ($tag == 'isnt' || isset($atts['not'])) {
         $condition = !$condition;
     }
     if (!$condition) {
         $content = $else;
         // Everything after [else]
     }
     if ($format == 'true') {
         // Format?
         $content = wpautop($content);
     }
     if ($shortcode != 'false') {
         // Shortcode?
         $content = do_ccs_shortcode($content);
     }
     return $content;
 }
Esempio n. 4
0
 static function array_field_shortcode($atts, $content, $shortcode_name)
 {
     $out = null;
     $array = null;
     $prev_state = self::$state;
     $prefix = CCS_Format::get_minus_prefix($shortcode_name);
     extract(shortcode_atts(array('field' => '', 'user_field' => '', 'each' => 'false', 'debug' => 'false', 'global' => '', 'json' => '', 'choices' => '', 'type' => '', 'name' => '', 'trim' => ''), $atts));
     if (!empty($global)) {
         $field = 'GLOBAL';
     } elseif (!empty($choices)) {
         $field = $choices;
     } elseif (isset($atts) && !empty($atts[0])) {
         $field = $atts[0];
     }
     // Inside ACF repeater/flex
     if (class_exists('CCS_To_ACF') && CCS_To_ACF::$state['is_repeater_or_flex_loop'] && $field != 'GLOBAL') {
         // Get sub field
         if (function_exists('get_sub_field')) {
             $array = get_sub_field($field);
         }
     } else {
         if ($field == 'GLOBAL') {
             $array = $GLOBALS[$global];
             if (!is_array($array)) {
                 $array = array('value' => $array);
             }
         } elseif (!empty($choices)) {
             // ACF checkbox/select/radio choices
             // Needs field key
             if (substr($choices, 0, 6) == 'field_') {
                 $key = $choices;
             } else {
                 $cmd = '[loop';
                 if (!empty($name)) {
                     $cmd .= ' name="' . $name . '"';
                 } else {
                     if (empty($type)) {
                         $type = get_post_type();
                         if (!$type) {
                             $type = 'post';
                         }
                     }
                     $cmd .= ' type=' . $type;
                 }
                 $key = do_ccs_shortcode($cmd . ' count=1][field _' . $choices . '][/loop]');
             }
             $field = get_field_object($key);
             if ($debug == 'true') {
                 $array = $field;
             } else {
                 $array = array();
                 if ($field) {
                     foreach ($field['choices'] as $key => $value) {
                         $array[] = array('value' => $key, 'label' => $value);
                     }
                     $each = 'true';
                 }
             }
             // User field
         } elseif (!empty($user_field)) {
             $array = CCS_User::get_user_field($user_field);
             // Normal field
         } else {
             if (self::$state['is_array_field']) {
                 // Nested array
                 $array = self::$state['current_field_value'];
                 $array = isset($array[$field]) ? $array[$field] : '';
                 //debug_array($array);
             } else {
                 $id = do_shortcode('[field id]');
                 $array = get_post_meta($id, $field, true);
             }
         }
         // Not array
         if (!empty($array) && !is_array($array)) {
             // See if it's an ACF field
             if (function_exists('get_field')) {
                 $array = get_field($field);
             }
         }
     }
     if ($json == 'true') {
         $array = json_decode($array, true);
     }
     if ($debug == 'true') {
         $out = self::print_array($array, false);
     }
     if (!empty($array) && is_array($array)) {
         self::$state['is_array_field'] = true;
         self::$state['array_field_index'] = 0;
         if ($each != 'true') {
             $array = array($array);
             // Create a single array
         }
         self::$state['array_field_count'] = count($array);
         foreach ($array as $each_array) {
             self::$state['current_field_value'] = $each_array;
             self::$state['array_field_index']++;
             // Starts from 1
             $this_content = $content;
             if (!empty($choices)) {
                 $this_content = str_replace('{VALUE}', @$each_array['value'], $content);
                 $this_content = str_replace('{LABEL}', @$each_array['label'], $this_content);
             }
             $this_content = str_replace('{' . $prefix . 'ARRAY_INDEX}', self::$state['array_field_index'], $this_content);
             $out .= do_ccs_shortcode($this_content);
         }
         self::$state['is_array_field'] = false;
     } else {
         $out = $array;
         // Empty or not array
     }
     if (is_array($out)) {
         $out = '[ Array ]';
     } elseif ($trim == 'true') {
         $out = trim($out, " \t\n\r\v,");
     }
     self::$state = $prev_state;
     return $out;
 }
Esempio n. 5
0
 static function url_shortcode($atts)
 {
     $urls = self::$urls;
     $url = null;
     extract(shortcode_atts(array('login' => '', 'logout' => '', 'go' => ''), $atts));
     if (empty($atts)) {
         $atts[0] = 'site';
     }
     $arg = $atts[0];
     // Allow checking empty parameters
     if (is_array($atts)) {
         $atts = CCS_Content::get_all_atts($atts);
     }
     // Find where to go after login/out
     if ($go == 'here' || isset($atts['logout']) && empty($go)) {
         $go = home_url(self::$route);
         // Current page URL
     } elseif (!empty($go)) {
         if ($go == 'home') {
             $go = isset($urls['home']) ? $urls['home'] : ($urls['home'] = get_option('home'));
         } elseif ($arg == 'login' || $arg == 'logout') {
             if (!strpos($go, ".")) {
                 // Go to page URL by slug
                 $go = do_shortcode('[content name="' . $go . '" field="url"]');
             } elseif (substr($go, 0, 4) !== 'http') {
                 // Make sure URL has http://
                 $go = 'http://' . $go;
             }
         }
     }
     if (isset($urls[$arg])) {
         // cached
         return untrailingslashit($urls[$arg]);
     }
     switch ($arg) {
         case 'wordpress':
             $url = $urls[$arg] = get_option('siteurl');
             break;
         case 'content':
             $url = $urls[$arg] = content_url();
             break;
         case 'admin':
             $url = $urls[$arg] = admin_url();
             break;
         case 'parent':
             // Parent Theme
         // Parent Theme
         case 'theme':
             $url = $urls[$arg] = get_bloginfo('template_directory');
             break;
         case 'child':
             $url = $urls[$arg] = get_bloginfo('stylesheet_directory');
             break;
         case 'uploads':
             // Get uploads directory
             $upload_dir = wp_upload_dir();
             if (!$upload_dir['error']) {
                 $url = $urls[$arg] = $upload_dir['baseurl'];
             } elseif ($url = get_option('upload_url_path')) {
                 // Prior to WordPress 3.5, this was set in Settings > Media > Full URL path to files
                 // In WordPress 3.5+ this is now hidden
                 $urls[$arg] = $url;
             } else {
                 $url = $urls[$arg] = get_option('siteurl') . '/' . get_option('upload_path');
             }
             break;
         case 'layout':
             $url = $urls[$arg] = content_url() . '/' . $arg;
             break;
         case 'views':
             if (defined('VIEWS_URL')) {
                 $url = VIEWS_URL;
             } else {
                 $url = $urls[$arg] = content_url() . '/' . $arg;
             }
             break;
         case 'login':
             // Don't cache, as go parameter could be different
             $url = wp_login_url($go);
             break;
         case 'logout':
             // Don't cache, as go parameter could be different
             $url = wp_logout_url($go);
             break;
         case 'current':
             // Current page URL
             $url = $urls[$arg] = home_url(self::$route);
             break;
         case 'home':
         default:
             $url = $urls[$arg] = get_option('home');
             break;
     }
     self::$urls = $urls;
     // Store it for later
     return untrailingslashit($url);
 }
Esempio n. 6
0
 public static function sort_gallery_by_title($a, $b)
 {
     $a_title = CCS_Content::wp_get_attachment_field($a, 'title');
     $b_title = CCS_Content::wp_get_attachment_field($b, 'title');
     return $a_title < $b_title ? -1 : 1;
 }
Esempio n. 7
0
 function if_shortcode($atts, $content = null, $shortcode_name)
 {
     $atts_original = $atts;
     $args = array('type' => '', 'name' => '', 'id' => '', 'author' => '', 'comment_author' => '', 'category' => '', 'tag' => '', 'taxonomy' => '', 'term' => '', 'compare' => '', 'tax_archive' => '', 'parent' => '', 'field' => '', 'custom' => '', 'user_field' => '', 'check' => '', 'value' => '', 'before' => '', 'after' => '', 'date_format' => '', 'in' => '', 'field_2' => '', 'today' => '', 'day_of_week' => '', 'lowercase' => '', 'case' => '', 'loose' => '', 'strict' => '', 'sub' => '', 'format' => '', 'contains' => '', 'exact' => '', 'empty' => 'true', 'zero' => '', 'sticky' => '', 'not' => '', 'start' => '', 'end' => '', 'every' => '', 'first' => '', 'last' => '', 'count' => '', 'each' => '', 'each_field' => '', 'each_value' => '', 'decode' => '', 'x' => '', 'query' => '', 'route' => '', 'pass' => '', 'false' => '', 'pass_empty' => 'true', 'flag' => '', 'no_flag' => '');
     extract(shortcode_atts($args, $atts, true));
     $atts = CCS_Content::get_all_atts($atts);
     if (isset($atts['and'])) {
         return self::if_all_conditions($atts, $content, $shortcode_name);
     }
     if (count($atts) == 0) {
         $condition = true;
     } else {
         $condition = false;
     }
     $out = '';
     // Get [else] block
     $if_else = self::get_if_else($content, $shortcode_name);
     $content = $if_else['if'];
     $else = $if_else['else'];
     if ((!empty($before) || !empty($after)) && empty($field)) {
         $field = 'date';
         // Default for before/after parameter
     }
     if (!empty($no_flag)) {
         $flag = $no_flag;
     }
     $compare = strtoupper($compare);
     if ($strict == 'true') {
         $loose = 'false';
     }
     // Alias
     if ($case == 'true') {
         $lowercase = 'false';
     }
     // Alias
     /*---------------------------------------------
      *
      * Get global post info
      *
      */
     $current_post_id = do_shortcode('[field id]');
     $post = get_post($current_post_id);
     /*---------------------------------------------
      *
      * If exists
      *
      */
     if (isset($atts['exists'])) {
         unset($atts['exists']);
         if (empty($atts)) {
             $result = do_ccs_shortcode($content);
         } else {
             // Check if post exists based on given parameters
             $result = CCS_Loop::the_loop_shortcode($atts_original, 'X');
             // Remove params for rest of condition checks
             $atts = array();
         }
         $result = trim($result);
         $condition = !empty($result);
     }
     /*---------------------------------------------
      *
      * Today
      *
      */
     if (!empty($day_of_week)) {
         $today = $day_of_week;
         $date_format = 'N';
         // 1~7, Mon~Sun
     }
     if (!empty($today)) {
         $result = do_ccs_shortcode('[today' . (!empty($date_format) ? ' format="' . $date_format . '"' : '') . ']');
         $condition = $result === $today;
     }
     /*---------------------------------------------
      *
      * Taxonomy: category, tags, ..
      *
      */
     if (!empty($category)) {
         $taxonomy = "category";
         $term = $category;
     }
     if (!empty($tag)) {
         $taxonomy = "post_tag";
         $term = $tag;
     }
     // Check if current post has taxonomy term
     if (!empty($taxonomy)) {
         if ($taxonomy == 'tag') {
             $taxonomy = 'post_tag';
         }
         $taxonomies = wp_get_post_terms($current_post_id, $taxonomy, array());
         $post_tax_array = array();
         foreach ($taxonomies as $term_object) {
             if (is_object($term_object)) {
                 $post_tax_array[] = $term_object->slug;
             }
         }
         $terms = self::comma_list_to_array($term);
         if (empty($term) && count($post_tax_array)) {
             // If no term query is set, then check if there's any term
             $condition = true;
         } else {
             foreach ($terms as $term) {
                 if (empty($compare) || $compare == 'OR') {
                     $condition = in_array($term, $post_tax_array) ? true : $condition;
                 } else {
                     // AND
                     $condition = in_array($term, $post_tax_array) ? true : false;
                     if (!$condition) {
                         break;
                     }
                     // Every term must be found
                 }
             }
         }
     }
     /*---------------------------------------------
      *
      * Inside [for/each] loop
      *
      */
     // Check if current term has children
     if (CCS_ForEach::$state['is_for_loop']) {
         if (isset($atts['children'])) {
             $current_term = CCS_ForEach::$current_term[CCS_ForEach::$index];
             $current_taxonomy = $current_term['taxonomy'];
             $terms = get_terms($current_taxonomy, array('parent' => $current_term['id']));
             if (!empty($terms) && $terms != array()) {
                 $condition = true;
             } else {
                 $condition = false;
             }
         }
         if (!empty($each)) {
             $v = do_shortcode('[each slug]');
             if ($decode == 'true') {
                 $v = urldecode($v);
             }
             $eaches = CCS_Loop::explode_list($each);
             $condition = in_array($v, $eaches);
         }
         if (!empty($each_field)) {
             $v = do_shortcode('[each ' . $each_field . ']');
             if ($decode == 'true') {
                 $v = urldecode($v);
             }
             if (!empty($each_value)) {
                 $condition = $v == $each_value;
             } else {
                 $condition = !empty($v);
             }
         }
         if (isset($atts['for-first'])) {
             $condition = $condition || CCS_ForEach::$state['for_count'] == 1;
         }
     }
     /*---------------------------------------------
      *
      * Field value contains
      *
      */
     if (!empty($contains)) {
         if ($exact === 'true') {
             $value = $contains;
         } else {
             $value = implode(',', explode(' ', $contains));
         }
         $contains_compare = !empty($compare) ? strtoupper($compare) : '';
         $compare = 'CONTAINS';
         if (empty($loose)) {
             $loose = 'true';
         }
         // Loose search by default
         $field = CCS_Loop::explode_list($field);
         if (count($field) > 1) {
             // Support searching multiple fields
             foreach ($field as $this_field) {
                 $condition = '[if field=' . $this_field . ' contains="' . $value . '"' . (!empty($contains_compare) ? ' compare=' . $contains_compare : '') . '].[/if]';
                 $condition = do_shortcode($condition);
                 $condition = !empty($condition);
                 if ($condition) {
                     break;
                 }
                 // If keyword in any of the fields
             }
             $field = '';
             // Skip default field value condition
         } else {
             $field = $field[0];
         }
     }
     /*---------------------------------------------
      *
      * Field: field="field_slug" value="this,that"
      *
      */
     if (!empty($field) || !empty($user_field) || !empty($check)) {
         // Post field
         if (!empty($field)) {
             if ($in == 'timestamp') {
                 $date_format = 'U';
                 if ($value == 'today') {
                     $value = 'today-between';
                 }
             }
             if ($field == 'date') {
                 if (empty($date_format)) {
                     $date_format = 'Ymd';
                 }
                 // Published date
                 $check = strtotime($post->post_date . ' +0000');
                 $check = date($date_format, $check);
             } elseif ($field == 'excerpt') {
                 $check = get_the_excerpt();
                 $empty = 'true';
                 $value = '';
                 // ?
             } elseif ($custom == 'true') {
                 $check = get_post_meta($current_post_id, $field, $single = true);
             } else {
                 // Normal field
                 $check = CCS_Content::get_prepared_field($field);
                 // do_shortcode('[field '.$field.']');// ;
             }
             // Date field
             if (!empty($before) || !empty($after)) {
                 if (!empty($field_2)) {
                     $field_2 = CCS_Content::get_prepared_field($field_2);
                     // Convert to imestamp
                     if ($in !== 'timestamp') {
                         $field_2 = strtotime($field_2 . ' +0000');
                     }
                     $now = intval($field_2);
                     //echo 'FIELD2:'.$field_2.' = '.$now.'<br>';
                 } else {
                     $now = current_time('timestamp');
                 }
                 if (!empty($before) && !empty($after)) {
                     $value_before = date($date_format, strtotime($before . ' +0000', $now));
                     $value_after = date($date_format, strtotime($after . ' +0000', $now));
                     $value = $value_before . ' - ' . $value_after;
                     $compare = 'BETWEEN';
                 } elseif (!empty($before)) {
                     $value = date($date_format, strtotime($before . ' +0000', $now));
                     $compare = empty($compare) ? '<' : $compare;
                 } elseif (!empty($after)) {
                     $value = date($date_format, strtotime($after . ' +0000', $now));
                     $compare = empty($compare) ? '>' : $compare;
                     //echo 'VALUE: '.$now.' '.$after.' = '.$value.'<br>';
                 }
             } elseif (!empty($field_2)) {
                 // Use second field as value
                 $value = CCS_Content::get_prepared_field($field_2);
                 if (!empty($date_format)) {
                     $check = date($date_format, strtotime($check . ' +0000'));
                     $value = date($date_format, strtotime($value . ' +0000'));
                 }
             }
             // User field
         } elseif (!empty($user_field)) {
             $field = $user_field;
             $check = CCS_User::get_user_field($field);
             if (!empty($sub)) {
                 $check = isset($check[$sub]) ? $check[$sub] : '';
             }
         } else {
             // Just check passed value
             // $check == $value
         }
         // Array
         if (!empty($sub)) {
             $check = isset($check[$sub]) ? $check[$sub] : '';
         }
         // start=".." end=".."
         if (!empty($start) && !empty($end)) {
             $value = $start . '..' . $end;
             // Placeholder
             $start_value = $start;
             $end_value = $end;
             $start = 'true';
             $end = 'true';
             // start=".."
         } elseif (!empty($start) && $start != 'true' && empty($value)) {
             $value = $start;
             $start = 'true';
             // end=".."
         } elseif (!empty($end) && $end != 'true' && empty($value)) {
             $value = $end;
             $end = 'true';
         }
         if ($check === '') {
             // ( empty($check) || ( $check == false ) ) {
             // @todo What if field value is boolean, i.e., checkbox?
             $condition = false;
         } else {
             if (!is_array($check)) {
                 $check = array($check);
             }
             if ($value !== '') {
                 // Allow false, 0
                 $values = self::comma_list_to_array($value);
                 $date_values = array('today', 'today-between', 'now', 'future', 'past', 'future not today', 'past and today', 'future-time', 'past-time');
                 foreach ($check as $check_this) {
                     if ($decode == 'true') {
                         $check_this = urldecode($check_this);
                     }
                     foreach ($values as $this_value) {
                         if (in_array($this_value, $date_values)) {
                             if (empty($date_format)) {
                                 $date_format = 'Ymd';
                             }
                             // ACF date field
                             // Support date values
                             $q = array('field' => $check_this, 'value' => $this_value, 'compare' => $compare, 'date_format' => $date_format);
                             $meta_query = CCS_Loop::prepare_meta_query($q);
                             $check_this = $meta_query['key'];
                             $this_value = $meta_query['value'];
                             $compare = $meta_query['compare'];
                             //debug_array($q);
                             if (is_array($this_value)) {
                                 $this_value = implode(',', $this_value);
                             }
                         }
                         //echo 'Check field: '.$field.' '.$check_this.' '.$compare.' '.$this_value.'<br>';
                         if ($start == 'true' && $end == 'true') {
                             // Check beginning and end of field value
                             if (substr($check_this, 0, strlen($start_value)) == $start_value && substr($check_this, strlen($check_this) - strlen($end_value)) == $end_value) {
                                 $condition = true;
                                 continue;
                             } else {
                                 $condition = false;
                                 break;
                             }
                         } elseif ($start == 'true') {
                             // Only check beginning of field value
                             $check_this = substr($check_this, 0, strlen($this_value));
                         } elseif ($end == 'true') {
                             // Only check end of field value
                             $check_this = substr($check_this, strlen($check_this) - strlen($this_value));
                         }
                         if ($loose == 'true') {
                             $check_this = CCS_Format::normalize_alphabet($check_this);
                             $this_value = CCS_Format::normalize_alphabet($this_value);
                         }
                         if ($loose == 'true' || $lowercase == 'true') {
                             $check_this = strtolower($check_this);
                             $this_value = strtolower($this_value);
                         }
                         if ($compare == 'AND') {
                             $condition = $this_value == $check_this ? true : false;
                             if (!$condition) {
                                 break;
                             }
                             // Every term must be found
                         } elseif ($compare == 'CONTAINS') {
                             $condition = strpos($check_this, $this_value) !== false;
                             if ($contains_compare != 'OR' && !$condition) {
                                 break;
                                 // Every term must be found
                             }
                         } else {
                             switch ($compare) {
                                 case 'MORE':
                                 case 'NEW':
                                 case 'NEWER':
                                 case '>':
                                     $condition = $check_this > $this_value ? true : $condition;
                                     break;
                                 case '>=':
                                     $condition = $check_this >= $this_value ? true : $condition;
                                     break;
                                 case 'LESS':
                                 case 'OLD':
                                 case 'OLDER':
                                 case '<':
                                     $condition = $check_this < $this_value ? true : $condition;
                                     break;
                                 case '<=':
                                     $condition = $check_this <= $this_value ? true : $condition;
                                     break;
                                 case 'BETWEEN':
                                     $values = explode(' - ', $this_value);
                                     // Hmm..to avoid conflict with ','
                                     if (isset($values[0]) && isset($values[1])) {
                                         $condition = $values[0] <= $check_this && $check_this <= $values[1] ? true : $condition;
                                     }
                                     break;
                                 case 'EQUAL':
                                 case '=':
                                 default:
                                     $condition = $check_this == $this_value ? true : $condition;
                                     break;
                             }
                         }
                         // End compare
                     }
                     // End for each value
                 }
                 // End for each check
             } else {
                 // No value specified - just check that there is field value
                 if ($empty == 'true') {
                     if (is_array($check)) {
                         $check = implode('', $check);
                     }
                     // catches ACF repeater
                     $condition = !empty($check) ? true : false;
                 } else {
                     $condition = false;
                 }
             }
         }
         // End if check not empty
     }
     // End field value condition
     /*---------------------------------------------
      *
      * Post type, name, id
      *
      */
     if (!empty($type)) {
         $types = self::comma_list_to_array($type);
         // Enable comma-separated list
         $current_post_type = isset($post->post_type) ? $post->post_type : null;
         $condition = in_array($current_post_type, $types) ? true : false;
     }
     if (!empty($id)) {
         $ids = self::comma_list_to_array($id);
         // Enable comma-separated list
         if (($find_key = array_search('this', $ids)) !== false) {
             $depth = CCS_Content::$state['depth'];
             if (isset(CCS_Content::$state['current_post_id'][$depth - 1])) {
                 $ids[$find_key] = CCS_Content::$state['current_post_id'][$depth - 1];
             } elseif (CCS_Loop::$state['is_loop']) {
                 $ids[$find_key] = CCS_Loop::$state['original_post_id'];
             } else {
                 $ids[$find_key] = get_the_ID();
             }
         }
         $condition = in_array($current_post_id, $ids) ? true : false;
     }
     if (!empty($name)) {
         $names = self::comma_list_to_array($name);
         $current_post_name = isset($post->post_name) ? $post->post_name : null;
         foreach ($names as $each_name) {
             if ($start == 'true') {
                 // Only check beginning of string
                 $this_value = substr($current_post_name, 0, strlen($each_name));
             } else {
                 $this_value = $current_post_name;
             }
             $condition = $this_value == $each_name ? true : $condition;
         }
     }
     /*---------------------------------------------
      *
      * Post author
      *
      */
     if (!empty($author)) {
         $authors = CCS_Loop::explode_list($author);
         $author_ids = array();
         foreach ($authors as $this_author) {
             if ($this_author == 'this') {
                 // current author ID
                 $author_ids[] = do_shortcode('[user id]');
             } elseif (is_numeric($this_author)) {
                 $author_ids[] = $this_author;
             } else {
                 // get author ID from user name
                 $author_ids[] = do_shortcode('[users search=' . $this_author . ' search_column=login][user id][/users]');
             }
         }
         if (CCS_Comments::$state['is_comments_loop']) {
             $post_id = do_shortcode('[comment post-id]');
         } else {
             $post_id = do_shortcode('[field id]');
         }
         $pass = do_shortcode('[field author-id id=' . $post_id . ']');
         if (empty($pass)) {
             $condition = false;
         } else {
             $value = implode(',', $author_ids);
         }
     }
     if (!empty($comment_author)) {
         if (CCS_Comments::$state['is_comments_loop']) {
             $authors = CCS_Loop::explode_list($comment_author);
             $author_ids = array();
             foreach ($authors as $this_author) {
                 if ($this_author == 'this') {
                     // current author ID
                     $author_ids[] = do_shortcode('[user id]');
                 } elseif ($this_author == 'same') {
                     // Same author as current post
                     if ($current_post) {
                         $author_ids[] = do_shortcode('[field author-id]');
                     }
                 } elseif (is_numeric($this_author)) {
                     $author_ids[] = $this_author;
                 } else {
                     // get author ID from user name
                     $author_ids[] = do_shortcode('[users search=' . $this_author . ' search_column=login][user id][/users]');
                 }
             }
             $check_author = do_shortcode('[comment author-id]');
             $condition = in_array($check_author, $author_ids);
         } else {
             $this_check = do_shortcode('[comments user='******' count=1].[/comments]');
             $condition = !empty($this_check);
         }
     }
     /*---------------------------------------------
      *
      * Post parent
      *
      */
     if (!empty($parent)) {
         $current_post_parent = isset($post->post_parent) ? $post->post_parent : 0;
         if ($current_post_parent == 0) {
             // Current post has no parent
             $condition = false;
         } else {
             $current_post_parent_slug = self::slug_from_id($current_post_parent);
             $parents = self::comma_list_to_array($parent);
             foreach ($parents as $check_parent) {
                 if (is_numeric($check_parent)) {
                     // compare to parent id
                     if (empty($compare) || $compare == 'OR') {
                         $condition = $check_parent == $current_post_parent ? true : $condition;
                     } else {
                         // AND
                         $condition = $check_parent == $current_post_parent ? true : false;
                         if (!$condition) {
                             break;
                         }
                         // Every term must be found
                     }
                 } else {
                     // compare to parent slug
                     if ($start == 'true') {
                         // Only check beginning of string
                         $check_this = substr($current_post_parent_slug, 0, strlen($check_parent));
                     } else {
                         $check_this = $current_post_parent_slug;
                     }
                     if (empty($compare) || $compare == 'OR') {
                         $condition = $check_parent == $check_this ? true : $condition;
                     } else {
                         // AND
                         $condition = $check_parent == $check_this ? true : false;
                         if (!$condition) {
                             break;
                         }
                         // Every term must be found
                     }
                 }
             }
         }
     }
     /*---------------------------------------------
      *
      * Attachments
      *
      */
     if (isset($atts['attached'])) {
         // Does the current post have any attachments?
         $current_id = get_the_ID();
         $posts = get_posts(array('post_parent' => $current_id, 'post_type' => 'attachment', 'post_status' => 'any', 'posts_per_page' => 1));
         if (!empty($posts)) {
             $condition = true;
         } else {
             $condition = false;
         }
     }
     /*---------------------------------------------
      *
      * If child post exists
      *
      */
     if (isset($atts['children']) && !CCS_ForEach::$state['is_for_loop'] && !CCS_Menu::$state['is_menu_loop']) {
         if (!empty($post)) {
             $children_array = get_children(array('post_parent' => $post->ID, 'posts_per_page' => '1', 'post_status' => 'publish'));
             $condition = count($children_array) > 0;
         }
     }
     /*---------------------------------------------
      *
      * [x] loop index
      *
      */
     if (!empty($x)) {
         $condition = $x == CCS_Format::$state['x_loop'];
     }
     /*---------------------------------------------
      *
      * Sticky post
      *
      */
     if (isset($atts['sticky'])) {
         $sticky = 'true';
     }
     if (!empty($sticky)) {
         $is_sticky = is_sticky();
         $condition = $is_sticky && $sticky == 'true' || !$is_sticky && $sticky == 'false';
     }
     /*---------------------------------------------
      *
      * Post format
      *
      */
     if (!empty($format) && function_exists('has_post_format')) {
         $formats = CCS_Loop::explode_list($format);
         foreach ($formats as $this_format) {
             $this_format = strtolower($this_format);
             if (has_post_format($this_format, $current_post_id)) {
                 $condition = true;
                 break;
             }
         }
     } elseif (isset($atts['format'])) {
         // Check if it exists
         $this_format = get_post_format($current_post_id);
         if (!empty($this_format)) {
             $condition = true;
         }
     }
     /*---------------------------------------------
      *
      * Has CCS gallery field
      *
      */
     if (isset($atts['gallery']) && class_exists('CCS_Gallery_Field')) {
         $condition = CCS_Gallery_Field::has_gallery();
     }
     /*---------------------------------------------
      *
      * Template: home, archive, single..
      * [if comment] - current post has comment
      *
      */
     $condition = isset($atts['home']) ? is_front_page() : $condition;
     $condition = isset($atts['comment']) ? get_comments_number($current_post_id) > 0 : $condition;
     $condition = isset($atts['image']) ? has_post_thumbnail() : $condition;
     $condition = isset($atts['loop']) ? CCS_Loop::$state['is_loop'] : $condition;
     $condition = isset($atts['archive']) ? is_archive() : $condition;
     $condition = isset($atts['single']) ? is_single() : $condition;
     $condition = isset($atts['search']) ? is_search() : $condition;
     $condition = isset($atts['404']) ? is_404() : $condition;
     $condition = isset($atts['none']) ? !have_posts() : $condition;
     if (isset($atts['tax_archive'])) {
         if ($tax_archive == 'true') {
             $tax_archive = '';
         }
         $condition = is_tax($tax_archive);
     }
     if (isset($atts['avatar'])) {
         $check = do_shortcode('[field avatar]');
         $condition = !empty($check);
     }
     /*---------------------------------------------
      *
      * Inside [loop]
      *
      */
     if (CCS_Loop::$state['is_loop']) {
         /*---------------------------------------------
          *
          * Every X number of posts
          *
          */
         if (!empty($every)) {
             $count = CCS_Loop::$state['loop_count'];
             if (substr($every, 0, 4) == 'not ') {
                 $every = substr($every, 4);
                 // Remove first 4 letters
                 // not Modulo
                 $condition = $every == 0 ? false : $count % $every != 0;
             } else {
                 // Modulo
                 $condition = $every == 0 ? false : $count % $every == 0;
             }
             if ($first == 'true') {
                 $condition = $condition || CCS_Loop::$state['loop_count'] == 1;
                 //unset($atts['first']);
             }
             if ($last == 'true') {
                 $condition = $condition || CCS_Loop::$state['loop_count'] == CCS_Loop::$state['post_count'];
                 //unset($atts['last']);
             }
         } elseif (!empty($count)) {
             if ($compare == '>=') {
                 $condition = CCS_Loop::$state['loop_count'] >= $count;
             } elseif ($compare == '<=') {
                 $condition = CCS_Loop::$state['loop_count'] <= $count;
             } elseif ($compare == '>' || $compare == 'MORE') {
                 $condition = CCS_Loop::$state['loop_count'] > $count;
             } elseif ($compare == '<' || $compare == 'LESS') {
                 $condition = CCS_Loop::$state['loop_count'] < $count;
             } else {
                 $condition = CCS_Loop::$state['loop_count'] == $count;
             }
         }
         /*---------------------------------------------
          *
          * First and last post in loop
          *
          */
         $condition = isset($atts['first']) ? CCS_Loop::$state['loop_count'] == 1 : $condition;
         $condition = isset($atts['last']) ? CCS_Loop::$state['loop_count'] == CCS_Loop::$state['post_count'] : $condition;
     }
     // End: if inside [loop]
     /*---------------------------------------------
      *
      * Menu loop
      *
      */
     if (CCS_Menu::$state['is_menu_loop']) {
         $condition = isset($atts['first']) ? CCS_Menu::$state['menu_index'][CCS_Menu::$state['depth']] == 1 : $condition;
         $condition = isset($atts['last']) ? CCS_Menu::$state['menu_index'][CCS_Menu::$state['depth']] == CCS_Menu::$state['total_menu_count'][CCS_Menu::$state['depth']] : $condition;
         if (isset($atts['children'])) {
             $children = do_shortcode('[loop menu=children].[/loop]');
             if (!empty($children)) {
                 $condition = true;
             } else {
                 $condition = false;
             }
         }
         if (!empty($every)) {
             $count = CCS_Menu::$state['menu_index'][CCS_Menu::$state['depth']];
             // Modulo
             $condition = $every == 0 ? false : $count % $every == 0;
         }
     }
     /*---------------------------------------------
      *
      * ACF repeater/flex/gallery
      *
      */
     if (class_exists('CCS_To_ACF')) {
         if (CCS_To_ACF::$state['is_repeater_or_flex_loop']) {
             if (!empty($every)) {
                 $condition = CCS_To_ACF::$state['repeater_index'] % $every == 0;
             }
             if (isset($atts['first'])) {
                 $condition = CCS_To_ACF::$state['repeater_index'] == 1;
             }
         }
         if (CCS_To_ACF::$state['is_gallery_loop']) {
             if (!empty($every)) {
                 $condition = CCS_To_ACF::$state['gallery_index'] % $every == 0;
             }
             if (isset($atts['first'])) {
                 $condition = CCS_To_ACF::$state['gallery_index'] == 1;
             }
         }
     }
     /*---------------------------------------------
      *
      * Inside array field
      *
      */
     if (CCS_Content::$state['is_array_field']) {
         if (isset($atts['first'])) {
             $condition = CCS_Content::$state['array_field_index'] == 1;
         }
         if (isset($atts['last'])) {
             $condition = CCS_Content::$state['array_field_index'] == CCS_Content::$state['array_field_count'];
         }
     }
     /*---------------------------------------------
      *
      * Inside comments loop
      *
      */
     if (CCS_Comments::$state['is_comments_loop']) {
         if (isset($atts['first'])) {
             $condition = CCS_Comments::$state['comments_loop_index'] == 1;
         }
         if (isset($atts['last'])) {
             $condition = CCS_Comments::$state['comments_loop_index'] == CCS_Comments::$state['comments_loop_count'];
         }
     }
     /*---------------------------------------------
      *
      * Passed value
      *
      */
     if (isset($atts['pass']) && empty($atts['pass']) && $empty != 'true' || $pass_empty != 'true' && empty($pass)) {
         // pass="******" empty="false" -- pass is empty
         $condition = false;
     } elseif (!empty($pass) && empty($value) && $empty != 'true') {
         // pass="******" empty="false" -- no value set
         $condition = true;
     } elseif (!empty($pass) && !empty($value)) {
         // pass="******" value="something"
         $values = CCS_Loop::explode_list($value);
         // Support multiple values
         $condition = in_array($pass, $values);
     }
     /*---------------------------------------------
      *
      * Query
      *
      */
     $queries = CCS_URL::get_queries();
     if (!empty($query)) {
         $query_check = isset($queries[$query]) ? $queries[$query] : '';
         if (!empty($value)) {
             $condition = $query_check == $value;
         } else {
             $condition = !empty($query_check);
         }
     }
     /*---------------------------------------------
      *
      * Route
      *
      */
     $routes = CCS_URL::get_routes();
     // Whole route
     if (!empty($route)) {
         $result = implode('/', $routes);
         $condition = $result == $route;
     }
     // Route parts: route_1, route_2, ...
     for ($i = 0; $i < count($routes); $i++) {
         if (isset($atts['route_' . ($i + 1)])) {
             $condition = $atts['route_' . ($i + 1)] == $routes[$i];
             if (!$condition) {
                 break;
             }
         } elseif (isset($atts[0]) && $atts[0] == 'route_' . ($i + 1)) {
             // if it exists
             $condition = !empty($routes[$i]);
             if (!$condition) {
                 break;
             }
         }
     }
     /*---------------------------------------------
      *
      * Not / else
      *
      */
     // Not - also catches compare="not"
     $condition = isset($atts['not']) ? !$condition : $condition;
     self::$state['is_if_block'] = true;
     $out = $condition ? do_ccs_shortcode($content) : do_ccs_shortcode($else);
     // [if]..[else]..[/if]
     self::$state['is_if_block'] = false;
     return $out;
 }
Esempio n. 8
0
 function each_shortcode($atts, $content = null, $shortcode_name)
 {
     if (!self::$state['is_for_loop']) {
         return;
     }
     // Must be inside a for loop
     if (isset($atts['image'])) {
         $field = $atts['image'];
     } else {
         $field = isset($atts[0]) ? $atts[0] : 'name';
         // Default: name
     }
     // Get term data for current nest level
     $term = self::$current_term[self::$index];
     $out = '';
     // Field value exists
     if (isset($term[$field])) {
         $out = $term[$field];
         // Try custom taxonomy field
     } else {
         $out = CCS_Content::get_the_taxonomy_field($term['taxonomy'], $term['id'], $field, $atts);
     }
     return $out;
 }
Esempio n. 9
0
 function loop_related_posts($atts, $content)
 {
     global $post;
     $outputs = array();
     $current_count = 0;
     if (CCS_Loop::$state['is_loop']) {
         $post_id = CCS_Loop::$state['current_post_id'];
         $post_type = do_ccs_shortcode('[field post-type]', false);
     } elseif (!empty($post)) {
         $post_id = $post->ID;
         $post_type = $post->post_type;
     } else {
         $post_id = 0;
         $post_type = 'any';
     }
     extract(shortcode_atts(array('type' => '', 'taxonomy' => 'category', 'field' => '', 'taxonomy_field' => '', 'value' => '', 'subfield' => '', 'count' => '', 'children' => '', 'order' => 'DESC', 'orderby' => 'date', 'relation' => 'or', 'operator' => 'in', 'trim' => ''), $atts));
     if (!empty($type)) {
         $post_type = CCS_Loop::explode_list($type);
     }
     if (empty($field) && isset($atts[0])) {
         $field = $atts[0];
     }
     if (!empty($taxonomy_field)) {
         $terms = do_ccs_shortcode('[field ' . $taxonomy_field . ']', false);
         $terms = CCS_Loop::explode_list($terms);
         if (empty($terms) || count($terms) == 0) {
             return;
         }
         $taxonomies = array();
         $term_objects = array();
         foreach ($terms as $term) {
             $term = self::get_term_by_id($term);
             $tax = $term->taxonomy;
             if (!in_array($tax, $taxonomies)) {
                 $taxonomies[] = $term->taxonomy;
             }
             $term_objects[] = $term;
         }
         $taxonomy = implode(',', $taxonomies);
         $terms = $term_objects;
     }
     /*---------------------------------------------
      *
      * ACF relationship field
      *
      */
     if ((!empty($field) || !empty($subfield)) && empty($value)) {
         if (class_exists('CCS_To_ACF') && CCS_To_ACF::is_acf_active()) {
             return CCS_To_ACF::loop_relationship_field($atts, $content);
         }
     }
     /*---------------------------------------------
      *
      * Related posts by taxonomy
      *
      */
     if (empty($count)) {
         $count = 99999;
     }
     // Hypothetical maximum number of posts
     if (!empty($taxonomy)) {
         self::$state['is_related_posts_loop'] = true;
         // Support multiple taxonomies
         $taxonomies = CCS_Loop::explode_list($taxonomy);
         $relation = strtoupper($relation);
         $tax_count = 0;
         $query = array('post_type' => $post_type, 'posts_per_page' => -1, 'order' => $order, 'orderby' => $orderby, 'tax_query' => array());
         $target_terms = array();
         foreach ($taxonomies as $current_taxonomy) {
             if ($current_taxonomy == 'tag') {
                 $current_taxonomy = 'post_tag';
             }
             // Get current post's taxonomy terms - unless given
             if (!isset($terms)) {
                 $term_objects = CCS_Content::get_the_terms_silently($post_id, $current_taxonomy);
             } else {
                 $term_objects = $terms;
             }
             if (!is_array($term_objects) || empty($term_objects)) {
                 continue;
             }
             foreach ($term_objects as $term) {
                 $target_terms[$current_taxonomy][] = $term->term_id;
             }
             if (empty($target_terms[$current_taxonomy])) {
                 continue;
             }
             if ($tax_count == 1) {
                 $query['tax_query']['relation'] = $relation;
             }
             $query['tax_query'][] = array('taxonomy' => $current_taxonomy, 'field' => 'id', 'terms' => $target_terms[$current_taxonomy], 'operator' => strtoupper($operator), 'include_children' => $children == 'true');
             $tax_count++;
         }
         $terms = $target_terms;
         // print_r($query); echo '<br><br>';
         $posts = new WP_Query($query);
         if ($posts->have_posts()) {
             while ($posts->have_posts()) {
                 // Set up post data
                 $posts->the_post();
                 // Skip current post
                 if ($post->ID != $post_id) {
                     // Manually filter out terms..
                     // For some reason, WP_Query is returning more than we need
                     $condition = false;
                     $tax_count = 0;
                     foreach ($taxonomies as $current_taxonomy) {
                         if ($current_taxonomy == 'tag') {
                             $current_taxonomy = 'post_tag';
                         }
                         // Include child terms
                         if ($children == 'true' && isset($terms[$current_taxonomy])) {
                             foreach ($terms[$current_taxonomy] as $this_term) {
                                 $child_terms = get_term_children($this_term, $current_taxonomy);
                                 if (!empty($child_terms)) {
                                     foreach ($child_terms as $child_term) {
                                         if (!in_array($child_term, $terms[$current_taxonomy])) {
                                             $terms[$current_taxonomy][] = $child_term;
                                         }
                                     }
                                 }
                             }
                         }
                         if (isset($terms[$current_taxonomy])) {
                             $tax_count++;
                             if ($relation == 'AND') {
                                 if (has_term($terms[$current_taxonomy], $current_taxonomy)) {
                                     if ($condition || $tax_count == 1) {
                                         $condition = true;
                                     }
                                 }
                             } else {
                                 if (has_term($terms[$current_taxonomy], $current_taxonomy)) {
                                     $condition = true;
                                 }
                             }
                         }
                     }
                     if ($condition) {
                         // OK, post fits the criteria
                         self::$state['current_related_post_id'] = $post->ID;
                         $current_count++;
                         if ($current_count <= $count) {
                             $outputs[] = do_ccs_shortcode($content);
                         }
                     }
                 }
             }
         }
         wp_reset_postdata();
         self::$state['is_related_posts_loop'] = false;
     }
     $out = implode('', $outputs);
     if (!empty($trim)) {
         $out = CCS_Format::trim($out, $trim);
     }
     return $out;
 }
Esempio n. 10
0
 function comment_shortcode($atts = array(), $content)
 {
     extract(shortcode_atts(array('template' => '', 'format' => '', 'date_format' => '', 'words' => '', 'more' => '&hellip;', 'length' => '', 'size' => '96'), $atts));
     /*---------------------------------------------
      *
      * Inside a comments loop
      *
      */
     if (self::$state['is_comments_loop']) {
         $comment = self::$state['current_comment'];
         if (empty($comment)) {
             return;
         }
         $out = '';
         // Display comment fields 
         $fields = array('ID', 'author', 'author-id', 'author-email', 'author-link', 'author-url', 'avatar', 'content', 'content-link', 'count', 'counted', 'date', 'title', 'title-link', 'link', 'post-ID', 'post-title', 'post-link', 'post-url', 'reply-link', 'url', 'user-id');
         if (!isset($atts[0])) {
             $atts[0] = 'content';
         }
         $post_id = $comment->comment_post_ID;
         $field = strtolower($atts[0]);
         $arg_field = $field;
         if ($arg_field == 'user-id') {
             $field = 'user_id';
         } else {
             $field = str_replace('-', '_', $arg_field);
             $field = 'comment_' . $field;
             // name of property in comment object
         }
         // Check first parameter [comment ~]
         switch ($arg_field) {
             case 'id':
                 $out = $comment->comment_ID;
                 break;
             case 'title':
                 $out = get_the_title($post_id);
                 break;
             case 'url':
                 $comment_id = $comment->comment_ID;
                 $out = get_permalink($post_id) . '#comment-' . $comment_id;
                 // Add anchor to comment
                 break;
             case 'link':
                 $title = get_the_title($post_id);
                 $comment_id = $comment->comment_ID;
                 $url = get_permalink($post_id) . '#comment-' . $comment_id;
                 // Add anchor to comment
                 break;
             case 'post-url':
                 $out = get_permalink($post_id);
                 // Just the post URL
                 break;
             case 'title-link':
             case 'post-link':
                 $title = get_the_title($post_id);
                 $url = get_permalink($post_id);
                 // $out = '<a href="'.$url.'">'.$title.'</a>';
                 break;
             case 'author-link':
                 $title = isset($comment->comment_author) ? $comment->comment_author : null;
                 $url = isset($comment->comment_author_url) ? $comment->comment_author_url : null;
                 // $out = '<a href="'.$url.'">'.$title.'</a>';
                 break;
             case 'author-id':
                 $out = $comment->user_id;
                 break;
             case 'avatar':
                 $author_email = get_comment_author_email($comment->comment_ID);
                 $out = get_avatar($author_email, $size);
                 break;
             case 'count':
                 $out = get_comments_number($post_id);
                 break;
             case 'counted':
                 $count = get_comments_number($post_id);
                 if ($count == 0) {
                     return 'No comments';
                 }
                 if ($count == 1) {
                     return '1 comment';
                 }
                 $out = $count . ' comments';
                 break;
             case 'content':
                 if (isset($comment->{$field})) {
                     $out = $comment->{$field};
                 }
                 if (empty($format)) {
                     $format = 'true';
                 }
                 // Format content by default
                 break;
             case 'content-link':
                 $comment_id = $comment->comment_ID;
                 $url = get_permalink($post_id) . '#comment-' . $comment_id;
                 // Add anchor to comment
                 if (isset($comment->comment_content)) {
                     $out = $comment->comment_content;
                 } else {
                     $out = '';
                 }
                 if (empty($format)) {
                     $format = 'true';
                 }
                 // Format content by default
                 break;
             case 'reply-link':
                 $comment_id = $comment->comment_ID;
                 //get the setting configured in the admin panel under settings discussions "Enable threaded (nested) comments  levels deep"
                 $max_depth = get_option('thread_comments_depth');
                 //add max_depth to the array and give it the value from above and set the depth to 1
                 $args = array('add_below' => 'comment', 'respond_id' => 'respond', 'reply_text' => __('Reply'), 'login_text' => __('Log in to Reply'), 'depth' => 1, 'before' => '', 'after' => '', 'max_depth' => $max_depth);
                 wp_enqueue_script('comment-reply');
                 // comment-reply.js
                 $out = get_comment_reply_link($args, $comment_id, $post_id);
                 break;
             default:
                 if (isset($comment->{$field})) {
                     $out = $comment->{$field};
                 }
                 break;
         }
         // Allow check for parameters without value
         $atts = CCS_Content::get_all_atts($atts);
         if (!empty($words)) {
             if ($more == 'false') {
                 $more = '';
             }
             $out = wp_trim_words($out, $words, $more);
         }
         if (!empty($length)) {
             $the_excerpt = $out;
             $the_excerpt = strip_tags(strip_shortcodes($the_excerpt));
             //Strips tags and images
             $out = mb_substr($the_excerpt, 0, $length, 'UTF-8');
         }
         if (isset($atts['date'])) {
             if (!empty($date_format)) {
                 $out = mysql2date($date_format, $out);
             } else {
                 // Default date format under Settings -> General
                 $out = mysql2date(get_option('date_format'), $out);
             }
         } elseif (!empty($out) && !empty($date_format)) {
             $out = mysql2date($date_format, $out);
             // date($date_format, strtotime($out));
         } elseif ($format == 'true') {
             $out = apply_filters('the_content', $out);
         }
         // Wrap in link after trimming and format
         if (isset($atts['title-link']) || isset($atts['post-link']) || isset($atts['author-link']) || isset($atts['link'])) {
             if (!empty($title) && !empty($url)) {
                 $out = '<a href="' . $url . '">' . $title . '</a>';
             } elseif (!empty($title)) {
                 $out = $title;
             }
             // no link found
         } elseif (isset($atts['content-link']) && !empty($out) && !empty($url)) {
             $out = '<a href="' . $url . '">' . $out . '</a>';
         }
         return $out;
     } else {
         // Outside comments loop
         // Check for parameters without value, i.e., [comment count]
         $atts = CCS_Content::get_all_atts($atts);
         if (isset($atts['count'])) {
             return get_comments_number();
         } elseif (isset($atts['counted'])) {
             $count = get_comments_number();
             if ($count == 0) {
                 return 'No comments';
             }
             if ($count == 1) {
                 return '1 comment';
             }
             return $count . ' comments';
         } elseif (isset($atts['total'])) {
             return CCS_Loop::$state['comment_count'];
         } elseif (isset($atts['form'])) {
             return self::comment_form_shortcode($atts, $content);
         } elseif (!empty($template) || isset($atts['template'])) {
             // Comments template
             $dir = '';
             if (empty($template)) {
                 $template = '/comments.php';
             }
             if (isset($template[0]) && $template[0] != '/') {
                 $template = '/' . $template;
             }
             $file = $dir . $template;
             // Maybe necessary
             //      global $withcomments;
             //      $withcomments = "1";
             // Return comments template
             ob_start();
             comments_template($file);
             return ob_get_clean();
         }
     }
     // Outside comments loop
 }
Esempio n. 11
0
 public static function render_field_tags($template, $parameters)
 {
     $post_id = !empty($parameters['id']) ? $parameters['id'] : get_the_ID();
     /*---------------------------------------------
      *
      * User defined fields
      *
      */
     if (!empty($parameters['fields'])) {
         $fields = self::explode_list($parameters['fields']);
         foreach ($fields as $this_field) {
             if (class_exists('CCS_To_ACF') && CCS_To_ACF::$state['is_repeater_or_flex_loop']) {
                 // Repeater or flexible content field: then get sub field
                 if (function_exists('get_sub_field')) {
                     $field_value = get_sub_field($this_field);
                 } else {
                     $field_value = null;
                 }
             } else {
                 // Enable predefined fields
                 $field_value = CCS_Content::get_prepared_field($this_field, $post_id);
             }
             if (is_array($field_value)) {
                 foreach ($field_value as $key => $value) {
                     $template = str_replace('{' . strtoupper($this_field) . ':' . strtoupper($key) . '}', $value, $template);
                 }
                 //$field_value = ucwords(implode(', ', $field_value));
                 $field_value = '(Array)';
             }
             $template = str_replace('{' . strtoupper($this_field) . '}', $field_value, $template);
         }
     }
     // @todo Deprecate below for better performance
     /*
         // Render default tags later, to allow custom fields to take priority
         if ( strpos($template, '{') !== false ) {
           $template = self::render_default_field_tags( $template );
         }
     */
     return $template;
 }
Esempio n. 12
0
 public static function render_field_tags($template, $parameters)
 {
     $post_id = !empty($parameters['id']) ? $parameters['id'] : get_the_ID();
     /*---------------------------------------------
      *
      * User defined fields
      *
      */
     if (!empty($parameters['fields'])) {
         $fields = CCS_Format::explode_list($parameters['fields']);
         foreach ($fields as $this_field) {
             if (class_exists('CCS_To_ACF') && CCS_To_ACF::$state['is_repeater_or_flex_loop']) {
                 // Repeater or flexible content field: then get sub field
                 if (function_exists('get_sub_field')) {
                     $field_value = get_sub_field($this_field);
                 } else {
                     $field_value = null;
                 }
             } else {
                 // Enable predefined fields
                 $field_value = CCS_Content::get_prepared_field($this_field, $post_id);
             }
             if (is_array($field_value)) {
                 foreach ($field_value as $key => $value) {
                     $template = str_replace('{' . strtoupper($this_field) . ':' . strtoupper($key) . '}', $value, $template);
                 }
                 // For replacing {FIELD} with array
                 $field_value = ucwords(implode(', ', $field_value));
             }
             $template = str_replace('{' . strtoupper($this_field) . '}', $field_value, $template);
         }
     }
     return $template;
 }