function meta_shortcode($atts, $content, $name)
 {
     if (!isset($this->shortcodes[$name])) {
         return;
     }
     $template = $this->shortcodes[$name];
     $atts['content'] = $content;
     foreach ($atts as $key => $value) {
         $tag = '{' . strtoupper($key) . '}';
         $template = str_replace($tag, $value, $template);
     }
     return $this->is_ccs ? do_ccs_shortcode($template) : do_shortcode($template);
 }
Example #2
0
 function calc_shortcode($atts, $content)
 {
     // Don't throw parse error unless in debug mode
     self::$math->suppress_errors = empty($atts['debug']);
     self::$math->vars(CCS_Pass::$vars);
     // Sync with get/set
     $result = self::$math->evaluate(do_ccs_shortcode($content));
     CCS_Pass::$vars = self::$math->vars();
     // Success/error returns nothing
     if (is_bool($result)) {
         return;
     }
     return $result;
 }
Example #3
0
function get_short($content = '', $data = array())
{
    // $data given as first argument
    if (is_array($content)) {
        $data = $content;
        $content = '';
    }
    // Use buffered content
    if (empty($content)) {
        $content = ob_get_clean();
    }
    // Pass data to shortcodes with {KEY}
    foreach ($data as $key => $value) {
        $tag = '{' . strtoupper($key) . '}';
        $content = str_replace($tag, $value, $content);
    }
    return do_ccs_shortcode($content);
}
Example #4
0
 function block_shortcode($atts, $content = '', $tag)
 {
     if (!is_array($atts)) {
         $atts = array($atts);
     }
     // Remove prefix
     while (isset($tag[0]) && $tag[0] == '-') {
         $tag = substr($tag, 1);
     }
     if (isset($atts['tag'])) {
         $tag = $atts['tag'];
     } elseif ($tag == 'block') {
         $tag = 'div';
     }
     // Construct block
     $out = '<' . $tag;
     foreach ($atts as $key => $value) {
         if ($key == 'tag') {
             continue;
         }
         if (is_numeric($key)) {
             $out .= ' ' . $value;
             // Attribute with no value
         } else {
             // Attribute values can have shortcodes with syntax: <shortcode>
             $value = str_replace(array('<', '>'), array('[', ']'), $value);
             $out .= ' ' . $key . '="' . do_ccs_shortcode($value) . '"';
         }
     }
     $out .= '>';
     if (!empty($content)) {
         $out .= do_ccs_shortcode($content);
         $out .= '</' . $tag . '>';
     }
     // Filter for extended features
     $data = array('atts' => $atts, 'content' => $content, 'tag' => $tag, 'out' => $out);
     $data = apply_filters('ccs_block_result', $data);
     return $data['out'];
 }
Example #5
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_ccs_shortcode($content);
         self::set_transient($name, $result, $expire);
     }
     return $result;
 }
Example #6
0
 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_Loop::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;
 }
Example #7
0
 function image_shortcode($atts, $content)
 {
     extract(shortcode_atts(array('alt' => '', 'width' => '', 'height' => '', 'class' => '', 'http' => ''), $atts));
     $src = do_ccs_shortcode($content);
     if ($http == 'true') {
         $src = self::maybe_add_http($src);
     }
     $out = '<img src="' . $src . '"';
     if (!empty($alt)) {
         $out .= ' alt="' . $alt . '"';
     }
     if (!empty($width)) {
         $out .= ' width="' . $width . '"';
     }
     if (!empty($height)) {
         $out .= ' height="' . $height . '"';
     }
     if (!empty($class)) {
         $out .= ' class="' . $class . '"';
     }
     $out .= '>';
     return $out;
 }
Example #8
0
 function when_shortcode($atts, $content)
 {
     if (!isset($atts[0])) {
         return;
     }
     $switch = self::$state['current_switch'];
     $when = $atts[0];
     if ($when == 'default') {
         self::$state['current_switch_default'] = $content;
         return;
     }
     return do_ccs_shortcode('[if ' . $switch . '=' . $when . ']' . $content . '[/if]');
 }
Example #9
0
 function comment_form_input_shortcode($atts, $content)
 {
     if (!isset($atts[0])) {
         return;
     }
     $inputs = self::$state['inputs'];
     if (in_array($atts[0], $inputs)) {
         self::$state['comment_form_fields'][$atts[0]] = do_ccs_shortcode($content);
     }
 }
