/** * Called when builder is rendered */ public function enqueue_static() { $shortcode_instance = fw_ext('shortcodes')->get_shortcode('section'); wp_enqueue_style($this->get_builder_type() . '_item_type_' . $this->get_type(), $shortcode_instance->locate_URI('/includes/page-builder-section-item/static/css/styles.css'), array(), fw()->theme->manifest->get_version()); wp_enqueue_script($this->get_builder_type() . '_item_type_' . $this->get_type(), $shortcode_instance->locate_URI('/includes/page-builder-section-item/static/js/scripts.js'), array('fw-events', 'underscore'), fw()->theme->manifest->get_version(), true); wp_localize_script($this->get_builder_type() . '_item_type_' . $this->get_type(), str_replace('-', '_', $this->get_builder_type() . '_item_type_' . $this->get_type() . '_data'), $this->get_item_data()); }
/** * Call add_post_type_support('{post-type}', 'fw-page-builder') * for post types checked on Page Builder Settings page. */ function _action_fw_ext_page_builder_add_support() { $feature_name = fw_ext('page-builder')->get_supports_feature_name(); foreach (array_keys(fw_get_db_ext_settings_option('page-builder', 'post_types')) as $slug) { add_post_type_support($slug, $feature_name); } }
/** * {@inheritdoc} */ public function execute(array $args, array $state = array()) { if (!isset($args['dir'])) { return new WP_Error('no_dir', __('Dir not specified', 'fw')); } $dir = $args['dir']; if (file_exists($dir)) { if (!fw_ext_backups_rmdir_recursive($dir)) { return new WP_Error('rmdir_fail', __('Cannot remove directory', 'fw') . ': ' . $dir); } } if (!mkdir($dir, 0777, true)) { return new WP_Error('mkdir_fail', __('Cannot create directory', 'fw') . ': ' . $dir); } $backups_dir = fw_ext('backups')->get_backups_dir(); if (!file_exists("{$backups_dir}/index.php")) { $contents = implode("\n", array('<?php', 'header(\'HTTP/1.0 403 Forbidden\');', 'die(\'<h1>Forbidden</h1>\');')); if (@file_put_contents("{$backups_dir}/index.php", $contents) === false) { return new WP_Error('index_create_fail', sprintf(__('Cannot create file: %s', 'fw'), "{$backups_dir}/index.php")); } } if (!file_exists("{$backups_dir}/.htaccess")) { $contents = implode("\n", array('Deny from all', '<IfModule mod_rewrite.c>', ' RewriteEngine On', ' RewriteRule . - [R=404,L]', '</IfModule>')); if (@file_put_contents("{$backups_dir}/.htaccess", $contents) === false) { return new WP_Error('htaccess_create_fail', sprintf(__('Cannot create file: %s', 'fw'), "{$backups_dir}/htaccess")); } } return true; }
public function prepare_items() { if (!is_null($this->total_items)) { return; } $this->total_items = count($this->_archives); $this->set_pagination_args(array('total_items' => $this->total_items, 'per_page' => $this->items_pre_page)); /** * @var FW_Extension_Backups $backups */ $backups = fw_ext('backups'); /** * Prepare items for output */ foreach ($this->_archives as $filename => $archive) { $time = get_date_from_gmt(gmdate('Y-m-d H:i:s', $archive['time']), get_option('date_format') . ' ' . get_option('time_format')); $filename_hash = md5($filename); $details = array(); $details[] = $archive['full'] ? __('Full Backup', 'fw') : __('Content Backup', 'fw'); if (function_exists('fw_human_bytes')) { $details[] = fw_human_bytes(filesize($archive['path'])); } $details[] = fw_html_tag('a', array('href' => $backups->get_download_link($filename), 'target' => '_blank', 'id' => 'download-' . $filename_hash, 'data-download-file' => $filename), esc_html__('Download', 'fw')); $details[] = fw_html_tag('a', array('href' => '#', 'onclick' => 'return false;', 'id' => 'delete-' . $filename_hash, 'data-delete-file' => $filename, 'data-confirm' => __("Warning! \n" . "You are about to delete a backup, it will be lost forever. \n" . "Are you sure?", 'fw')), esc_html__('Delete', 'fw')); $this->items[] = array('cb' => fw_html_tag('input', array('type' => 'radio', 'name' => 'archive', 'value' => $filename, 'id' => 'archive-' . $filename_hash)), 'details' => '<div>' . $time . '</div>' . '<div>' . implode(' | ', $details) . '</div>'); } }
/** * @internal * * @param array $option * @param array|null|string $input_value * * @return array|bool|int|string */ protected function _get_value_from_input($option, $input_value) { if (is_array($input_value) && !empty($input_value)) { fw_ext('forms')->set_db_settings_option('recaptcha-keys', $input_value); } return fw_ext('forms')->get_db_settings_option('recaptcha-keys', array()); }
/** * @internal * * @param array $option * @param array|null|string $input_value * * @return array|bool|int|string */ protected function _get_value_from_input($option, $input_value) { if (is_array($input_value) && !empty($input_value)) { fw_ext('mailer')->set_db_settings_option(null, fw_get_options_values_from_input($this->get_inner_options(), $input_value)); } return fw_ext('mailer')->get_db_settings_option(); }
public function enqueue_static() { wp_enqueue_style('fw-builder-' . $this->get_builder_type() . '-item-' . $this->get_type(), $this->get_uri('/static/css/styles.css')); wp_enqueue_script('fw-builder-' . $this->get_builder_type() . '-item-' . $this->get_type(), $this->get_uri('/static/js/scripts.js'), array('fw-events'), false, true); wp_localize_script('fw-builder-' . $this->get_builder_type() . '-item-' . $this->get_type(), 'fw_form_builder_item_type_' . $this->get_type(), array('options' => $this->get_options(), 'l10n' => array('item_title' => __('Number', 'fw'), 'label' => __('Label', 'fw'), 'edit_label' => __('Edit Label', 'fw'), 'toggle_required' => __('Toggle mandatory field', 'fw'), 'edit' => __('Edit', 'fw'), 'delete' => __('Delete', 'fw')), 'defaults' => array('type' => $this->get_type(), 'width' => fw_ext('forms')->get_config('items/width'), 'options' => fw_get_options_values_from_input($this->get_options(), array())))); fw()->backend->enqueue_options_static($this->get_options()); }
public function _enqueue($data) { $uri = fw_ext('builder')->get_uri('/includes/option-types/builder/includes/templates/components/' . $this->get_type()); $version = fw_ext('builder')->manifest->get_version(); wp_enqueue_style('fw-option-builder-templates-' . $this->get_type(), $uri . '/styles.css', array('fw-option-builder-templates'), $version); wp_enqueue_script('fw-option-builder-templates-' . $this->get_type(), $uri . '/scripts.js', array('fw-option-builder-templates'), $version, true); wp_localize_script('fw-option-builder-templates-' . $this->get_type(), '_fw_option_type_builder_templates_' . $this->get_type(), array('l10n' => array('template_name' => __('Template Name', 'fw'), 'save_template' => __('Save Builder Template', 'fw')))); }
protected function get_thumbnails_data() { /** * @var FW_Shortcode $cf_shortcode */ $cf_shortcode = fw_ext('shortcodes')->get_shortcode('contact_form'); $cf_thumbnail = array(array('tab' => __('Content Elements', 'fw'), 'title' => __('Contact form', 'fw'), 'description' => __('Add a Contact Form', 'fw'), 'image' => $cf_shortcode->locate_URI('/static/img/page_builder.png'))); return $cf_thumbnail; }
/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title'] . apply_filters('fw_language_switcher_widget_title', $instance['title']) . $args['after_title']; } fw_ext('translation')->frontend_language_switcher(); echo $args['after_widget']; }
/** * {@inheritdoc} * @param array $args * * uploads_dir - path to exported uploads dir (not the actual WP uploads dir! that remains untouched) */ public function execute(array $args, array $state = array()) { $backups = fw_ext('backups'); if (empty($args['uploads_dir'])) { return new WP_Error('no_uploads_dir', __('Uploads dir not specified', 'fw')); } else { $args['uploads_dir'] = fw_fix_path($args['uploads_dir']); if (!file_exists($args['uploads_dir'])) { /** * The uploads directory was not exported, nothing to do. */ return true; } } if (empty($state)) { $state = array('attachment_id' => 0); } /** * @var WPDB $wpdb */ global $wpdb; $sql = implode(array("SELECT * FROM {$wpdb->posts}", "WHERE post_type = 'attachment' AND post_mime_type LIKE %s AND ID > %d", "ORDER BY ID", "LIMIT 7"), " \n"); $wp_uploads_dir = wp_upload_dir(); $wp_uploads_dir_length = mb_strlen($wp_uploads_dir['basedir']); $started_time = time(); $timeout = $backups->get_timeout() - 7; while (time() - $started_time < $timeout) { $attachments = $wpdb->get_results($wpdb->prepare($sql, $wpdb->esc_like('image/') . '%', $state['attachment_id']), ARRAY_A); if (empty($attachments)) { return true; } foreach ($attachments as $attachment) { if (($meta = wp_get_attachment_metadata($attachment['ID'])) && isset($meta['sizes']) && is_array($meta['sizes'])) { $attachment_path = get_attached_file($attachment['ID']); $filename_length = mb_strlen(basename($attachment_path)); foreach ($meta['sizes'] as $size => $sizeinfo) { // replace wp_uploads_dir path $file_path = $args['uploads_dir'] . mb_substr($attachment_path, $wp_uploads_dir_length); // replace file name with resize name $file_path = mb_substr($file_path, 0, -$filename_length) . $sizeinfo['file']; if (file_exists($file_path)) { @unlink($file_path); } } } if (is_array($backup_sizes = get_post_meta($attachment['ID'], '_wp_attachment_backup_sizes', true))) { foreach ($backup_sizes as $size) { $del_file = path_join(dirname($meta['file']), $size['file']); @unlink(path_join($args['uploads_dir'], $del_file)); } } } $state['attachment_id'] = $attachment['ID']; } return $state; }
/** * @internal */ public function _init() { if (is_admin() && fw_ext('page-builder')) { require $this->get_declared_path('/includes/page-builder-column-item/class-page-builder-column-item.php'); /** * Note: A file is required from framework/extensions/shortcodes/includes/shortcode-template-components.php * because the shortcodes don't have includes/ functionality */ } }
protected function get_thumbnails_data() { $column_shortcode = fw_ext('shortcodes')->get_shortcode('column'); $builder_widths = fw_ext_builder_get_item_width($this->get_builder_type()); $column_thumbnails = array(); foreach ($builder_widths as $key => $value) { $column_thumbnails[$key] = array('tab' => __('Layout Elements', 'fw'), 'title' => apply_filters('fw_ext_shortcodes_column_title', $value['title'], $key), 'description' => apply_filters('fw_ext_shortcodes_column_description', sprintf(__('Add a %s column', 'fw'), $value['title']), $key), 'image' => $column_shortcode->locate_URI("/includes/page-builder-column-item/static/img/{$key}.png"), 'data' => array('width' => $key)); } return apply_filters('fw_shortcode_column_thumbnails_data', $column_thumbnails); }
public function render($data) { $form = $data['form']; if (empty($form)) { return ''; } $form_id = $data['id']; $this->set_db_data($this->get_name() . '-' . $form_id, $data); return $this->render_view('form', array('form_id' => $form_id, 'form_html' => fw_ext('forms')->render_form($form_id, $form, $this->get_name(), $submit_button = $this->render_view('submit', array('submit_button_text' => empty($data['submit_button_text']) ? __('Submit', 'fw') : $data['submit_button_text'], 'form_id' => $form_id))))); }
/** * Before 1.0.1 data was saved in a single wp option where all extensions save their data * https://github.com/ThemeFuse/Unyson-Forms-Extension/commit/8192e81ca04fd06b215fe938087b2d880d7d42cc?diff=unified#diff-ec141aa42759cc0c7735796a2c061f60R30 * * @param string $form_id * @return array|null Deleted data */ private static function delete_data_from_old_location($form_id) { /** * @var FW_Extension_Contact_Forms $contact_forms_extension */ $contact_forms_extension = fw_ext('contact-forms'); $data_key = $contact_forms_extension->get_name() . '-' . $form_id; if ($data = $contact_forms_extension->get_db_data($data_key)) { $contact_forms_extension->set_db_data($data_key, null); } return $data; }
/** * @return int * @since 2.0.3 */ function fw_ext_backups_demo_count() { static $access_key = null; if (is_null($access_key)) { $access_key = new FW_Access_Key('fw:ext:backups-demo:helper:count'); } /** * @var FW_Extension_Backups_Demo $extension */ $extension = fw_ext('backups-demo'); return $extension->_get_demos_count($access_key); }
function fw_ext_seo_sitemap_get_taxonomies_options() { $taxonomies = fw_ext('seo-sitemap')->config_taxonomies(); $prefix = fw()->extensions->get('seo-sitemap')->get_name() . '-'; $options = array(); foreach ($taxonomies as $taxonomy) { $tax = get_taxonomy($taxonomy); $option = array('label' => $tax->labels->name, 'text' => __('Check if you want to exclude this category', 'fw'), 'type' => 'checkbox', 'value' => false); $options[$prefix . 'exclude-taxonomy-' . $taxonomy] = $option; } return $options; }
/** * @param array $attributes Encoded attributes * @param $shortcode_tag 'button', 'section', etc. * @param $post_id * @return array|WP_Error * @since 1.3.0 */ function fw_ext_shortcodes_decode_attr(array $attributes, $shortcode_tag, $post_id) { /** * @var FW_Extension_Shortcodes $shortcodes_ext */ $shortcodes_ext = fw_ext('shortcodes'); foreach ($shortcodes_ext->get_attr_coder() as $coder) { if ($coder->can_decode($attributes, $shortcode_tag, $post_id)) { return $coder->decode($attributes, $shortcode_tag, $post_id); } } return $attributes; }
protected function get_thumbnails_data() { /** * @var FW_Shortcode $column_shortcode */ $column_shortcode = fw_ext('shortcodes')->get_shortcode('column'); $builder_widths = fw_ext_builder_get_item_width($this->get_builder_type()); $column_thumbnails = array(); foreach ($builder_widths as $key => $value) { $column_thumbnails[$key] = array('tab' => __('Layout Elements', 'fw'), 'title' => apply_filters('fw_ext_shortcodes_column_title', $value['title'], $key), 'description' => apply_filters('fw_ext_shortcodes_column_description', sprintf(__('Add a %s column', 'fw'), $value['title']), $key), 'icon' => ($icon = $column_shortcode->locate_URI("/thumbnails/{$key}.png")) ? $icon : 'dashicons dashicons-align-none', 'data' => array('width' => $key)); } return apply_filters('fw_shortcode_column_thumbnails_data', $column_thumbnails); }
/** * {@inheritdoc} * @param array $args */ public function execute(array $args, array $state = array()) { /** @var WPDB $wpdb */ global $wpdb; if (empty($state)) { $state = array('attachment_id' => 0, 'pending_sizes' => array(), 'processed_sizes' => array(), 'processed_images' => 0); if ($state['total_images'] = $wpdb->get_col($wpdb->prepare("SELECT COUNT(1) as total_images FROM {$wpdb->posts}" . " WHERE post_type = 'attachment' AND post_mime_type LIKE %s" . " LIMIT 1", $wpdb->esc_like('image/') . '%'), 0)) { $state['total_images'] = array_pop($state['total_images']); } else { return new WP_Error('total_images_fail', __('Cannot get total images count', 'fw')); } } /** @var FW_Extension_Backups $backups */ $backups = fw_ext('backups'); $max_time = time() + $backups->get_timeout(-10); // -SECONDS that one image size can take on a very slow server while (time() < $max_time) { if ($attachment_id = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts}" . " WHERE post_type = 'attachment' AND post_mime_type LIKE %s AND ID > %d" . " ORDER BY ID" . " LIMIT 1", $wpdb->esc_like('image/') . '%', $state['attachment_id']), 0)) { $attachment_id = array_pop($attachment_id); } else { return true; } if ($file_exists = file_exists($file = get_attached_file($attachment_id))) { if (empty($state['pending_sizes'])) { $state['pending_sizes'] = get_intermediate_image_sizes(); $state['processed_sizes'] = array(); } while (time() < $max_time && !empty($state['pending_sizes'])) { $this->current_size = array_shift($state['pending_sizes']); add_filter('intermediate_image_sizes', array($this, '_filter_image_sizes')); $meta = wp_generate_attachment_metadata($attachment_id, $file); $this->current_size = ''; remove_filter('intermediate_image_sizes', array($this, '_filter_image_sizes')); $state['processed_sizes'] = array_merge($state['processed_sizes'], $meta['sizes']); } if (isset($meta)) { $meta['sizes'] = $state['processed_sizes']; wp_update_attachment_metadata($attachment_id, $meta); unset($meta); } } if (empty($state['pending_sizes']) || !$file_exists) { // Proceed to next attachment $state['attachment_id'] = $attachment_id; $state['processed_sizes'] = $state['pending_sizes'] = array(); ++$state['processed_images']; } } return $state; }
/** * @param array $data * * id - form id * * form - builder value * * [submit_button_text] * @param array $view_data * @return string */ public function render($data, $view_data = array()) { $form = $data['form']; if (empty($form)) { return ''; } $form_id = $data['id']; $submit_button_text = empty($data['submit_button_text']) ? __('Submit', 'fw') : $data['submit_button_text']; /** * @var FW_Extension_Forms $forms_extension */ $forms_extension = fw_ext('forms'); return $this->render_view('form', array('form_id' => $form_id, 'form_html' => $forms_extension->render_form($form_id, $form, $this->get_name(), $this->render_view('submit', array('submit_button_text' => $submit_button_text, 'form_id' => $form_id, 'extra_data' => $view_data))), 'extra_data' => $view_data)); }
public function _enqueue($data) { if ($data['builder_type'] !== 'page-builder') { return; } if (version_compare(fw_ext('builder')->manifest->get_version(), '1.1.14', '<')) { // some important changes were added in Builder v1.1.14 return; } $uri = fw_ext('shortcodes')->get_uri('/shortcodes/' . $this->get_type() . '/includes/template-component'); $version = fw_ext('shortcodes')->manifest->get_version(); wp_enqueue_style('fw-option-builder-templates-' . $this->get_type(), $uri . '/styles.css', array('fw-option-builder-templates'), $version); wp_enqueue_script('fw-option-builder-templates-' . $this->get_type(), $uri . '/scripts.js', array('fw-option-builder-templates'), $version, true); wp_localize_script('fw-option-builder-templates-' . $this->get_type(), '_fw_option_type_builder_templates_' . $this->get_type(), array('l10n' => array('template_name' => __('Template Name', 'fw'), 'save_template' => __('Save Section', 'fw'), 'save_template_tooltip' => __('Save as Template', 'fw')))); }
/** * {@inheritdoc} */ public function get_custom_timeout(array $args, array $state = array()) { if (isset($args['type']) && ($type = self::get_type_($args['type']))) { /** * Download type can set custom timeout * For e.g. some download types are performed in steps and don't require timeout increase */ return $type->get_custom_timeout($args, $state); } else { /** * Usually downloading a file takes long time */ return fw_ext('backups')->get_config('max_timeout'); } }
protected function _render($atts, $content = null, $tag = '') { $form_data = array('id' => $atts['id'], 'form' => $atts['form'], 'email_to' => $atts['email_to'], 'subject_message' => $atts['subject_message'], 'success_message' => $atts['success_message'], 'failure_message' => $atts['failure_message']); /** * @var FW_Extension_Contact_Forms $extension */ $extension = fw_ext('contact-forms'); /** * Save form data because the extension needs to access it (by id) on form submit * * There is no other possibility to save form data by id because contact form is a shortcode * it has no save action and we can't access it by id (we don't know in which post it is) */ $extension->_set_form_db_data($atts['id'], $atts); return $extension->render(array('id' => $form_data['id'], 'form' => $form_data['form'], 'submit_button_text' => $atts['submit_button_text']), array_diff_key($atts, array('width' => true, 'mailer' => true, 'submit_button_text' => true), $form_data)); }
private function do_download($args, $state, $zip_path) { /** @var FW_Extension_Backups $backups */ $backups = fw_ext('backups'); $response = wp_remote_get(add_query_arg(array_merge(apply_filters('fw:ext:backups:task-type:piecemeal-download:query-args', $default_query_args = array('id' => urlencode($args['file_id']), 'position' => $state['position'], 'size' => $state['piece_size']), $args), $default_query_args), $args['url']), array('timeout' => $backups->get_timeout() - 7)); if (is_wp_error($response)) { if (($state['piece_size'] = abs($state['piece_size'] - $this->get_mb_in_bytes())) && $state['piece_size'] >= $this->get_min_piece_size()) { return $state; } return $response; } elseif (200 !== ($response_code = intval(wp_remote_retrieve_response_code($response)))) { return new WP_Error('request_failed', sprintf(__('Request failed. Error code: %d', 'fw'), $response_code)); } elseif (!($position = intval(isset($response['headers']['x-position']) ? $response['headers']['x-position'] : 0)) || $position > 0 && $position <= $state['position']) { return new WP_Error('invalid_position', __('Invalid byte position', 'fw') . ' (current: ' . $state['position'] . ', received: ' . $position . ')'); } elseif ($position > 0 && empty($response['body'])) { return new WP_Error('empty_body', __('Empty response body', 'fw')); } if (!$state['position']) { if (($filesize = intval(isset($response['headers']['x-filesize']) ? $response['headers']['x-filesize'] : 0)) && $filesize > 0 && $filesize > $position) { $state['filesize'] = $filesize; } } if ($position < 0) { if (!$state['position']) { return new WP_Error('empty_file', __('File ended without content', 'fw')); } $state['position'] = $position; return true; } $state['position'] = $position; if (!($f = fopen($zip_path, $state['position'] ? 'a' : 'w'))) { return new WP_Error('file_open_fail', __('Failed to open file', 'fw')); } if (substr($response['body'], 0, 3) === "") { /** * Remove UTF-8 BOM added by the server * Fixes https://github.com/ThemeFuse/Unyson-Backups-Extension/issues/25 */ $response['body'] = substr($response['body'], 3); } $write_result = fwrite($f, $response['body']); fclose($f); if (false === $write_result) { return new WP_Error('file_write_fail', __('Failed to write data to file', 'fw')); } return $state; }
/** * Test if HTTP Loopback Connections are enabled on this server */ function fw_ext_backups_loopback_test() { /** @var FW_Extension_Backups $backups */ $backups = fw_ext('backups'); $url = site_url('wp-admin/admin-ajax.php'); $response = wp_remote_post($url, array('blocking' => true, 'sslverify' => false, 'body' => array('action' => $backups->_get_test_ajax_action()))); $error = false; if (is_wp_error($response)) { $error = $response->get_error_message(); } elseif (200 !== ($response_code = intval(wp_remote_retrieve_response_code($response)))) { $error = sprintf(esc_html__('Response code: %d', 'fw'), $response_code); } elseif (isset($response['body']) && ($response_json = json_decode($response['body'], true)) && isset($response_json['success']) && true === $response_json['success']) { return false; } else { $error = __('Invalid JSON response', 'fw'); } return str_replace(array('{url}', '{error}'), array($url, $error), __('HTTP Loopback Connections are not enabled on this server. ' . 'If you need to contact your web host, ' . 'tell them that when PHP tries to connect back to the site ' . 'at the URL `{url}` and it gets the error `{error}`. ' . 'There may be a problem with the server configuration (eg local DNS problems, mod_security, etc) ' . 'preventing connections from working properly.', 'fw')); }
private function get_atts_string($atts) { if (version_compare(fw_ext('shortcodes')->manifest->get_version(), '1.3.0', '>=')) { /** * @var FW_Ext_Shortcodes_Attr_Coder_JSON $coder */ $coder = fw_ext('shortcodes')->get_attr_coder('json'); $encoded_atts = $coder->encode($atts, '', 0); } else { $coder = new _FW_Ext_Page_Builder_Shortcode_Atts_Coder(); $encoded_atts = $coder->encode_atts($atts); } $atts_string = ''; foreach ($encoded_atts as $key => $value) { $atts_string .= $key . '="' . $value . '" '; } return substr($atts_string, 0, -1); }
/** * Check if menu item is a MegaMenu item or is inside a MegaMenu item * @param WP_Post $item * @return bool */ function fw_ext_mega_menu_is_mm_item($item) { $cache_key = fw_ext('megamenu')->get_cache_key('/mm_item'); try { $mm_items = FW_Cache::get($cache_key); } catch (FW_Cache_Not_Found_Exception $e) { $mm_items = array(); } if (isset($mm_items[$item->ID])) { return $mm_items[$item->ID]; } $cursor_item = array('id' => $item->ID, 'parent' => $item->menu_item_parent); do { $is_mm_item = fw_ext_mega_menu_get_meta($cursor_item['id'], 'enabled'); } while (!$is_mm_item && intval($cursor_item['parent']) !== 0 && ($cursor_item = get_post($cursor_item['parent'])) && ($cursor_item = array('id' => $cursor_item->ID, 'parent' => get_post_meta($cursor_item->ID, '_menu_item_menu_item_parent', true)))); $mm_items[$item->ID] = (bool) $is_mm_item; FW_Cache::set($cache_key, $mm_items); return $mm_items[$item->ID]; }
/** * {@inheritdoc} */ public function frontend_validate(array $item, $input_value) { $mesages = array('not-configured' => __('Could not validate the form', 'fw'), 'not-human' => __('Please fill the recaptcha', 'fw')); $keys = fw_ext('forms')->get_db_settings_option('recaptcha-keys'); if (empty($keys)) { return $mesages['not-configured']; } $recaptcha = new ReCaptcha($keys['secret-key']); $gRecaptchaResponse = FW_Request::POST('g-recaptcha-response'); if (empty($gRecaptchaResponse)) { return $mesages['not-human']; } $resp = $recaptcha->verify($gRecaptchaResponse); if ($resp->isSuccess()) { return false; } else { $errors = $resp->getErrorCodes(); return $mesages['not-human']; } }
/** * {@inheritdoc} * @param array $args * * source_dir - everything from this directory will be added in zip * * destination_dir - where the zip file will be created * * Warning! * Zip can't be executed in steps, it will execute way too long, * because it is impossible to update a zip file, every time you add a file to zip, * a new temp copy of original zip is created with new modifications, it is compressed, * and the original zip is replaced. So when the zip will grow in size, * just adding a single file, will take a very long time. */ public function execute(array $args, array $state = array()) { if (!isset($args['source_dir'])) { return new WP_Error('no_source_dir', __('Source dir not specified', 'fw')); } else { $args['source_dir'] = fw_fix_path($args['source_dir']); } if (!isset($args['destination_dir'])) { return new WP_Error('no_destination_dir', __('Destination dir not specified', 'fw')); } else { $args['destination_dir'] = fw_fix_path($args['destination_dir']); } if (!class_exists('ZipArchive')) { return new WP_Error('zip_ext_missing', __('Zip extension missing', 'fw')); } $zip_path = $args['source_dir'] . '/' . implode('-', array('fw-backup', date('Y_m_d-H_i_s'), fw_ext('backups')->manifest->get_version())) . '.zip'; $zip = new ZipArchive(); if (false === ($zip_error_code = $zip->open($zip_path, ZipArchive::CREATE))) { return new WP_Error('cannot_open_zip', sprintf(__('Cannot open zip (Error code: %s)', 'fw'), $zip_error_code)); } $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($args['source_dir']), RecursiveIteratorIterator::LEAVES_ONLY); foreach ($files as $name => $file) { if (!$file->isDir()) { // Skip directories (they would be added automatically) if (($file_path = $file->getRealPath()) !== $zip_path) { $zip->addFile($file_path, substr(fw_fix_path($file_path), strlen($args['source_dir']) + 1)); } } } wp_cache_flush(); FW_Cache::clear(); // Zip archive will be created only after closing object if (!$zip->close()) { return new WP_Error('cannot_close_zip', __('Cannot close the zip file', 'fw')); } if (!rename($zip_path, $args['destination_dir'] . '/' . basename($zip_path))) { return new WP_Error('cannot_move_zip', __('Cannot move zip in destination dir', 'fw')); } return true; }