diff --git a/bin/luceneserver/ktlucene.jar b/bin/luceneserver/ktlucene.jar index cf908d4..92192d0 100644 --- a/bin/luceneserver/ktlucene.jar +++ b/bin/luceneserver/ktlucene.jar diff --git a/call_home.php b/call_home.php new file mode 100644 index 0000000..7520d41 --- /dev/null +++ b/call_home.php @@ -0,0 +1,18 @@ +||||| +*/ + +$data = isset($_REQUEST['system_info']) ? strip_tags($_REQUEST['system_info']) : ''; + +if(empty($data)){ + exit(0); +} + +$file = 'var/system_info.txt'; +$fp = fopen($file, 'a'); +fwrite($fp, $data."\n"); +fclose($fp); + +exit(0); +?> \ No newline at end of file diff --git a/dmsctl.bat b/dmsctl.bat index f024be8..576f42f 100644 --- a/dmsctl.bat +++ b/dmsctl.bat @@ -4,7 +4,7 @@ rem KnowledgeTree Control Script rem ============= SET ENVIRONMENT VARIABLES ============== -set INSTALL_PATH=%CD% +set INSTALL_PATH=%~dp0 cd .. cd .. set ZEND_PATH=%CD% diff --git a/dmsctl.sh b/dmsctl.sh index 30f402e..11e7467 100755 --- a/dmsctl.sh +++ b/dmsctl.sh @@ -2,7 +2,7 @@ # chkconfig: 2345 55 25 # description: KnowledgeTree Services # -# processname: ktdms +# processname: ktdms cd $(dirname $0) @@ -16,20 +16,37 @@ INSTALL_PATH=`pwd` JAVABIN=/usr/bin/java ZEND_DIR=/usr/local/zend +# exits if the UID is not 0 [root] +check_root_privileges() +{ + ID="id -u" + MYUID=`$ID 2> /dev/null` + if [ ! -z "$MYUID" ]; then + if [ $MYUID != 0 ]; then + echo "You need root privileges to run this script!"; + exit 1 + fi + else + echo "Could not detect UID"; + exit 1 + fi +} + + if [ -f /etc/zce.rc ];then . /etc/zce.rc else echo "/etc/zce.rc doesn't exist!" exit 1; fi - +check_root_privileges # OpenOffice SOFFICEFILE=soffice SOFFICE_PIDFILE=$INSTALL_PATH/var/log/soffice.bin.pid SOFFICE_PID="" SOFFICE_PORT="8100" -SOFFICEBIN=/usr/bin/soffice +SOFFICEBIN="/usr/share/ktdms-office/ktdms-office/openoffice/program/soffice" SOFFICE="$SOFFICEBIN -nofirststartwizard -nologo -headless -accept=socket,host=127.0.0.1,port=$SOFFICE_PORT;urp;StarOffice.ServiceManager" SOFFICE_STATUS="" @@ -38,7 +55,6 @@ LUCENE_PIDFILE=$INSTALL_PATH/var/log/lucene.pid LUCENE_PID="" LUCENE="$JAVABIN -Xms512M -Xmx512M -jar ktlucene.jar" LUCENE_STATUS="" -:q # Scheduler SCHEDULER_PATH="$INSTALL_PATH/bin/" @@ -71,7 +87,7 @@ get_pid() { get_soffice_pid() { get_pid $SOFFICE_PIDFILE if [ ! $PID ]; then - return + return fi if [ $PID -gt 0 ]; then SOFFICE_PID=$PID @@ -81,7 +97,7 @@ get_soffice_pid() { get_lucene_pid() { get_pid $LUCENE_PIDFILE if [ ! $PID ]; then - return + return fi if [ $PID -gt 0 ]; then LUCENE_PID=$PID @@ -91,7 +107,7 @@ get_lucene_pid() { get_scheduler_pid() { get_pid $SCHEDULER_PIDFILE if [ ! $PID ]; then - return + return fi if [ $PID -gt 0 ]; then SCHEDULER_PID=$PID @@ -101,7 +117,7 @@ get_scheduler_pid() { get_mysql_pid() { get_pid $MYSQL_PIDFILE if [ ! $PID ]; then - return + return fi if [ $PID -gt 0 ]; then MYSQL_PID=$PID @@ -183,7 +199,7 @@ start_soffice() { echo "$0 $ARG: openoffice could not be started" ERROR=3 fi - else + else echo "$0 $ARG: path to openoffice binary ($SOFFICEBIN) could not be found" ERROR=3 fi @@ -388,14 +404,45 @@ if [ ! -z ${2} ]; then [ "${2}" != "mysql" ] && [ "${2}" != "apache" ] && [ "${2}" != "agent" ] && [ "${2}" != "scheduler" ] && [ "${2}" != "soffice" ] && [ "${2}" != "lucene" ] && noserver $2 SERVER=$2 fi - + if [ "x$3" != "x" ]; then MYSQL_PASSWORD=$3 fi # Are we running for first time -[[ -e $INSTALL_PATH/var/bin/dmsinit.lock ]] || firstrun +if [ -e "/usr/share/knowledgetree/var/bin/dmsinit.lock" ] +then +echo ""; +else + if grep --quiet LD_LIBRARAY_PATH /etc/zce.rc ; then + echo "Nothing to be done ... maybe" + else + echo "PATH=/usr/local/zend/bin:$PATH" >> /etc/zce.rc + if [ -z $LD_LIBRARY_PATH ] ; then + echo "LD_LIBRARY_PATH=$ZEND_DIR/lib" >> /etc/zce.rc + else + echo "LD_LIBRARY_PATH=$ZEND_DIR/lib:$LD_LIBRARY_PATH" >> /etc/zce.rc + fi + fi + touch $INSTALL_PATH/var/bin/dmsinit.lock + $ZEND_DIR/bin/zendctl.sh restart +fi + +#if [ "ls /usr/share/knowledgetree/var/bin/dmsinit.lock" != "" ] ; then +# echo "No lock" +#e#lse +# echo "lock" +#f#i + +#if [ -f "/usr/share/knowledgetree/var/bin/dmsinit.lock"] ; then +# firstrun +#else +# echo 'safd'; +# exit 1; +#fi + +#[[ -e $INSTALL_PATH/var/bin/dmsinit.lock ]] || firstrun case $1 in help) help diff --git a/dmsctl.vbs b/dmsctl.vbs new file mode 100644 index 0000000..4ce0202 --- /dev/null +++ b/dmsctl.vbs @@ -0,0 +1,671 @@ +' +' KnowledgeTree +' +' +' + +' Service Name Consts +Const KTOFFICE = "KTOpenoffice" +Const KTSCHEDULER = "KTScheduler" +Const KTLUCENE = "KTLucene" + +' Service Control Manager Error Code Consts +Const SVC_SUCCESS = 0 ' Success +Const SVC_NOT_SUPPORTED = 1 ' Not Supported +Const SVC_ACCESS_DENIED = 2 ' Access Denied +Const SVC_DEPENDENT_SERVICES_RUNNING = 3 ' Dependent Services Running +Const SVC_INVALID_SERVICE_CONTROL = 4 ' Invalid Service Control +Const SVC_SERVICE_CANNOT_ACCEPT_CONTROL = 5 ' Service Cannot Accept Control +Const SVC_SERVICE_NOT_ACTIVE = 6 ' Service Not Active +Const SVC_SERVICE_REQUEST_TIMEOUT = 7 ' Service Request Timeout +Const SVC_UNKNOWN_FAILURE = 8 ' Unknown Failure +Const SVC_PATH_NOT_FOUND = 9 ' Path Not Found +Const SVC_SERVICE_ALREADY_RUNNING = 10 ' Service Already Running +Const SVC_SERVICE_DATABASE_LOCKED = 11 ' Service Database Locked +Const SVC_SERVICE_DEPENDENCY_DELETED = 12 ' Service Dependency Deleted +Const SVC_SERVICE_DEPENDENCY_FAILURE = 13 ' Service Dependency Failure +Const SVC_SERVICE_DISABLED = 14 ' Service Disabled +Const SVC_SERVICE_LOGON_FAILURE = 15 ' Service Logon Failure +Const SVC_SERVICE_MARKED_FOR_DELETION = 16 ' Service Marked For Deletion +Const SVC_SERVICES_NO_THREAD = 17 ' Service No Thread +Const SVC_STATUS_CIRCULAR_DEPENDENCY = 18 ' Status Circular Dependency +Const SVC_STATUS_DUPLICATE_NAME = 19 ' Status Duplicate Name +Const SVC_INVALID_NAME = 20 ' Status Invalid Name +Const SVC_STATUS_INVALID_PARAMETER = 21 ' Status Invalid Parameter +Const SVC_INVALID_SERVICES_ACCOUNT = 22 ' Status Invalid Service Account +Const SVC_STATUS_SERVICE_EXISTS = 23 ' Status Service Exists +Const SVC_SERVICE_ALREADY_PAUSED = 24 ' Service Already Paused + +Dim strComputer, currOS, currDir, doRunAs, lastErrorCode + +' Detecting the current directory +Set oFso = CreateObject("Scripting.FileSystemObject") +currDir = oFso.GetParentFolderName(Wscript.ScriptFullName) + +strComputer = "." +currOS = "" +doRunAs = false + +' Detecting the current OS +Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") +Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") + +For Each objOperatingSystem in colOperatingSystems + currOS = objOperatingSystem.Caption & " " & objOperatingSystem.Version + currOS = trim(currOS) +Next + +Public Function isWindowsVista() + isWindowsVista = false + If left(currOS, 19) = "Microsoft Windows Vista" Then + isWindowsVista = TRUE + End If +End Function + +Public Function isWindows7() + isWindows7 = false + If left(currOS, 19) = "Microsoft Windows 7" Then + isWindows7 = TRUE + End If +End Function + +Public Function isWindows2008() + isWindows2008 = false + If mid(currOS, 27, 42) = "2008 Enterprise" Then + isWindows2008 = TRUE + End If +End Function + +' Will call this further down when the individual services need starting +If doRunAs = TRUE Then + 'runAs "C:\Program Files (x86)\Zend\ktdms\knowledgetree", "dmsctl_install.bat" +End If + +Public Sub runAs(ByVal strFolder, ByVal strFile) + Set objShell = CreateObject("Shell.Application") + Set objFolder = objShell.Namespace(strFolder) + Set objFolderItem = objFolder.ParseName(strFile) + objFolderItem.InvokeVerb "runas" +End Sub + +dim objArgs, errMsg, result, strUsage, isSuccess + +strUsage = "USAGE:" &_ +"dmsctl.vbs [servicename]" & vbNewLine &_ +vbNewLine &_ +"help - this screen " & vbNewLine &_ +"start - start the services" & vbNewLine &_ +"stop - stop the services" & vbNewLine &_ +"restart - restart the services" & vbNewLine &_ +"install - install the services" & vbNewLine &_ +"uninstall - uninstall the services" & vbNewLine &_ +vbNewLine &_ +"servicename - optional service name to start/stop only that service." & vbNewLine &_ +" only mysql is supported for individual control at this time." + +Set objArgs = WScript.Arguments +If (objArgs.count < 1) Then + Wscript.Echo strUsage +Else + Select Case objArgs.Item(0) + Case "install" + isSuccess = TRUE ' Track if anything went wrong + + ' Installing KTOffice + result = exec(currDir & "\var\bin\officeinstall.bat") + + 'Install Failed + If result = 0 Then + isSuccess = false + writeLog "The " & KTOFFICE & " KnowledgeTree service could not be installed." + Else + writeLog "The " & KTOFFICE & " KnowledgeTree service was successfully installed." + End If + + ' Installing KTScheduler + result = exec(currDir & "\var\bin\schedulerinstall.bat") + + 'Install Failed + If result = 0 Then + isSuccess = false + writeLog "The " & KTSCHEDULER & " KnowledgeTree service could not be installed." + Else + writeLog "The " & KTSCHEDULER & " KnowledgeTree service was successfully installed." + End If + + ' Installing KTLucene + result = exec(currDir & "\var\bin\luceneinstall.bat") + + 'Install Failed + If result = 0 Then + isSuccess = false + writeLog "The " & KTLUCENE & " KnowledgeTree service could not be installed." + Else + writeLog "The " & KTLUCENE & " KnowledgeTree service was successfully installed." + End If + + If (isSuccess) Then + Wscript.Echo "The KnowledgeTree services were successfully installed" + Else + Wscript.Echo "There were errors installing the KnowledgeTree services please see the log for details ('knowledgetree/var/log/dmsctl.log')" + End If + + Case "start" + If (objArgs.count > 1) Then + Select Case objArgs.Item(1) + Case "soffice" + isSuccess = TRUE + svcName = KTOFFICE + If (NOT isServiceStarted(svcName)) Then + If (NOT startService(svcName)) Then + isSuccess = FALSE + writeLog "The " & KTOFFICE & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode + Else + writeLog "The " & KTOFFICE & " KnowledgeTree service was successfully started" + End If + + writeLog "Successfully started " & KTOFFICE + Else + writeLog KTOFFICE & " already started. Result Code: " & lastErrorCode + End If + + If (isSuccess) Then + Wscript.Echo "The " & KTOFFICE & " KnowledgeTree service was successfully started" + Else + Wscript.Echo "The " & KTOFFICE & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode + End If + + Case "scheduler" + isSuccess = TRUE + svcName = KTSCHEDULER + If (NOT isServiceStarted(svcName)) Then + If (NOT startService(svcName)) Then + isSuccess = FALSE + writeLog "The " & KTSCHEDULER & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode + Else + writeLog "The " & KTSCHEDULER & " KnowledgeTree service was successfully started" + End If + + writeLog "Successfully started " & KTSCHEDULER + Else + writeLog KTSCHEDULER & " already started. Result Code: " & lastErrorCode + End If + + If (isSuccess) Then + Wscript.Echo "The " & KTSCHEDULER & " KnowledgeTree service was successfully started" + Else + Wscript.Echo "The " & KTSCHEDULER & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode + End If + + Case "lucene" + isSuccess = TRUE + svcName = KTLUCENE + If (NOT isServiceStarted(svcName)) Then + If (NOT startService(svcName)) Then + isSuccess = false + writeLog "The " & KTLUCENE & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode + Else + writeLog "The " & KTLUCENE & " KnowledgeTree service was successfully started" + End If + + writeLog "Successfully started " & KTLUCENE + Else + writeLog KTLUCENE & " already started. Result Code: " & lastErrorCode + End If + + If (isSuccess) Then + Wscript.Echo "The " & KTLUCENE & " KnowledgeTree service was successfully started" + Else + Wscript.Echo "The " & KTLUCENE & " KnowledgeTree service could not be started. Result Code: " & lastErrorCode + End If + End Select + Else + isSuccess = TRUE + + svcName = KTOFFICE + If (NOT isServiceStarted(svcName)) Then + If (NOT startService(svcName)) Then + isSuccess = false + End If + writeLog "Successfully started " & KTOFFICE + Else + writeLog KTOFFICE & " already started. Result Code: " & lastErrorCode + End If + + svcName = KTSCHEDULER + If (NOT isServiceStarted(svcName)) Then + If (NOT startService(svcName)) Then + isSuccess = false + End If + writeLog "Successfully started " & KTSCHEDULER + Else + writeLog KTSCHEDULER & " already started. Result Code: " & lastErrorCode + End If + + svcName = KTLUCENE + If (NOT isServiceStarted(svcName)) Then + If (NOT startService(svcName)) Then + isSuccess = false + End If + writeLog "Successfully started " & KTLUCENE + Else + writeLog KTLUCENE & " already started. Result Code: " & lastErrorCode + End If + + If (isSuccess) Then + Wscript.Echo "The KnowledgeTree services were successfully started" + Else + Wscript.Echo "There were errors starting the KnowledgeTree services please see the log for details ('knowledgetree/var/log/dmsctl.log')" + End If + End If + Case "stop" + If (objArgs.count > 1) Then + Select Case objArgs.Item(1) + Case "soffice" + isSuccess = TRUE + svcName = KTOFFICE + If (isServiceStarted(svcName)) Then + If (NOT stopService(svcName)) Then + isSuccess = false + writeLog "The " & KTOFFICE & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode + Else + writeLog "The " & KTOFFICE & " KnowledgeTree service was successfully stopped" + End If + + writeLog "Successfully stopped " & KTOFFICE + Else + writeLog KTOFFICE & " already stopped. Result Code: " & lastErrorCode + End If + + If (isSuccess) Then + Wscript.Echo "The " & KTOFFICE & " KnowledgeTree service was successfully stopped" + Else + Wscript.Echo "The " & KTOFFICE & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode + End If + + Case "scheduler" + isSuccess = TRUE + svcName = KTSCHEDULER + If (isServiceStarted(svcName)) Then + If (NOT stopService(svcName)) Then + isSuccess = false + writeLog "The " & KTSCHEDULER & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode + Else + writeLog "The " & KTSCHEDULER & " KnowledgeTree service was successfully stopped" + End If + + writeLog "Successfully stopped " & KTSCHEDULER + Else + writeLog KTSCHEDULER & " already stopped. Result Code: " & lastErrorCode + End If + + If (isSuccess) Then + Wscript.Echo "The " & KTSCHEDULER & " KnowledgeTree service was successfully stopped" + Else + Wscript.Echo "The " & KTSCHEDULER & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode + End If + + Case "lucene" + isSuccess = TRUE + svcName = KTLUCENE + If (isServiceStarted(svcName)) Then + If (NOT stopService(svcName)) Then + isSuccess = false + writeLog "The " & KTLUCENE & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode + Else + writeLog "The " & KTLUCENE & " KnowledgeTree service was successfully stopped" + End If + + writeLog "Successfully stopped " & KTLUCENE + Else + writeLog KTLUCENE & " already stopped. Result Code: " & lastErrorCode + End If + + If (isSuccess) Then + Wscript.Echo "The " & KTLUCENE & " KnowledgeTree service was successfully stopped" + Else + Wscript.Echo "The " & KTLUCENE & " KnowledgeTree service could not be stopped. Result Code: " & lastErrorCode + End If + End Select + Else + 'Stopping all the services + isSuccess = TRUE + + svcName = KTOFFICE + If (isServiceStarted(svcName)) Then + If (NOT stopService(svcName)) Then + isSuccess = false + End If + writeLog "Successfully stopped " & KTOFFICE + Else + writeLog KTOFFICE & " already stopped. Result Code: " & lastErrorCode + End If + + svcName = KTSCHEDULER + If (isServiceStarted(svcName)) Then + If (NOT stopService(svcName)) Then + isSuccess = false + End If + writeLog "Successfully stopped " & KTSCHEDULER + Else + writeLog KTSCHEDULER & " already stopped. Result Code: " & lastErrorCode + End If + + svcName = KTLUCENE + If (isServiceStarted(svcName)) Then + If (NOT stopService(svcName)) Then + isSuccess = false + End If + writeLog "Successfully stopped " & KTLUCENE + Else + writeLog KTLUCENE & " already stopped. Result Code: " & lastErrorCode + End If + + If (isSuccess) Then + Wscript.Echo "The KnowledgeTree services were successfully stopped" + Else + Wscript.Echo "There were errors sopping the KnowledgeTree services please see the log for details ('knowledgetree/var/log/dmsctl.log')" + End If + End If + + Case "uninstall" + isSuccess = TRUE + + svcName = KTOFFICE + If (NOT uninstallService(svcName)) Then + isSuccess = false + writeLog "The KnowledgeTree KTOffice service could not be uninstalled" + End If + + svcName = KTSCHEDULER + If (NOT uninstallService(svcName)) Then + isSuccess = false + writeLog "The KnowledgeTree KTScheduler service could not be uninstalled" + End If + + svcName = KTLUCENE + If (NOT uninstallService(svcName)) Then + isSuccess = false + writeLog "The KnowledgeTree KTLucene service could not be uninstalled" + End If + + If (isSuccess) Then + Wscript.Echo "The KnowledgeTree services were uninstalled" + Else + Wscript.Echo "There were errors uninstalling the KnowledgeTree services please see the log for details ('knowledgetree/var/log/dmsctl.log')" + End If + + Case "uninstall_old" 'Depricated : This method prevents verbose error logging, using WMI to uninstall instead + isSuccess = TRUE ' Track if anything went wrong + + ' Stopping Then FALSE + 'svcName = KTOFFICE + 'If (isServiceStarted(svcName)) Then + ' If (NOT stopService(svcName)) Then + ' isSuccess = false + ' End If + 'End If + + ' FALSE KTOffice + result = exec("sc delete " & KTOFFICE) + + 'Uninstall Failed + If result = 0 Then + isSuccess = false + writeLog "The KnowledgeTree KTOffice service could not be uninstalled" + End If + + ' Stopping Then FALSE + 'svcName = KTSCHEDULER + 'If (isServiceStarted(svcName)) Then + ' If (NOT stopService(svcName)) Then + ' isSuccess = false + ' End If + 'End If + + ' FALSE KTScheduler + result = exec("sc delete " & KTSCHEDULER) + + 'Uninstall Failed + If result = 0 Then + isSuccess = false + writeLog "The KnowledgeTree KTScheduler service could not be uninstalled" + End If + + ' Stopping Then FALSE + 'svcName = KTLUCENE + 'If (isServiceStarted(svcName)) Then + ' If (NOT stopService(svcName)) Then + ' isSuccess = FALSE + ' End If + 'End If + + ' FALSE KTLucene + result = exec("sc delete " & KTLUCENE) + + 'Uninstall Failed + If result = 0 Then + isSuccess = FALSE + writeLog "The KnowledgeTree KTLucene service could not be uninstalled" + End If + + If (isSuccess) Then + Wscript.Echo "The KnowledgeTree services were uninstalled" + Else + Wscript.Echo "There were errors uninstalling the KnowledgeTree services please see the log for details ('knowledgetree/var/log/dmsctl.log')" + End If + + + Case Else + Wscript.Echo strUsage + End Select + +End If + +' Method to check if a service is installed +Public Function isServiceInstalled(ByVal svcName) + strComputer = "." + Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") + + ' Obtain an instance of the the class + ' using a key property value. + + isServiceInstalled = FALSE + + svcQry = "SELECT * from Win32_Service" + Set objOutParams = objWMIService.ExecQuery(svcQry) + + For Each objSvc in objOutParams + + Select Case objSvc.Name + Case svcName + isServiceInstalled = TRUE + End Select + + Next + + If (Not isServiceInstalled) Then + lastErrorCode = SVC_INVALID_NAME + End If + +End Function + +' Method to interrogate a service +Public Function isServiceStarted(ByVal svcName) + If (NOT isServiceInstalled( svcName )) Then + isServiceStarted = FALSE + Exit Function + End If + + strComputer = "." + Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") + + ' Obtain an instance of the the class + ' using a key property value. + Set objShare = objWMIService.Get("Win32_Service.Name='" & svcName & "'") + + ' no InParameters to define + + ' Execute the method and obtain the return status. + ' The OutParameters object in objOutParams + ' is created by the provider. + Set objOutParams = objWMIService.ExecMethod("Win32_Service.Name='" & svcName & "'", "InterrogateService") + + lastErrorCode = objOutParams.ReturnValue + + If (objOutParams.ReturnValue = SVC_SERVICE_NOT_ACTIVE) Then + isServiceStarted = FALSE + Else + isServiceStarted = TRUE + End If + +end Function + +' Method to start a service +Public Function startService(ByVal svcName) + If (NOT isServiceInstalled( svcName )) Then + writeLog "The KnowledgeTree " & svcName & " service could not be started because it isn't installed. Run 'dmsctl.vbs install' to correct." + startService = FALSE + Exit Function + End If + + strComputer = "." + Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") + ' Obtain an instance of the the class + ' using a key property value. + Set objShare = objWMIService.Get("Win32_Service.Name='" & svcName &"'") + + ' no InParameters to define + + ' Execute the method and obtain the return status. + ' The OutParameters object in objOutParams + ' is created by the provider. + Set objOutParams = objWMIService.ExecMethod("Win32_Service.Name='" & svcName & "'", "StartService") + + lastErrorCode = objOutParams.ReturnValue + + If (objOutParams.ReturnValue = SVC_SUCCESS) Then + startService = TRUE + Else + startService = FALSE + End If + +End Function + +' Method to stop a service +Public Function stopService(ByVal svcName) + If (NOT isServiceInstalled( svcName )) Then + writeLog "The KnowledgeTree " & svcName & " service could not be stopped because it isn't installed. Run 'dmsctl.vbs install' to correct." + stopService = FALSE + Exit Function + End If + + strComputer = "." + Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") + ' Obtain an instance of the the class + ' using a key property value. + Set objShare = objWMIService.Get("Win32_Service.Name='" & svcName &"'") + + ' no InParameters to define + + ' Execute the method and obtain the return status. + ' The OutParameters object in objOutParams + ' is created by the provider. + Set objOutParams = objWMIService.ExecMethod("Win32_Service.Name='" & svcName & "'", "StopService") + + lastErrorCode = objOutParams.ReturnValue + + If (objOutParams.ReturnValue = SVC_SUCCESS) Then + stopService = TRUE + Else + stopService = FALSE + End If + +End Function + +' Method to uninstall a service +Public Function uninstallService(ByVal svcName) + If (NOT isServiceInstalled( svcName )) Then + uninstallService = TRUE ' Service already uninstalled so return TRUE + Exit Function + End If + + wasStopped = TRUE + If (NOT stopService(svcName)) Then + wasStopped = FALSE + End If + + strComputer = "." + Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") + ' Obtain an instance of the the class + ' using a key property value. + Set objShare = objWMIService.Get("Win32_Service.Name='" & svcName & "'") + + ' no InParameters to define + + ' Execute the method and obtain the return status. + ' The OutParameters object in objOutParams + ' is created by the provider. + Set objOutParams = objWMIService.ExecMethod("Win32_Service.Name='" & svcName & "'", "Delete") + + lastErrorCode = objOutParams.ReturnValue + + If (objOutParams.ReturnValue = SVC_SUCCESS) Then + uninstallService = TRUE + Else + uninstallService = FALSE + + ' Extra Event logging to assist the Administrator + If (wasStopped) Then + writeLog "The KnowledgeTree " & svcName & " service could not be uninstalled because it could not be stopped. Stop this service manually before uninstalling." + uninstallService = FALSE ' Must be stop service before it can be uninstalled + End If + + End If + +End Function + + +' Execute a command +Public Function exec(ByVal cmd) + + Dim WshShell, oExec + Set WshShell = CreateObject("WScript.Shell") + + Set oExec = WshShell.Exec(cmd) + + Do While oExec.Status = 0 + WScript.Sleep 100 + Loop + + exec = oExec.Status + +End Function + +Public Sub createCustomEventLog(ByVal strName) + Const NO_VALUE = Empty + + Set WshShell = WScript.CreateObject("WScript.Shell") + WshShell.RegWrite _ + "HKLM\System\CurrentControlSet\Services\EventLog\" & strName & "\", NO_VALUE +End Sub + +' Event logging only works on Server 2003, 2000 and XP +Public Sub logEvent(ByVal strMessage) + ' Disabled until Windows Vista detection has been tested. + 'If (NOT isWindowsVista() AND NOT isWindows7() AND NOT isWindows2008()) Then + ' Const EVENT_SUCCESS = 0 + ' Set objShell = Wscript.CreateObject("Wscript.Shell") + ' objShell.LogEvent EVENT_SUCCESS, strMessage + 'End If +End Sub + +' Event logging only works on Server 2003, 2000 and XP +Public Sub writeLog(ByVal strMessage) + Set objFSO = CreateObject("Scripting.FileSystemObject") + ForAppending = 8 + Set objTextFile = objFSO.OpenTextFile (currDir & "\var\log\dmsctl.log", ForAppending, True) + objTextFile.WriteLine strMessage + objTextFile.Close +End Sub + diff --git a/dmsctl_install.bat b/dmsctl_install.bat new file mode 100644 index 0000000..112b1f1 --- /dev/null +++ b/dmsctl_install.bat @@ -0,0 +1,3 @@ +rem KnowledgeTree UAC Run installer as Administrator for Windows 7 and Vista +@echo off +call dmsctl.bat install \ No newline at end of file diff --git a/kthelp/ktcore/EN/welcome.html b/kthelp/ktcore/EN/welcome.html index 0e7007e..dc66eb8 100644 --- a/kthelp/ktcore/EN/welcome.html +++ b/kthelp/ktcore/EN/welcome.html @@ -4,7 +4,7 @@

#APP_NAME# is Document Management Made Simple.


- +

Easily and securely manage your company's document creation, editing, versioning, and sharing - all from a powerful Web interface and Microsoft® Office® and Windows® Explorer® tools.

diff --git a/kthelp/ktcore/EN/welcomeCommercial.html b/kthelp/ktcore/EN/welcomeCommercial.html index e829690..b4793a2 100644 --- a/kthelp/ktcore/EN/welcomeCommercial.html +++ b/kthelp/ktcore/EN/welcomeCommercial.html @@ -5,7 +5,7 @@

#APP_NAME# is Document Management Made Simple.


- +

Easily and securely manage your company's document creation, editing, versioning, and sharing - all from a powerful Web interface and Microsoft® Office and Windows® Explorer tools.


A subscription to #APP_NAME# provides your organization with product updates, enhanced document management features, and commercial support. Please view your welcome mailer for information on accessing these services.


