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);
 }
Example #2
0
 private function validateFile($file)
 {
     $language = OW::getLanguage();
     if (!UTIL_File::validateImage($file['name'])) {
         $error = $language->text('gheader', 'upload_file_extension_is_not_allowed');
         throw new InvalidArgumentException($error);
     }
     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');
         throw new InvalidArgumentException($error);
     }
 }
Example #3
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;
 }
Example #4
0
 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;
 }
Example #5
0
 public function user()
 {
     if (!OW::getRequest()->isAjax()) {
         OW::getNavigation()->activateMenuItem(OW_Navigation::ADMIN_SETTINGS, 'admin', 'sidebar_menu_item_user_settings');
     }
     $language = OW::getLanguage();
     $avatarService = BOL_AvatarService::getInstance();
     if (isset($_GET['del-avatar']) && in_array($_GET['del-avatar'], array(1, 2))) {
         $del = $avatarService->deleteCustomDefaultAvatar((int) $_GET['del-avatar']);
         if ($del) {
             OW::getFeedback()->info($language->text('admin', 'default_avatar_deleted'));
         }
         $this->redirect(OW::getRouter()->urlForRoute('admin_settings_user'));
     }
     $uploadMaxFilesize = (double) ini_get("upload_max_filesize");
     $postMaxSize = (double) ini_get("post_max_size");
     $maxUploadMaxFilesize = BOL_FileService::getInstance()->getUploadMaxFilesize();
     $this->assign('maxUploadMaxFilesize', $maxUploadMaxFilesize);
     $userSettingsForm = new UserSettingsForm($maxUploadMaxFilesize);
     $this->addForm($userSettingsForm);
     $conf = OW::getConfig();
     $avatarSize = $conf->getValue('base', 'avatar_size');
     $bigAvatarSize = $conf->getValue('base', 'avatar_big_size');
     $avatarUploadSize = $conf->getValue('base', 'avatar_max_upload_size');
     $userSettingsForm->getElement('avatar_max_upload_size')->setValue((double) $avatarUploadSize);
     $userSettingsForm->getElement('avatarSize')->setValue($avatarSize);
     $userSettingsForm->getElement('bigAvatarSize')->setValue($bigAvatarSize);
     $userSettingsForm->getElement('displayName')->setValue($conf->getValue('base', 'display_name_question'));
     // privacy
     $userSettingsForm->getElement('who_can_join')->setValue($conf->getValue('base', 'who_can_join'));
     $userSettingsForm->getElement('who_can_invite')->setValue($conf->getValue('base', 'who_can_invite'));
     $userSettingsForm->getElement('guests_can_view')->setValue($conf->getValue('base', 'guests_can_view'));
     $userSettingsForm->getElement('user_approve')->setValue($conf->getValue('base', 'mandatory_user_approve'));
     // profile questions
     $userSettingsForm->getElement('user_view_presentation')->setValue(OW::getConfig()->getValue('base', 'user_view_presentation') == 'tabs');
     $this->assign('displayConfirmEmail', !defined('OW_PLUGIN_XP'));
     if (OW::getRequest()->isPost() && $userSettingsForm->isValid($_POST)) {
         if (!empty($_FILES['avatar']['tmp_name']) && !UTIL_File::validateImage($_FILES['avatar']['name']) || !empty($_FILES['bigAvatar']['tmp_name']) && !UTIL_File::validateImage($_FILES['bigAvatar']['name'])) {
             OW::getFeedback()->error($language->text('base', 'not_valid_image'));
             $this->redirect();
         }
         $values = $userSettingsForm->getValues();
         $guestPassword = OW_Config::getInstance()->getValue('base', 'guests_can_view_password');
         if ((int) $values['guests_can_view'] === 3 && empty($values['password']) && is_null($guestPassword)) {
             OW::getFeedback()->error($language->text('admin', 'permission_global_privacy_empty_pass_error_message'));
             $this->redirect();
         } else {
             if ((int) $values['guests_can_view'] === 3 && strlen(trim($values['password'])) < 4 && strlen(trim($values['password'])) > 0) {
                 OW::getFeedback()->error($language->text('admin', 'permission_global_privacy_pass_length_error_message'));
                 $this->redirect();
             }
         }
         $res = $userSettingsForm->process();
         OW::getFeedback()->info($language->text('admin', 'user_settings_updated'));
         $this->redirect();
     }
     $avatar = $avatarService->getDefaultAvatarUrl(1);
     $avatarBig = $avatarService->getDefaultAvatarUrl(2);
     $this->assign('avatar', $avatar);
     $this->assign('avatarBig', $avatarBig);
     $custom = json_decode($conf->getValue('base', 'default_avatar'), true);
     $this->assign('customAvatar', $custom);
     $language->addKeyForJs('admin', 'confirm_avatar_delete');
     if (!OW::getRequest()->isAjax()) {
         OW::getDocument()->setHeading(OW::getLanguage()->text('admin', 'heading_user_settings'));
         OW::getDocument()->setHeadingIconClass('ow_ic_gear_wheel');
     }
     OW::getNavigation()->deactivateMenuItems(OW_Navigation::ADMIN_SETTINGS);
 }
Example #6
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));
    }
    //  }
}
Example #7
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;
 }
Example #8
0
 /**
  * @see OW_Validator::isValid()
  *
  * @param mixed $value
  */
 public function isValid($value)
 {
     if (empty($value)) {
         return true;
     }
     $realName = $value['name'];
     $tmpName = $value['tmp_name'];
     switch (false) {
         case is_uploaded_file($tmpName):
             $this->setErrorMessage(OW::getLanguage()->text('groups', 'errors_image_upload'));
             return false;
         case UTIL_File::validateImage($realName):
             $this->setErrorMessage(OW::getLanguage()->text('groups', 'errors_image_invalid'));
             return false;
     }
     return true;
 }
