Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 public function uploadTmpAvatar($file)
 {
     if (isset($file)) {
         $lang = OW::getLanguage();
         if (!UTIL_File::validateImage($file['name'])) {
             return array('result' => false, 'error' => $lang->text('base', 'not_valid_image'));
         }
         if (!empty($file['error'])) {
             $message = BOL_FileService::getInstance()->getUploadErrorMessage($file['error']);
         }
         if (!empty($message)) {
             return array('result' => false, 'error' => $message);
         }
         $filesize = OW::getConfig()->getValue('base', 'avatar_max_upload_size');
         if (empty($file['size']) || $filesize * 1024 * 1024 < $file['size']) {
             $message = OW::getLanguage()->text('base', 'upload_file_max_upload_filesize_error');
             return array('result' => false, 'error' => $message);
         }
         $avatarService = BOL_AvatarService::getInstance();
         $key = $avatarService->getAvatarChangeSessionKey();
         $uploaded = $avatarService->uploadUserTempAvatar($key, $file['tmp_name']);
         if (!$uploaded) {
             return array('result' => false, 'error' => $lang->text('base', 'upload_avatar_faild'));
         }
         $url = $avatarService->getTempAvatarUrl($key, 3);
         return array('result' => true, 'url' => $url);
     }
     return array('result' => false);
 }
Ejemplo n.º 3
0
 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);
         }
     }
 }
Ejemplo n.º 4
0
 public function processCleanUp()
 {
     $configs = OW::getConfig()->getValues('cacheextreme');
     //clean template cache
     if ($configs['template_cache']) {
         OW_ViewRenderer::getInstance()->clearCompiledTpl();
     }
     //clean db backend cache
     if ($configs['backend_cache']) {
         OW::getCacheManager()->clean(array(), OW_CacheManager::CLEAN_ALL);
     }
     //clean themes static contents cache
     if ($configs['theme_static']) {
         OW::getThemeManager()->getThemeService()->processAllThemes();
     }
     //clean plugins static contents cache
     if ($configs['plugin_static']) {
         $pluginService = BOL_PluginService::getInstance();
         $activePlugins = $pluginService->findActivePlugins();
         /* @var $pluginDto BOL_Plugin */
         foreach ($activePlugins as $pluginDto) {
             $pluginStaticDir = OW_DIR_PLUGIN . $pluginDto->getModule() . DS . 'static' . DS;
             if (file_exists($pluginStaticDir)) {
                 $staticDir = OW_DIR_STATIC_PLUGIN . $pluginDto->getModule() . DS;
                 if (file_exists($staticDir)) {
                     UTIL_File::removeDir($staticDir);
                 }
                 mkdir($staticDir);
                 chmod($staticDir, 0777);
                 UTIL_File::copyDir($pluginStaticDir, $staticDir);
             }
         }
     }
 }
Ejemplo n.º 5
0
 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;
     }
 }
Ejemplo n.º 6
0
 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;
     }
 }
