function programmatically_create_post()
{
    $url = 'http://widgets.pinterest.com/v3/pidgets/boards/bradleyblose/my-stuff/pins/';
    $json_O = json_decode(file_get_contents($url), true);
    $id = $json_O['data']['pins'][0]['id'];
    $titlelink = 'https://www.pinterest.com/pin/' . $id . '/';
    $title = get_title($titlelink);
    var_dump($title);
    $original = $json_O['data']['pins'][0]['images']['237x']['url'];
    $image_url = preg_replace('/237x/', '736x', $original);
    $description = $json_O['data']['pins'][0]['description'];
    // Initialize the page ID to -1. This indicates no action has been taken.
    $post_id = -1;
    // Setup the author, slug, and title for the post
    $author_id = 1;
    $mytitle = get_page_by_title($title, OBJECT, 'post');
    var_dump($mytitle);
    // If the page doesn't already exist, then create it
    if (NULL == get_page_by_title($title, OBJECT, 'post')) {
        // Set the post ID so that we know the post was created successfully
        $post_id = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $author_id, 'post_name' => $title, 'post_title' => $title, 'post_content' => $description, 'post_status' => 'publish', 'post_type' => 'post'));
        //upload featured image
        $upload_dir = wp_upload_dir();
        $image_data = file_get_contents($image_url);
        $filename = basename($image_url);
        if (wp_mkdir_p($upload_dir['path'])) {
            $file = $upload_dir['path'] . '/' . $filename;
            $path = $upload_dir['path'] . '/';
        } else {
            $file = $upload_dir['basedir'] . '/' . $filename;
            $path = $upload_dir['basedir'] . '/';
        }
        file_put_contents($file, $image_data);
        //edit featured image to correct specs to fit theme
        $pngfilename = $filename . '.png';
        $targetThumb = $path . '/' . $pngfilename;
        $img = new Imagick($file);
        $img->scaleImage(250, 250, true);
        $img->setImageBackgroundColor('None');
        $w = $img->getImageWidth();
        $h = $img->getImageHeight();
        $img->extentImage(250, 250, ($w - 250) / 2, ($h - 250) / 2);
        $img->writeImage($targetThumb);
        unlink($file);
        //Attach featured image
        $wp_filetype = wp_check_filetype($pngfilename, null);
        $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($pngfilename), 'post_content' => '', 'post_status' => 'inherit');
        $attach_id = wp_insert_attachment($attachment, $targetThumb, $post_id);
        require_once ABSPATH . 'wp-admin/includes/image.php';
        $attach_data = wp_generate_attachment_metadata($attach_id, $targetThumb);
        wp_update_attachment_metadata($attach_id, $attach_data);
        set_post_thumbnail($post_id, $attach_id);
        // Otherwise, we'll stop
    } else {
        // Arbitrarily use -2 to indicate that the page with the title already exists
        $post_id = -2;
    }
    // end if
}
Beispiel #2
0
 /**
  * Sets defaults like cache, compile and template directory paths.
  *
  * @throws Exception When cache path cannot be used.
  */
 public function __construct()
 {
     $upload_dir = wp_upload_dir();
     $current_theme = wp_get_theme();
     $theme_slug = $current_theme->get_stylesheet();
     /**
      * Make the upload folder the root for changing files, this is the place
      * that is most likely writable.
      *
      * Keeping the theme name as container prevents accidental problems with
      * caching or compiling files when switching themes.
      */
     $root = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $theme_slug;
     $this->cache_path = implode(DIRECTORY_SEPARATOR, array($root, 'cache', ''));
     $this->compile_path = implode(DIRECTORY_SEPARATOR, array($root, 'compiled', ''));
     /**
      * Filter: views directory
      */
     $views_path = Stencil_Environment::filter('path-views', 'views');
     /**
      * Get all directories (root + optional child theme)
      */
     $this->template_path = Stencil_File_System::get_potential_directories($views_path);
     /**
      * Attempt to make the directories
      */
     if (!wp_mkdir_p($this->cache_path)) {
         throw new Exception('Cache path could not be created.');
     }
     if (!wp_mkdir_p($this->compile_path)) {
         throw new Exception('Compile path could not be created.');
     }
 }
Beispiel #3
0
/**
 * Generate custom color scheme css
 *
 * @since 1.0
 */
