/**
  * Gets an array of data for icon sets of the current
  * site on a multisite install.
  *
  * @since 1.4.6
  * @return array An array of data for each icon set.
  */
 public static function get_sets_for_current_site()
 {
     if (!is_multisite()) {
         return self::get_sets();
     }
     // Store the original sets.
     $original_sets = self::$sets;
     // Register the icon sets.
     self::register_custom_sets();
     self::register_core_sets();
     // Get the new sets.
     $sets = self::$sets;
     // Revert to the original sets.
     self::$sets = $original_sets;
     // Return the sets.
     return $sets;
 }
 /** 
  * Enqueues the needed styles for any icon fields
  * in this module.
  *
  * @since 1.4.6
  * @return void
  */
 public function enqueue_icon_styles()
 {
     FLBuilderIcons::enqueue_styles_for_module($this);
 }
 /** 
  * 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);
     }
 }
Ejemplo n.º 4
0
 /**
  * Renders the markup for the icon selector.
  *
  * @since 1.0
  * @return void
  */
 public static function render_icon_selector()
 {
     $icon_sets = FLBuilderIcons::get_sets();
     include FL_BUILDER_DIR . 'includes/icon-selector.php';
     if (defined('DOING_AJAX')) {
         die;
     }
 }
    ?>
		</label>
		<?php 
}
?>
		
		<div class="fl-settings-form-content">

			<p><?php 
printf(__('Enable or disable icon sets using the options below or upload a custom icon set from either <a%s>Icomoon</a> or <a%s>Fontello</a>.', 'fl-builder'), ' href="https://icomoon.io/" target="_blank"', ' href="http://fontello.com/" target="_blank"');
?>
</p>
			
			<?php 
$enabled_icons = FLBuilderModel::get_enabled_icons();
$icon_sets = FLBuilderIcons::get_sets_for_current_site();
foreach ($icon_sets as $key => $set) {
    $checked = in_array($key, $enabled_icons) ? ' checked' : '';
    ?>
				<p>
					<label>
						<input type="checkbox" name="fl-enabled-icons[]" value="<?php 
    echo $key;
    ?>
" <?php 
    echo $checked;
    ?>
>
						<?php 
    echo ' ' . $set['name'];
    ?>
Ejemplo n.º 6
0
 /**
  * Renders the markup for the icon selector.
  *
  * @since 1.0
  * @return array
  */
 public static function render_icon_selector()
 {
     $icon_sets = FLBuilderIcons::get_sets();
     ob_start();
     include FL_BUILDER_DIR . 'includes/icon-selector.php';
     $html = ob_get_clean();
     return array('html' => $html);
 }