diff --git a/ssip/connector.php b/ssip/connector.php new file mode 100644 index 0000000000000000000000000000000000000000..7d17554c241430bc4c9931c18a0d8d658ec914ba --- /dev/null +++ b/ssip/connector.php @@ -0,0 +1,55 @@ + \ No newline at end of file diff --git a/ssip/core.inc b/ssip/core.inc new file mode 100644 index 0000000000000000000000000000000000000000..420611b5e6b6f62ae9ed5e9288ace908c7a00d0e --- /dev/null +++ b/ssip/core.inc @@ -0,0 +1,327 @@ +" ; + + $folder = opendir( $path ) ; + while ( $file = readdir( $folder ) ) { + if ( $file != '.' && $file != '..' && is_dir($path . $file) ) + print ''; + } + closedir( $folder ) ; + + // Close the "Folders" node. + print "" ; +} + +/** + * Print a xml node(s) representing a file or directory + */ +function _fck_connector_get_folders_and_files($resuorce_type, $current_folder) { + + // gets the ral path for the current folder + $url = _fck_connector_get_url_from_path($resuorce_type, $current_folder); + $path = _fck_connector_get_real_path($url); + + // Initialize the output buffers for "Folders" and "Files". + $sFolders = '' ; + $sFiles = '' ; + + $folder = opendir( $path ) ; + while ( $file = readdir( $folder ) ) { + if ( $file != '.' && $file != '..' ) { + if ( is_dir( $path . $file ) ) { + $sFolders .= ''; + } else { + $size = filesize( $path . $file ); + if ( $size > 0 ) { + $size = round( $size / 1024 ); + if ( $size < 1 ) $size = 1; + } + + $sFiles .= '' ; + } + } + } + + print $sFolders ; + // Close the "Folders" node. + print '' ; + + print $sFiles ; + // Close the "Files" node. + print '' ; +} + +/** + * tries to create a new folder in the current file system + */ +function _fck_connector_create_folder($resuorce_type, $current_folder) { + $error_number = '0' ; + $error_msg = '' ; + + if ( isset( $_GET['NewFolderName'] ) ) { + $folder_name = $_GET['NewFolderName'] ; + + $url = _fck_connector_get_url_from_path($resuorce_type, $current_folder); + $path = _fck_connector_get_real_path($url); + + if ( is_writable( $path ) ) { + $path .= $folder_name; + + $error_msg = _fck_connector_create_server_folder($path); + + switch ( $error_msg ) { + case '' : + $error_number = '0' ; + break ; + case 'Invalid argument' : + case 'No such file or directory' : + $error_number = '102' ; // Path too long. + break ; + default : + $error_number = '110' ; + break ; + } + } else { + $sErrorNumber = '103' ; + } + } else { + $error_number = '102' ; + } + + // Create the "Error" node. + print '' ; +} + +/** + * Tries to upload a file to the current file system + */ +function _fck_connector_file_upload($resuorce_type, $current_folder) { + $sErrorNumber = '0' ; + $sFileName = '' ; + + if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) ) { + $oFile = $_FILES['NewFile'] ; + + // Map the virtual path to the local server path. + $url = _fck_connector_get_url_from_path($resuorce_type, $current_folder); + $sServerDir = _fck_connector_get_real_path($url); + + // Get the uploaded file name. + $sFileName = $oFile['name'] ; + $sOriginalFileName = $sFileName ; + + $iCounter = 0 ; + + while ( true ) { + $sFilePath = $sServerDir . $sFileName ; + + if ( is_file( $sFilePath ) ) { + $iCounter++ ; + $oPathInfo = pathinfo( $sFilePath ) ; + $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $oPathInfo['extension'] ; + $sErrorNumber = '201' ; + } else { + move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ; + break ; + } + } + } else { + $sErrorNumber = '202' ; + } + + print '' ; + + exit ; +} + +/** + * Creates a new folder + */ +function _fck_connector_create_server_folder($path) { + if ( !file_exists( $path ) ) { + // Turn off all error reporting. + error_reporting( 0 ) ; + // Enable error tracking to catch the error. + ini_set( 'track_errors', '1' ) ; + + mkdir( $path, 0777 ); + + $error_msg = $php_errormsg ; + + // Restore the configurations. + ini_restore('track_errors'); + ini_restore('error_reporting'); + + return $error_msg ; + } + return ''; +} + + + +/** + * Write the XML header for connector response + */ +function _fck_connector_xml_header($command, $resource_type, $current_folder) { + // Create the XML document header. + print '' ; + + // Create the main "Connector" node. + print '' ; + + // Add the current folder node. + $path = _fck_connector_to_xml_attribute($current_folder); + $url = _fck_connector_to_xml_attribute( _fck_connector_get_url_from_path($resource_type, $current_folder ) ); + print '' ; +} + +/** + * Writes the XML footer fro connector response + */ +function _fck_connector_xml_footer() { + print '' ; +} + +/** + * Formats a value as xml attribute + */ +function _fck_connector_to_xml_attribute( $value ) { + return utf8_encode( htmlspecialchars( $value ) ) ; +} + +/** + * Gets the url fro a specified folder + */ +function _fck_connector_get_url_from_path($resource_type, $current_folder) { + $properties = _fck_connector_properties(); + $path = $properties['context_path'] . $properties[$resource_type]; + return _fck_connector_remove_from_end( $path, '/' ) . $current_folder; +} + +/** + * Gets the real path in the current file system for the specified resource + */ +function _fck_connector_get_real_path($path) { + $properties = _fck_connector_properties(); + $separator = $properties['path_separator']; + if ($separator == '\\') { + $separator .= '\\'; + } + + $sp = $_SERVER["PATH_TRANSLATED"]; + $sp = substr($sp, 0, strpos($sp, 'modules')); + $sp = _fck_connector_remove_from_end($sp, $separator); + + // rewrite path to replace context path + if ( !empty($properties['context_path']) && strstr($path, $properties['context_path'])) { + $path = substr($path, strlen($properties['context_path']) + strpos($path, $properties['context_path'])); + } + if ( empty($path) ) { + $path = '/'; + } + if ( !ereg('/$', $path) ) { + $path .= '/'; + } + $sp .= str_replace('/', $separator, $path); + return $sp; +} + +/** + * Removes from the end of $source the specified $char + */ +function _fck_connector_remove_from_end($source, $char) { + $pattern = '|' . $char . '+$|' ; + return preg_replace( $pattern, '', $source) ; +} + +?> \ No newline at end of file diff --git a/ssip/properties.inc b/ssip/properties.inc new file mode 100644 index 0000000000000000000000000000000000000000..c1c13b756341e9ad181551c67f883766936b8061 --- /dev/null +++ b/ssip/properties.inc @@ -0,0 +1,42 @@ + \ No newline at end of file