/** * Saves the enabled icons. * * @since 1.0 * @access private * @return void */ private static function save_enabled_icons() { if (isset($_POST['fl-icons-nonce']) && wp_verify_nonce($_POST['fl-icons-nonce'], 'icons')) { // Make sure we have at least one enabled icon set. if (!isset($_POST['fl-enabled-icons']) && empty($_POST['fl-new-icon-set'])) { self::add_error(__("Error! You must have at least one icon set enabled.", 'fl-builder')); return; } $filesystem = FLBuilderUtils::get_filesystem(); $enabled_icons = array(); // Sanitize the enabled icons. if (isset($_POST['fl-enabled-icons']) && is_array($_POST['fl-enabled-icons'])) { $enabled_icons = array_map('sanitize_text_field', $_POST['fl-enabled-icons']); } // Update the enabled sets. self::update_enabled_icons($enabled_icons); // Delete a set? if (!empty($_POST['fl-delete-icon-set'])) { $sets = FLBuilderIcons::get_sets(); $key = sanitize_text_field($_POST['fl-delete-icon-set']); $index = array_search($key, $enabled_icons); if (false !== $index) { unset($enabled_icons[$index]); } if (isset($sets[$key])) { $filesystem->rmdir($sets[$key]['path'], true); FLBuilderIcons::remove_set($key); } } // Upload a new set? if (!empty($_POST['fl-new-icon-set'])) { $dir = FLBuilderModel::get_cache_dir('icons'); $id = (int) $_POST['fl-new-icon-set']; $path = get_attached_file($id); $new_path = $dir['path'] . 'icon-' . time() . '/'; $unzipped = unzip_file($path, $new_path); // Unzip failed. if (!$unzipped) { self::add_error(__("Error! Could not unzip file.", 'fl-builder')); return; } // Move files if unzipped into a subfolder. $files = $filesystem->dirlist($new_path); if (1 == count($files)) { $values = array_values($files); $subfolder_info = array_shift($values); $subfolder = $new_path . $subfolder_info['name'] . '/'; if (file_exists($subfolder) && is_dir($subfolder)) { $files = $filesystem->dirlist($subfolder); if ($files) { foreach ($files as $file) { $filesystem->move($subfolder . $file['name'], $new_path . $file['name']); } } $filesystem->rmdir($subfolder); } } // Check for supported sets. $is_icomoon = file_exists($new_path . 'selection.json'); $is_fontello = file_exists($new_path . 'config.json'); // Show an error if we don't have a supported icon set. if (!$is_icomoon && !$is_fontello) { $filesystem->rmdir($new_path, true); self::add_error(__("Error! Please upload an icon set from either Icomoon or Fontello.", 'fl-builder')); return; } // Enable the new set. if (is_array($enabled_icons)) { $key = FLBuilderIcons::get_key_from_path($new_path); $enabled_icons[] = $key; } } // Update the enabled sets again in case they have changed. self::update_enabled_icons($enabled_icons); } }
/** * Register custom icon set data in the internal sets array. * * @since 1.4.6 * @access private * @return void */ private static function register_custom_sets() { // Get uploaded sets. $enabled_icons = FLBuilderModel::get_enabled_icons(); $upload_info = FLBuilderModel::get_cache_dir('icons'); $folders = glob($upload_info['path'] . '*'); // Make sure we have an array. if (!is_array($folders)) { return; } // Loop through uploaded sets. foreach ($folders as $folder) { $folder = trailingslashit($folder); // This is an Icomoon font. if (file_exists($folder . 'selection.json')) { $data = json_decode(file_get_contents($folder . 'selection.json')); $key = basename($folder); $url = str_ireplace($upload_info['path'], $upload_info['url'], $folder); if (isset($data->icons)) { if (is_admin() || in_array($key, $enabled_icons)) { self::$sets[$key] = array('name' => $data->metadata->name, 'prefix' => '', 'type' => 'icomoon', 'path' => $folder, 'url' => $url, 'stylesheet' => $url . 'style.css', 'icons' => array()); foreach ($data->icons as $icon) { $prefs = $data->preferences->fontPref; $postfix = isset($prefs->postfix) ? $prefs->postfix : ''; if (isset($prefs->selector) && 'class' == $prefs->selector) { $selector = trim(str_replace('.', ' ', $prefs->classSelector)) . ' '; } else { $selector = ''; } self::$sets[$key]['icons'][] = $selector . $prefs->prefix . $icon->properties->name . $postfix; } } } } else { if (file_exists($folder . 'config.json')) { $data = json_decode(file_get_contents($folder . 'config.json')); $key = basename($folder); $name = empty($data->name) ? 'Fontello' : $data->name; $url = str_ireplace($upload_info['path'], $upload_info['url'], $folder); $style = empty($data->name) ? 'fontello' : $data->name; // Append the date to the name? if (empty($data->name)) { $time = str_replace('icon-', '', $key); $date_format = get_option('date_format'); $time_format = get_option('time_format'); $date = date($date_format . ' ' . $time_format); $name .= ' (' . $date . ')'; } if (isset($data->glyphs)) { if (is_admin() || in_array($key, $enabled_icons)) { self::$sets[$key] = array('name' => $name, 'prefix' => '', 'type' => 'fontello', 'path' => $folder, 'url' => $url, 'stylesheet' => $url . 'css/' . $style . '.css', 'icons' => array()); foreach ($data->glyphs as $icon) { if ($data->css_use_suffix) { self::$sets[$key]['icons'][] = $icon->css . $data->css_prefix_text; } else { self::$sets[$key]['icons'][] = $data->css_prefix_text . $icon->css; } } } } } } } }
/** * Update to version 1.2.8 or later. * * @since 1.2.8 * @access private * @return void */ private static function v_1_2_8() { global $wpdb; if (self::pre_1_2_8_table_exists()) { $table = $wpdb->prefix . 'fl_builder_nodes'; $metas = $wpdb->get_results("SELECT * FROM {$wpdb->postmeta} WHERE meta_key = '_fl_builder_layout'"); $cache_dir = FLBuilderModel::get_cache_dir(); // Loop through the layout ids for each post. foreach ($metas as $meta) { // Get the old layout nodes from the database. $published = $wpdb->get_results("SELECT * FROM {$table} WHERE layout = '{$meta->meta_value}' AND status = 'published'"); $draft = $wpdb->get_results("SELECT * FROM {$table} WHERE layout = '{$meta->meta_value}' AND status = 'draft'"); // Convert the old nodes to new ones. $published = self::v_1_2_8_convert_nodes($published); $draft = self::v_1_2_8_convert_nodes($draft); // Add the new layout post meta. update_post_meta($meta->post_id, '_fl_builder_data', $published); update_post_meta($meta->post_id, '_fl_builder_draft', $draft); } // Backup the old builder table. self::pre_1_2_8_backup(); // Drop the old builder table. if (file_exists($cache_dir['path'] . 'backup.dat')) { $wpdb->query("DROP TABLE {$wpdb->prefix}fl_builder_nodes"); } // Delete old post meta. delete_post_meta_by_key('_fl_builder_layout'); delete_post_meta_by_key('_fl_builder_layout_export'); delete_post_meta_by_key('_fl_builder_css'); delete_post_meta_by_key('_fl_builder_css-draft'); delete_post_meta_by_key('_fl_builder_js'); delete_post_meta_by_key('_fl_builder_js-draft'); // Convert global settings. self::v_1_2_8_convert_global_settings(); // Delete all asset cache. $css = glob($cache_dir['path'] . '*.css'); $js = glob($cache_dir['path'] . '*.js'); if (is_array($css)) { array_map('unlink', $css); } if (is_array($js)) { array_map('unlink', $js); } } }
/** * @method _get_cropped_path * @protected */ protected function _get_cropped_path() { $crop = empty($this->settings->crop) ? 'none' : $this->settings->crop; $url = $this->_get_uncropped_url(); $cache_dir = FLBuilderModel::get_cache_dir(); if (empty($url)) { $filename = uniqid(); // Return a file that doesn't exist. } else { if (stristr($url, '?')) { $parts = explode('?', $url); $url = $parts[0]; } $pathinfo = pathinfo($url); $dir = $pathinfo['dirname']; $ext = $pathinfo['extension']; $name = wp_basename($url, ".{$ext}"); $new_ext = strtolower($ext); $filename = "{$name}-{$crop}.{$new_ext}"; } return array('filename' => $filename, 'path' => $cache_dir['path'] . $filename, 'url' => $cache_dir['url'] . $filename); }