Example #9
0
 /**
  * Add file
  * 
  * @param string $plugin
  * @return integer|string
  */
 public static function addFile($plugin)
 {
     $uploaddir = OW::getPluginManager()->getPlugin('base')->getUserFilesDir();
     $name = $_FILES['file']['name'];
     if (!UTIL_File::validateImage($name)) {
         return OW::getLanguage()->text('base', 'invalid_file_type_acceptable_file_types_jpg_png_gif');
     }
     $tmpname = $_FILES['file']['tmp_name'];
     if ((int) $_FILES['file']['size'] > (double) OW::getConfig()->getValue('base', 'tf_max_pic_size') * 1024 * 1024) {
         return OW::getLanguage()->text('base', 'upload_file_max_upload_filesize_error');
     }
     $image = new UTIL_Image($tmpname);
     $height = $image->getHeight();
     $width = $image->getWidth();
     $id = BOL_MediaPanelService::getInstance()->add($plugin, 'image', OW::getUser()->getId(), array('name' => $name, 'height' => $height, 'width' => $width));
     OW::getStorage()->copyFile($tmpname, $uploaddir . $id . '-' . $name);
     @unlink($tmpname);
     return $id;
 }
Example #10
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));
    }
    //  }
}
Example #11
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);
     }
 }
 public function getAttachmentType(MAILBOX_BOL_Attachment $attachment)
 {
     $type = 'doc';
     if (UTIL_File::validateImage($attachment->fileName)) {
         $type = 'image';
     }
     return $type;
 }
