function do_ccs_shortcode($content, $global = true) { $prev = CCS_Plugin::$state['doing_ccs_filter']; CCS_Plugin::$state['doing_ccs_filter'] = true; //$content = CCS_Format::protect_script($content, $global); $content = do_local_shortcode('ccs', $content, false); CCS_Plugin::$state['doing_ccs_filter'] = $prev; // Restore if ($global) { $content = do_shortcode($content); } return $content; }
public static function pass_shortcode($atts, $content, $shortcode_name) { $args = array('field' => '', 'date_format' => '', 'in' => '', 'fields' => '', 'array' => '', 'debug' => '', 'field_loop' => '', 'taxonomy_loop' => '', 'list' => '', 'acf_gallery' => '', 'current' => '', 'orderby' => '', 'order' => '', 'hide_empty' => 'false', 'pre_render' => 'false', 'post_render' => 'true', 'trim' => 'false', 'count' => '9999', 'user_field' => '', 'user_fields' => '', 'global' => '', 'sub' => '', 'random' => ''); extract(shortcode_atts($args, $atts, true)); if ($pre_render == 'true') { $content = do_local_shortcode('ccs', $content, true); } if (CCS_Loop::$state['is_loop']) { $post_id = do_shortcode('[field id]'); } else { $post_id = get_the_ID(); } // Support nested $prefix = ''; if (substr($shortcode_name, 0, 2) == '--') { $prefix = '--'; } elseif (substr($shortcode_name, 0, 1) == '-') { $prefix = '-'; } if (!empty($date_format)) { // Date format: allow escape via "//" because "\" disappears in shortcode parameters $date_format = str_replace("//", "\\", $date_format); } /*--------------------------------------------- * * Pass single field to {FIELD} * */ if (!empty($global) && empty($field) && $field != '0') { $field = 'this'; } if (!empty($array)) { $field = $array; } if (!empty($field) || $field == '0') { if ($field == 'gallery') { $field = '_custom_gallery'; } // Support CCS gallery field // Pass global variable if (!empty($global)) { $field_value = ''; if ($global == 'route') { // Parsed URL route $request = CCS_URL::get_route(); $requests = CCS_URL::get_routes(); if ($field == 'this') { $field_value = $request; // whole thing for ($i = 0; $i < 6; $i++) { $part = ''; if (isset($requests[$i])) { $part = $requests[$i]; } $tag = '{' . $prefix . 'FIELD_' . ($i + 1) . '}'; $content = str_replace($tag, $part, $content); } } else { if (isset($requests[intval($field)])) { $field_value = $requests[intval($field)]; } } } elseif ($global == 'query') { // Parsed query string $field_value = CCS_URL::get_query(); $query_array = CCS_URL::get_queries(); foreach ($query_array as $key => $value) { $tag = '{' . $prefix . strtoupper($key) . '}'; $content = str_replace($tag, $value, $content); } if (!empty($fields)) { // Remove what was not rendered $fields = CCS_Loop::explode_list($fields); foreach ($fields as $key) { $tag = '{' . $prefix . strtoupper($key) . '}'; $content = str_replace($tag, '', $content); } $fields = ''; } elseif (!empty($field)) { $tag = '{' . $prefix . 'FIELD' . '}'; $value = isset($query_array[$field]) ? $query_array[$field] : ''; $content = str_replace($tag, $value, $content); } } else { if ($field == 'this' && isset($GLOBALS[$global])) { $field_value = $GLOBALS[$global]; } elseif (!empty($sub) && isset($GLOBALS[$global][$field][$sub])) { $field_value = $GLOBALS[$global][$field][$sub]; } elseif (isset($GLOBALS[$global][$field])) { $field_value = $GLOBALS[$global][$field]; } } // end global // Repeater or flexible content field } elseif (class_exists('CCS_To_ACF') && CCS_To_ACF::$state['is_repeater_or_flex_loop']) { if ($field == 'index') { $field_value = CCS_To_ACF::$state['repeater_index']; } elseif (function_exists('get_sub_field')) { $field_value = get_sub_field($field); } else { $field_value = null; } // Predefined or custom field } else { $field_value = CCS_Content::get_prepared_field($field, $post_id); } if (is_array($field_value)) { if (!empty($array)) { if ($debug == 'true') { ob_start(); echo '<pre><code>'; print_r($field_value); echo '</code></pre>'; return ob_get_clean(); } // array parameter foreach ($field_value as $key => $value) { $content = str_replace('{' . strtoupper($key) . '}', $value, $content); } } else { // field parameter foreach ($field_value as $key => $value) { $content = str_replace('{' . $prefix . 'FIELD:' . strtoupper($key) . '}', $value, $content); } } //$field_value = '(Array)'; $field_value = implode(",", $field_value); } else { // Clean extra spaces if it's a list $field_value = CCS_Loop::clean_list($field_value); } if (!empty($date_format)) { // Date format for custom field if (!empty($in) && $in == 'timestamp' && is_numeric($field_value)) { $field_value = gmdate("Y-m-d H:i:s", $field_value); } if ($date_format == 'true') { $date_format = get_option('date_format'); } $field_value = mysql2date($date_format, $field_value); } // Replace it $content = str_replace('{' . $prefix . 'FIELD}', $field_value, $content); /*--------------------------------------------- * * Pass each item in a list stored in a field * */ } elseif (!empty($field_loop)) { if ($field_loop == 'gallery' && class_exists('CCS_Gallery_Field')) { // Support gallery field $field_values = CCS_Gallery_Field::get_image_ids(); } else { $field_values = get_post_meta($post_id, $field_loop, true); } if (!empty($field_values)) { if (!is_array($field_values)) { $field_values = CCS_Loop::explode_list($field_values); } // Get comma-separated list of values $contents = null; // Loop for the number of field values foreach ($field_values as $field_value) { $contents[] = str_replace('{' . $prefix . 'FIELD}', $field_value, $content); } $content = implode('', $contents); } /*--------------------------------------------- * * Pass image IDs from ACF gallery * */ } elseif (!empty($acf_gallery)) { if (function_exists('get_field') && function_exists('get_sub_field')) { $field = $acf_gallery; $images = get_field($acf_gallery, $post_id, false); if (empty($field_value)) { // Try sub field $images = get_sub_field($acf_gallery, $post_id, false); } if (!empty($images)) { $ids = array(); foreach ($images as $image) { $ids[] = $image['id']; } if (is_array($ids)) { $replace = implode(',', $ids); } else { $replace = $ids; } $content = str_replace('{' . $prefix . 'FIELD}', $replace, $content); } } /*--------------------------------------------- * * Pass each taxonomy term * */ } elseif (!empty($taxonomy_loop)) { if ($current == 'true') { if (empty($orderby) && empty($order)) { // Doesn't accept order/orderby parameters - but it's cached $terms = get_the_terms($post_id, $taxonomy_loop); } else { $terms = wp_get_object_terms($post_id, $taxonomy_loop, array('orderby' => empty($orderby) ? 'name' : $orderby, 'order' => empty($order) ? 'ASC' : strtoupper($order))); } } else { // Get all terms: not by post ID $terms = get_terms($taxonomy_loop, array('orderby' => empty($orderby) ? 'name' : $orderby, 'order' => empty($order) ? 'ASC' : strtoupper($order), 'hide_empty' => $hide_empty == 'true')); } $contents = ''; // Loop through each term if (!empty($terms)) { $i = 0; foreach ($terms as $term) { if ($i++ >= $count) { break; } $slug = $term->slug; $id = $term->term_id; $name = $term->name; $replaced_content = str_replace('{' . $prefix . 'TERM}', $slug, $content); $replaced_content = str_replace('{' . $prefix . 'TERM_ID}', $id, $replaced_content); $replaced_content = str_replace('{' . $prefix . 'TERM_NAME}', $name, $replaced_content); $contents .= $replaced_content; } } $content = $contents; /*--------------------------------------------- * * Pass an arbitrary list of items * */ } elseif (!empty($list)) { $items = CCS_Loop::explode_list($list); // Comma-separated list -> array // Create range $new_items = array(); foreach ($items as $item) { if (strpos($item, '~') !== false) { $pair = CCS_Loop::explode_list($item, '~'); $list = range($pair[0], $pair[1]); foreach ($list as $list_item) { $new_items[] = $list_item; } } else { $new_items[] = $item; } } $items = $new_items; $contents = ''; foreach ($items as $item) { $replaced_content = $content; // Multiple items per loop if (strpos($item, ':') !== false) { $parts = explode(':', $item); $count = count($parts); for ($i = 0; $i < $count; $i++) { $this_item = trim($parts[$i]); // Index starts at ITEM_1 $replaced_content = str_replace('{' . $prefix . 'ITEM_' . ($i + 1) . '}', $this_item, $replaced_content); // Would this be useful? // $replaced_content = str_replace('{Item_'.$i.'}', ucfirst($this_item), // $replaced_content); } } else { $replaced_content = str_replace('{' . $prefix . 'ITEM}', $item, $replaced_content); $replaced_content = str_replace('{' . $prefix . 'Item}', ucfirst($item), $replaced_content); } $contents .= $replaced_content; } $content = $contents; } /*--------------------------------------------- * * Pass user field(s) * */ if (!empty($user_field)) { $user_field_value = do_shortcode('[user ' . $user_field . ' out="slug"]'); // Replace it $content = str_replace('{' . $prefix . 'USER_FIELD}', $user_field_value, $content); } if (!empty($user_fields)) { $user_fields_array = CCS_Loop::explode_list($user_fields); foreach ($user_fields_array as $this_field) { $user_field_value = do_shortcode('[user ' . $this_field . ' out="slug"]'); // Replace {FIELD_NAME} $content = str_replace('{' . $prefix . strtoupper($this_field) . '}', $user_field_value, $content); } } if (!empty($random)) { $content = str_replace('{' . $prefix . 'RANDOM}', do_shortcode('[random ' . $random . ']'), $content); } if (!empty($fields)) { if (!empty($global)) { $fields = CCS_Loop::explode_list($fields); foreach ($fields as $this_field) { $tag = '{' . $prefix . strtoupper($this_field) . '}'; $value = ''; if (isset($GLOBALS[$global][$this_field])) { $value = $GLOBALS[$global][$this_field]; } $content = str_replace($tag, $value, $content); } } else { // Replace these fields (+default) $content = CCS_Loop::render_field_tags($content, array('fields' => $fields)); } } else { $content = CCS_Loop::render_default_field_tags($content); } if ($post_render == 'true') { $content = do_local_shortcode('ccs', $content, true); } // Trim trailing white space and comma if ($trim != 'false') { if ($trim == 'true') { $trim = null; } $content = rtrim($content, " \t\n\r\v," . $trim); } return $content; }
function wck_repeater_shortcode($atts, $content) { extract(shortcode_atts(array('meta' => '', 'metabox' => '', 'id' => ''), $atts)); if (!empty($metabox)) { $meta = $metabox; } if (empty($meta)) { return; } // Needs metabox name $out = null; self::$state['is_wck_repeater'] = true; self::$state['wck_repeater_meta'] = $meta; if (!empty($id)) { self::$state['wck_repeater_id'] = $id; $metas = get_cfc_meta($meta, $id); } else { self::$state['wck_repeater_id'] = 0; $metas = get_cfc_meta($meta); } // Loop through repeater foreach ($metas as $key => $value) { self::$state['wck_repeater_key'] = $key; $out[] = do_local_shortcode('ccs', $content, true); } self::$state['is_wck_repeater'] = false; self::$state['wck_repeater_id'] = 0; return implode("", $out); }
function switch_shortcode($atts, $content) { $switch = ''; foreach ($atts as $key => $value) { if (is_numeric($key)) { $switch .= $value; continue; } // Add trailing parameter for when/case switch ($key) { case 'taxonomy': $switch .= $key . '=' . $value . ' term'; break; case 'field': // Fall through // Fall through case 'user_field': $switch .= $key . '=' . $value . ' value'; break; default: // Put other params in front $switch = $key . '=' . $value . ' ' . $switch; break; } } if (empty($switch)) { return; } self::$state['current_switch'] = $switch; self::$state['current_switch_default'] = ''; $result = do_local_shortcode('ccs_switch', $content); // If empty, do default $check = trim($result); // Strip new lines if (empty($check)) { $result = self::$state['current_switch_default']; } self::$state['current_switch'] = ''; self::$state['current_switch_default'] = ''; if (!empty($result)) { $result = do_ccs_shortcode($result); } return $result; }
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(); }
public static function render_template($template) { $template = self::render_field_tags($template, self::$state['parameters']); $template = do_local_shortcode('loop', $template, false); if (self::$state['parameters']['local'] == 'true') { $template = do_ccs_shortcode($template); } else { $template = do_shortcode($template); } $template = apply_filters('ccs_loop_each_result', $template, self::$state['parameters']); return $template; }