/**
  * Display an admin notice to install the default pages if wanted
  */
 public function display_notice()
 {
     // delete_option( '_wolf_' . wolf_get_theme_slug() . '_default_pages' );
     if (!get_option('_wolf_' . wolf_get_theme_slug() . '_default_pages') && array() != $this->default_posts) {
         $default_pages_install_message = sprintf(__('You can install default pages to help you to get started with <strong>%s</strong> theme.', 'wolf'), WOLF_THEME_NAME);
         if (function_exists('wolf_theme_register_required_plugins')) {
             $default_pages_install_message .= '<br>' . __('<strong>It is recommended to install and activate the plugins you need from the recommended plugins list first</strong>, in order to install the default pages accordingly.', 'wolf') . '<br>';
         }
         $default_pages_install_message .= '<br>' . sprintf(__('<a href="%1$s" class="button-primary">Install default pages</a> <a href="%2$s" class="button">Dismiss this message</a>', 'wolf'), esc_url(admin_url('index.php?wolf-default-pages=true')), esc_url(admin_url('index.php?wolf-default-pages=false')));
         wolf_admin_notice($default_pages_install_message, 'updated', true);
         return false;
     }
 }
 /**
  * Get data from uploaded zip file
  */
 public function get_data()
 {
     $data = array();
     if (isset($_POST['import-submit'])) {
         if (!empty($_FILES['import-zip']['name'])) {
             $options_file = null;
             $widgets_file = null;
             $content_file = null;
             $file_content = null;
             $tmp_dir = WOLF_THEME_TMP_DIR;
             $file = $_FILES['import-zip'];
             $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
             $folder_name = str_replace('.' . $ext, '', $file['name']);
             if ('zip' != $ext) {
                 // error not zip file
                 $message = __('It seems that you are trying to upload the wrong file. It must be a zip archive containing the demo data files.', 'wolf');
                 wolf_admin_notice($message, 'error');
             } else {
                 // Go
                 $zip = new ZipArchive();
                 if ($zip->open($file['tmp_name']) === TRUE) {
                     $zip->extractTo($tmp_dir);
                     $zip->close();
                     $tmp_folder_path = $tmp_dir . '/' . $folder_name;
                     // get text file
                     foreach (glob($tmp_folder_path . '/*.txt') as $filename) {
                         $options_file = $filename;
                         break;
                     }
                     // get json file
                     foreach (glob($tmp_folder_path . '/*.json') as $filename) {
                         $widgets_file = $filename;
                         break;
                     }
                     // get content file
                     foreach (glob($tmp_folder_path . '/*.xml') as $filename) {
                         $content_file = $filename;
                         break;
                     }
                     if (!$options_file || !$widgets_file || !$content_file) {
                         // error no files in zip
                         $message = __('We couldn\'t find the right files in the archives. Please be sure that you have selected the right zip file.', 'wolf');
                         wolf_admin_notice($message, 'error');
                     } else {
                         // all good, return the data in an array
                         $data['options_file'] = $options_file;
                         $data['widgets_file'] = $widgets_file;
                         $data['content_file'] = $content_file;
                         $this->import_content = isset($_POST['import_content']);
                         $this->import_widgets = isset($_POST['import_widgets']);
                         $this->import_settings = isset($_POST['import_settings']);
                         return $data;
                     }
                 } else {
                     // error unknown
                     $message = __('We couldn\'t import the demo data.', 'wolf');
                     $message .= $this->fallback_error_message();
                     wolf_admin_notice($message, 'error');
                     return false;
                 }
             }
         } else {
             // error no file
             $message = __('Please select a file to upload', 'wolf');
             wolf_admin_notice($message, 'error');
             return false;
         }
     }
 }
 /**
  * Unzip files in tmp folder, then replace the files
  *
  * @param string $file
  * @return bool
  */
 public function unzip($file)
 {
     $this->theme_dir = WOLF_THEME_DIR;
     $this->tmp_dir = WOLF_THEME_DIR . '/tmp';
     wolf_clean_folder($this->tmp_dir);
     // ensure that the tmp folder is empty
     $file_path = $file['tmp_name'];
     $zip = new ZipArchive();
     $res = $zip->open($file_path);
     if ($res === TRUE) {
         $zip->extractTo($this->tmp_dir);
         $zip->close();
         $this->recurse_copy($this->tmp_dir . '/' . wolf_get_theme_slug(), $this->theme_dir);
         wolf_clean_folder($this->tmp_dir);
         $this->remove_deprecated_files($this->theme_dir);
         return true;
     } else {
         $message = __('An occur occured while trying to update the theme.', 'wolf');
         wolf_admin_notice($message, 'error');
         return false;
     }
 }
 /**
  * Add an update or error notice to the dashboard when needed
  */
 public function display_notice()
 {
     global $pagenow;
     // Theme update notifications
     if ($pagenow == 'index.php') {
         wolf_theme_update_notification_message();
     }
     if (WOLF_ERROR_NOTICES) {
         /* Error notices
           	--------------------------------------------------------*/
         // No cURL
         $no_cURL = __('The <strong>cURL</strong> extension is not installed on your server. This extension is required to display theme update notifications.', 'wolf');
         if (!function_exists('curl_init')) {
             wolf_admin_notice($no_cURL, 'error', true, 'no_cURL');
         }
         // No GD library
         $no_GD_library = __('The <strong>GD library</strong> extension is not installed on your server. This extension is essential to Wordpress to be able to resize your images. Please contact your hosting service for more informations.', 'wolf');
         if (!extension_loaded('gd') && !function_exists('gd_info')) {
             wolf_admin_notice($no_GD_library, 'error', true, 'no_GD_library');
         }
     }
     /* Always display wrong theme installation notice
       	-------------------------------------------------------------------*/
     /* Incorect Installation */
     $wrong_install = sprintf(__('It seems that <strong>the theme has been installed incorrectly</strong>. Go <a href="%s" target="_blank">here</a> to find instructions about theme installation.', 'wolf'), 'http://wolfthemes.com/common-wordpress-theme-issues/');
     $wolf_wp_themes_folder = basename(dirname(dirname(dirname(__FILE__))));
     if ($wolf_wp_themes_folder != 'themes') {
         wolf_admin_notice($wrong_install, 'error');
     }
     return false;
 }
