setupInfo : 5.3.4 2009/09/16
startFile : mwftp5/common/classes/mwfCommonView.php : 1
<?
include_once( HCLIB_DIR . '/hcView.php' );
class mwfCommonView extends hcView {
function mwfCommonView( &$req, &$resp ){
parent::hcView( $req, $resp );
}
function viewHeader( &$resp ){
/*
* HEADER
*/
$commonTemplatesDir = APP_DIR . '/' . MWF_DIR . '/common/templates';
$_header = new hcViewContainer( $commonTemplatesDir . '/_header.tpl' );
$cssFile = APP_WEB_DIR . '/' . MWF_DIR . '/common/templates/mwftp5.css';
$_header->addChild( $cssFile, 'CSS_FILE' );
$jsFile = APP_WEB_DIR . '/' . MWF_DIR . '/common/templates/mwftp5.js';
$_header->addChild( $jsFile, 'JS_FILE' );
// CHARSET
$mm =& $resp->getMessageManager();
$charset = $mm->getCharset();
$_header->addChild( $charset, 'CHARSET' );
$_header->addChild( APP_PRODUCT_NAME, 'APP_PRODUCT_NAME' );
$headerView = $_header->view();
if( defined('FREE_VERSION') && FREE_VERSION )
$headerView .= FREE_VERSION_NOTICE2;
return $headerView;
}
function prefillViewContainer( &$viewContainer ){
/*
* HEADER
*/
$commonTemplatesDir = APP_DIR . '/' . MWF_DIR . '/common/templates';
/*
$_header = new hcViewContainer( $commonTemplatesDir . '/_header.tpl' );
$cssFile = APP_WEB_DIR . '/' . MWF_DIR . '/common/templates/mwftp5.css';
$_header->addChild( $cssFile, 'CSS_FILE' );
$jsFile = APP_WEB_DIR . '/' . MWF_DIR . '/common/templates/mwftp5.js';
$_header->addChild( $jsFile, 'JS_FILE' );
// CHARSET
$mm =& $this->_resp->getMessageManager();
$charset = $mm->getCharset();
$_header->addChild( $charset, 'CHARSET' );
$viewContainer->addChild( $_header, '_HEADER' );
*/
$mm =& $this->_resp->getMessageManager();
/*
* FOOTER
*/
$_footer = new hcViewContainer( $commonTemplatesDir . '/_footer.tpl' );
$_footer->addChild( APP_VERSION, 'APP_VERSION' );
$_footer->addChild( APP_PRODUCT_SITE, 'APP_PRODUCT_SITE' );
$_footer->addChild( APP_PRODUCT_NAME, 'APP_PRODUCT_NAME' );
// SELECT LANGUAGE
$selectLanguage = M('info/language') . ': ';
$languages = $mm->getLanguages();
reset( $languages );
$currentLanguage = $mm->getCurrentLanguage();
$currentUrl = $this->_resp->currentUrl();
$glue = strpos( $currentUrl, '?' ) ? '&' : '?';
foreach( $languages as $l ){
if( $currentLanguage == $l )
$selectLanguage .= '<STRONG>'. $l . '</STRONG> ';
else
$selectLanguage .= '<A HREF="' . $currentUrl . $glue . 'lang=' . $l . '">' . $l . '</A> ';
}
$_footer->addChild( $selectLanguage, 'SELECT_LANGUAGE' );
$viewContainer->addChild( $_footer, '_FOOTER' );
}
function view( $childView = '' ){
$mm =& $this->_resp->getMessageManager();
$mm->process( $childView );
return $childView;
}
}
?>
startFile : mwftp5/common/templates/mwftp5.css : 1
#mwf {
BACKGROUND-COLOR: #FFFFFF;
FONT-FAMILY: Arial, Helvetica, Tahoma, Verdana, Sans-Serif;
FONT-SIZE: 10pt;
WIDTH: 80%;
}
#mwf TABLE {
WIDTH: 100%;
}
#mwf TABLE, TR, TD, DIV {
TEXT-ALIGN: left;
FONT-SIZE: 10pt;
BORDER-COLLAPSE: collapse;
PADDING: 2px;
VERTICAL-ALIGN: middle;
MARGIN-LEFT: auto;
MARGIN-RIGHT: auto;
}
#mwf FORM {
PADDING: 0px;
MARGIN: 0px;
}
#mwf OPTION.header {
background-color: #DDDDDD;
}
#mwf A {
MARGIN: 1px;
}
#mwf INPUT {
FONT-FAMILY: Tahoma, Verdana, Arial, Helvetica;
FONT-SIZE: 8pt;
FONT-WEIGHT: bold;
PADDING: 2px;
MARGIN: 1px;
TEXT-DECORATION: none;
COLOR: #000000;
BORDER: #800000 1px solid;
BACKGROUND-COLOR: #EEEEEE;
}
#mwf INPUT:focus {
BACKGROUND-COLOR: #DDDDDD;
}
#mwf INPUT.readonly {
BACKGROUND-COLOR: #FFFFFF;
BORDER-STYLE: none;
COLOR: #808080;
}
#mwf LABEL {
MARGIN-RIGHT: 2px;
}
#mwf P {
CLEAR: both;
}
#mwf LEGEND {
FONT-WEIGHT: bold;
COLOR: #000080;
}
#mwf H1 {
FONT-WEIGHT: bold;
FONT-SIZE: 20px;
MARGIN: 4px;
PADDING: 4px;
}
#mwf H3 {
COLOR: #BFD2E7;
FONT-WEIGHT: bold;
FONT-SIZE: 16px;
MARGIN: 2px;
PADDING: 2px;
}
#mwf H4 {
COLOR: #DAE407;
FONT-WEIGHT: bold;
FONT-SIZE: 14px;
MARGIN: 1px;
PADDING: 1px;
}
#mwf FIELDSET {
PADDING: 5px;
}
/* Named divs */
#mwfFileListing, #mwfFileListingConfiguration, #mwfFilePath, #mwfFileActionsBar, #mwfTopLevelActionsBar, #mwfActionResults {
BORDER-BOTTOM: #C9C9C9 1px solid;
MARGIN: 0px;
PADDING: 2px;
TEXT-ALIGN: left;
MARGIN-LEFT: auto;
MARGIN-RIGHT: auto;
}
#mwfFileListingContainer {
MARGIN: 0px;
PADDING: 0px;
}
#mwfFileActionForms FORM {
DISPLAY: none;
BACKGROUND-COLOR: #EEEEEE;
PADDING: 10px;
}
#mwfFileActionsBar FORM {
DISPLAY: inline;
}
#mwfFileListing {
FONT-SIZE: 9pt;
}
#mwfFileListing A {
FONT-WEIGHT: normal;
COLOR: #444444;
TEXT-DECORATION: underline;
}
#mwfFileListing A STRONG {
FONT-WEIGHT: bold;
}
#mwfFileListing A:hover {
COLOR: #0080FF;
TEXT-DECORATION: underline;
}
#mwfFileListing TH, #mwfActionResults .header {
BACKGROUND-COLOR: #BFD2E7;
TEXT-ALIGN: left;
FONT-WEIGHT: bold;
BORDER-BOTTOM: #800000 1px solid;
MARGIN: 2px;
PADDING: 2px;
}
#mwfFileListing TD {
PADDING: 3px;
BORDER-BOTTOM: #C9C9C9 1px solid;
}
#mwfFileListing DIV {
PADDING: 3px;
BACKGROUND-COLOR: FFFFFF;
}
#mwfFileListing INPUT {
BORDER: 0px;
CURSOR: pointer;
CURSOR: hand;
COLOR: #808080;
MARGIN: 0px;
PADDING: 0px;
BACKGROUND-COLOR: #FFFFFF;
}
#mwfFileListingConfiguration, #mwfFileListingConfiguration {
BACKGROUND-COLOR: #EEEEEE;
}
#mwfFileListingConfiguration STRONG {
MARGIN: 2px;
}
#mwfFileListingConfiguration FORM {
MARGIN: 0px;
}
#mwfFileListingConfiguration FIELDSET {
DISPLAY: inline;
PADDING: 3px;
}
#mwfFileListingConfiguration LEGEND {
FONT-WEIGHT: normal;
}
#mwfFileShortListing H4 {
DISPLAY: block;
FONT-WEIGHT: bold;
FONT-SIZE: 14px;
COLOR: #DAE407;
MARGIN: 0px;
}
#mwfFilePath {
BACKGROUND-COLOR: #EEEEEE;
}
#mwfFileEdit TEXTAREA {
WIDTH: 100%;
}
#mwfFileActionsBar {
BACKGROUND-COLOR: #DDDDDD;
}
#mwfFileActionsBar INPUT {
BORDER: 0px;
CURSOR: pointer;
CURSOR: hand;
COLOR: #FFFFFF;
BACKGROUND-COLOR: #0FB2C7;
BORDER-BOTTOM: #C9C9C9 1px solid;
BORDER-RIGHT: #C9C9C9 1px solid;
}
#mwfTopLevelActionsBar {
BACKGROUND-COLOR: #DAE407;
PADDING: 5px;
}
#mwfTopLevelActionsBar A {
COLOR: #000000;
MARGIN: 4px;
TEXT-DECORATION: none;
}
#mwfTopLevelActionsBar A:hover {
TEXT-DECORATION: underline;
}
#mwfActionResults {
WIDTH: 100%;
}
#mwfUserLoginForm {
TEXT-ALIGN: left;
}
#mwfUserLoginForm LABEL {
FLOAT: left;
WIDTH: 120px;
}
#mwfAdminLoginForm {
TEXT-ALIGN: left;
}
#mwfAdminLoginForm LABEL {
FLOAT: left;
WIDTH: 30%;
}
#mwfAdminPanel {
TEXT-ALIGN: left;
}
#mwfAdminPanel LABEL {
FLOAT: left;
WIDTH: 30%;
}
#mwfAppInfo, #mwfAd {
TEXT-ALIGN: left;
WIDTH: 100%;
FONT-FAMILY: Arial, Helvetica, Tahoma, Verdana, Sans-Serif;
FONT-SIZE: 10pt;
BACKGROUND-COLOR: #EEEEEE;
MARGIN-TOP: 10px;
}
#mwfAppInfo A, #mwfAd A {
TEXT-DECORATION: none;
}
#mwfAppInfo B, #mwfAd B {
COLOR: #800000;
}
#mwfAppInfo B.hit {
COLOR: #386376;
}
#mwfAppInfo B.code {
COLOR: #F06342;
}
startFile : mwftp5/common/templates/mwftp5.js : 1
var DIV_FILE_LISTING_CONTAINER = 'mwfFileListingContainer';
var DIV_FILE_ACTION_FORMS = 'mwfFileActionForms';
/*
* PUBLIC FILE ACTION FUNCTIONS
*/
function printFileActionOptions( isDir ){
code = '';
for( actionId = 1; actionId < fileActions.length; actionId++ ){
onDir = fileActions[ actionId ][ 2 ];
if( (! isDir) || onDir ){
actionTitle = fileActions[ actionId ][ 0 ];
code += '<OPTION VALUE="' + actionId + '">' + actionTitle + '</OPTION>';
}
}
document.write( code );
}
function fileActionCode( actionId ){
actionId = arguments[ 0 ];
if( arguments.length > 1 )
selectedFileName = arguments[ 1 ];
code = '';
fileNamePlaceHolder = '_selectedFileName_';
if( actionId > 0 ){
code = fileActions[ actionId ][ 1 ];
position = code.lastIndexOf(fileNamePlaceHolder);
while( position > -1 ){
code = code.slice( 0, position ) + selectedFileName + code.slice( position + fileNamePlaceHolder.length )
position = code.lastIndexOf(fileNamePlaceHolder);
}
}
return code;
}
//showActionForm
function shaf( formId, fileListId, errorNoteId ){
var ok = true;
if( fileListId ){
filesArray = _getSelectedFiles();
if( filesArray.length > 0 ){
fileList = new myDiv( fileListId );
fileList.setContent( _buildSelectedFilesListHTML(filesArray) );
}
else {
ok = false;
}
}
// HIDE FILE LISTING CONTAINER
_hideElement( DIV_FILE_LISTING_CONTAINER );
// NOW SHOW THE ELEMENT
if( ok )
_showElement( formId );
else
_showElement( errorNoteId );
return ok;
}
function downloadAction( errorNoteId ){
var ok = false;
filesArray = _getSelectedFiles();
if( filesArray.length > 0 )
ok = true;
// SHOW THE ERROR
if( ! ok ){
// HIDE FILE LISTING CONTAINER
_hideElement( DIV_FILE_LISTING_CONTAINER );
_showElement( errorNoteId );
}
return ok;
}
//hideActionForm
function hdaf( formId, fileListId ){
if( fileListId ){
fileList = new myDiv( fileListId );
fileList.setContent( '' );
}
_hideElement( formId );
// SHOW FILE LISTING CONTAINER
_showElement( DIV_FILE_LISTING_CONTAINER );
return true;
}
//setFileCheckbox
function sfc( ctl, selectTrue ){
ctl.checked = selectTrue;
return true;
}
//setAllFileCheckboxes
function safc( selectTrue ){
filesCheckboxes = _getFilesCheckboxes();
for( i = 0; i < filesCheckboxes.length; i++ ){
el = filesCheckboxes[ i ];
sfc( el, selectTrue )
}
return true;
}
//setControlValue
function scv( ctl, val ){
ctl.value = val;
return true;
}
function countSelectedItems(){
filesArray = _getSelectedFiles();
return filesArray.length;
}
/*
* PRIVATE FILE ACTION FUNCTIONS
*/
function _showElement( elementId ){
var thisElement = new myDiv( elementId );
if( thisElement )
thisElement.show();
return true;
}
function _hideElement( elementId ){
var thisElement = new myDiv( elementId );
if( thisElement )
thisElement.hide();
return true;
}
function _getFilesCheckboxes(){
checkboxes = new Array();
thisForms = document.forms;
for( i = 0; i < thisForms.length; i++ ){
thisElements = thisForms[ i ].elements;
for( j = 0; j < thisElements.length; j++ ){
el = thisElements[ j ];
if( el.type == "checkbox" && el.name == CHNDL_FILE_NAME )
checkboxes.push( el );
}
}
return checkboxes;
}
function _getSelectedFiles(){
selectedFiles = new Array();
filesCheckboxes = _getFilesCheckboxes();
for( i = 0; i < filesCheckboxes.length; i++ ){
el = filesCheckboxes[ i ];
if( el.checked )
selectedFiles.push( el.value );
}
return selectedFiles;
}
function _buildSelectedFilesListHTML( filesArray ){
var fileTemplateString = new String( SELECTED_FILE_TEMPLATE );
var filesContainerTemplateString = new String( SELECTED_FILES_CONTAINER_TEMPLATE );
var allFilesString = "";
for( i = 0; i < filesArray.length; i++ ){
thisFileString = fileTemplateString.replace( /{FILE_NAME}/g, filesArray[i] );
allFilesString += thisFileString;
}
thisString = filesContainerTemplateString.replace( /{FILES}/g, allFilesString );
return thisString;
}
/*
* CHMOD FUNCTIONS
*/
function ctl_inc( ctl, val, inc){
if( ! inc )
val = -val;
var old_val = ctl.value;
if( ! old_val)
old_val = 0;
// ctl.value = parseInt(old_val) + parseInt(val);
ctl.value = format_chmod( parseInt(old_val, 10) + parseInt(val, 10) );
}
function format_chmod(dig){
var str = new String('' + dig);
var final_length = 3;
var add_length = final_length - str.length;
for(var i=0; i < add_length; i++){
str = '0' + str;
}
return str;
}
function fill_chmod( dig, r_ctl, w_ctl, x_ctl){
var r_mask = 4; var w_mask = 2; var x_mask = 1;
r_ctl.checked = ( dig & r_mask ) ? true : false;
w_ctl.checked = ( dig & w_mask ) ? true : false;
x_ctl.checked = ( dig & x_mask ) ? true : false;
}
function btnCancel_Click(){
window.close();
}
function transferControlValue( srcControl, trgControl ){
// window.opener.document.mwForm[trgControlName].value = srcControl.value;
trgControl.value = srcControl.value;
window.close();
}
function transferControlValue_old( srcControlName, trgControlName ){
window.opener.document.mwForm[trgControlName].value = document.mwForm[srcControlName].value;
window.close();
}
function openWindow( url ){
nw = window.open(url, 'newWin', 'scrollbars=yes,status=yes,menubar=no,location=no,resizable=yes,width=580,height=300');
// nw = window.open(url, 'newWin', 'scrollbars=yes,status=no,menubar=no,location=no,resizable=yes,width=510,height=300');
}
function fetchObjectPosLeft(elm){
var left = elm.offsetLeft;
while((elm = elm.offsetParent) != null){
left += elm.offsetLeft;
}
return left;
}
function fetchObjectPosTop(elm){
var top = elm.offsetTop;
while((elm = elm.offsetParent) != null){
top += elm.offsetTop;
}
return top;
}
function myDiv( htmlDivID ){
htmlDiv = document.getElementById( htmlDivID );
if( ! htmlDiv ){
alert( "No div: " + htmlDivID );
return false;
}
else {
// alert( htmlDivID + ': OK' );
}
this.htmlDiv = document.getElementById( htmlDivID );
this.setLeft = setLeft;
this.setTop = setTop;
this.getLeft = getLeft;
this.getTop = getTop;
this.getWidth = getWidth;
this.getHeight = getHeight;
this.show = show;
this.hide = hide;
this.isHidden = isHidden;
this.setContent = setContent;
}
function setContent( content ){
// alert( this.htmlDiv.innerHTML );
this.htmlDiv.innerHTML = content;
// this.htmlDiv.childNodes[0].innerHTML = content;
}
function getLeft(){
return fetchObjectPosLeft( this.htmlDiv );
}
function setLeft( left ){
if( left < 0 )
left = 5;
this.htmlDiv.style.left = left;
}
function getTop(){
return fetchObjectPosTop( this.htmlDiv );
}
function setTop( top ){
this.htmlDiv.style.top = top;
}
function getWidth(){
return this.htmlDiv.offsetWidth;
}
function getHeight(){
return this.htmlDiv.offsetHeight;
}
function show(){
// this.htmlDiv.style.display = "";
this.htmlDiv.style.display = "block";
}
function hide(){
this.htmlDiv.style.display = "none";
}
function isHidden(){
if( this.htmlDiv.style.display == "none" )
return true;
else
return false;
}
/*
* SOME CONSTANTS SHOULD BE DEFINED BEFORE
*/
function showNextFileField( fieldHandle ){
var maxFields = HTML_MAX_FILE_FIELDS;
for( i = 2; i <= maxFields; i++ ){
thisDiv = new myDiv( fieldHandle + i );
if( ! thisDiv )
continue;
if( thisDiv.isHidden() ){
thisDiv.show();
break;
}
}
}
function checkFields(){
for(var i = 0; i < arguments.length; i++){
// if(! f.elements[ arguments[i] ].value){
var ctl = arguments[i];
if(! ctl.value ){
alert('Please fill all the required fields!');
return false;
}
}
return true;
}
function sprintf()
{
if (!arguments || arguments.length < 1 || !RegExp)
{
return;
}
var str = arguments[0];
var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
var a = b = [], numSubstitutions = 0, numMatches = 0;
while (a = re.exec(str))
{
var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
var pPrecision = a[5], pType = a[6], rightPart = a[7];
//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);
numMatches++;
if (pType == '%')
{
subst = '%';
}
else
{
numSubstitutions++;
if (numSubstitutions >= arguments.length)
{
alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
}
var param = arguments[numSubstitutions];
var pad = '';
if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
else if (pPad) pad = pPad;
var justifyRight = true;
if (pJustify && pJustify === "-") justifyRight = false;
var minLength = -1;
if (pMinLength) minLength = parseInt(pMinLength);
var precision = -1;
if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
var subst = param;
if (pType == 'b') subst = parseInt(param).toString(2);
else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
else if (pType == 'u') subst = Math.abs(param);
else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
else if (pType == 'o') subst = parseInt(param).toString(8);
else if (pType == 's') subst = param;
else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
}
str = leftpart + subst + rightPart;
}
return str;
}
function makeHttpRequest(url, callback_function, fParamString, return_xml){
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml [15]');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Unfortunatelly you browser doesn\'t support this feature.');
return false;
}
http_request.onreadystatechange = function() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
if (return_xml) {
if( fParamString != "" )
evalCode = callback_function + '(' + fParamString + ', http_request.responseXML)';
else
evalCode = callback_function + '(http_request.responseXML)';
}
else {
if( fParamString != "" )
evalCode = callback_function + '(' + fParamString + ', http_request.responseText)';
else
evalCode = callback_function + '(http_request.responseText)';
}
eval( evalCode );
} else {
alert('There was a problem with the request.(Code: ' + http_request.status + ')');
}
}
}
http_request.open('GET', url, true);
http_request.send(null);
}
// how may be 'insert', 'append', 'prepend'
function AjaxCall( url2fetch, div2update, how ){
functionParamsString = '"' + div2update + '", "' + how + '"';
makeHttpRequest( url2fetch, 'addHtmlToElement', functionParamsString, false );
}
// how may be 'insert', 'append', 'prepend'
function addHtmlToElement( elementName, how, code ){
ele = document.getElementById( elementName );
switch( how ){
case 'insert':
ele.innerHTML = code;
break;
case 'append':
ele.innerHTML += code;
break;
case 'prepend':
ele.innerHTML = code + ele.innerHTML;
break;
}
}
function openStatusWindow(){
displayUploadStatus();
setTimeout("displayUploadStatus();", 2000);
}
function displayUploadStatus(){
AjaxCall( 'status.php', 'mwfUploadStatus', 'insert');
}
function hideShowStatus(){
svn=document.getElementsByTagName("DIV");
for( a=0; a < svn.length; a++ ){
if( svn[a].className == 'hcShowStatus' ){
svn[a].style.display = "none";
}
}
}
startFile : mwftp5/common/templates/_footer.tpl : 1
<DIV ID="mwfAppInfo">
<DIV STYLE="FLOAT: left"><A HREF="{APP_PRODUCT_SITE}"><B>{APP_PRODUCT_NAME}</B></A> Ver. {APP_VERSION}</DIV>
<DIV STYLE="FLOAT: right">{SELECT_LANGUAGE}</DIV>
<DIV STYLE="CLEAR: both"></DIV>
copyright © 2000-2009 <A HREF="http://www.hitcode.com/"><B CLASS="hit">hit</B><B CLASS="code">code</B></A>
</DIV>
</DIV>
</CENTER>
</BODY>
</HTML>
startFile : mwftp5/common/templates/_header.tpl : 1
<HTML>
<HEAD>
<TITLE>{APP_PRODUCT_NAME}</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset={CHARSET}">
<LINK REL="stylesheet" TYPE="text/css" HREF="{CSS_FILE}">
<SCRIPT LANGUAGE=JAVASCRIPT SRC="{JS_FILE}"></SCRIPT>
</HEAD>
<BODY>
<CENTER>
<DIV ID="mwf">
startFile : mwftp5/ftp/generateIncludes.py : 1
#!/usr/bin/python
import glob, os, re, sys
def getDirs( startDir ):
dirs = []
for d in glob.glob(startDir + '/*'):
if os.path.isdir( d ):
dirs.append( d );
return dirs
###########################################################
# this function opens a directory and processes its files
# returns an array of available classes
###########################################################
def processDir( dirName ):
print "Processing dir: " + dirName
includeFiles = []
for f in glob.glob(dirName + '/*'):
if os.path.isdir( f ):
childFiles = processDir( f )
for childF in childFiles:
includeFiles.append( childF )
else:
includeFiles.append( f )
return includeFiles
###########################################################
# main script
###########################################################
d = '_files'
dirs = getDirs( '.' )
for d in dirs:
includeFiles = processDir( d + '/classes' )
incFileName = d + '/include.php'
incFile = open( incFileName, 'w')
incFile.write( "<?\n" );
for fileName in includeFiles:
fileName = fileName[ len(d): ]
if( fileName == '_init.php' ):
continue
fileName = fileName.replace( '\\', '/' )
line = "include_once( FILES_DIR . '" + fileName + "');\n"
incFile.write(line)
incFile.write( "?>" );
incFile.close()
startFile : mwftp5/ftp/index.php : 1
<?
/***********************************/
/* INITIALIZE
/***********************************/
include_once( dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '_init.php' );
/***********************************/
/* THE APPLICATION CODE
/***********************************/
$fm = new mwfFileManagerFTP();
$fm->setLoginInfo( FTP_HOST, FTP_USER, FTP_PASS );
if( defined('USER_START_DIR') )
$fm->setRootDir( USER_START_DIR );
else
$fm->setRootDir( '' );
// VIEW MANAGER
$vm = new mwfViewManager( 'rich' );
// SECURITY MANAGER
// $sm
// instantiated in the _init file
// TOP-LEVEL ACTIONS LIST
// $tlActions
// instantiated in the _init file
// CONTROLLER
$ah = new mwfActionHandler;
$ah->setFileManager( $fm );
$ah->setViewManager( $vm );
$ah->setSecurityManager( $sm );
$ah->setTopLevelActions( $tlActions );
// HEADER
echo mwfCommonView::viewHeader( &$resp );
// VIEW
$view =& $ah->handleAction( $req, $resp );
echo $view->view();
$fm->quit();
?>
startFile : mwftp5/ftp/index_init.php : 1
<?
myInit( __FILE__ );
if( ! isset($req) )
$req = new hcRequest;
if( ! isset($resp) )
$resp = new hcResponse;
?>
startFile : mwftp5/ftp/index_files/include.php : 1
<?
include_once( FILES_DIR . '/classes/fileManager/mwfFileManager.php');
include_once( FILES_DIR . '/classes/fileManager/mwfFileManagerFTP.php');
include_once( FILES_DIR . '/classes/fileManager/mwfFileManagerLocal.php');
include_once( FILES_DIR . '/classes/listingParser/mwfRawListingParser_FTP.php');
include_once( FILES_DIR . '/classes/listingParser/mwfRawListingParser_FTP_Unix.php');
include_once( FILES_DIR . '/classes/listingParser/mwfRawListingParser_FTP_Win.php');
include_once( FILES_DIR . '/classes/mwfActionHandler.php');
include_once( FILES_DIR . '/classes/mwfFilePager.php');
include_once( FILES_DIR . '/classes/mwfFileSorter.php');
include_once( FILES_DIR . '/classes/mwfPath.php');
include_once( FILES_DIR . '/classes/views/mwfViewManager.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_Chmod.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_CopyTo.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_Delete.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_DirectDir.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_Email.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_Ftpload.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_MoveTo.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_MultiCopyTo.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_NewDir.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_NewFile.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_NoteSelectItems.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_Rename.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_Transload.php');
include_once( FILES_DIR . '/classes/views/rich/actionForms/mwActionForm_Upload.php');
include_once( FILES_DIR . '/classes/views/rich/controls/mwfActionControl_FileModeSelector.php');
include_once( FILES_DIR . '/classes/views/rich/mwfView.php');
include_once( FILES_DIR . '/classes/views/rich/mwfView_ActionResult.php');
include_once( FILES_DIR . '/classes/views/rich/mwfView_FileEdit.php');
include_once( FILES_DIR . '/classes/views/rich/mwfView_FileList.php');
include_once( FILES_DIR . '/classes/views/rich/mwfView_SelectDir.php');
include_once( FILES_DIR . '/classes/views/rich/objectViews/mwfView_FilePager.php');
include_once( FILES_DIR . '/classes/views/rich/objectViews/mwfView_FileSorter.php');
?>
startFile : mwftp5/ftp/index_files/classes/mwfActionHandler.php : 1
<?
if( defined('FREE_VERSION') && FREE_VERSION )
include( dirname(__FILE__) . '/mwfActionHandler_Free.php' );
else
include( dirname(__FILE__) . '/mwfActionHandler_Full.php' );
?>
startFile : mwftp5/ftp/index_files/classes/mwfActionHandler_Base.php : 1
<?
include_once( HCLIB_DIR . '/hcActionHandler.php' );
define( 'VIEW_HANDLE_FILE_LIST', 11 );
define( 'VIEW_HANDLE_SELECT_DIR', 12 );
define( 'VIEW_HANDLE_SELECT_FILE', 13 );
define( 'VIEW_HANDLE_FILE_EDIT', 14 );
define( 'VIEW_HANDLE_FILE_VIEW', 15 );
// THE FOLLOWING ACTIONS ARE HERE:
// newfile, edit, save, chdir, delete, move, copy, newdir, rename, chmod, download, email, upload, transload, ftpload
class mwfActionHandler_Base extends hcActionHandler {
var $fm;
var $_currentDir;
var $_tlActions;
function mwfActionHandler(){
ini_set( 'track_errors', '1' );
parent::hcActionHandler();
$this->fm = null;
$this->_currentDir = null;
$this->_tlActions = array();
}
function handleAction( &$req, &$resp ){
$view = parent::handleAction( $req, $resp );
if( ! $view ) {
$viewHandle = $this->getViewHandle();
switch( $viewHandle ){
case VIEW_HANDLE_FILE_LIST:
$view =& $this->prepareView_FileList();
break;
case VIEW_HANDLE_FILE_EDIT:
$view =& $this->prepareView_FileEdit();
break;
case VIEW_HANDLE_FILE_VIEW:
$view =& $this->prepareView_FileView();
break;
case VIEW_HANDLE_SELECT_DIR:
$view =& $this->prepareView_SelectDir();
break;
default:
echo "Don't have a view defined for handle $viewHandle!";
exit;
}
}
return $view;
}
function prepareActions(){
$actions = array();
$actions[] = array( 'init', 'init', 0 );
$op = $this->_req->getParam( 'op' );
if ( $op != 'chdir' )
$actions[] = array( 'chdir', 'goToCurrentDir', 0 );
if( $op ){
if( method_exists($this, "action_$op") )
$actions[] = array( $op, 'action_' . $op, 1 );
else
echo "There's no handler for the <B>$op</B> action.";
}
reset( $actions );
return $actions;
}
function init(){
// $processName = M('process/login');
// $this->addActionProcess( $processName );
$return = $this->fm->init();
// HERE WE ADD ONLY ERROR RESULT, IF IT SUCCESSFULLY CHANGED TO THIS DIR, NO NEED TO INFORM THE USER ABOUT IT
if( ! $return )
$this->addActionResult( "Initialize", 1, $this->fm->getLastSystemError() );
return $return;
}
function getDefaultViewHandle(){
$viewHandle = $this->_req->getStateParam( PARAM_VIEW_HANDLE );
if( ! $viewHandle )
$viewHandle = VIEW_HANDLE_FILE_LIST;
return $viewHandle;
}
function goToCurrentDir(){
$return = 0;
$dir = '';
$dir = $this->_req->getStateParam( CHNDL_DIR_NAME );
// $return = $this->cd( $dir );
$return = $this->setCurrentDir( $dir );
return $return;
}
function setCurrentDir( $dir ){
$this->_currentDir = $dir;
$this->_resp->setStateParam( CHNDL_DIR_NAME, $this->getCurrentDir() );
return 1;
}
function getCurrentDir(){
return $this->_currentDir;
}
function cd( $dirName = "" ){
$return = $this->fm->cd( $dirName );
// HERE WE ADD ONLY ERROR RESULT, IF IT SUCCESSFULLY CHANGED TO THIS DIR, NO NEED TO INFORM THE USER ABOUT IT
if( $return ){
$this->setCurrentDir( $dirName );
}
else {
$this->_resp->resetStateParam( CHNDL_DIR_NAME );
}
return $return;
}
/*
* ACTION FUNCTIONS
*/
function action_view(){
$maxFileSize = 0;
if( defined('SETTING_MAX_FILE_SIZE') ){
$settingsManager =& mwfSettingsManager::getInstance();
$maxFileSize = $settingsManager->get( SETTING_MAX_FILE_SIZE );
$maxFileSize = 1024 * $maxFileSize;
}
$result = 0;
$name = $this->_req->getParam( CHNDL_FILE_NAME );
if( ! $name ){
$this->_forwardBack();
return $result;
}
$fullName = $this->getCurrentDir() . '/' . $name;
$actionString = "Open file <B>$name</B> to view.";
$fileContent = $this->fm->getFileContent( $fullName );
$fileSize = strlen( $fileContent );
if( $maxFileSize && $fileSize > $maxFileSize ){
$errorString = M('action/upload/error/tooBig', array('fileSize' => ceil($fileSize / 1024) . ' Kb', 'allowedSize' => $maxFileSize / 1024 . ' Kb'));
$this->addActionResult( $actionString, 1, $errorString );
return $result;
}
if( $fileContent || $fileContent == '' ){
$result = 1;
}
if( $result ){
$this->_viewData['fileContent'] =& $fileContent;
$this->_viewData['fileName'] =& $name;
$this->setViewHandle( VIEW_HANDLE_FILE_VIEW );
}
else {
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
return $result;
}
function action_chdir(){
$dir = $this->_req->getParam( CHNDL_DIR_NAME );
$currentDir = $this->_req->getStateParam( CHNDL_DIR_NAME );
if( ! $dir ){
$this->_resp->resetStateParam( CHNDL_DIR_NAME );
$forwardTo = $this->_resp->generateUrl();
$this->setForward( $forwardTo );
return true;
}
$result = $this->cd( $dir );
if( $result ){
// $this->_resp->setStateParam( CHNDL_DIR_NAME, $this->getCurrentDir() );
// SKIP FORWARD ACTION AS IT DOUBLES THE FTP CONNECTIONS FOR AS SIMPLE OPERATION AS CHANGE DIR
// ALTHOUGH IT IS LOOKING GOOD FOR THE MVC PURIST
$forwardTo = $this->_resp->generateUrl();
$this->setForward( $forwardTo );
}
else {
// RESTORE OLD DIRECTORY FROM SESSION AS IT HAS BEEN DELETED IN THE cd() METHOD
$this->_resp->setStateParam( CHNDL_DIR_NAME, $currentDir );
$this->addActionResult( M('action/goto/description', array('dirName' => $dir)), 1, $this->fm->getLastSystemError() );
}
return $result;
}
function action_delete(){
$result = 0;
$fileNames = $this->_req->getParam( CHNDL_FILE_NAME );
if( ! $fileNames ){
$this->_forwardBack();
return $result;
}
foreach( $fileNames as $fName ){
$fullName = $this->getCurrentDir() . '/' . $fName;
if( $this->fm->isDir( $fullName ) )
$result = $this->_deleteDir( $fName );
else
$result = $this->_deleteFile( $fName );
}
return $result;
}
function _deleteFile( $name ){
$actionString = M('action/delete/description/file', array('name' => $name) );
$fullName = $this->getCurrentDir() . '/' . $name;
$processName = M('process/delete/file', array('name' => $name) );
$this->addActionProcess( $processName );
$result = $this->fm->deleteFile( $fullName );
if( $result ){
$this->addActionResult( $actionString );
}
else {
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
return $result;
}
function _deleteDir( $name ){
$actionString = M('action/delete/description/dir', array('name' => $name) );
$fullName = $this->getCurrentDir() . '/' . $name;
$processName = M('process/delete/dir', array('name' => $name) );
$this->addActionProcess( $processName );
$result = $this->fm->deleteDir( $fullName );
if( $result )
$this->addActionResult( $actionString );
else
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
return $result;
}
function action_move(){
$result = 0;
$fileNames = $this->_req->getParam( CHNDL_FILE_NAME );
if( ! $fileNames ){
$this->_forwardBack();
return $result;
}
$files2move = array();
// MULTIPLE FILES
foreach( $fileNames as $fName ){
$moveToDirControlName = CHNDL_MOVETO_DIR_NAME;
$moveToDir = $this->_req->getParam( $moveToDirControlName );
$files2move[ $fName ] = array( $moveToDir );
}
if( ! count($files2move) ){
$this->_forwardBack();
return $result;
}
foreach( $files2move as $fName => $moveToInfo ){
$moveToDir = $moveToInfo[0];
if( $moveToDir )
$moveToString = $moveToDir;
else{
$moveToString = M('common/homeDir');
$mm =& $this->_resp->getMessageManager();
$mm->process( $moveToString );
}
$actionString = M('action/move/description', array('name' => $fName, 'destinationDir' => $moveToString) );
if( $this->getCurrentDir() == $moveToDir ){
$errorString = M('action/move/error/sourceTargetCoincide');
$this->addActionResult( $actionString, 1, $errorString );
continue;
}
$fullName = $this->getCurrentDir() . '/' . $fName;
$newName = $moveToDir . '/' . $fName;
$processName = M('process/move', array('name' => $fName) );
$this->addActionProcess( $processName );
$result = $this->fm->rename( $fullName, $newName );
if( $result )
$this->addActionResult( $actionString );
else
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
return $result;
}
function action_multi_copy(){
return $this->action_copy( 1 );
}
function _checkActionAllowed( $action ){
$result = 0;
$actionString = "<B>$action</B>";
$errorString = M('action/error/notAllowed', array('name' => $action) );
$currentDir = $this->getCurrentDir();
$currentUser = $this->fm->getUser();
if( $this->sm->isAllowed( $action, $currentDir, $currentUser ) )
$result = 1;
else
$this->addActionResult( $actionString, 1, $errorString );
return $result;
}
function action_newdir(){
$result = 0;
$currentDir = $this->getCurrentDir();
$filenum = 10;
$dirs2make = array();
for($i = 1; $i <= $filenum; $i++){
$newDirControlName = CHNDL_NEW_DIR_NAME . $i;
$newDirName = $this->_req->getParam( $newDirControlName );
if( ! $newDirName )
continue;
$dirs2make[ $newDirName ] = 1;
}
if( ! count($dirs2make) ){
$this->_forwardBack();
return $result;
}
foreach( $dirs2make as $newDirName => $bbb ){
$actionString = M('action/newDir/description', array('dirName' => $newDirName) );
$fullName = $currentDir . '/' . $newDirName;
$processName = M('process/newDir', array('dirName' => $newDirName) );
$this->addActionProcess( $processName );
$result = $this->fm->newDir( $fullName );
if( $result )
$this->addActionResult( $actionString );
else
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
return $result;
}
function action_copy( $multi = 0 ){
$result = 0;
$fileNames = $this->_req->getParam( CHNDL_FILE_NAME );
if( ! $fileNames ){
$this->_forwardBack();
return $result;
}
$currentDir = $this->getCurrentDir();
$files2copy = array();
// MULTIPLE FILES
foreach( $fileNames as $fName ){
if( $multi ){
$copyToDirControlName = CHNDL_MULTICOPYTO_DIR_NAME;
$newName = $fName;
}
else {
$copyToDirControlName = CHNDL_COPYTO_DIR_NAME;
$newNameFieldName = CHNDL_COPYTO_NEW_FILE_NAME;
$newName = $this->_req->getParam( $newNameFieldName );
}
$copyToDir = $this->_req->getParam( $copyToDirControlName );
if( ! $newName )
$newName = $fName;
$files2copy[ $fName ] = array( $copyToDir, $newName );
}
if( ! count($files2copy) ){
$this->_forwardBack();
return $result;
}
foreach( $files2copy as $fName => $copyToInfo ){
$copyToDir = $copyToInfo[0];
$newName = $copyToInfo[1];
if( ($copyToDir != $currentDir) && $copyToDir )
$copyToString = $copyToDir . '/' . $newName;
else
$copyToString = $newName;
$actionString = M('action/copy/description', array('name' => $fName, 'destinationDir' => $copyToString) );
$fullName = $currentDir . '/' . $fName;
$newFullName = $copyToDir . '/' . $newName;
if( $fullName == $newFullName ){
$errorString = M('action/copy/error/sourceTargetCoincide');
$this->addActionResult( $actionString, 1, $errorString );
continue;
}
$processName = M('process/copy', array('name' => $fName) );
$this->addActionProcess( $processName );
$result = $this->fm->copy( $fullName, $newFullName );
if( $result )
$this->addActionResult( $actionString );
else
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
return $result;
}
function action_rename(){
$result = 0;
$fileNames = $this->_req->getParam( CHNDL_FILE_NAME );
if( ! $fileNames ){
$this->_forwardBack();
return $result;
}
$files2rename = array();
// MULTIPLE FILES
foreach( $fileNames as $oldName ){
if( ! $oldName )
continue;
$newNameFieldName = CHNDL_RENAME_NEW_NAME;
$newName = $this->_req->getParam( $newNameFieldName );
if( ! $newName )
continue;
$files2rename[ $oldName ] = $newName;
}
if( ! count($files2rename) ){
$this->_forwardBack();
return $result;
}
foreach( $files2rename as $oldName => $newName ){
$actionString = M('action/rename/description', array('oldName' => $oldName, 'newName' => $newName));
$oldName = $this->getCurrentDir() . '/' . $oldName;
$newName = $this->getCurrentDir() . '/' . $newName;
if( $oldName == $newName ){
$errorString = M('action/rename/error/sourceTargetCoincide');
$this->addActionResult( $actionString, 1, $errorString );
continue;
}
$processName = M('process/rename', array('name' => $oldName) );
$this->addActionProcess( $processName );
$result = $this->fm->rename( $oldName, $newName );
if( $result )
$this->addActionResult( $actionString );
else
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
return $result;
}
function action_chmod(){
$result = 0;
$fileNames = $this->_req->getParam( CHNDL_FILE_NAME );
if( ! $fileNames ){
$this->_forwardBack();
return $result;
}
$files2chmod = array();
// MULTIPLE FILES
foreach( $fileNames as $fileName ){
if( ! $fileName )
continue;
$newModeFieldName = CHNDL_CHMOD_NEW_MODE;
$newMode = $this->_req->getParam( $newModeFieldName );
if( ! $newMode )
continue;
$files2chmod[ $fileName ] = $newMode;
}
if( ! count($files2chmod) ){
$this->_forwardBack();
return $result;
}
foreach( $files2chmod as $fileName => $newMode ){
$actionString = M('action/chmod/description', array('fileName' => $fileName, 'mode' => $newMode));
$fileName = $this->getCurrentDir() . '/' . $fileName;
$processName = M('process/chmod', array('name' => $fileName) );
$this->addActionProcess( $processName );
$result = $this->fm->chmod( $fileName, $newMode );
if( $result )
$this->addActionResult( $actionString );
else
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
return $result;
}
function action_email(){
$result = 0;
$fileNames = $this->_req->getParam( CHNDL_FILE_NAME );
if( ! $fileNames ){
$this->_forwardBack();
return $result;
}
$sendToEmail = $this->_req->getParam( CHNDL_EMAIL_ADDRESS );
if( ! $sendToEmail ){
$this->_forwardBack();
return $result;
}
$fileGroup =& $this->_prepareFileGroup( $fileNames );
if( $fileGroup ){
$subj = M('action/email/msgSubject');
$fromName = M('action/email/msgFromName');
$from = M('action/email/msgFrom');
$msg = M('action/email/msgBody');
$msg .= join("\n", $fileGroup->getFileList());
$mm =& $this->_resp->getMessageManager();
$mm->process( $msg );
$mm->process( $subj );
$mm->process( $from );
$mm->process( $fromName );
SendEmail($from, $fromName, $sendToEmail, $subj, $msg, $fileGroup->getName(), $fileGroup->getFileHandle(), 0 );
$actionString = M('action/email/description', array('email' => $sendToEmail) );
$this->addActionResult( $actionString );
}
return $result;
}
function &_prepareFileGroup( &$fileList ){
$result = 0;
$prepareZip = 0;
$settingsManager =& mwfSettingsManager::getInstance();
$toEditExtensionsString = $settingsManager->get( SETTING_EDIT_EXTENSIONS );
$toEditArray = preg_split( "/\s*\,\s*/", $toEditExtensionsString );
if( count($fileList) > 1 ){
$prepareZip = 1;
}
else {
$fileName = $fileList[ 0 ];
if( $this->getCurrentDir() )
$fullName = $this->getCurrentDir() . '/' . $fileName;
else
$fullName = $fileName;
if ( $this->fm->isDir( $fullName ) )
$prepareZip = 1;
}
// NOW EXPAND THE SUPPLIED FILELIST - GET THE SUBDIRECTORIES LISTING
$fileList = $this->fm->expandFileList( $fileList, $this->getCurrentDir() );
// PREPARE ZIP
if( $prepareZip ){
$downloadFileName = 'mwftp_' . mt_rand(100000, 999999) . '.zip';
$downloadFileHandle =& $this->_prepareZip( $fileList );
if( $downloadFileHandle )
$result = 1;
}
// DO NOT PREPARE ZIP - FIRST FILE ONLY
else {
// DOWNLOAD MODE
preg_match("/\.(.{2,4})$/", $fullName, $matches);
$fileExtension = ($matches) ? $matches[0] : '';
if( inArrayWithWildcards($fileExtension, $toEditArray) ){
$mode = FILE_MODE_ASCII;
}
else {
$mode = FILE_MODE_BINARY;
}
$downloadFileHandle =& $this->fm->getFileHandle( $fullName, $mode );
if( $downloadFileHandle ){
$downloadFileName = $fileName;
$result = 1;
}
else {
$actionString = M('file/openRemoteFile', array('name' => $fileName));
$errorMessage = M('file/error/cannotOpenRemoteFile', array('name' => $fullName)) . ': ' . $this->fm->getLastSystemError();
$this->addActionResult( $actionString, 1, $errorMessage );
}
}
// PREPARING RESULT
if( $result ){
$fileGroup = new hcFileGroup();
$fileGroup->setFileList( $fileList );
$fileGroup->setFileHandle( $downloadFileHandle );
$fileGroup->setName( $downloadFileName );
$fileGroup->setTotalSize( $downloadFileHandle->getTotalSize() );
return $fileGroup;
}
else
return $result;
}
// RETURNS A ZIP FILE HANDLE OR null ON ERROR
function &_prepareZip( &$fileList ){
$settingsManager =& mwfSettingsManager::getInstance();
$toEditExtensionsString = $settingsManager->get( SETTING_EDIT_EXTENSIONS );
$toEditArray = preg_split( "/\s*\,\s*/", $toEditExtensionsString );
$result = 0;
$zipFileHandle = new hcZipFile();
reset( $fileList );
foreach( $fileList as $fileName ){
if( $this->getCurrentDir() )
$fullName = $this->getCurrentDir() . '/' . $fileName;
else
$fullName = $fileName;
$actionString = M('file/openRemoteFile', array('name' => $fullName));
// PREPARE ZIP FILE
// DOWNLOAD MODE
preg_match("/\.(.{2,4})$/", $fullName, $matches);
$fileExtension = ($matches) ? $matches[0] : '';
if( inArrayWithWildcards($fileExtension, $toEditArray) ){
$mode = FILE_MODE_ASCII;
}
else {
$mode = FILE_MODE_BINARY;
}
$fileContent = $this->fm->getFileContent( $fullName, $mode );
if( ! ( $fileContent || $fileContent = '') ){
$errorMessage = M('file/error/cannotOpenRemoteFile', array('name' => $fileName)) . ': ' . $this->fm->getLastSystemError();
$this->addActionResult( $actionString, 1, $errorMessage );
$result = 0;
break;
}
$result = 1;
$zipFileHandle->addFile( $fileContent, $fileName );
// WORKAROUND: as it may disconnect, reconnect again
$this->fm->quit();
$this->fm->init();
}
if( $result )
return $zipFileHandle;
else
return null;
}
function action_upload(){
$maxFileSize = 0;
if( defined('SETTING_MAX_FILE_SIZE') ){
$settingsManager =& mwfSettingsManager::getInstance();
$maxFileSize = $settingsManager->get( SETTING_MAX_FILE_SIZE );
$maxFileSize = 1024 * $maxFileSize;
}
$result = 0;
$uploadsCount = 0;
$filenum = 10;
$files2upload = array();
$tempDir = SESSION_TEMP_DIR . '/uploads';
if(! file_exists( SESSION_TEMP_DIR ))
mkdir(SESSION_TEMP_DIR, 0777);
if(! file_exists( $tempDir ))
mkdir($tempDir, 0777);
for($i = 1; $i <= $filenum; $i++){
$uploadFileControlName = CHNDL_UPLOAD_FIELD . $i;
$uploadModeControlName = CHNDL_UPLOAD_MODE . $i;
if( isset($_FILES[$uploadFileControlName]) )
$fileName = trim($_FILES[$uploadFileControlName]['name']);
else
continue;
if( ! $fileName )
continue;
$processName = M('process/putFileToWeb', array('name' => $fileName) );
$this->addActionProcess( $processName );
$uploadsCount++;
$mode = $_POST[$uploadModeControlName];
$actionString = M('action/upload/descriptionWithMode', array('fileName' => $fileName, 'transferMode' => getTranferModeString($mode)));
if( is_uploaded_file($_FILES[$uploadFileControlName]['tmp_name']) ){
$fileName = $this->getCurrentDir() . '/' . $fileName;
$fileSize = $_FILES[$uploadFileControlName]['size'];
if( $fileSize == 0 ){
$this->addActionResult( $actionString, 1, M('action/upload/error/zeroSize') );
continue;
}
elseif( $maxFileSize && $fileSize > $maxFileSize ){
$errorString = M('action/upload/error/tooBig', array('fileSize' => ceil($fileSize / 1024) . ' Kb', 'allowedSize' => $maxFileSize / 1024 . ' Kb'));
$this->addActionResult( $actionString, 1, $errorString );
continue;
}
else {
$localName = $_FILES[$uploadFileControlName]['tmp_name'];
/* THIS IS open_basedir WORKAROUND */
$myTempName = $tempDir . '/' . basename($localName);
move_uploaded_file( $localName, $myTempName );
$localName = $myTempName;
$files2upload[] = array(
'name' => $fileName,
'mode' => $mode,
'localName' => $localName,
);
}
}
else {
$errorCode = $_FILES[$uploadFileControlName]['error'];
if( defined('UPLOAD_ERR_INI_SIZE') && ($errorCode == UPLOAD_ERR_INI_SIZE) ){
$fileSize = $_FILES[$uploadFileControlName]['size'];
$phpUploadAllowed = ini_get('upload_max_filesize');
$errorString = M('action/upload/error/tooBig', array('fileSize' => ceil($fileSize / 1024) . ' Kb', 'allowedSize' => $phpUploadAllowed * 1024 . ' Kb'));
}
else {
$errorString = $php_errormsg;
}
$this->addActionResult( $actionString, 1, $errorString );
}
}
foreach( $files2upload as $fInfo ){
$fileName = $fInfo['name'];
$mode = $fInfo['mode'];
$localName = $fInfo['localName'];
$actionString = M('action/upload/descriptionWithMode', array('fileName' => $fileName, 'transferMode' => getTranferModeString($mode)));
$processName = M('process/putFileToFtp', array('name' => $fileName) );
$this->addActionProcess( $processName );
$result = $this->fm->upload( $localName, $fileName, $mode );
if( $result )
$this->addActionResult( $actionString );
else
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
cleanDir( $tempDir );
if( ! $uploadsCount )
$this->_forwardBack();
return $result;
}
function action_transload(){
$maxFileSize = 0;
if( defined('SETTING_MAX_FILE_SIZE') ){
$settingsManager =& mwfSettingsManager::getInstance();
$maxFileSize = $settingsManager->get( SETTING_MAX_FILE_SIZE );
$maxFileSize = 1024 * $maxFileSize;
}
$result = 0;
$uploadsCount = 0;
$filenum = 10;
$files2transload = array();
for($i = 1; $i <= $filenum; $i++){
$transloadFileControlName = CHNDL_TRANSLOAD_FIELD . $i;
$transloadModeControlName = CHNDL_TRANSLOAD_MODE . $i;
$fromURL = $this->_req->getParam($transloadFileControlName);
if( ! $fromURL || $fromURL == 'http://' )
continue;
$mode = $this->_req->getParam($transloadModeControlName);
$uploadsCount++;
if( ! preg_match("/^http:\/\//", $fromURL) )
$fromURL = 'http://' . $fromURL;
$fileName = basename( $fromURL );
$dirName = dirname( $fromURL );
$actionString = M('action/transload/description', array('fileName' => $fileName, 'sourceUrl' => $dirName));
// get the file from URL
$processName = M('process/getFileFromWeb', array('name' => $fileName) );
$this->addActionProcess( $processName );
if( ini_get('allow_url_fopen') ){
$fileContent = '';
if( ! ($fin = @fopen($fromURL, 'r')) ){
$errorMessage = M('action/transload/error/cannotOpenRemoteFile', array('url' => $fromURL, 'sourceUrl' => $dirName));
$errorMessage .= "<BR>fopen():" . $php_errormsg;
$this->addActionResult( $actionString, 1, $errorMessage );
continue;
}
}
else {
$fin = null;
$snoopy = new Snoopy();
$snoopy->fetch( $fromURL );
if( ! preg_match( '/^2\d{2}/', $snoopy->status ) ){ //NOT OK
$errorMessage = M('action/transload/error/cannotOpenRemoteFile', array('url' => $fromURL, 'sourceUrl' => $dirName));
$errorMessage .= "<BR>HTTP status: " . $snoopy->status;
$this->addActionResult( $actionString, 1, $errorMessage );
continue;
}
if (is_array($snoopy->results)){
$fileContent = implode( '', $snoopy->results );
}
else
$fileContent = $snoopy->results;
}
$files2transload[] = array(
'name' => $fileName,
'mode' => $mode,
'fromURL' => $fromURL,
'fileHandle' => $fin,
'fileContent' => $fileContent,
);
}
foreach( $files2transload as $fInfo ){
$fileName = $fInfo['name'];
$mode = $fInfo['mode'];
$fromURL = $fInfo['fromURL'];
$fileHandle =& $fInfo['fileHandle'];
$fileContent =& $fInfo['fileContent'];
$dirName = dirname( $fromURL );
$actionString = M('action/transload/description', array('fileName' => $fileName, 'sourceUrl' => $dirName));
$fileName = $this->getCurrentDir() . '/' . $fileName;
if( $fileHandle ){
$fileContent = '';
while (!feof($fileHandle)) {
$fileContent .= fread($fileHandle, 4096);
}
}
if( $fileContent ){
$fileSize = strlen( $fileContent );
if( $fileSize == 0 ){
$this->addActionResult( $actionString, 1, M('action/upload/error/zeroSize') );
continue;
}
elseif( $maxFileSize && $fileSize > $maxFileSize ){
$errorString = M('action/upload/error/tooBig', array('fileSize' => ceil($fileSize / 1024) . ' Kb', 'allowedSize' => $maxFileSize / 1024 . ' Kb'));
$this->addActionResult( $actionString, 1, $errorString );
continue;
}
$processName = M('process/putFileToFtp', array('name' => $fileName) );
$this->addActionProcess( $processName );
$result = $this->fm->setFileContent( $fileName, $fileContent, $mode );
}
else {
$this->addActionResult( $actionString, 1, M('action/upload/error/zeroSize') );
continue;
// $result = $this->fm->uploadByHandle( $fileHandle, $fileName, $mode );
}
if( $result ){
if( ( ! $fileContent ) && (! fclose($fileHandle)) ){
$errorMessage = M('action/transload/error/cannotCloseRemoteFile', array('url' => $fromURL));
$errorMessage .= "<BR>fclose():" . $php_errormsg;
$this->addActionResult( $actionString, 1, $errorMessage );
continue;
}
$this->addActionResult( $actionString );
}
else
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
if( ! $uploadsCount )
$this->_forwardBack();
return $result;
}
function action_applyfilter(){
$result = 0;
$filterValue = $this->_req->getParam( CHNDL_FILTER_VALUE_NAME );
if( ! $filterValue ){
$this->_forwardBack();
return $result;
}
$result = 1;
$this->_resp->setStateParam( CHNDL_FILTER_VALUE_NAME, $filterValue );
$this->_req->setStateParam( CHNDL_FILTER_VALUE_NAME, $filterValue );
// ALSO RESET PAGER
$filePager = new mwfFilePager;
$filePager->resetState( $this->_req, $this->_resp );
return $result;
}
function action_resetfilter(){
$result = 1;
$this->_resp->resetStateParam( CHNDL_FILTER_VALUE_NAME );
$this->_req->resetStateParam( CHNDL_FILTER_VALUE_NAME );
$this->_forwardBack();
return $result;
}
function action_ftpload(){
$result = 0;
$uploadsCount = 0;
$filenum = 10;
$files2ftpload = array();
$srcFTP_Host = $this->_req->getParam( CHNDL_FTPLOAD_SRC_HOST );
$srcFTP_User = $this->_req->getParam( CHNDL_FTPLOAD_SRC_USER );
$srcFTP_Pass = $this->_req->getParam( CHNDL_FTPLOAD_SRC_PASSWORD );
if( ! $srcFTP_Host && ! $srcFTP_User && ! $srcFTP_Pass ){
$this->_forwardBack();
return 0;
}
$actionString = M('action/ftpLoad');
if( ! ($srcFTP_Host && $srcFTP_User && $srcFTP_Pass) ){
$this->addActionResult( $actionString, 1, M('action/ftpLoad/noSourceFtpServerDetails') );
return 0;
}
$srcFTP = new mwfFileManagerFTP();
$srcFTP->setLoginInfo( $srcFTP_Host, $srcFTP_User, $srcFTP_Pass );
if( ! $srcFTP->init() ){
$this->addActionResult( $actionString, 1, $srcFTP->getLastSystemError() );
return 0;
}
for($i = 1; $i <= $filenum; $i++){
$ftploadFileControlName = CHNDL_FTPLOAD_FIELD . $i;
$ftploadModeControlName = CHNDL_FTPLOAD_MODE . $i;
$srcName = $this->_req->getParam($ftploadFileControlName);
if( ! $srcName )
continue;
$mode = $this->_req->getParam($ftploadModeControlName);
$uploadsCount++;
$shortName = basename( $srcName );
$actionString = M('action/ftpLoad/description', array('fileName' => $shortName, 'sourceServer' => $srcFTP_Host) );
// GET THE FILE FROM THE SRC FTP SERVER
$processName = M('process/getFileFromFtp', array('name' => $shortName) );
$this->addActionProcess( $processName );
$fileContent = $srcFTP->getFileContent( $srcName );
if( ! ( $fileContent || $fileContent = '') ){
$errorMessage = M('action/ftpLoad/error/cannotGetRemoteFile', array('fileName' => $srcName, 'ftpServer' => $srcFTP_Host) );
$this->addActionResult( $actionString, 1, $errorMessage );
continue;
}
$tempHandle = tmpfile();
fputs( $tempHandle, $fileContent );
rewind( $tempHandle );
$files2ftpload[] = array(
'name' => $shortName,
'mode' => $mode,
'srcName' => $srcName,
'fileHandle' => $tempHandle,
);
}
foreach( $files2ftpload as $fInfo ){
$fileName = $fInfo['name'];
$mode = $fInfo['mode'];
$srcName = $fInfo['srcName'];
$fileHandle =& $fInfo['fileHandle'];
$shortName = basename( $srcName );
$actionString = M('action/ftpLoad/description', array('fileName' => $shortName, 'srcFtpServer' => $srcFTP_Host));;
$fileName = $this->getCurrentDir() . '/' . $fileName;
$processName = M('process/putFileToFtp', array('name' => $shortName) );
$this->addActionProcess( $processName );
$result = $this->fm->uploadByHandle( $fileHandle, $fileName, $mode );
if( $result ){
if( ! fclose($fileHandle) ){
$errorMessage = M('file/error/cannotClose');
$errorMessage .= "<BR>fclose():" . $php_errormsg;
$this->addActionResult( $actionString, 1, $errorMessage );
continue;
}
$this->addActionResult( $actionString );
}
else
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
if( ! $uploadsCount )
$this->_forwardBack();
return $result;
}
/*
* END OF ACTION FUNCTIONS
*/
/*
* PREPARATIONS FOR CONCRETE VIEWS
*/
function &prepareView_FileList(){
$view =& $this->vm->getViewObject_FileList( $this->_req, $this->_resp );
$filter = $this->_req->getStateParam( CHNDL_FILTER_VALUE_NAME );
$currentDir = $this->getCurrentDir();
$currentDirName = ( $currentDir ) ? $currentDir : '';
$processName = M('process/getFileList', array('dirName' => $currentDirName) );
$this->addActionProcess( $processName );
$fileList = $this->fm->getFileList( $currentDir, $filter );
$this->_viewData['fileList'] = $fileList;
$this->_viewData['currentDir'] = $currentDir;
$this->_viewData['filter'] = $filter;
$this->_viewData['topLevelActions'] = $this->_tlActions;
$this->_viewData['user'] = $this->fm->getUser();
$this->_viewData['host'] = $this->fm->getHost();
$this->_viewData['allowedActions'] = $this->sm->listAllowedActions();
$settingsManager =& mwfSettingsManager::getInstance();
$toEditExtensionsString = $settingsManager->get( SETTING_EDIT_EXTENSIONS );
$toEditArray = preg_split( "/\s*\,\s*/", $toEditExtensionsString );
$toViewExtensionsString = $settingsManager->get( SETTING_VIEW_EXTENSIONS );
$toViewArray = preg_split( "/\s*\,\s*/", $toViewExtensionsString );
$fileExtensions = array();
$fileExtensions['edit'] = $toEditArray;
$fileExtensions['view'] = $toViewArray;
$this->_viewData['fileExtensions'] = $fileExtensions;
$view->setData( $this->_viewData );
return $view;
}
function &prepareView_SelectDir(){
$view =& $this->vm->getViewObject_SelectDir( $this->_req, $this->_resp );
$targetControl = $this->_req->getStateParam( PARAM_TARGET_CONTROL );
$this->_viewData['fileList'] = $this->fm->getFileList( $this->getCurrentDir() );
$this->_viewData['currentDir'] = $this->getCurrentDir();
$this->_viewData['targetControl'] = $targetControl;
$view->setData( $this->_viewData );
return $view;
}
function &prepareView_FileView(){
$view =& $this->vm->getViewObject_FileView( $this->_req, $this->_resp );
$view->setData( $this->_viewData );
return $view;
}
function &prepareView_FileEdit(){
$view =& $this->vm->getViewObject_FileEdit( $this->_req, $this->_resp );
$this->_viewData['currentDir'] = $this->getCurrentDir();
$this->_viewData['user'] = $this->fm->getUser();
$this->_viewData['host'] = $this->fm->getHost();
$this->_viewData['topLevelActions'] = $this->_tlActions;
$view->setData( $this->_viewData );
return $view;
}
function &prepareView_ActionResult(){
$view =& $this->vm->getViewObject_ActionResult( $this->_req, $this->_resp );
$this->_viewData['actionResults'] = $this->getActionResults();
$returnLinks =& $this->getReturnLinks();
if( $returnLinks ){
// HANDLE MULTIPLE RETURN LINKS - NOTHING ELSE TO DO
}
else {
$returnURL = $this->_resp->generateUrl(
array(), // action
array( 'p' => null )
);
$returnLinks[] = array( 'url' => $returnURL, 'title' => M('actionResult/returnBack') );
}
$this->_viewData['returnLinks'] = $returnLinks;
$view->setData( $this->_viewData );
return $view;
}
/*
* END OF CONCRETE VIEWS
*/
/*
* MISC METHODS
*/
function setFileManager( &$fm ){
$this->fm =& $fm;
}
function setTopLevelActions( &$tlActions ){
$this->_tlActions =& $tlActions;
}
/*
* END OF MISC METHODS
*/
}
?>
startFile : mwftp5/ftp/index_files/classes/mwfActionHandler_Free.php : 1
<?
include_once( dirname(__FILE__) . '/mwfActionHandler_Base.php' );
class mwfActionHandler extends mwfActionHandler_Base {
/*
* ACTION FUNCTIONS
*/
function action_newfile(){
$actionString = M('action/edit');
$result = 0;
$this->addActionResult( $actionString, 1, FREE_VERSION_NOTICE );
return $result;
}
function action_edit(){
$actionString = M('action/edit');
$result = 0;
$this->addActionResult( $actionString, 1, FREE_VERSION_NOTICE );
return $result;
}
function action_save(){
$actionString = M('action/save');
$result = 0;
$this->addActionResult( $actionString, 1, FREE_VERSION_NOTICE );
return $result;
}
function action_download(){
$actionString = M('action/download');
$result = 0;
$this->addActionResult( $actionString, 1, FREE_VERSION_NOTICE );
return $result;
}
function action_zip_upload(){
$actionString = M('action/unzipUpload');
$result = 0;
$this->addActionResult( $actionString, 1, FREE_VERSION_NOTICE );
return $result;
}
/*
* END OF ACTION FUNCTIONS
*/
}
?>
startFile : mwftp5/ftp/index_files/classes/mwfActionHandler_Full.php : 1
<?
include_once( dirname(__FILE__) . '/mwfActionHandler_Base.php' );
class mwfActionHandler extends mwfActionHandler_Base {
/*
* ACTION FUNCTIONS
*/
function action_newfile(){
$result = 0;
$name = $this->_req->getParam( CHNDL_NEW_FILE_NAME );
if( ! $name ){
$this->_forwardBack();
return $result;
}
$this->_viewData['fileContent'] = '';
$this->_viewData['fileName'] =& $name;
$this->setViewHandle( VIEW_HANDLE_FILE_EDIT );
}
function action_edit(){
$maxFileSize = 0;
if( defined('SETTING_MAX_FILE_SIZE') ){
$settingsManager =& mwfSettingsManager::getInstance();
$maxFileSize = $settingsManager->get( SETTING_MAX_FILE_SIZE );
$maxFileSize = 1024 * $maxFileSize;
}
$result = 0;
$name = $this->_req->getParam( CHNDL_FILE_NAME );
if( ! $name ){
$this->_forwardBack();
return $result;
}
$fullName = $this->getCurrentDir() . '/' . $name;
$actionString = "Open file <B>$name</B> to edit.";
$processName = M('process/getFileFromFtp', array('name' => $name) );
$this->addActionProcess( $processName );
$fileContent = $this->fm->getFileContent( $fullName );
$fileSize = strlen( $fileContent );
if( $maxFileSize && $fileSize > $maxFileSize ){
$errorString = M('action/upload/error/tooBig', array('fileSize' => ceil($fileSize / 1024) . ' Kb', 'allowedSize' => $maxFileSize / 1024 . ' Kb'));
$this->addActionResult( $actionString, 1, $errorString );
return $result;
}
if( $fileContent || $fileContent == '' ){
$result = 1;
}
if( $result ){
$this->_viewData['fileContent'] =& $fileContent;
$this->_viewData['fileName'] =& $name;
$this->setViewHandle( VIEW_HANDLE_FILE_EDIT );
}
else {
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
return $result;
}
function action_save(){
$maxFileSize = 0;
if( defined('SETTING_MAX_FILE_SIZE') ){
$settingsManager =& mwfSettingsManager::getInstance();
$maxFileSize = $settingsManager->get( SETTING_MAX_FILE_SIZE );
$maxFileSize = 1024 * $maxFileSize;
}
$result = 0;
$name = $this->_req->getParam( CHNDL_FILE_NAME );
if( ! $name ){
$this->_forwardBack();
return $result;
}
$saveIn = $this->_req->getParam( CHNDL_SAVEIN_DIR_NAME );
if( $saveIn != $this->getCurrentDir() ){
if( ! $this->cd( $saveIn ) ){
if( $saveIn )
$saveInString = $saveIn;
else {
$saveInString = M('common/homeDir');
$mm =& $this->_resp->getMessageManager();
$mm->process( $saveInString );
}
$actionString = M('action/save/description', array('name' => $name));
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
return $result;
}
}
$fullName = $this->getCurrentDir() . '/' . $name;
$actionString = M('action/save/description', array('name' => $fullName));
$processName = M('process/getPostData');
$this->addActionProcess( $processName );
$newFileContent = $this->_req->getParam( CHNDL_FILE_CONTENT );
$fileSize = strlen( $newFileContent );
if( $maxFileSize && $fileSize > $maxFileSize ){
$errorString = M('action/upload/error/tooBig', array('fileSize' => ceil($fileSize / 1024) . ' Kb', 'allowedSize' => $maxFileSize / 1024 . ' Kb'));
$this->addActionResult( $actionString, 1, $errorString );
return $result;
}
if( $newFileContent || $newFileContent == '' ){
$processName = M('process/putFileToFtp', array('name' => $name) );
$this->addActionProcess( $processName );
$result = $this->fm->setFileContent( $fullName, $newFileContent, FILE_MODE_ASCII );
}
if( $result ){
// TO THIS FILE EDIT
$title = M('common/toFileList');
$returnURL1 = $this->_resp->generateUrl();
$this->addReturnLink( $title, $returnURL1 );
// TO FILE LISTING
$title = M('action/edit/description', array('name' => $name) );
$returnURL2 = $this->_resp->generateUrl(
array (
'op' => 'edit',
CHNDL_FILE_NAME => $name
)
);
$this->addReturnLink( $title, $returnURL2 );
$this->addActionResult( $actionString );
}
else {
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
return $result;
}
function action_download(){
$result = 0;
$fileNames = $this->_req->getParam( CHNDL_FILE_NAME );
if( ! $fileNames ){
$this->_forwardBack();
return $result;
}
if( ! is_array($fileNames) )
$fileNames = array( $fileNames );
$fileGroup =& $this->_prepareFileGroup( $fileNames );
if( $fileGroup )
$this->_pushDownload( $fileGroup->getFileHandle(), $fileGroup->getName(), $fileGroup->getTotalSize() );
return $result;
}
function _pushDownload( &$fileHandle, $fileName, $totalSize = 0 ){
if( ob_get_contents() )
ob_end_clean();
header("Type: application/force-download");
header("Content-Type: application/force-download");
header("Content-Length: $totalSize");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=\"$fileName\"");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Connection: close");
while ( ! $fileHandle->feof() )
echo $fileHandle->fread(4096);
$fileHandle->fclose();
exit;
}
function action_zip_upload(){
$result = 0;
$uploadsCount = 0;
$filenum = 1;
$files2unzip = array();
$justCreatedDirs = array();
$tempDir = SESSION_TEMP_DIR . '/uploads';
for($i = 1; $i <= $filenum; $i++){
$uploadFileControlName = CHNDL_UPLOAD_FIELD . $i;
$uploadModeControlName = CHNDL_UPLOAD_MODE . $i;
if( isset($_FILES[$uploadFileControlName]) )
$fileName = trim($_FILES[$uploadFileControlName]['name']);
else
continue;
if( ! $fileName )
continue;
$processName = M('process/putFileToWeb', array('name' => $fileName) );
$this->addActionProcess( $processName );
$uploadsCount++;
$mode = $_POST[$uploadModeControlName];
$modeString = ($mode == UNZIP_MODE_TREE) ? M('action/unzipUpload/unzipMode/tree') : M('action/unzipUpload/unzipMode/flat');
$actionString = M('action/unzipUpload/description', array('fileName' => $fileName));
$actionString .= '. ' . M('action/unzipUpload/unzipMode') . ': ' . $modeString;
if( is_uploaded_file($_FILES[$uploadFileControlName]['tmp_name']) ){
$fileName = $this->getCurrentDir() . '/' . $fileName;
if( $_FILES[$uploadFileControlName]['size'] == 0 ){
$this->addActionResult( $actionString, 1, M('action/upload/error/zeroSize') );
continue;
}
else {
$localName = $_FILES[$uploadFileControlName]['tmp_name'];
$files2unzip[] = array(
'name' => $fileName,
'localName' => $localName,
'mode' => $mode,
);
}
}
else {
$errorCode = $_FILES[$uploadFileControlName]['error'];
if( defined('UPLOAD_ERR_INI_SIZE') && ($errorCode == UPLOAD_ERR_INI_SIZE) ){
$fileSize = $_FILES[$uploadFileControlName]['size'];
$phpUploadAllowed = ini_get('upload_max_filesize');
$errorString = M('action/upload/error/tooBig', array('fileSize' => ceil($fileSize / 1024) . ' Kb', 'allowedSize' => $phpUploadAllowed * 1024 . ' Kb'));
}
else {
$errorString = $php_errormsg;
}
$this->addActionResult( $actionString, 1, $errorString );
}
}
foreach( $files2unzip as $fInfo ){
$fileName = $fInfo['name'];
$localName = $fInfo['localName'];
$mode = $fInfo['mode'];
$modeString = ($mode == UNZIP_MODE_TREE) ? M('action/unzipUpload/unzipMode/tree') : M('action/unzipUpload/unzipMode/flat');
$actionString = M('action/unzipUpload/description', array('fileName' => $fileName));
$actionString .= '. ' . M('action/unzipUpload/unzipMode') . ': ' . $modeString;
$processName = M('process/unzip', array('name' => basename($fileName)) );
$this->addActionProcess( $processName );
$zip = new PclZip($localName);
$list = $zip->listContent();
if ($list == 0){
$errorString = $zip->errorInfo(true);
$errorMsg = M('action/unzipUpload/error/cannotOpenZip', array('errorString' => $errorString) );
$this->addActionResult( $actionString, 1, $errorMsg );
continue;
}
// CHECK IF IT IS WITHIN THE ALLOWED ZIP ENTRIES COUNT
// count files
$listCount = 0;
reset( $list );
foreach( $list as $li ){
if( ! $li['folder'] )
$listCount++;
}
$settingsManager =& mwfSettingsManager::getInstance();
$maxQty = $settingsManager->get( SETTING_UNZIP_UPLOAD_ENTRIES_QTY );
if( $listCount > $maxQty ){
$errorMsg = M('action/unzipUpload/error/tooManyFiles', array('count' => $listCount, 'maxCount' => $maxQty) );
$this->addActionResult( $actionString, 1, $errorMsg );
continue;
}
$filesCount = count( $list );
for ( $i = 0; $i < $filesCount; $i++ ){
$zipEntryFullName = $list[$i]['stored_filename'];;
$zipEntryFilesize = $list[$i]['size'];
if ( $zipEntryFilesize == 0 )
continue;
$fileInfo =& $zip->extractByIndex( $i, PCLZIP_OPT_PATH, $tempDir );
$zipEntryLocalName = $fileInfo[0]['filename'];;
$zipEntryFullName = $fileInfo[0]['stored_filename'];
if( $mode == UNZIP_MODE_TREE )
$zipEntryName = $zipEntryFullName;
else
$zipEntryName = basename( $zipEntryFullName );
$actionString = M('action/upload/description', array('fileName' => $zipEntryName));
// CREATE PATH DIRS
if( $mode == UNZIP_MODE_TREE ){
$zipEntryDir = dirname( $zipEntryFullName );
if( $zipEntryDir && $zipEntryDir != '.' && $zipEntryDir != '..' ){
$zipEntryFullDir = $this->getCurrentDir() . '/' . $zipEntryDir;
if( ! $this->fm->isDir($zipEntryFullDir) && ! in_array($zipEntryFullDir, $justCreatedDirs ) ){
$result = $this->fm->newDir( $zipEntryFullDir );
if( ! $result ){
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
continue;
}
$justCreatedDirs[] = $zipEntryFullDir;
$zipEntryFullDir = dirname($zipEntryFullDir);
while( $zipEntryFullDir && $zipEntryFullDir != '.' & $zipEntryFullDir != '/' && $zipEntryFullDir != '\/' ){
if( ! in_array( $zipEntryFullDir, $justCreatedDirs ) )
$justCreatedDirs[] = $zipEntryFullDir;
$zipEntryFullDir = dirname($zipEntryFullDir);
}
}
}
}
$zipEntryName = $this->getCurrentDir() . '/' . $zipEntryName;
$processName = M('process/putFileToFtp', array('name' => $zipEntryName) );
$this->addActionProcess( $processName );
$result = $this->fm->upload( $zipEntryLocalName, $zipEntryName );
// DELETE TEMP FILE
unlink( $zipEntryLocalName );
if( $result )
$this->addActionResult( $actionString );
else
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
}
if( ! $uploadsCount )
$this->_forwardBack();
cleanDir( $tempDir );
return $result;
}
/*
* END OF ACTION FUNCTIONS
*/
}
?>
startFile : mwftp5/ftp/index_files/classes/mwfFilePager.php : 1
<?
include_once( HCLIB_DIR . '/hcPagerStateBased.php' );
class mwfFilePager extends hcPagerStateBased {
function mwfFilePager(){
parent::hcPagerStateBased();
$tplDir = 'views/_common/pager';
$this->_tplFileMainMulti = $tplDir . '/mainMultiPages.tpl';
$this->_tplFileMainSingle = $tplDir . '/mainSinglePage.tpl';
$this->_tplFilePageCurrent = $tplDir . '/pageCurrent.tpl';
$this->_tplFilePageOther = $tplDir . '/pageOther.tpl';
$this->setConfFile( FILES_DIR . '/conf/filePager.conf');
$this->conf();
}
}
?>
startFile : mwftp5/ftp/index_files/classes/mwfFileSorter.php : 1
<?
include_once( HCLIB_DIR . '/hcSorter.php' );
class mwfFileSorter extends hcSorter {
function mwfFileSorter(){
parent::hcSorter();
$tplDir = FILES_DIR . '/templates/views/_common/sorter';
$this->_tplFileMainNoSorting = $tplDir . '/mainNoSorting.tpl';
$this->_tplFileMainWithSorting = $tplDir . '/mainWithSorting.tpl';
$this->_tplFileCriterionNotSelected = $tplDir . '/criterionNotSelected.tpl';
$this->_tplFileCriterionSelectedAsc = $tplDir . '/criterionSelectedAsc.tpl';
$this->_tplFileCriterionSelectedDesc = $tplDir . '/criterionSelectedDesc.tpl';
$this->setConfFile( FILES_DIR . '/conf/fileSorter.conf');
$this->conf();
}
}
?>
startFile : mwftp5/ftp/index_files/classes/mwfPath.php : 1
<?
include_once( HCLIB_DIR . '/hcActionControl.php' );
class mwfPath extends hcActionControl {
var $path;
var $urls;
var $links;
var $sep;
function mwfPath( $path = '' ){
$this->links = array();
$this->titles = array();
$this->sep = ' / ';
}
function initPath( $path = '' ){
if( substr($path, 0, 1) == '/' )
$homeLink = '/';
else
$homeLink = '';
$split = explode('/', $path);
$adder = '';
foreach($split as $dir){
if( ! $dir)
continue;
if( $adder )
$this->links[] = $adder . '/' . $dir;
else
$this->links[] = $homeLink . $dir;
$this->titles[] = $dir;
if( $adder )
$adder .= "/$dir";
else
$adder = $homeLink . $dir;
}
// add home directory
array_unshift( $this->links, $homeLink );
array_unshift( $this->titles, M('common/home') );
}
function init( &$req, &$resp ){
$this->_req =& $req;
$this->_resp =& $resp;
}
function view(){
$v = '';
if( $this->_wrappingDiv )
$v .= $this->getWrappingDivString();
$count = count($this->links);
for( $i = 0; $i < $count ; $i++ ){
$compSep = ( $i ) ? $this->sep : '';
$viewTitle = $this->titles[$i];
$link = new hcActionControl_Link( $this->_resp );
$link->setValue( $viewTitle );
// CURRENT DIRECTORY
if( $i == ($count - 1) ){
$link->wrapBy( new hcHtmlElement('<STRONG>') );
}
else {
$goTo = $this->links[$i];
if( $goTo ){
$link->setParam( 'op', 'chdir' );
$link->setParam( CHNDL_DIR_NAME, $this->links[$i] );
}
else {
$link->setStateParam( CHNDL_DIR_NAME, null );
}
}
$v .= $compSep . $link->view();
}
if( $this->_wrappingDiv )
$v .= '</DIV>';
return $v;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/fileManager/mwfFileManager.php : 1
<?
class mwfFileManager {
var $_currentFileList;
var $_fileLists;
var $_lastSystemError;
var $_rootDir;
function mwfFileManager(){
$this->_currentFileList = null;
$this->_fileLists = array();
$this->_lastSystemError = '';
$this->_rootDir = '';
}
function setRootDir( $dirName = "/" ){
$dirName = $this->normalizePath( $dirName );
$this->_rootDir = $dirName;
}
function &getFileList( $path, $filter = '' ){
$pathHandle = ( $path ) ? $path : '~';
if( ! isset($this->_fileLists[$pathHandle]) )
$this->_loadFileList( $path );
if( $filter ){
$returnArray = applyFilter( $this->_fileLists[$pathHandle], $filter, 'name' );
}
else
$returnArray =& $this->_fileLists[$pathHandle];
return $returnArray;
}
function getFileInfo( $fullName ){
$returnArray = null;
$dirName = dirname( $fullName );
$fileName = basename( $fullName );
$fileList =& $this->getFileList( $dirName );
if( isset( $fileList[$fileName] ) )
$returnArray = $fileList[$fileName];
return $returnArray;
}
function init(){
// TO IMPLEMENT IN CHILD CLASSES
return 1;
}
function _loadFileList( $path = '' ){
// TO IMPLEMENT IN CHILD CLASSES
}
function setLastSystemError( $errStr ){
$this->_lastSystemError = $errStr;
}
function getLastSystemError(){
return $this->_lastSystemError;
}
function getFullPath( $relativePath = '' ){
if( $this->_rootDir )
$fullPath = $this->_rootDir . '/' . $relativePath;
else
$fullPath = $relativePath;
$fullPath = $this->normalizePath( $fullPath );
return $fullPath;
}
function getRelativePath( $fullPath = '' ){
$fullPath = $this->normalizePath( $fullPath );
$relativePath = substr( $fullPath, strlen($this->_rootDir) );
return $relativePath;
}
function getPath( $dirName, $fName ){
$path = $currentDir . '/' . $dirName;
$path = $this->normalizePath( $path );
// STRIP STARTING SLASH
if( substr($path, 0, 1) == '/'){
$path = substr($path, 1);
}
return $path;
}
function isDir( $fullName ){
$dirName = dirname( $fullName );
$fName = basename( $fullName );
$currentFileList =& $this->getFileList( $dirName );
if( isset($currentFileList[$fName]) && ($currentFileList[$fName]['type'] == 'dir') )
return 1;
else
return 0;
}
function expandFileList( $fileList, $prefixDir ){
// $fileList is just an array of names, without infos
$returnFileList = array();
reset( $fileList );
foreach( $fileList as $fName ){
$fullName = $prefixDir . '/' . $fName;
// DIRECTORY
if( $this->isDir( $fullName ) ){
$childDirFileList =& $this->getFileList( $fullName );
$childDirFileList_FullNames = array();
foreach( array_keys($childDirFileList) as $fn )
$childDirFileList_FullNames[] = $fName . '/' . $fn;
$returnFileList = array_merge( $returnFileList, $this->expandFileList($childDirFileList_FullNames, $prefixDir) );
}
// FILE
else
$returnFileList[] = $fName;
}
return $returnFileList;
}
/*
* This function replaces the \ with / and deletes excessive slashes
*/
function normalizePath( $fName ){
$posSlash = strpos( $fName, "/" );
$posForwardSlash = strpos( $fName, "\/" );
// ONLY FILE NAME IS GIVEN
if( ($posSlash === false) && ($posForwardSlash === false) ){
// return the file name itself
}
// FULL PATH IS GIVEN. ALTHOUGH IT IS RELATIVE TO THE ROOT DIRECTORY
else {
$fName = str_replace( "\\", "/", $fName );
$fName = preg_replace( "/\/{2,}/", "/", $fName );
}
return $fName;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/fileManager/mwfFileManagerFTP.php : 1
<?
include_once( 'mwfFileManager.php' );
include_once( HCLIB_DIR . '/ftp-client-class.php' );
include_once( FILES_DIR . '/classes/listingParser/mwfRawListingParser_FTP_Win.php' );
include_once( FILES_DIR . '/classes/listingParser/mwfRawListingParser_FTP_Unix.php' );
class mwfFileManagerFTP extends mwfFileManager {
var $ftp;
var $ftpHost;
var $ftpUser;
var $ftpPass;
var $ftpPort;
var $_pwd;
function mwfFileManagerFTP(){
parent::mwfFileManager();
$this->_pwd = null;
$this->ftp =& getFtpEngine();
$this->ftp->timeout = 5;
$this->ftp->debug = false;
}
function setLoginInfo( $ftpHost, $ftpUser, $ftpPass, $ftpPort = 21 ){
//parse $ftpHost to get a port
if ( preg_match('/:/', $ftpHost) ){
preg_match('/(.+):(.+)/', $ftpHost, $m);
$ftpHost = $m[1];
$ftpPort = $m[2];
}
$this->ftpHost = $ftpHost;
$this->ftpUser = $ftpUser;
$this->ftpPass = $ftpPass;
$this->ftpPort = $ftpPort;
}
function getUser(){
return $this->ftpUser;
}
function getHost(){
return $this->ftpHost;
}
function init(){
$return = 0;
$return = $this->login( $this->ftpHost, $this->ftpUser, $this->ftpPass, $this->ftpPort );
return $return;
}
function quit(){
$this->ftp->ftp_quit();
}
function login(){
$return = 0;
if (! $this->ftp->ftp_connect( $this->ftpHost, $this->ftpPort ) ){
$errorString = M('ftp/action/login/error/cannotConnect', array('ftpHost' => $this->ftpHost, 'ftpPort' => $this->ftpPort) );
$errorString .= '<BR>' . M('common/systemErrorMessage') . ': ' . $this->ftp->getLastSystemMessage();
$this->setLastSystemError( $errorString );
return $return;
}
if (! $this->ftp->ftp_login( $this->ftpUser, $this->ftpPass ) ){
$this->quit();
$errorString = M('ftp/action/login/error/cannotLogin', array('ftpHost' => $this->ftpHost, 'ftpUser' => $this->ftpUser) );
$errorString .= '<BR>' . M('common/systemErrorMessage') . ': ' . $this->ftp->getLastSystemMessage();
$this->setLastSystemError( $errorString );
return $return;
}
$return = 1;
return $return;
}
function cd( $dirName = "" ){
$return = 0;
$dir2go = $this->getFullPath( $dirName );
if( $this->ftp->ftp_chdir( $dir2go ) )
$return = 1;
else
$this->setLastSystemError( $this->ftp->getLastSystemMessage() );
if( $return )
$this->setPwd( $this->getPwd() );
// $this->setPwd( $dir2go );
return $return;
}
function setPwd( $dir ){
$this->_pwd = $dir;
}
function getPwd(){
$fullDir = $this->ftp->ftp_pwd();
// GET RELATIVE DIR
$relativeDir = $this->getRelativePath( $fullDir );
return $relativeDir;
}
function pwd(){
if( isset($this->_pwd) )
$fullDir = $this->_pwd;
else
$fullDir = $this->ftp->ftp_pwd();
// GET RELATIVE DIR
$relativeDir = $this->getRelativePath( $fullDir );
return $relativeDir;
}
function _loadFileList( $path = '' ){
$rawList = array();
$pwd = $this->getPwd();
if( $pwd != $path ){
$fullPath = $this->getFullPath( $path );
if( $fullPath ){
if( $this->ftp->ftp_chdir( $fullPath ) ){
$rawList = $this->ftp->ftp_rawlist();
}
}
else
$rawList = $this->ftp->ftp_rawlist();
$this->ftp->ftp_chdir( $pwd );
}
else {
$rawList = $this->ftp->ftp_rawlist();
}
if( ! $rawList )
$rawList = array();
$rawListingParser =& $this->_findParser( $rawList );
$fileList =& $rawListingParser->parse( $rawList );
$pathHandle = ( $path ) ? $path : '~';
$this->_fileLists[$pathHandle] =& $fileList;
}
function _findParser( &$rawListing ){
reset( $rawListing );
$os = 'unix';
foreach( $rawListing as $line ){
$line = trim( $line );
if( ! $line )
continue;
if( preg_match("/^total/", $line) || preg_match("/\.{1,2}$/", $line) )
continue;
$re1 = '/^([0-9\-]{8})[ ]+([0-9:]{5}[APM]{2})[ ]+[ ]+[ ]+[ ]/'; // RE to check if it's win
if( preg_match($re1, $line) ) //windows one
$os = 'win';
else
$os = 'unix';
break;
}
switch( $os ){
case 'win':
$rawListingParser = new mwfRawListingParser_FTP_Win;
break;
case 'unix':
$rawListingParser = new mwfRawListingParser_FTP_Unix;
break;
}
return $rawListingParser;
}
function deleteFile( $fName ){
$return = 0;
$fName = $this->getFullPath( $fName );
if( $this->ftp->ftp_delete($fName) )
$return = 1;
else
$this->setLastSystemError( $this->ftp->getLastSystemMessage() );
return $return;
}
function deleteDir( $dirName ){
$return = 1;
// FIRST TRY TO DELETE THE DIRECTORY ITSELF
// GET A LIST OF ALL THE FILES IN THE DIRECTORY
$thisDirList =& $this->getFileList( $dirName );
// GO THRU AND DELETE EACH FILE OR SUB-DIRECTORY
foreach( $thisDirList as $ni ){
if( ! $ni )
continue;
if( $ni['type'] == 'dir'){ //delete dir
if( ! $this->deleteDir( $dirName . '/' . $ni['name'] ) ){
$return = 0;
break;
}
}
else { //delete file
if( ! $this->deleteFile( $dirName . '/' . $ni['name'] ) ){
$return = 0;
break;
}
}
}
// NOW DELETE THE DIR ITSELF
if( $return ){
$fullDirName = $this->getFullPath( $dirName );
if( ! $this->ftp->ftp_rmdir($fullDirName) ){
$this->setLastSystemError( $this->ftp->getLastSystemMessage() );
$return = 0;
}
}
return $return;
}
function rename( $oldName, $newName ){
$return = 0;
$oldName = $this->getFullPath( $oldName );
$newName = $this->getFullPath( $newName );
if( $this->ftp->ftp_rename($oldName, $newName) )
$return = 1;
else
$this->setLastSystemError( $this->ftp->getLastSystemMessage() );
return $return;
}
function copy( $fromName, $toName, $mode = FILE_MODE_BINARY ){
$return = 0;
$this->quit();
$this->init();
$fileContent = $this->getFileContent($fromName);
$result = 0;
if( $fileContent || $fileContent == '' ){
$this->quit();
$this->init();
$result = $this->setFileContent($toName, $fileContent);
}
if( $result )
$return = 1;
else
$this->setLastSystemError( $this->ftp->getLastSystemMessage() );
return $return;
}
function chmod( $fileName, $newMode ){
$return = 0;
$fileName = $this->getFullPath( $fileName );
$string = "CHMOD $newMode $fileName";
if( $this->ftp->ftp_site($string) )
$return = 1;
else
$this->setLastSystemError( $this->ftp->getLastSystemMessage() );
return $return;
}
function upload( $localName, $toName, $mode = FILE_MODE_BINARY ){
$return = 0;
$toName = $this->getFullPath( $toName );
if( $this->ftp->ftp_put($toName, $localName, $mode) )
$return = 1;
else
$this->setLastSystemError( $this->ftp->getLastSystemMessage() );
return $return;
}
function uploadByHandle( &$localFH, $toName, $mode = FILE_MODE_BINARY ){
$return = 0;
$toName = $this->getFullPath( $toName );
if( $this->ftp->ftp_fput($toName, $localFH, $mode) )
$return = 1;
else
$this->setLastSystemError( $this->ftp->getLastSystemMessage() );
return $return;
}
function setFileContent( $fName, $fileContent, $mode = FILE_MODE_BINARY ){
$return = 0;
if( ! $fName ){
$this->setLastSystemError( 'getFileContent(): filename is not specified!' );
return $return;
}
$fName = $this->getFullPath( $fName );
$localHandle = tmpfile();
fwrite( $localHandle, $fileContent );
if( ! $this->ftp->ftp_fput($fName, $localHandle, $mode) ){
$this->setLastSystemError( $this->ftp->getLastSystemMessage() );
return $return;
}
$return = 1;
return $return;
}
function getFileContent( $fName, $mode = FILE_MODE_BINARY ){
$fileContent = '';
if( ! $fName ){
$this->setLastSystemError( 'getFileContent(): filename is not specified!' );
return 0;
}
$fh =& $this->getFileHandle( $fName, $mode );
if( ! $fh )
return 0;
while ( ! $fh->feof() )
$fileContent .= $fh->fread(4096);
$fh->fclose();
return $fileContent;
}
function &getFileHandle( $fName, $mode = FILE_MODE_BINARY ){
$return = null;
if( ! $fName ){
$this->setLastSystemError( 'getFileHandle(): filename is not specified!' );
return $return;
}
$fileInfo = $this->getFileInfo( $fName );
$fileSize = $fileInfo['size'];
$fName = $this->getFullPath( $fName );
$fsock = tmpfile();
if( ! $this->ftp->ftp_fget( $fsock, $fName, $mode ) ){
$this->setLastSystemError( $this->ftp->getLastSystemMessage() );
return $return;
}
$fh = new hcFileHandle( $fsock );
$fh->setTotalSize( $fileSize );
return $fh;
}
function getFileInfo( $fileName ){
preg_match( "/^(.*)?\/(.*)/", $fileName, $m );
if( count($m) > 1 )
$path = $m[ 1 ];
else
$path = '';
$fileListInfo =& $this->getFileList( $path );
$fileInfo =& $fileListInfo[ basename($fileName) ];
return $fileInfo;
}
function newDir( $dirName ){
$return = 0;
$parentDir = dirname($dirName);
if( $parentDir && $parentDir != '/' && $parentDir != '\\' && ( ! $this->isDir( $parentDir ) ) )
$this->newDir( $parentDir );
$dirName = $this->getFullPath( $dirName );
if( $this->ftp->ftp_mkdir($dirName) )
$return = 1;
else
$this->setLastSystemError( $this->ftp->getLastSystemMessage() );
return $return;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/fileManager/mwfFileManagerLocal.php : 1
<?
include_once( 'mwfFileManager.php' );
class mwfFileManagerLocal extends mwfFileManager {
function mwfFileManagerLocal(){
parent::mwfFileManager();
}
function cd( $dirName = "" ){
$return = 0;
$dir2go = $this->getFullPath( $dirName );
if( @chdir( $dir2go ) )
$return = 1;
else
$this->setLastSystemError( $php_errormsg );
return $return;
}
function pwd(){
$fullDir = getcwd();
// GET RELATIVE DIR
$relativeDir = $this->getRelativePath( $fullDir );
return $relativeDir;
}
function _loadFileList(){
$this->_currentFileList = array();
$fullDir = $this->getFullPath( $this->pwd() );
if( $dh = opendir($fullDir) ){
while( ($file = readdir($dh)) !== false ){
if( $file == '.' || $file == '..' )
continue;
$f = array();
$fullName = $fullDir . '/' . $file;
$fileStat = stat( $fullName );
if( is_dir($fullName) ){
$f['type'] = 'dir';
$f['weight'] = 2;
$f['size'] = 0;
}
elseif( is_link($fullName) ) {
$f['type'] = 'link';
$f['weight'] = 1;
$f['size'] = 0;
}
else {
$f['type'] = 'file';
$f['weight'] = 0;
$f['size'] = $fileStat[7] / 1024;
}
$f['name'] = $file;
$this->_currentFileList[] = $f;
}
closedir($dh);
}
}
}
?>
startFile : mwftp5/ftp/index_files/classes/listingParser/mwfRawListingParser_FTP.php : 1
<?
class mwfRawListingParser_FTP {
function afterParse( &$list ){
foreach( array_keys($list) as $name ){
$ni =& $list[ $name ];
if(substr($ni['mode'], 0, 1) == 'd'){ //directory
$ni['type'] = 'dir';
$ni['weight'] = 2;
}
elseif(substr($ni['mode'], 0, 1) == 'l'){ //link
$ni['type'] = 'link';
$name = $ni['name'];
preg_match( '/(.+)\s*->\s*(.+)$/', $name, $m );
// $name = preg_replace( '/\s+->.+$/', '', $name );
$linkName = $m[1];
$goto = $m[2];
$ni['name'] = $linkName;
$ni['goto'] = $goto;
$ni['weight'] = 1;
}
else {
preg_match("/\.(.{2,4})$/", $ni['name'], $matches);
$ni['type'] = ($matches) ? $matches[0] : '?';
$ni['weight'] = 0;
}
$list[ $name ] =& $ni;
}
}
}
?>
startFile : mwftp5/ftp/index_files/classes/listingParser/mwfRawListingParser_FTP_Unix.php : 1
<?
include_once( 'mwfRawListingParser_FTP.php' );
class mwfRawListingParser_FTP_Unix extends mwfRawListingParser_FTP {
function &parse( &$rawList ){
// SOME CONFIGURATION VARS
$listField = array('mode', 'digit', 'owner', 'group', 'size', 'month', 'day', 'time', 'name');
$months = array('Jan'=>'01', 'Feb'=>'02', 'Mar'=>'03', 'Apr'=>'04', 'May'=>'05', 'Jun'=>'06', 'Jul'=>'07', 'Aug'=>'08', 'Sep'=>'09', 'Oct'=>'10', 'Nov'=>'11', 'Dec'=>'12');
$num = count( $rawList );
$returnList = array();
for($i = 0; $i < $num; $i++){
$line = trim($rawList[$i]);
if( ! $line )
continue;
if( preg_match("/^total/", $line) || preg_match("/\.{1,2}$/", $line) )
continue;
$ni = array();
$splittingCode = 'list(';
foreach( $listField as $field )
$splittingCode .= '$ni["' . $field . '"], ';
$splittingCode .= ') = preg_split("/ +/", $line, 9);';
eval("$splittingCode");
$noYear = false;
// now parse date and time
$new_time = preg_replace("/(\d{1,})\:(\d{1,})/", sprintf("%02d:%02d",'\\1','\\2'), $ni['time']);
if($new_time != $ni['time']){ //current year
// sometimes it is not current year but previous if date is bigger than today's
$currentYear = date("Y");
$noYear = true;
$ni['year'] = $currentYear;
}
else {
$ni['year'] = $ni['time'];
$ni['time'] = '00:00';
}
preg_match("/(\d{1,2})\:(\d{1,2})/", $ni['time'], $matches);
$ni['hour'] = $matches[1]; $ni['minute'] = $matches[2];
$ni['date'] = mktime( $ni['hour'], $ni['minute'], 0, $months[$ni['month']], $ni['day'], $ni['year'] );
if( $noYear ){
if( $ni['date'] > time() ){
$ni['year'] = $ni['year'] - 1;
$ni['date'] = mktime( $ni['hour'], $ni['minute'], 0, $months[$ni['month']], $ni['day'], $ni['year'] );
}
}
// creating a hash
$returnList[ $ni['name'] ] = $ni;
}
$this->afterParse( $returnList );
return $returnList;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/listingParser/mwfRawListingParser_FTP_Win.php : 1
<?
include_once( 'mwfRawListingParser_FTP.php' );
class mwfRawListingParser_FTP_Win extends mwfRawListingParser_FTP {
function &parse( &$rawList ){
// SOME CONFIGURATION VARS
$listField = array('date', 'time', 'size', 'name');
$months = array('Jan'=>'01', 'Feb'=>'02', 'Mar'=>'03', 'Apr'=>'04', 'May'=>'05', 'Jun'=>'06', 'Jul'=>'07', 'Aug'=>'08', 'Sep'=>'09', 'Oct'=>'10', 'Nov'=>'11', 'Dec'=>'12');
$num2months = array('01'=>'Jan', '02'=>'Feb', '03'=>'Mar', '04'=>'Apr', '05'=>'May', '06'=>'Jun', '07'=>'Jul', '08'=>'Aug', '09'=>'Sep', '10'=>'Oct', '11'=>'Nov', '12'=>'Dec');
$num = count( $rawList );
$returnList = array();
for($i = 0; $i < $num; $i++){
$line = trim($rawList[$i]);
if( ! $line )
continue;
if( preg_match("/^total/", $line) || preg_match("/\.{1,2}$/", $line) )
continue;
$ni = array();
if ( preg_match('<DIR>', $line) )//directory
$ni['mode'] = 'd';
else
$ni['mode'] = '-';
$splittingCode = 'list(';
foreach( $listField as $field )
$splittingCode .= '$ni["' . $field . '"], ';
$splittingCode .= ') = preg_split("/ +/", $line, 4);';
eval("$splittingCode");
// now parse date and time
preg_match( '/(\d{1,})\:(\d{1,})([PA])M/', $ni['time'], $m );
$hour = $m[1]; $min = $m[2];
if( $m[3] == 'P' )
$hour += 12;
$ni['time'] = "$hour:$min";
$ni['hour'] = $hour;
$ni['minute'] = $min;
// parse date
preg_match( '/(\d{1,})-(\d{1,})-(\d{1,})/', $ni['date'], $m );
if( $m[3] < 50 ) // > 2000
$ni['year'] = 2000 + $m[3];
else
$ni['year'] = 1900 + $m[3];
$ni['day'] = $m[2];
$ni['month'] = $num2months[ $m[1] ];
$ni['date'] = mktime( $ni['hour'], $ni['minute'], 0, $months[$ni['month']], $ni['day'], $ni['year'] );
$ni['owner'] = 'n/a';
$ni['group'] = 'n/a';
// creating a hash
$returnList[ $ni['name'] ] = $ni;
}
$this->afterParse( $returnList );
return $returnList;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/mwfViewManager.php : 1
<?
class mwfViewManager {
var $_dir;
function mwfViewManager( $dir ){
$this->_dir = $dir;
}
function &getViewObject_FileList( &$req, &$resp ){
include_once( $this->_dir . '/mwfView_FileList.php' );
$viewObject = new mwfView_FileList( $req, $resp );
return $viewObject;
}
function getViewObject_Forward( &$req, &$resp ){
include_once( HCLIB_DIR . '/hcView_Forward.php' );
$viewObject = new hcView_Forward( $req, $resp );
return $viewObject;
}
function getViewObject_SelectDir( &$req, &$resp ){
include_once( $this->_dir . '/mwfView_SelectDir.php' );
$viewObject = new mwfView_SelectDir( $req, $resp );
return $viewObject;
}
function getViewObject_FileView( &$req, &$resp ){
include_once( $this->_dir . '/mwfView_FileView.php' );
$viewObject = new mwfView_FileView( $req, $resp );
return $viewObject;
}
function getViewObject_FileEdit( &$req, &$resp ){
include_once( $this->_dir . '/mwfView_FileEdit.php' );
$viewObject = new mwfView_FileEdit( $req, $resp );
return $viewObject;
}
function getViewObject_ActionResult( &$req, &$resp ){
include_once( $this->_dir . '/mwfView_ActionResult.php' );
$viewObject = new mwfView_ActionResult( $req, $resp );
return $viewObject;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/mwfView.php : 1
<?
class mwfView extends mwfCommonView {
function mwfView( &$req, &$resp ){
parent::mwfCommonView( $req, $resp );
$this->setTemplatesDir( FILES_DIR . '/templates/views/rich' );
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/mwfView_ActionResult.php : 1
<?
include_once( 'mwfView.php' );
class mwfView_ActionResult extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
actionResults => action, is_error, msg
returnLinks => array of return options - each as array( 'url' => url, 'title' => title )
*/
function view(){
$viewData =& $this->getData();
$actionResults = $viewData['actionResults'];
$actionResultsTemplateContainer = new hcViewContainer( $this->getTemplatesDir() . '/ActionResult/actionResults.tpl' );
$this->prefillViewContainer( $actionResultsTemplateContainer );
$arContainer = new hcViewContainer( $this->getTemplatesDir() . '/ActionResult/actionResult.tpl' );
$arString = '';
// ACTION RESULTS
foreach( $actionResults as $ar ){
$this->fillActionResultContainer( $arContainer, $ar );
$arString .= $arContainer->view();
$arContainer->clearChildren();
}
// RETURN LINKS
$returnLinks = $viewData['returnLinks'];
$rlArray = array();
foreach( $returnLinks as $rlInfo ){
$rl = new hcActionControl_Link( $this->_resp );
$rl->setValue( $rlInfo['title'] );
$rl->forceURL( $rlInfo['url'] );
$rlArray[] = $rl;
$rlArray[] = '<BR>';
}
$actionResultsTemplateContainer->addChild( $arString, 'ACTION_RESULTS' );
$actionResultsTemplateContainer->addChild( $rlArray, 'RETURN_LINKS' );
echo parent::view( $actionResultsTemplateContainer->view() );
}
function fillActionResultContainer( &$viewContainer, &$actionInfo ){
$status = $actionInfo['is_error'] ? M('actionResult/resultFailed') : M('actionResult/resultOk');
$viewContainer->addChild( $actionInfo['action'], 'ACTION_REQUESTED' );
$viewContainer->addChild( $status, 'STATUS' );
$viewContainer->addChild( $actionInfo['msg'], 'ERROR_MSG' );
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/mwfView_FileEdit.php : 1
<?
include_once( 'mwfView.php' );
class mwfView_FileEdit extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
* fileContent - the file content
* currentDir - current directory
*/
function view(){
$viewData =& $this->getData();
$fileName = $viewData['fileName'];
$currentDir = $viewData['currentDir'];
$fileContent = $viewData['fileContent'];
$form = new hcActionForm( $this->_resp );
$form->setAction( APP_ROOT_PAGE );
/*
* init path
*/
$path = new mwfPath;
$path->init( $this->_req, $this->_resp );
$path->initPath( $currentDir );
// FILE CONTENT CONTROL
$fileContentControl = new hcActionControl_Textarea( $this->_resp );
$fileContentControl->forceHTMLName( CHNDL_FILE_CONTENT );
$fileContentControl->setValue( $fileContent );
$fileContentControl->nowrap();
// FILE NAME AND DIR CONTROLS
$fileControlsGroup = new hcActionControlSet();
$fileControlsGroup->setLegend( M('action/edit/saveAs') );
// SAVEIN CONTROL
$saveToDirGroup = new hcActionControlGroup();
$saveInControl = new hcActionControl_Text( $this->_resp );
$saveInControl->forceHTMLName( CHNDL_SAVEIN_DIR_NAME );
$saveInControl->setValue( $currentDir );
$saveInControl->setLabel( M('action/edit/dirName') );
$saveInControl->setSize( 80 );
$btnSelectDir = new hcActionControl_Button( $this->_resp );
$btnSelectDir->setValue( M('form/selectDir') );
$dirSelectorWinURL = $this->_resp->generateURL(
array(),
array(
PARAM_VIEW_HANDLE => VIEW_HANDLE_SELECT_DIR,
PARAM_TARGET_CONTROL => $form->getName() . '.' . $saveInControl->getHTMLName(),
)
);
$btnSelectDir->setOnClick( "openWindow(\"$dirSelectorWinURL\");" );
$saveToDirGroup->addChild( $saveInControl );
$saveToDirGroup->addChild( $btnSelectDir );
$saveToDirGroup->wrapBy( new hcHtmlElement('<DIV>') );
// FILENAME CONTROL
$saveToFileGroup = new hcActionControlGroup();
$fnameControlGroup = new hcActionControlSet();
$fnameControl = new hcActionControl_Text( $this->_resp );
$fnameControl->setLabel( M('action/edit/fileName') );
$fnameControl->forceHTMLName( CHNDL_FILE_NAME );
$fnameControl->setValue( $fileName );
$fnameControl->setSize( 40 );
$saveToFileGroup->addChild( $fnameControl );
$saveToFileGroup->wrapBy( new hcHtmlElement('<DIV>') );
$fileControlsGroup->addChild( $saveToDirGroup );
$fileControlsGroup->addChild( $saveToFileGroup );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
// SAVE
$btnSave = new hcActionControl_Submit( $this->_resp );
$btnSave->setParam( 'op', 'save' );
// $btnSave->setParam( 'name', $fileName );
$btnSave->setValue( M('action/edit/save') );
$buttons->addChild( $btnSave );
$buttons->wrapBy( new hcHtmlElement('<DIV>') );
// FILL IN FORM
$form->addChild( $fileControlsGroup );
$form->addChild( $fileContentControl );
$form->addChild( $buttons );
// FILL CONTAINER
$viewContainer = new hcViewContainer( $this->getTemplatesDir() . '/FileEdit/fileEdit.tpl' );
$this->prefillViewContainer( $viewContainer );
// NOW TOP LEVEL ACTIONS
$tlActions = '';
$tlActionsArray = $viewData['topLevelActions'];
if( $tlActionsArray )
$tlActions =& $this->buildTopLevelActions( $tlActionsArray );
// HOST INFO
$hostInfo = $viewData['user'] . '@' . $viewData['host'];
$viewContainer->addChild( $form, 'FILEEDIT_FORM' );
$viewContainer->addChild( $path, 'PATH' );
$viewContainer->addChild( $tlActions, 'TOP_LEVEL_ACTIONS' );
$viewContainer->addChild( $hostInfo, 'HOST_INFO' );
echo parent::view( $viewContainer->view() );
}
function &buildTopLevelActions( $tlActions ){
$resp = cloneObject( $this->_resp );
$resp->resetStateParams( array( 'skip' => array('sid') ) );
$actions = new hcActionControlGroup();
foreach( $tlActions as $tlActionInfo ){
$a = new hcActionControl_Link( $this->_resp );
$url = $resp->generateUrl(
$tlActionInfo['actions'],
array(),
$tlActionInfo['handler']
);
$a->forceURL( $url );
$a->setValue( $tlActionInfo['title'] );
$actions->addChild( $a );
}
return $actions;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/mwfView_FileList.php : 1
<?
include_once( 'mwfView.php' );
include_once( 'objectViews/mwfView_FilePager.php' );
include_once( 'objectViews/mwfView_FileSorter.php' );
include_once( 'actionForms/mwActionForm_Rename.php' );
include_once( 'actionForms/mwActionForm_MoveTo.php' );
include_once( 'actionForms/mwActionForm_Chmod.php' );
include_once( 'actionForms/mwActionForm_CopyTo.php' );
include_once( 'actionForms/mwActionForm_MultiCopyTo.php' );
include_once( 'actionForms/mwActionForm_Delete.php' );
include_once( 'actionForms/mwActionForm_Upload.php' );
include_once( 'actionForms/mwActionForm_ZipUpload.php' );
include_once( 'actionForms/mwActionForm_Transload.php' );
include_once( 'actionForms/mwActionForm_Ftpload.php' );
include_once( 'actionForms/mwActionForm_NewDir.php' );
include_once( 'actionForms/mwActionForm_NewFile.php' );
include_once( 'actionForms/mwActionForm_DirectDir.php' );
include_once( 'actionForms/mwActionForm_NoteSelectItems.php' );
include_once( 'actionForms/mwActionForm_Email.php' );
include_once( 'actionForms/mwActionForm_Download.php' );
include_once( 'controls/mwfActionControl_FileModeSelector.php' );
class mwfView_FileList extends mwfView {
var $_actionFormsIDs;
/*
* The data for this view is an array of data. The keys are: fileList, currentDir:
* fileList - an array of files info
* currentDir - current directory
* filter - currently applied filename filter
*/
function view(){
$settingsManager =& mwfSettingsManager::getInstance();
$this->_actionFormsIDs = array();
/*
* get ref to viewData
*/
$viewData =& $this->getData();
$files =& $viewData['fileList'];
$currentDir = $viewData['currentDir'];
$filter = $viewData['filter'];
$allowedActions =& $viewData['allowedActions'];
$fileExtensions =& $viewData['fileExtensions'];
/*
* init
*/
// FileSorter
$fileSorter = new mwfFileSorter;
$fileSorter->init( $this->_req, $this->_resp );
// FilePager
$filePager = new mwfFilePager;
$filePager->setCount( count($files) );
if( defined('SETTING_DEFAULT_PAGE_SIZE') ){
$defaultPagesize = $settingsManager->get( SETTING_DEFAULT_PAGE_SIZE );
$filePager->setPagesize( $defaultPagesize );
}
$filePager->init( $this->_req, $this->_resp );
/*
* apply sorter and pager
*/
$fileSorter->processArrays( $files );
$filePager->process( $files );
$filePagerView = new mwfView_FilePager( $this->_req, $this->_resp );
$pagerViewData = array();
$pagerViewData['pages'] =& $filePager->getPages();
$pagerViewData['currentPage'] = $filePager->getPage();
$pagerViewData['paramName'] = $filePager->getParamName();
$pagerViewData['pagesizeParamName'] = $filePager->getPagesizeParamName();
$pagerViewData['pagesizeOptions'] = $filePager->getPagesizeOptions();
$pagerViewData['currentPagesize'] = $filePager->getPagesize();
$filePagerView->setData( $pagerViewData );
$fileSorterView = new mwfView_FileSorter( $this->_req, $this->_resp );
$sorterViewData = array();
$sorterViewData['sortings'] =& $fileSorter->getSortings();
$sorterViewData['paramName'] = $fileSorter->getParamName();
$fileSorterView->setData( $sorterViewData );
/*
* init path
*/
$path = new mwfPath;
$path->init( $this->_req, $this->_resp );
$path->initPath( $currentDir );
/*
* GLOBAL ACTIONS
*/
$gActions = array();
$commonInputFields = array();
/********************/
/* SELECT ITEMS NOTE */
/********************/
// FORM
$selectItemsNote = new mwActionForm_NoteSelectItems( $this->_req, $this->_resp );
$selectItemsNoteID = $selectItemsNote->getID();
$this->_actionFormsIDs['selectItemsNote'] = array( $selectItemsNoteID );
$commonInputFields[] =& $selectItemsNote;
/********************/
/* DIRECT DIR ENTRY */
/********************/
$thisActionHandle = 'chdir';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$directdirForm = new mwActionForm_DirectDir( $this->_req, $this->_resp );
$thisFormID = $directdirForm->getID();
$directdirForm->setCurrentDir( $currentDir );
$commonInputFields[] =& $directdirForm;
// BUTTON
$btnDirectDirGo = new hcActionControl_Button( $this->_resp );
$btnDirectDirGo->setHandle( $thisActionHandle );
$btnDirectDirGo->setValue( M('action/goto') );
$onClickString = "shaf( \"$thisFormID\", null, null );";
$btnDirectDirGo->setOnclick( $onClickString );
$gActions[] =& $btnDirectDirGo;
}
/********************/
/* NEW DIRECTORY */
/********************/
$thisActionHandle = 'newdir';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$newdirForm = new mwActionForm_NewDir( $this->_req, $this->_resp );
$thisFormID = $newdirForm->getID();
$commonInputFields[] =& $newdirForm;
// BUTTON
$btnNewDir = new hcActionControl_Button( $this->_resp, 0 );
$btnNewDir->setHandle( $thisActionHandle );
$btnNewDir->setValue( M('action/newDir') );
$onClickString = "shaf( \"$thisFormID\", null, null );";
$btnNewDir->setOnclick( $onClickString );
$gActions[] =& $btnNewDir;
}
/********************/
/* NEW FILE */
/********************/
$thisActionHandle = 'newfile';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$newfileForm = new mwActionForm_NewFile( $this->_req, $this->_resp );
$thisFormID = $newfileForm->getID();
$commonInputFields[] =& $newfileForm;
// BUTTON
$btnNewFile = new hcActionControl_Button( $this->_resp, 0 );
$btnNewFile->setHandle( $thisActionHandle );
$btnNewFile->setValue( M('action/newFile') );
$onClickString = "shaf( \"$thisFormID\", null, null );";
$btnNewFile->setOnclick( $onClickString );
$gActions[] =& $btnNewFile;
}
/********************/
/* UPLOAD */
/********************/
$thisActionHandle = 'upload';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$uploadForm = new mwActionForm_Upload( $this->_req, $this->_resp );
$thisFormID = $uploadForm->getID();
$commonInputFields[] =& $uploadForm;
// BUTTON
$btnUploadCommon = new hcActionControl_Button( $this->_resp, 0 );
$btnUploadCommon->setHandle( $thisActionHandle );
$btnUploadCommon->setValue( M('action/upload') );
$onClickString = "shaf( \"$thisFormID\", null, null );";
$btnUploadCommon->setOnclick( $onClickString );
$gActions[] =& $btnUploadCommon;
}
/********************/
/* ZIP UPLOAD */
/********************/
$thisActionHandle = 'zip_upload';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$zipUploadForm = new mwActionForm_ZipUpload( $this->_req, $this->_resp );
$thisFormID = $zipUploadForm->getID();
$commonInputFields[] =& $zipUploadForm;
// BUTTON
$btnZipUploadCommon = new hcActionControl_Button( $this->_resp, 0 );
$btnZipUploadCommon->setHandle( $thisActionHandle );
$btnZipUploadCommon->setValue( M('action/unzipUpload') );
$onClickString = "shaf( \"$thisFormID\", null, null );";
$btnZipUploadCommon->setOnclick( $onClickString );
$gActions[] =& $btnZipUploadCommon;
}
/********************/
/* TRANSLOAD */
/********************/
$thisActionHandle = 'transload';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$transloadForm = new mwActionForm_Transload( $this->_req, $this->_resp );
$thisFormID = $transloadForm->getID();
$commonInputFields[] =& $transloadForm;
// BUTTON
$btnTransloadCommon = new hcActionControl_Button( $this->_resp, 0 );
$btnTransloadCommon->setHandle( $thisActionHandle );
$btnTransloadCommon->setValue( M('action/transload') );
$onClickString = "shaf( \"$thisFormID\", null, null );";
$btnTransloadCommon->setOnclick( $onClickString );
$gActions[] =& $btnTransloadCommon;
}
/********************/
/* FTPLOAD */
/********************/
$thisActionHandle = 'ftpload';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$ftploadForm = new mwActionForm_Ftpload( $this->_req, $this->_resp );
$thisFormID = $ftploadForm->getID();
$commonInputFields[] =& $ftploadForm;
// BUTTON
$btnFtploadCommon = new hcActionControl_Button( $this->_resp, 0 );
$btnFtploadCommon->setHandle( $thisActionHandle );
$btnFtploadCommon->setValue( M('action/ftpLoad') );
$onClickString = "shaf( \"$thisFormID\", null, null );";
$btnFtploadCommon->setOnclick( $onClickString );
$gActions[] =& $btnFtploadCommon;
}
/********************/
/* EMAIL */
/********************/
$thisActionHandle = 'email';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$emailForm = new mwActionForm_Email( $this->_req, $this->_resp );
$thisFormID = $emailForm->getID();
$selectedFilesID = $emailForm->getSelectedFilesID();
$this->_actionFormsIDs[$thisActionHandle] = array( $thisFormID, $selectedFilesID );
$commonInputFields[] =& $emailForm;
// BUTTON
$btnEmailCommon = new hcActionControl_Button( $this->_resp, 0 );
$btnEmailCommon->setHandle( $thisActionHandle );
$btnEmailCommon->setValue( M('action/email') );
$onClickString = "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" );";
$btnEmailCommon->setOnclick( $onClickString );
$gActions[] =& $btnEmailCommon;
}
/********************/
/* CHMOD */
/********************/
$thisActionHandle = 'chmod';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$chmodForm = new mwActionForm_Chmod( $this->_req, $this->_resp );
$thisFormID = $chmodForm->getID();
$selectedFilesID = $chmodForm->getSelectedFilesID();
$this->_actionFormsIDs[$thisActionHandle] = array( $thisFormID, $selectedFilesID );
$commonInputFields[] =& $chmodForm;
// BUTTON
$btnChmodCommon = new hcActionControl_Button( $this->_resp, 0 );
$btnChmodCommon->setHandle( $thisActionHandle );
$btnChmodCommon->setValue( M('action/chmod') );
$onClickString = "return ";
$onClickString .= "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" ) && ";
$onClickString .= "fillMyMode( \"$thisFormID\" );";
$btnChmodCommon->setOnclick( $onClickString );
$gActions[] =& $btnChmodCommon;
}
/********************/
/* DELETE */
/********************/
$thisActionHandle = 'delete';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$deleteForm = new mwActionForm_Delete( $this->_req, $this->_resp );
$thisFormID = $deleteForm->getID();
$selectedFilesID = $deleteForm->getSelectedFilesID();
$this->_actionFormsIDs[$thisActionHandle] = array( $thisFormID, $selectedFilesID );
$commonInputFields[] =& $deleteForm;
// BUTTON
$btnDeleteCommon = new hcActionControl_Button( $this->_resp, 0 );
$btnDeleteCommon->setHandle( $thisActionHandle );
$btnDeleteCommon->setValue( M('action/delete') );
$onClickString = "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" );";
$btnDeleteCommon->setOnclick( $onClickString );
$gActions[] =& $btnDeleteCommon;
}
/********************/
/* MOVE TO */
/********************/
$thisActionHandle = 'move';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$moveToForm = new mwActionForm_MoveTo( $this->_req, $this->_resp );
$thisFormID = $moveToForm->getID();
$moveToForm->setCurrentDir( $currentDir );
$selectedFilesID = $moveToForm->getSelectedFilesID();
$this->_actionFormsIDs[$thisActionHandle] = array( $thisFormID, $selectedFilesID );
$commonInputFields[] =& $moveToForm;
// BUTTON
$btnMoveCommon = new hcActionControl_Button( $this->_resp, 0 );
$btnMoveCommon->setHandle( $thisActionHandle );
$btnMoveCommon->setValue( M('action/move') );
$onClickString = "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" );";
$btnMoveCommon->setOnclick( $onClickString );
$gActions[] =& $btnMoveCommon;
}
/********************/
/* MULTI COPY TO */
/********************/
$thisActionHandle = 'multi_copy';
if( in_array( 'copy', $allowedActions ) ){
// FORM
$multiCopyToForm = new mwActionForm_MultiCopyTo( $this->_req, $this->_resp );
$thisFormID = $multiCopyToForm->getID();
$multiCopyToForm->setCurrentDir( $currentDir );
$selectedFilesID = $multiCopyToForm->getSelectedFilesID();
$commonInputFields[] =& $multiCopyToForm;
// BUTTON
$btnMultiCopyCommon = new hcActionControl_Button( $this->_resp, 0 );
$btnMultiCopyCommon->setHandle( $thisActionHandle );
$btnMultiCopyCommon->setValue( M('action/copy') );
$onClickString = "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" );";
$btnMultiCopyCommon->setOnclick( $onClickString );
$gActions[] =& $btnMultiCopyCommon;
}
/********************/
/* COPY TO */
/********************/
$thisActionHandle = 'copy';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$copyToForm = new mwActionForm_CopyTo( $this->_req, $this->_resp );
$copyToForm->setCurrentDir( $currentDir );
$thisFormID = $copyToForm->getID();
$selectedFilesID = $copyToForm->getSelectedFilesID();
$this->_actionFormsIDs[$thisActionHandle] = array( $thisFormID, $selectedFilesID );
$commonInputFields[] =& $copyToForm;
}
/********************/
/* DOWNLOAD */
/********************/
$thisActionHandle = 'download';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$downloadForm = new mwActionForm_Download( $this->_req, $this->_resp );
$thisFormID = $downloadForm->getID();
$selectedFilesID = $downloadForm->getSelectedFilesID();
$commonInputFields[] =& $downloadForm;
// BUTTON
$btnDownload = new hcActionControl_Button( $this->_resp, 0 );
$btnDownload->setParam( 'op', $thisActionHandle );
$btnDownload->setValue( M('action/download') );
$onClickString = "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" );";
$btnDownload->setOnclick( $onClickString );
$gActions[] =& $btnDownload;
}
/********************/
/* RENAME */
/********************/
$thisActionHandle = 'rename';
if( in_array( $thisActionHandle, $allowedActions ) ){
// FORM
$renameForm = new mwActionForm_Rename( $this->_req, $this->_resp );
$thisFormID = $renameForm->getID();
$selectedFilesID = $renameForm->getSelectedFilesID();
$this->_actionFormsIDs[$thisActionHandle] = array( $thisFormID, $selectedFilesID );
$commonInputFields[] =& $renameForm;
/*
// BUTTON
$btnRename = new hcActionControl_Button( $this->_resp, 0 );
$btnRename->setHandle( $thisActionHandle );
$btnRename->setValue( 'Rename' );
$onClickString = "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" );";
$btnRename->setOnclick( $onClickString );
$gActions[] =& $btnRename;
*/
}
/********************/
/* FILTER */
/********************/
$fileFilter = new hcActionForm( $this->_resp );
$fileFilterOptions = new hcActionControlSet();
$fileFilterOptions->setLegend( M('fileFilter/header') );
// FIELD
$ctlFilterValue = new hcActionControl_Text( $this->_resp );
$ctlFilterValue->forceHTMLName( CHNDL_FILTER_VALUE_NAME );
$ctlFilterValue->setValue( $filter );
$ctlFilterValue->setSize( 20 );
// BUTTONS
$btnFilter = new hcActionControl_Submit( $this->_resp );
$btnFilter->setParam( 'op', 'applyfilter' );
$btnFilter->setValue( M('form/apply') );
$btnResetFilter = new hcActionControl_Submit( $this->_resp );
$btnResetFilter->setParam( 'op', 'resetfilter' );
$btnResetFilter->setValue( M('form/reset') );
$fileFilterOptions->addChild( $ctlFilterValue );
$fileFilterOptions->addChild( $btnFilter );
if( $filter )
$fileFilterOptions->addChild( $btnResetFilter );
$fileFilter->addChild( $fileFilterOptions );
/********************/
/* TOP LEVEL ACTIONS */
/********************/
$tlActions = '';
$tlActionsArray = $viewData['topLevelActions'];
if( $tlActionsArray )
$tlActions =& $this->buildTopLevelActions( $tlActionsArray );
// HOST INFO
$hostInfo = $viewData['user'] . '@' . $viewData['host'];
/*
* FILE LISTING
*/
$fileInListContainer = new hcViewContainer( $this->getTemplatesDir() . '/FileList/fileInList.tpl' );
$dirInListContainer = new hcViewContainer( $this->getTemplatesDir() . '/FileList/dirInList.tpl' );
$listing = '';
$selectActions = array();
foreach( $files as $f ){
global $actionId;
$actionId = 0;
if( ($f['type'] == 'dir') || ($f['type'] == 'link') ){
$listingElementContainer =& $dirInListContainer;
$this->fillDirContainer( $listingElementContainer, $f, $allowedActions, $selectActions );
}
else {
$listingElementContainer =& $fileInListContainer;
$this->fillFileContainer( $listingElementContainer, $f, $allowedActions, $selectActions, $fileExtensions );
}
$listing .= $listingElementContainer->view();
$listingElementContainer->clearChildren();
}
// NOW FILL THE CONTAINER
$listTemplateContainer = new hcViewContainer( $this->getTemplatesDir() . '/FileList/fileList.tpl' );
$this->prefillViewContainer( $listTemplateContainer );
$listTemplateContainer->addChild( $listing, 'FILE_LISTING' );
$listTemplateContainer->addChild( $fileSorterView, 'FILE_SORTER' );
$listTemplateContainer->addChild( $filePagerView, 'FILE_PAGER' );
$listTemplateContainer->addChild( $path, 'PATH' );
$listTemplateContainer->addChild( $fileFilter, 'FILE_FILTER' );
$listTemplateContainer->addChild( $gActions, 'ACTIONS' );
$listTemplateContainer->addChild( $commonInputFields, 'INPUT_FIELDS' );
$listTemplateContainer->addChild( $tlActions, 'TOP_LEVEL_ACTIONS' );
$listTemplateContainer->addChild( $hostInfo, 'HOST_INFO' );
// ADD SOME JAVASCRIPT STUFF
$listTemplateContainer->addChild( HTML_DIV_ACTION_WRAPPER, 'HTML_DIV_ACTION_WRAPPER' );
$listTemplateContainer->addChild( HTML_DIV_ACTION_CALL_BUTTON, 'HTML_DIV_ACTION_CALL_BUTTON' );
$listTemplateContainer->addChild( HTML_MAX_FILE_FIELDS, 'HTML_MAX_FILE_FIELDS' );
$listTemplateContainer->addChild( CHNDL_FILE_NAME, 'CHNDL_FILE_NAME' );
// PREPARE THE SELECT LIST ACTIONS OPTION
$shown = array();
$selectActionsArrayCode = '';
reset( $selectActions );
foreach( $selectActions as $actionId => $aInfo){
list( $actionTitle, $actionCodeTemplate, $actOnDir ) = $aInfo;
$selectActionsArrayCode .= 'fileActions[' . $actionId . '] = new Array("' . $actionTitle . '", "' . addslashes($actionCodeTemplate) . "\", $actOnDir);\n";
}
$selectActionsArrayCode = "fileActions = new Array();\n" . $selectActionsArrayCode;
$listTemplateContainer->addChild( $selectActionsArrayCode, 'SELECT_ACTIONS' );
// SELECTED FILE TEMPLATE
// WRAPPER
$ctlGroup = new hcActionControlSet();
$ctlGroup->setLegend( M('form/selectedItems') );
$t = '{FILES}';
$ctlGroup->addChild( $t );
$selectedFilesContainer = $ctlGroup->view();
// FILE
$checkbox = new hcActionControl_Checkbox( $this->_resp );
$checkbox->forceHTMLName( CHNDL_FILE_NAME . '[]' );
$checkbox->setValue( '{FILE_NAME}' );
$checkbox->set();
$checkbox->setLabel( '{FILE_NAME}', 1 ); // second argument to put on right
$checkbox->wrapBy( new hcHtmlElement('<DIV>') );
$selectedFileTemplate = $checkbox->view();
$listTemplateContainer->addChild( addslashes($selectedFilesContainer), 'SELECTED_FILES_CONTAINER_TEMPLATE' );
$listTemplateContainer->addChild( addslashes($selectedFileTemplate), 'SELECTED_FILE_TEMPLATE' );
/*
* view
*/
echo parent::view( $listTemplateContainer->view() );
}
function &buildTopLevelActions( $tlActions ){
$resp = cloneObject( $this->_resp );
$resp->resetStateParams( array( 'skip' => array('sid') ) );
$actions = new hcActionControlGroup();
foreach( $tlActions as $tlActionInfo ){
$a = new hcActionControl_Link( $this->_resp );
$url = $resp->generateUrl(
$tlActionInfo['actions'],
array(),
$tlActionInfo['handler']
);
$a->forceURL( $url );
$a->setValue( $tlActionInfo['title'] );
$actions->addChild( $a );
}
return $actions;
}
function fillFileContainer( &$viewContainer, &$fileInfo, &$allowedActions, &$selectActions, $fileExtensions = array() ){
global $actionId;
$fileName = $fileInfo['name'];
preg_match("/\.(.{2,4})$/", $fileName, $matches);
$fileExtension = ($matches) ? $matches[0] : '';
$fileID = getUniqueID();
$fileInfo['id'] = $fileID;
// PREFILL COMMON FIELDS
$this->commonFieldsFill( $viewContainer, $fileInfo );
/*
* ADD ACTIONS
*/
$fileActions = array();
list( $selectItemsNoteID ) = $this->_actionFormsIDs['selectItemsNote'];
// PREFILL COMMON ACTIONS
$this->commonActionsFill( $fileActions, $fileInfo, $allowedActions, $selectActions );
$fileNameControl = 'this.form.' . CHNDL_FILE_NAME;
$fileNameValue = 'this.form.' . CHNDL_FILE_NAME . '.value';
// COPY TO
$thisActionHandle = 'copy';
if( in_array( $thisActionHandle, $allowedActions ) ){
$actionTitle = M('action/copy');
list( $thisFormID, $selectedFilesID ) = $this->_actionFormsIDs[$thisActionHandle];
// CHNDL_COPYTO_NEW_FILE_NAME
$onClickString = "safc(false) && sfc( $fileNameControl, true ) && ";
$onClickString .= "scv( document.forms[\"" . $thisFormID . "\"]." . CHNDL_COPYTO_NEW_FILE_NAME . ", $fileNameValue ) && ";
$onClickString .= "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" );";
$actionId++;
if( ! isset($selectActions[$actionId]) )
$selectActions[$actionId] = array( $actionTitle, $onClickString, 0 );
}
// FILE SCPECIFIC ACTIONS
// EDIT
$thisActionHandle = 'edit';
if( in_array($thisActionHandle, $allowedActions) ){
$actionTitle = M('action/edit');
if( isset($fileExtensions[$thisActionHandle]) ){
// ALLOWED TO EDIT THIS
if( inArrayWithWildcards($fileExtension, $fileExtensions[$thisActionHandle]) ){
$fileLink = new hcActionControl_Link( $this->_resp );
$fileLink->setParam( 'op', $thisActionHandle );
$fileLink->setParam( CHNDL_FILE_NAME, $fileName );
$fileLink->setTitle( $actionTitle );
$fileLink->setValue( $fileName );
}
}
$url = $this->_resp->generateUrl(
array(
'op' => $thisActionHandle,
CHNDL_FILE_NAME => '_selectedFileName_',
)
);
$onClickString = 'document.location.href="' . $url . '"';
$actionId++;
if( ! isset($selectActions[$actionId]) )
$selectActions[$actionId] = array( $actionTitle, $onClickString, 0 );
}
// VIEW
$thisActionHandle = 'view';
if( in_array('edit', $allowedActions) || in_array('view', $allowedActions) ){
$actionTitle = M('action/view');
if( isset($fileExtensions[$thisActionHandle]) ){
// ALLOWED TO VIEW THIS
// if( in_array($fileExtension, $fileExtensions[$thisActionHandle]) ){
if( inArrayWithWildcards($fileExtension, $fileExtensions[$thisActionHandle]) ){
$fileLink = new hcActionControl_Link( $this->_resp );
$fileLink->setParam( 'op', $thisActionHandle );
$fileLink->setParam( CHNDL_FILE_NAME, $fileName );
$fileLink->setTitle( $actionTitle );
$fileLink->setValue( $fileName );
$fileLink->setTarget( '_blank' );
}
}
$url = $this->_resp->generateUrl(
array(
'op' => $thisActionHandle,
CHNDL_FILE_NAME => '_selectedFileName_',
)
);
$onClickString = 'document.location.href="' . $url . '"';
$actionId++;
if( ! isset($selectActions[$actionId]) )
$selectActions[$actionId] = array( $actionTitle, $onClickString, 0 );
}
if( ! isset($fileLink) )
$fileLink = $fileName;
// SELECT ACTION LIST
$fillForSelect = array(
"0" => M('action/selectAction'),
);
foreach( $selectActions as $actionId => $aInfo){
list( $actionTitle, $actionCodeTemplate ) = $aInfo;
// $fillForSelect[ "$actionId" ] = $actionTitle;
}
$onChange = "eval( fileActionCode(this.value, $fileNameValue) )";
/*
$select = new hcActionControl_Select( $this->_resp );
$select->fill( $fillForSelect );
$select->setClasses( array('0' => 'header') );
$select->setOnChange( $onChange );
$select->setOnMouseOver( $onClick );
$fileActions[] =& $select;
*/
$selectCode = '<SELECT onChange="' . $onChange . '"><OPTION VALUE="0" CLASS="header">' . M('action/selectAction') . '</OPTION><SCRIPT LANGUAGE="JavaScript">printFileActionOptions(0);</SCRIPT></SELECT>';
$fileActions[] = $selectCode;
$viewContainer->addChild( $fileLink, 'FILE_LINK' );
$viewContainer->addChild( $fileActions, 'FILE_ACTIONS' );
}
function fillDirContainer( &$viewContainer, &$dirInfo, &$allowedActions, &$selectActions ){
$dirName = $dirInfo['name'];
$goToName = ( isset($dirInfo['goto']) ) ? $dirInfo['goto'] : $dirName;
$fileID = getUniqueID();
$dirInfo['id'] = $fileID;
$viewData =& $this->getData();
$currentDir = $viewData['currentDir'];
if( $currentDir )
$dirPath = $currentDir . '/' . $goToName;
else
$dirPath = $goToName;
// $dirInfo['type'] = '';
$dirInfo['size'] = '';
// PREFILL COMMON FIELDS
$this->commonFieldsFill( $viewContainer, $dirInfo );
$fileNameControl = 'this.form.' . CHNDL_FILE_NAME;
$fileNameValue = 'this.form.' . CHNDL_FILE_NAME . '.value';
$dirLink = new hcActionControl_Link( $this->_resp );
$dirLink->setParam( 'op', 'chdir' );
$dirLink->setParam( CHNDL_DIR_NAME, $dirPath );
$dirLink->setValue( $dirName );
$dirLink->wrapBy( new hcHtmlElement('<STRONG>') );
$viewContainer->addChild( $dirLink, 'DIR_LINK' );
/*
* ADD ACTIONS
*/
$dirActions = array();
$onChange = "eval( fileActionCode(this.value, $fileNameValue) )";
$selectCode = '<SELECT onChange="' . $onChange . '"><OPTION VALUE="0" CLASS="header">' . M('action/selectAction') . '</OPTION><SCRIPT LANGUAGE="JavaScript">printFileActionOptions(1);</SCRIPT></SELECT>';
$dirActions[] = $selectCode;
// PREFILL COMMON ACTIONS
$this->commonActionsFill( $dirActions, $dirInfo, $allowedActions, $selectActions );
$viewContainer->addChild( $dirActions, 'DIR_ACTIONS' );
}
function commonFieldsFill( &$viewContainer, &$fileInfo ){
$formattedDate = formatDateTime( $fileInfo['date'] );
$formattedSize = formatSize( $fileInfo['size'] );
$formattedMode = formatMode( $fileInfo['mode'] );
$viewContainer->addChild( $fileInfo['name'], 'NAME' );
$viewContainer->addChild( $fileInfo['id'], 'FILE_ID' );
$viewContainer->addChild( $formattedMode, 'MODE' );
$viewContainer->addChild( $fileInfo['type'], 'TYPE' );
$viewContainer->addChild( $fileInfo['owner'], 'OWNER' );
$viewContainer->addChild( $fileInfo['group'], 'GROUP' );
$viewContainer->addChild( $formattedSize, 'SIZE' );
$viewContainer->addChild( $formattedDate, 'DATE' );
$viewContainer->addChild( CHNDL_FILE_NAME, 'CHNDL_FILE_NAME' );
}
function commonActionsFill( &$actions, &$fileInfo, &$globallyAllowedActions, &$selectActions ){
global $actionId;
$allowedActions = array();
// $perFileActions = array( 'delete', 'rename', 'move', 'copy', 'chmod', 'email', 'download' );
$perFileActions = array( 'download', 'rename', 'delete', 'move', 'copy', 'chmod', 'email' );
reset( $globallyAllowedActions );
foreach( $globallyAllowedActions as $a ){
if( in_array($a, $perFileActions) )
$allowedActions[] = $a;
}
$viewData =& $this->getData();
$currentDir = $viewData['currentDir'];
$fileName = $fileInfo['name'];
$fileID = $fileInfo['id'];
$fileMode = $fileInfo['mode'];
list( $selectItemsNoteID ) = $this->_actionFormsIDs['selectItemsNote'];
$fileNameControl = 'this.form.' . CHNDL_FILE_NAME;
$fileNameValue = 'this.form.' . CHNDL_FILE_NAME . '.value';
// DELETE
$thisActionHandle = 'delete';
if( in_array( $thisActionHandle, $allowedActions ) ){
$actionTitle = M('action/delete');
list( $thisFormID, $selectedFilesID ) = $this->_actionFormsIDs[$thisActionHandle];
$onClickString = "safc(false) && sfc( $fileNameControl, true ) && ";
$onClickString .= "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" );";
$actionId++;
if( ! isset($selectActions[$actionId]) )
$selectActions[$actionId] = array( $actionTitle, $onClickString, 1 );
}
// RENAME
$thisActionHandle = 'rename';
if( in_array( $thisActionHandle, $allowedActions ) ){
$actionTitle = M('action/rename');
list( $thisFormID, $selectedFilesID ) = $this->_actionFormsIDs[$thisActionHandle];
$onClickString = "safc(false) && sfc( $fileNameControl, true ) && ";
$onClickString .= "scv( document.forms[\"" . $thisFormID . "\"]." . CHNDL_RENAME_NEW_NAME . ", $fileNameValue ) && ";
$onClickString .= "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" );";
$actionId++;
if( ! isset($selectActions[$actionId]) )
$selectActions[$actionId] = array( $actionTitle, $onClickString, 1 );
}
// MOVE TO
$thisActionHandle = 'move';
if( in_array( $thisActionHandle, $allowedActions ) ){
$actionTitle = M('action/move');
list( $thisFormID, $selectedFilesID ) = $this->_actionFormsIDs[$thisActionHandle];
$onClickString = "safc(false) && sfc( $fileNameControl, true ) && ";
$onClickString .= "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" );";
$actionId++;
if( ! isset($selectActions[$actionId]) )
$selectActions[$actionId] = array( $actionTitle, $onClickString, 1 );
}
// CHMOD
$thisActionHandle = 'chmod';
if( in_array( $thisActionHandle, $allowedActions ) ){
$actionTitle = M('action/chmod');
list( $thisFormID, $selectedFilesID ) = $this->_actionFormsIDs[$thisActionHandle];
$onClickString = "safc(false) && sfc( $fileNameControl, true ) && ";
$onClickString .= "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" ) && ";
$onClickString .= "fillMyMode( \"$thisFormID\" );";
$actionId++;
if( ! isset($selectActions[$actionId]) )
$selectActions[$actionId] = array( $actionTitle, $onClickString, 1 );
}
// EMAIL
$thisActionHandle = 'email';
if( in_array( $thisActionHandle, $allowedActions ) ){
$actionTitle = M('action/email');
list( $thisFormID, $selectedFilesID ) = $this->_actionFormsIDs[$thisActionHandle];
$onClickString = "safc(false) && sfc( $fileNameControl, true ) && ";
$onClickString .= "shaf( \"$thisFormID\", \"$selectedFilesID\", \"$selectItemsNoteID\" );";
$actionId++;
if( ! isset($selectActions[$actionId]) )
$selectActions[$actionId] = array( $actionTitle, $onClickString, 1 );
}
// DOWNLOAD
$thisActionHandle = 'download';
if( in_array( $thisActionHandle, $allowedActions ) ){
$actionTitle = M('action/download');
$url = $this->_resp->generateUrl(
array(
'op' => $thisActionHandle,
CHNDL_FILE_NAME => '_selectedFileName_',
)
);
$onClickString = 'document.location.href="' . $url . '"';
$actionId++;
if( ! isset($selectActions[$actionId]) )
$selectActions[$actionId] = array( $actionTitle, $onClickString, 1 );
}
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/mwfView_FileView.php : 1
<?
include_once( 'mwfView.php' );
class mwfView_FileView extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
* fileContent - the file content
* currentDir - current directory
*/
function view(){
$viewData =& $this->getData();
$fileName = $viewData['fileName'];
$fileContent = $viewData['fileContent'];
preg_match( "/\.(\w+)$/", $fileName, $matches );
$fileExtension = $matches[ 1 ];
switch( $fileExtension ){
case 'doc':
$contentType = 'application/msword';
header("Content-Disposition: attachment; filename=\"$fileName\"");
break;
case 'xls':
$contentType = 'application/ms-excel';
header("Content-Disposition: attachment; filename=\"$fileName\"");
break;
case 'pdf':
$contentType = 'application/pdf';
header("Content-Disposition: attachment; filename=\"$fileName\"");
break;
case 'ppt':
$contentType = 'application/ms-powerpoint';
header("Content-Disposition: attachment; filename=\"$fileName\"");
break;
default:
$contentType = 'image/' . $fileExtension;
}
@ob_end_clean();
header("Type: $contentType");
header('Content-type: ' . $contentType );
echo $fileContent;
exit;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/mwfView_SelectDir.php : 1
<?
include_once( 'mwfView.php' );
class mwfView_SelectDir extends mwfView {
/*
* The data for this view is an array of data. The keys are: fileList, currentDir:
* fileList - an array of files info
* currentDir - current directory
* targetControl - target control name - where to set the selected directory name
*/
// function mwfView_SelectDir( &$args ){
// parent::mwfView( $args );
// }
function view(){
/*
* init
*/
// FileSorter
$fileSorter = new mwfFileSorter;
$fileSorter->init( $this->_req, $this->_resp );
/*
* prepare view
*/
$viewData =& $this->getData();
$files =& $viewData['fileList'];
$currentDir = $viewData['currentDir'];
$targetControlName = $viewData['targetControl'];
$targetControl = 'window.opener.document.' . $targetControlName;
$form = new hcActionForm( $this->_resp );
$form->setAction( APP_ROOT_PAGE );
$form->enablePersistence( 0 );
/*
* init path
*/
$path = new mwfPath;
$path->init( $this->_req, $this->_resp );
$path->initPath( $currentDir );
/*
* apply sorter and pager
*/
$fileSorter->processArrays( $files );
$listTemplateContainer = new hcViewContainer( $this->getTemplatesDir() . '/SelectDir/fileList.tpl' );
$this->prefillViewContainer( $listTemplateContainer );
$fileInListContainer = new hcViewContainer( $this->getTemplatesDir() . '/SelectDir/fileInList.tpl' );
$dirInListContainer = new hcViewContainer( $this->getTemplatesDir() . '/SelectDir/dirInList.tpl' );
$dirListingCode = '';
$fileListingCode = '';
foreach( $files as $f ){
if( $f['type'] == 'dir' ){
$listingElementContainer =& $dirInListContainer;
$this->fillDirContainer( $listingElementContainer, $f );
$dirListingCode .= $listingElementContainer->view();
}
else {
$listingElementContainer =& $fileInListContainer;
$this->fillFileContainer( $listingElementContainer, $f );
$fileListingCode .= $listingElementContainer->view();
}
$listingElementContainer->clearChildren();
}
if( $dirListingCode ){
$dirListingHeader = new hcActionControl_Label( $this->_resp );
$dirListingHeader->setValue( M('common/dirs') );
$dirListingHeader->wrapBy( new hcHtmlElement('<H4>') );
$dirListing = new hcActionControlGroup();
$dirListing->addChild( $dirListingHeader );
$dirListing->addChild( $dirListingCode );
}
else {
$dirListing = '';
}
if( $fileListingCode ){
$fileListingHeader = new hcActionControl_Label( $this->_resp );
$fileListingHeader->setValue( M('common/files') );
$fileListingHeader->wrapBy( new hcHtmlElement('<H4>') );
$fileListing = new hcActionControlGroup();
$fileListing->addChild( $fileListingHeader );
$fileListing->addChild( $fileListingCode );
}
else {
$fileListing = '';
}
/*
* ADD GLOBAL ACTIONS
*/
// SELECTED DIR
$helpLabel = new hcActionControl_Label( $this->_resp );
$helpLabel->setValue( M('action/selectDir/help') );
$helpLabel->wrapBy( new hcHtmlElement('<STRONG>') );
$ctlSelectedDir = new hcActionControl_Hidden( $this->_resp );
$ctlSelectedDir->forceHTMLName( CHNDL_NEW_DIR_NAME );
// $ctlSelectedDir->setSize( 60 );
$ctlSelectedDir->setValue( $currentDir );
$buttons = new hcActionControlGroup();
$btnSelectedDirOK = new hcActionControl_Button( $this->_resp );
$btnSelectedDirOK->setValue( M('form/ok') );
$srcControlName = $ctlSelectedDir->getHTMLName();
$srcControl = 'this.form.' . $srcControlName;
$btnSelectedDirOK->setOnClick( "transferControlValue( $srcControl, $targetControl );" );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnClick( 'btnCancel_Click();' );
$buttons->addChild( $btnSelectedDirOK );
$buttons->addChild( $btnCancel );
$form->addChild( $ctlSelectedDir );
$form->addChild( $buttons );
// SO NOW ADD ACTIONS
$listTemplateContainer->addChild( $helpLabel, 'HELP_LABEL' );
$listTemplateContainer->addChild( $path, 'PATH' );
$listTemplateContainer->addChild( $fileListing, 'FILE_LISTING' );
$listTemplateContainer->addChild( $dirListing, 'DIR_LISTING' );
$listTemplateContainer->addChild( $form, 'ACTIONS' );
/*
* view
*/
echo parent::view( $listTemplateContainer->view() );
}
function fillFileContainer( &$viewContainer, &$fileInfo ){
$fileName = $fileInfo['name'];
$fileID = getUniqueID();
$fileInfo['id'] = $fileID;
// PREFILL COMMON FIELDS
$this->commonFieldsFill( $viewContainer, $fileInfo );
}
function fillDirContainer( &$viewContainer, &$dirInfo ){
$dirName = $dirInfo['name'];
$fileID = getUniqueID();
$dirInfo['id'] = $fileID;
$viewData =& $this->getData();
$currentDir = $viewData['currentDir'];
if( $currentDir )
$dirPath = $currentDir . '/' . $dirName;
else
$dirPath = $dirName;
$dirInfo['type'] = '';
$dirInfo['size'] = '';
// PREFILL COMMON FIELDS
$this->commonFieldsFill( $viewContainer, $dirInfo );
$dirLink = new hcActionControl_Link( $this->_resp );
$dirLink->setParam( 'op', 'chdir' );
$dirLink->setParam( CHNDL_DIR_NAME, $dirPath );
$dirLink->setValue( $dirName );
$dirLink->wrapBy( new hcHtmlElement('<STRONG>') );
$dirLinkView = $dirLink->view() . ' ';
$viewContainer->addChild( $dirLinkView, 'DIR_LINK' );
}
function commonFieldsFill( &$viewContainer, &$fileInfo ){
$viewContainer->addChild( $fileInfo['name'] . ' ', 'NAME' );
$viewContainer->addChild( $fileInfo['id'], 'FILE_ID' );
$viewContainer->addChild( $fileInfo['mode'], 'MODE' );
$viewContainer->addChild( $fileInfo['type'], 'TYPE' );
$viewContainer->addChild( $fileInfo['owner'], 'OWNER' );
$viewContainer->addChild( $fileInfo['group'], 'GROUP' );
$viewContainer->addChild( $fileInfo['size'], 'SIZE' );
$viewContainer->addChild( $fileInfo['date'], 'DATE' );
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm.php : 1
<?
class mwActionForm {
var $_req;
var $_resp;
var $_form;
var $_selectedFilesID;
var $_currentDir;
function mwActionForm( &$req, &$resp ){
$this->_req =& $req;
$this->_resp =& $resp;
$this->_form = new hcActionForm( $this->_resp );
$this->_form->setAction( APP_ROOT_PAGE );
$this->_selectedFilesID = 'sf_' . $this->_form->getID();
$this->setCurrentDir( null );
}
function setCurrentDir( $dir ){
$this->_currentDir = $dir;
}
function getCurrentDir(){
return $this->_currentDir;
}
function getID(){
return $this->_form->getID();
}
function getSelectedFilesID(){
return $this->_selectedFilesID;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_Chmod.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_Chmod extends mwActionForm {
function view(){
$inputFields = array();
$view = '';
$thisActionHandle = 'chmod';
$this->_form->setLegend( M('action/chmod') );
$selectedFiles = new hcHtmlElement( '<DIV>' );
$selectedFiles->setID( $this->_selectedFilesID );
// FIELDS
$modeGroup = new hcActionControlSet();
$modeGroup->setLegend( M('action/chmod') );
$ctlModeSelector = new mwfActionControl_FileModeSelector( $this->_resp );
$ctlModeSelector->forceHTMLName( CHNDL_CHMOD_NEW_MODE );
$modeGroup->addChild( $ctlModeSelector );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\", \"" . $this->_selectedFilesID . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $modeGroup );
$this->_form->addChild( $buttons );
$this->_form->addChild( $selectedFiles );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_CopyTo.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_CopyTo extends mwActionForm {
function view(){
$inputFields = array();
$view = '';
$thisActionHandle = 'copy';
$this->_form->setLegend( M('action/copy') );
$selectedFiles = new hcHtmlElement( '<DIV>' );
$selectedFiles->setID( $this->_selectedFilesID );
// FIELDS
$copyGroup = new hcActionControlSet();
$copyGroup->setLegend( M('form/destination') );
$groupCopyToDirName = new hcActionControlGroup();
$ctlCopyToDirName = new hcActionControl_Text( $this->_resp );
$ctlCopyToDirName->forceHTMLName( CHNDL_COPYTO_DIR_NAME );
// $ctlCopyToDirName->setLabel( 'Copy to' );
$ctlCopyToDirName->setSize( 80 );
$ctlCopyToDirName->setValue( $this->getCurrentDir() );
$btnSelectDir_CopyTo = new hcActionControl_Button( $this->_resp );
$btnSelectDir_CopyTo->setValue( M('form/selectDir') );
$dirSelectorWinURL = $this->_resp->generateURL(
array(),
array(
PARAM_VIEW_HANDLE => VIEW_HANDLE_SELECT_DIR,
PARAM_TARGET_CONTROL => $this->_form->getName() . '.' . $ctlCopyToDirName->getHTMLName(),
)
);
$btnSelectDir_CopyTo->setOnClick( "openWindow(\"$dirSelectorWinURL\");" );
$groupCopyToDirName->addChild( $ctlCopyToDirName );
$groupCopyToDirName->addChild( $btnSelectDir_CopyTo );
$groupCopyToDirName->wrapBy( new hcHtmlElement('<DIV>') );
$ctlCopyToNewName = new hcActionControl_Text( $this->_resp );
$ctlCopyToNewName->forceHTMLName( CHNDL_COPYTO_NEW_FILE_NAME );
$ctlCopyToNewName->setLabel( M('action/copy/newName') );
$ctlCopyToNewName->setSize( 30 );
$ctlCopyToNewName->wrapBy( new hcHtmlElement('<DIV>') );
$copyGroup->addChild( $ctlCopyToDirName );
$copyGroup->addChild( $btnSelectDir_CopyTo );
$copyGroup->addChild( $ctlCopyToNewName );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\", \"" . $this->_selectedFilesID . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $copyGroup );
$this->_form->addChild( $buttons );
$this->_form->addChild( $selectedFiles );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_Delete.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_Delete extends mwActionForm {
function view(){
$inputFields = array();
$view = '';
$thisActionHandle = 'delete';
$this->_form->setLegend( M('action/delete') );
$ctlDeleteLabel = new hcActionControl_Label( $this->_resp );
$ctlDeleteLabel->setValue( M('action/delete/confirmNote') );
$ctlDeleteLabel->wrapBy( new hcHtmlElement('<DIV>') );
$selectedFiles = new hcHtmlElement( '<DIV>' );
$selectedFiles->setID( $this->_selectedFilesID );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\", \"" . $this->_selectedFilesID . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $ctlDeleteLabel );
$this->_form->addChild( $buttons );
$this->_form->addChild( $selectedFiles );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_DirectDir.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_DirectDir extends mwActionForm {
function view(){
$thisActionHandle = 'chdir';
$this->_form->setLegend( M('action/goto') );
$namesGroup = new hcActionControlSet();
$namesGroup->setLegend( M('form/destination') );
// TARGET DIR NAME
$ctlDirectDirName = new hcActionControl_Text( $this->_resp );
$ctlDirectDirName->forceHTMLName( CHNDL_DIR_NAME );
$ctlDirectDirName->setSize( 80 );
// $ctlDirectDirName->setLabel( M('actionForm/goto/destinationDirectory') );
$ctlDirectDirName->setValue( $this->getCurrentDir() );
$btnSelectDir_DirectDir = new hcActionControl_Button( $this->_resp );
$btnSelectDir_DirectDir->setValue( M('form/selectDir') );
$dirSelectorWinURL = $this->_resp->generateURL(
array(),
array(
PARAM_VIEW_HANDLE => VIEW_HANDLE_SELECT_DIR,
PARAM_TARGET_CONTROL => $this->_form->getName() . '.' . $ctlDirectDirName->getHTMLName(),
)
);
$btnSelectDir_DirectDir->setOnClick( "openWindow(\"$dirSelectorWinURL\");" );
$namesGroup->addChild( $ctlDirectDirName );
$namesGroup->addChild( $btnSelectDir_DirectDir );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $namesGroup );
$this->_form->addChild( $buttons );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_Download.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_Download extends mwActionForm {
function view(){
$inputFields = array();
$view = '';
$thisActionHandle = 'download';
$this->_form->setLegend( M('action/download') );
if( defined('FREE_VERSION') && FREE_VERSION ){
$vreeVersionNotice = FREE_VERSION_NOTICE;
$this->_form->addChild( $vreeVersionNotice );
}
$selectedFiles = new hcHtmlElement( '<DIV>' );
$selectedFiles->setID( $this->_selectedFilesID );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\", \"" . $this->_selectedFilesID . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $ctlDeleteLabel );
$this->_form->addChild( $buttons );
$this->_form->addChild( $selectedFiles );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_Email.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_Email extends mwActionForm {
function view(){
$inputFields = array();
$view = '';
$thisActionHandle = 'email';
$this->_form->setLegend( M('action/email') );
$selectedFiles = new hcHtmlElement( '<DIV>' );
$selectedFiles->setID( $this->_selectedFilesID );
// FIELDS
$emailToGroup = new hcActionControlSet();
$emailToGroup->setLegend( M('action/email/to') );
$ctlEmailTo = new hcActionControl_Text( $this->_resp );
$ctlEmailTo->forceHTMLName( CHNDL_EMAIL_ADDRESS );
// $ctlEmailTo->setLabel( 'Email to' );
$ctlEmailTo->setSize( 40 );
$emailToGroup->addChild( $ctlEmailTo );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\", \"" . $this->_selectedFilesID . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $emailToGroup );
$this->_form->addChild( $buttons );
$this->_form->addChild( $selectedFiles );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_Ftpload.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_Ftpload extends mwActionForm {
function view(){
$settingsManager =& mwfSettingsManager::getInstance();
$uploadFieldsNum = HTML_MAX_FILE_FIELDS;
$thisActionHandle = 'ftpload';
$this->_form->setLegend( M('action/ftpLoad') );
$fileIntGroupHandle = HTML_DIV_ACTION_WRAPPER . CHNDL_FTPLOAD_FIELD;
// ADD FIELD BUTTON
$btnAddField = new hcActionControl_Button( $this->_resp );
$btnAddField->setValue( M('form/addField') . ' (max ' . HTML_MAX_FILE_FIELDS . ')' );
$btnAddField->setOnclick( "showNextFileField( \"$fileIntGroupHandle\" )" );
// FIELDS
// SRC FTP SERVER
$srcFtpGroup = new hcActionControlSet();
$srcFtpGroup->setLegend( M('action/ftpLoad/sourceFtpServerDetails') );
$ctlFtploadHost = new hcActionControl_Text( $this->_resp );
$ctlFtploadHost->forceHTMLName( CHNDL_FTPLOAD_SRC_HOST );
$ctlFtploadHost->setLabel( M('ftp/host') );
$ctlFtploadHost->setSize( 30 );
$ctlFtploadHost->wrapBy( new hcHtmlElement('<DIV>') );
$ctlFtploadUser = new hcActionControl_Text( $this->_resp );
$ctlFtploadUser->forceHTMLName( CHNDL_FTPLOAD_SRC_USER );
$ctlFtploadUser->setLabel( M('ftp/user') );
$ctlFtploadUser->wrapBy( new hcHtmlElement('<DIV>') );
$ctlFtploadPass = new hcActionControl_Password( $this->_resp );
$ctlFtploadPass->forceHTMLName( CHNDL_FTPLOAD_SRC_PASSWORD );
$ctlFtploadPass->setLabel( M('ftp/password') );
$ctlFtploadPass->wrapBy( new hcHtmlElement('<DIV>') );
$srcFtpGroup->addChild( $ctlFtploadHost );
$srcFtpGroup->addChild( $ctlFtploadUser );
$srcFtpGroup->addChild( $ctlFtploadPass );
// FILES
$filesGroup = new hcActionControlSet();
$filesGroup->setLegend( M('form/selectFiles') );
for( $j = 1; $j <= $uploadFieldsNum; $j++ ){
$internalGroup = new hcActionControlGroup();
$ctlFtploadField = new hcActionControl_Text( $this->_resp, $j );
$ctlFtploadField->setHandle( CHNDL_FTPLOAD_FIELD );
// $ctlFtploadField->setLabel( 'File path' );
$ctlFtploadField->setSize( 60 );
$ctlFtploadMode = new hcActionControl_Select( $this->_resp, $j );
if( defined('SETTING_DEFAULT_UPLOAD_MODE') )
$defaultUploadMode = $settingsManager->get( SETTING_DEFAULT_UPLOAD_MODE );
else
$defaultUploadMode = FILE_MODE_ASCII;
$ctlFtploadMode->fill( array(FILE_MODE_ASCII => 'ascii', FILE_MODE_BINARY => 'binary') );
$ctlFtploadMode->setHandle( CHNDL_TRANSLOAD_MODE );
$ctlFtploadMode->setValue( $defaultUploadMode );
$ctlFtploadMode->setLabel( M('form/transferMode') );
$internalGroup->addChild( $ctlFtploadMode );
$internalGroup->addChild( $ctlFtploadField );
$internalGroup->setWrappingDiv(
array(
'id' => $fileIntGroupHandle . $j,
'style' => ( $j > 1 ) ? 'DISPLAY: none' : '',
)
);
$wrapDiv = new hcHtmlElement( '<DIV>' );
$wrapDiv->setID( $fileIntGroupHandle . $j );
if( $j > 1 )
$wrapDiv->setStyle( 'DISPLAY: none' );
$internalGroup->wrapBy( $wrapDiv );
$filesGroup->addChild( $internalGroup );
}
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $btnAddField );
$this->_form->addChild( $srcFtpGroup );
$this->_form->addChild( $filesGroup );
$this->_form->addChild( $buttons );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_MoveTo.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_MoveTo extends mwActionForm {
function view(){
$inputFields = array();
$view = '';
$thisActionHandle = 'move';
$this->_form->setLegend( M('action/move') );
$selectedFiles = new hcHtmlElement( '<DIV>' );
$selectedFiles->setID( $this->_selectedFilesID );
// FIELDS
$moveGroup = new hcActionControlSet();
$moveGroup->setLegend( M('form/destination') );
$ctlMoveToDirName = new hcActionControl_Text( $this->_resp );
$ctlMoveToDirName->forceHTMLName( CHNDL_MOVETO_DIR_NAME );
// $ctlMoveToDirName->setLabel( M('actionForm/move/destinationDirectory') );
$ctlMoveToDirName->setSize( 80 );
$ctlMoveToDirName->setValue( $this->getCurrentDir() );
$btnSelectDir_MoveTo = new hcActionControl_Button( $this->_resp );
$btnSelectDir_MoveTo->setValue( M('form/selectDir') );
$dirSelectorWinURL = $this->_resp->generateURL(
array(),
array(
PARAM_VIEW_HANDLE => VIEW_HANDLE_SELECT_DIR,
PARAM_TARGET_CONTROL => $this->_form->getName() . '.' . $ctlMoveToDirName->getHTMLName(),
)
);
$btnSelectDir_MoveTo->setOnClick( "openWindow(\"$dirSelectorWinURL\");" );
$moveGroup->addChild( $ctlMoveToDirName );
$moveGroup->addChild( $btnSelectDir_MoveTo );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hideElement( \"" . $this->_form->getID() . "\" )" );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\", \"" . $this->_selectedFilesID . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $moveGroup );
$this->_form->addChild( $buttons );
$this->_form->addChild( $selectedFiles );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_MultiCopyTo.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_MultiCopyTo extends mwActionForm {
function view(){
$inputFields = array();
$view = '';
$thisActionHandle = 'multi_copy';
$this->_form->setLegend( M('action/copy') );
$selectedFiles = new hcHtmlElement( '<DIV>' );
$selectedFiles->setID( $this->_selectedFilesID );
// FIELDS
$copyGroup = new hcActionControlSet();
$copyGroup->setLegend( M('form/destination') );
$groupCopyToDirName = new hcActionControlGroup();
$ctlCopyToDirName = new hcActionControl_Text( $this->_resp );
$ctlCopyToDirName->forceHTMLName( CHNDL_MULTICOPYTO_DIR_NAME );
// $ctlCopyToDirName->setLabel( 'Copy to' );
$ctlCopyToDirName->setSize( 80 );
$ctlCopyToDirName->setValue( $this->getCurrentDir() );
$btnSelectDir_CopyTo = new hcActionControl_Button( $this->_resp );
$btnSelectDir_CopyTo->setValue( M('form/selectDir') );
$dirSelectorWinURL = $this->_resp->generateURL(
array(),
array(
PARAM_VIEW_HANDLE => VIEW_HANDLE_SELECT_DIR,
PARAM_TARGET_CONTROL => $this->_form->getName() . '.' . $ctlCopyToDirName->getHTMLName(),
)
);
$btnSelectDir_CopyTo->setOnClick( "openWindow(\"$dirSelectorWinURL\");" );
$copyGroup->addChild( $ctlCopyToDirName );
$copyGroup->addChild( $btnSelectDir_CopyTo );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\", \"" . $this->_selectedFilesID . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $copyGroup );
$this->_form->addChild( $buttons );
$this->_form->addChild( $selectedFiles );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_NewDir.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_NewDir extends mwActionForm {
function view(){
$newdirFieldsNum = HTML_MAX_FILE_FIELDS;
$thisActionHandle = 'newdir';
$this->_form->setLegend( M('action/newDir') );
$fileIntGroupHandle = HTML_DIV_ACTION_WRAPPER . CHNDL_NEW_DIR_NAME;
// ADD FIELD BUTTON
$btnAddField = new hcActionControl_Button( $this->_resp );
$btnAddField->setValue( M('form/addField') . ' (max ' . HTML_MAX_FILE_FIELDS . ')' );
$btnAddField->setOnclick( "showNextFileField( \"$fileIntGroupHandle\" )" );
// FIELDS
$namesGroup = new hcActionControlSet();
$namesGroup->setLegend( M('action/newDir') );
for( $j = 1; $j <= $newdirFieldsNum; $j++ ){
$ctlNewDirName = new hcActionControl_Text( $this->_resp, $j );
$ctlNewDirName->setHandle( CHNDL_NEW_DIR_NAME );
// $ctlNewDirName->setLabel( 'New Directory' );
$ctlNewDirName->setSize( 30 );
$wrapDiv = new hcHtmlElement( '<DIV>' );
$wrapDiv->setID( $fileIntGroupHandle . $j );
if( $j > 1 )
$wrapDiv->setStyle( 'DISPLAY: none' );
$ctlNewDirName->wrapBy( $wrapDiv );
$namesGroup->addChild( $ctlNewDirName );
}
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $btnAddField );
$this->_form->addChild( $namesGroup );
$this->_form->addChild( $buttons );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_NewFile.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_NewFile extends mwActionForm {
function view(){
$thisActionHandle = 'newfile';
$this->_form->setLegend( M('action/newFile') );
$namesGroup = new hcActionControlSet();
$namesGroup->setLegend( M('action/newFile') );
// NEW NAMES
$ctlNewFileName = new hcActionControl_Text( $this->_resp );
$ctlNewFileName->forceHTMLName( CHNDL_NEW_FILE_NAME );
// $ctlNewFileName->setLabel( 'New File Name' );
$ctlNewFileName->setSize( 30 );
$namesGroup->addChild( $ctlNewFileName );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $namesGroup );
$this->_form->addChild( $buttons );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_NoteSelectItems.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_NoteSelectItems extends mwActionForm {
function view(){
$thisActionHandle = 'noteselectitems';
$this->_form->setLegend( M('action/error/noItemsSelected') );
$ctlGroup = new hcActionControlSet();
$ctlGroup->setLegend( M('action/error/noItemsSelected') );
// NOTE
$myNote = new hcActionControl_Label( $this->_resp );
$myNote->setValue( M('action/error/noItemsSelected/selectOne') );
$ctlGroup->addChild( $myNote );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/ok') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\" )" );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $ctlGroup );
$this->_form->addChild( $buttons );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_Rename.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_Rename extends mwActionForm {
function view(){
$inputFields = array();
$view = '';
$thisActionHandle = 'rename';
$this->_form->setLegend( M('action/rename') );
$selectedFiles = new hcHtmlElement( '<DIV>' );
$selectedFiles->setID( $this->_selectedFilesID );
// FIELDS
$renameGroup = new hcActionControlSet();
$renameGroup->setLegend( M('action/rename/renameTo') );
$ctlRenameTo = new hcActionControl_Text( $this->_resp );
$ctlRenameTo->forceHTMLName( CHNDL_RENAME_NEW_NAME );
// $ctlRenameTo->setLabel( 'Rename to' );
$ctlRenameTo->setSize( 30 );
$renameGroup->addChild( $ctlRenameTo );
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\", \"" . $this->_selectedFilesID . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $renameGroup );
$this->_form->addChild( $buttons );
$this->_form->addChild( $selectedFiles );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_Transload.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_Transload extends mwActionForm {
function view(){
$settingsManager =& mwfSettingsManager::getInstance();
$uploadFieldsNum = HTML_MAX_FILE_FIELDS;
$thisActionHandle = 'transload';
$this->_form->setLegend( M('action/transload') );
$fileIntGroupHandle = HTML_DIV_ACTION_WRAPPER . CHNDL_TRANSLOAD_FIELD;
// ADD FIELD BUTTON
$btnAddField = new hcActionControl_Button( $this->_resp );
$btnAddField->setValue( M('form/addField') . ' (max ' . HTML_MAX_FILE_FIELDS . ')' );
$btnAddField->setOnclick( "showNextFileField( \"$fileIntGroupHandle\" )" );
// FIELDS
$filesGroup = new hcActionControlSet();
$filesGroup->setLegend( M('form/selectFiles') );
for( $j = 1; $j <= $uploadFieldsNum; $j++ ){
$internalGroup = new hcActionControlGroup();
$ctlTransloadField = new hcActionControl_Text( $this->_resp, $j );
$ctlTransloadField->setHandle( CHNDL_TRANSLOAD_FIELD );
$ctlTransloadField->setLabel( 'URL' );
$ctlTransloadField->setValue( 'http://' );
$ctlTransloadField->setSize( 60 );
$ctlTransloadMode = new hcActionControl_Select( $this->_resp, $j );
if( defined('SETTING_DEFAULT_UPLOAD_MODE') )
$defaultUploadMode = $settingsManager->get( SETTING_DEFAULT_UPLOAD_MODE );
else
$defaultUploadMode = FILE_MODE_ASCII;
$ctlTransloadMode->fill( array(FILE_MODE_ASCII => 'ascii', FILE_MODE_BINARY => 'binary') );
$ctlTransloadMode->setHandle( CHNDL_TRANSLOAD_MODE );
$ctlTransloadMode->setValue( $defaultUploadMode );
$ctlTransloadMode->setLabel( M('form/transferMode') );
$internalGroup->addChild( $ctlTransloadMode );
$internalGroup->addChild( $ctlTransloadField );
$wrapDiv = new hcHtmlElement( '<DIV>' );
$wrapDiv->setID( $fileIntGroupHandle . $j );
if( $j > 1 )
$wrapDiv->setStyle( 'DISPLAY: none' );
$internalGroup->wrapBy( $wrapDiv );
$filesGroup->addChild( $internalGroup );
}
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $btnAddField );
$this->_form->addChild( $filesGroup );
$this->_form->addChild( $buttons );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_Upload.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_Upload extends mwActionForm {
function view(){
$settingsManager =& mwfSettingsManager::getInstance();
$uploadFieldsNum = HTML_MAX_FILE_FIELDS;
$thisActionHandle = 'upload';
$this->_form->enableUploads();
$this->_form->setLegend( M('action/upload') );
$fileIntGroupHandle = HTML_DIV_ACTION_WRAPPER . CHNDL_UPLOAD_FIELD;
// ADD FIELD BUTTON
$btnAddField = new hcActionControl_Button( $this->_resp );
$btnAddField->setValue( M('form/addField') . ' (max ' . HTML_MAX_FILE_FIELDS . ')' );
$btnAddField->setOnclick( "showNextFileField( \"$fileIntGroupHandle\" )" );
// FIELDS
$filesGroup = new hcActionControlSet();
$filesGroup->setLegend( M('form/selectFiles') );
for( $j = 1; $j <= $uploadFieldsNum; $j++ ){
$internalGroup = new hcActionControlGroup();
$ctlUploadField = new hcActionControl_Upload( $this->_resp, $j );
$ctlUploadField->setHandle( CHNDL_UPLOAD_FIELD );
$ctlUploadField->setSize( 60 );
$ctlUploadMode = new hcActionControl_Select( $this->_resp, $j );
if( defined('SETTING_DEFAULT_UPLOAD_MODE') )
$defaultUploadMode = $settingsManager->get( SETTING_DEFAULT_UPLOAD_MODE );
else
$defaultUploadMode = FILE_MODE_ASCII;
$ctlUploadMode->fill( array(FILE_MODE_ASCII => 'ascii', FILE_MODE_BINARY => 'binary') );
$ctlUploadMode->setHandle( CHNDL_UPLOAD_MODE );
$ctlUploadMode->setValue( $defaultUploadMode );
$ctlUploadMode->setLabel( M('form/transferMode') );
$internalGroup->addChild( $ctlUploadMode );
$internalGroup->addChild( $ctlUploadField );
$wrapDiv = new hcHtmlElement( '<DIV>' );
$wrapDiv->setID( $fileIntGroupHandle . $j );
if( $j > 1 )
$wrapDiv->setStyle( 'DISPLAY: none' );
$internalGroup->wrapBy( $wrapDiv );
$filesGroup->addChild( $internalGroup );
}
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $btnAddField );
$this->_form->addChild( $filesGroup );
$this->_form->addChild( $buttons );
// view
$view = $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/actionForms/mwActionForm_ZipUpload.php : 1
<?
include_once( 'mwActionForm.php' );
class mwActionForm_ZipUpload extends mwActionForm {
function view(){
$settingsManager =& mwfSettingsManager::getInstance();
$thisActionHandle = 'zip_upload';
$this->_form->enableUploads();
$this->_form->setLegend( M('action/unzipUpload') );
if( defined('FREE_VERSION') && FREE_VERSION ){
$vreeVersionNotice = FREE_VERSION_NOTICE;
$this->_form->addChild( $vreeVersionNotice );
}
$fileIntGroupHandle = HTML_DIV_ACTION_WRAPPER . CHNDL_UPLOAD_FIELD;
$uploadFieldsNum = 1;
// FIELDS
$filesGroup = new hcActionControlSet();
$filesGroup->setLegend( M('form/selectFile') );
for( $j = 1; $j <= $uploadFieldsNum; $j++ ){
$internalGroup = new hcActionControlGroup();
$ctlUploadMode = new hcActionControl_Select( $this->_resp, $j );
$ctlUploadMode->fill( array(UNZIP_MODE_TREE => M('action/unzipUpload/unzipMode/tree'), UNZIP_MODE_FLAT => M('action/unzipUpload/unzipMode/flat')) );
$ctlUploadMode->setHandle( CHNDL_UPLOAD_MODE );
$ctlUploadMode->setLabel( M('action/unzipUpload/unzipMode') );
$ctlUploadField = new hcActionControl_Upload( $this->_resp, $j );
$ctlUploadField->setHandle( CHNDL_UPLOAD_FIELD );
$ctlUploadField->setSize( 60 );
$internalGroup->addChild( $ctlUploadMode );
$internalGroup->addChild( $ctlUploadField );
$wrapDiv = new hcHtmlElement( '<DIV>' );
$wrapDiv->setID( $fileIntGroupHandle . $j );
if( $j > 1 )
$wrapDiv->setStyle( 'DISPLAY: none' );
$internalGroup->wrapBy( $wrapDiv );
$filesGroup->addChild( $internalGroup );
}
// ACTION BUTTONS
$buttons = new hcActionControlGroup();
$btnConfirm = new hcActionControl_Submit( $this->_resp );
$btnConfirm->setHandle( $thisActionHandle );
$btnConfirm->setParam( 'op', $thisActionHandle );
$btnConfirm->setValue( M('form/ok') );
$btnCancel = new hcActionControl_Button( $this->_resp );
$btnCancel->setValue( M('form/cancel') );
$btnCancel->setOnclick( "hdaf( \"" . $this->_form->getID() . "\" )" );
$buttons->addChild( $btnConfirm );
$buttons->addChild( $btnCancel );
// FILL IN FORM
$this->_form->addChild( $filesGroup );
$this->_form->addChild( $buttons );
// view
$view = '';
$view .= $this->_form->view();
return $view;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/controls/mwfActionControl_FileModeSelector.php : 1
<?
class mwfActionControl_FileModeSelector extends hcActionControl {
function view(){
$view = '';
$currentMode = $this->getValue();
$id = $this->getID();
$htmlName = $this->getHTMLName();
if( $this->_label )
$note = $this->_label . ':';
else
$note = '';
$viewContainer = new hcViewContainer( FILES_DIR . '/templates/views/rich/controls/fileModeSelector.tpl' );
$viewContainer->addChild( $id, 'ID' );
$viewContainer->addChild( $currentMode, 'CURRENT_MODE' );
$viewContainer->addChild( $htmlName, 'MODE_CONTROL_NAME' );
$viewContainer->addChild( $note, 'CONTROL_NOTE' );
$view = $viewContainer->view();
return $view;
}
}
startFile : mwftp5/ftp/index_files/classes/views/rich/objectViews/mwfView_FilePager.php : 1
<?
class mwfView_FilePager extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
pages => array of pages - each as array( 'pn' => pn, 'title' => title )
currentPage => currently selected page
paramName => HTML param name to transfer page number
pagesizeParamName => HTML param name to transfer page size
pagesizeOptions => array of available pagesize options to select
currentPagesize => currently selected pagesize
*/
function view(){
$out = '';
// SOME VIEW DATA
$viewData =& $this->getData();
$pagesArray = $viewData['pages'];
$currentPage = $viewData['currentPage'];
$paramName = $viewData['paramName'];
$pagesizeParamName = $viewData['pagesizeParamName'];
$pagesizeOptions = $viewData['pagesizeOptions'];
$currentPagesize = $viewData['currentPagesize'];
// CONTAINER
$pagerOptions = new hcActionForm( $this->_resp );
// PAGE LINKS
$pageLinks = new hcActionControlSet();
$pageLinks->setLegend( M('pager/header') );
reset( $pagesArray );
foreach( $pagesArray as $pi ){
$pageNumber = $pi['pn'];
$pageTitle = $pi['title'];
if( $currentPage == $pageNumber ){ // current page
$pageLink = new hcActionControl_Label( $this->_resp );
$pageLink->setValue( $pageTitle );
$pageLink->wrapBy( new hcHtmlElement('<strong>') );
}
else { // other page
$pageLink = new hcActionControl_Link( $this->_resp );
$pageLink->setStateParam( $paramName, $pageNumber );
$pageLink->setValue( $pageTitle );
}
$pageLinks->addChild( $pageLink );
}
// PAGESIZE SELECTOR
$pagesizeLinks = new hcActionControlSet();
$pagesizeLinks->setLegend( M('pager/pageSizeHeader') );
if( ! $pagesizeOptions )
$pagesizeOptions = array( 5, 10, 15, 0 );
reset( $pagesizeOptions );
foreach( $pagesizeOptions as $pagesize ){
$linkTitle = $pagesize ? $pagesize : M('pager/pageSizeAll');
if( $currentPagesize == $pagesize ){ // current pagesize
$pagesizeLink = new hcActionControl_Label( $this->_resp );
$pagesizeLink->setValue( $linkTitle );
$pagesizeLink->wrapBy( new hcHtmlElement('<strong>') );
}
else { // other pagesize
$pagesizeLink = new hcActionControl_Link( $this->_resp );
$pagesizeLink->setStateParam( $paramName, null );
$pagesizeLink->setStateParam( $pagesizeParamName, $pagesize );
$pagesizeLink->setValue( $linkTitle );
}
$pagesizeLinks->addChild( $pagesizeLink );
}
// FILL IN THE FORM
$pagerOptions->addChild( $pageLinks );
$pagerOptions->addChild( $pagesizeLinks );
$out = $pagerOptions->view();
return $out;
}
}
?>
startFile : mwftp5/ftp/index_files/classes/views/rich/objectViews/mwfView_FileSorter.php : 1
<?
class mwfView_FileSorter extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
pages => array of pages - each as array( 'pn' => pn, 'title' => title )
currentPage => currently selected page
paramName => HTML param name to transfer page number
*/
function view(){
$out = '';
// SOME VIEW DATA
$viewData =& $this->getData();
$sortingsArray = $viewData['sortings'];
$paramName = $viewData['paramName'];
// CONTAINER
$sorterOptions = new hcActionForm( $this->_resp );
$sorterOptions->enablePersistence( 0 );
// SORT LINKS
$sortLinks = new hcActionControlSet();
$sortLinks->setLegend( M('sorter/header') );
reset( $sortingsArray );
foreach( $sortingsArray as $si ){
$showStatus = null;
$sortTitle = $si['title'];
$sortAction = $si['action'];
$sortShow = $si['show'];
if( $sortShow )
$showStatus = ($sortShow == 'asc') ? '^' : 'v';
$sortLink = new hcActionControl_Link( $this->_resp );
$sortLink->setStateParam( $paramName, $sortAction );
$sortLink->setValue( $sortTitle );
$sortLinks->addChild( $sortLink );
if( $showStatus )
$sortLinks->addChild( $showStatus );
}
// FILL IN THE FORM
$sorterOptions->addChild( $sortLinks );
$out = $sorterOptions->view();
return $out;
}
}
?>
startFile : mwftp5/ftp/index_files/conf/filePager.conf : 1
<?
$_pagerConf = array(
'name' => 'p', // HTML name
'pagesize' => 10, // default pagesize
'pagesize_options' => array( 10, 20, 30, 0), // selectable pagesizes - 0 means all
);
?>
startFile : mwftp5/ftp/index_files/conf/fileSorter.conf : 1
<?
$_sorterConf = array(
'name' => 's', // HTML name
'default' => 1, // default sorting
'criteria' => array( // sorting criterea
// propertyName Label Shown, Comparision Type (int/string)
'name' => array( M('fileList/nameHeader'), 'string' ),
'size' => array( M('fileList/sizeHeader'), 'int' ),
'type' => array( M('fileList/typeHeader'), 'string' ),
'date' => array( M('fileList/dateHeader'), 'int' ),
),
'preSort' => array( // preSort criterea
// propertyName ASC/DESC, Comparision Type
'weight' => array('ASC', 'int' ),
),
);
?>
startFile : mwftp5/ftp/index_files/templates/views/rich/ActionResult/actionResult.tpl : 1
<DIV STYLE="WIDTH=75%; FLOAT: left">{ACTION_REQUESTED}</DIV>
<DIV STYLE="WIDTH=20%; FLOAT: right">{STATUS}</DIV>
<DIV STYLE="CLEAR: both"></DIV>
<DIV>{ERROR_MSG}</DIV>
startFile : mwftp5/ftp/index_files/templates/views/rich/ActionResult/actionResults.tpl : 1
<SCRIPT LANGUAGE="JavaScript">
hideShowStatus();
</SCRIPT>
<DIV ID="mwfActionResults">
<DIV CLASS="header">
<DIV STYLE="WIDTH=75%; FLOAT: left"><message>actionResult/actionHeader</message></DIV>
<DIV STYLE="WIDTH=20%; FLOAT: right"><message>actionResult/statusHeader</message></DIV>
<DIV STYLE="CLEAR: both"></DIV>
</DIV>
{ACTION_RESULTS}
<DIV ID="mwfFileActionsBar">
{RETURN_LINKS}
</DIV>
</DIV>
{_FOOTER}
startFile : mwftp5/ftp/index_files/templates/views/rich/controls/fileModeSelector.tpl : 1
<TABLE BORDER="1" STYLE="BORDER: #000000 1px solid; WIDTH: 300px; MARGIN-LEFT: 0px">
<TR>
<TD COLSPAN="3">user</TD>
<TD COLSPAN="3">group</TD>
<TD COLSPAN="3">other</TD>
<TD></TD>
</TR>
<TR ALIGN="center">
<TD>r</TD><TD>w</TD><TD>x</TD>
<TD>r</TD><TD>w</TD><TD>x</TD>
<TD>r</TD><TD>w</TD><TD>x</TD>
<TD>mode</TD>
</TR>
<TR>
<TD><INPUT TYPE=checkbox NAME="ur" onClick="ctl_inc(this.form.{MODE_CONTROL_NAME}, 400, this.checked)"></TD>
<TD><INPUT TYPE=checkbox NAME="uw" onClick="ctl_inc(this.form.{MODE_CONTROL_NAME}, 200, this.checked)"></TD>
<TD><INPUT TYPE=checkbox NAME="ux" onClick="ctl_inc(this.form.{MODE_CONTROL_NAME}, 100, this.checked)"></TD>
<TD><INPUT TYPE=checkbox NAME="gr" onClick="ctl_inc(this.form.{MODE_CONTROL_NAME}, 40, this.checked)"></TD>
<TD><INPUT TYPE=checkbox NAME="gw" onClick="ctl_inc(this.form.{MODE_CONTROL_NAME}, 20, this.checked)"></TD>
<TD><INPUT TYPE=checkbox NAME="gx" onClick="ctl_inc(this.form.{MODE_CONTROL_NAME}, 10, this.checked)"></TD>
<TD><INPUT TYPE=checkbox NAME="or" onClick="ctl_inc(this.form.{MODE_CONTROL_NAME}, 4, this.checked)"></TD>
<TD><INPUT TYPE=checkbox NAME="ow" onClick="ctl_inc(this.form.{MODE_CONTROL_NAME}, 2, this.checked)"></TD>
<TD><INPUT TYPE=checkbox NAME="ox" onClick="ctl_inc(this.form.{MODE_CONTROL_NAME}, 1, this.checked)"></TD>
<TD><INPUT SIZE=4 TYPE=text NAME="{MODE_CONTROL_NAME}" VALUE="777"></TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript">
function fillMyMode( formId ){
var f = document.forms[ formId ];
fill_chmod( f.{MODE_CONTROL_NAME}.value.substring(0, 1), f.ur, f.uw, f.ux );
fill_chmod( f.{MODE_CONTROL_NAME}.value.substring(1, 2), f.gr, f.gw, f.gx );
fill_chmod( f.{MODE_CONTROL_NAME}.value.substring(2, 3), f.or, f.ow, f.ox );
}
</SCRIPT>
startFile : mwftp5/ftp/index_files/templates/views/rich/FileEdit/fileEdit.tpl : 1
<SCRIPT LANGUAGE="JavaScript">
hideShowStatus();
</SCRIPT>
<DIV ID="mwfTopLevelActionsBar">
<DIV STYLE="FLOAT: left">{HOST_INFO}</DIV>
<DIV STYLE="FLOAT: right">{TOP_LEVEL_ACTIONS}</DIV>
<DIV STYLE="CLEAR: both"></DIV>
</DIV>
<DIV ID="mwfFilePath">
{PATH}
</DIV>
<DIV ID="mwfFileEdit">
{FILEEDIT_FORM}
</DIV>
{_FOOTER}
startFile : mwftp5/ftp/index_files/templates/views/rich/FileList/dirInList.tpl : 1
<FORM METHOD="post">
<TR>
<TD><INPUT TYPE=checkbox ID="{CHNDL_FILE_NAME}" NAME="{CHNDL_FILE_NAME}" VALUE="{NAME}"></TD>
<TD ALIGN=left>{DIR_LINK}</TD>
<TD>{TYPE}</TD>
<TD></TD>
<TD>{DATE}</TD>
<TD>{MODE}</TD>
<TD STYLE="TEXT-ALIGN: right">{DIR_ACTIONS}</TD>
</TR>
</FORM>
startFile : mwftp5/ftp/index_files/templates/views/rich/FileList/fileInList.tpl : 1
<FORM METHOD="post">
<TR>
<TD><INPUT TYPE=checkbox ID="{CHNDL_FILE_NAME}" NAME="{CHNDL_FILE_NAME}" VALUE="{NAME}"></TD>
<TD ALIGN=left>{FILE_LINK}</TD>
<TD>{TYPE}</TD>
<TD>{SIZE}</TD>
<TD>{DATE}</TD>
<TD>{MODE}</TD>
<TD STYLE="TEXT-ALIGN: right">{FILE_ACTIONS}</TD>
</TR>
</FORM>
startFile : mwftp5/ftp/index_files/templates/views/rich/FileList/fileList.tpl : 1
<SCRIPT LANGUAGE="JavaScript">
hideShowStatus();
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
/*
* NOW DEFINE SOME CONSTANTS
*/
var HTML_DIV_ACTION_WRAPPER = "{HTML_DIV_ACTION_WRAPPER}";
var HTML_DIV_ACTION_CALL_BUTTON = "{HTML_DIV_ACTION_CALL_BUTTON}";
var CHNDL_FILE_NAME = "{CHNDL_FILE_NAME}";
var HTML_MAX_FILE_FIELDS = {HTML_MAX_FILE_FIELDS};
var SELECTED_FILE_TEMPLATE = "{SELECTED_FILE_TEMPLATE}";
var SELECTED_FILES_CONTAINER_TEMPLATE = "{SELECTED_FILES_CONTAINER_TEMPLATE}";
{SELECT_ACTIONS}
</SCRIPT>
<DIV ID="mwfTopLevelActionsBar">
<DIV STYLE="FLOAT: left">{HOST_INFO}</DIV>
<DIV STYLE="FLOAT: right">{TOP_LEVEL_ACTIONS}</DIV>
<DIV STYLE="CLEAR: both"></DIV>
</DIV>
<DIV ID="mwfFilePath">
{PATH}
</DIV>
<DIV ID="mwfFileActionForms">
{INPUT_FIELDS}
</DIV>
<DIV ID="mwfFileListingContainer">
<DIV ID="mwfFileActionsBar">
{ACTIONS}
</DIV>
<DIV ID="mwfFileListingConfiguration">
<DIV STYLE="FLOAT: left; WIDTH: 25%;">{FILE_SORTER}</DIV>
<DIV STYLE="FLOAT: left;">{FILE_PAGER}</DIV>
<DIV STYLE="FLOAT: right; WIDTH: 40%; TEXT-ALIGN: right;">{FILE_FILTER}</DIV>
<DIV STYLE="CLEAR: both; MARGIN: 0px; PADDING: 0px;"></DIV>
</DIV>
<DIV ID="mwfFileListing">
<TABLE>
<TR>
<TH WIDTH="2%"><INPUT TYPE=checkbox NAME=switcher onClick="safc( this.checked )"></TH>
<TH WIDTH="33%"><message>fileList/nameHeader</message></TH>
<TH WIDTH="5%"><message>fileList/typeHeader</message></TH>
<TH WIDTH="10%"><message>fileList/sizeHeader</message></TH>
<TH WIDTH="15%"><message>fileList/dateHeader</message></TH>
<TH WIDTH="5%"><message>fileList/modeHeader</message></TH>
<TH STYLE="TEXT-ALIGN: right"><message>fileList/actionsHeader</message></TH>
</TR>
{FILE_LISTING}
</TABLE>
</DIV>
</DIV>
{_FOOTER}
startFile : mwftp5/ftp/index_files/templates/views/rich/SelectDir/dirInList.tpl : 1
{DIR_LINK}
startFile : mwftp5/ftp/index_files/templates/views/rich/SelectDir/fileInList.tpl : 1
{NAME}
startFile : mwftp5/ftp/index_files/templates/views/rich/SelectDir/fileList.tpl : 1
<DIV>{HELP_LABEL}</DIV>
<DIV ID="mwfFilePath">
{PATH}
</DIV>
<DIV ID="mwfFileActionsBar">{ACTIONS}</DIV>
<DIV ID="mwfFileListing">
<DIV ID="mwfFileShortListing">
{DIR_LISTING}
{FILE_LISTING}
</DIV>
</DIV>
{_FOOTER}
startFile : mwftp5/hoster/index.php : 1
<?
/***********************************/
/* INITIALIZE
/***********************************/
include_once( dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '_init.php' );
/***********************************/
/* THE APPLICATION CODE
/***********************************/
$fm = new mwfFileManagerFTP();
$vm = new mwfViewManager();
// CONTROLLER
$ah = new mwfActionHandler;
$ah->setFileManager( $fm );
$ah->setViewManager( $vm );
// HEADER
echo mwfCommonView::viewHeader( &$resp );
// VIEW
$view =& $ah->handleAction( $req, $resp );
echo $view->view();
?>
startFile : mwftp5/hoster/index_init.php : 1
<?
myInit( __FILE__ );
if( ! isset($req) )
$req = new hcRequest;
if( ! isset($resp) )
$resp = new hcResponse;
/*
* PACKAGE hoster SPECIFIC INIT STUFF
*/
// THESE ARE HTML CONTROL HANDLES
?>
startFile : mwftp5/hoster/version.txt : 1
5.3.4
startFile : mwftp5/hoster/_ftp_init.php : 1
<?
/****************************************************/
/* THIS FILE CONFIGURES THE CORE FTP PACKAGE */
/****************************************************/
// TRY TO START A SESSION
$session = new hcSession( $req, $resp, 3000, SESSION_DIR );
// CONNECT TO AN EXISTING SESSION
if( ! $session->start() ){ //session problems
echo $session->getDetailedErrorMessage( APP_ROOT_PAGE );
exit;
}
$sData = $session->getData();
if( ! ($sData && isset($sData['ftpUser']) && isset($sData['ftpPass']) ) ){
echo "This page cannot be opened without the session started. Please use the login page first.";
exit;
}
define( 'SESSION_TEMP_DIR', SESSION_DIR . '/' . $session->getTempDirName() );
/*
// APPLICATION SPECIFIC INITIALIZE
*/
// TOP LEVEL ACTIONS
$tlActions = array();
if( ! defined('DIRECT_CONNECTION_HOST') ){
$tlActions[] =
array(
'title' => M('action/logout'),
'handler' => _HANDLER_HOSTER,
'actions' => array(
'op' => 'logout',
)
);
}
// SECURITY MANAGER
include_once( _MODULE_HOSTER_DIR . '/_files/classes/mwfSecurityManager.php');
$actionList = array( 'newdir', 'newfile', 'edit', 'save', 'chdir', 'delete', 'move', 'copy','multi_copy','rename','chmod','download','email','upload','zip_upload','transload','ftpload', 'applyfilter', 'resetfilter' );
$sm = new mwfSecurityManager( _MODULE_HOSTER_DIR . '/_files/conf/permissions.php' );
$sm->setActions( $actionList );
// SETTINGS MANAGER
include_once( _MODULE_HOSTER_DIR . '/_files/classes/mwfSettingsManager.php');
$settingsManager =& mwfSettingsManager::getInstance();
$ftpHost = $settingsManager->get( SETTING_FTP_HOST );
/*
* THIS IS REQUIRED BY THE CORE FTP PACKAGE
*/
//define( 'FTP_HOST', $ftpHost );
define( 'FTP_HOST', $sData['ftpHost'] );
define( 'FTP_USER', $sData['ftpUser'] );
define( 'FTP_PASS', $sData['ftpPass'] );
?>
startFile : mwftp5/hoster/_init.php : 1
<?
define( '_HANDLER_HOSTER', $req->addHandler( _MODULE_HOSTER_DIR . '/index.php', 1 ) );
define( '_HANDLER_FTP', $req->addHandler(
array(
_MODULE_HOSTER_DIR . '/_ftp_init.php',
_MODULE_FTP_DIR . '/index.php'
)
)
);
define( '_HANDLER_HOSTER_ADMIN_LOGIN', $req->addHandler( _MODULE_HOSTER_DIR . '/admin/login.php', 0 ) );
define( '_HANDLER_HOSTER_ADMIN_PANEL', $req->addHandler( _MODULE_HOSTER_DIR . '/admin/index.php', 0 ) );
?>
startFile : mwftp5/hoster/admin/generateIncludes.py : 1
#!/usr/bin/python
import glob, os, re, sys
def getDirs( startDir ):
dirs = []
for d in glob.glob(startDir + '/*'):
if os.path.isdir( d ):
dirs.append( d );
return dirs
###########################################################
# this function opens a directory and processes its files
# returns an array of available classes
###########################################################
def processDir( dirName ):
print "Processing dir: " + dirName
includeFiles = []
for f in glob.glob(dirName + '/*'):
if os.path.isdir( f ):
childFiles = processDir( f )
for childF in childFiles:
includeFiles.append( childF )
else:
includeFiles.append( f )
return includeFiles
###########################################################
# main script
###########################################################
d = '_files'
dirs = getDirs( '.' )
for d in dirs:
includeFiles = processDir( d + '/classes' )
incFileName = d + '/include.php'
incFile = open( incFileName, 'w')
incFile.write( "<?\n" );
for fileName in includeFiles:
fileName = fileName[ len(d): ]
if( fileName == '_init.php' ):
continue
fileName = fileName.replace( '\\', '/' )
line = "include_once( FILES_DIR . '" + fileName + "');\n"
incFile.write(line)
incFile.write( "?>" );
incFile.close()
startFile : mwftp5/hoster/admin/index.php : 1
<?
/***********************************/
/* INITIALIZE
/***********************************/
include_once( dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '_init.php' );
/***********************************/
/* THE APPLICATION CODE
/***********************************/
$vm = new mwfViewManager();
// CONTROLLER
$ah = new mwfActionHandler;
$ah->setTopLevelActions( $tlActions );
$ah->setViewManager( $vm );
// HEADER
echo mwfCommonView::viewHeader( &$resp );
// VIEW
$view =& $ah->handleAction( $req, $resp );
echo $view->view();
?>
startFile : mwftp5/hoster/admin/index_init.php : 1
<?
myInit( __FILE__ );
if( ! isset($req) )
$req = new hcRequest;
if( ! isset($resp) )
$resp = new hcResponse;
/*
* PACKAGE hoster SPECIFIC INIT STUFF
*/
// TRY TO START A SESSION
$session = new hcSession( $req, $resp, 3000, SESSION_DIR );
// CONNECT TO AN EXISTING SESSION
if( ! $session->start() ){ //session problems
echo $session->getDetailedErrorMessage( APP_ROOT_PAGE );
exit;
}
$sData = $session->getData();
if( ! ( $sData && isset($sData['userName']) ) ){
echo "This page cannot be opened without the session started. Please use the login page first.";
exit;
}
$tlActions = array(
array(
'title' => M('adminArea/settings'),
'actions' => array(
'op' => 'viewsettings',
)
),
array(
'title' => M('adminArea/permissions'),
'actions' => array(
'op' => 'viewpermissions',
)
),
array(
'title' => M('adminArea/password'),
'actions' => array(
'op' => 'viewpassform',
)
),
array(
'title' => M('action/logout'),
'actions' => array(
'op' => 'logout',
)
),
);
?>
startFile : mwftp5/hoster/admin/login.php : 1
<?
/***********************************/
/* INITIALIZE
/***********************************/
include_once( dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '_init.php' );
/***********************************/
/* THE APPLICATION CODE
/***********************************/
$vm = new mwfViewManager();
// CONTROLLER
$ah = new mwfActionHandler;
$ah->setViewManager( $vm );
// HEADER
echo mwfCommonView::viewHeader( &$resp );
// VIEW
$view =& $ah->handleAction( $req, $resp );
echo $view->view();
?>
startFile : mwftp5/hoster/admin/login_init.php : 1
<?
myInit( __FILE__ );
if( ! isset($req) )
$req = new hcRequest;
if( ! isset($resp) )
$resp = new hcResponse;
?>
startFile : mwftp5/hoster/admin/index_files/include.php : 1
<?
include_once( FILES_DIR . '/../_files/classes/views/mwfView.php');
include_once( FILES_DIR . '/../_files/classes/views/mwfView_ActionResult.php');
include_once( FILES_DIR . '/classes/mwfActionHandler.php');
include_once( FILES_DIR . '/classes/views/mwfViewManager.php');
include_once( FILES_DIR . '/classes/views/mwfView_Configuration.php');
include_once( FILES_DIR . '/classes/views/mwfView_PassForm.php');
include_once( _MODULE_HOSTER_DIR . '/_files/classes/mwfSettingsManager.php');
include_once( _MODULE_HOSTER_DIR . '/_files/classes/mwfSecurityManager.php');
?>
startFile : mwftp5/hoster/admin/index_files/classes/mwfActionHandler.php : 1
<?
include_once( HCLIB_DIR . '/hcActionHandler.php' );
define( 'VIEW_HANDLE_CONFIGURATION', 31 );
define( 'VIEW_HANDLE_PERMISSIONS', 32 );
define( 'VIEW_HANDLE_PASSFORM', 33 );
class mwfActionHandler extends hcActionHandler {
var $_tlActions;
function mwfActionHandler(){
parent::hcActionHandler();
$this->_tlActions = array();
}
function handleAction( &$req, &$resp ){
$view = parent::handleAction( $req, $resp );
$this->_viewData['topLevelActions'] = $this->_tlActions;
if( ! $view ) {
$viewHandle = $this->getViewHandle();
switch( $viewHandle ){
case VIEW_HANDLE_CONFIGURATION:
$view =& $this->prepareView_Configuration();
break;
case VIEW_HANDLE_PERMISSIONS:
$view =& $this->prepareView_Permissions();
break;
case VIEW_HANDLE_PASSFORM:
$view =& $this->prepareView_PassForm();
break;
}
}
return $view;
}
function init(){
return 1;
}
function getDefaultViewHandle(){
$viewHandle = parent::getDefaultViewHandle();
if( ! $viewHandle )
$viewHandle = VIEW_HANDLE_CONFIGURATION;
return $viewHandle;
}
/*
* ACTION FUNCTIONS
*/
function action_viewpermissions(){
$this->setViewHandle( VIEW_HANDLE_PERMISSIONS );
return 1;
}
function action_viewpassform(){
$this->setViewHandle( VIEW_HANDLE_PASSFORM );
return 1;
}
function action_viewsettings(){
$this->setViewHandle( VIEW_HANDLE_CONFIGURATION );
return 1;
}
function action_savesettings(){
$result = 0;
$actionString = M('adminArea/settings/action/save/description');
$settingsManager =& mwfSettingsManager::getInstance();
$settingsArray = $settingsManager->getAll();
foreach( array_keys($settingsArray) as $k ){
$v = $this->_req->getParam( $k );
$settingsManager->setValue( $k, $v );
}
if( $settingsManager->save() ){
$title = M('actionResult/returnBack');
$returnURL = $this->_resp->generateUrl(
array (
'op' => 'viewsettings',
)
);
$this->addReturnLink( $title, $returnURL );
$this->addActionResult( $actionString );
$result = 1;
}
else
$this->addActionResult( $actionString, 1, 'Error when saving the settings file!' );
return $result;
}
function action_savepassword(){
$result = 1;
$actionString = M('adminArea/password/action/change/description');
$title = M('actionResult/returnBack');
$returnURL = $this->_resp->generateUrl( array ( 'op' => 'viewpassform' ) );
$this->addReturnLink( $title, $returnURL );
$adminPass = new mwPassword( _MODULE_HOSTER_DIR . '/_files/conf/admin_pass.php' );
$oldPass = $this->_req->getParam( CHNDL_OLD_PASS );
$newPass1 = $this->_req->getParam( CHNDL_NEW_PASS1 );
$newPass2 = $this->_req->getParam( CHNDL_NEW_PASS2 );
if( ! $oldPass ){
$this->addActionResult( $actionString, 1, M('adminArea/password/action/change/error/oldPasswordMissing') );
return $result;
}
if( ! $adminPass->check($oldPass) ){
$this->addActionResult( $actionString, 1, M('adminLoginAction/passwordError') . ': ' . $adminPass->getError() );
return $result;
}
if( ! ( $newPass1 && $newPass2 ) ){
$this->addActionResult( $actionString, 1, M('adminArea/password/action/change/error/newPasswordMissing') );
return $result;
}
if( $newPass1 != $newPass2 ){
$this->addActionResult( $actionString, 1, M('adminArea/password/action/change/error/passwordsDiffer') );
return $result;
}
// OKAY, NOW SET NEW PASS
if( ! $adminPass->set( $newPass1 ) ){
$this->addActionResult( $actionString, 1, $adminPass->getError() );
return $result;
}
$result = 1;
$this->resetReturnLinks();
$this->addActionResult( $actionString );
return $result;
}
function action_savepermissions(){
$result = 0;
$actionString = M('adminArea/permissions/action/save/description');
// SECURITY MANAGER
$actionList = array( 'newdir', 'newfile', 'edit', 'save', 'chdir', 'delete', 'move', 'copy','rename','chmod','download','email','upload','transload','ftpload', 'applyfilter', 'resetfilter' );
$sm = new mwfSecurityManager( _MODULE_HOSTER_DIR . '/_files/conf/permissions.php' );
$sm->setActions( $actionList );
$permissionsArray = $sm->getAll();
foreach( array_keys($permissionsArray) as $k ){
$v = $this->_req->getParam( HTML_PERM_FORM_PREFIX . $k );
if( $v )
$sm->actionAllow( $k );
else
$sm->actionDeny( $k );
}
if( $sm->save() ){
$title = M('actionResult/returnBack');
$returnURL = $this->_resp->generateUrl(
array (
'op' => 'viewpermissions',
)
);
$this->addReturnLink( $title, $returnURL );
$this->addActionResult( $actionString );
$result = 1;
}
else
$this->addActionResult( $actionString, 1, M('adminArea/permissions/action/save/error') );
return $result;
}
function action_logout(){
$result = 0;
// DESTROY SESSION
$session = new hcSession( $this->_req, $this->_resp, SESSION_LIFETIME, SESSION_DIR );
$session->start();
$session->destroy();
// REDIRECT TO LOGIN PAGE
$this->_resp->setHandler( _HANDLER_HOSTER_ADMIN_LOGIN );
$forwardTo = $this->_resp->generateNewUrl();
$this->setForward( $forwardTo );
$result = 1;
return $result;
}
/*
* END OF ACTION FUNCTIONS
*/
/*
* PREPARATIONS FOR CONCRETE VIEWS
*/
function &prepareView_Configuration(){
$view =&
$this->vm->getViewObject_Configuration(
$this->_req,
$this->_resp
);
$settingsManager =& mwfSettingsManager::getInstance();
$this->_viewData['configurationValues'] = $settingsManager->getAll();
$view->setData( $this->_viewData );
return $view;
}
function &prepareView_PassForm(){
$view =&
$this->vm->getViewObject_PassForm(
$this->_req,
$this->_resp
);
$view->setData( $this->_viewData );
return $view;
}
function &prepareView_Permissions(){
$view =&
$this->vm->getViewObject_Permissions(
$this->_req,
$this->_resp
);
// SECURITY MANAGER
$actionList = array( 'newdir', 'newfile', 'edit', 'save', 'chdir', 'delete', 'move', 'copy','rename','chmod','download','email','upload','zip_upload','transload','ftpload','applyfilter', 'resetfilter' );
$sm = new mwfSecurityManager( _MODULE_HOSTER_DIR . '/_files/conf/permissions.php' );
$sm->setActions( $actionList );
$this->_viewData['permissionsValues'] = $sm->getAll();
$view->setData( $this->_viewData );
return $view;
}
/*
* END OF CONCRETE VIEWS
*/
/*
* MISC METHODS
*/
function setTopLevelActions( &$tlActions ){
$this->_tlActions =& $tlActions;
}
function setFileManager( &$fm ){
$this->fm = $fm;
}
/*
* END OF MISC METHODS
*/
}
?>
startFile : mwftp5/hoster/admin/index_files/classes/views/mwfViewManager.php : 1
<?
class mwfViewManager {
var $_dir;
function mwfViewManager( $dir = '' ){
$this->_dir = $dir;
if( $this->_dir )
$this->_dir .= '/';
}
function getViewObject_Forward( &$req, &$resp ){
include_once( HCLIB_DIR . '/hcView_Forward.php' );
$viewObject = new hcView_Forward( $req, $resp );
return $viewObject;
}
function getViewObject_ActionResult( &$req, &$resp ){
$viewObject = new mwfView_ActionResult( $req, $resp );
return $viewObject;
}
function &getViewObject_Configuration( &$req, &$resp ){
include_once( $this->_dir . 'mwfView_Configuration.php' );
$viewObject = new mwfView_Configuration( $req, $resp );
return $viewObject;
}
function &getViewObject_PassForm( &$req, &$resp ){
include_once( $this->_dir . 'mwfView_PassForm.php' );
$viewObject = new mwfView_PassForm( $req, $resp );
return $viewObject;
}
function &getViewObject_Permissions( &$req, &$resp ){
include_once( $this->_dir . 'mwfView_Permissions.php' );
$viewObject = new mwfView_Permissions( $req, $resp );
return $viewObject;
}
}
?>
startFile : mwftp5/hoster/admin/index_files/classes/views/mwfView_Configuration.php : 1
<?
class mwfView_Configuration extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
actionResults => action, is_error, msg
returnLinks => array of return options - each as array( 'url' => url, 'title' => title )
*/
function view(){
$viewData =& $this->getData();
$configurationValues = $viewData['configurationValues'];
$topLevelActionsArray = $viewData['topLevelActions'];
$formContainer = new hcViewContainer( $this->getTemplatesDir() . '/Configuration/configuration.tpl' );
$this->prefillViewContainer( $formContainer );
// TOP LINKS
$tlActions =& $this->buildTopLevelActions( $topLevelActionsArray );
// THIS FORM
$thisForm = new hcActionForm( $this->_resp );
$thisForm->setAction( APP_ROOT_PAGE );
$thisForm->setLegend( M('adminArea/settings') );
// CONF FORM
$confForm = new hcActionControlGroup();
// FIELDS
$general = new hcActionControlSet();
$general->setLegend( M('adminArea/settings/general') );
$zipUpload = new hcActionControlSet();
$zipUpload->setLegend( M('adminArea/settings/zipUpload') );
// SETTINGS
foreach( $configurationValues as $settingKey => $settingArray ){
list($settingValue, $settingTitle) = $settingArray;
if( $settingKey == SETTING_DEFAULT_UPLOAD_MODE ){
$confControl = new hcActionControl_Select( $this->_resp );
$confControl->forceHTMLName( $settingKey );
$confControl->setLabel( $settingTitle );
$confControl->fill( array(FILE_MODE_ASCII => 'ascii', FILE_MODE_BINARY => 'binary') );
$confControl->setValue( $settingValue );
}
elseif( $settingKey == SETTING_DEFAULT_PAGE_SIZE ){
include_once( _MODULE_FTP_DIR . '/index_files/conf/filePager.conf' );
$fill = array();
foreach( $_pagerConf[ 'pagesize_options' ] as $v ){
$fill[ "$v" ] = ( $v == 0 ) ? M('pager/pageSizeAll') : $v;
}
$confControl = new hcActionControl_Select( $this->_resp );
$confControl->forceHTMLName( $settingKey );
$confControl->setLabel( $settingTitle );
$confControl->fill( $fill );
$confControl->setValue( $settingValue );
}
else {
$confControl = new hcActionControl_Text( $this->_resp );
$confControl->forceHTMLName( $settingKey );
$confControl->setLabel( $settingTitle );
$confControl->setSize( 50 );
$confControl->setValue( $settingValue );
}
switch( $settingKey ){
case SETTING_UNZIP_UPLOAD_ENTRIES_QTY:
$zipUpload->addChild( $confControl );
break;
default:
$general->addChild( $confControl );
}
$br = '<P>';
$general->addChild( $br );
}
// BUTTONS
$buttons = new hcActionControlGroup();
$btnSave = new hcActionControl_Submit( $this->_resp );
$btnSave->setParam( 'op', 'savesettings' );
$btnSave->setValue( M('adminArea/settings/action/save') );
/*
$checkFields = array(
'this.form.' . SETTING_FTP_HOST,
);
$onClickString = 'return checkFields( ' . join(',', $checkFields) . ' )';
$btnSave->setOnClick( $onClickString );
*/
$buttons->addChild( $btnSave );
// FILL IN THE FORM
$thisForm->addChild( $general );
$thisForm->addChild( $zipUpload );
$thisForm->addChild( $buttons );
$formContainer->addChild( $thisForm, 'CONFIGURATION_FORM' );
$formContainer->addChild( $tlActions, 'TOP_LEVEL_ACTIONS' );
echo parent::view( $formContainer->view() );
}
}
?>
startFile : mwftp5/hoster/admin/index_files/classes/views/mwfView_PassForm.php : 1
<?
class mwfView_PassForm extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
actionResults => action, is_error, msg
returnLinks => array of return options - each as array( 'url' => url, 'title' => title )
*/
function view(){
$viewData =& $this->getData();
$topLevelActionsArray = $viewData['topLevelActions'];
$formContainer = new hcViewContainer( $this->getTemplatesDir() . '/PassForm/passForm.tpl' );
$this->prefillViewContainer( $formContainer );
// TOP LINKS
$tlActions =& $this->buildTopLevelActions( $topLevelActionsArray );
// THIS FORM
$thisForm = new hcActionForm( $this->_resp );
$thisForm->setAction( APP_ROOT_PAGE );
$thisForm->setLegend( M('adminArea/password') );
// CONF FORM
$passwordControls = new hcActionControlGroup();
// FIELDS
$fields = new hcActionControlSet();
$fields->setLegend( M('adminArea/password/action/change') );
$oldPassControl = new hcActionControl_Password( $this->_resp );
$oldPassControl->forceHTMLName( CHNDL_OLD_PASS );
$oldPassControl->setLabel( M('adminArea/password/action/change/oldPassword') );
$oldPassControl->setSize( 30 );
$oldPassControl->wrapBy( new hcHtmlElement('<DIV>') );
$newPassControl1 = new hcActionControl_Password( $this->_resp );
$newPassControl1->forceHTMLName( CHNDL_NEW_PASS1 );
$newPassControl1->setLabel( M('adminArea/password/action/change/newPassword') );
$newPassControl1->setSize( 30 );
$newPassControl1->wrapBy( new hcHtmlElement('<DIV>') );
$newPassControl2 = new hcActionControl_Password( $this->_resp );
$newPassControl2->forceHTMLName( CHNDL_NEW_PASS2 );
$newPassControl2->setLabel( M('adminArea/password/action/change/confirmNewPassword') );
$newPassControl2->setSize( 30 );
$newPassControl2->wrapBy( new hcHtmlElement('<DIV>') );
// BUTTONS
$buttons = new hcActionControlGroup();
$btnSave = new hcActionControl_Submit( $this->_resp );
$btnSave->setParam( 'op', 'savepassword' );
$btnSave->setValue( M('adminArea/password/action/change') );
$buttons->addChild( $btnSave );
$fields->addChild( $oldPassControl );
$fields->addChild( $newPassControl1 );
$fields->addChild( $newPassControl2 );
// FILL IN THE FORM
$thisForm->addChild( $fields );
$thisForm->addChild( $buttons );
$formContainer->addChild( $thisForm, 'PASSWORD_FORM' );
$formContainer->addChild( $tlActions, 'TOP_LEVEL_ACTIONS' );
echo parent::view( $formContainer->view() );
}
}
?>
startFile : mwftp5/hoster/admin/index_files/classes/views/mwfView_Permissions.php : 1
<?
class mwfView_Permissions extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
actionResults => action, is_error, msg
returnLinks => array of return options - each as array( 'url' => url, 'title' => title )
*/
function view(){
$viewData =& $this->getData();
$permissionsValues = $viewData['permissionsValues'];
$topLevelActionsArray = $viewData['topLevelActions'];
$formContainer = new hcViewContainer( $this->getTemplatesDir() . '/Permissions/permissions.tpl' );
$this->prefillViewContainer( $formContainer );
// TOP LINKS
$tlActions =& $this->buildTopLevelActions( $topLevelActionsArray );
// THIS FORM
$thisForm = new hcActionForm( $this->_resp );
$thisForm->setAction( APP_ROOT_PAGE );
$thisForm->setLegend( M('adminArea/permissions') );
// PERM FORM
$permForm = new hcActionControlGroup();
// FIELDS
$fields = new hcActionControlSet();
$fields->setLegend( M('adminArea/permissions') );
foreach( $permissionsValues as $actionName => $isAllowed ){
$actionControl = new hcActionControl_Checkbox( $this->_resp );
$actionControl->forceHTMLName( HTML_PERM_FORM_PREFIX . $actionName );
$actionControl->setLabel( $actionName );
$actionControl->wrapBy( new hcHtmlElement('<DIV>') );
if( $isAllowed )
$actionControl->set();
$fields->addChild( $actionControl );
}
// BUTTONS
$buttons = new hcActionControlGroup();
$btnSave = new hcActionControl_Submit( $this->_resp );
$btnSave->setParam( 'op', 'savepermissions' );
$btnSave->setValue( M('adminArea/permissions/action/save') );
$buttons->addChild( $btnSave );
// FILL IN THE FORM
$thisForm->addChild( $fields );
$thisForm->addChild( $buttons );
$formContainer->addChild( $thisForm, 'PERMISSIONS_FORM' );
$formContainer->addChild( $tlActions, 'TOP_LEVEL_ACTIONS' );
echo parent::view( $formContainer->view() );
}
}
?>
startFile : mwftp5/hoster/admin/index_files/templates/views/Configuration/configuration.tpl : 1
<DIV ID="mwfAdminPanel">
<DIV ID="mwfTopLevelActionsBar">
{TOP_LEVEL_ACTIONS}
</DIV>
<DIV ID="mwfAdminPanelForm">
{CONFIGURATION_FORM}
</DIV>
</DIV>
{_FOOTER}
startFile : mwftp5/hoster/admin/index_files/templates/views/PassForm/passForm.tpl : 1
<DIV ID="mwfAdminPanel">
<DIV ID="mwfTopLevelActionsBar">
{TOP_LEVEL_ACTIONS}
</DIV>
<DIV ID="mwfAdminPanelForm">
{PASSWORD_FORM}
</DIV>
</DIV>
{_FOOTER}
startFile : mwftp5/hoster/admin/index_files/templates/views/Permissions/permissions.tpl : 1
<DIV ID="mwfAdminPanel">
<DIV ID="mwfTopLevelActionsBar">
{TOP_LEVEL_ACTIONS}
</DIV>
<DIV ID="mwfAdminPanelForm">
{PERMISSIONS_FORM}
</DIV>
</DIV>
{_FOOTER}
startFile : mwftp5/hoster/admin/login_files/include.php : 1
<?
include_once( FILES_DIR . '/../_files/classes/views/mwfView.php');
include_once( FILES_DIR . '/../_files/classes/views/mwfView_ActionResult.php');
include_once( FILES_DIR . '/classes/mwfActionHandler.php');
include_once( FILES_DIR . '/classes/views/mwfViewManager.php');
include_once( FILES_DIR . '/classes/views/mwfView_LoginForm.php');
?>
startFile : mwftp5/hoster/admin/login_files/classes/mwfActionHandler.php : 1
<?
include_once( HCLIB_DIR . '/hcActionHandler.php' );
define( 'VIEW_HANDLE_LOGIN_FORM', 21 );
class mwfActionHandler extends hcActionHandler {
function mwfActionHandler(){
parent::hcActionHandler();
}
function handleAction( &$req, &$resp ){
$view = parent::handleAction( $req, $resp );
if( ! $view ) {
$viewHandle = $this->getViewHandle();
switch( $viewHandle ){
case VIEW_HANDLE_LOGIN_FORM:
$view =& $this->prepareView_LoginForm();
break;
}
}
return $view;
}
function init(){
return 1;
}
function getDefaultViewHandle(){
$viewHandle = parent::getDefaultViewHandle();
if( ! $viewHandle )
$viewHandle = VIEW_HANDLE_LOGIN_FORM;
return $viewHandle;
}
/*
* ACTION FUNCTIONS
*/
function action_login(){
$result = 0;
$actionString = M('adminLoginAction/actionName');
$adminPass = new mwPassword( _MODULE_HOSTER_DIR . '/_files/conf/admin_pass.php' );
$suppliedPass = $this->_req->getParam( CHNDL_ADMIN_PASS );
if( ! $suppliedPass ){
$this->_forwardBack();
return $result;
}
if( ! $adminPass->check($suppliedPass) ){
$this->addActionResult( $actionString, 1, M('adminLoginAction/passwordError') . ': ' . $adminPass->getError() . '!' );
}
else {
// SAVE SESSION DATA
$session = new hcSession( $this->_req, $this->_resp, SESSION_LIFETIME, SESSION_DIR );
$sData = array (
'userName' => 'admin',
);
// START UP A NEW SESSION
if( ! ($sid = $session->startNew( $sData )) ){
$this->addActionResult( M('session/startNew'), 1, M('session/createError') );
return $result;
}
// REDIRECT TO FTP PAGE
$this->_resp->setHandler( _HANDLER_HOSTER_ADMIN_PANEL );
$forwardTo = $this->_resp->generateUrl();
$this->setForward( $forwardTo );
$result = 1;
}
return $result;
}
/*
* END OF ACTION FUNCTIONS
*/
/*
* PREPARATIONS FOR CONCRETE VIEWS
*/
function &prepareView_LoginForm(){
$view =&
$this->vm->getViewObject_LoginForm(
$this->_req,
$this->_resp
);
return $view;
}
/*
* END OF CONCRETE VIEWS
*/
/*
* MISC METHODS
*/
function setFileManager( &$fm ){
$this->fm = $fm;
}
/*
* END OF MISC METHODS
*/
}
?>
startFile : mwftp5/hoster/admin/login_files/classes/views/mwfViewManager.php : 1
<?
class mwfViewManager {
var $_dir;
function mwfViewManager( $dir = '' ){
$this->_dir = $dir;
if( $this->_dir )
$this->_dir .= '/';
}
function getViewObject_Forward( &$req, &$resp ){
include_once( HCLIB_DIR . '/hcView_Forward.php' );
$viewObject = new hcView_Forward( $req, $resp );
return $viewObject;
}
function getViewObject_ActionResult( &$req, &$resp ){
$viewObject = new mwfView_ActionResult( $req, $resp );
return $viewObject;
}
function &getViewObject_LoginForm( &$req, &$resp ){
include_once( $this->_dir . 'mwfView_LoginForm.php' );
$viewObject = new mwfView_LoginForm( $req, $resp );
return $viewObject;
}
}
?>
startFile : mwftp5/hoster/admin/login_files/classes/views/mwfView_LoginForm.php : 1
<?
class mwfView_LoginForm extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
* fileContent - the file content
* currentDir - current directory
*/
function view(){
$viewData =& $this->getData();
// THIS FORM
$thisForm = new hcActionForm( $this->_resp );
$thisForm->setAction( APP_ROOT_PAGE );
$thisForm->setLegend( M('loginForm/actionName_AdminLogin') );
// BUTTONS
$buttons = new hcActionControlGroup();
$btnLogin = new hcActionControl_Submit( $this->_resp );
$btnLogin->setParam( 'op', 'login' );
$btnLogin->setValue( M('loginForm/actionName') );
$buttons->addChild( $btnLogin );
// FIELDS
$fields = new hcActionControlSet();
$fields->setLegend( M('loginForm/header') );
$passControl = new hcActionControl_Password( $this->_resp );
$passControl->forceHTMLName( CHNDL_ADMIN_PASS );
$passControl->setLabel( M('loginForm/password') );
$passControl->setSize( 20 );
$fields->addChild( $passControl );
$userLink = new hcActionControl_Link( $this->_resp );
$userLink->setHandler( _HANDLER_HOSTER );
$userLink->setValue( M('loginForm/actionName_UserLogin') );
// FILL IN THE FORM
$thisForm->addChild( $fields );
$thisForm->addChild( $buttons );
$viewContainer = new hcViewContainer( $this->getTemplatesDir() . '/loginForm.tpl' );
$this->prefillViewContainer( $viewContainer );
$viewContainer->addChild( $thisForm, 'LOGIN_FORM' );
$viewContainer->addChild( $userLink, 'USER_LINK' );
echo parent::view( $viewContainer->view() );
}
}
?>
startFile : mwftp5/hoster/admin/login_files/templates/views/loginForm.tpl : 1
<DIV ID="mwfAdminLoginForm">
{LOGIN_FORM}
<DIV STYLE="TEXT-ALIGN: right;">
{USER_LINK}
</DIV>
</DIV>
{_FOOTER}
startFile : mwftp5/hoster/admin/_files/include.php : 1
<?
include_once( FILES_DIR . '/classes/views/init.php');
include_once( FILES_DIR . '/classes/views/mwfView.php');
include_once( FILES_DIR . '/classes/views/mwfView_ActionResult.php');
?>
startFile : mwftp5/hoster/admin/_files/classes/views/mwfView.php : 1
<?
class mwfView extends mwfCommonView {
var $_tlActionsArray;
function mwfView( &$req, &$resp ){
parent::mwfCommonView( $req, $resp );
$this->setTemplatesDir( FILES_DIR . '/templates/views' );
}
function &buildTopLevelActions( $tlActions ){
$actions = new hcActionControlGroup();
foreach( $tlActions as $tlActionInfo ){
if( ! isset($tlActionInfo['handler']) )
$tlActionInfo['handler'] = null;
$a = new hcActionControl_Link( $this->_resp );
$url = $this->_resp->generateUrl(
$tlActionInfo['actions'],
array(),
$tlActionInfo['handler']
);
$a->forceURL( $url );
$a->setValue( $tlActionInfo['title'] );
$actions->addChild( $a );
}
return $actions;
}
}
?>
startFile : mwftp5/hoster/admin/_files/classes/views/mwfView_ActionResult.php : 1
<?
include_once( 'mwfView.php' );
class mwfView_ActionResult extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
actionResults => action, is_error, msg
returnLinks => array of return options - each as array( 'url' => url, 'title' => title )
*/
function view(){
$this->setTemplatesDir( MODULE_ROOT_DIR . '/_files/templates/views' );
$viewData =& $this->getData();
$actionResults = $viewData['actionResults'];
$actionResultsTemplateContainer = new hcViewContainer( $this->getTemplatesDir() . '/ActionResult/actionResults.tpl' );
$this->prefillViewContainer( $actionResultsTemplateContainer );
$arContainer = new hcViewContainer( $this->getTemplatesDir() . '/ActionResult/actionResult.tpl' );
$arString = '';
// ACTION RESULTS
foreach( $actionResults as $ar ){
$this->fillActionResultContainer( $arContainer, $ar );
$arString .= $arContainer->view();
$arContainer->clearChildren();
}
// RETURN LINKS
$returnLinks = $viewData['returnLinks'];
$rlArray = array();
foreach( $returnLinks as $rlInfo ){
$rl = new hcActionControl_Link( $this->_resp );
$rl->setValue( $rlInfo['title'] );
$rl->forceURL( $rlInfo['url'] );
$rlArray[] = $rl;
$rlArray[] = '<BR>';
}
$actionResultsTemplateContainer->addChild( $arString, 'ACTION_RESULTS' );
$actionResultsTemplateContainer->addChild( $rlArray, 'RETURN_LINKS' );
echo parent::view( $actionResultsTemplateContainer->view() );
}
function fillActionResultContainer( &$viewContainer, &$actionInfo ){
$status = $actionInfo['is_error'] ? M('actionResult/resultFailed') : M('actionResult/resultOk');
$viewContainer->addChild( $actionInfo['action'], 'ACTION_REQUESTED' );
$viewContainer->addChild( $status, 'STATUS' );
$viewContainer->addChild( $actionInfo['msg'], 'ERROR_MSG' );
}
}
?>
startFile : mwftp5/hoster/admin/_files/templates/views/loginForm.tpl : 1
{LOGIN_FORM}
{_FOOTER}
startFile : mwftp5/hoster/admin/_files/templates/views/ActionResult/actionResult.tpl : 1
<TR>
<TD>{ACTION_REQUESTED}</TD>
<TD>{STATUS}</TD>
</TR>
<TR>
<TD COLSPAN="2">{ERROR_MSG}</TD>
</TR>
startFile : mwftp5/hoster/admin/_files/templates/views/ActionResult/actionResults.tpl : 1
<DIV ID="mwfActionResults">
<TABLE>
<TR>
<TH WIDTH=80%><message>actionResult/actionHeader</message></TH>
<TH WIDTH=20%><message>actionResult/statusHeader</message></TH>
</TR>
{ACTION_RESULTS}
</TABLE>
<DIV ID="mwfFileActionsBar">
{RETURN_LINKS}
</DIV>
</DIV>
{_FOOTER}
startFile : mwftp5/hoster/admin/_files/templates/views/Configuration/configuration.tpl : 1
{TOP_LEVEL_ACTIONS}
<DIV CLASS="mwf">
{CONFIGURATION_FORM}
</DIV>
{_FOOTER}
startFile : mwftp5/hoster/admin/_files/templates/views/PassForm/passForm.tpl : 1
{TOP_LEVEL_ACTIONS}
<DIV CLASS="mwf">
{PASSWORD_FORM}
</DIV>
{_FOOTER}
startFile : mwftp5/hoster/admin/_files/templates/views/Permissions/permissions.tpl : 1
{TOP_LEVEL_ACTIONS}
<DIV CLASS="mwf">
{PERMISSIONS_FORM}
</DIV>
{_FOOTER}
startFile : mwftp5/hoster/index_files/include.php : 1
<?
include_once( FILES_DIR . '/classes/mwfActionHandler.php');
include_once( FILES_DIR . '/classes/mwfFileManager.php');
include_once( FILES_DIR . '/classes/mwfFileManagerFTP.php');
include_once( FILES_DIR . '/classes/views/mwfView.php');
include_once( FILES_DIR . '/classes/views/mwfViewManager.php');
include_once( FILES_DIR . '/classes/views/mwfView_ActionResult.php');
include_once( FILES_DIR . '/classes/views/mwfView_LoginForm.php');
include_once( _MODULE_HOSTER_DIR . '/_files/classes/mwfSettingsManager.php');
include_once( _MODULE_HOSTER_DIR . '/_files/classes/mwfSecurityManager.php');
?>
startFile : mwftp5/hoster/index_files/classes/mwfActionHandler.php : 1
<?
include_once( HCLIB_DIR . '/hcActionHandler.php' );
define( 'VIEW_HANDLE_LOGIN_FORM', 21 );
class mwfActionHandler extends hcActionHandler {
var $fm;
function mwfActionHandler(){
parent::hcActionHandler();
$this->fm = null;
}
function handleAction( &$req, &$resp ){
$view = parent::handleAction( $req, $resp );
if( ! $view ) {
$viewHandle = $this->getViewHandle();
switch( $viewHandle ){
case VIEW_HANDLE_LOGIN_FORM:
$view =& $this->prepareView_LoginForm();
break;
}
}
return $view;
}
function init(){
return 1;
}
function getDefaultViewHandle(){
$viewHandle = parent::getDefaultViewHandle();
if( ! $viewHandle )
$viewHandle = VIEW_HANDLE_LOGIN_FORM;
return $viewHandle;
}
/*
* ACTION FUNCTIONS
*/
function action_login(){
$result = 0;
// $ftpHost = $this->_req->getParam( CHNDL_FTP_HOST );
$ftpUser = $this->_req->getParam( CHNDL_FTP_USER );
$ftpPass = $this->_req->getParam( CHNDL_FTP_PASS );
$ftpStartDir = $this->_req->getParam( CHNDL_FTP_STARTDIR );
$settingsManager =& mwfSettingsManager::getInstance();
$ftpHost = $settingsManager->get( CHNDL_FTP_HOST );
$ftpHost = trim( $ftpHost );
if( preg_match("/;/", $ftpHost) ){
// WILL BE SUPPLIED FROM THE SELECT LIST
$ftpHostId = $this->_req->getParam( CHNDL_FTP_HOST );
$hosts = preg_split( "/\s*;\s*/", $ftpHost );
$ftpHost = $hosts[ $ftpHostId - 1 ];
}
elseif( ! $ftpHost ){
$ftpHost = $this->_req->getParam( CHNDL_FTP_HOST );
}
$actionString = M('loginAction/actionName', array('ftpHost' => $ftpHost, 'ftpUser' => $ftpUser));
$this->fm->setLoginInfo( $ftpHost, $ftpUser, $ftpPass );
if( ! $this->fm->login() ){
$this->addActionResult( $actionString, 1, $this->fm->getLastSystemError() );
}
else {
// SAVE SESSION DATA
$session = new hcSession( $this->_req, $this->_resp, SESSION_LIFETIME, SESSION_DIR );
$sData = array (
'ftpHost' => $ftpHost,
'ftpUser' => $ftpUser,
'ftpPass' => $ftpPass,
);
// START UP A NEW SESSION
if( ! ($sid = $session->startNew( $sData )) ){
$this->addActionResult( M('session/startNew'), 1, M('session/createError') );
return $result;
}
// START DIR
if( isset($ftpStartDir) && $ftpStartDir ){
$this->_resp->setActionParam( 'op', 'chdir' );
$this->_resp->setActionParam( CHNDL_DIR_NAME, $ftpStartDir );
}
// REDIRECT TO FTP PAGE
$this->_resp->setHandler( _HANDLER_FTP );
$forwardTo = $this->_resp->generateUrl();
$this->setForward( $forwardTo );
$result = 1;
}
return $result;
}
function action_logout(){
$result = 0;
// DESTROY SESSION
$session = new hcSession( $this->_req, $this->_resp, SESSION_LIFETIME, SESSION_DIR );
$session->start();
$session->destroy();
// REDIRECT TO LOGIN PAGE
$this->_resp->setHandler( _HANDLER_HOSTER );
$forwardTo = $this->_resp->generateNewUrl();
$this->setForward( $forwardTo );
$result = 1;
return $result;
}
/*
* END OF ACTION FUNCTIONS
*/
/*
* PREPARATIONS FOR CONCRETE VIEWS
*/
function &prepareView_LoginForm(){
$view =&
$this->vm->getViewObject_LoginForm(
$this->_req,
$this->_resp
);
$view->setData( $this->_viewData );
return $view;
}
/*
* END OF CONCRETE VIEWS
*/
/*
* MISC METHODS
*/
function setFileManager( &$fm ){
$this->fm = $fm;
}
/*
* END OF MISC METHODS
*/
}
?>
startFile : mwftp5/hoster/index_files/classes/mwfFileManager.php : 1
<?
class mwfFileManager {
var $_lastSystemError;
function mwfFileManager(){
$this->_lastSystemError = '';
}
function setLastSystemError( $errStr ){
$this->_lastSystemError = $errStr;
}
function getLastSystemError(){
return $this->_lastSystemError;
}
}
?>
startFile : mwftp5/hoster/index_files/classes/mwfFileManagerFTP.php : 1
<?
include_once( 'mwfFileManager.php' );
include_once( HCLIB_DIR . '/ftp-client-class.php' );
class mwfFileManagerFTP extends mwfFileManager {
var $ftp;
var $ftpHost;
var $ftpUser;
var $ftpPass;
var $ftpPort;
function mwfFileManagerFTP(){
parent::mwfFileManager();
$this->ftp =& getFtpEngine();
$this->ftp->timeout = 5;
$this->ftp->debug = false;
}
function setLoginInfo( $ftpHost, $ftpUser, $ftpPass, $ftpPort = 21 ){
//parse $ftpHost to get a port
if ( preg_match('/:/', $ftpHost) ){
preg_match('/(.+):(.+)/', $ftpHost, $m);
$ftpHost = $m[1];
$ftpPort = $m[2];
}
$this->ftpHost = $ftpHost;
$this->ftpUser = $ftpUser;
$this->ftpPass = $ftpPass;
$this->ftpPort = $ftpPort;
}
function login(){
$return = 0;
if (! $this->ftp->ftp_connect( $this->ftpHost, $this->ftpPort ) ){
$errorString = M('ftp/action/login/error/cannotConnect', array('ftpHost' => $this->ftpHost, 'ftpPort' => $this->ftpPort) );
$errorString .= '<BR>' . M('common/systemErrorMessage') . ': ' . $this->ftp->getLastSystemMessage();
$this->setLastSystemError( $errorString );
return $return;
}
if (! $this->ftp->ftp_login( $this->ftpUser, $this->ftpPass ) ){
$this->quit();
$errorString = M('ftp/action/login/error/cannotLogin', array('ftpHost' => $this->ftpHost, 'ftpUser' => $this->ftpUser) );
$errorString .= '<BR>' . M('common/systemErrorMessage') . ': ' . $this->ftp->getLastSystemMessage();
$this->setLastSystemError( $errorString );
return $return;
}
$return = 1;
return $return;
}
function quit(){
$this->ftp->ftp_quit();
}
}
?>
startFile : mwftp5/hoster/index_files/classes/views/mwfView.php : 1
<?
class mwfView extends mwfCommonView {
function mwfView( &$req, &$resp ){
parent::mwfCommonView( $req, $resp );
$this->setTemplatesDir( FILES_DIR . '/templates/views' );
}
}
?>
startFile : mwftp5/hoster/index_files/classes/views/mwfViewManager.php : 1
<?
class mwfViewManager {
var $_dir;
function mwfViewManager( $dir = '' ){
$this->_dir = $dir;
if( $this->_dir )
$this->_dir .= '/';
}
function &getViewObject_LoginForm( &$req, &$resp ){
include_once( $this->_dir . 'mwfView_LoginForm.php' );
$viewObject = new mwfView_LoginForm( $req, $resp );
return $viewObject;
}
function getViewObject_Forward( &$req, &$resp ){
include_once( HCLIB_DIR . '/hcView_Forward.php' );
$viewObject = new hcView_Forward( $req, $resp );
return $viewObject;
}
function getViewObject_ActionResult( &$req, &$resp ){
include_once( $this->_dir . 'mwfView_ActionResult.php' );
$viewObject = new mwfView_ActionResult( $req, $resp );
return $viewObject;
}
}
?>
startFile : mwftp5/hoster/index_files/classes/views/mwfView_ActionResult.php : 1
<?
include_once( 'mwfView.php' );
class mwfView_ActionResult extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
actionResults => action, is_error, msg
returnLinks => array of return options - each as array( 'url' => url, 'title' => title )
*/
function view(){
$viewData =& $this->getData();
$actionResults = $viewData['actionResults'];
$actionResultsTemplateContainer = new hcViewContainer( $this->getTemplatesDir() . '/ActionResult/actionResults.tpl' );
$this->prefillViewContainer( $actionResultsTemplateContainer );
$arContainer = new hcViewContainer( $this->getTemplatesDir() . '/ActionResult/actionResult.tpl' );
$arString = '';
// ACTION RESULTS
foreach( $actionResults as $ar ){
$this->fillActionResultContainer( $arContainer, $ar );
$arString .= $arContainer->view();
$arContainer->clearChildren();
}
// RETURN LINKS
$returnLinks = $viewData['returnLinks'];
$rlArray = array();
foreach( $returnLinks as $rlInfo ){
$rl = new hcActionControl_Link( $this->_resp );
$rl->setValue( $rlInfo['title'] );
$rl->forceURL( $rlInfo['url'] );
$rlArray[] = $rl;
$rlArray[] = '<BR>';
}
$actionResultsTemplateContainer->addChild( $arString, 'ACTION_RESULTS' );
$actionResultsTemplateContainer->addChild( $rlArray, 'RETURN_LINKS' );
echo parent::view( $actionResultsTemplateContainer->view() );
}
function fillActionResultContainer( &$viewContainer, &$actionInfo ){
$status = $actionInfo['is_error'] ? M('actionResult/resultFailed') : M('actionResult/resultOk');
$viewContainer->addChild( $actionInfo['action'], 'ACTION_REQUESTED' );
$viewContainer->addChild( $status, 'STATUS' );
$viewContainer->addChild( $actionInfo['msg'], 'ERROR_MSG' );
}
}
?>
startFile : mwftp5/hoster/index_files/classes/views/mwfView_LoginForm.php : 1
<?
include_once( 'mwfView.php' );
class mwfView_LoginForm extends mwfView {
/*
* The data for this view is an array of action results. The keys are:
* fileContent - the file content
* currentDir - current directory
*/
function view(){
$viewData =& $this->getData();
// THIS FORM
$thisForm = new hcActionForm( $this->_resp );
$thisForm->setAction( APP_ROOT_PAGE );
$thisForm->setLegend( M('loginForm/actionName_UserLogin') );
// BUTTONS
$buttons = new hcActionControlGroup();
$btnLogin = new hcActionControl_Submit( $this->_resp );
$btnLogin->setParam( 'op', 'login' );
$btnLogin->setValue( M('loginForm/actionName', array('user' => 'Xpen')) );
$buttons->addChild( $btnLogin );
// FIELDS
$fields = new hcActionControlSet();
$fields->setLegend( M('loginForm/header') );
// CHECK IF WE HAVE MULTIPLE SERVERS
$settingsManager =& mwfSettingsManager::getInstance();
$ftpHost = $settingsManager->get( CHNDL_FTP_HOST );
$ftpHost = trim( $ftpHost );
if( preg_match("/;/", $ftpHost) ){
$hosts = preg_split( "/\s*;\s*/", $ftpHost );
$fill = array();
$i = 1;
foreach( $hosts as $h ){
$fill[ $i ] = $h;
$i++;
}
$hostControl = new hcActionControl_Select( $this->_resp );
$hostControl->fill( $fill );
$hostControl->forceHTMLName( CHNDL_FTP_HOST );;
$hostControl->setLabel( 'Host' );
$fields->addChild( $hostControl );
}
elseif( ! $ftpHost ){
$hostControl = new hcActionControl_Text( $this->_resp );
$hostControl->forceHTMLName( CHNDL_FTP_HOST );;
$hostControl->setLabel( 'Host' );
$fields->addChild( $hostControl );
}
$userControl = new hcActionControl_Text( $this->_resp );
$userControl->forceHTMLName( CHNDL_FTP_USER );
$userControl->setLabel( M('loginForm/username') );
$userControl->setSize( 20 );
$userControl->wrapBy( new hcHtmlElement('<DIV>') );
$passControl = new hcActionControl_Password( $this->_resp );
$passControl->forceHTMLName( CHNDL_FTP_PASS );
$passControl->setLabel( M('loginForm/password') );
$passControl->setSize( 20 );
$passControl->wrapBy( new hcHtmlElement('<DIV>') );
if( ! defined('USER_START_DIR') ){
$startDirControl = new hcActionControl_Text( $this->_resp );
$startDirControl->forceHTMLName( CHNDL_DIR_NAME );
$startDirControl->setLabel( M('loginForm/startDirectory') );
$startDirControl->setSize( 30 );
$startDirControl->wrapBy( new hcHtmlElement('<DIV>') );
}
$fields->addChild( $userControl );
$fields->addChild( $passControl );
$fields->addChild( $startDirControl );
$adminLink = new hcActionControl_Link( $this->_resp );
$adminLink->setHandler( _HANDLER_HOSTER_ADMIN_LOGIN );
$adminLink->setValue( M('loginForm/actionName_AdminLogin') );
// FILL IN THE FORM
$thisForm->addChild( $fields );
$thisForm->addChild( $buttons );
$viewContainer = new hcViewContainer( $this->getTemplatesDir() . '/loginForm.tpl' );
$this->prefillViewContainer( $viewContainer );
$viewContainer->addChild( $thisForm, 'LOGIN_FORM' );
$viewContainer->addChild( $adminLink, 'ADMIN_LINK' );
echo parent::view( $viewContainer->view() );
}
}
?>
startFile : mwftp5/hoster/index_files/templates/views/loginForm.tpl : 1
<DIV ID="mwfUserLoginForm">
{LOGIN_FORM}
<DIV STYLE="TEXT-ALIGN: right;">
{ADMIN_LINK}
</DIV>
</DIV>
{_FOOTER}
startFile : mwftp5/hoster/index_files/templates/views/ActionResult/actionResult.tpl : 1
<TR>
<TD>{ACTION_REQUESTED}</TD>
<TD>{STATUS}</TD>
</TR>
<TR>
<TD COLSPAN="2">{ERROR_MSG}</TD>
</TR>
startFile : mwftp5/hoster/index_files/templates/views/ActionResult/actionResults.tpl : 1
<DIV ID="mwfActionResults">
<TABLE>
<TR>
<TH WIDTH=80%><message>actionResult/actionHeader</message></TH>
<TH WIDTH=20%><message>actionResult/statusHeader</message></TH>
</TR>
{ACTION_RESULTS}
</TABLE>
<DIV ID="mwfFileActionsBar">
{RETURN_LINKS}
</DIV>
</DIV>
{_FOOTER}
startFile : mwftp5/hoster/lang/eng.php : 1
<?
/*
* LANGUAGE INFORMATION
*/
$msg['_info_/name'] = 'English';
$msg['_info_/code'] = 'eng';
$msg['_info_/charset'] = 'iso-8859-1';
$msg['_info_/version'] = '5.2.0';
$msg['_info_/author'] = 'Algis Alekna';
/*
* COMMON PART
*/
// LANGUAGE
$msg['info/language'] = 'Language';
// FILES
$msg['file/openRemoteFile'] = 'Open remote file <B><param>name</param></B>';
$msg['file/error/cannotOpen'] = 'Unable to open file';
$msg['file/error/cannotClose'] = 'Unable to close file';
$msg['file/error/cannotOpenRemoteFile'] = 'Unable to open remote file <B><param>name</param></B>';
// SESSION
$msg['session/startNew'] = 'Start a new session';
$msg['session/createError'] = 'Unable to start session';
$msg['session/error'] = 'Session error';
// ACTION RESULT
$msg['actionResult/actionHeader'] = 'Action';
$msg['actionResult/statusHeader'] = 'Result';
$msg['actionResult/resultOk'] = 'OK';
$msg['actionResult/resultFailed'] = 'Error';
$msg['actionResult/returnBack'] = 'Return';
// PASSWORD
$msg['password/wrong'] = 'Incorrect password';
// FILE ACCESS
$msg['fileAccess/fileDoesNotExist'] = 'File <B><param>filename</param></B> does not exist';
$msg['fileAccess/fileNotReadable'] = 'Unable to open file <B><param>filename</param></B> for reading';
$msg['fileAccess/fileNotWritable'] = 'Unable to open file <B><param>filename</param></B> for writing';
$msg['fileAccess/cannotClose'] = 'Unable to close file <B><param>filename</param></B>';
/*
* FTP ENGINE PART
*/
// COMMON
$msg['common/systemErrorMessage'] = 'System error';
$msg['common/home'] = 'Home';
$msg['common/homeDir'] = 'Starting directory';
$msg['common/toFileList'] = 'To file list';
$msg['common/files'] = 'Files';
$msg['common/dirs'] = 'Folders';
// FTP TERMINOLOGY
$msg['ftp/host'] = 'FTP Server';
$msg['ftp/user'] = 'Username';
$msg['ftp/password'] = 'Password';
// LOGIN
$msg['ftp/action/login/description'] = 'Login to <B><param>ftpHost</param></B> as <B><param>ftpUser</param></B>';
$msg['ftp/action/login/error/cannotConnect'] = 'Unable to connect to FTP server <B><param>ftpHost</param> </B> (port <param>ftpPort</param>)!';
$msg['ftp/action/login/error/cannotLogin'] = 'Unable to login to <B><param>ftpHost</param></B> as <B><param>ftpUser</param></B>!';
// FILE LISTING
$msg['fileList/nameHeader'] = 'Filename';
$msg['fileList/typeHeader'] = 'Type';
$msg['fileList/sizeHeader'] = 'Size, Kb';
$msg['fileList/dateHeader'] = 'Date';
$msg['fileList/modeHeader'] = 'Mode';
$msg['fileList/actionsHeader'] = 'Actions';
// SORTER
$msg['sorter/header'] = 'Sort By';
// PAGER
$msg['pager/header'] = 'Pages';
$msg['pager/pageSizeHeader'] = 'Per Page';
$msg['pager/pageSizeAll'] = 'all';
// FILE NAME FILTER
$msg['fileFilter/header'] = 'File Name Filter';
// FORMS
$msg['form/ok'] = 'OK';
$msg['form/cancel'] = 'Cancel';
$msg['form/apply'] = 'Apply';
$msg['form/reset'] = 'Reset';
$msg['form/select'] = 'Select';
$msg['form/selectFile'] = 'Select File';
$msg['form/selectFiles'] = 'Select Files';
$msg['form/selectDir'] = 'Select Directory';
$msg['form/transferMode'] = 'Mode';
$msg['form/addField'] = 'Add Field';
$msg['form/selectedItems'] = 'Selected Items';
$msg['form/destination'] = 'Where';
// ACTIONS
$msg['action/selectAction'] = 'Action Selection';
$msg['action/error/notAllowed'] = 'Sorry, the action <B><param>name</param> is not allowed';
$msg['action/error/noItemsSelected'] = 'No Items Selected';
$msg['action/error/noItemsSelected/selectOne'] = 'Please select at least one item for this action';
$msg['action/goto'] = 'Go To';
$msg['action/goto/description'] = 'Go To <B><param>dirName</param></B>';
$msg['action/newDir'] = 'New Directory';
$msg['action/newDir/description'] = 'Make new directory <B><param>dirName</param></B>';
$msg['action/newFile'] = 'New File';
$msg['action/upload'] = 'Upload';
$msg['action/upload/description'] = 'Upload <B><param>fileName</param></B>';
$msg['action/upload/descriptionWithMode'] = 'Upload <B><param>fileName</param></B> in <I><param>transferMode</param></I> mode';
$msg['action/upload/error/tooBig'] = 'The file size is bigger than allowed <B><param>allowedSize</param></B>';
$msg['action/upload/error/zeroSize'] = 'The file size is zero';
$msg['action/unzipUpload'] = 'Unzip & Upload';
$msg['action/unzipUpload/description'] = 'Unzip and upload <B><param>fileName</param></B>';
$msg['action/unzipUpload/unzipMode'] = 'Unzip mode';
$msg['action/unzipUpload/unzipMode/tree'] = 'Tree';
$msg['action/unzipUpload/unzipMode/flat'] = 'Flat';
$msg['action/unzipUpload/error/cannotOpenZip'] = 'Unable to open the zip file. Error <param>errorString</param>';
$msg['action/unzipUpload/error/tooManyFiles'] = 'The Zip file contains more entries (<param>count</param>) than allowed in the settings (<param>maxCount</param>)';
$msg['action/transload'] = 'Transload';
$msg['action/transload/description'] = 'Transload <B><param>fileName</param></B> from <B><param>sourceUrl</param></B>';
$msg['action/transload/error/cannotOpenRemoteFile'] = 'Unable to open remote file <B><param>url</param></B>';
$msg['action/transload/error/cannotCloseRemoteFile'] = 'Unable to close remote file <B><param>url</param></B>';
$msg['action/ftpLoad'] = 'Upload From FTP';
$msg['action/ftpLoad/desripition'] = 'Upload from FTP server <B><param>serverAddress</param></B>';
$msg['action/ftpLoad/sourceFtpServerDetails'] = 'Source FTP Server Details';
$msg['action/ftpLoad/noSourceFtpServerDetails'] = 'The source FTP server details incomplete';
$msg['action/ftpLoad/description'] = 'Upload <B><param>fileName</param></B> from <param>sourceServer</param>';
$msg['action/ftpLoad/error/cannotGetRemoteFile'] = 'Unable to open file <B><param>fileName</param></B> from <param>ftpServer</param> FTP server';
$msg['action/email'] = 'Email';
$msg['action/email/description'] = 'Email files to <B><param>email</param></B>';
$msg['action/email/to'] = 'To';
$msg['action/email/msgFrom'] = 'hide@address.com';
$msg['action/email/msgFromName'] = 'OurWebFTP';
$msg['action/email/msgSubject'] = 'Files from OurWebFTP';
$msg['action/email/msgBody'] = "The attached zip file contains the following files:\n";
$msg['action/chmod'] = 'Chmod';
$msg['action/chmod/description'] = 'Chmod <B><param>fileName</param></B> to <B><param>mode</param></B>';
$msg['action/delete'] = 'Delete';
$msg['action/delete/confirmNote'] = 'Are you sure that you want to delete the selected entries?';
$msg['action/delete/description/file'] = 'Delete file <B><param>name</param></B>';
$msg['action/delete/description/dir'] = 'Delete directory <B><param>name</param></B>';
$msg['action/move'] = 'Move';
$msg['action/move/description'] = 'Move <B><param>name</param></B> to <B><param>destinationDir</param></B>';
$msg['action/move/error/sourceTargetCoincide'] = 'The source and destination directories are the same';
$msg['action/copy'] = 'Copy';
$msg['action/copy/description'] = 'Copy <B><param>name</param></B> to <B><param>destinationDir</param></B>';
$msg['action/copy/newName'] = 'New Name';
$msg['action/copy/error/sourceTargetCoincide'] = 'The source and destination files are the same';
$msg['action/download'] = 'Download';
$msg['action/logout'] = 'Logout';
$msg['action/edit'] = 'Edit';
$msg['action/edit/description'] = 'Edit file <B><param>name</param></B>';
$msg['action/edit/saveAs'] = 'Save As';
$msg['action/edit/save'] = 'Save';
$msg['action/edit/fileName'] = 'File';
$msg['action/edit/dirName'] = 'Directory';
$msg['action/view'] = 'View';
$msg['action/save'] = 'Save';
$msg['action/save/description'] = 'Save file <B><param>name</param></B>';
$msg['action/rename'] = 'Rename';
$msg['action/rename/description'] = 'Rename <B><param>oldName</param></B> to <B><param>newName</param></B>';
$msg['action/rename/renameTo'] = 'Rename To';
$msg['action/rename/error/sourceTargetCoincide'] = 'The source and destination files are the same';
$msg['action/selectDir/help'] = 'Proceed to the destination directory then click OK';
/*
* OURWEBFTP PACKAGE PART
*/
// LOGIN FORM
$msg['loginForm/header'] = 'Please Login';
$msg['loginForm/username'] = 'Username';
$msg['loginForm/password'] = 'Password';
$msg['loginForm/startDirectory'] = 'Starting Directory';
$msg['loginForm/actionName'] = 'Enter';
$msg['loginForm/actionName_UserLogin'] = 'Online FTP Login';
$msg['loginForm/actionName_AdminLogin'] = 'Administrator Login';
// ADMIN LOGIN ACTION
$msg['adminLoginAction/actionName'] = 'Login to admin panel';
$msg['adminLoginAction/passwordError'] = 'Admin password error';
// ADMIN AREA
$msg['adminArea/settings'] = 'Settings';
$msg['adminArea/permissions'] = 'Permissions';
$msg['adminArea/password'] = 'Admin Password';
$msg['adminArea/settings/general'] = 'General';
$msg['adminArea/settings/general/ftpHost'] = 'FTP Server Address (leave empty to allow any, or use ";" to separate several)';
$msg['adminArea/settings/general/fileExtToEdit'] = 'File extensions to edit';
$msg['adminArea/settings/general/fileExtToView'] = 'File extensions to view';
$msg['adminArea/settings/general/defaultUploadMode'] = 'Default upload mode';
$msg['adminArea/settings/general/defaultPageSize'] = 'Default page size';
$msg['adminArea/settings/general/maxUploadSize'] = 'Max upload file limit (server limit - <param>serverLimit</param>)';
$msg['adminArea/settings/zipUpload'] = 'Zip Upload';
$msg['adminArea/settings/zipUpload/maxFilesInZip'] = 'Max number of elements in zip archives';
$msg['adminArea/settings/action/save'] = 'Save';
$msg['adminArea/settings/action/save/description'] = 'Save settings';
$msg['adminArea/settings/action/save/error'] = 'Save settings error';
$msg['adminArea/permissions/action/save'] = 'Save';
$msg['adminArea/permissions/action/save/description'] = 'Save permissions';
$msg['adminArea/permissions/action/save/error'] = 'Save permissions error';
$msg['adminArea/password/action/change'] = 'Change';
$msg['adminArea/password/action/change/description'] = 'Change admin password';
$msg['adminArea/password/action/change/oldPassword'] = 'Old Password';
$msg['adminArea/password/action/change/newPassword'] = 'New Password';
$msg['adminArea/password/action/change/confirmNewPassword'] = 'Confirm New Password';
$msg['adminArea/password/action/change/error/oldPasswordMissing'] = 'Old password missing';
$msg['adminArea/password/action/change/error/newPasswordMissing'] = 'New password missing';
$msg['adminArea/password/action/change/error/passwordsDiffer'] = 'Passwords differ';
?>
startFile : mwftp5/hoster/_files/classes/mwfSecurityManager.php : 1
<?
include_once( HCLIB_DIR . '/hcSecurityManager.php' );
class mwfSecurityManager extends hcSecurityManager {
var $_fileName;
function mwfSecurityManager( $fileName ){
$this->_fileName = $fileName;
parent::hcSecurityManager();
$this->load();
}
function load(){
$loadedArray = $this->_load();
foreach( $loadedArray as $k => $v )
if( $v )
$this->actionAllow( $k );
else
$this->actionDeny( $k );
}
function save(){
reset( $this->_actions );
return $this->_save( $this->_actions );
}
function isAllowed( $action, $dirName = '', $userName = '' ){
$return = 0;
if( $this->isActionDefined( $action ) )
$return = $this->_actions[ $action ];
else
echo "Action <B>$action</B> is not defined in the security manager!";
return $return;
}
function _load(){
$returnArray = array();
if( file_exists( $this->_fileName ) ){
include_once( $this->_fileName );
if( isset($_hcpa) && is_array($_hcpa) ){
foreach( $_hcpa as $k => $v )
$returnArray[ $k ] = $v;
}
}
return $returnArray;
}
function _save( $array ){
$return = 0;
reset( $array );
$code = "<?\n";
foreach( $array as $k => $v ){
$code .= "\$_hcpa[\"$k\"] = \"$v\";\n";
}
$code .= "?>";
$file = new mwFile( $this->_fileName );
if( ! $file->open( 'w' ) ){
return $return;
}
if( ! $file->set_content( $code ) ){
return $return;
}
if( ! $file->close() ){
return $return;
}
$return = 1;
return $return;
}
}
?>
startFile : mwftp5/hoster/_files/classes/mwfSettingsManager.php : 1
<?
define( 'SETTING_FTP_HOST', 'ftp_host' );
define( 'SETTING_EDIT_EXTENSIONS', 'ext_edit' );
define( 'SETTING_VIEW_EXTENSIONS', 'ext_view' );
define( 'SETTING_UNZIP_UPLOAD_ENTRIES_QTY', 'unzip_upload_entries_qty' );
define( 'SETTING_DEFAULT_UPLOAD_MODE', 'default_upload_mode' );
define( 'SETTING_DEFAULT_PAGE_SIZE', 'default_page_size' );
define( 'SETTING_MAX_FILE_SIZE', 'max_file_size' );
class mwfSettingsManager extends hcPersistentArray {
var $_settings;
function mwfSettingsManager(){
$fileName = _MODULE_HOSTER_DIR . '/_files/conf/settings.php';
$phpUploadAllowed = ini_get('upload_max_filesize');
$phpUploadAllowed = 1024 * $phpUploadAllowed;
parent::hcPersistentArray( $fileName );
$this->_settings = array(
SETTING_FTP_HOST => array( null, M('adminArea/settings/general/ftpHost') ),
SETTING_EDIT_EXTENSIONS => array( null, M('adminArea/settings/general/fileExtToEdit') ),
SETTING_VIEW_EXTENSIONS => array( null, M('adminArea/settings/general/fileExtToView') ),
SETTING_UNZIP_UPLOAD_ENTRIES_QTY => array( 50, M('adminArea/settings/zipUpload/maxFilesInZip') ),
SETTING_DEFAULT_UPLOAD_MODE => array( FILE_MODE_ASCII, M('adminArea/settings/general/defaultUploadMode') ),
SETTING_DEFAULT_PAGE_SIZE => array( 10, M('adminArea/settings/general/defaultPageSize') ),
SETTING_MAX_FILE_SIZE => array( $phpUploadAllowed, M('adminArea/settings/general/maxUploadSize', array('serverLimit' => $phpUploadAllowed . 'Kb')) ),
);
$this->load();
}
function load(){
$loadedArray = parent::_load();
foreach( $loadedArray as $k => $v )
$this->setValue( $k, $v );
}
function save(){
reset( $this->_settings );
$saveArray = array();
foreach( $this->_settings as $key => $settingArray ){
list($value, $title) = $settingArray;
$saveArray[ $key ] = $value;
}
return parent::_save( $saveArray );
}
function get( $param ){
$return = null;
if( isset($this->_settings[$param] ) )
$return = $this->_settings[$param][0];
return $return;
}
function getTitle( $param ){
}
function setValue( $param, $value ){
if( ! isset($this->_settings[$param]) )
$this->_settings[$param] = array();
$this->_settings[$param][0] = $value;
}
function getAll(){
reset( $this->_settings );
return $this->_settings;
}
// Singleton stuff
function &getInstance(){
return hcMySingletonFunction( 'mwfSettingsManager' );
}
}
?>
startFile : mwftp5/hoster/_files/conf/admin_pass.php : 2
3d801aa532c1cec3ee82d87a99fdf63f
startFile : mwftp5/hoster/_files/conf/permissions.php : 2
<?
$_hcpa["newdir"] = "1";
$_hcpa["newfile"] = "1";
$_hcpa["edit"] = "1";
$_hcpa["save"] = "1";
$_hcpa["chdir"] = "1";
$_hcpa["delete"] = "1";
$_hcpa["move"] = "1";
$_hcpa["copy"] = "1";
$_hcpa["rename"] = "1";
$_hcpa["chmod"] = "1";
$_hcpa["download"] = "1";
$_hcpa["email"] = "1";
$_hcpa["upload"] = "1";
$_hcpa["zip_upload"] = "1";
$_hcpa["transload"] = "1";
$_hcpa["ftpload"] = "1";
$_hcpa["applyfilter"] = "1";
$_hcpa["resetfilter"] = "1";
$_hcpa["view"] = "1";
?>
startFile : mwftp5/hoster/_files/conf/settings.php : 2
<?
$_hcpa["ftp_host"] = "";
$_hcpa["ext_edit"] = ".html, .htm, .php";
$_hcpa["ext_view"] = ".jpg, .png, .gif, .bmp";
$_hcpa["unzip_upload_entries_qty"] = "50";
$_hcpa["default_upload_mode"] = "1";
$_hcpa["default_page_size"] = "0";
$_hcpa["max_file_size"] = "2048";
?>
startFile : mwftp5/_hclib/ftp-client-class.php : 1
<?php
ini_set( 'track_errors', 1 );
define( 'FILE_MODE_ASCII', 0 );
define( 'FILE_MODE_BINARY', 1 );
/*********************************************************************
*
* PHP FTP Client Class By TOMO ( hide@address.com )
*
* - Version 0.12 (2002/01/11)
* - This script is free but without any warranty.
* - You can freely copy, use, modify or redistribute this script
* for any purpose.
* - But please do not erase this information!!.
*
* Modified by Algis Alekna (2003/05/07)
* - Added methods to store and read files thru handles
* - Added recurse option for rmdir
********************************************************************/
function &getFtpEngine(){
$ftpEngine = new ftp_pure;
// if( extension_loaded('ftp') )
// $ftpEngine = new ftp_builtin;
// else
// $ftpEngine = new ftp_pure;
return $ftpEngine;
}
class ftp_builtin extends ftp_base {
/* Public variables */
var $umask;
var $timeout;
/* Private variables */
var $ftp_sock;
var $ftp_resp;
/* Constractor */
function ftp_builtin(){
$this->debug = false;
$this->umask = 0022;
$this->timeout = 30;
$this->ftp_resp = "";
$this->ftp_sock = null;
if( ! defined('FILE_MODE_ASCII') )
define( 'FILE_MODE_ASCII', 0 );
if( ! defined('FILE_MODE_BINARY') )
define( 'FILE_MODE_BINARY', 1 );
}
/* Public functions */
function ftp_connect( $server, $port = 21 ){
$this->ftp_debug("Trying to ".$server.":".$port." ...\n");
$this->ftp_sock = @fsockopen($server, $port, $errno, $errstr, $this->timeout);
$this->ftp_sock = @ftp_connect( $server, $port, $this->timeout );
if ( ! $this->ftp_sock ) {
$msg = "Cannot connect to remote host $server:$port. ";
$msg .= "ftp_connect() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
return FALSE;
}
$this->ftp_debug("Connected to remote host \"".$server.":".$port."\"\n");
return TRUE;
}
function ftp_login($user, $pass){
$response = false;
if( @ftp_login( $this->ftp_sock, $user, $pass ) ){
$this->ftp_debug("Authentication succeeded\n");
$response = true;
}
else {
$msg = "ftp_login() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_pwd(){
$response = '';
$pwd = ftp_pwd( $this->ftp_sock );
if( $pwd !== false ){
$response = $pwd;
}
else {
$msg = "ftp_pwd() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_chdir($pathname) {
$response = false;
if( @ftp_chdir( $this->ftp_sock, $pathname ) ){
$response = true;
}
else {
$msg = "ftp_chdir() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_rawlist($pathname = "" ){
$list = ftp_rawlist( $this->ftp_sock, '-a ' . $pathname );
if( ! $list )
$list = array();
$this->ftp_debug(implode("<BR>\n", $list));
return $list;
}
function ftp_delete($pathname){
$response = false;
if( @ftp_delete( $this->ftp_sock, $pathname ) )
$response = true;
else {
$msg = "ftp_delete() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_rmdir($pathname){
$response = false;
if( @ftp_rmdir( $this->ftp_sock, $pathname ) )
$response = true;
else {
$msg = "ftp_rmdir() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_mkdir($pathname){
$response = false;
if( $dirName = @ftp_mkdir( $this->ftp_sock, $pathname ) )
$response = $dirName;
else {
$msg = "ftp_mkdir() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_rename($from, $to){
$response = false;
if( @ftp_rename( $this->ftp_sock, $from, $to ) )
$response = true;
else {
$msg = "ftp_rename() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_fget( &$localHandle, $remotefile, $mode = FILE_MODE_BINARY){
$response = false;
$mode = ( $mode == FILE_MODE_BINARY ) ? FTP_BINARY : FTP_ASCII;
if( @ftp_fget( $this->ftp_sock, $localHandle, $remotefile, $mode ) ){
rewind( $localHandle );
$response = true;
}
else {
$msg = "ftp_fget() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_fput($remotefile, &$localHandle, $mode = FILE_MODE_BINARY){ //returns a ref to file handle
$response = false;
$mode = ( $mode == FILE_MODE_ASCII ) ? FTP_ASCII : FTP_BINARY;
rewind( $localHandle );
if( @ftp_fput( $this->ftp_sock, $remotefile, $localHandle, $mode ) ){
$response = true;
}
else {
$msg = "ftp_fput() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_get($localfile, $remotefile, $mode = FILE_MODE_BINARY){
$response = false;
$mode = ( $mode == FILE_MODE_BINARY ) ? FTP_BINARY : FTP_ASCII;
if( @ftp_get( $this->ftp_sock, $localfile, $remotefile, $mode ) ){
$response = true;
}
else {
$msg = "ftp_get() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_put($remotefile, $localfile, $mode = FILE_MODE_BINARY){
$response = false;
$mode = ( $mode == FILE_MODE_BINARY ) ? FTP_BINARY : FTP_ASCII;
if( @ftp_put( $this->ftp_sock, $remotefile, $localfile, $mode ) ){
$response = true;
}
else {
$msg = "ftp_put() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_site( $command ){
$response = false;
if( @ftp_site( $this->ftp_sock, $command ) )
$response = true;
else {
$msg = "ftp_site() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
function ftp_quit(){
$response = false;
if( @ftp_quit( $this->ftp_sock ) )
$response = true;
else {
$msg = "ftp_quit() - " . $php_errormsg . "\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
$response = false;
}
return $response;
}
}
/***********************************/
/* PURE FTP REALISATION - PASSIVE MODE ONLY
/***********************************/
class ftp_pure extends ftp_base
{
/* Public variables */
var $umask;
var $timeout;
/* Private variables */
var $ftp_sock;
var $ftp_resp;
/* Constractor */
function ftp_pure()
{
$this->debug = FALSE;
$this->umask = 0022;
$this->timeout = 30;
$this->ftp_resp = "";
}
/* Public functions */
function ftp_connect($server, $port = 21)
{
$this->ftp_debug("Trying to ".$server.":".$port." ...\n");
$this->ftp_sock = @fsockopen($server, $port, $errno, $errstr, $this->timeout);
if (!$this->ftp_sock || !$this->ftp_ok()) {
$msg = "Cannot connect to remote host $server:$port. ";
$msg .= "fsockopen() - " . $errstr . " (" . $errno . ")\n";
$this->ftp_debug( $msg );
$this->setLastSystemMessage( $msg );
return FALSE;
}
$this->ftp_debug("Connected to remote host \"".$server.":".$port."\"\n");
return TRUE;
}
function ftp_login($user, $pass)
{
$this->ftp_putcmd("USER", $user);
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : USER command failed\n");
return FALSE;
}
$this->ftp_putcmd("PASS", $pass);
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : PASS command failed\n");
return FALSE;
}
$this->ftp_debug("Authentication succeeded\n");
return TRUE;
}
function ftp_pwd()
{
$this->ftp_putcmd("PWD");
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : PWD command failed\n");
return FALSE;
}
return preg_replace("/^[0-9]{3} \"(.+)\".*\r\n/", "\\1", $this->ftp_resp);
}
function ftp_chdir($pathname) {
$this->ftp_putcmd("CWD", $pathname);
$response = $this->ftp_ok();
if ( ! $response ){
$this->ftp_debug("Error : CWD command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
}
return $response;
}
function ftp_delete($pathname){
$this->ftp_putcmd("DELE", $pathname);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : DELE command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
}
return $response;
}
function ftp_rmdir($pathname){
//now delete the dir itself
$this->ftp_putcmd("RMD", $pathname);
$response = $this->ftp_ok();
if (!$response)
$this->ftp_debug("Error : RMD command failed\n");
return $response;
}
function ftp_mkdir($pathname){
$this->ftp_putcmd("MKD", $pathname);
$response = $this->ftp_ok();
if ( ! $response ){
$this->ftp_debug("Error : MKD command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
}
return $response;
}
function ftp_rename($from, $to){
$this->ftp_putcmd("RNFR", $from);
if ( ! $this->ftp_ok() ){
$this->ftp_debug("Error : RNFR command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
return FALSE;
}
$this->ftp_putcmd("RNTO", $to);
$response = $this->ftp_ok();
if ( ! $response ){
$this->ftp_debug("Error : RNTO command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
}
return $response;
}
function ftp_rawlist($pathname = "", $pattern = ""){
$list = array();
if (!($string = $this->ftp_pasv())) {
return FALSE;
}
if( $pattern )
$this->ftp_putcmd("LIST -a $pattern", $pathname);
else
$this->ftp_putcmd("LIST -a", $pathname);
$sock_data = $this->ftp_open_data_connection($string);
if (!$sock_data || !$this->ftp_ok()) {
$this->ftp_debug("Error : Cannot connect to remote host\n");
$this->ftp_debug("Error : LIST command failed\n");
return FALSE;
}
$this->ftp_debug("Connected to remote host\n");
while (!feof($sock_data)) {
$list[] = ereg_replace("[\r\n]", "", fgets($sock_data, 512));
}
$this->ftp_debug(implode("<BR>\n", $list));
$this->ftp_close_data_connection($sock_data);
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : LIST command failed\n");
return FALSE;
}
return $list;
}
function ftp_fget( &$localHandle, $remotefile, $mode = FILE_MODE_BINARY){
if( !$this->ftp_type($mode) ){
$this->ftp_debug("Error : GET command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
return FALSE;
}
if( !($string = $this->ftp_pasv()) ){
$this->ftp_debug("Error : GET command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
return FALSE;
}
$this->ftp_putcmd("RETR", $remotefile);
$localHandle = $this->ftp_open_data_connection($string);
if (!$localHandle || !$this->ftp_ok()){
$this->ftp_debug("Error : Cannot connect to remote host\n GET command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
return FALSE;
}
return true;
}
function ftp_fput($remotefile, &$localHandle, $mode = FILE_MODE_BINARY){ //returns a ref to file handle
if(!$this->ftp_type($mode)){
$this->ftp_debug("Error : PUT command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
return FALSE;
}
if(!($string = $this->ftp_pasv())) {
$this->ftp_debug("Error : PUT command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
return FALSE;
}
$this->ftp_putcmd("STOR", $remotefile);
$sock_data = $this->ftp_open_data_connection($string);
if (!$sock_data || !$this->ftp_ok()) {
$this->ftp_debug("Error : Cannot connect to remote host\n");
$this->ftp_debug("Error : PUT command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
return FALSE;
}
rewind( $localHandle );
while( ! feof($localHandle) )
fwrite( $sock_data, fread($localHandle, 4096 ) );
return true;
}
function ftp_get($localfile, $remotefile, $mode = FILE_MODE_BINARY)
{
umask($this->umask);
if (@file_exists($localfile)) {
$this->ftp_debug("Warning : local file will be overwritten\n");
}
$fp = @fopen($localfile, "w");
if (!$fp) {
$this->ftp_debug("Error : Cannot create \"".$localfile."\"");
$this->ftp_debug("Error : GET command failed\n");
return FALSE;
}
if (!$this->ftp_type($mode)) {
$this->ftp_debug("Error : GET command failed\n");
return FALSE;
}
if (!($string = $this->ftp_pasv())) {
$this->ftp_debug("Error : GET command failed\n");
return FALSE;
}
$this->ftp_putcmd("RETR", $remotefile);
$sock_data = $this->ftp_open_data_connection($string);
if (!$sock_data || !$this->ftp_ok()) {
$this->ftp_debug("Error : Cannot connect to remote host\n");
$this->ftp_debug("Error : GET command failed\n");
return FALSE;
}
$this->ftp_debug("Connected to remote host\n");
$this->ftp_debug("Retrieving remote file \"".$remotefile."\" to local file \"".$localfile."\"\n");
while (!feof($sock_data)) {
fputs($fp, fread($sock_data, 4096));
}
fclose($fp);
$this->ftp_close_data_connection($sock_data);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : GET command failed\n");
}
return $response;
}
function ftp_put($remotefile, $localfile, $mode = FILE_MODE_BINARY)
{
if (!@file_exists($localfile)) {
$this->ftp_debug("Error : No such file or directory \"".$localfile."\"\n");
$this->ftp_debug("Error : PUT command failed\n");
$this->setLastSystemMessage( "No such file or directory $localfile. " . $php_errormsg );
return FALSE;
}
$fp = @fopen($localfile, "r");
if (!$fp) {
$this->ftp_debug("Error : Cannot read file \"".$localfile."\"\n");
$this->ftp_debug("Error : PUT command failed\n");
$this->setLastSystemMessage( "Cannot read file $localfile. " . $php_errormsg );
return FALSE;
}
if (!$this->ftp_type($mode)) {
$this->ftp_debug("Error : PUT command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
return FALSE;
}
if (!($string = $this->ftp_pasv())) {
$this->ftp_debug("Error : PUT command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
return FALSE;
}
$this->ftp_putcmd("STOR", $remotefile);
$sock_data = $this->ftp_open_data_connection($string);
if (!$sock_data || !$this->ftp_ok()) {
$this->ftp_debug("Error : Cannot connect to remote host\n");
$this->ftp_debug("Error : PUT command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
return FALSE;
}
$this->ftp_debug("Connected to remote host\n");
$this->ftp_debug("Storing local file \"".$localfile."\" to remote file \"".$remotefile."\"\n");
while (!feof($fp)) {
fputs($sock_data, fread($fp, 4096));
}
fclose($fp);
$this->ftp_close_data_connection($sock_data);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : PUT command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
}
return $response;
}
function ftp_site( $command ){
$this->ftp_putcmd("SITE", $command);
$response = $this->ftp_ok();
if( ! $response ){
$this->ftp_debug("Error : SITE command failed\n");
$this->setLastSystemMessage( $this->ftp_resp );
}
return $response;
}
function ftp_quit()
{
$this->ftp_putcmd("QUIT");
if (!$this->ftp_ok() || !fclose($this->ftp_sock)) {
$this->ftp_debug("Error : QUIT command failed\n");
return FALSE;
}
$this->ftp_debug("Disconnected from remote host\n");
return TRUE;
}
/* Private Functions */
function ftp_type($mode = FILE_MODE_BINARY)
{
if ($mode == FILE_MODE_BINARY) {
$type = "I"; //Binary mode
} else {
$type = "A"; //ASCII mode
}
$this->ftp_putcmd("TYPE", $type);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : TYPE command failed\n");
}
return $response;
}
function ftp_port($ip_port)
{
$this->ftp_putcmd("PORT", $ip_port);
$response = $this->ftp_ok();
if (!$response) {
$this->ftp_debug("Error : PORT command failed\n");
}
return $response;
}
function ftp_pasv()
{
$this->ftp_putcmd("PASV");
if (!$this->ftp_ok()) {
$this->ftp_debug("Error : PASV command failed\n");
return FALSE;
}
$ip_port = ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*\r\n$", "\\1", $this->ftp_resp);
return $ip_port;
}
function ftp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
$cmd = $cmd." ".$arg;
// $cmd = $cmd.' "'.$arg . '"';
}
@fputs($this->ftp_sock, $cmd."\r\n");
$this->ftp_debug("> ".$cmd."\n");
return TRUE;
}
function ftp_ok()
{
$this->ftp_resp = "";
do {
$res = @fgets($this->ftp_sock, 512);
$this->ftp_resp .= $res;
} while (substr($res, 3, 1) != " ");
$this->ftp_debug(str_replace("\r\n", "\n", $this->ftp_resp));
if (!ereg("^[123]", $this->ftp_resp)) {
return FALSE;
}
return TRUE;
}
function ftp_close_data_connection($sock)
{
$this->ftp_debug("Disconnected from remote host\n");
return fclose($sock);
}
function ftp_open_data_connection($ip_port)
{
if (!ereg("[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+", $ip_port)) {
$this->ftp_debug("Error : Illegal ip-port format(".$ip_port.")\n");
return FALSE;
}
$DATA = explode(",", $ip_port);
$ipaddr = $DATA[0].".".$DATA[1].".".$DATA[2].".".$DATA[3];
$port = $DATA[4]*256 + $DATA[5];
$this->ftp_debug("Trying to ".$ipaddr.":".$port." ...\n");
$data_connection = @fsockopen($ipaddr, $port, $errno, $errstr);
if (!$data_connection) {
$this->ftp_debug("Error : Cannot open data connection to ".$ipaddr.":".$port."\n");
$this->ftp_debug("Error : ".$errstr." (".$errno.")\n");
return FALSE;
}
return $data_connection;
}
}
class ftp_base {
var $debug;
var $_systemMessage;
function ftp_debug($message = ""){
if ($this->debug)
echo '<PRE>' . $message . '</PRE>';
return true;
}
function getLastSystemMessage(){
return $this->_systemMessage;
}
function setLastSystemMessage( $msg ){
$this->_systemMessage = $msg;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl.php : 1
<?
class hcActionControl {
var $_resp;
var $_actionParams;
var $_stateParams;
var $_id;
var $_handle;
var $_value;
var $_onClick;
var $_onMouseOver;
var $_relatedControls;
var $_htmlName;
var $_wrappingDiv;
var $_wrapper;
var $_label;
var $_labelOnRight;
function hcActionControl( &$resp, $id = 0 ){
$this->_resp =& $resp;
$this->_actionParams = array();
$this->_stateParams = array();
$this->_relatedControls = array();
$this->_wrappingDiv = array();
$this->_wrapper = null;
if( ! $id )
$id = getUniqueID();
$this->setID( $id );
$this->setHandle( 'control' );
$this->_htmlName = null;
$this->_value = null;
$this->_onClick = null;
$this->_label = null;
$this->_labelOnRight = false;
}
function wrapBy( &$HtmlElement ){
$this->_wrapper = $HtmlElement;
}
function setWrappingDiv( $array ){
$this->_wrappingDiv = $array;
}
function getWrappingDivString(){
$idString = ''; $classString = ''; $styleString = '';
if( isset($this->_wrappingDiv['id']) )
$idString = ' ID="' . $this->_wrappingDiv['id'] . '" ';
if( isset($this->_wrappingDiv['class']) )
$classString = ' CLASS="' . $this->_wrappingDiv['class'] . '" ';
if( isset($this->_wrappingDiv['style']) )
$styleString = ' STYLE="' . $this->_wrappingDiv['style'] . '" ';
$view = '<DIV' . $idString . $classString . $styleString . '>';
return $view;
}
function forceHTMLName( $htmlName ){
$this->_htmlName = $htmlName;
}
function getHTMLName(){
if( $this->_htmlName )
$htmlName = $this->_htmlName;
else
$htmlName = $this->getHandle() . $this->getID();
return $htmlName;
}
function addRelatedControl( &$ctl, $handle ){
$this->_relatedControls[ $handle ] =& $ctl;
}
function setLabel( $label, $onRight = 0 ){
$this->_label = $label;
if( $onRight )
$this->_labelOnRight = true;
}
function setID( $id ){
$this->_id = $id;
}
function getID(){
return $this->_id;
}
function setHandle( $handle ){
$this->_handle = $handle;
}
function getHandle(){
return $this->_handle;
}
function setParam( $pName, $pValue ){
$this->_actionParams[ $pName ] = $pValue;
}
function setStateParam( $pName, $pValue ){
$this->_stateParams[ $pName ] = $pValue;
}
function setValue( $value, $allowHtml = false ){
if( ! $allowHtml )
$value = htmlentities( $value );
$this->_value = $value;
}
function getValue(){
return $this->_value;
}
function setOnClick( $onClick ){
$this->_onClick = $onClick;
}
function setOnMouseOver( $onMouseOver ){
$this->_onMouseOver = $onMouseOver;
}
function view(){
return 'This should be implemented in child classes!';
}
}
?>
startFile : mwftp5/_hclib/hcActionControlGroup.php : 1
<?
include_once( 'hcPatterns.php' );
class hcActionControlGroup extends hcPatterns {
var $_wrapper;
function setWrappingDiv( $obj ){
}
function wrapBy( &$HtmlElement ){
$this->_wrapper = $HtmlElement;
}
function view(){
$view = '';
if( $this->_wrapper )
$view .= $this->_wrapper->getOpenTag();
$childrenArray =& $this->getChildrenArray();
foreach( $childrenArray as $child )
$view .= $this->viewChild( $child );
if( $this->_wrapper )
$view .= $this->_wrapper->getCloseTag();
return $view;
}
function viewChild( &$child ){
$thisView = '';
// object
if( is_object($child) ){
if( method_exists( $child, 'view' ) ){
$thisView = $child->view();
}
}
// array of strings
else if( is_array($child) ){
foreach( $child as $c )
$thisView .= $this->viewChild( $c );
}
// just a string
else {
$thisView = $child;
}
return $thisView;
}
}
?>
startFile : mwftp5/_hclib/hcActionControlSet.php : 1
<?
include_once( 'hcPatterns.php' );
class hcActionControlSet extends hcPatterns {
var $_legend;
function setLegend( $legend ){
$this->_legend = $legend;
}
function view(){
$view = '';
$view .= "<FIELDSET>";
$view .= '<LEGEND>' . $this->_legend . "</LEGEND>";
$childrenArray =& $this->getChildrenArray();
foreach( $childrenArray as $child )
$view .= $this->viewChild( $child );
$view .= "</FIELDSET>";
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl_Button.php : 1
<?
include_once( 'hcActionControl.php' );
class hcActionControl_Button extends hcActionControl {
function view(){
$view = '';
if( $this->_wrappingDiv )
$view .= $this->getWrappingDivString();
$view .= '<INPUT TYPE="button" ID="' . $this->getHTMLName() . '" NAME="' . $this->getHTMLName() . '" VALUE="' . $this->getValue() . '"';
if( $this->_onMouseOver )
$view .= ' ONMOUSEOVER="' . $this->_onMouseOver . '"';
if( $this->_onClick ){
$onClickString = ' ONCLICK=\'' . $this->_onClick . '\'';
$view .= $onClickString;
}
$view .= '>';
if( $this->_wrappingDiv )
$view .= '</DIV>';
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl_Checkbox.php : 1
<?
include_once( 'hcActionControl.php' );
class hcActionControl_Checkbox extends hcActionControl {
var $_checked = false;
function view(){
$view = '';
if( $this->_wrapper )
$view .= $this->_wrapper->getOpenTag();
if( $this->_label && (! $this->_labelOnRight) )
$view .= '<LABEL FOR="' . $this->getHTMLName() . '">' . $this->_label . '</LABEL>';
$view .= '<INPUT TYPE="checkbox" NAME="' . $this->getHTMLName() . '"';
if( $this->_onMouseOver )
$view .= ' ONMOUSEOVER="' . $this->_onMouseOver . '"';
if( $this->_onClick )
$view .= ' ONCLICK="' . $this->_onClick . '"';
if( $this->_value )
$view .= ' VALUE="' . $this->_value . '"';
if( $this->_checked )
$view .= ' CHECKED';
$view .= '>';
if( $this->_label && $this->_labelOnRight )
$view .= '<LABEL FOR="' . $this->getHTMLName() . '">' . $this->_label . '</LABEL>';
if( $this->_wrapper )
$view .= $this->_wrapper->getCloseTag();
return $view;
}
function set(){
$this->_checked = true;
}
function reset(){
$this->_checked = false;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl_Hidden.php : 1
<?
include_once( 'hcActionControl.php' );
class hcActionControl_Hidden extends hcActionControl {
function view(){
$view = '';
$view .= '<INPUT TYPE="hidden" NAME="' . $this->getHTMLName() . '" VALUE="' . $this->getValue() . '">';
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl_Label.php : 1
<?
include_once( 'hcActionControl.php' );
class hcActionControl_Label extends hcActionControl {
function view(){
$view = '';
if( $this->_wrapper )
$view .= $this->_wrapper->getOpenTag();
$view .= $this->getValue();
if( $this->_wrapper )
$view .= $this->_wrapper->getCloseTag();
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl_Link.php : 1
<?
include_once( 'hcActionControl.php' );
class hcActionControl_Link extends hcActionControl {
var $_url = null;
var $_title = null;
var $_handler = null;
var $_target = '';
function forceURL( $url ){
$this->_url = $url;
}
function setHandler( $handler ){
$this->_handler = $handler;
}
function setTitle( $title ){
$this->_title = $title;
}
function setTarget( $target ){
$this->_target = $target;
}
/*
function setParam( $pName, $pValue, $allowHtml = false ){
// if( ! $allowHtml )
// $pValue = urlencode( $pValue );
parent::setParam( $pName, $pValue );
}
*/
function setValue( $value ){
parent::setValue( $value, true );
}
function getUrl(){
return $this->generateUrl();
}
function generateUrl(){
if( $this->_url )
$url = $this->_url;
else {
$resp = cloneObject( $this->_resp );
if( $this->_handler )
$resp->setHandler( $this->_handler );
$url = $resp->generateUrl( $this->_actionParams, $this->_stateParams );
}
return $url;
}
function view(){
$url = $this->generateUrl();
if( ! $this->getValue() )
$this->setValue($url);
$view = '';
$view .= '<A ID="' . $this->getHTMLName() . '" NAME="' . $this->getHTMLName() . '"';
$view .= ' HREF="' . $url . '"';
if( $this->_title )
$view .= ' TITLE="' . $this->_title . '"';
if( $this->_onMouseOver )
$view .= ' ONMOUSEOVER="' . $this->_onMouseOver . '"';
if( $this->_target )
$view .= ' TARGET=\'' . $this->_target . '\'';
if( $this->_onClick ){
$onClickString = ' ONCLICK=\'' . $this->_onClick . '\'';
$view .= $onClickString;
}
$view .= '>';
if( $this->_wrapper )
$view .= $this->_wrapper->getOpenTag();
$view .= $this->getValue();
if( $this->_wrapper )
$view .= $this->_wrapper->getCloseTag();
$view .= '</A>';
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl_Password.php : 1
<?
include_once( 'hcActionControl.php' );
class hcActionControl_Password extends hcActionControl {
var $_size = 0;
var $_isRequired = false;
function setSize( $size ){
$this->_size = $size;
}
function setRequired(){
$this->_isRequired = true;
}
function view(){
$view = '';
if( $this->_wrapper )
$view .= $this->_wrapper->getOpenTag();
if( $this->_label ){
$style = '';
if( $this->_isRequired )
$style = ' STYLE="FONT-WEIGHT: bold" ';
$view .= '<LABEL FOR="' . $this->getHTMLName() . '"' . $style . '>' . $this->_label . '</LABEL>';
}
$view .= '<INPUT TYPE="password" NAME="' . $this->getHTMLName() . '" VALUE="' . $this->getValue() . '"';
if( $this->_size )
$view .= ' SIZE="' . $this->_size . '"';
if( $this->_onMouseOver )
$view .= ' ONMOUSEOVER="' . $this->_onMouseOver . '"';
if( $this->_onClick )
$view .= ' ONCLICK="' . $this->_onClick . '"';
$view .= '>';
if( $this->_wrapper )
$view .= $this->_wrapper->getCloseTag();
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl_Select.php : 1
<?
include_once( 'hcActionControl.php' );
class hcActionControl_Select extends hcActionControl {
var $_classes = array();
var $_onChange = '';
var $_optGroup = '';
function fill( $array ){
$this->_fill = $array;
}
function setClasses( $classes ){
$this->_classes = $classes;
}
function setOnChange( $onChange ){
$this->_onChange = $onChange;
}
function setOptgroup( $label ){
$this->_optGroup = $label;
}
function view(){
$view = '';
if( $this->_wrapper )
$view .= $this->_wrapper->getOpenTag();
if( $this->_label )
$view .= '<LABEL FOR="' . $this->getHTMLName() . '">' . $this->_label . '</LABEL>';
$view .= '<SELECT NAME="' . $this->getHTMLName() . '"' . ' ID="' . $this->getHTMLName() . '"';
if( $this->_onChange )
$view .= ' onChange="' . $this->_onChange . '"';
if( $this->_onClick )
$view .= ' onClick="' . $this->_onClick . '"';
if( $this->_onMouseOver )
$view .= ' onMouseOver="' . $this->_onMouseOver . '"';
$view .= '>';
if( $this->_optGroup )
$view .= '<OPTGROUP LABEL="' . $this->_optGroup . '">';
reset( $this->_fill );
foreach( $this->_fill as $k => $v ){
$selected = ( $this->getValue() == $k ) ? ' SELECTED' : '';
$class = ( isset($this->_classes[$k]) ) ? ' CLASS="' . $this->_classes[$k] . '"' : '';
$view .= '<OPTION VALUE="' . htmlspecialchars($k) . '"' . $class . $selected . '>' . htmlspecialchars($v);
$view .= '</OPTION>';
}
if( $this->_optGroup )
$view .= '</OPTGROUP>';
$view .= '</SELECT>';
if( $this->_wrapper )
$view .= $this->_wrapper->getCloseTag();
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl_Submit.php : 1
<?
include_once( 'hcActionControl.php' );
class hcActionControl_Submit extends hcActionControl {
function getHTMLName(){
$htmlName = $this->_resp->_httpButtonStart . $this->getHandle() . $this->getID();
return $htmlName;
}
function getHiddenName(){
$hiddenName = $this->_resp->_httpHiddenStart . $this->getHandle() . $this->getID();
return $hiddenName;
}
function getRelatedName(){
$hiddenName = $this->_resp->_httpRelatedStart . $this->getHandle() . $this->getID();
return $hiddenName;
}
function getActionString(){
$actionString = $this->_resp->buildActionString( $this->_actionParams );
return $actionString;
}
function getRelatedString(){
$relatedControls = array();
reset( $this->_relatedControls );
foreach( $this->_relatedControls as $h => $ctl )
$relatedControls[ $h ] = $ctl->getHTMLName();
$relatedString = $this->_resp->buildActionString( $relatedControls );
return $relatedString;
}
function view(){
$view = '';
$relatedString = $this->getRelatedString();
if( $this->_wrappingDiv )
$view .= $this->getWrappingDivString();
$view .= '<INPUT TYPE=hidden NAME="' . $this->getHiddenName() . '" VALUE="' . $this->getActionString() . '">' . "\n";
if( $relatedString )
$view .= '<INPUT TYPE=hidden NAME="' . $this->getRelatedName() . '" VALUE="' . $this->getRelatedString() . '">';
if( $this->_label )
$view .= '<LABEL FOR="' . $this->getHTMLName() . '">' . $this->_label . "</LABEL>\n";
$view .= '<INPUT TYPE="submit" ID="' . $this->getHTMLName() . '" NAME="' . $this->getHTMLName() . '" VALUE="' . $this->getValue() . '"';
if( $this->_onMouseOver )
$view .= ' ONMOUSEOVER="' . $this->_onMouseOver . '"';
if( $this->_onClick )
$view .= ' ONCLICK=\'' . $this->_onClick . '\'';
$view .= ">\n";
if( $this->_wrappingDiv )
$view .= "</DIV>\n";
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl_Text.php : 1
<?
include_once( 'hcActionControl.php' );
class hcActionControl_Text extends hcActionControl {
var $_size = 0;
var $_isRequired = false;
var $_isReadonly = false;
function setSize( $size ){
$this->_size = $size;
}
function setRequired(){
$this->_isRequired = true;
}
function setReadonly(){
$this->_isReadonly = true;
}
function setValue( $value ){
parent::setValue( $value, true );
}
function view(){
$view = '';
if( $this->_wrapper )
$view .= $this->_wrapper->getOpenTag();
if( $this->_label ){
$style = '';
if( $this->_isRequired )
$style = ' STYLE="FONT-WEIGHT: bold" ';
$view .= '<LABEL FOR="' . $this->getHTMLName() . '"' . $style . '>' . $this->_label . '</LABEL>';
}
$view .= '<INPUT TYPE="text" NAME="' . $this->getHTMLName() . '" VALUE="' . $this->getValue() . '"';
if( $this->_size )
$view .= ' SIZE="' . $this->_size . '"';
if( $this->_onMouseOver )
$view .= ' ONMOUSEOVER="' . $this->_onMouseOver . '"';
if( $this->_onClick )
$view .= ' ONCLICK="' . $this->_onClick . '"';
if( $this->_isReadonly )
$view .= ' READONLY DISABLED CLASS="readonly" ';
$view .= '>';
if( $this->_wrapper )
$view .= $this->_wrapper->getCloseTag();
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl_Textarea.php : 1
<?
include_once( 'hcActionControl.php' );
class hcActionControl_Textarea extends hcActionControl {
var $_cols = 80;
var $_rows = 25;
var $nowrap = false;
function setSize( $cols, $rows ){
$this->_cols = $cols;
$this->_rows = $rows;
}
function nowrap( $nw = true ){
$this->nowrap = $nw;
}
function view(){
$view = '';
if( $this->_wrapper )
$view .= $this->_wrapper->getOpenTag();
if( $this->_label )
$view .= '<LABEL FOR="' . $this->getHTMLName() . '">' . $this->_label . '</LABEL>';
$view .= '<TEXTAREA NAME="' . $this->getHTMLName() . '" COLS="' . $this->_cols . '" ROWS="' . $this->_rows . '"';
// if( $this->nowrap )
// $view .= ' STYLE="white-space: nowrap"';
if( $this->nowrap )
$view .= ' WRAP="off"';
$view .= '">';
$view .= $this->getValue();
$view .= '</TEXTAREA>';
if( $this->_wrapper )
$view .= $this->_wrapper->getCloseTag();
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionControl_Upload.php : 1
<?
include_once( 'hcActionControl.php' );
class hcActionControl_Upload extends hcActionControl {
var $_size = 0;
function setSize( $size ){
$this->_size = $size;
}
function view(){
$view = '';
$view .= '<INPUT TYPE="file" NAME="' . $this->getHTMLName() . '"';
if( $this->_size )
$view .= ' SIZE="' . $this->_size . '"';
$view .= '>';
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionForm.php : 1
<?
include_once( 'hcPatterns.php' );
class hcActionForm extends hcPatterns {
var $_resp;
var $_action;
var $_name;
var $_id;
var $_legend;
var $_persistent;
var $_uploads;
function hcActionForm( &$resp ){
parent::hcPatterns();
$this->_resp =& $resp;
$this->_action = null;
$this->setName( 'hcaf' . getUniqueID() );
$this->enablePersistence();
$this->enableUploads( 0 );
}
function enablePersistence( $p = 1 ){
$this->_persistent = $p;
}
function setAction( $actionPage ){
$this->_action = $actionPage;
}
function enableUploads( $u = 1 ){
$this->_uploads = $u;
}
function setName( $name ){
$this->_name = $name;
$this->_id = $name;
}
function getName(){
return $this->_name;
}
function getID(){
return $this->_id;
}
function setLegend( $legend ){
$this->_legend = $legend;
}
function view(){
$view = '';
$view .= "\n" . '<FORM NAME="' . $this->getName() . '" ID="' . $this->getID() . '" METHOD="post"';
if( $this->_uploads )
$view .= ' ENCTYPE="multipart/form-data"';
if( $this->_action )
$view .= ' ACTION="' . $this->_action . '"';
$view .= ">\n";
if( $this->_persistent ){
$persistentFields = $this->_resp->generatePersistentFields();
$view .= $persistentFields . "\n";
}
if( $this->_legend )
$view .= '<H3>' . $this->_legend . "</H3>\n";
$childrenArray =& $this->getChildrenArray();
foreach( $childrenArray as $child )
$view .= $this->viewChild( $child ) . "\n";
$view .= "</FORM>\n";
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcActionHandler.php : 1
<?
define( 'VIEW_HANDLE_ACTION_RESULT', 1 );
define( 'VIEW_HANDLE_FORWARD', 2 );
define( 'PARAM_VIEW_HANDLE', 'view' );
class hcActionHandler {
var $ar;
var $vm;
var $sm;
var $forward;
var $returnLinks;
var $_req;
var $_resp;
var $_viewHandle;
var $_viewData;
function hcActionHandler(){
$this->forward = null;
$this->ar = array();
$this->vm = null;
$this->sm = null;
$this->returnLinks = array();
$this->_req = null;
$this->_resp = null;
$this->_viewHandle = null;
$this->_viewData = array();
}
function handleAction( &$req, &$resp ){
if( ! $req )
die( 'No request object supplied in handleAction()!' );
if( ! $resp )
die( 'No response object supplied in handleAction()!' );
$this->_req =& $req;
$this->_resp =& $resp;
$view = null;
$actions = $this->prepareActions();
foreach( $actions as $actionInfo ){
$operation = $actionInfo[ 0 ];
$actionMethodName = $actionInfo[ 1 ];
$checkSecurity = $actionInfo[ 2 ];
if( ( ! $checkSecurity ) || ( $this->_checkActionAllowed($operation) ) ){
eval("\$this->$actionMethodName();");
}
$viewHandle = $this->getViewHandle();
if( $viewHandle )
break;
}
if( ! $viewHandle ){
$viewHandle = $this->getDefaultViewHandle();
$this->setViewHandle( $viewHandle );
}
switch( $viewHandle ){
case VIEW_HANDLE_FORWARD:
$view =& $this->prepareView_Forward();
break;
case VIEW_HANDLE_ACTION_RESULT:
$view =& $this->prepareView_ActionResult();
break;
}
return $view;
}
function _checkActionAllowed( $action ){
if( ! $this->sm )
return 1;
$result = 0;
$actionString = "Action <B>$action</B>";
$errorString = "Sorry, this action is not allowed!";
if( $this->sm->isAllowed( $action ) )
$result = 1;
else
$this->addActionResult( $actionString, 1, $errorString );
return $result;
}
function prepareActions(){
$actions = array();
$actions[] = array( 'init', 'init', 0 );
$op = $this->_req->getParam( 'op' );
if( $op ){
if( method_exists($this, "action_$op") )
$actions[] = array( $op, 'action_' . $op, 1 );
else
echo "There's no handler for the <B>$op</B> action.";
}
reset( $actions );
return $actions;
}
function init(){
echo 'hcActionHandler::init(): to implement in child classes!';
}
function getDefaultViewHandle(){
$viewHandle = $this->_req->getStateParam( PARAM_VIEW_HANDLE );
return $viewHandle;
}
/*
* ACTION FUNCTIONS
*/
/*
* END OF ACTION FUNCTIONS
*/
/*
* PREPARATIONS FOR CONCRETE VIEWS
*/
function &prepareView_Forward(){
$view =& $this->vm->getViewObject_Forward( $this->_req, $this->_resp );
$this->_viewData['forwardTo'] = $this->getForward();
$view->setData( $this->_viewData );
return $view;
}
function &prepareView_ActionResult(){
$view =& $this->vm->getViewObject_ActionResult( $this->_req, $this->_resp );
$this->_viewData['actionResults'] = $this->getActionResults();
$returnLinks =& $this->getReturnLinks();
if( $returnLinks ){
// HANDLE MULTIPLE RETURN LINKS - NOTHING ELSE TO DO
}
else {
$returnURL = $this->_resp->generateUrl(
array(), // action
array( 'p' => null )
);
$returnLinks[] = array( 'url' => $returnURL, 'title' => M('actionResult/returnBack') );
}
$this->_viewData['returnLinks'] = $returnLinks;
$view->setData( $this->_viewData );
return $view;
}
/*
* END OF CONCRETE VIEWS
*/
/*
* MISC METHODS
*/
function _forwardBack(){
$forwardTo = $this->_resp->generateUrl();
$this->setForward( $forwardTo );
}
function addReturnLink( $title, $url ){
$array = array();
$array['url'] = $url;
$array['title'] = $title;
$this->returnLinks[] = $array;
}
function resetReturnLinks(){
$this->returnLinks = array();
}
function &getReturnLinks(){
return $this->returnLinks;
}
function addActionProcess( $actionWanted ){
// SHOW STATUS
$mm =& $this->_resp->getMessageManager();
$statusString = $actionWanted;
$mm->process( $statusString );
showStatus( $statusString );
}
function addActionResult( $actionWanted, $isError = 0, $msg = '' ){
$array = array();
$array['action'] = $actionWanted;
$array['is_error'] = $isError;
$array['msg'] = $msg;
$this->ar[] = $array;
$this->setViewHandle( VIEW_HANDLE_ACTION_RESULT );
}
function &getActionResults(){
return $this->ar;
}
function setForward( $forwardTo ){
$this->forward = $forwardTo;
$this->setViewHandle( VIEW_HANDLE_FORWARD );
}
function getForward(){
return $this->forward;
}
function setViewHandle( $viewHandle ){
$this->_viewHandle = $viewHandle;
}
function getViewHandle(){
return $this->_viewHandle;
}
function setViewManager( &$vm ){
$this->vm = $vm;
}
function setSecurityManager( &$sm ){
$this->sm = $sm;
}
/*
* END OF MISC METHODS
*/
}
?>
startFile : mwftp5/_hclib/hcGetURL.php : 1
<?
/**
* This class is for generating URLs with GET parameters
*/
class hcGetURL {
var $_param;
var $_stickyParam;
var $_target;
function hcGetURL(){
$this->_param = array();
$this->_stickyParam = array();
$this->_target = '';
}
function setTarget( $t ){
$this->_target = $t;
}
function setParam( $p, $v ){
if( $v )
$this->_param[ $p ] = $v;
else
unset($this->_param[ $p ]);
}
function setStickyParam( $p, $v ){
$this->_stickyParam[ $p ] = $v;
}
/**
* Note that after calling this method the _param array gets cleared
*/
function getLine(){
$line = '';
$count = 0;
reset( $this->_stickyParam );
reset( $this->_param );
$tempParamArray = array_merge( $this->_stickyParam, $this->_param );
foreach( $tempParamArray as $k => $v ){
if( $count )
$line .= '&';
$line .= $k . '=' . $v;
$count++;
}
if( $line ){
$line = $this->_target . '?' . $line;
}
else
$line = $this->_target;
// clear $this->_param array
$this->_param = array();
return $line;
}
// Singleton stuff
function &getInstance(){
return hcSingletonFunction( 'hcGetURL' );
}
}
?>
startFile : mwftp5/_hclib/hcHtmlElement.php : 1
<?
class hcHtmlElement {
var $_tag;
var $_style;
var $_id;
function hcHtmlElement( $elementTag ){
// STRIP STARTING AND ENDING >
$this->_tag = substr( $elementTag, 1, -1 );
$this->_style = null;
$this->_id = null;
}
function generateID(){
$this->setID( 'hhe' . getUniqueID() );
}
function getOpenTag(){
$tag = '<' . $this->_tag;
if( $this->_id )
$tag .= ' ID="' . $this->_id . '"';
if( $this->_style )
$tag .= ' STYLE="' . $this->_style . '"';
$tag .= '>';
return $tag;
}
function getCloseTag(){
$tag = '</' . $this->_tag . '>';
return $tag;
}
function setID( $id ){
$this->_id = $id;
}
function getID(){
return $this->_id;
}
function setStyle( $style ){
$this->_style = $style;
}
function view(){
$view = '';
$view .= $this->getOpenTag();
$view .= $this->getCloseTag();
return $view;
}
}
?>
startFile : mwftp5/_hclib/hcLibrary.php : 1
<?
function showStatus( $msg ){
static $divId = 0;
$previousDiv = 'status_' . $divId;
$divId++;
$myDivId = 'status_' . $divId;
if( ob_get_contents() ){
ob_end_flush();
ob_implicit_flush(1);
}
echo '<DIV CLASS="hcShowStatus" ID="' . $myDivId . '">' . $msg;
echo ' ... ';
echo '</DIV>';
echo "\n";
flush();
// artificial delay
// for( $i = 1; $i < 3000000; $i++ ){
// }
}
function cloneObject( &$object ){
if( preg_match("/^5\./", PHP_VERSION) ){
$code = '$return = clone $object;';
eval( $code );
}
else
$return = $object;
return $return;
}
function inArrayWithWildcards( $test, &$array ){
$return = false;
$reReplacesKeys = array( '.', '*', '?' );
$reReplacesValues = array( '\.', '(.*)', '.' );
reset( $array );
foreach( $array as $entry ){
$re = str_replace( $reReplacesKeys, $reReplacesValues, $entry );
$re = '^' . $re . '$';
$re = '/' . $re . '/';
if( preg_match( $re, $test ) ){
$return = true;
break;
}
}
return $return;
}
function cleanDir( $dirName, $deleteItself = 0 ){
if( ! (file_exists($dirName) && is_dir($dirName)) )
return true;
if ( $handle = opendir($dirName) ){
while ( false !== ($f = readdir($handle)) ){
if ($f != '.' && $f != '..') {
if( is_dir( $dirName . '/' . $f ) )
cleanDir( $dirName . '/' . $f, 1 );
else
unlink( $dirName . '/' . $f );
}
}
closedir($handle);
if( $deleteItself )
rmdir( $dirName );
}
}
function getFileResourcesDirectory( $fileName ){
$strippedFileName = basename( $fileName, '.php');
$strippedFileName = str_replace( '_init', '', $strippedFileName );
$dirName = $strippedFileName . '_files';
return $dirName;
}
function getUniqueID(){
static $id = 0;
$id++;
return $id;
}
function formatDate( $timestamp ){
$formattedDate = date( 'Y/m/d', $timestamp );
return $formattedDate;
}
function formatDateTime( $timestamp ){
$formattedDate = date( 'Y/m/d H:i', $timestamp );
return $formattedDate;
}
function formatSize( $size ){
$sizeInKB = $size / 1024;
$formattedSize = number_format( $sizeInKB, 1, '.', ' ' );
return $formattedSize;
}
function formatMode( $string ){
//$string looks like -rwxrwxrwx
$string = substr( $string, 1);
if( strlen($string) == 9 ){
$sw = array('r' => 4, 'w' => 2, 'x' => 1, '-' => 0);
$out = '';
for( $j = 0; $j < strlen($string)/3; $j++){
$temp_out = 0;
for($i = 0; $i < 3; $i++){
$temp_out += $sw[ substr($string, 3*$j + $i, 1) ];
}
$out .= $temp_out;
}
}
else {
$out = 'n/a';
}
return $out;
}
function getTranferModeString( $index ){
switch( $index ){
case FILE_MODE_ASCII:
$string = 'ascii';
break;
case FILE_MODE_BINARY:
$string = 'binary';
break;
default:
$string = 'unknown';
}
return $string;
}
function unhtmlentities( $string ){
// $trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = get_html_translation_table(HTML_SPECIALCHARS);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}
function applyFilter( &$array, $filter, $key = '' ){
$returnArray = array();
reset( $array );
$reReplacesKeys = array( '.', '*', '?' );
$reReplacesValues = array( '\.', '(.*)', '.' );
$re = str_replace( $reReplacesKeys, $reReplacesValues, $filter );
$re = '^' . $re . '$';
$re = '/' . $re . '/';
foreach( $array as $item ){
if( $key )
$test = $item[ $key ];
else
$test = $item;
if( preg_match( $re, $test ) ){
$returnArray[] = $item;
}
}
return $returnArray;
}
class hcFileHandle {
var $_fh;
var $_totalSize;
function hcFileHandle( &$fh ){
$this->_fh = $fh;
}
function fread( $bytes = 4024 ){
return fread( $this->_fh, $bytes );
}
function feof(){
return feof( $this->_fh );
}
function rewind(){
return rewind( $this->_fh );
}
function fclose(){
return fclose( $this->_fh );
}
function getTotalSize(){
return $this->_totalSize;
}
function setTotalSize( $totalSize ){
$this->_totalSize = $totalSize;
}
}
class hcFileGroup {
var $_fh;
var $_fileList;
var $_name;
var $_totalSize;
function &getFileList(){
return $this->_fileList;
}
function setFileList( &$fl ){
$this->_fileList = $fl;
}
function getFileHandle(){
return $this->_fh;
}
function setFileHandle( &$fh ){
$this->_fh = $fh;
}
function getName(){
return $this->_name;
}
function setName( $name ){
$this->_name = $name;
}
function getTotalSize(){
return $this->_totalSize;
}
function setTotalSize( $totalSize ){
$this->_totalSize = $totalSize;
}
}
function SendEmail($From, $FromName , $To, $Subject, $Text, $fname, &$fh, $debug = 0){
// $AttmFiles is array like array[0] = array(test.zip', $fh);
$OB = "----=_OuterBoundary_000";
$IB = "----=_InnerBoundary_001";
$Text;
$From or die("sender address missing");
$To or die("recipient address missing");
$headers = "MIME-Version: 1.0\n";
$headers .= "From: " . $FromName . " <" . $From . ">\n";
// $headers .= "To: " . $To . " <" . $To . ">\n";
$headers .= "Reply-To: " . $FromName . " <" . $From . ">\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: My PHP Mailer\n";
$headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n";
$Msg = '';
$Msg.="\n--".$OB."\n";
$Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";
//plaintext section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
// plaintext goes here
$Msg.=$Text."\n\n";
$Msg.="\n--".$IB."--\n";
// attachments
if($fname){
$Msg .= "\n--" . $OB . "\n";
$Msg .= "Content-Type: application/octetstream;\n\tname=\"" . $fname. "\"\n";
$Msg .= "Content-Transfer-Encoding: base64\n";
$Msg .= "Content-Disposition: attachment;\n\tfilename=\"" . $fname . "\"\n\n";
//file goes here
$FileContent = '';
while( ! $fh->feof() )
$FileContent .= $fh->fread();
$FileContent = chunk_split(base64_encode($FileContent));
$Msg .= $FileContent;
$Msg .= "\n\n";
}
//message ends
$Msg .= "\n--".$OB."--\n";
if( $debug ){
echo "To:<BR>$To<BR>";
echo "Subj:<BR>$Subject<BR>";
echo "Headers:<BR>$headers<BR>";
echo "Msg:<BR>$Msg<BR>";
}
else {
mail( $To, $Subject, $Msg, $headers );
}
}
// A generic function to create and fetch static objects
function &hcMySingletonFunction( $class ) {
// Declare a static variable to hold the object instance
static $instances;
// If the instance is not there, create one
if( ! isset($instances[$class]) ){
$instances[$class] = new $class;
}
return $instances[$class];
}
?>
startFile : mwftp5/_hclib/hcMessageManager.php : 1
<?
class hcMessageManager {
var $_filesDir = '';
var $_msg;
var $_lang;
var $_cookieName;
var $_paramName;
var $_allLanguages = array();
function hcMessageManager( $filesDir ){
$this->_cookieName = 'hcmmlanguage';
$this->_paramName = 'lang';
$this->_filesDir = $filesDir;
$this->initLanguages();
}
function init(){
$langCode = '';
// CHANGE LANGUAGE
if( isset($_GET[$this->_paramName]) ){
$suppliedCode = $_GET[$this->_paramName];
if( $this->languageExists( $suppliedCode ) ){
$langCode = $suppliedCode;
setcookie($this->_cookieName, $langCode, time() + 30 * 24 * 60 * 60); // Set cookie to remember for 30 days
}
}
if( ! $langCode ){
if( isset($_COOKIE[ $this->_cookieName ]) )
$langCode = $_COOKIE[ $this->_cookieName ];
else
$langCode = 'eng';
}
if( $this->languageExists( $langCode ) )
$this->setLanguage( $langCode );
}
function initLanguages(){
$suffix = '.php';
$files = getDirListing( $this->_filesDir );
reset( $files );
foreach( $files as $f ){
$l = substr( $f, 0, -strlen($suffix) );
$this->_allLanguages[] = $l;
}
}
function languageExists( $isoCode ){
return in_array( $isoCode, $this->_allLanguages );
}
function getLanguages(){
return $this->_allLanguages;
}
function getCurrentLanguage(){
return $this->_lang;
}
function setLanguage( $isoCode ){
$messageFile = $this->_filesDir . '/' . $isoCode . '.php';
include_once( $messageFile );
$this->_msg =& $msg;
$this->_lang = $isoCode;
}
function getCharset(){
$charset = 'iso-8859-1';
if( $this->_lang ){
if( isset($this->_msg['_info_/charset']) )
$charset = $this->_msg['_info_/charset'];
}
return $charset;
}
function get( $str ){
if( $this->_lang ){
if( isset( $this->_msg[ $str ] ) )
return $this->_msg[ $str ];
else {
// echo "notice: '$str' is not defined in the language manager.<BR>";
return $str;
}
}
else {
return $str;
}
}
/********************************************************************************************/
/* this function replaces {MESSAGE:some text} with 'some text' in the required language */
/********************************************************************************************/
function process( &$str ){
$tagStarts = array('<message>', htmlspecialchars('<message>') );
$tagEnds = array('</message>', htmlspecialchars('</message>') );
$count = count( $tagStarts );
for( $i = 0; $i < $count; $i++ ){
$tagStart = $tagStarts[$i]; $tagEnd = $tagEnds[$i];
$re = '/' . preg_quote($tagStart, "/") . '(.+)' . preg_quote($tagEnd, "/") . '/U';
preg_match_all( $re, $str, $m );
if( isset($m[1]) ){
reset( $m[1] );
foreach( $m[1] as $msg ){
// PARSE PARAMS
$toReplace = $tagStart . $msg . $tagEnd;
$msg = unhtmlentities( $msg );
$suppliedParams = $this->getSuppliedParams( $msg );
if( $suppliedParams ){
$msg = $this->removeParams( $msg );
}
$replaceWith = $this->get( $msg );
if( $suppliedParams ){
$replaceWith = str_replace( array_keys($suppliedParams), array_values($suppliedParams), $replaceWith );
}
$str = str_replace( $toReplace, $replaceWith, $str );
}
}
}
}
function getSuppliedParams( $str ){
$result = array();
$paramStart = '<param>';
$paramEnd = '</param>';
$paramNameStart = preg_quote('<name>', "/");
$paramNameEnd = preg_quote('</name>', "/");
$paramValueStart = preg_quote('<value>', "/");
$paramValueEnd = preg_quote('</value>', "/");
$re = '/' . preg_quote($paramStart, "/") . '(.+)' . preg_quote($paramEnd, "/") . '/U';
preg_match_all( $re, $str, $m );
if( isset($m[1]) ){
reset( $m[1] );
foreach( $m[1] as $msg ){
$reName = '/' . $paramNameStart . '(.+)' . $paramNameEnd . '/U';
preg_match( $reName, $msg, $innerM1 );
$name = $innerM1[1];
$name = $paramStart . $name . $paramEnd;
$reValue = '/' . $paramValueStart . '(.*)' . $paramValueEnd . '/U';
preg_match( $reValue, $msg, $innerM2 );
$value = $innerM2[1];
$result[ $name ] = $value;
}
}
return $result;
}
function removeParams( $str ){
$paramStart = preg_quote('<param>', "/");
$paramEnd = preg_quote('</param>', "/");
$re = '/' . $paramStart . '.+' . $paramEnd . '/';
$str = preg_replace( $re, '', $str );
return $str;
}
}
function M( $msg, $params = array() ){
$tagStart = '<message>';
$tagEnd = '</message>';
if( $params ){
reset( $params );
foreach( $params as $name => $value ){
$msg .= '<param><name>' . $name . '</name><value>' . $value . '</value></param>';
}
}
return $tagStart . $msg . $tagEnd;
}
?>
startFile : mwftp5/_hclib/hcPager.php : 1
<?
//include_once( 'hcQueryLimit.php' );
//class hcPager extends hcQueryLimit {
class hcPager {
var $_page;
var $_ps;
var $_ps_options;
var $_confFile;
var $_shownPages;
var $_count;
var $_offset;
function hcPager( $offset = 0, $pageSize = 5, $shownPages = 10 ){
$this->reset();
$this->setCount( $offset );
$this->setPagesize( $pageSize );
$this->setPagesizeOptions( array() );
$this->setShownPages( $shownPages );
// parent::hcQueryLimit( $this->getOffset(), $this->getPagesize() );
$this->_init();
}
function setCount( $c = 0 ){
$this->_count = $c;
}
function reset(){
$this->_page = 1;
}
function getDefaultPage(){
return 1;
}
function conf(){
include( $this->_confFile );
// initialize
$this->setParamName( $_pagerConf['name'] );
$this->setPagesize( $_pagerConf['pagesize'] );
if( isset($_pagerConf['pagesize_options']) )
$this->setPagesizeOptions( $_pagerConf['pagesize_options'] );
}
function setConfFile( $confFile ){
$this->_confFile = $confFile;
}
// USED IN BUILDING QUERIES - REDEFINES THE ONE IN hcQueryLimit
function getOffset(){
return $this->getPagesize() * ($this->getPage() - 1);
}
function getPagesize(){
return $this->_ps;
}
function setPagesize( $ps ){
$this->_ps = $ps;
}
function setPagesizeOptions( $array ){
$this->_ps_options = $array;
}
function getPagesizeOptions(){
return $this->_ps_options;
}
function getShownPages(){
return $this->_shownPages;
}
function setShownPages( $shownPages ){
$this->_shownPages = $shownPages;
}
function _init(){
}
function getPage(){
return $this->_page;
}
function setPage( $p ){
if( ($p > $this->getNumPages()) || ($p <= 0) )
$p = 1;
$this->_page = $p;
}
function getNumPages(){
if( ($this->_ps == 0) || ($this->_count == 0) )
$pagesCount = 1;
else
$pagesCount = ceil( $this->_count / (float)$this->_ps );
return $pagesCount;
}
function process( &$arr ){
$this->setCount( count($arr) );
// $this->setPage( $this->getPage() );
if( $this->_ps ){
$start = ($this->getPage() - 1) * $this->_ps;
$arr = array_slice( $arr, $start, $this->_ps );
}
}
function getSQLString(){
$start = ($this->getPage() - 1) * $this->_ps;
$limitString = $start . ', ' . $this->_ps;
return $limitString;
}
function &getPagesOld(){
$pages = array();
// SETTING PAGES ARRAY
for( $pn = 1; $pn <= $this->getNumPages(); $pn++ ){
$pages[] = array(
'pn' => $pn,
'title' => $pn
);
}
return $pages;
}
function &getPages(){
$pages = array();
// SETTING PAGES ARRAY
$thisNumPages = $this->getNumPages();
$shownPages = $this->getShownPages();
$currentPage = $this->getPage();
if( $thisNumPages < $shownPages ){
for( $pn = 1; $pn <= $this->getNumPages(); $pn++ ){
$pages[] = array(
'pn' => $pn,
'title' => $pn
);
}
}
else {
$slotsNumber = ceil( $thisNumPages / (float)$shownPages );
$currentSlot = ceil( $currentPage / (float)$shownPages );
// ADD FIRST PAGE LINK
if( $currentSlot > 2 ){
$pages[] = array(
'pn' => 1,
'title' => 1,
);
}
// ADD PREVIOUS SLOT LINK
if( $currentSlot > 1 ){
$prevSlotStart = 1 + ($currentSlot - 2) * $shownPages;
$prevSlotEnd = ($currentSlot - 1) * $shownPages;
$prevSlotTitle = $prevSlotStart . '-' . $prevSlotEnd;
$pages[] = array(
'pn' => $prevSlotEnd,
'title' => $prevSlotTitle
);
}
// ADD CURRENT SLOT LINKS
for( $i = 1; $i <= $shownPages; $i++ ){
$pn = $i + ($currentSlot - 1) * $shownPages;
if( $pn > $thisNumPages )
break;
$pages[] = array(
'pn' => $pn,
'title' => $pn
);
}
// ADD NEXT SLOT LINK
if( $currentSlot < $slotsNumber ){
$nextSlotStart = 1 + $currentSlot * $shownPages;
$nextSlotEnd = ($currentSlot + 1) * $shownPages;
if( $nextSlotEnd > $thisNumPages )
$nextSlotEnd = $thisNumPages;
$nextSlotTitle = $nextSlotStart . '-' . $nextSlotEnd;
$pages[] = array(
'pn' => $nextSlotStart,
'title' => $nextSlotTitle
);
}
// ADD LAST PAGE LINK
if( $currentSlot < ($slotsNumber - 1) ){
$pages[] = array(
'pn' => $thisNumPages,
'title' => $thisNumPages,
);
}
}
return $pages;
}
}
?>
startFile : mwftp5/_hclib/hcPagerStateBased.php : 1
<?
include_once( 'hcPager.php' );
class hcPagerStateBased extends hcPager {
var $_paramName;
var $_pagesizeParamName;
function hcPagerStateBased(){
parent::hcPager();
}
function getParamName(){
// name used in HTML forms
return $this->_paramName;
}
function getPagesizeParamName(){
return $this->_pagesizeParamName;
}
function setParamName( $name ){
// name used in HTML forms
$this->_paramName = $name;
$this->_pagesizeParamName = $name . '_ps';
}
function init( &$req, &$resp ){
$this->reset();
if( $req->getStateParam( $this->getParamName() ) ){
$this->setPage( $req->getStateParam( $this->getParamName() ) );
}
$requestedPagesize = $req->getStateParam( $this->getPagesizeParamName() );
if( strlen($requestedPagesize) > 0 ){
$this->setPagesize( $requestedPagesize );
}
if( $this->getPage() == 1 )
$resp->resetStateParam( $this->getParamName() );
else
$resp->setStateParam( $this->getParamName(), $this->getPage() );
}
function resetState( &$req, &$resp ){
$req->resetStateParam( $this->getParamName() );
$resp->resetStateParam( $this->getParamName() );
}
}
?>
startFile : mwftp5/_hclib/hcPatterns.php : 1
<?
class hcPatterns {
/**
* private
* holds the object children for the COMPOSITE pattern
*/
var $_children;
var $_children_count;
var $_children_index;
var $_parent;
var $_container;
var $_pathComponents;
/**
* Constructor
*/
function hcPatterns(){
$this->_children = array();
$this->_children_index = 0;
$this->_children_count = 0;
$this->_parent = null;
$this->_observers = array();
$this->_pathComponents = array();
}
/**
* Register a child
* @return children count, i.e. the next id
*/
function addChild( &$child, $skipSetContainer = 0 ){
$this->_children[] = $child;
$this->_children_count++;
// $child->setParent( $this );
if( ( ! $skipSetContainer ) && method_exists( $child, 'setContainer' ) )
$child->setContainer( $this );
return $this->_children_count;
}
function clearChildren(){
$this->_children = array();
$this->resetChildren();
$this->setChildrenCount();
}
function &getChildrenArray(){
return $this->_children;
}
function setChildrenArray( &$array ){
$this->_children =& $array;
}
function sliceChildren( $offset, $count ){
$this->_children =& array_slice( $this->_children, $offset, $count );
// now reset the child count and index
$this->setChildrenCount();
$this->setChildrenIndex(0);
}
function getChildrenCount(){
return count( $this->_children );
}
function setChildrenIndex( $i = 0 ){
$this->_children_index = $i;
}
function setChildrenCount(){
$this->_children_count = count( $this->_children );
}
/**
* Sort children by supplied sorting object
* @return void
*/
function processChildren( &$processObject ){
$processObject->process( $this->_children );
// now reset the child count and index
$this->setChildrenCount();
$this->setChildrenIndex(0);
}
function resetChildren(){
$this->_children_index = 0;
// reset($this->_children );
}
/**
* Fetch a child
* @return void
*/
function fetchChild(){
if( $this->_children_index < $this->_children_count ){
$ret = $this->_children[ $this->_children_index ];
$this->_children_index++;
}
else
$ret = false;
return $ret;
}
/**
* Removes a child
* @return void
*/
function removeChild( &$child ){
$i = 0;
foreach( $this->_children as $c ){
if( $c == $child ){//remove this one
$this->_children[$i]->unsetParent();
unset( $this->_children[$i] );
$this->_children_count--;
break;
}
$i++;
}
}
function viewChild( &$child ){
$thisView = '';
// object
if( is_object($child) ){
if( method_exists( $child, 'view' ) ){
$thisView = $child->view();
}
}
// array of strings
else if( is_array($child) ){
foreach( $child as $c )
$thisView .= $this->viewChild( $c );
}
// just a string
else {
$thisView = $child;
}
return $thisView;
}
/**
* When a child is added we also register the container for it
* @return void
*/
function setContainer( &$cont ){
$this->_container =& $cont;
}
function &getContainer(){
return $this->_container;
}
/**
* When a child is added we also register parent for it
* @return void
*/
function setParent( &$parent ){
$this->_parent =& $parent;
}
function unsetParent( &$parent ){
unset($this->_parent);
}
function &getParent(){
return $this->_parent;
}
/**
* Return an array of objects up to root starting from the object itself
*/
function &getPathComponents(){
if( ! $this->_pathComponents ){
$this->_pathComponents = array( &$this );
if( $p =& $this->getParent() ){
$this->_pathComponents = array_merge( $this->_pathComponents, $p->getPathComponents() );
}
}
return $this->_pathComponents;
}
function resetPathComponents(){
$this->_pathComponents = array();
}
function getPathString(){
global $CONF;
$path = '';
// starts from root to myself
$pathComponents =& $this->getPathComponents();
$pathCount = count($pathComponents);
for( $i = $pathCount - 1; $i >= 0; $i-- ){
$p =& $pathComponents[$i];
$path .= $p->getTitle();
if( $i )
$path .= $CONF['GEN_PATH_SEP'];
}
return $path;
}
/**
* Observable stuff
*
* Observable
*/
/**
* Adds an observer
* @return void
*/
function addObserver( &$observer ){
$this->_observers[] =& $observer;
}
/**
* Notifies observers
* @return void
*/
function notifyObservers( $reason = '', $params = array() ){
$count = count( $this->_observers );
for( $i = 0; $i < $count; $i++ )
$this->_observers[$i]->update( $this, $reason, $params );
}
/**
* Observer
*
* Updates observer
* @return void
*/
function update( &$obj, $reason, $params = array() ){
// do some stuff here
}
}
startFile : mwftp5/_hclib/hcPersistentArray.php : 1
<?
class hcPersistentArray {
var $_fileName;
function hcPersistentArray( $fileName ){
$this->_fileName = $fileName;
}
function _load(){
$returnArray = array();
if( file_exists( $this->_fileName ) ){
include_once( $this->_fileName );
if( isset($_hcpa) && is_array($_hcpa) ){
foreach( $_hcpa as $k => $v )
$returnArray[ $k ] = $v;
}
}
return $returnArray;
}
function _save( $array ){
$return = 0;
reset( $array );
$code = "<?\n";
foreach( $array as $k => $v ){
$code .= "\$_hcpa[\"$k\"] = \"$v\";\n";
}
$code .= "?>";
$file = new mwFile( $this->_fileName );
if( ! $file->open( 'w' ) ){
return $return;
}
if( ! $file->set_content( $code ) ){
return $return;
}
if( ! $file->close() ){
return $return;
}
$return = 1;
return $return;
}
}
?>
startFile : mwftp5/_hclib/hcRequestResponse.php : 1
<?
/**
* This class implements getting request and response stuff for HTML views
*/
include_once( 'hcGetURL.php' );
class hcRequest extends hcReqRespBase {
var $_handlers;
function hcRequest( $skipPost = 0 ){
parent::hcReqRespBase();
if( ! $skipPost )
$this->getPost();
$this->_handlers = array();
}
/*
* THESE ARE HANDLING FUNCTIONS
*/
function getHandlerFiles(){
$handlerID =$this->getHandler();
if( ! $handlerID )
$handlerID = $this->getDefaultHandler();
$files = $this->getHandlerFilesByID( $handlerID );
if( ! is_array($files) )
$files = array( $files );
reset( $files );
return $files;
}
function getDefaultHandlerID(){
if( isset($this->_defaultHandler) ){
$defaultHandlerID = $this->_defaultHandler;
}
elseif( count($this->_handlers) == 1 ){
$keys = array_keys($this->_handlers);
$defaultHandlerID = $keys[0];
}
else
die( 'Cannot get the default handler ID!' );
return $defaultHandlerID;
}
// RETURNS HANDLER ID
function addHandler( $handlerFile, $default = 0 ){
static $handlerID = 0;
$handlerID++;
$this->_handlers[ $handlerID ] = $handlerFile;
if( $default || count($this->_handlers) == 0 ){
$this->setDefaultHandler( $handlerID );
}
return $handlerID;
}
function getHandlerFilesByID( $handlerID ){
if( isset($this->_handlers[ $handlerID ] ) )
return $this->_handlers[ $handlerID ];
}
function _getRequestParam( $p ){
if( isset($_REQUEST[$p]) )
$this->setParam( $p, $_REQUEST[$p] );
}
function _getRequestParams(){
reset($_REQUEST);
foreach( array_keys($_REQUEST) as $p ){
$this->setParam( $p, $_REQUEST[$p] );
}
}
function resetParams(){
$this->_param = array();
}
function isParamSubmitted( $p ){
return isset($this->_param[$p]);
}
function _initStateParams(){
$result = array();
// find if we have POST
if( isset($_POST[$this->_httpStateName]) ){
$v = $_POST[ $this->_httpStateName ];
$result = $this->parseAction( $v );
}
// find if we have GET
elseif( isset($_GET[$this->_httpStateName]) ){
$v = $_GET[ $this->_httpStateName ];
$result = $this->parseAction( $v );
}
while( list($k, $v) = each($result) ){
$this->setStateParam( $k, $v );
}
// NOW GET HANDLER
if( isset($_REQUEST[$this->_httpHandlerName]) ){
$handler = $_REQUEST[ $this->_httpHandlerName ];
$this->setHandler( $handler );
}
}
function getPost(){
// at first get some GET & POST vars
$this->_getRequestParams();
$this->_initStateParams();
// now get mwa_ stuff
// lazy stuff, already have code with this vars
$button_start = $this->_httpButtonStart;
$select_start = $this->_httpSelectStart;
$hidden_start = $this->_httpHiddenStart;
$related_start = $this->_httpRelatedStart;
$btn_note_start = $this->_httpButtonNoteStart;
$get_name = $this->_httpActionName;
reset($_POST);
reset($_GET);
$found = 0;
$result = array();
// find one POST variable
if( isset( $_POST[ $get_name ] ) ){
$v = $_POST[ $get_name ];
$result = $this->parseAction( $v );
}
// find if we have POST
foreach( array_keys($_POST) as $var ){
// got a button clicked
if( substr($var, 0, strlen($button_start) ) == $button_start ){
$hidden_name = substr( $var, strlen($button_start) );
// GET HIDDEN FIELD
if( isset($_POST[ $hidden_start.$hidden_name ]) ){
$v = $_POST[ $hidden_start.$hidden_name ];
$thisResult = $this->parseAction( $v );
if( isset($thisResult['hasNote']) && $thisResult['hasNote'] ){
// GET NOTE
$noteName = $btn_note_start.$hidden_name;
if( isset($_POST[$noteName]) ){
$noteValue = $_POST[$noteName];
$thisResult['actionNote'] = $noteValue;
}
unset($thisResult['hasNote']);
}
// GET RELATED ITEMS
$relatedResult = array();
$related_name = substr( $var, strlen($related_start) );
if( isset($_POST[ $related_start.$related_name ]) ){
$related = $_POST[ $related_start.$related_name ];
$relatedControls = $this->parseAction( $related );
foreach( $relatedControls as $ctlHandle => $ctlName ){
if( isset($_POST[$ctlName]) )
$relatedResult[ $ctlHandle ] = $_POST[$ctlName];
}
}
$result = array_merge( $result, $thisResult, $relatedResult );
$found = 1;
break;
}
}
if( substr($var, 0, strlen($button_start) ) == $select_start ){ // got a SELECT input
$v = $_POST[ $var ];
if( $v ){
$result = $this->parseAction( $v );
$found = 1;
break;
}
}
}
if( ! $found){ // not found a button clicked, probably GET method
if( isset( $_GET[ $get_name ] ) ){
$v = $_GET[ $get_name ];
$result = $this->parseAction( $v );
}
}
reset($_POST);
reset($_GET);
//returns stuff like $result['action']='approve', $result['id']=12,
while( list($k, $v) = each($result) ){
$this->setParam( $k, $v );
}
}
/**
* this function searches for a list of selected checkboxes sharing a name of the same pattern (currently only starting)
* for example broken_12, broken_22 etc.
* return array of name remainders, i.e. if you specify $pattern = broken_ then it returns (12, 24) etc
**/
function getSelectedArray( $start ){
$founds = array();
reset( $_POST );
foreach( $_POST as $k => $v ){
if( substr($k, 0, strlen($start) ) == $start ){ // MATCHES
$founds[] = substr( $k, strlen($start) );
}
}
return $founds;
}
function parseAction( $line ){
$result = array();
//parsing action string, it looks like "action:view__id:12"
if($line){
$parts1 = explode( $this->sep1, $line );
$num_parts = count($parts1);
for($i = 0; $i < $num_parts; $i++){
$parts2 = explode( $this->sep2, $parts1[$i], 2 );
if( $parts2[0] ){
$value = str_replace( $this->sep1_replace, $this->sep1, $parts2[1] );
$result["$parts2[0]"] = $value;
}
}
}
//returns stuff like $result['action']='view', $result['id']=12,
return $result;
}
}
class hcResponse extends hcReqRespBase {
var $_actionParams;
var $_target;
var $_buttonsConf;
var $_mm;
function hcResponse( $request = null ){
parent::hcReqRespBase();
$this->_actionParams = array();
$this->_handler = null;
$this->_mm = null;
if( $request ){
$this->_initStateParams( $request );
}
}
function setMessageManager( &$mm ){
$this->_mm = $mm;
}
function &getMessageManager(){
return $this->_mm;
}
function currentUrl(){
if( ! isset($_SERVER['REQUEST_URI']) ){
$arr = explode("/", $_SERVER['PHP_SELF']);
$_SERVER['REQUEST_URI'] = '/' . $arr[count($arr)-1];
if( $_SERVER['argv'][0] != '' )
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['argv'][0];
}
$currentUrl = $_SERVER['REQUEST_URI'];
return $currentUrl;
}
function setTarget( $t ){
$this->_target = $t;
}
function getTarget(){
if( isset($this->_target) )
return $this->_target;
else
return '';
}
function _initStateParams( &$req ){
$stateParams = $req->getStateParams();
foreach( $stateParams as $p => $v ){
$this->setStateParam( $p, $v );
}
$this->setHandler( $req->getHandler() );
$this->setDefaultHandler( $req->getDefaultHandler() );
}
function generatePersistentFields(){
$string = '';
if( $this->_stateParams )
$string = '<INPUT TYPE="hidden" NAME="' . $this->_httpStateName . '" VALUE="' . $this->buildActionString($this->_stateParams) . '">';
if( $this->_actionParams )
$string .= '<INPUT TYPE="hidden" NAME="' . $this->_httpActionName . '" VALUE="' . $this->buildActionString($this->_actionParams) . '">';
$handler = $this->getHandler();
if( $handler && $handler != $this->getDefaultHandler() )
$string .= '<INPUT TYPE="hidden" NAME="' . $this->_httpHandlerName . '" VALUE="' . $handler . '">';
return $string;
}
function generateNewUrl( $stateParams = array(), $actionParams = array(), $handler = '' ){
$url = new hcGetURL();
$url->setTarget( $this->getTarget() );
$url->setParam( $this->_httpActionName, $this->buildActionString($actionParams) );
$url->setParam( $this->_httpStateName, $this->buildActionString($stateParams) );
if( ! $handler )
$handler = $this->getHandler();
if( $handler && $handler != $this->getDefaultHandler() )
$url->setParam( $this->_httpHandlerName, $handler );
$urlLine = $url->getLine();
return $urlLine;
}
function generateUrl( $actionParams2Change = array(), $stateParams2Change = array(), $handler = '' ){
$url = new hcGetURL();
$url->setTarget( $this->getTarget() );
$stateParams = array_merge( $this->_stateParams, $stateParams2Change );
$actionParams = array_merge( $this->_actionParams, $actionParams2Change );
$url->setParam( $this->_httpActionName, urlencode($this->buildActionString($actionParams)) );
$url->setParam( $this->_httpStateName, urlencode($this->buildActionString($stateParams)) );
if( ! $handler )
$handler = $this->getHandler();
if( $handler && $handler != $this->getDefaultHandler() )
$url->setParam( $this->_httpHandlerName, $handler );
return $url->getLine();
}
function &getStateUrl( $stateParams2Change = array() ){
$url = new hcGetURL();
$url->setTarget( $this->getTarget() );
$stateParams = array_merge( $this->_stateParams, $stateParams2Change );
$url->setParam( $this->_httpStateName, $this->buildActionString($stateParams) );
return $url;
}
function setActionParam( $p, $v ){
$this->_actionParams[ $p ] = $v;
}
function getActionParam( $p ){
if( isset($this->_actionParams[$p]) )
return $this->_actionParams[$p];
else
return;
}
function resetActionParams(){
$this->_actionParams = array();
}
function resetStateParams( $args = array() ){
reset($this->_stateParams);
if( isset($args['skip']) ){
foreach( $this->_stateParams as $k => $v ){
if( ! in_array($k, $args['skip']) )
unset($this->_stateParams[$k]);
}
}
else {
$this->_stateParams = array();
}
}
/**
* This method generates the line with action and properties encoded.
* Usually we use it in GET URLs.
*/
function buildActionString( $array ){
$line = '';
$count = 0;
foreach( $array as $k => $v ){
if( ($v != '') || ($v != null) || ( (is_int($v) && $v==0) ) ){
if( $count )
$line .= $this->sep1;
$v = str_replace( $this->sep1, $this->sep1_replace, $v );
$v = str_replace( $this->sep2, $this->sep2_replace, $v );
$line .= $k . $this->sep2 . $v;
$count++;
}
else {
}
}
return $line;
}
}
class hcRequestStaticHTML extends hcRequest {
function hcRequestStaticHTML(){
parent::hcRequest( 1 );
}
}
class hcResponseStaticHTML extends hcResponse {
function hcResponseStaticHTML(){
parent::hcResponse( 1 );
$this->sep1 = '_'; // SEPARATORS TO BE USED IN FILENAME ENCODING
$this->sep2 = '-';
}
function getHTMLPageName( $stateParams2Change = array() ){
$pageName = 'index';
$stateParams = array_merge( $this->_stateParams, $stateParams2Change );
$line = '';
if( $stateParams ){
$count = 0;
foreach( $stateParams as $k => $v ){
if( ($v != '') || ($v != null) ){
if( $count )
$line .= $this->sep1;
$line .= $k . $this->sep2 . $v;
$count++;
}
}
if( $line )
$line = '_' . $line;
}
$pageName = $pageName . $line . '.' . STATIC_PAGES_TYPE;
return $pageName;
}
}
class hcReqRespBase {
var $sep1;
var $sep2;
var $_param;
var $_stateParams;
var $_httpButtonStart;
var $_httpSelectStart;
var $_httpHiddenStart;
var $_httpRelatedStart;
var $_httpHandlerName;
var $_httpActionName;
var $_httpStateName;
var $_handler;
var $_defaultHandler;
function hcReqRespBase(){
$this->sep1 = '__';
$this->sep2 = ':';
$this->sep1_replace = '_*_*';
$this->sep2_replace = ':';
// now mwa_ stuff
$this->_httpButtonStart = 'mwb_';
$this->_httpButtonNoteStart = 'mwbnote_';
$this->_httpSelectStart = 'mws_';
$this->_httpHiddenStart = 'mwa_';
$this->_httpRelatedStart = 'mwr_';
$this->_httpActionName = 'mwa';
$this->_httpStateName = 'mwst';
$this->_httpHandlerName = 'mwh';
$this->_param = array();
$this->_stateParams = array();
$this->_handler = null;
$this->_defaultHandler = null;
}
function getParam( $p ){
if( isset($this->_param[ $p ]) )
return $this->_param[ $p ];
else
return;
}
function setParam( $p, $v ){
// echo "<BR>setting $p to " . print_r($v);
$noTranslateString = 'notranslate';
if( is_string($v) ){
if( get_magic_quotes_gpc() )
$v = stripslashes( $v );
$controlEnd = substr( $p, strlen($noTranslateString) + 2, strlen($noTranslateString) );
if( $controlEnd != $noTranslateString )
$v = unhtmlentities( $v );
}
$this->_param[ $p ] =& $v;
}
function unsetParam( $p ){
unset($this->_param[ $p ]);
}
function setStateParam( $p, $v ){
if( is_string($v) ){
if( get_magic_quotes_gpc() )
$v = stripslashes( $v );
$v = unhtmlentities( $v );
}
$this->_stateParams[ $p ] = $v;
}
function getStateParam( $p ){
if( isset($this->_stateParams[$p]) )
return $this->_stateParams[$p];
else
return;
}
function resetStateParam( $param ){
unset( $this->_stateParams[$param] );
}
function getStateParams(){
$a = array();
reset( $this->_stateParams );
foreach( $this->_stateParams as $k => $v ){
$a[ $k ] = $v;
}
return $a;
}
function getHandler(){
return $this->_handler;
}
function setHandler( $h ){
$this->_handler = $h;
}
function getDefaultHandler(){
if( ! $this->_defaultHandler )
die( 'Do not have the default handler set!' );
return $this->_defaultHandler;
}
function setDefaultHandler( $h ){
$this->_defaultHandler = $h;
}
}
?>
startFile : mwftp5/_hclib/hcSecurityManager.php : 1
<?
class hcSecurityManager {
var $_actions;
function hcSecurityManager(){
}
function setActions( $actionsArray ){
reset( $actionsArray );
foreach( $actionsArray as $action ){
if( ! $this->isActionDefined( $action ) ){
$this->defineAction( $action );
$this->actionAllow( $action );
}
}
}
function defineAction( $action ){
$this->_actions[ $action ] = 0;
}
function getAll(){
reset( $this->_actions );
return $this->_actions;
}
function listAllowedActions( $dirName = '', $userName = '' ){
$allowedActions = array();
reset( $this->_actions );
foreach( $this->_actions as $a => $k ){
if( $this->isAllowed( $a, $dirName, $userName ) )
$allowedActions[] = $a;
}
return $allowedActions;
}
function isAllowed( $action, $dirName = '', $userName = '' ){
// implement in child classes
return 1;
}
function actionAllow( $action, $userName = '' ){
$this->_actions[ $action ] = 1;
}
function actionDeny( $action, $userName = '' ){
$this->_actions[ $action ] = 0;
}
function isActionDefined( $action ){
return isset( $this->_actions[ $action ] );
}
}
?>
startFile : mwftp5/_hclib/hcSession.php : 1
<?
include_once('mwSessionFile.php');
define( 'SESSION_HANDLE', 'sid' );
class hcSession {
var $_req;
var $_resp;
var $_se; //SESSION ENGINE
var $_data; //SESSION DATA
var $_enc; // ENCRYPT OR NOT
var $_expireTime;
var $_sessionDir;
var $_errorMsg;
function hcSession( &$req, &$resp, $expireTime = 300, $sessionDir = './sessions' ){
$this->_req =& $req;
$this->_resp =& $resp;
$this->_enc = 1;
$this->_expireTime = $expireTime;
$this->_sessionDir = $sessionDir;
$this->_errorMsg = '';
}
function setErrorMsg( $msg ){
$this->_errorMsg = $msg;
}
function getErrorMsg(){
return $this->_errorMsg;
}
function start(){
$sid = $this->_req->getStateParam( SESSION_HANDLE );
if( ! $sid ){
$this->setErrorMsg( 'No session id given' );
return 0;
}
$this->_se = new mwSessionFile( $this->_sessionDir, $sid, $this->_expireTime );
$this->_se->_enc = $this->_enc;
if( $this->_se->err ){
$this->setErrorMsg( $this->_se->err );
return 0;
}
if( !( $d = $this->_se->get_data()) ){
$this->setErrorMsg( 'Cannot load the session data' );
return 0;
}
$this->_data = $d;
$this->_resp->setStateParam( SESSION_HANDLE, $sid );
return 1;
}
function startNew( $sdata = array() ){
$this->_se = new mwSessionFile( $this->_sessionDir, 0, $this->_expireTime );
$this->_se->_enc = $this->_enc;
if( $this->_se->err )
return 0;
if( ! $this->setData($sdata) )
return 0;
$sid = $this->_se->sid();
$this->_resp->setStateParam( SESSION_HANDLE, $sid );
return $sid;
}
function setData( $sdata = array() ){
if( ! $this->_se->set_data( $sdata ) )
return 0;
$this->_data = $sdata;
return 1;
}
function getData(){
return $this->_data;
}
function destroy(){
$this->_se->destroy();
$this->_resp->resetStateParam( SESSION_HANDLE );
}
function getDetailedErrorMessage( $returnUrl ){
echo $this->getErrorMsg();
echo "<BR><A HREF='$returnUrl'>home page</A>";
}
function getTempDirName(){
return $this->_se->get_dirname();
}
// Singleton stuff
function &getInstance(){
return hcMySingletonFunction( 'hcSession' );
}
}
?>
startFile : mwftp5/_hclib/hcSorter.php : 1
<?
class hcSorter {
var $_paramName;
var $_matrix;
var $_selected;
var $_defaultSelection;
var $_index;
var $_view;
var $_confFile;
var $_preSort;
var $_resp;
function hcSorter(){
// object properties on which to sort are stored here
$this->_matrix = array();
$this->_view = array();
$this->_preSort = array();
$this->_resp = null;
$this->_paramName = '';
// 1 means selected the 0th criterion asc, 2 - 0th desc, 3 - 1st asc etc
// $this->setSelection( 0 );
}
function conf(){
include_once( $this->_confFile );
// populating
while( list($sorterPname, $propArray) = each($_sorterConf['criteria']) ){
$this->addSortingProp(
$sorterPname,
$propArray[0],
$propArray[1]
);
}
// populating preSort
if( isset($_sorterConf['preSort']) ){
while( list($sorterPname, $propArray) = each($_sorterConf['preSort']) ){
$this->addPreSort(
$sorterPname,
$propArray[0],
$propArray[1]
);
}
}
// initialize
$this->setParamName( $_sorterConf['name'] );
$this->setSelection( $_sorterConf['default'] );
$this->setDefaultSelection( $_sorterConf['default'] );
}
function init( &$req, &$resp ){
$this->reset();
if( $req->getStateParam( $this->getParamName() ) ){
$this->setSelection( $req->getStateParam( $this->getParamName() ) );
}
if( $this->getSelection() != $this->getDefaultSelection() )
$resp->setStateParam( $this->getParamName(), $this->getSelection() );
$this->_resp = $resp;
}
function setConfFile( $confFile ){
$this->_confFile = $confFile;
}
function getParamName(){
// name used in HTML forms
return $this->_paramName;
}
function setParamName( $name ){
// name used in HTML forms
$this->_paramName = $name;
}
function getNumSortings(){
return count( $this->_matrix );
}
function getSortingProp( $id ){
return $this->_matrix[$id];
}
function getSortingPropTitle( $id ){
return $this->_matrix[$id]['plabel'];
}
function addSortingProp( $pname, $plabel, $type = 'int', $whereType = 'db' ){
$newAddition = array(
'pname' => $pname,
'plabel' => $plabel,
'type' => $type, // 'int' or 'string'
'whereType' => $whereType, // 'db' or 'memory'
);
$this->_matrix[] = $newAddition;
}
function addPreSort( $pname, $sOrder, $type = 'int' ){
$this->_preSort[] = array( $pname, $sOrder, $type );
}
function setSelection( $s ){
if( $this->getNumSortings() == 0 ){
$this->_selected = 0;
}
else {
if ( $s > 2 * $this->getNumSortings() or $s <= 0)
$s = 1;
$this->_selected = $s;
}
}
function getSelection(){
return $this->_selected;
}
function setDefaultSelection( $s ){
$this->_defaultSelection = $s;
}
function getDefaultSelection(){
return $this->_defaultSelection;
}
function reset(){
if( $this->getDefaultSelection() )
$this->setDefaultSelection( $this->getDefaultSelection() );
}
function getIndex(){
$selection = $this->getSelection();
$index = floor( ($selection - 1) / 2 );
return $index;
}
function getSortingValueAsc( $index ){
return 2 * $index + 1;
}
function getSortingValueDesc( $index ){
return 2 * $index + 2;
}
// returns 0 if not selected, 1 if selected ASC, 2 if selected DESC
function getSelectionStatus( $sortIndex ){
$selected = $this->getSelection();
if( $selected == 2* $sortIndex + 1 )
return 1;
elseif( $selected == 2* $sortIndex + 2 )
return 2;
else
return 0;
}
/*
* Process array of objects
*/
function process( &$array ){
if( ! $this->_selected )
return;
$pname = $this->_matrix[ $this->getIndex() ]['pname'];
$type = $this->_matrix[ $this->getIndex() ]['type'];
$selectionStatus = $this->getSelectionStatus( $this->getIndex() );
if( $selectionStatus == 2 )
$arguments = '$b, $a';
else
$arguments = '$a, $b';
$fcode_int = "
\$al = \$a->getProp('$pname');
\$bl = \$b->getProp('$pname');
if (\$al == \$bl)
return 0;
elseif (\$al < \$bl)
return 1;
else
return -1;
";
$fcode_string = "
\$al = strtolower( \$a->getProp('$pname') );
\$bl = strtolower( \$b->getProp('$pname') );
return strcmp(\$al, \$bl);
";
if( $type == 'string' )
$func = create_function( $arguments, $fcode_string );
else
$func = create_function( $arguments, $fcode_int );
usort( $array, $func );
}
/*
* Process array of arrays
*/
function processArrays( &$array ){
if( ! $this->_selected )
return;
global $_TEMP_COMPARES;
$_TEMP_COMPARES = array();
// PRESORT
$preSortArray = array();
foreach( $this->_preSort as $arr )
// print_r( $arr );
$_TEMP_COMPARES[] = $arr;
// MAIN SORTING
$pname = $this->_matrix[ $this->getIndex() ]['pname'];
$type = $this->_matrix[ $this->getIndex() ]['type'];
$selectionStatus = $this->getSelectionStatus( $this->getIndex() );
if( $selectionStatus == 2 ) // ASC
$direction = 'asc';
else // DESC
$direction = 'desc';
$_TEMP_COMPARES[] = array( $pname, $direction, $type );
// RUN SORTING
usort( $array, 'multipleCompare' );
$_TEMP_COMPARES = array();
}
/*
* Process array of arrays
*/
function processArraysOld( &$array ){
if( ! $this->_selected )
return;
$pname = $this->_matrix[ $this->getIndex() ]['pname'];
$type = $this->_matrix[ $this->getIndex() ]['type'];
$selectionStatus = $this->getSelectionStatus( $this->getIndex() );
if( $selectionStatus == 2 )
$arguments = '$b, $a';
else
$arguments = '$a, $b';
$fcode_int = "
\$al = \$a['$pname'];
\$bl = \$b['$pname'];
if (\$al == \$bl)
return 0;
elseif (\$al < \$bl)
return 1;
else
return -1;
";
$fcode_string = "
\$al = strtolower( \$a['$pname'] );
\$bl = strtolower( \$b['$pname'] );
return strcmp(\$al, \$bl);
";
if( $type == 'string' )
$func = create_function( $arguments, $fcode_string );
else
$func = create_function( $arguments, $fcode_int );
usort( $array, $func );
}
function &getSortings(){
$sortings = array();
// WE HAVE SORTING CRITERIA
if( $this->getNumSortings() > 0 ){
// SETTING SORTING LINKS
for( $sortIndex = 0; $sortIndex < $this->getNumSortings(); $sortIndex++ ){
$thisArray = array();
$sortingTitle = $this->getSortingPropTitle($sortIndex);
$thisArray['title'] = $sortingTitle;
// prepare sorting values
// get sorting value ASC
if( $this->getSortingValueAsc($sortIndex) != $this->getDefaultSelection() )
$sortValueAsc = $this->getSortingValueAsc($sortIndex);
else
$sortValueAsc = 0;
// get sorting value DESC
if( $this->getSortingValueDesc($sortIndex) != $this->getDefaultSelection() )
$sortValueDesc = $this->getSortingValueDesc($sortIndex);
else
$sortValueDesc = 0;
$selectionStatus = $this->getSelectionStatus( $sortIndex );
switch( $selectionStatus ){
case 0:
// NOT SELECTED
$thisArray['action'] = $sortValueAsc;
$thisArray['show'] = null;
break;
case 1:
// SELECTED ASC
$thisArray['action'] = $sortValueDesc;
$thisArray['show'] = 'asc';
break;
case 2:
// SELECTED DESC
$thisArray['action'] = $sortValueAsc;
$thisArray['show'] = 'desc';
break;
}
$sortings[] = $thisArray;
}
}
return $sortings;
}
function getSQLString(){
$orderByArray = array();
// PRE SORT
$preSortArray = array();
foreach( $this->_preSort as $arr )
$preSortArray[] = $arr[0] . ' ' . $arr[1];
$preSortString = join( ', ', $preSortArray );
if( $preSortString )
$orderByArray[] = $preSortString;
// MAIN SORTING
if( $this->getNumSortings() > 0 ){
$pname = $this->_matrix[ $this->getIndex() ]['pname'];
$type = $this->_matrix[ $this->getIndex() ]['type'];
if( $pname ){
$selectionStatus = $this->getSelectionStatus( $this->getIndex() );
if( $selectionStatus == 2 )
$order = ($type == 'int') ? 'ASC' : 'DESC';
else
$order = ($type == 'int') ? 'DESC' : 'ASC';
$mainSortString = $pname . ' ' . $order;
if( $mainSortString )
$orderByArray[] = $mainSortString;
}
}
// FINAL ORDER BY STRING
$orderByString = join( ', ', $orderByArray );
return $orderByString;
}
}
function multipleCompare( $a, $b ){
global $_TEMP_COMPARES;
reset( $_TEMP_COMPARES );
$return = 0;
foreach( $_TEMP_COMPARES as $c ){
$pname = $c[0];
$direction = $c[1];
$type = $c[2];
if( $type == 'int' ){
$fcode = "
\$al = \$a['$pname'];
\$bl = \$b['$pname'];
if (\$al == \$bl)
return 0;
elseif (\$al < \$bl)
return 1;
else
return -1;
";
}
else {
$fcode = "
\$al = strtolower( \$a['$pname'] );
\$bl = strtolower( \$b['$pname'] );
return strcmp(\$bl, \$al);
";
}
if( strtolower($direction) == 'asc' )
$arguments = '$a, $b';
else
$arguments = '$b, $a';
$func = create_function( $arguments, $fcode );
$sortFuncReturn = $func( $a, $b );
if( $sortFuncReturn != 0 ){
$return = $sortFuncReturn;
break;
}
}
return $return;
}
?>
startFile : mwftp5/_hclib/hcTemplateEngine.php : 1
<?
class hcTemplateEngine {
var $_filesContent;
var $_root;
var $_parsePHP;
function hcTemplateEngine(){
$this->_filesContent = array();
$this->setParsePHP();
}
function setRoot( $root ){
$this->_root = $root;
}
function setParsePHP( $p = 0 ){
$this->_parsePHP = $p;
}
function processContent( &$content, &$keys, &$values, $parsePHP = 0 ){
$exists = array();
$keysCount = count($keys);
// for( $i = 0; $i < $keysCount; $i++ ){
for( $i = $keysCount - 1; $i >= 0; $i-- ){
if( isset($exists[$keys[$i]]) ){
unset($keys[$i]);
unset($values[$i]);
}
else {
$exists[$keys[$i]] = 1;
$keys[$i] = '{' . $keys[$i] . '}';
}
}
// PARSE PHP
if( $parsePHP )
$this->processPHP( $content );
$result = str_replace( $keys, $values, $content );
return $result;
}
function processFile( $tplFile, &$keys, &$values, $parsePHP = 0 ){
if( ! isset( $this->_filesContent[$tplFile] ) )
$this->_readFile($tplFile);
return $this->processContent( $this->_filesContent[$tplFile], $keys, $values, $parsePHP );
}
function processPHP( &$str ){
$php_start = 0;
// extract and clean them from parent handle
// $tag = '<php>';
// $endtag = '</php>';
$tag = '<?';
$endtag = '?>';
while(is_long($php_start = strpos($str, $tag, $php_start))){
$start_pos = $php_start + strlen($tag);
$end_pos = strpos($str, $endtag, $start_pos); //the 3rd param is to start searching from the starting tag - not to mix the ending tag of the 1st block if we want for the 2nd
if (!$end_pos) { echo "template: php code has no ending tag!", exit; }
$php_end = $end_pos + strlen($endtag);
$php_code = substr($str, $start_pos, $end_pos - $start_pos);
if( strtolower(substr($php_code, 0, 3)) == 'php' )
$php_code = substr($php_code, 3);
// before php code
$part1 = substr($str, 0, $php_start);
// here set the php output
ob_start();
eval($php_code);
$output = ob_get_contents();
ob_end_clean();
// after php code
$part2 = substr($str, $php_end, strlen($str));
$str = $part1 . $output . $part2;
}
}
function _readFile( $tplFile ){
$fullName = $this->_root . '/' . $tplFile;
if( $this->_root )
$fullName = $this->_root . '/' . $tplFile;
else
$fullName = $tplFile;
if(! file_exists($fullName) ){
echo "hcTemplateEngine::_readFile(): file $fullName does not exist.";
exit;
}
$tmp = '';
if( filesize($fullName) > 0 ){
$tmp = fread($fp = fopen($fullName, 'r'), filesize($fullName));
fclose($fp);
}
$this->_filesContent[$tplFile] = $tmp;
}
// Singleton stuff
function &getInstance(){
return hcMySingletonFunction( 'hcTemplateEngine' );
}
}
?>
startFile : mwftp5/_hclib/hcView.php : 1
<?
class hcView {
var $data;
var $_resp;
var $_req;
var $_templatesDir;
function hcView( &$req, &$resp ){
$this->_req = $req;
$this->_resp = $resp;
}
function setData( &$data ){
$this->_data = $data;
}
function &getData(){
return $this->_data;
}
function setTemplatesDir( $tDir ){
$this->_templatesDir = $tDir;
}
function getTemplatesDir(){
return $this->_templatesDir;
}
function prefillViewContainer( &$viewContainer ){
}
}
?>
startFile : mwftp5/_hclib/hcViewContainer.php : 1
<?
include_once( 'hcPatterns.php');
// actually it extends the Composite pattern
// also extends the hcView class
class hcViewContainer extends hcPatterns {
/**
* private
* holds the template file name
*/
var $_tplFile;
/**
* private, array
* holds the template labels
*/
var $_templateLabels;
var $_filler;
function hcViewContainer( $tplFile = '' ){
parent::hcPatterns();
$this->_tplFile = $tplFile;
$this->_content = '';
$this->_filler = null;
}
function setContent( &$content ){
$this->_content =& $content;
}
/**
* redefines the addChild() method to add template placeholders
*/
function addChild( $child, $in_template ){
// child my be an object with view() method or just a string
$id = parent::addChild( $child ) - 1;
$this->_templateLabels[ $id ] = $in_template;
}
function fill( &$filler ){
$children =& $filler->getChildren();
foreach( array_keys($children) as $k )
$this->addChild( $children[$k], $k );
}
/**
* implements the view
*/
function view( $parsePHP = 0 ){
$tpl =& hcTemplateEngine::getInstance();
if( $parsePHP )
$tpl->setParsePHP( $parsePHP );
$keys = array();
$values = array();
// traversing children
// @todo: implement hcPatterns incapsulated approach
for( $i = 0; $i < $this->_children_count; $i++ ){
$child =& $this->_children[ $i ];
$thisView = '';
$in_template = $this->_templateLabels[ $i ];
$thisView = $this->viewChild( $child );
$keys[] = $in_template;
$values[] = $thisView;
}
if( $this->_content )
$out = $tpl->processContent( $this->_content, $keys, $values, $parsePHP );
else
$out = $tpl->processFile( $this->_tplFile, $keys, $values, $parsePHP );
return $out;
}
function viewChild( &$child ){
$thisView = '';
// object
if( is_object($child) ){
if( method_exists( $child, 'view' ) ){
$thisView = $child->view();
}
}
// array of strings
else if( is_array($child) ){
foreach( $child as $c )
$thisView .= $this->viewChild( $c );
}
// just a string
else {
$thisView = $child;
}
return $thisView;
}
}
?>
startFile : mwftp5/_hclib/hcView_Forward.php : 1
<?
include_once( 'hcView.php' );
class hcView_Forward extends hcView {
/*
* The data for this view is an array of action results. The keys are:
forwardTo => url
*/
function view(){
$viewData =& $this->getData();
$forwardTo = $viewData['forwardTo'];
$locationString = 'Location: ' . $forwardTo;
header( $locationString );
}
}
?>
startFile : mwftp5/_hclib/hcZipFile.php : 1
<?
include_once( 'zip.lib.php' );
class hcZipFile {
var $_compressor;
var $totalZize = 0;
function hcZipFile(){
$this->totalZize = 0;
$this->_compressor = new zipfile();
$this->rewind();
}
function addFile( $fileContent, $filePath ){
$this->_compressor->addFile( $fileContent, $filePath );
}
function getTotalSize(){
return $this->_compressor->getTotalSize();
}
function fread( $bytes = 0 ){
$this->_feof = true;
return $this->_compressor->fread();
}
function feof(){
return $this->_feof;
}
function rewind(){
$this->_feof = false;
}
function fclose(){
return true;
}
}
?>
startFile : mwftp5/_hclib/mwEncryptor.php : 1
<?
class mwEncryptor {
var $key;
function mwEncryptor($key = ''){
$this->key = $key;
}
function encrypt($data){
$out = '';
if( strlen($this->key)>0 ){ // real encryption
$current_key = md5($this->key);
$key_len = strlen($current_key);
$data_len = strlen($data);
$iterations = ceil( $data_len / $key_len);
for($i = 0; $i < $iterations; $i++){
$out .= substr($data, $i * $key_len, $key_len) ^ $current_key;
$current_key = md5($current_key);
}
}
else { //hashing - for passwords
$out = md5($data);
}
return $out;
}
function decrypt($data){
$out = '';
$current_key = md5($this->key);
$key_len = strlen($current_key);
$data_len = strlen($data);
$iterations = ceil( $data_len / $key_len);
for($i = 0; $i < $iterations; $i++){
$out .= substr($data, $i * $key_len, $key_len) ^ $current_key;
$current_key = md5($current_key);
}
return $out;
}
}
?>
startFile : mwftp5/_hclib/mwFile.php : 1
<?
class mwFile {
var $err;
var $filename;
var $fh; //file handle
function mwFile($filename){
$this->filename = $filename;
$this->err = '';
return 1;
}
function create_path($path){
$ok = 0;
if( file_exists( $path )){
$ok = 1;
return $ok;
}
if(! file_exists( dirname($path) )){
$ok = $this->create_path( dirname($path) );
}
if( mkdir($path, 0755) ){
chmod($path, 0755);
$ok = 1;
}
else{
echo "Failed to create $path directory!<BR>";
return 0;
}
return $ok;
}
function createPathToMe(){
return $this->create_path( dirname($this->filename) );
}
function size(){
if( $this->exists() ){
clearstatcache();
return filesize($this->filename);
}
else
return 0;
}
function exists(){
clearstatcache();
$exists = file_exists($this->filename);
if( $exists )
$this->filename = realpath($this->filename);
return $exists;
}
function mtime(){
clearstatcache();
return filemtime($this->filename);
}
function utime($time = 0){
if($time)
touch($this->filename, $time, $time);
else
touch($this->filename);
}
function unlink(){
if( $this->exists() ){
$this->close();
return unlink( $this->filename );
}
}
function get_content(){
$content = '';
rewind( $this->fh );
$fileSize = filesize($this->filename);
if( $fileSize > 0 )
$content = fread ($this->fh, filesize($this->filename));
return $content;
}
function set_content($content){
$length = strlen( $content );
$return = 1;
rewind( $this->fh );
$writeResult = fwrite($this->fh, $content, $length);
if( $writeResult === FALSE )
$return = 0;
// fflush( $this->fh );
// ftruncate( $this->fh, ftell($this->fh) );
return $return;
}
function insert($offset, $string){
if(! strlen($string) )
return 0;
// inserts $string at specified $offset
$string = strval($string);
fseek($this->fh, $offset);
if ( ! fwrite($this->fh, $string) ) {
print "Can't write \"$string\" to file $this->filename at";
return;
}
//echo "<BR>INSERTED '$string' AT $offset<BR>";
return 1;
}
function get_string($offset, $len){
fseek($this->fh, $offset);
$string = trim( fread($this->fh, $len) );
return $string;
}
function open($mode = 'r'){ // mode - 'r', 'w', 'r+', 'a'
if( ($mode == 'r') && (! $this->exists()) )
return 0;
$mode = $mode . 'b';
if( ! $this->exists() )
$this->createPathToMe();
if(! $this->fh =& fopen($this->filename, $mode) ){
echo "cant open file <B>$this->filename</B> for <I>$mode</I> mode.";
exit;
}
//echo "opening " . $this->filename ." for $mode mode<BR>";
return 1;
}
function close(){
if( ! isset($this->fh) ){
return 1;
}
if(! fclose($this->fh) ){
echo "cant close file <B>$this->filename</B>.";
return 0;
exit;
}
//echo "closing " . $this->filename ."<BR>";
unset($this->fh);
return 1;
}
}
?>
startFile : mwftp5/_hclib/mwPassword.php : 1
<?
class mwPasswordLite {
var $err;
var $enc;
function mwPasswordLite($enc = ''){
$this->enc = $enc;
return 1;
}
function set_enc($enc) {
$this->enc = $enc;
}
function check($pass){
if( md5($pass) == $this->enc)
return 1;
else{
$this->err = M('password/wrong');
return 0;
}
}
}
class mwPassword {
var $err;
var $filename;
function mwPassword($filename){
$this->filename = $filename;
return 1;
}
function check($pass){
if( $this->exists() ){
$encrypted = $this->get_content();
}
else{
$this->err = M('fileAccess/fileDoesNotExist', array('filename' => $this->filename) );
return 0;
}
if( md5($pass) == $encrypted){
return 1;
}
else{
$this->err = M('password/wrong');
return 0;
}
}
function getError(){
return $this->err;
}
function set($pass){
$pass = md5($pass);
if( $this->set_content($pass) )
return 1;
else{
echo $this->err;
return 0;
}
}
function exists(){
return file_exists($this->filename);
}
function get_content(){
if(! $file = @fopen($this->filename, "r") ){
$this->err = M('fileAccess/fileNotReadable', array('filename' => $this->filename) );
return 0;
}
$content = '';
$content = fread ($file, filesize($this->filename));
$content = trim($content);
if(! fclose($file) ){
$this->err = M('fileAccess/cannotClose', array('filename' => $this->filename) );
return 0;
}
return $content;
}
function set_content($content){
if(! $file = @fopen($this->filename, "w") ){
$this->err = M('fileAccess/fileNotWritable', array('filename' => $this->filename) );
return 0;
}
fwrite($file, $content);
if(! fclose($file) ){
$this->err = M('fileAccess/cannotClose', array('filename' => $this->filename) );
return 0;
}
return 1;
}
}
?>
startFile : mwftp5/_hclib/mwSessionFile.php : 1
<?
include_once( 'mwFile.php' );
include_once( 'mwEncryptor.php' );
class mwSessionFile {
var $sid;
var $dir;
var $file;
var $lifetime;
var $key;
var $err;
var $error;
function mwSessionFile($dir, $sid = 0, $lifetime = 300){
$this->dir = $dir;
$this->sid = $sid;
$this->lifetime = $lifetime;
$this->err = '';
$this->error = '';
if($this->sid){ //session exists, checking
$this->file = new mwFile( $this->dir . '/' . $this->get_filename(), 1 );
if( ! $this->file ){
$this->err = "Cannot create session file!";
return;
}
if( $this->is_expired() ){
$this->err = "Session has expired!";
return;
}
$this->reset_time(); //update time
}
else { //new session
$this->sid = $this->generate_sid();
$this->file = new mwFile( $this->dir . '/' . $this->get_filename() );
}
$this->clean_up(); //clean old sessions
$this->err = '';
$this->file->close();
}
function sid(){
return $this->sid;
}
function is_expired(){
//first check if file exists
if (! $this->file->exists() ){
return 1;
}
//if lifetime is set to 0, session is not expiring
if( ! $this->lifetime )
return 0;
//now check file modification time
if( $this->file->mtime() + $this->lifetime < time() ){//expired
$this->file->unlink();
return 1;
}
return 0;
}
function reset_time(){
$this->file->utime();
}
function clean_up(){
//if lifetime is set to 0, sessions are not expiring, don't delete them
if( ! $this->lifetime )
return;
$valid_start_time = time() - $this->lifetime;
if( $dir = @opendir($this->dir) ){
while( ($filename = readdir($dir)) !== false ){
if( preg_match( "/^\./", $filename ) )
continue;
$fullName = $this->dir . '/' . $filename;
if( is_dir($fullName) && filemtime($fullName) < $valid_start_time )
cleanDir( $fullName, 1 );
else {
$file = new mwFile( $this->dir . '/' . $filename );
if( $file->mtime() < $valid_start_time){ //expired
if(! $file->unlink() ){
// echo "Cannot delete session file <B>$filename</B><BR>";
}
}
}
}
closedir($dir);
}
}
function get_data(){
$this->file->open();
if( ! $content = $this->file->get_content() ){; // got encrypted string
$this->err = $this->file->err;
return 0;
}
$this->file->close();
if( $this->_enc ){
$enc = new mwEncryptor( $this->get_key() );
$content = $enc->decrypt($content); //got serialized array
}
return unserialize($content);
}
function set_data($data){
if(! $data){
$this->err = 'Empty data!';
return 0;
}
$data = serialize($data);
if( $this->_enc ){
$enc = new mwEncryptor( $this->get_key() );
$data = $enc->encrypt($data);
}
$this->file->open( 'w' );
if( ! $this->file->set_content($data) ){
$this->file->close();
$this->err = $this->file->err;
return 0;
}
$this->file->close();
return 1;
}
function get_filename(){
return md5( $this->sid . __LINE__ . PHP_VERSION );
}
function get_dirname(){
return $this->get_filename() . '_';
}
function get_key(){
return md5( __LINE__ . $this->sid . PHP_OS );
}
function generate_sid(){
mt_srand( $this->make_seed() );
$long_sid = md5( mt_rand() . time()); //32 long
$short_sid = '';
for( $i = 0; $i < 8; $i++){
$short_sid .= substr( $long_sid, $i * 4, 1 );
}
return $short_sid;
}
function destroy(){
$this->file->unlink();
$tempDir = $this->dir . '/' . $this->get_dirname();
if( file_exists($tempDir) )
cleanDir( $tempDir, 1 );
unset($this);
}
function make_seed(){
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
}
?>
startFile : mwftp5/_hclib/pclzip.lib.php : 1
<?php
// --------------------------------------------------------------------------------
// PhpConcept Library - Zip Module 2.3
// --------------------------------------------------------------------------------
// License GNU/LGPL - Vincent Blavet - November 2004
// http://www.phpconcept.net
// --------------------------------------------------------------------------------
//
// Presentation :
// PclZip is a PHP library that manage ZIP archives.
// So far tests show that archives generated by PclZip are readable by
// WinZip application and other tools.
//
// Description :
// See readme.txt and http://www.phpconcept.net
//
// Warning :
// This library and the associated files are non commercial, non professional
// work.
// It should not have unexpected results. However if any damage is caused by
// this software the author can not be responsible.
// The use of this software is at the risk of the user.
//
// --------------------------------------------------------------------------------
// $Id: pclzip.lib.php,v 1.34 2004/11/16 19:54:28 vblavet Exp $
// --------------------------------------------------------------------------------
// ----- Constants
define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
define( 'PCLZIP_SEPARATOR', ',' );
define( 'PCLZIP_ERROR_EXTERNAL', 0 );
define( 'PCLZIP_TEMPORARY_DIR', '' );
$g_pclzip_version = "2.3";
define( 'PCLZIP_ERR_USER_ABORTED', 2 );
define( 'PCLZIP_ERR_NO_ERROR', 0 );
define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
define( 'PCLZIP_ERR_MISSING_FILE', -4 );
define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
define( 'PCLZIP_OPT_PATH', 77001 );
define( 'PCLZIP_OPT_ADD_PATH', 77002 );
define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
define( 'PCLZIP_OPT_BY_NAME', 77008 );
define( 'PCLZIP_OPT_BY_INDEX', 77009 );
define( 'PCLZIP_OPT_BY_EREG', 77010 );
define( 'PCLZIP_OPT_BY_PREG', 77011 );
define( 'PCLZIP_OPT_COMMENT', 77012 );
define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
define( 'PCLZIP_CB_PRE_ADD', 78003 );
define( 'PCLZIP_CB_POST_ADD', 78004 );
/* For futur use
define( 'PCLZIP_CB_PRE_LIST', 78005 );
define( 'PCLZIP_CB_POST_LIST', 78006 );
define( 'PCLZIP_CB_PRE_DELETE', 78007 );
define( 'PCLZIP_CB_POST_DELETE', 78008 );
*/
class PclZip
{
var $zipname = '';
var $zip_fd = 0;
var $error_code = 1;
var $error_string = '';
function PclZip($p_zipname)
{
if (!function_exists('gzopen'))
{
die('Abort '.basename(__FILE__).' : Missing zlib extensions');
}
$this->zipname = $p_zipname;
$this->zip_fd = 0;
return;
}
function create($p_filelist /*, options */)
{
$v_result=1;
$this->privErrorReset();
$v_options = array();
$v_add_path = "";
$v_remove_path = "";
$v_remove_all_path = false;
$v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
$v_size = func_num_args();
if ($v_size > 1) {
$v_arg_list = &func_get_args();
array_shift($v_arg_list);
$v_size--;
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
array (PCLZIP_OPT_REMOVE_PATH => 'optional',
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
PCLZIP_OPT_ADD_PATH => 'optional',
PCLZIP_CB_PRE_ADD => 'optional',
PCLZIP_CB_POST_ADD => 'optional',
PCLZIP_OPT_NO_COMPRESSION => 'optional',
PCLZIP_OPT_COMMENT => 'optional'
));
if ($v_result != 1) {
return 0;
}
if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
$v_add_path = $v_options[PCLZIP_OPT_ADD_PATH];
}
if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
$v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
}
if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
$v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
}
}
else {
$v_add_path = $v_arg_list[0];
if ($v_size == 2) {
$v_remove_path = $v_arg_list[1];
}
else if ($v_size > 2) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
"Invalid number / type of arguments");
return 0;
}
}
}
$p_result_list = array();
if (is_array($p_filelist))
{
$v_result = $this->privCreate($p_filelist, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);
}
else if (is_string($p_filelist))
{
$v_list = explode(PCLZIP_SEPARATOR, $p_filelist);
$v_result = $this->privCreate($v_list, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);
}
else
{
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
$v_result = PCLZIP_ERR_INVALID_PARAMETER;
}
if ($v_result != 1)
{
return 0;
}
return $p_result_list;
}
function add($p_filelist /* options */)
{
$v_result=1;
$this->privErrorReset();
$v_options = array();
$v_add_path = "";
$v_remove_path = "";
$v_remove_all_path = false;
$v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
$v_size = func_num_args();
if ($v_size > 1) {
$v_arg_list = &func_get_args();
array_shift($v_arg_list);
$v_size--;
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
array (PCLZIP_OPT_REMOVE_PATH => 'optional',
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
PCLZIP_OPT_ADD_PATH => 'optional',
PCLZIP_CB_PRE_ADD => 'optional',
PCLZIP_CB_POST_ADD => 'optional',
PCLZIP_OPT_NO_COMPRESSION => 'optional',
PCLZIP_OPT_COMMENT => 'optional',
PCLZIP_OPT_ADD_COMMENT => 'optional',
PCLZIP_OPT_PREPEND_COMMENT => 'optional'
));
if ($v_result != 1) {
return 0;
}
if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
$v_add_path = $v_options[PCLZIP_OPT_ADD_PATH];
}
if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
$v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
}
if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
$v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
}
}
else {
$v_add_path = $v_arg_list[0];
if ($v_size == 2) {
$v_remove_path = $v_arg_list[1];
}
else if ($v_size > 2) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
return 0;
}
}
}
$p_result_list = array();
if (is_array($p_filelist))
{
$v_result = $this->privAdd($p_filelist, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);
}
else if (is_string($p_filelist))
{
$v_list = explode(PCLZIP_SEPARATOR, $p_filelist);
$v_result = $this->privAdd($v_list, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);
}
else
{
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
$v_result = PCLZIP_ERR_INVALID_PARAMETER;
}
if ($v_result != 1)
{
return 0;
}
return $p_result_list;
}
function listContent()
{
$v_result=1;
$this->privErrorReset();
if (!$this->privCheckFormat()) {
return(0);
}
$p_list = array();
if (($v_result = $this->privList($p_list)) != 1)
{
unset($p_list);
return(0);
}
return $p_list;
}
//
function extract(/* options */)
{
$v_result=1;
$this->privErrorReset();
if (!$this->privCheckFormat()) {
return(0);
}
$v_options = array();
$v_path = "./";
$v_remove_path = "";
$v_remove_all_path = false;
$v_size = func_num_args();
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
if ($v_size > 0) {
$v_arg_list = &func_get_args();
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
array (PCLZIP_OPT_PATH => 'optional',
PCLZIP_OPT_REMOVE_PATH => 'optional',
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
PCLZIP_OPT_ADD_PATH => 'optional',
PCLZIP_CB_PRE_EXTRACT => 'optional',
PCLZIP_CB_POST_EXTRACT => 'optional',
PCLZIP_OPT_SET_CHMOD => 'optional',
PCLZIP_OPT_BY_NAME => 'optional',
PCLZIP_OPT_BY_EREG => 'optional',
PCLZIP_OPT_BY_PREG => 'optional',
PCLZIP_OPT_BY_INDEX => 'optional',
PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
PCLZIP_OPT_REPLACE_NEWER => 'optional'
,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
));
if ($v_result != 1) {
return 0;
}
if (isset($v_options[PCLZIP_OPT_PATH])) {
$v_path = $v_options[PCLZIP_OPT_PATH];
}
if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
$v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
}
if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
$v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
}
if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
$v_path .= '/';
}
$v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
}
}
else {
$v_path = $v_arg_list[0];
if ($v_size == 2) {
$v_remove_path = $v_arg_list[1];
}
else if ($v_size > 2) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
return 0;
}
}
}
$p_list = array();
$v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
$v_remove_all_path, $v_options);
if ($v_result < 1) {
unset($p_list);
return(0);
}
return $p_list;
}
function extractByIndex($p_index /* $options */)
{
$v_result=1;
$this->privErrorReset();
if (!$this->privCheckFormat()) {
return(0);
}
$v_options = array();
$v_path = "./";
$v_remove_path = "";
$v_remove_all_path = false;
$v_size = func_num_args();
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
if ($v_size > 1) {
$v_arg_list = &func_get_args();
array_shift($v_arg_list);
$v_size--;
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
array (PCLZIP_OPT_PATH => 'optional',
PCLZIP_OPT_REMOVE_PATH => 'optional',
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
PCLZIP_OPT_ADD_PATH => 'optional',
PCLZIP_CB_PRE_EXTRACT => 'optional',
PCLZIP_CB_POST_EXTRACT => 'optional',
PCLZIP_OPT_SET_CHMOD => 'optional',
PCLZIP_OPT_REPLACE_NEWER => 'optional'
,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
));
if ($v_result != 1) {
return 0;
}
if (isset($v_options[PCLZIP_OPT_PATH])) {
$v_path = $v_options[PCLZIP_OPT_PATH];
}
if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
$v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
}
if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
$v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
}
if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
$v_path .= '/';
}
$v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
}
if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
$v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
}
else {
}
}
else {
$v_path = $v_arg_list[0];
if ($v_size == 2) {
$v_remove_path = $v_arg_list[1];
}
else if ($v_size > 2) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
return 0;
}
}
}
$v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
$v_options_trick = array();
$v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
array (PCLZIP_OPT_BY_INDEX => 'optional' ));
if ($v_result != 1) {
return 0;
}
$v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
return(0);
}
return $p_list;
}
function delete(/* options */)
{
$v_result=1;
$this->privErrorReset();
if (!$this->privCheckFormat()) {
return(0);
}
$v_options = array();
$v_size = func_num_args();
if ($v_size <= 0) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing arguments");
return 0;
}
$v_arg_list = &func_get_args();
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
array (PCLZIP_OPT_BY_NAME => 'optional',
PCLZIP_OPT_BY_EREG => 'optional',
PCLZIP_OPT_BY_PREG => 'optional',
PCLZIP_OPT_BY_INDEX => 'optional' ));
if ($v_result != 1) {
return 0;
}
if ( (!isset($v_options[PCLZIP_OPT_BY_NAME]))
&& (!isset($v_options[PCLZIP_OPT_BY_EREG]))
&& (!isset($v_options[PCLZIP_OPT_BY_PREG]))
&& (!isset($v_options[PCLZIP_OPT_BY_INDEX]))) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "At least one filtering rule must be set");
return 0;
}
$v_list = array();
if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1)
{
unset($v_list);
return(0);
}
return $v_list;
}
function deleteByIndex($p_index)
{
$p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
return $p_list;
}
function properties()
{
$this->privErrorReset();
if (!$this->privCheckFormat()) {
return(0);
}
$v_prop = array();
$v_prop['comment'] = '';
$v_prop['nb'] = 0;
$v_prop['status'] = 'not_exist';
if (@is_file($this->zipname))
{
if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
{
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
return 0;
}
$v_central_dir = array();
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
{
return 0;
}
$this->privCloseFd();
$v_prop['comment'] = $v_central_dir['comment'];
$v_prop['nb'] = $v_central_dir['entries'];
$v_prop['status'] = 'ok';
}
return $v_prop;
}
function duplicate($p_archive)
{
$v_result = 1;
$this->privErrorReset();
if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
{
$v_result = $this->privDuplicate($p_archive->zipname);
}
else if (is_string($p_archive))
{
if (!is_file($p_archive)) {
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
$v_result = PCLZIP_ERR_MISSING_FILE;
}
else {
$v_result = $this->privDuplicate($p_archive);
}
}
else
{
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
$v_result = PCLZIP_ERR_INVALID_PARAMETER;
}
return $v_result;
}
function merge($p_archive_to_add)
{
$v_result = 1;
$this->privErrorReset();
if (!$this->privCheckFormat()) {
return(0);
}
if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
{
$v_result = $this->privMerge($p_archive_to_add);
}
else if (is_string($p_archive_to_add))
{
$v_object_archive = new PclZip($p_archive_to_add);
$v_result = $this->privMerge($v_object_archive);
}
else
{
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
$v_result = PCLZIP_ERR_INVALID_PARAMETER;
}
return $v_result;
}
function errorCode()
{
if (PCLZIP_ERROR_EXTERNAL == 1) {
return(PclErrorCode());
}
else {
return($this->error_code);
}
}
function errorName($p_with_code=false)
{
$v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION' );
if (isset($v_name[$this->error_code])) {
$v_value = $v_name[$this->error_code];
}
else {
$v_value = 'NoName';
}
if ($p_with_code) {
return($v_value.' ('.$this->error_code.')');
}
else {
return($v_value);
}
}
function errorInfo($p_full=false)
{
if (PCLZIP_ERROR_EXTERNAL == 1) {
return(PclErrorString());
}
else {
if ($p_full) {
return($this->errorName(true)." : ".$this->error_string);
}
else {
return($this->error_string." [code ".$this->error_code."]");
}
}
}
function privCheckFormat($p_level=0)
{
$v_result = true;
// ----- Reset the file system cache
clearstatcache();
$this->privErrorReset();
if (!is_file($this->zipname)) {
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
return(false);
}
if (!is_readable($this->zipname)) {
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
return(false);
}
return $v_result;
}
function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
{
$v_result=1;
$i=0;
while ($i<$p_size) {
if (!isset($v_requested_options[$p_options_list[$i]])) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
return PclZip::errorCode();
}
switch ($p_options_list[$i]) {
case PCLZIP_OPT_PATH :
case PCLZIP_OPT_REMOVE_PATH :
case PCLZIP_OPT_ADD_PATH :
if (($i+1) >= $p_size) {
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
$v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);
$i++;
break;
case PCLZIP_OPT_BY_NAME :
if (($i+1) >= $p_size) {
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
if (is_string($p_options_list[$i+1])) {
$v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
}
else if (is_array($p_options_list[$i+1])) {
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
}
else {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
$i++;
break;
case PCLZIP_OPT_BY_EREG :
case PCLZIP_OPT_BY_PREG :
if (($i+1) >= $p_size) {
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
if (is_string($p_options_list[$i+1])) {
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
}
else {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
$i++;
break;
case PCLZIP_OPT_COMMENT :
case PCLZIP_OPT_ADD_COMMENT :
case PCLZIP_OPT_PREPEND_COMMENT :
if (($i+1) >= $p_size) {
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
"Missing parameter value for option '"
.PclZipUtilOptionText($p_options_list[$i])
."'");
return PclZip::errorCode();
}
if (is_string($p_options_list[$i+1])) {
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
}
else {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
"Wrong parameter value for option '"
.PclZipUtilOptionText($p_options_list[$i])
."'");
return PclZip::errorCode();
}
$i++;
break;
case PCLZIP_OPT_BY_INDEX :
if (($i+1) >= $p_size) {
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
$v_work_list = array();
if (is_string($p_options_list[$i+1])) {
$p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
$v_work_list = explode(",", $p_options_list[$i+1]);
}
else if (is_integer($p_options_list[$i+1])) {
$v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
}
else if (is_array($p_options_list[$i+1])) {
$v_work_list = $p_options_list[$i+1];
}
else {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
$v_sort_flag=false;
$v_sort_value=0;
for ($j=0; $j<sizeof($v_work_list); $j++) {
$v_item_list = explode("-", $v_work_list[$j]);
$v_size_item_list = sizeof($v_item_list);
if ($v_size_item_list == 1) {
$v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
$v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
}
elseif ($v_size_item_list == 2) {
$v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
$v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
}
else {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
$v_sort_flag=true;
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
$v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
}
if ($v_sort_flag) {
}
$i++;
break;
case PCLZIP_OPT_REMOVE_ALL_PATH :
case PCLZIP_OPT_EXTRACT_AS_STRING :
case PCLZIP_OPT_NO_COMPRESSION :
case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
case PCLZIP_OPT_REPLACE_NEWER :
case PCLZIP_OPT_STOP_ON_ERROR :
$v_result_list[$p_options_list[$i]] = true;
break;
case PCLZIP_OPT_SET_CHMOD :
if (($i+1) >= $p_size) {
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
$v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
$i++;
break;
case PCLZIP_CB_PRE_EXTRACT :
case PCLZIP_CB_POST_EXTRACT :
case PCLZIP_CB_PRE_ADD :
case PCLZIP_CB_POST_ADD :
/* for futur use
case PCLZIP_CB_PRE_DELETE :
case PCLZIP_CB_POST_DELETE :
case PCLZIP_CB_PRE_LIST :
case PCLZIP_CB_POST_LIST :
*/
if (($i+1) >= $p_size) {
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
$v_function_name = $p_options_list[$i+1];
if (!function_exists($v_function_name)) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
return PclZip::errorCode();
}
$v_result_list[$p_options_list[$i]] = $v_function_name;
$i++;
break;
default :
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
"Unknown parameter '"
.$p_options_list[$i]."'");
return PclZip::errorCode();
}
$i++;
}
if ($v_requested_options !== false) {
for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
if ($v_requested_options[$key] == 'mandatory') {
if (!isset($v_result_list[$key])) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
return PclZip::errorCode();
}
}
}
}
return $v_result;
}
function privCreate($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
{
$v_result=1;
$v_list_detail = array();
if (($v_result = $this->privOpenFd('wb')) != 1)
{
return $v_result;
}
$v_result = $this->privAddList($p_list, $p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options);
$this->privCloseFd();
return $v_result;
}
function privAdd($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
{
$v_result=1;
$v_list_detail = array();
if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
{
$v_result = $this->privCreate($p_list, $p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options);
return $v_result;
}
if (($v_result=$this->privOpenFd('rb')) != 1)
{
return $v_result;
}
$v_central_dir = array();
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
{
$this->privCloseFd();
return $v_result;
}
@rewind($this->zip_fd);
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
{
$this->privCloseFd();
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
return PclZip::errorCode();
}
$v_size = $v_central_dir['offset'];
while ($v_size != 0)
{
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = fread($this->zip_fd, $v_read_size);
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
$v_size -= $v_read_size;
}
$v_swap = $this->zip_fd;
$this->zip_fd = $v_zip_temp_fd;
$v_zip_temp_fd = $v_swap;
$v_header_list = array();
if (($v_result = $this->privAddFileList($p_list, $v_header_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options)) != 1)
{
fclose($v_zip_temp_fd);
$this->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
$v_offset = @ftell($this->zip_fd);
$v_size = $v_central_dir['size'];
while ($v_size != 0)
{
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = @fread($v_zip_temp_fd, $v_read_size);
@fwrite($this->zip_fd, $v_buffer, $v_read_size);
$v_size -= $v_read_size;
}
for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
{
if ($v_header_list[$i]['status'] == 'ok') {
if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
fclose($v_zip_temp_fd);
$this->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
$v_count++;
}
$this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
}
$v_comment = $v_central_dir['comment'];
if (isset($p_options[PCLZIP_OPT_COMMENT])) {
$v_comment = $p_options[PCLZIP_OPT_COMMENT];
}
if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
$v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
}
if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
$v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
}
$v_size = @ftell($this->zip_fd)-$v_offset;
if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
{
unset($v_header_list);
return $v_result;
}
$v_swap = $this->zip_fd;
$this->zip_fd = $v_zip_temp_fd;
$v_zip_temp_fd = $v_swap;
$this->privCloseFd();
@fclose($v_zip_temp_fd);
@unlink($this->zipname);
PclZipUtilRename($v_zip_temp_name, $this->zipname);
return $v_result;
}
function privOpenFd($p_mode)
{
$v_result=1;
if ($this->zip_fd != 0)
{
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
return PclZip::errorCode();
}
if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
{
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
return PclZip::errorCode();
}
return $v_result;
}
function privCloseFd()
{
$v_result=1;
if ($this->zip_fd != 0)
@fclose($this->zip_fd);
$this->zip_fd = 0;
return $v_result;
}
function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
{
$v_result=1;
$v_header_list = array();
if (($v_result = $this->privAddFileList($p_list, $v_header_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options)) != 1)
{
return $v_result;
}
$v_offset = @ftell($this->zip_fd);
for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
{
if ($v_header_list[$i]['status'] == 'ok') {
if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
return $v_result;
}
$v_count++;
}
$this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
}
$v_comment = '';
if (isset($p_options[PCLZIP_OPT_COMMENT])) {
$v_comment = $p_options[PCLZIP_OPT_COMMENT];
}
$v_size = @ftell($this->zip_fd)-$v_offset;
if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
{
unset($v_header_list);
return $v_result;
}
return $v_result;
}
function privAddFileList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
{
$v_result=1;
$v_header = array();
$v_nb = sizeof($p_result_list);
for ($j=0; ($j<count($p_list)) && ($v_result==1); $j++)
{
$p_filename = PclZipUtilTranslateWinPath($p_list[$j], false);
if ($p_filename == "")
{
continue;
}
if (!file_exists($p_filename))
{
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '$p_filename' does not exists");
return PclZip::errorCode();
}
/* This test is done later
if (strlen($p_filename) > 0xFF)
{
PclZip::privErrorLog(-5, "File name is too long (max. 255) : '$p_filename'");
return PclZip::errorCode();
}
*/
if ((is_file($p_filename)) || ((is_dir($p_filename)) && !$p_remove_all_dir)) {
if (($v_result = $this->privAddFile($p_filename, $v_header, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options)) != 1)
{
return $v_result;
}
$p_result_list[$v_nb++] = $v_header;
}
if (@is_dir($p_filename))
{
if ($p_filename != ".")
$v_path = $p_filename."/";
else
$v_path = "";
if ($p_hdir = @opendir($p_filename)) {
$p_hitem = @readdir($p_hdir);// '.' directory
$p_hitem = @readdir($p_hdir);// '..' directory
while (($p_hitem = @readdir($p_hdir)) !== false) {
if (is_file($v_path.$p_hitem)) {
if (($v_result = $this->privAddFile($v_path.$p_hitem, $v_header, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options)) != 1) {
return $v_result;
}
$p_result_list[$v_nb++] = $v_header;
}
else {
$p_temp_list[0] = $v_path.$p_hitem;
$v_result = $this->privAddFileList($p_temp_list, $p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, $p_options);
$v_nb = sizeof($p_result_list);
}
}
}
unset($p_temp_list);
unset($p_hdir);
unset($p_hitem);
}
}
return $v_result;
}
function privAddFile($p_filename, &$p_header, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
{
$v_result=1;
if ($p_filename == "")
{
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
return PclZip::errorCode();
}
$v_stored_filename = $p_filename;
if ($p_remove_all_dir) {
$v_stored_filename = basename($p_filename);
}
else if ($p_remove_dir != "")
{
if (substr($p_remove_dir, -1) != '/')
$p_remove_dir .= "/";
if ((substr($p_filename, 0, 2) == "./") || (substr($p_remove_dir, 0, 2) == "./"))
{
if ((substr($p_filename, 0, 2) == "./") && (substr($p_remove_dir, 0, 2) != "./"))
$p_remove_dir = "./".$p_remove_dir;
if ((substr($p_filename, 0, 2) != "./") && (substr($p_remove_dir, 0, 2) == "./"))
$p_remove_dir = substr($p_remove_dir, 2);
}
$v_compare = PclZipUtilPathInclusion($p_remove_dir, $p_filename);
if ($v_compare > 0)
{
if ($v_compare == 2) {
$v_stored_filename = "";
}
else {
$v_stored_filename = substr($p_filename, strlen($p_remove_dir));
}
}
}
if ($p_add_dir != "")
{
if (substr($p_add_dir, -1) == "/")
$v_stored_filename = $p_add_dir.$v_stored_filename;
else
$v_stored_filename = $p_add_dir."/".$v_stored_filename;
}
$v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
clearstatcache();
$p_header['version'] = 20;
$p_header['version_extracted'] = 10;
$p_header['flag'] = 0;
$p_header['compression'] = 0;
$p_header['mtime'] = filemtime($p_filename);
$p_header['crc'] = 0;
$p_header['compressed_size'] = 0;
$p_header['size'] = filesize($p_filename);
$p_header['filename_len'] = strlen($p_filename);
$p_header['extra_len'] = 0;
$p_header['comment_len'] = 0;
$p_header['disk'] = 0;
$p_header['internal'] = 0;
$p_header['external'] = (is_file($p_filename)?0x00000000:0x00000010);
$p_header['offset'] = 0;
$p_header['filename'] = $p_filename;
$p_header['stored_filename'] = $v_stored_filename;
$p_header['extra'] = '';
$p_header['comment'] = '';
$p_header['status'] = 'ok';
$p_header['index'] = -1;
if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
$v_local_header = array();
$this->privConvertHeader2FileInfo($p_header, $v_local_header);
eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
if ($v_result == 0) {
$p_header['status'] = "skipped";
$v_result = 1;
}
if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
$p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
}
}
if ($p_header['stored_filename'] == "") {
$p_header['status'] = "filtered";
}
if (strlen($p_header['stored_filename']) > 0xFF) {
$p_header['status'] = 'filename_too_long';
}
if ($p_header['status'] == 'ok') {
if (is_file($p_filename))
{
if (($v_file = @fopen($p_filename, "rb")) == 0) {
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
return PclZip::errorCode();
}
if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
$v_content_compressed = @fread($v_file, $p_header['size']);
$p_header['crc'] = @crc32($v_content_compressed);
$p_header['compressed_size'] = $p_header['size'];
$p_header['compression'] = 0;
}
else {
$v_content = @fread($v_file, $p_header['size']);
$p_header['crc'] = @crc32($v_content);
$v_content_compressed = @gzdeflate($v_content);
$p_header['compressed_size'] = strlen($v_content_compressed);
$p_header['compression'] = 8;
}
/*
if ((isset($p_options[PCLZIP_OPT_CRYPT]))
&& ($p_options[PCLZIP_OPT_CRYPT] != "")) {
$v_header = 'xxxxxxxxxxxx';
$v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed,
$p_header['compressed_size'],
$v_header,
$p_header['crc'],
"test");
$p_header['compressed_size'] += 12;
$p_header['flag'] = 1;
$v_content_compressed = $v_header.$v_content_compressed;
}
*/
if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
@fclose($v_file);
return $v_result;
}
$v_binary_data = pack('a'.$p_header['compressed_size'],
$v_content_compressed);
@fwrite($this->zip_fd, $v_binary_data, $p_header['compressed_size']);
@fclose($v_file);
}
else {
if (@substr($p_header['stored_filename'], -1) != '/') {
$p_header['stored_filename'] .= '/';
}
$p_header['size'] = 0;
$p_header['external'] = 0x00000010;// Value for a folder : to be checked
if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
{
return $v_result;
}
}
}
if (isset($p_options[PCLZIP_CB_POST_ADD])) {
$v_local_header = array();
$this->privConvertHeader2FileInfo($p_header, $v_local_header);
eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
if ($v_result == 0) {
$v_result = 1;
}
}
return $v_result;
}
function privWriteFileHeader(&$p_header)
{
$v_result=1;
$p_header['offset'] = ftell($this->zip_fd);
$v_date = getdate($p_header['mtime']);
$v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
$v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
$v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
$p_header['version_extracted'], $p_header['flag'],
$p_header['compression'], $v_mtime, $v_mdate,
$p_header['crc'], $p_header['compressed_size'],
$p_header['size'],
strlen($p_header['stored_filename']),
$p_header['extra_len']);
fputs($this->zip_fd, $v_binary_data, 30);
if (strlen($p_header['stored_filename']) != 0)
{
fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
}
if ($p_header['extra_len'] != 0)
{
fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
}
return $v_result;
}
function privWriteCentralFileHeader(&$p_header)
{
$v_result=1;
$v_date = getdate($p_header['mtime']);
$v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
$v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
$v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
$p_header['version'], $p_header['version_extracted'],
$p_header['flag'], $p_header['compression'],
$v_mtime, $v_mdate, $p_header['crc'],
$p_header['compressed_size'], $p_header['size'],
strlen($p_header['stored_filename']),
$p_header['extra_len'], $p_header['comment_len'],
$p_header['disk'], $p_header['internal'],
$p_header['external'], $p_header['offset']);
fputs($this->zip_fd, $v_binary_data, 46);
if (strlen($p_header['stored_filename']) != 0)
{
fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
}
if ($p_header['extra_len'] != 0)
{
fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
}
if ($p_header['comment_len'] != 0)
{
fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
}
return $v_result;
}
function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
{
$v_result=1;
$v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
$p_nb_entries, $p_size,
$p_offset, strlen($p_comment));
fputs($this->zip_fd, $v_binary_data, 22);
if (strlen($p_comment) != 0)
{
fputs($this->zip_fd, $p_comment, strlen($p_comment));
}
return $v_result;
}
function privList(&$p_list)
{
$v_result=1;
if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
{
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
return PclZip::errorCode();
}
$v_central_dir = array();
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
{
return $v_result;
}
@rewind($this->zip_fd);
if (@fseek($this->zip_fd, $v_central_dir['offset']))
{
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
return PclZip::errorCode();
}
for ($i=0; $i<$v_central_dir['entries']; $i++)
{
if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
{
return $v_result;
}
$v_header['index'] = $i;
$this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
unset($v_header);
}
$this->privCloseFd();
return $v_result;
}
function privConvertHeader2FileInfo($p_header, &$p_info)
{
$v_result=1;
$p_info['filename'] = $p_header['filename'];
$p_info['stored_filename'] = $p_header['stored_filename'];
$p_info['size'] = $p_header['size'];
$p_info['compressed_size'] = $p_header['compressed_size'];
$p_info['mtime'] = $p_header['mtime'];
$p_info['comment'] = $p_header['comment'];
$p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
$p_info['index'] = $p_header['index'];
$p_info['status'] = $p_header['status'];
return $v_result;
}
function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
{
$v_result=1;
if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../") && (substr($p_path,1,2)!=":/")))
$p_path = "./".$p_path;
if (($p_path != "./") && ($p_path != "/"))
{
while (substr($p_path, -1) == "/")
{
$p_path = substr($p_path, 0, strlen($p_path)-1);
}
}
if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
{
$p_remove_path .= '/';
}
$p_remove_path_size = strlen($p_remove_path);
if (($v_result = $this->privOpenFd('rb')) != 1)
{
return $v_result;
}
$v_central_dir = array();
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
{
$this->privCloseFd();
return $v_result;
}
$v_pos_entry = $v_central_dir['offset'];
$j_start = 0;
for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
{
@rewind($this->zip_fd);
if (@fseek($this->zip_fd, $v_pos_entry))
{
$this->privCloseFd();
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
return PclZip::errorCode();
}
$v_header = array();
if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
{
$this->privCloseFd();
return $v_result;
}
$v_header['index'] = $i;
$v_pos_entry = ftell($this->zip_fd);
$v_extract = false;
if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
&& ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
&& (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
$v_extract = true;
}
}
elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
$v_extract = true;
}
}
}
else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
&& ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
$v_extract = true;
}
}
else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
&& ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
$v_extract = true;
}
}
else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
&& ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
$v_extract = true;
}
if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
$j_start = $j+1;
}
if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
break;
}
}
}
else {
$v_extract = true;
}
// ----- Check compression method
if ( ($v_extract)
&& ( ($v_header['compression'] != 8)
&& ($v_header['compression'] != 0))) {
$v_header['status'] = 'unsupported_compression';
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
"Filename '".$v_header['stored_filename']."' is "
."compressed by an unsupported compression "
."method (".$v_header['compression'].") ");
return PclZip::errorCode();
}
}
// ----- Check encrypted files
if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
$v_header['status'] = 'unsupported_encryption';
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
"Unsupported encryption for "
." filename '".$v_header['stored_filename']
."'");
return PclZip::errorCode();
}
}
if (($v_extract) && ($v_header['status'] != 'ok')) {
$v_result = $this->privConvertHeader2FileInfo($v_header,
$p_file_list[$v_nb_extracted++]);
if ($v_result != 1) {
$this->privCloseFd();
return $v_result;
}
$v_extract = false;
}
if ($v_extract)
{
@rewind($this->zip_fd);
if (@fseek($this->zip_fd, $v_header['offset']))
{
$this->privCloseFd();
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
return PclZip::errorCode();
}
if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
$v_result1 = $this->privExtractFileAsString($v_header, $v_string);
if ($v_result1 < 1) {
$this->privCloseFd();
return $v_result1;
}
if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
{
$this->privCloseFd();
return $v_result;
}
$p_file_list[$v_nb_extracted]['content'] = $v_string;
$v_nb_extracted++;
if ($v_result1 == 2) {
break;
}
}
elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
&& ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
$v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
if ($v_result1 < 1) {
$this->privCloseFd();
return $v_result1;
}
if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
$this->privCloseFd();
return $v_result;
}
if ($v_result1 == 2) {
break;
}
}
else {
$v_result1 = $this->privExtractFile($v_header,
$p_path, $p_remove_path,
$p_remove_all_path,
$p_options);
if ($v_result1 < 1) {
$this->privCloseFd();
return $v_result1;
}
if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
{
$this->privCloseFd();
return $v_result;
}
if ($v_result1 == 2) {
break;
}
}
}
}
$this->privCloseFd();
return $v_result;
}
//
function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
{
$v_result=1;
if (($v_result = $this->privReadFileHeader($v_header)) != 1)
{
return $v_result;
}
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
}
if ($p_remove_all_path == true) {
$p_entry['filename'] = basename($p_entry['filename']);
}
else if ($p_remove_path != "")
{
if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
{
$p_entry['status'] = "filtered";
return $v_result;
}
$p_remove_path_size = strlen($p_remove_path);
if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
{
$p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
}
}
if ($p_path != '')
{
$p_entry['filename'] = $p_path."/".$p_entry['filename'];
}
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
$v_local_header = array();
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
if ($v_result == 0) {
$p_entry['status'] = "skipped";
$v_result = 1;
}
if ($v_result == 2) {
$p_entry['status'] = "aborted";
$v_result = PCLZIP_ERR_USER_ABORTED;
}
$p_entry['filename'] = $v_local_header['filename'];
}
if ($p_entry['status'] == 'ok') {
if (file_exists($p_entry['filename']))
{
if (is_dir($p_entry['filename']))
{
$p_entry['status'] = "already_a_directory";
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
"Filename '".$p_entry['filename']."' is "
."already used by an existing directory");
return PclZip::errorCode();
}
}
else if (!is_writeable($p_entry['filename']))
{
$p_entry['status'] = "write_protected";
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
"Filename '".$p_entry['filename']."' exists "
."and is write protected");
return PclZip::errorCode();
}
}
else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
{
if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
&& ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
}
else {
$p_entry['status'] = "newer_exist";
if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
&& ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
"Newer version of '".$p_entry['filename']."' exists "
."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
return PclZip::errorCode();
}
}
}
else {
}
}
else {
if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
$v_dir_to_check = $p_entry['filename'];
else if (!strstr($p_entry['filename'], "/"))
$v_dir_to_check = "";
else
$v_dir_to_check = dirname($p_entry['filename']);
if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
$p_entry['status'] = "path_creation_fail";
$v_result = 1;
}
}
}
if ($p_entry['status'] == 'ok') {
if (!(($p_entry['external']&0x00000010)==0x00000010))
{
if ($p_entry['compression'] == 0) {
// ----- Opening destination file
if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
{
$p_entry['status'] = "write_error";
return $v_result;
}
$v_size = $p_entry['compressed_size'];
while ($v_size != 0)
{
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = fread($this->zip_fd, $v_read_size);
$v_binary_data = pack('a'.$v_read_size, $v_buffer);
@fwrite($v_dest_file, $v_binary_data, $v_read_size);
$v_size -= $v_read_size;
}
fclose($v_dest_file);
touch($p_entry['filename'], $p_entry['mtime']);
}
else {
if (($p_entry['flag'] & 1) == 1) {
/*
$v_encryption_header = @fread($this->zip_fd, 12);
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12);
$this->privDecrypt($v_encryption_header, $v_buffer,
$p_entry['compressed_size']-12, $p_entry['crc']);
*/
}
else {
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
}
$v_file_content = @gzinflate($v_buffer);
unset($v_buffer);
if ($v_file_content === FALSE) {
$p_entry['status'] = "error";
return $v_result;
}
if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
$p_entry['status'] = "write_error";
return $v_result;
}
@fwrite($v_dest_file, $v_file_content, $p_entry['size']);
unset($v_file_content);
@fclose($v_dest_file);
@touch($p_entry['filename'], $p_entry['mtime']);
}
if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
@chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
}
}
}
// ----- Change abort status
if ($p_entry['status'] == "aborted") {
$p_entry['status'] = "skipped";
}
elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
$v_local_header = array();
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
if ($v_result == 2) {
$v_result = PCLZIP_ERR_USER_ABORTED;
}
}
return $v_result;
}
function privExtractFileInOutput(&$p_entry, &$p_options)
{
$v_result=1;
if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
return $v_result;
}
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
}
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
$v_local_header = array();
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
if ($v_result == 0) {
$p_entry['status'] = "skipped";
$v_result = 1;
}
if ($v_result == 2) {
$p_entry['status'] = "aborted";
$v_result = PCLZIP_ERR_USER_ABORTED;
}
$p_entry['filename'] = $v_local_header['filename'];
}
if ($p_entry['status'] == 'ok') {
if (!(($p_entry['external']&0x00000010)==0x00000010)) {
if ($p_entry['compressed_size'] == $p_entry['size']) {
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
echo $v_buffer;
unset($v_buffer);
}
else {
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
$v_file_content = gzinflate($v_buffer);
unset($v_buffer);
echo $v_file_content;
unset($v_file_content);
}
}
}
// ----- Change abort status
if ($p_entry['status'] == "aborted") {
$p_entry['status'] = "skipped";
}
elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
$v_local_header = array();
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
if ($v_result == 2) {
$v_result = PCLZIP_ERR_USER_ABORTED;
}
}
return $v_result;
}
function privExtractFileAsString(&$p_entry, &$p_string)
{
$v_result=1;
$v_header = array();
if (($v_result = $this->privReadFileHeader($v_header)) != 1)
{
return $v_result;
}
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
}
if (!(($p_entry['external']&0x00000010)==0x00000010))
{
if ($p_entry['compressed_size'] == $p_entry['size'])
{
$p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
}
else
{
$v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
if (($p_string = @gzinflate($v_data)) === FALSE) {
}
}
}
else {
}
return $v_result;
}
function privReadFileHeader(&$p_header)
{
$v_result=1;
$v_binary_data = @fread($this->zip_fd, 4);
$v_data = unpack('Vid', $v_binary_data);
if ($v_data['id'] != 0x04034b50)
{
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
return PclZip::errorCode();
}
$v_binary_data = fread($this->zip_fd, 26);
if (strlen($v_binary_data) != 26)
{
$p_header['filename'] = "";
$p_header['status'] = "invalid_header";
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
return PclZip::errorCode();
}
$v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
$p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
if ($v_data['extra_len'] != 0) {
$p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
}
else {
$p_header['extra'] = '';
}
$p_header['version_extracted'] = $v_data['version'];
$p_header['compression'] = $v_data['compression'];
$p_header['size'] = $v_data['size'];
$p_header['compressed_size'] = $v_data['compressed_size'];
$p_header['crc'] = $v_data['crc'];
$p_header['flag'] = $v_data['flag'];
$p_header['mdate'] = $v_data['mdate'];
$p_header['mtime'] = $v_data['mtime'];
if ($p_header['mdate'] && $p_header['mtime'])
{
$v_hour = ($p_header['mtime'] & 0xF800) >> 11;
$v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
$v_seconde = ($p_header['mtime'] & 0x001F)*2;
$v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
$v_month = ($p_header['mdate'] & 0x01E0) >> 5;
$v_day = $p_header['mdate'] & 0x001F;
$p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
}
else
{
$p_header['mtime'] = time();
}
$p_header['stored_filename'] = $p_header['filename'];
$p_header['status'] = "ok";
return $v_result;
}
function privReadCentralFileHeader(&$p_header)
{
$v_result=1;
$v_binary_data = @fread($this->zip_fd, 4);
$v_data = unpack('Vid', $v_binary_data);
if ($v_data['id'] != 0x02014b50)
{
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
return PclZip::errorCode();
}
$v_binary_data = fread($this->zip_fd, 42);
if (strlen($v_binary_data) != 42)
{
$p_header['filename'] = "";
$p_header['status'] = "invalid_header";
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
return PclZip::errorCode();
}
$p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
if ($p_header['filename_len'] != 0)
$p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
else
$p_header['filename'] = '';
if ($p_header['extra_len'] != 0)
$p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
else
$p_header['extra'] = '';
if ($p_header['comment_len'] != 0)
$p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
else
$p_header['comment'] = '';
if ($p_header['mdate'] && $p_header['mtime'])
{
$v_hour = ($p_header['mtime'] & 0xF800) >> 11;
$v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
$v_seconde = ($p_header['mtime'] & 0x001F)*2;
$v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
$v_month = ($p_header['mdate'] & 0x01E0) >> 5;
$v_day = $p_header['mdate'] & 0x001F;
$p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
}
else
{
$p_header['mtime'] = time();
}
$p_header['stored_filename'] = $p_header['filename'];
$p_header['status'] = 'ok';
if (substr($p_header['filename'], -1) == '/') {
$p_header['external'] = 0x00000010;
}
return $v_result;
}
function privCheckFileHeaders(&$p_local_header, &$p_central_header)
{
$v_result=1;
// ----- Check the static values
// TBC
if ($p_local_header['filename'] != $p_central_header['filename']) {
}
if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
}
if ($p_local_header['flag'] != $p_central_header['flag']) {
}
if ($p_local_header['compression'] != $p_central_header['compression']) {
}
if ($p_local_header['mtime'] != $p_central_header['mtime']) {
}
if ( isset($p_local_header['filename_len']) && $p_local_header['filename_len'] != $p_central_header['filename_len']) {
}
// ----- Look for flag bit 3
if (($p_local_header['flag'] & 8) == 8) {
$p_local_header['size'] = $p_central_header['size'];
$p_local_header['compressed_size'] = $p_central_header['compressed_size'];
$p_local_header['crc'] = $p_central_header['crc'];
}
return $v_result;
}
function privReadEndCentralDir(&$p_central_dir)
{
$v_result=1;
$v_size = filesize($this->zipname);
@fseek($this->zip_fd, $v_size);
if (@ftell($this->zip_fd) != $v_size)
{
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
return PclZip::errorCode();
}
$v_found = 0;
if ($v_size > 26) {
@fseek($this->zip_fd, $v_size-22);
if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
{
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
return PclZip::errorCode();
}
$v_binary_data = @fread($this->zip_fd, 4);
$v_data = @unpack('Vid', $v_binary_data);
if ($v_data['id'] == 0x06054b50) {
$v_found = 1;
}
$v_pos = ftell($this->zip_fd);
}
if (!$v_found) {
$v_maximum_size = 65557;// 0xFFFF + 22;
if ($v_maximum_size > $v_size)
$v_maximum_size = $v_size;
@fseek($this->zip_fd, $v_size-$v_maximum_size);
if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
{
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
return PclZip::errorCode();
}
$v_pos = ftell($this->zip_fd);
$v_bytes = 0x00000000;
while ($v_pos < $v_size)
{
$v_byte = @fread($this->zip_fd, 1);
$v_bytes = ($v_bytes << 8) | Ord($v_byte);
if ($v_bytes == 0x504b0506)
{
$v_pos++;
break;
}
$v_pos++;
}
if ($v_pos == $v_size)
{
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
return PclZip::errorCode();
}
}
$v_binary_data = fread($this->zip_fd, 18);
if (strlen($v_binary_data) != 18)
{
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
return PclZip::errorCode();
}
$v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
// ----- Removed in release 2.2 see readme file
// The check of the file size is a little too strict.
// Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
// While decrypted, zip has training 0 bytes
if (0) {
PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
'The central dir is not at the end of the archive.'
.' Some trailing bytes exists after the archive.');
return PclZip::errorCode();
}
}
if ($v_data['comment_size'] != 0)
$p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
else
$p_central_dir['comment'] = '';
$p_central_dir['entries'] = $v_data['entries'];
$p_central_dir['disk_entries'] = $v_data['disk_entries'];
$p_central_dir['offset'] = $v_data['offset'];
$p_central_dir['size'] = $v_data['size'];
$p_central_dir['disk'] = $v_data['disk'];
$p_central_dir['disk_start'] = $v_data['disk_start'];
return $v_result;
}
function privDeleteByRule(&$p_result_list, &$p_options)
{
$v_result=1;
$v_list_detail = array();
if (($v_result=$this->privOpenFd('rb')) != 1)
{
return $v_result;
}
$v_central_dir = array();
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
{
$this->privCloseFd();
return $v_result;
}
@rewind($this->zip_fd);
$v_pos_entry = $v_central_dir['offset'];
@rewind($this->zip_fd);
if (@fseek($this->zip_fd, $v_pos_entry))
{
$this->privCloseFd();
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
return PclZip::errorCode();
}
$v_header_list = array();
$j_start = 0;
for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
{
$v_header_list[$v_nb_extracted] = array();
if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
{
$this->privCloseFd();
return $v_result;
}
$v_header_list[$v_nb_extracted]['index'] = $i;
$v_found = false;
if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
&& ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
&& (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
$v_found = true;
}
elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
&& ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
$v_found = true;
}
}
elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
$v_found = true;
}
}
}
else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
&& ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
$v_found = true;
}
}
else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
&& ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
$v_found = true;
}
}
else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
&& ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
$v_found = true;
}
if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
$j_start = $j+1;
}
if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
break;
}
}
}
if ($v_found)
{
unset($v_header_list[$v_nb_extracted]);
}
else
{
$v_nb_extracted++;
}
}
if ($v_nb_extracted > 0) {
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
$v_temp_zip = new PclZip($v_zip_temp_name);
if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
$this->privCloseFd();
return $v_result;
}
for ($i=0; $i<sizeof($v_header_list); $i++) {
@rewind($this->zip_fd);
if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
$this->privCloseFd();
$v_temp_zip->privCloseFd();
@unlink($v_zip_temp_name);
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
return PclZip::errorCode();
}
$v_local_header = array();
if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
$this->privCloseFd();
$v_temp_zip->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
if ($this->privCheckFileHeaders($v_local_header,
$v_header_list[$i]) != 1) {
}
unset($v_local_header);
if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
$this->privCloseFd();
$v_temp_zip->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
$this->privCloseFd();
$v_temp_zip->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
}
$v_offset = @ftell($v_temp_zip->zip_fd);
for ($i=0; $i<sizeof($v_header_list); $i++) {
if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
$v_temp_zip->privCloseFd();
$this->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
$v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
}
$v_comment = '';
if (isset($p_options[PCLZIP_OPT_COMMENT])) {
$v_comment = $p_options[PCLZIP_OPT_COMMENT];
}
$v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
unset($v_header_list);
$v_temp_zip->privCloseFd();
$this->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
$v_temp_zip->privCloseFd();
$this->privCloseFd();
@unlink($this->zipname);
PclZipUtilRename($v_zip_temp_name, $this->zipname);
unset($v_temp_zip);
}
else if ($v_central_dir['entries'] != 0) {
$this->privCloseFd();
if (($v_result = $this->privOpenFd('wb')) != 1) {
return $v_result;
}
if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
return $v_result;
}
$this->privCloseFd();
}
return $v_result;
}
function privDirCheck($p_dir, $p_is_dir=false)
{
$v_result = 1;
if (($p_is_dir) && (substr($p_dir, -1)=='/'))
{
$p_dir = substr($p_dir, 0, strlen($p_dir)-1);
}
if ((is_dir($p_dir)) || ($p_dir == ""))
{
return 1;
}
$p_parent_dir = dirname($p_dir);
if ($p_parent_dir != $p_dir)
{
if ($p_parent_dir != "")
{
if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
{
return $v_result;
}
}
}
if (!@mkdir($p_dir, 0777))
{
PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
return PclZip::errorCode();
}
return $v_result;
}
function privMerge(&$p_archive_to_add)
{
$v_result=1;
if (!is_file($p_archive_to_add->zipname))
{
$v_result = 1;
return $v_result;
}
if (!is_file($this->zipname))
{
$v_result = $this->privDuplicate($p_archive_to_add->zipname);
return $v_result;
}
if (($v_result=$this->privOpenFd('rb')) != 1)
{
return $v_result;
}
$v_central_dir = array();
if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
{
$this->privCloseFd();
return $v_result;
}
@rewind($this->zip_fd);
if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
{
$this->privCloseFd();
return $v_result;
}
$v_central_dir_to_add = array();
if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
{
$this->privCloseFd();
$p_archive_to_add->privCloseFd();
return $v_result;
}
@rewind($p_archive_to_add->zip_fd);
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
{
$this->privCloseFd();
$p_archive_to_add->privCloseFd();
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
return PclZip::errorCode();
}
$v_size = $v_central_dir['offset'];
while ($v_size != 0)
{
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = fread($this->zip_fd, $v_read_size);
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
$v_size -= $v_read_size;
}
$v_size = $v_central_dir_to_add['offset'];
while ($v_size != 0)
{
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
$v_size -= $v_read_size;
}
$v_offset = @ftell($v_zip_temp_fd);
$v_size = $v_central_dir['size'];
while ($v_size != 0)
{
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = @fread($this->zip_fd, $v_read_size);
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
$v_size -= $v_read_size;
}
$v_size = $v_central_dir_to_add['size'];
while ($v_size != 0)
{
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
@fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
$v_size -= $v_read_size;
}
$v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
$v_size = @ftell($v_zip_temp_fd)-$v_offset;
$v_swap = $this->zip_fd;
$this->zip_fd = $v_zip_temp_fd;
$v_zip_temp_fd = $v_swap;
if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
{
$this->privCloseFd();
$p_archive_to_add->privCloseFd();
@fclose($v_zip_temp_fd);
$this->zip_fd = null;
unset($v_header_list);
return $v_result;
}
$v_swap = $this->zip_fd;
$this->zip_fd = $v_zip_temp_fd;
$v_zip_temp_fd = $v_swap;
$this->privCloseFd();
$p_archive_to_add->privCloseFd();
@fclose($v_zip_temp_fd);
@unlink($this->zipname);
PclZipUtilRename($v_zip_temp_name, $this->zipname);
return $v_result;
}
function privDuplicate($p_archive_filename)
{
$v_result=1;
if (!is_file($p_archive_filename))
{
$v_result = 1;
return $v_result;
}
if (($v_result=$this->privOpenFd('wb')) != 1)
{
return $v_result;
}
if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
{
$this->privCloseFd();
PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
return PclZip::errorCode();
}
$v_size = filesize($p_archive_filename);
while ($v_size != 0)
{
$v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = fread($v_zip_temp_fd, $v_read_size);
@fwrite($this->zip_fd, $v_buffer, $v_read_size);
$v_size -= $v_read_size;
}
$this->privCloseFd();
@fclose($v_zip_temp_fd);
return $v_result;
}
function privErrorLog($p_error_code=0, $p_error_string='')
{
if (PCLZIP_ERROR_EXTERNAL == 1) {
PclError($p_error_code, $p_error_string);
}
else {
$this->error_code = $p_error_code;
$this->error_string = $p_error_string;
}
}
function privErrorReset()
{
if (PCLZIP_ERROR_EXTERNAL == 1) {
PclErrorReset();
}
else {
$this->error_code = 0;
$this->error_string = '';
}
}
function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc)
{
$v_result=1;
$v_pwd = "test";
$p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header,
$p_crc, $v_pwd);
return $v_result;
}
}
function PclZipUtilPathReduction($p_dir)
{
$v_result = "";
if ($p_dir != "")
{
$v_list = explode("/", $p_dir);
for ($i=sizeof($v_list)-1; $i>=0; $i--)
{
if ($v_list[$i] == ".")
{
}
else if ($v_list[$i] == "..")
{
$i--;
}
else if (($v_list[$i] == "") && ($i!=(sizeof($v_list)-1)) && ($i!=0))
{
}
else
{
$v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
}
}
}
return $v_result;
}
function PclZipUtilPathInclusion($p_dir, $p_path)
{
$v_result = 1;
$v_list_dir = explode("/", $p_dir);
$v_list_dir_size = sizeof($v_list_dir);
$v_list_path = explode("/", $p_path);
$v_list_path_size = sizeof($v_list_path);
$i = 0;
$j = 0;
while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
if ($v_list_dir[$i] == '') {
$i++;
continue;
}
if ($v_list_path[$j] == '') {
$j++;
continue;
}
if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) {
$v_result = 0;
}
$i++;
$j++;
}
if ($v_result) {
while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
$v_result = 2;
}
else if ($i < $v_list_dir_size) {
$v_result = 0;
}
}
return $v_result;
}
function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
{
$v_result = 1;
if ($p_mode==0)
{
while ($p_size != 0)
{
$v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = @fread($p_src, $v_read_size);
@fwrite($p_dest, $v_buffer, $v_read_size);
$p_size -= $v_read_size;
}
}
else if ($p_mode==1)
{
while ($p_size != 0)
{
$v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = @gzread($p_src, $v_read_size);
@fwrite($p_dest, $v_buffer, $v_read_size);
$p_size -= $v_read_size;
}
}
else if ($p_mode==2)
{
while ($p_size != 0)
{
$v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = @fread($p_src, $v_read_size);
@gzwrite($p_dest, $v_buffer, $v_read_size);
$p_size -= $v_read_size;
}
}
else if ($p_mode==3)
{
while ($p_size != 0)
{
$v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
$v_buffer = @gzread($p_src, $v_read_size);
@gzwrite($p_dest, $v_buffer, $v_read_size);
$p_size -= $v_read_size;
}
}
return $v_result;
}
function PclZipUtilRename($p_src, $p_dest)
{
$v_result = 1;
if (!@rename($p_src, $p_dest)) {
if (!@copy($p_src, $p_dest)) {
$v_result = 0;
}
else if (!@unlink($p_src)) {
$v_result = 0;
}
}
return $v_result;
}
function PclZipUtilOptionText($p_option)
{
$v_list = get_defined_constants();
for (reset($v_list); $v_key = key($v_list); next($v_list)) {
$v_prefix = substr($v_key, 0, 10);
if ((($v_prefix == 'PCLZIP_OPT') || ($v_prefix == 'PCLZIP_CB_'))
&& ($v_list[$v_key] == $p_option)) {
return $v_key;
}
}
$v_result = 'Unknown';
return $v_result;
}
function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
{
if (stristr(php_uname(), 'windows')) {
if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
$p_path = substr($p_path, $v_position+1);
}
if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
$p_path = strtr($p_path, '\\', '/');
}
}
return $p_path;
}
?>
startFile : mwftp5/_hclib/SnoopyStripped.php : 1
<?php
/*************************************************
Stripped version of Snoopy
only methods required by Link Department
Stripped by Algis Alekna
hide@address.com
11 November 2003
Snoopy - the PHP net client
Author: Monte Ohrt <hide@address.com>
Copyright (c): 1999-2000 ispi, all rights reserved
Version: 1.01
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You may contact the author of Snoopy by e-mail at:
hide@address.com
Or, write to:
Monte Ohrt
CTO, ispi
237 S. 70th suite 220
Lincoln, NE 68510
The latest version of Snoopy can be obtained from:
http://snoopy.sourceforge.com
*************************************************/
class Snoopy
{
/**** Public variables ****/
/* user definable vars */
var $host = "www.php.net"; // host name we are connecting to
var $port = 80; // port we are connecting to
var $proxy_host = ""; // proxy host to use
var $proxy_port = ""; // proxy port to use
var $agent = "Snoopy v1.01"; // agent we masquerade as
var $referer = ""; // referer info to pass
var $cookies = array(); // array of cookies to pass
// $cookies["username"]="joe";
var $rawheaders = array(); // array of raw headers to send
// $rawheaders["Content-type"]="text/html";
var $maxredirs = 5; // http redirection depth maximum. 0 = disallow
var $lastredirectaddr = ""; // contains address of last redirected address
var $offsiteok = true; // allows redirection off-site
var $maxframes = 0; // frame content depth maximum. 0 = disallow
var $expandlinks = true; // expand links to fully qualified URLs.
// this only applies to fetchlinks()
// or submitlinks()
var $passcookies = true; // pass set cookies back through redirects
// NOTE: this currently does not respect
// dates, domains or paths.
var $user = ""; // user for http authentication
var $pass = ""; // password for http authentication
// http accept types
var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
var $results = ""; // where the content is put
var $error = ""; // error messages sent here
var $response_code = ""; // response code returned from server
var $headers = array(); // headers returned from server sent here
var $maxlength = 500000; // max return data length (body)
var $read_timeout = 0; // timeout on read operations, in seconds
// supported only since PHP 4 Beta 4
// set to 0 to disallow timeouts
var $timed_out = false; // if a read operation timed out
var $status = 0; // http request status
var $curl_path = "/usr/local/bin/curl";
// Snoopy will use cURL for fetching
// SSL content if a full system path to
// the cURL binary is supplied here.
// set to false if you do not have
// cURL installed. See http://curl.haxx.se
// for details on installing cURL.
// Snoopy does *not* use the cURL
// library functions built into php,
// as these functions are not stable
// as of this Snoopy release.
/**** Private variables ****/
var $_maxlinelen = 4096; // max line length (headers)
var $_httpmethod = "GET"; // default http request method
var $_httpversion = "HTTP/1.0"; // default http request version
var $_submit_method = "POST"; // default submit method
var $_submit_type = "application/x-www-form-urlencoded"; // default submit type
var $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type
var $_redirectaddr = false; // will be set if page fetched is a redirect
var $_redirectdepth = 0; // increments on an http redirect
var $_frameurls = array(); // frame src urls
var $_framedepth = 0; // increments on frame depth
var $_isproxy = false; // set if using a proxy server
var $_fp_timeout = 30; // timeout for socket connection
/*======================================================================*\
Function: fetch
Purpose: fetch the contents of a web page
(and possibly other protocols in the
future like ftp, nntp, gopher, etc.)
Input: $URI the location of the page to fetch
Output: $this->results the output text from the fetch
\*======================================================================*/
function fetch($URI)
{
//preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS);
$URI_PARTS = parse_url($URI);
if (!empty($URI_PARTS["user"]))
$this->user = $URI_PARTS["user"];
if (!empty($URI_PARTS["pass"]))
$this->pass = $URI_PARTS["pass"];
switch($URI_PARTS["scheme"])
{
case "http":
$this->host = $URI_PARTS["host"];
if(!empty($URI_PARTS["port"]))
$this->port = $URI_PARTS["port"];
if($this->_connect($fp))
{
if($this->_isproxy)
{
// using proxy, send entire URI
$this->_httprequest($URI,$fp,$URI,$this->_httpmethod);
}
else
{
$path = $URI_PARTS["path"].( isset($URI_PARTS["query"]) ? "?".$URI_PARTS["query"] : "");
// no proxy, send only the path
$this->_httprequest($path, $fp, $URI, $this->_httpmethod);
}
$this->_disconnect($fp);
if($this->_redirectaddr)
{
/* url was redirected, check if we've hit the max depth */
if($this->maxredirs > $this->_redirectdepth)
{
// only follow redirect if it's on this site, or offsiteok is true
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
{
/* follow the redirect */
$this->_redirectdepth++;
$this->lastredirectaddr=$this->_redirectaddr;
$this->fetch($this->_redirectaddr);
}
}
}
if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
{
$frameurls = $this->_frameurls;
$this->_frameurls = array();
while(list(,$frameurl) = each($frameurls))
{
if($this->_framedepth < $this->maxframes)
{
$this->fetch($frameurl);
$this->_framedepth++;
}
else
break;
}
}
}
else
{
return false;
}
return true;
break;
case "https":
// if(!$this->curl_path || (!is_executable($this->curl_path)))
// return false;
if(!$this->curl_path )
return false;
$this->host = $URI_PARTS["host"];
if(!empty($URI_PARTS["port"]))
$this->port = $URI_PARTS["port"];
if($this->_isproxy)
{
// using proxy, send entire URI
$this->_httpsrequest($URI,$URI,$this->_httpmethod);
}
else
{
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
// no proxy, send only the path
$this->_httpsrequest($path, $URI, $this->_httpmethod);
}
if($this->_redirectaddr)
{
/* url was redirected, check if we've hit the max depth */
if($this->maxredirs > $this->_redirectdepth)
{
// only follow redirect if it's on this site, or offsiteok is true
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
{
/* follow the redirect */
$this->_redirectdepth++;
$this->lastredirectaddr=$this->_redirectaddr;
$this->fetch($this->_redirectaddr);
}
}
}
if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
{
$frameurls = $this->_frameurls;
$this->_frameurls = array();
while(list(,$frameurl) = each($frameurls))
{
if($this->_framedepth < $this->maxframes)
{
$this->fetch($frameurl);
$this->_framedepth++;
}
else
break;
}
}
return true;
break;
default:
// not a valid protocol
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
return false;
break;
}
return true;
}
/*======================================================================*\
Function: fetchlinks
Purpose: fetch the links from a web page
Input: $URI where you are fetching from
Output: $this->results an array of the URLs
\*======================================================================*/
function fetchlinks($URI){
if ( $this->fetch($URI) ){
if( is_array($this->results) ){
for($x=0;$x<count($this->results);$x++)
$this->results[$x] = $this->_striplinks($this->results[$x]);
}
else
$this->results = $this->_striplinks($this->results);
if($this->expandlinks)
$this->results = $this->_expandlinks($this->results, $URI);
return true;
}
else {
return false;
}
}
/*======================================================================*\
Function: fetchtext
Purpose: fetch the text from a web page, stripping the links
Input: $URI where you are fetching from
Output: $this->results the text from the web page
\*======================================================================*/
function fetchtext($URI)
{
if($this->fetch($URI))
{
if(is_array($this->results))
{
for($x=0;$x<count($this->results);$x++)
$this->results[$x] = $this->_striptext($this->results[$x]);
}
else
$this->results = $this->_striptext($this->results);
return true;
}
else
return false;
}
/*======================================================================*\
Private functions
\*======================================================================*/
/*======================================================================*\
Function: _striplinks
Purpose: strip the hyperlinks from an html document
Input: $document document to strip.
Output: $match an array of the links
\*======================================================================*/
function _striplinks($document)
{
$match = array();
preg_match_all("'<\s*a\s.*?href\s*=\s* # find <a href=
([\"\'])? # find single or double quote
(?(1) (.*?)\\1 | ([^\s\>]+)) # if quote found, match up to next matching
# quote, otherwise match up to next space
'isx",$document,$links);
// catenate the non-empty matches from the conditional subpattern
while(list($key,$val) = each($links[2]))
{
if(!empty($val))
$match[] = $val;
}
while(list($key,$val) = each($links[3]))
{
if(!empty($val))
$match[] = $val;
}
// return the links
return $match;
}
/*======================================================================*\
Function: _striptext
Purpose: strip the text from an html document
Input: $document document to strip.
Output: $text the resulting text
\*======================================================================*/
function _striptext($document)
{
// I didn't use preg eval (//e) since that is only available in PHP 4.0.
// so, list your entities one by one here. I included some of the
// more common ones.
$search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // strip out html tags
"'([\r\n])[\s]+'", // strip out white space
"'&(quot|#34|#034|#x22);'i", // replace html entities
"'&(amp|#38|#038|#x26);'i", // added hexadecimal values
"'&(lt|#60|#060|#x3c);'i",
"'&(gt|#62|#062|#x3e);'i",
"'&(nbsp|#160|#xa0);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&(reg|#174);'i",
"'&(deg|#176);'i",
"'&(#39|#039|#x27);'",
"'&(euro|#8364);'i", // europe
"'&a(uml|UML);'", // german
"'&o(uml|UML);'",
"'&u(uml|UML);'",
"'&A(uml|UML);'",
"'&O(uml|UML);'",
"'&U(uml|UML);'",
"'ß'i",
);
$replace = array( "",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
chr(174),
chr(176),
chr(39),
chr(128),
"ä",
"ö",
"ü",
"Ä",
"Ö",
"Ü",
"ß",
);
$text = preg_replace($search,$replace,$document);
return $text;
}
/*======================================================================*\
Function: _expandlinks
Purpose: expand each link into a fully qualified URL
Input: $links the links to qualify
$URI the full URI to get the base from
Output: $expandedLinks the expanded links
\*======================================================================*/
function _expandlinks($links,$URI)
{
preg_match("/^[^\?]+/",$URI,$match);
$match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);
$search = array( "|^http://".preg_quote($this->host)."|i",
"|^(?!http://)(\/)?(?!mailto:)|i",
"|/\./|",
"|/[^\/]+/\.\./|"
);
$replace = array( "",
$match."/",
"/",
"/"
);
$expandedLinks = preg_replace($search, $replace, $links);
return $expandedLinks;
}
/*======================================================================*\
Function: _httprequest
Purpose: go get the http data from the server
Input: $url the url to fetch
$fp the current open file pointer
$URI the full URI
$body body contents to send if any (POST)
Output:
\*======================================================================*/
function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="")
{
$cookie_headers = '';
if($this->passcookies && $this->_redirectaddr)
$this->setcookies();
$URI_PARTS = parse_url($URI);
if(empty($url))
$url = "/";
$headers = $http_method." ".$url." ".$this->_httpversion."\r\n";
if(!empty($this->agent))
$headers .= "User-Agent: ".$this->agent."\r\n";
if(!empty($this->host) && !isset($this->rawheaders['Host']))
$headers .= "Host: ".$this->host."\r\n";
if(!empty($this->accept))
$headers .= "Accept: ".$this->accept."\r\n";
if(!empty($this->referer))
$headers .= "Referer: ".$this->referer."\r\n";
if(!empty($this->cookies))
{
if(!is_array($this->cookies))
$this->cookies = (array)$this->cookies;
reset($this->cookies);
if ( count($this->cookies) > 0 ) {
$cookie_headers .= 'Cookie: ';
foreach ( $this->cookies as $cookieKey => $cookieVal ) {
$cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; ";
}
$headers .= substr($cookie_headers,0,-2) . "\r\n";
}
}
if(!empty($this->rawheaders))
{
if(!is_array($this->rawheaders))
$this->rawheaders = (array)$this->rawheaders;
while(list($headerKey,$headerVal) = each($this->rawheaders))
$headers .= $headerKey.": ".$headerVal."\r\n";
}
if(!empty($content_type)) {
$headers .= "Content-type: $content_type";
if ($content_type == "multipart/form-data")
$headers .= "; boundary=".$this->_mime_boundary;
$headers .= "\r\n";
}
if(!empty($body))
$headers .= "Content-length: ".strlen($body)."\r\n";
if(!empty($this->user) || !empty($this->pass))
$headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n";
$headers .= "\r\n";
// set the read timeout if needed
if ($this->read_timeout > 0)
socket_set_timeout($fp, $this->read_timeout);
$this->timed_out = false;
fwrite($fp,$headers.$body,strlen($headers.$body));
//echo "<BR> ---- REQUEST START ---- <BR>";
//echo nl2br($headers.$body) . "<BR>";
//echo "<BR> ---- REQUEST END ---- <BR>";
$this->_redirectaddr = false;
unset($this->headers);
//echo "<BR> ---- RESPONSE START ---- <BR>";
while($currentHeader = fgets($fp,$this->_maxlinelen))
{
//echo "$currentHeader<BR>";
if ($this->read_timeout > 0 && $this->_check_timeout($fp))
{
$this->status=-100;
return false;
}
if($currentHeader == "\r\n")
break;
// if a header begins with Location: or URI:, set the redirect
if(preg_match("/^(Location:|URI:)/i",$currentHeader))
{
// get URL portion of the redirect
preg_match("/^(Location:|URI:)[ ]+(.*)/",chop($currentHeader),$matches);
// look for :// in the Location header to see if hostname is included
if(!preg_match("|\:\/\/|",$matches[2]))
{
// no host in the path, so prepend
$this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
// eliminate double slash
if(!preg_match("|^/|",$matches[2]))
$this->_redirectaddr .= "/".$matches[2];
else
$this->_redirectaddr .= $matches[2];
}
else
$this->_redirectaddr = $matches[2];
}
if(preg_match("|^HTTP/|",$currentHeader))
{
if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
{
$this->status= $status[1];
}
$this->response_code = $currentHeader;
}
$this->headers[] = $currentHeader;
}
//echo "<BR> ---- RESPONSE END ---- <BR>";
$results = '';
do {
$_data = fread($fp, $this->maxlength);
if (strlen($_data) == 0) {
break;
}
$results .= $_data;
} while(true);
if ($this->read_timeout > 0 && $this->_check_timeout($fp))
{
$this->status=-100;
return false;
}
// check if there is a a redirect meta tag
if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
{
$this->_redirectaddr = $this->_expandlinks($match[1],$URI);
}
// have we hit our frame depth and is there frame src to fetch?
if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match))
{
$this->results[] = $results;
for($x=0; $x<count($match[1]); $x++)
$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
}
// have we already fetched framed content?
elseif(is_array($this->results))
$this->results[] = $results;
// no framed content
else
$this->results = $results;
return true;
}
/*======================================================================*\
Function: _httpsrequest
Purpose: go get the https data from the server using curl
Input: $url the url to fetch
$URI the full URI
$body body contents to send if any (POST)
Output:
\*======================================================================*/
function _httpsrequest($url,$URI,$http_method,$content_type="",$body="")
{
if($this->passcookies && $this->_redirectaddr)
$this->setcookies();
$headers = array();
$URI_PARTS = parse_url($URI);
if(empty($url))
$url = "/";
// GET ... header not needed for curl
//$headers[] = $http_method." ".$url." ".$this->_httpversion;
if(!empty($this->agent))
$headers[] = "User-Agent: ".$this->agent;
if(!empty($this->host))
$headers[] = "Host: ".$this->host;
if(!empty($this->accept))
$headers[] = "Accept: ".$this->accept;
if(!empty($this->referer))
$headers[] = "Referer: ".$this->referer;
if(!empty($this->cookies))
{
if(!is_array($this->cookies))
$this->cookies = (array)$this->cookies;
reset($this->cookies);
if ( count($this->cookies) > 0 ) {
$cookie_str = 'Cookie: ';
foreach ( $this->cookies as $cookieKey => $cookieVal ) {
$cookie_str .= $cookieKey."=".urlencode($cookieVal)."; ";
}
$headers[] = substr($cookie_str,0,-2);
}
}
if(!empty($this->rawheaders))
{
if(!is_array($this->rawheaders))
$this->rawheaders = (array)$this->rawheaders;
while(list($headerKey,$headerVal) = each($this->rawheaders))
$headers[] = $headerKey.": ".$headerVal;
}
if(!empty($content_type)) {
if ($content_type == "multipart/form-data")
$headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary;
else
$headers[] = "Content-type: $content_type";
}
if(!empty($body))
$headers[] = "Content-length: ".strlen($body);
if(!empty($this->user) || !empty($this->pass))
$headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass);
for($curr_header = 0; $curr_header < count($headers); $curr_header++)
$cmdline_params .= " -H \"".$headers[$curr_header]."\"";
if(!empty($body))
$cmdline_params .= " -d \"$body\"";
if($this->read_timeout > 0)
$cmdline_params .= " -m ".$this->read_timeout;
$headerfile = uniqid(time());
exec($this->curl_path." -D \"/tmp/$headerfile\"".$cmdline_params." ".$URI,$results,$return);
if($return)
{
$this->error = "Error: cURL could not retrieve the document, error $return.";
return false;
}
$results = implode("\r\n",$results);
$result_headers = file("/tmp/$headerfile");
$this->_redirectaddr = false;
unset($this->headers);
for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++)
{
// if a header begins with Location: or URI:, set the redirect
if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader]))
{
// get URL portion of the redirect
preg_match("/^(Location: |URI:)\s+(.*)/",chop($result_headers[$currentHeader]),$matches);
// look for :// in the Location header to see if hostname is included
if(!preg_match("|\:\/\/|",$matches[2]))
{
// no host in the path, so prepend
$this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
// eliminate double slash
if(!preg_match("|^/|",$matches[2]))
$this->_redirectaddr .= "/".$matches[2];
else
$this->_redirectaddr .= $matches[2];
}
else
$this->_redirectaddr = $matches[2];
}
if(preg_match("|^HTTP/|",$result_headers[$currentHeader]))
$this->response_code = $result_headers[$currentHeader];
$this->headers[] = $result_headers[$currentHeader];
}
// check if there is a a redirect meta tag
if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
{
$this->_redirectaddr = $this->_expandlinks($match[1],$URI);
}
// have we hit our frame depth and is there frame src to fetch?
if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match))
{
$this->results[] = $results;
for($x=0; $x<count($match[1]); $x++)
$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
}
// have we already fetched framed content?
elseif(is_array($this->results))
$this->results[] = $results;
// no framed content
else
$this->results = $results;
unlink("/tmp/$headerfile");
return true;
}
/*======================================================================*\
Function: setcookies()
Purpose: set cookies for a redirection
\*======================================================================*/
function setcookies()
{
for($x=0; $x<count($this->headers); $x++)
{
if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match))
$this->cookies[$match[1]] = $match[2];
}
}
/*======================================================================*\
Function: _check_timeout
Purpose: checks whether timeout has occurred
Input: $fp file pointer
\*======================================================================*/
function _check_timeout($fp)
{
if ($this->read_timeout > 0) {
$fp_status = socket_get_status($fp);
if ($fp_status["timed_out"]) {
$this->timed_out = true;
return true;
}
}
return false;
}
/*======================================================================*\
Function: _connect
Purpose: make a socket connection
Input: $fp file pointer
\*======================================================================*/
function _connect(&$fp)
{
if(!empty($this->proxy_host) && !empty($this->proxy_port))
{
$this->_isproxy = true;
$host = $this->proxy_host;
$port = $this->proxy_port;
}
else
{
$host = $this->host;
$port = $this->port;
}
$this->status = 0;
if($fp = @fsockopen(
$host,
$port,
$errno,
$errstr,
$this->_fp_timeout
))
{
// socket connection succeeded
return true;
}
else
{
// socket connection failed
$this->status = $errno;
switch($errno)
{
case -3:
$this->error="socket creation failed (-3)";
case -4:
$this->error="dns lookup failure (-4)";
case -5:
$this->error="connection refused or timed out (-5)";
default:
$this->error="connection failed (".$errno.")";
}
return false;
}
}
/*======================================================================*\
Function: _disconnect
Purpose: disconnect a socket connection
Input: $fp file pointer
\*======================================================================*/
function _disconnect($fp)
{
return(fclose($fp));
}
}
?>
startFile : mwftp5/_hclib/zip.lib.php : 1
<?php
/* $Id: zip.lib.php 6461 2004-11-03 13:56:52Z garvinhicking $ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Zip file creation class.
* Makes zip files.
*
* Based on :
*
* http://www.zend.com/codex.php?id=535&single=1
* By Eric Mueller <hide@address.com>
*
* http://www.zend.com/codex.php?id=470&single=1
* by Denis125 <hide@address.com>
*
* a patch from Peter Listiak <hide@address.com> for last modified
* date and time of the compressed file
*
* Official ZIP file format: http://www.pkware.com/appnote.txt
*
* @access public
*/
class zipfile
{
/**
* Array to store compressed data
*
* @var array $datasec
*/
var $datasec = array();
/**
* Central directory
*
* @var array $ctrl_dir
*/
var $ctrl_dir = array();
/**
* End of central directory record
*
* @var string $eof_ctrl_dir
*/
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
/**
* Last offset position
*
* @var integer $old_offset
*/
var $old_offset = 0;
function zipfile(){
$this->error = "";
if( ! function_exists('gzcompress') )
$this->error = 'Zlib support is not enabled!';
$this->fileContent = '';
}
/**
* Converts an Unix timestamp to a four byte DOS date and time format (date
* in high two bytes, time in low two bytes allowing magnitude comparison).
*
* @param integer the current Unix timestamp
*
* @return integer the current date in a four byte DOS format
*
* @access private
*/
function unix2DosTime($unixtime = 0) {
$timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
if ($timearray['year'] < 1980) {
$timearray['year'] = 1980;
$timearray['mon'] = 1;
$timearray['mday'] = 1;
$timearray['hours'] = 0;
$timearray['minutes'] = 0;
$timearray['seconds'] = 0;
} // end if
return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
} // end of the 'unix2DosTime()' method
/**
* Adds "file" to archive
*
* @param string file contents
* @param string name of the file in the archive (may contains the path)
* @param integer the current timestamp
*
* @access public
*/
function addFile($data, $name, $time = 0)
{
$name = str_replace('\\', '/', $name);
$dtime = dechex($this->unix2DosTime($time));
$hexdtime = '\x' . $dtime[6] . $dtime[7]
. '\x' . $dtime[4] . $dtime[5]
. '\x' . $dtime[2] . $dtime[3]
. '\x' . $dtime[0] . $dtime[1];
eval('$hexdtime = "' . $hexdtime . '";');
$fr = "\x50\x4b\x03\x04";
$fr .= "\x14\x00"; // ver needed to extract
$fr .= "\x00\x00"; // gen purpose bit flag
$fr .= "\x08\x00"; // compression method
$fr .= $hexdtime; // last mod time and date
// "local file header" segment
$unc_len = strlen($data);
$crc = crc32($data);
$zdata = gzcompress($data);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug
$c_len = strlen($zdata);
$fr .= pack('V', $crc); // crc32
$fr .= pack('V', $c_len); // compressed filesize
$fr .= pack('V', $unc_len); // uncompressed filesize
$fr .= pack('v', strlen($name)); // length of filename
$fr .= pack('v', 0); // extra field length
$fr .= $name;
// "file data" segment
$fr .= $zdata;
// "data descriptor" segment (optional but necessary if archive is not
// served as file)
// nijel(2004-10-19): this seems not to be needed at all and causes
// problems in some cases (bug #1037737)
//$fr .= pack('V', $crc); // crc32
//$fr .= pack('V', $c_len); // compressed filesize
//$fr .= pack('V', $unc_len); // uncompressed filesize
// add this entry to array
$this -> datasec[] = $fr;
// now add to central directory record
$cdrec = "\x50\x4b\x01\x02";
$cdrec .= "\x00\x00"; // version made by
$cdrec .= "\x14\x00"; // version needed to extract
$cdrec .= "\x00\x00"; // gen purpose bit flag
$cdrec .= "\x08\x00"; // compression method
$cdrec .= $hexdtime; // last mod time & date
$cdrec .= pack('V', $crc); // crc32
$cdrec .= pack('V', $c_len); // compressed filesize
$cdrec .= pack('V', $unc_len); // uncompressed filesize
$cdrec .= pack('v', strlen($name) ); // length of filename
$cdrec .= pack('v', 0 ); // extra field length
$cdrec .= pack('v', 0 ); // file comment length
$cdrec .= pack('v', 0 ); // disk number start
$cdrec .= pack('v', 0 ); // internal file attributes
$cdrec .= pack('V', 32 ); // external file attributes - 'archive' bit set
$cdrec .= pack('V', $this -> old_offset ); // relative offset of local header
$this -> old_offset += strlen($fr);
$cdrec .= $name;
// optional extra field, file comment goes here
// save to central directory
$this -> ctrl_dir[] = $cdrec;
} // end of the 'addFile()' method
function getTotalSize(){
if( ! $this->fileContent )
$this->_prepareFileContent();
$totalSize = strlen( $this->fileContent );
return $totalSize;
}
function fread(){
return $this->file();
}
function _prepareFileContent(){
$data = implode('', $this -> datasec);
$ctrldir = implode('', $this -> ctrl_dir);
$this->fileContent =
$data .
$ctrldir .
$this -> eof_ctrl_dir .
pack('v', sizeof($this -> ctrl_dir)) . // total # of entries "on this disk"
pack('v', sizeof($this -> ctrl_dir)) . // total # of entries overall
pack('V', strlen($ctrldir)) . // size of central dir
pack('V', strlen($data)) . // offset to start of central dir
"\x00\x00"; // .zip file comment length
}
function file(){
$data = implode('', $this -> datasec);
$ctrldir = implode('', $this -> ctrl_dir);
if( ! $this->fileContent )
$this->_prepareFileContent();
return $this->fileContent;
}
} // end of the 'zipfile' class
?>
startFile : mwftp5/_hclib/_init.php : 1
<?
define( 'HCLIB_VERSION', '1.0.0' );
class hcLib {
function init( $requeredClasses = array() ){
if( $requeredClasses ){
foreach( $requeredClasses as $class )
$files2include[] = realpath( dirname(__FILE__) . '/' . $class . '.php' );
}
// INCLUDE ALL
$files2include = getDirListing( dirname(__FILE__) );
reset( $files2include );
foreach( $files2include as $f )
include_once( $f );
}
}
function getDirListing( $dirName ){
$ext = '.php';
$dirLising = array();
if ( $handle = opendir($dirName) ){
while ( false !== ($f = readdir($handle)) ){
$thisFileExt = substr( $f, -strlen($ext) );
if ( ($ext == $thisFileExt) && ($f != basename(__FILE__)) )
$dirLising[] = $f;
}
closedir($handle);
}
return $dirLising;
}
?>