コード例 #1
0
 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";
 }
コード例 #2
0
ファイル: functions.php プロジェクト: jimrucinski/Vine
 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);
     }
 }
コード例 #3
0
ファイル: functions.php プロジェクト: jimrucinski/Vine
 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'));
     }
 }
コード例 #4
0
 function get_export($name, $data_sources = array())
 {
     global $current_user;
     it_classes_load('it-zip.php');
     $zip = new ITZip();
     if (empty($data_sources)) {
         $data_sources = array_keys($this->_data_sources);
     }
     $theme_data = get_file_data(get_stylesheet_directory() . '/style.css', array('name' => 'Theme Name'), 'theme');
     $export_path = $this->_get_export_path($this->_guid, $name);
     $info = array('name' => $name, 'guid' => $this->_guid, 'builder_version' => $GLOBALS['it_builder_core_version'], 'builder_theme_name' => $theme_data['name'], 'timestamp' => time(), 'site_url' => get_bloginfo('url'), 'site_wpurl' => get_bloginfo('wpurl'), 'exported_by' => $current_user->display_name, 'data_sources' => array(), 'attachments' => array());
     add_action('builder_import_export_add_attachment', array($this, 'add_attachment'));
     foreach ((array) $data_sources as $var) {
         if (!isset($this->_data_sources[$var])) {
             continue;
         }
         $data = $this->_data_sources[$var]->get_export_data();
         $this->_add_zip_file_content($zip, "data-sources/{$var}.txt", $data);
         $data_source = array('name' => $this->_data_sources[$var]->get_name(), 'version' => $this->_data_sources[$var]->get_version(), 'data_size' => strlen(serialize($data)));
         $info['data_sources'][$var] = $data_source;
         unset($data);
     }
     $this->_attachments = array_unique($this->_attachments);
     $attachments = $files = array();
     it_classes_load('it-file-utility.php');
     foreach ((array) $this->_attachments as $attachment_id) {
         $url = wp_get_attachment_url($attachment_id);
         if (empty($url)) {
             continue;
         }
         $file = ITFileUtility::get_file_from_url($url);
         $attachment = array();
         $attachment['post'] = get_post($attachment_id);
         $attachment['file_name'] = basename($file);
         $attachment['metadata_alt'] = get_metadata('post', $attachment_id, '_wp_attachment_image_alt');
         if (empty($attachment['metadata_alt'])) {
             unset($attachment['metadata_alt']);
         }
         $attachments[$attachment_id] = $attachment;
         $files[$attachment_id] = $file;
     }
     $info['attachments'] = $attachments;
     $this->_add_zip_file_content($zip, 'info.txt', $info);
     foreach ((array) $files as $id => $file) {
         $zip->add_file($file, "attachments/{$id}/");
     }
     do_action('builder_exporter_modify_zip_content', $zip);
     $file = $zip->create_zip(array('file' => $export_path));
     if (is_wp_error($file)) {
         return $file;
     }
     $this->_load_data();
     $info['file'] = $file;
     $info['url'] = ITFileUtility::get_url_from_file($file);
     return $info;
 }
コード例 #5
0
ファイル: functions.php プロジェクト: jimrucinski/Vine
function builder_add_global_admin_styles()
{
    it_classes_load('it-file-utility.php');
    wp_enqueue_style('builder-global-admin-style', ITFileUtility::get_url_from_file(dirname(__FILE__) . '/css/admin-global.css'));
}
コード例 #6
0
ファイル: settings-tab.php プロジェクト: jimrucinski/Vine
 function add_admin_scripts()
 {
     it_classes_load('it-file-utility.php');
     wp_enqueue_script("{$this->_var}-jquery-toolips", ITFileUtility::get_url_from_file(dirname(__FILE__) . '/js/tooltip.js'), array('jquery'));
 }
コード例 #7
0
ファイル: tab-basic.php プロジェクト: jimrucinski/Vine
 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();
 }