Example #13
0
 public function edit($params)
 {
     $event = $this->getEventForParams($params);
     $language = OW::getLanguage();
     $modPermissions = OW::getUser()->isAuthorized('eventx');
     $ownerMode = $event->getUserId() == OW::getUser()->getId();
     if (!$ownerMode && !$modPermissions) {
         $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html');
         return;
     }
     $form = new EventAddForm('event_edit');
     $form->getElement('title')->setValue($event->getTitle());
     $form->getElement('desc')->setValue($event->getDescription());
     $form->getElement('location')->setValue($event->getLocation());
     $form->getElement('who_can_view')->setValue($event->getWhoCanView());
     $form->getElement('who_can_invite')->setValue($event->getWhoCanInvite());
     $form->getElement('who_can_invite')->setValue($event->getWhoCanInvite());
     $form->getElement('max_invites')->setValue($event->getMaxInvites());
     if (OW::getConfig()->getValue('eventx', 'enableCategoryList') == '1') {
         $catIds = $this->eventService->getItemCategoryId($event->id);
         $eventCategories = array();
         foreach ($catIds as $categoryObj) {
             $eventCategories[] = $categoryObj->categoryId;
         }
         if (OW::getConfig()->getValue('eventx', 'enableMultiCategories') == 1) {
             $form->getElement('event_category')->setValue($eventCategories);
         } else {
             $form->getElement('event_category')->setValue($eventCategories[0]);
         }
     }
     if (OW::getConfig()->getValue('eventx', 'enableTagsList') == '1') {
         $entityTags = BOL_TagService::getInstance()->findEntityTags($event->getId(), 'eventx');
         if ($entityTags) {
             $tags = array();
             foreach ($entityTags as $entityTag) {
                 $tags[] = $entityTag->getLabel();
             }
             $form->getElement('tags')->setValue($tags);
         }
     }
     $startTimeArray = array('hour' => date('G', $event->getStartTimeStamp()), 'minute' => date('i', $event->getStartTimeStamp()));
     $form->getElement('start_time')->setValue($startTimeArray);
     $startDate = date('Y', $event->getStartTimeStamp()) . '/' . date('n', $event->getStartTimeStamp()) . '/' . date('j', $event->getStartTimeStamp());
     $form->getElement('start_date')->setValue($startDate);
     if ($event->getEndTimeStamp() !== null) {
         $endTimeArray = array('hour' => date('G', $event->getEndTimeStamp()), 'minute' => date('i', $event->getEndTimeStamp()));
         $form->getElement('end_time')->setValue($endTimeArray);
         $endTimeStamp = $event->getEndTimeStamp();
         if ($event->getEndTimeDisable()) {
             $endTimeStamp = strtotime("-1 day", $endTimeStamp);
         }
         $endDate = date('Y', $endTimeStamp) . '/' . date('n', $endTimeStamp) . '/' . date('j', $endTimeStamp);
         $form->getElement('end_date')->setValue($endDate);
     }
     if ($event->getStartTimeDisable()) {
         $form->getElement('start_time')->setValue('all_day');
     }
     if ($event->getEndTimeDisable()) {
         $form->getElement('end_time')->setValue('all_day');
     }
     $form->getSubmitElement('submit')->setValue(OW::getLanguage()->text('eventx', 'edit_form_submit_label'));
     $checkboxId = UTIL_HtmlTag::generateAutoId('chk');
     $tdId = UTIL_HtmlTag::generateAutoId('td');
     $this->assign('tdId', $tdId);
     $this->assign('chId', $checkboxId);
     OW::getDocument()->addScript(OW::getPluginManager()->getPlugin("eventx")->getStaticJsUrl() . 'eventx.js');
     $enableMapSuggestion = OW::getConfig()->getValue('eventx', 'enableMapSuggestion');
     if ($enableMapSuggestion == '1') {
         OW::getDocument()->addScript("http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places");
         OW::getDocument()->addScript(OW::getPluginManager()->getPlugin("eventx")->getStaticJsUrl() . 'jquery.geocomplete.min.js');
     }
     $this->assign('enableMapSuggestion', $enableMapSuggestion);
     OW::getDocument()->addOnloadScript("new eventAddForm(" . json_encode(array('checkbox_id' => $checkboxId, 'end_date_id' => $form->getElement('end_date')->getId(), 'tdId' => $tdId)) . ")");
     if ($event->getImage()) {
         $this->assign('imgsrc', $this->eventService->generateImageUrl($event->getImage(), true));
     }
     $endDateFlag = $event->getEndDateFlag();
     if (OW::getRequest()->isPost()) {
         $endDateFlag = !empty($_POST['endDateFlag']);
         if ($form->isValid($_POST)) {
             $data = $form->getValues();
             $serviceEvent = new OW_Event(EVENTX_BOL_EventService::EVENTX_BEFORE_EVENTX_EDIT, array('eventId' => $event->id), $data);
             OW::getEventManager()->trigger($serviceEvent);
             $data = $serviceEvent->getData();
             $dateArray = explode('/', $data['start_date']);
             $startStamp = mktime(0, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0]);
             if ($data['start_time'] != 'all_day') {
                 $startStamp = mktime($data['start_time']['hour'], $data['start_time']['minute'], 0, $dateArray[1], $dateArray[2], $dateArray[0]);
             }
             if (!empty($_POST['endDateFlag']) && !empty($data['end_date'])) {
                 $dateArray = explode('/', $data['end_date']);
                 $endStamp = mktime(0, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0]);
                 $endStamp = strtotime("+1 day", $endStamp);
                 if ($data['end_time'] != 'all_day') {
                     $hour = 0;
                     $min = 0;
                     if ($data['end_time'] != 'all_day') {
                         $hour = $data['end_time']['hour'];
                         $min = $data['end_time']['minute'];
                     }
                     $dateArray = explode('/', $data['end_date']);
                     $endStamp = mktime($hour, $min, 0, $dateArray[1], $dateArray[2], $dateArray[0]);
                 }
             }
             $event->setStartTimeStamp($startStamp);
             if (empty($endStamp)) {
                 $endStamp = strtotime("+1 day", $startStamp);
                 $endStamp = mktime(0, 0, 0, date('n', $endStamp), date('j', $endStamp), date('Y', $endStamp));
             }
             if ($startStamp > $endStamp) {
                 OW::getFeedback()->error($language->text('eventx', 'add_form_invalid_end_date_error_message'));
                 $this->redirect();
             } else {
                 $event->setEndTimeStamp($endStamp);
                 if (!empty($_FILES['image']['name'])) {
                     if ((int) $_FILES['image']['error'] !== 0 || !is_uploaded_file($_FILES['image']['tmp_name']) || !UTIL_File::validateImage($_FILES['image']['name'])) {
                         OW::getFeedback()->error($language->text('base', 'not_valid_image'));
                         $this->redirect();
                     } else {
                         $event->setImage(uniqid());
                         $this->eventService->saveEventImage($_FILES['image']['tmp_name'], $event->getImage());
                     }
                 }
                 $event->setTitle(htmlspecialchars($data['title']));
                 $event->setLocation(UTIL_HtmlTag::autoLink(strip_tags($data['location'])));
                 $event->setWhoCanView((int) $data['who_can_view']);
                 $event->setWhoCanInvite((int) $data['who_can_invite']);
                 $event->setDescription($data['desc']);
                 $event->setEndDateFlag(!empty($_POST['endDateFlag']));
                 $event->setStartTimeDisable($data['start_time'] == 'all_day');
                 $event->setEndTimeDisable($data['end_time'] == 'all_day');
                 $event->setMaxInvites($data['max_invites']);
                 $this->eventService->saveEvent($event);
                 $eventCategory = isset($data['event_category']) ? $data['event_category'] : 1;
                 $this->eventService->setItemCategories($event->getId(), $eventCategory);
                 if (isset($data['tags'])) {
                     $tags = array();
                     $tags = $data['tags'];
                     foreach ($tags as $id => $tag) {
                         $tags[$id] = UTIL_HtmlTag::stripTags($tag);
                     }
                     BOL_TagService::getInstance()->updateEntityTags($event->id, 'eventx', $tags);
                 }
                 $e = new OW_Event(EVENTX_BOL_EventService::EVENTX_AFTER_EVENTX_EDIT, array('eventId' => $event->id));
                 OW::getEventManager()->trigger($e);
                 OW::getFeedback()->info($language->text('eventx', 'edit_form_success_message'));
                 $this->redirect(OW::getRouter()->urlForRoute('eventx.view', array('eventId' => $event->getId())));
             }
         }
     }
     if (!$endDateFlag) {
         $form->getElement('end_date')->addAttribute('disabled', 'disabled');
         $form->getElement('end_date')->addAttribute('style', 'display:none;');
         $form->getElement('end_time')->addAttribute('disabled', 'disabled');
         $form->getElement('end_time')->addAttribute('style', 'display:none;');
     }
     $this->assign('endDateFlag', $endDateFlag);
     $this->setPageHeading($language->text('eventx', 'edit_page_heading'));
     $this->setPageTitle($language->text('eventx', 'edit_page_title'));
     $this->addForm($form);
 }
