/**
  * Generate a child theme.
  *
  * @since 1.1.0
  */
 public function generate()
 {
     global $wp_filesystem;
     WP_Filesystem();
     $parent = wp_get_theme($this->template);
     if (!$parent->exists()) {
         return new WP_Error('invalid_template', esc_html__('Invalid parent theme slug.', 'audiotheme-agent'));
     }
     $parts = explode('/', $parent->get_template());
     $slug = sprintf('%s-child', reset($parts));
     $directory = path_join($parent->get_theme_root(), $slug);
     if ($wp_filesystem->exists($directory)) {
         return new WP_Error('directory_exists', esc_html__('Child theme directory already exists.', 'audiotheme-agent'));
     }
     if (false === $wp_filesystem->mkdir($directory)) {
         return new WP_Error('fs_error', esc_html__('Could not create child theme directory.', 'audiotheme-agent'));
     }
     $source = audiotheme_agent()->get_path('data/child-theme/');
     copy_dir($source, $directory);
     if ($parent->get_screenshot()) {
         $wp_filesystem->copy(path_join($parent->get_template_directory(), $parent->get_screenshot('relative')), path_join($directory, $parent->get_screenshot('relative')));
     }
     $data = array('{{author}}' => wp_get_current_user()->display_name, '{{author_url}}' => wp_get_current_user()->user_url, '{{name}}' => $parent->get('Name'), '{{slug}}' => $parent->get_template(), '{{url}}' => esc_url(home_url()));
     $files = array('functions.php', 'style.css');
     foreach ($files as $file) {
         $filename = path_join($directory, $file);
         $contents = $wp_filesystem->get_contents($filename);
         $contents = str_replace(array_keys($data), array_values($data), $contents);
         $wp_filesystem->put_contents($filename, $contents);
     }
     return true;
 }
/**
 * 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 eventon_generate_options_css($newdata = '')
{
    /** Define some vars **/
    $data = $newdata;
    $uploads = wp_upload_dir();
    //$css_dir = get_template_directory() . '/css/'; // Shorten code, save 1 call
    $css_dir = AJDE_EVCAL_DIR . '/' . EVENTON_BASE . '/assets/css/';
    //$css_dir = plugin_dir_path( __FILE__ ).  '/assets/css/';
    //echo $css_dir;
    /** Save on different directory if on multisite **/
    if (is_multisite()) {
        $aq_uploads_dir = trailingslashit($uploads['basedir']);
    } else {
        $aq_uploads_dir = $css_dir;
    }
    /** Capture CSS output **/
    ob_start();
    require $css_dir . 'dynamic_styles.php';
    $css = ob_get_clean();
    //print_r($css);
    /** Write to options.css file **/
    WP_Filesystem();
    global $wp_filesystem;
    if (!$wp_filesystem->put_contents($aq_uploads_dir . 'eventon_dynamic_styles.css', $css, 0777)) {
        return true;
    }
}
 /**
  * @throws EE_Error
  * @return WP_Filesystem_Base
  */
 private static function _get_wp_filesystem()
 {
     global $wp_filesystem;
     // no filesystem setup ???
     if (!$wp_filesystem instanceof WP_Filesystem_Base) {
         // if some eager beaver's just trying to get in there too early...
         if (!did_action('wp_loaded')) {
             $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
             if (WP_DEBUG) {
                 $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
             }
             throw new EE_Error($msg);
         } else {
             // should be loaded if we are past the wp_loaded hook...
             if (!function_exists('WP_Filesystem')) {
                 require_once ABSPATH . 'wp-admin/includes/file.php';
             }
             // basically check for direct or previously configured access
             if (!WP_Filesystem()) {
                 // turn on output buffering so that we can capture the credentials form
                 ob_start();
                 $credentials = request_filesystem_credentials('');
                 // store credentials form for the time being
                 EEH_File::$_credentials_form = ob_get_clean();
                 // if credentials do NOT exist
                 if ($credentials === FALSE) {
                     add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
                     throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
                 }
             }
         }
     }
     return $wp_filesystem;
 }
