Exemple #1
0
 function users_shortcode($atts, $content)
 {
     self::$state['user_query'] = '';
     /*---------------------------------------------
      *
      * [if empty]
      *
      */
     // If empty
     $middle = CCS_Loop::get_between('[if empty]', '[/if]', $content);
     $content = str_replace($middle, '', $content);
     $else = CCS_Loop::extract_else($middle);
     self::$state['if_empty'] = $middle;
     self::$state['if_empty_else'] = $else;
     $outputs = array();
     /*---------------------------------------------
      *
      * Prepare parameters
      *
      */
     $args = array();
     // Just pass these
     $pass_args = array('orderby', 'search', 'number', 'offset', 'meta_key');
     // Order by field value
     $sort_field_num = false;
     if (isset($atts['orderby'])) {
         if ($atts['orderby'] == 'id') {
             $atts['orderby'] = 'ID';
         } elseif (isset($atts['field']) && ($atts['orderby'] == 'field' || $atts['orderby'] == 'field_num')) {
             if ($atts['orderby'] == 'field') {
                 $atts['orderby'] = 'meta_value';
                 $atts['meta_key'] = $atts['field'];
             } else {
                 // Sort by field value number
                 $sort_field_num = $atts['field'];
                 unset($atts['orderby']);
             }
             unset($atts['field']);
         }
     }
     foreach ($pass_args as $arg) {
         if (isset($atts[$arg])) {
             $args[$arg] = $atts[$arg];
         }
     }
     if (isset($atts['count'])) {
         $args['number'] = $atts['count'];
     }
     if (isset($atts['order'])) {
         $args['order'] = strtoupper($atts['order']);
     }
     if (isset($atts['include'])) {
         $args['include'] = CCS_Format::explode_list($atts['include']);
     }
     if (isset($atts['exclude'])) {
         $args['exclude'] = CCS_Format::explode_list($atts['exclude']);
     }
     if (isset($atts['blog_id'])) {
         $args['blog_id'] = intval($atts['blog_id']);
     }
     if (isset($atts['search_columns'])) {
         $args['search_columns'] = CCS_Format::explode_list($atts['search_columns']);
     }
     if (isset($atts['field']) && isset($atts['value'])) {
         $compare = isset($atts['compare']) ? strtoupper($atts['compare']) : '=';
         switch ($compare) {
             case 'EQUAL':
                 $compare = '=';
                 break;
             case 'NOT':
             case 'NOT EQUAL':
                 $compare = '!=';
                 break;
             case 'MORE':
                 $compare = '>';
                 break;
             case 'LESS':
                 $compare = '<';
                 break;
         }
         $multiple = array('IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN');
         if (in_array($compare, $multiple)) {
             $value = CCS_Format::explode_list($atts['value']);
         } else {
             $value = $atts['value'];
         }
         $args['meta_query'][] = array('key' => $atts['field'], 'value' => $atts['value'], 'compare' => $compare);
         // Additional query
         if (isset($atts['relation']) && isset($atts['field_2']) && isset($atts['value_2'])) {
             $args['meta_query']['relation'] = strtoupper($atts['relation']);
             $args['meta_query'][] = array('key' => $atts['field_2'], 'value' => $atts['value_2'], 'compare' => isset($atts['compare_2']) ? strtoupper($atts['compare_2']) : '=');
         }
     }
     // Alter query to extend search function
     if (isset($args['search'])) {
         self::$state['user_query'] = $args['search'];
         add_action('pre_user_query', array(__CLASS__, 'extend_search'));
     }
     // Main action
     if (isset($atts['id'])) {
         $users = array(get_user_by('id', $atts['id']));
     } elseif (isset($atts['slug'])) {
         $users = array(get_user_by('slug', $atts['slug']));
     } elseif (isset($atts['role'])) {
         // Support query by multiple roles, because get_users() doesn't
         $users = array();
         $roles = CCS_Format::explode_list($atts['role']);
         foreach ($roles as $role) {
             if ($role == 'admin') {
                 $role = 'Administrator';
             } else {
                 $role = ucwords($role);
             }
             // Capitalize word
             $args['role'] = $role;
             $matching_users = get_users($args);
             $users = array_merge($users, $matching_users);
         }
     } else {
         $users = get_users($args);
     }
     if (isset($args['search'])) {
         self::$state['user_query'] = '';
         remove_action('pre_user_query', array(__CLASS__, 'extend_search'));
     }
     /*---------------------------------------------
      *
      * Filter results
      *
      */
     // Sort by field value number
     if ($sort_field_num !== false) {
         // This is necessary because get_users doesn't do meta_value_num query
         $new_users = array();
         foreach ($users as $user) {
             $key = $user->get($sort_field_num);
             $new_users[] = array('user' => $user, 'key' => $key);
         }
         usort($new_users, array(__CLASS__, 'sortByFieldNum'));
         if (isset($args['order']) && $args['order'] == 'DESC') {
             $new_users = array_reverse($new_users);
         }
         $users = array();
         foreach ($new_users as $user_array) {
             $users[] = $user_array['user'];
         }
     }
     self::$state['is_users_loop'] = true;
     /*---------------------------------------------
      *
      * Users Loop
      *
      */
     foreach ($users as $user) {
         self::$state['current_user_object'] = $user;
         // Support tags
         $content = str_replace('{USER_ID}', do_shortcode('[user id]'), $content);
         $content = str_replace('{USER_ROLE}', do_shortcode('[user role out="slug"]'), $content);
         $outputs[] = do_ccs_shortcode($content);
     }
     // [if empty]..[else]..[/if]
     if (count($users) == 0 && isset(self::$state['if_empty'])) {
         $outputs[] = do_ccs_shortcode(self::$state['if_empty']);
     } elseif (isset(self::$state['if_empty_else']) && count($users) > 0) {
         $outputs[] = do_ccs_shortcode(self::$state['if_empty_else']);
     }
     // Make a list
     // TODO: Add new function: CCS_Format::make_list()
     if (isset($atts['list'])) {
         $outerTag = $atts['list'] == 'true' ? 'ul' : $atts['list'];
         $innerTag = isset($atts['item']) ? $atts['item'] : 'li';
         $result = '<' . $outerTag . (isset($atts['list_class']) ? ' class="' . implode(' ', array_map('trim', explode(',', $atts['list_class']))) . '"' : '') . (isset($atts['list_style']) ? ' style="' . $atts['list_style'] . '"' : '') . '>';
         foreach ($outputs as $o) {
             $result .= '<' . $innerTag . (isset($atts['item_class']) ? ' class="' . implode(' ', array_map('trim', explode(',', $atts['item_class']))) . '"' : '') . (isset($atts['item_style']) ? ' style="' . $atts['item_style'] . '"' : '') . '>' . $o . '</' . $outerTag . '>';
         }
         $result .= '</' . $outerTag . '>';
     } else {
         $result = implode('', $outputs);
     }
     if (isset($atts['trim'])) {
         $trim = $atts['trim'];
         if ($trim == 'true') {
             $trim = null;
         }
         $result = trim($result, " \t\n\r\v," . $trim);
     }
     self::$state['is_users_loop'] = false;
     return $result;
 }