function bigboom_generate_custom_color_scheme()
{
    parse_str($_POST['data'], $data);
    if (!isset($data['custom_color_scheme'])) {
        return;
    }
    if (!$data['custom_color_scheme']) {
        return;
    }
    $color_1 = $data['custom_color_1'];
    if (!$color_1) {
        return;
    }
    // Prepare LESS to compile
    $less = file_get_contents(THEME_DIR . '/css/color-schemes/mixin.less');
    $less .= ".custom-color-scheme { .color-scheme({$color_1}); }";
    // Compile
    require THEME_DIR . '/inc/libs/lessc.inc.php';
    $compiler = new lessc();
    $compiler->setFormatter('compressed');
    $css = $compiler->compile($less);
    // Get file path
    $upload_dir = wp_upload_dir();
    $dir = path_join($upload_dir['basedir'], 'custom-css');
    $file = $dir . '/color-scheme.css';
    // Create directory if it doesn't exists
    wp_mkdir_p($dir);
    @file_put_contents($file, $css);
    wp_send_json_success();
}
Beispiel #4
0
function check_log_dir($dir)
{
    if (!is_dir($dir)) {
        $wp_upload_dir = wp_upload_dir();
        $dir = $wp_upload_dir['basedir'] . '/logs/';
    }
    $pathinfo = pathinfo($dir);
    $dirname = isset($pathinfo['dirname']) ? $pathinfo['dirname'] : NULL;
    if (!is_dir($dirname)) {
        return FALSE;
    }
    // force trailing slash!
    if (strrpos($dir, '/') != strlen($dir) - 1) {
        $dir .= '/';
    }
    // make directory if it doesnt exist
    if (!is_dir($dir)) {
        wp_mkdir_p($dir, 0755);
    }
    // change permissions if we cant write to it
    if (!is_writable($dir)) {
        @chmod($dir, 0755);
    }
    // test and make sure we can write to it
    if (!is_dir($dir) || !is_writable($dir)) {
        return FALSE;
    }
    // make sure htaccess is in place to protect log files
    if (!file_exists($dir . '.htaccess') && file_exists(__DIR__ . '/_htaccess.php')) {
        copy(__DIR__ . '/_htaccess.php', $dir . '.htaccess');
    }
    return $dir;
}
Beispiel #5
0
 static function add_image($image_url)
 {
     if (empty($image_url)) {
         return FALSE;
     }
     // Add Featured Image to Post
     $upload_dir = wp_upload_dir();
     // Set upload folder
     $image_data = file_get_contents($image_url);
     // Get image data
     $filename = basename($image_url);
     // Create image file name
     // Check folder permission and define file location
     if (wp_mkdir_p($upload_dir['path'])) {
         $file = $upload_dir['path'] . '/' . $filename;
     } else {
         $file = $upload_dir['basedir'] . '/' . $filename;
     }
     // Create the image  file on the server
     file_put_contents($file, $image_data);
     // Check image file type
     $wp_filetype = wp_check_filetype($filename, NULL);
     // Set attachment data
     $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($filename), 'post_content' => '', 'post_status' => 'inherit');
     // Create the attachment
     $attach_id = wp_insert_attachment($attachment, $file);
     // Include image.php
     require_once ABSPATH . 'wp-admin/includes/image.php';
     // Define attachment metadata
     $attach_data = wp_generate_attachment_metadata($attach_id, $file);
     // Assign metadata to attachment
     wp_update_attachment_metadata($attach_id, $attach_data);
     return $attach_id;
 }
Beispiel #6
0
 function update($file)
 {
     $response = array();
     $result = 0;
     // Create a temporary directory for all the files
     wp_mkdir_p($file . '.tmp');
     exec("{$this->command} export {$this->url} {$file}.tmp --force", $response, $result);
     if ($result === 0) {
         // Check if this is a plugin by scanning for a plugin header
         $files = glob($file . '.tmp/*.php');
         if (count($files) > 0) {
             foreach ($files as $tmp) {
                 $data = file_get_contents($tmp);
                 if (strpos($data, 'Plugin Name:') !== false) {
                     if (preg_match('/Version:\\s*(.*)/', $data, $matches) > 0) {
                         $this->version = trim($matches[1]);
                     }
                     break;
                 }
             }
             if (count($files) > 1) {
                 // Zip the directory
                 $zip = new zipfile();
                 $this->zip($zip, $file . '.tmp', $file . '.tmp');
                 $fd = fopen($file, 'w');
                 fwrite($fd, $zip->file());
                 fclose($fd);
             }
         }
         $this->cleanup($file . '.tmp');
     }
 }
 /**
  * Setup the backup object and create the tmp directory
  *
  */
 public function setUp()
 {
     HM\BackUpWordPress\Path::get_instance()->set_path(dirname(__FILE__) . '/tmp');
     $this->backup = new HM\BackUpWordPress\Backup();
     $this->backup->set_root(dirname(__FILE__) . '/test-data/');
     wp_mkdir_p(hmbkp_path());
 }
Beispiel #8
0
 public function folders()
 {
     global $mf_domain;
     $dir_list = "";
     $dir_list2 = "";
     wp_mkdir_p(MF_FILES_DIR);
     wp_mkdir_p(MF_CACHE_DIR);
     if (!is_dir(MF_CACHE_DIR)) {
         $dir_list2 .= "<li>" . MF_CACHE_DIR . "</li>";
     } elseif (!is_writable(MF_CACHE_DIR)) {
         $dir_list .= "<li>" . MF_CACHE_DIR . "</li>";
     }
     if (!is_dir(MF_FILES_DIR)) {
         $dir_list2 .= "<li>" . MF_FILES_DIR . "</li>";
     } elseif (!is_writable(MF_FILES_DIR)) {
         $dir_list .= "<li>" . MF_FILES_DIR . "</li>";
     }
     if ($dir_list2 != "") {
         echo "<div id='magic-fields-install-error-message' class='error'><p><strong>" . __('Magic Fields is not ready yet.', $mf_domain) . "</strong> " . __('must create the following folders (and must chmod 777):', $mf_domain) . "</p><ul>";
         echo $dir_list2;
         echo "</ul></div>";
     }
     if ($dir_list != "") {
         echo "<div id='magic-fields-install-error-message-2' class='error'><p><strong>" . __('Magic Fields is not ready yet.', $mf_domain) . "</strong> " . __('The following folders must be writable (usually chmod 777 is neccesary):', $mf_domain) . "</p><ul>";
         echo $dir_list;
         echo "</ul></div>";
     }
 }