コード例 #8
0
ファイル: it-file-utility.php プロジェクト: jimrucinski/Vine
 public static function add_to_media_library($file, $args = array())
 {
     if (is_bool($args)) {
         $args = array('move_to_uploads' => false);
     }
     $default_args = array('move_to_uploads' => true, 'url' => null, 'type' => null, 'name' => null, 'title' => null, 'content' => null, 'attachment_id' => null);
     $args = array_merge($default_args, $args);
     if (is_null($args['name'])) {
         $args['name'] = basename($file);
     }
     if (is_null($args['type'])) {
         $wp_filetype = wp_check_filetype_and_ext($file, $file);
         if (false !== $wp_filetype['proper_filename']) {
             $args['name'] = $wp_filetype['proper_filename'];
         }
         if (false !== $wp_filetype['type']) {
             $args['type'] = $wp_filetype['type'];
         } else {
             $args['type'] = '';
         }
     }
     if (true === $args['move_to_uploads']) {
         $uploads = wp_upload_dir();
         if (!is_array($uploads) || false !== $uploads['error']) {
             return false;
         }
         $filename = wp_unique_filename($uploads['path'], $args['name']);
         $new_file = "{$uploads['path']}/{$filename}";
         if (false === @copy($file, $new_file)) {
             return false;
         }
         $stat = stat(dirname($new_file));
         $perms = $stat['mode'] & 0666;
         @chmod($new_file, $perms);
         $args['url'] = "{$uploads['url']}/{$filename}";
         $file = $new_file;
         if (is_multisite()) {
             delete_transient('dirsize_cache');
         }
     }
     if (is_null($args['url'])) {
         $args['url'] = ITFileUtility::get_url_from_file($file);
     }
     if (is_null($args['title'])) {
         $title = preg_replace('/\\.[^.]+$/', '', basename($file));
     }
     if (is_null($args['content'])) {
         $args['content'] = '';
     }
     require_once ABSPATH . '/wp-admin/includes/image.php';
     if (false !== ($image_meta = @wp_read_image_metadata($file))) {
         if ('' !== trim($image_meta['title'])) {
             $args['title'] = $image_meta['title'];
         }
         if ('' !== trim($image_meta['caption'])) {
             $args['content'] = $image_meta['caption'];
         }
     }
     $attachment = array('post_mime_type' => $args['type'], 'guid' => $args['url'], 'post_title' => $args['title'], 'post_content' => $args['content']);
     $id = wp_insert_attachment($attachment, $file);
     if (!is_wp_error($id)) {
         wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));
     }
     $data = array('id' => $id, 'file' => $file, 'url' => $args['url'], 'type' => $args['type'], 'title' => $args['title'], 'caption' => $args['content']);
     return $data;
 }
コード例 #9
0
ファイル: it-post-type.php プロジェクト: jimrucinski/Vine
 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);
 }
コード例 #10
0
 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);
 }
