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(); }