コード例 #1
0
/**
 * Parse shortcodes in the page content
 * @param string page content to be evaluated for internal shortcodes
 */
function wpv_parse_content_shortcodes($content) {
	global $WPV_settings;
    
    $views_shortcodes_regex = wpv_inner_shortcodes_list_regex();
    
	$inner_expressions = array();
	$inner_expressions[] = "/\\[types.*?\\].*?\\[\\/types\\]/i";    
	$inner_expressions[] = "/\\[(". $views_shortcodes_regex .").*?\\]/i";
	// support for custom inner shortcodes via settings page
	// since 1.4
	$custom_inner_shortcodes = array();
	if ( isset( $WPV_settings->wpv_custom_inner_shortcodes ) && is_array( $WPV_settings->wpv_custom_inner_shortcodes ) ) {
		$custom_inner_shortcodes = $WPV_settings->wpv_custom_inner_shortcodes;
	}
	// wpv_custom_inner_shortcodes filter
	// since 1.4
	// takes an array of shortcodes and returns an array of shortcodes
	$custom_inner_shortcodes = apply_filters( 'wpv_custom_inner_shortcodes', $custom_inner_shortcodes );
	// remove duplicates
	$custom_inner_shortcodes = array_unique( $custom_inner_shortcodes );
	// add the custom inner shortcodes, whether they are self-closing or not
	if ( sizeof( $custom_inner_shortcodes ) > 0 ) {
		foreach ( $custom_inner_shortcodes as $custom_inner_shortcode ) {
			$inner_expressions[] = "/\\[" . $custom_inner_shortcode . ".*?\\].*?\\[\\/" . $custom_inner_shortcode . "\\]/i";
		}
		$inner_expressions[] = "/\\[(" . implode( '|', $custom_inner_shortcodes ) . ").*?\\]/i";
	}
	// search for shortcodes
	$matches = array();
	$counts = _find_outer_brackets($content, $matches);
	
	// iterate 0-level shortcode elements
	if($counts > 0) {
		foreach($matches as $match) {
			
			foreach ($inner_expressions as $inner_expression) {
				$inner_counts = preg_match_all($inner_expression, $match, $inner_matches);
				
				// replace all 1-level inner shortcode matches
				if($inner_counts > 0) {
					foreach($inner_matches[0] as &$inner_match) {
						// execute shortcode content and replace
						$resolved_match = wpv_preprocess_shortcodes_in_html_elements($inner_match);
						$filter_state = new WPV_WP_filter_state( 'the_content' );
						$resolved_match = do_shortcode( $resolved_match );
						$filter_state->restore();
						$content = str_replace($inner_match, $resolved_match, $content);
						$match = str_replace($inner_match, $resolved_match, $match);
					}
				}
			}
		}
	}
	
	return $content;
}
コード例 #2
0
/**
* wpv_preprocess_shortcodes_in_html_elements
*
* Processes Views shortcodes inside HTML attributes, fixing a compatibility issue with WordPress 4.2.3 and beyond.
* Heavily inspired in do_shortcodes_in_html_tags.
*
* @since 1.9.1
*/

