Security
Headlines
HeadlinesLatestCVEs

Headline

CVE-2023-3052: azexo_html.php in page-builder-by-azexo/trunk – WordPress Plugin Repository

The Page Builder by AZEXO plugin for WordPress is vulnerable to Cross-Site Request Forgery in versions up to, and including, 1.27.133. This is due to missing or incorrect nonce validation on the 'azh_add_post’, 'azh_duplicate_post’, ‘azh_update_post’ and ‘azh_remove_post’ functions. This makes it possible for unauthenticated attackers to create, modify, and delete a post via a forged request granted they can trick a site administrator into performing an action such as clicking on a link.

CVE
#sql#google#linux#js#wordpress#php#c++#auth#ssl

1<?php2/*3 Plugin Name: Page Builder by AZEXO4 Description: Front-end page builder5 Author: azexo6 Author URI: http://azexo.com7 Version: 1.27.1338 Text Domain: azh9 */1011define('AZH_VERSION’, ‘1.27’);12define('AZH_PLUGIN_VERSION’, ‘1.27.133’);13define('AZH_URL’, plugins_url('’, __FILE__));14define('AZH_DIR’, trailingslashit(dirname(__FILE__)));15define('AZH_PLUGIN_NAME’, trailingslashit(basename(dirname(__FILE__))) . ‘azexo_html.php’);1617//ini_get(‘mbstring.func_overload’) !==false && ini_get(‘mbstring.func_overload’) > 01819function azh_linux_path($path) {20 return str_replace('\\’, '/’, $path);21}2223global $azh_shortcodes;24$azh_shortcodes = array();2526include_once(AZH_DIR . ‘icons.php’ );27include_once(AZH_DIR . ‘auto_templates.php’ );28include_once(AZH_DIR . ‘widgets.php’ );29include_once(AZH_DIR . ‘integrations/gutenberg.php’ );30include_once(AZH_DIR . ‘integrations/elementor.php’ );31include_once(AZH_DIR . ‘integrations/wpbakery.php’ );32include_once(AZH_DIR . ‘integrations/divi.php’ );33//include_once(AZH_DIR . ‘integrations/siteorigin.php’ );34//include_once(AZH_DIR . ‘integrations/beaver.php’ );35include_once(AZH_DIR . ‘integrations/misc.php’ );36if (file_exists(AZH_DIR . ‘integrations/woocommerce.php’)) {37 include_once(AZH_DIR . ‘integrations/woocommerce.php’ );38}39include_once(AZH_DIR . ‘google-fonts.php’ );40if (is_admin()) {41 include_once(AZH_DIR . ‘admin.php’ );42 if (file_exists(AZH_DIR . ‘envato/updater.php’)) {43 include_once(AZH_DIR . ‘envato/updater.php’ );44 }45 include_once(AZH_DIR . ‘settings.php’ );46 include_once(AZH_DIR . ‘customizer.php’ );47 if (file_exists(AZH_DIR . ‘html_template_export.php’)) {48 include_once(AZH_DIR . ‘html_template_export.php’ );49 }50 include_once(AZH_DIR . ‘options-translation.php’);51}52include_once(AZH_DIR . ‘templates.php’ );5354add_action('plugins_loaded’, ‘azh_plugins_loaded’);5556function azh_plugins_loaded() {57 load_plugin_textdomain('azh’, FALSE, basename(dirname(__FILE__)) . ‘/languages/’);58 add_action('add_meta_boxes’, 'azh_add_meta_boxes’, 10, 2);59 $settings = get_option(‘azh-settings’);60 $icon_types = array('fontawesome’, 'openiconic’, 'typicons’, 'entypo’, 'linecons’, ‘themify’);61 global $azh_icons, $azh_icons_index;62 $azh_icons = array();63 $azh_icons_index = array();64 foreach ($icon_types as $icon_type) {65 $azh_icons[$icon_type] = array();66 $arr1 = apply_filters('azh_icon-type-' . $icon_type, array());67 foreach ($arr1 as $arr2) {68 if (is_array($arr2)) {69 if (count($arr2) == 1) {70 reset($arr2);71 $azh_icons[$icon_type][key($arr2)] = current($arr2);72 $azh_icons_index[key($arr2)] = $icon_type;73 } else {74 foreach ($arr2 as $arr3) {75 if (count($arr3) == 1) {76 reset($arr3);77 $azh_icons[$icon_type][key($arr3)] = current($arr3);78 $azh_icons_index[key($arr3)] = $icon_type;79 }80 }81 }82 }83 }84 }85 if (isset($settings[‘custom-icons-classes’])) {86 $custom_icons = explode(“\n", trim($settings[‘custom-icons-classes’]));87 if (count($custom_icons) <= 1) {88 $custom_icons = explode(" “, trim($settings[‘custom-icons-classes’]));89 }90 $azh_icons[‘custom’] = array_combine($custom_icons, $custom_icons);91 $azh_icons_index = array_merge($azh_icons_index, array_combine($custom_icons, array_fill(0, count($custom_icons), ‘custom’)));92 }939495 $azh_widgets = get_option(‘azh_widgets’);96 if (is_array($azh_widgets) || empty($azh_widgets)) {97 update_post_cache($azh_widgets);98 } else {99 $azh_widgets = get_posts(array(100 ‘post_type’ => 'azh_widget’,101 ‘posts_per_page’ => '-1’,102 ));103 update_option('azh_widgets’, $azh_widgets);104 update_post_cache($azh_widgets);105 }106}107108register_activation_hook(__FILE__, ‘azh_activate’);109110function azh_activate() {111 update_option('azh-library’, array());112 update_option('azh-elements-library-shortcode’, array());113 update_option('azh-sections-library-shortcode’, array());114 update_option('azh-all-settings’, array());115 update_option('azh-get-content-scripts’, array());116 update_option('azh-content-settings’, array());117}118119add_filter('azh_directory’, ‘azh_directory’);120121function azh_directory($dir) {122 $dir[untrailingslashit(dirname(__FILE__)) . ‘/azh’] = plugins_url('’, __FILE__) . '/azh’;123 return $dir;124}125126add_action('edit_form_after_title’, 'azh_print_switch_mode_button’, 10, 1);127128function azh_print_switch_mode_button($post) {129 $settings = get_option(‘azh-settings’);130 if (is_object($post) && isset($settings[‘post-types’]) && in_array($post->post_type, array_keys($settings[‘post-types’]))) {131 wp_nonce_field(basename(__FILE__), ‘_azh_edit_mode_nonce’);132 ?>133 <div id="azh-switch-mode">134 <input id="azh-switch-mode-input” type="hidden” name="_azh_edit_mode" value="<?php echo get_post_meta($post->ID, 'azh’, true); ?>" />135 <button id="azh-switch-mode-button" class="azh-button button button-primary button-hero">136 <span class="azh-switch-mode-on">137 <?php _e('← Back to WordPress Editor’, ‘azh’); ?>138 </span>139 <span class="azh-switch-mode-off">140 <span class="dashicons dashicons-schedule"></span>141 <?php _e('Edit with AZEXO’, ‘azh’); ?>142 </span>143 </button>144 </div>145 <div id="azh-editor">146 <a id="azh-go-to-edit-page-link" href="<?php echo add_query_arg('azh’, 'customize’, get_edit_post_link($post)); ?>">147 <div id="azh-editor-button" class="azh-button button button-primary button-hero">148 <span class="dashicons dashicons-schedule"></span>149 <?php _e('Edit with AZEXO’, ‘azh’); ?>150 </div>151 </a>152 </div>153 <?php154 }155}156157add_action('save_post’, ‘azh_save_post’, 10, 3);158159function azh_save_post($post_id, $post, $update) {160 if (!isset($_POST[‘_azh_edit_mode_nonce’]) || !wp_verify_nonce($_POST[‘_azh_edit_mode_nonce’], basename(__FILE__))) {161 return;162 }163// if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) {164// return;165// }166 if (!empty($_POST[‘_azh_edit_mode’])) {167 update_post_meta($post_id, ‘azh’, ‘azh’);168 } else {169 delete_post_meta($post_id, ‘azh’);170 }171172 if ($post->post_type == ‘azh_widget’) {173 $azh_widgets = get_option(‘azh_widgets’);174 if (!is_array($azh_widgets)) {175 $azh_widgets = array();176 }177 $azh_widgets[$post_id] = $post;178 update_option(‘azh_widgets’, $azh_widgets);179 update_post_cache($azh_widgets);180 }181 $settings = get_option(‘azh-settings’);182 if (isset($settings[‘post-types’]) && in_array($post->post_type, array_keys($settings[‘post-types’]))) {183 $settings = get_option(‘azh-forms-settings’, array());184 $current_user = wp_get_current_user();185 $forms = azh_get_forms_from_page($post);186 foreach ($forms as $form_title => $form) {187 $fields = ‘’;188 foreach ($form as $name => $field) {189 $fields .= $field[‘label’] . ‘: {’ . $name . "}\n";190 }191 if (!isset($settings[$form_title . '-to’])) {192 $settings[$form_title . '-to’] = $current_user->user_email;193 }194 if (!isset($settings[$form_title . '-subject-template’])) {195 $settings[$form_title . '-subject-template’] = esc_html__(‘{form_title} submission’, ‘azh’);196 }197 if (!isset($settings[$form_title . '-body-template’])) {198 $settings[$form_title . '-body-template’] = $fields;199 }200 }201 update_option('azh-forms-settings’, $settings);202 }203}204205function azh_get_frontend_object() {206 $azh = array(207 ‘device_prefixes’ => azh_device_prefixes(),208 ‘site_url’ => site_url(),209 ‘ajaxurl’ => admin_url(‘admin-ajax.php’),210 ‘post_id’ => get_the_ID(),211 ‘i18n’ => array()212 );213 return apply_filters('azh_get_frontend_object’, $azh);214}215216function azh_get_shapes() {217 azh_filesystem();218 global $wp_filesystem;219 $shapes = array();220 $iterator = new DirectoryIterator(AZH_DIR . ‘shapes’);221 foreach ($iterator as $fileInfo) {222 if ($fileInfo->isFile() && $fileInfo->getExtension() == ‘svg’) {223 $shapes[$fileInfo->getFilename()] = $wp_filesystem->get_contents($fileInfo->getPathname());224 }225 }226 return $shapes;227}228229function azh_get_object() {230 static $azh;231 if (empty($azh)) {232 $empty_html = esc_html__('Please switch to HTML and input content’, ‘azh’);233 global $azh_shortcodes, $azh_google_fonts, $azh_google_fonts_locale_subsets;234 $settings = get_option(‘azh-settings’);235 $patterns = isset($settings[‘patterns’]) ? $settings[‘patterns’] : ‘’;236 $patterns = preg_replace("/\r\n/", "\n", $patterns);237 $properties = explode("\n\n", $patterns);238 $patterns = array();239 foreach ($properties as $property) {240 $property = explode("\n", $property);241 $patterns[$property[0]] = array();242 if ($property[0] == ‘dropdown_patterns’) {243 for ($i = 1; $i < count($property); $i = $i + 2) {244 $options = array();245 $options_value_label = explode("|", $property[$i + 1]);246 foreach ($options_value_label as $value_label) {247 $vl = explode(“:", $value_label);248 $options[$vl[0]] = $vl[1];249 }250 $patterns[$property[0]][] = array(251 ‘pattern’ => $property[$i],252 ‘options’ => $options,253 );254 }255 } else {256 for ($i = 1; $i < count($property); $i++) {257 $patterns[$property[0]][] = $property[$i];258 }259 }260 }261 $edit_post_frontend_link = add_query_arg(array(‘azh’ => 'customize’, ‘azhp’ => get_the_ID()), get_permalink());262 if (isset($_GET[‘azhf’]) && is_numeric($_GET[‘azhf’])) {263 $edit_post_frontend_link = add_query_arg(array(‘azh’ => 'customize’, ‘azhp’ => get_the_ID()), get_permalink((int) $_GET[‘azhf’]));264 }265 $post_settings = get_post_meta(get_the_ID(), '_azh_settings’, true);266 //$settings = array_replace_recursive($settings, $post_settings);267 $all_settings = azh_get_all_settings();268 $library = azh_get_library();269 $html = azh_get_shapes();270 $azh = array(271 ‘options’ => apply_filters('azh_options’, $patterns),272 ‘dirs_options’ => $all_settings,273 ‘files_settings’ => azh_get_files_settings($all_settings),274 ‘files_scripts’ => azh_get_files_scripts($library),275 ‘icons’ => apply_filters('azh_icons’, array()),276 ‘shortcodes’ => $azh_shortcodes,277 ‘shortcode_instances’ => isset($post_settings[‘shortcodes’]) ? $post_settings[‘shortcodes’] : array(),278 ‘html’ => $html,279 ‘site_url’ => site_url(),280 ‘plugin_url’ => AZH_URL,281 ‘ajaxurl’ => admin_url(‘admin-ajax.php’),282 ‘helpers’ => array(283 ‘.azh-wrapper.azh-inline’ => esc_html__('<strong>Right mouse click without text selection</strong> - switch between text and link<br><strong>Right mouse click with text selection</strong> - split text-field to 3 text-fields<br><strong>Drag-and-drop text-field</strong> - merge 2 adjacent text-fields’, ‘azh’),284 ),285 ‘user_logged_in’ => is_user_logged_in(),286 ‘post_id’ => get_the_ID(),287 ‘edit_post_link’ => is_admin() ? ‘’ : get_edit_post_link(),288 ‘edit_post_frontend_link’ => $edit_post_frontend_link,289 ‘default_category’ => apply_filters('azh_default_category’, get_template()),290 ‘google_fonts’ => $azh_google_fonts,291 ‘google_fonts_locale_subsets’ => $azh_google_fonts_locale_subsets,292 ‘locale’ => get_locale(),293 ‘fill_utility_on_init’ => array(),294 ‘cloneable_refresh’ => array(295 '.az-cloneable-refresh’,296 ),297 ‘cloneable_refresh_children’ => array(298 '.g-recaptcha’,299 '.az-gmap’,300 '.az-cloneable-refresh’,301 ),302 ‘device_prefixes’ => azh_device_prefixes(),303 ‘device_prefix’ => 'lg’,304 ‘responsive’ => true,305 ‘editor_toolbar’ => array('boldButton’, 'italicButton’, 'linkButton’, 'leftButton’, 'centerButton’, 'rightButton’, 'sizeSelector’, 'colorInput’, 'colorBgInput’, ‘removeFormatButton’),306 ‘table_editor’ => true,307 ‘recognition’ => false,308 ‘categories_order’ => array('layout’, 'content’, 'forms’, 'free-positioning’, 'WordPress’, 'WooCommerce’, 'AZEXO’, ‘elements’),309 ‘i18n’ => array(310 ‘select_element’ => esc_html__('Select Elements’, ‘azh’),311 ‘paste_from_clipboard’ => esc_html__('Paste from clipboard’, ‘azh’),312 ‘ok’ => esc_html__('OK’, ‘azh’),313 ‘cancel’ => esc_html__('Cancel’, ‘azh’),314 ‘edit_link’ => esc_html__('Edit link’, ‘azh’),315 ‘edit_image’ => esc_html__('Edit image’, ‘azh’),316 ‘edit_icon’ => esc_html__('Edit icon’, ‘azh’),317 ‘label’ => esc_html__('Label’, ‘azh’),318 ‘value’ => esc_html__('Value’, ‘azh’),319 ‘clone’ => esc_html__('Clone’, ‘azh’),320 ‘remove’ => esc_html__('Remove’, ‘azh’),321 ‘clone_pack’ => esc_html__('Clone pack’, ‘azh’),322 ‘remove_pack’ => esc_html__('Remove pack’, ‘azh’),323 ‘move’ => esc_html__('Move’, ‘azh’),324 ‘default’ => esc_html__('Default’, ‘azh’),325 ‘section’ => esc_html__('Section’, ‘azh’),326 ‘element’ => esc_html__('Element’, ‘azh’),327 ‘elements’ => esc_html__('Elements’, ‘azh’),328 ‘general’ => esc_html__('General’, ‘azh’),329 ‘content’ => esc_html__('Content’, ‘azh’),330 ‘layout’ => esc_html__('Layout’, ‘azh’),331 ‘forms’ => esc_html__('Forms’, ‘azh’),332 ‘free-positioning’ => esc_html__('Free positioning’, ‘azh’),333 ‘add_element’ => esc_html__('Add element’, ‘azh’),334 ‘move_element’ => esc_html__('Relative shift of element (click to reset shift)', ‘azh’),335 ‘add_element_after’ => esc_html__('Add element after’, ‘azh’),336 ‘add_element_before’ => esc_html__('Add element before’, ‘azh’),337 ‘remove_element’ => esc_html__('Remove element’, ‘azh’),338 ‘edit_tags’ => esc_html__('Edit tags’, ‘azh’),339 ‘saved’ => esc_html__('Saved’, ‘azh’),340 ‘select_image’ => esc_html__('Select image’, ‘azh’),341 ‘click_to_edit_shortcode’ => esc_html__('Click to edit shortcode’, ‘azh’),342 ‘shortcode_edit’ => esc_html__('Shortcode edit’, ‘azh’),343 ‘options’ => esc_html__('Options’, ‘azh’),344 ‘select_options_edit’ => esc_html__('Select options edit’, ‘azh’),345 ‘value_must_be_unique_in_this_scope’ => esc_html__('Value must be unique in this scope’, ‘azh’),346 ‘insert_column_before’ => esc_html__('Insert column before’, ‘azh’),347 ‘insert_column_after’ => esc_html__('Insert column after’, ‘azh’),348 ‘insert_row_before’ => esc_html__('Insert row before’, ‘azh’),349 ‘insert_row_after’ => esc_html__('Insert row after’, ‘azh’),350 ‘delete_row’ => esc_html__('Delete row’, ‘azh’),351 ‘delete_column’ => esc_html__('Delete column’, ‘azh’),352 ‘elements_hierarchy’ => esc_html__('Elements hierarchy’, ‘azh’),353 //backend builder354 ‘edit_frontend_builder’ => esc_html__('Edit with AZEXO’, ‘azh’),355 ‘empty_html’ => $empty_html,356 ‘enter_text_here’ => esc_html__('enter text here’, ‘azh’),357 ‘upload_text’ => esc_html__('Upload’, ‘azh’),358 ‘edit_text’ => esc_html__('Edit’, ‘azh’),359 ‘clear’ => esc_html__('Clear’, ‘azh’),360 ‘collapse’ => esc_html__('Collapse’, ‘azh’),361 ‘expand’ => esc_html__('Expand’, ‘azh’),362 ‘clone’ => esc_html__('Clone’, ‘azh’),363 ‘copy’ => esc_html__('Copy’, ‘azh’),364 ‘copied’ => esc_html__('Copied’, ‘azh’),365 ‘paste’ => esc_html__('Paste’, ‘azh’),366 ‘move’ => esc_html__('Move’, ‘azh’),367 ‘done’ => esc_html__('Done’, ‘azh’),368 ‘add’ => esc_html__('Add’, ‘azh’),369 ‘remove’ => esc_html__('Remove’, ‘azh’),370 ‘set’ => esc_html__('Set’, ‘azh’),371 ‘title’ => esc_html__('Title’, ‘azh’),372 ‘url’ => esc_html__('URL’, ‘azh’),373 ‘selected’ => esc_html__('Selected’, ‘azh’),374 ‘required’ => esc_html__('Required’, ‘azh’),375 ‘checked’ => esc_html__('Checked’, ‘azh’),376 ‘device’ => esc_html__('Device’, ‘azh’),377 ‘large’ => esc_html__('Large’, ‘azh’),378 ‘medium’ => esc_html__('Medium’, ‘azh’),379 ‘small’ => esc_html__('Small’, ‘azh’),380 ‘preview’ => esc_html__('Preview’, ‘azh’),381 ‘customize’ => esc_html__(‘Customize’, ‘azh’),382 //’elements’ => esc_html__('elements’, ‘azh’),383 ‘sections’ => esc_html__('sections’, ‘azh’),384 ‘extra_small’ => esc_html__('Extra small’, ‘azh’),385 ‘column_width’ => esc_html__('Column width’, ‘azh’),386 ‘column_offset’ => esc_html__('Column offset’, ‘azh’),387 ‘column_responsive’ => esc_html__('Column responsive settings’, ‘azh’),388 ‘select_url’ => esc_html__('Select URL’, ‘azh’),389 ‘switch_to_html’ => esc_html__('Switch to html’, ‘azh’),390 ‘switch_to_customizer’ => esc_html__('Switch to customizer’, ‘azh’),391 ‘control_description’ => esc_html__('Control description’, ‘azh’),392 ‘description’ => esc_html__('Description’, ‘azh’),393 ‘filter_by_tag’ => esc_html__('Filter by tag’, ‘azh’),394 ‘paste_sections_list_here’ => esc_html__('Paste sections list here’, ‘azh’),395 ‘content_wrapper_does_not_exists’ => esc_html__('Sorry, the content area was not found in your page. You must call the_content function in the current template, in order for AZEXO builder to work on this page.’, ‘azh’),396 ‘element_settings’ => esc_html__('Element settings’, ‘azh’),397 ‘column_settings’ => esc_html__('Column settings’, ‘azh’),398 ‘section_settings’ => esc_html__('Section settings’, ‘azh’),399 ‘revision_does_not_have_builder_content’ => esc_html__('Revision does not have builder content’, ‘azh’),400 ‘revision_has_been_restored’ => esc_html__('Revision has been restored’, ‘azh’),401 ‘shortcode’ => esc_html__('Shortcode’, ‘azh’),402 ‘edit_item_tags’ => esc_html__('Edit item tags’, ‘azh’),403 ‘tags’ => esc_html__('Tags’, ‘azh’),404 ‘change_the_tags_of_this_item’ => esc_html__('Change the tags of this item (separated by comma)', ‘azh’),405 ‘edit_section_html’ => esc_html__('Edit section HTML’, ‘azh’),406 ‘html_is_not_valid’ => esc_html__('HTML is not valid.’, ‘azh’),407 ‘last_column_can_not_be_deleted’ => esc_html__('Last column can not be deleted’, ‘azh’),408 ‘source_code’ => esc_html__('Source code’, ‘azh’),409 ),410 );411 $azh = apply_filters('azh_get_object’, $azh);412 }413 return $azh;414}415416function azh_editor_scripts() {417 wp_enqueue_script('simplemodal’, plugins_url('js/jquery.simplemodal.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);418 wp_enqueue_style('azh_admin’, plugins_url('css/admin.css’, __FILE__), false, AZH_PLUGIN_VERSION);419 wp_enqueue_style('select2’, plugins_url('css/select2.css’, __FILE__), false, AZH_PLUGIN_VERSION);420 wp_enqueue_script('select2’, plugins_url('js/select2.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);421 wp_enqueue_script('azh_admin’, plugins_url('js/admin.js’, __FILE__), array(‘azexo_html’), AZH_PLUGIN_VERSION, true);422423 wp_enqueue_script(‘jquery-ui-sortable’);424 wp_enqueue_style('azexo_html’, plugins_url('css/azexo_html.css’, __FILE__), array(), AZH_PLUGIN_VERSION);425 wp_enqueue_script('azexo_html’, plugins_url('js/azexo_html.js’, __FILE__), array('underscore’, 'azh_htmlparser’, 'jquery-ui-sortable’, ‘jquery-ui-autocomplete’), AZH_PLUGIN_VERSION, true);426 wp_enqueue_style('jquery-ui’, plugins_url('css/jquery-ui.css’, __FILE__), false, AZH_PLUGIN_VERSION, false);427 wp_enqueue_script('azh_htmlparser’, plugins_url('js/htmlparser.js’, __FILE__), AZH_PLUGIN_VERSION, true);428 wp_enqueue_script('ace’, plugins_url('js/ace/ace.js’, __FILE__), AZH_PLUGIN_VERSION, true);429430 wp_localize_script('azexo_html’, 'azh’, azh_get_object());431}432433function azh_add_meta_boxes($post_type, $post) {434 $settings = get_option(‘azh-settings’);435 if (!isset($_GET[‘azh’])) {436 $dirs = apply_filters('azh_directory’, array_combine(array(get_template_directory() . ‘/azh’), array(get_template_directory_uri() . ‘/azh’)));437 if (is_array($dirs)) {438 foreach ($dirs as $dir => $uri) {439 if (is_dir($dir) && isset($settings[‘post-types’]) && in_array($post_type, apply_filters('azh_meta_box_post_types’, array_keys($settings[‘post-types’])))) {440 add_meta_box('azh’, __('AZEXO Builder’, ‘azh’), 'azh_meta_box’, $post_type, 'side’, ‘default’);441 break;442 }443 }444 }445 }446 if (in_array($post_type, apply_filters('azh_meta_box_post_types’, array_keys($settings[‘post-types’])))) {447 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {448 wp_enqueue_script('azh_admin_frontend’, plugins_url('js/admin-frontend.js’, __FILE__), array('jquery’, 'underscore’, 'azh_htmlparser’, 'jquery-ui-mouse’, 'jquery-ui-sortable’, ‘jquery-ui-autocomplete’), AZH_PLUGIN_VERSION, true);449 $azh = azh_get_object();450 wp_localize_script('azh_admin_frontend’, 'azh’, $azh);451 wp_enqueue_style('azh_admin’, plugins_url('css/admin.css’, __FILE__), false, AZH_PLUGIN_VERSION);452 wp_enqueue_style('jquery-ui’, plugins_url('css/jquery-ui.css’, __FILE__), false, AZH_PLUGIN_VERSION);453 azh_builder_scripts();454 } else {455 azh_editor_scripts();456 }457 do_action('azh_load’, $post_type, $post);458 }459}460461add_filter('page_row_actions’, 'azh_page_row_actions’, 10, 2);462463function azh_page_row_actions($actions, $post) {464 if (get_post_meta($post->ID, 'azh’, true)) {465 $settings = get_option(‘azh-settings’);466 if (isset($settings[‘post-types’]) && in_array($post->post_type, array_keys($settings[‘post-types’]))) {467 $actions[‘azh’] = ‘<a href="’ . add_query_arg('azh’, 'customize’, get_edit_post_link($post)) . '” title="’ . esc_attr__('Edit with AZEXO’, ‘azh’) . ‘">’ . esc_html__('Edit with AZEXO’, ‘azh’) . '</a>’;468 }469 }470 return $actions;471}472473add_filter('display_post_states’, 'azh_display_post_states’, 10, 2);474475function azh_display_post_states($post_states, $post) {476 if (get_post_meta($post->ID, 'azh’, true)) {477 $settings = get_option(‘azh-settings’);478 if (isset($settings[‘post-types’]) && in_array($post->post_type, array_keys($settings[‘post-types’]))) {479 $post_states[‘azh’] = __('AZEXO’, ‘azh’);480 }481 }482 return $post_states;483}484485function azh_get_library() {486 static $library = array();487 if (!empty($library)) {488 return $library;489 }490 $library = get_option('azh-library’, array());491 $user = wp_get_current_user();492 if (in_array('administrator’, (array) $user->roles) && WP_DEBUG || empty($library)) {493 $general_elements = array();494 $elements = array();495 $elements_dir = array();496 $elements_uri = array();497 $elements_categories = array();498 $general_sections = array();499 $sections = array();500 $sections_dir = array();501 $sections_uri = array();502 $sections_categories = array();503 $dirs = apply_filters('azh_directory’, array_combine(array(get_template_directory() . ‘/azh’), array(get_template_directory_uri() . ‘/azh’)));504 if (is_array($dirs)) {505 foreach ($dirs as $dir => $uri) {506 if (is_dir($dir)) {507 $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST);508 foreach ($iterator as $fileInfo) {509 if ($fileInfo->isFile() && $fileInfo->getExtension() == ‘html’) {510 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’ && strpos($fileInfo->getPathname(), ‘pre-made’) !== false) {511 continue;512 }513 $sections[azh_linux_path($fileInfo->getPathname())] = $fileInfo->getFilename();514 $sections_dir[azh_linux_path($fileInfo->getPathname())] = azh_linux_path($dir);515 $sections_uri[azh_linux_path($fileInfo->getPathname())] = $uri;516 $sections_categories[trim(str_replace(azh_linux_path($dir), '’, azh_linux_path($fileInfo->getPath())), ‘/’)] = true;517 if (in_array(strtolower(basename(dirname($fileInfo->getPathname()))), array(‘empty rows’))) {518 $general_sections[azh_linux_path($fileInfo->getPathname())] = $fileInfo->getFilename();519 }520 }521 if ($fileInfo->isFile() && $fileInfo->getExtension() == ‘htm’) {522 $elements[azh_linux_path($fileInfo->getPathname())] = $fileInfo->getFilename();523 $elements_dir[azh_linux_path($fileInfo->getPathname())] = azh_linux_path($dir);524 $elements_uri[azh_linux_path($fileInfo->getPathname())] = $uri;525 $elements_categories[trim(str_replace(azh_linux_path($dir), '’, azh_linux_path($fileInfo->getPath())), ‘/’)] = true;526 if (in_array(strtolower(basename(dirname($fileInfo->getPathname()))), array('empty rows’, ‘general’))) {527 $general_elements[azh_linux_path($fileInfo->getPathname())] = $fileInfo->getFilename();528 }529 }530 }531 }532 }533 }534 ksort($elements);535 ksort($elements_categories);536 ksort($sections);537 ksort($sections_categories);538 $library = apply_filters('azh_get_library’, array(539 ‘general_elements’ => $general_elements, //used for adding “general” class540 ‘elements’ => $elements, //used for adding element name541 ‘elements_dir’ => $elements_dir, //used for AZH folder relativity542 ‘elements_uri’ => $elements_uri, //used for make URL relative to AZH folder543 ‘elements_categories’ => $elements_categories, //used for generation category filter - based on substring of element path544 ‘general_sections’ => $general_sections,545 ‘sections’ => $sections,546 ‘sections_dir’ => $sections_dir,547 ‘sections_uri’ => $sections_uri,548 ‘sections_categories’ => $sections_categories,549 ));550 update_option('azh-library’, $library);551 }552 return $library;553}554555function azh_get_files_settings($all_settings) {556 $files_settings = array();557 foreach ($all_settings as $dir => $settings) {558 if (isset($settings[‘files_settings’])) {559 foreach ($settings[‘files_settings’] as $file => $file_settings) {560 if (!isset($files_settings[$file])) {561 $files_settings[$file] = array();562 }563 $files_settings[$file] = array_replace_recursive($files_settings[$file], $file_settings);564 }565 }566 }567 return $files_settings;568}569570function azh_get_files_scripts($library) {571 static $files_scripts = array();572 if (!empty($files_scripts)) {573 return $files_scripts;574 }575 $files_scripts = apply_filters('azh_get_files_scripts’, $files_scripts, $library);576 return $files_scripts;577}578579function azh_get_files_order($all_settings) {580 $files_order = array();581 foreach ($all_settings as $dir => $settings) {582 if (isset($settings[‘files_settings’])) {583 foreach ($settings[‘files_settings’] as $file => $file_settings) {584 if (isset($file_settings[‘order’])) {585 $files_order[$dir . ‘/’ . $file] = $file_settings[‘order’];586 }587 }588 }589 }590 return $files_order;591}592593function azh_meta_box($post = NULL, $metabox = NULL, $post_type = ‘page’) {594 if (!is_null($post)) {595 $post_type = get_post_type($post);596 }597 $library = azh_get_library();598 $all_settings = azh_get_all_settings();599 $files_order = azh_get_files_order($all_settings);600 extract($library);601 ?>602 <?php //if ($post_type != ‘azh_widget’): ?>603 <div class="azh-actions" style="display: none;">604 <a href="#" class="azh-copy-sections-list"><?php esc_html_e('Copy sections’, ‘azh’) ?></a>605 <a href="#" class="azh-insert-sections-list"><?php esc_html_e('Insert sections’, ‘azh’) ?></a>606 </div>607 <div class="azh-structure" style="max-height: 600px;"></div>608 <div class="azh-section-operations">609 <a href="#" class="azh-add-section" data-open="<?php esc_html_e('Add section’, ‘azh’) ?>" data-close="<?php esc_html_e('Close library’, ‘azh’) ?>"><?php esc_html_e('Add section’, ‘azh’) ?></a> 610 <a href="#" class="azh-add-section" data-category="empty rows" data-open="<?php esc_html_e('Add empty section’, ‘azh’) ?>" data-close="<?php esc_html_e('Close library’, ‘azh’) ?>"><?php esc_html_e('Add empty section’, ‘azh’) ?></a> 611 </div>612 <?php //endif; ?>613 <div class="azh-library" style="display: none;">614 <?php //if ($post_type != ‘azh_widget’): ?>615 <div class="azh-library-filters">616 <select class="azh-categories">617 <option value=""><?php esc_html_e('Filter by category’, ‘azh’) ?></option>618 <?php619 foreach ($sections_categories as $category => $flag) {620 ?>621 <option value="<?php print esc_attr($category) ?>"><?php print esc_html($category) ?></option>622 <?php623 }624 ?>625 </select>626 </div>627 <div class="azh-sections">628 <?php629 foreach ($sections as $path => $name) {630 $preview = '’;631 if (file_exists(str_replace('.html’, '.jpg’, $path))) {632 $preview = str_replace('.html’, '.jpg’, $path);633 }634 if (file_exists(str_replace('.html’, '.png’, $path))) {635 $preview = str_replace('.html’, '.png’, $path);636 }637 $dir = $sections_dir[$path];638 $url = str_replace($dir, $sections_uri[$path], $path);639 if (file_exists($preview)) {640 $preview = str_replace($dir, $sections_uri[$path], $preview);641 ?><div class="azh-section azh-fuzzy <?php print isset($general_sections[$path]) ? ‘general’ : '’; ?>" data-url="<?php print esc_attr($url); ?>" data-order="<?php print isset($files_order[$path]) ? $files_order[$path] : 999999 ?>" data-path="<?php print esc_attr(ltrim(str_replace($dir, '’, $path), ‘/’)) ?>" data-dir="<?php print esc_attr($dir) ?>" data-dir-uri="<?php print esc_attr($sections_uri[$path]) ?>" style="background-image: url(‘<?php print esc_attr($preview); ?>’);"><div class="azh-name"><?php print esc_html($name) ?></div><img src="<?php print esc_attr($preview); ?>"></div><?php642 } else {643 ?><div class="azh-section no-image <?php print isset($general_sections[$path]) ? ‘general’ : '’; ?>" data-url="<?php print esc_attr($url); ?>" data-order="<?php print isset($files_order[$path]) ? $files_order[$path] : 999999 ?>" data-path="<?php print esc_attr(ltrim(str_replace($dir, '’, $path), ‘/’)) ?>" data-dir="<?php print esc_attr($dir) ?>" data-dir-uri="<?php print esc_attr($sections_uri[$path]) ?>"><div class="azh-name"><?php print esc_html($name) ?></div><img src="<?php print esc_attr($preview); ?>"></div><?php644 }645 }646 ?> 647 </div>648 <?php //endif; ?>649 <div class="azh-elements" style="display: none;"> 650 <div class="azh-elements-filters">651 <select class="azh-categories">652 <option value="" selected=""><?php esc_html_e('Filter by category’, ‘azh’) ?></option>653 <?php654 foreach ($elements_categories as $category => $flag) {655 ?>656 <option value="<?php print esc_attr($category) ?>"><?php print esc_html($category) ?></option>657 <?php658 }659 ?>660 </select>661 </div>662 <?php663 foreach ($elements as $path => $name) {664 $preview = '’;665 if (file_exists(str_replace('.htm’, '.jpg’, $path))) {666 $preview = str_replace('.htm’, '.jpg’, $path);667 }668 if (file_exists(str_replace('.htm’, '.png’, $path))) {669 $preview = str_replace('.htm’, '.png’, $path);670 }671 if (file_exists(str_replace('.htm’, '.svg’, $path))) {672 $preview = str_replace('.htm’, '.svg’, $path);673 }674 $dir = $elements_dir[$path];675 $url = str_replace($dir, $elements_uri[$path], $path);676 if (file_exists($preview)) {677 $preview = str_replace($dir, $elements_uri[$path], $preview);678 ?><div class="azh-element <?php print isset($general_elements[$path]) ? ‘general’ : '’; ?>" data-url="<?php print esc_attr($url); ?>" data-order="<?php print isset($files_order[$path]) ? $files_order[$path] : 999999 ?>" data-path="<?php print esc_attr(ltrim(str_replace($dir, '’, $path), ‘/’)) ?>" data-dir="<?php print esc_attr($dir) ?>" data-dir-uri="<?php print esc_attr($elements_uri[$path]) ?>" style="background-image: url(‘<?php print esc_attr($preview); ?>’);"><div class="azh-name"><?php print esc_html($name) ?></div></div><?php679 } else {680 ?><div class="azh-element no-image <?php print isset($general_elements[$path]) ? ‘general’ : '’; ?>" data-url="<?php print esc_attr($url); ?>" data-order="<?php print isset($files_order[$path]) ? $files_order[$path] : 999999 ?>" data-path="<?php print esc_attr(ltrim(str_replace($dir, '’, $path), ‘/’)) ?>" data-dir="<?php print esc_attr($dir) ?>" data-dir-uri="<?php print esc_attr($elements_uri[$path]) ?>"><div class="azh-name"><?php print esc_html($name) ?></div></div><?php681 }682 }683 ?> 684 </div>685 </div>686 <?php687}688689add_filter('admin_body_class’, ‘azh_admin_body_class’);690691function azh_admin_body_class($classes) {692 global $pagenow;693 $settings = get_option(‘azh-settings’);694 if (in_array($pagenow, array('post.php’, ‘post-new.php’)) && isset($settings[‘post-types’]) && in_array(get_post_type(), array_keys($settings[‘post-types’]))) {695 $post = get_post();696697 $mode_class = get_post_meta($post->ID, 'azh’, true) ? ‘azh-editor-active’ : '’;698699 $classes .= ' ' . $mode_class;700 }701 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {702 $classes .= ' azh-customize’;703 }704705 return $classes;706}707708add_filter('body_class’, ‘azh_body_class’);709710function azh_body_class($classes) {711 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {712 $classes[] = 'azh-customize’;713 }714 return $classes;715}716717function azh_parse_revision($revision) {718 static $authors;719 $current_time = current_time(‘timestamp’);720721 $date = date_i18n(_x('M j @ H:i’, 'revision date format’, ‘azh’), strtotime($revision->post_modified));722723 $human_time = human_time_diff(strtotime($revision->post_modified), $current_time);724725 if (false !== strpos($revision->post_name, ‘autosave’)) {726 $type = 'autosave’;727 } else {728 $type = 'revision’;729 }730731 if (!isset($authors[$revision->post_author])) {732 $authors[$revision->post_author] = array(733 ‘avatar’ => get_avatar($revision->post_author, 22),734 ‘display_name’ => get_the_author_meta('display_name’, $revision->post_author),735 );736 }737 return array(738 ‘id’ => $revision->ID,739 ‘author’ => $authors[$revision->post_author][‘display_name’],740 ‘date’ => sprintf(__('%1$s ago (%2$s)', ‘azh’), $human_time, $date),741 ‘type’ => $type,742 ‘gravatar’ => $authors[$revision->post_author][‘avatar’],743 );744}745746function azh_get_revisions($post_id = 0, $query_args = array()) {747 $post = get_post($post_id);748749 if (!$post || empty($post->ID)) {750 return array();751 }752753 $revisions = array();754755 $default_query_args = array(756 ‘posts_per_page’ => 100,757 ‘meta_key’ => '_azh_content’,758 );759760 $query_args = array_merge($default_query_args, $query_args);761762 $posts = wp_get_post_revisions($post->ID, $query_args);763764 foreach ($posts as $revision) {765 $revisions[] = azh_parse_revision($revision);766 }767768 return $revisions;769}770771add_action('wp_footer’, ‘azh_footer’);772773function azh_footer() {774 $post = get_post();775 if (isset($post->ID) && current_user_can('edit_post’, $post->ID)) {776 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {777 $azh = azh_get_object();778 $revisions = azh_get_revisions();779 ?>780 <div id="azexo-html-library">781 <div class="azh-library-actions">782 <div class="azh-builder" title="<?php esc_html_e('Builder’, ‘azh’); ?>"></div>783 <div class="azh-revisions" title="<?php esc_html_e('Revisions history’, ‘azh’); ?>"></div>784 <div class="azh-divider"></div>785 <div class="azh-save" title="<?php esc_html_e('Save page’, ‘azh’); ?>"></div>786 <a href="<?php print get_permalink(); ?>" target="_blank" class="azh-live" title="<?php esc_html_e('View page’, ‘azh’); ?>"></a>787 <a href="<?php print get_edit_post_link($post); ?>" class="azh-edit-page" title="<?php esc_html_e('Edit page’, ‘azh’); ?>"></a>788 </div>789 <div class="azh-panel azh-builder azh-active">790 <?php791 azh_meta_box();792 ?>793 </div>794 <div class="azh-panel azh-revisions">795 <div class="azh-panel-title">796 <?php esc_html_e('Revisions history’, ‘azh’); ?>797 </div>798 <div class="azh-restore-revision" style="display: none"><?php esc_html_e('Restore this revision’, ‘azh’); ?></div> 799 <div class="azh-panel-content">800 <?php foreach ($revisions as $revision): ?>801 <div class="azh-revision" data-id="<?php print $revision[‘id’]; ?>" data-type="<?php print $revision[‘type’]; ?>">802 <div class="azh-gravatar">803 <?php print $revision[‘gravatar’]; ?>804 </div>805 <div class="azh-details">806 <div class="azh-date">807 <?php print $revision[‘date’]; ?>808 </div>809 <div class="azh-meta">810 <?php print $revision[‘author’]; ?>811 </div>812 </div>813 </div>814 <?php endforeach; ?>815 </div>816 </div> 817 </div>818 <?php819 }820 }821 if (apply_filters('azexo-credits’, true)) {822 print '<div class="azexo-credits">Works with <a href="https://azexo.com" target="_blank">AZEXO</a> page builder</div>’;823 }824}825826add_action('admin_enqueue_scripts’, ‘azh_admin_scripts’);827828function azh_admin_scripts() {829 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {830 azh_icon_font_enqueue(‘fontawesome’);831 azh_icon_font_enqueue(‘openiconic’);832 azh_icon_font_enqueue(‘typicons’);833 azh_icon_font_enqueue(‘entypo’);834 azh_icon_font_enqueue(‘linecons’);835 azh_icon_font_enqueue(‘themify’);836 azh_icon_font_enqueue(‘custom’);837 }838}839840add_filter('azh_icons’, ‘azh_icons’);841842function azh_icons($icons) {843 global $azh_icons;844 return array_merge($azh_icons, $icons);845}846847function azh_get_icon_font_url($font) {848 switch ($font) {849 case 'fontawesome’:850 return array(‘font-awesome’ => plugins_url('css/font-awesome/css/font-awesome.min.css’, __FILE__));851 break;852 case 'openiconic’:853 return array(‘openiconic’ => plugins_url('css/az-open-iconic/az_openiconic.min.css’, __FILE__));854 break;855 case 'typicons’:856 return array(‘typicons’ => plugins_url('css/typicons/src/font/typicons.min.css’, __FILE__));857 break;858 case 'entypo’:859 return array(‘entypo’ => plugins_url('css/az-entypo/az_entypo.min.css’, __FILE__));860 break;861 case 'linecons’:862 return array(‘linecons-icons’ => plugins_url('css/az-linecons/az_linecons_icons.min.css’, __FILE__));863 break;864 case 'themify’:865 return array(‘themify-icons’ => plugins_url('css/themify/css/themify-icons.css’, __FILE__));866 break;867 case 'custom’:868 $urls = array();869 $settings = get_option(‘azh-settings’);870 if (!empty($settings[‘custom-icons-css’])) {871 $dirs = apply_filters('azh_directory’, array_combine(array(get_template_directory() . ‘/azh’), array(get_template_directory_uri() . ‘/azh’)));872 if (is_array($dirs)) {873 foreach ($dirs as $dir => $uri) {874 if (is_dir($dir)) {875 $custom_icons_css = explode(“\n", $settings[‘custom-icons-css’]);876 if (is_array($custom_icons_css)) {877 foreach ($custom_icons_css as $file) {878 if (file_exists($dir . ‘/’ . $file)) {879 $urls[$uri . ‘/’ . $file] = $uri . ‘/’ . $file;880 }881 }882 }883 }884 }885 }886 }887 return $urls;888 break;889 default:890 return apply_filters('azh_get_icon_font_url’, false, $font);891 }892 return false;893}894895function azh_icon_font_enqueue($font) {896 $urls = (array) azh_get_icon_font_url($font);897 if (!empty($urls)) {898 foreach ($urls as $handle => $url) {899 wp_enqueue_style($handle, $url);900 }901 }902}903904function azh_content_begin($content) {905 global $azh_widget_nested, $post;906 if (!isset($azh_widget_nested)) {907 $azh_widget_nested = 0;908 }909 if (is_object($post)) {910 if ($post->post_type == ‘azh_widget’) {911 $content = azh_get_post_content($post);912 $azh_widget_nested++;913 if ($azh_widget_nested == 1) {914 remove_filter('the_content’, ‘wptexturize’);915 remove_filter('the_content’, 'convert_smilies’, 20);916 remove_filter('the_content’, ‘wpautop’);917 remove_filter('the_content’, 'gutenberg_wpautop’, 6);918 remove_filter('the_content’, ‘shortcode_unautop’);919 remove_filter('the_content’, ‘prepend_attachment’);920 remove_filter('the_content’, ‘wp_make_content_images_responsive’);921 }922 } else {923 $settings = get_option(‘azh-settings’);924 if (isset($settings[‘post-types’]) && in_array($post->post_type, array_keys($settings[‘post-types’])) && get_post_meta($post->ID, 'azh’, true)) {925 $content = azh_get_post_content($post);926 remove_filter('the_content’, ‘wpautop’);927 remove_filter('the_content’, 'gutenberg_wpautop’, 6);928 }929 }930 }931 return $content;932}933934function azh_content_end($content) {935 global $azh_widget_nested, $post;936937 if (is_object($post)) {938 if ($post->post_type == ‘azh_widget’) {939 $post_id = azh_post_id_from_url();940 if (!$post_id) {941 $current_post = azh_get_earliest_current_post(array('vc_widget’, ‘azh_widget’), false);942 if ($current_post) {943 $post_id = $current_post->ID;944 }945 }946 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’ && $post_id == $post->ID) {947 $content = ‘<div class="azh-content-wrapper">’ . $content . '</div>’;948 }949 $azh_widget_nested–;950 if ($azh_widget_nested == 0) {951 add_filter('the_content’, ‘wptexturize’);952 add_filter('the_content’, 'convert_smilies’, 20);953 add_filter('the_content’, ‘wpautop’);954 add_filter('the_content’, ‘shortcode_unautop’);955 add_filter('the_content’, ‘prepend_attachment’);956 add_filter('the_content’, ‘wp_make_content_images_responsive’);957 }958 } else {959 $settings = get_option(‘azh-settings’);960 if (isset($settings[‘post-types’]) && in_array($post->post_type, array_keys($settings[‘post-types’])) && get_post_meta($post->ID, 'azh’, true)) {961 $post_id = azh_post_id_from_url();962 if (!$post_id) {963 $current_post = azh_get_earliest_current_post(array('vc_widget’, ‘azh_widget’), false);964 if ($current_post) {965 $post_id = $current_post->ID;966 }967 }968 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’ && $post_id == $post->ID) {969 if (empty($content)) {970 $content = '<div data-section="content"><div data-cloneable><div data-element=” “></div></div></div>’;971 }972 $content = ‘<div class="azh-content-wrapper">’ . $content . ‘</div>’;973 }974 if (!empty($content) && false === strpos($content, ' data-section=’)) {975 $content = ‘<div data-section="content">’ . $content . '</div>’;976 }977 add_filter('the_content’, ‘wpautop’);978 }979 }980 }981 return $content;982}983984function azh_enqueue_icons($content) {985 global $azh_icons, $azh_icons_index;986 foreach ($azh_icons as $icon_type => $icons) {987 $pattern = ‘/’ . implode('|’, array_keys($icons)) . '/’;988 if (preg_match($pattern, $content, $matches)) {989 if (isset($azh_icons_index[$matches[0]])) {990 azh_icon_font_enqueue($azh_icons_index[$matches[0]]);991 }992 }993 }994}995996function azh_get_icons_fonts_urls($content) {997 $fonts_urls = array();998 global $azh_icons, $azh_icons_index;999 foreach ($azh_icons as $icon_type => $icons) {1000 $pattern = ‘/’ . implode('|’, array_keys($icons)) . '/’;1001 if (preg_match($pattern, $content, $matches)) {1002 $urls = (array) azh_get_icon_font_url($azh_icons_index[$matches[0]]);1003 if (!empty($urls)) {1004 $fonts_urls = array_merge($fonts_urls, $urls);1005 }1006 }1007 }1008 return $fonts_urls;1009}10101011function azh_generate_ids($content) {1012 preg_match_all('{{id-(\d+)}}’, $content, $matches);1013 if ($matches) {1014 $numbers = array_unique($matches[1]);1015 sort($numbers, SORT_NUMERIC);1016 foreach ($numbers as $number) {1017 $id = ‘id’ . substr(md5(rand()), 0, 7);1018 $content = str_replace('{{id-' . $number . '}}’, $id, $content);1019 }1020 }1021 return $content;1022}10231024function azh_uri_replace($content) {1025 $dirs = apply_filters('azh_directory’, array_combine(array(get_template_directory() . ‘/azh’), array(get_template_directory_uri() . ‘/azh’)));1026 return preg_replace_callback('#{{azh-uri}}([\/\w\d\-\_\.]+)#i’, function($m) use ($dirs) {1027 foreach ($dirs as $path => $url) {1028 if (file_exists($path . $m[1])) {1029 return $url . $m[1];1030 }1031 }1032 return '’;1033 }, $content);1034}10351036function azh_replaces($content, $azh_uri = false) {1037 $replaces = array(1038 ‘azh-uri’ => $azh_uri ? $azh_uri : apply_filters('azh_uri’, get_template_directory_uri() . ‘/azh’),1039 );10401041 $post = azh_get_closest_current_post('azh_widget’, false);1042 if ($post) {1043 $replaces[‘post_title’] = $post->post_title;1044 $replaces[‘post_excerpt’] = $post->post_excerpt;1045 $replaces[‘post_content’] = $post->post_content;1046 $replaces[‘post_thumbnail’] = get_the_post_thumbnail_url($post, ‘full’);1047 $replaces[‘post_permalink’] = get_permalink($post);1048 } else {1049 $replaces[‘post_title’] = get_bloginfo(‘name’);1050 $replaces[‘post_excerpt’] = get_bloginfo(‘description’);1051 $replaces[‘post_content’] = '’;1052 $replaces[‘post_thumbnail’] = '’;1053 $replaces[‘post_permalink’] = '’;1054 }10551056 $replaces = apply_filters('azh_replaces’, $replaces);1057 $content = preg_replace_callback('#{{([^}]+)}}#i’, function($m) use ($replaces) {1058 if (isset($replaces[$m[1]])) { // If it exists in our array 1059 return $replaces[$m[1]]; // Then replace it from our array1060 } else {1061 return $m[0]; // Otherwise return the whole match (basically we won’t change it)1062 }1063 }, $content);10641065 return $content;1066}10671068function azh_remove_comments($content) {1069 $content = preg_replace_callback('#\[\[([^\]]+)\]\]#i’, function($m) {1070 return '’;1071 }, $content);1072 return $content;1073}10741075function azh_post_id_from_url() {1076 $post_id = isset($_GET[‘azhp’]) ? $_GET[‘azhp’] : false;10771078 if (!$post_id) {1079 $post_id = isset($_GET[‘p’]) ? $_GET[‘p’] : false;1080 }1081 if (!$post_id) {1082 $post_id = isset($_GET[‘page_id’]) ? $_GET[‘page_id’] : false;1083 }1084 if (!$post_id) {1085 $post_id = isset($_GET[‘post’]) ? $_GET[‘post’] : false;1086 }1087 return $post_id;1088}10891090function azh_refresh_attachements_urls($old_home_url, $new_home_url) {1091 $settings = get_option(‘azh-settings’);1092 if (isset($settings[‘post-types’]) && is_array($settings[‘post-types’])) {1093 $pages = get_posts(array(1094 ‘post_type’ => array_keys($settings[‘post-types’]),1095 ‘post_status’ => 'publish’,1096 ‘ignore_sticky_posts’ => 1,1097 ‘no_found_rows’ => 1,1098 ‘posts_per_page’ => -1,1099 ‘numberposts’ => -1,1100 ‘meta_query’ => array(1101 array(1102 ‘key’ => '_azh_content’,1103 ‘compare’ => 'EXISTS’,1104 ),1105 array(1106 ‘key’ => 'azh’,1107 ‘value’ => 'azh’,1108 )1109 )1110 ));1111 foreach ($pages as $page) {1112 $content = azh_get_post_content($page);1113 preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#’, $content, $match);1114 if ($match) {1115 foreach ($match[0] as $url) {1116 if (strpos($url, $old_home_url) !== false) {1117 $new_url = str_replace($old_home_url, $new_home_url, $url);1118 $post_id = attachment_url_to_postid($new_url);1119 if ($post_id) {1120 $content = str_replace($url, $new_url, $content);1121 }1122 }1123 }1124 azh_set_post_content($content, $page->ID);1125 }1126 }1127 }1128}11291130add_action('init’, ‘azh_init’);11311132function azh_init() {1133 if (is_admin()) {1134 $settings = get_option(‘azh-settings’);11351136 if (!isset($settings[‘home_url’]) || $settings[‘home_url’] !== home_url(‘/’) || !isset($settings[‘version’]) || $settings[‘version’] !== AZH_PLUGIN_VERSION) {1137 if (isset($settings[‘home_url’]) && !empty($settings[‘home_url’]) && $settings[‘home_url’] !== home_url(‘/’)) {1138 azh_refresh_attachements_urls($settings[‘home_url’], home_url(‘/’));1139 }1140 $settings[‘home_url’] = home_url(‘/’);1141 $settings[‘version’] = AZH_PLUGIN_VERSION;1142 update_option('azh-settings’, $settings);1143 update_option('azh-library’, array());1144 update_option('azh-all-settings’, array());1145 update_option('azh-get-content-scripts’, array());1146 update_option('azh-content-settings’, array());1147 }11481149 if (isset($settings[‘post-types’]) && is_array($settings[‘post-types’])) {1150 foreach ($settings[‘post-types’] as $post_type => $flag) {1151 add_post_type_support($post_type, ‘revisions’);1152 }11531154 if (!isset($settings[‘post-types’][‘azh_widget’])) {1155 if (isset($settings[‘post-types’])) {1156 $settings[‘post-types’][‘azh_widget’] = 1;1157 } else {1158 $settings[‘post-types’] = array(1159 ‘page’ => 1,1160 ‘azh_widget’ => 1,1161 );1162 }1163 update_option('azh-settings’, $settings);1164 }1165 }1166 }11671168 $current_user = wp_get_current_user();11691170 azh_add_element(array(1171 “name” => “Form",1172 “base” => “azh_form",1173 “show_in_dialog” => false,1174 ‘params’ => array(1175 array(1176 ‘type’ => 'textfield’,1177 ‘group’ => esc_html__('Notification’, ‘azh’),1178 ‘heading’ => esc_html__('Notification to email’, ‘azh’),1179 ‘param_name’ => 'to_email’,1180 ‘value’ => $current_user->user_email,1181 ),1182 array(1183 ‘type’ => 'textfield’,1184 ‘group’ => esc_html__('Notification’, ‘azh’),1185 ‘heading’ => esc_html__('Email subject template’, ‘azh’),1186 ‘param_name’ => 'subject_template’,1187 ‘value’ => '’,1188 ‘description’ => __('Available form fields: {form-fields}’, ‘azh’),1189 ),1190 array(1191 ‘type’ => 'textarea_raw_html’,1192 ‘group’ => esc_html__('Notification’, ‘azh’),1193 ‘heading’ => esc_html__('Email body template’, ‘azh’),1194 ‘param_name’ => 'content’,1195 ‘value’ => '’,1196 ‘description’ => __('Available form fields: {form-fields} ', ‘azh’),1197 ),1198 array(1199 ‘type’ => 'url’,1200 ‘group’ => esc_html__('Confirmation’, ‘azh’),1201 ‘heading’ => esc_html__('Confirmation redirect’, ‘azh’),1202 ‘param_name’ => 'success_redirect’,1203 ‘value’ => '’,1204 ),1205 array(1206 ‘type’ => 'textfield’,1207 ‘group’ => esc_html__('Confirmation’, ‘azh’),1208 ‘heading’ => esc_html__('Confirmation message’, ‘azh’),1209 ‘param_name’ => 'success’,1210 ‘value’ => '’,1211 ),1212 array(1213 ‘type’ => 'textfield’,1214 ‘group’ => esc_html__('Autoresponder’, ‘azh’),1215 ‘heading’ => esc_html__('Autorespond to email from submitted values’, ‘azh’),1216 ‘param_name’ => 'autoresponder_to_email’,1217 ‘value’ => '’,1218 ‘description’ => __('Available form fields: {form-fields}’, ‘azh’),1219 ),1220 array(1221 ‘type’ => 'textfield’,1222 ‘group’ => esc_html__('Autoresponder’, ‘azh’),1223 ‘heading’ => esc_html__('Autorespond from email’, ‘azh’),1224 ‘param_name’ => 'autoresponder_from_email’,1225 ‘value’ => get_bloginfo(‘admin_email’),1226 ),1227 array(1228 ‘type’ => 'textfield’,1229 ‘group’ => esc_html__('Autoresponder’, ‘azh’),1230 ‘heading’ => esc_html__('Email subject template’, ‘azh’),1231 ‘param_name’ => 'autoresponder_subject_template’,1232 ‘value’ => '’,1233 ‘description’ => __('Available form fields: {form-fields}’, ‘azh’),1234 ),1235 array(1236 ‘type’ => 'textarea_raw_html’,1237 ‘group’ => esc_html__('Autoresponder’, ‘azh’),1238 ‘heading’ => esc_html__('Email body template’, ‘azh’),1239 ‘param_name’ => 'autoresponder_body_template’,1240 ‘value’ => '’,1241 ‘description’ => __('Available form fields: {form-fields} ', ‘azh’),1242 ),1243 ),1244 ), ‘azh_form’);12451246 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {1247 if (defined(‘SCRIPT_DEBUG’)) {1248 if (!SCRIPT_DEBUG && !defined(‘CONCATENATE_SCRIPTS’)) {1249 define('CONCATENATE_SCRIPTS’, false);1250 }1251 } else {1252 define('SCRIPT_DEBUG’, true);1253 }12541255 $post_id = get_the_ID();1256 if (!$post_id) {1257 $post_id = azh_post_id_from_url();1258 }1259 if ($post_id) {1260 $post = get_post($post_id);1261 update_post_meta($post_id, 'azh’, ‘azh’);1262 if ($post->post_status == ‘auto-draft’) {1263 wp_update_post(array(1264 ‘ID’ => $post_id,1265 ‘post_status’ => 'draft’,1266 ));1267 }1268 }1269 }1270}12711272add_filter('the_content’, 'azh_the_content’, 0);12731274function azh_the_content($content) {12751276 $content = azh_content_begin($content);1277 $settings = get_option(‘azh-settings’);1278 if (get_post_type() == ‘azh_widget’ || (isset($settings[‘post-types’]) && in_array(get_post_type(), array_keys($settings[‘post-types’])) && get_post_meta(get_the_ID(), 'azh’, true))) {12791280 if (preg_match('/carousel-wrapper/’, $content)) {1281 wp_enqueue_script(‘owl.carousel’);1282 wp_enqueue_style(‘owl.carousel’);1283 }1284 if (preg_match('/(image-popup|iframe-popup)/’, $content)) {1285 wp_enqueue_script(‘magnific-popup’);1286 wp_enqueue_style(‘magnific-popup’);1287 }1288 if (preg_match('/data-sr/’, $content)) {1289 wp_enqueue_script(‘scrollReveal’);1290 }1291 if (preg_match('/masonry/’, $content)) {1292 wp_enqueue_script(‘masonry’);1293 }1294 if (preg_match('/azexo-tabs/’, $content)) {1295 wp_enqueue_script(‘jquery-ui-tabs’);1296 }1297 if (preg_match('/azexo-accordion/’, $content)) {1298 wp_enqueue_script(‘jquery-ui-accordion’);1299 }1300 }13011302 $content = azh_replaces($content);1303 $content = azh_generate_ids($content);1304 $content = azh_remove_comments($content);13051306 azh_enqueue_icons($content);13071308 return $content;1309}13101311add_filter('the_content’, 'azh_the_content_last’, 100);13121313function azh_the_content_last($content) {13141315 $content = azh_content_end($content);1316 return $content;1317}13181319add_action('widgets_init’, ‘azh_widgets_register_widgets’);13201321function azh_widgets_register_widgets() {1322 register_widget(‘AZH_Widget’);1323}13241325class AZH_Widget extends WP_Widget {13261327 function __construct() {1328 parent::__construct('azh_widget’, __('AZEXO - HTML Widget’, ‘azh’));1329 }13301331 function widget($args, $instance) {13321333 $body = '’;1334 if (!empty($instance[‘post’])) {1335 $wpautop = false;1336 if (has_filter('the_content’, ‘wpautop’)) {1337 remove_filter('the_content’, ‘wpautop’);1338 $wpautop = true;1339 }1340 $gutenberg_wpautop = false;1341 if (has_filter('the_content’, ‘gutenberg_wpautop’)) {1342 remove_filter('the_content’, 'gutenberg_wpautop’, 6);1343 $gutenberg_wpautop = true;1344 }13451346 if ($instance[‘post’] == NULL) {1347 $body = ‘<div data-post-id="’ . get_the_ID() . ‘">’ . apply_filters('the_content’, get_the_content()) . '</div>’;1348 } else {13491350 if (!apply_filters(‘azh_widget_’ . $instance[‘post’] . '_visible’, true, $instance[‘post’])) {1351 return;1352 }13531354 global $post, $wp_query;1355 $original = $post;1356 $post = get_post($instance[‘post’]);1357 setup_postdata($post);1358 $body = ‘<div data-post-id="’ . $instance[‘post’] . ‘">’ . apply_filters('the_content’, $post->post_content) . '</div>’;1359 $wp_query->post = $original;1360 wp_reset_postdata();1361 }13621363 if ($wpautop) {1364 add_filter('the_content’, ‘wpautop’);1365 }1366 if ($gutenberg_wpautop) {1367 add_filter('the_content’, 'gutenberg_wpautop’, 6);1368 }1369 }13701371 $args = apply_filters('azh_widget_args’, $args, $instance, $body);13721373 $title = apply_filters('widget_title’, empty($instance[‘title’]) ? ‘’ : $instance[‘title’], $instance, $this->id_base);13741375 print $args[‘before_widget’];1376 if ($title) {1377 print $args[‘before_title’] . $title . $args[‘after_title’];1378 }13791380 print $body;13811382 print $args[‘after_widget’];1383 }13841385 function form($instance) {1386 $defaults = array(‘post’ => '’, ‘title’ => ‘’);1387 $instance = wp_parse_args((array) $instance, $defaults);138813891390 $azh_widgets = array();1391 $loop = new WP_Query(array(1392 ‘post_type’ => 'azh_widget’,1393 ‘post_status’ => 'publish’,1394 ‘showposts’ => 100,1395 ‘orderby’ => 'title’,1396 ‘order’ => 'ASC’,1397 ));1398 if ($loop->have_posts()) {1399 global $post, $wp_query;1400 $original = $post;1401 while ($loop->have_posts()) {1402 $loop->the_post();1403 $azh_widgets[] = $post;1404 }1405 $wp_query->post = $original;1406 wp_reset_postdata();1407 }1408 ?>1409 <p>1410 <label for="<?php echo $this->get_field_id(‘title’); ?>"><?php _e('Title:’, ‘azh’); ?></label>1411 <input class="widefat” id="<?php echo $this->get_field_id(‘title’); ?>” name="<?php echo $this->get_field_name(‘title’); ?>” type="text" value="<?php echo $instance[‘title’]; ?>" />1412 </p>1413 <p>1414 <label for="<?php echo $this->get_field_id(‘post’); ?>"><?php _e('AZH Widget:’, ‘azh’); ?></label>1415 <select class="widefat" id="<?php echo $this->get_field_id(‘post’); ?>" name="<?php echo $this->get_field_name(‘post’); ?>">1416 <?php1417 foreach ($azh_widgets as $azh_widget) :1418 ?>1419 <option value="<?php echo $azh_widget->ID ?>" <?php selected($azh_widget->ID, $instance[‘post’]) ?>><?php echo $azh_widget->post_title; ?></option>1420 <?php endforeach; ?>1421 </select>1422 </p> 1423 <?php1424 }14251426}14271428add_action('init’, ‘azh_widgets_register’);14291430function azh_widgets_register() {1431 register_post_type('azh_widget’, array(1432 ‘labels’ => array(1433 ‘name’ => __('AZH Widget’, ‘azh’),1434 ‘singular_name’ => __('AZH Widget’, ‘azh’),1435 ‘add_new’ => __('Add AZH Widget’, ‘azh’),1436 ‘add_new_item’ => __('Add New AZH Widget’, ‘azh’),1437 ‘edit_item’ => __('Edit AZH Widget’, ‘azh’),1438 ‘new_item’ => __('New AZH Widget’, ‘azh’),1439 ‘view_item’ => __('View AZH Widget’, ‘azh’),1440 ‘search_items’ => __('Search AZH Widgets’, ‘azh’),1441 ‘not_found’ => __('No AZH Widget found’, ‘azh’),1442 ‘not_found_in_trash’ => __('No AZH Widget found in Trash’, ‘azh’),1443 ‘parent_item_colon’ => __('Parent AZH Widget:’, ‘azh’),1444 ‘menu_name’ => __('AZH Widgets’, ‘azh’),1445 ),1446 ‘query_var’ => false,1447 ‘rewrite’ => false,1448 ‘hierarchical’ => true,1449 ‘supports’ => array('title’, 'editor’, 'revisions’, 'thumbnail’, ‘custom-fields’),1450 ‘show_ui’ => true,1451 ‘show_in_nav_menus’ => true,1452 ‘show_in_menu’ => true,1453 ‘public’ => false,1454 ‘exclude_from_search’ => true,1455 ‘publicly_queryable’ => true,1456 )1457 );1458 register_taxonomy('widget_type’, array(‘azh_widget’), array(1459 ‘label’ => __('Widget type’, ‘azh’),1460 ‘hierarchical’ => true,1461 ));1462}14631464add_filter('manage_azh_widget_posts_columns’, ‘azh_widget_columns’);14651466function azh_widget_columns($columns) {1467 $columns[‘shortcode’] = __('Shortcode’, ‘azh’);1468 return $columns;1469}14701471add_action('manage_azh_widget_posts_custom_column’, ‘azh_widget_custom_columns’, 10, 2);14721473function azh_widget_custom_columns($column, $post_id) {1474 switch ($column) {1475 case ‘shortcode’ :1476 print '[azh_post id="’ . $post_id . '"]';1477 break;1478 }1479}14801481//add_filter('default_content’, 'azh_default_content’, 10, 2);14821483function azh_default_content($content, $post) {14841485 if ($post->post_type == ‘azh_widget’) {1486 return '<div data-section="element"><div data-cloneable><div data-element=" “></div></div></div>’;1487 }14881489 return $content;1490}14911492function azh_builder_scripts() {1493 wp_enqueue_style('azh_admin_frontend’, plugins_url('css/admin-frontend.css’, __FILE__), false, AZH_PLUGIN_VERSION);1494 wp_enqueue_script('azh-frontend-customization-options’, plugins_url('frontend-customization-options.js’, __FILE__), false, AZH_PLUGIN_VERSION, true);1495 wp_enqueue_script('simplemodal’, plugins_url('js/jquery.simplemodal.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);1496 wp_enqueue_style('select2’, plugins_url('css/select2.css’, __FILE__), false, AZH_PLUGIN_VERSION);1497 wp_enqueue_script('select2’, plugins_url('js/select2.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);1498 wp_enqueue_script('azh_admin’, plugins_url('js/admin.js’, __FILE__), array(‘azh_admin_frontend’), AZH_PLUGIN_VERSION, true);1499 wp_enqueue_script('azh_htmlparser’, plugins_url('js/htmlparser.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);1500 wp_enqueue_script('azh_html_editor’, plugins_url('js/html_editor.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);1501 wp_enqueue_script(‘jquery-ui-mouse’);1502 wp_enqueue_script(‘jquery-ui-sortable’);1503 wp_enqueue_script(‘jquery-ui-resizable’);1504 wp_enqueue_script(‘jquery-ui-autocomplete’);1505 wp_enqueue_script(‘jquery-ui-draggable’);1506 wp_enqueue_style(‘dashicons’);1507 wp_enqueue_script('ace’, plugins_url('js/ace/ace.js’, __FILE__), false, AZH_PLUGIN_VERSION);1508 wp_enqueue_script('css’, plugins_url('js/css.js’, __FILE__), false, AZH_PLUGIN_VERSION);150915101511 $suffix = SCRIPT_DEBUG ? ‘’ : '.min’;1512 wp_register_script('iris’, '/wp-admin/js/iris.min.js’, array('jquery-ui-draggable’, 'jquery-ui-slider’, ‘jquery-touch-punch’), AZH_PLUGIN_VERSION, 1);1513 wp_register_script('wp-color-picker’, “/wp-admin/js/color-picker$suffix.js", array(‘iris’), false, true);1514 wp_enqueue_style('wp-color-picker’, “/wp-admin/css/color-picker$suffix.css”);1515 wp_enqueue_script('wp-color-picker-alpha’, plugins_url('js/wp-color-picker-alpha.js’, __FILE__), array(‘wp-color-picker’), AZH_PLUGIN_VERSION, true);1516 wp_localize_script('wp-color-picker’, 'wpColorPickerL10n’, array(1517 ‘clear’ => __('Clear’, ‘azh’),1518 ‘defaultString’ => __('Default’, ‘azh’),1519 ‘pick’ => __('Select Color’, ‘azh’),1520 ‘current’ => __('Current Color’, ‘azh’),1521 ));1522}15231524function azh_device_prefixes() {1525 $settings = get_option(‘azh-settings’);1526 $device_prefixes = array(1527 ‘lg’ => array(1528 ‘label’ => __('Large device’, ‘azh’),1529 ‘width’ => false,1530 ‘height’ => false,1531 ‘container’ => 1170,1532 ‘min’ => 12001533 ),1534 ‘md’ => array(1535 ‘label’ => __('Medium device’, ‘azh’),1536 ‘width’ => 992,1537 ‘height’ => false,1538 ‘container’ => 970,1539 ‘max’ => 1199,1540 ‘min’ => 9921541 ),1542 ‘sm’ => array(1543 ‘label’ => __('Small device’, ‘azh’),1544 ‘width’ => 768,1545 ‘height’ => 1150,1546 ‘container’ => 750,1547 ‘max’ => 991,1548 ‘min’ => 7681549 ),1550 ‘xs’ => array(1551 ‘label’ => __(‘Extra small device’, ‘azh’),1552 ‘width’ => 320,1553 ‘height’ => 750,1554 ‘max’ => 7671555 ),1556 );1557 if (isset($settings[‘container-widths’])) {1558 $widths = explode("\n", trim($settings[‘container-widths’]));1559 if (count($widths) >= 3) {1560 $sm_min_max = explode(“:", $widths[0]);1561 $md_min_max = explode(“:", $widths[1]);1562 $lg_min_max = explode(“:", $widths[2]);1563 if (count($sm_min_max) === 2 && count($md_min_max) === 2 && count($lg_min_max) === 2) {15641565 $device_prefixes[‘sm’][‘container’] = (int) $sm_min_max[1];1566 $device_prefixes[‘sm’][‘width’] = (int) $sm_min_max[0];1567 $device_prefixes[‘md’][‘container’] = (int) $md_min_max[1];1568 $device_prefixes[‘md’][‘width’] = (int) $md_min_max[0];1569 $device_prefixes[‘lg’][‘container’] = (int) $lg_min_max[1];157015711572 $device_prefixes[‘xs’][‘max’] = (int) $sm_min_max[0] - 1;1573 $device_prefixes[‘sm’][‘min’] = (int) $sm_min_max[0];1574 $device_prefixes[‘sm’][‘max’] = (int) $md_min_max[0] - 1;1575 $device_prefixes[‘md’][‘min’] = (int) $md_min_max[0];1576 $device_prefixes[‘md’][‘max’] = (int) $lg_min_max[0] - 1;1577 $device_prefixes[‘lg’][‘min’] = (int) $lg_min_max[0];1578 }1579 }1580 }1581 return $device_prefixes;1582}15831584function azh_container_widths() {1585 $device_prefixes = azh_device_prefixes();15861587 $custom_css = “.az-container {1588 padding-right: 15px;1589 padding-left: 15px;1590 margin-left: auto;1591 margin-right: auto;1592 box-sizing: border-box;1593 }\n";1594 foreach (array('xs’, 'sm’, ‘md’, ‘lg’) as $prefix) {1595 $settings = $device_prefixes[$prefix];1596 if (isset($settings[‘min’]) && $settings[‘container’]) {1597 $custom_css .= “@media (min-width: " . $settings[‘min’] . “px) {1598 .az-container {1599 max-width: " . $settings[‘container’] . “px;1600 }1601 }\n";1602 }1603 }1604 wp_add_inline_style('azh_frontend’, $custom_css);1605 return $custom_css;1606}16071608function azh_get_sections_elements_edit_links($edit_links) {1609 $sections_edit = array();1610 $post = get_post();1611 preg_match_all('/ data-section=[\’”]([^\’”]+)[\’”]/i’, azh_get_post_content($post), $matches);1612 if (is_array($matches)) {1613 $post_type_object = get_post_type_object($post->post_type);1614 foreach ($matches[1] as $match) {1615 $sections_edit['[data-section="’ . $match . '”]'] = esc_url(admin_url(sprintf($post_type_object->_edit_link . ‘&action=edit&section=’ . $match, get_the_ID())));1616 }1617 }1618 $edit_links[‘sections’] = array(1619 ‘links’ => $sections_edit,1620 ‘css’ => array(‘top’ => '0’, ‘left’ => ‘0’),1621 ‘text’ => esc_html__('Edit section’, ‘azh’),1622 ‘target’ => '_self’,1623 );1624 $elements_edit = array();1625 preg_match_all('/ data-element=[\’”]([^\’”]+)[\’”]/i’, azh_get_post_content($post), $matches);1626 if (is_array($matches)) {1627 $post_type_object = get_post_type_object($post->post_type);1628 foreach ($matches[1] as $match) {1629 $elements_edit['[data-element="’ . $match . '”]'] = esc_url(admin_url(sprintf($post_type_object->_edit_link . ‘&action=edit&element=’ . $match, get_the_ID())));1630 }1631 }1632 $edit_links[‘elements’] = array(1633 ‘links’ => $elements_edit,1634 ‘css’ => array(‘top’ => '0’, ‘right’ => ‘0’),1635 ‘text’ => esc_html__('Edit element’, ‘azh’),1636 ‘target’ => ‘_self’,1637 );1638 return $edit_links;1639}16401641function azh_get_edit_links() {1642 global $post;1643 $edit_links = array();1644 $azh_widgets_edit = array();1645 if (is_object($post)) {1646 global $wp_widget_factory;1647 foreach ($wp_widget_factory->widgets as $name => $widget_obj) {1648 if ($name == ‘AZH_Widget’) {1649 $instances = $widget_obj->get_settings();1650 foreach ($instances as $number => $instance) {1651 if (isset($instance[‘post’]) && is_numeric($instance[‘post’])) {1652 $widget_post = get_post($instance[‘post’]);1653 //$selector = ‘#’ . $widget_obj->id_base . '-' . $number;1654 $selector = '[data-post-id="’ . $instance[‘post’] . '”]';1655 if ($widget_post) {1656 $azh_widgets_edit[$selector] = add_query_arg(array(‘azh’ => 'customize’, ‘azhf’ => $post->ID), get_edit_post_link($widget_post));1657 }1658 }1659 }1660 }1661 }1662 }1663 $edit_links[‘azh_widgets’] = array(1664 ‘links’ => $azh_widgets_edit,1665 ‘text’ => esc_html__('Edit AZH Widget’, ‘azh’),1666 ‘target’ => '_blank’,1667 );1668 if (is_page() && get_post_meta(get_the_ID(), 'azh’, true)) {1669 //$edit_links = azh_get_sections_elements_edit_links($edit_links);1670 }1671 return $edit_links;1672}16731674add_action('wp_enqueue_scripts’, ‘azh_scripts’);16751676function azh_scripts() {1677 global $post;1678 wp_enqueue_script('isotope’, plugins_url('js/isotope.pkgd.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);1679 wp_enqueue_script('waypoints’, plugins_url('js/jquery.waypoints.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);1680 wp_enqueue_script('countdown’, plugins_url('js/jquery.countdown.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);1681 wp_enqueue_script('maskedinput’, plugins_url('js/jquery.maskedinput.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);1682 wp_enqueue_style('swiper’, plugins_url('css/swiper.css’, __FILE__), false, AZH_PLUGIN_VERSION);1683 wp_enqueue_script('swiper’, plugins_url('js/swiper.js’, __FILE__), false, AZH_PLUGIN_VERSION, true);1684 wp_enqueue_style('animate’, plugins_url('css/animate.css’, __FILE__), false, AZH_PLUGIN_VERSION);1685 wp_enqueue_style('magnific-popup’, plugins_url('css/magnific-popup.css’, __FILE__), false, AZH_PLUGIN_VERSION);1686 wp_enqueue_script('magnific-popup’, plugins_url('js/jquery.magnific-popup.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);1687 wp_enqueue_script('scrollReveal’, plugins_url('js/scrollReveal.js’, __FILE__), array(‘jquery’), AZH_PLUGIN_VERSION, true);1688 wp_enqueue_script('azh-parallax’, plugins_url('js/parallax.js’, __FILE__), false, AZH_PLUGIN_VERSION, true);1689 wp_enqueue_script('rellax’, plugins_url('js/rellax.js’, __FILE__), false, AZH_PLUGIN_VERSION, true);1690 wp_enqueue_script('liquid’, plugins_url('js/liquid.js’, __FILE__), false, AZH_PLUGIN_VERSION);169116921693 $user = wp_get_current_user();1694 if (isset($post->ID) && current_user_can('edit_post’, $post->ID)) {1695 wp_enqueue_script('azh_admin_frontend’, plugins_url('js/admin-frontend.js’, __FILE__), array('jquery’, 'underscore’, 'jquery-ui-mouse’, 'jquery-ui-sortable’, 'jquery-ui-resizable’, 'jquery-ui-draggable’, ‘jquery-ui-autocomplete’), AZH_PLUGIN_VERSION, true);1696 wp_enqueue_script('azh_frontend’, plugins_url('js/frontend.js’, __FILE__), array('jquery’, 'imagesloaded’, ‘azh_admin_frontend’), AZH_PLUGIN_VERSION, true);1697 wp_enqueue_style('azh_frontend’, plugins_url('css/frontend.css’, __FILE__), false, AZH_PLUGIN_VERSION);1698 $azh = azh_get_object();1699 if (in_array('administrator’, (array) $user->roles)) {1700 $azh[‘edit_links’] = azh_get_edit_links();1701 }1702 wp_localize_script('azh_admin_frontend’, 'azh’, $azh);17031704 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {1705 azh_builder_scripts();1706 }1707 } else {1708 wp_enqueue_script('azh_frontend’, plugins_url('js/frontend.js’, __FILE__), array('jquery’, ‘imagesloaded’), AZH_PLUGIN_VERSION, true);1709 wp_enqueue_style('azh_frontend’, plugins_url('css/frontend.css’, __FILE__), false, AZH_PLUGIN_VERSION);17101711 if (get_page_template_slug() != ‘azexo-html-library.php’) {1712 wp_localize_script('azh_frontend’, 'azh’, azh_get_frontend_object());1713 }1714 }17151716 azh_container_widths();1717 $settings = get_option(‘azh-settings’);1718 if (isset($settings[‘credits’]) && isset($settings[‘credits’][‘enable’]) && $settings[‘credits’][‘enable’]) {1719 wp_add_inline_style('azh_frontend’, ‘.azexo-credits {display: block;}’);1720 }17211722 $post_content = azh_get_post_content($post);1723 $post_settings = azh_get_post_settings();1724 $widgets_content = azh_get_widgets_content();1725 $included_widgets_content = azh_get_included_widgets_content($post_content);1726 $fonts_url = azh_get_google_fonts_url($post_settings, $widgets_content . $included_widgets_content . $post_content, $post);1727 if ($fonts_url) {1728 wp_enqueue_style('azh-fonts’, $fonts_url, array(), null);1729 }1730 $post_scripts = azh_get_post_scripts();1731 if (!empty($post_scripts[‘css’])) {1732 foreach ($post_scripts[‘css’] as $css) {1733 wp_enqueue_style($css, $css);1734 }1735 }1736 if (!empty($post_scripts[‘js’])) {1737 foreach ($post_scripts[‘js’] as $js) {1738 wp_enqueue_script($js, $js, array(‘azh_frontend’), false, true);1739 }1740 }1741}17421743add_filter('post_type_link’, 'azh_post_link’, 10, 3);17441745function azh_post_link($permalink, $post, $leavename) {1746 if (in_array($post->post_type, array(‘azh_widget’))) {1747 $external_url = get_post_meta($post->ID, 'external_url’, true);1748 if (!empty($external_url)) {1749 return $external_url;1750 }1751 }1752 return $permalink;1753}17541755function azh_group_label_order($a, $b) {1756 if ($a[‘group’] < $b[‘group’]) {1757 return -1;1758 } else {1759 if ($a[‘group’] > $b[‘group’]) {1760 return 1;1761 } else {1762 if ($a[‘label’] < $b[‘label’]) {1763 return -1;1764 } else {1765 if ($a[‘label’] > $b[‘label’]) {1766 return 1;1767 } else {1768 return 0;1769 }1770 }1771 }1772 }1773}17741775add_action('wp_ajax_azh_terms_autocomplete_labels’, ‘azh_terms_autocomplete_labels’);17761777function azh_terms_autocomplete_labels() {1778 azh_get_terms_labels();1779 wp_die();1780}17811782function azh_get_terms_labels($taxonomy = array(), $slug = false) {1783 $include = array_filter(explode(',’, sanitize_text_field($_POST[‘values’])));1784 if (empty($taxonomy)) {1785 $taxonomies_types = get_taxonomies(array(‘public’ => true), ‘objects’);1786 $taxonomy = array_keys($taxonomies_types);1787 }1788 $args = array(1789 ‘taxonomy’ => $taxonomy,1790 ‘hide_empty’ => false,1791 );1792 if (!empty($include)) {1793 if ($slug) {1794 $args[‘slug’] = $include;1795 } else {1796 $args[‘include’] = $include;1797 }1798 }1799 $terms = get_terms($args);1800 $data = array();1801 if (is_array($terms) && !empty($terms)) {1802 foreach ($terms as $term) {1803 if (is_object($term)) {1804 if ($slug) {1805 $data[$term->slug] = $term->name;1806 } else {1807 $data[$term->term_id] = $term->name;1808 }1809 }1810 }1811 }1812 print json_encode($data);1813}18141815add_action('wp_ajax_azh_posts_autocomplete_labels’, ‘azh_posts_autocomplete_labels’);18161817function azh_posts_autocomplete_labels() {1818 azh_get_posts_labels();1819 wp_die();1820}18211822function azh_get_posts_labels($post_type = ‘any’) {1823 if (empty($post_type)) {1824 $post_type = 'any’;1825 }1826 $include = array_filter(explode(',’, sanitize_text_field($_POST[‘values’])));1827 if (empty($include)) {1828 $include = array(0);1829 }1830 $data = array();1831 $posts = get_posts(array(1832 ‘post_type’ => $post_type,1833 ‘include’ => $include,1834 ));1835 if (is_array($posts) && !empty($posts)) {1836 foreach ($posts as $post) {1837 if (is_object($post)) {1838 $data[$post->ID] = $post->post_title;1839 }1840 }1841 }1842 print json_encode($data);1843}18441845add_action('wp_ajax_azh_autocomplete_labels’, ‘azh_autocomplete_labels’);18461847function azh_autocomplete_labels() {1848 if (isset($_POST[‘shortcode’]) && isset($_POST[‘param_name’]) && isset($_POST[‘values’])) {1849 do_action(‘azh_autocomplete_’ . sanitize_text_field($_POST[‘shortcode’]) . ‘_’ . sanitize_text_field($_POST[‘param_name’]) . ‘_labels’);1850 }1851 wp_die();1852}18531854add_action('wp_ajax_azh_terms_autocomplete’, ‘azh_terms_autocomplete’);18551856function azh_terms_autocomplete() {1857 azh_search_terms();1858 wp_die();1859}18601861function azh_search_terms($taxonomy = array(), $slug = false) {1862 $data = array();1863 $taxonomies_types = get_taxonomies(array(‘public’ => true), ‘objects’);1864 if (empty($taxonomy)) {1865 $taxonomy = array_keys($taxonomies_types);1866 }1867 $exclude = array();1868 if (isset($_POST[‘exclude’])) {1869 $exclude = array_filter(explode(',’, sanitize_text_field($_POST[‘exclude’])));1870 }1871 $terms = get_terms(array(1872 ‘taxonomy’ => $taxonomy,1873 ‘hide_empty’ => false,1874 ‘exclude’ => $exclude,1875 ‘search’ => sanitize_text_field($_POST[‘search’]),1876 ));1877 if (is_array($terms) && !empty($terms)) {1878 foreach ($terms as $term) {1879 if (is_object($term)) {1880 if ($slug) {1881 $data[] = array(1882 ‘label’ => $term->name,1883 ‘value’ => $term->slug,1884 ‘group’ => isset($taxonomies_types[$term->taxonomy], $taxonomies_types[$term->taxonomy]->labels, $taxonomies_types[$term->taxonomy]->labels->name) ? $taxonomies_types[$term->taxonomy]->labels->name : __('Taxonomies’, ‘azh’),1885 );1886 } else {1887 $data[] = array(1888 ‘label’ => $term->name,1889 ‘value’ => $term->term_id,1890 ‘group’ => isset($taxonomies_types[$term->taxonomy], $taxonomies_types[$term->taxonomy]->labels, $taxonomies_types[$term->taxonomy]->labels->name) ? $taxonomies_types[$term->taxonomy]->labels->name : __('Taxonomies’, ‘azh’),1891 );1892 }1893 }1894 }1895 }1896 usort($data, ‘azh_group_label_order’);1897 print json_encode($data);1898}18991900add_action('wp_ajax_azh_posts_autocomplete’, ‘azh_posts_autocomplete’);19011902function azh_posts_autocomplete() {1903 azh_search_posts();1904 wp_die();1905}19061907function azh_search_posts($post_type = ‘any’) {1908 if (empty($post_type)) {1909 $post_type = 'any’;1910 }1911 $data = array();1912 $post_types = get_post_types(array(‘public’ => true), ‘objects’);1913 $exclude = array();1914 if (isset($_POST[‘exclude’])) {1915 $exclude = array_filter(explode(',’, sanitize_text_field($_POST[‘exclude’])));1916 }19171918 $posts = get_posts(array(1919 ‘post_type’ => $post_type,1920 ‘exclude’ => $exclude,1921 ‘s’ => sanitize_text_field($_POST[‘search’]),1922 ));1923 if (is_array($posts) && !empty($posts)) {1924 foreach ($posts as $post) {1925 if (is_object($post)) {1926 $data[] = array(1927 ‘label’ => $post->post_title,1928 ‘value’ => $post->ID,1929 ‘group’ => isset($post_types[$post->post_type], $post_types[$post->post_type]->labels, $post_types[$post->post_type]->labels->name) ? $post_types[$post->post_type]->labels->name : __('Posts’, ‘azh’),1930 );1931 }1932 }1933 }1934 usort($data, ‘azh_group_label_order’);1935 print json_encode($data);1936}19371938add_action('wp_ajax_azh_autocomplete’, ‘azh_autocomplete’);19391940function azh_autocomplete() {1941 if (isset($_POST[‘shortcode’]) && isset($_POST[‘param_name’]) && isset($_POST[‘search’])) {1942 do_action(‘azh_autocomplete_’ . sanitize_text_field($_POST[‘shortcode’]) . ‘_’ . sanitize_text_field($_POST[‘param_name’]));1943 }1944 wp_die();1945}19461947add_action('wp_ajax_azh_search_post’, ‘azh_search_post’);19481949function azh_search_post() {1950 if (isset($_REQUEST[‘values’]) && is_array($_REQUEST[‘values’])) {1951 $ids = array_map('sanitize_text_field’, $_REQUEST[‘values’]);1952 $options = array();1953 $posts = get_posts(array(1954 ‘post_type’ => 'any’,1955 ‘include’ => $ids,1956 ));1957 if (!empty($posts)) {1958 foreach ($posts as $post) {1959 $options[$post->ID] = $post->post_title;1960 }1961 }1962 print json_encode($options);1963 wp_die();1964 }1965 $results = array(1966 ‘results’ => array(),1967 );1968 if (isset($_REQUEST[‘term’])) {1969 $post_type = 'any’;1970 if (!empty($_REQUEST[‘post_type’])) {1971 $post_type = array_map('sanitize_text_field’, (array) $_REQUEST[‘post_type’]);1972 }1973 $posts = get_posts(array(1974 ‘post_type’ => $post_type,1975 ‘s’ => sanitize_text_field($_REQUEST[‘term’]),1976 ‘posts_per_page’ => '10’,1977 ));1978 if (!empty($posts)) {1979 $groups = array();1980 foreach ($posts as $post) {1981 if (!isset($groups[$post->post_type])) {1982 $groups[$post->post_type] = array();1983 }1984 $groups[$post->post_type][] = array(1985 ‘id’ => $post->ID,1986 ‘text’ => $post->post_title,1987 );1988 }1989 foreach ($groups as $post_type => $group) {1990 $obj = get_post_type_object($post_type);1991 $results[‘results’][] = array(1992 ‘text’ => $obj->labels->singular_name,1993 ‘children’ => $group,1994 );1995 }1996 }1997 }1998 print json_encode($results);1999 wp_die();2000}20012002add_action('wp_ajax_azh_search_term’, ‘azh_search_term’);20032004function azh_search_term() {2005 $slug = isset($_REQUEST[‘slug’]) ? true : false;2006 if (isset($_REQUEST[‘values’]) && is_array($_REQUEST[‘values’])) {2007 $values = array_map('sanitize_text_field’, $_REQUEST[‘values’]);2008 $options = array();2009 $args = array(2010 ‘hide_empty’ => false,2011 );2012 if ($slug) {2013 $args[‘slug’] = $values;2014 } else {2015 $args[‘include’] = $values;2016 }2017 $terms = get_terms($args);2018 if (!empty($terms)) {2019 foreach ($terms as $term) {2020 if ($slug) {2021 $options[$term->slug] = $term->name;2022 } else {2023 $options[$term->term_id] = $term->name;2024 }2025 }2026 }2027 print json_encode($options);2028 wp_die();2029 }2030 $results = array(2031 ‘results’ => array(),2032 );2033 if (isset($_REQUEST[‘term’])) {2034 $taxonomies_types = get_taxonomies(array(‘public’ => true), ‘objects’);2035 $taxonomy = array_keys($taxonomies_types);2036 if (!empty($_REQUEST[‘taxonomy’])) {2037 $taxonomy = array_map('sanitize_text_field’, (array) $_REQUEST[‘taxonomy’]);2038 }2039 $terms = get_terms(array(2040 ‘taxonomy’ => $taxonomy,2041 ‘hide_empty’ => false,2042 ‘search’ => sanitize_text_field($_REQUEST[‘term’]),2043 ));20442045 if (!empty($terms)) {2046 $groups = array();2047 foreach ($terms as $term) {2048 if (!isset($groups[$term->taxonomy])) {2049 $groups[$term->taxonomy] = array();2050 }2051 if ($slug) {2052 $groups[$term->taxonomy][] = array(2053 ‘id’ => $term->slug,2054 ‘text’ => $term->name,2055 );2056 } else {2057 $groups[$term->taxonomy][] = array(2058 ‘id’ => $term->term_id,2059 ‘text’ => $term->name,2060 );2061 }2062 }2063 foreach ($groups as $taxonomy => $group) {2064 $results[‘results’][] = array(2065 ‘text’ => $taxonomies_types[$taxonomy]->labels->name,2066 ‘children’ => $group,2067 );2068 }2069 }2070 }2071 print json_encode($results);2072 wp_die();2073}20742075function azh_get_attributes($tag, $atts) {2076 global $azh_shortcodes;2077 if (isset($azh_shortcodes)) {2078 if ($tag && isset($azh_shortcodes[$tag])) {2079 $settings = $azh_shortcodes[$tag];2080 if (isset($settings[‘params’]) && !empty($settings[‘params’])) {2081 if(!is_array($atts)) {2082 $atts = array();2083 }2084 foreach ($settings[‘params’] as $param) {2085 if (!isset($atts[$param[‘param_name’]]) && isset($param[‘value’])) {2086 $atts[$param[‘param_name’]] = $param[‘value’];2087 if (is_array($atts[$param[‘param_name’]])) {2088 $atts[$param[‘param_name’]] = current($atts[$param[‘param_name’]]);2089 }2090 }2091 }2092 }2093 }2094 }2095 return $atts;2096}20972098function azh_shortcode($atts, $content = null, $tag = null) {2099 global $azh_shortcodes;2100 if (isset($azh_shortcodes)) {2101 if ($tag && isset($azh_shortcodes[$tag])) {2102 $atts = azh_get_attributes($tag, $atts);2103 if (isset($azh_shortcodes[$tag][‘html_template’]) && file_exists($azh_shortcodes[$tag][‘html_template’])) {2104 ob_start();2105 include($azh_shortcodes[$tag][‘html_template’]);2106 return ob_get_clean();2107 } else {2108 $located = locate_template(‘vc_templates’ . ‘/’ . $tag . ‘.php’);2109 if ($located) {2110 ob_start();2111 include($located);2112 return ob_get_clean();2113 }2114 }2115 }2116 }2117}21182119function azh_add_element($settings, $func = false) {2120 global $azh_shortcodes;2121 if (isset($settings[‘base’])) {2122 $azh_shortcodes[$settings[‘base’]] = apply_filters('azh_add_element’, $settings);2123 if (!shortcode_exists($settings[‘base’])) {2124 if ($func) {2125 add_shortcode($settings[‘base’], $func);2126 } else {2127 add_shortcode($settings[‘base’], ‘azh_shortcode’);2128 }2129 }2130 }2131}21322133function azexo_get_dir_files($src) {2134 $files = array();2135 $dir = opendir($src);2136 if (is_resource($dir))2137 while (false !== ( $file = readdir($dir))) {2138 if (( $file != ‘.’ ) && ( $file != ‘…’ )) {2139 $files[$file] = realpath($src . ‘/’ . $file);2140 }2141 }2142 closedir($dir);2143 return $files;2144}21452146function azexo_get_skins() {2147 $skins = array();2148 if (is_child_theme()) {2149 $files = azexo_get_dir_files(get_stylesheet_directory() . ‘/less’);2150 } else {2151 $files = azexo_get_dir_files(get_template_directory() . ‘/less’);2152 }2153 foreach ($files as $name => $path) {2154 if (is_dir($path)) {2155 $skin_files = azexo_get_dir_files($path);2156 if (isset($skin_files[‘skin.less’])) {2157 $skins[] = $name;2158 }2159 }2160 }2161 return $skins;2162}21632164add_action('wp_ajax_azh_upload’, ‘azh_upload’);21652166function azh_upload() {2167 if (isset($_POST[‘code’]) && isset($_POST[‘dir’]) && isset($_POST[‘file’])) {2168 $user = wp_get_current_user();2169 if (in_array('administrator’, (array) $user->roles)) {2170 $file = sanitize_text_field($_POST[‘dir’]) . ‘/’ . sanitize_text_field($_POST[‘file’]);2171 if (file_exists($file)) {2172 azh_filesystem();2173 global $wp_filesystem;2174 if ($wp_filesystem->put_contents($file, stripslashes($_POST[‘code’]), FS_CHMOD_FILE)) {2175 print '1’;2176 }2177 }2178 }2179 }2180 wp_die();2181}21822183add_action('wp_ajax_azh_copy’, ‘azh_copy’);21842185function azh_copy() {2186 if (isset($_POST[‘code’])) {2187 update_option('azh_clipboard’, stripslashes($_POST[‘code’]));2188 }2189 if (isset($_POST[‘path’])) {2190 update_option('azh_clipboard_path’, stripslashes($_POST[‘path’]));2191 }2192 wp_die();2193}21942195add_action('wp_ajax_azh_paste’, ‘azh_paste’);21962197function azh_paste() {2198 print json_encode(array(2199 ‘code’ => get_option(‘azh_clipboard’),2200 ‘path’ => get_option(‘azh_clipboard_path’),2201 ));2202 wp_die();2203}22042205function azh_shortcode_restore($atts, $content = null, $tag = null) {2206 $shortcode = '[' . $tag;2207 if (is_array($atts)) {2208 foreach ($atts as $name => $value) {2209 $shortcode .= ' ' . $name . ‘="’ . $value . '"’;2210 }2211 }2212 $shortcode .= ']‘;2213 if ($content) {2214 $shortcode .= $content . '[/’ . $tag . ']';2215 }2216 return $shortcode;2217}22182219function azh_shortcode_wrapper($atts, $content = null, $tag = null) {2220 $shortcode = ‘<div data-element="">’ . azh_shortcode_restore($atts, $content, $tag) . '</div>’;2221 return $shortcode;2222}22232224function azh_wrap_shortcodes($content) {2225 global $shortcode_tags;2226 $original_shortcode_tags = $shortcode_tags;2227 $tags = array_keys($shortcode_tags);2228 $shortcode_tags = array();2229 foreach ($tags as $tag) {2230 if (strpos($tag, ‘azh_’) === false) {2231 $shortcode_tags[$tag] = 'azh_shortcode_wrapper’;2232 }2233 }2234 $content = do_shortcode($content);2235 $shortcode_tags = $original_shortcode_tags;2236 return $content;2237}22382239function azh_get_post_content($post) {2240 if (is_object($post)) {2241 $content = get_post_meta($post->ID, '_azh_content’, true);2242 if (empty($content) && !empty($post->post_content) && ((get_post_meta($post->ID, ‘azh’, true) || $post->post_type === ‘azh_widget’))) {2243 $content = $post->post_content;2244 $content = azh_wrap_shortcodes($content);2245 if (!empty($content) && false === strpos($content, ' data-section=’)) {2246 $content = ‘<div data-section="content">’ . $content . '</div>’;2247 }2248 return azh_set_post_content($content, $post->ID);2249 }2250 return $content;2251 }2252}22532254function azh_wp_post_content($content, $post_id) {2255 $override = apply_filters('azh_wp_post_content’, false, $content, $post_id);2256 if ($override) {2257 return $override;2258 }2259 $plain_content = $content;2260 if (!empty($plain_content)) {2261 $allowedposttags = array(2262 ‘address’ => array(),2263 ‘a’ => array(2264 ‘href’ => true,2265 ‘rel’ => true,2266 ‘rev’ => true,2267 ‘name’ => true,2268 ‘target’ => true,2269 ),2270 ‘abbr’ => array(),2271 ‘acronym’ => array(),2272 ‘area’ => array(2273 ‘alt’ => true,2274 ‘coords’ => true,2275 ‘href’ => true,2276 ‘nohref’ => true,2277 ‘shape’ => true,2278 ‘target’ => true,2279 ),2280 ‘article’ => array(2281 ‘align’ => true,2282 ‘dir’ => true,2283 ‘lang’ => true,2284 ‘xml:lang’ => true,2285 ),2286 ‘aside’ => array(2287 ‘align’ => true,2288 ‘dir’ => true,2289 ‘lang’ => true,2290 ‘xml:lang’ => true,2291 ),2292 ‘audio’ => array(2293 ‘autoplay’ => true,2294 ‘controls’ => true,2295 ‘loop’ => true,2296 ‘muted’ => true,2297 ‘preload’ => true,2298 ‘src’ => true,2299 ),2300 ‘b’ => array(),2301 ‘bdo’ => array(2302 ‘dir’ => true,2303 ),2304 ‘big’ => array(),2305 ‘blockquote’ => array(2306 ‘cite’ => true,2307 ‘lang’ => true,2308 ‘xml:lang’ => true,2309 ),2310 ‘br’ => array(),2311 ‘button’ => array(2312 ‘disabled’ => true,2313 ‘name’ => true,2314 ‘type’ => true,2315 ‘value’ => true,2316 ),2317 ‘caption’ => array(2318 ‘align’ => true,2319 ),2320 ‘cite’ => array(2321 ‘dir’ => true,2322 ‘lang’ => true,2323 ),2324 ‘code’ => array(),2325 ‘col’ => array(2326 ‘align’ => true,2327 ‘char’ => true,2328 ‘charoff’ => true,2329 ‘span’ => true,2330 ‘dir’ => true,2331 ‘valign’ => true,2332 ‘width’ => true,2333 ),2334 ‘colgroup’ => array(2335 ‘align’ => true,2336 ‘char’ => true,2337 ‘charoff’ => true,2338 ‘span’ => true,2339 ‘valign’ => true,2340 ‘width’ => true,2341 ),2342 ‘del’ => array(2343 ‘datetime’ => true,2344 ),2345 ‘dd’ => array(),2346 ‘dfn’ => array(),2347 ‘details’ => array(2348 ‘align’ => true,2349 ‘dir’ => true,2350 ‘lang’ => true,2351 ‘open’ => true,2352 ‘xml:lang’ => true,2353 ),2354// ‘div’ => array(2355// ‘align’ => true,2356// ‘dir’ => true,2357// ‘lang’ => true,2358// ‘xml:lang’ => true,2359// ),2360 ‘dl’ => array(),2361 ‘dt’ => array(),2362 ‘em’ => array(),2363 ‘fieldset’ => array(),2364 ‘figure’ => array(2365 ‘align’ => true,2366 ‘dir’ => true,2367 ‘lang’ => true,2368 ‘xml:lang’ => true,2369 ),2370 ‘figcaption’ => array(2371 ‘align’ => true,2372 ‘dir’ => true,2373 ‘lang’ => true,2374 ‘xml:lang’ => true,2375 ),2376 ‘font’ => array(2377 ‘color’ => true,2378 ‘face’ => true,2379 ‘size’ => true,2380 ),2381 ‘footer’ => array(2382 ‘align’ => true,2383 ‘dir’ => true,2384 ‘lang’ => true,2385 ‘xml:lang’ => true,2386 ),2387 ‘form’ => array(2388 ‘action’ => true,2389 ‘accept’ => true,2390 ‘accept-charset’ => true,2391 ‘enctype’ => true,2392 ‘method’ => true,2393 ‘name’ => true,2394 ‘target’ => true,2395 ),2396 ‘h1’ => array(2397 ‘align’ => true,2398 ),2399 ‘h2’ => array(2400 ‘align’ => true,2401 ),2402 ‘h3’ => array(2403 ‘align’ => true,2404 ),2405 ‘h4’ => array(2406 ‘align’ => true,2407 ),2408 ‘h5’ => array(2409 ‘align’ => true,2410 ),2411 ‘h6’ => array(2412 ‘align’ => true,2413 ),2414 ‘header’ => array(2415 ‘align’ => true,2416 ‘dir’ => true,2417 ‘lang’ => true,2418 ‘xml:lang’ => true,2419 ),2420 ‘hgroup’ => array(2421 ‘align’ => true,2422 ‘dir’ => true,2423 ‘lang’ => true,2424 ‘xml:lang’ => true,2425 ),2426 ‘hr’ => array(2427 ‘align’ => true,2428 ‘noshade’ => true,2429 ‘size’ => true,2430 ‘width’ => true,2431 ),2432 ‘i’ => array(),2433 ‘img’ => array(2434 ‘alt’ => true,2435 ‘align’ => true,2436 ‘border’ => true,2437 ‘height’ => true,2438 ‘hspace’ => true,2439 ‘longdesc’ => true,2440 ‘vspace’ => true,2441 ‘src’ => true,2442 ‘usemap’ => true,2443 ‘width’ => true,2444 ),2445 ‘ins’ => array(2446 ‘datetime’ => true,2447 ‘cite’ => true,2448 ),2449 ‘kbd’ => array(),2450 ‘label’ => array(2451 ‘for’ => true,2452 ),2453 ‘legend’ => array(2454 ‘align’ => true,2455 ),2456 ‘li’ => array(2457 ‘align’ => true,2458 ‘value’ => true,2459 ),2460 ‘map’ => array(2461 ‘name’ => true,2462 ),2463 ‘mark’ => array(),2464 ‘menu’ => array(2465 ‘type’ => true,2466 ),2467 ‘nav’ => array(2468 ‘align’ => true,2469 ‘dir’ => true,2470 ‘lang’ => true,2471 ‘xml:lang’ => true,2472 ),2473 ‘p’ => array(2474 ‘align’ => true,2475 ‘dir’ => true,2476 ‘lang’ => true,2477 ‘xml:lang’ => true,2478 ),2479 ‘pre’ => array(2480 ‘width’ => true,2481 ),2482 ‘q’ => array(2483 ‘cite’ => true,2484 ),2485 ‘s’ => array(),2486 ‘samp’ => array(),2487// ‘span’ => array(2488// ‘dir’ => true,2489// ‘align’ => true,2490// ‘lang’ => true,2491// ‘xml:lang’ => true,2492// ),2493 ‘section’ => array(2494 ‘align’ => true,2495 ‘dir’ => true,2496 ‘lang’ => true,2497 ‘xml:lang’ => true,2498 ),2499 ‘small’ => array(),2500 ‘strike’ => array(),2501 ‘strong’ => array(),2502 ‘sub’ => array(),2503 ‘summary’ => array(2504 ‘align’ => true,2505 ‘dir’ => true,2506 ‘lang’ => true,2507 ‘xml:lang’ => true,2508 ),2509 ‘sup’ => array(),2510 ‘table’ => array(2511 ‘align’ => true,2512 ‘bgcolor’ => true,2513 ‘border’ => true,2514 ‘cellpadding’ => true,2515 ‘cellspacing’ => true,2516 ‘dir’ => true,2517 ‘rules’ => true,2518 ‘summary’ => true,2519 ‘width’ => true,2520 ),2521 ‘tbody’ => array(2522 ‘align’ => true,2523 ‘char’ => true,2524 ‘charoff’ => true,2525 ‘valign’ => true,2526 ),2527 ‘td’ => array(2528 ‘abbr’ => true,2529 ‘align’ => true,2530 ‘axis’ => true,2531 ‘bgcolor’ => true,2532 ‘char’ => true,2533 ‘charoff’ => true,2534 ‘colspan’ => true,2535 ‘dir’ => true,2536 ‘headers’ => true,2537 ‘height’ => true,2538 ‘nowrap’ => true,2539 ‘rowspan’ => true,2540 ‘scope’ => true,2541 ‘valign’ => true,2542 ‘width’ => true,2543 ),2544 ‘textarea’ => array(2545 ‘cols’ => true,2546 ‘rows’ => true,2547 ‘disabled’ => true,2548 ‘name’ => true,2549 ‘readonly’ => true,2550 ),2551 ‘tfoot’ => array(2552 ‘align’ => true,2553 ‘char’ => true,2554 ‘charoff’ => true,2555 ‘valign’ => true,2556 ),2557 ‘th’ => array(2558 ‘abbr’ => true,2559 ‘align’ => true,2560 ‘axis’ => true,2561 ‘bgcolor’ => true,2562 ‘char’ => true,2563 ‘charoff’ => true,2564 ‘colspan’ => true,2565 ‘headers’ => true,2566 ‘height’ => true,2567 ‘nowrap’ => true,2568 ‘rowspan’ => true,2569 ‘scope’ => true,2570 ‘valign’ => true,2571 ‘width’ => true,2572 ),2573 ‘thead’ => array(2574 ‘align’ => true,2575 ‘char’ => true,2576 ‘charoff’ => true,2577 ‘valign’ => true,2578 ),2579 ‘title’ => array(),2580 ‘tr’ => array(2581 ‘align’ => true,2582 ‘bgcolor’ => true,2583 ‘char’ => true,2584 ‘charoff’ => true,2585 ‘valign’ => true,2586 ),2587 ‘track’ => array(2588 ‘default’ => true,2589 ‘kind’ => true,2590 ‘label’ => true,2591 ‘src’ => true,2592 ‘srclang’ => true,2593 ),2594 ‘tt’ => array(),2595 ‘u’ => array(),2596 ‘ul’ => array(2597 ‘type’ => true,2598 ),2599 ‘ol’ => array(2600 ‘start’ => true,2601 ‘type’ => true,2602 ‘reversed’ => true,2603 ),2604 ‘var’ => array(),2605 ‘video’ => array(2606 ‘autoplay’ => true,2607 ‘controls’ => true,2608 ‘height’ => true,2609 ‘loop’ => true,2610 ‘muted’ => true,2611 ‘poster’ => true,2612 ‘preload’ => true,2613 ‘src’ => true,2614 ‘width’ => true,2615 ),2616 ‘iframe’ => array(2617 ‘src’ => true,2618 ),2619 );2620 $allowedposttags = apply_filters('azh_plain_allowedposttags’, $allowedposttags, $post_id);2621 if ($allowedposttags) {2622 $plain_content = wp_kses($content, $allowedposttags);2623 }2624 }2625 return $plain_content;2626}26272628function azh_set_post_content($content, $post_id) {2629 $content = apply_filters('azh_set_post_content’, $content, $post_id);2630 update_post_meta($post_id, '_azh_content’, $content);26312632 $post_content = $content;2633 if (get_post_type($post_id) !== ‘azh_widget’) {2634 $post_content = azh_wp_post_content($post_content, $post_id);2635 }2636 wp_update_post(array(2637 ‘ID’ => $post_id,2638 ‘post_content’ => $post_content,2639 ));2640 return $content;2641}26422643function azh_save_revision($revision_id) {2644 $parent_id = wp_is_post_revision($revision_id);2645 if ($parent_id && get_post_meta($parent_id, 'azh’, true)) {2646 $content = get_post_meta($parent_id, '_azh_content’, true);2647 update_metadata('post’, $revision_id, '_azh_content’, $content);26482649 $settings = get_post_meta($parent_id, '_azh_settings’, true);2650 update_metadata('post’, $revision_id, '_azh_settings’, $settings);26512652 update_metadata('post’, $revision_id, 'azh’, ‘azh’);2653 }2654}26552656add_action('wp_restore_post_revision’, 'azh_restore_post_revision’, 10, 2);26572658function azh_restore_post_revision($parent_id, $revision_id) {2659 if (get_post_meta($revision_id, 'azh’, true)) {2660 $content = get_post_meta($revision_id, '_azh_content’, true);2661 update_post_meta($parent_id, '_azh_content’, $content);26622663 $settings = get_post_meta($revision_id, '_azh_settings’, true);2664 update_post_meta($parent_id, '_azh_settings’, $settings);26652666 update_post_meta($parent_id, 'azh’, ‘azh’);2667 }2668}26692670add_action('wp_ajax_azh_autosave’, ‘azh_autosave’);26712672function azh_autosave() {2673 if (isset($_POST[‘content’]) && is_numeric((int) $_POST[‘post_id’])) {2674 $post = get_post((int) $_POST[‘post_id’]);2675 if (current_user_can('edit_post’, $post->ID)) {26762677 add_filter('wp_save_post_revision_post_has_changed’, ‘__return_true’);2678 add_action('_wp_put_post_revision’, ‘azh_save_revision’);26792680 $content = stripslashes($_POST[‘content’]);26812682 $old_autosave = wp_get_post_autosave((int) $_POST[‘post_id’], get_current_user_id());26832684 if ($old_autosave) {2685 wp_delete_post_revision($old_autosave->ID);2686 }26872688 if ($post->post_type !== ‘azh_widget’) {2689 $content = azh_wp_post_content($content, $post->ID);2690 }26912692 $autosave_id = wp_create_post_autosave(array(2693 ‘post_ID’ => (int) $_POST[‘post_id’],2694 ‘post_title’ => __('Auto Save’, ‘azh’) . ' ' . date(‘Y-m-d H:i’),2695 ‘post_modified’ => current_time(‘mysql’),2696 ‘post_content’ => $content,2697 ));26982699 if ($autosave_id && !is_wp_error($autosave_id)) {2700 if (isset($_POST[‘shortcodes’])) {2701 $settings = get_post_meta((int) $_POST[‘post_id’], '_azh_settings’, true);2702 $settings[‘shortcodes’] = stripslashes_deep($_POST[‘shortcodes’]);2703 update_metadata('post’, $autosave_id, '_azh_settings’, $settings);27042705// $settings = array_replace_recursive(get_option('azh-settings’, array()), $settings);2706// update_option('azh-settings’, $settings);2707 }27082709 $content = apply_filters('azh_set_post_content’, $content, $autosave_id);2710 update_metadata('post’, $autosave_id, '_azh_content’, $content);27112712 print json_encode(azh_parse_revision(get_post($autosave_id)));2713 }2714 }2715 }2716 wp_die();2717}27182719add_action('wp_ajax_azh_save’, ‘azh_save’);27202721function azh_save() {2722 if (isset($_POST[‘content’]) && is_numeric((int) $_POST[‘post_id’])) {2723 $post = get_post((int) $_POST[‘post_id’]);2724 if (current_user_can('edit_post’, $post->ID)) {27252726 add_filter('wp_save_post_revision_post_has_changed’, ‘__return_true’);2727 add_action('_wp_put_post_revision’, ‘azh_save_revision’);27282729 if (isset($_POST[‘shortcodes’])) {2730 $settings = get_post_meta((int) $_POST[‘post_id’], '_azh_settings’, true);2731 $settings[‘shortcodes’] = stripslashes_deep($_POST[‘shortcodes’]);2732 update_post_meta((int) $_POST[‘post_id’], '_azh_settings’, $settings);273327342735// $settings = array_replace_recursive(get_option('azh-settings’, array()), $settings);2736// update_option('azh-settings’, $settings);2737 }27382739 azh_set_post_content(stripslashes($_POST[‘content’]), (int) $_POST[‘post_id’]);2740 update_post_meta((int) $_POST[‘post_id’], 'azh’, ‘azh’);27412742 $revisions = wp_get_post_revisions((int) $_POST[‘post_id’]);2743 $latest_revision = array_shift($revisions);27442745 print json_encode(azh_parse_revision($latest_revision));2746 }2747 }2748 wp_die();2749}27502751add_action('wp_ajax_azh_update_shortcode’, ‘azh_update_shortcode’);27522753function azh_update_shortcode() {2754 if (isset($_POST[‘instance’]) && isset($_POST[‘shortcode’]) && is_numeric((int) $_POST[‘post_id’])) {2755 $shortcode = stripslashes($_POST[‘shortcode’]);2756 $instance = sanitize_text_field($_POST[‘instance’]);27572758 $settings = get_post_meta((int) $_POST[‘post_id’], '_azh_settings’, true);2759 $settings[‘shortcodes’][$instance] = $shortcode;2760 update_post_meta((int) $_POST[‘post_id’], '_azh_settings’, $settings);27612762 $shortcodes = get_option(‘azh-shortcodes’);2763 $shortcodes[$instance] = $shortcode;2764 update_option('azh-shortcodes’, $shortcodes);2765276627672768 global $post, $wp_query;2769 $original = $post;2770 $post = get_post((int) $_POST[‘post_id’]);2771 setup_postdata($post);27722773 print do_shortcode($shortcode);2774 //wp_print_styles();2775 //wp_print_scripts();27762777 $wp_query->post = $original;2778 wp_reset_postdata();2779 }2780 wp_die();2781}27822783azh_add_element(array(2784 “name” => esc_html__('Text’, ‘azh’),2785 “category” => esc_html__('WordPress’, ‘azh’),2786 “base” => “azh_text",2787 “image” => AZH_URL . '/images/text.png’,2788 “show_settings_on_create” => true,2789 ‘params’ => array(2790 array(2791 ‘type’ => 'textarea_html’,2792 ‘heading’ => esc_html__('Content’, ‘azh’),2793 ‘holder’ => 'div’,2794 ‘param_name’ => 'content’,2795 ‘value’ => wp_kses(__('<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.</p>’, ‘azh’), array(‘p’))2796 ),2797 ),2798 ), ‘azh_text’);27992800function azh_text($atts, $content = null, $tag = null) {2801 return do_shortcode(shortcode_unautop($content));2802}28032804function azh_get_file($file, $azh_uri, $frontend = true) {2805 if (file_exists($file)) {2806 azh_filesystem();2807 global $wp_filesystem;2808 $content = $wp_filesystem->get_contents($file);2809 $content = azh_replaces($content, $azh_uri);2810 $content = azh_generate_ids($content);2811 $content = azh_remove_comments($content);2812 $content = str_replace(array(“\t", “\r", “\n”), '’, $content);2813 $content = preg_replace('/> +</’, '><’, $content);2814 if ($frontend) {2815 azh_enqueue_icons($content);2816 $content = do_shortcode($content);2817 }2818 return $content;2819 } else {2820 return '’;2821 }2822}28232824function azh_enqueue_content_scripts($content) {2825 $fonts_url = azh_get_google_fonts_url(azh_get_content_settings($content), $content);2826 if ($fonts_url) {2827 wp_enqueue_style('azh-fonts-' . md5($content), $fonts_url, array(), null);2828 }28292830 $scripts = azh_get_content_scripts($content);2831 if (!empty($scripts[‘css’])) {2832 foreach ($scripts[‘css’] as $css) {2833 wp_enqueue_style($css, $css);2834 }2835 }2836 if (!empty($scripts[‘js’])) {2837 foreach ($scripts[‘js’] as $js) {2838 wp_enqueue_script($js, $js, array(), false, true);2839 }2840 }2841}28422843add_shortcode('azh_post’, ‘azh_post’);28442845function azh_post($atts, $content = null, $tag = null) {2846 if (isset($atts[‘id’])) {28472848 if (!apply_filters(‘azh_widget_’ . $atts[‘id’] . '_visible’, true, $atts[‘id’])) {2849 return '’;2850 }28512852 global $post, $wp_query;2853 $original = $post;2854 $post = get_post($atts[‘id’]);2855 setup_postdata($post);2856 $content = ‘<div data-post-id="’ . $atts[‘id’] . ‘">’ . apply_filters('the_content’, get_the_content(‘’)) . '</div>’;2857 $wp_query->post = $original;2858 wp_reset_postdata();28592860 azh_enqueue_content_scripts($content);28612862 return $content;2863 }2864}28652866add_action('wp_ajax_azh_get_wp_editor’, ‘azh_get_wp_editor’);28672868function azh_get_wp_editor() {2869 ob_start();2870 wp_editor('’, sanitize_text_field($_POST[‘id’]), array(2871 ‘dfw’ => false,2872 ‘media_buttons’ => true,2873 ‘tabfocus_elements’ => 'insert-media-button’,2874 ‘editor_height’ => 360,2875 ‘wpautop’ => false,2876 ‘drag_drop_upload’ => true,2877 ));2878 $editor = ob_get_contents();2879 ob_end_clean();2880 print $editor;2881 die();2882}28832884add_action('admin_bar_menu’, 'azh_admin_bar_menu’, 999);28852886function azh_admin_bar_menu($wp_admin_bar) {2887 if (!(isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’)) {2888 if (!is_admin()) {2889 $wp_admin_bar->add_node(array(2890 ‘id’ => 'edit-links’,2891 ‘title’ => esc_html__('Edit links’, ‘azh’),2892 ‘href’ => '#’,2893 ‘meta’ => array(2894 ‘class’ => 'active’,2895 ),2896 ));2897 }2898 $settings = get_option(‘azh-settings’);2899 if ((isset($settings[‘post-types’]) && in_array(get_post_type(), array_keys($settings[‘post-types’])) && get_post_meta(get_the_ID(), 'azh’, true)) || (is_singular() && get_post_type() == ‘azh_widget’)) {2900 $wp_admin_bar->add_node(array(2901 ‘id’ => 'azh-frontend-builder’,2902 ‘title’ => esc_html__('Edit with AZEXO’, ‘azh’),2903 ‘href’ => add_query_arg('azh’, 'customize’, get_edit_post_link()),2904 ));2905 }2906 }2907}29082909add_action('template_redirect’, ‘azh_template_redirect’);29102911function azh_template_redirect() {2912 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘library’ && isset($_GET[‘customize’])) {2913 $files = explode('|’, $_GET[‘customize’]);2914 $library = azh_get_library();2915 $content = '’;2916 foreach ($files as $file) {2917 if (is_array($library[‘elements’])) {2918 foreach ($library[‘elements’] as $element_file => $name) {2919 if (strlen($element_file) - strlen($file) == strrpos($element_file, $file)) {2920 $content .= ‘<div data-element="’ . esc_attr(ltrim(str_replace($library[‘elements_dir’][$element_file], '’, $element_file), ‘/’)) . '">’;2921 $content .= azh_get_file($element_file, $library[‘elements_uri’][$element_file]);2922 $content .= '</div>’;2923 break;2924 }2925 }2926 }2927 if (is_array($library[‘sections’])) {2928 foreach ($library[‘sections’] as $section_file => $name) {2929 if (strlen($section_file) - strlen($file) == strrpos($section_file, $file)) {2930 $content .= ‘<div data-section="’ . esc_attr(ltrim(str_replace($library[‘sections_dir’][$section_file], '’, $section_file), ‘/’)) . '">’;2931 $content .= azh_get_file($section_file, $library[‘sections_uri’][$section_file]);2932 $content .= '</div>’;2933 break;2934 }2935 }2936 }2937 }2938 if (!empty($content)) {2939 $post_id = wp_insert_post(array(2940 ‘post_title’ => '’,2941 ‘post_type’ => 'page’,2942 ‘post_status’ => 'publish’,2943 ‘post_author’ => get_current_user_id(),2944 ‘post_content’ => $content,2945 ), true);2946 if (!is_wp_error($post_id)) {2947 azh_set_post_content($content, $post_id);2948 add_post_meta($post_id, 'azh’, 'azh’, true);2949 exit(wp_redirect(get_permalink($post_id)));2950 }2951 }2952 }2953}29542955add_filter('theme_page_templates’, 'azh_theme_page_templates’, 10, 4);29562957function azh_theme_page_templates($post_templates, $theme, $post, $post_type) {2958 $post_templates[‘azexo-html-template.php’] = esc_html__('AZEXO Canvas’, ‘azh’);2959 $post_templates[‘azexo-html-library.php’] = esc_html__('AZEXO Library’, ‘azh’);2960 return $post_templates;2961}29622963add_filter('template_include’, ‘azh_template_include’);29642965function azh_template_include($template) {2966 global $azh_current_post_stack;2967 if (is_object(get_queried_object()) && get_class(get_queried_object()) == ‘WP_Post’) {2968 $azh_current_post_stack = array(get_queried_object());2969 }2970 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘library’) {2971 return plugin_dir_path(__FILE__) . 'azexo-html-library.php’;2972 }2973 if (is_page()) {2974 $template_slug = get_page_template_slug();2975 if ($template_slug == ‘azexo-html-template.php’) {2976 $template = locate_template(‘azexo-html-template.php’);2977 if (!$template) {2978 $template = plugin_dir_path(__FILE__) . 'azexo-html-template.php’;2979 }2980 return $template;2981 }2982 if ($template_slug == ‘azexo-html-library.php’) {2983 $template = locate_template(‘azexo-html-library.php’);2984 if (!$template) {2985 $template = plugin_dir_path(__FILE__) . 'azexo-html-library.php’;2986 }2987 return $template;2988 }2989 } else {2990 if (is_singular() && get_post_type() == ‘azh_widget’) {2991 $template = locate_template(‘azh-template.php’);2992 if (!$template) {2993 $template = plugin_dir_path(__FILE__) . 'azh-template.php’;2994 }2995 return $template;2996 }2997 }2998 return $template;2999}30003001add_filter('post_class’, 'azh_post_class’, 100);30023003function azh_post_class($classes) {3004 if (is_page()) {3005 if (get_page_template_slug() == ‘azexo-html-template.php’) {3006 $classes = array(‘az-container’);3007 }3008 }3009 return $classes;3010}30113012function azh_filesystem() {3013 static $creds = false;30143015 require_once ABSPATH . '/wp-admin/includes/template.php’;3016 require_once ABSPATH . '/wp-admin/includes/file.php’;30173018 if ($creds === false) {3019 if (false === ( $creds = request_filesystem_credentials(admin_url()) )) {3020 exit();3021 }3022 }30233024 if (!WP_Filesystem($creds)) {3025 request_filesystem_credentials(admin_url(), '’, true);3026 exit();3027 }3028}30293030function azh_get_all_settings() {3031 static $all_settings = array();3032 if (!empty($all_settings)) {3033 return $all_settings;3034 }3035 $all_settings = get_option('azh-all-settings’, array());3036 $user = wp_get_current_user();3037 if (in_array('administrator’, (array) $user->roles) && WP_DEBUG || empty($all_settings)) {3038 azh_filesystem();3039 global $wp_filesystem;3040 $all_settings = array();3041 $dirs = apply_filters('azh_directory’, array_combine(array(get_template_directory() . ‘/azh’), array(get_template_directory_uri() . ‘/azh’)));3042 if (is_array($dirs)) {3043 foreach ($dirs as $dir => $uri) {3044 if (is_dir($dir)) {3045 $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST);3046 foreach ($iterator as $fileInfo) {3047 if ($fileInfo->isFile() && $fileInfo->getExtension() == ‘json’) {3048 $settings = $wp_filesystem->get_contents($fileInfo->getPathname());3049 if ($settings) {3050 $settings = json_decode($settings, true);3051 $all_settings[$fileInfo->getPath()] = $settings;3052 }3053 }3054 }3055 }3056 }3057 }3058 update_option('azh-all-settings’, $all_settings);3059 }3060 return apply_filters('azh-all-settings’, $all_settings);3061}30623063function azh_get_content_settings($content) {3064 $md5 = md5($content);3065 $content_settings = get_option('azh-content-settings’, array());3066 $user = wp_get_current_user();3067 if (in_array('administrator’, (array) $user->roles) || !isset($content_settings[$md5])) {3068 $pattern = get_shortcode_regex(array(‘azh_post’));3069 $content = preg_replace_callback(“/$pattern/i", 'do_shortcode_tag’, $content);3070 preg_match_all('/(data-section|data-element)=[\’”]([^\’”]+)[\’”]/i’, $content, $matches);3071 if (is_array($matches)) {3072 foreach ($matches[2] as $section) {3073 $dirs = apply_filters('azh_directory’, array_combine(array(get_template_directory() . ‘/azh’), array(get_template_directory_uri() . ‘/azh’)));3074 if (is_array($dirs)) {3075 foreach ($dirs as $dir => $uri) {3076 if (is_dir($dir)) {3077 if (file_exists($dir . ‘/’ . $section)) {3078 $folders = explode('/’, $section);3079 $subdir = '’;3080 foreach ($folders as $folder) {3081 $subdir = $subdir . ‘/’ . $folder;3082 if (!isset($content_settings[$md5][$dir . $subdir]) && is_dir($dir . $subdir)) {3083 if (file_exists($dir . $subdir . ‘/azh_settings.json’)) {3084 azh_filesystem();3085 global $wp_filesystem;3086 $settings = $wp_filesystem->get_contents($dir . $subdir . ‘/azh_settings.json’);3087 if ($settings) {3088 $settings = json_decode($settings, true);3089 $content_settings[$md5][$dir . $subdir] = $settings;3090 }3091 }3092 }3093 }3094 }3095 }3096 }3097 }3098 }3099 }3100 update_option('azh-content-settings’, $content_settings);3101 }31023103 return isset($content_settings[$md5]) ? $content_settings[$md5] : false;3104}31053106function azh_get_visible_widgets() {3107 global $wp_widget_factory;3108 $settings = array();3109 $widget_areas = wp_get_sidebars_widgets();3110 foreach ($widget_areas as $widget_area => $widgets) {3111 if (empty($widgets)) {3112 continue;3113 }31143115 if (!is_array($widgets)) {3116 continue;3117 }31183119 if (‘wp_inactive_widgets’ == $widget_area) {3120 continue;3121 }31223123 foreach ($widgets as $position => $widget_id) {3124 // Find the conditions for this widget.3125 if (preg_match('/^(.+?)-(\d+)$/’, $widget_id, $matches)) {3126 $id_base = $matches[1];3127 $widget_number = intval($matches[2]);3128 } else {3129 $id_base = $widget_id;3130 $widget_number = null;3131 }31323133 $wp_widget = null;3134 foreach ($wp_widget_factory->widgets as $widget_class => $widget_object) {3135 if ($widget_object->id_base == $id_base) {3136 $wp_widget = $widget_object;3137 }3138 }3139 if (!isset($settings[$id_base])) {3140 $settings[$id_base] = get_option(‘widget_’ . $id_base);3141 }31423143 // New multi widget (WP_Widget)3144 if (!is_null($widget_number)) {3145 //$settings[$id_base][$widget_number]3146 //$widget_areas[$widget_area][$position]3147 }3148 // Old single widget3149 else if (!empty($settings[$id_base])) {3150 //$widget_areas[$widget_area][$position]3151 }3152 }3153 }3154 return $settings;3155}31563157function azh_get_widgets_content() {3158 static $widgets_content = false;3159 if ($widgets_content === false) {3160 $widgets_content = '’;3161 $visible_widgets = azh_get_visible_widgets();3162 foreach ($visible_widgets as $id_base => $widgets) {3163 if ($id_base == ‘azh_widget’) {3164 foreach ($widgets as $i => $settings) {3165 if (isset($settings[‘post’]) && is_numeric($settings[‘post’])) {3166 $widget_post = get_post($settings[‘post’]);3167 $widgets_content .= azh_get_post_content($widget_post);3168 }3169 }3170 }3171 }3172 }3173 return $widgets_content;3174}31753176function azh_get_included_widgets_content($post_content) {3177 static $widgets_content = false;3178 if ($widgets_content === false) {3179 $widgets_content = '’;3180 preg_match_all(‘/’ . get_shortcode_regex(array(‘azh_post’)) . '/s’, $post_content, $matches);3181 if (!empty($matches)) {3182 foreach ($matches[3] as $atts) {3183 $atts = shortcode_parse_atts($atts);3184 if ($atts[‘id’] && is_numeric($atts[‘id’])) {3185 $widget_post = get_post($atts[‘id’]);3186 $widgets_content .= azh_get_post_content($widget_post);3187 }3188 }3189 }3190 }3191 return $widgets_content;3192}31933194function azh_get_post_settings($post = false) {3195 global $azh_content;3196 if ($azh_content) {3197 return azh_get_content_settings($azh_content);3198 } else {3199 if (!$post) {3200 $post = get_post();3201 }3202 if ($post) {3203 $post_content = azh_get_post_content($post);3204 if (empty($post_content)) {3205 return azh_get_content_settings(azh_get_widgets_content() . azh_get_included_widgets_content($post->post_content) . $post->post_content);3206 } else {3207 return azh_get_content_settings(azh_get_widgets_content() . azh_get_included_widgets_content($post_content) . $post_content);3208 }3209 } else {3210 return false;3211 }3212 }3213}32143215function azh_get_content_scripts($content) {3216 $cache = get_option('azh-get-content-scripts’, array());3217 $md5 = md5($content);3218 $user = wp_get_current_user();3219 if (in_array('administrator’, (array) $user->roles) && WP_DEBUG || !isset($cache[$md5])) {3220 $post_scripts = array(‘paths’ => array(), ‘css’ => array(), ‘js’ => array());3221 $pattern = get_shortcode_regex(array(‘azh_post’));3222 $content = preg_replace_callback(“/$pattern/i", 'do_shortcode_tag’, $content);3223 preg_match_all('/(data-section|data-element)=[\’”]([^\’”]+)[\’"]/i’, $content, $matches);3224 if (is_array($matches)) {3225 foreach ($matches[2] as $section_element) {3226 $dirs = apply_filters('azh_directory’, array_combine(array(get_template_directory() . ‘/azh’), array(get_template_directory_uri() . ‘/azh’)));3227 if (is_array($dirs)) {3228 foreach ($dirs as $dir => $uri) {3229 if (is_dir($dir)) {3230 if (file_exists($dir . ‘/’ . $section_element)) {3231 $post_scripts[‘paths’][$section_element] = $dir . ‘/’ . $section_element;3232 $folders = explode('/’, $section_element);3233 $subdir = '’;3234 foreach ($folders as $folder) {3235 $subdir = $subdir . ‘/’ . $folder;3236 if (is_dir($dir . $subdir)) {3237 if (file_exists($dir . $subdir . ‘/azh_settings.json’)) {3238 $iterator = new DirectoryIterator($dir . $subdir);3239 foreach ($iterator as $fileInfo) {3240 if ($fileInfo->isFile() && $fileInfo->getExtension() == ‘css’) {3241 $post_scripts[‘css’][$dir . $subdir . ‘/’ . $fileInfo->getFilename()] = $uri . $subdir . ‘/’ . $fileInfo->getFilename();3242 }3243 }3244 }3245 if (file_exists($dir . $subdir . ‘/azh_settings.json’)) {3246 $iterator = new DirectoryIterator($dir . $subdir);3247 foreach ($iterator as $fileInfo) {3248 if ($fileInfo->isFile() && $fileInfo->getExtension() == ‘js’) {3249 $post_scripts[‘js’][$dir . $subdir . ‘/’ . $fileInfo->getFilename()] = $uri . $subdir . ‘/’ . $fileInfo->getFilename();3250 }3251 }3252 }3253 }3254 }3255 }3256 }3257 }3258 }3259 }3260 }3261 $cache[$md5] = $post_scripts;3262 update_option('azh-get-content-scripts’, $cache);3263 }3264 $post_scripts = $cache[$md5];3265 $post_scripts = apply_filters('azh_get_content_scripts’, $post_scripts, $content);3266 return $post_scripts;3267}32683269function azh_get_post_scripts() {3270 global $azh_content;3271 if ($azh_content) {3272 return azh_get_content_scripts($azh_content);3273 } else {3274 $post = get_post();3275 if ($post) {3276 $post_content = azh_get_post_content($post);3277 if (empty($post_content)) {3278 return azh_get_content_scripts(azh_get_widgets_content() . azh_get_included_widgets_content($post->post_content) . $post->post_content);3279 } else {3280 return azh_get_content_scripts(azh_get_widgets_content() . azh_get_included_widgets_content($post_content) . $post_content);3281 }3282 } else {3283 return azh_get_content_scripts(azh_get_widgets_content());3284 }3285 }3286}32873288global $azh_current_post_stack;3289$azh_current_post_stack = array();3290add_action('the_post’, ‘azh_the_post’);32913292function azh_the_post($post) {3293 if (is_object($post) && get_class($post) == ‘WP_Post’) {3294 global $azh_current_post_stack;3295 $index = count($azh_current_post_stack);3296 while ($index) {3297 $index–;3298 if (isset($azh_current_post_stack[$index]->ID)) {3299 if ($azh_current_post_stack[$index]->ID == $post->ID) {3300 array_splice($azh_current_post_stack, $index);3301 }3302 }3303 }3304 $azh_current_post_stack[] = $post;3305 }3306}33073308function azh_get_earliest_current_post($post_type, $equal = true) {3309 global $azh_current_post_stack;3310 $post = null;3311 $index = 0;3312 $post_type = (array) $post_type;3313 while ($index < count($azh_current_post_stack)) {3314 if ($equal) {3315 if (in_array($azh_current_post_stack[$index]->post_type, $post_type)) {3316 $post = $azh_current_post_stack[$index];3317 break;3318 }3319 } else {3320 if (!in_array($azh_current_post_stack[$index]->post_type, $post_type)) {3321 $post = $azh_current_post_stack[$index];3322 break;3323 }3324 }3325 $index++;3326 }3327 if (is_null($post)) {3328 $post = apply_filters('azh_get_earliest_current_post’, $post, $post_type, $equal);3329 }3330 return $post;3331}33323333function azh_get_closest_current_post($post_type, $equal = true) {3334 global $azh_current_post_stack;3335 $post = null;3336 $index = count($azh_current_post_stack);3337 $post_type = (array) $post_type;3338 while ($index) {3339 $index–;3340 if ($equal) {3341 if (in_array($azh_current_post_stack[$index]->post_type, $post_type)) {3342 $post = $azh_current_post_stack[$index];3343 break;3344 }3345 } else {3346 if (!in_array($azh_current_post_stack[$index]->post_type, $post_type)) {3347 $post = $azh_current_post_stack[$index];3348 break;3349 }3350 }3351 }3352 if (is_null($post)) {3353 $post = apply_filters('azh_get_closest_current_post’, $post, $post_type, $equal);3354 }3355 return $post;3356}33573358function azh_is_current_post($id) {3359 global $azh_current_post_stack;3360 $current_post = reset($azh_current_post_stack);3361 return $current_post && is_object($current_post) && (is_single() || is_page()) && ($current_post->ID == $id);3362}33633364function azh_get_first_shortcode($content, $first_shortcode) {3365 preg_match_all(‘/’ . get_shortcode_regex() . '/s’, $content, $matches, PREG_SET_ORDER);3366 if (!empty($matches)) {3367 foreach ($matches as $shortcode) {3368 if ($first_shortcode === $shortcode[2]) {3369 $pos = strpos($content, $shortcode[0]);3370 if ($pos !== false)3371 return $shortcode[0];3372 }3373 }3374 }3375 return false;3376}33773378function azh_post_video_url() {3379 $embed = azh_get_first_shortcode(get_the_content(‘’), ‘embed’);3380 if ($embed) {3381 preg_match(‘/’ . get_shortcode_regex(array(‘embed’)) . '/s’, $embed, $matches);3382 return trim($matches[5]);3383 } else {3384 return trim(get_post_meta(get_the_ID(), '_video’, true));3385 }3386}33873388function azh_add_image_size($size) {3389 if (!has_image_size($size) && !in_array($size, array('thumbnail’, 'medium’, ‘large’))) {3390 $size_array = explode('x’, $size);3391 if (count($size_array) == 2) {3392 add_image_size($size, $size_array[0], $size_array[1], true);3393 }3394 }3395}33963397function azh_get_attachment_url($attachment_id, $size) {3398 azh_add_image_size($size);33993400 $metadata = wp_get_attachment_metadata($attachment_id);3401 if (is_array($metadata)) {3402 $regenerate = false;3403 $size_array = explode('x’, $size);3404 if (count($size_array) == 2) {3405 $regenerate = true;3406 if (isset($metadata[‘width’]) && isset($metadata[‘height’])) {3407 if ((intval($metadata[‘width’]) < intval($size_array[0])) && (intval($metadata[‘height’]) < intval($size_array[1]))) {3408 $regenerate = false;3409 }3410 } else {3411 $regenerate = false;3412 }3413 }3414 if ($regenerate && (!isset($metadata[‘sizes’]) || !isset($metadata[‘sizes’][$size]))) {3415 if (isset($metadata[‘sizes’]) && is_array($metadata[‘sizes’])) {3416 foreach ($metadata[‘sizes’] as $meta => $data) {3417 azh_add_image_size($meta);3418 }3419 }3420 require_once(ABSPATH . ‘wp-admin/includes/image.php’);3421 require_once(ABSPATH . ‘wp-admin/includes/post.php’);3422 wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, get_attached_file($attachment_id)));3423 $metadata = wp_get_attachment_metadata($attachment_id);3424 }3425 }3426 $image = wp_get_attachment_image_src($attachment_id, $size);3427 if (empty($image)) {3428 $image = wp_get_attachment_image_src($attachment_id, ‘full’);3429 }3430 return $image[0];3431}34323433function azh_get_post_gallery_urls($size) {3434 $gallery = get_post_gallery(get_the_ID(), false);3435 if (is_array($gallery)) {3436 if (isset($gallery[‘ids’])) {3437 $attachment_ids = explode(",", $gallery[‘ids’]);3438 $urls = array();3439 foreach ($attachment_ids as $attachment_id) {3440 $urls[] = azh_get_attachment_url($attachment_id, $size);3441 }3442 return $urls;3443 }3444 }3445 $attachment_ids = get_post_meta(get_the_ID(), '_gallery’, true);3446 if ($attachment_ids) {3447 $attachment_ids = explode(“,", $attachment_ids);3448 $urls = array();3449 foreach ($attachment_ids as $attachment_id) {3450 $urls[] = azh_get_attachment_url($attachment_id, $size);3451 }3452 return $urls;3453 }3454 $attachment_ids = get_children(array(‘post_parent’ => get_the_ID(), ‘fields’ => 'ids’, ‘post_status’ => 'inherit’, ‘post_type’ => 'attachment’, ‘post_mime_type’ => 'image’, ‘order’ => 'ASC’, ‘orderby’ => ‘menu_order ID’));3455 if (!empty($attachment_ids)) {3456 $urls = array();3457 foreach ($attachment_ids as $attachment_id) {3458 $urls[] = azh_get_attachment_url($attachment_id, $size);3459 }3460 return $urls;3461 }3462 if (is_array($gallery)) {3463 if (isset($gallery[‘src’]) && is_array($gallery[‘src’])) {3464 return $gallery[‘src’];3465 }3466 }3467 return array();3468}34693470add_action('widgets_init’, ‘azh_widgets_init’);34713472function azh_widgets_init() {3473 if (function_exists(‘register_sidebar’)) {3474 register_sidebar(array(‘name’ => esc_html__('AZEXO Canvas header’, ‘AZEXO’), ‘id’ => “azh_header", ‘before_widget’ => '<div id="%1$s” class="widget %2$s">’, ‘after_widget’ => '</div>’, ‘before_title’ => '’, ‘after_title’ => ‘’));3475 register_sidebar(array(‘name’ => esc_html__('AZEXO Canvas footer’, ‘AZEXO’), ‘id’ => “azh_footer", ‘before_widget’ => '<div id="%1$s” class="widget %2$s">’, ‘after_widget’ => '</div>’, ‘before_title’ => '’, ‘after_title’ => ‘’));3476 }3477}34783479add_filter('azh_settings_google_fonts’, 'azh_settings_google_fonts’, 10, 2);34803481function azh_settings_google_fonts($google_fonts, $settings) {3482 if (isset($settings[‘main-google-font’])) {3483 $google_fonts[] = $settings[‘main-google-font’];3484 }3485 if (isset($settings[‘menu-google-font’])) {3486 $google_fonts[] = $settings[‘menu-google-font’];3487 }3488 if (isset($settings[‘header-google-font’])) {3489 $google_fonts[] = $settings[‘header-google-font’];3490 }3491 return $google_fonts;3492}34933494function azh_get_google_fonts($azh_settings = false, $post = false) {3495 $settings = get_option(‘azh-settings’);34963497 $all_google_fonts = explode(“\n", $settings[‘google-fonts’] ? $settings[‘google-fonts’] : ‘’);34983499 $settings_google_fonts = apply_filters('azh_settings_google_fonts’, array(), $settings);3500 foreach ($settings_google_fonts as $font) {3501 $all_google_fonts[] = str_replace(' ', '+’, $font) . ':100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic’;3502 }3503 if ($post) {3504 $post_google_fonts = apply_filters('azh_post_google_fonts’, array(), $post);3505 foreach ($post_google_fonts as $font) {3506 $all_google_fonts[] = str_replace(' ', '+’, $font) . ':100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic’;3507 }3508 }35093510 if ($azh_settings && is_array($azh_settings)) {3511 foreach ($azh_settings as $dir_settings) {3512 if (isset($dir_settings[‘google-fonts’])) {3513 $dir_settings_google_fonts = explode(“\n", $dir_settings[‘google-fonts’]);3514 $all_google_fonts = array_merge($all_google_fonts, $dir_settings_google_fonts);3515 }3516 }3517 }3518 $google_fonts = array();3519 if (is_array($all_google_fonts)) {3520 $all_google_fonts = array_unique($all_google_fonts);3521 foreach ($all_google_fonts as $font_family) {3522 if (!empty($font_family)) {3523 $font = explode(':’, $font_family);3524 if (!isset($google_fonts[$font[0]])) {3525 $google_fonts[$font[0]] = array();3526 }3527 if (count($font) == 2) {3528 $weights = explode(',’, $font[1]);3529 foreach ($weights as $weight) {3530 if (!isset($google_fonts[$font[0]][$weight])) {3531 $google_fonts[$font[0]][$weight] = true;3532 }3533 }3534 }3535 }3536 }3537 }3538 return $google_fonts;3539}35403541function azh_get_google_fonts_url($azh_settings = false, $content = false, $post = false) {3542 global $azh_google_fonts, $azh_google_fonts_locale_subsets;3543 $fonts_url = false;3544 $google_fonts = azh_get_google_fonts($azh_settings, $post);3545 $font_families = array();3546 foreach ($google_fonts as $font_family => $weights) {3547 if (‘off’ !== esc_html__('on’, $font_family . ' font: on or off’, ‘azh’)) {3548 $font_families[] = $font_family . ‘:’ . implode(',’, array_keys($weights));3549 }3550 }3551 if ($content) {3552 $pattern = ‘/font-family: \’(' . implode('|’, $azh_google_fonts) . ')\’/’;3553 $fonts = array();3554 if (preg_match_all($pattern, $content, $matches)) {3555 foreach ($matches[1] as $match) {3556 $fonts[] = $match;3557 }3558 }3559 $fonts = array_unique($fonts);3560 foreach ($fonts as $font) {3561 $font_families[] = $font . ':100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic’;3562 }3563 }3564 if (!empty($font_families)) {3565 $subset = 'latin,latin-ext’;3566 if (isset($azh_google_fonts_locale_subsets[get_locale()])) {3567 $subset = $azh_google_fonts_locale_subsets[get_locale()];3568 }3569 $query_args = array(3570 ‘family’ => implode(urlencode(‘|’), $font_families),3571 ‘subset’ => $subset,3572 );3573 $fonts_url = add_query_arg($query_args, (is_ssl() ? ‘https’ : ‘http’) . ‘://fonts.googleapis.com/css’);3574 }3575 return $fonts_url;3576}35773578add_action('wp_ajax_azh_get_scripts_urls’, ‘azh_get_scripts_urls’);35793580function azh_get_scripts_urls() {3581 if (isset($_POST[‘content’])) {3582 $scripts = azh_get_content_scripts(stripslashes($_POST[‘content’]));3583 $fonts_url = azh_get_google_fonts_url(azh_get_content_settings(stripslashes($_POST[‘content’])));3584 if ($fonts_url) {3585 $scripts[‘css’][] = $fonts_url;3586 }3587 $scripts[‘css’] = array_merge($scripts[‘css’], azh_get_icons_fonts_urls(stripslashes($_POST[‘content’])));3588 print json_encode($scripts);3589 }3590 die();3591}35923593function azh_parse_form_field($field, &$fields) {3594 $name = trim($field->name);3595 $name = str_replace(array('[', ']'), '’, $name);3596 $fields[$name] = array(3597 ‘tag’ => $field->tag,3598 ‘label’ => $name,3599 ‘type’ => isset($field->type) ? $field->type : '’,3600 ‘options’ => array(),3601 );3602 if ($field->tag == ‘select’) {3603 $options = array();3604 foreach ($field->children() as $option) {3605 $options[$option->value] = $option->innertext;3606 }3607 $fields[$name][‘options’] = $options;3608 }3609}36103611function azh_get_form_fields_from_content($content) {3612 include_once(AZH_DIR . ‘simple_html_dom.php’ );3613 $fields = array();3614 $content = azh_replaces($content);3615 $content = azh_generate_ids($content);3616 $content = azh_remove_comments($content);3617 $html = str_get_html($content);3618 $fields = array();3619 if ($html) {3620 foreach ($html->find('[name]') as $field) {3621 azh_parse_form_field($field, $fields);3622 }3623 }3624 return $fields;3625}36263627function azh_get_forms_from_content($content) {3628 include_once(AZH_DIR . ‘simple_html_dom.php’ );3629 $forms = array();3630 $content = azh_replaces($content);3631 $content = azh_generate_ids($content);3632 $content = azh_remove_comments($content);3633 $html = str_get_html($content);3634 if ($html) {3635 foreach ($html->find(‘form’) as $form) {3636 $fields = array();3637 if (count($form->find('input[name="form_title”]')) > 0) {3638 $form_title = $form->find('input[name="form_title”]', 0);3639 foreach ($form->find('[name]') as $field) {3640 azh_parse_form_field($field, $fields);3641 }3642 $forms[$form_title->value] = $fields;3643 }3644 }3645 }3646 return $forms;3647}36483649function azh_get_forms_from_page($page) {3650 return array_merge_recursive(azh_get_forms_from_content(azh_get_post_content($page)), apply_filters('azh_get_forms_from_page’, array(), $page));3651}36523653function azh_get_forms_from_pages() {3654 $user_id = get_current_user_id();3655 if ($user_id) {3656 static $forms = array();3657 if (isset($forms[$user_id])) {3658 return $forms[$user_id];3659 }3660 $forms[$user_id] = array();3661 $pages = get_posts(array(3662 ‘post_type’ => 'page’,3663 ‘post_status’ => 'publish’,3664 ‘author’ => $user_id,3665 ‘ignore_sticky_posts’ => 1,3666 ‘no_found_rows’ => 1,3667 ‘posts_per_page’ => '-1’,3668 ‘meta_query’ => array(3669 array(3670 ‘key’ => 'azh’,3671 ‘value’ => 'azh’,3672 )3673 )3674 ));3675 if (!empty($pages)) {3676 foreach ($pages as $page) {3677 $forms[$user_id] = array_merge($forms[$user_id], azh_get_forms_from_page($page));3678 }3679 }3680 $azh_widgets = get_posts(array(3681 ‘post_type’ => 'azh_widget’,3682 ‘post_status’ => 'publish’,3683 ‘author’ => $user_id,3684 ‘ignore_sticky_posts’ => 1,3685 ‘no_found_rows’ => 1,3686 ‘posts_per_page’ => '-1’,3687 ));3688 if (!empty($azh_widgets)) {3689 foreach ($azh_widgets as $azh_widget) {3690 $forms[$user_id] = array_merge($forms[$user_id], azh_get_forms_from_page($azh_widget));3691 }3692 }3693 return $forms[$user_id];3694 }3695 return false;3696}36973698add_filter('wp_kses_allowed_html’, 'azh_kses_allowed_html’, 10, 2);36993700function azh_kses_allowed_html($allowedposttags, $context) {3701 if ($context == ‘post’) {3702 //if (isset($allowedposttags[‘form’])) {3703 $allowedposttags[‘form’][‘data-azh-form’] = 1;3704 //}3705 }3706 return $allowedposttags;3707}37083709add_shortcode('azh_home_url’, ‘azh_home_url’);37103711function azh_home_url($atts, $content = null, $tag = null) {3712 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {3713 return addslashes(azh_shortcode_restore($atts, $content, $tag));3714 } else {3715 return esc_url(home_url(isset($atts[‘path’]) ? $atts[‘path’] : ‘’));3716 }3717}37183719add_shortcode('azh_get_search_query’, ‘azh_get_search_query’);37203721function azh_get_search_query($atts, $content = null, $tag = null) {3722 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {3723 return addslashes(azh_shortcode_restore($atts, $content, $tag));3724 } else {3725 return get_search_query();3726 }3727}37283729function azh_form($atts, $content = null, $tag = null) {3730 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {3731 return addslashes(azh_shortcode_restore($atts, $content, $tag));3732 } else {3733 static $count = 0;3734 $nonce = wp_create_nonce('azh-form-nonce-' . $count) . ‘|’ . $count;3735 $count++;3736 $form_settings = $atts;3737 if (!empty($content)) {3738 //$form_settings[‘content’] = base64_decode($content);3739 $form_settings[‘content’] = $content;3740 }3741 if (!empty($atts[‘autoresponder_body_template’])) {3742 //$form_settings[‘autoresponder_body_template’] = base64_decode($atts[‘autoresponder_body_template’]);3743 }3744 delete_transient($nonce);3745 set_transient($nonce, $form_settings, HOUR_IN_SECONDS);3746 return $nonce;3747 }3748}37493750function azh_recursive_sanitize_text_field($array) {3751 foreach ($array as $key => &$value) {3752 if (is_array($value)) {3753 $value = azh_recursive_sanitize_text_field($value);3754 } else {3755 $value = wp_unslash(sanitize_text_field($value));3756 }3757 }3758 return $array;3759}37603761add_action('wp_ajax_nopriv_azh_process_form’, ‘azh_process_form’);3762add_action('wp_ajax_azh_process_form’, ‘azh_process_form’);37633764function azh_process_form() {3765 $response = '’;3766 $nonce = isset($_POST[‘nonce’]) ? sanitize_text_field($_POST[‘nonce’]) : 0;3767 $nonce = explode('|’, $nonce);3768 if (wp_verify_nonce($nonce[0], 'azh-form-nonce-' . $nonce[1])) {3769 unset($_POST[‘action’]);3770 unset($_POST[‘nonce’]);3771 $form_settings = get_transient(implode('|’, $nonce));37723773 $files = array();3774 if (!empty($_FILES)) {3775 if (!function_exists(‘wp_handle_upload’)) {3776 require_once( ABSPATH . ‘wp-admin/includes/file.php’ );3777 }3778 foreach ($_FILES as $name => $file) {3779 $attachments = array();3780 if (is_array($file[‘name’])) {3781 foreach ($file[‘name’] as $key => $value) {3782 if ($file[‘name’][$key]) {3783 $attachments[] = array(3784 ‘name’ => $file[‘name’][$key],3785 ‘type’ => $file[‘type’][$key],3786 ‘tmp_name’ => $file[‘tmp_name’][$key],3787 ‘error’ => $file[‘error’][$key],3788 ‘size’ => $file[‘size’][$key]3789 );3790 }3791 }3792 } else {3793 $attachments[] = $file;3794 }3795 $files[$name] = array();3796 foreach ($attachments as $attachment) {3797 $upload = wp_handle_upload($attachment, array(‘test_form’ => false));3798 if ($upload && !isset($upload[‘error’])) {3799 $files[$name][] = $upload[‘file’];3800 }3801 }3802 }3803 }38043805 $response = array(‘message’ => esc_html__('Form submitted successfully’, ‘azh’), ‘status’ => ‘success’);3806 $response = apply_filters('azh_process_form’, $response, $files, $form_settings);38073808 $settings = get_option(‘azh-forms-settings’);38093810 if (isset($settings[‘form-submission-notification’]) && $settings[‘form-submission-notification’] == ‘cron’) {3811 wp_schedule_single_event(time() + 5, 'azh_process_form_cron_event’, array(3812 ‘post_id’ => (int) $_POST[‘post_id’],3813 ‘fields’ => azh_recursive_sanitize_text_field($_POST),3814 ‘files’ => $files,3815 ‘form_settings’ => $form_settings,3816 ));3817 } else {3818 do_action('azh_process_form_cron_event’, (int) $_POST[‘post_id’], azh_recursive_sanitize_text_field($_POST), $files, $form_settings);3819 }38203821 if (isset($_POST[‘form_title’])) {3822 if (shortcode_exists(‘cfdb-save-form-post’)) {3823 do_shortcode('[cfdb-save-form-post]');3824 }3825 }38263827 if (!empty($form_settings[‘success_redirect’])) {3828 $response[‘status’] = 'redirect’;3829 $response[‘url’] = $form_settings[‘success_redirect’];3830 }3831 if (!empty($form_settings[‘success’])) {3832 $response[‘message’] = $form_settings[‘success’];3833 }3834 } else {3835 $response = array(‘message’ => esc_html__('Does not permitted’, ‘azh’), ‘status’ => ‘error’);3836 }3837 if (isset($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) === ‘xmlhttprequest’) {3838 print json_encode($response);3839 wp_die();3840 } else {3841 switch ($response[‘status’]) {3842 case ‘redirect’ :3843 if (empty($response[‘url’])) {3844 exit(wp_redirect(get_permalink((int) $_POST[‘post_id’])));3845 } else {3846 exit(wp_redirect($response[‘url’]));3847 }3848 break;3849 case ‘success’ :3850 if (empty($_POST[‘success-redirect’])) {3851 exit(wp_redirect(get_permalink((int) $_POST[‘post_id’])));3852 } else {3853 exit(wp_redirect($_POST[‘success-redirect’]));3854 }3855 break;3856 case ‘error’ :3857 if (empty($_POST[‘error-redirect’])) {3858 exit(wp_redirect(get_permalink((int) $_POST[‘post_id’])));3859 } else {3860 exit(wp_redirect($_POST[‘error-redirect’]));3861 }3862 break;3863 default:3864 exit(wp_redirect(get_permalink((int) $_POST[‘post_id’])));3865 }3866 }3867}38683869function azh_tokens($string, $fields) {3870 $string = preg_replace_callback('#{([^}]+)}#’, function($m) use ($fields) {3871 if (isset($fields[strtolower($m[1])])) { // If it exists in our array 3872 return $fields[strtolower($m[1])]; // Then replace it from our array3873 } else {3874 return $m[0]; // Otherwise return the whole match (basically we won’t change it)3875 }3876 }, $string);3877 return $string;3878}38793880add_filter('wp_mail_from_name’, ‘azh_wp_mail_from_name’);38813882function azh_wp_mail_from_name($from_name) {3883 return get_bloginfo(‘name’);3884}38853886function azh_is_base64_encoded($data) {3887 if (preg_match('%^[a-zA-Z0-9/+]*={0,2}$%’, $data)) {3888 return TRUE;3889 } else {3890 return FALSE;3891 }3892}38933894function azh_mail($email, $from, $subject, $message, $fields, $files) {3895 if (azh_is_base64_encoded($message)) {3896 $message = base64_decode($message);3897 }3898 $subject = azh_tokens($subject, $fields);3899 $message = azh_tokens($message, $fields);39003901 $attachments = array();3902 foreach ($files as $name => $file) {3903 $attachments = array_merge($attachments, $file);3904 if (count($file) === 1) {3905 $message = str_replace(‘{’ . $name . '}’, basename($file[0]), $message);3906 }3907 }39083909 $headers = array();3910 $headers[] = ‘from: ' . $from;3911 wp_mail($email, $subject, $message, $headers, $attachments);3912}39133914add_action(‘azh_process_form_cron_event’, ‘azh_form_notification’, 10, 4);39153916function azh_form_notification($post_id, $fields, $files, $form_settings) {3917 $form_title = false;3918 if (isset($fields[‘form_title’])) {3919 $form_title = $fields[‘form_title’];3920 }3921 $email = false;3922 $subject = false;3923 $message = false;3924 if ($form_settings && $form_settings[‘to_email’]) {3925 $email = $form_settings[‘to_email’];3926 $subject = isset($form_settings[‘subject_template’]) ? $form_settings[‘subject_template’] : ‘’;3927 $message = isset($form_settings[‘content’]) ? $form_settings[‘content’] : ‘’;3928 } else {3929 $settings = get_option(‘azh-forms-settings’);3930 if ($settings) {3931 if (!empty($form_title) && isset($settings[$form_title . '-to’])) {3932 $email = $settings[$form_title . '-to’];3933 $subject = isset($settings[$form_title . '-subject-template’]) ? $settings[$form_title . '-subject-template’] : ‘’;3934 $message = isset($settings[$form_title . '-body-template’]) ? $settings[$form_title . '-body-template’] : '’;3935 }3936 }3937 }3938 if ($form_title) {3939 //$forms = azh_get_forms_from_pages();3940 //$fields = $forms[$form_title]; 3941 }3942 if (!empty($email)) {3943 azh_mail($email, get_bloginfo(‘admin_email’), $subject, $message, $fields, $files);3944 }3945 if (!empty($form_settings[‘autoresponder_to_email’]) && !empty($form_settings[‘autoresponder_subject_template’]) && !empty($form_settings[‘autoresponder_body_template’])) {3946 $email = $form_settings[‘autoresponder_to_email’];3947 $from = $form_settings[‘autoresponder_from_email’];3948 $subject = $form_settings[‘autoresponder_subject_template’];3949 $message = $form_settings[‘autoresponder_body_template’];39503951 $email = azh_tokens($email, $fields);39523953 if (empty($from)) {3954 $from = get_bloginfo(‘admin_email’);3955 }39563957 azh_mail($email, $from, $subject, $message, $fields, $files);3958 }3959}39603961add_action('wp_ajax_azh_get_posts’, ‘azh_get_posts’);3962add_action('wp_ajax_nopriv_azh_get_posts’, ‘azh_get_posts’);39633964function azh_get_posts() {3965 if (isset($_POST[‘ids’]) && is_array($_POST[‘ids’])) {3966 $user_id = get_current_user_id();3967 if ($user_id) {3968 $posts = array();3969 foreach ($_POST[‘ids’] as $id) {3970 if (is_numeric($id)) {3971 $post = get_post($id);3972 if ($post) {3973 $meta = get_post_meta($id);3974 foreach ($meta as &$v) {3975 $v = reset($v);3976 }3977 $posts[$id] = array(3978 ‘post_thumbnail’ => wp_get_attachment_url(get_post_thumbnail_id($id)),3979 ‘post’ => $post,3980 ‘meta’ => $meta,3981 );3982 }3983 }3984 }3985 print json_encode($posts);3986 }3987 }3988 wp_die();3989}39903991function azh_get_element_width($element_file) {3992 $all_settings = azh_get_all_settings();3993 $element_width = '100%’;3994 foreach ($all_settings as $dir => $settings) {3995 if (strpos($element_file, $dir) == 0) {3996 if (isset($settings[‘elements-widths’])) {3997 foreach ($settings[‘elements-widths’] as $element => $width) {3998 if ($element_file == $dir . ‘/’ . $element) {3999 $element_width = $width;4000 break;4001 }4002 }4003 }4004 }4005 }4006 return $element_width;4007}40084009function azh_get_page_template($files) {4010 $content = '’;4011 $library = azh_get_library();4012 $files = explode('|’, $files);4013 foreach ($files as $file) {4014 if (is_array($library[‘elements’])) {4015 foreach ($library[‘elements’] as $element_file => $name) {4016 if (strlen($element_file) - strlen($file) == strrpos($element_file, $file)) {4017 $content .= ‘<div data-element="’ . esc_attr(ltrim(str_replace($library[‘elements_dir’][$element_file], '’, $element_file), ‘/’)) . '” style="margin: auto; max-width: ' . azh_get_element_width($element_file) . '">’;4018 $content .= azh_get_file($element_file, $library[‘elements_uri’][$element_file]);4019 $content .= '</div>’;4020 break;4021 }4022 }4023 }4024 if (is_array($library[‘sections’])) {4025 foreach ($library[‘sections’] as $section_file => $name) {4026 if (strlen($section_file) - strlen($file) == strrpos($section_file, $file)) {4027 $content .= ‘<div data-section="’ . esc_attr(ltrim(str_replace($library[‘sections_dir’][$section_file], '’, $section_file), ‘/’)) . '">’;4028 $content .= azh_get_file($section_file, $library[‘sections_uri’][$section_file]);4029 $content .= '</div>’;4030 break;4031 }4032 }4033 }4034 }4035 return $content;4036}40374038add_action('wp_ajax_azh_restore_revision’, ‘azh_restore_revision’);40394040function azh_restore_revision() {4041 if (isset($_POST[‘post_id’]) && is_numeric((int) $_POST[‘post_id’])) {4042 $user_id = get_current_user_id();4043 if ($user_id) {4044 $post_id = wp_restore_post_revision((int) $_POST[‘post_id’]);4045 }4046 }4047}40484049add_action('wp_ajax_azh_load_post’, ‘azh_load_post’);40504051function azh_load_post() {4052 if (isset($_POST[‘post_id’]) && is_numeric((int) $_POST[‘post_id’])) {4053 $user_id = get_current_user_id();4054 if ($user_id) {4055 $content = '’;4056 $settings = array();4057 $scripts = array();4058 if (get_post_meta((int) $_POST[‘post_id’], 'azh’, true)) {4059 $content = get_post_meta((int) $_POST[‘post_id’], '_azh_content’, true);4060 $scripts = azh_get_content_scripts($content);406140624063 global $post, $wp_query;4064 $original = $post;4065 $post = get_post((int) $_POST[‘post_id’]);4066 setup_postdata($post);4067 $content = do_shortcode($content);4068 $wp_query->post = $original;4069 wp_reset_postdata();40704071 $settings = get_post_meta((int) $_POST[‘post_id’], '_azh_settings’, true);4072 }4073 //wp_print_styles();4074 //wp_print_scripts();4075 print json_encode(array(4076 ‘content’ => $content,4077 ‘settings’ => $settings,4078 ‘scripts’ => $scripts,4079 ));4080 }4081 }4082 wp_die();4083}40844085function azh_create_post($post) {4086 $user_id = get_current_user_id();4087 if ($user_id) {4088 $new_post_id = wp_insert_post(array(4089 ‘post_title’ => sanitize_text_field($post[‘post_title’]),4090 ‘post_status’ => (isset($post[‘post_status’]) ? sanitize_text_field($post[‘post_status’]) : ‘publish’),4091 ‘post_type’ => sanitize_text_field($post[‘post_type’]),4092 ‘post_author’ => $user_id4093 ));4094 if (isset($post[‘general_element’])) {4095 $general_element = sanitize_text_field($post[‘general_element’]);40964097 $default = ‘<div data-section="element"><div data-cloneable=""><div data-element="general/’ . $general_element . '">’;4098 $library = azh_get_library();4099 if (is_array($library[‘elements’]) && is_array($library[‘general_elements’])) {4100 foreach ($library[‘general_elements’] as $element_file => $name) {4101 if ($name == $general_element) {4102 if (isset($library[‘elements’][$element_file])) {4103 $default .= azh_get_file($element_file, $library[‘elements_uri’][$element_file], false);4104 }4105 }4106 }4107 }4108 $default .= '</div></div></div>’;4109 azh_set_post_content($default, $new_post_id);4110 update_post_meta($new_post_id, 'azh’, ‘azh’);4111 }4112 if (isset($post[‘element’])) {4113 $element = sanitize_text_field($post[‘element’]);41144115 $default = ‘<div data-section="element"><div data-cloneable=""><div data-element="’ . $element . '">’;4116 $library = azh_get_library();4117 if (is_array($library[‘elements’])) {4118 foreach ($library[‘elements’] as $element_file => $name) {4119 $path = ltrim(str_replace($library[‘elements_dir’][$element_file], '’, $element_file), ‘/’);4120 if ($path == $element) {4121 if (isset($library[‘elements’][$element_file])) {4122 $default .= azh_get_file($element_file, $library[‘elements_uri’][$element_file], false);4123 }4124 }4125 }4126 }4127 $default .= '</div></div></div>’;4128 azh_set_post_content($default, $new_post_id);4129 update_post_meta($new_post_id, 'azh’, ‘azh’);4130 }4131 return $new_post_id;4132 }4133}41344135add_action('wp_ajax_azh_add_post’, ‘azh_add_post’);41364137function azh_add_post() {4138 if (isset($_POST[‘post_title’]) && isset($_POST[‘post_type’])) {4139 print azh_create_post($_POST);4140 }4141 wp_die();4142}41434144function azh_clone_post($post) {4145 $post_array = (array) $post;4146 unset($post_array[‘ID’]);4147 $new_post_id = wp_insert_post($post_array);4148 $data = get_post_meta($post->ID);4149 foreach ($data as $key => $values) {4150 foreach ($values as $value) {4151 add_post_meta($new_post_id, $key, maybe_unserialize($value));4152 }4153 }4154 return $new_post_id;4155}41564157add_action('wp_ajax_azh_duplicate_post’, ‘azh_duplicate_post’);41584159function azh_duplicate_post() {4160 if (isset($_POST[‘post_id’]) && is_numeric($_POST[‘post_id’])) {4161 $user_id = get_current_user_id();4162 if ($user_id) {4163 $post = get_post((int) $_POST[‘post_id’]);4164 if (current_user_can('edit_post’, $post->ID)) {4165 print azh_clone_post($post);4166 }4167 }4168 }4169 wp_die();4170}41714172add_action('wp_ajax_azh_remove_post’, ‘azh_remove_post’);41734174function azh_remove_post() {4175 if (isset($_POST[‘post_id’]) && is_numeric($_POST[‘post_id’])) {4176 $user_id = get_current_user_id();4177 if ($user_id) {4178 $post = get_post((int) $_POST[‘post_id’]);4179 if (current_user_can('edit_post’, $post->ID)) {4180 wp_delete_post($post->ID);4181 }4182 }4183 }4184 wp_die();4185}41864187add_action('wp_ajax_azh_update_post’, ‘azh_update_post’);4188add_action('wp_ajax_nopriv_azh_update_post’, ‘azh_update_post’);41894190function azh_update_post() {4191 if (isset($_POST[‘post’]) && isset($_POST[‘post’][‘ID’]) && is_numeric($_POST[‘post’][‘ID’])) {4192 $user_id = get_current_user_id();4193 if ($user_id) {4194 $post = get_post((int) $_POST[‘post’][‘ID’]);4195 if (current_user_can('edit_post’, $post->ID)) {4196 if (count($_POST[‘post’]) > 1) {4197 if (isset($_POST[‘post’][‘post_content’])) {4198 $post_content = $_POST[‘post’][‘post_content’];4199 }4200 $post_data = azh_recursive_sanitize_text_field($_POST[‘post’]);4201 if (isset($_POST[‘post’][‘post_content’])) {4202 $post_data[‘post_content’] = $post_content;4203 }4204 wp_update_post($post_data);4205 }4206 if (isset($_POST[‘meta’]) && is_array($_POST[‘meta’])) {4207 $post_meta = azh_recursive_sanitize_text_field($_POST[‘meta’]);4208 foreach ($post_meta as $key => $value) {4209 update_post_meta((int) $_POST[‘post’][‘ID’], $key, $value);4210 }4211 }4212 }4213 }4214 }4215 wp_die();4216}42174218function azh_dec($encoded) {4219 $decoded = "";4220 $strlen = strlen($encoded);4221 for ($i = 0; $i < strlen($encoded); $i++) {4222 $b = ord($encoded[$i]);4223 $a = $b ^ 7;4224 $decoded .= chr($a);4225 }4226 return $decoded;4227}42284229add_shortcode('azh_sections_library’, ‘azh_sections_library’);42304231function azh_sections_library($atts, $content = null, $tag = null) {4232 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {4233 return azh_shortcode_restore($atts, $content, $tag);4234 } else {4235 $sections_library = get_option('azh-sections-library-shortcode’, array());4236 if (empty($sections_library)) {4237 ob_start();4238 include(AZH_DIR . ‘shortcodes/azh_sections_library.php’ );4239 $sections_library = ob_get_clean();4240 update_option('azh-sections-library-shortcode’, $sections_library);4241 }4242 azh_enqueue_icons($sections_library);4243 return $sections_library;4244 }4245}42464247add_shortcode('azh_elements_library’, ‘azh_elements_library’);42484249function azh_elements_library($atts, $content = null, $tag = null) {4250 if (isset($_GET[‘azh’]) && $_GET[‘azh’] == ‘customize’) {4251 return azh_shortcode_restore($atts, $content, $tag);4252 } else {4253 $elements_library = get_option('azh-elements-library-shortcode’, array());4254 if (empty($elements_library)) {4255 ob_start();4256 include(AZH_DIR . ‘shortcodes/azh_elements_library.php’ );4257 $elements_library = ob_get_clean();4258 update_option('azh-elements-library-shortcode’, $elements_library);4259 }4260 azh_enqueue_icons($elements_library);4261 return $elements_library;4262 }4263}

CVE: Latest News

CVE-2023-50976: Transactions API Authorization by oleiman · Pull Request #14969 · redpanda-data/redpanda
CVE-2023-6905
CVE-2023-6903
CVE-2023-6904
CVE-2023-3907