Beispiel #5
0
 protected function _validate_form()
 {
     $url = wp_nonce_url('admin.php?page=vimeography-my-themes');
     if (false === ($creds = request_filesystem_credentials($url))) {
         // if we get here, then we don't have credentials yet,
         // but have just produced a form for the user to fill in,
         // so stop processing for now
         return true;
         // stop the normal page form from displaying
     }
     // now we have some credentials, try to get the wp_filesystem running
     if (!WP_Filesystem($creds)) {
         // our credentials were no good, ask the user for them again
         request_filesystem_credentials($url);
         return true;
     }
     if (empty($_FILES)) {
         return;
     }
     // if this fails, check_admin_referer() will automatically print a "failed" page and die.
     if (!empty($_FILES) && check_admin_referer('vimeography-install-theme', 'vimeography-theme-verification')) {
         $name = substr(wp_filter_nohtml_kses($_FILES['vimeography-theme']['name']), 0, -4);
         if ($_FILES['vimeography-theme']['type'] != 'application/zip') {
             $this->messages[] = array('type' => 'error', 'heading' => 'Ruh Roh.', 'message' => 'Make sure you are uploading the actual .zip file, not a subfolder or file.');
         } else {
             global $wp_filesystem;
             if (!unzip_file($_FILES['vimeography-theme']['tmp_name'], VIMEOGRAPHY_THEME_PATH)) {
                 $this->messages[] = array('type' => 'error', 'heading' => 'Ruh Roh.', 'message' => 'The theme could not be installed.');
             } else {
                 $this->messages[] = array('type' => 'success', 'heading' => 'Theme installed.', 'message' => 'You can now use the "' . $name . '" theme in your galleries.');
             }
         }
     }
 }
 /**
  * put your comment there...
  * 
  */
 public function delete()
 {
     // Initialize.
     WP_Filesystem();
     // initialize vars.
     $wpFileSystem =& $GLOBALS['wp_filesystem'];
     $ids = array();
     $dbDriver = cssJSToolbox::getInstance()->getDBDriver();
     $fsConfig = cssJSToolbox::$config->fileSystem;
     // Import dependencies.
     cssJSToolbox::import('framework:db:mysql:xtable.inc.php');
     CJTxTable::import('template');
     // Delete only templates in "trash" state!
     // For more security don't even delete templates with SYSTEM Attribute flag
     // is turned ON!
     $sysFlag = CJTTemplateTable::ATTRIBUTES_SYSTEM_FLAG;
     $idsQueryList = implode(',', $this->inputs['ids']);
     $templates = $dbDriver->select("SELECT id, queueName `directory`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM #__cjtoolbox_templates \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE ID IN ({$idsQueryList}) AND ((attributes & {$sysFlag}) = 0) AND (`state` = 'trash')");
     if (!empty($templates)) {
         // Deleing template directory files.
         foreach ($templates as $template) {
             // Absolute path to template directory!
             $templateDirectoryAbsPath = WP_CONTENT_DIR . "/{$fsConfig->contentDir}/{$fsConfig->templatesDir}/{$template->directory}";
             // Delete template directory RECUSIVLY!
             $wpFileSystem->rmdir($templateDirectoryAbsPath, true);
         }
         // Get templates IDs to delete.
         $ids = implode(', ', array_keys($templates));
         // Permenantly delete all templates data from
         // templates table and all refernced tables.
         $dbDriver->startTransaction()->delete("DELETE FROM #__cjtoolbox_block_templates WHERE templateId IN ({$ids})")->delete("DELETE FROM #__cjtoolbox_template_revisions WHERE templateId IN ({$ids})")->delete("DELETE FROM #__cjtoolbox_templates WHERE id IN ({$ids})")->commit()->processQueue();
     }
     return $ids;
 }
 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}");
     }
 }