Example #10
0
 function load($atts)
 {
     global $post;
     extract(shortcode_atts(array('dir' => null, 'file' => null, 'css' => null, 'cache' => 'true', 'js' => null, 'gfonts' => null, 'format' => null, 'shortcode' => null, 'php' => 'true', 'debug' => 'false', 'view' => ''), $atts));
     /*---------------------------------------------
      *
      * Load view template: [load view]
      *
      */
     if (isset($atts[0]) && $atts[0] == 'view') {
         $dir = 'views';
         if (!empty($view)) {
             $file = $view;
             $out = do_shortcode_file($file, $dir, $return = true);
         } else {
             // Default routing for view template
             $current_post_type = $post->post_type;
             $current_post_slug = $post->post_name;
             // post_type/post_slug.html
             $file = $current_post_type . '/' . $current_post_slug;
             $out = do_shortcode_file($file, $dir, $return = true);
             if (!$out) {
                 // If not, post_slug.html
                 $out = do_shortcode_file($current_post_slug, $dir, $return = true);
             }
         }
         return $out;
     }
     /*---------------------------------------------
      *
      * Set up paths
      *
      */
     $root_path = ABSPATH;
     $path = trailingslashit($root_path);
     $site_url = trailingslashit(get_site_url());
     $content_url = trailingslashit(content_url());
     $content_path = trailingslashit(WP_CONTENT_DIR);
     if (strpos($file, 'http://') !== false || strpos($file, 'https://') !== false || strpos($css, 'http://') !== false || strpos($css, 'https://') !== false || strpos($js, 'http://') !== false || strpos($js, 'https://') !== false) {
         $dir = 'web';
     }
     switch ($dir) {
         case 'web':
             $path = '';
             break;
         case 'site':
             $dir = trailingslashit(home_url());
             break;
             // Site address
         // Site address
         case 'wordpress':
             $dir = $site_url;
             break;
             // WordPress directory
         // WordPress directory
         case 'content':
             $dir = $content_url;
             $path = $content_path;
             break;
         case 'layout':
             $dir = $content_url . 'layout/';
             $path = $content_path . 'layout/';
             break;
         case 'views':
             $dir = $content_url . 'views/';
             $path = $content_path . 'views/';
             break;
         case 'child':
             $dir = trailingslashit(get_stylesheet_directory_uri());
             $path = trailingslashit(get_stylesheet_directory());
             break;
         default:
             if ($dir == 'theme' || $dir == 'template') {
                 $dir = trailingslashit(get_template_directory_uri());
                 $path = trailingslashit(get_template_directory());
             } else {
                 $dir = trailingslashit(get_stylesheet_directory_uri());
                 $path = trailingslashit(get_stylesheet_directory());
                 if ($css != '') {
                     $dir .= 'css/';
                 }
                 if ($js != '') {
                     $dir .= 'js/';
                 }
             }
     }
     $out = '';
     /*---------------------------------------------
      *
      * Load CSS - [load css]
      *
      */
     if (!empty($css)) {
         if ($dir == 'web') {
             $dir = '';
             if (strpos($css, 'http://') === false && strpos($css, 'https://') === false) {
                 $dir = 'http://';
             }
         }
         $out = '<link rel="stylesheet" type="text/css" href="' . $dir . $css;
         if ($cache == 'false') {
             // Generate random string to prevent caching
             $tail = '';
             for ($i = 0; $i < 8; $i++) {
                 $tail .= rand(0, 9);
             }
             $out .= '?' . $tail;
         }
         $out .= '" />';
         return $out;
     }
     /*---------------------------------------------
      *
      * Load Google Fonts - [load gfonts]
      *
      */
     if (!empty($gfonts)) {
         return '<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=' . $gfonts . '" />';
     }
     /*---------------------------------------------
      *
      * Load JS - [load js]
      *
      */
     if (!empty($js)) {
         if ($dir == 'web') {
             $dir = '';
             if (strpos($js, 'http://') === false && strpos($js, 'https://') === false) {
                 $dir = 'http://';
             }
         }
         // cache/version?
         return '<script type="text/javascript" src="' . $dir . $js . '"></script>';
     }
     /*---------------------------------------------
      *
      * Load file - [load file]
      *
      */
     if (!empty($file)) {
         if ($dir != 'web') {
             // Include file
             ob_start();
             @(include $path . $file);
             $out = ob_get_clean();
         } else {
             // Get external file
             if (strpos($file, 'http://') === false && strpos($file, 'https://') === false) {
                 $file = 'http://' . $file;
             }
             $url = $file;
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $url);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             $data = curl_exec($ch);
             $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
             curl_close($ch);
             if ($status == 200) {
                 $out = $data;
                 // Success
             }
         }
         if (!empty($out)) {
             if ($format == 'on' || $format == 'true') {
                 // Format only if specified
                 $out = wpautop($out);
             }
             if ($shortcode != 'false' && $shortcode != 'off') {
                 // Do shortcode by default
                 $out = do_ccs_shortcode($out);
             }
             return $out;
         }
     }
 }
