本文整理汇总了PHP中UTIL_File::sanitizeName方法的典型用法代码示例。如果您正苦于以下问题:PHP UTIL_File::sanitizeName方法的具体用法?PHP UTIL_File::sanitizeName怎么用?PHP UTIL_File::sanitizeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTIL_File
的用法示例。
在下文中一共展示了UTIL_File::sanitizeName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
//.........这里部分代码省略.........
if ($credits === false) {
$this->assign('authMsg', OW::getEventManager()->call('usercredits.error_message', $eventParams));
}
if (!OW::getRequest()->isAjax()) {
OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'forum', 'forum');
}
$groupSelect = $forumService->getGroupSelectList(0, false, $userId);
OW::getDocument()->setHeading(OW::getLanguage()->text('forum', 'create_new_topic'));
}
OW::getDocument()->setDescription(OW::getLanguage()->text('forum', 'meta_description_add_topic'));
OW::getDocument()->setTitle(OW::getLanguage()->text('forum', 'meta_title_add_topic'));
OW::getDocument()->setHeadingIconClass('ow_ic_write');
$this->assign('isHidden', $isHidden);
$form = $this->generateForm($groupSelect, $groupId, $isHidden);
OW::getDocument()->addStyleDeclaration('
.disabled_option {
color: #9F9F9F;
}
');
$enableAttachments = OW::getConfig()->getValue('forum', 'enable_attachments');
$this->assign('enableAttachments', $enableAttachments);
if (OW::getRequest()->isPost() && $form->isValid($_POST)) {
$data = $form->getValues();
if ($data['group']) {
$topicDto = new FORUM_BOL_Topic();
$topicDto->userId = $userId;
$topicDto->groupId = $data['group'];
$topicDto->title = strip_tags($data['title']);
$forumService->saveOrUpdateTopic($topicDto);
$postDto = new FORUM_BOL_Post();
$postDto->topicId = $topicDto->id;
$postDto->userId = $userId;
$postDto->text = trim($data['text']);
$postDto->createStamp = time();
$forumService->saveOrUpdatePost($postDto);
$topicDto->lastPostId = $postDto->getId();
$forumService->saveOrUpdateTopic($topicDto);
// subscribe author to new posts
if ($data['subscribe']) {
$subService = FORUM_BOL_SubscriptionService::getInstance();
$subs = new FORUM_BOL_Subscription();
$subs->userId = $userId;
$subs->topicId = $topicDto->id;
$subService->addSubscription($subs);
}
$accepted = floatval(OW::getConfig()->getValue('forum', 'attachment_filesize') * 1024 * 1024);
if (isset($data['attachments']) && count($data['attachments'])) {
$filesArray = $data['attachments'];
$filesCount = count($filesArray['name']);
$attachmentService = FORUM_BOL_PostAttachmentService::getInstance();
$skipped = 0;
for ($i = 0; $i < $filesCount; $i++) {
if (!strlen($filesArray['tmp_name'][$i])) {
continue;
}
// skip unsupported extensions
$ext = UTIL_File::getExtension($filesArray['name'][$i]);
if (!$attachmentService->fileExtensionIsAllowed($ext)) {
$skipped++;
continue;
}
// skip too big files
if ($filesArray['size'][$i] > $accepted) {
$skipped++;
continue;
}
$attachmentDto = new FORUM_BOL_PostAttachment();
$attachmentDto->postId = $postDto->id;
$attachmentDto->fileName = htmlspecialchars($filesArray['name'][$i]);
$attachmentDto->fileNameClean = UTIL_File::sanitizeName($attachmentDto->fileName);
$attachmentDto->fileSize = $filesArray['size'][$i];
$attachmentDto->hash = uniqid();
$added = $attachmentService->addAttachment($attachmentDto, $filesArray['tmp_name'][$i]);
if (!$added) {
$skipped++;
}
}
if ($skipped) {
OW::getFeedback()->warning(OW::getLanguage()->text('forum', 'not_all_attachments_added'));
}
}
$topicUrl = OW::getRouter()->urlForRoute('topic-default', array('topicId' => $topicDto->id));
//Newsfeed
$params = array('pluginKey' => 'forum', 'entityType' => 'forum-topic', 'entityId' => $topicDto->id, 'userId' => $topicDto->userId);
$event = new OW_Event('feed.action', $params);
OW::getEventManager()->trigger($event);
if ($credits === true) {
OW::getEventManager()->call('usercredits.track_action', $eventParams);
}
if ($isHidden) {
$params = array('topicId' => $topicDto->id, 'entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId, 'userId' => $topicDto->userId, 'topicUrl' => $topicUrl, 'topicTitle' => $topicDto->title, 'postText' => $postDto->text);
$event = new OW_Event('forum.topic_add', $params);
OW::getEventManager()->trigger($event);
}
$this->redirect($topicUrl);
} else {
$form->getElement('group')->addError(OW::getLanguage()->text('forum', 'select_group_error'));
}
}
}
示例2: processUploadedFile
public function processUploadedFile($pluginKey, array $fileInfo, $bundle = null, $validFileExtensions = array(), $maxUploadSize = null, $dimensions = null)
{
$language = OW::getLanguage();
$error = false;
if (!OW::getUser()->isAuthenticated()) {
throw new InvalidArgumentException($language->text('base', 'user_is_not_authenticated'));
}
if (empty($fileInfo) || !is_uploaded_file($fileInfo['tmp_name'])) {
throw new InvalidArgumentException($language->text('base', 'upload_file_fail'));
}
if ($fileInfo['error'] != UPLOAD_ERR_OK) {
switch ($fileInfo['error']) {
case UPLOAD_ERR_INI_SIZE:
$error = $language->text('base', 'upload_file_max_upload_filesize_error');
break;
case UPLOAD_ERR_PARTIAL:
$error = $language->text('base', 'upload_file_file_partially_uploaded_error');
break;
case UPLOAD_ERR_NO_FILE:
$error = $language->text('base', 'upload_file_no_file_error');
break;
case UPLOAD_ERR_NO_TMP_DIR:
$error = $language->text('base', 'upload_file_no_tmp_dir_error');
break;
case UPLOAD_ERR_CANT_WRITE:
$error = $language->text('base', 'upload_file_cant_write_file_error');
break;
case UPLOAD_ERR_EXTENSION:
$error = $language->text('base', 'upload_file_invalid_extention_error');
break;
default:
$error = $language->text('base', 'upload_file_fail');
}
throw new InvalidArgumentException($error);
}
if (empty($validFileExtensions)) {
$validFileExtensions = json_decode(OW::getConfig()->getValue('base', 'attch_ext_list'), true);
}
if ($maxUploadSize === null) {
$maxUploadSize = OW::getConfig()->getValue('base', 'attch_file_max_size_mb');
}
if (!empty($validFileExtensions) && !in_array(UTIL_File::getExtension($fileInfo['name']), $validFileExtensions)) {
throw new InvalidArgumentException($language->text('base', 'upload_file_extension_is_not_allowed'));
}
// get all bundle upload size
$bundleSize = floor($fileInfo['size'] / 1024);
if ($bundle !== null) {
$list = $this->attachmentDao->findAttahcmentByBundle($pluginKey, $bundle);
/* @var $item BOL_Attachment */
foreach ($list as $item) {
$bundleSize += $item->getSize();
}
}
if ($maxUploadSize > 0 && $bundleSize > $maxUploadSize * 1024) {
throw new InvalidArgumentException($language->text('base', 'upload_file_max_upload_filesize_error'));
}
$attachDto = new BOL_Attachment();
$attachDto->setUserId(OW::getUser()->getId());
$attachDto->setAddStamp(time());
$attachDto->setStatus(0);
$attachDto->setSize(floor($fileInfo['size'] / 1024));
$attachDto->setOrigFileName(htmlspecialchars($fileInfo['name']));
$attachDto->setFileName(uniqid() . '_' . UTIL_File::sanitizeName($attachDto->getOrigFileName()));
$attachDto->setPluginKey($pluginKey);
if ($bundle !== null) {
$attachDto->setBundle($bundle);
}
$this->attachmentDao->save($attachDto);
$uploadPath = $this->getAttachmentsDir() . $attachDto->getFileName();
$tempPath = $this->getAttachmentsDir() . 'temp_' . $attachDto->getFileName();
if (in_array(UTIL_File::getExtension($fileInfo['name']), array('jpg', 'jpeg', 'gif', 'png'))) {
try {
$image = new UTIL_Image($fileInfo['tmp_name']);
if (empty($dimensions)) {
$dimensions = array('width' => 1000, 'height' => 1000);
}
$image->resizeImage($dimensions['width'], $dimensions['height'])->orientateImage()->saveImage($tempPath);
$image->destroy();
@unlink($fileInfo['tmp_name']);
} catch (Exception $e) {
throw new InvalidArgumentException($language->text('base', 'upload_file_fail'));
}
} else {
move_uploaded_file($fileInfo['tmp_name'], $tempPath);
}
OW::getStorage()->copyFile($tempPath, $uploadPath);
OW::getStorage()->chmod($uploadPath, 0666);
unlink($tempPath);
return array('uid' => $attachDto->getBundle(), 'dto' => $attachDto, 'path' => $uploadPath, 'url' => $this->getAttachmentsUrl() . $attachDto->getFileName());
}
示例3: index
public function index(array $params = null)
{
$forumService = FORUM_BOL_ForumService::getInstance();
if (!isset($params['id']) || !($postId = (int) $params['id'])) {
throw new Redirect404Exception();
}
$postDto = $forumService->findPostById($postId);
if (!$postDto) {
throw new Redirect404Exception();
}
$userId = OW::getUser()->getId();
$topicId = $postDto->topicId;
$topicDto = $forumService->findTopicById($topicId);
$forumGroup = $forumService->getGroupInfo($topicDto->groupId);
$forumSection = $forumService->findSectionById($forumGroup->sectionId);
$isHidden = $forumSection->isHidden;
if ($isHidden) {
$isModerator = OW::getUser()->isAuthorized($forumSection->entity);
$eventParams = array('entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId, 'action' => 'add_topic');
$event = new OW_Event('forum.check_permissions', $eventParams);
OW::getEventManager()->trigger($event);
$canPost = $event->getData();
//check permissions
$canEdit = OW::getUser()->isAuthorized($forumSection->entity, 'add_topic', $postDto->userId);
} else {
$isModerator = OW::getUser()->isAuthorized('forum');
$canPost = true;
$canEdit = $postDto->userId == OW::getUser()->getId();
}
if ((!$canEdit || !$canPost) && !$isModerator) {
$this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html');
return;
}
$this->assign('postId', $postId);
$editPostForm = $this->generateEditPostForm($postDto);
$this->addForm($editPostForm);
$lang = OW::getLanguage();
$router = OW::getRouter();
if (OW::getRequest()->isPost() && $editPostForm->isValid($_POST)) {
$values = $editPostForm->getValues();
$postId = (int) $values['post-id'];
$text = $values['text'];
$topicId = (int) $values['topic'];
$topicUrl = OW::getRouter()->urlForRoute('topic-default', array('topicId' => $topicId));
$postDto = $forumService->findPostById($postId);
if ($postDto === null || $postDto->userId != $userId && !$isModerator) {
$this->redirect($topicUrl);
}
//save post
$postDto->text = $text;
$forumService->saveOrUpdatePost($postDto);
//save post edit info
$editPostDto = $forumService->findEditPost($postId);
if ($editPostDto === null) {
$editPostDto = new FORUM_BOL_EditPost();
}
$editPostDto->postId = $postId;
$editPostDto->userId = $userId;
$editPostDto->editStamp = time();
$forumService->saveOrUpdateEditPost($editPostDto);
if (isset($_FILES['attachments']) && count($_FILES['attachments'])) {
$filesArray = $_FILES['attachments'];
$filesCount = count($filesArray['name']);
$attachmentService = FORUM_BOL_PostAttachmentService::getInstance();
$skipped = 0;
$accepted = floatval(OW::getConfig()->getValue('forum', 'attachment_filesize') * 1024 * 1024);
for ($i = 0; $i < $filesCount; $i++) {
if (!strlen($filesArray['tmp_name'][$i])) {
continue;
}
// skip unsupported extensions
$ext = UTIL_File::getExtension($filesArray['name'][$i]);
if (!$attachmentService->fileExtensionIsAllowed($ext)) {
$skipped++;
continue;
}
// skip too big files
if ($filesArray['size'][$i] > $accepted) {
$skipped++;
continue;
}
$attachmentDto = new FORUM_BOL_PostAttachment();
$attachmentDto->postId = $postDto->id;
$attachmentDto->fileName = htmlspecialchars($filesArray['name'][$i]);
$attachmentDto->fileNameClean = UTIL_File::sanitizeName($attachmentDto->fileName);
$attachmentDto->fileSize = $filesArray['size'][$i];
$attachmentDto->hash = uniqid();
$added = $attachmentService->addAttachment($attachmentDto, $filesArray['tmp_name'][$i]);
if (!$added) {
$skipped++;
}
}
if ($skipped) {
OW::getFeedback()->warning($lang->text('forum', 'not_all_attachments_added'));
$this->redirect();
}
}
$this->redirect($forumService->getPostUrl($topicId, $postId, true));
}
$enableAttachments = OW::getConfig()->getValue('forum', 'enable_attachments');
//.........这里部分代码省略.........
示例4: addPost
/**
* This action adds a post and after execution redirects to default action
*
* @param array $params
*/
public function addPost(array $params)
{
if (!isset($params['topicId']) || !($topicId = (int) $params['topicId'])) {
throw new Redirect404Exception();
}
$topicDto = $this->forumService->findTopicById($topicId);
if (!$topicDto) {
throw new Redirect404Exception();
}
$addPostForm = $this->generateAddPostForm($topicId);
if (OW::getRequest()->isPost() && $addPostForm->isValid($_POST)) {
$data = $addPostForm->getValues();
if ($data['topic'] && $data['topic'] == $topicDto->id && !$topicDto->locked) {
if (!OW::getUser()->getId()) {
throw new AuthenticateException();
}
$postDto = new FORUM_BOL_Post();
$postDto->topicId = $data['topic'];
$postDto->userId = OW::getUser()->getId();
$postDto->text = trim($data['text']);
$postDto->createStamp = time();
$this->forumService->saveOrUpdatePost($postDto);
$topicDto->lastPostId = $postDto->getId();
$this->forumService->saveOrUpdateTopic($topicDto);
$this->forumService->deleteByTopicId($topicId);
if (isset($data['attachments']) && count($data['attachments'])) {
$filesArray = $data['attachments'];
$filesCount = count($filesArray['name']);
$attachmentService = FORUM_BOL_PostAttachmentService::getInstance();
$skipped = 0;
$accepted = floatval(OW::getConfig()->getValue('forum', 'attachment_filesize') * 1024 * 1024);
for ($i = 0; $i < $filesCount; $i++) {
if (!strlen($filesArray['tmp_name'][$i])) {
continue;
}
// skip unsupported extensions
$ext = UTIL_File::getExtension($filesArray['name'][$i]);
if (!$attachmentService->fileExtensionIsAllowed($ext)) {
$skipped++;
continue;
}
// skip too big files
if ($filesArray['size'][$i] > $accepted) {
$skipped++;
continue;
}
$attachmentDto = new FORUM_BOL_PostAttachment();
$attachmentDto->postId = $postDto->id;
$attachmentDto->fileName = htmlspecialchars($filesArray['name'][$i]);
$attachmentDto->fileNameClean = UTIL_File::sanitizeName($attachmentDto->fileName);
$attachmentDto->fileSize = $filesArray['size'][$i];
$attachmentDto->hash = uniqid();
$added = $attachmentService->addAttachment($attachmentDto, $filesArray['tmp_name'][$i]);
if (!$added) {
$skipped++;
}
}
if ($skipped) {
OW::getFeedback()->warning(OW::getLanguage()->text('forum', 'not_all_attachments_added'));
}
}
$postUrl = $this->forumService->getPostUrl($topicId, $postDto->id);
$event = new OW_Event('forum.add_post', array('postId' => $postDto->id, 'topicId' => $topicId, 'userId' => $postDto->userId));
OW::getEventManager()->trigger($event);
$forumGroup = $this->forumService->findGroupById($topicDto->groupId);
if ($forumGroup) {
$forumSection = $this->forumService->findSectionById($forumGroup->sectionId);
if ($forumSection) {
$pluginKey = $forumSection->isHidden ? $forumSection->entity : 'forum';
$eventParams = array('pluginKey' => $pluginKey, 'action' => 'add_post');
if ($credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams) === true) {
OW::getEventManager()->call('usercredits.track_action', $eventParams);
}
}
}
$this->redirect($postUrl);
}
} else {
$this->redirect(OW::getRouter()->urlForRoute('topic-default', array('topicId' => $topicId)));
}
}