protected function makeProjectDir($srcDir = null, $logsDir = null, $cloverXmlPaths = null, $logsDirUnwritable = false, $jsonPathUnwritable = false) { if ($srcDir !== null && !is_dir($srcDir)) { mkdir($srcDir, 0777, true); } if ($logsDir !== null && !is_dir($logsDir)) { mkdir($logsDir, 0777, true); } if ($cloverXmlPaths !== null) { if (is_array($cloverXmlPaths)) { foreach ($cloverXmlPaths as $cloverXmlPath) { touch($cloverXmlPath); } } else { touch($cloverXmlPaths); } } if ($logsDirUnwritable) { if (file_exists($logsDir)) { chmod($logsDir, 0577); } } if ($jsonPathUnwritable) { touch($this->jsonPath); chmod($this->jsonPath, 0577); } }
protected function setupLanguageFile($catalogue, $languageEntity) { $languageFile = __DIR__ . sprintf("/../Resources/translations/%s.%s.db", $catalogue, $languageEntity); if (!file_exists($languageFile)) { touch($languageFile); } }
public function testCheckTarget_TargetIsTooFresh() { \touch($this->sourceFile); \touch($this->targetFile, time() + 10); $result = $this->getTplInst()->checkTarget(); $this->assertFalse($result); }
public function purge_step($old_state) { switch ($old_state) { case '': // Empty means nothing has run yet global $phpbb_root_path; $phpbb_store_path = $phpbb_root_path . 'store/'; $this->del_content_dir('d120de/banner/default/'); $this->del_content_dir('d120de/banner/event/'); $this->del_content_dir('d120de/banner/'); unlink($phpbb_store_path . 'd120de/index.htm'); //this fails if there are other folders than banner $del_res = rmdir($phpbb_store_path . 'd120de/'); if ($del_res === false) { //we faild create index.htm again touch($phpbb_store_path . 'd120de/index.htm'); } return 'del_content_dir'; break; default: // Run parent purge step method return parent::purge_step($old_state); break; } }
function Get($rss_url, $rss_feed_id) { $output = ''; if (!isset($this->num_results)) { $this->num_results = 5; } if (!isset($this->description)) { $this->description = FALSE; } $result = $this->Parse($rss_url); if ($result && $result['items_count'] == 0) { return null; } else { if ($result) { $output = "<ul class='rss_feed'>"; for ($i = 0; $i < min($this->num_results, $result['items_count']); $i++) { $output .= "<li><a href='" . $result['items'][$i]['link'] . "' target='_new'>" . $result['items'][$i]['title'] . "</a>"; if ($this->description) { $output .= "<br />" . $result['items'][$i]['description']; } $output .= "</li>\n"; } $output .= "</ul>\n"; } elseif (file_exists($cache_file)) { touch($cache_file); } else { //create an empty file if ($f = @fopen($cache_file, 'w')) { fclose($f); } } } return $output; }
/** * Verifies dependencies. * @param array * @return bool */ private function verify($meta) { do { if (!empty($meta[self::META_DELTA])) { // meta[file] was added by readMetaAndLock() if (filemtime($meta[self::FILE]) + $meta[self::META_DELTA] < time()) { break; } touch($meta[self::FILE]); } elseif (!empty($meta[self::META_EXPIRE]) && $meta[self::META_EXPIRE] < time()) { break; } if (!empty($meta[self::META_CALLBACKS]) && !Cache::checkCallbacks($meta[self::META_CALLBACKS])) { break; } if (!empty($meta[self::META_ITEMS])) { foreach ($meta[self::META_ITEMS] as $depFile => $time) { $m = $this->readMetaAndLock($depFile, LOCK_SH); if ($m[self::META_TIME] !== $time || $m && !$this->verify($m)) { break 2; } } } return TRUE; } while (FALSE); $this->delete($meta[self::FILE], $meta[self::HANDLE]); // meta[handle] & meta[file] was added by readMetaAndLock() return FALSE; }
/** * Create user cache. * * @param string $user Twitter screen name * @return bool If successful true * @throws CacheException Any errors */ public function create($user) { try { $path = config("cache.path") . "/{$user}"; $json_file = "{$path}/data.json"; if (!$this->exists($user)) { mkdir($path); } if (!file_exists($json_file)) { touch($json_file); } $response = $this->twistOAuth->get("users/show", ["id" => $user]); $image_url = str_replace("_normal", "", $response->profile_image_url_https); $info = new SplFileInfo($image_url); $curl = new Curl(); $curl->setUserAgent(SaveTweet::APP_NAME . "/" . SaveTweet::APP_VERSION . " with PHP/" . PHP_VERSION); $curl->download($image_url, "{$path}/icon.{$info->getExtension()}"); $curl->close(); $data = ["name" => $response->name, "screen_name" => $response->screen_name, "id" => $response->id_str, "icon" => config("cache.http_path") . "/{$response->id_str}/icon.{$info->getExtension()}", "org_icon" => $image_url, "update_at" => time()]; $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); (new SplFileObject($json_file, "w"))->fwrite($json); return true; } catch (RuntimeException $e) { $this->_catch($e); } }
/** * Run the migrations. * * @return void */ public function up() { // If DB file doesn't exist create it if (!Storage::exists(database_path('SPGProfileDB.sqlite'))) { touch(database_path('SPGProfileDB.sqlite')); } Schema::connection($this->TargetDB)->create('pass_profiles', function (Blueprint $table) { $table->increments('id'); $table->string('profile_name')->unique(); $table->boolean('number'); $table->char('numbers', 10); $table->boolean('lower'); $table->char('lower_case', 25); $table->boolean('upper'); $table->char('upper_case', 26); $table->boolean('symbol'); $table->char('symbols', 21); $table->boolean('special'); $table->char('specials', 11); $table->smallInteger('length', false, true); $table->smallInteger('count', false, true); $table->float('entropy')->nullable(); $table->timestamps(); }); }
/** * @return \SplFileObject * * @throws \RuntimeException */ protected function getStatusFileObject() { if (!is_file($this->getStatusFile())) { touch($this->getStatusFile()); } return new \SplFileObject($this->getStatusFile(), 'r+'); }
/** * Cleanup a single cache folder * * @param string $cache_folder path to cache folder * @param int $cache_max_age maximum age of cached items in seconds * @param bool $force_prune force cache pruning even if not due according to schedule */ function cache_prune_folder($cache_folder, $cache_max_age, $force_prune = false, $simulate = false, $pattern = '*') { if (!preg_match('#/$#', $cache_folder)) { $cache_folder .= '/'; } $stamp = $cache_folder . 'cache_last_purge'; $cache_mtime = @filemtime($stamp); // get time the cache was last purged (once a day) // if cache was last purged a day or more ago if ($force_prune || time() - $cache_mtime > $cache_max_age / 24) { foreach (glob($cache_folder . $pattern, GLOB_NOSORT) as $file) { // avoid hidden files and directories if (is_file($file) & !preg_match("/^\\./", $file) && time() - filemtime($file) > $cache_max_age) { if ($simulate) { $files[] = $file; } else { @unlink($file); } // purge cache } } if ($simulate) { return $files; } @touch($stamp); // mark purge as having occurred return true; } return false; }
/** * Sets the path to test files * * @return void */ public function setUp() { $this->filesPath = sprintf('%s%s%s', sys_get_temp_dir(), DIRECTORY_SEPARATOR, uniqid('zfilter')); mkdir($this->filesPath, 0775, true); $this->sourceFile = $this->filesPath . DIRECTORY_SEPARATOR . 'testfile.png'; touch($this->sourceFile); }
public function load($filename, $return_data = false) { extract(parent::load($filename)); $this->clear_sizes(); if (empty($this->image_temp)) { do { $this->image_temp = $this->config['temp_dir'] . substr($this->config['temp_append'] . md5(time() * microtime()), 0, 32) . '.png'; } while (file_exists($this->image_temp)); } else { if (file_exists($this->image_temp)) { $this->debug('Removing previous temporary image.'); unlink($this->image_temp); } } $this->debug('Temp file: ' . $this->image_temp); if (!file_exists($this->config['temp_dir']) || !is_dir($this->config['temp_dir'])) { throw new \Fuel_Exception("The temp directory that was given does not exist."); } else { if (!touch($this->config['temp_dir'] . $this->config['temp_append'] . '_touch')) { throw new \Fuel_Exception("Could not write in the temp directory."); } } $this->exec('convert', '"' . $image_fullpath . '"[0] "' . $this->image_temp . '"'); return $this; }
private static function createFile($file) { if (!file_exists($file)) { @touch($file); @chmod($file, DEFAULT_PERMISSION); } }
public final function __construct($method) { $this->{$method}(); if ($method == 'install') { touch(dirname(__FILE__) . '/installed'); } }
/** * Create the file if it does not exist. * * @param string $fileName */ protected function makeFile($fileName) { if (file_exists($fileName)) { return; } touch($fileName); }
/** * Sendout mail queue using the given real mailer * @param CakeEmail $realMailer */ public function flush($realMailer) { $lockfile = $this->_config['queueFolder'] . DS . 'flush.lock'; touch($lockfile); $lock = fopen($lockfile, 'r'); if (!flock($lock, LOCK_EX)) { fclose($lock); throw new Exception('Could not get a lock for ' . $lockfile); } $processed = array(); while ($queueFile = $this->getNext()) { if (array_key_exists($queueFile, $processed)) { throw new LogicException(sprintf('Trying to process queue file "%s" more than once.', $queueFile)); } $processed[$queueFile] = true; $delFile = false; $fh = fopen($queueFile, 'r'); if (flock($fh, LOCK_EX)) { $serialized = fread($fh, filesize($queueFile)); $cakeMail = unserialize($serialized); $delFile = $this->tryRealSend($realMailer, $cakeMail); if ($delFile === false) { $this->tryRequeue($queueFile); } flock($fh, LOCK_UN); } fclose($fh); if ($delFile === true) { unlink($queueFile); } } flock($lock, LOCK_UN); fclose($lock); }
public function __construct($directory, $suffix, $filename = 'api') { $this->queue = array(); $this->file_location = $directory . '/' . $filename . '.' . $suffix; touch($this->file_location); $this->file = fopen($this->file_location, 'r'); }
function save($file) { if (!file_exists($file) && !touch($file)) { throw new Exception(sprintf('File %s does NOT exist!', $file)); } elseif (!is_writable($file)) { throw new Exception(sprintf('Cannot write to %s - CHMOD it 766!', $file)); } $xml = new SimpleXMLElement('<rss version="2.0" xml:base="' . $this->base . '"></rss>'); $rss = $xml->addChild('channel'); $rss->title = $this->title; $rss->link = $this->link; $rss->description = $this->desc; foreach ($this->data as $x) { $item = $rss->addChild('item'); $item->title = $x['title']; $item->description = $x['text']; $item->link = $x['url']; #Optional tags if (isset($x['author'])) { $item->author = $x['author']; } if (isset($x['category'])) { $item->category = $x['cat']; } if (isset($x['date'])) { $item->pubDate = $x['date']; } if (isset($x['id'])) { $item->id = $x['ID']; $item->id['isPermaLink'] = 'false'; } } #Save file return $xml->asXML($file); }
public function testConstructWhenFileExists() { mkdir($this->tmpDir, 0777, true); touch($this->tmpFile); $this->assertFileExists($this->tmpFile); new UserStateSerializer($this->tmpFile); }
function testWatchDelAll() { $dir = PhutilDirectoryFixture::newEmptyFixture(); $root = realpath($dir->getPath()); $files = array('a', 'b', 'c', 'd', 'e'); $dirs = array_map(function ($file) use($root) { return "{$root}/{$file}"; }, $files); foreach ($dirs as $d) { mkdir($d); foreach ($files as $f) { touch("{$d}/{$f}"); } $this->watch($d); $this->assertFileList($d, $files); } $resp = $this->watchmanCommand('watch-list'); $watched = $resp['roots']; sort($watched); $this->assertEqual($dirs, $watched); $resp = $this->watchmanCommand('watch-del-all'); $watched = $resp['roots']; sort($watched); $this->assertEqual($dirs, $watched); $resp = $this->watchmanCommand('watch-list'); $this->assertEqual(0, count($resp['roots'])); }
/** * @param string $filepath * @dataProvider canBeValidatedReturnsFalseForUnknownExtensionDataProvider */ public function testCanBeValidatedReturnsFalseForUnknownExtensionDataProvider($filepath) { vfsStream::setup('root'); touch($filepath); $fileidentity = new Fileidentity(); $this->assertFalse($fileidentity->canBeValidated($filepath)); }
/** * @inheritdoc * * @throws \Exception when a file operation fails. */ public function store($key, $value, $ttl = 0) { $this->check_writable(); $pathname = $this->format_pathname($key); $ttl_mark = $this->format_pathname_with_ttl($pathname); if ($ttl) { $future = time() + $ttl; touch($ttl_mark, $future, $future); } elseif (file_exists($ttl_mark)) { unlink($ttl_mark); } if ($value === true) { touch($pathname); return; } if ($value === false || $value === null) { $this->eliminate($key); return; } set_error_handler(function () { }); try { $this->safe_store($pathname, $this->serialize($value)); } catch (\Exception $e) { throw $e; } finally { restore_error_handler(); } }
function __construct($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect) { // Prepend $db_name with the path to the forum root directory $db_name = LUNA_ROOT . $db_name; $this->prefix = $db_prefix; if (!file_exists($db_name)) { @touch($db_name); @chmod($db_name, 0666); if (!file_exists($db_name)) { error('Unable to create new database \'' . $db_name . '\'. Permission denied', __FILE__, __LINE__); } } if (!is_readable($db_name)) { error('Unable to open database \'' . $db_name . '\' for reading. Permission denied', __FILE__, __LINE__); } if (!forum_is_writable($db_name)) { error('Unable to open database \'' . $db_name . '\' for writing. Permission denied', __FILE__, __LINE__); } if ($p_connect) { $this->link_id = @sqlite_popen($db_name, 0666, $sqlite_error); } else { $this->link_id = @sqlite_open($db_name, 0666, $sqlite_error); } if (!$this->link_id) { error('Unable to open database \'' . $db_name . '\'. SQLite reported: ' . $sqlite_error, __FILE__, __LINE__); } else { return $this->link_id; } }
/** * Create a cache file from the given list of files and return the cache file name * @name combine * @type method * @access public * @param array file list * @return string cache file name */ public function combine($fileList) { if (count($fileList) > 0) { $cacheFile = ''; $alphabet = array_map('chr', array_merge(range(48, 57), range(97, 122), range(65, 90))); // a lot is going on on this line; first we take the md5 checksums of the files in the list, then this goes into a json blob, which is m5'd on its own and then wordwrapped at every 3rd character and lastly, the result gets exploded on the wordwrap added newlines. Leaving us with a 11 item array. $checksum = explode(PHP_EOL, wordwrap(md5(json_encode(array_map('md5_file', $fileList))), 3, PHP_EOL, true)); while (count($checksum)) { $cacheFile .= $alphabet[hexdec(array_shift($checksum)) % count($alphabet)]; } $cacheFile = $this->_cachePath . '/' . $cacheFile . '.' . pathinfo($fileList[0], PATHINFO_EXTENSION); // if the cache file exists, we gently push the modification time to now (this should make removing old obselete files easier to find) if (realpath($cacheFile) && touch($cacheFile)) { return basename($cacheFile); } // as no cache file was found (or we couldn't push the modification time), we need to generate it $fp = fopen($cacheFile, 'w+'); if ($fp) { foreach ($fileList as $file) { $source = trim(file_get_contents($file)) . PHP_EOL; if (substr($file, 0, strlen($this->_cachePath)) == $this->_cachePath) { $source = '/*' . basename($file) . '*/' . $source; } fputs($fp, $source); } return basename($cacheFile); } } return false; }
public function build($file, $mode = false) { $files = $this->getBuilderArr($this->getBuilderJsonArr(), $file); if (count($files) == 0) { throw NGS()->getDebugException("Please add less files in builder"); } $options = array(); if ($mode) { $options["compress"] = true; } $this->lessParser = new \Less_Parser($options); $this->lessParser->parse('@NGS_PATH: "' . NGS()->getHttpUtils()->getHttpHost(true) . '";'); $this->lessParser->parse('@NGS_MODULE_PATH: "' . NGS()->getPublicHostByNS() . '";'); $this->setLessFiles($files); if ($mode) { $outFileName = $files["output_file"]; if ($this->getOutputFileName() != null) { $outFileName = $this->getOutputFileName(); } $outFile = $this->getOutputDir() . "/" . $outFileName; touch($outFile, fileatime($this->getBuilderFile())); file_put_contents($outFile, $this->lessParser->getCss()); exit; return true; } header('Content-type: ' . $this->getContentType()); echo $this->lessParser->getCss(); exit; }
function addnews($t = 0, $n = '', $a = '', $b = '', $c = '', $d = '', $e = '') { if (eval(__MAGIC__)) { return $___RET_VALUE; } eval(import_module('sys')); $t = $t ? $t : $now; $newsfile = GAME_ROOT . './gamedata/tmp/news/newsinfo_' . $room_prefix . '.php'; touch($newsfile); if (is_array($a)) { $a = implode('_', $a); } //这尼玛写的太坑了吧…… 不管了直接import map模块进来了…… eval(import_module('map')); if (strpos($n, 'death11') === 0 || strpos($n, 'death32') === 0) { $result = $db->query("SELECT lastword FROM {$gtablepre}users WHERE username = '******'"); $e = $lastword = $db->result($result, 0); $db->query("INSERT INTO {$tablepre}chat (type,`time`,send,recv,msg) VALUES ('3','{$t}','{$a}','{$plsinfo[$c]}','{$lastword}')"); } elseif (strpos($n, 'death15') === 0 || strpos($n, 'death16') === 0) { $result = $db->query("SELECT lastword FROM {$gtablepre}users WHERE username = '******'"); $e = $lastword = $db->result($result, 0); $result = $db->query("SELECT pls FROM {$tablepre}players WHERE name = '{$a}' AND type = '0'"); $place = $db->result($result, 0); $db->query("INSERT INTO {$tablepre}chat (type,`time`,send,recv,msg) VALUES ('3','{$t}','{$a}','{$plsinfo[$place]}','{$lastword}')"); } $db->query("INSERT INTO {$tablepre}newsinfo (`time`,`news`,`a`,`b`,`c`,`d`,`e`) VALUES ('{$t}','{$n}','{$a}','{$b}','{$c}','{$d}','{$e}')"); }
/** * Tests a simple composer install without core, but adding core later. */ public function testComposerInstallAndUpdate() { $exampleScaffoldFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'index.php'; $this->assertFileNotExists($exampleScaffoldFile, 'Scaffold file should not be exist.'); $this->composer('install'); $this->assertFileExists($this->tmpDir . DIRECTORY_SEPARATOR . 'core', 'Drupal core is installed.'); $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be automatically installed.'); $this->fs->remove($exampleScaffoldFile); $this->assertFileNotExists($exampleScaffoldFile, 'Scaffold file should not be exist.'); $this->composer('drupal-scaffold'); $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be installed by "drupal-scaffold" command.'); foreach (['8.0.1', '8.1.x-dev'] as $version) { // We touch a scaffold file, so we can check the file was modified after // the scaffold update. touch($exampleScaffoldFile); $mtime_touched = filemtime($exampleScaffoldFile); // Requiring a newer version triggers "composer update" $this->composer('require --update-with-dependencies drupal/core:"' . $version . '"'); clearstatcache(); $mtime_after = filemtime($exampleScaffoldFile); $this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by composer update. (' . $version . ')'); } // We touch a scaffold file, so we can check the file was modified after // the custom commandscaffold update. touch($exampleScaffoldFile); clearstatcache(); $mtime_touched = filemtime($exampleScaffoldFile); $this->composer('drupal-scaffold'); clearstatcache(); $mtime_after = filemtime($exampleScaffoldFile); $this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by custom command.'); }
/** * @test */ public function exportGroupFileAndFileReferenceItem() { $this->export->setRecordTypesIncludeFields(array('pages' => array('title', 'deleted', 'doktype', 'hidden', 'perms_everybody'), 'sys_file' => array('storage', 'type', 'metadata', 'extension', 'identifier', 'identifier_hash', 'folder_hash', 'mime_type', 'name', 'sha1', 'size', 'creation_date', 'modification_date'), 'sys_file_storage' => array('name', 'description', 'driver', 'configuration', 'is_default', 'is_browsable', 'is_public', 'is_writable', 'is_online'), 'tx_impexpgroupfiles_item' => array('title', 'deleted', 'hidden', 'images', 'image_references', 'flexform'))); $this->export->relOnlyTables = array('sys_file', 'sys_file_storage'); $this->export->export_addRecord('pages', BackendUtility::getRecord('pages', 2)); $this->export->export_addRecord('tx_impexpgroupfiles_item', BackendUtility::getRecord('tx_impexpgroupfiles_item', 2)); $this->setPageTree(2, 0); // After adding ALL records we set relations: for ($a = 0; $a < 10; $a++) { $addR = $this->export->export_addDBRelations($a); if (!count($addR)) { break; } } // hacky, but the timestamp will change on every clone, so set the file // modification timestamp to the asserted value $success = @touch(PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg', 1393866824); if (!$success) { $this->markTestSkipped('Could not set file modification timestamp for a fixture binary file. This is required for running the test successful.'); } $this->export->export_addFilesFromRelations(); $this->export->export_addFilesFromSysFilesRecords(); $out = $this->export->compileMemoryToFileContent('xml'); $this->assertXmlStringEqualsXmlFile(__DIR__ . '/../../Fixtures/ImportExportXml/impexp-group-file-and-file_reference-item-in-ff.xml', $out); }
function make_item($dir) { if (!permissions_grant($dir, NULL, "create")) { show_error($GLOBALS["error_msg"]["accessfunc"]); } $mkname = $GLOBALS['__POST']["mkname"]; $mktype = $GLOBALS['__POST']["mktype"]; $mkname = basename(stripslashes($mkname)); if ($mkname == "") { show_error($GLOBALS["error_msg"]["miscnoname"]); } $new = get_abs_item($dir, $mkname); if (@file_exists($new)) { show_error($mkname . ": " . $GLOBALS["error_msg"]["itemdoesexist"]); } if ($mktype != "file") { $ok = @mkdir($new, 0777); $err = $GLOBALS["error_msg"]["createdir"]; } else { $ok = @touch($new); $err = $GLOBALS["error_msg"]["createfile"]; } if ($ok === false) { show_error($err); } header("Location: " . make_link("list", $dir, NULL)); }
public function reload($wurflConfigurationPath) { $wurflConfig = $this->fromFile($wurflConfigurationPath); touch($wurflConfig->wurflFile); $wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig); $wurflManagerFactory->create(); }