コード例 #1
0
 function common_copy($files_array, $fs_dir, $revert = false, &$zip_array)
 {
     extract(tep_load('message_stack'));
     $install_path = DIR_FS_PLUGINS . $this->key . '/';
     $result_array = array();
     $cleanup_array = array('/\\\\/', '/\\/{2,}/');
     $filter = "/[^0-9a-z\\-_\\/\\.]+/i";
     foreach ($files_array as $key => $value) {
         $key = trim(preg_replace($cleanup_array, '/', $key), '/');
         $value = rtrim(preg_replace($cleanup_array, '/', $value), '/');
         if (!empty($key)) {
             $org_key = $key;
             $key = tep_create_safe_string($key, '', $filter);
             if ($key != $org_key) {
                 $msg->add_session(sprintf(ERROR_INVALID_FILE_NAME, $org_key));
                 continue;
             }
             $srctype = 'file';
         }
         $input_file = $install_path . $key;
         if ($srctype == 'file') {
             if (!$revert) {
                 //$install_path = DIR_FS_PLUGINS.$this->key.'/';
                 //$input_file = $install_path . $key;
                 if (is_file($fs_dir . $value)) {
                     @unlink($fs_dir . $value);
                 }
                 $tmp_array = explode('/', ltrim($value, '/'));
                 array_pop($tmp_array);
                 if (is_array($tmp_array) && count($tmp_array)) {
                     $sub_dir = '';
                     if (substr($value, 0, 1) == '/') {
                         $sub_dir = $fs_dir . '/';
                     }
                     for ($i2 = 0, $j2 = count($tmp_array); $i2 < $j2; $i2++) {
                         $sub_dir .= $tmp_array[$i2];
                         if (!tep_mkdir($sub_dir)) {
                             $msg->add_session(sprintf(ERROR_CREATE_DIR, $sub_dir));
                             return $result_array;
                         }
                         $sub_dir .= '/';
                     }
                 }
                 if (!tep_read_contents($input_file, $contents)) {
                     $msg->add_session(sprintf(ERROR_INVALID_FILE, $input_file));
                     continue;
                 }
                 if (!tep_write_contents($fs_dir . $value, $contents)) {
                     $msg->add_session(sprintf(ERROR_WRITING_FILE, $value));
                     continue;
                 }
             } else {
                 if (!tep_read_contents($fs_dir . $value, $contents)) {
                     $msg->add_session(sprintf(ERROR_INVALID_FILE, $input_file));
                     continue;
                 }
                 if (isset($_POST['zip'])) {
                     $zip_array[$key] = $contents;
                 }
                 if (!tep_write_contents($input_file, $contents)) {
                     $msg->add_session(sprintf(ERROR_WRITING_FILE, $value));
                     continue;
                 }
             }
             $result_array[$input_file] = $value;
         }
     }
     return $result_array;
 }
コード例 #2
0
ファイル: install.php プロジェクト: enigma1/i-metrics-cms
 function create_references()
 {
     extract(tep_load('database', 'languages'));
     $options_array = $this->load_options();
     //$lng->create_plugin_folders($this);
     $lng->create_table('TABLE_BANNERS');
     $result = true;
     $dir = trim($options_array['banners_path'], '/');
     $path = tep_front_physical_path(DIR_WS_CATALOG . $dir);
     if (!empty($dir)) {
         $result = tep_mkdir($path);
     }
     $path = tep_front_physical_path(DIR_WS_CATALOG);
     $files_query_raw = "select filename from " . TABLE_BANNERS . " where filename != ''";
     $files_array = $db->query_to_array($files_query_raw, false, false);
     for ($i = 0, $j = count($files_array); $i < $j; $i++) {
         $src = $this->admin_path . 'front/images/' . basename($files_array[$i]['filename']);
         $dst = $path . $files_array[$i]['filename'];
         if (is_file($src)) {
             copy($src, $dst);
         }
     }
     return $result;
 }
コード例 #3
0
 case 'deleteconfirm':
     if (empty($current_file)) {
         tep_redirect(tep_href_link($g_script, tep_get_all_get_params('action', 'info')));
     }
     @unlink($current_file);
     $messageStack->add_session(sprintf(WARNING_FILE_REMOVED, $current_path_file), 'warning');
     tep_redirect(tep_href_link($g_script, tep_get_all_get_params('action', 'info')));
     break;
 case 'insert':
     $folder = $g_db->prepare_input($_POST['folder_name']);
     $new_file_path = $current_path . $folder;
     if (is_dir($current_file_path)) {
         $messageStack->add_session(sprintf(ERROR_CREATE_DIR_EXISTS, $current_file_path));
         tep_redirect(tep_href_link($g_script, tep_get_all_get_params('action', 'info', 'goto') . 'goto=' . $new_file_path));
     }
     $result = tep_mkdir($sub_dir);
     if (!$result) {
         $messageStack->add_session(sprintf(ERROR_CREATE_DIR, $current_file_path));
     } else {
         $messageStack->add_session(sprintf(SUCCESS_DIR_CREATED, $new_file_path), 'success');
     }
     break;
 case 'save':
     if (empty($current_file)) {
         $messageStack->add_session(ERROR_FILE_INVALID);
         tep_redirect(tep_href_link($g_script, tep_get_all_get_params('action')));
     }
     $result = tep_write_contents($current_path_file, $g_db->prepare_input($_POST['file_contents']));
     if (!$result) {
         $messageStack->add_session(WARNING_FILE_LENGTH, 'warning');
     }