Example #11
0
 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;
 }
Example #12
0
 static function set_shortcode($atts, $content = '')
 {
     if (empty($atts[0])) {
         return;
     }
     $var = $atts[0];
     // Do shortcode by default
     if (empty($atts['shortcode'])) {
         $content = do_ccs_shortcode($content);
     }
     if (!empty($atts['trim'])) {
         $trim = $atts['trim'] == 'true' ? '' : $atts['trim'];
         $content = trim($content, " \t\n\r\v," . $trim);
     }
     self::$vars[$var] = $content;
 }
Example #13
0
 function do_raw($attr, $content)
 {
     return do_ccs_shortcode($content);
 }
Example #14
0
 function default_loop_shortcode($atts, $template)
 {
     // If empty
     $if_empty = self::get_between('[if empty]', '[/if]', $template);
     $content = str_replace($if_empty, '', $template);
     $max = isset($atts['count']) ? $atts['count'] : 9999;
     $count = 0;
     ob_start();
     if (have_posts()) {
         while (have_posts()) {
             $count++;
             if ($count > $max) {
                 break;
             }
             the_post();
             // Set up post data
             echo do_ccs_shortcode($content);
         }
     } elseif (!empty($if_empty)) {
         echo do_ccs_shortcode($if_empty);
     }
     return ob_get_clean();
 }
Example #15
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;
 }
Example #16
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;
 }
Example #17
0
 function link_shortcode($atts, $content)
 {
     extract(shortcode_atts(array('field' => '', 'custom' => '', 'url' => '', 'alt' => '', 'title' => '', 'target' => '', 'open' => '', 'http' => '', 'id' => '', 'type' => '', 'name' => '', 'link_id' => '', 'class' => '', 'mail' => '', 'before' => '', 'after' => '', 'escape' => 'true'), $atts));
     if (empty($field)) {
         $field = isset($atts[0]) ? $atts[0] : 'url';
     }
     // default
     if (!empty($url)) {
         $value = $url;
     } else {
         $x = '[field ' . $field;
         if (!empty($id)) {
             $x .= ' id=' . $id;
         } elseif (!empty($name)) {
             $x .= ' name=\'' . $name . '\'';
         }
         if (!empty($type)) {
             $x .= ' type=' . $type;
         }
         if (!empty($custom)) {
             $x .= ' custom=' . $custom;
         }
         $x .= ']';
         $value = do_shortcode($x);
         if ($escape == 'true') {
             $value = esc_html($value);
         }
     }
     if ($mail == 'true') {
         $before = "mailto:";
     }
     $value = $before . $value . $after;
     if ($http == 'true') {
         $value = self::maybe_add_http($value);
     }
     $out = '<a href="' . $value . '"';
     if (!empty($alt)) {
         $out .= ' alt="' . $alt . '"';
     }
     if (!empty($class)) {
         $out .= ' class="' . $class . '"';
     }
     if (!empty($link_id)) {
         $out .= ' id="' . $link_id . '"';
     }
     if (!empty($title)) {
         $out .= ' title="' . $title . '"';
     }
     if ($open == 'new') {
         $target = '_blank';
     }
     if (!empty($target)) {
         $out .= ' target="' . $target . '"';
     }
     $out .= '>';
     $out .= do_ccs_shortcode($content);
     $out .= '</a>';
     return $out;
 }
Example #18
0
 function when_shortcode($atts, $content)
 {
     //if (!isset($atts[0])) return;
     $switch = self::$state['current_switch'];
     $switch_slug = explode('=', $switch);
     $switch_slug = $switch_slug[0];
     $condition = '';
     foreach ($atts as $key => $value) {
         if ($value == 'default') {
             self::$state['current_switch_default'] = $content;
             return;
         } elseif ($value == 'or') {
             continue;
         }
         $this_switch = $switch;
         if (is_numeric($key)) {
             if ($switch_slug === 'check') {
                 $this_switch = $switch . ' value';
             }
         } else {
             $this_switch = $switch . ' ' . $key;
         }
         // Backward compatibility for multiple values
         $values = explode(',', $value);
         foreach ($values as $val) {
             $condition .= '[if ' . $this_switch . '=' . $val . ']x[/if]';
         }
     }
     //echo str_replace(array('[',']'), '', $condition).'<br>';
     $condition = do_shortcode($condition);
     if (!empty($condition)) {
         // True
         return do_ccs_shortcode($content);
     }
 }
 static function ccs_content_filter($content)
 {
     $content = do_ccs_shortcode($content, false);
     // This gets passed to do_shortcode
     return $content;
 }