diff --git a/lib/plugins/plugin.inc.php b/lib/plugins/plugin.inc.php index 132c1ca..295bd09 100644 --- a/lib/plugins/plugin.inc.php +++ b/lib/plugins/plugin.inc.php @@ -5,7 +5,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -751,6 +751,11 @@ class KTPlugin { )); } + }else{ + // Update the plugin path, in case it has moved + $oEntity->updateFromArray(array( + 'path' => $this->stripKtDir($this->sFilename) + )); } /* ** Quick fix for optimisation. Reread must run plugin setup. ** */ $this->setup(); diff --git a/lib/plugins/pluginutil.inc.php b/lib/plugins/pluginutil.inc.php index f0460fb..c0e3b3a 100644 --- a/lib/plugins/pluginutil.inc.php +++ b/lib/plugins/pluginutil.inc.php @@ -5,7 +5,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -598,10 +598,18 @@ class KTPluginUtil { if (!KTUtil::isAbsolutePath($sPath)) { $sPath = sprintf("%s/%s", KT_DIR, $sPath); } + // Check that the file exists at the given path + // If it doesn't set it as unavailable and disabled + // else set it as available and enabled. + // We'll document this in case they've specifically disabled certain plugins if (!file_exists($sPath)) { $oPluginEntity->setUnavailable(true); $oPluginEntity->setDisabled(true); $res = $oPluginEntity->update(); + }elseif ($oPluginEntity->getUnavailable()){ + $oPluginEntity->setUnavailable(false); + $oPluginEntity->setDisabled(false); + $res = $oPluginEntity->update(); } } KTPluginEntity::clearAllCaches(); diff --git a/lib/util/ktpclzip.inc.php b/lib/util/ktpclzip.inc.php index 2afa80a..b173109 100644 --- a/lib/util/ktpclzip.inc.php +++ b/lib/util/ktpclzip.inc.php @@ -117,6 +117,10 @@ class KTPclZip { */ function createZipFile($sFolder) { //Overriding $this->aPaths with specified + if (!is_dir($sFolder)) { + PEAR::raiseError( sprintf( _kt( "Couldn't create zip file, invalid folder was specified %s " ) , $sFolder )); + } + if (!is_null($sFolder)) { $this->aPaths = $sFolder; } @@ -139,20 +143,36 @@ class KTPclZip { return $sExportCode; } - /* - * Returns the part of the folder to be excluded from the zip content structure - * + + /* * @params: $sPath folder to start from. * @params: $ds directory separator */ - function getExcludePath($sPath, $ds = '/') { + static function getExcludePath($sPath, $ds = '/') { //Will grab the part of the full path to exclude from the zip contents - if ($sPath[strlen($sPath)] == $ds) { - //Chopping the last ds to make the keepPath contain an actual folder name - $sPath = substr($sPath, 0, strlen($sPath) - 1); + + /* + * For windows the pre drive letter needs to be removed for it to work with the pclzip class for version 2.5 + */ + // Now using pclzip 2.8.2 so no need to strip the drive letter. + /* + if (stristr(PHP_OS,'WIN')) { + $sPath = end(explode(':', $sPath)); } - $keepPath = end(explode($ds, $sPath)); - $excludePath = str_replace($keepPath, '', $sPath); + */ + + //Generating the exclude path : Flexible method (Can set $cutOff = count($aDir) - 1;) to include the parent folder. + /* + $aDir = explode($ds, $sPath); + $cutOff = count($aDir); + for ($i = 0; $i < $cutOff; $i++) { + //echo $aDir[$i] . "\n"; + $excludePath .= $aDir[$i] . '/'; + } + */ + + $excludePath = str_replace('\\', '/', $sPath); + return $excludePath; } diff --git a/lib/widgets/portlet.inc.php b/lib/widgets/portlet.inc.php index 2fecf6a..3b7c618 100644 --- a/lib/widgets/portlet.inc.php +++ b/lib/widgets/portlet.inc.php @@ -5,7 +5,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -153,13 +153,12 @@ class KTActionPortlet extends KTPortlet { // Create button html $button = ""; diff --git a/plugins/search2/reporting/IndexErrors.php b/plugins/search2/reporting/IndexErrors.php index 0ccca13..5171bdf 100644 --- a/plugins/search2/reporting/IndexErrors.php +++ b/plugins/search2/reporting/IndexErrors.php @@ -5,7 +5,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -54,6 +54,11 @@ class IndexErrorsDispatcher extends KTAdminDispatcher { //Number of items on a page $itemsPerPage = 50; + $pageNum = 1; + + if(isset($_REQUEST['itemsPerPage'])){ + $itemsPerPage = $_REQUEST['itemsPerPage']; + } //registerTypes registers the mime types and populates the needed tables. $indexer = Indexer::get(); @@ -128,6 +133,11 @@ class IndexErrorsDispatcher extends KTAdminDispatcher { if(isset($_REQUEST['pageValue'])) { $pageNum = (int)$_REQUEST['pageValue']; + + if($pageNum > $pages){ + $pageNum = $pages; + } + $start = (($pageNum-1)*$itemsPerPage)-1; $limit = $start+$itemsPerPage; for($i = $start; $i <= $limit; $i++){ @@ -145,13 +155,18 @@ class IndexErrorsDispatcher extends KTAdminDispatcher { } } + $config = KTConfig::getSingleton(); + $rootUrl = $config->get('KnowledgeTree/rootUrl'); + $oTemplate->setData(array( 'context' => $this, 'pageList' => $aPages, 'pageCount' => $pages, + 'pageNum' => $pageNum, 'itemCount' => $items, 'itemsPerPage' => $itemsPerPage, - 'indexErrors' => $aIndexList + 'indexErrors' => $aIndexList, + 'root_url' => $rootUrl )); return $oTemplate; diff --git a/plugins/search2/reporting/PendingDocuments.php b/plugins/search2/reporting/PendingDocuments.php index 8198b5e..386bb40 100644 --- a/plugins/search2/reporting/PendingDocuments.php +++ b/plugins/search2/reporting/PendingDocuments.php @@ -5,7 +5,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -51,6 +51,14 @@ class PendingDocumentsDispatcher extends KTAdminDispatcher function do_main() { + //Number of items on a page + $itemsPerPage = 50; + $pageNum = 1; + + if(isset($_REQUEST['itemsPerPage'])){ + $itemsPerPage = $_REQUEST['itemsPerPage']; + } + //registerTypes registers the mime types and populates the needed tables. $indexer = Indexer::get(); $indexer->registerTypes(); @@ -68,6 +76,51 @@ class PendingDocumentsDispatcher extends KTAdminDispatcher $aPendingDocs[$key] = $doc; } + $aPendingList = array(); + + //creating page variables and loading the items for the current page + if(!empty($aPendingDocs)){ + $items = count($aPendingDocs); + + if(fmod($items, $itemsPerPage) > 0){ + $pages = floor($items/$itemsPerPage)+1; + }else{ + $pages = ($items/$itemsPerPage); + } + for($i=1; $i<=$pages; $i++){ + $aPages[] = $i; + } + if($items < $itemsPerPage){ + $limit = $items-1; + }else{ + $limit = $itemsPerPage-1; + } + + if(isset($_REQUEST['pageValue'])) + { + $pageNum = (int)$_REQUEST['pageValue']; + + if($pageNum > $pages){ + $pageNum = $pages; + } + + $start = (($pageNum-1)*$itemsPerPage)-1; + $limit = $start+$itemsPerPage; + for($i = $start; $i <= $limit; $i++){ + if(isset($aPendingDocs[$i])) + { + $aPendingList[] = $aPendingDocs[$i]; + } + } + } + else + { + for($i = 0; $i <= $limit; $i++){ + $aPendingList[] = $aPendingDocs[$i]; + } + } + } + $oTemplating =& KTTemplating::getSingleton(); $oTemplate =& $oTemplating->loadTemplate('ktcore/search2/reporting/pendingdocuments'); @@ -76,7 +129,12 @@ class PendingDocumentsDispatcher extends KTAdminDispatcher $oTemplate->setData(array( 'context' => $this, - 'pending_docs' => $aPendingDocs, + 'pageList' => $aPages, + 'pageCount' => $pages, + 'pageNum' => $pageNum, + 'itemCount' => $items, + 'itemsPerPage' => $itemsPerPage, + 'pending_docs' => $aPendingList, 'root_url' => $rootUrl )); return $oTemplate; diff --git a/plugins/thumbnails/thumbnails.php b/plugins/thumbnails/thumbnails.php index a2fe432..c99060f 100755 --- a/plugins/thumbnails/thumbnails.php +++ b/plugins/thumbnails/thumbnails.php @@ -147,10 +147,10 @@ class thumbnailGenerator extends BaseProcessor $mimeType = KTMime::getMimeTypeName($mimeTypeId); // Get the pdf source file - if the document is a pdf then use the document as the source - if($mimeType == 'application/pdf'){ + if($mimeType == 'application/pdf') { $pdfDir = $default->documentRoot; $pdfFile = $pdfDir . DIRECTORY_SEPARATOR . $this->document->getStoragePath(); - }else{ + } else { $pdfDir = $default->pdfDirectory; $pdfFile = $pdfDir .DIRECTORY_SEPARATOR. $this->document->iId.'.pdf'; } @@ -175,28 +175,23 @@ class thumbnailGenerator extends BaseProcessor $default->log->debug('Thumbnail Generator Plugin: PDF file does not exist, cannot generate a thumbnail'); return false; } - // if a previous version of the thumbnail exists - delete it + + // if a previous version of the thumbnail exists - delete it if (file_exists($thumbnailfile)) { @unlink($thumbnailfile); } // do generation - // if (extension_loaded('imagick')) { - $pathConvert = (!empty($default->convertPath)) ? $default->convertPath : 'convert'; - // windows path may contain spaces - - if (stristr(PHP_OS,'WIN')) { - $cmd = "\"{$pathConvert}\" -size 200x200 \"{$pdfFile}[0]\" -resize 200x200 \"$thumbnailfile\""; - } - else { - $cmd = "{$pathConvert} -size 200x200 {$pdfFile}[0] -resize 200x200 $thumbnailfile"; - } - $result = KTUtil::pexec($cmd); - return true; - //}else{ - //$default->log->debug('Thumbnail Generator Plugin: Imagemagick not installed, cannot generate a thumbnail'); - // return false; - //} - + $pathConvert = (!empty($default->convertPath)) ? $default->convertPath : 'convert'; + // windows path may contain spaces + if (stristr(PHP_OS,'WIN')) { + $cmd = "\"{$pathConvert}\" \"{$pdfFile}[0]\" -resize 200x200 \"$thumbnailfile\""; + } + else { + $cmd = "{$pathConvert} {$pdfFile}[0] -resize 200x200 $thumbnailfile"; + } + + $result = KTUtil::pexec($cmd); + return true; } } diff --git a/plugins/thumbnails/thumbnailsPlugin.php b/plugins/thumbnails/thumbnailsPlugin.php index 86d6351..2d32844 100755 --- a/plugins/thumbnails/thumbnailsPlugin.php +++ b/plugins/thumbnails/thumbnailsPlugin.php @@ -49,6 +49,15 @@ class thumbnailsPlugin extends KTPlugin { require_once(KT_LIB_DIR . '/templating/templating.inc.php'); $oTemplating =& KTTemplating::getSingleton(); $oTemplating->addLocation('thumbnails', $plugin_dir.'templates', 'thumbnails.generator.processor.plugin'); + + // check for existing config settings entry and only add if not already present + $sql = 'SELECT id FROM `config_settings` WHERE group_name = "externalBinary" AND item = "convertPath"'; + $result = DBUtil::getOneResult($sql); + if(PEAR::isError($result) || empty($result)) { + DBUtil::runQuery('INSERT INTO `config_settings` (group_name, display_name, description, item, value, default_value, type, options, can_edit) ' + . 'VALUES ("externalBinary", "convert", "The path to the ImageMagick \"convert\" binary", "convertPath", "default", "convert", ' + . '"string", NULL, 1);'); + } } } diff --git a/resources/css/kt-framing.css b/resources/css/kt-framing.css index 4a31a8a..f326b0d 100644 --- a/resources/css/kt-framing.css +++ b/resources/css/kt-framing.css @@ -25,6 +25,7 @@ body { /*margin-top: 15px;*/ margin-left: 10px; + margin-right: 25px; } .copyright { @@ -1218,20 +1219,6 @@ The text will be hidden for screen view. The generic fahrner-ish approach comes text-decoration: none; } -.portlet_button a .arrow_download { - background: transparent url(../../resources/graphics/download_arrow.gif) center right no-repeat; - width: 20px; - height: 47px; - float: right; -} - -.portlet_button a .arrow_upload { - background: transparent url(../../resources/graphics/upload_arrow.gif) center right no-repeat; - width: 20px; - height: 47px; - float: right; -} - .portlet_button a .big_btn_left { background: transparent url(../../resources/graphics/btn_left.gif) top left no-repeat; width: 10px; @@ -1246,16 +1233,23 @@ The text will be hidden for screen view. The generic fahrner-ish approach comes text-align: center; vertical-align: middle; align: center; - width: 89%; + width: 80%; } .portlet_button a .big_btn_right { - background: transparent url(../../resources/graphics/btn_right.gif) top right no-repeat; float: left; - width: 10px; + width: 25px; height: 47px; } +.portlet_button a .arrow_upload{ + background: transparent url(../../resources/graphics/btn_right_up.gif) top right no-repeat; +} + +.portlet_button a .arrow_download{ + background: transparent url(../../resources/graphics/btn_right_down.gif) top right no-repeat; +} + .portlet_button a:hover .big_btn_left { background: transparent url(../../resources/graphics/btn_left_ro.gif) top left no-repeat; } @@ -1264,8 +1258,12 @@ The text will be hidden for screen view. The generic fahrner-ish approach comes background: transparent url(../../resources/graphics/btn_middle_ro.gif) repeat-x; } -.portlet_button a:hover .big_btn_right { - background: transparent url(../../resources/graphics/btn_right_ro.gif) top right no-repeat; +.portlet_button a:hover .arrow_upload { + background: transparent url(../../resources/graphics/btn_right_ro_up.gif) top right no-repeat; +} + +.portlet_button a:hover .arrow_download { + background: transparent url(../../resources/graphics/btn_right_ro_down.gif) top right no-repeat; } @@ -1292,7 +1290,7 @@ The text will be hidden for screen view. The generic fahrner-ish approach comes width: 47%; margin-top: 0; margin-left: 0; - padding-right: 2em; + padding-right: 3em; float: left; padding-bottom: 2em; height: 100%; diff --git a/resources/graphics/btn_right_down.gif b/resources/graphics/btn_right_down.gif new file mode 100644 index 0000000..abf8217 --- /dev/null +++ b/resources/graphics/btn_right_down.gif diff --git a/resources/graphics/btn_right_ro_down.gif b/resources/graphics/btn_right_ro_down.gif new file mode 100644 index 0000000..17704f8 --- /dev/null +++ b/resources/graphics/btn_right_ro_down.gif diff --git a/resources/graphics/btn_right_ro_up.gif b/resources/graphics/btn_right_ro_up.gif new file mode 100644 index 0000000..585ea2e --- /dev/null +++ b/resources/graphics/btn_right_ro_up.gif diff --git a/resources/graphics/btn_right_up.gif b/resources/graphics/btn_right_up.gif new file mode 100644 index 0000000..5db07ce --- /dev/null +++ b/resources/graphics/btn_right_up.gif diff --git a/search2/documentProcessor/bin/documentProcessor.php b/search2/documentProcessor/bin/documentProcessor.php index 297fa3e..e1a003e 100644 --- a/search2/documentProcessor/bin/documentProcessor.php +++ b/search2/documentProcessor/bin/documentProcessor.php @@ -6,7 +6,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -47,6 +47,7 @@ chdir(dirname(__FILE__)); require_once('../documentProcessor.inc.php'); $documentProcessor = DocumentProcessor::get(); +$documentProcessor->processIndexQueue(); $documentProcessor->processQueue(); exit; ?> diff --git a/search2/documentProcessor/documentProcessor.inc.php b/search2/documentProcessor/documentProcessor.inc.php index 3e54746..2532a63 100644 --- a/search2/documentProcessor/documentProcessor.inc.php +++ b/search2/documentProcessor/documentProcessor.inc.php @@ -6,7 +6,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -105,6 +105,11 @@ class DocumentProcessor return $singleton; } + /** + * Load the processors that will get run on the documents, eg pdf generation + * + * @return array + */ private function loadProcessors() { // Get list of registered processors (plugins) @@ -116,7 +121,7 @@ class DocumentProcessor if(PEAR::isError($results)){ global $default; - $default->log->debug('documentProcessor: error loading processors').' - '.$results->getMessage(); + $default->log->error('documentProcessor: error loading processors').' - '.$results->getMessage(); return false; } @@ -139,34 +144,65 @@ class DocumentProcessor return $processors; } - public function processQueue() + /** + * Fetch the documents in the indexing queue and start the indexer + * + */ + public function processIndexQueue() { global $default; - $default->log->debug('documentProcessor: starting'); + + if(!$default->enableIndexing){ + $default->log->debug('documentProcessor: indexer disabled'); + return ; + } + + $default->log->debug('documentProcessor: starting indexer'); // Check for lock file to ensure processor is not currently running $cacheDir = $default->cacheDirectory; $lockFile = $cacheDir . DIRECTORY_SEPARATOR . 'document_processor.lock'; if(file_exists($lockFile)){ - // lock file exists, exit - $default->log->debug('documentProcessor: stopping, lock file in place '.$lockFile); - return ; + // If something causes the document processor to stop part way through processing, the lock + // file will remain stopping the document processor from resuming. To workaround this problem + // we check the creation date of the lockfile and remove it if it is older than 24 hours or + // 48 hours if the batch size is greater than 1000 documents. + $stat = stat($lockFile); + $created = $stat['mtime']; + + $gap = 24; + if($this->limit > 1000){ + $gap = 48; + $default->log->warn('documentProcessor: batch size of documents to index is set to '.$this->limit.', this could cause problems.'); + } + $check = time() - ($gap*60*60); + + if($check > $created){ + $default->log->error('documentProcessor: lock file is older than '.$gap.' hours, deleting it to restart indexing - '.$lockFile); + @unlink($lockFile); + }else{ + // lock file exists, exit + // through a warning if the lock file is older than half an hour + $small_gap = time() - (30*60); + if($small_gap > $created){ + $default->log->warn('documentProcessor: stopping, lock file in place since '. date('Y-m-d H:i:s', $created) .' - '.$lockFile); + } + return ; + } } - if($default->enableIndexing){ - // Setup indexing - load extractors, run diagnostics - if($this->indexer->preIndexingSetup() === false){ - $default->log->debug('documentProcessor: stopping - indexer setup failed.'); - return; - } + // Setup indexing - load extractors, run diagnostics + if($this->indexer->preIndexingSetup() === false){ + $default->log->error('documentProcessor: stopping - indexer setup failed.'); + return; } // Get document queue $queue = $this->indexer->getDocumentsQueue($this->limit); if(empty($queue)){ - $default->log->debug('documentProcessor: stopping - no documents in processing queue'); + $default->log->debug('documentProcessor: stopping - no documents in indexing queue'); return ; } @@ -177,7 +213,8 @@ class DocumentProcessor foreach($queue as $item){ // Get the document object - $document = Document::get($item['document_id']); + $docId = $item['document_id']; + $document = Document::get($docId); if (PEAR::isError($document)) { @@ -186,9 +223,59 @@ class DocumentProcessor } // index document - if($default->enableIndexing){ - $this->indexer->processDocument($document, $item); - } + $this->indexer->processDocument($document, $item); + } + + // update the indexer statistics + $this->indexer->updateIndexStats(); + + // Remove lock file to indicate processing has completed + if(file_exists($lockFile)){ + @unlink($lockFile); + } + + $default->log->debug('documentProcessor: stopping indexer, batch completed'); + } + + /** + * Fetch the process queue for running the processors on + * + */ + public function processQueue() + { + global $default; + $default->log->debug('documentProcessor: starting processing'); + + if($this->processors === false){ + $default->log->info('documentProcessor: stopping - no processors enabled'); + return ; + } + + // Get processing queue + // Use the same batch size as the indexer (for now) + // If the batch size is huge then reset it to a smaller number + // Open office leaks memory, so we don't want to do too many documents at once + $batch = ($this->limit > 500) ? 500 : $this->limit; + + $queue = $this->indexer->getDocumentProcessingQueue($batch); + + if(empty($queue)){ + $default->log->debug('documentProcessor: stopping - no documents in processing queue'); + return ; + } + + // Process queue + foreach($queue as $item){ + + // Get the document object + $docId = $item['document_id']; + $document = Document::get($docId); + + if (PEAR::isError($document)) + { + Indexer::unqueueDocFromProcessing($docId, "Cannot resolve document id: {$document->getMessage()}", 'error'); + continue; + } // loop through processors if($this->processors !== false){ @@ -205,18 +292,11 @@ class DocumentProcessor $processor->setDocument($document); $processor->processDocument(); } + Indexer::unqueueDocFromProcessing($docId, "Document processed", 'debug'); } } - // update the indexer statistics - $this->indexer->updateIndexStats(); - - // Remove lock file to indicate processing has completed - if(file_exists($lockFile)){ - @unlink($lockFile); - } - - $default->log->debug('documentProcessor: stopping'); + $default->log->debug('documentProcessor: stopping processing, batch completed'); } /** diff --git a/search2/indexing/extractors/OpenOfficeTextExtractor.inc.php b/search2/indexing/extractors/OpenOfficeTextExtractor.inc.php index 36e18cc..dfee453 100644 --- a/search2/indexing/extractors/OpenOfficeTextExtractor.inc.php +++ b/search2/indexing/extractors/OpenOfficeTextExtractor.inc.php @@ -1,14 +1,11 @@ unzip) { return sprintf(_kt("Cannot locate unzip: %s."), $this->unzip); diff --git a/search2/indexing/extractors/OpenXmlTextExtractor.inc.php b/search2/indexing/extractors/OpenXmlTextExtractor.inc.php index 4cb09ba..773d3be 100644 --- a/search2/indexing/extractors/OpenXmlTextExtractor.inc.php +++ b/search2/indexing/extractors/OpenXmlTextExtractor.inc.php @@ -6,7 +6,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -37,6 +37,8 @@ * */ +require_once(KT_DIR.'/thirdparty/peclzip/pclzip.lib.php'); + class OpenXmlTextExtractor extends ExternalDocumentExtractor { public function __construct() @@ -217,6 +219,9 @@ class OpenXmlTextExtractor extends ExternalDocumentExtractor } $filename = str_replace('\\','/',$filename); + /* + // Removing the unzip command as the whole document gets unzipped at the start + $cmd = '"' .$this->unzip . '"' . ' ' . str_replace( array('{source}','{part}', '{target_dir}'), array($this->sourcefile, $filename,$this->openxml_dir), $this->unzip_params); @@ -226,6 +231,7 @@ class OpenXmlTextExtractor extends ExternalDocumentExtractor $this->output = _kt('Failed to execute command: ') . $cmd; return false; } + */ $filename = $this->openxml_dir . "/$filename"; if (!file_exists($filename)) @@ -321,6 +327,7 @@ class OpenXmlTextExtractor extends ExternalDocumentExtractor */ public function diagnose() { + return null; if (false === $this->unzip) { return sprintf(_kt("Cannot locate unzip: %s."), $this->unzip); diff --git a/search2/indexing/indexerCore.inc.php b/search2/indexing/indexerCore.inc.php index ead6e54..9b26082 100755 --- a/search2/indexing/indexerCore.inc.php +++ b/search2/indexing/indexerCore.inc.php @@ -6,7 +6,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -643,6 +643,16 @@ abstract class Indexer $default->log->debug("index: Queuing indexing of $document_id"); + // Appending the process queue to the index for convenience + // Don't want to complicate matters by creating too many new classes and files + Indexer::unqueueDocFromProcessing($document_id); + + // enqueue item + $date = date('Y-m-d H:i:s'); + $sql = "INSERT INTO process_queue(document_id, date_added) VALUES($document_id, '$date')"; + DBUtil::runQuery($sql); + + $default->log->debug("Processing queue: Queuing document for processing - $document_id"); } private static function incrementCount() @@ -722,8 +732,37 @@ abstract class Indexer DBUtil::runQuery($sql); $default->log->debug("Indexer::clearoutDeleted: removed documents from indexing queue that have been deleted"); + + // Multiple indexing processes cannot occur at the same time - the lock file prevents this. + // However if the indexing is interrupted the documents can get stuck in the queue with the processdate set + // but never having been indexed. To prevent this we will clear the processdate on all documents without errors. + $sql = 'UPDATE index_files SET processdate = null where processdate is not null and status_msg is null'; + $res = DBUtil::runQuery($sql); + + if(PEAR::isError($res)){ + $default->log->error("Indexer::clearoutDeleted: something happened ".$res->getMessage); + } + + $default->log->debug("Indexer::clearoutDeleted: resetting processdate for documents that may be stuck"); } + /** + * Clearout the processing of documents that no longer exist. + * + */ + public static function clearoutDeletedFromProcessor() + { + global $default; + + $sql = 'DELETE FROM + process_queue + WHERE + document_id in (SELECT d.id FROM documents AS d WHERE d.status_id=3) OR + NOT EXISTS(SELECT process_queue.document_id FROM documents WHERE process_queue.document_id=documents.id)'; + $result = DBUtil::runQuery($sql); + + $default->log->debug("Process queue: removed documents from processing queue that have been deleted"); + } /** * Check if a document is scheduled to be indexed @@ -1191,7 +1230,7 @@ abstract class Indexer } /** - * Get the queue of documents for processing + * Get the queue of documents for indexing * Refactored from indexDocuments() */ public function getDocumentsQueue($max = null) @@ -1222,7 +1261,7 @@ abstract class Indexer if (PEAR::isError($result)) { //unlink($indexLockFile); - if ($this->debug) $default->log->debug('indexDocuments: stopping - db error'); + if ($this->debug) $default->log->error('indexDocuments: stopping - db error'); return; } KTUtil::setSystemSetting('luceneIndexingDate', time()); @@ -1253,6 +1292,51 @@ abstract class Indexer } /** + * Get the queue of documents for processing + * + */ + public function getDocumentProcessingQueue($max = null) + { + global $default; + $max = (empty($max)) ? 20 : $max; + + // Cleanup the queue + Indexer::clearoutDeletedFromProcessor(); + + $date = date('Y-m-d H:i:s'); + // identify the indexers that must run + // mysql specific limit! + $sql = "SELECT + pq.document_id, mt.filetypes, mt.mimetypes + FROM + process_queue pq + INNER JOIN documents d ON pq.document_id=d.id + INNER JOIN document_metadata_version dmv ON d.metadata_version_id=dmv.id + INNER JOIN document_content_version dcv ON dmv.content_version_id=dcv.id + INNER JOIN mime_types mt ON dcv.mime_id=mt.id + WHERE + (pq.date_processed IS NULL or pq.date_processed < date_sub('$date', interval 1 day)) AND dmv.status_id=1 + ORDER BY date_added + LIMIT $max"; + + $result = DBUtil::getResultArray($sql); + if (PEAR::isError($result)) + { + $default->log->error('Processing queue: stopping - db error: '.$result->getMessage()); + return; + } + + // bail if no work to do + if (count($result) == 0) + { + $default->log->debug('Processing queue: stopping - no work to be done'); + return; + } + + return $result; + } + + /** * Process a document - extract text and index it * Refactored from indexDocuments() * @@ -1813,7 +1897,7 @@ abstract class Indexer } /** - * Remove the document from the queue. This is normally called when it has been processed. + * Remove the document from the indexing queue. This is normally called when it has been processed. * * @param int $docid */ @@ -1829,6 +1913,23 @@ abstract class Indexer } /** + * Remove the document from the processing queue. This is normally called when it has been processed. + * + * @param int $docid + */ + public static function unqueueDocFromProcessing($docid, $reason=false, $level='debug') + { + $sql = "DELETE FROM process_queue WHERE document_id=$docid"; + $result = DBUtil::runQuery($sql); + + if ($reason !== false) + { + global $default; + $default->log->$level("Processor queue: removing document $docid from the queue - $reason"); + } + } + + /** * Run a query on the index. * * @param string $query diff --git a/setup/migrate/config/commercial_config.xml b/setup/migrate/config/commercial_config.xml index a41216e..514ff41 100644 --- a/setup/migrate/config/commercial_config.xml +++ b/setup/migrate/config/commercial_config.xml @@ -10,7 +10,7 @@ installation - database + database services complete diff --git a/setup/migrate/config/community_config.xml b/setup/migrate/config/community_config.xml index d4c6097..01ac9bc 100644 --- a/setup/migrate/config/community_config.xml +++ b/setup/migrate/config/community_config.xml @@ -10,7 +10,7 @@ installation - database + database services complete diff --git a/setup/migrate/migrater.php b/setup/migrate/migrater.php index dff40d1..d7b6907 100644 --- a/setup/migrate/migrater.php +++ b/setup/migrate/migrater.php @@ -540,6 +540,9 @@ class Migrater { $this->_landing(); } elseif ($res == 'landing') { $this->_landing(); + } elseif ($res == 'binstall') { + $util = new MigrateUtil(); + $util->redirect('../wizard/index.php?step_name=dependencies'); } else { } break; @@ -550,10 +553,10 @@ class Migrater { $util = new MigrateUtil(); $util->redirect('../wizard/index.php?step_name=installtype'); break; - case 'binstall': - $util = new MigrateUtil(); - $util->redirect('../wizard/index.php?step_name=dependencies'); - break; +// case 'binstall': +// $util = new MigrateUtil(); +// $util->redirect('../wizard/index.php?step_name=dependencies'); +// break; default: // TODO : handle silent $this->_landing(); diff --git a/setup/migrate/steps/migrateComplete.php b/setup/migrate/steps/migrateComplete.php index 1609660..1fe77e8 100644 --- a/setup/migrate/steps/migrateComplete.php +++ b/setup/migrate/steps/migrateComplete.php @@ -1,6 +1,6 @@ temp_variables = array("step_name"=>"complete", "silent"=>$this->silent); - $this->doRun(); - return 'landing'; + return $this->doRun(); } function doRun() { - $this->checkServices(); - $this->checkSqlDump(); - $this->checkPaths(); + $this->checkSqlDump(); + if(!$this->inStep("complete")) { + + return 'landing'; + } + if($this->next()) { + if($this->checkZendMysql()) { + return 'binstall'; + } else { + return 'error'; + } + } $this->removeInstallSessions(); - $this->storeSilent();// Set silent mode variables + return 'landing'; } private function removeInstallSessions() { @@ -77,26 +104,13 @@ class migrateComplete extends Step { } } - private function checkPaths() { - $installation = $this->getDataFromSession("installation"); // Get installation directory - foreach ($installation['urlPaths'] as $path) { - if(is_writable($path['path']) && is_readable($path['path'])) { - $this->temp_variables['paths'][$path['name']]['class'] = "tick"; - } else { - $this->temp_variables['paths'][$path['name']]['class'] = "cross_orange"; - } - $this->temp_variables['paths'][$path['name']]['name'] = $path['name']; - $this->temp_variables['paths'][$path['name']]['msg'] = $path['path']; - } - } - private function checkSqlDump() { $database = $this->getDataFromSession("database"); // Get installation directory $sqlFile = $database['dumpLocation']; if(file_exists($sqlFile)) { $this->temp_variables['sql']['class'] = "tick"; - $this->temp_variables['sql']['name'] = "dms.sql"; - $this->temp_variables['sql']['msg'] = "Data file created"; + $this->temp_variables['sql']['name'] = "";//dms.sql + $this->temp_variables['sql']['msg'] = $sqlFile; return true; } else { $this->temp_variables['sql']['class'] = "cross"; @@ -106,41 +120,75 @@ class migrateComplete extends Step { } } - private function checkServices() - { - $services = $this->util->loadInstallServices(); // Use installer services class - $this->conf = $this->getDataFromSession("installation"); // Get installation directory - foreach ($services as $serviceName) { - $className = OS.$serviceName; - $serv = $this->util->loadInstallService($className); - $serv->load(); - $sStatus = $serv->status(); - if($sStatus == 'STARTED') { - $state = 'cross'; - $this->error[] = "Service : {$serv->getName()} could not be uninstalled.
"; - $this->services_check = 'cross'; - //$stopmsg = OS.'GetStopMsg'; - $this->temp_variables['services'][$serv->getName()]['msg'] = "Service Running"; //$serv->getStopMsg($this->conf['location']); - } else { - $state = 'tick'; - $this->temp_variables['services'][$serv->getName()]['msg'] = "Service has been uninstalled"; - } - $this->temp_variables['services'][$serv->getName()]['class'] = $state; - $this->temp_variables['services'][$serv->getName()]['name'] = $serv->getName(); + /** + * Check if services are uninstall + * + */ + private function checkMysql() { + $running = false; + if(WINDOWS_OS) { + $cmd = "sc query {$this->mysqlServiceName}"; + $response = $this->util->pexec($cmd); + if($response['out']) { + $state = preg_replace('/^STATE *\: *\d */', '', trim($response['out'][3])); // Status store in third key + } + if($state == "STARTED") + $running = true; + } else { + $installation = $this->getDataFromSession("installation"); // Get installation directory + $mysqlPid = $installation['location'].DS."mysql".DS."data".DS."mysqld.pid"; + if(file_exists($mysqlPid)) + $running = true; } - if ($this->services_check != 'tick') { + if($running) { + $this->temp_variables['ktmysql']['class'] = "cross"; + $this->temp_variables['ktmysql']['name'] = "KTMysql"; + $this->temp_variables['ktmysql']['msg'] = "Service Running"; + $this->error[] = "Service : KTMysql running.
"; return false; + } else { + $this->temp_variables['ktmysql']['class'] = "tick"; + $this->temp_variables['ktmysql']['name'] = "KTMysql"; + $this->temp_variables['ktmysql']['msg'] = "Service has been uninstalled"; + return true; } - - return true; } - /** - * Set all silent mode varibles - * - */ - private function storeSilent() { - $this->temp_variables['servicesCheck'] = $this->services_check; + private function checkZendMysql() { + $running = false; + if(WINDOWS_OS) { + $cmd = "sc query {$this->zendMysql}"; + $response = $this->util->pexec($cmd); + if($response['out']) { + $state = preg_replace('/^STATE *\: *\d */', '', trim($response['out'][3])); // Status store in third key + } + if($state == "STARTED" || $state == "RUNNING") + $running = true; + } else { + //TODO : Read fomr my.cnf file + $mysqlPid = "/var/run/mysqld/mysqld.sock"; + if(file_exists($mysqlPid)) + $running = true; + $mysqlPid = "/var/run/mysqld/mysqld.pid"; + if(file_exists($mysqlPid)) + $running = true; + } + if($running) { + $this->temp_variables['zmysql']['class'] = "tick"; + $this->temp_variables['zmysql']['name'] = "KTMysql"; + $this->temp_variables['zmysql']['msg'] = "Service Running"; + return true; + } else { + $this->temp_variables['zmysql']['class'] = "cross"; + $this->temp_variables['zmysql']['name'] = "Mysql"; + $this->temp_variables['zmysql']['msg'] = "Service not running"; + $this->error[] = "Service : KTMysql running.
"; + return false; + } + } + + public function getErrors() { + return $this->error; } } ?> \ No newline at end of file diff --git a/setup/migrate/steps/migrateDatabase.php b/setup/migrate/steps/migrateDatabase.php index 179d212..d304329 100644 --- a/setup/migrate/steps/migrateDatabase.php +++ b/setup/migrate/steps/migrateDatabase.php @@ -1,6 +1,6 @@ sqlDumpFile = realpath($sqlFile); // Store location of dump return true; + } else { + unlink($sqlFile); } } $noFile = true; @@ -168,9 +170,9 @@ class migrateDatabase extends Step } $cmd = $exe.' -u"'.$dbAdminUser.'" -p"'.$dbAdminPass.'" --port="'.$port.'" '.$dbName.' > '.$sqlFile; if($noFile) { - $this->error[]['error'] = "Could not connect to the KnowledgeTree Database"; - $this->error[]['msg'] = "Make sure all KnowledgeTree Services are running."; - $this->error[]['cmd'] = "

Click Next after resolving the above errors.

"; + $this->error[]['error'] = "The KnowledgeTree Setup Wizard was unable to connect to your KnowledgeTree 3.6.1 database."; + $this->error[]['msg'] = "Please ensure that all KnowledgeTree Services are running."; + $this->error[]['cmd'] = "Click Next after resolving the above errors."; $this->temp_variables['manual_export'] = ""; } else { $this->error[]['error'] = "Could not export database:"; diff --git a/setup/migrate/steps/migrateInstallation.php b/setup/migrate/steps/migrateInstallation.php index 0718624..e97c313 100644 --- a/setup/migrate/steps/migrateInstallation.php +++ b/setup/migrate/steps/migrateInstallation.php @@ -128,7 +128,7 @@ class migrateInstallation extends step public function detectInstallation() { if(WINDOWS_OS) { - $knownWindowsLocations = array("C:\Program Files\ktdms"=>"C:\Program Files\ktdms\knowledgeTree\config\config-path","C:\Program Files x86\ktdms"=>"C:\Program Files x86\ktdms\knowledgeTree\config\config-path","C:\ktdms"=>"C:\ktdms\knowledgeTree\config\config-path"); + $knownWindowsLocations = array("C:\Program Files\ktdms"=>"C:\Program Files\ktdms\knowledgeTree\config\config-path","C:\Program Files (x86)\ktdms"=>"C:\Program Files (x86)\ktdms\knowledgeTree\config\config-path","C:\ktdms"=>"C:\ktdms\knowledgeTree\config\config-path"); foreach ($knownWindowsLocations as $loc=>$configPath) { if(file_exists($configPath)) $this->location = $loc; @@ -160,7 +160,7 @@ class migrateInstallation extends step public function checkVersion() { if($this->foundVersion < $this->supportedVersion) { $this->versionError = true; - $this->error[] = "KT installation needs to be 3.6.1 or higher"; + $this->error[] = "KnowledgeTree installation needs to be 3.6.1 or higher"; return false; } @@ -173,7 +173,7 @@ class migrateInstallation extends step $foundVersion = file_get_contents($verFile); return $foundVersion; } else { - $this->error[] = "KT installation version not found"; + $this->error[] = "KnowledgeTree installation version not found"; } return false; @@ -214,10 +214,10 @@ class migrateInstallation extends step return true; } - $this->error[] = "KT installation configuration file empty"; + $this->error[] = "KnowledgeTree installation configuration file empty"; } } else { - $this->error[] = "KT installation configuration file not found"; + $this->error[] = "KnowledgeTree installation configuration file not found"; } } else { $this->error[] = "Please Enter a Location"; @@ -241,16 +241,10 @@ class migrateInstallation extends step if ($froot == 'default') { $froot = $this->location; } - $this->ktSettings = array('fileSystemRoot'=> $froot, - ); + $this->ktSettings = array('fileSystemRoot'=> $froot); $varDir = $froot.DS.'var'; - $this->urlPaths = array(array('name'=> 'Var Directory', 'path'=> $varDir), - array('name'=> 'Log Directory', 'path'=> $varDir.DS.'log'), - array('name'=> 'Document Root', 'path'=> $varDir.DS.'Documents'), - array('name'=> 'UI Directory', 'path'=> $froot.DS.'presentation'.DS.'lookAndFeel'.DS.'knowledgeTree'), - array('name'=> 'Temporary Directory', 'path'=> $varDir.DS.'tmp'), - array('name'=> 'Cache Directory', 'path'=> $varDir.DS.'cache'), - array('name'=> 'Upload Directory', 'path'=> $varDir.DS.'uploads'), + $this->urlPaths = array( + array('name'=> 'Document Root', 'path'=> $froot.DS.'Documents'), ); $this->dbSettings['dbPort'] = $this->util->getPort($this->location); // Add Port $this->temp_variables['urlPaths'] = $this->urlPaths; diff --git a/setup/migrate/steps/migrateServices.php b/setup/migrate/steps/migrateServices.php index b1f0aed..acd6d87 100644 --- a/setup/migrate/steps/migrateServices.php +++ b/setup/migrate/steps/migrateServices.php @@ -116,6 +116,7 @@ class migrateServices extends Step protected $conf = array(); + protected $mysqlServiceName = "KTMysql"; /** * Main control of services setup * @@ -155,10 +156,12 @@ class migrateServices extends Step * @return boolean */ private function doRun() { + $installation = $this->getDataFromSession("installation"); // Get installation directory + $this->conf = $installation['location']; if(!$this->alreadyUninstalled()) { // Pre-check if services are uninstalled $this->uninstallServices(); } - $this->uninstallServices(); + //$this->uninstallServices(); return $this->checkServices(); } @@ -186,12 +189,23 @@ class migrateServices extends Step } private function mysqlRunning() { - $installation = $this->getDataFromSession("installation"); // Get installation directory - $mysqlPid = $installation['location'].DS."mysql".DS."data".DS."mysqld.pid"; - if(file_exists($mysqlPid)) { - return true; + $running = false; + if(WINDOWS_OS) { + $cmd = "sc query {$this->mysqlServiceName}"; + $response = $this->util->pexec($cmd); + if($response['out']) { + $state = preg_replace('/^STATE *\: *\d */', '', trim($response['out'][3])); // Status store in third key + } + if($state == "STARTED" || $state == 'RUNNING') { + $running = true; + } + } else { + $installation = $this->getDataFromSession("installation"); // Get installation directory + $mysqlPid = $installation['location'].DS."mysql".DS."data".DS."mysqld.pid"; + if(file_exists($mysqlPid)) + $running = true; } - return false; + return $running; } /** @@ -199,11 +213,10 @@ class migrateServices extends Step * */ private function uninstallServices() { - $this->conf = $this->getDataFromSession("installation"); // Get installation directory - if($this->conf['location'] != '') { - $func = OS."Stop";// Try the dmsctl - $this->$func(); - } + $func = OS."Stop"; + //echo "$func"; + $this->$func(); + $this->shutdown(); } @@ -225,12 +238,18 @@ class migrateServices extends Step * */ private function windowsStop() { + $cmd = "sc stop KTScheduler"; + $response = $this->util->pexec($cmd); + $cmd = "sc stop KTLucene"; + $response = $this->util->pexec($cmd); + $cmd = "sc stop KTOpenoffice"; + $response = $this->util->pexec($cmd); + $cmd = "sc delete KTOpenoffice"; + $response = $this->util->pexec($cmd); $cmd = "sc delete KTLucene"; - $this->util->pexec($cmd); + $response = $this->util->pexec($cmd); $cmd = "sc delete KTScheduler"; - $this->util->pexec($cmd); - $cmd = "sc delete KTOpenoffice"; - $this->util->pexec($cmd); + $response = $this->util->pexec($cmd); } /** @@ -247,10 +266,17 @@ class migrateServices extends Step $serv->uninstall(); } } + $this->shutdownMysql(); + } + + private function shutdownMysql() { + $cmd = "sc stop {$this->mysqlServiceName}"; + $response = $this->util->pexec($cmd); + } /** - * Check if services are uninstall + * Check if services are uninstall * */ private function checkServices() { @@ -259,18 +285,22 @@ class migrateServices extends Step $serv = $this->util->loadInstallService($className); $serv->load(); $sStatus = $serv->status(); - if($sStatus == 'STARTED') { + if($sStatus == 'STARTED' || $sStatus == 'RUNNING') { + $state = 'cross'; + $this->error[] = "Service : {$serv->getName()} could not be uninstalled.
"; + $this->serviceCheck = 'cross'; + $this->temp_variables['services'][$serv->getName()]['msg'] = "Service Running"; + } elseif ($sStatus == 'STOPPED') { $state = 'cross'; $this->error[] = "Service : {$serv->getName()} could not be uninstalled.
"; $this->serviceCheck = 'cross'; - //$stopmsg = OS.'GetStopMsg'; - $this->temp_variables['services'][$serv->getName()]['msg'] = "Service Running"; //$serv->getStopMsg($this->conf['location']); + $this->temp_variables['services'][$serv->getName()]['msg'] = "Service Stopped, please uninstall service"; } else { $state = 'tick'; $this->temp_variables['services'][$serv->getName()]['msg'] = "Service has been uninstalled"; } $this->temp_variables['services'][$serv->getName()]['class'] = $state; - $this->temp_variables['services'][$serv->getName()]['name'] = $serv->getName(); + $this->temp_variables['services'][$serv->getName()]['name'] = $serv->getHRName(); } if(!$this->checkMysql()) { return false; @@ -287,18 +317,40 @@ class migrateServices extends Step * */ private function checkMysql() { - $installation = $this->getDataFromSession("installation"); // Get installation directory - $mysqlPid = $installation['location'].DS."mysql".DS."data".DS."mysqld.pid"; - if(file_exists($mysqlPid)) { + $running = false; + if(WINDOWS_OS) { + $cmd = "sc query {$this->mysqlServiceName}"; + $response = $this->util->pexec($cmd); + if($response['out']) { + $state = preg_replace('/^STATE *\: *\d */', '', trim($response['out'][3])); // Status store in third key + } + if($state == "STARTED" || $state == "RUNNING") { + $running = true; + } + } else { + $installation = $this->getDataFromSession("installation"); // Get installation directory + $mysqlPid = $installation['location'].DS."mysql".DS."data".DS."mysqld.pid"; + if(file_exists($mysqlPid)) + $running = true; + } + if($running) { $this->temp_variables['services']['KTMysql']['class'] = "cross"; - $this->temp_variables['services']['KTMysql']['name'] = "KTMysql"; + if(WINDOWS_OS) { + $this->temp_variables['services']['KTMysql']['name'] = "KnowledgeTree Mysql Service. (KTMysql)"; + } else { + $this->temp_variables['services']['KTMysql']['name'] = "KnowledgeTree Mysql Service."; + } $this->temp_variables['services']['KTMysql']['msg'] = "Service Running"; $this->error[] = "Service : KTMysql running.
"; return false; } else { $this->temp_variables['services']['KTMysql']['class'] = "tick"; - $this->temp_variables['services']['KTMysql']['name'] = "KTMysql"; - $this->temp_variables['services']['KTMysql']['msg'] = "Service has been uninstalled"; + if(WINDOWS_OS) { + $this->temp_variables['services']['KTMysql']['name'] = "KnowledgeTree Mysql Service. (KTMysql)"; + } else { + $this->temp_variables['services']['KTMysql']['name'] = "KnowledgeTree Mysql Service."; + } + $this->temp_variables['services']['KTMysql']['msg'] = "Service has been stopped"; return true; } } diff --git a/setup/migrate/templates/complete.tpl b/setup/migrate/templates/complete.tpl index 03f5c92..f1fd284 100644 --- a/setup/migrate/templates/complete.tpl +++ b/setup/migrate/templates/complete.tpl @@ -1,72 +1,23 @@

Migration Completed

-

This allows you to check that your KnowledgeTree configuration is set - up correctly. You can run this at any time after configuration to check - that things are still set up correctly.

- - ' - . '' - . 'Click Here for help on overcoming post migrate issues
'; - } - ?> +

Your database migration was successfully completed. Please check the section below for details of the migration and final instructions

+ -

Exported Database

- - - - - - -
'>     
- -

Uninstalled Services

- - - - - - - - - - - -
'>     
- -

System Path

- - - - - - - - - - - -
'>     
+

KnowledgeTree database successfully exported to:

+ '>      +

+

Start new MySQL service

+ In order to complete the upgrade process please start the Zend Server MySQL service and then click Next to continue (Click here for help). +

+ + '>      + + +
- + +
js('form.js'); } ?> \ No newline at end of file diff --git a/setup/migrate/templates/database.tpl b/setup/migrate/templates/database.tpl index da30653..b1d0399 100644 --- a/setup/migrate/templates/database.tpl +++ b/setup/migrate/templates/database.tpl @@ -3,16 +3,10 @@
This step configures the connection to the database server and migrates the database. - -
- -

