require_once 'wp-updates-plugin.php';
new WPUpdatesPluginUpdater_295('http://wp-updates.com/api/2/plugin', plugin_basename(__FILE__));
function espresso_cache_dir()
{
    # Start with the upload dir
    $dir = wp_upload_dir();
    # Add the Espresso dir and eventually try to create it
    $dir = $dir['basedir'] . DIRECTORY_SEPARATOR . 'espresso-addons' . DIRECTORY_SEPARATOR;
    if (!is_dir($dir)) {
        if (!mkdir($dir)) {
            return false;
        }
    }
    return $dir;
}
define('ESPRESSO_CACHE_DIR', espresso_cache_dir());
function cache_writable_folder()
{
    $message = '<div style="padding:15px; font-size:16px; line-height:24px;"><strong>Espresso Message:</strong> You need to make the &ldquo;/cache/&rdquo; directory writable before the slider/menu image uploads will work properly.<div style="font-size:13px; padding-top:5px; line-height:19px;"><strong>Location:</strong> ' . ESPRESSO_CACHE_DIR . '</div></div>';
    echo '<div class="message updated" style="margin-top:20px;">' . $message . '</div>';
}
if (!is_writable(ESPRESSO_CACHE_DIR)) {
    if (is_admin()) {
        add_action('admin_notices', 'cache_writable_folder');
    }
    return;
}
require_once 'base/base.php';
require_once 'sliders/slider.php';
require_once 'menus/menus.php';
require_once 'feature-blocks/feature-blocks.php';
Beispiel #2
0
 function ajax_upload()
 {
     # Collect filedata
     $target_dir = espresso_cache_dir();
     $wp_upload_dir = wp_upload_dir();
     if (!isset($_POST['image_name'])) {
         echo json_encode(array('success' => false, 'error' => 'No image name provided'));
         exit;
     }
     $image_name = preg_replace('/[^\\w\\._\\-]+/', '_', $_POST['image_name']);
     $filename = ESPRESSO_CACHE_DIR . '/' . $image_name;
     if (!file_exists($target_dir . '/' . $image_name)) {
         echo json_encode(array('success' => false, 'error' => 'File does not seem to exist'));
         die;
     }
     # Check extenstion
     $extenstion = array_pop(explode('.', $filename));
     $available = array('jpg', 'jpeg', 'gif', 'png');
     if (!in_array($extenstion, $available)) {
         echo json_encode(array('success' => false, 'error' => 'Invalid image extension'));
         die;
     }
     # Set a new name for the file
     $rand = substr(md5(microtime()), 0, 10);
     $filename = str_replace($extenstion, $rand . '.' . $extenstion, $filename);
     # Copy the file, now that it's okay
     $original = $target_dir . '/' . $image_name;
     copy($original, $filename);
     # Check the post
     if (!isset($_POST['post_id'])) {
         echo json_encode(array('success' => false, 'error' => 'No post ID set'));
         exit;
     }
     if (!get_post($_POST['post_id'])) {
         echo json_encode(array('success' => false, 'error' => 'There is no post with the given ID!'));
         exit;
     }
     # Try to insert an attachment
     $wp_filetype = wp_check_filetype(basename($filename), null);
     $attachment = array('guid' => $wp_upload_dir['baseurl'] . _wp_relative_upload_path($filename), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit');
     $attach_id = wp_insert_attachment($attachment, $filename, $_POST['post_id']);
     require_once ABSPATH . 'wp-admin/includes/image.php';
     $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
     wp_update_attachment_metadata($attach_id, $attach_data);
     # Check the new src of the image
     $src = wp_get_attachment_image_src($attach_id, 'full');
     $src = $src[0];
     # Get thumb path
     $thumb_path = wp_get_attachment_image_src($attach_id, 'big-id');
     # Get small thumb path
     $small_thumb_path = wp_get_attachment_image_src($attach_id, 'image-preview');
     # Output the result
     echo json_encode(array('success' => true, 'image_id' => $attach_id, 'thumb_path' => $thumb_path[0], 'small_thumb_path' => $small_thumb_path[0]));
     unlink($original);
     die;
 }