コード例 #4
0
ファイル: install.php プロジェクト: enigma1/i-metrics-cms
 function create_download_path()
 {
     $options_array = $this->load_options();
     $result = true;
     $dir = DIR_FS_CATALOG . tep_trail_path($options_array['download_path']);
     if (!empty($dir)) {
         $result = tep_mkdir($dir);
     }
     return $result;
 }
コード例 #5
0
ファイル: pkunzip.php プロジェクト: enigma1/i-metrics-cms
 /**
  * Writes a file inside the ZIP to a local file
  *
  * @access private
  * @param string $data  The file data
  * @param string $name  The file name
  * @param string $path  The file path (if any)
  * @param int $time     The file mod time
  * @return boolean
  */
 function WriteDataToFile($data, $name, $path, $time = null)
 {
     if (substr($this->output_file_path, -1) != '/' && $this->output_file_path != '') {
         $this->output_file_path .= '/';
     }
     if (!is_writeable($this->output_file_path)) {
         // make sure we can write to the output directory
         trigger_error("Unable to write to output file path \"{$this->output_file_path}\"", E_USER_WARNING);
         return false;
     } else {
         $directory_string = '';
         // used for paths in the zip file
         if ($path != '') {
             clearstatcache();
             $directories = explode('/', $path);
             // get a path for the zip file
             foreach ($directories as $directory) {
                 // iterate over each directory and concatenate the directory string
                 $directory_string .= $directory;
                 if (!tep_mkdir($this->output_file_path . $directory_string)) {
                     // tried to make the folder, failed, cant write this file, sorry
                     trigger_error("Unable to create directory \"{$this->output_file_path}{$directory_string}\"", E_USER_WARNING);
                     return false;
                 }
                 $directory_string .= '/';
                 // append trailing slash for next round
             }
         }
         $filename = $this->output_file_path . $directory_string . $name;
         if (file_exists($filename) && $this->overwrite_existing_files == false) {
             // check existance and overwrite directive
             trigger_error("File \"{$filename}\" already exists", E_USER_WARNING);
             return false;
         }
         $fp = @fopen($filename, 'w+b');
         // open output file
         if (!$fp) {
             trigger_error("Failed to open \"{$this->output_file_path}{$directory_string}\" for writing", E_USER_WARNING);
             return false;
         }
         fwrite($fp, $data);
         fclose($fp);
         if ($time != null) {
             touch($filename, $time);
         }
         // set mtime
         return true;
     }
 }
コード例 #6
0
ファイル: languages.php プロジェクト: enigma1/i-metrics-cms
 function create_plugin_folders($plugin)
 {
     if (!is_object($plugin) || empty($plugin->key) || !isset($plugin->options_array['strings']) || empty($plugin->front_strings_array)) {
         return false;
     }
     $valid_folder = false;
     $missing_folders = array();
     $admin_path = $plugin->options_array['strings'];
     foreach ($this->languages as $id => $value) {
         $path = DIR_FS_PLUGINS . tep_trail_path($plugin->key) . tep_trail_path($admin_path) . $value['language_path'];
         if (!is_dir($path)) {
             $missing_folders[] = $path;
         } elseif (empty($valid_folder)) {
             $valid_folder = $path;
         }
     }
     if (empty($valid_folder) && !empty($missing_folders)) {
         return false;
     }
     for ($i = 0, $j = count($missing_folders); $i < $j; $i++) {
         tep_copy_dir($valid_folder, $missing_folders[$i]);
     }
     $fs_plugins = tep_front_physical_path(DIR_WS_CATALOG_STRINGS);
     foreach ($this->languages as $id => $value) {
         $path = $fs_plugins . tep_trail_path($value['language_path']) . $plugin->key;
         tep_mkdir($path);
     }
     return true;
 }
コード例 #7
0
ファイル: general.php プロジェクト: enigma1/i-metrics-cms
function tep_copy_dir($src, $dst)
{
    extract(tep_load('message_stack'));
    //closedir(opendir($src));
    //closedir(opendir($dst));
    $src = rtrim($src, '/');
    $dst = rtrim($dst, '/');
    if (empty($src) || empty($dst) || !is_dir($src)) {
        return;
    }
    $result = tep_mkdir($dst);
    if (!$result) {
        $msg->add_session(sprintf(ERROR_CREATE_DIR, $dst));
        return;
    }
    $sub_array = glob($src . '/*');
    if (empty($sub_array)) {
        return;
    }
    foreach ($sub_array as $sub) {
        $entry = basename($sub);
        if (is_file($sub)) {
            $contents = '';
            if (!tep_read_contents($src . '/' . $entry, $contents)) {
                $msg->add_session(sprintf(ERROR_INVALID_FILE, $src . '/' . $entry));
                continue;
            }
            if (!tep_write_contents($dst . '/' . $entry, $contents)) {
                $msg->add_session(sprintf(ERROR_WRITING_FILE, $src . '/' . $entry));
                continue;
            }
        } else {
            tep_copy_dir($src . '/' . $entry, $dst . '/' . $entry);
        }
    }
    closedir(opendir($src));
    closedir(opendir($dst));
}