Ejemplo n.º 7
0
 /**
  * @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 ">&nbsp;</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>';
 }
Ejemplo n.º 8
0
 protected function createAvatar($userId)
 {
     $avatarService = BOL_AvatarService::getInstance();
     $path = $_FILES['userPhoto']['tmp_name'];
     if (!file_exists($path)) {
         return false;
     }
     if (!UTIL_File::validateImage($_FILES['userPhoto']['name'])) {
         return false;
     }
     $event = new OW_Event('base.before_avatar_change', array('userId' => $userId, 'avatarId' => null, 'upload' => true, 'crop' => false, 'isModerable' => false));
     OW::getEventManager()->trigger($event);
     $avatarSet = $avatarService->setUserAvatar($userId, $path, array('isModerable' => false, 'trackAction' => false));
     if ($avatarSet) {
         $avatar = $avatarService->findByUserId($userId);
         if ($avatar) {
             $event = new OW_Event('base.after_avatar_change', array('userId' => $userId, 'avatarId' => $avatar->id, 'upload' => true, 'crop' => false));
             OW::getEventManager()->trigger($event);
         }
     }
     return $avatarSet;
 }
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 private function exportThemes(ZipArchive $za, $archiveDir)
 {
     $currentTheme = OW::getThemeManager()->getSelectedTheme()->getDto();
     $currentThemeDir = OW::getThemeManager()->getSelectedTheme()->getRootDir();
     $currentThemeUserfilesDir = OW_DIR_THEME_USERFILES;
     $this->configs['currentTheme'] = array('name' => $currentTheme->name, 'customCss' => $currentTheme->customCss, 'customCssFileName' => $currentTheme->customCssFileName, 'description' => $currentTheme->description, 'isActive' => $currentTheme->isActive, 'sidebarPosition' => $currentTheme->sidebarPosition, 'title' => $currentTheme->title);
     $controlValueList = OW::getDbo()->queryForList(" SELECT * FROM " . BOL_ThemeControlValueDao::getInstance()->getTableName() . " WHERE themeId = :themeId ", array('themeId' => $currentTheme->id));
     foreach ($controlValueList as $controlValue) {
         $this->configs['controlValue'][$controlValue['themeControlKey']] = $controlValue['value'];
     }
     $za->addEmptyDir($archiveDir . '/' . $currentTheme->getName());
     $this->zipFolder($za, $currentThemeDir, $archiveDir . '/' . $currentTheme->getName() . '/');
     $themesDir = Ow::getPluginManager()->getPlugin('dataexporter')->getPluginFilesDir() . 'themes' . DS;
     UTIL_File::copyDir(OW_DIR_THEME_USERFILES, $themesDir);
     $fileList = Ow::getStorage()->getFileNameList(OW_DIR_THEME_USERFILES);
     mkdir($themesDir, 0777);
     foreach ($fileList as $file) {
         if (Ow::getStorage()->isFile($file)) {
             Ow::getStorage()->copyFileToLocalFS($file, $themesDir . mb_substr($file, mb_strlen(OW_DIR_THEME_USERFILES)));
         }
     }
     $za->addEmptyDir($archiveDir . '/themes');
     $this->zipFolder($za, $themesDir, $archiveDir . '/themes/');
 }
Ejemplo n.º 11
0
 /**
  * Update theme info in the [OW_DB_PREFIX]_base_theme table according to the theme.xml file and force theme rebuilding if necessary
  * @param $name
  * @param bool $processTheme
  */
 public function updateThemeInfo($name, $processTheme = false)
 {
     $path = OW_DIR_THEME . $name;
     $xmlFiles = UTIL_File::findFiles($path, array('xml'), 1);
     $themeXml = $xmlFiles[0];
     if (basename($themeXml) === self::MANIFEST_FILE) {
         $xml = simplexml_load_file($themeXml);
         $title = (string) $xml->name;
         $build = (int) $xml->build;
         $developerKey = (string) $xml->developerKey;
         $sidebarPosition = (string) $xml->sidebarPosition;
         if (!in_array(trim($sidebarPosition), array('left', 'right', 'none'))) {
             $sidebarPosition = 'none';
         }
         $xmlArray = (array) $xml;
         unset($xmlArray['masterPages']);
         $description = json_encode($xmlArray);
         if (!trim($title)) {
             $title = $name;
         }
         $theme = $this->findThemeByName($name);
         if (empty($theme)) {
             return;
         }
         $theme->setName($name);
         $theme->setTitle($title);
         $theme->setDescription($description);
         $theme->setSidebarPosition($sidebarPosition);
         $theme->setDeveloperKey($developerKey);
         $this->themeDao->save($theme);
         if ($processTheme) {
             $this->processTheme($theme->getId());
         }
     }
 }
Ejemplo n.º 12
0
 /**
  *
  * @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']);
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * Uploads avatar
  *
  * @return boolean
  */
 public function process()
 {
     $values = $this->getValues();
     $avatarService = BOL_AvatarService::getInstance();
     $userId = OW::getUser()->getId();
     if (strlen($_FILES['avatar']['tmp_name'])) {
         if (!UTIL_File::validateImage($_FILES['avatar']['name'])) {
             return array('result' => false, 'error' => -1);
         }
         $event = new OW_Event('base.before_avatar_change', array('userId' => $userId, 'upload' => true, 'crop' => false));
         OW::getEventManager()->trigger($event);
         $avatarSet = $avatarService->setUserAvatar($userId, $_FILES['avatar']['tmp_name']);
         $event = new OW_Event('base.after_avatar_change', array('userId' => $userId, 'upload' => true, 'crop' => false));
         OW::getEventManager()->trigger($event);
         $avatar = $avatarService->findByUserId($userId);
         if ($avatar) {
             $avatarService->trackAvatarChangeActivity($userId, $avatar->id);
         }
         return array('result' => $avatarSet);
     } else {
         return array('result' => false);
     }
 }
