function testRandomFromFolderWithFoldersNoMtime() { $count = 0; $another_count = 0; $css_count = 0; $ext_count = 0; $test_count = 0; for ($i = 0; $i < 30; $i++) { $result = FileUtils::randomFromFolder("/" . FRAMEWORK_CORE_PATH . "tests/io/test_dir/content_dir/", false, true); $this->assertNotNull($result); if ($result == "/" . FRAMEWORK_CORE_PATH . "tests/io/test_dir/content_dir/another_dir/") { $another_count += 1; } if ($result == "/" . FRAMEWORK_CORE_PATH . "tests/io/test_dir/content_dir/css_test.css") { $css_count += 1; } if ($result == "/" . FRAMEWORK_CORE_PATH . "tests/io/test_dir/content_dir/ext_test.plug.txt") { $ext_count += 1; } if ($result == "/" . FRAMEWORK_CORE_PATH . "tests/io/test_dir/content_dir/test_file.txt") { $test_count += 1; } $sum = $another_count + $css_count + $ext_count + $test_count; $this->assertTrue($count == $sum - 1); $count += 1; } }
public function after_create() { UserMailer::deliver_new_user($this->email, $this); $path = FileUtils::join(NIMBLE_ROOT, 'get', $this->username); FileUtils::mkdir_p($path); chmod($path, 0755); }
protected static function clearCacheDir($path) { if (is_dir($path)) { return FileUtils::rrmdir($path); } return true; }
public static function loadDir($path) { $files = FileUtils::getFilesForDirectory($path); foreach ($files as $file) { self::loadFile($path . DIRECTORY_SEPARATOR . $file); } }
protected function __construct() { $this->array = ArrayUtils::instance(); $this->file = FileUtils::instance(); $this->object = ObjectUtils::instance(); $this->string = StringUtils::instance(); }
function uploadWare($file, $fields) { $rs = FileUtils::UpWare($file, true); if ($rs != false) { $fields['title'] = $rs; } $this->_dbmaterials->create($fields); }
private function _deleteTempAvatarFiles($uid) { $files = $this->_getTempAvatarFiles($uid); $path = UploadUtils::getTempAvatarPath(); foreach ($files as $fileName) { FileUtils::safeDeleteFile($path . '/' . $fileName); } }
public function __destruct() { try { FileUtils::removeDirectory($this->path, true); } catch (BaseException $e) { // boo! deal with garbage yourself. } }
public function getItemsTable($pageNumber, $num, $response, $key, $valueToSearch) { $mainTag = new Div(); $tdNum = 3; $tdNumTotal = $tdNum * 2 - 1; $indOnPage = 0; $items = 0; $td = 0; $item = new Item(); $rowIndex = 1; $tdHeight = Utils::isSquareViewMode() ? 300 : 30; $highLightId = Utils::getFromGET(UrlParameters::HIGH_LIGHT_ELEMENT); $isMetro = array_key_exists(UrlParameters::VIEW_MODE, $_GET) && Utils::getFromGET(UrlParameters::VIEW_MODE) == "metro" || !array_key_exists(UrlParameters::VIEW_MODE, $_GET); $isCompact = array_key_exists(UrlParameters::VIEW_MODE, $_GET) && Utils::getFromGET(UrlParameters::VIEW_MODE) == "compact"; $isExtend = array_key_exists(UrlParameters::VIEW_MODE, $_GET) && Utils::getFromGET(UrlParameters::VIEW_MODE) == "extend"; $isList = array_key_exists(UrlParameters::VIEW_MODE, $_GET) && Utils::getFromGET(UrlParameters::VIEW_MODE) == "list"; $rowViewClass = $isCompact ? 'compact' : ($isMetro ? "metro" : ($isExtend ? "extend" : ($isList ? "list" : "list"))); if ($response != 0) { $mainTag->addStyleClass("items_table"); $rowView = new Div(); $mainTag->addChild($rowView); while ($row = mysql_fetch_array($response)) { $items++; $indOnPage++; $td++; if (ceil(fmod($indOnPage, $tdNum)) == 1) { $rowIndex++; $indOnPage = 1; $td = 1; } elseif (Utils::isEven($td)) { $td++; } $rowView->addStyleClass($rowViewClass); $cellView = new Div(); $rowView->addChild($cellView); $keyItem = $row["key_item"]; $images = FileUtils::getFilesByPrefixByDescription(Constants::DEFAULT_ROOT_CATALOG_PATH . DIRECTORY_SEPARATOR . $keyItem . DIRECTORY_SEPARATOR, Constants::MEDIUM_IMAGE, 'jpg'); if (count($images) == 0) { $capImage = FileUtils::getCapImage(Labels::CAP_IMAGE_FOR_CLOTHING); $images = [$capImage]; } $item = null; if ($isMetro) { $item = Item::getMetroItemView($row["name"], $images, $row["key_item"], $pageNumber, $num, $key, $valueToSearch, $row['god_type'], Utils::formatClotheTitle($row["name"]), $highLightId == $row["key_item"]); } elseif ($isCompact) { //$name, $images, $itemId, $pageNumber, $num, $key, $valueToSearch, $type, $trimName, $isHighLightElement $item = Item::getCompactItemView($row["name"], $images, $row["key_item"], $pageNumber, $num, $key, $valueToSearch, $row['god_type'], Utils::formatClotheTitle($row["name"]), $highLightId == $row["key_item"]); } elseif ($isExtend) { $item = Item::getSquareItemView($row["name"], $images, $row["key_item"], $pageNumber, $num, $key, $valueToSearch, $row['god_type'], Utils::formatClotheTitle($row["name"])); } elseif ($isList) { $item = Item::getLineItemView($row["name"], $images, $row["key_item"], $pageNumber, $num, $key, $valueToSearch, $row['god_type'], Utils::trimFormatClotheTitle($row["name"]), $highLightId == $row["key_item"]); } $cellView->addChild($item); $cellView->addStyleClass("catalog_good_item"); } } return $mainTag; }
function clearOldFiles() { $files = FileUtils::getFiles("../tmpworksheets"); foreach ($files as $fName) { if (filectime($fName) < time() - 1 * 60 * 60) { unlink($fName); } } }
function copyFile(PhingFile $sourceFile, PhingFile $destFile, $overwrite = false, $preserveLastModified = true, &$filterChains = null, Project $project) { // writes to tmp file first, then rename it to avoid file locking race // conditions $parent = $destFile->getParentFile(); $tmpFile = new PhingFile($parent, substr(md5(time()), 0, 8)); parent::copyFile($sourceFile, $tmpFile, $overwrite, $preserveLastModified, $filterChains, $project); $tmpFile->renameTo($destFile); }
public function setUp() { $dir = dirname(__FILE__); $this->nimble = Nimble::getINstance(); Nimble::set_config('stylesheet_folder', FileUtils::join($dir, 'assets', 'stylesheets')); Nimble::set_config('stylesheet_folder_url', '/stylesheet'); Nimble::set_config('javascript_folder', FileUtils::join($dir, 'assets', 'javascript')); Nimble::set_config('javascript_folder_url', '/javascript'); }
public function about() { $this->set_default_side_bar(); require_once FileUtils::join(NIMBLE_ROOT, 'lib', 'markdown.php'); $template = FileUtils::join(NIMBLE_ROOT, 'app', 'view', 'help', 'about.markdown'); $this->about = file_get_contents($template); $this->title = 'About Pearfarm'; Nimble::set_title($this->title); }
private static function saveBookletImage($bookletCode, $imageName, $base64Image) { $bookletImagesRoot = DBPreferencesType::getPreferenceS(Constants::BOOKLET_IMAGE_PATH); $bookletImageDirectory = FileUtils::buildPath($bookletImagesRoot, $bookletCode); FileUtils::createDir($bookletImageDirectory); $imageEditor = ImageEditor::newImageBase64($base64Image); $bookletImagePath = FileUtils::buildPath($bookletImagesRoot, $bookletCode, $imageName); $imageEditor->saveImage($bookletImagePath); return FileUtils::buildPath($bookletCode, $imageName); }
public static function parse(DOMNode $node) { if ($node->nodeName == self::getNodeName()) { if (($code = HTTPCode::getByCode(XMLUtils::getChildByName($node, "code")->nodeValue)) != null) { return new Error(FileUtils::getAbsolutePath(XMLUtils::getChildByName($node, "file")->nodeValue, VIEWS_FOLDER), $code); } throw new Exception("Unknown HTTP Code '" . XMLUtils::getChildByName($node, "code")->nodeValue . "'"); } throw new Exception("Unexpected node '" . $node->nodeName . "', expected '" . self::getNodeName() . "'"); }
public function testUniqueNames() { $uniqueName = FileUtils::makeUniqueName('Chasey Lain.jpeg'); $this->assertEquals(substr($uniqueName, strpos($uniqueName, '.')), '.jpeg'); $uniqueName = FileUtils::makeUniqueName('Елена Беркова.jpeg'); $this->assertEquals(substr($uniqueName, strpos($uniqueName, '.')), '.jpeg'); $uniqueName = FileUtils::makeUniqueLatinName('Елена Беркова.gif'); //animated gif ;) $this->assertEquals(substr($uniqueName, strpos($uniqueName, '.')), '.gif'); }
public static function create_package() { $user = User::find_by_username('bob'); $file = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'bobs_other_package-0.0.1.tgz'); $package = Package::from_upload(array('file' => $file, 'user' => $user)); foreach (User::_find('all') as $user) { $raiting = '0.' . $user->id; PackageRating::_create(array('user_id' => $user->id, 'package_id' => $package->id, 'rating' => (double) $raiting)); } }
public function upfile($file, $fields) { $rs = FileUtils::upfile($file, true); if ($rs != false) { $fields['name'] = $rs; $fields['url'] = FileUtils::GetPath() . "/" . $fields['name']; } $this->insertFile($fields); return $fields; }
/** * tries to include the requested plugin and returns the plugin class name, or false if plugin not found. * @param string $pluginName name of the plugin * @return string class name or false if not found */ protected function _load($pluginName, $section) { $cleanName = FileUtils::sanitize($pluginName); $className = strtolower("Plugins_{$cleanName}_{$section}"); if (M::resolve_class($className, 'plugins', function () use($cleanName) { PluginRegistry::initPlugin($cleanName); })) { return $className; } }
public static function MoveUploadedFile($value, $target, $replaceIfExists = false) { if ($replaceIfExists) { if (FileUtils::IsUploadedFile($value)) { if (FileUtils::FileExists($target)) { FileUtils::RemoveFile($target); } } } move_uploaded_file($value, $target); }
function changeUserProfilePhoto($photoForm) { $formObjRaw = new FormDTO(PROFILE_SETTINGS_PHOTO_FORM, $photoForm); $responseDTO = new ResponseDTO(PROFILE_SETTINGS_PHOTO_FORM); try { $formDataObj = $formObjRaw->getFormData(); $validator = new FormValidator(PROFILE_SETTINGS_PHOTO_FORM, $formDataObj); $validationError = $validator->checkAll(); if (sizeof($validationError) == 0) { $userLogged = SessionUtils::getUserLogged(); $uploadedPhoto = FileUtils::uploadPhotoModel($formDataObj[PROFILE_SETTINGS_PHOTO_FORM . PHOTO], $userLogged->getDefaultAlbumId(), PROFILE_SETTINGS_PHOTO_FORM); if (get_class($uploadedPhoto) === PHOTODTO) { $photoDAO = new PhotoDAO(); $updateProfilePhoto = $photoDAO->updateProfilePhoto($uploadedPhoto); $userLogged = SessionUtils::getUserLogged(); $userLogged->setProfilePhoto($uploadedPhoto); SessionUtils::setUserLogged($userLogged); return $uploadedPhoto; } else { $responseDTO->setResponseSucc("Errore durante l'inserimento della foto profilo"); } } else { if (array_key_exists(PHOTO, $validationError)) { $responseDTO->setErrField(PHOTO, $validationError[PHOTO]); } } return $responseDTO; } catch (PDOException $pdoe) { throw $pdoe; } catch (UserNotAuthenticatedExceptionDTO $authExp) { throw $authExp; } catch (Exception $e) { throw $e; } }
/** * comparison method of the interface * * @return bool if the files are equal * @throws BuildException if it all went pear-shaped */ public function evaluate() { if ($this->file1 == null || $this->file2 == null) { throw new BuildException("both file1 and file2 are required in filesmatch"); } $fu = new FileUtils(); return $fu->contentEquals($this->file1, $this->file2); }
public function testGetFileExtensionFromMime() { $this->assertEquals('png', FileUtils::getExtensionFromMime('image/png')); $this->assertEquals('jpg', FileUtils::getExtensionFromMime('image/jpeg')); $this->assertEquals('jpg', FileUtils::getExtensionFromMime('image/jpg')); $this->assertNull(FileUtils::getExtensionFromMime('application/octet-stream')); }
public function __construct() { if (static::$enabled) { FileUtils::mkdir_p(FileUtils::join(FileUtils::join(NIMBLE_ROOT, 'log'))); $this->log_file = FileUtils::join(NIMBLE_ROOT, 'log', NIMBLE_ENV . '.log'); } }
public static function create_package() { $user = User::find_by_username('bob'); $file = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'bobs_other_package-0.0.1.tgz'); $pp = Package::from_upload(array('file' => $file, 'user' => $user)); $p = Package::update($pp->id, array('url' => 'http://jetviper21.com')); }
public function execute($params) { if (is_array($params) && count($params) > 0) { $command = array_shift($params); $exec = Command::factory($command); $exec->longHelp($params); } else { $this->line('This command displays global help text or specific help text for a command if provided'); $this->line('Usage:'); $this->line('help'); $this->line(' Displays this help'); $this->line('help [COMMAND_NAME]'); $this->line(' Displays specific and longer help for [COMMAND_NAME]'); $this->line('help [COMMAND_NAME] [SUBCOMMAND_NAME] and so on....'); $this->line(' Displays specific and longer help for [SUBCOMMAND_NAME] if [COMMAND_NAME] contains some subcommands (e.g. the plugin command)'); $this->line('=========='); $this->line('Here is the list of available root commands:'); $dir = dirname(realpath(__FILE__)); foreach (FileUtils::getAllFiles($dir, 'php') as $afile) { $subcname = basename($afile, '.php'); $subc = Command::factory($subcname); $this->line('====== ' . $subcname . ' ======'); $subc->shortHelp(); } } }
public static function updatePrices($data) { $result = []; if (count($data) > 0) { $dbPreference = new DBPreferencesType(); $priceDirectory = $dbPreference->getPreference(Constants::PRICE_DIRECTORY)[DB::TABLE_PREFERENCES__VALUE]; for ($orderIndex = 0; $orderIndex < count(self::$operationsOrder); $orderIndex++) { $currentAction = self::$operationsOrder[$orderIndex]; foreach ($data as $key => $value) { if ($value['action'] == $currentAction) { $operationRes = false; switch ($currentAction) { case self::PRICE_DEL: $operationRes = unlink(FileUtils::buildPath($priceDirectory, $value['name'])); break; case self::PRICE_RENAME: $operationRes = rename(FileUtils::buildPath($priceDirectory, $value['name']), FileUtils::buildPath($priceDirectory, $value['new_name'])); break; case self::PRICE_ADD: $operationRes = FileUtils::createFileBase64($value['file'], FileUtils::buildPath($priceDirectory, $value['name'])); break; } $result[$key] = $operationRes; } } } } return $result; }
private function _runAction($res, $uid) { if (empty($_FILES['userAvatar']['tmp_name'])) { return WebUtils::makeErrorInfo_oldVersion($res, WebUtils::t('请选择上传的文件')); } if ($_FILES['userAvatar']['error'] > 0) { return WebUtils::makeErrorInfo_oldVersion($res, WebUtils::t('上传文件失败')); } if ($_FILES['userAvatar']['size'] > 2000000) { return WebUtils::makeErrorInfo_oldVersion($res, WebUtils::t('上传文件太大')); } $savePath = UploadUtils::getTempAvatarPath(); $fileName = sprintf('%s/avatar_%s.jpg', $savePath, $uid); if (move_uploaded_file($_FILES['userAvatar']['tmp_name'], $fileName)) { $imageData = file_get_contents($fileName); $image = $this->_uploadAvatarByUcenter($uid, $fileName, $imageData); FileUtils::safeDeleteFile($fileName); if (!empty($image)) { return array_merge($res, array('icon_url' => '', 'pic_path' => $image)); } // WebUtils::httpRequestAppAPI('user/saveavatar', array('avatar' => $image, 'hacker_uid' => 1)); // die(); } return WebUtils::makeErrorInfo_oldVersion($res, WebUtils::t('上传文件失败')); }
public static function load($xmlfile, $prefix) { if (is_file($xmlfile)) { $dom = new DOMDocument(); $dom->load($xmlfile); if ($dom->validate()) { $root = $dom->documentElement; // Preliminary path modifications foreach ($root->getElementsByTagName("include") as $include) { $include->nodeValue = FileUtils::resolveRelativePath(FileUtils::getFileParent($xmlfile), $include->nodeValue); } // Reading attributes $actions = array(); foreach (XMLUtils::getChildrenByName($root, "action") as $child) { $actions[] = AbstractAction::parse($child); } $subsites = array(); foreach (XMLUtils::getChildrenByName($root, "subsite") as $child) { $subsites[] = Subsite::parse($child); } $targets = array(); foreach (XMLUtils::getChildrenByName($root, "target") as $child) { $targets[] = Target::parse($child); } return new Subsite($subsites, $targets, $actions, $prefix); } else { throw new Exception("Document validation failed for '" . $xmlfile . "'"); } } else { throw new Exception("Not a file '" . $xmlfile . "'"); } }
public function testGetHelp() { $_SERVER['SERVER_NAME'] = 'bob.localhost.com'; $dir = FileUtils::join(NIMBLE_ROOT, 'app', 'view', 'help', 'markdown'); foreach (HelpController::get_markdown_files($dir) as $help) { $name = substr(basename($help), 0, -9); $this->get('show', array(), array('name' => $name)); $this->responseIncludes(ucwords(Inflector::humanize($name))); $this->controller = new HelpController(); } }