' ){ $value = substr( $value, 0, -3 ); } } } if( $value == '' ){ array_push( $to_replace, $default ); }else{ array_push( $to_replace, $value ); } } $content = str_ireplace( $cp_tags, $to_replace, $content ); return $content; } public static function replace_wp_params( $content, $enc_content = null ){ $params = self::wp_params_list(); $metadata = Shortcoder_Metadata::metadata(); $metadata[ 'enclosed_content' ] = $enc_content; $all_params = array(); $to_replace = array(); foreach( $params as $group => $group_info ){ $all_params = array_merge( $group_info[ 'params' ], $all_params ); } foreach( $all_params as $id => $name ){ if( array_key_exists( $id, $metadata ) ){ $placeholder = '$$' . $id . '$$'; $to_replace[ $placeholder ] = $metadata[ $id ]; } } $content = strtr( $content, $to_replace ); return $content; } public static function replace_custom_fields( $content ){ global $post; preg_match_all('/\$\$custom_field\:(.*?)\$\$/', $content, $matches ); if( empty( $matches[0] ) ){ return $content; } $cf_tags = $matches[1]; foreach( $cf_tags as $cf_tag ){ $cf_data = explode( ':', $cf_tag, 2 ); $cf_name = trim( $cf_data[0] ); $cf_default_val = count( $cf_data ) == 2 ? trim( $cf_data[1] ) : ''; if( empty( $cf_name ) ){ continue; } if( is_object( $post ) ){ $cf_actual_val = get_post_meta( $post->ID, $cf_name, true ); $value = $cf_actual_val == '' ? $cf_default_val : $cf_actual_val; }else{ $value = $cf_default_val; } $full_tag = '$$custom_field:' . $cf_tag . '$$'; $content = str_replace( $full_tag, $value, $content ); } return $content; } public static function process_content( $content, $settings ){ $content = do_shortcode( $content ); if( $settings[ '_sc_execute_blocks' ] == 'yes' ){ $content = do_blocks( $content ); } return $content; } public static function wp_params_list(){ return apply_filters( 'sc_mod_wp_params', array( 'wp_info' => array( 'name' => __( 'WordPress information', 'shortcoder' ), 'icon' => 'wordpress-alt', 'params' => array( 'url' => __( 'URL of the post/location', 'shortcoder' ), 'title' => __( 'Title of the post/location', 'shortcoder' ), 'short_url' => __( 'Short URL of the post/location', 'shortcoder' ), 'post_id' => __( 'Post ID', 'shortcoder' ), 'post_image' => __( 'Post featured image URL', 'shortcoder' ), 'post_excerpt' => __( 'Post excerpt', 'shortcoder' ), 'post_author' => __( 'Post author', 'shortcoder' ), 'post_date' => __( 'Post date', 'shortcoder' ), 'post_modified_date' => __( 'Post modified date', 'shortcoder' ), 'post_comments_count' => __( 'Post comments count', 'shortcoder' ), 'post_slug' => __( 'Post slug', 'shortcoder' ), 'site_name' => __( 'Site title', 'shortcoder' ), 'site_description' => __( 'Site description', 'shortcoder' ), 'site_url' => __( 'Site URL', 'shortcoder' ), 'site_wpurl' => __( 'WordPress URL', 'shortcoder' ), 'site_charset' => __( 'Site character set', 'shortcoder' ), 'wp_version' => __( 'WordPress version', 'shortcoder' ), 'stylesheet_url' => __( 'Active theme\'s stylesheet URL', 'shortcoder' ), 'stylesheet_directory' => __( 'Active theme\'s directory', 'shortcoder' ), 'atom_url' => __( 'Atom feed URL', 'shortcoder' ), 'rss_url' => __( 'RSS 2.0 feed URL', 'shortcoder' ) ) ), 'date_info' => array( 'name' => __( 'Date parameters', 'shortcoder' ), 'icon' => 'calendar-alt', 'params' => array( 'day' => __( 'Day', 'shortcoder' ), 'day_lz' => __( 'Day - leading zeros', 'shortcoder' ), 'day_ws' => __( 'Day - words - short form', 'shortcoder' ), 'day_wf' => __( 'Day - words - full form', 'shortcoder' ), 'month' => __( 'Month', 'shortcoder' ), 'month_lz' => __( 'Month - leading zeros', 'shortcoder' ), 'month_ws' => __( 'Month - words - short form', 'shortcoder' ), 'month_wf' => __( 'Month - words - full form', 'shortcoder' ), 'year' => __( 'Year', 'shortcoder' ), 'year_2d' => __( 'Year - 2 digit', 'shortcoder' ), ) ), 'sc_cnt' => array( 'name' => __( 'Shortcode enclosed content', 'shortcoder' ), 'icon' => 'text', 'params' => array( 'enclosed_content' => __( 'Shortcode enclosed content', 'shortcoder' ) ) ) )); } public static function set_defaults( $a, $b ){ $a = (array) $a; $b = (array) $b; $result = $b; foreach ( $a as $k => &$v ) { if ( is_array( $v ) && isset( $result[ $k ] ) ) { $result[ $k ] = self::set_defaults( $v, $result[ $k ] ); } else { $result[ $k ] = $v; } } return $result; } } Shortcoder::init(); ?>