page = $page = add_theme_page(__('Footer'), __('Footer'), 'edit_theme_options', 'custom-footer', array(&$this, 'admin_page'));
add_action("admin_print_scripts-$page", array(&$this, 'js_includes'));
add_action("admin_print_styles-$page", array(&$this, 'css_includes'));
add_action("admin_head-$page", array(&$this, 'take_action'), 50);
add_action("admin_head-$page", array(&$this, 'js'), 50);
add_action("admin_head-$page", $this->admin_footer_callback, 51);
}
/**
* Get the current step.
*
* @since 2.6.0
*
* @return int Current step
*/
function step() {
if ( ! isset( $_GET['step'] ) )
return 1;
$step = (int) $_GET['step'];
if ( $step < 1 || 3 < $step )
$step = 1;
return $step;
}
/**
* Set up the enqueue for the JavaScript files.
*
* @since 2.1.0
*/
function js_includes() {
$step = $this->step();
if ( 2 == $step )
wp_enqueue_script('imgareaselect');
}
/**
* Set up the enqueue for the CSS files
*
* @since 2.7
*/
function css_includes() {
$step = $this->step();
if ( 2 == $step )
wp_enqueue_style('imgareaselect');
}
/**
* Execute custom footer modification.
*
* @since 2.6.0
*/
function take_action() {
if ( ! current_user_can('edit_theme_options') )
return;
if ( empty( $_POST ) )
return;
$this->updated = true;
if ( isset( $_POST['removefooter'] ) ) {
$fdi = get_theme_mod('fdi', FDI);
check_admin_referer( 'custom-footer-removeimg', 'wpnonce-custom-footer-removeimg' );
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => 0,
'orderby' => 'rand'
);
$attachments = get_posts($args);
$img_id=0;
if ($attachments){
foreach ($attachments as $post){
setup_postdata($post->ID);
$img = wp_get_attachment_image_src( $post->ID, 'full');
if($img[0] == esc_url(get_theme_mod('footer_image'.$fdi, '')))
{
$img_id=$post->ID;
}
}
if($img_id!=0)
wp_delete_attachment( $img_id);
remove_theme_mod('footer_image'.$fdi);
}
return;
}
if(isset($_REQUEST['select']))
$this->updated=false;
if(isset($_REQUEST['cat1']))
$this->updated=false;
if(isset($_REQUEST['cat2']))
$this->updated=false;
if(isset($_REQUEST['cat3']))
$this->updated=false;
if(isset($_REQUEST['cat4']))
$this->updated=false;
}
/**
* Execute Javascript depending on step.
*
* @since 2.1.0
*/
function js() {
$step = $this->step();
if (2 == $step )
$this->js_2();
}
/**
* Display Javascript based on Step 2.
*
* @since 2.6.0
*/
function js_2() { ?>
updated ) ) { ?>
Visit your site to see how it looks.' ), home_url( '/' ) ); ?>
|
|
|
|
0)
set_theme_mod('cat1', $_REQUEST['cat1']);
print "Category #1 : " . get_cat_name(get_theme_mod('cat1', '0')) . ".";
?>
|
0)
set_theme_mod('cat2', $_REQUEST['cat2']);
print "Category #2 : " . get_cat_name(get_theme_mod('cat2', '0')) . ".";
?>
|
0)
set_theme_mod('cat3', $_REQUEST['cat3']);
print "Category #3 : " . get_cat_name(get_theme_mod('cat3', '0')) . ".";
?>
|
0)
set_theme_mod('cat4', $_REQUEST['cat4']);
print "Category #4 : " . get_cat_name(get_theme_mod('cat4', '0')) . ".";
?>
|
|
|
|
|
|
%1$d × %2$d pixels will be used as-is.' ), FOOTER_IMAGE_WIDTH, FOOTER_IMAGE_HEIGHT ); ?>
|
false);
$file = wp_handle_upload($_FILES['import'], $overrides);
if ( isset($file['error']) )
wp_die( $file['error'], __( 'Image Upload Error' ) );
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$filename = basename($file);
// Construct the object array
$object = array(
'post_title' => $filename,
'post_content' => $url,
'post_mime_type' => $type,
'guid' => $url);
// Save the data
$id = wp_insert_attachment($object, $file);
list($width, $height, $type, $attr) = getimagesize( $file );
if ( $width == FOOTER_IMAGE_WIDTH && $height == FOOTER_IMAGE_HEIGHT ) {
// Add the meta-data
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
set_theme_mod('footer_image'.get_theme_mod('fdi', FDI), esc_url($url));
do_action('wp_create_file_in_uploads', $file, $id); // For replication
return $this->finished();
} elseif ( $width > FOOTER_IMAGE_WIDTH ) {
$oitar = $width / FOOTER_IMAGE_WIDTH;
$image = wp_crop_image($file, 0, 0, $width, $height, FOOTER_IMAGE_WIDTH, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
if ( is_wp_error( $image ) )
wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
$image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication
$url = str_replace(basename($url), basename($image), $url);
$width = $width / $oitar;
$height = $height / $oitar;
} else {
$oitar = 1;
}
?>
1 ) {
$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
$_POST['width'] = $_POST['width'] * $_POST['oitar'];
$_POST['height'] = $_POST['height'] * $_POST['oitar'];
}
$original = get_attached_file( $_POST['attachment_id'] );
$cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], FOOTER_IMAGE_WIDTH, FOOTER_IMAGE_HEIGHT);
if ( is_wp_error( $cropped ) )
wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
$cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication
$parent = get_post($_POST['attachment_id']);
$parent_url = $parent->guid;
$url = str_replace(basename($parent_url), basename($cropped), $parent_url);
// Construct the object array
$object = array(
'ID' => $_POST['attachment_id'],
'post_title' => basename($cropped),
'post_content' => $url,
'post_mime_type' => 'image/jpeg',
'guid' => $url
);
// Update the attachment
wp_insert_attachment($object, $cropped);
wp_update_attachment_metadata( $_POST['attachment_id'], wp_generate_attachment_metadata( $_POST['attachment_id'], $cropped ) );
set_theme_mod('footer_image'.get_theme_mod('fdi', FDI), $url);
// cleanup
$medium = str_replace(basename($original), 'midsize-'.basename($original), $original);
@unlink( apply_filters( 'wp_delete_file', $medium ) );
@unlink( apply_filters( 'wp_delete_file', $original ) );
return $this->finished();
}
/**
* Display last step of custom footer image page.
*
* @since 2.1.0
*/
function finished() {
$this->updated = true;
$this->step_1();
}
/**
* Display the page based on the current step.
*
* @since 2.1.0
*/
function admin_page() {
if ( ! current_user_can('edit_theme_options') )
wp_die(__('You do not have permission to customize footers.'));
$step = $this->step();
if ( 1 == $step )
$this->step_1();
elseif ( 2 == $step )
$this->step_2();
elseif ( 3 == $step )
$this->step_3();
}
}
?>