Example #14
0
 /**
  * Update event controller
  * 
  * @param array $params 
  */
 public function edit($params)
 {
     $event = $this->getEventForParams($params);
     $language = OW::getLanguage();
     $form = new EventAddForm('event_edit');
     $form->getElement('title')->setValue($event->getTitle());
     $form->getElement('desc')->setValue($event->getDescription());
     $form->getElement('location')->setValue($event->getLocation());
     $form->getElement('who_can_view')->setValue($event->getWhoCanView());
     $form->getElement('who_can_invite')->setValue($event->getWhoCanInvite());
     $form->getElement('who_can_invite')->setValue($event->getWhoCanInvite());
     $startTimeArray = array('hour' => date('G', $event->getStartTimeStamp()), 'minute' => date('i', $event->getStartTimeStamp()));
     $form->getElement('start_time')->setValue($startTimeArray);
     $startDate = date('Y', $event->getStartTimeStamp()) . '/' . date('n', $event->getStartTimeStamp()) . '/' . date('j', $event->getStartTimeStamp());
     $form->getElement('start_date')->setValue($startDate);
     if ($event->getEndTimeStamp() !== null) {
         $endTimeArray = array('hour' => date('G', $event->getEndTimeStamp()), 'minute' => date('i', $event->getEndTimeStamp()));
         $form->getElement('end_time')->setValue($endTimeArray);
         $endTimeStamp = $event->getEndTimeStamp();
         if ($event->getEndTimeDisable()) {
             $endTimeStamp = strtotime("-1 day", $endTimeStamp);
         }
         $endDate = date('Y', $endTimeStamp) . '/' . date('n', $endTimeStamp) . '/' . date('j', $endTimeStamp);
         $form->getElement('end_date')->setValue($endDate);
     }
     if ($event->getStartTimeDisable()) {
         $form->getElement('start_time')->setValue('all_day');
     }
     if ($event->getEndTimeDisable()) {
         $form->getElement('end_time')->setValue('all_day');
     }
     $form->getSubmitElement('submit')->setValue(OW::getLanguage()->text('event', 'edit_form_submit_label'));
     $checkboxId = UTIL_HtmlTag::generateAutoId('chk');
     $tdId = UTIL_HtmlTag::generateAutoId('td');
     $this->assign('tdId', $tdId);
     $this->assign('chId', $checkboxId);
     OW::getDocument()->addScript(OW::getPluginManager()->getPlugin("event")->getStaticJsUrl() . 'event.js');
     OW::getDocument()->addOnloadScript("new eventAddForm(" . json_encode(array('checkbox_id' => $checkboxId, 'end_date_id' => $form->getElement('end_date')->getId(), 'tdId' => $tdId)) . ")");
     if ($event->getImage()) {
         $this->assign('imgsrc', $this->eventService->generateImageUrl($event->getImage(), true));
     }
     $endDateFlag = $event->getEndDateFlag();
     if (OW::getRequest()->isPost()) {
         $endDateFlag = !empty($_POST['endDateFlag']);
         //$this->assign('endDateFlag', !empty($_POST['endDateFlag']));
         if ($form->isValid($_POST)) {
             $data = $form->getValues();
             $serviceEvent = new OW_Event(EVENT_BOL_EventService::EVENT_BEFORE_EVENT_EDIT, array('eventId' => $event->id), $data);
             OW::getEventManager()->trigger($serviceEvent);
             $data = $serviceEvent->getData();
             $dateArray = explode('/', $data['start_date']);
             $startStamp = mktime(0, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0]);
             if ($data['start_time'] != 'all_day') {
                 $startStamp = mktime($data['start_time']['hour'], $data['start_time']['minute'], 0, $dateArray[1], $dateArray[2], $dateArray[0]);
             }
             if (!empty($_POST['endDateFlag']) && !empty($data['end_date'])) {
                 $dateArray = explode('/', $data['end_date']);
                 $endStamp = mktime(0, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0]);
                 $endStamp = strtotime("+1 day", $endStamp);
                 if ($data['end_time'] != 'all_day') {
                     $hour = 0;
                     $min = 0;
                     if ($data['end_time'] != 'all_day') {
                         $hour = $data['end_time']['hour'];
                         $min = $data['end_time']['minute'];
                     }
                     $dateArray = explode('/', $data['end_date']);
                     $endStamp = mktime($hour, $min, 0, $dateArray[1], $dateArray[2], $dateArray[0]);
                 }
             }
             $event->setStartTimeStamp($startStamp);
             if (empty($endStamp)) {
                 $endStamp = strtotime("+1 day", $startStamp);
                 $endStamp = mktime(0, 0, 0, date('n', $endStamp), date('j', $endStamp), date('Y', $endStamp));
             }
             if ($startStamp > $endStamp) {
                 OW::getFeedback()->error($language->text('event', 'add_form_invalid_end_date_error_message'));
                 $this->redirect();
             } else {
                 $event->setEndTimeStamp($endStamp);
                 if (!empty($_FILES['image']['name'])) {
                     if ((int) $_FILES['image']['error'] !== 0 || !is_uploaded_file($_FILES['image']['tmp_name']) || !UTIL_File::validateImage($_FILES['image']['name'])) {
                         OW::getFeedback()->error($language->text('base', 'not_valid_image'));
                         $this->redirect();
                     } else {
                         $event->setImage(uniqid());
                         $this->eventService->saveEventImage($_FILES['image']['tmp_name'], $event->getImage());
                     }
                 }
                 $event->setTitle(htmlspecialchars($data['title']));
                 $event->setLocation(UTIL_HtmlTag::autoLink(strip_tags($data['location'])));
                 $event->setWhoCanView((int) $data['who_can_view']);
                 $event->setWhoCanInvite((int) $data['who_can_invite']);
                 $event->setDescription($data['desc']);
                 $event->setEndDateFlag(!empty($_POST['endDateFlag']));
                 $event->setStartTimeDisable($data['start_time'] == 'all_day');
                 $event->setEndTimeDisable($data['end_time'] == 'all_day');
                 $this->eventService->saveEvent($event);
                 $e = new OW_Event(EVENT_BOL_EventService::EVENT_AFTER_EVENT_EDIT, array('eventId' => $event->id));
                 OW::getEventManager()->trigger($e);
                 OW::getFeedback()->info($language->text('event', 'edit_form_success_message'));
                 $this->redirect(OW::getRouter()->urlForRoute('event.view', array('eventId' => $event->getId())));
             }
         }
     }
     if (!$endDateFlag) {
         // $form->getElement('start_time')->addAttribute('disabled', 'disabled');
         // $form->getElement('start_time')->addAttribute('style', 'display:none;');
         $form->getElement('end_date')->addAttribute('disabled', 'disabled');
         $form->getElement('end_date')->addAttribute('style', 'display:none;');
         $form->getElement('end_time')->addAttribute('disabled', 'disabled');
         $form->getElement('end_time')->addAttribute('style', 'display:none;');
     }
     $this->assign('endDateFlag', $endDateFlag);
     $this->setPageHeading($language->text('event', 'edit_page_heading'));
     $this->setPageTitle($language->text('event', 'edit_page_title'));
     OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'event', 'main_menu_item');
     $this->addForm($form);
 }
