Ejemplo n.º 1
0
 public function get($id, $request)
 {
     if (UserChannel::find($id)->belongToUser(Session::get()->id)) {
         $uploadId = Upload::generateId(6);
         Upload::create(array('id' => $uploadId, 'channel_id' => $id, 'video_id' => Video::generateId(6), 'expire' => Utils::tps() + 86400));
         $data = array();
         $data['currentPageTitle'] = 'Mettre en ligne';
         $data['uploadId'] = $uploadId;
         $data['thumbnail'] = Config::getValue_('default-thumbnail');
         $data['channelId'] = $id;
         $data['currentPage'] = 'upload';
         //$data['predefined_descriptions'] = PredefinedDescription::getDescriptionByChannelsids($id);
         return new ViewResponse('upload/upload', $data);
     } else {
         return new RedirectResponse(WEBROOT . 'upload');
     }
 }
 public function __construct($controller, $name, $fields = null, $actions = null)
 {
     $fields = new FieldList($Nickname = TextField::create('Nickname')->setTitle(_t('Member.NICKNAME', 'Member.NICKNAME')), $Location = BootstrapGeoLocationField::create('Location')->setTitle(_t('Member.LOCATION', 'Member.LOCATION')), $About = TextareaField::create('About')->setTitle(_t('DonatorProfile.ABOUT', 'DonatorProfile.ABOUT'))->setPlaceholder(_t('DonatorProfile.ABOUTDESCRIPTION', 'DonatorProfile.ABOUTDESCRIPTION')), $Active = CheckboxField::create('Active')->setTitle(_t('Member.ACTIVE', 'Member.ACTIVE')), $Avatar = BootstrapFileField::create('Avatar')->setTitle(_t('Member.AVATAR', 'Member.AVATAR')));
     $Location->setRightTitle(_t('Member.LOCATIONDESCRIPTION', 'Member.LOCATIONDESCRIPTION'));
     $About->setRightTitle(_t('DonatorProfile.ABOUTDESCRIPTION', 'DonatorProfile.ABOUTDESCRIPTION'));
     // Upload Parameters
     $exts = array('jpg', 'jpeg', 'gif', 'png');
     $validator = new Upload_Validator();
     $validator->setAllowedExtensions($exts);
     $validator->setAllowedMaxFileSize(5000000);
     $upload = Upload::create();
     $upload->setValidator($validator);
     // Avatar Upload Folder
     $Avatar->setFolderName("Uploads/Members/" . Member::currentUser()->ID . "/Avatars");
     $Avatar->setUpload($upload);
     $actions = new FieldList($Submit = BootstrapLoadingFormAction::create('doSave')->setTitle(_t('HostelEditForm.SAVEBUTTON', 'HostelEditForm.SAVEBUTTON')));
     parent::__construct($controller, $name, $fields, $actions, new RequiredFields("Nickname", "Location", "About"));
     $this->loadDataFrom(Member::currentUser());
 }
 public function __construct($controller, $name, $fields = null, $actions = null)
 {
     $fields = new FieldList($Version = BootstrapSemVerField::create('Version')->setTitle(_t('BoxVersion.VERSION', 'BoxVersion.VERSION')), $Description = TextareaField::create('Description')->setTitle(_t('Box.DESCRIPTION', 'Box.DESCRIPTION')), $File = new BootstrapUploadField('File', _t('Box.FILE', 'Box.FILE')), $BoxID = HiddenField::create('BoxID'));
     $actions = new FieldList($Submit = BootstrapLoadingFormAction::create('doAdd')->setTitle(_t('BoxAddForm.DOADD', 'BoxAddForm.DOADD')));
     parent::__construct($controller, $name, $fields, $actions, new RequiredFields("Version", "Description", "File", "BoxID"));
     if (isset($GLOBALS['BoxID'])) {
         $Box = Box::get()->byID($GLOBALS['BoxID']);
         $BoxID->setValue($Box->ID);
         $Description->setValue($Box->Description);
         $File->setFolderName("Uploads/Boxes/" . $Box->Slug);
     }
     // Upload Parameters
     $exts = array('box');
     $validator = new Upload_Validator();
     $validator->setAllowedExtensions($exts);
     //$validator->setAllowedMaxFileSize(5000000);
     $upload = Upload::create();
     $upload->setValidator($validator);
     $File->setUpload($upload);
     $this->loadDataFrom(singleton('BoxProvider'));
 }
 public function __construct($controller, $name, $fields = null, $actions = null)
 {
     $fields = new FieldList($Nickname = TextField::create('Nickname')->setTitle(_t('Member.NICKNAME', 'Member.NICKNAME')), $Location = BootstrapGeoLocationField::create('Location')->setTitle(_t('Member.LOCATION', 'Member.LOCATION')), $Adults = DropdownField::create('Adults')->setTitle(_t('RefugeeProfile.ADULTS', 'RefugeeProfile.ADULTS'))->setSource(Config::inst()->get('Member', 'people_sum')), $Children = DropdownField::create('Children')->setTitle(_t('RefugeeProfile.CHILDREN', 'RefugeeProfile.CHILDREN'))->setSource(Config::inst()->get('Member', 'people_sum')), $Baby = CheckboxField::create('Baby')->setTitle(_t('RefugeeProfile.BABY', 'RefugeeProfile.BABY')), $About = TextareaField::create('About')->setTitle(_t('RefugeeProfile.ABOUT', 'RefugeeProfile.ABOUT'))->setPlaceholder(_t('RefugeeProfile.ABOUTDESCRIPTION', 'RefugeeProfile.ABOUTDESCRIPTION')), $Active = CheckboxField::create('Active')->setTitle(_t('Member.ACTIVE', 'Member.ACTIVE')), $Avatar = BootstrapFileField::create('Avatar')->setTitle(_t('Member.AVATAR', 'Member.AVATAR')));
     $Location->setRightTitle(_t('Member.LOCATIONDESCRIPTION', 'Member.LOCATIONDESCRIPTION'));
     $Adults->setRightTitle(_t('RefugeeProfile.ADULTSDESCRIPTION', 'RefugeeProfile.ADULTSDESCRIPTION'));
     $Children->setRightTitle(_t('RefugeeProfile.CHILDRENDESCRIPTION', 'RefugeeProfile.CHILDRENDESCRIPTION'));
     $Baby->setRightTitle(_t('RefugeeProfile.BABYDESCRIPTION', 'RefugeeProfile.BABYDESCRIPTION'));
     $About->setRightTitle(_t('RefugeeProfile.ABOUTDESCRIPTION', 'RefugeeProfile.ABOUTDESCRIPTION'));
     // Upload Parameters
     $exts = array('jpg', 'jpeg', 'gif', 'png');
     $validator = new Upload_Validator();
     $validator->setAllowedExtensions($exts);
     $validator->setAllowedMaxFileSize(5000000);
     $upload = Upload::create();
     $upload->setValidator($validator);
     // Avatar Upload Folder
     $Avatar->setFolderName("Uploads/Members/" . Member::currentUser()->ID . "/Avatars");
     $Avatar->setUpload($upload);
     $actions = new FieldList($Submit = BootstrapLoadingFormAction::create('doSave')->setTitle(_t('RefugeeEditForm.SAVEBUTTON', 'RefugeeEditForm.SAVEBUTTON')));
     parent::__construct($controller, $name, $fields, $actions, new RequiredFields("Nickname", "Location", "Adults", "Children", "About"));
     $this->loadDataFrom(Member::currentUser());
 }
