<?php namespace Sina_Extension\Manager;use \Elementor\Plugin;use \Elementor\Api;if(!defined('ABSPATH')){exit;}class Sina_Ext_Manager{private static $instance=null;public static function instance(){if(null==self::$instance){self::$instance=new self;}return self::$instance;}public function __construct(){if(!empty(get_option('sina_templates_option'))){add_action('elementor/init',[$this,'library_source'],15);if(defined('ELEMENTOR_VERSION')&&version_compare(ELEMENTOR_VERSION,'2.3.0','>')){add_action('elementor/ajax/register_actions',[$this,'register_ajax'],25);}if(defined('Elementor\Api::LIBRARY_OPTION_KEY')){add_filter('option_'.Api::LIBRARY_OPTION_KEY,[$this,'add_categories']);}}}public function add_categories($data){if(defined('SINA_EXT_PRO_WIDGETS')){$categories=['chart','contact form','countdown','fun fact','hover image','image accordion','image marker','image scroller','instant search','login form','niche blocks','register form','news ticker','posts','posts carousel','posts gallery','posts load on scroll','posts tab','tab','tilt box','others',];}else{$categories=['contact form','countdown','fun fact','login form','news ticker','posts','posts carousel','posts tab','others',];}if(defined('ELEMENTOR_VERSION')&&version_compare(ELEMENTOR_VERSION,'2.3.9','>')){$data['types_data']['block']['categories']=array_merge($categories,$data['types_data']['block']['categories']);}else{$data['categories']=array_merge($categories,$data['categories']);}return $data;}public function register_ajax($ajax){if(!isset($_REQUEST['actions'])){return;}$axax_actions=json_decode(stripslashes($_REQUEST['actions']),true);$template=false;foreach($axax_actions as $data=>$action_data){if(!isset($action_data['get_template_data'])){$template=$action_data;}}if(!isset($template['data'])||empty($template['data'])){return;}if(empty($template['data']['template_id'])){return;}if(false===strpos($template['data']['template_id'],'sina_ext_')){return;}$ajax->register_ajax_action('get_template_data',[$this,'get_template']);}public function get_template($args){$template_source=Plugin::instance()->templates_manager->get_source('sina_ext_templates');$template=$template_source->get_data($args);return $template;}public function library_source(){require_once(SINA_EXT_INC.'sina-ext-library.php');Plugin::instance()->templates_manager->register_source('Elementor\TemplateLibrary\Sina_Ext_Library');}}