芝麻web文件管理V1.00
编辑当前文件:/home/projzpbv/www/wp-content/plugins/calculated-fields-form/inc/cpcff_amp.inc.php
_main_obj = $main_obj; add_action( 'init', array( $this, 'amp_init' ) ); // for amp pages. } // End __construct. /** * Loads the form's preview in AMP pages. * * @return void. */ public function amp_init() { if ( ! empty( $_GET['cff-amp-form'] ) && get_option( 'CP_CALCULATEDFIELDSF_AMP', CP_CALCULATEDFIELDSF_AMP ) ) { error_reporting( E_ERROR|E_PARSE ); $atts = $this->_params_to_attrs(); $page_title = ( ! empty( $atts['page_title'] ) ) ? $atts['page_title'] : ''; print '' . '' . ( get_option( 'CP_CALCULATEDFIELDSF_EXCLUDE_CRAWLERS', false ) ? '
' : '' ) . '
' . '
' . '
' . esc_html( $page_title ) . '
'; // Patch for editor preview. if ( empty( $_GET['cff-editor-preview'] ) ) { print ''; } global $wp_styles, $wp_scripts; if ( ! empty( $wp_scripts ) ) { $wp_scripts->reset(); } $message = $this->_main_obj->public_form( $atts ); ob_start(); if ( ! empty( $wp_styles ) ) { $wp_styles->do_items(); } if ( ! empty( $wp_scripts ) ) { $wp_scripts->do_items(); } if ( class_exists( 'Error' ) ) { try { wp_footer(); } catch ( Error $err ) { error_log( $err->getMessage() ); } } $message .= ob_get_contents(); ob_end_clean(); print '' . '' . $message . // phpcs:ignore WordPress.Security.EscapeOutput '' . ''; remove_all_actions( 'shutdown' ); exit; } } // End amp_init. /** * Checks if the page is AMP or not * * Checks first for the existence of functions: "is_amp_endpoint" or "ampforwp_is_amp_endpoint", * and if they don't exists, checks the URL. * * @return bool. */ public function is_amp() { if ( ! get_option( 'CP_CALCULATEDFIELDSF_AMP', CP_CALCULATEDFIELDSF_AMP ) ) { return false; } if ( ! empty( $_REQUEST['isamp'] ) ) { return true; } if ( empty( $_GET['non-amp'] ) ) { if ( function_exists( 'ampforwp_is_amp_endpoint' ) ) { return ampforwp_is_amp_endpoint(); } elseif( function_exists( 'amp_is_request' ) ) { return amp_is_request(); } elseif ( function_exists( 'is_amp_endpoint' ) ) { return is_amp_endpoint(); } } return false; } // End is_amp. /** * Returns an iframe tag for loading the a webpage with the form only, specially useful for AMP pages. * * @return string, the iframe tag's structure for loading a page with the form. */ public function get_iframe( $atts ) { $url = CPCFF_AUXILIARY::site_url(); $url = preg_replace( '/^http\:/i', 'https:', $url ); $url .= ( strpos( $url, '?' ) === false ) ? '?' : '&'; $url .= 'cff-amp-form=' . ( ( ! empty( $atts['id'] ) ) ? $atts['id'] : '' ); $height = ''; $width = ''; foreach ( $atts as $attr_name => $attr_value ) { if ( 'amp_iframe_height' == $attr_name ) { $height = $attr_value; } elseif ( 'amp_iframe_width' == $attr_name ) { $width = $attr_value; } elseif ( 'id' != $attr_name ) { $url .= '&cff-form-attr-' . $attr_name . '=' . $attr_value; } } if ( empty( $height ) ) { $height = 320; } else { $url .= '&cff-form-height=' . $height; } if ( empty( $width ) ) { $width = 500; } $url .= '&non-amp=1'; add_action( 'amp_post_template_css', array( $this, 'amp_css' ) ); add_filter( 'amp_post_template_data', array( $this, 'amp_iframe' ) ); return '
' . esc_html( __( 'Click to expand', 'calculated-fields-form' ) ) . '
'; } /** * Includes the CSS rules for the amp version of form * * @param object $template form template. */ public function amp_css( $template ) { print '#cff-form-iframe{margin:0;}'; } // End amp_css. /** * Checks if the amp-iframe.js was included, and includes it if not. * * @param array $data associative array. * @return $data, associative array. */ public function amp_iframe( $data ) { if ( empty( $data['amp_component_scripts']['amp-iframe'] ) ) { $data['amp_component_scripts']['amp-iframe'] = 'https://cdn.ampproject.org/v0/amp-iframe-0.1.js'; } return $data; } // End amp_iframe. /** * Converts the URL parameters related with the form in the redirection process required for load the forms into the amp-frames * * The parameter cff-amp-form is converted in the id attribute, * and the parameteres with the name: cff-form-attr-
, are converted in the attributes
* * @return array $attrs. */ private function _params_to_attrs() { $attrs = array(); if ( ! empty( $_GET ) ) { foreach ( $_GET as $param => $value ) { if ( 'cff-amp-form' == $param ) { $attrs['id'] = @intval( $value ); } elseif ( preg_match( '/^cff\-form\-attr\-/i', $param ) ) { $param = preg_replace( '/^cff\-form\-attr\-/i', '', $param ); $param = sanitize_text_field( $param ); $attrs[ $param ] = sanitize_text_field( $value ); } } } return $attrs; } // End _params_to_attrs. /** * Reads the form height from the URL parameter cff-form-height, returns 500 by default. * * @return int. */ private function _get_styles() { return ( ! empty( $_GET['cff-form-height'] ) && is_numeric( $_GET['cff-form-height'] ) && ( $height = intval( $_GET['cff-form-height'] ) ) !== 0 ) ? 'overflow-x:hidden;overflow-y:auto;height:' . $height . 'px;padding:5px 32px 5px 5px;' : ''; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments } } }