public function transform($item, $parentObject, $duplicateStrategy) { $newFile = $this->getTypeForFile($item->Name); $folderPath = $parentObject->getRelativePath(); $parentId = $parentObject ? $parentObject->ID : 0; $filter = 'ParentID = \'' . Convert::raw2sql($parentId) . '\' and Title = \'' . Convert::raw2sql($item->Name) . '\''; $existing = DataObject::get_one('File', $filter); if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_SKIP) { // just return the existing children return new TransformResult($existing, null); } else { if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_OVERWRITE) { $newFile = $existing; } } // $newFile->Name = $item->Name; $newFile->Title = $item->Name; $newFile->MenuTitle = $item->Name; // $size = filesize($item->FilePath); $details = array('size' => $size, 'name' => $item->Name, 'tmp_name' => $item->FilePath); $upload = new FileLoader(); $folderPath = trim(substr($folderPath, strpos($folderPath, '/')), '/'); try { $upload->loadIntoFile($details, $newFile, $folderPath); } catch (ValidationException $ve) { // ignore for now, there should really be a proper error reporting mechanism though... SS_Log::log("File import failed: " . $ve->getMessage(), SS_Log::WARN); } return new TransformResult($newFile, null); }
/** * @test */ public function render_withoutTemplateEngine_returnString() { $this->mockedFileLoader->shouldReceive('load')->with('test', 'template')->andReturn('test {{param1}} test {{param2}} test'); $response = $this->invokeMethod('render', ['test', ['param1' => 'value1', 'param2' => 'value2']]); $this->assertInstanceOf('Neat\\Http\\Response', $response); $this->assertSame('test value1 test value2 test', $response->body); }
/** * @param string $fullJsonPath * @param bool $appendToExists * @throws Exception */ protected function loadAppsRules($fullJsonPath, $appendToExists = false) { $jsonData = $this->jsonLoader->load($fullJsonPath); $decoded = json_decode($jsonData, true); if ($appendToExists) { $decoded['apps'] = array_merge($this->apps, $decoded['apps']); } $this->apps = $decoded['apps']; }
/** * Locates a class from a namespace. * * @param string $class * @param string $namespace * * @return string|false */ public function locate($class, $namespace) { if (0 !== strpos($class, $namespace)) { return false; } $name = trim(str_replace($namespace, '', $class), '\\'); $file = str_replace('\\', DIRECTORY_SEPARATOR, $name) . '.php'; $path = parent::locate($file, $namespace); return $path; }
function _outputFileLoaderFile($matches) { $fullPath = FileLoader::load($matches[1]); if ($fullPath) { CacheHeaders($fullPath); header('Content-type: '.mime_type($fullPath)); echo file_get_contents($fullPath); exit; } _404(); }
public function transform($item, $parentObject, $duplicateStrategy) { // no children of docs $pageChildren = new DataObjectSet(); // okay, first we'll create the new page item, // and map a bunch of child information across $newPage = new File(); // write the content item to a location on disk $filename = $item->Name; $folderPath = $parentObject->getRelativePath(); // see if there's an existing one, and what we should do if there is $parentId = $parentObject ? $parentObject->ID : 0; // Use the title, because SS sometimes converts filenames $filter = 'ParentID = \'' . Convert::raw2sql($parentId) . '\' and Title = \'' . Convert::raw2sql($filename) . '\''; $existing = DataObject::get_one('File', $filter); if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_SKIP) { // just return the existing children return new TransformResult($existing, $pageChildren); } else { if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_OVERWRITE) { $newPage = $existing; } } $folderPath = trim(substr($folderPath, strpos($folderPath, '/')), '/'); // write it to a cache directory first $path = $this->getCacheDir(); $item->streamContent($path . '/' . $filename); $size = filesize($path . '/' . $filename); $details = array('size' => $size, 'name' => $item->Name, 'tmp_name' => $path . '/' . $filename); $newPage->Name = $item->Name; $newPage->Title = $item->Title; $newPage->MenuTitle = $item->MenuTitle; // what else should we map across? // $newPage->MatrixId = $item->id; // $newPage->OriginalProperties = serialize($item->getRemoteProperties()); $upload = new FileLoader(); $upload->loadIntoFile($details, $newPage, $folderPath); return new TransformResult($newPage, $pageChildren); }
/** * Constructor. * @param $argv array task arguments */ function UsageStatsLoader($args) { parent::FileLoader($args); $this->_geoLocationTool = new GeoLocationTool(); $plugin = PluginRegistry::getPlugin('generic', 'usagestatsplugin'); // Load the metric type constant. PluginRegistry::loadCategory('reports'); $this->_plugin = $plugin; $this->_plugin->import('UsageStatsTemporaryRecordDAO'); $statsDao = new UsageStatsTemporaryRecordDAO(); DAORegistry::registerDAO('UsageStatsTemporaryRecordDAO', $statsDao); $this->_counterRobotsListFile = $this->_getCounterRobotListFile(); $journalDao = DAORegistry::getDAO('JournalDAO'); /* @var $journalDao JournalDAO */ $journalFactory = $journalDao->getAll(); /* @var $journalFactory DAOResultFactory */ $journalsByPath = array(); while ($journal = $journalFactory->next()) { /* @var $journal Journal */ $journalsByPath[$journal->getPath()] = $journal; } $this->_journalsByPath = $journalsByPath; $this->checkFolderStructure(true); }
public function __construct(FileLoader $loader, $jsonFilePath) { $json = json_decode($loader->load($jsonFilePath), true); $this->categories = $json['categories']; }
/** * @copydoc FileLoader::executeActions() */ protected function executeActions() { $plugin = $this->_plugin; if (!$plugin->getEnabled()) { $this->addExecutionLogEntry(__('plugins.generic.usageStats.pluginNotEnabled'), SCHEDULED_TASK_MESSAGE_TYPE_WARNING); return false; } if (!$this->_counterRobotsListFile || !file_exists($this->_counterRobotsListFile)) { $this->addExecutionLogEntry(__('plugins.generic.usageStats.noCounterBotList', array('botlist' => $this->_counterRobotsListFile)), SCHEDULED_TASK_MESSAGE_TYPE_WARNING); return false; } return parent::executeActions(); }
/** * @see FileLoader::executeActions() */ function executeActions() { $plugin =& $this->_plugin; if (!$plugin->getEnabled()) { $this->addExecutionLogEntry(__('plugins.generic.usageStats.openFileFailed'), SCHEDULED_TASK_MESSAGE_TYPE_WARNING); return true; } parent::executeActions(); }
/** * @see FileLoader::executeActions() */ function executeActions() { $plugin =& $this->_plugin; if (!$plugin->getEnabled()) { $this->addExecutionLogEntry(__('plugins.generic.usageStats.pluginDisabled'), SCHEDULED_TASK_MESSAGE_TYPE_WARNING); return true; } // It's possible that the processing directory has files that // were being processed but the php process was stopped before // finishing the processing, or there may be a concurrent process running. // Warn the user if this is the case. $processingDirFiles = glob($this->getProcessingPath() . DIRECTORY_SEPARATOR . '*'); $processingDirError = is_array($processingDirFiles) && count($processingDirFiles); if ($processingDirError) { $this->addExecutionLogEntry(__('plugins.generic.usageStats.processingPathNotEmpty', array('directory' => $this->getProcessingPath())), SCHEDULED_TASK_MESSAGE_TYPE_ERROR); } if ($this->_autoStage) { $this->autoStage(); } return parent::executeActions() && !$processingDirError; }
protected static function getPartsForMatches($matches) { $urlSuffix = html_entity_decode($matches[3]); $file = self::$currentInstance->urlSuffixToFile($urlSuffix); if (strpos($matches[0], '/' . FileLoader::fileDir() . '/') !== FALSE) { $file = ''; // do not rewrite fileloader urls $replacement = $matches[0]; } else { if ($file) { $replacement = $matches[1] . $file . $matches[4]; } else { Kurogo::log(LOG_NOTICE, "Unable to determine file name for '{$matches[0]}'", 'api'); $replacement = $matches[0]; } } return array($urlSuffix, $file, $replacement); }
/** * @covers Zepto\FileLoader::get_folder_contents() * @expectedException UnexpectedValueException */ public function testGetFolderContentsWithInvalidDir() { $actual = $this->loader->get_folder_contents('non-existent'); $expected = array('404.md' => '404.md', 'index.md' => 'index.md', 'sub/index.md' => 'sub/index.md', 'sub/page.md' => 'sub/page.md'); $this->assertEquals($expected, $actual); }
/** * Constructor. * * Set up a file loader for Carbon Core classes and files. */ public function __construct() { parent::__construct(CARBON_CORE_NAMESPACE, CARBON_CORE_ROOT); }
public function testGlobalVariablesInLoadedFileAppearInGlobalScope() { $this->assertTrue(!isset($GLOBALS['testVar'])); // BIG FAT NOTE: // // We *have* to load a different class here, because DummyClass1 // has already been loaded, and cannot be loaded again $fileLoader = new FileLoader(); $newClasses = $fileLoader->loadPhpFile(__DIR__ . '/DummyClass2.php'); $this->assertTrue(isset($GLOBALS['testVar'])); $this->assertEquals('trout', $GLOBALS['testVar']); }
public static function loadClassByName($className) { return FileLoader::load($className); }
/** * 缓存获取与设置结束,存入文件或者内存 * @param null $cacheTime * @return bool */ public function cacheSave($cacheTime = null) { if (isset($cacheTime) && !empty($cacheTime)) { $this->setCacheTime($cacheTime); } if ($this->ifGetByEcho) { // 获取输出缓冲数据 $this->cacheContent = ob_get_contents(); ob_end_flush(); } // 更新内存中的缓存信息 $this->cacheInfo[$this->cacheDigest]['expiredTime'] = $this->cacheTime; $this->cacheInfo[$this->cacheDigest]['expiredDateTime'] = date("Y-m-d H:i:s", $this->cacheTime); $ifSave = false; // 缓存文件地址 $cacheContentFile = new FileLoader(PathGeneration::getFolder("{$this->cachePath}{$this->cacheId}") . "{$this->cacheDigest}.tmp", array("mode" => "write")); $cacheInfoFile = new FileLoader("{$this->cachePath}{$this->cacheId}_info.tmp", array("mode" => "write")); if ($cacheInfoFile->isWritable()) { if ($cacheContentFile->isWritable()) { $cacheInfoFile->write(json_encode($this->cacheInfo)); $cacheContentFile->write($this->cacheContent); $cacheContentFile->close(); $ifSave = true; } $cacheInfoFile->close(); } return $ifSave; }
/** * Constructor. * @param $argv array task arguments */ function PKPUsageStatsLoader($args) { $plugin = PluginRegistry::getPlugin('generic', 'usagestatsplugin'); /* @var $plugin UsageStatsPlugin */ $this->_plugin = $plugin; $arg = current($args); switch ($arg) { case 'autoStage': if ($plugin->getSetting(0, 'createLogFiles')) { $this->_autoStage = true; } break; case 'externalLogFiles': $this->_externalLogFiles = true; break; } // Define the base filesystem path. $args[0] = $plugin->getFilesPath(); parent::FileLoader($args); $this->_baseSystemUrl = Config::getVar('general', 'base_url'); $this->_baseSystemEscapedPath = str_replace('/', '\\/', parse_url($this->_baseSystemUrl, PHP_URL_PATH)); // Load the metric type constant. PluginRegistry::loadCategory('reports'); import('classes.statistics.StatisticsHelper'); $statsHelper = new StatisticsHelper(); $geoLocationTool = $statsHelper->getGeoLocationTool(); $this->_geoLocationTool = $geoLocationTool; $plugin->import('UsageStatsTemporaryRecordDAO'); $statsDao = new UsageStatsTemporaryRecordDAO(); DAORegistry::registerDAO('UsageStatsTemporaryRecordDAO', $statsDao); $this->_counterRobotsListFile = $this->_getCounterRobotListFile(); $contextDao = Application::getContextDAO(); /* @var $contextDao ContextDAO */ $contextFactory = $contextDao->getAll(); /* @var $contextFactory DAOResultFactory */ $contextsByPath = array(); while ($context = $contextFactory->next()) { /* @var $context Context */ $contextsByPath[$context->getPath()] = $context; } $this->_contextsByPath = $contextsByPath; $this->checkFolderStructure(true); if ($this->_autoStage) { // Copy all log files to stage directory, except the current day one. $fileMgr = new FileManager(); $logsDirFiles = glob($plugin->getUsageEventLogsPath() . DIRECTORY_SEPARATOR . '*'); $processingDirFiles = glob($this->getProcessingPath() . DIRECTORY_SEPARATOR . '*'); if (is_array($logsDirFiles) && is_array($processingDirFiles)) { // It's possible that the processing directory have files that // were being processed but the php process was stopped before // finishing the processing. Just copy them to the stage directory too. $dirFiles = array_merge($logsDirFiles, $processingDirFiles); foreach ($dirFiles as $filePath) { // Make sure it's a file. if ($fileMgr->fileExists($filePath)) { // Avoid current day file. $filename = pathinfo($filePath, PATHINFO_BASENAME); $currentDayFilename = $plugin->getUsageEventCurrentDayLogName(); if ($filename == $currentDayFilename) { continue; } if ($fileMgr->copyFile($filePath, $this->getStagePath() . DIRECTORY_SEPARATOR . $filename)) { $fileMgr->deleteFile($filePath); } } } } } }
function _outputFileLoaderFile($matches) { _outputFile(FileLoader::load($matches[1])); }
<?php /** * Created by IntelliJ IDEA. * User: Voww * Date: 16.12.2015 * Time: 10:35 */ set_include_path("C:/wamp/www/testserver.int/imsmedia/"); include_once "parser/xml_parser/XMLParser.php"; include_once "loader/file_loader/FileLoader.php"; include_once "IMSMediaHeader.html"; $parser = new XMLParser(); $loader = new FileLoader(); $output = '<a href="/imsmedia/Import.html"><button>Back</button></a><hr>'; try { $uploadFileName = $loader->load(); $output .= "A file was imported succesfully<br>"; $content = file_get_contents($uploadFileName); $parser->parse($content); $currencies = $parser->parseCurrencies(); $measurements = $parser->parseMeasurements(); $categories = $parser->parseCategories(); $products = $parser->parseProducts(); AbstractDAO::closeConnection(); $output .= "<h2>Measurements</h2>"; $output .= nl2br($measurements); $output .= "<h2>Currencies</h2>"; $output .= nl2br($currencies); $output .= "<h2>Categories</h2>"; $output .= nl2br($categories);
public function processFileRequest($extension) { if (self::isSystemFolderRequest()) { $part = explode('/', $this->uri); $path = (string) ''; $type = $part[0]; unset($part[0]); // remove uri keyword switch ($type) { case URI_FILE_KEYWORD: $path = RESOURCE_PATH . '/data/files'; break; case URI_MODULE_KEYWORD: $path = ABS_PATH . '/modules/' . $part[1]; unset($part[1]); // remove modulename break; } $file = $path . '/' . implode('/', $part); } else { $file = array(RESOURCE_PATH . '/data/pres/template/source/' . $extension . '/' . $this->uri, PRESET_PATH . '/source/' . $extension . '/' . $this->uri); } // load and display requested file $FileLoader = new FileLoader($this->res); $FileLoader->getFile($file); // end function }