Example #20
0
 function blog_shortcode($atts, $content)
 {
     extract(shortcode_atts(array('id' => ''), $atts));
     $out = $content;
     if (empty($id) || !blog_exists($id)) {
         return;
     }
     switch_to_blog($id);
     $out = do_ccs_shortcode($out);
     restore_current_blog();
     return $out;
 }
Example #21
0
 static function loop_menu_shortcode($atts, $content)
 {
     extract(shortcode_atts(array('name' => '', 'order' => 'ASC', 'orderby' => 'menu', 'count' => '', 'list' => '', 'ul_class' => '', 'li_class' => '', 'ul_id' => '', 'li_id' => '', 'parent' => 'true'), $atts));
     if (empty($name)) {
         return;
     }
     if ($orderby == 'menu') {
         $orderby = 'menu_order';
     }
     if (empty($count)) {
         $count = 99999;
     }
     // All
     $args = array('order' => strtoupper($order), 'orderby' => $orderby, 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true, 'update_post_term_cache' => false);
     $items = wp_get_nav_menu_items($name, $args);
     if (empty($items)) {
         return;
     }
     $result = '';
     self::$state['depth']++;
     self::$state['current_menu_names'][self::$state['depth']] = $name;
     $index = 0;
     $final_items = array();
     foreach ($items as $key => $menu_item) {
         $id = @$menu_item->object_id;
         $type = @$menu_item->type;
         $menu_types = array('custom', 'taxonomy');
         if (in_array($type, $menu_types)) {
             if ($type == 'taxonomy') {
                 $id = @$menu_item->ID;
             }
             $type = 'type=nav_menu_item ';
         } else {
             $type = '';
         }
         $skip = false;
         if (empty($id)) {
             $skip = true;
         }
         if (!empty($parent)) {
             $pid = @$menu_item->menu_item_parent;
             //debug_array('CHECK PARENT:'.$parent.' == '.$pid.'<br>');
             if ($parent == 'true') {
                 if ($pid != 0) {
                     $skip = true;
                 }
             } elseif ($pid != $parent) {
                 $skip = true;
             }
         }
         if (!$skip) {
             $final_items[] = $menu_item;
         }
     }
     $max = count($final_items);
     foreach ($final_items as $menu_item) {
         $index++;
         if ($index > $count) {
             continue;
         }
         $prevo = self::$state['current_menu_object'];
         //debug_array($menu_item);
         $url = $menu_item->url;
         $title = $menu_item->title;
         self::$state['current_menu_object'] = array('title' => $title, 'title-link' => '<a href="' . $url . '">' . $title . '</a>', 'url' => $url, 'id' => $menu_item->object_id);
         self::$state['total_menu_count'][self::$state['depth']] = $max;
         self::$state['menu_index'][self::$state['depth']] = $index;
         self::$state['current_menu_parameters'][self::$state['depth']] = $atts;
         self::$state['current_menu_item_ids'][self::$state['depth']] = $menu_item->object_id;
         self::$state['is_menu_loop'] = true;
         $item_result = do_ccs_shortcode($content);
         self::$state['current_menu_object'] = $prevo;
         if ($list == 'true') {
             $item_result_wrap = '<li';
             if (!empty($li_id)) {
                 $item_result_wrap .= ' id="' . $li_id . '"';
             }
             if (!empty($li_class)) {
                 $item_result_wrap .= ' class="' . $li_class . '"';
             }
             $item_result_wrap .= '>';
             $item_result = $item_result_wrap . $item_result . '</li>';
         }
         $result .= $item_result;
     }
     if ($list == 'true' && !empty($result)) {
         $begin = '<ul';
         if (!empty($ul_id)) {
             $begin .= ' id="' . $ul_id . '"';
         }
         if (!empty($ul_class)) {
             $begin .= ' class="' . $ul_class . '"';
         }
         $begin .= '>';
         $result = $begin . $result . '</ul>';
     }
     self::$state['is_menu_loop'] = false;
     self::$state['depth']--;
     return $result;
 }