Exemple #2
0
 public static function get_if_else($content, $shortcode_name = '', $else_name = 'else')
 {
     // Get [else] if it exists
     $prefix = CCS_Format::get_minus_prefix($shortcode_name);
     $else_name = $prefix . $else_name;
     $content_array = explode('[' . $else_name . ']', $content);
     $content = $content_array[0];
     if (count($content_array) > 1) {
         $else = $content_array[1];
     } else {
         $else = '';
     }
     return array('if' => $content, 'else' => $else);
 }
Exemple #3
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;
 }
Exemple #4
0
 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' => '');
     $atts = self::replace_variables($atts);
     extract(shortcode_atts($args, $atts, true));
     // Shortcuts
     if (isset($atts[0])) {
         if ($atts[0] === 'route') {
             $global = 'route';
         } elseif ($atts[0] === 'vars') {
             $global = 'vars';
         }
     }
     if ($pre_render == 'true') {
         $content = do_ccs_shortcode($content);
     }
     // This should get the current post in all contexts
     $post_id = do_shortcode('[field id]');
     // Support nested
     $prefix = CCS_Format::get_minus_prefix($shortcode_name);
     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_Format::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);
                 }
             } elseif ($global == 'vars') {
                 foreach (self::$vars as $key => $value) {
                     $tag = '{' . $prefix . strtoupper($key) . '}';
                     $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_Format::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 a list of items
      *
      */
     if (!empty($list)) {
         $items = CCS_Format::explode_list($list);
         // Comma-separated list -> array
         // Create range
         $new_items = array();
         foreach ($items as $item) {
             if (strpos($item, '~') !== false) {
                 $pair = CCS_Format::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_Format::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_Format::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_field_tags($content, array());
     }
     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;
 }
Exemple #5
0
 static function format_number($atts, $content)
 {
     $currency = !empty($atts['currency']) ? $atts['currency'] : '';
     $decimals = !empty($atts['decimals']) ? $atts['decimals'] : 0;
     $point = !empty($atts['point']) ? $atts['point'] : '.';
     $thousands = !empty($atts['thousands']) ? $thousands === 'false' ? '' : $atts['thousands'] : '';
     $content = CCS_Format::getCurrency(floatval($content), $currency, $decimals, $point, $thousands);
     return $content;
 }
 function for_shortcode($atts, $content = null, $shortcode_name)
 {
     $args = array('each' => '', 'term' => '', 'terms' => '', 'orderby' => '', 'order' => '', 'count' => '', 'parent' => '', 'parents' => '', 'children' => '', 'current' => '', 'trim' => '', 'empty' => 'true', 'exclude' => '');
     extract(shortcode_atts($args, $atts, true));
     // Top parent loop
     if (!self::$state['is_for_loop']) {
         self::$state['is_for_loop'] = true;
         // Nested loop
     } else {
         $parent_term = self::$current_term[self::$index];
         // Same taxonomy as parent
         if ($each == 'child' && isset($parent_term['taxonomy'])) {
             $each = $parent_term['taxonomy'];
         }
         // Get parent term unless specified
         if (empty($parent) && isset($parent_term['id'])) {
             $parent = $parent_term['id'];
         }
         // Nest index
         self::$index++;
     }
     if ($each == 'tag') {
         $each = 'post_tag';
     }
     $out = '';
     $prefix = CCS_Format::get_minus_prefix($shortcode_name);
     // Get [else] block
     $if_else = CCS_If::get_if_else($content, $shortcode_name, 'for-else');
     $content = $if_else['if'];
     $else = $if_else['else'];
     // Get terms according to parameters
     // @todo Refactor - keep it DRY
     // @todo Consolidate with CCS_Content::get_taxonomies
     $query = array('orderby' => !empty($orderby) ? $orderby : 'name', 'order' => $order, 'number' => $count, 'parent' => $parents == 'true' ? 0 : '', 'hide_empty' => $empty == 'true' ? 0 : 1);
     $term_ids = array();
     if (!empty($terms)) {
         $term = $terms;
     }
     // Alias
     if (!empty($term)) {
         $terms = CCS_Format::explode_list($term);
         // Multiple values support
         foreach ($terms as $this_term) {
             if (is_numeric($this_term)) {
                 $term_ids[] = $this_term;
             } else {
                 /* Get term ID from slug */
                 $term_id = get_term_by('slug', $this_term, $each);
                 if (!empty($term_id)) {
                     $term_ids[] = $term_id->term_id;
                 }
             }
         }
         if (!empty($term_ids)) {
             $query['include'] = $term_ids;
         } else {
             // Nothing found
             // Return to parent loop
             if (self::$index > 0) {
                 self::$index--;
             } else {
                 self::$state['is_for_loop'] = false;
             }
             return do_ccs_shortcode($else);
         }
     }
     // Inside loop, or current is true
     if (CCS_Loop::$state['is_loop'] && $current != "false" || $current == "true") {
         if ($current == "true") {
             $post_id = get_the_ID();
         } else {
             $post_id = CCS_Loop::$state['current_post_id'];
         }
         // Inside [loop]
         $taxonomies = wp_get_post_terms($post_id, $each, $query);
         // Current and parent parameters together
         if (!empty($parent)) {
             if (is_numeric($parent)) {
                 $parent_term_id = $parent;
             } else {
                 // Get parent term ID from slug
                 $term = get_term_by('slug', $parent, $each);
                 if (!empty($term)) {
                     $parent_term_id = $term->term_id;
                 } else {
                     $parent_term_id = null;
                 }
             }
             if (!empty($parent_term_id)) {
                 // Filter out terms that do not have the specified parent
                 // TODO: Why not set this as query for wp_get_post_terms above..?
                 foreach ($taxonomies as $key => $term) {
                     // TODO: What about children parameter for all descendants..?
                     if ($term->parent != $parent_term_id) {
                         unset($taxonomies[$key]);
                     }
                 }
             }
         }
         // Not inside loop
     } else {
         if (empty($parent)) {
             $taxonomies = get_terms($each, $query);
             if (!empty($term) && $children == 'true') {
                 if (isset($query['include'])) {
                     unset($query['include']);
                 }
                 // Get descendants of each term
                 $new_taxonomies = $taxonomies;
                 foreach ($taxonomies as $term_object) {
                     $query['child_of'] = $term_object->term_id;
                     $new_terms = get_terms($each, $query);
                     if (!empty($new_terms)) {
                         $new_taxonomies += $new_terms;
                         foreach ($new_terms as $new_term) {
                             $term_ids[] = $new_term->term_id;
                         }
                     }
                 }
                 $taxonomies = $new_taxonomies;
             }
             // Get terms by parent
         } else {
             if (is_numeric($parent)) {
                 $parent_term_id = $parent;
             } else {
                 // Get parent term ID from slug
                 $term = get_term_by('slug', $parent, $each);
                 if (!empty($term)) {
                     $parent_term_id = $term->term_id;
                 } else {
                     $parent_term_id = null;
                 }
             }
             if (!empty($parent_term_id)) {
                 /* Get direct children */
                 if ($children !== 'true') {
                     // Direct children only
                     $query['parent'] = $parent_term_id;
                 } else {
                     // All descendants
                     $query['child_of'] = $parent_term_id;
                 }
                 $taxonomies = get_terms($each, $query);
             } else {
                 $taxonomies = null;
             }
             // No parent found
         }
     }
     if (count($term_ids) > 0) {
         $new_taxonomies = array();
         // Sort terms according to given ID order: get_terms doesn't do order by ID
         foreach ($term_ids as $term_id) {
             foreach ($taxonomies as $term_object) {
                 if ($term_object->term_id == $term_id) {
                     $new_taxonomies[] = $term_object;
                 }
             }
         }
         $taxonomies = $new_taxonomies;
     }
     // Array and not empty
     if (is_array($taxonomies) && count($taxonomies) > 0) {
         $each_term = array();
         $each_term['taxonomy'] = $each;
         // Taxonomy name
         $excludes = CCS_Format::explode_list($exclude);
         $index = 0;
         if (empty($count)) {
             $count = 9999;
         }
         // Show all
         foreach ($taxonomies as $term_object) {
             // Exclude IDs or slugs
             $condition = true;
             foreach ($excludes as $exclude) {
                 if (is_numeric($exclude)) {
                     // Exclude ID
                     if ($exclude == $term_object->term_id) {
                         $condition = false;
                     }
                 } else {
                     // Exclude slug
                     if ($exclude == $term_object->slug) {
                         $condition = false;
                     }
                 }
             }
             if ($condition && ++$index <= $count) {
                 $each_term['id'] = $term_object->term_id;
                 $each_term['name'] = $term_object->name;
                 $each_term['slug'] = $term_object->slug;
                 $each_term['description'] = $term_object->description;
                 $term_link = get_term_link($term_object);
                 if (is_wp_error($term_link)) {
                     $term_link = null;
                 }
                 $each_term['url'] = $term_link;
                 $each_term['link'] = '<a href="' . $each_term['url'] . '">' . $each_term['name'] . '</a>';
                 // Alias for backward compatibility
                 $each_term['name-link'] = $each_term['link'];
                 // Replace {TAGS}
                 // @todo Use a general-purpose function in CCS_Loop for replacing tags
                 $replaced_content = str_replace('{' . $prefix . 'TERM}', $each_term['slug'], $content);
                 $replaced_content = str_replace('{' . $prefix . 'TERM_ID}', $each_term['id'], $replaced_content);
                 $replaced_content = str_replace('{' . $prefix . 'TERM_NAME}', $each_term['name'], $replaced_content);
                 // Make term data available to [each]
                 self::$current_term[self::$index] = $each_term;
                 self::$state['for_count']++;
                 $out .= do_ccs_shortcode($replaced_content);
             }
         }
         // For each term
     } else {
         // No taxonomy found
         $out .= do_ccs_shortcode($else);
     }
     // Trim final output
     if (!empty($trim)) {
         if ($trim == 'true') {
             $trim = null;
         }
         $out = trim($out, " \t\n\r\v," . $trim);
     }
     // Return to parent loop
     if (self::$index > 0) {
         self::$index--;
     } else {
         self::$state['is_for_loop'] = false;
     }
     self::$state['for_count'] = 0;
     return $out;
 }
 public static function attached_shortcode($atts, $content, $tag)
 {
     $args = array('orderby' => '', 'order' => '', 'category' => '', 'count' => '', 'offset' => '', 'trim' => '', 'id' => '', 'field' => '', 'columns' => '', 'pad' => '', 'between' => '');
     extract(shortcode_atts($args, $atts, true));
     /*---------------------------------------------
      *
      * Get attachments
      *
      */
     $attachment_ids = array();
     if (!empty($id)) {
         $parent_id = 0;
         // Any post
     } elseif (!empty($field)) {
         // Specific attachment ID from field
         $id = do_shortcode('[field ' . $field . ']');
         if (empty($id)) {
             return;
         }
         $parent_id = 0;
         // Any post
     } else {
         $parent_id = do_shortcode('[field id]');
         // Attachments of current post
         if (empty($parent_id)) {
             return;
         }
     }
     if (isset($atts[0]) && $atts[0] == 'gallery') {
         // Get attachment IDs from gallery field
         $attachment_ids = CCS_Gallery_Field::get_image_ids($parent_id);
         // Support for orderby title
         if ($orderby == 'title') {
             usort($attachment_ids, array($this, 'sort_gallery_by_title'));
         }
     } else {
         $attach_args = array('post_parent' => $parent_id, 'post_type' => 'attachment', 'post_status' => 'any', 'posts_per_page' => '-1');
         // default orderby
         $attach_args['orderby'] = empty($orderby) ? 'date' : $orderby;
         // default for titles
         if ($orderby == 'title') {
             $order = empty($order) ? 'ASC' : $order;
         }
         if (!empty($order)) {
             $attach_args['order'] = $order;
         }
         if (!empty($category)) {
             $attach_args['category'] = $category;
         }
         if (!empty($count)) {
             $attach_args['posts_per_page'] = $count;
         }
         if (!empty($offset)) {
             $attach_args['offset'] = $offset;
         }
         if (!empty($id)) {
             $attach_args['post__in'] = CCS_Format::explode_list($id);
             $attach_args['orderby'] = empty($orderby) ? 'post__in' : $orderby;
             unset($attach_args['post_parent']);
         }
         // Get attachments for current post
         $posts = get_posts($attach_args);
         $index = 0;
         foreach ($posts as $post) {
             $attachment_ids[$index] = $post->ID;
             // Keep it in order
             $index++;
         }
     }
     // If no images in gallery field
     if (count($attachment_ids) == 0) {
         return null;
     }
     /*---------------------------------------------
      *
      * Compile template
      *
      */
     $out = array();
     // if nested, save previous state
     if ($tag[0] == '-') {
         $prev_state = self::$state;
     }
     self::$state['is_attachment_loop'] = true;
     foreach ($attachment_ids as $index => $attachment_id) {
         self::$state['current_attachment_id'] = $attachment_id;
         $out[] = do_ccs_shortcode($content);
     }
     self::$state['is_attachment_loop'] = false;
     // if nested, restore previous state
     if ($tag[0] == '-') {
         self::$state = $prev_state;
     }
     /*---------------------------------------------
      *
      * Post-process
      *
      * TODO: Combine this with loop and others
      *
      */
     if (!empty($columns)) {
         $out = CCS_Loop::render_columns($out, $columns, $pad, $between);
     } else {
         $out = implode('', $out);
         if ($trim == 'true') {
             $out = trim($out, " \t\n\r\v,");
         }
     }
     return $out;
 }
Exemple #8
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;
 }
Exemple #9
0
 public static function loop_relationship_field($atts, $content)
 {
     if (!self::is_acf_active()) {
         return;
     }
     extract(shortcode_atts(array('field' => '', 'subfield' => '', 'sub' => '', 'trim' => '', 'option' => ''), $atts));
     $output = array();
     if (empty($field) && isset($atts[0])) {
         $field = $atts[0];
     }
     // If in repeater or flexible content, get subfield by default
     if (self::$state['is_repeater_or_flex_loop']) {
         if (empty($subfield)) {
             $subfield = $field;
             $field = null;
         }
     }
     // Support getting field from option page
     $option = $option == 'true' ? 'option' : false;
     if (!empty($field)) {
         $posts = get_field($field, $option);
     } elseif (!empty($subfield)) {
         $posts = get_sub_field($subfield);
         // Gets option from the_row()
     } else {
         return null;
     }
     if ($posts) {
         self::$state['is_relationship_loop'] = true;
         $index_now = 0;
         if (!is_array($posts)) {
             $posts = array($posts);
             // Single post
         }
         foreach ($posts as $post) {
             $index_now++;
             self::$state['relationship_id'] = $post->ID;
             $output[] = str_replace('{COUNT}', $index_now, do_ccs_shortcode($content));
         }
     }
     self::$state['is_relationship_loop'] = false;
     $output = implode('', $output);
     if (!empty($trim)) {
         $output = CCS_Format::trim($output, $trim);
     }
     return $output;
 }
 function comment_form_shortcode($atts, $content)
 {
     extract(shortcode_atts(array('fields' => 'author, email, url'), $atts));
     $enabled_fields = CCS_Format::explode_list($fields);
     self::$state['comment_form_fields'] = array();
     $content = do_local_shortcode('comment-form', $content, true);
     // Prepare arguments
     $commenter = wp_get_current_commenter();
     $req = get_option('require_name_email');
     $aria_req = $req ? " aria-required='true'" : '';
     /*---------------------------------------------
      *
      * Inputs
      *
      */
     $options = array();
     $rendered_fields = array();
     $defined_inputs = self::$state['comment_form_fields'];
     foreach (self::$state['inputs'] as $each_input) {
         $do_define = isset($defined_inputs[$each_input]);
         // Input fields
         if (in_array($each_input, array('author', 'email', 'url')) && in_array($each_input, $enabled_fields)) {
             if ($do_define) {
                 $rendered_fields[$each_input] = $defined_inputs[$each_input];
             } elseif ($each_input == 'author') {
                 $rendered_fields[$each_input] = '<p class="comment-form-author"><label for="author">' . 'Name' . '</label> ' . ($req ? '<span class="required">*</span>' : '') . '<input id="author" name="author" type="text" value="' . esc_attr($commenter['comment_author']) . '" size="30"' . $aria_req . ' /></p>';
             } elseif ($each_input == 'email') {
                 $rendered_fields[$each_input] = '<p class="comment-form-email"><label for="email">' . __('Email', 'domainreference') . '</label> ' . ($req ? '<span class="required">*</span>' : '') . '<input id="email" name="email" type="text" value="' . esc_attr($commenter['comment_author_email']) . '" size="30"' . $aria_req . ' /></p>';
             } elseif ($each_input == 'url') {
                 $rendered_fields[$each_input] = '<p class="comment-form-url"><label for="url">' . __('Website', 'domainreference') . '</label>' . '<input id="url" name="url" type="text" value="' . esc_attr($commenter['comment_author_url']) . '" size="30" /></p>';
             }
             // Comment form options
         } elseif (in_array($each_input, array('comment', 'reply', 'reply_to', 'cancel', 'submit', 'login', 'logged-in', 'before', 'after'))) {
             if ($each_input == 'login') {
                 if ($do_define) {
                     $template = $defined_inputs[$each_input];
                 } else {
                     $template = '<p class="must-log-in">' . 'You must be <a href="%s">logged in</a> to post a comment.' . '</p>';
                 }
                 $options[$each_input] = sprintf($template, wp_login_url(apply_filters('the_permalink', get_permalink())));
             } elseif ($each_input == 'logged-in') {
                 if ($do_define) {
                     $template = $defined_inputs[$each_input];
                 } else {
                     $template = '<p class="logged-in-as">' . 'Logged in as <a href="%1$s">%2$s</a>. ' . '<a href="%3$s" title="Log out of this account">Log out?</a>' . '</p>';
                 }
                 $user_identity = do_shortcode('[user]');
                 if (!empty($user_identity)) {
                     $options[$each_input] = sprintf($template, admin_url('profile.php'), $user_identity, wp_logout_url(apply_filters('the_permalink', get_permalink())));
                 } else {
                     $options[$each_input] = '';
                 }
             } elseif ($do_define) {
                 // Option is set by a local shortcode
                 $options[$each_input] = $defined_inputs[$each_input];
             } else {
                 if ($each_input == 'comment') {
                     // Default comment textarea
                     $options[$each_input] = '<p><textarea placeholder="" id="comment" class="form-control" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>';
                 } elseif ($each_input == 'reply') {
                     $options[$each_input] = '';
                     // Leave a Reply
                 } elseif ($each_input == 'reply_to') {
                     $options[$each_input] = '';
                     // Leave a Reply to %s
                 } elseif ($each_input == 'cancel') {
                     $options[$each_input] = 'Cancel Reply';
                 } elseif ($each_input == 'submit') {
                     $options[$each_input] = 'Post Comment';
                 } elseif ($each_input == 'before') {
                     $options[$each_input] = '';
                 } elseif ($each_input == 'after') {
                     $options[$each_input] = '';
                 }
             }
         }
         // End comment form options
     }
     // For each field
     $args = array('fields' => apply_filters('comment_form_default_fields', $rendered_fields), 'id_form' => 'commentform', 'id_submit' => 'commentsubmit', 'title_reply' => $options['reply'], 'title_reply_to' => $options['reply_to'], 'cancel_reply_link' => $options['cancel'], 'label_submit' => $options['submit'], 'comment_field' => $options['comment'], 'must_log_in' => $options['login'], 'logged_in_as' => $options['logged-in'], 'comment_notes_before' => $options['before'], 'comment_notes_after' => $options['after']);
     // Return comment form
     ob_start();
     comment_form($args);
     return ob_get_clean();
 }
Exemple #11
0
 public static function process_results($results)
 {
     $parameters = self::$state['parameters'];
     if (!is_array($results)) {
         $results = array($results);
     }
     $results = apply_filters('ccs_loop_all_results', $results);
     $result = apply_filters('ccs_loop_preprocess_combined_result', implode('', $results));
     /*---------------------------------------------
      *
      * Process the combined result
      *
      */
     /*---------------------------------------------
      *
      * Strip tags
      *
      */
     if (!empty($parameters['strip'])) {
         $strip_tags = $parameters['strip'];
         if ($strip_tags == 'true') {
             $result = wp_kses($result, array());
         } else {
             // Allow certain tags
             $result = strip_tags(html_entity_decode($result), $strip_tags);
         }
     }
     /*---------------------------------------------
      *
      * Trim
      *
      */
     if (!empty($parameters['trim'])) {
         $trim = $parameters['trim'];
         if (empty($parameters['columns']) && $parameters['list'] != 'true') {
             $result = CCS_Format::trim($result, $trim);
         } else {
             // Trim each item for columns or list
             $new_results = array();
             foreach ($results as $result) {
                 $new_results[] = CCS_Format::trim($result, $trim);
             }
             $results = $new_results;
         }
     }
     /*---------------------------------------------
      *
      * Escape/unescape HTML
      *
      */
     if ($parameters['escape'] == 'true') {
         $new_results = array();
         foreach ($results as $result) {
             $new_results[] = esc_html($result);
         }
         $results = $new_results;
     }
     if ($parameters['unescape'] == 'true') {
         $new_results = array();
         foreach ($results as $result) {
             $new_results[] = htmlspecialchars_decode($result);
         }
         $results = $new_results;
     }
     /*---------------------------------------------
      *
      * Finally, columns or list
      *
      */
     if (!empty($parameters['columns'])) {
         $result = self::render_columns($results, $parameters['columns'], $parameters['pad'], $parameters['between']);
     } elseif (!empty($parameters['list'])) {
         // Wrap each list item
         $new_results = null;
         $item_tag = !empty($parameters['item']) ? $parameters['item'] : 'li';
         $item_class = !empty($parameters['item_class']) ? ' class="' . $parameters['item_class'] . '"' : null;
         $item_style = !empty($parameters['item_style']) ? ' style="' . $parameters['item_style'] . '"' : null;
         $list_tag = $parameters['list'] == 'true' ? 'ul' : $parameters['list'];
         $list_class = !empty($parameters['list_class']) ? ' class="' . $parameters['list_class'] . '"' : null;
         $list_style = !empty($parameters['list_style']) ? ' style="' . $parameters['list_style'] . '"' : null;
         $parameters['item_count'] = count($results);
         foreach ($results as $result) {
             $item = '<' . $item_tag . $item_class . $item_style . '>' . $result . '</' . $item_tag . '>';
             if (!empty($parameters['paginate'])) {
                 $item = '<' . $list_tag . $list_class . $list_style . '>' . $item . '</' . $list_tag . '>';
             }
             $new_results .= apply_filters('ccs_loop_each_item', $item, $parameters);
         }
         if (empty($parameters['paginate'])) {
             $result = '<' . $list_tag . $list_class . $list_style . '>' . $new_results . '</' . $list_tag . '>';
         } else {
             $result = $new_results;
         }
     }
     /*---------------------------------------------
      *
      * Cache the final result
      *
      */
     if (self::$state['do_cache'] == 'true') {
         CCS_Cache::set_transient(self::$state['cache_name'], $result, $parameters['expire']);
     }
     return apply_filters('ccs_loop_final_result', $result, $parameters);
 }
Exemple #12
0
 public static function clean_list($list, $delimiter = '')
 {
     if (empty($delimiter)) {
         $delimiter = ',';
     }
     $list = CCS_Format::explode_list($list, $delimiter);
     return implode($delimiter, $list);
 }