function wpv_preprocess_shortcodes_in_html_elements( $content ) {
	global $WPV_settings;
	$views_shortcodes_regex = wpv_inner_shortcodes_list_regex();
	$inner_expressions = array();
	$inner_expressions[] = array(
								 'regex'       => "/\\[types.*?\\]\\[\\/types\\]/i",
								 'has_content' => false
								);
	$inner_expressions[] = array(
								 'regex'       => "/\\[types.*?\\](.*?)\\[\\/types\\]/i",
								 'has_content' => true
								);
	$inner_expressions[] = array(
								 'regex'       => "/\\[(". $views_shortcodes_regex .").*?\\]/i",
								 'has_content' => false
								);
	
	// support for custom inner shortcodes via settings page
	// since 1.4
	$custom_inner_shortcodes = array();
	if ( isset( $WPV_settings->wpv_custom_inner_shortcodes ) && is_array( $WPV_settings->wpv_custom_inner_shortcodes ) ) {
		$custom_inner_shortcodes = $WPV_settings->wpv_custom_inner_shortcodes;
	}
	// wpv_custom_inner_shortcodes filter
	// since 1.4
	// takes an array of shortcodes and returns an array of shortcodes
	$custom_inner_shortcodes = apply_filters( 'wpv_custom_inner_shortcodes', $custom_inner_shortcodes );
	// remove duplicates
	$custom_inner_shortcodes = array_unique( $custom_inner_shortcodes );
	// add the custom inner shortcodes, whether they are self-closing or not
	if ( sizeof( $custom_inner_shortcodes ) > 0 ) {
		foreach ( $custom_inner_shortcodes as $custom_inner_shortcode ) {
			$inner_expressions[] = array(
										 'regex'       => "/\\[" . $custom_inner_shortcode . ".*?\\](.*?)\\[\\/" . $custom_inner_shortcode . "\\]/is",
										 'has_content' => true
										);
		}
		$inner_expressions[] = array(
									 'regex' => "/\\[(" . implode( '|', $custom_inner_shortcodes ) . ").*?\\]/i",
									 'has_content' => false
									);
	}
			
			
	// Normalize entities in unfiltered HTML before adding placeholders.
	$trans = array( '[' => '[', ']' => ']' );
	$content = strtr( $content, $trans );
	
	$textarr = wpv_html_split( $content );

	foreach ( $textarr as &$element ) {
		if ( '' == $element || '<' !== $element[0] ) {
			continue;
		}

		$noopen = false === strpos( $element, '[' );
		$noclose = false === strpos( $element, ']' );
		if ( $noopen || $noclose ) {
			// This element does not contain shortcodes.
			continue;
		}

		if ( '<!--' === substr( $element, 0, 4 ) || '<![CDATA[' === substr( $element, 0, 9 ) ) {
			continue;
		}
		
		foreach ( $inner_expressions as $shortcode ) {
			$counts = preg_match_all( $shortcode[ 'regex' ], $element, $matches );
			
			if ( $counts > 0 ) {
				foreach ( $matches[0] as $index => &$match ) {
					
					// We need to exclude wpv-post-body here otherwise
					// wpautop can be applied to it too soon.
					
					if ( strpos( $match, '[wpv-post-body' ) !== 0 ) {
						$string_to_replace = $match;
						
						// execute shortcode content and replace
						
						if ( $shortcode[ 'has_content' ] ) {
							$inner_content = $matches[1][ $index ];
							if ( $inner_content ) {
								$new_inner_content = wpv_preprocess_shortcodes_in_html_elements( $inner_content );
								$match = str_replace( $inner_content, $new_inner_content, $match );
							}
						}
						$filter_state = new WPV_WP_filter_state( 'the_content' );
						$replacement = do_shortcode( $match );
						$filter_state->restore();
						$resolved_match = $replacement;
						$element = str_replace( $string_to_replace, $resolved_match, $element );
					}
				}
			}
		}
		
	}
	
	$content = implode( '', $textarr );
	
	return $content;
}
コード例 #3
0
/**
 * Content of wpv-conditional modal window.
 *
 * Content of wpv-conditional modal window used when we editing a entryn and
 * setup a wpv-conditional shortcode using Views Shortcode GUI API
 *
 * @since 1.9.0
 *
 * @param string $id Shortcode id
 * @param array $ shortcode data
 * @param array $ css classes
 * @param array $post_type post type
 *
 * @return string Content of modal window for wpv-shortcode.
 */