/**
 * Creates blank index.php and .htaccess files
 *
 * This function runs approximately once per month in order to ensure all folders
 * have their necessary protection files
 *
 * @since 1.1.5
 * @return void
 */
function edd_create_protection_files($force = false)
{
    if (false === get_transient('edd_check_protection_files') || $force) {
        $wp_upload_dir = wp_upload_dir();
        $upload_path = $wp_upload_dir['basedir'] . '/edd';
        wp_mkdir_p($upload_path);
        // Top level blank index.php
        if (!file_exists($upload_path . '/index.php')) {
            @file_put_contents($upload_path . '/index.php', '<?php' . PHP_EOL . '// Silence is golden.');
        }
        // Top level .htaccess file
        $rules = edd_get_htaccess_rules();
        if (file_exists($upload_path . '/.htaccess')) {
            $contents = @file_get_contents($upload_path . '/.htaccess');
            if (false === strpos($contents, $rules) || !$contents) {
                @file_put_contents($upload_path . '/.htaccess', $rules);
            }
        }
        // Now place index.php files in all sub folders
        $folders = edd_scan_folders($upload_path);
        foreach ($folders as $folder) {
            // Create index.php, if it doesn't exist
            if (!file_exists($folder . 'index.php')) {
                @file_put_contents($folder . 'index.php', '<?php' . PHP_EOL . '// Silence is golden.');
            }
        }
        // Check for the files once per day
        set_transient('edd_check_protection_files', true, 3600 * 24);
    }
}
 public function download()
 {
     if (!function_exists('WP_Filesystem')) {
         require ABSPATH . 'wp-admin/includes/file.php';
     }
     global $wp_filesystem;
     WP_Filesystem();
     $u = wp_upload_dir();
     $basedir = $u['basedir'];
     $remove = str_replace(get_option('siteurl'), '', $u['baseurl']);
     $basedir = str_replace($remove, '', $basedir);
     $abspath = $basedir . $this->get_local_path();
     $dir = dirname($abspath);
     if (!is_dir($dir) && !wp_mkdir_p($dir)) {
         $this->display_and_exit("Please check permissions. Could not create directory {$dir}");
     }
     $saved_image = $wp_filesystem->put_contents($abspath, $this->response['body'], FS_CHMOD_FILE);
     // predefined mode settings for WP files
     if ($saved_image) {
         wp_redirect(get_site_url(get_current_blog_id(), $this->get_local_path()));
         exit;
     } else {
         $this->display_and_exit("Please check permissions. Could not write image {$dir}");
     }
 }
 function install()
 {
     global $wpdb;
     $table_name = $wpdb->prefix . "egcl_certificates";
     //if($wpdb->get_var("show tables like '".$table_name."'") != $table_name)
     //{
     $upload_dir = wp_upload_dir();
     if (!file_exists($upload_dir["basedir"] . '/egiftcardlite')) {
         wp_mkdir_p($upload_dir["basedir"] . '/egiftcardlite');
     }
     $sourcelocation = plugin_dir_path(__FILE__) . 'defaultimages/';
     $targetlocation = $upload_dir["basedir"] . '/egiftcardlite/';
     copy($sourcelocation . 'smallimage_sample.png', $targetlocation . 'smallimage_sample.png');
     copy($sourcelocation . 'bigimage_sample.png', $targetlocation . 'bigimage_sample.png');
     copy($sourcelocation . 'certimage_sample.jpg', $targetlocation . 'certimage_sample.jpg');
     $sql = "CREATE TABLE " . $table_name . " (\r\n\t\t\t\tid int(11) NOT NULL auto_increment,\r\n\t\t\t\ttx_str varchar(31) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tcode varchar(31) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\trecipient varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\temail varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tprice float NOT NULL,\r\n\t\t\t\tcurrency varchar(15) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tstatus int(11) NOT NULL,\r\n\t\t\t\tregistered int(11) NOT NULL,\r\n\t\t\t\tblocked int(11) NOT NULL,\r\n\t\t\t\tdeleted int(11) NULL,\r\n\t\t\t\tecard tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\tUNIQUE KEY  id (id)\r\n\t\t\t);";
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     dbDelta($sql);
     //}
     $table_name = $wpdb->prefix . "egcl_transactions";
     if ($wpdb->get_var("show tables like '" . $table_name . "'") != $table_name) {
         $sql = "CREATE TABLE " . $table_name . " (\r\n\t\t\t\tid int(11) NOT NULL auto_increment,\r\n\t\t\t\ttx_str varchar(31) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tpayer_name varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tpayer_email varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tgross float NOT NULL,\r\n\t\t\t\tcurrency varchar(15) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tpayment_status varchar(31) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\ttransaction_type varchar(31) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tdetails text collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tcreated int(11) NOT NULL,\r\n\t\t\t\tUNIQUE KEY  id (id)\r\n\t\t\t);";
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         dbDelta($sql);
     }
 }