Beispiel #8
0
function export()
{
    global $wpdb;
    $px_table_name = $wpdb->prefix . 'gcm_users';
    $query = "SELECT * FROM {$px_table_name}";
    $datas = $wpdb->get_results($query);
    $url = wp_nonce_url('admin.php?page=px-gcm-export', 'px-gcm-export');
    if (false === ($creds = request_filesystem_credentials($url, '', false, false, null))) {
        return true;
    }
    if (!WP_Filesystem($creds)) {
        // our credentials were not good, ask the user for them again
        request_filesystem_credentials($url, '', true, false, null);
        return true;
    }
    global $wp_filesystem;
    $contentdir = trailingslashit($wp_filesystem->wp_content_dir());
    $in = "Databse ID;GCM Registration ID;Device OS;Device Model;Created At;Messages sent to this Device;\n";
    foreach ($datas as $data) {
        $in .= $data->id . ";" . $data->gcm_regid . ";" . $data->os . ";" . $data->model . ";" . $data->created_at . ";" . $data->send_msg . "\n";
    }
    mb_convert_encoding($in, "ISO-8859-1", "UTF-8");
    if (!$wp_filesystem->put_contents($contentdir . 'GCM-Export.csv', $in, FS_CHMOD_FILE)) {
        echo 'Failed saving file';
    }
    return content_url() . "/GCM-Export.csv";
}
 function __construct()
 {
     // register lazy autoloading
     spl_autoload_register('self::lazy_loader');
     // filter for s3 images
     add_filter('wp_get_attachment_url', array($this, 'wp_get_attachment_url'), 10, 2);
     add_filter('image_downsize', array($this, 'image_downsize'), 10, 2);
     // admin only functionality
     if (is_admin()) {
         // ensure that $wp_filesystem is activated for this plugin
         if (!function_exists('download_url')) {
             require_once ABSPATH . 'wp-admin/includes/file.php';
         }
         global $wp_filesystem;
         WP_Filesystem();
         // enable the settings
         $this->rsrgroup = new WC_RSRGroup_Integration();
         // TODO: fix " Call to undefined function get_plugin_data() "
         // $this->plugin_data = get_plugin_data( __FILE__ );
         $this->path = self::get_plugin_path();
         $this->dir = trailingslashit(basename($this->path));
         $this->url = plugins_url() . '/' . $this->dir;
         add_action('init', array($this, 'load_textdomain'));
         add_action('init', array($this, 'load_custom_fields'));
         add_action('admin_menu', array($this, 'admin_menu'));
         add_filter('manage_upload_columns', array($this, 'manage_upload_columns'));
         add_action('manage_media_custom_column', array($this, 'manage_media_custom_column'), 10, 2);
         add_action('woocommerce_rsrgroup_import_inventory', array($this, 'import_inventory'));
         // WooCommerce actions
         add_action('woocommerce_product_options_pricing', array($this, 'product_options_pricing'));
         add_action('woocommerce_product_options_sku', array($this, 'product_options_sku'));
         add_action('woocommerce_process_product_meta_simple', array($this, 'process_product_meta'));
     }
 }
Beispiel #10
0
/**
 * Upgrade
 *
 * All the functionality for upgrading XT Themes
 *
 * @since 1.0.0
 */
function xt_upgrade()
{
    global $XT_Theme, $wpdb, $wp_filesystem, $post;
    $xt_version_option_key = XT_THEME_ID . '_version';
    $xt_theme = wp_get_theme();
    $old_version = get_option($xt_version_option_key, '1.0.0');
    // false
    $new_version = $XT_Theme->parent_version;
    if ($new_version !== $old_version) {
        /*
         * 1.0.4
         *
         * @created 2015-02-21
         */
        if ($old_version < '1.0.4') {
            $xt_upload_dir = XT_Theme::get_upload_dir();
            if (empty($wp_filesystem)) {
                require_once ABSPATH . '/wp-admin/includes/file.php';
                WP_Filesystem();
            }
            if ($wp_filesystem->is_dir($xt_upload_dir['dir'] . '/assets/')) {
                $wp_filesystem->delete($xt_upload_dir['dir'] . '/assets/', true, 'd');
                $wp_filesystem->delete($xt_upload_dir['dir'] . '/bower_components/', true, 'd');
                $wp_filesystem->delete($xt_upload_dir['dir'] . '/cache/', true, 'd');
            }
            update_option($xt_version_option_key, '1.0.4');
        }
        update_option($xt_version_option_key, $new_version);
        self::sass_compile_flag();
        xt_redirect_after_migration();
    }
}
 public function __construct()
 {
     if (!function_exists('WP_Filesystem')) {
         require_once ABSPATH . 'wp-admin/includes/file.php';
     }
     WP_Filesystem();
 }
 /**
  * Try downloading and saving the image locally and then redirect to it.
  * @param string $img_path Path of the image inside uploads folder
  */
 public function try_download($img_path)
 {
     if (!function_exists('WP_Filesystem')) {
         require ABSPATH . 'wp-admin/includes/file.php';
     }
     global $wp_filesystem;
     WP_Filesystem();
     $mirror_url = $this->get_mirror_url($img_path);
     if ($mirror_url === false) {
         status_header(404);
         exit;
     }
     // Download
     $response = wp_remote_get($mirror_url);
     // Die if not successful.
     if (is_wp_error($response) || 200 !== $response['response']['code']) {
         wp_die(__('Unable to download the file.', 'h1aid'));
     }
     $body = wp_remote_retrieve_body($response);
     $abspath = $this->content_base_dir;
     $destination = trailingslashit($abspath) . $img_path;
     // Save to file system.
     $result = $wp_filesystem->put_contents($destination, $response['body'], FS_CHMOD_FILE);
     // predefined mode settings for WP files
     // Redirect if successful.
     if (true === $result) {
         wp_redirect(trailingslashit($this->content_base_url) . $img_path, 301);
         exit;
     } else {
         wp_die(__('Unable to save file to filesystem.', 'h1aid'));
     }
 }