The Setup Wizard will now migrate your existing database to the new Zend Server stack. This process may take - several minutes to complete.


+

The Setup Wizard will now export your existing database in preparation for the migration to the new KnowledgeTree Stack.


Please ensure that your database is backed up before proceeding. If you need assistance with backing up see the  'Backing up and restoring KnowledgeTree'  wiki entry.

diff --git a/setup/migrate/templates/installation.tpl b/setup/migrate/templates/installation.tpl index 4bc960b..ffcd8da 100644 --- a/setup/migrate/templates/installation.tpl +++ b/setup/migrate/templates/installation.tpl @@ -1,15 +1,5 @@

Current Installation

- - -       - KnowledgeTree installation has been detected. Please click Next to continue. -

-       @@ -26,19 +16,18 @@

- Enter the full path of the installation you wish to upgrade: -

-

- The default is 'C:\Program Files\ktdms' on Windows and '/opt/ktdms' or '/home/username/ktdms/' on other operating systems. + The Setup Wizard will now prepare your current KnowledgeTree database for migration to the new KnowledgeTree Stack. +

+ +

+ Please enter the full path of the installation you wish to upgrade:

-

- - Make sure that the KnowledgeTree services are running. - -

-
+

+

+ (The default is 'C:\Program Files\ktdms' on Windows and '/opt/ktdms' or '/home/username/ktdms/' on other operating systems.) +

- +
js('form.js'); } ?> \ No newline at end of file diff --git a/setup/migrate/templates/services.tpl b/setup/migrate/templates/services.tpl index 5038d51..37e6ea7 100644 --- a/setup/migrate/templates/services.tpl +++ b/setup/migrate/templates/services.tpl @@ -2,7 +2,7 @@

Deactivate Services

- All KnowledgeTree services need to be deactivated before the migration takes place. + All KnowledgeTree services need to be shutdown before the migration can continue.

All services are uninstalled. -

     "; ?>Services Check

+

     "; ?>Please shutdown the following services

- -
+
- - + + @@ -76,7 +75,7 @@
'>     

-

Click Next if deactivating the above services.

+

Click Next if the above services are deactivated .

diff --git a/setup/migrate/templates/wizard.tpl b/setup/migrate/templates/wizard.tpl index 4309d2e..a82660a 100644 --- a/setup/migrate/templates/wizard.tpl +++ b/setup/migrate/templates/wizard.tpl @@ -11,6 +11,9 @@ css('wizard.css'); ?> css('migrate.css'); ?> css('ie6.css'); ?> + css('ie7.css'); ?> + css('ie8.css'); ?> + css('community.css'); ?> diff --git a/setup/upgrade/lib/UpgradeItems.inc.php b/setup/upgrade/lib/UpgradeItems.inc.php index 2e5e3fc..80d8696 100644 --- a/setup/upgrade/lib/UpgradeItems.inc.php +++ b/setup/upgrade/lib/UpgradeItems.inc.php @@ -5,7 +5,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the @@ -57,16 +57,16 @@ require_once("../wizard/dbUtilities.php"); // {{{ Upgrade_Already_Applied class Upgrade_Already_Applied { - + function Upgrade_Already_Applied($oUpgradeItem) { $this->oUpgradeItem = $oUpgradeItem; } - + } // }}} class UpgradeItem { - + public $type = ""; public $name; public $version; @@ -76,7 +76,8 @@ class UpgradeItem { public $parent; public $date; public $result; - + protected $error; + function UpgradeItem($name, $version, $description = null, $phase = 0, $priority = 0) { $this->name = $name; $this->version = $version; @@ -86,7 +87,7 @@ class UpgradeItem { $this->description = $description; $this->phase = $phase; $this->priority = $priority; - + $this->dbUtilities = new dbUtilities(); $this->iniUtilities = new iniUtilities(); } @@ -122,6 +123,14 @@ class UpgradeItem { return $this->type; } + public function getErrors() + { + if(isset($this->error[0])){ + return $this->error[0]; + } + return $this->error; + } + /** * Runs a DB query and returns a result based on arguments which specify what to look for * @@ -135,13 +144,13 @@ class UpgradeItem { $this->dbUtilities = new dbUtilities(); $this->iniUtilities = new iniUtilities(); } - + $wizConfigHandler = new configuration(); $configPath = $wizConfigHandler->readConfigPathIni(); - + $this->iniUtilities->load($configPath); $dconf = $this->iniUtilities->getSection('db'); - $this->dbUtilities->load($dconf['dbHost'], '', $dconf['dbUser'], $dconf['dbPass'], $dconf['dbName']); + $this->dbUtilities->load($dconf['dbHost'], '', $dconf['dbAdminUser'], $dconf['dbAdminPass'], $dconf['dbName']); $result = $this->dbUtilities->query($query); if($checkResult) { $assArr = $this->dbUtilities->fetchAssoc($result); @@ -153,7 +162,7 @@ class UpgradeItem { } return !is_null($result); } - + function _upgradeTableInstalled() { $query = "SELECT COUNT(id) FROM upgrades"; $res = $this->runDBQuery($query, true, true); @@ -169,7 +178,7 @@ class UpgradeItem { } $query = "SELECT id FROM upgrades WHERE descriptor = '".$this->getDescriptor()."' AND result = 1"; $res = $this->runDBQuery($query, true, false); - + if(!$res) { return true; } @@ -214,7 +223,7 @@ class UpgradeItem { } $sql = "INSERT INTO upgrades (`id`, `descriptor`, `description`, `date_performed`, `result`, `parent`) VALUES (NULL, '". $this->getDescriptor()."', '".$this->description."', '".$this->date."', '".$result."', '".$parentid."')"; $this->dbUtilities->query($sql); - + return true; } @@ -225,7 +234,7 @@ class UpgradeItem { } // end class UpgradeItem class SQLUpgradeItem extends UpgradeItem { - + function SQLUpgradeItem($path, $version = null, $description = null, $phase = null, $priority = null) { $this->type = "sql"; $this->priority = 0; @@ -335,7 +344,7 @@ class SQLUpgradeItem extends UpgradeItem { $phase = 0; return array($fromVersion, $toVersion, $description, $phase); } - $matched = preg_match('#^([\d.]*)/(?:(\d*)-)?(.*)\.sql$#', $path, $matches); + $matched = preg_match('#^([\d\.-]*)/(?:(\d*)-)?(.*)\.sql$#', $path, $matches); //$matched = preg_match('#^([\d.]*)/(?:(\d*)-)?(.*):(?:(\d*))\.sql$#', $path, $matches); if ($matched != 0) { $fromVersion = $matches[1]; @@ -366,11 +375,11 @@ class SQLUpgradeItem extends UpgradeItem { $queries = SQLFile::sqlFromFile($sqlupgradedir . $this->name); return $this->dbUtilities->runQueries($queries); } - + } // end class SQLUpgradeItem class KTRebuildPermissionObserver { - + function start() { $this->lastBeat = time(); } @@ -384,11 +393,11 @@ class KTRebuildPermissionObserver { } function end() { } - + } class RecordUpgradeItem extends UpgradeItem { - + function RecordUpgradeItem ($version, $oldversion = null) { $this->type = "upgrade"; if (is_null($oldversion)) { @@ -426,7 +435,7 @@ class RecordUpgradeItem extends UpgradeItem { KTPermissionUtil::rebuildPermissionLookups(true); $po->end(); */ - + $versionFile=KT_DIR . '/docs/VERSION-NAME.txt'; $fp = fopen($versionFile,'rt'); $systemVersion = fread($fp, filesize($versionFile)); @@ -495,7 +504,7 @@ class RecordUpgradeItem extends UpgradeItem { @unlink($sFile); } } - + } // end class RecordUpgradeItem ?> diff --git a/setup/upgrade/step.php b/setup/upgrade/step.php index 691224b..5a36d16 100644 --- a/setup/upgrade/step.php +++ b/setup/upgrade/step.php @@ -467,7 +467,7 @@ class Step $foundVersion = file_get_contents($verFile); return $foundVersion; } else { - $this->error[] = "KT installation version not found"; + $this->error[] = "KnowledgeTree installation version not found"; } return false; diff --git a/setup/upgrade/steps/upgradeComplete.php b/setup/upgrade/steps/upgradeComplete.php index eaa399d..89f5378 100644 --- a/setup/upgrade/steps/upgradeComplete.php +++ b/setup/upgrade/steps/upgradeComplete.php @@ -49,8 +49,13 @@ class upgradeComplete extends Step { public function doStep() { $this->temp_variables = array("step_name"=>"complete", "silent"=>$this->silent); + $this->temp_variables['isCE'] = false; + $type = $this->util->getVersionType(); + if($type == "community") + $this->temp_variables['isCE'] = true; $this->doRun(); $this->storeSilent(); + $this->util->deleteMigrateFile(); return 'landing'; } @@ -86,7 +91,7 @@ class upgradeComplete extends Step { */ protected function storeSilent() { $v = $this->getDataFromSession('upgradeProperties'); - $this->temp_variables['sysVersion'] = $v['upgrade_version']; + $this->temp_variables['sysVersion'] = $this->util->readVersion(); $this->temp_variables['migrateCheck'] = $this->migrateCheck; $this->temp_variables['servicesCheck'] = $this->servicesCheck; } diff --git a/setup/upgrade/steps/upgradeDatabase.php b/setup/upgrade/steps/upgradeDatabase.php index 789f483..4ebbbfe 100644 --- a/setup/upgrade/steps/upgradeDatabase.php +++ b/setup/upgrade/steps/upgradeDatabase.php @@ -1,6 +1,6 @@ temp_variables = array("step_name"=>"database", "silent"=>$this->silent, + $this->temp_variables = array("step_name"=>"database", "silent"=>$this->silent, "loadingText"=>"The database upgrade is under way. Please wait until it completes"); $this->initErrors(); + $this->checkMigration(); if(!$this->inStep("database")) { $this->doRun(); return 'landing'; @@ -119,25 +121,31 @@ class upgradeDatabase extends Step } return 'error'; } - + $this->doRun(); return 'landing'; } + + public function checkMigration() { + if($this->util->isMigration()) { + $this->migrateCheck = true; + } + } private function confirmUpgrade() { return isset($_POST['ConfirmUpgrade']); } - + private function upgrading() { return isset($_POST['RunUpgrade']); - } - + } + private function doRun($action = null) { $this->readConfig(); - + $this->util->dbUtilities->load($this->dbSettings['dbHost'], $this->dbSettings['dbPort'], $this->dbSettings['dbUser'],$this->dbSettings['dbPass'], $this->dbSettings['dbName']); $this->temp_variables['action'] = $action; - + if (is_null($action) || ($action == 'preview')) { $this->temp_variables['title'] = 'Preview Upgrade'; $this->temp_variables['upgradeTable'] = $this->generateUpgradeTable(); @@ -154,10 +162,10 @@ class upgradeDatabase extends Step } $this->temp_variables['backupSuccessful'] = true; } - + return true; } - + private function generateUpgradeTable() { $this->sysVersion = $this->readVersion(); $this->temp_variables['systemVersion'] = $this->sysVersion; @@ -194,10 +202,10 @@ class upgradeDatabase extends Step $foundVersion = file_get_contents($verFile); return $foundVersion; } else { - $this->error[] = "KT installation version not found"; + $this->error[] = "KnowledgeTree installation version not found"; } - return false; + return false; } /** @@ -213,14 +221,15 @@ class upgradeDatabase extends Step $this->error[$e] = false; } } - + public function storeSilent() { $this->temp_variables['paths'] = $this->paths; $this->temp_variables['sysVersion'] = $this->sysVersion; $this->temp_variables['sysVersion'] = $this->sysVersion; $this->temp_variables['dbSettings'] = $this->dbSettings; + $this->temp_variables['migrateCheck'] = $this->migrateCheck; } - + private function upgradeConfirm() { if (!isset($_SESSION['backupStatus']) || $_SESSION['backupStatus'] === false) { @@ -234,12 +243,12 @@ class upgradeDatabase extends Step private function doDatabaseUpgrade() { $errors = false; - + $this->temp_variables['detail'] = '

The table below describes the upgrades that have occurred to upgrade your KnowledgeTree installation to ' . $this->sysVersion . ''; - + $this->performPreUpgradeActions(); - + $res = $this->performAllUpgrades(); if (!$res) { $errors = true; @@ -247,7 +256,7 @@ class upgradeDatabase extends Step // TODO instantiate error details hideable section? $this->temp_variables['upgradeStatus'] = 'Database upgrade failed

- Please restore from your backup and ensure that the database does not contain + Please restore from your backup and ensure that the database does not contain any unsupported modifications and try the upgrade process again.

If the problem persists, contact KnowledgeTree Support.'; @@ -255,27 +264,27 @@ class upgradeDatabase extends Step else { $this->temp_variables['upgradeStatus'] = 'Upgrade succeeded.'; } - + $this->performPostUpgradeActions(); - - + + return !$errors; } private function performPreUpgradeActions() { - + // This is just to test and needs to be updated to a more sane and error resistent architrcture if it works. // It should idealy work the same as the upgrades. // Lock the scheduler $lockFile = $this->cachePath . DIRECTORY_SEPARATOR . 'scheduler.lock'; touch($lockFile); return true; - + } - + private function deleteDirectory($sPath) { if (empty($sPath) || !is_dir($sPath)) return; - + if (!WINDOWS_OS) { if (file_exists('/bin/rm')) { $this->util->pexec(array('/bin/rm', '-rf', $sPath)); @@ -303,28 +312,31 @@ class upgradeDatabase extends Step closedir($hPath); rmdir($sPath); } - + private function performPostUpgradeActions() { - + // This is just to test and needs to be updated to a more sane and error resistent architrcture if it works. // It should idealy work the same as the upgrades. - + // Ensure all plugins are re-registered. $sql = "TRUNCATE plugin_helper"; $this->util->dbUtilities->query($sql); - + // Clear out all caches and proxies - they need to be regenerated with the new code $this->deleteDirectory($this->proxyPath); $this->deleteDirectory($this->cachePath); - + + // Recreate the cache directory - it doesn't get regenerated + mkdir($this->cachePath, 0755); + // Unlock the scheduler $lockFile = $this->cachePath . DIRECTORY_SEPARATOR . 'scheduler.lock'; if(file_exists($lockFile)){ unlink($lockFile); } - + return true; - + } private function performAllUpgrades () { @@ -343,11 +355,12 @@ class upgradeDatabase extends Step } else { $class = "even"; } - $this->temp_variables['upgradeTable'] .= sprintf('

%s
' . "\n", $class, + $this->temp_variables['upgradeTable'] .= sprintf('
%s
' . "\n", $class, htmlspecialchars($upgrade->getDescription())); ++$row; $res = $upgrade->performUpgrade(); - $this->temp_variables['upgradeTable'] .= sprintf('
%s
', $this->showResult($res)); + $errors = $upgrade->getErrors(); + $this->temp_variables['upgradeTable'] .= sprintf('
%s
', $this->showResult($res, $errors)); $this->temp_variables['upgradeTable'] .= '
' . "\n"; $this->temp_variables['upgradeTable'] .= "
\n"; if ($res === false) { @@ -355,11 +368,11 @@ class upgradeDatabase extends Step break; } } - + return $res; } - - private function showResult($res) { + + private function showResult($res, $errors = null) { if ($res && is_a($res, 'Upgrade_Already_Applied')) { return 'Already applied'; } @@ -367,7 +380,15 @@ class upgradeDatabase extends Step return 'Success'; } if ($res === false) { - return 'Failure'; + $str = 'Failure'; + if(is_array($errors)){ + $str .= '
    '; + foreach ($errors as $error){ + $str .= '
  • '.$error."
  • \n"; + } + $str .= '
'; + } + return $str; } return $res; } diff --git a/setup/upgrade/templates/complete.tpl b/setup/upgrade/templates/complete.tpl index 9d86f35..0099c84 100644 --- a/setup/upgrade/templates/complete.tpl +++ b/setup/upgrade/templates/complete.tpl @@ -1,38 +1,64 @@ -

Database Upgrade Completed

-
-

Your database has been upgraded to
-

+
+ -

Services

- The KnowledgeTree services need to be started to allow for optimal functioning of the search, indexing and pdf generation. - - To start the services, execute the dmsctl.sh shell script in the KnowledgeTree directory from a terminal. +
+

Services

+ The KnowledgeTree services need to be started to allow for optimal functioning of the search, indexing and pdf generation. + + To start the services, execute the dmsctl.sh shell script in the KnowledgeTree directory from a terminal. +
+
+ + To start the services, execute the dmsctl.bat batch file in the KnowledgeTree directory from a command prompt, run as administrator. +
+
+ +

+ + Using shortcuts:
+ [START MENU] => [Programs] => [KnowledgeTree 3.7.x] => [services]
- - To start the services, execute the dmsctl.bat batch file in the KnowledgeTree directory from a command prompt, run as administrator. + Click [Install Services]
+ [START MENU] => [Programs] => [KnowledgeTree 3.7.x] => [services]
- -

- - cd
- dmsctl.bat install
- dmsctl.bat start - + Click [Start Services] +
+
+ Alternatively: +
+ Open a command prompt and enter the following: +
+
+ cd
+ dmsctl.bat install
+ dmsctl.bat start + + cd /usr/share/knowledgetree-ce
- sudo ./dmsctl.sh start + + cd /usr/share/knowledgetree
-

-
+ sudo ./dmsctl.sh start +

+
+ +
+
- Finish + +
\ No newline at end of file diff --git a/setup/upgrade/templates/database.tpl b/setup/upgrade/templates/database.tpl index 6c4c51d..e2d3079 100644 --- a/setup/upgrade/templates/database.tpl +++ b/setup/upgrade/templates/database.tpl @@ -21,7 +21,7 @@ -

We are about to start the upgrade process.

+

We are about to start the upgrade process. Are you sure you want to proceed with the upgrade process?

Please ensure that you have made a backup before continuing with the upgrade process.

@@ -29,17 +29,9 @@
'; - */ echo $upgradeTable; echo '

'; // hiding pre-upgrade notification - /* - echo $postUpgrade; - echo '

'; - */ echo $upgradeStatus; echo '

'; } @@ -58,9 +50,15 @@ + + + + diff --git a/setup/upgrade/templates/installation.tpl b/setup/upgrade/templates/installation.tpl index ad1b10a..f7a5542 100644 --- a/setup/upgrade/templates/installation.tpl +++ b/setup/upgrade/templates/installation.tpl @@ -8,7 +8,7 @@ You will not be able to log into KnowledgeTree until your the database upgrade process is completed.

- !!NB!! You are advised to backup the database before attempting the upgrade. !!NB!! + You are advised to backup the database before attempting the upgrade.