Beispiel #12
0
 function install($last_modified)
 {
     global $wp_version;
     // Add / update the version number
     if (get_option('k2version') === false) {
         add_option('k2version', K2_CURRENT, 'This option stores K2\'s version number');
     } else {
         update_option('k2version', K2_CURRENT);
     }
     // Add / update the last modified timestamp
     if (get_option('k2lastmodified') === false) {
         add_option('k2lastmodified', $last_modified, 'This option stores K2\'s last application modification. Used for version checking');
     } else {
         update_option('k2lastmodified', $last_modified);
     }
     if (get_option('k2active') === false) {
         add_option('k2active', 0, 'This option stores if K2 has been activated');
     } else {
         update_option('k2active', 0);
     }
     // Create support folders for WordPressMU
     if (K2_MU) {
         if (!is_dir(ABSPATH . UPLOADS . 'k2support/')) {
             wp_mkdir_p(ABSPATH . UPLOADS . 'k2support/');
         }
         if (!is_dir(K2_STYLES_PATH)) {
             wp_mkdir_p(K2_STYLES_PATH);
         }
         if (!is_dir(K2_HEADERS_PATH)) {
             wp_mkdir_p(K2_HEADERS_PATH);
         }
     }
     // Call the install handlers
     do_action('k2_install');
 }
 public static function save_woff_fonts_css()
 {
     $fonts_dir = WP_CONTENT_DIR . '/uploads/fpd_fonts';
     //create fancy product orders directory
     if (!file_exists($fonts_dir)) {
         wp_mkdir_p($fonts_dir);
     }
     $fonts_css = WP_CONTENT_DIR . '/uploads/fpd_fonts/jquery.fancyProductDesigner-fonts.css';
     chmod($fonts_css, 0775);
     $handle = @fopen($fonts_css, 'w') or print 'Cannot open file:  ' . $fonts_css;
     $files = scandir($fonts_dir);
     $data = '';
     if (is_array($files)) {
         foreach ($files as $file) {
             if (preg_match("/.woff/", $file)) {
                 $new_file = str_replace(' ', '_', $file);
                 rename($fonts_dir . '/' . $file, $fonts_dir . '/' . $new_file);
                 $data .= '@font-face {' . "\n";
                 $data .= '  font-family: "' . preg_replace("/\\.[^.\\s]{3,4}\$/", "", str_replace('_', ' ', $file)) . '";' . "\n";
                 $data .= '  src: local("#"), url("' . content_url('/uploads/fpd_fonts/' . $new_file) . '") format("woff");' . "\n";
                 $data .= '  font-weight: normal;' . "\n";
                 $data .= '  font-style: normal;' . "\n";
                 $data .= '}' . "\n\n\n";
             }
         }
     }
     fwrite($handle, $data);
     fclose($handle);
 }
Beispiel #14
0
/**
 * Get custom styles and store them in custom.css file or use inline css fallback
 * This function will be called by masterslider save handler
 *
 * @return void
 */
function msp_save_custom_styles()
{
    $uploads = wp_upload_dir();
    $css_dir = apply_filters('masterslider_custom_css_dir', $uploads['basedir'] . '/' . MSWP_SLUG);
    $css_file = $css_dir . '/custom.css';
    $css_terms = "/*\n===============================================================\n # CUSTOM CSS\n - Please do not edit this file. this file is generated by server-side code\n - Every changes here will be overwritten\n===============================================================*/\n\n";
    // Get all custom css styles
    $css = msp_get_all_custom_css();
    /**
     * Initialize the WP_Filesystem
     */
    global $wp_filesystem;
    if (empty($wp_filesystem)) {
        require_once ABSPATH . '/wp-admin/includes/file.php';
        WP_Filesystem();
    }
    if (wp_mkdir_p($css_dir) && !$wp_filesystem->put_contents($css_file, $css_terms . $css, 0644)) {
        // if the directory is not writable, try inline css fallback
        msp_update_option('custom_inline_style', $css);
        // save css rules as option to print as inline css
    } else {
        $custom_css_ver = msp_get_option('masterslider_custom_css_ver', '1.0');
        $custom_css_ver = (double) $custom_css_ver + 0.1;
        msp_update_option('masterslider_custom_css_ver', $custom_css_ver);
        // disable inline css output
        msp_update_option('custom_inline_style', '');
    }
}
/**
 * Install woocommerce
 */