Beispiel #13
0
 /**
  * Save the submitted image as a temporary file.
  *
  * @todo Revisit file handling.
  *
  * @param string $img Base64 encoded image.
  * @return false|string File name on success, false on failure.
  */
 protected function save_temp_image($img)
 {
     // Strip the "data:image/png;base64," part and decode the image.
     $img = explode(',', $img);
     $img = isset($img[1]) ? base64_decode($img[1]) : base64_decode($img[0]);
     if (!$img) {
         return false;
     }
     // Upload to tmp folder.
     $filename = 'user-feedback-' . date('Y-m-d-H-i');
     $tempfile = wp_tempnam($filename);
     if (!$tempfile) {
         return false;
     }
     // WordPress adds a .tmp file extension, but we want .png.
     if (rename($tempfile, $filename . '.png')) {
         $tempfile = $filename . '.png';
     }
     if (!WP_Filesystem(request_filesystem_credentials(''))) {
         return false;
     }
     /**
      * WordPress Filesystem API.
      *
      * @var \WP_Filesystem_Base $wp_filesystem
      */
     global $wp_filesystem;
     $success = $wp_filesystem->put_contents($tempfile, $img);
     if (!$success) {
         return false;
     }
     return $tempfile;
 }
 /**
  * Save the redirect file
  *
  * @return bool
  */
 public function save_file()
 {
     global $wp_filesystem;
     // Generate file content
     $file_content = $this->generate_file_content();
     if (null == $file_content) {
         return false;
     }
     // Set the filesystem URL
     $url = wp_nonce_url('admin.php?page=wpseo_redirects#top#settings', 'update-htaccess');
     // Get the credentials
     $credentials = request_filesystem_credentials($url, '', false, WPSEO_Redirect_File_Manager::get_htaccess_file_path());
     // Check if WP_Filesystem is working
     if (WP_Filesystem($credentials, WPSEO_Redirect_File_Manager::get_htaccess_file_path())) {
         // Read current htaccess
         $htaccess = '';
         if (file_exists(WPSEO_Redirect_File_Manager::get_htaccess_file_path())) {
             $htaccess = file_get_contents(WPSEO_Redirect_File_Manager::get_htaccess_file_path());
         }
         $htaccess = preg_replace("`# BEGIN YOAST REDIRECTS.*# END YOAST REDIRECTS" . PHP_EOL . "`is", "", $htaccess);
         // New Redirects
         $file_content = "# BEGIN YOAST REDIRECTS" . PHP_EOL . "<IfModule mod_rewrite.c>" . PHP_EOL . "RewriteEngine On" . PHP_EOL . $file_content . "</IfModule>" . PHP_EOL . "# END YOAST REDIRECTS" . PHP_EOL;
         // Prepend our redirects to htaccess file
         $htaccess = $file_content . $htaccess;
         // Update the .htaccess file
         $wp_filesystem->put_contents(WPSEO_Redirect_File_Manager::get_htaccess_file_path(), $htaccess, FS_CHMOD_FILE);
     }
 }
Beispiel #15
0
 /**
  * Parse PDF file
  *
  * @param string $filename
  *
  * @return Document
  */
 public function parseFile($filename)
 {
     global $wp_filesystem;
     WP_Filesystem();
     $content = $wp_filesystem->exists($filename) ? $wp_filesystem->get_contents($filename) : '';
     return $this->parseContent($content);
 }