Ejemplo n.º 5
0
 /**
  * Create a new file field.
  *
  * @param string $name The internal field name, passed to forms.
  * @param string $title The field label.
  * @param int $value The value of the field.
  */
 public function __construct($name, $title = null, $value = null)
 {
     $this->upload = Upload::create();
     parent::__construct($name, $title, $value);
 }
Ejemplo n.º 6
0
 /**
  * Post a message to the forum. This method is called whenever you want to make a
  * new post or edit an existing post on the forum
  *
  * @param Array - Data
  * @param Form - Submitted Form
  */
 function doPostMessageForm($data, $form)
 {
     $member = Member::currentUser();
     $content = isset($data['Content']) ? $this->filterLanguage($data["Content"]) : "";
     $title = isset($data['Title']) ? $this->filterLanguage($data["Title"]) : false;
     // If a thread id is passed append the post to the thread. Otherwise create
     // a new thread
     $thread = false;
     if (isset($data['ThreadID'])) {
         $thread = DataObject::get_by_id('ForumThread', $data['ThreadID']);
     }
     // If this is a simple edit the post then handle it here. Look up the correct post,
     // make sure we have edit rights to it then update the post
     $post = false;
     if (isset($data['ID'])) {
         $post = DataObject::get_by_id('Post', $data['ID']);
         if ($post && $post->isFirstPost()) {
             if ($title) {
                 $thread->Title = $title;
             }
         }
     }
     // Check permissions
     $messageSet = array('default' => _t('Forum.LOGINTOPOST', 'You\'ll need to login before you can post to that forum. Please do so below.'), 'alreadyLoggedIn' => _t('Forum.NOPOSTPERMISSION', 'I\'m sorry, but you do not have permission post to this forum.'), 'logInAgain' => _t('Forum.LOGINTOPOSTAGAIN', 'You have been logged out of the forums.  If you would like to log in again to post, enter a username and password below.'));
     // Creating new thread
     if (!$thread && !$this->canPost()) {
         Security::permissionFailure($this, $messageSet);
         return false;
     }
     // Replying to existing thread
     if ($thread && !$post && !$thread->canPost()) {
         Security::permissionFailure($this, $messageSet);
         return false;
     }
     // Editing existing post
     if ($thread && $post && !$post->canEdit()) {
         Security::permissionFailure($this, $messageSet);
         return false;
     }
     if (!$thread) {
         $thread = new ForumThread();
         $thread->ForumID = $this->ID;
         if ($title) {
             $thread->Title = $title;
         }
         $starting_thread = true;
     }
     // Upload and Save all files attached to the field
     // Attachment will always be blank, If they had an image it will be at least in Attachment-0
     //$attachments = new DataObjectSet();
     $attachments = new ArrayList();
     if (!empty($data['Attachment-0']) && !empty($data['Attachment-0']['tmp_name'])) {
         $id = 0;
         //
         // @todo this only supports ajax uploads. Needs to change the key (to simply Attachment).
         //
         while (isset($data['Attachment-' . $id])) {
             $image = $data['Attachment-' . $id];
             if ($image && !empty($image['tmp_name'])) {
                 $file = Post_Attachment::create();
                 $file->OwnerID = Member::currentUserID();
                 $folder = Config::inst()->get('ForumHolder', 'attachments_folder');
                 try {
                     $upload = Upload::create()->loadIntoFile($image, $file, $folder);
                     $file->write();
                     $attachments->push($file);
                 } catch (ValidationException $e) {
                     $message = _t('Forum.UPLOADVALIDATIONFAIL', 'Unallowed file uploaded. Please only upload files of the following: ');
                     $message .= implode(', ', Config::inst()->get('File', 'allowed_extensions'));
                     $form->addErrorMessage('Attachment', $message, 'bad');
                     Session::set("FormInfo.Form_PostMessageForm.data", $data);
                     return $this->redirectBack();
                 }
             }
             $id++;
         }
     }
     // from now on the user has the correct permissions. save the current thread settings
     $thread->write();
     if (!$post || !$post->canEdit()) {
         $post = new Post();
         $post->AuthorID = $member ? $member->ID : 0;
         $post->ThreadID = $thread->ID;
     }
     $post->ForumID = $thread->ForumID;
     $post->Content = $content;
     $post->write();
     if ($attachments) {
         foreach ($attachments as $attachment) {
             $attachment->PostID = $post->ID;
             $attachment->write();
         }
     }
     // Add a topic subscription entry if required
     $isSubscribed = ForumThread_Subscription::already_subscribed($thread->ID);
     if (isset($data['TopicSubscription'])) {
         if (!$isSubscribed) {
             // Create a new topic subscription for this member
             $obj = new ForumThread_Subscription();
             $obj->ThreadID = $thread->ID;
             $obj->MemberID = Member::currentUserID();
             $obj->write();
         }
     } elseif ($isSubscribed) {
         // See if the member wanted to remove themselves
         DB::prepared_query('DELETE FROM "ForumThread_Subscription" WHERE "ThreadID" = ? AND "MemberID" = ?', array($post->ThreadID, $member->ID));
     }
     // Send any notifications that need to be sent
     ForumThread_Subscription::notify($post);
     // Send any notifications to moderators of the forum
     if (Forum::$notify_moderators) {
         if (isset($starting_thread) && $starting_thread) {
             $this->notifyModerators($post, $thread, true);
         } else {
             $this->notifyModerators($post, $thread);
         }
     }
     return $this->redirect($post->Link());
 }