function do_install_woocommerce()
{
    global $woocommerce_settings, $woocommerce;
    // Do install
    woocommerce_default_options();
    woocommerce_tables_install();
    woocommerce_install_custom_fields();
    // Register post types
    $woocommerce->init_taxonomy();
    // Add default taxonomies
    woocommerce_default_taxonomies();
    // Install folder for uploading files and prevent hotlinking
    $upload_dir = wp_upload_dir();
    $downloads_url = $upload_dir['basedir'] . '/woocommerce_uploads';
    if (wp_mkdir_p($downloads_url) && !file_exists($downloads_url . '/.htaccess')) {
        if ($file_handle = @fopen($downloads_url . '/.htaccess', 'w')) {
            fwrite($file_handle, 'deny from all');
            fclose($file_handle);
        }
    }
    // Install folder for logs
    $logs_url = WP_PLUGIN_DIR . "/" . plugin_basename(dirname(dirname(__FILE__))) . '/logs';
    if (wp_mkdir_p($logs_url) && !file_exists($logs_url . '/.htaccess')) {
        if ($file_handle = @fopen($logs_url . '/.htaccess', 'w')) {
            fwrite($file_handle, 'deny from all');
            fclose($file_handle);
        }
    }
    // Clear transient cache
    $woocommerce->clear_product_transients();
    // Update version
    update_option("woocommerce_db_version", $woocommerce->version);
}
/**
 * Install woocommerce
 */
function do_install_woocommerce()
{
    global $woocommerce_settings, $woocommerce;
    // Do install
    woocommerce_default_options();
    woocommerce_tables_install();
    woocommerce_default_taxonomies();
    woocommerce_populate_custom_fields();
    // Install folder for uploading files and prevent hotlinking
    $upload_dir = wp_upload_dir();
    $downloads_url = $upload_dir['basedir'] . '/woocommerce_uploads';
    if (wp_mkdir_p($downloads_url) && !file_exists($downloads_url . '/.htaccess')) {
        if ($file_handle = fopen($downloads_url . '/.htaccess', 'w')) {
            fwrite($file_handle, 'deny from all');
            fclose($file_handle);
        }
    }
    // Install folder for logs
    $logs_url = WP_PLUGIN_DIR . "/" . plugin_basename(dirname(dirname(__FILE__))) . '/logs';
    if (wp_mkdir_p($logs_url) && !file_exists($logs_url . '/.htaccess')) {
        if ($file_handle = fopen($logs_url . '/.htaccess', 'w')) {
            fwrite($file_handle, 'deny from all');
            fclose($file_handle);
        }
    }
    // Clear transient cache (if this is an upgrade then woocommerce_class will be defined)
    if ($woocommerce instanceof woocommerce) {
        $woocommerce->clear_product_transients();
    }
    // Update version
    update_option("woocommerce_db_version", $woocommerce->version);
}
/**
 * Creates blank index.php and .htaccess files
 *
 * This function runs approximately once per month in order
 * to ensure all folders have their necessary protection files
 *
 * @access      private
 * @since       1.1.5
 * @return      void
*/
function edd_create_protection_files()
{
    if (false === get_transient('edd_check_protection_files')) {
        $wp_upload_dir = wp_upload_dir();
        $upload_path = $wp_upload_dir['basedir'] . '/edd';
        wp_mkdir_p($upload_path);
        // top level blank index.php
        if (!file_exists($upload_path . '/index.php')) {
            @file_put_contents($upload_path . '/index.php', '<?php' . PHP_EOL . '// silence is golden');
        }
        // top level .htaccess file
        $rules = 'Options -Indexes';
        if (file_exists($upload_path . '/.htaccess')) {
            $contents = @file_get_contents($upload_path . '/.htaccess');
            if (false === strpos($contents, 'Options -Indexes') || !$contents) {
                @file_put_contents($upload_path . '/.htaccess', $rules);
            }
        }
        // now place index.php files in all sub folders
        $folders = edd_scan_folders($upload_path);
        foreach ($folders as $folder) {
            // create index.php, if it doesn't exist
            if (!file_exists($folder . 'index.php')) {
                @file_put_contents($folder . 'index.php', '<?php' . PHP_EOL . '// silence is golden');
            }
        }
        // only have this run the first time. This is just to create .htaccess files in existing folders
        set_transient('edd_check_protection_files', true, 2678400);
    }
}
Beispiel #18
0
function get_image_url($path, $id, $width, $height)
{
    $image_path = $path;
    $upload_directory = wp_upload_dir();
    $modified_image_directory = $upload_directory["basedir"] . "/blog/" . $id . "/";
    if (!file_exists($modified_image_directory)) {
        wp_mkdir_p($modified_image_directory);
    }
    $file_name_with_ending = explode("/", $image_path);
    $file_name_with_ending = $file_name_with_ending[count($file_name_with_ending) - 1];
    $file_name_without_ending = explode(".", $file_name_with_ending);
    $file_ending = $file_name_without_ending[count($file_name_without_ending) - 1];
    $file_name_without_ending = $file_name_without_ending[count($file_name_without_ending) - 2];
    $modified_image_path = $modified_image_directory . md5($file_name_without_ending) . "." . $file_ending;
    if (!file_exists($modified_image_path)) {
        $image = wp_get_image_editor($image_path);
        if (!is_wp_error($image)) {
            $rotate = 180;
            $modified_file_name_without_ending = $file_name_without_ending . "-" . $width . "x" . $height . "-" . $rotate . "dg";
            $image->resize($width, $height);
            $image->rotate($rotate);
            $image->save($modified_file_name_without_ending);
        }
    }
    $modified_image_url = $upload_directory["url"] . "/" . $modified_file_name_without_ending . "." . $file_ending;
    return $modified_image_url;
}
/**
 * Creates blank index.php and .htaccess files
 *
 * This function runs approximately once per month in order to ensure all folders
 * have their necessary protection files
 *
 * @since 1.1.5
 *
 * @param bool $force
 * @param bool $method
 */
