properties();
if (!$list['nb'])
return false;
//echo "Number of files in archive : ".$list['nb']." ";
echo "Copying the files ";
$result = $unzipArchive->extract(PCLZIP_OPT_PATH, $dir);
if ($result == 0) {
echo 'Could not unarchive the file: ' . $unzipArchive->errorInfo(true) . ' ';
return false;
} else {
//print_r($result);
foreach ($result as $item) {
if ($item['status'] != 'ok')
echo $item['stored_filename'] . ' ... ' . $item['status'] . ' ';
}
return true;
}
}
function themedrive_handle_theme_liberal($package)
{
echo "Downloading the theme from " . $package . " ";
$file = download_url($package);
if (is_wp_error($file)) {
echo 'Download failed: ' . $file->get_error_message();
return;
}
echo "Unpacking the theme ";
// Unzip theme to theme directory
//theme dir
$result = themedrive_unzip($file, ABSPATH . "wp-content/themes/");
// Once extracted, delete the package
unlink($file);
if ($result)
echo " Theme installed successfully.
";
else {
echo " Error installing the theme.
You can try installing the theme manually: $package
";
}
return;
}
function themedrive_handle_theme_rigid($package)
{
global $wp_filesystem;
if (!$wp_filesystem || !is_object($wp_filesystem))
WP_Filesystem($credentials);
if (!is_object($wp_filesystem)) {
echo 'Could not access filesystem.
';
return;
}
$working_dir = $base . 'wp-content/upgrade/themes';
// Clean up working directory
if ($wp_filesystem->is_dir($working_dir))
$wp_filesystem->delete($working_dir, true);
echo "Unpacking the theme ";
// Unzip package to theme directory
$result = unzip_file($file, $working_dir);
if (is_wp_error($result)) {
unlink($file);
$wp_filesystem->delete($working_dir, true);
echo 'Unpack failed : ' . $result->get_error_message() . '
';
return;
}
echo "Installing the theme ";
// Copy new version of plugin into place.
if (!copy_dir($working_dir, $base . "wp-content/themes")) {
//TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails.
$wp_filesystem->delete($working_dir, true);
echo 'Installation failed (theme already installed?)
';
return;
}
//Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
$filelist = array_keys($wp_filesystem->dirlist($working_dir));
// Remove working directory
$wp_filesystem->delete($working_dir, true);
// Once extracted, delete the package
unlink($file);
echo "Theme installed successfully.
";
return;
}
function themedrive_get_theme()
{
$gettheme = get_option('td_themes');
if (!empty($gettheme)) {
return $gettheme;
} else {
return '';
}
}
function themedrive_get_level()
{
$getlevel = get_option('td_level');
if ($getlevel!='') {
return 'level_' . $getlevel;
} else {
return 'level_10';
}
}
function themedrive_determine_theme()
{
if (!isset($_GET['theme'])) {
if (!current_user_can(themedrive_get_level())) {
// not admin
return false;
} else {
$theme = themedrive_get_theme();
if ($theme == '') {
// no admin-only theme defined, short-circuit out
return false;
}
}
}
$all = $_GET + $_POST;
if (isset($all['theme'])) {
$theme = $all['theme'];
}
$theme_data = get_theme($theme);
if (!empty($theme_data)) {
// Don't let people peek at unpublished themes
if (isset($theme_data['Status']) && $theme_data['Status'] != 'publish') {
return false;
}
return $theme_data;
}
// perhaps they are using the theme directory instead of title
$themes = get_themes();
foreach ($themes as $theme_data) {
// use Stylesheet as it's unique to the theme - Template could point to another theme's templates
if ($theme_data['Stylesheet'] == $theme) {
// Don't let people peek at unpublished themes
if (isset($theme_data['Status']) && $theme_data['Status'] != 'publish') {
return false;
}
return $theme_data;
}
}
return false;
}
function themedrive_get_template($template)
{
$theme = themedrive_determine_theme();
if ($theme === false) {
return $template;
}
return $theme['Template'];
}
function themedrive_get_stylesheet($stylesheet)
{
$theme = themedrive_determine_theme();
if ($theme === false) {
return $stylesheet;
}
return $theme['Stylesheet'];
}
function themedrive_switcher()
{
$themes = get_themes();
$default_theme = get_current_theme();
if (count($themes) > 1) {
$theme_names = array_keys($themes);
natcasesort($theme_names);
$ts = '