commit c2c8ac74beaa639de911f7e3f370e3066f1422e8 Author: Josh Knapp Date: Fri Dec 27 14:10:25 2024 -0800 establish base code diff --git a/css/fw-store-embed.css b/css/fw-store-embed.css new file mode 100644 index 0000000..1843175 --- /dev/null +++ b/css/fw-store-embed.css @@ -0,0 +1,37 @@ +.fw-store-parent { + align-content: center; + vertical-align: top; + overflow-y: auto; + text-align:center; + margin:0 auto; + max-width: 1000px; +} + +.product-tile { + align-content: center; + vertical-align: top; + background: white; + display:inline-block; + width:200px; + margin:0 25px 25px; + +} + +.product-tile img { + max-height: 350px; +} + +.image__badges { + color: red; + justify-content: center; + position: absolute; + font-weight: bold; + margin: auto; +} +.badge { + color: red !important; + margin: auto; + padding: 60px; + font-size: 20px; + font-style: italic; +} diff --git a/fw-store-embed.php b/fw-store-embed.php new file mode 100644 index 0000000..7369ab9 --- /dev/null +++ b/fw-store-embed.php @@ -0,0 +1,18 @@ +' . "\n"; + echo '

' . get_admin_page_title() . '

' . "\n"; + echo '
' . "\n"; + + settings_fields( 'fourthwall_settings_group' ); + do_settings_sections( 'fourthwall_settings_name' ); + submit_button(); + + echo '
' . "\n"; + echo '' . "\n"; + + } + + function render_fourth_url_field() { + + // Retrieve data from the database. + $options = get_option( 'fourthwall_settings_name' ); + + // Set default value. + $value = isset( $options['fourth_url'] ) ? $options['fourth_url'] : ''; + + // Field output. + echo ''; + echo '

' . __( 'The fourth wall URL', 'fourthwall_text_domain' ) . '

'; + + } + +} + +new fourthwall_settings; diff --git a/libs/shortcode.php b/libs/shortcode.php new file mode 100644 index 0000000..cdcbc4f --- /dev/null +++ b/libs/shortcode.php @@ -0,0 +1,57 @@ +loadHTML(file_get_contents($url)); + $dom->documentURI = $url; + $divs = $dom->getElementsByTagName('div'); + foreach ($divs as $div) { + if ($div->hasAttribute('data-testid') && $div->getAttribute('data-testid') === 'product') { + $xpath = new DOMXPath($dom); + + $tileItem = $xpath->query('.//img[contains(@class, "tile__item--1") + and not(contains(@class, "badge")) + and not(contains(@class, "tile_options")) + and not(contains(@class, "tile__item--2"))]', $div); + $tileDesc = $xpath->query('.//*[contains(@class, "tile__description") + and not(contains(@class, "badge")) + and not(contains(@class, "tile_options"))]', $div); + $tileHeading = $xpath->query('.//*[contains(@class, "tile__heading") + and not(contains(@class, "badge")) + and not(contains(@class, "tile_options"))]', $div); + $tilePrices = $xpath->query('.//*[contains(@class, "tile__prices") + and not(contains(@class, "badge")) + and not(contains(@class, "tile_options"))]', $div); + $productHTML = ''; + if ($tileItem->length > 0) { + $productHTML .= $dom->saveHTML($tileItem->item(0)); + } + if ($tileDesc->length > 0) { + $productHTML .= $dom->saveHTML($tileDesc->item(0)); + } + if ($tileHeading->length > 0) { + $productHTML .= $dom->saveHTML($tileHeading->item(0)); + } + if ($tilePrices->length > 0) { + $productHTML .= $dom->saveHTML($tilePrices->item(0)); + } + + $html = $html . '
' . $productHTML . '
'; + } + } + $html = str_replace('a href="', 'a target="_blank" href="' . $url, $html); + return $html; +} + +function fwembed_shortcode( $atts ) { + $options = get_option( 'fourthwall_settings_name' ); + $value = isset( $options['fourth_url'] ) ? $options['fourth_url'] : 'https://latinosagainstspookyshit-shop.fourthwall.com'; + $store_html = fwembed_parse_html($value); + $store_render = '
' . PHP_EOL . $store_html . PHP_EOL . '
'; + return $store_render; +} +add_shortcode( 'fourthwall', 'fwembed_shortcode' );