本文整理汇总了PHP中ConfService::currentContextIsCommandLine方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfService::currentContextIsCommandLine方法的具体用法?PHP ConfService::currentContextIsCommandLine怎么用?PHP ConfService::currentContextIsCommandLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfService
的用法示例。
在下文中一共展示了ConfService::currentContextIsCommandLine方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resyncAction
public function resyncAction($actionName, $httpVars, $fileVars)
{
if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) {
AJXP_Controller::applyActionInBackground(ConfService::getRepository()->getId(), "resync_storage", $httpVars);
} else {
$file = $this->getResyncTimestampFile(true);
file_put_contents($file, time());
$this->indexIsSync();
}
}
示例2: switchAction
public function switchAction($action, $httpVars, $fileVars)
{
$selection = new UserSelection();
$dir = $httpVars["dir"] or "";
$dir = AJXP_Utils::decodeSecureMagic($dir);
if ($dir == "/") {
$dir = "";
}
$selection->initFromHttpVars($httpVars);
if (!$selection->isEmpty()) {
//$this->filterUserSelectionToHidden($selection->getFiles());
}
$urlBase = "pydio://" . ConfService::getRepository()->getId();
$mess = ConfService::getMessages();
switch ($action) {
case "monitor_compression":
$percentFile = fsAccessWrapper::getRealFSReference($urlBase . $dir . "/.zip_operation_" . $httpVars["ope_id"]);
$percent = 0;
if (is_file($percentFile)) {
$percent = intval(file_get_contents($percentFile));
}
if ($percent < 100) {
AJXP_XMLWriter::header();
AJXP_XMLWriter::triggerBgAction("monitor_compression", $httpVars, $mess["powerfs.1"] . " ({$percent}%)", true, 1);
AJXP_XMLWriter::close();
} else {
@unlink($percentFile);
AJXP_XMLWriter::header();
if ($httpVars["on_end"] == "reload") {
AJXP_XMLWriter::triggerBgAction("reload_node", array(), "powerfs.2", true, 2);
} else {
$archiveName = AJXP_Utils::sanitize($httpVars["archive_name"], AJXP_SANITIZE_FILENAME);
$archiveName = str_replace("'", "\\'", $archiveName);
$jsCode = "\n PydioApi.getClient().downloadSelection(null, \$('download_form'), 'postcompress_download', {ope_id:'" . $httpVars["ope_id"] . "',archive_name:'" . $archiveName . "'});\n ";
AJXP_XMLWriter::triggerBgJsAction($jsCode, $mess["powerfs.3"], true);
AJXP_XMLWriter::triggerBgAction("reload_node", array(), "powerfs.2", true, 2);
}
AJXP_XMLWriter::close();
}
break;
case "postcompress_download":
$archive = AJXP_Utils::getAjxpTmpDir() . DIRECTORY_SEPARATOR . $httpVars["ope_id"] . "_" . AJXP_Utils::sanitize(AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]), AJXP_SANITIZE_FILENAME);
$fsDriver = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("access");
if (is_file($archive)) {
if (!$fsDriver->getFilteredOption("USE_XSENDFILE", ConfService::getRepository()) && !$fsDriver->getFilteredOption("USE_XACCELREDIRECT", ConfService::getRepository())) {
register_shutdown_function("unlink", $archive);
}
$fsDriver->readFile($archive, "force-download", $httpVars["archive_name"], false, null, true);
} else {
echo "<script>alert('Cannot find archive! Is ZIP correctly installed?');</script>";
}
break;
case "compress":
case "precompress":
$archiveName = AJXP_Utils::sanitize(AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]), AJXP_SANITIZE_FILENAME);
if (!ConfService::currentContextIsCommandLine() && ConfService::backgroundActionsSupported()) {
$opeId = substr(md5(time()), 0, 10);
$httpVars["ope_id"] = $opeId;
AJXP_Controller::applyActionInBackground(ConfService::getRepository()->getId(), $action, $httpVars);
AJXP_XMLWriter::header();
$bgParameters = array("dir" => SystemTextEncoding::toUTF8($dir), "archive_name" => SystemTextEncoding::toUTF8($archiveName), "on_end" => isset($httpVars["on_end"]) ? $httpVars["on_end"] : "reload", "ope_id" => $opeId);
AJXP_XMLWriter::triggerBgAction("monitor_compression", $bgParameters, $mess["powerfs.1"] . " (0%)", true);
AJXP_XMLWriter::close();
session_write_close();
exit;
}
$rootDir = fsAccessWrapper::getRealFSReference($urlBase) . $dir;
$percentFile = $rootDir . "/.zip_operation_" . $httpVars["ope_id"];
$compressLocally = $action == "compress" ? true : false;
// List all files
$todo = array();
$args = array();
$replaceSearch = array($rootDir, "\\");
$replaceReplace = array("", "/");
foreach ($selection->getFiles() as $selectionFile) {
$baseFile = $selectionFile;
$args[] = escapeshellarg(substr($selectionFile, strlen($dir) + ($dir == "/" ? 0 : 1)));
$selectionFile = fsAccessWrapper::getRealFSReference($urlBase . $selectionFile);
$todo[] = ltrim(str_replace($replaceSearch, $replaceReplace, $selectionFile), "/");
if (is_dir($selectionFile)) {
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($selectionFile), RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $name => $object) {
$todo[] = str_replace($replaceSearch, $replaceReplace, $name);
}
}
if (trim($baseFile, "/") == "") {
// ROOT IS SELECTED, FIX IT
$args = array(escapeshellarg(basename($rootDir)));
$rootDir = dirname($rootDir);
break;
}
}
$cmdSeparator = PHP_OS == "WIN32" || PHP_OS == "WINNT" || PHP_OS == "Windows" ? "&" : ";";
if (!$compressLocally) {
$archiveName = AJXP_Utils::getAjxpTmpDir() . DIRECTORY_SEPARATOR . $httpVars["ope_id"] . "_" . $archiveName;
}
chdir($rootDir);
$cmd = $this->getFilteredOption("ZIP_PATH") . " -r " . escapeshellarg($archiveName) . " " . implode(" ", $args);
$fsDriver = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("access");
$c = $fsDriver->getConfigs();
//.........这里部分代码省略.........
示例3: receiveAction
/**
* @param String $action
* @param Array $httpVars
* @param Array $fileVars
* @throws Exception
*/
public function receiveAction($action, $httpVars, $fileVars)
{
//VAR CREATION OUTSIDE OF ALL CONDITIONS, THEY ARE "MUST HAVE" VAR !!
$messages = ConfService::getMessages();
$repository = ConfService::getRepository();
$userSelection = new UserSelection($repository, $httpVars);
$nodes = $userSelection->buildNodes();
$currentDirPath = AJXP_Utils::safeDirname($userSelection->getUniqueNode()->getPath());
$currentDirPath = rtrim($currentDirPath, "/") . "/";
$currentDirUrl = $userSelection->currentBaseUrl() . $currentDirPath;
if (empty($httpVars["compression_id"])) {
$compressionId = sha1(rand());
$httpVars["compression_id"] = $compressionId;
} else {
$compressionId = $httpVars["compression_id"];
}
$progressCompressionFileName = $this->getPluginCacheDir(false, true) . DIRECTORY_SEPARATOR . "progressCompressionID-" . $compressionId . ".txt";
if (empty($httpVars["extraction_id"])) {
$extractId = sha1(rand());
$httpVars["extraction_id"] = $extractId;
} else {
$extractId = $httpVars["extraction_id"];
}
$progressExtractFileName = $this->getPluginCacheDir(false, true) . DIRECTORY_SEPARATOR . "progressExtractID-" . $extractId . ".txt";
if ($action == "compression") {
$archiveName = AJXP_Utils::sanitize(AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]), AJXP_SANITIZE_FILENAME);
$archiveFormat = $httpVars["type_archive"];
$tabTypeArchive = array(".tar", ".tar.gz", ".tar.bz2");
$acceptedExtension = false;
foreach ($tabTypeArchive as $extensionArchive) {
if ($extensionArchive == $archiveFormat) {
$acceptedExtension = true;
break;
}
}
if ($acceptedExtension == false) {
file_put_contents($progressCompressionFileName, "Error : " . $messages["compression.16"]);
throw new AJXP_Exception($messages["compression.16"]);
}
$typeArchive = $httpVars["type_archive"];
//if we can run in background we do it
if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) {
$archivePath = $currentDirPath . $archiveName;
file_put_contents($progressCompressionFileName, $messages["compression.5"]);
AJXP_Controller::applyActionInBackground($repository->getId(), "compression", $httpVars);
AJXP_XMLWriter::header();
AJXP_XMLWriter::triggerBgAction("check_compression_status", array("repository_id" => $repository->getId(), "compression_id" => $compressionId, "archive_path" => SystemTextEncoding::toUTF8($archivePath)), $messages["compression.5"], true, 2);
AJXP_XMLWriter::close();
return null;
} else {
$maxAuthorizedSize = 4294967296;
$currentDirUrlLength = strlen($currentDirUrl);
$tabFolders = array();
$tabAllRecursiveFiles = array();
$tabFilesNames = array();
foreach ($nodes as $node) {
$nodeUrl = $node->getUrl();
if (is_file($nodeUrl) && filesize($nodeUrl) < $maxAuthorizedSize) {
array_push($tabAllRecursiveFiles, $nodeUrl);
array_push($tabFilesNames, substr($nodeUrl, $currentDirUrlLength));
}
if (is_dir($nodeUrl)) {
array_push($tabFolders, $nodeUrl);
}
}
//DO A FOREACH OR IT'S GONNA HAVE SOME SAMES FILES NAMES
foreach ($tabFolders as $value) {
$dossiers = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($value));
foreach ($dossiers as $file) {
if ($file->isDir()) {
continue;
}
array_push($tabAllRecursiveFiles, $file->getPathname());
array_push($tabFilesNames, substr($file->getPathname(), $currentDirUrlLength));
}
}
//WE STOP IF IT'S JUST AN EMPTY FOLDER OR NO FILES
if (empty($tabFilesNames)) {
file_put_contents($progressCompressionFileName, "Error : " . $messages["compression.17"]);
throw new AJXP_Exception($messages["compression.17"]);
}
try {
$tmpArchiveName = tempnam(AJXP_Utils::getAjxpTmpDir(), "tar-compression") . ".tar";
$archive = new PharData($tmpArchiveName);
} catch (Exception $e) {
file_put_contents($progressCompressionFileName, "Error : " . $e->getMessage());
throw $e;
}
$counterCompression = 0;
//THE TWO ARRAY ARE MERGED FOR THE FOREACH LOOP
$tabAllFiles = array_combine($tabAllRecursiveFiles, $tabFilesNames);
foreach ($tabAllFiles as $fullPath => $fileName) {
try {
$archive->addFile(AJXP_MetaStreamWrapper::getRealFSReference($fullPath), $fileName);
//.........这里部分代码省略.........
示例4: recursiveIndexation
/**
*
* @param AJXP_Node $node
* @param int $depth
* @throws Exception
*/
public function recursiveIndexation($node, $depth = 0)
{
$repository = $node->getRepository();
$user = $node->getUser();
$messages = ConfService::getMessages();
if ($user == null && AuthService::usersEnabled()) {
$user = AuthService::getLoggedUser();
}
if ($depth == 0) {
$this->logDebug("Starting indexation - node.index.recursive.start - " . memory_get_usage(true) . " - " . $node->getUrl());
$this->setIndexStatus("RUNNING", str_replace("%s", $node->getPath(), $messages["core.index.8"]), $repository, $user);
AJXP_Controller::applyHook("node.index.recursive.start", array($node));
} else {
if ($this->isInterruptRequired($repository, $user)) {
$this->logDebug("Interrupting indexation! - node.index.recursive.end - " . $node->getUrl());
AJXP_Controller::applyHook("node.index.recursive.end", array($node));
$this->releaseStatus($repository, $user);
throw new Exception("User interrupted");
}
}
if (!ConfService::currentContextIsCommandLine()) {
@set_time_limit(120);
}
$url = $node->getUrl();
$this->logDebug("Indexing Node parent node " . $url);
$this->setIndexStatus("RUNNING", str_replace("%s", $node->getPath(), $messages["core.index.8"]), $repository, $user);
try {
AJXP_Controller::applyHook("node.index", array($node));
} catch (Exception $e) {
$this->logDebug("Error Indexing Node " . $url . " (" . $e->getMessage() . ")");
}
$handle = opendir($url);
if ($handle !== false) {
while (($child = readdir($handle)) != false) {
if ($child[0] == ".") {
continue;
}
$childNode = new AJXP_Node(rtrim($url, "/") . "/" . $child);
$childUrl = $childNode->getUrl();
if (is_dir($childUrl)) {
$this->logDebug("Entering recursive indexation for " . $childUrl);
$this->recursiveIndexation($childNode, $depth + 1);
} else {
try {
$this->logDebug("Indexing Node " . $childUrl);
AJXP_Controller::applyHook("node.index", array($childNode));
} catch (Exception $e) {
$this->logDebug("Error Indexing Node " . $childUrl . " (" . $e->getMessage() . ")");
}
}
}
closedir($handle);
} else {
$this->logDebug("Cannot open {$url}!!");
}
if ($depth == 0) {
$this->logDebug("End indexation - node.index.recursive.end - " . memory_get_usage(true) . " - " . $node->getUrl());
$this->setIndexStatus("RUNNING", "Indexation finished, cleaning...", $repository, $user);
AJXP_Controller::applyHook("node.index.recursive.end", array($node));
$this->releaseStatus($repository, $user);
$this->logDebug("End indexation - After node.index.recursive.end - " . memory_get_usage(true) . " - " . $node->getUrl());
}
}
示例5: switchAction
public function switchAction($action, $httpVars, $postProcessData)
{
switch ($action) {
//------------------------------------
// SHARING FILE OR FOLDER
//------------------------------------
case "scheduler_runAll":
$tasks = AJXP_Utils::loadSerialFile($this->getDbFile(), false, "json");
$message = "";
$startRunning = $this->countCurrentlyRunning();
$statuses = array();
foreach ($tasks as $index => $task) {
$tasks[$index]["status"] = $this->getTaskStatus($task["task_id"]);
}
usort($tasks, array($this, "sortTasksByPriorityStatus"));
foreach ($tasks as $task) {
if (isset($task["task_id"])) {
$res = $this->runTask($task["task_id"], $task["status"], $startRunning);
if ($res) {
$message .= "Running " . $task["label"] . " \n ";
}
}
}
if (empty($message)) {
$message = "Nothing to do";
}
if (ConfService::currentContextIsCommandLine()) {
print date("Y-m-d H:i:s") . "\t" . $message . "\n";
} else {
AJXP_XMLWriter::header();
AJXP_XMLWriter::sendMessage($message, null);
AJXP_XMLWriter::reloadDataNode();
AJXP_XMLWriter::close();
}
break;
case "scheduler_runTask":
$err = -1;
$this->runTask($httpVars["task_id"], null, $err, true);
AJXP_XMLWriter::header();
AJXP_XMLWriter::reloadDataNode();
AJXP_XMLWriter::close();
break;
case "scheduler_generateCronExpression":
$phpCmd = ConfService::getCoreConf("CLI_PHP");
$rootInstall = AJXP_INSTALL_PATH . DIRECTORY_SEPARATOR . "cmd.php";
$logFile = AJXP_CACHE_DIR . DIRECTORY_SEPARATOR . "cmd_outputs" . DIRECTORY_SEPARATOR . "cron_commands.log";
$cronTiming = "*/5 * * * *";
HTMLWriter::charsetHeader("text/plain", "UTF-8");
print "{$cronTiming} {$phpCmd} {$rootInstall} -r=ajxp_conf -u=" . AuthService::getLoggedUser()->getId() . " -p=YOUR_PASSWORD_HERE -a=scheduler_runAll >> {$logFile}";
break;
default:
break;
}
}
示例6: switchAction
function switchAction($action, $httpVars, $fileVars)
{
if (!isset($this->actions[$action])) {
return;
}
$selection = new UserSelection();
$dir = $httpVars["dir"] or "";
$dir = AJXP_Utils::securePath($dir);
if ($dir == "/") {
$dir = "";
}
$selection->initFromHttpVars($httpVars);
if (!$selection->isEmpty()) {
//$this->filterUserSelectionToHidden($selection->getFiles());
}
$urlBase = "ajxp.fs://" . ConfService::getRepository()->getId();
$mess = ConfService::getMessages();
switch ($action) {
case "monitor_compression":
$percentFile = fsAccessWrapper::getRealFSReference($urlBase . $dir . "/.zip_operation_" . $httpVars["ope_id"]);
$percent = 0;
if (is_file($percentFile)) {
$percent = intval(file_get_contents($percentFile));
}
if ($percent < 100) {
AJXP_XMLWriter::header();
AJXP_XMLWriter::triggerBgAction("monitor_compression", $httpVars, $mess["powerfs.1"] . " ({$percent}%)", true, 1);
AJXP_XMLWriter::close();
} else {
@unlink($percentFile);
AJXP_XMLWriter::header();
if ($httpVars["on_end"] == "reload") {
AJXP_XMLWriter::triggerBgAction("reload_node", array(), "powerfs.2", true, 2);
} else {
$archiveName = $httpVars["archive_name"];
$jsCode = "\n \$('download_form').action = window.ajxpServerAccessPath;\n \$('download_form').secure_token.value = window.Connexion.SECURE_TOKEN;\n \$('download_form').select('input').each(function(input){\n if(input.name!='get_action' && input.name!='secure_token') input.remove();\n });\n \$('download_form').insert(new Element('input', {type:'hidden', name:'ope_id', value:'" . $httpVars["ope_id"] . "'}));\n \$('download_form').insert(new Element('input', {type:'hidden', name:'archive_name', value:'" . $archiveName . "'}));\n \$('download_form').insert(new Element('input', {type:'hidden', name:'get_action', value:'postcompress_download'}));\n \$('download_form').submit();\n ";
AJXP_XMLWriter::triggerBgJsAction($jsCode, "powerfs.3", true);
AJXP_XMLWriter::triggerBgAction("reload_node", array(), "powerfs.2", true, 2);
}
AJXP_XMLWriter::close();
}
break;
case "postcompress_download":
$archive = AJXP_Utils::getAjxpTmpDir() . "/" . $httpVars["ope_id"] . "_" . $httpVars["archive_name"];
//$fsDriver = new fsAccessDriver("fake", "");
$fsDriver = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("access");
$fsDriver->readFile($archive, "force-download", $httpVars["archive_name"], false, null, true);
break;
case "compress":
case "precompress":
if (!ConfService::currentContextIsCommandLine() && ConfService::backgroundActionsSupported()) {
$opeId = substr(md5(time()), 0, 10);
$httpVars["ope_id"] = $opeId;
AJXP_Controller::applyActionInBackground(ConfService::getRepository()->getId(), $action, $httpVars);
AJXP_XMLWriter::header();
$bgParameters = array("dir" => $dir, "archive_name" => $httpVars["archive_name"], "on_end" => isset($httpVars["on_end"]) ? $httpVars["on_end"] : "reload", "ope_id" => $opeId);
AJXP_XMLWriter::triggerBgAction("monitor_compression", $bgParameters, $mess["powerfs.1"] . " (0%)", true);
AJXP_XMLWriter::close();
session_write_close();
exit;
}
$rootDir = fsAccessWrapper::getRealFSReference($urlBase) . $dir;
$percentFile = $rootDir . "/.zip_operation_" . $httpVars["ope_id"];
$compressLocally = $action == "compress" ? true : false;
// List all files
$todo = array();
$args = array();
$replaceSearch = array($rootDir, "\\");
$replaceReplace = array("", "/");
foreach ($selection->getFiles() as $selectionFile) {
$args[] = '"' . substr($selectionFile, strlen($dir) + ($dir == "/" ? 0 : 1)) . '"';
$selectionFile = fsAccessWrapper::getRealFSReference($urlBase . $selectionFile);
$todo[] = ltrim(str_replace($replaceSearch, $replaceReplace, $selectionFile), "/");
if (is_dir($selectionFile)) {
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($selectionFile), RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $name => $object) {
$todo[] = str_replace($replaceSearch, $replaceReplace, $name);
}
}
}
$cmdSeparator = PHP_OS == "WIN32" || PHP_OS == "WINNT" || PHP_OS == "Windows" ? "&" : ";";
$archiveName = $httpVars["archive_name"];
if (!$compressLocally) {
$archiveName = AJXP_Utils::getAjxpTmpDir() . "/" . $httpVars["ope_id"] . "_" . $archiveName;
}
chdir($rootDir);
$cmd = "zip -r \"" . $archiveName . "\" " . implode(" ", $args);
$fsDriver = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("access");
$c = $fsDriver->getConfigs();
if (!isset($c["SHOW_HIDDEN_FILES"]) || $c["SHOW_HIDDEN_FILES"] == false) {
$cmd .= " -x .\\*";
}
$cmd .= " " . $cmdSeparator . " echo ZIP_FINISHED";
$proc = popen($cmd, "r");
$toks = array();
$handled = array();
$finishedEchoed = false;
while (!feof($proc)) {
set_time_limit(20);
$results = fgets($proc, 256);
//.........这里部分代码省略.........
示例7: switchAction
public function switchAction($action, $httpVars, $fileVars)
{
//AJXP_Logger::logAction("DL file", $httpVars);
$repository = ConfService::getRepository();
if (!$repository->detectStreamWrapper(false)) {
return false;
}
$plugin = AJXP_PluginsService::findPlugin("access", $repository->getAccessType());
$streamData = $plugin->detectStreamWrapper(true);
$dir = AJXP_Utils::decodeSecureMagic($httpVars["dir"]);
$destStreamURL = $streamData["protocol"] . "://" . $repository->getId() . $dir . "/";
if (isset($httpVars["file"])) {
$parts = parse_url($httpVars["file"]);
$getPath = $parts["path"];
$basename = basename($getPath);
}
if (isset($httpVars["dlfile"])) {
$dlFile = $streamData["protocol"] . "://" . $repository->getId() . AJXP_Utils::decodeSecureMagic($httpVars["dlfile"]);
$realFile = file_get_contents($dlFile);
if (empty($realFile)) {
throw new Exception("cannot find file {$dlFile} for download");
}
$parts = parse_url($realFile);
$getPath = $parts["path"];
$basename = basename($getPath);
}
switch ($action) {
case "external_download":
if (!ConfService::currentContextIsCommandLine() && ConfService::backgroundActionsSupported()) {
$unixProcess = AJXP_Controller::applyActionInBackground($repository->getId(), "external_download", $httpVars);
if ($unixProcess !== null) {
@file_put_contents($destStreamURL . "." . $basename . ".pid", $unixProcess->getPid());
}
AJXP_XMLWriter::header();
AJXP_XMLWriter::triggerBgAction("reload_node", array(), "Triggering DL ", true, 2);
AJXP_XMLWriter::close();
session_write_close();
exit;
}
require_once AJXP_BIN_FOLDER . "/class.HttpClient.php";
$mess = ConfService::getMessages();
session_write_close();
$client = new HttpClient($parts["host"]);
$collectHeaders = array("ajxp-last-redirection" => "", "content-disposition" => "", "content-length" => "");
$client->setHeadersOnly(true, $collectHeaders);
$client->setMaxRedirects(8);
$client->setDebug(false);
$client->get($getPath);
$pidHiddenFileName = $destStreamURL . "." . $basename . ".pid";
if (is_file($pidHiddenFileName)) {
$pid = file_get_contents($pidHiddenFileName);
@unlink($pidHiddenFileName);
}
AJXP_Logger::debug("COLLECTED HEADERS", $client->collectHeaders);
$collectHeaders = $client->collectHeaders;
$totalSize = -1;
if (!empty($collectHeaders["content-disposition"]) && strstr($collectHeaders["content-disposition"], "filename") !== false) {
$ar = explode("filename=", $collectHeaders["content-disposition"]);
$basename = trim(array_pop($ar));
$basename = str_replace("\"", "", $basename);
// Remove quotes
}
if (!empty($collectHeaders["content-length"])) {
$totalSize = intval($collectHeaders["content-length"]);
AJXP_Logger::debug("Should download {$totalSize} bytes!");
}
if ($totalSize != -1) {
$node = new AJXP_Node($destStreamURL . $basename);
AJXP_Controller::applyHook("node.before_create", array($node, $totalSize));
}
$qData = false;
if (!empty($collectHeaders["ajxp-last-redirection"])) {
$newParsed = parse_url($collectHeaders["ajxp-last-redirection"]);
$client->host = $newParsed["host"];
$getPath = $newParsed["path"];
if (isset($newParsed["query"])) {
$qData = parse_url($newParsed["query"]);
}
}
$tmpFilename = $destStreamURL . $basename . ".dlpart";
$hiddenFilename = $destStreamURL . "__" . $basename . ".ser";
$filename = $destStreamURL . $basename;
$dlData = array("sourceUrl" => $getPath, "totalSize" => $totalSize);
if (isset($pid)) {
$dlData["pid"] = $pid;
}
//file_put_contents($hiddenFilename, serialize($dlData));
$fpHid = fopen($hiddenFilename, "w");
fputs($fpHid, serialize($dlData));
fclose($fpHid);
$client->redirect_count = 0;
$client->setHeadersOnly(false);
$destStream = fopen($tmpFilename, "w");
if ($destStream !== false) {
$client->writeContentToStream($destStream);
$client->get($getPath, $qData);
fclose($destStream);
}
rename($tmpFilename, $filename);
unlink($hiddenFilename);
//.........这里部分代码省略.........
示例8: recursiveIndexation
public function recursiveIndexation($url)
{
//print("Indexing $url \n");
$this->logDebug("Indexing content of folder " . $url);
if (ConfService::currentContextIsCommandLine() && $this->verboseIndexation) {
print "Indexing content of " . $url . "\n";
}
@set_time_limit(60);
$handle = opendir($url);
if ($handle !== false) {
while (($child = readdir($handle)) != false) {
if ($child[0] == ".") {
continue;
}
$newUrl = $url . "/" . $child;
$this->logDebug("Indexing Node " . $newUrl);
try {
$this->updateNodeIndex(null, new AJXP_Node($newUrl));
} catch (Exception $e) {
$this->logDebug("Error Indexing Node " . $newUrl . " (" . $e->getMessage() . ")");
}
}
closedir($handle);
} else {
$this->logDebug("Cannot open {$url}!!");
}
}
示例9: switchAction
public function switchAction($action, $httpVars, $fileVars)
{
//$this->logInfo("DL file", $httpVars);
$repository = ConfService::getRepository();
if (!$repository->detectStreamWrapper(false)) {
return false;
}
$plugin = AJXP_PluginsService::findPlugin("access", $repository->getAccessType());
$streamData = $plugin->detectStreamWrapper(true);
$dir = AJXP_Utils::decodeSecureMagic($httpVars["dir"]);
$destStreamURL = $streamData["protocol"] . "://" . $repository->getId() . $dir . "/";
$dlURL = null;
if (isset($httpVars["file"])) {
$parts = parse_url($httpVars["file"]);
$getPath = $parts["path"];
$basename = basename($getPath);
$dlURL = $httpVars["file"];
}
if (isset($httpVars["dlfile"])) {
$dlFile = $streamData["protocol"] . "://" . $repository->getId() . AJXP_Utils::decodeSecureMagic($httpVars["dlfile"]);
$realFile = file_get_contents($dlFile);
if (empty($realFile)) {
throw new Exception("cannot find file {$dlFile} for download");
}
$parts = parse_url($realFile);
$getPath = $parts["path"];
$basename = basename($getPath);
$dlURL = $realFile;
}
switch ($action) {
case "external_download":
if (!ConfService::currentContextIsCommandLine() && ConfService::backgroundActionsSupported()) {
$unixProcess = AJXP_Controller::applyActionInBackground($repository->getId(), "external_download", $httpVars);
if ($unixProcess !== null) {
@file_put_contents($destStreamURL . "." . $basename . ".pid", $unixProcess->getPid());
}
AJXP_XMLWriter::header();
AJXP_XMLWriter::triggerBgAction("reload_node", array(), "Triggering DL ", true, 2);
AJXP_XMLWriter::close();
session_write_close();
exit;
}
require_once AJXP_BIN_FOLDER . "/http_class/http_class.php";
session_write_close();
$httpClient = new http_class();
$arguments = array();
$httpClient->GetRequestArguments($httpVars["file"], $arguments);
$err = $httpClient->Open($arguments);
$collectHeaders = array("ajxp-last-redirection" => "", "content-disposition" => "", "content-length" => "");
if (empty($err)) {
$err = $httpClient->SendRequest($arguments);
$httpClient->follow_redirect = true;
$pidHiddenFileName = $destStreamURL . "." . $basename . ".pid";
if (is_file($pidHiddenFileName)) {
$pid = file_get_contents($pidHiddenFileName);
@unlink($pidHiddenFileName);
}
if (empty($err)) {
$httpClient->ReadReplyHeaders($collectHeaders);
$totalSize = -1;
if (!empty($collectHeaders["content-disposition"]) && strstr($collectHeaders["content-disposition"], "filename") !== false) {
$ar = explode("filename=", $collectHeaders["content-disposition"]);
$basename = trim(array_pop($ar));
$basename = str_replace("\"", "", $basename);
// Remove quotes
}
if (!empty($collectHeaders["content-length"])) {
$totalSize = intval($collectHeaders["content-length"]);
$this->logDebug("Should download {$totalSize} bytes!");
}
if ($totalSize != -1) {
$node = new AJXP_Node($destStreamURL . $basename);
AJXP_Controller::applyHook("node.before_create", array($node, $totalSize));
}
$tmpFilename = $destStreamURL . $basename . ".dlpart";
$hiddenFilename = $destStreamURL . "__" . $basename . ".ser";
$filename = $destStreamURL . $basename;
$dlData = array("sourceUrl" => $getPath, "totalSize" => $totalSize);
if (isset($pid)) {
$dlData["pid"] = $pid;
}
//file_put_contents($hiddenFilename, serialize($dlData));
$fpHid = fopen($hiddenFilename, "w");
fputs($fpHid, serialize($dlData));
fclose($fpHid);
// NOW READ RESPONSE
$destStream = fopen($tmpFilename, "w");
while (true) {
$body = "";
$error = $httpClient->ReadReplyBody($body, 1000);
if ($error != "" || strlen($body) == 0) {
break;
}
fwrite($destStream, $body, strlen($body));
}
fclose($destStream);
rename($tmpFilename, $filename);
unlink($hiddenFilename);
}
$httpClient->Close();
//.........这里部分代码省略.........
示例10: switchAction
//.........这里部分代码省略.........
$partO = fopen($destination . "/" . $userfile_name, "r");
$appendF = fopen($destination . "/" . $appendTo, "a+");
while (!feof($partO)) {
$buf = fread($partO, 1024);
fwrite($appendF, $buf, strlen($buf));
}
fclose($partO);
fclose($appendF);
$this->logDebug("Done, closing streams!");
}
@unlink($destination . "/" . $userfile_name);
$userfile_name = $appendTo;
}
$this->changeMode($destination . "/" . $userfile_name, $repoData);
$createdNode = new AJXP_Node($destination . "/" . $userfile_name);
//AJXP_Controller::applyHook("node.change", array(null, $createdNode, false));
$logMessage .= "{$mess['34']} " . SystemTextEncoding::toUTF8($userfile_name) . " {$mess['35']} {$dir}";
$this->logInfo("Upload File", array("file" => $this->addSlugToPath(SystemTextEncoding::fromUTF8($dir)) . "/" . $userfile_name));
}
if (isset($errorMessage)) {
$this->logDebug("Return error {$errorCode} {$errorMessage}");
return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage));
} else {
$this->logDebug("Return success");
if ($already_existed) {
return array("SUCCESS" => true, "UPDATED_NODE" => $createdNode);
} else {
return array("SUCCESS" => true, "CREATED_NODE" => $createdNode);
}
}
return;
break;
case "lsync":
if (!ConfService::currentContextIsCommandLine()) {
die("This command must be accessed via CLI only.");
}
$fromNode = null;
$toNode = null;
$copyOrMove = false;
if (isset($httpVars["from"])) {
$fromNode = new AJXP_Node($this->urlBase . AJXP_Utils::decodeSecureMagic($httpVars["from"]));
}
if (isset($httpVars["to"])) {
$toNode = new AJXP_Node($this->urlBase . AJXP_Utils::decodeSecureMagic($httpVars["to"]));
}
if (isset($httpVars["copy"]) && $httpVars["copy"] == "true") {
$copyOrMove = true;
}
AJXP_Controller::applyHook("node.change", array($fromNode, $toNode, $copyOrMove));
break;
//------------------------------------
// XML LISTING
//------------------------------------
//------------------------------------
// XML LISTING
//------------------------------------
case "ls":
if (!isset($dir) || $dir == "/") {
$dir = "";
}
$lsOptions = $this->parseLsOptions(isset($httpVars["options"]) ? $httpVars["options"] : "a");
$startTime = microtime();
if (isset($httpVars["file"])) {
$uniqueFile = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
}
$dir = AJXP_Utils::securePath($dir);