EstudioJuridicoAlmagro_Web/www/wpv_common/admin/ajax/base.php
2013-03-01 18:06:10 +00:00

185 lines
4.9 KiB
PHP

<?php
// galleries
function gallery_get_image_action_callback() {
$html = gallery_create_image_item($_POST['id']);
if ($html) {
exit;
} else {
echo '0';
exit;
}
}
add_action('wp_ajax_theme-gallery-get-image', 'gallery_get_image_action_callback');
function gallery_create_image_item($id) {
$image = & get_post($id);
if ($image):
$meta = wp_get_attachment_metadata($id);
$date = mysql2date(get_option('date_format'), $image->post_date);
$size = $meta['width'] . ' x ' . $meta['height'] . 'px';
return include(WPV_ADMIN_HELPERS . 'gallery-item.php');
endif;
return false;
}
/*
* media upload
*/
function media_get_image_action_callback() {
$image = & get_post($_POST['id']);
if($image)
echo $image->guid;
else
echo '0';
exit;
}
add_action('wp_ajax_wpv-media-get-image', 'media_get_image_action_callback');
/// handles ajax request when saving a theme's options
function save_theme_config_callback() {
foreach($_POST['config'] as &$opt) {
$opt = stripslashes($opt);
}
unset($opt);
$output = json_encode($_POST['config']);
$_POST['file'] = trim($_POST['file']);
if(file_put_contents(WPV_SAVED_OPTIONS.$_POST['file'], $output)) {
echo '<span class="success">'. __('Success.', 'wpv') . '</span>';
} else {
echo '<span class="error">'. __('Cannot save file.', 'wpv') . '</span>';
}
exit;
}
add_action('wp_ajax_save_theme_config', 'save_theme_config_callback');
// deletes a skin
function delete_theme_config_callback() {
$_POST['file'] = trim($_POST['file']);
if(@unlink(WPV_SAVED_OPTIONS.$_POST['file'])) {
echo '<span class="success">'. __('Success.', 'wpv') . '</span>';
} else {
echo '<span class="error">'. __('Cannot delete file.', 'wpv') . '</span>';
}
exit;
}
add_action('wp_ajax_delete_theme_config', 'delete_theme_config_callback');
// lists available theme configs
function wpv_available_configs_callback() {
$skins_dir = opendir(WPV_SAVED_OPTIONS);
if(isset($_POST['prefix'])) {
$prefix = $_POST['prefix'].'_';
echo '<option value="">'.__('Available skins', 'wpv').'</option>';
while($file = readdir($skins_dir)):
if($file != "." && $file != ".." && strpos($file, $prefix) == 0):
?>
<option value="<?php echo WPV_SAVED_OPTIONS_URI.$file?>"><?php echo str_replace($prefix, '', $file) ?></option>
<?php
endif;
endwhile;
closedir($skins_dir);
}
exit;
}
add_action('wp_ajax_wpv-available-configs', 'wpv_available_configs_callback');
function save_theme_last_config_callback() {
wpv_update_option('last-active-skin', $_POST['name']);
echo '<span class="success">The changes are temporary, you have to click "Save options".</span>';
exit;
}
add_action('wp_ajax_save_last_theme_config', 'save_theme_last_config_callback');
// gets the stylesheet for the font preview
function wpv_font_preview_callback() {
global $available_fonts;
$url = wpv_get_font_url($_POST['face']);
if(!empty($url)) {
echo $url;
}
exit;
}
add_action('wp_ajax_wpv-font-preview', 'wpv_font_preview_callback');
// lists available templates
function wpv_available_templates_callback() {
$templates_dir = opendir(WPV_TEMPLATES_DIR);
echo '<option value="">'.__('Available templates', 'wpv').'</option>';
while($file = readdir($templates_dir)):
if($file != "." && $file != ".." && strpos($file, THEME_SLUG) == 0):
?>
<option value="<?php echo WPV_TEMPLATES_URI.$file?>"><?php echo str_replace(THEME_SLUG, '', $file) ?></option>
<?php
endif;
endwhile;
closedir($templates_dir);
exit;
}
add_action('wp_ajax_wpv-available-templates', 'wpv_available_templates_callback');
// saves a template
function wpv_save_template_callback() {
foreach($_POST['template'] as &$opt) {
if(is_string($opt)) {
$opt = stripslashes($opt);
}
}
unset($opt);
$output = json_encode($_POST['template']);
$_POST['file'] = trim($_POST['file']);
if(file_put_contents(WPV_TEMPLATES_DIR.THEME_SLUG.$_POST['file'], $output)) {
echo '<span class="success">'. __('Success.', 'wpv') . '</span>';
} else {
echo '<span class="error">'. __('Cannot save file.', 'wpv') . '</span>';
}
exit;
}
add_action('wp_ajax_wpv-save-template', 'wpv_save_template_callback');
// deletes a template
function wpv_delete_template_callback() {
$file = WPV_TEMPLATES_DIR.THEME_SLUG.$_POST['file'];
if(@unlink($file)) {
echo '<span class="success">'. __('Deleted.', 'wpv') . '</span>';
} else {
echo '<span class="error">'. __('Cannot delete file.', 'wpv') . '</span>';
}
exit;
}
add_action('wp_ajax_wpv-delete-template', 'wpv_delete_template_callback');
// saves the theme/framework options
function wpv_save_options_callback() {
$page = include WPV_ADMIN_OPTIONS . str_replace('wpv_', '', $_POST['page']) . '.php';
wpv_save_config($page['config']);
_e('Saved', 'wpv');
exit;
}
add_action('wp_ajax_wpv-save-options', 'wpv_save_options_callback');