Example #5
0
function wolf_save_theme_css()
{
    if (isset($_POST['wolf-theme-css-save'])) {
        //debug( $_POST );
        update_option('wolf_theme_css_' . wolf_get_theme_slug(), $_POST['wolf_theme_css']);
        wolf_admin_notice(__('Your settings have been saved.', 'wolf'), 'updated');
    }
    /**
     * Back from WpAdmin construct in case of WPML
     */
    if (isset($_GET['message']) && 'save' == $_GET['message'] && isset($_GET['page']) && $_GET['page'] == 'wolf-theme-css') {
        wolf_admin_notice(__('Your settings have been saved.', 'wolf'), 'updated');
    }
}
 /**
  * Import options from zip file or txt file
  */
 public function import_options()
 {
     if (isset($_POST['wolf-options-import-file-submit'])) {
         if (!empty($_FILES['wolf-options-import-file']['name'])) {
             $txt_file = null;
             $file_content = null;
             $tmp_dir = WOLF_THEME_TMP_DIR;
             $file = $_FILES['wolf-options-import-file'];
             $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
             $folder_name = str_replace('.' . $ext, '', $file['name']);
             if ('zip' != $ext && 'txt' != $ext) {
                 $message = __('Only .txt file or zip file containing a text file are allowed', 'wolf');
                 wolf_admin_notice($message, 'error');
             } else {
                 // Go
                 if ('zip' == $ext) {
                     // unzip file
                     $zip = new ZipArchive();
                     if ($zip->open($file['tmp_name']) === TRUE) {
                         $zip->extractTo($tmp_dir);
                         $zip->close();
                         $tmp_folder = $tmp_dir;
                         if (is_dir($tmp_dir . '/' . $folder_name)) {
                             $tmp_folder = $tmp_dir . '/' . $folder_name;
                         }
                         // get text file
                         foreach (glob($tmp_folder . '/*.txt') as $filename) {
                             $txt_file = $filename;
                             break;
                         }
                         if ($txt_file) {
                             $file_content = file_get_contents($txt_file);
                         } else {
                             $message = __('It seems that your archive is empty or does not contain a txt file', 'wolf');
                             wolf_admin_notice($message, 'error');
                         }
                     } else {
                         $message = __('We could not import the theme options', 'wolf');
                         wolf_admin_notice($message, 'error');
                     }
                 } elseif ('txt' == $ext) {
                     $file_content = file_get_contents($file['tmp_name']);
                 }
                 if ('' != $file_content) {
                     // debug( $file_content );
                     $data = @unserialize(base64_decode($file_content));
                     if ($data && is_array($data)) {
                         update_option('wolf_theme_options_' . wolf_get_theme_slug(), $data);
                         wolf_admin_notice(__('New options imported successfully', 'wolf'), 'updated');
                     } else {
                         wolf_admin_notice(__('The file doesn\'t seem to contain any options.', 'wolf'), 'updated');
                     }
                 } else {
                     $message = __('Looks like your text file is empty', 'wolf');
                     wolf_admin_notice($message, 'error');
                 }
                 // clean tmp folder
                 wolf_clean_folder($tmp_dir);
             }
         } else {
             $message = __('Please Select a file to upload', 'wolf');
             wolf_admin_notice($message, 'error');
         }
         return false;
     }
 }
 /**
  * Check if a folder exists and is writable
  *
  * @param
  * @return
  */
 function wolf_check_folder($dir)
 {
     $message = null;
     $result = true;
     $error_id = '';
     if (is_writable($dir)) {
         $result = true;
     }
     if (is_dir($dir) && !is_writable($dir)) {
         if (chmod($dir, 775)) {
             $result = true;
         } else {
             $message = sprintf(__('The <strong>%1$s</strong> directory has to be writable. Please set the folder permission to 775 through your FTP client <br>or with the command line <strong>chmod 775 %2$s</strong>', 'wolf'), $dir, $dir);
             $error_id = 'error_' . $dir . '_dir_permission';
             $result = false;
         }
     } elseif (!is_dir($dir)) {
         $old_mask = umask(0);
         if (!mkdir($dir, 775)) {
             $message = sprintf(__('Error while trying to find the folder <strong>%1$s</strong>. Please create it manually and set the permission to 775 through your FTP client<br>or with the command line <strong>mkdir -m 775 %2$s</strong>', 'wolf'), $dir, $dir);
             $error_id = 'error_' . $dir . '_dir';
             $result = false;
         }
         umask($old_mask);
     }
     if (false == $result) {
         wolf_admin_notice($message, 'error', true, $error_id);
     }
     return $result;
 }