Beispiel #16
0
 public function install_branch()
 {
     include_once ABSPATH . '/wp-admin/includes/file.php';
     if (get_filesystem_method() === 'direct' && !is_dir(WP_CONTENT_DIR . '/thesis') && is_dir(THESIS_SKINS)) {
         // first, set up wp_filesystem
         WP_Filesystem();
         $f = $GLOBALS['wp_filesystem'];
         // directories
         $directories = array('thesis/', 'thesis/boxes/', 'thesis/packages/', 'thesis/skins/');
         foreach ($directories as $dir) {
             $f->mkdir($f->wp_content_dir() . $dir);
         }
         // master.php
         $f->put_contents($f->wp_content_dir() . 'thesis/master.php', "<?php\n// This is the Thesis master.php file.\n// Use this file to affect every site on your network.\n// Note: this is the last file included in Thesis!\n");
         // move skins
         $from = trailingslashit($f->find_folder(THESIS_SKINS));
         $to = $f->wp_content_dir() . 'thesis/skins/';
         $skins = array_keys($f->dirlist($from));
         foreach ($skins as $skin) {
             $f->move($from . $skin, $to . $skin);
             if (!$f->exists($to . $skin . '/images')) {
                 $f->mkdir($to . $skin . '/images');
             }
             if (!$f->exists($to . $skin . '/custom.php')) {
                 $f->put_contents($to . $skin . '/custom.php', "<?php\n/*\n\tThis file is for skin specific customizations. Be careful not to change your skin's skin.php file as that will be upgraded in the future and your work will be lost.\n\tIf you are more comfortable with PHP, we recommend using the super powerful Thesis Box system to create elements that you can interact with in the Thesis HTML Editor.\n*/");
             }
         }
         // clean up
         if (($lib = array_keys($f->dirlist(THESIS_SKINS))) && empty($lib)) {
             $f->delete(THESIS_SKINS);
         }
     }
 }
 function shoestrap_init_filesystem()
 {
     if (empty($wp_filesystem)) {
         require_once ABSPATH . '/wp-admin/includes/file.php';
         WP_Filesystem();
     }
 }