Example #15
0
 public static function process($plugin, $params)
 {
     $language = OW::getLanguage();
     $uploaddir = OW::getPluginManager()->getPlugin('base')->getUserFilesDir();
     $name = $_FILES['file']['name'];
     if (!UTIL_File::validateImage($name)) {
         OW::getFeedback()->error("Invalid file type. Acceptable file types: JPG/PNG/GIF");
         OW::getApplication()->redirect();
     }
     $tmpname = $_FILES['file']['tmp_name'];
     if ((int) $_FILES['file']['size'] > (double) OW::getConfig()->getValue('base', 'tf_max_pic_size') * 1024 * 1024) {
         OW::getFeedback()->error($language->text('base', 'upload_file_max_upload_filesize_error'));
         OW::getApplication()->redirect();
     }
     $image = new UTIL_Image($tmpname);
     $height = $image->getHeight();
     $width = $image->getWidth();
     $id = BOL_MediaPanelService::getInstance()->add($plugin, 'image', OW::getUser()->getId(), array('name' => $name, 'height' => $height, 'width' => $width));
     $uploadFilePath = $uploaddir . $id . '-' . $name;
     $tmpUploadFilePath = $uploaddir . 'tmp_' . $id . '-' . $name;
     $image->saveImage($tmpUploadFilePath);
     $storage = OW::getStorage();
     $storage->copyFile($tmpUploadFilePath, $uploadFilePath);
     @unlink($tmpUploadFilePath);
     $params['pid'] = $id;
     OW::getApplication()->redirect(OW::getRouter()->urlFor('BASE_CTRL_MediaPanel', 'gallery', $params) . '#bottom');
 }
Example #16
0
 public function updateFile($params)
 {
     if (!OW::getUser()->isAdmin()) {
         throw new AuthenticationException();
         exit;
     }
     $slideId = isset($params['slideId']) ? trim($params['slideId']) : null;
     $service = SLIDESHOW_BOL_Service::getInstance();
     $slide = $service->findSlideById($slideId);
     $result = array('error' => true, 'message' => '');
     if ($slide) {
         $formElementId = 'file_' . $slide->widgetId;
         $language = OW::getLanguage();
         if (empty($_FILES['slide'])) {
             $result['message'] = "File not selected";
         } else {
             $file = $_FILES['slide'];
             if (is_uploaded_file($file['tmp_name'])) {
                 $iniValue = floatval(ini_get('upload_max_filesize'));
                 $maxSize = 1024 * 1024 * ($iniValue ? $iniValue : 4);
                 if (!UTIL_File::validateImage($file['name'])) {
                     $result['message'] = $language->text('slideshow', 'upload_file_extension_not_allowed');
                 } else {
                     if ($file['size'] > $maxSize) {
                         $result['message'] = $language->text('slideshow', 'upload_file_max_filesize_error');
                     } else {
                         if ($service->updateSlideImage($slide->id, $file)) {
                             $result['slide_id'] = $slideId;
                             $result['error'] = false;
                             $result['input_id'] = $formElementId;
                         } else {
                             $result['message'] = $language->text('slideshow', 'upload_file_error');
                         }
                     }
                 }
             }
         }
     }
     exit("<script>parent.window.OW.trigger('slideshow.upload_file_complete', [" . json_encode($result) . "]);</script>");
 }
