晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/rainic/public_html/oldTZh/wp-content/plugins/persian-elementor/widget/ |
Upload File : |
<?php
/**
* Aparat Integration for Elementor Video Widget
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
// Check if feature is enabled in settings
$options = get_option('persian_elementor', []);
if (!($options['efa-aparat-video'] ?? true)) {
return; // Don't load if feature is disabled
}
class Persian_Elementor_Aparat_Integration {
private static $instance = null;
public static function get_instance() {
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
public function __construct() {
// Wait until Elementor is fully loaded
add_action('elementor/init', [$this, 'init']);
}
public function init() {
// Add Aparat as a video source and our custom controls
add_action('elementor/element/video/section_video/before_section_end', [$this, 'add_aparat_controls']);
// Hide irrelevant default controls when Aparat is selected
add_action('elementor/element/video/section_video/after_section_end', [$this, 'modify_video_controls']);
// Add Aparat as a video source
add_filter('elementor/frontend/widget/before_render', [$this, 'before_render_video'], 10, 2);
// Handle Aparat video rendering
add_filter('elementor/widget/render_content', [$this, 'render_aparat_video'], 10, 2);
// Add editor scripts for preview
add_action('elementor/editor/after_enqueue_scripts', [$this, 'enqueue_editor_scripts']);
}
/**
* Add Aparat specific controls to the video widget
*/
public function add_aparat_controls($element) {
// First add Aparat option to video_type dropdown
$video_type = $element->get_controls('video_type');
if ($video_type && is_array($video_type) && isset($video_type['options'])) {
$video_type['options'] = array_merge(
['aparat' => esc_html__('آپارات', 'persian-elementor')],
$video_type['options']
);
$element->update_control('video_type', ['options' => $video_type['options']]);
}
// Now add Aparat-specific controls
$element->add_control(
'aparat_url',
[
'label' => esc_html__('آدرس آپارات', 'persian-elementor'),
'type' => \Elementor\Controls_Manager::TEXT,
'dynamic' => [
'active' => true,
'categories' => [
\Elementor\Modules\DynamicTags\Module::POST_META_CATEGORY,
\Elementor\Modules\DynamicTags\Module::URL_CATEGORY,
],
],
'placeholder' => esc_html__('آدرس ویدئو آپارات را وارد کنید', 'persian-elementor'),
'default' => 'https://www.aparat.com/v/b491rbh',
'label_block' => true,
'condition' => [
'video_type' => 'aparat',
],
'frontend_available' => true,
]
);
$element->add_control(
'start_m',
[
'label' => esc_html__('زمان شروع (دقیقه)', 'persian-elementor'),
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 0,
'max' => 59,
'default' => 0,
'condition' => [
'video_type' => 'aparat',
],
'frontend_available' => true,
]
);
$element->add_control(
'start_s',
[
'label' => esc_html__('زمان شروع (ثانیه)', 'persian-elementor'),
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 0,
'max' => 59,
'default' => 0,
'condition' => [
'video_type' => 'aparat',
],
'frontend_available' => true,
]
);
$element->add_control(
'mute_aparat',
[
'label' => esc_html__('پخش بیصدا', 'persian-elementor'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => esc_html__('بله', 'persian-elementor'),
'label_off' => esc_html__('خیر', 'persian-elementor'),
'return_value' => 'yes',
'default' => 'no',
'condition' => [
'video_type' => 'aparat',
],
'frontend_available' => true,
]
);
$element->add_control(
'title_show_aparat',
[
'label' => esc_html__('نمایش عنوان', 'persian-elementor'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => esc_html__('بله', 'persian-elementor'),
'label_off' => esc_html__('خیر', 'persian-elementor'),
'return_value' => 'yes',
'default' => 'yes',
'condition' => [
'video_type' => 'aparat',
],
'frontend_available' => true,
]
);
$element->add_control(
'recom_self',
[
'label' => esc_html__('ویدیو های پیشنهادی', 'persian-elementor'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => esc_html__('بله', 'persian-elementor'),
'label_off' => esc_html__('خیر', 'persian-elementor'),
'return_value' => 'yes',
'default' => 'no',
'condition' => [
'video_type' => 'aparat',
],
'frontend_available' => true,
]
);
}
/**
* Modify default video controls to hide irrelevant ones for Aparat
*/
public function modify_video_controls($element) {
// Hide irrelevant controls for Aparat
$element->update_control(
'youtube_url',
[
'condition' => [
'video_type' => 'youtube',
],
]
);
$element->update_control(
'vimeo_url',
[
'condition' => [
'video_type' => 'vimeo',
],
]
);
$element->update_control(
'dailymotion_url',
[
'condition' => [
'video_type' => 'dailymotion',
],
]
);
$element->update_control(
'insert_url',
[
'condition' => [
'video_type' => 'hosted',
],
]
);
$element->update_control(
'hosted_url',
[
'condition' => [
'video_type' => ['hosted'],
'insert_url' => '',
],
]
);
$element->update_control(
'external_url',
[
'condition' => [
'video_type' => ['hosted'],
'insert_url' => 'yes',
],
]
);
$element->update_control(
'start',
[
'condition' => [
'video_type!' => ['aparat'],
],
]
);
$element->update_control(
'end',
[
'condition' => [
'video_type' => ['youtube', 'hosted'],
],
]
);
$element->update_control(
'video_options',
[
'condition' => [
'video_type!' => ['aparat'],
],
]
);
// Update the play_on_mobile condition to exclude aparat
$element->update_control(
'play_on_mobile',
[
'condition' => [
'autoplay' => 'yes',
'video_type!' => ['aparat'],
],
]
);
// Update the mute control to exclude aparat (we have our own mute_vid control)
$element->update_control(
'mute',
[
'condition' => [
'video_type!' => ['aparat'],
],
]
);
// Hide other video-provider specific controls when Aparat is selected
$controls_to_update = [
'loop', 'controls', 'showinfo', 'modestbranding', 'logo',
'yt_privacy', 'lazy_load', 'rel', 'vimeo_title',
'vimeo_portrait', 'vimeo_byline', 'color',
'download_button', 'preload', 'poster' // Removed 'image_overlay'
];
foreach ($controls_to_update as $control_name) {
$control = $element->get_controls($control_name);
if ($control) {
$condition = isset($control['condition']) ? $control['condition'] : [];
// Ensure 'video_type!' condition exists and includes 'aparat'
if (!isset($condition['video_type!'])) {
$condition['video_type!'] = [];
}
if (!is_array($condition['video_type!'])) {
$condition['video_type!'] = (array) $condition['video_type!'];
}
if (!in_array('aparat', $condition['video_type!'])) {
$condition['video_type!'][] = 'aparat';
}
// Removed special handling for image_overlay
// For other controls, just update the video_type condition
$element->update_control($control_name, ['condition' => $condition]);
}
}
}
/**
* Before rendering the video widget, check if we need to override settings
*/
public function before_render_video($widget) {
if ('video' !== $widget->get_name()) {
return;
}
$settings = $widget->get_settings_for_display();
if (!empty($settings['video_type']) && 'aparat' === $settings['video_type']) {
// This is our hook that we'll use to intercept the rendering
$widget->add_render_attribute('_wrapper', 'data-video-type', 'aparat');
}
}
/**
* Extract video hash from Aparat URL
*/
private function extract_aparat_hash($url) {
// Handle different URL formats
$patterns = [
// Standard format: https://www.aparat.com/v/HASH
'~aparat\.com/v/([a-zA-Z0-9]+)~i',
// Alternative format with showvideo: https://www.aparat.com/video/video/embed/videohash/HASH
'~videohash/([a-zA-Z0-9]+)~i',
// Fallback - try to get the last segment of the URL
'~/([a-zA-Z0-9]+)$~'
];
foreach ($patterns as $pattern) {
if (preg_match($pattern, $url, $matches)) {
return $matches[1];
}
}
return '';
}
/**
* Generate Aparat embed HTML
*
* @param string $video_hash The Aparat video hash
* @param array $params The parameters for the iframe
* @return string The HTML for the embed
*/
private function generate_aparat_embed_html($video_hash, $params) {
$iframe_src = add_query_arg(
$params,
'https://www.aparat.com/video/video/embed/videohash/' . esc_attr($video_hash) . '/vt/frame'
);
ob_start();
echo '<style>
.h_iframe-aparat_embed_frame {
position: relative;
overflow: hidden;
width: 100%;
}
.h_iframe-aparat_embed_frame .ratio {
display: block;
width: 100%;
height: auto;
}
.h_iframe-aparat_embed_frame iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
}
</style>';
echo '<div class="h_iframe-aparat_embed_frame">';
echo '<span style="display: block; padding-top: 57%"></span>';
printf(
'<iframe src="%s" allow="autoplay" allowFullScreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>',
esc_url($iframe_src)
);
echo '</div>';
return ob_get_clean();
}
/**
* Render Aparat video content
*/
public function render_aparat_video($widget_content, $widget) {
// Only process video widget
if ('video' !== $widget->get_name()) {
return $widget_content;
}
$settings = $widget->get_settings_for_display();
// Only handle Aparat videos
if (empty($settings['video_type']) || 'aparat' !== $settings['video_type']) {
return $widget_content;
}
// Process Aparat video
ob_start();
// Sanitize and validate inputs
$video_url = sanitize_text_field($settings['aparat_url']);
$video_hash = $this->extract_aparat_hash($video_url);
// Calculate start time (minutes + seconds)
$start_m = isset($settings['start_m']) ? absint($settings['start_m']) : 0;
$start_s = isset($settings['start_s']) ? absint($settings['start_s']) : 0;
$start_time = ($start_m * 60) + $start_s;
// Set default values for removed controls
$autoplay = !empty($settings['autoplay']) ? 'true' : 'false';
$mute_aparat = (!empty($settings['mute_aparat']) && $settings['mute_aparat'] === 'yes') ? 'true' : 'false';
$title_show_aparat = (!empty($settings['title_show_aparat']) && $settings['title_show_aparat'] === 'yes') ? 'true' : 'false';
$recom_self = (!empty($settings['recom_self']) && $settings['recom_self'] === 'yes') ? 'self' : null; // Check the new setting
// Check if we have a valid video hash
if (empty($video_hash)) {
echo '<p>' . esc_html__('آدرس ویدیو آپارات معتبر نیست.', 'persian-elementor') . '</p>';
return ob_get_clean();
}
// Build iframe URL with only relevant parameters
$params = [];
// Only add titleShow when explicitly enabled
if ($title_show_aparat === 'true') {
$params['titleShow'] = 'true';
}
// Only add muted when explicitly enabled
if ($mute_aparat === 'true') {
$params['muted'] = 'true';
}
// Always include autoplay setting
$params['autoplay'] = $autoplay;
// Add start time parameter if it's not zero
if ($start_time > 0) {
$params['t'] = $start_time;
}
// Add recom parameter if enabled
if ($recom_self === 'self') {
$params['recom'] = 'self';
}
echo $this->generate_aparat_embed_html($video_hash, $params);
return ob_get_clean();
}
/**
* Add script for handling Aparat in Elementor editor preview
*/
public function enqueue_editor_scripts() {
// Register script for editor preview
wp_enqueue_script(
'persian-elementor-aparat-editor',
plugins_url('/assets/js/aparat-editor.js', dirname(__FILE__)),
['elementor-editor'],
'1.0.0',
true
);
// Localize script with translation strings
wp_localize_script(
'persian-elementor-aparat-editor',
'persianElementorAparat',
[
'invalidUrl' => esc_html__('آدرس ویدیو آپارات معتبر نیست.', 'persian-elementor'),
]
);
}
}
// Initialize the class
Persian_Elementor_Aparat_Integration::get_instance();