HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux mail.btech-izolacje.pl 5.15.0-140-generic #150-Ubuntu SMP Sat Apr 12 06:00:09 UTC 2025 x86_64
User: pewna6876 (1017)
PHP: 8.2.28
Disabled: NONE
Upload Files
File: /home/pewnabryka.pl/public_html/wp-content/plugins/vehica-core/app/Managers/EmbedPreviewManager.php
<?php


namespace Vehica\Managers;


use Vehica\Core\Manager;
use Vehica\Model\Post\Field\EmbedField;

/**
 * Class EmbedPreviewManager
 * @package Vehica\Managers
 */
class EmbedPreviewManager extends Manager
{

    public function boot()
    {
        add_action('admin_post_nopriv_vehica_embed_preview', [$this, 'preview']);
        add_action('admin_post_vehica_embed_preview', [$this, 'preview']);

        add_filter('oembed_result', static function ($data, $url) {
            if (strpos($url, 'facebook') !== false && strpos($url, 'videos') !== false) {
                return '<iframe src="https://www.facebook.com/plugins/video.php?href=' . urlencode($url) . '" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowfullscreen="true" allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share" allowFullScreen="true"></iframe>';
            }

            return $data;
        }, 10, 2);
    }

    public function preview()
    {
        if (empty($_POST['url']) || empty($_POST['fieldId'])) {
            return;
        }

        $embed = wp_oembed_get($_POST['url']);
        $fieldId = (int)$_POST['fieldId'];
        $field = vehicaApp('embed_fields')->find(static function ($embedField) use ($fieldId) {
            /* @var EmbedField $embedField */
            return $embedField->getId() === $fieldId;
        });

        if (!$field instanceof EmbedField) {
            return;
        }

        if (empty($embed) && $field->allowRawHtml()) {
            echo stripslashes_deep($_POST['url']);
            return;
        }

        echo vehica_filter($embed);
    }

}