예제 #1
0
 /**
  * Check if files can be upgraded
  *
  * @param string $path files path
  * @param array $hash_table table with hashes of original files
  * @param array $result resulting array
  * @param string $package package to check files from
  * @param array $custom_theme_files list of custom theme files
  * @return boolean always true
  */
 function fn_uc_check_files($path, $hash_table, &$result, $package, $custom_theme_files)
 {
     // Simple copy for a file
     if (is_file($path)) {
         // Get original file name
         $original_file = str_replace(Registry::get('config.dir.upgrade') . $package . '/package/', Registry::get('config.dir.root') . '/', $path);
         $relative_file = str_replace(Registry::get('config.dir.root') . '/', '', $original_file);
         $file_name = fn_basename($original_file);
         if (file_exists($original_file)) {
             if (md5_file($original_file) != md5_file($path)) {
                 $_relative_file = $relative_file;
                 // For themes, convert relative path to themes_repository
                 if (strpos($relative_file, 'design/themes/') === 0) {
                     $_relative_file = str_replace('design/themes/', 'var/themes_repository/', $relative_file);
                     // replace all themes except base
                     if (fn_uc_check_array_value($relative_file, $custom_theme_files) && strpos($relative_file, '/' . Registry::get('config.base_theme') . '/') === false) {
                         $_relative_file = preg_replace('!design/\\themes/([\\w]+)/!S', 'var/themes_repository/${1}/', $relative_file);
                     }
                 }
                 if (!empty($hash_table[$_relative_file])) {
                     if (md5_file($original_file) != $hash_table[$_relative_file]) {
                         $result['changed'][] = $relative_file;
                     }
                 } else {
                     $result['changed'][] = $relative_file;
                 }
             }
         } else {
             $result['new'][] = $relative_file;
         }
         return true;
     }
     if (is_dir($path)) {
         $dir = dir($path);
         while (false !== ($entry = $dir->read())) {
             if ($entry == '.' || $entry == '..') {
                 continue;
             }
             fn_uc_check_files(rtrim($path, '/') . '/' . $entry, $hash_table, $result, $package, $custom_theme_files);
         }
         // Clean up
         $dir->close();
         return true;
     } else {
         fn_set_notification('E', __('error'), __('text_uc_incorrect_upgrade_path'));
         return false;
     }
 }
예제 #2
0
 public static function checkUpgradePermissions($upgrade_dirs, $is_writable = true)
 {
     foreach ($upgrade_dirs as $upgrade_dir) {
         if (is_array($upgrade_dir)) {
             $is_writable = self::checkUpgradePermissions($upgrade_dir, $is_writable);
         } elseif (!is_dir($upgrade_dir)) {
             fn_uc_mkdir($upgrade_dir);
             self::checkUpgradePermissions(array($upgrade_dir), $is_writable);
         } elseif (!self::isWritableDest($upgrade_dir)) {
             return false;
         }
         if (!is_array($upgrade_dir)) {
             $check_result = array();
             fn_uc_check_files($upgrade_dir, array(), $check_result, '', '');
             $is_writable = empty($check_result);
         }
         if (!$is_writable) {
             break;
         }
     }
     return $is_writable;
 }
예제 #3
0
/**
 * Check if files can be upgraded
 *
 * @param string $path files path
 * @param array $hash_table table with hashes of original files
 * @param array $result resulting array
 * @param string $package package to check files from
 * @param array $custom_skin_files list of custom skin files
 * @return boolean always true
 */
function fn_uc_check_files($path, $hash_table, &$result, $package, $custom_skin_files)
{
    // Simple copy for a file
    if (is_file($path)) {
        // Get original file name
        $original_file = str_replace(DIR_UPGRADE . $package . '/package/', DIR_ROOT . '/', $path);
        $relative_file = str_replace(DIR_ROOT . '/', '', $original_file);
        $file_name = basename($original_file);
        if (file_exists($original_file)) {
            if (md5_file($original_file) != md5_file($path)) {
                $_relative_file = $relative_file;
                // For skins, convert relative path to skins_repository
                if (strpos($relative_file, 'skins/') === 0) {
                    $_relative_file = preg_replace('/skins\\/[\\w]+\\//', 'var/skins_repository/base/', $relative_file);
                    // replace all skins except basic
                    if (fn_uc_check_array_value($relative_file, $custom_skin_files) && strpos($relative_file, '/basic/') === false) {
                        $_relative_file = preg_replace('/skins\\/([\\w]+)\\//', 'var/skins_repository/${1}/', $relative_file);
                    }
                }
                if (!empty($hash_table[$_relative_file])) {
                    if (md5_file($original_file) != $hash_table[$_relative_file]) {
                        $result['changed'][] = $relative_file;
                    }
                } else {
                    $result['changed'][] = $relative_file;
                }
            }
        } else {
            $result['new'][] = $relative_file;
        }
        $status = fn_uc_is_writable($original_file, true);
        if ($status['result'] == false) {
            $result['non_writable'][] = $relative_file;
        }
        if ($status['no_ftp'] == true) {
            $result['no_ftp'] = true;
        }
        return true;
    }
    if (is_dir($path)) {
        $dir = dir($path);
        while (false !== ($entry = $dir->read())) {
            if ($entry == '.' || $entry == '..') {
                continue;
            }
            fn_uc_check_files(rtrim($path, '/') . '/' . $entry, $hash_table, $result, $package, $custom_skin_files);
        }
        // Clean up
        $dir->close();
        return true;
    } else {
        return false;
    }
}