function wpv_shortcode_wpv_conditional_callback( $id, $data = array(), $classes = array(), $post_type = '' ) {
	global $WP_Views;
    /*if ( empty($post_type) ) {
        return __('Wrong post type', 'wpv-views');
    }*/
	/*
	if ( empty( $post_type ) ) {
		$post_type_slug = '';
	} else {
		if ( isset( $post_type->slug ) ) {
			$post_type_slug = $post_type->slug;
		} elseif ( isset( $post_type->name ) ) {
			$post_type_slug = $post_type->name;
		} else {
			$post_type_slug = '';
		}
	}
	*/
    
    $content = '';
    $fields = array(
        'types' => array(
            'label' => __('Types Fields', 'wpv-views'),
        ),
        'custom-fields' => array(
            'label' => __('Custom Fields', 'wpv-views'),
        ),
        'views-shortcodes' => array(
            'label' => __('Views Shortcodes', 'wpv-views'),
        ),
        'custom-shortcodes' => array(
            'label' => __('Custom Shortcodes', 'wpv-views'),
        ),
        'custom-functions' => array(
            'label' => __('Custom Functions', 'wpv-views'),
        ),
    );
    foreach( array_keys($fields) as $key ) {
        $fields[$key]['fields'] = array();
        $fields[$key]['slug'] = $key;
    }

    /**
     * get types custom fields
     */
	 /*
    $groups = apply_filters('wpcf_get_groups_by_post_type', array(), $post_type);
    if ( !empty($groups) ) {
        foreach( $groups as $group_id => $group_data ) {
            $fields_from_group = apply_filters('wpcf_fields_by_group', array(), $group_id);
            foreach ( $fields_from_group as $field_slug => $field_data ) {
                $fields['types']['fields'][$field_slug] = array(
                    'label' => $field_data['name'],
                    'slug' => sprintf('$(%s)', $field_data['slug']),
                    'type' => $field_data['type'],
                );
            }
        }
    }
	*/

	$post_meta_keys = $WP_Views->get_meta_keys();
	//$post_meta_keys = array_diff( $post_meta_keys, apply_filters( 'wpcf_get_all_fields_slugs', array() ) );
    if ( !empty( $post_meta_keys ) ) {
        foreach( $post_meta_keys as $key ) {
            if ( empty($key) ) {
                continue;
            }
			if ( wpv_is_types_custom_field( $key ) ) {
				$fields['types']['fields'][$key] = array(
					'label' => wpv_types_get_field_name( $key ),
					'slug' => sprintf('$(%s)', $key),
					'type' => 'text',
				);

			} else {
				$fields['custom-fields']['fields'][$key] = array(
					'label' => $key,
					'slug' => sprintf('$(%s)', $key),
					'type' => 'text',
				);
			}
        }
    }

    /**
     * get Views options
     */
    $options = get_option('wpv_options');

    /**
     * Views hidden CF's - already done in get_meta_keys() above!!
     */
	/*
    if ( isset($options['wpv_show_hidden_fields']) && !empty($options['wpv_show_hidden_fields'] ) ) {
        foreach( explode(',', $options['wpv_show_hidden_fields']) as $key) {
            if ( empty($key) ) {
                continue;
            }
            $fields['custom-fields']['fields'][$key] = array(
                'label' => $key,
                'slug' => sprintf('$(%s)', $key),
                'type' => 'text',
            );
        }
    }
	*/

    /**
     * Views Shortcodes
     */

    global $shortcode_tags;
    if ( is_array($shortcode_tags) ) {
        foreach (array_keys($shortcode_tags) as $key) {
            $views_shortcodes_regex = wpv_inner_shortcodes_list_regex();
            $include_expression = "/(". $views_shortcodes_regex .").*?/i";
           
            $check_shortcode = preg_match_all($include_expression, $key, $inner_matches);
            if ( $check_shortcode == 0 ){
                continue;
            }
            /**
             * do not add non-Views shortcodes
             */
            if ( !preg_match('/^wpv/', $key ) ) {
                continue;
            }
            /**
             * add shortode to list
             */
            $fields['views-shortcodes']['fields'][$key] = array(
                'label' => $key,
                'slug' => sprintf('\'[%s]\'', $key),
                'type' => 'text',
            );
        }
        ksort($fields['views-shortcodes']['fields']);
    }

    /**
     * Custom Functions
     */
    if ( isset($options['wpv_custom_conditional_functions']) && !empty($options['wpv_custom_conditional_functions'] ) ) {
        foreach( $options['wpv_custom_conditional_functions'] as $key) {
            if ( empty($key) ) {
                continue;
            }
            $fields['custom-functions']['fields'][$key] = array(
                'label' => $key,
                'slug' => sprintf('%s()', $key),
                'type' => 'text',
            );
        }
    }

    /**
     * Custom Shortcodes
     */
    if ( isset($options['wpv_custom_inner_shortcodes']) && !empty($options['wpv_custom_inner_shortcodes'] ) ) {

        foreach( $options['wpv_custom_inner_shortcodes'] as $key) {
            if ( empty($key) ) {
                continue;
            }
            $fields['custom-shortcodes']['fields'][$key] = array(
                'label' => $key,
                'slug' => sprintf('\'[%s]\'', $key),
                'type' => 'text',
            );
        }
    }

    /**
     * remove empty sections
     */
    foreach( $fields as $key => $field ) {
        if ( empty($field['fields']) ) {
            unset($fields[$key]);
        }
    }

    /**
     * fields json
     */
    $fields = array(
        'labels' => array(
            'select_choose' => esc_html( __('-- Select origin --', 'wpv-views') ),
            'button_delete' => esc_html( __('Delete', 'wpv-views') ),
        ),
        'fields' => $fields,
    );

    foreach ( $fields['fields'] as $key => $data ) {
        if (empty($data) ) {
            unset($fields['fields'][$key]);
        }
    }

    $content .= '<script type="text/javascript">';
    $content .= sprintf('wpv_conditional_data = %s;',json_encode($fields));
    $content .= '</script>';
	$content .= '<span class="js-wpv-shortcode-gui-content"></span>';
    $content .= '<table id="js-wpv-conditionals" class="wpv-conditionals" data-field-name="wpv-conditional"><thead><tr>';
    $content .= sprintf('<th style="width:310px">%s</th>', __('Data origin', 'wpv-views'));
    $content .= sprintf('<th>%s</th>', __('Comparison', 'wpv-views'));
    $content .= sprintf('<th>%s</th>', __('Value', 'wpv-views'));
    $content .= sprintf('<th>%s</th>', __('Relationship', 'wpv-views'));
    $content .= '<th style="width:50px;text-align:right;">&nbsp</th></tr></thead>';
    $content .= sprintf('<tfoot><td colspan="5"><button class="button js-wpv-views-conditional-add-term" >%s</button></td></tr></tfoot>', __('Add another condition', 'wpv-views'));
    $content .= '<tbody class="js-wpv-views-conditional-body"></tbody>';
    $content .= '</table>';
    return $content;
}