public function addTemplate($fileName, $roleIds = null, $default = false) { $canvasWidth = self::CANVAS_WIDTH; $canvasHeight = $this->config['cover_height']; $coverImage = new UTIL_Image($fileName); $imageHeight = $coverImage->getHeight(); $imageWidth = $coverImage->getWidth(); $css = array('width' => 'auto', 'height' => 'auto'); $tmp = $canvasWidth * $imageHeight / $imageWidth; if ($tmp >= $canvasHeight) { $css['width'] = '100%'; } else { $css['height'] = '100%'; } $template = new UHEADER_BOL_Template(); $extension = UTIL_File::getExtension($fileName); $template->file = uniqid('template-') . '.' . $extension; $template->default = $default; $template->timeStamp = time(); $dimensions = array('height' => $imageHeight, 'width' => $imageWidth); $template->setSettings(array('dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0))); $this->service->saveTemplate($template); if ($roleIds !== null) { $this->service->saveRoleIdsForTemplateId($template->id, $roleIds); } $templatePath = $this->service->getTemplatePath($template); OW::getStorage()->copyFile($fileName, $templatePath); }
public function import($params) { $importDir = $params['importDir']; $txtFile = $importDir . 'configs.txt'; // import configs if (file_exists($txtFile)) { $string = file_get_contents($txtFile); $configs = json_decode($string, true); } if (!$configs) { return; } $attachmentService = FORUM_BOL_PostAttachmentService::getInstance(); $attDir = OW::getPluginManager()->getPlugin('forum')->getUserFilesDir(); $attachments = $attachmentService->findAllAttachments(); if (!$attachments) { return; } foreach ($attachments as $file) { OW::getDbo()->query("SELECT 1 "); $ext = UTIL_File::getExtension($file->fileName); $path = $attachmentService->getAttachmentFilePath($file->id, $file->hash, $ext); $fileName = str_replace($attDir, '', $path); $content = file_get_contents($configs['url'] . '/' . $fileName); if (mb_strlen($content)) { OW::getStorage()->fileSetContent($path, $content); } } }
public function includeStaticFile($file) { $document = OW::getDocument(); $staticUrl = $this->plugin->getStaticUrl(); $ext = UTIL_File::getExtension($file); $file .= "?" . $this->plugin->getDto()->build; switch ($ext) { case "css": $document->addStyleSheet($staticUrl . $file); break; case "js": $document->addScript($staticUrl . $file); break; } }
public function addFile(MAILBOX_BOL_FileUpload $dto, $filePath) { $ext = UTIL_File::getExtension($dto->fileName); if (!$this->fileExtensionIsAllowed($ext) && !file_exists($filePath)) { return false; } $uploadPath = $this->getUploadFilePath($dto->hash, $ext); $dto->filePath = $uploadPath; $this->saveOrUpdate($dto); $attId = $dto->id; if (move_uploaded_file($filePath, $uploadPath)) { @chmod($uploadPath, 0666); return true; } else { $this->uploadFileDao->deleteById($attId); return false; } }
/** * @see FormElement::renderInput() * * @param array $params * @return string */ public function renderInput($params = null) { parent::renderInput($params); $fileElementId = $this->getId() . '_file'; $entityId = $this->getValue(); if (empty($entityId)) { $entityId = uniqid('upload'); } $iframeUrl = OW::getRouter()->urlFor('MAILBOX_CTRL_Mailbox', 'fileUpload', array('entityId' => $entityId, 'formElementId' => $fileElementId)); $attachFileHtml = '<div id="file_attachment" class="ow_mailbox_attachment"> <span class="ow_mailbox_attachment_icon ow_ic_attach "> </span> <a class="file" href="javascript://"></a> (<span class="filesize"></span>) <a rel="40" class="ow_delete_attachment ow_lbutton ow_hidden" href="javascript://" style="display: none;">' . OW::getLanguage()->text('mailbox', 'attache_file_delete_button') . '</a> </div>'; $fileList = array(); if (!empty($entityId)) { $fileService = MAILBOX_BOL_FileUploadService::getInstance(); $uploadFileDtoList = $fileService->findUploadFileList($entityId); foreach ($uploadFileDtoList as $uploadFileDto) { $file = array(); $file['hash'] = $uploadFileDto->hash; $file['filesize'] = round($uploadFileDto->fileSize / 1024, 2) . 'Kb'; $file['filename'] = $uploadFileDto->fileName; $file['fileUrl'] = $fileService->getUploadFileUrl($uploadFileDto->hash, UTIL_File::getExtension($uploadFileDto->fileName)); $fileList[] = $file; } } $params = array('elementId' => $fileElementId, 'ajaxResponderUrl' => OW::getRouter()->urlFor("MAILBOX_CTRL_Mailbox", "responder"), 'fileResponderUrl' => $iframeUrl, 'attachFileHtml' => $attachFileHtml, 'fileList' => $fileList); $script = " window.fileUpload_" . $this->getId() . " = new fileUpload(" . json_encode($params) . ");\n window.fileUpload_" . $this->getId() . ".init();"; OW::getDocument()->addOnloadScript($script); OW::getDocument()->addScript(OW::getPluginManager()->getPlugin("mailbox")->getStaticJsUrl() . 'ajax_file_upload.js'); $hiddenAttr = array('id' => $this->getId(), 'type' => 'hidden', 'name' => $this->getName(), 'value' => $entityId); $fileAttr = $this->attributes; unset($fileAttr['name']); $fileAttr['id'] = $fileElementId; return UTIL_HtmlTag::generateTag('input', $hiddenAttr) . '<span class="' . $fileElementId . '_class">' . UTIL_HtmlTag::generateTag('input', $fileAttr) . '</span> <div id="' . $fileElementId . '_list" class="ow_small ow_smallmargin"> <div class="ow_attachments_label mailbox_attachments_label ow_hidden">' . OW::getLanguage()->text('mailbox', 'attachments') . ' :</div> </div>'; }
public function getFileNameList($dirPath, $prefix = null, array $fileTypes = null) { $dirPath = UTIL_File::removeLastDS($dirPath); $resultList = array(); $handle = opendir($dirPath); while (($item = readdir($handle)) !== false) { if ($item === '.' || $item === '..') { continue; } if ($prefix != null) { $prefixLength = strlen($prefix); if (!($prefixLength <= strlen($item) && substr($item, 0, $prefixLength) === $prefix)) { continue; } } $path = $dirPath . DS . $item; if ($fileTypes === null || is_file($path) && in_array(UTIL_File::getExtension($item), $fileTypes)) { $resultList[] = $path; } } closedir($handle); return $resultList; }
/** * * @param array $conversationIdList * @return array<MAILBOX_BOL_Attachment> */ public function deleteAttachmentsByConversationList(array $conversationIdList) { $attachmentList = $this->attachmentDao->findAttachmentstByConversationList($conversationIdList); foreach ($attachmentList as $attachment) { $ext = UTIL_File::getExtension($attachment['fileName']); $path = $this->getAttachmentFilePath($attachment['id'], $attachment['hash'], $ext); if (OW::getStorage()->removeFile($path)) { $this->attachmentDao->deleteById($attachment['id']); } } }
public function deleteAttachmentFiles() { $attachDtoList = $this->attachmentDao->getAttachmentForDelete(); foreach ($attachDtoList as $attachDto) { /* @var $attachDto MAILBOX_BOL_Attachment */ $ext = UTIL_File::getExtension($attachDto->fileName); $attachmentPath = $this->getAttachmentFilePath($attachDto->id, $attachDto->hash, $ext, $attachDto->fileName); try { OW::getStorage()->removeFile($attachmentPath); $this->attachmentDao->deleteById($attachDto->id); } catch (Exception $ex) { } } }
public function save($params) { $data = $params['data']; $authAdapter = new OW_RemoteAuthAdapter($data['facebookId'], 'facebook'); $nonQuestions = array('name', 'email', 'avatarUrl'); $nonQuestionsValue = array(); foreach ($nonQuestions as $name) { $nonQuestionsValue[$name] = empty($data[$name]) ? null : $data[$name]; unset($data[$name]); } $data['realname'] = $nonQuestionsValue['name']; $email = $nonQuestionsValue['email']; $password = uniqid(); $user = BOL_UserService::getInstance()->findByEmail($email); $newUser = false; if ($user === null) { $newUser = true; $username = $this->makeUsername($nonQuestionsValue['name']); $user = BOL_UserService::getInstance()->createUser($username, $password, $email, null, true); } BOL_QuestionService::getInstance()->saveQuestionsData(array_filter($data), $user->id); if (!empty($nonQuestionsValue['avatarUrl'])) { $avatarUrl = $nonQuestionsValue['avatarUrl']; $pluginfilesDir = OW::getPluginManager()->getPlugin('skadateios')->getPluginFilesDir(); $ext = UTIL_File::getExtension($avatarUrl); $tmpFile = $pluginfilesDir . uniqid('avatar-') . (empty($ext) ? '' : '.' . $ext); copy($avatarUrl, $tmpFile); BOL_AvatarService::getInstance()->setUserAvatar($user->id, $tmpFile); @unlink($tmpFile); } if (!$authAdapter->isRegistered()) { $authAdapter->register($user->id); } if ($newUser) { $event = new OW_Event(OW_EventManager::ON_USER_REGISTER, array('method' => 'facebook', 'userId' => $user->id, 'params' => array())); OW::getEventManager()->trigger($event); } OW::getUser()->login($user->id); $this->assign('success', true); $this->respondUserData($user->id); }
public function addFromPhotos($query) { $photoId = $query['photoId']; $groupId = $query['groupId']; if (!GHEADER_CLASS_CreditsBridge::getInstance()->credits->isAvaliable(GHEADER_CLASS_Credits::ACTION_ADD)) { $error = GHEADER_CLASS_CreditsBridge::getInstance()->credits->getErrorMessage(GHEADER_CLASS_Credits::ACTION_ADD); throw new InvalidArgumentException($error); } $sourcePath = GHEADER_CLASS_PhotoBridge::getInstance()->pullPhoto($photoId); if ($sourcePath === null) { throw new InvalidArgumentException("The requested photo wasn't find"); } $canvasWidth = $query['width']; $canvasHeight = OW::getConfig()->getValue('gheader', 'cover_height'); $coverImage = new UTIL_Image($sourcePath); $imageHeight = $coverImage->getHeight(); $imageWidth = $coverImage->getWidth(); $css = array('width' => 'auto', 'height' => 'auto'); $tmp = $canvasWidth * $imageHeight / $imageWidth; if ($tmp >= $canvasHeight) { $css['width'] = '100%'; } else { $css['height'] = '100%'; } $this->validateImage($coverImage, $canvasWidth, $canvasHeight); $cover = $this->service->findCoverByGroupId($groupId, GHEADER_BOL_Cover::STATUS_TMP); if ($cover === null) { $cover = new GHEADER_BOL_Cover(); } $extension = UTIL_File::getExtension($sourcePath); $cover->file = uniqid('cover-' . $groupId . '-') . '.' . $extension; $cover->groupId = $groupId; $cover->status = GHEADER_BOL_Cover::STATUS_TMP; $cover->timeStamp = time(); $dimensions = array('height' => $imageHeight, 'width' => $imageWidth); $cover->setSettings(array('photoId' => $photoId, 'dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0))); $this->service->saveCover($cover); $coverPath = $this->service->getCoverPath($cover); OW::getStorage()->copyFile($sourcePath, $coverPath); @unlink($sourcePath); $coverUrl = $this->service->getCoverUrl($cover); return array('src' => $coverUrl, 'data' => $cover->getSettings()); }
public function setCustomDefaultAvatar($size, $file) { $conf = json_decode(OW::getConfig()->getValue('base', 'default_avatar'), true); $dir = OW::getPluginManager()->getPlugin('base')->getUserFilesDir() . 'avatars' . DS; $ext = UTIL_File::getExtension($file['name']); $prefix = 'default_' . ($size == 1 ? self::AVATAR_PREFIX : self::AVATAR_BIG_PREFIX); $fileName = $prefix . uniqid() . '.' . $ext; if (is_uploaded_file($file['tmp_name'])) { $storage = OW::getStorage(); if ($storage->copyFile($file['tmp_name'], $dir . $fileName)) { if (isset($conf[$size])) { $storage->removeFile($dir . $conf[$size]); } $conf[$size] = $fileName; OW::getConfig()->saveConfig('base', 'default_avatar', json_encode($conf)); return true; } } return false; }
private static function getExtension($filenName) { if (strrpos($filenName, '.') == 0) { return null; } return UTIL_File::getExtension($filenName); }
public function processPhotoAttachment(array $fileInfo) { $language = OW::getLanguage(); $error = false; if (!OW::getUser()->isAuthenticated() || empty($fileInfo) || !is_uploaded_file($fileInfo['tmp_name'])) { $error = $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'); } } if (!in_array(UTIL_File::getExtension($_FILES['attachment']['name']), array('jpeg', 'jpg', 'png', 'gif'))) { $error = $language->text('base', 'upload_file_extension_is_not_allowed'); } if ((int) $_FILES['attachment']['size'] > (double) OW::getConfig()->getValue('base', 'tf_max_pic_size') * 1024 * 1024) { $error = $language->text('base', 'upload_file_max_upload_filesize_error'); } if ($error !== false) { throw new InvalidArgumentException($error); } $attachDto = new BOL_Attachment(); $attachDto->setUserId(OW::getUser()->getId()); $attachDto->setAddStamp(time()); $attachDto->setStatus(0); $this->attachmentDao->save($attachDto); $fileName = 'attach_' . $attachDto->getId() . '.' . UTIL_File::getExtension($_FILES['attachment']['name']); $attachDto->setFileName($fileName); $this->attachmentDao->save($attachDto); $uploadPath = $this->getAttachmentsDir() . $fileName; $uploadUrl = $this->getAttachmentsUrl() . $fileName; try { $image = new UTIL_Image($fileInfo['tmp_name']); $image->resizeImage(1000, 1000)->orientateImage()->saveImage($uploadPath); } catch (Exception $e) { throw new InvalidArgumentException($language->text('base', 'upload_file_fail')); } chmod($uploadPath, 0666); return array('genId' => $attachDto->getId(), 'url' => $uploadUrl); }
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'); $this->assign('enableAttachments', $enableAttachments); if ($enableAttachments) { $attachments = FORUM_BOL_PostAttachmentService::getInstance()->findAttachmentsByPostIdList(array($postId)); $this->assign('attachments', $attachments); } $topicInfo = $forumService->getTopicInfo($topicId); $groupUrl = $router->urlForRoute('group-default', array('groupId' => $topicDto->groupId)); $topicUrl = $forumService->getPostUrl($topicId, $postId); $lang->addKeyForJs('forum', 'confirm_delete_attachment'); OW::getDocument()->setHeading(OW::getLanguage()->text('forum', 'edit_post_title')); OW::getDocument()->setHeadingIconClass('ow_ic_edit'); $this->assign('isHidden', $isHidden); if ($isHidden) { $event = new OW_Event('forum.find_forum_caption', array('entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId)); OW::getEventManager()->trigger($event); $eventData = $event->getData(); $componentForumCaption = $eventData['component']; if (!empty($componentForumCaption)) { $this->assign('componentForumCaption', $componentForumCaption->render()); } else { $componentForumCaption = false; $this->assign('componentForumCaption', $componentForumCaption); } $bcItems = array(array('href' => OW::getRouter()->urlForRoute('topic-default', array('topicId' => $topicId)), 'label' => OW::getLanguage()->text('forum', 'back_to_topic'))); $breadCrumbCmp = new BASE_CMP_Breadcrumb($bcItems); $this->addComponent('breadcrumb', $breadCrumbCmp); OW::getNavigation()->deactivateMenuItems(OW_Navigation::MAIN); OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, $forumSection->entity, $eventData['key']); } else { $bcItems = array(array('href' => $router->urlForRoute('forum-default'), 'label' => $lang->text('forum', 'forum_index')), array('href' => $router->urlForRoute('forum-default') . '#section-' . $topicInfo['sectionId'], 'label' => $topicInfo['sectionName']), array('href' => $groupUrl, 'label' => $topicInfo['groupName']), array('href' => $topicUrl, 'label' => htmlspecialchars($topicDto->title))); $breadCrumbCmp = new BASE_CMP_Breadcrumb($bcItems, $lang->text('forum', 'post_location')); $this->addComponent('breadcrumb', $breadCrumbCmp); OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'forum', 'forum'); } }
public function imageUploader($file, $query) { $error = false; $language = OW::getLanguage(); if (!UTIL_File::validateImage($file['name'])) { $error = $language->text('base', 'upload_file_extension_is_not_allowed'); } if ((int) $file['size'] > (double) OW::getConfig()->getValue('base', 'tf_max_pic_size') * 1024 * 1024) { $error = $language->text('base', 'upload_file_max_upload_filesize_error'); } if ($error) { return array('type' => 'uploadError', 'error' => $error, 'result' => $file); } $service = BOL_AttachmentService::getInstance(); $attachDto = new BOL_Attachment(); $attachDto->setUserId(OW::getUser()->getId()); $attachDto->setAddStamp(time()); $attachDto->setStatus(0); $service->saveAttachment($attachDto); $fileName = 'attach_' . $attachDto->getId() . '.' . UTIL_File::getExtension($file['name']); $attachDto->setFileName($fileName); $service->saveAttachment($attachDto); $uploadPath = $service->getAttachmentsTempDir() . $fileName; $uploadUrl = $service->getAttachmentsTempUrl() . $fileName; if (!move_uploaded_file($file['tmp_name'], $uploadPath)) { return array('type' => 'uploadError', 'error' => $language->text('base', 'upload_file_fail'), 'result' => $file); } @chmod($uploadPath, 0666); $markup = array('html' => '<img src="' . $uploadUrl . '" />', 'js' => '', 'css' => ''); $content = new EQUESTIONS_CMP_AttPhotoPreview($uploadUrl); $result = array(); $result['content'] = array('html' => $content->render(), 'js' => '', 'css' => ''); $result['oembed'] = array("type" => "file", 'filePath' => $uploadPath, "fileId" => $attachDto->getId()); $response = array('content' => $markup, 'type' => 'imageUploader', 'result' => $result); return $response; }
/** * Updates gift template image * * @param VIRTUALGIFTS_BOL_Template $template * @param array $file * * @return boolean */ public function updateTemplateImage(VIRTUALGIFTS_BOL_Template $template, $file) { $time = time(); $ext = UTIL_File::getExtension($file['name']); $pluginFilesPath = $this->getGiftPluginFilesPath($template->id, $time, $ext); if (move_uploaded_file($file['tmp_name'], $pluginFilesPath)) { $filePath = $this->getGiftFilePath($template->id, $time, $ext); $storage = OW::getStorage(); $storage->copyFile($pluginFilesPath, $filePath); @unlink($pluginFilesPath); // remove old image $filePath = $this->getGiftFilePath($template->id, $template->uploadTimestamp, $template->extension); $storage->removeFile($filePath); // update template dto $template->extension = $ext; $template->uploadTimestamp = $time; $this->templateDao->save($template); return true; } return false; }
public function fileUpload($params) { if (OW::getRequest()->isAjax()) { exit; } $configs = OW::getConfig()->getValues('mailbox'); $entityId = isset($params['entityId']) ? $params['entityId'] : null; $formElementId = isset($params['formElementId']) ? $params['formElementId'] : null; $language = OW::getLanguage(); $fileService = MAILBOX_BOL_FileUploadService::getInstance(); $file = array(); $message = $language->text('mailbox', 'upload_file_fail'); $error = true; switch (true) { case empty($configs['enable_attachments']): $message = $language->text('mailbox', 'file_attachment_disabled'); break; case !empty($formElementId) && !empty($_FILES['attachmet']) && !empty($entityId) && OW::getUser()->isAuthorized('mailbox', 'send_message'): $list = $fileService->findUploadFileList($entityId); if (count($list) < 5) { $fileDto = new MAILBOX_BOL_FileUpload(); $fileDto->fileName = $_FILES['attachmet']['name']; $fileDto->entityId = $entityId; $fileDto->fileSize = $_FILES['attachmet']['size']; $fileDto->timestamp = time(); $fileDto->userId = OW::getUser()->getId(); $fileDto->hash = uniqid(); $uploadError = $_FILES['attachmet']['error']; switch ($uploadError) { case UPLOAD_ERR_INI_SIZE: $message = $language->text('mailbox', 'upload_file_max_upload_filesize_error'); break; case UPLOAD_ERR_PARTIAL: $message = $language->text('mailbox', 'upload_file_file_partially_uploaded_error'); break; case UPLOAD_ERR_NO_FILE: $message = $language->text('mailbox', 'upload_file_no_file_error'); break; case UPLOAD_ERR_NO_TMP_DIR: $message = $language->text('mailbox', 'upload_file_no_tmp_dir_error'); break; case UPLOAD_ERR_CANT_WRITE: $message = $language->text('mailbox', 'upload_file_cant_write_file_error'); break; case UPLOAD_ERR_EXTENSION: $message = $language->text('mailbox', 'upload_file_invalid_extention_error'); break; case UPLOAD_ERR_OK: $ext = UTIL_File::getExtension($fileDto->fileName); if (!$fileService->fileExtensionIsAllowed($ext)) { $message = $language->text('mailbox', 'upload_file_extension_is_not_allowed'); } else { if ($fileDto->fileSize > (double) $configs['upload_max_file_size'] * 1024 * 1024) { $message = $language->text('mailbox', 'upload_file_max_upload_filesize_error'); } else { if ($fileService->addFile($fileDto, $_FILES['attachmet']['tmp_name'])) { $error = false; $message = ''; $file = array('error' => false, 'filename' => $fileDto->fileName, 'filesize' => round($fileDto->fileSize / 1024, 2) . ' Kb', 'hash' => $fileDto->hash, 'url' => $fileService->getUploadFileUrl($fileDto->hash, UTIL_File::getExtension($fileDto->fileName))); } } } break; } } else { $message = $language->text('mailbox', 'upload_file_count_files_error'); } break; } $file['input_id'] = $formElementId; $file['error'] = $error; $file['message'] = $message; exit("<script>\n parent.window.OW.trigger('mailbox.attach_file_complete', [" . json_encode($file) . "]);\n </script>"); }
public function sendReport($params) { $userId = OW::getUser()->getId(); if (!$userId) { throw new ApiResponseErrorException(); } if (empty($params['entityId']) || empty($params['entityType']) || !isset($params['reason'])) { throw new ApiResponseErrorException(); } $entityId = $params['entityId']; $entityType = $params['entityType']; $userService = BOL_UserService::getInstance(); $lang = OW::getLanguage(); $reasons = array(0 => 'spam', 1 => 'offensive', 2 => 'illegal'); $reason = $lang->text('skadateios', $reasons[$params['reason']]); $user = $userService->findUserById($userId); $assigns = array('reason' => $reason, 'reportedUserUrl' => OW_URL_HOME . 'user/' . $user->getUsername()); switch ($entityType) { case 'photo': if (!is_numeric($entityId)) { $name = substr($entityId, strrpos($entityId, '/') + 1); $parts = explode("_", $name); $entityId = $parts[1]; } $ownerId = PHOTO_BOL_PhotoService::getInstance()->findPhotoOwner($entityId); $reportedUser = $userService->findUserById($ownerId); if (!$reportedUser) { throw new ApiResponseErrorException(); } $assigns['userUrl'] = OW_URL_HOME . 'photo/view/' . $entityId . '/latest'; break; case 'avatar': $ownerId = $entityId; $reportedUser = $userService->findUserById($ownerId); if (!$reportedUser) { throw new ApiResponseErrorException(); } $assigns['userUrl'] = OW_URL_HOME . 'user/' . $reportedUser->getUsername(); break; case 'attachment': $attachment = MAILBOX_BOL_AttachmentDao::getInstance()->findById($entityId); $ext = UTIL_File::getExtension($attachment->fileName); $attachmentPath = MAILBOX_BOL_ConversationService::getInstance()->getAttachmentFilePath($attachment->id, $attachment->hash, $ext, $attachment->fileName); $assigns['userUrl'] = OW::getStorage()->getFileUrl($attachmentPath); break; default: case 'profile': $ownerId = $entityId; $reportedUser = $userService->findUserById($ownerId); if (!$reportedUser) { throw new ApiResponseErrorException(); } $assigns['userUrl'] = OW_URL_HOME . 'user/' . $reportedUser->getUsername(); break; } $subject = $lang->text('skadateios', 'user_reported_subject'); $text = $lang->text('skadateios', 'user_reported_notification_text', $assigns); $html = $lang->text('skadateios', 'user_reported_notification_html', $assigns); try { $email = OW::getConfig()->getValue('base', 'site_email'); $mail = OW::getMailer()->createMail()->addRecipientEmail($email)->setTextContent($text)->setHtmlContent($html)->setSubject($subject); OW::getMailer()->send($mail); } catch (Exception $e) { throw new ApiResponseErrorException(); } }
public function edit($params) { if (!isset($params['id']) || !($id = (int) $params['id'])) { throw new Redirect404Exception(); return; } $language = OW::getLanguage(); $config = OW::getConfig(); $sponsor = SPONSORS_BOL_Service::getInstance()->findSponsorById($id); if (!$sponsor->id) { throw new Redirect404Exception(); return; } $sponsorForm = new Form('sponsorForm'); $sponsorForm->setEnctype('multipart/form-data'); $element = new TextField('sponsorName'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'sponsor_name')); $element->setInvitation($language->text('sponsors', 'sponsor_name_desc')); $element->setValue($sponsor->name); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorEmail'); $element->setRequired(true); $validator = new EmailValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_email_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_email')); $element->setInvitation($language->text('sponsors', 'sponsor_email_desc')); $element->setValue($sponsor->email); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorWebsite'); $element->setRequired(true); $validator = new UrlValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_url_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_website')); $element->setInvitation($language->text('sponsors', 'sponsor_website_desc')); $element->setHasInvitation(true); $element->setValue($sponsor->website); $sponsorForm->addElement($element); $element = new TextField('sponsorAmount'); $element->setRequired(true); $minAmount = $config->getValue('sponsors', 'minimumPayment'); $validator = new FloatValidator(0); $validator->setErrorMessage($language->text('sponsors', 'invalid_amount_value')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_payment_amount')); $element->setInvitation($language->text('sponsors', 'admin_payment_amount_desc')); $element->setHasInvitation(true); $element->setValue($sponsor->price); $sponsorForm->addElement($element); $element = new TextField('sponsorValidity'); $element->setRequired(true); $element->setValue($sponsor->validity); $validator = new IntValidator(0); $validator->setErrorMessage($language->text('sponsors', 'invalid_numeric_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsorship_validatity')); $element->setInvitation($language->text('sponsors', 'sponsorship_validatity_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new FileField('sponsorImage'); $element->setLabel($language->text('sponsors', 'sponsorsh_image_file')); $sponsorForm->addElement($element); $element = new Submit('editSponsor'); $element->setValue(OW::getLanguage()->text('sponsors', 'edit_sponsor_btn')); $sponsorForm->addElement($element); if (OW::getRequest()->isPost()) { if ($sponsorForm->isValid($_POST)) { $values = $sponsorForm->getValues(); $allowedImageExtensions = array('jpg', 'jpeg', 'gif', 'png', 'tiff'); $sponsorImageFile = ""; if (isset($_FILES['sponsorImage']) && in_array(UTIL_File::getExtension($_FILES['sponsorImage']['name']), $allowedImageExtensions)) { $backupPath = OW::getPluginManager()->getPlugin('sponsors')->getUserFilesDir() . $_FILES['sponsorImage']['name']; move_uploaded_file($_FILES['sponsorImage']['tmp_name'], $backupPath); $sponsorImageFile = $_FILES['sponsorImage']['name']; } $sponsor->name = $values['sponsorName']; $sponsor->email = $values['sponsorEmail']; $sponsor->website = $values['sponsorWebsite']; $sponsor->price = $values['sponsorAmount']; if (!empty($sponsorImageFile)) { $sponsor->image = $sponsorImageFile; } $sponsor->userId = $sponsor->userId; $sponsor->status = $sponsor->status; $sponsor->validity = $values['sponsorValidity']; if (SPONSORS_BOL_Service::getInstance()->addSponsor($sponsor)) { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_edit_ok')); } else { OW::getFeedback()->error(OW::getLanguage()->text('sponsors', 'sponsor_edit_error')); } } } $this->addForm($sponsorForm); $fields = array(); foreach ($sponsorForm->getElements() as $element) { if (!$element instanceof HiddenField) { $fields[$element->getName()] = $element->getName(); } } $this->assign('formData', $fields); $this->assign('currentLogoImage', OW::getPluginManager()->getPlugin('sponsors')->getUserFilesUrl() . $sponsor->image); $this->setPageHeading(OW::getLanguage()->text('sponsors', 'edit_sponsor_heading')); $this->setPageTitle(OW::getLanguage()->text('sponsors', 'edit_sponsor_heading')); $this->setPageHeadingIconClass('ow_ic_edit'); }
public function editTemplate($params) { if (OW::getRequest()->isPost() && $_POST['form_name'] == 'edit-template-form') { $tpls = explode('|', $_POST['tplId']); if (!count($tpls)) { $this->redirect(OW::getRouter()->urlForRoute('virtual_gifts_templates')); } $giftsService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance(); foreach ($tpls as $tplId) { $dto = $giftsService->findTemplateById((int) $tplId); if (!$dto) { continue; } $dto->categoryId = !empty($_POST['category']) ? (int) $_POST['category'] : null; $dto->price = !empty($_POST['price']) ? abs(floatval($_POST['price'])) : 0; $giftsService->updateTemplate($dto); $event = new BASE_CLASS_EventCollector('usercredits.action_update'); $event->add(array('pluginKey' => 'virtualgifts', 'action' => 'template_' . $tplId, 'amount' => $dto->price == 0 ? 0 : -$dto->price, 'hidden' => 1)); OW::getEventManager()->trigger($event); if (!empty($_FILES['file']['tmp_name'])) { $extension = UTIL_File::getExtension($_FILES['file']['name']); if ($giftsService->extIsAllowed($extension)) { $giftsService->updateTemplateImage($dto, $_FILES['file']); } } } OW::getFeedback()->info(OW::getLanguage()->text('virtualgifts', 'template_updated')); } $this->redirect(OW::getRouter()->urlForRoute('virtual_gifts_templates')); }
/** * Controller's default action * * @param array $params * @throws AuthenticateException */ public function index(array $params = null) { $groupId = isset($params['groupId']) && (int) $params['groupId'] ? (int) $params['groupId'] : 0; $forumService = FORUM_BOL_ForumService::getInstance(); $forumGroup = $forumService->getGroupInfo($groupId); if ($forumGroup) { $forumSection = $forumService->findSectionById($forumGroup->sectionId); $isHidden = $forumSection->isHidden; } else { $isHidden = false; } if (!OW::getUser()->isAuthenticated()) { throw new AuthenticateException(); } $userId = OW::getUser()->getId(); $this->assign('authMsg', null); if ($isHidden) { //$isModerator = OW::getUser()->isAuthorized($forumSection->entity); //$canEdit = OW::getUser()->isAuthorized($forumSection->entity, 'add_topic'); $eventParams = array('entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId, 'action' => 'add_topic'); $event = new OW_Event('forum.check_permissions', $eventParams); OW::getEventManager()->trigger($event); if (!$event->getData()) { $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html'); return; } $eventParams = array('pluginKey' => $forumSection->entity, 'action' => 'add_post'); $credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams); if ($credits === false) { $this->assign('authMsg', OW::getEventManager()->call('usercredits.error_message', $eventParams)); } $event = new OW_Event('forum.find_forum_caption', array('entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId)); OW::getEventManager()->trigger($event); $eventData = $event->getData(); $componentForumCaption = $eventData['component']; if (!empty($componentForumCaption)) { $this->assign('componentForumCaption', $componentForumCaption->render()); } else { $componentForumCaption = false; $this->assign('componentForumCaption', $componentForumCaption); } $bcItems = array(array('href' => OW::getRouter()->urlForRoute('group-default', array('groupId' => $forumGroup->getId())), 'label' => OW::getLanguage()->text($forumSection->entity, 'view_all_topics'))); $breadCrumbCmp = new BASE_CMP_Breadcrumb($bcItems); $this->addComponent('breadcrumb', $breadCrumbCmp); OW::getNavigation()->deactivateMenuItems(OW_Navigation::MAIN); OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, $forumSection->entity, $eventData['key']); $groupSelect = array(array('label' => $forumGroup->name, 'value' => $forumGroup->getId(), 'disabled' => false)); OW::getDocument()->setHeading(OW::getLanguage()->text($forumSection->entity, 'create_new_topic', array('group' => $forumGroup->name))); } else { $canEdit = OW::getUser()->isAuthorized('forum', 'edit'); if (!$userId || !$canEdit) { $this->assign('authMsg', OW::getLanguage()->text('base', 'authorization_failed_feedback')); } $eventParams = array('pluginKey' => 'forum', 'action' => 'add_post'); $credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams); 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')); } } }
/** * Replaces slide image with a new one * * @param $slideId * @param $file */ public function updateSlideImage($slideId, $file) { if (!$slideId) { return false; } $storage = OW::getStorage(); $slide = $this->findSlideById($slideId); $oldPath = $this->getImageDir($slide->id, $slide->widgetId, $slide->addStamp, $slide->ext); $ext = UTIL_File::getExtension($file['name']); $newAddStamp = time(); $tmpPath = $this->getImageTmpDir($slide->id, $slide->widgetId, $newAddStamp, $slide->ext); $destPath = $this->getImageDir($slide->id, $slide->widgetId, $newAddStamp, $slide->ext); if (move_uploaded_file($file['tmp_name'], $tmpPath)) { $image = new UTIL_Image($tmpPath); $image->resizeImage(1000, null)->saveImage($tmpPath); $slide->width = $image->getWidth(); $slide->height = $image->getHeight(); $slide->ext = $ext; $slide->addStamp = $newAddStamp; $this->slideDao->save($slide); $storage->removeFile($oldPath); $storage->copyFile($tmpPath, $destPath); @unlink($tmpPath); return true; } return false; }
public function deleteAttachment($attId) { /* @var FORUM_BOL_PostAttachment $attachment */ $attachment = $this->findPostAttachmentById($attId); if (!$attachment) { return true; } $ext = UTIL_File::getExtension($attachment->fileName); $path = $this->getAttachmentFilePath($attId, $attachment->hash, $ext, $attachment->fileNameClean); $storage = OW::getStorage(); if ($storage->fileExists($path)) { $storage->removeFile($path); } $this->attachmentDao->deleteById($attId); return true; }
private function addTemplate($file, $roleId = null) { $canvasWidth = self::CANVAS_WIDTH; $canvasHeight = $this->config['cover_height']; $this->validateFile($file); $pluginfilesDir = OW::getPluginManager()->getPlugin('uheader')->getPluginFilesDir(); $tmpTplPath = $pluginfilesDir . uniqid('tmp_') . '.jpg'; if (!move_uploaded_file($file['tmp_name'], $tmpTplPath)) { throw new InvalidArgumentException('Moving uploaded file faild'); } $coverImage = new UTIL_Image($tmpTplPath); $imageHeight = $coverImage->getHeight(); $imageWidth = $coverImage->getWidth(); $css = array('width' => 'auto', 'height' => 'auto'); $tmp = $canvasWidth * $imageHeight / $imageWidth; if ($tmp >= $canvasHeight) { $css['width'] = '100%'; } else { $css['height'] = '100%'; } $this->validateImage($coverImage, $canvasWidth, $canvasHeight); $template = new UHEADER_BOL_Template(); $extension = UTIL_File::getExtension($file['name']); $template->file = uniqid('template-') . '.' . $extension; $template->default = false; $template->timeStamp = time(); $dimensions = array('height' => $imageHeight, 'width' => $imageWidth); $template->setSettings(array('dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0))); $this->service->saveTemplate($template); if ($roleId !== null) { $this->service->saveRoleIdsForTemplateId($template->id, array($roleId)); } $templatePath = $this->service->getTemplatePath($template); OW::getStorage()->copyFile($tmpTplPath, $templatePath); @unlink($tmpTplPath); }
public function moveTemporaryFile($tmpId, $title = '') { $tmp = BOL_FileTemporaryDao::getInstance()->findById($tmpId); $tmpPath = BOL_FileTemporaryService::getInstance()->getTemporaryFilePath($tmpId); if (!$tmp) { throw new LogicException(); } if (!UTIL_File::validateImage($tmp->filename)) { throw new LogicException(); } $image = new BOL_ThemeImage(); $image->addDatetime = time(); $image->title = $title; $dimensions = getimagesize($tmpPath); $image->dimensions = "{$dimensions[0]}x{$dimensions[1]}"; $image->filesize = UTIL_File::getFileSize($tmpPath); $this->themeImageDao->save($image); $ext = UTIL_File::getExtension($tmp->filename); $imageName = 'theme_image_' . $image->getId() . '.' . $ext; $newTempName = $tmp->filename . '.' . $ext; rename($tmp->filename, $newTempName); OW::getStorage()->copyFile($tmpPath, $this->userfileImagesDir . $imageName); if (file_exists($newTempName)) { unlink($newTempName); } BOL_FileTemporaryDao::getInstance()->deleteById($tmpId); $image->setFilename($imageName); $this->themeImageDao->save($image); return $image; }
private function processContent($content) { $resultArray = array('foundLinks' => array(), 'foundImages' => array(), 'meta' => array()); // get all page links $links = array(); preg_match_all('/<a[^<>]+href=["\']([^"\']+)["\']/i', $content, $links, PREG_PATTERN_ORDER); $links = array_unique($links[1]); foreach ($links as $link) { if (mb_strstr($link, 'javascript://')) { continue; } else { if (mb_strstr($link, '.') && in_array(UTIL_File::getExtension($link), array('gif', 'jpg', 'png', 'jpeg'))) { $resultArray['foundImages'][] = $link; continue; } } if (mb_strstr($link, '#')) { $link = mb_substr($link, 0, strpos($link, '#')); } $resultArray['foundLinks'][] = UTIL_String::removeFirstAndLastSlashes($link); } $images = array(); preg_match_all('/<img\\s+src="(.*?)"/i', $content, $images); $images = array_unique($images[1]); foreach ($images as $image) { if (mb_strstr($image, OW_URL_STATIC_THEMES) || !mb_strstr($image, '.') || !in_array(UTIL_File::getExtension($image), array('gif', 'jpg', 'png', 'jpeg'))) { continue; } if (mb_strstr($image, '?')) { $image = substr($image, 0, mb_strpos($image, '?')); } $resultArray['foundImages'][] = $image; } /* spec hack to find hidden images-------------- */ $images = array(); preg_match_all('/showPhotoCmp\\((.+)\\)/i', $content, $images); $imageIds = array_unique($images[1]); if (OW::getPluginManager()->isPluginActive('photo')) { $photoPl = OW::getPluginManager()->getPlugin('photo'); foreach ($imageIds as $id) { if (intval($id) > 0) { $resultArray['foundImages'][] = OW_URL_PLUGIN_USERFILES . $photoPl->getModuleName() . DS . 'photo_original_' . intval($id) . '.jpg'; } } } /* --------------spec hack to find hidden images */ $metaList = array(); preg_match_all('/<meta[^\\<\\>]+>/i', $content, $metaList); foreach ($metaList[0] as $meta) { if (mb_strstr($meta, 'http-equiv="')) { continue; } $nameArray = array(); preg_match_all('/name\\s*=\\s*"(.*?)"/i', $meta, $nameArray); $valueArray = array(); preg_match_all('/content\\s*=\\s*"(.*?)"/i', $meta, $valueArray); if (!empty($nameArray[1][0]) && !empty($valueArray[1][0])) { $resultArray['meta'][$nameArray[1][0]] = $valueArray[1][0]; } } // get title $start = mb_strpos($content, '<title>') + mb_strlen('<title>'); $end = mb_strpos($content, '</title>'); if ($start) { $resultArray['title'] = mb_substr($content, $start, $end - $start); } return $resultArray; }
/** * @param string $file */ public function addImage($file) { if (!is_uploaded_file($file['tmp_name'])) { throw new LogicException(); } if ((int) $file['size'] > self::CONTROL_IMAGE_MAX_FILE_SIZE) { throw new LogicException(); } if (!UTIL_File::validateImage($file['name'])) { throw new LogicException(); } $image = new BOL_ThemeImage(); $this->themeImageDao->save($image); $ext = UTIL_File::getExtension($file['name']); $imageName = 'theme_image_' . $image->getId() . '.' . $ext; //cloudfiles header fix for amazon : need right extension to upload file with right header $newTempName = $file['tmp_name'] . '.' . $ext; rename($file['tmp_name'], $newTempName); OW::getStorage()->copyFile($newTempName, $this->userfileImagesDir . $imageName); if (file_exists($newTempName)) { unlink($newTempName); } $image->setFilename($imageName); $this->themeImageDao->save($image); return $image; }
public function sendMessage($userId, $subject, $message, $attachments = array()) { $conversationService = MAILBOX_BOL_ConversationService::getInstance(); // credits check $creditsEventParams = array('pluginKey' => 'mailbox', 'action' => 'send_message'); if (OW::getEventManager()->call('usercredits.check_balance', $creditsEventParams) === false) { $error = OW::getEventManager()->call('usercredits.error_message', $creditsEventParams); throw new LogicException($error); } $conversation = $conversationService->createConversation($this->userId, $userId, htmlspecialchars($subject), $message); $message = $conversationService->getLastMessages($conversation->id); foreach ($attachments as $fileDto) { $attachmentDto = new MAILBOX_BOL_Attachment(); $attachmentDto->messageId = $message->initiatorMessageId; $attachmentDto->fileName = htmlspecialchars($fileDto->fileName); $attachmentDto->fileSize = $fileDto->fileSize; $attachmentDto->hash = $fileDto->hash; $tmpFilePath = OW::getPluginManager()->getPlugin('mcompose')->getPluginFilesDir() . uniqid('mcomose_') . '.' . UTIL_File::getExtension($fileDto->fileName); if ($conversationService->fileExtensionIsAllowed(UTIL_File::getExtension($fileDto->fileName)) && copy($fileDto->filePath, $tmpFilePath)) { $conversationService->addAttachment($attachmentDto, $tmpFilePath); } } // credits track OW::getEventManager()->call('usercredits.track_action', $creditsEventParams); return true; }
/** * Creates new conversation * * @param int $initiatorId * @param int $interlocutorId */ public function process($initiatorId, $interlocutorId) { if (OW::getRequest()->isAjax()) { if (empty($initiatorId) || empty($interlocutorId)) { echo json_encode(array('result' => false)); exit; } $isAuthorized = OW::getUser()->isAuthorized('mailbox', 'send_message'); if (!$isAuthorized) { echo json_encode(array('result' => 'permission_denied')); exit; } // credits check $eventParams = array('pluginKey' => 'mailbox', 'action' => 'send_message', 'extra' => array('senderId' => $initiatorId, 'recipientId' => $interlocutorId)); $credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams); if ($credits === false) { $error = OW::getEventManager()->call('usercredits.error_message', $eventParams); echo json_encode(array('result' => 'permission_denied', 'message' => $error)); exit; } $captcha = $this->getElement('captcha'); $captcha->setRequired(); if ($this->displayCapcha && (!$captcha->isValid() || !UTIL_Validator::isCaptchaValid($captcha->getValue()))) { echo json_encode(array('result' => 'display_captcha')); exit; } $values = $this->getValues(); $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $uploadFiles = MAILBOX_BOL_FileUploadService::getInstance(); $conversation = $conversationService->createConversation($initiatorId, $interlocutorId, htmlspecialchars($values['subject']), $values['message']); $message = $conversationService->getLastMessages($conversation->id); $fileDtoList = $uploadFiles->findUploadFileList($values['attachments']); foreach ($fileDtoList as $fileDto) { $attachmentDto = new MAILBOX_BOL_Attachment(); $attachmentDto->messageId = $message->initiatorMessageId; $attachmentDto->fileName = htmlspecialchars($fileDto->fileName); $attachmentDto->fileSize = $fileDto->fileSize; $attachmentDto->hash = $fileDto->hash; if ($conversationService->fileExtensionIsAllowed(UTIL_File::getExtension($fileDto->fileName))) { $conversationService->addAttachment($attachmentDto, $fileDto->filePath); } $uploadFiles->deleteUploadFile($fileDto->hash, $fileDto->userId); } // credits track if ($credits === true) { OW::getEventManager()->call('usercredits.track_action', $eventParams); } BOL_PreferenceService::getInstance()->savePreferenceValue('mailbox_create_conversation_display_capcha', false, OW::getUser()->getId()); $timestamp = 0; if ($this->displayCapcha == false) { $timestamp = time(); } BOL_PreferenceService::getInstance()->savePreferenceValue('mailbox_create_conversation_stamp', $timestamp, OW::getUser()->getId()); echo json_encode(array('result' => true)); exit; } }
public function page() { if (!OW::getRequest()->isAjax()) { OW::getNavigation()->activateMenuItem(OW_Navigation::ADMIN_SETTINGS, 'admin', 'sidebar_menu_item_main_settings'); } $language = OW::getLanguage(); $menu = $this->getMenu(); $this->addComponent('menu', $menu); if (!OW::getRequest()->isAjax()) { OW::getDocument()->setHeading(OW::getLanguage()->text('admin', 'heading_page_settings')); OW::getDocument()->setHeadingIconClass('ow_ic_file'); } $form = new Form('page_settings'); $form->setEnctype(Form::ENCTYPE_MULTYPART_FORMDATA); $this->addForm($form); $headCode = new Textarea('head_code'); $headCode->setLabel($language->text('admin', 'page_settings_form_headcode_label')); $headCode->setDescription($language->text('admin', 'page_settings_form_headcode_desc')); $form->addElement($headCode); $bottomCode = new Textarea('bottom_code'); $bottomCode->setLabel($language->text('admin', 'page_settings_form_bottomcode_label')); $bottomCode->setDescription($language->text('admin', 'page_settings_form_bottomcode_desc')); $form->addElement($bottomCode); $favicon = new FileField('favicon'); $favicon->setLabel($language->text('admin', 'page_settings_form_favicon_label')); $favicon->setDescription($language->text('admin', 'page_settings_form_favicon_desc')); $form->addElement($favicon); $enableFavicon = new CheckboxField('enable_favicon'); $form->addElement($enableFavicon); $submit = new Submit('save'); $submit->setValue($language->text('admin', 'save_btn_label')); $form->addElement($submit); $faviconPath = OW::getPluginManager()->getPlugin('base')->getUserFilesDir() . 'favicon.ico'; $faviconUrl = OW::getPluginManager()->getPlugin('base')->getUserFilesUrl() . 'favicon.ico'; $this->assign('faviconSrc', $faviconUrl); if (OW::getRequest()->isPost()) { if ($form->isValid($_POST)) { $data = $form->getValues(); OW::getConfig()->saveConfig('base', 'html_head_code', $data['head_code']); OW::getConfig()->saveConfig('base', 'html_prebody_code', $data['bottom_code']); if (!empty($_FILES['favicon']['name'])) { if ((int) $_FILES['favicon']['error'] === 0 && is_uploaded_file($_FILES['favicon']['tmp_name']) && UTIL_File::getExtension($_FILES['favicon']['name']) === 'ico') { if (file_exists($faviconPath)) { @unlink($faviconPath); } @move_uploaded_file($_FILES['favicon']['tmp_name'], $faviconPath); if (file_exists($_FILES['favicon']['tmp_name'])) { @unlink($_FILES['favicon']['tmp_name']); } } else { OW::getFeedback()->error($language->text('admin', 'page_settings_favicon_submit_error_message')); } } OW::getConfig()->saveConfig('base', 'favicon', !empty($data['enable_favicon'])); OW::getFeedback()->info($language->text('admin', 'settings_submit_success_message')); } else { OW::getFeedback()->error($language->text('admin', 'settings_submit_error_message')); } $this->redirect(); } $headCode->setValue(OW::getConfig()->getValue('base', 'html_head_code')); $bottomCode->setValue(OW::getConfig()->getValue('base', 'html_prebody_code')); $enableFavicon->setValue((int) OW::getConfig()->getValue('base', 'favicon')); $this->assign('faviconEnabled', OW::getConfig()->getValue('base', 'favicon')); $script = "\$('#{$enableFavicon->getId()}').change(function(){ if(this.checked){ \$('#favicon_enabled').show();\$('#favicon_desabled').hide(); \$('{$favicon->getId()}').attr('disabled', true);}else{ \$('#favicon_enabled').hide();\$('#favicon_desabled').show(); \$('{$favicon->getId()}').attr('disabled', false);} });"; OW::getDocument()->addOnloadScript($script); }