Example #17
0
    /**
     * Default action
     */
    public function index(array $params = null)
    {
        $this->setTemplate(OW::getPluginManager()->getPlugin("photo")->getCtrlViewDir() . "upload_index.html");
        list($entityType, $entityId) = $this->getEntity($params);
        try {
            $this->checkUploadPermissins($entityType, $entityId);
        } catch (PHOTO_Exception $e) {
            $this->assign("auth_msg", $e->getMessage());
            return;
        }
        $language = OW::getLanguage();
        $userId = OW::getUser()->getId();
        $config = OW::getConfig();
        if (!empty($params['album']) && (int) $params['album']) {
            $albumId = (int) $params['album'];
            $uploadToAlbum = PHOTO_BOL_PhotoAlbumService::getInstance()->findAlbumById($albumId);
            if (!$uploadToAlbum || $uploadToAlbum->userId != $userId) {
                $this->onUploadReset($entityType, $entityId);
            }
        }
        $fileSizeLimit = $config->getValue('photo', 'accepted_filesize');
        $this->assign('limitMsg', $language->text('photo', 'size_limit', array('size' => $fileSizeLimit)));
        $this->assign('auth_msg', null);
        $photoUploadForm = $this->createPhotoUploadForm($entityType, $entityId);
        if (isset($uploadToAlbum)) {
            $photoUploadForm->getElement('albumId')->setValue($uploadToAlbum->id);
        }
        $this->addForm($photoUploadForm);
        $tmpPhotoService = PHOTO_BOL_PhotoTemporaryService::getInstance();
        if (OW::getRequest()->isPost()) {
            if (!$photoUploadForm->isValid($_POST)) {
                OW::getFeedback()->warning($language->text('photo', 'no_photo_uploaded'));
                $this->redirect();
            }
            $values = $photoUploadForm->getValues();
            $photosArray = $values['photos'];
            if (!count($photosArray['name'])) {
                OW::getFeedback()->warning($language->text('photo', 'no_photo_uploaded'));
                $this->redirect();
            }
            $accepted = floatval($config->getValue('photo', 'accepted_filesize') * 1024 * 1024);
            // Delete old temporary photos
            $tmpPhotoService->deleteUserTemporaryPhotos($userId);
            $uploadedCount = 0;
            $selectedCount = 0;
            $photosArray = array_reverse($photosArray);
            for ($i = 0; $i < count($photosArray['name']); $i++) {
                if (strlen($photosArray['name'][$i])) {
                    $selectedCount++;
                }
                if (strlen($photosArray['tmp_name'][$i])) {
                    if (!UTIL_File::validateImage($photosArray['name'][$i]) || $photosArray['size'][$i] > $accepted) {
                        continue;
                    }
                    if ($tmpPhotoService->addTemporaryPhoto($photosArray['tmp_name'][$i], $userId, $i)) {
                        $uploadedCount++;
                    }
                }
            }
            if ($uploadedCount == 0) {
                OW::getFeedback()->warning($language->text('photo', 'no_photo_uploaded'));
                $this->redirect();
            } else {
                if ($selectedCount > $uploadedCount) {
                    OW::getFeedback()->warning($language->text('photo', 'not_all_photos_uploaded'));
                }
            }
            $this->onUploadComplete($entityType, $entityId, $uploadedCount, empty($values['albumId']) ? null : $values['albumId']);
        }
        $advancedUpload = OW::getConfig()->getValue('photo', 'advanced_upload_enabled');
        if ($advancedUpload) {
            $menuJs = 'var $tabs = $("a[href^=js-call]", "#ow_photo_upload_menu");
                $tabs.click(function(){
                    var $this = $(this);
                    $tabs.parent().removeClass("active");
                    $this.parent().addClass("active");
                    $(".ow_photo_upload_page").hide();
                    $("#page_" + $this.data("tab_content")).show();

                }).each(function(){
                    var command = this.href.split(":");
                    $(this).data("tab_content", command[1]);
                    $(this).attr("href", "javascript://");
                });';
            OW::getDocument()->addOnloadScript($menuJs);
            $completeUrl = OW::getRouter()->urlFor(get_class($this), "flashUploadComplete", array("entityType" => $entityType, "entityId" => $entityId, "albumId" => empty($uploadToAlbum) ? null : $uploadToAlbum->id));
            OW::getDocument()->addScriptDeclaration('window.flashUploadComplete = function() {
                    document.location.href = ' . json_encode($completeUrl) . ';
                };');
            $plugin = OW::getPluginManager()->getPlugin('photo');
            OW::getDocument()->addScript($plugin->getStaticJsUrl() . 'swfobject.js');
            $mainSwfUrl = $plugin->getStaticUrl() . 'swf/main.swf';
            $xiSwfUrl = $plugin->getStaticUrl() . 'swf/playerProductInstall.swf';
            $res = OW::getConfig()->getValue('photo', 'fullsize_resolution');
            $path = OW::getRouter()->urlFor(get_class($this), 'flashUpload', array("entityType" => $entityType, "entityId" => $entityId));
            preg_match('/^http(s)?:\\/\\/[^?#%\\/]+\\/(.*)/', $path, $match);
            $path = $match[2];
            $js = 'var swfVersionStr = "10.0.0";
            var xiSwfUrlStr = "' . $xiSwfUrl . '";
            var flashvars = {};
            flashvars.uploadPath = "' . $path . '";
            flashvars.fileName = "photo";
            flashvars.lang = ' . $this->getLangXml() . ';
            flashvars.album = "my-album";
            flashvars.description = "description";
            flashvars.res = ' . json_encode($res ? $res : 1024) . ';
            var params = {};
            params.wmode = "transparent";
            params.quality = "high";
            params.bgcolor = "#ffffff";
            params.allowscriptaccess = "sameDomain";
            params.allowfullscreen = "false";
            var attributes = {};
            attributes.id = "Main";
            attributes.name = "Main";
            attributes.align = "middle";
            swfobject.embedSWF("' . $mainSwfUrl . '", "ow_flash_photo_uploader", "695", "440", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
            swfobject.createCSS("#ow_flash_photo_uploader", "display:block; text-align:left;");';
            OW::getDocument()->addOnloadScript($js);
            $tmpPhotoService->deleteUserTemporaryPhotos($userId);
        }
        $this->assign('advancedUpload', $advancedUpload);
        OW::getDocument()->setTitle($language->text('photo', 'meta_title_photo_upload'));
        OW::getDocument()->setHeading($language->text('photo', 'upload_photos'));
        OW::getDocument()->setHeadingIconClass('ow_ic_picture');
        OW::getDocument()->setDescription($language->text('photo', 'meta_description_photo_upload'));
        $albumsUrl = OW::getRouter()->urlForRoute('photo_user_albums', array('user' => BOL_UserService::getInstance()->getUserName($userId)));
        $this->assign("allAlbumsBtn", array("label" => $language->text("photo", "my_albums"), "url" => $albumsUrl));
        $menu = $this->getMenu();
        if ($menu !== null) {
            $this->addComponent("menu", $menu);
        }
    }
Example #18
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');
 }
Example #19
0
 /**
  * @see OW_Validator::isValid()
  *
  * @param mixed $value
  */
 public function isValid($value)
 {
     $language = OW::getLanguage();
     if (!isset($_FILES['image']['name']) || strlen($_FILES['image']['name']) == 0) {
         $return = false;
         if (!$this->setRequired) {
             $return = true;
         }
         return $return;
     }
     if (isset($_FILES['image']['name']) && !UTIL_File::validateImage($_FILES['image']['name'])) {
         return false;
     }
     if ($_FILES['image']['error'] != UPLOAD_ERR_OK) {
         $message = '';
         switch ($_FILES['image']['error']) {
             case UPLOAD_ERR_INI_SIZE:
                 $message = $language->text('base', 'upload_file_max_upload_filesize_error');
                 break;
             case UPLOAD_ERR_PARTIAL:
                 $message = $language->text('base', 'upload_file_file_partially_uploaded_error');
                 break;
             case UPLOAD_ERR_NO_FILE:
                 $message = $language->text('base', 'upload_file_no_file_error');
                 break;
             case UPLOAD_ERR_NO_TMP_DIR:
                 $message = $language->text('base', 'upload_file_no_tmp_dir_error');
                 break;
             case UPLOAD_ERR_CANT_WRITE:
                 $message = $language->text('base', 'upload_file_cant_write_file_error');
                 break;
             case UPLOAD_ERR_EXTENSION:
                 $message = $language->text('base', 'upload_file_invalid_extention_error');
                 break;
         }
         if (!empty($message)) {
             $this->setErrorMessage($message);
             return false;
         }
     }
     return true;
 }