コード例 #11
0
ファイル: it-image-utility.php プロジェクト: jimrucinski/Vine
 public static function resize_image($file, $max_w = 0, $max_h = 0, $crop = true, $suffix = null, $dest_path = null, $jpeg_quality = 90)
 {
     it_classes_load('it-file-utility.php');
     if (is_numeric($file)) {
         $file_info = ITFileUtility::get_file_attachment($file);
         if (false === $file_info) {
             return new WP_Error('error_loading_image_attachment', "Could not find requested file attachment ({$file})");
         }
         $file = $file_info['file'];
     } else {
         $file_attachment_id = '';
     }
     if (preg_match('/\\.ico$/', $file)) {
         return array('file' => $file, 'url' => ITFileUtility::get_url_from_file($file), 'name' => basename($file));
     }
     if (version_compare($GLOBALS['wp_version'], '3.4.9', '>')) {
         // Compat code taken from pre-release 3.5.0 code.
         if (!file_exists($file)) {
             return new WP_Error('error_loading_image', sprintf(__('File &#8220;%s&#8221; doesn&#8217;t exist?'), $file));
         }
         if (!function_exists('imagecreatefromstring')) {
             return new WP_Error('error_loading_image', __('The GD image library is not installed.'));
         }
         // Set artificially high because GD uses uncompressed images in memory
         @ini_set('memory_limit', apply_filters('image_memory_limit', WP_MAX_MEMORY_LIMIT));
         $image = imagecreatefromstring(file_get_contents($file));
         if (!is_resource($image)) {
             return new WP_Error('error_loading_image', sprintf(__('File &#8220;%s&#8221; is not an image.'), $file));
         }
     } else {
         require_once ABSPATH . 'wp-admin/includes/image.php';
         $image = wp_load_image($file);
         if (!is_resource($image)) {
             return new WP_Error('error_loading_image', $image);
         }
     }
     list($orig_w, $orig_h, $orig_type) = getimagesize($file);
     $dims = ITImageUtility::_image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop);
     if (!$dims) {
         return new WP_Error('error_resizing_image', "Could not resize image");
     }
     list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;
     if ($orig_w == $dst_w && $orig_h == $dst_h) {
         return array('file' => $file, 'url' => ITFileUtility::get_url_from_file($file), 'name' => basename($file));
     }
     if (!$suffix) {
         $suffix = "resized-image-{$dst_w}x{$dst_h}";
     }
     $info = pathinfo($file);
     $dir = $info['dirname'];
     $ext = $info['extension'];
     $name = basename($file, ".{$ext}");
     if (!is_null($dest_path) && ($_dest_path = realpath($dest_path))) {
         $dir = $_dest_path;
     }
     $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
     if (file_exists($destfilename)) {
         if (filemtime($file) > filemtime($destfilename)) {
             unlink($destfilename);
         } else {
             return array('file' => $destfilename, 'url' => ITFileUtility::get_url_from_file($destfilename), 'name' => basename($destfilename));
         }
     }
     // ImageMagick cannot resize animated PNG files yet, so this only works for
     // animated GIF files.
     $animated = false;
     if (ITImageUtility::is_animated_gif($file)) {
         $coalescefilename = "{$dir}/{$name}-coalesced-file.{$ext}";
         if (!file_exists($coalescefilename)) {
             system("convert {$file} -coalesce {$coalescefilename}");
         }
         if (file_exists($coalescefilename)) {
             system("convert -crop {$src_w}x{$src_h}+{$src_x}+{$src_y}! {$coalescefilename} {$destfilename}");
             if (file_exists($destfilename)) {
                 system("mogrify -resize {$dst_w}x{$dst_h} {$destfilename}");
                 system("convert -layers optimize {$destfilename}");
                 $animated = true;
             }
         }
     }
     if (!$animated) {
         $newimage = imagecreatetruecolor($dst_w, $dst_h);
         // preserve PNG transparency
         if (IMAGETYPE_PNG == $orig_type && function_exists('imagealphablending') && function_exists('imagesavealpha')) {
             imagealphablending($newimage, false);
             imagesavealpha($newimage, true);
         }
         imagecopyresampled($newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
         // we don't need the original in memory anymore
         if ($orig_type == IMAGETYPE_GIF) {
             if (!imagegif($newimage, $destfilename)) {
                 return new WP_Error('resize_path_invalid', __('Resize path invalid'));
             }
         } elseif ($orig_type == IMAGETYPE_PNG) {
             if (!imagepng($newimage, $destfilename)) {
                 return new WP_Error('resize_path_invalid', __('Resize path invalid'));
             }
         } else {
             // all other formats are converted to jpg
             $destfilename = "{$dir}/{$name}-{$suffix}.jpg";
             if (!imagejpeg($newimage, $destfilename, apply_filters('jpeg_quality', $jpeg_quality))) {
                 return new WP_Error('resize_path_invalid', __('Resize path invalid'));
             }
         }
         imagedestroy($newimage);
     }
     imagedestroy($image);
     // Set correct file permissions
     $stat = stat(dirname($destfilename));
     $perms = $stat['mode'] & 0666;
     //same permissions as parent folder, strip off the executable bits
     @chmod($destfilename, $perms);
     return array('file' => $destfilename, 'url' => ITFileUtility::get_url_from_file($destfilename), 'name' => basename($destfilename));
 }