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.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / tutor-droip / backend / Helper.php
tutor / tutor-droip / backend Last commit date
ElementGenerator 1 year ago Ajax.php 1 year ago Backend.php 1 year ago Editor.php 1 year ago Frontend.php 1 year ago Helper.php 1 year ago Iframe.php 1 year ago Pages.php 1 year ago
Helper.php
189 lines
1 <?php
2
3 /**
4 * Preview script for html markup generator
5 *
6 * @package tutor-droip-elements
7 */
8
9 namespace TutorLMSDroip;
10
11 use Droip\Ajax\ExportImport;
12
13 if (! defined('ABSPATH')) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Class Helper
19 * This class is used to define all helper functions.
20 */
21 class Helper
22 {
23
24 /**
25 * Function to activate droip elements plugin
26 */
27 public static function t_d_e_activate()
28 {
29 self::get_course_template_posts();
30 }
31
32 /**
33 * This function will verify nonce
34 * ACT like API calls auth middleware
35 *
36 * @param string $action ajax action name.
37 *
38 * @return void
39 */
40 public static function verify_nonce($action = -1)
41 {
42 $nonce = sanitize_text_field(isset($_SERVER['HTTP_X_WP_NONCE']) ? wp_unslash($_SERVER['HTTP_X_WP_NONCE']) : null);
43 if (! wp_verify_nonce($nonce, $action)) {
44 wp_send_json_error('Not authorized');
45 exit;
46 }
47 }
48
49 /**
50 * Get course template post
51 *
52 * @return mixed
53 */
54 public static function get_course_template_posts()
55 {
56 $all_templates = get_posts(
57 array(
58 'post_type' => 'droip_template',
59 'posts_per_page' => -1,
60 'post_status' => ['draft', 'publish'],
61 )
62 );
63 $data = [];
64 foreach ($all_templates as $key => $template) {
65 $conditions = get_post_meta($template->ID, 'droip_template_conditions', true);
66 if ($conditions) {
67 foreach ($conditions as $key2 => $condition) {
68 if ($condition['category'] === 'courses') {
69 $data[] = $template;
70 }
71 }
72 }
73 }
74
75 if (count($data) === 0) {
76 //create a course template
77 $post_id = wp_insert_post(
78 array(
79 'post_title' => 'Course Details',
80 'post_name' => 'Course Details',
81 'post_type' => 'droip_template'
82 )
83 );
84 $conditions = array(
85 array(
86 'category' => 'courses',
87 'taxonomy' => '*',
88 'visibility' => 'show'
89 )
90 );
91 update_post_meta($post_id, 'droip_template_conditions', $conditions);
92
93 if (class_exists('Droip\Ajax\ExportImport')) {
94 $template_path = TDE_ROOT_PATH . '/assets/course-details.zip';
95 ExportImport::process_droip_template_zip($template_path, false, $post_id);
96 }
97
98 $data[] = get_post($post_id);
99 }
100 return $data;
101 }
102
103 public static function upload_layout_pack($obj)
104 {
105 try {
106 foreach ($obj['pages'] as $key => $page) {
107 $zip_path = self::download_zip_from_remote($page['src'], $page['ID'] . '.zip');
108
109 $post_id = self::get_post_id_for_template_import($obj['ID'], $page);
110
111 if (isset($page['conditions'])) {
112 update_post_meta($post_id, 'droip_template_conditions', $page['conditions']);
113 }
114 if (class_exists('Droip\Ajax\ExportImport')) {
115 ExportImport::process_droip_template_zip($zip_path, false, $post_id);
116 unlink($zip_path);
117 }
118 }
119 } catch (\Throwable $th) {
120 return false;
121 }
122 return true;
123 }
124
125 private static function get_post_id_for_template_import($parent_id, $page_info)
126 {
127 global $wpdb;
128 $meta_key = 'droip_template_imported_' . $parent_id . '_' . $page_info['ID'];
129 $imported_flag = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}postmeta WHERE meta_key = '" . $meta_key . "'", OBJECT);
130 $post_id = null;
131 $post_status = null;
132 foreach ($imported_flag as $key => $p_meta) {
133 $post = get_post($p_meta->post_id);
134 if ($post && $post->post_type === $page_info['post_type']) {
135 $post_id = $p_meta->post_id;
136 $post_status = $post->post_status;
137 break;
138 }
139 }
140
141 if (! $post_id || 'trash' === $post_status) {
142 $post_id = wp_insert_post(
143 array(
144 'post_title' => $page_info['title'],
145 'post_name' => $page_info['title'],
146 'post_type' => $page_info['post_type'],
147 'post_status' => 'publish',
148 )
149 );
150 }
151
152 update_post_meta($post_id, $meta_key, true);
153 update_post_meta($post_id, '_wp_page_template', DROIP_FULL_CANVAS_TEMPLATE_PATH);
154 update_post_meta($post_id, 'droip_include_wp_header', 'true');
155 update_post_meta($post_id, 'droip_include_wp_footer', 'true');
156 if ($page_info['ID'] === 'home') {
157 update_option('page_on_front', $post_id);
158 update_option('show_on_front', 'page');
159 }
160 return $post_id;
161 }
162
163 /**
164 * [download_zip description]
165 *
166 * @param [type] $remote_ile [$remote_ile description]
167 * @param [type] $new_name [$new_name description]
168 *
169 * @return [type] [return description]
170 */
171 private static function download_zip_from_remote($remote_ile, $new_name)
172 {
173 try {
174 // Local path to save the downloaded file.
175 $local_file = wp_upload_dir()['basedir'] . '/' . $new_name;
176 // Download the file from the remote server.
177 $file_contents = file_get_contents($remote_ile);
178 // Save the file locally.
179 if ($file_contents !== false) {
180 file_put_contents($local_file, $file_contents);
181 return $local_file;
182 }
183 } catch (\Throwable $th) {
184 // throw $th;
185 }
186 return false;
187 }
188 }
189