Ejemplo n.º 14
0
 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) {
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Uninstalls plugin.
  *
  * @param string $key
  */
 public function uninstall($key)
 {
     if (empty($key)) {
         throw new LogicException('');
     }
     $pluginDto = $this->findPluginByKey(trim($key));
     if ($pluginDto === null) {
         throw new LogicException('');
     }
     // trigger event
     $event = new OW_Event(OW_EventManager::ON_BEFORE_PLUGIN_UNINSTALL, array('pluginKey' => $pluginDto->getKey()));
     OW::getEventManager()->trigger($event);
     include OW_DIR_PLUGIN . $pluginDto->getModule() . DS . 'deactivate.php';
     // include plugin custom uninstall script
     include OW_DIR_PLUGIN . $pluginDto->getModule() . DS . 'uninstall.php';
     // delete plugin work dirs
     $dirsToRemove = array(OW_DIR_PLUGINFILES . $pluginDto->getModule(), OW_DIR_PLUGIN_USERFILES . $pluginDto->getModule());
     if (!defined('OW_PLUGIN_XP')) {
         $dirsToRemove[] = OW_DIR_STATIC_PLUGIN . $pluginDto->getModule();
     }
     foreach ($dirsToRemove as $dir) {
         if (file_exists($dir)) {
             UTIL_File::removeDir($dir);
         }
     }
     // remove plugin configs
     OW::getConfig()->deletePluginConfigs($pluginDto->getKey());
     // delete language prefix
     $prefixId = BOL_LanguageService::getInstance()->findPrefixId($pluginDto->getKey());
     if (!empty($prefixId)) {
         BOL_LanguageService::getInstance()->deletePrefix($prefixId, true);
     }
     //delete authorization stuff
     BOL_AuthorizationService::getInstance()->deleteGroup($pluginDto->getKey());
     // drop plugin tables
     $tables = OW::getDbo()->queryForColumnList("SHOW TABLES LIKE '" . str_replace('_', '\\_', OW_DB_PREFIX) . $pluginDto->getKey() . "\\_%'");
     if (!empty($tables)) {
         $query = "DROP TABLE ";
         foreach ($tables as $table) {
             $query .= "`" . $table . "`,";
         }
         $query = substr($query, 0, -1);
         OW::getDbo()->query($query);
     }
     //remove entry in DB
     $this->deletePluginById($pluginDto->getId());
 }
Ejemplo n.º 16
0
function uploadPhoto()
{
    global $language;
    global $PHOTO_BOL_PhotoService_inst;
    global $PHOTO_BOL_PhotoAlbumService;
    global $PHOTO_BOL_PhotoTemporaryService;
    global $BOL_AuthorizationService;
    global $getConfig;
    $app = \Slim\Slim::getInstance();
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->setStatus(200);
    $user_id = $app->request()->params('user_id');
    //$data = $_POST;
    //$requdired_data = array("userId");
    //    foreach ($required_data as $rdata) {
    //        if (!array_key_exists($rdata, $data) || empty($data[$rdata])) {
    //            $return = array("message" => "Please enter " . $rdata, "status" => "false");
    //            echo json_encode($return);
    //            exit();
    //        }
    //    }
    $language = $language;
    $userId = $user_id;
    $albumName = "randoms";
    // Delete old temporary photos
    $tmpPhotoService = $PHOTO_BOL_PhotoTemporaryService;
    $photoService = $PHOTO_BOL_PhotoService_inst;
    $photoAlbumService = $PHOTO_BOL_PhotoAlbumService;
    $file = $_FILES['photo'];
    print_r($file);
    die;
    $tmpPhotoService->deleteUserTemporaryPhotos($userId);
    $accepted = floatval($getConfig->getValue('photo', 'accepted_filesize') * 1024 * 1024);
    if (strlen($file['tmp_name'])) {
        if (!UTIL_File::validateImage($file['name']) || $file['size'] > $accepted) {
            $json = array("response_message" => $language->text('photo', 'no_photo_uploaded'), "response_status" => "0");
            $app->response->setBody(json_encode($json));
            //$this->redirect();
        }
        $tmpPhotoService->addTemporaryPhoto($file['tmp_name'], $userId, 1);
        $tmpList = $tmpPhotoService->findUserTemporaryPhotos($userId, 'order');
        $tmpList = array_reverse($tmpList);
        // check album exists
        if (!($album = $photoAlbumService->findAlbumByName($albumName, $userId))) {
            $album = new PHOTO_BOL_PhotoAlbum();
            $album->name = $albumName;
            $album->userId = $userId;
            $album->createDatetime = time();
            $photoAlbumService->addAlbum($album);
        }
        foreach ($tmpList as $tmpPhoto) {
            $photo = $tmpPhotoService->moveTemporaryPhoto($tmpPhoto['dto']->id, $album->id, null);
            if ($photo) {
                $BOL_AuthorizationService->trackAction('photo', 'upload');
                $photoService->createAlbumCover($album->id, array($photo));
                $photoService->triggerNewsfeedEventOnSinglePhotoAdd($album, $photo);
                $photoParams = array('addTimestamp' => $photo->addDatetime, 'photoId' => $photo->id, 'hash' => $photo->hash, 'description' => $photo->description);
                $event = new OW_Event(PHOTO_CLASS_EventHandler::EVENT_ON_PHOTO_ADD, array($photoParams));
                OW::getEventManager()->trigger($event);
                $photo = $photoService->findPhotoById($photo->id);
                if ($photo) {
                    $return_data = array("response_status" => "1", "response_message" => "photo has been uploaded with success!");
                    $app->response->setBody(json_encode($return_data));
                } else {
                    //                    $json = array("message" => "photo not uploaded, something went wrong!", "status" => "false");
                    //                    echo json_encode($json);
                    //                    exit();
                    $return_data = array("response_status" => "0", "response_message" => "photo not uploaded, something went wrong!");
                    $app->response->setBody(json_encode($return_data));
                }
            }
        }
    } else {
        //        $json = array("message" => $language->text('photo', 'no_photo_uploaded'), "status" => "false");
        //        echo json_encode($json);
        //        exit();
        $return_data = array("response_message" => $language->text('photo', 'no_photo_uploaded'), "response_status" => "0");
        $app->response->setBody(json_encode($return_data));
    }
    //  }
}
Ejemplo n.º 17
0
function uploadPhoto()
{
    global $language;
    global $PHOTO_BOL_PhotoTemporaryService;
    global $PHOTO_BOL_PhotoService_inst;
    global $PHOTO_BOL_PhotoAlbumService;
    global $getConfig;
    global $BOL_AuthorizationService;
    $app = \Slim\Slim::getInstance();
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->setStatus(200);
    //Lang Call Start
    $hammu_lang_id = $app->request()->params("lang_id");
    if (!empty($hammu_lang_id)) {
        getCurrentLanguages($hammu_lang_id);
    }
    //Lang Call end
    $user_id = $app->request()->params('user_id');
    $language = $language;
    $userId = $user_id;
    $albumName = "randoms";
    // Delete old temporary photos
    $tmpPhotoService = $PHOTO_BOL_PhotoTemporaryService;
    $photoService = $PHOTO_BOL_PhotoService_inst;
    $photoAlbumService = $PHOTO_BOL_PhotoAlbumService;
    $file = $_FILES['photo'];
    $tmpPhotoService->deleteUserTemporaryPhotos($userId);
    $accepted = floatval($getConfig->getValue('photo', 'accepted_filesize') * 1024 * 1024);
    if (strlen($file['tmp_name'])) {
        if (!UTIL_File::validateImage($file['name']) || $file['size'] > $accepted) {
            $json = array("response_message" => $language->text('photo', 'no_photo_uploaded'), "response_status" => "0");
            $app->response->setBody(json_encode($json));
            //$this->redirect();
        }
        $tmpPhotoService->addTemporaryPhoto($file['tmp_name'], $userId, 1);
        $tmpList = $tmpPhotoService->findUserTemporaryPhotos($userId, 'order');
        $tmpList = array_reverse($tmpList);
        // check album exists
        if (!($album = $photoAlbumService->findAlbumByName($albumName, $userId))) {
            $album = new PHOTO_BOL_PhotoAlbum();
            $album->name = $albumName;
            $album->userId = $userId;
            $album->createDatetime = time();
            $photoAlbumService->addAlbum($album);
        }
        foreach ($tmpList as $tmpPhoto) {
            $photo = $tmpPhotoService->moveTemporaryPhoto($tmpPhoto['dto']->id, $album->id, null);
            if ($photo) {
                $BOL_AuthorizationService->trackAction('photo', 'upload');
                $photoService->createAlbumCover($album->id, array($photo));
                $photoService->triggerNewsfeedEventOnSinglePhotoAdd($album, $photo);
                $photoParams = array('addTimestamp' => $photo->addDatetime, 'photoId' => $photo->id, 'hash' => $photo->hash, 'description' => $photo->description);
                $event = new OW_Event(PHOTO_CLASS_EventHandler::EVENT_ON_PHOTO_ADD, array($photoParams));
                OW::getEventManager()->trigger($event);
                $photo = $photoService->findPhotoById($photo->id);
                $photoDataArr = array('albumId' => $photo->albumId, 'status' => $photo->status, 'hash' => $photo->hash, 'id' => $photo->id, 'uploadKey' => $photo->uploadKey);
                if ($photo) {
                    $message = $language->text("hammu", "photo_upload_success");
                    //"photo has been uploaded successfully!"
                    $return_data = array("response_status" => "1", "response_message" => $message, "data" => $photoDataArr);
                    $app->response->setBody(json_encode($return_data));
                } else {
                    $message = $language->text("hammu", "photo_upload_fail");
                    //"photo not uploaded, something went wrong!"
                    $return_data = array("response_status" => "0", "response_message" => $message);
                    $app->response->setBody(json_encode($return_data));
                }
            }
        }
    } else {
        $return_data = array("response_message" => $language->text('photo', 'no_photo_uploaded'), "response_status" => "0");
        $app->response->setBody(json_encode($return_data));
    }
    //  }
}
Ejemplo n.º 18
0
 /**
  * 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;
     }
 }
Ejemplo n.º 19
0
 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;
 }
Ejemplo n.º 20
0
 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());
 }
Ejemplo n.º 21
0
 public function coreUpdate()
 {
     $this->checkXP();
     if (!(bool) OW::getConfig()->getValue('base', 'update_soft')) {
         throw new Redirect404Exception();
     }
     $language = OW::getLanguage();
     $archivePath = OW_DIR_PLUGINFILES . 'ow' . DS . 'core.zip';
     $tempDir = OW_DIR_PLUGINFILES . 'ow' . DS . 'core' . DS;
     $ftp = $this->getFtpConnection();
     $errorMessage = false;
     OW::getApplication()->setMaintenanceMode(true);
     $this->pluginService->downloadCore($archivePath);
     if (!file_exists($archivePath)) {
         $errorMessage = $language->text('admin', 'core_update_download_error');
     } else {
         mkdir($tempDir);
         $zip = new ZipArchive();
         $zopen = $zip->open($archivePath);
         if ($zopen === true) {
             $zip->extractTo($tempDir);
             $zip->close();
             $ftp->uploadDir($tempDir, OW_DIR_ROOT);
             $ftp->chmod(0777, OW_DIR_STATIC);
             $ftp->chmod(0777, OW_DIR_STATIC_PLUGIN);
         } else {
             $errorMessage = $language->text('admin', 'core_update_unzip_error');
         }
     }
     if (file_exists($tempDir)) {
         UTIL_File::removeDir($tempDir);
     }
     if (file_exists($archivePath)) {
         unlink($archivePath);
     }
     if ($errorMessage !== false) {
         OW::getApplication()->setMaintenanceMode(false);
         OW::getFeedback()->error($errorMessage);
         $this->redirect(OW::getRouter()->urlFor('ADMIN_CTRL_Index', 'index'));
     }
     $this->redirect(OW_URL_HOME . 'ow_updates/index.php');
 }
Ejemplo n.º 22
0
 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');
 }
Ejemplo n.º 23
0
 * use this file except in compliance with the License. You may obtain a copy
 * of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
try {
    $sql = "SHOW COLUMNS FROM `" . OW_DB_PREFIX . "video_clip` LIKE 'plugin';";
    $cols = Updater::getDbo()->queryForList($sql);
    if (!count($cols)) {
        $sql = "ALTER TABLE `" . OW_DB_PREFIX . "video_clip` ADD `plugin` VARCHAR(255) NULL DEFAULT 'video' ; ";
        Updater::getDbo()->update($sql);
    }
} catch (Exception $e) {
}
// refresh static cache
$plugin = OW::getPluginManager()->getPlugin('spvideolite');
$staticDir = OW_DIR_STATIC_PLUGIN . $plugin->getModuleName() . DS;
$pluginStaticDir = OW_DIR_PLUGIN . $plugin->getModuleName() . DS . 'static' . DS;
if (file_exists($staticDir)) {
    UTIL_File::removeDir($staticDir);
}
mkdir($staticDir);
chmod($staticDir, 0777);
UTIL_File::copyDir($pluginStaticDir, $staticDir);
Ejemplo n.º 24
0
 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);
 }
Ejemplo n.º 25
0
 public function createAvatar($userId, $isModerable = true, $trackAction = true)
 {
     $key = $this->getAvatarChangeSessionKey();
     $path = $this->getTempAvatarPath($key, 2);
     if (!file_exists($path)) {
         return false;
     }
     if (!UTIL_File::validateImage($path)) {
         return false;
     }
     $event = new OW_Event('base.before_avatar_change', array('userId' => $userId, 'avatarId' => null, 'upload' => true, 'crop' => false, 'isModerable' => $isModerable));
     OW::getEventManager()->trigger($event);
     $avatarSet = $this->setUserAvatar($userId, $path, array('isModerable' => $isModerable, 'trackAction' => $trackAction));
     if ($avatarSet) {
         $avatar = $this->findByUserId($userId);
         if ($avatar) {
             $event = new OW_Event('base.after_avatar_change', array('userId' => $userId, 'avatarId' => $avatar->id, 'upload' => true, 'crop' => false));
             OW::getEventManager()->trigger($event);
         }
         $this->deleteUserTempAvatar($key);
     }
     return $avatarSet;
 }
Ejemplo n.º 26
0
 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;
 }
Ejemplo n.º 27
0
 public function edit(array $params)
 {
     if (empty($params['id'])) {
         throw new Redirect404Exception();
     }
     $projectId = (int) $params['id'];
     $service = OCSFUNDRAISING_BOL_Service::getInstance();
     $project = $service->getGoalById($projectId);
     if (!$project) {
         throw new Redirect404Exception();
     }
     $viewerId = OW::getUser()->getId();
     $isOwner = $viewerId && $project['dto']->ownerId == $viewerId;
     if (!$isOwner) {
         throw new Redirect404Exception();
     }
     $lang = OW::getLanguage();
     $form = new OCSFUNDRAISING_CLASS_GoalEditForm();
     $this->addForm($form);
     $service = OCSFUNDRAISING_BOL_Service::getInstance();
     $goal = $service->getGoalById($projectId);
     if (OW::getRequest()->isPost() && $form->isValid($_POST)) {
         $values = $form->getValues();
         $goal = $goal['dto'];
         $goal->name = trim($values['name']);
         $goal->description = UTIL_HtmlTag::stripJs($values['description']);
         $goal->amountMin = floatval($values['min']);
         $goal->amountTarget = floatval($values['target']);
         $goal->ownerType = 'user';
         $goal->ownerId = OW::getUser()->getId();
         $date = explode('/', $values['end']);
         if (!empty($date[1]) && !empty($date[2]) && !empty($date[0])) {
             $goal->endStamp = mktime(0, 0, 0, $date[1], $date[2], $date[0]);
         }
         $goal->categoryId = (int) $values['category'];
         $imageValid = true;
         $imagePosted = false;
         if (!empty($_FILES['image']['name'])) {
             if ((int) $_FILES['image']['error'] !== 0 || !is_uploaded_file($_FILES['image']['tmp_name']) || !UTIL_File::validateImage($_FILES['image']['name'])) {
                 $imageValid = false;
                 OW::getFeedback()->error($lang->text('base', 'not_valid_image'));
             } else {
                 $imagePosted = true;
             }
         }
         if ($imagePosted && $imageValid) {
             $service->saveImage($goal->id, $_FILES['image']['tmp_name'], $goal->image);
         }
         $service->update($goal);
         OW::getFeedback()->info($lang->text('ocsfundraising', 'goal_updated'));
         $this->redirect(OW::getRouter()->urlForRoute('ocsfundraising.project', array('id' => $projectId)));
     }
     $form->getElement('projectId')->setValue($projectId);
     $form->getElement('name')->setValue($goal['dto']->name);
     $form->getElement('description')->setValue($goal['dto']->description);
     $form->getElement('target')->setValue($goal['dto']->amountTarget);
     $form->getElement('min')->setValue(floatval($goal['dto']->amountMin));
     $form->getElement('category')->setValue(floatval($goal['dto']->categoryId));
     if ($goal['dto']->endStamp) {
         $date = date('Y/m/d', $goal['dto']->endStamp);
         $form->getElement('end')->setValue($date);
     }
     $image = $goal['dto']->image ? $service->generateImageUrl($goal['dto']->image, true) : null;
     $this->assign('image', $image);
     $this->setPageHeading($lang->text('ocsfundraising', 'edit_project'));
     $this->setPageTitle($lang->text('ocsfundraising', 'edit_project'));
     OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'ocsfundraising', 'projects');
 }
Ejemplo n.º 28
0
 protected function updateCachedEntities($options)
 {
     $options = intval($options);
     if ($options === 1 || $options & 1 << 1) {
         OW_ViewRenderer::getInstance()->clearCompiledTpl();
     }
     if ($options === 1 || $options & 1 << 2) {
         BOL_ThemeService::getInstance()->updateThemeList();
         BOL_ThemeService::getInstance()->processAllThemes();
         if (OW::getConfig()->configExists('base', 'cachedEntitiesPostfix')) {
             OW::getConfig()->saveConfig('base', 'cachedEntitiesPostfix', uniqid());
         }
         $event = new OW_Event('base.update_cache_entities');
         OW::getEventManager()->trigger($event);
     }
     if ($options === 1 || $options & 1 << 3) {
         BOL_LanguageService::getInstance()->generateCacheForAllActiveLanguages();
     }
     if ($options === 1 || $options & 1 << 4) {
         OW::getCacheManager()->clean(array(), OW_CacheManager::CLEAN_ALL);
     }
     if (($options === 1 || $options & 1 << 5) && !defined('OW_PLUGIN_XP')) {
         $pluginService = BOL_PluginService::getInstance();
         $activePlugins = $pluginService->findActivePlugins();
         /* @var $pluginDto BOL_Plugin */
         foreach ($activePlugins as $pluginDto) {
             $pluginStaticDir = OW_DIR_PLUGIN . $pluginDto->getModule() . DS . 'static' . DS;
             if (file_exists($pluginStaticDir)) {
                 $staticDir = OW_DIR_STATIC_PLUGIN . $pluginDto->getModule() . DS;
                 if (!file_exists($staticDir)) {
                     mkdir($staticDir);
                     chmod($staticDir, 0777);
                 }
                 UTIL_File::copyDir($pluginStaticDir, $staticDir);
             }
         }
     }
 }
Ejemplo n.º 29
0
 private function cleanImportDir($dir)
 {
     $dh = opendir($dir);
     while ($node = readdir($dh)) {
         if ($node == '.' || $node == '..') {
             continue;
         }
         if (is_dir($dir . $node)) {
             UTIL_File::removeDir($dir . $node);
             continue;
         }
         unlink($dir . $node);
     }
 }
Ejemplo n.º 30
0
    /**
     * 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'));
            }
        }
    }