Example #20
0
 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;
 }
Example #21
0
 /**
  * @see Validator::isValid()
  *
  * @param mixed $value
  */
 public function isValid($value)
 {
     $language = OW::getLanguage();
     if (!isset($_FILES['userPhoto']['name']) || strlen($_FILES['userPhoto']['name']) == 0) {
         $return = false;
         if (!$this->setRequired) {
             $return = true;
         }
         return $return;
     }
     if (isset($_FILES['userPhoto']['name']) && !UTIL_File::validateImage($_FILES['userPhoto']['name'])) {
         return false;
     }
     if (!is_writable(BOL_AvatarService::getInstance()->getAvatarsDir())) {
         $this->setErrorMessage($language->text('base', 'not_writable_avatar_dir'));
         return false;
     }
     return true;
 }
Example #22
0
 /**
  * @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;
 }
Example #23
0
    public function photo(array $params = null)
    {
        if (!OW::getUser()->isAuthenticated()) {
            throw new AuthenticateException();
        }
        $language = OW::getLanguage();
        if (!OW::getUser()->isAuthorized('photo', 'upload')) {
            $status = BOL_AuthorizationService::getInstance()->getActionStatus('photo', 'upload');
            $this->assign('auth_msg', $status['msg']);
            return;
        }
        $config = OW::getConfig();
        $userQuota = (int) $config->getValue('photo', 'user_quota');
        $userId = OW::getUser()->getId();
        if (!($this->photoService->countUserPhotos($userId) <= $userQuota)) {
            $this->assign('auth_msg', $language->text('photo', 'quota_exceeded', array('limit' => $userQuota)));
        } else {
            $accepted = floatval($config->getValue('photo', 'accepted_filesize') * 1024 * 1024);
            $this->assign('auth_msg', null);
            $form = new PHOTO_MCLASS_UploadForm();
            $this->addForm($form);
            $photoAlbumService = PHOTO_BOL_PhotoAlbumService::getInstance();
            $albums = $photoAlbumService->findUserAlbumList($userId, 1, 100);
            $this->assign('albums', $albums);
            if (!empty($params['album']) && (int) $params['album']) {
                $albumId = (int) $params['album'];
                $uploadToAlbum = $photoAlbumService->findAlbumById($albumId);
                if (!$uploadToAlbum || $uploadToAlbum->userId != $userId) {
                    $this->redirect(OW::getRouter()->urlForRoute('photo_upload'));
                }
                $form->getElement('album')->setValue($uploadToAlbum->name);
            }
            if ($albums) {
                $script = '$("#album_select").change(function(event){
                    $("#album_input").val($(this).val());
                });';
                OW::getDocument()->addOnloadScript($script);
            }
            $script = '$("#upload-file-field").change(function(){
                var img = $("#photo-file-prevew");
                var name = $(".owm_upload_img_name_label span");

                img.hide();
                name.text("");

                if (!this.files || !this.files[0]) return;

                if ( window.FileReader ) {
                    var reader = new FileReader();
                    reader.onload = function (e) {
                        img.show().attr("src", e.target.result);
                    }
                    reader.readAsDataURL(this.files[0]);
                } else {
                    name.text(this.files[0].name);
                }
                $(".owm_upload_photo_browse_wrap").addClass("owm_upload_photo_attach_wrap");
            });';
            OW::getDocument()->addOnloadScript($script);
            if (OW::getRequest()->isPost()) {
                $form->isValid($_POST);
                $values = $form->getValues();
                // Delete old temporary photos
                $tmpPhotoService = PHOTO_BOL_PhotoTemporaryService::getInstance();
                $photoService = PHOTO_BOL_PhotoService::getInstance();
                $file = $_FILES['photo'];
                $tmpPhotoService->deleteUserTemporaryPhotos($userId);
                if (strlen($file['tmp_name'])) {
                    if (!UTIL_File::validateImage($file['name']) || $file['size'] > $accepted) {
                        OW::getFeedback()->warning($language->text('photo', 'no_photo_uploaded'));
                        $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($values['album'], $userId))) {
                        $album = new PHOTO_BOL_PhotoAlbum();
                        $album->name = $values['album'];
                        $album->userId = $userId;
                        $album->createDatetime = time();
                        $photoAlbumService->addAlbum($album);
                    }
                    foreach ($tmpList as $tmpPhoto) {
                        $photo = $tmpPhotoService->moveTemporaryPhoto($tmpPhoto['dto']->id, $album->id, $values['description']);
                        if ($photo) {
                            BOL_AuthorizationService::getInstance()->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 = $this->photoService->findPhotoById($photo->id);
                            if ($photo->status != PHOTO_BOL_PhotoDao::STATUS_APPROVED) {
                                OW::getFeedback()->info(OW::getLanguage()->text('photo', 'photo_uploaded_pending_approval'));
                                if (PHOTO_BOL_PhotoAlbumService::getInstance()->countAlbumPhotos($photo->albumId)) {
                                    $this->redirect(OW::getRouter()->urlForRoute('photo_user_album', array('user' => BOL_UserService::getInstance()->getUserName($userId), 'album' => $album->id)));
                                } else {
                                    $this->redirect(OW::getRouter()->urlForRoute('photo_user_albums', array('user' => BOL_UserService::getInstance()->getUserName($userId))));
                                }
                            } else {
                                OW::getFeedback()->info($language->text('photo', 'photos_uploaded', array('count' => 1)));
                                $this->redirect(OW::getRouter()->urlForRoute('view_photo', array('id' => $photo->id)));
                            }
                        }
                    }
                } else {
                    OW::getFeedback()->warning($language->text('photo', 'no_photo_uploaded'));
                    $this->redirect();
                }
            }
        }
        OW::getDocument()->setHeading($language->text('photo', 'upload_photos'));
        OW::getDocument()->setTitle($language->text('photo', 'meta_title_photo_upload'));
    }
Example #24
0
 public function user()
 {
     if (!OW::getRequest()->isAjax()) {
         OW::getNavigation()->activateMenuItem(OW_Navigation::ADMIN_SETTINGS, 'admin', 'sidebar_menu_item_user_settings');
     }
     $language = OW::getLanguage();
     $menu = $this->getUsersMenu();
     $menu->getElement('general')->setActive(true);
     $this->addComponent('menu', $menu);
     $avatarService = BOL_AvatarService::getInstance();
     if (isset($_GET['del-avatar']) && in_array($_GET['del-avatar'], array(1, 2))) {
         $del = $avatarService->deleteCustomDefaultAvatar((int) $_GET['del-avatar']);
         if ($del) {
             OW::getFeedback()->info($language->text('admin', 'default_avatar_deleted'));
         }
         $this->redirect(OW::getRouter()->urlForRoute('admin_settings_user'));
     }
     $uploadMaxFilesize = (double) ini_get("upload_max_filesize");
     $postMaxSize = (double) ini_get("post_max_size");
     $maxUploadMaxFilesize = BOL_FileService::getInstance()->getUploadMaxFilesize();
     $this->assign('maxUploadMaxFilesize', $maxUploadMaxFilesize);
     $userSettingsForm = new UserSettingsForm($maxUploadMaxFilesize);
     $this->addForm($userSettingsForm);
     $conf = OW::getConfig();
     $avatarSize = $conf->getValue('base', 'avatar_size');
     $bigAvatarSize = $conf->getValue('base', 'avatar_big_size');
     $avatarUploadSize = $conf->getValue('base', 'avatar_max_upload_size');
     $userSettingsForm->getElement('avatar_max_upload_size')->setValue((double) $avatarUploadSize);
     $userSettingsForm->getElement('avatarSize')->setValue($avatarSize);
     $userSettingsForm->getElement('bigAvatarSize')->setValue($bigAvatarSize);
     $userSettingsForm->getElement('displayName')->setValue($conf->getValue('base', 'display_name_question'));
     $this->assign('displayConfirmEmail', !defined('OW_PLUGIN_XP'));
     if (OW::getRequest()->isPost() && $userSettingsForm->isValid($_POST)) {
         if (!empty($_FILES['avatar']['tmp_name']) && !UTIL_File::validateImage($_FILES['avatar']['name']) || !empty($_FILES['bigAvatar']['tmp_name']) && !UTIL_File::validateImage($_FILES['bigAvatar']['name'])) {
             OW::getFeedback()->error($language->text('base', 'not_valid_image'));
             $this->redirect();
         }
         $res = $userSettingsForm->process();
         OW::getFeedback()->info($language->text('admin', 'user_settings_updated'));
         $this->redirect();
     }
     $avatar = $avatarService->getDefaultAvatarUrl(1);
     $avatarBig = $avatarService->getDefaultAvatarUrl(2);
     $this->assign('avatar', $avatar);
     $this->assign('avatarBig', $avatarBig);
     $custom = json_decode($conf->getValue('base', 'default_avatar'), true);
     $this->assign('customAvatar', $custom);
     $language->addKeyForJs('admin', 'confirm_avatar_delete');
     if (!OW::getRequest()->isAjax()) {
         OW::getDocument()->setHeading(OW::getLanguage()->text('admin', 'heading_user_settings'));
         OW::getDocument()->setHeadingIconClass('ow_ic_gear_wheel');
     }
     OW::getNavigation()->deactivateMenuItems(OW_Navigation::ADMIN_SETTINGS);
 }
Example #25
0
 public function editGoal()
 {
     if (OW::getRequest()->isPost() && $_POST['form_name'] == 'edit-goal-form') {
         $service = OCSFUNDRAISING_BOL_Service::getInstance();
         $goalId = $_POST['goalId'];
         if (!$goalId || !($goal = $service->getGoalById($goalId))) {
             $this->redirect(OW::getRouter()->urlForRoute('ocsfundraising.admin'));
         }
         $goal['dto']->name = trim($_POST['name']);
         $goal['dto']->description = trim($_POST['description']);
         $goal['dto']->amountTarget = floatval($_POST['target']);
         $goal['dto']->amountCurrent = floatval($_POST['current']);
         $goal['dto']->amountMin = floatval($_POST['min']);
         $goal['dto']->categoryId = $_POST['category'];
         $goal['dto']->ownerType = 'admin';
         $goal['dto']->ownerId = OW::getUser()->getId();
         if (!empty($_POST['month_end']) && !empty($_POST['day_end']) && !empty($_POST['year_end'])) {
             $goal['dto']->endStamp = mktime(0, 0, 0, $_POST['month_end'], $_POST['day_end'], $_POST['year_end']);
         } else {
             $goal['dto']->endStamp = null;
         }
         $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(OW::getLanguage()->text('base', 'not_valid_image'));
             } else {
                 $imagePosted = true;
             }
         }
         if ($imagePosted && $imageValid) {
             $service->saveImage($goal['dto']->id, $_FILES['image']['tmp_name'], $goal['dto']->image);
         }
         $service->update($goal['dto']);
         OW::getFeedback()->info(OW::getLanguage()->text('ocsfundraising', 'goal_updated'));
     }
     $this->redirect(OW::getRouter()->urlForRoute('ocsfundraising.admin'));
 }