function at_scroll_plugin_compiler_file($options, $css, $changed_values)
{
    global $wp_filesystem;
    $file_css = dirname(__FILE__) . '/../style/style.css';
    $file_js = dirname(__FILE__) . '/../js/init.js';
    $data = $options;
    ob_start();
    // Capture all output (output buffering)
    require 'style.php';
    // Generate CSS
    $css_file_content = ob_get_clean();
    // Get generated CSS (output buffering)
    ob_end_flush();
    ob_start();
    // Capture all output (output buffering)
    require 'init.js.php';
    // Generate js
    $js_file_content = ob_get_clean();
    // Get generated js (output buffering)
    ob_end_flush();
    if (empty($wp_filesystem)) {
        require_once ABSPATH . '/wp-admin/includes/file.php';
        WP_Filesystem();
    }
    if ($wp_filesystem) {
        $wp_filesystem->put_contents($file_css, $css_file_content, FS_CHMOD_FILE);
        $wp_filesystem->put_contents($file_js, $js_file_content, FS_CHMOD_FILE);
    }
}
 /**
  * _request_filesystem_credentials
  * if attempting to enable full logging, WordPress may require filesystem credentials for FTP or SSH depending on the server
  *
  * @access   protected
  * @param bool $show_errors
  * @return bool
  */
 protected function _request_filesystem_credentials($show_errors = TRUE)
 {
     require_once ABSPATH . 'wp-admin/includes/file.php';
     $url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'request_filesystem_credentials'), $this->_admin_base_url);
     $credentials = request_filesystem_credentials($url);
     if ($credentials == FALSE) {
         if ($show_errors) {
             EE_Error::get_notices(FALSE);
             EE_Error::reset_notices();
             EE_Error::add_error(__('Connection settings are missing or incorrect. Please verify that the connection settings below are correct.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
             add_filter('FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', '__return_false');
         }
         return FALSE;
     }
     // now we have some credentials, try to get the wp_filesystem running
     $WP_Filesystem = WP_Filesystem($credentials);
     if (!$WP_Filesystem) {
         if ($show_errors) {
             EE_Error::get_notices(FALSE);
             EE_Error::reset_notices();
             EE_Error::add_error(__('There was an error connecting to the server. Please verify that the connection settings below are correct.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
             add_filter('FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', '__return_false');
         }
         // our credentials were no good, ask the user for them again
         request_filesystem_credentials($url);
         return FALSE;
     }
     EE_Registry::instance()->CFG->admin->use_full_logging = TRUE;
     return TRUE;
 }
Beispiel #20
0
/**
 * Move the framework to the plugins directory.
 *
 * @since 1.2.0
 */
function audiotheme_framework_not_a_theme()
{
    global $wp_filesystem;
    if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'audiotheme-theme-to-plugin')) {
        return false;
    }
    $move_url = wp_nonce_url('themes.php', 'audiotheme-theme-to-plugin');
    if (false === ($credentials = request_filesystem_credentials($move_url))) {
        return true;
    }
    if (!WP_Filesystem($credentials)) {
        // Credentials weren't good, ask again.
        request_filesystem_credentials($move_url);
        return true;
    }
    $plugin_dir = $wp_filesystem->wp_plugins_dir() . 'audiotheme/';
    $theme_dir = trailingslashit(get_template_directory());
    // Check if the framework plugin directory already exists.
    if (is_dir($plugin_dir)) {
        $redirect = add_query_arg('atmovemsg', 'plugin-exists', admin_url('themes.php'));
        wp_safe_redirect(esc_url_raw($redirect));
        exit;
    }
    // Move the plugin.
    if ($wp_filesystem->move($theme_dir, $plugin_dir)) {
        // @todo Any way to re-activate the previous theme?
        wp_safe_redirect(esc_url_raw(admin_url('plugins.php')));
        exit;
    } else {
        $redirect = add_query_arg('atmovemsg', 'move-failed', admin_url('themes.php'));
        wp_safe_redirect(esc_url_raw($redirect));
        exit;
    }
}
 /**
  * Get the google fonts from the API or in the cache
  */
 public function get_fonts($amount = 500)
 {
     $selectDirectory = get_template_directory() . '/inc/customizer/';
     $selectDirectoryInc = get_template_directory() . '/inc/customizer/';
     $finalselectDirectory = '';
     if (is_dir($selectDirectory)) {
         $finalselectDirectory = $selectDirectory;
     }
     if (is_dir($selectDirectoryInc)) {
         $finalselectDirectory = $selectDirectoryInc;
     }
     $fontFile = $finalselectDirectory . '/json/google-web-fonts.json';
     if (file_exists($fontFile)) {
         global $wp_filesystem;
         if (empty($wp_filesystem)) {
             tokopress_include_file(ABSPATH . '/wp-admin/includes/file.php');
             WP_Filesystem();
         }
         $content = json_decode($wp_filesystem->get_contents($fontFile));
     }
     if ($amount == 'all') {
         return $content->items;
     } else {
         return array_slice($content->items, 0, $amount);
     }
 }
 function download_extension()
 {
     extract($_REQUEST);
     if (isset($item)) {
         //$extension_file_name = (isset($_REQUEST['zip'])) ? $_REQUEST['zip']."/{$item}.zip" : $this->downloads_dir."/{$item}.zip";
         //$extension_file_name = $this->edd_dir."{$item}.zip";
         $extension_file_name = $this->edd_dir . "{$item}";
         //$extension_file_name = file_exists( $extension_file_name )? $extension_file_name : "{$this->downloads_dir}{$item}.zip";
         $body = array();
         if (file_exists($extension_file_name)) {
             if (!function_exists('WP_Filesystem')) {
                 require_once ABSPATH . 'wp-admin/includes/file.php';
             }
             WP_Filesystem();
             global $wp_filesystem;
             $content = $wp_filesystem->get_contents($extension_file_name);
             $content = runway_base_encode($content);
             $body['success'] = true;
             $body['content'] = $content;
             $body['error_message'] = '';
         } else {
             $body['success'] = false;
             $body['content'] = '';
             $body['error_message'] = __('File <b>', 'framework') . $item . '</b> ' . __('not found on server', 'framework');
         }
         echo json_encode($body);
     }
     die;
 }
Beispiel #23
0
function fetch_pocket_count($url)
{
    if (WP_Filesystem()) {
        //WP_Filesystemの初期化
        global $wp_filesystem;
        //$wp_filesystemオブジェクトの呼び出し
        $query = 'http://widgets.getpocket.com/v1/button?v=1&count=horizontal&url=' . $url;
        //URL(クエリ)先の情報を取得
        $result = wp_remote_get($query);
        //var_dump($result["body"]);
        // 正規表現でカウント数のところだけを抽出
        preg_match('/<em id="cnt">([0-9.]+)<\\/em>/i', $result["body"], $count);
        // 共有数を表示
        return isset($count[1]) ? intval($count[1]) : 0;
        // //$wp_filesystemオブジェクトのメソッドとして呼び出す
        // $html = $wp_filesystem->get_contents($query);
        // $dom = new DOMDocument('1.0', 'UTF-8');
        // $dom->preserveWhiteSpace = false;
        // $dom->loadHTML($html);
        // $xpath = new DOMXPath($dom);
        // $result = $xpath->query('//em[@id = "cnt"]')->item(0);
        // return isset($result->nodeValue) ? intval($result->nodeValue) : 0;
    }
    return 0;
}
Beispiel #24
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', '');
    }
}
Beispiel #25
0
 private function update_plugins()
 {
     global $king, $wp_filesystem;
     require_once ABSPATH . 'wp-admin/includes/file.php';
     $fields = array('action', '_wp_http_referer', '_wpnonce');
     $canUnZip = false;
     if (false !== ($creds = request_filesystem_credentials('', '', false, false, $fields))) {
         if (!WP_Filesystem($creds)) {
             request_filesystem_credentials($url, $method, true, false, $fields);
         } else {
             $canUnZip = true;
         }
     }
     if ($canUnZip == true) {
         $direct = ABSPATH . DS . 'wp-content' . DS . 'plugins';
         $path = THEME_PATH . DS . 'core' . DS . 'sample' . DS . 'plugins' . DS;
         $plugins = array('linstar-helper', 'LayerSlider', 'contact-form-7', 'js_composer');
         foreach ($plugins as $plugin) {
             $tmpfile = $path . $plugin . '.zip';
             if (!is_dir($direct . DS . $plugin)) {
                 unzip_file($tmpfile, $direct);
             } else {
                 @rename($direct . DS . $plugin, $direct . DS . $plugin . '_tmpl');
                 if (unzip_file($tmpfile, $direct)) {
                     self::removeDir($direct . DS . $plugin . '_tmpl');
                 } else {
                     @rename($direct . DS . $plugin . '_tmpl', $direct . DS . $plugin);
                 }
             }
         }
         //end foreach
     }
     //end if canUnZip
 }
 /**
  *  __construct
  *
  *  @since	1.0.0
  */
 function __construct()
 {
     // Vars
     global $wp_filesystem;
     if (empty($wp_filesystem)) {
         require_once ABSPATH . '/wp-admin/includes/file.php';
         WP_Filesystem();
     }
     $this->name = 'fonticonpicker';
     $this->label = __('Icon Picker', 'acf');
     $this->category = __("jQuery", 'acf');
     $this->defaults = array('allow_null' => 0);
     $this->l10n = array();
     parent::__construct();
     // Settings
     $this->settings = array('dir' => get_template_directory_uri() . '/inc/includes/acf-fonticonpicker', 'path' => get_template_directory() . '/inc/includes/acf-fonticonpicker', 'config' => get_template_directory() . '/inc/includes/acf-fonticonpicker', 'icons' => get_template_directory_uri() . '/inc/includes/acf-fonticonpicker/icons/style.css', 'version' => '1.0.0');
     // Apply a filter so that you can load icon set from theme
     $this->settings = apply_filters('acf/acf_field_fonticonpicker/settings', $this->settings);
     // Enqueue icons style in the frontend
     add_action('wp_enqueue_scripts', array($this, 'frontend_enqueue'));
     // Load icons list from the icons JSON file
     if (is_admin()) {
         $json_file = trailingslashit($this->settings['config']) . '/icons/selection.json';
         if ($wp_filesystem->exists($json_file)) {
             $json_content = $wp_filesystem->get_contents($json_file);
             if (!$json_content) {
                 return new WP_Error('reading_error', 'Error when reading file');
             }
             $this->json_content = json_decode($json_content, true);
         }
     }
 }
