balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class.pb_sc_check.php (2749B)


      1 <?php
      2 namespace CVEC\classes\vc;
      3 
      4 defined('ABSPATH') || die();
      5 
      6 class pb_sc_check
      7 {
      8     public static function Check_sc_exist_in_post($array_list, $post_id)
      9     {
     10         $content_post = get_post($post_id);
     11         $content = $content_post->post_content;
     12         $return_array = [];
     13         foreach ($array_list as $key => $array) {
     14             if (stripos($content, $key)) {
     15                 $return_array[] = $array;
     16             }
     17         }
     18         if ($return_array && !empty($return_array)) {
     19             return $return_array;
     20         } else {
     21             return false;
     22         }
     23     }
     24 
     25     public static function Check_ele_sc_exist_in_post($array_list, $post_id)
     26     {
     27         $elementor_array = '';
     28         $css_editor = '';
     29         //if (version_compare(ELEMENTOR_VERSION, '2.6.10', '>=')) {
     30         //$elementor_array = get_post_meta($post_id, '_elementor_elements_usage', true);
     31         //}
     32         //if (!is_array($elementor_array)) {
     33         $return_array = [];
     34         $elementor_array = [];
     35         $content_post = \Elementor\Plugin::$instance->documents->get($post_id);
     36         $content_post = $content_post ? $content_post->get_elements_data() : [];
     37 
     38         \Elementor\Plugin::$instance->db->iterate_data($content_post, function ($element) use (&$elementor_array, &$css_editor) {
     39             if (empty($element['widgetType'])) {
     40                 $type = $element['elType'];
     41             } else {
     42                 $type = $element['widgetType'];
     43             }
     44             if (!empty($element['settings'][CSS_EDITOR_NAME])) {
     45                 $css_editor .= $element['settings'][CSS_EDITOR_NAME];
     46             }
     47             if (!isset($elementor_array[$type])) {
     48                 $elementor_array[$type] = 0;
     49             }
     50             $elementor_array[$type]++;
     51             return $element;
     52         });
     53         // }
     54 
     55         if ($css_editor != '') {
     56             $filename = pb_build_css::$targetdircss . "css_editor_{$post_id}.css";
     57             if (file_exists($filename)) {
     58                 unlink($filename);
     59             }
     60             if (!is_dir(pb_build_css::$targetdircss)) {
     61                 @mkdir(pb_build_css::$targetdircss, 0777, true);
     62             }
     63             file_put_contents($filename, $css_editor);
     64         } else {
     65             $filename = pb_build_css::$targetdircss . "css_editor_{$post_id}.css";
     66             if (file_exists($filename)) {
     67                 unlink($filename);
     68             }
     69         }
     70         foreach ($array_list as $key => $array) {
     71             if (array_key_exists($key, $elementor_array)) {
     72                 $return_array[] = $array;
     73             }
     74         }
     75 
     76         if ($return_array && !empty($return_array)) {
     77             return $return_array;
     78         } else {
     79             return false;
     80         }
     81     }
     82 
     83 }