If you have already done this, you may skip this step and can continue directly to the upgrade. diff --git a/setup/upgrade/templates/loading.tpl b/setup/upgrade/templates/loading.tpl index ba837db..350fc4a 100644 --- a/setup/upgrade/templates/loading.tpl +++ b/setup/upgrade/templates/loading.tpl @@ -1,5 +1,5 @@ diff --git a/setup/upgrade/templates/wizard.tpl b/setup/upgrade/templates/wizard.tpl index 723d255..464d790 100644 --- a/setup/upgrade/templates/wizard.tpl +++ b/setup/upgrade/templates/wizard.tpl @@ -11,6 +11,9 @@ css('wizard.css'); ?> css('migrate.css'); ?> css('ie6.css'); ?> + css('ie7.css'); ?> + css('ie8.css'); ?> + css('community.css'); ?> diff --git a/setup/upgrade/upgradeWizard.php b/setup/upgrade/upgradeWizard.php index 71b649c..1e4c873 100644 --- a/setup/upgrade/upgradeWizard.php +++ b/setup/upgrade/upgradeWizard.php @@ -146,18 +146,6 @@ class UpgradeWizard { } /** - * Create upgrade file - * - * @author KnowledgeTree Team - * @access private - * @param none - * @return void - */ - private function createUpgradeFile() { - touch(SYSTEM_DIR.'var'.DS.'bin'.DS."upgrade.lock"); - } - - /** * Remove upgrade file * * @author KnowledgeTree Team @@ -222,11 +210,11 @@ class UpgradeWizard { */ public function dispatch() { $this->load(); - // is this necessary? - $this->createUpgradeFile(); $response = $this->systemChecks(); if($this->util->installationSpecified()) { // Check if the migrator needs to be accessed $this->util->redirect('../wizard/index.php?step_name=install_type'); + } elseif ($this->util->finishInstall()) { // Check if the installer has completed + $this->util->redirect('../../login.php'); } if($response === true) { $this->displayUpgrader(); diff --git a/setup/upgrade/upgrader.php b/setup/upgrade/upgrader.php index ccabb71..7ceb3f1 100644 --- a/setup/upgrade/upgrader.php +++ b/setup/upgrade/upgrader.php @@ -400,20 +400,6 @@ class Upgrader { for ($i=1; $i< count($steps)+1; $i++) { $this->_upgradeHelper($steps[$i]); } - - $this->_completeUpgrade(); - } - - /** - * Complete upgrade cleanup process - * - * @author KnowledgeTree Team - * @param none - * @access private - * @return void - */ - private function _completeUpgrade() { - touch("upgrade"); } /** diff --git a/setup/wizard/installUtil.php b/setup/wizard/installUtil.php index 0796d87..400bd7f 100644 --- a/setup/wizard/installUtil.php +++ b/setup/wizard/installUtil.php @@ -522,42 +522,56 @@ class InstallUtil { } } + /** - * Check if system needs to be accessed + * Check if system needs to be migrated * * @author KnowledgeTree Team * @access public * @param none * @return boolean */ - public function finishSpecified() { - if(isset($_GET['Finish'])) { - if($_GET['Finish'] == "Finish") { + public function migrationSpecified() { + if(isset($_POST['installtype'])) { + if($_POST['installtype'] == "Upgrade Installation") { return true; } } return false; - } + } + + public function upgradeInstall() { + if(isset($_GET['Upgrade'])) { + return true; + } + if(isset($_GET['Next'])) { + if($_POST['Next'] == "Upgrade") { + return true; + } + } + return false; + } + /** - * Check if system needs to be migrated + * Check if system needs to be accessed * * @author KnowledgeTree Team * @access public * @param none * @return boolean */ - public function migrationSpecified() { - if(isset($_POST['installtype'])) { - if($_POST['installtype'] == "Upgrade Installation") { + public function finishInstall() { + if(isset($_GET['Next'])) { + if($_GET['Next'] == "Finish") { return true; } } return false; } - + /** * Check if system needs to be migrated * @@ -595,7 +609,6 @@ class InstallUtil { } public function loginSpecified() { -// return true; if(isset($_GET['Return'])) { if($_GET['Return'] == "Return To Installation") { return true; @@ -727,7 +740,13 @@ class InstallUtil { return true; return false; } - + + public function isCommunity() { + if(INSTALL_TYPE == "community") + return true; + return false; + } + /** * Determine type of installation * @@ -859,7 +878,7 @@ class InstallUtil { return $type; } - return false; + return "community"; } /** @@ -1040,8 +1059,93 @@ class InstallUtil { } // }}} - /* - Just Because. - */ + // {{{ copyDirectory + function copyDirectory($sSrc, $sDst, $bMove = false) { + if (file_exists($sDst)) { + return false; //PEAR::raiseError(_kt("Destination directory already exists.")); + } + if (!WINDOWS_OS) { + if ($bMove && file_exists('/bin/mv')) { + $this->pexec(array('/bin/mv', $sSrc, $sDst)); + return; + } + if (!$bMove && file_exists('/bin/cp')) { + $this->pexec(array('/bin/cp', '-R', $sSrc, $sDst)); + return; + } + } + if (substr($sDst, 0, strlen($sSrc)) === $sSrc) { + return false; //PEAR::raiseError(_kt("Destination of move is within source")); + } + $hSrc = @opendir($sSrc); + if ($hSrc === false) { + return false; //PEAR::raiseError(sprintf(_kt("Could not open source directory: %s"), $sSrc)); + } + if (@mkdir($sDst, 0777) === false) { + return false; //PEAR::raiseError(sprintf(_kt("Could not create destination directory: %s"), $sDst)); + } + while (($sFilename = readdir($hSrc)) !== false) { + if (in_array($sFilename, array('.', '..'))) { + continue; + } + $sOldFile = sprintf("%s/%s", $sSrc, $sFilename); + $sNewFile = sprintf("%s/%s", $sDst, $sFilename); + if (is_dir($sOldFile)) { + $this->copyDirectory($sOldFile, $sNewFile, $bMove); + continue; + } + if ($bMove) { + $this->moveFile($sOldFile, $sNewFile); + } else { + copy($sOldFile, $sNewFile); + } + } + if ($bMove) { + @rmdir($sSrc); + } + } + // }}} + + // {{{ moveFile + function moveFile ($sSrc, $sDst) { + // Only 4.3.3 and above allow us to use rename across partitions + // on Unix-like systems. + if (!WINDOWS_OS) { + // If /bin/mv exists, just use it. + if (file_exists('/bin/mv')) { + $this->pexec(array('/bin/mv', $sSrc, $sDst)); + return; + } + $aSrcStat = stat($sSrc); + if ($aSrcStat === false) { + return false; //PEAR::raiseError(sprintf(_kt("Couldn't stat source file: %s"), $sSrc)); + } + $aDstStat = stat(dirname($sDst)); + if ($aDstStat === false) { + return false; //PEAR::raiseError(sprintf(_kt("Couldn't stat destination location: %s"), $sDst)); + } + if ($aSrcStat["dev"] === $aDstStat["dev"]) { + $res = @rename($sSrc, $sDst); + if ($res === false) { + return false; //PEAR::raiseError(sprintf(_kt("Couldn't move file to destination: %s"), $sDst)); + } + return; + } + $res = @copy($sSrc, $sDst); + if ($res === false) { + return false; //PEAR::raiseError(sprintf(_kt("Could not copy to destination: %s"), $sDst)); + } + $res = @unlink($sSrc); + if ($res === false) { + return false; //PEAR::raiseError(sprintf(_kt("Could not remove source: %s"), $sSrc)); + } + } else { + $res = @rename($sSrc, $sDst); + if ($res === false) { + return false; //PEAR::raiseError(sprintf(_kt("Could not move to destination: %s"), $sDst)); + } + } + } + // }}} } ?> diff --git a/setup/wizard/installWizard.php b/setup/wizard/installWizard.php index bed117e..978ea2f 100644 --- a/setup/wizard/installWizard.php +++ b/setup/wizard/installWizard.php @@ -104,18 +104,6 @@ class InstallWizard { public function __construct(){} /** - * Check if system has been install - * - * @author KnowledgeTree Team - * @access private - * @param none - * @return boolean - */ - private function isSystemInstalled() { - return $this->util->isSystemInstalled(); - } - - /** * Display the wizard * * @author KnowledgeTree Team @@ -280,12 +268,17 @@ class InstallWizard { } elseif ($this->getBypass() === "0") { $this->createInstallFile(); } - if(!$this->isSystemInstalled()) { // Check if the systems not installed - if($this->util->loginSpecified()) { + if ($this->util->finishInstall()) { // Check if the installer has completed + $this->util->redirect('../../login.php'); + } elseif ($this->util->upgradeInstall()) { // Check if the upgrader needs to be accessed + $this->util->redirect('../upgrade/index.php'); + } + if(!$this->util->isSystemInstalled()) { // Check if the systems not installed + if($this->util->loginSpecified()) { // Back to wizard from upgrader $this->util->redirect('../../control.php'); } elseif($this->util->migrationSpecified()) { // Check if the migrator needs to be accessed $this->util->redirect('../migrate/index.php?'); - } elseif ($this->util->upgradeSpecified()) { + } elseif ($this->util->upgradeSpecified()) { // Check if the upgrader needs to be accessed $this->util->redirect('../upgrade/index.php?action=installer'); } $response = $this->systemChecks(); diff --git a/setup/wizard/lib/plugins/pluginutil.inc.php b/setup/wizard/lib/plugins/pluginutil.inc.php new file mode 100644 index 0000000..698b410 --- /dev/null +++ b/setup/wizard/lib/plugins/pluginutil.inc.php @@ -0,0 +1,732 @@ +. + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * California 94120-7775, or email info@knowledgetree.com. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "Powered by + * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. + * Contributor( s): ______________________________________ + * + */ + +//require_once(KT_LIB_DIR . '/plugins/pluginentity.inc.php'); +//require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); +// +//class KTPluginResourceRegistry { +// var $aResources = array(); +// +// function &getSingleton() { +// if (!KTUtil::arrayGet($GLOBALS, 'oKTPluginResourceRegistry')) { +// $GLOBALS['oKTPluginResourceRegistry'] = new KTPluginResourceRegistry; +// } +// return $GLOBALS['oKTPluginResourceRegistry']; +// } +// +// function registerResource($sPath) { +// $this->aResources[$sPath] = true; +// } +// +// function isRegistered($sPath) { +// if (KTUtil::arrayGet($this->aResources, $sPath)) { +// return true; +// } +// $sPath = dirname($sPath); +// if (KTUtil::arrayGet($this->aResources, $sPath)) { +// return true; +// } +// return false; +// } +//} + +class KTPluginUtil { +// const CACHE_FILENAME = 'kt_plugins.cache'; +// +// /** +// * Store the plugin cache in the cache directory. +// * @deprecated +// */ +// static function savePluginCache($array) +// { +// $config = KTConfig::getSingleton(); +// $cachePlugins = $config->get('cache/cachePlugins', false); +// if (!$cachePlugins) +// { +// return false; +// } +// +// $cacheDir = $config->get('cache/cacheDirectory'); +// +// $written = file_put_contents($cacheDir . '/' . KTPluginUtil::CACHE_FILENAME , serialize($array)); +// +// if (!$written) +// { +// global $default; +// +// $default->log->warn('savePluginCache - The cache did not write anything.'); +// +// // try unlink a zero size file - just in case +// @unlink($cacheFile); +// } +// } + +// /** +// * Remove the plugin cache. +// * @deprecated +// */ +// static function removePluginCache() +// { +// $config = KTConfig::getSingleton(); +// $cachePlugins = $config->get('cache/cachePlugins', false); +// if (!$cachePlugins) +// { +// return false; +// } +// $cacheDir = $config->get('cache/cacheDirectory'); +// +// $cacheFile=$cacheDir . '/' . KTPluginUtil::CACHE_FILENAME; +// @unlink($cacheFile); +// } + +// /** +// * Reads the plugin cache file. This must still be unserialised. +// * @deprecated +// * @return mixed Returns false on failure, or the serialised cache. +// */ +// static function readPluginCache() +// { +// $config = KTConfig::getSingleton(); +// $cachePlugins = $config->get('cache/cachePlugins', false); +// if (!$cachePlugins) +// { +// return false; +// } +// $cacheDir = $config->get('cache/cacheDirectory'); +// +// $cacheFile=$cacheDir . '/' . KTPluginUtil::CACHE_FILENAME; +// if (!is_file($cacheFile)) +// { +// return false; +// } +// +// $cache = file_get_contents($cacheFile); +// +// // we check for an empty cache in case there was a problem. We rather try and reload everything otherwise. +// if (strlen($cache) == 0) +// { +// return false; +// } +// if (!class_exists('KTPluginEntityProxy')) { +// KTEntityUtil::_proxyCreate('KTPluginEntity', 'KTPluginEntityProxy'); +// } +// +// return unserialize($cache); +// } + +// /** +// * Load the plugins for the current page +// * +// * @param unknown_type $sType +// */ +// static function loadPlugins ($sType) { +// +// // Check the current page - can be extended. +// // Currently we only distinguish between the dashboard and everything else. +// if($sType != 'dashboard'){ +// $sType = 'general'; +// } +// +// $aPlugins = array(); +// $aPluginHelpers = array(); +// $aDisabled = array(); +// +// // Get the list of enabled plugins +// $query = "SELECT h.classname, h.pathname, h.plugin FROM plugin_helper h +// INNER JOIN plugins p ON (p.namespace = h.plugin) +// WHERE p.disabled = 0 AND h.classtype='plugin' ORDER BY p.orderby"; +// $aPluginHelpers = DBUtil::getResultArray($query); +// +// if(PEAR::isError($aPluginHelpers)){ +// global $default; +// $default->log->debug('Error in pluginutil: '.$aPluginHelpers->getMessage()); +// return false; +// } +// +// // Check that there are plugins and if not, register them +// if (empty($aPluginHelpers) || (isset($_POST['_force_plugin_truncate']))) { +// DBUtil::startTransaction(); +// KTPluginUtil::registerPlugins(); +// DBUtil::commit(); +// +// $query = "SELECT h.classname, h.pathname, h.plugin FROM plugin_helper h +// INNER JOIN plugins p ON (p.namespace = h.plugin) +// WHERE p.disabled = 0 AND h.classtype='plugin' ORDER BY p.orderby"; +// $aPluginHelpers = DBUtil::getResultArray($query); +// } +// +// // Create plugin objects +// foreach ($aPluginHelpers as $aItem){ +// $classname = $aItem['classname']; +// $path = $aItem['pathname']; +// +// if (!empty($path)) { +// $path = KT_DIR.'/'.$path; +// require_once($path); +// +// $oPlugin = new $classname($path); +// if($oPlugin->load()){ +// $aPlugins[] = $oPlugin; +// }else{ +// $aDisabled[] = "'{$aItem['plugin']}'"; +// } +// } +// } +// +// $sDisabled = implode(',', $aDisabled); +// +// // load plugin helpers into global space +// $query = 'SELECT h.* FROM plugin_helper h +// INNER JOIN plugins p ON (p.namespace = h.plugin) +// WHERE p.disabled = 0 ';//WHERE viewtype='{$sType}'"; +// if(!empty($sDisabled)){ +// $query .= " AND h.plugin NOT IN ($sDisabled) "; +// } +// $query .= ' ORDER BY p.orderby'; +// +// $aPluginList = DBUtil::getResultArray($query); +// +// KTPluginUtil::load($aPluginList); +// +// // Load the template locations - ignore disabled plugins +// // Allow for templates that don't correctly link to the plugin +// $query = "SELECT * FROM plugin_helper h +// LEFT JOIN plugins p ON (p.namespace = h.plugin) +// WHERE h.classtype='locations' AND (disabled = 0 OR disabled IS NULL) AND unavailable = 0"; +// +// $aLocations = DBUtil::getResultArray($query); +// +// if(!empty($aLocations)){ +// $oTemplating =& KTTemplating::getSingleton(); +// foreach ($aLocations as $location){ +// $aParams = explode('|', $location['object']); +// call_user_func_array(array(&$oTemplating, 'addLocation2'), $aParams); +// } +// } +// return true; +// } + + /** + * Load the plugins into the global space + * + * @param array $aPlugins + */ + function load($aPlugins) { + + require_once(KT_LIB_DIR . '/actions/actionregistry.inc.php'); + require_once(KT_LIB_DIR . '/actions/portletregistry.inc.php'); + require_once(KT_LIB_DIR . '/triggers/triggerregistry.inc.php'); + require_once(KT_LIB_DIR . '/plugins/pageregistry.inc.php'); + require_once(KT_LIB_DIR . '/authentication/authenticationproviderregistry.inc.php'); + require_once(KT_LIB_DIR . "/plugins/KTAdminNavigation.php"); + require_once(KT_LIB_DIR . "/dashboard/dashletregistry.inc.php"); + require_once(KT_LIB_DIR . "/i18n/i18nregistry.inc.php"); + require_once(KT_LIB_DIR . "/help/help.inc.php"); + require_once(KT_LIB_DIR . "/workflow/workflowutil.inc.php"); + require_once(KT_LIB_DIR . "/widgets/widgetfactory.inc.php"); + require_once(KT_LIB_DIR . "/validation/validatorfactory.inc.php"); + require_once(KT_LIB_DIR . "/browse/columnregistry.inc.php"); + require_once(KT_LIB_DIR . "/browse/criteriaregistry.php"); + require_once(KT_LIB_DIR . "/authentication/interceptorregistry.inc.php"); + + $oPRegistry =& KTPortletRegistry::getSingleton(); + $oTRegistry =& KTTriggerRegistry::getSingleton(); + $oARegistry =& KTActionRegistry::getSingleton(); + $oPageRegistry =& KTPageRegistry::getSingleton(); + $oAPRegistry =& KTAuthenticationProviderRegistry::getSingleton(); + $oAdminRegistry =& KTAdminNavigationRegistry::getSingleton(); + $oDashletRegistry =& KTDashletRegistry::getSingleton(); + $oi18nRegistry =& KTi18nRegistry::getSingleton(); + $oKTHelpRegistry =& KTHelpRegistry::getSingleton(); + $oWFTriggerRegistry =& KTWorkflowTriggerRegistry::getSingleton(); + $oColumnRegistry =& KTColumnRegistry::getSingleton(); + $oNotificationHandlerRegistry =& KTNotificationRegistry::getSingleton(); + $oTemplating =& KTTemplating::getSingleton(); + $oWidgetFactory =& KTWidgetFactory::getSingleton(); + $oValidatorFactory =& KTValidatorFactory::getSingleton(); + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton(); + $oInterceptorRegistry =& KTInterceptorRegistry::getSingleton(); + $oKTPluginRegistry =& KTPluginRegistry::getSingleton(); + + + // Loop through the loaded plugins and register them for access + foreach ($aPlugins as $plugin){ + $sName = $plugin['namespace']; + $sParams = $plugin['object']; + $aParams = explode('|', $sParams); + $sClassType = $plugin['classtype']; + + switch ($sClassType) { + case 'portlet': + $aLocation = unserialize($aParams[0]); + if($aLocation != false){ + $aParams[0] = $aLocation; + } + if(isset($aParams[3])){ + $aParams[3] = KTPluginUtil::getFullPath($aParams[3]); + } + call_user_func_array(array(&$oPRegistry, 'registerPortlet'), $aParams); + break; + + case 'trigger': + if(isset($aParams[4])){ + $aParams[4] = KTPluginUtil::getFullPath($aParams[4]); + } + call_user_func_array(array(&$oTRegistry, 'registerTrigger'), $aParams); + break; + + case 'action': + if(isset($aParams[3])){ + $aParams[3] = KTPluginUtil::getFullPath($aParams[3]); + } + call_user_func_array(array(&$oARegistry, 'registerAction'), $aParams); + break; + + case 'page': + if(isset($aParams[2])){ + $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); + } + call_user_func_array(array(&$oPageRegistry, 'registerPage'), $aParams); + break; + + case 'authentication_provider': + if(isset($aParams[3])){ + $aParams[3] = KTPluginUtil::getFullPath($aParams[3]); + } + $aParams[0] = _kt($aParams[0]); + call_user_func_array(array(&$oAPRegistry, 'registerAuthenticationProvider'), $aParams); + break; + + case 'admin_category': + $aParams[1] = _kt($aParams[1]); + $aParams[2] = _kt($aParams[2]); + call_user_func_array(array(&$oAdminRegistry, 'registerCategory'), $aParams); + break; + + case 'admin_page': + if(isset($aParams[5])){ + $aParams[5] = KTPluginUtil::getFullPath($aParams[5]); + } + $aParams[3] = _kt($aParams[3]); + $aParams[4] = _kt($aParams[4]); + call_user_func_array(array(&$oAdminRegistry, 'registerLocation'), $aParams); + break; + + case 'dashlet': + if(isset($aParams[2])){ + $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); + } + call_user_func_array(array(&$oDashletRegistry, 'registerDashlet'), $aParams); + break; + + case 'i18nlang': + if(isset($aParams[2]) && $aParams[2] != 'default'){ + $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); + } + call_user_func_array(array(&$oi18nRegistry, 'registeri18nLang'), $aParams); + + + case 'i18n': + if(isset($aParams[2])){ + $aParams[1] = $aParams[2]; + unset($aParams[2]); + } else { + $aParams[1] = KTPluginUtil::getFullPath($aParams[1]); + } + call_user_func_array(array(&$oi18nRegistry, 'registeri18n'), $aParams); + break; + + case 'language': + call_user_func_array(array(&$oi18nRegistry, 'registerLanguage'), $aParams); + break; + + case 'help_language': + if(isset($aParams[2])){ + $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); + } + call_user_func_array(array(&$oKTHelpRegistry, 'registerHelp'), $aParams); + break; + + case 'workflow_trigger': + if(isset($aParams[2])){ + $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); + } + call_user_func_array(array(&$oWFTriggerRegistry, 'registerWorkflowTrigger'), $aParams); + break; + + case 'column': + if(isset($aParams[3])){ + $aParams[3] = KTPluginUtil::getFullPath($aParams[3]); + } + $aParams[0] = _kt($aParams[0]); + call_user_func_array(array(&$oColumnRegistry, 'registerColumn'), $aParams); + break; + + case 'view': + $aParams[0] = _kt($aParams[0]); + call_user_func_array(array(&$oColumnRegistry, 'registerView'), $aParams); + break; + + case 'notification_handler': + if(isset($aParams[2])){ + $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); + } + call_user_func_array(array(&$oNotificationHandlerRegistry, 'registerNotificationHandler'), $aParams); + break; + + case 'template_location': + if(isset($aParams[1])){ + $aParams[1] = KTPluginUtil::getFullPath($aParams[1]); + } + call_user_func_array(array(&$oTemplating, 'addLocation2'), $aParams); + break; + + case 'criterion': + $aInit = unserialize($aParams[3]); + if($aInit != false){ + $aParams[3] = $aInit; + } + if(isset($aParams[2])){ + $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); + } + call_user_func_array(array(&$oCriteriaRegistry, 'registerCriterion'), $aParams); + break; + + case 'widget': + if(isset($aParams[2])){ + $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); + } + call_user_func_array(array(&$oWidgetFactory, 'registerWidget'), $aParams); + break; + + case 'validator': + if(isset($aParams[2])){ + $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); + } + call_user_func_array(array(&$oValidatorFactory, 'registerValidator'), $aParams); + break; + + case 'interceptor': + if(isset($aParams[2])){ + $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); + } + call_user_func_array(array(&$oInterceptorRegistry, 'registerInterceptor'), $aParams); + break; + + case 'plugin': + if(isset($aParams[2])){ + $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); + } + $oKTPluginRegistry->_aPluginDetails[$sName] = $aParams; + break; + } + } + } + + /** + * Get the absolute path + */ + function getFullPath($sPath = '') { + if(empty($sPath)){ + return ''; + } + $sPath = (KTUtil::isAbsolutePath($sPath)) ? $sPath : KT_DIR . '/' . $sPath; + return $sPath; + } + + /** + * This loads the plugins in the plugins folder. It searches for files ending with 'Plugin.php'. + * This is called by the 'Re-read plugins' action in the web interface. + */ + function registerPlugins () { + global $default; + + // Path to lock file + $cacheDir = $default->cacheDirectory . DIRECTORY_SEPARATOR; + $lockFile = $cacheDir.'plugin_register.lock'; + + // Check if the lock file exists + if(KTPluginUtil::doCheck($lockFile)){ + return true; + } + + // Create the lock file, run through the plugin registration and then delete the lock file + touch($lockFile); + KTPluginUtil::doPluginRegistration(); + @unlink($lockFile); + } + + /** + * Check the lockfile + */ + function doCheck($lockFile) + { + if(file_exists($lockFile)){ + // If it does exist, do a stat on it to check when it was created. + // if it was accessed more than 5 minutes ago then delete it and proceed with the plugin registration + // otherwise wait till lock file is deleted signalling that the registration is complete and return. + + $stat = stat($lockFile); + + $time = time() - (60 * 5); + if($stat['mtime'] > $time){ + + $cnt = 0; + + while(file_exists($lockFile)){ + $cnt++; + sleep(2); + + // if we've been waiting too long - typically it should only take a few seconds so 2 mins is too much time. + if($cnt > 60){ + @unlink($lockFile); + return false; + } + } + return true; + } + @unlink($lockFile); + } + return false; + } + + /* Get the priority of the plugin */ + function getPluginPriority($sFile) { + $defaultPriority = 10; + $priority = array( + "ktcore" => 1, + "ktstandard" => 2, + "i18n" => 3 + ); + foreach($priority as $pattern => $priority) { + if(ereg($pattern, $sFile)) { + return $priority; + } + } + return $defaultPriority; + } + + /** + * Read the plugins directory and register all plugins in the database. + */ + function doPluginRegistration() + { + global $default; + + KTPluginUtil::_deleteSmartyFiles(); + require_once(KT_LIB_DIR . '/cache/cache.inc.php'); + $oCache =& KTCache::getSingleton(); + $oCache->deleteAllCaches(); + + // Remove all entries from the plugin_helper table and refresh it. + $query = "DELETE FROM plugin_helper"; + $res = DBUtil::runQuery($query); + + $files = array(); + $plugins = array(); + + KTPluginUtil::_walk(KT_DIR . '/plugins', $files); + foreach ($files as $sFile) { + $plugin_ending = "Plugin.php"; + if (substr($sFile, -strlen($plugin_ending)) === $plugin_ending) { + /* Set default priority */ + $plugins[$sFile] = KTPluginUtil::getPluginPriority($sFile); + } + } + + /* Sort the plugins by priority */ + asort($plugins); + + /* + Add a check to indicate that plugin registration is occuring. + This check has been put in place to prevent the plugin being registered on every page load. + */ + $_SESSION['plugins_registerplugins'] = true; + foreach($plugins as $sFile => $priority) { + require_once($sFile); + } + $_SESSION['plugins_registerplugins'] = false; + + $oRegistry =& KTPluginRegistry::getSingleton(); + $aRegistryList = $oRegistry->getPlugins(); + foreach ($aRegistryList as $oPlugin) { + $res = $oPlugin->register(); + if (PEAR::isError($res)) { + //var_dump($res); + $default->log->debug('Register of plugin failed: ' . $res->getMessage()); + } + } + + $aPluginList = KTPluginEntity::getList(); + foreach ($aPluginList as $oPluginEntity) { + $sPath = $oPluginEntity->getPath(); + if (!KTUtil::isAbsolutePath($sPath)) { + $sPath = sprintf("%s/%s", KT_DIR, $sPath); + } + if (!file_exists($sPath)) { + $oPluginEntity->setUnavailable(true); + $oPluginEntity->setDisabled(true); + $res = $oPluginEntity->update(); + } + } + KTPluginEntity::clearAllCaches(); + + KTPluginUtil::_deleteSmartyFiles(); + require_once(KT_LIB_DIR . '/cache/cache.inc.php'); + $oCache =& KTCache::getSingleton(); + $oCache->deleteAllCaches(); + + //KTPluginUtil::removePluginCache(); + } + + function _deleteSmartyFiles() { + $oConfig =& KTConfig::getSingleton(); + $dir = sprintf('%s/%s', $oConfig->get('urls/varDirectory'), 'tmp'); + + $dh = @opendir($dir); + if (empty($dh)) { + return; + } + $aFiles = array(); + while (false !== ($sFilename = readdir($dh))) { + if (substr($sFilename, -10) == "smarty.inc") { + $aFiles[] = sprintf('%s/%s', $dir, $sFilename); + } + if (substr($sFilename, -10) == "smarty.php") { + $aFiles[] = sprintf('%s/%s', $dir, $sFilename); + } + } + foreach ($aFiles as $sFile) { + @unlink($sFile); + } + } + + function _walk ($path, &$files) { + if (!is_dir($path)) { + return; + } + $dirh = opendir($path); + while (($entry = readdir($dirh)) !== false) { + if (in_array($entry, array('.', '..'))) { + continue; + } + $newpath = $path . '/' . $entry; + if (is_dir($newpath)) { + KTPluginUtil::_walk($newpath, $files); + } + if (!is_file($newpath)) { + continue; + } + $files[] = $newpath; + } + } + + function resourceIsRegistered($path) { + $oRegistry =& KTPluginResourceRegistry::getSingleton(); + return $oRegistry->isRegistered($path); + } + + function registerResource($path) { + $oRegistry =& KTPluginResourceRegistry::getSingleton(); + $oRegistry->registerResource($path); + } + + function readResource($sPath) { + global $default; + $php_file = ".php"; + if (substr($sPath, -strlen($php_file)) === $php_file) { + require_once($php_file); + } else { + $pi = pathinfo($sPath); + $mime_type = ""; + $sExtension = KTUtil::arrayGet($pi, 'extension'); + if (!empty($sExtension)) { + $mime_type = DBUtil::getOneResultKey(array("SELECT mimetypes FROM " . $default->mimetypes_table . " WHERE LOWER(filetypes) = ?", $sExtension), "mimetypes"); + } + if (empty($mime_type)) { + $mime_type = "application/octet-stream"; + } + $sFullPath = KT_DIR . '/plugins' . $sPath; + header("Content-Type: $mime_type"); + header("Content-Length: " . filesize($sFullPath)); + readfile($sFullPath); + } + } + + /** + * Get the full path to the plugin + * + * @param string $sNamespace The namespace of the plugin + * @param bool $relative Whether the path should be relative or full + * @return string + */ + static function getPluginPath($sNamespace, $relative = false) + { + $oEntity = KTPluginEntity::getByNamespace($sNamespace); + + if(PEAR::isError($oEntity)){ + return $oEntity; + } + $dir = dirname($oEntity->getPath()) . '/'; + + if(!$relative){ + $dir = KT_DIR . '/' . $dir; + } + + return $dir; + } + + // utility function to detect if the plugin is loaded and active. + static function pluginIsActive($sNamespace) { + + $oReg =& KTPluginRegistry::getSingleton(); + $plugin = $oReg->getPlugin($sNamespace); + + if (is_null($plugin) || PEAR::isError($plugin)) { return false; } // no such plugin + else { // check if its active + $ent = KTPluginEntity::getByNamespace($sNamespace); + + if (PEAR::isError($ent)) { return false; } + + // we now can ask + return (!$ent->getDisabled()); + } + } +} + +?> diff --git a/setup/wizard/lib/services/unixLucene.php b/setup/wizard/lib/services/unixLucene.php index a14062c..b751115 100644 --- a/setup/wizard/lib/services/unixLucene.php +++ b/setup/wizard/lib/services/unixLucene.php @@ -50,6 +50,7 @@ class unixLucene extends unixService { private $javaXms; private $javaXmx; public $name = "KTLucene"; + public $hrname = "KnowledgeTree Indexer Service"; /** * Load defaults needed by service @@ -223,6 +224,10 @@ class unixLucene extends unixService { return $this->name; } + public function getHRName() { + return $this->hrname; + } + public function getStopMsg($installDir) { return "";//"Execute from terminal : $installDir/dmsctl.sh stop"; } diff --git a/setup/wizard/lib/services/unixOpenOffice.php b/setup/wizard/lib/services/unixOpenOffice.php index aae0af7..cf4cd9a 100644 --- a/setup/wizard/lib/services/unixOpenOffice.php +++ b/setup/wizard/lib/services/unixOpenOffice.php @@ -54,6 +54,7 @@ class unixOpenOffice extends unixService { // office executable private $soffice; public $name = "KTOpenOffice"; + public $hrname = "KnowledgeTree OpenOffice.org Service"; /** * Load defaults needed by service @@ -173,6 +174,10 @@ class unixOpenOffice extends unixService { return $this->name; } + public function getHRName() { + return $this->hrname; + } + public function getStopMsg($installDir) { return "";//"Execute from terminal : $installDir/dmsctl.sh stop"; } diff --git a/setup/wizard/lib/services/unixScheduler.php b/setup/wizard/lib/services/unixScheduler.php index 73e10fe..a1235eb 100644 --- a/setup/wizard/lib/services/unixScheduler.php +++ b/setup/wizard/lib/services/unixScheduler.php @@ -48,6 +48,7 @@ class unixScheduler extends unixService { private $scheduler; private $phpCli; public $name = "KTScheduler"; + public $hrname = "KnowledgeTree Scheduler Service"; /** * Load defaults needed by service @@ -178,7 +179,7 @@ class unixScheduler extends unixService { function start() { // TODO : Write sh on the fly? Not sure the reasoning here $source = $this->getSchedulerSourceLoc(); - $this->writeSchedulerTask(); +// $this->writeSchedulerTask(); $logFile = "/dev/null"; // @unlink($logFile); if($source) { // Source @@ -201,6 +202,10 @@ class unixScheduler extends unixService { return $this->name; } + public function getHRName() { + return $this->hrname; + } + public function getStopMsg($installDir) { return "Service Running";//"Execute from terminal : $installDir/dmsctl.sh stop"; } diff --git a/setup/wizard/lib/services/windowsLucene.php b/setup/wizard/lib/services/windowsLucene.php index 173d007..a370651 100644 --- a/setup/wizard/lib/services/windowsLucene.php +++ b/setup/wizard/lib/services/windowsLucene.php @@ -132,6 +132,10 @@ class windowsLucene extends windowsService { */ public $name = "KTLucene"; + public $hrname = "KnowledgeTree Indexer Service. (KTLucene)"; + + public $description = "KnowledgeTree Indexer Service."; + /** * Load defaults needed by service * @@ -417,23 +421,15 @@ class windowsLucene extends windowsService { */ public function install() { $state = $this->status(); -// if($state == '') { $luceneExe = $this->getLuceneExe(); $luceneSource = $this->getLuceneSource(); $luceneDir = $this->getluceneDir(); -// if($luceneExe && $luceneSource && $luceneDir) { - $cmd = "\"{$luceneExe}\""." -install \"".$this->getName()."\" \"".$this->getJavaJVM(). "\" -Djava.class.path=\"".$luceneSource."\"". " -start ".$this->getLuceneServer(). " -out \"".$this->getLuceneOut()."\" -err \"".$this->getLuceneError()."\" -current \"".$luceneDir."\" -auto"; - if(DEBUG) { - echo "$cmd
"; - return false; - } - $this->writeLuceneInstall($cmd); - //$response = $this->util->pexec($cmd); -// return $response; -// } - return $state; -// } - + $cmd = "\"{$luceneExe}\""." -install \"".$this->getName()."\" \"".$this->getJavaJVM(). "\" -Djava.class.path=\"".$luceneSource."\"". " -start ".$this->getLuceneServer(). " -out \"".$this->getLuceneOut()."\" -err \"".$this->getLuceneError()."\" -current \"".$luceneDir."\" -auto"; + if(DEBUG) { + echo "$cmd
"; + return false; + } + $this->writeLuceneInstall($cmd); return $state; } @@ -468,6 +464,10 @@ class windowsLucene extends windowsService { return ''; } + public function getHRName() { + return $this->hrname; + } + public function getStopMsg($installDir) { return "";//"Execute from command prompt : $installDir/dmsctl.bat stop"; } diff --git a/setup/wizard/lib/services/windowsOpenOffice.php b/setup/wizard/lib/services/windowsOpenOffice.php index d9591ff..8ac99ac 100644 --- a/setup/wizard/lib/services/windowsOpenOffice.php +++ b/setup/wizard/lib/services/windowsOpenOffice.php @@ -130,8 +130,12 @@ class windowsOpenOffice extends windowsService { * @param none * @return string */ - public $name = "KTOpenOffice"; + public $name = "KTOpenoffice"; + public $hrname = "KnowledgeTree OpenOffice.org Service. (KTOpenOffice)"; + + public $description = "KnowledgeTree OpenOffice.org Service."; + /** * Load defaults needed by service * @@ -210,7 +214,7 @@ class windowsOpenOffice extends windowsService { if($status == '') { $binary = $this->getBin(); if($binary != '') { - $cmd = "\"{$this->winservice}\" install $this->name "."-displayname {$this->name} -start auto \"".$binary."\" -headless -invisible -nofirststartwizard -\"accept=socket,host={$this->host},port={$this->port};urp;\"";; + $cmd = "\"{$this->winservice}\" install \"{$this->name}\" -description \"{$this->description}\" -displayname \"{$this->name}\" -start auto \"".$binary."\" -headless -invisible -nofirststartwizard -\"accept=socket,host={$this->host},port={$this->port};urp;\"";; if(DEBUG) { echo "$cmd
"; return false; @@ -257,6 +261,10 @@ class windowsOpenOffice extends windowsService { return false; } + public function getHRName() { + return $this->hrname; + } + public function getStopMsg($installDir) { return "";//"Execute from command prompt : $installDir/dmsctl.bat stop"; } diff --git a/setup/wizard/lib/services/windowsScheduler.php b/setup/wizard/lib/services/windowsScheduler.php index 786be80..c4d4899 100644 --- a/setup/wizard/lib/services/windowsScheduler.php +++ b/setup/wizard/lib/services/windowsScheduler.php @@ -77,6 +77,10 @@ class windowsScheduler extends windowsService { */ public $name = "KTScheduler"; + public $hrname = "KnowledgeTree Scheduler Service. (KTScheduler)"; + + public $description = "KnowledgeTree Scheduler Service."; + /** * Load defaults needed by service * @@ -178,7 +182,7 @@ class windowsScheduler extends windowsService { } private function setOptions() { - $this->options = "-displayname {$this->name} -start auto -binary \"{$this->getSchedulerScriptPath()}\" -headless -invisible "; + $this->options = "-displayname \"{$this->name}\" -description \"{$this->description}\" -start auto -binary \"{$this->getSchedulerScriptPath()}\" -headless -invisible "; } private function writeTaskRunner() { @@ -231,36 +235,9 @@ class windowsScheduler extends windowsService { $state = $this->status(); if($state == '') { $this->writeTaskRunner(); - //if (function_exists('win32_create_service')) { // TODO what if it does not exist? check how the dmsctl.bat does this - if(DEBUG) { - echo '
';
-            		print_r(array('service' => $this->name, 'display' => $this->name, 'path' => $this->getSchedulerScriptPath()));
-    	            echo '
'; - echo '
';
-    	            print_r(file_get_contents($this->getSchedulerScriptPath()));
-    	            echo '
'; - return ; - } - /* - $response = win32_create_service(array( - 'service' => $this->name, - 'display' => $this->name, - 'path' => $this->getSchedulerScriptPath() - )); - return $response; - */ - //} else { // Attempt to use the winserv - // TODO: Add service using winserv - $this->setWinservice(); - $this->setOptions(); - $cmd = "\"{$this->winservice}\" install $this->name $this->options"; - if(DEBUG) { - echo "$cmd
"; - return false; - } - //$response = $this->util->pexec($cmd); - //return $response; - //} + $this->setWinservice(); + $this->setOptions(); + $cmd = "\"{$this->winservice}\" install $this->name $this->options"; $this->writeSchedulerInstall($cmd); } return $state; @@ -278,8 +255,12 @@ class windowsScheduler extends windowsService { return false; } + public function getHRName() { + return $this->hrname; + } + public function getStopMsg($installDir) { - return "";//"Execute from command prompt : $installDir/dmsctl.bat stop"; + return ""; } } ?> \ No newline at end of file diff --git a/setup/wizard/path.php b/setup/wizard/path.php index 3e6f299..eba0223 100644 --- a/setup/wizard/path.php +++ b/setup/wizard/path.php @@ -45,6 +45,8 @@ define('AGENT', 'IE6'); } else if(preg_match("/MSIE 7\.\d/", $browser)) { define('AGENT', 'IE7'); + } else if(preg_match("/MSIE 8\.\d/", $browser)) { + define('AGENT', 'IE8'); } else { define('AGENT', 'OTHER'); } @@ -64,7 +66,6 @@ } else { define('DS', '/'); } - $wizard = realpath(dirname(__FILE__)); // Define environment root $wizard = realpath(dirname(__FILE__)); $xdir = explode(DS, $wizard); diff --git a/setup/wizard/resources/css/community.css b/setup/wizard/resources/css/community.css new file mode 100644 index 0000000..ece34f6 --- /dev/null +++ b/setup/wizard/resources/css/community.css @@ -0,0 +1,43 @@ +#step_content { + min-height: 400px; +} + +#step_content_dependencies { + min-height:270px; +} + +#step_content_configuration { + min-height:130px; +} + +#step_content_services { + min-height:230px; +} + +#step_content_registration { + min-height:100px; +} + +#step_content_registration_confirm { + min-height:300px; +} + +#step_content_install { + min-height:150px; +} + +#step_content_database { + min-height:240px; +} + +#step_content_database_confirm { + min-height:370px; +} + +#step_content_complete { + min-height:340px; +} + +.license_agreement { + height:270px; +} \ No newline at end of file diff --git a/setup/wizard/resources/css/ie7.css b/setup/wizard/resources/css/ie7.css index cbe9d70..d58c963 100644 --- a/setup/wizard/resources/css/ie7.css +++ b/setup/wizard/resources/css/ie7.css @@ -1,27 +1,3 @@ #logo { right:70%; } - -.onclick { - cursor: pointer; - color: #EC7725; - /*width: 150px;*/width:350px;padding-top:12px;position:static; -} - -.dependency_details { - padding-top:12px; - position:static; - width:650px; -} - -.dependencies { - position:static; - right:30%; - width:650px; -} - -.description_complete { - position:static; - right:35%; - width:100%; -} \ No newline at end of file diff --git a/setup/wizard/resources/css/ie8.css b/setup/wizard/resources/css/ie8.css new file mode 100644 index 0000000..947b34e --- /dev/null +++ b/setup/wizard/resources/css/ie8.css @@ -0,0 +1,3 @@ +#logo { + right:70%; +} \ No newline at end of file diff --git a/setup/wizard/resources/css/wizard.css b/setup/wizard/resources/css/wizard.css index 84adbf2..929bbc0 100644 --- a/setup/wizard/resources/css/wizard.css +++ b/setup/wizard/resources/css/wizard.css @@ -368,7 +368,7 @@ select { .onclick { cursor: pointer; color: #EC7725; - /*width: 150px;*/width:350px;top:12px;position:relative; + /*width: 150px;*//*width:350px;top:12px;position:relative;*/width:350px;padding-top:12px;position:static; } .description { @@ -563,15 +563,15 @@ td.dir_description { } .dependency_details { - top:12px; - position:relative; + /*top:12px;*/padding-top:12px; + /*position:relative;*/position:static; width:650px; } .dependencies { - position:relative; + /*position:relative;*/position:static; right:30%; - width:880px; + /*width:880px;*/width:650px; } .registration_template { @@ -583,7 +583,7 @@ td.dir_description { } .description_complete { - position:relative; + /*position:relative;*/position:static; right:35%; width:100%; } @@ -594,4 +594,28 @@ td.dir_description { .advoptions { top:0px; +} + +.description_1 { + color:#898989; + font-size:100%; + line-height:150%; + font-family:sans-serif; +} + +.twitter { + +} + +.facebook { + +} + +.connect { + float:none; + padding-bottom:0; + padding-left:560px; + padding-right:10px; + padding-top:10px; + position:static; } \ No newline at end of file diff --git a/setup/wizard/resources/graphics/facebookbutton.png b/setup/wizard/resources/graphics/facebookbutton.png new file mode 100644 index 0000000..8d98e0c --- /dev/null +++ b/setup/wizard/resources/graphics/facebookbutton.png diff --git a/setup/wizard/resources/graphics/twitterbutton.png b/setup/wizard/resources/graphics/twitterbutton.png new file mode 100644 index 0000000..06edb56 --- /dev/null +++ b/setup/wizard/resources/graphics/twitterbutton.png diff --git a/setup/wizard/steps/complete.php b/setup/wizard/steps/complete.php index bf7b214..6309b5f 100644 --- a/setup/wizard/steps/complete.php +++ b/setup/wizard/steps/complete.php @@ -61,6 +61,10 @@ class complete extends Step { function doStep() { $this->temp_variables = array("step_name"=>"complete", "silent"=>$this->silent); + $this->temp_variables['isCE'] = false; + $type = $this->util->getVersionType(); + if($type == "community") + $this->temp_variables['isCE'] = true; $this->doRun(); return 'landing'; } @@ -69,10 +73,14 @@ class complete extends Step { $this->checkFileSystem(); // check filesystem (including location of document directory and logging) $this->checkDb(); // check database $this->checkServices(); // check services - $this->checkInstallType();// Set silent mode variables - $this->storeSilent();// Set silent mode variables + $this->checkInstallType(); // Set silent mode variables + $this->storeSilent(); // Set silent mode variables } + /** + * Check all the system paths + * + */ private function checkFileSystem() { // defaults @@ -130,6 +138,10 @@ class complete extends Step { } } + /** + * Check if a database connection can be made + * + */ private function checkDb() { // defaults @@ -199,6 +211,10 @@ class complete extends Step { } } + /** + * Check if all services are deactivated + * + */ private function checkServices() { $services = new services(); @@ -217,15 +233,28 @@ class complete extends Step { return true; } + /** + * Check the install type and store + * + */ function checkInstallType() { if ($this->util->isMigration()) { $this->migrate_check = true; + $this->registerPlugins(); // Set silent mode variables } else { $this->migrate_check = false; } } /** + * Register extra commercial plugins + * + */ + private function registerPlugins() { + + } + + /** * Set all silent mode varibles * */ @@ -236,7 +265,6 @@ class complete extends Step { $this->temp_variables['database_check'] = $this->database_check; $this->temp_variables['migrate_check'] = $this->migrate_check; $this->temp_variables['servicesValidation'] = $this->servicesValidation; - //if(!$this->pathsSection) {die;} else {echo 'huh';} $this->temp_variables['pathsSection'] = $this->pathsSection; $this->temp_variables['databaseSection'] = $this->databaseSection; $this->temp_variables['privilegesSection'] = $this->privilegesSection; diff --git a/setup/wizard/steps/configuration.php b/setup/wizard/steps/configuration.php index bd64d0e..2a0ffc6 100644 --- a/setup/wizard/steps/configuration.php +++ b/setup/wizard/steps/configuration.php @@ -247,10 +247,12 @@ class configuration extends Step public function doRun($edit = false) { $server = $this->getServerInfo(); - if(!$edit) $this->temp_variables['server'] = $server; + if(!$edit || $this->util->isMigration()) + $this->temp_variables['server'] = $server; $paths = $this->getPathInfo($server['file_system_root']['value']); - if(!$edit) $this->temp_variables['paths'] = $paths; + if(!$edit || $this->util->isMigration()) + $this->temp_variables['paths'] = $paths; // Rewrite file system root if(!$this->fpath) { @@ -432,13 +434,15 @@ class configuration extends Step { if(isset($this->temp_variables['paths'])) { if ($this->util->isMigration()) { // Check if its an upgrade - $this->readInstallation(); // Read values from config.ini of other installation + $this->readConfigPath(); // Read contents of config-path file as only var Documents are used of old stack + $this->readInstallation(); // Read values from config.ini of other installation and overwrite config-path's $dirs = $this->getFromConfigPath(); // Store contents } else { $dirs = $this->temp_variables['paths']; // Pull from temp } } else { if ($this->util->isMigration()) { // Check if its an upgrade + $this->readConfigPath(); // Read contents of config-path file as only var Documents are used of old stack $this->readInstallation(); // Read values from config.ini of other installation } else { $this->readConfigPath(); // Read contents of config-path file @@ -455,13 +459,13 @@ class configuration extends Step } if(WINDOWS_OS) $path = preg_replace('/\//', '\\',$path); - $dirs[$key]['path'] = $path; - $path = $class = strtolower(substr($path,0,1)).substr($path,1); // Damn you windows - if(isset($dir['file'])) { - $class = $this->util->checkPermission($path, false, true); - } else { - $class = $this->util->checkPermission($path, $dir['create']); - } + $dirs[$key]['path'] = $path; + $path = $class = strtolower(substr($path,0,1)).substr($path,1); // Damn you windows + if(isset($dir['file'])) { + $class = $this->util->checkPermission($path, false, true); + } else { + $class = $this->util->checkPermission($path, $dir['create']); + } if(isset($class['msg'])) { if($class['class'] != 'tick') { $this->temp_variables['paths_perms'] = $class['class']; diff --git a/setup/wizard/steps/database.php b/setup/wizard/steps/database.php index aa62be1..e3b1313 100644 --- a/setup/wizard/steps/database.php +++ b/setup/wizard/steps/database.php @@ -309,11 +309,7 @@ class database extends Step $this->error['dmsuserpassword'] = "Passwords do not match: " . $this->dmsuserpassword." ". $this->getPassword2(); return false; } -// if($this->dport == '') { -// $this->util->dbUtilities->load($this->dhost, $this->duname, $this->dpassword, $this->dname); -// } else { - $this->util->dbUtilities->load($this->dhost, $this->dport, $this->duname, $this->dpassword, $this->dname); -// } + $this->util->dbUtilities->load($this->dhost, $this->dport, $this->duname, $this->dpassword, $this->dname); if (!$this->util->dbUtilities->getDatabaseLink()) { $this->error['con'] = "Could not connect to the database, please check username and password"; return false; @@ -642,12 +638,20 @@ class database extends Step $this->error['con'] = "Could not populate schema "; } $this->writeBinaries(); - // ensure a guid was generated and is stored - $this->util->getSystemIdentifier(); + $this->addServerPort(); + $this->util->getSystemIdentifier(); // ensure a guid was generated and is stored + $this->reBuildPaths(); return true; } + private function addServerPort() { + $conf = $this->util->getDataFromSession('configuration'); + $port = $conf['server']['port']['value']; + $iserverPorts = 'UPDATE config_settings SET value = "'.$port.'" where group_name = "server" and item IN("internal_server_port", "server_port");'; // Update internal server port + $this->util->dbUtilities->query($iserverPorts); + } + /** * Create database * @@ -770,16 +774,26 @@ class database extends Step $this->parse_mysql_dump($sqlFile); $dropPluginHelper = "TRUNCATE plugin_helper;"; // Remove plugin helper table $this->util->dbUtilities->query($dropPluginHelper); - $updateUrls = 'UPDATE config_settings c SET c.value = "default" where c.group_name = "urls";'; // Remove references to old paths - $this->util->dbUtilities->query($updateUrls); + $this->addServerPort(); + $this->util->dbUtilities->query($iserverPorts); $updateExternalBinaries = 'UPDATE config_settings c SET c.value = "default" where c.group_name = "externalBinary";'; // Remove references to old paths $this->util->dbUtilities->query($updateExternalBinaries); + $this->reBuildPaths(); $this->writeBinaries(); // Rebuild some of the binaries $this->util->getSystemIdentifier(); // ensure a guid was generated and is stored return true; } + private function reBuildPaths() { + $conf = $this->util->getDataFromSession('configuration'); + $paths = $conf['paths']; + foreach ($paths as $k=>$path) { + $sql = 'UPDATE config_settings SET value = "'.$path['path'].'" where item = "'.$k.'";'; + $this->util->dbUtilities->query($sql); + } + } + private function writeBinaries() { // if Windows, attempt to insert full paths to binaries if (WINDOWS_OS) { @@ -790,12 +804,47 @@ class database extends Step 'df' => array(0 => 'externalBinary', 1 => SYSTEM_ROOT . 'bin\gnuwin32\df.exe'), 'zip' => array(0 => 'export', 1 => SYSTEM_ROOT . 'bin\zip\zip.exe'), 'unzip' => array(0 => 'import', 1 => SYSTEM_ROOT . 'bin\unzip\unzip.exe')); + + if (INSTALL_TYPE == 'commercial' || true) { + $winBinaries['pdf2swf'] = array(0 => 'externalBinary', 1 => SYSTEM_ROOT . 'bin\swftools\pdf2swf.exe'); + } + foreach ($winBinaries as $displayName => $bin) { // continue without attempting to set the path if we can't find the file in the specified location if (!file_exists($bin[1])) continue; - $updateBin = 'UPDATE config_settings c SET c.value = "'. str_replace('\\', '\\\\', $bin[1]) . '" ' - . 'where c.group_name = "' . $bin[0] . '" and c.display_name = "'.$displayName.'";'; + + // escape paths for insert/update query + $bin[1] = str_replace('\\', '\\\\', $bin[1]); + + // instaView won't exist, must be inserted instead of updated + // TODO this may need to be modified to first check for existing setting as with the convert step below; not necessary for 3.7.0.x + if ($displayName == 'pdf2swf') { + $updateBin = 'INSERT INTO `config_settings` (group_name, display_name, description, item, value, default_value, type, options, can_edit) ' + . 'VALUES ("' . $bin[0] . '", "' . $displayName . '", "The path to the SWFTools \"pdf2swf\" binary", "pdf2swfPath", ' + . '"' . $bin[1] . '", "pdf2swf", "string", NULL, 1);'; + } + // on a migration, the convert setting will not exist, so do something similar to the above, but first check whether it exists + else if ($displayName == 'convert') { + // check for existing config settings entry and only add if not already present + $sql = 'SELECT id FROM `config_settings` WHERE group_name = "externalBinary" AND item = "convertPath"'; + $result = $this->util->dbUtilities->query($sql); + $output = $this->util->dbUtilities->fetchAssoc($result); + if(is_null($output)) { + $updateBin = 'INSERT INTO `config_settings` (group_name, display_name, description, item, value, default_value, type, options, can_edit) ' + . 'VALUES ("' . $bin[0] . '", "' . $displayName . '", "The path to the ImageMagick \"convert\" binary", "convertPath", ' + . '"' . $bin[1] . '", "convert", "string", NULL, 1)'; + } + else { + $updateBin = 'UPDATE config_settings c SET c.value = "'. $bin[1] . '" ' + . 'where c.group_name = "' . $bin[0] . '" and c.display_name = "'.$displayName.'";'; + } + } + else { + $updateBin = 'UPDATE config_settings c SET c.value = "'. $bin[1] . '" ' + . 'where c.group_name = "' . $bin[0] . '" and c.display_name = "'.$displayName.'";'; + } + $this->util->dbUtilities->query($updateBin); } } diff --git a/setup/wizard/steps/install.php b/setup/wizard/steps/install.php index 951e0af..0e4b78b 100644 --- a/setup/wizard/steps/install.php +++ b/setup/wizard/steps/install.php @@ -60,9 +60,11 @@ class install extends step * @var array */ protected $runInstall = true; + private $ce_check = false; public function doStep() { $this->temp_variables = array("step_name"=>"install"); + $this->checkInstallType(); // Set silent mode variables if(!$this->inStep("install")) { return 'landing'; } @@ -104,6 +106,24 @@ class install extends step $this->callHome(); } + /** + * Check the install type and store + * + */ + function checkInstallType() { + if ($this->util->isCommunity()) { + $this->ce_check = true; + $this->registerPlugins(); // Set silent mode variables + } else { + $this->ce_check = false; + } + $this->temp_variables['ce_check'] = $this->ce_check; + } + + function registerPlugins() { + + } + public function callHome() { $conf = $this->getDataFromSession("install"); // retrieve database information from session $dbconf = $this->getDataFromSession("database"); @@ -116,5 +136,7 @@ class install extends step $this->util->dbUtilities->query($query); $this->util->dbUtilities->close(); // close the database connection } + + } ?> \ No newline at end of file diff --git a/setup/wizard/steps/installtype.php b/setup/wizard/steps/installtype.php index 6932613..252845c 100644 --- a/setup/wizard/steps/installtype.php +++ b/setup/wizard/steps/installtype.php @@ -45,6 +45,10 @@ class installType extends step public function doStep() { $this->temp_variables = array("step_name"=>"installtype"); + $type = $this->util->getVersionType(); + $this->temp_variables['isCE'] = false; + if($type == "community") + $this->temp_variables['isCE'] = true; if(!$this->inStep("installtype")) { return 'landing'; } diff --git a/setup/wizard/templates/complete.tpl b/setup/wizard/templates/complete.tpl index 4f41431..1f57252 100644 --- a/setup/wizard/templates/complete.tpl +++ b/setup/wizard/templates/complete.tpl @@ -4,9 +4,7 @@

This step allows you to check that your KnowledgeTree configuration is set up correctly. - Click Finish to browse to the KnowledgeTree Web Interface. Default login credentials are username: admin and password: admin. -


+

Services

@@ -29,12 +28,31 @@

- - cd
- dmsctl.bat install
- dmsctl.bat start - - cd /usr/share/knowledgetree-ce
+ + Using shortcuts: +
+ [START MENU] => [Programs] => [KnowledgeTree 3.7.x] => [services] +
+ Click [Install Services] +
+ [START MENU] => [Programs] => [KnowledgeTree 3.7.x] => [services] +
+ Click [Start Services] +
+
+ Alternatively: +
+ Open a command prompt and enter the following: +
+ cd
+ dmsctl.bat install
+ dmsctl.bat start + + + cd /usr/share/knowledgetree-ce
+ + cd /usr/share/knowledgetree
+ sudo ./dmsctl.sh start

@@ -46,7 +64,6 @@ $iconFlag = "     "; $checkHeading = "

".$iconFlag."Paths and Permissions

"; ?> - - - - - - "; @@ -67,7 +79,6 @@ echo $pathsCheck; ?> -' . $varDirectory . ''; ?> ' . $documentRoot . ''; ?> @@ -80,10 +91,8 @@ -

-     "; @@ -96,10 +105,7 @@ $details = 'Hide Details'; $display = 'block'; }?> - - -"; @@ -129,10 +135,7 @@ $details = 'Hide Details'; $display = 'block'; }?> - - -"; @@ -148,7 +151,6 @@ -
@@ -160,46 +162,18 @@
Show Details
- - - - - - - - -
     "; ?> Lucene Service Could not be started Started - - - - - -
     "; ?> Scheduler Service Could not be started Started - - - - - -
     "; ?> OpenOffice Service Could not be started Started - - - - - -
@@ -208,14 +182,22 @@
+
- Next + + - Finish + + js('form.js'); } ?> \ No newline at end of file diff --git a/setup/wizard/templates/configuration.tpl b/setup/wizard/templates/configuration.tpl index 6f97ca1..dcbd3dc 100644 --- a/setup/wizard/templates/configuration.tpl +++ b/setup/wizard/templates/configuration.tpl @@ -61,19 +61,8 @@
 
' /> - - -
 
- - - /> -     - - /> - - - +

     "; ?>Paths and Permissions

Show Details
diff --git a/setup/wizard/templates/configuration_confirm.tpl b/setup/wizard/templates/configuration_confirm.tpl index d9f9382..3903b58 100644 --- a/setup/wizard/templates/configuration_confirm.tpl +++ b/setup/wizard/templates/configuration_confirm.tpl @@ -49,11 +49,6 @@
 
- - Do you have SSL Enabled?: -
 
- -

Paths and Permissions

diff --git a/setup/wizard/templates/database.tpl b/setup/wizard/templates/database.tpl index 5ee9985..86fc6bb 100644 --- a/setup/wizard/templates/database.tpl +++ b/setup/wizard/templates/database.tpl @@ -11,7 +11,7 @@
This step configures the connection to the database server and installs the database. The details for an administrative
- user on the database server are required in order to be able to configure and install the installation database. + user on the database server are required in order to be able to configure and install the KnowledgeTree database.
@@ -63,7 +63,7 @@ - + diff --git a/setup/wizard/templates/dependencies.tpl b/setup/wizard/templates/dependencies.tpl index 75dc8ef..d14b796 100644 --- a/setup/wizard/templates/dependencies.tpl +++ b/setup/wizard/templates/dependencies.tpl @@ -20,16 +20,13 @@      Your system is not quite ready to run KnowledgeTree. See the list below to determine which areas you need to address. -      Not all optional dependencies required by KnowledgeTree have been met but you will be able to continue. - -Click here for help on overcoming dependency issues @@ -38,10 +35,6 @@ $iconFlag = "     "; $checkHeading = "

".$iconFlag."PHP Version Check

"; ?> - -      "; - ?> "; $phpVersionCheck .= "
"; ?> - -  

"; $phpVersionCheck .= "

Your version of PHP must be between 5.0 and 5.2 to run optimally. Versions that are 5.3 or higher are not recommended.

"; ?> -      {$version['version']}"; ?>      {$version['version']}"; ?> Refresh"; ?> - Refresh"; ?> - "; ?> -
@@ -89,7 +74,6 @@ $iconFlag = "     "; $checkHeading = "

".$iconFlag."PHP Extensions

"; ?> - "; $phpExtensionCheck .= "
"; ?> - - The extensions shown in red below are required for KnowledgeTree to run optimally. Items shown in orange are optional, but recommended.

"; ?> -
 
 
@@ -164,7 +143,6 @@ $iconFlag = "     "; $checkHeading = "

".$iconFlag."PHP Configurations

"; ?> -"; $phpDirectivesCheck .= "
"; ?> - - The configurations shown in red below are required for KnowledgeTree to run optimally. Items shown in orange are optional, but recommended.

"; ?> - - -
diff --git a/setup/wizard/templates/install.tpl b/setup/wizard/templates/install.tpl index a24f755..e8ebdf9 100644 --- a/setup/wizard/templates/install.tpl +++ b/setup/wizard/templates/install.tpl @@ -1,8 +1,13 @@

Finalizing System Installation

-
+ +
+ +
+

The wizard will now complete the installation and run a final check on your system.

+

We would greatly appreciate it if you would allow us to collect anonymous usage statistics to help us provide a better quality product.
@@ -13,6 +18,21 @@

  

+ +

+ We would greatly appreciate it if you would allow us to collect anonymous usage statistics to help us provide a better quality product. +
+
+ The information includes a unique identification number, number of users you have created, your operating system type and your IP address. Your privacy is protected by the KnowledgeTree Privacy and Data Protection Agreements. +

+ +







+ +

+    + +

+
diff --git a/setup/wizard/templates/installtype.tpl b/setup/wizard/templates/installtype.tpl index e057e35..373219b 100644 --- a/setup/wizard/templates/installtype.tpl +++ b/setup/wizard/templates/installtype.tpl @@ -7,16 +7,18 @@
- + - + + - + +
diff --git a/setup/wizard/templates/license.tpl b/setup/wizard/templates/license.tpl index 0aba327..989654a 100644 --- a/setup/wizard/templates/license.tpl +++ b/setup/wizard/templates/license.tpl @@ -4,9 +4,8 @@ foreach($errors as $k=>$e) { echo "".$e.""; } - //print_r($errors); }?> -

+

Please read and accept the license agreement below before continuing with the setup.

diff --git a/setup/wizard/templates/welcome.tpl b/setup/wizard/templates/welcome.tpl index 91c842b..f35eb42 100644 --- a/setup/wizard/templates/welcome.tpl +++ b/setup/wizard/templates/welcome.tpl @@ -7,6 +7,5 @@
image('kt_browse.png'); ?>
- js('form.js'); } ?> \ No newline at end of file diff --git a/setup/wizard/templates/wizard.tpl b/setup/wizard/templates/wizard.tpl index 25b8730..6a2d8a6 100644 --- a/setup/wizard/templates/wizard.tpl +++ b/setup/wizard/templates/wizard.tpl @@ -11,6 +11,8 @@ css('wizard.css'); ?> css('ie6.css'); ?> css('ie7.css'); ?> + css('ie8.css'); ?> + css('community.css'); ?> diff --git a/sql/mysql/install/data.sql b/sql/mysql/install/data.sql index 1a7d4d3..14e795e 100755 --- a/sql/mysql/install/data.sql +++ b/sql/mysql/install/data.sql @@ -1767,14 +1767,15 @@ INSERT INTO `upgrades` VALUES (223, 'sql*3.6.2*0*3.6.2/data_types.sql', 'Add large text and date fields','2009-05-01 00:00:00',1,'upgrade*3.6.2*99*upgrade3.6.2'), (224,'upgrade*3.6.2*99*upgrade3.6.2','Upgrade from version 3.6.1 to 3.6.2','2009-05-01 00:00:00',1,'upgrade*3.6.2*99*upgrade3.6.2'), (225,'upgrade*3.6.3*99*upgrade3.6.3','Upgrade from version 3.6.2 to 3.6.3','2009-06-01 00:00:00',1,'upgrade*3.6.3*99*upgrade3.6.3'), -(226,'sql*3.7.0-1*0*3.7.0-1/plugins_admin.sql','Database upgrade to version 3.7.0-1: Plugins admin','2009-09-01 00:00:00',1,'upgrade*3.7.0-1*99*upgrade3.7.0-1'), -(227,'sql*3.7.0-1*0*3.7.0-1/config_settings.sql','Database upgrade to version 3.7.0-1: Config settings','2009-09-01 00:00:00',1,'upgrade*3.7.0-1*99*upgrade3.7.0-1'), -(228,'sql*3.7.0-1*0*3.7.0-1/plugin_helper.sql','Database upgrade to version 3.7.0-1: Plugin helper','2009-09-01 00:00:00',1,'upgrade*3.7.0-1*99*upgrade3.7.0-1'), -(229,'sql*3.7.0-1*0*3.7.0-1/call_home_task.sql','Database upgrade to version 3.7.0-1: Call home task','2009-09-01 00:00:00',1,'upgrade*3.7.0-1*99*upgrade3.7.0-1'), -(230,'sql*3.7.0-1*0*3.7.0-1/hide_zip_config.sql','Database upgrade to version 3.7.0-1: Hide zip config','2009-09-01 00:00:00',1,'upgrade*3.7.0-1*99*upgrade3.7.0-1'), -(231,'sql*3.7.0-1*0*3.7.0-1/mime_extractors_reset.sql','Database upgrade to version 3.7.0-1: Mime extractors reset','2009-09-01 00:00:00',1,'upgrade*3.7.0-1*99*upgrade3.7.0-1'), -(232,'upgrade*3.7.0-1*99*upgrade3.7.0-1','Upgrade from version 3.6.3 to 3.7.0-1','2009-11-13 00:00:00',1,'upgrade*3.7.0-1*99*upgrade3.7.0-1'), -(233,'upgrade*3.7.0.2*99*upgrade3.7.0.2','Upgrade from version 3.7.0-1 to 3.7.0.2','2009-11-19 00:00:00',1,'upgrade*3.7.0.2*99*upgrade3.7.0.2'); +(226,'sql*3.7.0.1*0*3.7.0.1/plugins_admin.sql','Database upgrade to version 3.7.0.1: Plugins admin','2009-09-01 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'), +(227,'sql*3.7.0.1*0*3.7.0.1/config_settings.sql','Database upgrade to version 3.7.0.1: Config settings','2009-09-01 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'), +(228,'sql*3.7.0.1*0*3.7.0.1/plugin_helper.sql','Database upgrade to version 3.7.0.1: Plugin helper','2009-09-01 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'), +(229,'sql*3.7.0.1*0*3.7.0.1/call_home_task.sql','Database upgrade to version 3.7.0.1: Call home task','2009-09-01 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'), +(230,'sql*3.7.0.1*0*3.7.0.1/hide_zip_config.sql','Database upgrade to version 3.7.0.1: Hide zip config','2009-09-01 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'), +(231,'sql*3.7.0.1*0*3.7.0.1/mime_extractors_reset.sql','Database upgrade to version 3.7.0.1: Mime extractors reset','2009-09-01 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'), +(232,'upgrade*3.7.0.1*99*upgrade3.7.0.1','Upgrade from version 3.6.3 to 3.7.0.1','2009-11-13 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'), +(233,'sql*3.7.0.2*0*3.7.0.2/processor_queue.sql','Database upgrade to version 3.7.0.1: Processor Queue','2009-09-01 00:00:00',1,'upgrade*3.7.0.2*99*upgrade3.7.0.2'), +(234,'upgrade*3.7.0.2*99*upgrade3.7.0.2','Upgrade from version 3.7.0.1 to 3.7.0.2','2009-11-19 00:00:00',1,'upgrade*3.7.0.2*99*upgrade3.7.0.2'); /*!40000 ALTER TABLE `upgrades` ENABLE KEYS */; UNLOCK TABLES; diff --git a/sql/mysql/install/structure.sql b/sql/mysql/install/structure.sql index e86d9a6..e4a604d 100644 --- a/sql/mysql/install/structure.sql +++ b/sql/mysql/install/structure.sql @@ -4,7 +4,7 @@ -- KnowledgeTree Community Edition -- Document Management Made Simple -- Copyright (C) 2008, 2009 KnowledgeTree Inc. --- +-- -- -- This program is free software; you can redistribute it and/or modify it under -- the terms of the GNU General Public License version 3 as published by the @@ -1327,6 +1327,20 @@ CREATE TABLE `plugins` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- +-- Table structure for table `process_queue` +-- + +CREATE table `process_queue` ( + `document_id` int(11) NOT NULL, + `date_added` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, + `date_processed` timestamp, + `status_msg` mediumtext, + `process_type` varchar(20), + PRIMARY KEY (`document_id`), + CONSTRAINT `process_queue_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- -- Table structure for table `role_allocations` -- diff --git a/sql/mysql/upgrade/3.7.0-1/call_home_task.sql b/sql/mysql/upgrade/3.7.0.1/call_home_task.sql index 0ba0234..0ba0234 100644 --- a/sql/mysql/upgrade/3.7.0-1/call_home_task.sql +++ b/sql/mysql/upgrade/3.7.0.1/call_home_task.sql diff --git a/sql/mysql/upgrade/3.7.0-1/config_settings.sql b/sql/mysql/upgrade/3.7.0.1/config_settings.sql index 0bba239..2f92edb 100644 --- a/sql/mysql/upgrade/3.7.0-1/config_settings.sql +++ b/sql/mysql/upgrade/3.7.0.1/config_settings.sql @@ -1,5 +1,2 @@ INSERT INTO `config_settings` (group_name, display_name, description, item, value, default_value, type, options, can_edit) -VALUES ('urls', 'Internal Var Directory', 'The path to the internal var directory that must sit within the web root', 'internalVarDirectory', 'default', '${fileSystemRoot}/var', 'string', NULL, 0); - -INSERT INTO `config_settings` (group_name, display_name, description, item, value, default_value, type, options, can_edit) -VALUES ('externalBinary', 'convert', 'The path to the ImageMagick "convert" binary', 'convertPath', 'default', 'convert', 'string', NULL, 1); \ No newline at end of file +VALUES ('urls', 'Internal Var Directory', 'The path to the internal var directory that must sit within the web root', 'internalVarDirectory', 'default', '${fileSystemRoot}/var', 'string', NULL, 0); \ No newline at end of file diff --git a/sql/mysql/upgrade/3.7.0-1/hide_zip_config.sql b/sql/mysql/upgrade/3.7.0.1/hide_zip_config.sql index 27abae2..27abae2 100644 --- a/sql/mysql/upgrade/3.7.0-1/hide_zip_config.sql +++ b/sql/mysql/upgrade/3.7.0.1/hide_zip_config.sql diff --git a/sql/mysql/upgrade/3.7.0-1/mime_extractors_reset.sql b/sql/mysql/upgrade/3.7.0.1/mime_extractors_reset.sql index 9e81e6d..9e81e6d 100644 --- a/sql/mysql/upgrade/3.7.0-1/mime_extractors_reset.sql +++ b/sql/mysql/upgrade/3.7.0.1/mime_extractors_reset.sql diff --git a/sql/mysql/upgrade/3.7.0-1/plugin_helper.sql b/sql/mysql/upgrade/3.7.0.1/plugin_helper.sql index 469e624..469e624 100644 --- a/sql/mysql/upgrade/3.7.0-1/plugin_helper.sql +++ b/sql/mysql/upgrade/3.7.0.1/plugin_helper.sql diff --git a/sql/mysql/upgrade/3.7.0-1/plugins_admin.sql b/sql/mysql/upgrade/3.7.0.1/plugins_admin.sql index 7782f08..7782f08 100644 --- a/sql/mysql/upgrade/3.7.0-1/plugins_admin.sql +++ b/sql/mysql/upgrade/3.7.0.1/plugins_admin.sql diff --git a/sql/mysql/upgrade/3.7.0.2/processor_queue.sql b/sql/mysql/upgrade/3.7.0.2/processor_queue.sql new file mode 100644 index 0000000..81250da --- /dev/null +++ b/sql/mysql/upgrade/3.7.0.2/processor_queue.sql @@ -0,0 +1,13 @@ +-- +-- Table structure for table `process_queue` +-- + +CREATE table `process_queue` ( + `document_id` int(11) NOT NULL, + `date_added` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, + `date_processed` timestamp, + `status_msg` mediumtext, + `process_type` varchar(20), + PRIMARY KEY (`document_id`), + CONSTRAINT `process_queue_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/templates/ktcore/principals/about.smarty b/templates/ktcore/principals/about.smarty index 0426788..56e1ca9 100644 --- a/templates/ktcore/principals/about.smarty +++ b/templates/ktcore/principals/about.smarty @@ -5,8 +5,6 @@ {if ($smallVersion !== 'Community Edition')} {i18n}All rights reserved.{/i18n}
{/if} - -{i18n}.{/i18n}
{if ($smallVersion == 'Community Edition')} {i18n}This program is free software and published under the GNU General Public License version 3{/i18n}

@@ -31,143 +29,55 @@
  • Blogs: See what the KnowledgeTree team have to say
  • +

    Thanks to the following contributors for helping us with code contributions and testing...

    -
      -
    • - Fu Bin -
    • -
    • - Blackhold -
    • -
    • - Chris Buechler -
    • -
    • - Guillaume Dufloux -
    • -
    • - David Alfonso Faspar -
    • -
    • - Ruud Feringa -
    • -
    • - Hilário Fernandes -
    • -
    • - William Hawkins -
    • -
    • - Lody Hoekstra -
    • -
    • - Kenny Horan -
    • -
    • - Artur Kiwa -
    • -
    • - Michael Knight -
    • -
    • - Jeongkyu Kim -
    • -
    • - Rogerio Kohler -
    • -
    • - Piotr Krawiecki -
    • -
    • - Ola Larsson -
    • -
    • - Pavel Lastovicka -
    • -
    • - Michel Loiseleur -
    • -
    • - Renat Lumpau -
    • -
    • - Marco Lusini -
    • -
    • - Michael Malone -
    • -
    • - Jochem Meijers -
    • -
    • - John Miles -
    • -
    • - Ismail Mogal -
    • -
    • - David Nalley -
    • -
    • - Marco Napetti -
    • -
    • - Manuela Patrono -
    • -
    • - Antti Poro -
    • -
    • - Nicolas Quienot -
    • -
    • - Ken Rainsforth -
    • -
    • - Antonio Rizzelli -
    • -
    • - Greg Rundlett -
    • -
    • - Leonardo Russo -
    • -
    • - Ricardo Silva -
    • -
    • - Mario Steinhoff -
    • -
    • - Phillip Steinbachs -
    • -
    • - Tahir Tahang -
    • -
    • - Paul Trgina -
    • -
    • - Harry Tsio -
    • -
    • - Bjarte Kalstveit Vebjørnsen -
    • -
    • - Zakariah -
    • -
    • - Jaime Zarate -
    • -
    • - And all the KnowledgeTree staff that "dogfood" KnowledgeTree every day. -
    • - -
    + Fu Bin, + Blackhold, + Chris Buechler, + Guillaume Dufloux, + David Alfonso Faspar, + Ruud Feringa, + Hilário Fernandes, + William Hawkins, + Lody Hoekstra, + Kenny Horan, + Artur Kiwa, + Michael Knight, + Jeongkyu Kim, + Rogerio Kohler, + Piotr Krawiecki , + Ola Larsson, + Pavel Lastovicka, + Michel Loiseleur , + Renat Lumpau, + Marco Lusini, + Michael Malone, + Jochem Meijers, + John Miles, + Ismail Mogal, + David Nalley, + Marco Napetti, + Manuela Patrono, + Antti Poro, + Nicolas Quienot, + Ken Rainsforth, + Antonio Rizzelli, + Greg Rundlett, + Leonardo Russo, + Ricardo Silva, + Mario Steinhoff, + Phillip Steinbachs, + Tahir Tahang, + Paul Trgina, + Harry Tsio, + Bjarte Kalstveit Vebjørnsen, + Zakariah, + Jaime Zarate,

    + And the KnowledgeTree team who "dogfood" KnowledgeTree every day.

    [If you feel you should be here too, please let us know at contributions@knowledgetree.com]

    - +

    This software utilizes third-party software from Pear, PHPMailer, Smarty Template Engine, JSCalendar, Mochikit, Moxiecode Systems, Yahoo Developer Network.

    diff --git a/templates/ktcore/search2/reporting/indexerrors.smarty b/templates/ktcore/search2/reporting/indexerrors.smarty index 5cd2280..f479102 100644 --- a/templates/ktcore/search2/reporting/indexerrors.smarty +++ b/templates/ktcore/search2/reporting/indexerrors.smarty @@ -40,7 +40,7 @@ {foreach key=key from=$indexErrors item=indexError} - {$indexError.filename|truncate:40:'...'} + {$indexError.filename|truncate:40:'...'} {if $indexError.extractor}{$indexError.extractor}{else}

    {i18n}n/a{/i18n}

    {/if} {$indexError.indexdate} @@ -57,18 +57,31 @@ -
    -{foreach item=page from=$pageList} -{$page} -{/foreach} -
    - - - - -
    {$itemCount} items, {$itemsPerPage} items per page.
    +
    + {foreach item=page from=$pageList} + {if $pageNum == $page} + {$page}  + {else} + {$page}  + {/if} + {/foreach} +
    + + +
    {$itemCount} {i18n}items{/i18n}, {$itemsPerPage} {i18n}items per page{/i18n}.
    + + + + {i18n}items per page{/i18n} + + diff --git a/templates/ktcore/search2/reporting/pendingdocuments.smarty b/templates/ktcore/search2/reporting/pendingdocuments.smarty index 3cc8a52..ae6b6f3 100644 --- a/templates/ktcore/search2/reporting/pendingdocuments.smarty +++ b/templates/ktcore/search2/reporting/pendingdocuments.smarty @@ -1,6 +1,16 @@ +{literal} + +{/literal}

    {i18n}Pending Documents Indexing Queue{/i18n}

    -{i18n}This report lists documents that are waiting to be indexed.{/i18n} -

    +

    {i18n}This report lists documents that are waiting to be indexed.{/i18n}

    +
    {i18n}If a document is not associated with an extractor, no content will be added to the index. These documents can be identified in the list by the extractor column reflecting n/a.{/i18n}

    @@ -11,6 +21,9 @@ {else} +
    + + @@ -33,6 +46,40 @@ + + + + + + + + + +
    +
    + {foreach item=page from=$pageList} + {if $pageNum == $page} + {$page}  + {else} + {$page}  + {/if} + {/foreach} +
    +
    +
    {$itemCount} {i18n}items{/i18n}, + {$itemsPerPage} {i18n}items per page{/i18n}. +
    +
    + + {i18n}items per page{/i18n} +
    +
    + {/if} diff --git a/thirdparty/peclzip/pclzip.lib.php b/thirdparty/peclzip/pclzip.lib.php old mode 100755 new mode 100644 index d387f00..e7facc1 --- a/thirdparty/peclzip/pclzip.lib.php +++ b/thirdparty/peclzip/pclzip.lib.php @@ -1,8 +1,8 @@ magic_quotes_status = -1; // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1); return; } // -------------------------------------------------------------------------------- @@ -244,7 +270,6 @@ // -------------------------------------------------------------------------------- function create($p_filelist) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ..."); $v_result=1; // ----- Reset the error handler @@ -256,7 +281,6 @@ // ----- Look for variable options arguments $v_size = func_num_args(); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); // ----- Look for arguments if ($v_size > 1) { @@ -269,7 +293,6 @@ // ----- Look for first arg if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); // ----- Parse the options $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, @@ -279,11 +302,13 @@ PCLZIP_CB_PRE_ADD => 'optional', PCLZIP_CB_POST_ADD => 'optional', PCLZIP_OPT_NO_COMPRESSION => 'optional', - PCLZIP_OPT_COMMENT => 'optional' + PCLZIP_OPT_COMMENT => 'optional', + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', + PCLZIP_OPT_TEMP_FILE_ON => 'optional', + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' //, PCLZIP_OPT_CRYPT => 'optional' )); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } } @@ -292,7 +317,6 @@ // Here we need to support the first historic synopsis of the // method. else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); // ----- Get the first argument $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; @@ -304,27 +328,29 @@ else if ($v_size > 2) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return 0; } } } + + // ----- Look for default option values + $this->privOptionDefaultThreshold($v_options); // ----- Init $v_string_list = array(); $v_att_list = array(); $v_filedescr_list = array(); $p_result_list = array(); - + // ----- Look if the $p_filelist is really an array if (is_array($p_filelist)) { - + // ----- Look if the first element is also an array // This will mean that this is a file description entry if (isset($p_filelist[0]) && is_array($p_filelist[0])) { $v_att_list = $p_filelist; } - + // ----- The list is a list of string names else { $v_string_list = $p_filelist; @@ -340,10 +366,9 @@ // ----- Invalid variable type for $p_filelist else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } - + // ----- Reformat the string list if (sizeof($v_string_list) != 0) { foreach ($v_string_list as $v_string) { @@ -351,16 +376,18 @@ $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; } else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Ignore an empty filename"); } } } - + // ----- For each file in the list check the attributes $v_supported_attributes = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' + ,PCLZIP_ATT_FILE_MTIME => 'optional' + ,PCLZIP_ATT_FILE_CONTENT => 'optional' + ,PCLZIP_ATT_FILE_COMMENT => 'optional' ); foreach ($v_att_list as $v_entry) { $v_result = $this->privFileDescrParseAtt($v_entry, @@ -368,7 +395,6 @@ $v_options, $v_supported_attributes); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } } @@ -376,19 +402,16 @@ // ----- Expand the filelist (expand directories) $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } // ----- Call the create fct $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list); return $p_result_list; } // -------------------------------------------------------------------------------- @@ -430,7 +453,6 @@ // -------------------------------------------------------------------------------- function add($p_filelist) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ..."); $v_result=1; // ----- Reset the error handler @@ -442,7 +464,6 @@ // ----- Look for variable options arguments $v_size = func_num_args(); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); // ----- Look for arguments if ($v_size > 1) { @@ -455,7 +476,6 @@ // ----- Look for first arg if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected"); // ----- Parse the options $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, @@ -467,11 +487,13 @@ PCLZIP_OPT_NO_COMPRESSION => 'optional', PCLZIP_OPT_COMMENT => 'optional', PCLZIP_OPT_ADD_COMMENT => 'optional', - PCLZIP_OPT_PREPEND_COMMENT => 'optional' + PCLZIP_OPT_PREPEND_COMMENT => 'optional', + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', + PCLZIP_OPT_TEMP_FILE_ON => 'optional', + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' //, PCLZIP_OPT_CRYPT => 'optional' )); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } } @@ -480,7 +502,6 @@ // Here we need to support the first historic synopsis of the // method. else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); // ----- Get the first argument $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; @@ -494,27 +515,29 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return 0; } } } + // ----- Look for default option values + $this->privOptionDefaultThreshold($v_options); + // ----- Init $v_string_list = array(); $v_att_list = array(); $v_filedescr_list = array(); $p_result_list = array(); - + // ----- Look if the $p_filelist is really an array if (is_array($p_filelist)) { - + // ----- Look if the first element is also an array // This will mean that this is a file description entry if (isset($p_filelist[0]) && is_array($p_filelist[0])) { $v_att_list = $p_filelist; } - + // ----- The list is a list of string names else { $v_string_list = $p_filelist; @@ -530,22 +553,24 @@ // ----- Invalid variable type for $p_filelist else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } - + // ----- Reformat the string list if (sizeof($v_string_list) != 0) { foreach ($v_string_list as $v_string) { $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; } } - + // ----- For each file in the list check the attributes $v_supported_attributes = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' + ,PCLZIP_ATT_FILE_MTIME => 'optional' + ,PCLZIP_ATT_FILE_CONTENT => 'optional' + ,PCLZIP_ATT_FILE_COMMENT => 'optional' ); foreach ($v_att_list as $v_entry) { $v_result = $this->privFileDescrParseAtt($v_entry, @@ -553,7 +578,6 @@ $v_options, $v_supported_attributes); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } } @@ -561,19 +585,16 @@ // ----- Expand the filelist (expand directories) $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } // ----- Call the create fct $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list); return $p_result_list; } // -------------------------------------------------------------------------------- @@ -606,7 +627,7 @@ // write protected // newer_exist : the file was not extracted because a newer file exists // path_creation_fail : the file is not extracted because the folder - // does not exists and can not be created + // does not exist and can not be created // write_error : the file was not extracted because there was a // error while writing the file // read_error : the file was not extracted because there was a error @@ -621,7 +642,6 @@ // -------------------------------------------------------------------------------- function listContent() { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', ""); $v_result=1; // ----- Reset the error handler @@ -629,7 +649,6 @@ // ----- Check archive if (!$this->privCheckFormat()) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return(0); } @@ -638,12 +657,10 @@ if (($v_result = $this->privList($p_list)) != 1) { unset($p_list); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); return(0); } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); return $p_list; } // -------------------------------------------------------------------------------- @@ -682,7 +699,6 @@ // -------------------------------------------------------------------------------- function extract() { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", ""); $v_result=1; // ----- Reset the error handler @@ -690,7 +706,6 @@ // ----- Check archive if (!$this->privCheckFormat()) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return(0); } @@ -703,7 +718,6 @@ // ----- Look for variable options arguments $v_size = func_num_args(); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); // ----- Default values for option $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; @@ -715,7 +729,6 @@ // ----- Look for first arg if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options"); // ----- Parse the options $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, @@ -734,10 +747,12 @@ PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', PCLZIP_OPT_REPLACE_NEWER => 'optional' ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' - ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' + ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', + PCLZIP_OPT_TEMP_FILE_ON => 'optional', + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' )); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } @@ -764,7 +779,6 @@ // Here we need to support the first historic synopsis of the // method. else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); // ----- Get the first argument $v_path = $v_arg_list[0]; @@ -778,14 +792,15 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); return 0; } } } + // ----- Look for default option values + $this->privOptionDefaultThreshold($v_options); + // ----- Trace - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'"); // ----- Call the extracting fct $p_list = array(); @@ -793,12 +808,10 @@ $v_remove_all_path, $v_options); if ($v_result < 1) { unset($p_list); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); return(0); } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); return $p_list; } // -------------------------------------------------------------------------------- @@ -843,7 +856,6 @@ //function extractByIndex($p_index, options...) function extractByIndex($p_index) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ..."); $v_result=1; // ----- Reset the error handler @@ -851,7 +863,6 @@ // ----- Check archive if (!$this->privCheckFormat()) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return(0); } @@ -864,7 +875,6 @@ // ----- Look for variable options arguments $v_size = func_num_args(); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); // ----- Default values for option $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; @@ -880,7 +890,6 @@ // ----- Look for first arg if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options"); // ----- Parse the options $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, @@ -894,10 +903,12 @@ PCLZIP_OPT_SET_CHMOD => 'optional', PCLZIP_OPT_REPLACE_NEWER => 'optional' ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' - ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' + ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', + PCLZIP_OPT_TEMP_FILE_ON => 'optional', + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' )); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } @@ -920,10 +931,8 @@ } if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set."); } else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set."); } } @@ -931,7 +940,6 @@ // Here we need to support the first historic synopsis of the // method. else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis"); // ----- Get the first argument $v_path = $v_arg_list[0]; @@ -945,14 +953,12 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return 0; } } } // ----- Trace - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "index='$p_index', path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'"); // ----- Trick // Here I want to reuse extractByRule(), so I need to parse the $p_index @@ -962,19 +968,19 @@ $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, array (PCLZIP_OPT_BY_INDEX => 'optional' )); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX]; + // ----- Look for default option values + $this->privOptionDefaultThreshold($v_options); + // ----- Call the extracting fct if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); return(0); } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); return $p_list; } // -------------------------------------------------------------------------------- @@ -990,7 +996,7 @@ // Options : // PCLZIP_OPT_BY_INDEX : // PCLZIP_OPT_BY_NAME : - // PCLZIP_OPT_BY_EREG : + // PCLZIP_OPT_BY_EREG : // PCLZIP_OPT_BY_PREG : // Return Values : // 0 on failure, @@ -999,7 +1005,6 @@ // -------------------------------------------------------------------------------- function delete() { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", ""); $v_result=1; // ----- Reset the error handler @@ -1007,7 +1012,6 @@ // ----- Check archive if (!$this->privCheckFormat()) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return(0); } @@ -1016,7 +1020,6 @@ // ----- Look for variable options arguments $v_size = func_num_args(); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method"); // ----- Look for arguments if ($v_size > 0) { @@ -1030,7 +1033,6 @@ PCLZIP_OPT_BY_PREG => 'optional', PCLZIP_OPT_BY_INDEX => 'optional' )); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } } @@ -1043,7 +1045,6 @@ if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) { $this->privSwapBackMagicQuotes(); unset($v_list); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo()); return(0); } @@ -1051,7 +1052,6 @@ $this->privSwapBackMagicQuotes(); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list); return $v_list; } // -------------------------------------------------------------------------------- @@ -1064,12 +1064,10 @@ // -------------------------------------------------------------------------------- function deleteByIndex($p_index) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'"); - + $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list); return $p_list; } // -------------------------------------------------------------------------------- @@ -1090,7 +1088,6 @@ // -------------------------------------------------------------------------------- function properties() { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", ""); // ----- Reset the error handler $this->privErrorReset(); @@ -1101,7 +1098,6 @@ // ----- Check archive if (!$this->privCheckFormat()) { $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return(0); } @@ -1115,16 +1111,14 @@ if (@is_file($this->zipname)) { // ----- Open the zip file - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) { $this->privSwapBackMagicQuotes(); - + // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0); return 0; } @@ -1133,7 +1127,6 @@ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return 0; } @@ -1150,7 +1143,6 @@ $this->privSwapBackMagicQuotes(); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop); return $v_prop; } // -------------------------------------------------------------------------------- @@ -1169,7 +1161,6 @@ // -------------------------------------------------------------------------------- function duplicate($p_archive) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", ""); $v_result = 1; // ----- Reset the error handler @@ -1178,7 +1169,6 @@ // ----- Look if the $p_archive is a PclZip object if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'"); // ----- Duplicate the archive $v_result = $this->privDuplicate($p_archive->zipname); @@ -1187,7 +1177,6 @@ // ----- Look if the $p_archive is a string (so a filename) else if (is_string($p_archive)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'"); // ----- Check that $p_archive is a valid zip file // TBC : Should also check the archive format @@ -1211,7 +1200,6 @@ } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -1232,7 +1220,6 @@ // -------------------------------------------------------------------------------- function merge($p_archive_to_add) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", ""); $v_result = 1; // ----- Reset the error handler @@ -1240,14 +1227,12 @@ // ----- Check archive if (!$this->privCheckFormat()) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0); return(0); } // ----- Look if the $p_archive_to_add is a PclZip object if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object"); // ----- Merge the archive $v_result = $this->privMerge($p_archive_to_add); @@ -1256,7 +1241,6 @@ // ----- Look if the $p_archive_to_add is a string (so a filename) else if (is_string($p_archive_to_add)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename"); // ----- Create a temporary archive $v_object_archive = new PclZip($p_archive_to_add); @@ -1274,7 +1258,6 @@ } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -1389,7 +1372,6 @@ // -------------------------------------------------------------------------------- function privCheckFormat($p_level=0) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", ""); $v_result = true; // ----- Reset the file system cache @@ -1402,7 +1384,6 @@ if (!is_file($this->zipname)) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo()); return(false); } @@ -1410,7 +1391,6 @@ if (!is_readable($this->zipname)) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo()); return(false); } @@ -1424,7 +1404,6 @@ // TBC // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -1446,13 +1425,11 @@ // -------------------------------------------------------------------------------- function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", ""); $v_result=1; - + // ----- Read the options $i=0; while ($i<$p_size) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'"); // ----- Check if the option is supported if (!isset($v_requested_options[$p_options_list[$i]])) { @@ -1460,7 +1437,6 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -1476,16 +1452,64 @@ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Get the value - $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); + $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); $i++; break; + case PCLZIP_OPT_TEMP_FILE_THRESHOLD : + // ----- Check the number of parameters + 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(); + } + + // ----- Check for incompatible options + if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); + return PclZip::errorCode(); + } + + // ----- Check the value + $v_value = $p_options_list[$i+1]; + if ((!is_integer($v_value)) || ($v_value<0)) { + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); + return PclZip::errorCode(); + } + + // ----- Get the value (and convert it in bytes) + $v_result_list[$p_options_list[$i]] = $v_value*1048576; + $i++; + break; + + case PCLZIP_OPT_TEMP_FILE_ON : + // ----- Check for incompatible options + if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); + return PclZip::errorCode(); + } + + $v_result_list[$p_options_list[$i]] = true; + break; + + case PCLZIP_OPT_TEMP_FILE_OFF : + // ----- Check for incompatible options + if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) { + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); + return PclZip::errorCode(); + } + // ----- Check for incompatible options + if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); + return PclZip::errorCode(); + } + + $v_result_list[$p_options_list[$i]] = true; + break; + case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : // ----- Check the number of parameters if (($i+1) >= $p_size) { @@ -1493,19 +1517,16 @@ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Get the value if ( is_string($p_options_list[$i+1]) && ($p_options_list[$i+1] != '')) { - $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); + $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); $i++; } else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored."); } break; @@ -1517,7 +1538,6 @@ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -1533,15 +1553,16 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); $i++; break; // ----- Look for options that request an EREG or PREG expression case PCLZIP_OPT_BY_EREG : + // ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG + // to PCLZIP_OPT_BY_PREG + $p_options_list[$i] = PCLZIP_OPT_BY_PREG; case PCLZIP_OPT_BY_PREG : //case PCLZIP_OPT_CRYPT : // ----- Check the number of parameters @@ -1550,7 +1571,6 @@ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -1563,10 +1583,8 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); $i++; break; @@ -1583,7 +1601,6 @@ ."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -1599,10 +1616,8 @@ ."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); $i++; break; @@ -1614,14 +1629,12 @@ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Get the value $v_work_list = array(); if (is_string($p_options_list[$i+1])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'"); // ----- Remove spaces $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); @@ -1630,11 +1643,9 @@ $v_work_list = explode(",", $p_options_list[$i+1]); } else if (is_integer($p_options_list[$i+1])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an 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])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array"); $v_work_list = $p_options_list[$i+1]; } else { @@ -1642,10 +1653,9 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - + // ----- Reduce the index list // each index item in the list must be a couple with a start and // an end value : [0,3], [5-5], [8-10], ... @@ -1656,10 +1666,10 @@ // ----- Explode the item $v_item_list = explode("-", $v_work_list[$j]); $v_size_item_list = sizeof($v_item_list); - + // ----- TBC : Here we might check that each item is a // real integer ... - + // ----- Look for single value if ($v_size_item_list == 1) { // ----- Set the option value @@ -1676,15 +1686,12 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extracted index item = [".$v_result_list[$p_options_list[$i]][$j]['start'].",".$v_result_list[$p_options_list[$i]][$j]['end']."]"); // ----- Look for list sort if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ..."); $v_sort_flag=true; // ----- TBC : An automatic sort should be writen ... @@ -1692,16 +1699,14 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; } - + // ----- Sort the items if ($v_sort_flag) { // TBC : To Be Completed - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ..."); } // ----- Next option @@ -1716,7 +1721,6 @@ case PCLZIP_OPT_REPLACE_NEWER : case PCLZIP_OPT_STOP_ON_ERROR : $v_result_list[$p_options_list[$i]] = true; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); break; // ----- Look for options that request an octal value @@ -1727,13 +1731,11 @@ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Get the value $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'"); $i++; break; @@ -1754,13 +1756,11 @@ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Get the value $v_function_name = $p_options_list[$i+1]; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'"); // ----- Check that the value is a valid existing function if (!function_exists($v_function_name)) { @@ -1768,7 +1768,6 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -1784,7 +1783,6 @@ .$p_options_list[$i]."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -1797,22 +1795,66 @@ for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { // ----- Look for mandatory option if ($v_requested_options[$key] == 'mandatory') { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); // ----- Look if present if (!isset($v_result_list[$key])) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } } } } + + // ----- Look for default values + if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { + + } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); + return $v_result; + } + // -------------------------------------------------------------------------------- + + // -------------------------------------------------------------------------------- + // Function : privOptionDefaultThreshold() + // Description : + // Parameters : + // Return Values : + // -------------------------------------------------------------------------------- + function privOptionDefaultThreshold(&$p_options) + { + $v_result=1; + + if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) + || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) { + return $v_result; + } + + // ----- Get 'memory_limit' configuration value + $v_memory_limit = ini_get('memory_limit'); + $v_memory_limit = trim($v_memory_limit); + $last = strtolower(substr($v_memory_limit, -1)); + + if($last == 'g') + //$v_memory_limit = $v_memory_limit*1024*1024*1024; + $v_memory_limit = $v_memory_limit*1073741824; + if($last == 'm') + //$v_memory_limit = $v_memory_limit*1024*1024; + $v_memory_limit = $v_memory_limit*1048576; + if($last == 'k') + $v_memory_limit = $v_memory_limit*1024; + + $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO); + + + // ----- Sanity check : No threshold if value lower than 1M + if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) { + unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]); + } + + // ----- Return return $v_result; } // -------------------------------------------------------------------------------- @@ -1827,19 +1869,17 @@ // -------------------------------------------------------------------------------- function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", ""); $v_result=1; - + // ----- For each file in the list check the attributes foreach ($p_file_list as $v_key => $v_value) { - + // ----- Check if the option is supported if (!isset($v_requested_options[$v_key])) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -1848,16 +1888,13 @@ case PCLZIP_ATT_FILE_NAME : if (!is_string($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); - + if ($p_filedescr['filename'] == '') { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -1866,16 +1903,13 @@ case PCLZIP_ATT_FILE_NEW_SHORT_NAME : if (!is_string($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); if ($p_filedescr['new_short_name'] == '') { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } break; @@ -1883,27 +1917,46 @@ case PCLZIP_ATT_FILE_NEW_FULL_NAME : if (!is_string($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); if ($p_filedescr['new_full_name'] == '') { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } break; + // ----- Look for options that takes a string + case PCLZIP_ATT_FILE_COMMENT : + if (!is_string($v_value)) { + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); + return PclZip::errorCode(); + } + + $p_filedescr['comment'] = $v_value; + break; + + case PCLZIP_ATT_FILE_MTIME : + if (!is_integer($v_value)) { + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); + return PclZip::errorCode(); + } + + $p_filedescr['mtime'] = $v_value; + break; + + case PCLZIP_ATT_FILE_CONTENT : + $p_filedescr['content'] = $v_value; + break; + default : // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Unknown parameter '".$v_key."'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -1912,22 +1965,19 @@ for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { // ----- Look for mandatory option if ($v_requested_options[$key] == 'mandatory') { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")"); // ----- Look if present if (!isset($p_file_list[$key])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } } } } - + // end foreach } - + // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -1935,6 +1985,12 @@ // -------------------------------------------------------------------------------- // Function : privFileDescrExpand() // Description : + // This method look for each item of the list to see if its a file, a folder + // or a string to be added as file. For any other type of files (link, other) + // just ignore the item. + // Then prepare the information that will be stored for that file. + // When its a folder, expand the folder with all the files that are in that + // folder (recursively). // Parameters : // Return Values : // 1 on success. @@ -1942,58 +1998,59 @@ // -------------------------------------------------------------------------------- function privFileDescrExpand(&$p_filedescr_list, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", ""); $v_result=1; - + // ----- Create a result list $v_result_list = array(); - + // ----- Look each entry for ($i=0; $iprivCalculateStoredFilename($v_descr, $p_options); - + // ----- Add the descriptor in result list $v_result_list[sizeof($v_result_list)] = $v_descr; - + // ----- Look for folder if ($v_descr['type'] == 'folder') { // ----- List of items in folder @@ -2001,58 +2058,59 @@ $v_dirlist_nb = 0; if ($v_folder_handler = @opendir($v_descr['filename'])) { while (($v_item_handler = @readdir($v_folder_handler)) !== false) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory"); // ----- Skip '.' and '..' if (($v_item_handler == '.') || ($v_item_handler == '..')) { continue; } - + // ----- Compose the full filename $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; - + // ----- Look for different stored filename // Because the name of the folder was changed, the name of the // files/sub-folders also change - if ($v_descr['stored_filename'] != $v_descr['filename']) { - $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; + if (($v_descr['stored_filename'] != $v_descr['filename']) + && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { + if ($v_descr['stored_filename'] != '') { + $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; + } + else { + $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; + } } - + $v_dirlist_nb++; } + + @closedir($v_folder_handler); } else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped."); // TBC : unable to open folder in read mode } - + // ----- Expand each element of the list if ($v_dirlist_nb != 0) { // ----- Expand if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } - + // ----- Concat the resulting list - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')"); $v_result_list = array_merge($v_result_list, $v_dirlist_descr); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'"); } else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand."); } - + // ----- Free local array unset($v_dirlist_descr); } } - + // ----- Get the result list $p_filedescr_list = $v_result_list; // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -2065,10 +2123,9 @@ // -------------------------------------------------------------------------------- function privCreate($p_filedescr_list, &$p_result_list, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list"); $v_result=1; $v_list_detail = array(); - + // ----- Magic quotes trick $this->privDisableMagicQuotes(); @@ -2076,7 +2133,6 @@ if (($v_result = $this->privOpenFd('wb')) != 1) { // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -2090,7 +2146,6 @@ $this->privSwapBackMagicQuotes(); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -2103,34 +2158,29 @@ // -------------------------------------------------------------------------------- function privAdd($p_filedescr_list, &$p_result_list, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list"); $v_result=1; $v_list_detail = array(); // ----- Look if the archive exists or is empty if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it."); // ----- Do a create $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Magic quotes trick $this->privDisableMagicQuotes(); // ----- Open the zip file - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); if (($v_result=$this->privOpenFd('rb')) != 1) { // ----- Magic quotes trick $this->privSwapBackMagicQuotes(); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -2140,20 +2190,16 @@ { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Go to beginning of File - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); @rewind($this->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); // ----- Creates a temporay file $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; // ----- Open the temporary file in write mode - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) { $this->privCloseFd(); @@ -2162,7 +2208,6 @@ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -2172,7 +2217,6 @@ while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); $v_buffer = fread($this->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; @@ -2195,20 +2239,17 @@ $this->privSwapBackMagicQuotes(); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Store the offset of the central dir $v_offset = @ftell($this->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset"); // ----- Copy the block of file headers from the old archive $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); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); $v_buffer = @fread($v_zip_temp_fd, $v_read_size); @fwrite($this->zip_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; @@ -2226,7 +2267,6 @@ $this->privSwapBackMagicQuotes(); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } $v_count++; @@ -2259,7 +2299,6 @@ $this->privSwapBackMagicQuotes(); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -2287,7 +2326,6 @@ PclZipUtilRename($v_zip_temp_name, $this->zipname); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -2299,7 +2337,6 @@ // -------------------------------------------------------------------------------- function privOpenFd($p_mode) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode); $v_result=1; // ----- Look if already open @@ -2309,24 +2346,20 @@ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Open the zip file - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Open file in '.$p_mode.' mode'); if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -2338,7 +2371,6 @@ // -------------------------------------------------------------------------------- function privCloseFd() { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCloseFd", ""); $v_result=1; if ($this->zip_fd != 0) @@ -2346,7 +2378,6 @@ $this->zip_fd = 0; // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -2367,7 +2398,6 @@ // function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options) function privAddList($p_filedescr_list, &$p_result_list, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list"); $v_result=1; // ----- Add the files @@ -2375,7 +2405,6 @@ if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) { // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -2389,7 +2418,6 @@ if ($v_header_list[$i]['status'] == 'ok') { if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } $v_count++; @@ -2415,12 +2443,10 @@ unset($v_header_list); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -2429,55 +2455,54 @@ // Function : privAddFileList() // Description : // Parameters : - // $p_filedescr_list : An array containing the file description + // $p_filedescr_list : An array containing the file description // or directory names to add in the zip // $p_result_list : list of added files with their properties (specially the status field) // Return Values : // -------------------------------------------------------------------------------- function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list"); $v_result=1; $v_header = array(); // ----- Recuperate the current number of elt in list $v_nb = sizeof($p_result_list); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements"); // ----- Loop on the files for ($j=0; ($jprivAddFile($p_filedescr_list[$j], $v_header, $p_options); if ($v_result != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -2485,10 +2510,8 @@ $p_result_list[$v_nb++] = $v_header; } } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "After add, list have ".$v_nb." elements"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -2501,9 +2524,8 @@ // -------------------------------------------------------------------------------- function privAddFile($p_filedescr, &$p_header, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'"); $v_result=1; - + // ----- Working variable $p_filename = $p_filedescr['filename']; @@ -2513,19 +2535,18 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - - // ----- Look for a stored different filename + + // ----- Look for a stored different filename + /* TBC : Removed if (isset($p_filedescr['stored_filename'])) { $v_stored_filename = $p_filedescr['stored_filename']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"'); } else { $v_stored_filename = $p_filedescr['stored_filename']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same'); } + */ // ----- Set the file properties clearstatcache(); @@ -2533,29 +2554,63 @@ $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)?0xFE49FFE0:0x41FF0010); - $p_header['external'] = (is_file($p_filename)?0x00000000:0x00000010); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'"); $p_header['offset'] = 0; $p_header['filename'] = $p_filename; - $p_header['stored_filename'] = $v_stored_filename; +// TBC : Removed $p_header['stored_filename'] = $v_stored_filename; + $p_header['stored_filename'] = $p_filedescr['stored_filename']; $p_header['extra'] = ''; - $p_header['comment'] = ''; $p_header['status'] = 'ok'; $p_header['index'] = -1; + // ----- Look for regular file + if ($p_filedescr['type']=='file') { + $p_header['external'] = 0x00000000; + $p_header['size'] = filesize($p_filename); + } + + // ----- Look for regular folder + else if ($p_filedescr['type']=='folder') { + $p_header['external'] = 0x00000010; + $p_header['mtime'] = filemtime($p_filename); + $p_header['size'] = filesize($p_filename); + } + + // ----- Look for virtual file + else if ($p_filedescr['type'] == 'virtual_file') { + $p_header['external'] = 0x00000000; + $p_header['size'] = strlen($p_filedescr['content']); + } + + + // ----- Look for filetime + if (isset($p_filedescr['mtime'])) { + $p_header['mtime'] = $p_filedescr['mtime']; + } + else if ($p_filedescr['type'] == 'virtual_file') { + $p_header['mtime'] = time(); + } + else { + $p_header['mtime'] = filemtime($p_filename); + } + + // ------ Look for file comment + if (isset($p_filedescr['comment'])) { + $p_header['comment_len'] = strlen($p_filedescr['comment']); + $p_header['comment'] = $p_filedescr['comment']; + } + else { + $p_header['comment_len'] = 0; + $p_header['comment'] = ''; + } + // ----- Look for pre-add callback if (isset($p_options[PCLZIP_CB_PRE_ADD])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction"); // ----- Generate a local information $v_local_header = array(); @@ -2564,7 +2619,8 @@ // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. - eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);'); +// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);'); + $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header); if ($v_result == 0) { // ----- Change the file status $p_header['status'] = "skipped"; @@ -2575,7 +2631,6 @@ // Only some fields can be modified if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New stored filename is '".$p_header['stored_filename']."'"); } } @@ -2583,7 +2638,7 @@ if ($p_header['stored_filename'] == "") { $p_header['status'] = "filtered"; } - + // ----- Check the path length if (strlen($p_header['stored_filename']) > 0xFF) { $p_header['status'] = 'filename_too_long'; @@ -2593,85 +2648,103 @@ if ($p_header['status'] == 'ok') { // ----- Look for a file - if (is_file($p_filename)) - { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file"); + if ($p_filedescr['type'] == 'file') { + // ----- Look for using temporary file to zip + if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) + && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) + || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) + && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { + $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); + if ($v_result < PCLZIP_ERR_NO_ERROR) { + return $v_result; + } + } + + // ----- Use "in memory" zip algo + else { + // ----- Open the source file 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"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed"); - // ----- Read the file content - $v_content_compressed = @fread($v_file, $p_header['size']); + // ----- Read the file content + $v_content = @fread($v_file, $p_header['size']); - // ----- Calculate the CRC - $p_header['crc'] = @crc32($v_content_compressed); + // ----- Close the file + @fclose($v_file); + // ----- Calculate the CRC + $p_header['crc'] = @crc32($v_content); + + // ----- Look for no compression + if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { // ----- Set header parameters $p_header['compressed_size'] = $p_header['size']; $p_header['compression'] = 0; } + + // ----- Look for normal compression else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed"); - // ----- Read the file content - $v_content = @fread($v_file, $p_header['size']); - - // ----- Calculate the CRC - $p_header['crc'] = @crc32($v_content); - - // ----- Compress the file - $v_content_compressed = @gzdeflate($v_content); + // ----- Compress the content + $v_content = @gzdeflate($v_content); // ----- Set header parameters - $p_header['compressed_size'] = strlen($v_content_compressed); + $p_header['compressed_size'] = strlen($v_content); $p_header['compression'] = 8; } + + // ----- Call the header generation + if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { + @fclose($v_file); + return $v_result; + } + + // ----- Write the compressed (or not) content + @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); - // ----- Look for encryption - /* - if ((isset($p_options[PCLZIP_OPT_CRYPT])) - && ($p_options[PCLZIP_OPT_CRYPT] != "")) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ...."); - - // Should be a random header - $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; - - // ----- Add the header to the data - $v_content_compressed = $v_header.$v_content_compressed; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed).""); } - */ + } + + // ----- Look for a virtual file (a file from string) + else if ($p_filedescr['type'] == 'virtual_file') { + + $v_content = $p_filedescr['content']; + + // ----- Calculate the CRC + $p_header['crc'] = @crc32($v_content); + + // ----- Look for no compression + if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { + // ----- Set header parameters + $p_header['compressed_size'] = $p_header['size']; + $p_header['compression'] = 0; + } + + // ----- Look for normal compression + else { + // ----- Compress the content + $v_content = @gzdeflate($v_content); + + // ----- Set header parameters + $p_header['compressed_size'] = strlen($v_content); + $p_header['compression'] = 8; + } + // ----- Call the header generation if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { @fclose($v_file); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Write the compressed (or not) content - @fwrite($this->zip_fd, - $v_content_compressed, $p_header['compressed_size']); - - // ----- Close the file - @fclose($v_file); + @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); } // ----- Look for a directory - else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder"); + else if ($p_filedescr['type'] == 'folder') { // ----- Look for directory last '/' if (@substr($p_header['stored_filename'], -1) != '/') { $p_header['stored_filename'] .= '/'; @@ -2685,7 +2758,6 @@ // ----- Call the header generation if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } } @@ -2693,7 +2765,6 @@ // ----- Look for post-add callback if (isset($p_options[PCLZIP_CB_POST_ADD])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_ADD]."()') is defined for the extraction"); // ----- Generate a local information $v_local_header = array(); @@ -2702,7 +2773,8 @@ // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. - eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);'); +// eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);'); + $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header); if ($v_result == 0) { // ----- Ignored $v_result = 1; @@ -2713,7 +2785,116 @@ } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); + return $v_result; + } + // -------------------------------------------------------------------------------- + + // -------------------------------------------------------------------------------- + // Function : privAddFileUsingTempFile() + // Description : + // Parameters : + // Return Values : + // -------------------------------------------------------------------------------- + function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) + { + $v_result=PCLZIP_ERR_NO_ERROR; + + // ----- Working variable + $p_filename = $p_filedescr['filename']; + + + // ----- Open the source file + 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(); + } + + // ----- Creates a compressed temporary file + $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; + if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { + fclose($v_file); + PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); + return PclZip::errorCode(); + } + + // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks + $v_size = filesize($p_filename); + while ($v_size != 0) { + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); + $v_buffer = @fread($v_file, $v_read_size); + //$v_binary_data = pack('a'.$v_read_size, $v_buffer); + @gzputs($v_file_compressed, $v_buffer, $v_read_size); + $v_size -= $v_read_size; + } + + // ----- Close the file + @fclose($v_file); + @gzclose($v_file_compressed); + + // ----- Check the minimum file size + if (filesize($v_gzip_temp_name) < 18) { + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); + return PclZip::errorCode(); + } + + // ----- Extract the compressed attributes + if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); + return PclZip::errorCode(); + } + + // ----- Read the gzip file header + $v_binary_data = @fread($v_file_compressed, 10); + $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data); + + // ----- Check some parameters + $v_data_header['os'] = bin2hex($v_data_header['os']); + + // ----- Read the gzip file footer + @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); + $v_binary_data = @fread($v_file_compressed, 8); + $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); + + // ----- Set the attributes + $p_header['compression'] = ord($v_data_header['cm']); + //$p_header['mtime'] = $v_data_header['mtime']; + $p_header['crc'] = $v_data_footer['crc']; + $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; + + // ----- Close the file + @fclose($v_file_compressed); + + // ----- Call the header generation + if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { + return $v_result; + } + + // ----- Add the compressed data + if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) + { + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); + return PclZip::errorCode(); + } + + // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks + fseek($v_file_compressed, 10); + $v_size = $p_header['compressed_size']; + while ($v_size != 0) + { + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); + $v_buffer = @fread($v_file_compressed, $v_read_size); + //$v_binary_data = pack('a'.$v_read_size, $v_buffer); + @fwrite($this->zip_fd, $v_buffer, $v_read_size); + $v_size -= $v_read_size; + } + + // ----- Close the file + @fclose($v_file_compressed); + + // ----- Unlink the temporary file + @unlink($v_gzip_temp_name); + + // ----- Return return $v_result; } // -------------------------------------------------------------------------------- @@ -2728,9 +2909,8 @@ // -------------------------------------------------------------------------------- function privCalculateStoredFilename(&$p_filedescr, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'"); $v_result=1; - + // ----- Working variables $p_filename = $p_filedescr['filename']; if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { @@ -2752,16 +2932,18 @@ $p_remove_all_dir = 0; } + // ----- Look for full name change if (isset($p_filedescr['new_full_name'])) { - $v_stored_filename = $p_filedescr['new_full_name']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing full name of '".$p_filename."' for '".$v_stored_filename."'"); + // ----- Remove drive letter if any + $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']); } - + // ----- Look for path and/or short name change else { // ----- Look for short name change + // Its when we cahnge just the filename but not the path if (isset($p_filedescr['new_short_name'])) { $v_path_info = pathinfo($p_filename); $v_dir = ''; @@ -2769,7 +2951,6 @@ $v_dir = $v_path_info['dirname'].'/'; } $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing short name of '".$p_filename."' for '".$v_stored_filename."'"); } else { // ----- Calculate the stored filename @@ -2779,7 +2960,6 @@ // ----- Look for all path to remove if ($p_remove_all_dir) { $v_stored_filename = basename($p_filename); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove all path selected change '".$p_filename."' for '".$v_stored_filename."'"); } // ----- Look for partial path remove else if ($p_remove_dir != "") { @@ -2788,7 +2968,7 @@ 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; @@ -2804,33 +2984,31 @@ if ($v_compare > 0) { if ($v_compare == 2) { $v_stored_filename = ""; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Path to remove is the current folder"); } else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove path '$p_remove_dir' in file '$v_stored_filename'"); $v_stored_filename = substr($v_stored_filename, strlen($p_remove_dir)); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Result is '$v_stored_filename'"); } } } + + // ----- Remove drive letter if any + $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename); + // ----- Look for path to add 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; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'"); } } // ----- Filename (reduce the path of stored name) $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); $p_filedescr['stored_filename'] = $v_stored_filename; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Stored filename will be '".$p_filedescr['stored_filename']."', strlen ".strlen($p_filedescr['stored_filename'])); - + // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -2843,15 +3021,12 @@ // -------------------------------------------------------------------------------- function privWriteFileHeader(&$p_header) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"'); $v_result=1; // ----- Store the offset position of the file $p_header['offset'] = ftell($this->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'File offset of the header :'.$p_header['offset']); // ----- Transform UNIX mtime to DOS format mdate/mtime - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); $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']; @@ -2879,7 +3054,6 @@ } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -2892,20 +3066,18 @@ // -------------------------------------------------------------------------------- function privWriteCentralFileHeader(&$p_header) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"'); $v_result=1; // TBC //for(reset($p_header); $key = key($p_header); next($p_header)) { - // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "header[$key] = ".$p_header[$key]); //} // ----- Transform UNIX mtime to DOS format mdate/mtime - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); $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']; + // ----- Packed data $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, $p_header['version'], $p_header['version_extracted'], @@ -2935,7 +3107,6 @@ } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -2948,7 +3119,6 @@ // -------------------------------------------------------------------------------- function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralHeader", 'nb_entries='.$p_nb_entries.', size='.$p_size.', offset='.$p_offset.', comment="'.$p_comment.'"'); $v_result=1; // ----- Packed data @@ -2966,7 +3136,6 @@ } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -2979,24 +3148,21 @@ // -------------------------------------------------------------------------------- function privList(&$p_list) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privList", "list"); $v_result=1; // ----- Magic quotes trick $this->privDisableMagicQuotes(); // ----- Open the zip file - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) { // ----- Magic quotes trick $this->privSwapBackMagicQuotes(); - + // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -3005,15 +3171,11 @@ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Go to beginning of Central Dir - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Offset : ".$v_central_dir['offset']."'"); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); @rewind($this->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); if (@fseek($this->zip_fd, $v_central_dir['offset'])) { $this->privSwapBackMagicQuotes(); @@ -3022,10 +3184,8 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'"); // ----- Read each entry for ($i=0; $i<$v_central_dir['entries']; $i++) @@ -3034,7 +3194,6 @@ if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) { $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } $v_header['index'] = $i; @@ -3051,7 +3210,6 @@ $this->privSwapBackMagicQuotes(); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -3071,17 +3229,19 @@ // $p_info['comment'] = Comment associated with the file. // $p_info['folder'] = true/false : indicates if the entry is a folder or not. // $p_info['status'] = status of the action on the file. + // $p_info['crc'] = CRC of the file content. // Parameters : // Return Values : // -------------------------------------------------------------------------------- function privConvertHeader2FileInfo($p_header, &$p_info) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privConvertHeader2FileInfo", "Filename='".$p_header['filename']."'"); $v_result=1; // ----- Get the interesting attributes - $p_info['filename'] = $p_header['filename']; - $p_info['stored_filename'] = $p_header['stored_filename']; + $v_temp_path = PclZipUtilPathReduction($p_header['filename']); + $p_info['filename'] = $v_temp_path; + $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']); + $p_info['stored_filename'] = $v_temp_path; $p_info['size'] = $p_header['size']; $p_info['compressed_size'] = $p_header['compressed_size']; $p_info['mtime'] = $p_header['mtime']; @@ -3089,9 +3249,9 @@ $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); $p_info['index'] = $p_header['index']; $p_info['status'] = $p_header['status']; + $p_info['crc'] = $p_header['crc']; // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -3114,7 +3274,6 @@ // -------------------------------------------------------------------------------- function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privExtractByRule", "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'"); $v_result=1; // ----- Magic quotes trick @@ -3133,9 +3292,7 @@ // ----- Look for the path end '/' while (substr($p_path, -1) == "/") { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'"); $p_path = substr($p_path, 0, strlen($p_path)-1); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]"); } } @@ -3147,11 +3304,9 @@ $p_remove_path_size = strlen($p_remove_path); // ----- Open the zip file - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); if (($v_result = $this->privOpenFd('rb')) != 1) { $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -3163,7 +3318,6 @@ $this->privCloseFd(); $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -3174,12 +3328,9 @@ $j_start = 0; for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry : '$i'"); // ----- Read next Central dir entry - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position before rewind : ".ftell($this->zip_fd)."'"); @rewind($this->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position after rewind : ".ftell($this->zip_fd)."'"); if (@fseek($this->zip_fd, $v_pos_entry)) { // ----- Close the zip file @@ -3190,10 +3341,8 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after fseek : ".ftell($this->zip_fd)."'"); // ----- Read the file header $v_header = array(); @@ -3203,7 +3352,6 @@ $this->privCloseFd(); $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -3219,49 +3367,43 @@ // ----- Look for extract by name rule if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'"); // ----- Look if the filename is in the list for ($j=0; ($j 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])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path"); $v_extract = true; } } // ----- Look for a filename elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one."); $v_extract = true; } } } // ----- Look for extract by ereg rule + // ereg() is deprecated with PHP 5.3 + /* else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'"); if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); $v_extract = true; } } + */ // ----- Look for extract by preg rule else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'"); if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); $v_extract = true; } } @@ -3269,23 +3411,18 @@ // ----- Look for extract by index rule else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); - + // ----- Look if the index is in the list for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range"); $v_extract = true; } if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop"); $j_start = $j+1; } if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop"); break; } } @@ -3293,7 +3430,6 @@ // ----- Look for no rule, which means extract all the archive else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with no rule (extract all)"); $v_extract = true; } @@ -3301,35 +3437,30 @@ if ( ($v_extract) && ( ($v_header['compression'] != 8) && ($v_header['compression'] != 0))) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported compression method (".$v_header['compression'].")"); $v_header['status'] = 'unsupported_compression'; // ----- Look for PCLZIP_OPT_STOP_ON_ERROR if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); $this->privSwapBackMagicQuotes(); - + PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, "Filename '".$v_header['stored_filename']."' is " ."compressed by an unsupported compression " ."method (".$v_header['compression'].") "); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } } - + // ----- Check encrypted files if (($v_extract) && (($v_header['flag'] & 1) == 1)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption"); $v_header['status'] = 'unsupported_encryption'; // ----- Look for PCLZIP_OPT_STOP_ON_ERROR if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); $this->privSwapBackMagicQuotes(); @@ -3338,35 +3469,29 @@ ." filename '".$v_header['stored_filename'] ."'"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } } // ----- Look for real extraction if (($v_extract) && ($v_header['status'] != 'ok')) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "No need for extract"); $v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++]); if ($v_result != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } $v_extract = false; } - + // ----- Look for real extraction if ($v_extract) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file '".$v_header['filename']."', index '$i'"); // ----- Go to the file position - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); @rewind($this->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); if (@fseek($this->zip_fd, $v_header['offset'])) { // ----- Close the zip file @@ -3378,20 +3503,19 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); // ----- Look for extraction as string if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) { + $v_string = ''; + // ----- Extracting the file - $v_result1 = $this->privExtractFileAsString($v_header, $v_string); + $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options); if ($v_result1 < 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); return $v_result1; } @@ -3402,7 +3526,6 @@ $this->privCloseFd(); $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -3411,7 +3534,7 @@ // ----- Next extracted file $v_nb_extracted++; - + // ----- Look for user callback abort if ($v_result1 == 2) { break; @@ -3425,7 +3548,6 @@ if ($v_result1 < 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); return $v_result1; } @@ -3433,7 +3555,6 @@ if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -3452,7 +3573,6 @@ if ($v_result1 < 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1); return $v_result1; } @@ -3463,7 +3583,6 @@ $this->privCloseFd(); $this->privSwapBackMagicQuotes(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -3480,7 +3599,6 @@ $this->privSwapBackMagicQuotes(); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -3496,18 +3614,15 @@ // -------------------------------------------------------------------------------- function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'"); $v_result=1; // ----- Read the file header if (($v_result = $this->privReadFileHeader($v_header)) != 1) { // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); // ----- Check that the file header is coherent with $p_entry info if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { @@ -3518,15 +3633,12 @@ if ($p_remove_all_path == true) { // ----- Look for folder entry that not need to be extracted if (($p_entry['external']&0x00000010)==0x00000010) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The entry is a folder : need to be filtered"); $p_entry['status'] = "filtered"; - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "All path is removed"); // ----- Get the basename of the path $p_entry['filename'] = basename($p_entry['filename']); } @@ -3534,28 +3646,23 @@ // ----- Look for path to remove else if ($p_remove_path != "") { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look for some path to remove"); if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'"); // ----- Change the file status $p_entry['status'] = "filtered"; // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } $p_remove_path_size = strlen($p_remove_path); if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'"); // ----- Remove the path $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'"); } } @@ -3563,28 +3670,24 @@ if ($p_path != '') { $p_entry['filename'] = $p_path."/".$p_entry['filename']; } - + // ----- Check a base_dir_restriction if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction"); $v_inclusion = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], - $p_entry['filename']); + $p_entry['filename']); if ($v_inclusion == 0) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction"); PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, "Filename '".$p_entry['filename']."' is " ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } } // ----- Look for pre-extract callback if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction"); // ----- Generate a local information $v_local_header = array(); @@ -3593,16 +3696,16 @@ // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. - eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); +// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); + $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); if ($v_result == 0) { // ----- Change the file status $p_entry['status'] = "skipped"; $v_result = 1; } - + // ----- Look for abort result if ($v_result == 2) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); // ----- This status is internal and will be changed in 'skipped' $p_entry['status'] = "aborted"; $v_result = PCLZIP_ERR_USER_ABORTED; @@ -3611,10 +3714,8 @@ // ----- Update the informations // Only some fields can be modified $p_entry['filename'] = $v_local_header['filename']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'"); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'"); // ----- Look if extraction should be done if ($p_entry['status'] == 'ok') { @@ -3622,35 +3723,30 @@ // ----- Look for specific actions while the file exist if (file_exists($p_entry['filename'])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists"); // ----- Look if file is a directory if (is_dir($p_entry['filename'])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory"); // ----- Change the file status $p_entry['status'] = "already_a_directory"; - + // ----- Look for PCLZIP_OPT_STOP_ON_ERROR // For historical reason first PclZip implementation does not stop // when this kind of error occurs. if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, "Filename '".$p_entry['filename']."' is " ."already used by an existing directory"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); - } + } } // ----- Look if file is write protected else if (!is_writeable($p_entry['filename'])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is write protected"); // ----- Change the file status $p_entry['status'] = "write_protected"; @@ -3660,28 +3756,23 @@ // when this kind of error occurs. if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Filename '".$p_entry['filename']."' exists " ."and is write protected"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); - } + } } // ----- Look if the extracted file is older else if (filemtime($p_entry['filename']) > $p_entry['mtime']) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is newer (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")"); // ----- Change the file status if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_REPLACE_NEWER is selected, file will be replaced"); - } - else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be replaced"); + } + else { $p_entry['status'] = "newer_exist"; // ----- Look for PCLZIP_OPT_STOP_ON_ERROR @@ -3689,19 +3780,16 @@ // when this kind of error occurs. if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped"); PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Newer version of '".$p_entry['filename']."' exists " ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); + } } - } } else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is older than the extrated one - will be replaced by the extracted one (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")"); } } @@ -3714,19 +3802,17 @@ else $v_dir_to_check = dirname($p_entry['filename']); - if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '".$p_entry['filename']."'"); - - // ----- Change the file status - $p_entry['status'] = "path_creation_fail"; - - // ----- Return - ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); - //return $v_result; - $v_result = 1; + if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { + + // ----- Change the file status + $p_entry['status'] = "path_creation_fail"; + + // ----- Return + //return $v_result; + $v_result = 1; + } } } - } // ----- Look if extraction should be done if ($p_entry['status'] == 'ok') { @@ -3736,35 +3822,30 @@ { // ----- Look for not compressed file if ($p_entry['compression'] == 0) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); - // ----- Opening destination file + // ----- Opening destination file if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); // ----- Change the file status $p_entry['status'] = "write_error"; // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read '".$p_entry['size']."' bytes"); // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks $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); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes"); $v_buffer = @fread($this->zip_fd, $v_read_size); /* Try to speed up the code $v_binary_data = pack('a'.$v_read_size, $v_buffer); @fwrite($v_dest_file, $v_binary_data, $v_read_size); */ - @fwrite($v_dest_file, $v_buffer, $v_read_size); + @fwrite($v_dest_file, $v_buffer, $v_read_size); $v_size -= $v_read_size; } @@ -3773,92 +3854,87 @@ // ----- Change the file mtime touch($p_entry['filename'], $p_entry['mtime']); - + } else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (Compression method ".$p_entry['compression'].")"); // ----- TBC // Need to be finished if (($p_entry['flag'] & 1) == 1) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File is encrypted"); - /* - // ----- Read the encryption header - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read 12 encryption header bytes"); - $v_encryption_header = @fread($this->zip_fd, 12); - - // ----- Read the encrypted & compressed file in a buffer - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".($p_entry['compressed_size']-12)."' compressed & encrypted bytes"); - $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12); - - // ----- Decrypt the buffer - $this->privDecrypt($v_encryption_header, $v_buffer, - $p_entry['compressed_size']-12, $p_entry['crc']); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Buffer is '".$v_buffer."'"); - */ - } - else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".$p_entry['compressed_size']."' compressed bytes"); - // ----- Read the compressed file in a buffer (one shot) - $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); + PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.'); + return PclZip::errorCode(); } - // ----- Decompress the file - $v_file_content = @gzinflate($v_buffer); - unset($v_buffer); - if ($v_file_content === FALSE) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to inflate compressed file"); - - // ----- Change the file status - // TBC - $p_entry['status'] = "error"; - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); - return $v_result; + // ----- Look for using temporary file to unzip + if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) + && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) + || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) + && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) { + $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options); + if ($v_result < PCLZIP_ERR_NO_ERROR) { + return $v_result; + } } + + // ----- Look for extract in memory + else { - // ----- Opening destination file - if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode"); - - // ----- Change the file status - $p_entry['status'] = "write_error"; - - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); - return $v_result; + + // ----- Read the compressed file in a buffer (one shot) + $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); + + // ----- Decompress the file + $v_file_content = @gzinflate($v_buffer); + unset($v_buffer); + if ($v_file_content === FALSE) { + + // ----- Change the file status + // TBC + $p_entry['status'] = "error"; + + return $v_result; + } + + // ----- Opening destination file + if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { + + // ----- Change the file status + $p_entry['status'] = "write_error"; + + return $v_result; + } + + // ----- Write the uncompressed data + @fwrite($v_dest_file, $v_file_content, $p_entry['size']); + unset($v_file_content); + + // ----- Closing the destination file + @fclose($v_dest_file); + } - // ----- Write the uncompressed data - @fwrite($v_dest_file, $v_file_content, $p_entry['size']); - unset($v_file_content); - - // ----- Closing the destination file - @fclose($v_dest_file); - // ----- Change the file mtime @touch($p_entry['filename'], $p_entry['mtime']); } // ----- Look for chmod option if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "chmod option activated '".$p_options[PCLZIP_OPT_SET_CHMOD]."'"); // ----- Change the mode of the file @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); } } - // ----- Change abort status - if ($p_entry['status'] == "aborted") { - $p_entry['status'] = "skipped"; - } - + // ----- Change abort status + if ($p_entry['status'] == "aborted") { + $p_entry['status'] = "skipped"; + } + // ----- Look for post-extract callback elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction"); // ----- Generate a local information $v_local_header = array(); @@ -3867,17 +3943,92 @@ // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. - eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); +// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); + $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); // ----- Look for abort result if ($v_result == 2) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); $v_result = PCLZIP_ERR_USER_ABORTED; } } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); + return $v_result; + } + // -------------------------------------------------------------------------------- + + // -------------------------------------------------------------------------------- + // Function : privExtractFileUsingTempFile() + // Description : + // Parameters : + // Return Values : + // -------------------------------------------------------------------------------- + function privExtractFileUsingTempFile(&$p_entry, &$p_options) + { + $v_result=1; + + // ----- Creates a temporary file + $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; + if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) { + fclose($v_file); + PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); + return PclZip::errorCode(); + } + + + // ----- Write gz file format header + $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3)); + @fwrite($v_dest_file, $v_binary_data, 10); + + // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks + $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_buffer, $v_read_size); + $v_size -= $v_read_size; + } + + // ----- Write gz file format footer + $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']); + @fwrite($v_dest_file, $v_binary_data, 8); + + // ----- Close the temporary file + @fclose($v_dest_file); + + // ----- Opening destination file + if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { + $p_entry['status'] = "write_error"; + return $v_result; + } + + // ----- Open the temporary gz file + if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) { + @fclose($v_dest_file); + $p_entry['status'] = "read_error"; + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); + return PclZip::errorCode(); + } + + + // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks + $v_size = $p_entry['size']; + while ($v_size != 0) { + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); + $v_buffer = @gzread($v_src_file, $v_read_size); + //$v_binary_data = pack('a'.$v_read_size, $v_buffer); + @fwrite($v_dest_file, $v_buffer, $v_read_size); + $v_size -= $v_read_size; + } + @fclose($v_dest_file); + @gzclose($v_src_file); + + // ----- Delete the temporary file + @unlink($v_gzip_temp_name); + + // ----- Return return $v_result; } // -------------------------------------------------------------------------------- @@ -3890,16 +4041,13 @@ // -------------------------------------------------------------------------------- function privExtractFileInOutput(&$p_entry, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileInOutput', ""); $v_result=1; // ----- Read the file header if (($v_result = $this->privReadFileHeader($v_header)) != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); // ----- Check that the file header is coherent with $p_entry info if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { @@ -3908,7 +4056,6 @@ // ----- Look for pre-extract callback if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction"); // ----- Generate a local information $v_local_header = array(); @@ -3917,7 +4064,8 @@ // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. - eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); +// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); + $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); if ($v_result == 0) { // ----- Change the file status $p_entry['status'] = "skipped"; @@ -3926,7 +4074,6 @@ // ----- Look for abort result if ($v_result == 2) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); // ----- This status is internal and will be changed in 'skipped' $p_entry['status'] = "aborted"; $v_result = PCLZIP_ERR_USER_ABORTED; @@ -3935,11 +4082,9 @@ // ----- Update the informations // Only some fields can be modified $p_entry['filename'] = $v_local_header['filename']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'"); } // ----- Trace - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'"); // ----- Look if extraction should be done if ($p_entry['status'] == 'ok') { @@ -3948,8 +4093,6 @@ if (!(($p_entry['external']&0x00000010)==0x00000010)) { // ----- Look for not compressed file if ($p_entry['compressed_size'] == $p_entry['size']) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes"); // ----- Read the file in a buffer (one shot) $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); @@ -3959,12 +4102,10 @@ unset($v_buffer); } else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file"); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Reading '".$p_entry['size']."' bytes"); // ----- Read the compressed file in a buffer (one shot) $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); - + // ----- Decompress the file $v_file_content = gzinflate($v_buffer); unset($v_buffer); @@ -3973,7 +4114,6 @@ echo $v_file_content; unset($v_file_content); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); } } @@ -3984,7 +4124,6 @@ // ----- Look for post-extract callback elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction"); // ----- Generate a local information $v_local_header = array(); @@ -3993,16 +4132,15 @@ // ----- Call the callback // Here I do not use call_user_func() because I need to send a reference to the // header. - eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); +// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); + $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); // ----- Look for abort result if ($v_result == 2) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction"); $v_result = PCLZIP_ERR_USER_ABORTED; } } - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -4013,9 +4151,8 @@ // Parameters : // Return Values : // -------------------------------------------------------------------------------- - function privExtractFileAsString(&$p_entry, &$p_string) + function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileAsString', "p_entry['filename']='".$p_entry['filename']."'"); $v_result=1; // ----- Read the file header @@ -4023,52 +4160,110 @@ if (($v_result = $this->privReadFileHeader($v_header)) != 1) { // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'"); // ----- Check that the file header is coherent with $p_entry info if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { // TBC } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file in string (with path) '".$p_entry['filename']."', size '$v_header[size]'"); + // ----- Look for pre-extract callback + if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { - // ----- Do the extraction (if not a folder) - if (!(($p_entry['external']&0x00000010)==0x00000010)) - { - // ----- Look for not compressed file -// if ($p_entry['compressed_size'] == $p_entry['size']) - if ($p_entry['compression'] == 0) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file"); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes"); - - // ----- Reading the file - $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); + // ----- Generate a local information + $v_local_header = array(); + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); + + // ----- Call the callback + // Here I do not use call_user_func() because I need to send a reference to the + // header. +// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); + $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); + if ($v_result == 0) { + // ----- Change the file status + $p_entry['status'] = "skipped"; + $v_result = 1; } - else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (compression method '".$p_entry['compression']."')"); + + // ----- Look for abort result + if ($v_result == 2) { + // ----- This status is internal and will be changed in 'skipped' + $p_entry['status'] = "aborted"; + $v_result = PCLZIP_ERR_USER_ABORTED; + } + + // ----- Update the informations + // Only some fields can be modified + $p_entry['filename'] = $v_local_header['filename']; + } - // ----- Reading the file - $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); - // ----- Decompress the file - if (($p_string = @gzinflate($v_data)) === FALSE) { - // TBC + // ----- Look if extraction should be done + if ($p_entry['status'] == 'ok') { + + // ----- Do the extraction (if not a folder) + if (!(($p_entry['external']&0x00000010)==0x00000010)) { + // ----- Look for not compressed file + // if ($p_entry['compressed_size'] == $p_entry['size']) + if ($p_entry['compression'] == 0) { + + // ----- Reading the file + $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); } + else { + + // ----- Reading the file + $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); + + // ----- Decompress the file + if (($p_string = @gzinflate($v_data)) === FALSE) { + // TBC + } + } + + // ----- Trace } - - // ----- Trace - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done"); + else { + // TBC : error : can not extract a folder in a string + } + } - else { - // TBC : error : can not extract a folder in a string + + // ----- Change abort status + if ($p_entry['status'] == "aborted") { + $p_entry['status'] = "skipped"; + } + + // ----- Look for post-extract callback + elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { + + // ----- Generate a local information + $v_local_header = array(); + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); + + // ----- Swap the content to header + $v_local_header['content'] = $p_string; + $p_string = ''; + + // ----- Call the callback + // Here I do not use call_user_func() because I need to send a reference to the + // header. +// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); + $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); + + // ----- Swap back the content to header + $p_string = $v_local_header['content']; + unset($v_local_header['content']); + + // ----- Look for abort result + if ($v_result == 2) { + $v_result = PCLZIP_ERR_USER_ABORTED; + } } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -4081,25 +4276,20 @@ // -------------------------------------------------------------------------------- function privReadFileHeader(&$p_header) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadFileHeader", ""); $v_result=1; // ----- Read the 4 bytes signature $v_binary_data = @fread($this->zip_fd, 4); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); $v_data = unpack('Vid', $v_binary_data); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); // ----- Check signature if ($v_data['id'] != 0x04034b50) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid File header"); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -4111,51 +4301,36 @@ { $p_header['filename'] = ""; $p_header['status'] = "invalid_header"; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Extract the values - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header : '".$v_binary_data."'"); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header (Hex) : '".bin2hex($v_binary_data)."'"); $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); // ----- Get filename - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "File name length : ".$v_data['filename_len']); $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename : \''.$p_header['filename'].'\''); // ----- Get extra_fields - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extra field length : ".$v_data['extra_len']); if ($v_data['extra_len'] != 0) { $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); } else { $p_header['extra'] = ''; } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Extra field : \''.bin2hex($p_header['extra']).'\''); // ----- Extract properties $p_header['version_extracted'] = $v_data['version']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : ('.$p_header['version_extracted'].') \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); $p_header['compression'] = $v_data['compression']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compression method : \''.$p_header['compression'].'\''); $p_header['size'] = $v_data['size']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_header['size'].'\''); $p_header['compressed_size'] = $v_data['compressed_size']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_header['compressed_size'].'\''); $p_header['crc'] = $v_data['crc']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); $p_header['flag'] = $v_data['flag']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\''); $p_header['filename_len'] = $v_data['filename_len']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename_len : \''.$p_header['filename_len'].'\''); // ----- Recuperate date in UNIX format $p_header['mdate'] = $v_data['mdate']; @@ -4173,19 +4348,16 @@ $v_day = $p_header['mdate'] & 0x001F; // ----- Get UNIX date format - $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); + $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); } else { $p_header['mtime'] = time(); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); } // TBC //for(reset($v_data); $key = key($v_data); next($v_data)) { - // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Attribut[$key] = ".$v_data[$key]); //} // ----- Set the stored filename @@ -4195,7 +4367,6 @@ $p_header['status'] = "ok"; // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -4208,25 +4379,20 @@ // -------------------------------------------------------------------------------- function privReadCentralFileHeader(&$p_header) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadCentralFileHeader", ""); $v_result=1; // ----- Read the 4 bytes signature $v_binary_data = @fread($this->zip_fd, 4); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); $v_data = unpack('Vid', $v_binary_data); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); // ----- Check signature if ($v_data['id'] != 0x02014b50) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid Central Dir File signature"); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -4238,56 +4404,41 @@ { $p_header['filename'] = ""; $p_header['status'] = "invalid_header"; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data)); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Extract the values - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header : '".$v_binary_data."'"); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header (Hex) : '".bin2hex($v_binary_data)."'"); $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); // ----- Get filename - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File name length : ".$p_header['filename_len']); if ($p_header['filename_len'] != 0) $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); else $p_header['filename'] = ''; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Filename : \''.$p_header['filename'].'\''); // ----- Get extra - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Extra length : ".$p_header['extra_len']); if ($p_header['extra_len'] != 0) $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); else $p_header['extra'] = ''; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Extra : \''.$p_header['extra'].'\''); // ----- Get comment - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Comment length : ".$p_header['comment_len']); if ($p_header['comment_len'] != 0) $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); else $p_header['comment'] = ''; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Comment : \''.$p_header['comment'].'\''); // ----- Extract properties - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version : \''.($p_header['version']/10).'.'.($p_header['version']%10).'\''); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\''); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Size : \''.$p_header['size'].'\''); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Compressed Size : \''.$p_header['compressed_size'].'\''); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\''); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Flag : \''.$p_header['flag'].'\''); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Offset : \''.$p_header['offset'].'\''); // ----- Recuperate date in UNIX format - if ($p_header['mdate'] && $p_header['mtime']) + //if ($p_header['mdate'] && $p_header['mtime']) + // TBC : bug : this was ignoring time with 0/0/0 + if (1) { // ----- Extract time $v_hour = ($p_header['mtime'] & 0xF800) >> 11; @@ -4300,14 +4451,12 @@ $v_day = $p_header['mdate'] & 0x001F; // ----- Get UNIX date format - $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); + $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); } else { $p_header['mtime'] = time(); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\''); } // ----- Set the stored filename @@ -4317,18 +4466,13 @@ $p_header['status'] = 'ok'; // ----- Look if it is a directory - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Internal (Hex) : '".sprintf("Ox%04X", $p_header['internal'])."'"); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "External (Hex) : '".sprintf("Ox%04X", $p_header['external'])."' (".(($p_header['external']&0x00000010)==0x00000010?'is a folder':'is a file').')'); if (substr($p_header['filename'], -1) == '/') { //$p_header['external'] = 0x41FF0010; $p_header['external'] = 0x00000010; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Force folder external : \''.sprintf("Ox%04X", $p_header['external']).'\''); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Header of filename : \''.$p_header['filename'].'\''); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -4343,44 +4487,31 @@ // -------------------------------------------------------------------------------- function privCheckFileHeaders(&$p_local_header, &$p_central_header) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFileHeaders", ""); $v_result=1; - // ----- Check the static values - // TBC - if ($p_local_header['filename'] != $p_central_header['filename']) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename" : TBC To Be Completed'); - } - if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "version_extracted" : TBC To Be Completed'); - } - if ($p_local_header['flag'] != $p_central_header['flag']) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "flag" : TBC To Be Completed'); - } - if ($p_local_header['compression'] != $p_central_header['compression']) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "compression" : TBC To Be Completed'); - } - if ($p_local_header['mtime'] != $p_central_header['mtime']) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "mtime" : TBC To Be Completed'); - } - if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename_len" : TBC To Be Completed'); - } - - // ----- Look for flag bit 3 - if (($p_local_header['flag'] & 8) == 8) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Purpose bit flag bit 3 set !'); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'File size, compression size and crc found in central header'); - $p_local_header['size'] = $p_central_header['size']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_local_header['size'].'\''); - $p_local_header['compressed_size'] = $p_central_header['compressed_size']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_local_header['compressed_size'].'\''); - $p_local_header['crc'] = $p_central_header['crc']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_local_header['crc']).'\''); - } + // ----- 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 ($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 - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -4393,21 +4524,17 @@ // -------------------------------------------------------------------------------- function privReadEndCentralDir(&$p_central_dir) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadEndCentralDir", ""); $v_result=1; // ----- Go to the end of the zip file $v_size = filesize($this->zipname); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size of the file :$v_size"); @fseek($this->zip_fd, $v_size); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position at end of zip file : \''.ftell($this->zip_fd).'\''); if (@ftell($this->zip_fd) != $v_size) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -4415,28 +4542,22 @@ // in this case the end of central dir is at 22 bytes of the file end $v_found = 0; if ($v_size > 26) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Look for central dir with no comment'); @fseek($this->zip_fd, $v_size-22); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after min central position : \''.ftell($this->zip_fd).'\''); if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Read for bytes $v_binary_data = @fread($this->zip_fd, 4); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Binary data is : '".sprintf("%08x", $v_binary_data)."'"); $v_data = @unpack('Vid', $v_binary_data); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'"); // ----- Check signature if ($v_data['id'] == 0x06054b50) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found central dir at the default position."); $v_found = 1; } @@ -4445,7 +4566,6 @@ // ----- Go back to the maximum possible size of the Central Dir End Record if (!$v_found) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Start extended search of end central dir'); $v_maximum_size = 65557; // 0xFFFF + 22; if ($v_maximum_size > $v_size) $v_maximum_size = $v_size; @@ -4456,10 +4576,8 @@ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after max central position : \''.ftell($this->zip_fd).'\''); // ----- Read byte per byte in order to find the signature $v_pos = ftell($this->zip_fd); @@ -4470,12 +4588,14 @@ $v_byte = @fread($this->zip_fd, 1); // ----- Add the byte - $v_bytes = ($v_bytes << 8) | Ord($v_byte); + //$v_bytes = ($v_bytes << 8) | Ord($v_byte); + // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number + // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. + $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); // ----- Compare the bytes if ($v_bytes == 0x504b0506) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Found End Central Dir signature at position : \''.ftell($this->zip_fd).'\''); $v_pos++; break; } @@ -4486,13 +4606,11 @@ // ----- Look if not found end of central dir if ($v_pos == $v_size) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to find End of Central Dir Record signature"); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } } @@ -4503,25 +4621,19 @@ // ----- Look for invalid block size if (strlen($v_binary_data) != 18) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Extract the values - ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record : '".$v_binary_data."'"); - ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record (Hex) : '".bin2hex($v_binary_data)."'"); $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); // ----- Check the global size - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Comment length : ".$v_data['comment_size']); if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The central dir is not at the end of the archive. Some trailing bytes exists after the archive."); // ----- Removed in release 2.2 see readme file // The check of the file size is a little too strict. @@ -4534,38 +4646,29 @@ .' Some trailing bytes exists after the archive.'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } } // ----- Get comment - if ($v_data['comment_size'] != 0) + if ($v_data['comment_size'] != 0) { $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); + } else $p_central_dir['comment'] = ''; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment : \''.$p_central_dir['comment'].'\''); $p_central_dir['entries'] = $v_data['entries']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries : \''.$p_central_dir['entries'].'\''); $p_central_dir['disk_entries'] = $v_data['disk_entries']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries for this disk : \''.$p_central_dir['disk_entries'].'\''); $p_central_dir['offset'] = $v_data['offset']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Offset of Central Dir : \''.$p_central_dir['offset'].'\''); $p_central_dir['size'] = $v_data['size']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size of Central Dir : \''.$p_central_dir['size'].'\''); $p_central_dir['disk'] = $v_data['disk']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Disk number : \''.$p_central_dir['disk'].'\''); $p_central_dir['disk_start'] = $v_data['disk_start']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Start disk number : \''.$p_central_dir['disk_start'].'\''); // TBC //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) { - // //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "central_dir[$key] = ".$p_central_dir[$key]); //} // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -4578,16 +4681,13 @@ // -------------------------------------------------------------------------------- function privDeleteByRule(&$p_result_list, &$p_options) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", ""); $v_result=1; $v_list_detail = array(); // ----- Open the zip file - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); if (($v_result=$this->privOpenFd('rb')) != 1) { // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -4596,21 +4696,16 @@ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privCloseFd(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Go to beginning of File - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); @rewind($this->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'"); // ----- Scan all the files // ----- Start at beginning of Central Dir $v_pos_entry = $v_central_dir['offset']; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'"); @rewind($this->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); if (@fseek($this->zip_fd, $v_pos_entry)) { // ----- Close the zip file @@ -4620,17 +4715,14 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); // ----- Read each entry $v_header_list = array(); $j_start = 0; for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry (index '$i')"); // ----- Read the file header $v_header_list[$v_nb_extracted] = array(); @@ -4639,11 +4731,9 @@ // ----- Close the zip file $this->privCloseFd(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename (index '$i') : '".$v_header_list[$v_nb_extracted]['stored_filename']."'"); // ----- Store the index $v_header_list[$v_nb_extracted]['index'] = $i; @@ -4654,54 +4744,47 @@ // ----- Look for extract by name rule if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'"); // ----- Look if the filename is in the list for ($j=0; ($j 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])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path"); $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])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The entry is the searched directory"); $v_found = true; } } // ----- Look for a filename elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one."); $v_found = true; } } } // ----- Look for extract by ereg rule + // ereg() is deprecated with PHP 5.3 + /* else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'"); if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); $v_found = true; } } + */ // ----- Look for extract by preg rule else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'"); if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression"); $v_found = true; } } @@ -4709,41 +4792,33 @@ // ----- Look for extract by index rule else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); // ----- Look if the index is in the list for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range"); $v_found = true; } if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop"); $j_start = $j+1; } if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop"); break; } } } else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "No argument mean remove all file"); $v_found = true; } // ----- Look for deletion if ($v_found) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' need to be deleted"); unset($v_header_list[$v_nb_extracted]); } else { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' will not be deleted"); $v_nb_extracted++; } } @@ -4758,24 +4833,18 @@ $v_temp_zip = new PclZip($v_zip_temp_name); // ----- Open the temporary zip file in write mode - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary write mode"); if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { $this->privCloseFd(); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Look which file need to be kept for ($i=0; $izip_fd)."'"); @rewind($this->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'"); if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { // ----- Close the zip file $this->privCloseFd(); @@ -4786,10 +4855,8 @@ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'"); // ----- Read the file header $v_local_header = array(); @@ -4800,10 +4867,9 @@ @unlink($v_zip_temp_name); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } - + // ----- Check that local file header is same as central file header if ($this->privCheckFileHeaders($v_local_header, $v_header_list[$i]) != 1) { @@ -4819,10 +4885,8 @@ @unlink($v_zip_temp_name); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset for this file is '".$v_header_list[$i]['offset']."'"); // ----- Read/write the data block if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { @@ -4832,27 +4896,22 @@ @unlink($v_zip_temp_name); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } } // ----- Store the offset of the central dir $v_offset = @ftell($v_temp_zip->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "New offset of central dir : $v_offset"); // ----- Re-Create the Central Dir files header - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the new central directory"); for ($i=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) { $v_temp_zip->privCloseFd(); $this->privCloseFd(); @unlink($v_zip_temp_name); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -4860,7 +4919,6 @@ $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the central directory footer"); // ----- Zip file comment $v_comment = ''; @@ -4880,7 +4938,6 @@ @unlink($v_zip_temp_name); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -4896,22 +4953,20 @@ // TBC : I should test the result ... //@rename($v_zip_temp_name, $this->zipname); PclZipUtilRename($v_zip_temp_name, $this->zipname); - + // ----- Destroy the temporary archive unset($v_temp_zip); } - + // ----- Remove every files : reset the file else if ($v_central_dir['entries'] != 0) { $this->privCloseFd(); if (($v_result = $this->privOpenFd('wb')) != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -4919,7 +4974,6 @@ } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -4939,25 +4993,21 @@ { $v_result = 1; - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDirCheck", "entry='$p_dir', is_dir='".($p_is_dir?"true":"false")."'"); // ----- Remove the final '/' if (($p_is_dir) && (substr($p_dir, -1)=='/')) { $p_dir = substr($p_dir, 0, strlen($p_dir)-1); } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for entry '$p_dir'"); // ----- Check the directory availability if ((is_dir($p_dir)) || ($p_dir == "")) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, "'$p_dir' is a directory"); return 1; } // ----- Extract parent directory $p_parent_dir = dirname($p_dir); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'"); // ----- Just a check if ($p_parent_dir != $p_dir) @@ -4967,26 +5017,22 @@ { if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } } } // ----- Create the directory - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'"); if (!@mkdir($p_dir, 0777)) { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created"); return $v_result; } // -------------------------------------------------------------------------------- @@ -5000,41 +5046,34 @@ // -------------------------------------------------------------------------------- function privMerge(&$p_archive_to_add) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privMerge", "archive='".$p_archive_to_add->zipname."'"); $v_result=1; // ----- Look if the archive_to_add exists if (!is_file($p_archive_to_add->zipname)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to add does not exist. End of merge."); // ----- Nothing to merge, so merge is a success $v_result = 1; // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Look if the archive exists if (!is_file($this->zipname)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, duplicate the archive_to_add."); // ----- Do a duplicate $v_result = $this->privDuplicate($p_archive_to_add->zipname); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Open the zip file - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); if (($v_result=$this->privOpenFd('rb')) != 1) { // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -5043,23 +5082,18 @@ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privCloseFd(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Go to beginning of File - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'"); @rewind($this->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'"); // ----- Open the archive_to_add file - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open archive_to_add in binary read mode"); if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) { $this->privCloseFd(); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -5070,20 +5104,16 @@ $this->privCloseFd(); $p_archive_to_add->privCloseFd(); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Go to beginning of File - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'"); @rewind($p_archive_to_add->zip_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'"); // ----- Creates a temporay file $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; // ----- Open the temporary file in write mode - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) { $this->privCloseFd(); @@ -5092,7 +5122,6 @@ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -5102,7 +5131,6 @@ while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); $v_buffer = fread($this->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; @@ -5113,7 +5141,6 @@ while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); $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; @@ -5121,14 +5148,12 @@ // ----- Store the offset of the central dir $v_offset = @ftell($v_zip_temp_fd); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset"); // ----- Copy the block of file headers from the old archive $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); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); $v_buffer = @fread($this->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; @@ -5139,7 +5164,6 @@ while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); $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; @@ -5170,7 +5194,6 @@ unset($v_header_list); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } @@ -5196,7 +5219,6 @@ PclZipUtilRename($v_zip_temp_name, $this->zipname); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -5209,33 +5231,27 @@ // -------------------------------------------------------------------------------- function privDuplicate($p_archive_filename) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDuplicate", "archive_filename='$p_archive_filename'"); $v_result=1; // ----- Look if the $p_archive_filename exists if (!is_file($p_archive_filename)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to duplicate does not exist. End of duplicate."); // ----- Nothing to duplicate, so duplicate is a success. $v_result = 1; // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Open the zip file - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); if (($v_result=$this->privOpenFd('wb')) != 1) { // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Open the temporary file in write mode - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode"); if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) { $this->privCloseFd(); @@ -5243,7 +5259,6 @@ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo()); return PclZip::errorCode(); } @@ -5253,7 +5268,6 @@ while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read $v_read_size bytes"); $v_buffer = fread($v_zip_temp_fd, $v_read_size); @fwrite($this->zip_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; @@ -5266,7 +5280,6 @@ @fclose($v_zip_temp_fd); // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -5306,29 +5319,6 @@ // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- - // Function : privDecrypt() - // Description : - // Parameters : - // Return Values : - // -------------------------------------------------------------------------------- - function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc) - { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDecrypt', "size=".$p_size.""); - $v_result=1; - - // ----- To Be Modified ;-) - $v_pwd = "test"; - - $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header, - $p_crc, $v_pwd); - - // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); - return $v_result; - } - // -------------------------------------------------------------------------------- - - // -------------------------------------------------------------------------------- // Function : privDisableMagicQuotes() // Description : // Parameters : @@ -5336,36 +5326,28 @@ // -------------------------------------------------------------------------------- function privDisableMagicQuotes() { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDisableMagicQuotes', ""); $v_result=1; // ----- Look if function exists if ( (!function_exists("get_magic_quotes_runtime")) || (!function_exists("set_magic_quotes_runtime"))) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Look if already done if ($this->magic_quotes_status != -1) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote already disabled"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Get and memorize the magic_quote value $this->magic_quotes_status = @get_magic_quotes_runtime(); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Current magic_quotes_runtime status is '".($this->magic_quotes_status==0?'disable':'enable')."'"); // ----- Disable magic_quotes if ($this->magic_quotes_status == 1) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Disable magic_quotes"); @set_magic_quotes_runtime(0); } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -5378,32 +5360,25 @@ // -------------------------------------------------------------------------------- function privSwapBackMagicQuotes() { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privSwapBackMagicQuotes', ""); $v_result=1; // ----- Look if function exists if ( (!function_exists("get_magic_quotes_runtime")) || (!function_exists("set_magic_quotes_runtime"))) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Look if something to do if ($this->magic_quotes_status != -1) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote not modified"); - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // ----- Swap back magic_quotes if ($this->magic_quotes_status == 1) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Enable back magic_quotes"); @set_magic_quotes_runtime($this->magic_quotes_status); } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -5420,7 +5395,6 @@ // -------------------------------------------------------------------------------- function PclZipUtilPathReduction($p_dir) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathReduction", "dir='$p_dir'"); $v_result = ""; // ----- Look for not empty path @@ -5447,7 +5421,6 @@ // ----- It is an invalid path, so the path is not modified // TBC $v_result = $p_dir; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid path is unchanged"); $v_skip = 0; } } @@ -5471,7 +5444,7 @@ } } } - + // ----- Look for skip if ($v_skip > 0) { while ($v_skip > 0) { @@ -5482,7 +5455,6 @@ } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -5504,19 +5476,16 @@ // -------------------------------------------------------------------------------- function PclZipUtilPathInclusion($p_dir, $p_path) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathInclusion", "dir='$p_dir', path='$p_path'"); $v_result = 1; - + // ----- Look for path beginning by ./ if ( ($p_dir == '.') || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_dir '".$p_dir."'"); } if ( ($p_path == '.') || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_path '".$p_path."'"); } // ----- Explode dir and path by directory separator @@ -5529,7 +5498,6 @@ $i = 0; $j = 0; while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Working on dir($i)='".$v_list_dir[$i]."' and path($j)='".$v_list_path[$j]."'"); // ----- Look for empty dir (path reduction) if ($v_list_dir[$i] == '') { @@ -5543,7 +5511,6 @@ // ----- Compare the items if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Items ($i,$j) are different"); $v_result = 0; } @@ -5554,11 +5521,9 @@ // ----- Look if everything seems to be the same if ($v_result) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Look for tie break"); // ----- Skip all the empty items while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Looking on dir($i)='".($i < $v_list_dir_size?$v_list_dir[$i]:'')."' and path($j)='".($j < $v_list_path_size?$v_list_path[$j]:'')."'"); if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { // ----- There are exactly the same @@ -5571,7 +5536,6 @@ } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -5589,30 +5553,23 @@ // -------------------------------------------------------------------------------- function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilCopyBlock", "size=$p_size, mode=$p_mode"); $v_result = 1; if ($p_mode==0) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset before read :".(@ftell($p_src))); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset before write :".(@ftell($p_dest))); while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); $v_buffer = @fread($p_src, $v_read_size); @fwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; } - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset after read :".(@ftell($p_src))); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset after write :".(@ftell($p_dest))); } else if ($p_mode==1) { while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); $v_buffer = @gzread($p_src, $v_read_size); @fwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; @@ -5623,7 +5580,6 @@ while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); $v_buffer = @fread($p_src, $v_read_size); @gzwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; @@ -5634,7 +5590,6 @@ while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes"); $v_buffer = @gzread($p_src, $v_read_size); @gzwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; @@ -5642,7 +5597,6 @@ } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -5661,26 +5615,21 @@ // -------------------------------------------------------------------------------- function PclZipUtilRename($p_src, $p_dest) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilRename", "source=$p_src, destination=$p_dest"); $v_result = 1; // ----- Try to rename the files if (!@rename($p_src, $p_dest)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to rename file, try copy+unlink"); // ----- Try to copy & unlink the src if (!@copy($p_src, $p_dest)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to copy file"); $v_result = 0; } else if (!@unlink($p_src)) { - //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to unlink old filename"); $v_result = 0; } } // ----- Return - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- @@ -5696,23 +5645,20 @@ // -------------------------------------------------------------------------------- function PclZipUtilOptionText($p_option) { - //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilOptionText", "option='".$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_prefix == 'PCLZIP_ATT')) - && ($v_list[$v_key] == $p_option)) { - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_key); - return $v_key; + $v_prefix = substr($v_key, 0, 10); + if (( ($v_prefix == 'PCLZIP_OPT') + || ($v_prefix == 'PCLZIP_CB_') + || ($v_prefix == 'PCLZIP_ATT')) + && ($v_list[$v_key] == $p_option)) { + return $v_key; } } - + $v_result = 'Unknown'; - //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); return $v_result; } // -------------------------------------------------------------------------------- diff --git a/var/bin/schedulerTask.sh b/var/bin/schedulerTask.sh index 93ce1c8..4e7d69c 100755 --- a/var/bin/schedulerTask.sh +++ b/var/bin/schedulerTask.sh @@ -2,11 +2,11 @@ PHP_CLI="/usr/local/zend/bin/php" BIN_DIR=$(dirname $0) -INSTALL_DIR="../../${BIN_DIR}" +INSTALL_DIR="../..${BIN_DIR}" cd $INSTALL_DIR/bin while true; do $PHP_CLI -Cq scheduler.php sleep 30 -done \ No newline at end of file +done