Beispiel #27
0
 function log($message = '', $type = 'notice')
 {
     global $wp_filesystem;
     WP_Filesystem();
     // if we're not active, don't do anything
     if (!$this->active || !file_exists($this->logfile)) {
         return false;
     }
     // get the existing log
     $existing = $wp_filesystem->get_contents($this->logfile);
     // format our entry
     $entry = '[' . date('Y-d-m G:i:s', current_time('timestamp')) . '][' . sanitize_text_field($type) . ']';
     // flag it with the process ID
     $entry .= '[' . SearchWP::instance()->getPid() . ']';
     // sanitize the message
     $message = sanitize_text_field(esc_html($message));
     $message = str_replace('=&gt;', '=>', $message);
     // put back array identifiers
     $message = str_replace('-&gt;', '->', $message);
     // put back property identifiers
     $message = str_replace('&#039;', "'", $message);
     // put back apostrophe's
     // finally append the message
     $entry .= ' ' . $message;
     // append the entry
     $log = $existing . "\n" . $entry;
     // write log
     $wp_filesystem->put_contents($this->logfile, $log);
     error_log($log);
 }
Beispiel #28
0
function sixscan_htaccess_uninstall()
{
    global $wp_filesystem;
    if ($wp_filesystem == NULL) {
        WP_Filesystem();
    }
    $is_direct = $wp_filesystem->method == 'direct';
    $local_htaccess_path = sixscan_common_get_htaccess_file_path($is_direct);
    try {
        if ($wp_filesystem->exists($local_htaccess_path)) {
            $htaccess_content = $wp_filesystem->get_contents($local_htaccess_path);
            $a = preg_replace('@# Created by 6Scan plugin(.*?)# End of 6Scan plugin@s', '', $htaccess_content);
            if ($wp_filesystem->put_contents($local_htaccess_path, $a) === FALSE) {
                throw new Exception('Failed to open htaccess during installation');
            }
        }
        if ($wp_filesystem->exists(sixscan_common_get_htaccess_dest_path($is_direct))) {
            $wp_filesystem->delete(sixscan_common_get_htaccess_dest_path($is_direct));
        }
        if ($wp_filesystem->exists(sixscan_common_get_signature_dest_path($is_direct))) {
            $wp_filesystem->delete(sixscan_common_get_signature_dest_path($is_direct));
        }
    } catch (Exception $e) {
        return $e;
    }
    return TRUE;
}
 function filesystem_init($form_url, $method = '', $context = false, $fields = null)
 {
     global $wp_filesystem;
     if (!empty($this->creds)) {
         return true;
     }
     ob_start();
     /* dESiGNERz-CREW.iNFO for PRO users - first attempt to get credentials */
     if (false === ($this->creds = request_filesystem_credentials($form_url, $method, false, $context))) {
         $this->creds = array();
         $this->parent->ftp_form = ob_get_contents();
         ob_end_clean();
         /**
          * if we comes here - we don't have credentials
          * so the request for them is displaying
          * no need for further processing
          **/
         return false;
     }
     /* dESiGNERz-CREW.iNFO for PRO users - now we got some credentials - try to use them*/
     if (!WP_Filesystem($this->creds)) {
         $this->creds = array();
         /* dESiGNERz-CREW.iNFO for PRO users - incorrect connection data - ask for credentials again, now with error message */
         request_filesystem_credentials($form_url, '', true, $context);
         $this->parent->ftp_form = ob_get_contents();
         ob_end_clean();
         return false;
     }
     return true;
 }
 function shoestrap_makecss($method = 'php')
 {
     global $wp_filesystem;
     $file = shoestrap_css();
     // Initialize the Wordpress filesystem, no more using file_put_contents function
     if (empty($wp_filesystem)) {
         require_once ABSPATH . '/wp-admin/includes/file.php';
         WP_Filesystem();
     }
     $content = ac_compiler_get_top_message();
     $content .= shoestrap_compiler();
     if (is_writeable($file) || !file_exists($file) && is_writeable(dirname($file))) {
         if (!$wp_filesystem->put_contents($file, $content, FS_CHMOD_FILE)) {
             return apply_filters('shoestrap_css_output', $content);
         }
     }
     // Now create the Alleycat.css file
     $file = get_template_directory() . '/assets/css/alleycat.css';
     $content = ac_compiler_get_top_message();
     $content .= alleycat_compiler();
     if (is_writeable($file) || !file_exists($file) && is_writeable(dirname($file))) {
         if (!$wp_filesystem->put_contents($file, $content, FS_CHMOD_FILE)) {
             return apply_filters('shoestrap_css_output', $content);
         }
     }
 }