function add_stylesheet() { if (empty($this->_active_extension_directory)) { return; } it_classes_load('it-file-utility.php'); $url = ITFileUtility::get_url_from_file("{$this->_active_extension_directory}/style.css"); echo "<link rel='stylesheet' href='{$url}' type='text/css' media='screen' />\n"; }
function BuilderExtensionTeasersRight() { // Include the file for setting the image sizes require_once dirname(__FILE__) . '/lib/image-size.php'; // Helpers it_classes_load('it-file-utility.php'); $this->_base_url = ITFileUtility::get_url_from_file(dirname(__FILE__)); // Calling only if not on a singular if (!is_singular()) { add_action('builder_layout_engine_render', array(&$this, 'change_render_content'), 0); } }
function generate_stylesheet($layout_id, $layout_settings) { it_classes_load('it-file-utility.php'); require_once dirname(__FILE__) . '/layout-engine.php'; $this->stylesheet = apply_filters('builder_get_layout_style_rules', '', $layout_id, $layout_settings); $file = "{$this->path}/{$layout_id}.css"; $file = ITFileUtility::get_writable_file($file); if (is_wp_error($file) || false === file_put_contents($file, $this->stylesheet)) { return; } $this->layout['stylesheet_version'] = $this->get_current_stylesheet_version(); $this->layout['stylesheet_file'] = $file; $this->layout_settings['layouts'][$this->layout_id] = $this->layout; $this->update_layout_storage(); }
function _setup_plugin_feature($plugin_feature) { $dir = "plugin-features/{$plugin_feature}"; $template = locate_template("{$dir}/init.php", true); if (empty($template) && file_exists(builder_main_get_builder_core_path() . "/{$dir}/init.php")) { require_once builder_main_get_builder_core_path() . "/{$dir}/init.php"; } if (!is_admin()) { it_classes_load('it-file-utility.php'); $file = locate_template("{$dir}/style.css"); if (!empty($file)) { $url = ITFileUtility::get_url_from_file($file); $this->_style_queue[] = array($plugin_feature, $url); } $file = locate_template("{$dir}/script.js"); if (!empty($file)) { $url = ITFileUtility::get_url_from_file($file); $this->_script_queue[] = array($plugin_feature, $url); } } if (!empty($this->_style_queue) || !empty($this->_script_queue)) { add_action('wp_enqueue_scripts', array($this, 'enqueue_files')); } }
function _cleanup_old_temp_directories() { it_classes_load('it-file-utility.php'); $directories = ITFileUtility::locate_file('deleteme-builder-import-export-*'); if (is_wp_error($directories)) { return; } foreach ((array) $directories as $directory) { $stats = stat($directory); if (time() - 3600 > $stats['atime']) { ITFileUtility::delete_directory($directory); } } }
function builder_create_child_theme($args = array()) { $default_args = array('child_directory' => false, 'overwrite_existing' => false, 'name' => false, 'source_directory' => get_template_directory(), 'source_type' => 'parent', 'parent_directory' => get_template_directory()); extract(ITUtility::merge_defaults($args, $default_args)); if (empty($name)) { $name = sprintf(__('%s - Custom', 'it-l10n-Builder-Paige'), $themes[basename($parent_directory)]->get('Name')); } $name = preg_replace('/^\\s+/', '', $name); $name = preg_replace('/\\s+$/', '', $name); $themes = wp_get_themes(); $names = array(); foreach ($themes as $theme) { $names[] = $theme->get('Name'); } if (in_array($name, $names)) { $count = 2; while (in_array("{$name} {$count}", $names)) { $count++; } $name = "{$name} {$count}"; } if (empty($child_directory)) { $child_directory = preg_replace('/[^a-z0-9]+/i', '-', ucfirst($name)); if (!preg_match('/^builder/i', $child_directory)) { $child_directory = "Builder-{$child_directory}"; } $child_directory = dirname($parent_directory) . "/{$child_directory}"; } if (is_dir($child_directory) && !$overwrite_existing) { $count = 2; while (is_dir("{$child_directory}-{$count}")) { $count++; } $child_directory .= "-{$count}"; } it_classes_load('it-file-utility.php'); if ('copy' == $source_type) { ITFileUtility::copy($source_directory, $child_directory, array('folder_mode' => 0775, 'file_mode' => 0664)); $stylesheet = file_get_contents("{$child_directory}/style.css"); $stylesheet = preg_replace('/(Theme Name:\\s*).*/i', "\$1{$name}", $stylesheet); file_put_contents("{$child_directory}/style.css", $stylesheet); } else { ITFileUtility::mkdir($child_directory, array('create_index' => false)); $files = array('style.css' => '', 'style-mobile.css' => '', 'style-tablet.css' => '', 'style-responsive.css' => '', 'rtl.css' => '', 'functions-child.php' => 'functions.php', 'screenshot.png' => '', 'screenshot.jpg' => '', 'screenshot.gif' => '', 'images' => '', 'lang' => '', 'plugin-features' => ''); $files = apply_filters('builder-filter-files-to-copy-to-child', $files); $stylesheet_data_headers = array('name' => 'Theme Name', 'theme_uri' => 'Theme URI', 'description' => 'Description', 'author' => 'Author', 'author_uri' => 'Author URI', 'version' => 'Version', 'license' => 'License', 'license_uri' => 'License URI', 'tags' => 'Tags', 'text_domain' => 'Text Domain', 'domain_path' => 'Domain Path', 'template' => 'Template'); $stylesheet_data = get_file_data("{$parent_directory}/style.css", $stylesheet_data_headers); $stylesheet_data['description'] = sprintf(__('This is a generated child theme for the %1$s theme. You should activate and modify this theme instead of %1$s. Doing so allows you to modify this child theme while allowing automatic upgrades for %1$s.', 'it-l10n-Builder-Paige'), $stylesheet_data['name']); $stylesheet_data['name'] = $name; $stylesheet_data['template'] = basename($parent_directory); $child_header = "/*\n"; foreach ($stylesheet_data_headers as $index => $header) { $child_header .= "{$header}: {$stylesheet_data[$index]}\n"; } $child_header .= '*/'; if (isset($files['style.css'])) { $stylesheet = file_get_contents("{$parent_directory}/style.css"); $stylesheet = preg_replace('|/\\*.*Theme Name:.*?\\*/|si', $child_header, $stylesheet); } else { $stylesheet = "{$child_header}\n\n\n@import url('../" . basename($parent_directory) . "/style.css');"; } file_put_contents("{$child_directory}/style.css", $stylesheet); foreach ($files as $source => $destination) { if ('style.css' == $source) { continue; } if (!file_exists("{$parent_directory}/{$source}")) { continue; } if (empty($destination)) { $destination = $source; } ITFileUtility::copy("{$parent_directory}/{$source}", "{$child_directory}/{$destination}", array('folder_mode' => 0775, 'file_mode' => 0664)); } } add_option('builder_manually_switched_theme', true); switch_theme(basename($child_directory)); }
function builder_enqueue_tooltip_script() { wp_enqueue_script('pluginbuddy-tooltip-js', ITFileUtility::url_from_file(dirname(__FILE__) . '/js/jquery.tooltip.js')); }
function _render($fields) { $data = $fields['data']; if (!empty($data['attachment'])) { if (!wp_attachment_is_image($data['attachment'])) { return; } $post = get_post($data['attachment']); $file = get_attached_file($data['attachment']); } else { if (!empty($data['manual_file'])) { $file = builder_main_get_builder_core_path() . '/lib/layout-engine/default-images/' . $data['manual_file']; if (!file_exists($file)) { return; } } } $image_width = $fields['widths']['element_width']; it_classes_load('it-file-utility.php'); if ('custom' == $data['height_type']) { $resized_image = ITFileUtility::resize_image($file, $image_width, $data['height'], true); } else { $resized_image = ITFileUtility::resize_image($file, $image_width); } if (!is_array($resized_image) && is_wp_error($resized_image)) { echo "<!-- Resize Error: " . $resized_image->get_error_message() . " -->"; } else { $image_url = $resized_image['url']; } if (!empty($data['url'])) { $attributes['href'] = $data['url']; if (!empty($data['new_window'])) { $attributes['target'] = '_blank'; } ITUtility::print_open_tag('a', $attributes); } if (!empty($data['image_alt'])) { $alt = $data['image_alt']; } if (empty($alt)) { $alt = get_post_meta($data['attachment'], '_wp_attachment_image_alt', true); } if (empty($alt)) { $alt = $data['name']; } $attributes = array('src' => $image_url, 'alt' => $alt); $new_attributes = apply_filters('builder_image_module_filter_img_attributes', $attributes, $fields); if (empty($new_attributes)) { $new_attributes = $attributes; } else { if (empty($new_attributes['src'])) { $new_attributes['src'] = $attributes['src']; } } $attributes = $new_attributes; ITUtility::print_self_closing_tag('img', $attributes); if (!empty($data['url'])) { echo "</a>"; } }
function _delete() { $count = 0; $guids = array(); if (!isset($_REQUEST['guid'])) { ITForm::check_nonce('site_exports'); } else { if (is_array($_REQUEST['guid']) || !isset($_REQUEST['guid'])) { ITForm::check_nonce('site_exports'); $guids = $_REQUEST['guid']; } else { ITForm::check_nonce("delete_guid_{$_GET['guid']}"); $guids = array($_GET['guid']); } } $count = count($guids); it_classes_load('it-file-utility.php'); foreach ((array) $guids as $guid) { if (isset($this->_exports['exports'][$guid])) { ITFileUtility::delete_directory(dirname($this->_exports['exports'][$guid]['file'])); unset($this->_exports['exports'][$guid]); } } if ($count > 0) { $this->_storage->save($this->_exports); } $redirect = "{$this->_parent->_self_link}&deleted={$count}"; wp_redirect($redirect); exit; }
function _save() { it_classes_load('it-file-utility.php'); $data = ITForm::get_post_data(); if (ITFileUtility::file_uploaded('uploaded_favicon')) { if (preg_match('/\\.ico$/', $_FILES['uploaded_favicon']['name'])) { $path = ITFileUtility::get_writable_directory('builder-favicon'); $name = ITUtility::get_random_string(array(6, 10)) . '.ico'; if (copy($_FILES['uploaded_favicon']['tmp_name'], "{$path}/{$name}")) { $data['favicon']['file'] = "{$path}/{$name}"; $data['favicon']['url'] = ITFileUtility::get_url_from_file("{$path}/{$name}"); @chmod("{$path}/{$name}", 0644); } else { $this->_errors[] = new WP_Error('unable-to-save-favicon', __('Unable to save the supplied Favicon image file. Pleave verify that the wp-content/uploads directory can be written to.', 'it-l10n-Builder-Cohen')); } } else { $file = ITFileUtility::create_favicon('builder-favicon', $_FILES['uploaded_favicon']['tmp_name']); if (false != $file) { $url = ITFileUtility::get_url_from_file($file); $data['favicon'] = array('file' => $file, 'url' => $url); $original_extension = strtolower(preg_replace('/.+\\.([^.]+)$/', '\\1', $_FILES['uploaded_favicon']['name'])); $original_file = preg_replace('/\\.ico/', "-original.{$original_extension}", $file); $original_url = ITFileUtility::get_url_from_file($original_file); if (copy($_FILES['uploaded_favicon']['tmp_name'], $original_file)) { $data['favicon']['original_file'] = $original_file; $data['favicon']['original_url'] = $original_url; if (false !== ($file_data = @file_get_contents($original_file))) { if (false !== ($im = @imagecreatefromstring($file_data))) { list($width, $height) = getimagesize($original_file); $new_im = imagecreatetruecolor(16, 16); imagecolortransparent($new_im, imagecolorallocatealpha($new_im, 0, 0, 0, 127)); imagealphablending($new_im, false); imagesavealpha($new_im, true); if (false !== imagecopyresampled($new_im, $im, 0, 0, 0, 0, 16, 16, $width, $height)) { $resized_file = preg_replace('/(\\.[^.]+)$/', '-resized\\1', $original_file); $result = imagepng($new_im, $resized_file); if (true == $result) { $data['favicon']['original_resized_file'] = $resized_file; $data['favicon']['original_resized_url'] = ITFileUtility::get_url_from_file($resized_file); } } } unset($file_data); } } } else { $this->_errors[] = new WP_Error('unable-to-create-favicon', __('Unable to generate a Favicon image from the supplied file. Please verify that the file is a valid JPG, JPEG, PNG, GIF, or ICO image.', 'it-l10n-Builder-Cohen')); } } } $this->_options = array_merge($this->_options, $data); $this->_parent->_save(); }
public static function delete_directory($path) { if (!is_dir($path)) { return true; } $files = array_merge(glob("{$path}/*"), glob("{$path}/.*")); $contents = array(); foreach ((array) $files as $file) { if (in_array(basename($file), array('.', '..'))) { continue; } if (is_dir($file)) { ITFileUtility::delete_directory($file); } else { if (is_file($file)) { @unlink($file); } } } @rmdir($path); if (!is_dir($path)) { return true; } return false; }
function __setup_default_settings() { // For full list of available settings, see the register_post_type() function in wp-includes/post.php // Common settings: can_export, description, exclude_from_search, has_archive, hierarchical, menu_icon, // public, register_meta_box_cb, rewrite, show_in_nav_menus, show_ui, supports $default_settings = array('public' => true, 'has_archive' => true, 'supports' => array('title', 'editor'), 'register_meta_box_cb' => array(&$this, '__register_meta_boxes')); $default_settings['labels'] = $this->__get_default_labels(); if (!empty($this->_slug)) { $default_settings['rewrite'] = array('slug' => $this->_slug); } $this->_settings = array_merge($default_settings, $this->_settings); if (!empty($this->_settings['menu_icon']) && !preg_match('/^http/', $this->_settings['menu_icon'])) { if (!isset($this->_url_base)) { it_classes_load('it-file-utility.php'); $this->_url_base = ITFileUtility::get_url_from_file(dirname($this->_file)); } $this->_settings['menu_icon'] = $this->_url_base . '/' . $this->_settings['menu_icon']; } $slug = apply_filters("it_custom_post_type_{$this->_var}_filter_slug", ''); if (!empty($slug)) { $this->_settings['rewrite'] = array('slug' => $slug); } $this->_settings = apply_filters("it_custom_post_type_{$this->_var}_filter_settings", $this->_settings); }
function create_zip($args = array()) { if (empty($this->_path)) { return false; } if (is_string($args)) { $args = array('name' => $args); } if (!is_array($args)) { $args = array(); } $default_args = array('file' => null, 'name' => 'temp', 'extension' => '.zip', 'disable_compression' => false, 'append_zip' => false, 'paths' => array()); $args = array_merge($default_args, $args); if (!empty($args['file']) && is_file($args['file']) && !is_writable($args['file'])) { return new WP_Error('cannot_overwrite_existing_file', 'The requested zip file path to be used exists and cannot be overridden'); } if (!empty($args['file'])) { if (!ITFileUtility::is_file_writable($args['file'])) { return new WP_Error('create_zip_file_not_writable', 'Requested zip file name is not writable'); } $file = $args['file']; } else { $file = ITFileUtility::create_writable_file(array('name' => $args['name'], 'extension' => $args['extension'], 'custom_search_paths' => $args['paths'])); if (is_wp_error($file)) { return $file; } } $result = false; if (true !== $this->_args['force_compatibility']) { $result = $this->_create_native_zip($file, $args); } if (true !== $result) { $result = $this->_create_compatibility_zip($file, $args); } if (is_wp_error($result)) { return $result; } else { if (true !== $result) { return new WP_Error('unknown_zip_failure', 'Zip file creation failed for an unknown reason'); } } if (empty($args['file'])) { $this->_zip = $file; } return $file; }
function get_preview_image($data = array()) { if (empty($data)) { $data = $this->get_defaults(); } $layout_option = $this->get_layout_option(); $path = "{$this->module_path}/images"; if (is_callable(array($this, '_get_custom_preview_image_name'))) { $custom_name = $this->_get_custom_preview_image_name($data); } if (!empty($custom_name)) { $path .= "/{$custom_name}"; } else { if (file_exists("{$path}/{$layout_option}_{$data[$layout_option]}.gif")) { $path = "{$path}/{$layout_option}_{$data[$layout_option]}.gif"; } else { if (file_exists("{$path}/preview.gif")) { $path = "{$path}/preview.gif"; } else { return ''; } } } it_classes_load('it-file-utility.php'); return ITFileUtility::get_url_from_file($path); }
public static function create_favicon($dir_name, $image, $sizes = false) { it_classes_load('it-file-utility.php'); require_once dirname(__FILE__) . '/classes/class-php-ico.php'; if (!is_array($sizes) || false === $sizes) { $sizes = array(array(16, 16), array(24, 24), array(32, 32), array(48, 48)); } $ico = new PHP_ICO($image, $sizes); $path = ITFileUtility::get_writable_directory($dir_name); while (empty($name) || file_exists("{$path}/{$name}")) { $name = ITUtility::get_random_string(array(6, 10)) . '.ico'; } $result = $ico->save_ico("{$path}/{$name}"); if (true != $result) { return false; } @chmod("{$path}/{$name}", 0644); return "{$path}/{$name}"; }
function _load_path_info() { $old_cache_base_path = ''; // delete_option( $this->_args['option_name'] ); $path_info = $this->_get_path_info(); if (!empty($path_info['path'])) { if (is_writable($path_info['path'])) { $path_info['url'] = ITUtility::get_url_from_file($path_info['path']); $this->_path = $path_info['path']; $this->_url = $path_info['url']; $this->_versions = $path_info['versions']; $this->_empty_types = $path_info['empty_types']; return; } if (is_dir($path_info['path'])) { $old_cache_path = $path_info['path']; } } it_classes_load('it-file-utility.php'); $path_info = ITFileUtility::get_writable_uploads_directory('it-file-cache/' . $this->_args['base_path']); if (false === $path_info) { $this->_file_cache_enabled = false; return; } $path_info['versions'] = array(); $path_info['empty_types'] = array(); $this->_update_path_info($path_info); if (!empty($old_cache_base_path) && is_dir($old_cache_base_path)) { ITFileUtility::copy($old_cache_base_path . '/*', $this->_path); } }