product_event(); if ( Option::check( 'enable_pctag' ) && Option::check( 'pctag_id' ) ) { echo $this->pinterest( Option::get( 'pctag_id' ) ); } if ( Option::check( 'pctag_website' ) ) { echo "\n" . Option::get( 'pctag_website' ) . "\n"; } } protected function pinterest( $tag ) { return "\n \n\n"; } protected function search_event( $search_query, $tag ) { return "\n\n"; } protected function pinterest_event( string $type, string $tag, array $data = [] ) { $event_data = ""; $noscript_data = ""; if ( count( $data ) > 0 ) { // Event data is printed as a JSON object in which <, >, &, ' and " are written // as \u escapes, so every key and value stays text inside the script element. $json = wp_json_encode( $data, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_FORCE_OBJECT ); // Data that cannot be encoded is left out of the script call and of the fallback image alike. if ( is_string( $json ) ) { $event_data = ", " . $json; // Every key and value is percent-encoded before it joins the fallback address. foreach ( $data as $key => $value ) { $noscript_data .= "&ed[" . rawurlencode( (string) $key ) . "]=" . rawurlencode( (string) $value ); } } } // The fallback address is escaped as an attribute value. esc_url() is not used here // because it rewrites the square brackets of the ed[key] parameter names. $noscript_url = esc_attr( "https://ct.pinterest.com/v3/?tid={$tag}&event={$type}{$noscript_data}&noscript=1" ); return "\n\n\n"; } protected function product_event( string $type, string $tag ) { } protected function view_category( string $tag ) { return "\n \n"; } // Stored event rows are checked again each time they are printed, whatever wrote them. // A row is kept only when its type is made of letters, digits and underscores and its // value is a single piece of text or a number. Both are returned as text. function flattenArray( $multiArray ) : array { $flattenedArray = []; if ( !is_array( $multiArray ) ) { return $flattenedArray; } foreach ( $multiArray as $array ) { if ( !is_array( $array ) || !isset( $array['type'], $array['value'] ) ) { continue; } if ( !is_scalar( $array['type'] ) || !is_scalar( $array['value'] ) ) { continue; } $type = (string) $array['type']; $value = (string) $array['value']; if ( empty( $type ) || empty( $value ) ) { continue; } if ( !preg_match( '/^[a-zA-Z0-9_]+$/D', $type ) ) { continue; } $flattenedArray[$type] = $value; } return $flattenedArray; } } $TrackingControllers = new TrackingController();