function edd_create_protection_files($force = false, $method = false)
{
    if (false === get_transient('edd_check_protection_files') || $force) {
        $upload_path = edd_get_upload_dir();
        // Make sure the /edd folder is created
        wp_mkdir_p($upload_path);
        // Top level .htaccess file
        $rules = edd_get_htaccess_rules($method);
        if (edd_htaccess_exists()) {
            $contents = @file_get_contents($upload_path . '/.htaccess');
            if ($contents !== $rules || !$contents) {
                // Update the .htaccess rules if they don't match
                @file_put_contents($upload_path . '/.htaccess', $rules);
            }
        } elseif (wp_is_writable($upload_path)) {
            // Create the file if it doesn't exist
            @file_put_contents($upload_path . '/.htaccess', $rules);
        }
        // Top level blank index.php
        if (!file_exists($upload_path . '/index.php') && wp_is_writable($upload_path)) {
            @file_put_contents($upload_path . '/index.php', '<?php' . PHP_EOL . '// Silence is golden.');
        }
        // Now place index.php files in all sub folders
        $folders = edd_scan_folders($upload_path);
        foreach ($folders as $folder) {
            // Create index.php, if it doesn't exist
            if (!file_exists($folder . 'index.php') && wp_is_writable($folder)) {
                @file_put_contents($folder . 'index.php', '<?php' . PHP_EOL . '// Silence is golden.');
            }
        }
        // Check for the files once per day
        set_transient('edd_check_protection_files', true, 3600 * 24);
    }
}
 public function register()
 {
     $local_test = false;
     $fpd_css_url = $local_test ? 'http://radykal.dev/fpd3/css/jquery.fancyProductDesigner.css' : plugins_url('/css/jquery.fancyProductDesigner.min.css', FPD_PLUGIN_ROOT_PHP);
     $fpd_js_url = $local_test ? 'http://radykal.dev/fpd3/js/jquery.fancyProductDesigner.js' : plugins_url('/js/jquery.fancyProductDesigner.min.js', FPD_PLUGIN_ROOT_PHP);
     $fpd_js_url = get_option('fpd_debug_mode') == 'yes' ? plugins_url('/js/jquery.fancyProductDesigner.js', FPD_PLUGIN_ROOT_PHP) : $fpd_js_url;
     //register css files
     wp_register_style('fpd-icon-font', plugins_url('/css/icon-font.css', FPD_PLUGIN_ROOT_PHP), false, Fancy_Product_Designer::FPD_VERSION);
     $fonts_dir = WP_CONTENT_DIR . '/uploads/fpd_fonts';
     $fonts_css = $fonts_dir . '/jquery.fancyProductDesigner-fonts.css';
     if (!file_exists($fonts_css)) {
         if (!file_exists($fonts_dir)) {
             wp_mkdir_p($fonts_dir);
         }
         $handle = @fopen($fonts_css, 'w') or print 'Cannot open file:  ' . $fonts_css;
         fclose($handle);
     }
     wp_register_style('fpd-fonts', content_url('/uploads/fpd_fonts/jquery.fancyProductDesigner-fonts.css', FPD_PLUGIN_ROOT_PHP), false, Fancy_Product_Designer::FPD_VERSION);
     wp_register_style('fpd-plugins', plugins_url('/css/plugins.min.css', FPD_PLUGIN_ROOT_PHP), false, Fancy_Product_Designer::FPD_VERSION);
     wp_register_style('fpd-jquery-ui', plugins_url('/css/jquery-ui.css', FPD_PLUGIN_ROOT_PHP), false, Fancy_Product_Designer::FPD_VERSION);
     wp_register_style('jquery-fpd', $fpd_css_url, array('fpd-fonts', 'fpd-jquery-ui'), Fancy_Product_Designer::FPD_VERSION);
     wp_enqueue_style('font-awesome-4', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css', false, '4.3.0');
     wp_register_style('fpd-jssocials-theme', plugins_url('/assets/jssocials/jssocials-theme-flat.css', FPD_PLUGIN_ROOT_PHP), false, '0.2.0');
     wp_register_style('fpd-jssocials', plugins_url('/assets/jssocials/jssocials.css', FPD_PLUGIN_ROOT_PHP), array('font-awesome-4', 'fpd-jssocials-theme'), '0.2.0');
     wp_register_script('fpd-jssocials', plugins_url('/assets/jssocials/jssocials.min.js', FPD_PLUGIN_ROOT_PHP), false, '0.2.0');
     //register js files
     wp_register_script('fpd-plugins', plugins_url('/js/plugins.js', FPD_PLUGIN_ROOT_PHP), false, Fancy_Product_Designer::FPD_VERSION);
     wp_register_script('fabric', plugins_url('/js/fabric.js', FPD_PLUGIN_ROOT_PHP), false, Fancy_Product_Designer::FPD_VERSION);
     wp_register_script('fpd-jquery-form', plugins_url('/js/jquery.form.min.js', FPD_PLUGIN_ROOT_PHP));
     $fpd_dep = array('jquery', 'jquery-ui-draggable', 'jquery-ui-resizable', 'jquery-ui-sortable', 'jquery-ui-slider', 'fabric');
     if (get_option('fpd_debug_mode') == 'yes' || $local_test) {
         array_push($fpd_dep, 'fpd-plugins');
     }
     wp_register_script('jquery-fpd', $fpd_js_url, $fpd_dep, Fancy_Product_Designer::FPD_VERSION);
 }
 /**
  * Setup the backup object
  *
  */
 public function setUp()
 {
     $this->backup = new HM\BackUpWordPress\Backup();
     $this->backup->set_type('database');
     $this->custom_path = WP_CONTENT_DIR . '/custom';
     wp_mkdir_p($this->custom_path);
 }
Beispiel #22
0
 /**
  * nggGallery::get_thumbnail_folder()
  *
  * @param mixed $gallerypath
  * @param bool $include_Abspath
  * @return string $foldername
  */
 static function create_thumbnail_folder($gallerypath, $include_Abspath = TRUE)
 {
     if (!$include_Abspath) {
         $gallerypath = ABSPATH . $gallerypath;
     }
     if (!file_exists($gallerypath)) {
         return FALSE;
     }
     if (is_dir($gallerypath . '/thumbs/')) {
         return '/thumbs/';
     }
     if (is_admin()) {
         if (!is_dir($gallerypath . '/thumbs/')) {
             if (!wp_mkdir_p($gallerypath . '/thumbs/')) {
                 if (SAFE_MODE) {
                     nggAdmin::check_safemode($gallerypath . '/thumbs/');
                 } else {
                     nggGallery::show_error(__('Unable to create directory ', 'nggallery') . $gallerypath . '/thumbs !');
                 }
                 return FALSE;
             }
             return '/thumbs/';
         }
     }
     return FALSE;
 }
Beispiel #23
0
/**
 * Get uploads from the production site and store them
 * in the local filesystem if they don't already exist.
 *
 * @return  void
 */
function uploads_proxy()
{
    global $wp_filesystem;
    WP_Filesystem();
    // The relative request path
    $requestPath = $_SERVER['REQUEST_URI'];
    // The relative uploads path
    $uploadsPath = str_replace(get_bloginfo('url'), '', wp_upload_dir()['baseurl']);
    // Check if a upload was requested
    if (strpos($requestPath, $uploadsPath) === 0) {
        // The absolute remote path to the upload
        $remotePath = UP_SITEURL . $requestPath;
        // Get the remote upload file
        $response = wp_remote_get($remotePath);
        // Check the response code
        if ($response['response']['code'] === 200) {
            // The file path relative to the uploads path to store the upload file to
            $relativeUploadFile = str_replace($uploadsPath, '', $_SERVER['REQUEST_URI']);
            // The absolute file path to store the upload file to
            $absoluteUploadFile = wp_upload_dir()['basedir'] . $relativeUploadFile;
            // Make sure the upload directory exists
            wp_mkdir_p(pathinfo($absoluteUploadFile)['dirname']);
            if ($wp_filesystem->put_contents(urldecode($absoluteUploadFile), $response['body'], FS_CHMOD_FILE)) {
                // Redirect to the stored upload
                wp_redirect($requestPath);
            }
        }
    }
}
 function _handle_logo_upload()
 {
     if (!isset($_FILES['wdeb_logo'])) {
         return false;
     }
     $name = $_FILES['wdeb_logo']['name'];
     if (!$name) {
         return false;
     }
     $allowed = array('jpg', 'jpeg', 'png', 'gif');
     $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
     if (!in_array($ext, $allowed)) {
         wp_die(__('This file type is not supported', 'wdeb'));
     }
     $wp_upload_dir = wp_upload_dir();
     $logo_dir = $wp_upload_dir['basedir'] . '/wdeb';
     $logo_path = $wp_upload_dir['baseurl'] . '/wdeb';
     if (!file_exists($logo_dir)) {
         wp_mkdir_p($logo_dir);
     }
     while (file_exists("{$logo_dir}/{$name}")) {
         $name = rand(0, 9) . $name;
     }
     if (move_uploaded_file($_FILES['wdeb_logo']['tmp_name'], "{$logo_dir}/{$name}")) {
         if (defined('WP_NETWORK_ADMIN') && WP_NETWORK_ADMIN) {
             $opts = $this->data->get_options('wdeb');
             $opts['wdeb_logo'] = "{$logo_path}/{$name}";
             $this->data->set_options($opts, 'wdeb');
         } else {
             update_option('wdeb_logo', "{$logo_path}/{$name}");
         }
     }
 }
 function synved_option_item_addon_install($id, $name, $item)
 {
     $return = null;
     $type = synved_option_item_type($item);
     $target = synved_option_item_property($item, 'target');
     $folder = synved_option_item_property($item, 'folder');
     $field_name = synved_option_name_default($id);
     $path = null;
     if (file_exists($target)) {
         $path = $target;
     }
     if ($type != 'addon' || $path == null) {
         return false;
     }
     $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
     if (substr($path, -1) != DIRECTORY_SEPARATOR) {
         $path .= DIRECTORY_SEPARATOR;
     }
     if (isset($_FILES[$field_name])) {
         foreach ($_FILES[$field_name]["error"] as $key => $error) {
             if ($key == $name && $error == UPLOAD_ERR_OK) {
                 $tmp_name = $_FILES[$field_name]["tmp_name"][$key];
                 $name = $_FILES[$field_name]["name"][$key];
                 $tmpfname = wp_tempnam($name . '.zip');
                 if (move_uploaded_file($tmp_name, $tmpfname)) {
                     global $wp_filesystem;
                     $unzip_path = realpath($path);
                     $dirs = glob($path . '*', GLOB_ONLYDIR);
                     if ($wp_filesystem != null) {
                         $unzip_path = $wp_filesystem->find_folder($unzip_path);
                     }
                     wp_mkdir_p(realpath($path));
                     $return = unzip_file($tmpfname, $unzip_path);
                     if ($wp_filesystem != null) {
                         $wp_filesystem->delete($tmpfname);
                     }
                     $dirs_new = glob($path . '*', GLOB_ONLYDIR);
                     $dirs_diff = array_values(array_diff($dirs_new, $dirs));
                     $addon_path = $path;
                     if ($dirs_diff != null) {
                         $folder_path = null;
                         foreach ($dirs_diff as $dir) {
                             if (basename($dir) == $folder) {
                                 $folder_path = $dir;
                             }
                         }
                         // XXX no correct path, was unzip successful?
                         if ($folder_path == null) {
                             $folder_path = $dirs_diff[0];
                         }
                         $addon_path = $folder_path;
                     }
                     synved_option_set($id, $name, $addon_path);
                 }
             }
         }
     }
     return $return;
 }
 public function get_upload_dir()
 {
     $wp_upload_dir = wp_upload_dir();
     $path = $wp_upload_dir['basedir'] . '/pojo_forms';
     // Make sure the /pojo_forms folder is created
     wp_mkdir_p($path);
     return apply_filters('pojo_forms_upload_folder', $path);
 }
Beispiel #27
0
 private static function get_upload_directory()
 {
     $upload_dir_array = wp_upload_dir();
     $path = $upload_dir_array['basedir'];
     $path = trailingslashit($path) . 'tribe-importer';
     wp_mkdir_p($path);
     return $path;
 }
 /**
  * Setup the backup object and create the tmp directory
  *
  * @access public
  */
 public function setUp()
 {
     $this->backup = new HM_Backup();
     $this->backup->set_root(dirname(__FILE__) . '/test-data/');
     $this->backup->set_path(dirname(__FILE__) . '/tmp');
     hmbkp_rmdirtree($this->backup->get_path());
     wp_mkdir_p($this->backup->get_path());
 }
function wptouch_create_directory_if_not_exist($dir)
{
    if (!file_exists($dir)) {
        // Try and make the directory
        return @wp_mkdir_p($dir);
    }
    return true;
}
Beispiel #30
-1
 /**
  * Generate custom CSS when save theme options
  *
  * @return void
  */
 function generate_css()
 {
     // Update last time saved
     set_theme_mod('last_saved', time());
     $css = '';
     $css .= $this->design_custom_css();
     $css .= $this->custom_color_scheme();
     // Write custom CSS to static file
     $dir = $this->get_dir();
     $file = $dir . $this->file;
     if ($css) {
         wp_mkdir_p($dir);
         // Create directory if it doesn't exists
         // Getting credentials
         $url = wp_nonce_url('themes.php?page=theme-options');
         if (false === ($creds = request_filesystem_credentials($url, '', false, false, null))) {
             return;
         }
         // Try to get the wp_filesystem running
         if (!WP_Filesystem($creds)) {
             // Ask the user for them again
             request_filesystem_credentials($url, '', true, false, null);
             return;
         }
         global $wp_filesystem;
         $wp_filesystem->put_contents($file, $css, FS_CHMOD_FILE);
     } else {
         // Remove file and directory
         @unlink($file);
         @rmdir($dir);
     }
 }